Debugging OS on real hardware
Debugging OS on real hardware
My OS crashes on real hardware for now, but it worked fine a week ago. So, the question is: How to debug my operating system on real hardware and fix my error?
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Re: Debugging OS on real hardware
Hard but powerful way:
1. Debug it using Bochs.
2. Implement GDB stub and debug via serial port.
Easy way: don't forget about printf-debugging. Insert printing calls around suspicious parts of code, then look where your execution has stopped.
1. Debug it using Bochs.
2. Implement GDB stub and debug via serial port.
Easy way: don't forget about printf-debugging. Insert printing calls around suspicious parts of code, then look where your execution has stopped.
Re: Debugging OS on real hardware
You can print debug information on screen or use RS232 or another port (it is harder). You also can use infinite loop (in the case of triggering a hardware reset).catnikita255 wrote:How to debug my operating system on real hardware and fix my error?
- BrightLight
- Member
- Posts: 901
- Joined: Sat Dec 27, 2014 9:11 am
- Location: Maadi, Cairo, Egypt
- Contact:
Re: Debugging OS on real hardware
You know your OS is advanced when you stop using the Intel programming guide as a reference.
Re: Debugging OS on real hardware
My OS works fine on Bochs. I can't debug by printfs, because it crashes before it can write comething on the screen. And about serial port - I don't have serial port on my notebook. I can do it with my development machine, but I don't have any serial cables.Nable wrote:Hard but powerful way:
1. Debug it using Bochs.
2. Implement GDB stub and debug via serial port.
Easy way: don't forget about printf-debugging. Insert printing calls around suspicious parts of code, then look where your execution has stopped.
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Re: Debugging OS on real hardware
I am stupid. Delete this thread, please, it was one line added by me I don't know for what - accessing memory on -1.
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
-
- Member
- Posts: 1146
- Joined: Sat Mar 01, 2014 2:59 pm
Re: Debugging OS on real hardware
If you use a version-control system such as git, you can view the commit history and see what's been changed in the past week. Yet another reason why I've started using git as part of my regular workflow.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
- Schol-R-LEA
- Member
- Posts: 1925
- Joined: Fri Oct 27, 2006 9:42 am
- Location: Athens, GA, USA
Re: Debugging OS on real hardware
I cannot agree more. While it doesn't have to be git and Github (a lot of people dislike git, it seems, though I've never had much trouble with it), some sort of off-site version control is a must even as a hobbyist, especially in a major project like OS dev. There are enough different [CD]VCSes, and free, low-cost, or ad-supported [CD]VCS hosts, that there are very good few reasons why anyone wouldn't use one.onlyonemac wrote:If you use a version-control system such as git, you can view the commit history and see what's been changed in the past week. Yet another reason why I've started using git as part of my regular workflow.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
-
- Member
- Posts: 1146
- Joined: Sat Mar 01, 2014 2:59 pm
Re: Debugging OS on real hardware
Note also the value of a VCS even if you don't link it to an online host. Personally I use github for some things, but a lot of the time I use git "offline" (i.e. just a local repository, with no source repository to push to) to manage my own code on my hard drive.Schol-R-LEA wrote:I cannot agree more. While it doesn't have to be git and Github (a lot of people dislike git, it seems, though I've never had much trouble with it), some sort of off-site version control is a must even as a hobbyist, especially in a major project like OS dev. There are enough different [CD]VCSes, and free, low-cost, or ad-supported [CD]VCS hosts, that there are very good few reasons why anyone wouldn't use one.onlyonemac wrote:If you use a version-control system such as git, you can view the commit history and see what's been changed in the past week. Yet another reason why I've started using git as part of my regular workflow.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Re: Debugging OS on real hardware
Testing on real hardware should be done ASAP because emulators are not real hardware. Debugging is best done by catching serious bugs like protection fault, stack fault and double faults with handlers, and then printing register state on-screen. These handlers can be tested on an emulator. Printf-debugging is worthless.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Debugging OS on real hardware
rdos wrote:Debugging is best done by (...) printing register state on-screen.
Yup, rdos is back in full glory!rdos wrote:Printf-debugging is worthless.
-
- Member
- Posts: 63
- Joined: Fri May 01, 2015 2:23 am
- Libera.chat IRC: Hellbender
Re: Debugging OS on real hardware
And don't forget about bisect. Just let git tell which commit exactly caused the bug!onlyonemac wrote:If you use a version-control system such as git, you can view the commit history and see what's been changed in the past week. Yet another reason why I've started using git as part of my regular workflow.
Hellbender OS at github.
Re: Debugging OS on real hardware
Heh, especially when said printfs alter state, either preventing bugs or triggering them. I started out printing stuff to the screen, but later switched to Bochs's debug IO port. Even that can alter behavior significantly (blah).rdos wrote:Testing on real hardware should be done ASAP because emulators are not real hardware. Debugging is best done by catching serious bugs like protection fault, stack fault and double faults with handlers, and then printing register state on-screen. These handlers can be tested on an emulator. Printf-debugging is worthless.
Btw, in addition to printing out registers in exception handlers, it can also be helpful to print out the first dozen or so bytes from the top of the stack.
Re: Debugging OS on real hardware
I must be misunderstanding printf debugging. What's wrong with it ?
If a trainstation is where trains stop, what is a workstation ?
Re: Debugging OS on real hardware
Everything. They alter state and introduce new bugs + cannot tell you what a debugger typically can tell you. Once the basic exception handlers are in place, the next step is to integrate a remote debugger or local debugger thread so you can single step the kernel, preferably in source-code form. Before that is done, planting "int 3" in code, which triggers the exception handlers, is a good way to get the current register state.gerryg400 wrote:I must be misunderstanding printf debugging. What's wrong with it ?
Of course, if you are in an emulator rather than on real hardware, then the emulator might have good options for doing the above an easier way, but you still need it when you come to real hardware that isn't booting.