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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
import lldb
import binascii
import os
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
from lldbsuite.test.gdbclientutils import *
from lldbsuite.test.lldbgdbclient import GDBRemoteTestBase
@skipIfRemote
class TestProcessConnect(GDBRemoteTestBase):
NO_DEBUG_INFO_TESTCASE = True
def test_gdb_remote_sync(self):
"""Test the gdb-remote command in synchronous mode"""
try:
self.dbg.SetAsync(False)
self.expect(
"gdb-remote " + self.server.get_connect_address(),
substrs=["Process", "stopped"],
)
finally:
self.dbg.GetSelectedTarget().GetProcess().Kill()
def test_gdb_remote_async(self):
"""Test the gdb-remote command in asynchronous mode"""
try:
self.dbg.SetAsync(True)
self.expect(
"gdb-remote " + self.server.get_connect_address(),
matching=False,
substrs=["Process", "stopped"],
)
lldbutil.expect_state_changes(
self, self.dbg.GetListener(), self.process(), [lldb.eStateStopped]
)
finally:
self.dbg.GetSelectedTarget().GetProcess().Kill()
lldbutil.expect_state_changes(
self, self.dbg.GetListener(), self.process(), [lldb.eStateExited]
)
@skipIfWindows
def test_process_connect_sync(self):
"""Test the gdb-remote command in synchronous mode"""
try:
self.dbg.SetAsync(False)
self.expect(
"platform select remote-gdb-server",
substrs=["Platform: remote-gdb-server", "Connected: no"],
)
self.expect(
"process connect " + self.server.get_connect_url(),
substrs=["Process", "stopped"],
)
finally:
self.dbg.GetSelectedTarget().GetProcess().Kill()
@skipIfWindows
def test_process_connect_async(self):
"""Test the gdb-remote command in asynchronous mode"""
try:
self.dbg.SetAsync(True)
self.expect(
"platform select remote-gdb-server",
substrs=["Platform: remote-gdb-server", "Connected: no"],
)
self.expect(
"process connect " + self.server.get_connect_url(),
matching=False,
substrs=["Process", "stopped"],
)
lldbutil.expect_state_changes(
self, self.dbg.GetListener(), self.process(), [lldb.eStateStopped]
)
finally:
self.dbg.GetSelectedTarget().GetProcess().Kill()
lldbutil.expect_state_changes(
self, self.dbg.GetListener(), self.process(), [lldb.eStateExited]
)
def test_breakpoint_count(self):
"""
Test that breakpoint count gets reset for each new connection.
"""
class MyResponder(MockGDBServerResponder):
def __init__(self):
super().__init__()
self.continued = False
def qfThreadInfo(self):
return "m47"
def qsThreadInfo(self):
return "l"
def setBreakpoint(self, packet):
return "OK"
def readRegister(self, reg):
# Pretend we're at the breakpoint after we've been resumed.
return "3412000000000000" if self.continued else "4747000000000000"
def cont(self):
self.continued = True
return "T05thread=47;reason:breakpoint"
# Connect to the first process and set our breakpoint.
self.server.responder = MyResponder()
target = self.createTarget("a.yaml")
process = self.connect(target)
bkpt = target.BreakpointCreateByAddress(0x1234)
self.assertTrue(bkpt.IsValid())
self.assertEqual(bkpt.GetNumLocations(), 1)
# "continue" the process. It should hit our breakpoint.
process.Continue()
self.assertState(process.GetState(), lldb.eStateStopped)
self.assertEqual(bkpt.GetHitCount(), 1)
# Now kill it. The breakpoint should still show a hit count of one.
process.Kill()
self.server.stop()
self.assertEqual(bkpt.GetHitCount(), 1)
# Start over, and reconnect.
self.server = MockGDBServer(self.server_socket_class())
self.server.start()
process = self.connect(target)
# The hit count should be reset.
self.assertEqual(bkpt.GetHitCount(), 0)
|