[Lldb-commits] [lldb] [lldb] Initialize the host platform under Emscripten (PR #223162)

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


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



Hey @JDevlieghere, I’m not sure whether you’ve had a chance to see my [RFC: Embeddable LLVM tool drivers for long-lived hosts](https://discourse.llvm.org/t/rfc-embeddable-llvm-tool-drivers-for-long-lived-hosts/91754), but I’m working on [WasmBolt](https://github.com/anutosh491/WasmBolt) (try [here](https://anutosh21.github.io/WasmBolt/)) —essentially an attempt to bring a Godbolt-style LLVM playground into the browser, with the LLVM toolchain itself running through WebAssembly rather than a remote compilation server.

I’ve now started investigating LLDB support. The first milestone is to compile `liblldb` with Emscripten and use LLDB’s real SB API for static inspection of a WebAssembly binary entirely inside the browser process.

**The initial experiment is working**: the Emscripten-built LLDB can load a Wasm binary containing DWARF information, discover C++ symbols and source lines, inspect sections, disassemble functions, and resolve/set a breakpoint by function name.

While testing this, I found that LLDB did not initialize a host platform under Emscripten. `HostInfo` already treats Emscripten as using `HostInfoLinux`, but `PlatformLinux::Initialize()` only creates the corresponding host platform when `__linux__` is defined. This leaves the debugger without a selected platform and causes `CreateTarget` to fail when it checks the discovered Wasm architecture.

This patch extends that existing condition to `__EMSCRIPTEN__`. With the change, the same LLDB SB API program works without manually selecting a platform.

This is intended to be the **first of a few small patches** needed to make building and embedding `liblldb` under Emscripten cleanly supported. I’m keeping the patches separate so each change can be reviewed on its own.

There is currently no upstream LLDB Emscripten CI configuration that exercises this branch, so I validated it manually using an Emscripten-built `liblldb` and a Wasm binary compiled with debug information. Hope that's okay !

>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] [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);



More information about the lldb-commits mailing list