X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FConsole%2FServer.cc;h=719f527b4fea6f1c9cec588e18cad1f8f18d0c84;hb=6745b9a3712f3221fe4b076ed7abb1ab92d6ac2b;hp=d3261331bc6c3b71f05067576bf0921eb58c641b;hpb=368058ef8f5eb65ea7e210351af25f49ddd0f342;p=senf.git diff --git a/Utils/Console/Server.cc b/Utils/Console/Server.cc index d326133..719f527 100644 --- a/Utils/Console/Server.cc +++ b/Utils/Console/Server.cc @@ -27,6 +27,7 @@ #include "Server.ih" // Custom includes +#include #include #include #include @@ -36,6 +37,9 @@ #include "../../Utils/membind.hh" #include "../../Utils/Logger/SenfLog.hh" #include "LineEditor.hh" +#include "ScopedDirectory.hh" +#include "Sysdir.hh" +#include "ParsedCommand.hh" //#include "Server.mpp" #define prefix_ @@ -93,7 +97,8 @@ prefix_ senf::console::Server::Server(ServerHandle handle) : handle_ (handle), event_ ("senf::console::Server", senf::membind(&Server::newClient, this), handle_, scheduler::FdEvent::EV_READ), - root_ (senf::console::root().thisptr()), mode_ (Automatic) + root_ (senf::console::root().thisptr()), mode_ (Automatic), + name_ (::program_invocation_short_name) {} prefix_ void senf::console::Server::newClient(int event) @@ -284,14 +289,21 @@ prefix_ std::string::size_type senf::console::Client::handleInput(std::string da _1 )); } catch (Executor::ExitException &) { - // This generates an EOF condition on the Handle. This EOF condition is expected - // to be handled gracefully by the ClientReader. We cannot call stop() here, since we - // are called from the client reader callback and that will continue executing even if we - // call stop here ... + // This generates an EOF condition on the Handle. This EOF condition is expected to be + // handled gracefully by the ClientReader. We cannot call stop() here, since we are called + // from the client reader callback and that will continue executing after stop() has been + // called. stop() however will delete *this instance ... BANG ... handle_.facet().shutdown(senf::TCPSocketProtocol::ShutRD); } catch (std::exception & ex) { - stream() << ex.what() << std::endl; + std::string msg (ex.what()); + std::string::size_type i (msg.find("-- \n")); + if (i != std::string::npos) { + backtrace_ = msg.substr(0,i); + msg = msg.substr(i+4); + } else + backtrace_.clear(); + stream() << msg << std::endl; } catch (...) { stream() << "unidentified error (unknown exception thrown)" << std::endl; @@ -337,6 +349,26 @@ prefix_ std::ostream & senf::console::operator<<(std::ostream & os, Client * cli return os << *client; } +/////////////////////////////////////////////////////////////////////////// +// senf::console::Client::SysBacktrace + +prefix_ senf::console::Client::SysBacktrace::SysBacktrace() +{ + sysdir().node().add("backtrace", &SysBacktrace::backtrace) + .doc("Display the backtrace of the last error / exception in this console"); +} + +prefix_ void senf::console::Client::SysBacktrace::backtrace(std::ostream & os) +{ + Client & client (Client::get(os)); + if (client.backtrace().empty()) + os << "(no backtrace)"; + else + os << client.backtrace(); +} + +senf::console::Client::SysBacktrace senf::console::Client::SysBacktrace::instance_; + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "Server.mpp"