Generate PDB files for better debugging on Windows (#16008)
authorpeter <peterghost86@gmail.com>
Thu, 17 Jan 2019 07:31:57 +0000 (23:31 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 17 Jan 2019 07:34:32 +0000 (23:34 -0800)
commitf7733526aa84af9001fe024117cc66221f9df85e
treeebfcb94fd6d62973eeb0486067a0f4e4e5a49860
parent0dfdc2cbdb71b5a8dcac0c3e6cc59b74ad2b30dc
Generate PDB files for better debugging on Windows (#16008)

Summary:
1. Unify `build_pytorch_libs.bat`, `setup.py` and `torch/CMakeLists.txt` on the debugging flags with the `CMAKE_BUILD_TYPE` being `Debug`, `Release` and `RelWithDebInfo`.
2. Install PDBs through CMake if they are generated.

Reference:
1. CMake PDB install: https://gitlab.kitware.com/cmake/cmake/issues/18393#note_459199
2. About debugging flags https://stackoverflow.com/a/4662345
3. MSDN page about /DEBUG flag: https://docs.microsoft.com/en-us/cpp/build/reference/debug-generate-debug-info?view=vs-2017
4. MSDN page about /Z{i/I/7}: https://docs.microsoft.com/en-us/cpp/build/reference/z7-zi-zi-debug-information-format?view=vs-2017

Work to do:
- [x] Test the changes work in Release config through this PR
- [ ] <del> Test debug build through https://github.com/pytorch/pytorch/pull/16009 </del>
- [x] Test release build with debugging symbols through #16013

Difficulties:
- [x] Replace /Zi flags with /Z7 (which will be added if DEBUG or RelWithDebInfo is used), as it is not supported by sccache
- [x] Resolve `LINK : fatal error LNK1210: exceeded internal ILK size limit; link with /INCREMENTAL:NO` in the debug build
- [ ] DEBUG build blocked by a MSVC bug. In order to resolve it, we'll need to update the MSVC in CI: https://developercommunity.visualstudio.com/content/problem/225957/fatal-error-lnk1318-unexpected-pdb-error-ok-0.html
Pull Request resolved: https://github.com/pytorch/pytorch/pull/16008

Differential Revision: D13709527

Pulled By: ezyang

fbshipit-source-id: e8365bc75d9ec64099093f7001f83d99a06b196b
13 files changed:
CMakeLists.txt
c10/CMakeLists.txt
c10/cuda/CMakeLists.txt
caffe2/CMakeLists.txt
cmake/Dependencies.cmake
cmake/ProtoBuf.cmake
modules/detectron/CMakeLists.txt
modules/module_test/CMakeLists.txt
modules/observers/CMakeLists.txt
setup.py
tools/build_pytorch_libs.bat
torch/CMakeLists.txt
torch/lib/libshm_windows/CMakeLists.txt