GDB (xrefs)
Loading...
Searching...
No Matches
psymtab.h
Go to the documentation of this file.
1/* Public partial symbol table definitions.
2
3 Copyright (C) 2009-2023 Free Software Foundation, Inc.
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
23#include "gdbsupport/gdb_obstack.h"
24#include "symfile.h"
25#include "gdbsupport/next-iterator.h"
26#include "bcache.h"
27
28struct partial_symbol;
29
30/* Specialization of bcache to store partial symbols. */
31
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
46/* An instance of this class manages the partial symbol tables and
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
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.
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. */
63
65{
66public:
67 psymtab_storage () = default;
69
71
72 /* Discard all partial symbol tables starting with "psymtabs" and
73 proceeding until "to" has been discarded. */
74
76 {
77 while (psymtabs != to)
79 }
80
81 /* Discard the partial symbol table. */
82
83 void discard_psymtab (struct partial_symtab *pst);
84
85 /* Return the obstack that is used for storage by this object. */
86
87 struct obstack *obstack ()
88 {
89 if (!m_obstack.has_value ())
90 m_obstack.emplace ();
91 return &*m_obstack;
92 }
93
94 /* Allocate storage for the "dependencies" field of a psymtab.
95 NUMBER says how many dependencies there are. */
96
98 {
99 return OBSTACK_CALLOC (obstack (), number, struct partial_symtab *);
100 }
101
102 /* Install a psymtab on the psymtab list. This transfers ownership
103 of PST to this object. */
104
106
107 using partial_symtab_range = next_range<partial_symtab>;
108
109 /* A range adapter that makes it possible to iterate over all
110 psymtabs in one objfile. */
111
113 {
115 }
116
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
124 /* A byte cache where we can stash arbitrary "chunks" of bytes that
125 will not change. */
126
128
129private:
130
131 /* The obstack where allocations are made. This is lazily allocated
132 so that we don't waste memory when there are no psymtabs. */
133
134 gdb::optional<auto_obstack> m_obstack;
135};
136
137#endif /* PSYMTAB_H */
struct partial_symtab * psymtabs
Definition psymtab.h:122
gdb::optional< auto_obstack > m_obstack
Definition psymtab.h:134
void discard_psymtab(struct partial_symtab *pst)
Definition psymtab.c:1364
psymtab_storage()=default
DISABLE_COPY_AND_ASSIGN(psymtab_storage)
partial_symtab_range range()
Definition psymtab.h:112
void install_psymtab(partial_symtab *pst)
Definition psymtab.c:71
struct partial_symtab ** allocate_dependencies(int number)
Definition psymtab.h:97
void discard_psymtabs_to(struct partial_symtab *to)
Definition psymtab.h:75
next_range< partial_symtab > partial_symtab_range
Definition psymtab.h:107
struct obstack * obstack()
Definition psymtab.h:87
psymbol_bcache psymbol_cache
Definition psymtab.h:127
unsigned long hash(const void *addr, int length) override
Definition psymtab.c:1211
int compare(const void *left, const void *right, int length) override
Definition psymtab.c:1233