Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Maxim Kokryashkin <m.kokryashkin@tarantool.org>,
	Igor Munkin <imun@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH luajit 1/2] gdb: introduce dumpers for GCobj
Date: Thu,  9 Jun 2022 13:11:13 +0300	[thread overview]
Message-ID: <7539a0ac196ba192636d5f6cfc1c03d9f50f7c4a.1654767443.git.skaplun@tarantool.org> (raw)
In-Reply-To: <cover.1654767443.git.skaplun@tarantool.org>

Our gdb extension already has dumpers for TValues. But sometimes it
may be useful to dump GCobjects without stack context. This patch adds
additional wrappers around dumpers for GC objects, to get the
corresponding GC object from a TValue.
---
 src/luajit-gdb.py | 151 +++++++++++++++++++++++++++++++---------------
 1 file changed, 102 insertions(+), 49 deletions(-)

diff --git a/src/luajit-gdb.py b/src/luajit-gdb.py
index baf66f66..779a25f8 100644
--- a/src/luajit-gdb.py
+++ b/src/luajit-gdb.py
@@ -301,35 +301,28 @@ gclen = {
 
 # Dumpers {{{
 
-def dump_lj_tnil(tv):
-    return 'nil'
-
-def dump_lj_tfalse(tv):
-    return 'false'
+# GCobj dumpers.
 
-def dump_lj_ttrue(tv):
-    return 'true'
+def dump_lj_gco_lightud(gcobj):
+    return 'light userdata @ {}'.format(strx64(gcobj))
 
-def dump_lj_tlightud(tv):
-    return 'light userdata @ {}'.format(strx64(gcval(tv['gcr'])))
-
-def dump_lj_tstr(tv):
+def dump_lj_gco_str(gcobj):
     return 'string {body} @ {address}'.format(
-        body = strdata(gcval(tv['gcr'])),
-        address = strx64(gcval(tv['gcr']))
+        body = strdata(gcobj),
+        address = strx64(gcobj)
     )
 
-def dump_lj_tupval(tv):
-    return 'upvalue @ {}'.format(strx64(gcval(tv['gcr'])))
+def dump_lj_gco_upval(gcobj):
+    return 'upvalue @ {}'.format(strx64(gcobj))
 
-def dump_lj_tthread(tv):
-    return 'thread @ {}'.format(strx64(gcval(tv['gcr'])))
+def dump_lj_gco_thread(gcobj):
+    return 'thread @ {}'.format(strx64(gcobj))
 
-def dump_lj_tproto(tv):
-    return 'proto @ {}'.format(strx64(gcval(tv['gcr'])))
+def dump_lj_gco_proto(gcobj):
+    return 'proto @ {}'.format(strx64(gcobj))
 
-def dump_lj_tfunc(tv):
-    func = cast('struct GCfuncC *', gcval(tv['gcr']))
+def dump_lj_gco_func(gcobj):
+    func = cast('struct GCfuncC *', gcobj)
     ffid = func['ffid']
 
     if ffid == 0:
@@ -345,57 +338,117 @@ def dump_lj_tfunc(tv):
     else:
         return 'fast function #{}'.format(int(ffid))
 
-def dump_lj_ttrace(tv):
-    trace = cast('struct GCtrace *', gcval(tv['gcr']))
+def dump_lj_gco_trace(gcobj):
+    trace = cast('struct GCtrace *', gcobj)
     return 'trace {traceno} @ {addr}'.format(
         traceno = strx64(trace['traceno']),
         addr = strx64(trace)
     )
 
-def dump_lj_tcdata(tv):
-    return 'cdata @ {}'.format(strx64(gcval(tv['gcr'])))
+def dump_lj_gco_cdata(gcobj):
+    return 'cdata @ {}'.format(strx64(gcobj))
 
-def dump_lj_ttab(tv):
-    table = cast('GCtab *', gcval(tv['gcr']))
+def dump_lj_gco_tab(gcobj):
+    table = cast('GCtab *', gcobj)
     return 'table @ {gcr} (asize: {asize}, hmask: {hmask})'.format(
         gcr = strx64(table),
         asize = table['asize'],
         hmask = strx64(table['hmask']),
     )
 
-def dump_lj_tudata(tv):
-    return 'userdata @ {}'.format(strx64(gcval(tv['gcr'])))
+def dump_lj_gco_udata(gcobj):
+    return 'userdata @ {}'.format(strx64(gcobj))
+
+def dump_lj_gco_invalid(gcobj):
+    return 'not valid type @ {}'.format(strx64(gcobj))
+
+# TValue dumpers.
+
+def dump_lj_tv_nil(tv):
+    return 'nil'
+
+def dump_lj_tv_false(tv):
+    return 'false'
+
+def dump_lj_tv_true(tv):
+    return 'true'
+
+def dump_lj_tv_lightud(tv):
+    return dump_lj_gco_lightud(gcval(tv['gcr']))
+
+def dump_lj_tv_str(tv):
+    return dump_lj_gco_str(gcval(tv['gcr']))
+
+def dump_lj_tv_upval(tv):
+    return dump_lj_gco_upval(gcval(tv['gcr']))
+
+def dump_lj_tv_thread(tv):
+    return dump_lj_gco_thread(gcval(tv['gcr']))
+
+def dump_lj_tv_proto(tv):
+    return dump_lj_gco_proto(gcval(tv['gcr']))
+
+def dump_lj_tv_func(tv):
+    return dump_lj_gco_func(gcval(tv['gcr']))
+
+def dump_lj_tv_trace(tv):
+    return dump_lj_gco_trace(gcval(tv['gcr']))
 
-def dump_lj_tnumx(tv):
+def dump_lj_tv_cdata(tv):
+    return dump_lj_gco_cdata(gcval(tv['gcr']))
+
+def dump_lj_tv_tab(tv):
+    return dump_lj_gco_tab(gcval(tv['gcr']))
+
+def dump_lj_tv_udata(tv):
+    return dump_lj_gco_udata(gcval(tv['gcr']))
+
+def dump_lj_tv_numx(tv):
     if tvisint(tv):
         return 'integer {}'.format(cast('int32_t', tv['i']))
     else:
         return 'number {}'.format(cast('double', tv['n']))
 
-def dump_lj_invalid(tv):
-    return 'not valid type @ {}'.format(strx64(gcval(tv['gcr'])))
+def dump_lj_tv_invalid(tv):
+    return dump_lj_tv_udata(gcval(tv['gcr']))
 
 # }}}
 
-dumpers = {
-    'LJ_TNIL': dump_lj_tnil,
-    'LJ_TFALSE': dump_lj_tfalse,
-    'LJ_TTRUE': dump_lj_ttrue,
-    'LJ_TLIGHTUD': dump_lj_tlightud,
-    'LJ_TSTR': dump_lj_tstr,
-    'LJ_TUPVAL': dump_lj_tupval,
-    'LJ_TTHREAD': dump_lj_tthread,
-    'LJ_TPROTO': dump_lj_tproto,
-    'LJ_TFUNC': dump_lj_tfunc,
-    'LJ_TTRACE': dump_lj_ttrace,
-    'LJ_TCDATA': dump_lj_tcdata,
-    'LJ_TTAB': dump_lj_ttab,
-    'LJ_TUDATA': dump_lj_tudata,
-    'LJ_TNUMX': dump_lj_tnumx,
+gco_dumpers = {
+    'LJ_TLIGHTUD': dump_lj_gco_lightud,
+    'LJ_TSTR':     dump_lj_gco_str,
+    'LJ_TUPVAL':   dump_lj_gco_upval,
+    'LJ_TTHREAD':  dump_lj_gco_thread,
+    'LJ_TPROTO':   dump_lj_gco_proto,
+    'LJ_TFUNC':    dump_lj_gco_func,
+    'LJ_TTRACE':   dump_lj_gco_trace,
+    'LJ_TCDATA':   dump_lj_gco_cdata,
+    'LJ_TTAB':     dump_lj_gco_tab,
+    'LJ_TUDATA':   dump_lj_gco_udata,
 }
 
+tv_dumpers = {
+    'LJ_TNIL':     dump_lj_tv_nil,
+    'LJ_TFALSE':   dump_lj_tv_false,
+    'LJ_TTRUE':    dump_lj_tv_true,
+    'LJ_TLIGHTUD': dump_lj_tv_lightud,
+    'LJ_TSTR':     dump_lj_tv_str,
+    'LJ_TUPVAL':   dump_lj_tv_upval,
+    'LJ_TTHREAD':  dump_lj_tv_thread,
+    'LJ_TPROTO':   dump_lj_tv_proto,
+    'LJ_TFUNC':    dump_lj_tv_func,
+    'LJ_TTRACE':   dump_lj_tv_trace,
+    'LJ_TCDATA':   dump_lj_tv_cdata,
+    'LJ_TTAB':     dump_lj_tv_tab,
+    'LJ_TUDATA':   dump_lj_tv_udata,
+    'LJ_TNUMX':    dump_lj_tv_numx,
+}
+
+def dump_gcobj(gcobj):
+    return gco_dumpers.get(typenames(i2notu32(gcobj['gch']['gct'])), dump_lj_gco_invalid)(gcobj)
+
 def dump_tvalue(tvalue):
-    return dumpers.get(typenames(itypemap(tvalue)), dump_lj_invalid)(tvalue)
+    return tv_dumpers.get(typenames(itypemap(tvalue)), dump_lj_tv_invalid)(tvalue)
 
 def dump_framelink(L, fr):
     fr2 = fr + LJ_FR2
@@ -408,7 +461,7 @@ def dump_framelink(L, fr):
             p = 'P' if frame_typep(fr2) & FRAME_P else ''
         ),
         d = cast('TValue *', fr2) - cast('TValue *', frame_prev(fr2)),
-        f = dump_lj_tfunc(fr),
+        f = dump_lj_tv_func(fr),
     )
 
 def dump_stack_slot(L, slot, base=None, top=None, eol='\n'):
-- 
2.34.1


  reply	other threads:[~2022-06-09 10:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-09 10:11 [Tarantool-patches] [PATCH luajit 0/2] Introduce dumpers for bytecodes in gdb Sergey Kaplun via Tarantool-patches
2022-06-09 10:11 ` Sergey Kaplun via Tarantool-patches [this message]
2022-07-04 15:24   ` [Tarantool-patches] [PATCH luajit 1/2] gdb: introduce dumpers for GCobj Maxim Kokryashkin via Tarantool-patches
2022-07-14 12:08     ` Sergey Kaplun via Tarantool-patches
2022-07-19  8:39       ` Maxim Kokryashkin via Tarantool-patches
2022-06-09 10:11 ` [Tarantool-patches] [PATCH luajit 2/2] gdb: introduce lj-bc, lj-func and lj-proto dumpers Sergey Kaplun via Tarantool-patches
2022-07-04 16:10   ` Maxim Kokryashkin via Tarantool-patches
2022-07-14 15:41     ` Sergey Kaplun via Tarantool-patches
2022-07-19  8:40       ` Maxim Kokryashkin via Tarantool-patches

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=7539a0ac196ba192636d5f6cfc1c03d9f50f7c4a.1654767443.git.skaplun@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imun@tarantool.org \
    --cc=m.kokryashkin@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit 1/2] gdb: introduce dumpers for GCobj' \
    /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