misc/gdb.py: Allow overriding stack_size [ci skip]

This commit is contained in:
Takashi Kokubun 2023-07-20 15:02:48 -07:00
Родитель 210caa777b
Коммит 8d9a25a6d7
1 изменённых файлов: 26 добавлений и 8 удалений

Просмотреть файл

@ -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))