[lldb-dev] [Bug 32149] Interrupting inferior during a getline causes the stream to fail

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


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::getline(std::cin, Line);
  return 0;

Anyway, this isn't an issue with lldb.

You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20170306/49469cc2/attachment.html>

More information about the lldb-dev mailing list