[Lldb-commits] [lldb] r217355 - driver: handle write error better
compnerd at compnerd.org
Sun Sep 7 19:47:13 PDT 2014
Date: Sun Sep 7 21:47:13 2014
New Revision: 217355
driver: handle write error better
We would previously simply assume that the write would always succeed. However,
write(2) may return -1 for error as well as fail to perform a complete write (in
which case the returned number of bytes will be less than the requested bytes).
Explicitly check if an error condition is encountered. This would previously
not be caught as we default initialized success to true. Add an assertion that
we always perform a complete write (a continuous retry could be added to ensure
that we finish writing completely).
This was caught by GCC's signed comparison warning and manual inspection.
--- lldb/trunk/tools/driver/Driver.cpp (original)
+++ lldb/trunk/tools/driver/Driver.cpp Sun Sep 7 21:47:13 2014
@@ -931,7 +931,15 @@ Driver::MainLoop ()
if (err == 0)
- if (write (fds[WRITE], commands_data, commands_size) == commands_size)
+ ssize_t nrwr = write(fds[WRITE], commands_data, commands_size);
+ if (nrwr < 0)
+ fprintf(stderr, "error: write(%i, %p, %zd) failed (errno = %i) "
+ "when trying to open LLDB commands pipe\n",
+ fds[WRITE], commands_data, commands_size, errno);
+ success = false;
+ else if (static_cast<size_t>(nrwr) == commands_size)
// Close the write end of the pipe so when we give the read end to
// the debugger/command interpreter it will exit when it consumes all
@@ -953,10 +961,18 @@ Driver::MainLoop ()
- fprintf(stderr, "error: fdopen(%i, \"r\") failed (errno = %i) when trying to open LLDB commands pipe\n", fds[READ], errno);
+ "error: fdopen(%i, \"r\") failed (errno = %i) when "
+ "trying to open LLDB commands pipe\n",
+ fds[READ], errno);
success = false;
+ assert(!"partial writes not handled");
+ success = false;
More information about the lldb-commits