Commit | Line | Data |
---|---|---|
c35384fb TT |
1 | /* Minimal symbol table definitions for GDB. |
2 | ||
3666a048 | 3 | Copyright (C) 2011-2021 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 |
23 | struct 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 | ||
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; | |
1db66e34 AB |
40 | |
41 | /* Return the obj_section from OBJFILE for MINSYM. */ | |
42 | ||
43 | struct obj_section *obj_section () const | |
44 | { | |
45 | return minsym->obj_section (objfile); | |
46 | } | |
7cbd4a93 TT |
47 | }; |
48 | ||
b19686e0 TT |
49 | /* This header declares most of the API for dealing with minimal |
50 | symbols and minimal symbol tables. A few things are declared | |
51 | elsewhere; see below. | |
c35384fb | 52 | |
b19686e0 TT |
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. | |
56 | ||
57 | For the definition of the minimal symbol structure, see struct | |
58 | minimal_symbol in symtab.h. | |
59 | ||
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. | |
63 | */ | |
64 | ||
8dddcb8f TT |
65 | struct msym_bunch; |
66 | ||
873a915e TT |
67 | /* An RAII-based object that is used to record minimal symbols while |
68 | they are being read. */ | |
69 | class minimal_symbol_reader | |
70 | { | |
71 | public: | |
72 | ||
8dddcb8f TT |
73 | /* Prepare to start collecting minimal symbols. This should be |
74 | called by a symbol reader to initialize the minimal symbol | |
75 | module. */ | |
873a915e | 76 | |
d25e8719 | 77 | explicit minimal_symbol_reader (struct objfile *); |
873a915e TT |
78 | |
79 | ~minimal_symbol_reader (); | |
b19686e0 | 80 | |
873a915e TT |
81 | /* Install the minimal symbols that have been collected into the |
82 | given objfile. */ | |
b19686e0 | 83 | |
d25e8719 | 84 | void install (); |
b19686e0 | 85 | |
8dddcb8f TT |
86 | /* Record a new minimal symbol. This is the "full" entry point; |
87 | simpler convenience entry points are also provided below. | |
88 | ||
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. | |
94 | ||
95 | Arguments are: | |
96 | ||
97 | NAME - the symbol's name | |
8dddcb8f TT |
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 | |
ce6c454e | 104 | */ |
8dddcb8f | 105 | |
31edb802 | 106 | struct minimal_symbol *record_full (gdb::string_view name, |
ce6c454e | 107 | bool copy_name, |
8dddcb8f TT |
108 | CORE_ADDR address, |
109 | enum minimal_symbol_type ms_type, | |
110 | int section); | |
111 | ||
112 | /* Like record_full, but: | |
31edb802 | 113 | - computes the length of NAME |
ce6c454e | 114 | - passes COPY_NAME = true, |
8dddcb8f TT |
115 | - and passes a default SECTION, depending on the type |
116 | ||
117 | This variant does not return the new symbol. */ | |
118 | ||
ce6c454e TT |
119 | void record (const char *name, CORE_ADDR address, |
120 | enum minimal_symbol_type ms_type); | |
8dddcb8f TT |
121 | |
122 | /* Like record_full, but: | |
31edb802 | 123 | - computes the length of NAME |
3db066bc | 124 | - passes COPY_NAME = true. |
8dddcb8f | 125 | |
3db066bc TT |
126 | This variant does not return the new symbol. */ |
127 | ||
128 | void record_with_info (const char *name, CORE_ADDR address, | |
129 | enum minimal_symbol_type ms_type, | |
130 | int section) | |
8dddcb8f | 131 | { |
31edb802 | 132 | record_full (name, true, address, ms_type, section); |
8dddcb8f TT |
133 | } |
134 | ||
873a915e TT |
135 | private: |
136 | ||
af9a2161 | 137 | DISABLE_COPY_AND_ASSIGN (minimal_symbol_reader); |
d25e8719 TT |
138 | |
139 | struct objfile *m_objfile; | |
b19686e0 | 140 | |
8dddcb8f TT |
141 | /* Bunch currently being filled up. |
142 | The next field points to chain of filled bunches. */ | |
143 | ||
144 | struct msym_bunch *m_msym_bunch; | |
145 | ||
146 | /* Number of slots filled in current bunch. */ | |
147 | ||
148 | int m_msym_bunch_index; | |
149 | ||
150 | /* Total number of minimal symbols recorded so far for the | |
151 | objfile. */ | |
152 | ||
153 | int m_msym_count; | |
154 | }; | |
c35384fb | 155 | |
b19686e0 TT |
156 | \f |
157 | ||
4024cf2b PA |
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. */ | |
162 | ||
163 | bool msymbol_is_function (struct objfile *objfile, | |
164 | minimal_symbol *minsym, | |
165 | CORE_ADDR *func_address_p = NULL); | |
bf223d3e | 166 | |
c7ee338a CB |
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". */ | |
c35384fb TT |
169 | |
170 | unsigned int msymbol_hash (const char *); | |
171 | ||
b19686e0 TT |
172 | /* Like msymbol_hash, but compute a hash code that is compatible with |
173 | strcmp_iw. */ | |
174 | ||
175 | unsigned int msymbol_hash_iw (const char *); | |
176 | ||
c35384fb TT |
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 | |
179 | requirements. */ | |
180 | ||
181 | #define SYMBOL_HASH_NEXT(hash, c) \ | |
deeeba55 | 182 | ((hash) * 67 + TOLOWER ((unsigned char) (c)) - 113) |
c35384fb | 183 | |
b19686e0 TT |
184 | \f |
185 | ||
b19686e0 TT |
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 | |
3b7344d5 TT |
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. */ | |
b19686e0 | 192 | |
3b7344d5 TT |
193 | struct bound_minimal_symbol lookup_minimal_symbol (const char *, |
194 | const char *, | |
195 | struct objfile *); | |
c35384fb | 196 | |
3b7344d5 TT |
197 | /* Like lookup_minimal_symbol, but searches all files and |
198 | objfiles. */ | |
7c7b6655 TT |
199 | |
200 | struct bound_minimal_symbol lookup_bound_minimal_symbol (const char *); | |
201 | ||
b19686e0 TT |
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 | |
3b7344d5 TT |
204 | is non-NULL, limit the search to that objfile. Returns a bound |
205 | minimal symbol that matches, or an "empty" bound minimal symbol | |
206 | otherwise. | |
b19686e0 TT |
207 | |
208 | This function only searches the mangled (linkage) names. */ | |
209 | ||
3b7344d5 TT |
210 | struct bound_minimal_symbol lookup_minimal_symbol_text (const char *, |
211 | struct objfile *); | |
c35384fb | 212 | |
4b610737 TT |
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. */ | |
219 | ||
220 | extern struct bound_minimal_symbol lookup_minimal_symbol_linkage | |
221 | (const char *name, struct objfile *objf) | |
222 | ATTRIBUTE_NONNULL (1) ATTRIBUTE_NONNULL (2); | |
223 | ||
b19686e0 TT |
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. */ | |
228 | ||
c35384fb | 229 | struct minimal_symbol *lookup_minimal_symbol_by_pc_name |
b19686e0 | 230 | (CORE_ADDR, const char *, struct objfile *); |
c35384fb | 231 | |
20944a6e PA |
232 | enum class lookup_msym_prefer |
233 | { | |
234 | /* Prefer mst_text symbols. */ | |
235 | TEXT, | |
236 | ||
237 | /* Prefer mst_solib_trampoline symbols when there are text and | |
238 | trampoline symbols at the same address. Otherwise prefer | |
239 | mst_text symbols. */ | |
240 | TRAMPOLINE, | |
241 | ||
242 | /* Prefer mst_text_gnu_ifunc symbols when there are text and ifunc | |
243 | symbols at the same address. Otherwise prefer mst_text | |
244 | symbols. */ | |
245 | GNU_IFUNC, | |
246 | }; | |
247 | ||
b19686e0 TT |
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 | |
733d0a67 AB |
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. | |
c35384fb | 253 | |
b19686e0 TT |
254 | If SECTION is NULL, this uses the result of find_pc_section |
255 | instead. | |
256 | ||
7cbd4a93 | 257 | The result has a non-NULL 'minsym' member if such a symbol is |
20944a6e PA |
258 | found, or NULL if PC is not in a suitable range. |
259 | ||
260 | See definition of lookup_msym_prefer for description of PREFER. By | |
733d0a67 AB |
261 | default mst_text symbols are preferred. |
262 | ||
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 | |
265 | PC_IN. */ | |
c35384fb | 266 | |
7cbd4a93 | 267 | struct bound_minimal_symbol lookup_minimal_symbol_by_pc_section |
733d0a67 AB |
268 | (CORE_ADDR pc_in, |
269 | struct obj_section *section, | |
270 | lookup_msym_prefer prefer = lookup_msym_prefer::TEXT, | |
271 | bound_minimal_symbol *previous = nullptr); | |
c35384fb | 272 | |
b19686e0 TT |
273 | /* Backward compatibility: search through the minimal symbol table |
274 | for a matching PC (no section given). | |
275 | ||
276 | This is a wrapper that calls lookup_minimal_symbol_by_pc_section | |
277 | with a NULL section argument. */ | |
c35384fb | 278 | |
7cbd4a93 | 279 | struct bound_minimal_symbol lookup_minimal_symbol_by_pc (CORE_ADDR); |
c35384fb | 280 | |
b19686e0 TT |
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. | |
c35384fb | 285 | |
41c1efc6 TT |
286 | For each matching symbol, CALLBACK is called with the symbol. */ |
287 | ||
288 | void iterate_over_minimal_symbols | |
289 | (struct objfile *objf, const lookup_name_info &name, | |
ca31ab1d | 290 | gdb::function_view<bool (struct minimal_symbol *)> callback); |
c35384fb | 291 | |
50e65b17 TT |
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 | |
296 | of the function. */ | |
297 | ||
298 | CORE_ADDR minimal_symbol_upper_bound (struct bound_minimal_symbol minsym); | |
299 | ||
74ea4be4 PA |
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 | |
302 | address. */ | |
303 | ||
304 | type *find_minsym_type_and_address (minimal_symbol *msymbol, objfile *objf, | |
305 | CORE_ADDR *address_p); | |
306 | ||
c35384fb | 307 | #endif /* MINSYMS_H */ |