Home | History | Annotate | Download | only in rdar-12437442
      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 datetime
     10 import lldbutil
     11 
     12 class DataFormatterRdar12437442TestCase(TestBase):
     13 
     14     mydir = os.path.join("functionalities", "data-formatter", "rdar-12437442")
     15 
     16     @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
     17     @dsym_test
     18     def test_rdar12437442_with_dsym_and_run_command(self):
     19         """Test that we update SBValues correctly as dynamic types change."""
     20         self.buildDsym()
     21         self.rdar12437442_tester()
     22 
     23     @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
     24     @dwarf_test
     25     def test_rdar12437442_with_dwarf_and_run_command(self):
     26         """Test that we update SBValues correctly as dynamic types change."""
     27         self.buildDwarf()
     28         self.rdar12437442_tester()
     29 
     30     def setUp(self):
     31         # Call super's setUp().
     32         TestBase.setUp(self)
     33         # Find the line number to break at.
     34         self.line = line_number('main.m', '// Set break point at this line.')
     35 
     36     def rdar12437442_tester(self):
     37         """Test that we update SBValues correctly as dynamic types change."""
     38         self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
     39 
     40         lldbutil.run_break_set_by_file_and_line (self, "main.m", self.line, num_expected_locations=1, loc_exact=True)
     41 
     42         self.runCmd("run", RUN_SUCCEEDED)
     43 
     44         # The stop reason of the thread should be breakpoint.
     45         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
     46             substrs = ['stopped',
     47                        'stop reason = breakpoint'])
     48 
     49         # This is the function to remove the custom formats in order to have a
     50         # clean slate for the next test case.
     51         def cleanup():
     52             self.runCmd('type format clear', check=False)
     53             self.runCmd('type summary clear', check=False)
     54             self.runCmd('type synth clear', check=False)
     55 
     56         # Execute the cleanup function during test case tear down.
     57         self.addTearDownHook(cleanup)
     58 
     59         self.runCmd("log enable lldb types -f types.log")
     60 
     61         # Now run the bulk of the test
     62         id_x = self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread().GetSelectedFrame().FindVariable("x")
     63         id_x.SetPreferDynamicValue(lldb.eDynamicCanRunTarget)
     64         id_x.SetPreferSyntheticValue(True)
     65         
     66         if self.TraceOn():
     67             self.runCmd("expr --dynamic-type run-target --ptr-depth 1 -- x")
     68 
     69         self.assertTrue(id_x.GetSummary() == '@"5 objects"', "array does not get correct summary")
     70 
     71         self.runCmd("next")
     72         self.runCmd("frame select 0")
     73 
     74         id_x = self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread().GetSelectedFrame().FindVariable("x")
     75         id_x.SetPreferDynamicValue(lldb.eDynamicCanRunTarget)
     76         id_x.SetPreferSyntheticValue(True)
     77 
     78         if self.TraceOn():
     79             self.runCmd("expr --dynamic-type run-target --ptr-depth 1 -- x")
     80 
     81         self.assertTrue(id_x.GetNumChildren() == 7, "dictionary does not have 7 children")
     82         id_x.SetPreferSyntheticValue(False)
     83         self.assertFalse(id_x.GetNumChildren() == 7, "dictionary still looks synthetic")
     84         id_x.SetPreferSyntheticValue(True)
     85         self.assertTrue(id_x.GetSummary() == "7 key/value pairs", "dictionary does not get correct summary")
     86 
     87 
     88 if __name__ == '__main__':
     89     import atexit
     90     lldb.SBDebugger.Initialize()
     91     atexit.register(lambda: lldb.SBDebugger.Terminate())
     92     unittest2.main()
     93