OSDev.org
https://forum.osdev.org/

Best way to handle crashes in an OS
https://forum.osdev.org/viewtopic.php?f=1&t=32752
Page 1 of 1

Author:  anatolik [ Tue Feb 13, 2018 8:36 am ]
Post subject:  Best way to handle crashes in an OS

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.

Author:  thomasloven [ Tue Feb 13, 2018 8:44 am ]
Post subject:  Re: Best way to handle crashes in an OS

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.

Author:  anatolik [ Tue Feb 13, 2018 9:07 am ]
Post subject:  Re: Best way to handle crashes in an OS

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.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/