Skip to content

Commit 4351838

Browse files
Work around AV in dbgeng when loading image as dump
1 parent 1df7e98 commit 4351838

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

DbgProvider/public/Debugger/DbgEngDebugger.cs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,29 @@ internal static DbgEngDebugger NewDebugger()
6767
return _GlobalDebugger;
6868
}
6969

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+
7084
internal void LoadCrashDump( string dumpFileName,
71-
string targetFriendlyName )
85+
string targetFriendlyName )
7286
{
7387
DbgEngThread.Singleton.Execute( () =>
7488
{
89+
if( dumpFileName.EndsWith( ".dll" ) || dumpFileName.EndsWith( ".exe" ) )
90+
{
91+
m_loadingImageHack = 1;
92+
}
7593
CheckHr( m_debugClient.OpenDumpFileWide( dumpFileName, 0 ) );
7694
SetNextTargetName( targetFriendlyName );
7795
} );
@@ -4302,12 +4320,19 @@ public DbgEngContext GetCurrentDbgEngContext()
43024320
threadIdOrAddr = uiThreadId;
43034321
}
43044322

4305-
hr = m_debugSymbols.GetCurrentScopeFrameIndexEx( DEBUG_FRAME.DEFAULT, out frameId );
4306-
if( 0 != hr )
4323+
if( m_loadingImageHack-- > 0 )
43074324
{
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+
}
43114336
}
43124337
} );
43134338

DbgProvider/public/Debugger/RealDebugEventCallbacks.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ public int ChangeSymbolState( DEBUG_CSS Flags, ulong Argument )
609609
m_debugger.m_sympath = null;
610610
}
611611

612+
// Re: m_loadingImageHack: this is where the AV in dbgeng occurs.
612613
var eventArgs = new SymbolStateChangedEventArgs( m_debugger, Flags, Argument );
613614
int retVal = _RaiseEvent( m_debugger.SymbolStateChanged, eventArgs );
614615
if( _ShouldOutput( retVal, eventArgs ) )

0 commit comments

Comments
 (0)