Why I cannot get Valgrind diagnostic information with CMake?

I am now running CTest with or without Valgrind in Ubuntu Linux. Firstly, I set up a CMakeLists.txt script to enable testing:

enable_testing()
include(CTest)
if(UNIX)
  set(CTEST_MEMORYCHECK_COMMAND, "usr/bin/valgrind")
  set(CTEST_MEMORYCHECK_COMMAND_OPTIONS, "--trace-children=yes --leak-check=full")
endif()

add_test(NAME test
        WORKING_DIRECTORY ${my_outputdirectory}
        COMMAND test_exe)

When I run the test without valgrind, I use the following command:

cmake -G "CodeBlocks - Unix Makefiles"
ctest -D ExperimentalBuild  
ctest -R test -D ExperimentalTest  

That works fine. However, when I run the following command to invoke valgrind:

 cmake -G "CodeBlocks - Unix Makefiles"
    ctest -D ExperimentalBuild  
    ctest -R test -D ExperimentalMemChec

the following message appear:

--Processing memory checking output:
Memory checking results:

This is definitely not the diagnostic information I expect. I was wondering what I should do next. Thanks!

EDIT: Later on, I find that the diagnostic information can be available only in the case where the memory leak happens. However, the diagnostic information is very vague in the sense that the location where the error occurs is not given. How could I obtain more detailed information?

I use a python script which parses my memory leaks from valgrind it is available here.

In CMake I use the following command to add a memory test:

ADD_TEST(testName ${Test_Dir}/memtest.py ${CMAKE_CURRENT_BINARY_DIR}/testExecutable ${CMAKE_BINARY_DIR})

Such that I do not need to parse the memory leak errors direct in cmake. The python script simply executes a memory check with valgrind on the executable and returns an error if a leak was found. If a leak was found the test then fails otherwise it passes. Hope this might help you.

ctest(1) — CMake 3.14.7 Documentation, Some CMake-generated build trees can have multiple build configurations in the same tree. Test output is normally suppressed and only summary information is displayed. an older version of CDash which doesn't support compressed test output. Otherwise, CTest must “scrape” the build output log for diagnostics. Valgrind memcheck. Valgrind Memcheck is a tool that helps identify memory errors in C and C++ code. It can detect various problems such as memory leaks, invalid memory access, incorrect freeing of memory, and using undefined values.

By default, CMake does not build debug symbols for Makefile projects, so Valgrind is unable to determine the exact location of a leak in source code.

Try running cmake with

cmake -DCMAKE_BUILD_TYPE=Debug /path/to/source

which should add the compiler option for building debug symbols.

[CMake] Valgrind does not find tests, Hello, I have a basic Nighly script which runs our basic test and works fine. My script [startScriptValgrind.cmake]:* # Set Information for build´┐Ż sudo apt-get install lcov cmake -D COVERAGE=ON -D CMAKE_BUILD_TYPE=Debug ../ make make code_coverage This generates a index.html page in the build/coverage sub-directory that can be viewed locally in a web browser.

CMake by default uses the following command line arguments for valgrind memcheck:

--log-file=/Path/to/build-dir/Testing/Temporary/MemoryChecker.1.log \
-q --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=50

Note that the --log-file argument means that any valgrind errors ends up in that file. I find it more useful when valgrind posts the information to the stderr, so a build server like Jenkins or TeamCity can show it more easily. In order to do that, you have to set the MEMORYCHECK_COMMAND_OPTIONS variable with --log-fd=2 (and other options if you'd like) so it overrides the --log-file option. More info here.

Passing Variables to ctest - cmake - php, Is there a way besides environment variables to pass information to ctest? with cmake there is: I also have ctest that runs all executables added by add_test CMake command. Why I cannot get Valgrind diagnostic information with CMake? sudo apt-get install lcov cmake -D COVERAGE=ON -D CMAKE_BUILD_TYPE=Debug ../ make make code_coverage This generates a index.html page in the build/coverage sub-directory that can be viewed locally in a web browser.

cmake-variables(7) — cmake-data — Debian unstable — Debian , This page documents variables that are provided by CMake or have meaning to For general information on variables, see the Variables section in the cmake- language manual. It can be useful for diagnostic or debug messages. where to locate those files in a way that doesn't depend on where the function is called. The cmake-properties(7) manual is printed in a human-readable text format. The help is printed to a named <f>ile if given.--help-variable <var> [<f>] Print help for one variable and exit. The cmake-variables(7) manual entry for <var> is printed in a human-readable text format. The help is printed to a named <f>ile if given.

CMakeLists.txt - external/dynamorio, move info like "build core solely from DDK" from make/compiler.mk into. # HowToBuild.wiki i#310: support building over cygwin ssh where we cannot build pdbs. option(CLANG_COLOR_DIAGNOSTICS "force colored clang diagnostics" OFF) REGEX "annotations/valgrind.h|annotations/memcheck.h" EXCLUDE). Valgrind is a multipurpose code profiling and memory debugging tool for Linux when on the x86 and, as of version 3, AMD64, architectures. It allows you to run your program in Valgrind's own environment that monitors memory usage such as calls to malloc and free (or new and delete in C++).

Setting up your Development Environment, Install Git for Windows https://git-scm.com/downloads; Install MSys2 Open terminal use: brew install valgrind cppcheck gcc make cmake emacs diagnostics; Minimize background apps; Don't let apps access diagnostic info files by accessing /mnt/c but Windows cannot access Ubuntu files -- learned it the hard way! Contribute to Ghost1995/Valgrind development by creating an account on GitHub. Dismiss Join GitHub today. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

Comments
  • Debug is one of the build types defined in your cache file, it just sends a certain additional string when you use it. How it's defined may vary, you can edit it.