Re: [patch] i386: handle_BUG(): don't print garbage if debug info unavailable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 10 Jul 2006 10:30:55 -0400
Chuck Ebbert <[email protected]> wrote:

> handle_BUG() tries to print file and line number even when
> they're not available (CONFIG_DEBUG_BUGVERBOSE is not set.)
> Change this to print a message stating info is unavailable
> instead of printing a misleading message.
> 
> Signed-off-by: Chuck Ebbert <[email protected]>
> 
> ---
> 
>  Compile tested only, with/without CONFIG_DEBUG_BUGVERBOSE.
> 
>  arch/i386/kernel/traps.c |   20 +++++++++++++-------
>  1 files changed, 13 insertions(+), 7 deletions(-)
> 
> --- 2.6.18-rc1-nb.orig/arch/i386/kernel/traps.c
> +++ 2.6.18-rc1-nb/arch/i386/kernel/traps.c
> @@ -324,13 +324,14 @@ void show_registers(struct pt_regs *regs
>  
>  static void handle_BUG(struct pt_regs *regs)
>  {
> +	unsigned long eip = regs->eip;
>  	unsigned short ud2;
> +
> +#ifdef CONFIG_DEBUG_BUGVERBOSE
>  	unsigned short line;
>  	char *file;
>  	char c;
> -	unsigned long eip;
> -
> -	eip = regs->eip;
> +#endif
>  
>  	if (eip < PAGE_OFFSET)
>  		goto no_bug;
> @@ -338,21 +339,26 @@ static void handle_BUG(struct pt_regs *r
>  		goto no_bug;
>  	if (ud2 != 0x0b0f)
>  		goto no_bug;
> +	printk(KERN_EMERG "------------[ cut here ]------------\n");
> +
> +#ifdef CONFIG_DEBUG_BUGVERBOSE
>  	if (__get_user(line, (unsigned short __user *)(eip + 2)))
> -		goto bug;
> +		goto no_info;
>  	if (__get_user(file, (char * __user *)(eip + 4)) ||
>  		(unsigned long)file < PAGE_OFFSET || __get_user(c, file))
>  		file = "<bad filename>";
>  
> -	printk(KERN_EMERG "------------[ cut here ]------------\n");
>  	printk(KERN_EMERG "kernel BUG at %s:%d!\n", file, line);
> +#else
> +	goto no_info;
> +#endif
>  
>  no_bug:
>  	return;
>  
>  	/* Here we know it was a BUG but file-n-line is unavailable */
> -bug:
> -	printk(KERN_EMERG "Kernel BUG\n");
> +no_info:
> +	printk(KERN_EMERG "Kernel BUG at [verbose debug info unavailable]\n");
>  }
>  

I think we can do it a lot more tidily.

static void handle_BUG(struct pt_regs *regs)
{
	unsigned long eip = regs->eip;
	unsigned short ud2;

	if (eip < PAGE_OFFSET)
		return;
	if (__get_user(ud2, (unsigned short __user *)eip))
		return;
	if (ud2 != 0x0b0f)
		return;

	printk(KERN_EMERG "------------[ cut here ]------------\n");

#ifdef CONFIG_DEBUG_BUGVERBOSE
	do {
		unsigned short line;
		char *file;
		char c;

		if (__get_user(line, (unsigned short __user *)(eip + 2)))
			break;
		if (__get_user(file, (char * __user *)(eip + 4)) ||
		    (unsigned long)file < PAGE_OFFSET || __get_user(c, file))
			file = "<bad filename>";

		printk(KERN_EMERG "kernel BUG at %s:%d!\n", file, line);
		return;
	} while (0);
#endif
	printk(KERN_EMERG "Kernel BUG at [verbose debug info unavailable]\n");
}


OK?
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux