forked from llvm/llvm-project
- Notifications
You must be signed in to change notification settings - Fork 339
/
Copy pathlldbgdbclient.py
106 lines (87 loc) · 3.41 KB
/
lldbgdbclient.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
importos
importos.path
importlldb
fromlldbsuite.test.lldbtestimport*
fromlldbsuite.test.gdbclientutilsimport*
classGDBRemoteTestBase(TestBase):
"""
Base class for GDB client tests.
This class will setup and start a mock GDB server for the test to use.
It also provides assertPacketLogContains, which simplifies the checking
of packets sent by the client.
"""
NO_DEBUG_INFO_TESTCASE=True
server=None
server_socket_class=TCPServerSocket
defsetUp(self):
TestBase.setUp(self)
self.server=MockGDBServer(self.server_socket_class())
self.server.start()
deftearDown(self):
# TestBase.tearDown will kill the process, but we need to kill it early
# so its client connection closes and we can stop the server before
# finally calling the base tearDown.
ifself.process() isnotNone:
self.process().Kill()
self.server.stop()
TestBase.tearDown(self)
defcreateTarget(self, yaml_path):
"""
Create a target by auto-generating the object based on the given yaml
instructions.
This will track the generated object so it can be automatically removed
during tearDown.
"""
yaml_base, ext=os.path.splitext(yaml_path)
obj_path=self.getBuildArtifact(yaml_base)
self.yaml2obj(yaml_path, obj_path)
returnself.dbg.CreateTarget(obj_path)
defconnect(self, target):
"""
Create a process by connecting to the mock GDB server.
Includes assertions that the process was successfully created.
"""
listener=self.dbg.GetListener()
error=lldb.SBError()
process=target.ConnectRemote(
listener, self.server.get_connect_url(), "gdb-remote", error
)
self.assertTrue(error.Success(), error.description)
self.assertTrue(process, PROCESS_IS_VALID)
returnprocess
defassertPacketLogContains(self, packets, log=None):
"""
Assert that the mock server's packet log contains the given packets.
The packet log includes all packets sent by the client and received
by the server. This fuction makes it easy to verify that the client
sent the expected packets to the server.
The check does not require that the packets be consecutive, but does
require that they are ordered in the log as they ordered in the arg.
"""
iflogisNone:
log=self.server.responder.packetLog
i=0
j=0
whilei<len(packets) andj<len(log):
iflog[j] ==packets[i]:
i+=1
j+=1
ifi<len(packets):
self.fail(
"Did not receive: %s\nLast 10 packets:\n\t%s"
% (packets[i], "\n\t".join(log))
)
classGDBPlatformClientTestBase(GDBRemoteTestBase):
"""
Base class for platform server clients.
This class extends GDBRemoteTestBase by automatically connecting
via "platform connect" in the setUp() method.
"""
defsetUp(self):
super().setUp()
self.runCmd("platform select remote-gdb-server")
self.runCmd("platform connect "+self.server.get_connect_url())
self.assertTrue(self.dbg.GetSelectedPlatform().IsConnected())
deftearDown(self):
self.dbg.GetSelectedPlatform().DisconnectRemote()
super().tearDown()