Reputation: 53
I have my structure with several members and I would like to see them all indexed in order.
Struct Ant
{
int type;
char name[100];
long long int food;
}
Now, when I execute the command in gdb
(gdb) ptype struct Ant
$1 = struct
{
int type;
char name[100];
long long int food;
}
I would like to see the output something like
{
0, int type;
1, char name[100];
2, long long int food;
}
Is there a way to get the index of each structure field in order in GDB ?
Upvotes: 0
Views: 187
Reputation: 22519
There is no built-in way to do this. If you need this you can write it yourself in a couple of ways.
One way would be to use the gdb CLI: use set logging
and friends to dump the ptype
output to a file, then use shell
to run some other command on the file to format it the way you like.
Another way would be to use gdb's Python scripting capability to inspect the type and display it how you like. If you search for the pahole
command (maybe already on your system, try locate pahole.py
-- some Linux distros ship this) you can see an example of how this is done.
Upvotes: 1