Author: Ebuka Ezike Date: 2026-08-03T11:49:01+01:00 New Revision: 750b9d9e7ac0a98b2cc107eec8a9d6eb442711a5
URL: https://github.com/llvm/llvm-project/commit/750b9d9e7ac0a98b2cc107eec8a9d6eb442711a5 DIFF: https://github.com/llvm/llvm-project/commit/750b9d9e7ac0a98b2cc107eec8a9d6eb442711a5.diff LOG: [lldb][lldb-server] Update the expected gdbserver's architecture (#210946) gdbserver recognises 'x86_64' arch as 'i386:x86-64', this prevents gdb (binary) from connecting to lldb-server since lldb-server reports architecture as 'x86_64'. we already do something similar when connecting a server to lldb. This does not affect lldb -> lldb-server since we use qHostInfo to get that information. Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/test/API/tools/lldb-server/registers-target-xml-reading/TestGdbRemoteTargetXmlPacket.py Removed: ################################################################################ diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 4f11cf8c5475e..8fe1674c167ac 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -43,6 +43,7 @@ #include "lldb/Utility/StreamString.h" #include "lldb/Utility/UnimplementedError.h" #include "lldb/Utility/UriParser.h" +#include "llvm/ADT/StringSwitch.h" #include "llvm/Support/ErrorExtras.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/JSON.h" @@ -3313,13 +3314,17 @@ GDBRemoteCommunicationServerLLGS::BuildTargetXml() { response.IndentMore(); response.Indent(); - response.Printf("<architecture>%s</architecture>\n", - m_current_process->GetArchitecture() - .GetTriple() - .getArchName() - .str() - .c_str()); - + const llvm::StringRef arch_name = + m_current_process->GetArchitecture().GetTriple().getArchName(); + // Match gdbserver's expected architecture. We do the reverse when + // decoding the architecture when receiving the target.xml + // in ProcessGDBRemote::GetGDBServerRegisterInfoXMLAndProcess. + const llvm::StringRef new_arch_name = StringSwitch<llvm::StringRef>(arch_name) + .Case("x86_64", "i386:x86-64") + .Case("riscv64", "riscv:rv64") + .Case("riscv32", "riscv:rv32") + .Default(arch_name); + response.Format("<architecture>{}</architecture>\n", new_arch_name); response.Indent("<feature>\n"); const int registers_count = reg_context.GetUserRegisterCount(); diff --git a/lldb/test/API/tools/lldb-server/registers-target-xml-reading/TestGdbRemoteTargetXmlPacket.py b/lldb/test/API/tools/lldb-server/registers-target-xml-reading/TestGdbRemoteTargetXmlPacket.py index 603aa0033f086..d873fbe04c825 100644 --- a/lldb/test/API/tools/lldb-server/registers-target-xml-reading/TestGdbRemoteTargetXmlPacket.py +++ b/lldb/test/API/tools/lldb-server/registers-target-xml-reading/TestGdbRemoteTargetXmlPacket.py @@ -40,7 +40,15 @@ def test_g_target_xml_returns_correct_data(self): architecture = root.find("architecture") self.assertIsNotNone(architecture) - self.assertIn(self.getArchitecture(), architecture.text) + # Match the expected gdbserver's arch, see GDBRemoteCommunicationServerLLGS::BuildTargetXml. + replaced_arch = { + "x86_64": "i386:x86-64", + "riscv64": "riscv:rv64", + "riscv32": "riscv:rv32", + } + arch: str = self.getArchitecture() + expected_arch = replaced_arch.get(arch, arch) + self.assertIn(architecture.text, expected_arch) feature = root.find("feature") self.assertIsNotNone(feature) _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
