diff options
author | binji <binji@chromium.org> | 2015-05-29 15:10:04 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-29 22:10:45 +0000 |
commit | 9641ea083dbe1635f5d942b5f725b6cc969f98c0 (patch) | |
tree | b022c699cca5bd5c017dd7c4211217448fc66480 /native_client_sdk | |
parent | 397f242c79014073d48318a9299d11f0923796a7 (diff) | |
download | chromium_src-9641ea083dbe1635f5d942b5f725b6cc969f98c0.zip chromium_src-9641ea083dbe1635f5d942b5f725b6cc969f98c0.tar.gz chromium_src-9641ea083dbe1635f5d942b5f725b6cc969f98c0.tar.bz2 |
[NaCl SDK] nacl_io: Nicer PPError logging.
Print the PPError string and code whenever a Pepper function fails.
BUG=171993
R=sbc@chromium.org
Review URL: https://codereview.chromium.org/1150223004
Cr-Commit-Position: refs/heads/master@{#332054}
Diffstat (limited to 'native_client_sdk')
8 files changed, 116 insertions, 24 deletions
diff --git a/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc b/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc index b71de27..954d8e3 100644 --- a/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc +++ b/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc @@ -123,7 +123,7 @@ Error Html5Fs::Mkdir(const Path& path, int permissions) { int32_t result = file_ref_iface_->MakeDirectory( fileref_resource.pp_resource(), PP_FALSE, PP_BlockUntilComplete()); if (result != PP_OK) - return PPErrorToErrno(result); + return PPERROR_TO_ERRNO(result); return 0; } @@ -178,7 +178,7 @@ Error Html5Fs::RemoveInternal(const Path& path, int remove_type) { int32_t result = file_ref_iface_->Delete(fileref_resource.pp_resource(), PP_BlockUntilComplete()); if (result != PP_OK) - return PPErrorToErrno(result); + return PPERROR_TO_ERRNO(result); return 0; } @@ -206,7 +206,7 @@ Error Html5Fs::Rename(const Path& path, const Path& newpath) { new_fileref_resource.pp_resource(), PP_BlockUntilComplete()); if (result != PP_OK) - return PPErrorToErrno(result); + return PPERROR_TO_ERRNO(result); return 0; } @@ -307,7 +307,7 @@ Error Html5Fs::Init(const FsInitArgs& args) { if (!main_thread) { filesystem_open_has_result_ = true; - filesystem_open_error_ = PPErrorToErrno(result); + filesystem_open_error_ = PPERROR_TO_ERRNO(result); return filesystem_open_error_; } @@ -340,7 +340,7 @@ void Html5Fs::FilesystemOpenCallbackThunk(void* user_data, int32_t result) { void Html5Fs::FilesystemOpenCallback(int32_t result) { AUTO_LOCK(filesysem_open_lock_); filesystem_open_has_result_ = true; - filesystem_open_error_ = PPErrorToErrno(result); + filesystem_open_error_ = PPERROR_TO_ERRNO(result); pthread_cond_signal(&filesystem_open_cond_); } diff --git a/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs_node.cc b/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs_node.cc index a178d85..bb3a8f5 100644 --- a/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs_node.cc +++ b/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs_node.cc @@ -80,7 +80,7 @@ Error Html5FsNode::FSync() { int32_t result = file_io_iface_->Flush(fileio_resource_, PP_BlockUntilComplete()); if (result != PP_OK) - return PPErrorToErrno(result); + return PPERROR_TO_ERRNO(result); return 0; } @@ -104,7 +104,7 @@ Error Html5FsNode::GetDents(size_t offs, int32_t result = file_ref_iface_->ReadDirectoryEntries( fileref_resource_, output, PP_BlockUntilComplete()); if (result != PP_OK) - return PPErrorToErrno(result); + return PPERROR_TO_ERRNO(result); PP_DirectoryEntry* entries = static_cast<PP_DirectoryEntry*>(output_buf.data); @@ -151,7 +151,7 @@ Error Html5FsNode::GetStat(struct stat* stat) { int32_t result = file_ref_iface_->Query(fileref_resource_, &info, PP_BlockUntilComplete()); if (result != PP_OK) - return PPErrorToErrno(result); + return PPERROR_TO_ERRNO(result); // Fill in known info here. memcpy(stat, &stat_, sizeof(stat_)); @@ -191,7 +191,7 @@ Error Html5FsNode::Read(const HandleAttr& attr, static_cast<int32_t>(count), PP_BlockUntilComplete()); if (result < 0) - return PPErrorToErrno(result); + return PPERROR_TO_ERRNO(result); *out_bytes = result; return 0; @@ -204,7 +204,7 @@ Error Html5FsNode::FTruncate(off_t size) { int32_t result = file_io_iface_->SetLength( fileio_resource_, size, PP_BlockUntilComplete()); if (result != PP_OK) - return PPErrorToErrno(result); + return PPERROR_TO_ERRNO(result); return 0; } @@ -223,7 +223,7 @@ Error Html5FsNode::Write(const HandleAttr& attr, static_cast<int32_t>(count), PP_BlockUntilComplete()); if (result < 0) - return PPErrorToErrno(result); + return PPERROR_TO_ERRNO(result); *out_bytes = result; return 0; @@ -245,7 +245,7 @@ Error Html5FsNode::GetSize(off_t* out_size) { int32_t result = file_io_iface_->Query(fileio_resource_, &info, PP_BlockUntilComplete()); if (result != PP_OK) - return PPErrorToErrno(result); + return PPERROR_TO_ERRNO(result); *out_size = info.size; return 0; @@ -299,7 +299,7 @@ Error Html5FsNode::Init(int open_flags) { OpenFlagsToPPAPIOpenFlags(open_flags), PP_BlockUntilComplete()); if (open_result != PP_OK) - return PPErrorToErrno(open_result); + return PPERROR_TO_ERRNO(open_result); return 0; } diff --git a/native_client_sdk/src/libraries/nacl_io/httpfs/http_fs_node.cc b/native_client_sdk/src/libraries/nacl_io/httpfs/http_fs_node.cc index 73930a7..6952b01 100644 --- a/native_client_sdk/src/libraries/nacl_io/httpfs/http_fs_node.cc +++ b/native_client_sdk/src/libraries/nacl_io/httpfs/http_fs_node.cc @@ -342,7 +342,7 @@ Error HttpFsNode::OpenUrl(const char* method, out_request->pp_resource(), PP_BlockUntilComplete()); if (result != PP_OK) - return PPErrorToErrno(result); + return PPERROR_TO_ERRNO(result); out_response->Reset( loader_interface->GetResponseInfo(out_loader->pp_resource())); @@ -670,7 +670,7 @@ Error HttpFsNode::ReadResponseToBuffer(const ScopedResource& loader, } if (bytes_read < 0) - return PPErrorToErrno(bytes_read); + return PPERROR_TO_ERRNO(bytes_read); assert(bytes_read <= bytes_to_read); bytes_to_read -= bytes_read; diff --git a/native_client_sdk/src/libraries/nacl_io/pepper_interface.cc b/native_client_sdk/src/libraries/nacl_io/pepper_interface.cc index ad92a8f..545c1a1 100644 --- a/native_client_sdk/src/libraries/nacl_io/pepper_interface.cc +++ b/native_client_sdk/src/libraries/nacl_io/pepper_interface.cc @@ -6,6 +6,8 @@ #include <errno.h> #include <ppapi/c/pp_errors.h> +#include "nacl_io/log.h" + namespace nacl_io { void PepperInterface::AddRefResource(PP_Resource resource) { @@ -103,4 +105,79 @@ int PPErrorToErrno(int32_t err) { return EINVAL; } +#if !defined(NDEBUG) + +int PPErrorToErrnoLog(int32_t err, const char* file, int line) { + if (err >= PP_OK) + return err; + +#define PP_ERRORS(V) \ + V(PP_OK) \ + V(PP_OK_COMPLETIONPENDING) \ + V(PP_ERROR_FAILED) \ + V(PP_ERROR_ABORTED) \ + V(PP_ERROR_BADARGUMENT) \ + V(PP_ERROR_BADRESOURCE) \ + V(PP_ERROR_NOINTERFACE) \ + V(PP_ERROR_NOACCESS) \ + V(PP_ERROR_NOMEMORY) \ + V(PP_ERROR_NOSPACE) \ + V(PP_ERROR_NOQUOTA) \ + V(PP_ERROR_INPROGRESS) \ + V(PP_ERROR_NOTSUPPORTED) \ + V(PP_ERROR_BLOCKS_MAIN_THREAD) \ + V(PP_ERROR_MALFORMED_INPUT) \ + V(PP_ERROR_RESOURCE_FAILED) \ + V(PP_ERROR_FILENOTFOUND) \ + V(PP_ERROR_FILEEXISTS) \ + V(PP_ERROR_FILETOOBIG) \ + V(PP_ERROR_FILECHANGED) \ + V(PP_ERROR_NOTAFILE) \ + V(PP_ERROR_TIMEDOUT) \ + V(PP_ERROR_USERCANCEL) \ + V(PP_ERROR_NO_USER_GESTURE) \ + V(PP_ERROR_CONTEXT_LOST) \ + V(PP_ERROR_NO_MESSAGE_LOOP) \ + V(PP_ERROR_WRONG_THREAD) \ + V(PP_ERROR_WOULD_BLOCK_THREAD) \ + V(PP_ERROR_CONNECTION_CLOSED) \ + V(PP_ERROR_CONNECTION_RESET) \ + V(PP_ERROR_CONNECTION_REFUSED) \ + V(PP_ERROR_CONNECTION_ABORTED) \ + V(PP_ERROR_CONNECTION_FAILED) \ + V(PP_ERROR_CONNECTION_TIMEDOUT) \ + V(PP_ERROR_ADDRESS_INVALID) \ + V(PP_ERROR_ADDRESS_UNREACHABLE) \ + V(PP_ERROR_ADDRESS_IN_USE) \ + V(PP_ERROR_MESSAGE_TOO_BIG) \ + V(PP_ERROR_NAME_NOT_RESOLVED) + +#define ERROR_STRING_PAIR(x) {x, #x}, + + const struct { + int err; + const char* name; + } kErrorStringPair[] = { + PP_ERRORS(ERROR_STRING_PAIR) + }; + +#undef ERROR_STRING_PAIR +#undef PP_ERRORS + + const char* err_string = "Unknown PPError value"; + for (size_t i = 0; i < sizeof(kErrorStringPair) / sizeof(kErrorStringPair[0]); + ++i) { + if (err == kErrorStringPair[i].err) { + err_string = kErrorStringPair[i].name; + } + } + + nacl_io_log(LOG_PREFIX "%s:%d: Got PPError %d = %s\n", file, line, err, + err_string); + + return PPErrorToErrno(err); +} + +#endif + } // namespace nacl_io diff --git a/native_client_sdk/src/libraries/nacl_io/pepper_interface.h b/native_client_sdk/src/libraries/nacl_io/pepper_interface.h index 967e34e..1ebd3c6 100644 --- a/native_client_sdk/src/libraries/nacl_io/pepper_interface.h +++ b/native_client_sdk/src/libraries/nacl_io/pepper_interface.h @@ -71,6 +71,21 @@ namespace nacl_io { int PPErrorToErrno(int32_t err); +// Helper function to log real pepper error at call site. +#if defined(NDEBUG) + +#define PPERROR_TO_ERRNO(err) \ + PPErrorToErrno(err) + +#else + +int PPErrorToErrnoLog(int32_t err, const char* file, int line); + +#define PPERROR_TO_ERRNO(err) \ + PPErrorToErrnoLog(err, __FILE__, __LINE__) + +#endif + class PepperInterface { public: virtual ~PepperInterface() {} diff --git a/native_client_sdk/src/libraries/nacl_io/socket/socket_node.cc b/native_client_sdk/src/libraries/nacl_io/socket/socket_node.cc index 4eaf6ac..181a876 100644 --- a/native_client_sdk/src/libraries/nacl_io/socket/socket_node.cc +++ b/native_client_sdk/src/libraries/nacl_io/socket/socket_node.cc @@ -448,7 +448,7 @@ Error SocketNode::SendHelper(const HandleAttr& attr, void SocketNode::SetError_Locked(int pp_error_num) { SetStreamFlags(SSF_ERROR | SSF_CLOSED); ClearStreamFlags(SSF_CAN_SEND | SSF_CAN_RECV); - last_errno_ = PPErrorToErrno(pp_error_num); + last_errno_ = PPERROR_TO_ERRNO(pp_error_num); } Error SocketNode::Shutdown(int how) { diff --git a/native_client_sdk/src/libraries/nacl_io/socket/tcp_node.cc b/native_client_sdk/src/libraries/nacl_io/socket/tcp_node.cc index 738206e..d7de53c 100644 --- a/native_client_sdk/src/libraries/nacl_io/socket/tcp_node.cc +++ b/native_client_sdk/src/libraries/nacl_io/socket/tcp_node.cc @@ -355,7 +355,7 @@ Error TcpNode::SetNoDelay_Locked() { PP_TCPSOCKET_OPTION_NO_DELAY, PP_MakeBool(tcp_nodelay_ ? PP_TRUE : PP_FALSE), PP_BlockUntilComplete()); - return PPErrorToErrno(error); + return PPERROR_TO_ERRNO(error); } Error TcpNode::SetSockOpt(int lvl, @@ -378,7 +378,7 @@ Error TcpNode::SetSockOpt(int lvl, PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE, PP_MakeInt32(bufsize), PP_BlockUntilComplete()); - return PPErrorToErrno(error); + return PPERROR_TO_ERRNO(error); } else if (lvl == SOL_SOCKET && optname == SO_SNDBUF) { if (static_cast<size_t>(len) < sizeof(int)) return EINVAL; @@ -389,7 +389,7 @@ Error TcpNode::SetSockOpt(int lvl, PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE, PP_MakeInt32(bufsize), PP_BlockUntilComplete()); - return PPErrorToErrno(error); + return PPERROR_TO_ERRNO(error); } return SocketNode::SetSockOpt(lvl, optname, optval, len); @@ -482,7 +482,7 @@ Error TcpNode::Bind(const struct sockaddr* addr, socklen_t len) { if (err != PP_OK) { filesystem_->ppapi()->ReleaseResource(local_addr_); local_addr_ = 0; - return PPErrorToErrno(err); + return PPERROR_TO_ERRNO(err); } local_addr_ = TCPInterface()->GetLocalAddress(socket_resource_); @@ -571,7 +571,7 @@ Error TcpNode::Listen(int backlog) { int err = TCPInterface()->Listen( socket_resource_, backlog, PP_BlockUntilComplete()); if (err != PP_OK) - return PPErrorToErrno(err); + return PPERROR_TO_ERRNO(err); ClearStreamFlags(SSF_CAN_CONNECT); SetStreamFlags(SSF_LISTENING); diff --git a/native_client_sdk/src/libraries/nacl_io/socket/udp_node.cc b/native_client_sdk/src/libraries/nacl_io/socket/udp_node.cc index 7b8bc1e..7f6da12 100644 --- a/native_client_sdk/src/libraries/nacl_io/socket/udp_node.cc +++ b/native_client_sdk/src/libraries/nacl_io/socket/udp_node.cc @@ -227,7 +227,7 @@ Error UdpNode::SetSockOpt(int lvl, PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE, PP_MakeInt32(bufsize), PP_BlockUntilComplete()); - return PPErrorToErrno(error); + return PPERROR_TO_ERRNO(error); } else if (lvl == SOL_SOCKET && optname == SO_SNDBUF) { if (static_cast<size_t>(len) < sizeof(int)) return EINVAL; @@ -238,7 +238,7 @@ Error UdpNode::SetSockOpt(int lvl, PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE, PP_MakeInt32(bufsize), PP_BlockUntilComplete()); - return PPErrorToErrno(error); + return PPERROR_TO_ERRNO(error); } return SocketNode::SetSockOpt(lvl, optname, optval, len); @@ -260,7 +260,7 @@ Error UdpNode::Bind(const struct sockaddr* addr, socklen_t len) { UDPInterface()->Bind(socket_resource_, out_addr, PP_BlockUntilComplete()); filesystem_->ppapi()->ReleaseResource(out_addr); if (err != 0) - return PPErrorToErrno(err); + return PPERROR_TO_ERRNO(err); // Get the address that was actually bound (in case addr was 0.0.0.0:0). out_addr = UDPInterface()->GetBoundAddress(socket_resource_); |