cvs commit: src/sys/alpha/alpha support.s src/sys/i386/i386
swtch.s src/sys/kern kern_shutdown.c src/sys/sys systm.h
John Baldwin
jhb at FreeBSD.org
Wed Feb 18 11:12:46 PST 2004
On Wednesday 18 February 2004 12:40 pm, Marcel Moolenaar wrote:
> On Wed, Feb 18, 2004 at 08:39:09AM -0500, John Baldwin wrote:
> > Use MPASS() (macros that came in with SMPng from BSD/OS). MPASS(foo)
> > will work much like assert() in userland including file/line number info.
> > I use it a lot for simple != NULL tests and the like.
>
> I like the behaviour of MPASS(), just not its name and the fact it's
> defined in lock.h. If we can call it ASSERT and move its definition
> to systm.h, then I'm hooked.
I have wanted to have a better name for it and it's associated friends
(MPASS2, MPASS3, MPASS4). KASSERT() really is a good name, and perhaps what
we should do is replace MPASS/KASSERT() with something like this:
KASSERT(condition) (just asserts a condition like MPASS does now)
KASSERTV(condition, printf args) (verbose assertion, has its own message)
These could perhaps output the current file and line, but then you have the
problem of things like the mutex code that pass around file and line info to
give more relevant file and line numbers (and hence the MPASS3() and MPASS4()
macros that BSD/OS provides). If you want to preserve that, perhaps one
could add:
KASSERTL(condition, file, line)
KASSERTLV(condition, file, line, printf args)
Thus, you have:
#define KASSERT(condition) KASSERTL(condition, __FILE__, __LINE__)
#define KASSERTV(condition, ...) KASSERTLV(condition, __FILE__, __LINE__, \
__VA_ARGS__)
#define KASSERTL(condition, file, line) KASSERTLV(condition, file, line, \
"%s", __STRING(condition))
#define KASSERTLV(condition, file, line, ...) do { \
if (!(condition)) { \
printf("Assertion \""); \
printf(__VA_ARGS__); \
printf("\" failed at %s:%d\n", file, line); \
} \
} while(0)
Even nicer might be to make fixup_filename() from subr_witness.c a global
#ifdef INVARIANTS_SUPPORT and have KASSERTLV() use that (it trims any (../)*
from the front of a filename to improve readability of messages by just
returning a char * pointer farther along in the string).
If ASSERT() is preferred to KASSERT() that would certain ease the transition
to the different macros.
--
John Baldwin <jhb at FreeBSD.org> <>< http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve" = http://www.FreeBSD.org
More information about the cvs-src
mailing list