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 1/4] dbg: clean up and unification
Date: Fri, 20 Nov 2026 16:50:19 +0300	[thread overview]
Message-ID: <awBQG923VfbwTK09@root> (raw)
In-Reply-To: <0a9a648552eb3a3bbaa9639e0d567ae008cb0e14.1794522533.git.m.elhimov@vk.team>

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

On 13.11.26, Mikhail Elhimov wrote:
> * unified `dbg.eval` approach to simplify error handling (exception in
>   case of any failure)
> * removed trailing newline in all the dumpers to unify composing of the

Typo: s/trailing newline/trailing newlines/

>   complex output
> * newly introduced `dbg.print` is used whenever trailing newline is
>   needed to make code more compact and clean
> * moved handling of a missing command arg to command level (all the
>   dump-like functions now expect concrete value)
> * unified handling of command-level error (introduced special exception
>   for LLDB that works similar to `gdb.GdbError`, i.e. doesn't cause
>   traceback to be printed)
> * in `gdb.eval()` dropped check of the value returned by
>   `gdb.parse_and_eval()` as it would also fail for an expression like
>  `'0'` (looks like a kind of experimental code that was left by mistake)
> * `lldb.eval()` is adjusted to return object of the same type as
>   `lldb.cast()` method returns (this improves consistency)
> * renamed `dbg.eval` argument to reflect its meaning (it is
>   an expression rather than a command)
> ---
>  src/luajit_dbg.py                             | 178 +++++++++--------
>  .../debug-extension-tests.py                  | 182 +++++++++++++-----
>  2 files changed, 234 insertions(+), 126 deletions(-)
> 
> diff --git a/src/luajit_dbg.py b/src/luajit_dbg.py
> index 80057a4e..77abf8c6 100644
> --- a/src/luajit_dbg.py
> +++ b/src/luajit_dbg.py

<snipped>

> @@ -694,8 +703,13 @@ class _LLDBDebugger(Debugger):
>      def write(self, msg):
>          sys.stdout.write(msg)
>  
> +    class DbgError(Exception):
> +        '''Raised to indicate an error during command execution.
> +        Doesn't cause a traceback to be printed (like gdb.GdbError for GDB).'''

Side note: I'm a little bit concerned about that, but if it is needed
for the consistency with LLDB, I'm OK with that.

> +        pass
> +
>      def error(self, errmsg):
> -        return Exception(errmsg)
> +        return self.DbgError(errmsg)
>  
>      def check_libluajit(self):
>          # TODO: Implement postpone loading for LLDB too.
> @@ -738,12 +752,27 @@ class _LLDBDebugger(Debugger):
>          def __call__(ljbase, debugger, args, exe_ctx, result):
>              try:
>                  ljbase.execute(args)
> -            except Exception as e:
> +            except _LLDBDebugger.DbgError as e:
>                  msg = 'Failed to execute command `{}`: {}'.format(
>                      ljbase.name,
>                      e
>                  )
>                  result.SetError(msg)
> +                # `result` is an output argument of LLDB command
> +                # handler. If error message is set, LLDB displays

Typo: s/error/an error/

> +                # it in session. But such a message is missing in

Typo: s/session/the session/

> +                # output when the same problem occurs in batch

Typo: s/output/the output/

> +                # mode, so in order to be able to catch this kind
> +                # of error in batch mode it is needed to put it
> +                # into stderr explicitly.
> +                # Also to avoid duplication of the same error
> +                # message in interactive mode, it should be done
> +                # in batch mode only. There is no official way to
> +                # check if LLDB is in the batch mode so one of the
> +                # recommended workarounds is used below that
> +                # checks if tty is not used for standard input.
> +                if not sys.stdin.isatty():
> +                    result.PutError(lldb.SBFile.Create(sys.stderr, True))
>  
>          @abc.abstractmethod
>          def execute(ljbase, args):
> @@ -2399,7 +2428,7 @@ def dump_proto(proto):

<snipped>

> diff --git a/test/tarantool-debugger-tests/debug-extension-tests.py b/test/tarantool-debugger-tests/debug-extension-tests.py
> index ab44121c..fe8c5028 100644
> --- a/test/tarantool-debugger-tests/debug-extension-tests.py
> +++ b/test/tarantool-debugger-tests/debug-extension-tests.py
> @@ -19,30 +19,6 @@ LLDB = 'lldb' in DEBUGGER
>  EXTENSION = EXTENSION_PATH + '/luajit_dbg.py'
>  TIMEOUT = 10
>  
> -if LLDB:
> -    INFERIOR_ARGS = '--'
> -    LOAD_EXTENSION = 'command script import ' + EXTENSION
> -    PROCESS_RUN = (
> -        # Prevent errors in case when running tests in Docker.
> -        'settings set target.disable-aslr false\n'
> -        'process launch'
> -    )
> -    # Don't run any initialization scripts.
> -    RUN_CMD_FILE = [
> -        '--batch',
> -        '--no-lldbinit',
> -        '--no-use-colors',
> -        '--source-quietly',
> -        '--source'
> -    ]
> -else:
> -    # GDB.
> -    INFERIOR_ARGS = '--args'
> -    LOAD_EXTENSION = 'source ' + EXTENSION
> -    PROCESS_RUN = 'run'
> -    # Don't run any initialization scripts.
> -    RUN_CMD_FILE = ['--batch', '--nx', '--quiet', '--command']
> -
>  TEST_VERBOSE = os.getenv('DEBUGGER_TEST_VERBOSE', default=False)
>  
>  RX_ADDR = r'0x[a-f0-9]+'
> @@ -60,7 +36,7 @@ def persist(data):

<snipped>

> +if LLDB:
> +    INFERIOR_ARGS = '--'
> +    LOAD_EXTENSION = 'command script import ' + EXTENSION
> +    PROCESS_RUN = (
> +        # Prevent errors in case when running tests in Docker.
> +        'settings set target.disable-aslr false\n'
> +        'process launch'
> +    )
> +    # Don't run any initialization scripts.
> +    RUN_CMD_FILE = [
> +        '--batch',
> +        '--no-lldbinit',
> +        '--no-use-colors',
> +        '--source-quietly',
> +        '--source'
> +    ]
> +    SET_EXEC = 'target create ' + LUAJIT_BINARY
> +    SET_RUN_ARGS = 'settings set target.run-args'
> +
> +    def execute_process(cmd, timeout=TIMEOUT):
> +        # While executing extension commands LLDB might produce

Typo: s/commands/commands,/

> +        # errors that cannot be caught in extension. The internal

Typo: s/extension/the extension/

> +        # parser does some processing in background and might
> +        # emit an error message into stderr asynchronously. Also

Typo: s/Also/Also,/

> +        # the internal parser has a kind of fallback mechanism
> +        # that might resolve the problem, but is not able to
> +        # "cancel" the error message which might fail tests in

Typo: s/message which/message, which/

> +        # this case.
> +        #
> +        # List of regex that specifies lines to be wiped out from
> +        # the LLDB output. In case additional cleaning is needed,
> +        # just append this list with the correponding regex (use

Typo: s/correponding/corresponding/

> +        # as strict regex as possible in order to avoid accidental

Typo: s/strict regex as/strictest regex/

<snipped>

> @@ -129,42 +160,38 @@ else:
>  
>  class TestCaseBase(unittest.TestCase):
>      @classmethod
> -    def construct_cmds(cls):
> -        return '\n'.join([
> +    def construct_cmds(cls, deferred, *run_args):
> +        cmds = [
> +            SET_EXEC,
> +            SET_RUN_ARGS + ' ' + ' '.join(run_args),
>              'b {loc}'.format(loc=cls.location),
>              PROCESS_RUN,
>              'n',
> -            LOAD_EXTENSION,
>              cls.extension_cmds.strip(),
> -            'q',
> -        ])
> +        ]
> +        cmds.insert(0 if deferred else 1, LOAD_EXTENSION)

Minor: It may be nice to add the comment that we load the extension
either before or after LuaJIT symbols are loaded.

> +        return '\n'.join(cmds)
>  
> -    @classmethod
> -    def setUpClass(cls):
> -        cmd_file = persist(cls.construct_cmds())
> -        script_file = persist(cls.lua_script)
> +    def check(self, deferred=False):
> +        script_file = persist(self.lua_script)
> +        cmd_file = persist(self.construct_cmds(deferred, script_file.name))
>          process_cmd = [
>              DEBUGGER,
>              *RUN_CMD_FILE,
>              cmd_file.name,
> -            INFERIOR_ARGS,

Why is this part missing? AMIUC, that this flag si not needed anymore
after `SET_RUN_ARGS` is introduced? After removing, its variable is
unused. Shouldn't it be removed then?

> -            LUAJIT_BINARY,
> -            script_file.name,
>          ]

<snipped>

>  
>  
>  # Test that the emitted debug information supports macro
> @@ -1051,8 +1078,65 @@ class TestLJCTypeBase(TestCaseBase):
>      pattern = r'\[\d+\] <int>'
>  
>  
> -for test_cls in TestCaseBase.__subclasses__():
> +class TestMissingArgBase(TestCaseBase):
> +    location = 'lj_cf_print'
> +    lua_script = 'print(1)'
> +    pattern = r'Argument is required\n'
> +
> +    @classmethod
> +    def setUpClass(cls):
> +        cls.extension_cmds = '{}\n'.format(cls.cmd_name)
> +        super(TestMissingArgBase, cls).setUpClass()
> +
> +
> +class TestMissingArgLJFunc(TestMissingArgBase):
> +    cmd_name = 'lj-func'
> +
> +
> +class TestMissingArgLJTValue(TestMissingArgBase):
> +    cmd_name = 'lj-tv'
> +
> +
> +class TestMissingArgLJBC(TestMissingArgBase):
> +    cmd_name = 'lj-bc'
> +
> +
> +class TestMissingArgLJStr(TestMissingArgBase):
> +    cmd_name = 'lj-str'
> +
> +
> +class TestMissingArgLJTable(TestMissingArgBase):
> +    cmd_name = 'lj-tab'
> +
> +
> +class TestMissingArgLJProto(TestMissingArgBase):
> +    cmd_name = 'lj-proto'
> +
> +
> +class TestMissingArgLJGCO(TestMissingArgBase):
> +    cmd_name = 'lj-gco'
> +
> +
> +class TestMissingArgLJCType(TestMissingArgBase):
> +    cmd_name = 'lj-ctype'

Minor: It looks like this classes can be generated in cycle.
Feel free to ignore.

> +
> +
> +def get_leaf_subclasses(cls):
> +    subclasses = cls.__subclasses__()
> +    if not subclasses:
> +        yield cls
> +    else:
> +        for sub in subclasses:
> +            for leaf in get_leaf_subclasses(sub):
> +                yield leaf
> +
> +
> +for test_cls in get_leaf_subclasses(TestCaseBase):
>      test_cls.test = lambda self: self.check()

Please add the comment that we double-check each function functionality
in deferred loading mode to be sure that we initialize all internal
variables correctly (as we discussed offline).

> +    test_cls.test_with_deferred_loading = \
> +        unittest.skipIf(LLDB, "not supported for LLDB")(
> +            lambda self: self.check(True)
> +        )
>  
>  if __name__ == '__main__':
>      unittest.main(verbosity=2)
> -- 
> 2.55.0
> 

-- 
Best regards,
Sergey Kaplun

  reply	other threads:[~2026-11-20 13:48 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] dbg: avoid hardcoded enums 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 [this message]
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
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=awBQG923VfbwTK09@root \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=m.elhimov@vk.team \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit 1/4] dbg: clean up and unification' \
    /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