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

Re: [Xen-devel] [PATCH 2 of 3] xen/debug: Introduce ASSERT_PRINTK()



>>> On 08.10.12 at 20:16, Andrew Cooper <andrew.cooper3@xxxxxxxxxx> wrote:
> This is a variant of ASSERT() which takes a predicate, and a variable
> number of arguments which get fed to prink() before the BUG().
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> 
> --
> This does use C99 varadic macros, but given that we use other C99
> features without #ifdef guards, I felt it not necessary to guard this as
> well.
> 
> diff -r 2927e18e9a7c -r 477ccdb9870e xen/include/xen/lib.h
> --- a/xen/include/xen/lib.h
> +++ b/xen/include/xen/lib.h
> @@ -38,11 +38,26 @@ do {                                    
>  } while (0)
>  #endif
>  
> +#ifndef assert_printk_failed
> +#define assert_printk_failed(p, ...)                            \
> +do {                                                            \
> +    printk("Assertion '%s' failed, line %d, file %s\n", p ,     \
> +                   __LINE__, __FILE__);                         \
> +    printk(__VA_ARGS__);                                        \

The first argument here necessarily is a format string, so it
should also be enforced that way. Which then opens the
question whether the two printk()-s shouldn't be folded (at the
price of requiring the format string to be a literal).

I wonder though whether we wouldn't be better off following
Linux'es WARN() et al infrastructure, rather than extending the
ASSERT() one.

Jan

> +    BUG();                                                      \
> +} while (0)
> +#endif /* assert_printk_failed */
> +
>  #ifdef CONFIG_ASSERTS
>  #define ASSERT(p) \
>      do { if ( unlikely(!(p)) ) assert_failed(#p); } while (0)
> +
> +#define ASSERT_PRINTK(p, ...)                                   \
> +    do { if ( unlikely(!(p)) )                                  \
> +            assert_printk_failed(#p, __VA_ARGS__); } while (0)
>  #else
>  #define ASSERT(p) do { if ( 0 && (p) ); } while (0)
> +#define ASSERT_PRINTK(p, ...) do { if ( 0 && (p) ); } while (0)
>  #endif
>  
>  #define ABS(_x) ({                              \




_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.