From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 2E18F469719 for ; Fri, 28 Feb 2020 13:51:36 +0300 (MSK) Date: Fri, 28 Feb 2020 13:46:13 +0300 From: Igor Munkin Message-ID: <20200228104613.GQ404@tarantool.org> References: <20200226224148.pq3mqfd4amh63rqd@tkn_work_nb> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200226224148.pq3mqfd4amh63rqd@tkn_work_nb> Subject: Re: [Tarantool-patches] [PATCH v2 luajit 0/3] Introduce gdb extension for LuaJIT List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexander Turenko Cc: tarantool-patches@dev.tarantool.org 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: | | 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 | > > 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