Code ={code,na" /> Code ={code,na" /> Code ={code,na"/>

natvis display of linked list that ends in raw view

372 views Asked by At

I have this

struct llist {
  char code[CODE_SIZE];
...
  llist *next;
}

And my natvis file contains this

<Type Name="llist">
    <DisplayString>Code ={code,na}</DisplayString>
    <StringView>code</StringView>
    <Expand>
        <LinkedListItems>
            <HeadPointer>this</HeadPointer>
            <NextPointer>next</NextPointer>
            <ValueNode>this</ValueNode>
        </LinkedListItems>
    </Expand>
</Type>

I see

> pt_llist | 0x... Code ="Default"

This is good, and when I expand the var I see the linked list as a list of items. When I expand one of the children I see a list from that point, what I want is the raw data now. I changed this line <ValueNode>this,!</ValueNode>, this gives me the list but with raw data. enter image description here

How do I get my list formatted the way I want and only when I expand a child will it display the raw data?

This might not be doable with the struct I have. But it is legacy code and I can't change it anytime soon. So I was just hoping to have a way to see the data better in debug.

Thanks

1

There are 1 answers

2
Werner Henze On BEST ANSWER

The debugger cannot determine if you want a simple one element only view or the list view. But you can for example have a default view and a simple view. The default view can display all elements and the simple view can only display the element itself. Here is a small adjustment to your natvis that shows what I mean:

<Type Name="llist">
  <DisplayString>Code ={code,na}</DisplayString>
  <StringView>code</StringView>
  <Expand>
    <LinkedListItems ExcludeView="simple">
      <HeadPointer>this</HeadPointer>
      <NextPointer>next</NextPointer>
      <ValueNode>this,view(simple)</ValueNode>
    </LinkedListItems>
  </Expand>
</Type>

This displays as output in debugger

The trick is to use the ExcludeView="..." and ,view(...) as described on MSDN. The name "simple" was my choice, you can choose any other name. You can even have multiple views.