|
From: Andy H. <And...@au...> - 2009-05-19 11:45:46
|
I have some code that uses the pre-processor to generate code to log messages: #define logDebug if ( Log::minLevel <= Log::LVL_DEBUG ) Log::printLog Helgrind reports data races ultimately due to the global Log::minLevel. While technically this is a potential race condition, Log::minLevel is essentially a constant after startup. I tried to add suppressions for the mangled Log::printLog method, however because of the #define, helgrind reports the race on lines where LogDebug is used, not the Log::printLog method. Is there any way to add a suppression based on the global variable? Thanks, Andy |
|
From: Colin M. <col...@pi...> - 2009-05-19 14:20:35
|
Andy Howell wrote:
> I have some code that uses the pre-processor to generate code to log messages:
>
> #define logDebug if ( Log::minLevel <= Log::LVL_DEBUG ) Log::printLog
>
> Helgrind reports data races ultimately due to the global Log::minLevel. While technically
> this is a potential race condition, Log::minLevel is essentially a constant after startup.
>
> I tried to add suppressions for the mangled Log::printLog method, however because of the
> #define, helgrind reports the race on lines where LogDebug is used, not the Log::printLog
> method.
>
> Is there any way to add a suppression based on the global variable?
>
> Thanks,
>
> Andy
>
Andy,
not an ideal solution, but could you do something like this
static boolean logRequired(void)
{
return (Log::minLevel <= Log::LVL_DEBUG);
}
#define logDebug if ( logRequired() ) Log::printLog
and then suppress the warning for logRequired()
Of course, you need to disable auto-inlining for logRequired()
HTH,
Colin S. Miller
|
|
From: Andy H. <And...@au...> - 2009-05-21 17:18:13
|
Colin Miller wrote:
> Andy Howell wrote:
>> I have some code that uses the pre-processor to generate code to log messages:
>>
>> #define logDebug if ( Log::minLevel <= Log::LVL_DEBUG ) Log::printLog
>>
>> Helgrind reports data races ultimately due to the global Log::minLevel. While technically
>> this is a potential race condition, Log::minLevel is essentially a constant after startup.
>>
>> I tried to add suppressions for the mangled Log::printLog method, however because of the
>> #define, helgrind reports the race on lines where LogDebug is used, not the Log::printLog
>> method.
>>
>> Is there any way to add a suppression based on the global variable?
>>
>> Thanks,
>>
>> Andy
>>
> Andy,
> not an ideal solution, but could you do something like this
>
> static boolean logRequired(void)
> {
> return (Log::minLevel <= Log::LVL_DEBUG);
> }
> #define logDebug if ( logRequired() ) Log::printLog
>
>
> and then suppress the warning for logRequired()
>
>
> Of course, you need to disable auto-inlining for logRequired()
>
Colin,
Thanks, that did the trick. I tried various combinations declaring minLevel as a const
and evilly circumventing the 'const-ness'. Good for generating core dumps, but not much else.
Regards,
Andy
|
|
From: Julian S. <js...@ac...> - 2009-05-21 17:27:34
|
On Thursday 21 May 2009, Andy Howell wrote:
> Colin Miller wrote:
> > Andy Howell wrote:
> >> I have some code that uses the pre-processor to generate code to log
> >> messages:
> >>
> >> #define logDebug if ( Log::minLevel <= Log::LVL_DEBUG ) Log::printLog
> >>
> >> Helgrind reports data races ultimately due to the global Log::minLevel.
> >> While technically this is a potential race condition, Log::minLevel is
> >> essentially a constant after startup.
> >>
> >> I tried to add suppressions for the mangled Log::printLog method,
> >> however because of the #define, helgrind reports the race on lines where
> >> LogDebug is used, not the Log::printLog method.
> >>
> >> Is there any way to add a suppression based on the global variable?
> >>
> >> Thanks,
> >>
> >> Andy
> >
> > Andy,
> > not an ideal solution, but could you do something like this
> >
> > static boolean logRequired(void)
> > {
> > return (Log::minLevel <= Log::LVL_DEBUG);
> > }
> > #define logDebug if ( logRequired() ) Log::printLog
> >
> >
> > and then suppress the warning for logRequired()
> >
> >
> > Of course, you need to disable auto-inlining for logRequired()
Yes, I would strongly suggest adding __attribute__((noinline)) to the
declaration, if you want this to work (somewhat more) reliably in the
presence of inlining.
J
|