Vscode native lua debugger for tool development?

Hi.

Is it possible to use the vscode native lua debugger in vscode?

I have seen mention of remdebug, etc. and I can attach to processes but I’m not sure how this works in vscode or what port renoise would expose?

I have installed globally on windows, with luarocks, and luasocket.

I have installed these extensions:

In .vscode/launch.json I can have attach, launch, etc. what port does renoise remdebug listen on?

When I attempt to use debug.start() I get this message in terminal:

** Failed to connect the controller to the debugger engine. Please check your firewall settings for Lua based programs.

Press return to exit...

I’ve added both lua.exe and renoise.exe to my windows firewall, etc.

Also this screenshot may help:


I was able to get it /sorta/kinda/ working but it’s missing some stuff or I’ve misconfigured it?

edit derp - here is a fixed bit of code:

local rdebug = require("remdebug.engine")
-- default config is "localhost" on port 8171
-- rdebug.configure { host = "127.0.0.1", port = 8171}
rdebug.start()

I had been using engine.engine like a dummy before. I think this should work but now seeing this in the renoise terminal:

*** ...se 3.5.2\Resources\Scripts\Libraries\remdebug\engine.lua:109: attempt to call method 'gfind' (a nil value)
*** stack traceback:
***   ...se 3.5.2\Resources\Scripts\Libraries\remdebug\engine.lua:109: in function 'break_dir'
***   ...se 3.5.2\Resources\Scripts\Libraries\remdebug\engine.lua:133: in function 'merge_paths'
***   ...se 3.5.2\Resources\Scripts\Libraries\remdebug\engine.lua:271: in function '__index'
***   ...se 3.5.2\Resources\Scripts\Libraries\remdebug\engine.lua:567: in function 'start'
***   main.lua:6: in main chunk

Thanks in advance for any help.

1 Like

Update

OK I am getting farther.

I am now in debian linux 12 to make sure I get the best developer experience as Windows was a PITA to deal with.

I have installed lua5.1:
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio

I have installed luasocket:
luarocks install luasocket

What I’m doing to test the debugger:

cd ~/usr/share/local/renoise-3.5.2/Scripts/Libraries/remdebug
lua controller.lua

This works and shows this output:

-- Lua Remote Debugger --
Run the program you wish to debug with 'remdebug.engine.start()' now

Now in Renoise, I open the Scripting Terminal & Editor window from Tools menu.
Next I open TestPad.lua

…and paste this (from the docs here:
https://renoise.github.io/xrnx/start/debugging.html#step-by-step-guide

debug.start()

local function sum(a, b)
    return a + b
end

local c = sum(1, 2)
print(c)

debug.stop()

Then click Execute

The terminal window in Renoise shows this on 1st Execute now:

3

However, no debugging happens.

So I click the Execute again after switching back to Editor and now the terminal shows this:

*** /usr/local/share/lua/5.1/remdebug/engine.lua:109: attempt to call method 'gfind' (a nil value)
*** stack traceback:
***   /usr/local/share/lua/5.1/remdebug/engine.lua:109: in function 'break_dir'
***   /usr/local/share/lua/5.1/remdebug/engine.lua:133: in function 'merge_paths'
***   /usr/local/share/lua/5.1/remdebug/engine.lua:271: in function '__index'
***   /usr/local/share/lua/5.1/remdebug/engine.lua:567: in function 'start'
***   /usr/local/share/lua/5.1/remdebug/session.lua:108: in function 'start'
***   TestPad.lua:1: in main chunk

@Beatslaughter has been helping me on the side and said to change line 109 gfind to gmatch which I did – doing this like so:
vim /usr/local/share/renoise-3.5.2/Scripts/Libraries/remdebug/engine.lua +109

The line is:

for w in path:gfind("[^\/]+") do

and I edit it to be:

for w in path:gmatch("[^\/]+") do

Then I close and reopen Renoise. This seems to be required to get the change in place; perhaps Renoise loads a copy in memory on startup?

Any way, after I do this, I repeat the sequence:

cd ~/usr/share/local/renoise-3.5.2/Scripts/Libraries/remdebug
lua controller.lua

Then Execute TestPad.lua and the controller crashes with this message:

-- Lua Remote Debugger --
Run the program you wish to debug with 'remdebug.engine.start()' now
lua: controller.lua:164: attempt to index local 'breakpoint' (a nil value)
stack traceback:
	controller.lua:164: in main chunk
	[C]: ?
grymmjack@debian:/usr/local/share/renoise-3.5.2/Scripts/Libraries/remdebug$

What am I doing wrong? How do I set a breakpoint, or is this related to the gfindgmatch edit?

At any rate I can’t get it to work properly and would love some help!

@taktik if you have any ideas, or @dblue I’d appreciate it!

1 Like

No idea,

only isn’t this

a different path to

?

Maybe symlink in /usr/local/share/lua/5.1/ to ~/usr/share/local/renoise-3.5.2/Scripts/Libraries/remdebug ?

Are those extensions even using remdebug? Doesn’t look like it to me.

This is a rabbit hole… here are the steps i got and how far i came on Windows:

  • In the remdebug Renoise directory in engine.lua gfind is not supported anymore with Luajit, i’ve replaced the function with the following code, which appears to split the path fine:
    Split taken from : lua-users wiki: Split Join
local function break_dir(path)
  _assert(type(path) == 'string')
  
  local paths = {}

  path = path:gsub("\\", "/")

  function string:split(sep)
     local sep, fields = sep or ":", {}
     local pattern = string.format("([^%s]+)", sep)
     self:gsub(pattern, function(c) fields[#fields+1] = c end)
     return fields
  end

  return path:split("/")
end

Looking at the controller.lua code Renoise should send the breakpoint information with filename and lines to the controller which seems to fail?

Maybe someone has an idea on how to progress or it could also be some issue with the move from Lua to Luajit?