使用 cmake 编译时 Valgrind 不显示行号
Valgrind not showing line numbers when compiled with cmake
我正在使用命令 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)
我希望您使用 -g
编译代码并假设您 运行ning 代码在 Ubuntu
或 Mac OS
尝试 运行 valgrind
像这样 Ubuntu
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --dsymutil=yes --log-file="log.txt" ./pony_gpExe.
您需要告诉 cmake
生成调试可执行文件。没有看到你的 cmake 配置,很难告诉你如何做到这一点,但 default/convention,它应该是:
cmake -DCMAKE_BUILD_TYPE=Debug
有关更多信息,请参阅 Debug vs Release in CMAKE 上的此答案。
所以,我不知道为什么,但随机 valgrind 开始显示行号......我并没有真正做任何不同的事情,但无论哪种方式都有效......
我正在使用命令 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)
我希望您使用 -g
编译代码并假设您 运行ning 代码在 Ubuntu
或 Mac OS
尝试 运行 valgrind
像这样 Ubuntu
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --dsymutil=yes --log-file="log.txt" ./pony_gpExe.
您需要告诉 cmake
生成调试可执行文件。没有看到你的 cmake 配置,很难告诉你如何做到这一点,但 default/convention,它应该是:
cmake -DCMAKE_BUILD_TYPE=Debug
有关更多信息,请参阅 Debug vs Release in CMAKE 上的此答案。
所以,我不知道为什么,但随机 valgrind 开始显示行号......我并没有真正做任何不同的事情,但无论哪种方式都有效......