次の方法で共有


Make Static Driver Verifier More Efficient: Add a Preset Filter to PFD/OACR Defect Viewer

The Static Driver Tools team ships two products in the WDK, PREfast for Drivers, and Static Driver Verifier (SDV). As such, we have a lot of interaction between the products and have emphasized using the light-weight tool (PFD) to help with some of best-practice work that should be done to maximize the effectiveness of SDV. When PFD checks a driver, it checks rules related to this best-practice work and if found, they’re listed under warning numbers 6001, 6011, 28101, 28155, 28169, 28177, and 28182. A post on specifically that kind of work will shortly follow this entry, which provides specific details about the most important warnings in that list; the purpose of this post is to provide you with a means of keeping that warning set available at your finger-tips.

The defect viewer included with both standalone PREfast for Drivers (PFD) tool and the OACR tool include a small number of “preset filters” that will limit the number of defects displayed to the developer when viewing their results. While both of the viewers will maintain settings for a custom list between sessions (if, for example, you had limited your list to the above 7 warnings), it certainly is useful to have the ability to add your own preset filter that works best with your project.

The following steps can add a Preset filter to either the standalone PFD viewer or the OACR viewer, whichever is your preference. The preset filter can also be used with standalone PFD during the build process to limit the number of defects it looks for:

(Note: The environment variable PUBLIC_ROOT refers to the root of the WDK Build Environment that is currently being operated in.)

In all three cases, you’re going to add the following bit of XML to the filters.xml file associated with the viewer you’re running. In each case, I have added this as the last “preset”, appearing after “wspmin” in that file:

<preset name="Static Driver Verifier Prerequisites" invert="1">
<excludeWarnings>
6001;6011;28101;28155;28169;28177;28182
</excludeWarnings>
<excludeRegExps>pft;NTPub;VC6;MFC;ATL;LKRH;MIDL;INC</excludeRegExps>
</preset>

To add this preset filter to the PFD Viewer, add the above XML chunk to: %PUBLIC_ROOT%\tools\pfd\scripts\DefectUI\filters.xml.

To add this preset filter to the x86 OACR Build Environments, add the above XML chunk to: %PUBLIC_ROOT%\bin\x86\OACR\viewer\scripts\defectui\filters.xml

To add this preset filter to the amd64 OACR Build Environments, add the above XML chunk to: %PUBLIC_ROOT%\bin\amd64\OACR\viewer\scripts\defectui\filters.xml

Once those steps are completed, the defect viewer that you use will have a new drop-down appear in the Preset Filters called “Static Driver Verifier Prerequisites” for both the x86 and amd64 build environments:

PFD Viewer with new Preset

If that snippet is added to all three instances of filters.xml, it will be available in any of those scenarios where you are reviewing defects. It is worth mentioning, however, that standalone PFD provides two advantages over relying on OACR:

1. Warnings 6001 and 6011 are enabled by default in standalone PFD. Catching (and clearing!) the issues concerning uninitialized variables (6001) and null dereferences (6011) before scanning your driver with Static Driver Verifier is a very good thing to do: either has a chance of confusing the SDV engine.

2. The new preset filter can be applied while building the driver, limiting what the scanner looks for and reports on. Use the following command line to do so (assuming you named the preset "Static Driver Verifier Prerequisites"), the example beneath shows the output on the sample "fail_driver1" that ships with PFD:

Prefast /filter /filterpreset=”Static Driver Verifier Prerequisites” build –cZ

Demo of using the filterpreset with standalone PFD

(UPDATE Note: Included warning 6001 in the list.)

Comments

  • Anonymous
    May 11, 2009
    Normal 0 false false false EN-US X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table

  • Anonymous
    October 16, 2011
    The comment has been removed