Caphyon / clang-power-tools

Bringing clang-tidy magic to Visual Studio C++ developers.
http://www.clangpowertools.com
Apache License 2.0
487 stars 57 forks source link

Support for WPP tracing #236

Open fulopboti opened 6 years ago

fulopboti commented 6 years ago

Projects which use WPP tracing (WindowsAplicationForDriversXX) and do include the tmh files will raise errors such as: C:\...\myfile.c:8:10: fatal error: 'myfile.tmh' file not found

example source file:

#include "myfile.h"
#include "trace.h"
#include "myfile.tmh"

int square(int num) {
    return num*num;
}

example trace.h:

#ifndef __TRACE_H_INCLUDED__
#define __TRACE_H_INCLUDED__
//
// WPP Control GUID for MyProject: 2DC429B3-080F-4539-A340-D1C707D47E31
//
#define WPP_CONTROL_GUIDS                                              \
    WPP_DEFINE_CONTROL_GUID(                                           \
        MyProject, (2DC429B3,080F,4539,A340,D1C707D47E31),      \
        WPP_DEFINE_BIT(TRACE_FLAG_APPLICATION)      /* bit  0 = 0x00000001 */ \
        ) 

#define WPP_LEVEL_FLAGS_LOGGER(lvl,flags) WPP_LEVEL_LOGGER(flags)
#define WPP_LEVEL_FLAGS_ENABLED(lvl,flags) (WPP_LEVEL_ENABLED(flags) && WPP_CONTROL(WPP_BIT_ ## flags).Level  >= lvl)

#define WPP_LEVEL_FLAGS_TIMESTAMP_LOGGER(lvl, flags, tmpstamp) WPP_LEVEL_LOGGER(flags)
#define WPP_LEVEL_FLAGS_TIMESTAMP_ENABLED(lvl, flags, tmpstamp) WPP_LEVEL_FLAGS_ENABLED(lvl, flags)

//
// Here we define our logging functions
//
// begin_wpp config
//
// FUNC AppLogTrace{LEVEL=TRACE_LEVEL_VERBOSE, FLAGS=TRACE_FLAG_APPLICATION}(MSG, ...);
// FUNC AppLogInfo{LEVEL=TRACE_LEVEL_INFORMATION, FLAGS=TRACE_FLAG_APPLICATION}(MSG, ...);
// FUNC AppLogWarning{LEVEL=TRACE_LEVEL_WARNING, FLAGS=TRACE_FLAG_APPLICATION}(MSG, ...);
// FUNC AppLogError{LEVEL=TRACE_LEVEL_ERROR, FLAGS=TRACE_FLAG_APPLICATION}(MSG, ...);
// FUNC AppLogCritical{LEVEL=TRACE_LEVEL_CRITICAL, FLAGS=TRACE_FLAG_APPLICATION}(MSG, ...);
//
// end_wpp
//

#endif//__TRACE_H_INCLUDED__
cpp-red-lion commented 6 years ago

Hi,

Thank you for bringing this issue to our attention.

Can you attach a small sample VS project (with source files) reproducing this problem?

fulopboti commented 6 years ago

Hi, I have attached a zip for a sample application.

Afaik MsBuild uses a WPP precompiler, which generates these tmh files, which contains macros for logging messages trough ETW.

From a procmon log we can see that the MsBuild.exe starts the C:\Program Files (x86)\MSBuild\14.0\bin\Tracker.exe with a commandline which then starts the tracewpp.exe, to generate these tmh files.

As a solution you could generate temporary tmh files which contain only the macros with empty bodies from the comment in the trace.h file.

SampleApp.zip