I wrote a x86 assembly program for MBR section. I compile it as follows:
nasm hellombr.asm -f bin -o hellombr.img
Then I run it in qemu:
You should let nasm create the debugging symbols in an ELF file and then dump this to a flat binary to be used in the MBR. You can then instruct GDB to read the necessary symbols from the ELF file.
The complete procedure would then become something like this:
$ nasm hellombr.asm -f elf -g -o hellombr.elf $ objcopy -O binary hellombr.elf hellombr.img $ qemu -s -S -fda hellombr.img -boot a $ gdb (gdb) symbol-file hellombr.elf (gdb) target remote localhost:1234
For an explanation of the flags I pass to qemu see this answer.