TestPlatformProcessConnect.py
2.95 KB
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
import time
import gdbremote_testcase
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class TestPlatformProcessConnect(gdbremote_testcase.GdbRemoteTestCaseBase):
mydir = TestBase.compute_mydir(__file__)
@llgs_test
@no_debug_info_test
@skipIf(remote=False)
@expectedFailureAll(hostoslist=["windows"], triple='.*-android')
def test_platform_process_connect(self):
self.build()
self.init_llgs_test(False)
working_dir = lldb.remote_platform.GetWorkingDirectory()
src = lldb.SBFileSpec(self.getBuildArtifact("a.out"))
dest = lldb.SBFileSpec(os.path.join(working_dir, "a.out"))
err = lldb.remote_platform.Put(src, dest)
if err.Fail():
raise RuntimeError(
"Unable copy '%s' to '%s'.\n>>> %s" %
(f, wd, err.GetCString()))
m = re.search("^(.*)://([^:/]*)", configuration.lldb_platform_url)
protocol = m.group(1)
hostname = m.group(2)
unix_protocol = protocol.startswith("unix-")
if unix_protocol:
p = re.search("^(.*)-connect", protocol)
path = lldbutil.join_remote_paths(configuration.lldb_platform_working_dir,
self.getBuildDirBasename(), "platform-%d.sock" % int(time.time()))
listen_url = "%s://%s" % (p.group(1), path)
else:
listen_url = "*:0"
port_file = "%s/port" % working_dir
commandline_args = [
"platform",
"--listen",
listen_url,
"--socket-file",
port_file,
"--",
"%s/a.out" %
working_dir,
"foo"]
self.spawnSubprocess(
self.debug_monitor_exe,
commandline_args,
install_remote=False)
socket_id = lldbutil.wait_for_file_on_target(self, port_file)
self.dbg.SetAsync(False)
new_platform = lldb.SBPlatform(lldb.remote_platform.GetName())
self.dbg.SetSelectedPlatform(new_platform)
if unix_protocol:
connect_url = "%s://%s%s" % (protocol, hostname, socket_id)
else:
connect_url = "%s://%s:%s" % (protocol, hostname, socket_id)
command = "platform connect %s" % (connect_url)
result = lldb.SBCommandReturnObject()
self.dbg.GetCommandInterpreter().HandleCommand(command, result)
self.assertTrue(
result.Succeeded(),
"platform process connect failed: %s" %
result.GetOutput())
target = self.dbg.GetSelectedTarget()
process = target.GetProcess()
thread = process.GetThreadAtIndex(0)
breakpoint = target.BreakpointCreateByName("main")
process.Continue()
frame = thread.GetFrameAtIndex(0)
self.assertEqual(frame.GetFunction().GetName(), "main")
self.assertEqual(frame.FindVariable("argc").GetValueAsSigned(), 2)
process.Continue()