OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 16, 2024 3:13 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: What should I put in a panic screen(to be usefull for debug)
PostPosted: Thu Nov 09, 2017 9:48 am 
Offline

Joined: Tue Nov 07, 2017 9:25 am
Posts: 1
I made a panic screen with a simple output to warn about a kernel error, but I think I should add to it some things to make it more useful when debugging, but the problem is... What should I add?
I mean, what do you think is useful to know when a kernel crashes? How can I implement that things? Thanks in advance!


Top
 Profile  
 
 Post subject: Re: What should I put in a panic screen(to be usefull for de
PostPosted: Thu Nov 09, 2017 10:06 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
Contents of general purpose, segment, stack pointer, flag and IP registers at a minimum. (Note that you want the values before any exception handlers were called.)

You could also put in details of GDT and IDT. Have a look at the information screen on the qemu monitor for some ideas.


Top
 Profile  
 
 Post subject: Re: What should I put in a panic screen(to be usefull for de
PostPosted: Thu Nov 09, 2017 10:21 am 
Offline
Member
Member

Joined: Sun Sep 06, 2015 5:40 am
Posts: 47
If you want to put a little more effort in, you could provide a stacktrace (working back through the stack frame return addresses) or even provide a disassembly of the instruction that caused the panic (if for example caused by a page fault)

_________________
OS on Github | My Rust ACPI library


Top
 Profile  
 
 Post subject: Re: What should I put in a panic screen(to be usefull for de
PostPosted: Thu Nov 09, 2017 11:35 am 
Offline
Member
Member

Joined: Tue May 13, 2014 3:02 am
Posts: 280
Location: Private, UK
You're asking what information would be useful for debugging your OS/applications? It's your OS, you're the one debugging, you tell us...

Personally, I don't put much information on the "panic screen", just a basic description of the error and the process/thread IDs involved, since that's "user facing". The rest of the information (register values, an attempt at a stack trace, etc.) is dumped out to the serial port (this will be configurable eventually).

If you find yourself needing information that's not available, you can always add it. Code isn't immutable.

_________________
Image


Top
 Profile  
 
 Post subject: Re: What should I put in a panic screen(to be usefull for de
PostPosted: Thu Nov 09, 2017 1:06 pm 
Offline
Member
Member

Joined: Thu May 17, 2007 1:27 pm
Posts: 999
In my experience looking at any register over than RIP and CR2 (and maybe RSP) is a waste of time once you get past the "there might be an error in my paging/GDT code" stage.

Printing the program that caused the panic is essential. Maybe also print the context: Did the panic occur during an IRQ handler? In a page fault handler? In a syscall?

Stack traces are certainly nice if you have them but also quite complicated to implement: You have to write a DWARF unwinder and ensure that all assembly functions are correctly annotated with CFI pseudo instructions; this will be a PITA.

_________________
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].


Top
 Profile  
 
 Post subject: Re: What should I put in a panic screen(to be usefull for de
PostPosted: Thu Nov 09, 2017 1:12 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
I have found it very valuable to see that a register I expected to contain a valid memory address is zero (just a simple example).


Top
 Profile  
 
 Post subject: Re: What should I put in a panic screen(to be usefull for de
PostPosted: Fri Nov 10, 2017 6:51 pm 
Offline
Member
Member

Joined: Sat Feb 27, 2010 8:55 pm
Posts: 147
Korona wrote:
In my experience looking at any register over than RIP and CR2 (and maybe RSP) is a waste of time once you get past the "there might be an error in my paging/GDT code" stage.

Printing the program that caused the panic is essential. Maybe also print the context: Did the panic occur during an IRQ handler? In a page fault handler? In a syscall?

Stack traces are certainly nice if you have them but also quite complicated to implement: You have to write a DWARF unwinder and ensure that all assembly functions are correctly annotated with CFI pseudo instructions; this will be a PITA.


For "normal" functions, won't RBP point to the old RBP, followed by (going up) the old RIP, followed by the passed variables? Couldn't you get each function's stack frame by following the trail of RBP's?


Top
 Profile  
 
 Post subject: Re: What should I put in a panic screen(to be usefull for de
PostPosted: Sat Nov 11, 2017 5:59 am 
Offline
Member
Member

Joined: Thu May 17, 2007 1:27 pm
Posts: 999
That only true if you compile with -fno-omit-frame-pointer. In addition to that you still need some annotations to mark IRQ/exception entries, otherwise your backtrace will not work across those frames.

iansjack wrote:
I have found it very valuable to see that a register I expected to contain a valid memory address is zero (just a simple example).

Yes, if you're coding in assembly, that will be helpful. If you're coding in a higher language you first have to figure (from the disassembly) out which register stores which value; this process is often tiresome and not effective. Instead I usually resort to printf() debugging to check if any variable contains bogus values. This is usually even faster than invoking GDB and setting the correct breakpoints.

_________________
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 557 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group