1 """ 2 Test lldb data formatter subsystem. 3 """ 4 5 import os, time 6 import unittest2 7 import lldb 8 from lldbtest import * 9 import lldbutil 10 11 class StdVectorDataFormatterTestCase(TestBase): 12 13 mydir = os.path.join("functionalities", "data-formatter", "data-formatter-stl", "libstdcpp", "vector") 14 15 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 16 @dsym_test 17 def test_with_dsym_and_run_command(self): 18 """Test data formatter commands.""" 19 self.buildDsym() 20 self.data_formatter_commands() 21 22 @dwarf_test 23 @expectedFailureClang # llvm.org/pr15301 LLDB prints incorrect sizes of STL containers 24 @expectedFailureIcc # llvm.org/pr15301 LLDB prints incorrect sizes of STL containers 25 def test_with_dwarf_and_run_command(self): 26 """Test data formatter commands.""" 27 if "gcc" in self.getCompiler() and "4.8" in self.getCompilerVersion(): 28 self.skipTest("llvm.org/pr15301 LLDB prints incorrect sizes of STL containers") 29 self.buildDwarf() 30 self.data_formatter_commands() 31 32 def setUp(self): 33 # Call super's setUp(). 34 TestBase.setUp(self) 35 # Find the line number to break at. 36 self.line = line_number('main.cpp', '// Set break point at this line.') 37 38 def data_formatter_commands(self): 39 """Test that that file and class static variables display correctly.""" 40 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) 41 42 lldbutil.run_break_set_by_source_regexp (self, "Set break point at this line.") 43 44 self.runCmd("run", RUN_SUCCEEDED) 45 46 # The stop reason of the thread should be breakpoint. 47 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 48 substrs = ['stopped', 49 'stop reason = breakpoint']) 50 51 # This is the function to remove the custom formats in order to have a 52 # clean slate for the next test case. 53 def cleanup(): 54 self.runCmd('type format clear', check=False) 55 self.runCmd('type summary clear', check=False) 56 self.runCmd('type filter clear', check=False) 57 self.runCmd('type synth clear', check=False) 58 self.runCmd("settings set target.max-children-count 256", check=False) 59 60 # Execute the cleanup function during test case tear down. 61 self.addTearDownHook(cleanup) 62 63 # empty vectors (and storage pointers SHOULD BOTH BE NULL..) 64 self.expect("frame variable numbers", 65 substrs = ['numbers = size=0']) 66 67 self.runCmd("c") 68 69 # first value added 70 self.expect("frame variable numbers", 71 substrs = ['numbers = size=1', 72 '[0] = 1', 73 '}']) 74 75 # add some more data 76 self.runCmd("c"); 77 78 self.expect("frame variable numbers", 79 substrs = ['numbers = size=4', 80 '[0] = 1', 81 '[1] = 12', 82 '[2] = 123', 83 '[3] = 1234', 84 '}']) 85 86 self.expect("p numbers", 87 substrs = ['$', 'size=4', 88 '[0] = 1', 89 '[1] = 12', 90 '[2] = 123', 91 '[3] = 1234', 92 '}']) 93 94 95 # check access to synthetic children 96 self.runCmd("type summary add --summary-string \"item 0 is ${var[0]}\" std::int_vect int_vect") 97 self.expect('frame variable numbers', 98 substrs = ['item 0 is 1']); 99 100 self.runCmd("type summary add --summary-string \"item 0 is ${svar[0]}\" std::int_vect int_vect") 101 #import time 102 #time.sleep(19) 103 self.expect('frame variable numbers', 104 substrs = ['item 0 is 1']); 105 # move on with synths 106 self.runCmd("type summary delete std::int_vect") 107 self.runCmd("type summary delete int_vect") 108 109 # add some more data 110 self.runCmd("c"); 111 112 self.expect("frame variable numbers", 113 substrs = ['numbers = size=7', 114 '[0] = 1', 115 '[1] = 12', 116 '[2] = 123', 117 '[3] = 1234', 118 '[4] = 12345', 119 '[5] = 123456', 120 '[6] = 1234567', 121 '}']) 122 123 self.expect("p numbers", 124 substrs = ['$', 'size=7', 125 '[0] = 1', 126 '[1] = 12', 127 '[2] = 123', 128 '[3] = 1234', 129 '[4] = 12345', 130 '[5] = 123456', 131 '[6] = 1234567', 132 '}']) 133 134 # check access-by-index 135 self.expect("frame variable numbers[0]", 136 substrs = ['1']); 137 self.expect("frame variable numbers[1]", 138 substrs = ['12']); 139 self.expect("frame variable numbers[2]", 140 substrs = ['123']); 141 self.expect("frame variable numbers[3]", 142 substrs = ['1234']); 143 144 # but check that expression does not rely on us 145 # (when expression gets to call into STL code correctly, we will have to find 146 # another way to check this) 147 self.expect("expression numbers[6]", matching=False, error=True, 148 substrs = ['1234567']) 149 150 # check that MightHaveChildren() gets it right 151 self.assertTrue(self.frame().FindVariable("numbers").MightHaveChildren(), "numbers.MightHaveChildren() says False for non empty!") 152 153 # clear out the vector and see that we do the right thing once again 154 self.runCmd("c") 155 156 self.expect("frame variable numbers", 157 substrs = ['numbers = size=0']) 158 159 self.runCmd("c") 160 161 # first value added 162 self.expect("frame variable numbers", 163 substrs = ['numbers = size=1', 164 '[0] = 7', 165 '}']) 166 167 # check if we can display strings 168 self.runCmd("c") 169 170 self.expect("frame variable strings", 171 substrs = ['goofy', 172 'is', 173 'smart']) 174 175 self.expect("p strings", 176 substrs = ['goofy', 177 'is', 178 'smart']) 179 180 # test summaries based on synthetic children 181 self.runCmd("type summary add std::string_vect string_vect --summary-string \"vector has ${svar%#} items\" -e") 182 self.expect("frame variable strings", 183 substrs = ['vector has 3 items', 184 'goofy', 185 'is', 186 'smart']) 187 188 self.expect("p strings", 189 substrs = ['vector has 3 items', 190 'goofy', 191 'is', 192 'smart']) 193 194 self.runCmd("c"); 195 196 self.expect("frame variable strings", 197 substrs = ['vector has 4 items']) 198 199 # check access-by-index 200 self.expect("frame variable strings[0]", 201 substrs = ['goofy']); 202 self.expect("frame variable strings[1]", 203 substrs = ['is']); 204 205 # but check that expression does not rely on us 206 # (when expression gets to call into STL code correctly, we will have to find 207 # another way to check this) 208 self.expect("expression strings[0]", matching=False, error=True, 209 substrs = ['goofy']) 210 211 # check that MightHaveChildren() gets it right 212 self.assertTrue(self.frame().FindVariable("strings").MightHaveChildren(), "strings.MightHaveChildren() says False for non empty!") 213 214 self.runCmd("c") 215 216 self.expect("frame variable strings", 217 substrs = ['vector has 0 items']) 218 219 if __name__ == '__main__': 220 import atexit 221 lldb.SBDebugger.Initialize() 222 atexit.register(lambda: lldb.SBDebugger.Terminate()) 223 unittest2.main() 224