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