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