什么是Linux相当于MSVC ++的选项/ d1reportSingleClassLayout? [英] What is the Linux equivalent to MSVC++'s option /d1reportSingleClassLayout?

查看:1138
本文介绍了什么是Linux相当于MSVC ++的选项/ d1reportSingleClassLayout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发到Linux,但我不能找到我可以得到类似于/ d1reportSingleClassLayout从MSVC ++在g ++或clang ++下的输出。如果这些编译器没有这样的功能,是否有一个外部工具提供类似的可视化?

I am moving development to Linux but I couldn't find how I can get an output similar to /d1reportSingleClassLayout from MSVC++ under g++ or clang++. If these compiler do not have such a feature, is there an external tool that provides similar visualization?

推荐答案

文件的调试信息( -g 选项),然后使用 pahole 显示结构布局。 pahole 通常可从 dwarves 包(来源; 在GitHub上< a>; 在Ubuntu )。

You need to compile the file with debugging information (-g option) then use pahole to display the struct layout. pahole is usually available from the dwarves package (source; on GitHub; in Ubuntu).

$ g++ -ggdb -c -o myfile.o myfile.cpp
$ pahole -C MyClass myfile.o
class MyClass {
public:

    int ()(void) * *           _vptr.MyClass;        /*     0     4 */
    int                        i;                    /*     4     4 */
    const char  *              c;                    /*     8     4 */
    void MyClass(class MyClass *, const class MyClass  &);

    void MyClass(class MyClass *);

    virtual void ~MyClass(class MyClass *, int);


    /* size: 12, cachelines: 1, members: 3 */
    /* last cacheline: 12 bytes */
};

-C 选项可让您选择类/结构体检查。

The -C option lets you select which class/struct to examine.

如果你没有访问 pahole ,你可以得到相同的信息从 readelf -wi myfile.o eu-readelf -winfo myfile.o 中可读的形式。本文 https://www.kernel.org/doc /ols/2007/ols2007v2-pages-35-44.pdf 描述 pahole 与其他 dwarves 工具。

If you don't have access to pahole you can get the same information in a much less readable form from readelf -wi myfile.o or eu-readelf -winfo myfile.o. The paper https://www.kernel.org/doc/ols/2007/ols2007v2-pages-35-44.pdf describes pahole alongside other dwarves tools.

这篇关于什么是Linux相当于MSVC ++的选项/ d1reportSingleClassLayout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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