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

后端 未结 10 1173
野性不改
野性不改 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:41

    GCC has a builtin function named __builtin_trap which you can see here, however it is assumed that code execution halts once this is reached.

    you should ensure that the __builtin_trap() call is conditional, otherwise no code will be emitted after it.

    this post fueled by all of 5 minutes of testing, YMMV.

提交回复
热议问题