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