[ZeroBrane Studio] Re: debug lua on an embedded micro

  • From: "Steve Russell" <steve.russell@xxxxxxxxxxxxxxxxxxxxx>
  • To: <zerobrane@xxxxxxxxxxxxx>
  • Date: Wed, 17 Sep 2014 09:58:27 +0100

Hi,

 

I see that option now – it is available when a breakpoint is hit.  Having done 
this, my script does not continue. The error is:

 

Test.lua:18: cannot resume dead coroutine

 

Line 18 is where it’d halted at a breakpoint when I detached.

 

Adding the line “os.exit = require('mobdebug').done” did behave better though, 
allowing me to use the stop button to detach & allow me script to continue.  I 
could repeatedly start my script & stop the debug in this way.

 

Whilst the debugger was stopped I stopped the debug server in ZB and got into 
all sorts of mess in the script when I tried restarting - errors stating the 
debugger had unexpectedly gone and then moddebug errors & then a hanging app.

 

I’m thinking of implementing the two lines needed for debug in C++ when I 
create the Lua VM so my end users do not need to add these lines to their 
script.  Is there any reason why these debug lines should not be left in a 
script all the time? Are there any overheads?  I’m thinking it’s just a slight 
start up overhead when looking for a debug server.

 

Steve

 

From: zerobrane-bounce@xxxxxxxxxxxxx [mailto:zerobrane-bounce@xxxxxxxxxxxxx] On 
Behalf Of Paul K
Sent: 16 September 2014 19:01
To: zerobrane@xxxxxxxxxxxxx
Subject: [ZeroBrane Studio] Re: debug lua on an embedded micro

 

Hi Steve,

 

> Is there a correct procedure for stopping a debug session.  I was mid 
> debugging a Lua function call run() but when I stop debugging (Shift+F5) or 
> stop the server in ZB, my application crashes.  I think Lua is calling 
> os_exit() and causing my app to quit unceremoniously (which I can probably 
> tidy up).  But why would Lua try to quit?

 

Yes, starting from v0.70 ZBS includes "Project | Detach process" (also on the 
toolbar on the right side next to Stop). This will stop debugging, but will 
continue the process without "killing" it.

 

Another option that I use for environments like this is to set "os.exit = 
require('mobdebug').done" in your application after "require('mobdebug')", 
which will have the same effect as described above when you hit "Stop 
debugging" in the IDE.

 

In a similar way you can change os.exit to some more complex code that will 
stop debugging (using done() and then do whatever graceful shutdown you need to 
do in your application).

 

Paul.

 

Other related posts: