如何调试Windbg?(如何获取有关Windbg正在做什么的信息)

Dom*_*que 1 windbg visual-studio natvis

大多数人都知道,Windbg 可用于调试程序,但现在我想做相反的事情:我想调试我在 Windbg 中所做的事情,让我向您展示原因:

我发现了一个有趣的本机可视化工具,包含以下条目:

<Type Name='CMap&lt;*,*,*,*&gt;'>
  <AlternativeType Name="CMapStringToString"/>                 
  <AlternativeType Name="CMapStringToPtr"/>                    
  <DisplayString>{{size = {m_nCount} }}</DisplayString>         
  <Expand>                                                     
    <CustomListItems>                                          
      <Variable Name='pHashtable' InitialValue='m_pHashTable'/>
      <Variable Name='hashtable_index' InitialValue='0'/>      
      <Variable Name='pList' InitialValue='*m_pHashTable'/>    
      <Variable Name='i' InitialValue='0'/>                    
      <Loop Condition='hashtable_index &lt; m_nHashTableSize'> 
        <Exec>pList = pHashtable[hashtable_index]</Exec>       
        <Loop Condition='pList '>                              
          <Item Name='{i}: [{pList->key}]'>pList->value</Item> 
          <Exec>pList = pList->pNext</Exec>                    
          <Exec>++i</Exec>                                     
        </Loop>                                                
        <Exec>++hashtable_index</Exec>                         
      </Loop>                                                  
    </CustomListItems>                                         
  </Expand>                                                    
</Type>                                                        

<Type Name='CMap&lt;*,*,*,*&gt;' IncludeView='keys'>
  <AlternativeType Name="CMapStringToString::CAssoc"/>
  <AlternativeType Name="CMapStringToPtr::CAssoc"/>
  <DisplayString>{{size = {m_nCount} }}</DisplayString>
  <Expand>
    <CustomListItems>
      <Variable Name='pHashtable' InitialValue='m_pHashTable'/>
      <Variable Name='hashtable_index' InitialValue='0'/>
      <Variable Name='pList' InitialValue='*m_pHashTable'/>
      <Variable Name='i' InitialValue='0'/>
      <Loop Condition='hashtable_index &lt; m_nHashTableSize'>
        <Exec>pList = pHashtable[hashtable_index]</Exec>
        <Loop Condition='pList '>
          <Item Name='[{i}].key:'>pList->key</Item>
          <Item Name='  [{i}].value:'>pList->value</Item>
          <Exec>pList = pList->pNext</Exec>
          <Exec>++i</Exec>
        </Loop>
        <Exec>++hashtable_index</Exec>
      </Loop>
    </CustomListItems>
  </Expand>
</Type>
Run Code Online (Sandbox Code Playgroud)

这些条目确保 CMap 对象以良好的方式显示,一个在另一个下。与另一个内部条目一起,这会在 Visual Studio 监视窗口中给出以下结果:

0x000000005b9c95d0 Element L"Element1" (ID1/SubID1.1, L"interesting_information.1"/L"1.0.0.0")
0x0000000059484d20 Element L"Element2" (ID1/SubID1.2, L"interesting_information.2"/L"2.0.0.0")
0x000000004caa6110 Element L"Element3" (ID2/SubID2.1, L"interesting_information.3"/L"3.0.0.0")
...
(this goes until the end of the CMap)
Run Code Online (Sandbox Code Playgroud)

当我尝试在 Windbg 中执行相同操作(使用命令dx)时,这会提供类似的信息,但它以条目号 49 结束:

Windbg Prompt>dx -r1 (*((<application>!CMap<unsigned __int64,unsigned __int64,CElement *,CElement *> *)0x13fbd2ae0))

["  [0].value:"] : 0x6dce7fd0 [Type: CElement *]
["[1].key:"]     : 0x7984000007a3 [Type: unsigned __int64]
["  [1].value:"] : 0x5b9c95d0 [Type: CElement *]
["[2].key:"]     : 0x79840000053f [Type: unsigned __int64]
...
["  [49].value:"] : 0x1bab05b0 [Type: CElement *]
[...]            [Type: CMap<unsigned __int64,unsigned __int64,CElement *,CElement *>]
Run Code Online (Sandbox Code Playgroud)

(通过单击条目,我可以获得更多信息,这些信息由提到的其他本机可视化器条目正确呈现)

我想知道条目显示​​停止于 49 的原因。CMap我已经知道我可以通过单击...(将-c 100, -c 200, ... 添加到dx命令中)来获取更多条目,但是如果我可以获得更多信息(例如Visual Studio 的输出窗口中的选项“调试、输出窗口、常规输出设置、Natvis 诊断消息”设置为“详细”),我就能够诊断并解决我的问题。

有人知道怎么做这个吗?
提前致谢

小智 5

目前,WinDbg 中的 NatVis 不提供与 Visual Studio 类似的“扩展诊断”。

也就是说,默认情况下,“dx”命令将显示任何容器的前 100 个条目,并显示用于继续的 DML 链接([...])。如果您想要超过 100 个条目,则可以使用格式说明符来指示要显示的条目数(这与 Visual Studio 中的相同)。

例如:

dx <container expression>,1000
Run Code Online (Sandbox Code Playgroud)

将显示 1000 个在继续链接之前评估的条目,而不是默认的 100 个。