如何在nasm中包含调试信息?

时间:2015-01-02 19:34:44

标签: linux assembly gdb nasm

我有这个源代码:

;  hello.asm  a first program for nasm for Linux, Intel, gcc
;
; assemble: nasm -f elf -l hello.lst  hello.asm
; link:     gcc -o hello  hello.o
; run:          hello 
; output is:    Hello World 

    SECTION .data       ; data section
msg:    db "Hello World",10 ; the string to print, 10=cr
len:    equ $-msg       ; "$" means "here"
                ; len is a value, not an address

    SECTION .text       ; code section
        global main     ; make label available to linker 
main:               ; standard  gcc  entry point

    mov edx,len     ; arg3, length of string to print
    mov ecx,msg     ; arg2, pointer to string
    mov ebx,1       ; arg1, where to write, screen
    mov eax,4       ; write command to int 80 hex
    int 0x80        ; interrupt 80 hex, call kernel

    mov ebx,0       ; exit code, 0=normal
    mov eax,1       ; exit command to kernel
    int 0x80        ; interrupt 80 hex, call kernel

此代码取自here

我在VirtualBox上运行 ubuntu 12.04 32位用于学习目的。

我遵循的步骤是:

  • nasm -f elf -g -F stabs hello.asm
  • ld -o hello hello.o
  • gdb hello -tui

现在,当我只运行 hello 时,它会正常运行,但gdb无法显示任何源代码。为什么?当我在gdb中尝试运行时,我会看到 Hello World 文本,但它没有显示来源。

1 个答案:

答案 0 :(得分:5)

看起来stabs格式不适用于GDB,请尝试使用DWARF(http://en.wikipedia.org/wiki/DWARF

编译
  

nasm -f elf -g -F dwarf hello.asm

然后在gdb类型

  

启动

然后

  

SI

你会看到带有评论的来源。正如Koray Tugay所说,gdb中很可能存在一个错误。

相关问题