Create views of OpenCASCADE objects in the Debugger

eryar@163.com

Abstract. The Visual Studio Natvis framework lets you customize the way Visual Studio displays native types in debugger variable windows such as the Watch, Locals and Data Tips windows. It supersedes the autoexp.dat file that has been used in earlier versions of Visual Studio and offers XML syntax, better diagnostics, versioning, and multiple file support. The container in OpenCASCADE is difficult for debugging, such as TColStd_Array1OfInteger in the TColStd package, .etc. Use the natvis framework to create views of these objects will make it easy for developers to inspect them during debugging and so accelerate the debug process.

Key Words. Visual Studio Natvis, OpenCASCADE

1. Introduction

因 为OpenCASCADE早期使用C开发,所以自定义了一些容器类,如包TColStd中的类,TColGeom包及包TopTools中的类等,这些类 在C++中都可以使用STL来替代了。这些类在Debug过程中,很难查看其中的值,如TColStd_Array1OfInteger,这个类相当于 std::vector<int>,但是Debug时只能看到数据的指针,不容易查看容器中每个元素的值,如下图1.1所示:

Figure 1.1 View of TColStd_Array1OfInteger in Locals Window

由 上图1.1可知,对于这个类的对象,Debug时只能看到数据的起始指针。为了方便自定义类型调试,Visual Studio在2012版本以后,引入了Natvis框架,用来替代原来的autoexp.dat来为自定义类型定义调试时的数据显示。Natvis使用 了XML文件,可读性更好,易于实现。

本文使用Visual Studio的Natvis框架,来对OpenCASCADE中的一些容器类数据进行可视化,方便开发者对OpenCASCADE的调试。

2.For Array Container

对于OpenCASCADE的包TColStd中的数组类,定义其natvis如下所示:

<Type Name="TColStd_Array1OfInteger">
<DisplayString Condition="isAllocated != 1">empty</DisplayString>
<DisplayString>{{size = {myUpperBound - myLowerBound + 1}}}</DisplayString>
<Expand>
<Item Condition="isAllocated == 1" Name="[size]">myUpperBound - myLowerBound + 1</Item>
<ArrayItems Condition="isAllocated == 1">
<Size>myUpperBound - myLowerBound + 1</Size>
<ValuePointer>(Standard_Integer*)(myStart) + myLowerBound</ValuePointer>
</ArrayItems>
</Expand>
</Type>

调试时数据显示如下图2.1所示:

Figure 2.1 OpenCASCADE array in Locals Windows

同理,可对此包中其他一维数组使用同样的规则,即可对其中的数据可视化,与std::vector显示的效果一样,方便调试。

3.For List Container

对于OpenCASCADE的包TColStd中的链表类,定义其natvis如下所示:

<Type Name="TColStd_ListNodeOfListOfInteger">
<DisplayString>{{current = {myValue}}}</DisplayString>
<Expand>
<LinkedListItems>
<HeadPointer>this</HeadPointer>
<NextPointer>(TColStd_ListNodeOfListOfInteger*)myNext</NextPointer>
<ValueNode>this-&gt;myValue</ValueNode>
</LinkedListItems>
</Expand>
</Type> <Type Name="TColStd_ListOfInteger">
<DisplayString Condition="myFirst == 0">empty</DisplayString>
<Expand>
<Item Name="first">(TColStd_ListNodeOfListOfInteger*)myFirst</Item>
</Expand>
</Type>

调试时对于类TColStd_ListOfInteger,natvis诊断说找不到类TColStd_ListNodeOfListOfInteger定义,当跟踪到此类一个具体函数时,就可以看到具体的值了:

Figure 3.1 Natvis gives a Error info

跟踪到TColStd_ListOfInteger内部后,就可以看到类TColStd_ListNodeOfListOfInteger中的数据了,但是从TColStd_ListOfInteger的函数中出来后,就看不到了。

如果这个问题解决了,对于类TopoDS_ListOfShape中的数据也可以用同样的方式来显示,极大地方便了开发者对其调试。如果你对此有解决办法,欢迎不吝赐教。

Figure 3.2 Data view for TColStd_ListNodeOfListOfInteger

先从简单的容器类着手,解决后可将TopoDS_ListOfShape中的数据显示出来,为OpenCASCADE程序的调试提供方便。

4.Conclusion

Visual Studio 2012版本以后引入了Natvis框架来对自定义的类进行可视化,方便调试。OpenCASCADE中有很多容器类直接使用了指针,调试程序时数据很不 直观。应用Natvis来对一些类在调试时的视图进行配置,可以方便查看其中数据,使OpenCASCADE的调试更轻松。

对于一维数组的natvis定义还是很简单的,但是对于List出现了问题。如果这个问题解决了,对TopoDS_ListOfShape的可视化也可做同样的处理,方便造型算法调试。若您有解决方案,望不吝赐教。

5. References

1. Create custom views of native objects in the debugger.

https://msdn.microsoft.com/en-us/library/vstudio/jj620914.aspx

2. Writing debugger type visualizers for C++ using .natvis files

https://code.msdn.microsoft.com/Writing-type-visualizers-2eae77a2#content

3. vczh. C++实用技巧之配置Visual C++的调试器显示数据结构的格式.

http://www.cppblog.com/vczh/archive/2013/03/21/198665.html

4. stl.natvis in %VSINSTALLDIR%\Common7\Packages\Debugger\Visualizers

5. qt5.natvis in %VSINSTALLDIR%\Common7\Packages\Debugger\Visualizers

Create views of OpenCASCADE objects in the Debugger的更多相关文章

  1. 【IOS笔记】Views

    Views Because view objects are the main way your application interacts with the user, they have many ...

  2. View Programming Guide for iOS ---- iOS 视图编程指南(四)---Views

    Views Because view objects are the main way your application interacts with the user, they have many ...

  3. Create view failed with ORA-01031:insufficient privileges

    有时候在ORACLE数据库创建视图时会遇到:ORA-01031:insufficient privileges错误,我也多次碰到了各种创建视图出错的情况,很多时候也没有太在意,今天被一同事问起这个问题 ...

  4. Chapter 7 Integrity(完整性), Views(视图), Security(安全性), and Catalogs(目录)

    from Database Design to Physical Form CREATE TABLE integrity constraints (完整性约束) CREATE VIEW Securit ...

  5. iOS学习笔记(6)——翻译苹果文档About Windows and Views

    About Windows and Views 关于窗口和视图 In iOS, you use windows and views to present your application’s cont ...

  6. Django基础(一)_URLconf、Views、template、ORM

    一 什么是web框架? 框架,即framework,特指为解决一个开放性问题而设计的具有一定约束性的支撑结构,使用框架可以帮你快速开发特定的系统,简单地说,就是你用别人搭建好的舞台来做表演. 对于所有 ...

  7. create feature from text file

    '''---------------------------------------------------------------------------------- Tool Name: Cre ...

  8. Note of IOS 7 - Views

    1. Views presentation: A view (an object whose class is UIView or a subclass of UIView) knows how to ...

  9. Node.js log3:create ejs engine and jade engine

    The base condition is ensure that you have  installed express. 1.create   ejs engine Using windows d ...

随机推荐

  1. 时代杂志发文:2017 AR/MR将变得比VR更加重要

    每到年末都有很多企业或高管分析科技产业明年趋势.近日,时代杂志网页版刊登了2017年科技行业的五大趋势和热点话题的预测.该本作者TimBajarin,是硅谷市场研究公司CreativeStrategi ...

  2. Code HighLight

    #!/bin/sh BEG=`date --date '-7 days' +%Y%m%d` END=`date --date '-1 days' +%Y%m%d` #BEG='20140509' #E ...

  3. unity3D脚本中,update ,fixupdate 和lateupdate的区别

    1.MonoBehaviour.Update 更新 当MonoBehaviour启用时,其Update在每一帧被调用. 2.MonoBehaviour.FixedUpdate 固定更新 当MonoBe ...

  4. Java|今天起,别再扯订阅和回调函数

    编程史上有两个令人匪夷所思的说辞,一个是订阅,一个是回调函数. 我想应该还有很多同学为“事件的订阅”和“回调函数”所困扰,因为事情本来就不应该按这个套路来解释. 多直白,所谓的“回调函数”你完全可以线 ...

  5. GitHub托管项目

    1.进入Repositories->点击 new repositories; 2.输入Repository name 直接创建项目: 3.记录你的项目地址,如:https://github.co ...

  6. sql 更新列表中最老的一条数据

    今天组长给个任务说要给摄像头触发一个列表.让缓存5条数据,每次摄像头触发更新一条,丢掉最老的一条数据.原来的update是直接更新掉一条,没带缓存的.然后搞了个sql语句,是这样的: UPDATE C ...

  7. 汉字正则表达式[\u4E00-\u9FFF]原因

    转载易天:正则表达式的汉字匹配 这里是几个主要非英文语系字符范围 2E80-33FFh:中日韩符号区.收容康熙字典部首.中日韩辅助部首.注音符号.日本假名.韩文音符,中日韩的符号.标点.带圈或带括符文 ...

  8. 解决:View调用invalidate()后不刷新onDraw()

    近来学android图片处理,按照例子来,自定义一个View,之后在Activity里面手动调用该View的invalidate()后,一直无法刷新onDraw() 上网搜了一下,有两种解决办法: 一 ...

  9. Raid 介绍以及软raid的实现

    RAID: old Redundant Arrays of Inexpensive Disks (廉价磁盘冗余阵列) new Redundant Arrays of Independent Disks ...

  10. Android之Json的学习

    json数据包含json对象,json数组,对象是{ },数组是[ ], 数组里面还可以包含json对象,json对象之间是用逗号(,)隔开 形式如下: { "languages" ...