[SOLVED] Debugging using ZeroBrane Studio

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
randomnovice
Party member
Posts: 126
Joined: Sat May 09, 2015 9:15 pm

[SOLVED] Debugging using ZeroBrane Studio

Post by randomnovice »

Hi folks,

I'm running into an occasional spinning wheel of death bug (infinite loop somewhere!?) and my programme is long enough and (probably unnecessarily) complicated enough that it's not easy to spot exactly where/how.

I wrote it using TextEdit before discovering the wonders of ZeroBrane (which is fab btw).

I think ZeroBrane will allow me to evaluate variables etc. in real (run)time, but I haven't yet understood how. I've looked at some blogs & posts on this and have managed to activate the print command to print live (rather than after the programme finishes) which is helpful but I believe it should be possible to do more i.e. ask to evaluate variables during operation.

What would I love to do is when the spinning wheel bug comes up, ask some questions of the programme and see if I can discover how it ended up like that. Or it would also be helpful to know what line of code it is attempting to execute.

I think there is a way to run the programme step-by-step, waiting each time before continuing, but this isn't much good to me as it runs thousands of iterations before any bug ever crops up (and the bug appears to be sporadic).

Thanks in advance!
Last edited by randomnovice on Sun Jun 18, 2017 4:35 pm, edited 1 time in total.
User avatar
artofwork
Citizen
Posts: 91
Joined: Mon Sep 15, 2014 1:17 am
Location: East Coast USA

Re: Debugging using ZeroBrane Studio

Post by artofwork »

I don't debug a program by using the debugger I usually test a program step by step, testing each value as I go and if i run into an issue i'll comment out all the code until i find what is causing the issue.

The only time data is printed the console or written to file is when you tell it to do so. There is no magical method in existence which will execute print unless you program a procedure or method that does just that.

Based on your question I think you need to take a moment of your time and learn lua from the ground up because knowing the behavior of print and even io.write is something most of us who do know the language having been using since day one of learning it.
alloyed
Citizen
Posts: 80
Joined: Thu May 28, 2015 8:45 pm
Contact:

Re: Debugging using ZeroBrane Studio

Post by alloyed »

So when I'm writing something that could be an infinite loop I use something the following function

Code: Select all

local function safe_iter(max_iters)
    max_iters = max_iters or 10000
    local i = 0
    return function()
        i = i + 1
        if i > max_iters then error("iteration limit reached") end
    end
end
use like so

Code: Select all

local incr = safe_iter()
while true do
    incr()
end
and this catches infinite loops before they kill my computer, with a nice stack trace
To know when you might be writing an infinite loop, look for while/repeat loops, or functions that call themselves (aka recursive functions). sometimes, a function can call itself in a roundabout way, for example a() -> b() -> c() -> a(). This is harder to debug, and I don't have really great answers for it that aren't complex, so my suggestion would be to try to avoid the situation entirely. This is not amazing advice but hopefully this gives you something to look for?
randomnovice
Party member
Posts: 126
Joined: Sat May 09, 2015 9:15 pm

Re: Debugging using ZeroBrane Studio

Post by randomnovice »

Thanks both,
The problem with testing step-by-step is in this case it's an AI and the issue is sporadic. Sometimes it runs absolutely fine multiple times in a row. Other times the AI just gets stuck somewhere.
I'll just have to re-check all the loops and try to find one that could somehow get stuck.
Like I said - even being able to know what line was attempting to be executed when you stop the programme would be super helpful if such a thing existed.
brucejs777
Prole
Posts: 6
Joined: Wed Jun 14, 2017 8:06 am

Re: Debugging using ZeroBrane Studio

Post by brucejs777 »

I'd like to get the LOVE debugging to work as well. Debug facility exist for good reason, and I've found it indispensable over the years for efficient and effective debuging.
ZeroBrane can debug Lua programs when the interpreter is set to Lua. But it seems to lose it's debug facility when the interpreter is set to LOVE. Perhaps there is a different way to set up the build so as to run in Lua interpreter mode, yet use LOVE as a library ?
User avatar
easy82
Party member
Posts: 184
Joined: Thu Apr 18, 2013 10:46 pm
Location: Hungary

Re: Debugging using ZeroBrane Studio

Post by easy82 »

Hello guys. I think you are missing 1 line of code:
http://notebook.kulchenko.com/zerobrane ... -debugging
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Debugging using ZeroBrane Studio

Post by zorg »

easy82 wrote: Sat Jun 17, 2017 9:21 pm Hello guys. I think you are missing 1 line of code:
http://notebook.kulchenko.com/zerobrane ... -debugging
Don't be afraid to be more specific! (Hadd érezzék a törődést) :3
Paul on the zerobrane site wrote:Add if arg[#arg] == "-debug" then require("mobdebug").start() end line to your script somewhere inside love.load(arg) function. This will allow you to use Project | Run command to run the application and Project | Start Debugging to debug your application.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
randomnovice
Party member
Posts: 126
Joined: Sat May 09, 2015 9:15 pm

Re: Debugging using ZeroBrane Studio

Post by randomnovice »

Thanks both. I did try that line before but I actually get an error:

Error
main.ua:64: attempt to get length of local 'arg' (a nil value)

Traceback

main.lua:64: in function 'load'
main.lua:8: in function <main.lua:3>
[C]: in funtion 'xpcall'
randomnovice
Party member
Posts: 126
Joined: Sat May 09, 2015 9:15 pm

Re: Debugging using ZeroBrane Studio

Post by randomnovice »

Shall I change the call of
love.load()

in love.run() to

love.load({"-debug"}) ??
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Debugging using ZeroBrane Studio

Post by zorg »

You don't call love.load yourself, you define it, it's a callback.

In love.run, it should look like this:

Code: Select all

if love.load then love.load(arg) end
In your main.lua or whatever, this should work, though i never used zerobrane:

Code: Select all

function love.load(arg)
    if arg[#arg] == "-debug" then require("mobdebug").start() end
end
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 4 guests