]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/psymtab.h
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / psymtab.h
CommitLineData
ccefe4c4
TT
1/* Public partial symbol table definitions.
2
213516ef 3 Copyright (C) 2009-2023 Free Software Foundation, Inc.
ccefe4c4
TT
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20#ifndef PSYMTAB_H
21#define PSYMTAB_H
22
bf31fd38 23#include "gdbsupport/gdb_obstack.h"
44b13c5a 24#include "symfile.h"
268a13a5 25#include "gdbsupport/next-iterator.h"
25629dfd 26#include "bcache.h"
44b13c5a 27
d320c2b5
TT
28struct partial_symbol;
29
89806626
SM
30/* Specialization of bcache to store partial symbols. */
31
32struct psymbol_bcache : public gdb::bcache
33{
34 /* Calculate a hash code for the given partial symbol. The hash is
35 calculated using the symbol's value, language, domain, class
36 and name. These are the values which are set by
37 add_psymbol_to_bcache. */
38 unsigned long hash (const void *addr, int length) override;
39
40 /* Returns true if the symbol LEFT equals the symbol RIGHT.
41 For the comparison this function uses a symbols value,
42 language, domain, class and name. */
43 int compare (const void *left, const void *right, int length) override;
44};
45
d320c2b5 46/* An instance of this class manages the partial symbol tables and
8d7bcccb
TT
47 partial symbols for a given objfile.
48
49 The core psymtab functions -- those in psymtab.c -- arrange for
50 nearly all psymtab- and psymbol-related allocations to happen
51 either in the psymtab_storage object (either on its obstack or in
52 other memory managed by this class), or on the per-BFD object. The
53 only link from the psymtab storage object back to the objfile (or
54 objfile_obstack) that is made by the core psymtab code is the
f056b22b
TT
55 compunit_symtab member in the standard_psymtab -- and a given
56 symbol reader can avoid this by implementing its own subclasses of
57 partial_symtab.
8d7bcccb
TT
58
59 However, it is up to each symbol reader to maintain this invariant
60 in other ways, if it wants to reuse psymtabs across multiple
61 objfiles. The main issue here is ensuring that read_symtab_private
62 does not point into objfile_obstack. */
cbd70537 63
d320c2b5
TT
64class psymtab_storage
65{
66public:
89806626 67 psymtab_storage () = default;
d320c2b5 68 ~psymtab_storage ();
b22a7c6a 69
d320c2b5
TT
70 DISABLE_COPY_AND_ASSIGN (psymtab_storage);
71
72 /* Discard all partial symbol tables starting with "psymtabs" and
73 proceeding until "to" has been discarded. */
b22a7c6a 74
d320c2b5 75 void discard_psymtabs_to (struct partial_symtab *to)
b22a7c6a 76 {
d320c2b5
TT
77 while (psymtabs != to)
78 discard_psymtab (psymtabs);
b22a7c6a 79 }
d320c2b5
TT
80
81 /* Discard the partial symbol table. */
82
83 void discard_psymtab (struct partial_symtab *pst);
84
5923a04c
TT
85 /* Return the obstack that is used for storage by this object. */
86
87 struct obstack *obstack ()
88 {
8d7bcccb
TT
89 if (!m_obstack.has_value ())
90 m_obstack.emplace ();
91 return &*m_obstack;
5923a04c
TT
92 }
93
a9342b62
TT
94 /* Allocate storage for the "dependencies" field of a psymtab.
95 NUMBER says how many dependencies there are. */
96
97 struct partial_symtab **allocate_dependencies (int number)
98 {
99 return OBSTACK_CALLOC (obstack (), number, struct partial_symtab *);
100 }
101
abaa2f23
TT
102 /* Install a psymtab on the psymtab list. This transfers ownership
103 of PST to this object. */
b596a3c7 104
abaa2f23 105 void install_psymtab (partial_symtab *pst);
b596a3c7 106
9be25986 107 using partial_symtab_range = next_range<partial_symtab>;
f252c6d5
TT
108
109 /* A range adapter that makes it possible to iterate over all
110 psymtabs in one objfile. */
111
112 partial_symtab_range range ()
113 {
114 return partial_symtab_range (psymtabs);
115 }
116
d320c2b5
TT
117
118 /* Each objfile points to a linked list of partial symtabs derived from
119 this file, one partial symtab structure for each compilation unit
120 (source file). */
121
122 struct partial_symtab *psymtabs = nullptr;
123
d320c2b5
TT
124 /* A byte cache where we can stash arbitrary "chunks" of bytes that
125 will not change. */
126
89806626 127 psymbol_bcache psymbol_cache;
d320c2b5 128
5923a04c
TT
129private:
130
8d7bcccb
TT
131 /* The obstack where allocations are made. This is lazily allocated
132 so that we don't waste memory when there are no psymtabs. */
5923a04c 133
8d7bcccb 134 gdb::optional<auto_obstack> m_obstack;
b22a7c6a
TT
135};
136
ccefe4c4 137#endif /* PSYMTAB_H */