Commit | Line | Data |
---|---|---|
c35384fb TT |
1 | /* Minimal symbol table definitions for GDB. |
2 | ||
b811d2c2 | 3 | Copyright (C) 2011-2020 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; | |
40 | }; | |
41 | ||
b19686e0 TT |
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. | |
c35384fb | 45 | |
b19686e0 TT |
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 | ||
8dddcb8f TT |
58 | struct msym_bunch; |
59 | ||
873a915e TT |
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 | ||
8dddcb8f TT |
66 | /* Prepare to start collecting minimal symbols. This should be |
67 | called by a symbol reader to initialize the minimal symbol | |
68 | module. */ | |
873a915e | 69 | |
d25e8719 | 70 | explicit minimal_symbol_reader (struct objfile *); |
873a915e TT |
71 | |
72 | ~minimal_symbol_reader (); | |
b19686e0 | 73 | |
873a915e TT |
74 | /* Install the minimal symbols that have been collected into the |
75 | given objfile. */ | |
b19686e0 | 76 | |
d25e8719 | 77 | void install (); |
b19686e0 | 78 | |
8dddcb8f TT |
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 | |
8dddcb8f TT |
91 | COPY_NAME - if true, the minsym code must make a copy of NAME. If |
92 | false, then NAME must be NUL-terminated, and must have a lifetime | |
93 | that is at least as long as OBJFILE's lifetime. | |
94 | ADDRESS - the address of the symbol | |
95 | MS_TYPE - the type of the symbol | |
96 | SECTION - the symbol's section | |
ce6c454e | 97 | */ |
8dddcb8f | 98 | |
31edb802 | 99 | struct minimal_symbol *record_full (gdb::string_view name, |
ce6c454e | 100 | bool copy_name, |
8dddcb8f TT |
101 | CORE_ADDR address, |
102 | enum minimal_symbol_type ms_type, | |
103 | int section); | |
104 | ||
105 | /* Like record_full, but: | |
31edb802 | 106 | - computes the length of NAME |
ce6c454e | 107 | - passes COPY_NAME = true, |
8dddcb8f TT |
108 | - and passes a default SECTION, depending on the type |
109 | ||
110 | This variant does not return the new symbol. */ | |
111 | ||
ce6c454e TT |
112 | void record (const char *name, CORE_ADDR address, |
113 | enum minimal_symbol_type ms_type); | |
8dddcb8f TT |
114 | |
115 | /* Like record_full, but: | |
31edb802 | 116 | - computes the length of NAME |
3db066bc | 117 | - passes COPY_NAME = true. |
8dddcb8f | 118 | |
3db066bc TT |
119 | This variant does not return the new symbol. */ |
120 | ||
121 | void record_with_info (const char *name, CORE_ADDR address, | |
122 | enum minimal_symbol_type ms_type, | |
123 | int section) | |
8dddcb8f | 124 | { |
31edb802 | 125 | record_full (name, true, address, ms_type, section); |
8dddcb8f TT |
126 | } |
127 | ||
873a915e TT |
128 | private: |
129 | ||
af9a2161 | 130 | DISABLE_COPY_AND_ASSIGN (minimal_symbol_reader); |
d25e8719 TT |
131 | |
132 | struct objfile *m_objfile; | |
b19686e0 | 133 | |
8dddcb8f TT |
134 | /* Bunch currently being filled up. |
135 | The next field points to chain of filled bunches. */ | |
136 | ||
137 | struct msym_bunch *m_msym_bunch; | |
138 | ||
139 | /* Number of slots filled in current bunch. */ | |
140 | ||
141 | int m_msym_bunch_index; | |
142 | ||
143 | /* Total number of minimal symbols recorded so far for the | |
144 | objfile. */ | |
145 | ||
146 | int m_msym_count; | |
147 | }; | |
c35384fb | 148 | |
b19686e0 TT |
149 | \f |
150 | ||
4024cf2b PA |
151 | /* Return whether MSYMBOL is a function/method. If FUNC_ADDRESS_P is |
152 | non-NULL, and the MSYMBOL is a function, then *FUNC_ADDRESS_P is | |
153 | set to the function's address, already resolved if MINSYM points to | |
154 | a function descriptor. */ | |
155 | ||
156 | bool msymbol_is_function (struct objfile *objfile, | |
157 | minimal_symbol *minsym, | |
158 | CORE_ADDR *func_address_p = NULL); | |
bf223d3e | 159 | |
c7ee338a CB |
160 | /* Compute a hash code for the string argument. Unlike htab_hash_string, |
161 | this is a case-insensitive hash to support "set case-sensitive off". */ | |
c35384fb TT |
162 | |
163 | unsigned int msymbol_hash (const char *); | |
164 | ||
b19686e0 TT |
165 | /* Like msymbol_hash, but compute a hash code that is compatible with |
166 | strcmp_iw. */ | |
167 | ||
168 | unsigned int msymbol_hash_iw (const char *); | |
169 | ||
c35384fb TT |
170 | /* Compute the next hash value from previous HASH and the character C. This |
171 | is only a GDB in-memory computed value with no external files compatibility | |
172 | requirements. */ | |
173 | ||
174 | #define SYMBOL_HASH_NEXT(hash, c) \ | |
deeeba55 | 175 | ((hash) * 67 + TOLOWER ((unsigned char) (c)) - 113) |
c35384fb | 176 | |
b19686e0 TT |
177 | \f |
178 | ||
b19686e0 TT |
179 | /* Look through all the current minimal symbol tables and find the |
180 | first minimal symbol that matches NAME. If OBJF is non-NULL, limit | |
3b7344d5 TT |
181 | the search to that objfile. If SFILE is non-NULL, the only |
182 | file-scope symbols considered will be from that source file (global | |
183 | symbols are still preferred). Returns a bound minimal symbol that | |
184 | matches, or an empty bound minimal symbol if no match is found. */ | |
b19686e0 | 185 | |
3b7344d5 TT |
186 | struct bound_minimal_symbol lookup_minimal_symbol (const char *, |
187 | const char *, | |
188 | struct objfile *); | |
c35384fb | 189 | |
3b7344d5 TT |
190 | /* Like lookup_minimal_symbol, but searches all files and |
191 | objfiles. */ | |
7c7b6655 TT |
192 | |
193 | struct bound_minimal_symbol lookup_bound_minimal_symbol (const char *); | |
194 | ||
b19686e0 TT |
195 | /* Look through all the current minimal symbol tables and find the |
196 | first minimal symbol that matches NAME and has text type. If OBJF | |
3b7344d5 TT |
197 | is non-NULL, limit the search to that objfile. Returns a bound |
198 | minimal symbol that matches, or an "empty" bound minimal symbol | |
199 | otherwise. | |
b19686e0 TT |
200 | |
201 | This function only searches the mangled (linkage) names. */ | |
202 | ||
3b7344d5 TT |
203 | struct bound_minimal_symbol lookup_minimal_symbol_text (const char *, |
204 | struct objfile *); | |
c35384fb | 205 | |
4b610737 TT |
206 | /* Look through the minimal symbols in OBJF (and its separate debug |
207 | objfiles) for a global (not file-local) minsym whose linkage name | |
208 | is NAME. This is somewhat similar to lookup_minimal_symbol_text, | |
209 | only data symbols (not text symbols) are considered, and a non-NULL | |
210 | objfile is not accepted. Returns a bound minimal symbol that | |
211 | matches, or an "empty" bound minimal symbol otherwise. */ | |
212 | ||
213 | extern struct bound_minimal_symbol lookup_minimal_symbol_linkage | |
214 | (const char *name, struct objfile *objf) | |
215 | ATTRIBUTE_NONNULL (1) ATTRIBUTE_NONNULL (2); | |
216 | ||
b19686e0 TT |
217 | /* Look through all the current minimal symbol tables and find the |
218 | first minimal symbol that matches NAME and PC. If OBJF is non-NULL, | |
219 | limit the search to that objfile. Returns a pointer to the minimal | |
220 | symbol that matches, or NULL if no match is found. */ | |
221 | ||
c35384fb | 222 | struct minimal_symbol *lookup_minimal_symbol_by_pc_name |
b19686e0 | 223 | (CORE_ADDR, const char *, struct objfile *); |
c35384fb | 224 | |
20944a6e PA |
225 | enum class lookup_msym_prefer |
226 | { | |
227 | /* Prefer mst_text symbols. */ | |
228 | TEXT, | |
229 | ||
230 | /* Prefer mst_solib_trampoline symbols when there are text and | |
231 | trampoline symbols at the same address. Otherwise prefer | |
232 | mst_text symbols. */ | |
233 | TRAMPOLINE, | |
234 | ||
235 | /* Prefer mst_text_gnu_ifunc symbols when there are text and ifunc | |
236 | symbols at the same address. Otherwise prefer mst_text | |
237 | symbols. */ | |
238 | GNU_IFUNC, | |
239 | }; | |
240 | ||
b19686e0 TT |
241 | /* Search through the minimal symbol table for each objfile and find |
242 | the symbol whose address is the largest address that is still less | |
243 | than or equal to PC, and which matches SECTION. | |
c35384fb | 244 | |
b19686e0 TT |
245 | If SECTION is NULL, this uses the result of find_pc_section |
246 | instead. | |
247 | ||
7cbd4a93 | 248 | The result has a non-NULL 'minsym' member if such a symbol is |
20944a6e PA |
249 | found, or NULL if PC is not in a suitable range. |
250 | ||
251 | See definition of lookup_msym_prefer for description of PREFER. By | |
252 | default mst_text symbols are preferred. */ | |
c35384fb | 253 | |
7cbd4a93 | 254 | struct bound_minimal_symbol lookup_minimal_symbol_by_pc_section |
20944a6e PA |
255 | (CORE_ADDR, |
256 | struct obj_section *, | |
257 | lookup_msym_prefer prefer = lookup_msym_prefer::TEXT); | |
c35384fb | 258 | |
b19686e0 TT |
259 | /* Backward compatibility: search through the minimal symbol table |
260 | for a matching PC (no section given). | |
261 | ||
262 | This is a wrapper that calls lookup_minimal_symbol_by_pc_section | |
263 | with a NULL section argument. */ | |
c35384fb | 264 | |
7cbd4a93 | 265 | struct bound_minimal_symbol lookup_minimal_symbol_by_pc (CORE_ADDR); |
c35384fb | 266 | |
b19686e0 TT |
267 | /* Iterate over all the minimal symbols in the objfile OBJF which |
268 | match NAME. Both the ordinary and demangled names of each symbol | |
269 | are considered. The caller is responsible for canonicalizing NAME, | |
270 | should that need to be done. | |
c35384fb | 271 | |
41c1efc6 TT |
272 | For each matching symbol, CALLBACK is called with the symbol. */ |
273 | ||
274 | void iterate_over_minimal_symbols | |
275 | (struct objfile *objf, const lookup_name_info &name, | |
ca31ab1d | 276 | gdb::function_view<bool (struct minimal_symbol *)> callback); |
c35384fb | 277 | |
50e65b17 TT |
278 | /* Compute the upper bound of MINSYM. The upper bound is the last |
279 | address thought to be part of the symbol. If the symbol has a | |
280 | size, it is used. Otherwise use the lesser of the next minimal | |
281 | symbol in the same section, or the end of the section, as the end | |
282 | of the function. */ | |
283 | ||
284 | CORE_ADDR minimal_symbol_upper_bound (struct bound_minimal_symbol minsym); | |
285 | ||
74ea4be4 PA |
286 | /* Return the type of MSYMBOL, a minimal symbol of OBJFILE. If |
287 | ADDRESS_P is not NULL, set it to the MSYMBOL's resolved | |
288 | address. */ | |
289 | ||
290 | type *find_minsym_type_and_address (minimal_symbol *msymbol, objfile *objf, | |
291 | CORE_ADDR *address_p); | |
292 | ||
c35384fb | 293 | #endif /* MINSYMS_H */ |