@@ -67,11 +67,29 @@ internal static DbgEngDebugger NewDebugger()
67
67
return _GlobalDebugger ;
68
68
}
69
69
70
+
71
+ // There's a bug in dbgeng.dll that results in an AV in dbgeng. The situation is
72
+ // triggered when we load up an image file as a dump. After we call WaitForEvent,
73
+ // dbgeng calls back into us to notify us of various state changes, and in those,
74
+ // we query current state, such as a the current scope frame, and then dbgeng AVs.
75
+ //
76
+ // If we didn't handle it, it would get handled by dbgeng's own WaitForEvent
77
+ // underneath us, so now DbgEngWrapper catches all exceptions that come out of
78
+ // dbgeng. However, even in that case, some of dbgeng's internal state gets messed
79
+ // up (engine nesting level), so we'll conspire to avoid hitting the AV in the
80
+ // first place: When loading an image as a dump file, we'll skip calling
81
+ // GetCurrentScopeFrameIndexEx that first time.
82
+ internal int m_loadingImageHack ;
83
+
70
84
internal void LoadCrashDump ( string dumpFileName ,
71
- string targetFriendlyName )
85
+ string targetFriendlyName )
72
86
{
73
87
DbgEngThread . Singleton . Execute ( ( ) =>
74
88
{
89
+ if ( dumpFileName . EndsWith ( ".dll" ) || dumpFileName . EndsWith ( ".exe" ) )
90
+ {
91
+ m_loadingImageHack = 1 ;
92
+ }
75
93
CheckHr ( m_debugClient . OpenDumpFileWide ( dumpFileName , 0 ) ) ;
76
94
SetNextTargetName ( targetFriendlyName ) ;
77
95
} ) ;
@@ -4302,12 +4320,19 @@ public DbgEngContext GetCurrentDbgEngContext()
4302
4320
threadIdOrAddr = uiThreadId ;
4303
4321
}
4304
4322
4305
- hr = m_debugSymbols . GetCurrentScopeFrameIndexEx ( DEBUG_FRAME . DEFAULT , out frameId ) ;
4306
- if ( 0 != hr )
4323
+ if ( m_loadingImageHack -- > 0 )
4307
4324
{
4308
- LogManager . Trace ( "GetCurrentDbgEngContext: no current frame: {0}." ,
4309
- Util . FormatErrorCode ( hr ) ) ;
4310
- return ;
4325
+ LogManager . Trace ( "Avoiding querying current scope frame to avoid dbgeng bug." ) ;
4326
+ }
4327
+ else
4328
+ {
4329
+ hr = m_debugSymbols . GetCurrentScopeFrameIndexEx ( DEBUG_FRAME . DEFAULT , out frameId ) ;
4330
+ if ( 0 != hr )
4331
+ {
4332
+ LogManager . Trace ( "GetCurrentDbgEngContext: no current frame: {0}." ,
4333
+ Util . FormatErrorCode ( hr ) ) ;
4334
+ return ;
4335
+ }
4311
4336
}
4312
4337
} ) ;
4313
4338
0 commit comments