I. Program variables
to view the value of a variable in a file:
file::variable
function::variable
You can specify the variables you want to see in this form, in which file or in which function. For example, view the value of global variable x in file f2.c:
gdb) P ' f2.c ':: X
two. View the value of an array
Sometimes you need to look at the value of a contiguous amount of memory space. For example, a paragraph of an array, or the size of dynamically allocated data. You can use GDB's "@"
The left side of the "@" is the value of the address of the first memory, and the right side of "@" you want to see the length of the memory. For example, there is a statement in your program that says:
int *array = (int *) malloc (len * sizeof (int));
so, during GDB debugging, you can display the value of this dynamic array as follows:
P *[email Protected]
Two-dimensional array printing
P **[email Protected]
If it is a static array, you can display the contents of all the data in the array directly with the print array name.
-
It is common for gdb to print out the contents of some strings when debugging, by
p [email protected]_len when printing a string, there is usually a length limit, I test the Linux machine defaults to 200, but the actual output length Str_len may be greater than this value. The result is not fully output, but omitted, by command
Set Print element 0You can do it.
p/xx Displays the variable in hexadecimal format.
d Displays the variable in decimal format.
u displays unsigned integers in hexadecimal format.
o Displays the variable in octal format.
T displays the variable in binary format.
a displays the variable in hexadecimal format.
c Displays the variable in character format.
f Displays the variable in floating-point number format.
GDB print variable and array values under Emacs