【发布时间】:2016-08-04 15:38:00
【问题描述】:
如何在 NASM 代码中包含调试符号以在 Windows 上使用 GDB 进行调试?
编写了一些 NASM 程序集后,我想使用 GDB 对其进行调试。
我使用以下命令进行组装和链接:
nasm -f win32 insertion_sort.asm
ld insertion_sort.obj
但是,启动 GDB (gdb a) 会产生:
Reading symbols from C:\Users\nze\Desktop\asm\sorting\insertion_sort\a.exe...(no debugging symbols found)...done.
在下面的代码中,我无法引用 _array 之类的:
(gdb) x/4xw _array
No symbol table is loaded. Use the "file" command.
(gdb) x/4xw array
0x1: Cannot access memory at address 0x1
另外,在_exit处设置断点:
(gdb) break exit
Breakpoint 1 at 0x401464
(gdb) run
Starting program: C:\Users\nze\Desktop\asm\sorting\insertion_sort/insertion_sort.exe
[New Thread 5488.0x1c7c]
[New Thread 5488.0xc54]
[Inferior 1 (process 5488) exited with code 01]
导致 GDB 在运行时只运行程序完成...
怎么了?
汇编代码为:
BITS 32
section .data
_array: dd 4, 2, 8, 6, 1
_len: equ ($ - _array) / 4
section .text
global _start
_start:
push ebp
mov ebp, esp
xor ecx, ecx
_outer:
inc ecx
cmp ecx, _len
jge _exit
mov ebx, ecx
dec ebx
lea esi, [_array + ecx * 4]
lea edi, [_array + ebx * 4]
_inner:
cmp ebx, 0
jl _outer
mov eax, [edi]
cmp eax, [esi]
jle _outer
xchg eax, dword [esi] ; swap [esi] and [edi]
mov dword [edi], eax
sub esi, 4
sub edi, 4
dec ebx
jmp _inner
_exit:
mov esp, ebp
pop ebp
ret
【问题讨论】:
-
我的
nasm说:'win32' 输出格式的有效调试格式是('*' 表示默认):* null Null 调试格式。除非你说别的,否则除了使符号全局化并使用反汇编之外,你无能为力。 -
你会写示例命令吗?
-
小丑,为什么我需要使符号全局化?
-
这是怎么回事?为什么这个问题有来自不同用户的相同代码this one?
-
您实际上不需要调试符号,普通符号可以很好地进行汇编调试。
x/4xw array的问题在于,无论出于何种原因,您都需要输入x/4xw &array。
标签: debugging assembly gdb nasm mingw32