Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Lua Development Tools » Proper method to debug Lua script from Luaj project
Proper method to debug Lua script from Luaj project [message #1219439] Tue, 03 December 2013 21:12 Go to next message
Patrick Hoey is currently offline Patrick Hoey
Messages: 14
Registered: December 2013
Junior Member
I have been following the http://wiki.eclipse.org/Koneki/LDT/Developer_Area/User_Guides/User_Guide_1.0#Launching_DBGp_Client
as well as googling around for possible solutions.

Here is my problem. I am trying to debug a Lua script from Eclipse with the Koneki project plugin, and I have set a breakpoint within a Lua function. The breakpoint never gets hit, and it appears that the Lua attach debug process terminates. I even set the debug option to "Break at the first line" and this does work, but then as soon as I continue, the debug process terminates.

In my mind, I would think that I would start the DBGp Server (Lua Attach to Application), and then start my java app (which loads and calls functions of the Lua scripts via LuaJ). I then run the "Lua Application" with my lua script in order for the lua client to load.

I guess I am not clear on how to properly debug a Lua script within Eclipse (using Koneki Lua plugin) when the scripts are loaded from LuaJ within a Java application.
Re: Proper method to debug Lua script from Luaj project [message #1219766 is a reply to message #1219439] Thu, 05 December 2013 17:12 Go to previous messageGo to next message
Marc Aubry is currently offline Marc Aubry
Messages: 83
Registered: August 2012
Member
Hi Patrick,

We will need more information to help you:
Which debugger transport layer do you use with LuaJ ?
Can you check the option "Enable DBGP logging" in the Lua attach launch configuration and post the logs here ?

Thanks
Re: Proper method to debug Lua script from Luaj project [message #1219775 is a reply to message #1219766] Thu, 05 December 2013 18:05 Go to previous messageGo to next message
Patrick Hoey is currently offline Patrick Hoey
Messages: 14
Registered: December 2013
Junior Member
Hello,

I guess the primary issue that I am struggling with is the setup in order to debug a Lua script that is invoked in Java code via LuaJ (on Windows 7 platform). I have setup the Lua project, debugger server, and client connection. This setup seems more appropriate for lua scripts running independently though. My question is whether it is possible to set a breakpoint within a function of a lua script, and have this point break when invoked from Java via LuaJ.

1) For the debugger setup, I am launching the DBGP server, and connecting to it with the client file provided by the "Lua Debugger Client" link. I am using the LuaRocks 2.1 socket binaries as well as the LuaRocks runtime interpreter (5.1).
2) Here are the logs with "Enable DBGP logging" enabled:
Quote:

Event CREATE from org.eclipse.koneki.ldt.debug.core.internal.LuaDebugTarget
Event MODEL_SPECIFIC/1 from org.eclipse.dltk.launching.InterpreterConfig
Event CHANGE from org.eclipse.dltk.launching.process.ScriptRuntimeProcess
Event CREATE from org.eclipse.dltk.launching.process.ScriptRuntimeProcess
Event CHANGE from org.eclipse.dltk.launching.process.ScriptRuntimeProcess
Event CHANGE from org.eclipse.dltk.launching.process.ScriptRuntimeProcess
Event MODEL_SPECIFIC/5 from org.eclipse.dltk.dbgp.internal.DbgpDebugingEngine
<< <?xml version="1.0" encoding="UTF-8" ?>
<init fileuri="unknown:/" idekey="dbgp_1386265547549" protocol_version="1.0" parent="" thread="main" appid="Lua DBGp" language="Lua" session="1386265547_main" xmlns="urn:debugger_protocol_v1"/>
>> feature_set -n max_children -i 29 -v 32
<< <?xml version="1.0" encoding="UTF-8" ?>
<response feature="max_children" success="1" command="feature_set" transaction_id="29" xmlns="urn:debugger_protocol_v1"/>
>> feature_set -n max_depth -i 30 -v 2
<< <?xml version="1.0" encoding="UTF-8" ?>
<response feature="max_depth" success="1" command="feature_set" transaction_id="30" xmlns="urn:debugger_protocol_v1"/>
>> feature_set -n max_data -i 31 -v 8192
<< <?xml version="1.0" encoding="UTF-8" ?>
<response feature="max_data" success="1" command="feature_set" transaction_id="31" xmlns="urn:debugger_protocol_v1"/>
>> feature_get -n stdin -i 32
<< <?xml version="1.0" encoding="UTF-8" ?>
<response transaction_id="32" feature_name="stdin" command="feature_get" supported="0" xmlns="urn:debugger_protocol_v1"><![CDATA[false]]></response>
>> feature_set -n notify_ok -i 33 -v 1
<< <?xml version="1.0" encoding="UTF-8" ?>
<response feature="notify_ok" success="0" command="feature_set" transaction_id="33" xmlns="urn:debugger_protocol_v1"/>
>> stdout -c 2 -i 34
<< <?xml version="1.0" encoding="UTF-8" ?>
<response command="stdout" transaction_id="34" success="1" xmlns="urn:debugger_protocol_v1"/>
>> stderr -c 2 -i 35
<< <?xml version="1.0" encoding="UTF-8" ?>
<response command="stderr" transaction_id="35" success="1" xmlns="urn:debugger_protocol_v1"/>
>> breakpoint_set -r 0 -t line -s enabled -n 18 -i 36 -f file:///F:/Users/phoey/phoey_phoeyPC/workspace/cyberpunkgame-android/assets/data/scripts/atm.lua
<< <?xml version="1.0" encoding="UTF-8" ?>
<response transaction_id="36" id="0" state="enabled" command="breakpoint_set" xmlns="urn:debugger_protocol_v1"/>
Event CREATE from org.eclipse.dltk.internal.debug.core.model.ScriptThread
Event MODEL_SPECIFIC/4 from org.eclipse.dltk.internal.debug.core.model.ScriptThread
Event RESUME from org.eclipse.dltk.internal.debug.core.model.ScriptThread
>> step_into -i 37
Event CHANGE from org.eclipse.dltk.internal.debug.core.model.ScriptThread
Event MODEL_SPECIFIC/2 from org.eclipse.koneki.ldt.debug.core.internal.LuaDebugTarget
<< <?xml version="1.0" encoding="UTF-8" ?>
<response transaction_id="37" status="break" xmlns="urn:debugger_protocol_v1" command="step_into" reason="ok"/>
>> stack_get -i 38
Event MODEL_SPECIFIC/3 from org.eclipse.dltk.internal.debug.core.model.ScriptThread
<< <?xml version="1.0" encoding="UTF-8" ?>
<response transaction_id="38" command="stack_get" xmlns="urn:debugger_protocol_v1"><stack lineno="3" level="0" filename="file:///f:/users/phoey/phoey_phoeypc/workspace/cyberpunkgame-android/assets/data/scripts/atm.lua" type="file"/></response>
Event CHANGE from org.eclipse.dltk.internal.debug.core.model.ScriptThread
>> breakpoint_get -d 0 -i 39
<< <?xml version="1.0" encoding="UTF-8" ?>
<response transaction_id="39" command="breakpoint_get" xmlns="urn:debugger_protocol_v1"><breakpoint id="0" hit_count="0" state="enabled" filename="file:///f:/users/phoey/phoey_phoeypc/workspace/cyberpunkgame-android/assets/data/scripts/atm.lua" hit_value="0" type="line" lineno="18" hit_condition=">="/></response>
>> coroutine_list -i 40
<< <?xml version="1.0" encoding="UTF-8" ?>
<response transaction_id="40" command="coroutine_list" xmlns="urn:debugger_protocol_v1"/>
Event SUSPEND from org.eclipse.dltk.internal.debug.core.model.ScriptThread
>> coroutine_list -i 41
<< <?xml version="1.0" encoding="UTF-8" ?>
<response transaction_id="41" command="coroutine_list" xmlns="urn:debugger_protocol_v1"/>
Event TERMINATE from org.eclipse.koneki.ldt.debug.core.internal.attach.LuaAttachDebuggingEngineRunner$1

Any help would be appreciated. Thanks.
Re: Proper method to debug Lua script from Luaj project [message #1219915 is a reply to message #1219775] Fri, 06 December 2013 17:27 Go to previous messageGo to next message
Marc Aubry is currently offline Marc Aubry
Messages: 83
Registered: August 2012
Member
It seems you are misleading something (I don't kown what), let's try explain the debugger from another point of view.
There are 2 ways to debug your lua code:

- Using the "Lua Attach to Application", you are responsible to call the debugger in your Lua code and to launch your Java application by yourself. This is explained in the user guide [1]. Starting the launch configuration will only start the DBGP server who is waiting for the debbugger to connect.

- Using the "Lua Application" launch configuration, you have to register your Java application as a Lua interpreter, see [2]. Then configure a launch configuration to use your interpreter. Launching the launch configuration will start your java application. If your Java application don't handle the -e option to execute some Lua code you have also to call the debugger in your code.

If your java application create more than one Lua thread you will have to restart the DBGP server and client for each Lua thread.

I hope this can help you, otherwise please try to precise your questions.


[1]http://wiki.eclipse.org/Koneki/LDT/Developer_Area/User_Guides/User_Guide_1.0#Local_Debug
[2]http://wiki.eclipse.org/Koneki/LDT/Developer_Area/User_Guides/User_Guide_1.0#Attach_Debug
Re: Proper method to debug Lua script from Luaj project [message #1219937 is a reply to message #1219915] Fri, 06 December 2013 22:35 Go to previous messageGo to next message
Patrick Hoey is currently offline Patrick Hoey
Messages: 14
Registered: December 2013
Junior Member
Ok, now I understand where my confusion was. I am new to the Lua environment, and it was made more confusing by using a third party integration tool (LuaJ) to interact with the Lua scripts. I now understand that there are two distinct methods to debug in Eclipse (LDT) with Lua. What I did not understand before is that LuaJ library itself is the interpreter, just like if Lua was installed with an executable.

Once I connected the dots, I understood how to make my debug target. For this example, I am using the "Lua Application" target for debugging.

The first step was adding my own interpreter. Under "Lua Application", I "managed interpreters" (generic Lua) in order to add LuaJ. It appears that the "Interpreter executable" field expects a specific file, so passing in the LuaJ command was not an option. I created a batch file (on Windows) and wrapped the LuaJ command in the file with the following line:

java.exe -cp F:\Users\phoey\phoey_phoeyPC\workspace\cyberpunkgame\libs\luaj-jse-3.0-beta1.jar lua %*

This allows for all the parameters to be passed to the batch file as if it was an executable.

In the environment of the "Lua Application" debug target, I set both LUA_PATH and LUA_CPATH (append environment):

LUA_PATH = F:/Users/phoey/phoey_phoeyPC/workspace/cyberpunkgame-android/assets/data/scripts/?.lua;?.lua;D:/luarocks/lib/lua/5.1/?.lua;d:/luarocks/2.1/lua/?/init.lua
LUA_CPATH = D:/luarocks/lib/lua/5.1/?.dll

I also made sure my "Working Directory" was set to where my lua scripts were (through the Arguments tab)

My first problem was the following:
F:\Users\phoey\phoey_phoeyPC\workspace\cyberpunkgame-android\assets\data\scripts>java.exe -cp F:\Users\phoey\phoey_phoeyPC\workspace\cyberpunkgame\libs\luaj-jse-3.0-beta1.jar lua -e "require ('debugger')();" F:\Users\phoey\phoey_phoeyPC\workspace\cyberpunkgame-android\assets\data\scripts\atm.lua
org.luaj.vm2.LuaError: @debugger.lua:2283 Luaj-jse 3.0-beta1is not supported.
stack traceback:
debugger.lua:2265: in main chunk
string:1: in main chunk
[Java]: in ?
at org.luaj.vm2.lib.BaseLib$error.call(Unknown Source)
at org.luaj.vm2.lib.TwoArgFunction.call(Unknown Source)
at org.luaj.vm2.LuaClosure.execute(Unknown Source)
at org.luaj.vm2.LuaClosure.call(Unknown Source)
at org.luaj.vm2.lib.PackageLib$require.call(Unknown Source)
at org.luaj.vm2.LuaClosure.execute(Unknown Source)
at org.luaj.vm2.LuaClosure.onInvoke(Unknown Source)
at org.luaj.vm2.LuaClosure.invoke(Unknown Source)
at lua.processScript(Unknown Source)
at lua.main(Unknown Source)

The LuaJ interpreter returns "Luaj-jse 3.0-beta1" (supports Lua 5.2) but the client debugger.lua script expects either a "Lua 5.1" or "Lua 5.2". I modified the script for LuaJ support by setting the version to "Lua 5.2".

But now, after resolving that issue, I keep getting the following error:

F:\Users\phoey\phoey_phoeyPC\workspace\cyberpunkgame-android\assets\data\scripts>java.exe -cp F:\Users\phoey\phoey_phoeyPC\workspace\cyberpunkgame\libs\luaj-jse-3.0-beta1.jar lua -e "require ('debugger')();" F:\Users\phoey\phoey_phoeyPC\workspace\cyberpunkgame-android\assets\data\scripts\atm.lua
org.luaj.vm2.LuaError: @debugger.lua:1704 Unable to determine the working directory.
stack traceback:
debugger.lua:1702: in function 'init'
debugger.lua:2685: in function <debugger.lua:2676>
string:1: in main chunk
[Java]: in ?
at org.luaj.vm2.lib.BaseLib$error.call(Unknown Source)
at org.luaj.vm2.lib.TwoArgFunction.call(Unknown Source)
at org.luaj.vm2.LuaClosure.execute(Unknown Source)
at org.luaj.vm2.LuaClosure.call(Unknown Source)
at org.luaj.vm2.LuaClosure.execute(Unknown Source)
at org.luaj.vm2.LuaClosure.call(Unknown Source)
at org.luaj.vm2.LuaClosure.execute(Unknown Source)
at org.luaj.vm2.LuaClosure.onInvoke(Unknown Source)
at org.luaj.vm2.LuaClosure.invoke(Unknown Source)
at lua.processScript(Unknown Source)
at lua.main(Unknown Source)

The environment variables are set as well as the working directory. In putting print statements in, I have found that the M.init() is being called (in debugger.lua) where both executionplatform and workingdirectory parameters are nil.

The function tries to guess if the OS is windows with the following call:
local p = io.popen("echo %os%")

but the value returned is nil, and so the OS is set to Unix as the default and therefore never enters the windows path parsing code.

Any ideas on how to troubleshoot this issue? I don't understand why the io call (to open the process and run the echo command) is failing.

UPDATE: I added an assert around the io.popen call to get additional information. This is what I get:

@debugger.lua:1642 io error: Cannot run program "echo": CreateProcess error=2, The system cannot find the file specified
stack traceback:
debugger.lua:1641: in function <debugger.lua:1640>
[Java]: in function 'pcall'
debugger.lua:1651: in function 'init'
debugger.lua:2692: in function <debugger.lua:2683>
string:1: in main chunk
[Java]: in ?

UPDATE 2
I changed the line in iswindows() from
local p = io.popen("echo %os%")
to
local p = io.popen("cmd /C echo %os%")
and now it recognizes my system as Windows_NT (I am developing on a Windows 7 64bit system)

I also changed the line in getworkingdirectory() from
local p = io.popen("echo %cd%")
to
local p = io.popen("cmd /C echo %cd%")

Now the script can determine my working directory correctly.

Unfortunately, I am now getting this error:
F:\Users\phoey\phoey_phoeyPC\workspace\cyberpunkgame-android\assets\data\scripts>java.exe -cp F:\Users\phoey\phoey_phoeyPC\workspace\cyberpunkgame\libs\luaj-jse-3.0-beta1.jar lua -e "require ('debugger')();" F:\Users\phoey\phoey_phoeyPC\workspace\cyberpunkgame-android\assets\data\scripts\atm.lua
org.luaj.vm2.LuaError: @debugger.lua:173 module 'socket' not found: socket
no field package.preload['socket']
socket.lua
no class 'socket'
stack traceback:
debugger.lua:172: in function 'require'
debugger.lua:2696: in function <debugger.lua:2683>
string:1: in main chunk
[Java]: in ?
at org.luaj.vm2.LuaValue.error(Unknown Source)
at org.luaj.vm2.lib.PackageLib$require.call(Unknown Source)
at org.luaj.vm2.LuaClosure.execute(Unknown Source)
at org.luaj.vm2.LuaClosure.call(Unknown Source)
at org.luaj.vm2.lib.PackageLib$require.call(Unknown Source)
at org.luaj.vm2.LuaClosure.execute(Unknown Source)
at org.luaj.vm2.LuaClosure.call(Unknown Source)
at org.luaj.vm2.LuaClosure.execute(Unknown Source)
at org.luaj.vm2.LuaClosure.onInvoke(Unknown Source)
at org.luaj.vm2.LuaClosure.invoke(Unknown Source)
at lua.processScript(Unknown Source)
at lua.main(Unknown Source)


As stated earlier, I have the socket.lua (core.dll) in my LUA_PATH and LUA_CPATH respectively, so I am not sure why it is ignoring the paths. Any ideas?

[Updated on: Fri, 06 December 2013 23:07]

Report message to a moderator

Re: Proper method to debug Lua script from Luaj project [message #1219976 is a reply to message #1219937] Sat, 07 December 2013 21:31 Go to previous messageGo to next message
Patrick Hoey is currently offline Patrick Hoey
Messages: 14
Registered: December 2013
Junior Member
For LuaJ to work, it appears I would have to implement my own transport interface ( based on Java sockets ) in order to use the DBGp Lua client. Depending on alternatives, I may or may not implement this.

Anyways, thank you for your help.
Re: Proper method to debug Lua script from Luaj project [message #1220377 is a reply to message #1219976] Wed, 11 December 2013 11:49 Go to previous messageGo to next message
Simon Bernard is currently offline Simon Bernard
Messages: 287
Registered: July 2009
Senior Member
Just for information we have a java transport layer composed of 2 files :
http://git.eclipse.org/c/koneki/org.eclipse.koneki.ldt.git/tree/plugins/org.eclipse.koneki.ldt.debug.core/script/internal/debugger/transport/java.lua
http://git.eclipse.org/c/koneki/org.eclipse.koneki.ldt.git/tree/plugins/org.eclipse.koneki.ldt.support.lua51/src/org/eclipse/koneki/ldt/support/lua51/internal/interpreter/TransportLayerModule.java

This is dependent of JNLua, but maybe this could help.

If you implement a new transport layer, do not hesitate to share it with us Smile.
Re: Proper method to debug Lua script from Luaj project [message #1220426 is a reply to message #1220377] Wed, 11 December 2013 17:01 Go to previous message
Patrick Hoey is currently offline Patrick Hoey
Messages: 14
Registered: December 2013
Junior Member
Hello Simon,

Thanks for your reply.

In the last few days, I ported my Java source from using LuaJ to JNLua, including the Lua scripts. This actually gave me more control over the Lua calls made in Java, and so I am closer to the Lua layer. Now the LUA_PATH and LUA_CPATH environment variables are respected, and I can easily load third party native libraries in Lua using the JNLua interface.

I posted a follow up with another question regarding attaching to a Java process after I set all of this up. The post is here:
http://www.eclipse.org/forums/index.php/m/1220255/

In summary, there appear to be problems with debugging with LDT where the files are loaded from lua_load() (the dynamic code comment). There was one little excerpt in this forum that caught my attention in how the developer solved his problem:
"To use an embedded script you need to load it in the style of luaL_loadfile, pushing the filename onto the stack first with lua_pushfstring(L, "@%s", filename); and removing it after calling luaL_loadbuffer."

Posting is here: http://www.eclipse.org/forums/index.php/mv/msg/486668/1057860/#msg_1057860

I posted a request with JNLua project to see if it makes sense to expose lua_pushfstring() and luaL_loadbuffer() but have not yet received a reply.

Either way, I found an alternative with ZeroBrane's Studio Lua Debugger. I installed and set a breakpoint, and without much configuration was able to debug my script.

Thanks again.

[Updated on: Wed, 11 December 2013 18:37]

Report message to a moderator

Previous Topic:Breakpoint not hit after attaching to Java application
Next Topic:LDT 1.1RC2 and LuaDocumentor 0.1.3 are out.
Goto Forum:
  


Current Time: Wed Oct 22 23:06:28 GMT 2014

Powered by FUDForum. Page generated in 0.01705 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software