vscode emmy_lua调试OpenResty lua代码
背景
我是windows下的vscode远程开发linux下的openresty项目,现需要调试lua代码,因此vscode安装了emmy_lua 0.5.3到远程服务器
过程
在vscode里安装最新版的emmy_lua,但是调试时候报version `GLIBC_2.28' not found
就是emmy_core.so需要高版本的gclib,加入emmy_lua群后热心的大佬说自己编译debugger,步骤如下
git clone https://github.com/EmmyLua/EmmyLuaDebugger.git
cd EmmyLuaDebugger/
cmake .
make && make install
# 这个目录在vscode中安装了扩展后就会有
mv /root/.vscode-server/extensions/tangzx.emmylua-0.5.3/debugger/emmy/linux/emmy_core.so /root/.vscode-server/extensions/tangzx.emmylua-0.5.3/debugger/emmy/linux/emmy_core.so.bak
cd emmy_core/
cp emmy_core.so /root/.vscode-server/extensions/tangzx.emmylua-0.5.3/debugger/emmy/linux
vscode launch.json配置
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "emmylua_new",
"request": "launch",
"name": "EmmyLua New Debug",
"host": "localhost",
"port": 9955,
"ext": [
".lua",
".lua.txt",
".lua.bytes"
],
"ideConnectDebugger": false
},
{
"name": "Open Resty",
"type": "cppdbg",
"request": "launch",
"program": "/learn/openresty/install/bin/openresty",//需要配置
"cwd": "/learn/openresty/example/openresty/simplehttp",
"args": ["-c", "/learn/openresty/example/openresty/simplehttp/conf/nginx.conf"],
"stopAtEntry": false,
"environment": [],
"externalConsole": false,//可以配置,这边不能搞成true
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
}
]
}
当然在能正常调试前,还需要做些准备工作
worker_processes 1;
events {
worker_connections 512;
}
daemon off;
master_process off;
http {
# 此处配置init.lua
init_by_lua_file /learn/openresty/example/openresty/simplehttp/service/http/init.lua;
server {
listen 80;
server_name *.*;
location = /example {
# 仅有rewrite是不行的。需要有content返回,否则404
rewrite_by_lua_file /learn/openresty/example/openresty/simplehttp/service/http/rewrite_example.lua;
content_by_lua_file /learn/openresty/example/openresty/simplehttp/service/http/content_example.lua;
}
location /test {
content_by_lua_block {
ngx.say("hello, world1")
}
}
}
}
init.lua如下
package.cpath = package.cpath .. ";/root/.vscode-server/extensions/tangzx.emmylua-0.5.3/debugger/emmy/linux/emmy_core.so"
-- 这边引入了emmy_core,我们重新编译的就是这个
local dbg = require("emmy_core")
-- 连接到emmy debugger监听的端口
dbg.tcpConnect("localhost", 9966)
按照上面的配置,那么调试的步骤是先启动emmy_lua_new, 监听9966端口,再启动OpenResty。
在rewrite_example.lua文件中设置断点,访问localhost/example即可进入断点:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?