5 dll minidump exception exit visual-c++
我有一个MFC SDI应用程序,它在启动期间加载DLL.我只能查看源代码并使用DLL但不能更改和重新编译它.
现在的情况是,每当DLL引发错误时,它将调用exit(),如下所示.
bool Func()
{
// .. do something here
if (error) { exit(999); }
}
Run Code Online (Sandbox Code Playgroud)
在我的MFC应用程序中,我设置了SetUnhandledExceptionFilter来处理所有异常,并创建了一个MiniDump用于调试目的.
所以现在的问题是,每当DLL遇到任何错误时,它只会调用状态代码为999的exit(),而我的ExceptionFilter将无法捕获它,因此没有为PostMortem调试创建MiniDump.
我很想知道:
1.我的全局异常处理程序有没有其他方法可以捕获它?
2.我可以覆盖exit()函数,以便在调用时,我调用"throw("error encounter!")"并且我的全局异常处理程序可以捕获它.
3.我尝试在我的MFC应用程序中使用atexit(),每当DLL调用exit()时,我都会注册另一个函数来抛出错误.但似乎这种方式效果不佳.
我真正想做的是,每当DLL遇到错误时,我都希望生成一个MiniDump,这样我就可以进行PostMortem调试.还有什么可能在这种情况下有效吗?
谢谢.
这是我编写的用于在 exit() 函数中放置断点的宏:
Imports System.IO
' Sets breakpoints on all exit functions. useful for catching library code that
' calls exit in the debugger.
Sub AddBreakpointsToExit()
Dim bp As EnvDTE.Breakpoint
Dim bps As EnvDTE.Breakpoints
Dim envVar As String = "VS90COMNTOOLS"
Dim comnTools As String = System.Environment.GetEnvironmentVariable(envVar)
If (String.IsNullOrEmpty(comnTools)) Then
Throw New System.Exception("Environment variable '" + envVar + "' doesn't exist.")
End If
Dim filePath As String = System.IO.Path.Combine(comnTools, "..\..\VC\crt\src\crt0dat.c")
' set exit function names and line #s:
Dim exitFunctions(0 To 4) As String
exitFunctions(0) = "exit"
exitFunctions(1) = "_exit"
exitFunctions(2) = "_cexit"
exitFunctions(3) = "_c_exit"
' line numbers are based on the Visual Studio 2008 definition.
' TODO: check and add options if 2005 or 2010 are differen.t
Dim exitLines(0 To 4) As Integer
exitLines(0) = 412
exitLines(1) = 420
exitLines(2) = 427
exitLines(3) = 434
' set breakpoints:
For i = 0 To 3 Step 1
bps = DTE.Debugger.Breakpoints.Add(File:=filePath, Line:=exitLines(i))
Next i
End Sub
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1444 次 |
最近记录: |