Search code examples
assemblygdbnasmlldbdwarf

Debug symbols in NASM (once more)


This question has been asked several times on StackOverflow but I tried all the answers and I still cannot get NASM to include DWARF debugging symbols.

I am using NASM 2.13.02 under Ubuntu 18.04 64-bit. I am not sure if I am still missing something?

In case it matters, I would actually like to use both LLDB and GDB.

Thanks.

Here is my code:

section .bss
section .text

global _start

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

Here is how I build and link it:

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

The resulting file is:

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

Trying to check if DWARF data is included:

$ dwarfdump hello
No DWARF information present in hello
$

Running it under 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) 

Solution

  • I am self-answering my own question based on a suggestion from @Michael Petch who was the person that actually found the root cause.

    The issue was that I was using ld with -s which means "strip all", including debug symbols, i.e. I was undermining my own effort.

    The correct commands should be:

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

    Now, with 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) 
    $