Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Feb 2013 14:58:43 -0500
From:      Garance A Drosehn <gad@FreeBSD.org>
To:        Christoph Mallon <christoph.mallon@gmx.de>
Cc:        Kirk McKusick <mckusick@mckusick.com>, freebsd-arch@FreeBSD.org
Subject:   Re: Proposal: Unify printing the function name in panic messages()
Message-ID:  <51194D73.2010804@FreeBSD.org>
In-Reply-To: <51141E33.4080103@gmx.de>
References:  <51141E33.4080103@gmx.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2/7/13 4:35 PM, Christoph Mallon wrote:
>
> 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 always by using __func__.

> Do you have suggestions to improve this proposal?
>
> 	Chrsopth

While I'm replying to the first message in the thread, I've read
most of the messages up to this point.  I do very little development
in the kernel, but as it happens I've spent the last three weeks
untangling a somewhat large C-based project which has similar
messages, and due to the nature of the project it's nearly impossible
to run debuggers on it.  So I can't just pop into the debugger and
get some kind of stack trace.

That project uses __func__ on some printf()s, and __FILE__ on others.
I found it quite useful there.  When tracking down a few specific
bugs there were multiple places which could generate the error
message I was looking for, so I added __LINE__ to those printf()s.
This was helpful, particularly in one case where the entire message
was specified as a constant string in one place, but the same error
*could* be printed out by a different printf which built the message
via format specifiers.  So scanning for the message would pick up
the first case as an obvious hit, and never notice the second case.
And, of course, it turned out that the message in my log file was
coming from that second case.

So maybe it'd be good to have two panic options.  One with the
__LINE__ number, and one without.

-- 
Garance Alistair Drosehn            =   gad@gilead.netel.rpi.edu
Senior Systems Programmer           or  gad@freebsd.org
Rensselaer Polytechnic Institute    or  drosih@rpi.edu



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?51194D73.2010804>