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 091226F867; Tue, 1 Feb 2022 00:37:29 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 091226F867 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1643665049; bh=cqC2Kc+G6tXCC7/oEQBR90k+hNGpsZZ/cm1VX0TVbxE=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=I2VsViTEL3V24z5fj2EnbUiB/m00nIfBL2xDBaQPF1qG9nEs3erpY+VY9gj1fPQz3 OSzfshYr2q4c6ShDUg/ugKWSwL971/Ydpa8b7grFe+YAjMo5eRY43n91vMYBhJkWeD IfAXJf0LWARW/5e3xp7fp777ll4/Ieajytrtoo/s= 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 A07286F867 for ; Tue, 1 Feb 2022 00:36:55 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A07286F867 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1nEeM2-0002SX-Jv; Tue, 01 Feb 2022 00:36:55 +0300 To: Sergey Kaplun , Maxim Kokryashkin Date: Tue, 1 Feb 2022 00:33:54 +0300 Message-Id: <0868c62b88c5c39f30b052191d489671be7afc20.1643645066.git.imun@tarantool.org> X-Mailer: git-send-email 2.34.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD99F281FB7F96F126DCE6C712E020AF857D6DE8BB6CE83F72B00894C459B0CD1B97008CECF24940081A805D7C5839175AF87F19ABF61EF05D6599FBF3E6EA3F319 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE74BE895B46187343CEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006374FBED2B83F5E00CA8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D85580469DD76170E9ABA077739C3F8939117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B658CDF7FFE3EBBCC0089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-8FC586DF: 6EFBBC1D9D64D975 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CCED4562AEA10A75FA6E511B3FFB271087A944C7C6E8FE9F59C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF166FC1BB2721D293DC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3451BBE684D17D7221D63045526E0FB55870E32E291AA733AD0B69D650B0386EC8F15CF2476A94F8C81D7E09C32AA3244C26E89B2BA8173FCB0F309A4EF771EAEB60759606DA2E136A927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojj6iw2H+lRYwtPJnBn+3eTA== X-Mailru-Sender: 689FA8AB762F739339CABD9B3CA9A7D6BA799DDD537B01B101B65008BDEC76A3A7C8D0F45F857DBFE9F1EFEE2F478337FB559BB5D741EB964C8C2C849690F8E70A04DAD6CC59E3365FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH 1/2] gdb: unwind Lua stack top part 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: Igor Munkin via Tarantool-patches Reply-To: Igor Munkin Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Prior to this patch the dump of Lua stack top (or bottom if we consider address growth direction) part was almost hardcoded except the number of its free slots. This leads to the following drawbacks of command: * Red zone stack slots are collapsed like the way similar to free stack slots are except for the single difference: one needs to use to inspect them regardless the fact they are used or not. * Top slot is hardcoded, that is confusing in case both base and top point to a single slot (e.g. function call with no arguments given). As a result of these changes red zone slots are dumped unconditionally on the top of the stack dump and top slot is unwound like the occupied slots are. The only artefact of the latter is the possible garbage printed as the top slot value. One can find the new example of output below: | (gdb) lj-stack L | ----------- Red zone: 5 slots ----------- | 0x40047fc0 [ ] VALUE: nil | 0x40047fb8 [ ] VALUE: nil | 0x40047fb0 [ ] VALUE: nil | 0x40047fa8 [ ] VALUE: nil | 0x40047fa0 [ ] VALUE: nil | ----------- Stack: 168 slots ----------- | 0x40047f98 [ M] VALUE: nil | 0x40047ae0:0x40047f90 [ ] 151 slots: Free stack slots | 0x40047ad8 [ BT ] VALUE: number 2.3873123941281106e-313 | 0x40047ad0 [ ] FRAME: [PP] delta=1, fast function #27 | 0x40047ac8 [ ] FRAME: [L] delta=7, fast function #20 | 0x40047ac0 [ ] VALUE: Lua function @ 0x400c00b0, 2 upvalues, "@builtin/box/console.lua":243 | 0x40047ab8 [ ] VALUE: nil | 0x40047ab0 [ ] VALUE: Lua function @ 0x4014bb78, 0 upvalues, "return collectgarbage()":0 | 0x40047aa8 [ ] VALUE: nil | 0x40047aa0 [ ] VALUE: string "collectgarbage()" @ 0x40116660 | 0x40047a98 [ ] VALUE: table @ 0x400c0f88 (asize: 0, hmask: 0x1) | 0x40047a90 [ ] FRAME: [LP] delta=3, Lua function @ 0x4014fe30, 3 upvalues, "@builtin/box/console.lua":379 | 0x40047a88 [ ] VALUE: string "collectgarbage()" @ 0x40116660 | 0x40047a80 [ ] VALUE: table @ 0x400c0f88 (asize: 0, hmask: 0x1) | 0x40047a78 [ ] FRAME: [L] delta=3, Lua function @ 0x40075aa8, 1 upvalues, "@builtin/box/console.lua":701 | 0x40047a70 [ ] VALUE: string "/home/imun" @ 0x400ff388 | 0x40047a68 [ ] VALUE: table @ 0x400c0f88 (asize: 0, hmask: 0x1) | 0x40047a60 [ ] FRAME: [CP] delta=1, Lua function @ 0x4014d0c8, 5 upvalues, "@builtin/box/console.lua":746 | 0x40047a58 [S ] FRAME: dummy L Signed-off-by: Igor Munkin --- src/luajit-gdb.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/luajit-gdb.py b/src/luajit-gdb.py index 4488775c..758ba10c 100644 --- a/src/luajit-gdb.py +++ b/src/luajit-gdb.py @@ -391,47 +391,49 @@ def dump_framelink(L, fr): f = dump_lj_tfunc(fr), ) -def dump_stack_slot(L, slot, base=None, top=None): +def dump_stack_slot(L, slot, base=None, top=None, eol='\n'): base = base or L['base'] top = top or L['top'] - return '{addr}{padding} [ {B}{T}{M}] VALUE: {value}\n'.format( + return '{addr}{padding} [ {B}{T}{M}] VALUE: {value}{eol}'.format( addr = strx64(slot), padding = PADDING, B = 'B' if slot == base else ' ', T = 'T' if slot == top else ' ', M = 'M' if slot == mref('TValue *', L['maxstack']) else ' ', value = dump_tvalue(slot), + eol = eol, ) def dump_stack(L, base=None, top=None): base = base or L['base'] top = top or L['top'] + stack = mref('TValue *', L['stack']) maxstack = mref('TValue *', L['maxstack']) red = 5 + 2 * LJ_FR2 dump = '\n'.join([ - '{start}:{end} [ ] {n} slots: Red zone'.format( - start = strx64(maxstack + 1), - end = strx64(maxstack + red), - n = red, + '{padding} Red zone: {nredslots: >2} slots {padding}'.format( + padding = '-' * len(PADDING), + nredslots = red, ), - '{maxstack}{padding} [ M]'.format( - maxstack = strx64(maxstack), - padding = PADDING, + *( + dump_stack_slot(L, maxstack + offset, base, top, '') + for offset in range(red, 0, -1) ), + '{padding} Stack: {nstackslots: >5} slots {padding}'.format( + padding = '-' * len(PADDING), + nstackslots = int((tou64(maxstack) - tou64(stack)) >> 3), + ), + dump_stack_slot(L, maxstack, base, top, ''), '{start}:{end} [ ] {nfreeslots} slots: Free stack slots'.format( start = strx64(top + 1), end = strx64(maxstack - 1), nfreeslots = int((tou64(maxstack) - tou64(top) - 8) >> 3), ), - '{top}{padding} [ T ]'.format( - top = strx64(top), - padding = PADDING, - ) ]) + '\n' - slot = top - 1 + slot = top framelink = base - (1 + LJ_FR2) # XXX: Lua stack unwinding algorithm consists of the following steps: @@ -447,7 +449,7 @@ def dump_stack(L, base=None, top=None): dump += dump_stack_slot(L, slot, base, top) slot -= 1 - while framelink > mref('TValue *', L['stack']): + while framelink > stack: assert slot == framelink + LJ_FR2, "Invalid slot during frame unwind" dump += dump_framelink(L, framelink) framelink = frame_prev(framelink + LJ_FR2) - LJ_FR2 -- 2.34.0