TestInferiorChanged.py revision 431d839a33e9a274e705f7a268a1c9de2ffc2da2
1"""Test lldb reloads the inferior after it was changed during the session.""" 2 3import os, time 4import unittest2 5import lldb 6from lldbtest import * 7import lldbutil 8 9class ChangedInferiorTestCase(TestBase): 10 11 mydir = os.path.join("functionalities", "inferior-changed") 12 13 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 14 def test_inferior_crashing_dsym(self): 15 """Test lldb reloads the inferior after it was changed during the session.""" 16 self.buildDsym() 17 self.inferior_crashing() 18 self.cleanup() 19 d = {'C_SOURCES': 'main2.c'} 20 self.buildDsym(dictionary=d) 21 self.setTearDownCleanup(dictionary=d) 22 self.inferior_not_crashing() 23 24 def test_inferior_crashing_dwarf(self): 25 """Test lldb reloads the inferior after it was changed during the session.""" 26 self.buildDwarf() 27 self.inferior_crashing() 28 self.cleanup() 29 d = {'C_SOURCES': 'main2.c'} 30 self.buildDwarf(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 exe = os.path.join(os.getcwd(), "a.out") 44 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 45 46 self.runCmd("run", RUN_SUCCEEDED) 47 48 # The stop reason of the thread should be a bad access exception. 49 self.expect("thread list", STOPPED_DUE_TO_EXC_BAD_ACCESS, 50 substrs = ['stopped', 51 'stop reason = EXC_BAD_ACCESS']) 52 53 # And it should report the correct line number. 54 self.expect("thread backtrace all", 55 substrs = ['stop reason = EXC_BAD_ACCESS', 56 'main.c:%d' % self.line1]) 57 58 def inferior_not_crashing(self): 59 """Test lldb reloads the inferior after it was changed during the session.""" 60 self.runCmd("process kill") 61 self.runCmd("run", RUN_SUCCEEDED) 62 self.runCmd("process status") 63 64 if 'EXC_BAD_ACCESS' in self.res.GetOutput(): 65 self.fail("Inferior changed, but lldb did not perform a reload") 66 67 # Break inside the main. 68 lldbutil.run_break_set_by_file_and_line (self, "main2.c", self.line2, num_expected_locations=1, loc_exact=True) 69 70 self.runCmd("run", RUN_SUCCEEDED) 71 72 # The stop reason of the thread should be breakpoint. 73 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 74 substrs = ['stopped', 75 'stop reason = breakpoint']) 76 77 self.runCmd("frame variable int_ptr") 78 self.expect("frame variable *int_ptr", 79 substrs = ['= 7']) 80 self.expect("expression *int_ptr", 81 substrs = ['= 7']) 82 83 84if __name__ == '__main__': 85 import atexit 86 lldb.SBDebugger.Initialize() 87 atexit.register(lambda: lldb.SBDebugger.Terminate()) 88 unittest2.main() 89