Is it possible in gdb to go to a line before the currently executing line. e.g:
void my_fun( somePtrType** arr,int start,int end)
{
// arr is an array of p
Yes! With the new version 7.0 gdb, you can do exactly that!
The command would be "reverse-step
", or "reverse-next
".
You can get gdb-7.0 from ftp.gnu.org:/pub/gnu/gdb
If you run into the error: Target child does not support this command.
then try adding target record
at the beginning of execution, after starting run
.
Edit: Since GDB 7.6 target record
is deprecated, use target record-full
instead.
Yes, it is possible, and straightforward, now, with real hardware (ie. not just with a VM). GDB-7.0 supports reverse debugging with commands like reverse-step and reverse-continue, on native linux x86 machines.
There is a tutorial here: http://www.sourceware.org/gdb/wiki/ProcessRecord/Tutorial
If your setup code for arr is just above "line a" (a very commonly scenario), you can do it like this:
tbreak myfilename.c:123
(line 123 is the start of setup code for arr) then
jump 123
The "tbreak" prevents gdb from continuing (resuming) the program after the jump.
then you can step through the setup code or just set a breakpoint at "line a" and continue