Skip to content

Commit

Permalink
gdb: display fast function name along with ffid
Browse files Browse the repository at this point in the history
  • Loading branch information
elhimov committed Aug 7, 2024
1 parent 01f4586 commit 272fb07
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/luajit-gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import gdb
import sys
import itertools

# make script compatible with the ancient Python {{{

Expand All @@ -14,6 +15,7 @@
CONNECTED = False
int = long
range = xrange
filter = itertools.ifilter


# }}}
Expand Down Expand Up @@ -74,6 +76,20 @@ def strx64(val):
hex(int(cast('uint64_t', val) & 0xFFFFFFFFFFFFFFFF)))


def find(predicate, iterable, default=None):
return next(filter(predicate, iterable), default)


def enumval_name(type, val, default):
assert type.code == gdb.TYPE_CODE_ENUM, "enumval_name expects enum type \
but type of code {} was given".format(type.code)
enumval_attr = 'enumval'
if not hasattr(type.fields()[0], 'enumval'):
enumval_attr = 'bitpos'
field = find(lambda x: getattr(x, enumval_attr) == val, type.fields())
return default if field is None else field.name


# Types {{{


Expand Down Expand Up @@ -426,7 +442,7 @@ def dump_lj_tproto(tv):

def dump_lj_tfunc(tv):
func = cast('struct GCfuncC *', gcval(tv['gcr']))
ffid = func['ffid']
ffid = int(func['ffid'])

if ffid == 0:
pt = funcproto(func)
Expand All @@ -439,7 +455,9 @@ def dump_lj_tfunc(tv):
elif ffid == 1:
return 'C function @ {}'.format(strx64(func['f']))
else:
return 'fast function #{}'.format(int(ffid))
ffid_enum = gdb.parse_and_eval('FF__MAX').type
ffid_name = enumval_name(ffid_enum, ffid, 'UNKNOWN')
return 'fast function #{}({})'.format(ffid, ffid_name)


def dump_lj_ttrace(tv):
Expand Down

0 comments on commit 272fb07

Please sign in to comment.