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 static psymtab_storage::partial_symtab_range
84 require_partial_symbols (struct objfile
*objfile
)
86 objfile
->require_partial_symbols (true);
87 return objfile
->psymtabs ();
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 /* Find which partial symtab contains PC and SECTION. Return NULL if
259 none. We return the psymtab that contains a symbol whose address
260 exactly matches PC, or, if we cannot find an exact match, the
261 psymtab that contains a symbol whose address is closest to PC. */
263 static struct partial_symtab
*
264 find_pc_sect_psymtab (struct objfile
*objfile
,
265 psymtab_storage
*partial_symtabs
,
267 struct obj_section
*section
,
268 struct bound_minimal_symbol msymbol
)
270 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better
271 granularity than the later used TEXTLOW/TEXTHIGH one. However, we need
272 to take care as the PSYMTABS_ADDRMAP can hold things other than partial
273 symtabs in some cases.
275 This function should only be called for objfiles that are using partial
276 symtabs, not for objfiles that are using indexes (.gdb_index or
277 .debug_names), however 'maintenance print psymbols' calls this function
278 directly for all objfiles. If we assume that PSYMTABS_ADDRMAP contains
279 partial symtabs then we will end up returning a pointer to an object
280 that is not a partial_symtab, which doesn't end well. */
282 if (partial_symtabs
->psymtabs
!= NULL
283 && partial_symtabs
->psymtabs_addrmap
!= NULL
)
285 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
287 struct partial_symtab
*pst
288 = ((struct partial_symtab
*)
289 addrmap_find (partial_symtabs
->psymtabs_addrmap
,
293 /* FIXME: addrmaps currently do not handle overlayed sections,
294 so fall back to the non-addrmap case if we're debugging
295 overlays and the addrmap returned the wrong section. */
296 if (overlay_debugging
&& msymbol
.minsym
!= NULL
&& section
!= NULL
)
298 struct partial_symbol
*p
;
300 /* NOTE: This assumes that every psymbol has a
301 corresponding msymbol, which is not necessarily
302 true; the debug info might be much richer than the
303 object's symbol table. */
304 p
= find_pc_sect_psymbol (objfile
, pst
, pc
, section
);
306 || (p
->address (objfile
)
307 != BMSYMBOL_VALUE_ADDRESS (msymbol
)))
311 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
312 PSYMTABS_ADDRMAP we used has already the best 1-byte
313 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
314 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
323 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
324 which still have no corresponding full SYMTABs read. But it is not
325 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
328 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
329 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
330 debug info type in single OBJFILE. */
332 for (partial_symtab
*pst
: require_partial_symbols (objfile
))
333 if (!pst
->psymtabs_addrmap_supported
334 && pc
>= pst
->text_low (objfile
) && pc
< pst
->text_high (objfile
))
336 struct partial_symtab
*best_pst
;
338 best_pst
= find_pc_sect_psymtab_closer (objfile
, pc
, section
, pst
,
340 if (best_pst
!= NULL
)
347 /* Psymtab version of find_pc_sect_compunit_symtab. See its definition in
348 the definition of quick_symbol_functions in symfile.h. */
350 struct compunit_symtab
*
351 psymbol_functions::find_pc_sect_compunit_symtab
352 (struct objfile
*objfile
,
353 struct bound_minimal_symbol msymbol
,
355 struct obj_section
*section
,
358 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
,
359 m_partial_symtabs
.get (),
364 if (warn_if_readin
&& ps
->readin_p (objfile
))
365 /* Might want to error() here (in case symtab is corrupt and
366 will cause a core dump), but maybe we can successfully
367 continue, so let's not. */
369 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
370 paddress (objfile
->arch (), pc
));
371 psymtab_to_symtab (objfile
, ps
);
372 return ps
->get_compunit_symtab (objfile
);
377 /* Find which partial symbol within a psymtab matches PC and SECTION.
378 Return NULL if none. */
380 static struct partial_symbol
*
381 find_pc_sect_psymbol (struct objfile
*objfile
,
382 struct partial_symtab
*psymtab
, CORE_ADDR pc
,
383 struct obj_section
*section
)
385 struct partial_symbol
*best
= NULL
;
387 const CORE_ADDR textlow
= psymtab
->text_low (objfile
);
389 gdb_assert (psymtab
!= NULL
);
391 /* Cope with programs that start at address 0. */
392 best_pc
= (textlow
!= 0) ? textlow
- 1 : 0;
394 /* Search the global symbols as well as the static symbols, so that
395 find_pc_partial_function doesn't use a minimal symbol and thus
396 cache a bad endaddr. */
397 for (partial_symbol
*p
: psymtab
->global_psymbols
)
399 if (p
->domain
== VAR_DOMAIN
400 && p
->aclass
== LOC_BLOCK
401 && pc
>= p
->address (objfile
)
402 && (p
->address (objfile
) > best_pc
403 || (psymtab
->text_low (objfile
) == 0
404 && best_pc
== 0 && p
->address (objfile
) == 0)))
406 if (section
!= NULL
) /* Match on a specific section. */
408 if (!matching_obj_sections (p
->obj_section (objfile
),
412 best_pc
= p
->address (objfile
);
417 for (partial_symbol
*p
: psymtab
->static_psymbols
)
419 if (p
->domain
== VAR_DOMAIN
420 && p
->aclass
== LOC_BLOCK
421 && pc
>= p
->address (objfile
)
422 && (p
->address (objfile
) > best_pc
423 || (psymtab
->text_low (objfile
) == 0
424 && best_pc
== 0 && p
->address (objfile
) == 0)))
426 if (section
!= NULL
) /* Match on a specific section. */
428 if (!matching_obj_sections (p
->obj_section (objfile
),
432 best_pc
= p
->address (objfile
);
440 /* Psymtab version of lookup_symbol. See its definition in
441 the definition of quick_symbol_functions in symfile.h. */
443 struct compunit_symtab
*
444 psymbol_functions::lookup_symbol (struct objfile
*objfile
,
445 block_enum block_index
, const char *name
,
446 const domain_enum domain
)
448 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
449 struct compunit_symtab
*stab_best
= NULL
;
451 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
453 lookup_name_info psym_lookup_name
= lookup_name
.make_ignore_params ();
455 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
457 if (!ps
->readin_p (objfile
)
458 && lookup_partial_symbol (objfile
, ps
, psym_lookup_name
,
459 psymtab_index
, domain
))
461 struct symbol
*sym
, *with_opaque
= NULL
;
462 struct compunit_symtab
*stab
= psymtab_to_symtab (objfile
, ps
);
463 /* Note: While psymtab_to_symtab can return NULL if the
464 partial symtab is empty, we can assume it won't here
465 because lookup_partial_symbol succeeded. */
466 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
467 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
469 sym
= block_find_symbol (block
, name
, domain
,
470 block_find_non_opaque_type_preferred
,
473 /* Some caution must be observed with overloaded functions
474 and methods, since the index will not contain any overload
475 information (but NAME might contain it). */
478 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
480 if (with_opaque
!= NULL
481 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
484 /* Keep looking through other psymtabs. */
491 /* Psymtab version of lookup_global_symbol_language. See its definition in
492 the definition of quick_symbol_functions in symfile.h. */
495 psymbol_functions::lookup_global_symbol_language (struct objfile
*objfile
,
498 bool *symbol_found_p
)
500 *symbol_found_p
= false;
501 if (objfile
->sf
== NULL
)
502 return language_unknown
;
504 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
506 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
508 struct partial_symbol
*psym
;
509 if (ps
->readin_p (objfile
))
512 psym
= lookup_partial_symbol (objfile
, ps
, lookup_name
, 1, domain
);
515 *symbol_found_p
= true;
516 return psym
->ginfo
.language ();
520 return language_unknown
;
523 /* Returns true if PSYM matches LOOKUP_NAME. */
526 psymbol_name_matches (partial_symbol
*psym
,
527 const lookup_name_info
&lookup_name
)
529 const language_defn
*lang
= language_def (psym
->ginfo
.language ());
530 symbol_name_matcher_ftype
*name_match
531 = lang
->get_symbol_name_matcher (lookup_name
);
532 return name_match (psym
->ginfo
.search_name (), lookup_name
, NULL
);
535 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
536 the global block of PST if GLOBAL, and otherwise the static block.
537 MATCH is the comparison operation that returns true iff MATCH (s,
538 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
539 non-null, the symbols in the block are assumed to be ordered
540 according to it (allowing binary search). It must be compatible
541 with MATCH. Returns the symbol, if found, and otherwise NULL. */
543 static struct partial_symbol
*
544 match_partial_symbol (struct objfile
*objfile
,
545 struct partial_symtab
*pst
, int global
,
546 const lookup_name_info
&name
, domain_enum domain
,
547 symbol_compare_ftype
*ordered_compare
)
549 struct partial_symbol
**start
, **psym
;
550 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
552 ? pst
->global_psymbols
.size ()
553 : pst
->static_psymbols
.size ());
554 int do_linear_search
= 1;
560 &pst
->global_psymbols
[0] :
561 &pst
->static_psymbols
[0]);
563 if (global
&& ordered_compare
) /* Can use a binary search. */
565 do_linear_search
= 0;
567 /* Binary search. This search is guaranteed to end with center
568 pointing at the earliest partial symbol whose name might be
569 correct. At that point *all* partial symbols with an
570 appropriate name will be checked against the correct
574 top
= start
+ length
- 1;
578 center
= bottom
+ (top
- bottom
) / 2;
579 gdb_assert (center
< top
);
581 enum language lang
= (*center
)->ginfo
.language ();
582 const char *lang_ln
= name
.language_lookup_name (lang
);
584 if (ordered_compare ((*center
)->ginfo
.search_name (),
590 gdb_assert (top
== bottom
);
592 while (top
<= real_top
593 && psymbol_name_matches (*top
, name
))
595 if (symbol_matches_domain ((*top
)->ginfo
.language (),
596 (*top
)->domain
, domain
))
602 /* Can't use a binary search or else we found during the binary search that
603 we should also do a linear search. */
605 if (do_linear_search
)
607 for (psym
= start
; psym
< start
+ length
; psym
++)
609 if (symbol_matches_domain ((*psym
)->ginfo
.language (),
610 (*psym
)->domain
, domain
)
611 && psymbol_name_matches (*psym
, name
))
619 /* Look, in partial_symtab PST, for symbol whose natural name is
620 LOOKUP_NAME. Check the global symbols if GLOBAL, the static
623 static struct partial_symbol
*
624 lookup_partial_symbol (struct objfile
*objfile
,
625 struct partial_symtab
*pst
,
626 const lookup_name_info
&lookup_name
,
627 int global
, domain_enum domain
)
629 struct partial_symbol
**start
, **psym
;
630 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
632 ? pst
->global_psymbols
.size ()
633 : pst
->static_psymbols
.size ());
634 int do_linear_search
= 1;
640 &pst
->global_psymbols
[0] :
641 &pst
->static_psymbols
[0]);
643 if (global
) /* This means we can use a binary search. */
645 do_linear_search
= 0;
647 /* Binary search. This search is guaranteed to end with center
648 pointing at the earliest partial symbol whose name might be
649 correct. At that point *all* partial symbols with an
650 appropriate name will be checked against the correct
654 top
= start
+ length
- 1;
658 center
= bottom
+ (top
- bottom
) / 2;
660 gdb_assert (center
< top
);
662 if (strcmp_iw_ordered ((*center
)->ginfo
.search_name (),
663 lookup_name
.c_str ()) >= 0)
673 gdb_assert (top
== bottom
);
675 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
676 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
677 while (top
>= start
&& symbol_matches_search_name (&(*top
)->ginfo
,
681 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
684 while (top
<= real_top
&& symbol_matches_search_name (&(*top
)->ginfo
,
687 if (symbol_matches_domain ((*top
)->ginfo
.language (),
688 (*top
)->domain
, domain
))
694 /* Can't use a binary search or else we found during the binary search that
695 we should also do a linear search. */
697 if (do_linear_search
)
699 for (psym
= start
; psym
< start
+ length
; psym
++)
701 if (symbol_matches_domain ((*psym
)->ginfo
.language (),
702 (*psym
)->domain
, domain
)
703 && symbol_matches_search_name (&(*psym
)->ginfo
, lookup_name
))
711 /* Get the symbol table that corresponds to a partial_symtab.
712 This is fast after the first time you do it.
713 The result will be NULL if the primary symtab has no symbols,
714 which can happen. Otherwise the result is the primary symtab
715 that contains PST. */
717 static struct compunit_symtab
*
718 psymtab_to_symtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
720 /* If it is a shared psymtab, find an unshared psymtab that includes
721 it. Any such psymtab will do. */
722 while (pst
->user
!= NULL
)
725 /* If it's been looked up before, return it. */
726 if (pst
->get_compunit_symtab (objfile
))
727 return pst
->get_compunit_symtab (objfile
);
729 /* If it has not yet been read in, read it. */
730 if (!pst
->readin_p (objfile
))
732 scoped_restore decrementer
= increment_reading_symtab ();
736 printf_filtered (_("Reading in symbols for %s...\n"),
738 gdb_flush (gdb_stdout
);
741 pst
->read_symtab (objfile
);
744 return pst
->get_compunit_symtab (objfile
);
747 /* Psymtab version of find_last_source_symtab. See its definition in
748 the definition of quick_symbol_functions in symfile.h. */
751 psymbol_functions::find_last_source_symtab (struct objfile
*ofp
)
753 struct partial_symtab
*cs_pst
= NULL
;
755 for (partial_symtab
*ps
: require_partial_symbols (ofp
))
757 const char *name
= ps
->filename
;
758 int len
= strlen (name
);
760 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
761 || strcmp (name
, "<<C++-namespaces>>") == 0)))
767 if (cs_pst
->readin_p (ofp
))
769 internal_error (__FILE__
, __LINE__
,
770 _("select_source_symtab: "
771 "readin pst found and no symtabs."));
775 struct compunit_symtab
*cust
= psymtab_to_symtab (ofp
, cs_pst
);
779 return compunit_primary_filetab (cust
);
785 /* Psymtab version of forget_cached_source_info. See its definition in
786 the definition of quick_symbol_functions in symfile.h. */
789 psymbol_functions::forget_cached_source_info (struct objfile
*objfile
)
791 for (partial_symtab
*pst
: require_partial_symbols (objfile
))
793 if (pst
->fullname
!= NULL
)
795 xfree (pst
->fullname
);
796 pst
->fullname
= NULL
;
802 print_partial_symbols (struct gdbarch
*gdbarch
, struct objfile
*objfile
,
803 const std::vector
<partial_symbol
*> &symbols
,
804 const char *what
, struct ui_file
*outfile
)
806 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
807 for (partial_symbol
*p
: symbols
)
810 fprintf_filtered (outfile
, " `%s'", p
->ginfo
.linkage_name ());
811 if (p
->ginfo
.demangled_name () != NULL
)
813 fprintf_filtered (outfile
, " `%s'",
814 p
->ginfo
.demangled_name ());
816 fputs_filtered (", ", outfile
);
820 fputs_filtered ("undefined domain, ", outfile
);
823 /* This is the usual thing -- don't print it. */
826 fputs_filtered ("struct domain, ", outfile
);
829 fputs_filtered ("module domain, ", outfile
);
832 fputs_filtered ("label domain, ", outfile
);
834 case COMMON_BLOCK_DOMAIN
:
835 fputs_filtered ("common block domain, ", outfile
);
838 fputs_filtered ("<invalid domain>, ", outfile
);
844 fputs_filtered ("undefined", outfile
);
847 fputs_filtered ("constant int", outfile
);
850 fputs_filtered ("static", outfile
);
853 fputs_filtered ("register", outfile
);
856 fputs_filtered ("pass by value", outfile
);
859 fputs_filtered ("pass by reference", outfile
);
861 case LOC_REGPARM_ADDR
:
862 fputs_filtered ("register address parameter", outfile
);
865 fputs_filtered ("stack parameter", outfile
);
868 fputs_filtered ("type", outfile
);
871 fputs_filtered ("label", outfile
);
874 fputs_filtered ("function", outfile
);
876 case LOC_CONST_BYTES
:
877 fputs_filtered ("constant bytes", outfile
);
880 fputs_filtered ("unresolved", outfile
);
882 case LOC_OPTIMIZED_OUT
:
883 fputs_filtered ("optimized out", outfile
);
886 fputs_filtered ("computed at runtime", outfile
);
889 fputs_filtered ("<invalid location>", outfile
);
892 fputs_filtered (", ", outfile
);
893 fputs_filtered (paddress (gdbarch
, p
->unrelocated_address ()), outfile
);
894 fprintf_filtered (outfile
, "\n");
899 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
900 struct ui_file
*outfile
)
902 struct gdbarch
*gdbarch
= objfile
->arch ();
905 if (psymtab
->anonymous
)
907 fprintf_filtered (outfile
, "\nAnonymous partial symtab (%s) ",
912 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
915 fprintf_filtered (outfile
, "(object ");
916 gdb_print_host_address (psymtab
, outfile
);
917 fprintf_filtered (outfile
, ")\n\n");
918 fprintf_filtered (outfile
, " Read from object file %s (",
919 objfile_name (objfile
));
920 gdb_print_host_address (objfile
, outfile
);
921 fprintf_filtered (outfile
, ")\n");
923 if (psymtab
->readin_p (objfile
))
925 fprintf_filtered (outfile
,
926 " Full symtab was read (at ");
927 gdb_print_host_address (psymtab
->get_compunit_symtab (objfile
), outfile
);
928 fprintf_filtered (outfile
, ")\n");
931 fprintf_filtered (outfile
, " Symbols cover text addresses ");
932 fputs_filtered (paddress (gdbarch
, psymtab
->text_low (objfile
)), outfile
);
933 fprintf_filtered (outfile
, "-");
934 fputs_filtered (paddress (gdbarch
, psymtab
->text_high (objfile
)), outfile
);
935 fprintf_filtered (outfile
, "\n");
936 fprintf_filtered (outfile
, " Address map supported - %s.\n",
937 psymtab
->psymtabs_addrmap_supported
? "yes" : "no");
938 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
939 psymtab
->number_of_dependencies
);
940 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
942 fprintf_filtered (outfile
, " %d ", i
);
943 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
944 fprintf_filtered (outfile
, " %s\n",
945 psymtab
->dependencies
[i
]->filename
);
947 if (psymtab
->user
!= NULL
)
949 fprintf_filtered (outfile
, " Shared partial symtab with user ");
950 gdb_print_host_address (psymtab
->user
, outfile
);
951 fprintf_filtered (outfile
, "\n");
953 if (!psymtab
->global_psymbols
.empty ())
955 print_partial_symbols
956 (gdbarch
, objfile
, psymtab
->global_psymbols
,
959 if (!psymtab
->static_psymbols
.empty ())
961 print_partial_symbols
962 (gdbarch
, objfile
, psymtab
->static_psymbols
,
965 fprintf_filtered (outfile
, "\n");
968 /* Count the number of partial symbols in OBJFILE. */
971 count_psyms (struct objfile
*objfile
)
974 for (partial_symtab
*pst
: objfile
->psymtabs ())
976 count
+= pst
->global_psymbols
.size ();
977 count
+= pst
->static_psymbols
.size ();
982 /* Psymtab version of print_stats. See its definition in
983 the definition of quick_symbol_functions in symfile.h. */
986 psymbol_functions::print_stats (struct objfile
*objfile
, bool print_bcache
)
992 int n_psyms
= count_psyms (objfile
);
994 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
998 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
1000 if (!ps
->readin_p (objfile
))
1003 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"),
1005 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
1006 m_partial_symtabs
->psymbol_cache
.memory_used ());
1010 printf_filtered (_("Psymbol byte cache statistics:\n"));
1011 m_partial_symtabs
->psymbol_cache
.print_statistics
1012 ("partial symbol cache");
1016 /* Psymtab version of dump. See its definition in
1017 the definition of quick_symbol_functions in symfile.h. */
1020 psymbol_functions::dump (struct objfile
*objfile
)
1022 struct partial_symtab
*psymtab
;
1024 if (m_partial_symtabs
->psymtabs
)
1026 printf_filtered ("Psymtabs:\n");
1027 for (psymtab
= m_partial_symtabs
->psymtabs
;
1029 psymtab
= psymtab
->next
)
1031 printf_filtered ("%s at ",
1033 gdb_print_host_address (psymtab
, gdb_stdout
);
1034 printf_filtered (", ");
1037 printf_filtered ("\n\n");
1041 /* Psymtab version of expand_symtabs_for_function. See its definition in
1042 the definition of quick_symbol_functions in symfile.h. */
1045 psymbol_functions::expand_symtabs_for_function (struct objfile
*objfile
,
1046 const char *func_name
)
1048 lookup_name_info
base_lookup (func_name
, symbol_name_match_type::FULL
);
1049 lookup_name_info lookup_name
= base_lookup
.make_ignore_params ();
1051 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
1053 if (ps
->readin_p (objfile
))
1056 if ((lookup_partial_symbol (objfile
, ps
, lookup_name
, 1, VAR_DOMAIN
)
1058 || (lookup_partial_symbol (objfile
, ps
, lookup_name
, 0, VAR_DOMAIN
)
1060 psymtab_to_symtab (objfile
, ps
);
1064 /* Psymtab version of expand_all_symtabs. See its definition in
1065 the definition of quick_symbol_functions in symfile.h. */
1068 psymbol_functions::expand_all_symtabs (struct objfile
*objfile
)
1070 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
))
1071 psymtab_to_symtab (objfile
, psymtab
);
1074 /* Psymtab version of expand_symtabs_with_fullname. See its definition in
1075 the definition of quick_symbol_functions in symfile.h. */
1078 psymbol_functions::expand_symtabs_with_fullname (struct objfile
*objfile
,
1079 const char *fullname
)
1081 for (partial_symtab
*p
: require_partial_symbols (objfile
))
1083 /* Anonymous psymtabs don't have a name of a source file. */
1087 /* psymtab_to_fullname tries to open the file which is slow.
1088 Don't call it if we know the basenames don't match. */
1089 if ((basenames_may_differ
1090 || filename_cmp (lbasename (fullname
), lbasename (p
->filename
)) == 0)
1091 && filename_cmp (fullname
, psymtab_to_fullname (p
)) == 0)
1092 psymtab_to_symtab (objfile
, p
);
1096 /* Psymtab version of map_symbol_filenames. See its definition in
1097 the definition of quick_symbol_functions in symfile.h. */
1100 psymbol_functions::map_symbol_filenames (struct objfile
*objfile
,
1101 symbol_filename_ftype
*fun
,
1105 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
1107 const char *fullname
;
1109 if (ps
->readin_p (objfile
))
1112 /* We can skip shared psymtabs here, because any file name will be
1113 attached to the unshared psymtab. */
1114 if (ps
->user
!= NULL
)
1117 /* Anonymous psymtabs don't have a file name. */
1123 fullname
= psymtab_to_fullname (ps
);
1126 (*fun
) (ps
->filename
, fullname
, data
);
1130 /* Finds the fullname that a partial_symtab represents.
1132 If this functions finds the fullname, it will save it in ps->fullname
1133 and it will also return the value.
1135 If this function fails to find the file that this partial_symtab represents,
1136 NULL will be returned and ps->fullname will be set to NULL. */
1139 psymtab_to_fullname (struct partial_symtab
*ps
)
1141 gdb_assert (!ps
->anonymous
);
1143 /* Use cached copy if we have it.
1144 We rely on forget_cached_source_info being called appropriately
1145 to handle cases like the file being moved. */
1146 if (ps
->fullname
== NULL
)
1148 gdb::unique_xmalloc_ptr
<char> fullname
;
1149 scoped_fd fd
= find_and_open_source (ps
->filename
, ps
->dirname
,
1151 ps
->fullname
= fullname
.release ();
1155 /* rewrite_source_path would be applied by find_and_open_source, we
1156 should report the pathname where GDB tried to find the file. */
1158 if (ps
->dirname
== NULL
|| IS_ABSOLUTE_PATH (ps
->filename
))
1159 fullname
.reset (xstrdup (ps
->filename
));
1161 fullname
.reset (concat (ps
->dirname
, SLASH_STRING
,
1162 ps
->filename
, (char *) NULL
));
1164 ps
->fullname
= rewrite_source_path (fullname
.get ()).release ();
1165 if (ps
->fullname
== NULL
)
1166 ps
->fullname
= fullname
.release ();
1170 return ps
->fullname
;
1173 /* Psymtab version of map_matching_symbols. See its definition in
1174 the definition of quick_symbol_functions in symfile.h. */
1177 psymbol_functions::map_matching_symbols
1178 (struct objfile
*objfile
,
1179 const lookup_name_info
&name
, domain_enum domain
,
1181 gdb::function_view
<symbol_found_callback_ftype
> callback
,
1182 symbol_compare_ftype
*ordered_compare
)
1184 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
1186 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
1189 if (ps
->readin_p (objfile
)
1190 || match_partial_symbol (objfile
, ps
, global
, name
, domain
,
1193 struct compunit_symtab
*cust
= psymtab_to_symtab (objfile
, ps
);
1194 const struct block
*block
;
1198 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
1199 if (!iterate_over_symbols_terminated (block
, name
,
1206 /* A helper for psym_expand_symtabs_matching that handles searching
1207 included psymtabs. This returns true if a symbol is found, and
1208 false otherwise. It also updates the 'searched_flag' on the
1209 various psymtabs that it searches. */
1212 recursively_search_psymtabs
1213 (struct partial_symtab
*ps
,
1214 struct objfile
*objfile
,
1215 enum search_domain domain
,
1216 const lookup_name_info
&lookup_name
,
1217 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> sym_matcher
)
1220 enum psymtab_search_status result
= PST_SEARCHED_AND_NOT_FOUND
;
1223 if (ps
->searched_flag
!= PST_NOT_SEARCHED
)
1224 return ps
->searched_flag
== PST_SEARCHED_AND_FOUND
;
1226 /* Recurse into shared psymtabs first, because they may have already
1227 been searched, and this could save some time. */
1228 for (i
= 0; i
< ps
->number_of_dependencies
; ++i
)
1232 /* Skip non-shared dependencies, these are handled elsewhere. */
1233 if (ps
->dependencies
[i
]->user
== NULL
)
1236 r
= recursively_search_psymtabs (ps
->dependencies
[i
],
1237 objfile
, domain
, lookup_name
,
1241 ps
->searched_flag
= PST_SEARCHED_AND_FOUND
;
1246 partial_symbol
**gbound
= (ps
->global_psymbols
.data ()
1247 + ps
->global_psymbols
.size ());
1248 partial_symbol
**sbound
= (ps
->static_psymbols
.data ()
1249 + ps
->static_psymbols
.size ());
1250 partial_symbol
**bound
= gbound
;
1252 /* Go through all of the symbols stored in a partial
1253 symtab in one loop. */
1254 partial_symbol
**psym
= ps
->global_psymbols
.data ();
1259 if (bound
== gbound
&& !ps
->static_psymbols
.empty ())
1261 psym
= ps
->static_psymbols
.data ();
1272 if ((domain
== ALL_DOMAIN
1273 || (domain
== MODULES_DOMAIN
1274 && (*psym
)->domain
== MODULE_DOMAIN
)
1275 || (domain
== VARIABLES_DOMAIN
1276 && (*psym
)->aclass
!= LOC_TYPEDEF
1277 && (*psym
)->aclass
!= LOC_BLOCK
)
1278 || (domain
== FUNCTIONS_DOMAIN
1279 && (*psym
)->aclass
== LOC_BLOCK
)
1280 || (domain
== TYPES_DOMAIN
1281 && (*psym
)->aclass
== LOC_TYPEDEF
))
1282 && psymbol_name_matches (*psym
, lookup_name
)
1283 && (sym_matcher
== NULL
1284 || sym_matcher ((*psym
)->ginfo
.search_name ())))
1286 /* Found a match, so notify our caller. */
1287 result
= PST_SEARCHED_AND_FOUND
;
1294 ps
->searched_flag
= result
;
1295 return result
== PST_SEARCHED_AND_FOUND
;
1298 /* Psymtab version of expand_symtabs_matching. See its definition in
1299 the definition of quick_symbol_functions in symfile.h. */
1302 psymbol_functions::expand_symtabs_matching
1303 (struct objfile
*objfile
,
1304 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
1305 const lookup_name_info
*lookup_name
,
1306 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
1307 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
1308 enum search_domain domain
)
1310 /* Clear the search flags. */
1311 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
1312 ps
->searched_flag
= PST_NOT_SEARCHED
;
1314 for (partial_symtab
*ps
: m_partial_symtabs
->range ())
1318 if (ps
->readin_p (objfile
))
1321 /* We skip shared psymtabs because file-matching doesn't apply
1322 to them; but we search them later in the loop. */
1323 if (ps
->user
!= NULL
)
1333 match
= file_matcher (ps
->filename
, false);
1336 /* Before we invoke realpath, which can get expensive when many
1337 files are involved, do a quick comparison of the basenames. */
1338 if (basenames_may_differ
1339 || file_matcher (lbasename (ps
->filename
), true))
1340 match
= file_matcher (psymtab_to_fullname (ps
), false);
1346 if ((symbol_matcher
== NULL
&& lookup_name
== NULL
)
1347 || recursively_search_psymtabs (ps
, objfile
, domain
,
1348 lookup_name
->make_ignore_params (),
1351 struct compunit_symtab
*symtab
=
1352 psymtab_to_symtab (objfile
, ps
);
1354 if (expansion_notify
!= NULL
)
1355 expansion_notify (symtab
);
1360 /* Psymtab version of has_symbols. See its definition in
1361 the definition of quick_symbol_functions in symfile.h. */
1364 psymbol_functions::has_symbols (struct objfile
*objfile
)
1366 return m_partial_symtabs
->psymtabs
!= NULL
;
1369 /* Helper function for psym_find_compunit_symtab_by_address that fills
1370 in m_psymbol_map for a given range of psymbols. */
1373 psymbol_functions::fill_psymbol_map
1374 (struct objfile
*objfile
,
1375 struct partial_symtab
*psymtab
,
1376 std::set
<CORE_ADDR
> *seen_addrs
,
1377 const std::vector
<partial_symbol
*> &symbols
)
1379 for (partial_symbol
*psym
: symbols
)
1381 if (psym
->aclass
== LOC_STATIC
)
1383 CORE_ADDR addr
= psym
->address (objfile
);
1384 if (seen_addrs
->find (addr
) == seen_addrs
->end ())
1386 seen_addrs
->insert (addr
);
1387 m_psymbol_map
.emplace_back (addr
, psymtab
);
1393 /* See find_compunit_symtab_by_address in quick_symbol_functions, in
1397 psymbol_functions::find_compunit_symtab_by_address (struct objfile
*objfile
,
1400 if (m_psymbol_map
.empty ())
1402 std::set
<CORE_ADDR
> seen_addrs
;
1404 for (partial_symtab
*pst
: require_partial_symbols (objfile
))
1406 fill_psymbol_map (objfile
, pst
,
1408 pst
->global_psymbols
);
1409 fill_psymbol_map (objfile
, pst
,
1411 pst
->static_psymbols
);
1414 m_psymbol_map
.shrink_to_fit ();
1416 std::sort (m_psymbol_map
.begin (), m_psymbol_map
.end (),
1417 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1418 const std::pair
<CORE_ADDR
, partial_symtab
*> &b
)
1420 return a
.first
< b
.first
;
1424 auto iter
= std::lower_bound
1425 (m_psymbol_map
.begin (), m_psymbol_map
.end (), address
,
1426 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1432 if (iter
== m_psymbol_map
.end () || iter
->first
!= address
)
1435 return psymtab_to_symtab (objfile
, iter
->second
);
1438 quick_symbol_functions_up
1439 make_psymbol_functions (const std::shared_ptr
<psymtab_storage
> &storage
)
1441 return quick_symbol_functions_up (new psymbol_functions (storage
));
1446 /* Partially fill a partial symtab. It will be completely filled at
1447 the end of the symbol list. */
1449 partial_symtab::partial_symtab (const char *filename
,
1450 struct objfile
*objfile
,
1452 : partial_symtab (filename
, objfile
)
1454 set_text_low (textlow
);
1455 set_text_high (raw_text_low ()); /* default */
1458 /* Perform "finishing up" operations of a partial symtab. */
1461 partial_symtab::end ()
1463 global_psymbols
.shrink_to_fit ();
1464 static_psymbols
.shrink_to_fit ();
1466 /* Sort the global list; don't sort the static list. */
1467 std::sort (global_psymbols
.begin (),
1468 global_psymbols
.end (),
1469 [] (partial_symbol
*s1
, partial_symbol
*s2
)
1471 return strcmp_iw_ordered (s1
->ginfo
.search_name (),
1472 s2
->ginfo
.search_name ()) < 0;
1476 /* See psymtab.h. */
1479 psymbol_bcache::hash (const void *addr
, int length
)
1481 unsigned long h
= 0;
1482 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1483 unsigned int lang
= psymbol
->ginfo
.language ();
1484 unsigned int domain
= psymbol
->domain
;
1485 unsigned int theclass
= psymbol
->aclass
;
1487 h
= fast_hash (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1488 h
= fast_hash (&lang
, sizeof (unsigned int), h
);
1489 h
= fast_hash (&domain
, sizeof (unsigned int), h
);
1490 h
= fast_hash (&theclass
, sizeof (unsigned int), h
);
1491 /* Note that psymbol names are interned via compute_and_set_names, so
1492 there's no need to hash the contents of the name here. */
1493 h
= fast_hash (&psymbol
->ginfo
.m_name
, sizeof (psymbol
->ginfo
.m_name
), h
);
1498 /* See psymtab.h. */
1501 psymbol_bcache::compare (const void *addr1
, const void *addr2
, int length
)
1503 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1504 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1506 return (memcmp (&sym1
->ginfo
.value
, &sym2
->ginfo
.value
,
1507 sizeof (sym1
->ginfo
.value
)) == 0
1508 && sym1
->ginfo
.language () == sym2
->ginfo
.language ()
1509 && sym1
->domain
== sym2
->domain
1510 && sym1
->aclass
== sym2
->aclass
1511 /* Note that psymbol names are interned via
1512 compute_and_set_names, so there's no need to compare the
1513 contents of the name here. */
1514 && sym1
->ginfo
.linkage_name () == sym2
->ginfo
.linkage_name ());
1517 /* Helper function, initialises partial symbol structure and stashes
1518 it into objfile's bcache. Note that our caching mechanism will
1519 use all fields of struct partial_symbol to determine hash value of the
1520 structure. In other words, having two symbols with the same name but
1521 different domain (or address) is possible and correct. */
1523 static struct partial_symbol
*
1524 add_psymbol_to_bcache (const partial_symbol
&psymbol
, struct objfile
*objfile
,
1527 /* Stash the partial symbol away in the cache. */
1528 return ((struct partial_symbol
*)
1529 objfile
->partial_symtabs
->psymbol_cache
.insert
1530 (&psymbol
, sizeof (struct partial_symbol
), added
));
1533 /* See psympriv.h. */
1536 partial_symtab::add_psymbol (const partial_symbol
&psymbol
,
1537 psymbol_placement where
,
1538 struct objfile
*objfile
)
1542 /* Stash the partial symbol away in the cache. */
1543 partial_symbol
*psym
= add_psymbol_to_bcache (psymbol
, objfile
, &added
);
1545 /* Do not duplicate global partial symbols. */
1546 if (where
== psymbol_placement::GLOBAL
&& !added
)
1549 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1550 std::vector
<partial_symbol
*> &list
1551 = (where
== psymbol_placement::STATIC
1554 list
.push_back (psym
);
1557 /* See psympriv.h. */
1560 partial_symtab::add_psymbol (gdb::string_view name
, bool copy_name
,
1562 enum address_class theclass
,
1564 psymbol_placement where
,
1566 enum language language
, struct objfile
*objfile
)
1568 struct partial_symbol psymbol
;
1569 memset (&psymbol
, 0, sizeof (psymbol
));
1571 psymbol
.set_unrelocated_address (coreaddr
);
1572 psymbol
.ginfo
.set_section_index (section
);
1573 psymbol
.domain
= domain
;
1574 psymbol
.aclass
= theclass
;
1575 psymbol
.ginfo
.set_language (language
, objfile
->partial_symtabs
->obstack ());
1576 psymbol
.ginfo
.compute_and_set_names (name
, copy_name
, objfile
->per_bfd
);
1578 add_psymbol (psymbol
, where
, objfile
);
1581 /* See psympriv.h. */
1583 partial_symtab::partial_symtab (const char *filename_
, struct objfile
*objfile
)
1584 : searched_flag (PST_NOT_SEARCHED
),
1588 objfile
->partial_symtabs
->install_psymtab (this);
1590 filename
= objfile
->intern (filename_
);
1592 if (symtab_create_debug
)
1594 /* Be a bit clever with debugging messages, and don't print objfile
1595 every time, only when it changes. */
1596 static char *last_objfile_name
= NULL
;
1598 if (last_objfile_name
== NULL
1599 || strcmp (last_objfile_name
, objfile_name (objfile
)) != 0)
1601 xfree (last_objfile_name
);
1602 last_objfile_name
= xstrdup (objfile_name (objfile
));
1603 fprintf_filtered (gdb_stdlog
,
1604 "Creating one or more psymtabs for objfile %s ...\n",
1607 fprintf_filtered (gdb_stdlog
,
1608 "Created psymtab %s for module %s.\n",
1609 host_address_to_string (this), filename
);
1613 /* See psympriv.h. */
1616 partial_symtab::expand_dependencies (struct objfile
*objfile
)
1618 for (int i
= 0; i
< number_of_dependencies
; ++i
)
1620 if (!dependencies
[i
]->readin_p (objfile
)
1621 && dependencies
[i
]->user
== NULL
)
1623 /* Inform about additional files to be read in. */
1626 fputs_filtered (" ", gdb_stdout
);
1628 fputs_filtered ("and ", gdb_stdout
);
1630 printf_filtered ("%s...", dependencies
[i
]->filename
);
1631 wrap_here (""); /* Flush output */
1632 gdb_flush (gdb_stdout
);
1634 dependencies
[i
]->expand_psymtab (objfile
);
1641 psymtab_storage::discard_psymtab (struct partial_symtab
*pst
)
1643 struct partial_symtab
**prev_pst
;
1646 Empty psymtabs happen as a result of header files which don't
1647 have any symbols in them. There can be a lot of them. But this
1648 check is wrong, in that a psymtab with N_SLINE entries but
1649 nothing else is not empty, but we don't realize that. Fixing
1650 that without slowing things down might be tricky. */
1652 /* First, snip it out of the psymtab chain. */
1654 prev_pst
= &psymtabs
;
1655 while ((*prev_pst
) != pst
)
1656 prev_pst
= &((*prev_pst
)->next
);
1657 (*prev_pst
) = pst
->next
;
1663 /* We need to pass a couple of items to the addrmap_foreach function,
1666 struct dump_psymtab_addrmap_data
1668 struct objfile
*objfile
;
1669 struct partial_symtab
*psymtab
;
1670 struct ui_file
*outfile
;
1672 /* Non-zero if the previously printed addrmap entry was for PSYMTAB.
1673 If so, we want to print the next one as well (since the next addrmap
1674 entry defines the end of the range). */
1675 int previous_matched
;
1678 /* Helper function for dump_psymtab_addrmap to print an addrmap entry. */
1681 dump_psymtab_addrmap_1 (void *datap
, CORE_ADDR start_addr
, void *obj
)
1683 struct dump_psymtab_addrmap_data
*data
1684 = (struct dump_psymtab_addrmap_data
*) datap
;
1685 struct gdbarch
*gdbarch
= data
->objfile
->arch ();
1686 struct partial_symtab
*addrmap_psymtab
= (struct partial_symtab
*) obj
;
1687 const char *psymtab_address_or_end
= NULL
;
1691 if (data
->psymtab
== NULL
1692 || data
->psymtab
== addrmap_psymtab
)
1693 psymtab_address_or_end
= host_address_to_string (addrmap_psymtab
);
1694 else if (data
->previous_matched
)
1695 psymtab_address_or_end
= "<ends here>";
1697 if (data
->psymtab
== NULL
1698 || data
->psymtab
== addrmap_psymtab
1699 || data
->previous_matched
)
1701 fprintf_filtered (data
->outfile
, " %s%s %s\n",
1702 data
->psymtab
!= NULL
? " " : "",
1703 paddress (gdbarch
, start_addr
),
1704 psymtab_address_or_end
);
1707 data
->previous_matched
= (data
->psymtab
== NULL
1708 || data
->psymtab
== addrmap_psymtab
);
1713 /* Helper function for maintenance_print_psymbols to print the addrmap
1714 of PSYMTAB. If PSYMTAB is NULL print the entire addrmap. */
1717 dump_psymtab_addrmap (struct objfile
*objfile
,
1718 psymtab_storage
*partial_symtabs
,
1719 struct partial_symtab
*psymtab
,
1720 struct ui_file
*outfile
)
1722 struct dump_psymtab_addrmap_data addrmap_dump_data
;
1724 if ((psymtab
== NULL
1725 || psymtab
->psymtabs_addrmap_supported
)
1726 && partial_symtabs
->psymtabs_addrmap
!= NULL
)
1728 addrmap_dump_data
.objfile
= objfile
;
1729 addrmap_dump_data
.psymtab
= psymtab
;
1730 addrmap_dump_data
.outfile
= outfile
;
1731 addrmap_dump_data
.previous_matched
= 0;
1732 fprintf_filtered (outfile
, "%sddress map:\n",
1733 psymtab
== NULL
? "Entire a" : " A");
1734 addrmap_foreach (partial_symtabs
->psymtabs_addrmap
,
1735 dump_psymtab_addrmap_1
, &addrmap_dump_data
);
1740 maintenance_print_psymbols (const char *args
, int from_tty
)
1742 struct ui_file
*outfile
= gdb_stdout
;
1743 char *address_arg
= NULL
, *source_arg
= NULL
, *objfile_arg
= NULL
;
1744 int i
, outfile_idx
, found
;
1746 struct obj_section
*section
= NULL
;
1750 gdb_argv
argv (args
);
1752 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
1754 if (strcmp (argv
[i
], "-pc") == 0)
1756 if (argv
[i
+ 1] == NULL
)
1757 error (_("Missing pc value"));
1758 address_arg
= argv
[++i
];
1760 else if (strcmp (argv
[i
], "-source") == 0)
1762 if (argv
[i
+ 1] == NULL
)
1763 error (_("Missing source file"));
1764 source_arg
= argv
[++i
];
1766 else if (strcmp (argv
[i
], "-objfile") == 0)
1768 if (argv
[i
+ 1] == NULL
)
1769 error (_("Missing objfile name"));
1770 objfile_arg
= argv
[++i
];
1772 else if (strcmp (argv
[i
], "--") == 0)
1774 /* End of options. */
1778 else if (argv
[i
][0] == '-')
1780 /* Future proofing: Don't allow OUTFILE to begin with "-". */
1781 error (_("Unknown option: %s"), argv
[i
]);
1788 if (address_arg
!= NULL
&& source_arg
!= NULL
)
1789 error (_("Must specify at most one of -pc and -source"));
1791 stdio_file arg_outfile
;
1793 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
1795 if (argv
[outfile_idx
+ 1] != NULL
)
1796 error (_("Junk at end of command"));
1797 gdb::unique_xmalloc_ptr
<char> outfile_name
1798 (tilde_expand (argv
[outfile_idx
]));
1799 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
1800 perror_with_name (outfile_name
.get ());
1801 outfile
= &arg_outfile
;
1804 if (address_arg
!= NULL
)
1806 pc
= parse_and_eval_address (address_arg
);
1807 /* If we fail to find a section, that's ok, try the lookup anyway. */
1808 section
= find_pc_section (pc
);
1812 for (objfile
*objfile
: current_program_space
->objfiles ())
1814 int printed_objfile_header
= 0;
1815 int print_for_objfile
= 1;
1818 if (objfile_arg
!= NULL
)
1820 = compare_filenames_for_search (objfile_name (objfile
),
1822 if (!print_for_objfile
)
1825 psymtab_storage
*partial_symtabs
= objfile
->partial_symtabs
.get ();
1827 if (address_arg
!= NULL
)
1829 struct bound_minimal_symbol msymbol
= { NULL
, NULL
};
1831 /* We don't assume each pc has a unique objfile (this is for
1833 struct partial_symtab
*ps
1834 = find_pc_sect_psymtab (objfile
, partial_symtabs
, pc
,
1838 if (!printed_objfile_header
)
1840 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1841 objfile_name (objfile
));
1842 printed_objfile_header
= 1;
1844 dump_psymtab (objfile
, ps
, outfile
);
1845 dump_psymtab_addrmap (objfile
, partial_symtabs
, ps
, outfile
);
1851 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
1853 int print_for_source
= 0;
1856 if (source_arg
!= NULL
)
1859 = compare_filenames_for_search (ps
->filename
, source_arg
);
1862 if (source_arg
== NULL
1863 || print_for_source
)
1865 if (!printed_objfile_header
)
1867 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1868 objfile_name (objfile
));
1869 printed_objfile_header
= 1;
1871 dump_psymtab (objfile
, ps
, outfile
);
1872 dump_psymtab_addrmap (objfile
, partial_symtabs
, ps
,
1878 /* If we're printing all the objfile's symbols dump the full addrmap. */
1880 if (address_arg
== NULL
1881 && source_arg
== NULL
1882 && partial_symtabs
->psymtabs_addrmap
!= NULL
)
1884 outfile
->puts ("\n");
1885 dump_psymtab_addrmap (objfile
, partial_symtabs
, NULL
, outfile
);
1891 if (address_arg
!= NULL
)
1892 error (_("No partial symtab for address: %s"), address_arg
);
1893 if (source_arg
!= NULL
)
1894 error (_("No partial symtab for source file: %s"), source_arg
);
1898 /* List all the partial symbol tables whose names match REGEXP (optional). */
1901 maintenance_info_psymtabs (const char *regexp
, int from_tty
)
1906 for (struct program_space
*pspace
: program_spaces
)
1907 for (objfile
*objfile
: pspace
->objfiles ())
1909 struct gdbarch
*gdbarch
= objfile
->arch ();
1911 /* We don't want to print anything for this objfile until we
1912 actually find a symtab whose name matches. */
1913 int printed_objfile_start
= 0;
1915 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
))
1920 || re_exec (psymtab
->filename
))
1922 if (! printed_objfile_start
)
1924 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
1926 printf_filtered ("((struct objfile *) %s)\n",
1927 host_address_to_string (objfile
));
1928 printed_objfile_start
= 1;
1931 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1933 printf_filtered ("((struct partial_symtab *) %s)\n",
1934 host_address_to_string (psymtab
));
1936 printf_filtered (" readin %s\n",
1937 psymtab
->readin_p (objfile
) ? "yes" : "no");
1938 printf_filtered (" fullname %s\n",
1940 ? psymtab
->fullname
: "(null)");
1941 printf_filtered (" text addresses ");
1942 fputs_filtered (paddress (gdbarch
,
1943 psymtab
->text_low (objfile
)),
1945 printf_filtered (" -- ");
1946 fputs_filtered (paddress (gdbarch
,
1947 psymtab
->text_high (objfile
)),
1949 printf_filtered ("\n");
1950 printf_filtered (" psymtabs_addrmap_supported %s\n",
1951 (psymtab
->psymtabs_addrmap_supported
1953 printf_filtered (" globals ");
1954 if (!psymtab
->global_psymbols
.empty ())
1956 ("(* (struct partial_symbol **) %s @ %d)\n",
1957 host_address_to_string (psymtab
->global_psymbols
.data ()),
1958 (int) psymtab
->global_psymbols
.size ());
1960 printf_filtered ("(none)\n");
1961 printf_filtered (" statics ");
1962 if (!psymtab
->static_psymbols
.empty ())
1964 ("(* (struct partial_symbol **) %s @ %d)\n",
1965 host_address_to_string (psymtab
->static_psymbols
.data ()),
1966 (int) psymtab
->static_psymbols
.size ());
1968 printf_filtered ("(none)\n");
1970 printf_filtered (" user %s "
1971 "((struct partial_symtab *) %s)\n",
1972 psymtab
->user
->filename
,
1973 host_address_to_string (psymtab
->user
));
1974 printf_filtered (" dependencies ");
1975 if (psymtab
->number_of_dependencies
)
1979 printf_filtered ("{\n");
1980 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1982 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
1984 /* Note the string concatenation there --- no
1986 printf_filtered (" psymtab %s "
1987 "((struct partial_symtab *) %s)\n",
1989 host_address_to_string (dep
));
1991 printf_filtered (" }\n");
1994 printf_filtered ("(none)\n");
1995 printf_filtered (" }\n");
1999 if (printed_objfile_start
)
2000 printf_filtered ("}\n");
2004 /* Check consistency of currently expanded psymtabs vs symtabs. */
2007 maintenance_check_psymtabs (const char *ignore
, int from_tty
)
2010 struct compunit_symtab
*cust
= NULL
;
2011 const struct blockvector
*bv
;
2012 const struct block
*b
;
2014 for (objfile
*objfile
: current_program_space
->objfiles ())
2015 for (partial_symtab
*ps
: require_partial_symbols (objfile
))
2017 struct gdbarch
*gdbarch
= objfile
->arch ();
2019 /* We don't call psymtab_to_symtab here because that may cause symtab
2020 expansion. When debugging a problem it helps if checkers leave
2021 things unchanged. */
2022 cust
= ps
->get_compunit_symtab (objfile
);
2024 /* First do some checks that don't require the associated symtab. */
2025 if (ps
->text_high (objfile
) < ps
->text_low (objfile
))
2027 printf_filtered ("Psymtab ");
2028 puts_filtered (ps
->filename
);
2029 printf_filtered (" covers bad range ");
2030 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
2032 printf_filtered (" - ");
2033 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
2035 printf_filtered ("\n");
2039 /* Now do checks requiring the associated symtab. */
2042 bv
= COMPUNIT_BLOCKVECTOR (cust
);
2043 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
2044 for (partial_symbol
*psym
: ps
->static_psymbols
)
2046 /* Skip symbols for inlined functions without address. These may
2047 or may not have a match in the full symtab. */
2048 if (psym
->aclass
== LOC_BLOCK
2049 && psym
->ginfo
.value
.address
== 0)
2052 sym
= block_lookup_symbol (b
, psym
->ginfo
.search_name (),
2053 symbol_name_match_type::SEARCH_NAME
,
2057 printf_filtered ("Static symbol `");
2058 puts_filtered (psym
->ginfo
.linkage_name ());
2059 printf_filtered ("' only found in ");
2060 puts_filtered (ps
->filename
);
2061 printf_filtered (" psymtab\n");
2064 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2065 for (partial_symbol
*psym
: ps
->global_psymbols
)
2067 sym
= block_lookup_symbol (b
, psym
->ginfo
.search_name (),
2068 symbol_name_match_type::SEARCH_NAME
,
2072 printf_filtered ("Global symbol `");
2073 puts_filtered (psym
->ginfo
.linkage_name ());
2074 printf_filtered ("' only found in ");
2075 puts_filtered (ps
->filename
);
2076 printf_filtered (" psymtab\n");
2079 if (ps
->raw_text_high () != 0
2080 && (ps
->text_low (objfile
) < BLOCK_START (b
)
2081 || ps
->text_high (objfile
) > BLOCK_END (b
)))
2083 printf_filtered ("Psymtab ");
2084 puts_filtered (ps
->filename
);
2085 printf_filtered (" covers ");
2086 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
2088 printf_filtered (" - ");
2089 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
2091 printf_filtered (" but symtab covers only ");
2092 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
2093 printf_filtered (" - ");
2094 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
2095 printf_filtered ("\n");
2100 void _initialize_psymtab ();
2102 _initialize_psymtab ()
2104 add_cmd ("psymbols", class_maintenance
, maintenance_print_psymbols
, _("\
2105 Print dump of current partial symbol definitions.\n\
2106 Usage: mt print psymbols [-objfile OBJFILE] [-pc ADDRESS] [--] [OUTFILE]\n\
2107 mt print psymbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
2108 Entries in the partial symbol table are dumped to file OUTFILE,\n\
2109 or the terminal if OUTFILE is unspecified.\n\
2110 If ADDRESS is provided, dump only the file for that address.\n\
2111 If SOURCE is provided, dump only that file's symbols.\n\
2112 If OBJFILE is provided, dump only that file's minimal symbols."),
2113 &maintenanceprintlist
);
2115 add_cmd ("psymtabs", class_maintenance
, maintenance_info_psymtabs
, _("\
2116 List the partial symbol tables for all object files.\n\
2117 This does not include information about individual partial symbols,\n\
2118 just the symbol table structures themselves."),
2119 &maintenanceinfolist
);
2121 add_cmd ("check-psymtabs", class_maintenance
, maintenance_check_psymtabs
,
2123 Check consistency of currently expanded psymtabs versus symtabs."),