From 5af9da1ff0f589bce8af787d03a956cbc97eb3eb Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Fri, 2 Nov 2018 22:49:24 +0100 Subject: [PATCH] finish objectifying the backtraces --- include/simgrid/Exception.hpp | 2 ++ include/xbt/backtrace.hpp | 13 ++++--------- src/xbt/backtrace.cpp | 34 ++++++++++++++-------------------- src/xbt/exception.cpp | 4 ++-- 4 files changed, 22 insertions(+), 31 deletions(-) diff --git a/include/simgrid/Exception.hpp b/include/simgrid/Exception.hpp index 0fe9a32615..b7d232fa2d 100644 --- a/include/simgrid/Exception.hpp +++ b/include/simgrid/Exception.hpp @@ -63,6 +63,8 @@ public: /** Return the information about where the exception was thrown */ xbt::ThrowPoint const& throw_point() const { return throwpoint_; } + std::string const resolve_backtrace() const { return throwpoint_.backtrace_.resolve(); } + private: xbt::ThrowPoint throwpoint_; }; diff --git a/include/xbt/backtrace.hpp b/include/xbt/backtrace.hpp index de3765e822..99b3cb10be 100644 --- a/include/xbt/backtrace.hpp +++ b/include/xbt/backtrace.hpp @@ -41,17 +41,12 @@ public: Backtrace(); Backtrace(const Backtrace& bt); ~Backtrace(); + /** @brief Translate the backtrace in a human friendly form, unmangled with source code locations. */ + std::string const resolve() const; + /** @brief Display the resolved backtrace on stderr */ + void display() const; }; -/* Translate the backtrace in an human friendly form - * - * Try resolve symbols and source code locations. - */ -XBT_PUBLIC std::string resolve_backtrace(const Backtrace& bt); } } - -/** @brief Display a previously captured backtrace */ -XBT_PUBLIC void xbt_backtrace_display(const simgrid::xbt::Backtrace& bt); - #endif diff --git a/src/xbt/backtrace.cpp b/src/xbt/backtrace.cpp index db93b541f1..9e732d7b8e 100644 --- a/src/xbt/backtrace.cpp +++ b/src/xbt/backtrace.cpp @@ -33,22 +33,10 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_backtrace, xbt, "Backtrace"); -void xbt_backtrace_display(const simgrid::xbt::Backtrace& bt) -{ - std::string backtrace = simgrid::xbt::resolve_backtrace(bt); - if (backtrace.empty()) { - fprintf(stderr, "(backtrace not set -- did you install Boost.Stacktrace?)\n"); - return; - } - fprintf(stderr, "Backtrace (displayed in actor %s):\n", SIMIX_process_self_get_name()); - std::fprintf(stderr, "%s\n", backtrace.c_str()); -} - /** @brief show the backtrace of the current point (lovely while debugging) */ void xbt_backtrace_display_current() { - simgrid::xbt::Backtrace bt = simgrid::xbt::Backtrace(); - xbt_backtrace_display(bt); + simgrid::xbt::Backtrace().display(); } namespace simgrid { @@ -105,23 +93,29 @@ Backtrace::~Backtrace() delete impl_; } } -} // namespace xbt -} // namespace simgrid -namespace simgrid { -namespace xbt { - -std::string resolve_backtrace(const Backtrace& bt) +std::string const Backtrace::resolve() const { std::string result(""); #if HAVE_BOOST_STACKTRACE std::stringstream ss; - ss << bt.impl_->st; + ss << impl_->st; result.append(ss.str()); #endif return result; } +void Backtrace::display() const +{ + std::string backtrace = resolve(); + if (backtrace.empty()) { + fprintf(stderr, "(backtrace not set -- did you install Boost.Stacktrace?)\n"); + return; + } + fprintf(stderr, "Backtrace (displayed in actor %s):\n", SIMIX_process_self_get_name()); + std::fprintf(stderr, "%s\n", backtrace.c_str()); +} + } // namespace xbt } // namespace simgrid diff --git a/src/xbt/exception.cpp b/src/xbt/exception.cpp index 042232c277..94130b30c2 100644 --- a/src/xbt/exception.cpp +++ b/src/xbt/exception.cpp @@ -90,7 +90,7 @@ void log_exception(e_xbt_log_priority_t prio, const char* context, std::exceptio // Do we have a backtrace? if (with_context != nullptr && not simgrid::config::get_value("exception/cutpath")) { - auto backtrace = simgrid::xbt::resolve_backtrace(with_context->throw_point().backtrace_); + auto backtrace = with_context->resolve_backtrace(); XBT_LOG(prio, " -> %s", backtrace.c_str()); } @@ -120,7 +120,7 @@ static void show_backtrace(const simgrid::xbt::Backtrace& bt) XBT_LOG(xbt_log_priority_critical, "Display of current backtrace disabled by --cfg=exception/cutpath."); return; } - std::string res = resolve_backtrace(bt); + std::string res = bt.resolve(); XBT_LOG(xbt_log_priority_critical, "Current backtrace:"); XBT_LOG(xbt_log_priority_critical, " -> %s", res.c_str()); } -- 2.20.1