pkulchenko / MobDebug

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

Official document on debugging openresty is a bit misleading #67

Closed brynne8 closed 2 years ago

brynne8 commented 2 years ago

ref: http://notebook.kulchenko.com/zerobrane/debugging-openresty-nginx-lua-scripts-with-zerobrane-studio

MobDebug is one of the best ways to debug OpenResty. But the doc is a bit misleading about the configuration. In the example config

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    lua_package_path '<ZBS>/lualibs/?/?.lua;<ZBS>/lualibs/?.lua;;';
    lua_package_cpath '<ZBS>/bin/clibs/?.dll;;';
    server {
        location /hellolua {
           default_type 'text/plain';
           content_by_lua_file 'lua/content.lua';
        }
    }
}

It points the lua package path and cpath to the libs in the ZeroBrane Studio path, which isn't common way of setting these paths. This example made us to think that MobDebug relies on libraries introduced by ZeroBrane to work, but actually only LuaSocket is needed for debugging, and pointing the paths to <ZBS>/... is not needed.

Copy <ZBS>/bin/clibs/socket/core.dll to <NGINX>/socket/core.dll (core.dylib and core.so files are in the bin folder as well).

The LuaSocket binary lib can also be incompatible with OpenResty or ngx-lua, so it's better to tell people to install LuaSocket compatible with OpenResty, or to compile LuaSocket themselves using the same environment as OpenResty.

pkulchenko commented 2 years ago

Why is it misleading? I find that it's safer to reference the libs from the ZeroBrane Studio folder rather than to copy them to the NGINX folders, but you definitely have the option of doing it the way you described.

brynne8 commented 2 years ago

Because we often don't need to use lua and c libraries from ZeroBrane in a real-world nginx-lua application. We often point the paths elsewhere where our luajit and batteries installed, and use ZeroBrane as a remote debugger.

pkulchenko commented 2 years ago

I agree, but the instructions are in the context of debugging that application and you'd need that reference to debug it (and wouldn't need in all other cases).