2

Here I want to ask this question. When I am debugging a program, sometimes I wish I can run a previous instruction again. Like in Microsoft Visual Studio, we can drag the position indicator (remember the yellow arrow) to the previous instruction you want to locate.

For example:

My program is currently at line 72, and suppose line 70 is in the same function that line 72 sits in. Now I want to re-run line 70 again. Is there any way to do that?

Thanks.

Dan Fego
  • 13,644
  • 6
  • 48
  • 59
Xi Duan
  • 93
  • 1
  • 9

3 Answers3

5

I want to re-run line 70 again

Use the GDB jump command.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
1

You can normally call functions within gdb with the call command:

(gdb) call some_function(arg1, arg2);

However, if you want to specifically go back the program, you could always find the memory location of the line in question and set the instruction pointer to it.

(gdb) set $eip = <some memory address>

That being said, I don't know of a way to fully "unwind" the program's state, if that's what Visual Studio does. In other words, any other program state may be different the second time through.

Dan Fego
  • 13,644
  • 6
  • 48
  • 59
  • I don't think Visual Studio totally unwind the variables. However, I tried reverse-*, that work well for me expect the `target record` thing. Otherwise, the message of "Target child does not support this command." is thrown. Any way to set `target record` in advance? – Xi Duan Jan 17 '12 at 05:50
0

Use gdb command jump, e.g.:

jump 70
eyllanesc
  • 235,170
  • 19
  • 170
  • 241