我正在汇编程序集中调试c程序,以了解gcc编译器的工作原理。我想读取我的$ fs段寄存器,所以我使用x / x $ fs,但它告诉我它无法访问内存。如何读取i386上包含段,通用和控制寄存器的任何寄存器:86_64?
答案 0 :(得分:11)
info registers
打印出我的寄存器值,这就是你的想法:
(gdb) info registers
rax 0x7ffff7731ec8 140737344904904
rbx 0x0 0
rcx 0x0 0
rdx 0x7fffffffd618 140737488344600
rsi 0x7fffffffd608 140737488344584
rdi 0x1 1
rbp 0x0 0x0
rsp 0x7fffffffd528 0x7fffffffd528
r8 0x7ffff7730300 140737344897792
r9 0x7ffff7dec250 140737351959120
r10 0x7fffffffd390 140737488343952
r11 0x7ffff73d0b50 140737341360976
r12 0x400be0 4197344
r13 0x7fffffffd600 140737488344576
r14 0x0 0
r15 0x0 0
rip 0x402330 0x402330 <main>
eflags 0x246 [ PF ZF IF ]
cs 0x33 51
ss 0x2b 43
ds 0x0 0
es 0x0 0
fs 0x0 0
gs 0x0 0
(gdb)
答案 1 :(得分:9)
info all-registers
为您提供所有寄存器值,包括FPU寄存器堆栈,xmm寄存器。
(gdb) i all-r
rax 0x2aaaaace62ce 46912498459342
rbx 0x2aab18e71290 46914345570960
rcx 0x2aaab2020d60 46912619285856
rdx 0xffffffffffd934ee -2542354
rsi 0x2aab18ec7a40 46914345925184
rdi 0xa 10
rbp 0x2aab18e6f000 0x2aab18e6f000
rsp 0x2aab18e6f000 0x2aab18e6f000
r8 0xe 14
r9 0x2aab18eb1f08 46914345836296
r10 0x2aaab9085000 46912737136640
r11 0x0 0
r12 0x2aab18ec7170 46914345922928
r13 0x477f3280 1199518336
r14 0x7 7
r15 0x2aaada787000 46913298132992
rip 0x2aaaaae3b18e 0x2aaaaae3b18e <flt_fadd+4>
eflags 0x283 643
ds 0x0 0
es 0x0 0
fs 0x0 0
gs 0x0 0
st0 10 (raw 0x4002a000000000000000)
st1 3 (raw 0x4000c000000000000000)
st2 0 (raw 0x00000000000000000000)
st3 0 (raw 0x00000000000000000000)
st4 0 (raw 0x00000000000000000000)
st5 0 (raw 0x00000000000000000000)
st6 0 (raw 0x00000000000000000000)
st7 0 (raw 0x00000000000000000000)
fctrl 0x137f 4991
fstat 0x7000 28672
ftag 0xc0 192
fiseg 0xaae3afe5 -1427918875
fioff 0x2aaa 10922
foseg 0x18e6ee48 417787464
fooff 0x2aab 10923
fop 0x704 1796
xmm0 {f = {0x0, 0x6, 0x0, 0x0}} {f = {0, 6.48876953, 0, 0}}
xmm1 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}}
xmm2 {f = {0x0, 0x1c0, 0x0, 0x0}} {f = {0, 448, 0, 0}}
xmm3 {f = {0x0, 0x1, 0x0, 0x0}} {f = {0, 1.75, 0, 0}}
xmm4 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}}
xmm5 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}}
xmm6 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}}
xmm7 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}}
xmm8 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}}
xmm9 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}}
xmm10 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}}
xmm11 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}}
xmm12 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}}
xmm13 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}}
xmm14 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}}
xmm15 {f = {0x0, 0x0, 0x0, 0x0}} {f = {0, 0, 0, 0}}
mxcsr 0x1fa0 8096
答案 2 :(得分:3)
您必须使用p
和set
命令来读取/设置寄存器。每台机器的寄存器名称不同;使用信息寄存器查看您机器上使用的名称。有关示例的详细信息,请参阅GDB手册的registers部分。
要打印$fs
寄存器的值,您可以执行以下操作:
(gdb) p/x $fs
$1 = 0x0
x
命令执行的操作是检查内存。但是,有些情况下你无法做到。例如,如果地址指向的内存受到保护。因此,如果您尝试检查虚拟地址0x0
的内存,gdb显然拒绝这样做,例如:
(gdb) x/x $fs
0x0: Cannot access memory at address 0x0
希望它有所帮助。祝你好运!