Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] gdb: display fast function name along with ffid
@ 2024-08-07 11:31 Mikhail Elhimov via Tarantool-patches
  0 siblings, 0 replies; only message in thread
From: Mikhail Elhimov via Tarantool-patches @ 2024-08-07 11:31 UTC (permalink / raw)
  To: skaplun, m.kokryashkin; +Cc: tarantool-patches

Part of tarantool/tarantool#4808
---

Branch: https://github.com/tarantool/luajit/tree/elhimov/gh-4808-display-fast-function-name
Issue: https://github.com/tarantool/tarantool/issues/4808

 src/luajit-gdb.py | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/luajit-gdb.py b/src/luajit-gdb.py
index d2070e9b..967124a8 100644
--- a/src/luajit-gdb.py
+++ b/src/luajit-gdb.py
@@ -4,6 +4,7 @@
 import re
 import gdb
 import sys
+import itertools
 
 # make script compatible with the ancient Python {{{
 
@@ -14,6 +15,7 @@ if LEGACY:
     CONNECTED = False
     int = long
     range = xrange
+    filter = itertools.ifilter
 
 
 # }}}
@@ -74,6 +76,14 @@ def strx64(val):
                   hex(int(cast('uint64_t', val) & 0xFFFFFFFFFFFFFFFF)))
 
 
+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 hasattr(type.fields()[0], 'enumval') else 'bitpos'
+    field = next(filter(lambda x: getattr(x, enumval_attr) == val, type.fields()), None)
+    return field.name if field is not None else default
+
+
 # Types {{{
 
 
@@ -426,7 +436,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)
@@ -439,7 +449,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):
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-08-07 11:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-07 11:31 [Tarantool-patches] [PATCH] gdb: display fast function name along with ffid Mikhail Elhimov via Tarantool-patches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox