This is an archive of the discontinued LLVM Phabricator instance.

[lldb] [Host] Make Terminal methods return llvm::Error
ClosedPublic

Authored by mgorny on Oct 15 2021, 7:39 AM.

Diff Detail

Event Timeline

mgorny requested review of this revision.Oct 15 2021, 7:39 AM
mgorny created this revision.
mgorny updated this revision to Diff 380011.Oct 15 2021, 8:09 AM

Move common code and error handling to GetData() and SetData() methods.

mgorny retitled this revision from [lldb] [Host] Make Terminal methods return llvm::Error [WIP] to [lldb] [Host] Make Terminal methods return llvm::Error.Oct 15 2021, 8:10 AM
mgorny edited the summary of this revision. (Show Details)
mgorny added inline comments.
lldb/source/Host/common/Terminal.cpp
75

My gut feeling is telling me that this can be simplified somehow… or we could assume tcsetattr() is cheap and just do the change unconditionally.

labath added inline comments.Oct 17 2021, 11:45 PM
lldb/include/lldb/Host/Terminal.h
23

Move this into the protected section

lldb/source/Host/common/Terminal.cpp
75

yeah, I think it'd be fine to call tcsetattr unconditionally

mgorny marked an inline comment as done.Oct 18 2021, 2:20 AM
mgorny added inline comments.
lldb/include/lldb/Host/Terminal.h
23

If I do that, I can't use it from TerminalState.

mgorny updated this revision to Diff 380318.Oct 18 2021, 2:36 AM

Simplify the internal setting logic.

labath added inline comments.Oct 19 2021, 12:31 AM
lldb/include/lldb/Host/Terminal.h
23

I see. I was expecting that TerminalState was a friend or something. Given the new setup I think it would make sense to make it a friend so that it can use Get/SetData instead of raw tc[gs]etattr calls (and hopefully avoid some ifdefs).

mgorny updated this revision to Diff 380609.Oct 19 2021, 1:40 AM
mgorny marked 2 inline comments as done.

Make Terminal::Data private and befriend TerminalState.

labath accepted this revision.Oct 19 2021, 1:53 AM
This revision is now accepted and ready to land.Oct 19 2021, 1:53 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptOct 19 2021, 4:31 AM
thakis added a subscriber: thakis.Oct 27 2021, 9:28 AM

This causes lots of warnings on Windows, where TERMIOS is false: http://45.33.8.238/win/47744/step_4.txt (look for "Terminal.cpp"). Could you take a look? It looks like return statements are genuinely missing there.

This causes lots of warnings on Windows, where TERMIOS is false: http://45.33.8.238/win/47744/step_4.txt (look for "Terminal.cpp"). Could you take a look? It looks like return statements are genuinely missing there.

When LLDB_ENABLE_TERMIOS is false, GetData() always returns an error, so the code below should not be reachable. I suppose I could add llvm_unreachable() for that. I'll try that and make a diff if it works.

This causes lots of warnings on Windows, where TERMIOS is false: http://45.33.8.238/win/47744/step_4.txt (look for "Terminal.cpp"). Could you take a look? It looks like return statements are genuinely missing there.

When LLDB_ENABLE_TERMIOS is false, GetData() always returns an error, so the code below should not be reachable. I suppose I could add llvm_unreachable() for that. I'll try that and make a diff if it works.

Maybe it'd be easier to read if you move

return llvm::createStringError(llvm::inconvertibleErrorCode(),
                               "termios support missing in LLDB");

into some function and then do

llvm::Error Terminal::SetCanonical(bool enabled) {
#if LLDB_ENABLE_TERMIOS
  ...actual body...
#else
  return ThatErrorFunction();
#endif
``

(etc) in all the functions instead of hiding it in GetData()? Then it's obvious in every function what's going on.

Thanks, that sounds like a good idea. Changed D112632 to do that.