From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 0BFABD31FD3; Wed, 17 Apr 2024 19:04:07 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 0BFABD31FD3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1713369847; bh=aRtVQNNEE8q58m6huq669ngWKTtzol4pV7HHzeyV+hc=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=GjMdbwj+frdqv8RU9XI6f/dK0aN83iZNnr6DBdqfFF17/2gmKPhRDhCIDSSb3tR/D vnjvhh1jgGonzZtUIppA5RDTXYlmjabylSTLHD0bDDZL4qcqH0F9zUDQehAeVxE+m+ ruTo/AqUDheCTQ7hxwAF6dQC3lZ66lxH54V+n/2A= Received: from smtp42.i.mail.ru (smtp42.i.mail.ru [95.163.41.65]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id DA815D31FC6 for ; Wed, 17 Apr 2024 19:04:04 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DA815D31FC6 Received: by smtp42.i.mail.ru with esmtpa (envelope-from ) id 1rx7lU-00000004wpG-0Kub; Wed, 17 Apr 2024 19:04:04 +0300 Date: Wed, 17 Apr 2024 19:00:00 +0300 To: Maxim Kokryashkin Message-ID: References: <13501abba00ac3e072284d36a531c721e279722f.1712182830.git.m.kokryashkin@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <13501abba00ac3e072284d36a531c721e279722f.1712182830.git.m.kokryashkin@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD9F97E3C14763C38E23ADB05FB32D12D62E142C792615B32A1182A05F538085040CDDDD589EAC6F8C4D4FF92D56319F19784FD7E8909351CF166B37BDEEB48F18E906DE0852CB23FE4 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7FCFCB92DA8654BB0EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637CAA352D56883AEE98638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D801B259F4DCD4C29B3308C8BE00FC44E60E5E72795E3BBCEDCC7F00164DA146DAFE8445B8C89999728AA50765F7900637E603D20A273AEC4F389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC817119E5299B287EEF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE33AC447995A7AD187441229DB5CFFAA63A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E735BA6625F88748EAEFC4224003CC83647689D4C264860C145E X-C1DE0DAB: 0D63561A33F958A58F7D34534D2B60A05002B1117B3ED6960333A92D75673779361FAC1196A180DE823CB91A9FED034534781492E4B8EEAD3CCD70CEBBF18A22BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFE76269FDB5D2E8E17D4412384B991AEBB28DC2D656ED1A91079F26F6FD1282434D6692FC0148BA754AA6A4DA8F63241636F268FA5A70EE7CD8DC7104FAD5FEDBADBA62E33D63DF38C226CC413062362A913E6812662D5F2A5EAB5682573093F7837F15F2B5E4A70B33F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojKLjB1Eikxbrf6mnmMu2twQ== X-DA7885C5: 873BA1BBEEE4892EF255D290C0D534F9F4F1255939C65321C8792751F0E551D04269E3E7F633478F5B1A4C17EAA7BC4BEF2421ABFA55128DAF83EF9164C44C7E X-Mailru-Sender: 689FA8AB762F7393590D8C940224AE335A449F628E219BD8BFA4A02C6F61090DF844F0F027FB1AC3E49D44BB4BD9522A059A1ED8796F048DB274557F927329BE89D5A3BC2B10C37545BD1C3CC395C826B4A721A3011E896F X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit v6 1/2] debug: generalized extension X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Maxim! Thanks for the patch! Please consider my comments below. On 04.04.24, Maxim Kokryashkin wrote: > --- > src/luajit-gdb.py | 885 -------------------------- > src/{luajit_lldb.py => luajit_dbg.py} | 616 ++++++++++++------ Since luajit_lldb.py is gone, please change the comment in <.flake8rc>. > 2 files changed, 416 insertions(+), 1085 deletions(-) > delete mode 100644 src/luajit-gdb.py > rename src/{luajit_lldb.py => luajit_dbg.py} (63%) > > diff --git a/src/luajit-gdb.py b/src/luajit-gdb.py > deleted file mode 100644 > diff --git a/src/luajit_lldb.py b/src/luajit_dbg.py > similarity index 63% > rename from src/luajit_lldb.py > rename to src/luajit_dbg.py > index 5ac11b65..a42d8f25 100644 > --- a/src/luajit_lldb.py > +++ b/src/luajit_dbg.py > @@ -1,10 +1,230 @@ > -# LLDB extension for LuaJIT post-mortem analysis. > -# To use, just put 'command script import /src/luajit_lldb.py' > -# in lldb. > +# Debug extension for LuaJIT post-mortem analysis. > +# To use in LLDB: 'command script import /src/luajit_dbg.py' > +# To use in GDB: 'source /src/luajit_dbg.py' > > import abc > import re > -import lldb > +import sys > +import types > + > +from importlib import import_module > + > +# make script compatible with the ancient Python {{{ Typo: s/make script/Make the script/ > +class Debugger(object): > + def __init__(self): > + self.GDB = False > + self.LLDB = False > + > + debuggers = { > + 'gdb': lambda lib: True, > + 'lldb': lambda lib: lib.debugger is not None, > + } > + for name, healthcheck in debuggers.items(): > + lib = None > + try: > + lib = import_module(name) > + if healthcheck(lib): Why do we need this healthcheck? Why just import of the module isn't enough? Please add a comment near `debuggers` definition. > + setattr(self, name.upper(), True) > + globals()[name] = lib > + self.name = name > + except Exception: > + continue > + > + assert self.LLDB != self.GDB > + > + def find_type(self, typename): > + if self.LLDB: > + return target.FindFirstType(typename) > + else: > + return gdb.lookup_type(typename) Why do you drop the cache for types here? It may be critical when running scripts for the search of objects on big coredumps or the attached process. > + > + def type_to_pointer_type(self, tp): > + if self.LLDB: > + return tp.GetPointerType() > + else: > + return tp.pointer() > + > + def type_member_offset(self, member): > + if self.LLDB: > + return member.GetOffsetInBytes() > + else: > + return member.bitpos / 8 Should it be `//`? > +class Struct(object): Should we do this part for GDB too? I thought that this class generation may be skipped for GDB. > def __init__(self, value): > self.value = value > > def __getitem__(self, name): > +def make_property_from_metadata(field, tp): > + builtin = { > + 'uint': dbg.to_unsigned, > + 'int': dbg.to_signed, > + 'string': dbg.to_str, > + } > + if tp in builtin.keys(): > + return lambda self: builtin[tp](self[field]) > + else: > + return lambda self: globals()[tp](self[field]) > + > + > +for cls, metainfo in c_structs.items(): > + cls_dict = {} > + for field in metainfo: May you please name field[0], field[1] as local variables for better readability? > + if not isinstance(field[0], str): > + cls_dict[field[1]] = field[0] > + else: > + cls_dict[field[1]] = property( > + make_property_from_metadata(field[1], field[0]) > + ) > + globals()[cls] = type(cls, (Struct, ), cls_dict) > > > for cls in Struct.__subclasses__(): > ptr_name = cls.__name__ + 'Ptr' > > - > - ret = frame.EvaluateExpression(command) > - return ret > + return dbg.to_unsigned(dbg.eval(command)) Why do we need return unsigned here? > > @abc.abstractproperty > def command(self): > @@ -270,7 +491,7 @@ class Command(object): > @@ -278,6 +499,11 @@ class Command(object): > properly routed to LLDB frontend. Any unhandled exception will be > automatically transformed into proper errors. > """ > + def invoke(self, arg, from_tty): > + try: > + self.execute(arg) > + except Exception as e: > + dbg.write(e) Why do we need this change? The error message for such situation is changed and non informative: | Breakpoint 1, lj_cf_dofile (L=0x2) at /home/burii/reviews/luajit/lj-dbg/src/lib_base.c:429 | 429 { | (gdb) lj-stack L | Python Exception : unsupported operand type(s) for +: 'MemoryError' and 'str' | Error occurred in Python: unsupported operand type(s) for +: 'MemoryError' and 'str' Within the following implementation all works as expected. | def invoke(self, arg, from_tty): | self.execute(arg) This produces more understandable reason of an error: | (gdb) lj-stack L | Python Exception : Cannot access memory at address 0x26 | Error occurred in Python: Cannot access memory at address 0x26 Also, maybe it is good to add a test for this error. -- Best regards, Sergey Kaplun