@@ -72,7 +72,7 @@ public bool IsClosed
7272 public uint MaxInstructionSize { get ; private set ; }
7373 public bool Is64BitArch { get ; private set ; }
7474 public CommandLock CommandLock { get { return _commandLock ; } }
75- public MICommandFactory MICommandFactory { get ; protected set ; }
75+ public MICommandFactory MICommandFactory { get ; }
7676 public Logger Logger { private set ; get ; }
7777
7878 [ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Microsoft.Security" , "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes" ) ]
@@ -124,12 +124,12 @@ public StoppingEventArgs(Results results, BreakRequest asyncRequest = BreakReque
124124 }
125125
126126 private ITransport _transport ;
127- private CommandLock _commandLock = new CommandLock ( ) ;
127+ private readonly CommandLock _commandLock = new CommandLock ( ) ;
128128
129129 /// <summary>
130130 /// The last command we sent over the transport. This includes both the command name and arguments.
131131 /// </summary>
132- private string _lastCommandText ;
132+ private string _lastCommandText = string . Empty ;
133133 private uint _lastCommandId ;
134134
135135 /// <summary>
@@ -169,6 +169,7 @@ public Debugger(LaunchOptions launchOptions, Logger logger)
169169 _debuggeePids = new Dictionary < string , int > ( ) ;
170170 Logger = logger ;
171171 _miResults = new MIResults ( logger ) ;
172+ MICommandFactory = MICommandFactory . GetInstance ( launchOptions . DebuggerMIMode , this ) ;
172173 }
173174
174175 protected void SetDebuggerPid ( int debuggerPid )
@@ -392,7 +393,7 @@ private async Task<bool> DoInternalBreakActions(bool fIsAsyncBreak)
392393 }
393394 catch ( Exception e ) when ( ExceptionHelper . BeforeCatch ( e , Logger , reportOnlyCorrupting : true ) )
394395 {
395- if ( firstException != null )
396+ if ( firstException is null )
396397 {
397398 firstException = e ;
398399 }
@@ -404,7 +405,7 @@ private async Task<bool> DoInternalBreakActions(bool fIsAsyncBreak)
404405 {
405406 if ( this . IsClosed )
406407 {
407- source . TrySetException ( new DebuggerDisposedException ( _closeMessage ) ) ;
408+ source . TrySetException ( new DebuggerDisposedException ( GetTargetProcessExitedReason ( ) ) ) ;
408409 }
409410 else
410411 {
@@ -524,7 +525,7 @@ private void Close(string closeMessage)
524525 Debug . Assert ( _closeMessage == null , "Why was Close called more than once? Should be impossible." ) ;
525526
526527 _closeMessage = closeMessage ;
527- _transport . Close ( ) ;
528+ _transport ? . Close ( ) ;
528529 lock ( _waitingOperations )
529530 {
530531 foreach ( var value in _waitingOperations . Values )
@@ -905,7 +906,7 @@ private Task<Results> CmdAsyncInternal(string command, ResultClass expectedResul
905906 {
906907 if ( this . IsClosed )
907908 {
908- throw new DebuggerDisposedException ( _closeMessage ) ;
909+ throw new DebuggerDisposedException ( GetTargetProcessExitedReason ( ) ) ;
909910 }
910911
911912 id = ++ _lastCommandId ;
@@ -992,13 +993,13 @@ public void OnDebuggerProcessExit(/*OPTIONAL*/ string exitCode)
992993 if ( isMinGWOrCygwin && IsUnsupportedWindowsGdbVersion ( _gdbVersion ) )
993994 {
994995 exception = new MIDebuggerInitializeFailedUnsupportedGdbException (
995- this . MICommandFactory . Name , _initialErrors . ToList ( ) . AsReadOnly ( ) , _initializationLog . ToList ( ) . AsReadOnly ( ) , _gdbVersion ) ;
996+ this . MICommandFactory . Name , ( _initialErrors ? . ToList ( ) ?? new List < string > ( ) ) . AsReadOnly ( ) , ( _initializationLog ? . ToList ( ) ?? new List < string > ( ) ) . AsReadOnly ( ) , _gdbVersion ) ;
996997 SendUnsupportedWindowsGdbEvent ( _gdbVersion ) ;
997998 }
998999 else
9991000 {
10001001 exception = new MIDebuggerInitializeFailedException (
1001- this . MICommandFactory . Name , _initialErrors . ToList ( ) . AsReadOnly ( ) , _initializationLog . ToList ( ) . AsReadOnly ( ) ) ;
1002+ this . MICommandFactory . Name , ( _initialErrors ? . ToList ( ) ?? new List < string > ( ) ) . AsReadOnly ( ) , ( _initializationLog ? . ToList ( ) ?? new List < string > ( ) ) . AsReadOnly ( ) ) ;
10021003 }
10031004
10041005 _initialErrors = null ;
@@ -1029,7 +1030,7 @@ public void OnDebuggerProcessExit(/*OPTIONAL*/ string exitCode)
10291030 {
10301031 if ( DebuggerExitEvent != null )
10311032 {
1032- DebuggerExitEvent ( this , null ) ;
1033+ DebuggerExitEvent ( this , EventArgs . Empty ) ;
10331034 }
10341035 }
10351036 }
@@ -1419,8 +1420,7 @@ this.LaunchOptions is LocalLaunchOptions &&
14191420
14201421 private void OnNotificationOutput ( string cmd )
14211422 {
1422- Results results = null ;
1423- if ( ( results = MICommandFactory . IsModuleLoad ( cmd ) ) != null )
1423+ if ( MICommandFactory . IsModuleLoad ( cmd ) is Results results )
14241424 {
14251425 if ( LibraryLoadEvent != null )
14261426 {
@@ -1460,12 +1460,12 @@ private void OnNotificationOutput(string cmd)
14601460 else if ( cmd . StartsWith ( "thread-created," , StringComparison . Ordinal ) )
14611461 {
14621462 results = _miResults . ParseResultList ( cmd . Substring ( "thread-created," . Length ) ) ;
1463- ThreadCreatedEvent ( this , new ResultEventArgs ( results , 0 ) ) ;
1463+ ThreadCreatedEvent ? . Invoke ( this , new ResultEventArgs ( results , 0 ) ) ;
14641464 }
14651465 else if ( cmd . StartsWith ( "thread-exited," , StringComparison . Ordinal ) )
14661466 {
14671467 results = _miResults . ParseResultList ( cmd . Substring ( "thread-exited," . Length ) ) ;
1468- ThreadExitedEvent ( this , new ResultEventArgs ( results , 0 ) ) ;
1468+ ThreadExitedEvent ? . Invoke ( this , new ResultEventArgs ( results , 0 ) ) ;
14691469 }
14701470 else if ( cmd . StartsWith ( "telemetry," , StringComparison . Ordinal ) )
14711471 {
@@ -1619,14 +1619,15 @@ private async void PostCommand(string cmd)
16191619
16201620 private void SendToTransport ( string cmd )
16211621 {
1622- _transport . Send ( cmd ) ;
1622+ ITransport transport = _transport ?? throw new InvalidOperationException ( ) ;
1623+ transport . Send ( cmd ) ;
16231624
16241625 // https://github.com/Microsoft/MIEngine/issues/616 :
16251626 // If it is local gdb (MinGW/Cygwin) on Windows, we need to send an extra line after commands
16261627 // so that if it errors, the error will come through.
16271628 if ( this . SendNewLineAfterCmd )
16281629 {
1629- _transport . Send ( String . Empty ) ;
1630+ transport . Send ( String . Empty ) ;
16301631 }
16311632 }
16321633
0 commit comments