9

我正在汇编中调试 ac 程序以了解 gcc 编译器的工作原理。我想读取我的 $fs 段寄存器,所以我使用 x/x $fs,但是它告诉我它无法访问内存。如何读取 i386:86_64 上包括段、通用和控制寄存器的任何寄存器?

4

3 回答 3

14

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) 
于 2012-04-26T00:13:34.150 回答
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
于 2012-11-15T13:56:38.830 回答
4

您必须使用pset命令来读取/设置寄存器。每台机器的寄存器名称不同;使用信息寄存器查看您机器上使用的名称。有关示例的详细信息,请参阅GDB 手册的寄存器部分。

要打印$fs寄存器的值,您可以这样做:

(gdb) p/x $fs
$1 = 0x0

命令所做的是x检查内存。但是,在某些情况下,您无法做到。例如,如果某个地址指向的内存受到保护。因此,如果您尝试检查虚拟地址处的内存0x0,gdb 显然拒绝这样做,例如:

(gdb) x/x $fs
0x0:    Cannot access memory at address 0x0

希望能帮助到你。祝你好运!

于 2012-04-26T00:05:46.867 回答