How do I show which fields a structure has in GDB?

I came across a structure (called ngx_http_variable_value_t ) in my GDB session (debugger), and I would like to print which fields it has in the console.

Is it possible?

+59
c emacs nginx gdb
Nov 20 '09 at 6:06
source share
7 answers

You can use the gdb ptype command to print out the definition of a structure or class.

+105
Nov 20 '09 at 13:28
source share

If you have debugging symbols, you can simply print the value: print variable or print *variable if it is a pointer to a structure.

+57
Nov 20 '09 at 6:10
source share

set print pretty on

This option also gives newlines and padding for p *my_struct_pointer .

What do you prefer:

 $2 = {path = {mnt = 0xffff8800070ce1a0, dentry = 0xffff880006850600},last = {{{hash = 3537271320, len = 2}, hash_len = 12127205912}, name = 0xffff88000659501c "../b.out"} 

or

 $3 = { path = { mnt = 0xffff8800070ce1a0, dentry = 0xffff880006850600 }, last = { { { hash = 3537271320, len = 2 }, hash_len = 12127205912 }, name = 0xffff88000659501c "../b.out" }, } 
+12
Feb 18 '17 at 20:00
source share

In addition to using the command line option, you can also use graphical debuggers. I suggest gdbgui , but there are quite a few of them.

screenshot

Disclaimer: I am a developer of gdbgui

+5
Feb 16 '17 at 22:22
source share

I did this only through the graphical interfaces for gdb. Found this entry in gdb online docs. Hope it helps. I believe this will require the code to be created with debugging information included.

ptype [arg] ptype accepts the same arguments as whatis, but prints a detailed description of the type, not just the type name.

Debugging with GDB: Symbols

+2
Nov 20 '09 at 7:58
source share

I would look at the Data Display Debugger .

+1
Nov 20 '09 at 8:31
source share
  p *((struct my_struct*) variable) 

This will help you print structure details in GDB.

0
Mar 19 '19 at 5:45
source share



All Articles