How to debug Lua state with GDB - AnaNek/tarantool GitHub Wiki

Clone openresty-gdb-utils to, say, ~/tools/openresty/openresty-gdb-utils.

Apply the patch:

diff --git a/luajit21.py b/luajit21.py
index 7728ac4..333d378 100644
--- a/luajit21.py
+++ b/luajit21.py
@@ -113,6 +113,10 @@ def get_global_L():
     if gL:
         return gL.value()
 
+    gL, _ = gdb.lookup_symbol("tarantool_L")
+    if gL:
+        return gL.value()
+
     cycle = gdb.lookup_global_symbol("ngx_cycle")
     if cycle:
         cycle = cycle.value()

Enable openresty-gdb-utils in ~/.gdbinit (replace USER with your username in two places below):

# {{{ openresty-gdb-utils

# https://github.com/openresty/openresty-gdb-utils/tree/5838a8ee2df67f3098e4cf63156fe99ee3be0349#installation

directory /home/USER/tools/openresty/openresty-gdb-utils

py import sys
py sys.path.append("/home/USER/tools/openresty/openresty-gdb-utils")

source luajit20.gdb
source ngx-lua.gdb
source luajit21.py
source ngx-raw-req.py
set python print-stack full

# }}}

Use lbt (lua backtrace):

$ gdb tarantool
(gdb) run
tarantool> function foo() require('fiber').sleep(100) end
tarantool> foo()
Ctrl+C
(gdb) lbt
C:lbox_fiber_sleep
function foo()
    require('fiber').sleep(100)
end:2
builtin#20
@builtin/box/console.lua:153
@builtin/box/console.lua:409
@builtin/box/console.lua:458

Use lval (Lua value) when looking into a core file:

# Say, we have a Lua stack of an iproto request in `port` variable.
# It is usual for tx_process_call() stack frame when a Lua function
# is called.
(gdb) set $L=((struct port_lua) port)->L
(gdb) $L->top
<...>
(gdb) $L->top+1
<...>
⚠️ **GitHub.com Fallback** ⚠️