Skip to content

Instantly share code, notes, and snippets.

@xaxxon
Created May 30, 2017 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xaxxon/519ccaae2d7c58df1d5147164aa6964c to your computer and use it in GitHub Desktop.
Save xaxxon/519ccaae2d7c58df1d5147164aa6964c to your computer and use it in GitHub Desktop.
std::string demangle_typeid_name(const std::string & mangled_name) {
#ifdef V8TOOLKIT_DEMANGLE_NAMES
// printf("Starting name demangling\n");
std::string result;
int status;
auto demangled_name_needs_to_be_freed = abi::__cxa_demangle(mangled_name.c_str(), nullptr, 0, &status);
result = demangled_name_needs_to_be_freed;
if (demangled_name_needs_to_be_freed == nullptr) {
return mangled_name;
}
if (status == 0) {
result = demangled_name_needs_to_be_freed;
} else {
// https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.3/a01696.html
//-1: A memory allocation failiure occurred.
//-2: mangled_name is not a valid name under the C++ ABI mangling rules.
//-3: One of the arguments is invalid.
result = mangled_name;
}
if (demangled_name_needs_to_be_freed) {
free(demangled_name_needs_to_be_freed);
}
return result;
#else
return mangled_name;
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment