gdb: step over throw statement in C++

北战南征 提交于 2019-12-12 17:22:50

问题


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 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.



来源:https://stackoverflow.com/questions/34595588/gdb-step-over-throw-statement-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!