Automatic date update in version.in
[deliverable/binutils-gdb.git] / gdb / minsyms.h
1 /* Minimal symbol table definitions for GDB.
2
3 Copyright (C) 2011-2021 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 MINSYMS_H
21 #define MINSYMS_H
22
23 struct type;
24
25 /* Several lookup functions return both a minimal symbol and the
26 objfile in which it is found. This structure is used in these
27 cases. */
28
29 struct bound_minimal_symbol
30 {
31 /* The minimal symbol that was found, or NULL if no minimal symbol
32 was found. */
33
34 struct minimal_symbol *minsym;
35
36 /* If MINSYM is not NULL, then this is the objfile in which the
37 symbol is defined. */
38
39 struct objfile *objfile;
40
41 /* Return the obj_section from OBJFILE for MINSYM. */
42
43 struct obj_section *obj_section () const
44 {
45 return minsym->obj_section (objfile);
46 }
47 };
48
49 /* This header declares most of the API for dealing with minimal
50 symbols and minimal symbol tables. A few things are declared
51 elsewhere; see below.
52
53 A minimal symbol is a symbol for which there is no direct debug
54 information. For example, for an ELF binary, minimal symbols are
55 created from the ELF symbol table.
56
57 For the definition of the minimal symbol structure, see struct
58 minimal_symbol in symtab.h.
59
60 Minimal symbols are stored in tables attached to an objfile; see
61 objfiles.h for details. Code should generally treat these tables
62 as opaque and use functions provided by minsyms.c to inspect them.
63 */
64
65 struct msym_bunch;
66
67 /* An RAII-based object that is used to record minimal symbols while
68 they are being read. */
69 class minimal_symbol_reader
70 {
71 public:
72
73 /* Prepare to start collecting minimal symbols. This should be
74 called by a symbol reader to initialize the minimal symbol
75 module. */
76
77 explicit minimal_symbol_reader (struct objfile *);
78
79 ~minimal_symbol_reader ();
80
81 /* Install the minimal symbols that have been collected into the
82 given objfile. */
83
84 void install ();
85
86 /* Record a new minimal symbol. This is the "full" entry point;
87 simpler convenience entry points are also provided below.
88
89 This returns a new minimal symbol. It is ok to modify the returned
90 minimal symbol (though generally not necessary). It is not ok,
91 though, to stash the pointer anywhere; as minimal symbols may be
92 moved after creation. The memory for the returned minimal symbol
93 is still owned by the minsyms.c code, and should not be freed.
94
95 Arguments are:
96
97 NAME - the symbol's name
98 COPY_NAME - if true, the minsym code must make a copy of NAME. If
99 false, then NAME must be NUL-terminated, and must have a lifetime
100 that is at least as long as OBJFILE's lifetime.
101 ADDRESS - the address of the symbol
102 MS_TYPE - the type of the symbol
103 SECTION - the symbol's section
104 */
105
106 struct minimal_symbol *record_full (gdb::string_view name,
107 bool copy_name,
108 CORE_ADDR address,
109 enum minimal_symbol_type ms_type,
110 int section);
111
112 /* Like record_full, but:
113 - computes the length of NAME
114 - passes COPY_NAME = true,
115 - and passes a default SECTION, depending on the type
116
117 This variant does not return the new symbol. */
118
119 void record (const char *name, CORE_ADDR address,
120 enum minimal_symbol_type ms_type);
121
122 /* Like record_full, but:
123 - computes the length of NAME
124 - passes COPY_NAME = true.
125
126 This variant does not return the new symbol. */
127
128 void record_with_info (const char *name, CORE_ADDR address,
129 enum minimal_symbol_type ms_type,
130 int section)
131 {
132 record_full (name, true, address, ms_type, section);
133 }
134
135 private:
136
137 DISABLE_COPY_AND_ASSIGN (minimal_symbol_reader);
138
139 struct objfile *m_objfile;
140
141 /* Bunch currently being filled up.
142 The next field points to chain of filled bunches. */
143
144 struct msym_bunch *m_msym_bunch;
145
146 /* Number of slots filled in current bunch. */
147
148 int m_msym_bunch_index;
149
150 /* Total number of minimal symbols recorded so far for the
151 objfile. */
152
153 int m_msym_count;
154 };
155
156 \f
157
158 /* Return whether MSYMBOL is a function/method. If FUNC_ADDRESS_P is
159 non-NULL, and the MSYMBOL is a function, then *FUNC_ADDRESS_P is
160 set to the function's address, already resolved if MINSYM points to
161 a function descriptor. */
162
163 bool msymbol_is_function (struct objfile *objfile,
164 minimal_symbol *minsym,
165 CORE_ADDR *func_address_p = NULL);
166
167 /* Compute a hash code for the string argument. Unlike htab_hash_string,
168 this is a case-insensitive hash to support "set case-sensitive off". */
169
170 unsigned int msymbol_hash (const char *);
171
172 /* Like msymbol_hash, but compute a hash code that is compatible with
173 strcmp_iw. */
174
175 unsigned int msymbol_hash_iw (const char *);
176
177 /* Compute the next hash value from previous HASH and the character C. This
178 is only a GDB in-memory computed value with no external files compatibility
179 requirements. */
180
181 #define SYMBOL_HASH_NEXT(hash, c) \
182 ((hash) * 67 + TOLOWER ((unsigned char) (c)) - 113)
183
184 \f
185
186 /* Look through all the current minimal symbol tables and find the
187 first minimal symbol that matches NAME. If OBJF is non-NULL, limit
188 the search to that objfile. If SFILE is non-NULL, the only
189 file-scope symbols considered will be from that source file (global
190 symbols are still preferred). Returns a bound minimal symbol that
191 matches, or an empty bound minimal symbol if no match is found. */
192
193 struct bound_minimal_symbol lookup_minimal_symbol (const char *,
194 const char *,
195 struct objfile *);
196
197 /* Like lookup_minimal_symbol, but searches all files and
198 objfiles. */
199
200 struct bound_minimal_symbol lookup_bound_minimal_symbol (const char *);
201
202 /* Look through all the current minimal symbol tables and find the
203 first minimal symbol that matches NAME and has text type. If OBJF
204 is non-NULL, limit the search to that objfile. Returns a bound
205 minimal symbol that matches, or an "empty" bound minimal symbol
206 otherwise.
207
208 This function only searches the mangled (linkage) names. */
209
210 struct bound_minimal_symbol lookup_minimal_symbol_text (const char *,
211 struct objfile *);
212
213 /* Look through the minimal symbols in OBJF (and its separate debug
214 objfiles) for a global (not file-local) minsym whose linkage name
215 is NAME. This is somewhat similar to lookup_minimal_symbol_text,
216 only data symbols (not text symbols) are considered, and a non-NULL
217 objfile is not accepted. Returns a bound minimal symbol that
218 matches, or an "empty" bound minimal symbol otherwise. */
219
220 extern struct bound_minimal_symbol lookup_minimal_symbol_linkage
221 (const char *name, struct objfile *objf)
222 ATTRIBUTE_NONNULL (1) ATTRIBUTE_NONNULL (2);
223
224 /* Look through all the current minimal symbol tables and find the
225 first minimal symbol that matches NAME and PC. If OBJF is non-NULL,
226 limit the search to that objfile. Returns a pointer to the minimal
227 symbol that matches, or NULL if no match is found. */
228
229 struct minimal_symbol *lookup_minimal_symbol_by_pc_name
230 (CORE_ADDR, const char *, struct objfile *);
231
232 enum class lookup_msym_prefer
233 {
234 /* Prefer mst_text symbols. */
235 TEXT,
236
237 /* Prefer mst_solib_trampoline symbols when there are text and
238 trampoline symbols at the same address. Otherwise prefer
239 mst_text symbols. */
240 TRAMPOLINE,
241
242 /* Prefer mst_text_gnu_ifunc symbols when there are text and ifunc
243 symbols at the same address. Otherwise prefer mst_text
244 symbols. */
245 GNU_IFUNC,
246 };
247
248 /* Search through the minimal symbol table for each objfile and find
249 the symbol whose address is the largest address that is still less
250 than or equal to PC_IN, and which matches SECTION. A matching symbol
251 must either be zero sized and have address PC_IN, or PC_IN must fall
252 within the range of addresses covered by the matching symbol.
253
254 If SECTION is NULL, this uses the result of find_pc_section
255 instead.
256
257 The result has a non-NULL 'minsym' member if such a symbol is
258 found, or NULL if PC is not in a suitable range.
259
260 See definition of lookup_msym_prefer for description of PREFER. By
261 default mst_text symbols are preferred.
262
263 If the PREVIOUS pointer is non-NULL, and no matching symbol is found,
264 then the contents will be set to reference the closest symbol before
265 PC_IN. */
266
267 struct bound_minimal_symbol lookup_minimal_symbol_by_pc_section
268 (CORE_ADDR pc_in,
269 struct obj_section *section,
270 lookup_msym_prefer prefer = lookup_msym_prefer::TEXT,
271 bound_minimal_symbol *previous = nullptr);
272
273 /* Backward compatibility: search through the minimal symbol table
274 for a matching PC (no section given).
275
276 This is a wrapper that calls lookup_minimal_symbol_by_pc_section
277 with a NULL section argument. */
278
279 struct bound_minimal_symbol lookup_minimal_symbol_by_pc (CORE_ADDR);
280
281 /* Iterate over all the minimal symbols in the objfile OBJF which
282 match NAME. Both the ordinary and demangled names of each symbol
283 are considered. The caller is responsible for canonicalizing NAME,
284 should that need to be done.
285
286 For each matching symbol, CALLBACK is called with the symbol. */
287
288 void iterate_over_minimal_symbols
289 (struct objfile *objf, const lookup_name_info &name,
290 gdb::function_view<bool (struct minimal_symbol *)> callback);
291
292 /* Compute the upper bound of MINSYM. The upper bound is the last
293 address thought to be part of the symbol. If the symbol has a
294 size, it is used. Otherwise use the lesser of the next minimal
295 symbol in the same section, or the end of the section, as the end
296 of the function. */
297
298 CORE_ADDR minimal_symbol_upper_bound (struct bound_minimal_symbol minsym);
299
300 /* Return the type of MSYMBOL, a minimal symbol of OBJFILE. If
301 ADDRESS_P is not NULL, set it to the MSYMBOL's resolved
302 address. */
303
304 type *find_minsym_type_and_address (minimal_symbol *msymbol, objfile *objf,
305 CORE_ADDR *address_p);
306
307 #endif /* MINSYMS_H */
This page took 0.03587 seconds and 4 git commands to generate.