Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

Debugging the Swift Toolchain

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.

Prerequisites

  1. From swift.org/download, download and install both:
  2. Clone the Swift repo

Setup

  1. Select the desired toolchain in Xcode's Settings: Components > Toolchains
  2. From the swift-source/swift directory, run:
    • git fetch --tags
    • git checkout swift-5.2.1-RELEASE

Source Paths

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.

Find the Debugging Symbols Root Directory

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.

Customize LLDB target.source-map

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment