Re: [PATCH] BUG preserve registers

Andrew Morton
2002-02-09T19:36:11Z

Linus Torvalds wrote:
>
> On Sat, 9 Feb 2002, Hugh Dickins wrote:
> >
> > It's frustrating that when Verbose BUG() reporting is configured,
> > info gets lost: fix for i386 below. This is your area, Andrew:
> > please confirm to Marcelo if you'd like him to apply this.
> >
> > Example: in hpa's recent prune_dcache crash, %eax showed the length of
> > the kernel BUG printk, when we'd have liked to see the invalid d_count:
> > off-by-one or obviously corrupted?
>
> Don't do it this way.
>
> Instead, put the string printout in the _trap_ handler, and make the
> format of BUG() be something like this:
>
> #ifdef CONFIG_DEBUG_BUGVERBOSE
> #define BUGSTR "\"" __FILE__ "\""
> #else
> #define BUGSTR ""
> #endif
>
> #define BUG() \
> asm("ud2\n\t.word __LINE__\n\t.asciiz " BUGSTR)
>

Is better, except the filename gets expanded multipe times into
the object file. How about:

#define BUG() \
asm( "ud2\n" \
"\t.word %0\n" \
"\t.long %1\n" \
: : "i" (__LINE__), "i" (__FILE__))

void erp(void)
{
if (c())
BUG();
if (d())
BUG();
}

-