Using GDB to debug a program assembled with NASM

From: Joshua Davies (spamtrap_at_crayne.org)
Date: 11/01/04


Date: Mon, 1 Nov 2004 21:56:39 +0000 (UTC)

Hi, I'm new to assembler programming - NASM seems to be a natural
choice for assembler programming under Linux, but I'm having trouble
getting GDB to debug my apps. If I have the following file named
sample.asm:

  section .text
    global _start

  _start:
    mov eax, 1
    add eax, 5

    mov ebx, 0 ; return code
    mov eax, 1 ; syscall 'exit'
    int 0x80

and assemble it with:

$ nasm -f elf -g sample.asm
$ ld sample.o

I can run the resulting a.out just fine. I'd like to step through it
with a debugger, but when I load it with gdb, it won't let me
single-step:

$ gdb a.out
(gdb) break _start
Breakpoint 1 at 0x8048080: file sample.asm, line 6.
(gdb) set step-mode on
(gdb) r
Starting program: a.out

Program exited normally.
(gdb)

It seems to set the breakpoint (I don't get an error message), but it
doesn't stop - it just runs through the whole program. I've tried it
with step-mode on & off (the default) with no luck. Can anybody see
what I'm missing?



Relevant Pages

  • Re: Gnu Debugger + fasm/nasm
    ... For Nasm 0.98.38 ('.39 should be coming ... doesn't need to be anything special, except that gdb likes the first ... There's a lot of help - "help command" - available in gdb itself. ... echo asm debugging commands, see "help" for other gdb comands\n ...
    (comp.lang.asm.x86)
  • Re: Debugging with nasm
    ... >> I wrote a little ASM progie with Nasm and output a ELF executable. ... NASM still doesn't support the gdb debug format. ... > gdb disassemble and info commands to see the code and register values. ... 1st bug in MS win2k source code found after 20 minutes: ...
    (comp.lang.asm.x86)
  • Debugging with nasm
    ... I wrote a little ASM progie with Nasm and output a ELF executable. ... I tried debugging it with DDD and GDB, but none of both is able to display ... If I type "list" in GDB, not only the source code not gets displayed but ...
    (comp.lang.asm.x86)
  • Debugging with Nasm
    ... I wrote a little ASM progie with Nasm and output a ELF executable. ... I tried debugging it with DDD and GDB, but none of both is able to display ... If I type "list" in GDB, not only the source code not gets displayed but ...
    (alt.lang.asm)
  • Re: Debugging with nasm
    ... NASM still doesn't support the gdb debug format. ... I use to define shorter macros for the commands. ... Displays values of normal registers ...
    (comp.lang.asm.x86)