38#if defined(__ANDROID__) && !defined(RTTI_DUMP_USE_PRINTF)
39#include <android/log.h>
40#define RTTI_DUMP_LOG(fmt, ...) \
41 __android_log_print(ANDROID_LOG_INFO, "rtti_dump", fmt, ## __VA_ARGS__)
43#define RTTI_DUMP_LOG(fmt, ...) printf(fmt "\n", ## __VA_ARGS__)
47#define RTTI_DUMP_UNUSED __attribute__((unused))
56extern "C" const std::type_info *__cxa_current_exception_type();
66RTTI_DUMP_UNUSED const std::type_info *runtime_typeid(
const volatile T *dynptr) {
67 T *dynptr_unqual =
const_cast<T*
>(dynptr);
73 (void)
sizeof(
dynamic_cast<void*
>(dynptr_unqual));
75 void *vptr = *
reinterpret_cast<void**
>(dynptr_unqual);
76 void *typeid_void =
reinterpret_cast<void**
>(vptr)[-1];
77 return reinterpret_cast<const std::type_info*
>(typeid_void);
83 if (!dladdr(
const_cast<void*
>(ptr), &
info)) {
85 snprintf(buf,
sizeof(buf),
"[error: dladdr failed - %d]", errno);
88 return std::string(
info.dli_fname);
95void dump_type(
const std::type_info *type,
const char *label=
"dump_type",
int indent=0) {
96 const std::string prefix = label + std::string(
": ") + std::string(indent,
' ');
98 RTTI_DUMP_LOG(
"%sERROR: dump_type called with type==NULL!", prefix.c_str());
101 virtual ~type_info() {}
102 const char *type_name;
104 assert(
sizeof(type_info) ==
sizeof(std::type_info));
105 const char *
const name = type->name();
106 const char *
const raw_name =
reinterpret_cast<const type_info*
>(type)->type_name;
107 if (
name == raw_name) {
109 }
else if (raw_name + 1 ==
name) {
110 RTTI_DUMP_LOG(
"%stype %s (raw name == '%s' @ %p):", prefix.c_str(),
name, raw_name, raw_name);
115 prefix.c_str(), type, dladdr_fname(type).c_str());
117 prefix.c_str(),
name, dladdr_fname(
name).c_str());
123void dump_current_exception(
const char *label=
"dump_current_exception") {
124 const std::type_info *type = __cxa_current_exception_type();
126 dump_type(type, label);
128 RTTI_DUMP_LOG(
"%s: ERROR: dump_current_exception called outside a catch block!", label);
132namespace hierarchy_dumper_internals {
139 struct __class_type_info : std::type_info {};
141 struct __si_class_type_info : __class_type_info {
145 struct __base_class_type_info {
150 struct __vmi_class_type_info : __class_type_info {
158 std::set<const std::type_info*>
seen_;
160 Dumper(
const char *label) :
label_(label) {}
161 void dump_type(
const std::type_info *
info,
int indent);
164 const int kIndent = 4;
166 void Dumper::dump_type(
const std::type_info *
info,
int indent) {
167 ::rtti_dump::dump_type(
info,
label_, indent * kIndent);
173 const std::type_info *info_type = runtime_typeid(
info);
174 __base_class_type_info lone_base = { 0 };
175 const __base_class_type_info *base_table = NULL;
176 unsigned int base_count = 0;
182 const int sub_indent_sp = (indent + 1) * kIndent;
184 if (info_type == NULL) {
187 }
else if (!strcmp(info_type->name(),
"N10__cxxabiv120__si_class_type_infoE")) {
188 const __si_class_type_info &infox =
189 *
reinterpret_cast<const __si_class_type_info*
>(
info);
190 lone_base.__base_type = infox.__base_type;
192 base_table = &lone_base;
193 }
else if (!strcmp(info_type->name(),
"N10__cxxabiv121__vmi_class_type_infoE")) {
194 const __vmi_class_type_info &infox =
195 *
reinterpret_cast<const __vmi_class_type_info*
>(
info);
196 base_count = infox.__base_count;
197 base_table = infox.__base_info;
200 if (base_count > 0) {
206 for (
unsigned int i = 0; i < base_count; ++i) {
217void dump_class_hierarchy(
const std::type_info *
info,
const char *label=
"dump_class_hierarchy") {
218 hierarchy_dumper_internals::Dumper dumper(label);
219 dumper.dump_type(
info, 0);
unsigned int __base_count
const __class_type_info * __base_type
#define RTTI_DUMP_LOG(fmt,...)
std::set< const std::type_info * > seen_
__base_class_type_info __base_info[1]