Skip to content

Commit

Permalink
show function return value after stepping out
Browse files Browse the repository at this point in the history
  • Loading branch information
Trass3r committed Sep 17, 2020
1 parent ec52d60 commit cd08c1a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
19 changes: 17 additions & 2 deletions src/MIDebugEngine/Engine.Impl/DebuggedProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal class DebuggedProcess : MICore.Debugger
public AD7Engine Engine { get; private set; }
public List<string> VariablesToDelete { get; private set; }
public List<IVariableInformation> ActiveVariables { get; private set; }

public VariableInformation ReturnValue { get; private set; }
public SourceLineCache SourceLineCache { get; private set; }
public ThreadCache ThreadCache { get; private set; }
public Disassembly Disassembly { get; private set; }
Expand Down Expand Up @@ -1053,6 +1053,7 @@ private async Task HandleBreakModeEvent(ResultEventArgs results, BreakRequest br
varInfo.Dispose();
}
this.ActiveVariables.Clear();
ReturnValue = null; // already disposed above
}

ThreadCache.MarkDirty();
Expand Down Expand Up @@ -1235,8 +1236,19 @@ private async Task HandleBreakModeEvent(ResultEventArgs results, BreakRequest br
}
}
}
else if (reason == "end-stepping-range" || reason == "function-finished")
// step over/into
// NB: unfortunately this event does not provide a return value: https://sourceware.org/bugzilla/show_bug.cgi?id=26354
else if (reason == "end-stepping-range")
_callback.OnStepComplete(thread);
// step out
else if (reason == "function-finished")
{
string resultVar = results.Results.TryFindString("gdb-result-var"); // a gdb value history var like "$1"
if (!string.IsNullOrEmpty(resultVar))
{
ReturnValue = new VariableInformation("$ReturnValue", resultVar, cxt, Engine, (AD7Thread)thread.Client, isParameter: false);
await ReturnValue.Eval();
}
_callback.OnStepComplete(thread);
}
else if (reason == "signal-received")
Expand Down Expand Up @@ -1874,6 +1886,9 @@ internal async Task<List<VariableInformation>> GetLocalsAndParameters(AD7Thread
variables.Add(vi);
}

if (ReturnValue != null && ctx.Level == 0)
variables.Add(ReturnValue);

return variables;
}

Expand Down
8 changes: 4 additions & 4 deletions src/MIDebugEngine/Engine.Impl/Variables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ internal SimpleVariableInformation(string name, bool isParam = false, string val

internal async Task<VariableInformation> CreateMIDebuggerVariable(ThreadContext ctx, AD7Engine engine, AD7Thread thread)
{
VariableInformation vi = new VariableInformation(Name, ctx, engine, thread, IsParameter);
VariableInformation vi = new VariableInformation(Name, Name, ctx, engine, thread, IsParameter);
await vi.Eval();
return vi;
}
Expand All @@ -73,7 +73,7 @@ public ArgumentList(int level, List<SimpleVariableInformation> args)
{ }
}

internal class VariableInformation : IVariableInformation
internal sealed class VariableInformation : IVariableInformation
{
public string Name { get; private set; }
public string Value { get; private set; }
Expand Down Expand Up @@ -190,12 +190,12 @@ private VariableInformation(ThreadContext ctx, AD7Engine engine, AD7Thread threa
}

//this constructor is used to create root nodes (local/params)
internal VariableInformation(string expr, ThreadContext ctx, AD7Engine engine, AD7Thread thread, bool isParameter = false)
internal VariableInformation(string displayName, string expr, ThreadContext ctx, AD7Engine engine, AD7Thread thread, bool isParameter = false)
: this(ctx, engine, thread)
{
// strip off formatting string
_strippedName = StripFormatSpecifier(expr, out _format);
Name = expr;
Name = displayName;
IsParameter = isParameter;
_parent = null;
VariableNodeType = NodeType.Root;
Expand Down
4 changes: 2 additions & 2 deletions src/MIDebugEngine/Natvis.Impl/Natvis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ internal IVariableInformation GetVariable(string expr, AD7StackFrame frame)
if (expr.EndsWith(",viz", StringComparison.Ordinal))
{
expr = expr.Substring(0, expr.Length - 4);
variable = new VariableInformation(expr, frame.ThreadContext, frame.Engine, frame.Thread);
variable = new VariableInformation(expr, expr, frame.ThreadContext, frame.Engine, frame.Thread);
variable.SyncEval();
if (!variable.Error)
{
Expand All @@ -442,7 +442,7 @@ internal IVariableInformation GetVariable(string expr, AD7StackFrame frame)
}
else
{
variable = new VariableInformation(expr, frame.ThreadContext, frame.Engine, frame.Thread);
variable = new VariableInformation(expr, expr, frame.ThreadContext, frame.Engine, frame.Thread);
}
return variable;
}
Expand Down

0 comments on commit cd08c1a

Please sign in to comment.