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