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++ 中转储类/结构成员变量
基础教程推荐
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 提升 ASIO 流缓冲 2021-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- c++ STL设置差异 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
