How do I show what fields a struct has in GDB?

c gdb
prismofeverything picture prismofeverything · Nov 20, 2009 · Viewed 87.8k times · Source

I came upon a struct (called ngx_http_variable_value_t) in my GDB (debugger) session and I would like to print what fields it has in the console.

Is that possible?

Answer

Nate picture Nate · Nov 20, 2009

You can use the GDB command ptype to print out the definition of a struct or class.

Additionally, use ptype /o to print offsets and sizes of all fields in a struct (like pahole).