Monday, April 25, 2011

Great OSR ONLINE Article About WPP | Famel

Copied from http://www.osronline.com/article.cfm?article=375:

Date:  10-Mar-05, Modified: 21-Mar-05
From: Hector J. Rodriguez
To:    Driver Developers Re: Need help with WPP tracing?
Here are three hot tips that'll help you use WPP tracing in drivers: The first tip is to not include the WPP_INIT_TRACING macro in more than one module. Here's an sneak peak at an upcoming article from The NT Insider that explains the problem: If you happen to be conditionally compiling your driver to work for XP and Windows 2000, you might notice that the WPP_INIT_TRACING macro on XP and later takes a pointer to your driver object instead of a device object. Therefore, you only need to call the macro once during DriverEntry processing. There is something to watch out for here though that tripped me up for a while. The WPP preprocessor will not tolerate the WPP_INIT_TRACING macro being in more than one module even if it is conditionally compiled out of one of the modules. So, if you call WPP_INIT_TRACING in your DriverEntry in one module if compiling for XP and call WPP_INIT_TRACING in your PnP module if compiling for Windows 2000, you will get compiler errors due to multiple definitions. The only solution is to add a separate module that exports functions that call the macros. The second tip comes from a question that showed up on NTDEV the other day. If you want to conditionally compile your driver such that WPP tracing is enabled in the free build and DbgPrint is used in the checked build, you can't just define a macro that calls the trace function in the free build and DbgPrint in the checked build. The issue arises for a similar reason to that of the first tip, the WPP preprocessor and the C preprocessor don't exactly go out for drinks after work. Your best bet is to code up something like this in your SOURCES: RUN_WPP=(Other parameters here) \
        -func:OsrTracePrint(LEVEL,FLAGS,(MSG,…)) And this in your main include file: #ifdef DBG #define OsrTracePrint(_level,_flag_,_msg_)  \
    if (OsrDebugLevel >= (_level_) && \
        OsrDebugFlags & (_flag_)) {\
        DbgPrint (DRIVER_NAME": ");\
        DbgPrint _msg_; \
    } #else //
// Just let WPP define OsrTracePrint
//

No comments:

Post a Comment