Page MenuHomeFreeBSD

Improve panic/KASSERT: make source code location info non-optional
Needs ReviewPublic

Authored by sobomax on Sep 9 2024, 7:33 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Mar 19, 12:02 AM
Unknown Object (File)
Jan 19 2026, 1:04 AM
Unknown Object (File)
Jan 17 2026, 5:08 PM
Unknown Object (File)
Nov 26 2025, 3:47 PM
Unknown Object (File)
Nov 23 2025, 6:46 AM
Unknown Object (File)
Nov 4 2025, 5:00 AM
Unknown Object (File)
Nov 4 2025, 4:28 AM
Unknown Object (File)
Oct 30 2025, 2:22 AM

Details

Reviewers
imp
olce
Summary

Our KASSERT / panic mechanism does not capture any location information by default, sometimes leaving user with a message that is ambiguous or hard to locate (i.e. KASSERT called from a macro etc). This patch aims at improving this situation by recording information about call site from which a particular KASSERT / panic originates and displaying this as part of the panic message.

Please note that there are some KASSERT-derived macros that try to capture that info still (which is after this would be somewhat redundant), I opted in to leave them as is just because I don't have a capacity/time to test such changes.

The overhead is 24 bytes (two pointers and int) per call site plus the size of the strings, but those are likely to be re-used by the compiler, so in practice it's about 48 bytes per call site on average. There are 15k call sites in GENERIC and about 24k in LINT.

Here the test panic screenshot:

VirtualBox_Sippy Install Test (node-9a4cb78c)_09_09_2024_09_21_52.png (768×1 px, 26 KB)

What is also interesting, that this would provide more precise location than the backtrace in many cases, since due to inlining the function calling the panic() might not be the actual function listed by the backtrace. As seen on the screenshot, the function with failed KASSERT() is pipe_create(), while the function calling panic() is sys_pipe2().

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

sobomax edited the summary of this revision. (Show Details)
sobomax edited the summary of this revision. (Show Details)
  • fix buildworld
  • added KASSERT_PANIC_NOCONTEXT option allowing to avoid compiling extra location strings
  • made format a bit closer to what MPASS4() would produce today
  • improve wording on panic(9) and update KASSERT(9) to match.