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