You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/debugger/create-custom-views-of-native-objects.md
+53-66Lines changed: 53 additions & 66 deletions
Original file line number
Diff line number
Diff line change
@@ -10,11 +10,11 @@ ms.tgt_pltfrm: ""
10
10
ms.topic: "article"
11
11
f1_keywords:
12
12
- "natvis"
13
-
dev_langs:
14
-
- "FSharp"
15
-
- "VB"
16
-
- "CSharp"
17
-
- "C++"
13
+
#dev_langs:
14
+
# - "FSharp"
15
+
# - "VB"
16
+
# - "CSharp"
17
+
# - "C++"
18
18
ms.assetid: 2d9a177a-e14b-404f-a6af-49498eff0bd7
19
19
caps.latest.revision: 19
20
20
author: "mikejo5000"
@@ -66,8 +66,7 @@ The Visual Studio Natvis framework lets you customize the way Visual Studio disp
66
66
67
67
The basic structure of a .natvis file is one or more `Type` elements, where each `Type` element represents a visualization entry for a type whose fully qualified name is specified in the `Name` attribute.
@@ -125,10 +124,10 @@ The Visual Studio Natvis framework lets you customize the way Visual Studio disp
125
124
To control how an expression is displayed in a variable window, you can use any of the format specifiers that are described in the [Format Specifiers](../debugger/format-specifiers-in-cpp.md#BKMK_Visual_Studio_2012_format_specifiers) section of the [Format Specifiers in C++](../debugger/format-specifiers-in-cpp.md) topic. Note that format specifiers are ignored when the virtualization entry is used internally by Natvis, such as the `Size` expression in in a [ArrayItems expansion](../debugger/create-custom-views-of-native-objects.md#BKMK_ArrayItems_expansion).
126
125
127
126
## Natvis views
128
-
Natvis views allow you to see any type in more than one way. For example, you can define a view named **simple** that gives you a simplified view of a type. For example, here is the visualization of `std::vector`:
127
+
Natvis views allow you to see any type in more than one way. For example, you can define a view named **simple** that gives you a simplified view of a type. For example, here is the visualization of `std::vector`:
@@ -184,8 +182,8 @@ The Visual Studio Natvis framework lets you customize the way Visual Studio disp
184
182
185
183
**Templated classes** The `Name` attribute of the `Type` element accepts an asterisk `*` as a wildcard character that can be used for templated class names:
@@ -201,8 +199,8 @@ The Visual Studio Natvis framework lets you customize the way Visual Studio disp
201
199
#### Inheritable attribute
202
200
You can specify whether a visualization applies only to a base type or to a base type and all derived types with the optional `Inheritable` attribute. In the following, the visualization applies only to the `BaseClass` type:
@@ -216,17 +214,17 @@ The Visual Studio Natvis framework lets you customize the way Visual Studio disp
216
214
217
215
In the following example, we will first parse the entry that matches the 2015 STL, and if that fails to parse, we will use the alternate entry for the 2013 version of the STL:
@@ -237,7 +235,7 @@ The Visual Studio Natvis framework lets you customize the way Visual Studio disp
237
235
#### <aname="BKMK_Versioning"></a> Version element
238
236
Use the `Version` element to scope visualizations to specific modules and their versions so that name collisions can be minimized and different visualizations can be used for different versions of the types. For example:
@@ -252,7 +250,7 @@ The Visual Studio Natvis framework lets you customize the way Visual Studio disp
252
250
#### Optional attribute
253
251
The `Optional` attribute can appear on any node. If any sub-expression inside an optional node fails to parse, that node is ignored, but the rest of the Type element is still valid. In the following type, `[State]` is non-optional, but `[Exception]` is optional. This means that if `MyNamespace::MyClass` contains a field named _`M_exceptionHolder`, you will still both `[State]` node and the `[Exception]` node, but if the `_M_exceptionHolder` is missing, you will see only the `[State]` node.
254
252
255
-
```xml
253
+
```xml
256
254
<TypeName="MyNamespace::MyClass">
257
255
<Expand>
258
256
<ItemName="[State]">_M_State</Item>
@@ -264,8 +262,8 @@ The Visual Studio Natvis framework lets you customize the way Visual Studio disp
The optional `Condition` attribute is available for many visualization elements and specifies when a visualization rule should be used. If the expression inside the condition attribute resolves to `false`, then the visualization rule specified by the element is not applied. If it evaluates to true, or if there is no `Condition` attribute, then the visualization rule is applied to the type. You can use this attribute for `if-else` logic in the visualization entries. For example, the visualization below has two `DisplayString` elements for a smart pointer type:
@@ -280,8 +278,8 @@ The Visual Studio Natvis framework lets you customize the way Visual Studio disp
280
278
### IncludeView and ExcludeView attributes
281
279
These attributes specify elements that are to be displayed or not displayed in different views. For example, given the Natvis specification of `std::vector`:
A `DisplayString` element specifies the string to be shown as the value of the variable. It accepts arbitrary strings mixed with expressions. Everything inside curly braces is interpreted as an expression. For instance, a `DisplayString` entry like this:
303
301
304
-
```xml
302
+
```xml
305
303
<TypeName="CPoint">
306
304
<DisplayString>{{x={x} y={y}}}</DisplayString>
307
305
</Type>
@@ -320,11 +318,10 @@ The Visual Studio Natvis framework lets you customize the way Visual Studio disp
320
318
### <aname="BKMK_StringView"></a> StringView
321
319
The `StringView` element defines the expression whose value is going to be sent to the built-in text visualizer. For example, suppose we have the following visualization for the `ATL::CStringT` type:
322
320
323
-
```xml
324
-
<TypeName="ATL::CStringT<wchar_t,*>">
321
+
```xml
322
+
<TypeName="ATL::CStringT<wchar_t,*>">
325
323
<DisplayString>{m_pszData,su}</DisplayString>
326
-
</Type>
327
-
324
+
</Type>
328
325
```
329
326
330
327
The `CStringT` object looks like:
@@ -335,12 +332,11 @@ The Visual Studio Natvis framework lets you customize the way Visual Studio disp
335
332
336
333
Adding a `StringView` element will indicate to the debugger that this value can be viewed by a text visualization:
337
334
338
-
```
339
-
<Type Name="ATL::CStringT<wchar_t,*>">
335
+
```xml
336
+
<TypeName="ATL::CStringT<wchar_t,*>">
340
337
<DisplayString>{m_pszData,su}</DisplayString>
341
338
<StringView>m_pszData,su</StringView>
342
339
</Type>
343
-
344
340
```
345
341
346
342
Notice the magnifying glass icon shown next to the value below. Choosing the icon will launch the text visualizer which will display the string that `m_pszData` points to.
@@ -362,7 +358,7 @@ The Visual Studio Natvis framework lets you customize the way Visual Studio disp
The `Item` element is the most basic and the most common element to be used in an `Expand` node. `Item` defines a single child element. For example, suppose that you have a `CRect` class with `top`, `left`, `right`, and `bottom` as its fields and the following visualization entry:
Use the `ArrayItems` node to have the Visual Studio debugger interpret the type as an array and display its individual elements. The visualization for `std::vector` is a good example:
@@ -429,7 +424,6 @@ The Visual Studio Natvis framework lets you customize the way Visual Studio disp
429
424
</ArrayItems>
430
425
</Expand>
431
426
</Type>
432
-
433
427
```
434
428
435
429
`Direction` specifies whether the array is row-major or column-major order. `Rank` specifies the rank of the array. The `Size` element accepts the implicit `$i` parameter which it substitutes with the dimension index to find the length of the array in that dimension. For example, in the previous example, above the expression `_M_extent.M_base[0]` should give the length of the 0th dimension, `_M_extent._M_base[1]` the 1st and so on.
@@ -441,8 +435,8 @@ The Visual Studio Natvis framework lets you customize the way Visual Studio disp
You can use the `ArrayItems` expansion, only if the array elements are laid out contiguously in memory. The debugger gets to the next element by simply incrementing its pointer to the current element. To support cases where you need to manipulate the index to the value node, `IndexListItems` nodes can be used. Here’s a visualization using `IndexListItems` node:
@@ -452,7 +446,6 @@ The Visual Studio Natvis framework lets you customize the way Visual Studio disp
452
446
</IndexListItems>
453
447
</Expand>
454
448
</Type>
455
-
456
449
```
457
450
458
451
You can now use the `[]` operator with an `IndexListItems` expansion, for example `vector[i]`. The `[]` operator can be used with any visualization of a single-dimensional array that uses `ArrayItems` or `IndexListItems`, even if the type itself does not allow this operator (for example `CATLArray`).
@@ -462,8 +455,8 @@ The Visual Studio Natvis framework lets you customize the way Visual Studio disp
If the visualized type represents a linked list, the debugger can display its children by using a `LinkedListItems` node. Here’s the visualization for the `CAtlList` type using this feature:
@@ -475,7 +468,6 @@ The Visual Studio Natvis framework lets you customize the way Visual Studio disp
475
468
</LinkedListItems>
476
469
</Expand>
477
470
</Type>
478
-
479
471
```
480
472
481
473
The `Size` element refers to the length of the list. `HeadPointer` points to the first element, `NextPointer` refers to the next element, and `ValueNode` refers to the value of the item.
@@ -489,10 +481,10 @@ The Visual Studio Natvis framework lets you customize the way Visual Studio disp
489
481
490
482
The visualizer for CAtlMap is an excellent example of where `CustomListItems` is appropriate.
If the visualized type represents a tree, the debugger can walk the tree and display its children by using a `TreeItems` node. Here’s the visualization for the `std::map` type using this feature:
@@ -536,7 +528,6 @@ The Visual Studio Natvis framework lets you customize the way Visual Studio disp
536
528
</TreeItems>
537
529
</Expand>
538
530
</Type>
539
-
540
531
```
541
532
542
533
The syntax is very similar to the `LinkedListItems` node. `LeftPointer`, `RightPointer`, and `ValueNode` are evaluated under the context of the tree node class, and `ValueNode` can be left empty or have `this` to refer to the tree node itself.
@@ -548,36 +539,34 @@ The Visual Studio Natvis framework lets you customize the way Visual Studio disp
548
539
549
540
To see the values of the vector, you have to drill down two levels in the variable window passing through _Myptr member. By adding an `ExpandedItem` element, you can eliminate the `_Myptr` variable from the hierarchy and directly view the vector elements::
The example below shows how to aggregate properties from the base class in a derived class. Suppose the `CPanel` class derives from `CFrameworkElement`. Instead of repeating the properties that come from the base `CFrameworkElement` class, the `ExpandedItem` node allows those properties to be appended to the child list of the `CPanel` class. The **nd** format specifier which turns off visualization matching for the derived class is necessary here. Otherwise, the expression `*(CFrameworkElement*)this` will cause the `CPanel` visualization to be applied again because the default visualization type matching rules consider it the most appropriate one. Using the **nd** format specifier instructs the debugger to use the base class visualization or the base class default expansion if the base class doesn’t have a visualization.
Where the `ExpandedItem` element provides a flatter view of data by eliminating hierarchies, the `Synthetic` node does the opposite. It allows you to create an artificial child element (that is, a child element that is not a result of an expression). This child element can contain children elements of its own. In the following example, the visualization for the `Concurrency::array` type uses a `Synthetic` node to show a diagnostic message to the user:
@@ -633,9 +621,8 @@ The Visual Studio Natvis framework lets you customize the way Visual Studio disp
633
621
634
622
Each type defined in the .natvis file must explicitly list the UI visualizers that can display them. The debugger matches the visualizer references in the type entries to match types with the registered visualizers. For example, the following type entry for `std::vector` references the UIVisualizer in our example above.
0 commit comments