问题
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.
回答1:
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 next
ing 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 throw
s. 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.
来源:https://stackoverflow.com/questions/34595588/gdb-step-over-throw-statement-in-c