簡體   English   中英

如何(臨時)使用 natvis 對 CPtrList 條目進行類型轉換?

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

我正在使用基於 STL 的 C++ 解決方案,並且我正在使用 CPtrList 集合。

我這里有一個 CPtrList 集合,包含void *條目,我想使用 natvis 文件自動對它們進行類型轉換。

目前,我的 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>

因此,我的 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&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>  

它唯一的小問題是,如果您從監視窗口復制它創建的表達式,它將看起來像一個數字轉換為您想要的類型的指針,而不是像語法一樣漂亮的數組,因此如果內存位置移動,導致它不會被更新。 如果您引用包含對象的父對象,這沒什么大不了的,只是很煩人。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM