emkey08
emkey08

Reputation: 6161

Step over a C++ throw statement in GDB

When debugging a C++ program with the GNU GDB debugger, I can step over the next line of code with the GDB command:

next

However, when an exception is thrown within that next line, like e.g.

throw SomeException();

then GDB continues to run until the next breakpoint instead of stopping within the first line of the catch block.

Is this a bug within GDB, or am I just using the wrong command?

I'm using GDB version 7.7 on MinGW32 / Windows.

Upvotes: 2

Views: 538

Answers (1)

Tom Tromey
Tom Tromey

Reputation: 22519

On Linux this works properly. In particular there is a special debugging marker (either a function or an "SDT probe", depending on how things were built) in the low-level unwinding code that is used when an exception is thrown. GDB puts a breakpoint at this spot. When this breakpoint is hit, GDB examines the target stack frame of the throw and, if it is above the nexting frame, puts a temporary breakpoint at the target of the throw.

This required some changes in GDB, but also some changes in the C++ runtime in order to inform GDB about throws. As far as I know, nobody has ever done the work to port this code to MinGW. Maybe it could be done by modifying the appropriate unwind-mumble.c file in the GCC sources.

Upvotes: 5

Related Questions