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