Skip to content

Commit

Permalink
User Story 1556887: [MIEngine Natvis] Support size specifiers for poi…
Browse files Browse the repository at this point in the history
…nters as arrays (#1329)

* Handle static sized array case for StripFormatSpecifier()

* Add array pointer test
  • Loading branch information
gc46 authored Jul 15, 2022
1 parent b70358d commit 2d32c7e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/MIDebugEngine/Engine.Impl/Variables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,13 @@ private string StripFormatSpecifier(string exp, out string formatSpecifier)
// TODO: could return '(T(*)[n])(exp)' but requires T
var m = Regex.Match(trimmed, @"^\[?(\d+)\]?$");
if (m.Success)
{
if (_engine.DebuggedProcess.MICommandFactory.Mode == MIMode.Gdb)
return "*" + exp.Substring(0, lastComma) + "@" + trimmed; // this does not work for lldb

return exp.Substring(0, lastComma);
}


// array with dynamic size
if (Regex.Match(trimmed, @"^\[([a-zA-Z_][a-zA-Z_\d]*)\]$").Success)
Expand Down
39 changes: 39 additions & 0 deletions test/CppTests/Tests/NatvisTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,45 @@ public void TestThisConditional(ITestSettings settings)
}
}

[Theory]
[DependsOnTest(nameof(CompileNatvisDebuggee))]
[RequiresTestSettings]
// Disable on macOS
[UnsupportedDebugger(SupportedDebugger.Lldb, SupportedArchitecture.x64 | SupportedArchitecture.x86)]
public void TestArrayPointer(ITestSettings settings)
{
this.TestPurpose("This test checks if the comma format specifier is visualized.");
this.WriteSettings(settings);

IDebuggee debuggee = Debuggee.Open(this, settings.CompilerSettings, NatvisName, DebuggeeMonikers.Natvis.Default);

this.Comment("Run the debuggee, check argument count");
using (IDebuggerRunner runner = CreateDebugAdapterRunner(settings))
{
this.Comment("Configure launch");
LaunchCommand launch = new LaunchCommand(settings.DebuggerSettings, debuggee.OutputPath);
runner.RunCommand(launch);

this.Comment("Set Breakpoint");
SourceBreakpoints writerBreakpoints = debuggee.Breakpoints(NatvisSourceName, ReturnSourceLine);
runner.SetBreakpoints(writerBreakpoints);

runner.Expects.StoppedEvent(StoppedReason.Breakpoint).AfterConfigurationDone();

using (IThreadInspector threadInspector = runner.GetThreadInspector())
{
IFrameInspector currentFrame = threadInspector.Stack.First();

this.Comment("Verifying comma format specifier");
int[] expected = { 0, 1, 4, 9 };
currentFrame.AssertEvaluateAsIntArray("arr._array,4", EvaluateContext.Watch, expected);
}

runner.Expects.ExitedEvent(exitCode: 0).TerminatedEvent().AfterContinue();
runner.DisconnectAndVerify();
}
}

#endregion
}
}

0 comments on commit 2d32c7e

Please sign in to comment.