]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/tools/lldb-mi/signal/TestMiSignal.py
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / tools / lldb-mi / signal / TestMiSignal.py
1 """
2 Test that the lldb-mi handles signals properly.
3 """
4
5 from __future__ import print_function
6
7
8
9 import lldbmi_testcase
10 from lldbsuite.test.lldbtest import *
11
12 class MiSignalTestCase(lldbmi_testcase.MiTestCaseBase):
13
14     mydir = TestBase.compute_mydir(__file__)
15
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."""
20
21         self.spawnLldbMi(args = None)
22
23         # Load executable
24         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
25         self.expect("\^done")
26
27         # Run to main
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\"")
33
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")
39
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\"")
43
44         # Continue (to loop forever)
45         self.runCmd("-exec-continue")
46         self.expect("\^running")
47
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\"")
51
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)."""
57
58         self.spawnLldbMi(args = None)
59
60         # Load executable
61         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
62         self.expect("\^done")
63
64         # Run with stop-at-entry flag
65         self.runCmd("-interpreter-exec command \"process launch -s\"")
66         self.expect("\^done")
67
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\"" ])
74
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\"")
81
82     @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows
83     @skipUnlessDarwin
84     def test_lldbmi_stopped_when_stopatentry_remote(self):
85         """Test that 'lldb-mi --interpreter' notifies after it was stopped on entry (remote)."""
86
87         # Prepare debugserver
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"
93         import random
94         port = 12000 + random.randint(0,3999) # the same as GdbRemoteTestCaseBase.get_next_port
95         import pexpect
96         debugserver_child = pexpect.spawn("%s %s:%d" % (debugserver_exe, hostname, port))
97         self.addTearDownHook(lambda: debugserver_child.terminate(force = True))
98
99         self.spawnLldbMi(args = None)
100
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")
108
109         # Run with stop-at-entry flag
110         self.runCmd("-interpreter-exec command \"process launch -s\"")
111         self.expect("\^done")
112
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\"")
115
116         # Exit
117         self.runCmd("-gdb-exit")
118         self.expect("\^exit")
119
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)."""
125
126         self.spawnLldbMi(args = None)
127
128         # Load executable
129         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
130         self.expect("\^done")
131
132         # Run to main
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\"")
138
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")
144
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\"" ])
151
152     @skipUnlessDarwin
153     def test_lldbmi_stopped_when_segfault_remote(self):
154         """Test that 'lldb-mi --interpreter' notifies after it was stopped when segfault occurred (remote)."""
155
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"
162         import random
163         port = 12000 + random.randint(0,3999) # the same as GdbRemoteTestCaseBase.get_next_port
164         import pexpect
165         debugserver_child = pexpect.spawn("%s %s:%d" % (debugserver_exe, hostname, port))
166         self.addTearDownHook(lambda: debugserver_child.terminate(force = True))
167
168         self.spawnLldbMi(args = None)
169
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")
177
178         # Run to main
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\"")
185
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")
191
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\"")
194
195         # Exit
196         self.runCmd("-gdb-exit")
197         self.expect("\^exit")