Skip to content

Commit

Permalink
Add support for '`' instead of '-exec' prefaces for sending gdb comma…
Browse files Browse the repository at this point in the history
…nds (#976)

* Add support for '`' instead of '-exec' prefaces for sending gdb commands

* Fix FXCop error
  • Loading branch information
pieandcakes authored Mar 2, 2020
1 parent 7afd062 commit 2a2d619
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
29 changes: 25 additions & 4 deletions src/MIDebugEngine/Engine.Impl/Variables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,20 +421,41 @@ public string EvalDependentExpression(string expr)
return val;
}

/// <summary>
/// This allows console commands to be sent through the eval channel via a '-exec ' or '`' preface
/// </summary>
/// <param name="command">raw command</param>
/// <param name="strippedCommand">command stripped of the preface ('-exec ' or '`')</param>
/// <returns>true if it is a console command</returns>
private bool IsConsoleExecCmd(string command, out string strippedCommand)
{
strippedCommand = string.Empty;
string execCommandString = "-exec ";
if (command.StartsWith(execCommandString, StringComparison.Ordinal))
{
strippedCommand = command.Substring(execCommandString.Length);
return true;
}
else if (command[0] == '`')
{
strippedCommand = command.Substring(1).TrimStart(); // remove spaces if any
return true;
}
return false;
}

internal async Task Eval(enum_EVALFLAGS dwFlags = 0)
{
this.VerifyNotDisposed();

await _engine.UpdateRadixAsync(_engine.CurrentRadix()); // ensure the radix value is up-to-date

string execCommandString = "-exec ";

try
{
if (_strippedName.StartsWith(execCommandString))
string consoleCommand;
if (IsConsoleExecCmd(_strippedName, out consoleCommand))
{
// special case for executing raw mi commands.
string consoleCommand = _strippedName.Substring(execCommandString.Length);
string consoleResults = null;

consoleResults = await MIDebugCommandDispatcher.ExecuteCommand(consoleCommand, _debuggedProcess, ignoreFailures: true);
Expand Down
10 changes: 6 additions & 4 deletions src/OpenDebugAD7/AD7DebugSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ private void StepInternal(int threadId, enum_STEPKIND stepKind, enum_STEPUNIT st
#region DebugAdapterBase

protected override void HandleInitializeRequestAsync(IRequestResponder<InitializeArguments, InitializeResponse> responder)
{
{
InitializeArguments arguments = responder.Arguments;

m_engineConfiguration = EngineConfiguration.TryGet(arguments.AdapterID);
Expand Down Expand Up @@ -1825,10 +1825,12 @@ protected override void HandleEvaluateRequestAsync(IRequestResponder<EvaluateArg
DateTime evaluationStartTime = DateTime.Now;

bool isExecInConsole = false;
// If this is an -exec command, log telemetry
if (!String.IsNullOrEmpty(expression) && expression.StartsWith("-exec", StringComparison.Ordinal) && context == EvaluateArguments.ContextValue.Repl)
// If the expression isn't empty and its a Repl request, do additional checking
if (!String.IsNullOrEmpty(expression) && context == EvaluateArguments.ContextValue.Repl)
{
isExecInConsole = true;
// If this is an -exec command (or starts with '`') treat it as a console command and log telemetry
if (expression.StartsWith("-exec", StringComparison.Ordinal) || expression[0] == '`')
isExecInConsole = true;
}

int hr;
Expand Down

0 comments on commit 2a2d619

Please sign in to comment.