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 | ||
873a915e TT |
56 | /* An RAII-based object that is used to record minimal symbols while |
57 | they are being read. */ | |
58 | class minimal_symbol_reader | |
59 | { | |
60 | public: | |
61 | ||
62 | /* Prepare to start collecting minimal symbols. This should be called | |
63 | by a symbol reader to initialize the minimal symbol module. | |
64 | Currently, minimal symbol table creation is not reentrant; it | |
65 | relies on global (static) variables in minsyms.c. */ | |
66 | ||
d25e8719 | 67 | explicit minimal_symbol_reader (struct objfile *); |
873a915e TT |
68 | |
69 | ~minimal_symbol_reader (); | |
b19686e0 | 70 | |
873a915e TT |
71 | /* Install the minimal symbols that have been collected into the |
72 | given objfile. */ | |
b19686e0 | 73 | |
d25e8719 | 74 | void install (); |
b19686e0 | 75 | |
873a915e TT |
76 | private: |
77 | ||
78 | /* No need for these. They are intentionally not defined anywhere. */ | |
79 | minimal_symbol_reader &operator= | |
80 | (const minimal_symbol_reader &); | |
81 | minimal_symbol_reader (const minimal_symbol_reader &); | |
d25e8719 TT |
82 | |
83 | struct objfile *m_objfile; | |
873a915e | 84 | }; |
b19686e0 TT |
85 | |
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 | |
98 | NAME_LEN - the length of the name | |
99 | COPY_NAME - if true, the minsym code must make a copy of NAME. If | |
100 | false, then NAME must be NUL-terminated, and must have a lifetime | |
101 | that is at least as long as OBJFILE's lifetime. | |
102 | ADDRESS - the address of the symbol | |
103 | MS_TYPE - the type of the symbol | |
104 | SECTION - the symbol's section | |
b19686e0 TT |
105 | appropriate obj_section for the minimal symbol. This can be NULL. |
106 | OBJFILE - the objfile associated with the minimal symbol. */ | |
c35384fb TT |
107 | |
108 | struct minimal_symbol *prim_record_minimal_symbol_full | |
b19686e0 TT |
109 | (const char *name, |
110 | int name_len, | |
111 | int copy_name, | |
112 | CORE_ADDR address, | |
113 | enum minimal_symbol_type ms_type, | |
c35384fb | 114 | int section, |
b19686e0 TT |
115 | struct objfile *objfile); |
116 | ||
117 | /* Like prim_record_minimal_symbol_full, but: | |
118 | - uses strlen to compute NAME_LEN, | |
99f4262f | 119 | - passes COPY_NAME = 1, |
e6dc44a8 | 120 | - and passes a default SECTION, depending on the type |
b19686e0 TT |
121 | |
122 | This variant does not return the new symbol. */ | |
123 | ||
124 | void prim_record_minimal_symbol (const char *, CORE_ADDR, | |
125 | enum minimal_symbol_type, | |
126 | struct objfile *); | |
127 | ||
128 | /* Like prim_record_minimal_symbol_full, but: | |
129 | - uses strlen to compute NAME_LEN, | |
99f4262f | 130 | - passes COPY_NAME = 1. */ |
c35384fb TT |
131 | |
132 | struct minimal_symbol *prim_record_minimal_symbol_and_info | |
133 | (const char *, | |
134 | CORE_ADDR, | |
135 | enum minimal_symbol_type, | |
136 | int section, | |
c35384fb TT |
137 | struct objfile *); |
138 | ||
b19686e0 TT |
139 | /* Create the terminating entry of OBJFILE's minimal symbol table. |
140 | If OBJFILE->msymbols is zero, allocate a single entry from | |
141 | OBJFILE->objfile_obstack; otherwise, just initialize | |
142 | OBJFILE->msymbols[OBJFILE->minimal_symbol_count]. */ | |
143 | ||
144 | void terminate_minimal_symbol_table (struct objfile *objfile); | |
145 | ||
b19686e0 TT |
146 | \f |
147 | ||
148 | /* Compute a hash code for the string argument. */ | |
c35384fb TT |
149 | |
150 | unsigned int msymbol_hash (const char *); | |
151 | ||
b19686e0 TT |
152 | /* Like msymbol_hash, but compute a hash code that is compatible with |
153 | strcmp_iw. */ | |
154 | ||
155 | unsigned int msymbol_hash_iw (const char *); | |
156 | ||
c35384fb TT |
157 | /* Compute the next hash value from previous HASH and the character C. This |
158 | is only a GDB in-memory computed value with no external files compatibility | |
159 | requirements. */ | |
160 | ||
161 | #define SYMBOL_HASH_NEXT(hash, c) \ | |
162 | ((hash) * 67 + tolower ((unsigned char) (c)) - 113) | |
163 | ||
b19686e0 TT |
164 | \f |
165 | ||
b19686e0 TT |
166 | /* Look through all the current minimal symbol tables and find the |
167 | first minimal symbol that matches NAME. If OBJF is non-NULL, limit | |
3b7344d5 TT |
168 | the search to that objfile. If SFILE is non-NULL, the only |
169 | file-scope symbols considered will be from that source file (global | |
170 | symbols are still preferred). Returns a bound minimal symbol that | |
171 | matches, or an empty bound minimal symbol if no match is found. */ | |
b19686e0 | 172 | |
3b7344d5 TT |
173 | struct bound_minimal_symbol lookup_minimal_symbol (const char *, |
174 | const char *, | |
175 | struct objfile *); | |
c35384fb | 176 | |
3b7344d5 TT |
177 | /* Like lookup_minimal_symbol, but searches all files and |
178 | objfiles. */ | |
7c7b6655 TT |
179 | |
180 | struct bound_minimal_symbol lookup_bound_minimal_symbol (const char *); | |
181 | ||
b19686e0 | 182 | /* Find the minimal symbol named NAME, and return both the minsym |
7cbd4a93 | 183 | struct and its objfile. This only checks the linkage name. */ |
b19686e0 | 184 | |
7cbd4a93 | 185 | struct bound_minimal_symbol lookup_minimal_symbol_and_objfile (const char *); |
b19686e0 TT |
186 | |
187 | /* Look through all the current minimal symbol tables and find the | |
188 | first minimal symbol that matches NAME and has text type. If OBJF | |
3b7344d5 TT |
189 | is non-NULL, limit the search to that objfile. Returns a bound |
190 | minimal symbol that matches, or an "empty" bound minimal symbol | |
191 | otherwise. | |
b19686e0 TT |
192 | |
193 | This function only searches the mangled (linkage) names. */ | |
194 | ||
3b7344d5 TT |
195 | struct bound_minimal_symbol lookup_minimal_symbol_text (const char *, |
196 | struct objfile *); | |
c35384fb | 197 | |
b19686e0 TT |
198 | /* Look through all the current minimal symbol tables and find the |
199 | first minimal symbol that matches NAME and is a solib trampoline. | |
200 | If OBJF is non-NULL, limit the search to that objfile. Returns a | |
201 | pointer to the minimal symbol that matches, or NULL if no match is | |
202 | found. | |
203 | ||
204 | This function only searches the mangled (linkage) names. */ | |
205 | ||
3b7344d5 | 206 | struct bound_minimal_symbol lookup_minimal_symbol_solib_trampoline |
c35384fb TT |
207 | (const char *, |
208 | struct objfile *); | |
209 | ||
b19686e0 TT |
210 | /* Look through all the current minimal symbol tables and find the |
211 | first minimal symbol that matches NAME and PC. If OBJF is non-NULL, | |
212 | limit the search to that objfile. Returns a pointer to the minimal | |
213 | symbol that matches, or NULL if no match is found. */ | |
214 | ||
c35384fb | 215 | struct minimal_symbol *lookup_minimal_symbol_by_pc_name |
b19686e0 | 216 | (CORE_ADDR, const char *, struct objfile *); |
c35384fb | 217 | |
b19686e0 TT |
218 | /* Search through the minimal symbol table for each objfile and find |
219 | the symbol whose address is the largest address that is still less | |
220 | than or equal to PC, and which matches SECTION. | |
c35384fb | 221 | |
b19686e0 TT |
222 | If SECTION is NULL, this uses the result of find_pc_section |
223 | instead. | |
224 | ||
7cbd4a93 TT |
225 | The result has a non-NULL 'minsym' member if such a symbol is |
226 | found, or NULL if PC is not in a suitable range. */ | |
c35384fb | 227 | |
7cbd4a93 | 228 | struct bound_minimal_symbol lookup_minimal_symbol_by_pc_section |
c35384fb TT |
229 | (CORE_ADDR, |
230 | struct obj_section *); | |
231 | ||
b19686e0 TT |
232 | /* Backward compatibility: search through the minimal symbol table |
233 | for a matching PC (no section given). | |
234 | ||
235 | This is a wrapper that calls lookup_minimal_symbol_by_pc_section | |
236 | with a NULL section argument. */ | |
c35384fb | 237 | |
7cbd4a93 | 238 | struct bound_minimal_symbol lookup_minimal_symbol_by_pc (CORE_ADDR); |
c35384fb | 239 | |
b19686e0 TT |
240 | /* Iterate over all the minimal symbols in the objfile OBJF which |
241 | match NAME. Both the ordinary and demangled names of each symbol | |
242 | are considered. The caller is responsible for canonicalizing NAME, | |
243 | should that need to be done. | |
c35384fb | 244 | |
b19686e0 TT |
245 | For each matching symbol, CALLBACK is called with the symbol and |
246 | USER_DATA as arguments. */ | |
c35384fb TT |
247 | |
248 | void iterate_over_minimal_symbols (struct objfile *objf, | |
249 | const char *name, | |
250 | void (*callback) (struct minimal_symbol *, | |
251 | void *), | |
252 | void *user_data); | |
253 | ||
50e65b17 TT |
254 | /* Compute the upper bound of MINSYM. The upper bound is the last |
255 | address thought to be part of the symbol. If the symbol has a | |
256 | size, it is used. Otherwise use the lesser of the next minimal | |
257 | symbol in the same section, or the end of the section, as the end | |
258 | of the function. */ | |
259 | ||
260 | CORE_ADDR minimal_symbol_upper_bound (struct bound_minimal_symbol minsym); | |
261 | ||
c35384fb | 262 | #endif /* MINSYMS_H */ |