Reputation: 8160
So when glibc crashes, it has a *glibc detected * crash message. It then prints a bunch of backtraces, like
*** glibc detected *** ./odin: free(): invalid pointer: 0xbfba4444 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(+0x6b161)[0xb75f9161]
/lib/tls/i686/cmov/libc.so.6(+0x6c9b8)[0xb75fa9b8]
/lib/tls/i686/cmov/libc.so.6(cfree+0x6d)[0xb75fda9d]
/usr/lib/libstdc++.so.6(_ZdlPv+0x1f)[0xb77da2ef]
All well and good, but other cases when things crash, I've been doing backtrace() and then using a system call to addr2line and printing the actual points in the function instead. But when it's a glibc crash, it quits bypassing any signal handlers I called.
Is there a way to hook against these glibc crashes?
Upvotes: 3
Views: 942
Reputation: 153
IIRC, glibc actually invokes abort()
, so handling SIGABRT
and printing a backtrace from that should give you the information you need.
However, I'd suggest trying valgrind: the message you're getting suggests that you have a memory corruption problem.
Side comment (sorry if this is redundant ;-)): core dumps are sometimes more useful that just backtraces. They can be enabled by e.g. setting ulimit -c unlimited
in bash. When the program crashes it will produce a file named core.
(or just core
-- this depends on the system you're running; if your system runs abrtd core files are put into /var/cache/abrt
if I'm not mistaken). Then you can inspect core files using gdb by running gdb -c core a.out
; the gdb session will look like as if the process just have crashed.
Upvotes: 3
Reputation: 7160
That is an option for memory functions, you can toggle it using mallopt
. By the sounds of it you want to set M_CHECK_ACTION
to zero to allow execution to continue, unless you want the program to exit straight away in which case see if 2
allows you to do what you want.
This small program produces the normal glibc error: test1.c
This one ignores the error and carries on: test2.c
This one aborts on the error: test3.c
Upvotes: 3