How to go to the previous line in GDB?

前端 未结 9 773
北荒
北荒 2020-11-29 16:33

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         


        
相关标签:
9条回答
  • 2020-11-29 17:30

    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.

    0 讨论(0)
  • 2020-11-29 17:33

    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

    0 讨论(0)
  • 2020-11-29 17:36

    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

    0 讨论(0)
提交回复
热议问题