1 /* Minimal symbol table definitions for GDB.
3 Copyright (C) 2011-2021 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/>. */
25 /* Several lookup functions return both a minimal symbol and the
26 objfile in which it is found. This structure is used in these
29 struct bound_minimal_symbol
31 /* The minimal symbol that was found, or NULL if no minimal symbol
34 struct minimal_symbol
*minsym
;
36 /* If MINSYM is not NULL, then this is the objfile in which the
39 struct objfile
*objfile
;
41 /* Return the obj_section from OBJFILE for MINSYM. */
43 struct obj_section
*obj_section () const
45 return minsym
->obj_section (objfile
);
49 /* This header declares most of the API for dealing with minimal
50 symbols and minimal symbol tables. A few things are declared
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.
57 For the definition of the minimal symbol structure, see struct
58 minimal_symbol in symtab.h.
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.
67 /* An RAII-based object that is used to record minimal symbols while
68 they are being read. */
69 class minimal_symbol_reader
73 /* Prepare to start collecting minimal symbols. This should be
74 called by a symbol reader to initialize the minimal symbol
77 explicit minimal_symbol_reader (struct objfile
*);
79 ~minimal_symbol_reader ();
81 /* Install the minimal symbols that have been collected into the
86 /* Record a new minimal symbol. This is the "full" entry point;
87 simpler convenience entry points are also provided below.
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.
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
106 struct minimal_symbol
*record_full (gdb::string_view name
,
109 enum minimal_symbol_type ms_type
,
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
117 This variant does not return the new symbol. */
119 void record (const char *name
, CORE_ADDR address
,
120 enum minimal_symbol_type ms_type
);
122 /* Like record_full, but:
123 - computes the length of NAME
124 - passes COPY_NAME = true.
126 This variant does not return the new symbol. */
128 void record_with_info (const char *name
, CORE_ADDR address
,
129 enum minimal_symbol_type ms_type
,
132 record_full (name
, true, address
, ms_type
, section
);
137 DISABLE_COPY_AND_ASSIGN (minimal_symbol_reader
);
139 struct objfile
*m_objfile
;
141 /* Bunch currently being filled up.
142 The next field points to chain of filled bunches. */
144 struct msym_bunch
*m_msym_bunch
;
146 /* Number of slots filled in current bunch. */
148 int m_msym_bunch_index
;
150 /* Total number of minimal symbols recorded so far for the
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. */
163 bool msymbol_is_function (struct objfile
*objfile
,
164 minimal_symbol
*minsym
,
165 CORE_ADDR
*func_address_p
= NULL
);
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". */
170 unsigned int msymbol_hash (const char *);
172 /* Like msymbol_hash, but compute a hash code that is compatible with
175 unsigned int msymbol_hash_iw (const char *);
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
181 #define SYMBOL_HASH_NEXT(hash, c) \
182 ((hash) * 67 + TOLOWER ((unsigned char) (c)) - 113)
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. */
193 struct bound_minimal_symbol
lookup_minimal_symbol (const char *,
197 /* Like lookup_minimal_symbol, but searches all files and
200 struct bound_minimal_symbol
lookup_bound_minimal_symbol (const char *);
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
208 This function only searches the mangled (linkage) names. */
210 struct bound_minimal_symbol
lookup_minimal_symbol_text (const char *,
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. */
220 extern struct bound_minimal_symbol lookup_minimal_symbol_linkage
221 (const char *name
, struct objfile
*objf
)
222 ATTRIBUTE_NONNULL (1) ATTRIBUTE_NONNULL (2);
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. */
229 struct minimal_symbol
*lookup_minimal_symbol_by_pc_name
230 (CORE_ADDR
, const char *, struct objfile
*);
232 enum class lookup_msym_prefer
234 /* Prefer mst_text symbols. */
237 /* Prefer mst_solib_trampoline symbols when there are text and
238 trampoline symbols at the same address. Otherwise prefer
242 /* Prefer mst_text_gnu_ifunc symbols when there are text and ifunc
243 symbols at the same address. Otherwise prefer mst_text
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.
254 If SECTION is NULL, this uses the result of find_pc_section
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.
260 See definition of lookup_msym_prefer for description of PREFER. By
261 default mst_text symbols are preferred.
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
267 struct bound_minimal_symbol lookup_minimal_symbol_by_pc_section
269 struct obj_section
*section
,
270 lookup_msym_prefer prefer
= lookup_msym_prefer::TEXT
,
271 bound_minimal_symbol
*previous
= nullptr);
273 /* Backward compatibility: search through the minimal symbol table
274 for a matching PC (no section given).
276 This is a wrapper that calls lookup_minimal_symbol_by_pc_section
277 with a NULL section argument. */
279 struct bound_minimal_symbol
lookup_minimal_symbol_by_pc (CORE_ADDR
);
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.
286 For each matching symbol, CALLBACK is called with the symbol. */
288 void iterate_over_minimal_symbols
289 (struct objfile
*objf
, const lookup_name_info
&name
,
290 gdb::function_view
<bool (struct minimal_symbol
*)> callback
);
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
298 CORE_ADDR
minimal_symbol_upper_bound (struct bound_minimal_symbol minsym
);
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
304 type
*find_minsym_type_and_address (minimal_symbol
*msymbol
, objfile
*objf
,
305 CORE_ADDR
*address_p
);
307 #endif /* MINSYMS_H */