首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

用gdb取得寄存器的值

2012-12-21 
用gdb获得寄存器的值This GDB was configured as i686-linux-gnu.For bug reporting instructions, plea

用gdb获得寄存器的值

This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/ubuntu/gdb_debug...done.
(gdb) b main
Breakpoint 1 at 0x804840a: file gdb_debug.c, line 11.
(gdb) r
Starting program: /home/ubuntu/gdb_debug

Breakpoint 1, main () at gdb_debug.c:11
11f1();
(gdb) list
6double x = -5.5625;
7printf("%d\n",x);
8}
9main()
10{
11f1();
12}
(gdb) x/i $pc
=> 0x804840a <main+6>:call   0x80483c4 <f1>
(gdb) si
f1 () at gdb_debug.c:3
3{
(gdb) si
0x080483c53{
(gdb) si
0x080483c73{
(gdb) disass main
Dump of assembler code for function main:
   0x08048404 <+0>:push   %ebp
   0x08048405 <+1>:mov    %esp,%ebp
   0x08048407 <+3>:and    $0xfffffff0,%esp
   0x0804840a <+6>:call   0x80483c4 <f1>
   0x0804840f <+11>:mov    %ebp,%esp
   0x08048411 <+13>:pop    %ebp
   0x08048412 <+14>:ret   
End of assembler dump.
(gdb) disass f1
Dump of assembler code for function f1:
   0x080483c4 <+0>:push   %ebp
   0x080483c5 <+1>:mov    %esp,%ebp
=> 0x080483c7 <+3>:push   %ebx
   0x080483c8 <+4>:sub    $0x24,%esp
   0x080483cb <+7>:mov    $0x3039,%ebx
   0x080483d0 <+12>:mov    $0x80484e0,%eax
   0x080483d5 <+17>:mov    %ebx,0x4(%esp)
   0x080483d9 <+21>:mov    %eax,(%esp)
   0x080483dc <+24>:call   0x80482f4 <printf@plt>
   0x080483e1 <+29>:fldl   0x80484e8
   0x080483e7 <+35>:fstpl  -0x10(%ebp)
   0x080483ea <+38>:mov    $0x80484e0,%eax
   0x080483ef <+43>:fldl   -0x10(%ebp)
   0x080483f2 <+46>:fstpl  0x4(%esp)
   0x080483f6 <+50>:mov    %eax,(%esp)
   0x080483f9 <+53>:call   0x80482f4 <printf@plt>
   0x080483fe <+58>:add    $0x24,%esp
   0x08048401 <+61>:pop    %ebx
   0x08048402 <+62>:pop    %ebp
   0x08048403 <+63>:ret   
---Type <return> to continue, or q <return> to quit---
End of assembler dump.
(gdb)

IP是指令寄存器,存放当前指令的下一条指令的地址。CPU该执行哪条指令就是通过IP来指示的。
EIP是32位机的指令寄存器。

IP:instruction pointer
PC: progtam counter 
两者都是一个寄存器,指向当前执行指令的下一条指令。


(gdb) info all-registers  //显示所有寄存器的内容
eip            0x80483c50x80483c5 <f1+1>

(gdb) disass f1   //反汇编函数f1
Dump of assembler code for function f1:
   0x080483c4 <+0>:push   %ebp
=> 0x080483c5 <+1>:mov    %esp,%ebp
   0x080483c7 <+3>:push   %ebx

EBP: 栈底指针
ESP: 栈顶指针

通用寄存器:
(gdb) info all-registers
eax            0xbffff1d4-1073745452
ecx            0xf877f12f-126357201
edx            0x11
ebx            0x303912345  //寄存器变量存在此
st0~7是80位的浮点数寄存器,用于存放浮点数:
st0            0(raw 0x00000000000000000000)
st1            0(raw 0x00000000000000000000)
st2            0(raw 0x00000000000000000000)
st3            0(raw 0x00000000000000000000)
st4            0(raw 0x00000000000000000000)
---Type <return> to continue, or q <return> to quit---
st5            0(raw 0x00000000000000000000)
st6            0(raw 0x00000000000000000000)
st7            -5.5625(raw 0xc001b200000000000000)

热点排行