<HTML><BODY><div class="cl-g9ujor93tf"><div>Hi, Sergey! Thanks for the patch!</div><div> </div><div>I tried the tests under Ubuntu 20.04 and Ubuntu 24.04 with gcc and clang LuaJIT builds:</div><div> </div><div>1) Ubuntu 20 + gcc: all tests were passed.</div><div>2) Ubuntu 20 + clang: some of gdb and lldb tests were failed.<div><div><div>3) Ubuntu 24 + gcc: some of lldb tests were failed.</div><div>4) Ubuntu 24 + clang: some of gdb and lldb tests were failed.</div></div></div><br> </div><div data-signature-widget="container"><div data-signature-widget="content"><div>--<br>Best regards,</div><div>Evgeniy Temirgaleev</div></div></div><br><div class="mail-quote-collapse"><blockquote style="border-left:1px solid #0857A6;margin:10px;padding:0 0 0 10px"><span>From: Sergey Kaplun <<a href="mailto:skaplun@tarantool.org">skaplun@tarantool.org</a>><br>To: Sergey Bronnikov <<a href="mailto:sergeyb@tarantool.org">sergeyb@tarantool.org</a>>, Evgeniy Temirgaleev <<a href="mailto:e.temirgaleev@tarantool.org">e.temirgaleev@tarantool.org</a>><br>Cc: tarantool-patches@dev.tarantool.org, Sergey Kaplun <<a href="mailto:skaplun@tarantool.org">skaplun@tarantool.org</a>><br>Date: Thursday, June 4, 2026 12:31 PM +03:00</span><br> <div><div id=""><div class="cl-jtafqhlttt"><div class="js-helper_mr_css_attr js-readmsg-msg_mr_css_attr"><div id="style_17805654901972613236_mr_css_attr"><div id="style_17805654901972613236_BODY_mr_css_attr">Branch: <a href="https://github.com/tarantool/luajit/tree/skaplun/gh-4808-gco-func-proto-bytecode">https://github.com/tarantool/luajit/tree/skaplun/gh-4808-gco-func-proto-bytecode</a><br>Issue: <a href="https://github.com/tarantool/tarantool/issues/4808">https://github.com/tarantool/tarantool/issues/4808</a><br><br>This patch set allows you to inspect bytecodes for a single instruction,<br>as well as for all bytecodes inside a function or its prototype via GDB<br>and LLDB.<br><br>The first patch is a fixup for the LLDB indexing negative values. It may<br>affect the lj-stack command. The second patch fixes the DUALNUM mode<br>detection in LLDB. These fixes are required for the last patch in the<br>series.<br><br>The third auxiliary patch is needed to introduce dumpers for GC objects<br>similar to TValues dumpers. Also, it may be useful during different<br>debugging scenarios, so it introduces the lj-gco <GCobj *> command to<br>dump the GC object info in the same format as for a TValue slot.<br><br>The last patch introduces 3 new commands:<br>* lj-bc <GCIns *> -- dump single bytecode instruction<br>* lj-func <GCfunc *> -- dump all bytecode instructions for Lua function<br>or report type of C or F function<br>* lj-proto <GCproto *> -- dump all bytecode instructions for the<br>prototype<br><br>For example, we have the following Lua script named <tmp.lua>:<br><br>| 1 local function mywhile(a)<br>| 2 local r = 0<br>| 3 print(a)<br>| 4 while (a < 30) do<br>| 5 r = r + a * r/2<br>| 6 end<br>| 7 return r<br>| 8 end<br>| 9<br>| 10 local uvname1 = false<br>| 11 local uvname2 = false<br>| 12 local function myif(a)<br>| 13 local s1 = a + 4<br>| 14 local s2 = s1 + 4<br>| 15 uvname1 = "s10"<br>| 16 uvname2 = "s11"<br>| 17 print(a)<br>| 18 if a > 10 then<br>| 19 return a + s2 + s1<br>| 20 else<br>| 21 return a - 10 - s2 - s1<br>| 22 end<br>| 23 end<br>| 24<br>| 25 local f1 = myif<br>| 26 local f2 = mywhile<br>| 27 myif(12)<br>| 28 mywhile(12)<br><br>Assume we set a breakpoint at `lj_cf_print` (line 3).<br>The lj-stack output contains the following lines:<br><br>| 0x40001970 [ ] VALUE: Lua function @ 0x400083c0, 0 upvalues, "@../tmp.lua":1<br>| 0x40001968 [ ] VALUE: Lua function @ 0x40002148, 2 upvalues, "@../tmp.lua":12<br>| ...<br>| 0x40001940 [ ] FRAME: [V] delta=1, Lua function @ 0x400084a0, 0 upvalues, "@../tmp.lua":0<br><br>The first one is `myif()` function the second is `mywhile()` and the<br>last one is function loaded via `dofile()`.<br><br>The resulting output for the functions is the following:<br><br>1)<br>| (gdb) lj-func 0x400083c0<br>| "@../tmp.lua":1-8<br>| 0000 FUNCF rbase: 4<br>| 0001 KSHORT dst: 1 lits: 0<br>| 0002 GGET dst: 2 str: 0 ; string "print" @ 0x400037f0<br>| 0003 MOV dst: 3 var: 0<br>| 0004 CALL base: 2 lit: 1 lit: 2<br>| 0005 KSHORT dst: 2 lits: 30<br>| 0006 ISGE var: 0 var: 2<br>| 0007 JMP rbase: 2 jump: => 0013<br>| 0008 LOOP rbase: 2 jump: => 0013<br>| 0009 MULVV dst: 2 var: 0 var: 1<br>| 0010 DIVVN dst: 2 var: 2 num: 0 ; number 2<br>| 0011 ADDVV dst: 1 var: 1 var: 2<br>| 0012 JMP rbase: 2 jump: => 0005<br>| 0013 RET1 rbase: 1 lit: 2<br><br>The report is the same as for the following command:<br>| lj-proto (GCproto *)(((char *)(((GCfuncL *)0x400083c0)->pc.ptr32))-sizeof(GCproto))<br><br>2)<br>| (gdb) lj-func 0x40002148<br>| "@../tmp.lua":12-23<br>| 0000 FUNCF rbase: 5<br>| 0001 ADDVN dst: 1 var: 0 num: 0 ; number 4<br>| 0002 ADDVN dst: 2 var: 1 num: 0 ; number 4<br>| 0003 USETS uv: 0 str: 0 ; 0x40002527 "uvname1" ; string "s10" @ 0x40002298<br>| 0004 USETS uv: 1 str: 1 ; 0x4000252f "uvname2" ; string "s11" @ 0x400022b8<br>| 0005 GGET dst: 3 str: 2 ; string "print" @ 0x400037f0<br>| 0006 MOV dst: 4 var: 0<br>| 0007 CALL base: 3 lit: 1 lit: 2<br>| 0008 KSHORT dst: 3 lits: 10<br>| 0009 ISGE var: 3 var: 0<br>| 0010 JMP rbase: 3 jump: => 0015<br>| 0011 ADDVV dst: 3 var: 0 var: 2<br>| 0012 ADDVV dst: 3 var: 3 var: 1<br>| 0013 RET1 rbase: 3 lit: 2<br>| 0014 JMP rbase: 3 jump: => 0019<br>| 0015 SUBVN dst: 3 var: 0 num: 1 ; number 10<br>| 0016 SUBVV dst: 3 var: 3 var: 2<br>| 0017 SUBVV dst: 3 var: 3 var: 1<br>| 0018 RET1 rbase: 3 lit: 2<br>| 0019 RET0 rbase: 0 lit: 1<br><br>3)<br><br>| (gdb) lj-func 0x400084a0<br>| "@../tmp.lua":0-30<br>| 0000 FUNCV rbase: 8<br>| 0001 FNEW dst: 0 func: 0 ; "@../tmp.lua":1<br>| 0002 KPRI dst: 1 pri: 1<br>| 0003 KPRI dst: 2 pri: 1<br>| 0004 FNEW dst: 3 func: 1 ; "@../tmp.lua":12<br>| 0005 MOV dst: 4 var: 3<br>| 0006 MOV dst: 5 var: 0<br>| 0007 MOV dst: 6 var: 3<br>| 0008 KSHORT dst: 7 lits: 12<br>| 0009 CALL base: 6 lit: 1 lit: 2<br>| 0010 MOV dst: 6 var: 0<br>| 0011 KSHORT dst: 7 lits: 12<br>| 0012 CALL base: 6 lit: 1 lit: 2<br>| 0013 UCLO rbase: 0 jump: => 0014<br>| 0014 RET0 rbase: 0 lit: 1<br><br>The single bytecode instruction may be useful when you debug the VM:<br><br>| (gdb) b lj_BC_ISGE<br>| Breakpoint 2 at 0x5555555f0a08<br>| (gdb) c<br>| Continuing.<br>| Breakpoint 2, 0x00005555555f0a08 in lj_BC_ISGE ()<br>| (gdb) lj-bc $rbx # PC refers __the next instruction__<br>| JMP rbase: 3 jump: +5<br>| (gdb) lj-bc ((BCIns *)$rbx) - 1 # current instruction<br>| ISGE var: 3 var: 0<br><br><br>Sergey Kaplun (4):<br>dbg: fix lj-stack command for LLDB<br>dbg: fix DUALNUM detection for LLDB<br>dbg: introduce lj-gco command<br>dbg: introduce lj-bc, lj-func and lj-proto dumpers<br><br>src/luajit_dbg.py | 650 ++++++++++++++++--<br>.../debug-extension-tests.py | 203 +++++-<br>2 files changed, 757 insertions(+), 96 deletions(-)<br><br>--<br>2.54.0</div></div></div></div></div></div></blockquote></div></div></BODY></HTML>