tech-kern archive

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

Re: KASSERTMSG fix



On Sep 7, 2011, at 11:56 AM, David Laight wrote:

> On Wed, Sep 07, 2011 at 06:14:19PM +0200, Joerg Sonnenberger wrote:
>> 
>>> This can work around the limitations elegantly though (provided all call
>>> sites are fixed):
>>> 
>>> #define KASSERTMSG(e, fmt, ...) do {            \
>>> panic(                                        \
>>>   "kernel diag assert \"%s\" failed: file \"%s\", line %d; " fmt, \
>>>   #e, __FILE__, __LINE__, ## __VA_ARGS__);    \
>>> } while(0)
>> 
>> That assumes that fmt is a string literal. I don't think it is easier
>> than:
>> 
>> panic_verbose(__FILE__, __LINE__, #e, fmt, ##__VA_ARGS__);
> 
> The latter has the advantage that the string for __FILE__ will
> only occur once in the object file.
> 
> However it might be better do something like:
> (a static inline might be easier to define)
> 
> #define KASSERTMSG(e1, op, e2, fmt, ...) do { \
>       uintptr_t _e1 = (uintptr_t)e1, _e2 = (uintptr_t)e2; \
>       if (!(_e1 op _e2)) \
>               panic_verbose(__FILE__, __LINE__, #e1, _e1, #op, #e2, _e2, \
>                   fmt, ##__VA_ARGS__); \
>   } while (0)
> 
> So that the output can contain the numeric values that failed the compare.

No it isn't.  KASSERTMSG is so you can print the values in a sensible manner.



Home | Main Index | Thread Index | Old Index