[ZeroBrane Studio] Re: Step In , Step Out in LUA

  • From: Paul K <paul@xxxxxxxxxxxxx>
  • To: zerobrane@xxxxxxxxxxxxx
  • Date: Sun, 24 Nov 2013 09:51:39 -0800

Hi Lucas,

ZeroBrane Studio is using Mobdebug debugger, which implements "step
in" and "step out" commands.

To answer your question, these commands work this way: the debugger
sets a line hook (using debug.sethook command), which then keeps track
of where in the script is the execution. When you run "step in"
command, it sets a flag to stop at the very next command. The hook
then checks for that flag
(https://github.com/pkulchenko/ZeroBraneStudio/blob/master/lualibs/mobdebug/mobdebug.lua#L514-L520;
the variable is step_into) and if it's set, it suspends the debugging
at that step.

"step out" is a bit more complex, but works in a similar way. When the
command is executed, the debugging keeps the current position in the
stack and only stops when the position in the stack is current-1. It
applies some logic to "fix" stack calculations in some cases and to
make it work for Lua and LuaJIT interpreters (see the explanation
here: 
https://github.com/pkulchenko/ZeroBraneStudio/blob/master/lualibs/mobdebug/mobdebug.lua#L451-L462).
It also checks for whether this code is running in a separate
coroutine as coroutines have their own stack.

Paul.

On Sun, Nov 24, 2013 at 8:08 AM, Lucas Saraiva
<lucassaraiva12@xxxxxxxxxxxx> wrote:
> Hello, my name is Lucas Scott student UFOP (Federal University of Ouro
> Preto) in the course of Information Systems.
> I have a project in a college laboratory (LEDs) made in 'lua' and 'wxlua',
> studying the software that you have created I saw that it has the function
> 'step in' 'step out'.
> For my project I need this feature and would like to know how you did this
> using only 'lua', took a look at the debug library 'lua' and I could not
> find anything.
>
> Thank you for your attention.

Other related posts: