OLD | NEW |
---|---|
1 // Copyright (c) 2010 Google Inc. | 1 // Copyright (c) 2010 Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 16 matching lines...) Expand all Loading... | |
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
30 // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com> | 30 // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com> |
31 | 31 |
32 // language.cc: Subclasses and singletons for google_breakpad::Language. | 32 // language.cc: Subclasses and singletons for google_breakpad::Language. |
33 // See language.h for details. | 33 // See language.h for details. |
34 | 34 |
35 #include "common/language.h" | 35 #include "common/language.h" |
36 | 36 |
37 #include <stdlib.h> | |
38 | |
39 #if !defined(__ANDROID__) | |
40 #include <cxxabi.h> | |
41 #endif | |
42 | |
43 #include <limits> | |
44 | |
45 namespace { | |
46 | |
47 string MakeQualifiedNameWithSeparator(const string& parent_name, | |
48 const char* separator, | |
49 const string& name) { | |
50 if (parent_name.empty()) { | |
51 return name; | |
52 } | |
53 | |
54 return parent_name + separator + name; | |
55 } | |
56 | |
57 } // namespace | |
58 | |
37 namespace google_breakpad { | 59 namespace google_breakpad { |
38 | 60 |
39 // C++ language-specific operations. | 61 // C++ language-specific operations. |
40 class CPPLanguage: public Language { | 62 class CPPLanguage: public Language { |
41 public: | 63 public: |
42 CPPLanguage() {} | 64 CPPLanguage() {} |
65 | |
43 string MakeQualifiedName(const string &parent_name, | 66 string MakeQualifiedName(const string &parent_name, |
44 const string &name) const { | 67 const string &name) const { |
45 if (parent_name.empty()) | 68 return MakeQualifiedNameWithSeparator(parent_name, "::", name); |
46 return name; | 69 } |
47 else | 70 |
48 return parent_name + "::" + name; | 71 virtual DemangleResult DemangleName(const string& mangled, |
72 std::string* demangled) const { | |
73 #if defined(__ANDROID__) | |
74 // Android NDK doesn't provide abi::__cxa_demangle. | |
75 demangled->clear(); | |
76 return kDontDemangle; | |
77 #endif | |
Ted Mielczarek
2016/09/23 14:28:44
You need to wrap the rest of the function body in
| |
78 | |
79 int status; | |
80 char* demangled_c = | |
81 abi::__cxa_demangle(mangled.c_str(), NULL, NULL, &status); | |
82 | |
83 DemangleResult result; | |
84 if (status == 0) { | |
85 result = kDemangleSuccess; | |
86 demangled->clear(); | |
87 } else { | |
88 result = kDemangleFailure; | |
89 demangled->assign(demangled_c); | |
dawikur
2016/09/26 13:28:02
It is possible that demangled_c here is nullptr, w
| |
90 } | |
91 | |
92 if (demangled_c) { | |
93 free(reinterpret_cast<void*>(demangled_c)); | |
94 } | |
95 | |
96 return result; | |
49 } | 97 } |
50 }; | 98 }; |
51 | 99 |
52 CPPLanguage CPPLanguageSingleton; | 100 CPPLanguage CPPLanguageSingleton; |
53 | 101 |
54 // Java language-specific operations. | 102 // Java language-specific operations. |
55 class JavaLanguage: public Language { | 103 class JavaLanguage: public Language { |
56 public: | 104 public: |
105 JavaLanguage() {} | |
106 | |
57 string MakeQualifiedName(const string &parent_name, | 107 string MakeQualifiedName(const string &parent_name, |
58 const string &name) const { | 108 const string &name) const { |
59 if (parent_name.empty()) | 109 return MakeQualifiedNameWithSeparator(parent_name, ".", name); |
60 return name; | |
61 else | |
62 return parent_name + "." + name; | |
63 } | 110 } |
64 }; | 111 }; |
65 | 112 |
66 JavaLanguage JavaLanguageSingleton; | 113 JavaLanguage JavaLanguageSingleton; |
67 | 114 |
115 // Swift language-specific operations. | |
116 class SwiftLanguage: public Language { | |
117 public: | |
118 SwiftLanguage() {} | |
119 | |
120 string MakeQualifiedName(const string &parent_name, | |
121 const string &name) const { | |
122 return MakeQualifiedNameWithSeparator(parent_name, ".", name); | |
123 } | |
124 | |
125 virtual DemangleResult DemangleName(const string& mangled, | |
126 std::string* demangled) const { | |
127 // There is no programmatic interface to a Swift demangler. Pass through the | |
128 // mangled form because it encodes more information than the qualified name | |
129 // that would have been built by MakeQualifiedName(). The output can be | |
130 // post-processed by xcrun swift-demangle to transform mangled Swift names | |
131 // into something more readable. | |
132 demangled->assign(mangled); | |
133 return kDemangleSuccess; | |
134 } | |
135 }; | |
136 | |
137 SwiftLanguage SwiftLanguageSingleton; | |
138 | |
68 // Assembler language-specific operations. | 139 // Assembler language-specific operations. |
69 class AssemblerLanguage: public Language { | 140 class AssemblerLanguage: public Language { |
141 public: | |
142 AssemblerLanguage() {} | |
143 | |
70 bool HasFunctions() const { return false; } | 144 bool HasFunctions() const { return false; } |
71 string MakeQualifiedName(const string &parent_name, | 145 string MakeQualifiedName(const string &parent_name, |
72 const string &name) const { | 146 const string &name) const { |
73 return name; | 147 return name; |
74 } | 148 } |
75 }; | 149 }; |
76 | 150 |
77 AssemblerLanguage AssemblerLanguageSingleton; | 151 AssemblerLanguage AssemblerLanguageSingleton; |
78 | 152 |
79 const Language * const Language::CPlusPlus = &CPPLanguageSingleton; | 153 const Language * const Language::CPlusPlus = &CPPLanguageSingleton; |
80 const Language * const Language::Java = &JavaLanguageSingleton; | 154 const Language * const Language::Java = &JavaLanguageSingleton; |
155 const Language * const Language::Swift = &SwiftLanguageSingleton; | |
81 const Language * const Language::Assembler = &AssemblerLanguageSingleton; | 156 const Language * const Language::Assembler = &AssemblerLanguageSingleton; |
82 | 157 |
83 } // namespace google_breakpad | 158 } // namespace google_breakpad |
OLD | NEW |