简体   繁体   English

如何(临时)使用 natvis 对 CPtrList 条目进行类型转换?

[英]How to (temporarily) typecast CPtrList entries using natvis?

I'm working with a C++ solution, based on STL, and I'm using CPtrList collections.我正在使用基于 STL 的 C++ 解决方案,并且我正在使用 CPtrList 集合。

I have here a CPtrList collection, containing void * entries, and I would like to typecast those automatically using a natvis file.我这里有一个 CPtrList 集合,包含void *条目,我想使用 natvis 文件自动对它们进行类型转换。

Currently, my natvis looks as follows:目前,我的 natvis 如下所示:

<Type Name="CList&lt;*,*&gt;">
  <AlternativeType Name="CObList"></AlternativeType>
  <AlternativeType Name="CPtrList"></AlternativeType>
  <AlternativeType Name="CStringList"></AlternativeType>
  <AlternativeType Name="CTypedPtrList&lt;*,*&gt;"></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>

As a result the entries of my CPtrList look like the following:因此,我的 CPtrList 条目如下所示:

0x<something>      void *
0x<something else> void *
...

I would like to have the entries typecasted into something like this:我想将条目类型转换为这样的:

<information>      CElement::SL_SET_PARAMETER*
<information else> CElement::SL_SET_PARAMETER*

Once I know how to get this done, I can add a "SL_SET_PARAMETER" entry in my natvis and decide how to display this, but therefore I first need to explain to natvis that every CPtrList entry should be casted into a "SL_SET_PARAMETER" object.一旦我知道如何完成这项工作,我就可以在我的 natvis 中添加一个“SL_SET_PARAMETER”条目并决定如何显示它,但因此我首先需要向 natvis 解释每个 CPtrList 条目都应该被转换为“SL_SET_PARAMETER”对象。

Does anybody know how to do this?有谁知道如何做到这一点?

You would have to use a <CustomListItems> tag (see CustomListItems expansion item in the MS documentation for more details).您必须使用<CustomListItems>标记(有关更多详细信息,请参阅MS 文档中的CustomListItems 扩展项)。 This is the most generic specification of a displayed type which allows local variables and looping.这是显示类型的最通用规范,它允许局部变量和循环。

The example that they use in their documentation is as follows:他们在文档中使用的示例如下:

<Type Name="ATL::CAtlMap&lt;*,*,*,*&gt;">  
    <AlternativeType Name="ATL::CMapToInterface&lt;*,*,*&gt;"/>  
    <AlternativeType Name="ATL::CMapToAutoPtr&lt;*,*,*&gt;"/>  
    <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>  

The only minor issue it has is that if you copy the expression that this creates from a watch window, it will look like a number casted to a pointer of the type you wanted, instead of having a nice looking array like syntax and as such will result in it not being updated if the memory location moves.它唯一的小问题是,如果您从监视窗口复制它创建的表达式,它将看起来像一个数字转换为您想要的类型的指针,而不是像语法一样漂亮的数组,因此如果内存位置移动,导致它不会被更新。 If you reference a parent containing object, this isn't a big deal, just annoying.如果您引用包含对象的父对象,这没什么大不了的,只是很烦人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM