Better BUG() macro - take 2
PATCH 1/1 Better BUG() macro - take 2
Ok, it appears that some people want the __FILE__, __LINE__ (or equivalent) in BUG() and some don't. Fair enough. I used the existing config option CONFIG_DEBUG_ERRORS to allow people to choose. There was also interest in having BUG() in a more sensible place (e.g. <linux/kernel.h>) and the arch specific part separate (I picked <asm-xxx/system.h>).
This only deals with i386 - wanted to put this out for comment before editing for the others. Change for other arch is simple though - just remove BUG() from asm/page.h and put the *(int *)0=0; type part of what was BUG() into asm/system.h as machine_bug(). Oh, and add the config option to arch/*/config.in if it isn't already in use.
Feedback welcome (& thanks to those who already have done so)
Paul.
main.c renamed from main.c~ +3 -0
@@ -130,6 +130,9 @@char *execute_command;char root_device_name[64 ]; +#ifdef CONFIG_DEBUG_ERRORS +const char *kernel_bug ="kernel BUG at %s: line %d!\n" ; +#endif static char * argv_init[MAX_INIT_ARGS +2 ] = {"init" ,NULL , };static char * envp_init[MAX_INIT_ENVS +2 ] = {"HOME=/" ,"TERM=linux" ,NULL , };
asm-i386/page.h renamed from asm-i386/page.h~ +0 -9
@@ -82,15 +82,6 @@#ifndef __ASSEMBLY__ -/* -* Tell the user there is some problem. Beep too, so we can -* see^H^H^Hhear bugs in early bootup as well! -*/ -#define BUG () do { \ - printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \ - __asm__ __volatile__(".byte 0x0f,0x0b"); \ -} while (0) -#define PAGE_BUG (page) do { \ BUG(); \ } while (0)
i386/config.in renamed from i386/config.in~ +1 -0
@@ -366,4 +366,5 @@ #bool 'Debug kmalloc/kfree' CONFIG_DEBUG_MALLOC bool 'Magic SysRq key' CONFIG_MAGIC_SYSRQ +bool 'Verbose kernel error messages' CONFIG_DEBUG_ERRORS endmenu
ksyms.c renamed from ksyms.c~ +1 -0
@@ -463,6 +463,7 @@EXPORT_SYMBOL (securebits);EXPORT_SYMBOL (cap_bset);EXPORT_SYMBOL (daemonize); +EXPORT_SYMBOL (kernel_bug);/* Program loader interfaces */ EXPORT_SYMBOL (setup_arg_pages);
asm-i386/system.h renamed from asm-i386/system.h~ +2 -0
@@ -112,6 +112,8 @@ __asm__("movl %0,%%cr0" : :"r" (x));#define stts () write_cr0(8 | read_cr0()) +#define machine_bug () __asm__ __volatile__(".byte 0x0f,0x0b") +#endif /* __KERNEL__ */ static inline unsigned long get_limit (unsigned long segment)
linux/mount.h renamed from linux/mount.h~ +2 -0
@@ -12,6 +12,8 @@#define _LINUX_MOUNT_H#ifdef __KERNEL__ +#include <asm/system.h> +#define MNT_VISIBLE 1struct vfsmount
linux/kernel.h renamed from linux/kernel.h~ +17 -0
@@ -9,6 +9,7 @@#include <stdarg.h> #include <linux/linkage.h> +#include <linux/config.h> #include <linux/stddef.h> /* Optimization barrier */
@@ -83,6 +84,22 @@if (console_loglevel) console_loglevel =15 ; } + +/* +* Multiple copies of the printk text, plus long pathnames from +* __FILE__ used to waste around 100k of memory! Paul G. +*/ +#ifdef CONFIG_DEBUG_ERRORS +extern const char *kernel_bug; +#define SOURCE_LOCATION () printk(kernel_bug, __FILE__, __LINE__) +#else +#define SOURCE_LOCATION () +#endif + +#define BUG () do { \ + SOURCE_LOCATION(); \ + machine_bug(); \ +} while (0)#if DEBUG #define pr_debug(fmt,arg...) \
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
Quoted 5 lines · On 02.20 Paul Gortmaker wrote:
main.c renamed from main.c~ +3
-0+#ifdef CONFIG_DEBUG_ERRORS +const char *kernel_bug ="kernel BUG at %s: line %d!\n" ; +#endif
..
Quoted 3 lines
EXPORT_SYMBOL(daemonize);
+EXPORT_SYMBOL(kernel_bug);
Should also be #ifdef'd.
Signature · 4 lines
J.A. Magallon $> cd pub mailto:[email protected] $> more beer Linux werewolf 2.4.1-ac19 #1 SMP Mon Feb 19 21:52:31 CET 2001 i686
Quoted 11 lines · Paul Gortmaker
Ok, it appears that some people want the
__FILE__,__LINE__(or equivalent) inBUG()and some don't. Fair enough. I used the existing config optionCONFIG_DEBUG_ERRORSto allow people to choose. There was also interest in havingBUG()in a more sensible place (e.g. <linux/kernel.h>) and the arch specific part separate (I picked <asm-xxx/system.h>).This only deals with i386 - wanted to put this out for comment before editing for the others. Change for other arch is simple though - just remove
BUG()fromasm/page.hand put the *(int *)0=0; type part of what wasBUG()intoasm/system.hasmachine_bug(). Oh, and add the config option toarch/*/config.inif it isn't already in use.
I noticed the wasteful strings in the kernel image recently and am excited about this patch.
However, shouldn't this be fixed for all architectures?
Once that happens and the EXPORT_SYMBOL is #ifdef'd, I hope you submit this to Alan.