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