ff708310ca938c8546874738252f5c18bde8509a
[openbsd] /
1
2 import time
3
4 import gdbremote_testcase
5 from lldbsuite.test.decorators import *
6 from lldbsuite.test.lldbtest import *
7 from lldbsuite.test import lldbutil
8
9
10 class TestPlatformProcessConnect(gdbremote_testcase.GdbRemoteTestCaseBase):
11     mydir = TestBase.compute_mydir(__file__)
12
13     def setUp(self):
14         super(TestPlatformProcessConnect, self).setUp()
15         self._initial_platform = lldb.DBG.GetSelectedPlatform()
16
17     def tearDown(self):
18         lldb.DBG.SetSelectedPlatform(self._initial_platform)
19         super(TestPlatformProcessConnect, self).tearDown()
20
21     @llgs_test
22     @no_debug_info_test
23     @skipIf(remote=False)
24     @expectedFailureAll(hostoslist=["windows"], triple='.*-android')
25     def test_platform_process_connect(self):
26         self.build()
27         self.init_llgs_test(False)
28
29         working_dir = lldb.remote_platform.GetWorkingDirectory()
30         src = lldb.SBFileSpec(self.getBuildArtifact("a.out"))
31         dest = lldb.SBFileSpec(os.path.join(working_dir, "a.out"))
32         err = lldb.remote_platform.Put(src, dest)
33         if err.Fail():
34             raise RuntimeError(
35                 "Unable copy '%s' to '%s'.\n>>> %s" %
36                 (f, wd, err.GetCString()))
37
38         m = re.search("^(.*)://([^:/]*)", configuration.lldb_platform_url)
39         protocol = m.group(1)
40         hostname = m.group(2)
41         unix_protocol = protocol.startswith("unix-")
42         if unix_protocol:
43             p = re.search("^(.*)-connect", protocol)
44             path = lldbutil.join_remote_paths(configuration.lldb_platform_working_dir,
45                     self.getBuildDirBasename(), "platform-%d.sock" % int(time.time()))
46             listen_url = "%s://%s" % (p.group(1), path)
47         else:
48             listen_url = "*:0"
49
50         port_file = "%s/port" % working_dir
51         commandline_args = [
52             "platform",
53             "--listen",
54             listen_url,
55             "--socket-file",
56             port_file,
57             "--",
58             "%s/a.out" %
59             working_dir,
60             "foo"]
61         self.spawnSubprocess(
62             self.debug_monitor_exe,
63             commandline_args,
64             install_remote=False)
65         self.addTearDownHook(self.cleanupSubprocesses)
66
67         socket_id = lldbutil.wait_for_file_on_target(self, port_file)
68
69         new_debugger = lldb.SBDebugger.Create()
70         new_debugger.SetAsync(False)
71
72         def del_debugger(new_debugger=new_debugger):
73             del new_debugger
74         self.addTearDownHook(del_debugger)
75
76         new_platform = lldb.SBPlatform(lldb.remote_platform.GetName())
77         new_debugger.SetSelectedPlatform(new_platform)
78         new_interpreter = new_debugger.GetCommandInterpreter()
79
80         if unix_protocol:
81             connect_url = "%s://%s%s" % (protocol, hostname, socket_id)
82         else:
83             connect_url = "%s://%s:%s" % (protocol, hostname, socket_id)
84
85         command = "platform connect %s" % (connect_url)
86         result = lldb.SBCommandReturnObject()
87         new_interpreter.HandleCommand(command, result)
88         self.assertTrue(
89             result.Succeeded(),
90             "platform process connect failed: %s" %
91             result.GetOutput())
92
93         target = new_debugger.GetSelectedTarget()
94         process = target.GetProcess()
95         thread = process.GetThreadAtIndex(0)
96
97         breakpoint = target.BreakpointCreateByName("main")
98         process.Continue()
99
100         frame = thread.GetFrameAtIndex(0)
101         self.assertEqual(frame.GetFunction().GetName(), "main")
102         self.assertEqual(frame.FindVariable("argc").GetValueAsSigned(), 2)
103         process.Continue()