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 "gdbsupport/gdb_regex.h"
33 #include "dictionary.h"
35 #include "cp-support.h"
39 #include "gdbsupport/buildargv.h"
41 static struct partial_symbol
*lookup_partial_symbol (struct objfile
*,
42 struct partial_symtab
*,
43 const lookup_name_info
&,
47 static const char *psymtab_to_fullname (struct partial_symtab
*ps
);
49 static struct partial_symbol
*find_pc_sect_psymbol (struct objfile
*,
50 struct partial_symtab
*,
52 struct obj_section
*);
54 static struct compunit_symtab
*psymtab_to_symtab (struct objfile
*objfile
,
55 struct partial_symtab
*pst
);
57 psymtab_storage::~psymtab_storage ()
59 partial_symtab
*iter
= psymtabs
;
60 while (iter
!= nullptr)
62 partial_symtab
*next
= iter
->next
;
71 psymtab_storage::install_psymtab (partial_symtab
*pst
)
79 /* Ensure that the partial symbols for OBJFILE have been loaded. This
80 will print a message when symbols are loaded. This function
81 returns a range adapter suitable for iterating over the psymtabs of
84 psymtab_storage::partial_symtab_range
85 psymbol_functions::require_partial_symbols (struct objfile
*objfile
)
87 objfile
->require_partial_symbols (true);
88 return m_partial_symtabs
->range ();
91 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
92 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
94 static struct partial_symtab
*
95 find_pc_sect_psymtab_closer (struct objfile
*objfile
,
96 CORE_ADDR pc
, struct obj_section
*section
,
97 struct partial_symtab
*pst
,
98 struct bound_minimal_symbol msymbol
)
100 struct partial_symtab
*tpst
;
101 struct partial_symtab
*best_pst
= pst
;
102 CORE_ADDR best_addr
= pst
->text_low (objfile
);
104 gdb_assert (!pst
->psymtabs_addrmap_supported
);
106 /* An objfile that has its functions reordered might have
107 many partial symbol tables containing the PC, but
108 we want the partial symbol table that contains the
109 function containing the PC. */
110 if (!(objfile
->flags
& OBJF_REORDERED
)
111 && section
== NULL
) /* Can't validate section this way. */
114 if (msymbol
.minsym
== NULL
)
117 /* The code range of partial symtabs sometimes overlap, so, in
118 the loop below, we need to check all partial symtabs and
119 find the one that fits better for the given PC address. We
120 select the partial symtab that contains a symbol whose
121 address is closest to the PC address. By closest we mean
122 that find_pc_sect_symbol returns the symbol with address
123 that is closest and still less than the given PC. */
124 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
126 if (pc
>= tpst
->text_low (objfile
) && pc
< tpst
->text_high (objfile
))
128 struct partial_symbol
*p
;
131 /* NOTE: This assumes that every psymbol has a
132 corresponding msymbol, which is not necessarily
133 true; the debug info might be much richer than the
134 object's symbol table. */
135 p
= find_pc_sect_psymbol (objfile
, tpst
, pc
, section
);
137 && (p
->address (objfile
) == BMSYMBOL_VALUE_ADDRESS (msymbol
)))
140 /* Also accept the textlow value of a psymtab as a
141 "symbol", to provide some support for partial
142 symbol tables with line information but no debug
143 symbols (e.g. those produced by an assembler). */
145 this_addr
= p
->address (objfile
);
147 this_addr
= tpst
->text_low (objfile
);
149 /* Check whether it is closer than our current
150 BEST_ADDR. Since this symbol address is
151 necessarily lower or equal to PC, the symbol closer
152 to PC is the symbol which address is the highest.
153 This way we return the psymtab which contains such
154 best match symbol. This can help in cases where the
155 symbol information/debuginfo is not complete, like
156 for instance on IRIX6 with gcc, where no debug info
157 is emitted for statics. (See also the nodebug.exp
159 if (this_addr
> best_addr
)
161 best_addr
= this_addr
;
169 /* See psympriv.h. */
171 struct partial_symtab
*
172 psymbol_functions::find_pc_sect_psymtab (struct objfile
*objfile
,
174 struct obj_section
*section
,
175 struct bound_minimal_symbol msymbol
)
177 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better
178 granularity than the later used TEXTLOW/TEXTHIGH one. However, we need
179 to take care as the PSYMTABS_ADDRMAP can hold things other than partial
180 symtabs in some cases.
182 This function should only be called for objfiles that are using partial
183 symtabs, not for objfiles that are using indexes (.gdb_index or
184 .debug_names), however 'maintenance print psymbols' calls this function
185 directly for all objfiles. If we assume that PSYMTABS_ADDRMAP contains
186 partial symtabs then we will end up returning a pointer to an object
187 that is not a partial_symtab, which doesn't end well. */
189 if (m_partial_symtabs
->psymtabs
!= NULL
190 && m_partial_symtabs
->psymtabs_addrmap
!= NULL
)
192 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
194 struct partial_symtab
*pst
195 = ((struct partial_symtab
*)
196 addrmap_find (m_partial_symtabs
->psymtabs_addrmap
,
200 /* FIXME: addrmaps currently do not handle overlayed sections,
201 so fall back to the non-addrmap case if we're debugging
202 overlays and the addrmap returned the wrong section. */
203 if (overlay_debugging
&& msymbol
.minsym
!= NULL
&& section
!= NULL
)
205 struct partial_symbol
*p
;
207 /* NOTE: This assumes that every psymbol has a
208 corresponding msymbol, which is not necessarily
209 true; the debug info might be much richer than the
210 object's symbol table. */
211 p
= find_pc_sect_psymbol (objfile
, pst
, pc
, section
);
213 || (p
->address (objfile
)
214 != BMSYMBOL_VALUE_ADDRESS (msymbol
)))
218 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
219 PSYMTABS_ADDRMAP we used has already the best 1-byte
220 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
221 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
230 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
231 which still have no corresponding full SYMTABs read. But it is not
232 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
235 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
236 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
237 debug info type in single OBJFILE. */
239 for (partial_symtab
*pst
: require_partial_symbols (objfile
))
240 if (!pst
->psymtabs_addrmap_supported
241 && pc
>= pst
->text_low (objfile
) && pc
< pst
->text_high (objfile
))
243 struct partial_symtab
*best_pst
;
245 best_pst
= find_pc_sect_psymtab_closer (objfile
, pc
, section
, pst
,
247 if (best_pst
!= NULL
)
254 /* Psymtab version of find_pc_sect_compunit_symtab. See its definition in
255 the definition of quick_symbol_functions in symfile.h. */
257 struct compunit_symtab
*
258 psymbol_functions::find_pc_sect_compunit_symtab
259 (struct objfile
*objfile
,
260 struct bound_minimal_symbol msymbol
,
262 struct obj_section
*section
,
265 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
,
270 if (warn_if_readin
&& ps
->readin_p (objfile
))
271 /* Might want to error() here (in case symtab is corrupt and
272 will cause a core dump), but maybe we can successfully
273 continue, so let's not. */
275 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
276 paddress (objfile
->arch (), pc
));
277 psymtab_to_symtab (objfile
, ps
);
278 return ps
->get_compunit_symtab (objfile
);
283 /* Find which partial symbol within a psymtab matches PC and SECTION.
284 Return NULL if none. */
286 static struct partial_symbol
*
287 find_pc_sect_psymbol (struct objfile
*objfile
,
288 struct partial_symtab
*psymtab
, CORE_ADDR pc
,
289 struct obj_section
*section
)
291 struct partial_symbol
*best
= NULL
;
293 const CORE_ADDR textlow
= psymtab
->text_low (objfile
);
295 gdb_assert (psymtab
!= NULL
);
297 /* Cope with programs that start at address 0. */
298 best_pc
= (textlow
!= 0) ? textlow
- 1 : 0;
300 /* Search the global symbols as well as the static symbols, so that
301 find_pc_partial_function doesn't use a minimal symbol and thus
302 cache a bad endaddr. */
303 for (partial_symbol
*p
: psymtab
->global_psymbols
)
305 if (p
->domain
== VAR_DOMAIN
306 && p
->aclass
== LOC_BLOCK
307 && pc
>= p
->address (objfile
)
308 && (p
->address (objfile
) > best_pc
309 || (psymtab
->text_low (objfile
) == 0
310 && best_pc
== 0 && p
->address (objfile
) == 0)))
312 if (section
!= NULL
) /* Match on a specific section. */
314 if (!matching_obj_sections (p
->obj_section (objfile
),
318 best_pc
= p
->address (objfile
);
323 for (partial_symbol
*p
: psymtab
->static_psymbols
)
325 if (p
->domain
== VAR_DOMAIN
326 && p
->aclass
== LOC_BLOCK
327 && pc
>= p
->address (objfile
)
328 && (p
->address (objfile
) > best_pc
329 || (psymtab
->text_low (objfile
) == 0
330 && best_pc
== 0 && p
->address (objfile
) == 0)))
332 if (section
!= NULL
) /* Match on a specific section. */
334 if (!matching_obj_sections (p
->obj_section (objfile
),
338 best_pc
= p
->address (objfile
);
346 /* Psymtab version of lookup_global_symbol_language. See its definition in
347 the definition of quick_symbol_functions in symfile.h. */
350 psymbol_functions::lookup_global_symbol_language (struct objfile
*objfile
,
353 bool *symbol_found_p
)
355 *symbol_found_p
= false;
356 if (objfile
->sf
== NULL
)
357 return language_unknown
;
359 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
361 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
363 struct partial_symbol
*psym
;
364 if (ps
->readin_p (objfile
))
367 psym
= lookup_partial_symbol (objfile
, ps
, lookup_name
, 1, domain
);
370 *symbol_found_p
= true;
371 return psym
->ginfo
.language ();
375 return language_unknown
;
378 /* Returns true if PSYM matches LOOKUP_NAME. */
381 psymbol_name_matches (partial_symbol
*psym
,
382 const lookup_name_info
&lookup_name
)
384 const language_defn
*lang
= language_def (psym
->ginfo
.language ());
385 symbol_name_matcher_ftype
*name_match
386 = lang
->get_symbol_name_matcher (lookup_name
);
387 return name_match (psym
->ginfo
.search_name (), lookup_name
, NULL
);
390 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
391 the global block of PST if GLOBAL, and otherwise the static block.
392 MATCH is the comparison operation that returns true iff MATCH (s,
393 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
394 non-null, the symbols in the block are assumed to be ordered
395 according to it (allowing binary search). It must be compatible
396 with MATCH. Returns the symbol, if found, and otherwise NULL. */
398 static struct partial_symbol
*
399 match_partial_symbol (struct objfile
*objfile
,
400 struct partial_symtab
*pst
, int global
,
401 const lookup_name_info
&name
, domain_enum domain
,
402 symbol_compare_ftype
*ordered_compare
)
404 struct partial_symbol
**start
, **psym
;
405 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
407 ? pst
->global_psymbols
.size ()
408 : pst
->static_psymbols
.size ());
409 int do_linear_search
= 1;
415 &pst
->global_psymbols
[0] :
416 &pst
->static_psymbols
[0]);
418 if (global
&& ordered_compare
) /* Can use a binary search. */
420 do_linear_search
= 0;
422 /* Binary search. This search is guaranteed to end with center
423 pointing at the earliest partial symbol whose name might be
424 correct. At that point *all* partial symbols with an
425 appropriate name will be checked against the correct
429 top
= start
+ length
- 1;
433 center
= bottom
+ (top
- bottom
) / 2;
434 gdb_assert (center
< top
);
436 enum language lang
= (*center
)->ginfo
.language ();
437 const char *lang_ln
= name
.language_lookup_name (lang
);
439 if (ordered_compare ((*center
)->ginfo
.search_name (),
445 gdb_assert (top
== bottom
);
447 while (top
<= real_top
448 && psymbol_name_matches (*top
, name
))
450 if (symbol_matches_domain ((*top
)->ginfo
.language (),
451 (*top
)->domain
, domain
))
457 /* Can't use a binary search or else we found during the binary search that
458 we should also do a linear search. */
460 if (do_linear_search
)
462 for (psym
= start
; psym
< start
+ length
; psym
++)
464 if (symbol_matches_domain ((*psym
)->ginfo
.language (),
465 (*psym
)->domain
, domain
)
466 && psymbol_name_matches (*psym
, name
))
474 /* Look, in partial_symtab PST, for symbol whose natural name is
475 LOOKUP_NAME. Check the global symbols if GLOBAL, the static
478 static struct partial_symbol
*
479 lookup_partial_symbol (struct objfile
*objfile
,
480 struct partial_symtab
*pst
,
481 const lookup_name_info
&lookup_name
,
482 int global
, domain_enum domain
)
484 struct partial_symbol
**start
, **psym
;
485 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
487 ? pst
->global_psymbols
.size ()
488 : pst
->static_psymbols
.size ());
489 int do_linear_search
= 1;
495 &pst
->global_psymbols
[0] :
496 &pst
->static_psymbols
[0]);
498 if (global
) /* This means we can use a binary search. */
500 do_linear_search
= 0;
502 /* Binary search. This search is guaranteed to end with center
503 pointing at the earliest partial symbol whose name might be
504 correct. At that point *all* partial symbols with an
505 appropriate name will be checked against the correct
509 top
= start
+ length
- 1;
513 center
= bottom
+ (top
- bottom
) / 2;
515 gdb_assert (center
< top
);
517 if (strcmp_iw_ordered ((*center
)->ginfo
.search_name (),
518 lookup_name
.c_str ()) >= 0)
528 gdb_assert (top
== bottom
);
530 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
531 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
532 while (top
>= start
&& symbol_matches_search_name (&(*top
)->ginfo
,
536 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
539 while (top
<= real_top
&& symbol_matches_search_name (&(*top
)->ginfo
,
542 if (symbol_matches_domain ((*top
)->ginfo
.language (),
543 (*top
)->domain
, domain
))
549 /* Can't use a binary search or else we found during the binary search that
550 we should also do a linear search. */
552 if (do_linear_search
)
554 for (psym
= start
; psym
< start
+ length
; psym
++)
556 if (symbol_matches_domain ((*psym
)->ginfo
.language (),
557 (*psym
)->domain
, domain
)
558 && symbol_matches_search_name (&(*psym
)->ginfo
, lookup_name
))
566 /* Get the symbol table that corresponds to a partial_symtab.
567 This is fast after the first time you do it.
568 The result will be NULL if the primary symtab has no symbols,
569 which can happen. Otherwise the result is the primary symtab
570 that contains PST. */
572 static struct compunit_symtab
*
573 psymtab_to_symtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
575 /* If it is a shared psymtab, find an unshared psymtab that includes
576 it. Any such psymtab will do. */
577 while (pst
->user
!= NULL
)
580 /* If it's been looked up before, return it. */
581 if (pst
->get_compunit_symtab (objfile
))
582 return pst
->get_compunit_symtab (objfile
);
584 /* If it has not yet been read in, read it. */
585 if (!pst
->readin_p (objfile
))
587 scoped_restore decrementer
= increment_reading_symtab ();
591 printf_filtered (_("Reading in symbols for %s...\n"),
593 gdb_flush (gdb_stdout
);
596 pst
->read_symtab (objfile
);
599 return pst
->get_compunit_symtab (objfile
);
602 /* Psymtab version of find_last_source_symtab. See its definition in
603 the definition of quick_symbol_functions in symfile.h. */
606 psymbol_functions::find_last_source_symtab (struct objfile
*ofp
)
608 struct partial_symtab
*cs_pst
= NULL
;
610 for (partial_symtab
*ps
: require_partial_symbols (ofp
))
612 const char *name
= ps
->filename
;
613 int len
= strlen (name
);
615 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
616 || strcmp (name
, "<<C++-namespaces>>") == 0)))
622 if (cs_pst
->readin_p (ofp
))
624 internal_error (__FILE__
, __LINE__
,
625 _("select_source_symtab: "
626 "readin pst found and no symtabs."));
630 struct compunit_symtab
*cust
= psymtab_to_symtab (ofp
, cs_pst
);
634 return cust
->primary_filetab ();
640 /* Psymtab version of forget_cached_source_info. See its definition in
641 the definition of quick_symbol_functions in symfile.h. */
644 psymbol_functions::forget_cached_source_info (struct objfile
*objfile
)
646 for (partial_symtab
*pst
: require_partial_symbols (objfile
))
648 if (pst
->fullname
!= NULL
)
650 xfree (pst
->fullname
);
651 pst
->fullname
= NULL
;
657 print_partial_symbols (struct gdbarch
*gdbarch
, struct objfile
*objfile
,
658 const std::vector
<partial_symbol
*> &symbols
,
659 const char *what
, struct ui_file
*outfile
)
661 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
662 for (partial_symbol
*p
: symbols
)
665 fprintf_filtered (outfile
, " `%s'", p
->ginfo
.linkage_name ());
666 if (p
->ginfo
.demangled_name () != NULL
)
668 fprintf_filtered (outfile
, " `%s'",
669 p
->ginfo
.demangled_name ());
671 fputs_filtered (", ", outfile
);
675 fputs_filtered ("undefined domain, ", outfile
);
678 /* This is the usual thing -- don't print it. */
681 fputs_filtered ("struct domain, ", outfile
);
684 fputs_filtered ("module domain, ", outfile
);
687 fputs_filtered ("label domain, ", outfile
);
689 case COMMON_BLOCK_DOMAIN
:
690 fputs_filtered ("common block domain, ", outfile
);
693 fputs_filtered ("<invalid domain>, ", outfile
);
699 fputs_filtered ("undefined", outfile
);
702 fputs_filtered ("constant int", outfile
);
705 fputs_filtered ("static", outfile
);
708 fputs_filtered ("register", outfile
);
711 fputs_filtered ("pass by value", outfile
);
714 fputs_filtered ("pass by reference", outfile
);
716 case LOC_REGPARM_ADDR
:
717 fputs_filtered ("register address parameter", outfile
);
720 fputs_filtered ("stack parameter", outfile
);
723 fputs_filtered ("type", outfile
);
726 fputs_filtered ("label", outfile
);
729 fputs_filtered ("function", outfile
);
731 case LOC_CONST_BYTES
:
732 fputs_filtered ("constant bytes", outfile
);
735 fputs_filtered ("unresolved", outfile
);
737 case LOC_OPTIMIZED_OUT
:
738 fputs_filtered ("optimized out", outfile
);
741 fputs_filtered ("computed at runtime", outfile
);
744 fputs_filtered ("<invalid location>", outfile
);
747 fputs_filtered (", ", outfile
);
748 fputs_filtered (paddress (gdbarch
, p
->unrelocated_address ()), outfile
);
749 fprintf_filtered (outfile
, "\n");
754 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
755 struct ui_file
*outfile
)
757 struct gdbarch
*gdbarch
= objfile
->arch ();
760 if (psymtab
->anonymous
)
762 fprintf_filtered (outfile
, "\nAnonymous partial symtab (%s) ",
767 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
770 fprintf_filtered (outfile
, "(object %s)\n\n",
771 host_address_to_string (psymtab
));
772 fprintf_filtered (outfile
, " Read from object file %s (%s)\n",
773 objfile_name (objfile
),
774 host_address_to_string (objfile
));
776 if (psymtab
->readin_p (objfile
))
779 " Full symtab was read (at %s)\n",
780 host_address_to_string (psymtab
->get_compunit_symtab (objfile
)));
782 fprintf_filtered (outfile
, " Symbols cover text addresses ");
783 fputs_filtered (paddress (gdbarch
, psymtab
->text_low (objfile
)), outfile
);
784 fprintf_filtered (outfile
, "-");
785 fputs_filtered (paddress (gdbarch
, psymtab
->text_high (objfile
)), outfile
);
786 fprintf_filtered (outfile
, "\n");
787 fprintf_filtered (outfile
, " Address map supported - %s.\n",
788 psymtab
->psymtabs_addrmap_supported
? "yes" : "no");
789 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
790 psymtab
->number_of_dependencies
);
791 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
792 fprintf_filtered (outfile
, " %d %s\n", i
,
793 host_address_to_string (psymtab
->dependencies
[i
]));
794 if (psymtab
->user
!= NULL
)
795 fprintf_filtered (outfile
, " Shared partial symtab with user %s\n",
796 host_address_to_string (psymtab
->user
));
797 if (!psymtab
->global_psymbols
.empty ())
799 print_partial_symbols
800 (gdbarch
, objfile
, psymtab
->global_psymbols
,
803 if (!psymtab
->static_psymbols
.empty ())
805 print_partial_symbols
806 (gdbarch
, objfile
, psymtab
->static_psymbols
,
809 fprintf_filtered (outfile
, "\n");
812 /* Count the number of partial symbols in OBJFILE. */
815 psymbol_functions::count_psyms ()
818 for (partial_symtab
*pst
: m_partial_symtabs
->range ())
820 count
+= pst
->global_psymbols
.size ();
821 count
+= pst
->static_psymbols
.size ();
826 /* Psymtab version of print_stats. See its definition in
827 the definition of quick_symbol_functions in symfile.h. */
830 psymbol_functions::print_stats (struct objfile
*objfile
, bool print_bcache
)
836 int n_psyms
= count_psyms ();
838 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
842 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
844 if (!ps
->readin_p (objfile
))
847 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"),
849 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
850 m_partial_symtabs
->psymbol_cache
.memory_used ());
854 printf_filtered (_("Psymbol byte cache statistics:\n"));
855 m_partial_symtabs
->psymbol_cache
.print_statistics
856 ("partial symbol cache");
860 /* Psymtab version of dump. See its definition in
861 the definition of quick_symbol_functions in symfile.h. */
864 psymbol_functions::dump (struct objfile
*objfile
)
866 struct partial_symtab
*psymtab
;
868 if (m_partial_symtabs
->psymtabs
)
870 printf_filtered ("Psymtabs:\n");
871 for (psymtab
= m_partial_symtabs
->psymtabs
;
873 psymtab
= psymtab
->next
)
874 printf_filtered ("%s at %s\n",
876 host_address_to_string (psymtab
));
877 printf_filtered ("\n\n");
881 /* Psymtab version of expand_all_symtabs. See its definition in
882 the definition of quick_symbol_functions in symfile.h. */
885 psymbol_functions::expand_all_symtabs (struct objfile
*objfile
)
887 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
))
888 psymtab_to_symtab (objfile
, psymtab
);
891 /* Psymtab version of map_symbol_filenames. See its definition in
892 the definition of quick_symbol_functions in symfile.h. */
895 psymbol_functions::map_symbol_filenames
896 (struct objfile
*objfile
,
897 gdb::function_view
<symbol_filename_ftype
> fun
,
900 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
902 const char *fullname
;
904 if (ps
->readin_p (objfile
))
907 /* We can skip shared psymtabs here, because any file name will be
908 attached to the unshared psymtab. */
909 if (ps
->user
!= NULL
)
912 /* Anonymous psymtabs don't have a file name. */
918 fullname
= psymtab_to_fullname (ps
);
921 fun (ps
->filename
, fullname
);
925 /* Finds the fullname that a partial_symtab represents.
927 If this functions finds the fullname, it will save it in ps->fullname
928 and it will also return the value.
930 If this function fails to find the file that this partial_symtab represents,
931 NULL will be returned and ps->fullname will be set to NULL. */
934 psymtab_to_fullname (struct partial_symtab
*ps
)
936 gdb_assert (!ps
->anonymous
);
938 /* Use cached copy if we have it.
939 We rely on forget_cached_source_info being called appropriately
940 to handle cases like the file being moved. */
941 if (ps
->fullname
== NULL
)
943 gdb::unique_xmalloc_ptr
<char> fullname
944 = find_source_or_rewrite (ps
->filename
, ps
->dirname
);
945 ps
->fullname
= fullname
.release ();
951 /* Psymtab version of expand_matching_symbols. See its definition in
952 the definition of quick_symbol_functions in symfile.h. */
955 psymbol_functions::expand_matching_symbols
956 (struct objfile
*objfile
,
957 const lookup_name_info
&name
, domain_enum domain
,
959 symbol_compare_ftype
*ordered_compare
)
961 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
964 if (!ps
->readin_p (objfile
)
965 && match_partial_symbol (objfile
, ps
, global
, name
, domain
,
967 psymtab_to_symtab (objfile
, ps
);
971 /* A helper for psym_expand_symtabs_matching that handles searching
972 included psymtabs. This returns true if a symbol is found, and
973 false otherwise. It also updates the 'searched_flag' on the
974 various psymtabs that it searches. */
977 recursively_search_psymtabs
978 (struct partial_symtab
*ps
,
979 struct objfile
*objfile
,
980 block_search_flags search_flags
,
982 enum search_domain search
,
983 const lookup_name_info
&lookup_name
,
984 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> sym_matcher
)
987 enum psymtab_search_status result
= PST_SEARCHED_AND_NOT_FOUND
;
990 if (ps
->searched_flag
!= PST_NOT_SEARCHED
)
991 return ps
->searched_flag
== PST_SEARCHED_AND_FOUND
;
993 /* Recurse into shared psymtabs first, because they may have already
994 been searched, and this could save some time. */
995 for (i
= 0; i
< ps
->number_of_dependencies
; ++i
)
999 /* Skip non-shared dependencies, these are handled elsewhere. */
1000 if (ps
->dependencies
[i
]->user
== NULL
)
1003 r
= recursively_search_psymtabs (ps
->dependencies
[i
],
1004 objfile
, search_flags
, domain
, search
,
1005 lookup_name
, sym_matcher
);
1008 ps
->searched_flag
= PST_SEARCHED_AND_FOUND
;
1013 partial_symbol
**gbound
= (ps
->global_psymbols
.data ()
1014 + ps
->global_psymbols
.size ());
1015 partial_symbol
**sbound
= (ps
->static_psymbols
.data ()
1016 + ps
->static_psymbols
.size ());
1017 partial_symbol
**bound
= gbound
;
1019 /* Go through all of the symbols stored in a partial
1020 symtab in one loop. */
1021 partial_symbol
**psym
= ps
->global_psymbols
.data ();
1023 if ((search_flags
& SEARCH_GLOBAL_BLOCK
) == 0)
1025 if (ps
->static_psymbols
.empty ())
1029 psym
= ps
->static_psymbols
.data ();
1038 if (bound
== gbound
&& !ps
->static_psymbols
.empty ()
1039 && (search_flags
& SEARCH_STATIC_BLOCK
) != 0)
1041 psym
= ps
->static_psymbols
.data ();
1052 if ((domain
== UNDEF_DOMAIN
1053 || symbol_matches_domain ((*psym
)->ginfo
.language (),
1054 (*psym
)->domain
, domain
))
1055 && (search
== ALL_DOMAIN
1056 || (search
== MODULES_DOMAIN
1057 && (*psym
)->domain
== MODULE_DOMAIN
)
1058 || (search
== VARIABLES_DOMAIN
1059 && (*psym
)->aclass
!= LOC_TYPEDEF
1060 && (*psym
)->aclass
!= LOC_BLOCK
)
1061 || (search
== FUNCTIONS_DOMAIN
1062 && (*psym
)->aclass
== LOC_BLOCK
)
1063 || (search
== TYPES_DOMAIN
1064 && (*psym
)->aclass
== LOC_TYPEDEF
))
1065 && psymbol_name_matches (*psym
, lookup_name
)
1066 && (sym_matcher
== NULL
1067 || sym_matcher ((*psym
)->ginfo
.search_name ())))
1069 /* Found a match, so notify our caller. */
1070 result
= PST_SEARCHED_AND_FOUND
;
1077 ps
->searched_flag
= result
;
1078 return result
== PST_SEARCHED_AND_FOUND
;
1081 /* Psymtab version of expand_symtabs_matching. See its definition in
1082 the definition of quick_symbol_functions in symfile.h. */
1085 psymbol_functions::expand_symtabs_matching
1086 (struct objfile
*objfile
,
1087 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
1088 const lookup_name_info
*lookup_name
,
1089 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
1090 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
1091 block_search_flags search_flags
,
1093 enum search_domain search
)
1095 /* Clear the search flags. */
1096 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
1097 ps
->searched_flag
= PST_NOT_SEARCHED
;
1099 gdb::optional
<lookup_name_info
> psym_lookup_name
;
1100 if (lookup_name
!= nullptr)
1101 psym_lookup_name
= lookup_name
->make_ignore_params ();
1103 /* This invariant is documented in quick-functions.h. */
1104 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
1106 for (partial_symtab
*ps
: m_partial_symtabs
->range ())
1110 if (ps
->readin_p (objfile
))
1120 match
= file_matcher (ps
->filename
, false);
1123 /* Before we invoke realpath, which can get expensive when many
1124 files are involved, do a quick comparison of the basenames. */
1125 if (basenames_may_differ
1126 || file_matcher (lbasename (ps
->filename
), true))
1127 match
= file_matcher (psymtab_to_fullname (ps
), false);
1133 if (lookup_name
== nullptr
1134 || recursively_search_psymtabs (ps
, objfile
, search_flags
,
1139 struct compunit_symtab
*symtab
=
1140 psymtab_to_symtab (objfile
, ps
);
1142 gdb_assert (symtab
!= nullptr);
1144 if (expansion_notify
!= NULL
)
1145 if (!expansion_notify (symtab
))
1153 /* Psymtab version of has_symbols. See its definition in
1154 the definition of quick_symbol_functions in symfile.h. */
1157 psymbol_functions::has_symbols (struct objfile
*objfile
)
1159 return m_partial_symtabs
->psymtabs
!= NULL
;
1162 /* See quick_symbol_functions::has_unexpanded_symtabs in quick-symbol.h. */
1165 psymbol_functions::has_unexpanded_symtabs (struct objfile
*objfile
)
1167 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
))
1169 /* Is this already expanded? */
1170 if (psymtab
->readin_p (objfile
))
1173 /* It has not yet been expanded. */
1180 /* Helper function for psym_find_compunit_symtab_by_address that fills
1181 in m_psymbol_map for a given range of psymbols. */
1184 psymbol_functions::fill_psymbol_map
1185 (struct objfile
*objfile
,
1186 struct partial_symtab
*psymtab
,
1187 std::set
<CORE_ADDR
> *seen_addrs
,
1188 const std::vector
<partial_symbol
*> &symbols
)
1190 for (partial_symbol
*psym
: symbols
)
1192 if (psym
->aclass
== LOC_STATIC
)
1194 CORE_ADDR addr
= psym
->address (objfile
);
1195 if (seen_addrs
->find (addr
) == seen_addrs
->end ())
1197 seen_addrs
->insert (addr
);
1198 m_psymbol_map
.emplace_back (addr
, psymtab
);
1204 /* See find_compunit_symtab_by_address in quick_symbol_functions, in
1208 psymbol_functions::find_compunit_symtab_by_address (struct objfile
*objfile
,
1211 if (m_psymbol_map
.empty ())
1213 std::set
<CORE_ADDR
> seen_addrs
;
1215 for (partial_symtab
*pst
: require_partial_symbols (objfile
))
1217 fill_psymbol_map (objfile
, pst
,
1219 pst
->global_psymbols
);
1220 fill_psymbol_map (objfile
, pst
,
1222 pst
->static_psymbols
);
1225 m_psymbol_map
.shrink_to_fit ();
1227 std::sort (m_psymbol_map
.begin (), m_psymbol_map
.end (),
1228 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1229 const std::pair
<CORE_ADDR
, partial_symtab
*> &b
)
1231 return a
.first
< b
.first
;
1235 auto iter
= std::lower_bound
1236 (m_psymbol_map
.begin (), m_psymbol_map
.end (), address
,
1237 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1243 if (iter
== m_psymbol_map
.end () || iter
->first
!= address
)
1246 return psymtab_to_symtab (objfile
, iter
->second
);
1251 /* Partially fill a partial symtab. It will be completely filled at
1252 the end of the symbol list. */
1254 partial_symtab::partial_symtab (const char *filename
,
1255 psymtab_storage
*partial_symtabs
,
1256 objfile_per_bfd_storage
*objfile_per_bfd
,
1258 : partial_symtab (filename
, partial_symtabs
, objfile_per_bfd
)
1260 set_text_low (textlow
);
1261 set_text_high (raw_text_low ()); /* default */
1264 /* Perform "finishing up" operations of a partial symtab. */
1267 partial_symtab::end ()
1269 global_psymbols
.shrink_to_fit ();
1270 static_psymbols
.shrink_to_fit ();
1272 /* Sort the global list; don't sort the static list. */
1273 std::sort (global_psymbols
.begin (),
1274 global_psymbols
.end (),
1275 [] (partial_symbol
*s1
, partial_symbol
*s2
)
1277 return strcmp_iw_ordered (s1
->ginfo
.search_name (),
1278 s2
->ginfo
.search_name ()) < 0;
1282 /* See psymtab.h. */
1285 psymbol_bcache::hash (const void *addr
, int length
)
1287 unsigned long h
= 0;
1288 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1289 unsigned int lang
= psymbol
->ginfo
.language ();
1290 unsigned int domain
= psymbol
->domain
;
1291 unsigned int theclass
= psymbol
->aclass
;
1293 h
= fast_hash (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1294 h
= fast_hash (&lang
, sizeof (unsigned int), h
);
1295 h
= fast_hash (&domain
, sizeof (unsigned int), h
);
1296 h
= fast_hash (&theclass
, sizeof (unsigned int), h
);
1297 /* Note that psymbol names are interned via compute_and_set_names, so
1298 there's no need to hash the contents of the name here. */
1299 h
= fast_hash (&psymbol
->ginfo
.m_name
, sizeof (psymbol
->ginfo
.m_name
), h
);
1304 /* See psymtab.h. */
1307 psymbol_bcache::compare (const void *addr1
, const void *addr2
, int length
)
1309 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1310 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1312 return (memcmp (&sym1
->ginfo
.value
, &sym2
->ginfo
.value
,
1313 sizeof (sym1
->ginfo
.value
)) == 0
1314 && sym1
->ginfo
.language () == sym2
->ginfo
.language ()
1315 && sym1
->domain
== sym2
->domain
1316 && sym1
->aclass
== sym2
->aclass
1317 /* Note that psymbol names are interned via
1318 compute_and_set_names, so there's no need to compare the
1319 contents of the name here. */
1320 && sym1
->ginfo
.linkage_name () == sym2
->ginfo
.linkage_name ());
1323 /* See psympriv.h. */
1326 partial_symtab::add_psymbol (const partial_symbol
&psymbol
,
1327 psymbol_placement where
,
1328 psymtab_storage
*partial_symtabs
,
1329 struct objfile
*objfile
)
1333 /* Stash the partial symbol away in the cache. */
1334 partial_symbol
*psym
1335 = ((struct partial_symbol
*)
1336 partial_symtabs
->psymbol_cache
.insert
1337 (&psymbol
, sizeof (struct partial_symbol
), &added
));
1339 /* Do not duplicate global partial symbols. */
1340 if (where
== psymbol_placement::GLOBAL
&& !added
)
1343 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1344 std::vector
<partial_symbol
*> &list
1345 = (where
== psymbol_placement::STATIC
1348 list
.push_back (psym
);
1351 /* See psympriv.h. */
1354 partial_symtab::add_psymbol (gdb::string_view name
, bool copy_name
,
1356 enum address_class theclass
,
1358 psymbol_placement where
,
1360 enum language language
,
1361 psymtab_storage
*partial_symtabs
,
1362 struct objfile
*objfile
)
1364 struct partial_symbol psymbol
;
1365 memset (&psymbol
, 0, sizeof (psymbol
));
1367 psymbol
.set_unrelocated_address (coreaddr
);
1368 psymbol
.ginfo
.set_section_index (section
);
1369 psymbol
.domain
= domain
;
1370 psymbol
.aclass
= theclass
;
1371 psymbol
.ginfo
.set_language (language
, partial_symtabs
->obstack ());
1372 psymbol
.ginfo
.compute_and_set_names (name
, copy_name
, objfile
->per_bfd
);
1374 add_psymbol (psymbol
, where
, partial_symtabs
, objfile
);
1377 /* See psympriv.h. */
1379 partial_symtab::partial_symtab (const char *filename_
,
1380 psymtab_storage
*partial_symtabs
,
1381 objfile_per_bfd_storage
*objfile_per_bfd
)
1382 : searched_flag (PST_NOT_SEARCHED
),
1386 partial_symtabs
->install_psymtab (this);
1388 filename
= objfile_per_bfd
->intern (filename_
);
1390 if (symtab_create_debug
)
1392 /* Be a bit clever with debugging messages, and don't print objfile
1393 every time, only when it changes. */
1394 static std::string last_bfd_name
;
1395 const char *this_bfd_name
1396 = bfd_get_filename (objfile_per_bfd
->get_bfd ());
1398 if (last_bfd_name
.empty () || last_bfd_name
!= this_bfd_name
)
1400 last_bfd_name
= this_bfd_name
;
1401 fprintf_filtered (gdb_stdlog
,
1402 "Creating one or more psymtabs for %s ...\n",
1405 fprintf_filtered (gdb_stdlog
,
1406 "Created psymtab %s for module %s.\n",
1407 host_address_to_string (this), filename
);
1411 /* See psympriv.h. */
1414 partial_symtab::expand_dependencies (struct objfile
*objfile
)
1416 for (int i
= 0; i
< number_of_dependencies
; ++i
)
1418 if (!dependencies
[i
]->readin_p (objfile
)
1419 && dependencies
[i
]->user
== NULL
)
1421 /* Inform about additional files to be read in. */
1424 puts_filtered (" ");
1425 gdb_stdout
->wrap_here (0);
1426 puts_filtered ("and ");
1427 gdb_stdout
->wrap_here (0);
1428 printf_filtered ("%s...", dependencies
[i
]->filename
);
1429 gdb_stdout
->wrap_here (0); /* Flush output */
1430 gdb_flush (gdb_stdout
);
1432 dependencies
[i
]->expand_psymtab (objfile
);
1439 psymtab_storage::discard_psymtab (struct partial_symtab
*pst
)
1441 struct partial_symtab
**prev_pst
;
1444 Empty psymtabs happen as a result of header files which don't
1445 have any symbols in them. There can be a lot of them. But this
1446 check is wrong, in that a psymtab with N_SLINE entries but
1447 nothing else is not empty, but we don't realize that. Fixing
1448 that without slowing things down might be tricky. */
1450 /* First, snip it out of the psymtab chain. */
1452 prev_pst
= &psymtabs
;
1453 while ((*prev_pst
) != pst
)
1454 prev_pst
= &((*prev_pst
)->next
);
1455 (*prev_pst
) = pst
->next
;
1461 /* Helper function for maintenance_print_psymbols to print the addrmap
1462 of PSYMTAB. If PSYMTAB is NULL print the entire addrmap. */
1465 dump_psymtab_addrmap (struct objfile
*objfile
,
1466 psymtab_storage
*partial_symtabs
,
1467 struct partial_symtab
*psymtab
,
1468 struct ui_file
*outfile
)
1470 if ((psymtab
== NULL
1471 || psymtab
->psymtabs_addrmap_supported
)
1472 && partial_symtabs
->psymtabs_addrmap
!= NULL
)
1474 if (psymtab
== nullptr)
1475 fprintf_filtered (outfile
, _("Entire address map:\n"));
1477 fprintf_filtered (outfile
, _("Address map:\n"));
1478 addrmap_dump (partial_symtabs
->psymtabs_addrmap
, outfile
, psymtab
);
1483 maintenance_print_psymbols (const char *args
, int from_tty
)
1485 struct ui_file
*outfile
= gdb_stdout
;
1486 char *address_arg
= NULL
, *source_arg
= NULL
, *objfile_arg
= NULL
;
1487 int i
, outfile_idx
, found
;
1489 struct obj_section
*section
= NULL
;
1493 gdb_argv
argv (args
);
1495 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
1497 if (strcmp (argv
[i
], "-pc") == 0)
1499 if (argv
[i
+ 1] == NULL
)
1500 error (_("Missing pc value"));
1501 address_arg
= argv
[++i
];
1503 else if (strcmp (argv
[i
], "-source") == 0)
1505 if (argv
[i
+ 1] == NULL
)
1506 error (_("Missing source file"));
1507 source_arg
= argv
[++i
];
1509 else if (strcmp (argv
[i
], "-objfile") == 0)
1511 if (argv
[i
+ 1] == NULL
)
1512 error (_("Missing objfile name"));
1513 objfile_arg
= argv
[++i
];
1515 else if (strcmp (argv
[i
], "--") == 0)
1517 /* End of options. */
1521 else if (argv
[i
][0] == '-')
1523 /* Future proofing: Don't allow OUTFILE to begin with "-". */
1524 error (_("Unknown option: %s"), argv
[i
]);
1531 if (address_arg
!= NULL
&& source_arg
!= NULL
)
1532 error (_("Must specify at most one of -pc and -source"));
1534 stdio_file arg_outfile
;
1536 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
1538 if (argv
[outfile_idx
+ 1] != NULL
)
1539 error (_("Junk at end of command"));
1540 gdb::unique_xmalloc_ptr
<char> outfile_name
1541 (tilde_expand (argv
[outfile_idx
]));
1542 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
1543 perror_with_name (outfile_name
.get ());
1544 outfile
= &arg_outfile
;
1547 if (address_arg
!= NULL
)
1549 pc
= parse_and_eval_address (address_arg
);
1550 /* If we fail to find a section, that's ok, try the lookup anyway. */
1551 section
= find_pc_section (pc
);
1555 for (objfile
*objfile
: current_program_space
->objfiles ())
1557 int printed_objfile_header
= 0;
1558 int print_for_objfile
= 1;
1561 if (objfile_arg
!= NULL
)
1563 = compare_filenames_for_search (objfile_name (objfile
),
1565 if (!print_for_objfile
)
1568 for (const auto &iter
: objfile
->qf
)
1570 psymbol_functions
*psf
1571 = dynamic_cast<psymbol_functions
*> (iter
.get ());
1575 psymtab_storage
*partial_symtabs
1576 = psf
->get_partial_symtabs ().get ();
1578 if (address_arg
!= NULL
)
1580 struct bound_minimal_symbol msymbol
= { NULL
, NULL
};
1582 /* We don't assume each pc has a unique objfile (this is for
1584 struct partial_symtab
*ps
1585 = psf
->find_pc_sect_psymtab (objfile
, pc
, section
, msymbol
);
1588 if (!printed_objfile_header
)
1590 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1591 objfile_name (objfile
));
1592 printed_objfile_header
= 1;
1594 dump_psymtab (objfile
, ps
, outfile
);
1595 dump_psymtab_addrmap (objfile
, partial_symtabs
, ps
, outfile
);
1601 for (partial_symtab
*ps
: psf
->require_partial_symbols (objfile
))
1603 int print_for_source
= 0;
1606 if (source_arg
!= NULL
)
1609 = compare_filenames_for_search (ps
->filename
, source_arg
);
1612 if (source_arg
== NULL
1613 || print_for_source
)
1615 if (!printed_objfile_header
)
1617 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1618 objfile_name (objfile
));
1619 printed_objfile_header
= 1;
1621 dump_psymtab (objfile
, ps
, outfile
);
1622 dump_psymtab_addrmap (objfile
, partial_symtabs
, ps
,
1628 /* If we're printing all the objfile's symbols dump the full addrmap. */
1630 if (address_arg
== NULL
1631 && source_arg
== NULL
1632 && partial_symtabs
->psymtabs_addrmap
!= NULL
)
1634 outfile
->puts ("\n");
1635 dump_psymtab_addrmap (objfile
, partial_symtabs
, NULL
, outfile
);
1642 if (address_arg
!= NULL
)
1643 error (_("No partial symtab for address: %s"), address_arg
);
1644 if (source_arg
!= NULL
)
1645 error (_("No partial symtab for source file: %s"), source_arg
);
1649 /* List all the partial symbol tables whose names match REGEXP (optional). */
1652 maintenance_info_psymtabs (const char *regexp
, int from_tty
)
1657 for (struct program_space
*pspace
: program_spaces
)
1658 for (objfile
*objfile
: pspace
->objfiles ())
1660 struct gdbarch
*gdbarch
= objfile
->arch ();
1662 /* We don't want to print anything for this objfile until we
1663 actually find a symtab whose name matches. */
1664 int printed_objfile_start
= 0;
1666 for (const auto &iter
: objfile
->qf
)
1668 psymbol_functions
*psf
1669 = dynamic_cast<psymbol_functions
*> (iter
.get ());
1672 for (partial_symtab
*psymtab
: psf
->require_partial_symbols (objfile
))
1677 || re_exec (psymtab
->filename
))
1679 if (! printed_objfile_start
)
1681 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
1682 gdb_stdout
->wrap_here (2);
1683 printf_filtered ("((struct objfile *) %s)\n",
1684 host_address_to_string (objfile
));
1685 printed_objfile_start
= 1;
1688 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1689 gdb_stdout
->wrap_here (4);
1690 printf_filtered ("((struct partial_symtab *) %s)\n",
1691 host_address_to_string (psymtab
));
1693 printf_filtered (" readin %s\n",
1694 psymtab
->readin_p (objfile
) ? "yes" : "no");
1695 printf_filtered (" fullname %s\n",
1697 ? psymtab
->fullname
: "(null)");
1698 printf_filtered (" text addresses ");
1699 puts_filtered (paddress (gdbarch
,
1700 psymtab
->text_low (objfile
)));
1701 printf_filtered (" -- ");
1702 puts_filtered (paddress (gdbarch
,
1703 psymtab
->text_high (objfile
)));
1704 printf_filtered ("\n");
1705 printf_filtered (" psymtabs_addrmap_supported %s\n",
1706 (psymtab
->psymtabs_addrmap_supported
1708 printf_filtered (" globals ");
1709 if (!psymtab
->global_psymbols
.empty ())
1711 ("(* (struct partial_symbol **) %s @ %d)\n",
1712 host_address_to_string (psymtab
->global_psymbols
.data ()),
1713 (int) psymtab
->global_psymbols
.size ());
1715 printf_filtered ("(none)\n");
1716 printf_filtered (" statics ");
1717 if (!psymtab
->static_psymbols
.empty ())
1719 ("(* (struct partial_symbol **) %s @ %d)\n",
1720 host_address_to_string (psymtab
->static_psymbols
.data ()),
1721 (int) psymtab
->static_psymbols
.size ());
1723 printf_filtered ("(none)\n");
1725 printf_filtered (" user %s "
1726 "((struct partial_symtab *) %s)\n",
1727 psymtab
->user
->filename
,
1728 host_address_to_string (psymtab
->user
));
1729 printf_filtered (" dependencies ");
1730 if (psymtab
->number_of_dependencies
)
1734 printf_filtered ("{\n");
1735 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1737 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
1739 /* Note the string concatenation there --- no
1741 printf_filtered (" psymtab %s "
1742 "((struct partial_symtab *) %s)\n",
1744 host_address_to_string (dep
));
1746 printf_filtered (" }\n");
1749 printf_filtered ("(none)\n");
1750 printf_filtered (" }\n");
1755 if (printed_objfile_start
)
1756 printf_filtered ("}\n");
1760 /* Check consistency of currently expanded psymtabs vs symtabs. */
1763 maintenance_check_psymtabs (const char *ignore
, int from_tty
)
1766 struct compunit_symtab
*cust
= NULL
;
1767 const struct blockvector
*bv
;
1768 const struct block
*b
;
1770 for (objfile
*objfile
: current_program_space
->objfiles ())
1772 for (const auto &iter
: objfile
->qf
)
1774 psymbol_functions
*psf
1775 = dynamic_cast<psymbol_functions
*> (iter
.get ());
1779 for (partial_symtab
*ps
: psf
->require_partial_symbols (objfile
))
1781 struct gdbarch
*gdbarch
= objfile
->arch ();
1783 /* We don't call psymtab_to_symtab here because that may cause symtab
1784 expansion. When debugging a problem it helps if checkers leave
1785 things unchanged. */
1786 cust
= ps
->get_compunit_symtab (objfile
);
1788 /* First do some checks that don't require the associated symtab. */
1789 if (ps
->text_high (objfile
) < ps
->text_low (objfile
))
1791 printf_filtered ("Psymtab ");
1792 puts_filtered (ps
->filename
);
1793 printf_filtered (" covers bad range ");
1794 puts_filtered (paddress (gdbarch
, ps
->text_low (objfile
)));
1795 printf_filtered (" - ");
1796 puts_filtered (paddress (gdbarch
, ps
->text_high (objfile
)));
1797 printf_filtered ("\n");
1801 /* Now do checks requiring the associated symtab. */
1804 bv
= COMPUNIT_BLOCKVECTOR (cust
);
1805 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1806 for (partial_symbol
*psym
: ps
->static_psymbols
)
1808 /* Skip symbols for inlined functions without address. These may
1809 or may not have a match in the full symtab. */
1810 if (psym
->aclass
== LOC_BLOCK
1811 && psym
->ginfo
.value
.address
== 0)
1814 sym
= block_lookup_symbol (b
, psym
->ginfo
.search_name (),
1815 symbol_name_match_type::SEARCH_NAME
,
1819 printf_filtered ("Static symbol `");
1820 puts_filtered (psym
->ginfo
.linkage_name ());
1821 printf_filtered ("' only found in ");
1822 puts_filtered (ps
->filename
);
1823 printf_filtered (" psymtab\n");
1826 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1827 for (partial_symbol
*psym
: ps
->global_psymbols
)
1829 sym
= block_lookup_symbol (b
, psym
->ginfo
.search_name (),
1830 symbol_name_match_type::SEARCH_NAME
,
1834 printf_filtered ("Global symbol `");
1835 puts_filtered (psym
->ginfo
.linkage_name ());
1836 printf_filtered ("' only found in ");
1837 puts_filtered (ps
->filename
);
1838 printf_filtered (" psymtab\n");
1841 if (ps
->raw_text_high () != 0
1842 && (ps
->text_low (objfile
) < BLOCK_START (b
)
1843 || ps
->text_high (objfile
) > BLOCK_END (b
)))
1845 printf_filtered ("Psymtab ");
1846 puts_filtered (ps
->filename
);
1847 printf_filtered (" covers ");
1848 puts_filtered (paddress (gdbarch
, ps
->text_low (objfile
)));
1849 printf_filtered (" - ");
1850 puts_filtered (paddress (gdbarch
, ps
->text_high (objfile
)));
1851 printf_filtered (" but symtab covers only ");
1852 puts_filtered (paddress (gdbarch
, BLOCK_START (b
)));
1853 printf_filtered (" - ");
1854 puts_filtered (paddress (gdbarch
, BLOCK_END (b
)));
1855 printf_filtered ("\n");
1862 void _initialize_psymtab ();
1864 _initialize_psymtab ()
1866 add_cmd ("psymbols", class_maintenance
, maintenance_print_psymbols
, _("\
1867 Print dump of current partial symbol definitions.\n\
1868 Usage: mt print psymbols [-objfile OBJFILE] [-pc ADDRESS] [--] [OUTFILE]\n\
1869 mt print psymbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
1870 Entries in the partial symbol table are dumped to file OUTFILE,\n\
1871 or the terminal if OUTFILE is unspecified.\n\
1872 If ADDRESS is provided, dump only the file for that address.\n\
1873 If SOURCE is provided, dump only that file's symbols.\n\
1874 If OBJFILE is provided, dump only that file's minimal symbols."),
1875 &maintenanceprintlist
);
1877 add_cmd ("psymtabs", class_maintenance
, maintenance_info_psymtabs
, _("\
1878 List the partial symbol tables for all object files.\n\
1879 This does not include information about individual partial symbols,\n\
1880 just the symbol table structures themselves."),
1881 &maintenanceinfolist
);
1883 add_cmd ("check-psymtabs", class_maintenance
, maintenance_check_psymtabs
,
1885 Check consistency of currently expanded psymtabs versus symtabs."),