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