[SOLVED] Getting valgrind debug symbols to work properly in Debian
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Getting valgrind debug symbols to work properly in Debian
Edit: You'll probably want to skip to post #7 /Edit
About 6 months ago I decided to make a little gtkmm application. I ran valgrind on the first tutorial example (here's a link, but the code is totally irrelevant to the question): https://developer.gnome.org/gtkmm-tu...xample.html.en
and found that it "definitely lost" 16 kb, and much more with big GUIs. So I thought maybe I'd try to get to the bottom of it. But the valgrind output looks sketchy and starts with a bunch of errors:
Code:
--22792-- WARNING: Serious error when reading debug info
--22792-- When reading debug info from /lib/x86_64-linux-gnu/ld-2.22.so:
--22792-- Ignoring non-Dwarf2/3/4 block in .debug_info
I'm running Debian sid and just updated (which puts me at valgrind 1:3.11.0-1+b1), and still get the errors. I'm not the best C programmer in the world, and can't really figure out what they're talking about in those threads. Is this a patch I can apply? Do I have to download the latest code and compile, or is there a more clever fix?
And is valgrind not as popular as I thought? Seems like people would be bellyaching about this a lot more. Thanks for any input, and sorry if I'm being dense about something.
Last edited by crazy-yiuf; 06-27-2016 at 01:14 PM.
Ok, I read it better and it looks like I just need to compile it, bleh. Sorry for the dumb post, I'll mark it as solved until I inevitably can't get it to work, or just give up for another six months.
apt-get source valgrind
patch -p0 < thepatch
cd valgrind-3.11.0/
dpkg-buildpackage -us -uc
apt-get install #any dependencies it complains about in the previous step
dpkg-buildpackage -us -uc
#this took about an hour on my old 1ghz processor
cd ..
dpkg -i valgrind_3.11.0-1.1_amd64.deb
dpkg -i valgrind-dbg_3.11.0-1.1_amd64.deb
dpkg -i valgrind-mpi_3.11.0-1.1_amd64.deb
And now I know how to patch and rebuild packages on Debian! Unfortunately, the output isn't all that much more useful, so I guess that's why it hasn't urgently been pushed into the repos.
Last edited by crazy-yiuf; 06-25-2016 at 01:22 AM.
which on google seems to be related to mangled versions? Though I see these mismatches showing up a lot of other places too. So I uninstalled the three packages, and verified that "which valgrind" didn't find anything. Then I installed the manually built debs and did a stat /usr/bin/valgrind:
Unmodified since 2015?? Where is it pulling this binary from? I guess it's possible that the makefile didn't deem it necessary to change the main binary, in which case, why the CRC mismatch?
After some digging, I've found that buildpackage uses debhelper, which sets the mtime of all package files to the latest date in the change log. The latest date in the valgrind change log is Sept. 25, 2015
I'm satisfied with my valgrind now. Now to track down the rest of the debug symbols. Also for future googlers I feel I should say "modify time timestamp wrong binary buildpackage deb mtime"
"modify time timestamp wrong binary buildpackage deb mtime"
valgrind is a wrapper script that the compiler doesn't modify:
Code:
$ cat /usr/bin/valgrind
#!/bin/sh -e
#
# Valgrind wrapper
# Default Debian debug libraries.
DBGPATH=/usr/lib/debug
# Use debug libraries if found.
if [ -z "$LD_LIBRARY_PATH" ]; then
export LD_LIBRARY_PATH="$DBGPATH"
else
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$DBGPATH"
fi
# Force C++ STL to use malloc and to free memory by disabling
# memory caching.
# For gcc < 3.4 versions
export GLIBCPP_FORCE_NEW=1
# For gcc >= 3.4 versions
export GLIBCXX_FORCE_NEW=1
# Use 'exec' to avoid having another shell process hanging around.
exec $0.bin "$@"
Ah. Right you are. I really should have thought of that. Thanks!
I'm stuck again, though. I'm back to my gtkmm hello world program. I went through and installed all of the -dbg and -dbgsym packages I could find for these:
Code:
echo `pkg-config gtkmm-3.0 --cflags --libs`
And I still get::
Code:
valgrind -v --leak-check=full --track-origins=yes ./a.out
...
==14373== 16,384 bytes in 1 blocks are definitely lost in loss record 10,453 of 10,465
==14373== at 0x4C29C0F: malloc (vg_replace_malloc.c:299)
==14373== by 0x8671728: g_malloc (gmem.c:94)
==14373== by 0x867B8CB: g_quark_init (gquark.c:62)
==14373== by 0x400F2D9: call_init.part.0 (dl-init.c:72)
==14373== by 0x400F3EA: call_init (dl-init.c:30)
==14373== by 0x400F3EA: _dl_init (dl-init.c:120)
==14373== by 0x4000CC9: ??? (in /lib/x86_64-linux-gnu/ld-2.22.so)
==14373==
==14373== LEAK SUMMARY:
==14373== definitely lost: 16,384 bytes in 1 blocks
==14373== indirectly lost: 0 bytes in 0 blocks
==14373== possibly lost: 8,040 bytes in 103 blocks
==14373== still reachable: 1,891,323 bytes in 20,689 blocks
==14373== of which reachable via heuristic:
==14373== length64 : 35,320 bytes in 460 blocks
==14373== newarray : 2,384 bytes in 69 blocks
==14373== suppressed: 0 bytes in 0 blocks
==14373== Reachable blocks (those to which a pointer was found) are not shown.
==14373== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==14373==
==14373== ERROR SUMMARY: 70 errors from 70 contexts (suppressed: 0 from 0)
==14373== ERROR SUMMARY: 70 errors from 70 contexts (suppressed: 0 from 0)
I'm new to valgrind, but here I'm assuming:
1. The ??? is what I really need to find the leak?
2. The ??? is caused by a library being compiled without debug information?
3. There's probably some other method for figuring out which executable it came from even without the debug symbols? Maybe gdb?
If I'm interpreting the valgrind -v correctly, I'm still missing the debug symbols for these:
libxkbcommon0
libepoxy0
libdbus-1-3
liblzma5
also valgrind-dbg apparently doesn't have a dynamic symbol table, but I doubt that's related.
Last edited by crazy-yiuf; 06-26-2016 at 08:22 PM.
Ah. Right you are. I really should have thought of that. Thanks!
I'm stuck again, though. I'm back to my gtkmm hello world program. I went through and installed all of the -dbg and -dbgsym packages I could find for these:
Code:
echo `pkg-config gtkmm-3.0 --cflags --libs`
And I still get::
Code:
valgrind -v --leak-check=full --track-origins=yes ./a.out
...
==14373== 16,384 bytes in 1 blocks are definitely lost in loss record 10,453 of 10,465
==14373== at 0x4C29C0F: malloc (vg_replace_malloc.c:299)
==14373== by 0x8671728: g_malloc (gmem.c:94)
==14373== by 0x867B8CB: g_quark_init (gquark.c:62)
==14373== by 0x400F2D9: call_init.part.0 (dl-init.c:72)
==14373== by 0x400F3EA: call_init (dl-init.c:30)
==14373== by 0x400F3EA: _dl_init (dl-init.c:120)
==14373== by 0x4000CC9: ??? (in /lib/x86_64-linux-gnu/ld-2.22.so)
==14373==
==14373== LEAK SUMMARY:
==14373== definitely lost: 16,384 bytes in 1 blocks
==14373== indirectly lost: 0 bytes in 0 blocks
==14373== possibly lost: 8,040 bytes in 103 blocks
==14373== still reachable: 1,891,323 bytes in 20,689 blocks
==14373== of which reachable via heuristic:
==14373== length64 : 35,320 bytes in 460 blocks
==14373== newarray : 2,384 bytes in 69 blocks
==14373== suppressed: 0 bytes in 0 blocks
==14373== Reachable blocks (those to which a pointer was found) are not shown.
==14373== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==14373==
==14373== ERROR SUMMARY: 70 errors from 70 contexts (suppressed: 0 from 0)
==14373== ERROR SUMMARY: 70 errors from 70 contexts (suppressed: 0 from 0)
I'm new to valgrind, but here I'm assuming:
1. The ??? is what I really need to find the leak?
2. The ??? is caused by a library being compiled without debug information?
3. There's probably some other method for figuring out which executable it came from even without the debug symbols? Maybe gdb?
4.1. My program uses the C++ STL and string classes. Valgrind reports 'still reachable' memory leaks involving these classes at the exit of the program, but there should be none.
First of all: relax, it's probably not a bug, but a feature. Many implementations of the C++ standard libraries use their own memory pool allocators. Memory for quite a number of destructed objects is not immediately freed and given back to the OS, but kept in the pool(s) for later re-use. The fact that the pools are not freed at the exit of the program cause Valgrind to report this memory as still reachable. The behaviour not to free pools at the exit could be called a bug of the library though.
Yeah, I'd ignore it if it was anything other than "definitely lost". There's a good chance you're right, but I'm going to try to prove it to myself as a learning exercise. Thanks though, any more thoughts are also appreciated.
I should have noted that I've been running with:
export G_SLICE=always-malloc
export G_DEBUG=gc-friendly
export NO_AT_BRIDGE=1
I don't have gnome installed, so the NO_AT_BRIDGE is to suppress this sort of error (which it manages to do about half the time):
Code:
** (synaptic:16706): WARNING **: Error retrieving accessibility bus address: org.freedesktop.DBus.Error.ServiceUnknown: The name org.a11y.Bus was not provided by any .service files
Also I'm compiling with:
g++ -gdwarf-4 `pkg-config gtkmm-3.0 --cflags --libs` main.cpp
Edit: export GLIBCXX_FORCE_NEW didn't make a difference.
Edit: Spent the day updating an old Kali installation, so I could try it in a full gnome environment. Exact same number - 16,384.
Last edited by crazy-yiuf; 06-27-2016 at 11:22 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.