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如下所示:

  1. <Type Name="TColStd_Array1OfInteger">
  2. <DisplayString Condition="isAllocated != 1">empty</DisplayString>
  3. <DisplayString>{{size = {myUpperBound - myLowerBound + 1}}}</DisplayString>
  4. <Expand>
  5. <Item Condition="isAllocated == 1" Name="[size]">myUpperBound - myLowerBound + 1</Item>
  6. <ArrayItems Condition="isAllocated == 1">
  7. <Size>myUpperBound - myLowerBound + 1</Size>
  8. <ValuePointer>(Standard_Integer*)(myStart) + myLowerBound</ValuePointer>
  9. </ArrayItems>
  10. </Expand>
  11. </Type>

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

Figure 2.1 OpenCASCADE array in Locals Windows

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

3.For List Container

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

  1. <Type Name="TColStd_ListNodeOfListOfInteger">
  2. <DisplayString>{{current = {myValue}}}</DisplayString>
  3. <Expand>
  4. <LinkedListItems>
  5. <HeadPointer>this</HeadPointer>
  6. <NextPointer>(TColStd_ListNodeOfListOfInteger*)myNext</NextPointer>
  7. <ValueNode>this-&gt;myValue</ValueNode>
  8. </LinkedListItems>
  9. </Expand>
  10. </Type>
  11.  
  12. <Type Name="TColStd_ListOfInteger">
  13. <DisplayString Condition="myFirst == 0">empty</DisplayString>
  14. <Expand>
  15. <Item Name="first">(TColStd_ListNodeOfListOfInteger*)myFirst</Item>
  16. </Expand>
  17. </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. 整理 PHPstorm实用个人配置,修改调整个性化快捷键,修改使用phpstorm创建的模板的默认注释:

    对你有助请点赞,请顶------送人玫瑰,手留余香! 1:58 2016/3/12 整理PHPstorm实用个人配置,修改调整个性化快捷键,修改使用phpstorm创建的模板的默认注释: PHPsto ...

  2. 分布式数据库的四分结构设计 BCDE

    首先,对关系型数据库的表进行四种分类定义: Basis 根基,Content 内容, Description 说明, Extension 扩展. Basis:Baisis 表是唯一的,为了实现标准而得 ...

  3. C,C++

    C与C++的Struct有何区别,Java有Struct吗,C++里Struct与Class区别: C++虚析构函数作用: static静态变量初始化: 深复制与浅复制区别: const * int ...

  4. #研发解决方案#分布式并行计算调度和管理系统Summoner

    郑昀 创建于2015/11/10 最后更新于2015/11/12 关键词:佣金计算.定时任务.数据抽取.数据清洗.数据计算.Java.Redis.MySQL.Zookeeper.azkaban2.oo ...

  5. 使用poco 的NetSSL_OpenSSL 搭建https 服务端,使用C++客户端,java 客户端访问,python访问(python还没找到带证书访问的代码.)

    V20161028 由于项目原因,需要用到https去做一些事情. 这儿做了一些相应的研究. 这个https 用起来也是折腾人,还是研究了一周多+之前的一些积累. 目录 1,java client 通 ...

  6. sql 存储过程 output参数的使用

    /*嵌套存储过程中需要输出来的参数*/output 就是这个存储过程返回的值 也可以说输出的值--创建存储过程 求最大值CREATE PROCEDURE [dbo].[P_Max]@a int, -- ...

  7. 异常处理_Maven多模块web项目整合ssm+dubbo

    异常如下: [ERROR][org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader. ...

  8. HDU---BigZhuGod的粉丝

    Problem Description 真正的粉丝,是不需要题目描述的^_^.   Input 第一行输入数据组数T(1≤T≤100).接下来T行,每行一个有格式的字符串,详见样例,字符串长度不超过1 ...

  9. 【codevs】刷题记录→_→(推荐看!)

    注:本文是我原先在csdn内写的一篇博文,现转到这里,两篇博文尽量同时更新. //#include<iostream->shuati> //define 为什么刷  学长☞hzwer ...

  10. Quartz 2D在ios中的使用简述二:创建画布

    在iOS中使用Quartz画图时,第一步就是要获取画布(图形上下文),然后再画布上做各种操作.先看下CoreGraphics.h这个头文件,就可以知道能够创建多少种上下文类型. #include &l ...