delve/pkg/proc/native/proc_unix.go
Derek Parker 3e60ae202b *: Add --tty flag for debug / exec
This flag allows users on UNIX systems to set the tty for the program
being debugged by Delve. This is useful for debugging command line
applications which need access to their own TTY, and also for
controlling the output of the debugged programs so that IDEs may open a
dedicated terminal to show the output for the process.
2020-04-10 09:53:13 -07:00

31 lines
557 B
Go

// +build !windows
package native
import (
"fmt"
"os"
"os/exec"
isatty "github.com/mattn/go-isatty"
)
func attachProcessToTTY(process *exec.Cmd, tty string) (*os.File, error) {
f, err := os.OpenFile(tty, os.O_RDWR, 0)
if err != nil {
return nil, err
}
if !isatty.IsTerminal(f.Fd()) {
f.Close()
return nil, fmt.Errorf("%s is not a terminal", f.Name())
}
process.Stdin = f
process.Stdout = f
process.Stderr = f
process.SysProcAttr.Setpgid = false
process.SysProcAttr.Setsid = true
process.SysProcAttr.Setctty = true
return f, nil
}