2 Test lldb-mi -target-xxx commands.
5 from __future__ import print_function
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 from lldbsuite.test import lldbutil
12 class MiTargetTestCase(lldbmi_testcase.MiTestCaseBase):
14 mydir = TestBase.compute_mydir(__file__)
16 @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows
17 @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
18 @skipIfLinux # cannot attach to process on linux
19 def test_lldbmi_target_attach_wait_for(self):
20 """Test that 'lldb-mi --interpreter' works for -target-attach -n <name> --waitfor."""
22 # Build target executable with unique name
23 exeName = self.testMethodName
25 self.buildProgram("test_attach.cpp", exeName)
26 self.addTearDownCleanup(dictionary=d)
28 self.spawnLldbMi(args = None)
31 # FIXME: -file-exec-and-sybmols is not required for target attach, but the test will not pass without this
32 self.runCmd("-file-exec-and-symbols %s" % exeName)
36 self.runCmd("-target-attach -n %s --waitfor" % exeName)
37 time.sleep(4) # Give attach time to setup
39 # Start target process
40 self.spawnSubprocess(os.path.join(os.path.dirname(__file__), exeName));
41 self.addTearDownHook(self.cleanupSubprocesses)
44 # Set breakpoint on printf
45 line = line_number('test_attach.cpp', '// BP_i++')
46 self.runCmd("-break-insert -f test_attach.cpp:%d" % line)
47 self.expect("\^done,bkpt={number=\"1\"")
49 # Continue to breakpoint
50 self.runCmd("-exec-continue")
51 self.expect("\*stopped,reason=\"breakpoint-hit\"")
54 self.runCmd("-target-detach")
57 @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows
58 @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
59 @skipIfLinux # cannot attach to process on linux
60 def test_lldbmi_target_attach_name(self):
61 """Test that 'lldb-mi --interpreter' works for -target-attach -n <name>."""
63 # Build target executable with unique name
64 exeName = self.testMethodName
66 self.buildProgram("test_attach.cpp", exeName)
67 self.addTearDownCleanup(dictionary=d)
69 # Start target process
70 targetProcess = self.spawnSubprocess(os.path.join(os.path.dirname(__file__), exeName));
71 self.addTearDownHook(self.cleanupSubprocesses)
73 self.spawnLldbMi(args = None)
76 self.runCmd("-target-attach -n %s" % exeName)
79 # Set breakpoint on printf
80 line = line_number('test_attach.cpp', '// BP_i++')
81 self.runCmd("-break-insert -f test_attach.cpp:%d" % line)
82 self.expect("\^done,bkpt={number=\"1\"")
84 # Continue to breakpoint
85 self.runCmd("-exec-continue")
86 self.expect("\*stopped,reason=\"breakpoint-hit\"")
89 self.runCmd("-target-detach")
92 @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows
93 @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
94 @skipIfLinux # cannot attach to process on linux
95 def test_lldbmi_target_attach_pid(self):
96 """Test that 'lldb-mi --interpreter' works for -target-attach <pid>."""
98 # Build target executable with unique name
99 exeName = self.testMethodName
101 self.buildProgram("test_attach.cpp", exeName)
102 self.addTearDownCleanup(dictionary=d)
104 # Start target process
105 targetProcess = self.spawnSubprocess(os.path.join(os.path.dirname(__file__), exeName));
106 self.addTearDownHook(self.cleanupSubprocesses)
108 self.spawnLldbMi(args = None)
111 self.runCmd("-target-attach %d" % targetProcess.pid)
112 self.expect("\^done")
114 # Set breakpoint on printf
115 line = line_number('test_attach.cpp', '// BP_i++')
116 self.runCmd("-break-insert -f test_attach.cpp:%d" % line)
117 self.expect("\^done,bkpt={number=\"1\"")
119 # Continue to breakpoint
120 self.runCmd("-exec-continue")
121 self.expect("\*stopped,reason=\"breakpoint-hit\"")
124 self.runCmd("-target-detach")
125 self.expect("\^done")