停止执行我的程序并转到调试器而不设置断点(Visual Studio/GCC和C++)

zxc*_*cat 3 debugging cross-platform breakpoints visual-studio

我前段时间在SO上找到了有关此功能的信息,但主题是Visual Studio隐藏功能(2005-2008)的副本我再也找不到了.

我想用这样的东西:

#ifdef DEBUG
#define break_here(condition) if (condition) ... // don't remember, what must be here
#else
#define break_here(condition) if (condition) return H_FAIL;
#endif
//...
hresult = do_something(...);
break_here(hresult != H_OK);
//...
var = do_other_thing(...);
break_here(var > MAX_VAR);
Run Code Online (Sandbox Code Playgroud)

它必须表现得像一个错误的断点.这就像断言,但没有对话,更轻量级.

我不能在这里使用普通断点,因为我的模块是几个项目的一部分,可以在几个VS解决方案中进行编辑.当在其他解决方案中编辑代码时,这会导致在一个解决方案中设置的断点在源中移位.

cra*_*str 9

看看DebugBreak

导致在当前进程中发生断点异常.这允许调用线程通知调试器处理异常.

例:

 var = do_other_thing(...);
 if (var > MAX_VAR)
      DebugBreak();
Run Code Online (Sandbox Code Playgroud)