Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pahole doesn't show classes in namespaces

I am trying to use pahole to analyze the memory layout of a C++ program which has some classes inside namespaces. pahole only lists classes in the global namespace. Is there an option to also list the other classes?

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 */
};
like image 848
Niautanor Avatar asked Jan 29 '26 21:01

Niautanor


1 Answers

After poking around in the source, I found out that the --show_private_classes option also prints classes defined in namespaces.

The namespace qualifier is dropped from the class name (ns1::foo and ns2::foo are both printed as just foo) but it's enough for my use case.

like image 84
Niautanor Avatar answered Feb 01 '26 12:02

Niautanor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!