Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/DebugEngineHost.Common/HostLogChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ public interface ILogChannel

public class HostLogChannel : ILogChannel
{
private readonly Action<string> _log;
private readonly Action<string>? _log;
private StreamWriter? _logFile;
private LogLevel _minLevelToBeLogged;

private readonly object _lock = new object();

private HostLogChannel() { _log = null!; }
private HostLogChannel() { }

public HostLogChannel(Action<string> logAction, string? file, LogLevel logLevel)
public HostLogChannel(Action<string>? logAction, string? file, LogLevel logLevel)
{
_log = logAction;

Expand Down
4 changes: 2 additions & 2 deletions src/DebugEngineHost.Stub/DebugEngineHost.ref.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public static class HostLogger
/// </summary>
/// <param name="callback">The callback to use to send the engine log.</param>
/// <param name="level">The level of the log to filter the channel on.</param>
public static void EnableHostLogging(Action<string> callback, LogLevel level = LogLevel.Verbose)
public static void EnableHostLogging(Action<string>? callback, LogLevel level = LogLevel.Verbose)
{
throw new NotImplementedException();
}
Expand Down Expand Up @@ -527,7 +527,7 @@ public static bool IsRunInTerminalAvailable()
/// <returns>true if the message is sent, false if not.</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "cwd")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public static void RunInTerminal(string title, string workingDirectory, bool useExternalConsole, IReadOnlyList<string> commandArgs, IReadOnlyDictionary<string, string> environmentVariables, Action<int?> success, Action<string> failure)
public static void RunInTerminal(string title, string workingDirectory, bool useExternalConsole, IReadOnlyList<string> commandArgs, IReadOnlyDictionary<string, string?> environmentVariables, Action<int?> success, Action<string> failure)
{
throw new NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion src/DebugEngineHost.VSCode/HostLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void EnableNatvisDiagnostics(Action<string> callback, LogLevel lev
}
}

public static void EnableHostLogging(Action<string> callback, LogLevel level = LogLevel.Verbose)
public static void EnableHostLogging(Action<string>? callback, LogLevel level = LogLevel.Verbose)
{
if (s_engineLogChannel is null)
{
Expand Down
8 changes: 4 additions & 4 deletions src/DebugEngineHost.VSCode/HostRunInTerminal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.DebugEngineHost
{
public static class HostRunInTerminal
{
private static Action<string, string, bool, List<string>, Dictionary<string, object>, Action<int?>, Action<string>>? s_runInTerminalCallback;
private static Action<string, string, bool, List<string>, Dictionary<string, object?>, Action<int?>, Action<string>>? s_runInTerminalCallback;

/// <summary>
/// Checks to see if RunInTerminal is available
Expand All @@ -23,11 +23,11 @@ public static bool IsRunInTerminalAvailable()
/// <summary>
/// Passes the call to the UI to attempt to RunInTerminal if possible.
/// </summary>
public static void RunInTerminal(string title, string cwd, bool useExternalConsole, IReadOnlyList<string> commandArgs, IReadOnlyDictionary<string, string> environmentVars, Action<int?> success, Action<string> failure)
public static void RunInTerminal(string title, string cwd, bool useExternalConsole, IReadOnlyList<string> commandArgs, IReadOnlyDictionary<string, string?> environmentVars, Action<int?> success, Action<string> failure)
{
if (s_runInTerminalCallback is not null)
{
Dictionary<string, object> env = new Dictionary<string, object>();
Dictionary<string, object?> env = new Dictionary<string, object?>();
foreach (var item in environmentVars)
{
env.Add(item.Key, item.Value);
Expand All @@ -41,7 +41,7 @@ public static void RunInTerminal(string title, string cwd, bool useExternalConso
/// Registers callback to call when RunInTerminal is called
/// </summary>
/// <param name="runInTerminalCallback">Callback for RunInTerminal</param>
public static void RegisterRunInTerminalCallback(Action<string, string, bool, List<string>, Dictionary<string, object>, Action<int?>, Action<string>> runInTerminalCallback)
public static void RegisterRunInTerminalCallback(Action<string, string, bool, List<string>, Dictionary<string, object?>, Action<int?>, Action<string>> runInTerminalCallback)
{
Debug.Assert(runInTerminalCallback != null, "Callback should not be null.");
s_runInTerminalCallback = runInTerminalCallback;
Expand Down
2 changes: 1 addition & 1 deletion src/DebugEngineHost/HostLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class HostLogger
private static FeedbackLogBuffer? s_circularBuffer;
private static VSFeedbackLogger? s_feedbackLogger;

public static void EnableHostLogging(Action<string> callback, LogLevel level = LogLevel.Verbose)
public static void EnableHostLogging(Action<string>? callback, LogLevel level = LogLevel.Verbose)
{
if (s_engineLogChannel is null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/DebugEngineHost/HostRunInTerminal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static bool IsRunInTerminalAvailable()

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "cwd")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public static void RunInTerminal(string title, string workingDirectory, bool useExternalConsole, IReadOnlyList<string> commandArgs, IReadOnlyDictionary<string, string> environmentVariables, Action<int?> success, Action<string> failure)
public static void RunInTerminal(string title, string workingDirectory, bool useExternalConsole, IReadOnlyList<string> commandArgs, IReadOnlyDictionary<string, string?> environmentVariables, Action<int?> success, Action<string> failure)
{
throw new NotImplementedException();
}
Expand Down
12 changes: 8 additions & 4 deletions src/MICore/CommandFactories/MICommandFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,34 @@ public enum AsyncBreakSignal

public abstract class MICommandFactory
{
protected Debugger _debugger;
protected readonly Debugger _debugger;

public MIMode Mode { get; private set; }

public abstract string Name { get; }

internal int MajorVersion { get; set; }

protected MICommandFactory(Debugger debugger)
{
_debugger = debugger;
}

public static MICommandFactory GetInstance(MIMode mode, Debugger debugger)
{
MICommandFactory commandFactory;

switch (mode)
{
case MIMode.Gdb:
commandFactory = new GdbMICommandFactory();
commandFactory = new GdbMICommandFactory(debugger);
break;
case MIMode.Lldb:
commandFactory = new LlldbMICommandFactory();
commandFactory = new LlldbMICommandFactory(debugger);
break;
default:
throw new ArgumentException(null, nameof(mode));
}
commandFactory._debugger = debugger;
commandFactory.Mode = mode;
commandFactory.Radix = 10;
return commandFactory;
Expand Down
5 changes: 5 additions & 0 deletions src/MICore/CommandFactories/gdb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ internal class GdbMICommandFactory : MICommandFactory
private int _currentThreadId = 0;
private uint _currentFrameLevel = 0;

public GdbMICommandFactory(Debugger debugger)
: base(debugger)
{
}

public override string Name
{
get { return "GDB"; }
Expand Down
5 changes: 5 additions & 0 deletions src/MICore/CommandFactories/lldb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ namespace MICore
{
internal class LlldbMICommandFactory : MICommandFactory
{
public LlldbMICommandFactory(Debugger debugger)
: base(debugger)
{
}

public override string Name
{
get { return "LLDB"; }
Expand Down
33 changes: 17 additions & 16 deletions src/MICore/Debugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public bool IsClosed
public uint MaxInstructionSize { get; private set; }
public bool Is64BitArch { get; private set; }
public CommandLock CommandLock { get { return _commandLock; } }
public MICommandFactory MICommandFactory { get; protected set; }
public MICommandFactory MICommandFactory { get; }
public Logger Logger { private set; get; }

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
Expand Down Expand Up @@ -124,12 +124,12 @@ public StoppingEventArgs(Results results, BreakRequest asyncRequest = BreakReque
}

private ITransport _transport;
private CommandLock _commandLock = new CommandLock();
private readonly CommandLock _commandLock = new CommandLock();

/// <summary>
/// The last command we sent over the transport. This includes both the command name and arguments.
/// </summary>
private string _lastCommandText;
private string _lastCommandText = string.Empty;
private uint _lastCommandId;

/// <summary>
Expand Down Expand Up @@ -169,6 +169,7 @@ public Debugger(LaunchOptions launchOptions, Logger logger)
_debuggeePids = new Dictionary<string, int>();
Logger = logger;
_miResults = new MIResults(logger);
MICommandFactory = MICommandFactory.GetInstance(launchOptions.DebuggerMIMode, this);
}

protected void SetDebuggerPid(int debuggerPid)
Expand Down Expand Up @@ -392,7 +393,7 @@ private async Task<bool> DoInternalBreakActions(bool fIsAsyncBreak)
}
catch (Exception e) when (ExceptionHelper.BeforeCatch(e, Logger, reportOnlyCorrupting: true))
{
if (firstException != null)
if (firstException is null)
{
firstException = e;
}
Expand All @@ -404,7 +405,7 @@ private async Task<bool> DoInternalBreakActions(bool fIsAsyncBreak)
{
if (this.IsClosed)
{
source.TrySetException(new DebuggerDisposedException(_closeMessage));
source.TrySetException(new DebuggerDisposedException(GetTargetProcessExitedReason()));
}
else
{
Expand Down Expand Up @@ -524,7 +525,7 @@ private void Close(string closeMessage)
Debug.Assert(_closeMessage == null, "Why was Close called more than once? Should be impossible.");

_closeMessage = closeMessage;
_transport.Close();
_transport?.Close();
lock (_waitingOperations)
{
foreach (var value in _waitingOperations.Values)
Expand Down Expand Up @@ -905,7 +906,7 @@ private Task<Results> CmdAsyncInternal(string command, ResultClass expectedResul
{
if (this.IsClosed)
{
throw new DebuggerDisposedException(_closeMessage);
throw new DebuggerDisposedException(GetTargetProcessExitedReason());
}

id = ++_lastCommandId;
Expand Down Expand Up @@ -992,13 +993,13 @@ public void OnDebuggerProcessExit(/*OPTIONAL*/ string exitCode)
if (isMinGWOrCygwin && IsUnsupportedWindowsGdbVersion(_gdbVersion))
{
exception = new MIDebuggerInitializeFailedUnsupportedGdbException(
this.MICommandFactory.Name, _initialErrors.ToList().AsReadOnly(), _initializationLog.ToList().AsReadOnly(), _gdbVersion);
this.MICommandFactory.Name, (_initialErrors?.ToList() ?? new List<string>()).AsReadOnly(), (_initializationLog?.ToList() ?? new List<string>()).AsReadOnly(), _gdbVersion);
SendUnsupportedWindowsGdbEvent(_gdbVersion);
}
else
{
exception = new MIDebuggerInitializeFailedException(
this.MICommandFactory.Name, _initialErrors.ToList().AsReadOnly(), _initializationLog.ToList().AsReadOnly());
this.MICommandFactory.Name, (_initialErrors?.ToList() ?? new List<string>()).AsReadOnly(), (_initializationLog?.ToList() ?? new List<string>()).AsReadOnly());
}

_initialErrors = null;
Expand Down Expand Up @@ -1029,7 +1030,7 @@ public void OnDebuggerProcessExit(/*OPTIONAL*/ string exitCode)
{
if (DebuggerExitEvent != null)
{
DebuggerExitEvent(this, null);
DebuggerExitEvent(this, EventArgs.Empty);
}
}
}
Expand Down Expand Up @@ -1419,8 +1420,7 @@ this.LaunchOptions is LocalLaunchOptions &&

private void OnNotificationOutput(string cmd)
{
Results results = null;
if ((results = MICommandFactory.IsModuleLoad(cmd)) != null)
if (MICommandFactory.IsModuleLoad(cmd) is Results results)
{
if (LibraryLoadEvent != null)
{
Expand Down Expand Up @@ -1460,12 +1460,12 @@ private void OnNotificationOutput(string cmd)
else if (cmd.StartsWith("thread-created,", StringComparison.Ordinal))
{
results = _miResults.ParseResultList(cmd.Substring("thread-created,".Length));
ThreadCreatedEvent(this, new ResultEventArgs(results, 0));
ThreadCreatedEvent?.Invoke(this, new ResultEventArgs(results, 0));
}
else if (cmd.StartsWith("thread-exited,", StringComparison.Ordinal))
{
results = _miResults.ParseResultList(cmd.Substring("thread-exited,".Length));
ThreadExitedEvent(this, new ResultEventArgs(results, 0));
ThreadExitedEvent?.Invoke(this, new ResultEventArgs(results, 0));
}
else if (cmd.StartsWith("telemetry,", StringComparison.Ordinal))
{
Expand Down Expand Up @@ -1619,14 +1619,15 @@ private async void PostCommand(string cmd)

private void SendToTransport(string cmd)
{
_transport.Send(cmd);
ITransport transport = _transport ?? throw new InvalidOperationException();
transport.Send(cmd);
Comment on lines 1620 to +1623

// https://github.com/Microsoft/MIEngine/issues/616 :
// If it is local gdb (MinGW/Cygwin) on Windows, we need to send an extra line after commands
// so that if it errors, the error will come through.
if (this.SendNewLineAfterCmd)
{
_transport.Send(String.Empty);
transport.Send(String.Empty);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/MIDebugEngine/Engine.Impl/DebuggedProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public DebuggedProcess(bool bLaunched, LaunchOptions launchOptions, ISampleEngin
_libraryLoaded = new List<string>();
_loadOrder = 0;
_deleteEntryPointBreakpoint = false;
MICommandFactory = MICommandFactory.GetInstance(launchOptions.DebuggerMIMode, this);
_waitDialog = (MICommandFactory.SupportsStopOnDynamicLibLoad() && launchOptions.WaitDynamicLibLoad) ? new HostWaitDialog(ResourceStrings.LoadingSymbolMessage, ResourceStrings.LoadingSymbolCaption) : null;
Natvis = new Natvis.Natvis(this, launchOptions.ShowDisplayString, configStore);

Expand Down
Loading