From owner-freebsd-arch@FreeBSD.ORG Thu Feb 7 21:37:22 2013 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 41872283 for ; Thu, 7 Feb 2013 21:37:22 +0000 (UTC) (envelope-from christoph.mallon@gmx.de) Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by mx1.freebsd.org (Postfix) with ESMTP id B32A068 for ; Thu, 7 Feb 2013 21:37:21 +0000 (UTC) Received: from mailout-de.gmx.net ([10.1.76.28]) by mrigmx.server.lan (mrigmx002) with ESMTP (Nemesis) id 0MSomp-1UTEvG0sy5-00Ro6f for ; Thu, 07 Feb 2013 22:37:15 +0100 Received: (qmail invoked by alias); 07 Feb 2013 21:37:11 -0000 Received: from p5B132387.dip.t-dialin.net (EHLO rotluchs.lokal) [91.19.35.135] by mail.gmx.net (mp028) with SMTP; 07 Feb 2013 22:37:11 +0100 X-Authenticated: #1673122 X-Provags-ID: V01U2FsdGVkX1+TnIskUuGTKJNO1g+tC3H5In4PzfgckMMzg8civT ToRsW4pnlne79t Message-ID: <51141E33.4080103@gmx.de> Date: Thu, 07 Feb 2013 22:35:47 +0100 From: Christoph Mallon User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:17.0) Gecko/20130129 Thunderbird/17.0.2 MIME-Version: 1.0 To: freebsd-arch@freebsd.org Subject: Proposal: Unify printing the function name in panic messages() Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 Cc: Kirk McKusick X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Feb 2013 21:37:22 -0000 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