[ANN] New GDB tools for setting breakpoints on Lua functions for LuaJIT v2.1

  • From: "Yichun Zhang (agentzh)" <agentzh@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx, openresty-en <openresty-en@xxxxxxxxxxxxxxxx>
  • Date: Sun, 21 Dec 2014 18:05:26 -0800

Hi folks

I've been working on some new GDB extension tools for setting GDB
breakpoints directly on Lua function call entries and returns
interpreted by LuaJIT v2.1.

The tools are opensourced at GitHub and are documented properly here:

    https://github.com/openresty/nginx-gdb-utils#lb

Basically the new "lb" command sets a breakpoint on the specified Lua
function call entries while "lrb" sets a breakpoint on Lua function
returns (except tail-calls). The "ldel" command can be used to remove
such breakpoints while the "linfob" can be used to view them.

Both the Lua function arguments and return values are inspected
automatically upon hitting the corresponding Lua-land breakpoints.

Right now, only interpreted Lua function callers atop LuaJIT v2.1 are
supported. JIT compiled callers are just silently ignored. But I do
have plans to add support for JIT compiled callers in the near future.

Both the stock "luajit" command-line utility and OpenResty/ngx_lua are
supported out of the box. Suupport for other LuaJIT-embedded
environment should be easy as well.

All these new GDB commands are written in Python [1] and can work with
any recent official GDB versions.

None of these GDB commands call any code in the inferior nor modify
any inferior data, so they are considered safe and should not crash
the target user processes at any rate.

No need to patch or rebuild LuaJIT, nor restart your LuaJIT-embedded
processes. Just attach to a running process with gdb and play!

I recently used these tools to successfully track down a weird bug in
one of our online Lua systems. So they should be quite usable already.

The existing "lbt" command [2] for dumping the current Lua backtrace
does not work very well at these Lua-land breakpoints yet. But I do
have plans to add support for that  in the near future as well.

We may also port these breakpoint tools over to the systemtap [3] and
ktap [4] dynamic tracing platforms in the future as well.

Feedback will be highly appreciated as always :)

Thanks!
-agentzh

[1] Alas. I'd rather write these tools in Lua but Python is currently
the only proper scripting language officially supported by GDB.
[2] https://github.com/openresty/nginx-gdb-utils#lbt
[3] https://sourceware.org/systemtap/
[4] http://www.ktap.org/

Other related posts:

  • » [ANN] New GDB tools for setting breakpoints on Lua functions for LuaJIT v2.1 - Yichun Zhang (agentzh)