]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/psymtab.c
Move psymtab statistics printing to psymtab.c
[thirdparty/binutils-gdb.git] / gdb / psymtab.c
1 /* Partial symbol tables.
2
3 Copyright (C) 2009-2021 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 != nullptr
88 && objfile->sf->sym_read_psymbols)
89 {
90 if (verbose)
91 printf_filtered (_("Reading symbols from %s...\n"),
92 objfile_name (objfile));
93 (*objfile->sf->sym_read_psymbols) (objfile);
94
95 if (verbose && !objfile_has_symbols (objfile))
96 printf_filtered (_("(No debugging symbols found in %s)\n"),
97 objfile_name (objfile));
98 }
99 }
100
101 return objfile->psymtabs ();
102 }
103
104 /* Helper function for psym_map_symtabs_matching_filename that
105 expands the symtabs and calls the iterator. */
106
107 static bool
108 partial_map_expand_apply (struct objfile *objfile,
109 const char *name,
110 const char *real_path,
111 struct partial_symtab *pst,
112 gdb::function_view<bool (symtab *)> callback)
113 {
114 struct compunit_symtab *last_made = objfile->compunit_symtabs;
115
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
120 /* Don't visit already-expanded psymtabs. */
121 if (pst->readin_p (objfile))
122 return 0;
123
124 /* This may expand more than one symtab, and we want to iterate over
125 all of them. */
126 psymtab_to_symtab (objfile, pst);
127
128 return iterate_over_some_symtabs (name, real_path, objfile->compunit_symtabs,
129 last_made, callback);
130 }
131
132 /* Psymtab version of map_symtabs_matching_filename. See its definition in
133 the definition of quick_symbol_functions in symfile.h. */
134
135 bool
136 psymbol_functions::map_symtabs_matching_filename
137 (struct objfile *objfile,
138 const char *name,
139 const char *real_path,
140 gdb::function_view<bool (symtab *)> callback)
141 {
142 const char *name_basename = lbasename (name);
143
144 for (partial_symtab *pst : require_partial_symbols (objfile, true))
145 {
146 /* Anonymous psymtabs don't have a file name. */
147 if (pst->anonymous)
148 continue;
149
150 if (compare_filenames_for_search (pst->filename, name))
151 {
152 while (pst->user)
153 pst = pst->user;
154
155 if (partial_map_expand_apply (objfile, name, real_path,
156 pst, callback))
157 return true;
158 continue;
159 }
160
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)
165 continue;
166
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 }
190
191 return false;
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 *
198 find_pc_sect_psymtab_closer (struct objfile *objfile,
199 CORE_ADDR pc, struct obj_section *section,
200 struct partial_symtab *pst,
201 struct bound_minimal_symbol msymbol)
202 {
203 struct partial_symtab *tpst;
204 struct partial_symtab *best_pst = pst;
205 CORE_ADDR best_addr = pst->text_low (objfile);
206
207 gdb_assert (!pst->psymtabs_addrmap_supported);
208
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. */
213 if (!(objfile->flags & OBJF_REORDERED)
214 && section == NULL) /* Can't validate section this way. */
215 return pst;
216
217 if (msymbol.minsym == NULL)
218 return pst;
219
220 /* The code range of partial symtabs sometimes overlap, so, in
221 the loop below, we need to check all partial symtabs and
222 find the one that fits better for the given PC address. We
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 {
229 if (pc >= tpst->text_low (objfile) && pc < tpst->text_high (objfile))
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. */
238 p = find_pc_sect_psymbol (objfile, tpst, pc, section);
239 if (p != NULL
240 && (p->address (objfile) == BMSYMBOL_VALUE_ADDRESS (msymbol)))
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)
248 this_addr = p->address (objfile);
249 else
250 this_addr = tpst->text_low (objfile);
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
257 best match symbol. This can help in cases where the
258 symbol information/debuginfo is not complete, like
259 for instance on IRIX6 with gcc, where no debug info
260 is emitted for statics. (See also the nodebug.exp
261 testcase.) */
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
272 /* Find which partial symtab contains PC and SECTION. Return NULL if
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. */
276
277 static struct partial_symtab *
278 find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
279 struct obj_section *section,
280 struct bound_minimal_symbol msymbol)
281 {
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)
296 {
297 CORE_ADDR baseaddr = objfile->text_section_offset ();
298
299 struct partial_symtab *pst
300 = ((struct partial_symtab *)
301 addrmap_find (objfile->partial_symtabs->psymtabs_addrmap,
302 pc - baseaddr));
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. */
308 if (overlay_debugging && msymbol.minsym != NULL && section != NULL)
309 {
310 struct partial_symbol *p;
311
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. */
316 p = find_pc_sect_psymbol (objfile, pst, pc, section);
317 if (p == NULL
318 || (p->address (objfile)
319 != BMSYMBOL_VALUE_ADDRESS (msymbol)))
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
344 for (partial_symtab *pst : require_partial_symbols (objfile, true))
345 if (!pst->psymtabs_addrmap_supported
346 && pc >= pst->text_low (objfile) && pc < pst->text_high (objfile))
347 {
348 struct partial_symtab *best_pst;
349
350 best_pst = find_pc_sect_psymtab_closer (objfile, pc, section, pst,
351 msymbol);
352 if (best_pst != NULL)
353 return best_pst;
354 }
355
356 return NULL;
357 }
358
359 /* Psymtab version of find_pc_sect_compunit_symtab. See its definition in
360 the definition of quick_symbol_functions in symfile.h. */
361
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)
369 {
370 struct partial_symtab *ps = find_pc_sect_psymtab (objfile, pc, section,
371 msymbol);
372 if (ps != NULL)
373 {
374 if (warn_if_readin && ps->readin_p (objfile))
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"),
380 paddress (objfile->arch (), pc));
381 psymtab_to_symtab (objfile, ps);
382 return ps->get_compunit_symtab (objfile);
383 }
384 return NULL;
385 }
386
387 /* Find which partial symbol within a psymtab matches PC and SECTION.
388 Return NULL if none. */
389
390 static struct partial_symbol *
391 find_pc_sect_psymbol (struct objfile *objfile,
392 struct partial_symtab *psymtab, CORE_ADDR pc,
393 struct obj_section *section)
394 {
395 struct partial_symbol *best = NULL;
396 CORE_ADDR best_pc;
397 const CORE_ADDR textlow = psymtab->text_low (objfile);
398
399 gdb_assert (psymtab != NULL);
400
401 /* Cope with programs that start at address 0. */
402 best_pc = (textlow != 0) ? textlow - 1 : 0;
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. */
407 for (partial_symbol *p : psymtab->global_psymbols)
408 {
409 if (p->domain == VAR_DOMAIN
410 && p->aclass == LOC_BLOCK
411 && pc >= p->address (objfile)
412 && (p->address (objfile) > best_pc
413 || (psymtab->text_low (objfile) == 0
414 && best_pc == 0 && p->address (objfile) == 0)))
415 {
416 if (section != NULL) /* Match on a specific section. */
417 {
418 if (!matching_obj_sections (p->obj_section (objfile),
419 section))
420 continue;
421 }
422 best_pc = p->address (objfile);
423 best = p;
424 }
425 }
426
427 for (partial_symbol *p : psymtab->static_psymbols)
428 {
429 if (p->domain == VAR_DOMAIN
430 && p->aclass == LOC_BLOCK
431 && pc >= p->address (objfile)
432 && (p->address (objfile) > best_pc
433 || (psymtab->text_low (objfile) == 0
434 && best_pc == 0 && p->address (objfile) == 0)))
435 {
436 if (section != NULL) /* Match on a specific section. */
437 {
438 if (!matching_obj_sections (p->obj_section (objfile),
439 section))
440 continue;
441 }
442 best_pc = p->address (objfile);
443 best = p;
444 }
445 }
446
447 return best;
448 }
449
450 /* Psymtab version of lookup_symbol. See its definition in
451 the definition of quick_symbol_functions in symfile.h. */
452
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)
457 {
458 const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
459 struct compunit_symtab *stab_best = NULL;
460
461 lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
462
463 lookup_name_info psym_lookup_name = lookup_name.make_ignore_params ();
464
465 for (partial_symtab *ps : require_partial_symbols (objfile, true))
466 {
467 if (!ps->readin_p (objfile)
468 && lookup_partial_symbol (objfile, ps, psym_lookup_name,
469 psymtab_index, domain))
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);
477 const struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
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 }
497
498 return stab_best;
499 }
500
501 /* Psymtab version of lookup_global_symbol_language. See its definition in
502 the definition of quick_symbol_functions in symfile.h. */
503
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)
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;
519 if (ps->readin_p (objfile))
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
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 {
539 const language_defn *lang = language_def (psym->ginfo.language ());
540 symbol_name_matcher_ftype *name_match
541 = lang->get_symbol_name_matcher (lookup_name);
542 return name_match (psym->ginfo.search_name (), lookup_name, NULL);
543 }
544
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 *
554 match_partial_symbol (struct objfile *objfile,
555 struct partial_symtab *pst, int global,
556 const lookup_name_info &name, domain_enum domain,
557 symbol_compare_ftype *ordered_compare)
558 {
559 struct partial_symbol **start, **psym;
560 struct partial_symbol **top, **real_top, **bottom, **center;
561 int length = (global
562 ? pst->global_psymbols.size ()
563 : pst->static_psymbols.size ());
564 int do_linear_search = 1;
565
566 if (length == 0)
567 return NULL;
568
569 start = (global ?
570 &pst->global_psymbols[0] :
571 &pst->static_psymbols[0]);
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
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. */
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);
590
591 enum language lang = (*center)->ginfo.language ();
592 const char *lang_ln = name.language_lookup_name (lang);
593
594 if (ordered_compare ((*center)->ginfo.search_name (),
595 lang_ln) >= 0)
596 top = center;
597 else
598 bottom = center + 1;
599 }
600 gdb_assert (top == bottom);
601
602 while (top <= real_top
603 && psymbol_name_matches (*top, name))
604 {
605 if (symbol_matches_domain ((*top)->ginfo.language (),
606 (*top)->domain, domain))
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 {
619 if (symbol_matches_domain ((*psym)->ginfo.language (),
620 (*psym)->domain, domain)
621 && psymbol_name_matches (*psym, name))
622 return *psym;
623 }
624 }
625
626 return NULL;
627 }
628
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. */
632
633 static struct partial_symbol *
634 lookup_partial_symbol (struct objfile *objfile,
635 struct partial_symtab *pst,
636 const lookup_name_info &lookup_name,
637 int global, domain_enum domain)
638 {
639 struct partial_symbol **start, **psym;
640 struct partial_symbol **top, **real_top, **bottom, **center;
641 int length = (global
642 ? pst->global_psymbols.size ()
643 : pst->static_psymbols.size ());
644 int do_linear_search = 1;
645
646 if (length == 0)
647 return NULL;
648
649 start = (global ?
650 &pst->global_psymbols[0] :
651 &pst->static_psymbols[0]);
652
653 if (global) /* This means we can use a binary search. */
654 {
655 do_linear_search = 0;
656
657 /* Binary search. This search is guaranteed to end with center
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. */
662
663 bottom = start;
664 top = start + length - 1;
665 real_top = top;
666 while (top > bottom)
667 {
668 center = bottom + (top - bottom) / 2;
669
670 gdb_assert (center < top);
671
672 if (strcmp_iw_ordered ((*center)->ginfo.search_name (),
673 lookup_name.c_str ()) >= 0)
674 {
675 top = center;
676 }
677 else
678 {
679 bottom = center + 1;
680 }
681 }
682
683 gdb_assert (top == bottom);
684
685 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
686 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
687 while (top >= start && symbol_matches_search_name (&(*top)->ginfo,
688 lookup_name))
689 top--;
690
691 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
692 top++;
693
694 while (top <= real_top && symbol_matches_search_name (&(*top)->ginfo,
695 lookup_name))
696 {
697 if (symbol_matches_domain ((*top)->ginfo.language (),
698 (*top)->domain, domain))
699 return *top;
700 top++;
701 }
702 }
703
704 /* Can't use a binary search or else we found during the binary search that
705 we should also do a linear search. */
706
707 if (do_linear_search)
708 {
709 for (psym = start; psym < start + length; psym++)
710 {
711 if (symbol_matches_domain ((*psym)->ginfo.language (),
712 (*psym)->domain, domain)
713 && symbol_matches_search_name (&(*psym)->ginfo, lookup_name))
714 return *psym;
715 }
716 }
717
718 return NULL;
719 }
720
721 /* Get the symbol table that corresponds to a partial_symtab.
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. */
726
727 static struct compunit_symtab *
728 psymtab_to_symtab (struct objfile *objfile, struct partial_symtab *pst)
729 {
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
735 /* If it's been looked up before, return it. */
736 if (pst->get_compunit_symtab (objfile))
737 return pst->get_compunit_symtab (objfile);
738
739 /* If it has not yet been read in, read it. */
740 if (!pst->readin_p (objfile))
741 {
742 scoped_restore decrementer = increment_reading_symtab ();
743
744 if (info_verbose)
745 {
746 printf_filtered (_("Reading in symbols for %s...\n"),
747 pst->filename);
748 gdb_flush (gdb_stdout);
749 }
750
751 pst->read_symtab (objfile);
752 }
753
754 return pst->get_compunit_symtab (objfile);
755 }
756
757 /* Psymtab version of find_last_source_symtab. See its definition in
758 the definition of quick_symbol_functions in symfile.h. */
759
760 struct symtab *
761 psymbol_functions::find_last_source_symtab (struct objfile *ofp)
762 {
763 struct partial_symtab *cs_pst = NULL;
764
765 for (partial_symtab *ps : require_partial_symbols (ofp, true))
766 {
767 const char *name = ps->filename;
768 int len = strlen (name);
769
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 {
777 if (cs_pst->readin_p (ofp))
778 {
779 internal_error (__FILE__, __LINE__,
780 _("select_source_symtab: "
781 "readin pst found and no symtabs."));
782 }
783 else
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 }
791 }
792 return NULL;
793 }
794
795 /* Psymtab version of forget_cached_source_info. See its definition in
796 the definition of quick_symbol_functions in symfile.h. */
797
798 void
799 psymbol_functions::forget_cached_source_info (struct objfile *objfile)
800 {
801 for (partial_symtab *pst : require_partial_symbols (objfile, true))
802 {
803 if (pst->fullname != NULL)
804 {
805 xfree (pst->fullname);
806 pst->fullname = NULL;
807 }
808 }
809 }
810
811 static void
812 print_partial_symbols (struct gdbarch *gdbarch, struct objfile *objfile,
813 const std::vector<partial_symbol *> &symbols,
814 const char *what, struct ui_file *outfile)
815 {
816 fprintf_filtered (outfile, " %s partial symbols:\n", what);
817 for (partial_symbol *p : symbols)
818 {
819 QUIT;
820 fprintf_filtered (outfile, " `%s'", p->ginfo.linkage_name ());
821 if (p->ginfo.demangled_name () != NULL)
822 {
823 fprintf_filtered (outfile, " `%s'",
824 p->ginfo.demangled_name ());
825 }
826 fputs_filtered (", ", outfile);
827 switch (p->domain)
828 {
829 case UNDEF_DOMAIN:
830 fputs_filtered ("undefined domain, ", outfile);
831 break;
832 case VAR_DOMAIN:
833 /* This is the usual thing -- don't print it. */
834 break;
835 case STRUCT_DOMAIN:
836 fputs_filtered ("struct domain, ", outfile);
837 break;
838 case MODULE_DOMAIN:
839 fputs_filtered ("module domain, ", outfile);
840 break;
841 case LABEL_DOMAIN:
842 fputs_filtered ("label domain, ", outfile);
843 break;
844 case COMMON_BLOCK_DOMAIN:
845 fputs_filtered ("common block domain, ", outfile);
846 break;
847 default:
848 fputs_filtered ("<invalid domain>, ", outfile);
849 break;
850 }
851 switch (p->aclass)
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);
903 fputs_filtered (paddress (gdbarch, p->unrelocated_address ()), outfile);
904 fprintf_filtered (outfile, "\n");
905 }
906 }
907
908 static void
909 dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
910 struct ui_file *outfile)
911 {
912 struct gdbarch *gdbarch = objfile->arch ();
913 int i;
914
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 }
925 fprintf_filtered (outfile, "(object ");
926 gdb_print_host_address (psymtab, outfile);
927 fprintf_filtered (outfile, ")\n\n");
928 fprintf_filtered (outfile, " Read from object file %s (",
929 objfile_name (objfile));
930 gdb_print_host_address (objfile, outfile);
931 fprintf_filtered (outfile, ")\n");
932
933 if (psymtab->readin_p (objfile))
934 {
935 fprintf_filtered (outfile,
936 " Full symtab was read (at ");
937 gdb_print_host_address (psymtab->get_compunit_symtab (objfile), outfile);
938 fprintf_filtered (outfile, ")\n");
939 }
940
941 fprintf_filtered (outfile, " Symbols cover text addresses ");
942 fputs_filtered (paddress (gdbarch, psymtab->text_low (objfile)), outfile);
943 fprintf_filtered (outfile, "-");
944 fputs_filtered (paddress (gdbarch, psymtab->text_high (objfile)), outfile);
945 fprintf_filtered (outfile, "\n");
946 fprintf_filtered (outfile, " Address map supported - %s.\n",
947 psymtab->psymtabs_addrmap_supported ? "yes" : "no");
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 }
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 }
963 if (!psymtab->global_psymbols.empty ())
964 {
965 print_partial_symbols
966 (gdbarch, objfile, psymtab->global_psymbols,
967 "Global", outfile);
968 }
969 if (!psymtab->static_psymbols.empty ())
970 {
971 print_partial_symbols
972 (gdbarch, objfile, psymtab->static_psymbols,
973 "Static", outfile);
974 }
975 fprintf_filtered (outfile, "\n");
976 }
977
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
992 /* Psymtab version of print_stats. See its definition in
993 the definition of quick_symbol_functions in symfile.h. */
994
995 void
996 psymbol_functions::print_stats (struct objfile *objfile, bool print_bcache)
997 {
998 int i;
999
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
1019 {
1020 printf_filtered (_("Psymbol byte cache statistics:\n"));
1021 objfile->partial_symtabs->psymbol_cache.print_statistics
1022 ("partial symbol cache");
1023 }
1024 }
1025
1026 /* Psymtab version of dump. See its definition in
1027 the definition of quick_symbol_functions in symfile.h. */
1028
1029 void
1030 psymbol_functions::dump (struct objfile *objfile)
1031 {
1032 struct partial_symtab *psymtab;
1033
1034 if (objfile->partial_symtabs->psymtabs)
1035 {
1036 printf_filtered ("Psymtabs:\n");
1037 for (psymtab = objfile->partial_symtabs->psymtabs;
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 (", ");
1045 wrap_here (" ");
1046 }
1047 printf_filtered ("\n\n");
1048 }
1049 }
1050
1051 /* Psymtab version of expand_symtabs_for_function. See its definition in
1052 the definition of quick_symbol_functions in symfile.h. */
1053
1054 void
1055 psymbol_functions::expand_symtabs_for_function (struct objfile *objfile,
1056 const char *func_name)
1057 {
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
1061 for (partial_symtab *ps : require_partial_symbols (objfile, true))
1062 {
1063 if (ps->readin_p (objfile))
1064 continue;
1065
1066 if ((lookup_partial_symbol (objfile, ps, lookup_name, 1, VAR_DOMAIN)
1067 != NULL)
1068 || (lookup_partial_symbol (objfile, ps, lookup_name, 0, VAR_DOMAIN)
1069 != NULL))
1070 psymtab_to_symtab (objfile, ps);
1071 }
1072 }
1073
1074 /* Psymtab version of expand_all_symtabs. See its definition in
1075 the definition of quick_symbol_functions in symfile.h. */
1076
1077 void
1078 psymbol_functions::expand_all_symtabs (struct objfile *objfile)
1079 {
1080 for (partial_symtab *psymtab : require_partial_symbols (objfile, true))
1081 psymtab_to_symtab (objfile, psymtab);
1082 }
1083
1084 /* Psymtab version of expand_symtabs_with_fullname. See its definition in
1085 the definition of quick_symbol_functions in symfile.h. */
1086
1087 void
1088 psymbol_functions::expand_symtabs_with_fullname (struct objfile *objfile,
1089 const char *fullname)
1090 {
1091 for (partial_symtab *p : require_partial_symbols (objfile, true))
1092 {
1093 /* Anonymous psymtabs don't have a name of a source file. */
1094 if (p->anonymous)
1095 continue;
1096
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)
1102 psymtab_to_symtab (objfile, p);
1103 }
1104 }
1105
1106 /* Psymtab version of map_symbol_filenames. See its definition in
1107 the definition of quick_symbol_functions in symfile.h. */
1108
1109 void
1110 psymbol_functions::map_symbol_filenames (struct objfile *objfile,
1111 symbol_filename_ftype *fun,
1112 void *data,
1113 int need_fullname)
1114 {
1115 for (partial_symtab *ps : require_partial_symbols (objfile, true))
1116 {
1117 const char *fullname;
1118
1119 if (ps->readin_p (objfile))
1120 continue;
1121
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
1127 /* Anonymous psymtabs don't have a file name. */
1128 if (ps->anonymous)
1129 continue;
1130
1131 QUIT;
1132 if (need_fullname)
1133 fullname = psymtab_to_fullname (ps);
1134 else
1135 fullname = NULL;
1136 (*fun) (ps->filename, fullname, data);
1137 }
1138 }
1139
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. */
1147
1148 static const char *
1149 psymtab_to_fullname (struct partial_symtab *ps)
1150 {
1151 gdb_assert (!ps->anonymous);
1152
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. */
1156 if (ps->fullname == NULL)
1157 {
1158 gdb::unique_xmalloc_ptr<char> fullname;
1159 scoped_fd fd = find_and_open_source (ps->filename, ps->dirname,
1160 &fullname);
1161 ps->fullname = fullname.release ();
1162
1163 if (fd.get () < 0)
1164 {
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. */
1167
1168 if (ps->dirname == NULL || IS_ABSOLUTE_PATH (ps->filename))
1169 fullname.reset (xstrdup (ps->filename));
1170 else
1171 fullname.reset (concat (ps->dirname, SLASH_STRING,
1172 ps->filename, (char *) NULL));
1173
1174 ps->fullname = rewrite_source_path (fullname.get ()).release ();
1175 if (ps->fullname == NULL)
1176 ps->fullname = fullname.release ();
1177 }
1178 }
1179
1180 return ps->fullname;
1181 }
1182
1183 /* Psymtab version of map_matching_symbols. See its definition in
1184 the definition of quick_symbol_functions in symfile.h. */
1185
1186 void
1187 psymbol_functions::map_matching_symbols
1188 (struct objfile *objfile,
1189 const lookup_name_info &name, domain_enum domain,
1190 int global,
1191 gdb::function_view<symbol_found_callback_ftype> callback,
1192 symbol_compare_ftype *ordered_compare)
1193 {
1194 const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
1195
1196 for (partial_symtab *ps : require_partial_symbols (objfile, true))
1197 {
1198 QUIT;
1199 if (ps->readin_p (objfile)
1200 || match_partial_symbol (objfile, ps, global, name, domain,
1201 ordered_compare))
1202 {
1203 struct compunit_symtab *cust = psymtab_to_symtab (objfile, ps);
1204 const struct block *block;
1205
1206 if (cust == NULL)
1207 continue;
1208 block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), block_kind);
1209 if (!iterate_over_symbols_terminated (block, name,
1210 domain, callback))
1211 return;
1212 }
1213 }
1214 }
1215
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
1219 various psymtabs that it searches. */
1220
1221 static bool
1222 recursively_search_psymtabs
1223 (struct partial_symtab *ps,
1224 struct objfile *objfile,
1225 enum search_domain domain,
1226 const lookup_name_info &lookup_name,
1227 gdb::function_view<expand_symtabs_symbol_matcher_ftype> sym_matcher)
1228 {
1229 int keep_going = 1;
1230 enum psymtab_search_status result = PST_SEARCHED_AND_NOT_FOUND;
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],
1247 objfile, domain, lookup_name,
1248 sym_matcher);
1249 if (r != 0)
1250 {
1251 ps->searched_flag = PST_SEARCHED_AND_FOUND;
1252 return true;
1253 }
1254 }
1255
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 ());
1260 partial_symbol **bound = gbound;
1261
1262 /* Go through all of the symbols stored in a partial
1263 symtab in one loop. */
1264 partial_symbol **psym = ps->global_psymbols.data ();
1265 while (keep_going)
1266 {
1267 if (psym >= bound)
1268 {
1269 if (bound == gbound && !ps->static_psymbols.empty ())
1270 {
1271 psym = ps->static_psymbols.data ();
1272 bound = sbound;
1273 }
1274 else
1275 keep_going = 0;
1276 continue;
1277 }
1278 else
1279 {
1280 QUIT;
1281
1282 if ((domain == ALL_DOMAIN
1283 || (domain == MODULES_DOMAIN
1284 && (*psym)->domain == MODULE_DOMAIN)
1285 || (domain == VARIABLES_DOMAIN
1286 && (*psym)->aclass != LOC_TYPEDEF
1287 && (*psym)->aclass != LOC_BLOCK)
1288 || (domain == FUNCTIONS_DOMAIN
1289 && (*psym)->aclass == LOC_BLOCK)
1290 || (domain == TYPES_DOMAIN
1291 && (*psym)->aclass == LOC_TYPEDEF))
1292 && psymbol_name_matches (*psym, lookup_name)
1293 && (sym_matcher == NULL
1294 || sym_matcher ((*psym)->ginfo.search_name ())))
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
1308 /* Psymtab version of expand_symtabs_matching. See its definition in
1309 the definition of quick_symbol_functions in symfile.h. */
1310
1311 void
1312 psymbol_functions::expand_symtabs_matching
1313 (struct objfile *objfile,
1314 gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
1315 const lookup_name_info *lookup_name,
1316 gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
1317 gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
1318 enum search_domain domain)
1319 {
1320 /* Clear the search flags. */
1321 for (partial_symtab *ps : require_partial_symbols (objfile, true))
1322 ps->searched_flag = PST_NOT_SEARCHED;
1323
1324 for (partial_symtab *ps : objfile->psymtabs ())
1325 {
1326 QUIT;
1327
1328 if (ps->readin_p (objfile))
1329 continue;
1330
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)
1334 continue;
1335
1336 if (file_matcher)
1337 {
1338 bool match;
1339
1340 if (ps->anonymous)
1341 continue;
1342
1343 match = file_matcher (ps->filename, false);
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
1349 || file_matcher (lbasename (ps->filename), true))
1350 match = file_matcher (psymtab_to_fullname (ps), false);
1351 }
1352 if (!match)
1353 continue;
1354 }
1355
1356 if ((symbol_matcher == NULL && lookup_name == NULL)
1357 || recursively_search_psymtabs (ps, objfile, domain,
1358 lookup_name->make_ignore_params (),
1359 symbol_matcher))
1360 {
1361 struct compunit_symtab *symtab =
1362 psymtab_to_symtab (objfile, ps);
1363
1364 if (expansion_notify != NULL)
1365 expansion_notify (symtab);
1366 }
1367 }
1368 }
1369
1370 /* Psymtab version of has_symbols. See its definition in
1371 the definition of quick_symbol_functions in symfile.h. */
1372
1373 bool
1374 psymbol_functions::has_symbols (struct objfile *objfile)
1375 {
1376 return objfile->partial_symtabs->psymtabs != NULL;
1377 }
1378
1379 /* Helper function for psym_find_compunit_symtab_by_address that fills
1380 in m_psymbol_map for a given range of psymbols. */
1381
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)
1388 {
1389 for (partial_symbol *psym : symbols)
1390 {
1391 if (psym->aclass == LOC_STATIC)
1392 {
1393 CORE_ADDR addr = psym->address (objfile);
1394 if (seen_addrs->find (addr) == seen_addrs->end ())
1395 {
1396 seen_addrs->insert (addr);
1397 m_psymbol_map.emplace_back (addr, psymtab);
1398 }
1399 }
1400 }
1401 }
1402
1403 /* See find_compunit_symtab_by_address in quick_symbol_functions, in
1404 symfile.h. */
1405
1406 compunit_symtab *
1407 psymbol_functions::find_compunit_symtab_by_address (struct objfile *objfile,
1408 CORE_ADDR address)
1409 {
1410 if (m_psymbol_map.empty ())
1411 {
1412 std::set<CORE_ADDR> seen_addrs;
1413
1414 for (partial_symtab *pst : require_partial_symbols (objfile, true))
1415 {
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);
1422 }
1423
1424 m_psymbol_map.shrink_to_fit ();
1425
1426 std::sort (m_psymbol_map.begin (), m_psymbol_map.end (),
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
1435 (m_psymbol_map.begin (), m_psymbol_map.end (), address,
1436 [] (const std::pair<CORE_ADDR, partial_symtab *> &a,
1437 CORE_ADDR b)
1438 {
1439 return a.first < b;
1440 });
1441
1442 if (iter == m_psymbol_map.end () || iter->first != address)
1443 return NULL;
1444
1445 return psymtab_to_symtab (objfile, iter->second);
1446 }
1447
1448 quick_symbol_functions_up
1449 make_psymbol_functions ()
1450 {
1451 return quick_symbol_functions_up (new psymbol_functions);
1452 }
1453
1454 \f
1455
1456 /* Partially fill a partial symtab. It will be completely filled at
1457 the end of the symbol list. */
1458
1459 partial_symtab::partial_symtab (const char *filename,
1460 struct objfile *objfile,
1461 CORE_ADDR textlow)
1462 : partial_symtab (filename, objfile)
1463 {
1464 set_text_low (textlow);
1465 set_text_high (raw_text_low ()); /* default */
1466 }
1467
1468 /* Perform "finishing up" operations of a partial symtab. */
1469
1470 void
1471 partial_symtab::end ()
1472 {
1473 global_psymbols.shrink_to_fit ();
1474 static_psymbols.shrink_to_fit ();
1475
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 });
1484 }
1485
1486 /* See psymtab.h. */
1487
1488 unsigned long
1489 psymbol_bcache::hash (const void *addr, int length)
1490 {
1491 unsigned long h = 0;
1492 struct partial_symbol *psymbol = (struct partial_symbol *) addr;
1493 unsigned int lang = psymbol->ginfo.language ();
1494 unsigned int domain = psymbol->domain;
1495 unsigned int theclass = psymbol->aclass;
1496
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);
1501 /* Note that psymbol names are interned via compute_and_set_names, so
1502 there's no need to hash the contents of the name here. */
1503 h = fast_hash (&psymbol->ginfo.m_name, sizeof (psymbol->ginfo.m_name), h);
1504
1505 return h;
1506 }
1507
1508 /* See psymtab.h. */
1509
1510 int
1511 psymbol_bcache::compare (const void *addr1, const void *addr2, int length)
1512 {
1513 struct partial_symbol *sym1 = (struct partial_symbol *) addr1;
1514 struct partial_symbol *sym2 = (struct partial_symbol *) addr2;
1515
1516 return (memcmp (&sym1->ginfo.value, &sym2->ginfo.value,
1517 sizeof (sym1->ginfo.value)) == 0
1518 && sym1->ginfo.language () == sym2->ginfo.language ()
1519 && sym1->domain == sym2->domain
1520 && sym1->aclass == sym2->aclass
1521 /* Note that psymbol names are interned via
1522 compute_and_set_names, so there's no need to compare the
1523 contents of the name here. */
1524 && sym1->ginfo.linkage_name () == sym2->ginfo.linkage_name ());
1525 }
1526
1527 /* Helper function, initialises partial symbol structure and stashes
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
1533 static struct partial_symbol *
1534 add_psymbol_to_bcache (const partial_symbol &psymbol, struct objfile *objfile,
1535 bool *added)
1536 {
1537 /* Stash the partial symbol away in the cache. */
1538 return ((struct partial_symbol *)
1539 objfile->partial_symtabs->psymbol_cache.insert
1540 (&psymbol, sizeof (struct partial_symbol), added));
1541 }
1542
1543 /* See psympriv.h. */
1544
1545 void
1546 partial_symtab::add_psymbol (const partial_symbol &psymbol,
1547 psymbol_placement where,
1548 struct objfile *objfile)
1549 {
1550 bool added;
1551
1552 /* Stash the partial symbol away in the cache. */
1553 partial_symbol *psym = add_psymbol_to_bcache (psymbol, objfile, &added);
1554
1555 /* Do not duplicate global partial symbols. */
1556 if (where == psymbol_placement::GLOBAL && !added)
1557 return;
1558
1559 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1560 std::vector<partial_symbol *> &list
1561 = (where == psymbol_placement::STATIC
1562 ? static_psymbols
1563 : global_psymbols);
1564 list.push_back (psym);
1565 }
1566
1567 /* See psympriv.h. */
1568
1569 void
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)
1577 {
1578 struct partial_symbol psymbol;
1579 memset (&psymbol, 0, sizeof (psymbol));
1580
1581 psymbol.set_unrelocated_address (coreaddr);
1582 psymbol.ginfo.set_section_index (section);
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
1588 add_psymbol (psymbol, where, objfile);
1589 }
1590
1591 /* See psympriv.h. */
1592
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)
1597 {
1598 objfile->partial_symtabs->install_psymtab (this);
1599
1600 filename = objfile->intern (filename_);
1601
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
1609 || strcmp (last_objfile_name, objfile_name (objfile)) != 0)
1610 {
1611 xfree (last_objfile_name);
1612 last_objfile_name = xstrdup (objfile_name (objfile));
1613 fprintf_filtered (gdb_stdlog,
1614 "Creating one or more psymtabs for objfile %s ...\n",
1615 last_objfile_name);
1616 }
1617 fprintf_filtered (gdb_stdlog,
1618 "Created psymtab %s for module %s.\n",
1619 host_address_to_string (this), filename);
1620 }
1621 }
1622
1623 /* See psympriv.h. */
1624
1625 void
1626 partial_symtab::expand_dependencies (struct objfile *objfile)
1627 {
1628 for (int i = 0; i < number_of_dependencies; ++i)
1629 {
1630 if (!dependencies[i]->readin_p (objfile)
1631 && dependencies[i]->user == NULL)
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
1650 void
1651 psymtab_storage::discard_psymtab (struct partial_symtab *pst)
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
1662 /* First, snip it out of the psymtab chain. */
1663
1664 prev_pst = &psymtabs;
1665 while ((*prev_pst) != pst)
1666 prev_pst = &((*prev_pst)->next);
1667 (*prev_pst) = pst->next;
1668 delete pst;
1669 }
1670
1671 \f
1672
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 {
1693 struct dump_psymtab_addrmap_data *data
1694 = (struct dump_psymtab_addrmap_data *) datap;
1695 struct gdbarch *gdbarch = data->objfile->arch ();
1696 struct partial_symtab *addrmap_psymtab = (struct partial_symtab *) obj;
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
1732 if ((psymtab == NULL
1733 || psymtab->psymtabs_addrmap_supported)
1734 && objfile->partial_symtabs->psymtabs_addrmap != NULL)
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");
1742 addrmap_foreach (objfile->partial_symtabs->psymtabs_addrmap,
1743 dump_psymtab_addrmap_1, &addrmap_dump_data);
1744 }
1745 }
1746
1747 static void
1748 maintenance_print_psymbols (const char *args, int from_tty)
1749 {
1750 struct ui_file *outfile = gdb_stdout;
1751 char *address_arg = NULL, *source_arg = NULL, *objfile_arg = NULL;
1752 int i, outfile_idx, found;
1753 CORE_ADDR pc = 0;
1754 struct obj_section *section = NULL;
1755
1756 dont_repeat ();
1757
1758 gdb_argv argv (args);
1759
1760 for (i = 0; argv != NULL && argv[i] != NULL; ++i)
1761 {
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] == '-')
1787 {
1788 /* Future proofing: Don't allow OUTFILE to begin with "-". */
1789 error (_("Unknown option: %s"), argv[i]);
1790 }
1791 else
1792 break;
1793 }
1794 outfile_idx = i;
1795
1796 if (address_arg != NULL && source_arg != NULL)
1797 error (_("Must specify at most one of -pc and -source"));
1798
1799 stdio_file arg_outfile;
1800
1801 if (argv != NULL && argv[outfile_idx] != NULL)
1802 {
1803 if (argv[outfile_idx + 1] != NULL)
1804 error (_("Junk at end of command"));
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 ());
1809 outfile = &arg_outfile;
1810 }
1811
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 }
1818
1819 found = 0;
1820 for (objfile *objfile : current_program_space->objfiles ())
1821 {
1822 int printed_objfile_header = 0;
1823 int print_for_objfile = 1;
1824
1825 QUIT;
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). */
1839 struct partial_symtab *ps = find_pc_sect_psymtab (objfile, pc,
1840 section, msymbol);
1841 if (ps != NULL)
1842 {
1843 if (!printed_objfile_header)
1844 {
1845 outfile->printf ("\nPartial symtabs for objfile %s\n",
1846 objfile_name (objfile));
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 {
1856 for (partial_symtab *ps : require_partial_symbols (objfile, true))
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 {
1872 outfile->printf ("\nPartial symtabs for objfile %s\n",
1873 objfile_name (objfile));
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
1886 && objfile->partial_symtabs->psymtabs_addrmap != NULL)
1887 {
1888 outfile->puts ("\n");
1889 dump_psymtab_addrmap (objfile, NULL, outfile);
1890 }
1891 }
1892
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 }
1900 }
1901
1902 /* List all the partial symbol tables whose names match REGEXP (optional). */
1903
1904 static void
1905 maintenance_info_psymtabs (const char *regexp, int from_tty)
1906 {
1907 if (regexp)
1908 re_comp (regexp);
1909
1910 for (struct program_space *pspace : program_spaces)
1911 for (objfile *objfile : pspace->objfiles ())
1912 {
1913 struct gdbarch *gdbarch = objfile->arch ();
1914
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;
1918
1919 for (partial_symtab *psymtab : require_partial_symbols (objfile, true))
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",
1941 psymtab->readin_p (objfile) ? "yes" : "no");
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 ");
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 ());
1963 else
1964 printf_filtered ("(none)\n");
1965 printf_filtered (" statics ");
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 ());
1971 else
1972 printf_filtered ("(none)\n");
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));
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 }
2002
2003 if (printed_objfile_start)
2004 printf_filtered ("}\n");
2005 }
2006 }
2007
2008 /* Check consistency of currently expanded psymtabs vs symtabs. */
2009
2010 static void
2011 maintenance_check_psymtabs (const char *ignore, int from_tty)
2012 {
2013 struct symbol *sym;
2014 struct compunit_symtab *cust = NULL;
2015 const struct blockvector *bv;
2016 const struct block *b;
2017
2018 for (objfile *objfile : current_program_space->objfiles ())
2019 for (partial_symtab *ps : require_partial_symbols (objfile, true))
2020 {
2021 struct gdbarch *gdbarch = objfile->arch ();
2022
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. */
2026 cust = ps->get_compunit_symtab (objfile);
2027
2028 /* First do some checks that don't require the associated symtab. */
2029 if (ps->text_high (objfile) < ps->text_low (objfile))
2030 {
2031 printf_filtered ("Psymtab ");
2032 puts_filtered (ps->filename);
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;
2041 }
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);
2048 for (partial_symbol *psym : ps->static_psymbols)
2049 {
2050 /* Skip symbols for inlined functions without address. These may
2051 or may not have a match in the full symtab. */
2052 if (psym->aclass == LOC_BLOCK
2053 && psym->ginfo.value.address == 0)
2054 continue;
2055
2056 sym = block_lookup_symbol (b, psym->ginfo.search_name (),
2057 symbol_name_match_type::SEARCH_NAME,
2058 psym->domain);
2059 if (!sym)
2060 {
2061 printf_filtered ("Static symbol `");
2062 puts_filtered (psym->ginfo.linkage_name ());
2063 printf_filtered ("' only found in ");
2064 puts_filtered (ps->filename);
2065 printf_filtered (" psymtab\n");
2066 }
2067 }
2068 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
2069 for (partial_symbol *psym : ps->global_psymbols)
2070 {
2071 sym = block_lookup_symbol (b, psym->ginfo.search_name (),
2072 symbol_name_match_type::SEARCH_NAME,
2073 psym->domain);
2074 if (!sym)
2075 {
2076 printf_filtered ("Global symbol `");
2077 puts_filtered (psym->ginfo.linkage_name ());
2078 printf_filtered ("' only found in ");
2079 puts_filtered (ps->filename);
2080 printf_filtered (" psymtab\n");
2081 }
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 ");
2088 puts_filtered (ps->filename);
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");
2100 }
2101 }
2102 }
2103
2104 void _initialize_psymtab ();
2105 void
2106 _initialize_psymtab ()
2107 {
2108 add_cmd ("psymbols", class_maintenance, maintenance_print_psymbols, _("\
2109 Print dump of current partial symbol definitions.\n\
2110 Usage: mt print psymbols [-objfile OBJFILE] [-pc ADDRESS] [--] [OUTFILE]\n\
2111 mt print psymbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
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."),
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
2125 add_cmd ("check-psymtabs", class_maintenance, maintenance_check_psymtabs,
2126 _("\
2127 Check consistency of currently expanded psymtabs versus symtabs."),
2128 &maintenancelist);
2129 }