我正在尝试使用msvc可视化工具来实现一个个人可视化器。问题是我不知道如何处理工会问题。一个简单的示例,其结构( value)包含两个结构(string1和string2 )的联合:
typedef struct value
{ int type; /* variable type */
union
{
string1 sval;
string2 sval2;
} t;
}
typedef struct string1
{
int size;
char *data;
} aString1;
typedef struct string2
{
int size;
char *data;
} aString2;我可以用natvis中的以下代码为string1和string2创建两种类型:
<Type Name="string1"> /// (A) preview
<DisplayString>{{ string 1 }}</DisplayString>
<Expand>
<Item Name="text">data</Item>
</Expand>
</Type>
<Type Name="string2"> /// (B) preview
<DisplayString>{{ string 2 }}</DisplayString>
<Expand>
<Item Name="text">data</Item>
</Expand>
</Type>但是,当我有一个"value“变量(联合)时,如何自动预览这些类型。我坚持这一点:(假设变量类型为1表示string1,2表示string2 )。我所做的是:
<Type Name="value">
<DisplayString>{{Value}}</DisplayString>
<Expand>
<Synthetic Name="String 1 Name" Condition="type==1"> // assume type of string1 = 1
/// here i want to call preview I have created for string1 in (A)
</Synthetic>
<Synthetic Name="String 2 Name" Condition="type==2"> // assume type of string2 = 2
/// here i want to call preview I have created for string2 in (B)
</Synthetic>
</Expand>
</Type>因此,我希望根据类型值,调试将显示正确的可视化工具。你能解释一下我如何处理与纳特维斯的关系吗?还是有什么地方可以举个例子?(官方的msvc文档不考虑工会。)显然,这个例子是没有意义的,但它只是为了理解,因为我有一个更复杂的联盟。
发布于 2016-10-27 08:06:14
下列措施应能发挥作用:
<Type Name="value">
<DisplayString Condition="type == 1">{t.sval}</DisplayString>
<DisplayString Condition="type == 2">{t.sval2}</DisplayString>
<Expand>
<ExpandedItem Condition="type == 1">t.sval</ExpandedItem>
<ExpandedItem Condition="type == 2">t.sval2</ExpandedItem>
</Expand>
</Type>ExpandedItem移除联合视图并使用string1 resp。相反,string2展开取决于类型的值。
我没有尝试使用我在这里发布的XML,因此可能会出现一些语法错误,但是您应该能够让它处理一些小的调整(如果有的话)。
https://stackoverflow.com/questions/35399052
复制相似问题