7d70ad3da9c424854e8ef5bb0816e81bfa41abd4
[openbsd] /
1 """
2 Test lldb data formatter subsystem.
3 """
4
5
6
7 import lldb
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 from lldbsuite.test import lldbutil
11
12
13 class TypeSummaryListScriptTestCase(TestBase):
14
15     mydir = TestBase.compute_mydir(__file__)
16
17     def test_typesummarylist_script(self):
18         """Test data formatter commands."""
19         self.build()
20         self.data_formatter_commands()
21
22     def setUp(self):
23         # Call super's setUp().
24         TestBase.setUp(self)
25         # Find the line number to break at.
26         self.line = line_number('main.cpp', 'Break here')
27
28     def data_formatter_commands(self):
29         """Test printing out Python summary formatters."""
30         self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
31
32         lldbutil.run_break_set_by_file_and_line(
33             self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
34
35         self.runCmd("run", RUN_SUCCEEDED)
36
37         # The stop reason of the thread should be breakpoint.
38         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
39                     substrs=['stopped',
40                              'stop reason = breakpoint'])
41
42         # This is the function to remove the custom formats in order to have a
43         # clean slate for the next test case.
44         def cleanup():
45             self.runCmd('type category delete TSLSFormatters', check=False)
46             self.runCmd('type format clear', check=False)
47             self.runCmd('type summary clear', check=False)
48             self.runCmd('type filter clear', check=False)
49             self.runCmd('type synth clear', check=False)
50
51         self.addTearDownHook(cleanup)
52
53         self.runCmd("command script import tslsformatters.py")
54
55         self.expect(
56             "frame variable myStruct",
57             substrs=['A data formatter at work'])
58
59         self.expect('type summary list', substrs=['Struct_SummaryFormatter'])
60         self.expect(
61             'type summary list Struct',
62             substrs=['Struct_SummaryFormatter'])