From 8d9a25a6d799c50514213b0d15250d9c260213d1 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Thu, 20 Jul 2023 15:02:48 -0700 Subject: [PATCH] misc/gdb.py: Allow overriding stack_size [ci skip] --- misc/gdb.py | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/misc/gdb.py b/misc/gdb.py index 96d7c3cafb..0a1b20008c 100644 --- a/misc/gdb.py +++ b/misc/gdb.py @@ -1,8 +1,17 @@ +import argparse import textwrap -# Usage: -# cfp: Dump the current cfp -# cfp 1: Dump the caller cfp +# usage: [-h] [-s STACK_SIZE] [uplevel] +# +# Dump a control frame +# +# positional arguments: +# uplevel CFP offset from the stack top +# +# options: +# -h, --help show this help message and exit +# -s STACK_SIZE, --stack-size STACK_SIZE +# override stack_size (useful for JIT frames) class CFP(gdb.Command): FRAME_MAGICS = [ # frame types @@ -35,10 +44,16 @@ class CFP(gdb.Command): def __init__(self): super(CFP, self).__init__('cfp', gdb.COMMAND_USER) - def invoke(self, offset, from_tty): - if not offset: - offset = '0' - cfp = f'(ruby_current_ec->cfp + ({offset}))' + self.parser = argparse.ArgumentParser(description='Dump a control frame') + self.parser.add_argument('uplevel', type=int, nargs='?', default=0, help='CFP offset from the stack top') + self.parser.add_argument('-s', '--stack-size', type=int, help='override stack_size (useful for JIT frames)') + + def invoke(self, args, from_tty): + try: + args = self.parser.parse_args(args.split()) + except SystemExit: + return + cfp = f'(ruby_current_ec->cfp + ({args.uplevel}))' end_cfp = self.get_int('ruby_current_ec->vm_stack + ruby_current_ec->vm_stack_size') cfp_count = int((end_cfp - self.get_int('ruby_current_ec->cfp')) / self.get_int('sizeof(rb_control_frame_t)')) @@ -65,7 +80,10 @@ class CFP(gdb.Command): self.print_stack(cfp, -1, self.frame_types(cfp, -1)) print() - stack_size = int((self.get_int(f'{cfp}->sp') - self.get_int(f'vm_base_ptr({cfp})')) / 8) + if args.stack_size is not None: + stack_size = args.stack_size + else: + stack_size = int((self.get_int(f'{cfp}->sp') - self.get_int(f'vm_base_ptr({cfp})')) / 8) print(f'Stack (size={stack_size}):') for i in range(0, stack_size): self.print_stack(cfp, i, self.rp(cfp, i))