1"""Test lldb reloads the inferior after it was changed during the session.""" 2 3 4 5import time 6import lldb 7from lldbsuite.test.decorators import * 8from lldbsuite.test.lldbtest import * 9from lldbsuite.test import configuration 10from lldbsuite.test import lldbutil 11 12 13class ChangedInferiorTestCase(TestBase): 14 15 mydir = TestBase.compute_mydir(__file__) 16 17 @skipIf(hostoslist=["windows"]) 18 @no_debug_info_test 19 @skipIfReproducer # VFS is a snapshot. 20 def test_inferior_crashing(self): 21 """Test lldb reloads the inferior after it was changed during the session.""" 22 self.build() 23 self.inferior_crashing() 24 self.cleanup() 25 # lldb needs to recognize the inferior has changed. If lldb needs to check the 26 # new module timestamp, make sure it is not the same as the old one, so add a 27 # 1 second delay. 28 time.sleep(1) 29 d = {'C_SOURCES': 'main2.c'} 30 self.build(dictionary=d) 31 self.setTearDownCleanup(dictionary=d) 32 self.inferior_not_crashing() 33 34 def setUp(self): 35 # Call super's setUp(). 36 TestBase.setUp(self) 37 # Find the line number of the crash. 38 self.line1 = line_number('main.c', '// Crash here.') 39 self.line2 = line_number('main2.c', '// Not crash here.') 40 41 def inferior_crashing(self): 42 """Inferior crashes upon launching; lldb should catch the event and stop.""" 43 self.exe = self.getBuildArtifact("a.out") 44 self.runCmd("file " + self.exe, CURRENT_EXECUTABLE_SET) 45 46 self.runCmd("run", RUN_SUCCEEDED) 47 48 # We should have one crashing thread 49 self.assertEqual( 50 len(lldbutil.get_crashed_threads(self, self.dbg.GetSelectedTarget().GetProcess())), 51 1, 52 STOPPED_DUE_TO_EXC_BAD_ACCESS) 53 54 # And it should report the correct line number. 55 self.expect("thread backtrace all", substrs=['main.c:%d' % self.line1]) 56 57 def inferior_not_crashing(self): 58 """Test lldb reloads the inferior after it was changed during the session.""" 59 self.runCmd("process kill") 60 self.runCmd("run", RUN_SUCCEEDED) 61 self.runCmd("process status") 62 63 self.assertNotEqual( 64 len(lldbutil.get_crashed_threads(self, self.dbg.GetSelectedTarget().GetProcess())), 65 1, 66 "Inferior changed, but lldb did not perform a reload") 67 68 # Break inside the main. 69 lldbutil.run_break_set_by_file_and_line( 70 self, "main2.c", self.line2, num_expected_locations=1, loc_exact=True) 71 72 self.runCmd("run", RUN_SUCCEEDED) 73 74 # The stop reason of the thread should be breakpoint. 75 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 76 substrs=['stopped', 77 'stop reason = breakpoint']) 78 79 self.runCmd("frame variable int_ptr") 80 self.expect("frame variable *int_ptr", 81 substrs=['= 7']) 82 self.expect("expression *int_ptr", 83 substrs=['= 7']) 84