码迷,mamicode.com
首页 > 数据库 > 详细

gdb汇编调试tips

时间:2015-02-16 15:29:28      阅读:351      评论:0      收藏:0      [点我收藏+]

标签:

1、内存查看命令x.

x/x 以十六进制输出

x/d 以十进制输出

x/c 以单字符输出

x/i  反汇编 – 通常,我们会使用 x/10i $ip-20 来查看当前的汇编($ip是指令寄存器)

x/s 以字符串输出

(gdb) x/10i main
   0x80483bb <main>:    push   %ebp
   0x80483bc <main+1>:    mov    %esp,%ebp
   0x80483be <main+3>:    and    $0xfffffff0,%esp
   0x80483c1 <main+6>:    sub    $0x20,%esp
   0x80483c4 <main+9>:    movl   $0x0,0x1c(%esp)
   0x80483cc <main+17>:    movl   $0x5,(%esp)
=> 0x80483d3 <main+24>:    call   0x8048394 <fact>
   0x80483d8 <main+29>:    mov    %eax,0x1c(%esp)
   0x80483dc <main+33>:    mov    0x1c(%esp),%eax
   0x80483e0 <main+37>:    leave  

 

2、内存断点break

break *addr 表示在地址addr处打断点.

(gdb) disassemble main
Dump of assembler code for function main:
   0x080483bb <+0>:    push   %ebp
   0x080483bc <+1>:    mov    %esp,%ebp
   0x080483be <+3>:    and    $0xfffffff0,%esp
   0x080483c1 <+6>:    sub    $0x20,%esp
   0x080483c4 <+9>:    movl   $0x0,0x1c(%esp)
   0x080483cc <+17>:    movl   $0x5,(%esp)
   0x080483d3 <+24>:    call   0x8048394 <fact>
   0x080483d8 <+29>:    mov    %eax,0x1c(%esp)
   0x080483dc <+33>:    mov    0x1c(%esp),%eax
   0x080483e0 <+37>:    leave  
   0x080483e1 <+38>:    ret    
End of assembler dump.
(gdb) b *0x080483d3
Breakpoint 1 at 0x80483d3: file test.c, line 14.
(gdb) run
Starting program: /mnt/hgfs/Share/csapp/a.out 

Breakpoint 1, 0x080483d3 in main () at test.c:14
14        c = fact(5);

 

3、打印寄存器

可以使用 info registers查看所有寄存器:

(gdb) info registers 
eax            0xbffff6c4    -1073744188
ecx            0x6400d69f    1677776543
edx            0x1    1
ebx            0x288ff4    2658292
esp            0xbffff5f0    0xbffff5f0
ebp            0xbffff618    0xbffff618
esi            0x0    0
edi            0x0    0
eip            0x80483c4    0x80483c4 <main+9>
eflags         0x286    [ PF SF IF ]
cs             0x73    115
ss             0x7b    123
ds             0x7b    123
es             0x7b    123
fs             0x0    0
gs             0x33    51

或者使用 p/x $ebp打印ebp寄存器的值

(gdb) p/x $ebp
$2 = 0xbffff618

 

4、设置观察点

 当我们需要关注每次执行后ebp的值,可以用display设置观察点

(gdb) display $ebp
1: $ebp = (void *) 0xbffff618
(gdb) si
14        c = fact(5);
1: $ebp = (void *) 0xbffff618
(gdb) si
0x080483d3    14        c = fact(5);
1: $ebp = (void *) 0xbffff618

 

gdb汇编调试tips

标签:

原文地址:http://www.cnblogs.com/ym65536/p/4264731.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!