【问题标题】:Valgrind not showing line numbers when compiled with cmake使用 cmake 编译时 Valgrind 不显示行号
【发布时间】:2018-05-22 05:45:45
【问题描述】:

我正在使用命令cmake .. -G "CodeBlocks - Ninja 编译我的项目,它工作正常,但是当我运行 valgrind 时它不显示任何行号。 这是我正在使用的 valgrind 命令:valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --log-file="log.txt" ./pony_gpExe

这是一个输出示例:

==5402== Use of uninitialised value of size 8
==5402==    at 0x40447B: get_double_arr_length (in /home/robbie/Dropbox/MIT/pony_gp_ubuntu/build/pony_gpExe)
==5402==    by 0x405184: get_test_and_train_data (in /home/robbie/Dropbox/MIT/pony_gp_ubuntu/build/pony_gpExe)
==5402==    by 0x4027B3: setup (in /home/robbie/Dropbox/MIT/pony_gp_ubuntu/build/pony_gpExe)
==5402==    by 0x402861: main (in /home/robbie/Dropbox/MIT/pony_gp_ubuntu/build/pony_gpExe)
==5402==  Uninitialised value was created by a stack allocation
==5402==    at 0x405149: get_test_and_train_data (in /home/robbie/Dropbox/MIT/pony_gp_ubuntu/build/pony_gpExe)

不确定这是否有用,但这是我的主要 CMakeLists.txt:

cmake_minimum_required(VERSION 3.4.3)
project (pony_gp)
set(DIR ${pony_gp_SOURCE_DIR})

file(GLOB_RECURSE pony_gp_SOURCES "${DIR}/src/*.c")
file(GLOB_RECURSE pony_gp_HEADERS "${DIR}/include/*.h")

foreach (_headerFile ${pony_gp_HEADERS})
    get_filename_component(_dir ${_headerFile} PATH)
    list (APPEND pony_gp_INCLUDE_DIRS ${_dir})
endforeach()
list(REMOVE_DUPLICATES pony_gp_INCLUDE_DIRS)

include("${DIR}/include/CMakeLists.txt")
include_directories(${pony_gp_INCLUDE_DIRS})
add_executable (pony_gpExe ${pony_gp_SOURCES})

if (CMAKE_COMPILER_IS_GNUCC)

    target_link_libraries(pony_gpExe m)

    find_program(MEMORYCHECK_COMMAND valgrind)
    set(MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full")
    set(MEMORYCHECK_SUPPRESSIONS_FILE "${DIR}/valgrind_suppress.txt")
endif()

include(CTest)
add_test(test pony_gpExe)

【问题讨论】:

    标签: c debugging cmake valgrind


    【解决方案1】:

    您需要告诉cmake 生成调试可执行文件。没有看到你的 cmake 配置,很难告诉你如何做到这一点,但默认/约定,它应该是:

    cmake -DCMAKE_BUILD_TYPE=Debug
    

    有关更多信息,请参阅Debug vs Release in CMAKE 上的此答案。

    【讨论】:

    • 我添加了这个,但它没有修复它。我应该包括什么来清楚地了解我的 cmake 配置? CmakeLists.txt?
    • 是的,从那里开始。恐怕我对cmake不是很熟悉。
    • 这对我有用,是我需要让 valgrind 显示行号的唯一更改。
    【解决方案2】:

    我希望您使用 -g 编译代码并假设您在 UbuntuMac OS 中运行代码

    尝试像这样在 Ubuntu 中运行 valgrind 就可以了

    valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --dsymutil=yes --log-file="log.txt" ./pony_gpExe. 
    

    【讨论】:

    • 我试过了,但没有解决。是的,我在 Ubuntu 上运行它。
    • 它只是打印我的程序的输出。
    • 你是不是像 cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug 那样构建的?
    • 是的,我试过准确输入,但仍然没有解决任何问题。
    【解决方案3】:

    所以,我不知道为什么,但随机 valgrind 开始显示行号...我并没有真正做任何不同的事情,但无论哪种方式都有效...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-30
      • 2014-04-23
      相关资源
      最近更新 更多