Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Valgrind (below main), how to get full stack trace?

I have the following stack trace from valgrind. But it does not give me the full stack trace.

==2433== Invalid free() / delete / delete[] / realloc()
==2433==    at 0x402B06C: free (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2433==    by 0x43F345B: av_freep (mem.c:172)
==2433==    by 0x5A6F4D2: (below main) (libc-start.c:226)

In gdb, I think I get the same error:

#5  0xb7c1345c in av_free (ptr=<optimized out>) at libavutil/mem.c:172
#6  av_freep (arg=0x88a2e48) at libavutil/mem.c:181
#7  0xb7c165c8 in av_opt_free (obj=0x88a2ba0) at libavutil/opt.c:787
#8  0xb6b56efc in avcodec_close (avctx=0x88a2ba0) at libavcodec/utils.c:1675
#9  0x0808a3e0 in encode_lavc_finish (ctx=0x8343a40) at encode_lavc.c:288
#10 0x08077d0b in exit_player_with_rc (mpctx=0x8313058, how=EXIT_EOF, rc=0)
at mplayer.c:705
#11 0x0806ced0 in main (argc=8, argv=0xbffff374) at mplayer.c:4771 

But with the gdb trace goes all the way up to main().

How do I get the full stack trace in valgrind, is at all possible?

like image 717
rhlee Avatar asked Oct 07 '22 12:10

rhlee


1 Answers

In gdb, I think I get the same error

You didn't get an error in GDB. You got a breakpoint on av_free, but surely av_free is called a lot, and you've provided no evidence that this particular call is the one that triggers Valgrind error.

It's very likely that some other call to av_free is in fact triggering the Valgrind error, and it's also very likely that that call is executing from atexit handler, the Valgrind stack is in fact a full stack trace.

If you are using a recent version of Valgrind, you can actually debug the program running under Valgrind with --vgdb-error=1, and attach GDB exactly where the problem happens. Documentation here.

like image 158
Employed Russian Avatar answered Oct 10 '22 07:10

Employed Russian