xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/dwarf2/mapped-index.h (revision 6881a4007f077b54e5f51159c52b9b25f57deb0d)
1*6881a400Schristos /* Base class for mapped indices
2*6881a400Schristos 
3*6881a400Schristos    Copyright (C) 2021-2023 Free Software Foundation, Inc.
4*6881a400Schristos 
5*6881a400Schristos    This file is part of GDB.
6*6881a400Schristos 
7*6881a400Schristos    This program is free software; you can redistribute it and/or modify
8*6881a400Schristos    it under the terms of the GNU General Public License as published by
9*6881a400Schristos    the Free Software Foundation; either version 3 of the License, or
10*6881a400Schristos    (at your option) any later version.
11*6881a400Schristos 
12*6881a400Schristos    This program is distributed in the hope that it will be useful,
13*6881a400Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
14*6881a400Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*6881a400Schristos    GNU General Public License for more details.
16*6881a400Schristos 
17*6881a400Schristos    You should have received a copy of the GNU General Public License
18*6881a400Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19*6881a400Schristos 
20*6881a400Schristos #ifndef GDB_DWARF2_MAPPED_INDEX_H
21*6881a400Schristos #define GDB_DWARF2_MAPPED_INDEX_H
22*6881a400Schristos 
23*6881a400Schristos #include "language.h"
24*6881a400Schristos 
25*6881a400Schristos /* An index into a (C++) symbol name component in a symbol name as
26*6881a400Schristos    recorded in the mapped_index's symbol table.  For each C++ symbol
27*6881a400Schristos    in the symbol table, we record one entry for the start of each
28*6881a400Schristos    component in the symbol in a table of name components, and then
29*6881a400Schristos    sort the table, in order to be able to binary search symbol names,
30*6881a400Schristos    ignoring leading namespaces, both completion and regular look up.
31*6881a400Schristos    For example, for symbol "A::B::C", we'll have an entry that points
32*6881a400Schristos    to "A::B::C", another that points to "B::C", and another for "C".
33*6881a400Schristos    Note that function symbols in GDB index have no parameter
34*6881a400Schristos    information, just the function/method names.  You can convert a
35*6881a400Schristos    name_component to a "const char *" using the
36*6881a400Schristos    'mapped_index::symbol_name_at(offset_type)' method.  */
37*6881a400Schristos 
38*6881a400Schristos struct name_component
39*6881a400Schristos {
40*6881a400Schristos   /* Offset in the symbol name where the component starts.  Stored as
41*6881a400Schristos      a (32-bit) offset instead of a pointer to save memory and improve
42*6881a400Schristos      locality on 64-bit architectures.  */
43*6881a400Schristos   offset_type name_offset;
44*6881a400Schristos 
45*6881a400Schristos   /* The symbol's index in the symbol and constant pool tables of a
46*6881a400Schristos      mapped_index.  */
47*6881a400Schristos   offset_type idx;
48*6881a400Schristos };
49*6881a400Schristos 
50*6881a400Schristos class cooked_index_vector;
51*6881a400Schristos 
52*6881a400Schristos /* Base class of all DWARF scanner types.  */
53*6881a400Schristos 
54*6881a400Schristos struct dwarf_scanner_base
55*6881a400Schristos {
56*6881a400Schristos   dwarf_scanner_base () = default;
57*6881a400Schristos   virtual ~dwarf_scanner_base () = default;
58*6881a400Schristos   DISABLE_COPY_AND_ASSIGN (dwarf_scanner_base);
59*6881a400Schristos 
60*6881a400Schristos   /* Return a quick_symbol_functions instance that refers back to this
61*6881a400Schristos      dwarf_scanner_base.  */
62*6881a400Schristos   virtual quick_symbol_functions_up make_quick_functions () const = 0;
63*6881a400Schristos 
64*6881a400Schristos   /* An ad hoc version check.  This is needed for .gdb_index to check
65*6881a400Schristos      whether a version 8 or above index is in use.  Returns true if
66*6881a400Schristos      the index is usable, false otherwise.  */
67*6881a400Schristos   virtual bool version_check () const
68*6881a400Schristos   {
69*6881a400Schristos     return true;
70*6881a400Schristos   }
71*6881a400Schristos 
72*6881a400Schristos   /* This is called when writing an index.  For a cooked index, it
73*6881a400Schristos      will return 'this' as a cooked index.  For other forms, it will
74*6881a400Schristos      throw an exception with an appropriate error message.  */
75*6881a400Schristos   virtual cooked_index_vector *index_for_writing () = 0;
76*6881a400Schristos };
77*6881a400Schristos 
78*6881a400Schristos /* Base class containing bits shared by both .gdb_index and
79*6881a400Schristos    .debug_name indexes.  */
80*6881a400Schristos 
81*6881a400Schristos struct mapped_index_base : public dwarf_scanner_base
82*6881a400Schristos {
83*6881a400Schristos   mapped_index_base () = default;
84*6881a400Schristos   DISABLE_COPY_AND_ASSIGN (mapped_index_base);
85*6881a400Schristos 
86*6881a400Schristos   /* The name_component table (a sorted vector).  See name_component's
87*6881a400Schristos      description above.  */
88*6881a400Schristos   std::vector<name_component> name_components;
89*6881a400Schristos 
90*6881a400Schristos   /* How NAME_COMPONENTS is sorted.  */
91*6881a400Schristos   enum case_sensitivity name_components_casing;
92*6881a400Schristos 
93*6881a400Schristos   /* Return the number of names in the symbol table.  */
94*6881a400Schristos   virtual size_t symbol_name_count () const = 0;
95*6881a400Schristos 
96*6881a400Schristos   /* Get the name of the symbol at IDX in the symbol table.  */
97*6881a400Schristos   virtual const char *symbol_name_at
98*6881a400Schristos     (offset_type idx, dwarf2_per_objfile *per_objfile) const = 0;
99*6881a400Schristos 
100*6881a400Schristos   /* Return whether the name at IDX in the symbol table should be
101*6881a400Schristos      ignored.  */
102*6881a400Schristos   virtual bool symbol_name_slot_invalid (offset_type idx) const
103*6881a400Schristos   {
104*6881a400Schristos     return false;
105*6881a400Schristos   }
106*6881a400Schristos 
107*6881a400Schristos   /* Build the symbol name component sorted vector, if we haven't
108*6881a400Schristos      yet.  */
109*6881a400Schristos   void build_name_components (dwarf2_per_objfile *per_objfile);
110*6881a400Schristos 
111*6881a400Schristos   /* Returns the lower (inclusive) and upper (exclusive) bounds of the
112*6881a400Schristos      possible matches for LN_NO_PARAMS in the name component
113*6881a400Schristos      vector.  */
114*6881a400Schristos   std::pair<std::vector<name_component>::const_iterator,
115*6881a400Schristos 	    std::vector<name_component>::const_iterator>
116*6881a400Schristos     find_name_components_bounds (const lookup_name_info &ln_no_params,
117*6881a400Schristos 				 enum language lang,
118*6881a400Schristos 				 dwarf2_per_objfile *per_objfile) const;
119*6881a400Schristos 
120*6881a400Schristos   cooked_index_vector *index_for_writing () override
121*6881a400Schristos   {
122*6881a400Schristos     error (_("Cannot use an index to create the index"));
123*6881a400Schristos   }
124*6881a400Schristos };
125*6881a400Schristos 
126*6881a400Schristos #endif /* GDB_DWARF2_MAPPED_INDEX_H */
127