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