summaryrefslogtreecommitdiffstats
path: root/lldb/tools/driver/Driver.cpp
diff options
context:
space:
mode:
authorSaleem Abdulrasool <compnerd@compnerd.org>2014-09-08 02:47:13 +0000
committerSaleem Abdulrasool <compnerd@compnerd.org>2014-09-08 02:47:13 +0000
commit9e5b49831c1fe91b3626bc25ad56de8c32bfedd2 (patch)
tree269cc874a3c47bb0ea98e033976e79cace7633bf /lldb/tools/driver/Driver.cpp
parent09716297643f402cf948e1c52b06627e5d6cb3f5 (diff)
downloadbcm5719-llvm-9e5b49831c1fe91b3626bc25ad56de8c32bfedd2.tar.gz
bcm5719-llvm-9e5b49831c1fe91b3626bc25ad56de8c32bfedd2.zip
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. llvm-svn: 217355
Diffstat (limited to 'lldb/tools/driver/Driver.cpp')
-rw-r--r--lldb/tools/driver/Driver.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/lldb/tools/driver/Driver.cpp b/lldb/tools/driver/Driver.cpp
index 854310031c3..4ed696ec1ab 100644
--- a/lldb/tools/driver/Driver.cpp
+++ b/lldb/tools/driver/Driver.cpp
@@ -931,7 +931,15 @@ Driver::MainLoop ()
#endif
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 ()
}
else
{
- fprintf(stderr, "error: fdopen(%i, \"r\") failed (errno = %i) when trying to open LLDB commands pipe\n", fds[READ], errno);
+ fprintf(stderr,
+ "error: fdopen(%i, \"r\") failed (errno = %i) when "
+ "trying to open LLDB commands pipe\n",
+ fds[READ], errno);
success = false;
}
}
+ else
+ {
+ assert(!"partial writes not handled");
+ success = false;
+ }
}
else
{
OpenPOWER on IntegriCloud