Tarantool development patches archive
 help / color / mirror / Atom feed
From: Igor Munkin <imun@tarantool.org>
To: Alexander Turenko <alexander.turenko@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v2 luajit 0/3] Introduce gdb extension for LuaJIT
Date: Fri, 28 Feb 2020 13:46:13 +0300	[thread overview]
Message-ID: <20200228104613.GQ404@tarantool.org> (raw)
In-Reply-To: <20200226224148.pq3mqfd4amh63rqd@tkn_work_nb>

Sasha,

Thanks for the report, I've digged a problem a bit and found a solution
for the subj based on the events[1].

On 27.02.20, Alexander Turenko wrote:
> Bugreport:
> 
> When I source the extension from .gdbinit and run gdb to inspect a core
> file like so:
> 
> gdb tarantool \
>     -ex "set solib-search-path $(realpath lib64):$(realpath lib64/lua/5.1):$(realpath lib64/tarantool):$(realpath lib64/tarantool/http):$(realpath lib64/tarantool/cron)" \
>     -ex "add-auto-load-safe-path $(realpath .)" \
>     -ex "set sysroot $(realpath .)" \
>     -ex 'set substitute-path /build/usr/src/debug/tarantool-2.2.1.137 src/tarantool' \
>     -ex 'core core'
> 
> I got 'luajit-gdb.py failed to load: no debugging symbols found for
> libluajit' warning and the extesion is not loaded.

Now you will see the following:
| <snipped>
| luajit-gdb.py loading postponed until libluajit objfile is loaded
| Reading symbols from ./usr/bin/tarantool...
| lj-arch command initialized
| lj-tv command initialized
| lj-str command initialized
| lj-tab command initialized
| lj-stack command initialized
| lj-state command initialized
| lj-gc command initialized
| luajit-gdb.py is successfully loaded
| <snipped>

> 
> However if I source it afterwards it loded successfully.
> 
> I guess it is because `gdb.parse_and_eval('IRT_PTR')` and
> `gdb.parse_and_eval('IRT_PGC')` needs values from runtime, which is
> available only after `-ex 'core core'` command.
> 
> Possible solution: always register lj-* functions, but load those values
> inside them (if it is not already done). A kind of lazy loading.
> 
> WBR, Alexander Turenko.

Fixed, squashed, force-pushed to the branch. Diff is below:

================================================================================

diff --git a/src/luajit-gdb.py b/src/luajit-gdb.py
index 0ac0aaa..f23e119 100644
--- a/src/luajit-gdb.py
+++ b/src/luajit-gdb.py
@@ -659,9 +659,20 @@ The command requires no args and dumps current GC stats:
             stats = dump_gc(g)
         ))
 
-def load(commands):
+def init(commands):
     global LJ_64, LJ_GC64, LJ_FR2
 
+    if not gdb.lookup_global_symbol('luaJIT_setmode'):
+        gdb.write('luajit-gdb.py initialization is postponed '
+                  'until libluajit objfile is loaded\n')
+        gdb.events.new_objfile.connect(load)
+        return
+
+    try:
+        gdb.events.new_objfile.disconnect(load)
+    except:
+        pass # was not connected
+
     try:
         LJ_64 = str(gdb.parse_and_eval('IRT_PTR')) == 'IRT_P64'
         LJ_FR2 = LJ_GC64 = str(gdb.parse_and_eval('IRT_PGC')) == 'IRT_P64'
@@ -675,12 +686,15 @@ def load(commands):
 
     gdb.write('luajit-gdb.py is successfully loaded\n')
 
-load({
-    'lj-arch': LJDumpArch,
-    'lj-tv': LJDumpTValue,
-    'lj-str': LJDumpString,
-    'lj-tab': LJDumpTable,
-    'lj-stack': LJDumpStack,
-    'lj-state': LJState,
-    'lj-gc': LJGC,
-})
+def load(event=None):
+    init({
+        'lj-arch': LJDumpArch,
+        'lj-tv': LJDumpTValue,
+        'lj-str': LJDumpString,
+        'lj-tab': LJDumpTable,
+        'lj-stack': LJDumpStack,
+        'lj-state': LJState,
+        'lj-gc': LJGC,
+    })
+
+load(None)

================================================================================

[1]: https://sourceware.org/gdb/onlinedocs/gdb/Events-In-Python.html#Events-In-Python

-- 
Best regards,
IM

  reply	other threads:[~2020-02-28 10:51 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-05 16:22 Igor Munkin
2020-02-05 16:22 ` [Tarantool-patches] [PATCH v2 luajit 1/3] gdb: introduce luajit-gdb extension Igor Munkin
2020-02-13 13:24   ` Igor Munkin
2020-02-05 16:22 ` [Tarantool-patches] [PATCH v2 luajit 2/3] gdb: adjust the extension to be used with Python 2 Igor Munkin
2020-02-05 16:22 ` [Tarantool-patches] [PATCH v2 luajit 3/3] gdb: enhance the extension loading Igor Munkin
2020-02-13 11:48   ` Igor Munkin
2020-02-13 12:24     ` Igor Munkin
2020-02-26 22:41 ` [Tarantool-patches] [PATCH v2 luajit 0/3] Introduce gdb extension for LuaJIT Alexander Turenko
2020-02-28 10:46   ` Igor Munkin [this message]
2020-03-02 16:00     ` Igor Munkin
2020-03-03 14:16       ` Sergey Ostanevich
2020-02-26 22:45 ` Alexander Turenko
2020-02-27 10:48   ` Igor Munkin
2020-02-27 11:35     ` Alexander Turenko
2020-03-03 16:17       ` Igor Munkin
2020-03-03 22:39         ` Alexander Turenko
2020-03-17 22:46           ` Igor Munkin
2020-02-26 23:04 ` Alexander Turenko
2020-02-27 10:13   ` Igor Munkin
2020-02-26 23:10 ` Alexander Turenko
2020-02-27 10:37   ` Igor Munkin
2020-03-05  7:44 ` Kirill Yukhin
2020-03-05  9:22   ` Igor Munkin

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=20200228104613.GQ404@tarantool.org \
    --to=imun@tarantool.org \
    --cc=alexander.turenko@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2 luajit 0/3] Introduce gdb extension for LuaJIT' \
    /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