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

后端 未结 10 1145
野性不改
野性不改 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条回答
  •  -上瘾入骨i
    2020-12-01 09:37

    #define __debugbreak() \
    do \
    {       static bool b; \
            while (!b) \
                    sleep(1); \
            b = false; \
    } while (false)
    

    When the process is sleeping, you can attach a debugger to the process, change the variable b to break the loop and do your thing. This code might not work in an optimized build!

提交回复
热议问题