Skip to content

Conversation

@iridinite
Copy link
Contributor

This would result in array elements in Natvis using incorrect expressions. For instance, the first array element would use the literal [0] as expression instead of the actual element path, which is on its own meaningless.

This affects a lot of other code: VariableInformation.Size and Address make use of FullName, it's used for Natvis, and it is passed to AD7 through DEBUG_PROPERTY_INFO.bstrFullName.

Repro case

Source:

template<typename T>
struct MyArray
{
	int mLength;
	T* mBuffer;
};

struct Wrapper
{
	int mFoo;
};

int main(int argc, char* argv[])
{
	MyArray<Wrapper> array;
	array.mLength = 1;
	array.mBuffer = new Wrapper[1];
	array.mBuffer[0].mFoo = 123456789;

	__builtin_debugtrap();
}

Natvis:

<Type Name="MyArray&lt;*&gt;">
	<DisplayString>Length={mLength}</DisplayString>
	<Expand>
		<ArrayItems>
			<Size>mLength</Size>
			<ValuePointer>mBuffer</ValuePointer>
		</ArrayItems>
	</Expand>
</Type>
<Type Name="Wrapper">
	<DisplayString>Wow, custom! {mFoo}</DisplayString>
</Type>
  1. Ensure a debugger is attached to MIDebugEngine.
  2. Place a breakpoint in SimpleWrapper.FullName.
  3. Launch the min repro application.
  4. When breaking in the debugger (using the trap instruction), switch to the Locals view in Visual Studio.
  5. Expand array.
  6. This will trigger the breakpoint in SimpleWrapper.FullName.
  7. Observe how [0] is returned as full name instead of the expected expression ((*(Wrapper(*)[1])(((array).mBuffer)+0)))[0].

This should be my last PR for now, apologies for blasting them at you rapid-fire. :)

iridinite and others added 2 commits September 16, 2025 10:38
This would result in array elements in Natvis using incorrect expressions,
e.g. the first array element would use the literal '[0]' as expression
instead of the actual element path, which does not work.
@gregg-miskelly gregg-miskelly self-requested a review September 23, 2025 00:01
@gregg-miskelly gregg-miskelly merged commit 1e21dd2 into microsoft:main Sep 23, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants