我有这个源代码:

;  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中运行tryp时,我会看到Hello World文本很好,但它没有显示源代码.

解决方法:

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

编译

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

然后在gdb类型

start

然后

si

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

标签: linux, gdb, assembly, nasm

相关文章推荐

添加新评论,含*的栏目为必填