Commit | Line | Data |
---|---|---|
c35384fb TT |
1 | /* Minimal symbol table definitions for GDB. |
2 | ||
618f726f | 3 | Copyright (C) 2011-2016 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 | ||
7cbd4a93 TT |
23 | /* Several lookup functions return both a minimal symbol and the |
24 | objfile in which it is found. This structure is used in these | |
25 | cases. */ | |
26 | ||
27 | struct bound_minimal_symbol | |
28 | { | |
29 | /* The minimal symbol that was found, or NULL if no minimal symbol | |
30 | was found. */ | |
31 | ||
32 | struct minimal_symbol *minsym; | |
33 | ||
34 | /* If MINSYM is not NULL, then this is the objfile in which the | |
35 | symbol is defined. */ | |
36 | ||
37 | struct objfile *objfile; | |
38 | }; | |
39 | ||
b19686e0 TT |
40 | /* This header declares most of the API for dealing with minimal |
41 | symbols and minimal symbol tables. A few things are declared | |
42 | elsewhere; see below. | |
c35384fb | 43 | |
b19686e0 TT |
44 | A minimal symbol is a symbol for which there is no direct debug |
45 | information. For example, for an ELF binary, minimal symbols are | |
46 | created from the ELF symbol table. | |
47 | ||
48 | For the definition of the minimal symbol structure, see struct | |
49 | minimal_symbol in symtab.h. | |
50 | ||
51 | Minimal symbols are stored in tables attached to an objfile; see | |
52 | objfiles.h for details. Code should generally treat these tables | |
53 | as opaque and use functions provided by minsyms.c to inspect them. | |
54 | */ | |
55 | ||
8dddcb8f TT |
56 | struct msym_bunch; |
57 | ||
873a915e TT |
58 | /* An RAII-based object that is used to record minimal symbols while |
59 | they are being read. */ | |
60 | class minimal_symbol_reader | |
61 | { | |
62 | public: | |
63 | ||
8dddcb8f TT |
64 | /* Prepare to start collecting minimal symbols. This should be |
65 | called by a symbol reader to initialize the minimal symbol | |
66 | module. */ | |
873a915e | 67 | |
d25e8719 | 68 | explicit minimal_symbol_reader (struct objfile *); |
873a915e TT |
69 | |
70 | ~minimal_symbol_reader (); | |
b19686e0 | 71 | |
873a915e TT |
72 | /* Install the minimal symbols that have been collected into the |
73 | given objfile. */ | |
b19686e0 | 74 | |
d25e8719 | 75 | void install (); |
b19686e0 | 76 | |
8dddcb8f TT |
77 | /* Record a new minimal symbol. This is the "full" entry point; |
78 | simpler convenience entry points are also provided below. | |
79 | ||
80 | This returns a new minimal symbol. It is ok to modify the returned | |
81 | minimal symbol (though generally not necessary). It is not ok, | |
82 | though, to stash the pointer anywhere; as minimal symbols may be | |
83 | moved after creation. The memory for the returned minimal symbol | |
84 | is still owned by the minsyms.c code, and should not be freed. | |
85 | ||
86 | Arguments are: | |
87 | ||
88 | NAME - the symbol's name | |
89 | NAME_LEN - the length of the name | |
90 | COPY_NAME - if true, the minsym code must make a copy of NAME. If | |
91 | false, then NAME must be NUL-terminated, and must have a lifetime | |
92 | that is at least as long as OBJFILE's lifetime. | |
93 | ADDRESS - the address of the symbol | |
94 | MS_TYPE - the type of the symbol | |
95 | SECTION - the symbol's section | |
ce6c454e | 96 | */ |
8dddcb8f TT |
97 | |
98 | struct minimal_symbol *record_full (const char *name, | |
99 | int name_len, | |
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: | |
106 | - uses strlen to compute NAME_LEN, | |
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: | |
116 | - uses strlen to compute NAME_LEN, | |
ce6c454e | 117 | - passes COPY_NAME = true. */ |
8dddcb8f TT |
118 | |
119 | struct minimal_symbol *record_with_info (const char *name, | |
120 | CORE_ADDR address, | |
121 | enum minimal_symbol_type ms_type, | |
122 | int section) | |
123 | { | |
ce6c454e | 124 | return record_full (name, strlen (name), true, address, ms_type, section); |
8dddcb8f TT |
125 | } |
126 | ||
873a915e TT |
127 | private: |
128 | ||
129 | /* No need for these. They are intentionally not defined anywhere. */ | |
130 | minimal_symbol_reader &operator= | |
131 | (const minimal_symbol_reader &); | |
132 | minimal_symbol_reader (const minimal_symbol_reader &); | |
d25e8719 TT |
133 | |
134 | struct objfile *m_objfile; | |
b19686e0 | 135 | |
8dddcb8f TT |
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 | }; | |
c35384fb | 150 | |
b19686e0 TT |
151 | /* Create the terminating entry of OBJFILE's minimal symbol table. |
152 | If OBJFILE->msymbols is zero, allocate a single entry from | |
153 | OBJFILE->objfile_obstack; otherwise, just initialize | |
154 | OBJFILE->msymbols[OBJFILE->minimal_symbol_count]. */ | |
155 | ||
156 | void terminate_minimal_symbol_table (struct objfile *objfile); | |
157 | ||
b19686e0 TT |
158 | \f |
159 | ||
160 | /* Compute a hash code for the string argument. */ | |
c35384fb TT |
161 | |
162 | unsigned int msymbol_hash (const char *); | |
163 | ||
b19686e0 TT |
164 | /* Like msymbol_hash, but compute a hash code that is compatible with |
165 | strcmp_iw. */ | |
166 | ||
167 | unsigned int msymbol_hash_iw (const char *); | |
168 | ||
c35384fb TT |
169 | /* Compute the next hash value from previous HASH and the character C. This |
170 | is only a GDB in-memory computed value with no external files compatibility | |
171 | requirements. */ | |
172 | ||
173 | #define SYMBOL_HASH_NEXT(hash, c) \ | |
174 | ((hash) * 67 + tolower ((unsigned char) (c)) - 113) | |
175 | ||
b19686e0 TT |
176 | \f |
177 | ||
b19686e0 TT |
178 | /* Look through all the current minimal symbol tables and find the |
179 | first minimal symbol that matches NAME. If OBJF is non-NULL, limit | |
3b7344d5 TT |
180 | the search to that objfile. If SFILE is non-NULL, the only |
181 | file-scope symbols considered will be from that source file (global | |
182 | symbols are still preferred). Returns a bound minimal symbol that | |
183 | matches, or an empty bound minimal symbol if no match is found. */ | |
b19686e0 | 184 | |
3b7344d5 TT |
185 | struct bound_minimal_symbol lookup_minimal_symbol (const char *, |
186 | const char *, | |
187 | struct objfile *); | |
c35384fb | 188 | |
3b7344d5 TT |
189 | /* Like lookup_minimal_symbol, but searches all files and |
190 | objfiles. */ | |
7c7b6655 TT |
191 | |
192 | struct bound_minimal_symbol lookup_bound_minimal_symbol (const char *); | |
193 | ||
b19686e0 | 194 | /* Find the minimal symbol named NAME, and return both the minsym |
7cbd4a93 | 195 | struct and its objfile. This only checks the linkage name. */ |
b19686e0 | 196 | |
7cbd4a93 | 197 | struct bound_minimal_symbol lookup_minimal_symbol_and_objfile (const char *); |
b19686e0 TT |
198 | |
199 | /* Look through all the current minimal symbol tables and find the | |
200 | first minimal symbol that matches NAME and has text type. If OBJF | |
3b7344d5 TT |
201 | is non-NULL, limit the search to that objfile. Returns a bound |
202 | minimal symbol that matches, or an "empty" bound minimal symbol | |
203 | otherwise. | |
b19686e0 TT |
204 | |
205 | This function only searches the mangled (linkage) names. */ | |
206 | ||
3b7344d5 TT |
207 | struct bound_minimal_symbol lookup_minimal_symbol_text (const char *, |
208 | struct objfile *); | |
c35384fb | 209 | |
b19686e0 TT |
210 | /* Look through all the current minimal symbol tables and find the |
211 | first minimal symbol that matches NAME and is a solib trampoline. | |
212 | If OBJF is non-NULL, limit the search to that objfile. Returns a | |
213 | pointer to the minimal symbol that matches, or NULL if no match is | |
214 | found. | |
215 | ||
216 | This function only searches the mangled (linkage) names. */ | |
217 | ||
3b7344d5 | 218 | struct bound_minimal_symbol lookup_minimal_symbol_solib_trampoline |
c35384fb TT |
219 | (const char *, |
220 | struct objfile *); | |
221 | ||
b19686e0 TT |
222 | /* Look through all the current minimal symbol tables and find the |
223 | first minimal symbol that matches NAME and PC. If OBJF is non-NULL, | |
224 | limit the search to that objfile. Returns a pointer to the minimal | |
225 | symbol that matches, or NULL if no match is found. */ | |
226 | ||
c35384fb | 227 | struct minimal_symbol *lookup_minimal_symbol_by_pc_name |
b19686e0 | 228 | (CORE_ADDR, const char *, struct objfile *); |
c35384fb | 229 | |
b19686e0 TT |
230 | /* Search through the minimal symbol table for each objfile and find |
231 | the symbol whose address is the largest address that is still less | |
232 | than or equal to PC, and which matches SECTION. | |
c35384fb | 233 | |
b19686e0 TT |
234 | If SECTION is NULL, this uses the result of find_pc_section |
235 | instead. | |
236 | ||
7cbd4a93 TT |
237 | The result has a non-NULL 'minsym' member if such a symbol is |
238 | found, or NULL if PC is not in a suitable range. */ | |
c35384fb | 239 | |
7cbd4a93 | 240 | struct bound_minimal_symbol lookup_minimal_symbol_by_pc_section |
c35384fb TT |
241 | (CORE_ADDR, |
242 | struct obj_section *); | |
243 | ||
b19686e0 TT |
244 | /* Backward compatibility: search through the minimal symbol table |
245 | for a matching PC (no section given). | |
246 | ||
247 | This is a wrapper that calls lookup_minimal_symbol_by_pc_section | |
248 | with a NULL section argument. */ | |
c35384fb | 249 | |
7cbd4a93 | 250 | struct bound_minimal_symbol lookup_minimal_symbol_by_pc (CORE_ADDR); |
c35384fb | 251 | |
b19686e0 TT |
252 | /* Iterate over all the minimal symbols in the objfile OBJF which |
253 | match NAME. Both the ordinary and demangled names of each symbol | |
254 | are considered. The caller is responsible for canonicalizing NAME, | |
255 | should that need to be done. | |
c35384fb | 256 | |
b19686e0 TT |
257 | For each matching symbol, CALLBACK is called with the symbol and |
258 | USER_DATA as arguments. */ | |
c35384fb TT |
259 | |
260 | void iterate_over_minimal_symbols (struct objfile *objf, | |
261 | const char *name, | |
262 | void (*callback) (struct minimal_symbol *, | |
263 | void *), | |
264 | void *user_data); | |
265 | ||
50e65b17 TT |
266 | /* Compute the upper bound of MINSYM. The upper bound is the last |
267 | address thought to be part of the symbol. If the symbol has a | |
268 | size, it is used. Otherwise use the lesser of the next minimal | |
269 | symbol in the same section, or the end of the section, as the end | |
270 | of the function. */ | |
271 | ||
272 | CORE_ADDR minimal_symbol_upper_bound (struct bound_minimal_symbol minsym); | |
273 | ||
c35384fb | 274 | #endif /* MINSYMS_H */ |