有没有办法转储g ++编译程序的类布局 [英] Is there any way to dump the class layout of a g++ compiled program

查看:131
本文介绍了有没有办法转储g ++编译程序的类布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用g ++编译时,-fdump-class-hierarchy以(或多或少)人类可读格式导出程序的vtables。但是,生成的文件只包含关于vtable的信息,但 not 关于类布局本身。我希望获得所有程序类的布局的完整列表。

When compiling with g++, -fdump-class-hierarchy exports the program's vtables in a (more or less) human-readable format. However, the resulting file only contains information about the vtable but not about the class layout itself. I'd like to get a comprehensive list of the layout of all my program's classes.

clang提供了-cc1 -fdump-record-layouts参数来实现此目的。 MS编译器可以使用-d1reportAllClassLayout来调用。有没有这样做的g ++开关?

clang offers the -cc1 -fdump-record-layouts arguments to achieve this. The MS compiler can be called using -d1reportAllClassLayout. Is there any g++ switch that does this?

推荐答案

如果程序是用调试信息编译的,可以使用<$ c $

If the program is compiled with debugging information, you can use pahole to dump the struct and vtable layouts from the debugging information:

g++ -ggdb3 -c program.cpp
pahole program.o

请注意,g ++只会产生调试信息在程序中实际使用的结构,因此您可能需要添加一些虚函数来创建或以其他方式使用结构类型的对象。

Note that g++ will only generate debugging information for structs that are actually used within the program, so you may have to add some dummy functions to create or otherwise use objects of your struct types.

这篇关于有没有办法转储g ++编译程序的类布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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