GDB under View Memory command (x command)

Source: Internet
Author: User

http://blog.csdn.net/allenlinrui/article/details/5964046

You can use the Examine command (abbreviated as x) to view the values in the memory address. The syntax for the x command is as follows:

X/<n/f/u> <addr>

N, F, and u are optional parameters.

n is a positive integer that represents the number of memory units that need to be displayed, that is, the contents of several memory units are displayed backwards from the current address, and the size of a memory unit is defined by the following U.

F represents the format shown, see below. If the address refers to a string, then the format can be s, if the ground ten is the instruction address, then the format can be I.

U represents the number of bytes requested from the current address, and if not specified, gdb defaults to 4 bytes. The u parameter can be substituted with the following character, b for single byte, h for Double Byte, W for four bytes, and G for eight bytes. When we specify the byte length, GDB starts by referring to the memory address, reads and writes the specified byte, and takes it as a value.

<addr> represents a memory address.

Note: The relationship between N and U is strictly distinguished, N represents the number of units, and U represents the size of each cell.

N/f/u three parameters can be used together. For example:

Command: X/3uh 0x54320, which reads from memory address 0x54320, h means double-byte units, 3 for output three units, and U for hexadecimal display.

Output format

In general, GDB outputs the value of a variable based on the type of the variable. But you can also customize the format of GDB's output. For example, you want to output the hexadecimal of an integer, or binary to see the bit in the integer variable. To do this, you can use GDB's data display format:

x 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) Help X

Examine Memory:x/fmt ADDRESS.

Address is a expression for the memory address to examine.

FMT is a repeat count followed by a format letter and a size letter.

Format Letters is O (octal), X (hex), D (decimal), U (unsigned decimal),

T (binary), F (float), a (address), I (instruction), C (char) and S (String).

Size Letters is B (byte), H (Halfword), W (word), G (Giant, 8 bytes).

The specified number of objects of the specified size is printed

According to the format.

Defaults for format and size letters is those previously used.

Default count is 1. Default address is following last thing printed

With the This command or "print".

(GDB) P F1

$4 = 8.25

(GDB) P F2

$125.5

(GDB) x/x &f1

0xbffff380:0x41040000

(GDB) X/xw &f1

0xbffff380:0x41040000

(GDB) X/xw &f2

0xbffff384:0x42fb0000

(GDB) X/2xw &f1

0xbffff380:0x41040000 0x42fb0000

(GDB) X/4xw &f1

0xbffff380:0x41040000 0x42fb0000 0xbffff408 0x00bcba66

(GDB) X/TW &f1

0xbffff380:01000001000001000000000000000000

(GDB) X/2TW &f1

0xbffff380:01000001000001000000000000000000 01000010111110110000000000000000

(GDB) P record

$ $ = {12, 76, 48, 62, 94, 17, 32, 37, 52, 69}

(GDB) P &record

$11 = (int (*) [ten]) 0x8049740

(GDB) X/4uw 0x8049740

0x8049740 <record>: 12 76 48 62

(GDB) X/6ow 0x8049740

0x8049740 <record>: 014 0114 060 076

0x8049750 <record+16>: 0136 021

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.