Author Topic: gdb debug symbols in a bootloader  (Read 17364 times)

nobody

  • Guest
gdb debug symbols in a bootloader
« on: October 16, 2009, 02:50:23 PM »
I'm assembling a bootloader with

nasm -f bin emakeimg.asm -o enth.fbin      & dd'ing to an image

&

nasm -w+gnu-elf-extensions -o emakeimg.o emakeimg.asm

which I can run straight off in qemu

I can halt the execution of these with gdb (ni qemu) at the outset but can't stop it once its started cos there's no debug symbols

I note that only elf32 & 64 support stabs ie not elf.
The code eventually becomes pmode.
I've been trying to produce elf (but it doesnt recognise ORG)
and use ld to insert symbols in a binary but can't work out the syntax

To summarise I want to step through the bootloader under qemu with gdb.

Can someone please help me do this.
BTW I've tried -g and -F stabs.
Thx

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: gdb debug symbols in a bootloader
« Reply #1 on: October 16, 2009, 11:05:27 PM »
I know nothing of qemu, and consider gdb "unfriendly" at best. But looking at the makefile for the Linux bootsector, I see "-Ttext 0x0" and "--oformat binary" in the command line for ld. Also an "-s", but that will strip debug info, which you want to keep. They assemble with (G)as, of course, but we ought to be able to do the same with Nasm. "-f elf" (== "-f elf32") will insert "stabs" debug info, and "-Fdwarf" will insert dwarf debug info. You no longer need both "-F" and "-g" to get debug info.

I don't know if that'll work. The notion of debug info in a binary format file seems "improbable" to me. I don't see what gdb is going to have to work with. I don't know how well gdb copes with 16-bit code, in any case.

But using "-Ttext 0x0" (or 0x7C00?) seems to be the workaround for "elf doesn't know org" problem - maybe that'll be some help...

Best,
Frank

bobl

  • Guest
Re: gdb debug symbols in a bootloader
« Reply #2 on: October 17, 2009, 07:19:36 AM »
Frank
That helps a lot. Thanks very much.

Here's the missing ld line you refer to
ld -Ttext 0x0 -s --oformat binary infile.asm -o outfile.bin

Re "-f elf" (== "-f elf32") are you saying that -f elf produces 32 bit code and not 16 or that elf is 16 bit code but will insert stabs just like elf32?

gdb's the only one I know works with qemu.

I'm only trying to step a tiny OS which boots from real to pmode in a virtual pc. Gdb doesn't seem to have any hooks to get hold of.

What's your preferred debugger & is there a better way to do this?
Rgds Dean
I'd be interested in knowing your preferred debugger & what other ways there are to step this explore memory unprotected OSs on Linux/Windows

Thx once again
Dean

bobl

  • Guest
Re: gdb debug symbols in a bootloader
« Reply #3 on: October 17, 2009, 07:23:21 AM »
Please ignore the duplicated stuff at the bottom