summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/lli/ChildTarget/ChildTarget.cpp6
-rw-r--r--tools/lli/RPCChannel.h6
-rw-r--r--tools/lli/RemoteTargetExternal.h18
-rw-r--r--tools/lli/Unix/RPCChannel.inc35
-rw-r--r--tools/lli/Windows/RPCChannel.inc6
5 files changed, 30 insertions, 41 deletions
diff --git a/tools/lli/ChildTarget/ChildTarget.cpp b/tools/lli/ChildTarget/ChildTarget.cpp
index 1e3000da46..4603496c98 100644
--- a/tools/lli/ChildTarget/ChildTarget.cpp
+++ b/tools/lli/ChildTarget/ChildTarget.cpp
@@ -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;
diff --git a/tools/lli/RPCChannel.h b/tools/lli/RPCChannel.h
index d04c8c25b4..2d8c708128 100644
--- a/tools/lli/RPCChannel.h
+++ b/tools/lli/RPCChannel.h
@@ -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();
};
diff --git a/tools/lli/RemoteTargetExternal.h b/tools/lli/RemoteTargetExternal.h
index b332b19c0b..17218a8c23 100644
--- a/tools/lli/RemoteTargetExternal.h
+++ b/tools/lli/RemoteTargetExternal.h
@@ -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.
diff --git a/tools/lli/Unix/RPCChannel.inc b/tools/lli/Unix/RPCChannel.inc
index b7dec37d93..2a5d47650f 100644
--- a/tools/lli/Unix/RPCChannel.inc
+++ b/tools/lli/Unix/RPCChannel.inc
@@ -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);
}
diff --git a/tools/lli/Windows/RPCChannel.inc b/tools/lli/Windows/RPCChannel.inc
index 3ad57aecf9..82f2acbf14 100644
--- a/tools/lli/Windows/RPCChannel.inc
+++ b/tools/lli/Windows/RPCChannel.inc
@@ -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() {}