我正在尝试使用 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::foo
和 ns2::foo
都打印为 foo
),但对于我的用例来说已经足够了。
关于c++ - pahole 不显示命名空间中的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48965063/