Use these steps to debug components of the Swift toolchain. This allows you to see Swift's source code from the debugger – instead of disassembly. The debugger can also provide some variable names and values. This has been initially tested with libswiftCore.dylib.
These instructions were updated as of Swift 5.2.1.
- From swift.org/download, download and install both:
- Xcode Toolchain
- The toolchain's Debugging Symbols
- Clone the Swift repo
- Select the desired toolchain in Xcode's Settings:
Components > Toolchains - From the
swift-source/swiftdirectory, run:git fetch --tagsgit checkout swift-5.2.1-RELEASE
The installed debugging symbols contains paths that don't exist on your computer. LLDB can be configured to find paths that don't exist using its target.source-map setting.
From the .dSYM debugging symbols, use dwarfdump to find the source paths as they originally existed during the build. Use grep to filter for DW_AT_decl_file. In this example, grep will print only the first 10 matches.
dsym=/Library/Developer/Toolchains/swift-5.2.1-RELEASE.xctoolchain/usr/bin/swift.dSYM
dwarfdump "$dsym" | grep -m10 DW_AT_decl_file
This will produce output that looks like:
DW_AT_decl_file ("/Users/buildnode/jenkins/workspace/oss-swift-5.2-package-osx/llvm-project/llvm/include/llvm/ADT/None.h")
DW_AT_decl_file ("/Users/buildnode/jenkins/workspace/oss-swift-5.2-package-osx/llvm-project/llvm/include/llvm/ADT/Twine.h")
...
From this, the root on the build machine was /Users/buildnode/jenkins/workspace/oss-swift-5.2-package-osx.
Lastly, edit your ~/.lldbinit and configure the target.source-map setting. This maps the source path from the debugging symbols to the path of swift-source on your computer.
settings append target.source-map /Users/buildnode/jenkins/workspace/oss-swift-5.2-package-osx /Users/kastiglione/src/swift-source
