Symbol / PDB files in the Visual Studio debugger (original) (raw)

Specify symbol (.pdb) and source files in the Visual Studio debugger (C#, C++, Visual Basic, F#)

Program database (.pdb) files, also called symbol files, map identifiers and statements in your project's source code to corresponding identifiers and instructions in compiled apps. These mapping files link the debugger to your source code, which enables debugging.

When you build a project from the Visual Studio IDE with the standard Debug build configuration, the compiler creates the appropriate symbol files. This article describes how to manage symbol files in the IDE, for example:

For a detailed explanation of symbol files, see Understand symbol files and Visual Studio symbol settings.

How symbol files work

The .pdb file holds debugging and project state information that allows incremental linking of a Debug configuration of your app. The Visual Studio debugger uses .pdb files to determine two key pieces of information while debugging:

Symbol files also show the location of the source files, and optionally, the server to retrieve them from.

The debugger only loads .pdb files that exactly match the .pdb files created when an app was built (that is, the original .pdb files or copies). This exact duplication is necessary because the layout of apps can change even if the code itself isn't changed. For more information, see Why does Visual Studio require debugger symbol files to exactly match the binary files that they were built with?

Tip

To debug code outside your project source code, such as Windows code or third-party code your project calls, you must specify the location of the external code's .pdb files (and optionally, the source files), which must exactly match the builds in your app.

Where the debugger looks for symbols

When you debug a project in the Visual Studio IDE, the debugger automatically loads symbol files that it can find by default.

Note

When debugging managed code on a remote device, all symbol files must be located either on the local machine, or in a location specified in the debugger options.

The debugger searches for symbol files in the following locations, in the specified order:

  1. The project folder.
  2. The location specified inside the DLL or the executable (.exe) file.
    By default, if you have built a DLL or an .exe file on your computer, the linker places the full path and filename of the associated .pdb file in the DLL or .exe file. The debugger checks to see if the symbol file exists in that location.
  3. The same folder as the DLL or .exe file.
  4. Any locations specified in the debugger options for symbol files. To add and enable symbol locations, see Configure symbol locations and loading options.
    • Any local symbol cache folder.
    • Specified network, internet, or local symbol servers and locations, such as the Microsoft Symbol Servers if selected. Visual Studio can download debugging symbol files from symbol servers that implement the symsrv protocol. Visual Studio Team Foundation Server and the Debugging Tools for Windows are two tools that can use symbol servers.
      Symbol servers you might use include:
      Public Microsoft Symbol Servers: To debug a crash that occurs during a call to a system DLL or to a third-party library, you often need system .pdb files. System .pdb files contain symbols for Windows DLLs, .exe files, and device drivers. You can get symbols for Windows operating systems, MDAC, IIS, ISA, and .NET from the public Microsoft Symbol Servers.
      Symbol servers on an internal network or on your local machine: Your team or company can create symbol servers for your own products, and as a cache for symbols from external sources. You might have a symbol server on your own machine.
      Third-party symbol servers: Third-party providers of Windows applications and libraries can provide access to symbol server on the internet.

Warning

If you use a symbol server other than the public Microsoft Symbol Servers, make sure that the symbol server and its path are trustworthy. Because symbol files can contain arbitrary executable code, you can be exposed to security threats.

Configure location of symbol files and loading options

The debugger checks various locations for symbols by default. For more information, see Where the debugger looks for symbols.

From the Tools (or Debug) > Options menu, you can access the Debugging > Symbols options:

To specify symbol locations and loading options:

  1. Open the Tools (or Debug) > Options pane, and expand the All Settings > Debugging > General > Symbols > Search Locations section.

  2. In the right pane, select the checkbox for each desired server: Microsoft Symbol Servers, NuGet.org Symbol Server, and so on.

  3. Add a new symbol server location by selecting + Add in the toolbar for the Symbol file (.pdb) locations group box.
    Enter the URL (http), network share, or local path of the symbol server or symbol location in the text field. Statement completion helps you find the correct format.
    Screenshot that shows how to add a new symbol server location in Visual Studio.
    Note
    Only the specified folder is searched. You must add entries for any subfolders that you want to search.
    Select the Enabled checkbox, and then select Save.

  4. Add an Azure DevOps Symbol Server location by selecting the New Azure DevOps Symbol Server location link.
    In the Connect to Azure DevOps Symbol Server dialog, select an available symbol server, and then select Connect.
    Screenshot that shows how to add a new Azure DevOps Symbol Server location in Visual Studio.
    For more information, see Add Azure Artifacts symbol server.

    • To change the loading order for the symbol locations, use Ctrl + Up and Ctrl + Down, or select Move up and Move down.
    • To edit a URL or path, double-click the entry, or highlight the entry and select Edit.
    • To remove an entry, highlight the entry, and select Remove.
  5. Open the Tools (or Debug) > Options dialog, and expand the Debugging > Symbols section.

  6. In the Symbol file (.pdb) search locations group box, select the checkbox for each desired server: Microsoft Symbol Servers, NuGet.org Symbol Server, and so on.

  7. Add a new symbol server location by selecting New Location (+) in the toolbar for the Symbol file (.pdb) search locations group box.
    Enter the URL (http), network share, or local path of the symbol server or symbol location in the text field. Statement completion helps you find the correct format.
    Screenshot that shows how to add a new symbol server location.
    Note
    Only the specified folder is searched. You must add entries for any subfolders that you want to search.

  8. Add a new Azure DevOps Symbol Server location by selecting New Azure DevOps Symbol Server Location in the group box toolbar.
    In the Connect to Azure DevOps Symbol Server dialog, select an available symbol server, and then select Connect.
    For more information, see Add Azure Artifacts symbol server.

    • To change the loading order for the symbol locations, use Ctrl + Up and Ctrl + Down, or select the Up and Down actions.
    • To edit a URL or path, double-click the entry, or highlight the entry and press F2.
    • To remove an entry, highlight it, and select Remove Location (-).
  9. (Optional) Improve symbol loading performance by specifying a local folder path for copied symbols.
    For the Cache symbols in this directory option, enter a local folder path that symbol servers can copy symbols to.
    Note

    • Don't place the local symbol cache in a protected folder, such as C:\Windows or a subfolder. Use a read-write folder instead.
    • If the _NT_SYMBOL_PATH environment variable is set, the value overrides the Cache symbols in this directory value.
  10. Specify the modules for the debugger to load from the symbol file (.pdb) locations when it starts.

    1. Change to the All Settings > Debugging > General > Symbols > Search and Load section.
    2. Use the dropdown list to set the value of the Automatic symbol searching option:
      • Automatically choose what module symbols to search for (recommended): Allow Visual Studio to decide what symbols to search for and load. By default, Visual Studio automatically loads symbols built by your opened solution, and loads any other symbols required to perform common debugging operations. This option reduces the number of files that must be searched for and loaded by Visual Studio, which improves debugger performance. You can force other symbols to load by creating the list of Included modules.
        Screenshot that shows how to select and configure the Automatically choose what module symbols to search for option.
      • Search for all module symbols unless excluded: Force Visual Studio to load all symbols in your debugged process. This option isn't recommended because it can slow down your debugging experience. You can force Visual Studio to ignore certain symbols by creating the list of Excluded modules.
        Screenshot that shows how to select and configure the Search for all module symbols unless excluded option.

In the Debugging > Symbols section, select the value of the Symbol search preferences option:
Screenshot that shows how to select and configure the Symbol search preferences option.

  1. To apply your settings, select OK.

Specify module filters

Both the Automatically choose ... and Search for all ... options allow you to control what symbols are searched for during debugging.

For the Automatically choose what module symbols to search for option, specify the search list by creating the Included modules list.

Screenshot that shows how to create the list of included modules.

  1. Select + Add in the list toolbar.
  2. In the Add Item dialog, enter the Module Name, select the Enabled checkbox, and then select Save.
  3. Add more items to the list, as needed.

Specify the search list by selecting the Specify module filters link:

Screenshot that shows how to select the Specify module filters link.

For the Automatically choose what module symbols to search for option, the Automatic symbol search preferences dialog opens:

Screenshot of specifying module filters.

To create the Modules filter list, select New Module (+), enter the new modules, and then select OK.

Module filters support simple wild-card matching. The asterisk * matches any group of characters. For example, *myproduct* matches files such as myproduct.utilities.dll and entrypoint.myproduct.exe, among others.

You can configure other options to customize your experience:

For the Search for all module symbols, unless excluded option, specify the search list by creating the Excluded modules list.

Screenshot that shows how to create the list of excluded modules.

  1. Select + Add in the list toolbar.
  2. In the Add Item dialog, enter the Module Name, select the Enabled checkbox, and then select Save.
  3. Add more items to the list, as needed.

For the Search for all module symbols unless excluded option, the Symbol exclusion preferences dialog opens:

Screenshot of specifying excluded modules.

To create the Modules filter list, select New Module (+), enter the new modules, and then select OK.

In this dialog, you can choose what modules you don't want Visual Studio to load symbols for. In this scenario, Visual Studio attempts to load symbols for every module in your debugged process (including modules by non-Microsoft parties), unless you add a matching filter to exclude them. The only other way this behavior can be modified is by your Just My Code settings.

Other symbol options for debugging

You can select more debugging symbol options from the Tools (or Debug) > Options menu.

The following settings are available in the All Settings > Debugging > General section.

The following settings are available in the Debugging > General section.

Compiler symbol options

When you build a project from the Visual Studio IDE with the standard Debug build configuration, the C++ and managed compilers create the appropriate symbol files for your code. You can also set compiler options in code.

To set the compiler options for your build configurations in Visual Studio, see Set debug and release configurations.

.NET options

Build with /debug to create a .pdb file. You can build applications with /debug:full or /debug:pdbonly. Building with /debug:full generates debuggable code. Building with /debug:pdbonly generates .pdb files, but doesn't generate the DebuggableAttribute that tells the JIT compiler that debug information is available. Use /debug:pdbonly if you want to generate .pdb files for a release build that you don't want to be debuggable. For more information, see /debug (C# compiler options) or /debug (Visual Basic).

C/C++ options

Web applications

Set the web.config file of your ASP.NET application to debug mode. Debug mode causes ASP.NET to generate symbols for dynamically generated files and enables the debugger to attach to the ASP.NET application. Visual Studio sets this automatically when you start to debug, if you created your project from the web projects template.

Load symbols while debugging

You can use the Modules, Call Stack, Locals, Autos, or any Watch window to load symbols or change symbol options while debugging. For more information, see Get more familiar with how the debugger attaches to your app.

Work with symbols in the Modules window

During debugging, the Modules window shows the code modules the debugger is treating as user code, or My Code, and their symbol loading status. You can also monitor symbol loading status, load symbols, and change symbol options in the Modules window.

To monitor or change symbol locations or options while debugging:

  1. To open the Modules window, while debugging, select Debug > Windows > Modules (or press Ctrl + Alt + U).
  2. In the Modules window, right-click the Symbol Status or Symbol File headers, or any module.
  3. In the context menu, select one of the following options:
    Option Description
    Load Symbols Appears for modules with skipped, not found, or not loaded symbols. Attempts to load symbols from locations specified in the Tools > Options pane under the All Settings > Debugging > Symbols > Search and Load or Search Locations sections. If the symbol file isn't found or not loaded, launches File Explorer so you can specify a new location to search.
    Symbol Load Information Shows the location of a loaded symbol file, or the locations that were searched if the debugger can't find the file.
    Symbol Settings Opens the Tools > Options pane to the All Settings > Debugging > Symbols > Search Locations section, where you can edit and add symbol locations.
    Always Load Automatically Adds the selected symbol file to the list of files that are automatically loaded by the debugger.
    Decompile Source to Symbol File For .NET code, you can choose this option and then follow instructions in Generate and embed sources for an assembly.
    Option Description
    ----------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Load Symbols Appears for modules with skipped, not found, or not loaded symbols. Attempts to load symbols from locations specified on the Tools > Options dialog under the Debugging > Symbols section. If the symbol file isn't found or not loaded, launches File Explorer so you can specify a new location to search.
    Symbol Load Information Shows the location of a loaded symbol file, or the locations that were searched if the debugger can't find the file.
    Symbol Settings Opens the Tools > Options dialog to the Debugging > Symbols section, where you can edit and add symbol locations.
    Always Load Automatically Adds the selected symbol file to the list of files that are automatically loaded by the debugger.
    Decompile Source to Symbol File For .NET code, you can choose this option and then follow instructions in Generate and embed sources for an assembly.

Use the No Symbols Loaded/No Source Loaded pages

There are several ways for the debugger to break into code that doesn't have symbol or source files available:

When this happens, the debugger displays the No Symbols Loaded or No Source Loaded pages to help you find and load the necessary symbols or source.

Screenshot of the No Symbols Loaded page.

To use the No Symbols Loaded document page to help find and load missing symbols:

If the debugger finds the .pdb file after you execute one of the options, and can retrieve the source file using the information in the .pdb file, it displays the source. Otherwise, it displays a No Source Loaded page that describes the issue, with links to actions that might resolve the issue.

To add source file search paths to a solution:

You can specify the locations the debugger searches for source files, and exclude specific files from the search.

  1. Select the solution in Solution Explorer, and then select the Properties icon, press Alt+Enter, or right-click and select Properties.
  2. Select Debug Source Files.
    Debug source files page
  3. Under Directories containing source code, type or select source code locations to search. Use the New Line icon to add more locations, the Up and Down arrow icons to reorder them, or the X icon to delete them.
    Note
    The debugger searches only the specified directory. You must add entries for any subdirectories that you want to search.
  4. Under Do not look for these source files, type the names of source files to exclude from search.
  5. Select OK or Apply.