Home | History | Annotate | Download | only in map
      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 LibcxxMapDataFormatterTestCase(TestBase):
     12 
     13     mydir = os.path.join("functionalities", "data-formatter", "data-formatter-stl", "libcxx", "map")
     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 
     33     def data_formatter_commands(self):
     34         """Test that that file and class static variables display correctly."""
     35         self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
     36 
     37         lldbutil.run_break_set_by_source_regexp (self, "Set break point at this line.")
     38 
     39         self.runCmd("run", RUN_SUCCEEDED)
     40 
     41         # The stop reason of the thread should be breakpoint.
     42         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
     43             substrs = ['stopped',
     44                        'stop reason = breakpoint'])
     45 
     46         # This is the function to remove the custom formats in order to have a
     47         # clean slate for the next test case.
     48         def cleanup():
     49             self.runCmd('type format clear', check=False)
     50             self.runCmd('type summary clear', check=False)
     51             self.runCmd('type filter clear', check=False)
     52             self.runCmd('type synth clear', check=False)
     53             self.runCmd("settings set target.max-children-count 256", check=False)
     54 
     55         # Execute the cleanup function during test case tear down.
     56         self.addTearDownHook(cleanup)
     57 
     58         self.expect('image list',substrs=['libc++.1.dylib','libc++abi.dylib'])
     59 
     60         self.runCmd("frame variable ii --show-types")
     61                 
     62         self.expect('frame variable ii',
     63             substrs = ['size=0',
     64                        '{}'])
     65 
     66         self.runCmd("continue");
     67 
     68         self.expect('frame variable ii',
     69                     substrs = ['size=2',
     70                                '[0] = {',
     71                                'first = 0',
     72                                'second = 0',
     73                                '[1] = {',
     74                                'first = 1',
     75                                'second = 1'])
     76 
     77         self.runCmd("continue");
     78 
     79         self.expect('frame variable ii',
     80                     substrs = ['size=4',
     81                                '[2] = {',
     82                                'first = 2',
     83                                'second = 0',
     84                                '[3] = {',
     85                                'first = 3',
     86                                'second = 1'])
     87 
     88         self.runCmd("continue");
     89 
     90         self.expect("frame variable ii",
     91                     substrs = ['size=8',
     92                                '[5] = {',
     93                                'first = 5',
     94                                'second = 0',
     95                                '[7] = {',
     96                                'first = 7',
     97                                'second = 1'])
     98 
     99         self.expect("p ii",
    100                     substrs = ['size=8',
    101                                '[5] = {',
    102                                'first = 5',
    103                                'second = 0',
    104                                '[7] = {',
    105                                'first = 7',
    106                                'second = 1'])
    107 
    108         # check access-by-index
    109         self.expect("frame variable ii[0]",
    110                     substrs = ['first = 0',
    111                                'second = 0']);
    112         self.expect("frame variable ii[3]",
    113                     substrs = ['first =',
    114                                'second =']);
    115 
    116         # check that MightHaveChildren() gets it right
    117         self.assertTrue(self.frame().FindVariable("ii").MightHaveChildren(), "ii.MightHaveChildren() says False for non empty!")
    118 
    119         # check that the expression parser does not make use of
    120         # synthetic children instead of running code
    121         # TOT clang has a fix for this, which makes the expression command here succeed
    122         # since this would make the test fail or succeed depending on clang version in use
    123         # this is safer commented for the time being
    124         #self.expect("expression ii[8]", matching=False, error=True,
    125         #            substrs = ['1234567'])
    126 
    127         self.runCmd("continue");
    128         
    129         self.expect('frame variable ii',
    130                     substrs = ['size=0',
    131                                '{}'])
    132         
    133         self.runCmd("frame variable si --show-types")
    134 
    135         self.expect('frame variable si',
    136                     substrs = ['size=0',
    137                                '{}'])
    138 
    139         self.runCmd("continue");
    140 
    141         self.expect('frame variable si',
    142                     substrs = ['size=1',
    143                                '[0] = ',
    144                                'first = \"zero\"',
    145                                'second = 0'])
    146 
    147         self.runCmd("continue");
    148 
    149         self.expect("frame variable si",
    150                     substrs = ['size=4',
    151                                '[0] = ',
    152                                'first = \"zero\"',
    153                                'second = 0',
    154                                 '[1] = ',
    155                                 'first = \"one\"',
    156                                 'second = 1',
    157                                 '[2] = ',
    158                                 'first = \"two\"',
    159                                 'second = 2',
    160                                 '[3] = ',
    161                                 'first = \"three\"',
    162                                 'second = 3'])
    163 
    164         self.expect("p si",
    165                     substrs = ['size=4',
    166                                '[0] = ',
    167                                'first = \"zero\"',
    168                                'second = 0',
    169                                '[1] = ',
    170                                'first = \"one\"',
    171                                'second = 1',
    172                                '[2] = ',
    173                                'first = \"two\"',
    174                                'second = 2',
    175                                '[3] = ',
    176                                'first = \"three\"',
    177                                'second = 3'])
    178 
    179         # check that MightHaveChildren() gets it right
    180         self.assertTrue(self.frame().FindVariable("si").MightHaveChildren(), "si.MightHaveChildren() says False for non empty!")
    181 
    182         # check access-by-index
    183         self.expect("frame variable si[0]",
    184                     substrs = ['first = ', 'one',
    185                                'second = 1']);
    186         
    187         # check that the expression parser does not make use of
    188         # synthetic children instead of running code
    189         # TOT clang has a fix for this, which makes the expression command here succeed
    190         # since this would make the test fail or succeed depending on clang version in use
    191         # this is safer commented for the time being
    192         #self.expect("expression si[0]", matching=False, error=True,
    193         #            substrs = ['first = ', 'zero'])
    194 
    195         self.runCmd("continue");
    196         
    197         self.expect('frame variable si',
    198                     substrs = ['size=0',
    199                                '{}'])
    200 
    201         self.runCmd("continue");
    202         self.runCmd("frame variable is --show-types")
    203         
    204         self.expect('frame variable is',
    205                     substrs = ['size=0',
    206                                '{}'])
    207 
    208         self.runCmd("continue");
    209 
    210         self.expect("frame variable is",
    211                     substrs = ['size=4',
    212                                '[0] = ',
    213                                'second = \"goofy\"',
    214                                'first = 85',
    215                                '[1] = ',
    216                                'second = \"is\"',
    217                                'first = 1',
    218                                '[2] = ',
    219                                'second = \"smart\"',
    220                                'first = 2',
    221                                '[3] = ',
    222                                'second = \"!!!\"',
    223                                'first = 3'])
    224         
    225         self.expect("p is",
    226                     substrs = ['size=4',
    227                                '[0] = ',
    228                                'second = \"goofy\"',
    229                                'first = 85',
    230                                '[1] = ',
    231                                'second = \"is\"',
    232                                'first = 1',
    233                                '[2] = ',
    234                                'second = \"smart\"',
    235                                'first = 2',
    236                                '[3] = ',
    237                                'second = \"!!!\"',
    238                                'first = 3'])
    239 
    240         # check that MightHaveChildren() gets it right
    241         self.assertTrue(self.frame().FindVariable("is").MightHaveChildren(), "is.MightHaveChildren() says False for non empty!")
    242 
    243         # check access-by-index
    244         self.expect("frame variable is[0]",
    245                     substrs = ['first = ',
    246                                'second =']);
    247         
    248         # check that the expression parser does not make use of
    249         # synthetic children instead of running code
    250         # TOT clang has a fix for this, which makes the expression command here succeed
    251         # since this would make the test fail or succeed depending on clang version in use
    252         # this is safer commented for the time being
    253         #self.expect("expression is[0]", matching=False, error=True,
    254         #            substrs = ['first = ', 'goofy'])
    255 
    256         self.runCmd("continue");
    257         
    258         self.expect('frame variable is',
    259                     substrs = ['size=0',
    260                                '{}'])
    261 
    262         self.runCmd("continue");
    263         self.runCmd("frame variable ss --show-types")
    264         
    265         self.expect('frame variable ss',
    266                     substrs = ['size=0',
    267                                '{}'])
    268 
    269         self.runCmd("continue");
    270 
    271         self.expect("frame variable ss",
    272                     substrs = ['size=3',
    273                                '[0] = ',
    274                                'second = \"hello\"',
    275                                'first = \"ciao\"',
    276                                '[1] = ',
    277                                'second = \"house\"',
    278                                'first = \"casa\"',
    279                                '[2] = ',
    280                                'second = \"cat\"',
    281                                'first = \"gatto\"'])
    282         
    283         self.expect("p ss",
    284                     substrs = ['size=3',
    285                                '[0] = ',
    286                                'second = \"hello\"',
    287                                'first = \"ciao\"',
    288                                '[1] = ',
    289                                'second = \"house\"',
    290                                'first = \"casa\"',
    291                                '[2] = ',
    292                                'second = \"cat\"',
    293                                'first = \"gatto\"'])
    294 
    295         # check that MightHaveChildren() gets it right
    296         self.assertTrue(self.frame().FindVariable("ss").MightHaveChildren(), "ss.MightHaveChildren() says False for non empty!")
    297 
    298         # check access-by-index
    299         self.expect("frame variable ss[2]",
    300                     substrs = ['gatto', 'cat']);
    301         
    302         # check that the expression parser does not make use of
    303         # synthetic children instead of running code
    304         # TOT clang has a fix for this, which makes the expression command here succeed
    305         # since this would make the test fail or succeed depending on clang version in use
    306         # this is safer commented for the time being
    307         #self.expect("expression ss[3]", matching=False, error=True,
    308         #            substrs = ['gatto'])
    309 
    310         self.runCmd("continue");
    311         
    312         self.expect('frame variable ss',
    313                     substrs = ['size=0',
    314                                '{}'])
    315 
    316 if __name__ == '__main__':
    317     import atexit
    318     lldb.SBDebugger.Initialize()
    319     atexit.register(lambda: lldb.SBDebugger.Terminate())
    320     unittest2.main()
    321