Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Mikhail Elhimov <m.elhimov@vk.team>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit 2/4] dbg: avoid hardcoded enums
Date: Fri, 20 Nov 2026 17:13:11 +0300	[thread overview]
Message-ID: <awBVd0AkquL4I3fT@root> (raw)
In-Reply-To: <fd5adcd59ddf0307c88149715a11fddc1ba27a39.1794522533.git.m.elhimov@vk.team>

Hi, Mikhail!
Thanks for the update!
LGTM, with minor nits below.

On 13.11.26, Mikhail Elhimov wrote:
> Besides reducing lines of code this way the extension becomes compatible
> with various versions of LuaJIT because different versions might use
> different sets of enum members (a newer version might introduce
> additional BC/IR/etc.)
> 
> Prior to this patch, the string was used as a debugger-agnostic way to
> specify type, but this way might not work in the case of an enum because
> debugging information might be optimized out if no variable of such an
> enum type is declared and its members are used only as predefined
> constants. The type of enum is needed to be able to get human-readable
> value (member name instead of number). The alternative way to get enum
> type is to get it from the value, i.e. somehow obtain the value that is
> of enum type and then use this type to convert the numbers to the member
> names.
> 
> Creating the value of the given enum member is quite different in GDB
> and LLDB, so separate method `create_enum_value` was introduced in
> Debugger API. Also new method `cast_typeof` was introduced to perform
> value-based cast, i.e. it casts to the same type as a reference value.
> 
> Also this patch fixes the mapping of FPMATHOP to a human-readable form,
> because prior to this patch, IRFPMS contained the incorrect entry
> 'exp2'. IRFPMS is a human-readable form of enum IRFPMathOp, but there is
> no 'exp2' enum member actually (see IRFPMDEF). It looks like it was
> added by mistake initially (corresponding tests to check mapping of
> FPMATHOP were added).
> 
> Resolves tarantool/tarantool#13094
> Resolves tarantool/tarantool#13159
> ---
>  src/luajit_dbg.py                             | 675 +++++-------------
>  .../debug-extension-tests.py                  |  62 +-
>  2 files changed, 249 insertions(+), 488 deletions(-)
> 
> diff --git a/src/luajit_dbg.py b/src/luajit_dbg.py
> index 77abf8c6..ceba4c58 100644
> --- a/src/luajit_dbg.py
> +++ b/src/luajit_dbg.py
> @@ -106,6 +106,8 @@ class Debugger(object):
>      def initialize_extension(self, commands):
>          if self.configure():
>              for name, command in commands.items():
> +                if hasattr(command, 'pre_register'):
> +                    command.pre_register()

Please add the comment that this is needed for generated documentation
for function's help.

>                  self.register_command(command, name)
>                  self.write('{} command initialized\n'.format(name))
>              self.write('LuaJIT debug extension is successfully loaded\n')
> @@ -119,6 +121,13 @@ class Debugger(object):

<snipped>

> @@ -829,6 +916,55 @@ def strx64(val):
>      return re.sub('L?$', '', hex(int(tou64(val))))
>  
>  
> +class EnumBasedList(object):
> +    def __init__(self, max_enum_member, enum_name, map_func=None,
> +                 *map_func_args):
> +        self.__max_enum_member = max_enum_member
> +        self.__enum_name = enum_name
> +        self.__map_func = map_func
> +        self.__map_func_args = map_func_args
> +        # Lazy initialization (see __get_items) as the required
> +        # information might be unavailable at this moment.
> +        self.__items = None

Nit: Please sort these items alphabetically.
Nit: Please sort functions below alphabetically.

> +
> +    def __iter__(self):
> +        return iter(self.__get_items())
> +
> +    def __getitem__(self, key):
> +        return self.__get_items()[key]
> +
> +    def __len__(self):
> +        return len(self.__get_items())
> +
> +    def __get_items(self):
> +        if self.__items is None:
> +            try:
> +                max_enum_value = dbg.create_enum_value(
> +                    self.__max_enum_member, self.__enum_name
> +                )
> +            except Exception as e:
> +                msg = 'failed to resolve {} enum members using {}'.format(
> +                    self.__enum_name or 'anonymous',
> +                    self.__max_enum_member,
> +                )
> +                raise dbg.error('{}: {}'.format(msg, e))
> +            items = []
> +            for i in range(max_enum_value):
> +                item = str(dbg.cast_typeof(max_enum_value, i))
> +                if self.__map_func:
> +                    item = self.__map_func(item, *self.__map_func_args)
> +                items.append(item)
> +            self.__items = items
> +        return self.__items
> +
> +    def index(self, item):
> +        return self.__get_items().index(item)

Why do not use __index__ method for this?
Since `IRTYPES['num']` is more readable than `IRTYPES.index('num')`, IMO.
Since we assume that idx == value for these lists.

Also, it is worth mentinoning that these generated lists skips some enums
that are defined equal to others like there is no: IRT_PGC, IRT_PTR, and
also skips all enums that are greater than border __MAX value (IRT_MARK,
etc) (I suppose there is no need in this functionality right now, just
worth mentioning).


<snipped>

> -- 
> 2.55.0
> 

-- 
Best regards,
Sergey Kaplun

  reply	other threads:[~2026-11-20 14:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 23:42 [Tarantool-patches] [PATCH luajit 0/4] " Mikhail Elhimov via Tarantool-patches
2026-11-12 23:42 ` [Tarantool-patches] [PATCH luajit 1/4] dbg: clean up and unification Mikhail Elhimov via Tarantool-patches
2026-11-20 13:50   ` Sergey Kaplun via Tarantool-patches
2026-11-12 23:42 ` [Tarantool-patches] [PATCH luajit 2/4] dbg: avoid hardcoded enums Mikhail Elhimov via Tarantool-patches
2026-11-20 14:13   ` Sergey Kaplun via Tarantool-patches [this message]
2026-11-12 23:42 ` [Tarantool-patches] [PATCH luajit 3/4] dbg: display fast function name along with ffid Mikhail Elhimov via Tarantool-patches
2026-11-12 23:42 ` [Tarantool-patches] [PATCH luajit 4/4] dbg: remove wrong GC state Mikhail Elhimov 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=awBVd0AkquL4I3fT@root \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=m.elhimov@vk.team \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit 2/4] dbg: avoid hardcoded enums' \
    /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