0

I am trying to write a simple OS, I already wrote a bootloader but now I want to debug it, so I switched from using VirtualBox to QEMU because I saw it had better debugging. The problem is that after I added the -s parameter to QEMU command and successfully connected via GDB, it says that the symbol table isn't loaded and that I should use the "file" command. The only difference from what I did to what I saw people on the Internet do, is that they started GDB with gdb vmlinux, but I can't do that because I am not debugging a Linux kernel... so I figured that the issue is that I didn't start GDB with an executable, but using the "file" command on my OS image, and the compiled and linked .out file, tells me it's a "DOS/MBR boot sector", so I can't start GDB with either of them (I tried to do that anyways, but GDB failed).

Help would be appreciated.

EDIT: also, I did assemble the bootloader with the -g and --gstabs+ options.

Tal K
  • 93
  • 12

1 Answers1

0

gdb would like a file so that it can give you symbolic debugging information. For that you will need to give it a file in a format with debug info which corresponds to where your OS ends up in RAM. The "DOS/MBR boot sector" file is a disk image (the BIOS will load part of this into RAM for you, and it will then presumably finish loading code itself).

But gdb will also entirely happily let you do assembly-level debugging; you can just ignore the warning about not having a symbol table, and use the single step instruction, disassemble-from-pc and similar commands:

  • "disas $pc,+32" disassembles 32 bytes from the current PC
  • the display command prints after execution stops, so "disp /3i $pc" will print the next 3 instructions every time gdb gets control
  • "stepi" and "nexti" do single-instruction step/next ("step" and "next" are source-line stepping and require debug info)
Peter Maydell
  • 9,707
  • 1
  • 19
  • 25
  • Thanks for the answer, but GDB does not recognize the command "disassemble-from-pc", and I can't step because GDB "Cannot find bounds of current function"... any suggestions? – Tal K Aug 13 '18 at 11:41
  • 'disassemble' is the command; 'help disassemble' gives the help. You can disassemble from the PC by giving it the start and length, eg "disas $pc,+32" disassembles 32 bytes. Also useful is the display command, which prints after execution stops: "disp /3i $pc" will print the next 3 insns every time gdb gets control. You need to use "stepi" and "nexti", which do single-insn step/next, not "step" and "next", which are source-line stepping. – Peter Maydell Aug 13 '18 at 12:19
  • Cool; I've edited my answer to be more specific about comands that work without debug info. – Peter Maydell Aug 13 '18 at 14:01