def fuzz_obj(obj): obj.GetProcess() listener = lldb.SBListener() error = lldb.SBError() obj.Launch(listener, None, None, None, None, None, None, 0, True, error) obj.LaunchSimple(None, None, None) obj.AttachToProcessWithID(listener, 123, error) obj.AttachToProcessWithName(listener, 'lldb', False, error) obj.ConnectRemote(listener, "connect://to/here", None, error) obj.GetExecutable() obj.GetNumModules() obj.GetModuleAtIndex(0xffffffff) obj.GetDebugger() filespec = lldb.SBFileSpec() obj.FindModule(filespec) contextlist = lldb.SBSymbolContextList() obj.FindFunctions("the_func", 0xff, True, contextlist) obj.FindFirstType("dont_care") obj.FindTypes("dont_care") obj.FindFirstType(None) obj.GetInstructions(lldb.SBAddress(), bytearray()) obj.GetSourceManager() obj.FindGlobalVariables("my_global_var", 1) address = obj.ResolveLoadAddress(0xffff) obj.ResolveSymbolContextForAddress(address, 0) obj.BreakpointCreateByLocation("filename", 20) obj.BreakpointCreateByLocation(filespec, 20) obj.BreakpointCreateByName("func", None) obj.BreakpointCreateByRegex("func.", None) obj.BreakpointCreateByAddress(0xf0f0) obj.GetNumBreakpoints() obj.GetBreakpointAtIndex(0) obj.BreakpointDelete(0) obj.FindBreakpointByID(0) obj.EnableAllBreakpoints() obj.DisableAllBreakpoints() obj.DeleteAllBreakpoints() obj.GetNumWatchpoints() obj.GetWatchpointAtIndex(0) obj.DeleteWatchpoint(0) obj.FindWatchpointByID(0) obj.EnableAllWatchpoints() obj.DisableAllWatchpoints() obj.DeleteAllWatchpoints() obj.WatchAddress(123, 8, True, True) obj.GetBroadcaster() obj.GetDescription(lldb.SBStream(), lldb.eDescriptionLevelBrief) obj.Clear() for module in obj.module_iter(): print module for bp in obj.breakpoint_iter(): print bp for wp in obj.watchpoint_iter(): print wp
def find_functions(self, exe_name): """Exercise SBTaget.FindFunctions() API.""" exe = os.path.join(os.getcwd(), exe_name) # Create a target by the debugger. target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) list = lldb.SBSymbolContextList() num = target.FindFunctions('c', lldb.eFunctionNameTypeAuto, False, list) self.assertTrue(num == 1 and list.GetSize() == 1) for sc in list: self.assertTrue( sc.GetModule().GetFileSpec().GetFilename() == exe_name) self.assertTrue(sc.GetSymbol().GetName() == 'c')
def fuzz_obj(obj): obj.GetFileSpec() obj.GetPlatformFileSpec() obj.SetPlatformFileSpec(lldb.SBFileSpec()) obj.GetUUIDString() obj.ResolveFileAddress(sys.maxint) obj.ResolveSymbolContextForAddress(lldb.SBAddress(), 0) obj.GetDescription(lldb.SBStream()) obj.GetNumSymbols() obj.GetSymbolAtIndex(sys.maxint) obj.FindFunctions("my_func", 0xffffffff, True, lldb.SBSymbolContextList()) obj.FindGlobalVariables(lldb.SBTarget(), "my_global_var", 1) for section in obj.section_iter(): print section for symbol in obj.symbol_in_section_iter(lldb.SBSection()): print symbol for symbol in obj: print symbol
def module_and_section_boundary_condition(self): exe = os.path.join(os.getcwd(), "a.out") target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) self.assertTrue(target.GetNumModules() > 0) # Hide stdout if not running with '-t' option. if not self.TraceOn(): self.HideStdout() print "Number of modules for the target: %d" % target.GetNumModules() for module in target.module_iter(): print module # Get the executable module at index 0. exe_module = target.GetModuleAtIndex(0) print "Exe module: %s" % repr(exe_module) print "Number of sections: %d" % exe_module.GetNumSections() # Boundary condition testings. Should not crash lldb! exe_module.FindFirstType(None) exe_module.FindTypes(None) exe_module.FindGlobalVariables(target, None, 1) exe_module.FindFunctions(None, 0, True, lldb.SBSymbolContextList()) exe_module.FindSection(None) # Get the section at index 1. if exe_module.GetNumSections() > 1: sec1 = exe_module.GetSectionAtIndex(1) print sec1 else: sec1 = None if sec1: sec1.FindSubSection(None)
def test_SBSymbolContextList(self): """SBSymbolContextList object is valid after default construction.""" obj = lldb.SBSymbolContextList() if self.TraceOn(): print obj self.assertTrue(obj)
def test(self): """Exercise SBSymbolContext API extensively.""" self.build() exe = self.getBuildArtifact("a.out") # Create a target by the debugger. target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Now create a breakpoint on main.c by name 'c'. breakpoint = target.BreakpointCreateByName('c', exe) self.assertTrue(breakpoint and breakpoint.GetNumLocations() == 1, VALID_BREAKPOINT) # Now launch the process, and do not stop at entry point. process = target.LaunchSimple(None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be on self.line. thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint") frame0 = thread.GetFrameAtIndex(0) self.assertEqual(frame0.GetLineEntry().GetLine(), self.line) # Now get the SBSymbolContext from this frame. We want everything. :-) context = frame0.GetSymbolContext(lldb.eSymbolContextEverything) self.assertTrue(context) # Get the description of this module. module = context.GetModule() desc = lldbutil.get_description(module) self.expect(desc, "The module should match", exe=False, substrs=[exe]) compileUnit = context.GetCompileUnit() self.expect(str(compileUnit), "The compile unit should match", exe=False, substrs=[self.getSourcePath('main.c')]) function = context.GetFunction() self.assertTrue(function) block = context.GetBlock() self.assertTrue(block) lineEntry = context.GetLineEntry() self.expect(lineEntry.GetFileSpec().GetDirectory(), "The line entry should have the correct directory", exe=False, substrs=[self.mydir]) self.expect(lineEntry.GetFileSpec().GetFilename(), "The line entry should have the correct filename", exe=False, substrs=['main.c']) self.assertEqual(lineEntry.GetLine(), self.line, "The line entry's line number should match ") symbol = context.GetSymbol() self.assertTrue( function.GetName() == symbol.GetName() and symbol.GetName() == 'c', "The symbol name should be 'c'") sc_list = lldb.SBSymbolContextList() sc_list.Append(context) self.assertEqual(len(sc_list), 1) for sc in sc_list: self.assertEqual(lineEntry, sc.GetLineEntry())