113 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 PtrMatchingDataFormatterTestCase(TestBase):13 def setUp(self):14 # Call super's setUp().15 TestBase.setUp(self)16 # Find the line number to break at.17 self.line = line_number("main.cpp", "// Set break point at this line.")18 19 def test_summary_with_command(self):20 """Test "type summary add" command line option "--pointer-match-depth"."""21 self.build()22 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)23 24 lldbutil.run_break_set_by_file_and_line(25 self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True26 )27 28 self.runCmd("run", RUN_SUCCEEDED)29 30 # This is the function to remove the custom formats in order to have a31 # clean slate for the next test case.32 def cleanup():33 self.runCmd("type format clear", check=False)34 self.runCmd("type summary clear", check=False)35 36 # Execute the cleanup function during test case tear down.37 self.addTearDownHook(cleanup)38 39 # By default, --pointer-match-depth is 1.40 self.runCmd('type summary add --cascade true -s "MyInt" "Int"')41 self.expect(42 "frame variable",43 patterns=[44 r".* i = MyInt\n",45 r".* i_p = 0x.* MyInt\n",46 r".* i_pp = 0x[0-9a-f]+\n",47 r".* i_ppp = 0x[0-9a-f]+\n",48 r".* f = MyInt\n",49 r".* f_p = 0x[0-9a-f]+ MyInt\n",50 r".* f_pp = 0x[0-9a-f]+\n",51 r".* f_ppp = 0x[0-9a-f]+\n",52 r".* fp = 0x[0-9a-f]+ MyInt\n",53 r".* fp_p = 0x[0-9a-f]+\n",54 r".* fp_pp = 0x[0-9a-f]+\n",55 r".* b = MyInt\n",56 r".* b_p = 0x[0-9a-f]+ MyInt\n",57 r".* b_pp = 0x[0-9a-f]+\n",58 r".* bp = 0x[0-9a-f]+ MyInt\n",59 r".* bp_p = 0x[0-9a-f]+\n",60 r".* bp_pp = 0x[0-9a-f]+\n",61 ],62 )63 64 self.runCmd('type summary delete "Int"')65 self.runCmd(66 'type summary add --cascade true --pointer-match-depth 2 -s "MyInt" "Int"'67 )68 self.expect(69 "frame variable",70 patterns=[71 r".* i = MyInt\n",72 r".* i_p = 0x.* MyInt\n",73 r".* i_pp = 0x[0-9a-f]+ MyInt\n",74 r".* i_ppp = 0x[0-9a-f]+\n",75 r".* f = MyInt\n",76 r".* f_p = 0x[0-9a-f]+ MyInt\n",77 r".* f_pp = 0x[0-9a-f]+ MyInt\n",78 r".* f_ppp = 0x[0-9a-f]+\n",79 r".* fp = 0x[0-9a-f]+ MyInt\n",80 r".* fp_p = 0x[0-9a-f]+ MyInt\n",81 r".* fp_pp = 0x[0-9a-f]+\n",82 r".* b = MyInt\n",83 r".* b_p = 0x[0-9a-f]+ MyInt\n",84 r".* b_pp = 0x[0-9a-f]+ MyInt\n",85 r".* bp = 0x[0-9a-f]+ MyInt\n",86 r".* bp_p = 0x[0-9a-f]+ MyInt\n",87 r".* bp_pp = 0x[0-9a-f]+\n",88 ],89 )90 91 self.runCmd('type summary delete "Int"')92 self.runCmd(93 'type summary add --cascade true --pointer-match-depth 2 -s "MyFoo" "Foo"'94 )95 self.expect(96 "frame variable",97 patterns=[98 r".* f = MyFoo\n",99 r".* f_p = 0x[0-9a-f]+ MyFoo\n",100 r".* f_pp = 0x[0-9a-f]+ MyFoo\n",101 r".* f_ppp = 0x[0-9a-f]+\n",102 r".* fp = 0x[0-9a-f]+\n",103 r".* fp_p = 0x[0-9a-f]+\n",104 r".* fp_pp = 0x[0-9a-f]+\n",105 r".* b = MyFoo\n",106 r".* b_p = 0x[0-9a-f]+ MyFoo\n",107 r".* b_pp = 0x[0-9a-f]+ MyFoo\n",108 r".* bp = 0x[0-9a-f]+ MyFoo\n",109 r".* bp_p = 0x[0-9a-f]+ MyFoo\n",110 r".* bp_pp = 0x[0-9a-f]+\n",111 ],112 )113