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