如何安装DebugBreak处理程序? [英] How to install a DebugBreak handler?

查看:98
本文介绍了如何安装DebugBreak处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在为Visual Studio解决方案设置Appveyor,该解决方案将生成C ++库.我们的一些测试使C ++对象模糊不清,以确保它们不会做意外的事情.在调试版本下,它会引发一个断言(在发布版本中,它只会抛出该错误).

We are setting up Appveyor for our Visual Studio solution, which produces a C++ library. A few of our tests [dumb] fuzz C++ objects to ensure they don't do something unexpected. Under debug builds it causes an assert to fire (and in release builds it just throws).

我们使用一个自定义断言来避免Posix导致崩溃的行为,使正在调试的程序崩溃.如下所示.如果触发了断言并且未附加调试器,则看来Appveyor或操作系统会杀死该程序:

We use a custom assert to avoid Posix behavior of crashing a program being debugged. It is shown below. It appears Appveyor or the Operating System kills the program if an assert fires and a debugger is not attached:

如果调试器不存在,我们想安装DebugBreak处理程序.这应该确认它的操作系统正在执行中.理想情况下,该处理程序可以在Windows XP及更高版本以及VS2002及更高版本(我们支持的Windows组合)中运行.

We want to install a DebugBreak handler if a debugger is not present. This should confirm its the OS doing the killing. Ideally, the handler will work from Windows XP onwards and VS2002 and above (those are the Windows combinations we support).

我们如何在Windows平台上安装DebugBreak处理程序?

How do we install a DebugBreak handler on Windows platforms?

#  define MYLIB_ASSERT(exp) {                                     \
    if (!(exp)) {                                                 \
      std::ostringstream oss;                                     \
      oss << "Assertion failed: " << (char*)(__FILE__) << "("     \
          << (int)(__LINE__) << "): " << (char*)(__FUNCTION__)    \
          << std::endl;                                           \
      std::cerr << oss.str();                                     \
      __debugbreak();                                             \
    }                                                             \
}


我们不能真正确定是谁负责的,因为该行为未在MSDN上的 DebugBreak和__debugbreak C/C ++断言.

推荐答案

有几种不同的处理方式.

There are a few distinct ways to handle this.

从启动可能会调用DebugBreak()的过程中,可以使用 WaitForDebugEvent (或WaitForDebugEventEx)和 ContinueDebugEvent 来处理来自子级的调试事件.也就是说,父级充当调试器,子级充当调试对象,这与Visual Studio(以及其他)调试器的工作方式类似.

From the process that launches the one that may call DebugBreak(), you can use WaitForDebugEvent (or WaitForDebugEventEx) and ContinueDebugEvent to handle debug events from the child. I.e., the parent acts as a debugger, and the child as a debuggee, similar to how Visual Studio (among many others) debugger works.

您还可以使用 .附加后,大多数调试与父调试其子进程类似.

You can also attach to a running process using DebugActiveProcess. After you've attached, most of debugging is similar to a parent debugging its child process.

如果您不能(或不想)执行任何一种操作,则可以安装事后调试器.您可以通过在注册表中指定调试器来执行此操作,如上所述MSDN . Windows有一个"Windows错误报告"(WER),它会调用指定的事后调试器.

If you can't (or don't want to) do either of those, you can install a post-mortem debugger. You do this by specifying the debugger in the registry, as described on MSDN. Windows has a "Windows Error Reporting" (WER), which invokes the specified post-mortem debugger.

这篇关于如何安装DebugBreak处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆