def set_fiber(cls, fiber): cls.init() if not fiber: if not cls.instance.fiber: return "No active fiber." # get the relevant fiber's info, new one if specified, old one if not info = FiberInfo(fiber or cls.instance.fiber) if fiber: if not FiberPrinter(fiber).backtrace_available(): return "Can not activate a non-waiting fiber." # set the unwinder to do the right thing cls.instance.fiber_context_ptr = fiber["fiberImpl_"][ "fiberContext_"] else: # disable the unwinder cls.instance.fiber_context_ptr = None # track the active fiber (or lack thereof) cls.instance.fiber = fiber # Clear frame cache to make sure we actually use the right unwinder gdb.invalidate_cached_frames() return "[{action} fiber {id} ({info})]".format( action="Switching to" if fiber else "Deactivating", id=info.id, info=info)
def fiber_activate(fiber): fiber_type = gdb.lookup_type("folly::fibers::Fiber") if fiber.type != fiber_type: fiber = fiber.cast(fiber_type.pointer()).dereference() if not FiberPrinter(fiber).backtrace_available(): return "Can not activate a non-waiting fiber." gdb.invalidate_cached_frames() FiberUnwinder.set_fiber(fiber) return "Fiber 0x{:12x} activated. You can call 'bt' now.".format(int(fiber.address))
def do_enable_unwinder(arg, flag): """Enable/disable unwinder(s).""" (locus_re, name_re) = parse_unwinder_command_args(arg) total = 0 if locus_re.match("global"): total += do_enable_unwinder1(gdb.frame_unwinders, name_re, flag) if locus_re.match("progspace"): total += do_enable_unwinder1(gdb.current_progspace().frame_unwinders, name_re, flag) for objfile in gdb.objfiles(): if locus_re.match(objfile.filename): total += do_enable_unwinder1(objfile.frame_unwinders, name_re, flag) if total > 0: gdb.invalidate_cached_frames() print("%d unwinder%s %s" % (total, "" if total == 1 else "s", "enabled" if flag else "disabled"))
def register_unwinder(locus, unwinder, replace=False): """Register unwinder in given locus. The unwinder is prepended to the locus's unwinders list. Unwinder name should be unique. Arguments: locus: Either an objfile, progspace, or None (in which case the unwinder is registered globally). unwinder: An object of a gdb.Unwinder subclass replace: If True, replaces existing unwinder with the same name. Otherwise, raises exception if unwinder with the same name already exists. Returns: Nothing. Raises: RuntimeError: Unwinder name is not unique TypeError: Bad locus type """ if locus is None: if gdb.parameter("verbose"): gdb.write("Registering global %s unwinder ...\n" % unwinder.name) locus = gdb elif isinstance(locus, gdb.Objfile) or isinstance(locus, gdb.Progspace): if gdb.parameter("verbose"): gdb.write("Registering %s unwinder for %s ...\n" % (unwinder.name, locus.filename)) else: raise TypeError("locus should be gdb.Objfile or gdb.Progspace or None") i = 0 for needle in locus.frame_unwinders: if needle.name == unwinder.name: if replace: del locus.frame_unwinders[i] else: raise RuntimeError("Unwinder %s already exists." % unwinder.name) i += 1 locus.frame_unwinders.insert(0, unwinder) gdb.invalidate_cached_frames()
def fiber_deactivate(): FiberUnwinderFrameFilter.set_skip_frame_sp(None) gdb.invalidate_cached_frames() return "Fiber de-activated."