How do I merge multiple PDB files?

前端 未结 4 1023
太阳男子
太阳男子 2020-12-15 10:48

We are currently using a single command line tool to build our product on both Windows and Linux.

Si far its works nicely, allowing us to build out of source and wit

相关标签:
4条回答
  • 2020-12-15 11:20

    Merge PDB files are possible but only can be done by cl.exe and link.exe. I do NOT know any standlone tools to merge PDB files.

    You can use /PDB option to linker(I checked VC2005) to specify alternate pdb file name.

    Microsoft suggests to also include PDB files(each obj has a corresponding PDB file) along with .LIB file.

    You cannot archive PDB files inside .LIB file, I've tried it with VC2003, failed.

    Compile with /Z7 can avoid PDB files for .LIB, but object files are large, unless the link.exe strip the debug information. If you have no /debug option to linker, then your exe/dll cannot be debugged.

    Compiler(cl.exe) always write to vcXX.pdb file unless you use /Fd option to specify another name. Even when you use cl.exe to produce an executable "directly", It'll produce a vc80.pdb file and then the link.exe will produce the pdb file name same as the executable.

    cl /Zi test.c

    cl.exe -> vc80.pdb link.exe read vc80.pdb(the name is embedded in test.obj file) -> test.pdb

    Each time cl /Zi /c compile a file, it'll try to modify the existing vcXX.pdb file instead of overwrite it.

    I got the above conslusion by play with the compiler again and again, then capture sysinternals's procexp result and analyze it. Hope it helps.

    0 讨论(0)
  • 2020-12-15 11:26

    Unless you want to redistribute the static libraries with debug info, you don't actually need to merge any PDB files (or use /Z7 to embed the debug info).

    As @zhaorufei mentioned, when using /Zi, each object file contains a reference to its PDB file, which the linker then uses.

    Simply use /Fd to give each object a unique PDB file:

    > cl -c foo.cpp -Fo:target/foo.obj -Fd:target/foo.pdb -Zi
    > cl -c bar.cpp -Fo:target/bar.obj -Fd:target/bar.pdb -Zi
    
    > strings target/foo.obj | grep pdb
    D:\Dev\sample\target\foo.pdb
    > strings target/bar.obj | grep pdb
    D:\Dev\sample\target\bar.pdb
    

    This also has the benefit that it works around the issues of concurrent access to shared PDB files mentioned here, so you can parallelize the compile step like you wanted.

    Then link/archive the object files as usual. VC++ already embeds various kinds of information in the object files to pass them to the linker, such as the runtime link setting and dependency libraries - the PDB file path is no different. Creating a static library from the objects does not remove the references:

    > lib -out:target/all.lib target/foo.obj target/bar.obj
    > strings target/all.lib | grep pdb
    D:\Dev\sample\target\bar.pdb
    D:\Dev\sample\target\foo.pdb
    

    When linking this library to an executable or DLL, the linker still pulls in the debug info from the referenced PDBs and adds it to the final PDB file.

    The only caveat I can see is that the path is always absolute, so this may not work if you move the files around locally or to another machine before linking.

    0 讨论(0)
  • 2020-12-15 11:38

    No need to merge PDB files.

    Compile source files with /Z7 to avoid creating a PDB during the CL.EXE steps.

    Use LIB.EXE to create static libaries with embedded debugging information. Use LINK.EXE instead of CL.EXE to link, use /PDB to specify where the debugging information goes.

    If you are debugging a process with an EXE and one or more DLLs, feed your debugger a PDB for each image (EXE or DLL).

    0 讨论(0)
  • 2020-12-15 11:43

    I've not done C++ for a long time but from this article, it appears that this is a performance trick to stop the recreation of symbols for common headers.

    You could try /Z7 to embed info in each obj, and not create a PDB and then link and recreate it with a rebase as in this article.

    0 讨论(0)
提交回复
热议问题