swiftwasm/swift

Variable Inspection in Debugger

Closed this issue · 2 comments

Motivation

We have been supporting source-level debugging of Swift code in Chrome DevTools, but it doesn't support inspecting local variables on the paused call frame while it's supported in C/C++ Wasm binaries.

Preliminary Investigation

The Chrome DevTools extension extends the DevTools to interpret DWARF debug information embedded in WebAssembly binary. Because parsing & interpretation DWARF are well-known to be quite hard, they are porting existing native debugger implementation (LLDB, which is a part of LLVM project written in C++). The porting of the native debugger is done by Emscripten toolchain.

The variable inspection feature is done not only by DWARF information but also by cooperating with in-process compilers to know how the binary is code-generated and where member fields are placed in. So this means the DevTools extension ported not only the native debugger but also ported a part of Clang compiler.

Implementation Plan

Based on the preliminary investigation, we concluded what we need to integrate to the extension are:

  • TypeSystemSwift, which bridges debugger and in-process Swift compiler
  • A part of Swift compiler
  • Build a part of Swift compiler using Emscripten
    • swiftAST
    • swiftASTSectionImporter
    • swiftBasic
    • swiftClangImporter
    • swiftFrontend
    • swiftIDE
    • swiftParse
    • swiftRemoteAST
    • swiftRemoteInspection
    • swiftSIL
    • swiftSILOptimizer
    • swiftSerialization
  • Build Swift-related LLDB components using Emscripten
    • lldbPluginSwiftLanguage
    • lldbPluginSwiftLanguageRuntime
    • lldbPluginTypeSystemSwift
    • lldbPluginExpressionParserSwift
  • Install TypeSystemSwiftTypeRef to the SymbolBackend's DefaultPluginsContext
  • Make variable formatting work
    • Read reflection information from Wasm data segments
  • Make swift::reflection::ReflectionContext work with Wasm object format for debugging purpose

Upstreaming

swiftlang/swift