Skip to content

Commit c713778

Browse files
WardenGnawmpeyrotc
andauthored
Fix Rank > 1 Display Strings for Natvis (#1406)
* Fix Rank > 1 Display Strings for Natvis This PR fixes the display string for ArrayItems with Rank > 1 when the "[More...]" is expanded. Before "[More...]" will expand starting at [0,0] instead of [0,50] for the first expansion since the offsets are at 50. --------- Co-authored-by: Marco Peyrot <mapeyrot@microsoft.com>
1 parent 9233ae1 commit c713778

6 files changed

Lines changed: 14 additions & 36 deletions

File tree

src/MIDebugEngine/Natvis.Impl/Natvis.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -676,12 +676,8 @@ private IVariableInformation[] ExpandVisualized(IVariableInformation variable)
676676

677677
for (uint index = 0; index < requestedSize; ++index)
678678
{
679-
string displayName = (startIndex + index).ToString(CultureInfo.InvariantCulture);
680-
if (rank > 1)
681-
{
682-
displayName = GetDisplayNameFromArrayIndex(index, rank, dimensions, isForward);
683-
}
684-
679+
uint currentOffsetIndex = startIndex + index;
680+
string displayName = rank > 1 ? GetDisplayNameFromArrayIndex(currentOffsetIndex, rank, dimensions, isForward) : currentOffsetIndex.ToString(CultureInfo.InvariantCulture);
685681
children.Add(new SimpleWrapper("[" + displayName + "]", _process.Engine, arrayExpr.Children[index]));
686682
}
687683

test/CppTests/Tests/NatvisTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ public void TestArrayItems(ITestSettings settings)
181181

182182
// Multi-dimensional array
183183
var matrix = currentFrame.GetVariable("matrix");
184-
Assert.Equal("3", matrix.GetVariable("[1,1]").Value);
184+
Assert.Equal("1", matrix.GetVariable("[0,1]").Value);
185+
Assert.Equal("51", matrix.GetVariable("[More...]").GetVariable("[0,51]").Value);
185186
}
186187

187188
runner.Expects.ExitedEvent(exitCode: 0).TerminatedEvent().AfterContinue();
Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
class SimpleMatrix
22
{
33
public:
4-
int m_size1;
5-
int m_size2;
6-
bool m_fUseSize1;
4+
int m_rows;
5+
int m_cols;
76
int* m_pData;
87

9-
SimpleMatrix(int size1, int size2, bool fUseSize1)
8+
SimpleMatrix(int row, int col)
109
{
11-
m_size1 = size1;
12-
m_size2 = size2;
13-
m_fUseSize1 = fUseSize1;
10+
m_rows = row;
11+
m_cols = col;
1412

15-
m_pData = new int[GetSize()];
13+
m_pData = new int[row * col];
1614

17-
for (int i = 0; i < GetSize(); i++)
15+
for (int i = 0; i < row * col; i++)
1816
{
1917
m_pData[i] = i;
2018
}
2119
}
22-
23-
int GetSize()
24-
{
25-
return m_fUseSize1 ? m_size1 : m_size2;
26-
}
2720
};

test/CppTests/debuggees/natvis/src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ int main(int argc, char** argv)
4646
SimpleClass* simpleClass = nullptr;
4747
simpleClass = new SimpleClass();
4848

49-
SimpleMatrix matrix(5, 8, false);
49+
SimpleMatrix matrix(2, 256);
5050

5151
return 0;
52-
}
52+
}

test/CppTests/debuggees/natvis/src/visualizer_files/Simple.natvis

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<ArrayItems>
6565
<Direction>Forward</Direction>
6666
<Rank>2</Rank>
67-
<Size>($i == 1) ? 2 : m_size2/2</Size>
67+
<Size>($i == 0) ? m_rows : m_cols</Size>
6868
<ValuePointer>m_pData</ValuePointer>
6969
</ArrayItems>
7070
</Expand>

test/CppTests/debuggees/natvis/src/visualizer_files/Simple2.natvis

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,4 @@
2727
</TreeItems>
2828
</Expand>
2929
</Type>
30-
31-
<Type Name="SimpleMatrix">
32-
<DisplayString>SimpleMatrix</DisplayString>
33-
<Expand>
34-
<ArrayItems>
35-
<Direction>Forward</Direction>
36-
<Rank>2</Rank>
37-
<Size>($i == 1) ? 2 : m_size2/2</Size>
38-
<ValuePointer>m_pData</ValuePointer>
39-
</ArrayItems>
40-
</Expand>
41-
</Type>
4230
</AutoVisualizer>

0 commit comments

Comments
 (0)