Skip to content

Commit

Permalink
[swift] Add Swift support to LLDB for WebAssembly
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed Feb 20, 2025
1 parent d588930 commit aea3c02
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
gclient-condition = build_with_chromium == False
[submodule "extensions/cxx_debugging/third_party/llvm/src"]
path = extensions/cxx_debugging/third_party/llvm/src
url = https://chromium.googlesource.com/external/github.com/llvm/llvm-project
url = https://github.com/kateinoigakukun/llvm-project.git
gclient-condition = checkout_cxx_debugging_extension_deps == True
[submodule "extensions/cxx_debugging/third_party/lldb-eval/src"]
path = extensions/cxx_debugging/third_party/lldb-eval/src
Expand All @@ -26,3 +26,6 @@
path = third_party/inspector_protocol
url = https://chromium.googlesource.com/deps/inspector_protocol
gclient-condition = build_with_chromium == False
[submodule "extensions/cxx_debugging/third_party/swift/src"]
path = extensions/cxx_debugging/third_party/swift/src
url = https://github.com/kateinoigakukun/swift.git
11 changes: 11 additions & 0 deletions extensions/cxx_debugging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,20 @@ endif()
if (CXX_DEBUGGING_BUILD_WASM)
set(LLVM_ENABLE_RTTI "ON" CACHE STRING "")
set(LLVM_ENABLE_THREADS "OFF" CACHE STRING "")
set(LLVM_ENABLE_LIBEDIT "OFF" CACHE STRING "")

set(LLVM_EXTERNAL_SWIFT_SOURCE_DIR "${THIRD_PARTY_DIR}/swift/src" CACHE STRING "")
set(LLVM_EXTERNAL_PROJECTS "swift" CACHE STRING "")
set(SWIFT_ENABLE_DISPATCH "OFF" CACHE STRING "")
set(SWIFT_BUILD_SOURCEKIT "OFF" CACHE STRING "")
set(SWIFT_HOST_VARIANT_SDK "EMSCRIPTEN" CACHE STRING "")
set(SWIFT_HOST_VARIANT_ARCH "wasm32" CACHE STRING "")
set(SWIFT_INCLUDE_TESTS "OFF" CACHE STRING "")
add_compile_options(-fdeclspec)
else()
set(LLVM_ON_WIN32 0)
set(LLVM_ON_UNIX 1)
set(LLDB_ENABLE_SWIFT_SUPPORT "OFF" CACHE STRING "")
endif()


Expand Down
5 changes: 5 additions & 0 deletions extensions/cxx_debugging/ports/cmark-gfm-config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(cmark-gfm_FOUND TRUE)
set(cmark-gfm_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/include")
set(cmark-gfm_LIBRARIES)

add_library(libcmark-gfm INTERFACE)
4 changes: 4 additions & 0 deletions extensions/cxx_debugging/src/SymbolsBackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "WasmVendorPlugins.h"

#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
#include "Plugins/Language/Swift/SwiftLanguage.h"
#include "Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h"
#include "Plugins/ObjectFile/wasm/ObjectFileWasm.h"
#include "Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h"
#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
Expand All @@ -33,6 +35,8 @@ struct DefaultPluginsContext
lldb_private::FileSystem,
lldb_private::CPlusPlusLanguage,
lldb_private::TypeSystemClang,
lldb_private::SwiftLanguage,
lldb_private::TypeSystemSwiftTypeRef,
lldb_private::wasm::ObjectFileWasm,
lldb_private::wasm::SymbolVendorWasm,
symbols_backend::WasmProcess,
Expand Down
4 changes: 4 additions & 0 deletions extensions/cxx_debugging/src/SymbolsBackend.cc.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "WasmVendorPlugins.h"

#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
#include "Plugins/Language/Swift/SwiftLanguage.h"
#include "Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h"
#include "Plugins/ObjectFile/wasm/ObjectFileWasm.h"
#include "Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h"
#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
Expand All @@ -33,6 +35,8 @@ struct DefaultPluginsContext
lldb_private::FileSystem,
lldb_private::CPlusPlusLanguage,
lldb_private::TypeSystemClang,
lldb_private::SwiftLanguage,
lldb_private::TypeSystemSwiftTypeRef,
lldb_private::wasm::ObjectFileWasm,
lldb_private::wasm::SymbolVendorWasm,
symbols_backend::WasmProcess,
Expand Down
2 changes: 1 addition & 1 deletion extensions/cxx_debugging/third_party/llvm/src
Submodule src updated 581 files
1 change: 1 addition & 0 deletions extensions/cxx_debugging/third_party/swift/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
file://config/owner/INFRA_OWNERS
13 changes: 13 additions & 0 deletions extensions/cxx_debugging/third_party/swift/README.chromium
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Name: The Swift Programming Language
Short Name: swift
URL: https://github.com/swiftlang/swift
Version: N/A
Date: TODO
Revision: TODO
License: Apache 2.0 with LLVM Exceptions
License File: src/LICENSE.TXT
Shipped: no
Security Critical: no
Description: The Swift project produces a compiler, standard library, and other tools for developing software in the Swift programming language. In order to achieve ABI stability and debuggability, programs produced by the Swift compiler contain type layout information in its own metadata sections instead of the standard DWARF format. This metadata is used by both the Swift runtime and LLDB to inspect objects at runtime.

In the DevTools debugging extension, a part of the Swift project is used to read such metadata through LLDB's Swift language plugin.
1 change: 1 addition & 0 deletions extensions/cxx_debugging/third_party/swift/src
Submodule src added at 22c48b
5 changes: 5 additions & 0 deletions extensions/cxx_debugging/tools/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,17 @@ def stage2(source_dir, stage1_dir, OPTIONS):
}
cmake_args = [
OPTIONS.cmake, OPTIONS.extension_source, *CMAKE_DEFAULTS,
# ABI check must be turned off when building with -DNDEBUG
'-DLLVM_ABI_BREAKING_CHECKS=FORCE_OFF',
'-DCMAKE_CXX_FLAGS_RELWITHDEBINFO=-O1 -g -DNDEBUG',
'-DCMAKE_C_FLAGS_RELWITHDEBINFO=-O1 -g -DNDEBUG',
'-DCMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO=-O1 -g -DNDEBUG -gseparate-dwarf',
'-DCMAKE_CXX_FLAGS_DEBUG=-O0 -g -DNDEBUG',
'-DCMAKE_EXE_LINKER_FLAGS_DEBUG=-O0 -g -gseparate-dwarf',
'-DCMAKE_EXE_LINKER_FLAGS=-sERROR_ON_UNDEFINED_SYMBOLS=0',
'-DHAVE_POSIX_REGEX=0', '-Derrc_exit_code=0',
'-DHAVE_SIGALTSTACK=0',
'-Dcmark-gfm_DIR={}'.format(os.path.join(source_dir, 'ports')),
'-Derrc_exit_code__TRYRUN_OUTPUT=0',
'-DCMAKE_BUILD_TYPE={build_type}'.format(**cmake_settings),
'-DCMAKE_TOOLCHAIN_FILE={toolchain_file}'.format(**cmake_settings),
Expand Down

0 comments on commit aea3c02

Please sign in to comment.