pkulchenko / ZeroBraneStudio

Lightweight Lua-based IDE for Lua with code completion, syntax highlighting, live coding, remote debugger, and code analyzer; supports Lua 5.1, 5.2, 5.3, 5.4, LuaJIT and other Lua interpreters on Windows, macOS, and Linux
http://studio.zerobrane.com/
Other
2.62k stars 518 forks source link

debug openresty faild on linux #1002

Closed algtm closed 5 years ago

algtm commented 5 years ago

I follow the official guide to install openresty1.15 with apt in ubuntu18/16 and install zbs with bash 。 And follow this guide: to debug openresty But it shows error on serverside:

Can't start debugging for '/usr/local/openresty/nginx/lua/content.lua'. Compilation error:
Debugger connection closed
Debugging session completed (traced 0 instructions).

/usr/local/openresty/nginx/lua/content.lua

require('mobdebug').start('127.0.0.1')
local name = ngx.var.arg_name or "Anonymous"
ngx.say("Hello, ", name, "!")
ngx.say("Done debugging.")
require('mobdebug').done()

zbs project path /usr/local/openresty/nginx/lua/

nginx.conf

worker_processes  1;
events {
    worker_connections  1024;
}
http {
 lua_package_path '/opt/zbstudio/lualibs/?/?.lua;/opt/zbstudio/lualibs/?.lua;';
    lua_package_cpath '/opt/zbstudio/bin/linux/x64/clibs/?.so;';
    server {
        location /hellolua {
           default_type 'text/plain';
           content_by_lua_file 'lua/content.lua';
        }
    }
}

I have tried to change the system to centos7、ub16 and windows. Only windows work(all debug is local). But the lib I want to debug only support linux orz.

algtm commented 5 years ago

i fix this problem by use operesty with lua5.1 not luajit

pkulchenko commented 5 years ago

@vulntor, thank you for the update. I'd still be interested to know why it changed the result, as in this there shouldn't be much difference between lua5.1 and luajit. From the output you are showing, it looked like the debugging has started and then aborted after an error in the application. Were there any errors from luajit in nginx logs? Maybe there was some conflict with jit being set "on" by nginx and then set "off" by the debugger to make debug hooks to work properly?

algtm commented 5 years ago

@pkulchenko There are no error info in nginx log.But I use printlog to find that coro_debugger = corocreate(debugger_loop) not work in openresty's lua2 .Follow the stack and i find var ngx was set to nil after local ngx = type(metagindex) == "table" and metagindex.rawget and metagindex:rawget("ngx") or nil

In windows openresty use lua5.1 by default so I think this different is because mobdebug not support the special version luajit in openresty official install for linux. Then I build Nginx with lua5.1/luajit2.0.5/luajit2.1 beta3 and they all work well.

It seems Openresty use a luajit designed for openresty only because I saw this warning:

nginx: [alert] detected a LuaJIT version which is not OpenResty's; many optimizations will be disabled and performance will be compromised (see https://github.com/openresty/luajit2 for OpenResty's LuaJIT or, even better, consider using the OpenResty releases from https://openresty.org/en/download.html)
pkulchenko commented 5 years ago

@vulntor, interesting; thank you for the update. I wonder why the value of ngx is nil though in mobdebug.

Can you check the previous line (local metagindex = getmetatable(genv) and getmetatable(genv).__index) to see if there is indeed a metatable on _G and if there is, is it missing it's __index value or if ngx is not present there? Thanks!

algtm commented 5 years ago

@pkulchenko I am sorry I can't spend much on this. I am not very familiar with Lua. It's easy to Reproduce by install latest openresty.

pkulchenko commented 5 years ago

np; thanks for letting me know. I'll close the ticket, since you found a solution and will take a look when I get a chance.