GDB print details

Source: Internet
Author: User
Tags print object

The format of the print command in GDB print is: print xxx p xxx 1. print operator @ is an array-related operator, which will be described in more detail later.: Specifies a variable in a file or function. {} Indicates an object pointing to the memory address type. 2. view content global variables (visible to all files) Static global variables (visible to the current file) local variables (visible to the current Scope) if your local variables conflict with global variables (that is, duplicate names), the local variables usually hide the global variables. If you want to view the value of global variables, you can use the ":" OPERATOR: file: variable function: variableeg: to view the value of global variable x in file f2.c: gdb) P' f2. c ': x Note: If optimization options are enabled during program compilation, some variables may be inaccessible when you use GDB to debug the Optimized Program, or a value error code. To deal with this situation, you need to disable compilation optimization during program compilation. GCC, you can use the "-gstabs" option to solve this problem. 3. view array (1) dynamic array: p * array @ len array: the first address of the array, len: the length of the Data. eg: (gdb) p * array @ len $1 = {2, 4, 6, 8, 10} (2) the print array name can be directly used for static arrays, all the data in the array is displayed. 4. Output Format x displays variables in hexadecimal format. D. Display variables in decimal format. U displays unsigned integers in hexadecimal format. O display variables in octal format. T display variables in binary format. A displays variables in hexadecimal format. C. Display variables in character format. F. Display variables in floating point format. Eg: (gdb) p I $21 = 101 (gdb) p/a I $22 = 0x65 (gdb) p/c I $23 = 101 'E' 5. check the memory and use examine (abbreviated as x) to view the value in the memory address. Syntax: x/n, f, and u are optional parameters. (1) n is a positive integer that shows the memory length, that is, the content of several addresses is displayed from the current address to the back. (2) f indicates the display format. See the preceding section. If the address refers to a string, the format can be s. If location 10 is the instruction address, the format can be I. (3) u indicates the number of bytes requested from the current address. If not specified, GDB defaults to 4 bytes. The u parameter can be replaced by the following characters. B represents a single byte, h represents a double byte, w represents a four-character section, and g represents an eight-character section. When we specify the byte length, GDB reads and writes the specified byte starting from the memory address specified by the memory and takes it as a value. Eg: x/3uh 0x54320: Read content from memory address 0x54320. h indicates that two bytes are used as a unit, 3 indicates three units, and the u table is displayed in hexadecimal format. 6. Check register (1) it is very easy to view the register value. You can run the following command: info registers (2) to view the register information. (Except floating-point registers) info all-registers (3) view all registers. (Including floating-point registers) info registers (4) view the status of the specified register. The register contains the data when the program is running, such as the instruction address (ip) that the program is currently running, and the current stack address (sp) of the program. You can also use the print command to access the register. You only need to add a $ symbol before the register name. For example, p $ eip. 7. the format of variables automatically displayed by display is: display [/I | s] [expression | addr] eg: display/I $ pc is the environment variable of GDB, indicates the instruction address, And/I indicates that the output format is machine instruction code, that is, assembly. When the program is stopped, the source code corresponds to the machine script code. This is a very interesting function. (2) Other undisplay delete displays are automatically deleted. dnums indicates the automatically displayed number. If you want to delete multiple numbers at the same time, they can be separated by spaces. If you want to delete numbers within a range, you can use a minus sign (for example, 2-5) disable display enable display disable and enalbe do not delete automatic display settings, but only make them invalid and restored. Info display: displays the automatically displayed information of the display settings. GDB generates a table and reports to you how many automatic display settings are set in debugging, including the number, expression, and enable. 8. set (1) set print address on to open the address output. When the program displays the function information, GDB displays the parameter address of the function. (2) set print array on open the array display. When the array is displayed, each element occupies one line. If it is not opened, each element is separated by commas. (3) set print elements is mainly used to set arrays. If your array is too large, you can specify a maximum length for data display. When this length is reached, GDB is no longer displayed. If it is set to 0, it indicates no restriction. (4) set print null-stop if this option is enabled, when the string is displayed, the end character is used to stop the display. This option is off by default. (5) set print pretty on if the printf pretty option is enabled, it will be pretty when GDB displays the struct. For example: $1 = {next = 0x0, flags = {sweet = 1, sour = 1}, meat = 0x54 "Pork"} (6) set print union specifies whether the consortium data in the struct is explicitly displayed. (7) set print object is in C ++. If an object Pointer Points to its derived class, if this option is enabled, GDB will automatically display the output according to the rules of the virtual method call, if you disable this option, GDB will ignore the virtual function table.

Related Article

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.