All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: "Keir (Xen.org)" <keir@xen.org>,
	"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: Re: [PATCH 3 of 3] xen/debug: Introduce ASSERT_RUN()
Date: Mon, 15 Oct 2012 10:37:31 +0100	[thread overview]
Message-ID: <507BD95B.7070003@citrix.com> (raw)
In-Reply-To: <507BF24D02000078000A1497@nat28.tlf.novell.com>


On 15/10/12 10:23, Jan Beulich wrote:
>>>> On 08.10.12 at 20:16, Andrew Cooper <andrew.cooper3@citrix.com> wrote:
>> This is a variant of ASSERT() which takes a predicate, a function an
>> argument for the function.  It is designed for debugging in situations
>> where ASSERT_PRINTK() is perhaps not powerful enough.
>>
>> It will run the given function with the given argument before the BUG()
>> which kills Xen.
>>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
>>
>> diff -r 477ccdb9870e -r 0a1a3f35f56a xen/include/xen/lib.h
>> --- a/xen/include/xen/lib.h
>> +++ b/xen/include/xen/lib.h
>> @@ -48,6 +48,16 @@ do {                                    
>>  } while (0)
>>  #endif /* assert_printk_failed */
>>  
>> +#ifndef assert_run_failed
>> +#define assert_run_failed(p, func, arg)                         \
>> +do {                                                            \
>> +    printk("Assertion '%s' failed, line %d, file %s\n", p ,     \
>> +                   __LINE__, __FILE__);                         \
>> +    (func)((arg));                                              \
> Quite a few pointless parentheses here.

Ok

>
>> +    BUG();                                                      \
>> +} while (0)
>> +#endif /* assert_run_failed */
>> +
>>  #ifdef CONFIG_ASSERTS
>>  #define ASSERT(p) \
>>      do { if ( unlikely(!(p)) ) assert_failed(#p); } while (0)
>> @@ -55,9 +65,15 @@ do {                                    
>>  #define ASSERT_PRINTK(p, ...)                                   \
>>      do { if ( unlikely(!(p)) )                                  \
>>              assert_printk_failed(#p, __VA_ARGS__); } while (0)
>> +
>> +/* func expected to be void, taking a single void * argument */
>> +#define ASSERT_RUN(p, func, arg)                                \
> Since the user of the construct specifies both func and arg, I don't
> see the need to specify what type they are. Nor is it meaningful
> here whether the function returns void (it would at most need to
> be stated - I'd consider this mostly obvious - that an eventual
> return value doesn't get used).

Good point

>
>> +    do { if ( unlikely(!(p)) )                                  \
>> +            assert_run_failed(#p, func, arg); } while (0)
>>  #else
>>  #define ASSERT(p) do { if ( 0 && (p) ); } while (0)
>>  #define ASSERT_PRINTK(p, ...) do { if ( 0 && (p) ); } while (0)
>> +#define ASSERT_RUN(p, func, arg) do { if ( 0 && (p) ); } while (0)
> You shall evaluate func and arg (i.e. invoke func(arg)) in the
> (dead) if() body, to both avoid the need for #ifdef-s at use
> sites and check type compatibility even in non-debug (or non-
> assert, following your earlier patch) builds.
>
> Jan

I presume that you mean I should?  Why would that prevent the need for
#ifdefs? I can see the argument for type compatibility.

~Andrew

>
>>  #endif
>>  
>>  #define ABS(_x) ({                              \
>
>

-- 
Andrew Cooper - Dom0 Kernel Engineer, Citrix XenServer
T: +44 (0)1223 225 900, http://www.citrix.com

  reply	other threads:[~2012-10-15  9:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-08 18:16 [PATCH 0 of 3] Introduce more debugging flexibility with ASSERT() macros Andrew Cooper
2012-10-08 18:16 ` [PATCH 1 of 3] xen/debug: Allow ASSERT() to be enabled in a non-debug build Andrew Cooper
2012-10-08 18:16 ` [PATCH 2 of 3] xen/debug: Introduce ASSERT_PRINTK() Andrew Cooper
2012-10-15  9:17   ` Jan Beulich
2012-10-15  9:29     ` Andrew Cooper
2012-10-15  9:32       ` Jan Beulich
2012-10-08 18:16 ` [PATCH 3 of 3] xen/debug: Introduce ASSERT_RUN() Andrew Cooper
2012-10-15  9:23   ` Jan Beulich
2012-10-15  9:37     ` Andrew Cooper [this message]
2012-10-15  9:42       ` Jan Beulich
2012-10-15  9:52         ` Andrew Cooper
2012-10-15  9:59           ` Jan Beulich
2012-10-08 18:31 ` [PATCH 0 of 3] Introduce more debugging flexibility with ASSERT() macros Keir Fraser
2012-10-09  9:55   ` Andrew Cooper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=507BD95B.7070003@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=keir@xen.org \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.