x86汇编RIP寻址验证及GDB查看指定内存地址内容的问题
Hey there! Let's tackle your questions one by one—they're both super relevant for low-level debugging and x86 assembly analysis, so let's dive in.
1. How to view the content stored at 0xaddress(%register)?
You've got two easy, reliable ways to do this in GDB:
Let GDB compute the address directly:
Use thex(examine) command with the exact addressing expression. For example, if you're working with0x1234(%eax), run:x/wx 0x1234+$eaxBreakdown of the format:
wmeans examine 4 bytes (word-sized, ideal for 32-bit registers),xtells GDB to display the value in hexadecimal. Adjust the format as needed: usebfor single bytes,hfor 2-byte half-words,gfor 8-byte words, orsto view a null-terminated string.Calculate the address manually first:
- Fetch the current value of the target register:
(Replaceinfo registers registerregisterwith the actual register name, likeeaxorrbp.) - Add the
0xaddressoffset to the register's value to get the full memory address. - Examine that address with the
xcommand, e.g.:x/wx 0xdeadbeef # Swap this with your computed address
- Fetch the current value of the target register:
2. Understanding cmp 0x204d63(%rip),%eax and viewing its target value
First, the big answer: your core understanding is correct, but there's a tiny precision detail to note.
In x86-64 RIP-relative addressing, disp(%rip) calculates the effective address as:
Effective Address = Current RIP value + disp
The key nuance: when the CPU executes the cmp instruction, %rip already points to the next instruction (not the start of the cmp itself). So the math is indeed %rip + 0x204d63—you just need to remember that %rip here refers to the address right after the cmp instruction, which is how the CPU handles it natively.
To view the value at this address in GDB:
Simplest method (let GDB handle the math):
When your breakpoint hits thiscmpinstruction, run:x/wx 0x204d63+$ripGDB uses the current
$ripvalue (which matches what the CPU uses) to compute the effective address and show you the stored value immediately.Manual calculation method:
- Get the current
%ripvalue:info registers rip - Add
0x204d63to this value to get the target memory address. - Examine the address with:
x/wx <your_computed_address>
- Get the current
Bonus tip: If you use GDB's TUI mode (run
layout asmto enable it), you can useprint 0x204d63+$ripto get the effective address first, then examine it—this is handy if you want to note the address for later use.
内容的提问来源于stack exchange,提问作者9.1827E+11

