PASSERT() - asserting for panics
Matthew Dillon
dillon at apollo.backplane.com
Wed Sep 10 21:37:41 UTC 2008
: PASSERT("foo", panic("foo"));
:
:The patch is at http://www.FreeBSD.org/~jhb/patches/passert.patch and below:
:..
The general problem with creating a more complex style of assertion
is, well, that it is more complex. As a programmer who adds assertions
all over the place (HAMMER has 343 KKASSERTs, for example), the last
thing I want to do is to have to think about the assertion line itself
or have to read through the visual pollution. Most of the time I just
want to KKASSERT(condition) and be done with it.
I would consider using a DATASET (easily embedded in a statement as it
is a static declaration) to back the assertion macro and then simplify
it to just:
PASSERT(label, condition)
The kernel would collect the DATASETs together and provide a sysctl
API to allow the action taken to be managed at run-time based on the
label. You could even have a version that doesn't use a label at all
and is instead indexed by file and line. The output would be the
stringtized condition (similar to libc's assert(cond) or DFly's
KKASSERT(cond)). You could also have an optional macro to specify
a default action for the label, and a master global sysctl to override
everything.
The actual code generated would simply be the conditional and, say,
a call to _passert(&dataset), reducing code pollution as well as visual
pollution. I have considered doing something similar in DragonFly for
KKASSERT to reduce the code generated by the multi-argument panic()
it calls.
-Matt
More information about the freebsd-arch
mailing list