Search code examples
c#c++visual-studiodebugging

Is there easily achievable debugging from Visual Studio with multiple symbols (stripped vs full)?


We're releasing an application to public, in which we don't want to include full symbols. So we're stripping them as mentioned in official docs (Debugging with symbols, PDBstripped). Both full and stripped symbols are correctly generated, we store full symbols in private location (share drive) and ship the product with stripped ones. So far all good.

Issue happens when we want to debug released app (i.e. crashdump) - we open the dump from Visual Studio and it automatically loads local symbols inclided with the application (the stripped version). Once we remove those (delete local pdbs), it will start searching the network path and properly loads correct full symbols from there = all that because local symbols weren't found.

Attaching generic VS's Options form, we're having our path correctly specified below "Microsoft Symbol Servers" and works:

Form with symbols path definition

Is there any way to override the behavior and load full symbols with priority? I.e. give local symbols lower priority than the ones from network location? Or can we somehow force search loading on network location when we have just stripped symbols?


Solution

  • Question:

    Can we somehow force search loading on network location when we have just stripped symbols?

    Short answer:

    Yes, "Visual Studio 2022" does just that. If it cannot find the full symbol file in the executable file path, it searches for the search paths specified in the "Symbols" section of "Debug Options" (Symbol file (.pdb) locations).

    To test, we perform the following steps (As you know):

    1- Create a "C++ Console App" project in "Visual Studio 2022".

    2- Put the following code in the main file.

    ConsoleApplicationCppPDB.cpp:

    #include <iostream>
    
    int main()
    {
        throw std::invalid_argument("It is an exception!");
    }
    

    3- In the Properties form for the project, specify the names of two symbol files in the "Linker" section.

    PDB Files

    4- In the "Options" submenu of "Debug", add the network path as a search path in "Symbol file (.pdb) locations", so that if "Visual Studio" does not find full symbols PDB file, it will search this path. We used the local folder path here, but a network path will probably work as well, as Microsoft explains here: "Type the URL (http), network share, or local path of the symbol server or symbol location"

    SearchPath

    5- Build the project and then run the project and when the exception is displayed, create the dump file using the "Save Dump As..." submenu from the "Debug" main menu.

    6- Copy the two symbol files from the path of the executable file to the search path "C:\[PDB]"

    7- In the program path, delete the full symbols file so that only strip symbols remain.

    8- By double-clicking on the dump file, open it with "Visual Studio" and use the "Debug with Native Only" operation. "Visual Studio" finds the error line.

    9- Remove the symbols file from the search path ("C:\[PDB]") and run the previous step again, "Visual Studio" can no longer find the error line. So the symbols PDB file was loaded from the search path.

    Note 1:

    The file name or path of full symbols and strip symbols must be different, otherwise an error will occur.

    Note 2:

    As you know, if possible, it's best not to give the client any symbol files if you don't want them to have the source code. In general, if the client gives us the dump file, we can debug according to the version of the client program and the PDB & EXE files and the source code (TFS or Git) that we have for that version. But maybe making a dump file with some tools also requires the PDB file.