如何避免原生可视化程序中的递归



我正在调试一个C++程序,该程序包含相当多的CPtrArray对象
使用自定义的heap_stat脚本,我知道CPtrArray对象的指针值,其中包含许多条目。

使用原生可视化器,我确实可以看到每个CPtrArray对象中的条目数量,因此我对应的natvis条目:

<Type Name="CArray&lt;*,*&gt;">
<AlternativeType Name="CPtrArray"/> 
<DisplayString>{{size = {m_nSize}}}</DisplayString> 

问题是:这显示了元素的数量,但没有显示指针值。我想很容易解决这个问题,使用以下natvis条目:

<Type Name="CArray&lt;*,*&gt;">
<AlternativeType Name="CPtrArray"/> 
<DisplayString>{{size = {m_nSize}, pointer = {this}}}</DisplayString> 

然而,这向我显示了指针值,但也显示了更多::-(

{size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 {size = , pointer = }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}

有人知道我如何避免这种递归吗?

在第一条评论后编辑并回答

我对heap_stat脚本进行了如下调整:

if type_name.endswith("CPtrArray"):
collection_Size = typedVar('CPtrArray', ptr).m_nSize
...
dprintln(("0x" + pointer_format + "t%st Size:[%d]") % (ptr, type_name, collection_Size))

因此,我在heap_stat报告中得到了CPtrArray(和其他(对象的大小:

0x0732517c  mfc110u!CStringArray     Size:[0]
0x073256d4  mfc110u!CPtrArray    Size:[584]

我有COLUMN对象,它们具有CPtrArray属性,我想知道哪个对象与特定的CPtrArray对象相对应,因此我在监视窗口中添加了所有COLUMN对象:

((COLUMN*)0x073256d0)->paData   {size = 584, pointer = 0x073256d4 {size = 584, pointer = 0x073256d4 ...
((COLUMN*)0x07325780)->paData   {size = 0, pointer = 0x01234567 {size = 0, pointer = 0x01234567 ...
((COLUMN*)0x07325830)->paData   {size = 0, pointer = 0x02345678 {size = 0, pointer = 0x02345678 ...

正如你所看到的,递归给了我大量的信息(并大大降低了我的分析性能(,因此我希望避免它,而不需要扩展每个COLUMN对象来查看所需的信息。

经过一些后续操作后编辑

由于这个问题看起来像是Natvis处理中的一个bug,我决定在MSDN网站上写一篇重复的帖子。这篇文章最近被标记为"Triaged",我希望这意味着MSDN开发人员会考虑它。

提前感谢

递归扩展之所以完成,是因为调试器知道this的类型是CArray,以及该类型应如何显示。如果你只想要一个没有扩展的指针,你可以像中那样将指针投射到void*,从而放弃CArray类型的知识

<DisplayString>{{size = {m_nSize}, pointer = {(void*)this}}}</DisplayString>

问题是您通过natvis要求递归地显示它。this将显示this的DisplayString,现在您有一个无限递归。实际上,很少有natvis文件的DisplayString中包含this

相反,添加一个包含数组内容和其他内容的<Expand>节,这样就不会重复出现。

你可以显示指向数据的指针,这很容易实现,如果你想进行某种检查来识别相同的数组,但使用this,你将无法获得你想要的结果,因为它会用指针触发显示字符串。

相关内容

  • 没有找到相关文章

最新更新