Fix leak in solib-target.c:library_list_start_library
[deliverable/binutils-gdb.git] / gdb / psymtab.h
CommitLineData
ccefe4c4
TT
1/* Public partial symbol table definitions.
2
42a4f53d 3 Copyright (C) 2009-2019 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
a9342b62 23#include "gdb_obstack.h"
44b13c5a 24#include "symfile.h"
b22a7c6a 25#include "common/next-iterator.h"
44b13c5a 26
d320c2b5
TT
27struct partial_symbol;
28
710e1a31
SW
29/* A bcache for partial symbols. */
30
31struct psymbol_bcache;
32
d320c2b5 33/* An instance of this class manages the partial symbol tables and
8d7bcccb
TT
34 partial symbols for a given objfile.
35
36 The core psymtab functions -- those in psymtab.c -- arrange for
37 nearly all psymtab- and psymbol-related allocations to happen
38 either in the psymtab_storage object (either on its obstack or in
39 other memory managed by this class), or on the per-BFD object. The
40 only link from the psymtab storage object back to the objfile (or
41 objfile_obstack) that is made by the core psymtab code is the
42 compunit_symtab member in the psymtab.
43
44 However, it is up to each symbol reader to maintain this invariant
45 in other ways, if it wants to reuse psymtabs across multiple
46 objfiles. The main issue here is ensuring that read_symtab_private
47 does not point into objfile_obstack. */
cbd70537 48
d320c2b5
TT
49class psymtab_storage
50{
51public:
ccefe4c4 52
8d7bcccb 53 psymtab_storage ();
9291a0cd 54
d320c2b5 55 ~psymtab_storage ();
b22a7c6a 56
d320c2b5
TT
57 DISABLE_COPY_AND_ASSIGN (psymtab_storage);
58
59 /* Discard all partial symbol tables starting with "psymtabs" and
60 proceeding until "to" has been discarded. */
b22a7c6a 61
d320c2b5 62 void discard_psymtabs_to (struct partial_symtab *to)
b22a7c6a 63 {
d320c2b5
TT
64 while (psymtabs != to)
65 discard_psymtab (psymtabs);
b22a7c6a 66 }
d320c2b5
TT
67
68 /* Discard the partial symbol table. */
69
70 void discard_psymtab (struct partial_symtab *pst);
71
5923a04c
TT
72 /* Return the obstack that is used for storage by this object. */
73
74 struct obstack *obstack ()
75 {
8d7bcccb
TT
76 if (!m_obstack.has_value ())
77 m_obstack.emplace ();
78 return &*m_obstack;
5923a04c
TT
79 }
80
a9342b62
TT
81 /* Allocate storage for the "dependencies" field of a psymtab.
82 NUMBER says how many dependencies there are. */
83
84 struct partial_symtab **allocate_dependencies (int number)
85 {
86 return OBSTACK_CALLOC (obstack (), number, struct partial_symtab *);
87 }
88
b596a3c7
TT
89 /* Allocate a new psymtab on the psymtab obstack. The new psymtab
90 will be linked in to the "psymtabs" list, but otherwise all other
91 fields will be zero. */
92
93 struct partial_symtab *allocate_psymtab ();
94
d320c2b5
TT
95
96 /* Each objfile points to a linked list of partial symtabs derived from
97 this file, one partial symtab structure for each compilation unit
98 (source file). */
99
100 struct partial_symtab *psymtabs = nullptr;
101
102 /* Map addresses to the entries of PSYMTABS. It would be more efficient to
103 have a map per the whole process but ADDRMAP cannot selectively remove
104 its items during FREE_OBJFILE. This mapping is already present even for
105 PARTIAL_SYMTABs which still have no corresponding full SYMTABs read. */
106
107 struct addrmap *psymtabs_addrmap = nullptr;
108
d320c2b5
TT
109 /* A byte cache where we can stash arbitrary "chunks" of bytes that
110 will not change. */
111
112 struct psymbol_bcache *psymbol_cache;
113
114 /* Vectors of all partial symbols read in from file. The actual data
115 is stored in the objfile_obstack. */
116
117 std::vector<partial_symbol *> global_psymbols;
118 std::vector<partial_symbol *> static_psymbols;
5923a04c
TT
119
120private:
121
b596a3c7
TT
122 /* List of freed partial symtabs, available for re-use. */
123
124 struct partial_symtab *free_psymtabs = nullptr;
125
8d7bcccb
TT
126 /* The obstack where allocations are made. This is lazily allocated
127 so that we don't waste memory when there are no psymtabs. */
5923a04c 128
8d7bcccb 129 gdb::optional<auto_obstack> m_obstack;
b22a7c6a
TT
130};
131
d320c2b5
TT
132
133extern struct psymbol_bcache *psymbol_bcache_init (void);
134extern void psymbol_bcache_free (struct psymbol_bcache *);
135extern struct bcache *psymbol_bcache_get_bcache (struct psymbol_bcache *);
136
137extern const struct quick_symbol_functions psym_functions;
138
139extern const struct quick_symbol_functions dwarf2_gdb_index_functions;
140extern const struct quick_symbol_functions dwarf2_debug_names_functions;
141
b11896a5
TT
142/* Ensure that the partial symbols for OBJFILE have been loaded. If
143 VERBOSE is non-zero, then this will print a message when symbols
b22a7c6a
TT
144 are loaded. This function returns a range adapter suitable for
145 iterating over the psymtabs of OBJFILE. */
b11896a5 146
d320c2b5 147class objfile_psymtabs;
b22a7c6a
TT
148extern objfile_psymtabs require_partial_symbols (struct objfile *objfile,
149 int verbose);
b11896a5 150
ccefe4c4 151#endif /* PSYMTAB_H */
This page took 0.87373 seconds and 4 git commands to generate.