diff --git a/include/ircd/mods.h b/include/ircd/mods.h index f7fe45fb9..82dfae528 100644 --- a/include/ircd/mods.h +++ b/include/ircd/mods.h @@ -129,6 +129,9 @@ struct import_shared import_shared(const std::string &modname, const std::string &symname); }; + +std::string demangle(const std::string &symbol); + std::string postfixed(const std::string &name); std::string unpostfixed(const std::string &name); @@ -158,6 +161,7 @@ namespace ircd { using mods::module; // Bring struct module into main ircd:: using mods::import; using mods::import_shared; +using mods::demangle; } // namespace ircd diff --git a/ircd/mods.cc b/ircd/mods.cc index a0947a846..6bfec1442 100644 --- a/ircd/mods.cc +++ b/ircd/mods.cc @@ -24,6 +24,7 @@ * USA */ +#include #include #include @@ -582,6 +583,29 @@ ircd::mods::prefix_if_relative(const filesystem::path &path) return path.is_relative()? (modroot / path) : path; } +std::string +ircd::mods::demangle(const std::string &symbol) +{ + size_t len; + int status; + const custom_ptr buf + { + abi::__cxa_demangle(symbol.c_str(), nullptr, &len, &status), + std::free + }; + + switch(status) + { + case 0: break; + case -1: throw error("Demangle failed -1: memory allocation failure"); + case -2: throw error("Demangle failed -2: mangled name is not valid"); + case -3: throw error("Demangle failed -3: invalid argument"); + default: throw error("Demangle failed %d: unknown error", status); + } + + return { buf.get(), len }; +} + /////////////////////////////////////////////////////////////////////////////// // // mod (internal)