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