第3章“程序的机器级表示”:使用 GDB 调试器

如下表格中给出了一些 GDB 命令的例子,在使用机器级 IA32 程序时,会有所帮助。先运行 OBJDUMP 来获得程序的反汇编版本,是大有益处的。示例都是基于对文件 prog 运行 GDB 的。使用如下的命令行来启动 GDB:

unix> gdb prog

通常的方法是在程序中感兴趣的地方附近设置断点。断点可以设置在函数入口后面,或是设置在一个程序的地址处。在程序执行过程中,遇到一个断点时,程序会停下来,并将控制返回给用户。在断点处,能够以各种方式查看各个寄存器和存储器位置。也可以单步跟踪程序,一次只执行几条指令,或是前进到下一个断点。

命令 效果
开始和停止
quit Exit GDB
run Run your program(give command line arguments here)
kill Stop your program
断点
break sum Set breakpoint at entry to function sum
break *0x80483c3 Set breakpoint at address 0x80483c3
delete 1 Delete breakpoint 1
delete Delete all breakpoints
执行
stepi Execute one instruction
stepi 4 Execute four instructions
nexti Like stepi, but proceed through function calls
continue Resume execution
finish Run until current function returns
检查代码
disas Disassemble current function
disas sum Disassemble function sum
disas 0x80483b7 Disassemble function around address 0x80483b7
disas 0x80483b7 0x80483c7 Disassemble code within speci.ed address range
print /x $eip Print program counter in hex
检查数据
print $eax Print contents of %eax in decimal
print /x $eax Print contents of %eax in hex
print /t $eax Print contents of %eax in binary
print 0x100 Print decimal representation of 0x100
print /x 555 Print hex representation of 555
print /x ($ebp + 8) Print contents of %ebp plus 8 in hex
print *(int *) 0xbffff890 Print integer at address 0xbffff890
print *(int *) ($ebp + 8) Print integer at address %ebp + 8
x/2w 0xbffff890 Examine two(4-byte)words starting at address 0xb-ffff890
x/20b sum Examine .rst 20 bytes of function sum
有用的信息
info frame Information about current stack frame
info registers Values of all the registers
help Get information about GDB

你可能感兴趣的:(#,深入理解计算机系统,GDB)