在 GDB 和 DDD 中调试汇编代码和调试 C 语言代码是一样的,你可以通过设置断点来中断程序的运行,查看变量和寄存器的当前值,并可以对代码进行单步跟踪。图1 是在 DDD 中调试汇编代码时的情景:
 图1 用 DDD 中调试汇编程序
汇编程序员通常面对的都是一些比较苛刻的软硬件环境,短小精悍的ALD可能更能符合实际的需要,因此下面主要介绍一下如何用ALD来调试汇编程序。首先在命令行方式下执行ald命令来启动调试器,该命令的参数是将要被调试的可执行程序:
[xiaowp@gary doc]$ ald hello Assembly Language Debugger 0.1.3 Copyright (C) 2000-2002 Patrick Alken hello: ELF Intel 80386 (32 bit), LSB, Executable, Version 1 (current) Loading debugging symbols...(15 symbols loaded) ald> |
当 ALD 的提示符出现之后,用 disassemble 命令对代码段进行反汇编:
ald> disassemble -s .text Disassembling section .text (0x08048074 - 0x08048096) 08048074 BA0F000000 mov edx, 0xf 08048079 B998900408 mov ecx, 0x8049098 0804807E BB01000000 mov ebx, 0x1 08048083 B804000000 mov eax, 0x4 08048088 CD80 int 0x80 0804808A BB00000000 mov ebx, 0x0 0804808F B801000000 mov eax, 0x1 08048094 CD80 int 0x80 |
上述输出信息的第一列是指令对应的地址码,利用它可以设置在程序执行时的断点:
ald> break 0x08048088 Breakpoint 1 set for 0x08048088 |
断点设置好后,使用 run 命令开始执行程序。ALD 在遇到断点时将自动暂停程序的运行,同时会显示所有寄存器的当前值:
ald> run Starting program: hello Breakpoint 1 encountered at 0x08048088 eax = 0x00000004 ebx = 0x00000001 ecx = 0x08049098 edx = 0x0000000F esp = 0xBFFFF6C0 ebp = 0x00000000 esi = 0x00000000 edi = 0x00000000 ds = 0x0000002B es = 0x0000002B fs = 0x00000000 gs = 0x00000000 ss = 0x0000002B cs = 0x00000023 eip = 0x08048088 eflags = 0x00000246 Flags: PF ZF IF 08048088 CD80 int 0x80 |
如果需要对汇编代码进行单步调试,可以使用 next 命令:
ald> next Hello, world! eax = 0x0000000F ebx = 0x00000000 ecx = 0x08049098 edx = 0x0000000F esp = 0xBFFFF6C0 ebp = 0x00000000 esi = 0x00000000 edi = 0x00000000 ds = 0x0000002B es = 0x0000002B fs = 0x00000000 gs = 0x00000000 ss = 0x0000002B cs = 0x00000023 eip = 0x0804808F eflags = 0x00000346 Flags: PF ZF TF IF 0804808F B801000000 mov eax, 0x1 |
若想获得 ALD 支持的所有调试命令的详细列表,可以使用 help 命令:
ald> help Commands may be abbreviated. If a blank command is entered, the last command is repeated. Type `help <command>' for more specific information on <command>. General commands attach clear continue detach disassemble enter examine file help load next quit register run set step unload window write Breakpoint related commands break delete disable enable ignore lbreak tbreak |
(编辑:aniston)
|