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