Viewing source code that’s in the “wrong place”.

By Stephen Kellett
26 November, 2021

You’ve been given a program to debug. You’ve got the EXE and DLLs, and you’ve got the PDB files, so you can tell when the filenames, line numbers and symbol names are.

So far so good.

You’ve also got access to the source code, but the source is not on your machine, it’s on the original machine that the EXE and DLLs were built on.

How do you view the source using the various Validator tools? The answer is the same for all the Validators, so I’ll just concentrate on showing you how to do this with Coverage Validator.

Build Machine: XPS13

First, we need to create an application on the build machine and try working with it on the test machine.

I’m going to create exampleApp on the machine xps13 on drive D:\ in the dev directory. It’s an MFC application built with the standard MFC app project creation wizard.

Drive D on xps13 is shared. Full path to the application: \\xps13\d\dev\exampleApp\exampleApp

Files on computer XPS13

Test Machine

On the test machine, I’m going to create a similar directory structure to the test application, but it will only contain executable and PDB files. There will be no source code.

Example test machine

Coverage Validator: First Run

If we just run Coverage Validator without telling it where the source code is, the PDB file will be found and code coverage will be performed using the debug information, but it won’t be possible to view the source code because the source code paths point to d:\dev\exampleApp\exampleApp on the test machine. There is no source code on the test machine.

If you click on the filename on the left-hand panel a Find source file dialog box is displayed because the source file can’t be found at the specified location, or in any location in the Coverage Validator settings.

First run, unable to find source code

Configuring Source Code Location

For the dialog box above there are three options, two of which are useful in this scenario:

  • Search Folder…. Use the Microsoft Folder dialog to navigate to the location of the source code on the build machine. For this example, you need to choose the folder d:\dev\exampleApp\exampleAppon the networked machine xps13
  • File Locations…. Edit the Coverage Validator file location definitions. This will display a version of the File Locations tab which can be found on the Coverage Validator settings dialog.

The file location definitions can also be edited from the Coverage Validator settings dialog, which you can access via the Settings menu.

File locations dialog - PDB files

The first thing to note is that the default display for File Locations is the location of PDB files. We need to add the path \\xps13\d\dev\exampleApp\exampleApp to the Source Files section.

  • Change the Path Type combo to Source Files.
  • Click Add… to add a path to the list of paths.
  • Type the path \\xps13\d\dev\exampleApp\exampleApp into the edit box.
  • Click OK to accept the new settings.

File locations dialog - source files

Viewing Source Code

Now that we have the source code location correctly configured if we click on the filename in the left-hand panel we will see source code in the right-hand panel.

It’s possible that for your application you have more than one path to your source code on the build machine. If that’s the case just add as many paths as you need to the Source Files section of the File Locations settings.

Now able to find the source code

Conclusion

You’ve learned how to configure alternate locations to look for source code, useful for when the source code is in a different location than when the application was built.

Fully functional, free for 30 days