简体   繁体   中英

How to include debug symbols in NASM code for debugging using GDB on Windows?

How to include debug symbols in NASM code for debugging using GDB on Windows?

Having coded some NASM assembly, I want to debug it using GDB.

I assemble and link using the following commands:

nasm -f win32 insertion_sort.asm    
ld insertion_sort.obj

However, starting GDB ( gdb a ) yields:

Reading symbols from C:\Users\nze\Desktop\asm\sorting\insertion_sort\a.exe...(no debugging symbols found)...done.

In the code below I cannot reference _array like:

(gdb) x/4xw _array
No symbol table is loaded.  Use the "file" command.
(gdb) x/4xw array
0x1:    Cannot access memory at address 0x1

Also, setting breakpoint at _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]

causes GDB to just run the program to completion when run...

What is wrong?

The assembly code is:

    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

您是否尝试过包括可用于Windows(Codeview 8)的调试信息?

$ nasm -gcv8 -f win32 -o insertion_sort.o insertion_sort.asm $ gcc -m32 -o insertion_sort.exe insertion_sort.o

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM