Debugger.lua

I've spent a fair amount of time looking at the debug library in Lua. It's too much work to write my own debugger using it. (I'd have to debug the debugger.) There is an alternate solution that someone created known as debugger.lua.




Debugger.lua



Debugger.lua available on Git Hub at https://github.com/slembcke/debugger.lua Using debugger.lua is straight-forward. It comes with a good readme file as well as a tutorial. I'll just go through an overview of using the debugger.

To use it, you first have to place the debugger.lua file into your require path and then require it via:

local dbg = require("debugger")
-- Consider enabling auto_where to make stepping through code easier to follow.
dbg.auto_where
= 2

This is taken from the readme.

You can then call:

dbg()

to set a breakpoint. Once your code hits the breakpoint you can enter fairly standard commands to the debugger.

  • [return] - re-run last command
  • c(ontinue) - contiue execution
  • s(tep) - step forward by one line (into functions)
  • n(ext) - step forward by one line (skipping over functions)
  • p(rint) [expression] - execute the expression and print the result
  • f(inish) - step forward until exiting the current function
  • u(p) - move up the stack by one frame
  • d(own) - move down the stack by one frame
  • w(here) [line count] - print source code around the current line
  • t(race) - print the stack trace
  • l(ocals) - print the function arguments, locals and upvalues.
  • h(elp) - print this message
  • q(uit) - halt execution

If you've ever used a command-line debugger, this should feel very comfortable and familiar.

This is the debugger I've been looking for. It's simple to use, supported, and works the way I expect a debugger to work. Will I ever use the
debug library I learned about in the prior posts? Maybe, under certain situations, but I think debugger.lua will be my go-to.







This site does not track your information.