Debugging my OS

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
User avatar
hegde1997
Member
Member
Posts: 40
Joined: Mon Jan 30, 2012 7:36 am
Location: Bangalore, India
Contact:

Debugging my OS

Post by hegde1997 »

Hello,
I am using qemu to emulate my OS on windows. Now i am stuck with idt or gdt or both. My code looks all right. But as a whole when i type my irq 0 handling routine doesn't get called and my irq1 handling routine never gets called even once in a few seconds. So i thought to use debugger. I don't know which and how. I thought about gdb but in many places they told remote debugging OS but i don't want any remote debugging. My OS is running on qemu and want to debug my OS.
Walking my way in making my OS
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Debugging my OS

Post by JamesM »

Firstly, have you actually enabled interrupts?
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: Debugging my OS

Post by bubach »

I don't know if qemu even has an internal debugger, but bochs do - and I wouldn't survive long without it.

For Bochs 2.5.1 here's an example config which uses a 1.44mb floppy (inserted in A: or mounted as A:)

Code: Select all

# configuration file generated by Bochs
#
#    for BOS 0.05, as mounted img or
#      physical drive A:\
#
#plugin_ctrl: unmapped=1, biosdev=1, speaker=1, extfpuirq=1, gameport=1, pci_ide=1, acpi=1, ioapic=1
config_interface: win32config
display_library: win32
megs: 32
#romimage: file="C:\Program\Bochs-2.5.1\BIOS-bochs-latest"
#vgaromimage: file="C:\Program\Bochs-2.5.1\VGABIOS-lgpl-latest"
boot: floppy
floppy_bootsig_check: disabled=0
magic_break: enabled=1
floppya: type=1_44, 1_44="a:", status=inserted
# no floppyb
After that you run "bochsdbg.exe" with that config, and you will have to press "C" for continue in the console to let it run pass BIOS code and get into your kernel. To stop at any point in your kernel, insert assembly "xchg bx,bx" which bochs will recognize as a break-point.
You can then press (in the debug console):
C - continue execution
S - step one instruction forward
R - show register contents
X - show memory content at hex location, like "x 0x7c00"

Hope that helps :)
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Debugging my OS

Post by iansjack »

When running in qemu it is a remote host (which just happens to be running on the same computer). Follow the instructions for gdb specifying the remote host as "localhost". You can also use the built-in qemu monitor to inspect memory, debug code, display registers and virtual memory mapping, etc.

If you find that difficult, try running under SimNow which has a much more accessible built-in debugger.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Debugging my OS

Post by bluemoon »

If you find that difficult, overcome it or give up osdev, really.
debugger is critical tool for osdev.


for qemu, you can start it with -S -s switch, which correspond to gdb-stub and suspend.
then you can use gdb to connect to gdb as above mentioned.

you can also provide gdb with symbol file and put break points in functions, just as debugging ordinary program.
Post Reply