0

I am wondering which debugging tool I can use for an assembly program and how to use it.

I have written a simple bootloader in assembly. However, it is not quite working properly as I wished, even though I think the logic is correct. So, I am trying to use a debugger so that I can step through the bootloader, checking the register status and etc.

I tried GDB on Ubuntu, compiling my .asm to .elf and .o (Do I need to do it? If yes, what is the next step?) Also, I read that there is an internal debugger in Bochs simulator, but I can't quite find any document how to use it. I also have Visual Studio 2010, windbg, but I don't know how to use it for .asm file debugging.

If you have done this before, it would be an easy answer. Any help would be really appreciated.

Sincerely

ElectroJunkie
  • 301
  • 5
  • 16

1 Answers1

1

If you want to debug bootloader code, you obviously need to run it in the same environment that the code itself is going to run in. As I'm sure you already know, bootloader code is executed in real mode once the BIOS finishes doing the POST. The bootloader is then loaded into memory at 7c00h and a jump to that address is executed.

Obviously, this kind of environment cannot be reliably emulated once you've got your computer running and a "real" operating system already loaded, since by that time your CPU is in protected mode (or long mode, if it's AMD64). Your only option at this point is to use QEMU or Bochs in order to emulate a real PC inside your operating system. I've used Bochs to debug some bootloader code I've written in the past and it worked quite well. Check the manual pages for more detailed instructions.

Daniel Kamil Kozar
  • 18,476
  • 5
  • 50
  • 64
  • Thanks Daniel. It is weird that I couldn't get the Bochs internal debugger to work properly. I tried to config on command line, but it didn't quite work for me. (Even for command line, it just launches GUI emulator...) I guess I'll give another shot at reading the manual... – ElectroJunkie Feb 06 '12 at 21:28
  • I used to attach it to gdb and that technique worked okay. I'm sure it's the manual somewhere. – Daniel Kamil Kozar Feb 06 '12 at 21:29