Report lli remote IO errors consistently
authorAlp Toker <alp@nuanti.com>
Fri, 24 Jan 2014 17:18:52 +0000 (17:18 +0000)
committerAlp Toker <alp@nuanti.com>
Fri, 24 Jan 2014 17:18:52 +0000 (17:18 +0000)
This enables IO error reports in both the child and server processes.

The scheme still isn't entirely satisfactory and output is jumbled but it beats
having no output at all. This will hopefully unblock ARM support (PR18057).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200017 91177308-0d34-0410-b5e6-96231b3b80d8

tools/lli/ChildTarget/ChildTarget.cpp
tools/lli/RPCChannel.h
tools/lli/RemoteTargetExternal.h
tools/lli/Unix/RPCChannel.inc
tools/lli/Windows/RPCChannel.inc

index 1e3000da46adf5f2b1b3bf1ee65681605f498d8f..4603496c982b9c8c192da22682b12352547b2f5f 100644 (file)
@@ -34,9 +34,11 @@ private:
   // OS-specific functions
   void initializeConnection();
   int WriteBytes(const void *Data, size_t Size) {
-    return RPC.WriteBytes(Data, Size);
+    return RPC.WriteBytes(Data, Size) ? Size : -1;
+  }
+  int ReadBytes(void *Data, size_t Size) {
+    return RPC.ReadBytes(Data, Size) ? Size : -1;
   }
-  int ReadBytes(void *Data, size_t Size) { return RPC.ReadBytes(Data, Size); }
 
   // Communication handles (OS-specific)
   void *ConnectionData;
index d04c8c25b491bb90772d2a4e2700ddefa7ce69f5..2d8c7081284743ae532841358b56d7488e670062 100644 (file)
@@ -27,8 +27,6 @@ public:
   RPCChannel() {}
   ~RPCChannel();
 
-  static void ReportError(int rc, size_t Size, std::string &ErrorMsg);
-
   /// Start the remote process.
   ///
   /// @returns True on success. On failure, ErrorMsg is updated with
@@ -40,8 +38,8 @@ public:
   // This will get filled in as a point to an OS-specific structure.
   void *ConnectionData;
 
-  int WriteBytes(const void *Data, size_t Size);
-  int ReadBytes(void *Data, size_t Size);
+  bool WriteBytes(const void *Data, size_t Size);
+  bool ReadBytes(void *Data, size_t Size);
 
   void Wait();
 };
index b332b19c0b56345a4005950cc1ca7b9164346243..17218a8c23852d1597cd60c70a3d0a3112958e07 100644 (file)
@@ -32,24 +32,10 @@ class RemoteTargetExternal : public RemoteTarget {
   RPCChannel RPC;
 
   bool WriteBytes(const void *Data, size_t Size) {
-    int rc = RPC.WriteBytes(Data, Size);
-    if (rc != -1 && (size_t)rc == Size)
-      return true;
-
-    ErrorMsg = "WriteBytes: ";
-    RPC.ReportError(rc, Size, ErrorMsg);
-    return false;
+    return RPC.WriteBytes(Data, Size);
   }
 
-  bool ReadBytes(void *Data, size_t Size) {
-    int rc = RPC.ReadBytes(Data, Size);
-    if (rc != -1 && (size_t)rc == Size)
-      return true;
-
-    ErrorMsg = "ReadBytes: ";
-    RPC.ReportError(rc, Size, ErrorMsg);
-    return false;
-  }
+  bool ReadBytes(void *Data, size_t Size) { return RPC.ReadBytes(Data, Size); }
 
 public:
   /// Allocate space in the remote target address space.
index b7dec37d93d9b5147bc1a401d33bdea99d5b7478..2a5d47650ffe71dca1556302c95ede8e0518089c 100644 (file)
@@ -12,6 +12,9 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/raw_ostream.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/wait.h>
@@ -82,15 +85,14 @@ bool RPCChannel::createClient() {
   return true;
 }
 
-void RPCChannel::ReportError(int rc, size_t Size, std::string &ErrorMsg) {
-  if (rc == -1) {
-    if (errno == EPIPE)
-      ErrorMsg += "pipe closed";
-    else if (errno == EINTR)
-      ErrorMsg += "interrupted";
-    else
-      ErrorMsg += "file descriptor error";
-  } else {
+void RPCChannel::Wait() { wait(NULL); }
+
+static bool CheckError(int rc, size_t Size, const char *Desc) {
+  if (rc < 0) {
+    llvm::errs() << "IO Error: " << Desc << ": " << sys::StrError() << '\n';
+    return false;
+  } else if ((size_t)rc != Size) {
+    std::string ErrorMsg;
     char Number[10] = { 0 };
     ErrorMsg += "Expecting ";
     sprintf(Number, "%d", (uint32_t)Size);
@@ -98,19 +100,22 @@ void RPCChannel::ReportError(int rc, size_t Size, std::string &ErrorMsg) {
     ErrorMsg += " bytes, Got ";
     sprintf(Number, "%d", rc);
     ErrorMsg += Number;
+    llvm::errs() << "RPC Error: " << Desc << ": " << ErrorMsg << '\n';
+    return false;
   }
+  return true;
 }
 
-int RPCChannel::WriteBytes(const void *Data, size_t Size) {
-  return write(((ConnectionData_t *)ConnectionData)->OutputPipe, Data, Size);
+bool RPCChannel::WriteBytes(const void *Data, size_t Size) {
+  int rc = write(((ConnectionData_t *)ConnectionData)->OutputPipe, Data, Size);
+  return CheckError(rc, Size, "WriteBytes");
 }
 
-int RPCChannel::ReadBytes(void *Data, size_t Size) {
-  return read(((ConnectionData_t *)ConnectionData)->InputPipe, Data, Size);
+bool RPCChannel::ReadBytes(void *Data, size_t Size) {
+  int rc = read(((ConnectionData_t *)ConnectionData)->InputPipe, Data, Size);
+  return CheckError(rc, Size, "ReadBytes");
 }
 
-void RPCChannel::Wait() { wait(NULL); }
-
 RPCChannel::~RPCChannel() {
   delete static_cast<ConnectionData_t *>(ConnectionData);
 }
index 3ad57aecf944a97574924a93450f18a82c0464cf..82f2acbf14afb44dd1c8283bd3bb261be21f9325 100644 (file)
@@ -18,11 +18,9 @@ bool RPCChannel::createServer() { return false; }
 
 bool RPCChannel::createClient() { return false; }
 
-void RPCChannel::ReportError(int rc, size_t Size, std::string &ErrorMsg) {}
+bool RPCChannel::WriteBytes(const void *Data, size_t Size) { return false; }
 
-int RPCChannel::WriteBytes(const void *Data, size_t Size) { return -1; }
-
-int RPCChannel::ReadBytes(void *Data, size_t Size) { return -1; }
+bool RPCChannel::ReadBytes(void *Data, size_t Size) { return false; }
 
 void RPCChannel::Wait() {}