Search code examples
pythoncvalgrind

Do I need to install packages with debug symbols to use Valgrind on my C-compiled executable?


I'm in a systems programming class, and the python-based test driver for one of our assignments needs to run Valgrind on a C-compiled executable.

I'm trying to put Valgrind on my laptop. I'm using Ubuntu 18.04.4 LTS. I was reading though the Ubuntu wiki and the page on Valgrind said to "have packages with debug symbols installed." I checked the page they reference about this, and I still have no idea which packages I need to install with debug symbols.

I was reading though some stack overflow answers, and this one mentions that "Valgrind is readily usable for C/C++ code, but can even be used for other languages when configured." The Valgrind quickstart guide also give no warnings about debug symbols. It just says to use the flag -g when compiling.

Does the Ubuntu wiki's warning about debug symbols just apply to other programs that are not compiled from C?


Solution

  • Wiki says about any libraries your code links with. In order in analyze stracktraces from valgrind it is good to link with these libraries debug versions. What these libraries are depends only on your application.

    Imagine you develop some application. Then you want to trace some memory leak or segmentation fault. So you run your compiled program under valgrind. You compile your program with -g flag to have nice messages from valgrind when it prints out stack traces of allocations. Thanks to this flag you see more information in stack traces like exact function names of functions you coded.

    What wiki says. It says about any libraries which your code links with. E.g. you link with boost Stacktraces may include also function calls coming from boost. In order to have in stacktraces also more debug information about function names from boost you need to link with boost compiled with debug symbols.

    What you found on wiki is an advice, that if you link with e.g. some library from xserver-xorg-core, then it may be good for you to install also xserver-xorg-core-dbg, link with it and run such a linked app under valgrind. Your stacktraces will then look nicer even in parts not coded by you but only used by you from libraries provided by xserver-xorg-core(-dbg). That's all.

    The page they reference says:

    If you want to debug a crash from an application provided by Ubuntu, you are developing yourself, provided by a third-party, or need the debug symbols for particular libraries very often, it is helpful to install the relevant debugging packages.

    For many, but not all, packages, one can simply add a -dbg suffix to the package name to install it. For example:

    sudo apt-get install xserver-xorg-core-dbg

    This means the same what I wrote. I just tried to elaborate more.