-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathabiutils.cpp
50 lines (38 loc) · 1.2 KB
/
abiutils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "mutils/abiutils.hpp"
#include <cxxabi.h>
#include <exception>
#include <memory>
#include <cstdlib>
#include <string>
#include "mutils/private_access.hpp"
namespace mutils{
#ifdef __clang__
struct raw_exn_accessor {typedef void* (std::exception_ptr::*type);};
template struct stow_private<raw_exn_accessor,&std::exception_ptr::__ptr_>;
inline void* access_raw_exn(std::exception_ptr p){
return p.*stowed<raw_exn_accessor>::value;
}
inline __cxxabiv1::__cxa_exception* cxa_exception_from_thrown_object(void* thrown_object)
{
return static_cast<__cxxabiv1::__cxa_exception*>(thrown_object) - 1;
}
inline __cxxabiv1::__cxa_exception* access_cxa_exn(std::exception_ptr p){
return cxa_exception_from_thrown_object(access_raw_exn(p));
}
auto try_demangled_name(const std::type_info& ti){
std::unique_ptr<char, void(*)(void*)> own
(abi::__cxa_demangle
(ti.name(), nullptr,nullptr, nullptr),
std::free);
std::string r = own != nullptr ? own.get() : ti.name();
return r;
}
std::type_info* exn_type(std::exception_ptr p){
return access_cxa_exn(p)->exceptionType;
}
std::string exn_typename(std::exception_ptr p){
return try_demangled_name(*exn_type(p));
}
#else
#endif
}