1 | // -*- mode: c++ -*- |
2 | |
3 | // Copyright (c) 2010 Google Inc. |
4 | // All rights reserved. |
5 | // |
6 | // Redistribution and use in source and binary forms, with or without |
7 | // modification, are permitted provided that the following conditions are |
8 | // met: |
9 | // |
10 | // * Redistributions of source code must retain the above copyright |
11 | // notice, this list of conditions and the following disclaimer. |
12 | // * Redistributions in binary form must reproduce the above |
13 | // copyright notice, this list of conditions and the following disclaimer |
14 | // in the documentation and/or other materials provided with the |
15 | // distribution. |
16 | // * Neither the name of Google Inc. nor the names of its |
17 | // contributors may be used to endorse or promote products derived from |
18 | // this software without specific prior written permission. |
19 | // |
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 | |
32 | // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com> |
33 | |
34 | // language.h: Define google_breakpad::Language. Instances of |
35 | // subclasses of this class provide language-appropriate operations |
36 | // for the Breakpad symbol dumper. |
37 | |
38 | #ifndef COMMON_LINUX_LANGUAGE_H__ |
39 | #define COMMON_LINUX_LANGUAGE_H__ |
40 | |
41 | #include <string> |
42 | |
43 | #include "common/using_std_string.h" |
44 | |
45 | namespace google_breakpad { |
46 | |
47 | // An abstract base class for language-specific operations. We choose |
48 | // an instance of a subclass of this when we find the CU's language. |
49 | // This class's definitions are appropriate for CUs with no specified |
50 | // language. |
51 | class Language { |
52 | public: |
53 | // A base class destructor should be either public and virtual, |
54 | // or protected and nonvirtual. |
55 | virtual ~Language() {} |
56 | |
57 | // Return true if this language has functions to which we can assign |
58 | // line numbers. (Debugging info for assembly language, for example, |
59 | // can have source location information, but does not have functions |
60 | // recorded using DW_TAG_subprogram DIEs.) |
61 | virtual bool HasFunctions() const { return true; } |
62 | |
63 | // Construct a fully-qualified, language-appropriate form of NAME, |
64 | // given that PARENT_NAME is the name of the construct enclosing |
65 | // NAME. If PARENT_NAME is the empty string, then NAME is a |
66 | // top-level name. |
67 | // |
68 | // This API sort of assumes that a fully-qualified name is always |
69 | // some simple textual composition of the unqualified name and its |
70 | // parent's name, and that we don't need to know anything else about |
71 | // the parent or the child (say, their DIEs' tags) to do the job. |
72 | // This is true for the languages we support at the moment, and |
73 | // keeps things concrete. Perhaps a more refined operation would |
74 | // take into account the parent and child DIE types, allow languages |
75 | // to use their own data type for complex parent names, etc. But if |
76 | // C++ doesn't need all that, who would? |
77 | virtual string MakeQualifiedName (const string& parent_name, |
78 | const string& name) const = 0; |
79 | |
80 | enum DemangleResult { |
81 | // Demangling was not performed because it’s not appropriate to attempt. |
82 | kDontDemangle = -1, |
83 | |
84 | kDemangleSuccess, |
85 | kDemangleFailure, |
86 | }; |
87 | |
88 | // Wraps abi::__cxa_demangle() or similar for languages where appropriate. |
89 | virtual DemangleResult DemangleName(const string& mangled, |
90 | string* demangled) const { |
91 | demangled->clear(); |
92 | return kDontDemangle; |
93 | } |
94 | |
95 | // Instances for specific languages. |
96 | static const Language * const CPlusPlus, |
97 | * const Java, |
98 | * const Swift, |
99 | * const Rust, |
100 | * const Assembler; |
101 | }; |
102 | |
103 | } // namespace google_breakpad |
104 | |
105 | #endif // COMMON_LINUX_LANGUAGE_H__ |
106 | |