1 /* Partial symbol tables.
3 Copyright (C) 2009-2021 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 /* Helper function for psym_map_symtabs_matching_filename that
91 expands the symtabs and calls the iterator. */
94 partial_map_expand_apply (struct objfile
*objfile
,
96 const char *real_path
,
97 struct partial_symtab
*pst
,
98 gdb::function_view
<bool (symtab
*)> callback
)
100 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
102 /* Shared psymtabs should never be seen here. Instead they should
103 be handled properly by the caller. */
104 gdb_assert (pst
->user
== NULL
);
106 /* Don't visit already-expanded psymtabs. */
107 if (pst
->readin_p (objfile
))
110 /* This may expand more than one symtab, and we want to iterate over
112 psymtab_to_symtab (objfile
, pst
);
114 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
115 last_made
, callback
);
118 /* Psymtab version of map_symtabs_matching_filename. See its definition in
119 the definition of quick_symbol_functions in symfile.h. */
122 psymbol_functions::map_symtabs_matching_filename
123 (struct objfile
*objfile
,
125 const char *real_path
,
126 gdb::function_view
<bool (symtab
*)> callback
)
128 const char *name_basename
= lbasename (name
);
130 for (partial_symtab
*pst
: require_partial_symbols (objfile
))
132 /* Anonymous psymtabs don't have a file name. */
136 if (compare_filenames_for_search (pst
->filename
, name
))
141 if (partial_map_expand_apply (objfile
, name
, real_path
,
147 /* Before we invoke realpath, which can get expensive when many
148 files are involved, do a quick comparison of the basenames. */
149 if (! basenames_may_differ
150 && FILENAME_CMP (name_basename
, lbasename (pst
->filename
)) != 0)
153 if (compare_filenames_for_search (psymtab_to_fullname (pst
), name
))
155 if (partial_map_expand_apply (objfile
, name
, real_path
,
161 /* If the user gave us an absolute path, try to find the file in
162 this symtab and use its absolute path. */
163 if (real_path
!= NULL
)
165 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
166 gdb_assert (IS_ABSOLUTE_PATH (name
));
167 if (filename_cmp (psymtab_to_fullname (pst
), real_path
) == 0)
169 if (partial_map_expand_apply (objfile
, name
, real_path
,
180 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
181 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
183 static struct partial_symtab
*
184 find_pc_sect_psymtab_closer (struct objfile
*objfile
,
185 CORE_ADDR pc
, struct obj_section
*section
,
186 struct partial_symtab
*pst
,
187 struct bound_minimal_symbol msymbol
)
189 struct partial_symtab
*tpst
;
190 struct partial_symtab
*best_pst
= pst
;
191 CORE_ADDR best_addr
= pst
->text_low (objfile
);
193 gdb_assert (!pst
->psymtabs_addrmap_supported
);
195 /* An objfile that has its functions reordered might have
196 many partial symbol tables containing the PC, but
197 we want the partial symbol table that contains the
198 function containing the PC. */
199 if (!(objfile
->flags
& OBJF_REORDERED
)
200 && section
== NULL
) /* Can't validate section this way. */
203 if (msymbol
.minsym
== NULL
)
206 /* The code range of partial symtabs sometimes overlap, so, in
207 the loop below, we need to check all partial symtabs and
208 find the one that fits better for the given PC address. We
209 select the partial symtab that contains a symbol whose
210 address is closest to the PC address. By closest we mean
211 that find_pc_sect_symbol returns the symbol with address
212 that is closest and still less than the given PC. */
213 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
215 if (pc
>= tpst
->text_low (objfile
) && pc
< tpst
->text_high (objfile
))
217 struct partial_symbol
*p
;
220 /* NOTE: This assumes that every psymbol has a
221 corresponding msymbol, which is not necessarily
222 true; the debug info might be much richer than the
223 object's symbol table. */
224 p
= find_pc_sect_psymbol (objfile
, tpst
, pc
, section
);
226 && (p
->address (objfile
) == BMSYMBOL_VALUE_ADDRESS (msymbol
)))
229 /* Also accept the textlow value of a psymtab as a
230 "symbol", to provide some support for partial
231 symbol tables with line information but no debug
232 symbols (e.g. those produced by an assembler). */
234 this_addr
= p
->address (objfile
);
236 this_addr
= tpst
->text_low (objfile
);
238 /* Check whether it is closer than our current
239 BEST_ADDR. Since this symbol address is
240 necessarily lower or equal to PC, the symbol closer
241 to PC is the symbol which address is the highest.
242 This way we return the psymtab which contains such
243 best match symbol. This can help in cases where the
244 symbol information/debuginfo is not complete, like
245 for instance on IRIX6 with gcc, where no debug info
246 is emitted for statics. (See also the nodebug.exp
248 if (this_addr
> best_addr
)
250 best_addr
= this_addr
;
258 /* See psympriv.h. */
260 struct partial_symtab
*
261 psymbol_functions::find_pc_sect_psymtab (struct objfile
*objfile
,
263 struct obj_section
*section
,
264 struct bound_minimal_symbol msymbol
)
266 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better
267 granularity than the later used TEXTLOW/TEXTHIGH one. However, we need
268 to take care as the PSYMTABS_ADDRMAP can hold things other than partial
269 symtabs in some cases.
271 This function should only be called for objfiles that are using partial
272 symtabs, not for objfiles that are using indexes (.gdb_index or
273 .debug_names), however 'maintenance print psymbols' calls this function
274 directly for all objfiles. If we assume that PSYMTABS_ADDRMAP contains
275 partial symtabs then we will end up returning a pointer to an object
276 that is not a partial_symtab, which doesn't end well. */
278 if (m_partial_symtabs
->psymtabs
!= NULL
279 && m_partial_symtabs
->psymtabs_addrmap
!= NULL
)
281 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
283 struct partial_symtab
*pst
284 = ((struct partial_symtab
*)
285 addrmap_find (m_partial_symtabs
->psymtabs_addrmap
,
289 /* FIXME: addrmaps currently do not handle overlayed sections,
290 so fall back to the non-addrmap case if we're debugging
291 overlays and the addrmap returned the wrong section. */
292 if (overlay_debugging
&& msymbol
.minsym
!= NULL
&& section
!= NULL
)
294 struct partial_symbol
*p
;
296 /* NOTE: This assumes that every psymbol has a
297 corresponding msymbol, which is not necessarily
298 true; the debug info might be much richer than the
299 object's symbol table. */
300 p
= find_pc_sect_psymbol (objfile
, pst
, pc
, section
);
302 || (p
->address (objfile
)
303 != BMSYMBOL_VALUE_ADDRESS (msymbol
)))
307 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
308 PSYMTABS_ADDRMAP we used has already the best 1-byte
309 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
310 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
319 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
320 which still have no corresponding full SYMTABs read. But it is not
321 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
324 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
325 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
326 debug info type in single OBJFILE. */
328 for (partial_symtab
*pst
: require_partial_symbols (objfile
))
329 if (!pst
->psymtabs_addrmap_supported
330 && pc
>= pst
->text_low (objfile
) && pc
< pst
->text_high (objfile
))
332 struct partial_symtab
*best_pst
;
334 best_pst
= find_pc_sect_psymtab_closer (objfile
, pc
, section
, pst
,
336 if (best_pst
!= NULL
)
343 /* Psymtab version of find_pc_sect_compunit_symtab. See its definition in
344 the definition of quick_symbol_functions in symfile.h. */
346 struct compunit_symtab
*
347 psymbol_functions::find_pc_sect_compunit_symtab
348 (struct objfile
*objfile
,
349 struct bound_minimal_symbol msymbol
,
351 struct obj_section
*section
,
354 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
,
359 if (warn_if_readin
&& ps
->readin_p (objfile
))
360 /* Might want to error() here (in case symtab is corrupt and
361 will cause a core dump), but maybe we can successfully
362 continue, so let's not. */
364 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
365 paddress (objfile
->arch (), pc
));
366 psymtab_to_symtab (objfile
, ps
);
367 return ps
->get_compunit_symtab (objfile
);
372 /* Find which partial symbol within a psymtab matches PC and SECTION.
373 Return NULL if none. */
375 static struct partial_symbol
*
376 find_pc_sect_psymbol (struct objfile
*objfile
,
377 struct partial_symtab
*psymtab
, CORE_ADDR pc
,
378 struct obj_section
*section
)
380 struct partial_symbol
*best
= NULL
;
382 const CORE_ADDR textlow
= psymtab
->text_low (objfile
);
384 gdb_assert (psymtab
!= NULL
);
386 /* Cope with programs that start at address 0. */
387 best_pc
= (textlow
!= 0) ? textlow
- 1 : 0;
389 /* Search the global symbols as well as the static symbols, so that
390 find_pc_partial_function doesn't use a minimal symbol and thus
391 cache a bad endaddr. */
392 for (partial_symbol
*p
: psymtab
->global_psymbols
)
394 if (p
->domain
== VAR_DOMAIN
395 && p
->aclass
== LOC_BLOCK
396 && pc
>= p
->address (objfile
)
397 && (p
->address (objfile
) > best_pc
398 || (psymtab
->text_low (objfile
) == 0
399 && best_pc
== 0 && p
->address (objfile
) == 0)))
401 if (section
!= NULL
) /* Match on a specific section. */
403 if (!matching_obj_sections (p
->obj_section (objfile
),
407 best_pc
= p
->address (objfile
);
412 for (partial_symbol
*p
: psymtab
->static_psymbols
)
414 if (p
->domain
== VAR_DOMAIN
415 && p
->aclass
== LOC_BLOCK
416 && pc
>= p
->address (objfile
)
417 && (p
->address (objfile
) > best_pc
418 || (psymtab
->text_low (objfile
) == 0
419 && best_pc
== 0 && p
->address (objfile
) == 0)))
421 if (section
!= NULL
) /* Match on a specific section. */
423 if (!matching_obj_sections (p
->obj_section (objfile
),
427 best_pc
= p
->address (objfile
);
435 /* Psymtab version of lookup_symbol. See its definition in
436 the definition of quick_symbol_functions in symfile.h. */
438 struct compunit_symtab
*
439 psymbol_functions::lookup_symbol (struct objfile
*objfile
,
440 block_enum block_index
, const char *name
,
441 const domain_enum domain
)
443 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
444 struct compunit_symtab
*stab_best
= NULL
;
446 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
448 lookup_name_info psym_lookup_name
= lookup_name
.make_ignore_params ();
450 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
452 if (!ps
->readin_p (objfile
)
453 && lookup_partial_symbol (objfile
, ps
, psym_lookup_name
,
454 psymtab_index
, domain
))
456 struct symbol
*sym
, *with_opaque
= NULL
;
457 struct compunit_symtab
*stab
= psymtab_to_symtab (objfile
, ps
);
458 /* Note: While psymtab_to_symtab can return NULL if the
459 partial symtab is empty, we can assume it won't here
460 because lookup_partial_symbol succeeded. */
461 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
462 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
464 sym
= block_find_symbol (block
, name
, domain
,
465 block_find_non_opaque_type_preferred
,
468 /* Some caution must be observed with overloaded functions
469 and methods, since the index will not contain any overload
470 information (but NAME might contain it). */
473 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
475 if (with_opaque
!= NULL
476 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
479 /* Keep looking through other psymtabs. */
486 /* Psymtab version of lookup_global_symbol_language. See its definition in
487 the definition of quick_symbol_functions in symfile.h. */
490 psymbol_functions::lookup_global_symbol_language (struct objfile
*objfile
,
493 bool *symbol_found_p
)
495 *symbol_found_p
= false;
496 if (objfile
->sf
== NULL
)
497 return language_unknown
;
499 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
501 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
503 struct partial_symbol
*psym
;
504 if (ps
->readin_p (objfile
))
507 psym
= lookup_partial_symbol (objfile
, ps
, lookup_name
, 1, domain
);
510 *symbol_found_p
= true;
511 return psym
->ginfo
.language ();
515 return language_unknown
;
518 /* Returns true if PSYM matches LOOKUP_NAME. */
521 psymbol_name_matches (partial_symbol
*psym
,
522 const lookup_name_info
&lookup_name
)
524 const language_defn
*lang
= language_def (psym
->ginfo
.language ());
525 symbol_name_matcher_ftype
*name_match
526 = lang
->get_symbol_name_matcher (lookup_name
);
527 return name_match (psym
->ginfo
.search_name (), lookup_name
, NULL
);
530 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
531 the global block of PST if GLOBAL, and otherwise the static block.
532 MATCH is the comparison operation that returns true iff MATCH (s,
533 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
534 non-null, the symbols in the block are assumed to be ordered
535 according to it (allowing binary search). It must be compatible
536 with MATCH. Returns the symbol, if found, and otherwise NULL. */
538 static struct partial_symbol
*
539 match_partial_symbol (struct objfile
*objfile
,
540 struct partial_symtab
*pst
, int global
,
541 const lookup_name_info
&name
, domain_enum domain
,
542 symbol_compare_ftype
*ordered_compare
)
544 struct partial_symbol
**start
, **psym
;
545 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
547 ? pst
->global_psymbols
.size ()
548 : pst
->static_psymbols
.size ());
549 int do_linear_search
= 1;
555 &pst
->global_psymbols
[0] :
556 &pst
->static_psymbols
[0]);
558 if (global
&& ordered_compare
) /* Can use a binary search. */
560 do_linear_search
= 0;
562 /* Binary search. This search is guaranteed to end with center
563 pointing at the earliest partial symbol whose name might be
564 correct. At that point *all* partial symbols with an
565 appropriate name will be checked against the correct
569 top
= start
+ length
- 1;
573 center
= bottom
+ (top
- bottom
) / 2;
574 gdb_assert (center
< top
);
576 enum language lang
= (*center
)->ginfo
.language ();
577 const char *lang_ln
= name
.language_lookup_name (lang
);
579 if (ordered_compare ((*center
)->ginfo
.search_name (),
585 gdb_assert (top
== bottom
);
587 while (top
<= real_top
588 && psymbol_name_matches (*top
, name
))
590 if (symbol_matches_domain ((*top
)->ginfo
.language (),
591 (*top
)->domain
, domain
))
597 /* Can't use a binary search or else we found during the binary search that
598 we should also do a linear search. */
600 if (do_linear_search
)
602 for (psym
= start
; psym
< start
+ length
; psym
++)
604 if (symbol_matches_domain ((*psym
)->ginfo
.language (),
605 (*psym
)->domain
, domain
)
606 && psymbol_name_matches (*psym
, name
))
614 /* Look, in partial_symtab PST, for symbol whose natural name is
615 LOOKUP_NAME. Check the global symbols if GLOBAL, the static
618 static struct partial_symbol
*
619 lookup_partial_symbol (struct objfile
*objfile
,
620 struct partial_symtab
*pst
,
621 const lookup_name_info
&lookup_name
,
622 int global
, domain_enum domain
)
624 struct partial_symbol
**start
, **psym
;
625 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
627 ? pst
->global_psymbols
.size ()
628 : pst
->static_psymbols
.size ());
629 int do_linear_search
= 1;
635 &pst
->global_psymbols
[0] :
636 &pst
->static_psymbols
[0]);
638 if (global
) /* This means we can use a binary search. */
640 do_linear_search
= 0;
642 /* Binary search. This search is guaranteed to end with center
643 pointing at the earliest partial symbol whose name might be
644 correct. At that point *all* partial symbols with an
645 appropriate name will be checked against the correct
649 top
= start
+ length
- 1;
653 center
= bottom
+ (top
- bottom
) / 2;
655 gdb_assert (center
< top
);
657 if (strcmp_iw_ordered ((*center
)->ginfo
.search_name (),
658 lookup_name
.c_str ()) >= 0)
668 gdb_assert (top
== bottom
);
670 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
671 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
672 while (top
>= start
&& symbol_matches_search_name (&(*top
)->ginfo
,
676 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
679 while (top
<= real_top
&& symbol_matches_search_name (&(*top
)->ginfo
,
682 if (symbol_matches_domain ((*top
)->ginfo
.language (),
683 (*top
)->domain
, domain
))
689 /* Can't use a binary search or else we found during the binary search that
690 we should also do a linear search. */
692 if (do_linear_search
)
694 for (psym
= start
; psym
< start
+ length
; psym
++)
696 if (symbol_matches_domain ((*psym
)->ginfo
.language (),
697 (*psym
)->domain
, domain
)
698 && symbol_matches_search_name (&(*psym
)->ginfo
, lookup_name
))
706 /* Get the symbol table that corresponds to a partial_symtab.
707 This is fast after the first time you do it.
708 The result will be NULL if the primary symtab has no symbols,
709 which can happen. Otherwise the result is the primary symtab
710 that contains PST. */
712 static struct compunit_symtab
*
713 psymtab_to_symtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
715 /* If it is a shared psymtab, find an unshared psymtab that includes
716 it. Any such psymtab will do. */
717 while (pst
->user
!= NULL
)
720 /* If it's been looked up before, return it. */
721 if (pst
->get_compunit_symtab (objfile
))
722 return pst
->get_compunit_symtab (objfile
);
724 /* If it has not yet been read in, read it. */
725 if (!pst
->readin_p (objfile
))
727 scoped_restore decrementer
= increment_reading_symtab ();
731 printf_filtered (_("Reading in symbols for %s...\n"),
733 gdb_flush (gdb_stdout
);
736 pst
->read_symtab (objfile
);
739 return pst
->get_compunit_symtab (objfile
);
742 /* Psymtab version of find_last_source_symtab. See its definition in
743 the definition of quick_symbol_functions in symfile.h. */
746 psymbol_functions::find_last_source_symtab (struct objfile
*ofp
)
748 struct partial_symtab
*cs_pst
= NULL
;
750 for (partial_symtab
*ps
: require_partial_symbols (ofp
))
752 const char *name
= ps
->filename
;
753 int len
= strlen (name
);
755 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
756 || strcmp (name
, "<<C++-namespaces>>") == 0)))
762 if (cs_pst
->readin_p (ofp
))
764 internal_error (__FILE__
, __LINE__
,
765 _("select_source_symtab: "
766 "readin pst found and no symtabs."));
770 struct compunit_symtab
*cust
= psymtab_to_symtab (ofp
, cs_pst
);
774 return compunit_primary_filetab (cust
);
780 /* Psymtab version of forget_cached_source_info. See its definition in
781 the definition of quick_symbol_functions in symfile.h. */
784 psymbol_functions::forget_cached_source_info (struct objfile
*objfile
)
786 for (partial_symtab
*pst
: require_partial_symbols (objfile
))
788 if (pst
->fullname
!= NULL
)
790 xfree (pst
->fullname
);
791 pst
->fullname
= NULL
;
797 print_partial_symbols (struct gdbarch
*gdbarch
, struct objfile
*objfile
,
798 const std::vector
<partial_symbol
*> &symbols
,
799 const char *what
, struct ui_file
*outfile
)
801 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
802 for (partial_symbol
*p
: symbols
)
805 fprintf_filtered (outfile
, " `%s'", p
->ginfo
.linkage_name ());
806 if (p
->ginfo
.demangled_name () != NULL
)
808 fprintf_filtered (outfile
, " `%s'",
809 p
->ginfo
.demangled_name ());
811 fputs_filtered (", ", outfile
);
815 fputs_filtered ("undefined domain, ", outfile
);
818 /* This is the usual thing -- don't print it. */
821 fputs_filtered ("struct domain, ", outfile
);
824 fputs_filtered ("module domain, ", outfile
);
827 fputs_filtered ("label domain, ", outfile
);
829 case COMMON_BLOCK_DOMAIN
:
830 fputs_filtered ("common block domain, ", outfile
);
833 fputs_filtered ("<invalid domain>, ", outfile
);
839 fputs_filtered ("undefined", outfile
);
842 fputs_filtered ("constant int", outfile
);
845 fputs_filtered ("static", outfile
);
848 fputs_filtered ("register", outfile
);
851 fputs_filtered ("pass by value", outfile
);
854 fputs_filtered ("pass by reference", outfile
);
856 case LOC_REGPARM_ADDR
:
857 fputs_filtered ("register address parameter", outfile
);
860 fputs_filtered ("stack parameter", outfile
);
863 fputs_filtered ("type", outfile
);
866 fputs_filtered ("label", outfile
);
869 fputs_filtered ("function", outfile
);
871 case LOC_CONST_BYTES
:
872 fputs_filtered ("constant bytes", outfile
);
875 fputs_filtered ("unresolved", outfile
);
877 case LOC_OPTIMIZED_OUT
:
878 fputs_filtered ("optimized out", outfile
);
881 fputs_filtered ("computed at runtime", outfile
);
884 fputs_filtered ("<invalid location>", outfile
);
887 fputs_filtered (", ", outfile
);
888 fputs_filtered (paddress (gdbarch
, p
->unrelocated_address ()), outfile
);
889 fprintf_filtered (outfile
, "\n");
894 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
895 struct ui_file
*outfile
)
897 struct gdbarch
*gdbarch
= objfile
->arch ();
900 if (psymtab
->anonymous
)
902 fprintf_filtered (outfile
, "\nAnonymous partial symtab (%s) ",
907 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
910 fprintf_filtered (outfile
, "(object ");
911 gdb_print_host_address (psymtab
, outfile
);
912 fprintf_filtered (outfile
, ")\n\n");
913 fprintf_filtered (outfile
, " Read from object file %s (",
914 objfile_name (objfile
));
915 gdb_print_host_address (objfile
, outfile
);
916 fprintf_filtered (outfile
, ")\n");
918 if (psymtab
->readin_p (objfile
))
920 fprintf_filtered (outfile
,
921 " Full symtab was read (at ");
922 gdb_print_host_address (psymtab
->get_compunit_symtab (objfile
), outfile
);
923 fprintf_filtered (outfile
, ")\n");
926 fprintf_filtered (outfile
, " Symbols cover text addresses ");
927 fputs_filtered (paddress (gdbarch
, psymtab
->text_low (objfile
)), outfile
);
928 fprintf_filtered (outfile
, "-");
929 fputs_filtered (paddress (gdbarch
, psymtab
->text_high (objfile
)), outfile
);
930 fprintf_filtered (outfile
, "\n");
931 fprintf_filtered (outfile
, " Address map supported - %s.\n",
932 psymtab
->psymtabs_addrmap_supported
? "yes" : "no");
933 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
934 psymtab
->number_of_dependencies
);
935 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
937 fprintf_filtered (outfile
, " %d ", i
);
938 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
939 fprintf_filtered (outfile
, " %s\n",
940 psymtab
->dependencies
[i
]->filename
);
942 if (psymtab
->user
!= NULL
)
944 fprintf_filtered (outfile
, " Shared partial symtab with user ");
945 gdb_print_host_address (psymtab
->user
, outfile
);
946 fprintf_filtered (outfile
, "\n");
948 if (!psymtab
->global_psymbols
.empty ())
950 print_partial_symbols
951 (gdbarch
, objfile
, psymtab
->global_psymbols
,
954 if (!psymtab
->static_psymbols
.empty ())
956 print_partial_symbols
957 (gdbarch
, objfile
, psymtab
->static_psymbols
,
960 fprintf_filtered (outfile
, "\n");
963 /* Count the number of partial symbols in OBJFILE. */
966 psymbol_functions::count_psyms ()
969 for (partial_symtab
*pst
: m_partial_symtabs
->range ())
971 count
+= pst
->global_psymbols
.size ();
972 count
+= pst
->static_psymbols
.size ();
977 /* Psymtab version of print_stats. See its definition in
978 the definition of quick_symbol_functions in symfile.h. */
981 psymbol_functions::print_stats (struct objfile
*objfile
, bool print_bcache
)
987 int n_psyms
= count_psyms ();
989 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
993 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
995 if (!ps
->readin_p (objfile
))
998 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"),
1000 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
1001 m_partial_symtabs
->psymbol_cache
.memory_used ());
1005 printf_filtered (_("Psymbol byte cache statistics:\n"));
1006 m_partial_symtabs
->psymbol_cache
.print_statistics
1007 ("partial symbol cache");
1011 /* Psymtab version of dump. See its definition in
1012 the definition of quick_symbol_functions in symfile.h. */
1015 psymbol_functions::dump (struct objfile
*objfile
)
1017 struct partial_symtab
*psymtab
;
1019 if (m_partial_symtabs
->psymtabs
)
1021 printf_filtered ("Psymtabs:\n");
1022 for (psymtab
= m_partial_symtabs
->psymtabs
;
1024 psymtab
= psymtab
->next
)
1026 printf_filtered ("%s at ",
1028 gdb_print_host_address (psymtab
, gdb_stdout
);
1029 printf_filtered (", ");
1032 printf_filtered ("\n\n");
1036 /* Psymtab version of expand_symtabs_for_function. See its definition in
1037 the definition of quick_symbol_functions in symfile.h. */
1040 psymbol_functions::expand_symtabs_for_function (struct objfile
*objfile
,
1041 const char *func_name
)
1043 lookup_name_info
base_lookup (func_name
, symbol_name_match_type::FULL
);
1044 lookup_name_info lookup_name
= base_lookup
.make_ignore_params ();
1046 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
1048 if (ps
->readin_p (objfile
))
1051 if ((lookup_partial_symbol (objfile
, ps
, lookup_name
, 1, VAR_DOMAIN
)
1053 || (lookup_partial_symbol (objfile
, ps
, lookup_name
, 0, VAR_DOMAIN
)
1055 psymtab_to_symtab (objfile
, ps
);
1059 /* Psymtab version of expand_all_symtabs. See its definition in
1060 the definition of quick_symbol_functions in symfile.h. */
1063 psymbol_functions::expand_all_symtabs (struct objfile
*objfile
)
1065 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
))
1066 psymtab_to_symtab (objfile
, psymtab
);
1069 /* Psymtab version of expand_symtabs_with_fullname. See its definition in
1070 the definition of quick_symbol_functions in symfile.h. */
1073 psymbol_functions::expand_symtabs_with_fullname (struct objfile
*objfile
,
1074 const char *fullname
)
1076 for (partial_symtab
*p
: require_partial_symbols (objfile
))
1078 /* Anonymous psymtabs don't have a name of a source file. */
1082 /* psymtab_to_fullname tries to open the file which is slow.
1083 Don't call it if we know the basenames don't match. */
1084 if ((basenames_may_differ
1085 || filename_cmp (lbasename (fullname
), lbasename (p
->filename
)) == 0)
1086 && filename_cmp (fullname
, psymtab_to_fullname (p
)) == 0)
1087 psymtab_to_symtab (objfile
, p
);
1091 /* Psymtab version of map_symbol_filenames. See its definition in
1092 the definition of quick_symbol_functions in symfile.h. */
1095 psymbol_functions::map_symbol_filenames (struct objfile
*objfile
,
1096 symbol_filename_ftype
*fun
,
1100 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
1102 const char *fullname
;
1104 if (ps
->readin_p (objfile
))
1107 /* We can skip shared psymtabs here, because any file name will be
1108 attached to the unshared psymtab. */
1109 if (ps
->user
!= NULL
)
1112 /* Anonymous psymtabs don't have a file name. */
1118 fullname
= psymtab_to_fullname (ps
);
1121 (*fun
) (ps
->filename
, fullname
, data
);
1125 /* Finds the fullname that a partial_symtab represents.
1127 If this functions finds the fullname, it will save it in ps->fullname
1128 and it will also return the value.
1130 If this function fails to find the file that this partial_symtab represents,
1131 NULL will be returned and ps->fullname will be set to NULL. */
1134 psymtab_to_fullname (struct partial_symtab
*ps
)
1136 gdb_assert (!ps
->anonymous
);
1138 /* Use cached copy if we have it.
1139 We rely on forget_cached_source_info being called appropriately
1140 to handle cases like the file being moved. */
1141 if (ps
->fullname
== NULL
)
1143 gdb::unique_xmalloc_ptr
<char> fullname
;
1144 scoped_fd fd
= find_and_open_source (ps
->filename
, ps
->dirname
,
1146 ps
->fullname
= fullname
.release ();
1150 /* rewrite_source_path would be applied by find_and_open_source, we
1151 should report the pathname where GDB tried to find the file. */
1153 if (ps
->dirname
== NULL
|| IS_ABSOLUTE_PATH (ps
->filename
))
1154 fullname
.reset (xstrdup (ps
->filename
));
1156 fullname
.reset (concat (ps
->dirname
, SLASH_STRING
,
1157 ps
->filename
, (char *) NULL
));
1159 ps
->fullname
= rewrite_source_path (fullname
.get ()).release ();
1160 if (ps
->fullname
== NULL
)
1161 ps
->fullname
= fullname
.release ();
1165 return ps
->fullname
;
1168 /* Psymtab version of map_matching_symbols. See its definition in
1169 the definition of quick_symbol_functions in symfile.h. */
1172 psymbol_functions::map_matching_symbols
1173 (struct objfile
*objfile
,
1174 const lookup_name_info
&name
, domain_enum domain
,
1176 gdb::function_view
<symbol_found_callback_ftype
> callback
,
1177 symbol_compare_ftype
*ordered_compare
)
1179 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
1181 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
1184 if (ps
->readin_p (objfile
)
1185 || match_partial_symbol (objfile
, ps
, global
, name
, domain
,
1188 struct compunit_symtab
*cust
= psymtab_to_symtab (objfile
, ps
);
1189 const struct block
*block
;
1193 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
1194 if (!iterate_over_symbols_terminated (block
, name
,
1201 /* A helper for psym_expand_symtabs_matching that handles searching
1202 included psymtabs. This returns true if a symbol is found, and
1203 false otherwise. It also updates the 'searched_flag' on the
1204 various psymtabs that it searches. */
1207 recursively_search_psymtabs
1208 (struct partial_symtab
*ps
,
1209 struct objfile
*objfile
,
1210 enum search_domain domain
,
1211 const lookup_name_info
&lookup_name
,
1212 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> sym_matcher
)
1215 enum psymtab_search_status result
= PST_SEARCHED_AND_NOT_FOUND
;
1218 if (ps
->searched_flag
!= PST_NOT_SEARCHED
)
1219 return ps
->searched_flag
== PST_SEARCHED_AND_FOUND
;
1221 /* Recurse into shared psymtabs first, because they may have already
1222 been searched, and this could save some time. */
1223 for (i
= 0; i
< ps
->number_of_dependencies
; ++i
)
1227 /* Skip non-shared dependencies, these are handled elsewhere. */
1228 if (ps
->dependencies
[i
]->user
== NULL
)
1231 r
= recursively_search_psymtabs (ps
->dependencies
[i
],
1232 objfile
, domain
, lookup_name
,
1236 ps
->searched_flag
= PST_SEARCHED_AND_FOUND
;
1241 partial_symbol
**gbound
= (ps
->global_psymbols
.data ()
1242 + ps
->global_psymbols
.size ());
1243 partial_symbol
**sbound
= (ps
->static_psymbols
.data ()
1244 + ps
->static_psymbols
.size ());
1245 partial_symbol
**bound
= gbound
;
1247 /* Go through all of the symbols stored in a partial
1248 symtab in one loop. */
1249 partial_symbol
**psym
= ps
->global_psymbols
.data ();
1254 if (bound
== gbound
&& !ps
->static_psymbols
.empty ())
1256 psym
= ps
->static_psymbols
.data ();
1267 if ((domain
== ALL_DOMAIN
1268 || (domain
== MODULES_DOMAIN
1269 && (*psym
)->domain
== MODULE_DOMAIN
)
1270 || (domain
== VARIABLES_DOMAIN
1271 && (*psym
)->aclass
!= LOC_TYPEDEF
1272 && (*psym
)->aclass
!= LOC_BLOCK
)
1273 || (domain
== FUNCTIONS_DOMAIN
1274 && (*psym
)->aclass
== LOC_BLOCK
)
1275 || (domain
== TYPES_DOMAIN
1276 && (*psym
)->aclass
== LOC_TYPEDEF
))
1277 && psymbol_name_matches (*psym
, lookup_name
)
1278 && (sym_matcher
== NULL
1279 || sym_matcher ((*psym
)->ginfo
.search_name ())))
1281 /* Found a match, so notify our caller. */
1282 result
= PST_SEARCHED_AND_FOUND
;
1289 ps
->searched_flag
= result
;
1290 return result
== PST_SEARCHED_AND_FOUND
;
1293 /* Psymtab version of expand_symtabs_matching. See its definition in
1294 the definition of quick_symbol_functions in symfile.h. */
1297 psymbol_functions::expand_symtabs_matching
1298 (struct objfile
*objfile
,
1299 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
1300 const lookup_name_info
*lookup_name
,
1301 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
1302 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
1303 enum search_domain domain
)
1305 /* Clear the search flags. */
1306 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
1307 ps
->searched_flag
= PST_NOT_SEARCHED
;
1309 for (partial_symtab
*ps
: m_partial_symtabs
->range ())
1313 if (ps
->readin_p (objfile
))
1316 /* We skip shared psymtabs because file-matching doesn't apply
1317 to them; but we search them later in the loop. */
1318 if (ps
->user
!= NULL
)
1328 match
= file_matcher (ps
->filename
, false);
1331 /* Before we invoke realpath, which can get expensive when many
1332 files are involved, do a quick comparison of the basenames. */
1333 if (basenames_may_differ
1334 || file_matcher (lbasename (ps
->filename
), true))
1335 match
= file_matcher (psymtab_to_fullname (ps
), false);
1341 if ((symbol_matcher
== NULL
&& lookup_name
== NULL
)
1342 || recursively_search_psymtabs (ps
, objfile
, domain
,
1343 lookup_name
->make_ignore_params (),
1346 struct compunit_symtab
*symtab
=
1347 psymtab_to_symtab (objfile
, ps
);
1349 if (expansion_notify
!= NULL
)
1350 expansion_notify (symtab
);
1355 /* Psymtab version of has_symbols. See its definition in
1356 the definition of quick_symbol_functions in symfile.h. */
1359 psymbol_functions::has_symbols (struct objfile
*objfile
)
1361 return m_partial_symtabs
->psymtabs
!= NULL
;
1364 /* Helper function for psym_find_compunit_symtab_by_address that fills
1365 in m_psymbol_map for a given range of psymbols. */
1368 psymbol_functions::fill_psymbol_map
1369 (struct objfile
*objfile
,
1370 struct partial_symtab
*psymtab
,
1371 std::set
<CORE_ADDR
> *seen_addrs
,
1372 const std::vector
<partial_symbol
*> &symbols
)
1374 for (partial_symbol
*psym
: symbols
)
1376 if (psym
->aclass
== LOC_STATIC
)
1378 CORE_ADDR addr
= psym
->address (objfile
);
1379 if (seen_addrs
->find (addr
) == seen_addrs
->end ())
1381 seen_addrs
->insert (addr
);
1382 m_psymbol_map
.emplace_back (addr
, psymtab
);
1388 /* See find_compunit_symtab_by_address in quick_symbol_functions, in
1392 psymbol_functions::find_compunit_symtab_by_address (struct objfile
*objfile
,
1395 if (m_psymbol_map
.empty ())
1397 std::set
<CORE_ADDR
> seen_addrs
;
1399 for (partial_symtab
*pst
: require_partial_symbols (objfile
))
1401 fill_psymbol_map (objfile
, pst
,
1403 pst
->global_psymbols
);
1404 fill_psymbol_map (objfile
, pst
,
1406 pst
->static_psymbols
);
1409 m_psymbol_map
.shrink_to_fit ();
1411 std::sort (m_psymbol_map
.begin (), m_psymbol_map
.end (),
1412 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1413 const std::pair
<CORE_ADDR
, partial_symtab
*> &b
)
1415 return a
.first
< b
.first
;
1419 auto iter
= std::lower_bound
1420 (m_psymbol_map
.begin (), m_psymbol_map
.end (), address
,
1421 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1427 if (iter
== m_psymbol_map
.end () || iter
->first
!= address
)
1430 return psymtab_to_symtab (objfile
, iter
->second
);
1433 quick_symbol_functions_up
1434 make_psymbol_functions (const std::shared_ptr
<psymtab_storage
> &storage
)
1436 return quick_symbol_functions_up (new psymbol_functions (storage
));
1441 /* Partially fill a partial symtab. It will be completely filled at
1442 the end of the symbol list. */
1444 partial_symtab::partial_symtab (const char *filename
,
1445 psymtab_storage
*partial_symtabs
,
1446 struct objfile
*objfile
,
1448 : partial_symtab (filename
, partial_symtabs
, objfile
)
1450 set_text_low (textlow
);
1451 set_text_high (raw_text_low ()); /* default */
1454 /* Perform "finishing up" operations of a partial symtab. */
1457 partial_symtab::end ()
1459 global_psymbols
.shrink_to_fit ();
1460 static_psymbols
.shrink_to_fit ();
1462 /* Sort the global list; don't sort the static list. */
1463 std::sort (global_psymbols
.begin (),
1464 global_psymbols
.end (),
1465 [] (partial_symbol
*s1
, partial_symbol
*s2
)
1467 return strcmp_iw_ordered (s1
->ginfo
.search_name (),
1468 s2
->ginfo
.search_name ()) < 0;
1472 /* See psymtab.h. */
1475 psymbol_bcache::hash (const void *addr
, int length
)
1477 unsigned long h
= 0;
1478 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1479 unsigned int lang
= psymbol
->ginfo
.language ();
1480 unsigned int domain
= psymbol
->domain
;
1481 unsigned int theclass
= psymbol
->aclass
;
1483 h
= fast_hash (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1484 h
= fast_hash (&lang
, sizeof (unsigned int), h
);
1485 h
= fast_hash (&domain
, sizeof (unsigned int), h
);
1486 h
= fast_hash (&theclass
, sizeof (unsigned int), h
);
1487 /* Note that psymbol names are interned via compute_and_set_names, so
1488 there's no need to hash the contents of the name here. */
1489 h
= fast_hash (&psymbol
->ginfo
.m_name
, sizeof (psymbol
->ginfo
.m_name
), h
);
1494 /* See psymtab.h. */
1497 psymbol_bcache::compare (const void *addr1
, const void *addr2
, int length
)
1499 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1500 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1502 return (memcmp (&sym1
->ginfo
.value
, &sym2
->ginfo
.value
,
1503 sizeof (sym1
->ginfo
.value
)) == 0
1504 && sym1
->ginfo
.language () == sym2
->ginfo
.language ()
1505 && sym1
->domain
== sym2
->domain
1506 && sym1
->aclass
== sym2
->aclass
1507 /* Note that psymbol names are interned via
1508 compute_and_set_names, so there's no need to compare the
1509 contents of the name here. */
1510 && sym1
->ginfo
.linkage_name () == sym2
->ginfo
.linkage_name ());
1513 /* See psympriv.h. */
1516 partial_symtab::add_psymbol (const partial_symbol
&psymbol
,
1517 psymbol_placement where
,
1518 psymtab_storage
*partial_symtabs
,
1519 struct objfile
*objfile
)
1523 /* Stash the partial symbol away in the cache. */
1524 partial_symbol
*psym
1525 = ((struct partial_symbol
*)
1526 partial_symtabs
->psymbol_cache
.insert
1527 (&psymbol
, sizeof (struct partial_symbol
), &added
));
1529 /* Do not duplicate global partial symbols. */
1530 if (where
== psymbol_placement::GLOBAL
&& !added
)
1533 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1534 std::vector
<partial_symbol
*> &list
1535 = (where
== psymbol_placement::STATIC
1538 list
.push_back (psym
);
1541 /* See psympriv.h. */
1544 partial_symtab::add_psymbol (gdb::string_view name
, bool copy_name
,
1546 enum address_class theclass
,
1548 psymbol_placement where
,
1550 enum language language
,
1551 psymtab_storage
*partial_symtabs
,
1552 struct objfile
*objfile
)
1554 struct partial_symbol psymbol
;
1555 memset (&psymbol
, 0, sizeof (psymbol
));
1557 psymbol
.set_unrelocated_address (coreaddr
);
1558 psymbol
.ginfo
.set_section_index (section
);
1559 psymbol
.domain
= domain
;
1560 psymbol
.aclass
= theclass
;
1561 psymbol
.ginfo
.set_language (language
, partial_symtabs
->obstack ());
1562 psymbol
.ginfo
.compute_and_set_names (name
, copy_name
, objfile
->per_bfd
);
1564 add_psymbol (psymbol
, where
, partial_symtabs
, objfile
);
1567 /* See psympriv.h. */
1569 partial_symtab::partial_symtab (const char *filename_
,
1570 psymtab_storage
*partial_symtabs
,
1571 struct objfile
*objfile
)
1572 : searched_flag (PST_NOT_SEARCHED
),
1576 partial_symtabs
->install_psymtab (this);
1578 filename
= objfile
->intern (filename_
);
1580 if (symtab_create_debug
)
1582 /* Be a bit clever with debugging messages, and don't print objfile
1583 every time, only when it changes. */
1584 static char *last_objfile_name
= NULL
;
1586 if (last_objfile_name
== NULL
1587 || strcmp (last_objfile_name
, objfile_name (objfile
)) != 0)
1589 xfree (last_objfile_name
);
1590 last_objfile_name
= xstrdup (objfile_name (objfile
));
1591 fprintf_filtered (gdb_stdlog
,
1592 "Creating one or more psymtabs for objfile %s ...\n",
1595 fprintf_filtered (gdb_stdlog
,
1596 "Created psymtab %s for module %s.\n",
1597 host_address_to_string (this), filename
);
1601 /* See psympriv.h. */
1604 partial_symtab::expand_dependencies (struct objfile
*objfile
)
1606 for (int i
= 0; i
< number_of_dependencies
; ++i
)
1608 if (!dependencies
[i
]->readin_p (objfile
)
1609 && dependencies
[i
]->user
== NULL
)
1611 /* Inform about additional files to be read in. */
1614 fputs_filtered (" ", gdb_stdout
);
1616 fputs_filtered ("and ", gdb_stdout
);
1618 printf_filtered ("%s...", dependencies
[i
]->filename
);
1619 wrap_here (""); /* Flush output */
1620 gdb_flush (gdb_stdout
);
1622 dependencies
[i
]->expand_psymtab (objfile
);
1629 psymtab_storage::discard_psymtab (struct partial_symtab
*pst
)
1631 struct partial_symtab
**prev_pst
;
1634 Empty psymtabs happen as a result of header files which don't
1635 have any symbols in them. There can be a lot of them. But this
1636 check is wrong, in that a psymtab with N_SLINE entries but
1637 nothing else is not empty, but we don't realize that. Fixing
1638 that without slowing things down might be tricky. */
1640 /* First, snip it out of the psymtab chain. */
1642 prev_pst
= &psymtabs
;
1643 while ((*prev_pst
) != pst
)
1644 prev_pst
= &((*prev_pst
)->next
);
1645 (*prev_pst
) = pst
->next
;
1651 /* We need to pass a couple of items to the addrmap_foreach function,
1654 struct dump_psymtab_addrmap_data
1656 struct objfile
*objfile
;
1657 struct partial_symtab
*psymtab
;
1658 struct ui_file
*outfile
;
1660 /* Non-zero if the previously printed addrmap entry was for PSYMTAB.
1661 If so, we want to print the next one as well (since the next addrmap
1662 entry defines the end of the range). */
1663 int previous_matched
;
1666 /* Helper function for dump_psymtab_addrmap to print an addrmap entry. */
1669 dump_psymtab_addrmap_1 (void *datap
, CORE_ADDR start_addr
, void *obj
)
1671 struct dump_psymtab_addrmap_data
*data
1672 = (struct dump_psymtab_addrmap_data
*) datap
;
1673 struct gdbarch
*gdbarch
= data
->objfile
->arch ();
1674 struct partial_symtab
*addrmap_psymtab
= (struct partial_symtab
*) obj
;
1675 const char *psymtab_address_or_end
= NULL
;
1679 if (data
->psymtab
== NULL
1680 || data
->psymtab
== addrmap_psymtab
)
1681 psymtab_address_or_end
= host_address_to_string (addrmap_psymtab
);
1682 else if (data
->previous_matched
)
1683 psymtab_address_or_end
= "<ends here>";
1685 if (data
->psymtab
== NULL
1686 || data
->psymtab
== addrmap_psymtab
1687 || data
->previous_matched
)
1689 fprintf_filtered (data
->outfile
, " %s%s %s\n",
1690 data
->psymtab
!= NULL
? " " : "",
1691 paddress (gdbarch
, start_addr
),
1692 psymtab_address_or_end
);
1695 data
->previous_matched
= (data
->psymtab
== NULL
1696 || data
->psymtab
== addrmap_psymtab
);
1701 /* Helper function for maintenance_print_psymbols to print the addrmap
1702 of PSYMTAB. If PSYMTAB is NULL print the entire addrmap. */
1705 dump_psymtab_addrmap (struct objfile
*objfile
,
1706 psymtab_storage
*partial_symtabs
,
1707 struct partial_symtab
*psymtab
,
1708 struct ui_file
*outfile
)
1710 struct dump_psymtab_addrmap_data addrmap_dump_data
;
1712 if ((psymtab
== NULL
1713 || psymtab
->psymtabs_addrmap_supported
)
1714 && partial_symtabs
->psymtabs_addrmap
!= NULL
)
1716 addrmap_dump_data
.objfile
= objfile
;
1717 addrmap_dump_data
.psymtab
= psymtab
;
1718 addrmap_dump_data
.outfile
= outfile
;
1719 addrmap_dump_data
.previous_matched
= 0;
1720 fprintf_filtered (outfile
, "%sddress map:\n",
1721 psymtab
== NULL
? "Entire a" : " A");
1722 addrmap_foreach (partial_symtabs
->psymtabs_addrmap
,
1723 dump_psymtab_addrmap_1
, &addrmap_dump_data
);
1728 maintenance_print_psymbols (const char *args
, int from_tty
)
1730 struct ui_file
*outfile
= gdb_stdout
;
1731 char *address_arg
= NULL
, *source_arg
= NULL
, *objfile_arg
= NULL
;
1732 int i
, outfile_idx
, found
;
1734 struct obj_section
*section
= NULL
;
1738 gdb_argv
argv (args
);
1740 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
1742 if (strcmp (argv
[i
], "-pc") == 0)
1744 if (argv
[i
+ 1] == NULL
)
1745 error (_("Missing pc value"));
1746 address_arg
= argv
[++i
];
1748 else if (strcmp (argv
[i
], "-source") == 0)
1750 if (argv
[i
+ 1] == NULL
)
1751 error (_("Missing source file"));
1752 source_arg
= argv
[++i
];
1754 else if (strcmp (argv
[i
], "-objfile") == 0)
1756 if (argv
[i
+ 1] == NULL
)
1757 error (_("Missing objfile name"));
1758 objfile_arg
= argv
[++i
];
1760 else if (strcmp (argv
[i
], "--") == 0)
1762 /* End of options. */
1766 else if (argv
[i
][0] == '-')
1768 /* Future proofing: Don't allow OUTFILE to begin with "-". */
1769 error (_("Unknown option: %s"), argv
[i
]);
1776 if (address_arg
!= NULL
&& source_arg
!= NULL
)
1777 error (_("Must specify at most one of -pc and -source"));
1779 stdio_file arg_outfile
;
1781 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
1783 if (argv
[outfile_idx
+ 1] != NULL
)
1784 error (_("Junk at end of command"));
1785 gdb::unique_xmalloc_ptr
<char> outfile_name
1786 (tilde_expand (argv
[outfile_idx
]));
1787 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
1788 perror_with_name (outfile_name
.get ());
1789 outfile
= &arg_outfile
;
1792 if (address_arg
!= NULL
)
1794 pc
= parse_and_eval_address (address_arg
);
1795 /* If we fail to find a section, that's ok, try the lookup anyway. */
1796 section
= find_pc_section (pc
);
1800 for (objfile
*objfile
: current_program_space
->objfiles ())
1802 int printed_objfile_header
= 0;
1803 int print_for_objfile
= 1;
1806 if (objfile_arg
!= NULL
)
1808 = compare_filenames_for_search (objfile_name (objfile
),
1810 if (!print_for_objfile
)
1813 psymbol_functions
*psf
1814 = dynamic_cast<psymbol_functions
*> (objfile
->qf
.get ());
1818 psymtab_storage
*partial_symtabs
= psf
->get_partial_symtabs ().get ();
1820 if (address_arg
!= NULL
)
1822 struct bound_minimal_symbol msymbol
= { NULL
, NULL
};
1824 /* We don't assume each pc has a unique objfile (this is for
1826 struct partial_symtab
*ps
1827 = psf
->find_pc_sect_psymtab (objfile
, pc
, section
, msymbol
);
1830 if (!printed_objfile_header
)
1832 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1833 objfile_name (objfile
));
1834 printed_objfile_header
= 1;
1836 dump_psymtab (objfile
, ps
, outfile
);
1837 dump_psymtab_addrmap (objfile
, partial_symtabs
, ps
, outfile
);
1843 for (partial_symtab
*ps
: psf
->require_partial_symbols (objfile
))
1845 int print_for_source
= 0;
1848 if (source_arg
!= NULL
)
1851 = compare_filenames_for_search (ps
->filename
, source_arg
);
1854 if (source_arg
== NULL
1855 || print_for_source
)
1857 if (!printed_objfile_header
)
1859 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1860 objfile_name (objfile
));
1861 printed_objfile_header
= 1;
1863 dump_psymtab (objfile
, ps
, outfile
);
1864 dump_psymtab_addrmap (objfile
, partial_symtabs
, ps
,
1870 /* If we're printing all the objfile's symbols dump the full addrmap. */
1872 if (address_arg
== NULL
1873 && source_arg
== NULL
1874 && partial_symtabs
->psymtabs_addrmap
!= NULL
)
1876 outfile
->puts ("\n");
1877 dump_psymtab_addrmap (objfile
, partial_symtabs
, NULL
, outfile
);
1883 if (address_arg
!= NULL
)
1884 error (_("No partial symtab for address: %s"), address_arg
);
1885 if (source_arg
!= NULL
)
1886 error (_("No partial symtab for source file: %s"), source_arg
);
1890 /* List all the partial symbol tables whose names match REGEXP (optional). */
1893 maintenance_info_psymtabs (const char *regexp
, int from_tty
)
1898 for (struct program_space
*pspace
: program_spaces
)
1899 for (objfile
*objfile
: pspace
->objfiles ())
1901 struct gdbarch
*gdbarch
= objfile
->arch ();
1903 /* We don't want to print anything for this objfile until we
1904 actually find a symtab whose name matches. */
1905 int printed_objfile_start
= 0;
1907 psymbol_functions
*psf
1908 = dynamic_cast<psymbol_functions
*> (objfile
->qf
.get ());
1911 for (partial_symtab
*psymtab
: psf
->require_partial_symbols (objfile
))
1916 || re_exec (psymtab
->filename
))
1918 if (! printed_objfile_start
)
1920 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
1922 printf_filtered ("((struct objfile *) %s)\n",
1923 host_address_to_string (objfile
));
1924 printed_objfile_start
= 1;
1927 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1929 printf_filtered ("((struct partial_symtab *) %s)\n",
1930 host_address_to_string (psymtab
));
1932 printf_filtered (" readin %s\n",
1933 psymtab
->readin_p (objfile
) ? "yes" : "no");
1934 printf_filtered (" fullname %s\n",
1936 ? psymtab
->fullname
: "(null)");
1937 printf_filtered (" text addresses ");
1938 fputs_filtered (paddress (gdbarch
,
1939 psymtab
->text_low (objfile
)),
1941 printf_filtered (" -- ");
1942 fputs_filtered (paddress (gdbarch
,
1943 psymtab
->text_high (objfile
)),
1945 printf_filtered ("\n");
1946 printf_filtered (" psymtabs_addrmap_supported %s\n",
1947 (psymtab
->psymtabs_addrmap_supported
1949 printf_filtered (" globals ");
1950 if (!psymtab
->global_psymbols
.empty ())
1952 ("(* (struct partial_symbol **) %s @ %d)\n",
1953 host_address_to_string (psymtab
->global_psymbols
.data ()),
1954 (int) psymtab
->global_psymbols
.size ());
1956 printf_filtered ("(none)\n");
1957 printf_filtered (" statics ");
1958 if (!psymtab
->static_psymbols
.empty ())
1960 ("(* (struct partial_symbol **) %s @ %d)\n",
1961 host_address_to_string (psymtab
->static_psymbols
.data ()),
1962 (int) psymtab
->static_psymbols
.size ());
1964 printf_filtered ("(none)\n");
1966 printf_filtered (" user %s "
1967 "((struct partial_symtab *) %s)\n",
1968 psymtab
->user
->filename
,
1969 host_address_to_string (psymtab
->user
));
1970 printf_filtered (" dependencies ");
1971 if (psymtab
->number_of_dependencies
)
1975 printf_filtered ("{\n");
1976 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1978 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
1980 /* Note the string concatenation there --- no
1982 printf_filtered (" psymtab %s "
1983 "((struct partial_symtab *) %s)\n",
1985 host_address_to_string (dep
));
1987 printf_filtered (" }\n");
1990 printf_filtered ("(none)\n");
1991 printf_filtered (" }\n");
1995 if (printed_objfile_start
)
1996 printf_filtered ("}\n");
2000 /* Check consistency of currently expanded psymtabs vs symtabs. */
2003 maintenance_check_psymtabs (const char *ignore
, int from_tty
)
2006 struct compunit_symtab
*cust
= NULL
;
2007 const struct blockvector
*bv
;
2008 const struct block
*b
;
2010 for (objfile
*objfile
: current_program_space
->objfiles ())
2012 psymbol_functions
*psf
2013 = dynamic_cast<psymbol_functions
*> (objfile
->qf
.get ());
2017 for (partial_symtab
*ps
: psf
->require_partial_symbols (objfile
))
2019 struct gdbarch
*gdbarch
= objfile
->arch ();
2021 /* We don't call psymtab_to_symtab here because that may cause symtab
2022 expansion. When debugging a problem it helps if checkers leave
2023 things unchanged. */
2024 cust
= ps
->get_compunit_symtab (objfile
);
2026 /* First do some checks that don't require the associated symtab. */
2027 if (ps
->text_high (objfile
) < ps
->text_low (objfile
))
2029 printf_filtered ("Psymtab ");
2030 puts_filtered (ps
->filename
);
2031 printf_filtered (" covers bad range ");
2032 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
2034 printf_filtered (" - ");
2035 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
2037 printf_filtered ("\n");
2041 /* Now do checks requiring the associated symtab. */
2044 bv
= COMPUNIT_BLOCKVECTOR (cust
);
2045 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
2046 for (partial_symbol
*psym
: ps
->static_psymbols
)
2048 /* Skip symbols for inlined functions without address. These may
2049 or may not have a match in the full symtab. */
2050 if (psym
->aclass
== LOC_BLOCK
2051 && psym
->ginfo
.value
.address
== 0)
2054 sym
= block_lookup_symbol (b
, psym
->ginfo
.search_name (),
2055 symbol_name_match_type::SEARCH_NAME
,
2059 printf_filtered ("Static symbol `");
2060 puts_filtered (psym
->ginfo
.linkage_name ());
2061 printf_filtered ("' only found in ");
2062 puts_filtered (ps
->filename
);
2063 printf_filtered (" psymtab\n");
2066 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2067 for (partial_symbol
*psym
: ps
->global_psymbols
)
2069 sym
= block_lookup_symbol (b
, psym
->ginfo
.search_name (),
2070 symbol_name_match_type::SEARCH_NAME
,
2074 printf_filtered ("Global symbol `");
2075 puts_filtered (psym
->ginfo
.linkage_name ());
2076 printf_filtered ("' only found in ");
2077 puts_filtered (ps
->filename
);
2078 printf_filtered (" psymtab\n");
2081 if (ps
->raw_text_high () != 0
2082 && (ps
->text_low (objfile
) < BLOCK_START (b
)
2083 || ps
->text_high (objfile
) > BLOCK_END (b
)))
2085 printf_filtered ("Psymtab ");
2086 puts_filtered (ps
->filename
);
2087 printf_filtered (" covers ");
2088 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
2090 printf_filtered (" - ");
2091 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
2093 printf_filtered (" but symtab covers only ");
2094 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
2095 printf_filtered (" - ");
2096 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
2097 printf_filtered ("\n");
2103 void _initialize_psymtab ();
2105 _initialize_psymtab ()
2107 add_cmd ("psymbols", class_maintenance
, maintenance_print_psymbols
, _("\
2108 Print dump of current partial symbol definitions.\n\
2109 Usage: mt print psymbols [-objfile OBJFILE] [-pc ADDRESS] [--] [OUTFILE]\n\
2110 mt print psymbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
2111 Entries in the partial symbol table are dumped to file OUTFILE,\n\
2112 or the terminal if OUTFILE is unspecified.\n\
2113 If ADDRESS is provided, dump only the file for that address.\n\
2114 If SOURCE is provided, dump only that file's symbols.\n\
2115 If OBJFILE is provided, dump only that file's minimal symbols."),
2116 &maintenanceprintlist
);
2118 add_cmd ("psymtabs", class_maintenance
, maintenance_info_psymtabs
, _("\
2119 List the partial symbol tables for all object files.\n\
2120 This does not include information about individual partial symbols,\n\
2121 just the symbol table structures themselves."),
2122 &maintenanceinfolist
);
2124 add_cmd ("check-psymtabs", class_maintenance
, maintenance_check_psymtabs
,
2126 Check consistency of currently expanded psymtabs versus symtabs."),