Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 07 Feb 2013 22:35:47 +0100
From:      Christoph Mallon <christoph.mallon@gmx.de>
To:        freebsd-arch@freebsd.org
Cc:        Kirk McKusick <mckusick@mckusick.com>
Subject:   Proposal: Unify printing the function name in panic messages()
Message-ID:  <51141E33.4080103@gmx.de>

next in thread | raw e-mail | index | archive | help
Hi,

currently the style for printing panic messages varies greatly.
Here are some examples of the most common styles:
	panic("just a message");
	panic("function_name: message");
	panic("wrong_function_name: message");
	panic("%s: message", __func__);
Especially the third -- a wrong function name being shown -- is annoying and quite common.
I propose a simple macro, which wraps panic() and ensures that the right name is shown alawys by using __func__.
I talked with Kirk about this and he suggested, that the name should be toggleable by a global option.
This way, some space can be saved on memory constrained targets, where the size of the kernel is relevant.
As an additional benefit, this would shrink the size of the current kernel, because currently many places hardocde the name of the function in the string.

I propose the following macro:
/*
 * Panic and automatically prepend the name of the function to the panic
 * message.  If NAMED_PANIC is not set, the name is omitted.
 */ 
#ifdef NAMED_PANIC
#	define PANIC(fmt, ...) panic("%s: " fmt, __func__, ##__VA_ARGS__)
#else
#	define PANIC(fmt) panic(__VA_ARGS__)
#endif

Using a small awk script, I can automatically convert about 1.500 of the approximately 3.500 panic calls.
These are all calls, which either use __func__ (or __FUNCTION__, a gcc extension with the same effect) or hardcode the /correct/ function name.
The rest either uses subtly different styles, shows no function name or uses a wrong name.
The other calls should then be converted successively.
For patches, please see http://tron.homeunix.org/zeug/FreeBSD/panic/.

Do you have suggestions to improve this proposal?

	Chrsopth



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?51141E33.4080103>