Open Catalyn45 opened 4 days ago
Also to mention that the output of the detached process is redirected, which cause that the console of the dlv
process itself to close, thus not passing it to the debugged process, forcing the debugged process to make a new one.
Example of go code for creating detached dlv
process with redirected output:
package main
import (
"fmt"
"os"
"syscall"
)
const (
DETACHED_PROCESS = 0x00000008
)
func main() {
// Path to the executable
exePath := "D:\\repos\\delve\\dlv.exe"
argv := []string{exePath}
argv = append(argv, os.Args[1:]...)
// Process attributes
procAttr := &os.ProcAttr{
Files: []*os.File{
os.Stdin,
os.Stdout,
os.Stderr,
},
Sys: &syscall.SysProcAttr{
CreationFlags: DETACHED_PROCESS,
},
}
// Start the process
process, err := os.StartProcess(exePath, argv, procAttr)
if err != nil {
fmt.Printf("Error starting process: %v\n", err)
return
}
fmt.Printf("Detached process started with PID: %d\n", process.Pid)
// Wait for process to finish
state, err := process.Wait()
if err != nil {
fmt.Printf("Error waiting for process: %v\n", err)
}
fmt.Printf("exit code: %d\n", state.ExitCode())
}
So basically you could compile this program, then run output.exe dap -l 127.0.0.1:1234
, then try to connect with a dap client and start debugging something.
Figuring out how to setup and use nvim, nvim-dap and nvim-go-dap on windows sounds like something that would take me a long time, but I think I figured out how to reproduce and fix this problem using your program. Can you test https://github.com/go-delve/delve/pull/3867 and see if it works?
Tested your fix and it seems it solves the issue.
Thanks for working on that.
dlv version
)?1.23.1
go version
)?go1.22.0
Windows x64
dlv dap
server as detached process and connected to it with neovim dap client.goroutine 25 [running, locked to thread]: github.com/go-delve/delve/pkg/proc/native.(nativeProcess).addThread(0x0, 0x2b0, 0x10bc, 0x10?, 0x0, 0x0) D:/repos/delve/pkg/proc/native/proc_windows.go:302 +0x42 github.com/go-delve/delve/pkg/proc/native.(processGroup).waitForDebugEvent(0xc000382080, 0x1) D:/repos/delve/pkg/proc/native/proc_windows.go:406 +0x5e7 github.com/go-delve/delve/pkg/proc/native.initialize.func1() D:/repos/delve/pkg/proc/native/proc_windows.go:84 +0x25 github.com/go-delve/delve/pkg/proc/native.(*ptraceThread).handlePtraceFuncs(0xc0000c01b0) D:/repos/delve/pkg/proc/native/proc.go:405 +0x48 created by github.com/go-delve/delve/pkg/proc/native.newPtraceThread in goroutine 6 D:/repos/delve/pkg/proc/native/proc.go:492 +0xc6