磨刀不误砍柴工,你使用的工具决定了你的下限。我平时使用较多的代码编辑工具就是SourceInsight,这个工具速度快,操作方便,但处理非常大的项目的性能不是很理想,比如你要是添加整个Linux Kernel的源代码的话。
在使用SI浏览C语言项目代码时,用的最多的就是查找这个变量或函数在那里调用,通过查找来理解这个变量或函数的意义或作用是什么,是怎么使用的,理解其涉及的操作的执行逻辑等等。如果是C++语言的项目代码,除了上面,还要查找类的继承关系和谁使用了这个类,一般我都是通过查找类名,然后通过在搜索结果里查找public字符串来寻找它的继承类,通过查找new字符串来寻找谁生成实例而使用了它。
之前还专门搜索过从C++代码来导出类的继承和调用关系的工具。市场上是有这类工具的。
日常使用都还OK,也就这么用下来,并没有花很多时间研究SI这个工具,用的多是普通功能。里面有个Relation功能,之前理解过,能通过图表形式,显示函数或类的关系。当时知道有这个功能,也就没在意。今天想起来,再要查找某个基类的派生类时,突然想到,用这个功能不是正好可以解决这个问题吗,于是设置并使用了一下,真香!
下面参考帮助文档,来理解学习一下吧。
========== 分割线 ==========
关系窗口(Relation Window)是 Source Insight 的一项创新功能,可以显示当前选中的符号与其他事物之间的关系。关系窗口可以显示函数调用树、类层次结构、结构成员、引用树等。它可以停靠在源代码窗口旁边,并在后台工作,自动跟踪您正在选择的内容并显示关系信息。
The Relation Window is a Source Insight innovation that shows the relationship between the currently selected symbol and other things. The Relation Window can show function call trees, class hierarchies, structure members, reference trees, and more. It can be docked along side your source windows, and it works in the background tracking what you are selecting and showing relationship information automatically.
要显示关系窗口,请选择视图 > 面板 > 关系窗口。
To show the Relation Window, select View > Panels > Relation Window.
您可以在关系窗口选项对话框中指定关系类型和许多其他选项。请参阅: 关系窗口选项。
You can specify the relationship types and many other options in the Relation Window Options dialog. See: Relation Window Options.
关系窗口在后台运行,并跟踪您所选择的符号。关系窗口的优点在于您无需做任何特殊操作。在您工作时,它在后台运行,但您可以在需要时与它互动。您还可以打开多个关系窗口,分别显示不同类型的信息。
The Relation Window runs in the background and tracks what symbols you have selected. The beauty of the Relation Window is that you don’t have to do anything special. It works in the background while you work, but you can interact with it when you want to. You can also have several Relation Windows open, each showing different types of information.
1, Outline and Graph Views (大纲和图表视图)
关系窗口有两种视图: 大纲视图和图形视图。图形视图将符号显示为图形节点,并用线条将它们连接起来。关系图选项命令(关系窗口右键菜单中提供)可让您控制图形视图的外观。
The Relation Window has two types of views: Outline view and Graph view. The Graph view shows symbols as graph nodes with lines connecting them. The Relation Graph Options command (available on the Relation Window right-click menu) gives you control over the appearance of the graph view.
Outline View (大纲视图)
关系窗口大纲视图是关系层次结构的紧凑文本视图。您可以单击以展开或折叠大纲中的层级。
The Relation Window outline view is a compact, textual view of the relation hierarchy. You can click to expand and collapse levels in the outline.
Graph View(图形视图)
关系窗口图形视图是与大纲视图相同的关系的可视化表示。您可以展开和折叠图形中的节点。可以选择水平图形布局或垂直图形布局。您还可以打印图表,或将图表图像复制到系统剪贴板,以便在其他图像程序中进行处理。
The Relation Window graph view is a visual representation of the same relationship as the outline view. You can expand and collapse nodes in the graph. You can select either a horizontal graph layout, or a vertical graph layout. You can also print the graph, or copy the graph images to the system clipboard so you can process it in another imaging program.
要展开或折叠节点,请先将鼠标光标悬停在水平图形中节点的右边缘或左边缘上(或垂直图形中节点的顶部或底部中间)。鼠标光标将包含一个 + 或 - 符号。单击即可展开或折叠。
To expand or collapse a node, hover the mouse cursor first over the right or left edge of the node in a horizontal graph (or the top or bottom middle of a node in a vertical graph). The mouse cursor will contain a + or - symbol. Click to expand or collapse.
右键单击 "关系窗口",选择 "关系窗口图形选项",即可选择图形视图选项。请参阅: 关系窗口图形选项。
Relation Window Right-Click Menu
2, Relationship Rules (关系规则)
选择符号时显示的关系视图取决于符号的类型。您可以在 "关系窗口选项 "中对此进行控制。例如,您可以指定如果在源代码中选择一个函数,关系窗口将显示对该函数的引用。而如果选择一个类名,关系窗口将显示从该类派生出来的类。
The relation view that appears when you select a symbol depends on the type of symbol. You have control over this in the Relation Window Options. For example, you can specify that if you select a function in your source code, the Relation Window will show references to that function. And, if you select a class name, the Relation Window will show the classes derived from it.
每次 "关系窗口"展开一个符号以显示新的层级时,展开所代表的关系都是基于被展开的符号类型。这意味着每个关系窗口都有可能显示多种关系。 请参阅: 关系窗口选项。
Each time the Relation Window expands a symbol to show a new level, the relationship represented by the expansion is based on the type of symbol being expanded. That means each Relation Window can potentially show multiple relationships. See: Relation Window Options.
Relationship Types (关系类型)
这些关系可分为以下几大类,从计算速度最快到最慢依次排列:
* 包含 - 显示当前符号的内容。例如,结构体的成员。
* 调用 - 显示当前符号引用了哪些其他符号。例如,当前函数调用的函数。
* 调用和调用者 - 显示分割图;一边是当前函数调用的函数,另一边是调用当前函数的函数。
* 引用 - 显示哪些其他符号引用了当前符号。例如,调用当前函数的函数。
The relationships fall into these general categories, listed from computationally the fastest to slowest:
* Contains – show the contents of the current symbol. For example, the members of a struct.
* Calls – show what other symbols are referred to by the current symbol. For example, functions that are called by the current function.
* Calls and Callers - show a split graph; one side are the functions called by the current function, the other side is the functions that call the current function.
* References – show what other symbols refer to the current symbol. For example, functions that call the current function.
3, Call Graphs (调用图)
可以对函数调用图关系进行过滤,以便只显示您认为最有趣的路径。关系窗口属性对话框中的 "调用图过滤 "按钮将带您进入一个对话框,您可以通过指定要排除的特定函数来控制过滤。您还可以通过代码度量限制过滤函数。
The function call graph relationships can be filtered to show only what you consider the most interesting paths. The “Call Graph Filtering” button in the Relation Window Properties dialog box takes you to a dialog box that lets you control the filtering by specifying particular functions you want to exclude. You can also filter functions out by code metrics constraints.
请注意,Source Insight 将 C/C++ 宏视为合法的类似函数的符号,因此 C/C++ 宏可能会显示在调用图中。如果需要,可以在调用图过滤对话框中将其过滤掉。
Note that Source Insight considers C/C++ macros legitimate function-like symbols, and so C/C++ macros may show up in a call graph. You can filter them out in the Call Graph Filtering dialog box if you want.
Relation Window Performance (关系窗口性能)
关系窗口需要进行一些处理。某些关系的计算速度较慢。对于大型项目,"引用 "关系的计算速度最慢。
The Relation Window requires some processing. Some relationships are slower to compute. For very large projects, the “References” relationship will be the slowest to compute.
4, Multiple Relation Windows (多个关系窗口 )
您可以拥有多个关系窗口实例,这样就可以同时显示多个关系。每个关系窗口都有自己的关系选项。例如,一个窗口可以显示所选函数调用了哪些函数,另一个窗口可以显示哪些函数调用了所选函数。要创建新的关系窗口,请右键单击关系窗口并选择新建关系窗口。
You can have multiple Relation Window instances, so you can show multiple relationships at the same time. Each Relation Window has its own relationship options. For example, one window could show you what functions are called by the selected function, and another window could show you what functions make calls to the selected function. To create a new Relation Window, right-click on the Relation Window and select New Relation Window.
5, Customizing the Relation Window (自定义关系窗口)
关系窗口选项命令可从关系窗口工具栏或快捷菜单访问。您可以通过该命令控制显示哪些关系,以及窗口的显示方式。请参阅: 关系窗口选项。
The Relation Window Options command is accessed from the Relation Window toolbar or shortcut menu. You control what relationships are shown from this command, and how the window displayed. See: Relation Window Options.
您还可以使用关系图选项命令自定义关系窗口图表视图的外观。请参阅:关系窗口图形选项。
You can also customize the appearance of the Graph View of the Relation Window by using the Relation Graph Options command. See: Relation Window Graph Options.
6, Relation Window Graph Options(关系窗口图形选项)
具体使用可以参照帮助文档或者尝试一下。
7, Relation Window Options (关系窗口选项)
具体使用可以参照帮助文档或者尝试一下。
参考:
1,SourceInsight帮助
Features and Concepts -> Relation Window.