From 27ce8feb4adbb13c0efcc2d560c93dfb71785cb2 Mon Sep 17 00:00:00 2001 From: Alp Toker Date: Fri, 24 Jan 2014 17:18:52 +0000 Subject: [PATCH] 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 --- tools/lli/ChildTarget/ChildTarget.cpp | 6 +++-- tools/lli/RPCChannel.h | 6 ++--- tools/lli/RemoteTargetExternal.h | 18 ++------------ tools/lli/Unix/RPCChannel.inc | 35 +++++++++++++++------------ tools/lli/Windows/RPCChannel.inc | 6 ++--- 5 files changed, 30 insertions(+), 41 deletions(-) diff --git a/tools/lli/ChildTarget/ChildTarget.cpp b/tools/lli/ChildTarget/ChildTarget.cpp index 1e3000da46a..4603496c982 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 d04c8c25b49..2d8c7081284 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 b332b19c0b5..17218a8c238 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 b7dec37d93d..2a5d47650ff 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 #include #include @@ -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); } diff --git a/tools/lli/Windows/RPCChannel.inc b/tools/lli/Windows/RPCChannel.inc index 3ad57aecf94..82f2acbf14a 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() {} -- 2.34.1