1""" 2Test SBValue.GetObjectDescription() with the value from SBTarget.FindGlobalVariables(). 3""" 4 5from __future__ import print_function 6 7 8import lldb 9from lldbsuite.test.decorators import * 10from lldbsuite.test.lldbtest import * 11from lldbsuite.test import lldbutil 12 13 14class ObjectDescriptionAPITestCase(TestBase): 15 16 mydir = TestBase.compute_mydir(__file__) 17 18 def setUp(self): 19 # Call super's setUp(). 20 TestBase.setUp(self) 21 # Find the line number to break at. 22 self.source = 'main.m' 23 self.line = line_number( 24 self.source, '// Set break point at this line.') 25 26 # rdar://problem/10857337 27 @skipUnlessDarwin 28 @add_test_categories(['pyapi']) 29 def test_find_global_variables_then_object_description(self): 30 """Exercise SBTarget.FindGlobalVariables() API.""" 31 d = {'EXE': 'b.out'} 32 self.build(dictionary=d) 33 self.setTearDownCleanup(dictionary=d) 34 exe = self.getBuildArtifact('b.out') 35 36 # Create a target by the debugger. 37 target = self.dbg.CreateTarget(exe) 38 self.assertTrue(target, VALID_TARGET) 39 40 breakpoint = target.BreakpointCreateByLocation(self.source, self.line) 41 self.assertTrue(breakpoint, VALID_BREAKPOINT) 42 43 # Now launch the process, and do not stop at entry point. 44 process = target.LaunchSimple( 45 None, None, self.get_process_working_directory()) 46 self.assertTrue(process, PROCESS_IS_VALID) 47 # Make sure we hit our breakpoint: 48 thread_list = lldbutil.get_threads_stopped_at_breakpoint( 49 process, breakpoint) 50 self.assertTrue(len(thread_list) == 1) 51 52 thread = thread_list[0] 53 frame0 = thread.GetFrameAtIndex(0) 54 55 # Note my_global_str's object description prints fine here. 56 value_list1 = frame0.GetVariables(True, True, True, True) 57 for v in value_list1: 58 self.DebugSBValue(v) 59 if self.TraceOn(): 60 print("val:", v) 61 print("object description:", v.GetObjectDescription()) 62 if v.GetName() == 'my_global_str': 63 self.assertTrue(v.GetObjectDescription() == 64 'This is a global string') 65 66 # But not here! 67 value_list2 = target.FindGlobalVariables('my_global_str', 3) 68 for v in value_list2: 69 self.DebugSBValue(v) 70 if self.TraceOn(): 71 print("val:", v) 72 print("object description:", v.GetObjectDescription()) 73 if v.GetName() == 'my_global_str': 74 self.assertTrue(v.GetObjectDescription() == 75 'This is a global string') 76