在 g++ 中转储类/结构成员变量 [英] Dump class/struct member variables in g++

查看:15
本文介绍了在 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.)

(假设我不知道 AD 的类,或者有太多的类我不想自己列出来.)

(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++ 中转储类/结构成员变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆