utils/Demangle.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <cxxabi.h> | ||
| 4 | #include <string> | ||
| 5 | |||
| 6 | namespace simdb { | ||
| 7 | |||
| 8 | /*! | ||
| 9 | * \brief Represents the internal buffer size for demangling C++ symbols | ||
| 10 | */ | ||
| 11 | #define DEMANGLE_BUF_LENGTH 4096 | ||
| 12 | |||
| 13 | /*! | ||
| 14 | * \brief Demangles a C++ symbol | ||
| 15 | * \param Name Symbol name to demangle | ||
| 16 | * \return Demangled name if successful. If failed, returns the input | ||
| 17 | * name. Note that demangled names may match input name. | ||
| 18 | * \note Demangling is limited by DEMANGLE_BUF_LENGTH. results may be | ||
| 19 | * truncated or fail for very symbols. Change this value to support longer | ||
| 20 | * symbol names. | ||
| 21 | */ | ||
| 22 | 10 | inline std::string demangle(const std::string& name) noexcept | |
| 23 | { | ||
| 24 | char buf[DEMANGLE_BUF_LENGTH]; | ||
| 25 | 10 | size_t buf_size = DEMANGLE_BUF_LENGTH; | |
| 26 | int status; | ||
| 27 | 10 | char* out = __cxxabiv1::__cxa_demangle(name.c_str(), buf, &buf_size, &status); | |
| 28 | 10 | if (nullptr == out) | |
| 29 | { | ||
| 30 | 1 | return name; | |
| 31 | } | ||
| 32 | 18 | return std::string(out); | |
| 33 | } | ||
| 34 | |||
| 35 | 9 | template <typename T> inline std::string demangle_type() noexcept | |
| 36 | { | ||
| 37 | 18 | return demangle(typeid(T).name()); | |
| 38 | } | ||
| 39 | |||
| 40 | } // namespace simdb | ||
| 41 |