GDB print variable and array values under Emacs

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.