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 AdvDataFormatterTestCase(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 self.runCmd( 43 "settings set target.max-children-count 256", 44 check=False) 45 46 # Execute the cleanup function during test case tear down. 47 self.addTearDownHook(cleanup) 48 49 self.runCmd("type summary add --summary-string \"pippo\" \"i_am_cool\"") 50 51 self.runCmd( 52 "type summary add --summary-string \"pluto\" -x \"i_am_cool[a-z]*\"") 53 54 self.expect("frame variable cool_boy", 55 substrs=['pippo']) 56 57 self.expect("frame variable cooler_boy", 58 substrs=['pluto']) 59 60 self.runCmd("type summary delete i_am_cool") 61 62 self.expect("frame variable cool_boy", 63 substrs=['pluto']) 64 65 self.runCmd("type summary clear") 66 67 self.runCmd( 68 "type summary add --summary-string \"${var[]}\" -x \"int \\[[0-9]\\]") 69 70 self.expect("frame variable int_array", 71 substrs=['1,2,3,4,5']) 72 73 # this will fail if we don't do [] as regex correctly 74 self.runCmd( 75 'type summary add --summary-string "${var[].integer}" "i_am_cool[]') 76 77 self.expect("frame variable cool_array", 78 substrs=['1,1,1,1,6']) 79 80 self.runCmd("type summary clear") 81 82 self.runCmd( 83 "type summary add --summary-string \"${var[1-0]%x}\" \"int\"") 84 85 self.expect("frame variable iAmInt", 86 substrs=['01']) 87 88 self.runCmd( 89 "type summary add --summary-string \"${var[0-1]%x}\" \"int\"") 90 91 self.expect("frame variable iAmInt", 92 substrs=['01']) 93 94 self.runCmd("type summary clear") 95 96 self.runCmd("type summary add --summary-string \"${var[0-1]%x}\" int") 97 self.runCmd( 98 "type summary add --summary-string \"${var[0-31]%x}\" float") 99 100 self.expect("frame variable *pointer", 101 substrs=['0x', 102 '2']) 103 104 # check fix for <rdar://problem/11338654> LLDB crashes when using a 105 # "type summary" that uses bitfields with no format 106 self.runCmd("type summary add --summary-string \"${var[0-1]}\" int") 107 self.expect("frame variable iAmInt", 108 substrs=['9 1']) 109 110 self.expect("frame variable cool_array[3].floating", 111 substrs=['0x']) 112 113 self.runCmd( 114 "type summary add --summary-string \"low bits are ${*var[0-1]} tgt is ${*var}\" \"int *\"") 115 116 self.expect("frame variable pointer", 117 substrs=['low bits are', 118 'tgt is 6']) 119 120 self.expect( 121 "frame variable int_array --summary-string \"${*var[0-1]}\"", 122 substrs=['3']) 123 124 self.runCmd("type summary clear") 125 126 self.runCmd( 127 'type summary add --summary-string \"${var[0-1]}\" -x \"int \[[0-9]\]\"') 128 129 self.expect("frame variable int_array", 130 substrs=['1,2']) 131 132 self.runCmd( 133 'type summary add --summary-string \"${var[0-1]}\" "int []"') 134 135 self.expect("frame variable int_array", 136 substrs=['1,2']) 137 138 # Test the patterns are matched in reverse-chronological order. 139 self.runCmd( 140 'type summary add --summary-string \"${var[2-3]}\" "int []"') 141 142 self.expect("frame variable int_array", 143 substrs=['3,4']) 144 145 self.runCmd("type summary clear") 146 147 self.runCmd("type summary add -c -x \"i_am_cool \[[0-9]\]\"") 148 self.runCmd("type summary add -c i_am_cool") 149 150 self.expect( 151 "frame variable cool_array", 152 substrs=[ 153 '[0]', 154 'integer', 155 'floating', 156 'character', 157 '[1]', 158 'integer', 159 'floating', 160 'character', 161 '[2]', 162 'integer', 163 'floating', 164 'character', 165 '[3]', 166 'integer', 167 'floating', 168 'character', 169 '[4]', 170 'integer', 171 'floating', 172 'character', 173 ]) 174 175 self.runCmd( 176 "type summary add --summary-string \"int = ${*var.int_pointer}, float = ${*var.float_pointer}\" IWrapPointers") 177 178 self.expect("frame variable wrapper", 179 substrs=['int = 4', 180 'float = 1.1']) 181 182 self.runCmd( 183 "type summary add --summary-string \"low bits = ${*var.int_pointer[2]}\" IWrapPointers -p") 184 185 self.expect("frame variable wrapper", 186 substrs=['low bits = 1']) 187 188 self.expect("frame variable *wrap_pointer", 189 substrs=['low bits = 1']) 190 191 self.runCmd("type summary clear") 192 193 self.expect( 194 "frame variable int_array --summary-string \"${var[0][0-2]%hex}\"", 195 substrs=[ 196 '0x', 197 '7']) 198 199 self.runCmd("type summary clear") 200 201 self.runCmd( 202 "type summary add --summary-string \"${*var[].x[0-3]%hex} is a bitfield on a set of integers\" -x \"SimpleWithPointers \[[0-9]\]\"") 203 204 self.expect( 205 "frame variable couple --summary-string \"${*var.sp.x[0-2]} are low bits of integer ${*var.sp.x}. If I pretend it is an array I get ${var.sp.x[0-5]}\"", 206 substrs=[ 207 '1 are low bits of integer 9.', 208 'If I pretend it is an array I get [9,']) 209 210 # if the summary has an error, we still display the value 211 self.expect( 212 "frame variable couple --summary-string \"${*var.sp.foo[0-2]\"", 213 substrs=[ 214 '(Couple) couple = {', 215 'x = 0x', 216 'y = 0x', 217 'z = 0x', 218 's = 0x']) 219 220 self.runCmd( 221 "type summary add --summary-string \"${*var.sp.x[0-2]} are low bits of integer ${*var.sp.x}. If I pretend it is an array I get ${var.sp.x[0-5]}\" Couple") 222 223 self.expect("frame variable sparray", 224 substrs=['[0x0000000f,0x0000000c,0x00000009]']) 225 226 # check that we can format a variable in a summary even if a format is 227 # defined for its datatype 228 self.runCmd("type format add -f hex int") 229 self.runCmd( 230 "type summary add --summary-string \"x=${var.x%d}\" Simple") 231 232 self.expect("frame variable a_simple_object", 233 substrs=['x=3']) 234 235 self.expect("frame variable a_simple_object", matching=False, 236 substrs=['0x0']) 237 238 # now check that the default is applied if we do not hand out a format 239 self.runCmd("type summary add --summary-string \"x=${var.x}\" Simple") 240 241 self.expect("frame variable a_simple_object", matching=False, 242 substrs=['x=3']) 243 244 self.expect("frame variable a_simple_object", matching=True, 245 substrs=['x=0x00000003']) 246 247 self.expect_var_path("constInt", value='0x0000002a') 248 249 self.expect_var_path("volatileInt", value='0x0000002b') 250 251 self.expect_var_path("constVolatileInt", value='0x0000002c') 252 253 # check that we can correctly cap the number of children shown 254 self.runCmd("settings set target.max-children-count 5") 255 256 self.expect('frame variable a_long_guy', matching=True, 257 substrs=['a_1', 258 'b_1', 259 'c_1', 260 'd_1', 261 'e_1', 262 '...']) 263 264 # check that no further stuff is printed (not ALL values are checked!) 265 self.expect('frame variable a_long_guy', matching=False, 266 substrs=['f_1', 267 'g_1', 268 'h_1', 269 'i_1', 270 'j_1', 271 'q_1', 272 'a_2', 273 'f_2', 274 't_2', 275 'w_2']) 276 277 self.runCmd("settings set target.max-children-count 1") 278 self.expect('frame variable a_long_guy', matching=True, 279 substrs=['a_1', 280 '...']) 281 self.expect('frame variable a_long_guy', matching=False, 282 substrs=['b_1', 283 'c_1', 284 'd_1', 285 'e_1']) 286 self.expect('frame variable a_long_guy', matching=False, 287 substrs=['f_1', 288 'g_1', 289 'h_1', 290 'i_1', 291 'j_1', 292 'q_1', 293 'a_2', 294 'f_2', 295 't_2', 296 'w_2']) 297 298 self.runCmd("settings set target.max-children-count 30") 299 self.expect('frame variable a_long_guy', matching=True, 300 substrs=['a_1', 301 'b_1', 302 'c_1', 303 'd_1', 304 'e_1', 305 'z_1', 306 'a_2', 307 'b_2', 308 'c_2', 309 'd_2', 310 '...']) 311 self.expect('frame variable a_long_guy', matching=False, 312 substrs=['e_2', 313 'n_2', 314 'r_2', 315 'i_2', 316 'k_2', 317 'o_2']) 318 319 # override the cap 320 self.expect( 321 'frame variable a_long_guy --show-all-children', 322 matching=True, 323 substrs=[ 324 'a_1', 325 'b_1', 326 'c_1', 327 'd_1', 328 'e_1', 329 'z_1', 330 'a_2', 331 'b_2', 332 'c_2', 333 'd_2']) 334 self.expect( 335 'frame variable a_long_guy --show-all-children', 336 matching=True, 337 substrs=[ 338 'e_2', 339 'i_2', 340 'k_2', 341 'n_2', 342 'o_2', 343 'r_2', 344 ]) 345 self.expect( 346 'frame variable a_long_guy --show-all-children', 347 matching=False, 348 substrs=['...']) 349