actboy168 / lua-debug

Lua Debug Adapter for Visual Studio Code
MIT License
439 stars 95 forks source link

Debugger timeout and bad stdout output capture in the internal console #209

Closed benjaminGoldenRace closed 1 year ago

benjaminGoldenRace commented 1 year ago

I'm having issues when trying to debug lua, sometimes the debugger doesn't attach giving a timeout, other times nothing happens and I have to restart vs code to be able to press the debug button, and also the stdout captured in the internal console is not good. This is happening since version 1.60.2, in previous versions this was working properly.

actboy168 commented 1 year ago

What is your launch.json?

benjaminGoldenRace commented 1 year ago

I use two different configurations, the first one works more times than the second one:

{
    "name": "Debug LUA",
    "type": "lua",
    "request": "launch",
    "stopOnEntry": false,
    "runtimeExecutable": "${workspaceFolder}/Code/build/x32/Src/GoldenViewer/Debug/GoldenViewer.exe",
    "cwd": "${workspaceFolder}/_Output/win32/",
    "console": "internalConsole",
    "presentation": {
        "hidden": false,
        "group": "Lua"
    }
},
{
    "name": "Test LUA",
    "type": "lua",
    "request": "launch",
    "stopOnEntry": false,
    "runtimeExecutable": "${workspaceFolder}/_Output/tools/bin/lua/lua-5.3.5-win32/bin/lua.exe",
    "runtimeArgs": ["-e", "package.path=\"../../../_Output/tools/bin/lua/luarocks-3.3.1-windows-32/share/lua/5.3/?.lua;../../../_Output/tools/bin/lua/luarocks-3.3.1-windows-32/share/lua/5.3/?/init.lua;\"..package.path;package.cpath=\"../../../_Output/tools/bin/lua/luarocks-3.3.1-windows-32/lib/lua/5.3/?.dll;\"..package.cpath;local k,l,_=pcall(require,'luarocks.loader') _=k and l.add_context('busted','2.0.0-1')", "${workspaceFolder}/_Output/tools/bin/lua/luarocks-3.3.1-windows-32/lib/luarocks/rocks-5.3/busted/2.0.0-1/bin/busted", "${file}"],
    "cwd": "${workspaceFolder}/Code/tests/luaTests/",
    "console": "internalConsole",
    "presentation": {
        "hidden": false,
        "group": "Lua"
    }
},
actboy168 commented 1 year ago

I can't reproduce it. Can you provide a reproducible example?

benjaminGoldenRace commented 1 year ago

I've been testing with different configurations and the whole problem seems to be related with some kind of race condition capturing the stdout/stderr of the lua process when using internalConsole. With previous versions (before 1.60.2) the output is always captured correctly, but with the new versions the output seems to be captured only sometimes.

I've written a simple lua test that prints some text to the stdout and stderr, if you run the program without any breakpoint ("stopOnEntry": false), almost always the Debug Console of VSCode will be empty, but if you set a breakpoint and slowly run line by line, the text will appear in the console.

lua-debug-test.zip

This is very problematic when you have a bad configuration in the launch.json, because you can't see the error messages sometimes, and seems that the deubber is not attaching the runtime, but the real problem was some bad configuration that you can't see.

benjaminGoldenRace commented 1 year ago

With the version 1.61.0 the stdout is working now, but the stderr stream is not shown in the Debug Console of the VSCode with the lua-debug.test.zip