Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Drop simgrid::xbt::demangle and use boost::core::demangle instead.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 20 Feb 2021 10:41:41 +0000 (11:41 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 20 Feb 2021 10:43:21 +0000 (11:43 +0100)
ChangeLog
include/xbt/backtrace.hpp
src/kernel/actor/ActorImpl.cpp
src/kernel/context/ContextSwapped.cpp
src/kernel/context/ContextThread.cpp
src/kernel/lmm/maxmin.cpp
src/mc/mc_global.cpp
src/xbt/backtrace.cpp
src/xbt/exception.cpp

index 55e7fd5..782c65f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -22,6 +22,9 @@ S4U:
  - New functions: Comm::sendto_{init,async} to initiate a communication
    on between two (possibly remote) hosts.
 
+XBT:
+ - Drop simgrid::xbt::demangle. Please use boost::core::demangle instead.
+
 Documentation:
  - New section: Configuring the logs from the command line.
  - New section: Programming API of logs.
index 3df49ff..007c0c1 100644 (file)
@@ -20,12 +20,6 @@ SG_END_DECL
 namespace simgrid {
 namespace xbt {
 
-/** Try to demangle a C++ name
- *
- *  Return the origin string if this fails.
- */
-XBT_PUBLIC std::unique_ptr<char, std::function<void(char*)>> demangle(const char* name);
-
 class BacktraceImpl;
 /** A backtrace
  *
index d84e204..e2eb184 100644 (file)
@@ -18,6 +18,7 @@
 #include "src/surf/HostImpl.hpp"
 #include "src/surf/cpu_interface.hpp"
 
+#include <boost/core/demangle.hpp>
 #include <boost/range/algorithm.hpp>
 #include <utility>
 
@@ -321,8 +322,7 @@ void ActorImpl::yield()
     try {
       std::rethrow_exception(std::move(exception));
     } catch (const simgrid::Exception& e) {
-      std::string name = simgrid::xbt::demangle(typeid(e).name()).get();
-      e.rethrow_nested(XBT_THROW_POINT, name + " raised in kernel mode.");
+      e.rethrow_nested(XBT_THROW_POINT, boost::core::demangle(typeid(e).name()) + " raised in kernel mode.");
     }
   }
 
index 2a32096..bd913fb 100644 (file)
@@ -12,6 +12,7 @@
 
 #include "src/kernel/context/ContextSwapped.hpp"
 
+#include <boost/core/demangle.hpp>
 #include <memory>
 
 #ifdef _WIN32
@@ -51,7 +52,7 @@ void smx_ctx_wrapper(simgrid::kernel::context::SwappedContext* context)
   } catch (simgrid::ForcefulKillException const&) {
     XBT_DEBUG("Caught a ForcefulKillException");
   } catch (simgrid::Exception const& e) {
-    XBT_INFO("Actor killed by an uncaught exception %s", simgrid::xbt::demangle(typeid(e).name()).get());
+    XBT_INFO("Actor killed by an uncaught exception %s", boost::core::demangle(typeid(e).name()).c_str());
     throw;
   }
 #if HAVE_SANITIZER_ADDRESS_FIBER_SUPPORT
index b8bc3d1..f329df4 100644 (file)
@@ -11,6 +11,7 @@
 #include "src/xbt_modinter.h" /* prototype of os thread module's init/exit in XBT */
 #include "xbt/function_types.h"
 
+#include <boost/core/demangle.hpp>
 #include <functional>
 #include <utility>
 
@@ -103,7 +104,7 @@ void ThreadContext::wrapper(ThreadContext* context)
     XBT_DEBUG("Caught a ForcefulKillException in Thread::wrapper");
     xbt_assert(not context->is_maestro(), "Maestro shall not receive ForcefulKillExceptions, even when detached.");
   } catch (simgrid::Exception const& e) {
-    XBT_INFO("Actor killed by an uncaught exception %s", simgrid::xbt::demangle(typeid(e).name()).get());
+    XBT_INFO("Actor killed by an uncaught exception %s", boost::core::demangle(typeid(e).name()).c_str());
     throw;
   }
   // Signal to the caller (normally the maestro) that we have finished:
index a86ef6b..bd13a0a 100644 (file)
@@ -4,7 +4,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "src/kernel/lmm/maxmin.hpp"
-#include "xbt/backtrace.hpp"
+#include <boost/core/demangle.hpp>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_maxmin, surf, "Logging specific to SURF (maxmin)");
 
@@ -145,8 +145,8 @@ System::~System()
   Constraint* cnst;
 
   while ((var = extract_variable())) {
-    auto demangled = simgrid::xbt::demangle(var->id_ ? typeid(*var->id_).name() : "(unidentified)");
-    XBT_WARN("Probable bug: a %s variable (#%d) not removed before the LMM system destruction.", demangled.get(),
+    std::string demangled = boost::core::demangle(var->id_ ? typeid(*var->id_).name() : "(unidentified)");
+    XBT_WARN("Probable bug: a %s variable (#%d) not removed before the LMM system destruction.", demangled.c_str(),
              var->rank_);
     var_free(var);
   }
index dc6228a..53dec30 100644 (file)
@@ -18,9 +18,9 @@
 #include "src/mc/mc_smx.hpp"
 #include "src/mc/remote/AppSide.hpp"
 #include "src/mc/sosp/Snapshot.hpp"
-#include "xbt/backtrace.hpp"
 
 #include <array>
+#include <boost/core/demangle.hpp>
 #include <libunwind.h>
 #endif
 
@@ -115,17 +115,17 @@ void dumpStack(FILE* file, unw_cursor_t* cursor)
   do {
     const char* name = not unw_get_proc_name(cursor, buffer.data(), buffer.size(), &off) ? buffer.data() : "?";
     // Unmangle C++ names:
-    auto realname = simgrid::xbt::demangle(name);
+    std::string realname = boost::core::demangle(name);
 
 #if defined(__x86_64__)
     unw_word_t rip = 0;
     unw_word_t rsp = 0;
     unw_get_reg(cursor, UNW_X86_64_RIP, &rip);
     unw_get_reg(cursor, UNW_X86_64_RSP, &rsp);
-    fprintf(file, "  %i: %s (RIP=0x%" PRIx64 " RSP=0x%" PRIx64 ")\n", nframe, realname.get(), (std::uint64_t)rip,
+    fprintf(file, "  %i: %s (RIP=0x%" PRIx64 " RSP=0x%" PRIx64 ")\n", nframe, realname.c_str(), (std::uint64_t)rip,
             (std::uint64_t)rsp);
 #else
-    fprintf(file, "  %i: %s\n", nframe, realname.get());
+    fprintf(file, "  %i: %s\n", nframe, realname.c_str());
 #endif
 
     ++nframe;
index 35122fb..03e5ad7 100644 (file)
 #include <cstdlib>
 #include <sstream>
 
-// Try to detect and use the C++ itanium ABI for name demangling:
-#ifdef __GXX_ABI_VERSION
-#include <cxxabi.h>
-#endif
-
 #if HAVE_BOOST_STACKTRACE_BACKTRACE
 #define BOOST_STACKTRACE_USE_BACKTRACE
 #include <boost/stacktrace.hpp>
@@ -39,20 +34,6 @@ void xbt_backtrace_display_current()
 namespace simgrid {
 namespace xbt {
 
-std::unique_ptr<char, std::function<void(char*)>> demangle(const char* name)
-{
-#ifdef __GXX_ABI_VERSION
-  int status;
-  std::unique_ptr<char, std::function<void(char*)>> res(abi::__cxa_demangle(name, nullptr, nullptr, &status),
-                                                        &std::free);
-  if (res != nullptr)
-    return res;
-  // We did not manage to resolve this. Probably because this is not a mangled symbol:
-#endif
-  // Return the symbol:
-  return std::unique_ptr<char, std::function<void(char*)>>(xbt_strdup(name), &xbt_free_f);
-}
-
 class BacktraceImpl {
 #if HAVE_BOOST_STACKTRACE_BACKTRACE || HAVE_BOOST_STACKTRACE_ADDR2LINE
   const boost::stacktrace::stacktrace st;
index 54a0df5..cf4801a 100644 (file)
@@ -8,6 +8,7 @@
 #include <xbt/config.hpp>
 #include <xbt/log.hpp>
 
+#include <boost/core/demangle.hpp>
 #include <mutex>
 #include <sstream>
 
@@ -34,11 +35,11 @@ UnimplementedError::~UnimplementedError()   = default;
 void log_exception(e_xbt_log_priority_t prio, const char* context, std::exception const& exception)
 {
   try {
-    auto name = simgrid::xbt::demangle(typeid(exception).name());
+    std::string name = boost::core::demangle(typeid(exception).name());
 
     auto* with_context = dynamic_cast<const simgrid::Exception*>(&exception);
     if (with_context != nullptr) {
-      XBT_LOG(prio, "%s %s by %s/%d: %s", context, name.get(), with_context->throw_point().procname_.c_str(),
+      XBT_LOG(prio, "%s %s by %s/%d: %s", context, name.c_str(), with_context->throw_point().procname_.c_str(),
               with_context->throw_point().pid_, exception.what());
       // Do we have a backtrace?
       if (not simgrid::config::get_value<bool>("exception/cutpath")) {
@@ -46,7 +47,7 @@ void log_exception(e_xbt_log_priority_t prio, const char* context, std::exceptio
         XBT_LOG(prio, "Backtrace:\n%s", backtrace.c_str());
       }
     } else {
-      XBT_LOG(prio, "%s %s: %s", context, name.get(), exception.what());
+      XBT_LOG(prio, "%s %s: %s", context, name.c_str(), exception.what());
     }
   } catch (...) {
     // Don't log exceptions we got when trying to log exception