From cd08c1a07379da9cf4e7adbdaeedef4e6f012448 Mon Sep 17 00:00:00 2001 From: Andreas Hollandt Date: Fri, 7 Aug 2020 17:10:21 +0200 Subject: [PATCH] show function return value after stepping out fixes #1027 and microsoft/vscode-cpptools#3214 --- .../Engine.Impl/DebuggedProcess.cs | 19 +++++++++++++++++-- src/MIDebugEngine/Engine.Impl/Variables.cs | 8 ++++---- src/MIDebugEngine/Natvis.Impl/Natvis.cs | 4 ++-- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/MIDebugEngine/Engine.Impl/DebuggedProcess.cs b/src/MIDebugEngine/Engine.Impl/DebuggedProcess.cs index b0db63117..8603a80cd 100755 --- a/src/MIDebugEngine/Engine.Impl/DebuggedProcess.cs +++ b/src/MIDebugEngine/Engine.Impl/DebuggedProcess.cs @@ -25,7 +25,7 @@ internal class DebuggedProcess : MICore.Debugger public AD7Engine Engine { get; private set; } public List VariablesToDelete { get; private set; } public List 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; } @@ -1053,6 +1053,7 @@ private async Task HandleBreakModeEvent(ResultEventArgs results, BreakRequest br varInfo.Dispose(); } this.ActiveVariables.Clear(); + ReturnValue = null; // already disposed above } ThreadCache.MarkDirty(); @@ -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") @@ -1874,6 +1886,9 @@ internal async Task> GetLocalsAndParameters(AD7Thread variables.Add(vi); } + if (ReturnValue != null && ctx.Level == 0) + variables.Add(ReturnValue); + return variables; } diff --git a/src/MIDebugEngine/Engine.Impl/Variables.cs b/src/MIDebugEngine/Engine.Impl/Variables.cs index a5fcb0b7d..f24d82447 100644 --- a/src/MIDebugEngine/Engine.Impl/Variables.cs +++ b/src/MIDebugEngine/Engine.Impl/Variables.cs @@ -60,7 +60,7 @@ internal SimpleVariableInformation(string name, bool isParam = false, string val internal async Task 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; } @@ -73,7 +73,7 @@ public ArgumentList(int level, List args) { } } - internal class VariableInformation : IVariableInformation + internal sealed class VariableInformation : IVariableInformation { public string Name { get; private set; } public string Value { get; private set; } @@ -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; diff --git a/src/MIDebugEngine/Natvis.Impl/Natvis.cs b/src/MIDebugEngine/Natvis.Impl/Natvis.cs index c0e4f3ecc..bcb1c1192 100755 --- a/src/MIDebugEngine/Natvis.Impl/Natvis.cs +++ b/src/MIDebugEngine/Natvis.Impl/Natvis.cs @@ -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) { @@ -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; }