
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.
31 lines
557 B
Go
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
|
|
}
|