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 // OS-specific functions
void initializeConnection(); void initializeConnection();
int WriteBytes(const void *Data, size_t Size) { 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) // Communication handles (OS-specific)
void *ConnectionData; void *ConnectionData;

View File

@ -27,8 +27,6 @@ public:
RPCChannel() {} RPCChannel() {}
~RPCChannel(); ~RPCChannel();
static void ReportError(int rc, size_t Size, std::string &ErrorMsg);
/// Start the remote process. /// Start the remote process.
/// ///
/// @returns True on success. On failure, ErrorMsg is updated with /// @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. // This will get filled in as a point to an OS-specific structure.
void *ConnectionData; void *ConnectionData;
int WriteBytes(const void *Data, size_t Size); bool WriteBytes(const void *Data, size_t Size);
int ReadBytes(void *Data, size_t Size); bool ReadBytes(void *Data, size_t Size);
void Wait(); void Wait();
}; };

View File

@ -32,24 +32,10 @@ class RemoteTargetExternal : public RemoteTarget {
RPCChannel RPC; RPCChannel RPC;
bool WriteBytes(const void *Data, size_t Size) { bool WriteBytes(const void *Data, size_t Size) {
int rc = RPC.WriteBytes(Data, Size); return RPC.WriteBytes(Data, Size);
if (rc != -1 && (size_t)rc == Size)
return true;
ErrorMsg = "WriteBytes: ";
RPC.ReportError(rc, Size, ErrorMsg);
return false;
} }
bool ReadBytes(void *Data, size_t Size) { bool ReadBytes(void *Data, size_t Size) { return RPC.ReadBytes(Data, 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;
}
public: public:
/// Allocate space in the remote target address space. /// 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 <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/wait.h> #include <sys/wait.h>
@ -82,15 +85,14 @@ bool RPCChannel::createClient() {
return true; return true;
} }
void RPCChannel::ReportError(int rc, size_t Size, std::string &ErrorMsg) { void RPCChannel::Wait() { wait(NULL); }
if (rc == -1) {
if (errno == EPIPE) static bool CheckError(int rc, size_t Size, const char *Desc) {
ErrorMsg += "pipe closed"; if (rc < 0) {
else if (errno == EINTR) llvm::errs() << "IO Error: " << Desc << ": " << sys::StrError() << '\n';
ErrorMsg += "interrupted"; return false;
else } else if ((size_t)rc != Size) {
ErrorMsg += "file descriptor error"; std::string ErrorMsg;
} else {
char Number[10] = { 0 }; char Number[10] = { 0 };
ErrorMsg += "Expecting "; ErrorMsg += "Expecting ";
sprintf(Number, "%d", (uint32_t)Size); sprintf(Number, "%d", (uint32_t)Size);
@ -98,19 +100,22 @@ void RPCChannel::ReportError(int rc, size_t Size, std::string &ErrorMsg) {
ErrorMsg += " bytes, Got "; ErrorMsg += " bytes, Got ";
sprintf(Number, "%d", rc); sprintf(Number, "%d", rc);
ErrorMsg += Number; ErrorMsg += Number;
llvm::errs() << "RPC Error: " << Desc << ": " << ErrorMsg << '\n';
return false;
} }
return true;
} }
int RPCChannel::WriteBytes(const void *Data, size_t Size) { bool RPCChannel::WriteBytes(const void *Data, size_t Size) {
return write(((ConnectionData_t *)ConnectionData)->OutputPipe, Data, Size); int rc = write(((ConnectionData_t *)ConnectionData)->OutputPipe, Data, Size);
return CheckError(rc, Size, "WriteBytes");
} }
int RPCChannel::ReadBytes(void *Data, size_t Size) { bool RPCChannel::ReadBytes(void *Data, size_t Size) {
return read(((ConnectionData_t *)ConnectionData)->InputPipe, Data, Size); int rc = read(((ConnectionData_t *)ConnectionData)->InputPipe, Data, Size);
return CheckError(rc, Size, "ReadBytes");
} }
void RPCChannel::Wait() { wait(NULL); }
RPCChannel::~RPCChannel() { RPCChannel::~RPCChannel() {
delete static_cast<ConnectionData_t *>(ConnectionData); delete static_cast<ConnectionData_t *>(ConnectionData);
} }

View File

@ -18,11 +18,9 @@ bool RPCChannel::createServer() { return false; }
bool RPCChannel::createClient() { 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; } bool RPCChannel::ReadBytes(void *Data, size_t Size) { return false; }
int RPCChannel::ReadBytes(void *Data, size_t Size) { return -1; }
void RPCChannel::Wait() {} void RPCChannel::Wait() {}