简体   繁体   中英

Visual Studio. How to build DLL (in commandline) that debugging works by attaching to process?

Visual Studio. How to build DLL (in commandline) that debugging works by attaching to process ? As far as I know, here's what I am doing.

To build *.cpp files, I put these flags cl /Zi /Od

To make DLL, I put these link /DEBUG

I have tens of cpp files that later get made into DLL. But attaching to process debugging does not work...

Do I have to put more flags ? How do I check the DLL itself if it has sufficient debugging information or not ?

Thanks!

Do you have a PDB file for the DLL? Does it contain the debug information for all the objs? Are you compiling the files with cl /c also other than options mentioned below. Are your results of your compiling - the objs copied somewhere before you link them. Are the pdbs also copied?

These are various reasons causing your issue

  1. You are copying the objs to some directory before linking them. The pdbs aren't accessible while linking.
  2. Some clean up before linking causes deletion of the PDB.

Assuming you have 3 files a.cpp, b.cpp & c.cpp, this is what you can try

cl /c /Zi /Fd c:\mypath\mydll.pdb a.cpp
cl /c /Zi /Fd c:\mypath\mydll.pdb b.cpp
cl /c /Zi /Fd c:\mypath\mydll.pdb c.cpp

link /DEBUG fullpathtoa\a.obj fullpathtob\b.obj fullpathtob\c.obj whatever other options.

Then copy the pdb and dll both & try debugging it.

Another thing is that in most debuggers, you have a dialog box which shows all the binaries which are loaded and the corresponding PDBs which are loaded.

For eg.

Binary      PDB
a.exe       c:\abc\a.pdb
b.dll       c:\pqr\b.pdb
c.dll       Default symbols loaded.

The default symbols loaded means it didn't find the PDB. You can right click etc & point the debugger to the path of the PDB corresponding to c.pdb

In Visual Studio, you will see the above in Debug Menu Option-->Windows-->Modules. The 'Symbol Status' column will show the path of the PDB or 'Default Symbols Loaded'. What does it show for your dll?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM