]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/minsyms.h
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / minsyms.h
CommitLineData
c35384fb
TT
1/* Minimal symbol table definitions for GDB.
2
1d506c26 3 Copyright (C) 2011-2024 Free Software Foundation, Inc.
c35384fb
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 MINSYMS_H
21#define MINSYMS_H
22
74ea4be4
PA
23struct type;
24
7cbd4a93
TT
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
29struct bound_minimal_symbol
30{
f6b3ad54
TT
31 bound_minimal_symbol (struct minimal_symbol *msym, struct objfile *objf)
32 : minsym (msym),
33 objfile (objf)
34 {
35 }
36
37 bound_minimal_symbol () = default;
38
4aeddc50
SM
39 /* Return the address of the minimal symbol in the context of the objfile. */
40
41 CORE_ADDR value_address () const
42 {
43 return this->minsym->value_address (this->objfile);
44 }
45
7cbd4a93
TT
46 /* The minimal symbol that was found, or NULL if no minimal symbol
47 was found. */
48
29ba33db 49 struct minimal_symbol *minsym = nullptr;
7cbd4a93
TT
50
51 /* If MINSYM is not NULL, then this is the objfile in which the
52 symbol is defined. */
53
29ba33db 54 struct objfile *objfile = nullptr;
1db66e34
AB
55
56 /* Return the obj_section from OBJFILE for MINSYM. */
57
58 struct obj_section *obj_section () const
59 {
60 return minsym->obj_section (objfile);
61 }
7cbd4a93
TT
62};
63
b19686e0
TT
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.
c35384fb 67
b19686e0
TT
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.
71
72 For the definition of the minimal symbol structure, see struct
73 minimal_symbol in symtab.h.
74
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.
78*/
79
8dddcb8f
TT
80struct msym_bunch;
81
873a915e
TT
82/* An RAII-based object that is used to record minimal symbols while
83 they are being read. */
84class minimal_symbol_reader
85{
86 public:
87
8dddcb8f
TT
88 /* Prepare to start collecting minimal symbols. This should be
89 called by a symbol reader to initialize the minimal symbol
90 module. */
873a915e 91
d25e8719 92 explicit minimal_symbol_reader (struct objfile *);
873a915e
TT
93
94 ~minimal_symbol_reader ();
b19686e0 95
873a915e
TT
96 /* Install the minimal symbols that have been collected into the
97 given objfile. */
b19686e0 98
d25e8719 99 void install ();
b19686e0 100
8dddcb8f
TT
101 /* Record a new minimal symbol. This is the "full" entry point;
102 simpler convenience entry points are also provided below.
103
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.
109
110 Arguments are:
111
112 NAME - the symbol's name
8dddcb8f
TT
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
ce6c454e 119 */
8dddcb8f 120
8082468f 121 struct minimal_symbol *record_full (std::string_view name,
ce6c454e 122 bool copy_name,
9675da25 123 unrelocated_addr address,
8dddcb8f
TT
124 enum minimal_symbol_type ms_type,
125 int section);
126
127 /* Like record_full, but:
31edb802 128 - computes the length of NAME
ce6c454e 129 - passes COPY_NAME = true,
8dddcb8f
TT
130 - and passes a default SECTION, depending on the type
131
132 This variant does not return the new symbol. */
133
9675da25 134 void record (const char *name, unrelocated_addr address,
ce6c454e 135 enum minimal_symbol_type ms_type);
8dddcb8f
TT
136
137 /* Like record_full, but:
31edb802 138 - computes the length of NAME
3db066bc 139 - passes COPY_NAME = true.
8dddcb8f 140
3db066bc
TT
141 This variant does not return the new symbol. */
142
9675da25 143 void record_with_info (const char *name, unrelocated_addr address,
3db066bc
TT
144 enum minimal_symbol_type ms_type,
145 int section)
8dddcb8f 146 {
31edb802 147 record_full (name, true, address, ms_type, section);
8dddcb8f
TT
148 }
149
873a915e
TT
150 private:
151
af9a2161 152 DISABLE_COPY_AND_ASSIGN (minimal_symbol_reader);
d25e8719
TT
153
154 struct objfile *m_objfile;
b19686e0 155
8dddcb8f
TT
156 /* Bunch currently being filled up.
157 The next field points to chain of filled bunches. */
158
159 struct msym_bunch *m_msym_bunch;
160
161 /* Number of slots filled in current bunch. */
162
163 int m_msym_bunch_index;
164
165 /* Total number of minimal symbols recorded so far for the
166 objfile. */
167
168 int m_msym_count;
169};
c35384fb 170
b19686e0
TT
171\f
172
4024cf2b
PA
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. */
177
178bool msymbol_is_function (struct objfile *objfile,
179 minimal_symbol *minsym,
180 CORE_ADDR *func_address_p = NULL);
bf223d3e 181
c7ee338a
CB
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". */
c35384fb
TT
184
185unsigned int msymbol_hash (const char *);
186
b19686e0
TT
187/* Like msymbol_hash, but compute a hash code that is compatible with
188 strcmp_iw. */
189
190unsigned int msymbol_hash_iw (const char *);
191
c35384fb
TT
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. */
195
196#define SYMBOL_HASH_NEXT(hash, c) \
deeeba55 197 ((hash) * 67 + TOLOWER ((unsigned char) (c)) - 113)
c35384fb 198
b19686e0
TT
199\f
200
b19686e0
TT
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
3b7344d5
TT
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. */
b19686e0 207
3b7344d5
TT
208struct bound_minimal_symbol lookup_minimal_symbol (const char *,
209 const char *,
210 struct objfile *);
c35384fb 211
3b7344d5
TT
212/* Like lookup_minimal_symbol, but searches all files and
213 objfiles. */
7c7b6655
TT
214
215struct bound_minimal_symbol lookup_bound_minimal_symbol (const char *);
216
b19686e0
TT
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
3b7344d5
TT
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.
b19686e0
TT
222
223 This function only searches the mangled (linkage) names. */
224
3b7344d5
TT
225struct bound_minimal_symbol lookup_minimal_symbol_text (const char *,
226 struct objfile *);
c35384fb 227
4b610737
TT
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. */
234
235extern struct bound_minimal_symbol lookup_minimal_symbol_linkage
236 (const char *name, struct objfile *objf)
237 ATTRIBUTE_NONNULL (1) ATTRIBUTE_NONNULL (2);
238
47ef0ac7
TT
239/* A variant of lookup_minimal_symbol_linkage that iterates over all
240 objfiles. If ONLY_MAIN is true, then only an objfile with
241 OBJF_MAINLINE will be considered. */
242
243extern struct bound_minimal_symbol lookup_minimal_symbol_linkage
244 (const char *name, bool only_main)
245 ATTRIBUTE_NONNULL (1);
246
b19686e0
TT
247/* Look through all the current minimal symbol tables and find the
248 first minimal symbol that matches NAME and PC. If OBJF is non-NULL,
249 limit the search to that objfile. Returns a pointer to the minimal
250 symbol that matches, or NULL if no match is found. */
251
c35384fb 252struct minimal_symbol *lookup_minimal_symbol_by_pc_name
b19686e0 253 (CORE_ADDR, const char *, struct objfile *);
c35384fb 254
20944a6e
PA
255enum class lookup_msym_prefer
256{
257 /* Prefer mst_text symbols. */
258 TEXT,
259
260 /* Prefer mst_solib_trampoline symbols when there are text and
261 trampoline symbols at the same address. Otherwise prefer
262 mst_text symbols. */
263 TRAMPOLINE,
264
265 /* Prefer mst_text_gnu_ifunc symbols when there are text and ifunc
266 symbols at the same address. Otherwise prefer mst_text
267 symbols. */
268 GNU_IFUNC,
269};
270
b19686e0
TT
271/* Search through the minimal symbol table for each objfile and find
272 the symbol whose address is the largest address that is still less
733d0a67
AB
273 than or equal to PC_IN, and which matches SECTION. A matching symbol
274 must either be zero sized and have address PC_IN, or PC_IN must fall
275 within the range of addresses covered by the matching symbol.
c35384fb 276
b19686e0
TT
277 If SECTION is NULL, this uses the result of find_pc_section
278 instead.
279
7cbd4a93 280 The result has a non-NULL 'minsym' member if such a symbol is
20944a6e
PA
281 found, or NULL if PC is not in a suitable range.
282
283 See definition of lookup_msym_prefer for description of PREFER. By
733d0a67
AB
284 default mst_text symbols are preferred.
285
286 If the PREVIOUS pointer is non-NULL, and no matching symbol is found,
287 then the contents will be set to reference the closest symbol before
288 PC_IN. */
c35384fb 289
7cbd4a93 290struct bound_minimal_symbol lookup_minimal_symbol_by_pc_section
733d0a67
AB
291 (CORE_ADDR pc_in,
292 struct obj_section *section,
293 lookup_msym_prefer prefer = lookup_msym_prefer::TEXT,
294 bound_minimal_symbol *previous = nullptr);
c35384fb 295
b19686e0
TT
296/* Backward compatibility: search through the minimal symbol table
297 for a matching PC (no section given).
298
299 This is a wrapper that calls lookup_minimal_symbol_by_pc_section
300 with a NULL section argument. */
c35384fb 301
7cbd4a93 302struct bound_minimal_symbol lookup_minimal_symbol_by_pc (CORE_ADDR);
c35384fb 303
b19686e0
TT
304/* Iterate over all the minimal symbols in the objfile OBJF which
305 match NAME. Both the ordinary and demangled names of each symbol
306 are considered. The caller is responsible for canonicalizing NAME,
307 should that need to be done.
c35384fb 308
41c1efc6
TT
309 For each matching symbol, CALLBACK is called with the symbol. */
310
311void iterate_over_minimal_symbols
312 (struct objfile *objf, const lookup_name_info &name,
ca31ab1d 313 gdb::function_view<bool (struct minimal_symbol *)> callback);
c35384fb 314
50e65b17
TT
315/* Compute the upper bound of MINSYM. The upper bound is the last
316 address thought to be part of the symbol. If the symbol has a
317 size, it is used. Otherwise use the lesser of the next minimal
318 symbol in the same section, or the end of the section, as the end
319 of the function. */
320
321CORE_ADDR minimal_symbol_upper_bound (struct bound_minimal_symbol minsym);
322
74ea4be4
PA
323/* Return the type of MSYMBOL, a minimal symbol of OBJFILE. If
324 ADDRESS_P is not NULL, set it to the MSYMBOL's resolved
325 address. */
326
327type *find_minsym_type_and_address (minimal_symbol *msymbol, objfile *objf,
328 CORE_ADDR *address_p);
329
c35384fb 330#endif /* MINSYMS_H */