2 Test that the lldb-mi handles signals properly.
5 from __future__ import print_function
10 from lldbsuite.test.lldbtest import *
12 class MiSignalTestCase(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: Fails on FreeBSD apparently due to thread race conditions
18 def test_lldbmi_stopped_when_interrupt(self):
19 """Test that 'lldb-mi --interpreter' interrupt and resume a looping app."""
21 self.spawnLldbMi(args = None)
24 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
28 self.runCmd("-break-insert -f main")
29 self.expect("\^done,bkpt={number=\"1\"")
30 self.runCmd("-exec-run")
31 self.expect("\^running")
32 self.expect("\*stopped,reason=\"breakpoint-hit\"")
34 # Set doloop=1 and run (to loop forever)
35 self.runCmd("-data-evaluate-expression \"do_loop=1\"")
36 self.expect("\^done,value=\"1\"")
37 self.runCmd("-exec-continue")
38 self.expect("\^running")
40 # Test that -exec-interrupt can interrupt an execution
41 self.runCmd("-exec-interrupt")
42 self.expect("\*stopped,reason=\"signal-received\",signal-name=\"SIGINT\",signal-meaning=\"Interrupt\",.+?thread-id=\"1\",stopped-threads=\"all\"")
44 # Continue (to loop forever)
45 self.runCmd("-exec-continue")
46 self.expect("\^running")
48 # Test that Ctrl+C can interrupt an execution
49 self.child.sendintr() #FIXME: here uses self.child directly
50 self.expect("\*stopped,reason=\"signal-received\",signal-name=\"SIGINT\",signal-meaning=\"Interrupt\",.*thread-id=\"1\",stopped-threads=\"all\"")
52 @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows
53 @skipIfFreeBSD # llvm.org/pr22411: Fails on FreeBSD apparently due to thread race conditions
54 @skipIfLinux # llvm.org/pr22841: lldb-mi tests fail on all Linux buildbots
55 def test_lldbmi_stopped_when_stopatentry_local(self):
56 """Test that 'lldb-mi --interpreter' notifies after it was stopped on entry (local)."""
58 self.spawnLldbMi(args = None)
61 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
64 # Run with stop-at-entry flag
65 self.runCmd("-interpreter-exec command \"process launch -s\"")
68 # Test that *stopped is printed
69 # Note that message is different in Darwin and Linux:
70 # Darwin: "*stopped,reason=\"signal-received\",signal-name=\"SIGSTOP\",signal-meaning=\"Stop\",frame={level=\"0\",addr=\"0x[0-9a-f]+\",func=\"_dyld_start\",file=\"??\",fullname=\"??\",line=\"-1\"},thread-id=\"1\",stopped-threads=\"all\"
71 # Linux: "*stopped,reason=\"end-stepping-range\",frame={addr=\"0x[0-9a-f]+\",func=\"??\",args=[],file=\"??\",fullname=\"??\",line=\"-1\"},thread-id=\"1\",stopped-threads=\"all\"
72 self.expect([ "\*stopped,reason=\"signal-received\",signal-name=\"SIGSTOP\",signal-meaning=\"Stop\",frame=\{level=\"0\",addr=\"0x[0-9a-f]+\",func=\"_dyld_start\",file=\"\?\?\",fullname=\"\?\?\",line=\"-1\"\},thread-id=\"1\",stopped-threads=\"all\"",
73 "\*stopped,reason=\"end-stepping-range\",frame={addr=\"0x[0-9a-f]+\",func=\"\?\?\",args=\[\],file=\"\?\?\",fullname=\"\?\?\",line=\"-1\"},thread-id=\"1\",stopped-threads=\"all\"" ])
75 # Run to main to make sure we have not exited the application
76 self.runCmd("-break-insert -f main")
77 self.expect("\^done,bkpt={number=\"1\"")
78 self.runCmd("-exec-continue")
79 self.expect("\^running")
80 self.expect("\*stopped,reason=\"breakpoint-hit\"")
82 @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows
84 def test_lldbmi_stopped_when_stopatentry_remote(self):
85 """Test that 'lldb-mi --interpreter' notifies after it was stopped on entry (remote)."""
88 import lldbgdbserverutils
89 debugserver_exe = lldbgdbserverutils.get_debugserver_exe()
90 if not debugserver_exe:
91 self.skipTest("debugserver exe not found")
92 hostname = "localhost"
94 port = 12000 + random.randint(0,3999) # the same as GdbRemoteTestCaseBase.get_next_port
96 debugserver_child = pexpect.spawn("%s %s:%d" % (debugserver_exe, hostname, port))
97 self.addTearDownHook(lambda: debugserver_child.terminate(force = True))
99 self.spawnLldbMi(args = None)
101 # Connect to debugserver
102 self.runCmd("-interpreter-exec command \"platform select remote-macosx --sysroot /\"")
103 self.expect("\^done")
104 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
105 self.expect("\^done")
106 self.runCmd("-interpreter-exec command \"process connect connect://%s:%d\"" % (hostname, port))
107 self.expect("\^done")
109 # Run with stop-at-entry flag
110 self.runCmd("-interpreter-exec command \"process launch -s\"")
111 self.expect("\^done")
113 # Test that *stopped is printed
114 self.expect("\*stopped,reason=\"signal-received\",signal-name=\"SIGSTOP\",signal-meaning=\"Stop\",.+?thread-id=\"1\",stopped-threads=\"all\"")
117 self.runCmd("-gdb-exit")
118 self.expect("\^exit")
120 @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows
121 @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
122 @skipIfLinux # llvm.org/pr22841: lldb-mi tests fail on all Linux buildbots
123 def test_lldbmi_stopped_when_segfault_local(self):
124 """Test that 'lldb-mi --interpreter' notifies after it was stopped when segfault occurred (local)."""
126 self.spawnLldbMi(args = None)
129 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
130 self.expect("\^done")
133 self.runCmd("-break-insert -f main")
134 self.expect("\^done,bkpt={number=\"1\"")
135 self.runCmd("-exec-run")
136 self.expect("\^running")
137 self.expect("\*stopped,reason=\"breakpoint-hit\"")
139 # Set do_segfault=1 and run (to cause a segfault error)
140 self.runCmd("-data-evaluate-expression \"do_segfault=1\"")
141 self.expect("\^done,value=\"1\"")
142 self.runCmd("-exec-continue")
143 self.expect("\^running")
145 # Test that *stopped is printed
146 # Note that message is different in Darwin and Linux:
147 # Darwin: "*stopped,reason=\"exception-received\",exception=\"EXC_BAD_ACCESS (code=1, address=0x0)\",thread-id=\"1\",stopped-threads=\"all\""
148 # Linux: "*stopped,reason=\"exception-received\",exception=\"invalid address (fault address: 0x0)\",thread-id=\"1\",stopped-threads=\"all\""
149 self.expect([ "\*stopped,reason=\"exception-received\",exception=\"EXC_BAD_ACCESS \(code=1, address=0x0\)\",thread-id=\"1\",stopped-threads=\"all\"",
150 "\*stopped,reason=\"exception-received\",exception=\"invalid address \(fault address: 0x0\)\",thread-id=\"1\",stopped-threads=\"all\"" ])
153 def test_lldbmi_stopped_when_segfault_remote(self):
154 """Test that 'lldb-mi --interpreter' notifies after it was stopped when segfault occurred (remote)."""
156 # Prepare debugserver
157 import lldbgdbserverutils
158 debugserver_exe = lldbgdbserverutils.get_debugserver_exe()
159 if not debugserver_exe:
160 self.skipTest("debugserver exe not found")
161 hostname = "localhost"
163 port = 12000 + random.randint(0,3999) # the same as GdbRemoteTestCaseBase.get_next_port
165 debugserver_child = pexpect.spawn("%s %s:%d" % (debugserver_exe, hostname, port))
166 self.addTearDownHook(lambda: debugserver_child.terminate(force = True))
168 self.spawnLldbMi(args = None)
170 # Connect to debugserver
171 self.runCmd("-interpreter-exec command \"platform select remote-macosx --sysroot /\"")
172 self.expect("\^done")
173 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
174 self.expect("\^done")
175 self.runCmd("-interpreter-exec command \"process connect connect://%s:%d\"" % (hostname, port))
176 self.expect("\^done")
179 self.runCmd("-break-insert -f main")
180 self.expect("\^done,bkpt={number=\"1\"")
181 #FIXME -exec-run doesn't work
182 self.runCmd("-interpreter-exec command \"process launch\"") #FIXME: self.runCmd("-exec-run")
183 self.expect("\^done") #FIXME: self.expect("\^running")
184 self.expect("\*stopped,reason=\"breakpoint-hit\"")
186 # Set do_segfault=1 and run (to cause a segfault error)
187 self.runCmd("-data-evaluate-expression \"do_segfault=1\"")
188 self.expect("\^done,value=\"1\"")
189 self.runCmd("-exec-continue")
190 self.expect("\^running")
192 # Test that *stopped is printed
193 self.expect("\*stopped,reason=\"exception-received\",exception=\"EXC_BAD_ACCESS \(code=1, address=0x0\)\",thread-id=\"1\",stopped-threads=\"all\"")
196 self.runCmd("-gdb-exit")
197 self.expect("\^exit")