def test_dsym_swiftinterface(self): """Test that LLDB can import .swiftinterface files inside a .dSYM bundle.""" self.build() self.assertFalse(os.path.isdir(self.getBuildArtifact("AA.dylib.dSYM")), "dylib dsym exists") # The custom swift module cache location swift_mod_cache = self.getBuildArtifact("cache") self.assertTrue( os.path.isfile( self.getBuildArtifact( "a.out.dSYM/Contents/Resources/Swift/x86_64/AA.swiftinterface" )), "dsymutil doesn't support Swift interfaces") # Delete the .swiftinterface form the build dir. os.remove(self.getBuildArtifact("AA.swiftinterface")) # Clear the swift module cache (populated by the Makefile build) shutil.rmtree(swift_mod_cache) import glob self.assertFalse(os.path.isdir(swift_mod_cache), "module cache should not exist") # Update the settings to use the custom module cache location self.runCmd('settings set symbols.clang-modules-cache-path "%s"' % swift_mod_cache) # Set a breakpoint in and launch the main executable lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.swift")) # Check we are able to access the public fields of variables whose # types are from the .swiftinterface-only dylibs var = self.frame().FindVariable("x") lldbutil.check_variable(self, var, False, typename="AA.MyPoint") child_y = var.GetChildMemberWithName("y") # MyPoint.y is public lldbutil.check_variable(self, child_y, False, value="0") child_x = var.GetChildMemberWithName("x") # MyPoint.x isn't public self.assertFalse(child_x.IsValid()) # Expression evaluation using types from the .swiftinterface only # dylibs should work too lldbutil.check_expression(self, self.frame(), "y.magnitudeSquared", "404", use_summary=False) lldbutil.check_expression(self, self.frame(), "MyPoint(x: 1, y: 2).magnitudeSquared", "5", use_summary=False) # Check the swift module cache was populated with the .swiftmodule # files of the loaded modules self.assertTrue(os.path.isdir(swift_mod_cache), "module cache exists") a_modules = glob.glob(os.path.join(swift_mod_cache, 'AA-*.swiftmodule')) self.assertEqual(len(a_modules), 1)
def do_test(self): """Test that we display self correctly for an inline-initialized struct""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex('Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") theself = self.frame.FindVariable("self") var_a = theself.GetChildMemberWithName("a") lldbutil.check_variable(self,var_a,False,value="12") self.runCmd("next") var_b = theself.GetChildMemberWithName("b") lldbutil.check_variable(self,var_b,False,'"Hey"')
def do_test(self): """Test that tagged pointers are formatted correctly in a Swift context""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex('break here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var_a = self.frame.FindVariable("a") var_b = self.frame.FindVariable("b") lldbutil.check_variable(self,var_a,True,"Int64(3)") lldbutil.check_variable(self,var_b,True,"Int64(3)")
def test_dwarf_importer_exprs(self): lldb.SBDebugger.MemoryPressureDetected() self.runCmd("settings set symbols.use-swift-dwarfimporter true") self.build() target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( self, 'break here', lldb.SBFileSpec('main.swift')) lldbutil.check_variable(self, target.FindFirstGlobalVariable("pureSwift"), value="42") lldbutil.check_variable(self, target.FindFirstGlobalVariable("point"), typename='CModule.Point', num_children=2) self.expect("expr point", substrs=["x = 1", "y = 2"]) self.expect("expr enumerator", substrs=[".yellow"]) self.expect("expr pureSwiftStruct", substrs=["pure swift"]) self.expect("expr swiftStructCMember", substrs=[ "point", "x = 3", "y = 4", "sub", "x = 1", "y = 2", "z = 3", "swift struct c member" ]) self.expect("expr typedef", substrs=["x = 5", "y = 6"]) self.expect("expr union", substrs=["(DoubleLongUnion)", "long_val = 42"]) self.expect("expr fromSubmodule", substrs=["(FromSubmodule)", "x = 1", "y = 2", "z = 3"]) process.Clear() target.Clear() lldb.SBDebugger.MemoryPressureDetected()
def do_test(self): """Test that a 'let' Int is formatted properly""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") let = self.frame.FindVariable("x") var = self.frame.FindVariable("y") lldbutil.check_variable(self, let, False, value="10") lldbutil.check_variable(self, var, False, value="10")
def test_swift_different_clang_flags(self): """Test that we use the right compiler flags when debugging""" self.build() target, process, thread, modb_breakpoint = \ lldbutil.run_to_source_breakpoint( self, 'break here', lldb.SBFileSpec("modb.swift"), exe_name=self.getBuildArtifact("main"), extra_images=['moda', 'modb']) main_breakpoint = target.BreakpointCreateBySourceRegex( 'break here', lldb.SBFileSpec('main.swift')) self.assertTrue(modb_breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) var = self.frame().FindVariable("myThree") three = var.GetChildMemberWithName("three") lldbutil.check_variable(self, var, False, typename="modb.MyStruct") lldbutil.check_variable(self, three, False, value="3") process.Continue() threads = lldbutil.get_threads_stopped_at_breakpoint( process, main_breakpoint) var = self.frame().FindVariable("a") lldbutil.check_variable(self, var, False, value="2") var = self.frame().FindVariable("b") lldbutil.check_variable(self, var, False, value="3") var = self.frame().EvaluateExpression("fA()") lldbutil.check_variable(self, var, False, value="2")
def do_test(self): """Test the Any type""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, lldbtest.VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex('Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, lldbtest.VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, lldbtest.PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var_c = self.frame.FindVariable("c") var_c_x = var_c.GetChildMemberWithName("x") var_q = self.frame.FindVariable("q") lldbutil.check_variable(self,var_c_x,True,value="12") lldbutil.check_variable(self,var_q,True,value="12") self.expect("expression -d run -- q", substrs=['12']) self.expect("frame variable -d run -- q", substrs=['12'])
def test_negative(self): lldb.SBDebugger.MemoryPressureDetected() self.runCmd("log enable lldb types") self.runCmd("settings set symbols.use-swift-dwarfimporter false") self.build() log = self.getBuildArtifact("types.log") self.runCmd('log enable lldb types -f "%s"' % log) target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( self, 'break here', lldb.SBFileSpec('main.swift')) #lldbutil.check_variable(self, # target.FindFirstGlobalVariable("point"), # typename="Point", num_children=2) # This can't be resolved. lldbutil.check_variable( self, target.FindFirstGlobalVariable("swiftStructCMember"), num_children=0) found = False logfile = open(log, "r") for line in logfile: if "missing required module" in line: found = True self.assertTrue(found) process.Clear() target.Clear() lldb.SBDebugger.MemoryPressureDetected()
def do_test(self): """Test that an enum with only one case does not crash LLDB""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) maybeEvent = self.frame().FindVariable("maybeEvent") event = self.frame().FindVariable("event") lldbutil.check_variable(self, maybeEvent, use_dynamic=False, use_synthetic=True, value="Goofus") lldbutil.check_variable(self, event, use_dynamic=False, use_synthetic=True, value="Goofus")
def do_test(self): """Test that an enum with only one case does not crash LLDB""" exe_name = "a.out" exe = self.getBuildArtifact(exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) maybeEvent = self.frame().FindVariable("maybeEvent") event = self.frame().FindVariable("event") lldbutil.check_variable(self, maybeEvent, use_dynamic=False, use_synthetic=True, value="Goofus") lldbutil.check_variable(self, event, use_dynamic=False, use_synthetic=True, value="Goofus")
def test(self): """Test that reflection metadata is imported""" self.build() log = self.getBuildArtifact("types.log") self.runCmd('log enable lldb types -f "%s"' % log) target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( self, 'Set breakpoint here', lldb.SBFileSpec('main.swift'), extra_images=['dynamic_lib']) frame = thread.frames[0] var_c = frame.FindVariable("c") var_c_x = var_c.GetChildMemberWithName("x") lldbutil.check_variable(self, var_c_x, value="23") # Scan through the types log. import io logfile = io.open(log, "r", encoding='utf-8') found_exe = 0 found_lib = 0 for line in logfile: if re.search(r'Adding reflection metadata in .*a\.out', line): found_exe += 1 if re.search(r'Adding reflection metadata in .*dynamic_lib', line): found_lib += 1 self.assertEqual(found_exe, 1) self.assertEqual(found_lib, 1)
def doTest(self): target, process, thread, breakpoint = lldbutil.run_to_source_breakpoint( self, "break here", lldb.SBFileSpec("main.swift"), extra_images=['mod']) frame = thread.frames[0] # First try getting a non-resilient optional, to make sure that # part isn't broken: t_opt_var = frame.FindVariable("t_opt") self.assertSuccess(t_opt_var.GetError(), "Made t_opt value object") t_a_var = t_opt_var.GetChildMemberWithName("a") self.assertSuccess(t_a_var.GetError(), "The child was a") lldbutil.check_variable(self, t_a_var, False, value="2") # Make sure we can print an optional of a resilient type... # If we got the value out of the optional correctly, then # it's child will be "a". # First do this with "frame var": opt_var = frame.FindVariable("s_opt") self.assertSuccess(opt_var.GetError(), "Made s_opt value object") a_var = opt_var.GetChildMemberWithName("a") self.assertSuccess(a_var.GetError(), "The resilient child was 'a'") lldbutil.check_variable(self, a_var, False, value="1")
def do_test(self): """Test that tagged pointers are formatted correctly in a Swift context""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var_a = self.frame.FindVariable("a") var_b = self.frame.FindVariable("b") lldbutil.check_variable(self, var_a, True, "Int64(3)") lldbutil.check_variable(self, var_b, True, "Int64(3)")
def do_test(self): """Test the formatting of briged Swift metatypes""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex('Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var_k = self.frame.FindVariable("k") lldbutil.check_variable(self,var_k,False,"NSString")
def test_swift_bridged_metatype(self): """Test the formatting of bridged Swift metatypes""" self.build() lldbutil.run_to_source_breakpoint( self, 'Set breakpoint here', lldb.SBFileSpec('main.swift')) var_k = self.frame().FindVariable("k") lldbutil.check_variable(self, var_k, False, "NSString")
def test_swift_generic_enum_types(self): """Test that we handle reasonably generically-typed enums""" self.build() exe_name = "a.out" exe = self.getBuildArtifact(exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint1 = target.BreakpointCreateBySourceRegex( '// Set first breakpoint here.', self.main_source_spec) breakpoint2 = target.BreakpointCreateBySourceRegex( '// Set second breakpoint here.', self.main_source_spec) self.assertTrue(breakpoint1.GetNumLocations() > 0, VALID_BREAKPOINT) self.assertTrue(breakpoint2.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint1) self.assertTrue(len(threads) == 1) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd("type summary delete main.StringWrapper", check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) enumvar = self.get_variable("myOptionalU").GetStaticValue() self.assertTrue(enumvar.GetValue() is None, "static type has a value when it shouldn't") enumvar = enumvar.GetDynamicValue(lldb.eDynamicCanRunTarget) self.assertTrue(enumvar.GetValue() == "Some", "dynamic type's value should be Some") self.assertTrue(enumvar.GetSummary() == "3", "Some's summary should be 3") self.runCmd("continue") threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint2) self.assertTrue(len(threads) == 1) value = self.get_variable("value") lldbutil.check_variable(self, value, use_dynamic=True, summary='"Now with Content"', typename='String?')
def do_test(self): """Test that we use the right compiler flags when debugging""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) def cleanup(): execute_command("make cleanup") self.addTearDownHook(cleanup) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints main_breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.main_source_spec) self.assertTrue( main_breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) modb_breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.modb_source_spec) self.assertTrue( modb_breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) threads = lldbutil.get_threads_stopped_at_breakpoint( process, modb_breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("myThree") three = var.GetChildMemberWithName("three") lldbutil.check_variable(self, var, False, typename="modb.MyStruct") lldbutil.check_variable(self, three, False, value="3") process.Continue() threads = lldbutil.get_threads_stopped_at_breakpoint( process, main_breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("a") lldbutil.check_variable(self, var, False, value="2") var = self.frame.FindVariable("b") lldbutil.check_variable(self, var, False, value="3") var = self.frame.EvaluateExpression("fA()") lldbutil.check_variable(self, var, False, value="2")
def do_test(self): """Test that Swift.String formats properly""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex("Set breakpoint here", self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") s1 = self.frame.FindVariable("s1") s2 = self.frame.FindVariable("s2") lldbutil.check_variable(self, s1, summary='"Hello world"') lldbutil.check_variable(self, s2, summary='"ΞΕΛΛΘ"') TheVeryLongOne = self.frame.FindVariable("TheVeryLongOne") summaryOptions = lldb.SBTypeSummaryOptions() summaryOptions.SetCapping(lldb.eTypeSummaryUncapped) uncappedSummaryStream = lldb.SBStream() TheVeryLongOne.GetSummary(uncappedSummaryStream, summaryOptions) uncappedSummary = uncappedSummaryStream.GetData() self.assertTrue(uncappedSummary.find("someText") > 0, "uncappedSummary does not include the full string") summaryOptions.SetCapping(lldb.eTypeSummaryCapped) cappedSummaryStream = lldb.SBStream() TheVeryLongOne.GetSummary(cappedSummaryStream, summaryOptions) cappedSummary = cappedSummaryStream.GetData() self.assertTrue(cappedSummary.find("someText") <= 0, "cappedSummary includes the full string") self.assertTrue(cappedSummary.endswith('"...'), "cappedSummary ends with quote dot dot dot") IContainZerosASCII = self.frame.FindVariable("IContainZerosASCII") IContainZerosUnicode = self.frame.FindVariable("IContainZerosUnicode") IContainEscapes = self.frame.FindVariable("IContainEscapes") lldbutil.check_variable(self, IContainZerosASCII, summary='"a\\0b\\0c\\0d"') lldbutil.check_variable(self, IContainZerosUnicode, summary='"HFIHЗIHF\\0VЭHVHЗ90HGЭ"') lldbutil.check_variable(self, IContainEscapes, summary='"Hello\\u{8}\\n\\u{8}\\u{8}\\nGoodbye"') self.expect( 'expression -l objc++ -- (char*)"Hello\b\b\b\b\bGoodbye"', substrs=['"Hello\\b\\b\\b\\b\\bGoodbye"'] )
def do_test(self): """Test that we use the right compiler flags when debugging""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) def cleanup(): execute_command("make cleanup") self.addTearDownHook(cleanup) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints main_breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.main_source_spec) self.assertTrue(main_breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) modb_breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.modb_source_spec) self.assertTrue(modb_breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) threads = lldbutil.get_threads_stopped_at_breakpoint( process, modb_breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("myThree") three = var.GetChildMemberWithName("three") lldbutil.check_variable(self, var, False, typename="modb.MyStruct") lldbutil.check_variable(self, three, False, value="3") process.Continue() threads = lldbutil.get_threads_stopped_at_breakpoint( process, main_breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("a") lldbutil.check_variable(self, var, False, value="2") var = self.frame.FindVariable("b") lldbutil.check_variable(self, var, False, value="3") var = self.frame.EvaluateExpression("fA()") lldbutil.check_variable(self, var, False, value="2")
def test_swift_struct_change_rerun(self): """Test that we display self correctly for an inline-initialized struct""" copied_main_swift = self.getBuildArtifact("main.swift") # Cleanup the copied source file def cleanup(): if os.path.exists(copied_main_swift): os.unlink(copied_main_swift) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) print('build with main1.swift') cleanup() shutil.copyfile("main1.swift", copied_main_swift) self.build() (target, process, thread, breakpoint) = \ lldbutil.run_to_source_breakpoint( self, 'Set breakpoint here', lldb.SBFileSpec('main.swift')) var_a = self.frame().EvaluateExpression("a") var_a_a = var_a.GetChildMemberWithName("a") lldbutil.check_variable(self, var_a_a, False, value="12") var_a_b = var_a.GetChildMemberWithName("b") lldbutil.check_variable(self, var_a_b, False, '"Hey"') var_a_c = var_a.GetChildMemberWithName("c") self.assertFalse(var_a_c.IsValid(), "make sure a.c doesn't exist") process.Kill() print('build with main2.swift') cleanup() shutil.copyfile("main2.swift", copied_main_swift) self.build() # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) var_a = self.frame().EvaluateExpression("a") var_a_a = var_a.GetChildMemberWithName("a") lldbutil.check_variable(self, var_a_a, False, value="12") var_a_b = var_a.GetChildMemberWithName("b") lldbutil.check_variable(self, var_a_b, False, '"Hey"') var_a_c = var_a.GetChildMemberWithName("c") self.assertTrue(var_a_c.IsValid(), "make sure a.c does exist") lldbutil.check_variable(self, var_a_c, False, value='12.125')
def test_swift_bridged_metatype(self): """Test the formatting of bridged Swift metatypes""" self.build() lldbutil.run_to_source_breakpoint(self, 'Set breakpoint here', lldb.SBFileSpec('main.swift')) var_k = self.frame().FindVariable("k") if sys.platform.startswith("linux"): lldbutil.check_variable(self, var_k, False, "Foundation.NSString") else: lldbutil.check_variable(self, var_k, False, "NSString")
def do_check_api(self): """Check formatting for T? and T! when T is an ObjC type""" optColor_Some = self.frame.FindVariable("optColor_Some") lldbutil.check_variable(self, optColor_Some, use_dynamic=False, num_children=1) uoptColor_Some = self.frame.FindVariable("uoptColor_Some") lldbutil.check_variable(self, uoptColor_Some, use_dynamic=False, num_children=1)
def do_test(self): """Tests that we properly vend synthetic children for Swift.Dictionary""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint1 = target.BreakpointCreateBySourceRegex('// Set first breakpoint here.', self.main_source_spec) breakpoint2 = target.BreakpointCreateBySourceRegex('// Set second breakpoint here.', self.main_source_spec) self.assertTrue(breakpoint1.GetNumLocations() > 0, VALID_BREAKPOINT) self.assertTrue(breakpoint2.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint1) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd("type summary delete main.StringWrapper", check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) enumvar = self.get_variable("myOptionalU").GetStaticValue() self.assertTrue(enumvar.GetValue() is None, "static type has a value when it shouldn't") enumvar = enumvar.GetDynamicValue(lldb.eDynamicCanRunTarget) self.assertTrue(enumvar.GetValue() == "Some", "dynamic type's value should be Some") self.assertTrue(enumvar.GetSummary() == "3", "Some's summary should be 3") self.runCmd("continue") threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint2) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") value = self.get_variable("value") lldbutil.check_variable (self, value, use_dynamic = True, summary = '"Now with Content"', typename = 'String?')
def test_swift_string_variables(self): """Test that Swift.String formats properly""" self.build() lldbutil.run_to_source_breakpoint( self, 'Set breakpoint here', lldb.SBFileSpec('main.swift')) s1 = self.frame().FindVariable("s1") s2 = self.frame().FindVariable("s2") lldbutil.check_variable(self, s1, summary='"Hello world"') lldbutil.check_variable(self, s2, summary='"ΞΕΛΛΘ"') TheVeryLongOne = self.frame().FindVariable("TheVeryLongOne") summaryOptions = lldb.SBTypeSummaryOptions() summaryOptions.SetCapping(lldb.eTypeSummaryUncapped) uncappedSummaryStream = lldb.SBStream() TheVeryLongOne.GetSummary(uncappedSummaryStream, summaryOptions) uncappedSummary = uncappedSummaryStream.GetData() self.assertTrue(uncappedSummary.find("someText") > 0, "uncappedSummary does not include the full string") summaryOptions.SetCapping(lldb.eTypeSummaryCapped) cappedSummaryStream = lldb.SBStream() TheVeryLongOne.GetSummary(cappedSummaryStream, summaryOptions) cappedSummary = cappedSummaryStream.GetData() self.assertTrue( cappedSummary.find("someText") <= 0, "cappedSummary includes the full string") self.assertTrue( cappedSummary.endswith('"...'), "cappedSummary ends with quote dot dot dot") IContainZerosASCII = self.frame().FindVariable("IContainZerosASCII") IContainZerosUnicode = self.frame().FindVariable("IContainZerosUnicode") IContainEscapes = self.frame().FindVariable("IContainEscapes") lldbutil.check_variable( self, IContainZerosASCII, summary='"a\\0b\\0c\\0d"') lldbutil.check_variable( self, IContainZerosUnicode, summary='"HFIHЗIHF\\0VЭHVHЗ90HGЭ"') lldbutil.check_variable( self, IContainEscapes, summary='"Hello\\u{8}\\n\\u{8}\\u{8}\\nGoodbye"') self.expect( 'expression -l objc++ -- (char*)"Hello\b\b\b\b\bGoodbye"', substrs=['"Hello\\b\\b\\b\\b\\bGoodbye"'])
def test_multilang_formatter_categories(self): """Test that formatter categories can work for multiple languages""" self.build() target, process, thread, a_breakpoint = \ lldbutil.run_to_source_breakpoint( self, 'break here', lldb.SBFileSpec('main.swift')) frame = thread.frames[0] self.assertTrue(frame, "Frame 0 is valid.") dic = frame.FindVariable("dic") lldbutil.check_variable(self, dic, use_dynamic=False, summary="2 key/value pairs", num_children=2) child0 = dic.GetChildAtIndex(0) lldbutil.check_variable(self, child0, use_dynamic=False, num_children=2, typename="__lldb_autogen_nspair") id1 = child0.GetChildAtIndex(1) lldbutil.check_variable(self, id1, use_dynamic=False, typename="id") id1child0 = dic.GetChildAtIndex(1).GetChildAtIndex(0) lldbutil.check_variable(self, id1child0, use_dynamic=True, typename="Swift.Optional<Foundation.NSURL>", summary='"http://www.google.com"')
def test_swift_struct_init(self): """Test that we display self correctly for an inline-initialized struct""" self.build() lldbutil.run_to_source_breakpoint(self, 'Set breakpoint here', lldb.SBFileSpec('main.swift')) theself = self.frame().FindVariable("self") var_a = theself.GetChildMemberWithName("a") lldbutil.check_variable(self, var_a, False, value="12") self.runCmd("next") var_b = theself.GetChildMemberWithName("b") lldbutil.check_variable(self, var_b, False, '"Hey"')
def test_cross_module_extension(self): """Test that we correctly find private extension decls across modules""" self.build() target, process, thread, a_breakpoint = \ lldbutil.run_to_source_breakpoint( self, 'break here', lldb.SBFileSpec('moda.swift'), exe_name = self.getBuildArtifact("main")) b_breakpoint = target.BreakpointCreateBySourceRegex( 'break here', lldb.SBFileSpec('modb.swift')) self.assertTrue(b_breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) frame = thread.frames[0] self.assertTrue(frame, "Frame 0 is valid.") var = frame.FindVariable("a") child_v = var.GetChildMemberWithName("v") lldbutil.check_variable(self, var, False, typename="moda.S.A") lldbutil.check_variable(self, child_v, False, value="1") process.Continue() threads = lldbutil.get_threads_stopped_at_breakpoint( process, b_breakpoint) self.assertTrue(len(threads) == 1) frame = threads[0].frames[0] self.assertTrue(frame, "Frame 0 is valid.") var = frame.FindVariable("a") child_v = var.GetChildMemberWithName("v") lldbutil.check_variable(self, var, False, typename="moda.S.A") lldbutil.check_variable(self, child_v, False, value="3")
def test_dwarf_importer(self): self.runCmd("settings set symbols.use-swift-dwarfimporter true") self.build() target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( self, 'break here', lldb.SBFileSpec('main.swift')) lldbutil.check_variable(self, target.FindFirstGlobalVariable("pureSwift"), value="42") # Expect an Objective-C rendition for now. lldbutil.check_variable(self, target.FindFirstGlobalVariable("obj"), typename="Class", num_children=0) self.expect("fr v obj", substrs=["obj = 0x"])
def do_test(self): """Test that Swift.String formats properly""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") s1 = self.frame.FindVariable("s1") s2 = self.frame.FindVariable("s2") lldbutil.check_variable(self, s1, summary='"Hello world"') lldbutil.check_variable(self, s2, summary='"ΞΕΛΛΘ"') TheVeryLongOne = self.frame.FindVariable("TheVeryLongOne") summaryOptions = lldb.SBTypeSummaryOptions() summaryOptions.SetCapping(lldb.eTypeSummaryUncapped) uncappedSummaryStream = lldb.SBStream() TheVeryLongOne.GetSummary(uncappedSummaryStream, summaryOptions) uncappedSummary = uncappedSummaryStream.GetData() self.assertTrue( uncappedSummary.find("someText") > 0, "uncappedSummary does not include the full string") summaryOptions.SetCapping(lldb.eTypeSummaryCapped) cappedSummaryStream = lldb.SBStream() TheVeryLongOne.GetSummary(cappedSummaryStream, summaryOptions) cappedSummary = cappedSummaryStream.GetData() self.assertTrue( cappedSummary.find("someText") <= 0, "cappedSummary includes the full string") IContainZerosASCII = self.frame.FindVariable("IContainZerosASCII") IContainZerosUnicode = self.frame.FindVariable("IContainZerosUnicode") lldbutil.check_variable(self, IContainZerosASCII, summary='"a\\0b\\0c\\0d"') lldbutil.check_variable(self, IContainZerosUnicode, summary='"HFIHЗIHF\\0VЭHVHЗ90HGЭ"')
def test_swift_private_typealias(self): """Test that we can correctly print variables whose types are private type aliases""" self.build() (target, process, thread, breakpoint1) = \ lldbutil.run_to_source_breakpoint( self, 'breakpoint 1', lldb.SBFileSpec('main.swift')) breakpoint2 = target.BreakpointCreateBySourceRegex( 'breakpoint 2', lldb.SBFileSpec('main.swift')) self.assertTrue(breakpoint1.GetNumLocations() > 0, VALID_BREAKPOINT) self.assertTrue(breakpoint2.GetNumLocations() > 0, VALID_BREAKPOINT) var = self.frame().FindVariable("i") lldbutil.check_variable(self, var, False, typename="a.MyStruct.IntegerType", value="123") process.Continue() threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint2) self.assertTrue(len(threads) == 1) var = self.frame().FindVariable("a") dict_child_0 = var.GetChildAtIndex(0) child_0 = dict_child_0.GetChildAtIndex(0) child_1 = dict_child_0.GetChildAtIndex(1) lldbutil.check_variable( self, var, False, typename="Swift.Dictionary<Swift.String, a.MyStruct.IntegerType>") lldbutil.check_variable(self, child_0, False, '"hello"') lldbutil.check_variable(self, child_1, False, value='234')
def do_check_api(self): """Check formatting for T? and T! when T is an ObjC type""" optColor_Some = self.frame.FindVariable("optColor_Some") lldbutil.check_variable( self, optColor_Some, use_dynamic=False, num_children=1) uoptColor_Some = self.frame.FindVariable("uoptColor_Some") lldbutil.check_variable( self, uoptColor_Some, use_dynamic=False, num_children=1)
def test_any_type(self): """Test the Any type""" self.build() target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( self, 'Set breakpoint here', lldb.SBFileSpec('main.swift')) frame = thread.frames[0] var_c = frame.FindVariable("c") var_c_x = var_c.GetChildMemberWithName("x") var_q = frame.FindVariable("q") lldbutil.check_variable(self, var_c_x, True, value="12") lldbutil.check_variable(self, var_q, True, value="12") self.expect("expression -d run -- q", substrs=['12']) self.expect("frame variable -d run -- q", substrs=['12'])
def test(self): """Test the bound generic enum types in "optimized" code.""" self.build() target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( self, 'break one', lldb.SBFileSpec('main.swift')) bkpt_two = target.BreakpointCreateBySourceRegex( 'break two', lldb.SBFileSpec('main.swift')) self.assertGreater(bkpt_two.GetNumLocations(), 0) var_self = self.frame().FindVariable("self") # FIXME, this fails with a data extractor error. lldbutil.check_variable(self, var_self, False, value=None) lldbutil.continue_to_breakpoint(process, bkpt_two) var_self = self.frame().FindVariable("self") lldbutil.check_variable(self, var_self, True, value="success")
def do_check_api(self): """Check formatting for T? and T! when T is an ObjC type""" optColor_Some = self.frame().FindVariable("optColor_Some") # SwiftOptionalSyntheticFrontEnd passes GetNumChildren # through to the .some object. NSColor has no children. lldbutil.check_variable(self, optColor_Some, use_dynamic=False, num_children=0) uoptColor_Some = self.frame().FindVariable("uoptColor_Some") lldbutil.check_variable(self, uoptColor_Some, use_dynamic=False, num_children=0)
def test_swift_private_typealias(self): """Test that we can correctly print variables whose types are private type aliases""" self.build() exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint1 = target.BreakpointCreateBySourceRegex( 'breakpoint 1', self.a_source_spec) breakpoint2 = target.BreakpointCreateBySourceRegex( 'breakpoint 2', self.a_source_spec) self.assertTrue(breakpoint1.GetNumLocations() > 0, VALID_BREAKPOINT) self.assertTrue(breakpoint2.GetNumLocations() > 0, VALID_BREAKPOINT) process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint1) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("i") lldbutil.check_variable(self, var, False, typename="a.MyStruct.Type.IntegerType", value="123") process.Continue() threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint2) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("a") dict_child_0 = var.GetChildAtIndex(0) child_0 = dict_child_0.GetChildAtIndex(0) child_1 = dict_child_0.GetChildAtIndex(1) lldbutil.check_variable( self, var, False, typename= "Swift.Dictionary<Swift.String, a.MyStruct.Type.IntegerType>") lldbutil.check_variable(self, child_0, False, '"hello"') lldbutil.check_variable(self, child_1, False, value='234')
def test_swift_private_typealias(self): """Test that we can correctly print variables whose types are private type aliases""" self.build() exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint1 = target.BreakpointCreateBySourceRegex( 'breakpoint 1', self.a_source_spec) breakpoint2 = target.BreakpointCreateBySourceRegex( 'breakpoint 2', self.a_source_spec) self.assertTrue(breakpoint1.GetNumLocations() > 0, VALID_BREAKPOINT) self.assertTrue(breakpoint2.GetNumLocations() > 0, VALID_BREAKPOINT) process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint1) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("i") lldbutil.check_variable( self, var, False, typename="a.MyStruct.Type.IntegerType", value="123") process.Continue() threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint2) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("a") dict_child_0 = var.GetChildAtIndex(0) child_0 = dict_child_0.GetChildAtIndex(0) child_1 = dict_child_0.GetChildAtIndex(1) lldbutil.check_variable( self, var, False, typename="Swift.Dictionary<Swift.String, a.MyStruct.Type.IntegerType>") lldbutil.check_variable(self, child_0, False, '"hello"') lldbutil.check_variable(self, child_1, False, value='234')
def test_expr(self): self.runCmd("settings set symbols.use-swift-dwarfimporter true") self.build() target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( self, 'break here', lldb.SBFileSpec('main.swift')) lldbutil.check_variable(self, target.FindFirstGlobalVariable("pureSwift"), value="42") lldbutil.check_variable( self, target.FindFirstGlobalVariable("obj"), typename="Swift.Optional<ObjCModule.ObjCClass>", num_children=0) self.expect("expr obj", substrs=["ObjCClass", "private_ivar", "42"]) self.expect("expr swiftChild", substrs=["ObjCClass", "private_ivar", "42"])
def test_swift_nested_array(self): """Test Arrays of Arrays in Swift""" self.build() lldbutil.run_to_source_breakpoint(self, 'break here', lldb.SBFileSpec('main.swift')) var_aInt = self.frame().FindVariable("aInt") var_aC = self.frame().FindVariable("aC") lldbutil.check_variable(self, var_aInt, False, num_children=6) lldbutil.check_variable(self, var_aC, False, num_children=5) for i in range(0, 6): var_aIntChild = var_aInt.GetChildAtIndex(i) lldbutil.check_children(self, var_aIntChild, check_for_idx) for i in range(0, 5): var_aCChild = var_aC.GetChildAtIndex(i) lldbutil.check_children(self, var_aCChild, check_for_C)
def test_metatype(self): """Test the formatting of Swift metatypes""" self.build() target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( self, 'Set breakpoint here', lldb.SBFileSpec('main.swift')) frame = thread.frames[0] self.assertTrue(frame, "Frame 0 is valid.") var_s = frame.FindVariable("s") var_c = frame.FindVariable("c") var_f = frame.FindVariable("f") var_t = frame.FindVariable("t") var_p = frame.FindVariable("p") lldbutil.check_variable(self, var_s, False, "String") lldbutil.check_variable(self, var_c, False, "a.D") lldbutil.check_variable(self, var_f, False, "(Int) -> Int") lldbutil.check_variable(self, var_t, False, "(Int, Int, String)") lldbutil.check_variable(self, var_p, False, "a.P")
def doTestWithFlavor(self, exe_flavor, mod_flavor): self.createSymlinks(exe_flavor, mod_flavor) exe_name = "main" exe_path = os.path.join(os.getcwd(), exe_name) source_name = "main.swift" source_spec = lldb.SBFileSpec(source_name) # Create the target target = self.dbg.CreateTarget(exe_path) self.assertTrue(target, VALID_TARGET) breakpoint = target.BreakpointCreateBySourceRegex('break', source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") # Try 'frame variable' var = self.frame.FindVariable("s") child = var.GetChildMemberWithName("a") lldbutil.check_variable(self, child, False, value="1") # Try the expression parser self.expect("expr s.a", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["1"]) self.expect( "expr fA(s)", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["1"]) process.Kill() self.cleanupSymlinks()
def do_test(self): """Test the formatting of Swift metatypes""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var_s = self.frame.FindVariable("s") var_c = self.frame.FindVariable("c") # Enrico, there is no k var in the .swift file, and there is # no check on the k below. Commenting out for you to resolve. # var_k = self.frame.FindVariable("k") var_f = self.frame.FindVariable("f") var_t = self.frame.FindVariable("t") var_p = self.frame.FindVariable("p") lldbutil.check_variable(self, var_s, False, "String") lldbutil.check_variable(self, var_c, False, "a.D") lldbutil.check_variable(self, var_f, False, "(Int) -> Int") lldbutil.check_variable(self, var_t, False, "(Int, Int, String)") lldbutil.check_variable(self, var_p, False, "P")
def do_test(self): """Test Arrays of Arrays in Swift""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( '// break here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var_aInt = self.frame.FindVariable("aInt") var_aC = self.frame.FindVariable("aC") lldbutil.check_variable(self, var_aInt, False, num_children=6) lldbutil.check_variable(self, var_aC, False, num_children=5) for i in range(0, 6): var_aIntChild = var_aInt.GetChildAtIndex(i) lldbutil.check_children(self, var_aIntChild, check_for_idx) for i in range(0, 5): var_aCChild = var_aC.GetChildAtIndex(i) lldbutil.check_children(self, var_aCChild, check_for_C)
def do_test(self): """Test the AnyObject type""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex('Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var_object = self.frame.FindVariable("object") lldbutil.check_variable(self,var_object,use_dynamic=False,typename="AnyObject") lldbutil.check_variable(self,var_object,use_dynamic=True,typename="a.SomeClass") var_object_x = var_object.GetDynamicValue(lldb.eDynamicCanRunTarget).GetChildMemberWithName("x") lldbutil.check_variable(self,var_object_x,use_dynamic=False,value='12',typename="Swift.Int")
def do_test(self): """Test that we correctly find private extension decls across modules""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) def cleanup(): execute_command("make cleanup") self.addTearDownHook(cleanup) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints a_breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.a_source_spec) self.assertTrue(a_breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) b_breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.b_source_spec) self.assertTrue(b_breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) threads = lldbutil.get_threads_stopped_at_breakpoint( process, a_breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("a") child_v = var.GetChildMemberWithName("v") lldbutil.check_variable(self, var, False, typename="moda.S.A") lldbutil.check_variable(self, child_v, False, value="1") process.Continue() threads = lldbutil.get_threads_stopped_at_breakpoint( process, b_breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("a") child_v = var.GetChildMemberWithName("v") lldbutil.check_variable(self, var, False, typename="moda.S.A") lldbutil.check_variable(self, child_v, False, value="3")
def do_test(self): """Test that formatter categories can work for multiple languages""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex('break here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") dic = self.frame.FindVariable("dic") lldbutil.check_variable(self,dic,use_dynamic=False,summary="2 key/value pairs",num_children=2) child0 = dic.GetChildAtIndex(0) lldbutil.check_variable(self,child0,use_dynamic=False,num_children=2,typename="__lldb_autogen_nspair") id1 = child0.GetChildAtIndex(1) lldbutil.check_variable(self,id1,use_dynamic=False,typename="id") id1child0 = dic.GetChildAtIndex(1).GetChildAtIndex(0) lldbutil.check_variable(self,id1child0,use_dynamic=True,typename="NSURL *",summary='"http://www.google.com"')
def do_test(self): """Test that Swift.String formats properly""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") s3 = self.frame.FindVariable("s3") s4 = self.frame.FindVariable("s4") s5 = self.frame.FindVariable("s5") s6 = self.frame.FindVariable("s6") lldbutil.check_variable(self, s3, summary='"Hello world"') lldbutil.check_variable(self, s4, summary='"ΞΕΛΛΘ"') lldbutil.check_variable(self, s5, use_dynamic=True, summary='"abc"') lldbutil.check_variable(self, s6, summary='"abc"')
def do_test(self, build_dsym): """Test that we display self correctly for an inline-initialized struct""" # Cleanup the copied source file def cleanup(): if os.path.exists(self.main_source): os.unlink(self.main_source) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) if os.path.exists(self.main_source): os.unlink(self.main_source) shutil.copyfile('main1.swift', self.main_source) print 'build with main1.swift' self.build() exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var_a = self.frame.EvaluateExpression("a") print var_a var_a_a = var_a.GetChildMemberWithName("a") lldbutil.check_variable(self,var_a_a,False,value="12") var_a_b = var_a.GetChildMemberWithName("b") lldbutil.check_variable(self,var_a_b,False,'"Hey"') var_a_c = var_a.GetChildMemberWithName("c") self.assertFalse(var_a_c.IsValid(), "make sure a.c doesn't exist") process.Kill() print 'build with main2.swift' os.unlink (self.main_source) shutil.copyfile ('main2.swift', self.main_source) if build_dsym: self.buildDsym() else: self.buildDwarf() # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var_a = self.frame.EvaluateExpression("a") print var_a var_a_a = var_a.GetChildMemberWithName("a") lldbutil.check_variable(self,var_a_a,False,value="12") var_a_b = var_a.GetChildMemberWithName("b") lldbutil.check_variable(self,var_a_b,False,'"Hey"') var_a_c = var_a.GetChildMemberWithName("c") self.assertTrue(var_a_c.IsValid(), "make sure a.c does exist") lldbutil.check_variable(self,var_a_c,False,value='12.125')
def do_test(self): """Test that we are able to deal with ObjC-imported types""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex('Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") nss = self.frame.FindVariable("nss") nsn = self.frame.FindVariable("nsn") nsmo = self.frame.FindVariable("nsmo") nsmd = self.frame.FindVariable("nsmd") lldbutil.check_variable(self, nss, use_dynamic=False, typename="Foundation.NSString") lldbutil.check_variable(self, nsn, use_dynamic=False, typename="Foundation.NSNumber") lldbutil.check_variable(self, nsmo, use_dynamic=False, typename="CoreData.NSManagedObject") lldbutil.check_variable(self, nsmd, use_dynamic=False, typename="Foundation.NSMutableDictionary") #pending rdar://15798504, but not critical for the test #lldbutil.check_variable(self, nss, use_dynamic=True, summary='@"abc"') lldbutil.check_variable(self, nsn, use_dynamic=True, summary='(long)3') lldbutil.check_variable(self, nsmo, use_dynamic=True, typename='NSManagedObject *') lldbutil.check_variable(self, nsmd, use_dynamic=True, summary='1 key/value pair')
def check_foo(self, theFoo): x = theFoo.GetChildMemberWithName("x") y = theFoo.GetChildMemberWithName("y") lldbutil.check_variable(self, x, False, value='12') lldbutil.check_variable(self, y, False, '"12"')
def do_check_api(self): """Check formatting for T? and T!""" optS_Some = self.frame.FindVariable("optS_Some") lldbutil.check_variable(self,optS_Some,use_dynamic = False, num_children=2) uoptS_Some = self.frame.FindVariable("uoptS_Some") lldbutil.check_variable(self,uoptS_Some,use_dynamic = False, num_children=2) optString_None = self.frame.FindVariable("optString_None") lldbutil.check_variable(self,optString_None,use_dynamic = False, num_children=0) uoptString_None = self.frame.FindVariable("uoptString_None") lldbutil.check_variable(self,uoptString_None,use_dynamic = False, num_children=0) optString_Some = self.frame.FindVariable("optString_Some") lldbutil.check_variable(self,optString_Some,use_dynamic = False, num_children=1) uoptString_Some = self.frame.FindVariable("uoptString_Some") lldbutil.check_variable(self,uoptString_Some,use_dynamic = False, num_children=1)
def test_swift_private_decl_name(self): """Test that we correctly find private decls""" self.build() self.do_test() exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints a_breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.a_source_spec) self.assertTrue(a_breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) b_breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.b_source_spec) self.assertTrue(b_breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) threads = lldbutil.get_threads_stopped_at_breakpoint( process, a_breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("a") child_a = var.GetChildMemberWithName("a") child_b = var.GetChildMemberWithName("b") child_c = var.GetChildMemberWithName("c") lldbutil.check_variable(self, var, False, typename="a.S.A") lldbutil.check_variable(self, child_a, False, value="1") lldbutil.check_variable(self, child_b, False, '"hello"') lldbutil.check_variable(self, child_c, False, value='1.25') process.Continue() threads = lldbutil.get_threads_stopped_at_breakpoint( process, b_breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("a") child_a = var.GetChildMemberWithName("a") child_b = var.GetChildMemberWithName("b") child_c = var.GetChildMemberWithName("c") lldbutil.check_variable(self, var, False, typename="a.S.A") lldbutil.check_variable(self, child_a, False, value="3") lldbutil.check_variable(self, child_b, False, '"goodbye"') lldbutil.check_variable(self, child_c, False, value='1.25')