WPP preprocessor format specifier

I want to use WPP tracing in my driver. I am converting DbgPrint statement
to DoTraceMessage statement in the whole code. I want to print the first 40
chacters of a wide char string. Previously i used to do like this

#define GUID_SIZE_IN_CHARS 36
DbgPrint( “DeviceIoControlCommitDirty: IOCTL GUID %*.S\n”,
GUID_SIZE_IN_CHARS, (PWCHAR)Irp->AssociatedIrp.SystemBuffer);

This statement is not working in WPP tracing. Basically a format specifier
%*.S in not working in WPP. Please help me in achieving the same.

Thanks in advance


Regards
Rohit Gauba

Try making a UNICODE_STRING of it and using %wZ


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

“Rohit” wrote in message news:xxxxx@ntdev…
I want to use WPP tracing in my driver. I am converting DbgPrint statement to DoTraceMessage statement in the whole code. I want to print the first 40 chacters of a wide char string. Previously i used to do like this

#define GUID_SIZE_IN_CHARS 36
DbgPrint( "DeviceIoControlCommitDirty: IOCTL GUID %.S\n", GUID_SIZE_IN_CHARS, (PWCHAR)Irp->AssociatedIrp.SystemBuffer);

This statement is not working in WPP tracing. Basically a format specifier %
.S in not working in WPP. Please help me in achieving the same.

Thanks in advance


Regards
Rohit Gauba

Thanks maxim for the reply. One more question. Is it possible to use
multiple flags in DoTraceMessage. Multiple flags can be used by ORing the
flags.
like FLAG1 | FLAG2. I tried this but found that this is not working. Is
their any way to use multiple flags.

Regards
Rohit Gauba

On Sat, Feb 28, 2009 at 2:01 PM, Maxim S. Shatskih
wrote:

> Try making a UNICODE_STRING of it and using %wZ
>
> –
> Maxim S. Shatskih
> Windows DDK MVP
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
> “Rohit” wrote in message news:xxxxx@ntdev…
> I want to use WPP tracing in my driver. I am converting DbgPrint statement
> to DoTraceMessage statement in the whole code. I want to print the first 40
> chacters of a wide char string. Previously i used to do like this
>
> #define GUID_SIZE_IN_CHARS 36
> DbgPrint( "DeviceIoControlCommitDirty: IOCTL GUID %.S\n",
> GUID_SIZE_IN_CHARS, (PWCHAR)Irp->AssociatedIrp.SystemBuffer);
>
> This statement is not working in WPP tracing. Basically a format specifier
> %
.S in not working in WPP. Please help me in achieving the same.
>
> Thanks in advance
>
>
> –
> Regards
> Rohit Gauba
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Regards
Rohit Gauba

“A positive thought is the seed of a positive result”

Hi Rohit,

Please note that these flags are actually trace lavels so a single log can not be mapped to two
trace lavels. E.g. Some logs are informative while some are for reporting error.

Also note that if you enable logs for trace lavel 5 then it will generate logs for trace lavel 5 and
less than 5. That means you need not require to give two flags for same DoTraceMessage.

Thanks & Regards,
Amit.

Hi Amit,
Thanks a lot for the reply. But i feel That i was not able to express myself
clearly.

suppose i have appended a line in sources file

RUN_WPP=$(SOURCES) -km *-func:DoTraceLevelMessage(LEVEL,FLAGS,MSG,…)*

then from now onwards i can use DoTraceLevelMessage for generating trace
messages. First argument here is level and second argument is flags. In my
previous post i am talking about flags and not level. I hope now I am clear

Regards
Rohit Gauba

On Mon, Mar 2, 2009 at 5:05 PM, wrote:

> Hi Rohit,
>
> Please note that these flags are actually trace lavels so a single log can
> not be mapped to two
> trace lavels. E.g. Some logs are informative while some are for reporting
> error.
>
> Also note that if you enable logs for trace lavel 5 then it will generate
> logs for trace lavel 5 and
> less than 5. That means you need not require to give two flags for same
> DoTraceMessage.
>
> Thanks & Regards,
> Amit.
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Regards
Rohit Gauba

“A positive thought is the seed of a positive result”

Hi Rohit,

Please go through http://msdn.microsoft.com/en-us/library/ms793169.aspx

The flags that you are talking about are from WPP_CONTROL_GUIDS and first parameter to DoTraceLevelMessage is ETW?Level?defined?in?evntrace.h. So that is the difference.

And what I have explained in previous post is explanation of the flags in WPP_CONTROL_GUIDS and not of ETW?Level.

Thanks & Regards,
Amit.

Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/

Hi
I am able to use multiple flags in DoTraceMessage and DoTraceLevelMessage
but i just want to confirm that what i am doing is right or not or is their
any simple and easy way to achieve the same.

Basically i have made the following changes. Suppose we are using three
flags
Error, Noise and Unusual

then we have to define

#define WPP_BIT_Error Error
#define WPP_BIT_Noise Noise
#define WPP_BIT_Unusual Unusual

The purpose of defining these three #defines is to use Error instead of
WPP_BIT_Error in the whole code

also we need to define few macros

#define WPP_LEVEL_ENABLED(CTL) (WPP_CONTROL(CTL).Flags[WPP_FLAG_NO(CTL)] &
Var(CTL))
#define WPP_LEVEL_FLAGS_LOGGER(level,flags) WPP_LEVEL_LOGGER(flags)
#define WPP_LEVEL_FLAGS_ENABLED(level, flags) (WPP_LEVEL_ENABLED(flags) &&
WPP_CONTROL(flags).Level >= level)

the purpose of defining these macros is to override by default macro and to
provide our own. I have changed the definition of first macro a bit

suppose I want to log based upon two flags

DoTraceMessage(Error | Noise,“IOCTL count is %d”, ioctlcount);

since the value of Error is 1 and the value of Noise is 2 so we have to
device a mechnism to compute 2pow(0) | 2pow(1).

for doing the same I have define a struct and overload | (bitwise OR)
operator and computed 2pow(0) | 2pow(1).

struct A
{
A()
{
val = 0;
}

int Result ()
{
int ret=val;
val=0;
return ret;
}
A& operator | (int pval)
{
val |= 1<<(pval - 1);
return *this;
}
int val;
};
extern A obj;
#define Var(exp) (obj|exp).Result()

I guess it will work fine. Please suggest me if you find any bug in this
approach. I have sompiled the code and also seen the C-preprocessor output
and observe that everything is expected as i want. Note that Var macro is
used inside WPP_LEVEL_ENABLED macro

Regards
Rohit Gauba

On Tue, Mar 3, 2009 at 11:49 AM, Amit Kulkarni > wrote:

> Hi Rohit,
>
> Please go through http://msdn.microsoft.com/en-us/library/ms793169.aspx
>
> The flags that you are talking about are from WPP_CONTROL_GUIDS and first
> parameter to DoTraceLevelMessage is ETW Level defined in evntrace.h. So that
> is the difference.
>
> And what I have explained in previous post is explanation of the flags in
> WPP_CONTROL_GUIDS and not of ETW Level.
> Thanks & Regards,
> Amit.
>
> ------------------------------
> Did you know? You can CHAT without downloading messenger. Click herehttp:</http:>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Regards
Rohit Gauba

“A positive thought is the seed of a positive result”

Hi Rohit,
As I understand you want to log the message if certain flag bits (more than one) are set.
WPP is intended to log messages testing single flag bit only. If you want to log message where more than one flag is set, you can check it manually in your code, or define third flag which will ?represent? the flags you want to mix (e.g. ErrorOrNoise).

For the code you provided here is the bug: WPP pre-processor would produce a flags test condition as follows (((WPP_GLOBAL_Control[0].Control).Flags[0] & (1 << ( ((Error | Noise)-1) & 31 )))
For Error= 1 and Noise = 2, (Error | Noise = 3), the third bit will be tested instead of the first and second.
The right condition for that purpose would be ( ((1 << (Error - 1)) | (1<< (Noise-1))) & 31 ), which can?t be produced by WPP.
Again, if you explain your scenario we can find a workaround.

Thanks,
Zoran Dimov

Hi Dimovz,

I am sorry that I was not able to express clearly myself. In my previous
mail i have deefined a struct and overload operator bitwise OR(|) operator
for calculating the same that you were telling. And also i have defined one
macro named as Var which basically using operator overoading and computing
(Error|Noise) as (1<<(Error-1))|(1<<(Noise -1)). Offcourse i assumed that
Noise and Error has value less than 31, that is why I skipped that part & 31

struct A
{
A()
{
val = 0;
}

int Result ()
{
int ret=val;
val=0;
return ret;
}
A& operator | (int pval)
{
val |= 1<<(pval - 1);
return *this;
}
int val;
};
extern A obj;
#define Var(exp) (obj|exp).Result()

I am using Var macro in WPP_LEVEL_ENABLED macro. Var acro is the one which
calculated Var(Error|Noise) as (1<<(Error-1))|(1<<(Noise -1))

#define WPP_LEVEL_ENABLED(CTL) (WPP_CONTROL(CTL).Flags[WPP_FLAG_NO(CTL)] &
Var(CTL))

I hope now I am clear. Please let me know if you want more clarification.

Thanks for reply.

Regards
Rohit Gauba

On 3/15/09, xxxxx@live.com wrote:
>
> Hi Rohit,
> As I understand you want to log the message if certain flag bits (more than
> one) are set.
> WPP is intended to log messages testing single flag bit only. If you want
> to log message where more than one flag is set, you can check it manually in
> your code, or define third flag which will ?represent? the flags you want to
> mix (e.g. ErrorOrNoise).
>
> For the code you provided here is the bug: WPP pre-processor would produce
> a flags test condition as follows (((WPP_GLOBAL_Control[0].Control).Flags[0]
> & (1 << ( ((Error | Noise)-1) & 31 )))
> For Error= 1 and Noise = 2, (Error | Noise = 3), the third bit will be
> tested instead of the first and second.
> The right condition for that purpose would be ( ((1 << (Error - 1)) | (1<<
> (Noise-1))) & 31 ), which can?t be produced by WPP.
> Again, if you explain your scenario we can find a workaround.
>
> Thanks,
> Zoran Dimov
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Regards
Rohit Gauba

“A positive thought is the seed of a positive result”

Hi Rohit,

For some reason I missed your overloaded WPP_LEVEL_ENABLED macro.
Yes, with your macro you are handling multiple flags correctly.
The “& 31” operation is required if you add second provider in your code with seccond set of flags, so that the flags will be assumed again starting from 1 (WPP will start counting the second set from 2^16 + 1, for contol management reasons).

Also, it is good to remove the spaces when you OR the flags, so you will get them well presented when you consume with tracefmt (Error|Noise instead of Error | Noise)

Thanks,
Zoran Dimov