Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Evgeniy Temirgaleev <e.temirgaleev@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit 0/4] Introduce dumpers for bytecodes in debuggers
Date: Thu, 18 Jun 2026 21:48:25 +0300	[thread overview]
Message-ID: <ajQ9ecUtKjHkD-NH@root> (raw)
In-Reply-To: <1781793399.19260190@f722.i.mail.ru>

Hi, Evgeniy!
Thanks for the review!
Fixed your comments and force-pushed the branch.

On 18.06.26, Evgeniy Temirgaleev wrote:
> Hi, Sergey! Thanks for the patch!
> 
> I tried the tests under Ubuntu 20.04 and Ubuntu 24.04 with gcc and clang LuaJIT builds:
> 
> 1) Ubuntu 20 + gcc: all tests were passed.
> 2) Ubuntu 20 + clang: some of gdb and lldb tests were failed.
> 3) Ubuntu 24 + gcc: some of lldb tests were failed.
> 4) Ubuntu 24 + clang: some of gdb and lldb tests were failed.

Thanks a lot for these catches!

Ubuntu 24 has LLDB (18) with regression. It can't use the array object
as the initializer for `lldb.value`. This regression affects versions 17
- 19. See [1] for the details.

I've added the corresponding workaround for it:
===================================================================
diff --git a/src/luajit_dbg.py b/src/luajit_dbg.py
index 3a3ca9b8..2edb199a 100644
--- a/src/luajit_dbg.py
+++ b/src/luajit_dbg.py
@@ -324,7 +324,7 @@ class _LLDBDebugger(Debugger):
                 key = int(key)
             if type(key) is int:
                 # Allow array access.
-                if key >= 0:
+                if key >= 0 and not lldbval.sbvalue.TypeIsPointerType():
                     return lldb.value(
                         lldbval.sbvalue.GetValueForExpressionPath('[%i]' % key)
                     )
@@ -475,7 +475,22 @@ class _LLDBDebugger(Debugger):
         return strptr.sbvalue.summary
 
     def lookup_global(self, symbol):
-        return lldb.value(self.target.FindFirstGlobalVariable(symbol))
+        sbvalue = self.target.FindFirstGlobalVariable(symbol)
+        tp = sbvalue.GetType()
+        # XXX: LLDB in versions 17 - 19 can't use an array object
+        # as the initializer for `lldb.value` since `GetValue()`
+        # for it returns `None` leading to the invalid result.
+        # See https://github.com/llvm/llvm-project/pull/90144.
+        if (self.version < 17 or self.version > 19) or \
+           tp.GetTypeClass() != lldb.eTypeClassArray:
+            return lldb.value(sbvalue)
+        else:
+            ptr_tp = tp.GetArrayElementType().GetPointerType()
+            return self._lldb_value_from_raw(
+                sbvalue.GetLoadAddress(),
+                ptr_tp.GetByteSize(),
+                ptr_tp
+            )
 
     def eval(self, command):
         if not command:
===================================================================

Regarding clang issues, I suppose this is due to not enough dwarf
information about the macro definitions. That leads to test failures
(even if the extension works correctly).

I've added the following fix with detecting is the required macro
definitions supported. Patch is splitted via the corresponding commits.
===================================================================
diff --git a/test/tarantool-debugger-tests/debug-extension-tests.py b/test/tarantool-debugger-tests/debug-extension-tests.py
index b677942c..7e8ea5a2 100644
--- a/test/tarantool-debugger-tests/debug-extension-tests.py
+++ b/test/tarantool-debugger-tests/debug-extension-tests.py
@@ -97,6 +97,10 @@ IS_DUALNUM = execute_process([
     LUAJIT_BINARY, '-e', "print(require('ffi').abi('dualnum'))"
 ]).strip() == 'true'
 
+IS_GC64 = execute_process([
+    LUAJIT_BINARY, '-e', "print(require('ffi').abi('gc64'))"
+]).strip() == 'true'
+
 # If it is the guaranteed DUALNUM build (for example, on aarch64),
 # we use this regexp for the guaranteed 'integer' check and
 # 'number' for single-number build.
@@ -139,23 +143,54 @@ class TestCaseBase(unittest.TestCase):
             self.assertRegex(self.output, self.pattern.strip())
 
 
-# LLDB + Clang on macOS can't produce debug info for the C-defined
-# macros. Thus, we hardcoded its value manually.
+# Test that the emitted debug information supports macro
+# definitions.
+def check_macro_debug_info():
+    cmd_file = persist('\n'.join([
+        'b lj_cf_print',
+        *PROCESS_RUN,
+        'n',
+        'p gcval(L->base)',
+        'q',
+    ]))
+    process_cmd = [
+        DEBUGGER,
+        *RUN_CMD_FILE,
+        cmd_file.name,
+        INFERIOR_ARGS,
+        LUAJIT_BINARY,
+        '-e',
+        'print("")'
+    ]
+    output = execute_process(process_cmd)
+    cmd_file.close()
+    return re.search(r'\(GCobj \*\) ' + RX_ADDR, output) is not None
+
+
+SUPPORT_MACRO_EXPAND = check_macro_debug_info()
+
+
+# LLDB + Clang on macOS (for example) can't produce debug info
+# for the C-defined macros. Thus, we hardcoded its value manually.
 def gcval(arg):
-    if sys.platform == 'darwin':
-        # Assume GC64 build only.
-        LJ_GCVMASK = '(((uint64_t)1 << 47) - 1)'
-        return '(((' + arg + ')->gcr).gcptr64 & ' + LJ_GCVMASK + ')'
-    else:
+    if SUPPORT_MACRO_EXPAND:
         return 'gcval(' + arg + ')'
+    else:
+        if IS_GC64:
+            LJ_GCVMASK = '(((uint64_t)1 << 47) - 1)'
+            return '(((' + arg + ')->gcr).gcptr64 & ' + LJ_GCVMASK + ')'
+        else:
+            return '((' + arg + ')->gcr).gcptr32'
 
 
 def mref(arg, tp):
-    if sys.platform == 'darwin':
-        # Assume GC64 build only.
-        return '((' + tp + '*)(' + arg + ').ptr64)'
-    else:
+    if SUPPORT_MACRO_EXPAND:
         return 'mref(' + arg + ', ' + tp + ')'
+    else:
+        if IS_GC64:
+            return '((' + tp + '*)(' + arg + ').ptr64)'
+        else:
+            return '((' + tp + '*)(' + arg + ').ptr32)'
 
 
 class TestLoad(TestCaseBase):
===================================================================

I've checked in Ubuntu 24/26 Dockers, our CI (Ubuntu 20), and macOS M1.
Tests don't fail anymore.

> 
> --
> Best regards,
> Evgeniy Temirgaleev
> 

<snipped>

[1]: https://github.com/llvm/llvm-project/pull/90144

-- 
Best regards,
Sergey Kaplun

      reply	other threads:[~2026-06-18 18:49 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-04  9:30 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
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-09 13:57       ` Sergey Bronnikov 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
2026-06-09 13:58   ` Sergey Bronnikov via Tarantool-patches
2026-06-18 14:36 ` [Tarantool-patches] [PATCH luajit 0/4] Introduce dumpers for bytecodes in debuggers Evgeniy Temirgaleev via Tarantool-patches
2026-06-18 18:48   ` Sergey Kaplun 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=ajQ9ecUtKjHkD-NH@root \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=e.temirgaleev@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit 0/4] Introduce dumpers for bytecodes in debuggers' \
    /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