Skip to content

Commit

Permalink
misc/gdb.py: Allow overriding stack_size [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Jul 20, 2023
1 parent 210caa7 commit 8d9a25a
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions 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
Expand Down Expand Up @@ -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)'))
Expand All @@ -65,7 +80,10 @@ def invoke(self, offset, from_tty):
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))
Expand Down

0 comments on commit 8d9a25a

Please sign in to comment.