[Lldb-commits] [lldb] [lldb] Support building the Host library under Emscripten (PR #223169)
via lldb-commits
lldb-commits at lists.llvm.org
Sat Sep 12 12:57:39 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Anutosh Bhat (anutosh491)
<details>
<summary>Changes</summary>
This is a small follow-up to #<!-- -->223162. Please refer to that PR for the broader motivation and the initial `liblldb` WebAssembly experiment.
Once the host platform was initialized correctly, I hit the next set of issues while building LLDB with Emscripten.
`HostInfo.h` already treats Emscripten like a Linux host, but the corresponding Linux host sources were not being included by CMake. We were also trying to build the fork-based Posix process launcher, which cannot work inside the browser.
This patch therefore:
- includes the existing Linux host sources for Emscripten;
- skips `ProcessLauncherPosixFork`;
- returns a clear unsupported error from `Host::LaunchProcess`;
- avoids compiling the duplicate fallback for `Host::FindProcessThreads`.
I’m not trying to make native process launching work in the browser through this patch. The immediate goal is to get `liblldb` compiling cleanly so it can be embedded and used for Wasm/DWARF inspection.
With these changes, my Emscripten-built `liblldb` can use the real LLDB SB API to load a Wasm binary with debug information, find its C++ symbols and source lines, inspect its sections, disassemble a function, and resolve a breakpoint by function name.
There is currently no upstream LLDB Emscripten CI configuration for testing this path, so I tested it manually through the working WebAssembly build.
---
Full diff: https://github.com/llvm/llvm-project/pull/223169.diff
3 Files Affected:
- (modified) lldb/source/Host/CMakeLists.txt (+7-2)
- (modified) lldb/source/Host/common/Host.cpp (+7-2)
- (modified) lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp (+1-1)
``````````diff
diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt
index ebcad8f63e4f3d..af63762e8e7ba4 100644
--- a/lldb/source/Host/CMakeLists.txt
+++ b/lldb/source/Host/CMakeLists.txt
@@ -111,10 +111,15 @@ else()
posix/LockFilePosix.cpp
posix/MainLoopPosix.cpp
posix/PipePosix.cpp
- posix/ProcessLauncherPosixFork.cpp
posix/Support.cpp
)
+ if (NOT EMSCRIPTEN)
+ add_host_subdirectory(posix
+ posix/ProcessLauncherPosixFork.cpp
+ )
+ endif()
+
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
add_subdirectory(macosx/objcxx)
set(LLDBObjCLibs lldbHostMacOSXObjCXX)
@@ -137,7 +142,7 @@ else()
endif()
- elseif (CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
+ elseif (CMAKE_SYSTEM_NAME MATCHES "Linux|Android|Emscripten")
add_host_subdirectory(linux
linux/AbstractSocket.cpp
linux/Host.cpp
diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp
index c4e1500fe68ab1..b9bda63f3832a0 100644
--- a/lldb/source/Host/common/Host.cpp
+++ b/lldb/source/Host/common/Host.cpp
@@ -67,7 +67,7 @@
#if defined(_WIN32)
#include "lldb/Host/windows/ConnectionGenericFileWindows.h"
#include "lldb/Host/windows/ProcessLauncherWindows.h"
-#else
+#elif !defined(__EMSCRIPTEN__)
#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
#endif
@@ -362,7 +362,7 @@ FileSpec Host::GetModuleFileSpecForHostAddress(const void *host_addr) {
#endif
-#if !defined(__linux__)
+#if !defined(__linux__) && !defined(__EMSCRIPTEN__)
bool Host::FindProcessThreads(const lldb::pid_t pid, TidMap &tids_to_attach) {
return false;
}
@@ -583,6 +583,10 @@ Status Host::RunShellCommand(llvm::StringRef shell_path, const Args &args,
// platforms
#if !defined(__APPLE__)
Status Host::LaunchProcess(ProcessLaunchInfo &launch_info) {
+#if defined(__EMSCRIPTEN__)
+ return Status::FromErrorString(
+ "launching a host process is not supported under Emscripten");
+#else
std::unique_ptr<ProcessLauncher> delegate_launcher;
#if defined(_WIN32)
delegate_launcher.reset(new ProcessLauncherWindows());
@@ -599,6 +603,7 @@ Status Host::LaunchProcess(ProcessLaunchInfo &launch_info) {
launch_info.SetProcessID(process.GetProcessId());
return error;
+#endif
}
#endif // !defined(__APPLE__)
diff --git a/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp b/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
index 799fe5eec29bcf..81ac8f0615e0e6 100644
--- a/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
+++ b/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
@@ -102,7 +102,7 @@ void PlatformLinux::Initialize() {
PlatformPOSIX::Initialize();
if (g_initialize_count++ == 0) {
-#if defined(__linux__) && !defined(__ANDROID__)
+#if (defined(__linux__) || defined(__EMSCRIPTEN__)) && !defined(__ANDROID__)
PlatformSP default_platform_sp(new PlatformLinux(true));
default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
Platform::SetHostPlatform(default_platform_sp);
``````````
</details>
https://github.com/llvm/llvm-project/pull/223169
More information about the lldb-commits
mailing list