[Lldb-commits] [lldb] 270c989 - [lldb] [test] Rewrite g/p/G/P tests not to rely on hardcoded ARM regs
Michał Górny via lldb-commits
lldb-commits at lists.llvm.org
Mon Oct 11 05:12:03 PDT 2021
Author: Michał Górny
Date: 2021-10-11T14:07:28+02:00
New Revision: 270c989f6fef3bc336f7a4238754faa7c5993d3d
URL: https://github.com/llvm/llvm-project/commit/270c989f6fef3bc336f7a4238754faa7c5993d3d
DIFF: https://github.com/llvm/llvm-project/commit/270c989f6fef3bc336f7a4238754faa7c5993d3d.diff
LOG: [lldb] [test] Rewrite g/p/G/P tests not to rely on hardcoded ARM regs
Rewrite the register reading/writing tests to use explicit qRegisterInfo
packets rather than relying on ARM registers being hardcoded in LLDB.
While at it, use x86_64 for tests -- since it was easier for me to get
the register lists from that architecture.
Differential Revision: https://reviews.llvm.org/D111496
Added:
Modified:
lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
lldb/test/API/functionalities/gdb_remote_client/a.yaml
lldb/test/API/functionalities/gdb_remote_client/gdbclientutils.py
Removed:
################################################################################
diff --git a/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py b/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
index 497c5cbbbcdac..0b0982d2367e7 100644
--- a/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
+++ b/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
@@ -9,8 +9,28 @@
class TestGDBRemoteClient(GDBRemoteTestBase):
class gPacketResponder(MockGDBServerResponder):
+ registers = [
+ "name:rax;bitsize:64;offset:0;encoding:uint;format:hex;set:General Purpose Registers;ehframe:0;dwarf:0;",
+ "name:rbx;bitsize:64;offset:8;encoding:uint;format:hex;set:General Purpose Registers;ehframe:3;dwarf:3;",
+ "name:rcx;bitsize:64;offset:16;encoding:uint;format:hex;set:General Purpose Registers;ehframe:2;dwarf:2;generic:arg4;",
+ "name:rdx;bitsize:64;offset:24;encoding:uint;format:hex;set:General Purpose Registers;ehframe:1;dwarf:1;generic:arg3;",
+ "name:rdi;bitsize:64;offset:32;encoding:uint;format:hex;set:General Purpose Registers;ehframe:5;dwarf:5;generic:arg1;",
+ "name:rsi;bitsize:64;offset:40;encoding:uint;format:hex;set:General Purpose Registers;ehframe:4;dwarf:4;generic:arg2;",
+ "name:rbp;bitsize:64;offset:48;encoding:uint;format:hex;set:General Purpose Registers;ehframe:6;dwarf:6;generic:fp;",
+ "name:rsp;bitsize:64;offset:56;encoding:uint;format:hex;set:General Purpose Registers;ehframe:7;dwarf:7;generic:sp;",
+ ]
+
+ def qRegisterInfo(self, num):
+ try:
+ return self.registers[num]
+ except IndexError:
+ return "E45"
+
def readRegisters(self):
- return '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
+ return len(self.registers) * 16 * '0'
+
+ def readRegister(self, register):
+ return "0000000000000000"
def test_connect(self):
"""Test connecting to a remote gdb server"""
@@ -88,6 +108,7 @@ def test_read_registers_using_p_packets(self):
"""Test reading registers using 'p' packets"""
self.dbg.HandleCommand(
"settings set plugin.process.gdb-remote.use-g-packet-for-reading false")
+ self.server.responder = self.gPacketResponder()
target = self.createTarget("a.yaml")
process = self.connect(target)
@@ -128,11 +149,11 @@ def readRegister(self, register):
def read_registers(self, process):
self.for_each_gpr(
- process, lambda r: self.assertEquals("0x00000000", r.GetValue()))
+ process, lambda r: self.assertEquals("0x0000000000000000", r.GetValue()))
def write_registers(self, process):
self.for_each_gpr(
- process, lambda r: r.SetValueFromCString("0x00000000"))
+ process, lambda r: r.SetValueFromCString("0x0000000000000000"))
def for_each_gpr(self, process, operation):
registers = process.GetThreadAtIndex(0).GetFrameAtIndex(0).GetRegisters()
diff --git a/lldb/test/API/functionalities/gdb_remote_client/a.yaml b/lldb/test/API/functionalities/gdb_remote_client/a.yaml
index 6058b6ddd3c59..d62ebaac847c6 100644
--- a/lldb/test/API/functionalities/gdb_remote_client/a.yaml
+++ b/lldb/test/API/functionalities/gdb_remote_client/a.yaml
@@ -1,9 +1,9 @@
-!ELF
+--- !ELF
FileHeader:
- Class: ELFCLASS32
+ Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
- Machine: EM_ARM
+ Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
diff --git a/lldb/test/API/functionalities/gdb_remote_client/gdbclientutils.py b/lldb/test/API/functionalities/gdb_remote_client/gdbclientutils.py
index 082b935885fb9..c2974366e3457 100644
--- a/lldb/test/API/functionalities/gdb_remote_client/gdbclientutils.py
+++ b/lldb/test/API/functionalities/gdb_remote_client/gdbclientutils.py
@@ -200,6 +200,9 @@ def respond(self, packet):
return self.QEnvironment(packet)
if packet.startswith("QEnvironmentHexEncoded:"):
return self.QEnvironmentHexEncoded(packet)
+ if packet.startswith("qRegisterInfo"):
+ regnum = int(packet[len("qRegisterInfo"):], 16)
+ return self.qRegisterInfo(regnum)
return self.other(packet)
@@ -325,6 +328,9 @@ def QEnvironment(self, packet):
def QEnvironmentHexEncoded(self, packet):
return "OK"
+ def qRegisterInfo(self, num):
+ return ""
+
"""
Raised when we receive a packet for which there is no default action.
Override the responder class to implement behavior suitable for the test at
More information about the lldb-commits
mailing list