Displaying struct values in GDB

房东的猫 提交于 2019-12-03 08:40:32

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/12618331/displaying-struct-values-in-gdb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!