This is an archive of the discontinued LLVM Phabricator instance.

[lldb] [Host] Add setters for common teletype properties to Terminal
ClosedPublic

Authored by mgorny on Oct 3 2021, 11:29 AM.

Details

Summary

Add setters for common teletype properties to the Terminal class:

  • SetRaw() to enable common raw mode options
  • SetBaudRate() to set the baud rate
  • SetStopBits() to select the number of stop bits
  • SetParity() to control parity bit in the output
  • SetHardwareControlFlow() to enable or disable hardware control flow (if supported)

Diff Detail

Event Timeline

mgorny requested review of this revision.Oct 3 2021, 11:29 AM
mgorny created this revision.
mgorny updated this revision to Diff 377133.Oct 5 2021, 2:54 AM

Remove support for 1.5 stop bits — it's valid only for 5-bit transmission (which we don't support). Simplify the API to use integer instead of enum.

mgorny updated this revision to Diff 377949.Oct 7 2021, 12:05 PM

Remove the changes to ConnectionFileDescriptorPosix from this patch. Now it's purely new Terminal API.

mgorny updated this revision to Diff 380726.Oct 19 2021, 10:38 AM

Rebased to use llvm::Error return type. Moved Parity into Terminal class.

labath added inline comments.Oct 20 2021, 4:29 AM
lldb/source/Host/common/Terminal.cpp
316–347

I am wondering if we can avoid the double conversion (enum->bools->flags). Would something like this be shorter/cleaner:

unsigned(?) GetParityFlagMask() {
  return PARENB | PARODD
#ifdef CMSPAR
    | CMSPAR
#endif
  ;
}
Expected<unsigned> GetParityFlags(Parity) // error if parity not supported

SetParity(parity) {
getParityFlags(parity); // and check result
GetData(); // and check result
data.m_termios.c_cflag &= ~GetParityFlagMask();
data.m_termios.c_cflag |= flags;
SetData();
lldb/unittests/Host/posix/TerminalTest.cpp
187–189

btw, we have FailedWithMessage for this these days.

mgorny updated this revision to Diff 380943.Oct 20 2021, 7:06 AM

Make SetParity() simpler.

mgorny added inline comments.Oct 20 2021, 7:08 AM
lldb/source/Host/common/Terminal.cpp
316–347

TBH, I don't like the extra functions because they mean more #ifdefs. How do you feel about my new version? I think it might be less optimal but I think it's as readable as it gets.

labath accepted this revision.Oct 21 2021, 12:26 AM
labath added inline comments.
lldb/source/Host/common/Terminal.cpp
117

Out of curiosity: how does a baud rate of zero work?

316–347

I like that.

This revision is now accepted and ready to land.Oct 21 2021, 12:26 AM
mgorny added inline comments.Oct 21 2021, 12:46 AM
lldb/source/Host/common/Terminal.cpp
117

It triggers a "hang up" signal to the modem. To be honest, I don't think we actually need that and it's kinda ugly API, so maybe I should remove it.

Herald added a project: Restricted Project. · View Herald TranscriptOct 21 2021, 1:33 AM