[英]NATVIS reinterpret type or alias type
Is there a way in natvis to reinterpret a type to an already natvis-defined type? natvis 中有没有办法将类型重新解释为已经 natvis 定义的类型? or alias it?还是别名呢?
For example, I'd like to do this kind of "trick" (really necessary in my context even if that does sound really weird to you, it's a question of JIT symbol generation)例如,我想做这种“技巧”(在我的上下文中确实有必要,即使这听起来对你来说真的很奇怪,这是 JIT 符号生成的问题)
<Type Name="std::vector<*,*>">
<DisplayString>{*(stl1.dll!std::vector<$T0,$T1> *)this}</DisplayString>
</Type>
But it doesn't work to display the expand items, it just displays a string as value (which seems logical considering the 'DisplayString' role).但它不能显示展开项,它只是显示一个字符串作为值(考虑到“DisplayString”角色,这似乎是合乎逻辑的)。
I've also tried with a SmartPointer
trick, it does better but it turns out it doesn't work when there is base classes involved (it only displays the SmartPointer type and ignore completely inheritance)我也尝试过使用SmartPointer
技巧,它做得更好,但事实证明,当涉及基类时它不起作用(它只显示 SmartPointer 类型并完全忽略继承)
As you do not show your classes I can just show my own example code.由于您没有展示您的课程,我只能展示我自己的示例代码。
struct A { int x, y; };
struct B { int x, y; };
struct C { int v, w; };
int main()
{
A a{ 1,2 };
B b{ 3,4 };
C c{ 5,6 };
return 0;
}
And the natvis:和 natvis:
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="A">
<AlternativeType Name="B"/>
<AlternativeType Name="C"/>
<DisplayString>A {x}, {y}</DisplayString>
</Type>
</AutoVisualizer>
As you can see the AlternativeName
does the trick, but it is required on the natvis for the original class.如您所见, AlternativeName
可以解决问题,但原始 class 的 natvis 需要它。 And it requires that both classes have the same members/member names.它要求两个类具有相同的成员/成员名称。
Please also note that when playing around with natvis it is a good idea to enable natvis debugging.另请注意,在使用 natvis 时,最好启用 natvis 调试。 Go to menu Tools/Options/Debugging/"Output Windows"/"General Output Settings" and set "Natvis diagnostic messages (C++ only)" to a useful value. Go 到菜单工具/选项/调试/“输出窗口”/“常规 Output 设置”并将“Natvis 诊断消息(仅限 C++)”设置为有用的值。
I think you try to represent one type as another (transparently)?我认为您试图将一种类型表示为另一种类型(透明地)? In your case you should use ExpandedItem
.在您的情况下,您应该使用ExpandedItem
。 This should work:这应该有效:
<Type Name="std::vector<*,*>">
<Expand>
<ExpandedItem>
*(stl1.dll!std::vector<$T0,$T1> *)this
</ExpandedItem>
</Expand>
</Type>
But beware of recursion and side effects connecteed with reinterpret_cast
但要注意与reinterpret_cast
相关的递归和副作用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.