Last active
June 30, 2021 14:00
-
-
Save marty1885/c9b2faa49c35c53909048bf08e080607 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cxxabi.h> | |
#include <iostream> | |
void demangle_name(const std::string& mangled_name) | |
{ | |
std::size_t len = 0; | |
int status = 0; | |
auto name = __cxxabiv1::__cxa_demangle(mangled_name.c_str(), nullptr, &len, &status); | |
if (status == 0) | |
{ | |
std::cout << "demangled name:" << name << "\n"; | |
} | |
else | |
{ | |
std::cout << "demangle error\n"; | |
} | |
std::free(name); | |
} | |
template <typename T> | |
void demangle(T &&v) | |
{ | |
std::size_t len = 0; | |
int status = 0; | |
auto name = __cxxabiv1::__cxa_demangle(typeid(T).name(), nullptr, &len, &status); | |
if (status == 0) | |
{ | |
std::cout << "demangled name:" << name << "\n"; | |
} | |
else | |
{ | |
std::cout << "demangle error\n"; | |
} | |
std::free(name); | |
} | |
void f1(std::string &s1) {} | |
void f2(std::string &&s1) {} | |
int main() | |
{ | |
demangle(f1); // Good on FreeBSD 12. Fail on FreeBSD 13 | |
demangle(f2); // Fail on FreeBSD 12. Fail on FreeBSD 13 | |
demangle_name("i"); // Fail on FreeBSD 13 | |
demangle_name("8SayHello"); // Fail on FreeBSD 13 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment