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