Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display function return values #1036

Merged
merged 1 commit into from
Sep 18, 2020
Merged
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
2 changes: 1 addition & 1 deletion src/MIDebugEngine/AD7.Impl/AD7Thread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Microsoft.MIDebugEngine
{
// This class implements IDebugThread2 which represents a thread running in a program.
internal class AD7Thread : IDebugThread2
internal sealed class AD7Thread : IDebugThread2
{
private readonly AD7Engine _engine;
private readonly DebuggedThread _debuggedThread;
Expand Down
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);
Trass3r marked this conversation as resolved.
Show resolved Hide resolved
// step out
else if (reason == "function-finished")
{
string resultVar = results.Results.TryFindString("gdb-result-var"); // a gdb value history var like "$1"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately we only get the name of the caller instead of the callee here.

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 && ReturnValue.Client.Id == thread.Id)
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