Continue to debug after failed assertion on Linux?

前端 未结 5 725
萌比男神i
萌比男神i 2020-12-29 07:57

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 l

5条回答
  •  一向
    一向 (楼主)
    2020-12-29 08:06

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

    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");
    

    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);
    

提交回复
热议问题