1 """Test lldb reloads the inferior after it was changed during the session."""
3 from __future__ import print_function
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import configuration
12 from lldbsuite.test import lldbutil
15 class ChangedInferiorTestCase(TestBase):
17 mydir = TestBase.compute_mydir(__file__)
19 @skipIf(hostoslist=["windows"])
21 def test_inferior_crashing(self):
22 """Test lldb reloads the inferior after it was changed during the session."""
24 self.inferior_crashing()
26 # lldb needs to recognize the inferior has changed. If lldb needs to check the
27 # new module timestamp, make sure it is not the same as the old one, so add a
30 d = {'C_SOURCES': 'main2.c'}
31 self.build(dictionary=d)
32 self.setTearDownCleanup(dictionary=d)
33 self.inferior_not_crashing()
36 # Call super's setUp().
38 # Find the line number of the crash.
39 self.line1 = line_number('main.c', '// Crash here.')
40 self.line2 = line_number('main2.c', '// Not crash here.')
42 def inferior_crashing(self):
43 """Inferior crashes upon launching; lldb should catch the event and stop."""
44 self.exe = os.path.join(os.getcwd(), "a.out")
45 self.runCmd("file " + self.exe, CURRENT_EXECUTABLE_SET)
47 self.runCmd("run", RUN_SUCCEEDED)
49 # We should have one crashing thread
51 len(lldbutil.get_crashed_threads(self, self.dbg.GetSelectedTarget().GetProcess())),
53 STOPPED_DUE_TO_EXC_BAD_ACCESS)
55 # And it should report the correct line number.
56 self.expect("thread backtrace all", substrs=['main.c:%d' % self.line1])
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")
65 len(lldbutil.get_crashed_threads(self, self.dbg.GetSelectedTarget().GetProcess())),
67 "Inferior changed, but lldb did not perform a reload")
69 # Break inside the main.
70 lldbutil.run_break_set_by_file_and_line(
71 self, "main2.c", self.line2, num_expected_locations=1, loc_exact=True)
73 self.runCmd("run", RUN_SUCCEEDED)
75 # The stop reason of the thread should be breakpoint.
76 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
78 'stop reason = breakpoint'])
80 self.runCmd("frame variable int_ptr")
81 self.expect("frame variable *int_ptr",
83 self.expect("expression *int_ptr",