tags:

views:

708

answers:

7
A: 

Currently: no.

In the future: yes, according to that page.

Edit: on that note, just put your breakpoint 1 line earlier if you have a specific line in mind ahead of time. If your program is single-threaded then you should also just be able to run it a second time and get the same results, if you don't know (the first time) which line you want to break at.

Matt Ball
+2  A: 

according to http://sourceware.org/gdb/current/onlinedocs/gdb.html#SEC51 , and "if the target environment supports it", yes.

ax
AFAIU, reverse debugging has been implemented in GDB CVS Head for Linux/i386 and x86_64 targets.
Employed Russian
+2  A: 

If your program is short, the usual trick is,

  1. Place a new breakpoint at the previous line
  2. fire r to restart the debug

GDB was made to do that!

nik
A: 

Everyone wishes for a Omniscient Debugger like this one: http://www.lambdacs.com/debugger/, but they are (depending on the language/machine) difficult to make and have a lot of bookkeeping to do.

At the moment on real hardware and not in a VM, it is close to impossible to do it.

Tobias Langner
A: 

Short answer: No.

For workaround read below.

Though at line b it is not possible to determine the value at line a, it is possible to log the value of arr at a and b and other locations by only one breakpoint being hit.

  • Use the "display" command (*display variable_name* where variable_name is to be replaced with arr, *arr, **arr depending on what you are looking for) so that when any breakpoint is hit, the contents of the variable_name will be dumped on to the screen. Note that you can add to the display list when the variabe_name is in scope so that may require you to wait for your first breakpoint.
  • Create breakpoints at various locations of code where you are interested to log the value of variable_name. One such breakpoint would be at line a.
  • For each breakpoint, use command (*command breakpoint_number*) and instruct your breakpoint to not halt the execution of the program. The command that you need to use is continue followed by end. See example below.

(gdb) command 1

Type commands for when breakpoint 1 is hit, one per line. End with a line saying just "end".

continue

end

  • Put a breakpoint on line b.

Now when all other logging breakpoints are hit, the value of arr will be dumped on the screen but the breakpoint won't wait for user interaction and will auto-continue. When you hit a breakpoint at line b, you can see the past values of arr which would be logged in gdb itself.

Depending on the situation you can also dump (and display) a lot of useful information. For example you may also want to dump a loop counter (say i) if the above function is called 10000 times in a loop. That really depends on what you are trying to achieve.

tc
-1: It is possible with the new feature of gdb
Phong
Delete the -1 (didn't notice the date of the post which was before the new version of gdb was release)
Phong
+4  A: 

Yes! With the new version 7.0 gdb (just released this week), 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

Michael Snyder
.........cool:D
Neeraj
The command exists, but here "the target child does not support it" =(Voted up anyways. ;)
freitass
+2  A: 

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

Michael Snyder