Home | History | Annotate | Download | only in foundation
      1 """
      2 Test SBValue.GetObjectDescription() with the value from SBTarget.FindGlobalVariables().
      3 """
      4 
      5 import os, time
      6 import re
      7 import unittest2
      8 import lldb, lldbutil
      9 from lldbtest import *
     10 
     11 class ObjectDescriptionAPITestCase(TestBase):
     12 
     13     mydir = os.path.join("lang", "objc", "foundation")
     14 
     15     # rdar://problem/10857337
     16     @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
     17     @python_api_test
     18     @dsym_test
     19     def test_find_global_variables_then_object_description_with_dsym(self):
     20         """Exercise SBTaget.FindGlobalVariables() API."""
     21         d = {'EXE': 'a.out'}
     22         self.buildDsym(dictionary=d)
     23         self.setTearDownCleanup(dictionary=d)
     24         self.find_global_variables_then_object_description('a.out')
     25 
     26     # rdar://problem/10857337
     27     @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
     28     @python_api_test
     29     @dwarf_test
     30     def test_find_global_variables_then_object_description_with_dwarf(self):
     31         """Exercise SBTarget.FindGlobalVariables() API."""
     32         d = {'EXE': 'b.out'}
     33         self.buildDwarf(dictionary=d)
     34         self.setTearDownCleanup(dictionary=d)
     35         self.find_global_variables_then_object_description('b.out')
     36 
     37     def setUp(self):
     38         # Call super's setUp().
     39         TestBase.setUp(self)
     40         # Find the line number to break at.
     41         self.source = 'main.m'
     42         self.line = line_number(self.source, '// Set break point at this line.')
     43 
     44     def find_global_variables_then_object_description(self, exe_name):
     45         """Exercise SBTaget.FindGlobalVariables() followed by SBValue.GetObjectDescription()."""
     46         exe = os.path.join(os.getcwd(), exe_name)
     47 
     48         # Create a target by the debugger.
     49         target = self.dbg.CreateTarget(exe)
     50         self.assertTrue(target, VALID_TARGET)
     51 
     52         breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
     53         self.assertTrue(breakpoint, VALID_BREAKPOINT)
     54 
     55         # Now launch the process, and do not stop at entry point.
     56         process = target.LaunchSimple(None, None, os.getcwd())
     57         self.assertTrue(process, PROCESS_IS_VALID)
     58         # Make sure we hit our breakpoint:
     59         thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint)
     60         self.assertTrue (len(thread_list) == 1)
     61 
     62         thread = thread_list[0]
     63         frame0 = thread.GetFrameAtIndex(0)
     64 
     65         # Note my_global_str's object description prints fine here.
     66         value_list1 = frame0.GetVariables(True, True, True, True)
     67         for v in value_list1:
     68             self.DebugSBValue(v)
     69             if self.TraceOn():
     70                 print "val:", v
     71                 print "object description:", v.GetObjectDescription()
     72             if v.GetName() == 'my_global_str':
     73                 self.assertTrue(v.GetObjectDescription() == 'This is a global string')
     74 
     75         # But not here!
     76         value_list2 = target.FindGlobalVariables('my_global_str', 3)
     77         for v in value_list2:
     78             self.DebugSBValue(v)
     79             if self.TraceOn():
     80                 print "val:", v
     81                 print "object description:", v.GetObjectDescription()
     82             if v.GetName() == 'my_global_str':
     83                 self.assertTrue(v.GetObjectDescription() == 'This is a global string')
     84 
     85         
     86 if __name__ == '__main__':
     87     import atexit
     88     lldb.SBDebugger.Initialize()
     89     atexit.register(lambda: lldb.SBDebugger.Terminate())
     90     unittest2.main()
     91