Aman Jain
Aman Jain

Reputation: 11317

How to print a C structure recursively in gdb

How can I make gdb print a structure's fields recursively,
i.e. follow pointers.

Right now, I have to go inside each field and either specify a '*' to print
the sub structure, or have to type cast to see what's inside the substructure.

e.g.

typedef struct {
int a;
}A;

typedef struct {
A *pA;
int b;
}B;

typedef struct {
B *pB;
int c;
}C;

C var_c;
C *pC = var_c;

... ...

Now, I would like to do "p *pc" on gdb prompt,
to see everything rather than just the address of pB.

Upvotes: 7

Views: 3162

Answers (1)

Employed Russian
Employed Russian

Reputation: 213516

The best way to achieve what you want is to write a python pretty-printer for your structs. Documentation here.

Upvotes: 2

Related Questions