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 |
61 const int Language::kDontDemangle = std::numeric_limits<int>::min(); | |
62 | |
39 // C++ language-specific operations. | 63 // C++ language-specific operations. |
40 class CPPLanguage: public Language { | 64 class CPPLanguage: public Language { |
41 public: | 65 public: |
42 CPPLanguage() {} | 66 CPPLanguage() {} |
67 | |
43 string MakeQualifiedName(const string &parent_name, | 68 string MakeQualifiedName(const string &parent_name, |
44 const string &name) const { | 69 const string &name) const { |
45 if (parent_name.empty()) | 70 return MakeQualifiedNameWithSeparator(parent_name, "::", name); |
46 return name; | 71 } |
47 else | 72 |
48 return parent_name + "::" + name; | 73 virtual int DemangleName(const string& mangled, std::string* demangled) |
74 const { | |
75 char* demangled_c = NULL; | |
76 int status = kDontDemangle; | |
77 #if !defined(__ANDROID__) // Android NDK doesn't provide abi::__cxa_demangle. | |
78 demangled_c = abi::__cxa_demangle(mangled.c_str(), NULL, NULL, &status); | |
79 #endif | |
Ted Mielczarek
2016/09/14 10:20:10
This seems like it'd be clearer to read if it was
| |
80 | |
81 if (status != 0) { | |
82 demangled->clear(); | |
83 } else { | |
84 demangled->assign(demangled_c); | |
85 } | |
86 | |
87 if (demangled_c) { | |
88 free(reinterpret_cast<void*>(demangled_c)); | |
89 } | |
90 | |
91 return status; | |
49 } | 92 } |
50 }; | 93 }; |
51 | 94 |
52 CPPLanguage CPPLanguageSingleton; | 95 CPPLanguage CPPLanguageSingleton; |
53 | 96 |
54 // Java language-specific operations. | 97 // Java language-specific operations. |
55 class JavaLanguage: public Language { | 98 class JavaLanguage: public Language { |
56 public: | 99 public: |
100 JavaLanguage() {} | |
101 | |
57 string MakeQualifiedName(const string &parent_name, | 102 string MakeQualifiedName(const string &parent_name, |
58 const string &name) const { | 103 const string &name) const { |
59 if (parent_name.empty()) | 104 return MakeQualifiedNameWithSeparator(parent_name, ".", name); |
60 return name; | |
61 else | |
62 return parent_name + "." + name; | |
63 } | 105 } |
64 }; | 106 }; |
65 | 107 |
66 JavaLanguage JavaLanguageSingleton; | 108 JavaLanguage JavaLanguageSingleton; |
67 | 109 |
110 // Swift language-specific operations. | |
111 class SwiftLanguage: public Language { | |
112 public: | |
113 SwiftLanguage() {} | |
114 | |
115 string MakeQualifiedName(const string &parent_name, | |
116 const string &name) const { | |
117 return MakeQualifiedNameWithSeparator(parent_name, ".", name); | |
118 } | |
119 | |
120 virtual int DemangleName(const string& mangled, std::string* demangled) | |
121 const { | |
122 // There is no programmatic interface to a Swift demangler. Pass through the | |
123 // mangled form because it encodes more information than the qualified name | |
124 // that would have been built by MakeQualifiedName(). The output can be | |
125 // post-processed by xcrun swift-demangle to transform mangled Swift names | |
126 // into something more readable. | |
127 demangled->assign(mangled); | |
128 return 0; | |
129 } | |
130 }; | |
131 | |
132 SwiftLanguage SwiftLanguageSingleton; | |
133 | |
68 // Assembler language-specific operations. | 134 // Assembler language-specific operations. |
69 class AssemblerLanguage: public Language { | 135 class AssemblerLanguage: public Language { |
136 public: | |
137 AssemblerLanguage() {} | |
138 | |
70 bool HasFunctions() const { return false; } | 139 bool HasFunctions() const { return false; } |
71 string MakeQualifiedName(const string &parent_name, | 140 string MakeQualifiedName(const string &parent_name, |
72 const string &name) const { | 141 const string &name) const { |
73 return name; | 142 return name; |
74 } | 143 } |
75 }; | 144 }; |
76 | 145 |
77 AssemblerLanguage AssemblerLanguageSingleton; | 146 AssemblerLanguage AssemblerLanguageSingleton; |
78 | 147 |
79 const Language * const Language::CPlusPlus = &CPPLanguageSingleton; | 148 const Language * const Language::CPlusPlus = &CPPLanguageSingleton; |
80 const Language * const Language::Java = &JavaLanguageSingleton; | 149 const Language * const Language::Java = &JavaLanguageSingleton; |
150 const Language * const Language::Swift = &SwiftLanguageSingleton; | |
81 const Language * const Language::Assembler = &AssemblerLanguageSingleton; | 151 const Language * const Language::Assembler = &AssemblerLanguageSingleton; |
82 | 152 |
83 } // namespace google_breakpad | 153 } // namespace google_breakpad |
OLD | NEW |