Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

无法调试lua #198

Open
constly opened this issue Jul 30, 2024 · 5 comments
Open

无法调试lua #198

constly opened this issue Jul 30, 2024 · 5 comments

Comments

@constly
Copy link
Contributor

constly commented Jul 30, 2024

我按readme中的说明,把launch.json中的配置为:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lua",
            "request": "launch",
            "name": "Debug",
            "luaexe": "${workspaceFolder}/bin/msvc/debug/ant.exe",
            "luaVersion": "lua-latest",
            "path": null,
            "cpath": null,
            "console": "integratedTerminal",
            "stopOnEntry": true,
            "outputCapture": [],
            "program": "test/simple/main.lua",
            "arg": []
        }
    ]
}

在vscode中以调试方式启动时没反应,输出为:

PS F:\ant\ant>  f:; cd 'f:\ant\ant'; & 'F:/ant/ant/bin/msvc/debug/ant.exe' '-e' 'dofile[[c:/Users/Administrator/.vscode/extensions/actboy168.lua-debug-2.0.10-win32-x64/script/launch.lua]];DBG[[17344/lua-latest]]' 'test/simple/main.lua' 
PS F:\ant\ant> 

看起来没启动成功,程序直接退出了。我打开任务管理器,可以看到有lua-debug.exe。
之前是可以调试的,不知道那次更新后就不行了。

@cloudwu
Copy link
Contributor

cloudwu commented Jul 31, 2024

要更新调试器。vscode 的那个更新了没? @actboy168

@actboy168
Copy link
Contributor

@constly 我测试是没问题的,你是不是没更新调试器。

@constly
Copy link
Contributor Author

constly commented Jul 31, 2024

昨天晚上卸载重装了Lua Debug插件,不得行,不过今天早上来引擎的demo项目可以调试了(可能是重启了电脑)。

现在我这里自己的项目以及vaststars依然不能调试,
vaststars调试报错为:

PS G:\ant\github\vaststars>  & 'G:/ant/github/vaststars/bin/msvc/debug/ant.exe' '-e' 'dofile[[c:/Users/username/.vscode/extensions/actboy168.lua-debug-2.0.10-win32-x64/script/launch.lua]];DBG[[38296/lua-latest]]' 'startup/main.lua'
Service 1 error: /engine/firmware/ltask_service.lua:1: attempt to index a nil value
stack traceback:
        /engine/firmware/ltask_service.lua:1: in main chunk
PS G:\ant\github\vaststars>

vaststars的launch.json为:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lua",
            "request": "launch",
            "name": "Debug",
            "luaexe": "${workspaceFolder}/bin/msvc/debug/ant.exe",
            "luaVersion": "lua-latest",
            "path": null,
            "cpath": null,
            "console": "integratedTerminal",
            "stopOnEntry": true,
            "outputCapture": [],
            "program": "startup/main.lua",
            "arg": []
        }
    ]
}

@xingxingtie
Copy link

PS G:\ant\github\vaststars>  & 'G:/ant/github/vaststars/bin/msvc/debug/ant.exe' '-e' 'dofile[[c:/Users/username/.vscode/extensions/actboy168.lua-debug-2.0.10-win32-x64/script/launch.lua]];DBG[[38296/lua-latest]]' 'startup/main.lua'
Service 1 error: /engine/firmware/ltask_service.lua:1: attempt to index a nil value
stack traceback:
        /engine/firmware/ltask_service.lua:1: in main chunk
PS G:\ant\github\vaststars>

深感认同,这个报错我调试时也一直出现。即使用最新的Lua Debug也不行 跟踪了一下发现 ant/engine/firmware/debugger.lua 运行时有一个path一直获取的是空。 @constly 要不你也看下你的是不是也这样。

local function dofile(filename)
    local f = assert(io.open(filename))
    local str = f:read "a"
    f:close()
    return assert(load(str, "=(debugger.lua)"))(filename)
end

local path = os.getenv "LUA_DEBUG_PATH"
if path then  --此处path为nil,获取不到环境变量值。
    return dofile(path)
        : attach {}
end

@xingxingtie
Copy link

继续跟踪到C:\Users\abc\.vscode\extensions\actboy168.lua-debug-2.0.10-win32-x64\script\debugger.lua 第148行附近,添加打印

    local isWindows = package.config:sub(1, 1) == "\\"
    if isWindows then
        assert(package.loadlib(luadebug, 'init'))(cfg.luaapi)
    end

    ---@type LuaDebug
    dbg.rdebug = assert(package.loadlib(luadebug, 'luaopen_luadebug'))()
    if not os.getenv "LUA_DEBUG_PATH" then
	print("set path:", selfsource)    --添加打印
        dbg.rdebug.setenv("LUA_DEBUG_PATH", selfsource)
	print("get path:", os.getenv("LUA_DEBUG_PATH"))   --添加打印
	print("java home path:", os.getenv("JAVA_HOME"))  --添加打印
    else 
	print("pre set:", os.getenv("LUA_DEBUG_PATH"))
    end

打印结果是:

set path:       c:/Users/abc/.vscode/extensions/actboy168.lua-debug-2.0.10-win32-x64/script/debugger.lua
get path:       nil
java home path: D:\Program Files\Java\jdk-19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants