Tarantool development patches archive
 help / color / mirror / Atom feed
From: Mikhail Elhimov via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: skaplun@tarantool.org, m.kokryashkin@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH] gdb: display fast function name along with ffid
Date: Wed,  7 Aug 2024 14:31:28 +0300	[thread overview]
Message-ID: <20240807113128.3094487-1-m.elhimov@vk.team> (raw)

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


                 reply	other threads:[~2024-08-07 11:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240807113128.3094487-1-m.elhimov@vk.team \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=m.elhimov@vk.team \
    --cc=m.kokryashkin@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH] gdb: display fast function name along with ffid' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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