Home › Forums › General › Programming › Debugging Support for Lua
Tagged: zerobrane
- This topic has 36 replies, 4 voices, and was last updated 9 years, 4 months ago by atom.
-
AuthorPosts
-
September 23, 2014 at 8:12 am #29410
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 ?
September 23, 2014 at 11:25 am #29414nope, and i didn’t see any possibility to do that ever.
September 23, 2014 at 6:23 pm #29425Just 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.
September 25, 2014 at 6:27 am #29498I 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.
September 25, 2014 at 11:27 am #29508To 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
October 6, 2014 at 12:45 pm #30160I 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 ?
October 6, 2014 at 1:18 pm #30164Yes 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
October 9, 2014 at 11:02 am #30343So 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.
October 9, 2014 at 11:16 am #30344ok 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 ?
October 9, 2014 at 11:17 am #30346I think “io” might not be there, it was crashing when loaded, i’ll revisit it now to see if it can be enabled.
October 9, 2014 at 11:20 am #30348I 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 ?
October 9, 2014 at 11:28 am #30349Theese 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.
October 9, 2014 at 11:48 am #30350Yes 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.
October 9, 2014 at 11:51 am #30352IO is a base module of Lua, you won’t find it as an external package i think.
October 9, 2014 at 11:56 am #30354Trying 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 9 years, 5 months ago by synth.
October 9, 2014 at 12:53 pm #30357This 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);
October 9, 2014 at 1:19 pm #30358ok, 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.
October 9, 2014 at 1:24 pm #30359Yeah 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.
October 9, 2014 at 1:50 pm #30361It worked.
October 9, 2014 at 1:52 pm #30362I 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 9 years, 5 months ago by synth.
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.