[Lldb-commits] [lldb] [lldb] Support building the Host library under Emscripten (PR #223169)

Anutosh Bhat via lldb-commits lldb-commits at lists.llvm.org
Sat Sep 12 12:56:56 PDT 2026


https://github.com/anutosh491 created https://github.com/llvm/llvm-project/pull/223169

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.

>From 8e11de79b6f77ce851091621d60d5b6cf7362680 Mon Sep 17 00:00:00 2001
From: anutosh491 <andersonbhat491 at gmail.com>
Date: Sat, 12 Sep 2026 22:38:50 +0530
Subject: [PATCH 1/2] [lldb] Initialize the host platform under Emscripten

---
 lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp b/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
index 799fe5eec29bc..81ac8f0615e0e 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);

>From 11511d9d3e0eeb9cda8b1fae70294b315a63994b Mon Sep 17 00:00:00 2001
From: anutosh491 <andersonbhat491 at gmail.com>
Date: Sun, 13 Sep 2026 01:22:09 +0530
Subject: [PATCH 2/2] [lldb] Support building the Host library under Emscripten

---
 lldb/source/Host/CMakeLists.txt  | 9 +++++++--
 lldb/source/Host/common/Host.cpp | 9 +++++++--
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt
index ebcad8f63e4f3..af63762e8e7ba 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 c4e1500fe68ab..b9bda63f3832a 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__)
 



More information about the lldb-commits mailing list