(汇编新手)无法从GDB访问x86-64中的32位寄存器 [英] (Assembly newbie) Unable to access 32-bit registers in x86-64 from GDB
问题描述
所以我只是想在这个简单的程序中使用gdb访问 eax
.
So I am just trying to access eax
with gdb in this easy program.
C代码:
int main(){
int a = 1;
int b = 3;
int c = a + b;
return 1;
}
这是我的gdb尝试:
(gdb) disas
Dump of assembler code for function main:
0x000000000040049c <+0>: push %rbp
0x000000000040049d <+1>: mov %rsp,%rbp
0x00000000004004a0 <+4>: movl $0x1,-0x4(%rbp)
0x00000000004004a7 <+11>: movl $0x3,-0x8(%rbp)
0x00000000004004ae <+18>: mov -0x8(%rbp),%eax
0x00000000004004b1 <+21>: mov -0x4(%rbp),%edx
=> 0x00000000004004b4 <+24>: add %edx,%eax
0x00000000004004b6 <+26>: mov %eax,-0xc(%rbp)
0x00000000004004b9 <+29>: pop %rbp
0x00000000004004ba <+30>: retq
End of assembler dump.
(gdb) x $rbp
0x7fffffffe620: 0x00000000
(gdb) x $rbp-4
0x7fffffffe61c: 0x00000001
(gdb) x $rbp-8
0x7fffffffe618: 0x00000003
(gdb) x $eax
0x3: Cannot access memory at address 0x3
所以您可以看到,使用 x $ rbp
访问 rbp
没问题,但是我无法访问 eax
.
So you can see, I have no trouble using x $rbp
to access rbp
, but I'm unable to access eax
.
是否需要打开某些设置才能在64位系统上从gdb访问32位寄存器?
Is there some setting I need to turn on to access 32-bit registers from gdb on a 64-bit system?
推荐答案
x
命令代表 print
命令或 p
,它会显示其参数值.
The x
command stands for examine
. It accepts a pointer as input and shows what's there. You're looking for the print
command, or p
, which prints its argument's value.
p $eax
通过执行 x $ rbp
,您实际上正在查看堆栈中的内容.在您的示例中,看来 rbp
包含地址 0x7fffffffe620
.
By doing x $rbp
, you're actually looking at what's on the stack. It appears that rbp
contains the address 0x7fffffffe620
in your example.
您得到的错误消息 x $ eax
指示 eax
的值为3,并且由于该指针不是有效的指针,因此它向您显示一条错误消息
The error message you get doing x $eax
indicates that the value of eax
is 3, and since that's not a valid pointer, it shows you an error message instead.
这篇关于(汇编新手)无法从GDB访问x86-64中的32位寄存器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!