1

I am compiling my project with the command cmake .. -G "CodeBlocks - Ninja, which works fine, but when I run valgrind it does not display any lines numbers. This is the valgrind command I am using: valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --log-file="log.txt" ./pony_gpExe.

Here is an example of the output:

==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)

Not sure if this is helpful but here is my main 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)
Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
Robbie
  • 1,733
  • 2
  • 13
  • 20

3 Answers3

5

You need to tell cmake to produce a debug executable. Without seeing your cmake config, it's hard to tell you how to do this, but by default/convention, it should be:

cmake -DCMAKE_BUILD_TYPE=Debug

See this answer on Debug vs Release in CMAKE for additional infomation.

Timothy Jones
  • 21,495
  • 6
  • 60
  • 90
1

I hope you compiled your code with -g and assume you running code in Ubuntu or Mac OS

Try to run valgrind like this which does the trick in Ubuntu

valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --dsymutil=yes --log-file="log.txt" ./pony_gpExe. 
ntshetty
  • 1,293
  • 9
  • 20
0

So, I don't know why but randomly valgrind started to show the line numbers... I didn't really do anything different, but either way it works...

Robbie
  • 1,733
  • 2
  • 13
  • 20