From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (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 A388B4696C3 for ; Wed, 5 Feb 2020 19:24:47 +0300 (MSK) From: Igor Munkin Date: Wed, 5 Feb 2020 19:22:28 +0300 Message-Id: <29107e6f02c622f414fdaa08bb82a89ca0e30396.1580917791.git.imun@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v2 luajit 2/3] gdb: adjust the extension to be used with Python 2 List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org This patch covers all problems faced while using the extension via gdb compiled with Python 2. Signed-off-by: Igor Munkin --- src/luajit-gdb.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/luajit-gdb.py b/src/luajit-gdb.py index 77da5e6..90df101 100644 --- a/src/luajit-gdb.py +++ b/src/luajit-gdb.py @@ -1,5 +1,14 @@ import re import gdb +import sys + +# make script compatible with the ancient Python {{{ + +if re.match(r'^2\.', sys.version): + int = long + range = xrange + +# }}} gtype_cache = {} @@ -47,7 +56,8 @@ def i2notu32(val): return ~int(val) & 0xFFFFFFFF def strx64(val): - return hex(cast('uint64_t', val) & 0xFFFFFFFFFFFFFFFF) + return re.sub('L?$', '', + hex(int(cast('uint64_t', val) & 0xFFFFFFFFFFFFFFFF))) # Types {{{ @@ -169,7 +179,9 @@ def gcval(obj): def L(L=None): # lookup a symbol for the main coroutine considering the host app - for l in (L, *map(lambda l: lookup(l), ( + # XXX Fragile: though the loop initialization looks like a crap but it + # respects both Python 2 and Python 3. + for l in [ L ] + list(map(lambda l: lookup(l), ( # LuaJIT main coro (see luajit/src/luajit.c) 'globalL', # Tarantool main coro (see tarantool/src/lua/init.h) @@ -234,7 +246,10 @@ def tvislightud(o): def strdata(obj): # String is printed with pointer to it, thanks to gdb. Just strip it. - return str(cast('char *', cast('GCstr *', obj) + 1))[len(PADDING):] + try: + return str(cast('char *', cast('GCstr *', obj) + 1))[len(PADDING):] + except UnicodeEncodeError: + return "" def itypemap(o): if LJ_64 and not LJ_GC64: -- 2.24.0