Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:42

0001 //  Copyright 2015 Klemens Morgenstern
0002 //
0003 // This file provides a demangling for function names, i.e. entry points of a dll.
0004 //
0005 //  Distributed under the Boost Software License, Version 1.0.
0006 //  See http://www.boost.org/LICENSE_1_0.txt
0007 
0008 #ifndef BOOST_DLL_DEMANGLE_SYMBOL_HPP_
0009 #define BOOST_DLL_DEMANGLE_SYMBOL_HPP_
0010 
0011 #include <boost/dll/config.hpp>
0012 #include <string>
0013 #include <algorithm>
0014 #include <memory>
0015 
0016 #if defined(_MSC_VER) // MSVC, Clang-cl, and ICC on Windows
0017 
0018 namespace boost
0019 {
0020 namespace dll
0021 {
0022 namespace detail
0023 {
0024 
0025 typedef void * (__cdecl * allocation_function)(std::size_t);
0026 typedef void   (__cdecl * free_function)(void *);
0027 
0028 extern "C" char* __unDName( char* outputString,
0029         const char* name,
0030         int maxStringLength,    // Note, COMMA is leading following optional arguments
0031         allocation_function pAlloc,
0032         free_function pFree,
0033         unsigned short disableFlags
0034         );
0035 
0036 
0037 inline std::string demangle_symbol(const char *mangled_name)
0038 {
0039 
0040     allocation_function alloc =  [](std::size_t size){return static_cast<void*>(new char[size]);};
0041     free_function free_f      = [](void* p){delete [] static_cast<char*>(p);};
0042 
0043 
0044 
0045     std::unique_ptr<char> name { __unDName(
0046             nullptr,
0047             mangled_name,
0048             0,
0049             alloc,
0050             free_f,
0051             static_cast<unsigned short>(0))};
0052 
0053     return std::string(name.get());
0054 }
0055 inline std::string demangle_symbol(const std::string& mangled_name)
0056 {
0057     return demangle_symbol(mangled_name.c_str());
0058 }
0059 
0060 
0061 }}}
0062 #else
0063 
0064 #include <boost/core/demangle.hpp>
0065 
0066 namespace boost
0067 {
0068 namespace dll
0069 {
0070 namespace detail
0071 {
0072 
0073 inline std::string demangle_symbol(const char *mangled_name)
0074 {
0075 
0076     if (*mangled_name == '_')
0077     {
0078         //because it start's with an underline _
0079         auto dm = boost::core::demangle(mangled_name);
0080         if (!dm.empty())
0081             return dm;
0082         else
0083             return (mangled_name);
0084     }
0085 
0086     //could not demangled
0087     return "";
0088 
0089 
0090 }
0091 
0092 //for my personal convenience
0093 inline std::string demangle_symbol(const std::string& mangled_name)
0094 {
0095     return demangle_symbol(mangled_name.c_str());
0096 }
0097 
0098 
0099 }
0100 namespace experimental
0101 {
0102 using ::boost::dll::detail::demangle_symbol;
0103 }
0104 
0105 }}
0106 
0107 #endif
0108 
0109 #endif /* BOOST_DEMANGLE_HPP_ */