Skip to content

Instantly share code, notes, and snippets.

@roop
Last active January 21, 2020 06:55
Show Gist options
  • Save roop/94308a77aed665ed666d0d2472d3eec5 to your computer and use it in GitHub Desktop.
Save roop/94308a77aed665ed666d0d2472d3eec5 to your computer and use it in GitHub Desktop.
Notes on debugging on the Swift compiler

Invoking lldb

  • swiftc invokes sub-commands, so you shouldn't run lldb on the swiftc command itself. You can add the -### option to swiftc to see the underlying sub-commands. Pick the correct sub-command, then run lldb -- <command>.

  • Usually, we want the first command, so run something like:

    lldb -- `swiftc file.swift | head -n 1`
    
  • Use --one-line r to run immediately after loading, without having to set breakopints - great for debugging crashes

    lldb --one-line r -- `swiftc crash.swift | head -n 1`
    

Using lldb

  • When dumping a type, use type.dump(), not type->dump()

  • If you want to look inside llvm collections, you can't always dump them or see their size (possibly because the collection code is inlined). You can still iterate over it from the lldb shell:

    e -- for (auto item: collection) { item.dump(); printf("\n"); }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment