[llvm-bugs] [Bug 32149] Interrupting inferior during a getline causes the stream to fail

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Mar 6 14:22:46 PST 2017


http://bugs.llvm.org/show_bug.cgi?id=32149

Jim Ingham <jingham at apple.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|NEW                         |RESOLVED

--- Comment #3 from Jim Ingham <jingham at apple.com> ---
Looks like getline uses LibC's getc on macOS.  All of the getc family can get
EINTR if something interrupts this read call.  

That attaching with a debugger interrupts an ongoing system call most likely
varies from system to system.  But it does happen on macOS, and isn't something
the debugger can control.

It looks like getline doesn't handle EINTR itself.  It also sets both bad and
eof to true on EINTR on OSX.  But I don't think you can rely on that because if
I close the input by sending ^D I get the same result.

Something like this works, but it's a little ugly:

#include <iostream>
#include <string>
#include <stdio.h>

int main() {
  errno = 0;
  while (errno == EINTR || !std::cin.eof()) {
    std::string Line;
    errno = 0;
    std::cin.clear();
    std::getline(std::cin, Line);
  }
  return 0;
}

Anyway, this isn't an issue with lldb.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170306/e3e9c8b2/attachment.html>


More information about the llvm-bugs mailing list