Time for a DbgPrint/Ex question

All

I have a protocl driver running on W2k3 and later LH.

I abstraced writing debug msgs by wrapping it in a macro.
MyDbgPrint(MyComponnet, MyComponnetLogLevel, IN PCHAR Format, . .[arguments] );

It just resolves to DbgPrint after doing some prolog on whether to invoke DbgPrint or not depending on the MyComponnet and MyComponnetLogLevel for that component.

Basically provides another level of indirection where I can selectively see msgs belonging to only selected logical component (SEND, RCV, INIT, UNLOAd etc ) depending on MyComponentLogLevel (ERROR, WARNING, INFORMATION etc) of my protocol driver.
That way I can verbosity and severity of my components.

I call something like
MyDbgPrint(INIT, INFO, (“DriverEntry”));

Since my driver has to eventually run on LH, I wanted to use DbgPrintEx, but the problem with DbgPrintEx is
-it has 2 preceeding params before we can list the print va_list and va_args and
-it behaves as below.,
Not printed
DbgPrintEx(DPFLTR_IHVDRIVER_ID, 0xFFFFFFFF, (“DriverEntry”));
Printed
DbgPrintEx(DPFLTR_IHVDRIVER_ID, 0xFFFFFFFF, “DriverEntry”));

PS: Assume all masks, Filters are valid, enabled etc etc.

Q1) Can someone let me know why the first one does not print or how to make the first one print or (can MS make that format (with extra pair of braces) also to be printed ???).

I tried some macro stuff, but not able to come up with one that resolves to usable DbgPrintEx. I want
#define MyDbgPrint(MyComponnet, MyComponnetLogLevel, IN PCHAR Format, . .[arguments] );
to resolve to
DbgPrintEx(DPFLTR_IHVDRIVER_ID, 0xFFFFFFFF, IN PCHAR Format, . .[arguments]);

Q2) After I get this resolved, can I assume the following will alsways be printed irrespective of what the mask value is in registry or not have to set in dbgview or poke registry etc.

DbgPrintEx(DPFLTR_IHVDRIVER_ID, 0xFFFFFFFF, “XX”);
(I think) it should, but just want to confirm as DDK help makes conflicting statements on usability of DbgPrint in W2k3, LH and masks (WIN2000) etc.

–thanks

I don’t believe that you can map MyDbgPrint() to DbgPrintEx() directly using standard c macros. However, VC++ variadic macro support looks like it might help out here, but it would be non-standard (not that it really matters in a Windows driver). I tried this, and if my assesment of what you wish is correct, then I think that this will do what you wish:

#define MyDbgPrint(MyComponent, MyComponentLogLevel, Format, …) \
DbgPrintEx(DPFLTR_IHVDRIVER_ID, 0xFFFFFFFF, Format, VAR_ARGS);

MSDN:

http://msdn2.microsoft.com/en-us/library/ms177415(VS.80).aspx

Incidentally, what you might wish to use rather than DbgPrintEx is KdPrintEx, so that it doesn’t expand in FREE builds.

Good luck,

mm

  1. Perhaps you could

Correction - that should be VA_ARGS, not VAR_ARGS.

Sorry,

mm

xxxxx@yahoo.com wrote:

All

I have a protocl driver running on W2k3 and later LH.

I abstraced writing debug msgs by wrapping it in a macro.
MyDbgPrint(MyComponnet, MyComponnetLogLevel, IN PCHAR Format, . .[arguments] );

It just resolves to DbgPrint after doing some prolog on whether to invoke DbgPrint or not depending on the MyComponnet and MyComponnetLogLevel for that component.

Basically provides another level of indirection where I can selectively see msgs belonging to only selected logical component (SEND, RCV, INIT, UNLOAd etc ) depending on MyComponentLogLevel (ERROR, WARNING, INFORMATION etc) of my protocol driver.
That way I can verbosity and severity of my components.

I call something like
MyDbgPrint(INIT, INFO, (“DriverEntry”));

Since my driver has to eventually run on LH, I wanted to use DbgPrintEx, but the problem with DbgPrintEx is
-it has 2 preceeding params before we can list the print va_list and va_args and
-it behaves as below.,
Not printed
DbgPrintEx(DPFLTR_IHVDRIVER_ID, 0xFFFFFFFF, (“DriverEntry”));
Printed
DbgPrintEx(DPFLTR_IHVDRIVER_ID, 0xFFFFFFFF, “DriverEntry”));

PS: Assume all masks, Filters are valid, enabled etc etc.

Q1) Can someone let me know why the first one does not print or how to make the first one print or (can MS make that format (with extra pair of braces) also to be printed ???).

The first one will print, as long as the string is the only thing inside
the parens. If you have extra parameters, it won’t work.

DbgPrintEx( DPFLTR_IHVDRIVER_ID, 0xFFFFFFFF, (“What is this: %d\n”, 2
) );

The reason is that this is not a macro – it is a function call with
exactly three parameters. The third parameter happens to be an
expression using the comma operator. The value of the comma operator is
the right-hand value. In this case, that is 2.

There’s just no easy way to go from this:
MyDbgPrint( A, B, (C, D, E) );
to this:
YourDbgPrint( A, B, C, D, E );


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

MM, Tim

Thanks for your replies!

MM
I used variadic one and it works (compiles). Did not even have to include stdio.h even, probably was included somewhere. I guess it shoudl work when I test it once tomorrow.
thanks again!

Have a follow up macro question! for following code snippet
enum {abc=1};
PRINTX(abc)
abc should be printed – Note abc is a type no quotes are supplied when it is called.

The macro was MYPRINTXX(param) if(param) DbgPrint(%s, “param”).

I stopped at below which obviously did not work - prints “param” not abc.
Any way to print the variable (or string literal) passed as string literal through a macro.

msr wrote:

Have a follow up macro question! for following code snippet
enum {abc=1}; PRINTX(abc) abc should be printed – Note abc
is a type no quotes are supplied when it is called.

I stopped at below which obviously did not work - prints “param”
not abc. Any way to print the variable (or string literal) passed as
string literal through a macro.

How about:

#define PRINTX(x) if (x) DbgPrint(#x)

Chris
Thank you!

> ----------

From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of Tim Roberts[SMTP:xxxxx@probo.com]
Reply To: Windows System Software Devs Interest List
Sent: Tuesday, October 16, 2007 3:35 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Time for a DbgPrint/Ex question

There’s just no easy way to go from this:
MyDbgPrint( A, B, (C, D, E) );
to this:
YourDbgPrint( A, B, C, D, E );

It is possible and easy with variadic macros. I use it for a long time because didn’t want to remove extra parens from all the old code :slight_smile: First, it is necessary to define problem correctly i.e.

MyDbgPrint(A, B, (PrintParams)) -> YourDbgPrint(A, B, PrintParams)

Then, the old trick for parens removal can be utilized:

#define _REMOVE_PARENS(…) VA_ARGS

#define MyDbgPrint(A, B, PrintParams) \
YourDbgPrint(A, B, _REMOVE_PARENS PrintParams)

(haven’t tested, I use it a bit more complicated way)

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com]