From e9ce80880d92eaf6c24309dbdcb4dcccb8750df5 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Tue, 12 Jan 2021 11:19:33 -0800 Subject: [PATCH] remote file:line from decode errors --- src/client.cpp | 4 +++- src/clientconn.cpp | 12 ++++++++---- src/clientget.cpp | 3 ++- src/clientintrospect.cpp | 3 ++- src/clientmon.cpp | 3 ++- src/pvaproto.h | 2 ++ src/serverchan.cpp | 10 ++++++---- src/serverconn.cpp | 9 +++++---- src/serverget.cpp | 8 ++++---- src/serverintrospect.cpp | 2 +- src/servermon.cpp | 8 ++++---- 11 files changed, 39 insertions(+), 25 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index 7118ddf..c6b27f7 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -591,7 +591,9 @@ bool Context::Pvt::onSearch() } if(!M.good()) { - log_hex_printf(io, Level::Err, &searchMsg[0], nrx, "Invalid search reply %d from %s\n", nrx, src.tostring().c_str()); + log_hex_printf(io, Level::Err, &searchMsg[0], nrx, + "%s:%d Invalid search reply %d from %s\n", + M.file(), M.line(), nrx, src.tostring().c_str()); } return true; diff --git a/src/clientconn.cpp b/src/clientconn.cpp index 3372d13..efa9055 100644 --- a/src/clientconn.cpp +++ b/src/clientconn.cpp @@ -188,7 +188,8 @@ void Connection::handle_CONNECTION_VALIDATION() } if(!M.good()) { - log_err_printf(io, "Server %s sends invalid CONNECTION_VALIDATION. Disconnect...\n", peerName.c_str()); + log_err_printf(io, "%s:%d Server %s sends invalid CONNECTION_VALIDATION. Disconnect...\n", + M.file(), M.line(), peerName.c_str()); bev.reset(); return; } @@ -255,7 +256,8 @@ void Connection::handle_CONNECTION_VALIDATED() from_wire(M, sts); if(!M.good()) { - log_crit_printf(io, "Server %s sends invalid CONNECTION_VALIDATED. Disconnecting...\n", peerName.c_str()); + log_crit_printf(io, "%s:%d Server %s sends invalid CONNECTION_VALIDATED. Disconnecting...\n", + M.file(), M.line(), peerName.c_str()); bev.reset(); return; @@ -285,7 +287,8 @@ void Connection::handle_CREATE_CHANNEL() // "spec" calls for uint16_t Access Rights here, but pvAccessCPP don't include this (it's useless anyway) if(!M.good()) { - log_crit_printf(io, "Server %s sends invalid CREATE_CHANNEL. Disconnecting...\n", peerName.c_str()); + log_crit_printf(io, "%s:%d Server %s sends invalid CREATE_CHANNEL. Disconnecting...\n", + M.file(), M.line(), peerName.c_str()); bev.reset(); return; } @@ -350,7 +353,8 @@ void Connection::handle_DESTROY_CHANNEL() from_wire(M, cid); if(!M.good()) { - log_crit_printf(io, "Server %s sends invalid DESTROY_CHANNEL. Disconnecting...\n", peerName.c_str()); + log_crit_printf(io, "%s:%d Server %s sends invalid DESTROY_CHANNEL. Disconnecting...\n", + M.file(), M.line(), peerName.c_str()); bev.reset(); return; } diff --git a/src/clientget.cpp b/src/clientget.cpp index 883866c..91331d9 100644 --- a/src/clientget.cpp +++ b/src/clientget.cpp @@ -353,7 +353,8 @@ void Connection::handle_GPR(pva_app_msg_t cmd) } if(!M.good() || !gpr) { - log_crit_printf(io, "Server %s sends invalid op%02x. Disconnecting...\n", peerName.c_str(), cmd); + log_crit_printf(io, "%s:%d Server %s sends invalid op%02x. Disconnecting...\n", + M.file(), M.line(), peerName.c_str(), cmd); bev.reset(); return; } diff --git a/src/clientintrospect.cpp b/src/clientintrospect.cpp index 0e30179..abc800e 100644 --- a/src/clientintrospect.cpp +++ b/src/clientintrospect.cpp @@ -122,7 +122,8 @@ void Connection::handle_GET_FIELD() from_wire_type(M, rxRegistry, prototype); if(!M.good()) { - log_crit_printf(io, "Server %s sends invalid GET_FIELD. Disconnecting...\n", peerName.c_str()); + log_crit_printf(io, "%s:%d Server %s sends invalid GET_FIELD. Disconnecting...\n", + M.file(), M.line(), peerName.c_str()); bev.reset(); return; } diff --git a/src/clientmon.cpp b/src/clientmon.cpp index 94630ba..895eadb 100644 --- a/src/clientmon.cpp +++ b/src/clientmon.cpp @@ -430,7 +430,8 @@ void Connection::handle_MONITOR() } if(!M.good() || !mon) { - log_crit_printf(io, "Server %s sends invalid MONITOR. Disconnecting...\n", peerName.c_str()); + log_crit_printf(io, "%s:%d Server %s sends invalid MONITOR. Disconnecting...\n", + M.file(), M.line(), peerName.c_str()); bev.reset(); return; } diff --git a/src/pvaproto.h b/src/pvaproto.h index 25544c1..1804312 100644 --- a/src/pvaproto.h +++ b/src/pvaproto.h @@ -58,6 +58,8 @@ public: errline = lineno; } EPICS_ALWAYS_INLINE bool good() const { return !err; } + inline const char* file() const { return err ? err : "(null)"; } + EPICS_ALWAYS_INLINE int line() const { return errline; } // ensure (be resize/refill) that size()>=i inline bool ensure(size_t i) { diff --git a/src/serverchan.cpp b/src/serverchan.cpp index 5958063..db6d969 100644 --- a/src/serverchan.cpp +++ b/src/serverchan.cpp @@ -221,7 +221,7 @@ void ServerConn::handle_SEARCH() } if(!M.good()) - throw std::runtime_error("TCP Search decode error"); + throw std::runtime_error(SB()<server->sourcesLock.lockReader()); @@ -349,7 +349,8 @@ void ServerConn::handle_CREATE_CHANNEL() // "spec" calls for uint16_t Access Rights here, but pvAccessCPP don't include this (it's useless anyway) if(!R.good()) { M.fault(__FILE__, __LINE__); - log_err_printf(connio, "Client %s Encode error in CreateChan\n", peerName.c_str()); + log_err_printf(connio, "%s:%d Client %s Encode error in CreateChan\n", + M.file(), M.line(), peerName.c_str()); break; } } @@ -358,7 +359,8 @@ void ServerConn::handle_CREATE_CHANNEL() } if(!M.good()) { - log_err_printf(connio, "Client %s Decode error in CreateChan\n", peerName.c_str()); + log_err_printf(connio, "%s:%d Client %s Decode error in CreateChan\n", + M.file(), M.line(), peerName.c_str()); bev.reset(); } } @@ -372,7 +374,7 @@ void ServerConn::handle_DESTROY_CHANNEL() from_wire(M, sid); from_wire(M, cid); if(!M.good()) - throw std::runtime_error("Decode error in DestroyChan"); + throw std::runtime_error(SB()<