dbghelper: a debugging helper module for lua
What is it?
dbghelper is a module for lua 5.1 and 5.2 to aid debugging of lua programs. It injects a function resumeuntil into the debug table, which can resume a coroutine until a debug event occurs or the coroutine yields or returns.
cr = coroutine.create(function_to_debug)
ok, what = debug.resumeuntil(cr, mask, count, ...)
- coroutine to debug
- mask, count
- as for debug.sethook
- extra arguments to pass to the coroutine resume function (only use if the coroutine has yielded or on the first call)
- true if the coroutine can be resumed, false if not
- event that caused resumeuntil to return, can be any one of
- 'line', 'count', 'call', 'tail call', 'return', 'tail return' or 'yield' if ok is true,
- 'return' or 'error' if ok is false.
- the mask and count arguments can be nil. If both are nil, resumeuntil will just resume the coroutine until it returns, yields or throws an error.
- if an error occurred, the error message is returned as the third return value from resumeuntil
- if ok and what are true and 'yield', the debugged function has yielded and arguments passed to yield are returned as third and following return values from resumeuntil
- if ok and what are false and 'return', the debugged function has returned and any return values are returned as third and following return values from resumeuntil
- if ok is true and what is anything but 'yield', this signals that the corresponding debug hook has been invoked.
- only lua 5.1 will return 'tail return', only lua 5.2 will return 'tail call'.
Look at the included dbgtest.lua for some examples.
Download and building
You can get dbghelper-0.2 by clicking on this link.
The module source comes with a makefile. It tries to discover what version of lua you are using and where your include files are, but may not be too smart at that. Also, you need access to lua's source tree, especially lstate.h, to compile this. The location must be changed in the makefile.
The dbghelper module and all accompanying documentation and additional source code is released under the MIT/X11 license.
Copyright (c) 2012 Gunnar Zötl
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
If you have anything to say about this, comments, bug reports, whatever, feel free to email them to