Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate gdb symbol file with nasm?

Tags:

gdb

nasm

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.

like image 984
brianmearns Avatar asked Jun 28 '13 16:06

brianmearns


People also ask

How do I create a NASM assembly language file?

Use your favorite editor to create a nasm assembly language file. e.g. hello.asm shown below. Type the command: nasm -f elf -l hello.lst hello.asm If your program had no assembly time errors, nothing displays. If you had assembly time errors, fix them and repeat the command.

How can I get NASM to produce a 64-bit output?

If you would like to see all the different output formats that Nasm can produce, run the following command at your terminal prompt: Meanwhile, there are two fixes I've found that work for people using 64-bit machines. First, to produce a native 64-bit object module and executable, simply change elf to elf64 in Jeff's command, like so:

How to install NASM in the development environment using MinGW?

Now you need to insert NASM in the development environment MinGW. Unpack the NASM archive. You should get a folder containing, among other things, a file named nasm.exe. Copy this file into the directory C: \ MinGW \ bin.

What is NASM for Linux?

Netwide Assembler (NASM) is an assembler and dissembler for the Intel x86 architecture and is commonly used to create 16-bit, 32-bit (IA-32), and 64-bit (x86-64) programs. How to compile an assembly program with NASM for Linux? You can use any text editor, such as Gedit, KWrite, or XEmacs, to do so.


1 Answers

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.

like image 190
dbrank0 Avatar answered Oct 30 '22 06:10

dbrank0