void HandleCommand(object sender, EventArgs eventArgs) { try { taskContext.ThrowIfNotOnMainThread(); var cmdEventArgs = eventArgs as OleMenuCmdEventArgs; if (cmdEventArgs == null || !(cmdEventArgs.InValue is string)) { commandWindowWriter.PrintErrorMsg("ERROR: Unable to parse command."); return; } var commandText = (string)cmdEventArgs.InValue; var strArgs = commandText.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); Trace.WriteLine($"Executing 'Stadia.Debugger {commandText}'"); var result = BuildCommandParser().Execute(strArgs); Trace.WriteLine($"'Stadia.Debugger {commandText}' returned {result}."); } catch (Exception ex) when(!(ex is OutOfMemoryException)) { commandWindowWriter.PrintErrorMsg( $"Error - See logs for more info."); // The exception message will be printed to the command window by Visual Studio. Trace.WriteLine($"ERROR: Caught unexpected exception executing " + $"'Stadia.Debugger' command.{Environment.NewLine}" + ex.ToString()); throw; } }
private void HandleLLDBCommand(object sender, EventArgs e) { taskContext.ThrowIfNotOnMainThread(); string shellCommand; if (!TryGetCommand(e, out shellCommand)) { return; } var lldbShell = (ILLDBShell)serviceProvider.GetService(typeof(SLLDBShell)); if (lldbShell == null) { commandWindowWriter.PrintErrorMsg("ERROR: Unable to execute LLDB Shell command." + " No shell service found."); return; } try { lldbShell.ExecuteCommand(shellCommand); } catch (Exception ex) { commandWindowWriter.PrintErrorMsg( "ERROR: LLDB Shell command failed. Reason: '" + ex.Message + "'"); } }
// Should only be called from the UI thread! public void ExecuteCommand(string command) { taskContext.ThrowIfNotOnMainThread(); Trace.WriteLine(string.Format("Executing LLDB Shell command '{0}'", command)); if (debuggers.Count == 0) { commandWindowWriter.PrintErrorMsg( "ERROR: LLDB Shell command not handled. No debuggers attached."); return; } // TODO: Provide a mechanism for the client to pick which debugger to dispatch // the command to. if (debuggers.Count > 1) { commandWindowWriter.PrintErrorMsg( $"ERROR: There appears to be multiple ({debuggers.Count}) LLDB debuggers " + "attached and we don't currently support that. If this is unexpected you can " + "try restarting Visual Studio."); return; } var commandInterpreter = debuggers.First().GetCommandInterpreter(); if (commandInterpreter == null) { commandWindowWriter.PrintErrorMsg( "Unexpected ERROR: No command interpreter was found for the LLDB Shell."); return; } SbCommandReturnObject commandResult; commandInterpreter.HandleCommand(command, out commandResult); PrintCommandResult(commandResult); }