1fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi"""Test that lldb functions correctly after the inferior has crashed while in a recursive routine."""
2fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
3fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthiimport os, time
4fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthiimport unittest2
5fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthiimport lldb, lldbutil
6fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthifrom lldbtest import *
7fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
8fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthiclass CrashingRecursiveInferiorTestCase(TestBase):
9fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
10fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    mydir = os.path.join("functionalities", "inferior-crashing", "recursive-inferior")
11fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
12fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
13fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def test_recursive_inferior_crashing_dsym(self):
14fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        """Test that lldb reliably catches the inferior crashing (command)."""
15fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.buildDsym()
16fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.recursive_inferior_crashing()
17fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
18fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    @expectedFailureLinux('llvm.org/pr15415', ['gcc', 'clang']) # partial backtrace with -fomit-frame-pointer with tool-chains that support this option
19fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def test_recursive_inferior_crashing_dwarf(self):
20fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        """Test that lldb reliably catches the inferior crashing (command)."""
21fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.buildDwarf()
22fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.recursive_inferior_crashing()
23fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
24fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
25fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def test_recursive_inferior_crashing_registers_dsym(self):
26fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        """Test that lldb reliably reads registers from the inferior after crashing (command)."""
27fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.buildDsym()
28fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.recursive_inferior_crashing_registers()
29fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
30fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def test_recursive_inferior_crashing_register_dwarf(self):
31fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        """Test that lldb reliably reads registers from the inferior after crashing (command)."""
32fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.buildDwarf()
33fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.recursive_inferior_crashing_registers()
34fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
35fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    @python_api_test
36fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def test_recursive_inferior_crashing_python(self):
37fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        """Test that lldb reliably catches the inferior crashing (Python API)."""
38fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.buildDefault()
39fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.recursive_inferior_crashing_python()
40fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
41fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
42fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def test_recursive_inferior_crashing_expr_dsym(self):
43fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        """Test that the lldb expression interpreter can read from the inferior after crashing (command)."""
44fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.buildDsym()
45fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.recursive_inferior_crashing_expr()
46fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
47fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def test_recursive_inferior_crashing_expr_dwarf(self):
48fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        """Test that the lldb expression interpreter can read from the inferior after crashing (command)."""
49fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.buildDwarf()
50fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.recursive_inferior_crashing_expr()
51fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
52fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
53fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def test_recursive_inferior_crashing_step_dsym(self):
54fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        """Test that lldb functions correctly after stepping through a crash."""
55fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.buildDsym()
56fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.recursive_inferior_crashing_step()
57fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
58fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def test_recursive_inferior_crashing_step_dwarf(self):
59fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        """Test that stepping after a crash behaves correctly."""
60fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.buildDwarf()
61fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.recursive_inferior_crashing_step()
62fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
63fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
64fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def test_recursive_inferior_crashing_step_after_break_dsym(self):
65fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        """Test that stepping after a crash behaves correctly."""
66fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.buildDsym()
67fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.recursive_inferior_crashing_step_after_break()
68fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
69fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def test_recursive_inferior_crashing_step_after_break_dwarf(self):
70fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        """Test that lldb functions correctly after stepping through a crash."""
71fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.buildDwarf()
72fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.recursive_inferior_crashing_step_after_break()
73fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
74fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
75fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def test_recursive_inferior_crashing_expr_step_and_expr_dsym(self):
76fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        """Test that lldb expressions work before and after stepping after a crash."""
77fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.buildDsym()
78fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.recursive_inferior_crashing_expr_step_expr()
79fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
80fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    @expectedFailureLinux # due to llvm.org/pr15415 with -fomit-frame-pointer, and pr15989 with ebp/rbp
81fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def test_recursive_inferior_crashing_expr_step_and_expr_dwarf(self):
82fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        """Test that lldb expressions work before and after stepping after a crash."""
83fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.buildDwarf()
84fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.recursive_inferior_crashing_expr_step_expr()
85fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
86fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def set_breakpoint(self, line):
87fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        lldbutil.run_break_set_by_file_and_line (self, "main.c", line, num_expected_locations=1, loc_exact=True)
88fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
89fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def check_stop_reason(self):
90fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        if sys.platform.startswith("darwin"):
91fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi            stop_reason = 'stop reason = EXC_BAD_ACCESS'
92fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        else:
93fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi            stop_reason = 'stop reason = invalid address'
94fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
95fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        # The stop reason of the thread should be a bad access exception.
96fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.expect("thread list", STOPPED_DUE_TO_EXC_BAD_ACCESS,
97fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi            substrs = ['stopped',
98fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi                       stop_reason])
99fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
100fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        return stop_reason
101fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
102fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def setUp(self):
103fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        # Call super's setUp().
104fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        TestBase.setUp(self)
105fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        # Find the line number of the crash.
106fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.line = line_number('main.c', '// Crash here.')
107fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
108fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def recursive_inferior_crashing(self):
109fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        """Inferior crashes upon launching; lldb should catch the event and stop."""
110fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        exe = os.path.join(os.getcwd(), "a.out")
111fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
112fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
113fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.runCmd("run", RUN_SUCCEEDED)
114fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        stop_reason = self.check_stop_reason()
115fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
116fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        # And it should report a backtrace that includes main and the crash site.
117fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.expect("thread backtrace all",
118fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi            substrs = [stop_reason, 'main', 'argc', 'argv', 'recursive_function'])
119fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
120fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        # And it should report the correct line number.
121fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.expect("thread backtrace all",
122fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi            substrs = [stop_reason,
123fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi                       'main.c:%d' % self.line])
124fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
125fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def recursive_inferior_crashing_python(self):
126fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        """Inferior crashes upon launching; lldb should catch the event and stop."""
127fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        exe = os.path.join(os.getcwd(), "a.out")
128fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
129fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        target = self.dbg.CreateTarget(exe)
130fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.assertTrue(target, VALID_TARGET)
131fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
132fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        # Now launch the process, and do not stop at entry point.
133fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        # Both argv and envp are null.
134fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        process = target.LaunchSimple(None, None, os.getcwd())
135fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
136fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        if process.GetState() != lldb.eStateStopped:
137fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi            self.fail("Process should be in the 'stopped' state, "
138fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi                      "instead the actual state is: '%s'" %
139fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi                      lldbutil.state_type_to_str(process.GetState()))
140fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
141fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonException)
142fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        if not thread:
143fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi            self.fail("Fail to stop the thread upon bad access exception")
144fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
145fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        if self.TraceOn():
146fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi            lldbutil.print_stacktrace(thread)
147fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
148fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def recursive_inferior_crashing_registers(self):
149fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        """Test that lldb can read registers after crashing."""
150fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        exe = os.path.join(os.getcwd(), "a.out")
151fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
152fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
153fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.runCmd("run", RUN_SUCCEEDED)
154fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.check_stop_reason()
155fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
156fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        # lldb should be able to read from registers from the inferior after crashing.
157fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.expect("register read eax",
158fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi            substrs = ['eax = 0x'])
159fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
160fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def recursive_inferior_crashing_expr(self):
161fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        """Test that the lldb expression interpreter can read symbols after crashing."""
162fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        exe = os.path.join(os.getcwd(), "a.out")
163fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
164fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
165fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.runCmd("run", RUN_SUCCEEDED)
166fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.check_stop_reason()
167fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
168fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        # The lldb expression interpreter should be able to read from addresses of the inferior after a crash.
169fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.expect("p i",
170fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi            startstr = '(int) $0 =')
171fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
172fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def recursive_inferior_crashing_step(self):
173fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        """Test that lldb functions correctly after stepping through a crash."""
174fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        exe = os.path.join(os.getcwd(), "a.out")
175fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
176fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
177fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.set_breakpoint(self.line)
178fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.runCmd("run", RUN_SUCCEEDED)
179fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
180fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
181fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi            substrs = ['main.c:%d' % self.line,
182fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi                       'stop reason = breakpoint'])
183fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
184fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.runCmd("next")
185fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        stop_reason = self.check_stop_reason()
186fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
187fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        # The lldb expression interpreter should be able to read from addresses of the inferior after a crash.
188fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.expect("p i",
189fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi            substrs = ['(int) $0 ='])
190fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
191fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        # lldb should be able to read from registers from the inferior after crashing.
192fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.expect("register read eax",
193fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi            substrs = ['eax = 0x'])
194fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
195fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        # And it should report the correct line number.
196fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.expect("thread backtrace all",
197fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi            substrs = [stop_reason,
198fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi                       'main.c:%d' % self.line])
199fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
200fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def recursive_inferior_crashing_step_after_break(self):
201fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        """Test that lldb behaves correctly when stepping after a crash."""
202fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        exe = os.path.join(os.getcwd(), "a.out")
203fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
204fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
205fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.runCmd("run", RUN_SUCCEEDED)
206fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.check_stop_reason()
207fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
208fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        expected_state = 'exited' # Provide the exit code.
209fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        if sys.platform.startswith("darwin"):
210fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi            expected_state = 'stopped' # TODO: Determine why 'next' and 'continue' have no effect after a crash.
211fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
212fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.expect("next",
213fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi            substrs = ['Process', expected_state])
214fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
215fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.expect("thread list", error=True,
216fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi            substrs = ['Process must be launched'])
217fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
218fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    def recursive_inferior_crashing_expr_step_expr(self):
219fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        """Test that lldb expressions work before and after stepping after a crash."""
220fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        exe = os.path.join(os.getcwd(), "a.out")
221fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
222fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
223fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.runCmd("run", RUN_SUCCEEDED)
224fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.check_stop_reason()
225fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
226fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        # The lldb expression interpreter should be able to read from addresses of the inferior after a crash.
227fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.expect("p null",
228fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi            startstr = '(char *) $0 = 0x0')
229fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
230fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.runCmd("next")
231fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
232fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        # The lldb expression interpreter should be able to read from addresses of the inferior after a step.
233fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.expect("p null",
234fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi            startstr = '(char *) $1 = 0x0')
235fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
236fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi        self.check_stop_reason()
237fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi
238fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthiif __name__ == '__main__':
239fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    import atexit
240fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    lldb.SBDebugger.Initialize()
241fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    atexit.register(lambda: lldb.SBDebugger.Terminate())
242fb323f00d6124ac71f10e8bb6fa26782f04c2411Ashok Thirumurthi    unittest2.main()
243