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
)
80 psymtab_storage::partial_symtab_range
81 require_partial_symbols (struct objfile
*objfile
, bool verbose
)
83 if ((objfile
->flags
& OBJF_PSYMTABS_READ
) == 0)
85 objfile
->flags
|= OBJF_PSYMTABS_READ
;
87 if (objfile
->qf
->can_lazily_read_symbols ())
90 printf_filtered (_("Reading symbols from %s...\n"),
91 objfile_name (objfile
));
92 objfile
->qf
->read_partial_symbols (objfile
);
94 if (verbose
&& !objfile_has_symbols (objfile
))
95 printf_filtered (_("(No debugging symbols found in %s)\n"),
96 objfile_name (objfile
));
100 return objfile
->psymtabs ();
103 /* Helper function for psym_map_symtabs_matching_filename that
104 expands the symtabs and calls the iterator. */
107 partial_map_expand_apply (struct objfile
*objfile
,
109 const char *real_path
,
110 struct partial_symtab
*pst
,
111 gdb::function_view
<bool (symtab
*)> callback
)
113 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
115 /* Shared psymtabs should never be seen here. Instead they should
116 be handled properly by the caller. */
117 gdb_assert (pst
->user
== NULL
);
119 /* Don't visit already-expanded psymtabs. */
120 if (pst
->readin_p (objfile
))
123 /* This may expand more than one symtab, and we want to iterate over
125 psymtab_to_symtab (objfile
, pst
);
127 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
128 last_made
, callback
);
131 /* Psymtab version of map_symtabs_matching_filename. See its definition in
132 the definition of quick_symbol_functions in symfile.h. */
135 psymbol_functions::map_symtabs_matching_filename
136 (struct objfile
*objfile
,
138 const char *real_path
,
139 gdb::function_view
<bool (symtab
*)> callback
)
141 const char *name_basename
= lbasename (name
);
143 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
145 /* Anonymous psymtabs don't have a file name. */
149 if (compare_filenames_for_search (pst
->filename
, name
))
154 if (partial_map_expand_apply (objfile
, name
, real_path
,
160 /* Before we invoke realpath, which can get expensive when many
161 files are involved, do a quick comparison of the basenames. */
162 if (! basenames_may_differ
163 && FILENAME_CMP (name_basename
, lbasename (pst
->filename
)) != 0)
166 if (compare_filenames_for_search (psymtab_to_fullname (pst
), name
))
168 if (partial_map_expand_apply (objfile
, name
, real_path
,
174 /* If the user gave us an absolute path, try to find the file in
175 this symtab and use its absolute path. */
176 if (real_path
!= NULL
)
178 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
179 gdb_assert (IS_ABSOLUTE_PATH (name
));
180 if (filename_cmp (psymtab_to_fullname (pst
), real_path
) == 0)
182 if (partial_map_expand_apply (objfile
, name
, real_path
,
193 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
194 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
196 static struct partial_symtab
*
197 find_pc_sect_psymtab_closer (struct objfile
*objfile
,
198 CORE_ADDR pc
, struct obj_section
*section
,
199 struct partial_symtab
*pst
,
200 struct bound_minimal_symbol msymbol
)
202 struct partial_symtab
*tpst
;
203 struct partial_symtab
*best_pst
= pst
;
204 CORE_ADDR best_addr
= pst
->text_low (objfile
);
206 gdb_assert (!pst
->psymtabs_addrmap_supported
);
208 /* An objfile that has its functions reordered might have
209 many partial symbol tables containing the PC, but
210 we want the partial symbol table that contains the
211 function containing the PC. */
212 if (!(objfile
->flags
& OBJF_REORDERED
)
213 && section
== NULL
) /* Can't validate section this way. */
216 if (msymbol
.minsym
== NULL
)
219 /* The code range of partial symtabs sometimes overlap, so, in
220 the loop below, we need to check all partial symtabs and
221 find the one that fits better for the given PC address. We
222 select the partial symtab that contains a symbol whose
223 address is closest to the PC address. By closest we mean
224 that find_pc_sect_symbol returns the symbol with address
225 that is closest and still less than the given PC. */
226 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
228 if (pc
>= tpst
->text_low (objfile
) && pc
< tpst
->text_high (objfile
))
230 struct partial_symbol
*p
;
233 /* NOTE: This assumes that every psymbol has a
234 corresponding msymbol, which is not necessarily
235 true; the debug info might be much richer than the
236 object's symbol table. */
237 p
= find_pc_sect_psymbol (objfile
, tpst
, pc
, section
);
239 && (p
->address (objfile
) == BMSYMBOL_VALUE_ADDRESS (msymbol
)))
242 /* Also accept the textlow value of a psymtab as a
243 "symbol", to provide some support for partial
244 symbol tables with line information but no debug
245 symbols (e.g. those produced by an assembler). */
247 this_addr
= p
->address (objfile
);
249 this_addr
= tpst
->text_low (objfile
);
251 /* Check whether it is closer than our current
252 BEST_ADDR. Since this symbol address is
253 necessarily lower or equal to PC, the symbol closer
254 to PC is the symbol which address is the highest.
255 This way we return the psymtab which contains such
256 best match symbol. This can help in cases where the
257 symbol information/debuginfo is not complete, like
258 for instance on IRIX6 with gcc, where no debug info
259 is emitted for statics. (See also the nodebug.exp
261 if (this_addr
> best_addr
)
263 best_addr
= this_addr
;
271 /* Find which partial symtab contains PC and SECTION. Return NULL if
272 none. We return the psymtab that contains a symbol whose address
273 exactly matches PC, or, if we cannot find an exact match, the
274 psymtab that contains a symbol whose address is closest to PC. */
276 static struct partial_symtab
*
277 find_pc_sect_psymtab (struct objfile
*objfile
,
278 psymtab_storage
*partial_symtabs
,
280 struct obj_section
*section
,
281 struct bound_minimal_symbol msymbol
)
283 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better
284 granularity than the later used TEXTLOW/TEXTHIGH one. However, we need
285 to take care as the PSYMTABS_ADDRMAP can hold things other than partial
286 symtabs in some cases.
288 This function should only be called for objfiles that are using partial
289 symtabs, not for objfiles that are using indexes (.gdb_index or
290 .debug_names), however 'maintenance print psymbols' calls this function
291 directly for all objfiles. If we assume that PSYMTABS_ADDRMAP contains
292 partial symtabs then we will end up returning a pointer to an object
293 that is not a partial_symtab, which doesn't end well. */
295 if (partial_symtabs
->psymtabs
!= NULL
296 && partial_symtabs
->psymtabs_addrmap
!= NULL
)
298 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
300 struct partial_symtab
*pst
301 = ((struct partial_symtab
*)
302 addrmap_find (partial_symtabs
->psymtabs_addrmap
,
306 /* FIXME: addrmaps currently do not handle overlayed sections,
307 so fall back to the non-addrmap case if we're debugging
308 overlays and the addrmap returned the wrong section. */
309 if (overlay_debugging
&& msymbol
.minsym
!= NULL
&& section
!= NULL
)
311 struct partial_symbol
*p
;
313 /* NOTE: This assumes that every psymbol has a
314 corresponding msymbol, which is not necessarily
315 true; the debug info might be much richer than the
316 object's symbol table. */
317 p
= find_pc_sect_psymbol (objfile
, pst
, pc
, section
);
319 || (p
->address (objfile
)
320 != BMSYMBOL_VALUE_ADDRESS (msymbol
)))
324 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
325 PSYMTABS_ADDRMAP we used has already the best 1-byte
326 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
327 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
336 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
337 which still have no corresponding full SYMTABs read. But it is not
338 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
341 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
342 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
343 debug info type in single OBJFILE. */
345 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
346 if (!pst
->psymtabs_addrmap_supported
347 && pc
>= pst
->text_low (objfile
) && pc
< pst
->text_high (objfile
))
349 struct partial_symtab
*best_pst
;
351 best_pst
= find_pc_sect_psymtab_closer (objfile
, pc
, section
, pst
,
353 if (best_pst
!= NULL
)
360 /* Psymtab version of find_pc_sect_compunit_symtab. See its definition in
361 the definition of quick_symbol_functions in symfile.h. */
363 struct compunit_symtab
*
364 psymbol_functions::find_pc_sect_compunit_symtab
365 (struct objfile
*objfile
,
366 struct bound_minimal_symbol msymbol
,
368 struct obj_section
*section
,
371 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
,
372 m_partial_symtabs
.get (),
377 if (warn_if_readin
&& ps
->readin_p (objfile
))
378 /* Might want to error() here (in case symtab is corrupt and
379 will cause a core dump), but maybe we can successfully
380 continue, so let's not. */
382 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
383 paddress (objfile
->arch (), pc
));
384 psymtab_to_symtab (objfile
, ps
);
385 return ps
->get_compunit_symtab (objfile
);
390 /* Find which partial symbol within a psymtab matches PC and SECTION.
391 Return NULL if none. */
393 static struct partial_symbol
*
394 find_pc_sect_psymbol (struct objfile
*objfile
,
395 struct partial_symtab
*psymtab
, CORE_ADDR pc
,
396 struct obj_section
*section
)
398 struct partial_symbol
*best
= NULL
;
400 const CORE_ADDR textlow
= psymtab
->text_low (objfile
);
402 gdb_assert (psymtab
!= NULL
);
404 /* Cope with programs that start at address 0. */
405 best_pc
= (textlow
!= 0) ? textlow
- 1 : 0;
407 /* Search the global symbols as well as the static symbols, so that
408 find_pc_partial_function doesn't use a minimal symbol and thus
409 cache a bad endaddr. */
410 for (partial_symbol
*p
: psymtab
->global_psymbols
)
412 if (p
->domain
== VAR_DOMAIN
413 && p
->aclass
== LOC_BLOCK
414 && pc
>= p
->address (objfile
)
415 && (p
->address (objfile
) > best_pc
416 || (psymtab
->text_low (objfile
) == 0
417 && best_pc
== 0 && p
->address (objfile
) == 0)))
419 if (section
!= NULL
) /* Match on a specific section. */
421 if (!matching_obj_sections (p
->obj_section (objfile
),
425 best_pc
= p
->address (objfile
);
430 for (partial_symbol
*p
: psymtab
->static_psymbols
)
432 if (p
->domain
== VAR_DOMAIN
433 && p
->aclass
== LOC_BLOCK
434 && pc
>= p
->address (objfile
)
435 && (p
->address (objfile
) > best_pc
436 || (psymtab
->text_low (objfile
) == 0
437 && best_pc
== 0 && p
->address (objfile
) == 0)))
439 if (section
!= NULL
) /* Match on a specific section. */
441 if (!matching_obj_sections (p
->obj_section (objfile
),
445 best_pc
= p
->address (objfile
);
453 /* Psymtab version of lookup_symbol. See its definition in
454 the definition of quick_symbol_functions in symfile.h. */
456 struct compunit_symtab
*
457 psymbol_functions::lookup_symbol (struct objfile
*objfile
,
458 block_enum block_index
, const char *name
,
459 const domain_enum domain
)
461 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
462 struct compunit_symtab
*stab_best
= NULL
;
464 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
466 lookup_name_info psym_lookup_name
= lookup_name
.make_ignore_params ();
468 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
470 if (!ps
->readin_p (objfile
)
471 && lookup_partial_symbol (objfile
, ps
, psym_lookup_name
,
472 psymtab_index
, domain
))
474 struct symbol
*sym
, *with_opaque
= NULL
;
475 struct compunit_symtab
*stab
= psymtab_to_symtab (objfile
, ps
);
476 /* Note: While psymtab_to_symtab can return NULL if the
477 partial symtab is empty, we can assume it won't here
478 because lookup_partial_symbol succeeded. */
479 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
480 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
482 sym
= block_find_symbol (block
, name
, domain
,
483 block_find_non_opaque_type_preferred
,
486 /* Some caution must be observed with overloaded functions
487 and methods, since the index will not contain any overload
488 information (but NAME might contain it). */
491 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
493 if (with_opaque
!= NULL
494 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
497 /* Keep looking through other psymtabs. */
504 /* Psymtab version of lookup_global_symbol_language. See its definition in
505 the definition of quick_symbol_functions in symfile.h. */
508 psymbol_functions::lookup_global_symbol_language (struct objfile
*objfile
,
511 bool *symbol_found_p
)
513 *symbol_found_p
= false;
514 if (objfile
->sf
== NULL
)
515 return language_unknown
;
517 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
519 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
521 struct partial_symbol
*psym
;
522 if (ps
->readin_p (objfile
))
525 psym
= lookup_partial_symbol (objfile
, ps
, lookup_name
, 1, domain
);
528 *symbol_found_p
= true;
529 return psym
->ginfo
.language ();
533 return language_unknown
;
536 /* Returns true if PSYM matches LOOKUP_NAME. */
539 psymbol_name_matches (partial_symbol
*psym
,
540 const lookup_name_info
&lookup_name
)
542 const language_defn
*lang
= language_def (psym
->ginfo
.language ());
543 symbol_name_matcher_ftype
*name_match
544 = lang
->get_symbol_name_matcher (lookup_name
);
545 return name_match (psym
->ginfo
.search_name (), lookup_name
, NULL
);
548 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
549 the global block of PST if GLOBAL, and otherwise the static block.
550 MATCH is the comparison operation that returns true iff MATCH (s,
551 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
552 non-null, the symbols in the block are assumed to be ordered
553 according to it (allowing binary search). It must be compatible
554 with MATCH. Returns the symbol, if found, and otherwise NULL. */
556 static struct partial_symbol
*
557 match_partial_symbol (struct objfile
*objfile
,
558 struct partial_symtab
*pst
, int global
,
559 const lookup_name_info
&name
, domain_enum domain
,
560 symbol_compare_ftype
*ordered_compare
)
562 struct partial_symbol
**start
, **psym
;
563 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
565 ? pst
->global_psymbols
.size ()
566 : pst
->static_psymbols
.size ());
567 int do_linear_search
= 1;
573 &pst
->global_psymbols
[0] :
574 &pst
->static_psymbols
[0]);
576 if (global
&& ordered_compare
) /* Can use a binary search. */
578 do_linear_search
= 0;
580 /* Binary search. This search is guaranteed to end with center
581 pointing at the earliest partial symbol whose name might be
582 correct. At that point *all* partial symbols with an
583 appropriate name will be checked against the correct
587 top
= start
+ length
- 1;
591 center
= bottom
+ (top
- bottom
) / 2;
592 gdb_assert (center
< top
);
594 enum language lang
= (*center
)->ginfo
.language ();
595 const char *lang_ln
= name
.language_lookup_name (lang
);
597 if (ordered_compare ((*center
)->ginfo
.search_name (),
603 gdb_assert (top
== bottom
);
605 while (top
<= real_top
606 && psymbol_name_matches (*top
, name
))
608 if (symbol_matches_domain ((*top
)->ginfo
.language (),
609 (*top
)->domain
, domain
))
615 /* Can't use a binary search or else we found during the binary search that
616 we should also do a linear search. */
618 if (do_linear_search
)
620 for (psym
= start
; psym
< start
+ length
; psym
++)
622 if (symbol_matches_domain ((*psym
)->ginfo
.language (),
623 (*psym
)->domain
, domain
)
624 && psymbol_name_matches (*psym
, name
))
632 /* Look, in partial_symtab PST, for symbol whose natural name is
633 LOOKUP_NAME. Check the global symbols if GLOBAL, the static
636 static struct partial_symbol
*
637 lookup_partial_symbol (struct objfile
*objfile
,
638 struct partial_symtab
*pst
,
639 const lookup_name_info
&lookup_name
,
640 int global
, domain_enum domain
)
642 struct partial_symbol
**start
, **psym
;
643 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
645 ? pst
->global_psymbols
.size ()
646 : pst
->static_psymbols
.size ());
647 int do_linear_search
= 1;
653 &pst
->global_psymbols
[0] :
654 &pst
->static_psymbols
[0]);
656 if (global
) /* This means we can use a binary search. */
658 do_linear_search
= 0;
660 /* Binary search. This search is guaranteed to end with center
661 pointing at the earliest partial symbol whose name might be
662 correct. At that point *all* partial symbols with an
663 appropriate name will be checked against the correct
667 top
= start
+ length
- 1;
671 center
= bottom
+ (top
- bottom
) / 2;
673 gdb_assert (center
< top
);
675 if (strcmp_iw_ordered ((*center
)->ginfo
.search_name (),
676 lookup_name
.c_str ()) >= 0)
686 gdb_assert (top
== bottom
);
688 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
689 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
690 while (top
>= start
&& symbol_matches_search_name (&(*top
)->ginfo
,
694 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
697 while (top
<= real_top
&& symbol_matches_search_name (&(*top
)->ginfo
,
700 if (symbol_matches_domain ((*top
)->ginfo
.language (),
701 (*top
)->domain
, domain
))
707 /* Can't use a binary search or else we found during the binary search that
708 we should also do a linear search. */
710 if (do_linear_search
)
712 for (psym
= start
; psym
< start
+ length
; psym
++)
714 if (symbol_matches_domain ((*psym
)->ginfo
.language (),
715 (*psym
)->domain
, domain
)
716 && symbol_matches_search_name (&(*psym
)->ginfo
, lookup_name
))
724 /* Get the symbol table that corresponds to a partial_symtab.
725 This is fast after the first time you do it.
726 The result will be NULL if the primary symtab has no symbols,
727 which can happen. Otherwise the result is the primary symtab
728 that contains PST. */
730 static struct compunit_symtab
*
731 psymtab_to_symtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
733 /* If it is a shared psymtab, find an unshared psymtab that includes
734 it. Any such psymtab will do. */
735 while (pst
->user
!= NULL
)
738 /* If it's been looked up before, return it. */
739 if (pst
->get_compunit_symtab (objfile
))
740 return pst
->get_compunit_symtab (objfile
);
742 /* If it has not yet been read in, read it. */
743 if (!pst
->readin_p (objfile
))
745 scoped_restore decrementer
= increment_reading_symtab ();
749 printf_filtered (_("Reading in symbols for %s...\n"),
751 gdb_flush (gdb_stdout
);
754 pst
->read_symtab (objfile
);
757 return pst
->get_compunit_symtab (objfile
);
760 /* Psymtab version of find_last_source_symtab. See its definition in
761 the definition of quick_symbol_functions in symfile.h. */
764 psymbol_functions::find_last_source_symtab (struct objfile
*ofp
)
766 struct partial_symtab
*cs_pst
= NULL
;
768 for (partial_symtab
*ps
: require_partial_symbols (ofp
, true))
770 const char *name
= ps
->filename
;
771 int len
= strlen (name
);
773 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
774 || strcmp (name
, "<<C++-namespaces>>") == 0)))
780 if (cs_pst
->readin_p (ofp
))
782 internal_error (__FILE__
, __LINE__
,
783 _("select_source_symtab: "
784 "readin pst found and no symtabs."));
788 struct compunit_symtab
*cust
= psymtab_to_symtab (ofp
, cs_pst
);
792 return compunit_primary_filetab (cust
);
798 /* Psymtab version of forget_cached_source_info. See its definition in
799 the definition of quick_symbol_functions in symfile.h. */
802 psymbol_functions::forget_cached_source_info (struct objfile
*objfile
)
804 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
806 if (pst
->fullname
!= NULL
)
808 xfree (pst
->fullname
);
809 pst
->fullname
= NULL
;
815 print_partial_symbols (struct gdbarch
*gdbarch
, struct objfile
*objfile
,
816 const std::vector
<partial_symbol
*> &symbols
,
817 const char *what
, struct ui_file
*outfile
)
819 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
820 for (partial_symbol
*p
: symbols
)
823 fprintf_filtered (outfile
, " `%s'", p
->ginfo
.linkage_name ());
824 if (p
->ginfo
.demangled_name () != NULL
)
826 fprintf_filtered (outfile
, " `%s'",
827 p
->ginfo
.demangled_name ());
829 fputs_filtered (", ", outfile
);
833 fputs_filtered ("undefined domain, ", outfile
);
836 /* This is the usual thing -- don't print it. */
839 fputs_filtered ("struct domain, ", outfile
);
842 fputs_filtered ("module domain, ", outfile
);
845 fputs_filtered ("label domain, ", outfile
);
847 case COMMON_BLOCK_DOMAIN
:
848 fputs_filtered ("common block domain, ", outfile
);
851 fputs_filtered ("<invalid domain>, ", outfile
);
857 fputs_filtered ("undefined", outfile
);
860 fputs_filtered ("constant int", outfile
);
863 fputs_filtered ("static", outfile
);
866 fputs_filtered ("register", outfile
);
869 fputs_filtered ("pass by value", outfile
);
872 fputs_filtered ("pass by reference", outfile
);
874 case LOC_REGPARM_ADDR
:
875 fputs_filtered ("register address parameter", outfile
);
878 fputs_filtered ("stack parameter", outfile
);
881 fputs_filtered ("type", outfile
);
884 fputs_filtered ("label", outfile
);
887 fputs_filtered ("function", outfile
);
889 case LOC_CONST_BYTES
:
890 fputs_filtered ("constant bytes", outfile
);
893 fputs_filtered ("unresolved", outfile
);
895 case LOC_OPTIMIZED_OUT
:
896 fputs_filtered ("optimized out", outfile
);
899 fputs_filtered ("computed at runtime", outfile
);
902 fputs_filtered ("<invalid location>", outfile
);
905 fputs_filtered (", ", outfile
);
906 fputs_filtered (paddress (gdbarch
, p
->unrelocated_address ()), outfile
);
907 fprintf_filtered (outfile
, "\n");
912 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
913 struct ui_file
*outfile
)
915 struct gdbarch
*gdbarch
= objfile
->arch ();
918 if (psymtab
->anonymous
)
920 fprintf_filtered (outfile
, "\nAnonymous partial symtab (%s) ",
925 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
928 fprintf_filtered (outfile
, "(object ");
929 gdb_print_host_address (psymtab
, outfile
);
930 fprintf_filtered (outfile
, ")\n\n");
931 fprintf_filtered (outfile
, " Read from object file %s (",
932 objfile_name (objfile
));
933 gdb_print_host_address (objfile
, outfile
);
934 fprintf_filtered (outfile
, ")\n");
936 if (psymtab
->readin_p (objfile
))
938 fprintf_filtered (outfile
,
939 " Full symtab was read (at ");
940 gdb_print_host_address (psymtab
->get_compunit_symtab (objfile
), outfile
);
941 fprintf_filtered (outfile
, ")\n");
944 fprintf_filtered (outfile
, " Symbols cover text addresses ");
945 fputs_filtered (paddress (gdbarch
, psymtab
->text_low (objfile
)), outfile
);
946 fprintf_filtered (outfile
, "-");
947 fputs_filtered (paddress (gdbarch
, psymtab
->text_high (objfile
)), outfile
);
948 fprintf_filtered (outfile
, "\n");
949 fprintf_filtered (outfile
, " Address map supported - %s.\n",
950 psymtab
->psymtabs_addrmap_supported
? "yes" : "no");
951 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
952 psymtab
->number_of_dependencies
);
953 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
955 fprintf_filtered (outfile
, " %d ", i
);
956 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
957 fprintf_filtered (outfile
, " %s\n",
958 psymtab
->dependencies
[i
]->filename
);
960 if (psymtab
->user
!= NULL
)
962 fprintf_filtered (outfile
, " Shared partial symtab with user ");
963 gdb_print_host_address (psymtab
->user
, outfile
);
964 fprintf_filtered (outfile
, "\n");
966 if (!psymtab
->global_psymbols
.empty ())
968 print_partial_symbols
969 (gdbarch
, objfile
, psymtab
->global_psymbols
,
972 if (!psymtab
->static_psymbols
.empty ())
974 print_partial_symbols
975 (gdbarch
, objfile
, psymtab
->static_psymbols
,
978 fprintf_filtered (outfile
, "\n");
981 /* Count the number of partial symbols in OBJFILE. */
984 count_psyms (struct objfile
*objfile
)
987 for (partial_symtab
*pst
: objfile
->psymtabs ())
989 count
+= pst
->global_psymbols
.size ();
990 count
+= pst
->static_psymbols
.size ();
995 /* Psymtab version of print_stats. See its definition in
996 the definition of quick_symbol_functions in symfile.h. */
999 psymbol_functions::print_stats (struct objfile
*objfile
, bool print_bcache
)
1005 int n_psyms
= count_psyms (objfile
);
1007 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
1011 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1013 if (!ps
->readin_p (objfile
))
1016 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"),
1018 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
1019 m_partial_symtabs
->psymbol_cache
.memory_used ());
1023 printf_filtered (_("Psymbol byte cache statistics:\n"));
1024 m_partial_symtabs
->psymbol_cache
.print_statistics
1025 ("partial symbol cache");
1029 /* Psymtab version of dump. See its definition in
1030 the definition of quick_symbol_functions in symfile.h. */
1033 psymbol_functions::dump (struct objfile
*objfile
)
1035 struct partial_symtab
*psymtab
;
1037 if (m_partial_symtabs
->psymtabs
)
1039 printf_filtered ("Psymtabs:\n");
1040 for (psymtab
= m_partial_symtabs
->psymtabs
;
1042 psymtab
= psymtab
->next
)
1044 printf_filtered ("%s at ",
1046 gdb_print_host_address (psymtab
, gdb_stdout
);
1047 printf_filtered (", ");
1050 printf_filtered ("\n\n");
1054 /* Psymtab version of expand_symtabs_for_function. See its definition in
1055 the definition of quick_symbol_functions in symfile.h. */
1058 psymbol_functions::expand_symtabs_for_function (struct objfile
*objfile
,
1059 const char *func_name
)
1061 lookup_name_info
base_lookup (func_name
, symbol_name_match_type::FULL
);
1062 lookup_name_info lookup_name
= base_lookup
.make_ignore_params ();
1064 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1066 if (ps
->readin_p (objfile
))
1069 if ((lookup_partial_symbol (objfile
, ps
, lookup_name
, 1, VAR_DOMAIN
)
1071 || (lookup_partial_symbol (objfile
, ps
, lookup_name
, 0, VAR_DOMAIN
)
1073 psymtab_to_symtab (objfile
, ps
);
1077 /* Psymtab version of expand_all_symtabs. See its definition in
1078 the definition of quick_symbol_functions in symfile.h. */
1081 psymbol_functions::expand_all_symtabs (struct objfile
*objfile
)
1083 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
, true))
1084 psymtab_to_symtab (objfile
, psymtab
);
1087 /* Psymtab version of expand_symtabs_with_fullname. See its definition in
1088 the definition of quick_symbol_functions in symfile.h. */
1091 psymbol_functions::expand_symtabs_with_fullname (struct objfile
*objfile
,
1092 const char *fullname
)
1094 for (partial_symtab
*p
: require_partial_symbols (objfile
, true))
1096 /* Anonymous psymtabs don't have a name of a source file. */
1100 /* psymtab_to_fullname tries to open the file which is slow.
1101 Don't call it if we know the basenames don't match. */
1102 if ((basenames_may_differ
1103 || filename_cmp (lbasename (fullname
), lbasename (p
->filename
)) == 0)
1104 && filename_cmp (fullname
, psymtab_to_fullname (p
)) == 0)
1105 psymtab_to_symtab (objfile
, p
);
1109 /* Psymtab version of map_symbol_filenames. See its definition in
1110 the definition of quick_symbol_functions in symfile.h. */
1113 psymbol_functions::map_symbol_filenames (struct objfile
*objfile
,
1114 symbol_filename_ftype
*fun
,
1118 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1120 const char *fullname
;
1122 if (ps
->readin_p (objfile
))
1125 /* We can skip shared psymtabs here, because any file name will be
1126 attached to the unshared psymtab. */
1127 if (ps
->user
!= NULL
)
1130 /* Anonymous psymtabs don't have a file name. */
1136 fullname
= psymtab_to_fullname (ps
);
1139 (*fun
) (ps
->filename
, fullname
, data
);
1143 /* Finds the fullname that a partial_symtab represents.
1145 If this functions finds the fullname, it will save it in ps->fullname
1146 and it will also return the value.
1148 If this function fails to find the file that this partial_symtab represents,
1149 NULL will be returned and ps->fullname will be set to NULL. */
1152 psymtab_to_fullname (struct partial_symtab
*ps
)
1154 gdb_assert (!ps
->anonymous
);
1156 /* Use cached copy if we have it.
1157 We rely on forget_cached_source_info being called appropriately
1158 to handle cases like the file being moved. */
1159 if (ps
->fullname
== NULL
)
1161 gdb::unique_xmalloc_ptr
<char> fullname
;
1162 scoped_fd fd
= find_and_open_source (ps
->filename
, ps
->dirname
,
1164 ps
->fullname
= fullname
.release ();
1168 /* rewrite_source_path would be applied by find_and_open_source, we
1169 should report the pathname where GDB tried to find the file. */
1171 if (ps
->dirname
== NULL
|| IS_ABSOLUTE_PATH (ps
->filename
))
1172 fullname
.reset (xstrdup (ps
->filename
));
1174 fullname
.reset (concat (ps
->dirname
, SLASH_STRING
,
1175 ps
->filename
, (char *) NULL
));
1177 ps
->fullname
= rewrite_source_path (fullname
.get ()).release ();
1178 if (ps
->fullname
== NULL
)
1179 ps
->fullname
= fullname
.release ();
1183 return ps
->fullname
;
1186 /* Psymtab version of map_matching_symbols. See its definition in
1187 the definition of quick_symbol_functions in symfile.h. */
1190 psymbol_functions::map_matching_symbols
1191 (struct objfile
*objfile
,
1192 const lookup_name_info
&name
, domain_enum domain
,
1194 gdb::function_view
<symbol_found_callback_ftype
> callback
,
1195 symbol_compare_ftype
*ordered_compare
)
1197 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
1199 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1202 if (ps
->readin_p (objfile
)
1203 || match_partial_symbol (objfile
, ps
, global
, name
, domain
,
1206 struct compunit_symtab
*cust
= psymtab_to_symtab (objfile
, ps
);
1207 const struct block
*block
;
1211 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
1212 if (!iterate_over_symbols_terminated (block
, name
,
1219 /* A helper for psym_expand_symtabs_matching that handles searching
1220 included psymtabs. This returns true if a symbol is found, and
1221 false otherwise. It also updates the 'searched_flag' on the
1222 various psymtabs that it searches. */
1225 recursively_search_psymtabs
1226 (struct partial_symtab
*ps
,
1227 struct objfile
*objfile
,
1228 enum search_domain domain
,
1229 const lookup_name_info
&lookup_name
,
1230 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> sym_matcher
)
1233 enum psymtab_search_status result
= PST_SEARCHED_AND_NOT_FOUND
;
1236 if (ps
->searched_flag
!= PST_NOT_SEARCHED
)
1237 return ps
->searched_flag
== PST_SEARCHED_AND_FOUND
;
1239 /* Recurse into shared psymtabs first, because they may have already
1240 been searched, and this could save some time. */
1241 for (i
= 0; i
< ps
->number_of_dependencies
; ++i
)
1245 /* Skip non-shared dependencies, these are handled elsewhere. */
1246 if (ps
->dependencies
[i
]->user
== NULL
)
1249 r
= recursively_search_psymtabs (ps
->dependencies
[i
],
1250 objfile
, domain
, lookup_name
,
1254 ps
->searched_flag
= PST_SEARCHED_AND_FOUND
;
1259 partial_symbol
**gbound
= (ps
->global_psymbols
.data ()
1260 + ps
->global_psymbols
.size ());
1261 partial_symbol
**sbound
= (ps
->static_psymbols
.data ()
1262 + ps
->static_psymbols
.size ());
1263 partial_symbol
**bound
= gbound
;
1265 /* Go through all of the symbols stored in a partial
1266 symtab in one loop. */
1267 partial_symbol
**psym
= ps
->global_psymbols
.data ();
1272 if (bound
== gbound
&& !ps
->static_psymbols
.empty ())
1274 psym
= ps
->static_psymbols
.data ();
1285 if ((domain
== ALL_DOMAIN
1286 || (domain
== MODULES_DOMAIN
1287 && (*psym
)->domain
== MODULE_DOMAIN
)
1288 || (domain
== VARIABLES_DOMAIN
1289 && (*psym
)->aclass
!= LOC_TYPEDEF
1290 && (*psym
)->aclass
!= LOC_BLOCK
)
1291 || (domain
== FUNCTIONS_DOMAIN
1292 && (*psym
)->aclass
== LOC_BLOCK
)
1293 || (domain
== TYPES_DOMAIN
1294 && (*psym
)->aclass
== LOC_TYPEDEF
))
1295 && psymbol_name_matches (*psym
, lookup_name
)
1296 && (sym_matcher
== NULL
1297 || sym_matcher ((*psym
)->ginfo
.search_name ())))
1299 /* Found a match, so notify our caller. */
1300 result
= PST_SEARCHED_AND_FOUND
;
1307 ps
->searched_flag
= result
;
1308 return result
== PST_SEARCHED_AND_FOUND
;
1311 /* Psymtab version of expand_symtabs_matching. See its definition in
1312 the definition of quick_symbol_functions in symfile.h. */
1315 psymbol_functions::expand_symtabs_matching
1316 (struct objfile
*objfile
,
1317 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
1318 const lookup_name_info
*lookup_name
,
1319 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
1320 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
1321 enum search_domain domain
)
1323 /* Clear the search flags. */
1324 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1325 ps
->searched_flag
= PST_NOT_SEARCHED
;
1327 for (partial_symtab
*ps
: m_partial_symtabs
->range ())
1331 if (ps
->readin_p (objfile
))
1334 /* We skip shared psymtabs because file-matching doesn't apply
1335 to them; but we search them later in the loop. */
1336 if (ps
->user
!= NULL
)
1346 match
= file_matcher (ps
->filename
, false);
1349 /* Before we invoke realpath, which can get expensive when many
1350 files are involved, do a quick comparison of the basenames. */
1351 if (basenames_may_differ
1352 || file_matcher (lbasename (ps
->filename
), true))
1353 match
= file_matcher (psymtab_to_fullname (ps
), false);
1359 if ((symbol_matcher
== NULL
&& lookup_name
== NULL
)
1360 || recursively_search_psymtabs (ps
, objfile
, domain
,
1361 lookup_name
->make_ignore_params (),
1364 struct compunit_symtab
*symtab
=
1365 psymtab_to_symtab (objfile
, ps
);
1367 if (expansion_notify
!= NULL
)
1368 expansion_notify (symtab
);
1373 /* Psymtab version of has_symbols. See its definition in
1374 the definition of quick_symbol_functions in symfile.h. */
1377 psymbol_functions::has_symbols (struct objfile
*objfile
)
1379 return m_partial_symtabs
->psymtabs
!= NULL
;
1382 /* Helper function for psym_find_compunit_symtab_by_address that fills
1383 in m_psymbol_map for a given range of psymbols. */
1386 psymbol_functions::fill_psymbol_map
1387 (struct objfile
*objfile
,
1388 struct partial_symtab
*psymtab
,
1389 std::set
<CORE_ADDR
> *seen_addrs
,
1390 const std::vector
<partial_symbol
*> &symbols
)
1392 for (partial_symbol
*psym
: symbols
)
1394 if (psym
->aclass
== LOC_STATIC
)
1396 CORE_ADDR addr
= psym
->address (objfile
);
1397 if (seen_addrs
->find (addr
) == seen_addrs
->end ())
1399 seen_addrs
->insert (addr
);
1400 m_psymbol_map
.emplace_back (addr
, psymtab
);
1406 /* See find_compunit_symtab_by_address in quick_symbol_functions, in
1410 psymbol_functions::find_compunit_symtab_by_address (struct objfile
*objfile
,
1413 if (m_psymbol_map
.empty ())
1415 std::set
<CORE_ADDR
> seen_addrs
;
1417 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
1419 fill_psymbol_map (objfile
, pst
,
1421 pst
->global_psymbols
);
1422 fill_psymbol_map (objfile
, pst
,
1424 pst
->static_psymbols
);
1427 m_psymbol_map
.shrink_to_fit ();
1429 std::sort (m_psymbol_map
.begin (), m_psymbol_map
.end (),
1430 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1431 const std::pair
<CORE_ADDR
, partial_symtab
*> &b
)
1433 return a
.first
< b
.first
;
1437 auto iter
= std::lower_bound
1438 (m_psymbol_map
.begin (), m_psymbol_map
.end (), address
,
1439 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1445 if (iter
== m_psymbol_map
.end () || iter
->first
!= address
)
1448 return psymtab_to_symtab (objfile
, iter
->second
);
1451 quick_symbol_functions_up
1452 make_psymbol_functions (const std::shared_ptr
<psymtab_storage
> &storage
)
1454 return quick_symbol_functions_up (new psymbol_functions (storage
));
1459 /* Partially fill a partial symtab. It will be completely filled at
1460 the end of the symbol list. */
1462 partial_symtab::partial_symtab (const char *filename
,
1463 struct objfile
*objfile
,
1465 : partial_symtab (filename
, objfile
)
1467 set_text_low (textlow
);
1468 set_text_high (raw_text_low ()); /* default */
1471 /* Perform "finishing up" operations of a partial symtab. */
1474 partial_symtab::end ()
1476 global_psymbols
.shrink_to_fit ();
1477 static_psymbols
.shrink_to_fit ();
1479 /* Sort the global list; don't sort the static list. */
1480 std::sort (global_psymbols
.begin (),
1481 global_psymbols
.end (),
1482 [] (partial_symbol
*s1
, partial_symbol
*s2
)
1484 return strcmp_iw_ordered (s1
->ginfo
.search_name (),
1485 s2
->ginfo
.search_name ()) < 0;
1489 /* See psymtab.h. */
1492 psymbol_bcache::hash (const void *addr
, int length
)
1494 unsigned long h
= 0;
1495 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1496 unsigned int lang
= psymbol
->ginfo
.language ();
1497 unsigned int domain
= psymbol
->domain
;
1498 unsigned int theclass
= psymbol
->aclass
;
1500 h
= fast_hash (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1501 h
= fast_hash (&lang
, sizeof (unsigned int), h
);
1502 h
= fast_hash (&domain
, sizeof (unsigned int), h
);
1503 h
= fast_hash (&theclass
, sizeof (unsigned int), h
);
1504 /* Note that psymbol names are interned via compute_and_set_names, so
1505 there's no need to hash the contents of the name here. */
1506 h
= fast_hash (&psymbol
->ginfo
.m_name
, sizeof (psymbol
->ginfo
.m_name
), h
);
1511 /* See psymtab.h. */
1514 psymbol_bcache::compare (const void *addr1
, const void *addr2
, int length
)
1516 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1517 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1519 return (memcmp (&sym1
->ginfo
.value
, &sym2
->ginfo
.value
,
1520 sizeof (sym1
->ginfo
.value
)) == 0
1521 && sym1
->ginfo
.language () == sym2
->ginfo
.language ()
1522 && sym1
->domain
== sym2
->domain
1523 && sym1
->aclass
== sym2
->aclass
1524 /* Note that psymbol names are interned via
1525 compute_and_set_names, so there's no need to compare the
1526 contents of the name here. */
1527 && sym1
->ginfo
.linkage_name () == sym2
->ginfo
.linkage_name ());
1530 /* Helper function, initialises partial symbol structure and stashes
1531 it into objfile's bcache. Note that our caching mechanism will
1532 use all fields of struct partial_symbol to determine hash value of the
1533 structure. In other words, having two symbols with the same name but
1534 different domain (or address) is possible and correct. */
1536 static struct partial_symbol
*
1537 add_psymbol_to_bcache (const partial_symbol
&psymbol
, struct objfile
*objfile
,
1540 /* Stash the partial symbol away in the cache. */
1541 return ((struct partial_symbol
*)
1542 objfile
->partial_symtabs
->psymbol_cache
.insert
1543 (&psymbol
, sizeof (struct partial_symbol
), added
));
1546 /* See psympriv.h. */
1549 partial_symtab::add_psymbol (const partial_symbol
&psymbol
,
1550 psymbol_placement where
,
1551 struct objfile
*objfile
)
1555 /* Stash the partial symbol away in the cache. */
1556 partial_symbol
*psym
= add_psymbol_to_bcache (psymbol
, objfile
, &added
);
1558 /* Do not duplicate global partial symbols. */
1559 if (where
== psymbol_placement::GLOBAL
&& !added
)
1562 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1563 std::vector
<partial_symbol
*> &list
1564 = (where
== psymbol_placement::STATIC
1567 list
.push_back (psym
);
1570 /* See psympriv.h. */
1573 partial_symtab::add_psymbol (gdb::string_view name
, bool copy_name
,
1575 enum address_class theclass
,
1577 psymbol_placement where
,
1579 enum language language
, struct objfile
*objfile
)
1581 struct partial_symbol psymbol
;
1582 memset (&psymbol
, 0, sizeof (psymbol
));
1584 psymbol
.set_unrelocated_address (coreaddr
);
1585 psymbol
.ginfo
.set_section_index (section
);
1586 psymbol
.domain
= domain
;
1587 psymbol
.aclass
= theclass
;
1588 psymbol
.ginfo
.set_language (language
, objfile
->partial_symtabs
->obstack ());
1589 psymbol
.ginfo
.compute_and_set_names (name
, copy_name
, objfile
->per_bfd
);
1591 add_psymbol (psymbol
, where
, objfile
);
1594 /* See psympriv.h. */
1596 partial_symtab::partial_symtab (const char *filename_
, struct objfile
*objfile
)
1597 : searched_flag (PST_NOT_SEARCHED
),
1601 objfile
->partial_symtabs
->install_psymtab (this);
1603 filename
= objfile
->intern (filename_
);
1605 if (symtab_create_debug
)
1607 /* Be a bit clever with debugging messages, and don't print objfile
1608 every time, only when it changes. */
1609 static char *last_objfile_name
= NULL
;
1611 if (last_objfile_name
== NULL
1612 || strcmp (last_objfile_name
, objfile_name (objfile
)) != 0)
1614 xfree (last_objfile_name
);
1615 last_objfile_name
= xstrdup (objfile_name (objfile
));
1616 fprintf_filtered (gdb_stdlog
,
1617 "Creating one or more psymtabs for objfile %s ...\n",
1620 fprintf_filtered (gdb_stdlog
,
1621 "Created psymtab %s for module %s.\n",
1622 host_address_to_string (this), filename
);
1626 /* See psympriv.h. */
1629 partial_symtab::expand_dependencies (struct objfile
*objfile
)
1631 for (int i
= 0; i
< number_of_dependencies
; ++i
)
1633 if (!dependencies
[i
]->readin_p (objfile
)
1634 && dependencies
[i
]->user
== NULL
)
1636 /* Inform about additional files to be read in. */
1639 fputs_filtered (" ", gdb_stdout
);
1641 fputs_filtered ("and ", gdb_stdout
);
1643 printf_filtered ("%s...", dependencies
[i
]->filename
);
1644 wrap_here (""); /* Flush output */
1645 gdb_flush (gdb_stdout
);
1647 dependencies
[i
]->expand_psymtab (objfile
);
1654 psymtab_storage::discard_psymtab (struct partial_symtab
*pst
)
1656 struct partial_symtab
**prev_pst
;
1659 Empty psymtabs happen as a result of header files which don't
1660 have any symbols in them. There can be a lot of them. But this
1661 check is wrong, in that a psymtab with N_SLINE entries but
1662 nothing else is not empty, but we don't realize that. Fixing
1663 that without slowing things down might be tricky. */
1665 /* First, snip it out of the psymtab chain. */
1667 prev_pst
= &psymtabs
;
1668 while ((*prev_pst
) != pst
)
1669 prev_pst
= &((*prev_pst
)->next
);
1670 (*prev_pst
) = pst
->next
;
1676 /* We need to pass a couple of items to the addrmap_foreach function,
1679 struct dump_psymtab_addrmap_data
1681 struct objfile
*objfile
;
1682 struct partial_symtab
*psymtab
;
1683 struct ui_file
*outfile
;
1685 /* Non-zero if the previously printed addrmap entry was for PSYMTAB.
1686 If so, we want to print the next one as well (since the next addrmap
1687 entry defines the end of the range). */
1688 int previous_matched
;
1691 /* Helper function for dump_psymtab_addrmap to print an addrmap entry. */
1694 dump_psymtab_addrmap_1 (void *datap
, CORE_ADDR start_addr
, void *obj
)
1696 struct dump_psymtab_addrmap_data
*data
1697 = (struct dump_psymtab_addrmap_data
*) datap
;
1698 struct gdbarch
*gdbarch
= data
->objfile
->arch ();
1699 struct partial_symtab
*addrmap_psymtab
= (struct partial_symtab
*) obj
;
1700 const char *psymtab_address_or_end
= NULL
;
1704 if (data
->psymtab
== NULL
1705 || data
->psymtab
== addrmap_psymtab
)
1706 psymtab_address_or_end
= host_address_to_string (addrmap_psymtab
);
1707 else if (data
->previous_matched
)
1708 psymtab_address_or_end
= "<ends here>";
1710 if (data
->psymtab
== NULL
1711 || data
->psymtab
== addrmap_psymtab
1712 || data
->previous_matched
)
1714 fprintf_filtered (data
->outfile
, " %s%s %s\n",
1715 data
->psymtab
!= NULL
? " " : "",
1716 paddress (gdbarch
, start_addr
),
1717 psymtab_address_or_end
);
1720 data
->previous_matched
= (data
->psymtab
== NULL
1721 || data
->psymtab
== addrmap_psymtab
);
1726 /* Helper function for maintenance_print_psymbols to print the addrmap
1727 of PSYMTAB. If PSYMTAB is NULL print the entire addrmap. */
1730 dump_psymtab_addrmap (struct objfile
*objfile
,
1731 psymtab_storage
*partial_symtabs
,
1732 struct partial_symtab
*psymtab
,
1733 struct ui_file
*outfile
)
1735 struct dump_psymtab_addrmap_data addrmap_dump_data
;
1737 if ((psymtab
== NULL
1738 || psymtab
->psymtabs_addrmap_supported
)
1739 && partial_symtabs
->psymtabs_addrmap
!= NULL
)
1741 addrmap_dump_data
.objfile
= objfile
;
1742 addrmap_dump_data
.psymtab
= psymtab
;
1743 addrmap_dump_data
.outfile
= outfile
;
1744 addrmap_dump_data
.previous_matched
= 0;
1745 fprintf_filtered (outfile
, "%sddress map:\n",
1746 psymtab
== NULL
? "Entire a" : " A");
1747 addrmap_foreach (partial_symtabs
->psymtabs_addrmap
,
1748 dump_psymtab_addrmap_1
, &addrmap_dump_data
);
1753 maintenance_print_psymbols (const char *args
, int from_tty
)
1755 struct ui_file
*outfile
= gdb_stdout
;
1756 char *address_arg
= NULL
, *source_arg
= NULL
, *objfile_arg
= NULL
;
1757 int i
, outfile_idx
, found
;
1759 struct obj_section
*section
= NULL
;
1763 gdb_argv
argv (args
);
1765 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
1767 if (strcmp (argv
[i
], "-pc") == 0)
1769 if (argv
[i
+ 1] == NULL
)
1770 error (_("Missing pc value"));
1771 address_arg
= argv
[++i
];
1773 else if (strcmp (argv
[i
], "-source") == 0)
1775 if (argv
[i
+ 1] == NULL
)
1776 error (_("Missing source file"));
1777 source_arg
= argv
[++i
];
1779 else if (strcmp (argv
[i
], "-objfile") == 0)
1781 if (argv
[i
+ 1] == NULL
)
1782 error (_("Missing objfile name"));
1783 objfile_arg
= argv
[++i
];
1785 else if (strcmp (argv
[i
], "--") == 0)
1787 /* End of options. */
1791 else if (argv
[i
][0] == '-')
1793 /* Future proofing: Don't allow OUTFILE to begin with "-". */
1794 error (_("Unknown option: %s"), argv
[i
]);
1801 if (address_arg
!= NULL
&& source_arg
!= NULL
)
1802 error (_("Must specify at most one of -pc and -source"));
1804 stdio_file arg_outfile
;
1806 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
1808 if (argv
[outfile_idx
+ 1] != NULL
)
1809 error (_("Junk at end of command"));
1810 gdb::unique_xmalloc_ptr
<char> outfile_name
1811 (tilde_expand (argv
[outfile_idx
]));
1812 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
1813 perror_with_name (outfile_name
.get ());
1814 outfile
= &arg_outfile
;
1817 if (address_arg
!= NULL
)
1819 pc
= parse_and_eval_address (address_arg
);
1820 /* If we fail to find a section, that's ok, try the lookup anyway. */
1821 section
= find_pc_section (pc
);
1825 for (objfile
*objfile
: current_program_space
->objfiles ())
1827 int printed_objfile_header
= 0;
1828 int print_for_objfile
= 1;
1831 if (objfile_arg
!= NULL
)
1833 = compare_filenames_for_search (objfile_name (objfile
),
1835 if (!print_for_objfile
)
1838 psymtab_storage
*partial_symtabs
= objfile
->partial_symtabs
.get ();
1840 if (address_arg
!= NULL
)
1842 struct bound_minimal_symbol msymbol
= { NULL
, NULL
};
1844 /* We don't assume each pc has a unique objfile (this is for
1846 struct partial_symtab
*ps
1847 = find_pc_sect_psymtab (objfile
, partial_symtabs
, pc
,
1851 if (!printed_objfile_header
)
1853 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1854 objfile_name (objfile
));
1855 printed_objfile_header
= 1;
1857 dump_psymtab (objfile
, ps
, outfile
);
1858 dump_psymtab_addrmap (objfile
, partial_symtabs
, ps
, outfile
);
1864 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1866 int print_for_source
= 0;
1869 if (source_arg
!= NULL
)
1872 = compare_filenames_for_search (ps
->filename
, source_arg
);
1875 if (source_arg
== NULL
1876 || print_for_source
)
1878 if (!printed_objfile_header
)
1880 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1881 objfile_name (objfile
));
1882 printed_objfile_header
= 1;
1884 dump_psymtab (objfile
, ps
, outfile
);
1885 dump_psymtab_addrmap (objfile
, partial_symtabs
, ps
,
1891 /* If we're printing all the objfile's symbols dump the full addrmap. */
1893 if (address_arg
== NULL
1894 && source_arg
== NULL
1895 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
1897 outfile
->puts ("\n");
1898 dump_psymtab_addrmap (objfile
, partial_symtabs
, NULL
, outfile
);
1904 if (address_arg
!= NULL
)
1905 error (_("No partial symtab for address: %s"), address_arg
);
1906 if (source_arg
!= NULL
)
1907 error (_("No partial symtab for source file: %s"), source_arg
);
1911 /* List all the partial symbol tables whose names match REGEXP (optional). */
1914 maintenance_info_psymtabs (const char *regexp
, int from_tty
)
1919 for (struct program_space
*pspace
: program_spaces
)
1920 for (objfile
*objfile
: pspace
->objfiles ())
1922 struct gdbarch
*gdbarch
= objfile
->arch ();
1924 /* We don't want to print anything for this objfile until we
1925 actually find a symtab whose name matches. */
1926 int printed_objfile_start
= 0;
1928 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
, true))
1933 || re_exec (psymtab
->filename
))
1935 if (! printed_objfile_start
)
1937 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
1939 printf_filtered ("((struct objfile *) %s)\n",
1940 host_address_to_string (objfile
));
1941 printed_objfile_start
= 1;
1944 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1946 printf_filtered ("((struct partial_symtab *) %s)\n",
1947 host_address_to_string (psymtab
));
1949 printf_filtered (" readin %s\n",
1950 psymtab
->readin_p (objfile
) ? "yes" : "no");
1951 printf_filtered (" fullname %s\n",
1953 ? psymtab
->fullname
: "(null)");
1954 printf_filtered (" text addresses ");
1955 fputs_filtered (paddress (gdbarch
,
1956 psymtab
->text_low (objfile
)),
1958 printf_filtered (" -- ");
1959 fputs_filtered (paddress (gdbarch
,
1960 psymtab
->text_high (objfile
)),
1962 printf_filtered ("\n");
1963 printf_filtered (" psymtabs_addrmap_supported %s\n",
1964 (psymtab
->psymtabs_addrmap_supported
1966 printf_filtered (" globals ");
1967 if (!psymtab
->global_psymbols
.empty ())
1969 ("(* (struct partial_symbol **) %s @ %d)\n",
1970 host_address_to_string (psymtab
->global_psymbols
.data ()),
1971 (int) psymtab
->global_psymbols
.size ());
1973 printf_filtered ("(none)\n");
1974 printf_filtered (" statics ");
1975 if (!psymtab
->static_psymbols
.empty ())
1977 ("(* (struct partial_symbol **) %s @ %d)\n",
1978 host_address_to_string (psymtab
->static_psymbols
.data ()),
1979 (int) psymtab
->static_psymbols
.size ());
1981 printf_filtered ("(none)\n");
1983 printf_filtered (" user %s "
1984 "((struct partial_symtab *) %s)\n",
1985 psymtab
->user
->filename
,
1986 host_address_to_string (psymtab
->user
));
1987 printf_filtered (" dependencies ");
1988 if (psymtab
->number_of_dependencies
)
1992 printf_filtered ("{\n");
1993 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1995 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
1997 /* Note the string concatenation there --- no
1999 printf_filtered (" psymtab %s "
2000 "((struct partial_symtab *) %s)\n",
2002 host_address_to_string (dep
));
2004 printf_filtered (" }\n");
2007 printf_filtered ("(none)\n");
2008 printf_filtered (" }\n");
2012 if (printed_objfile_start
)
2013 printf_filtered ("}\n");
2017 /* Check consistency of currently expanded psymtabs vs symtabs. */
2020 maintenance_check_psymtabs (const char *ignore
, int from_tty
)
2023 struct compunit_symtab
*cust
= NULL
;
2024 const struct blockvector
*bv
;
2025 const struct block
*b
;
2027 for (objfile
*objfile
: current_program_space
->objfiles ())
2028 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
2030 struct gdbarch
*gdbarch
= objfile
->arch ();
2032 /* We don't call psymtab_to_symtab here because that may cause symtab
2033 expansion. When debugging a problem it helps if checkers leave
2034 things unchanged. */
2035 cust
= ps
->get_compunit_symtab (objfile
);
2037 /* First do some checks that don't require the associated symtab. */
2038 if (ps
->text_high (objfile
) < ps
->text_low (objfile
))
2040 printf_filtered ("Psymtab ");
2041 puts_filtered (ps
->filename
);
2042 printf_filtered (" covers bad range ");
2043 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
2045 printf_filtered (" - ");
2046 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
2048 printf_filtered ("\n");
2052 /* Now do checks requiring the associated symtab. */
2055 bv
= COMPUNIT_BLOCKVECTOR (cust
);
2056 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
2057 for (partial_symbol
*psym
: ps
->static_psymbols
)
2059 /* Skip symbols for inlined functions without address. These may
2060 or may not have a match in the full symtab. */
2061 if (psym
->aclass
== LOC_BLOCK
2062 && psym
->ginfo
.value
.address
== 0)
2065 sym
= block_lookup_symbol (b
, psym
->ginfo
.search_name (),
2066 symbol_name_match_type::SEARCH_NAME
,
2070 printf_filtered ("Static symbol `");
2071 puts_filtered (psym
->ginfo
.linkage_name ());
2072 printf_filtered ("' only found in ");
2073 puts_filtered (ps
->filename
);
2074 printf_filtered (" psymtab\n");
2077 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2078 for (partial_symbol
*psym
: ps
->global_psymbols
)
2080 sym
= block_lookup_symbol (b
, psym
->ginfo
.search_name (),
2081 symbol_name_match_type::SEARCH_NAME
,
2085 printf_filtered ("Global symbol `");
2086 puts_filtered (psym
->ginfo
.linkage_name ());
2087 printf_filtered ("' only found in ");
2088 puts_filtered (ps
->filename
);
2089 printf_filtered (" psymtab\n");
2092 if (ps
->raw_text_high () != 0
2093 && (ps
->text_low (objfile
) < BLOCK_START (b
)
2094 || ps
->text_high (objfile
) > BLOCK_END (b
)))
2096 printf_filtered ("Psymtab ");
2097 puts_filtered (ps
->filename
);
2098 printf_filtered (" covers ");
2099 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
2101 printf_filtered (" - ");
2102 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
2104 printf_filtered (" but symtab covers only ");
2105 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
2106 printf_filtered (" - ");
2107 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
2108 printf_filtered ("\n");
2113 void _initialize_psymtab ();
2115 _initialize_psymtab ()
2117 add_cmd ("psymbols", class_maintenance
, maintenance_print_psymbols
, _("\
2118 Print dump of current partial symbol definitions.\n\
2119 Usage: mt print psymbols [-objfile OBJFILE] [-pc ADDRESS] [--] [OUTFILE]\n\
2120 mt print psymbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
2121 Entries in the partial symbol table are dumped to file OUTFILE,\n\
2122 or the terminal if OUTFILE is unspecified.\n\
2123 If ADDRESS is provided, dump only the file for that address.\n\
2124 If SOURCE is provided, dump only that file's symbols.\n\
2125 If OBJFILE is provided, dump only that file's minimal symbols."),
2126 &maintenanceprintlist
);
2128 add_cmd ("psymtabs", class_maintenance
, maintenance_info_psymtabs
, _("\
2129 List the partial symbol tables for all object files.\n\
2130 This does not include information about individual partial symbols,\n\
2131 just the symbol table structures themselves."),
2132 &maintenanceinfolist
);
2134 add_cmd ("check-psymtabs", class_maintenance
, maintenance_check_psymtabs
,
2136 Check consistency of currently expanded psymtabs versus symtabs."),