继续在Linux上断言失败后调试? [英] Continue to debug after failed assertion on Linux?

查看:510
本文介绍了继续在Linux上断言失败后调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当一个断言失败,在Windows上,调试器停止时,Visual C ++显示消息,然后让你继续(或者,如果没有调试会话运行时,提供了推出的Visual Studio你)。

When an assertion fails with Visual C++ on Windows, the debugger stops, displays the message, and then lets you continue (or, if no debugging session is running, offers to launch visual studio for you).

在Linux上,似乎断言的默认行为()是显示错误和退出程序。因为我所有的断言通过宏,我试图用信号来解决这个问题,像

On Linux, it seems that the default behavior of assert() is to display the error and quit the program. Since all my asserts go through macros, I tried to use signals to get around this problem, like

#define ASSERT(TEST) if(!(TEST)) raise(SIGSTOP);

不过,虽然 GDB (通过的 KDevelop的)停在正确的点,我似乎无法继续过去的信号,手动发送信号中GDB只是让我挂,与控制既不GDB也不是调试过程。

But although GDB (through KDevelop) stops at the correct point, I can't seem to continue past the signal, and sending the signal manually within GDB just leaves me hanging, with control of neither GDB nor the debugged process.

推荐答案

您真的要重现行为的的DebugBreak 。这将停止该程序在调试器。

You really want to recreate the behavior of DebugBreak. This stops the program in the debugger.

我的DebugBreak LINUX的谷歌搜索止跌回升几个 <一个href=\"http://www.unix.com/high-level-programming/38082-win32-vc-debugbreak-linxu.html\">references这片内联汇编的这是应该做的是一样的。

My googling of "DebugBreak linux" has turned up several references to this piece of inline assembly which is supposed to do the same.

#define DEBUG_BREAK asm("int $3")

那么你的断言可以成为

Then your assert can become

#define ASSERT(TEST) if(!(TEST)) asm("int $3");

Andomar INT 3使CPU来提高中断3,根据 drpepper 一个更便携的方式做这将是拨打:

According to Andomar int 3 causes the cpu to raise interrupt 3. According to drpepper a more portable way to do this would be to call:

 raise(SIGTRAP);

这篇关于继续在Linux上断言失败后调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆