简体   繁体   English

NATVIS 重新解释类型或别名类型

[英]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&lt;*,*&gt;">
<DisplayString>{*(stl1.dll!std::vector&lt;$T0,$T1&gt *)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>

This display as此显示为在此处输入图像描述

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&lt;*,*&gt;">
    <Expand>
      <ExpandedItem>
        *(stl1.dll!std::vector&lt;$T0,$T1&gt *)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.

相关问题 使用 std::type_info 在 natvis 中进行转换 - Using std::type_info for casting in natvis Natvis用于可能被编译为dll或lib的类型 - Natvis for a type that may be compiled into dll or lib 使用运行时字符串在 natvis 中指定 object 类型 - Using a runtime string to specify object type in natvis 如何使用 natvis Visual Studio C++ 调试器可视化工具对单一类型进行多个列表扩展 - How to make multiple list expansions for a single type using natvis Visual Studio C++ debugger visualizer 在 function 模板中获取类型别名后面的类型名称 - Get name of type behind type alias in function template 错误40:整数类型不符合名称空间或别名的条件 - error 40: the type integer is not qualified with a namespace or alias Visual Studio 2015 给出“预期的 TS1110 类型”。 对于数字文字类型联合别名 - Visual Studio 2015 giving "TS1110 Type expected." for numeric literal type union alias VB.Net页面中具有ASP.Net导入指令的别名通用类型 - Alias Generic Type With ASP.Net Import Directive in VB.Net Page 如何防止生成的接口实现使用类型别名? - How can I prevent the generated implementation of an interface from using a type alias? 运用 <CustomVisualizer> 用natvis标记 - Using <CustomVisualizer> tag with natvis
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM