gdb cpuid GNU gdb Red Hat Linux (5.3post-0.20021129.18rh) Copyright 2003 Free Software Foundation, Inc. GDB is free software, covered bythe GNU General Public License, and you are welcome to change itand/or distribute copies ofit under certain conditions. Type "show copying"to see the conditions. There is absolutely no warranty for GDB. Type "show warranty"for details. This GDB was configured as"i386-redhat-linux-gnu"... (gdb)
使用 run 命令直接运行 cpuid 程序:
1 2 3 4 5
(gdb) run Starting program: /root/Test/cpuid The processor Vendor ID is'GenuineIntel' Program exited normally. (gdb)
可以使用 break 命令设置断点,汇编语言设定断点,必须指定某个标签的相对位置。格式如下:
1
break * label+offset
gdb 会直接忽略 _start 这个标签的断点:
1 2 3 4 5 6 7
(gdb) break * _start Breakpoint 1 at 0x8048074: file cpuid.s, line 9. (gdb) run Starting program: /root/Test/cpuid The processor Vendor ID is 'GenuineIntel' Program exited normally. (gdb)
(gdb) break * _start+1 Breakpoint 2 at 0x8048075: file cpuid.s, line 10. (gdb) run Starting program: /root/Test/cpuid Breakpoint 2, <function called from gdb> Current language: auto; currently asm (gdb) next 11 cpuid (gdb) next 12 movl $output, %edi (gdb) step 13 movl %ebx, 28(%edi) (gdb) step 14 movl %edx, 32(%edi) (gdb) cont Continuing. The processor Vendor ID is 'GenuineIntel' Program exited normally. (gdb)
如上操作,设置断点之后,直接 run 命令可以运行程序,到达断点就暂停。这时,使用 next 或者 step 命令可以单步执行每条指令;使用 cont 命令可以继续以正常的方式继续执行。 next 可以简化为 n;step 可以简化为 s;cont 可以简化为 c