Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2012 Natvis skip IndexListItems

I am creating a natvis file for the Qt classes and I ran into a problem.

In order to visualize QHash objects I created these two types:

<Type Name="QHashNode&lt;*,*&gt;">     <DisplayString Condition="next->next == 0">{{ key={key} value={value} h={h}}}</DisplayString>     <DisplayString>{{ key={key} value={value} h={h} withCollision }}</DisplayString>     <Expand>         <Item Name="NextNode">reinterpret_cast&lt;QHashNode&lt;$T1,$T2&gt; *&gt;(next)</Item>     </Expand> </Type>  <Type Name="QHash&lt;*,*&gt;">     <DisplayString>{{ size={d->size} buckets={d->numBuckets} }}</DisplayString>     <Expand>         <IndexListItems>             <Size>d->numBuckets</Size>             <ValueNode Condition="reinterpret_cast&lt;QHashNode&lt;$T1,$T2&gt; *&gt;(d->buckets[$i]) != e">reinterpret_cast&lt;QHashNode&lt;$T1,$T2&gt; *&gt;(d->buckets[$i])</ValueNode>         </IndexListItems>     </Expand> </Type> 

It pretty much works, but since the QHash is not continuous in memory, there are a lot of invalid entries. The condition

reinterpret_cast&lt;QHashNode&lt; $T1,$T2&gt; *&gt;(d->buckets[$i]) != e  

already filters those out that are invalid, but they are still shown as <Unable to display value>.

Does anyone know if there is a way to completely skip those entries?

I never really worked with the autoexp.dat file which was the old way to do it, but when looking at the file with the Qt-plugin installed it seems to me that the statement

#switch ($e.next != 0) #case 1 (     $e ) 

does exactly that, so I hope that there maybe is a way to do it in the natvis file as well?

If anyone's interested, I can give you the natvis file, but I only have QString, QByteArray, QList, QVector, QMap and (the problematic) QHash until now.

like image 243
brx Avatar asked Dec 06 '12 16:12

brx


1 Answers

According to the MSDN page on writing type visualizers, <IndexListItems> are by definition contiguous:

IndexListItems Expansion

ArrayItems assume array elements are laid out contiguously in memory. Debugger gets to the next element by simply incrementing its pointer to the current element. To support cases where you need to manipulate the index to the value node, index list items can be used. Here’s a visualizer using 'IndexListItems' node: [....] The only difference between ArrayItems and IndexListItems is that the 'ValueNode' expects the full expression to the ith element with the implicit '$i' parameter.

Also, might I point you at the Qt Labs VSTools repository and its documentation? In particular tools/Qt4EEAddin/qt5.natvis looks a great deal like what I think you're trying to write? (Or is it actually what you're writing? ^_^) Either way, I think the best you can do is what is in qt5.natvis, which has a special <DisplayString> for empty QHashNodes but does not try to elide empty buckets in the QHash.

like image 166
bks Avatar answered Sep 22 '22 07:09

bks