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
时间: 2024-11-06 02:50:42