1 /* Base class for mapped indices
3 Copyright (C) 2021-2023 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #ifndef GDB_DWARF2_MAPPED_INDEX_H
21 #define GDB_DWARF2_MAPPED_INDEX_H
25 /* An index into a (C++) symbol name component in a symbol name as
26 recorded in the mapped_index's symbol table. For each C++ symbol
27 in the symbol table, we record one entry for the start of each
28 component in the symbol in a table of name components, and then
29 sort the table, in order to be able to binary search symbol names,
30 ignoring leading namespaces, both completion and regular look up.
31 For example, for symbol "A::B::C", we'll have an entry that points
32 to "A::B::C", another that points to "B::C", and another for "C".
33 Note that function symbols in GDB index have no parameter
34 information, just the function/method names. You can convert a
35 name_component to a "const char *" using the
36 'mapped_index::symbol_name_at(offset_type)' method. */
40 /* Offset in the symbol name where the component starts. Stored as
41 a (32-bit) offset instead of a pointer to save memory and improve
42 locality on 64-bit architectures. */
43 offset_type name_offset
;
45 /* The symbol's index in the symbol and constant pool tables of a
52 /* Base class of all DWARF scanner types. */
54 struct dwarf_scanner_base
56 dwarf_scanner_base () = default;
57 virtual ~dwarf_scanner_base () = default;
58 DISABLE_COPY_AND_ASSIGN (dwarf_scanner_base
);
60 /* Return a quick_symbol_functions instance that refers back to this
61 dwarf_scanner_base. */
62 virtual quick_symbol_functions_up
make_quick_functions () const = 0;
64 /* An ad hoc version check. This is needed for .gdb_index to check
65 whether a version 8 or above index is in use. Returns true if
66 the index is usable, false otherwise. */
67 virtual bool version_check () const
72 /* This is called when writing an index. For a cooked index, it
73 will return 'this' as a cooked index. For other forms, it will
74 throw an exception with an appropriate error message. */
75 virtual cooked_index
*index_for_writing () = 0;
77 /* Wait for reading of the debuginfo to be completely finished.
78 This normally has a trivial implementation, but if a subclass
79 does any background reading, it's needed to ensure that the
80 reading is completed before destroying the containing per-BFD
82 virtual void wait_completely ()
87 /* Base class containing bits shared by both .gdb_index and
88 .debug_name indexes. */
90 struct mapped_index_base
: public dwarf_scanner_base
92 mapped_index_base () = default;
93 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
95 /* The name_component table (a sorted vector). See name_component's
97 std::vector
<name_component
> name_components
;
99 /* How NAME_COMPONENTS is sorted. */
100 enum case_sensitivity name_components_casing
;
102 /* Return the number of names in the symbol table. */
103 virtual size_t symbol_name_count () const = 0;
105 /* Get the name of the symbol at IDX in the symbol table. */
106 virtual const char *symbol_name_at
107 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const = 0;
109 /* Return whether the name at IDX in the symbol table should be
111 virtual bool symbol_name_slot_invalid (offset_type idx
) const
116 /* Build the symbol name component sorted vector, if we haven't
118 void build_name_components (dwarf2_per_objfile
*per_objfile
);
120 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
121 possible matches for LN_NO_PARAMS in the name component
123 std::pair
<std::vector
<name_component
>::const_iterator
,
124 std::vector
<name_component
>::const_iterator
>
125 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
127 dwarf2_per_objfile
*per_objfile
) const;
129 cooked_index
*index_for_writing () override
131 error (_("Cannot use an index to create the index"));
135 #endif /* GDB_DWARF2_MAPPED_INDEX_H */