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

launch.json - add option for logging stdout/stderr to file #140859

Closed
stellarpower opened this issue Jan 17, 2022 · 9 comments
Closed

launch.json - add option for logging stdout/stderr to file #140859

stellarpower opened this issue Jan 17, 2022 · 9 comments
Assignees
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues feature-request Request for new features or functionality

Comments

@stellarpower
Copy link

My application dumps useful information to stdout / stderr when I run it. When debugging, I'd like to be able to copy this to a file automatically, rather than need to use some wort of wrapper script that calls tee, copy-paste from the output console, or run separately to capture this. There may well be an existing workaround, but as this is quite a simple and I imagine commonly useful feature request, I think it would be nice to add support for it on its own.

I'd propose adding an option similar ot this to launch.json, most likely keeping it simple as it's a pretty trivial addition:

// ...
configurations: [{
    "name": "Foo",
    "type": "cppdbg",
    "request": "launch",
    "program": "${workspaceFolder}/main",

    // ...
    "log": {
        "stdout": "/path/to/file.out"
        "stderr": "/path/to/file.err"
        "stdin":  "/path/to/file.in" // Optional - capture anything typed into the run console.
     }
    // ...
        },
// ...
@weinand weinand added the debug Debug viewlet, configurations, breakpoints, adapter issues label Jan 17, 2022
@weinand weinand added the feature-request Request for new features or functionality label Jan 17, 2022
@weinand
Copy link
Contributor

weinand commented Jan 17, 2022

@stellarpower in theory this feature request sounds simple to implement but in reality it is difficult.

The problem is that VS Code knows nothing about "stdout/stdin/stderr" of the debuggee because only the debug extension controls the debuggee and "knows" if it supports "stdout/stdin/stderr" and whether it is possible to redirect "stdout/stdin/stderr" to/from a file.

So in your case the C/C++ extension would be in a much better position to implement that feature. I suggest to file a feature against the C/C++ extension too.

@stellarpower
Copy link
Author

Thanks for the fast response!

Afraid I'm not sure I understand, what do you mean by if the debuggee supports stdout/stdin/stderr? Every process forked ought to have at least these file descriptors opened I believe.

Presumably for any extenson being used to debug, if it outputs something to the integrated console as part of this it'd need to get access to the console in the same way as a different extension, wouldn't it?

@weinand
Copy link
Contributor

weinand commented Jan 17, 2022

@stellarpower VS Code does not know anything about "forked processes". It is the debug extension that might fork the debuggee. But when debugging Javascript running in a browser, or when attaching a debugger to an already running process, there is no need to "fork a process" and as a consequence there is nothing like "stdout/stdin/stderr".

If a debug extension starts a debuggee in the integrated (or external) terminal, then the debuggee's "stdout/stdin/stderr" are managed directly by the integrated terminal's shell. In this case not even the debug extension sees the input/output to/from "stdout/stdin/stderr". Only if the debuggee is launched in the debug console, has the debug extension a chance to see the stdout/stderr (but not even stdin, a missing piece currently discussed in microsoft/debug-adapter-protocol#216).

@stellarpower
Copy link
Author

stellarpower commented Jan 17, 2022 via email

@weinand
Copy link
Contributor

weinand commented Jan 17, 2022

Yes, the command that is used to run the debuggee in the shell could redirect "stdout/stdin/stderr". But this command is an implementation detail of the debug extension and not controlled by VS Code, so VS Code can not support this generically. So only the debug extension could implement this.

What makes things complex on that front is the fact that for many debuggers the debuggee is not directly launched in the shell but indirectly from within a command line debugger like "gdb". Redirecting "stdout/stdin/stderr" of "gdb" does not help redirecting "stdout/stdin/stderr" of the debuggee.

Bottom line: don't hold your breath while waiting for VS Code to implement this feature anytime soon - it is more realistic that individual debug extensions will implement that feature.

@weinand
Copy link
Contributor

weinand commented Jan 18, 2022

@stellarpower vscode-lldb supports stdio redirection already as part of the launch configuration: https://github.com/vadimcn/vscode-lldb/blob/master/MANUAL.md#stdio-redirection

@github-actions github-actions bot locked and limited conversation to collaborators May 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

4 participants
@roblourens @weinand @stellarpower and others