Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
finish objectifying the backtraces
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Fri, 2 Nov 2018 21:49:24 +0000 (22:49 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 3 Nov 2018 00:58:55 +0000 (01:58 +0100)
include/simgrid/Exception.hpp
include/xbt/backtrace.hpp
src/xbt/backtrace.cpp
src/xbt/exception.cpp

index 0fe9a32..b7d232f 100644 (file)
@@ -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_;
 };
index de3765e..99b3cb1 100644 (file)
@@ -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
index db93b54..9e732d7 100644 (file)
 
 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
index 042232c..94130b3 100644 (file)
@@ -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<bool>("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());
 }