Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect if internal console #3108

Closed
wants to merge 2 commits into from

Conversation

gfszr
Copy link
Contributor

@gfszr gfszr commented Aug 15, 2022

This PR is currently as draft to better improve implementation and pass tests.
This PR partially implements #3094, by implementing redirection of stdout and stderr to the debug console via DAP's OutputEvent's on Linux.

It partially does so as current debug backend API support receiving a path to a redirected file only, and not a io.Writer as an example. It also supports only the native backend and not other backends.

Achieving full support would require adding a generalized API so that we can pass an io.Writer to the native backend nicely, but this can be done later on and be discussed more, while Linux support can be easily implemented.

@gfszr gfszr force-pushed the redirect-if-internal-console branch 2 times, most recently from 5991d03 to 8679c98 Compare August 16, 2022 06:37
@gfszr gfszr marked this pull request as draft August 16, 2022 07:24
@@ -326,7 +326,7 @@ func openRedirects(redirects [3]string, foreground bool) (stdin, stdout, stderr
return dflt
}
var f *os.File
f, err = os.Create(path)
f, err = os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0o666)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a backwards incompatible change because you are not passsing O_TRUNC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add it - I still need to check whether O_TRUNC has any bad effect when opening a fifo.

// This is a var for testing
maxGoroutines = 1 << 10
)
// Max number of goroutines that we will return.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid unrelated reformats, they pollute blames and make merge conflicts unnecessarily harder.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My editor auto-formats using gofumpt, so it formatted some extra editted files. Will revert such changes.

@@ -1049,6 +1071,32 @@ func (s *Session) onLaunchRequest(request *dap.LaunchRequest) {
return
}

func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Followed a similar pattern I've seen later on of wrapping some logic in an inline function to ease breaking, not anything special - I can export it to a different method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you refer to this file, that pattern is to execute a defer, not to group anything.

)

func generateStdioTempPipes() (res [2]string, err error) {
err = errors.New("Unimplemented")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging this with just a linux implementation would be weird. This is enough of a prominent feature that having it implemented for one operating system implies that we have to implement it for at least the more important ones. I think it needs to support Windows and macOS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementing it to all platforms should be relatively easier if we can change the Redirects to not only be paths to stdout/stderr, but io.Writers. I'll implement complete support for native, which should be relatively easy to do soin that backend.

@@ -1049,6 +1071,32 @@ func (s *Session) onLaunchRequest(request *dap.LaunchRequest) {
return
}

func() {
if args.Console == "internalConsole" && runtime.GOOS == "linux" && (args.Backend == "default" || args.Backend == "native") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird that using internalConsole on an unsupported configuration fails silently. It's also weird that all values of console that aren't internalConsole are accepted as valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current behavior is that console is not checked, so it can also be completely invalid and dlv dap would accept it, so I'm not sure we necessarily have to validate the console argument.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suppose someone misspells internlaConsole, how do they notice?

Copy link
Contributor Author

@gfszr gfszr Aug 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually, such syntax can be checked in VSCode itself - it can present an error such as: "internalConsole" is not a valid "console" value".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not everyone uses vscode with dap. I thought that was the whole point of this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, true. I am not familiar with how every DAP client handles this, but adding an allowed list of declared DAP consoles (I think it is standardized) should be easy enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should just be the consoles that we support.

@gfszr
Copy link
Contributor Author

gfszr commented Aug 16, 2022

Thank you @aarzilli for the quick reply! 🙂
Added a few comments, will address your comments.

@gfszr gfszr force-pushed the redirect-if-internal-console branch from 8679c98 to 750a0b4 Compare October 1, 2022 11:47
@derekparker
Copy link
Member

Is this still being worked on @gfszr ?

@gfszr
Copy link
Contributor Author

gfszr commented Nov 16, 2022

Yes - currently having some difficulties on developing and testing on Windows and macOS, as requested in review.

@derekparker
Copy link
Member

Closing due to age.

@derekparker derekparker closed this Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants