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 EF39B6ECE3; Thu, 14 Jul 2022 18:43:32 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EF39B6ECE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1657813413; bh=Ss4ylU7q8A57bmwhdwrTvBmVXl3VLkv8/XvW3QDSLrE=; 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=rHOJS+j4FCmz8MJZpWBcDLkMLZId10xSFG6SPpD3sGQVW9+s1yHkNeqSIWtix6lJV WEo1hRVFJ4kNmT3xdSppbKqveG7MB1pF2c9t3MyNhD84YUbnwi+L9cTY6jLxNX3BhT Xadjbcy9fld5IDvAhyFxvul2s3mE39GlOHBRXUs0= Received: from smtp33.i.mail.ru (smtp33.i.mail.ru [94.100.177.93]) (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 37F406ECE3 for ; Thu, 14 Jul 2022 18:43:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 37F406ECE3 Received: by smtp33.i.mail.ru with esmtpa (envelope-from ) id 1oC0zy-0003cF-3P; Thu, 14 Jul 2022 18:43:30 +0300 Date: Thu, 14 Jul 2022 18:41:08 +0300 To: Maxim Kokryashkin Message-ID: References: <6ef8aa43d1a571fef477550885e24faf1e4b962b.1654767443.git.skaplun@tarantool.org> <1656951016.765494116@f748.i.mail.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1656951016.765494116@f748.i.mail.ru> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9E1E7861EDEC0DEA642A52A3D70DB4D8C9D750E388E4A7DAE00894C459B0CD1B980D0B0EC686275C4CCBB77FF23160FBEB4752CBDCF1EDB50B14F0FA0E0289DA8 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE745C0EDBD94D46193EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063796E7E609BFB2B1698638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8A8E24C620920872DC8F287E2856C2B85117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC566404C906FA8ADEA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD182CC0D3CB04F14752D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE042285CD7A5C321F6E0066C2D8992A164AD6D5ED66289B52698AB9A7B718F8C46E0066C2D8992A16725E5C173C3A84C3F45B66EA30F6D82CBA3038C0950A5D36B5C8C57E37DE458B0BC6067A898B09E46D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE72F88032165008D51731C566533BA786AA5CC5B56E945C8DA X-8FC586DF: 6EFBBC1D9D64D975 X-C1DE0DAB: 9604B64F49C60606AD91A466A1DEF99B296C473AB1E142185AC9E3593CE4B31AB1881A6453793CE9274300E5CE05BD4401A9E91200F654B0F56C66D0505D9834D71D610BA8056A10D28DFCDE70572BC832AB8B4677342EE29C2B6934AE262D3EE7EAB7254005DCED8DA55E71E02F9FC08E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34EE6683D9E546CC6259E3811CA61156EB335E1377C9640C8005464E42E9AF1F0D8429A93B5649B3B11D7E09C32AA3244C5972CBFEA39BB1BBDA9804D5B86E708351E887DA02A9F7BFFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojpf3/rFe+bF8UPk+C5a+6dQ== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A769FFB58298EB30447127E6236864438919BE4EBEF89FC7D6FADEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 2/2] gdb: introduce lj-bc, lj-func and lj-proto dumpers 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 review! On 04.07.22, Maxim Kokryashkin wrote: > > Hi, Sergey! > Thanks for the patch! >   > Please consider my comments below. Fixed, see iterative patches below. Branch is force-pushed. Side note: I've fixed you suggestions from the last one to the top one, so don't be confused by diff in them. >   > > > >diff --git a/src/luajit-gdb.py b/src/luajit-gdb.py > >index 779a25f8..339b57ed 100644 > >--- a/src/luajit-gdb.py > >+++ b/src/luajit-gdb.py > > >+___ = 0 > >+BC_NAME = 0 > >+BC_A = 1 > >+BC_B = 2 > >+BC_CD = 3 > >+BC_MM = 4 > >+ > >+BYTECODES = [ > >+ # Comparison ops. ORDER OPR. > >+ ['ISLT', 'var', ___, 'var', 'lt'], > >+ ['FUNCCW', 'rbase', ___, ___, ___], > >+] > I suggest rewriting that chunk with named tuple[1]. That is more readable > and more pythonic way of doing stuff like this. I've rewrited it with tuple (instead namedtuple) to avoid usage of "collections", also it helps to read each bytecode declaration. See the iterative patch below. =================================================================== diff --git a/src/luajit-gdb.py b/src/luajit-gdb.py index be86f599..98feebec 100644 --- a/src/luajit-gdb.py +++ b/src/luajit-gdb.py @@ -129,136 +129,131 @@ def bc_d(ins): return int(ins) >> 16 ___ = 0 -BC_NAME = 0 -BC_A = 1 -BC_B = 2 -BC_CD = 3 -BC_MM = 4 BYTECODES = [ # Comparison ops. ORDER OPR. - ['ISLT', 'var', ___, 'var', 'lt'], - ['ISGE', 'var', ___, 'var', 'lt'], - ['ISLE', 'var', ___, 'var', 'le'], - ['ISGT', 'var', ___, 'var', 'le'], - - ['ISEQV', 'var', ___, 'var', 'eq'], - ['ISNEV', 'var', ___, 'var', 'eq'], - ['ISEQS', 'var', ___, 'str', 'eq'], - ['ISNES', 'var', ___, 'str', 'eq'], - ['ISEQN', 'var', ___, 'num', 'eq'], - ['ISNEN', 'var', ___, 'num', 'eq'], - ['ISEQP', 'var', ___, 'pri', 'eq'], - ['ISNEP', 'var', ___, 'pri', 'eq'], + {'name': 'ISLT', 'ra': 'var', 'rb': ___, 'rcd': 'var', 'mm': 'lt'}, + {'name': 'ISGE', 'ra': 'var', 'rb': ___, 'rcd': 'var', 'mm': 'lt'}, + {'name': 'ISLE', 'ra': 'var', 'rb': ___, 'rcd': 'var', 'mm': 'le'}, + {'name': 'ISGT', 'ra': 'var', 'rb': ___, 'rcd': 'var', 'mm': 'le'}, + + {'name': 'ISEQV', 'ra': 'var', 'rb': ___, 'rcd': 'var', 'mm': 'eq'}, + {'name': 'ISNEV', 'ra': 'var', 'rb': ___, 'rcd': 'var', 'mm': 'eq'}, + {'name': 'ISEQS', 'ra': 'var', 'rb': ___, 'rcd': 'str', 'mm': 'eq'}, + {'name': 'ISNES', 'ra': 'var', 'rb': ___, 'rcd': 'str', 'mm': 'eq'}, + {'name': 'ISEQN', 'ra': 'var', 'rb': ___, 'rcd': 'num', 'mm': 'eq'}, + {'name': 'ISNEN', 'ra': 'var', 'rb': ___, 'rcd': 'num', 'mm': 'eq'}, + {'name': 'ISEQP', 'ra': 'var', 'rb': ___, 'rcd': 'pri', 'mm': 'eq'}, + {'name': 'ISNEP', 'ra': 'var', 'rb': ___, 'rcd': 'pri', 'mm': 'eq'}, # Unary test and copy ops. - ['ISTC', 'dst', ___, 'var', ___], - ['ISFC', 'dst', ___, 'var', ___], - ['IST', ___, ___, 'var', ___], - ['ISF', ___, ___, 'var', ___], - ['ISTYPE', 'var', ___, 'lit', ___], - ['ISNUM', 'var', ___, 'lit', ___], - ['MOV', 'dst', ___, 'var', ___], - ['NOT', 'dst', ___, 'var', ___], - ['UNM', 'dst', ___, 'var', 'unm'], - ['LEN', 'dst', ___, 'var', 'len'], - ['ADDVN', 'dst', 'var', 'num', 'add'], - ['SUBVN', 'dst', 'var', 'num', 'sub'], - ['MULVN', 'dst', 'var', 'num', 'mul'], - ['DIVVN', 'dst', 'var', 'num', 'div'], - ['MODVN', 'dst', 'var', 'num', 'mod'], + {'name': 'ISTC', 'ra': 'dst', 'rb': ___, 'rcd': 'var', 'mm': ___}, + {'name': 'ISFC', 'ra': 'dst', 'rb': ___, 'rcd': 'var', 'mm': ___}, + {'name': 'IST', 'ra': ___, 'rb': ___, 'rcd': 'var', 'mm': ___}, + {'name': 'ISF', 'ra': ___, 'rb': ___, 'rcd': 'var', 'mm': ___}, + {'name': 'ISTYPE', 'ra': 'var', 'rb': ___, 'rcd': 'lit', 'mm': ___}, + {'name': 'ISNUM', 'ra': 'var', 'rb': ___, 'rcd': 'lit', 'mm': ___}, + {'name': 'MOV', 'ra': 'dst', 'rb': ___, 'rcd': 'var', 'mm': ___}, + {'name': 'NOT', 'ra': 'dst', 'rb': ___, 'rcd': 'var', 'mm': ___}, + {'name': 'UNM', 'ra': 'dst', 'rb': ___, 'rcd': 'var', 'mm': 'unm'}, + {'name': 'LEN', 'ra': 'dst', 'rb': ___, 'rcd': 'var', 'mm': 'len'}, + {'name': 'ADDVN', 'ra': 'dst', 'rb': 'var', 'rcd': 'num', 'mm': 'add'}, + {'name': 'SUBVN', 'ra': 'dst', 'rb': 'var', 'rcd': 'num', 'mm': 'sub'}, + {'name': 'MULVN', 'ra': 'dst', 'rb': 'var', 'rcd': 'num', 'mm': 'mul'}, + {'name': 'DIVVN', 'ra': 'dst', 'rb': 'var', 'rcd': 'num', 'mm': 'div'}, + {'name': 'MODVN', 'ra': 'dst', 'rb': 'var', 'rcd': 'num', 'mm': 'mod'}, # Binary ops. ORDER OPR. - ['ADDNV', 'dst', 'var', 'num', 'add'], - ['SUBNV', 'dst', 'var', 'num', 'sub'], - ['MULNV', 'dst', 'var', 'num', 'mul'], - ['DIVNV', 'dst', 'var', 'num', 'div'], - ['MODNV', 'dst', 'var', 'num', 'mod'], + {'name': 'ADDNV', 'ra': 'dst', 'rb': 'var', 'rcd': 'num', 'mm': 'add'}, + {'name': 'SUBNV', 'ra': 'dst', 'rb': 'var', 'rcd': 'num', 'mm': 'sub'}, + {'name': 'MULNV', 'ra': 'dst', 'rb': 'var', 'rcd': 'num', 'mm': 'mul'}, + {'name': 'DIVNV', 'ra': 'dst', 'rb': 'var', 'rcd': 'num', 'mm': 'div'}, + {'name': 'MODNV', 'ra': 'dst', 'rb': 'var', 'rcd': 'num', 'mm': 'mod'}, - ['ADDVV', 'dst', 'var', 'var', 'add'], - ['SUBVV', 'dst', 'var', 'var', 'sub'], - ['MULVV', 'dst', 'var', 'var', 'mul'], - ['DIVVV', 'dst', 'var', 'var', 'div'], - ['MODVV', 'dst', 'var', 'var', 'mod'], + {'name': 'ADDVV', 'ra': 'dst', 'rb': 'var', 'rcd': 'var', 'mm': 'add'}, + {'name': 'SUBVV', 'ra': 'dst', 'rb': 'var', 'rcd': 'var', 'mm': 'sub'}, + {'name': 'MULVV', 'ra': 'dst', 'rb': 'var', 'rcd': 'var', 'mm': 'mul'}, + {'name': 'DIVVV', 'ra': 'dst', 'rb': 'var', 'rcd': 'var', 'mm': 'div'}, + {'name': 'MODVV', 'ra': 'dst', 'rb': 'var', 'rcd': 'var', 'mm': 'mod'}, - ['POW', 'dst', 'var', 'var', 'pow'], - ['CAT', 'dst', 'rbase', 'rbase', 'concat'], + {'name': 'POW', 'ra': 'dst', 'rb': 'var', 'rcd': 'var', 'mm': 'pow'}, + {'name': 'CAT', 'ra': 'dst', 'rb': 'rbase', 'rcd': 'rbase', 'mm': 'concat'}, # Constant ops. - ['KSTR', 'dst', ___, 'str', ___], - ['KCDATA', 'dst', ___, 'cdata', ___], - ['KSHORT', 'dst', ___, 'lits', ___], - ['KNUM', 'dst', ___, 'num', ___], - ['KPRI', 'dst', ___, 'pri', ___], - ['KNIL', 'base', ___, 'base', ___], + {'name': 'KSTR', 'ra': 'dst', 'rb': ___, 'rcd': 'str', 'mm': ___}, + {'name': 'KCDATA', 'ra': 'dst', 'rb': ___, 'rcd': 'cdata', 'mm': ___}, + {'name': 'KSHORT', 'ra': 'dst', 'rb': ___, 'rcd': 'lits', 'mm': ___}, + {'name': 'KNUM', 'ra': 'dst', 'rb': ___, 'rcd': 'num', 'mm': ___}, + {'name': 'KPRI', 'ra': 'dst', 'rb': ___, 'rcd': 'pri', 'mm': ___}, + {'name': 'KNIL', 'ra': 'base', 'rb': ___, 'rcd': 'base', 'mm': ___}, # Upvalue and function ops. - ['UGET', 'dst', ___, 'uv', ___], - ['USETV', 'uv', ___, 'var', ___], - ['USETS', 'uv', ___, 'str', ___], - ['USETN', 'uv', ___, 'num', ___], - ['USETP', 'uv', ___, 'pri', ___], - ['UCLO', 'rbase', ___, 'jump', ___], - ['FNEW', 'dst', ___, 'func', ___], + {'name': 'UGET', 'ra': 'dst', 'rb': ___, 'rcd': 'uv', 'mm': ___}, + {'name': 'USETV', 'ra': 'uv', 'rb': ___, 'rcd': 'var', 'mm': ___}, + {'name': 'USETS', 'ra': 'uv', 'rb': ___, 'rcd': 'str', 'mm': ___}, + {'name': 'USETN', 'ra': 'uv', 'rb': ___, 'rcd': 'num', 'mm': ___}, + {'name': 'USETP', 'ra': 'uv', 'rb': ___, 'rcd': 'pri', 'mm': ___}, + {'name': 'UCLO', 'ra': 'rbase', 'rb': ___, 'rcd': 'jump', 'mm': ___}, + {'name': 'FNEW', 'ra': 'dst', 'rb': ___, 'rcd': 'func', 'mm': ___}, # Table ops. - ['TNEW', 'dst', ___, 'lit', ___], - ['TDUP', 'dst', ___, 'tab', ___], - ['GGET', 'dst', ___, 'str', 'index'], - ['GSET', 'var', ___, 'str', 'newindex'], - ['TGETV', 'dst', 'var', 'var', 'index'], - ['TGETS', 'dst', 'var', 'str', 'index'], - ['TGETB', 'dst', 'var', 'lit', 'index'], - ['TGETR', 'dst', 'var', 'var', 'index'], - ['TSETV', 'var', 'var', 'var', 'newindex'], - ['TSETS', 'var', 'var', 'str', 'newindex'], - ['TSETB', 'var', 'var', 'lit', 'newindex'], - ['TSETM', 'base', ___, 'num', 'newindex'], - ['TSETR', 'var', 'var', 'var', 'newindex'], + {'name': 'TNEW', 'ra': 'dst', 'rb': ___, 'rcd': 'lit', 'mm': ___}, + {'name': 'TDUP', 'ra': 'dst', 'rb': ___, 'rcd': 'tab', 'mm': ___}, + {'name': 'GGET', 'ra': 'dst', 'rb': ___, 'rcd': 'str', 'mm': 'index'}, + {'name': 'GSET', 'ra': 'var', 'rb': ___, 'rcd': 'str', 'mm': 'newindex'}, + {'name': 'TGETV', 'ra': 'dst', 'rb': 'var', 'rcd': 'var', 'mm': 'index'}, + {'name': 'TGETS', 'ra': 'dst', 'rb': 'var', 'rcd': 'str', 'mm': 'index'}, + {'name': 'TGETB', 'ra': 'dst', 'rb': 'var', 'rcd': 'lit', 'mm': 'index'}, + {'name': 'TGETR', 'ra': 'dst', 'rb': 'var', 'rcd': 'var', 'mm': 'index'}, + {'name': 'TSETV', 'ra': 'var', 'rb': 'var', 'rcd': 'var', 'mm': 'newindex'}, + {'name': 'TSETS', 'ra': 'var', 'rb': 'var', 'rcd': 'str', 'mm': 'newindex'}, + {'name': 'TSETB', 'ra': 'var', 'rb': 'var', 'rcd': 'lit', 'mm': 'newindex'}, + {'name': 'TSETM', 'ra': 'base', 'rb': ___, 'rcd': 'num', 'mm': 'newindex'}, + {'name': 'TSETR', 'ra': 'var', 'rb': 'var', 'rcd': 'var', 'mm': 'newindex'}, # Calls and vararg handling. T = tail call. - ['CALLM', 'base', 'lit', 'lit', 'call'], - ['CALL', 'base', 'lit', 'lit', 'call'], - ['CALLMT', 'base', ___, 'lit', 'call'], - ['CALLT', 'base', ___, 'lit', 'call'], - ['ITERC', 'base', 'lit', 'lit', 'call'], - ['ITERN', 'base', 'lit', 'lit', 'call'], - ['VARG', 'base', 'lit', 'lit', ___], - ['ISNEXT', 'base', ___, 'jump', ___], + {'name': 'CALLM', 'ra': 'base', 'rb': 'lit', 'rcd': 'lit', 'mm': 'call'}, + {'name': 'CALL', 'ra': 'base', 'rb': 'lit', 'rcd': 'lit', 'mm': 'call'}, + {'name': 'CALLMT', 'ra': 'base', 'rb': ___, 'rcd': 'lit', 'mm': 'call'}, + {'name': 'CALLT', 'ra': 'base', 'rb': ___, 'rcd': 'lit', 'mm': 'call'}, + {'name': 'ITERC', 'ra': 'base', 'rb': 'lit', 'rcd': 'lit', 'mm': 'call'}, + {'name': 'ITERN', 'ra': 'base', 'rb': 'lit', 'rcd': 'lit', 'mm': 'call'}, + {'name': 'VARG', 'ra': 'base', 'rb': 'lit', 'rcd': 'lit', 'mm': ___}, + {'name': 'ISNEXT', 'ra': 'base', 'rb': ___, 'rcd': 'jump', 'mm': ___}, # Returns. - ['RETM', 'base', ___, 'lit', ___], - ['RET', 'rbase', ___, 'lit', ___], - ['RET0', 'rbase', ___, 'lit', ___], - ['RET1', 'rbase', ___, 'lit', ___], + {'name': 'RETM', 'ra': 'base', 'rb': ___, 'rcd': 'lit', 'mm': ___}, + {'name': 'RET', 'ra': 'rbase', 'rb': ___, 'rcd': 'lit', 'mm': ___}, + {'name': 'RET0', 'ra': 'rbase', 'rb': ___, 'rcd': 'lit', 'mm': ___}, + {'name': 'RET1', 'ra': 'rbase', 'rb': ___, 'rcd': 'lit', 'mm': ___}, # Loops and branches. I/J = interp/JIT, I/C/L = init/call/loop. - ['FORI', 'base', ___, 'jump', ___], - ['JFORI', 'base', ___, 'jump', ___], + {'name': 'FORI', 'ra': 'base', 'rb': ___, 'rcd': 'jump', 'mm': ___}, + {'name': 'JFORI', 'ra': 'base', 'rb': ___, 'rcd': 'jump', 'mm': ___}, - ['FORL', 'base', ___, 'jump', ___], - ['IFORL', 'base', ___, 'jump', ___], - ['JFORL', 'base', ___, 'lit', ___], + {'name': 'FORL', 'ra': 'base', 'rb': ___, 'rcd': 'jump', 'mm': ___}, + {'name': 'IFORL', 'ra': 'base', 'rb': ___, 'rcd': 'jump', 'mm': ___}, + {'name': 'JFORL', 'ra': 'base', 'rb': ___, 'rcd': 'lit', 'mm': ___}, - ['ITERL', 'base', ___, 'jump', ___], - ['IITERL', 'base', ___, 'jump', ___], - ['JITERL', 'base', ___, 'lit', ___], + {'name': 'ITERL', 'ra': 'base', 'rb': ___, 'rcd': 'jump', 'mm': ___}, + {'name': 'IITERL', 'ra': 'base', 'rb': ___, 'rcd': 'jump', 'mm': ___}, + {'name': 'JITERL', 'ra': 'base', 'rb': ___, 'rcd': 'lit', 'mm': ___}, - ['LOOP', 'rbase', ___, 'jump', ___], - ['ILOOP', 'rbase', ___, 'jump', ___], - ['JLOOP', 'rbase', ___, 'lit', ___], + {'name': 'LOOP', 'ra': 'rbase', 'rb': ___, 'rcd': 'jump', 'mm': ___}, + {'name': 'ILOOP', 'ra': 'rbase', 'rb': ___, 'rcd': 'jump', 'mm': ___}, + {'name': 'JLOOP', 'ra': 'rbase', 'rb': ___, 'rcd': 'lit', 'mm': ___}, - ['JMP', 'rbase', ___, 'jump', ___], + {'name': 'JMP', 'ra': 'rbase', 'rb': ___, 'rcd': 'jump', 'mm': ___}, # Function headers. I/J = interp/JIT, F/V/C = fixarg/vararg/C func. - ['FUNCF', 'rbase', ___, ___, ___], - ['IFUNCF', 'rbase', ___, ___, ___], - ['JFUNCF', 'rbase', ___, 'lit', ___], - ['FUNCV', 'rbase', ___, ___, ___], - ['IFUNCV', 'rbase', ___, ___, ___], - ['JFUNCV', 'rbase', ___, 'lit', ___], - ['FUNCC', 'rbase', ___, ___, ___], - ['FUNCCW', 'rbase', ___, ___, ___], + {'name': 'FUNCF', 'ra': 'rbase', 'rb': ___, 'rcd': ___, 'mm': ___}, + {'name': 'IFUNCF', 'ra': 'rbase', 'rb': ___, 'rcd': ___, 'mm': ___}, + {'name': 'JFUNCF', 'ra': 'rbase', 'rb': ___, 'rcd': 'lit', 'mm': ___}, + {'name': 'FUNCV', 'ra': 'rbase', 'rb': ___, 'rcd': ___, 'mm': ___}, + {'name': 'IFUNCV', 'ra': 'rbase', 'rb': ___, 'rcd': ___, 'mm': ___}, + {'name': 'JFUNCV', 'ra': 'rbase', 'rb': ___, 'rcd': 'lit', 'mm': ___}, + {'name': 'FUNCC', 'ra': 'rbase', 'rb': ___, 'rcd': ___, 'mm': ___}, + {'name': 'FUNCCW', 'ra': 'rbase', 'rb': ___, 'rcd': ___, 'mm': ___}, ] def proto_bc(proto): @@ -725,8 +720,7 @@ def funcuvname(pt, idx): return str(cast('char *', uvinfo)) -def dump_reg(bc, reg, value, jmp_format=None, jmp_ctx=None): - rtype = bc[reg] +def dump_reg(rtype, value, jmp_format=None, jmp_ctx=None): is_jmp = rtype == 'jump' if rtype == 'jump': @@ -745,8 +739,7 @@ def dump_reg(bc, reg, value, jmp_format=None, jmp_ctx=None): value = value, ) -def dump_kc(bc, reg, value, proto): - rtype = bc[reg] +def dump_kc(rtype, value, proto): kc = '' if proto: if rtype == 'str' or rtype == 'func': @@ -766,23 +759,21 @@ def dump_bc(ins, jmp_format=None, jmp_ctx=None, proto=None): return 'INVALID' bc = BYTECODES[op] - bc_name = bc[BC_NAME] - bc_hasa = bc[BC_A] - bc_hasb = bc[BC_B] - - kca = dump_kc(bc, BC_A, bc_a(ins), proto) if bc_hasa else '' - kcc = dump_kc(bc, BC_CD, bc_c(ins) if bc_hasb else bc_d(ins), proto) if bc[BC_CD] else '' + kca = dump_kc(bc['ra'], bc_a(ins), proto) if bc['ra'] else '' + kcc = dump_kc( + bc['rcd'], bc_c(ins) if bc['rb'] else bc_d(ins), proto + ) if bc['rcd'] else '' return '{name:6} {ra}{rb}{rcd}{kc}'.format( - name = bc_name, - ra = dump_reg(bc, BC_A, bc_a(ins)) + ' ' if bc_hasa else '', - rb = dump_reg(bc, BC_B, bc_b(ins)) + ' ' if bc_hasb else '', + name = bc['name'], + ra = dump_reg(bc['ra'], bc_a(ins)) + ' ' if bc['ra'] else '', + rb = dump_reg(bc['rb'], bc_b(ins)) + ' ' if bc['rb'] else '', rcd = dump_reg( - bc, BC_CD, bc_c(ins) if bc_hasb else bc_d(ins), + bc['rcd'], bc_c(ins) if bc['rb'] else bc_d(ins), jmp_format=jmp_format, jmp_ctx=jmp_ctx - ) if bc[BC_CD] else '', - kc=kca+kcc + ) if bc['rcd'] else '', + kc = kca + kcc ) def dump_proto(proto): =================================================================== >   > > >+def dump_reg(bc, reg, value, jmp_format=None, jmp_ctx=None): > >+ rtype = bc[reg] > >+ is_jmp = rtype == 'jump' > >+ padding = ':' + ' ' * (5 - len(rtype)) > >+ > >+ if rtype == 'jump': > >+ # Destination of jump instruction encoded as offset from BCBIAS_J. > >+ delta = value - 0x7fff > >+ if jmp_format: > >+ value = jmp_format(jmp_ctx, delta) > >+ else: > >+ prefix = '+' if delta >= 0 else '' > >+ value = prefix + str(delta) > >+ else: > >+ value = '{:3d}'.format(value) > >+ > >+ return '{rtype}{padding} {value}'.format( > >+ rtype = rtype, > >+ padding = padding, > >+ value = value, > >+ ) > The padding variable is unnecessary. You can use format-string > width specifier[2] instead. Fixed! Thanks! See the iterative patch below. =================================================================== diff --git a/src/luajit-gdb.py b/src/luajit-gdb.py index 0827ad45..be86f599 100644 --- a/src/luajit-gdb.py +++ b/src/luajit-gdb.py @@ -728,7 +728,6 @@ def funcuvname(pt, idx): def dump_reg(bc, reg, value, jmp_format=None, jmp_ctx=None): rtype = bc[reg] is_jmp = rtype == 'jump' - padding = ':' + ' ' * (5 - len(rtype)) if rtype == 'jump': # Destination of jump instruction encoded as offset from BCBIAS_J. @@ -741,9 +740,8 @@ def dump_reg(bc, reg, value, jmp_format=None, jmp_ctx=None): else: value = '{:3d}'.format(value) - return '{rtype}{padding} {value}'.format( - rtype = rtype, - padding = padding, + return '{rtype:6} {value}'.format( + rtype = rtype + ':', value = value, ) @@ -769,7 +767,6 @@ def dump_bc(ins, jmp_format=None, jmp_ctx=None, proto=None): bc = BYTECODES[op] bc_name = bc[BC_NAME] - name_padding = ' ' * (6 - len(bc_name)) bc_hasa = bc[BC_A] bc_hasb = bc[BC_B] @@ -777,9 +774,8 @@ def dump_bc(ins, jmp_format=None, jmp_ctx=None, proto=None): kca = dump_kc(bc, BC_A, bc_a(ins), proto) if bc_hasa else '' kcc = dump_kc(bc, BC_CD, bc_c(ins) if bc_hasb else bc_d(ins), proto) if bc[BC_CD] else '' - return '{name}{npad} {ra}{rb}{rcd}{kc}'.format( + return '{name:6} {ra}{rb}{rcd}{kc}'.format( name = bc_name, - npad = name_padding, ra = dump_reg(bc, BC_A, bc_a(ins)) + ' ' if bc_hasa else '', rb = dump_reg(bc, BC_B, bc_b(ins)) + ' ' if bc_hasb else '', rcd = dump_reg( ~ =================================================================== >   > > > > >+class LJDumpFunc(LJBase): > >+ ''' > >+lj-funcl > Typo: s/lj-funcl/lj-func Fixed! Thanks! See the iterative patch below. =================================================================== diff --git a/src/luajit-gdb.py b/src/luajit-gdb.py index f976b758..0827ad45 100644 --- a/src/luajit-gdb.py +++ b/src/luajit-gdb.py @@ -1051,7 +1051,7 @@ The constants or upvalues of the prototype are decoded after ';'. class LJDumpFunc(LJBase): ''' -lj-funcl +lj-func The command receives a of the corresponding GCfunc object and dumps the chunk name, where the corresponding function is defined, corresponding =================================================================== >   > >   > Side note: > In the present moment, passing an invalid pointer to `lj-func`/`lj-proto` results in empty > output, which is not a gdb-way (and not a UNIX-way either) of reporting errors. > Maybe it is a good idea to check the type of the  value under the pointer and > report corresponding errors.  Yes, maybe. But I suggest now just use the same interface as for other lj-* dumpers. We can refactor them later. >   > [1]:  https://docs.python.org/3/library/collections.html#collections.namedtuple > [2]:  https://docs.python.org/3/library/string.html#format-examples >   > -- > Best regards, > Maxim Kokryashkin -- Best regards, Sergey Kaplun