Report lli remote IO errors consistently

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
This commit is contained in:
Alp Toker 2014-01-24 17:18:52 +00:00
parent c166623dcd
commit 27ce8feb4a
5 changed files with 30 additions and 41 deletions

View 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;

View 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();
};

View 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.

View 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);
}

View 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() {}