WPP Intellisense Errors

Hi,

I’m using Visual Studio 2019 (16.3.2) and am seeing hundreds of WPP errors in the intellisense errors list. The project compiles fine and WPP tracing is working fine.

The errors I’m seeing are:
E0020 identifier “TRACE_DRIVER” is undefined
and
E0020 identifier “WPP_CALL_TSPIFC2532_cpp194” is undefined.

Things I’ve checked/tried so far:
Under Project Properties / Wpp Tracing
General: Run Wpp Tracing set to Yes
Search and Formatting: Function To Generate Trace Messages: TraceEvents(LEVEL, FLAGS, MSG, …)
File Options: Scan Configuration Data: trace.h

I’ve tried adding the .tmh file into the project in solution explorer and that seems to fix it momentarily until I start editing code again, then the intellisense errors return.

Anyone else have this annoyance and know how to fix it?

Thanks,
Erik

As far as I know, nobody’s built a great solution. Or phrased differently: if you find a great solution, please let me know, because I’d love to use it.

The problem is that WPP emits a header file with line numbers embedded in function names. The line number refers to the line of C code where the trace statement sits. (Footnote: this is why you can’t have two WPP traces on the same line of code.) This happens at build time. If you start editing the code, as soon as you insert/delete a line, that throws off the line numbers of all the following trace statements.

This could be fixed if VS was aware that it needed to regenerate the TMH every time you edit the file. (Much like it re-computes its intellisense for the C language every time you edit the file). But as far as I know, VS doesn’t have any deep understanding of WPP; the WDK just injects some msbuild goop to tell it to call out to some black box EXE that happens to have the side effect of dropping TMH files on disk.

I suspect if you wanted a proper fix, you’d have to implement some sort of VS extension that hooked into the editor and ran tracewpp.exe every time you insert/delete a line. Or edit a line that has a trace statement on it. Or edit a line that declares a variable that goes into a trace statement. Or edit a typedef that goes into a declaration of … And then you discover that it’s a hard problem to build an incremental intellisense engine without killing perf by running crap on every keystroke.

Maybe a “good enough” extension would run tracewpp.exe every 500ms or something.

Thanks for the insight on that Jeffrey.

I’ve found what I consider to be a sort of hackish way to turn off the WPP tracing intellisense errors for the file you’re currently editing.
At the top of the source file, after the #include “xxxxxx.tmh” line, you can add:

#undef TraceEvents
#define TraceEvents(...)

(Assuming “TraceEvents” is the name of your macro).

The downside to this approach is that you have to remember to comment out or delete those two lines before compiling.

If there was a way to define a preprocessor variable that only the intellisense compiler/interpreter was aware of we might be able to do something like this:

#if Intellisense
#undef TraceEvents
#define TraceEvents(...)
#endif

Erik’s mail appears to be languishing in the spam queue, so let me quote it here:

At the top of the source file, after the #include “xxxxxx.tmh” line, you can add:
#undef TraceEvents
#define TraceEvents(...)

This is a brillant hack, so thanks for that. I’ll add that the preprocessor macro __INTELLISENSE__ is defined while the IDE is calculating intellisense errors. So you can make this hack more ergonomic with:

#ifdef __INTELLISENSE__
#undef TraceEvents
#define TraceEvents(...)
#endif

You might even throw an UNREFERENCED_PARAMETER((__VA_ARGS__)) in there too, so you don’t get any warnings about variables that are only used in the format string of your trace message.

(Erik has been despammed)

Somebody (nudge nudge) needs to forward that to the Dev Kits team and make it the default when WPP tracing is enabled.

Peter

That’s cool!
I didn’t know about __INTELLISENSE__

Thanks!

@“Peter_Viscarola_(OSR)” said:
Somebody (nudge nudge) needs to forward that to the Dev Kits team and make it the default when WPP tracing is enabled.

I’ve squinted, scratched my chin, and meditated over your message. After hours of reading between the lines, I’ve come to the conclusion that you were hinting that I should go fix this.

So I just filed a bug on the team that owns this. I believe that there’s a fairly small addition that can be made to tracemacro.tpl (a file that ships with the kit) to make this something that you can configure once in one central header, instead of pasting boilerplate into each C file.