James
James

Reputation: 25523

How do I get a stack backtrace from a tracepoint? (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?

Upvotes: 5

Views: 1111

Answers (2)

Emilien
Emilien

Reputation: 2445

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.

Upvotes: 1

James
James

Reputation: 25523

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

Upvotes: 7

Related Questions