GDB (xrefs)
Loading...
Searching...
No Matches
psymtab.c
Go to the documentation of this file.
1/* Partial symbol tables.
2
3 Copyright (C) 2009-2023 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 "psymtab.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 "gdbsupport/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#include "gdbsupport/buildargv.h"
40
41static struct partial_symbol *lookup_partial_symbol (struct objfile *,
42 struct partial_symtab *,
43 const lookup_name_info &,
44 int,
46
47static const char *psymtab_to_fullname (struct partial_symtab *ps);
48
49static struct partial_symbol *find_pc_sect_psymbol (struct objfile *,
50 struct partial_symtab *,
51 CORE_ADDR,
52 struct obj_section *);
53
54static struct compunit_symtab *psymtab_to_symtab (struct objfile *objfile,
55 struct partial_symtab *pst);
56
58{
60 while (iter != nullptr)
61 {
62 partial_symtab *next = iter->next;
63 delete iter;
64 iter = next;
65 }
66}
67
68/* See psymtab.h. */
69
70void
76
77
78
79/* See psymtab.h. */
80
83{
84 gdb_assert ((objfile->flags & OBJF_PSYMTABS_READ) != 0);
85 return m_partial_symtabs->range ();
86}
87
88/* Find which partial symtab contains PC and SECTION starting at psymtab PST.
89 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
90
91static struct partial_symtab *
93 CORE_ADDR pc, struct obj_section *section,
94 struct partial_symtab *pst,
95 struct bound_minimal_symbol msymbol)
96{
97 struct partial_symtab *tpst;
98 struct partial_symtab *best_pst = pst;
99 CORE_ADDR best_addr = pst->text_low (objfile);
100
101 /* An objfile that has its functions reordered might have
102 many partial symbol tables containing the PC, but
103 we want the partial symbol table that contains the
104 function containing the PC. */
105 if (section == nullptr)
106 return pst;
107
108 if (msymbol.minsym == NULL)
109 return pst;
110
111 /* The code range of partial symtabs sometimes overlap, so, in
112 the loop below, we need to check all partial symtabs and
113 find the one that fits better for the given PC address. We
114 select the partial symtab that contains a symbol whose
115 address is closest to the PC address. By closest we mean
116 that find_pc_sect_symbol returns the symbol with address
117 that is closest and still less than the given PC. */
118 for (tpst = pst; tpst != NULL; tpst = tpst->next)
119 {
120 if (pc >= tpst->text_low (objfile) && pc < tpst->text_high (objfile))
121 {
122 struct partial_symbol *p;
123 CORE_ADDR this_addr;
124
125 /* NOTE: This assumes that every psymbol has a
126 corresponding msymbol, which is not necessarily
127 true; the debug info might be much richer than the
128 object's symbol table. */
129 p = find_pc_sect_psymbol (objfile, tpst, pc, section);
130 if (p != NULL
131 && (p->address (objfile) == msymbol.value_address ()))
132 return tpst;
133
134 /* Also accept the textlow value of a psymtab as a
135 "symbol", to provide some support for partial
136 symbol tables with line information but no debug
137 symbols (e.g. those produced by an assembler). */
138 if (p != NULL)
139 this_addr = p->address (objfile);
140 else
141 this_addr = tpst->text_low (objfile);
142
143 /* Check whether it is closer than our current
144 BEST_ADDR. Since this symbol address is
145 necessarily lower or equal to PC, the symbol closer
146 to PC is the symbol which address is the highest.
147 This way we return the psymtab which contains such
148 best match symbol. This can help in cases where the
149 symbol information/debuginfo is not complete, like
150 for instance on IRIX6 with gcc, where no debug info
151 is emitted for statics. (See also the nodebug.exp
152 testcase.) */
153 if (this_addr > best_addr)
154 {
155 best_addr = this_addr;
156 best_pst = tpst;
157 }
158 }
159 }
160 return best_pst;
161}
162
163/* See psymtab.h. */
164
165struct partial_symtab *
167 CORE_ADDR pc,
168 struct obj_section *section,
169 struct bound_minimal_symbol msymbol)
170{
172 if (pc >= pst->text_low (objfile) && pc < pst->text_high (objfile))
173 {
174 struct partial_symtab *best_pst;
175
176 best_pst = find_pc_sect_psymtab_closer (objfile, pc, section, pst,
177 msymbol);
178 if (best_pst != NULL)
179 return best_pst;
180 }
181
182 return NULL;
183}
184
185/* Psymtab version of find_pc_sect_compunit_symtab. See its definition in
186 the definition of quick_symbol_functions in symfile.h. */
187
188struct compunit_symtab *
190 (struct objfile *objfile,
191 struct bound_minimal_symbol msymbol,
192 CORE_ADDR pc,
193 struct obj_section *section,
194 int warn_if_readin)
195{
197 pc, section,
198 msymbol);
199 if (ps != NULL)
200 {
201 if (warn_if_readin && ps->readin_p (objfile))
202 /* Might want to error() here (in case symtab is corrupt and
203 will cause a core dump), but maybe we can successfully
204 continue, so let's not. */
205 warning (_("\
206(Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
207 paddress (objfile->arch (), pc));
209 return ps->get_compunit_symtab (objfile);
210 }
211 return NULL;
212}
213
214/* Find which partial symbol within a psymtab matches PC and SECTION.
215 Return NULL if none. */
216
217static struct partial_symbol *
219 struct partial_symtab *psymtab, CORE_ADDR pc,
220 struct obj_section *section)
221{
222 struct partial_symbol *best = NULL;
223 CORE_ADDR best_pc;
224 const CORE_ADDR textlow = psymtab->text_low (objfile);
225
226 gdb_assert (psymtab != NULL);
227
228 /* Cope with programs that start at address 0. */
229 best_pc = (textlow != 0) ? textlow - 1 : 0;
230
231 /* Search the global symbols as well as the static symbols, so that
232 find_pc_partial_function doesn't use a minimal symbol and thus
233 cache a bad endaddr. */
234 for (partial_symbol *p : psymtab->global_psymbols)
235 {
236 if (p->domain == VAR_DOMAIN
237 && p->aclass == LOC_BLOCK
238 && pc >= p->address (objfile)
239 && (p->address (objfile) > best_pc
240 || (psymtab->text_low (objfile) == 0
241 && best_pc == 0 && p->address (objfile) == 0)))
242 {
243 if (section != NULL) /* Match on a specific section. */
244 {
245 if (!matching_obj_sections (p->obj_section (objfile),
246 section))
247 continue;
248 }
249 best_pc = p->address (objfile);
250 best = p;
251 }
252 }
253
254 for (partial_symbol *p : psymtab->static_psymbols)
255 {
256 if (p->domain == VAR_DOMAIN
257 && p->aclass == LOC_BLOCK
258 && pc >= p->address (objfile)
259 && (p->address (objfile) > best_pc
260 || (psymtab->text_low (objfile) == 0
261 && best_pc == 0 && p->address (objfile) == 0)))
262 {
263 if (section != NULL) /* Match on a specific section. */
264 {
265 if (!matching_obj_sections (p->obj_section (objfile),
266 section))
267 continue;
268 }
269 best_pc = p->address (objfile);
270 best = p;
271 }
272 }
273
274 return best;
275}
276
277/* Psymtab version of lookup_global_symbol_language. See its definition in
278 the definition of quick_symbol_functions in symfile.h. */
279
280enum language
282 const char *name,
284 bool *symbol_found_p)
285{
286 *symbol_found_p = false;
287 if (objfile->sf == NULL)
288 return language_unknown;
289
291
293 {
294 struct partial_symbol *psym;
295 if (ps->readin_p (objfile))
296 continue;
297
298 psym = lookup_partial_symbol (objfile, ps, lookup_name, 1, domain);
299 if (psym)
300 {
301 *symbol_found_p = true;
302 return psym->ginfo.language ();
303 }
304 }
305
306 return language_unknown;
307}
308
309/* Returns true if PSYM matches LOOKUP_NAME. */
310
311static bool
313 const lookup_name_info &lookup_name)
314{
315 const language_defn *lang = language_def (psym->ginfo.language ());
316 symbol_name_matcher_ftype *name_match
317 = lang->get_symbol_name_matcher (lookup_name);
318 return name_match (psym->ginfo.search_name (), lookup_name, NULL);
319}
320
321/* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
322 the global block of PST if GLOBAL, and otherwise the static block.
323 MATCH is the comparison operation that returns true iff MATCH (s,
324 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
325 non-null, the symbols in the block are assumed to be ordered
326 according to it (allowing binary search). It must be compatible
327 with MATCH. Returns the symbol, if found, and otherwise NULL. */
328
329static struct partial_symbol *
331 struct partial_symtab *pst, int global,
333 symbol_compare_ftype *ordered_compare)
334{
335 struct partial_symbol **start, **psym;
336 struct partial_symbol **top, **real_top, **bottom, **center;
337 int length = (global
338 ? pst->global_psymbols.size ()
339 : pst->static_psymbols.size ());
340 int do_linear_search = 1;
341
342 if (length == 0)
343 return NULL;
344
345 start = (global ?
346 &pst->global_psymbols[0] :
347 &pst->static_psymbols[0]);
348
349 if (global && ordered_compare) /* Can use a binary search. */
350 {
351 do_linear_search = 0;
352
353 /* Binary search. This search is guaranteed to end with center
354 pointing at the earliest partial symbol whose name might be
355 correct. At that point *all* partial symbols with an
356 appropriate name will be checked against the correct
357 domain. */
358
359 bottom = start;
360 top = start + length - 1;
361 real_top = top;
362 while (top > bottom)
363 {
364 center = bottom + (top - bottom) / 2;
365 gdb_assert (center < top);
366
367 enum language lang = (*center)->ginfo.language ();
368 const char *lang_ln = name.language_lookup_name (lang);
369
370 if (ordered_compare ((*center)->ginfo.search_name (),
371 lang_ln) >= 0)
372 top = center;
373 else
374 bottom = center + 1;
375 }
376 gdb_assert (top == bottom);
377
378 while (top <= real_top
379 && psymbol_name_matches (*top, name))
380 {
381 if (symbol_matches_domain ((*top)->ginfo.language (),
382 (*top)->domain, domain))
383 return *top;
384 top++;
385 }
386 }
387
388 /* Can't use a binary search or else we found during the binary search that
389 we should also do a linear search. */
390
391 if (do_linear_search)
392 {
393 for (psym = start; psym < start + length; psym++)
394 {
395 if (symbol_matches_domain ((*psym)->ginfo.language (),
396 (*psym)->domain, domain)
397 && psymbol_name_matches (*psym, name))
398 return *psym;
399 }
400 }
401
402 return NULL;
403}
404
405/* Look, in partial_symtab PST, for symbol whose natural name is
406 LOOKUP_NAME. Check the global symbols if GLOBAL, the static
407 symbols if not. */
408
409static struct partial_symbol *
411 struct partial_symtab *pst,
412 const lookup_name_info &lookup_name,
413 int global, domain_enum domain)
414{
415 struct partial_symbol **start, **psym;
416 struct partial_symbol **top, **real_top, **bottom, **center;
417 int length = (global
418 ? pst->global_psymbols.size ()
419 : pst->static_psymbols.size ());
420 int do_linear_search = 1;
421
422 if (length == 0)
423 return NULL;
424
425 start = (global ?
426 &pst->global_psymbols[0] :
427 &pst->static_psymbols[0]);
428
429 if (global) /* This means we can use a binary search. */
430 {
431 do_linear_search = 0;
432
433 /* Binary search. This search is guaranteed to end with center
434 pointing at the earliest partial symbol whose name might be
435 correct. At that point *all* partial symbols with an
436 appropriate name will be checked against the correct
437 domain. */
438
439 bottom = start;
440 top = start + length - 1;
441 real_top = top;
442 while (top > bottom)
443 {
444 center = bottom + (top - bottom) / 2;
445
446 gdb_assert (center < top);
447
448 if (strcmp_iw_ordered ((*center)->ginfo.search_name (),
449 lookup_name.c_str ()) >= 0)
450 {
451 top = center;
452 }
453 else
454 {
455 bottom = center + 1;
456 }
457 }
458
459 gdb_assert (top == bottom);
460
461 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
462 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
463 while (top >= start && symbol_matches_search_name (&(*top)->ginfo,
464 lookup_name))
465 top--;
466
467 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
468 top++;
469
470 while (top <= real_top && symbol_matches_search_name (&(*top)->ginfo,
471 lookup_name))
472 {
473 if (symbol_matches_domain ((*top)->ginfo.language (),
474 (*top)->domain, domain))
475 return *top;
476 top++;
477 }
478 }
479
480 /* Can't use a binary search or else we found during the binary search that
481 we should also do a linear search. */
482
483 if (do_linear_search)
484 {
485 for (psym = start; psym < start + length; psym++)
486 {
487 if (symbol_matches_domain ((*psym)->ginfo.language (),
488 (*psym)->domain, domain)
489 && symbol_matches_search_name (&(*psym)->ginfo, lookup_name))
490 return *psym;
491 }
492 }
493
494 return NULL;
495}
496
497/* Get the symbol table that corresponds to a partial_symtab.
498 This is fast after the first time you do it.
499 The result will be NULL if the primary symtab has no symbols,
500 which can happen. Otherwise the result is the primary symtab
501 that contains PST. */
502
503static struct compunit_symtab *
505{
506 /* If it is a shared psymtab, find an unshared psymtab that includes
507 it. Any such psymtab will do. */
508 while (pst->user != NULL)
509 pst = pst->user;
510
511 /* If it's been looked up before, return it. */
512 if (pst->get_compunit_symtab (objfile))
513 return pst->get_compunit_symtab (objfile);
514
515 /* If it has not yet been read in, read it. */
516 if (!pst->readin_p (objfile))
517 {
518 scoped_restore decrementer = increment_reading_symtab ();
519
520 if (info_verbose)
521 {
522 gdb_printf (_("Reading in symbols for %s...\n"),
523 pst->filename);
525 }
526
527 pst->read_symtab (objfile);
528 }
529
530 return pst->get_compunit_symtab (objfile);
531}
532
533/* Psymtab version of find_last_source_symtab. See its definition in
534 the definition of quick_symbol_functions in symfile.h. */
535
536struct symtab *
538{
539 struct partial_symtab *cs_pst = NULL;
540
541 for (partial_symtab *ps : partial_symbols (ofp))
542 {
543 const char *name = ps->filename;
544 int len = strlen (name);
545
546 if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0
547 || strcmp (name, "<<C++-namespaces>>") == 0)))
548 cs_pst = ps;
549 }
550
551 if (cs_pst)
552 {
553 if (cs_pst->readin_p (ofp))
554 {
555 internal_error (_("select_source_symtab: "
556 "readin pst found and no symtabs."));
557 }
558 else
559 {
560 struct compunit_symtab *cust = psymtab_to_symtab (ofp, cs_pst);
561
562 if (cust == NULL)
563 return NULL;
564 return cust->primary_filetab ();
565 }
566 }
567 return NULL;
568}
569
570/* Psymtab version of forget_cached_source_info. See its definition in
571 the definition of quick_symbol_functions in symfile.h. */
572
573void
575{
577 {
578 if (pst->fullname != NULL)
579 {
580 xfree (pst->fullname);
581 pst->fullname = NULL;
582 }
583 }
584}
585
586static void
588 const std::vector<partial_symbol *> &symbols,
589 const char *what, struct ui_file *outfile)
590{
591 gdb_printf (outfile, " %s partial symbols:\n", what);
592 for (partial_symbol *p : symbols)
593 {
594 QUIT;
595 gdb_printf (outfile, " `%s'", p->ginfo.linkage_name ());
596 if (p->ginfo.demangled_name () != NULL)
597 {
598 gdb_printf (outfile, " `%s'",
599 p->ginfo.demangled_name ());
600 }
601 gdb_puts (", ", outfile);
602 switch (p->domain)
603 {
604 case UNDEF_DOMAIN:
605 gdb_puts ("undefined domain, ", outfile);
606 break;
607 case VAR_DOMAIN:
608 /* This is the usual thing -- don't print it. */
609 break;
610 case STRUCT_DOMAIN:
611 gdb_puts ("struct domain, ", outfile);
612 break;
613 case MODULE_DOMAIN:
614 gdb_puts ("module domain, ", outfile);
615 break;
616 case LABEL_DOMAIN:
617 gdb_puts ("label domain, ", outfile);
618 break;
620 gdb_puts ("common block domain, ", outfile);
621 break;
622 default:
623 gdb_puts ("<invalid domain>, ", outfile);
624 break;
625 }
626 switch (p->aclass)
627 {
628 case LOC_UNDEF:
629 gdb_puts ("undefined", outfile);
630 break;
631 case LOC_CONST:
632 gdb_puts ("constant int", outfile);
633 break;
634 case LOC_STATIC:
635 gdb_puts ("static", outfile);
636 break;
637 case LOC_REGISTER:
638 gdb_puts ("register", outfile);
639 break;
640 case LOC_ARG:
641 gdb_puts ("pass by value", outfile);
642 break;
643 case LOC_REF_ARG:
644 gdb_puts ("pass by reference", outfile);
645 break;
646 case LOC_REGPARM_ADDR:
647 gdb_puts ("register address parameter", outfile);
648 break;
649 case LOC_LOCAL:
650 gdb_puts ("stack parameter", outfile);
651 break;
652 case LOC_TYPEDEF:
653 gdb_puts ("type", outfile);
654 break;
655 case LOC_LABEL:
656 gdb_puts ("label", outfile);
657 break;
658 case LOC_BLOCK:
659 gdb_puts ("function", outfile);
660 break;
661 case LOC_CONST_BYTES:
662 gdb_puts ("constant bytes", outfile);
663 break;
664 case LOC_UNRESOLVED:
665 gdb_puts ("unresolved", outfile);
666 break;
668 gdb_puts ("optimized out", outfile);
669 break;
670 case LOC_COMPUTED:
671 gdb_puts ("computed at runtime", outfile);
672 break;
673 default:
674 gdb_puts ("<invalid location>", outfile);
675 break;
676 }
677 gdb_puts (", ", outfile);
678 gdb_puts (paddress (gdbarch, CORE_ADDR (p->unrelocated_address ())),
679 outfile);
680 gdb_printf (outfile, "\n");
681 }
682}
683
684static void
685dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
686 struct ui_file *outfile)
687{
688 struct gdbarch *gdbarch = objfile->arch ();
689 int i;
690
691 if (psymtab->anonymous)
692 {
693 gdb_printf (outfile, "\nAnonymous partial symtab (%s) ",
694 psymtab->filename);
695 }
696 else
697 {
698 gdb_printf (outfile, "\nPartial symtab for source file %s ",
699 psymtab->filename);
700 }
701 gdb_printf (outfile, "(object %s)\n\n",
702 host_address_to_string (psymtab));
703 gdb_printf (outfile, " Read from object file %s (%s)\n",
705 host_address_to_string (objfile));
706
707 if (psymtab->readin_p (objfile))
709 (outfile,
710 " Full symtab was read (at %s)\n",
711 host_address_to_string (psymtab->get_compunit_symtab (objfile)));
712
713 gdb_printf (outfile, " Symbols cover text addresses ");
714 gdb_puts (paddress (gdbarch, psymtab->text_low (objfile)), outfile);
715 gdb_printf (outfile, "-");
716 gdb_puts (paddress (gdbarch, psymtab->text_high (objfile)), outfile);
717 gdb_printf (outfile, "\n");
718 gdb_printf (outfile, " Depends on %d other partial symtabs.\n",
719 psymtab->number_of_dependencies);
720 for (i = 0; i < psymtab->number_of_dependencies; i++)
721 gdb_printf (outfile, " %d %s\n", i,
722 host_address_to_string (psymtab->dependencies[i]));
723 if (psymtab->user != NULL)
724 gdb_printf (outfile, " Shared partial symtab with user %s\n",
725 host_address_to_string (psymtab->user));
726 if (!psymtab->global_psymbols.empty ())
727 {
729 (gdbarch, objfile, psymtab->global_psymbols,
730 "Global", outfile);
731 }
732 if (!psymtab->static_psymbols.empty ())
733 {
735 (gdbarch, objfile, psymtab->static_psymbols,
736 "Static", outfile);
737 }
738 gdb_printf (outfile, "\n");
739}
740
741/* Count the number of partial symbols in OBJFILE. */
742
743int
745{
746 int count = 0;
747 for (partial_symtab *pst : m_partial_symtabs->range ())
748 {
749 count += pst->global_psymbols.size ();
750 count += pst->static_psymbols.size ();
751 }
752 return count;
753}
754
755/* Psymtab version of print_stats. See its definition in
756 the definition of quick_symbol_functions in symfile.h. */
757
758void
760{
761 int i;
762
763 if (!print_bcache)
764 {
765 int n_psyms = count_psyms ();
766 if (n_psyms > 0)
767 gdb_printf (_(" Number of \"partial\" symbols read: %d\n"),
768 n_psyms);
769
770 i = 0;
772 {
773 if (!ps->readin_p (objfile))
774 i++;
775 }
776 gdb_printf (_(" Number of psym tables (not yet expanded): %d\n"),
777 i);
778 gdb_printf (_(" Total memory used for psymbol cache: %d\n"),
779 m_partial_symtabs->psymbol_cache.memory_used ());
780 }
781 else
782 {
783 gdb_printf (_("Psymbol byte cache statistics:\n"));
784 m_partial_symtabs->psymbol_cache.print_statistics
785 ("partial symbol cache");
786 }
787}
788
789/* Psymtab version of dump. See its definition in
790 the definition of quick_symbol_functions in symfile.h. */
791
792void
794{
795 struct partial_symtab *psymtab;
796
797 if (m_partial_symtabs->psymtabs)
798 {
799 gdb_printf ("Psymtabs:\n");
800 for (psymtab = m_partial_symtabs->psymtabs;
801 psymtab != NULL;
802 psymtab = psymtab->next)
803 gdb_printf ("%s at %s\n",
804 psymtab->filename,
805 host_address_to_string (psymtab));
806 gdb_printf ("\n\n");
807 }
808}
809
810/* Psymtab version of expand_all_symtabs. See its definition in
811 the definition of quick_symbol_functions in symfile.h. */
812
813void
819
820/* Psymtab version of map_symbol_filenames. See its definition in
821 the definition of quick_symbol_functions in symfile.h. */
822
823void
825 (struct objfile *objfile,
826 gdb::function_view<symbol_filename_ftype> fun,
827 bool need_fullname)
828{
830 {
831 const char *fullname;
832
833 if (ps->readin_p (objfile))
834 continue;
835
836 /* We can skip shared psymtabs here, because any file name will be
837 attached to the unshared psymtab. */
838 if (ps->user != NULL)
839 continue;
840
841 /* Anonymous psymtabs don't have a file name. */
842 if (ps->anonymous)
843 continue;
844
845 QUIT;
846 if (need_fullname)
847 fullname = psymtab_to_fullname (ps);
848 else
849 fullname = NULL;
850 fun (ps->filename, fullname);
851 }
852}
853
854/* Finds the fullname that a partial_symtab represents.
855
856 If this functions finds the fullname, it will save it in ps->fullname
857 and it will also return the value.
858
859 If this function fails to find the file that this partial_symtab represents,
860 NULL will be returned and ps->fullname will be set to NULL. */
861
862static const char *
864{
865 gdb_assert (!ps->anonymous);
866
867 /* Use cached copy if we have it.
868 We rely on forget_cached_source_info being called appropriately
869 to handle cases like the file being moved. */
870 if (ps->fullname == NULL)
871 {
872 gdb::unique_xmalloc_ptr<char> fullname
874 ps->fullname = fullname.release ();
875 }
876
877 return ps->fullname;
878}
879
880/* Psymtab version of expand_matching_symbols. See its definition in
881 the definition of quick_symbol_functions in symfile.h. */
882
883void
885 (struct objfile *objfile,
886 const lookup_name_info &name, domain_enum domain,
887 int global,
888 symbol_compare_ftype *ordered_compare)
889{
891 {
892 QUIT;
893 if (!ps->readin_p (objfile)
894 && match_partial_symbol (objfile, ps, global, name, domain,
895 ordered_compare))
897 }
898}
899
900/* A helper for psym_expand_symtabs_matching that handles searching
901 included psymtabs. This returns true if a symbol is found, and
902 false otherwise. It also updates the 'searched_flag' on the
903 various psymtabs that it searches. */
904
905static bool
907 (struct partial_symtab *ps,
908 struct objfile *objfile,
909 block_search_flags search_flags,
910 domain_enum domain,
911 enum search_domain search,
912 const lookup_name_info &lookup_name,
913 gdb::function_view<expand_symtabs_symbol_matcher_ftype> sym_matcher)
914{
915 int keep_going = 1;
917 int i;
918
921
922 /* Recurse into shared psymtabs first, because they may have already
923 been searched, and this could save some time. */
924 for (i = 0; i < ps->number_of_dependencies; ++i)
925 {
926 int r;
927
928 /* Skip non-shared dependencies, these are handled elsewhere. */
929 if (ps->dependencies[i]->user == NULL)
930 continue;
931
933 objfile, search_flags, domain, search,
934 lookup_name, sym_matcher);
935 if (r != 0)
936 {
938 return true;
939 }
940 }
941
942 partial_symbol **gbound = (ps->global_psymbols.data ()
943 + ps->global_psymbols.size ());
944 partial_symbol **sbound = (ps->static_psymbols.data ()
945 + ps->static_psymbols.size ());
946 partial_symbol **bound = gbound;
947
948 /* Go through all of the symbols stored in a partial
949 symtab in one loop. */
950 partial_symbol **psym = ps->global_psymbols.data ();
951
952 if ((search_flags & SEARCH_GLOBAL_BLOCK) == 0)
953 {
954 if (ps->static_psymbols.empty ())
955 keep_going = 0;
956 else
957 {
958 psym = ps->static_psymbols.data ();
959 bound = sbound;
960 }
961 }
962
963 while (keep_going)
964 {
965 if (psym >= bound)
966 {
967 if (bound == gbound && !ps->static_psymbols.empty ()
968 && (search_flags & SEARCH_STATIC_BLOCK) != 0)
969 {
970 psym = ps->static_psymbols.data ();
971 bound = sbound;
972 }
973 else
974 keep_going = 0;
975 continue;
976 }
977 else
978 {
979 QUIT;
980
981 if ((domain == UNDEF_DOMAIN
982 || symbol_matches_domain ((*psym)->ginfo.language (),
983 (*psym)->domain, domain))
984 && (search == ALL_DOMAIN
985 || (search == MODULES_DOMAIN
986 && (*psym)->domain == MODULE_DOMAIN)
987 || (search == VARIABLES_DOMAIN
988 && (*psym)->aclass != LOC_TYPEDEF
989 && (*psym)->aclass != LOC_BLOCK)
990 || (search == FUNCTIONS_DOMAIN
991 && (*psym)->aclass == LOC_BLOCK)
992 || (search == TYPES_DOMAIN
993 && (*psym)->aclass == LOC_TYPEDEF))
994 && psymbol_name_matches (*psym, lookup_name)
995 && (sym_matcher == NULL
996 || sym_matcher ((*psym)->ginfo.search_name ())))
997 {
998 /* Found a match, so notify our caller. */
999 result = PST_SEARCHED_AND_FOUND;
1000 keep_going = 0;
1001 }
1002 }
1003 psym++;
1004 }
1005
1006 ps->searched_flag = result;
1007 return result == PST_SEARCHED_AND_FOUND;
1008}
1009
1010/* Psymtab version of expand_symtabs_matching. See its definition in
1011 the definition of quick_symbol_functions in symfile.h. */
1012
1013bool
1015 (struct objfile *objfile,
1016 gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
1017 const lookup_name_info *lookup_name,
1018 gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
1019 gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
1020 block_search_flags search_flags,
1021 domain_enum domain,
1022 enum search_domain search)
1023{
1024 /* Clear the search flags. */
1026 ps->searched_flag = PST_NOT_SEARCHED;
1027
1028 gdb::optional<lookup_name_info> psym_lookup_name;
1029 if (lookup_name != nullptr)
1030 psym_lookup_name = lookup_name->make_ignore_params ();
1031
1032 /* This invariant is documented in quick-functions.h. */
1033 gdb_assert (lookup_name != nullptr || symbol_matcher == nullptr);
1034
1035 for (partial_symtab *ps : m_partial_symtabs->range ())
1036 {
1037 QUIT;
1038
1039 if (ps->readin_p (objfile))
1040 continue;
1041
1042 if (file_matcher)
1043 {
1044 bool match;
1045
1046 if (ps->anonymous)
1047 continue;
1048
1049 match = file_matcher (ps->filename, false);
1050 if (!match)
1051 {
1052 /* Before we invoke realpath, which can get expensive when many
1053 files are involved, do a quick comparison of the basenames. */
1055 || file_matcher (lbasename (ps->filename), true))
1056 match = file_matcher (psymtab_to_fullname (ps), false);
1057 }
1058 if (!match)
1059 continue;
1060 }
1061
1062 if (lookup_name == nullptr
1063 || recursively_search_psymtabs (ps, objfile, search_flags,
1064 domain, search,
1065 *psym_lookup_name,
1066 symbol_matcher))
1067 {
1069
1070 if (cust != nullptr && expansion_notify != nullptr)
1071 if (!expansion_notify (cust))
1072 return false;
1073 }
1074 }
1075
1076 return true;
1077}
1078
1079/* Psymtab version of has_symbols. See its definition in
1080 the definition of quick_symbol_functions in symfile.h. */
1081
1082bool
1084{
1085 return m_partial_symtabs->psymtabs != NULL;
1086}
1087
1088/* See quick_symbol_functions::has_unexpanded_symtabs in quick-symbol.h. */
1089
1090bool
1092{
1093 for (partial_symtab *psymtab : partial_symbols (objfile))
1094 {
1095 /* Is this already expanded? */
1096 if (psymtab->readin_p (objfile))
1097 continue;
1098
1099 /* It has not yet been expanded. */
1100 return true;
1101 }
1102
1103 return false;
1104}
1105
1106
1107
1108/* Partially fill a partial symtab. It will be completely filled at
1109 the end of the symbol list. */
1110
1112 psymtab_storage *partial_symtabs,
1113 objfile_per_bfd_storage *objfile_per_bfd,
1114 unrelocated_addr textlow)
1115 : partial_symtab (filename, partial_symtabs, objfile_per_bfd)
1116{
1117 set_text_low (textlow);
1118 set_text_high (unrelocated_text_low ()); /* default */
1119}
1120
1121/* Perform "finishing up" operations of a partial symtab. */
1122
1123void
1125{
1126 global_psymbols.shrink_to_fit ();
1127 static_psymbols.shrink_to_fit ();
1128
1129 /* Sort the global list; don't sort the static list. */
1130 std::sort (global_psymbols.begin (),
1131 global_psymbols.end (),
1133 {
1134 return strcmp_iw_ordered (s1->ginfo.search_name (),
1135 s2->ginfo.search_name ()) < 0;
1136 });
1137}
1138
1139/* See psymtab.h. */
1140
1141unsigned long
1142psymbol_bcache::hash (const void *addr, int length)
1143{
1144 unsigned long h = 0;
1145 struct partial_symbol *psymbol = (struct partial_symbol *) addr;
1146 unsigned int lang = psymbol->ginfo.language ();
1147 unsigned int domain = psymbol->domain;
1148 unsigned int theclass = psymbol->aclass;
1149
1150 h = fast_hash (&psymbol->ginfo.m_value, sizeof (psymbol->ginfo.m_value), h);
1151 h = fast_hash (&lang, sizeof (unsigned int), h);
1152 h = fast_hash (&domain, sizeof (unsigned int), h);
1153 h = fast_hash (&theclass, sizeof (unsigned int), h);
1154 /* Note that psymbol names are interned via compute_and_set_names, so
1155 there's no need to hash the contents of the name here. */
1156 h = fast_hash (&psymbol->ginfo.m_name, sizeof (psymbol->ginfo.m_name), h);
1157
1158 return h;
1159}
1160
1161/* See psymtab.h. */
1162
1163int
1164psymbol_bcache::compare (const void *addr1, const void *addr2, int length)
1165{
1166 struct partial_symbol *sym1 = (struct partial_symbol *) addr1;
1167 struct partial_symbol *sym2 = (struct partial_symbol *) addr2;
1168
1169 return (memcmp (&sym1->ginfo.m_value, &sym2->ginfo.m_value,
1170 sizeof (sym1->ginfo.m_value)) == 0
1171 && sym1->ginfo.language () == sym2->ginfo.language ()
1172 && sym1->domain == sym2->domain
1173 && sym1->aclass == sym2->aclass
1174 /* Note that psymbol names are interned via
1175 compute_and_set_names, so there's no need to compare the
1176 contents of the name here. */
1177 && sym1->ginfo.linkage_name () == sym2->ginfo.linkage_name ());
1178}
1179
1180/* See psymtab.h. */
1181
1182void
1184 psymbol_placement where,
1185 psymtab_storage *partial_symtabs,
1186 struct objfile *objfile)
1187{
1188 bool added;
1189
1190 /* Stash the partial symbol away in the cache. */
1191 partial_symbol *psym
1192 = ((struct partial_symbol *)
1193 partial_symtabs->psymbol_cache.insert
1194 (&psymbol, sizeof (struct partial_symbol), &added));
1195
1196 /* Do not duplicate global partial symbols. */
1197 if (where == psymbol_placement::GLOBAL && !added)
1198 return;
1199
1200 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1201 std::vector<partial_symbol *> &list
1202 = (where == psymbol_placement::STATIC
1204 : global_psymbols);
1205 list.push_back (psym);
1206}
1207
1208/* See psymtab.h. */
1209
1210void
1213 enum address_class theclass,
1214 short section,
1215 psymbol_placement where,
1216 unrelocated_addr coreaddr,
1217 enum language language,
1218 psymtab_storage *partial_symtabs,
1219 struct objfile *objfile)
1220{
1221 struct partial_symbol psymbol;
1222 memset (&psymbol, 0, sizeof (psymbol));
1223
1224 psymbol.set_unrelocated_address (coreaddr);
1225 psymbol.ginfo.set_section_index (section);
1226 psymbol.domain = domain;
1227 psymbol.aclass = theclass;
1228 psymbol.ginfo.set_language (language, partial_symtabs->obstack ());
1230
1231 add_psymbol (psymbol, where, partial_symtabs, objfile);
1232}
1233
1234/* See psymtab.h. */
1235
1236partial_symtab::partial_symtab (const char *filename_,
1237 psymtab_storage *partial_symtabs,
1238 objfile_per_bfd_storage *objfile_per_bfd)
1239 : searched_flag (PST_NOT_SEARCHED),
1240 text_low_valid (0),
1241 text_high_valid (0)
1242{
1243 partial_symtabs->install_psymtab (this);
1244
1245 filename = objfile_per_bfd->intern (filename_);
1246
1247 if (symtab_create_debug >= 1)
1248 {
1249 /* Be a bit clever with debugging messages, and don't print objfile
1250 every time, only when it changes. */
1251 static std::string last_bfd_name;
1252 const char *this_bfd_name
1253 = bfd_get_filename (objfile_per_bfd->get_bfd ());
1254
1255 if (last_bfd_name.empty () || last_bfd_name != this_bfd_name)
1256 {
1257 last_bfd_name = this_bfd_name;
1258
1259 symtab_create_debug_printf ("creating one or more psymtabs for %s",
1260 this_bfd_name);
1261 }
1262
1263 symtab_create_debug_printf ("created psymtab %s for module %s",
1264 host_address_to_string (this), filename);
1265 }
1266}
1267
1268/* See psymtab.h. */
1269
1270void
1272{
1273 for (int i = 0; i < number_of_dependencies; ++i)
1274 {
1275 if (!dependencies[i]->readin_p (objfile)
1276 && dependencies[i]->user == NULL)
1277 {
1278 /* Inform about additional files to be read in. */
1279 if (info_verbose)
1280 {
1281 gdb_puts (" ");
1282 gdb_stdout->wrap_here (0);
1283 gdb_puts ("and ");
1284 gdb_stdout->wrap_here (0);
1285 gdb_printf ("%s...", dependencies[i]->filename);
1287 }
1289 }
1290 }
1291}
1292
1293
1294void
1296{
1297 struct partial_symtab **prev_pst;
1298
1299 /* From dbxread.c:
1300 Empty psymtabs happen as a result of header files which don't
1301 have any symbols in them. There can be a lot of them. But this
1302 check is wrong, in that a psymtab with N_SLINE entries but
1303 nothing else is not empty, but we don't realize that. Fixing
1304 that without slowing things down might be tricky. */
1305
1306 /* First, snip it out of the psymtab chain. */
1307
1308 prev_pst = &psymtabs;
1309 while ((*prev_pst) != pst)
1310 prev_pst = &((*prev_pst)->next);
1311 (*prev_pst) = pst->next;
1312 delete pst;
1313}
1314
1315
1316
1317static void
1318maintenance_print_psymbols (const char *args, int from_tty)
1319{
1320 struct ui_file *outfile = gdb_stdout;
1321 char *address_arg = NULL, *source_arg = NULL, *objfile_arg = NULL;
1322 int i, outfile_idx, found;
1323 CORE_ADDR pc = 0;
1324 struct obj_section *section = NULL;
1325
1326 dont_repeat ();
1327
1328 gdb_argv argv (args);
1329
1330 for (i = 0; argv != NULL && argv[i] != NULL; ++i)
1331 {
1332 if (strcmp (argv[i], "-pc") == 0)
1333 {
1334 if (argv[i + 1] == NULL)
1335 error (_("Missing pc value"));
1336 address_arg = argv[++i];
1337 }
1338 else if (strcmp (argv[i], "-source") == 0)
1339 {
1340 if (argv[i + 1] == NULL)
1341 error (_("Missing source file"));
1342 source_arg = argv[++i];
1343 }
1344 else if (strcmp (argv[i], "-objfile") == 0)
1345 {
1346 if (argv[i + 1] == NULL)
1347 error (_("Missing objfile name"));
1348 objfile_arg = argv[++i];
1349 }
1350 else if (strcmp (argv[i], "--") == 0)
1351 {
1352 /* End of options. */
1353 ++i;
1354 break;
1355 }
1356 else if (argv[i][0] == '-')
1357 {
1358 /* Future proofing: Don't allow OUTFILE to begin with "-". */
1359 error (_("Unknown option: %s"), argv[i]);
1360 }
1361 else
1362 break;
1363 }
1364 outfile_idx = i;
1365
1366 if (address_arg != NULL && source_arg != NULL)
1367 error (_("Must specify at most one of -pc and -source"));
1368
1369 stdio_file arg_outfile;
1370
1371 if (argv != NULL && argv[outfile_idx] != NULL)
1372 {
1373 if (argv[outfile_idx + 1] != NULL)
1374 error (_("Junk at end of command"));
1375 gdb::unique_xmalloc_ptr<char> outfile_name
1376 (tilde_expand (argv[outfile_idx]));
1377 if (!arg_outfile.open (outfile_name.get (), FOPEN_WT))
1378 perror_with_name (outfile_name.get ());
1379 outfile = &arg_outfile;
1380 }
1381
1382 if (address_arg != NULL)
1383 {
1384 pc = parse_and_eval_address (address_arg);
1385 /* If we fail to find a section, that's ok, try the lookup anyway. */
1386 section = find_pc_section (pc);
1387 }
1388
1389 found = 0;
1391 {
1392 int printed_objfile_header = 0;
1393 int print_for_objfile = 1;
1394
1395 QUIT;
1396 if (objfile_arg != NULL)
1397 print_for_objfile
1399 objfile_arg);
1400 if (!print_for_objfile)
1401 continue;
1402
1403 for (const auto &iter : objfile->qf)
1404 {
1406 = dynamic_cast<psymbol_functions *> (iter.get ());
1407 if (psf == nullptr)
1408 continue;
1409
1410 if (address_arg != NULL)
1411 {
1412 struct bound_minimal_symbol msymbol;
1413
1414 /* We don't assume each pc has a unique objfile (this is for
1415 debugging). */
1416 struct partial_symtab *ps
1417 = psf->find_pc_sect_psymtab (objfile, pc, section, msymbol);
1418 if (ps != NULL)
1419 {
1420 if (!printed_objfile_header)
1421 {
1422 outfile->printf ("\nPartial symtabs for objfile %s\n",
1424 printed_objfile_header = 1;
1425 }
1426 dump_psymtab (objfile, ps, outfile);
1427 found = 1;
1428 }
1429 }
1430 else
1431 {
1432 for (partial_symtab *ps : psf->partial_symbols (objfile))
1433 {
1434 int print_for_source = 0;
1435
1436 QUIT;
1437 if (source_arg != NULL)
1438 {
1439 print_for_source
1440 = compare_filenames_for_search (ps->filename, source_arg);
1441 found = 1;
1442 }
1443 if (source_arg == NULL
1444 || print_for_source)
1445 {
1446 if (!printed_objfile_header)
1447 {
1448 outfile->printf ("\nPartial symtabs for objfile %s\n",
1450 printed_objfile_header = 1;
1451 }
1452 dump_psymtab (objfile, ps, outfile);
1453 }
1454 }
1455 }
1456 }
1457 }
1458
1459 if (!found)
1460 {
1461 if (address_arg != NULL)
1462 error (_("No partial symtab for address: %s"), address_arg);
1463 if (source_arg != NULL)
1464 error (_("No partial symtab for source file: %s"), source_arg);
1465 }
1466}
1467
1468/* List all the partial symbol tables whose names match REGEXP (optional). */
1469
1470static void
1471maintenance_info_psymtabs (const char *regexp, int from_tty)
1472{
1473 if (regexp)
1474 re_comp (regexp);
1475
1476 for (struct program_space *pspace : program_spaces)
1477 for (objfile *objfile : pspace->objfiles ())
1478 {
1479 struct gdbarch *gdbarch = objfile->arch ();
1480
1481 /* We don't want to print anything for this objfile until we
1482 actually find a symtab whose name matches. */
1483 int printed_objfile_start = 0;
1484
1485 for (const auto &iter : objfile->qf)
1486 {
1488 = dynamic_cast<psymbol_functions *> (iter.get ());
1489 if (psf == nullptr)
1490 continue;
1491 for (partial_symtab *psymtab : psf->partial_symbols (objfile))
1492 {
1493 QUIT;
1494
1495 if (! regexp
1496 || re_exec (psymtab->filename))
1497 {
1498 if (! printed_objfile_start)
1499 {
1500 gdb_printf ("{ objfile %s ", objfile_name (objfile));
1501 gdb_stdout->wrap_here (2);
1502 gdb_printf ("((struct objfile *) %s)\n",
1503 host_address_to_string (objfile));
1504 printed_objfile_start = 1;
1505 }
1506
1507 gdb_printf (" { psymtab %s ", psymtab->filename);
1508 gdb_stdout->wrap_here (4);
1509 gdb_printf ("((struct partial_symtab *) %s)\n",
1510 host_address_to_string (psymtab));
1511
1512 gdb_printf (" readin %s\n",
1513 psymtab->readin_p (objfile) ? "yes" : "no");
1514 gdb_printf (" fullname %s\n",
1515 psymtab->fullname
1516 ? psymtab->fullname : "(null)");
1517 gdb_printf (" text addresses ");
1519 psymtab->text_low (objfile)));
1520 gdb_printf (" -- ");
1522 psymtab->text_high (objfile)));
1523 gdb_printf ("\n");
1524 gdb_printf (" globals ");
1525 if (!psymtab->global_psymbols.empty ())
1527 ("(* (struct partial_symbol **) %s @ %d)\n",
1528 host_address_to_string (psymtab->global_psymbols.data ()),
1529 (int) psymtab->global_psymbols.size ());
1530 else
1531 gdb_printf ("(none)\n");
1532 gdb_printf (" statics ");
1533 if (!psymtab->static_psymbols.empty ())
1535 ("(* (struct partial_symbol **) %s @ %d)\n",
1536 host_address_to_string (psymtab->static_psymbols.data ()),
1537 (int) psymtab->static_psymbols.size ());
1538 else
1539 gdb_printf ("(none)\n");
1540 if (psymtab->user)
1541 gdb_printf (" user %s "
1542 "((struct partial_symtab *) %s)\n",
1543 psymtab->user->filename,
1544 host_address_to_string (psymtab->user));
1545 gdb_printf (" dependencies ");
1546 if (psymtab->number_of_dependencies)
1547 {
1548 int i;
1549
1550 gdb_printf ("{\n");
1551 for (i = 0; i < psymtab->number_of_dependencies; i++)
1552 {
1553 struct partial_symtab *dep = psymtab->dependencies[i];
1554
1555 /* Note the string concatenation there --- no
1556 comma. */
1557 gdb_printf (" psymtab %s "
1558 "((struct partial_symtab *) %s)\n",
1559 dep->filename,
1560 host_address_to_string (dep));
1561 }
1562 gdb_printf (" }\n");
1563 }
1564 else
1565 gdb_printf ("(none)\n");
1566 gdb_printf (" }\n");
1567 }
1568 }
1569 }
1570
1571 if (printed_objfile_start)
1572 gdb_printf ("}\n");
1573 }
1574}
1575
1576/* Check consistency of currently expanded psymtabs vs symtabs. */
1577
1578static void
1579maintenance_check_psymtabs (const char *ignore, int from_tty)
1580{
1581 struct symbol *sym;
1582 struct compunit_symtab *cust = NULL;
1583 const struct blockvector *bv;
1584 const struct block *b;
1585
1587 {
1588 for (const auto &iter : objfile->qf)
1589 {
1591 = dynamic_cast<psymbol_functions *> (iter.get ());
1592 if (psf == nullptr)
1593 continue;
1594
1595 for (partial_symtab *ps : psf->partial_symbols (objfile))
1596 {
1597 struct gdbarch *gdbarch = objfile->arch ();
1598
1599 /* We don't call psymtab_to_symtab here because that may cause symtab
1600 expansion. When debugging a problem it helps if checkers leave
1601 things unchanged. */
1602 cust = ps->get_compunit_symtab (objfile);
1603
1604 /* First do some checks that don't require the associated symtab. */
1605 if (ps->text_high (objfile) < ps->text_low (objfile))
1606 {
1607 gdb_printf ("Psymtab ");
1608 gdb_puts (ps->filename);
1609 gdb_printf (" covers bad range ");
1610 gdb_puts (paddress (gdbarch, ps->text_low (objfile)));
1611 gdb_printf (" - ");
1612 gdb_puts (paddress (gdbarch, ps->text_high (objfile)));
1613 gdb_printf ("\n");
1614 continue;
1615 }
1616
1617 /* Now do checks requiring the associated symtab. */
1618 if (cust == NULL)
1619 continue;
1620 bv = cust->blockvector ();
1621 b = bv->static_block ();
1622 for (partial_symbol *psym : ps->static_psymbols)
1623 {
1624 /* Skip symbols for inlined functions without address. These may
1625 or may not have a match in the full symtab. */
1626 if (psym->aclass == LOC_BLOCK
1627 && psym->ginfo.value_address () == 0)
1628 continue;
1629
1630 sym = block_lookup_symbol (b, psym->ginfo.search_name (),
1632 psym->domain);
1633 if (!sym)
1634 {
1635 gdb_printf ("Static symbol `");
1636 gdb_puts (psym->ginfo.linkage_name ());
1637 gdb_printf ("' only found in ");
1638 gdb_puts (ps->filename);
1639 gdb_printf (" psymtab\n");
1640 }
1641 }
1642 b = bv->global_block ();
1643 for (partial_symbol *psym : ps->global_psymbols)
1644 {
1645 sym = block_lookup_symbol (b, psym->ginfo.search_name (),
1647 psym->domain);
1648 if (!sym)
1649 {
1650 gdb_printf ("Global symbol `");
1651 gdb_puts (psym->ginfo.linkage_name ());
1652 gdb_printf ("' only found in ");
1653 gdb_puts (ps->filename);
1654 gdb_printf (" psymtab\n");
1655 }
1656 }
1657 if (ps->unrelocated_text_high () != unrelocated_addr (0)
1658 && (ps->text_low (objfile) < b->start ()
1659 || ps->text_high (objfile) > b->end ()))
1660 {
1661 gdb_printf ("Psymtab ");
1662 gdb_puts (ps->filename);
1663 gdb_printf (" covers ");
1664 gdb_puts (paddress (gdbarch, ps->text_low (objfile)));
1665 gdb_printf (" - ");
1666 gdb_puts (paddress (gdbarch, ps->text_high (objfile)));
1667 gdb_printf (" but symtab covers only ");
1668 gdb_puts (paddress (gdbarch, b->start ()));
1669 gdb_printf (" - ");
1670 gdb_puts (paddress (gdbarch, b->end ()));
1671 gdb_printf ("\n");
1672 }
1673 }
1674 }
1675 }
1676}
1677
1678void _initialize_psymtab ();
1679void
1681{
1683Print dump of current partial symbol definitions.\n\
1684Usage: mt print psymbols [-objfile OBJFILE] [-pc ADDRESS] [--] [OUTFILE]\n\
1685 mt print psymbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
1686Entries in the partial symbol table are dumped to file OUTFILE,\n\
1687or the terminal if OUTFILE is unspecified.\n\
1688If ADDRESS is provided, dump only the symbols for the file with code at that address.\n\
1689If SOURCE is provided, dump only that file's symbols.\n\
1690If OBJFILE is provided, dump only that object file's symbols."),
1692
1694List the partial symbol tables for all object files.\n\
1695This does not include information about individual partial symbols,\n\
1696just the symbol table structures themselves."),
1698
1700 _("\
1701Check consistency of currently expanded psymtabs versus symtabs."),
1703}
const char *const name
void xfree(void *)
constexpr std::string_view s1
Definition 2.cc:26
constexpr std::string_view s2
Definition 2.cc:27
struct symbol * block_lookup_symbol(const struct block *block, const char *name, symbol_name_match_type match_type, const domain_enum domain)
Definition block.c:676
const char * c_str() const
Definition symtab.h:246
lookup_name_info make_ignore_params() const
Definition symtab.h:256
struct partial_symtab * psymtabs
Definition psymtab.h:122
void discard_psymtab(struct partial_symtab *pst)
Definition psymtab.c:1295
void install_psymtab(partial_symtab *pst)
Definition psymtab.c:71
next_range< partial_symtab > partial_symtab_range
Definition psymtab.h:107
struct obstack * obstack()
Definition psymtab.h:87
psymbol_bcache psymbol_cache
Definition psymtab.h:127
bool open(const char *name, const char *mode)
Definition ui-file.c:263
void printf(const char *,...) ATTRIBUTE_PRINTF(2
Definition ui-file.c:40
struct cmd_list_element * maintenanceprintlist
Definition cli-cmds.c:151
struct cmd_list_element * maintenancelist
Definition cli-cmds.c:143
struct cmd_list_element * maintenanceinfolist
Definition cli-cmds.c:147
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
Definition cli-decode.c:233
void dont_repeat()
Definition top.c:696
@ class_maintenance
Definition command.h:65
EXTERN_C char * re_comp(const char *)
bool info_verbose
Definition top.c:1941
language
Definition defs.h:211
@ language_unknown
Definition defs.h:212
#define QUIT
Definition defs.h:187
CORE_ADDR parse_and_eval_address(const char *exp)
Definition eval.c:52
static void keep_going(struct execution_control_state *ecs)
Definition infrun.c:8568
const struct language_defn * language_def(enum language lang)
Definition language.c:439
@ OBJF_PSYMTABS_READ
struct obj_section * find_pc_section(CORE_ADDR pc)
Definition objfiles.c:1128
const char * objfile_name(const struct objfile *objfile)
Definition objfiles.c:1259
std::string copy_name(struct stoken token)
Definition parse.c:319
struct program_space * current_program_space
Definition progspace.c:40
std::vector< struct program_space * > program_spaces
Definition progspace.c:37
static struct compunit_symtab * psymtab_to_symtab(struct objfile *objfile, struct partial_symtab *pst)
Definition psymtab.c:504
static struct partial_symbol * match_partial_symbol(struct objfile *objfile, struct partial_symtab *pst, int global, const lookup_name_info &name, domain_enum domain, symbol_compare_ftype *ordered_compare)
Definition psymtab.c:330
static void print_partial_symbols(struct gdbarch *gdbarch, struct objfile *objfile, const std::vector< partial_symbol * > &symbols, const char *what, struct ui_file *outfile)
Definition psymtab.c:587
void _initialize_psymtab()
Definition psymtab.c:1680
static bool recursively_search_psymtabs(struct partial_symtab *ps, struct objfile *objfile, block_search_flags search_flags, domain_enum domain, enum search_domain search, const lookup_name_info &lookup_name, gdb::function_view< expand_symtabs_symbol_matcher_ftype > sym_matcher)
Definition psymtab.c:907
static void dump_psymtab(struct objfile *objfile, struct partial_symtab *psymtab, struct ui_file *outfile)
Definition psymtab.c:685
static bool psymbol_name_matches(partial_symbol *psym, const lookup_name_info &lookup_name)
Definition psymtab.c:312
static void maintenance_check_psymtabs(const char *ignore, int from_tty)
Definition psymtab.c:1579
static struct partial_symbol * find_pc_sect_psymbol(struct objfile *, struct partial_symtab *, CORE_ADDR, struct obj_section *)
Definition psymtab.c:218
static void maintenance_info_psymtabs(const char *regexp, int from_tty)
Definition psymtab.c:1471
static struct partial_symtab * find_pc_sect_psymtab_closer(struct objfile *objfile, CORE_ADDR pc, struct obj_section *section, struct partial_symtab *pst, struct bound_minimal_symbol msymbol)
Definition psymtab.c:92
static struct partial_symbol * lookup_partial_symbol(struct objfile *, struct partial_symtab *, const lookup_name_info &, int, domain_enum)
Definition psymtab.c:410
static void maintenance_print_psymbols(const char *args, int from_tty)
Definition psymtab.c:1318
static const char * psymtab_to_fullname(struct partial_symtab *ps)
Definition psymtab.c:863
psymtab_search_status
Definition psymtab.h:198
@ PST_NOT_SEARCHED
Definition psymtab.h:199
@ PST_SEARCHED_AND_NOT_FOUND
Definition psymtab.h:201
@ PST_SEARCHED_AND_FOUND
Definition psymtab.h:200
psymbol_placement
Definition psymtab.h:208
int symbol_compare_ftype(const char *string1, const char *string2)
@ SEARCH_GLOBAL_BLOCK
@ SEARCH_STATIC_BLOCK
gdb::unique_xmalloc_ptr< char > find_source_or_rewrite(const char *filename, const char *dirname)
Definition source.c:1199
Definition block.h:109
CORE_ADDR start() const
Definition block.h:111
CORE_ADDR end() const
Definition block.h:119
struct block * static_block()
Definition block.h:405
struct block * global_block()
Definition block.h:397
CORE_ADDR value_address() const
Definition minsyms.h:41
struct minimal_symbol * minsym
Definition minsyms.h:49
symtab * primary_filetab() const
Definition symtab.c:415
struct blockvector * blockvector()
Definition symtab.h:1847
const void * insert(const void *addr, int length, bool *added=nullptr)
Definition bcache.c:143
void set_section_index(short idx)
Definition symtab.h:614
void compute_and_set_names(gdb::string_view linkage_name, bool copy_name, struct objfile_per_bfd_storage *per_bfd, gdb::optional< hashval_t > hash=gdb::optional< hashval_t >())
Definition symtab.c:943
const char * search_name() const
Definition symtab.c:1106
enum language language() const
Definition symtab.h:502
void set_language(enum language language, struct obstack *obstack)
Definition symtab.c:803
const char * m_name
Definition symtab.h:545
const char * linkage_name() const
Definition symtab.h:460
union general_symbol_info::@182 m_value
symbol_name_matcher_ftype * get_symbol_name_matcher(const lookup_name_info &lookup_name) const
Definition language.c:666
const char * intern(const char *str)
Definition objfiles.h:235
bfd * get_bfd() const
Definition objfiles.h:249
const struct sym_fns * sf
Definition objfiles.h:768
struct gdbarch * arch() const
Definition objfiles.h:507
struct objfile_per_bfd_storage * per_bfd
Definition objfiles.h:744
objfile_flags flags
Definition objfiles.h:724
std::forward_list< quick_symbol_functions_up > qf
Definition objfiles.h:772
void set_unrelocated_address(unrelocated_addr addr)
Definition psymtab.h:172
__extension__ enum domain_enum domain
Definition psymtab.h:184
CORE_ADDR address(const struct objfile *objfile) const
Definition psymtab.h:164
struct general_symbol_info ginfo
Definition psymtab.h:180
__extension__ enum address_class aclass
Definition psymtab.h:190
struct partial_symtab * user
Definition psymtab.h:428
virtual struct compunit_symtab * get_compunit_symtab(struct objfile *) const =0
struct partial_symtab ** dependencies
Definition psymtab.h:439
std::vector< partial_symbol * > static_psymbols
Definition psymtab.h:456
unrelocated_addr unrelocated_text_low() const
Definition psymtab.h:286
partial_symtab(const char *filename, psymtab_storage *partial_symtabs, objfile_per_bfd_storage *objfile_per_bfd) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
Definition psymtab.c:1236
const char * dirname
Definition psymtab.h:389
__extension__ enum psymtab_search_status searched_flag
Definition psymtab.h:464
const char * filename
Definition psymtab.h:381
virtual bool readin_p(struct objfile *) const =0
void set_text_high(unrelocated_addr addr)
Definition psymtab.h:318
virtual void expand_psymtab(struct objfile *)=0
std::vector< partial_symbol * > global_psymbols
Definition psymtab.h:447
int number_of_dependencies
Definition psymtab.h:441
virtual void read_symtab(struct objfile *)=0
struct partial_symtab * next
Definition psymtab.h:375
CORE_ADDR text_high(struct objfile *objfile) const
Definition psymtab.h:305
void expand_dependencies(struct objfile *)
Definition psymtab.c:1271
void set_text_low(unrelocated_addr addr)
Definition psymtab.h:311
void add_psymbol(gdb::string_view name, bool copy_name, domain_enum domain, enum address_class theclass, short section, psymbol_placement where, unrelocated_addr coreaddr, enum language language, psymtab_storage *partial_symtabs, struct objfile *objfile)
Definition psymtab.c:1211
CORE_ADDR text_low(struct objfile *objfile) const
Definition psymtab.h:299
char * fullname
Definition psymtab.h:385
objfiles_range objfiles()
Definition progspace.h:209
unsigned long hash(const void *addr, int length) override
Definition psymtab.c:1142
int compare(const void *left, const void *right, int length) override
Definition psymtab.c:1164
enum language lookup_global_symbol_language(struct objfile *objfile, const char *name, domain_enum domain, bool *symbol_found_p) override
Definition psymtab.c:281
struct compunit_symtab * find_pc_sect_compunit_symtab(struct objfile *objfile, struct bound_minimal_symbol msymbol, CORE_ADDR pc, struct obj_section *section, int warn_if_readin) override
Definition psymtab.c:190
void dump(struct objfile *objfile) override
Definition psymtab.c:793
void print_stats(struct objfile *objfile, bool print_bcache) override
Definition psymtab.c:759
void expand_matching_symbols(struct objfile *, const lookup_name_info &lookup_name, domain_enum domain, int global, symbol_compare_ftype *ordered_compare) override
Definition psymtab.c:885
void expand_all_symtabs(struct objfile *objfile) override
Definition psymtab.c:814
psymtab_storage::partial_symtab_range partial_symbols(struct objfile *objfile)
Definition psymtab.c:82
void forget_cached_source_info(struct objfile *objfile) override
Definition psymtab.c:574
void map_symbol_filenames(struct objfile *objfile, gdb::function_view< symbol_filename_ftype > fun, bool need_fullname) override
Definition psymtab.c:825
struct symtab * find_last_source_symtab(struct objfile *objfile) override
Definition psymtab.c:537
std::shared_ptr< psymtab_storage > m_partial_symtabs
Definition psymtab.h:695
bool has_unexpanded_symtabs(struct objfile *objfile) override
Definition psymtab.c:1091
struct partial_symtab * find_pc_sect_psymtab(struct objfile *objfile, CORE_ADDR pc, struct obj_section *section, struct bound_minimal_symbol msymbol)
Definition psymtab.c:166
bool expand_symtabs_matching(struct objfile *objfile, gdb::function_view< expand_symtabs_file_matcher_ftype > file_matcher, const lookup_name_info *lookup_name, gdb::function_view< expand_symtabs_symbol_matcher_ftype > symbol_matcher, gdb::function_view< expand_symtabs_exp_notify_ftype > expansion_notify, block_search_flags search_flags, domain_enum domain, enum search_domain kind) override
Definition psymtab.c:1015
bool has_symbols(struct objfile *objfile) override
Definition psymtab.c:1083
scoped_restore_tmpl< int > increment_reading_symtab(void)
Definition symfile.c:185
bool symbol_matches_search_name(const struct general_symbol_info *gsymbol, const lookup_name_info &name)
Definition symtab.c:1127
bool compare_filenames_for_search(const char *filename, const char *search_name)
Definition symtab.c:489
bool basenames_may_differ
Definition symtab.c:270
bool matching_obj_sections(struct obj_section *obj_first, struct obj_section *obj_second)
Definition symtab.c:1142
bool symbol_matches_domain(enum language symbol_language, domain_enum symbol_domain, domain_enum domain)
Definition symtab.c:2649
unsigned int symtab_create_debug
Definition symtab.c:254
search_domain
Definition symtab.h:945
@ VARIABLES_DOMAIN
Definition symtab.h:948
@ FUNCTIONS_DOMAIN
Definition symtab.h:951
@ TYPES_DOMAIN
Definition symtab.h:954
@ MODULES_DOMAIN
Definition symtab.h:957
@ ALL_DOMAIN
Definition symtab.h:960
address_class
Definition symtab.h:968
@ LOC_STATIC
Definition symtab.h:979
@ LOC_BLOCK
Definition symtab.h:1028
@ LOC_LABEL
Definition symtab.h:1022
@ LOC_REGISTER
Definition symtab.h:993
@ LOC_REF_ARG
Definition symtab.h:1001
@ LOC_UNRESOLVED
Definition symtab.h:1057
@ LOC_LOCAL
Definition symtab.h:1013
@ LOC_CONST
Definition symtab.h:975
@ LOC_CONST_BYTES
Definition symtab.h:1033
@ LOC_UNDEF
Definition symtab.h:971
@ LOC_OPTIMIZED_OUT
Definition symtab.h:1062
@ LOC_TYPEDEF
Definition symtab.h:1018
@ LOC_REGPARM_ADDR
Definition symtab.h:1009
@ LOC_COMPUTED
Definition symtab.h:1066
@ LOC_ARG
Definition symtab.h:997
bool symbol_name_matcher_ftype(const char *symbol_search_name, const lookup_name_info &lookup_name, completion_match_result *comp_match_res)
Definition symtab.h:399
domain_enum
Definition symtab.h:900
@ VAR_DOMAIN
Definition symtab.h:910
@ STRUCT_DOMAIN
Definition symtab.h:916
@ LABEL_DOMAIN
Definition symtab.h:924
@ COMMON_BLOCK_DOMAIN
Definition symtab.h:928
@ UNDEF_DOMAIN
Definition symtab.h:905
@ MODULE_DOMAIN
Definition symtab.h:920
#define symtab_create_debug_printf(fmt,...)
Definition symtab.h:2683
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition utils.c:3166
int strcmp_iw_ordered(const char *string1, const char *string2)
Definition utils.c:3077
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition utils.c:1886
void gdb_flush(struct ui_file *stream)
Definition utils.c:1498
void gdb_puts(const char *linebuffer, struct ui_file *stream)
Definition utils.c:1809
#define gdb_stdout
Definition utils.h:182