Export (0) Print
Expand All

Running Standalone PREfast for Drivers

To run PREfast for Drivers, use the following procedure.

  1. Open a WDK build environment window.

    To open a build environment window, use the follow menu path:

    Start | All Programs | Windows Driver Kits | WDK_Version | Build Environment | Operating System | Build Environment.

    Select the build environment for the Windows version on which the driver runs. PREfast for Drivers supports free and checked versions of all x86- and x64-based build environments.

    Be aware that unless you have explicitly configured OACR otherwise, OACR runs by default, and it is not necessary to run PFD as described here. For more information, see Windows Auto Code Review (OACR).

  2. Navigate to the driver's sources directory.

    This is the directory that contains the sources file for the driver. If you do not have a driver to test, consider running PREfast for Drivers on one of the sample code files packaged with the tool. To run PREfast for Drivers on its sample files, navigate to the \tools\pfd\samples subdirectory of the WDK. For more information, see Building the Samples.

  3. Start PREfast for Drivers. To start PREfast for Drivers, at the command prompt, type prefast followed your standard build command. For example:
    
    prefast build -cZ
    
    

    For more information about the syntax of this command, see PREfast Build. For a complete command syntax, see PREfast for Drivers Commands.

    As it runs, PREfast for Drivers writes a brief transaction log to the command line. When the compilation is complete, PREfast for Drivers displays a summary of the results.

    The following illustration shows the result of a prefast build -cZ command in the \tools\pfd\samples\fail_drivers\fail_driver1 subdirectory of the WDK.

    
     prefast build -zg
    -----------------------------------------------------------------------------
    Microsoft (R) PREfast Version 9.0.
    Copyright (C) Microsoft Corporation. All rights reserved.
    -----------------------------------------------------------------------------
    BUILD: Compile and Link for x86
    BUILD: Start time: Mon Mar 09 14:23:55 2009
    BUILD: Examining c:\winddk\7011\tools\pfd\samples\fail_dri
    vers\fail_driver1 directory for files to compile.
        c:\winddk\7011.0\tools\pfd\samples\fail_drivers\fail_dri
    ver1
    BUILD: Building generated files in c:\winddk\7011\tools\pf
    d\samples\fail_drivers\fail_driver1 directory
    BUILD: Compiling c:\winddk\7011\tools\pfd\samples\fail_dri
    vers\fail_driver1 directory
    Compiling - driver.c
    Compiling - driver.c
    BUILD: Finish time: Mon Mar 09 14:24:04 2009
    BUILD: Done
    
        4 files compiled
    -----------------------------------------------------------------------------
    Removing duplicate defects from the log...
    -----------------------------------------------------------------------------
    PREfast reported 10 defects during execution of the command.
    -----------------------------------------------------------------------------
    Enter PREFAST LIST to list the defect log as text within the console.
    Enter PREFAST VIEW to display the defect log user interface.
    
     
    
    
  4. Open the Defect Log. To open the Defect Log, the PREfast for Drivers output file, type a PREfast View command.
    
    prefast view
    
    
  5. View the Message List. In the Defect Log, examine the Message List. To make this task easier, click the title of the Warning column in the Message List to sort the warnings by warning number.

  6. Examine a warning. To examine the code associated with a particular warning, double-click the warning.

    When you double-click the warning, PREfast for Drivers opens the Annotated Source View of the warning. This view displays the code that elicited the warning.

    For more information about the warning, you can double-click the warning number to jump to the Help reference page. For example, if you double-click Warning 6001 in the Annotated Source View, PREfast for Drivers displays that Help topic from the PREfast for Drivers Warnings.

  7. Fix the code. If you determine that PREfast for Drivers has detected a coding error, fix the error in the code, and then run PREfast for Drivers again.

    If you are certain that the code is correct and that PREfast for Drivers has misinterpreted it, use the strategies in the Minimizing Noise section to suppress the error. Be sure to use a method that suppresses only the error that you have thoroughly investigated.

  8. Run PREfast for Drivers again. After fixing the code, use a PREfast Build command to run PREfast for Drivers and build your code again. For example:
    
    prefast build -cZ
    
    

    Then, use a PREfast View command to open the Defect Log.

    For example,

    
    prefast view
    
    

 

 

Send comments about this topic to Microsoft

Build date: 5/3/2011

Show:
© 2014 Microsoft