14 """Print a folly::fibers::Fiber""" 19 state = self.
val[
'state_']
20 d = gdb.types.make_enum_dict(state.type)
21 d = dict((v, k)
for k, v
in d.items())
25 if self.
state ==
"folly::fibers::Fiber::INVALID":
27 if self.
state ==
"folly::fibers::Fiber::NOT_STARTED":
29 if self.
state ==
"folly::fibers::Fiber::READY_TO_RUN":
31 if self.
state ==
"folly::fibers::Fiber::RUNNING":
33 if self.
state ==
"folly::fibers::Fiber::AWAITING":
35 if self.
state ==
"folly::fibers::Fiber::AWAITING_IMMEDIATE":
36 return "Awaiting immediate" 37 if self.
state ==
"folly::fibers::Fiber::YIELDED":
42 return self.
state !=
"folly::fibers::Fiber::INVALID" and \
43 self.
state !=
"folly::fibers::Fiber::NOT_STARTED" and \
44 self.
state !=
"folly::fibers::Fiber::RUNNING" 47 result = collections.OrderedDict()
53 return "folly::fibers::Fiber" 56 return "folly::fibers::Fiber" 61 return gdb.lookup_type(
'int')
64 return gdb.lookup_type(
'int')
73 raise gdb.GdbError(
"Index out of range")
80 super(GetFiberXMethodMatcher, self).
__init__(
81 "Fiber address method matcher")
84 def match(self, class_type, method_name):
85 if class_type.name ==
"folly::fibers::FiberManager" and \
86 method_name ==
"get_fiber":
93 fm[
'allFibers_'][
'data_'][
'root_plus_size_'][
'm_header']
94 fiber_hook = all_fibers[
'next_']
98 while fiber_hook != all_fibers.address:
99 fiber = fiber_hook.cast(gdb.lookup_type(
"int64_t"))
100 fiber = fiber - gdb.parse_and_eval(
101 "(int64_t)&'folly::fibers::Fiber'::globalListHook_")
103 gdb.lookup_type(
'folly::fibers::Fiber').pointer()).
dereference()
105 if FiberPrinter(fiber).state !=
"folly::fibers::Fiber::INVALID":
108 fiber_hook = fiber_hook.dereference()[
'next_']
110 fiber_count = fiber_count + 1
114 """Print a folly::fibers::Fiber""" 116 fiber_print_limit = 100
122 def limit_with_dots(fibers_iterator):
124 for fiber
in fibers_iterator:
129 yield (str(fiber.address), fiber)
135 return "folly::fibers::FiberManager" 138 return "folly::fibers::FiberManager" 143 super(FiberPrintLimitCommand, self).
__init__(
144 "fiber-print-limit", gdb.COMMAND_USER)
148 print(
"New limit has to be passed to 'fiber_print_limit' command")
150 FiberManagerPrinter.fiber_print_limit = int(arg)
151 print(
"New fiber limit for FiberManager printer set to " +
152 str(FiberManagerPrinter.fiber_print_limit))
169 cls.instance.skip_frame_sp = skip_frame_sp
172 self.
name =
"FiberUnwinderFrameFilter" 175 gdb.frame_filters[self.
name] = self
178 if not self.skip_frame_sp:
184 for frame
in frame_iter:
185 frame_sp = frame.inferior_frame().read_register(
"rsp")
186 if frame_sp == self.skip_frame_sp:
198 gdb.unwinder.register_unwinder(
None, cls.
instance)
200 fiber_impl = fiber[
'fiberImpl_']
201 cls.instance.fiber_context_ptr = fiber_impl[
'fiberContext_']
204 super(FiberUnwinder, self).
__init__(
"Fiber unwinder")
211 orig_sp = pending_frame.read_register(
'rsp')
212 orig_pc = pending_frame.read_register(
'rip')
214 void_star_star = gdb.lookup_type(
'uint64_t').pointer()
215 ptr = self.fiber_context_ptr.cast(void_star_star)
237 frame_id =
FrameId(rsp, orig_pc)
238 unwind_info = pending_frame.create_unwind_info(frame_id)
239 unwind_info.add_saved_register(
'rbp', rbp)
240 unwind_info.add_saved_register(
'rsp', rsp)
241 unwind_info.add_saved_register(
'rip', rip)
245 FiberUnwinderFrameFilter.set_skip_frame_sp(orig_sp)
251 fiber_type = gdb.lookup_type(
"folly::fibers::Fiber")
252 if fiber.type != fiber_type:
253 fiber = fiber.cast(fiber_type.pointer()).
dereference()
255 return "Can not activate a non-waiting fiber." 256 gdb.invalidate_cached_frames()
257 FiberUnwinder.set_fiber(fiber)
258 return "Fiber 0x{:12x} activated. You can call 'bt' now.".
format(int(fiber.address))
262 FiberUnwinderFrameFilter.set_skip_frame_sp(
None)
263 gdb.invalidate_cached_frames()
264 return "Fiber de-activated." 269 super(FiberActivateCommand, self).
__init__(
"fiber", gdb.COMMAND_USER)
273 print(
"folly::fibers::Fiber* has to be passed to 'fiber' command")
275 fiber_ptr = gdb.parse_and_eval(arg)
281 super(FiberDeactivateCommand, self).
__init__(
282 "fiber-deactivate", gdb.COMMAND_USER)
301 super(FiberXMethodMatcher, self).
__init__(
"Fiber method matcher")
304 def match(self, class_type, method_name):
305 if class_type.name ==
"folly::fibers::Fiber" and \
306 method_name ==
"activate":
313 super(Shortcut, self).
__init__(function_name)
324 global_cache_type = gdb.lookup_type(
325 "folly::fibers::(anonymous namespace)::GlobalCache<" + evb_type +
">")
327 raise gdb.GdbError(
"Unable to find types. " 328 "Please make sure debug info is available for this binary.\n" 329 "Have you run 'fbload debuginfo_fbpkg'?")
331 global_cache_instance_ptr_ptr = gdb.parse_and_eval(
332 "&'" + global_cache_type.name +
"::instance()::ret'")
333 global_cache_instance_ptr = global_cache_instance_ptr_ptr.cast(
334 global_cache_type.pointer().pointer()).
dereference()
335 if global_cache_instance_ptr == 0x0:
336 raise gdb.GdbError(
"FiberManager map is empty.")
338 global_cache_instance = global_cache_instance_ptr.dereference()
339 return global_cache_instance[
'map_']
351 pp = gdb.printing.RegexpCollectionPrettyPrinter(
"folly_fibers")
352 pp.add_printer(
'fibers::Fiber',
'^folly::fibers::Fiber$', FiberPrinter)
353 pp.add_printer(
'fibers::FiberManager',
'^folly::fibers::FiberManager$',
365 Shortcut(
"get_fiber_manager_map_evb", get_fiber_manager_map_evb)
366 Shortcut(
"get_fiber_manager_map_vevb", get_fiber_manager_map_vevb)
370 return "Pretty printers for folly::fibers" def get_result_type(self)
def build_pretty_printer()
def get_result_type(self)
def backtrace_available(self)
def __init__(self, function_name, value_lambda)
def get_fiber_manager_map_vevb()
def invoke(self, arg, from_tty)
def get_fiber_manager_map(evb_type)
def get_fiber_manager_map_evb()
def match(self, class_type, method_name)
def invoke(self, arg, from_tty)
def set_fiber(cls, fiber)
def fiber_manager_active_fibers(fm)
def fiber_activate(fiber)
def __call__(self, pending_frame)
def state_to_string(self)
def invoke(self, arg, from_tty)
def filter(self, frame_iter)
def match(self, class_type, method_name)
Formatter< false, Args... > format(StringPiece fmt, Args &&...args)
def filter_impl(self, frame_iter)
def __init__(self, sp, pc)
def set_skip_frame_sp(cls, skip_frame_sp)
constexpr detail::Dereference dereference