]>
Commit | Line | Data |
---|---|---|
ccefe4c4 | 1 | /* Partial symbol tables. |
95cf5869 | 2 | |
3666a048 | 3 | Copyright (C) 2009-2021 Free Software Foundation, Inc. |
ccefe4c4 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 | #include "defs.h" | |
21 | #include "symtab.h" | |
ccefe4c4 | 22 | #include "objfiles.h" |
b22a7c6a | 23 | #include "psympriv.h" |
ccefe4c4 TT |
24 | #include "block.h" |
25 | #include "filenames.h" | |
26 | #include "source.h" | |
27 | #include "addrmap.h" | |
28 | #include "gdbtypes.h" | |
ccefe4c4 TT |
29 | #include "ui-out.h" |
30 | #include "command.h" | |
e0eac551 | 31 | #include "readline/tilde.h" |
ccefe4c4 | 32 | #include "gdb_regex.h" |
40658b94 | 33 | #include "dictionary.h" |
c00f8484 KS |
34 | #include "language.h" |
35 | #include "cp-support.h" | |
dfc7bb5b | 36 | #include "gdbcmd.h" |
af5bf4ad | 37 | #include <algorithm> |
71a3c369 | 38 | #include <set> |
ccefe4c4 | 39 | |
5c80ed9d TT |
40 | static struct partial_symbol *lookup_partial_symbol (struct objfile *, |
41 | struct partial_symtab *, | |
8c072cb6 TT |
42 | const lookup_name_info &, |
43 | int, | |
ccefe4c4 TT |
44 | domain_enum); |
45 | ||
da5132d3 | 46 | static const char *psymtab_to_fullname (struct partial_symtab *ps); |
ccefe4c4 | 47 | |
5c80ed9d TT |
48 | static struct partial_symbol *find_pc_sect_psymbol (struct objfile *, |
49 | struct partial_symtab *, | |
ccefe4c4 TT |
50 | CORE_ADDR, |
51 | struct obj_section *); | |
52 | ||
43f3e411 DE |
53 | static struct compunit_symtab *psymtab_to_symtab (struct objfile *objfile, |
54 | struct partial_symtab *pst); | |
ccefe4c4 | 55 | |
d320c2b5 TT |
56 | psymtab_storage::~psymtab_storage () |
57 | { | |
6f17252b TT |
58 | partial_symtab *iter = psymtabs; |
59 | while (iter != nullptr) | |
60 | { | |
61 | partial_symtab *next = iter->next; | |
62 | delete iter; | |
63 | iter = next; | |
64 | } | |
d320c2b5 TT |
65 | } |
66 | ||
b596a3c7 TT |
67 | /* See psymtab.h. */ |
68 | ||
abaa2f23 TT |
69 | void |
70 | psymtab_storage::install_psymtab (partial_symtab *pst) | |
b596a3c7 | 71 | { |
abaa2f23 TT |
72 | pst->next = psymtabs; |
73 | psymtabs = pst; | |
b596a3c7 TT |
74 | } |
75 | ||
d320c2b5 TT |
76 | \f |
77 | ||
b22a7c6a | 78 | /* See psymtab.h. */ |
b11896a5 | 79 | |
f252c6d5 | 80 | psymtab_storage::partial_symtab_range |
26abc753 | 81 | require_partial_symbols (struct objfile *objfile, bool verbose) |
b11896a5 TT |
82 | { |
83 | if ((objfile->flags & OBJF_PSYMTABS_READ) == 0) | |
84 | { | |
85 | objfile->flags |= OBJF_PSYMTABS_READ; | |
86 | ||
5c3f1e5b TT |
87 | if (objfile->sf != nullptr |
88 | && objfile->sf->sym_read_psymbols) | |
b11896a5 TT |
89 | { |
90 | if (verbose) | |
3453e7e4 TT |
91 | printf_filtered (_("Reading symbols from %s...\n"), |
92 | objfile_name (objfile)); | |
b11896a5 | 93 | (*objfile->sf->sym_read_psymbols) (objfile); |
af5bf4ad | 94 | |
3453e7e4 TT |
95 | if (verbose && !objfile_has_symbols (objfile)) |
96 | printf_filtered (_("(No debugging symbols found in %s)\n"), | |
97 | objfile_name (objfile)); | |
b11896a5 TT |
98 | } |
99 | } | |
100 | ||
f252c6d5 | 101 | return objfile->psymtabs (); |
b11896a5 TT |
102 | } |
103 | ||
83827540 | 104 | /* Helper function for psym_map_symtabs_matching_filename that |
f8eba3c6 | 105 | expands the symtabs and calls the iterator. */ |
ccefe4c4 | 106 | |
14bc53a8 | 107 | static bool |
f8eba3c6 TT |
108 | partial_map_expand_apply (struct objfile *objfile, |
109 | const char *name, | |
f8eba3c6 TT |
110 | const char *real_path, |
111 | struct partial_symtab *pst, | |
14bc53a8 | 112 | gdb::function_view<bool (symtab *)> callback) |
f8eba3c6 | 113 | { |
43f3e411 | 114 | struct compunit_symtab *last_made = objfile->compunit_symtabs; |
f8eba3c6 | 115 | |
9439a077 TT |
116 | /* Shared psymtabs should never be seen here. Instead they should |
117 | be handled properly by the caller. */ | |
118 | gdb_assert (pst->user == NULL); | |
119 | ||
f8eba3c6 | 120 | /* Don't visit already-expanded psymtabs. */ |
5717c425 | 121 | if (pst->readin_p (objfile)) |
f8eba3c6 TT |
122 | return 0; |
123 | ||
124 | /* This may expand more than one symtab, and we want to iterate over | |
125 | all of them. */ | |
5c80ed9d | 126 | psymtab_to_symtab (objfile, pst); |
f8eba3c6 | 127 | |
14bc53a8 PA |
128 | return iterate_over_some_symtabs (name, real_path, objfile->compunit_symtabs, |
129 | last_made, callback); | |
f8eba3c6 TT |
130 | } |
131 | ||
83827540 DE |
132 | /* Psymtab version of map_symtabs_matching_filename. See its definition in |
133 | the definition of quick_symbol_functions in symfile.h. */ | |
f8eba3c6 | 134 | |
39298a5d TT |
135 | bool |
136 | psymbol_functions::map_symtabs_matching_filename | |
14bc53a8 PA |
137 | (struct objfile *objfile, |
138 | const char *name, | |
139 | const char *real_path, | |
140 | gdb::function_view<bool (symtab *)> callback) | |
ccefe4c4 | 141 | { |
c011a4f4 | 142 | const char *name_basename = lbasename (name); |
ccefe4c4 | 143 | |
26abc753 | 144 | for (partial_symtab *pst : require_partial_symbols (objfile, true)) |
b22a7c6a | 145 | { |
b22a7c6a TT |
146 | /* Anonymous psymtabs don't have a file name. */ |
147 | if (pst->anonymous) | |
288e77a7 | 148 | continue; |
ccefe4c4 | 149 | |
b22a7c6a TT |
150 | if (compare_filenames_for_search (pst->filename, name)) |
151 | { | |
eea9e357 TV |
152 | while (pst->user) |
153 | pst = pst->user; | |
154 | ||
b22a7c6a TT |
155 | if (partial_map_expand_apply (objfile, name, real_path, |
156 | pst, callback)) | |
157 | return true; | |
158 | continue; | |
159 | } | |
c011a4f4 | 160 | |
b22a7c6a TT |
161 | /* Before we invoke realpath, which can get expensive when many |
162 | files are involved, do a quick comparison of the basenames. */ | |
163 | if (! basenames_may_differ | |
164 | && FILENAME_CMP (name_basename, lbasename (pst->filename)) != 0) | |
288e77a7 | 165 | continue; |
05cba821 | 166 | |
b22a7c6a TT |
167 | if (compare_filenames_for_search (psymtab_to_fullname (pst), name)) |
168 | { | |
169 | if (partial_map_expand_apply (objfile, name, real_path, | |
170 | pst, callback)) | |
171 | return true; | |
172 | continue; | |
173 | } | |
174 | ||
175 | /* If the user gave us an absolute path, try to find the file in | |
176 | this symtab and use its absolute path. */ | |
177 | if (real_path != NULL) | |
178 | { | |
179 | gdb_assert (IS_ABSOLUTE_PATH (real_path)); | |
180 | gdb_assert (IS_ABSOLUTE_PATH (name)); | |
181 | if (filename_cmp (psymtab_to_fullname (pst), real_path) == 0) | |
182 | { | |
183 | if (partial_map_expand_apply (objfile, name, real_path, | |
184 | pst, callback)) | |
185 | return true; | |
186 | continue; | |
187 | } | |
188 | } | |
189 | } | |
ccefe4c4 | 190 | |
14bc53a8 | 191 | return false; |
ccefe4c4 TT |
192 | } |
193 | ||
194 | /* Find which partial symtab contains PC and SECTION starting at psymtab PST. | |
195 | We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */ | |
196 | ||
197 | static struct partial_symtab * | |
5c80ed9d TT |
198 | find_pc_sect_psymtab_closer (struct objfile *objfile, |
199 | CORE_ADDR pc, struct obj_section *section, | |
ccefe4c4 | 200 | struct partial_symtab *pst, |
77e371c0 | 201 | struct bound_minimal_symbol msymbol) |
ccefe4c4 | 202 | { |
ccefe4c4 TT |
203 | struct partial_symtab *tpst; |
204 | struct partial_symtab *best_pst = pst; | |
79748972 | 205 | CORE_ADDR best_addr = pst->text_low (objfile); |
ccefe4c4 | 206 | |
9750bca9 JK |
207 | gdb_assert (!pst->psymtabs_addrmap_supported); |
208 | ||
ccefe4c4 TT |
209 | /* An objfile that has its functions reordered might have |
210 | many partial symbol tables containing the PC, but | |
211 | we want the partial symbol table that contains the | |
212 | function containing the PC. */ | |
95cf5869 DE |
213 | if (!(objfile->flags & OBJF_REORDERED) |
214 | && section == NULL) /* Can't validate section this way. */ | |
ccefe4c4 TT |
215 | return pst; |
216 | ||
77e371c0 | 217 | if (msymbol.minsym == NULL) |
95cf5869 | 218 | return pst; |
ccefe4c4 TT |
219 | |
220 | /* The code range of partial symtabs sometimes overlap, so, in | |
221 | the loop below, we need to check all partial symtabs and | |
0df8b418 | 222 | find the one that fits better for the given PC address. We |
ccefe4c4 TT |
223 | select the partial symtab that contains a symbol whose |
224 | address is closest to the PC address. By closest we mean | |
225 | that find_pc_sect_symbol returns the symbol with address | |
226 | that is closest and still less than the given PC. */ | |
227 | for (tpst = pst; tpst != NULL; tpst = tpst->next) | |
228 | { | |
79748972 | 229 | if (pc >= tpst->text_low (objfile) && pc < tpst->text_high (objfile)) |
ccefe4c4 TT |
230 | { |
231 | struct partial_symbol *p; | |
232 | CORE_ADDR this_addr; | |
233 | ||
234 | /* NOTE: This assumes that every psymbol has a | |
235 | corresponding msymbol, which is not necessarily | |
236 | true; the debug info might be much richer than the | |
237 | object's symbol table. */ | |
5c80ed9d | 238 | p = find_pc_sect_psymbol (objfile, tpst, pc, section); |
ccefe4c4 | 239 | if (p != NULL |
02e9e7f7 | 240 | && (p->address (objfile) == BMSYMBOL_VALUE_ADDRESS (msymbol))) |
ccefe4c4 TT |
241 | return tpst; |
242 | ||
243 | /* Also accept the textlow value of a psymtab as a | |
244 | "symbol", to provide some support for partial | |
245 | symbol tables with line information but no debug | |
246 | symbols (e.g. those produced by an assembler). */ | |
247 | if (p != NULL) | |
02e9e7f7 | 248 | this_addr = p->address (objfile); |
ccefe4c4 | 249 | else |
79748972 | 250 | this_addr = tpst->text_low (objfile); |
ccefe4c4 TT |
251 | |
252 | /* Check whether it is closer than our current | |
253 | BEST_ADDR. Since this symbol address is | |
254 | necessarily lower or equal to PC, the symbol closer | |
255 | to PC is the symbol which address is the highest. | |
256 | This way we return the psymtab which contains such | |
0df8b418 | 257 | best match symbol. This can help in cases where the |
ccefe4c4 TT |
258 | symbol information/debuginfo is not complete, like |
259 | for instance on IRIX6 with gcc, where no debug info | |
0df8b418 MS |
260 | is emitted for statics. (See also the nodebug.exp |
261 | testcase.) */ | |
ccefe4c4 TT |
262 | if (this_addr > best_addr) |
263 | { | |
264 | best_addr = this_addr; | |
265 | best_pst = tpst; | |
266 | } | |
267 | } | |
268 | } | |
269 | return best_pst; | |
270 | } | |
271 | ||
95cf5869 | 272 | /* Find which partial symtab contains PC and SECTION. Return NULL if |
ccefe4c4 TT |
273 | none. We return the psymtab that contains a symbol whose address |
274 | exactly matches PC, or, if we cannot find an exact match, the | |
275 | psymtab that contains a symbol whose address is closest to PC. */ | |
95cf5869 | 276 | |
ccefe4c4 TT |
277 | static struct partial_symtab * |
278 | find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc, | |
279 | struct obj_section *section, | |
77e371c0 | 280 | struct bound_minimal_symbol msymbol) |
ccefe4c4 | 281 | { |
3dd9bb46 AB |
282 | /* Try just the PSYMTABS_ADDRMAP mapping first as it has better |
283 | granularity than the later used TEXTLOW/TEXTHIGH one. However, we need | |
284 | to take care as the PSYMTABS_ADDRMAP can hold things other than partial | |
285 | symtabs in some cases. | |
286 | ||
287 | This function should only be called for objfiles that are using partial | |
288 | symtabs, not for objfiles that are using indexes (.gdb_index or | |
289 | .debug_names), however 'maintenance print psymbols' calls this function | |
290 | directly for all objfiles. If we assume that PSYMTABS_ADDRMAP contains | |
291 | partial symtabs then we will end up returning a pointer to an object | |
292 | that is not a partial_symtab, which doesn't end well. */ | |
293 | ||
294 | if (objfile->partial_symtabs->psymtabs != NULL | |
295 | && objfile->partial_symtabs->psymtabs_addrmap != NULL) | |
ccefe4c4 | 296 | { |
b3b3bada | 297 | CORE_ADDR baseaddr = objfile->text_section_offset (); |
3dd9bb46 | 298 | |
b22a7c6a TT |
299 | struct partial_symtab *pst |
300 | = ((struct partial_symtab *) | |
d320c2b5 TT |
301 | addrmap_find (objfile->partial_symtabs->psymtabs_addrmap, |
302 | pc - baseaddr)); | |
ccefe4c4 TT |
303 | if (pst != NULL) |
304 | { | |
305 | /* FIXME: addrmaps currently do not handle overlayed sections, | |
306 | so fall back to the non-addrmap case if we're debugging | |
307 | overlays and the addrmap returned the wrong section. */ | |
95cf5869 | 308 | if (overlay_debugging && msymbol.minsym != NULL && section != NULL) |
ccefe4c4 TT |
309 | { |
310 | struct partial_symbol *p; | |
ad3bbd48 | 311 | |
ccefe4c4 TT |
312 | /* NOTE: This assumes that every psymbol has a |
313 | corresponding msymbol, which is not necessarily | |
314 | true; the debug info might be much richer than the | |
315 | object's symbol table. */ | |
5c80ed9d | 316 | p = find_pc_sect_psymbol (objfile, pst, pc, section); |
95cf5869 | 317 | if (p == NULL |
02e9e7f7 TT |
318 | || (p->address (objfile) |
319 | != BMSYMBOL_VALUE_ADDRESS (msymbol))) | |
ccefe4c4 TT |
320 | goto next; |
321 | } | |
322 | ||
323 | /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as | |
324 | PSYMTABS_ADDRMAP we used has already the best 1-byte | |
325 | granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into | |
326 | a worse chosen section due to the TEXTLOW/TEXTHIGH ranges | |
327 | overlap. */ | |
328 | ||
329 | return pst; | |
330 | } | |
331 | } | |
332 | ||
333 | next: | |
334 | ||
335 | /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs | |
336 | which still have no corresponding full SYMTABs read. But it is not | |
337 | present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB | |
338 | so far. */ | |
339 | ||
340 | /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of | |
341 | its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying | |
342 | debug info type in single OBJFILE. */ | |
343 | ||
26abc753 | 344 | for (partial_symtab *pst : require_partial_symbols (objfile, true)) |
9750bca9 | 345 | if (!pst->psymtabs_addrmap_supported |
79748972 | 346 | && pc >= pst->text_low (objfile) && pc < pst->text_high (objfile)) |
ccefe4c4 TT |
347 | { |
348 | struct partial_symtab *best_pst; | |
349 | ||
5c80ed9d TT |
350 | best_pst = find_pc_sect_psymtab_closer (objfile, pc, section, pst, |
351 | msymbol); | |
ccefe4c4 TT |
352 | if (best_pst != NULL) |
353 | return best_pst; | |
354 | } | |
355 | ||
356 | return NULL; | |
357 | } | |
358 | ||
95cf5869 DE |
359 | /* Psymtab version of find_pc_sect_compunit_symtab. See its definition in |
360 | the definition of quick_symbol_functions in symfile.h. */ | |
83827540 | 361 | |
39298a5d TT |
362 | struct compunit_symtab * |
363 | psymbol_functions::find_pc_sect_compunit_symtab | |
364 | (struct objfile *objfile, | |
365 | struct bound_minimal_symbol msymbol, | |
366 | CORE_ADDR pc, | |
367 | struct obj_section *section, | |
368 | int warn_if_readin) | |
ccefe4c4 TT |
369 | { |
370 | struct partial_symtab *ps = find_pc_sect_psymtab (objfile, pc, section, | |
371 | msymbol); | |
95cf5869 | 372 | if (ps != NULL) |
ccefe4c4 | 373 | { |
5717c425 | 374 | if (warn_if_readin && ps->readin_p (objfile)) |
ccefe4c4 TT |
375 | /* Might want to error() here (in case symtab is corrupt and |
376 | will cause a core dump), but maybe we can successfully | |
377 | continue, so let's not. */ | |
378 | warning (_("\ | |
379 | (Internal error: pc %s in read in psymtab, but not in symtab.)\n"), | |
08feed99 | 380 | paddress (objfile->arch (), pc)); |
5c80ed9d | 381 | psymtab_to_symtab (objfile, ps); |
5717c425 | 382 | return ps->get_compunit_symtab (objfile); |
ccefe4c4 TT |
383 | } |
384 | return NULL; | |
385 | } | |
386 | ||
387 | /* Find which partial symbol within a psymtab matches PC and SECTION. | |
95cf5869 | 388 | Return NULL if none. */ |
ccefe4c4 TT |
389 | |
390 | static struct partial_symbol * | |
5c80ed9d TT |
391 | find_pc_sect_psymbol (struct objfile *objfile, |
392 | struct partial_symtab *psymtab, CORE_ADDR pc, | |
ccefe4c4 TT |
393 | struct obj_section *section) |
394 | { | |
af5bf4ad | 395 | struct partial_symbol *best = NULL; |
ccefe4c4 | 396 | CORE_ADDR best_pc; |
79748972 | 397 | const CORE_ADDR textlow = psymtab->text_low (objfile); |
ccefe4c4 TT |
398 | |
399 | gdb_assert (psymtab != NULL); | |
400 | ||
0df8b418 | 401 | /* Cope with programs that start at address 0. */ |
79748972 | 402 | best_pc = (textlow != 0) ? textlow - 1 : 0; |
ccefe4c4 TT |
403 | |
404 | /* Search the global symbols as well as the static symbols, so that | |
405 | find_pc_partial_function doesn't use a minimal symbol and thus | |
406 | cache a bad endaddr. */ | |
932539d7 | 407 | for (partial_symbol *p : psymtab->global_psymbols) |
ccefe4c4 | 408 | { |
8a6d4234 TT |
409 | if (p->domain == VAR_DOMAIN |
410 | && p->aclass == LOC_BLOCK | |
02e9e7f7 TT |
411 | && pc >= p->address (objfile) |
412 | && (p->address (objfile) > best_pc | |
79748972 | 413 | || (psymtab->text_low (objfile) == 0 |
02e9e7f7 | 414 | && best_pc == 0 && p->address (objfile) == 0))) |
ccefe4c4 | 415 | { |
95cf5869 | 416 | if (section != NULL) /* Match on a specific section. */ |
ccefe4c4 | 417 | { |
8a6d4234 | 418 | if (!matching_obj_sections (p->obj_section (objfile), |
e27d198c | 419 | section)) |
ccefe4c4 TT |
420 | continue; |
421 | } | |
02e9e7f7 | 422 | best_pc = p->address (objfile); |
ccefe4c4 TT |
423 | best = p; |
424 | } | |
425 | } | |
426 | ||
932539d7 | 427 | for (partial_symbol *p : psymtab->static_psymbols) |
ccefe4c4 | 428 | { |
8a6d4234 TT |
429 | if (p->domain == VAR_DOMAIN |
430 | && p->aclass == LOC_BLOCK | |
02e9e7f7 TT |
431 | && pc >= p->address (objfile) |
432 | && (p->address (objfile) > best_pc | |
79748972 | 433 | || (psymtab->text_low (objfile) == 0 |
02e9e7f7 | 434 | && best_pc == 0 && p->address (objfile) == 0))) |
ccefe4c4 | 435 | { |
95cf5869 | 436 | if (section != NULL) /* Match on a specific section. */ |
ccefe4c4 | 437 | { |
8a6d4234 | 438 | if (!matching_obj_sections (p->obj_section (objfile), |
e27d198c | 439 | section)) |
ccefe4c4 TT |
440 | continue; |
441 | } | |
02e9e7f7 | 442 | best_pc = p->address (objfile); |
ccefe4c4 TT |
443 | best = p; |
444 | } | |
445 | } | |
446 | ||
447 | return best; | |
448 | } | |
449 | ||
95cf5869 DE |
450 | /* Psymtab version of lookup_symbol. See its definition in |
451 | the definition of quick_symbol_functions in symfile.h. */ | |
83827540 | 452 | |
39298a5d TT |
453 | struct compunit_symtab * |
454 | psymbol_functions::lookup_symbol (struct objfile *objfile, | |
455 | block_enum block_index, const char *name, | |
456 | const domain_enum domain) | |
ccefe4c4 | 457 | { |
ccefe4c4 | 458 | const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0); |
43f3e411 | 459 | struct compunit_symtab *stab_best = NULL; |
ccefe4c4 | 460 | |
b5ec771e PA |
461 | lookup_name_info lookup_name (name, symbol_name_match_type::FULL); |
462 | ||
8c072cb6 TT |
463 | lookup_name_info psym_lookup_name = lookup_name.make_ignore_params (); |
464 | ||
26abc753 | 465 | for (partial_symtab *ps : require_partial_symbols (objfile, true)) |
b22a7c6a | 466 | { |
5717c425 TT |
467 | if (!ps->readin_p (objfile) |
468 | && lookup_partial_symbol (objfile, ps, psym_lookup_name, | |
469 | psymtab_index, domain)) | |
b22a7c6a TT |
470 | { |
471 | struct symbol *sym, *with_opaque = NULL; | |
472 | struct compunit_symtab *stab = psymtab_to_symtab (objfile, ps); | |
473 | /* Note: While psymtab_to_symtab can return NULL if the | |
474 | partial symtab is empty, we can assume it won't here | |
475 | because lookup_partial_symbol succeeded. */ | |
476 | const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab); | |
582942f4 | 477 | const struct block *block = BLOCKVECTOR_BLOCK (bv, block_index); |
b22a7c6a TT |
478 | |
479 | sym = block_find_symbol (block, name, domain, | |
480 | block_find_non_opaque_type_preferred, | |
481 | &with_opaque); | |
482 | ||
483 | /* Some caution must be observed with overloaded functions | |
484 | and methods, since the index will not contain any overload | |
485 | information (but NAME might contain it). */ | |
486 | ||
487 | if (sym != NULL | |
488 | && SYMBOL_MATCHES_SEARCH_NAME (sym, lookup_name)) | |
489 | return stab; | |
490 | if (with_opaque != NULL | |
491 | && SYMBOL_MATCHES_SEARCH_NAME (with_opaque, lookup_name)) | |
492 | stab_best = stab; | |
493 | ||
494 | /* Keep looking through other psymtabs. */ | |
495 | } | |
496 | } | |
ccefe4c4 | 497 | |
bfb05775 | 498 | return stab_best; |
ccefe4c4 TT |
499 | } |
500 | ||
d3214198 TV |
501 | /* Psymtab version of lookup_global_symbol_language. See its definition in |
502 | the definition of quick_symbol_functions in symfile.h. */ | |
503 | ||
39298a5d TT |
504 | enum language |
505 | psymbol_functions::lookup_global_symbol_language (struct objfile *objfile, | |
506 | const char *name, | |
507 | domain_enum domain, | |
508 | bool *symbol_found_p) | |
d3214198 TV |
509 | { |
510 | *symbol_found_p = false; | |
511 | if (objfile->sf == NULL) | |
512 | return language_unknown; | |
513 | ||
514 | lookup_name_info lookup_name (name, symbol_name_match_type::FULL); | |
515 | ||
516 | for (partial_symtab *ps : require_partial_symbols (objfile, true)) | |
517 | { | |
518 | struct partial_symbol *psym; | |
5717c425 | 519 | if (ps->readin_p (objfile)) |
d3214198 TV |
520 | continue; |
521 | ||
522 | psym = lookup_partial_symbol (objfile, ps, lookup_name, 1, domain); | |
523 | if (psym) | |
524 | { | |
525 | *symbol_found_p = true; | |
526 | return psym->ginfo.language (); | |
527 | } | |
528 | } | |
529 | ||
530 | return language_unknown; | |
531 | } | |
532 | ||
b5ec771e PA |
533 | /* Returns true if PSYM matches LOOKUP_NAME. */ |
534 | ||
535 | static bool | |
536 | psymbol_name_matches (partial_symbol *psym, | |
537 | const lookup_name_info &lookup_name) | |
538 | { | |
c1b5c1eb | 539 | const language_defn *lang = language_def (psym->ginfo.language ()); |
b5ec771e | 540 | symbol_name_matcher_ftype *name_match |
c9debfb9 | 541 | = lang->get_symbol_name_matcher (lookup_name); |
c9d95fa3 | 542 | return name_match (psym->ginfo.search_name (), lookup_name, NULL); |
b5ec771e PA |
543 | } |
544 | ||
40658b94 PH |
545 | /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search |
546 | the global block of PST if GLOBAL, and otherwise the static block. | |
547 | MATCH is the comparison operation that returns true iff MATCH (s, | |
548 | NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is | |
549 | non-null, the symbols in the block are assumed to be ordered | |
550 | according to it (allowing binary search). It must be compatible | |
551 | with MATCH. Returns the symbol, if found, and otherwise NULL. */ | |
552 | ||
553 | static struct partial_symbol * | |
5c80ed9d TT |
554 | match_partial_symbol (struct objfile *objfile, |
555 | struct partial_symtab *pst, int global, | |
b054970d | 556 | const lookup_name_info &name, domain_enum domain, |
2edb89d3 | 557 | symbol_compare_ftype *ordered_compare) |
40658b94 PH |
558 | { |
559 | struct partial_symbol **start, **psym; | |
560 | struct partial_symbol **top, **real_top, **bottom, **center; | |
932539d7 TT |
561 | int length = (global |
562 | ? pst->global_psymbols.size () | |
563 | : pst->static_psymbols.size ()); | |
40658b94 PH |
564 | int do_linear_search = 1; |
565 | ||
566 | if (length == 0) | |
b5ec771e PA |
567 | return NULL; |
568 | ||
40658b94 | 569 | start = (global ? |
932539d7 TT |
570 | &pst->global_psymbols[0] : |
571 | &pst->static_psymbols[0]); | |
40658b94 PH |
572 | |
573 | if (global && ordered_compare) /* Can use a binary search. */ | |
574 | { | |
575 | do_linear_search = 0; | |
576 | ||
577 | /* Binary search. This search is guaranteed to end with center | |
dda83cd7 SM |
578 | pointing at the earliest partial symbol whose name might be |
579 | correct. At that point *all* partial symbols with an | |
580 | appropriate name will be checked against the correct | |
581 | domain. */ | |
40658b94 PH |
582 | |
583 | bottom = start; | |
584 | top = start + length - 1; | |
585 | real_top = top; | |
586 | while (top > bottom) | |
587 | { | |
588 | center = bottom + (top - bottom) / 2; | |
589 | gdb_assert (center < top); | |
b5ec771e | 590 | |
c1b5c1eb | 591 | enum language lang = (*center)->ginfo.language (); |
e0802d59 | 592 | const char *lang_ln = name.language_lookup_name (lang); |
b5ec771e | 593 | |
c9d95fa3 | 594 | if (ordered_compare ((*center)->ginfo.search_name (), |
af97b416 | 595 | lang_ln) >= 0) |
40658b94 PH |
596 | top = center; |
597 | else | |
598 | bottom = center + 1; | |
599 | } | |
600 | gdb_assert (top == bottom); | |
601 | ||
602 | while (top <= real_top | |
b054970d | 603 | && psymbol_name_matches (*top, name)) |
40658b94 | 604 | { |
c1b5c1eb | 605 | if (symbol_matches_domain ((*top)->ginfo.language (), |
8a6d4234 | 606 | (*top)->domain, domain)) |
40658b94 PH |
607 | return *top; |
608 | top++; | |
609 | } | |
610 | } | |
611 | ||
612 | /* Can't use a binary search or else we found during the binary search that | |
613 | we should also do a linear search. */ | |
614 | ||
615 | if (do_linear_search) | |
616 | { | |
617 | for (psym = start; psym < start + length; psym++) | |
618 | { | |
c1b5c1eb | 619 | if (symbol_matches_domain ((*psym)->ginfo.language (), |
8a6d4234 | 620 | (*psym)->domain, domain) |
b054970d | 621 | && psymbol_name_matches (*psym, name)) |
40658b94 PH |
622 | return *psym; |
623 | } | |
624 | } | |
625 | ||
626 | return NULL; | |
627 | } | |
628 | ||
8c072cb6 TT |
629 | /* Look, in partial_symtab PST, for symbol whose natural name is |
630 | LOOKUP_NAME. Check the global symbols if GLOBAL, the static | |
631 | symbols if not. */ | |
ccefe4c4 | 632 | |
18430289 | 633 | static struct partial_symbol * |
5c80ed9d | 634 | lookup_partial_symbol (struct objfile *objfile, |
8c072cb6 TT |
635 | struct partial_symtab *pst, |
636 | const lookup_name_info &lookup_name, | |
ccefe4c4 TT |
637 | int global, domain_enum domain) |
638 | { | |
ccefe4c4 TT |
639 | struct partial_symbol **start, **psym; |
640 | struct partial_symbol **top, **real_top, **bottom, **center; | |
932539d7 TT |
641 | int length = (global |
642 | ? pst->global_psymbols.size () | |
643 | : pst->static_psymbols.size ()); | |
ccefe4c4 TT |
644 | int do_linear_search = 1; |
645 | ||
646 | if (length == 0) | |
95cf5869 | 647 | return NULL; |
c00f8484 | 648 | |
ccefe4c4 | 649 | start = (global ? |
932539d7 TT |
650 | &pst->global_psymbols[0] : |
651 | &pst->static_psymbols[0]); | |
ccefe4c4 | 652 | |
0df8b418 | 653 | if (global) /* This means we can use a binary search. */ |
ccefe4c4 TT |
654 | { |
655 | do_linear_search = 0; | |
656 | ||
657 | /* Binary search. This search is guaranteed to end with center | |
dda83cd7 SM |
658 | pointing at the earliest partial symbol whose name might be |
659 | correct. At that point *all* partial symbols with an | |
660 | appropriate name will be checked against the correct | |
661 | domain. */ | |
ccefe4c4 TT |
662 | |
663 | bottom = start; | |
664 | top = start + length - 1; | |
665 | real_top = top; | |
666 | while (top > bottom) | |
667 | { | |
668 | center = bottom + (top - bottom) / 2; | |
e2ff18a0 SM |
669 | |
670 | gdb_assert (center < top); | |
671 | ||
c9d95fa3 | 672 | if (strcmp_iw_ordered ((*center)->ginfo.search_name (), |
e0802d59 | 673 | lookup_name.c_str ()) >= 0) |
ccefe4c4 TT |
674 | { |
675 | top = center; | |
676 | } | |
677 | else | |
678 | { | |
679 | bottom = center + 1; | |
680 | } | |
681 | } | |
e2ff18a0 SM |
682 | |
683 | gdb_assert (top == bottom); | |
ccefe4c4 | 684 | |
559a7a62 JK |
685 | /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will |
686 | search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */ | |
af97b416 TT |
687 | while (top >= start && symbol_matches_search_name (&(*top)->ginfo, |
688 | lookup_name)) | |
559a7a62 JK |
689 | top--; |
690 | ||
691 | /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */ | |
692 | top++; | |
693 | ||
af97b416 TT |
694 | while (top <= real_top && symbol_matches_search_name (&(*top)->ginfo, |
695 | lookup_name)) | |
ccefe4c4 | 696 | { |
c1b5c1eb | 697 | if (symbol_matches_domain ((*top)->ginfo.language (), |
8a6d4234 | 698 | (*top)->domain, domain)) |
56f37645 | 699 | return *top; |
ccefe4c4 TT |
700 | top++; |
701 | } | |
702 | } | |
703 | ||
704 | /* Can't use a binary search or else we found during the binary search that | |
40658b94 | 705 | we should also do a linear search. */ |
ccefe4c4 TT |
706 | |
707 | if (do_linear_search) | |
708 | { | |
709 | for (psym = start; psym < start + length; psym++) | |
710 | { | |
c1b5c1eb | 711 | if (symbol_matches_domain ((*psym)->ginfo.language (), |
8a6d4234 | 712 | (*psym)->domain, domain) |
af97b416 | 713 | && symbol_matches_search_name (&(*psym)->ginfo, lookup_name)) |
56f37645 | 714 | return *psym; |
ccefe4c4 TT |
715 | } |
716 | } | |
717 | ||
95cf5869 | 718 | return NULL; |
ccefe4c4 TT |
719 | } |
720 | ||
721 | /* Get the symbol table that corresponds to a partial_symtab. | |
f194fefb DE |
722 | This is fast after the first time you do it. |
723 | The result will be NULL if the primary symtab has no symbols, | |
724 | which can happen. Otherwise the result is the primary symtab | |
725 | that contains PST. */ | |
ccefe4c4 | 726 | |
43f3e411 | 727 | static struct compunit_symtab * |
5c80ed9d | 728 | psymtab_to_symtab (struct objfile *objfile, struct partial_symtab *pst) |
ccefe4c4 | 729 | { |
9439a077 TT |
730 | /* If it is a shared psymtab, find an unshared psymtab that includes |
731 | it. Any such psymtab will do. */ | |
732 | while (pst->user != NULL) | |
733 | pst = pst->user; | |
734 | ||
0df8b418 | 735 | /* If it's been looked up before, return it. */ |
5717c425 TT |
736 | if (pst->get_compunit_symtab (objfile)) |
737 | return pst->get_compunit_symtab (objfile); | |
ccefe4c4 TT |
738 | |
739 | /* If it has not yet been read in, read it. */ | |
5717c425 | 740 | if (!pst->readin_p (objfile)) |
ccefe4c4 | 741 | { |
c83dd867 | 742 | scoped_restore decrementer = increment_reading_symtab (); |
ad3bbd48 | 743 | |
077cbab2 TT |
744 | if (info_verbose) |
745 | { | |
fd760e79 | 746 | printf_filtered (_("Reading in symbols for %s...\n"), |
077cbab2 TT |
747 | pst->filename); |
748 | gdb_flush (gdb_stdout); | |
749 | } | |
750 | ||
891813be | 751 | pst->read_symtab (objfile); |
ccefe4c4 TT |
752 | } |
753 | ||
5717c425 | 754 | return pst->get_compunit_symtab (objfile); |
ccefe4c4 TT |
755 | } |
756 | ||
95cf5869 DE |
757 | /* Psymtab version of find_last_source_symtab. See its definition in |
758 | the definition of quick_symbol_functions in symfile.h. */ | |
83827540 | 759 | |
39298a5d TT |
760 | struct symtab * |
761 | psymbol_functions::find_last_source_symtab (struct objfile *ofp) | |
ccefe4c4 | 762 | { |
95cf5869 | 763 | struct partial_symtab *cs_pst = NULL; |
ccefe4c4 | 764 | |
26abc753 | 765 | for (partial_symtab *ps : require_partial_symbols (ofp, true)) |
ccefe4c4 TT |
766 | { |
767 | const char *name = ps->filename; | |
768 | int len = strlen (name); | |
ad3bbd48 | 769 | |
ccefe4c4 TT |
770 | if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0 |
771 | || strcmp (name, "<<C++-namespaces>>") == 0))) | |
772 | cs_pst = ps; | |
773 | } | |
774 | ||
775 | if (cs_pst) | |
776 | { | |
5717c425 | 777 | if (cs_pst->readin_p (ofp)) |
ccefe4c4 TT |
778 | { |
779 | internal_error (__FILE__, __LINE__, | |
780 | _("select_source_symtab: " | |
781 | "readin pst found and no symtabs.")); | |
782 | } | |
783 | else | |
43f3e411 DE |
784 | { |
785 | struct compunit_symtab *cust = psymtab_to_symtab (ofp, cs_pst); | |
786 | ||
787 | if (cust == NULL) | |
788 | return NULL; | |
789 | return compunit_primary_filetab (cust); | |
790 | } | |
ccefe4c4 TT |
791 | } |
792 | return NULL; | |
793 | } | |
794 | ||
95cf5869 DE |
795 | /* Psymtab version of forget_cached_source_info. See its definition in |
796 | the definition of quick_symbol_functions in symfile.h. */ | |
83827540 | 797 | |
39298a5d TT |
798 | void |
799 | psymbol_functions::forget_cached_source_info (struct objfile *objfile) | |
ccefe4c4 | 800 | { |
26abc753 | 801 | for (partial_symtab *pst : require_partial_symbols (objfile, true)) |
ccefe4c4 TT |
802 | { |
803 | if (pst->fullname != NULL) | |
804 | { | |
805 | xfree (pst->fullname); | |
806 | pst->fullname = NULL; | |
807 | } | |
808 | } | |
809 | } | |
810 | ||
811 | static void | |
02e9e7f7 | 812 | print_partial_symbols (struct gdbarch *gdbarch, struct objfile *objfile, |
932539d7 TT |
813 | const std::vector<partial_symbol *> &symbols, |
814 | const char *what, struct ui_file *outfile) | |
ccefe4c4 TT |
815 | { |
816 | fprintf_filtered (outfile, " %s partial symbols:\n", what); | |
932539d7 | 817 | for (partial_symbol *p : symbols) |
ccefe4c4 | 818 | { |
27618ce4 | 819 | QUIT; |
932539d7 TT |
820 | fprintf_filtered (outfile, " `%s'", p->ginfo.linkage_name ()); |
821 | if (p->ginfo.demangled_name () != NULL) | |
ccefe4c4 | 822 | { |
af97b416 | 823 | fprintf_filtered (outfile, " `%s'", |
932539d7 | 824 | p->ginfo.demangled_name ()); |
ccefe4c4 TT |
825 | } |
826 | fputs_filtered (", ", outfile); | |
932539d7 | 827 | switch (p->domain) |
ccefe4c4 TT |
828 | { |
829 | case UNDEF_DOMAIN: | |
830 | fputs_filtered ("undefined domain, ", outfile); | |
831 | break; | |
832 | case VAR_DOMAIN: | |
0df8b418 | 833 | /* This is the usual thing -- don't print it. */ |
ccefe4c4 TT |
834 | break; |
835 | case STRUCT_DOMAIN: | |
836 | fputs_filtered ("struct domain, ", outfile); | |
837 | break; | |
06ff036e AB |
838 | case MODULE_DOMAIN: |
839 | fputs_filtered ("module domain, ", outfile); | |
840 | break; | |
ccefe4c4 TT |
841 | case LABEL_DOMAIN: |
842 | fputs_filtered ("label domain, ", outfile); | |
843 | break; | |
06ff036e AB |
844 | case COMMON_BLOCK_DOMAIN: |
845 | fputs_filtered ("common block domain, ", outfile); | |
846 | break; | |
ccefe4c4 TT |
847 | default: |
848 | fputs_filtered ("<invalid domain>, ", outfile); | |
849 | break; | |
850 | } | |
932539d7 | 851 | switch (p->aclass) |
ccefe4c4 TT |
852 | { |
853 | case LOC_UNDEF: | |
854 | fputs_filtered ("undefined", outfile); | |
855 | break; | |
856 | case LOC_CONST: | |
857 | fputs_filtered ("constant int", outfile); | |
858 | break; | |
859 | case LOC_STATIC: | |
860 | fputs_filtered ("static", outfile); | |
861 | break; | |
862 | case LOC_REGISTER: | |
863 | fputs_filtered ("register", outfile); | |
864 | break; | |
865 | case LOC_ARG: | |
866 | fputs_filtered ("pass by value", outfile); | |
867 | break; | |
868 | case LOC_REF_ARG: | |
869 | fputs_filtered ("pass by reference", outfile); | |
870 | break; | |
871 | case LOC_REGPARM_ADDR: | |
872 | fputs_filtered ("register address parameter", outfile); | |
873 | break; | |
874 | case LOC_LOCAL: | |
875 | fputs_filtered ("stack parameter", outfile); | |
876 | break; | |
877 | case LOC_TYPEDEF: | |
878 | fputs_filtered ("type", outfile); | |
879 | break; | |
880 | case LOC_LABEL: | |
881 | fputs_filtered ("label", outfile); | |
882 | break; | |
883 | case LOC_BLOCK: | |
884 | fputs_filtered ("function", outfile); | |
885 | break; | |
886 | case LOC_CONST_BYTES: | |
887 | fputs_filtered ("constant bytes", outfile); | |
888 | break; | |
889 | case LOC_UNRESOLVED: | |
890 | fputs_filtered ("unresolved", outfile); | |
891 | break; | |
892 | case LOC_OPTIMIZED_OUT: | |
893 | fputs_filtered ("optimized out", outfile); | |
894 | break; | |
895 | case LOC_COMPUTED: | |
896 | fputs_filtered ("computed at runtime", outfile); | |
897 | break; | |
898 | default: | |
899 | fputs_filtered ("<invalid location>", outfile); | |
900 | break; | |
901 | } | |
902 | fputs_filtered (", ", outfile); | |
932539d7 | 903 | fputs_filtered (paddress (gdbarch, p->unrelocated_address ()), outfile); |
ccefe4c4 | 904 | fprintf_filtered (outfile, "\n"); |
ccefe4c4 TT |
905 | } |
906 | } | |
907 | ||
908 | static void | |
909 | dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab, | |
910 | struct ui_file *outfile) | |
911 | { | |
08feed99 | 912 | struct gdbarch *gdbarch = objfile->arch (); |
ccefe4c4 TT |
913 | int i; |
914 | ||
b4c41fc7 DE |
915 | if (psymtab->anonymous) |
916 | { | |
917 | fprintf_filtered (outfile, "\nAnonymous partial symtab (%s) ", | |
918 | psymtab->filename); | |
919 | } | |
920 | else | |
921 | { | |
922 | fprintf_filtered (outfile, "\nPartial symtab for source file %s ", | |
923 | psymtab->filename); | |
924 | } | |
ccefe4c4 TT |
925 | fprintf_filtered (outfile, "(object "); |
926 | gdb_print_host_address (psymtab, outfile); | |
927 | fprintf_filtered (outfile, ")\n\n"); | |
22068491 TT |
928 | fprintf_filtered (outfile, " Read from object file %s (", |
929 | objfile_name (objfile)); | |
ccefe4c4 | 930 | gdb_print_host_address (objfile, outfile); |
22068491 | 931 | fprintf_filtered (outfile, ")\n"); |
ccefe4c4 | 932 | |
5717c425 | 933 | if (psymtab->readin_p (objfile)) |
ccefe4c4 TT |
934 | { |
935 | fprintf_filtered (outfile, | |
936 | " Full symtab was read (at "); | |
5717c425 | 937 | gdb_print_host_address (psymtab->get_compunit_symtab (objfile), outfile); |
ccefe4c4 TT |
938 | fprintf_filtered (outfile, ")\n"); |
939 | } | |
940 | ||
ccefe4c4 | 941 | fprintf_filtered (outfile, " Symbols cover text addresses "); |
79748972 | 942 | fputs_filtered (paddress (gdbarch, psymtab->text_low (objfile)), outfile); |
ccefe4c4 | 943 | fprintf_filtered (outfile, "-"); |
79748972 | 944 | fputs_filtered (paddress (gdbarch, psymtab->text_high (objfile)), outfile); |
ccefe4c4 | 945 | fprintf_filtered (outfile, "\n"); |
9750bca9 JK |
946 | fprintf_filtered (outfile, " Address map supported - %s.\n", |
947 | psymtab->psymtabs_addrmap_supported ? "yes" : "no"); | |
ccefe4c4 TT |
948 | fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n", |
949 | psymtab->number_of_dependencies); | |
950 | for (i = 0; i < psymtab->number_of_dependencies; i++) | |
951 | { | |
952 | fprintf_filtered (outfile, " %d ", i); | |
953 | gdb_print_host_address (psymtab->dependencies[i], outfile); | |
954 | fprintf_filtered (outfile, " %s\n", | |
955 | psymtab->dependencies[i]->filename); | |
956 | } | |
9439a077 TT |
957 | if (psymtab->user != NULL) |
958 | { | |
959 | fprintf_filtered (outfile, " Shared partial symtab with user "); | |
960 | gdb_print_host_address (psymtab->user, outfile); | |
961 | fprintf_filtered (outfile, "\n"); | |
962 | } | |
932539d7 | 963 | if (!psymtab->global_psymbols.empty ()) |
ccefe4c4 | 964 | { |
d320c2b5 | 965 | print_partial_symbols |
932539d7 TT |
966 | (gdbarch, objfile, psymtab->global_psymbols, |
967 | "Global", outfile); | |
ccefe4c4 | 968 | } |
932539d7 | 969 | if (!psymtab->static_psymbols.empty ()) |
ccefe4c4 | 970 | { |
d320c2b5 | 971 | print_partial_symbols |
932539d7 TT |
972 | (gdbarch, objfile, psymtab->static_psymbols, |
973 | "Static", outfile); | |
ccefe4c4 TT |
974 | } |
975 | fprintf_filtered (outfile, "\n"); | |
976 | } | |
977 | ||
4829711b TT |
978 | /* Count the number of partial symbols in OBJFILE. */ |
979 | ||
980 | static int | |
981 | count_psyms (struct objfile *objfile) | |
982 | { | |
983 | int count = 0; | |
984 | for (partial_symtab *pst : objfile->psymtabs ()) | |
985 | { | |
986 | count += pst->global_psymbols.size (); | |
987 | count += pst->static_psymbols.size (); | |
988 | } | |
989 | return count; | |
990 | } | |
991 | ||
95cf5869 DE |
992 | /* Psymtab version of print_stats. See its definition in |
993 | the definition of quick_symbol_functions in symfile.h. */ | |
83827540 | 994 | |
39298a5d | 995 | void |
4829711b | 996 | psymbol_functions::print_stats (struct objfile *objfile, bool print_bcache) |
ccefe4c4 TT |
997 | { |
998 | int i; | |
ad3bbd48 | 999 | |
4829711b TT |
1000 | if (!print_bcache) |
1001 | { | |
1002 | int n_psyms = count_psyms (objfile); | |
1003 | if (n_psyms > 0) | |
1004 | printf_filtered (_(" Number of \"partial\" symbols read: %d\n"), | |
1005 | n_psyms); | |
1006 | ||
1007 | i = 0; | |
1008 | for (partial_symtab *ps : require_partial_symbols (objfile, true)) | |
1009 | { | |
1010 | if (!ps->readin_p (objfile)) | |
1011 | i++; | |
1012 | } | |
1013 | printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), | |
1014 | i); | |
1015 | printf_filtered (_(" Total memory used for psymbol cache: %d\n"), | |
1016 | objfile->partial_symtabs->psymbol_cache.memory_used ()); | |
1017 | } | |
1018 | else | |
ccefe4c4 | 1019 | { |
4829711b TT |
1020 | printf_filtered (_("Psymbol byte cache statistics:\n")); |
1021 | objfile->partial_symtabs->psymbol_cache.print_statistics | |
1022 | ("partial symbol cache"); | |
ccefe4c4 | 1023 | } |
ccefe4c4 TT |
1024 | } |
1025 | ||
95cf5869 DE |
1026 | /* Psymtab version of dump. See its definition in |
1027 | the definition of quick_symbol_functions in symfile.h. */ | |
83827540 | 1028 | |
39298a5d TT |
1029 | void |
1030 | psymbol_functions::dump (struct objfile *objfile) | |
ccefe4c4 TT |
1031 | { |
1032 | struct partial_symtab *psymtab; | |
1033 | ||
d320c2b5 | 1034 | if (objfile->partial_symtabs->psymtabs) |
ccefe4c4 TT |
1035 | { |
1036 | printf_filtered ("Psymtabs:\n"); | |
d320c2b5 | 1037 | for (psymtab = objfile->partial_symtabs->psymtabs; |
ccefe4c4 TT |
1038 | psymtab != NULL; |
1039 | psymtab = psymtab->next) | |
1040 | { | |
1041 | printf_filtered ("%s at ", | |
1042 | psymtab->filename); | |
1043 | gdb_print_host_address (psymtab, gdb_stdout); | |
1044 | printf_filtered (", "); | |
ccefe4c4 TT |
1045 | wrap_here (" "); |
1046 | } | |
1047 | printf_filtered ("\n\n"); | |
1048 | } | |
1049 | } | |
1050 | ||
95cf5869 DE |
1051 | /* Psymtab version of expand_symtabs_for_function. See its definition in |
1052 | the definition of quick_symbol_functions in symfile.h. */ | |
ccefe4c4 | 1053 | |
39298a5d TT |
1054 | void |
1055 | psymbol_functions::expand_symtabs_for_function (struct objfile *objfile, | |
1056 | const char *func_name) | |
ccefe4c4 | 1057 | { |
8c072cb6 TT |
1058 | lookup_name_info base_lookup (func_name, symbol_name_match_type::FULL); |
1059 | lookup_name_info lookup_name = base_lookup.make_ignore_params (); | |
1060 | ||
26abc753 | 1061 | for (partial_symtab *ps : require_partial_symbols (objfile, true)) |
b22a7c6a | 1062 | { |
5717c425 | 1063 | if (ps->readin_p (objfile)) |
b22a7c6a | 1064 | continue; |
ccefe4c4 | 1065 | |
8c072cb6 | 1066 | if ((lookup_partial_symbol (objfile, ps, lookup_name, 1, VAR_DOMAIN) |
b22a7c6a | 1067 | != NULL) |
8c072cb6 | 1068 | || (lookup_partial_symbol (objfile, ps, lookup_name, 0, VAR_DOMAIN) |
b22a7c6a TT |
1069 | != NULL)) |
1070 | psymtab_to_symtab (objfile, ps); | |
1071 | } | |
ccefe4c4 TT |
1072 | } |
1073 | ||
95cf5869 DE |
1074 | /* Psymtab version of expand_all_symtabs. See its definition in |
1075 | the definition of quick_symbol_functions in symfile.h. */ | |
83827540 | 1076 | |
39298a5d TT |
1077 | void |
1078 | psymbol_functions::expand_all_symtabs (struct objfile *objfile) | |
ccefe4c4 | 1079 | { |
26abc753 | 1080 | for (partial_symtab *psymtab : require_partial_symbols (objfile, true)) |
b22a7c6a | 1081 | psymtab_to_symtab (objfile, psymtab); |
ccefe4c4 TT |
1082 | } |
1083 | ||
95cf5869 DE |
1084 | /* Psymtab version of expand_symtabs_with_fullname. See its definition in |
1085 | the definition of quick_symbol_functions in symfile.h. */ | |
83827540 | 1086 | |
39298a5d TT |
1087 | void |
1088 | psymbol_functions::expand_symtabs_with_fullname (struct objfile *objfile, | |
1089 | const char *fullname) | |
ccefe4c4 | 1090 | { |
26abc753 | 1091 | for (partial_symtab *p : require_partial_symbols (objfile, true)) |
ccefe4c4 | 1092 | { |
b4c41fc7 DE |
1093 | /* Anonymous psymtabs don't have a name of a source file. */ |
1094 | if (p->anonymous) | |
1095 | continue; | |
1096 | ||
5ff888ce DE |
1097 | /* psymtab_to_fullname tries to open the file which is slow. |
1098 | Don't call it if we know the basenames don't match. */ | |
1099 | if ((basenames_may_differ | |
1100 | || filename_cmp (lbasename (fullname), lbasename (p->filename)) == 0) | |
1101 | && filename_cmp (fullname, psymtab_to_fullname (p)) == 0) | |
5c80ed9d | 1102 | psymtab_to_symtab (objfile, p); |
ccefe4c4 TT |
1103 | } |
1104 | } | |
1105 | ||
95cf5869 DE |
1106 | /* Psymtab version of map_symbol_filenames. See its definition in |
1107 | the definition of quick_symbol_functions in symfile.h. */ | |
83827540 | 1108 | |
39298a5d TT |
1109 | void |
1110 | psymbol_functions::map_symbol_filenames (struct objfile *objfile, | |
1111 | symbol_filename_ftype *fun, | |
1112 | void *data, | |
1113 | int need_fullname) | |
ccefe4c4 | 1114 | { |
26abc753 | 1115 | for (partial_symtab *ps : require_partial_symbols (objfile, true)) |
ccefe4c4 TT |
1116 | { |
1117 | const char *fullname; | |
1118 | ||
5717c425 | 1119 | if (ps->readin_p (objfile)) |
ccefe4c4 TT |
1120 | continue; |
1121 | ||
f80c6f3f DE |
1122 | /* We can skip shared psymtabs here, because any file name will be |
1123 | attached to the unshared psymtab. */ | |
1124 | if (ps->user != NULL) | |
1125 | continue; | |
1126 | ||
b4c41fc7 DE |
1127 | /* Anonymous psymtabs don't have a file name. */ |
1128 | if (ps->anonymous) | |
1129 | continue; | |
1130 | ||
821296b7 | 1131 | QUIT; |
74e2f255 DE |
1132 | if (need_fullname) |
1133 | fullname = psymtab_to_fullname (ps); | |
1134 | else | |
1135 | fullname = NULL; | |
2837d59e | 1136 | (*fun) (ps->filename, fullname, data); |
ccefe4c4 TT |
1137 | } |
1138 | } | |
1139 | ||
ccefe4c4 TT |
1140 | /* Finds the fullname that a partial_symtab represents. |
1141 | ||
1142 | If this functions finds the fullname, it will save it in ps->fullname | |
1143 | and it will also return the value. | |
1144 | ||
1145 | If this function fails to find the file that this partial_symtab represents, | |
1146 | NULL will be returned and ps->fullname will be set to NULL. */ | |
256f06f3 | 1147 | |
da5132d3 | 1148 | static const char * |
ccefe4c4 TT |
1149 | psymtab_to_fullname (struct partial_symtab *ps) |
1150 | { | |
fbd9ab74 | 1151 | gdb_assert (!ps->anonymous); |
ccefe4c4 | 1152 | |
256f06f3 DE |
1153 | /* Use cached copy if we have it. |
1154 | We rely on forget_cached_source_info being called appropriately | |
1155 | to handle cases like the file being moved. */ | |
fbd9ab74 JK |
1156 | if (ps->fullname == NULL) |
1157 | { | |
e0cc99a6 | 1158 | gdb::unique_xmalloc_ptr<char> fullname; |
2179fbc3 TT |
1159 | scoped_fd fd = find_and_open_source (ps->filename, ps->dirname, |
1160 | &fullname); | |
e0cc99a6 | 1161 | ps->fullname = fullname.release (); |
256f06f3 | 1162 | |
2179fbc3 | 1163 | if (fd.get () < 0) |
fbd9ab74 | 1164 | { |
fbd9ab74 JK |
1165 | /* rewrite_source_path would be applied by find_and_open_source, we |
1166 | should report the pathname where GDB tried to find the file. */ | |
ccefe4c4 | 1167 | |
fbd9ab74 | 1168 | if (ps->dirname == NULL || IS_ABSOLUTE_PATH (ps->filename)) |
0b581c69 | 1169 | fullname.reset (xstrdup (ps->filename)); |
fbd9ab74 | 1170 | else |
0b581c69 TT |
1171 | fullname.reset (concat (ps->dirname, SLASH_STRING, |
1172 | ps->filename, (char *) NULL)); | |
fbd9ab74 | 1173 | |
0b581c69 | 1174 | ps->fullname = rewrite_source_path (fullname.get ()).release (); |
fbd9ab74 | 1175 | if (ps->fullname == NULL) |
0b581c69 | 1176 | ps->fullname = fullname.release (); |
fbd9ab74 | 1177 | } |
95cf5869 | 1178 | } |
fbd9ab74 JK |
1179 | |
1180 | return ps->fullname; | |
ccefe4c4 TT |
1181 | } |
1182 | ||
95cf5869 DE |
1183 | /* Psymtab version of map_matching_symbols. See its definition in |
1184 | the definition of quick_symbol_functions in symfile.h. */ | |
40658b94 | 1185 | |
39298a5d TT |
1186 | void |
1187 | psymbol_functions::map_matching_symbols | |
199b4314 | 1188 | (struct objfile *objfile, |
b054970d | 1189 | const lookup_name_info &name, domain_enum domain, |
199b4314 TT |
1190 | int global, |
1191 | gdb::function_view<symbol_found_callback_ftype> callback, | |
199b4314 | 1192 | symbol_compare_ftype *ordered_compare) |
ccefe4c4 | 1193 | { |
40658b94 | 1194 | const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK; |
ccefe4c4 | 1195 | |
26abc753 | 1196 | for (partial_symtab *ps : require_partial_symbols (objfile, true)) |
ccefe4c4 TT |
1197 | { |
1198 | QUIT; | |
5717c425 | 1199 | if (ps->readin_p (objfile) |
b054970d | 1200 | || match_partial_symbol (objfile, ps, global, name, domain, |
40658b94 | 1201 | ordered_compare)) |
ccefe4c4 | 1202 | { |
43f3e411 | 1203 | struct compunit_symtab *cust = psymtab_to_symtab (objfile, ps); |
582942f4 | 1204 | const struct block *block; |
ad3bbd48 | 1205 | |
43f3e411 | 1206 | if (cust == NULL) |
ccefe4c4 | 1207 | continue; |
43f3e411 | 1208 | block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), block_kind); |
b054970d | 1209 | if (!iterate_over_symbols_terminated (block, name, |
6a3dbf1b | 1210 | domain, callback)) |
40658b94 | 1211 | return; |
ccefe4c4 TT |
1212 | } |
1213 | } | |
95cf5869 | 1214 | } |
ccefe4c4 | 1215 | |
14bc53a8 PA |
1216 | /* A helper for psym_expand_symtabs_matching that handles searching |
1217 | included psymtabs. This returns true if a symbol is found, and | |
1218 | false otherwise. It also updates the 'searched_flag' on the | |
9439a077 TT |
1219 | various psymtabs that it searches. */ |
1220 | ||
14bc53a8 PA |
1221 | static bool |
1222 | recursively_search_psymtabs | |
d2f7dcb2 JB |
1223 | (struct partial_symtab *ps, |
1224 | struct objfile *objfile, | |
1225 | enum search_domain domain, | |
b5ec771e | 1226 | const lookup_name_info &lookup_name, |
14bc53a8 | 1227 | gdb::function_view<expand_symtabs_symbol_matcher_ftype> sym_matcher) |
9439a077 | 1228 | { |
9439a077 | 1229 | int keep_going = 1; |
f486487f | 1230 | enum psymtab_search_status result = PST_SEARCHED_AND_NOT_FOUND; |
9439a077 TT |
1231 | int i; |
1232 | ||
1233 | if (ps->searched_flag != PST_NOT_SEARCHED) | |
1234 | return ps->searched_flag == PST_SEARCHED_AND_FOUND; | |
1235 | ||
1236 | /* Recurse into shared psymtabs first, because they may have already | |
1237 | been searched, and this could save some time. */ | |
1238 | for (i = 0; i < ps->number_of_dependencies; ++i) | |
1239 | { | |
1240 | int r; | |
1241 | ||
1242 | /* Skip non-shared dependencies, these are handled elsewhere. */ | |
1243 | if (ps->dependencies[i]->user == NULL) | |
1244 | continue; | |
1245 | ||
1246 | r = recursively_search_psymtabs (ps->dependencies[i], | |
b5ec771e PA |
1247 | objfile, domain, lookup_name, |
1248 | sym_matcher); | |
9439a077 TT |
1249 | if (r != 0) |
1250 | { | |
1251 | ps->searched_flag = PST_SEARCHED_AND_FOUND; | |
14bc53a8 | 1252 | return true; |
9439a077 TT |
1253 | } |
1254 | } | |
1255 | ||
932539d7 TT |
1256 | partial_symbol **gbound = (ps->global_psymbols.data () |
1257 | + ps->global_psymbols.size ()); | |
1258 | partial_symbol **sbound = (ps->static_psymbols.data () | |
1259 | + ps->static_psymbols.size ()); | |
af5bf4ad | 1260 | partial_symbol **bound = gbound; |
9439a077 TT |
1261 | |
1262 | /* Go through all of the symbols stored in a partial | |
1263 | symtab in one loop. */ | |
932539d7 | 1264 | partial_symbol **psym = ps->global_psymbols.data (); |
9439a077 TT |
1265 | while (keep_going) |
1266 | { | |
1267 | if (psym >= bound) | |
1268 | { | |
932539d7 | 1269 | if (bound == gbound && !ps->static_psymbols.empty ()) |
9439a077 | 1270 | { |
932539d7 | 1271 | psym = ps->static_psymbols.data (); |
9439a077 TT |
1272 | bound = sbound; |
1273 | } | |
1274 | else | |
1275 | keep_going = 0; | |
1276 | continue; | |
1277 | } | |
1278 | else | |
1279 | { | |
1280 | QUIT; | |
1281 | ||
b5ec771e | 1282 | if ((domain == ALL_DOMAIN |
59c35742 AB |
1283 | || (domain == MODULES_DOMAIN |
1284 | && (*psym)->domain == MODULE_DOMAIN) | |
b5ec771e | 1285 | || (domain == VARIABLES_DOMAIN |
8a6d4234 TT |
1286 | && (*psym)->aclass != LOC_TYPEDEF |
1287 | && (*psym)->aclass != LOC_BLOCK) | |
b5ec771e | 1288 | || (domain == FUNCTIONS_DOMAIN |
8a6d4234 | 1289 | && (*psym)->aclass == LOC_BLOCK) |
b5ec771e | 1290 | || (domain == TYPES_DOMAIN |
8a6d4234 | 1291 | && (*psym)->aclass == LOC_TYPEDEF)) |
b5ec771e | 1292 | && psymbol_name_matches (*psym, lookup_name) |
af97b416 | 1293 | && (sym_matcher == NULL |
c9d95fa3 | 1294 | || sym_matcher ((*psym)->ginfo.search_name ()))) |
9439a077 TT |
1295 | { |
1296 | /* Found a match, so notify our caller. */ | |
1297 | result = PST_SEARCHED_AND_FOUND; | |
1298 | keep_going = 0; | |
1299 | } | |
1300 | } | |
1301 | psym++; | |
1302 | } | |
1303 | ||
1304 | ps->searched_flag = result; | |
1305 | return result == PST_SEARCHED_AND_FOUND; | |
1306 | } | |
1307 | ||
95cf5869 DE |
1308 | /* Psymtab version of expand_symtabs_matching. See its definition in |
1309 | the definition of quick_symbol_functions in symfile.h. */ | |
83827540 | 1310 | |
39298a5d TT |
1311 | void |
1312 | psymbol_functions::expand_symtabs_matching | |
f8eba3c6 | 1313 | (struct objfile *objfile, |
14bc53a8 | 1314 | gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher, |
c1a66c06 | 1315 | const lookup_name_info *lookup_name, |
14bc53a8 PA |
1316 | gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher, |
1317 | gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify, | |
b5ec771e | 1318 | enum search_domain domain) |
ccefe4c4 | 1319 | { |
9439a077 | 1320 | /* Clear the search flags. */ |
26abc753 | 1321 | for (partial_symtab *ps : require_partial_symbols (objfile, true)) |
b22a7c6a | 1322 | ps->searched_flag = PST_NOT_SEARCHED; |
ccefe4c4 | 1323 | |
f252c6d5 | 1324 | for (partial_symtab *ps : objfile->psymtabs ()) |
9439a077 | 1325 | { |
30b3dd9d DE |
1326 | QUIT; |
1327 | ||
5717c425 | 1328 | if (ps->readin_p (objfile)) |
ccefe4c4 TT |
1329 | continue; |
1330 | ||
9439a077 TT |
1331 | /* We skip shared psymtabs because file-matching doesn't apply |
1332 | to them; but we search them later in the loop. */ | |
1333 | if (ps->user != NULL) | |
ccefe4c4 TT |
1334 | continue; |
1335 | ||
b4c41fc7 DE |
1336 | if (file_matcher) |
1337 | { | |
14bc53a8 | 1338 | bool match; |
680d1742 | 1339 | |
b4c41fc7 DE |
1340 | if (ps->anonymous) |
1341 | continue; | |
fbd9ab74 | 1342 | |
14bc53a8 | 1343 | match = file_matcher (ps->filename, false); |
680d1742 DE |
1344 | if (!match) |
1345 | { | |
1346 | /* Before we invoke realpath, which can get expensive when many | |
1347 | files are involved, do a quick comparison of the basenames. */ | |
1348 | if (basenames_may_differ | |
14bc53a8 PA |
1349 | || file_matcher (lbasename (ps->filename), true)) |
1350 | match = file_matcher (psymtab_to_fullname (ps), false); | |
680d1742 DE |
1351 | } |
1352 | if (!match) | |
b4c41fc7 DE |
1353 | continue; |
1354 | } | |
ccefe4c4 | 1355 | |
c1a66c06 TV |
1356 | if ((symbol_matcher == NULL && lookup_name == NULL) |
1357 | || recursively_search_psymtabs (ps, objfile, domain, | |
1358 | lookup_name->make_ignore_params (), | |
1359 | symbol_matcher)) | |
276d885b GB |
1360 | { |
1361 | struct compunit_symtab *symtab = | |
1362 | psymtab_to_symtab (objfile, ps); | |
1363 | ||
1364 | if (expansion_notify != NULL) | |
14bc53a8 | 1365 | expansion_notify (symtab); |
276d885b | 1366 | } |
ccefe4c4 TT |
1367 | } |
1368 | } | |
1369 | ||
95cf5869 DE |
1370 | /* Psymtab version of has_symbols. See its definition in |
1371 | the definition of quick_symbol_functions in symfile.h. */ | |
83827540 | 1372 | |
39298a5d TT |
1373 | bool |
1374 | psymbol_functions::has_symbols (struct objfile *objfile) | |
ccefe4c4 | 1375 | { |
d320c2b5 | 1376 | return objfile->partial_symtabs->psymtabs != NULL; |
ccefe4c4 TT |
1377 | } |
1378 | ||
71a3c369 | 1379 | /* Helper function for psym_find_compunit_symtab_by_address that fills |
75336a5a | 1380 | in m_psymbol_map for a given range of psymbols. */ |
71a3c369 | 1381 | |
75336a5a TT |
1382 | void |
1383 | psymbol_functions::fill_psymbol_map | |
1384 | (struct objfile *objfile, | |
1385 | struct partial_symtab *psymtab, | |
1386 | std::set<CORE_ADDR> *seen_addrs, | |
1387 | const std::vector<partial_symbol *> &symbols) | |
71a3c369 | 1388 | { |
932539d7 | 1389 | for (partial_symbol *psym : symbols) |
71a3c369 | 1390 | { |
8a6d4234 | 1391 | if (psym->aclass == LOC_STATIC) |
71a3c369 | 1392 | { |
02e9e7f7 | 1393 | CORE_ADDR addr = psym->address (objfile); |
71a3c369 TT |
1394 | if (seen_addrs->find (addr) == seen_addrs->end ()) |
1395 | { | |
1396 | seen_addrs->insert (addr); | |
75336a5a | 1397 | m_psymbol_map.emplace_back (addr, psymtab); |
71a3c369 TT |
1398 | } |
1399 | } | |
1400 | } | |
1401 | } | |
1402 | ||
1403 | /* See find_compunit_symtab_by_address in quick_symbol_functions, in | |
1404 | symfile.h. */ | |
1405 | ||
39298a5d TT |
1406 | compunit_symtab * |
1407 | psymbol_functions::find_compunit_symtab_by_address (struct objfile *objfile, | |
1408 | CORE_ADDR address) | |
71a3c369 | 1409 | { |
75336a5a | 1410 | if (m_psymbol_map.empty ()) |
71a3c369 | 1411 | { |
71a3c369 TT |
1412 | std::set<CORE_ADDR> seen_addrs; |
1413 | ||
26abc753 | 1414 | for (partial_symtab *pst : require_partial_symbols (objfile, true)) |
b22a7c6a | 1415 | { |
75336a5a TT |
1416 | fill_psymbol_map (objfile, pst, |
1417 | &seen_addrs, | |
1418 | pst->global_psymbols); | |
1419 | fill_psymbol_map (objfile, pst, | |
1420 | &seen_addrs, | |
1421 | pst->static_psymbols); | |
b22a7c6a | 1422 | } |
71a3c369 | 1423 | |
75336a5a | 1424 | m_psymbol_map.shrink_to_fit (); |
71a3c369 | 1425 | |
75336a5a | 1426 | std::sort (m_psymbol_map.begin (), m_psymbol_map.end (), |
71a3c369 TT |
1427 | [] (const std::pair<CORE_ADDR, partial_symtab *> &a, |
1428 | const std::pair<CORE_ADDR, partial_symtab *> &b) | |
1429 | { | |
1430 | return a.first < b.first; | |
1431 | }); | |
1432 | } | |
1433 | ||
1434 | auto iter = std::lower_bound | |
75336a5a | 1435 | (m_psymbol_map.begin (), m_psymbol_map.end (), address, |
71a3c369 TT |
1436 | [] (const std::pair<CORE_ADDR, partial_symtab *> &a, |
1437 | CORE_ADDR b) | |
1438 | { | |
1439 | return a.first < b; | |
1440 | }); | |
1441 | ||
75336a5a | 1442 | if (iter == m_psymbol_map.end () || iter->first != address) |
71a3c369 TT |
1443 | return NULL; |
1444 | ||
1445 | return psymtab_to_symtab (objfile, iter->second); | |
1446 | } | |
1447 | ||
39298a5d TT |
1448 | quick_symbol_functions_up |
1449 | make_psymbol_functions () | |
ccefe4c4 | 1450 | { |
39298a5d TT |
1451 | return quick_symbol_functions_up (new psymbol_functions); |
1452 | } | |
ccefe4c4 TT |
1453 | |
1454 | \f | |
1455 | ||
c3693a1d TT |
1456 | /* Partially fill a partial symtab. It will be completely filled at |
1457 | the end of the symbol list. */ | |
ccefe4c4 | 1458 | |
c3693a1d TT |
1459 | partial_symtab::partial_symtab (const char *filename, |
1460 | struct objfile *objfile, | |
1461 | CORE_ADDR textlow) | |
1462 | : partial_symtab (filename, objfile) | |
ccefe4c4 | 1463 | { |
c3693a1d TT |
1464 | set_text_low (textlow); |
1465 | set_text_high (raw_text_low ()); /* default */ | |
ccefe4c4 TT |
1466 | } |
1467 | ||
8763cede DE |
1468 | /* Perform "finishing up" operations of a partial symtab. */ |
1469 | ||
1470 | void | |
ae7754b2 | 1471 | partial_symtab::end () |
8763cede | 1472 | { |
ae7754b2 TT |
1473 | global_psymbols.shrink_to_fit (); |
1474 | static_psymbols.shrink_to_fit (); | |
8763cede | 1475 | |
ae7754b2 TT |
1476 | /* Sort the global list; don't sort the static list. */ |
1477 | std::sort (global_psymbols.begin (), | |
1478 | global_psymbols.end (), | |
1479 | [] (partial_symbol *s1, partial_symbol *s2) | |
1480 | { | |
1481 | return strcmp_iw_ordered (s1->ginfo.search_name (), | |
1482 | s2->ginfo.search_name ()) < 0; | |
1483 | }); | |
8763cede DE |
1484 | } |
1485 | ||
89806626 | 1486 | /* See psymtab.h. */ |
cbd70537 | 1487 | |
89806626 SM |
1488 | unsigned long |
1489 | psymbol_bcache::hash (const void *addr, int length) | |
cbd70537 SW |
1490 | { |
1491 | unsigned long h = 0; | |
1492 | struct partial_symbol *psymbol = (struct partial_symbol *) addr; | |
c1b5c1eb | 1493 | unsigned int lang = psymbol->ginfo.language (); |
8a6d4234 TT |
1494 | unsigned int domain = psymbol->domain; |
1495 | unsigned int theclass = psymbol->aclass; | |
cbd70537 | 1496 | |
4cbd39b2 CB |
1497 | h = fast_hash (&psymbol->ginfo.value, sizeof (psymbol->ginfo.value), h); |
1498 | h = fast_hash (&lang, sizeof (unsigned int), h); | |
1499 | h = fast_hash (&domain, sizeof (unsigned int), h); | |
1500 | h = fast_hash (&theclass, sizeof (unsigned int), h); | |
4d4eaa30 | 1501 | /* Note that psymbol names are interned via compute_and_set_names, so |
e793c052 | 1502 | there's no need to hash the contents of the name here. */ |
4d4eaa30 | 1503 | h = fast_hash (&psymbol->ginfo.m_name, sizeof (psymbol->ginfo.m_name), h); |
cbd70537 SW |
1504 | |
1505 | return h; | |
1506 | } | |
1507 | ||
89806626 | 1508 | /* See psymtab.h. */ |
cbd70537 | 1509 | |
89806626 SM |
1510 | int |
1511 | psymbol_bcache::compare (const void *addr1, const void *addr2, int length) | |
cbd70537 SW |
1512 | { |
1513 | struct partial_symbol *sym1 = (struct partial_symbol *) addr1; | |
1514 | struct partial_symbol *sym2 = (struct partial_symbol *) addr2; | |
1515 | ||
af97b416 | 1516 | return (memcmp (&sym1->ginfo.value, &sym2->ginfo.value, |
dda83cd7 | 1517 | sizeof (sym1->ginfo.value)) == 0 |
c1b5c1eb | 1518 | && sym1->ginfo.language () == sym2->ginfo.language () |
dda83cd7 SM |
1519 | && sym1->domain == sym2->domain |
1520 | && sym1->aclass == sym2->aclass | |
e793c052 | 1521 | /* Note that psymbol names are interned via |
4d4eaa30 | 1522 | compute_and_set_names, so there's no need to compare the |
e793c052 | 1523 | contents of the name here. */ |
dda83cd7 | 1524 | && sym1->ginfo.linkage_name () == sym2->ginfo.linkage_name ()); |
cbd70537 SW |
1525 | } |
1526 | ||
95cf5869 | 1527 | /* Helper function, initialises partial symbol structure and stashes |
ccefe4c4 TT |
1528 | it into objfile's bcache. Note that our caching mechanism will |
1529 | use all fields of struct partial_symbol to determine hash value of the | |
1530 | structure. In other words, having two symbols with the same name but | |
1531 | different domain (or address) is possible and correct. */ | |
1532 | ||
af5bf4ad | 1533 | static struct partial_symbol * |
ef5e5b0b SM |
1534 | add_psymbol_to_bcache (const partial_symbol &psymbol, struct objfile *objfile, |
1535 | bool *added) | |
ccefe4c4 | 1536 | { |
0df8b418 | 1537 | /* Stash the partial symbol away in the cache. */ |
25629dfd TT |
1538 | return ((struct partial_symbol *) |
1539 | objfile->partial_symtabs->psymbol_cache.insert | |
1540 | (&psymbol, sizeof (struct partial_symbol), added)); | |
ccefe4c4 TT |
1541 | } |
1542 | ||
703a86c2 | 1543 | /* See psympriv.h. */ |
ccefe4c4 | 1544 | |
7dc25483 | 1545 | void |
932539d7 TT |
1546 | partial_symtab::add_psymbol (const partial_symbol &psymbol, |
1547 | psymbol_placement where, | |
1548 | struct objfile *objfile) | |
ccefe4c4 | 1549 | { |
ef5e5b0b | 1550 | bool added; |
ccefe4c4 | 1551 | |
0df8b418 | 1552 | /* Stash the partial symbol away in the cache. */ |
ef5e5b0b | 1553 | partial_symbol *psym = add_psymbol_to_bcache (psymbol, objfile, &added); |
ccefe4c4 TT |
1554 | |
1555 | /* Do not duplicate global partial symbols. */ | |
75aedd27 | 1556 | if (where == psymbol_placement::GLOBAL && !added) |
7dc25483 | 1557 | return; |
ccefe4c4 | 1558 | |
0df8b418 | 1559 | /* Save pointer to partial symbol in psymtab, growing symtab if needed. */ |
932539d7 | 1560 | std::vector<partial_symbol *> &list |
75aedd27 | 1561 | = (where == psymbol_placement::STATIC |
932539d7 TT |
1562 | ? static_psymbols |
1563 | : global_psymbols); | |
0684bb51 | 1564 | list.push_back (psym); |
ccefe4c4 TT |
1565 | } |
1566 | ||
6eee24ce | 1567 | /* See psympriv.h. */ |
ccefe4c4 | 1568 | |
2467f4f6 | 1569 | void |
932539d7 TT |
1570 | partial_symtab::add_psymbol (gdb::string_view name, bool copy_name, |
1571 | domain_enum domain, | |
1572 | enum address_class theclass, | |
1573 | short section, | |
1574 | psymbol_placement where, | |
1575 | CORE_ADDR coreaddr, | |
1576 | enum language language, struct objfile *objfile) | |
2467f4f6 TT |
1577 | { |
1578 | struct partial_symbol psymbol; | |
1579 | memset (&psymbol, 0, sizeof (psymbol)); | |
1580 | ||
1581 | psymbol.set_unrelocated_address (coreaddr); | |
a52d653e | 1582 | psymbol.ginfo.set_section_index (section); |
2467f4f6 TT |
1583 | psymbol.domain = domain; |
1584 | psymbol.aclass = theclass; | |
1585 | psymbol.ginfo.set_language (language, objfile->partial_symtabs->obstack ()); | |
1586 | psymbol.ginfo.compute_and_set_names (name, copy_name, objfile->per_bfd); | |
1587 | ||
932539d7 | 1588 | add_psymbol (psymbol, where, objfile); |
2467f4f6 TT |
1589 | } |
1590 | ||
1591 | /* See psympriv.h. */ | |
1592 | ||
32caafd0 TT |
1593 | partial_symtab::partial_symtab (const char *filename_, struct objfile *objfile) |
1594 | : searched_flag (PST_NOT_SEARCHED), | |
1595 | text_low_valid (0), | |
1596 | text_high_valid (0) | |
ccefe4c4 | 1597 | { |
32caafd0 | 1598 | objfile->partial_symtabs->install_psymtab (this); |
ccefe4c4 | 1599 | |
be1e3d3e | 1600 | filename = objfile->intern (filename_); |
ccefe4c4 | 1601 | |
45cfd468 DE |
1602 | if (symtab_create_debug) |
1603 | { | |
1604 | /* Be a bit clever with debugging messages, and don't print objfile | |
1605 | every time, only when it changes. */ | |
1606 | static char *last_objfile_name = NULL; | |
1607 | ||
1608 | if (last_objfile_name == NULL | |
4262abfb | 1609 | || strcmp (last_objfile_name, objfile_name (objfile)) != 0) |
45cfd468 DE |
1610 | { |
1611 | xfree (last_objfile_name); | |
4262abfb | 1612 | last_objfile_name = xstrdup (objfile_name (objfile)); |
22068491 TT |
1613 | fprintf_filtered (gdb_stdlog, |
1614 | "Creating one or more psymtabs for objfile %s ...\n", | |
1615 | last_objfile_name); | |
45cfd468 | 1616 | } |
22068491 TT |
1617 | fprintf_filtered (gdb_stdlog, |
1618 | "Created psymtab %s for module %s.\n", | |
32caafd0 | 1619 | host_address_to_string (this), filename); |
45cfd468 | 1620 | } |
ccefe4c4 TT |
1621 | } |
1622 | ||
0494dbec TT |
1623 | /* See psympriv.h. */ |
1624 | ||
1625 | void | |
48993951 | 1626 | partial_symtab::expand_dependencies (struct objfile *objfile) |
0494dbec TT |
1627 | { |
1628 | for (int i = 0; i < number_of_dependencies; ++i) | |
1629 | { | |
5717c425 | 1630 | if (!dependencies[i]->readin_p (objfile) |
1eb73179 | 1631 | && dependencies[i]->user == NULL) |
0494dbec TT |
1632 | { |
1633 | /* Inform about additional files to be read in. */ | |
1634 | if (info_verbose) | |
1635 | { | |
1636 | fputs_filtered (" ", gdb_stdout); | |
1637 | wrap_here (""); | |
1638 | fputs_filtered ("and ", gdb_stdout); | |
1639 | wrap_here (""); | |
1640 | printf_filtered ("%s...", dependencies[i]->filename); | |
1641 | wrap_here (""); /* Flush output */ | |
1642 | gdb_flush (gdb_stdout); | |
1643 | } | |
1644 | dependencies[i]->expand_psymtab (objfile); | |
1645 | } | |
1646 | } | |
1647 | } | |
1648 | ||
1649 | ||
ccefe4c4 | 1650 | void |
d320c2b5 | 1651 | psymtab_storage::discard_psymtab (struct partial_symtab *pst) |
ccefe4c4 TT |
1652 | { |
1653 | struct partial_symtab **prev_pst; | |
1654 | ||
1655 | /* From dbxread.c: | |
1656 | Empty psymtabs happen as a result of header files which don't | |
1657 | have any symbols in them. There can be a lot of them. But this | |
1658 | check is wrong, in that a psymtab with N_SLINE entries but | |
1659 | nothing else is not empty, but we don't realize that. Fixing | |
1660 | that without slowing things down might be tricky. */ | |
1661 | ||
0df8b418 | 1662 | /* First, snip it out of the psymtab chain. */ |
ccefe4c4 | 1663 | |
d320c2b5 | 1664 | prev_pst = &psymtabs; |
ccefe4c4 TT |
1665 | while ((*prev_pst) != pst) |
1666 | prev_pst = &((*prev_pst)->next); | |
1667 | (*prev_pst) = pst->next; | |
6f17252b | 1668 | delete pst; |
ccefe4c4 TT |
1669 | } |
1670 | ||
ccefe4c4 TT |
1671 | \f |
1672 | ||
372405a5 DE |
1673 | /* We need to pass a couple of items to the addrmap_foreach function, |
1674 | so use a struct. */ | |
1675 | ||
1676 | struct dump_psymtab_addrmap_data | |
1677 | { | |
1678 | struct objfile *objfile; | |
1679 | struct partial_symtab *psymtab; | |
1680 | struct ui_file *outfile; | |
1681 | ||
1682 | /* Non-zero if the previously printed addrmap entry was for PSYMTAB. | |
1683 | If so, we want to print the next one as well (since the next addrmap | |
1684 | entry defines the end of the range). */ | |
1685 | int previous_matched; | |
1686 | }; | |
1687 | ||
1688 | /* Helper function for dump_psymtab_addrmap to print an addrmap entry. */ | |
1689 | ||
1690 | static int | |
1691 | dump_psymtab_addrmap_1 (void *datap, CORE_ADDR start_addr, void *obj) | |
1692 | { | |
709b5518 PA |
1693 | struct dump_psymtab_addrmap_data *data |
1694 | = (struct dump_psymtab_addrmap_data *) datap; | |
08feed99 | 1695 | struct gdbarch *gdbarch = data->objfile->arch (); |
709b5518 | 1696 | struct partial_symtab *addrmap_psymtab = (struct partial_symtab *) obj; |
372405a5 DE |
1697 | const char *psymtab_address_or_end = NULL; |
1698 | ||
1699 | QUIT; | |
1700 | ||
1701 | if (data->psymtab == NULL | |
1702 | || data->psymtab == addrmap_psymtab) | |
1703 | psymtab_address_or_end = host_address_to_string (addrmap_psymtab); | |
1704 | else if (data->previous_matched) | |
1705 | psymtab_address_or_end = "<ends here>"; | |
1706 | ||
1707 | if (data->psymtab == NULL | |
1708 | || data->psymtab == addrmap_psymtab | |
1709 | || data->previous_matched) | |
1710 | { | |
1711 | fprintf_filtered (data->outfile, " %s%s %s\n", | |
1712 | data->psymtab != NULL ? " " : "", | |
1713 | paddress (gdbarch, start_addr), | |
1714 | psymtab_address_or_end); | |
1715 | } | |
1716 | ||
1717 | data->previous_matched = (data->psymtab == NULL | |
1718 | || data->psymtab == addrmap_psymtab); | |
1719 | ||
1720 | return 0; | |
1721 | } | |
1722 | ||
1723 | /* Helper function for maintenance_print_psymbols to print the addrmap | |
1724 | of PSYMTAB. If PSYMTAB is NULL print the entire addrmap. */ | |
1725 | ||
1726 | static void | |
1727 | dump_psymtab_addrmap (struct objfile *objfile, struct partial_symtab *psymtab, | |
1728 | struct ui_file *outfile) | |
1729 | { | |
1730 | struct dump_psymtab_addrmap_data addrmap_dump_data; | |
1731 | ||
34c41c68 DE |
1732 | if ((psymtab == NULL |
1733 | || psymtab->psymtabs_addrmap_supported) | |
d320c2b5 | 1734 | && objfile->partial_symtabs->psymtabs_addrmap != NULL) |
372405a5 DE |
1735 | { |
1736 | addrmap_dump_data.objfile = objfile; | |
1737 | addrmap_dump_data.psymtab = psymtab; | |
1738 | addrmap_dump_data.outfile = outfile; | |
1739 | addrmap_dump_data.previous_matched = 0; | |
1740 | fprintf_filtered (outfile, "%sddress map:\n", | |
1741 | psymtab == NULL ? "Entire a" : " A"); | |
d320c2b5 TT |
1742 | addrmap_foreach (objfile->partial_symtabs->psymtabs_addrmap, |
1743 | dump_psymtab_addrmap_1, &addrmap_dump_data); | |
372405a5 DE |
1744 | } |
1745 | } | |
1746 | ||
dfc7bb5b | 1747 | static void |
990b9f9f | 1748 | maintenance_print_psymbols (const char *args, int from_tty) |
ccefe4c4 | 1749 | { |
34c41c68 | 1750 | struct ui_file *outfile = gdb_stdout; |
34c41c68 | 1751 | char *address_arg = NULL, *source_arg = NULL, *objfile_arg = NULL; |
34c41c68 DE |
1752 | int i, outfile_idx, found; |
1753 | CORE_ADDR pc = 0; | |
1754 | struct obj_section *section = NULL; | |
ccefe4c4 TT |
1755 | |
1756 | dont_repeat (); | |
1757 | ||
773a1edc | 1758 | gdb_argv argv (args); |
ccefe4c4 | 1759 | |
99e8a4f9 | 1760 | for (i = 0; argv != NULL && argv[i] != NULL; ++i) |
ccefe4c4 | 1761 | { |
34c41c68 DE |
1762 | if (strcmp (argv[i], "-pc") == 0) |
1763 | { | |
1764 | if (argv[i + 1] == NULL) | |
1765 | error (_("Missing pc value")); | |
1766 | address_arg = argv[++i]; | |
1767 | } | |
1768 | else if (strcmp (argv[i], "-source") == 0) | |
1769 | { | |
1770 | if (argv[i + 1] == NULL) | |
1771 | error (_("Missing source file")); | |
1772 | source_arg = argv[++i]; | |
1773 | } | |
1774 | else if (strcmp (argv[i], "-objfile") == 0) | |
1775 | { | |
1776 | if (argv[i + 1] == NULL) | |
1777 | error (_("Missing objfile name")); | |
1778 | objfile_arg = argv[++i]; | |
1779 | } | |
1780 | else if (strcmp (argv[i], "--") == 0) | |
1781 | { | |
1782 | /* End of options. */ | |
1783 | ++i; | |
1784 | break; | |
1785 | } | |
1786 | else if (argv[i][0] == '-') | |
ccefe4c4 | 1787 | { |
34c41c68 DE |
1788 | /* Future proofing: Don't allow OUTFILE to begin with "-". */ |
1789 | error (_("Unknown option: %s"), argv[i]); | |
ccefe4c4 | 1790 | } |
34c41c68 DE |
1791 | else |
1792 | break; | |
ccefe4c4 | 1793 | } |
34c41c68 | 1794 | outfile_idx = i; |
ccefe4c4 | 1795 | |
34c41c68 DE |
1796 | if (address_arg != NULL && source_arg != NULL) |
1797 | error (_("Must specify at most one of -pc and -source")); | |
ccefe4c4 | 1798 | |
d7e74731 PA |
1799 | stdio_file arg_outfile; |
1800 | ||
99e8a4f9 | 1801 | if (argv != NULL && argv[outfile_idx] != NULL) |
34c41c68 | 1802 | { |
34c41c68 DE |
1803 | if (argv[outfile_idx + 1] != NULL) |
1804 | error (_("Junk at end of command")); | |
ee0c3293 TT |
1805 | gdb::unique_xmalloc_ptr<char> outfile_name |
1806 | (tilde_expand (argv[outfile_idx])); | |
1807 | if (!arg_outfile.open (outfile_name.get (), FOPEN_WT)) | |
1808 | perror_with_name (outfile_name.get ()); | |
d7e74731 | 1809 | outfile = &arg_outfile; |
34c41c68 | 1810 | } |
ccefe4c4 | 1811 | |
34c41c68 DE |
1812 | if (address_arg != NULL) |
1813 | { | |
1814 | pc = parse_and_eval_address (address_arg); | |
1815 | /* If we fail to find a section, that's ok, try the lookup anyway. */ | |
1816 | section = find_pc_section (pc); | |
1817 | } | |
372405a5 | 1818 | |
34c41c68 | 1819 | found = 0; |
2030c079 | 1820 | for (objfile *objfile : current_program_space->objfiles ()) |
27618ce4 | 1821 | { |
34c41c68 DE |
1822 | int printed_objfile_header = 0; |
1823 | int print_for_objfile = 1; | |
1824 | ||
27618ce4 | 1825 | QUIT; |
34c41c68 DE |
1826 | if (objfile_arg != NULL) |
1827 | print_for_objfile | |
1828 | = compare_filenames_for_search (objfile_name (objfile), | |
1829 | objfile_arg); | |
1830 | if (!print_for_objfile) | |
1831 | continue; | |
1832 | ||
1833 | if (address_arg != NULL) | |
1834 | { | |
1835 | struct bound_minimal_symbol msymbol = { NULL, NULL }; | |
1836 | ||
1837 | /* We don't assume each pc has a unique objfile (this is for | |
1838 | debugging). */ | |
b22a7c6a TT |
1839 | struct partial_symtab *ps = find_pc_sect_psymtab (objfile, pc, |
1840 | section, msymbol); | |
34c41c68 DE |
1841 | if (ps != NULL) |
1842 | { | |
1843 | if (!printed_objfile_header) | |
1844 | { | |
d7e74731 PA |
1845 | outfile->printf ("\nPartial symtabs for objfile %s\n", |
1846 | objfile_name (objfile)); | |
34c41c68 DE |
1847 | printed_objfile_header = 1; |
1848 | } | |
1849 | dump_psymtab (objfile, ps, outfile); | |
1850 | dump_psymtab_addrmap (objfile, ps, outfile); | |
1851 | found = 1; | |
1852 | } | |
1853 | } | |
1854 | else | |
1855 | { | |
26abc753 | 1856 | for (partial_symtab *ps : require_partial_symbols (objfile, true)) |
34c41c68 DE |
1857 | { |
1858 | int print_for_source = 0; | |
1859 | ||
1860 | QUIT; | |
1861 | if (source_arg != NULL) | |
1862 | { | |
1863 | print_for_source | |
1864 | = compare_filenames_for_search (ps->filename, source_arg); | |
1865 | found = 1; | |
1866 | } | |
1867 | if (source_arg == NULL | |
1868 | || print_for_source) | |
1869 | { | |
1870 | if (!printed_objfile_header) | |
1871 | { | |
d7e74731 PA |
1872 | outfile->printf ("\nPartial symtabs for objfile %s\n", |
1873 | objfile_name (objfile)); | |
34c41c68 DE |
1874 | printed_objfile_header = 1; |
1875 | } | |
1876 | dump_psymtab (objfile, ps, outfile); | |
1877 | dump_psymtab_addrmap (objfile, ps, outfile); | |
1878 | } | |
1879 | } | |
1880 | } | |
1881 | ||
1882 | /* If we're printing all the objfile's symbols dump the full addrmap. */ | |
1883 | ||
1884 | if (address_arg == NULL | |
1885 | && source_arg == NULL | |
d320c2b5 | 1886 | && objfile->partial_symtabs->psymtabs_addrmap != NULL) |
372405a5 | 1887 | { |
d7e74731 | 1888 | outfile->puts ("\n"); |
34c41c68 | 1889 | dump_psymtab_addrmap (objfile, NULL, outfile); |
372405a5 | 1890 | } |
27618ce4 | 1891 | } |
372405a5 | 1892 | |
34c41c68 DE |
1893 | if (!found) |
1894 | { | |
1895 | if (address_arg != NULL) | |
1896 | error (_("No partial symtab for address: %s"), address_arg); | |
1897 | if (source_arg != NULL) | |
1898 | error (_("No partial symtab for source file: %s"), source_arg); | |
1899 | } | |
ccefe4c4 TT |
1900 | } |
1901 | ||
1902 | /* List all the partial symbol tables whose names match REGEXP (optional). */ | |
95cf5869 | 1903 | |
dfc7bb5b | 1904 | static void |
990b9f9f | 1905 | maintenance_info_psymtabs (const char *regexp, int from_tty) |
ccefe4c4 | 1906 | { |
ccefe4c4 TT |
1907 | if (regexp) |
1908 | re_comp (regexp); | |
1909 | ||
94c93c35 | 1910 | for (struct program_space *pspace : program_spaces) |
2030c079 | 1911 | for (objfile *objfile : pspace->objfiles ()) |
99d89cde | 1912 | { |
08feed99 | 1913 | struct gdbarch *gdbarch = objfile->arch (); |
ccefe4c4 | 1914 | |
99d89cde TT |
1915 | /* We don't want to print anything for this objfile until we |
1916 | actually find a symtab whose name matches. */ | |
1917 | int printed_objfile_start = 0; | |
ccefe4c4 | 1918 | |
26abc753 | 1919 | for (partial_symtab *psymtab : require_partial_symbols (objfile, true)) |
99d89cde TT |
1920 | { |
1921 | QUIT; | |
1922 | ||
1923 | if (! regexp | |
1924 | || re_exec (psymtab->filename)) | |
1925 | { | |
1926 | if (! printed_objfile_start) | |
1927 | { | |
1928 | printf_filtered ("{ objfile %s ", objfile_name (objfile)); | |
1929 | wrap_here (" "); | |
1930 | printf_filtered ("((struct objfile *) %s)\n", | |
1931 | host_address_to_string (objfile)); | |
1932 | printed_objfile_start = 1; | |
1933 | } | |
1934 | ||
1935 | printf_filtered (" { psymtab %s ", psymtab->filename); | |
1936 | wrap_here (" "); | |
1937 | printf_filtered ("((struct partial_symtab *) %s)\n", | |
1938 | host_address_to_string (psymtab)); | |
1939 | ||
1940 | printf_filtered (" readin %s\n", | |
5717c425 | 1941 | psymtab->readin_p (objfile) ? "yes" : "no"); |
99d89cde TT |
1942 | printf_filtered (" fullname %s\n", |
1943 | psymtab->fullname | |
1944 | ? psymtab->fullname : "(null)"); | |
1945 | printf_filtered (" text addresses "); | |
1946 | fputs_filtered (paddress (gdbarch, | |
1947 | psymtab->text_low (objfile)), | |
1948 | gdb_stdout); | |
1949 | printf_filtered (" -- "); | |
1950 | fputs_filtered (paddress (gdbarch, | |
1951 | psymtab->text_high (objfile)), | |
1952 | gdb_stdout); | |
1953 | printf_filtered ("\n"); | |
1954 | printf_filtered (" psymtabs_addrmap_supported %s\n", | |
1955 | (psymtab->psymtabs_addrmap_supported | |
1956 | ? "yes" : "no")); | |
1957 | printf_filtered (" globals "); | |
932539d7 TT |
1958 | if (!psymtab->global_psymbols.empty ()) |
1959 | printf_filtered | |
1960 | ("(* (struct partial_symbol **) %s @ %d)\n", | |
1961 | host_address_to_string (psymtab->global_psymbols.data ()), | |
1962 | (int) psymtab->global_psymbols.size ()); | |
99d89cde TT |
1963 | else |
1964 | printf_filtered ("(none)\n"); | |
1965 | printf_filtered (" statics "); | |
932539d7 TT |
1966 | if (!psymtab->static_psymbols.empty ()) |
1967 | printf_filtered | |
1968 | ("(* (struct partial_symbol **) %s @ %d)\n", | |
1969 | host_address_to_string (psymtab->static_psymbols.data ()), | |
1970 | (int) psymtab->static_psymbols.size ()); | |
99d89cde TT |
1971 | else |
1972 | printf_filtered ("(none)\n"); | |
a64fafb5 TV |
1973 | if (psymtab->user) |
1974 | printf_filtered (" user %s " | |
1975 | "((struct partial_symtab *) %s)\n", | |
1976 | psymtab->user->filename, | |
1977 | host_address_to_string (psymtab->user)); | |
99d89cde TT |
1978 | printf_filtered (" dependencies "); |
1979 | if (psymtab->number_of_dependencies) | |
1980 | { | |
1981 | int i; | |
1982 | ||
1983 | printf_filtered ("{\n"); | |
1984 | for (i = 0; i < psymtab->number_of_dependencies; i++) | |
1985 | { | |
1986 | struct partial_symtab *dep = psymtab->dependencies[i]; | |
1987 | ||
1988 | /* Note the string concatenation there --- no | |
1989 | comma. */ | |
1990 | printf_filtered (" psymtab %s " | |
1991 | "((struct partial_symtab *) %s)\n", | |
1992 | dep->filename, | |
1993 | host_address_to_string (dep)); | |
1994 | } | |
1995 | printf_filtered (" }\n"); | |
1996 | } | |
1997 | else | |
1998 | printf_filtered ("(none)\n"); | |
1999 | printf_filtered (" }\n"); | |
2000 | } | |
2001 | } | |
ccefe4c4 | 2002 | |
99d89cde TT |
2003 | if (printed_objfile_start) |
2004 | printf_filtered ("}\n"); | |
2005 | } | |
ccefe4c4 TT |
2006 | } |
2007 | ||
7d0c9981 | 2008 | /* Check consistency of currently expanded psymtabs vs symtabs. */ |
ccefe4c4 | 2009 | |
dfc7bb5b | 2010 | static void |
990b9f9f | 2011 | maintenance_check_psymtabs (const char *ignore, int from_tty) |
ccefe4c4 TT |
2012 | { |
2013 | struct symbol *sym; | |
43f3e411 | 2014 | struct compunit_symtab *cust = NULL; |
346d1dfe | 2015 | const struct blockvector *bv; |
582942f4 | 2016 | const struct block *b; |
ccefe4c4 | 2017 | |
2030c079 | 2018 | for (objfile *objfile : current_program_space->objfiles ()) |
26abc753 | 2019 | for (partial_symtab *ps : require_partial_symbols (objfile, true)) |
7d0c9981 | 2020 | { |
08feed99 | 2021 | struct gdbarch *gdbarch = objfile->arch (); |
7d0c9981 | 2022 | |
aed57c53 TT |
2023 | /* We don't call psymtab_to_symtab here because that may cause symtab |
2024 | expansion. When debugging a problem it helps if checkers leave | |
2025 | things unchanged. */ | |
5717c425 | 2026 | cust = ps->get_compunit_symtab (objfile); |
aed57c53 TT |
2027 | |
2028 | /* First do some checks that don't require the associated symtab. */ | |
2029 | if (ps->text_high (objfile) < ps->text_low (objfile)) | |
ccefe4c4 | 2030 | { |
aed57c53 | 2031 | printf_filtered ("Psymtab "); |
ccefe4c4 | 2032 | puts_filtered (ps->filename); |
aed57c53 TT |
2033 | printf_filtered (" covers bad range "); |
2034 | fputs_filtered (paddress (gdbarch, ps->text_low (objfile)), | |
2035 | gdb_stdout); | |
2036 | printf_filtered (" - "); | |
2037 | fputs_filtered (paddress (gdbarch, ps->text_high (objfile)), | |
2038 | gdb_stdout); | |
2039 | printf_filtered ("\n"); | |
2040 | continue; | |
ccefe4c4 | 2041 | } |
aed57c53 TT |
2042 | |
2043 | /* Now do checks requiring the associated symtab. */ | |
2044 | if (cust == NULL) | |
2045 | continue; | |
2046 | bv = COMPUNIT_BLOCKVECTOR (cust); | |
2047 | b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
932539d7 | 2048 | for (partial_symbol *psym : ps->static_psymbols) |
aed57c53 | 2049 | { |
5707e24b TV |
2050 | /* Skip symbols for inlined functions without address. These may |
2051 | or may not have a match in the full symtab. */ | |
932539d7 TT |
2052 | if (psym->aclass == LOC_BLOCK |
2053 | && psym->ginfo.value.address == 0) | |
5707e24b TV |
2054 | continue; |
2055 | ||
932539d7 | 2056 | sym = block_lookup_symbol (b, psym->ginfo.search_name (), |
aed57c53 | 2057 | symbol_name_match_type::SEARCH_NAME, |
932539d7 | 2058 | psym->domain); |
aed57c53 TT |
2059 | if (!sym) |
2060 | { | |
2061 | printf_filtered ("Static symbol `"); | |
932539d7 | 2062 | puts_filtered (psym->ginfo.linkage_name ()); |
aed57c53 TT |
2063 | printf_filtered ("' only found in "); |
2064 | puts_filtered (ps->filename); | |
2065 | printf_filtered (" psymtab\n"); | |
2066 | } | |
aed57c53 TT |
2067 | } |
2068 | b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
932539d7 | 2069 | for (partial_symbol *psym : ps->global_psymbols) |
ccefe4c4 | 2070 | { |
932539d7 | 2071 | sym = block_lookup_symbol (b, psym->ginfo.search_name (), |
aed57c53 | 2072 | symbol_name_match_type::SEARCH_NAME, |
932539d7 | 2073 | psym->domain); |
aed57c53 TT |
2074 | if (!sym) |
2075 | { | |
2076 | printf_filtered ("Global symbol `"); | |
932539d7 | 2077 | puts_filtered (psym->ginfo.linkage_name ()); |
aed57c53 TT |
2078 | printf_filtered ("' only found in "); |
2079 | puts_filtered (ps->filename); | |
2080 | printf_filtered (" psymtab\n"); | |
2081 | } | |
aed57c53 TT |
2082 | } |
2083 | if (ps->raw_text_high () != 0 | |
2084 | && (ps->text_low (objfile) < BLOCK_START (b) | |
2085 | || ps->text_high (objfile) > BLOCK_END (b))) | |
2086 | { | |
2087 | printf_filtered ("Psymtab "); | |
ccefe4c4 | 2088 | puts_filtered (ps->filename); |
aed57c53 TT |
2089 | printf_filtered (" covers "); |
2090 | fputs_filtered (paddress (gdbarch, ps->text_low (objfile)), | |
2091 | gdb_stdout); | |
2092 | printf_filtered (" - "); | |
2093 | fputs_filtered (paddress (gdbarch, ps->text_high (objfile)), | |
2094 | gdb_stdout); | |
2095 | printf_filtered (" but symtab covers only "); | |
2096 | fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout); | |
2097 | printf_filtered (" - "); | |
2098 | fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout); | |
2099 | printf_filtered ("\n"); | |
ccefe4c4 | 2100 | } |
ccefe4c4 | 2101 | } |
ccefe4c4 TT |
2102 | } |
2103 | ||
6c265988 | 2104 | void _initialize_psymtab (); |
dfc7bb5b | 2105 | void |
6c265988 | 2106 | _initialize_psymtab () |
dfc7bb5b YQ |
2107 | { |
2108 | add_cmd ("psymbols", class_maintenance, maintenance_print_psymbols, _("\ | |
2109 | Print dump of current partial symbol definitions.\n\ | |
48c5e7e2 TT |
2110 | Usage: mt print psymbols [-objfile OBJFILE] [-pc ADDRESS] [--] [OUTFILE]\n\ |
2111 | mt print psymbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\ | |
34c41c68 DE |
2112 | Entries in the partial symbol table are dumped to file OUTFILE,\n\ |
2113 | or the terminal if OUTFILE is unspecified.\n\ | |
2114 | If ADDRESS is provided, dump only the file for that address.\n\ | |
2115 | If SOURCE is provided, dump only that file's symbols.\n\ | |
2116 | If OBJFILE is provided, dump only that file's minimal symbols."), | |
dfc7bb5b YQ |
2117 | &maintenanceprintlist); |
2118 | ||
2119 | add_cmd ("psymtabs", class_maintenance, maintenance_info_psymtabs, _("\ | |
2120 | List the partial symbol tables for all object files.\n\ | |
2121 | This does not include information about individual partial symbols,\n\ | |
2122 | just the symbol table structures themselves."), | |
2123 | &maintenanceinfolist); | |
2124 | ||
7d0c9981 DE |
2125 | add_cmd ("check-psymtabs", class_maintenance, maintenance_check_psymtabs, |
2126 | _("\ | |
2127 | Check consistency of currently expanded psymtabs versus symtabs."), | |
dfc7bb5b YQ |
2128 | &maintenancelist); |
2129 | } |