c++ - Visual Studio 2012 Natvis 跳过 IndexListItems

标签 c++ qt visual-studio-2012

我正在为 Qt 类创建一个 natvis 文件,但遇到了问题。

为了可视化 QHash 对象,我创建了这两种类型:

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

它几乎可以工作,但是由于 QHash 在内存中不是连续的,所以有很多无效条目。 条件

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

已经过滤掉那些无效的,但它们仍然显示为<Unable to display value> .

有谁知道是否有办法完全跳过这些条目?

我从来没有真正使用过 autoexp.dat 文件,这是旧方法,但是在查看安装了 Qt 插件的文件时,在我看来该声明

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

确实如此,所以我希望在 natvis 文件中也有办法做到这一点?

如果有人有兴趣,我可以给你 natvis 文件,但我现在只有 QString、QByteArray、QList、QVector、QMap 和(有问题的)QHash。

最佳答案

根据MSDN page on writing type visualizers , <IndexListItems>根据定义是连续的:

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.

另外,我可以指点您the Qt Labs VSTools repository吗?和 its documentation ?特别是 tools/Qt4EEAddin/qt5.natvis看起来很像我认为你要写的东西? (或者实际上你在写什么?^_^)不管怎样,我认为你能做的最好的就是qt5.natvis中的内容。 ,它有一个特殊的 <DisplayString>为空 QHashNodes但不会尝试忽略 QHash 中的空桶.

关于c++ - Visual Studio 2012 Natvis 跳过 IndexListItems,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13748209/

相关文章:

c++ - 无法将 QtWebWidgets 添加到项目

c++ - 为什么这个 C++ 表达式甚至不生成警告?

c++ - 使用 C++11 编译 ui 代码时遇到 "unable to find string literal operator"错误

python - SWIG C++/Python 绑定(bind)和支持带有 std::enable_if 的条件成员

c++ - #ifdef 用于 32 位平台

qt - 如何在 Qt 中显示工具提示

c++ - 如何在 macOS 上的 Qt 中使用 OpenMP 进行编译?

visual-studio-2012 - 使用第 3 方 DLL 部署 WPF 应用程序

tfs - 工作区版本表包含未知架构版本

sql - 等待数据库引擎恢复句柄失败。检查 SQL Server 错误日志以了解潜在原因