Dump class/struct member variables in g++(在 g++ 中转储类/结构成员变量)
问题描述
g++ 中是否有用于转储结构/类的成员变量 的标志或工具?为了说明,考虑这样的源代码
Is there a flag in g++ or tools to dump the member variables of a struct/class? To illustrate, consider source code like this
struct A { virtual void m() {}; };
struct B : public A { int b; virtual void n() = 0; };
struct C : public B { int c1, c2; void o(); };
struct D : public C { virtual void n() {}; A d; };
我想得到类似的东西
A: 0 = (vptr)
B: 0 = (vptr)
4 = b
C: 0 = (vptr)
4 = b
8 = c1
12 = c2
D: 0 = (vptr)
4 = b
8 = c1
12 = c2
16 = d
(-fdump-class-hierarchy 不起作用.它只打印成员函数.)
(-fdump-class-hierarchy does not work. It only prints the member functions.)
(假设我不知道 A 到 D 的类,或者有太多的类我不想自己列出来.)
(Assume I don't know the classes A to D, or there are so many classes that I don't want to list them out myself.)
(具体来说,我想转储 http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/iokit/IOKit/IOUserClient.h).
(Specifically, I want to dump the member variables of http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/iokit/IOKit/IOUserClient.h).
推荐答案
为正确的工作使用正确的工具.g++ 并不是一个层次结构查看工具.
Use the right tool for the right job. g++ isn't much of a hierarchy viewing tool.
您总是可以使用像 doxygen 这样的外部工具,它可以转储 graphviz 图.
You can always use a external tool like doxygen, that can dump graphviz diagrams.
对于电源解决方案,有 gcc-xml,可以转储您的整个程序成一个xml文件,你可以随意解析.
For power-solutions there is gcc-xml, that can dump your whole program into an xml file that you can parse at will.
这篇关于在 g++ 中转储类/结构成员变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 g++ 中转储类/结构成员变量
基础教程推荐
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- CString 到 char* 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
