• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""
2Test process attach.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9import lldbutil
10
11class ProcessAttachTestCase(TestBase):
12
13    mydir = os.path.join("functionalities", "process_attach")
14
15    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
16    @dsym_test
17    def test_attach_to_process_by_id_with_dsym(self):
18        """Test attach by process id"""
19        self.buildDsym()
20        self.process_attach_by_id()
21
22    @dwarf_test
23    def test_attach_to_process_by_id_with_dwarf(self):
24        """Test attach by process id"""
25        self.buildDwarf()
26        self.process_attach_by_id()
27
28    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
29    @dsym_test
30    def test_attach_to_process_by_name_with_dsym(self):
31        """Test attach by process name"""
32        self.buildDsym()
33        self.process_attach_by_name()
34
35    @expectedFailureFreeBSD('llvm.org/pr16699')
36    @dwarf_test
37    def test_attach_to_process_by_name_with_dwarf(self):
38        """Test attach by process name"""
39        self.buildDwarf()
40        self.process_attach_by_name()
41
42    def setUp(self):
43        # Call super's setUp().
44        TestBase.setUp(self)
45
46    def process_attach_by_id(self):
47        """Test attach by process id"""
48
49        exe = os.path.join(os.getcwd(), "a.out")
50
51        # Spawn a new process
52        popen = self.spawnSubprocess(exe)
53        self.addTearDownHook(self.cleanupSubprocesses)
54
55        self.runCmd("process attach -p " + str(popen.pid))
56
57        target = self.dbg.GetSelectedTarget()
58
59        process = target.GetProcess()
60        self.assertTrue(process, PROCESS_IS_VALID)
61
62
63    def process_attach_by_name(self):
64        """Test attach by process name"""
65
66        exe = os.path.join(os.getcwd(), "a.out")
67
68        # Spawn a new process
69        popen = self.spawnSubprocess(exe)
70        self.addTearDownHook(self.cleanupSubprocesses)
71
72        self.runCmd("process attach -n a.out")
73
74        target = self.dbg.GetSelectedTarget()
75
76        process = target.GetProcess()
77        self.assertTrue(process, PROCESS_IS_VALID)
78
79
80if __name__ == '__main__':
81    import atexit
82    lldb.SBDebugger.Initialize()
83    atexit.register(lambda: lldb.SBDebugger.Terminate())
84    unittest2.main()
85