-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg/proc,service/*: Supports sending output to clients when running p…
…rograms remotely (#3253) * wip: Support sending output when remote debug * wip: Support local output and remote output * wip: fix stderr and stdout assignment error * wip: optimize code * wip: Only if outputMode is "remote" is the redirected console output * wip: Redirected debugMode output(Not tested on windows) * wip: support remote debugging output redirection of windows * wip: real-time write back output * wip: support for windows * wip: fix windows remote debug not output * wip: fix truncated output redirection * wip: delete printfln * wip: use debugger.Config to pass redirect(macOS) * wip: use debugger.Config to pass redirect(linux) * wip: Change redirect to a concrete type * wip: s.wg.wait before sending "terminated" * wip: add proc/redirect test(darwin and linux) * Merge branch 'master' of github.com:tttoad/delve into feat-console * wip: Fix test failure on windows * fix: undefined: proc.Redirects * fix: compile failure * wip: Remove useless code * fix: filename error * fix: os.file not close * test: add server_test.redirect * fix: Remove 'eol' from end of file * fix: gdbserial: File not closed in file mode. (in reality, gdbserial will never use file mode) * feat: Remove "only-remote". Fix spelling mistakes. * fix: spelling mistakes * refactor: redirect * fix: stdout and stderr are not set to default values * fix: Restore code logic for rr.openRedirects() * fix: Optimization Code * fix: utiltest * fix: execpt out * fix: Resource release for redirects * fix: build failure * fix: clean->clear * fix: build failure * fix: test failure * fix: Optimization Code * style: remove useless code * refactor: namedpipe * refactor: namedpipe, launch ... * fix: freebsd compile failure * fix: proc_darwin compile failure * style: remove useless code * feat: add d.config.Stdxx check on debug.Restart * style: formatting and adding comments * style: formatting and adding comments * feat: add d.config.Stdxx check on debug.Restart * style: namedpipe->redirector * style: namedPipe->redirector --------- Co-authored-by: 李翔 <qian.fu2@amh-group.com>
- Loading branch information
Showing
20 changed files
with
399 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
func main() { | ||
fmt.Println("hello world!") | ||
fmt.Fprintf(os.Stdout, "hello world!") | ||
fmt.Fprintf(os.Stderr, "hello world!\n") | ||
fmt.Fprintf(os.Stderr, "hello world! error!") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package proc | ||
|
||
import "os" | ||
|
||
// OutputRedirect Specifies where the target program output will be redirected to. | ||
// Only one of "Path" and "File" should be set. | ||
type OutputRedirect struct { | ||
// Path File path. | ||
Path string | ||
// File Redirect file. | ||
File *os.File | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package proc | ||
|
||
import ( | ||
"crypto/rand" | ||
"encoding/hex" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
"syscall" | ||
) | ||
|
||
type openOnRead struct { | ||
path string | ||
rd io.ReadCloser | ||
} | ||
|
||
func (oor *openOnRead) Read(p []byte) (n int, err error) { | ||
if oor.rd != nil { | ||
return oor.rd.Read(p) | ||
} | ||
|
||
fh, err := os.OpenFile(oor.path, os.O_RDONLY, os.ModeNamedPipe) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
oor.rd = fh | ||
return oor.rd.Read(p) | ||
} | ||
|
||
func (oor *openOnRead) Close() error { | ||
defer os.Remove(oor.path) | ||
|
||
fh, _ := os.OpenFile(oor.path, os.O_WRONLY|syscall.O_NONBLOCK, 0) | ||
if fh != nil { | ||
fh.Close() | ||
} | ||
|
||
return oor.rd.Close() | ||
} | ||
|
||
func Redirector() (reader io.ReadCloser, output OutputRedirect, err error) { | ||
r := make([]byte, 4) | ||
if _, err = rand.Read(r); err != nil { | ||
return reader, output, err | ||
} | ||
|
||
var path = filepath.Join(os.TempDir(), hex.EncodeToString(r)) | ||
|
||
if err = syscall.Mkfifo(path, 0o600); err != nil { | ||
_ = os.Remove(path) | ||
return reader, output, err | ||
} | ||
|
||
return &openOnRead{path: path}, OutputRedirect{Path: path}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package proc | ||
|
||
import ( | ||
"io" | ||
"os" | ||
) | ||
|
||
func Redirector() (reader io.ReadCloser, output OutputRedirect, err error) { | ||
reader, output.File, err = os.Pipe() | ||
|
||
return reader, output, err | ||
} |
Oops, something went wrong.