本文介绍了是否有一个可移植的等同于DebugBreak()/ __ debugbreak?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MSVC中,或导致调试器中断。在x86它相当于写_asm int 3,在x64它是不同的东西。当用gcc(或任何其他标准编译器)编译时,我也想做一个调试器。有平台独立的功能还是内在的?我看到了,但它没有



Sidenote:我主要想实现ASSERT,我理解我可以使用assert(),但我也想写DEBUG_BREAK


解决方案

基于#ifdef定义一个条件宏如何根据当前的架构或平台。



像:

  #ifdef _MSC_VER 
#define DEBUG_BREAK __debugbreak()
#else
...
#endif

这将由预处理器根据编译代码的平台扩展正确的调试器断点指令。这样,您就可以在代码中始终使用 DEBUG_BREAK


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 (or any other standard compiler) I want to do a break into debugger, too. Is there a platform independent function or intrinsic? I saw the XCode question about that, but it doesn't seem portable enough.

Sidenote: I mainly want to implement ASSERT with that, and I understand I can use assert() for that, but I also want to write DEBUG_BREAK or something into the code.

解决方案

What about defining a conditional macro based on #ifdef that expands to different constructs based on the current architecture or platform.

Something like:

#ifdef _MSC_VER
#define DEBUG_BREAK __debugbreak()
#else
...
#endif

This would be expanded by the preprocessor the correct debugger break instruction based on the platform where the code is compiled. This way you always use DEBUG_BREAK in your code.

这篇关于是否有一个可移植的等同于DebugBreak()/ __ debugbreak?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 03:05
查看更多