brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.1 KiB · 91b249b Raw
184 lines · python
1"""2Test lldb data formatter subsystem.3"""4 5import os6import lldb7from lldbsuite.test.decorators import *8from lldbsuite.test.lldbtest import *9from lldbsuite.test import lldbutil10 11 12class SkipSummaryDataFormatterTestCase(TestBase):13    def test_with_run_command(self):14        """Test data formatter commands."""15        self.build()16        self.data_formatter_commands()17 18    def setUp(self):19        # Call super's setUp().20        TestBase.setUp(self)21        # Find the line number to break at.22        self.line = line_number("main.cpp", "// Set break point at this line.")23 24    def data_formatter_commands(self):25        """Test that that file and class static variables display correctly."""26        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)27 28        # import lldbsuite.test.lldbutil as lldbutil29        lldbutil.run_break_set_by_file_and_line(30            self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True31        )32 33        self.runCmd("run", RUN_SUCCEEDED)34 35        # The stop reason of the thread should be breakpoint.36        self.expect(37            "thread list",38            STOPPED_DUE_TO_BREAKPOINT,39            substrs=["stopped", "stop reason = breakpoint"],40        )41 42        # This is the function to remove the custom formats in order to have a43        # clean slate for the next test case.44        def cleanup():45            self.runCmd("type format clear", check=False)46            self.runCmd("type summary clear", check=False)47 48        # Execute the cleanup function during test case tear down.49        self.addTearDownHook(cleanup)50 51        # Setup the summaries for this scenario52        # self.runCmd("type summary add --summary-string \"${var._M_dataplus._M_p}\" std::string")53        self.runCmd('type summary add --summary-string "Level 1" "DeepData_1"')54        self.runCmd('type summary add --summary-string "Level 2" "DeepData_2" -e')55        self.runCmd('type summary add --summary-string "Level 3" "DeepData_3"')56        self.runCmd('type summary add --summary-string "Level 4" "DeepData_4"')57        self.runCmd('type summary add --summary-string "Level 5" "DeepData_5"')58 59        # Default case, just print out summaries60        self.expect(61            "frame variable",62            substrs=[63                "(DeepData_1) data1 = Level 1",64                "(DeepData_2) data2 = Level 2 {",65                "m_child1 = Level 3",66                "m_child2 = Level 3",67                "m_child3 = Level 3",68                "m_child4 = Level 3",69                "}",70            ],71        )72 73        # Skip the default (should be 1) levels of summaries74        self.expect(75            "frame variable --no-summary-depth",76            substrs=[77                "(DeepData_1) data1 = {",78                "m_child1 = 0x",79                "}",80                "(DeepData_2) data2 = {",81                "m_child1 = Level 3",82                "m_child2 = Level 3",83                "m_child3 = Level 3",84                "m_child4 = Level 3",85                "}",86            ],87        )88 89        # Now skip 2 levels of summaries90        self.expect(91            "frame variable --no-summary-depth=2",92            substrs=[93                "(DeepData_1) data1 = {",94                "m_child1 = 0x",95                "}",96                "(DeepData_2) data2 = {",97                "m_child1 = {",98                "m_child1 = 0x",99                "Level 4",100                "m_child2 = {",101                "m_child3 = {",102                "}",103            ],104        )105 106        # Check that no "Level 3" comes out107        self.expect(108            "frame variable data1.m_child1 --no-summary-depth=2",109            matching=False,110            substrs=["Level 3"],111        )112 113        # Now expand a pointer with 2 level of skipped summaries114        self.expect(115            "frame variable data1.m_child1 --no-summary-depth=2",116            substrs=["(DeepData_2 *) data1.m_child1 = 0x"],117        )118 119        # Deref and expand said pointer120        self.expect(121            "frame variable *data1.m_child1 --no-summary-depth=2",122            substrs=[123                "(DeepData_2) *data1.m_child1 = {",124                "m_child2 = {",125                "m_child1 = 0x",126                "Level 4",127                "}",128            ],129        )130 131        # Expand an expression, skipping 2 layers of summaries132        self.expect(133            "frame variable data1.m_child1->m_child2 --no-summary-depth=2",134            substrs=[135                "(DeepData_3) data1.m_child1->m_child2 = {",136                "m_child2 = {",137                "m_child1 = Level 5",138                "m_child2 = Level 5",139                "m_child3 = Level 5",140                "}",141            ],142        )143 144        # Expand same expression, skipping only 1 layer of summaries145        self.expect(146            "frame variable data1.m_child1->m_child2 --no-summary-depth=1",147            substrs=[148                "(DeepData_3) data1.m_child1->m_child2 = {",149                "m_child1 = 0x",150                "Level 4",151                "m_child2 = Level 4",152                "}",153            ],154        )155 156        # Expand same expression, skipping 3 layers of summaries157        self.expect(158            "frame variable data1.m_child1->m_child2 --show-types --no-summary-depth=3",159            substrs=[160                "(DeepData_3) data1.m_child1->m_child2 = {",161                'm_some_text = "Just a test"',162                "m_child2 = {",163                'm_some_text = "Just a test"',164            ],165        )166 167        # Change summary and expand, first without --no-summary-depth then with168        # --no-summary-depth169        self.runCmd('type summary add --summary-string "${var.m_some_text}" DeepData_5')170 171        self.expect(172            "fr var data2.m_child4.m_child2.m_child2",173            substrs=['(DeepData_5) data2.m_child4.m_child2.m_child2 = "Just a test"'],174        )175 176        self.expect(177            "fr var data2.m_child4.m_child2.m_child2 --no-summary-depth",178            substrs=[179                "(DeepData_5) data2.m_child4.m_child2.m_child2 = {",180                'm_some_text = "Just a test"',181                "}",182            ],183        )184