-/* Copyright (c) 2005-2018. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2005-2019. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
-#ifndef SIMGRIX_XBT_BACKTRACE_HPP
-#define SIMGRIX_XBT_BACKTRACE_HPP
+#ifndef SIMGRID_XBT_BACKTRACE_HPP
+#define SIMGRID_XBT_BACKTRACE_HPP
#include <xbt/base.h>
#include <cstddef>
+#include <functional>
#include <memory>
#include <string>
#include <vector>
XBT_PUBLIC void xbt_backtrace_display_current();
SG_END_DECL()
-typedef void* xbt_backtrace_location_t;
-
-/** @brief reimplementation of glibc backtrace based directly on gcc library, without implicit malloc */
-XBT_PUBLIC int xbt_backtrace_no_malloc(void** bt, int size);
-
-/** @brief Captures a backtrace for further use */
-XBT_PUBLIC size_t xbt_backtrace_current(xbt_backtrace_location_t* loc, size_t count);
-
-/** @brief Display a previously captured backtrace */
-XBT_PUBLIC void xbt_backtrace_display(xbt_backtrace_location_t* loc, size_t count);
-
-/** @brief Get current backtrace with libunwind */
-XBT_PUBLIC int xbt_libunwind_backtrace(void** bt, int size);
-
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
*
* This is used (among other things) in exceptions to store the associated
*
* @ingroup XBT_ex
*/
-typedef std::vector<xbt_backtrace_location_t> Backtrace;
+class Backtrace {
+public:
+ BacktraceImpl* impl_ = nullptr;
+ Backtrace();
+ Backtrace(const Backtrace& bt);
+ Backtrace(Backtrace&& bt);
+ Backtrace& operator=(const Backtrace& rhs);
+ Backtrace& operator=(Backtrace&& rhs);
+ ~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;
+};
-/** Try to demangle a C++ name
- *
- * Return the origin string if this fails.
- */
-XBT_PUBLIC std::unique_ptr<char, void (*)(void*)> demangle(const char* name);
-
-/** Get the current backtrace */
-XBT_PUBLIC Backtrace backtrace();
-
-/* Translate the backtrace in a human friendly form
- *
- * Try resolve symbols and source code location.
- */
-XBT_PUBLIC std::vector<std::string> resolve_backtrace(xbt_backtrace_location_t const* loc, std::size_t count);
}
}
-
#endif