Proposal: Unify printing the function name in panic messages()

Christoph Mallon christoph.mallon at gmx.de
Thu Feb 7 21:37:22 UTC 2013


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


More information about the freebsd-arch mailing list