簡體   English   中英

如何在nasm中包含調試信息?

[英]How can I include debug information with 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

此代碼取自此處

我在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矮人hello.asm

然后在gdb類型

開始

然后

SI

你會看到有評論的來源等等。 正如Koray Tugay所說,gdb中很可能存在一個錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM