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