Doing this for 2 main reasons:
- Avoid stdout from corrupting DAP messages
- Make sure we can see in VSCode (or any other DAP client) the same output we see when debugging from the command line
Differential D80659
[lldb-vscode] Redirect stderr and stdout to DAPs console message wallace on May 27 2020, 1:14 PM. Authored by
Details
Diff Detail
Event TimelineComment Actions I don't actually use vscode, so I don't really know whether this is a good idea, but if you say it is then I can go with that. However, I think the implementation needs a lot of work:
The way I would imagine doing this is:
The stop forwarding is the trickiest part I think the most portable solution would be to just close the write end of the pipe, and join the forwarding thread (which will exit once read returns EOF). We should also think about testing all of this. Do we have a reliable mechanism to produce stdout/err output from lldb? I guess it the worst case we could try debugging a module which produces one of these warnings. Or, if this output is going to the same place as the SBDebuggers notion of stdout/err, then we could just stop calling SetOutputFileHandle, and have everything flow through this. That would reduce the overall complexity and would ensure this path gets better coverage, as it would be used in the common case instead of just for printing random errors. Comment Actions thanks for the feedback, I'll read it more carefully later. As for the tests it should be easy to set up, didn't want to spend time on that before we agreed on doing it this way. Comment Actions Btw, given that Richard has found some vscode code which already tries to send stderr to the console window https://github.com/microsoft/vscode/blob/master/src/vs/workbench/contrib/debug/node/debugAdapter.ts#L234, it would be good to first understand why doesn't that kick in. Maybe there's a vscode bug that could be fixed instead. Comment Actions The issue is fairly clear, that listener is only added if the optional constructor arg outputService is defined, but it never is. I was planning on putting up a diff this week some time to always read from stderr regardless. Comment Actions This update still doesn't add windows support but I just want to get a feel that I'm going on the right direction.
this turned out to be harder than I thought it would be, my plan was to print to stdout in python from a thread but I never see that print anywhere (not sure why though). A sure way to test this (what I did manually) is to put a script print('foo') command in lldninit. Unfortunately I can't use a local lldbinit since that's a concept of the lldb binary and not of liblldb (unless we want to add that option to lldb-vscode as well), so not really sure about this as well.
There no guarantee of this, people can just use sys.stdout.write in python.
I would still prefer to wrap liblldb's stderr into a console message so people can see it in the client(e.g.: VSCode) console rather than outputting it through the lldb-vscode stderr which will then be up to the client to decide what to do with it. Comment Actions Sorry, I missed this patch. Modulo the inline comments and the missing windows support and tests, I think this patch is ok-ish. However, I am still not convinced of its usefulness. Why would we be doing something (particularly a thing which will be hard to do in a cross-platform manner, and will very likely border on, or downright cross into, undefined behavior territory), if we get that from vscode for free?
Comment Actions
I'm not sure what you mean with get this for free on vscode... Right now lldb-vscode will just crash if there's any command in the lldbinit that outputs to stdout because it pollutes the protocol, I don't think think there's anything vscode can do about this. But even if it did vscode is not the only client of lldb-vscode, there are multiple others: https://microsoft.github.io/debug-adapter-protocol/implementors/tools/. I haven't answered this yet because I was trying to figure out why this only happens when parsing the lldbinit. I was looking into the CommandInterpreter{Python} code but to be honest it's not easy to figure out because there are multiple levels of indirection when it comes to processing the IO of the python interpreter, but it seems that the stdout while executing the lldbinit script is being flushed right away to the ImmediateOutputStream but haven't figure out when this is set in the case of CommandInterpreter::IOHandlerInputComplete. Comment Actions Sorry, I confused this with the patch that was wrapping stderr into DAP messages. Having python output break the protocol is definitely not good. Fixing it would be nice, but the solution should work on windows as well. One possibility I'd consider is making this fix at the python level (as this is a python problem). We already are trying to do some stdin/out/err redirection there, but it seems it's not good enough. It seems it should be easy enough (though hacky, but all of this is going to be hacky anyway) to replace sys.stdin/out/err with a custom wrapper object. |
clang-format not found in user's PATH; not linting file.