1 /* 2 * Copyright 2009-2011, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #include "demangle.h" 7 8 #include <string.h> 9 10 #ifdef _KERNEL_MODE 11 # include <debug.h> 12 #endif 13 14 15 static inline bool 16 looks_like_gcc3_symbol(const char* symbol) 17 { 18 return strncmp(symbol, "_Z", 2) == 0; 19 } 20 21 22 const char* 23 demangle_symbol(const char* mangledName, char* buffer, size_t bufferSize, 24 bool* _isObjectMethod) 25 { 26 // try the gcc3 demangler, if it looks like a gcc3 symbol 27 const char* demangled = NULL; 28 if (looks_like_gcc3_symbol(mangledName)) { 29 demangled = demangle_symbol_gcc3(mangledName, buffer, bufferSize, 30 _isObjectMethod); 31 if (demangled != NULL) 32 return demangled; 33 } 34 35 // fallback is gcc2 36 return demangle_symbol_gcc2(mangledName, buffer, bufferSize, 37 _isObjectMethod); 38 } 39 40 41 status_t 42 get_next_argument(uint32* _cookie, const char* mangledName, char* name, 43 size_t nameSize, int32* _type, size_t* _argumentLength) 44 { 45 // try the gcc3 demangler, if it looks like a gcc3 symbol 46 if (looks_like_gcc3_symbol(mangledName)) { 47 status_t error = get_next_argument_gcc3(_cookie, mangledName, name, 48 nameSize, _type, _argumentLength); 49 if (error == B_OK) 50 return B_OK; 51 } 52 53 // fallback is gcc2 54 return get_next_argument_gcc2(_cookie, mangledName, name, nameSize, _type, 55 _argumentLength); 56 } 57 58 59 #ifdef _KERNEL_MODE 60 61 static status_t 62 std_ops(int32 op, ...) 63 { 64 switch (op) { 65 case B_MODULE_INIT: 66 case B_MODULE_UNINIT: 67 return B_OK; 68 } 69 70 return B_BAD_VALUE; 71 } 72 73 74 static struct debugger_demangle_module_info sModuleInfo = { 75 { 76 "debugger/demangle/v1", 77 0, 78 std_ops 79 }, 80 81 demangle_symbol, 82 get_next_argument, 83 }; 84 85 module_info* modules[] = { 86 (module_info*)&sModuleInfo, 87 NULL 88 }; 89 90 #endif // _KERNEL_MODE 91