Re: Debug hooks and JIT

  • From: Alex <initrd.gz@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 15 Oct 2012 14:26:41 -0400

Yea, looking back on it now, I can see why a global hook would be better
for the debug library's intended usage. I only asked because I am making a
sandbox system (specifically for Garry's Mod, which is moving to LuaJIT)
with a perf limiter and debug hooks that only function in each
coroutine-encapsulated sandbox would allow me to easily separate out the
perf counters.

(Before anyone says anything, yes, I am aware that counting operations
using a debug hook isn't perfect and has exploits, but it is mostly meant
for catching runaway scripts, and any other system is more or less
impossible in my use case)

On Mon, Oct 15, 2012 at 8:36 AM, Mike Pall <mike-1210@xxxxxxxxxx> wrote:

> Alex wrote:
> > While on the subject, what is preventing per-coroutine debug hooks? Would
> > it be possible to make them work with the JIT compiler off?
>
> The Lua interpreter checks for hooks before every executed
> bytecode. The LuaJIT interpreter modifies the whole dispatch table
> for the interpreter instead and doesn't need to check for hooks at
> all. This means hooks are zero-cost, if not enabled.
>
> Enabling and disabling hooks per coroutine would mean aggregating
> the individual settings of all coroutines: e.g. some may have only
> call hooks, others have instructions hooks and the remainder has
> none. Different parts of the dispatch table would need to be
> patched or not, depending on a lot of factors. That's just too
> messy, so I didn't bother.
>
> IMHO per-coroutine hooks are a misfeature. Basically everyone who
> ever wrote a half-decent debugger or profiler for Lua didn't like
> the idea either (see Geoff's posting for some of the problems).
>
> --Mike
>
>

Other related posts: