1 /* Partial symbol tables.
3 Copyright (C) 2009-2022 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
25 #include "filenames.h"
31 #include "readline/tilde.h"
32 #include "gdb_regex.h"
33 #include "dictionary.h"
35 #include "cp-support.h"
40 static struct partial_symbol
*lookup_partial_symbol (struct objfile
*,
41 struct partial_symtab
*,
42 const lookup_name_info
&,
46 static const char *psymtab_to_fullname (struct partial_symtab
*ps
);
48 static struct partial_symbol
*find_pc_sect_psymbol (struct objfile
*,
49 struct partial_symtab
*,
51 struct obj_section
*);
53 static struct compunit_symtab
*psymtab_to_symtab (struct objfile
*objfile
,
54 struct partial_symtab
*pst
);
56 psymtab_storage::~psymtab_storage ()
58 partial_symtab
*iter
= psymtabs
;
59 while (iter
!= nullptr)
61 partial_symtab
*next
= iter
->next
;
70 psymtab_storage::install_psymtab (partial_symtab
*pst
)
78 /* Ensure that the partial symbols for OBJFILE have been loaded. This
79 will print a message when symbols are loaded. This function
80 returns a range adapter suitable for iterating over the psymtabs of
83 psymtab_storage::partial_symtab_range
84 psymbol_functions::require_partial_symbols (struct objfile
*objfile
)
86 objfile
->require_partial_symbols (true);
87 return m_partial_symtabs
->range ();
90 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
91 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
93 static struct partial_symtab
*
94 find_pc_sect_psymtab_closer (struct objfile
*objfile
,
95 CORE_ADDR pc
, struct obj_section
*section
,
96 struct partial_symtab
*pst
,
97 struct bound_minimal_symbol msymbol
)
99 struct partial_symtab
*tpst
;
100 struct partial_symtab
*best_pst
= pst
;
101 CORE_ADDR best_addr
= pst
->text_low (objfile
);
103 gdb_assert (!pst
->psymtabs_addrmap_supported
);
105 /* An objfile that has its functions reordered might have
106 many partial symbol tables containing the PC, but
107 we want the partial symbol table that contains the
108 function containing the PC. */
109 if (!(objfile
->flags
& OBJF_REORDERED
)
110 && section
== NULL
) /* Can't validate section this way. */
113 if (msymbol
.minsym
== NULL
)
116 /* The code range of partial symtabs sometimes overlap, so, in
117 the loop below, we need to check all partial symtabs and
118 find the one that fits better for the given PC address. We
119 select the partial symtab that contains a symbol whose
120 address is closest to the PC address. By closest we mean
121 that find_pc_sect_symbol returns the symbol with address
122 that is closest and still less than the given PC. */
123 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
125 if (pc
>= tpst
->text_low (objfile
) && pc
< tpst
->text_high (objfile
))
127 struct partial_symbol
*p
;
130 /* NOTE: This assumes that every psymbol has a
131 corresponding msymbol, which is not necessarily
132 true; the debug info might be much richer than the
133 object's symbol table. */
134 p
= find_pc_sect_psymbol (objfile
, tpst
, pc
, section
);
136 && (p
->address (objfile
) == BMSYMBOL_VALUE_ADDRESS (msymbol
)))
139 /* Also accept the textlow value of a psymtab as a
140 "symbol", to provide some support for partial
141 symbol tables with line information but no debug
142 symbols (e.g. those produced by an assembler). */
144 this_addr
= p
->address (objfile
);
146 this_addr
= tpst
->text_low (objfile
);
148 /* Check whether it is closer than our current
149 BEST_ADDR. Since this symbol address is
150 necessarily lower or equal to PC, the symbol closer
151 to PC is the symbol which address is the highest.
152 This way we return the psymtab which contains such
153 best match symbol. This can help in cases where the
154 symbol information/debuginfo is not complete, like
155 for instance on IRIX6 with gcc, where no debug info
156 is emitted for statics. (See also the nodebug.exp
158 if (this_addr
> best_addr
)
160 best_addr
= this_addr
;
168 /* See psympriv.h. */
170 struct partial_symtab
*
171 psymbol_functions::find_pc_sect_psymtab (struct objfile
*objfile
,
173 struct obj_section
*section
,
174 struct bound_minimal_symbol msymbol
)
176 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better
177 granularity than the later used TEXTLOW/TEXTHIGH one. However, we need
178 to take care as the PSYMTABS_ADDRMAP can hold things other than partial
179 symtabs in some cases.
181 This function should only be called for objfiles that are using partial
182 symtabs, not for objfiles that are using indexes (.gdb_index or
183 .debug_names), however 'maintenance print psymbols' calls this function
184 directly for all objfiles. If we assume that PSYMTABS_ADDRMAP contains
185 partial symtabs then we will end up returning a pointer to an object
186 that is not a partial_symtab, which doesn't end well. */
188 if (m_partial_symtabs
->psymtabs
!= NULL
189 && m_partial_symtabs
->psymtabs_addrmap
!= NULL
)
191 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
193 struct partial_symtab
*pst
194 = ((struct partial_symtab
*)
195 addrmap_find (m_partial_symtabs
->psymtabs_addrmap
,
199 /* FIXME: addrmaps currently do not handle overlayed sections,
200 so fall back to the non-addrmap case if we're debugging
201 overlays and the addrmap returned the wrong section. */
202 if (overlay_debugging
&& msymbol
.minsym
!= NULL
&& section
!= NULL
)
204 struct partial_symbol
*p
;
206 /* NOTE: This assumes that every psymbol has a
207 corresponding msymbol, which is not necessarily
208 true; the debug info might be much richer than the
209 object's symbol table. */
210 p
= find_pc_sect_psymbol (objfile
, pst
, pc
, section
);
212 || (p
->address (objfile
)
213 != BMSYMBOL_VALUE_ADDRESS (msymbol
)))
217 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
218 PSYMTABS_ADDRMAP we used has already the best 1-byte
219 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
220 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
229 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
230 which still have no corresponding full SYMTABs read. But it is not
231 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
234 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
235 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
236 debug info type in single OBJFILE. */
238 for (partial_symtab
*pst
: require_partial_symbols (objfile
))
239 if (!pst
->psymtabs_addrmap_supported
240 && pc
>= pst
->text_low (objfile
) && pc
< pst
->text_high (objfile
))
242 struct partial_symtab
*best_pst
;
244 best_pst
= find_pc_sect_psymtab_closer (objfile
, pc
, section
, pst
,
246 if (best_pst
!= NULL
)
253 /* Psymtab version of find_pc_sect_compunit_symtab. See its definition in
254 the definition of quick_symbol_functions in symfile.h. */
256 struct compunit_symtab
*
257 psymbol_functions::find_pc_sect_compunit_symtab
258 (struct objfile
*objfile
,
259 struct bound_minimal_symbol msymbol
,
261 struct obj_section
*section
,
264 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
,
269 if (warn_if_readin
&& ps
->readin_p (objfile
))
270 /* Might want to error() here (in case symtab is corrupt and
271 will cause a core dump), but maybe we can successfully
272 continue, so let's not. */
274 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
275 paddress (objfile
->arch (), pc
));
276 psymtab_to_symtab (objfile
, ps
);
277 return ps
->get_compunit_symtab (objfile
);
282 /* Find which partial symbol within a psymtab matches PC and SECTION.
283 Return NULL if none. */
285 static struct partial_symbol
*
286 find_pc_sect_psymbol (struct objfile
*objfile
,
287 struct partial_symtab
*psymtab
, CORE_ADDR pc
,
288 struct obj_section
*section
)
290 struct partial_symbol
*best
= NULL
;
292 const CORE_ADDR textlow
= psymtab
->text_low (objfile
);
294 gdb_assert (psymtab
!= NULL
);
296 /* Cope with programs that start at address 0. */
297 best_pc
= (textlow
!= 0) ? textlow
- 1 : 0;
299 /* Search the global symbols as well as the static symbols, so that
300 find_pc_partial_function doesn't use a minimal symbol and thus
301 cache a bad endaddr. */
302 for (partial_symbol
*p
: psymtab
->global_psymbols
)
304 if (p
->domain
== VAR_DOMAIN
305 && p
->aclass
== LOC_BLOCK
306 && pc
>= p
->address (objfile
)
307 && (p
->address (objfile
) > best_pc
308 || (psymtab
->text_low (objfile
) == 0
309 && best_pc
== 0 && p
->address (objfile
) == 0)))
311 if (section
!= NULL
) /* Match on a specific section. */
313 if (!matching_obj_sections (p
->obj_section (objfile
),
317 best_pc
= p
->address (objfile
);
322 for (partial_symbol
*p
: psymtab
->static_psymbols
)
324 if (p
->domain
== VAR_DOMAIN
325 && p
->aclass
== LOC_BLOCK
326 && pc
>= p
->address (objfile
)
327 && (p
->address (objfile
) > best_pc
328 || (psymtab
->text_low (objfile
) == 0
329 && best_pc
== 0 && p
->address (objfile
) == 0)))
331 if (section
!= NULL
) /* Match on a specific section. */
333 if (!matching_obj_sections (p
->obj_section (objfile
),
337 best_pc
= p
->address (objfile
);
345 /* Psymtab version of lookup_global_symbol_language. See its definition in
346 the definition of quick_symbol_functions in symfile.h. */
349 psymbol_functions::lookup_global_symbol_language (struct objfile
*objfile
,
352 bool *symbol_found_p
)
354 *symbol_found_p
= false;
355 if (objfile
->sf
== NULL
)
356 return language_unknown
;
358 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
360 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
362 struct partial_symbol
*psym
;
363 if (ps
->readin_p (objfile
))
366 psym
= lookup_partial_symbol (objfile
, ps
, lookup_name
, 1, domain
);
369 *symbol_found_p
= true;
370 return psym
->ginfo
.language ();
374 return language_unknown
;
377 /* Returns true if PSYM matches LOOKUP_NAME. */
380 psymbol_name_matches (partial_symbol
*psym
,
381 const lookup_name_info
&lookup_name
)
383 const language_defn
*lang
= language_def (psym
->ginfo
.language ());
384 symbol_name_matcher_ftype
*name_match
385 = lang
->get_symbol_name_matcher (lookup_name
);
386 return name_match (psym
->ginfo
.search_name (), lookup_name
, NULL
);
389 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
390 the global block of PST if GLOBAL, and otherwise the static block.
391 MATCH is the comparison operation that returns true iff MATCH (s,
392 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
393 non-null, the symbols in the block are assumed to be ordered
394 according to it (allowing binary search). It must be compatible
395 with MATCH. Returns the symbol, if found, and otherwise NULL. */
397 static struct partial_symbol
*
398 match_partial_symbol (struct objfile
*objfile
,
399 struct partial_symtab
*pst
, int global
,
400 const lookup_name_info
&name
, domain_enum domain
,
401 symbol_compare_ftype
*ordered_compare
)
403 struct partial_symbol
**start
, **psym
;
404 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
406 ? pst
->global_psymbols
.size ()
407 : pst
->static_psymbols
.size ());
408 int do_linear_search
= 1;
414 &pst
->global_psymbols
[0] :
415 &pst
->static_psymbols
[0]);
417 if (global
&& ordered_compare
) /* Can use a binary search. */
419 do_linear_search
= 0;
421 /* Binary search. This search is guaranteed to end with center
422 pointing at the earliest partial symbol whose name might be
423 correct. At that point *all* partial symbols with an
424 appropriate name will be checked against the correct
428 top
= start
+ length
- 1;
432 center
= bottom
+ (top
- bottom
) / 2;
433 gdb_assert (center
< top
);
435 enum language lang
= (*center
)->ginfo
.language ();
436 const char *lang_ln
= name
.language_lookup_name (lang
);
438 if (ordered_compare ((*center
)->ginfo
.search_name (),
444 gdb_assert (top
== bottom
);
446 while (top
<= real_top
447 && psymbol_name_matches (*top
, name
))
449 if (symbol_matches_domain ((*top
)->ginfo
.language (),
450 (*top
)->domain
, domain
))
456 /* Can't use a binary search or else we found during the binary search that
457 we should also do a linear search. */
459 if (do_linear_search
)
461 for (psym
= start
; psym
< start
+ length
; psym
++)
463 if (symbol_matches_domain ((*psym
)->ginfo
.language (),
464 (*psym
)->domain
, domain
)
465 && psymbol_name_matches (*psym
, name
))
473 /* Look, in partial_symtab PST, for symbol whose natural name is
474 LOOKUP_NAME. Check the global symbols if GLOBAL, the static
477 static struct partial_symbol
*
478 lookup_partial_symbol (struct objfile
*objfile
,
479 struct partial_symtab
*pst
,
480 const lookup_name_info
&lookup_name
,
481 int global
, domain_enum domain
)
483 struct partial_symbol
**start
, **psym
;
484 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
486 ? pst
->global_psymbols
.size ()
487 : pst
->static_psymbols
.size ());
488 int do_linear_search
= 1;
494 &pst
->global_psymbols
[0] :
495 &pst
->static_psymbols
[0]);
497 if (global
) /* This means we can use a binary search. */
499 do_linear_search
= 0;
501 /* Binary search. This search is guaranteed to end with center
502 pointing at the earliest partial symbol whose name might be
503 correct. At that point *all* partial symbols with an
504 appropriate name will be checked against the correct
508 top
= start
+ length
- 1;
512 center
= bottom
+ (top
- bottom
) / 2;
514 gdb_assert (center
< top
);
516 if (strcmp_iw_ordered ((*center
)->ginfo
.search_name (),
517 lookup_name
.c_str ()) >= 0)
527 gdb_assert (top
== bottom
);
529 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
530 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
531 while (top
>= start
&& symbol_matches_search_name (&(*top
)->ginfo
,
535 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
538 while (top
<= real_top
&& symbol_matches_search_name (&(*top
)->ginfo
,
541 if (symbol_matches_domain ((*top
)->ginfo
.language (),
542 (*top
)->domain
, domain
))
548 /* Can't use a binary search or else we found during the binary search that
549 we should also do a linear search. */
551 if (do_linear_search
)
553 for (psym
= start
; psym
< start
+ length
; psym
++)
555 if (symbol_matches_domain ((*psym
)->ginfo
.language (),
556 (*psym
)->domain
, domain
)
557 && symbol_matches_search_name (&(*psym
)->ginfo
, lookup_name
))
565 /* Get the symbol table that corresponds to a partial_symtab.
566 This is fast after the first time you do it.
567 The result will be NULL if the primary symtab has no symbols,
568 which can happen. Otherwise the result is the primary symtab
569 that contains PST. */
571 static struct compunit_symtab
*
572 psymtab_to_symtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
574 /* If it is a shared psymtab, find an unshared psymtab that includes
575 it. Any such psymtab will do. */
576 while (pst
->user
!= NULL
)
579 /* If it's been looked up before, return it. */
580 if (pst
->get_compunit_symtab (objfile
))
581 return pst
->get_compunit_symtab (objfile
);
583 /* If it has not yet been read in, read it. */
584 if (!pst
->readin_p (objfile
))
586 scoped_restore decrementer
= increment_reading_symtab ();
590 printf_filtered (_("Reading in symbols for %s...\n"),
592 gdb_flush (gdb_stdout
);
595 pst
->read_symtab (objfile
);
598 return pst
->get_compunit_symtab (objfile
);
601 /* Psymtab version of find_last_source_symtab. See its definition in
602 the definition of quick_symbol_functions in symfile.h. */
605 psymbol_functions::find_last_source_symtab (struct objfile
*ofp
)
607 struct partial_symtab
*cs_pst
= NULL
;
609 for (partial_symtab
*ps
: require_partial_symbols (ofp
))
611 const char *name
= ps
->filename
;
612 int len
= strlen (name
);
614 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
615 || strcmp (name
, "<<C++-namespaces>>") == 0)))
621 if (cs_pst
->readin_p (ofp
))
623 internal_error (__FILE__
, __LINE__
,
624 _("select_source_symtab: "
625 "readin pst found and no symtabs."));
629 struct compunit_symtab
*cust
= psymtab_to_symtab (ofp
, cs_pst
);
633 return compunit_primary_filetab (cust
);
639 /* Psymtab version of forget_cached_source_info. See its definition in
640 the definition of quick_symbol_functions in symfile.h. */
643 psymbol_functions::forget_cached_source_info (struct objfile
*objfile
)
645 for (partial_symtab
*pst
: require_partial_symbols (objfile
))
647 if (pst
->fullname
!= NULL
)
649 xfree (pst
->fullname
);
650 pst
->fullname
= NULL
;
656 print_partial_symbols (struct gdbarch
*gdbarch
, struct objfile
*objfile
,
657 const std::vector
<partial_symbol
*> &symbols
,
658 const char *what
, struct ui_file
*outfile
)
660 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
661 for (partial_symbol
*p
: symbols
)
664 fprintf_filtered (outfile
, " `%s'", p
->ginfo
.linkage_name ());
665 if (p
->ginfo
.demangled_name () != NULL
)
667 fprintf_filtered (outfile
, " `%s'",
668 p
->ginfo
.demangled_name ());
670 fputs_filtered (", ", outfile
);
674 fputs_filtered ("undefined domain, ", outfile
);
677 /* This is the usual thing -- don't print it. */
680 fputs_filtered ("struct domain, ", outfile
);
683 fputs_filtered ("module domain, ", outfile
);
686 fputs_filtered ("label domain, ", outfile
);
688 case COMMON_BLOCK_DOMAIN
:
689 fputs_filtered ("common block domain, ", outfile
);
692 fputs_filtered ("<invalid domain>, ", outfile
);
698 fputs_filtered ("undefined", outfile
);
701 fputs_filtered ("constant int", outfile
);
704 fputs_filtered ("static", outfile
);
707 fputs_filtered ("register", outfile
);
710 fputs_filtered ("pass by value", outfile
);
713 fputs_filtered ("pass by reference", outfile
);
715 case LOC_REGPARM_ADDR
:
716 fputs_filtered ("register address parameter", outfile
);
719 fputs_filtered ("stack parameter", outfile
);
722 fputs_filtered ("type", outfile
);
725 fputs_filtered ("label", outfile
);
728 fputs_filtered ("function", outfile
);
730 case LOC_CONST_BYTES
:
731 fputs_filtered ("constant bytes", outfile
);
734 fputs_filtered ("unresolved", outfile
);
736 case LOC_OPTIMIZED_OUT
:
737 fputs_filtered ("optimized out", outfile
);
740 fputs_filtered ("computed at runtime", outfile
);
743 fputs_filtered ("<invalid location>", outfile
);
746 fputs_filtered (", ", outfile
);
747 fputs_filtered (paddress (gdbarch
, p
->unrelocated_address ()), outfile
);
748 fprintf_filtered (outfile
, "\n");
753 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
754 struct ui_file
*outfile
)
756 struct gdbarch
*gdbarch
= objfile
->arch ();
759 if (psymtab
->anonymous
)
761 fprintf_filtered (outfile
, "\nAnonymous partial symtab (%s) ",
766 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
769 fprintf_filtered (outfile
, "(object %s)\n\n",
770 host_address_to_string (psymtab
));
771 fprintf_filtered (outfile
, " Read from object file %s (%s)\n",
772 objfile_name (objfile
),
773 host_address_to_string (objfile
));
775 if (psymtab
->readin_p (objfile
))
778 " Full symtab was read (at %s)\n",
779 host_address_to_string (psymtab
->get_compunit_symtab (objfile
)));
781 fprintf_filtered (outfile
, " Symbols cover text addresses ");
782 fputs_filtered (paddress (gdbarch
, psymtab
->text_low (objfile
)), outfile
);
783 fprintf_filtered (outfile
, "-");
784 fputs_filtered (paddress (gdbarch
, psymtab
->text_high (objfile
)), outfile
);
785 fprintf_filtered (outfile
, "\n");
786 fprintf_filtered (outfile
, " Address map supported - %s.\n",
787 psymtab
->psymtabs_addrmap_supported
? "yes" : "no");
788 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
789 psymtab
->number_of_dependencies
);
790 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
791 fprintf_filtered (outfile
, " %d %s\n", i
,
792 host_address_to_string (psymtab
->dependencies
[i
]));
793 if (psymtab
->user
!= NULL
)
794 fprintf_filtered (outfile
, " Shared partial symtab with user %s\n",
795 host_address_to_string (psymtab
->user
));
796 if (!psymtab
->global_psymbols
.empty ())
798 print_partial_symbols
799 (gdbarch
, objfile
, psymtab
->global_psymbols
,
802 if (!psymtab
->static_psymbols
.empty ())
804 print_partial_symbols
805 (gdbarch
, objfile
, psymtab
->static_psymbols
,
808 fprintf_filtered (outfile
, "\n");
811 /* Count the number of partial symbols in OBJFILE. */
814 psymbol_functions::count_psyms ()
817 for (partial_symtab
*pst
: m_partial_symtabs
->range ())
819 count
+= pst
->global_psymbols
.size ();
820 count
+= pst
->static_psymbols
.size ();
825 /* Psymtab version of print_stats. See its definition in
826 the definition of quick_symbol_functions in symfile.h. */
829 psymbol_functions::print_stats (struct objfile
*objfile
, bool print_bcache
)
835 int n_psyms
= count_psyms ();
837 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
841 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
843 if (!ps
->readin_p (objfile
))
846 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"),
848 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
849 m_partial_symtabs
->psymbol_cache
.memory_used ());
853 printf_filtered (_("Psymbol byte cache statistics:\n"));
854 m_partial_symtabs
->psymbol_cache
.print_statistics
855 ("partial symbol cache");
859 /* Psymtab version of dump. See its definition in
860 the definition of quick_symbol_functions in symfile.h. */
863 psymbol_functions::dump (struct objfile
*objfile
)
865 struct partial_symtab
*psymtab
;
867 if (m_partial_symtabs
->psymtabs
)
869 printf_filtered ("Psymtabs:\n");
870 for (psymtab
= m_partial_symtabs
->psymtabs
;
872 psymtab
= psymtab
->next
)
873 printf_filtered ("%s at %s\n",
875 host_address_to_string (psymtab
));
876 printf_filtered ("\n\n");
880 /* Psymtab version of expand_all_symtabs. See its definition in
881 the definition of quick_symbol_functions in symfile.h. */
884 psymbol_functions::expand_all_symtabs (struct objfile
*objfile
)
886 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
))
887 psymtab_to_symtab (objfile
, psymtab
);
890 /* Psymtab version of map_symbol_filenames. See its definition in
891 the definition of quick_symbol_functions in symfile.h. */
894 psymbol_functions::map_symbol_filenames
895 (struct objfile
*objfile
,
896 gdb::function_view
<symbol_filename_ftype
> fun
,
899 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
901 const char *fullname
;
903 if (ps
->readin_p (objfile
))
906 /* We can skip shared psymtabs here, because any file name will be
907 attached to the unshared psymtab. */
908 if (ps
->user
!= NULL
)
911 /* Anonymous psymtabs don't have a file name. */
917 fullname
= psymtab_to_fullname (ps
);
920 fun (ps
->filename
, fullname
);
924 /* Finds the fullname that a partial_symtab represents.
926 If this functions finds the fullname, it will save it in ps->fullname
927 and it will also return the value.
929 If this function fails to find the file that this partial_symtab represents,
930 NULL will be returned and ps->fullname will be set to NULL. */
933 psymtab_to_fullname (struct partial_symtab
*ps
)
935 gdb_assert (!ps
->anonymous
);
937 /* Use cached copy if we have it.
938 We rely on forget_cached_source_info being called appropriately
939 to handle cases like the file being moved. */
940 if (ps
->fullname
== NULL
)
942 gdb::unique_xmalloc_ptr
<char> fullname
943 = find_source_or_rewrite (ps
->filename
, ps
->dirname
);
944 ps
->fullname
= fullname
.release ();
950 /* Psymtab version of expand_matching_symbols. See its definition in
951 the definition of quick_symbol_functions in symfile.h. */
954 psymbol_functions::expand_matching_symbols
955 (struct objfile
*objfile
,
956 const lookup_name_info
&name
, domain_enum domain
,
958 symbol_compare_ftype
*ordered_compare
)
960 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
963 if (!ps
->readin_p (objfile
)
964 && match_partial_symbol (objfile
, ps
, global
, name
, domain
,
966 psymtab_to_symtab (objfile
, ps
);
970 /* A helper for psym_expand_symtabs_matching that handles searching
971 included psymtabs. This returns true if a symbol is found, and
972 false otherwise. It also updates the 'searched_flag' on the
973 various psymtabs that it searches. */
976 recursively_search_psymtabs
977 (struct partial_symtab
*ps
,
978 struct objfile
*objfile
,
979 block_search_flags search_flags
,
981 enum search_domain search
,
982 const lookup_name_info
&lookup_name
,
983 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> sym_matcher
)
986 enum psymtab_search_status result
= PST_SEARCHED_AND_NOT_FOUND
;
989 if (ps
->searched_flag
!= PST_NOT_SEARCHED
)
990 return ps
->searched_flag
== PST_SEARCHED_AND_FOUND
;
992 /* Recurse into shared psymtabs first, because they may have already
993 been searched, and this could save some time. */
994 for (i
= 0; i
< ps
->number_of_dependencies
; ++i
)
998 /* Skip non-shared dependencies, these are handled elsewhere. */
999 if (ps
->dependencies
[i
]->user
== NULL
)
1002 r
= recursively_search_psymtabs (ps
->dependencies
[i
],
1003 objfile
, search_flags
, domain
, search
,
1004 lookup_name
, sym_matcher
);
1007 ps
->searched_flag
= PST_SEARCHED_AND_FOUND
;
1012 partial_symbol
**gbound
= (ps
->global_psymbols
.data ()
1013 + ps
->global_psymbols
.size ());
1014 partial_symbol
**sbound
= (ps
->static_psymbols
.data ()
1015 + ps
->static_psymbols
.size ());
1016 partial_symbol
**bound
= gbound
;
1018 /* Go through all of the symbols stored in a partial
1019 symtab in one loop. */
1020 partial_symbol
**psym
= ps
->global_psymbols
.data ();
1022 if ((search_flags
& SEARCH_GLOBAL_BLOCK
) == 0)
1024 if (ps
->static_psymbols
.empty ())
1028 psym
= ps
->static_psymbols
.data ();
1037 if (bound
== gbound
&& !ps
->static_psymbols
.empty ()
1038 && (search_flags
& SEARCH_STATIC_BLOCK
) != 0)
1040 psym
= ps
->static_psymbols
.data ();
1051 if ((domain
== UNDEF_DOMAIN
1052 || symbol_matches_domain ((*psym
)->ginfo
.language (),
1053 (*psym
)->domain
, domain
))
1054 && (search
== ALL_DOMAIN
1055 || (search
== MODULES_DOMAIN
1056 && (*psym
)->domain
== MODULE_DOMAIN
)
1057 || (search
== VARIABLES_DOMAIN
1058 && (*psym
)->aclass
!= LOC_TYPEDEF
1059 && (*psym
)->aclass
!= LOC_BLOCK
)
1060 || (search
== FUNCTIONS_DOMAIN
1061 && (*psym
)->aclass
== LOC_BLOCK
)
1062 || (search
== TYPES_DOMAIN
1063 && (*psym
)->aclass
== LOC_TYPEDEF
))
1064 && psymbol_name_matches (*psym
, lookup_name
)
1065 && (sym_matcher
== NULL
1066 || sym_matcher ((*psym
)->ginfo
.search_name ())))
1068 /* Found a match, so notify our caller. */
1069 result
= PST_SEARCHED_AND_FOUND
;
1076 ps
->searched_flag
= result
;
1077 return result
== PST_SEARCHED_AND_FOUND
;
1080 /* Psymtab version of expand_symtabs_matching. See its definition in
1081 the definition of quick_symbol_functions in symfile.h. */
1084 psymbol_functions::expand_symtabs_matching
1085 (struct objfile
*objfile
,
1086 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
1087 const lookup_name_info
*lookup_name
,
1088 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
1089 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
1090 block_search_flags search_flags
,
1092 enum search_domain search
)
1094 /* Clear the search flags. */
1095 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
1096 ps
->searched_flag
= PST_NOT_SEARCHED
;
1098 gdb::optional
<lookup_name_info
> psym_lookup_name
;
1099 if (lookup_name
!= nullptr)
1100 psym_lookup_name
= lookup_name
->make_ignore_params ();
1102 /* This invariant is documented in quick-functions.h. */
1103 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
1105 for (partial_symtab
*ps
: m_partial_symtabs
->range ())
1109 if (ps
->readin_p (objfile
))
1119 match
= file_matcher (ps
->filename
, false);
1122 /* Before we invoke realpath, which can get expensive when many
1123 files are involved, do a quick comparison of the basenames. */
1124 if (basenames_may_differ
1125 || file_matcher (lbasename (ps
->filename
), true))
1126 match
= file_matcher (psymtab_to_fullname (ps
), false);
1132 if (lookup_name
== nullptr
1133 || recursively_search_psymtabs (ps
, objfile
, search_flags
,
1138 struct compunit_symtab
*symtab
=
1139 psymtab_to_symtab (objfile
, ps
);
1141 gdb_assert (symtab
!= nullptr);
1143 if (expansion_notify
!= NULL
)
1144 if (!expansion_notify (symtab
))
1152 /* Psymtab version of has_symbols. See its definition in
1153 the definition of quick_symbol_functions in symfile.h. */
1156 psymbol_functions::has_symbols (struct objfile
*objfile
)
1158 return m_partial_symtabs
->psymtabs
!= NULL
;
1161 /* See quick_symbol_functions::has_unexpanded_symtabs in quick-symbol.h. */
1164 psymbol_functions::has_unexpanded_symtabs (struct objfile
*objfile
)
1166 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
))
1168 /* Is this already expanded? */
1169 if (psymtab
->readin_p (objfile
))
1172 /* It has not yet been expanded. */
1179 /* Helper function for psym_find_compunit_symtab_by_address that fills
1180 in m_psymbol_map for a given range of psymbols. */
1183 psymbol_functions::fill_psymbol_map
1184 (struct objfile
*objfile
,
1185 struct partial_symtab
*psymtab
,
1186 std::set
<CORE_ADDR
> *seen_addrs
,
1187 const std::vector
<partial_symbol
*> &symbols
)
1189 for (partial_symbol
*psym
: symbols
)
1191 if (psym
->aclass
== LOC_STATIC
)
1193 CORE_ADDR addr
= psym
->address (objfile
);
1194 if (seen_addrs
->find (addr
) == seen_addrs
->end ())
1196 seen_addrs
->insert (addr
);
1197 m_psymbol_map
.emplace_back (addr
, psymtab
);
1203 /* See find_compunit_symtab_by_address in quick_symbol_functions, in
1207 psymbol_functions::find_compunit_symtab_by_address (struct objfile
*objfile
,
1210 if (m_psymbol_map
.empty ())
1212 std::set
<CORE_ADDR
> seen_addrs
;
1214 for (partial_symtab
*pst
: require_partial_symbols (objfile
))
1216 fill_psymbol_map (objfile
, pst
,
1218 pst
->global_psymbols
);
1219 fill_psymbol_map (objfile
, pst
,
1221 pst
->static_psymbols
);
1224 m_psymbol_map
.shrink_to_fit ();
1226 std::sort (m_psymbol_map
.begin (), m_psymbol_map
.end (),
1227 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1228 const std::pair
<CORE_ADDR
, partial_symtab
*> &b
)
1230 return a
.first
< b
.first
;
1234 auto iter
= std::lower_bound
1235 (m_psymbol_map
.begin (), m_psymbol_map
.end (), address
,
1236 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1242 if (iter
== m_psymbol_map
.end () || iter
->first
!= address
)
1245 return psymtab_to_symtab (objfile
, iter
->second
);
1250 /* Partially fill a partial symtab. It will be completely filled at
1251 the end of the symbol list. */
1253 partial_symtab::partial_symtab (const char *filename
,
1254 psymtab_storage
*partial_symtabs
,
1255 objfile_per_bfd_storage
*objfile_per_bfd
,
1257 : partial_symtab (filename
, partial_symtabs
, objfile_per_bfd
)
1259 set_text_low (textlow
);
1260 set_text_high (raw_text_low ()); /* default */
1263 /* Perform "finishing up" operations of a partial symtab. */
1266 partial_symtab::end ()
1268 global_psymbols
.shrink_to_fit ();
1269 static_psymbols
.shrink_to_fit ();
1271 /* Sort the global list; don't sort the static list. */
1272 std::sort (global_psymbols
.begin (),
1273 global_psymbols
.end (),
1274 [] (partial_symbol
*s1
, partial_symbol
*s2
)
1276 return strcmp_iw_ordered (s1
->ginfo
.search_name (),
1277 s2
->ginfo
.search_name ()) < 0;
1281 /* See psymtab.h. */
1284 psymbol_bcache::hash (const void *addr
, int length
)
1286 unsigned long h
= 0;
1287 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1288 unsigned int lang
= psymbol
->ginfo
.language ();
1289 unsigned int domain
= psymbol
->domain
;
1290 unsigned int theclass
= psymbol
->aclass
;
1292 h
= fast_hash (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1293 h
= fast_hash (&lang
, sizeof (unsigned int), h
);
1294 h
= fast_hash (&domain
, sizeof (unsigned int), h
);
1295 h
= fast_hash (&theclass
, sizeof (unsigned int), h
);
1296 /* Note that psymbol names are interned via compute_and_set_names, so
1297 there's no need to hash the contents of the name here. */
1298 h
= fast_hash (&psymbol
->ginfo
.m_name
, sizeof (psymbol
->ginfo
.m_name
), h
);
1303 /* See psymtab.h. */
1306 psymbol_bcache::compare (const void *addr1
, const void *addr2
, int length
)
1308 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1309 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1311 return (memcmp (&sym1
->ginfo
.value
, &sym2
->ginfo
.value
,
1312 sizeof (sym1
->ginfo
.value
)) == 0
1313 && sym1
->ginfo
.language () == sym2
->ginfo
.language ()
1314 && sym1
->domain
== sym2
->domain
1315 && sym1
->aclass
== sym2
->aclass
1316 /* Note that psymbol names are interned via
1317 compute_and_set_names, so there's no need to compare the
1318 contents of the name here. */
1319 && sym1
->ginfo
.linkage_name () == sym2
->ginfo
.linkage_name ());
1322 /* See psympriv.h. */
1325 partial_symtab::add_psymbol (const partial_symbol
&psymbol
,
1326 psymbol_placement where
,
1327 psymtab_storage
*partial_symtabs
,
1328 struct objfile
*objfile
)
1332 /* Stash the partial symbol away in the cache. */
1333 partial_symbol
*psym
1334 = ((struct partial_symbol
*)
1335 partial_symtabs
->psymbol_cache
.insert
1336 (&psymbol
, sizeof (struct partial_symbol
), &added
));
1338 /* Do not duplicate global partial symbols. */
1339 if (where
== psymbol_placement::GLOBAL
&& !added
)
1342 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1343 std::vector
<partial_symbol
*> &list
1344 = (where
== psymbol_placement::STATIC
1347 list
.push_back (psym
);
1350 /* See psympriv.h. */
1353 partial_symtab::add_psymbol (gdb::string_view name
, bool copy_name
,
1355 enum address_class theclass
,
1357 psymbol_placement where
,
1359 enum language language
,
1360 psymtab_storage
*partial_symtabs
,
1361 struct objfile
*objfile
)
1363 struct partial_symbol psymbol
;
1364 memset (&psymbol
, 0, sizeof (psymbol
));
1366 psymbol
.set_unrelocated_address (coreaddr
);
1367 psymbol
.ginfo
.set_section_index (section
);
1368 psymbol
.domain
= domain
;
1369 psymbol
.aclass
= theclass
;
1370 psymbol
.ginfo
.set_language (language
, partial_symtabs
->obstack ());
1371 psymbol
.ginfo
.compute_and_set_names (name
, copy_name
, objfile
->per_bfd
);
1373 add_psymbol (psymbol
, where
, partial_symtabs
, objfile
);
1376 /* See psympriv.h. */
1378 partial_symtab::partial_symtab (const char *filename_
,
1379 psymtab_storage
*partial_symtabs
,
1380 objfile_per_bfd_storage
*objfile_per_bfd
)
1381 : searched_flag (PST_NOT_SEARCHED
),
1385 partial_symtabs
->install_psymtab (this);
1387 filename
= objfile_per_bfd
->intern (filename_
);
1389 if (symtab_create_debug
)
1391 /* Be a bit clever with debugging messages, and don't print objfile
1392 every time, only when it changes. */
1393 static std::string last_bfd_name
;
1394 const char *this_bfd_name
1395 = bfd_get_filename (objfile_per_bfd
->get_bfd ());
1397 if (last_bfd_name
.empty () || last_bfd_name
!= this_bfd_name
)
1399 last_bfd_name
= this_bfd_name
;
1400 fprintf_filtered (gdb_stdlog
,
1401 "Creating one or more psymtabs for %s ...\n",
1404 fprintf_filtered (gdb_stdlog
,
1405 "Created psymtab %s for module %s.\n",
1406 host_address_to_string (this), filename
);
1410 /* See psympriv.h. */
1413 partial_symtab::expand_dependencies (struct objfile
*objfile
)
1415 for (int i
= 0; i
< number_of_dependencies
; ++i
)
1417 if (!dependencies
[i
]->readin_p (objfile
)
1418 && dependencies
[i
]->user
== NULL
)
1420 /* Inform about additional files to be read in. */
1423 fputs_filtered (" ", gdb_stdout
);
1425 fputs_filtered ("and ", gdb_stdout
);
1427 printf_filtered ("%s...", dependencies
[i
]->filename
);
1428 wrap_here (""); /* Flush output */
1429 gdb_flush (gdb_stdout
);
1431 dependencies
[i
]->expand_psymtab (objfile
);
1438 psymtab_storage::discard_psymtab (struct partial_symtab
*pst
)
1440 struct partial_symtab
**prev_pst
;
1443 Empty psymtabs happen as a result of header files which don't
1444 have any symbols in them. There can be a lot of them. But this
1445 check is wrong, in that a psymtab with N_SLINE entries but
1446 nothing else is not empty, but we don't realize that. Fixing
1447 that without slowing things down might be tricky. */
1449 /* First, snip it out of the psymtab chain. */
1451 prev_pst
= &psymtabs
;
1452 while ((*prev_pst
) != pst
)
1453 prev_pst
= &((*prev_pst
)->next
);
1454 (*prev_pst
) = pst
->next
;
1460 /* Helper function for maintenance_print_psymbols to print the addrmap
1461 of PSYMTAB. If PSYMTAB is NULL print the entire addrmap. */
1464 dump_psymtab_addrmap (struct objfile
*objfile
,
1465 psymtab_storage
*partial_symtabs
,
1466 struct partial_symtab
*psymtab
,
1467 struct ui_file
*outfile
)
1469 if ((psymtab
== NULL
1470 || psymtab
->psymtabs_addrmap_supported
)
1471 && partial_symtabs
->psymtabs_addrmap
!= NULL
)
1473 if (psymtab
== nullptr)
1474 fprintf_filtered (outfile
, _("Entire address map:\n"));
1476 fprintf_filtered (outfile
, _("Address map:\n"));
1477 addrmap_dump (partial_symtabs
->psymtabs_addrmap
, outfile
, psymtab
);
1482 maintenance_print_psymbols (const char *args
, int from_tty
)
1484 struct ui_file
*outfile
= gdb_stdout
;
1485 char *address_arg
= NULL
, *source_arg
= NULL
, *objfile_arg
= NULL
;
1486 int i
, outfile_idx
, found
;
1488 struct obj_section
*section
= NULL
;
1492 gdb_argv
argv (args
);
1494 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
1496 if (strcmp (argv
[i
], "-pc") == 0)
1498 if (argv
[i
+ 1] == NULL
)
1499 error (_("Missing pc value"));
1500 address_arg
= argv
[++i
];
1502 else if (strcmp (argv
[i
], "-source") == 0)
1504 if (argv
[i
+ 1] == NULL
)
1505 error (_("Missing source file"));
1506 source_arg
= argv
[++i
];
1508 else if (strcmp (argv
[i
], "-objfile") == 0)
1510 if (argv
[i
+ 1] == NULL
)
1511 error (_("Missing objfile name"));
1512 objfile_arg
= argv
[++i
];
1514 else if (strcmp (argv
[i
], "--") == 0)
1516 /* End of options. */
1520 else if (argv
[i
][0] == '-')
1522 /* Future proofing: Don't allow OUTFILE to begin with "-". */
1523 error (_("Unknown option: %s"), argv
[i
]);
1530 if (address_arg
!= NULL
&& source_arg
!= NULL
)
1531 error (_("Must specify at most one of -pc and -source"));
1533 stdio_file arg_outfile
;
1535 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
1537 if (argv
[outfile_idx
+ 1] != NULL
)
1538 error (_("Junk at end of command"));
1539 gdb::unique_xmalloc_ptr
<char> outfile_name
1540 (tilde_expand (argv
[outfile_idx
]));
1541 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
1542 perror_with_name (outfile_name
.get ());
1543 outfile
= &arg_outfile
;
1546 if (address_arg
!= NULL
)
1548 pc
= parse_and_eval_address (address_arg
);
1549 /* If we fail to find a section, that's ok, try the lookup anyway. */
1550 section
= find_pc_section (pc
);
1554 for (objfile
*objfile
: current_program_space
->objfiles ())
1556 int printed_objfile_header
= 0;
1557 int print_for_objfile
= 1;
1560 if (objfile_arg
!= NULL
)
1562 = compare_filenames_for_search (objfile_name (objfile
),
1564 if (!print_for_objfile
)
1567 for (const auto &iter
: objfile
->qf
)
1569 psymbol_functions
*psf
1570 = dynamic_cast<psymbol_functions
*> (iter
.get ());
1574 psymtab_storage
*partial_symtabs
1575 = psf
->get_partial_symtabs ().get ();
1577 if (address_arg
!= NULL
)
1579 struct bound_minimal_symbol msymbol
= { NULL
, NULL
};
1581 /* We don't assume each pc has a unique objfile (this is for
1583 struct partial_symtab
*ps
1584 = psf
->find_pc_sect_psymtab (objfile
, pc
, section
, msymbol
);
1587 if (!printed_objfile_header
)
1589 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1590 objfile_name (objfile
));
1591 printed_objfile_header
= 1;
1593 dump_psymtab (objfile
, ps
, outfile
);
1594 dump_psymtab_addrmap (objfile
, partial_symtabs
, ps
, outfile
);
1600 for (partial_symtab
*ps
: psf
->require_partial_symbols (objfile
))
1602 int print_for_source
= 0;
1605 if (source_arg
!= NULL
)
1608 = compare_filenames_for_search (ps
->filename
, source_arg
);
1611 if (source_arg
== NULL
1612 || print_for_source
)
1614 if (!printed_objfile_header
)
1616 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1617 objfile_name (objfile
));
1618 printed_objfile_header
= 1;
1620 dump_psymtab (objfile
, ps
, outfile
);
1621 dump_psymtab_addrmap (objfile
, partial_symtabs
, ps
,
1627 /* If we're printing all the objfile's symbols dump the full addrmap. */
1629 if (address_arg
== NULL
1630 && source_arg
== NULL
1631 && partial_symtabs
->psymtabs_addrmap
!= NULL
)
1633 outfile
->puts ("\n");
1634 dump_psymtab_addrmap (objfile
, partial_symtabs
, NULL
, outfile
);
1641 if (address_arg
!= NULL
)
1642 error (_("No partial symtab for address: %s"), address_arg
);
1643 if (source_arg
!= NULL
)
1644 error (_("No partial symtab for source file: %s"), source_arg
);
1648 /* List all the partial symbol tables whose names match REGEXP (optional). */
1651 maintenance_info_psymtabs (const char *regexp
, int from_tty
)
1656 for (struct program_space
*pspace
: program_spaces
)
1657 for (objfile
*objfile
: pspace
->objfiles ())
1659 struct gdbarch
*gdbarch
= objfile
->arch ();
1661 /* We don't want to print anything for this objfile until we
1662 actually find a symtab whose name matches. */
1663 int printed_objfile_start
= 0;
1665 for (const auto &iter
: objfile
->qf
)
1667 psymbol_functions
*psf
1668 = dynamic_cast<psymbol_functions
*> (iter
.get ());
1671 for (partial_symtab
*psymtab
: psf
->require_partial_symbols (objfile
))
1676 || re_exec (psymtab
->filename
))
1678 if (! printed_objfile_start
)
1680 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
1682 printf_filtered ("((struct objfile *) %s)\n",
1683 host_address_to_string (objfile
));
1684 printed_objfile_start
= 1;
1687 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1689 printf_filtered ("((struct partial_symtab *) %s)\n",
1690 host_address_to_string (psymtab
));
1692 printf_filtered (" readin %s\n",
1693 psymtab
->readin_p (objfile
) ? "yes" : "no");
1694 printf_filtered (" fullname %s\n",
1696 ? psymtab
->fullname
: "(null)");
1697 printf_filtered (" text addresses ");
1698 fputs_filtered (paddress (gdbarch
,
1699 psymtab
->text_low (objfile
)),
1701 printf_filtered (" -- ");
1702 fputs_filtered (paddress (gdbarch
,
1703 psymtab
->text_high (objfile
)),
1705 printf_filtered ("\n");
1706 printf_filtered (" psymtabs_addrmap_supported %s\n",
1707 (psymtab
->psymtabs_addrmap_supported
1709 printf_filtered (" globals ");
1710 if (!psymtab
->global_psymbols
.empty ())
1712 ("(* (struct partial_symbol **) %s @ %d)\n",
1713 host_address_to_string (psymtab
->global_psymbols
.data ()),
1714 (int) psymtab
->global_psymbols
.size ());
1716 printf_filtered ("(none)\n");
1717 printf_filtered (" statics ");
1718 if (!psymtab
->static_psymbols
.empty ())
1720 ("(* (struct partial_symbol **) %s @ %d)\n",
1721 host_address_to_string (psymtab
->static_psymbols
.data ()),
1722 (int) psymtab
->static_psymbols
.size ());
1724 printf_filtered ("(none)\n");
1726 printf_filtered (" user %s "
1727 "((struct partial_symtab *) %s)\n",
1728 psymtab
->user
->filename
,
1729 host_address_to_string (psymtab
->user
));
1730 printf_filtered (" dependencies ");
1731 if (psymtab
->number_of_dependencies
)
1735 printf_filtered ("{\n");
1736 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1738 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
1740 /* Note the string concatenation there --- no
1742 printf_filtered (" psymtab %s "
1743 "((struct partial_symtab *) %s)\n",
1745 host_address_to_string (dep
));
1747 printf_filtered (" }\n");
1750 printf_filtered ("(none)\n");
1751 printf_filtered (" }\n");
1756 if (printed_objfile_start
)
1757 printf_filtered ("}\n");
1761 /* Check consistency of currently expanded psymtabs vs symtabs. */
1764 maintenance_check_psymtabs (const char *ignore
, int from_tty
)
1767 struct compunit_symtab
*cust
= NULL
;
1768 const struct blockvector
*bv
;
1769 const struct block
*b
;
1771 for (objfile
*objfile
: current_program_space
->objfiles ())
1773 for (const auto &iter
: objfile
->qf
)
1775 psymbol_functions
*psf
1776 = dynamic_cast<psymbol_functions
*> (iter
.get ());
1780 for (partial_symtab
*ps
: psf
->require_partial_symbols (objfile
))
1782 struct gdbarch
*gdbarch
= objfile
->arch ();
1784 /* We don't call psymtab_to_symtab here because that may cause symtab
1785 expansion. When debugging a problem it helps if checkers leave
1786 things unchanged. */
1787 cust
= ps
->get_compunit_symtab (objfile
);
1789 /* First do some checks that don't require the associated symtab. */
1790 if (ps
->text_high (objfile
) < ps
->text_low (objfile
))
1792 printf_filtered ("Psymtab ");
1793 puts_filtered (ps
->filename
);
1794 printf_filtered (" covers bad range ");
1795 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
1797 printf_filtered (" - ");
1798 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
1800 printf_filtered ("\n");
1804 /* Now do checks requiring the associated symtab. */
1807 bv
= COMPUNIT_BLOCKVECTOR (cust
);
1808 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1809 for (partial_symbol
*psym
: ps
->static_psymbols
)
1811 /* Skip symbols for inlined functions without address. These may
1812 or may not have a match in the full symtab. */
1813 if (psym
->aclass
== LOC_BLOCK
1814 && psym
->ginfo
.value
.address
== 0)
1817 sym
= block_lookup_symbol (b
, psym
->ginfo
.search_name (),
1818 symbol_name_match_type::SEARCH_NAME
,
1822 printf_filtered ("Static symbol `");
1823 puts_filtered (psym
->ginfo
.linkage_name ());
1824 printf_filtered ("' only found in ");
1825 puts_filtered (ps
->filename
);
1826 printf_filtered (" psymtab\n");
1829 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1830 for (partial_symbol
*psym
: ps
->global_psymbols
)
1832 sym
= block_lookup_symbol (b
, psym
->ginfo
.search_name (),
1833 symbol_name_match_type::SEARCH_NAME
,
1837 printf_filtered ("Global symbol `");
1838 puts_filtered (psym
->ginfo
.linkage_name ());
1839 printf_filtered ("' only found in ");
1840 puts_filtered (ps
->filename
);
1841 printf_filtered (" psymtab\n");
1844 if (ps
->raw_text_high () != 0
1845 && (ps
->text_low (objfile
) < BLOCK_START (b
)
1846 || ps
->text_high (objfile
) > BLOCK_END (b
)))
1848 printf_filtered ("Psymtab ");
1849 puts_filtered (ps
->filename
);
1850 printf_filtered (" covers ");
1851 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
1853 printf_filtered (" - ");
1854 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
1856 printf_filtered (" but symtab covers only ");
1857 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
1858 printf_filtered (" - ");
1859 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
1860 printf_filtered ("\n");
1867 void _initialize_psymtab ();
1869 _initialize_psymtab ()
1871 add_cmd ("psymbols", class_maintenance
, maintenance_print_psymbols
, _("\
1872 Print dump of current partial symbol definitions.\n\
1873 Usage: mt print psymbols [-objfile OBJFILE] [-pc ADDRESS] [--] [OUTFILE]\n\
1874 mt print psymbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
1875 Entries in the partial symbol table are dumped to file OUTFILE,\n\
1876 or the terminal if OUTFILE is unspecified.\n\
1877 If ADDRESS is provided, dump only the file for that address.\n\
1878 If SOURCE is provided, dump only that file's symbols.\n\
1879 If OBJFILE is provided, dump only that file's minimal symbols."),
1880 &maintenanceprintlist
);
1882 add_cmd ("psymtabs", class_maintenance
, maintenance_info_psymtabs
, _("\
1883 List the partial symbol tables for all object files.\n\
1884 This does not include information about individual partial symbols,\n\
1885 just the symbol table structures themselves."),
1886 &maintenanceinfolist
);
1888 add_cmd ("check-psymtabs", class_maintenance
, maintenance_check_psymtabs
,
1890 Check consistency of currently expanded psymtabs versus symtabs."),