GDB Qemu debugging symbols

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
therll
Posts: 7
Joined: Sat Sep 28, 2013 10:29 pm

GDB Qemu debugging symbols

Post by therll »

My kernel compiles correctly in debug mode using

Code: Select all

i686-elf-gcc -g -T link.ld -o myos.bin -ffreestanding -O2 -nostdlib start.o main.o scrn.o gdt.o idt.o isrs.o irq.o timer.o kb.o
and boots in Qemu. However when I debug using GDB through

Code: Select all

target remote localhost:1234
, loading my bin file as the GDB symbol file returns an error:

Code: Select all

can't read symbols: File format not recognized.
I'm following http://wiki.osdev.org/Kernel_Debugging# ... _with_Qemu and I think the problem might be that my kernel isn't an elf file but I'm not sure how to make it an elf file or extract the symbols from this binary file. What am I doing wrong?
turboscrew
Posts: 10
Joined: Fri Jun 13, 2014 12:55 pm

Re: GDB Qemu debugging symbols

Post by turboscrew »

If you first produce an ELF then make bin from it, load the bin into the qemu, but the ELF in gdb before the "target remote"-command.
therll
Posts: 7
Joined: Sat Sep 28, 2013 10:29 pm

Re: GDB Qemu debugging symbols

Post by therll »

But how do I produce one big ELF from all the little compiled .o ELF files?
therll
Posts: 7
Joined: Sat Sep 28, 2013 10:29 pm

Re: GDB Qemu debugging symbols

Post by therll »

Ok I figured it out :D

Code: Select all

objdump -i
lists the available formats and the .ld linker script has an OUTPUT_FORMAT property which can be changed to elf32-i386 and then the symbols load just fine!
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: GDB Qemu debugging symbols

Post by max »

therll wrote:

Code: Select all

can't read symbols: File format not recognized.
I'm following http://wiki.osdev.org/Kernel_Debugging# ... _with_Qemu and I think the problem might be that my kernel isn't an elf file but I'm not sure how to make it an elf file or extract the symbols from this binary file. What am I doing wrong?
You must make sure that GDB understands the object format for your target platform. You can simply compile GDB from sources to get one specific for your target platform by doing the same as when you compiled your cross compiler (by adding the "--target" flag to configure).


EDIT:
therll wrote:lists the available formats and the .ld linker script has an OUTPUT_FORMAT property which can be changed to elf32-i386 and then the symbols load just fine!
I don't think that you really want that. You made a cross-compiler that compiles binaries for i686, and now you're linking them as i386? That's why you should make a cross-gdb (as described above), because it is able to read your target platforms object format.
turboscrew
Posts: 10
Joined: Fri Jun 13, 2014 12:55 pm

Re: GDB Qemu debugging symbols

Post by turboscrew »

If there is i686-elf-gcc, there is probably i686-elf-objdump too?
Post Reply