Re: [PATCH] a more efficient BUG() macro

Keith Owens
2001-02-18T01:47:47Z

On Sun, 18 Feb 2001 12:33:35 +1100,
Andrew Morton <andrewm@uow.edu.au> wrote:
>__BASE_FILE__ does this. It expands to the thing which you
>typed on the `gcc' command line.
>
>bix:/home/morton> ./a.out
>3 at a.c
>3 at a.c

But __LINE__ is wrong. Forget what I said about __C_FILE__ and
__C_LINE__, __C_LINE__ would not work for inline functions. Looks like
the best option is a combination of __BASE_FILE__ and function name.

a.h
#define BUG() \
printf("kernel BUG in func %s, file %s\n",__FUNCTION__,__BASE_FILE__);

static inline void hello(void)
{
BUG();
}

a.c
#include <stdio.h>
#include <a.h>

int main()
{
hello();
hello();
return 0;
}

# gcc -I`pwd` `pwd`/a.c -o a
# ./a
kernel BUG in func hello, file /home/kaos/a.c
kernel BUG in func hello, file /home/kaos/a.c