pkulchenko / MobDebug

Remote debugger for Lua.
Other
885 stars 192 forks source link

ZBS for Darktable on windows 64bits #38

Closed phweyland closed 6 years ago

phweyland commented 6 years ago

I'm trying to figure out how to use ZBS for Darktable plugins o Windows. The start of the module is like this:

local dt = require "darktable"
local debug = require "darktable.debug"
package.cpath = "C:/Program Files/darktable/bin/lua53.dll;"..package.cpath
package.cpath = "C:/Documents/Darktable/lua/luasocket/socket/core.dll;"..package.cpath
package.cpath = "C:/Documents/Darktable/lua/luasocket/mime/core.dll;"..package.cpath
package.path = package.path..";C:/Program Files (x86)/ZeroBraneStudio/lualibs/mobdebug/mobdebug.lua"
require('mobdebug').start()

And I get the following error.

LUA ERROR : error loading module 'socket' from file 'C:/Program Files (x86)/ZeroBraneStudio/lualibs/mobdebug/mobdebug.lua':
    ...iles (x86)/ZeroBraneStudio/lualibs/mobdebug/mobdebug.lua:222: too many C levels (limit is 200) in function at line 176 near 'value'

If I remove the darktable debug option the plugin doesn't start neither. Could you help fix this ?

ZBS: 1.70; MobDebug 0.70 Darktable 2.41 Windows 10 core.dll : the 64bits ones provided by you on a separate link.

pkulchenko commented 6 years ago

I don't think this is a problem with the IDE or its debugger; the error you see happens because loading of mobdebug.lua is looping because of the way your path/cpath settings are specified.

You need to specify the paths a bit differently:

package.cpath = "C:/Documents/Darktable/lua/luasocket/?.dll;"..package.cpath
package.path = package.path..";C:/Program Files (x86)/ZeroBraneStudio/lualibs/mobdebug/?.lua"
phweyland commented 6 years ago

Thank you for your quick answer. Now I get the error below. Something is still wrong:

LUA ERROR : ...iles (x86)/ZeroBraneStudio/lualibs/mobdebug/mobdebug.lua:102: module 'socket' not found:
    no field package.preload['socket']
    no file 'C:\Program Files\darktable\bin\..\share\lua\5.3\socket.lua'
    no file 'C:\Program Files\darktable\bin\..\share\lua\5.3\socket\init.lua'
...

the code is now: (I've also tried the commented lines)

local dt = require "darktable"
local debug = require "darktable.debug"
--package.cpath = "C:/Program Files/darktable/bin/?.dll;"..package.cpath
package.cpath = "C:/Documents/Darktable/lua/luasocket/?.dll;"..package.cpath
--package.cpath = "C:/Documents/Darktable/lua/luasocket/?/?.dll;"..package.cpath
package.path = package.path..";C:/Program Files (x86)/ZeroBraneStudio/lualibs/mobdebug/?.lua"
require('mobdebug').start()
pkulchenko commented 6 years ago

It seems like you also need to add path for the socket library; use the following instead of package.path assignment:

package.path = package.path..";C:/Program Files (x86)/ZeroBraneStudio/lualibs/mobdebug/?.lua;C:/Program Files (x86)/ZeroBraneStudio/lualibs/?.lua"

You can use a batch file instead of specifying the paths in the script; see the description here: https://studio.zerobrane.com/doc-remote-debugging

phweyland commented 6 years ago

Thank you. Seems to progress. The error is now (on 64bits system...):

LUA ERROR : error loading module 'socket.core' from file 'C:/Documents/Darktable/lua/luasocket/socket\core.dll':
    %1 is not a valid Win32 application.

With the code :

local dt = require "darktable"
local debug = require "darktable.debug"
package.cpath = "C:/Program Files/darktable/bin/?.dll;"..package.cpath
package.cpath = "C:/Documents/Darktable/lua/luasocket/?.dll;"..package.cpath
package.path = package.path..";C:/Program Files (x86)/ZeroBraneStudio/lualibs/mobdebug/?.lua;C:/Program Files (x86)/ZeroBraneStudio/lualibs/?.lua"
require('mobdebug').start()
pkulchenko commented 6 years ago

It's because you are loading 32bit libs included with the IDE into your (likely 64bit) application. You need to be using 64bit socket libraries. See the documentation for details. You can get 64bit socket libraries here: https://download.zerobrane.com/luasocket-3.0-win64.zip; you just need to make them available to your application and adjust package.cpath accordingly. Make sure you do not include 32bit libraries in cpath or at least that 64bit libraries are referenced earlier than 32bit libraries.

phweyland commented 6 years ago

This time ZBS gets started. I've just changed the library by the ones you've just provided. In your documentation, the paragraph "Debugging of 64bit applications" doesn't mention this link. I think this would be helpful. Thank you very much again for your quick and efficient support !

pkulchenko commented 6 years ago

I'll consider adding the link, but it's "unofficial", as it's expected that if you are using 64bit application, you are likely already have luasocket for it, although there may be cases like yours when it's a 3rd party application, which can benefit from the library.

phweyland commented 6 years ago

Now the breakpoints... do not break. On the initial break (green arrow) I can Step over along the main thread and it breaks at each step. But, even adding require('mobdebug').on() doesn't make the break (red point) work. Continuing to follow the faq, I've also tried to add debug.getinfo(1,"S").source, but that trigs an error:

LUA ERROR : error loading module 'mylua/groupDerivedImages' from file 'c:\Documents\Darktable\/lua/mylua/groupDerivedImages.lua':
    c:\Documents\Darktable\/lua/mylua/groupDerivedImages.lua:7: syntax error near 'local'

having this code:

local dt = require "darktable"
local debug = require "darktable.debug"
package.cpath = "C:/Documents/Darktable/lua/luasocket/?.dll;"..package.cpath
package.path = package.path..";C:/Program Files (x86)/ZeroBraneStudio/lualibs/mobdebug/?.lua;C:/Program Files (x86)/ZeroBraneStudio/lualibs/?.lua"
require('mobdebug').start()
debug.getinfo(1,"S").source
local gettext = dt.gettext
pkulchenko commented 6 years ago

debug.getinfo(1,"S").source local gettext = dt.gettext

You need to print the value. Change the first line here to print(debug.getinfo(1,"S").source), as the existing line is not valid syntax.

phweyland commented 6 years ago

Thank you for your patience ! dt.print(debug.getinfo(1,"S").source) gives this: image Is @ normal ? (when I use dt.print to show data I don't get this character).

pkulchenko commented 6 years ago

Yes, @ is normal and it's being handled correctly. I wonder where /lua/mylua path is coming from. I think it will be handled correctly if you drop the leading slash, so it looks like ...Darktable\lua/mylua/....