[Tarantool-patches] [PATCH v2 luajit 0/3] Introduce gdb extension for LuaJIT
Igor Munkin
imun at tarantool.org
Fri Feb 28 13:46:13 MSK 2020
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
More information about the Tarantool-patches
mailing list