Date: Wed, 10 Sep 2008 14:26:59 -0700 (PDT) From: Matthew Dillon <dillon@apollo.backplane.com> To: John Baldwin <jhb@freebsd.org> Cc: arch@freebsd.org Subject: Re: PASSERT() - asserting for panics Message-ID: <200809102126.m8ALQxdK032024@apollo.backplane.com> References: <200809101531.54646.jhb@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
: 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200809102126.m8ALQxdK032024>