在GDB中运行应用程序,直到发生exception

我正在开发一个multithreading应用程序,我想用GDB进行debugging。

问题是,我的一个线程不断死讯:

pure virtual method called terminate called without an active exception Abort 

我知道这个消息的原因,但我不知道我的线程在哪里发生。 回溯真的会有所帮助。

当我在GDB中运行我的应用程序时,每次线程暂停或恢复时都会暂停。 我希望我的应用程序能够继续正常运行,直到其中一个线程死亡,此时,所有事情都应该停止,以便我可以回溯。

您可以尝试使用“catchpoint”( catch throw )在生成exception的地方停止debugging器。

以下摘录从gdb手册描述了catchpointfunction。


5.1.3设置捕点

您可以使用catchpoints使debugging器停止某些types的程序事件,例如C ++exception或加载共享库。 使用catch命令设置一个入口点。

  • 赶上事件

    事件发生时停止。 事件可以是以下任何一种:

    • 抛出一个C ++exception。

    • 抓住

      捕捉一个C ++exception。

    • EXEC

      致电exec。 目前这仅适用于HP-UX。

    • 叉子

      拨打电话。 目前这仅适用于HP-UX。

    • vfork的

      打电话给vfork。 目前这仅适用于HP-UX。

    • 加载加载libname

      任何共享库的dynamic加载,或者库libname的加载。 目前这仅适用于HP-UX。

    • 卸载卸载libname

      卸载任何dynamic加载的共享库,或者卸载库libname。 目前这仅适用于HP-UX。

  • tcatch事件

    设置仅启用一个停靠点的一个引导点。 捕获点首次被捕获后自动删除。

使用info break命令列出当前的catchpoints。

GDB中的C ++exception处理(catch catch和catch catch)目前有一些限制:

 * If you call a function interactively, GDB normally returns control to you when the function has finished executing. If the call raises an exception, however, the call may bypass the mechanism that returns control to you and cause your program either to abort or to simply continue running until it hits a breakpoint, catches a signal that GDB is listening for, or exits. This is the case even if you set a catchpoint for the exception; catchpoints on exceptions are disabled within interactive calls. * You cannot raise an exception interactively. * You cannot install an exception handler interactively. 

有时catch不是debuggingexception处理的最佳方式:如果您需要知道exception的确切位置,最好在调用exception处理程序之前停止,因为这样可以在任何展开之前看到堆栈。 如果您在exception处理程序中设置断点,则可能不容易找出引发exception的位置。

要在exception处理程序被调用之前停止,您需要一些实现知识。 在GNU C ++的情况下,通过调用名为__raise_exception的库函数来引发exception,该函数具有以下ANSI C接口:

 /* addr is where the exception identifier is stored. id is the exception identifier. */ void __raise_exception (void **addr, void *id); 

要使debugging器在任何堆栈展开之前捕获所有exception,请在__raise_exception上设置断点(请参见断点;观察点和exception部分)。

使用依赖于id值的条件断点(请参见断点条件部分),可以在发生特定exception时停止程序。 当引发任何一个exception时,您可以使用多个条件断点来停止您的程序。

在__pure_virtual上设置一个断点

FWIW,显然,在gcc 4.1中,相应的函数名称已经改变,必须在这个函数中设置一个断点。

__cxa_pure_virtual