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