visual-studiowindbgnatvis

How to debug Windbg? (How to get information about what Windbg is doing)


As most of you know, Windbg can be used for debugging programs, but now I'd like to do just the opposite: I'd like to debug what I'm doing in Windbg, let me show you why:

I've found an interesting native visualiser, containing following entries:

<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>

These entries make sure that CMap objects get shown in a nice way, one under the other. Together with another internal entry, this gives following result in a Visual Studio watch-window:

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)

When I try to do the same in Windbg (using the dx commands), this gives similar information, but it ends at entry number 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 *>]

(By clicking on the entries, I get more information, which is correctly rendered by the mentioned other native visualiser entry)

I'd like to know the reason why the display of the CMap entries stops at 49. I already know I can get more entries by clicking on ... (which adds -c 100, -c 200, ... to the dx command) but if I could get more information (like the output window of Visual Studio with the option "Debugging, Output Window, General Output Settings, Natvis diagnostics messages" set to "Verbose"), I'd be able to diagnose and solve my problems.

Does anybody know how to do this?
Thanks in advance


Solution

  • windbg can debug windbg the child windbg debugging your actual binary

    iirc it is callef daisy wheeling

    open a command prompt

    type windbg windbg app and hit enter

    if you dont mind using the console version windbg has an inbuilt command

    .dbgdbg

    this will spawn a parent debugger to an existing instance