psymtab.h revision 1.8 1 1.1 christos /* Public partial symbol table definitions.
2 1.1 christos
3 1.8 christos Copyright (C) 2009-2019 Free Software Foundation, Inc.
4 1.1 christos
5 1.1 christos This file is part of GDB.
6 1.1 christos
7 1.1 christos This program is free software; you can redistribute it and/or modify
8 1.1 christos it under the terms of the GNU General Public License as published by
9 1.1 christos the Free Software Foundation; either version 3 of the License, or
10 1.1 christos (at your option) any later version.
11 1.1 christos
12 1.1 christos This program is distributed in the hope that it will be useful,
13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1 christos GNU General Public License for more details.
16 1.1 christos
17 1.1 christos You should have received a copy of the GNU General Public License
18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 1.1 christos
20 1.1 christos #ifndef PSYMTAB_H
21 1.1 christos #define PSYMTAB_H
22 1.1 christos
23 1.8 christos #include "gdb_obstack.h"
24 1.1 christos #include "symfile.h"
25 1.8 christos #include "common/next-iterator.h"
26 1.8 christos
27 1.8 christos struct partial_symbol;
28 1.1 christos
29 1.1 christos /* A bcache for partial symbols. */
30 1.1 christos
31 1.1 christos struct psymbol_bcache;
32 1.1 christos
33 1.8 christos /* An instance of this class manages the partial symbol tables and
34 1.8 christos partial symbols for a given objfile.
35 1.8 christos
36 1.8 christos The core psymtab functions -- those in psymtab.c -- arrange for
37 1.8 christos nearly all psymtab- and psymbol-related allocations to happen
38 1.8 christos either in the psymtab_storage object (either on its obstack or in
39 1.8 christos other memory managed by this class), or on the per-BFD object. The
40 1.8 christos only link from the psymtab storage object back to the objfile (or
41 1.8 christos objfile_obstack) that is made by the core psymtab code is the
42 1.8 christos compunit_symtab member in the psymtab.
43 1.8 christos
44 1.8 christos However, it is up to each symbol reader to maintain this invariant
45 1.8 christos in other ways, if it wants to reuse psymtabs across multiple
46 1.8 christos objfiles. The main issue here is ensuring that read_symtab_private
47 1.8 christos does not point into objfile_obstack. */
48 1.8 christos
49 1.8 christos class psymtab_storage
50 1.8 christos {
51 1.8 christos public:
52 1.8 christos
53 1.8 christos psymtab_storage ();
54 1.8 christos
55 1.8 christos ~psymtab_storage ();
56 1.8 christos
57 1.8 christos DISABLE_COPY_AND_ASSIGN (psymtab_storage);
58 1.8 christos
59 1.8 christos /* Discard all partial symbol tables starting with "psymtabs" and
60 1.8 christos proceeding until "to" has been discarded. */
61 1.8 christos
62 1.8 christos void discard_psymtabs_to (struct partial_symtab *to)
63 1.8 christos {
64 1.8 christos while (psymtabs != to)
65 1.8 christos discard_psymtab (psymtabs);
66 1.8 christos }
67 1.8 christos
68 1.8 christos /* Discard the partial symbol table. */
69 1.8 christos
70 1.8 christos void discard_psymtab (struct partial_symtab *pst);
71 1.8 christos
72 1.8 christos /* Return the obstack that is used for storage by this object. */
73 1.8 christos
74 1.8 christos struct obstack *obstack ()
75 1.8 christos {
76 1.8 christos if (!m_obstack.has_value ())
77 1.8 christos m_obstack.emplace ();
78 1.8 christos return &*m_obstack;
79 1.8 christos }
80 1.8 christos
81 1.8 christos /* Allocate storage for the "dependencies" field of a psymtab.
82 1.8 christos NUMBER says how many dependencies there are. */
83 1.8 christos
84 1.8 christos struct partial_symtab **allocate_dependencies (int number)
85 1.8 christos {
86 1.8 christos return OBSTACK_CALLOC (obstack (), number, struct partial_symtab *);
87 1.8 christos }
88 1.8 christos
89 1.8 christos /* Allocate a new psymtab on the psymtab obstack. The new psymtab
90 1.8 christos will be linked in to the "psymtabs" list, but otherwise all other
91 1.8 christos fields will be zero. */
92 1.8 christos
93 1.8 christos struct partial_symtab *allocate_psymtab ();
94 1.8 christos
95 1.8 christos typedef next_adapter<struct partial_symtab> partial_symtab_range;
96 1.8 christos
97 1.8 christos /* A range adapter that makes it possible to iterate over all
98 1.8 christos psymtabs in one objfile. */
99 1.8 christos
100 1.8 christos partial_symtab_range range ()
101 1.8 christos {
102 1.8 christos return partial_symtab_range (psymtabs);
103 1.8 christos }
104 1.8 christos
105 1.8 christos
106 1.8 christos /* Each objfile points to a linked list of partial symtabs derived from
107 1.8 christos this file, one partial symtab structure for each compilation unit
108 1.8 christos (source file). */
109 1.8 christos
110 1.8 christos struct partial_symtab *psymtabs = nullptr;
111 1.8 christos
112 1.8 christos /* Map addresses to the entries of PSYMTABS. It would be more efficient to
113 1.8 christos have a map per the whole process but ADDRMAP cannot selectively remove
114 1.8 christos its items during FREE_OBJFILE. This mapping is already present even for
115 1.8 christos PARTIAL_SYMTABs which still have no corresponding full SYMTABs read. */
116 1.8 christos
117 1.8 christos struct addrmap *psymtabs_addrmap = nullptr;
118 1.8 christos
119 1.8 christos /* A byte cache where we can stash arbitrary "chunks" of bytes that
120 1.8 christos will not change. */
121 1.8 christos
122 1.8 christos struct psymbol_bcache *psymbol_cache;
123 1.8 christos
124 1.8 christos /* Vectors of all partial symbols read in from file. The actual data
125 1.8 christos is stored in the objfile_obstack. */
126 1.8 christos
127 1.8 christos std::vector<partial_symbol *> global_psymbols;
128 1.8 christos std::vector<partial_symbol *> static_psymbols;
129 1.8 christos
130 1.8 christos private:
131 1.8 christos
132 1.8 christos /* List of freed partial symtabs, available for re-use. */
133 1.8 christos
134 1.8 christos struct partial_symtab *free_psymtabs = nullptr;
135 1.8 christos
136 1.8 christos /* The obstack where allocations are made. This is lazily allocated
137 1.8 christos so that we don't waste memory when there are no psymtabs. */
138 1.8 christos
139 1.8 christos gdb::optional<auto_obstack> m_obstack;
140 1.8 christos };
141 1.8 christos
142 1.8 christos
143 1.1 christos extern struct psymbol_bcache *psymbol_bcache_init (void);
144 1.1 christos extern void psymbol_bcache_free (struct psymbol_bcache *);
145 1.1 christos extern struct bcache *psymbol_bcache_get_bcache (struct psymbol_bcache *);
146 1.1 christos
147 1.1 christos extern const struct quick_symbol_functions psym_functions;
148 1.1 christos
149 1.1 christos extern const struct quick_symbol_functions dwarf2_gdb_index_functions;
150 1.8 christos extern const struct quick_symbol_functions dwarf2_debug_names_functions;
151 1.1 christos
152 1.1 christos /* Ensure that the partial symbols for OBJFILE have been loaded. If
153 1.1 christos VERBOSE is non-zero, then this will print a message when symbols
154 1.8 christos are loaded. This function returns a range adapter suitable for
155 1.8 christos iterating over the psymtabs of OBJFILE. */
156 1.1 christos
157 1.8 christos extern psymtab_storage::partial_symtab_range require_partial_symbols
158 1.8 christos (struct objfile *objfile, int verbose);
159 1.1 christos
160 1.1 christos #endif /* PSYMTAB_H */
161