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

标签 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 你好你好.o
  • gdb 你好-tui

现在,当我只运行 hello 时,它会正常运行,但 gdb 无法显示任何源代码。为什么?当我在 gdb 中尝试 run 时,我会看到很好的 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 - 如何在 nasm 中包含调试信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27747556/

相关文章:

python - 如果通过 strcpy() 获取用户输入,用户输入是否会被复制到超出空格或空字符的堆栈上

linux - 为什么我不能拦截子进程的段错误信号?

c - 编译器-调试器的奇怪行为

assembly - 汇编jmp内存表达式

linux - 在 ARM (armv7l/arm64/aarch64) 上构建 mongo shell 3.2.x - 段错误

linux - 学习网络驱动程序接口(interface)的好链接

assembly - 如何获取没有 NUL 字节的 objdump?

linux - 通过matlab设置FreeSurfer主题目录

java - 如何将 Java 应用程序安装到我的 linux 系统

c - 汇编代码会忽略 const 关键字吗?