15a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi"""Test that lldb functions correctly after the inferior has asserted."""
25a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
35a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthiimport os, time
45a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthiimport unittest2
55a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthiimport lldb, lldbutil
65a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthifrom lldbtest import *
75a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
85a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthiclass AssertingInferiorTestCase(TestBase):
95a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
105a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    mydir = os.path.join("functionalities", "inferior-assert")
115a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
125a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
135a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    def test_inferior_asserting_dsym(self):
145a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        """Test that lldb reliably catches the inferior asserting (command)."""
155a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.buildDsym()
165a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.inferior_asserting()
175a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
185a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    def test_inferior_asserting_dwarf(self):
195a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        """Test that lldb reliably catches the inferior asserting (command)."""
205a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.buildDwarf()
215a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.inferior_asserting()
225a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
235a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
245a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    def test_inferior_asserting_registers_dsym(self):
255a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        """Test that lldb reliably reads registers from the inferior after asserting (command)."""
265a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.buildDsym()
275a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.inferior_asserting_registers()
285a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
295a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    def test_inferior_asserting_register_dwarf(self):
305a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        """Test that lldb reliably reads registers from the inferior after asserting (command)."""
315a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.buildDwarf()
325a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.inferior_asserting_registers()
335a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
34b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi    @skipIfGcc # Avoid xpasses as the verion of libc used on the gcc buildbot has the required function symbols.
35b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi    @expectedFailureLinux # ResolveSymbolContextForAddress can fail using ELF with stripped function symbols.
36b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi    def test_inferior_asserting_disassemble(self):
37b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi        """Test that lldb reliably disassemblers frames after asserting (command)."""
38b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi        self.buildDefault()
39b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi        self.inferior_asserting_disassemble()
40b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi
415a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    @python_api_test
425a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    def test_inferior_asserting_python(self):
435a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        """Test that lldb reliably catches the inferior asserting (Python API)."""
445a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.buildDefault()
455a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.inferior_asserting_python()
465a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
475a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
485a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    def test_inferior_asserting_expr(self):
495a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        """Test that the lldb expression interpreter can read from the inferior after asserting (command)."""
505a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.buildDsym()
515a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.inferior_asserting_expr()
525a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
535a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    def test_inferior_asserting_expr(self):
545a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        """Test that the lldb expression interpreter can read from the inferior after asserting (command)."""
555a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.buildDwarf()
565a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.inferior_asserting_expr()
575a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
585a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
595a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    def test_inferior_asserting_step(self):
605a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        """Test that lldb functions correctly after stepping through a call to assert()."""
615a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.buildDsym()
625a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.inferior_asserting_step()
635a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
645a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    def test_inferior_asserting_step(self):
655a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        """Test that lldb functions correctly after stepping through a call to assert()."""
665a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.buildDwarf()
675a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.inferior_asserting_step()
685a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
695a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    def set_breakpoint(self, line):
705a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        lldbutil.run_break_set_by_file_and_line (self, "main.c", line, num_expected_locations=1, loc_exact=True)
715a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
725a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    def check_stop_reason(self):
735a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        stop_reason = 'stop reason = signal SIGABRT'
745a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
755a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        # The stop reason of the thread should be an abort signal or exception.
765a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.expect("thread list", STOPPED_DUE_TO_ASSERT,
775a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi            substrs = ['stopped',
785a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi                       stop_reason])
795a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
805a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        return stop_reason
815a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
825a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    def setUp(self):
835a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        # Call super's setUp().
845a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        TestBase.setUp(self)
855a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        # Find the line number of the call to assert.
865a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.line = line_number('main.c', '// Assert here.')
875a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
885a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    def inferior_asserting(self):
895a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        """Inferior asserts upon launching; lldb should catch the event and stop."""
905a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        exe = os.path.join(os.getcwd(), "a.out")
915a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
925a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
935a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.runCmd("run", RUN_SUCCEEDED)
945a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        stop_reason = self.check_stop_reason()
955a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
965a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        # And it should report a backtrace that includes the assert site.
975a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.expect("thread backtrace all",
985a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi            substrs = [stop_reason, 'main', 'argc', 'argv'])
995a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
1005a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        # And it should report the correct line number.
1015a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.expect("thread backtrace all",
1025a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi            substrs = [stop_reason,
1035a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi                       'main.c:%d' % self.line])
1045a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
1055a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    def inferior_asserting_python(self):
1065a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        """Inferior asserts upon launching; lldb should catch the event and stop."""
1075a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        exe = os.path.join(os.getcwd(), "a.out")
1085a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
1095a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        target = self.dbg.CreateTarget(exe)
1105a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.assertTrue(target, VALID_TARGET)
1115a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
1125a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        # Now launch the process, and do not stop at entry point.
1135a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        # Both argv and envp are null.
1145a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        process = target.LaunchSimple(None, None, os.getcwd())
1155a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
1165a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        if process.GetState() != lldb.eStateStopped:
1175a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi            self.fail("Process should be in the 'stopped' state, "
1185a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi                      "instead the actual state is: '%s'" %
1195a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi                      lldbutil.state_type_to_str(process.GetState()))
1205a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
1215a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonSignal)
1225a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        if not thread:
1235a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi            self.fail("Fail to stop the thread upon assert")
1245a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
1255a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        if self.TraceOn():
1265a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi            lldbutil.print_stacktrace(thread)
1275a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
1285a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    def inferior_asserting_registers(self):
1295a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        """Test that lldb can read registers after asserting."""
1305a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        exe = os.path.join(os.getcwd(), "a.out")
1315a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
1325a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
1335a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.runCmd("run", RUN_SUCCEEDED)
1345a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.check_stop_reason()
1355a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
1365a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        # lldb should be able to read from registers from the inferior after asserting.
1375a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.expect("register read eax",
1385a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi            substrs = ['eax = 0x'])
1395a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
140b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi    def inferior_asserting_disassemble(self):
141b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi        """Test that lldb can disassemble frames after asserting."""
142b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi        exe = os.path.join(os.getcwd(), "a.out")
143b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi
144b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi        # Create a target by the debugger.
145b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi        target = self.dbg.CreateTarget(exe)
146b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi        self.assertTrue(target, VALID_TARGET)
147b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi
148b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi        # Launch the process, and do not stop at the entry point.
149b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi        target.LaunchSimple(None, None, os.getcwd())
150b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi        self.check_stop_reason()
151b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi
152b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi        process = target.GetProcess()
153b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi        self.assertTrue(process.IsValid(), "current process is valid")
154b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi
155b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi        thread = process.GetThreadAtIndex(0)
156b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi        self.assertTrue(thread.IsValid(), "current thread is valid")
157b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi
158b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi        # lldb should be able to disassemble frames from the inferior after asserting.
159b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi        for frame in thread:
160b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi            self.assertTrue(frame.IsValid(), "current frame is valid")
161b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi
162b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi            self.runCmd("frame select " + str(frame.GetFrameID()), RUN_SUCCEEDED)
163b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi
164b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi            self.expect("disassemble -a %s" % frame.GetPC(),
165b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi                substrs = ['->', frame.GetFunctionName()])
166b8a579f45729be8bfcfdb834bba7ac5cf51ecafcAshok Thirumurthi
1675a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    def check_expr_in_main(self, thread):
1685a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        depth = thread.GetNumFrames()
1695a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        for i in range(depth):
1705a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi            frame = thread.GetFrameAtIndex(i)
1715a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi            self.assertTrue(frame.IsValid(), "current frame is valid")
1725a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi            if self.TraceOn():
1735a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi                print "Checking if function %s is main" % frame.GetFunctionName()
1745a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
1755a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi            if 'main' == frame.GetFunctionName():
1765a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi                frame_id = frame.GetFrameID()
1775a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi                self.runCmd("frame select " + str(frame_id), RUN_SUCCEEDED)
1785a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi                self.expect("p argc", substrs = ['(int)', ' = 1'])
1795a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi                self.expect("p hello_world", substrs = ['Hello'])
1805a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi                self.expect("p argv[0]", substrs = ['a.out'])
1815a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi                self.expect("p null_ptr", substrs = ['= 0x0'])
1825a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi                return True
1835a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        return False
1845a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
1855a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    def inferior_asserting_expr(self):
1865a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        """Test that the lldb expression interpreter can read symbols after asserting."""
1875a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        exe = os.path.join(os.getcwd(), "a.out")
1885a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
1895a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        # Create a target by the debugger.
1905a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        target = self.dbg.CreateTarget(exe)
1915a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.assertTrue(target, VALID_TARGET)
1925a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
1935a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        # Launch the process, and do not stop at the entry point.
1945a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        target.LaunchSimple(None, None, os.getcwd())
1955a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.check_stop_reason()
1965a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
1975a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        process = target.GetProcess()
1985a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.assertTrue(process.IsValid(), "current process is valid")
1995a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
2005a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        thread = process.GetThreadAtIndex(0)
2015a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.assertTrue(thread.IsValid(), "current thread is valid")
2025a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
2035a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        # The lldb expression interpreter should be able to read from addresses of the inferior after a call to assert().
2045a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.assertTrue(self.check_expr_in_main(thread), "cannot find 'main' in the backtrace")
2055a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
2065a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    def inferior_asserting_step(self):
2075a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        """Test that lldb functions correctly after stepping through a call to assert()."""
2085a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        exe = os.path.join(os.getcwd(), "a.out")
2095a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
2105a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        # Create a target by the debugger.
2115a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        target = self.dbg.CreateTarget(exe)
2125a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.assertTrue(target, VALID_TARGET)
2135a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
2145a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        # Launch the process, and do not stop at the entry point.
2155a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.set_breakpoint(self.line)
2165a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        target.LaunchSimple(None, None, os.getcwd())
2175a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
2185a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
2195a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi            substrs = ['main.c:%d' % self.line,
2205a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi                       'stop reason = breakpoint'])
2215a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
2225a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.runCmd("next")
2235a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        stop_reason = self.check_stop_reason()
2245a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
2255a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        # lldb should be able to read from registers from the inferior after asserting.
2265a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        if "x86_64" in self.getArchitecture():
2275a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi            self.expect("register read rbp", substrs = ['rbp = 0x'])
2285a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        if "i386" in self.getArchitecture():
2295a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi            self.expect("register read ebp", substrs = ['ebp = 0x'])
2305a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
2315a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        process = target.GetProcess()
2325a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.assertTrue(process.IsValid(), "current process is valid")
2335a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
2345a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        thread = process.GetThreadAtIndex(0)
2355a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.assertTrue(thread.IsValid(), "current thread is valid")
2365a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
2375a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        # The lldb expression interpreter should be able to read from addresses of the inferior after a call to assert().
2385a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.assertTrue(self.check_expr_in_main(thread), "cannot find 'main' in the backtrace")
2395a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
2405a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        # And it should report the correct line number.
2415a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi        self.expect("thread backtrace all",
2425a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi            substrs = [stop_reason,
2435a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi                       'main.c:%d' % self.line])
2445a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi
2455a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthiif __name__ == '__main__':
2465a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    import atexit
2475a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    lldb.SBDebugger.Initialize()
2485a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    atexit.register(lambda: lldb.SBDebugger.Terminate())
2495a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi    unittest2.main()
250