Is there a portable equivalent to DebugBreak()/__debugbreak?

后端 未结 10 1170
野性不改
野性不改 2020-12-01 08:49

In MSVC, DebugBreak() or __debugbreak cause a debugger to break. On x86 it is equivalent to writing \"_asm int 3\", on x64 it is something different. When compiling with gcc

10条回答
  •  再見小時候
    2020-12-01 09:24

    This seems to be a very good, portable solution to this question: https://github.com/scottt/debugbreak

    The header provided in the repository cited (debugbreak.h) encapsulates MSVC's

        __debugbreak, 
    

    and

        __asm__ volatile("int $0x03");
    

    on i386 and x86_64, and on ARM it implements

        __asm__ volatile(".inst 0xe7f001f0");
    

    as well as documenting some workarounds for problems noted in the header for single-stepping past the breakpoint in GDB plus a Python script for extending GDB on those platforms where stepi or cont get stuck. The script adds debugbreak-step and debugbreak-continue to GDB.

提交回复
热议问题