A GDB-like dynamic debugger for Lua programs on Linux.
中文文档 (Chinese) | Detailed Usage Guide
- Linux Platform Support: Designed for Linux environments.
- C++ Implementation: High performance with minimal overhead.
- Non-intrusive Dynamic Attach: Attaches directly to already running Lua processes without code modification.
- GDB-Style Debugging Interface:
- Breakpoints: Line breakpoints, function breakpoints, and conditional breakpoints. Flexible syntax supporting spaces (e.g.,
b file.lua:10,b file.lua 10,b file.lua : 10). - Execution Control: Next line (
n), step into (s), finish function (fin), continue (c), until (until/u). - Inspection & Evaluation: Stack backtrace (
bt), view/switch stack frames (f), inspect expressions (p), locals (i locals/i l), list source code (l). - Runtime Modification: Set local/upvalue/global variables (
set), execute arbitrary Lua snippets (r). - Breakpoint Management: Enable (
en), disable (dis), delete (d), temporary (tbreak/tb), inspect breakpoints (i b).
- Breakpoints: Line breakpoints, function breakpoints, and conditional breakpoints. Flexible syntax supporting spaces (e.g.,
- Linux OS (e.g., Ubuntu / Debian / CentOS)
- GCC / G++ supporting C++11 or higher
- GNU Readline development library (
libreadline-dev) - Lua 5.3+ headers and library
gdb(used to resolve Lua VM function addresses at attach time)- hookso binary (not vendored; no git submodule — CI checks out a pinned SHA)
- ptrace permission: if
/proc/sys/kernel/yama/ptrace_scopeis1, either run as the process owner with scope relaxed to0, or ensure Yama allows the attach (otherwise hookso/gdb cannot attach)
- Clone the repository:
git clone https://github.com/esrrhs/dLua.git cd dLua - Run
build.shto compiledlua(frontend CLI),dluaagent.so(debugger agent), andtest_unit:./build.sh
- Run unit tests to verify:
./test_unit
- Build or download hookso and make it discoverable (see Runtime path lookup below). Typical local layout: place
hooksonext todlua/dluaagent.so.
dlua does not use a git submodule. It resolves tools at runtime:
hookso (resolve_hookso / g_hookso):
$DLUA_HOOKSOif executabledirname(/proc/self/exe)/hookso./hooksohooksoonPATH
Failure lists every location tried on stderr.
dluaagent.so (absolute path for dlopen):
$DLUA_AGENTdirname(exe)/dluaagent.so./dluaagent.so
After inject, hookso call still uses the soname dluaagent.so.
# With hookso beside the build products (or DLUA_HOOKSO / DLUA_AGENT set):
./scripts/smoke_attach.shThis is a hookso-level inject check (no readline/expect): start lua test.lua, argp/triggerp dlopen → start/stop → dlclose, assert maps / call success.
- Single Lua state per attach:
dluaattaches to onelua_State*discovered from the target process. Processes that create multiple Lua states are only debugged for the state that was found at attach time; switch/reattach is required to debug another state. - Linux + hookso + gdb: Dynamic attach relies on hookso and
gdbfor address lookup; hookso is resolved at runtime (not packaged as a submodule). - Source path matching: Breakpoints match Lua
short_srcwith basename/suffix rules; prefer paths that appear inbtwhen ambiguous.
-
Start your target Lua process:
lua test.lua
Assume PID is
1234. -
Launch
dluaand attach to the target PID:./dlua 1234
When connected:
attach to 1234 ok, use ctrl+c to input command, eg: h -
Press
Ctrl+Cto interrupt execution and enter commands. For example:(dlua) b test.lua 23 (dlua) bt (dlua) p year (dlua) c (dlua) q
For full command references, detailed options, and examples, please see usage.md.
GDB-style long command aliases, up/down, frame, info frame and info args are supported; see usage for syntax and limits.
One-shot attach: dlua --batch -ex bt -p PID. Command files: dlua --batch -x inspect.dlua -p PID or interactive source FILE. See usage for supported commands, exit codes and safety limits.
Command files/batch now support step, next, continue, until, finish,
breakpoint edits, condition N [EXPR], set and r, with explicit completion at
real stops and bounded hook-driven waits. Use info upvalues and lexical Lua
print expressions. Reachable pre-existing/dormant coroutine hooks are tracked
and restored; dead-client leases clean up at the next VM hook. Discovery is
bounded, independent states remain serialized, and the agent is not dlclosed.
See usage for exact safety limits and expression side effects.
dlua --doctor diagnoses dependencies/ptrace; dlua --version identifies builds.
./scripts/package.sh creates a versioned archive and ./scripts/install.sh PREFIX
installs without sudo. CI now covers true attach/batch on both Lua 5.3/5.4,
version-labelled artifacts, verified cached downloads and no external usleep.