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 3A1606ECE4; Thu, 9 Jun 2022 13:13:40 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3A1606ECE4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1654769620; bh=iBWSkIu0QinZcdQv4rTSH8c7ou5XsyW4ERUce9d14zs=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=v4VGpmQKu91w3joxTWiRIZ6M1wvoWKofoYxqhqwCJmE3te59M51rI/XLTGkj3gxTq IcQL92iGWyu8lwF7Om5/5g3OXopj6UKj09wzRcTVFaSIS44FEj59NjnkhsBR21TXZS dlyjI0KsjLHaKO4juvpDNYVrTKnmZsjoJibJqNws= Received: from smtpng3.i.mail.ru (smtpng3.i.mail.ru [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 69A1A6ECE3 for ; Thu, 9 Jun 2022 13:13:38 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 69A1A6ECE3 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1nzFAW-0007Ak-GO; Thu, 09 Jun 2022 13:13:37 +0300 To: Maxim Kokryashkin , Igor Munkin Date: Thu, 9 Jun 2022 13:11:12 +0300 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9401830D0D29680878F42A9C359BB4C056ABDEB75F6E4F0B8182A05F5380850404C228DA9ACA6FE27EFEBAD6DBAE8276B8AA98922BAAC9FA9213A3E8367427884584A5EF8893988F4 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE742D9BD90C58D50E0EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637B323FE155BC226618638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8CC76FBC9E0DDF29702DAE43ADF49A4C1117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC2EE5AD8F952D28FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18CB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6AC294AFEFA671E80089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-8FC586DF: 6EFBBC1D9D64D975 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C83BF3A71D03FAA4AB123EEC51A06AA71C0F8C74A13CF7F169C2B6934AE262D3EE7EAB7254005DCED2972A488E2682F59F36E2E0160E5C55395B8A2A0B6518DF68C46860778A80D548DA55E71E02F9FC08E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3468964757141B82E08157431CA213D4C7D331BC31095B279E8830FBA055575A9364B3FD7967B40C041D7E09C32AA3244C2E0148682F7B72219FAFF49D3D6AC1FB64EE5813BBCA3A9D927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojgs1behNStkkMXyG19MzJzg== X-Mailru-Sender: 689FA8AB762F739339CABD9B3CA9A7D6565EC1060CBA59520DC47CD53426DE420FBE9A32752B8C9C2AA642CC12EC09F1FB559BB5D741EB962F61BD320559CF1EFD657A8799238ED55FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 0/2] Introduce dumpers for bytecodes in gdb 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" Branch: https://github.com/tarantool/luajit/tree/skaplun/gh-noticket-luajit-gdb-dump-bc This patchset allows to inspect bytecodes as for single instruction, as for all bytecodes inside function or its prototype via gdb. The first auxiliary patch is needed to introduce dumpers for GCobject similar to TValues dumpers. The second patch introduces 3 new commands: * lj-bc -- dump single bytecode instruction * lj-func -- dump all bytecode instructions for Lua function or report type of C or F function * lj-proto -- dump all bytecode instructions for the prototype For example, we have the following Lua script named : | 1 local function mywhile(a) | 2 local r = 0 | 3 print(a) | 4 while (a < 30) do | 5 r = r + a * r/2 | 6 end | 7 return r | 8 end | 9 | 10 local uvname1 = false | 11 local uvname2 = false | 12 local function myif(a) | 13 local s1 = a + 4 | 14 local s2 = s1 + 4 | 15 uvname1 = "s10" | 16 uvname2 = "s11" | 17 print(a) | 18 if a > 10 then | 19 return a + s2 + s1 | 20 else | 21 return a - 10 - s2 - s1 | 22 end | 23 end | 24 | 25 local f1 = myif | 26 local f2 = mywhile | 27 myif(12) | 28 mywhile(12) Assume, we set a breakpoint at `lj_cf_print` (line 3). The lj-stack output contains the following lines: | 0x40001970 [ ] VALUE: Lua function @ 0x400083c0, 0 upvalues, "@../tmp.lua":1 | 0x40001968 [ ] VALUE: Lua function @ 0x40002148, 2 upvalues, "@../tmp.lua":12 | ... | 0x40001940 [ ] FRAME: [V] delta=1, Lua function @ 0x400084a0, 0 upvalues, "@../tmp.lua":0 The first one is `myif()` function, the second is `mywhile()` and the last one is function loaded via `dofile()`. The resulting output for the functions is the following: 1) | (gdb) lj-func 0x400083c0 | "@../tmp.lua":1-8 | 0000 FUNCF rbase: 4 | 0001 KSHORT dst: 1 lits: 0 | 0002 GGET dst: 2 str: 0 ; string "print" @ 0x400037f0 | 0003 MOV dst: 3 var: 0 | 0004 CALL base: 2 lit: 1 lit: 2 | 0005 KSHORT dst: 2 lits: 30 | 0006 ISGE var: 0 var: 2 | 0007 JMP rbase: 2 jump: => 0013 | 0008 LOOP rbase: 2 jump: => 0013 | 0009 MULVV dst: 2 var: 0 var: 1 | 0010 DIVVN dst: 2 var: 2 num: 0 ; number 2 | 0011 ADDVV dst: 1 var: 1 var: 2 | 0012 JMP rbase: 2 jump: => 0005 | 0013 RET1 rbase: 1 lit: 2 The report is the same as for the following command: | lj-proto (GCproto *)(((char *)(((GCfuncL *)0x400083c0)->pc.ptr32))-sizeof(GCproto)) 2) | (gdb) lj-func 0x40002148 | "@../tmp.lua":12-23 | 0000 FUNCF rbase: 5 | 0001 ADDVN dst: 1 var: 0 num: 0 ; number 4 | 0002 ADDVN dst: 2 var: 1 num: 0 ; number 4 | 0003 USETS uv: 0 str: 0 ; 0x40002527 "uvname1" ; string "s10" @ 0x40002298 | 0004 USETS uv: 1 str: 1 ; 0x4000252f "uvname2" ; string "s11" @ 0x400022b8 | 0005 GGET dst: 3 str: 2 ; string "print" @ 0x400037f0 | 0006 MOV dst: 4 var: 0 | 0007 CALL base: 3 lit: 1 lit: 2 | 0008 KSHORT dst: 3 lits: 10 | 0009 ISGE var: 3 var: 0 | 0010 JMP rbase: 3 jump: => 0015 | 0011 ADDVV dst: 3 var: 0 var: 2 | 0012 ADDVV dst: 3 var: 3 var: 1 | 0013 RET1 rbase: 3 lit: 2 | 0014 JMP rbase: 3 jump: => 0019 | 0015 SUBVN dst: 3 var: 0 num: 1 ; number 10 | 0016 SUBVV dst: 3 var: 3 var: 2 | 0017 SUBVV dst: 3 var: 3 var: 1 | 0018 RET1 rbase: 3 lit: 2 | 0019 RET0 rbase: 0 lit: 1 3) | (gdb) lj-func 0x400084a0 | "@../tmp.lua":0-30 | 0000 FUNCV rbase: 8 | 0001 FNEW dst: 0 func: 0 ; "@../tmp.lua":1 | 0002 KPRI dst: 1 pri: 1 | 0003 KPRI dst: 2 pri: 1 | 0004 FNEW dst: 3 func: 1 ; "@../tmp.lua":12 | 0005 MOV dst: 4 var: 3 | 0006 MOV dst: 5 var: 0 | 0007 MOV dst: 6 var: 3 | 0008 KSHORT dst: 7 lits: 12 | 0009 CALL base: 6 lit: 1 lit: 2 | 0010 MOV dst: 6 var: 0 | 0011 KSHORT dst: 7 lits: 12 | 0012 CALL base: 6 lit: 1 lit: 2 | 0013 UCLO rbase: 0 jump: => 0014 | 0014 RET0 rbase: 0 lit: 1 The single bytecode instruction may be useful, when you debug VM: | (gdb) b lj_BC_ISGE | Breakpoint 2 at 0x5555555f0a08 | (gdb) c | Continuing. | Breakpoint 2, 0x00005555555f0a08 in lj_BC_ISGE () | (gdb) lj-bc $rbx # PC refers __the next instruction__ | JMP rbase: 3 jump: +5 | (gdb) lj-bc ((BCIns *)$rbx) - 1 # current instruction | ISGE var: 3 var: 0 Sergey Kaplun (2): gdb: introduce dumpers for GCobj gdb: introduce lj-bc, lj-func and lj-proto dumpers src/luajit-gdb.py | 475 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 425 insertions(+), 50 deletions(-) -- 2.34.1