在进程外使用 MiniDumpWriteDump 时如何获取异常信息?
在 Windows 上使用 MiniDumpWriteDump 函数创建进程的核心转储时,建议使用(例如 这里 和这里)MiniDumpWriteDump
是从另一个看门狗"进程运行的,因为在同一进程中调用时它可能无法正常工作.
When using the MiniDumpWriteDump function to create a core dump of a process on Windows, it is recommended (e.g. here, and here) that the MiniDumpWriteDump
is run from another "watchdog" process because it may well not work when called from within the same process.
目前,我们的应用程序在处理未处理的异常时调用它(我们从看门狗线程执行此操作).由于我们有时会遇到无法运行的问题,因此我们希望将其移至单独的进程.
At the moment, our application is calling it in-process on an unhandled exception (we do it from a watchdog thread). Since we sometimes have problems with it not working, we'd like to move it to a separate process.
现在,向另一个进程发出开始写入转储的信号是微不足道的(只需使用事件、信号量、你命名的)但是我如何传递我为回调函数获得的 LPEXCEPTION_POINTERS
信息我使用 SetUnhandledExceptionFilter
注册到另一个进程,以便它可以传递给 MiniDumpWriteDump
的 ExceptionParam
参数??
Now, signalling the other process to start writing the dump is trivial (just use an event, semaphore, you name it) but how do I pass the LPEXCEPTION_POINTERS
info I get for the callback function I register with SetUnhandledExceptionFilter
to the other process so that it can be passed to MiniDumpWriteDump
s ExceptionParam
argument??
推荐答案
您还需要 MINIDUMP_EXCEPTION_INFORMATION.ThreadId 值.最简单的方法,也是我让它工作的方式,是使用内存映射文件来传输 ThreadId 和 ExceptionPointers.以及唤醒看门狗的命名事件.指针在看门狗进程的上下文中无效并不重要.
You also need the MINIDUMP_EXCEPTION_INFORMATION.ThreadId value. The simplest way, and the way I made it work, is to use a memory-mapped file to transfer both the ThreadId and the ExceptionPointers. And a named event to wake up the watchdog. It doesn't matter that the pointer is not valid in the context of the watchdog process.
在监视进程中使用 CreateFileMapping + MapViewOfFile 作为其初始化的一部分,在看门狗中使用 OpenFileMapping + MapViewOfFile.然后您的 SetUnhandledExceptionFilter 应该只调用 GetCurrentThreadId() 并将 tid 和 pExcept 复制到内存映射文件视图,调用 SetEvent() 唤醒看门狗并永远阻塞,直到看门狗终止它.
Use CreateFileMapping + MapViewOfFile in the watched process as part of its initialization, OpenFileMapping + MapViewOfFile in the watchdog. Your SetUnhandledExceptionFilter should then only call GetCurrentThreadId() and copy the tid and the pExcept to the memory mapped file view, call SetEvent() to wake up the watchdog and block forever until the watchdog terminates it.
相关文章