Andrew Kaylor | 52dd223 | 2013-05-03 00:10:27 +0000 | [diff] [blame^] | 1 | """ |
| 2 | Test process attach. |
| 3 | """ |
| 4 | |
| 5 | import os, time |
| 6 | import unittest2 |
| 7 | import lldb |
| 8 | from lldbtest import * |
| 9 | import lldbutil |
| 10 | |
| 11 | class 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 | @expectedFailureLinux # lldb is unable to attach to process by id |
| 23 | @dwarf_test |
| 24 | def test_attach_to_process_by_id_with_dwarf(self): |
| 25 | """Test attach by process id""" |
| 26 | self.buildDwarf() |
| 27 | self.process_attach_by_id() |
| 28 | |
| 29 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
| 30 | @dsym_test |
| 31 | def test_attach_to_process_by_name_with_dsym(self): |
| 32 | """Test attach by process name""" |
| 33 | self.buildDsym() |
| 34 | self.process_attach_by_name() |
| 35 | |
| 36 | @expectedFailureLinux # due to bugzilla 14541 -- lldb is unable to attach to process by name |
| 37 | @dwarf_test |
| 38 | def test_attach_to_process_by_name_with_dwarf(self): |
| 39 | """Test attach by process name""" |
| 40 | self.buildDwarf() |
| 41 | self.process_attach_by_name() |
| 42 | |
| 43 | def setUp(self): |
| 44 | # Call super's setUp(). |
| 45 | TestBase.setUp(self) |
| 46 | |
| 47 | def process_attach_by_id(self): |
| 48 | """Test attach by process id""" |
| 49 | |
| 50 | exe = os.path.join(os.getcwd(), "a.out") |
| 51 | |
| 52 | #target = self.dbg.CreateTarget(exe) |
| 53 | |
| 54 | # Spawn a new process |
| 55 | popen = self.spawnSubprocess(exe) |
| 56 | self.addTearDownHook(self.cleanupSubprocesses) |
| 57 | |
| 58 | self.runCmd("process attach -p " + str(popen.pid)) |
| 59 | |
| 60 | target = self.dbg.GetSelectedTarget() |
| 61 | |
| 62 | process = target.GetProcess() |
| 63 | self.assertTrue(process, PROCESS_IS_VALID) |
| 64 | |
| 65 | |
| 66 | def process_attach_by_name(self): |
| 67 | """Test attach by process name""" |
| 68 | |
| 69 | exe = os.path.join(os.getcwd(), "a.out") |
| 70 | |
| 71 | # Spawn a new process |
| 72 | popen = self.spawnSubprocess(exe) |
| 73 | self.addTearDownHook(self.cleanupSubprocesses) |
| 74 | |
| 75 | target = self.dbg.GetSelectedTarget() |
| 76 | |
| 77 | self.runCmd("process attach -n a.out") |
| 78 | |
| 79 | proces = target.GetProcess() |
| 80 | self.assertTrue(process, PROCESS_IS_VALID) |
| 81 | |
| 82 | |
| 83 | if __name__ == '__main__': |
| 84 | import atexit |
| 85 | lldb.SBDebugger.Initialize() |
| 86 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 87 | unittest2.main() |