Reputation: 79
Sometimes in GDB I want to see the control flow that got the program to where it is now. Simply put, how do I make GDB print the last x lines executed?
Upvotes: 3
Views: 6747
Reputation: 35716
This is yet another use case for Reverse Debugging.
You should start process record and replay at some point:
(gdb) record
When you want to see last executed lines you can go backwards like this:
(gdb) reverse-step 3
or
(gdb) reverse-next 3
Upvotes: 5
Reputation: 1
You simply cannot do that (easily) in gdb
, because the execution trace of any program is not kept (and keeping it would be very expensive : it would slow down a lot the execution, and it would use a lot of resources - memory & disk space).
You can however use the backtrace
or bt
command of gdb
to show the call stack, that is the current instruction pointer in the current function, the calling function, the calling function of the calling function, and so forth
BTW, if you really wanted it, you might script recent gdb
using Python or Guile to give you such information. You certainly could keep the entire trace (by scripting around the step
& backtrace
functionalities).
Upvotes: 2