When I'm debugging, I sometimes find it useful to "replay" the last few statements of code. For example:
void foo (int & i) {
i = 0;
++i;
i++;
}
While running this through the debugger, you can add a breakpoint at the top of the function body, and then from any statement inside of foo
if you type: "jump file.cc:2" the debugger will return back to i = 0
. I appreciate that this isn't always perfect, but sometimes it can be enough to find the bug you're searching for.
I'm currently investigating a problem that results in an exception being thrown. The exception is being thrown at the bottom of a called fucntion, 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 be able to do, is to put a breakpoint before throw int ()
, then to jump over just that statement, finish the function bar - so that I can then jump back up to the i = 0
line in foo.
Is there a way I can jump past throw int ()
, or finish out of bar
without executing the throw statement?
The problem appears to be that there's no statement after the throw
so I have nowhere to put the breakpoint I want to jump to.
UPDATE:
To highlight 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
The close curly for 'bar' is on line 4 of 't.cc', however gdb considers this as a breakpoint for foo
.