0
votes

I am working on some rather large C++ app, with most of the code being stored in a static library, and some programs that use that code. I have what looks like a memory corruption run-time crash:

*** Error in `build/bin/myapp': malloc(): memory corruption (fast): 0x00000000021f62a0 ***

I want to check where that happens. GDB seems the right tool (OS: Ubuntu 14.04).

My makefiles handles both debug and release with a makefile command-line switch.

With the switch on, the -g flag is added and the .a library is 23.8 MB, while the app is 519 kB. Without, its 1.6 MB and 486kB (so I'm pretty sure the debugging symbols are there).

My (partial) CFLAGS, as suggested by the gcc manual: CFLAGS = -std=c++11 -g -Wall -O0 -fno-inline

I run gdb with:

gdb --args build/bin/myapp datafile.dat -a -b (...and more arguments)

My problem is that even in the debug build, gdb keeps telling me that it can't find any symbols:

Reading symbols from build/bin/myapp...(no debugging symbols found)...done.

If I run it from within gdb, it crashes with:

Program received signal SIGABRT, Aborted.
0x00007ffff5298cc9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
56  ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.

And the backtrace command shows indeed that symbols are missing: frames 10 to 18 have missing information, and are probably related to my code:

(gdb) bt
#0  0x00007ffff5298cc9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x00007ffff529c0d8 in __GI_abort () at abort.c:89
#2  0x00007ffff52d5394 in __libc_message (do_abort=do_abort@entry=1, fmt=fmt@entry=0x7ffff53e3b28 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/posix/libc_fatal.c:175
#3  0x00007ffff52e00f7 in malloc_printerr (action=<optimized out>, str=0x7ffff53e3ec8 "malloc(): memory corruption (fast)", ptr=<optimized out>) at malloc.c:4996
#4  0x00007ffff52e2e04 in _int_malloc (av=0x7ffff5620760 <main_arena>, bytes=36) at malloc.c:3359
#5  0x00007ffff52e47b0 in __GI___libc_malloc (bytes=36) at malloc.c:2891
#6  0x00007ffff5babe68 in operator new(unsigned long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#7  0x00007ffff5c03e69 in std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#8  0x000000000045a7a5 in char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) ()
#9  0x00007ffff5c05bd6 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) ()
   from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#10 0x000000000042df7f in ?? ()
#11 0x000000000042eef6 in ?? ()
#12 0x0000000000421dab in ?? ()
#13 0x0000000000422223 in ?? ()
#14 0x0000000000422cfe in ?? ()
#15 0x0000000000423393 in ?? ()
#16 0x0000000000424600 in ?? ()
#17 0x000000000040fd50 in ?? ()
#18 0x000000000040566d in ?? ()
#19 0x00007ffff5283ec5 in __libc_start_main (main=0x4053c0, argc=6, argv=0x7fffffffddf8, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, 
    stack_end=0x7fffffffdde8) at libc-start.c:287
#20 0x000000000040604f in ?? ()

I did check some of the many questions about this topic, but none of any help (most of these relate to a forgotten -g flag, or an added -s, stripping down the symbols).

Question: what can the next step be to find out why/where my crash happens?

Additional info:

  • gcc --version: 5.3.0
  • gdb --version: 7.7.1
  • code dependencies: boost and opencv
1
did you strip the executable? This removes debug info.Richard Hodges
Look at the output from make, it shows all commands being executed with all flags. Does it show the -g flag when building? It doesn't show the -s flag when linking? Or using the strip command?Some programmer dude
Thanks guys, but every build step is logged to console, and yes, its perfectly fine, -g and no -s, I checked that at first (see my CFLAGS).kebs
Ouch ! Sorry guys! Had a HARD CODED -s in my link make recipe (out of my LDFLAGS). Turns out it stripped everything!!! Fixed now, I'll probably erase this...kebs
Just FYI, for memory corruption problems you will generally find the bug faster with valgrind than with gdb.Tom Tromey

1 Answers

1
votes

but none of any help (most of these relate to a forgotten -g flag, or an added -s, stripping down the symbols).

It is almost certain that you either have a stray -s somewhere on your link line, or you run stip on the binary during installation.

Look at your link command line and install command carefully, there is strip somewhere in there.

P.S. As Tom Tromey already said, GDB is rarely effective in helping with a problem like this. Using Valgrind or Address Sanitizer will likely get you to the root cause much faster.