This is an archive of the discontinued LLVM Phabricator instance.

[lldb-vscode] Implement stderr/stdout on win32 and redirect lldb log to VSCode
ClosedPublic

Authored by nidefawl on Apr 4 2022, 5:37 AM.

Details

Summary

This patch implements stderr/stdout forwarding on windows.
This was previously not implemented in D99974.
I added separate callbacks so the output can be sent to the different channels VSCode provides (OutputType::Stdout, OutputType::Stderr, OutputType::Console).

This patch also passes a log callback handler to SBDebugger::Create to be able to see logging output when it is enabled.

Since the output is now redirect on early startup I removed the calls to SetOutputFileHandle/SetErrorFileHandle, which set them to /dev/null.

I send the output of stderr/stdout/lldb log to OutputType::Console

Diff Detail

Event Timeline

nidefawl created this revision.Apr 4 2022, 5:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 4 2022, 5:37 AM
nidefawl requested review of this revision.Apr 4 2022, 5:37 AM
nidefawl edited the summary of this revision. (Show Details)Apr 4 2022, 5:37 AM
mstorsjo added inline comments.
lldb/tools/lldb-vscode/OutputRedirector.cpp
15

Minor style issue - I guess it'd be less of double negation, if we'd change the ifdef to #if defined(_WIN32) .. #else

55

This change looks unrelated (although I'm not familiar with this piece of code), although it's probably correct

wallace added inline comments.Apr 4 2022, 9:43 PM
lldb/tools/lldb-vscode/OutputRedirector.cpp
15

feel free to refactor that part

lldb/tools/lldb-vscode/lldb-vscode.cpp
1444–1449

could you test by creating a .lldbinit file with garbage so that the debugger prints error messages during initialization, and then make sure that they are properly redirected to the console of the IDE?

nidefawl updated this revision to Diff 420531.Apr 5 2022, 8:59 AM

Reorder OS check to remove negation

nidefawl marked 2 inline comments as done.Apr 5 2022, 9:00 AM
nidefawl added inline comments.
lldb/tools/lldb-vscode/OutputRedirector.cpp
55

The reference to the StringRef is never stored, so this avoids a copy.
VSCode::SendOutput takes a StringRef and explicitly converts it to std::string before emplacing it in the json message.

lldb/tools/lldb-vscode/lldb-vscode.cpp
1444–1449

Yes, I can see the error messages in the VSCode debugger console. Both on windows and linux.

nidefawl marked 4 inline comments as done.Apr 5 2022, 9:02 AM
wallace accepted this revision.Apr 5 2022, 9:27 AM

thank you!

This revision is now accepted and ready to land.Apr 5 2022, 9:27 AM

Let me know if you need help upstreaming this patch.

nidefawl added a comment.EditedApr 5 2022, 10:30 AM

Let me know if you need help upstreaming this patch.

Yes I need some help.
This is my first contribution. I don't have commit access.

ok! I'll commit it for you