【问题标题】:Monitor process exceptions via Debug API通过 Debug API 监控进程异常
【发布时间】:2012-03-13 15:43:51
【问题描述】:

任何帮助开始使用在C++/CLI Win32 debugger library for x86 找到的示例代码来监视进程异常。

我做的一些代码是:

使用系统; 使用调试库; 命名空间 DebugTeste01 { 课堂节目 { 静态无效主要(字符串 [] 参数) { DebugUtil.DebugActiveProcess(4932); DebugEvent de = new DebugEvent(); ThreadContext tc = new ThreadContext(); LDTEntry ldte = 新的 LDTEntry(); 做 { debug_evt = DebugUtil.WaitForDebugEvent(0xffffffff); de = (DebugEvent)debug_evt; 进程 proc = Process.GetProcessById(de.processId); 对象 meminfo = DebugUtil.GetMemoryInfo(proc.Handle); //... 对象 modinf = DebugUtil.GetModuleInfo(proc.Handle); //... 开关 (debug_evt.GetType().ToString()) { 案例“DebugLibrary.DebugEvent_CreateProcess”: { DebugEvent_CreateProcess decp = (DebugEvent_CreateProcess)debug_evt; //一些动作,日志记录等 } 休息; 案例“DebugLibrary.DebugEvent_LoadDll”: { DebugEvent_LoadDll 检测 = (DebugEvent_LoadDll)debug_evt; //一些动作,日志记录等 } 休息; 案例“DebugLibrary.DebugEvent_CreateThread”: { DebugEvent_CreateThread 检测 = (DebugEvent_CreateThread)debug_evt; //一些动作,日志记录等 } 休息; 案例“DebugLibrary.DebugEvent_ExitThread”: { DebugEvent_ExitThread 检测 = (DebugEvent_ExitThread)debug_evt; //一些动作,日志记录等 } 休息; 案例“DebugLibrary.DebugEvent_Exception”: { DebugEvent_Exception 检测 = (DebugEvent_Exception)debug_evt; 异常记录 exbp = dect.exceptionRecord; 开关 (exbp.GetType().ToString()) { 案例“断点”: { //一些动作,日志记录等 exbp = null; } 休息; 案例“访问违规”: { //一些动作,日志记录等 exbp = null; } 休息; //更多案例 } } 休息; 默认: { //一些动作,日志记录等 debug_evt = null; } 休息; } 尝试 { DebugUtil.ContinueDebugEvent(de.processId, de.threadId, false); } 抓住 { 休息; } } 而(真); } } }

[编辑] 2012 年 3 月 14 日
好文章:Using the Windows Debugging API
[编辑] 2012 年 3 月 14 日
实施方面的改进。
现在,它具有最终应用程序的初始骨架构造。

【问题讨论】:

    标签: debugging exception


    【解决方案1】:

    在我看来,您正在寻找有关调试器编写的资源以供理解,在这种情况下,您最好的起点是MSDN,这提供了应该如何处理的基础知识。从那里开始,真正取决于您的应用程序和环境如何处理异常。

    作为对实际代码的注释,避免硬编码为 PID,而是使用进程名称。

    【讨论】:

    • 代码的目的是展示如何使用API​​,但首先要了解它是如何工作的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多