#include <folly/Demangle.h>
#include <algorithm>
#include <cstring>
#include <folly/CPortability.h>
#include <folly/CppAttributes.h>
#include <folly/Utility.h>
#include <folly/functional/Invoke.h>
#include <folly/lang/CString.h>
#if __has_include(<cxxabi.h>)
#include <cxxabi.h>
#endif
#if __has_include(<demangle.h>)
#pragma push_macro("HAVE_DECL_BASENAME")
#define HAVE_DECL_BASENAME …
#include <demangle.h>
#pragma pop_macro("HAVE_DECL_BASENAME")
#endif
#if __has_include(<cxxabi.h>)
[[gnu::weakref("__cxa_demangle")]] static char* cxxabi_demangle(
char const*, char*, size_t*, int*);
#else
static constexpr auto cxxabi_demangle = static_cast<char* (*)(...)>(nullptr);
#endif
#if __has_include(<demangle.h>)
namespace {
struct poison {};
[[maybe_unused]] FOLLY_ERASE void rust_demangle_callback(poison);
[[maybe_unused]] FOLLY_ERASE int rust_demangle_callback_fallback(
const char*, int, demangle_callbackref, void*) {
return 0;
}
FOLLY_CREATE_QUAL_INVOKER(
invoke_rust_demangle_primary, ::rust_demangle_callback);
FOLLY_CREATE_QUAL_INVOKER(
invoke_rust_demangle_fallback, rust_demangle_callback_fallback);
using invoke_rust_demangle_fn = folly::invoke_first_match<
invoke_rust_demangle_primary,
invoke_rust_demangle_fallback>;
constexpr invoke_rust_demangle_fn invoke_rust_demangle;
int call_rust_demangle_callback(
const char* mangled, int options, demangle_callbackref cb, void* opaque) {
return invoke_rust_demangle(mangled, options, cb, opaque);
}
}
using liberty_demangle_t = int(const char*, int, demangle_callbackref, void*);
static constexpr liberty_demangle_t* liberty_cplus_demangle =
cplus_demangle_v3_callback;
static constexpr liberty_demangle_t* liberty_rust_demangle =
call_rust_demangle_callback;
#if defined(DMGL_NO_RECURSE_LIMIT)
static constexpr auto liberty_demangle_options_no_recurse_limit =
DMGL_NO_RECURSE_LIMIT;
#else
static constexpr auto liberty_demangle_options_no_recurse_limit = 0;
#endif
static constexpr auto liberty_demangle_options =
DMGL_PARAMS | DMGL_ANSI | DMGL_TYPES |
liberty_demangle_options_no_recurse_limit;
#else
liberty_demangle_t;
static constexpr liberty_demangle_t* liberty_cplus_demangle = …;
static constexpr liberty_demangle_t* liberty_rust_demangle = …;
static constexpr auto liberty_demangle_options = …;
#endif
namespace folly {
bool const demangle_build_has_cxxabi = …;
bool const demangle_build_has_liberty = …
to_bool(liberty_cplus_demangle) &&
to_bool(liberty_rust_demangle);
namespace {
void demangleStringCallback(const char* str, size_t size, void* p) { … }
}
fbstring demangle(const char* name) { … }
namespace {
struct DemangleBuf { … };
void demangleBufCallback(const char* str, size_t size, void* p) { … }
}
size_t demangle(const char* name, char* out, size_t outSize) { … }
}