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