Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Bronnikov via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Sergey Kaplun <skaplun@tarantool.org>,
	Evgeniy Temirgaleev <e.temirgaleev@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit 1/4] dbg: fix lj-stack command for LLDB
Date: Fri, 5 Jun 2026 17:55:39 +0300	[thread overview]
Message-ID: <e5b7693f-eb95-4597-8975-81ab40accb87@tarantool.org> (raw)
In-Reply-To: <20260604093052.2221827-2-skaplun@tarantool.org>

[-- Attachment #1: Type: text/plain, Size: 5622 bytes --]

Hi, Sergey,

thanks for the patch! LGTM

On 6/4/26 12:30, Sergey Kaplun wrote:
> This commit is the follow-up for the commit
> 593fef813b7d36060e0c1b1ae2df0fbc0d604d1f ("lldb: refactor extension").
> `GetValueForExpressionPath()` may produce the empty value for negative
> indexes. This leads to incorrect frame unwinding in the LLDB extension
> and errors like:
> | Failed to execute command `lj-stack`:
> | 'Q' format requires 0 <= number <= 18446744073709551615
>
> This patch adds special handling for the negative indices.
> ---
>   src/luajit_dbg.py                             | 49 ++++++++++++++++---
>   .../debug-extension-tests.py                  | 26 +++++++---
>   2 files changed, 62 insertions(+), 13 deletions(-)
>
> diff --git a/src/luajit_dbg.py b/src/luajit_dbg.py
> index d9196f06..410f0191 100644
> --- a/src/luajit_dbg.py
> +++ b/src/luajit_dbg.py
> @@ -255,15 +255,31 @@ class _GDBDebugger(Debugger):
>   
>   class _LLDBDebugger(Debugger):
>       def _lldb_tp_isfp(self, tp):
> -        return tp.GetBasicType() in [
> +        return tp.GetCanonicalType().GetBasicType() in [
>               lldb.eBasicTypeFloat,
>               lldb.eBasicTypeDouble,
>               lldb.eBasicTypeLongDouble
>           ]
>   
> +    def _lldb_tp_issigned(self, tp):
> +        return tp.GetCanonicalType().GetBasicType() in [
> +            lldb.eBasicTypeChar,
> +            lldb.eBasicTypeSignedChar,
> +            lldb.eBasicTypeShort,
> +            lldb.eBasicTypeInt,
> +            lldb.eBasicTypeLong,
> +            lldb.eBasicTypeLongLong,
> +            lldb.eBasicTypeInt128
> +        ]
> +
>       def _lldb_value_from_raw(self, raw_value, size, tp):
>           isfp = self._lldb_tp_isfp(tp)
> -        pack_flag = '<d' if isfp else '<Q'
> +        if isfp:
> +            pack_flag = '<d'
> +        elif self._lldb_tp_issigned(tp):
> +            pack_flag = '<q'
> +        else:
> +            pack_flag = '<Q'
>           raw_data = struct.pack(pack_flag, raw_value)
>           sbdata = lldb.SBData()
>           sbdata.SetData(
> @@ -308,9 +324,24 @@ class _LLDBDebugger(Debugger):
>                   key = int(key)
>               if type(key) is int:
>                   # Allow array access.
> -                return lldb.value(
> -                    lldbval.sbvalue.GetValueForExpressionPath('[%i]' % key)
> -                )
> +                if key >= 0:
> +                    return lldb.value(
> +                        lldbval.sbvalue.GetValueForExpressionPath('[%i]' % key)
> +                    )
> +                else:
> +                    # GetValueForExpressionPath doesn't work for
> +                    # negative offsets.
> +                    sbvalue = lldbval.sbvalue
> +                    assert sbvalue.TypeIsPointerType(), \
> +                        'attempt to get index of non-pointer type'
> +                    tp = sbvalue.GetType().GetPointeeType()
> +                    sz = sbvalue.deref.size
> +                    addr = sbvalue.GetValueAsUnsigned() + key * sz
> +                    return lldb.value(self.target.CreateValueFromAddress(
> +                            '({tp}){addr}'.format(tp=tp, addr=addr),
> +                            lldb.SBAddress(addr, self.target),
> +                            tp,
> +                    ))
>               elif type(key) is str:
>                   return lldb.value(lldbval.sbvalue.GetChildMemberWithName(key))
>               raise Exception(TypeError('No item of type %s' % str(type(key))))
> @@ -417,8 +448,12 @@ class _LLDBDebugger(Debugger):
>           # may take the 8 bytes of memory instead of 4, before the
>           # cast. Construct the value on the fly.
>           tp = self._dbgtype(typestr)
> -        is_fp = self._lldb_tp_isfp(tp)
> -        rawval = float(val.GetValue()) if is_fp else val.GetValueAsUnsigned()
> +        if self._lldb_tp_isfp(tp):
> +            rawval = float(val.GetValue())
> +        elif self._lldb_tp_issigned(tp):
> +            rawval = val.GetValueAsSigned()
> +        else:
> +            rawval = val.GetValueAsUnsigned()
>           return self._lldb_value_from_raw(rawval, val.GetByteSize(), tp)
>   
>       def sizeof(self, typestr):
> diff --git a/test/tarantool-debugger-tests/debug-extension-tests.py b/test/tarantool-debugger-tests/debug-extension-tests.py
> index 61529561..7cb60d84 100644
> --- a/test/tarantool-debugger-tests/debug-extension-tests.py
> +++ b/test/tarantool-debugger-tests/debug-extension-tests.py
> @@ -186,16 +186,30 @@ class TestLJGC(TestCaseBase):
>       )
>   
>   
> -class TestLJStack(TestCaseBase):
> +STACK_RX = (
> +    r'-+ Redzone:\s+\d+ slots -+\n'
> +    r'(' + RX_ADDR + r'\s+' + RX_FRAME + r' VALUE: nil\n?)*\n'
> +    r'-+Stack:\s+\d+ slots -+\n'
> +    r'(' + RX_ADDR + r'(:' + RX_ADDR + r')?\s+' + RX_FRAME + r'.*\n?)+\n'
> +)
> +
> +
> +class TestLJStackBase(TestCaseBase):
>       extension_cmds = 'lj-stack'
>       location = 'lj_cf_print'
>       lua_script = 'print(1)'
> -    pattern = (
> -        r'-+ Redzone:\s+\d+ slots -+\n'
> -        r'(' + RX_ADDR + r'\s+' + RX_FRAME + r' VALUE: nil\n?)*\n'
> -        r'-+Stack:\s+\d+ slots -+\n'
> -        r'(' + RX_ADDR + r'(:' + RX_ADDR + r')?\s+' + RX_FRAME + r'.*\n?)+\n'
> +    pattern = STACK_RX
> +
> +
> +# Check LLDB correctness for the specific stack.
> +class TestLJStackFunc(TestCaseBase):
> +    extension_cmds = 'lj-stack'
> +    location = 'lj_cf_print'
> +    lua_script = (
> +        'local function nop() end\n'
> +        'print()\n'
>       )
> +    pattern = STACK_RX
>   
>   
>   class TestLJTV(TestCaseBase):

[-- Attachment #2: Type: text/html, Size: 6023 bytes --]

  reply	other threads:[~2026-06-05 14:55 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-04  9:30 [Tarantool-patches] [PATCH luajit 0/4] Introduce dumpers for bytecodes in debuggers Sergey Kaplun via Tarantool-patches
2026-06-04  9:30 ` [Tarantool-patches] [PATCH luajit 1/4] dbg: fix lj-stack command for LLDB Sergey Kaplun via Tarantool-patches
2026-06-05 14:55   ` Sergey Bronnikov via Tarantool-patches [this message]
2026-06-04  9:30 ` [Tarantool-patches] [PATCH luajit 2/4] dbg: fix DUALNUM detection " Sergey Kaplun via Tarantool-patches
2026-06-05 14:57   ` Sergey Bronnikov via Tarantool-patches
2026-06-05 16:01     ` Sergey Kaplun via Tarantool-patches
2026-06-04  9:30 ` [Tarantool-patches] [PATCH luajit 3/4] dbg: introduce lj-gco command Sergey Kaplun via Tarantool-patches
2026-06-05 15:02   ` Sergey Bronnikov via Tarantool-patches
2026-06-04  9:30 ` [Tarantool-patches] [PATCH luajit 4/4] dbg: introduce lj-bc, lj-func and lj-proto dumpers Sergey Kaplun via Tarantool-patches
2026-06-05 15:07   ` Sergey Bronnikov via Tarantool-patches
2026-06-05 16:10     ` Sergey Kaplun via Tarantool-patches
2026-06-05 14:55 ` [Tarantool-patches] [PATCH luajit 0/4] Introduce dumpers for bytecodes in debuggers Sergey Bronnikov via Tarantool-patches
2026-06-05 16:03 ` [Tarantool-patches] [PATCH luajit 3/5] dbg: update help for the lj-arch command Sergey Kaplun 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=e5b7693f-eb95-4597-8975-81ab40accb87@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=e.temirgaleev@tarantool.org \
    --cc=sergeyb@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit 1/4] dbg: fix lj-stack command for LLDB' \
    /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