Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying struct values in GDB

Tags:

c

debugging

gnu

gdb

In GDB, given a variable that points to a struct, print will display the raw pointer value and x will display the raw bytes pointed to. Is there any way to display the data pointed to as that struct, i.e. a list of fields and their values?

like image 495
rwallace Avatar asked Sep 27 '12 09:09

rwallace


1 Answers

print *variable 

If you do that it will display the value of that variable in GDB.
You also have an option to display the struct in an indentation and new line:

$1 = { next = 0x0, flags = { sweet = 1, sour = 1 }, meat = 0x54 "Pork" } 

For that you need to set the pretty print:

set print pretty on 

If you want to print an array of values you do like so:

print *array@len 
like image 90
Yarneo Avatar answered Sep 22 '22 05:09

Yarneo