Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Bronnikov via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Mikhail Elhimov <m.elhimov@vk.team>,
	Sergey Kaplun <skaplun@tarantool.org>,
	Evgeniy Temirgaleev <e.temirgaleev@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit v5] dbg: display fast function name along with ffid
Date: Fri, 16 Oct 2026 17:49:04 +0300	[thread overview]
Message-ID: <f362ac64-8783-4f3d-b31e-2d70d7952c5f@tarantool.org> (raw)
In-Reply-To: <20261015213833.380877-1-m.elhimov@vk.team>

Hi, Mikhail,

thanks for the patch! LGTM

Sergey

On 10/16/26 00:38, Mikhail Elhimov wrote:
> Part of tarantool/tarantool#4808
> ---
> Changes in v5:
>    * Dropped unnecessary changes
>    * Rebased onto https://lists.tarantool.org/pipermail/tarantool-patches/2026-October/030858.html
>
> Changes in v4:
>    * Adjusted mapping of enum member to name ('_' is replaced with '.' only if it is not preceded by another '_')
>    * Added tests of various ff (including unknown)
>    * Reduced code duplication
>    * Fixed typos
>
> Changes in v3:
>    * Fixed fast function regexp in tests
>
> Changes in v2:
>    * Format is changed to 'ffname (#ffid)'
>    * Replaced single '_' with '.' in ffname
>    * Adjusted tests to check mapping
>
> This patch is to be applied after https://lists.tarantool.org/pipermail/tarantool-patches/2026-October/030858.html
>
> Branch: https://github.com/tarantool/luajit/tree/elhimov/gh-4808-display-fast-function-name
> Related issue: https://github.com/tarantool/tarantool/issues/4808
>
>   src/luajit_dbg.py                             |  36 ++++--
>   .../debug-extension-tests.py                  | 122 ++++++++++++++----
>   2 files changed, 116 insertions(+), 42 deletions(-)
>
> diff --git a/src/luajit_dbg.py b/src/luajit_dbg.py
> index a4d7820e..a685ecfa 100644
> --- a/src/luajit_dbg.py
> +++ b/src/luajit_dbg.py
> @@ -1125,6 +1125,11 @@ def frames(L):
>   # LuaJIT macro implementations and structure access.
>   
>   
> +# Get FastFunc enum members and replace any single '_' with '.'.
> +FF_NAMES = EnumBasedList('FF__MAX', 'FastFunc', lambda x:
> +                         re.sub('(?<!_)_', '.', cut_prefix(x, 'FF_')))
> +
> +
>   def mref(typename, obj):
>       return dbg.cast(typename, obj['ptr64'] if LJ_GC64 else obj['ptr32'])
>   
> @@ -1691,6 +1696,11 @@ def ir_kint64(ir):
>   
>   # Dumpers.
>   
> +def dump_fast_function(ffid):
> +    ffname = FF_NAMES[ffid] if ffid < len(FF_NAMES) else 'unknown'
> +    return 'fast function {} (#{})'.format(ffname, ffid)
> +
> +
>   # GCobj dumpers.
>   
>   def dump_lj_gco_str(gcobj):
> @@ -1714,7 +1724,7 @@ def dump_lj_gco_proto(gcobj):
>   
>   def dump_lj_gco_func(gcobj):
>       func = dbg.cast('struct GCfuncC *', gcobj)
> -    ffid = func['ffid']
> +    ffid = int(func['ffid'])
>   
>       if ffid == 0:
>           pt = funcproto(func)
> @@ -1727,7 +1737,7 @@ def dump_lj_gco_func(gcobj):
>       elif ffid == 1:
>           return 'C function @ {}'.format(strx64(func['f']))
>       else:
> -        return 'fast function #{}'.format(int(ffid))
> +        return dump_fast_function(ffid)
>   
>   
>   def dump_lj_gco_trace(gcobj):
> @@ -2061,7 +2071,7 @@ def dump_proto(proto):
>       startbc = proto_bc(proto)
>       func_loc = proto_loc(proto)
>       # Location has the following format: '{chunk}:{firstline}'.
> -    dump = '{func_loc}-{lastline}\n'.format(
> +    dump = '{func_loc}-{lastline}'.format(
>           func_loc=func_loc,
>           lastline=proto['firstline'] + proto['numline'],
>       )
> @@ -2070,22 +2080,22 @@ def dump_proto(proto):
>           return '=> ' + str(npc_from + delta).zfill(4)
>   
>       for bcnum in range(0, int(proto['sizebc'])):
> -        dump += (str(bcnum).zfill(4) + ' ' + dump_bc(
> +        dump += '\n' + str(bcnum).zfill(4) + ' ' + dump_bc(
>               startbc[bcnum], jmp_format=jmp_format, jmp_ctx=bcnum, proto=proto,
> -        ) + '\n')
> +        )
>       return dump
>   
>   
>   def dump_func(func):
> -    ffid = func['ffid']
> +    ffid = int(func['ffid'])
>   
>       if ffid == 0:
>           pt = funcproto(func)
>           return dump_proto(pt)
>       elif ffid == 1:
> -        return 'C function @ {}\n'.format(strx64(func['f']))
> +        return 'C function @ {}'.format(strx64(func['f']))
>       else:
> -        return 'fast function #{}\n'.format(int(ffid))
> +        return dump_fast_function(ffid)
>   
>   
>   # FFI dumpers.
> @@ -2667,7 +2677,7 @@ function:
>       '''
>   
>       def execute(self, arg):
> -        dbg.write('{}'.format(dump_func(dbg.cast('GCfuncC *', dbg.eval(arg)))))
> +        dbg.write(dump_func(dbg.cast('GCfuncC *', dbg.eval(arg))) + '\n')
>   
>   
>   class LJGC(dbg.LJBase):
> @@ -2711,7 +2721,7 @@ the type and some info related to it.
>   * LJ_TFUNC: <LFUNC|CFUNC|FFUNC>
>     <LFUNC>: Lua function @ <gcr>, <nupvals> upvalues, <chunk:line>
>     <CFUNC>: C function <mcode address>
> -  <FFUNC>: fast function #<ffid>
> +  <FFUNC>: fast function <ffname> (#<ffid>)
>   * LJ_TTRACE: trace <traceno> @ <gcr>
>   * LJ_TCDATA: cdata @ <gcr>
>   * LJ_TTAB: table @ <gcr> (asize: <asize>, hmask: <hmask>)
> @@ -2784,9 +2794,7 @@ function:
>       '''
>   
>       def execute(self, arg):
> -        dbg.write('{}'.format(
> -            dump_proto(dbg.cast('GCproto *', dbg.eval(arg)))
> -        ))
> +        dbg.write(dump_proto(dbg.cast('GCproto *', dbg.eval(arg))) + '\n')
>   
>   
>   class LJDumpStack(dbg.LJBase):
> @@ -2931,7 +2939,7 @@ the type and some info related to it.
>   * LJ_TFUNC: <LFUNC|CFUNC|FFUNC>
>     <LFUNC>: Lua function @ <gcr>, <nupvals> upvalues, <chunk:line>
>     <CFUNC>: C function <mcode address>
> -  <FFUNC>: fast function #<ffid>
> +  <FFUNC>: fast function <ffname> (#<ffid>)
>   * LJ_TTRACE: trace <traceno> @ <gcr>
>   * LJ_TCDATA: cdata @ <gcr>
>   * LJ_TTAB: table @ <gcr> (asize: <asize>, hmask: <hmask>)
> diff --git a/test/tarantool-debugger-tests/debug-extension-tests.py b/test/tarantool-debugger-tests/debug-extension-tests.py
> index 359163e9..bbd53dcc 100644
> --- a/test/tarantool-debugger-tests/debug-extension-tests.py
> +++ b/test/tarantool-debugger-tests/debug-extension-tests.py
> @@ -35,6 +35,10 @@ if LLDB:
>           '--source-quietly',
>           '--source'
>       ]
> +
> +    def modify_obj_cmd(obj, val):
> +        return 'expression {} = {}'.format(obj, val)
> +
>   else:
>       # GDB.
>       INFERIOR_ARGS = '--args'
> @@ -43,6 +47,9 @@ else:
>       # Don't run any initialization scripts.
>       RUN_CMD_FILE = ['--batch', '--nx', '--quiet', '--command']
>   
> +    def modify_obj_cmd(obj, val):
> +        return 'set var {} = {}'.format(obj, val)
> +
>   TEST_VERBOSE = os.getenv('DEBUGGER_TEST_VERBOSE', default=False)
>   
>   RX_ADDR = r'0x[a-f0-9]+'
> @@ -334,13 +341,31 @@ class TestLJStackFunc(TestCaseBase):
>       pattern = STACK_RX
>   
>   
> +FFUNC_ARGS = (
> +    'print,\n'
> +    'math.min,\n'
> +    'getmetatable(io.stdout).close,\n'
> +    'getmetatable(io.stdout).__gc,\n'
> +    'getmetatable(io.stdout).__tostring,\n'
> +)
> +
> +
> +FFUNC_RX = (
> +    r'fast function print \(#[0-9]+\)\n'
> +    r'fast function math.min \(#[0-9]+\)\n'
> +    r'fast function io.method.close \(#[0-9]+\)\n'
> +    r'fast function io.method.__gc \(#[0-9]+\)\n'
> +    r'fast function io.method.__tostring \(#[0-9]+\)\n'
> +)
> +
> +
>   # Sorted in LJT order.
>   GCO_ARGS = (
>       '"hello",\n'
>       'coroutine.create(function() end),\n'
>       'function() end,\n'
> -    'require,\n'
> -    'print,\n'
> +    'require,\n' +
> +    FFUNC_ARGS +
>       'ffi.new("int*"),\n'
>       '{1},\n'
>       'newproxy(),\n'
> @@ -351,8 +376,8 @@ GCO_RX = (
>       r'string \"hello\" @ ' + RX_ADDR + r'\n'
>       r'thread @ ' + RX_ADDR + r'\n'
>       r'Lua function @ ' + RX_ADDR + r', [0-9]+ upvalues, .+:[0-9]+\n'
> -    r'C function @ ' + RX_ADDR + r'\n'
> -    r'fast function #[0-9]+\n'
> +    r'C function @ ' + RX_ADDR + r'\n' +
> +    FFUNC_RX +
>       r'cdata @ ' + RX_ADDR + r' \[\d+\] <int \*> 0x0\n'
>       r'table @ ' + RX_ADDR + r' \(asize: \d+, hmask: ' + RX_HASH + r'\)\n'
>       r'userdata @ ' + RX_ADDR + r'\n'
> @@ -361,21 +386,9 @@ GCO_RX = (
>   
>   class TestLJTV(TestCaseBase):
>       location = 'lj_cf_print'
> -    extension_cmds = (
> -        'lj-tv L->base\n'
> -        'lj-tv L->base + 1\n'
> -        'lj-tv L->base + 2\n'
> -        'lj-tv L->base + 3\n'
> -        'lj-tv L->base + 4\n'
> -        'lj-tv L->base + 5\n'
> -        'lj-tv L->base + 6\n'
> -        'lj-tv L->base + 7\n'
> -        'lj-tv L->base + 8\n'
> -        'lj-tv L->base + 9\n'
> -        'lj-tv L->base + 10\n'
> -        'lj-tv L->base + 11\n'
> -        'lj-tv L->base + 12\n'
> -        'lj-tv L->base + 13\n'
> +    extension_cmds = ''.join(
> +        ('lj-tv L->base+{}\n'.format(i)
> +         for i in range(4 + GCO_ARGS.count('\n') + 2))
>       )
>   
>       # Sorted in LJT order.
> @@ -436,15 +449,9 @@ class TestLJTab(TestCaseBase):
>   
>   class TestLJGCo(TestCaseBase):
>       location = 'lj_cf_print'
> -    extension_cmds = (
> -        'lj-gco ' + gcval('L->base + 0') + '\n'
> -        'lj-gco ' + gcval('L->base + 1') + '\n'
> -        'lj-gco ' + gcval('L->base + 2') + '\n'
> -        'lj-gco ' + gcval('L->base + 3') + '\n'
> -        'lj-gco ' + gcval('L->base + 4') + '\n'
> -        'lj-gco ' + gcval('L->base + 5') + '\n'
> -        'lj-gco ' + gcval('L->base + 6') + '\n'
> -        'lj-gco ' + gcval('L->base + 7') + '\n'
> +    extension_cmds = ''.join(
> +        ('lj-gco ' + gcval('L->base + {}'.format(i)) + '\n'
> +         for i in range(GCO_ARGS.count('\n')))
>       )
>   
>       lua_script = (
> @@ -458,6 +465,65 @@ class TestLJGCo(TestCaseBase):
>       pattern = GCO_RX
>   
>   
> +class TestLJGCoFFUnknown(TestCaseBase):
> +    location = 'lj_cf_print'
> +
> +    val = '((GCfuncC *)' + gcval('L->base') + ')'
> +    extension_cmds = (
> +        'lj-gco ' + val + '\n' +
> +        modify_obj_cmd(val + '->ffid', 242) + '\n'
> +        'lj-gco ' + val + '\n' +
> +        modify_obj_cmd(val + '->ffid', 253) + '\n'
> +        'lj-gco ' + val + '\n'
> +    )
> +
> +    lua_script = 'print(pcall)'
> +
> +    pattern = (
> +        r'fast function pcall \(#[0-9]+\)\n'
> +        r'fast function unknown \(#242\)\n'
> +        r'fast function unknown \(#253\)\n'
> +    )
> +
> +
> +class TestLJFuncFFKnown(TestCaseBase):
> +    location = 'lj_cf_print'
> +    extension_cmds = ''.join(
> +        ('lj-func ' + gcval('L->base + {}'.format(i)) + '\n'
> +         for i in range(FFUNC_ARGS.count('\n')))
> +    )
> +
> +    lua_script = (
> +        'print(\n' +
> +        FFUNC_ARGS +
> +        '  1\n'  # Stub for the pattern.
> +        ')\n'
> +    )
> +
> +    pattern = FFUNC_RX
> +
> +
> +class TestLJFuncFFUnknown(TestCaseBase):
> +    location = 'lj_cf_print'
> +
> +    val = '((GCfuncC *)' + gcval('L->base') + ')'
> +    extension_cmds = (
> +        'lj-func ' + val + '\n' +
> +        modify_obj_cmd(val + '->ffid', 242) + '\n'
> +        'lj-func ' + val + '\n' +
> +        modify_obj_cmd(val + '->ffid', 253) + '\n'
> +        'lj-func ' + val + '\n'
> +    )
> +
> +    lua_script = 'print(pcall)'
> +
> +    pattern = (
> +        r'fast function pcall \(#[0-9]+\)\n'
> +        r'fast function unknown \(#242\)\n'
> +        r'fast function unknown \(#253\)\n'
> +    )
> +
> +
>   PROTO_FUNC_SCRIPT = (
>       'local uvname = false\n'
>       'local function testf(...)\n'

      parent reply	other threads:[~2026-10-16 14:49 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09 13:07 [Tarantool-patches] [PATCH luajit] " Mikhail Elhimov via Tarantool-patches
2026-09-22  9:16 ` Sergey Kaplun via Tarantool-patches
2026-09-23 22:55   ` Mikhail Elhimov via Tarantool-patches
2026-09-24 16:48   ` [Tarantool-patches] [PATCH luajit v2] " Mikhail Elhimov via Tarantool-patches
2026-09-24 20:14     ` [Tarantool-patches] [PATCH luajit v3] " Mikhail Elhimov via Tarantool-patches
2026-09-28 13:02       ` Sergey Bronnikov via Tarantool-patches
2026-10-07 16:27         ` Mikhail Elhimov via Tarantool-patches
2026-10-07 16:33         ` [Tarantool-patches] [PATCH luajit v4] " Mikhail Elhimov via Tarantool-patches
2026-10-08 10:58           ` Sergey Bronnikov via Tarantool-patches
2026-10-14  9:53           ` Sergey Kaplun via Tarantool-patches
2026-10-15 21:38           ` [Tarantool-patches] [PATCH luajit v5] " Mikhail Elhimov via Tarantool-patches
2026-10-16 12:28             ` Sergey Kaplun via Tarantool-patches
2026-10-16 14:49             ` Sergey Bronnikov via Tarantool-patches [this message]

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=f362ac64-8783-4f3d-b31e-2d70d7952c5f@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=e.temirgaleev@tarantool.org \
    --cc=m.elhimov@vk.team \
    --cc=sergeyb@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit v5] dbg: 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