3

Forgive me as I'm pretty new here, but I am trying to debug the x86 assembly with gdb.

ex10.asm

global main
extern printf

section .data
        msg db "Testing %i...", 0x0a, 0x00

main:
        push ebp
        mov ebp, esp
        push 123
        push msg
        call printf
        mov eax, 0
        mov esp, ebp
        pop ebp
        ret

compiled and linked with below:

nasm -f elf32 -F dwarf -g ex10.asm -o ex10.o

gcc -m32 -gdwarf ex10.o -o ex10

ex10.o appears to have debug symbols

$ objdump --syms ./ex10.o | grep debug
00000000 l    d  .debug_info    00000000 .debug_info
00000000 l    d  .debug_abbrev  00000000 .debug_abbrev
00000000 l    d  .debug_line    00000000 .debug_line

ex10 appears to have no debug symbols

$ objdump --syms ./ex10 | grep debug
  ----returns nothing----

gdb ./ex10 returns below

$ gdb ./ex10
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
This GDB was configured as "x86_64-linux-gnu".
Reading symbols from ./ex10...
(No debugging symbols found in ./ex10)

After this, I'm not quite sure to look.Any suggestions or info i should provide?

also, nasm version

$ apt list --installed | grep nasm
nasm/focal,now 2.14.02-1 amd64 [installed]

1 Answers1

3

Reproduced with NASM version 2.15.05.

Without section .text (suggested by ssbssa):

readelf -w ex10.o

Section '.debug_aranges' has no debugging data.
Section '.debug_pubnames' has no debugging data.
Section '.debug_info' has no debugging data.
Section '.debug_abbrev' has no debugging data.
Section '.debug_line' has no debugging data.
Section '.debug_frame' has no debugging data.
Section '.debug_loc' has no debugging data.

so naturally you get nothing in the final link output.

Adding section .text before main solves the problem.

Note: you are expecting output from objdump --syms ./ex10 | grep debug, but that is the wrong thing to expect:

  1. there are no symbols named *debug* in your file
  2. you should ~never look at ELF files with objdump. Use readelf instead.

If you insist on using objdump, do this:

objdump -g ex10 | grep debug

Contents of the .debug_aranges section (loaded from ex10):
  Offset into .debug_info:  0x0
Contents of the .debug_info section (loaded from ex10):
Contents of the .debug_abbrev section (loaded from ex10):
Raw dump of debug contents of section .debug_line (loaded from ex10):
Employed Russian
  • 199,314
  • 34
  • 295
  • 362