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