]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/inferior-changed/TestInferiorChanged.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / inferior-changed / TestInferiorChanged.py
1 """Test lldb reloads the inferior after it was changed during the session."""
2
3 from __future__ import print_function
4
5
6 import os
7 import time
8 import lldb
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import configuration
12 from lldbsuite.test import lldbutil
13
14
15 class ChangedInferiorTestCase(TestBase):
16
17     mydir = TestBase.compute_mydir(__file__)
18
19     @skipIf(hostoslist=["windows"])
20     @no_debug_info_test
21     def test_inferior_crashing(self):
22         """Test lldb reloads the inferior after it was changed during the session."""
23         self.build()
24         self.inferior_crashing()
25         self.cleanup()
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
28         # 1 second delay.
29         time.sleep(1)
30         d = {'C_SOURCES': 'main2.c'}
31         self.build(dictionary=d)
32         self.setTearDownCleanup(dictionary=d)
33         self.inferior_not_crashing()
34
35     def setUp(self):
36         # Call super's setUp().
37         TestBase.setUp(self)
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.')
41
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)
46
47         self.runCmd("run", RUN_SUCCEEDED)
48
49         # We should have one crashing thread
50         self.assertEqual(
51             len(lldbutil.get_crashed_threads(self, self.dbg.GetSelectedTarget().GetProcess())),
52             1,
53             STOPPED_DUE_TO_EXC_BAD_ACCESS)
54
55         # And it should report the correct line number.
56         self.expect("thread backtrace all", substrs=['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         self.assertNotEqual(
65             len(lldbutil.get_crashed_threads(self, self.dbg.GetSelectedTarget().GetProcess())),
66             1,
67             "Inferior changed, but lldb did not perform a reload")
68
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)
72
73         self.runCmd("run", RUN_SUCCEEDED)
74
75         # The stop reason of the thread should be breakpoint.
76         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
77                     substrs=['stopped',
78                              'stop reason = breakpoint'])
79
80         self.runCmd("frame variable int_ptr")
81         self.expect("frame variable *int_ptr",
82                     substrs=['= 7'])
83         self.expect("expression *int_ptr",
84                     substrs=['= 7'])