我正在使用基于 STL 的 C++ 解决方案,并且我正在使用 CPtrList 集合。
我在这里有一个 CPtrList 集合,其中包含void *
条目,我想使用 natvis 文件自动对它们进行类型转换。
目前,我的 natvis 如下所示:
<Type Name="CList<*,*>">
<AlternativeType Name="CObList"></AlternativeType>
<AlternativeType Name="CPtrList"></AlternativeType>
<AlternativeType Name="CStringList"></AlternativeType>
<AlternativeType Name="CTypedPtrList<*,*>"></AlternativeType>
<DisplayString>{{iets anders Count = {m_nCount}}}</DisplayString>
<Expand>
<Item Name="Count">m_nCount</Item>
<LinkedListItems>
<Size>m_nCount</Size>
<HeadPointer>m_pNodeHead</HeadPointer>
<NextPointer>pNext</NextPointer>
<ValueNode>data</ValueNode>
</LinkedListItems>
</Expand>
</Type>
因此,我的 CPtrList 条目如下所示:
0x<something> void *
0x<something else> void *
...
我想将条目类型转换为这样的:
<information> CElement::SL_SET_PARAMETER*
<information else> CElement::SL_SET_PARAMETER*
一旦我知道如何完成这项工作,我就可以在我的 natvis 中添加一个“SL_SET_PARAMETER”条目并决定如何显示它,但因此我首先需要向 natvis 解释每个 CPtrList 条目都应该被转换为“SL_SET_PARAMETER”对象。
有人知道怎么做这个吗?
您必须使用<CustomListItems>
标签(有关更多详细信息,请参阅MS 文档中的CustomListItems 扩展项)。这是显示类型的最通用规范,它允许局部变量和循环。
他们在文档中使用的示例如下:
<Type Name="ATL::CAtlMap<*,*,*,*>">
<AlternativeType Name="ATL::CMapToInterface<*,*,*>"/>
<AlternativeType Name="ATL::CMapToAutoPtr<*,*,*>"/>
<DisplayString>{{Count = {m_nElements}}}</DisplayString>
<Expand>
<CustomListItems MaxItemsPerView="5000" ExcludeView="Test">
<Variable Name="iBucket" InitialValue="-1" />
<Variable Name="pBucket" InitialValue="m_ppBins == nullptr ? nullptr : *m_ppBins" />
<Variable Name="iBucketIncrement" InitialValue="-1" />
<Size>m_nElements</Size>
<Exec>pBucket = nullptr</Exec>
<Loop>
<If Condition="pBucket == nullptr">
<Exec>iBucket++</Exec>
<Exec>iBucketIncrement = __findnonnull(m_ppBins + iBucket, m_nBins - iBucket)</Exec>
<Break Condition="iBucketIncrement == -1" />
<Exec>iBucket += iBucketIncrement</Exec>
<Exec>pBucket = m_ppBins[iBucket]</Exec>
</If>
<Item>pBucket,na</Item>
<Exec>pBucket = pBucket->m_pNext</Exec>
</Loop>
</CustomListItems>
</Expand>
</Type>
它唯一的小问题是,如果您从监视窗口复制它创建的表达式,它将看起来像一个数字转换为您想要的类型的指针,而不是像语法一样漂亮的数组,因此如果内存位置移动,导致它不会被更新。如果您引用包含对象的父对象,这没什么大不了的,只是很烦人。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句