首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在NASM代码中包含调试符号,以便在Windows上使用GDB进行调试?

如何在NASM代码中包含调试符号,以便在Windows上使用GDB进行调试?
EN

Stack Overflow用户
提问于 2016-08-04 15:38:00
回答 1查看 1.5K关注 0票数 2

如何在NASM代码中包含调试符号,以便在Windows上使用GDB进行调试?

在编写了一些NASM程序集之后,我希望使用GDB来调试它。

我使用以下命令进行组装和链接:

代码语言:javascript
复制
nasm -f win32 insertion_sort.asm    
ld insertion_sort.obj

但是,启动GDB (gdb a)会产生:

代码语言:javascript
复制
Reading symbols from C:\Users\nze\Desktop\asm\sorting\insertion_sort\a.exe...(no debugging symbols found)...done.

在下面的代码中,我不能引用_array,例如:

代码语言:javascript
复制
(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设置断点

代码语言:javascript
复制
(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在运行时只运行程序完成.

怎么了?

汇编代码是:

代码语言:javascript
复制
    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
EN

回答 1

Stack Overflow用户

发布于 2016-11-08 14:57:19

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38771773

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档