Author: Jonas Devlieghere Date: 2026-08-06T09:51:12-07:00 New Revision: bd586dd26e3ba49616175c14cb2970c581fb94b7
URL: https://github.com/llvm/llvm-project/commit/bd586dd26e3ba49616175c14cb2970c581fb94b7 DIFF: https://github.com/llvm/llvm-project/commit/bd586dd26e3ba49616175c14cb2970c581fb94b7.diff LOG: [lldb] Use the standard GDB remote thread for a non-Wasm process (#214380) CanDebug returns true whenever the plugin is requested by name, and the architecture is not known until the stub reports it after connecting. This means that a non-Wasm process can end up with a ThreadWasm whose register context and unwinder have nothing to operate on. Create the plain ThreadGDBRemote once the architecture is known, and add a helper so that the check covers wasm64 as well as wasm32. rdar://182229301 Added: Modified: lldb/source/Plugins/Process/wasm/ProcessWasm.cpp lldb/source/Plugins/Process/wasm/ThreadWasm.cpp lldb/test/API/functionalities/gdb_remote_client/TestWasm.py Removed: ################################################################################ diff --git a/lldb/source/Plugins/Process/wasm/ProcessWasm.cpp b/lldb/source/Plugins/Process/wasm/ProcessWasm.cpp index e119b3e3ecf6d..f7d744c967ea0 100644 --- a/lldb/source/Plugins/Process/wasm/ProcessWasm.cpp +++ b/lldb/source/Plugins/Process/wasm/ProcessWasm.cpp @@ -73,8 +73,7 @@ bool ProcessWasm::CanDebug(lldb::TargetSP target_sp, if (Module *exe_module = target_sp->GetExecutableModulePointer()) { if (ObjectFile *exe_objfile = exe_module->GetObjectFile()) - return exe_objfile->GetArchitecture().GetMachine() == - llvm::Triple::wasm32; + return exe_objfile->GetArchitecture().GetTriple().isWasm(); } // However, if there is no wasm module, we return false, otherwise, @@ -83,6 +82,9 @@ bool ProcessWasm::CanDebug(lldb::TargetSP target_sp, } std::shared_ptr<ThreadGDBRemote> ProcessWasm::CreateThread(lldb::tid_t tid) { + if (!GetTarget().GetArchitecture().GetTriple().isWasm()) + return ProcessGDBRemote::CreateThread(tid); + return std::make_shared<ThreadWasm>(*this, tid); } diff --git a/lldb/source/Plugins/Process/wasm/ThreadWasm.cpp b/lldb/source/Plugins/Process/wasm/ThreadWasm.cpp index c7c05cb815261..bbf474906806d 100644 --- a/lldb/source/Plugins/Process/wasm/ThreadWasm.cpp +++ b/lldb/source/Plugins/Process/wasm/ThreadWasm.cpp @@ -20,8 +20,7 @@ using namespace lldb_private::wasm; Unwind &ThreadWasm::GetUnwinder() { if (!m_unwinder_up) { - assert(CalculateTarget()->GetArchitecture().GetMachine() == - llvm::Triple::wasm32); + assert(CalculateTarget()->GetArchitecture().GetTriple().isWasm()); m_unwinder_up.reset(new wasm::UnwindWasm(*this)); } return *m_unwinder_up; diff --git a/lldb/test/API/functionalities/gdb_remote_client/TestWasm.py b/lldb/test/API/functionalities/gdb_remote_client/TestWasm.py index 114ddd7adce5a..4e4a21d9416b1 100644 --- a/lldb/test/API/functionalities/gdb_remote_client/TestWasm.py +++ b/lldb/test/API/functionalities/gdb_remote_client/TestWasm.py @@ -501,3 +501,52 @@ def test_read_global(self): # Likewise for a global that does not exist. process.ReadMemory(globals_addr + 99, 4, error) self.assertFalse(error.Success()) + + @skipIfXmlSupportMissing + def test_non_wasm_process(self): + """Test that the plugin falls back to plain GDB remote debugging when + it is requested by name for a process that isn't WebAssembly.""" + + class NonWasmResponder(MockGDBServerResponder): + def qHostInfo(self): + return "triple:%s;ptrsize:8;endian:little;" % hex_encode_bytes( + "x86_64-unknown-linux-gnu" + ) + + def qfThreadInfo(self): + return "m1" + + def haltReason(self): + return "T02thread:1;threads:1;thread-pcs:10001bc00;" + + def qXferRead(self, obj, annex, offset, length): + if annex == "target.xml": + return ( + """<?xml version="1.0"?> + <target version="1.0"> + <architecture>i386:x86-64</architecture> + <feature name="org.gnu.gdb.i386.core"> + <reg name="rip" bitsize="64" regnum="0" type="code_ptr" group="general"/> + </feature> + </target>""", + False, + ) + return None, False + + self.server.responder = NonWasmResponder() + + target = self.dbg.CreateTarget("") + process = self.connect(target, "wasm") + lldbutil.expect_state_changes( + self, self.dbg.GetListener(), process, [lldb.eStateStopped] + ) + + self.assertEqual(process.GetPluginName(), "wasm") + self.assertIn("x86_64", target.GetTriple()) + + thread = process.GetThreadAtIndex(0) + self.assertTrue(thread.IsValid()) + self.assertEqual(thread.GetFrameAtIndex(0).GetPC(), 0x10001BC00) + self.assertNotIn( + "qWasmCallStack", "".join(self.server.responder.packetLog.get_received()) + ) _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
