I want to add some debugging & error-handling facilities to my kernel, and I'm curious about how other people have tackled assert().this thread is referenced in the FAQ
For example, let's say some code in a low-level part of the kernel (like the kernel-mode C run-time library) detects a logic error in a debug build and wants to report it via assert(). Here are the choices as I see them (assuming the assertion failed):
- 1. assert() prints out the file and line number, then panics.
- 2. assert() tries to capture the current register contents and a kernel stack dump itself, then prints out the file and line number, then panics.
- 3. assert() prints out the file and line number, then triggers one of the kernel's exception handlers (by executing int 3 maybe), which in turn dumps the machine state that it has already collected, and then panics.
As an aside, how important is machine state for debugging anyway? My feeling is that it's less important for assert(), since you have file & line numbers available, but it's important for all other cases... If I could probably do without it, I may just go for option 1.