首页 > 解决方案 > NASM 中的调试符号(再一次)

问题描述

这个问题已经在 StackOverflow 上被问过好几次了,但我尝试了所有的答案,但我仍然无法让 NASM 包含 DWARF 调试符号。

我在 Ubuntu 18.04 64 位下使用 NASM 2.13.02。我不确定我是否还缺少某些东西?

万一这很重要,我实际上想同时使用 LLDB 和 GDB。

谢谢。

这是我的代码:

section .bss
section .text

global _start

_start:
    mov ebx, 0
    mov eax, 1
    int 80h

这是我构建和链接它的方式:

nasm -g -F dwarf -f elf64 hello.asm
ld -s -o hello hello.o

结果文件是:

$ ls -la hello
-rwxr-xr-x 1 terry terry 352 Sep  4 18:21 hello
$

尝试检查是否包含 DWARF 数据:

$ dwarfdump hello
No DWARF information present in hello
$

在 gdb 下运行:

$ gdb ./hello 
GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
[... snip copyright ...]
Reading symbols from ./hello...(no debugging symbols found)...done.
(gdb) 

标签: assemblygdbnasmlldbdwarf

解决方案


我根据@Michael Petch 的建议自我回答我自己的问题,他是真正找到根本原因的人。

问题是我使用ld-s意思是“全部剥离”,包括调试符号,即我正在破坏自己的努力。

正确的命令应该是:

nasm -g -F dwarf -f elf64 hello.asm
ld -o hello hello.o

现在,使用 gdb:

$ gdb ./hello 
GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
[.. snip copyright ..]
Reading symbols from ./hello...done.

(gdb) b _start
Breakpoint 1 at 0x400080: file hello.asm, line 7.

(gdb) run
Starting program: /home/terry/hello 

Breakpoint 1, _start () at hello.asm:7
7       xor ebx, 0
(gdb) 
$

推荐阅读