]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/dll/detail/demangling/demangle_symbol.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / dll / detail / demangling / demangle_symbol.hpp
1 // Copyright 2015 Klemens Morgenstern
2 //
3 // This file provides a demangling for function names, i.e. entry points of a dll.
4 //
5 // Distributed under the Boost Software License, Version 1.0.
6 // See http://www.boost.org/LICENSE_1_0.txt
7
8 #ifndef BOOST_DLL_DEMANGLE_SYMBOL_HPP_
9 #define BOOST_DLL_DEMANGLE_SYMBOL_HPP_
10
11 #include <boost/config.hpp>
12 #include <string>
13 #include <algorithm>
14
15 #if defined(BOOST_MSVC) || defined(BOOST_MSVC_FULL_VER)
16
17 namespace boost
18 {
19 namespace dll
20 {
21 namespace detail
22 {
23
24 typedef void * (__cdecl * allocation_function)(std::size_t);
25 typedef void (__cdecl * free_function)(void *);
26
27 extern "C" char* __unDName( char* outputString,
28 const char* name,
29 int maxStringLength, // Note, COMMA is leading following optional arguments
30 allocation_function pAlloc,
31 free_function pFree,
32 unsigned short disableFlags
33 );
34
35
36 inline std::string demangle_symbol(const char *mangled_name)
37 {
38
39 allocation_function alloc = [](std::size_t size){return static_cast<void*>(new char[size]);};
40 free_function free_f = [](void* p){delete [] static_cast<char*>(p);};
41
42
43
44 std::unique_ptr<char> name { __unDName(
45 nullptr,
46 mangled_name,
47 0,
48 alloc,
49 free_f,
50 static_cast<unsigned short>(0))};
51
52 return std::string(name.get());
53 }
54 inline std::string demangle_symbol(const std::string& mangled_name)
55 {
56 return demangle_symbol(mangled_name.c_str());
57 }
58
59
60 }}}
61 #else
62
63 #include <boost/core/demangle.hpp>
64
65 namespace boost
66 {
67 namespace dll
68 {
69 namespace detail
70 {
71
72 inline std::string demangle_symbol(const char *mangled_name)
73 {
74
75 if (*mangled_name == '_')
76 {
77 //because it start's with an underline _
78 auto dm = boost::core::demangle(mangled_name);
79 if (!dm.empty())
80 return dm;
81 else
82 return (mangled_name);
83 }
84
85 //could not demangled
86 return "";
87
88
89 }
90
91 //for my personal convinience
92 inline std::string demangle_symbol(const std::string& mangled_name)
93 {
94 return demangle_symbol(mangled_name.c_str());
95 }
96
97
98 }
99 namespace experimental
100 {
101 using ::boost::dll::detail::demangle_symbol;
102 }
103
104 }}
105
106 #endif
107
108 #endif /* BOOST_DEMANGLE_HPP_ */