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("%s\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(arch_name) + .Case("x86_64", "i386:x86-64") + .Case("riscv64", "riscv:rv64") + .Case("riscv32", "riscv:rv32") + .Default(arch_name); + response.Format("{}\n", new_arch_name); response.Indent("\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)