Valerio Santinelli
Valerio Santinelli

Reputation: 1702

Tracing instructions with GDB Python scripting

I am trying to write a Python script for GDB to trace a function.

The idea is to set a breakpoint on an address location, let the program run and then, when it breaks, log to file registers, vectors and stack and find out what address the next instruction will be, set a breakpoint on that location and rinse and repeat.

I read through the documentation and I'm pretty confident registers, vectors and memory locations can be easily dumped. The actual problem is finding what the next instruction location will be as it requires to analyze the disassembly of the current instruction to determine where the next breakpoint should be placed.

Update

I am doing all this without using stepi or nexti because the target I'm debugging works only with hardware breakpoints and as far as I know those commands use software breakpoints to break at the next instruction

Is there anything like that in GDB?

Upvotes: 0

Views: 573

Answers (1)

Tom Tromey
Tom Tromey

Reputation: 22519

Yes, you can do this in gdb. Rather than trying to set a breakpoint on the next instruction, you can instead use the si command to single-step to the next instruction.

Upvotes: 0

Related Questions