Skip to content
Open
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/Natvis.Impl/Natvis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ private IVariableInformation[] ExpandVisualized(IVariableInformation variable)
// <ValueNode>m_element</ValueNode>
// </LinkedListItems>
LinkedListItemsType item = (LinkedListItemsType)i;
if (String.IsNullOrWhiteSpace(item.Condition))
if (!String.IsNullOrWhiteSpace(item.Condition))
{
if (!EvalCondition(item.Condition, variable, visualizer.ScopedNames, visualizer.Intrinsics))
continue;
Expand Down
50 changes: 48 additions & 2 deletions test/CppTests/Tests/NatvisTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public NatvisTests(ITestOutputHelper outputHelper) : base(outputHelper)
private const string NatvisSourceName = "main.cpp";

// These line numbers will need to change if src/natvis/main.cpp changes
private const int SimpleClassAssignmentLine = 65;
private const int ReturnSourceLine = 80;
private const int SimpleClassAssignmentLine = 66;
private const int ReturnSourceLine = 90;

[Theory]
[RequiresTestSettings]
Expand Down Expand Up @@ -674,6 +674,52 @@ public void TestHideRawView(ITestSettings settings)
}
}

[Theory]
[DependsOnTest(nameof(CompileNatvisDebuggee))]
[RequiresTestSettings]
public void TestLinkedListItemsCondition(ITestSettings settings)
{
this.TestPurpose("This test checks that a Condition attribute on LinkedListItems is evaluated correctly.");
this.WriteSettings(settings);

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

using (IDebuggerRunner runner = CreateDebugAdapterRunner(settings))
{
this.Comment("Configure launch");
string visFile = Path.Join(debuggee.SourceRoot, "visualizer_files", "Simple.natvis");

LaunchCommand launch = new LaunchCommand(settings.DebuggerSettings, debuggee.OutputPath, visFile, false);
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 LinkedListItems with Condition='isActive' when isActive is true");
var activeList = currentFrame.GetVariable("activeList");
Assert.Contains("active=true", activeList.Value);
Assert.Equal("3", activeList.GetVariable("Count").Value);
Assert.True(activeList.Variables.ContainsKey("[0]"), "activeList should show indexed children when condition is true");

this.Comment("Verifying LinkedListItems with Condition='isActive' when isActive is false");
var inactiveList = currentFrame.GetVariable("inactiveList");
Assert.Contains("active=false", inactiveList.Value);
Assert.Equal("2", inactiveList.GetVariable("Count").Value);
Assert.False(inactiveList.Variables.ContainsKey("[0]"), "inactiveList should not show indexed children when condition is false");
}

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

#endregion
}
}
25 changes: 25 additions & 0 deletions test/CppTests/debuggees/natvis/src/ConditionalLinkedList.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <cstddef>

class ConditionalLinkedList
{
private:
struct Node {
int data;
Node* next;
Node(int value) : data(value), next(NULL) {}
};

Node* head;
int numElements;
bool isActive;

public:
ConditionalLinkedList(bool active) : head(NULL), numElements(0), isActive(active) {}

void Add(int val) {
Node* n = new Node(val);
n->next = head;
head = n;
numElements++;
}
};
10 changes: 10 additions & 0 deletions test/CppTests/debuggees/natvis/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "SimpleMatrix.h"
#include "SimpleTemplated.h"
#include "DataPoint.h"
#include "ConditionalLinkedList.h"

class SimpleDisplayObject
{
Expand Down Expand Up @@ -77,5 +78,14 @@ int main(int argc, char** argv)
DataPoint dp(42);
DataPoint *dpPtr = &dp;

ConditionalLinkedList activeList(true);
activeList.Add(10);
activeList.Add(20);
activeList.Add(30);

ConditionalLinkedList inactiveList(false);
inactiveList.Add(100);
inactiveList.Add(200);

return 0;
}
14 changes: 14 additions & 0 deletions test/CppTests/debuggees/natvis/src/visualizer_files/Simple.natvis
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,18 @@
<DisplayString>{{ {this}={*this} }}</DisplayString>
</Type>

<Type Name="ConditionalLinkedList">
<DisplayString>{{ active={isActive}, count={numElements} }}</DisplayString>
<Expand>
<Item Name="IsActive">isActive</Item>
<Item Name="Count">numElements</Item>
<LinkedListItems Condition="isActive">
<Size>numElements</Size>
<HeadPointer>head</HeadPointer>
<NextPointer>next</NextPointer>
<ValueNode>data</ValueNode>
</LinkedListItems>
</Expand>
</Type>

</AutoVisualizer>
Loading