OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 3:05 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Best way to handle crashes in an OS
PostPosted: Tue Feb 13, 2018 8:36 am 
Offline

Joined: Sun Jul 07, 2013 7:29 pm
Posts: 16
Hi folks

I have a hobby OS that boots and does some minimalistic stuff. During development I regularly have crashes or hit assert statements in my code. Currently my exception handler prints registers state and hangs.

I am looking a way to improve debuggability of my crashed system. In particular I would love to have
1) an easy way to see desymbolized stack trace at the OS console
2) an easy way to inspect memory of live/crashed system

As of 1) I believe the standard solution is to use libbacktrace. Does anybody have an experience integrating this library into kernel code? How well this library works with binaries compiled with Link-Time-Optimization?

As of 2), does anybody integrated "memory inspection" feature into their OS? I am looking for a [ur=https://github.com/crash-utility/crash]crash[/url]-like tool that would allow to inspect data structures of a running or crashed system. Does anybody have any pointers how it can be achieved? In particular does QEMU/you-virtual-machine allow to store memory dump to filesystem on exception? Is there any way to store memory dump for a system that runs on bare hardware?

Thank you in advance. Any pointers/additional information is welcome.


Top
 Profile  
 
 Post subject: Re: Best way to handle crashes in an OS
PostPosted: Tue Feb 13, 2018 8:44 am 
Offline
Member
Member

Joined: Tue Feb 26, 2008 10:47 am
Posts: 89
Location: Sweden
If your kernel executable is in elf format, you can make a simple stacktrace by yourself.

I've done it here: https://github.com/thomasloven/os5/blob/master/kernel/drivers/debug.c#L212
I think it reads the symbols passed by a multiboot bootloader or someting... it was a long time since I did it this way...
This isn't my idea. But I can't remember where I picked it up...

Both qemu and bochs have built in functions for inspecting memory, and if you want a real debugger, you can connect gdb to qemu. Look up the -gdb flag.

I like to put a
Code:
asm("divide_by_zero_error:");
for(;;);

at the end of my fault handlers, and a
Code:
b divide_by_zero_error
in my .gdbinit. That way it will break automatically when anything happens.

_________________
Blawg


Top
 Profile  
 
 Post subject: Re: Best way to handle crashes in an OS
PostPosted: Tue Feb 13, 2018 9:07 am 
Offline

Joined: Sun Jul 07, 2013 7:29 pm
Posts: 16
Thank you thomasloven.

Quote:

Thank you, I'll look at it. And yes multiboot can load symbols section or I can put it into loadable ELF segment in my linker script.

If it is possible to desymbolize stack using such simple code, what is the point of using libbacktrace library then? Does this library have any advantages? Actually one feature that I am interested in is correct desymbolizing for LTO-compiled binaries, is there a sane way to achieve it. Sorry for asking it here, but libbacktrace documentation is very sparse.

Quote:
you can connect gdb to qemu

Thanks. That's a good point. For some reason I thought QEMU might have a flag like '--save-memory-dump-on-crash'. But a breakpoint in the exception handler I think will work as well.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 68 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