10

I'm working on a toy bootloader/kernel written in assembly and run on the qemu emulator. I can run qemu with -s -S option and debug with gdb using remote target, but I don't have any debug symbols loaded with gdb. How can I generate a symbol file from my assembly?

I'm using nasm to generate a binary image for qemu to run from my assembly file, but I haven't found anyway to include debug information in the image itself (I'm not sure if that even makes sense). I also found that gdb allows you to load an separate symbol file for debugging, so now my issue is how to generate a symbol file from my assembly code.

I've seen suggestions to use objcopy, but I believe that only works on elf files, not binary. I've tried getting nasm to generate an elf, but it keeps barfing because of my (necessary) org directive in the assembly file.

brianmearns
  • 9,581
  • 10
  • 52
  • 79

2 Answers2

9

It would say try it like this:

  1. use "-f elf -F dwarf -g" switches when assembling. This should produce elf file that contains debug symbols (and code and everything else).
  2. Use objcopy to generate binary file.
  3. Load binary file to your system.
  4. Attach debugger, then tell it to load symbols from your .elf file (symbol-file yourfile.elf)

You need to solve why nasm can't generate .elf file with .org you have in there. I have no idea. GNA as is fine with this.

SOFe
  • 7,867
  • 4
  • 33
  • 61
dbrank0
  • 9,026
  • 2
  • 37
  • 55
0
$  nasm -g -f elf64 -l 2.lst  2.asm
$  gcc -m64 -o 2.exe  2.o
Alex
  • 837
  • 8
  • 9