How to install a DebugBreak handler?

让人想犯罪 __ 提交于 2019-12-04 16:04:43

There are a few distinct ways to handle this.

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.

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.

We want to install a DebugBreak handler if a debugger is not present.

you need install usual windows exception handler, by using __try / __except or by AddVectoredExceptionHandler or by SetUnhandledExceptionFilter

when int 3 instruction is executed in your app (by calling __debugbreak or DebugBreak) - and debugger not present or not handle this - your exception handler will be called with exception code STATUS_BREAKPOINT.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!