1 /* Copyright (c) 2005-2016. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
11 // Try to detect and use the C++ intanium ABI for name demangling:
12 #ifdef __GXX_ABI_VERSION
16 #include <xbt/backtrace.h>
17 #include <xbt/backtrace.hpp>
19 #include <xbt/sysdep.h>
21 #include "src/internal_config.h"
25 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_backtrace, xbt, "Backtrace");
29 /** @brief show the backtrace of the current point (lovely while debugging) */
30 void xbt_backtrace_display_current()
32 const std::size_t size = 10;
33 xbt_backtrace_location_t bt[size];
34 size_t used = xbt_backtrace_current(bt, size);
35 xbt_backtrace_display(bt, used);
41 std::unique_ptr<char, void(*)(void*)> demangle(const char* name)
43 #ifdef __GXX_ABI_VERSION
45 auto res = std::unique_ptr<char, void(*)(void*)>(
46 abi::__cxa_demangle(name, nullptr, nullptr, &status),
51 // We did not manage to resolve this. Probably because this is not a mangled symbol:
54 return std::unique_ptr<char, void(*)(void*)>(xbt_strdup(name), std::free);
57 std::vector<xbt_backtrace_location_t> backtrace()
59 const std::size_t size = 10;
60 xbt_backtrace_location_t loc[size];
61 size_t used = xbt_backtrace_current(loc, size);
62 return std::vector<xbt_backtrace_location_t>(loc, loc + used);
68 #if HAVE_BACKTRACE && HAVE_EXECINFO_H && HAVE_POPEN && defined(ADDR2LINE)
69 # include "src/xbt/backtrace_linux.cpp"
71 # include "src/xbt/backtrace_dummy.cpp"