When I debug, sometimes itβs useful for me to βreplayβ the last few code statements. For instance:
void foo (int & i) { i = 0; ++i; i++; }
When you run this through the debugger, you can add a breakpoint at the top of the function body, and then from any statement inside foo , if you type: "jump file.cc:2" the debugger will go back to i = 0 . I appreciate that this is not always perfect, but sometimes it may be enough to find the error you are looking for.
I am currently studying a problem that throws an exception. The exception is the bottom of the called function, so something like:
void bar () { throw int (); } void foo (int & i) { i = 0; ++i; bar (); i++; } int main () { try { int i; foo (i); } catch (...) { } }
What I want to do is to set a breakpoint before throw int () , then jump over this statement, end the function panel so that I can then return to line i = 0 in Foo.
Is there a way I can jump over throw int () or end from bar without executing the throw statement?
The problem is that after throw there is no instruction, so I have nowhere to put a breakpoint on which I want to go.
UPDATE:
To emphasize what happens in my simple example above:
This GDB was configured as "i486-slackware-linux"... (gdb) break bar Breakpoint 1 at 0x804856a: file t.cc, line 3. (gdb) run Starting program: ..../t Breakpoint 1, bar () at t.cc:3 (gdb) break t.cc:4 Breakpoint 2 at 0x8048592: file t.cc, line 4. (gdb) jump t.cc:4 Line 4 is not in `bar()'. Jump anyway? (y or n) y Continuing at 0x8048592. Breakpoint 2, foo ( i=@0xb80155eb ) at t.cc:6
Closing the cursor for "bar" is on line 4 of "t.cc", however gdb considers this a breakpoint for foo .