Debug Attach Mode


Glider features an integrated debugger that is very easy to use. You just point Glider to your lua executable and the IDE will take care of including the debugger files, launching the runtime, and making a connection to the debugger. However sometimes it is not possible to just “point and shoot” per se. This might be because the Lua runtime cannot really be launched from the command line or that you cannot shutdown the running process. From version 2.0.22 we have introduced remote debugging that will make it very easy to debug these processes without any added configuration.

Please note that in order to use remote attach your lua runtime must have the following

  1. Lua socket support- This debugger uses this to communicate to the IDE
  2. Lua debug libraries- The debugger also needs this to attach the debug hook
  3. the loadstring component- Some environments have a sandbox that removes this.

Next, you must figure out what project root folder to load into Glider. Glider uses the result of debug.getinfo to figure out the currently executed lua file. Depending on how your environment is set up, this might return an absolute path or relative path. In the case of a relative path Glider must know what the root directory is so that it can properly convert to an absolute path. This conversion is necessary to open up files in the editor, set breakpoints, and other important tasks. To find out what paths your runtime is returning simply put this somewhere in your code:

    print(debug.getinfo( 2,"S" ).source)

For instance if my lua runtime is executing the script /Users/MyRuntime/Scripts/Game/main.lua and debug.getinfo returns Scripts/Game/main.lua then please open the folder /Users/MyRuntime in Glider. When Glider receives a breakpoint event it only sees Scripts/Game/main.lua but since it knows the project root folder, it can convert the relative path into the correct absolute path.


Heads up! Be aware that in order to open a folder into Glider, it must be considered a Lua project. Any folder with a main.lua or GliderProperties.proj is considered a lua project.


The difficult part is done. Now just insert the following code snippet somewhere in your project. The snippet should get executed when you wish to start debugging.

(function()
    local udp = require("socket").udp()
    local tcp = require("socket").bind('*',0)    
    local ip,port = tcp:getsockname()
    udp:setoption('broadcast',true) --broadcast so we can debug anywhere on the local network       
    udp:sendto(port, "255.255.255.255",24875 ) --initiate the connection to Glider
    local lib = tcp:accept():receive('*a') --accept the debugger library code
    loadstring(lib)() --execute the debugger library code
end)()

Next run your runtiime as you normally would. This may mean starting up your favorite lua based game, running your c++ project from visual studio, or starting your app on your phone. If you have a breakpoint set, you should see it light up.

Please let us know if we can streamline the process even more. Happy coding and if you have any questions feel free to ask below.