Home | History | Annotate | Download | only in vector
      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 LibcxxVectorDataFormatterTestCase(TestBase):
     12 
     13     mydir = os.path.join("functionalities", "data-formatter", "data-formatter-stl", "libcxx", "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     @skipIfLinux # No standard locations for libc++ on Linux, so skip for now 
     23     @dwarf_test
     24     def test_with_dwarf_and_run_command(self):
     25         """Test data formatter commands."""
     26         self.buildDwarf()
     27         self.data_formatter_commands()
     28 
     29     def setUp(self):
     30         # Call super's setUp().
     31         TestBase.setUp(self)
     32         # Find the line number to break at.
     33         self.line = line_number('main.cpp', '// Set break point at this line.')
     34         self.line2 = line_number('main.cpp', '// Set second break point at this line.')
     35 
     36     def data_formatter_commands(self):
     37         """Test that that file and class static variables display correctly."""
     38         self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
     39 
     40         lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=-1)
     41         lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line2, num_expected_locations=-1)
     42 
     43         self.runCmd("run", RUN_SUCCEEDED)
     44 
     45         # The stop reason of the thread should be breakpoint.
     46         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
     47             substrs = ['stopped',
     48                        'stop reason = breakpoint'])
     49 
     50         # This is the function to remove the custom formats in order to have a
     51         # clean slate for the next test case.
     52         def cleanup():
     53             self.runCmd('type format clear', check=False)
     54             self.runCmd('type summary clear', check=False)
     55             self.runCmd('type filter clear', check=False)
     56             self.runCmd('type synth clear', check=False)
     57             self.runCmd("settings set target.max-children-count 256", check=False)
     58 
     59         # Execute the cleanup function during test case tear down.
     60         self.addTearDownHook(cleanup)
     61 
     62         # empty vectors (and storage pointers SHOULD BOTH BE NULL..)
     63         self.expect("frame variable numbers",
     64             substrs = ['numbers = size=0'])
     65 
     66         self.runCmd("n")
     67         
     68         # first value added
     69         self.expect("frame variable numbers",
     70                     substrs = ['numbers = size=1',
     71                                '[0] = 1',
     72                                '}'])
     73 
     74         # add some more data
     75         self.runCmd("n");self.runCmd("n");self.runCmd("n");
     76     
     77         self.expect("frame variable numbers",
     78                     substrs = ['numbers = size=4',
     79                                '[0] = 1',
     80                                '[1] = 12',
     81                                '[2] = 123',
     82                                '[3] = 1234',
     83                                '}'])
     84 
     85         self.expect("p numbers",
     86                     substrs = ['$', 'size=4',
     87                                '[0] = 1',
     88                                '[1] = 12',
     89                                '[2] = 123',
     90                                '[3] = 1234',
     91                                '}'])
     92 
     93         
     94         # check access to synthetic children
     95         self.runCmd("type summary add --summary-string \"item 0 is ${var[0]}\" std::int_vect int_vect")
     96         self.expect('frame variable numbers',
     97                     substrs = ['item 0 is 1']);
     98         
     99         self.runCmd("type summary add --summary-string \"item 0 is ${svar[0]}\" std::int_vect int_vect")
    100         self.expect('frame variable numbers',
    101                     substrs = ['item 0 is 1']);
    102         # move on with synths
    103         self.runCmd("type summary delete std::int_vect")
    104         self.runCmd("type summary delete int_vect")
    105 
    106         # add some more data
    107         self.runCmd("n");self.runCmd("n");self.runCmd("n");
    108 
    109         self.expect("frame variable numbers",
    110                     substrs = ['numbers = size=7',
    111                                '[0] = 1',
    112                                '[1] = 12',
    113                                '[2] = 123',
    114                                '[3] = 1234',
    115                                '[4] = 12345',
    116                                '[5] = 123456',
    117                                '[6] = 1234567',
    118                                '}'])
    119             
    120         self.expect("p numbers",
    121                     substrs = ['$', 'size=7',
    122                                '[0] = 1',
    123                                '[1] = 12',
    124                                '[2] = 123',
    125                                '[3] = 1234',
    126                                '[4] = 12345',
    127                                '[5] = 123456',
    128                                '[6] = 1234567',
    129                                '}'])
    130 
    131         # check access-by-index
    132         self.expect("frame variable numbers[0]",
    133                     substrs = ['1']);
    134         self.expect("frame variable numbers[1]",
    135                     substrs = ['12']);
    136         self.expect("frame variable numbers[2]",
    137                     substrs = ['123']);
    138         self.expect("frame variable numbers[3]",
    139                     substrs = ['1234']);
    140 
    141         # clear out the vector and see that we do the right thing once again
    142         self.runCmd("n")
    143 
    144         self.expect("frame variable numbers",
    145             substrs = ['numbers = size=0'])
    146 
    147         self.runCmd("n")
    148 
    149         # first value added
    150         self.expect("frame variable numbers",
    151                     substrs = ['numbers = size=1',
    152                                '[0] = 7',
    153                                '}'])
    154 
    155         # check if we can display strings
    156         self.runCmd("c")
    157 
    158         self.expect("frame variable strings",
    159             substrs = ['goofy',
    160                        'is',
    161                        'smart'])
    162 
    163         self.expect("p strings",
    164                     substrs = ['goofy',
    165                                'is',
    166                                'smart'])
    167 
    168         # test summaries based on synthetic children
    169         self.runCmd("type summary add std::string_vect string_vect --summary-string \"vector has ${svar%#} items\" -e")
    170         self.expect("frame variable strings",
    171                     substrs = ['vector has 3 items',
    172                                'goofy',
    173                                'is',
    174                                'smart'])
    175 
    176         self.expect("p strings",
    177                     substrs = ['vector has 3 items',
    178                                'goofy',
    179                                'is',
    180                                'smart'])
    181 
    182         self.runCmd("n")
    183 
    184         self.expect("frame variable strings",
    185                     substrs = ['vector has 4 items'])
    186         
    187         # check access-by-index
    188         self.expect("frame variable strings[0]",
    189                     substrs = ['goofy']);
    190         self.expect("frame variable strings[1]",
    191                     substrs = ['is']);
    192 
    193         self.runCmd("n")
    194 
    195         self.expect("frame variable strings",
    196             substrs = ['vector has 0 items'])
    197 
    198 if __name__ == '__main__':
    199     import atexit
    200     lldb.SBDebugger.Initialize()
    201     atexit.register(lambda: lldb.SBDebugger.Terminate())
    202     unittest2.main()
    203