From 2842260c8282c8ade33bf483ddf7348bcbba2f91 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Thu, 14 Aug 2025 19:38:19 -0700 Subject: [PATCH] [LLDB] Add Swift support for WebAssembly --- .../Swift/LLDBMemoryReader.cpp | 5 +++- .../LanguageRuntime/Swift/LLDBMemoryReader.h | 4 +++ .../Swift/SwiftLanguageRuntime.cpp | 28 ++----------------- 3 files changed, 11 insertions(+), 26 deletions(-) diff --git a/lldb/source/Plugins/LanguageRuntime/Swift/LLDBMemoryReader.cpp b/lldb/source/Plugins/LanguageRuntime/Swift/LLDBMemoryReader.cpp index ecf7f3a4caf9f..6b3e8ec652a91 100644 --- a/lldb/source/Plugins/LanguageRuntime/Swift/LLDBMemoryReader.cpp +++ b/lldb/source/Plugins/LanguageRuntime/Swift/LLDBMemoryReader.cpp @@ -144,7 +144,7 @@ LLDBMemoryReader::getSymbolAddress(const std::string &name) { load_addr, swift::remote::RemoteAddress::DefaultAddressSpace); } -static std::unique_ptr +std::unique_ptr GetSwiftObjectFileFormat(llvm::Triple::ObjectFormatType obj_format_type) { std::unique_ptr obj_file_format; switch (obj_format_type) { @@ -157,6 +157,9 @@ GetSwiftObjectFileFormat(llvm::Triple::ObjectFormatType obj_format_type) { case llvm::Triple::COFF: obj_file_format = std::make_unique(); break; + case llvm::Triple::Wasm: + obj_file_format = std::make_unique(); + break; default: LLDB_LOG(GetLog(LLDBLog::Types), "Could not determine swift reflection " "section names for object format type"); diff --git a/lldb/source/Plugins/LanguageRuntime/Swift/LLDBMemoryReader.h b/lldb/source/Plugins/LanguageRuntime/Swift/LLDBMemoryReader.h index 2eef7c3bcec62..a42f503ad07cc 100644 --- a/lldb/source/Plugins/LanguageRuntime/Swift/LLDBMemoryReader.h +++ b/lldb/source/Plugins/LanguageRuntime/Swift/LLDBMemoryReader.h @@ -24,6 +24,10 @@ #include "llvm/Support/Memory.h" namespace lldb_private { + +std::unique_ptr +GetSwiftObjectFileFormat(llvm::Triple::ObjectFormatType obj_format_type); + class LLDBMemoryReader; class MemoryReaderLocalBufferHolder { public: diff --git a/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp index 32221809729a3..f8207ee6e679c 100644 --- a/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp +++ b/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp @@ -295,28 +295,6 @@ CreateExceptionResolver(const lldb::BreakpointSP &bkpt, bool catch_bp, bool thro return resolver_sp; } -static std::unique_ptr -GetObjectFileFormat(llvm::Triple::ObjectFormatType obj_format_type) { - std::unique_ptr obj_file_format; - switch (obj_format_type) { - case llvm::Triple::MachO: - obj_file_format = std::make_unique(); - break; - case llvm::Triple::ELF: - obj_file_format = std::make_unique(); - break; - case llvm::Triple::COFF: - obj_file_format = std::make_unique(); - break; - default: - if (Log *log = GetLog(LLDBLog::Types)) - log->Printf("%s: Could not find out swift reflection section names for " - "object format type.", - __FUNCTION__); - } - return obj_file_format; -} - static bool HasReflectionInfo(ObjectFile *obj_file) { if (!obj_file) return false; @@ -332,7 +310,7 @@ static bool HasReflectionInfo(ObjectFile *obj_file) { const auto obj_format_type = obj_file->GetArchitecture().GetTriple().getObjectFormat(); - auto obj_file_format_up = GetObjectFileFormat(obj_format_type); + auto obj_file_format_up = GetSwiftObjectFileFormat(obj_format_type); if (!obj_file_format_up) return false; @@ -561,7 +539,7 @@ bool SwiftLanguageRuntime::AddJitObjectFileToReflectionContext( llvm::SmallVector likely_module_names) { assert(obj_file.GetType() == ObjectFile::eTypeJIT && "Not a JIT object file!"); - auto obj_file_format = GetObjectFileFormat(obj_format_type); + auto obj_file_format = GetSwiftObjectFileFormat(obj_format_type); if (!obj_file_format) return false; @@ -607,7 +585,7 @@ std::optional SwiftLanguageRuntime::AddObjectFileToReflectionContext( auto obj_format_type = module->GetArchitecture().GetTriple().getObjectFormat(); - auto obj_file_format = GetObjectFileFormat(obj_format_type); + auto obj_file_format = GetSwiftObjectFileFormat(obj_format_type); if (!obj_file_format) return {};