lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

Eike Decker wrote:
> Well, but how else could I write a debugger that allows setting
> breakpoints in lua files?

The most efficient thing to do, is to only set the CALL/RETURN
hooks at first. Then whenever your hook is called, you only
lookup the function, since lua_getinfo(L, "f", &ar) is cheap.

Use the function object as a key for a weak keyed table which
stores whether this is a function which has a breakpoint set. If
the entry is nil, then lookup the file name and line number range
info (the expensive calls to lua_getinfo()). If it's a target
function, store true, else store false (negative caching). Now,
you have a cheap way to check whether you are entering a function
which has a breakpoint set.

So, whenever this is the case, activate the (sloooow) line hook,
too. Then just wait until the line is hit. Of course you need to
check whether the function has returned or a another one has been
called and (de)activate the line hook on-the-fly. You'll probably
need special handling for tailcalls (note: different behaviour
with LuaJIT) and errors.

Of course whenever the set of breakpoints changes, you need to
invalidate the cache (just flush it, it'll rebuild quickly).

Bye,
     Mike