Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp =================================================================== --- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -375,6 +375,33 @@ return regnums.size(); } +static std::vector GetRegisters_x86_64() { + ConstString empty_alt_name; + ConstString reg_set{"general purpose registers"}; + +#define REG(name, size) \ + DynamicRegisterInfo::Register { \ + ConstString(#name), empty_alt_name, reg_set, size, LLDB_INVALID_INDEX32, \ + lldb::eEncodingUint, lldb::eFormatHex, LLDB_INVALID_REGNUM, \ + LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, {}, {} \ + } +#define R64(name) REG(name, 8) +#define R32(name) REG(name, 4) + + std::vector registers{ + R64(rax), R64(rbx), R64(rcx), R64(rdx), R64(rsi), R64(rdi), + R64(rbp), R64(rsp), R64(r8), R64(r9), R64(r10), R64(r11), + R64(r12), R64(r13), R64(r14), R64(r15), R64(rip), R32(eflags), + R32(cs), R32(ss), R32(ds), R32(es), R32(fs), R32(gs), + }; + +#undef R32 +#undef R64 +#undef REG + + return registers; +} + void ProcessGDBRemote::BuildDynamicRegisterInfo(bool force) { if (!force && m_register_info_sp) return; @@ -394,6 +421,7 @@ // 2 - If the target definition doesn't have any of the info from the // target.xml (registers) then proceed to read the target.xml. // 3 - Fall back on the qRegisterInfo packets. + // 4 - Use hardcoded defaults if available. FileSpec target_definition_fspec = GetGlobalPluginProperties().GetTargetDefinitionFile(); @@ -507,6 +535,18 @@ } } + if (registers.empty()) { + switch (arch_to_use.GetMachine()) { + case llvm::Triple::x86: + break; + case llvm::Triple::x86_64: + registers = GetRegisters_x86_64(); + break; + default: + break; + } + } + AddRemoteRegisters(registers, arch_to_use); } Index: lldb/test/API/functionalities/gdb_remote_client/TestGDBServerNoTargetXML.py =================================================================== --- /dev/null +++ lldb/test/API/functionalities/gdb_remote_client/TestGDBServerNoTargetXML.py @@ -0,0 +1,154 @@ +from __future__ import print_function +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * +from lldbsuite.test.gdbclientutils import * +from lldbsuite.test.lldbgdbclient import GDBRemoteTestBase + +import binascii + + +class TestGDBServerTargetXML(GDBRemoteTestBase): + + mydir = TestBase.compute_mydir(__file__) + + @staticmethod + def filecheck_to_blob(fc): + for l in fc.strip().splitlines(): + val = l.split('0x')[1] + yield binascii.b2a_hex(bytes(reversed(binascii.a2b_hex(val)))).decode() + + @skipIfRemote + @skipIfLLVMTargetMissing("X86") + def test_x86_64_regs(self): + """Test grabbing various x86_64 registers from gdbserver.""" + + GPRS = ''' +CHECK-AMD64-DAG: rax = 0x0807060504030201 +CHECK-AMD64-DAG: rbx = 0x1817161514131211 +CHECK-AMD64-DAG: rcx = 0x2827262524232221 +CHECK-AMD64-DAG: rdx = 0x3837363534333231 +CHECK-AMD64-DAG: rsi = 0x4847464544434241 +CHECK-AMD64-DAG: rdi = 0x5857565554535251 +CHECK-AMD64-DAG: rbp = 0x6867666564636261 +CHECK-AMD64-DAG: rsp = 0x7877767574737271 +CHECK-AMD64-DAG: r8 = 0x8887868584838281 +CHECK-AMD64-DAG: r9 = 0x9897969594939291 +CHECK-AMD64-DAG: r10 = 0xa8a7a6a5a4a3a2a1 +CHECK-AMD64-DAG: r11 = 0xb8b7b6b5b4b3b2b1 +CHECK-AMD64-DAG: r12 = 0xc8c7c6c5c4c3c2c1 +CHECK-AMD64-DAG: r13 = 0xd8d7d6d5d4d3d2d1 +CHECK-AMD64-DAG: r14 = 0xe8e7e6e5e4e3e2e1 +CHECK-AMD64-DAG: r15 = 0xf8f7f6f5f4f3f2f1 +CHECK-AMD64-DAG: rip = 0x100f0e0d0c0b0a09 +CHECK-AMD64-DAG: eflags = 0x1c1b1a19 +CHECK-AMD64-DAG: cs = 0x2c2b2a29 +CHECK-AMD64-DAG: ss = 0x3c3b3a39 +''' + + SUPPL = ''' +CHECK-AMD64-DAG: eax = 0x04030201 +CHECK-AMD64-DAG: ebx = 0x14131211 +CHECK-AMD64-DAG: ecx = 0x24232221 +CHECK-AMD64-DAG: edx = 0x34333231 +CHECK-AMD64-DAG: esi = 0x44434241 +CHECK-AMD64-DAG: edi = 0x54535251 +CHECK-AMD64-DAG: ebp = 0x64636261 +CHECK-AMD64-DAG: esp = 0x74737271 +CHECK-AMD64-DAG: r8d = 0x84838281 +CHECK-AMD64-DAG: r9d = 0x94939291 +CHECK-AMD64-DAG: r10d = 0xa4a3a2a1 +CHECK-AMD64-DAG: r11d = 0xb4b3b2b1 +CHECK-AMD64-DAG: r12d = 0xc4c3c2c1 +CHECK-AMD64-DAG: r13d = 0xd4d3d2d1 +CHECK-AMD64-DAG: r14d = 0xe4e3e2e1 +CHECK-AMD64-DAG: r15d = 0xf4f3f2f1 + +CHECK-AMD64-DAG: ax = 0x0201 +CHECK-AMD64-DAG: bx = 0x1211 +CHECK-AMD64-DAG: cx = 0x2221 +CHECK-AMD64-DAG: dx = 0x3231 +CHECK-AMD64-DAG: si = 0x4241 +CHECK-AMD64-DAG: di = 0x5251 +CHECK-AMD64-DAG: bp = 0x6261 +CHECK-AMD64-DAG: sp = 0x7271 +CHECK-AMD64-DAG: r8w = 0x8281 +CHECK-AMD64-DAG: r9w = 0x9291 +CHECK-AMD64-DAG: r10w = 0xa2a1 +CHECK-AMD64-DAG: r11w = 0xb2b1 +CHECK-AMD64-DAG: r12w = 0xc2c1 +CHECK-AMD64-DAG: r13w = 0xd2d1 +CHECK-AMD64-DAG: r14w = 0xe2e1 +CHECK-AMD64-DAG: r15w = 0xf2f1 + +CHECK-AMD64-DAG: ah = 0x02 +CHECK-AMD64-DAG: bh = 0x12 +CHECK-AMD64-DAG: ch = 0x22 +CHECK-AMD64-DAG: dh = 0x32 + +CHECK-AMD64-DAG: al = 0x01 +CHECK-AMD64-DAG: bl = 0x11 +CHECK-AMD64-DAG: cl = 0x21 +CHECK-AMD64-DAG: dl = 0x31 +CHECK-AMD64-DAG: sil = 0x41 +CHECK-AMD64-DAG: dil = 0x51 +CHECK-AMD64-DAG: bpl = 0x61 +CHECK-AMD64-DAG: spl = 0x71 +CHECK-AMD64-DAG: r8l = 0x81 +CHECK-AMD64-DAG: r9l = 0x91 +CHECK-AMD64-DAG: r10l = 0xa1 +CHECK-AMD64-DAG: r11l = 0xb1 +CHECK-AMD64-DAG: r12l = 0xc1 +CHECK-AMD64-DAG: r13l = 0xd1 +CHECK-AMD64-DAG: r14l = 0xe1 +CHECK-AMD64-DAG: r15l = 0xf1 +''' + + class MyResponder(MockGDBServerResponder): + reg_data = ''.join(self.filecheck_to_blob(GPRS)) + + def readRegister(self, regnum): + return "" + + def readRegisters(self): + return self.reg_data + + def writeRegisters(self, reg_hex): + self.reg_data = reg_hex + return "OK" + + def haltReason(self): + return "T02thread:1ff0d;threads:1ff0d;thread-pcs:000000010001bc00;07:0102030405060708;10:1112131415161718;" + + self.server.responder = MyResponder() + + target = self.createTarget("basic_eh_frame.yaml") + process = self.connect(target) + lldbutil.expect_state_changes(self, self.dbg.GetListener(), process, + [lldb.eStateStopped]) + + # test all registers + self.filecheck("register read --all", __file__, + filecheck_options='--check-prefix=CHECK-AMD64') + + # test generic aliases + self.match("register read arg4", + ["rcx = 0x2827262524232221"]) + self.match("register read arg3", + ["rdx = 0x3837363534333231"]) + self.match("register read arg2", + ["rsi = 0x4847464544434241"]) + self.match("register read arg1", + ["rdi = 0x5857565554535251"]) + self.match("register read fp", + ["rbp = 0x6867666564636261"]) + self.match("register read sp", + ["rsp = 0x7877767574737271"]) + self.match("register read arg5", + ["r8 = 0x8887868584838281"]) + self.match("register read arg6", + ["r9 = 0x9897969594939291"]) + self.match("register read pc", + ["rip = 0x100f0e0d0c0b0a09"]) + self.match("register read flags", + ["eflags = 0x1c1b1a19"])