def load_modules(self, verbose=False): print("Loading modules...", end='') sys.stdout.flush() failed = 0 loaded = 0 for module in self.for_each_module(): modname = "{}".format(module['name'].string()) modfname = "{}.ko".format(modname) found = False for path in self.searchpath: modpath = self.find_module_file(modfname, path) if not modpath: continue found = True if 'module_core' in module.type: addr = long(module['module_core']) else: addr = long(module['core_layout']['base']) if verbose: print("Loading {} at {:#x}".format(modname, addr)) sections = self.get_module_sections(module) gdb.execute("add-symbol-file {} {:#x} {}".format( modpath, addr, sections), to_string=True) sal = gdb.find_pc_line(addr) if sal.symtab is None: objfile = gdb.lookup_objfile(modpath) self.load_debuginfo(objfile, modpath) # We really should check the version, but GDB doesn't export # a way to lookup sections. break if not found: if failed == 0: print() print("Couldn't find module file for {}".format(modname)) failed += 1 else: loaded += 1 if (loaded + failed) % 10 == 10: print(".", end='') sys.stdout.flush() print(" done. ({} loaded".format(loaded), end='') if failed: print(", {} failed)".format(failed)) else: print(")") # We shouldn't need this again, so why keep it around? del self.findmap self.findmap = {}
def load_modules(self, searchpath, verbose=False): print("Loading modules...", end='') sys.stdout.flush() failed = 0 loaded = 0 for module in for_each_module(): modname = "{}".format(module['name'].string()) modfname = "{}.ko".format(modname) found = False for path in searchpath: modpath = self.find_module_file(modfname, path) if not modpath: continue found = True if verbose: print("Loading {} at {}" .format(modname, module['module_core'])) sections = get_module_sections(module) gdb.execute("add-symbol-file {} {} {}" .format(modpath, module['module_core'], sections), to_string=True) sal = gdb.find_pc_line(long(module['module_core'])) if sal.symtab is None: objfile = gdb.lookup_objfile(modpath) load_debuginfo(searchpath, objfile, modpath) # We really should check the version, but GDB doesn't export # a way to lookup sections. break if not found: if failed == 0: print() print("Couldn't find module file for {}".format(modname)) failed += 1 else: loaded += 1 if (loaded + failed) % 10 == 10: print(".", end='') sys.stdout.flush() print(" done. ({} loaded".format(loaded), end='') if failed: print(", {} failed)".format(failed)) else: print(")") # We shouldn't need this again, so why keep it around? del self.findmap self.findmap = {}
def iterdump_Objfile(objfileName): x = None try: x = gdb.lookup_objfile(objfileName) except ValueError as err: pass if not x: _common.die('None such.') printf('Objfile {\n') for k, v in x.__dict__: printf('\t%s --> %s\n', str(k), str(v)) printf('}\n') y = x.progspace if not y: _common.die('No progspace associated.') printf('\nProgspace {\n') for k, v in y.__dict__: printf('\t%s --> %s\n', str(k), str(v)) printf('}\n')
if str(val.type).startswith("MVM"): try: val.cast(gdb.lookup_type("MVMObject" + (" *" if pointer else ""))) return MVMObjectPPrinter(val, pointer) except Exception as e: print("couldn't cast this:", e) pass return None def register_printers(objfile): objfile.pretty_printers.append(str_lookup_function) print("MoarVM string pretty printer registered") # XXX since this is currently nonfunctional, just ignore it for now # objfile.pretty_printers.append(mvmobject_lookup_function) # print("MoarVM Object pretty printer registered") commands = [] def register_commands(objfile): commands.append(AnalyzeHeapCommand()) print("moar-heap registered") commands.append(DiffHeapCommand()) print("diff-moar-heap registered") # We have to introduce our classes to gdb so that they can be used if __name__ == "__main__": the_objfile = gdb.current_objfile() if the_objfile == None: the_objfile = gdb.lookup_objfile("libmoar.so") register_printers(the_objfile) register_commands(the_objfile)
def load_modules(self, verbose: bool = False, debug: bool = False) -> None: """ Load modules (including debuginfo) into the crash session. This routine will attempt to locate modules and the corresponding debuginfo files, if separate, using the parameters defined when the CrashKernel object was initialized. Args: verbose (default=False): enable verbose output debug (default=False): enable even more verbose debugging output Raises: CrashKernelError: An error was encountered while loading a module. This does not include a failure to locate a module or its debuginfo. """ import crash.cache.syscache # pylint: disable=redefined-outer-name version = crash.cache.syscache.utsname.release print("Loading modules for {}".format(version), end='') if verbose: print(":", flush=True) failed = 0 loaded = 0 for module in for_each_module(): modname = "{}".format(module['name'].string()) modfname = "{}.ko".format(modname) found = False for path in self.module_path: try: modpath = self._find_module_file(modfname, path) except _NoMatchingFileError: continue try: self._check_module_version(modpath, module) except _ModinfoMismatchError as e: if verbose: print(str(e)) continue found = True if 'module_core' in module.type: addr = int(module['module_core']) else: addr = int(module['core_layout']['base']) if debug: print("Loading {} at {:#x}".format(modpath, addr)) elif verbose: print("Loading {} at {:#x}".format(modname, addr)) else: print(".", end='') sys.stdout.flush() sections = self._get_module_sections(module) percpu = int(module['percpu']) if percpu > 0: sections += " -s .data..percpu {:#x}".format(percpu) try: result = gdb.execute("add-symbol-file {} {:#x} {}".format( modpath, addr, sections), to_string=True) except gdb.error as e: raise CrashKernelError( "Error while loading module `{}': {}".format( modname, str(e))) if debug: print(result) objfile = gdb.lookup_objfile(modpath) if not objfile.has_symbols(): self._load_module_debuginfo(objfile, modpath, verbose) elif debug: print(" + has debug symbols") break if not found: if failed == 0: print() print("Couldn't find module file for {}".format(modname)) failed += 1 else: if not objfile.has_symbols(): print("Couldn't find debuginfo for {}".format(modname)) loaded += 1 if (loaded + failed) % 10 == 10: print(".", end='') sys.stdout.flush() print(" done. ({} loaded".format(loaded), end='') if failed: print(", {} failed)".format(failed)) else: print(")") # We shouldn't need this again, so why keep it around? del self.findmap self.findmap = {}