1""" 2Test lldb data formatter subsystem. 3""" 4 5 6 7import lldb 8from lldbsuite.test.lldbtest import * 9import lldbsuite.test.lldbutil as lldbutil 10 11 12class NamedSummariesDataFormatterTestCase(TestBase): 13 14 mydir = TestBase.compute_mydir(__file__) 15 16 def setUp(self): 17 # Call super's setUp(). 18 TestBase.setUp(self) 19 # Find the line number to break at. 20 self.line = line_number('main.cpp', '// Set break point at this line.') 21 22 def test_with_run_command(self): 23 """Test that that file and class static variables display correctly.""" 24 self.build() 25 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) 26 27 lldbutil.run_break_set_by_file_and_line( 28 self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True) 29 30 self.runCmd("run", RUN_SUCCEEDED) 31 32 # The stop reason of the thread should be breakpoint. 33 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 34 substrs=['stopped', 35 'stop reason = breakpoint']) 36 37 # This is the function to remove the custom formats in order to have a 38 # clean slate for the next test case. 39 def cleanup(): 40 self.runCmd('type format clear', check=False) 41 self.runCmd('type summary clear', check=False) 42 43 # Execute the cleanup function during test case tear down. 44 self.addTearDownHook(cleanup) 45 46 self.runCmd( 47 "type summary add --summary-string \"AllUseIt: x=${var.x} {y=${var.y}} {z=${var.z}}\" --name AllUseIt") 48 self.runCmd( 49 "type summary add --summary-string \"First: x=${var.x} y=${var.y} dummy=${var.dummy}\" First") 50 self.runCmd( 51 "type summary add --summary-string \"Second: x=${var.x} y=${var.y%hex}\" Second") 52 self.runCmd( 53 "type summary add --summary-string \"Third: x=${var.x} z=${var.z}\" Third") 54 55 self.expect('type summary list', substrs=['AllUseIt']) 56 57 self.expect("frame variable first", 58 substrs=['First: x=12']) 59 60 self.expect("frame variable first --summary AllUseIt", 61 substrs=['AllUseIt: x=12']) 62 63 # We *DO NOT* remember the summary choice anymore 64 self.expect("frame variable first", matching=False, 65 substrs=['AllUseIt: x=12']) 66 self.expect("frame variable first", 67 substrs=['First: x=12']) 68 69 self.runCmd("thread step-over") # 2 70 71 self.expect("frame variable first", 72 substrs=['First: x=12']) 73 74 self.expect("frame variable first --summary AllUseIt", 75 substrs=['AllUseIt: x=12', 76 'y=34']) 77 78 self.expect("frame variable second --summary AllUseIt", 79 substrs=['AllUseIt: x=65', 80 'y=43.25']) 81 82 self.expect("frame variable third --summary AllUseIt", 83 substrs=['AllUseIt: x=96', 84 'z=', 85 'E']) 86 87 self.runCmd("thread step-over") # 3 88 89 self.expect("frame variable second", 90 substrs=['Second: x=65', 91 'y=0x']) 92 93 # <rdar://problem/11576143> decided that invalid summaries will raise an error 94 # instead of just defaulting to the base summary 95 self.expect( 96 "frame variable second --summary NoSuchSummary", 97 error=True, 98 substrs=['must specify a valid named summary']) 99 100 self.runCmd("thread step-over") 101 102 self.runCmd( 103 "type summary add --summary-string \"FirstAndFriends: x=${var.x} {y=${var.y}} {z=${var.z}}\" First --name FirstAndFriends") 104 105 self.expect("frame variable first", 106 substrs=['FirstAndFriends: x=12', 107 'y=34']) 108 109 self.runCmd("type summary delete First") 110 111 self.expect("frame variable first --summary FirstAndFriends", 112 substrs=['FirstAndFriends: x=12', 113 'y=34']) 114 115 self.expect("frame variable first", matching=True, 116 substrs=['x = 12', 117 'y = 34']) 118 119 self.runCmd("type summary delete FirstAndFriends") 120 self.expect("type summary delete NoSuchSummary", error=True) 121 self.runCmd("type summary delete AllUseIt") 122 123 self.expect("frame variable first", matching=False, 124 substrs=['FirstAndFriends']) 125 126 self.runCmd("thread step-over") # 4 127 128 self.expect("frame variable first", matching=False, 129 substrs=['FirstAndFriends: x=12', 130 'y=34']) 131