The fun in bug tracking!
Posted: Sun Apr 27, 2008 9:40 pm
Hello everyone, I'm Josh, I'm 16, and I just started in OS development a few months ago. My OS is going great, working pretty smoothly (a few bugs pop up here and there). Now, let's be honest, no matter how good your OS is, you probably have some strange bugs that were caused by an error in your logic show up that may take a long time to track down. I've
become good at that. It's usually caused by using a wrong variable or bit or something, and it takes forever to track down, right? And it doesn't show up until later... well I thought it would be interesting to log these things so I can look back at them, and I'll post the list here. I'm sure this happens to you alot, right? Please share your experiences. How much of your development time is spent debugging? How often do you find the problem? I find the problem to 100% of them, and it usually takes me a couple of hours to a couple of days to find these things. Well, here is my
list, I hope this becomes an interesting conversation?
The list is ordered from when I started making my OS.
./16bit = my old (newbie) version (dos-like)
./32bit = current progressive version
16bit/osldr/int21.inc: function Int21
The function tested a wrong register for an error,
exiting randomly!
something else interesting in osldr? (Can't remember)
32bit/kernel/fat.c: function read_sector
Wrong pointer arithmetic! *((uint*)start+offset)
instead of *(uint*)(start+offset)
32bit/kernel/kenrel.c: interrupts
Interrupts were enabled after setting up the IDT. It worked fine like that
for a while, but later, only in bochs, a triple fault started occuring
on the instruction after sti. This wasn't obvious, because it was when I
started testing file streams. I think this problem was also occuring earlier,
and I just thought it had to do with a high ch0 PIT frequency? I may have moved
the PIC initialization code right after the IDT init code and just didn't
test it in bochs for a while. It works fine now, so this is my guess for
what the problem was.
4-23-08
32bit/kernel/fat.c: functions pop_cluster, push_cluster: Memory allocation bug
Wouldn't update clusterstacksize, so would always allocate insufficient memory
(clusterstacksize*2*sizeof(unsigned) is always 32, because clusterstacksize itself was never updated)
Took a few days to track down!
32bit/kernel/kernel.c: function page_map
Just remember to invalidate new mapped page tables, along with the new page.
32bit/kernel/kernel.c: function kfindrange
I changed the initialization routines to non-static to make it easy to trace the bug in
bochs, because the compiler doesn't optimize nonstatic functions a certain way. The
bug was then easy to find: kfindrange looked through the page tables without checking
if they existed first.
32bit/osldr/init.inc: function load_kernel
when later modifying this code to calculate the number of pages, I forgot all
about my ES register being based at 0x0, so I forgot to use ES! Segmentation...
32bit/kernel/kernel.c: function page_unmap
Tried to free a physical page using its logical address (when freeing page tables)...
become good at that. It's usually caused by using a wrong variable or bit or something, and it takes forever to track down, right? And it doesn't show up until later... well I thought it would be interesting to log these things so I can look back at them, and I'll post the list here. I'm sure this happens to you alot, right? Please share your experiences. How much of your development time is spent debugging? How often do you find the problem? I find the problem to 100% of them, and it usually takes me a couple of hours to a couple of days to find these things. Well, here is my
list, I hope this becomes an interesting conversation?
The list is ordered from when I started making my OS.
./16bit = my old (newbie) version (dos-like)
./32bit = current progressive version
16bit/osldr/int21.inc: function Int21
The function tested a wrong register for an error,
exiting randomly!
something else interesting in osldr? (Can't remember)
32bit/kernel/fat.c: function read_sector
Wrong pointer arithmetic! *((uint*)start+offset)
instead of *(uint*)(start+offset)
32bit/kernel/kenrel.c: interrupts
Interrupts were enabled after setting up the IDT. It worked fine like that
for a while, but later, only in bochs, a triple fault started occuring
on the instruction after sti. This wasn't obvious, because it was when I
started testing file streams. I think this problem was also occuring earlier,
and I just thought it had to do with a high ch0 PIT frequency? I may have moved
the PIC initialization code right after the IDT init code and just didn't
test it in bochs for a while. It works fine now, so this is my guess for
what the problem was.
4-23-08
32bit/kernel/fat.c: functions pop_cluster, push_cluster: Memory allocation bug
Wouldn't update clusterstacksize, so would always allocate insufficient memory
(clusterstacksize*2*sizeof(unsigned) is always 32, because clusterstacksize itself was never updated)
Took a few days to track down!
32bit/kernel/kernel.c: function page_map
Just remember to invalidate new mapped page tables, along with the new page.
32bit/kernel/kernel.c: function kfindrange
I changed the initialization routines to non-static to make it easy to trace the bug in
bochs, because the compiler doesn't optimize nonstatic functions a certain way. The
bug was then easy to find: kfindrange looked through the page tables without checking
if they existed first.
32bit/osldr/init.inc: function load_kernel
when later modifying this code to calculate the number of pages, I forgot all
about my ES register being based at 0x0, so I forgot to use ES! Segmentation...
32bit/kernel/kernel.c: function page_unmap
Tried to free a physical page using its logical address (when freeing page tables)...