Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Sept/Oct 2019 Issue of The NT Insider available


Download PDF here: http://insider.osr.com/2019/ntinsider_2019_01.pdf

It’s a particularly BIG issue, too: 40 pages of technical goodness, ranging from WDF to Minifilters. Check it out.
Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

WPP Intellisense Errors

Erik_DabrowskyErik_Dabrowsky Member - All Emails Posts: 21

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

Comments

  • Jeffrey_Tippet_[MSFT]Jeffrey_Tippet_[MSFT] Member - All Emails Posts: 552

    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.

  • Erik_DabrowskyErik_Dabrowsky Member - All Emails Posts: 21
    edited October 11

    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
    
  • Jeffrey_Tippet_[MSFT]Jeffrey_Tippet_[MSFT] Member - All Emails Posts: 552

    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.

  • Scott_Noone_(OSR)Scott_Noone_(OSR) Administrator Posts: 3,172

    (Erik has been despammed)

    -scott
    OSR

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 7,443

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

    Peter

    Peter Viscarola
    OSR
    @OSRDrivers

  • Erik_DabrowskyErik_Dabrowsky Member - All Emails Posts: 21
    edited October 11

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

    Thanks!

  • Jeffrey_Tippet_[MSFT]Jeffrey_Tippet_[MSFT] Member - All Emails Posts: 552

    @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.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
Writing WDF Drivers 21 Oct 2019 OSR Seminar Space & ONLINE
Internals & Software Drivers 18 Nov 2019 Dulles, VA
Kernel Debugging 30 Mar 2020 OSR Seminar Space
Developing Minifilters 27 Apr 2020 OSR Seminar Space & ONLINE