Debugging Support for Lua

Home Forums General Programming Debugging Support for Lua

Tagged: 

Viewing 20 posts - 1 through 20 (of 37 total)
  • Author
    Posts
  • #29410
    synth
    Participant
    • Topics: 13
    • Replies: 35
    • Total: 48

    Hi,

    Is there any debugging support for Lua in Ctrlr apart from console() ? For example can we :

    1. Set breakpoints in Lua code ?
    2. Watch variable values ?
    3. Step through code ?

    If not then does the lua bind library support adding these features ?

    #29414
    atom
    Keymaster
    • Topics: 159
    • Replies: 2945
    • Total: 3104
    • ★★★★★

    nope, and i didn’t see any possibility to do that ever.

    #29425
    atom
    Keymaster
    • Topics: 159
    • Replies: 2945
    • Total: 3104
    • ★★★★★

    Just to follow up.

    I tried adding debugging for some time but always ended up with a problems bigger then i was able to solve, i’ll approach the problem again with the knowledge i have today.

    Someone asked if you can replace lua with luaOO or luaJIT, you need to recompile Ctrlr, remove lua.c from the sources and add you own lua version (lua.c is the amalgamation of lua 5.1 sources), you could leave the headers and just link with whatever dynamic library provides the needed lua engine. But it can’t be done at runtime and you need to recompile Ctrlr.

    #29498
    synth
    Participant
    • Topics: 13
    • Replies: 35
    • Total: 48

    I was wondering if an external editor with remote debugging capabilities like ZeroBrane https://studio.zerobrane.com/features.html

    …could be supported by Ctrlr. Zerobrane has the ability to connect to a running Lua interpreter that has debugging support. If the Lua interpreter itself is compiled with Lua debugging support then it opens a socket to which an external debugger can connect.

    So the idea would be that breakpoints are set in the Lua code in an external debugger. Then when the breakpoints are hit then the lua interpretor is frozen in Ctrlr and the user can examine the stack, variables etc.

    The source code info would need to be conveyed to the external debugger of course so we would need the source code to be available in a file. Perhaps the lua methods for a panel can be read from a .lua file instead of being read from the .panel file. Then this file can simply be dropped into the external IDE/debugger.

    Furthermore code editing can be done there too and whenever the user saves the file, the file can be compiled into Ctrlr by CtrlrLuaManager.

    Of course before this we need to move Ctrlr to LuaJIT.

    #29508
    atom
    Keymaster
    • Topics: 159
    • Replies: 2945
    • Total: 3104
    • ★★★★★

    To do that, i need to add LuaSocket support to the current lua source. I have that planned once i’m done with lookandfeel stuff. I’m not sure if i need to change something to explicitly activate the debugging api in lua, i think it might be there already http://www.lua.org/pil/23.html

    #30160
    synth
    Participant
    • Topics: 13
    • Replies: 35
    • Total: 48

    I see that you added luasocket in https://github.com/RomanKubiak/ctrlr/commit/86a1b7e21dc2e40e535b71990126f5230b681dff

    I am yet to test this out, but does the debug library show stack traces and allow stepping through the code in Ctrlr now ?

    #30164
    atom
    Keymaster
    • Topics: 159
    • Replies: 2945
    • Total: 3104
    • ★★★★★

    Yes luasocket is there (untested so far), and the native “debug” library is activated, what it can do is written here: http://www.lua.org/pil/23.html

    a left this for now to fix the lookandfeel stuff but i’ll get back to it to see what it can do, and if we need to add an external debugger like RemDebug or ModDebug

    #30343
    synth
    Participant
    • Topics: 13
    • Replies: 35
    • Total: 48

    So I added a .lua file to one of my panels today with the following contents :

    
    --
    --
    --
    require('mobdebug').start()
    
    function testme()
        console("Test me called")
    end
    

    This is as given in http://studio.zerobrane.com/doc-remote-debugging.html

    It seems mobdebug is needed. I am not sure though if only the luasocket and mobdebug from Zerobrane works, or the luasocket library thats already there in Ctrlr (along with mobdebug also added to Ctrlr) will work.

    #30344
    synth
    Participant
    • Topics: 13
    • Replies: 35
    • Total: 48

    ok I added mobdebug from ZeroBrane to Ctrlr at Source\Lua\mobdebug

    I see that mobdebug requires some extra modules :

    
    --
    -- MobDebug 0.60
    -- Copyright 2011-14 Paul Kulchenko
    -- Based on RemDebug 1.0 Copyright Kepler Project 2005
    --
    
    -- use loaded modules or load explicitly on those systems that require that
    local require = require
    local io = io or require "io"
    local table = table or require "table"
    local string = string or require "string"
    local coroutine = coroutine or require "coroutine"
    -- protect require "os" as it may fail on embedded systems without os module
    local os = os or (function(module)
      local ok, res = pcall(require, module)
      return ok and res or nil
    end)("os")
    ..
    ...
    

    I will try to find the io library and the others and compile it in with Ctrlr. I wonder if there is some central place where I can get these standard libs for Lua.

    What is the Lua version being used by Ctrlr ?

    • This reply was modified 7 years, 8 months ago by synth.
    • This reply was modified 7 years, 8 months ago by synth.
    #30346
    atom
    Keymaster
    • Topics: 159
    • Replies: 2945
    • Total: 3104
    • ★★★★★

    I think “io” might not be there, it was crashing when loaded, i’ll revisit it now to see if it can be enabled.

    #30348
    synth
    Participant
    • Topics: 13
    • Replies: 35
    • Total: 48

    I wonder if there is some central place where I can get these standard libs for Lua.

    What is the Lua version being used by Ctrlr ?

    #30349
    atom
    Keymaster
    • Topics: 159
    • Replies: 2945
    • Total: 3104
    • ★★★★★

    Theese modules are core modules in Lua, we are using Lua 5.1

    To see how the Lua state is created have a look at the CtrlrLuaManager constructor. The io module is not there, but it’s because i was initializing it in the wrong way, the new “proper” way is the way debug and package modules are now loaded.

    With the package module loaded now you can load any other module inside Ctrlr without recompiling. There is a set of pre-defined paths that Lua uses to find those modules, you need to search the documentation for details.

    #30350
    synth
    Participant
    • Topics: 13
    • Replies: 35
    • Total: 48

    Yes I guess I can currently use “require” with the following patterns for the path to load packages distributed as .lua files, like mobdebug :

    http://www.lua.org/pil/8.1.html

    For C-packages there is http://www.lua.org/pil/8.2.html

    Still not sure where the io.lua file actually is though in Ctrlr. Or maybe its a C-package.

    ————-

    I found a C file in the current lua source code for lua-5.2.3 in liolib.c. I ll try getting the one for lua-5.1 and compiling it with Ctrlr.

    • This reply was modified 7 years, 8 months ago by synth.
    • This reply was modified 7 years, 8 months ago by synth.
    #30352
    atom
    Keymaster
    • Topics: 159
    • Replies: 2945
    • Total: 3104
    • ★★★★★

    IO is a base module of Lua, you won’t find it as an external package i think.

    #30354
    synth
    Participant
    • Topics: 13
    • Replies: 35
    • Total: 48

    Trying with :

    	lua_pushcfunction(luaState, luaopen_io);
    	lua_pushliteral(luaState, "io");
    	lua_call(luaState, 1, 0);

    in CtrlrLuaManager::CtrlrLuaManager(CtrlrPanel &_owner)

    —————-

    ok that did work and “local io = io or require “io” works now

    • This reply was modified 7 years, 8 months ago by synth.
    #30357
    atom
    Keymaster
    • Topics: 159
    • Replies: 2945
    • Total: 3104
    • ★★★★★

    This is how it should look like (the fact that it doesn’t is my stupidity and the fact that i didn’t read the manual), this seems to work (ctrlr is not crashing):

    lua_pushcfunction(luaState, luaopen_base);
        lua_pushliteral(luaState, "base");
        lua_call(luaState, 1, 0);
    
        lua_pushcfunction(luaState, luaopen_table);
        lua_pushliteral(luaState, "table");
        lua_call(luaState, 1, 0);
    
        lua_pushcfunction(luaState, luaopen_string);
        lua_pushliteral(luaState, "string");
        lua_call(luaState, 1, 0);
    
        lua_pushcfunction(luaState, luaopen_math);
        lua_pushliteral(luaState, "math");
        lua_call(luaState, 1, 0);
    
        lua_pushcfunction(luaState, luaopen_io);
        lua_pushliteral(luaState, "io");
        lua_call(luaState, 1, 0);
    
        lua_pushcfunction(luaState, luaopen_debug);
        lua_pushliteral(luaState, "debug");
        lua_call(luaState, 1, 0);
    
        lua_pushcfunction(luaState, luaopen_package);
        lua_pushliteral(luaState, "package");
        lua_call(luaState, 1, 0);
    #30358
    synth
    Participant
    • Topics: 13
    • Replies: 35
    • Total: 48

    ok, that helped.

    It seems the ‘os’ library is required now as mobdebug uses it :

    --
    -- MobDebug 0.60
    -- Copyright 2011-14 Paul Kulchenko
    -- Based on RemDebug 1.0 Copyright Kepler Project 2005
    --
    
    -- use loaded modules or load explicitly on those systems that require that
    local require = require
    local io = io or require "io"
    local table = table or require "table"
    local string = string or require "string"
    local coroutine = coroutine or require "coroutine"
    -- protect require "os" as it may fail on embedded systems without os module
    local os = os or (function(module)
      local ok, res = pcall(require, module)
      return ok and res or nil
    end)("os")
    
    local mobdebug = {....

    I tried :

    lua_pushcfunction(luaState, luaopen_os);
    lua_pushliteral(luaState, "os");
    lua_call(luaState, 1, 0);

    That compiles but it crashes with memory leaks in Juce.

    #30359
    atom
    Keymaster
    • Topics: 159
    • Replies: 2945
    • Total: 3104
    • ★★★★★

    Yeah i doubt we will be able to turn that on, i’ll need to spend more time on that. I’ll have a look at what is exactly happening.

    #30361
    synth
    Participant
    • Topics: 13
    • Replies: 35
    • Total: 48

    It worked.

    #30362
    synth
    Participant
    • Topics: 13
    • Replies: 35
    • Total: 48

    I have modified mobdebug to remove 1 line which refers to the ‘os’ library. Now it compiled and I can see the code stopped at the breakpoint in Zerobrane. I ll test it out and post the changes.

    ——————

    I copied mobdebug from ZeroBraneStudioEduPack-0.80-win32\lualibs\mobdebug\ into Source\Lua\mobdebug in Ctrlr and suddenly it seems to compile fine. I was getting an error in line 643 in mobdebug.lua earlier but that seems to be gone now.

    console() output seems to be sent to Ctrlr only after the debugging session completes. Probably print() may work better. I have yet to check if the watch window works in Zerobrane to observe locals

    • This reply was modified 7 years, 8 months ago by synth.
Viewing 20 posts - 1 through 20 (of 37 total)
  • The forum ‘Programming’ is closed to new topics and replies.
There is currently 0 users and 63 guests online
No users are currently active
Forum Statistics
Threads: 2,495, Posts: 17,374, Members: 77,605
Most users ever online was 12 on January 22, 2019 3:47 pm
Ctrlr