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
+19-4
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@ The same `TextBox` looks much simpler in the variable window when Natvis custom
40
40
41
41
## <aname="BKMK_Using_Natvis_files"></a>Use .natvis files in C++ projects
42
42
43
-
Natvis uses *.natvis* files to specify visualization rules. A *.natvis* file is an XML file with a *.natvis* extension. The Natvis schema is defined in *\<VS Installation Folder\>\Xml\Schemas\natvis.xsd*.
43
+
Natvis uses *.natvis* files to specify visualization rules. A *.natvis* file is an XML file with a *.natvis* extension. The Natvis schema is defined in *\<VS Installation Folder\>\Xml\Schemas\1033\natvis.xsd*.
44
44
45
45
The basic structure of a *.natvis* file is one or more `Type` elements representing visualization entries. The fully qualified name of each `Type` element is specified in its `Name` attribute.
46
46
@@ -127,18 +127,24 @@ The *.natvis* files are evaluated in the following order:
127
127
128
128
3. Any *.natvis* files installed and registered via a VSIX package.
129
129
130
-
::: moniker range="vs-2017"
130
+
::: moniker range=">= vs-2022"
131
131
132
-
4. The user-specific Natvis directory (for example, *%USERPROFILE%\Documents\Visual Studio 2017\Visualizers*).
132
+
4. The user-specific Natvis directory (for example, *%USERPROFILE%\Documents\Visual Studio 2022\Visualizers*).
133
133
134
134
::: moniker-end
135
135
136
-
::: moniker range=">= vs-2019"
136
+
::: moniker range="vs-2019"
137
137
138
138
4. The user-specific Natvis directory (for example, *%USERPROFILE%\Documents\Visual Studio 2019\Visualizers*).
139
139
140
140
::: moniker-end
141
141
142
+
::: moniker range="vs-2017"
143
+
144
+
4. The user-specific Natvis directory (for example, *%USERPROFILE%\Documents\Visual Studio 2017\Visualizers*).
145
+
146
+
::: moniker-end
147
+
142
148
5. The system-wide Natvis directory (*\<VS Installation Folder\>\Common7\Packages\Debugger\Visualizers*). This directory has the *.natvis* files that are installed with Visual Studio. If you have administrator permissions, you can add files to this directory.
143
149
144
150
## Modify .natvis files while debugging
@@ -154,6 +160,7 @@ If you modify the *.natvis* file outside of Visual Studio, the changes don't tak
154
160
Also use the **.natvisreload** command to upgrade the *.natvis* file to a newer version. For example, the *.natvis* file may be checked into source control, and you want to pick up recent changes that somebody else made.
155
161
156
162
## <aname="BKMK_Expressions_and_formatting"></a> Expressions and formatting
163
+
157
164
Natvis visualizations use C++ expressions to specify the data items to display. In addition to the enhancements and limitations of C++ expressions in the debugger, which are described in [Context operator (C++)](../debugger/context-operator-cpp.md), be aware of the following:
158
165
159
166
- Natvis expressions are evaluated in the context of the object being visualized, not the current stack frame. For example, `x` in a Natvis expression refers to the field named **x** in the object being visualized, not to a local variable named **x** in the current function. You can't access local variables in Natvis expressions, although you can access global variables.
@@ -237,6 +244,7 @@ A basic `Type` looks like this example:
237
244
3. What the members of the type should look like when the user expands the type in a variable window (the `Expand` node).
238
245
239
246
#### Templated classes
247
+
240
248
The `Name` attribute of the `Type` element accepts an asterisk `*` as a wildcard character that can be used for templated class names.
241
249
242
250
In the following example, the same visualization is used whether the object is a `CAtlArray<int>` or a `CAtlArray<float>`. If there's a specific visualization entry for a `CAtlArray<float>`, then it takes precedence over the generic one.
@@ -250,9 +258,11 @@ In the following example, the same visualization is used whether the object is a
250
258
You can reference template parameters in the visualization entry by using macros $T1, $T2, and so forth. To find examples of these macros, see the *.natvis* files shipped with Visual Studio.
251
259
252
260
#### <aname="BKMK_Visualizer_type_matching"></a> Visualizer type matching
261
+
253
262
If a visualization entry fails to validate, the next available visualization is used.
254
263
255
264
#### Inheritable attribute
265
+
256
266
The optional `Inheritable` attribute specifies whether a visualization applies only to a base type, or to a base type and all derived types. The default value of `Inheritable` is `true`.
257
267
258
268
In the following example, the visualization applies only to the `BaseClass` type:
@@ -288,6 +298,7 @@ The following example first parses the entry that matches the 2015 STL. If that
288
298
```
289
299
290
300
### Optional attribute
301
+
291
302
You can put an `Optional` attribute on any node. If a subexpression inside an optional node fails to parse, the debugger ignores that node, but applies the rest of the `Type` rules. In the following type, `[State]` is non-optional, but `[Exception]` is optional. If `MyNamespace::MyClass` has a field named _`M_exceptionHolder`, both the `[State]` node and the `[Exception]` node appear, but if there's no `_M_exceptionHolder` field, only the `[State]` node appears.
292
303
293
304
```xml
@@ -336,6 +347,7 @@ The `IncludeView` and `ExcludeView` attributes specify elements to display or no
336
347
You can use the `IncludeView` and `ExcludeView` attributes on types and on individual members.
337
348
338
349
### <aname="BKMK_Versioning"></a> Version element
350
+
339
351
The `Version` element scopes a visualization entry to a specific module and version. The `Version` element helps avoid name collisions, reduces inadvertent mismatches, and allows different visualizations for different type versions.
340
352
341
353
If a common header file that is used by different modules defines a type, the versioned visualization appears only when the type is in the specified module version.
@@ -437,6 +449,7 @@ The debugger automatically creates the **[Raw View]** node for every custom expa
437
449
> If the expression of the item element points to a complex type, the **Item** node itself is expandable.
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:
441
454
442
455
```xml
@@ -633,6 +646,7 @@ The following example shows how to aggregate properties from the base class in a
633
646
The **nd** format specifier, which turns off visualization matching for the derived class, is necessary here. Otherwise, the expression `*(CFrameworkElement*)this` would cause the `CPanel` visualization to be applied again, because the default visualization type matching rules consider it the most appropriate one. Use the **nd** format specifier to instruct the debugger to use the base class visualization, or the default expansion if the base class has no visualization.
While 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 isn't a result of an expression. The artificial element can have child 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:
637
651
638
652
```xml
@@ -699,6 +713,7 @@ Each type defined in the *.natvis* file must explicitly list any UI visualizers
699
713
You can see an example of a `UIVisualizer` in the [Image Watch](https://marketplace.visualstudio.com/search?term=%22Image%20Watch%22&target=VS&category=All%20categories&vsVersion=&sortBy=Relevance) extension used to view in-memory bitmaps.
700
714
701
715
### <aname="BKMK_CustomVisualizer"></a>CustomVisualizer element
716
+
702
717
`CustomVisualizer` is an extensibility point that specifies a VSIX extension that you write to control visualizations in Visual Studio code. For more information about writing VSIX extensions, see the [Visual Studio SDK](../extensibility/visual-studio-sdk.md).
703
718
704
719
It's a lot more work to write a custom visualizer than an XML Natvis definition, but you're free from constraints about what Natvis does or doesn't support. Custom visualizers have access to the full set of debugger extensibility APIs, which can query and modify the debuggee process or communicate with other parts of Visual Studio.
0 commit comments