TestInferiorAssert.py revision 5a7a23262e7f326162f4afd66ea494e9baa6bcb4
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 @expectedFailureLinux # bugzilla 15671 - backtrace does not include the assert site 195a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi def test_inferior_asserting_dwarf(self): 205a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi """Test that lldb reliably catches the inferior asserting (command).""" 215a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.buildDwarf() 225a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.inferior_asserting() 235a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 245a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 255a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi def test_inferior_asserting_registers_dsym(self): 265a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi """Test that lldb reliably reads registers from the inferior after asserting (command).""" 275a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.buildDsym() 285a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.inferior_asserting_registers() 295a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 305a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi def test_inferior_asserting_register_dwarf(self): 315a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi """Test that lldb reliably reads registers from the inferior after asserting (command).""" 325a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.buildDwarf() 335a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.inferior_asserting_registers() 345a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 355a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi @python_api_test 365a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi def test_inferior_asserting_python(self): 375a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi """Test that lldb reliably catches the inferior asserting (Python API).""" 385a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.buildDefault() 395a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.inferior_asserting_python() 405a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 415a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 425a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi def test_inferior_asserting_expr(self): 435a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi """Test that the lldb expression interpreter can read from the inferior after asserting (command).""" 445a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.buildDsym() 455a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.inferior_asserting_expr() 465a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 475a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi @expectedFailureLinux # bugzilla 15671 - backtrace does not include the assert site 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.buildDwarf() 515a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.inferior_asserting_expr() 525a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 535a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 545a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi def test_inferior_asserting_step(self): 555a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi """Test that lldb functions correctly after stepping through a call to assert().""" 565a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.buildDsym() 575a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.inferior_asserting_step() 585a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 595a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi @expectedFailureLinux # bugzilla 15671 - backtrace does not include the assert site 605a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi def test_inferior_asserting_step(self): 615a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi """Test that lldb functions correctly after stepping through a call to assert().""" 625a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.buildDwarf() 635a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.inferior_asserting_step() 645a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 655a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi def set_breakpoint(self, line): 665a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi lldbutil.run_break_set_by_file_and_line (self, "main.c", line, num_expected_locations=1, loc_exact=True) 675a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 685a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi def check_stop_reason(self): 695a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi stop_reason = 'stop reason = signal SIGABRT' 705a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 715a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi # The stop reason of the thread should be an abort signal or exception. 725a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.expect("thread list", STOPPED_DUE_TO_ASSERT, 735a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi substrs = ['stopped', 745a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi stop_reason]) 755a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 765a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi return stop_reason 775a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 785a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi def setUp(self): 795a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi # Call super's setUp(). 805a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi TestBase.setUp(self) 815a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi # Find the line number of the call to assert. 825a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.line = line_number('main.c', '// Assert here.') 835a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 845a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi def inferior_asserting(self): 855a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi """Inferior asserts upon launching; lldb should catch the event and stop.""" 865a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi exe = os.path.join(os.getcwd(), "a.out") 875a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 885a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 895a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.runCmd("run", RUN_SUCCEEDED) 905a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi stop_reason = self.check_stop_reason() 915a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 925a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi # And it should report a backtrace that includes the assert site. 935a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.expect("thread backtrace all", 945a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi substrs = [stop_reason, 'main', 'argc', 'argv']) 955a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 965a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi # And it should report the correct line number. 975a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.expect("thread backtrace all", 985a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi substrs = [stop_reason, 995a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 'main.c:%d' % self.line]) 1005a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1015a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi def inferior_asserting_python(self): 1025a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi """Inferior asserts upon launching; lldb should catch the event and stop.""" 1035a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi exe = os.path.join(os.getcwd(), "a.out") 1045a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1055a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi target = self.dbg.CreateTarget(exe) 1065a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.assertTrue(target, VALID_TARGET) 1075a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1085a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi # Now launch the process, and do not stop at entry point. 1095a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi # Both argv and envp are null. 1105a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi process = target.LaunchSimple(None, None, os.getcwd()) 1115a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1125a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi if process.GetState() != lldb.eStateStopped: 1135a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.fail("Process should be in the 'stopped' state, " 1145a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi "instead the actual state is: '%s'" % 1155a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi lldbutil.state_type_to_str(process.GetState())) 1165a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1175a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonSignal) 1185a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi if not thread: 1195a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.fail("Fail to stop the thread upon assert") 1205a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1215a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi if self.TraceOn(): 1225a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi lldbutil.print_stacktrace(thread) 1235a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1245a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi def inferior_asserting_registers(self): 1255a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi """Test that lldb can read registers after asserting.""" 1265a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi exe = os.path.join(os.getcwd(), "a.out") 1275a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 1285a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1295a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.runCmd("run", RUN_SUCCEEDED) 1305a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.check_stop_reason() 1315a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1325a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi # lldb should be able to read from registers from the inferior after asserting. 1335a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.expect("register read eax", 1345a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi substrs = ['eax = 0x']) 1355a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1365a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi def check_expr_in_main(self, thread): 1375a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi depth = thread.GetNumFrames() 1385a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi for i in range(depth): 1395a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi frame = thread.GetFrameAtIndex(i) 1405a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.assertTrue(frame.IsValid(), "current frame is valid") 1415a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi if self.TraceOn(): 1425a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi print "Checking if function %s is main" % frame.GetFunctionName() 1435a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1445a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi if 'main' == frame.GetFunctionName(): 1455a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi frame_id = frame.GetFrameID() 1465a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.runCmd("frame select " + str(frame_id), RUN_SUCCEEDED) 1475a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.expect("p argc", substrs = ['(int)', ' = 1']) 1485a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.expect("p hello_world", substrs = ['Hello']) 1495a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.expect("p argv[0]", substrs = ['a.out']) 1505a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.expect("p null_ptr", substrs = ['= 0x0']) 1515a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi return True 1525a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi return False 1535a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1545a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi def inferior_asserting_expr(self): 1555a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi """Test that the lldb expression interpreter can read symbols after asserting.""" 1565a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi exe = os.path.join(os.getcwd(), "a.out") 1575a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1585a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi # Create a target by the debugger. 1595a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi target = self.dbg.CreateTarget(exe) 1605a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.assertTrue(target, VALID_TARGET) 1615a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1625a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi # Launch the process, and do not stop at the entry point. 1635a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi target.LaunchSimple(None, None, os.getcwd()) 1645a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.check_stop_reason() 1655a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1665a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi process = target.GetProcess() 1675a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.assertTrue(process.IsValid(), "current process is valid") 1685a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1695a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi thread = process.GetThreadAtIndex(0) 1705a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.assertTrue(thread.IsValid(), "current thread is valid") 1715a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1725a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi # The lldb expression interpreter should be able to read from addresses of the inferior after a call to assert(). 1735a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.assertTrue(self.check_expr_in_main(thread), "cannot find 'main' in the backtrace") 1745a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1755a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi def inferior_asserting_step(self): 1765a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi """Test that lldb functions correctly after stepping through a call to assert().""" 1775a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi exe = os.path.join(os.getcwd(), "a.out") 1785a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1795a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi # Create a target by the debugger. 1805a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi target = self.dbg.CreateTarget(exe) 1815a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.assertTrue(target, VALID_TARGET) 1825a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1835a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi # Launch the process, and do not stop at the entry point. 1845a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.set_breakpoint(self.line) 1855a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi target.LaunchSimple(None, None, os.getcwd()) 1865a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1875a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 1885a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi substrs = ['main.c:%d' % self.line, 1895a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 'stop reason = breakpoint']) 1905a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1915a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.runCmd("next") 1925a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi stop_reason = self.check_stop_reason() 1935a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 1945a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi # lldb should be able to read from registers from the inferior after asserting. 1955a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi if "x86_64" in self.getArchitecture(): 1965a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.expect("register read rbp", substrs = ['rbp = 0x']) 1975a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi if "i386" in self.getArchitecture(): 1985a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.expect("register read ebp", substrs = ['ebp = 0x']) 1995a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 2005a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi process = target.GetProcess() 2015a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.assertTrue(process.IsValid(), "current process is valid") 2025a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 2035a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi thread = process.GetThreadAtIndex(0) 2045a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.assertTrue(thread.IsValid(), "current thread is valid") 2055a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 2065a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi # The lldb expression interpreter should be able to read from addresses of the inferior after a call to assert(). 2075a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.assertTrue(self.check_expr_in_main(thread), "cannot find 'main' in the backtrace") 2085a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 2095a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi # And it should report the correct line number. 2105a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi self.expect("thread backtrace all", 2115a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi substrs = [stop_reason, 2125a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 'main.c:%d' % self.line]) 2135a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi 2145a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthiif __name__ == '__main__': 2155a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi import atexit 2165a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi lldb.SBDebugger.Initialize() 2175a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi atexit.register(lambda: lldb.SBDebugger.Terminate()) 2185a7a23262e7f326162f4afd66ea494e9baa6bcb4Ashok Thirumurthi unittest2.main() 219