Static Linking

This tutorial describes how to setup Bug Validator to include or exclude different source files from instrumentation processing when you are statically linking your application with MFC and/or the C Runtime.

When you statically link to MFC and/or the CRT, the code for the MFC and/or CRT libraries is included in your application. This means that Bug Validator’s filtering by DLL policy will not work, as DLLs are not used to provide MFC and/or CRT support for statically linked applications.

This means that Bug Validator needs to know where the source code for your application, source code for 3rd parties (MFC, CRT, etc) and any other source code is kept.

Excluding MFC, CRT, STL source files

For the purposes of this tutorial we are going to assume the third party source code is the source code provided by Visual Studio for MFC, CRT and STL.

To exclude statically linked source code from instrumentation do this:

  1. Open the settings dialog by clicking the tools icon on the toolbar.
    Bug Validator Toolbar Settings
  2. The Settings Dialog is displayed. Select the File Locations tab.
    Bug Validator File Locations
  3. Set the Path Type to “Source Files” and then click File Scan… to display the Source File Search dialog.
    Source files dialog
  4. Select the Directory Search radiobox.
  5. Either type the path to the directory containing your application’s source code, or use the Browse… button to display a directory chooser dialog. Click OK when you are happy with the directory selection.
  6. The selected directory is scanned for source files. The results of the scan are displayed in the Source File Paths dialog.
    Source file paths dialog
  7. Click the Add to List button.
  8. The image shows one directory for an example statically linked application.
    Bug Validator File Locations Source Files
  9. Set the Path Type to “Third Party Source Files” and then click File Scan… to display the Third Party Source File Search dialog.
    Third party source files dialog
  10. Select the Visual Studio Search radiobox.
  11. Select the Visual Studio version you used to build the example application. Click OK when you are happy with the selection.
  12. The selected Visual Studio installation is scanned for third party source files. The results of the scan are displayed in the 3rd Party Source File Paths dialog.
    Third party source file paths dialog
  13. Click the Add to List button.
  14. The image shows many directories for the selected Visual Studio installation.
    Bug Validator File Locations Third Party Files
  15. Select the Hook Insertion tab.
    Bug Validator Settings Hook Insertion Static Linking Exclude MFC, CRT, STL
  16. Select the checkboxes in the section marked Source Code Line Hook Insertion. The image shows that 3rd party source code has been marked to be ignored (deselected).
  17. Note that the DLL Hook Insertion settings have no effect on statically linked code – thus we do not need to configure them.
  18. Click OK to accept the settings.

You have configured Bug Validator to work with statically linked applications – it will exclude MFC, CRT and STL source code from instrumentation.

Including MFC, CRT, STL source files

For the purposes of this tutorial we are going to assume the third party source code is the source code provided by Visual Studio for MFC, CRT and STL.

To include statically linked source code from instrumentation do this:

  1. Open the settings dialog by clicking the tools icon on the toolbar.
    Bug Validator Toolbar Settings
  2. The Settings Dialog is displayed. Select the File Locations tab.
    Bug Validator File Locations
  3. Set the Path Type to “Source Files” and then click File Scan… to display the Source File Search dialog.
    Source files dialog
  4. Select the Directory Search radiobox.
  5. Either type the path to the directory containing your application’s source code, or use the Browse… button to display a directory chooser dialog. Click OK when you are happy with the directory selection.
  6. The selected directory is scanned for source files. The results of the scan are displayed in the Source File Paths dialog.
    Source file paths dialog
  7. Click the Add to List button.
  8. The image shows one directory for an example statically linked application.
    Bug Validator File Locations Source Files
  9. Set the Path Type to “Third Party Source Files” and then click File Scan… to display the Third Party Source File Search dialog.
    Third party source files dialog
  10. Select the Visual Studio Search radiobox.
  11. Select the Visual Studio version you used to build the example application. Click OK when you are happy with the selection.
  12. The selected Visual Studio installation is scanned for third party source files. The results of the scan are displayed in the 3rd Party Source File Paths dialog.
    Third party source file paths dialog
  13. Click the Add to List button.
  14. The image shows many directories for the selected Visual Studio installation.
    Bug Validator File Locations Third Party Files
  15. Select the Hook Insertion tab.
    Bug Validator Settings Hook Insertion Static Linking Include MFC, CRT, STL
  16. Select the checkboxes in the section marked Source Code Line Hook Insertion. The image shows that 3rd party source code has been marked to be included (selected).
  17. Note that the DLL Hook Insertion settings have no effect on statically linked code – thus we do not need to configure them.
  18. Click OK to accept the settings.

You have configured Bug Validator to work with statically linked applications – it will include MFC, CRT and STL source code in the instrumentation.

 

Fully functional, free for 30 days