[ZeroBrane Studio] Re: Remote debugging with statically linked LuaJIT?

  • From: Paul K <paul@xxxxxxxxxxxxx>
  • To: "zerobrane@xxxxxxxxxxxxx" <zerobrane@xxxxxxxxxxxxx>
  • Date: Mon, 20 Oct 2014 21:25:30 -0700

Hi Jan,

> We have compiled LuaJIT (5.1, but we could upgrade to 5.2 if really required) 
> ourselves statically with MinGW and linked our program against it. Will that 
> still allow the remote debugging via package.path and package.cpath 
> modification or does that only allow the 3rd path, copying mobdebug.lua and 
> having to include luasocket ourselves?

I should probably have a separate page to cover this setup as it's a
popular question. I have the option covered on this page
(http://studio.zerobrane.com/doc-lua52-debugging.html), and the
recommendation is not specific to Lua 5.2.

Basically, there are two options (this is specific to Windows): (1)
you can compile luasocket libraries (you only need socket/core.dll)
into your application, or (2) you can create a proxy DLL and put it
into the same folder where you have your executable (that statically
includes the Lua interpreter). The executable itself has to export Lua
API calls, otherwise the proxy DLL won't work. This is the maillist
post (and related thread) that describes how this can be done:
http://lua-users.org/lists/lua-l/2013-11/msg00831.html. I used to
think that it may be useful to provide that proxy API packaged with
ZBS, but since the executable needs to be compiled exporting the API,
there is not much benefit in simply having lua51.dll (and
opportunities for confusion).

In terms of debugging your application, you don't need to copy any
files; if you use the proxy DLL (and copied it into the same folder as
your executable), you can use the following batch file:

set ZBS=D:\path\to\ZeroBraneStudio
set LUA_PATH=./?.lua;%ZBS%/lualibs/?/?.lua;%ZBS%/lualibs/?.lua
set LUA_CPATH=%ZBS%/bin/?.dll;%ZBS%/bin/clibs/?.dll
myapplication

If you statically compiled luasocket, then you don't need to set
LUA_CPATH and can use the same batch file, but comment out the third
line in in.

Either case assumes you have "require('mobdebug').start()" in your
application to start the debugging session.

Let me know if you need more details on any of the steps in the process.

Paul.

Other related posts: