Discussion:
Stack frame restart
Denis Golovan
2014-09-21 19:01:16 UTC
Permalink
Hi all

I am wondering, is it possible to create/simulate/force LuaJIT restart
current stack frame?

What I mean by that is something similar to some Common Lisp/APL
implementations have.

That is roughly following set of actions:
- setting a breakpoint inside some function
- waiting for it to trigger "debugger"
- change/recompile current function code
- and finally restart current stack frame using function new body
without restarting the entire stack/all related functions.

That thing is actually a killer feature...

BR,
Denis
Elias Hogstvedt
2014-09-21 19:43:18 UTC
Permalink
You can sort of simulate "break" by calling a function which would do an
infinite loop. Using this with debug.sethook and you can step to the next
line.

As for jumping back or restarting you could maybe call the function you're
in again (using debug.getinfo) with the same arguments (using
debug.getlocal) but this sounds very hacky and unreliable. I'm not sure if
the debug library is 100% in luajit but I do know that you need to disable
jit compilation to get an accurate call stack.
Post by Denis Golovan
Hi all
I am wondering, is it possible to create/simulate/force LuaJIT restart
current stack frame?
What I mean by that is something similar to some Common Lisp/APL
implementations have.
- setting a breakpoint inside some function
- waiting for it to trigger "debugger"
- change/recompile current function code
- and finally restart current stack frame using function new body
without restarting the entire stack/all related functions.
That thing is actually a killer feature...
BR,
Denis
Denis Golovan
2014-09-21 20:06:08 UTC
Permalink
Well.
Yes, I saw that debug thing. And yes, that seems to be a quite simple
task to step _forward_.

The real difficulty is to replace/restart current stack frame with
completely new set of local vars and let VM continue later. Just
calling the new/modified function is not enough.

Actually, I was even about to write a macro-like wrapper for functions
having "break" inside them. Conceptually it is just a (x)pcall
catching specially crafted error "exception" and restarting a stack
frame. But then I decided to ask the community :)
Post by Elias Hogstvedt
You can sort of simulate "break" by calling a function which would do an
infinite loop. Using this with debug.sethook and you can step to the next
line.
As for jumping back or restarting you could maybe call the function you're
in again (using debug.getinfo) with the same arguments (using
debug.getlocal) but this sounds very hacky and unreliable. I'm not sure if
the debug library is 100% in luajit but I do know that you need to disable
jit compilation to get an accurate call stack.
Post by Denis Golovan
Hi all
I am wondering, is it possible to create/simulate/force LuaJIT restart
current stack frame?
What I mean by that is something similar to some Common Lisp/APL
implementations have.
- setting a breakpoint inside some function
- waiting for it to trigger "debugger"
- change/recompile current function code
- and finally restart current stack frame using function new body
without restarting the entire stack/all related functions.
That thing is actually a killer feature...
BR,
Denis
Loading...