Following Allow to specify specific files for debug info by albanD · Pull Request #111748 · pytorch/pytorch · GitHub being merged, there is a new compilation flag that can be used to specify debug informations ONLY for a given subset of the source files via:
# Your usual build BUILD_CONFIG python setup.py develop # Enable debug mode for two files BUILD_CONFIG python setup.py clean USE_CUSTOM_DEBINFO=torch/csrc/Module.cpp;aten/src/ATen/native/cpu/SortingKernel.cpp BUILD_CONFIG python setup.py develop
If you use ccache (as you should), this will only recompile these two files and relink the binary. You will now have full debug info for these files!
This has two main benefits: going from your usual build to enabling debug infos only recompiles the files you care about and the final binary only has bebug info for these two files. This means it won’t be gigabytes big and will not slow gdb to a crawl!
Side note, @malfet has another trick to do this if you don’t like the clean:
touch path/to/file.cpp; ninja -n >build.sh; sed '-O3/-g' build.sh; sh -f build.sh