Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a stack backtrace from a tracepoint? (GDB)

Tags:

debugging

gdb

According to these docs it isn't possible to get a complete stack backtrace from a tracepoint, but it is possible to get a partial trace by recording a section of the stack.

How do I go about doing this?

like image 896
James Avatar asked Feb 14 '11 12:02

James


2 Answers

I've approximated the behaviour I wanted using commands on a breakpoint to print a backtrace then auto-continue:

> break functionName
> commands
> bt
> continue
> end
like image 85
James Avatar answered Oct 01 '22 20:10

James


For future reference, I just found something related to this in the gdb documentation 13.1.10 tracepoint restrictions which says that it is not possible to collect the result of the backtrace command in a tracepoint, but it's possible to collect the stack by reading something like *(unsigned char *)$esp@300. You'll probably need to adapt a little bit: you may need to read more bytes, and the stack pointer may have a different name (rsp for x86-64) Otherwise:

>collect *(unsigned char *)$esp@300
'esp' is a pseudo-register; GDB cannot yet trace its contents.
like image 27
Emilien Avatar answered Oct 01 '22 21:10

Emilien