c++ - pahole 不显示命名空间中的类

标签 c++ namespaces pahole

我正在尝试使用 pahole分析在命名空间中有一些类的 C++ 程序的内存布局。 pahole 只列出全局命名空间中的类。是否可以选择列出其他类?

MWE:

namespace ns {
  class Thing {
    public:
      int y;

      Thing(int y) : y(y) { }
  };
};

class Thong {
  public:
    int z;

    Thong(int z) : z(z) { }
};

int main(void) {
  ns::Thing x(1);
  Thong a(2);
  return x.y + a.z;
}
g++ -ggdb3 test.cpp
pahole --version; pahole a.out
v1.10
class Thong {
public:

    int                        z;                    /*     0     4 */
    void Thong(class Thong *, int);


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

最佳答案

翻了翻源码,发现--show_private_classes选项还打印命名空间中定义的类。

命名空间限定符从类名中删除( ns1::foons2::foo 都打印为 foo ),但对于我的用例来说已经足够了。

关于c++ - pahole 不显示命名空间中的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48965063/

相关文章:

c++ - 前向声明和友元函数

c++ - pahole C++11 支持?

c++ - gdb 退出并显示 : Program received signal SIGILL, 对使用 gcc/intel_mkl/gfortran -mavx 编译的 c c++ 程序的非法指令

c++ - SDL_Image 不显示图像

c++ - 未定义的行为和序列点

c++ - 将 Matlab 代码转换为静态 C++ 库

php - PHP中现有的类名冲突,需要一个创造性的解决方案

c# - 使用 System.Data 而不是 System.Data.SqlClient