Thursday, January 29, 2009

Building Windows Software Tracing from Visual Studio 2008

Rule File to use with Visual Studio 2008 SP1.

The Windows software trace preprocessor (abbreviated WPP; the preprocessor and related support tools are known as WPP Software Tracing) is a preprocessor that simplifies the use of WMI event tracing to implement efficient software tracing in drivers and applications that target Windows 2000 and later operating systems. WPP was created by Microsoft and is included in the Windows DDK.

WPP is run prior to compilation (in other words, before even the C preprocessor), and generates a trace message header for each file that it processes (by default this header is filename.tmh, where filename is the name of the processed source file). This header must then be explicitly included into the source file, for example:

// File: file.cxx
// This file is an example of using WPP
#include "file.tmh"


The preprocessing for WPP is normally handled by the DDK compiler. This rules out using Visual Studio to add this to your project. After looking around there is a nearly undocumented solution. The preprocessor also exists as an executable named tracewpp.exe in the bin directory in the DDK. Normally this would be
c:\WinDDK\6001.18002\bin\x86\tracewpp.exe


To add this to VS 2008 SP1, the easiest way I've found is to create a second project as a dependency to your driver project. Then each C/CPP file can use a custom build rule.

Here's how to setup the project.
Create a new project, and change the type to Utility. This will keep it from compiling the .c files.



Right click on the new project to edit the Custom Build Rules.


Add a custom rule file so that you can reuse it. I called mine WPP.

Here are the Build Rule properties you will need.


Rule file to use with Visual Studio 2008 SP1.

No comments: