actboy168 / lua-debug

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

Attach LUA with processName not working #47

Closed yosoymin closed 3 years ago

yosoymin commented 5 years ago

I'm trying to attach to a process with Lua 5.3.5 embedded that works perfectly in launch mode, but when trying to attach to it using the processName attribute, the debugger hangs and doesn't connect / inject debugger.dll into the process. This is my launch configuration:

{
    "name": "Attach LUA",
    "type": "lua",
    "request": "attach",
    "stopOnEntry": true,
    "processName": "GoldenViewer.exe",
    "consoleCoding": "utf8"
}

I've tried to debug the problem and what I've seen is that when using processName, the debugger (lua-debug.exe) uses stdio.lua module, that is implemented with bee.subprocess, and at the end a call to PeekNamedPipe(stdin, ...) is done, but in my case is always returning 0 bytes from the pipe, so never continues to the lua code proto.recv(STDIN:read(n), stat), and starts de update loop again.

I don't really understand the meaning of all this, I suppose vscode writes something in the stdin of the debugger to communicate with it, and lua-debug.exe is not receiving in stdin for some reason, but it's only a guess.

It's really an issue? I think I'm doing something wrong, can someone help me? Thanks

yosoymin commented 5 years ago

Ok, I was wrong when I said before that PeekNamedPipe return 0. I've activated the log and I can see this in the client.log file:

[2019-04-06 00:09:55][...extensions\actboy168.lua-debug-0.8.1\client\protocol.lua: 37][INFO  ] [recv] {"command":"initialize","arguments":{"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"lua","pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true,"supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"locale":"es"},"type":"request","seq":1}
[2019-04-06 00:09:55][...extensions\actboy168.lua-debug-0.8.1\client\protocol.lua: 51][INFO  ] [send] {"command":"initialize","request_seq":1,"type":"response","success":true,"body":{"supportsConfigurationDoneRequest":true,"supportsEvaluateForHovers":true,"supportsTerminateRequest":true,"supportsSetVariable":true,"exceptionBreakpointFilters":[{"filter":"pcall","label":"Exception: Lua pcall","default":false},{"filter":"xpcall","label":"Exception: Lua xpcall","default":false},{"filter":"lua_pcall","label":"Exception: C lua_pcall","default":true},{"filter":"lua_panic","label":"Exception: C lua_panic","default":true}],"supportsConditionalBreakpoints":true,"supportsExceptionInfoRequest":true,"supportsLoadedSourcesRequest":true,"supportsHitConditionalBreakpoints":true,"supportsLogPoints":true,"supportsDelayedStackTraceLoading":true},"seq":1}
[2019-04-06 00:09:55][...extensions\actboy168.lua-debug-0.8.1\client\protocol.lua: 37][INFO  ] [recv] {"command":"attach","arguments":{"name":"Attach LUA","type":"lua","request":"attach","stopOnEntry":true,"processName":"GoldenViewer.exe","consoleCoding":"utf8","workspaceFolder":"D:\\Code\\Nebula\\GoldenViewer\\Data","cwd":"D:\\Code\\Nebula\\GoldenViewer\\Data","sourceCoding":"ansi","outputCapture":["print","io.write","stderr"],"__sessionId":"dfd6ddc1-883a-4aea-86bd-965df195719a"},"type":"request","seq":2}

But, after that, anything else happens, the debugger doesn't connect and stays waiting to something at infinitum.

actboy168 commented 5 years ago

I have fixed it, if you still can't work, please let me know.

yosoymin commented 5 years ago

Now it's working ok. Thank you. There is only a little issue: if you detach and try to attach again to the same process, the debugger won't work, but I think this is not really important at all.