Skip to content

Commit aca51e9

Browse files
committed
Merged main into live
2 parents 696fbd3 + 89bf837 commit aca51e9

26 files changed

+209
-31
lines changed

docs/debugger/create-custom-views-of-native-objects.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Create custom views of C++ objects
33
description: Use the Natvis framework to customize the way Visual Studio displays native types in the debugger for your applications.
4-
ms.date: 02/20/2024
4+
ms.date: 01/10/2025
55
ms.topic: how-to
66
f1_keywords:
77
- natvis
@@ -675,7 +675,7 @@ While the `ExpandedItem` element provides a flatter view of data by eliminating
675675

676676
### Intrinsic expansion
677677

678-
A custom intrinsic function that can be called from an expression. An `<Intrinsic>` element must be accompanied by a debugger component that implements the function through the IDkmIntrinsicFunctionEvaluator140 interface.
678+
A custom intrinsic function that can be called from an expression. An `<Intrinsic>` element must be accompanied by a debugger component that implements the function through the IDkmIntrinsicFunctionEvaluator140 interface. For more information on implementing a custom intrinsic function, see [Implement NatVis custom intrinsic function](../debugger/implementing-natvis-intrinsic-function.md).
679679

680680
```xml
681681
<Type Name="std::vector&lt;*&gt;">
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
---
2+
title: Implement NatVis custom intrinsic function
3+
description: Learn how to use the Natvis framework to implement a custom intrinsic function.
4+
ms.date: 01/09/2025
5+
ms.topic: how-to
6+
f1_keywords:
7+
- natvis, intrinsic function
8+
dev_langs:
9+
- C++
10+
author: mikejo5000
11+
ms.author: mikejo
12+
manager: mijacobs
13+
ms.subservice: debug-diagnostics
14+
---
15+
16+
# Implement NatVis custom intrinsic function for C++
17+
18+
In this article, you learn about the guidelines for implementing a custom intrinsic function within a NatVis visualization. For more information about NatVis, see [Create custom views of C++ objects](../debugger/create-custom-views-of-native-objects.md).
19+
20+
## Syntax
21+
22+
A NatVis file may define an intrinsic function using the following syntax:
23+
24+
```xml
25+
<Intrinsic Name="Func" Expression="arg + 1">
26+
<Parameter Name="arg" Type="int" />
27+
</Intrinsic>
28+
```
29+
30+
Once the definition exists, any debugger expression may call the function, like any other function. For example, using the preceding NatVis definition, the expression `Func(3)` evaluates to 4.
31+
32+
An `<Intrinsic>` element may appear either on the file-level, or inside a `<Type>` element, before any other elements. Intrinsic functions defined within a `<Type>` define member functions of that type, while intrinsic functions defined outside a `<Type>` define global functions. For example:
33+
34+
```xml
35+
<?xml version="1.0" encoding="utf-8"?>
36+
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
37+
<Type Name="std::vector&lt;*&gt;">
38+
<Intrinsic Name="size" Expression="_Mypair._Myval2._Mylast - _Mypair._Myval2._Myfirst" />
39+
<Intrinsic Name="capacity" Expression="_Mypair._Myval2._Myend - _Mypair._Myval2._Myfirst" />
40+
</Type>
41+
<Intrinsic Name="LOWORD" Expression="arg & 0xFFFF">
42+
<Parameter Name="arg" Type="unsigned int" />
43+
</Intrinsic>
44+
</AutoVisualizer>
45+
```
46+
47+
In the preceding example, `size()` and `capacity()` are defined as member functions of the `std::vector` class,
48+
so whenever an expression evaluates `vector.size()`, it will actually evaluate
49+
`vector._Mypair._Myval2._Mylast - vector._Mypair._Myval2._Myfirst`, rather than perform a func-eval.
50+
Similarly, `LOWORD(0x12345678)` returns `0x5678`, also without func-eval.
51+
52+
For another example, see the [Intrinsic expansion](../debugger/create-custom-views-of-native-objects.md#intrinsic-expansion).
53+
54+
## Guidelines for using an intrinsic function
55+
56+
Be aware of the following guidelines when using an intrinsic function:
57+
58+
- Intrinsic functions may be overloaded, either with PDB-defined functions, or with each other.
59+
60+
- When an intrinsic function conflicts with a PDB-defined function with the same name and argument list, the intrinsic function will win. You can't func-eval the PDB function if an equivalent intrinsic function exists.
61+
62+
- You can't take the address of an intrinsic function; you can only call it.
63+
64+
- Intrinsic member functions must belong to the default view of the respective type in order to be evaluated in an expression. For example, a type entry with an `IncludeView` constraint may not specify an intrinsic function.
65+
66+
- Intrinsic functions may be called from any expression, including NatVis expressions. Intrinsic functions may also call each other. However, intrinsic functions that use recursion are currently not supported. For example:
67+
68+
```xml
69+
<!-- OK -->
70+
<Intrinsic Name="Func2" Expression="this-&gt;Func3(arg + 1)">
71+
<Parameter Name="arg" Type="int" />
72+
</Intrinsic>
73+
<Intrinsic Name="Func3" Expression="arg + 1">
74+
<Parameter Name="arg" Type="int"/>
75+
</Intrinsic>
76+
77+
<!-- Unsupported -->
78+
<Intrinsic Name="Func2" Expression="this-&gt;Func3(arg + 1)">
79+
<Parameter Name="arg" Type="int" />
80+
</Intrinsic>
81+
<Intrinsic Name="Func3" Expression="Func2(arg + 1)">
82+
<Parameter Name="arg" Type="int"/>
83+
</Intrinsic>
84+
85+
<!-- Also unsupported-->
86+
<Intrinsic Name="Fib" Expression="(n &lt;= 1) ? 1 : Fib(n - 1) + Fib(n - 2)">
87+
<Parameter Name="n" Type="int"/>
88+
</Intrinsic>
89+
```
90+
91+
- By default, intrinsic functions are assumed to be side-effect free. That is, they can be called in contexts that disallow side effects, and the implementation expression isn't allowed to contain side effects.
92+
93+
The definition can override this behavior by specifying the `SideEffect` attribute in the declaration. If the function is marked as having side effects, side effects in the implementation expression become permitted. However, invoking the function in contexts where side effects are prohibited is no longer permitted.
94+
95+
- When the definitions of two intrinsic functions conflict with each other (same name, same signature), the last one wins (within the same file).
96+
97+
Within different files, the instance in the file with higher priority wins (project is higher than user directory, which is higher than install directory). If a higher-priority definition contains an expression that does not parse, that definition is ignored, and the next-highest priority definition is used instead.
98+
99+
## Guidelines to implement an Intrinsic function
100+
101+
Intrinsic functions support two possible forms of implementation:
102+
103+
- Expression-based
104+
105+
The NatVis file defines an expression that evaluates to the return value of the function. The expression may use any arguments passed into it declared as `<Parameter>` elements. Functions defined within a class are also assumed to be "instance" functions, and may access the "this" pointer as well.
106+
107+
- Extension-based
108+
109+
The NatVis file provides instructions for invoking a debugger extension to actually evaluate the function. A debugger extension has full access to the Concord API, and has the ability to perform tasks that aren't possible within a NatVis expression.
110+
111+
To provide an extension-based implementation, the `<Intrinsic>` element should omit the `Expression` attribute and, instead, provide `SourceId`, `LanguageId`, `Id`, and `ReturnType` attributes, as provided in the following example:
112+
113+
```xml
114+
<Intrinsic Name="MyFunc" SourceId="a665fa54-6e7d-480e-a80b-1fc1202e9646" LanguageId="3a12d0b7-c26c-11d0-b442-00a0244a1dd2" Id="1000" ReturnType="double">
115+
<Parameter Type="int" />
116+
<Parameter Type="int" />
117+
<Parameter Type="int" />
118+
</Intrinsic>
119+
```
120+
121+
To implement the function, the debugger extension must implement the `IDkmIntrinsicFunctionEvaluator140` interface, using `LanguageId` and
122+
`SourceId` filters that match the corresponding values of the `<Intrinsic>` element in the NatVis file. When the function is called, the call translates into the component's `Execute()` method:
123+
124+
```cpp
125+
STDMETHOD(Execute)(
126+
_In_ Evaluation::IL::DkmILExecuteIntrinsic* pExecuteIntrinsic,
127+
_In_ Evaluation::DkmILContext* pILContext,
128+
_In_ Evaluation::IL::DkmCompiledILInspectionQuery* pInspectionQuery,
129+
_In_ const DkmArray<Evaluation::IL::DkmILEvaluationResult*>& Arguments,
130+
_In_opt_ DkmReadOnlyCollection<Evaluation::DkmCompiledInspectionQuery*>* pSubroutines,
131+
_Out_ DkmArray<Evaluation::IL::DkmILEvaluationResult*>* pResults,
132+
_Out_ Evaluation::IL::DkmILFailureReason* pFailureReason
133+
);
134+
```
135+
136+
The component receives the bytes of each argument via the `Arguments` argument. If the function in question is a member function,
137+
the `this` pointer comes first, followed by the explicit arguments. The component should return the result by allocating
138+
a single-element array in `pResults`, storing the bytes of the return value.
139+
140+
Use the following guidelines to implement functions:
141+
142+
- It's illegal to "mix and match" the two implementation forms. That is, you can't include both an expression and a source ID.
143+
144+
- Specifying a return type for an expression-based implementation is allowed, but not required. If a return type is specified, the return type of the expression must exactly match it (no implicit casting allowed). If a return type isn't specified, the return type is inferred from the expression. Any extension-based implementation must state a return type in the NatVis file.
145+
146+
- Non-recursive calls to other intrinsic functions are allowed. Recursion isn't allowed.
147+
148+
- If the function has side effects, you must specify `SideEffect="true"` in the declaration. It's illegal for an expression-based
149+
implementation to have side effects in the expression without declaring the function to have side effects. Invoking an extension-based
150+
implementation to have side effects without declaring the function as having side effects is undefined behavior, and should be avoided.
151+
152+
- Varargs intrinsic functions are allowed. To declare a varargs function, specify `Varargs="true"` in the declaration. While it's legal for an expression-based implementation to declare a `vararg` function, currently, only extension-based implementations have a way to access the variable arguments. With an extension-based implementation, the `Execute()` function receives all the arguments that are actually passed in, not just the declared arguments.
153+
154+
- Intrinsic functions consuming a class/struct/union type as an argument type aren't supported. Returning a class/struct/union type is OK. (A pointer or reference to a class/struct/union type is OK as an argument type).
155+
156+
## Customize the icon for calls to intrinsic functions.
157+
158+
By default, when you call an intrinsic function, the expression is given the pink diamond icon in the **Watch** window associated with function calls. You can override this behavior by specifying the `Category` attribute using one of the following values:
159+
160+
- Method. Use the pink diamond icon, typically used with method calls (default).
161+
- Property. Use the black wrench icon, typically used with properties.
162+
- Data. Use the blue diamond icon, typically used with data.
163+
164+
By combining intrinsic functions with the `<Item>` element, it's possible to author a NatVis file where item expressions have the wrench property icon:
165+
166+
```xml
167+
<Type Name="MyClass">
168+
<Intrinsic Name="GetValue" ReturnType="int" Expression="m_value" Category="Property" />
169+
<Expand>
170+
<Item Name="Value">this-&gt;GetValue()</Item>
171+
</Expand>
172+
</Type>
173+
```
174+
175+
> [!NOTE]
176+
> Placing the icon choice on the function level, rather than the `<Item>` level, avoids issues where the icon customization is lost when the full name is evaluated. Because the full name includes a call to the function, it has the same icon customization as the `<Item>` itself.
177+

docs/debugger/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@
170170
items:
171171
- name: Create custom views of C++ objects
172172
href: create-custom-views-of-native-objects.md
173+
- name: Implement NatVis custom intrinsic function
174+
href: implementing-natvis-intrinsic-function.md
173175
- name: C++ custom visualizer compatibility
174176
href: visual-cpp-custom-visualizer-compatibility.md
175177
- name: Custom views (.NET)

docs/extensibility/vsix/get-started/extension-anatomy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ A VSIX package is a .vsix file that contains one or more Visual Studio extension
1515

1616
An extension project is a C# project with a few extras that make it unique. The following video explores an extension project to better understand how extension projects work:
1717

18-
> [!VIDEO https://www.microsoft.com/videoplayer/embed/RWPhtJ]
18+
> [!VIDEO https://learn-video.azurefd.net/vod/player?id=cc3dbbb6-c221-469e-8320-208d816eff0a]
1919
2020
## File structure
2121
When creating new extensions using the **VSIX Project w/Command (Community)** template, the file structure looks as follows:

docs/extensibility/vsix/get-started/first-extension.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The extension you'll be writing today adds a command that inserts a new guid int
1717

1818
If you're a visual learner, check out this short video of someone following the tutorial.
1919

20-
> [!VIDEO https://www.microsoft.com/videoplayer/embed/RWPmjK]
20+
> [!VIDEO https://learn-video.azurefd.net/vod/player?id=fbe3f134-ac8d-461b-aa19-b114e73e0090]
2121
2222
Before you start writing your first Visual Studio extension (it's easy, I promise!), make sure you've got the [tools needed](get-tools.md).
2323

docs/extensibility/vsix/get-started/get-tools.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ To write extensions you have to install the extensibility workload. That's techn
1515

1616
The following video introduces the tools you'll need.
1717

18-
> [!VIDEO https://www.microsoft.com/videoplayer/embed/RWPhtT]
18+
> [!VIDEO https://learn-video.azurefd.net/vod/player?id=6535f5f1-df90-4ab7-ba5e-c5131357e2a2]
1919
2020
## Install extensibility workload
2121

docs/extensibility/vsix/get-started/useful-resources.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ These resources can help you better navigate the world of Visual Studio extensib
1515

1616
The following video introduces useful resources for Visual Studio extension authors.
1717

18-
> [!VIDEO https://www.microsoft.com/videoplayer/embed/RWP8Kw]
18+
> [!VIDEO https://learn-video.azurefd.net/vod/player?id=6348394e-2792-47d4-813c-7f01d6e343fa]
1919
2020
## Resources
2121
Here are some useful resources that can help you in your extension journey.

docs/extensibility/vsix/publish/checklist.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Here's a list of things to make sure to remember before publishing your Visual S
1414

1515
The following video introduces best practices to ensure your extension is the best it can be.
1616

17-
> [!VIDEO https://www.microsoft.com/videoplayer/embed/RWPmjM]
17+
> [!VIDEO https://learn-video.azurefd.net/vod/player?id=1572ac04-7818-426c-a453-1a5c2ac3f0fb]
1818
1919
## Adhere to threading rules
2020
Add the [Microsoft.VisualStudio.SDK.Analyzers](https://www.nuget.org/packages/Microsoft.VisualStudio.SDK.Analyzers/) NuGet package to your VSIX project, which will help you discover and fix common violations of best practices on threading.
@@ -55,4 +55,4 @@ It can be tempting to support versions of Visual Studio all the way back to Visu
5555
Here are our recommendations for deciding what versions of Visual Studio to support:
5656

5757
* Support only the previous and current version of Visual Studio - don't support older versions if possible.
58-
* Don't specify an open ended version range, for example,`[16.0,)`. Learn more about [version ranges](https://devblogs.microsoft.com/visualstudio/visual-studio-extensions-and-version-ranges-demystified/).
58+
* Don't specify an open ended version range, for example,`[16.0,)`. Learn more about [version ranges](https://devblogs.microsoft.com/visualstudio/visual-studio-extensions-and-version-ranges-demystified/).

docs/extensibility/vsix/publish/create-extension-pack.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ms.subservice: extensibility-integration
1313
This article shows you how to create an Extension Pack. An Extension Pack is a set of extensions that can be installed together. Extension Packs enable you to easily share your favorite extensions with other users or bundle a set of extensions together for a particular scenario.
1414

1515
The following video introduces how to create Extension Packs.
16-
> [!VIDEO https://www.microsoft.com/videoplayer/embed/RWP8KA]
16+
> [!VIDEO https://learn-video.azurefd.net/vod/player?id=00230c46-d0f6-4439-8fa0-a205243e764e]
1717
1818
## Create from project template
1919
The Extension Pack project template creates an Extension Pack with set of extensions that can be installed together.

docs/extensibility/vsix/publish/publish-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Make sure to check out [the checklist](checklist.md) to ensure your extension fo
1919
## Publish to the Marketplace
2020
The following video shows you how to share your new extension by uploading and publishing it to the Marketplace.
2121

22-
> [!VIDEO https://www.microsoft.com/videoplayer/embed/RWP8KB]
22+
> [!VIDEO https://learn-video.azurefd.net/vod/player?id=777d876f-78a1-4a35-b5e9-df4a5a55c683]
2323
2424
## Publish on a private gallery
2525
You can also host your own gallery of extensions either internally in your organization or in public, on any web host.

docs/extensibility/vsix/recipes/custom-tool-windows.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Custom tool windows are great options for adding complex UI to Visual Studio.
1515

1616
A tool window is a core UI concept in Visual Studio, and the following video will show you how to add a custom window.
1717

18-
> [!VIDEO https://www.microsoft.com/videoplayer/embed/RWPhtK]
18+
> [!VIDEO https://learn-video.azurefd.net/vod/player?id=ad69f1f5-0c9a-46b1-9d13-9e740f85478e]
1919
2020
A tool window is a window that can be moved around and docked just like the Solution Explorer, Error List, and other well-known tool windows. A tool window consists of an outer shell provided by Visual Studio and a custom inner UI control, which is usually a XAML `<usercontrol>`, provided by the extension.
2121

docs/extensibility/vsix/recipes/settings-options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Storing and retrieving settings is a must-have for many extensions. Let's explor
2121

2222
The following video shows you ho to add options to an extension.
2323

24-
> [!VIDEO https://www.microsoft.com/videoplayer/embed/RWPmjL]
24+
> [!VIDEO https://learn-video.azurefd.net/vod/player?id=5e1d8c37-2f54-4ab1-82e1-a66d075064fd]
2525
2626
Here's what it should look like in the **Tools > Options** dialog.
2727

docs/extensibility/vsix/visual-studio-community-toolkit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This toolkit will help you write successful Visual Studio extensions and there's
1515

1616
The following video introduces you to the Visual Studio extensibility model.
1717

18-
> [!VIDEO https://www.microsoft.com/videoplayer/embed/RWPht8]
18+
> [!VIDEO https://learn-video.azurefd.net/vod/player?id=70bf01cb-3b67-4476-a250-47558b7038b4]
1919
2020
## Pick your starting point
2121

subscriptions/admin-roles.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ There are two different roles in the new Visual Studio Subscriptions Admin Porta
1717
**Admins:** Only super admins can assign new admins and add them to agreements. An admin can only manage subscribers in the agreements that the super admin assigns to them.
1818

1919
Watch a demonstration about how to manage admins.
20-
> [!VIDEO https://www.microsoft.com/videoplayer/embed/RE4th6L]
20+
> [!VIDEO https://learn-video.azurefd.net/vod/player?id=6fc722fe-af29-45f7-864d-b4e32c0fea4f]
2121
2222
## Assigning admins
2323

@@ -51,4 +51,4 @@ To assign new admins:
5151

5252
+ Learn how to [assign subscriptions](assign-license.md)
5353
+ Learn more about the full range of [subscription benefits](https://visualstudio.microsoft.com/vs/benefits/)
54-
+ [Set agreement preferences](admin-preferences.md)
54+
+ [Set agreement preferences](admin-preferences.md)

subscriptions/assign-github.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Customers who have Enterprise Agreements (EA) with Microsoft are eligible to pur
1414

1515
Check out this video for steps to set up your organization and invite new members, or follow the step-by-step instructions below the video.
1616

17-
> [!VIDEO https://www.microsoft.com/videoplayer/embed/RWVcut]
17+
> [!VIDEO https://learn-video.azurefd.net/vod/player?id=f3e34a55-addb-4b08-8e4d-680c196f80dd]
1818
1919
Now that you purchased Visual Studio subscriptions with GitHub Enterprise, let’s get your organization set up. We begin with instructions for new GitHub Enterprise customers. If you’re an existing GitHub Enterprise customer, skip ahead to [Assigning Visual Studio subscriptions to organization members](#assign-visual-studio-subscriptions-to-organization-members).
2020

subscriptions/assign-guid.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Admins can now use the Visual Studio Subscriptions Admin Portal to assign specif
1414

1515
Watch the video or read on to learn how to assign specific subscriptions GUIDs to users.
1616

17-
> [!VIDEO https://www.microsoft.com/videoplayer/embed/RE4t4cl]
17+
> [!VIDEO https://learn-video.azurefd.net/vod/player?id=8d05e05a-2069-4e9a-ade1-c302b818e8e8]
1818
1919
## Assign specific subscription GUIDs to users
2020

0 commit comments

Comments
 (0)