[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Hooks, tailcalls and tracing LuaJIT
- From: Geoff Leyland <geoff_leyland@...>
- Date: Mon, 4 Apr 2011 14:30:37 +1200
Hi,
Thanks to a bad case of DFS [1] and NIH [2] I'm working on a line-by-line execution tracer and trace analyser [3].
It works pretty well so far with Lua - it can trace execution through Rima surviving tail calls/returns, resumes/yields and [x]pcalls/errors. Now I'm trying to get it to work with LuaJIT.
As documented [4], LuaJIT doesn't count tail calls, and consequently does not report tail returns to debug hooks. This makes tracing awkward.
It's possible to detect tail *calls* if you keep track of the stack depth, and notice when it doesn't change through a call, but to do this in general, you need to keep track of the stacks of all threads and be pcall/error aware. The trace *analyser* is smart enough to do that but I was hoping to keep the trace *collector* as simple as possible.
Has anyone got any bright ideas about how to detect tail calls or returns from the debug interface in LuaJIT? Any chance that LuaJIT could report tail returns like Lua does (without compromising performance)? Or that it could break the debug interface and add a hook argument for the "call" action that tells you whether the call is a tail call?
Cheers,
Geoff
[1] http://xkcd.com/761/
[2] http://en.wikipedia.org/wiki/Not_Invented_Here
[3] https://github.com/geoffleyland/luatrace
[4] http://luajit.org/status.html