From: Igor Munkin via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: Sergey Kaplun <skaplun@tarantool.org>, Maxim Kokryashkin <m.kokryashkin@tarantool.org> Cc: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH 1/2] gdb: unwind Lua stack top part Date: Tue, 1 Feb 2022 00:33:54 +0300 [thread overview] Message-ID: <0868c62b88c5c39f30b052191d489671be7afc20.1643645066.git.imun@tarantool.org> (raw) In-Reply-To: <cover.1643645066.git.imun@tarantool.org> 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 <lj-stack> 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 <lj-tv> 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 <lj-stack> 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 <imun@tarantool.org> --- 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
next prev parent reply other threads:[~2022-01-31 21:37 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-01-31 21:33 [Tarantool-patches] [PATCH 0/2] Minor enhancements in luajit-gdb.py Igor Munkin via Tarantool-patches 2022-01-31 21:33 ` Igor Munkin via Tarantool-patches [this message] 2022-02-09 10:14 ` [Tarantool-patches] [PATCH 1/2] gdb: unwind Lua stack top part Sergey Kaplun via Tarantool-patches 2022-02-09 18:02 ` Maxim Kokryashkin via Tarantool-patches 2022-02-11 19:11 ` Igor Munkin via Tarantool-patches 2022-02-11 19:11 ` Igor Munkin via Tarantool-patches 2022-01-31 21:33 ` [Tarantool-patches] [PATCH 2/2] gdb: add mmudata value to lj-gc output Igor Munkin via Tarantool-patches 2022-02-09 10:29 ` Sergey Kaplun via Tarantool-patches 2022-02-09 18:11 ` Maxim Kokryashkin via Tarantool-patches 2022-02-11 19:12 ` Igor Munkin via Tarantool-patches 2022-02-11 19:12 ` Igor Munkin via Tarantool-patches 2022-02-01 10:17 ` [Tarantool-patches] [PATCH 0/2] Minor enhancements in luajit-gdb.py Igor Munkin via Tarantool-patches 2022-02-11 20:42 ` Igor Munkin via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=0868c62b88c5c39f30b052191d489671be7afc20.1643645066.git.imun@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=imun@tarantool.org \ --cc=m.kokryashkin@tarantool.org \ --cc=skaplun@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 1/2] gdb: unwind Lua stack top part' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox