1 /* Partial symbol tables.
3 Copyright (C) 2009-2019 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/readline.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
*,
45 static const char *psymtab_to_fullname (struct partial_symtab
*ps
);
47 static struct partial_symbol
*find_pc_sect_psymbol (struct objfile
*,
48 struct partial_symtab
*,
50 struct obj_section
*);
52 static struct compunit_symtab
*psymtab_to_symtab (struct objfile
*objfile
,
53 struct partial_symtab
*pst
);
57 static unsigned long psymbol_hash (const void *addr
, int length
);
58 static int psymbol_compare (const void *addr1
, const void *addr2
, int length
);
60 psymtab_storage::psymtab_storage ()
61 : psymbol_cache (psymbol_hash
, psymbol_compare
)
65 psymtab_storage::~psymtab_storage ()
71 struct partial_symtab
*
72 psymtab_storage::allocate_psymtab ()
74 struct partial_symtab
*psymtab
;
76 if (free_psymtabs
!= nullptr)
78 psymtab
= free_psymtabs
;
79 free_psymtabs
= psymtab
->next
;
82 psymtab
= XOBNEW (obstack (), struct partial_symtab
);
84 memset (psymtab
, 0, sizeof (struct partial_symtab
));
86 psymtab
->next
= psymtabs
;
96 psymtab_storage::partial_symtab_range
97 require_partial_symbols (struct objfile
*objfile
, int verbose
)
99 if ((objfile
->flags
& OBJF_PSYMTABS_READ
) == 0)
101 objfile
->flags
|= OBJF_PSYMTABS_READ
;
103 if (objfile
->sf
->sym_read_psymbols
)
106 printf_filtered (_("Reading symbols from %s...\n"),
107 objfile_name (objfile
));
108 (*objfile
->sf
->sym_read_psymbols
) (objfile
);
110 /* Partial symbols list are not expected to changed after this
112 objfile
->partial_symtabs
->global_psymbols
.shrink_to_fit ();
113 objfile
->partial_symtabs
->static_psymbols
.shrink_to_fit ();
115 if (verbose
&& !objfile_has_symbols (objfile
))
116 printf_filtered (_("(No debugging symbols found in %s)\n"),
117 objfile_name (objfile
));
121 return objfile
->psymtabs ();
124 /* Helper function for psym_map_symtabs_matching_filename that
125 expands the symtabs and calls the iterator. */
128 partial_map_expand_apply (struct objfile
*objfile
,
130 const char *real_path
,
131 struct partial_symtab
*pst
,
132 gdb::function_view
<bool (symtab
*)> callback
)
134 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
136 /* Shared psymtabs should never be seen here. Instead they should
137 be handled properly by the caller. */
138 gdb_assert (pst
->user
== NULL
);
140 /* Don't visit already-expanded psymtabs. */
144 /* This may expand more than one symtab, and we want to iterate over
146 psymtab_to_symtab (objfile
, pst
);
148 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
149 last_made
, callback
);
152 /* Psymtab version of map_symtabs_matching_filename. See its definition in
153 the definition of quick_symbol_functions in symfile.h. */
156 psym_map_symtabs_matching_filename
157 (struct objfile
*objfile
,
159 const char *real_path
,
160 gdb::function_view
<bool (symtab
*)> callback
)
162 const char *name_basename
= lbasename (name
);
164 for (partial_symtab
*pst
: require_partial_symbols (objfile
, 1))
166 /* We can skip shared psymtabs here, because any file name will be
167 attached to the unshared psymtab. */
168 if (pst
->user
!= NULL
)
171 /* Anonymous psymtabs don't have a file name. */
175 if (compare_filenames_for_search (pst
->filename
, name
))
177 if (partial_map_expand_apply (objfile
, name
, real_path
,
183 /* Before we invoke realpath, which can get expensive when many
184 files are involved, do a quick comparison of the basenames. */
185 if (! basenames_may_differ
186 && FILENAME_CMP (name_basename
, lbasename (pst
->filename
)) != 0)
189 if (compare_filenames_for_search (psymtab_to_fullname (pst
), name
))
191 if (partial_map_expand_apply (objfile
, name
, real_path
,
197 /* If the user gave us an absolute path, try to find the file in
198 this symtab and use its absolute path. */
199 if (real_path
!= NULL
)
201 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
202 gdb_assert (IS_ABSOLUTE_PATH (name
));
203 if (filename_cmp (psymtab_to_fullname (pst
), real_path
) == 0)
205 if (partial_map_expand_apply (objfile
, name
, real_path
,
216 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
217 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
219 static struct partial_symtab
*
220 find_pc_sect_psymtab_closer (struct objfile
*objfile
,
221 CORE_ADDR pc
, struct obj_section
*section
,
222 struct partial_symtab
*pst
,
223 struct bound_minimal_symbol msymbol
)
225 struct partial_symtab
*tpst
;
226 struct partial_symtab
*best_pst
= pst
;
227 CORE_ADDR best_addr
= pst
->text_low (objfile
);
229 gdb_assert (!pst
->psymtabs_addrmap_supported
);
231 /* An objfile that has its functions reordered might have
232 many partial symbol tables containing the PC, but
233 we want the partial symbol table that contains the
234 function containing the PC. */
235 if (!(objfile
->flags
& OBJF_REORDERED
)
236 && section
== NULL
) /* Can't validate section this way. */
239 if (msymbol
.minsym
== NULL
)
242 /* The code range of partial symtabs sometimes overlap, so, in
243 the loop below, we need to check all partial symtabs and
244 find the one that fits better for the given PC address. We
245 select the partial symtab that contains a symbol whose
246 address is closest to the PC address. By closest we mean
247 that find_pc_sect_symbol returns the symbol with address
248 that is closest and still less than the given PC. */
249 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
251 if (pc
>= tpst
->text_low (objfile
) && pc
< tpst
->text_high (objfile
))
253 struct partial_symbol
*p
;
256 /* NOTE: This assumes that every psymbol has a
257 corresponding msymbol, which is not necessarily
258 true; the debug info might be much richer than the
259 object's symbol table. */
260 p
= find_pc_sect_psymbol (objfile
, tpst
, pc
, section
);
262 && (p
->address (objfile
) == BMSYMBOL_VALUE_ADDRESS (msymbol
)))
265 /* Also accept the textlow value of a psymtab as a
266 "symbol", to provide some support for partial
267 symbol tables with line information but no debug
268 symbols (e.g. those produced by an assembler). */
270 this_addr
= p
->address (objfile
);
272 this_addr
= tpst
->text_low (objfile
);
274 /* Check whether it is closer than our current
275 BEST_ADDR. Since this symbol address is
276 necessarily lower or equal to PC, the symbol closer
277 to PC is the symbol which address is the highest.
278 This way we return the psymtab which contains such
279 best match symbol. This can help in cases where the
280 symbol information/debuginfo is not complete, like
281 for instance on IRIX6 with gcc, where no debug info
282 is emitted for statics. (See also the nodebug.exp
284 if (this_addr
> best_addr
)
286 best_addr
= this_addr
;
294 /* Find which partial symtab contains PC and SECTION. Return NULL if
295 none. We return the psymtab that contains a symbol whose address
296 exactly matches PC, or, if we cannot find an exact match, the
297 psymtab that contains a symbol whose address is closest to PC. */
299 static struct partial_symtab
*
300 find_pc_sect_psymtab (struct objfile
*objfile
, CORE_ADDR pc
,
301 struct obj_section
*section
,
302 struct bound_minimal_symbol msymbol
)
304 CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
305 SECT_OFF_TEXT (objfile
));
307 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
308 than the later used TEXTLOW/TEXTHIGH one. */
310 if (objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
312 struct partial_symtab
*pst
313 = ((struct partial_symtab
*)
314 addrmap_find (objfile
->partial_symtabs
->psymtabs_addrmap
,
318 /* FIXME: addrmaps currently do not handle overlayed sections,
319 so fall back to the non-addrmap case if we're debugging
320 overlays and the addrmap returned the wrong section. */
321 if (overlay_debugging
&& msymbol
.minsym
!= NULL
&& section
!= NULL
)
323 struct partial_symbol
*p
;
325 /* NOTE: This assumes that every psymbol has a
326 corresponding msymbol, which is not necessarily
327 true; the debug info might be much richer than the
328 object's symbol table. */
329 p
= find_pc_sect_psymbol (objfile
, pst
, pc
, section
);
331 || (p
->address (objfile
)
332 != BMSYMBOL_VALUE_ADDRESS (msymbol
)))
336 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
337 PSYMTABS_ADDRMAP we used has already the best 1-byte
338 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
339 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
348 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
349 which still have no corresponding full SYMTABs read. But it is not
350 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
353 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
354 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
355 debug info type in single OBJFILE. */
357 for (partial_symtab
*pst
: require_partial_symbols (objfile
, 1))
358 if (!pst
->psymtabs_addrmap_supported
359 && pc
>= pst
->text_low (objfile
) && pc
< pst
->text_high (objfile
))
361 struct partial_symtab
*best_pst
;
363 best_pst
= find_pc_sect_psymtab_closer (objfile
, pc
, section
, pst
,
365 if (best_pst
!= NULL
)
372 /* Psymtab version of find_pc_sect_compunit_symtab. See its definition in
373 the definition of quick_symbol_functions in symfile.h. */
375 static struct compunit_symtab
*
376 psym_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
377 struct bound_minimal_symbol msymbol
,
379 struct obj_section
*section
,
382 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
, section
,
386 if (warn_if_readin
&& ps
->readin
)
387 /* Might want to error() here (in case symtab is corrupt and
388 will cause a core dump), but maybe we can successfully
389 continue, so let's not. */
391 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
392 paddress (get_objfile_arch (objfile
), pc
));
393 psymtab_to_symtab (objfile
, ps
);
394 return ps
->compunit_symtab
;
399 /* Find which partial symbol within a psymtab matches PC and SECTION.
400 Return NULL if none. */
402 static struct partial_symbol
*
403 find_pc_sect_psymbol (struct objfile
*objfile
,
404 struct partial_symtab
*psymtab
, CORE_ADDR pc
,
405 struct obj_section
*section
)
407 struct partial_symbol
*best
= NULL
;
409 const CORE_ADDR textlow
= psymtab
->text_low (objfile
);
411 gdb_assert (psymtab
!= NULL
);
413 /* Cope with programs that start at address 0. */
414 best_pc
= (textlow
!= 0) ? textlow
- 1 : 0;
416 /* Search the global symbols as well as the static symbols, so that
417 find_pc_partial_function doesn't use a minimal symbol and thus
418 cache a bad endaddr. */
419 for (int i
= 0; i
< psymtab
->n_global_syms
; i
++)
422 = objfile
->partial_symtabs
->global_psymbols
[psymtab
->globals_offset
425 if (p
->domain
== VAR_DOMAIN
426 && p
->aclass
== LOC_BLOCK
427 && pc
>= p
->address (objfile
)
428 && (p
->address (objfile
) > best_pc
429 || (psymtab
->text_low (objfile
) == 0
430 && best_pc
== 0 && p
->address (objfile
) == 0)))
432 if (section
!= NULL
) /* Match on a specific section. */
434 if (!matching_obj_sections (p
->obj_section (objfile
),
438 best_pc
= p
->address (objfile
);
443 for (int i
= 0; i
< psymtab
->n_static_syms
; i
++)
446 = objfile
->partial_symtabs
->static_psymbols
[psymtab
->statics_offset
449 if (p
->domain
== VAR_DOMAIN
450 && p
->aclass
== LOC_BLOCK
451 && pc
>= p
->address (objfile
)
452 && (p
->address (objfile
) > best_pc
453 || (psymtab
->text_low (objfile
) == 0
454 && best_pc
== 0 && p
->address (objfile
) == 0)))
456 if (section
!= NULL
) /* Match on a specific section. */
458 if (!matching_obj_sections (p
->obj_section (objfile
),
462 best_pc
= p
->address (objfile
);
470 /* Psymtab version of lookup_symbol. See its definition in
471 the definition of quick_symbol_functions in symfile.h. */
473 static struct compunit_symtab
*
474 psym_lookup_symbol (struct objfile
*objfile
,
475 block_enum block_index
, const char *name
,
476 const domain_enum domain
)
478 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
479 struct compunit_symtab
*stab_best
= NULL
;
481 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
483 for (partial_symtab
*ps
: require_partial_symbols (objfile
, 1))
485 if (!ps
->readin
&& lookup_partial_symbol (objfile
, ps
, name
,
486 psymtab_index
, domain
))
488 struct symbol
*sym
, *with_opaque
= NULL
;
489 struct compunit_symtab
*stab
= psymtab_to_symtab (objfile
, ps
);
490 /* Note: While psymtab_to_symtab can return NULL if the
491 partial symtab is empty, we can assume it won't here
492 because lookup_partial_symbol succeeded. */
493 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
494 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
496 sym
= block_find_symbol (block
, name
, domain
,
497 block_find_non_opaque_type_preferred
,
500 /* Some caution must be observed with overloaded functions
501 and methods, since the index will not contain any overload
502 information (but NAME might contain it). */
505 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
507 if (with_opaque
!= NULL
508 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
511 /* Keep looking through other psymtabs. */
518 /* Returns true if PSYM matches LOOKUP_NAME. */
521 psymbol_name_matches (partial_symbol
*psym
,
522 const lookup_name_info
&lookup_name
)
524 const language_defn
*lang
= language_def (psym
->ginfo
.language
);
525 symbol_name_matcher_ftype
*name_match
526 = get_symbol_name_matcher (lang
, lookup_name
);
527 return name_match (symbol_search_name (&psym
->ginfo
), lookup_name
, NULL
);
530 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
531 the global block of PST if GLOBAL, and otherwise the static block.
532 MATCH is the comparison operation that returns true iff MATCH (s,
533 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
534 non-null, the symbols in the block are assumed to be ordered
535 according to it (allowing binary search). It must be compatible
536 with MATCH. Returns the symbol, if found, and otherwise NULL. */
538 static struct partial_symbol
*
539 match_partial_symbol (struct objfile
*objfile
,
540 struct partial_symtab
*pst
, int global
,
541 const lookup_name_info
&name
, domain_enum domain
,
542 symbol_compare_ftype
*ordered_compare
)
544 struct partial_symbol
**start
, **psym
;
545 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
546 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
547 int do_linear_search
= 1;
553 &objfile
->partial_symtabs
->global_psymbols
[pst
->globals_offset
] :
554 &objfile
->partial_symtabs
->static_psymbols
[pst
->statics_offset
]);
556 if (global
&& ordered_compare
) /* Can use a binary search. */
558 do_linear_search
= 0;
560 /* Binary search. This search is guaranteed to end with center
561 pointing at the earliest partial symbol whose name might be
562 correct. At that point *all* partial symbols with an
563 appropriate name will be checked against the correct
567 top
= start
+ length
- 1;
571 center
= bottom
+ (top
- bottom
) / 2;
572 gdb_assert (center
< top
);
574 enum language lang
= (*center
)->ginfo
.language
;
576 = name
.language_lookup_name (lang
).c_str ();
578 if (ordered_compare (symbol_search_name (&(*center
)->ginfo
),
584 gdb_assert (top
== bottom
);
586 while (top
<= real_top
587 && psymbol_name_matches (*top
, name
))
589 if (symbol_matches_domain ((*top
)->ginfo
.language
,
590 (*top
)->domain
, domain
))
596 /* Can't use a binary search or else we found during the binary search that
597 we should also do a linear search. */
599 if (do_linear_search
)
601 for (psym
= start
; psym
< start
+ length
; psym
++)
603 if (symbol_matches_domain ((*psym
)->ginfo
.language
,
604 (*psym
)->domain
, domain
)
605 && psymbol_name_matches (*psym
, name
))
613 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
614 not contain any method/function instance information (since this would
615 force reading type information while reading psymtabs). Therefore,
616 if NAME contains overload information, it must be stripped before searching
619 static gdb::unique_xmalloc_ptr
<char>
620 psymtab_search_name (const char *name
)
622 switch (current_language
->la_language
)
626 if (strchr (name
, '('))
628 gdb::unique_xmalloc_ptr
<char> ret
= cp_remove_params (name
);
640 return make_unique_xstrdup (name
);
643 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
644 Check the global symbols if GLOBAL, the static symbols if not. */
646 static struct partial_symbol
*
647 lookup_partial_symbol (struct objfile
*objfile
,
648 struct partial_symtab
*pst
, const char *name
,
649 int global
, domain_enum domain
)
651 struct partial_symbol
**start
, **psym
;
652 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
653 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
654 int do_linear_search
= 1;
659 gdb::unique_xmalloc_ptr
<char> search_name
= psymtab_search_name (name
);
661 lookup_name_info
lookup_name (search_name
.get (), symbol_name_match_type::FULL
);
664 &objfile
->partial_symtabs
->global_psymbols
[pst
->globals_offset
] :
665 &objfile
->partial_symtabs
->static_psymbols
[pst
->statics_offset
]);
667 if (global
) /* This means we can use a binary search. */
669 do_linear_search
= 0;
671 /* Binary search. This search is guaranteed to end with center
672 pointing at the earliest partial symbol whose name might be
673 correct. At that point *all* partial symbols with an
674 appropriate name will be checked against the correct
678 top
= start
+ length
- 1;
682 center
= bottom
+ (top
- bottom
) / 2;
684 internal_error (__FILE__
, __LINE__
,
685 _("failed internal consistency check"));
686 if (strcmp_iw_ordered (symbol_search_name (&(*center
)->ginfo
),
687 search_name
.get ()) >= 0)
696 if (!(top
== bottom
))
697 internal_error (__FILE__
, __LINE__
,
698 _("failed internal consistency check"));
700 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
701 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
702 while (top
>= start
&& symbol_matches_search_name (&(*top
)->ginfo
,
706 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
709 while (top
<= real_top
&& symbol_matches_search_name (&(*top
)->ginfo
,
712 if (symbol_matches_domain ((*top
)->ginfo
.language
,
713 (*top
)->domain
, domain
))
719 /* Can't use a binary search or else we found during the binary search that
720 we should also do a linear search. */
722 if (do_linear_search
)
724 for (psym
= start
; psym
< start
+ length
; psym
++)
726 if (symbol_matches_domain ((*psym
)->ginfo
.language
,
727 (*psym
)->domain
, domain
)
728 && symbol_matches_search_name (&(*psym
)->ginfo
, lookup_name
))
736 /* Get the symbol table that corresponds to a partial_symtab.
737 This is fast after the first time you do it.
738 The result will be NULL if the primary symtab has no symbols,
739 which can happen. Otherwise the result is the primary symtab
740 that contains PST. */
742 static struct compunit_symtab
*
743 psymtab_to_symtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
745 /* If it is a shared psymtab, find an unshared psymtab that includes
746 it. Any such psymtab will do. */
747 while (pst
->user
!= NULL
)
750 /* If it's been looked up before, return it. */
751 if (pst
->compunit_symtab
)
752 return pst
->compunit_symtab
;
754 /* If it has not yet been read in, read it. */
757 scoped_restore decrementer
= increment_reading_symtab ();
759 (*pst
->read_symtab
) (pst
, objfile
);
762 return pst
->compunit_symtab
;
765 /* Psymtab version of find_last_source_symtab. See its definition in
766 the definition of quick_symbol_functions in symfile.h. */
768 static struct symtab
*
769 psym_find_last_source_symtab (struct objfile
*ofp
)
771 struct partial_symtab
*cs_pst
= NULL
;
773 for (partial_symtab
*ps
: require_partial_symbols (ofp
, 1))
775 const char *name
= ps
->filename
;
776 int len
= strlen (name
);
778 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
779 || strcmp (name
, "<<C++-namespaces>>") == 0)))
787 internal_error (__FILE__
, __LINE__
,
788 _("select_source_symtab: "
789 "readin pst found and no symtabs."));
793 struct compunit_symtab
*cust
= psymtab_to_symtab (ofp
, cs_pst
);
797 return compunit_primary_filetab (cust
);
803 /* Psymtab version of forget_cached_source_info. See its definition in
804 the definition of quick_symbol_functions in symfile.h. */
807 psym_forget_cached_source_info (struct objfile
*objfile
)
809 for (partial_symtab
*pst
: require_partial_symbols (objfile
, 1))
811 if (pst
->fullname
!= NULL
)
813 xfree (pst
->fullname
);
814 pst
->fullname
= NULL
;
820 print_partial_symbols (struct gdbarch
*gdbarch
, struct objfile
*objfile
,
821 struct partial_symbol
**p
, int count
, const char *what
,
822 struct ui_file
*outfile
)
824 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
828 fprintf_filtered (outfile
, " `%s'", (*p
)->ginfo
.name
);
829 if (symbol_demangled_name (&(*p
)->ginfo
) != NULL
)
831 fprintf_filtered (outfile
, " `%s'",
832 symbol_demangled_name (&(*p
)->ginfo
));
834 fputs_filtered (", ", outfile
);
835 switch ((*p
)->domain
)
838 fputs_filtered ("undefined domain, ", outfile
);
841 /* This is the usual thing -- don't print it. */
844 fputs_filtered ("struct domain, ", outfile
);
847 fputs_filtered ("module domain, ", outfile
);
850 fputs_filtered ("label domain, ", outfile
);
852 case COMMON_BLOCK_DOMAIN
:
853 fputs_filtered ("common block domain, ", outfile
);
856 fputs_filtered ("<invalid domain>, ", outfile
);
859 switch ((*p
)->aclass
)
862 fputs_filtered ("undefined", outfile
);
865 fputs_filtered ("constant int", outfile
);
868 fputs_filtered ("static", outfile
);
871 fputs_filtered ("register", outfile
);
874 fputs_filtered ("pass by value", outfile
);
877 fputs_filtered ("pass by reference", outfile
);
879 case LOC_REGPARM_ADDR
:
880 fputs_filtered ("register address parameter", outfile
);
883 fputs_filtered ("stack parameter", outfile
);
886 fputs_filtered ("type", outfile
);
889 fputs_filtered ("label", outfile
);
892 fputs_filtered ("function", outfile
);
894 case LOC_CONST_BYTES
:
895 fputs_filtered ("constant bytes", outfile
);
898 fputs_filtered ("unresolved", outfile
);
900 case LOC_OPTIMIZED_OUT
:
901 fputs_filtered ("optimized out", outfile
);
904 fputs_filtered ("computed at runtime", outfile
);
907 fputs_filtered ("<invalid location>", outfile
);
910 fputs_filtered (", ", outfile
);
911 fputs_filtered (paddress (gdbarch
, (*p
)->unrelocated_address ()), outfile
);
912 fprintf_filtered (outfile
, "\n");
918 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
919 struct ui_file
*outfile
)
921 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
924 if (psymtab
->anonymous
)
926 fprintf_filtered (outfile
, "\nAnonymous partial symtab (%s) ",
931 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
934 fprintf_filtered (outfile
, "(object ");
935 gdb_print_host_address (psymtab
, outfile
);
936 fprintf_filtered (outfile
, ")\n\n");
937 fprintf_filtered (outfile
, " Read from object file %s (",
938 objfile_name (objfile
));
939 gdb_print_host_address (objfile
, outfile
);
940 fprintf_filtered (outfile
, ")\n");
944 fprintf_filtered (outfile
,
945 " Full symtab was read (at ");
946 gdb_print_host_address (psymtab
->compunit_symtab
, outfile
);
947 fprintf_filtered (outfile
, " by function at ");
948 gdb_print_host_address (psymtab
->read_symtab
, outfile
);
949 fprintf_filtered (outfile
, ")\n");
952 fprintf_filtered (outfile
, " Symbols cover text addresses ");
953 fputs_filtered (paddress (gdbarch
, psymtab
->text_low (objfile
)), outfile
);
954 fprintf_filtered (outfile
, "-");
955 fputs_filtered (paddress (gdbarch
, psymtab
->text_high (objfile
)), outfile
);
956 fprintf_filtered (outfile
, "\n");
957 fprintf_filtered (outfile
, " Address map supported - %s.\n",
958 psymtab
->psymtabs_addrmap_supported
? "yes" : "no");
959 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
960 psymtab
->number_of_dependencies
);
961 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
963 fprintf_filtered (outfile
, " %d ", i
);
964 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
965 fprintf_filtered (outfile
, " %s\n",
966 psymtab
->dependencies
[i
]->filename
);
968 if (psymtab
->user
!= NULL
)
970 fprintf_filtered (outfile
, " Shared partial symtab with user ");
971 gdb_print_host_address (psymtab
->user
, outfile
);
972 fprintf_filtered (outfile
, "\n");
974 if (psymtab
->n_global_syms
> 0)
976 print_partial_symbols
978 &objfile
->partial_symtabs
->global_psymbols
[psymtab
->globals_offset
],
979 psymtab
->n_global_syms
, "Global", outfile
);
981 if (psymtab
->n_static_syms
> 0)
983 print_partial_symbols
985 &objfile
->partial_symtabs
->static_psymbols
[psymtab
->statics_offset
],
986 psymtab
->n_static_syms
, "Static", outfile
);
988 fprintf_filtered (outfile
, "\n");
991 /* Psymtab version of print_stats. See its definition in
992 the definition of quick_symbol_functions in symfile.h. */
995 psym_print_stats (struct objfile
*objfile
)
1000 for (partial_symtab
*ps
: require_partial_symbols (objfile
, 1))
1002 if (ps
->readin
== 0)
1005 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i
);
1008 /* Psymtab version of dump. See its definition in
1009 the definition of quick_symbol_functions in symfile.h. */
1012 psym_dump (struct objfile
*objfile
)
1014 struct partial_symtab
*psymtab
;
1016 if (objfile
->partial_symtabs
->psymtabs
)
1018 printf_filtered ("Psymtabs:\n");
1019 for (psymtab
= objfile
->partial_symtabs
->psymtabs
;
1021 psymtab
= psymtab
->next
)
1023 printf_filtered ("%s at ",
1025 gdb_print_host_address (psymtab
, gdb_stdout
);
1026 printf_filtered (", ");
1029 printf_filtered ("\n\n");
1033 /* Psymtab version of expand_symtabs_for_function. See its definition in
1034 the definition of quick_symbol_functions in symfile.h. */
1037 psym_expand_symtabs_for_function (struct objfile
*objfile
,
1038 const char *func_name
)
1040 for (partial_symtab
*ps
: require_partial_symbols (objfile
, 1))
1045 if ((lookup_partial_symbol (objfile
, ps
, func_name
, 1, VAR_DOMAIN
)
1047 || (lookup_partial_symbol (objfile
, ps
, func_name
, 0, VAR_DOMAIN
)
1049 psymtab_to_symtab (objfile
, ps
);
1053 /* Psymtab version of expand_all_symtabs. See its definition in
1054 the definition of quick_symbol_functions in symfile.h. */
1057 psym_expand_all_symtabs (struct objfile
*objfile
)
1059 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
, 1))
1060 psymtab_to_symtab (objfile
, psymtab
);
1063 /* Psymtab version of expand_symtabs_with_fullname. See its definition in
1064 the definition of quick_symbol_functions in symfile.h. */
1067 psym_expand_symtabs_with_fullname (struct objfile
*objfile
,
1068 const char *fullname
)
1070 for (partial_symtab
*p
: require_partial_symbols (objfile
, 1))
1072 /* Anonymous psymtabs don't have a name of a source file. */
1076 /* psymtab_to_fullname tries to open the file which is slow.
1077 Don't call it if we know the basenames don't match. */
1078 if ((basenames_may_differ
1079 || filename_cmp (lbasename (fullname
), lbasename (p
->filename
)) == 0)
1080 && filename_cmp (fullname
, psymtab_to_fullname (p
)) == 0)
1081 psymtab_to_symtab (objfile
, p
);
1085 /* Psymtab version of map_symbol_filenames. See its definition in
1086 the definition of quick_symbol_functions in symfile.h. */
1089 psym_map_symbol_filenames (struct objfile
*objfile
,
1090 symbol_filename_ftype
*fun
, void *data
,
1093 for (partial_symtab
*ps
: require_partial_symbols (objfile
, 1))
1095 const char *fullname
;
1100 /* We can skip shared psymtabs here, because any file name will be
1101 attached to the unshared psymtab. */
1102 if (ps
->user
!= NULL
)
1105 /* Anonymous psymtabs don't have a file name. */
1111 fullname
= psymtab_to_fullname (ps
);
1114 (*fun
) (ps
->filename
, fullname
, data
);
1118 /* Finds the fullname that a partial_symtab represents.
1120 If this functions finds the fullname, it will save it in ps->fullname
1121 and it will also return the value.
1123 If this function fails to find the file that this partial_symtab represents,
1124 NULL will be returned and ps->fullname will be set to NULL. */
1127 psymtab_to_fullname (struct partial_symtab
*ps
)
1129 gdb_assert (!ps
->anonymous
);
1131 /* Use cached copy if we have it.
1132 We rely on forget_cached_source_info being called appropriately
1133 to handle cases like the file being moved. */
1134 if (ps
->fullname
== NULL
)
1136 gdb::unique_xmalloc_ptr
<char> fullname
;
1137 scoped_fd fd
= find_and_open_source (ps
->filename
, ps
->dirname
,
1139 ps
->fullname
= fullname
.release ();
1143 /* rewrite_source_path would be applied by find_and_open_source, we
1144 should report the pathname where GDB tried to find the file. */
1146 if (ps
->dirname
== NULL
|| IS_ABSOLUTE_PATH (ps
->filename
))
1147 fullname
.reset (xstrdup (ps
->filename
));
1149 fullname
.reset (concat (ps
->dirname
, SLASH_STRING
,
1150 ps
->filename
, (char *) NULL
));
1152 ps
->fullname
= rewrite_source_path (fullname
.get ()).release ();
1153 if (ps
->fullname
== NULL
)
1154 ps
->fullname
= fullname
.release ();
1158 return ps
->fullname
;
1161 /* Psymtab version of map_matching_symbols. See its definition in
1162 the definition of quick_symbol_functions in symfile.h. */
1165 psym_map_matching_symbols
1166 (struct objfile
*objfile
,
1167 const lookup_name_info
&name
, domain_enum domain
,
1169 gdb::function_view
<symbol_found_callback_ftype
> callback
,
1170 symbol_compare_ftype
*ordered_compare
)
1172 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
1174 for (partial_symtab
*ps
: require_partial_symbols (objfile
, 1))
1178 || match_partial_symbol (objfile
, ps
, global
, name
, domain
,
1181 struct compunit_symtab
*cust
= psymtab_to_symtab (objfile
, ps
);
1182 const struct block
*block
;
1186 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
1187 if (!iterate_over_symbols_terminated (block
, name
,
1194 /* A helper for psym_expand_symtabs_matching that handles searching
1195 included psymtabs. This returns true if a symbol is found, and
1196 false otherwise. It also updates the 'searched_flag' on the
1197 various psymtabs that it searches. */
1200 recursively_search_psymtabs
1201 (struct partial_symtab
*ps
,
1202 struct objfile
*objfile
,
1203 enum search_domain domain
,
1204 const lookup_name_info
&lookup_name
,
1205 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> sym_matcher
)
1208 enum psymtab_search_status result
= PST_SEARCHED_AND_NOT_FOUND
;
1211 if (ps
->searched_flag
!= PST_NOT_SEARCHED
)
1212 return ps
->searched_flag
== PST_SEARCHED_AND_FOUND
;
1214 /* Recurse into shared psymtabs first, because they may have already
1215 been searched, and this could save some time. */
1216 for (i
= 0; i
< ps
->number_of_dependencies
; ++i
)
1220 /* Skip non-shared dependencies, these are handled elsewhere. */
1221 if (ps
->dependencies
[i
]->user
== NULL
)
1224 r
= recursively_search_psymtabs (ps
->dependencies
[i
],
1225 objfile
, domain
, lookup_name
,
1229 ps
->searched_flag
= PST_SEARCHED_AND_FOUND
;
1234 partial_symbol
**gbound
1235 = (objfile
->partial_symtabs
->global_psymbols
.data ()
1236 + ps
->globals_offset
+ ps
->n_global_syms
);
1237 partial_symbol
**sbound
1238 = (objfile
->partial_symtabs
->static_psymbols
.data ()
1239 + ps
->statics_offset
+ ps
->n_static_syms
);
1240 partial_symbol
**bound
= gbound
;
1242 /* Go through all of the symbols stored in a partial
1243 symtab in one loop. */
1244 partial_symbol
**psym
= (objfile
->partial_symtabs
->global_psymbols
.data ()
1245 + ps
->globals_offset
);
1250 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
1252 psym
= (objfile
->partial_symtabs
->static_psymbols
.data ()
1253 + ps
->statics_offset
);
1264 if ((domain
== ALL_DOMAIN
1265 || (domain
== VARIABLES_DOMAIN
1266 && (*psym
)->aclass
!= LOC_TYPEDEF
1267 && (*psym
)->aclass
!= LOC_BLOCK
)
1268 || (domain
== FUNCTIONS_DOMAIN
1269 && (*psym
)->aclass
== LOC_BLOCK
)
1270 || (domain
== TYPES_DOMAIN
1271 && (*psym
)->aclass
== LOC_TYPEDEF
))
1272 && psymbol_name_matches (*psym
, lookup_name
)
1273 && (sym_matcher
== NULL
1274 || sym_matcher (symbol_search_name (&(*psym
)->ginfo
))))
1276 /* Found a match, so notify our caller. */
1277 result
= PST_SEARCHED_AND_FOUND
;
1284 ps
->searched_flag
= result
;
1285 return result
== PST_SEARCHED_AND_FOUND
;
1288 /* Psymtab version of expand_symtabs_matching. See its definition in
1289 the definition of quick_symbol_functions in symfile.h. */
1292 psym_expand_symtabs_matching
1293 (struct objfile
*objfile
,
1294 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
1295 const lookup_name_info
&lookup_name_in
,
1296 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
1297 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
1298 enum search_domain domain
)
1300 lookup_name_info lookup_name
= lookup_name_in
.make_ignore_params ();
1302 /* Clear the search flags. */
1303 for (partial_symtab
*ps
: require_partial_symbols (objfile
, 1))
1304 ps
->searched_flag
= PST_NOT_SEARCHED
;
1306 for (partial_symtab
*ps
: objfile
->psymtabs ())
1313 /* We skip shared psymtabs because file-matching doesn't apply
1314 to them; but we search them later in the loop. */
1315 if (ps
->user
!= NULL
)
1325 match
= file_matcher (ps
->filename
, false);
1328 /* Before we invoke realpath, which can get expensive when many
1329 files are involved, do a quick comparison of the basenames. */
1330 if (basenames_may_differ
1331 || file_matcher (lbasename (ps
->filename
), true))
1332 match
= file_matcher (psymtab_to_fullname (ps
), false);
1338 if (recursively_search_psymtabs (ps
, objfile
, domain
,
1339 lookup_name
, symbol_matcher
))
1341 struct compunit_symtab
*symtab
=
1342 psymtab_to_symtab (objfile
, ps
);
1344 if (expansion_notify
!= NULL
)
1345 expansion_notify (symtab
);
1350 /* Psymtab version of has_symbols. See its definition in
1351 the definition of quick_symbol_functions in symfile.h. */
1354 psym_has_symbols (struct objfile
*objfile
)
1356 return objfile
->partial_symtabs
->psymtabs
!= NULL
;
1359 /* Helper function for psym_find_compunit_symtab_by_address that fills
1360 in psymbol_map for a given range of psymbols. */
1363 psym_fill_psymbol_map (struct objfile
*objfile
,
1364 struct partial_symtab
*psymtab
,
1365 std::set
<CORE_ADDR
> *seen_addrs
,
1366 const std::vector
<partial_symbol
*> &symbols
,
1370 for (int i
= 0; i
< length
; ++i
)
1372 struct partial_symbol
*psym
= symbols
[start
+ i
];
1374 if (psym
->aclass
== LOC_STATIC
)
1376 CORE_ADDR addr
= psym
->address (objfile
);
1377 if (seen_addrs
->find (addr
) == seen_addrs
->end ())
1379 seen_addrs
->insert (addr
);
1380 objfile
->psymbol_map
.emplace_back (addr
, psymtab
);
1386 /* See find_compunit_symtab_by_address in quick_symbol_functions, in
1389 static compunit_symtab
*
1390 psym_find_compunit_symtab_by_address (struct objfile
*objfile
,
1393 if (objfile
->psymbol_map
.empty ())
1395 std::set
<CORE_ADDR
> seen_addrs
;
1397 for (partial_symtab
*pst
: require_partial_symbols (objfile
, 1))
1399 psym_fill_psymbol_map (objfile
, pst
,
1401 objfile
->partial_symtabs
->global_psymbols
,
1402 pst
->globals_offset
,
1403 pst
->n_global_syms
);
1404 psym_fill_psymbol_map (objfile
, pst
,
1406 objfile
->partial_symtabs
->static_psymbols
,
1407 pst
->statics_offset
,
1408 pst
->n_static_syms
);
1411 objfile
->psymbol_map
.shrink_to_fit ();
1413 std::sort (objfile
->psymbol_map
.begin (), objfile
->psymbol_map
.end (),
1414 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1415 const std::pair
<CORE_ADDR
, partial_symtab
*> &b
)
1417 return a
.first
< b
.first
;
1421 auto iter
= std::lower_bound
1422 (objfile
->psymbol_map
.begin (), objfile
->psymbol_map
.end (), address
,
1423 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1429 if (iter
== objfile
->psymbol_map
.end () || iter
->first
!= address
)
1432 return psymtab_to_symtab (objfile
, iter
->second
);
1435 const struct quick_symbol_functions psym_functions
=
1438 psym_find_last_source_symtab
,
1439 psym_forget_cached_source_info
,
1440 psym_map_symtabs_matching_filename
,
1444 psym_expand_symtabs_for_function
,
1445 psym_expand_all_symtabs
,
1446 psym_expand_symtabs_with_fullname
,
1447 psym_map_matching_symbols
,
1448 psym_expand_symtabs_matching
,
1449 psym_find_pc_sect_compunit_symtab
,
1450 psym_find_compunit_symtab_by_address
,
1451 psym_map_symbol_filenames
1457 sort_pst_symbols (struct objfile
*objfile
, struct partial_symtab
*pst
)
1459 /* Sort the global list; don't sort the static list. */
1460 auto begin
= objfile
->partial_symtabs
->global_psymbols
.begin ();
1461 std::advance (begin
, pst
->globals_offset
);
1463 /* The psymbols for this partial_symtab are currently at the end of the
1465 auto end
= objfile
->partial_symtabs
->global_psymbols
.end ();
1467 std::sort (begin
, end
, [] (partial_symbol
*s1
, partial_symbol
*s2
)
1469 return strcmp_iw_ordered (symbol_search_name (&s1
->ginfo
),
1470 symbol_search_name (&s2
->ginfo
)) < 0;
1474 /* Allocate and partially fill a partial symtab. It will be
1475 completely filled at the end of the symbol list.
1477 FILENAME is the name of the symbol-file we are reading from. */
1479 struct partial_symtab
*
1480 start_psymtab_common (struct objfile
*objfile
,
1481 const char *filename
,
1484 struct partial_symtab
*psymtab
;
1486 psymtab
= allocate_psymtab (filename
, objfile
);
1487 psymtab
->set_text_low (textlow
);
1488 psymtab
->set_text_high (psymtab
->raw_text_low ()); /* default */
1489 psymtab
->globals_offset
= objfile
->partial_symtabs
->global_psymbols
.size ();
1490 psymtab
->statics_offset
= objfile
->partial_symtabs
->static_psymbols
.size ();
1494 /* Perform "finishing up" operations of a partial symtab. */
1497 end_psymtab_common (struct objfile
*objfile
, struct partial_symtab
*pst
)
1499 pst
->n_global_syms
= (objfile
->partial_symtabs
->global_psymbols
.size ()
1500 - pst
->globals_offset
);
1501 pst
->n_static_syms
= (objfile
->partial_symtabs
->static_psymbols
.size ()
1502 - pst
->statics_offset
);
1504 sort_pst_symbols (objfile
, pst
);
1507 /* Calculate a hash code for the given partial symbol. The hash is
1508 calculated using the symbol's value, language, domain, class
1509 and name. These are the values which are set by
1510 add_psymbol_to_bcache. */
1512 static unsigned long
1513 psymbol_hash (const void *addr
, int length
)
1515 unsigned long h
= 0;
1516 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1517 unsigned int lang
= psymbol
->ginfo
.language
;
1518 unsigned int domain
= psymbol
->domain
;
1519 unsigned int theclass
= psymbol
->aclass
;
1521 h
= hash_continue (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1522 h
= hash_continue (&lang
, sizeof (unsigned int), h
);
1523 h
= hash_continue (&domain
, sizeof (unsigned int), h
);
1524 h
= hash_continue (&theclass
, sizeof (unsigned int), h
);
1525 /* Note that psymbol names are interned via symbol_set_names, so
1526 there's no need to hash the contents of the name here. */
1527 h
= hash_continue (&psymbol
->ginfo
.name
,
1528 sizeof (psymbol
->ginfo
.name
), h
);
1533 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1534 For the comparison this function uses a symbols value,
1535 language, domain, class and name. */
1538 psymbol_compare (const void *addr1
, const void *addr2
, int length
)
1540 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1541 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1543 return (memcmp (&sym1
->ginfo
.value
, &sym2
->ginfo
.value
,
1544 sizeof (sym1
->ginfo
.value
)) == 0
1545 && sym1
->ginfo
.language
== sym2
->ginfo
.language
1546 && sym1
->domain
== sym2
->domain
1547 && sym1
->aclass
== sym2
->aclass
1548 /* Note that psymbol names are interned via
1549 symbol_set_names, so there's no need to compare the
1550 contents of the name here. */
1551 && sym1
->ginfo
.name
== sym2
->ginfo
.name
);
1554 /* Helper function, initialises partial symbol structure and stashes
1555 it into objfile's bcache. Note that our caching mechanism will
1556 use all fields of struct partial_symbol to determine hash value of the
1557 structure. In other words, having two symbols with the same name but
1558 different domain (or address) is possible and correct. */
1560 static struct partial_symbol
*
1561 add_psymbol_to_bcache (const char *name
, int namelength
, int copy_name
,
1563 enum address_class theclass
,
1566 enum language language
, struct objfile
*objfile
,
1569 struct partial_symbol psymbol
;
1570 memset (&psymbol
, 0, sizeof (psymbol
));
1572 psymbol
.set_unrelocated_address (coreaddr
);
1573 psymbol
.ginfo
.section
= section
;
1574 psymbol
.domain
= domain
;
1575 psymbol
.aclass
= theclass
;
1576 symbol_set_language (&psymbol
.ginfo
, language
,
1577 objfile
->partial_symtabs
->obstack ());
1578 symbol_set_names (&psymbol
.ginfo
, name
, namelength
, copy_name
,
1581 /* Stash the partial symbol away in the cache. */
1582 return ((struct partial_symbol
*)
1583 objfile
->partial_symtabs
->psymbol_cache
.insert
1584 (&psymbol
, sizeof (struct partial_symbol
), added
));
1587 /* Helper function, adds partial symbol to the given partial symbol list. */
1590 append_psymbol_to_list (std::vector
<partial_symbol
*> *list
,
1591 struct partial_symbol
*psym
,
1592 struct objfile
*objfile
)
1594 list
->push_back (psym
);
1595 OBJSTAT (objfile
, n_psyms
++);
1598 /* Add a symbol with a long value to a psymtab.
1599 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1600 The only value we need to store for psyms is an address.
1601 For all other psyms pass zero for COREADDR.
1602 Return the partial symbol that has been added. */
1605 add_psymbol_to_list (const char *name
, int namelength
, int copy_name
,
1607 enum address_class theclass
,
1609 psymbol_placement where
,
1611 enum language language
, struct objfile
*objfile
)
1613 struct partial_symbol
*psym
;
1617 /* Stash the partial symbol away in the cache. */
1618 psym
= add_psymbol_to_bcache (name
, namelength
, copy_name
, domain
, theclass
,
1619 section
, coreaddr
, language
, objfile
, &added
);
1621 /* Do not duplicate global partial symbols. */
1622 if (where
== psymbol_placement::GLOBAL
&& !added
)
1625 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1626 std::vector
<partial_symbol
*> *list
1627 = (where
== psymbol_placement::STATIC
1628 ? &objfile
->partial_symtabs
->static_psymbols
1629 : &objfile
->partial_symtabs
->global_psymbols
);
1630 append_psymbol_to_list (list
, psym
, objfile
);
1633 /* See psympriv.h. */
1636 init_psymbol_list (struct objfile
*objfile
, int total_symbols
)
1638 if (objfile
->partial_symtabs
->global_psymbols
.capacity () == 0
1639 && objfile
->partial_symtabs
->static_psymbols
.capacity () == 0)
1641 /* Current best guess is that approximately a twentieth of the
1642 total symbols (in a debugging file) are global or static
1643 oriented symbols, then multiply that by slop factor of
1645 objfile
->partial_symtabs
->global_psymbols
.reserve (total_symbols
/ 10);
1646 objfile
->partial_symtabs
->static_psymbols
.reserve (total_symbols
/ 10);
1650 /* See psympriv.h. */
1652 struct partial_symtab
*
1653 allocate_psymtab (const char *filename
, struct objfile
*objfile
)
1655 struct partial_symtab
*psymtab
1656 = objfile
->partial_symtabs
->allocate_psymtab ();
1659 = ((const char *) objfile
->per_bfd
->filename_cache
.insert
1660 (filename
, strlen (filename
) + 1));
1661 psymtab
->compunit_symtab
= NULL
;
1663 if (symtab_create_debug
)
1665 /* Be a bit clever with debugging messages, and don't print objfile
1666 every time, only when it changes. */
1667 static char *last_objfile_name
= NULL
;
1669 if (last_objfile_name
== NULL
1670 || strcmp (last_objfile_name
, objfile_name (objfile
)) != 0)
1672 xfree (last_objfile_name
);
1673 last_objfile_name
= xstrdup (objfile_name (objfile
));
1674 fprintf_filtered (gdb_stdlog
,
1675 "Creating one or more psymtabs for objfile %s ...\n",
1678 fprintf_filtered (gdb_stdlog
,
1679 "Created psymtab %s for module %s.\n",
1680 host_address_to_string (psymtab
), filename
);
1687 psymtab_storage::discard_psymtab (struct partial_symtab
*pst
)
1689 struct partial_symtab
**prev_pst
;
1692 Empty psymtabs happen as a result of header files which don't
1693 have any symbols in them. There can be a lot of them. But this
1694 check is wrong, in that a psymtab with N_SLINE entries but
1695 nothing else is not empty, but we don't realize that. Fixing
1696 that without slowing things down might be tricky. */
1698 /* First, snip it out of the psymtab chain. */
1700 prev_pst
= &psymtabs
;
1701 while ((*prev_pst
) != pst
)
1702 prev_pst
= &((*prev_pst
)->next
);
1703 (*prev_pst
) = pst
->next
;
1705 /* Next, put it on a free list for recycling. */
1707 pst
->next
= free_psymtabs
;
1708 free_psymtabs
= pst
;
1713 /* We need to pass a couple of items to the addrmap_foreach function,
1716 struct dump_psymtab_addrmap_data
1718 struct objfile
*objfile
;
1719 struct partial_symtab
*psymtab
;
1720 struct ui_file
*outfile
;
1722 /* Non-zero if the previously printed addrmap entry was for PSYMTAB.
1723 If so, we want to print the next one as well (since the next addrmap
1724 entry defines the end of the range). */
1725 int previous_matched
;
1728 /* Helper function for dump_psymtab_addrmap to print an addrmap entry. */
1731 dump_psymtab_addrmap_1 (void *datap
, CORE_ADDR start_addr
, void *obj
)
1733 struct dump_psymtab_addrmap_data
*data
1734 = (struct dump_psymtab_addrmap_data
*) datap
;
1735 struct gdbarch
*gdbarch
= get_objfile_arch (data
->objfile
);
1736 struct partial_symtab
*addrmap_psymtab
= (struct partial_symtab
*) obj
;
1737 const char *psymtab_address_or_end
= NULL
;
1741 if (data
->psymtab
== NULL
1742 || data
->psymtab
== addrmap_psymtab
)
1743 psymtab_address_or_end
= host_address_to_string (addrmap_psymtab
);
1744 else if (data
->previous_matched
)
1745 psymtab_address_or_end
= "<ends here>";
1747 if (data
->psymtab
== NULL
1748 || data
->psymtab
== addrmap_psymtab
1749 || data
->previous_matched
)
1751 fprintf_filtered (data
->outfile
, " %s%s %s\n",
1752 data
->psymtab
!= NULL
? " " : "",
1753 paddress (gdbarch
, start_addr
),
1754 psymtab_address_or_end
);
1757 data
->previous_matched
= (data
->psymtab
== NULL
1758 || data
->psymtab
== addrmap_psymtab
);
1763 /* Helper function for maintenance_print_psymbols to print the addrmap
1764 of PSYMTAB. If PSYMTAB is NULL print the entire addrmap. */
1767 dump_psymtab_addrmap (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
1768 struct ui_file
*outfile
)
1770 struct dump_psymtab_addrmap_data addrmap_dump_data
;
1772 if ((psymtab
== NULL
1773 || psymtab
->psymtabs_addrmap_supported
)
1774 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
1776 addrmap_dump_data
.objfile
= objfile
;
1777 addrmap_dump_data
.psymtab
= psymtab
;
1778 addrmap_dump_data
.outfile
= outfile
;
1779 addrmap_dump_data
.previous_matched
= 0;
1780 fprintf_filtered (outfile
, "%sddress map:\n",
1781 psymtab
== NULL
? "Entire a" : " A");
1782 addrmap_foreach (objfile
->partial_symtabs
->psymtabs_addrmap
,
1783 dump_psymtab_addrmap_1
, &addrmap_dump_data
);
1788 maintenance_print_psymbols (const char *args
, int from_tty
)
1790 struct ui_file
*outfile
= gdb_stdout
;
1791 char *address_arg
= NULL
, *source_arg
= NULL
, *objfile_arg
= NULL
;
1792 int i
, outfile_idx
, found
;
1794 struct obj_section
*section
= NULL
;
1798 gdb_argv
argv (args
);
1800 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
1802 if (strcmp (argv
[i
], "-pc") == 0)
1804 if (argv
[i
+ 1] == NULL
)
1805 error (_("Missing pc value"));
1806 address_arg
= argv
[++i
];
1808 else if (strcmp (argv
[i
], "-source") == 0)
1810 if (argv
[i
+ 1] == NULL
)
1811 error (_("Missing source file"));
1812 source_arg
= argv
[++i
];
1814 else if (strcmp (argv
[i
], "-objfile") == 0)
1816 if (argv
[i
+ 1] == NULL
)
1817 error (_("Missing objfile name"));
1818 objfile_arg
= argv
[++i
];
1820 else if (strcmp (argv
[i
], "--") == 0)
1822 /* End of options. */
1826 else if (argv
[i
][0] == '-')
1828 /* Future proofing: Don't allow OUTFILE to begin with "-". */
1829 error (_("Unknown option: %s"), argv
[i
]);
1836 if (address_arg
!= NULL
&& source_arg
!= NULL
)
1837 error (_("Must specify at most one of -pc and -source"));
1839 stdio_file arg_outfile
;
1841 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
1843 if (argv
[outfile_idx
+ 1] != NULL
)
1844 error (_("Junk at end of command"));
1845 gdb::unique_xmalloc_ptr
<char> outfile_name
1846 (tilde_expand (argv
[outfile_idx
]));
1847 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
1848 perror_with_name (outfile_name
.get ());
1849 outfile
= &arg_outfile
;
1852 if (address_arg
!= NULL
)
1854 pc
= parse_and_eval_address (address_arg
);
1855 /* If we fail to find a section, that's ok, try the lookup anyway. */
1856 section
= find_pc_section (pc
);
1860 for (objfile
*objfile
: current_program_space
->objfiles ())
1862 int printed_objfile_header
= 0;
1863 int print_for_objfile
= 1;
1866 if (objfile_arg
!= NULL
)
1868 = compare_filenames_for_search (objfile_name (objfile
),
1870 if (!print_for_objfile
)
1873 if (address_arg
!= NULL
)
1875 struct bound_minimal_symbol msymbol
= { NULL
, NULL
};
1877 /* We don't assume each pc has a unique objfile (this is for
1879 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
,
1883 if (!printed_objfile_header
)
1885 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1886 objfile_name (objfile
));
1887 printed_objfile_header
= 1;
1889 dump_psymtab (objfile
, ps
, outfile
);
1890 dump_psymtab_addrmap (objfile
, ps
, outfile
);
1896 for (partial_symtab
*ps
: require_partial_symbols (objfile
, 1))
1898 int print_for_source
= 0;
1901 if (source_arg
!= NULL
)
1904 = compare_filenames_for_search (ps
->filename
, source_arg
);
1907 if (source_arg
== NULL
1908 || print_for_source
)
1910 if (!printed_objfile_header
)
1912 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1913 objfile_name (objfile
));
1914 printed_objfile_header
= 1;
1916 dump_psymtab (objfile
, ps
, outfile
);
1917 dump_psymtab_addrmap (objfile
, ps
, outfile
);
1922 /* If we're printing all the objfile's symbols dump the full addrmap. */
1924 if (address_arg
== NULL
1925 && source_arg
== NULL
1926 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
1928 outfile
->puts ("\n");
1929 dump_psymtab_addrmap (objfile
, NULL
, outfile
);
1935 if (address_arg
!= NULL
)
1936 error (_("No partial symtab for address: %s"), address_arg
);
1937 if (source_arg
!= NULL
)
1938 error (_("No partial symtab for source file: %s"), source_arg
);
1942 /* List all the partial symbol tables whose names match REGEXP (optional). */
1945 maintenance_info_psymtabs (const char *regexp
, int from_tty
)
1947 struct program_space
*pspace
;
1952 ALL_PSPACES (pspace
)
1953 for (objfile
*objfile
: pspace
->objfiles ())
1955 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1957 /* We don't want to print anything for this objfile until we
1958 actually find a symtab whose name matches. */
1959 int printed_objfile_start
= 0;
1961 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
, 1))
1966 || re_exec (psymtab
->filename
))
1968 if (! printed_objfile_start
)
1970 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
1972 printf_filtered ("((struct objfile *) %s)\n",
1973 host_address_to_string (objfile
));
1974 printed_objfile_start
= 1;
1977 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1979 printf_filtered ("((struct partial_symtab *) %s)\n",
1980 host_address_to_string (psymtab
));
1982 printf_filtered (" readin %s\n",
1983 psymtab
->readin
? "yes" : "no");
1984 printf_filtered (" fullname %s\n",
1986 ? psymtab
->fullname
: "(null)");
1987 printf_filtered (" text addresses ");
1988 fputs_filtered (paddress (gdbarch
,
1989 psymtab
->text_low (objfile
)),
1991 printf_filtered (" -- ");
1992 fputs_filtered (paddress (gdbarch
,
1993 psymtab
->text_high (objfile
)),
1995 printf_filtered ("\n");
1996 printf_filtered (" psymtabs_addrmap_supported %s\n",
1997 (psymtab
->psymtabs_addrmap_supported
1999 printf_filtered (" globals ");
2000 if (psymtab
->n_global_syms
)
2002 auto p
= &(objfile
->partial_symtabs
2003 ->global_psymbols
[psymtab
->globals_offset
]);
2006 ("(* (struct partial_symbol **) %s @ %d)\n",
2007 host_address_to_string (p
),
2008 psymtab
->n_global_syms
);
2011 printf_filtered ("(none)\n");
2012 printf_filtered (" statics ");
2013 if (psymtab
->n_static_syms
)
2015 auto p
= &(objfile
->partial_symtabs
2016 ->static_psymbols
[psymtab
->statics_offset
]);
2019 ("(* (struct partial_symbol **) %s @ %d)\n",
2020 host_address_to_string (p
),
2021 psymtab
->n_static_syms
);
2024 printf_filtered ("(none)\n");
2025 printf_filtered (" dependencies ");
2026 if (psymtab
->number_of_dependencies
)
2030 printf_filtered ("{\n");
2031 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
2033 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
2035 /* Note the string concatenation there --- no
2037 printf_filtered (" psymtab %s "
2038 "((struct partial_symtab *) %s)\n",
2040 host_address_to_string (dep
));
2042 printf_filtered (" }\n");
2045 printf_filtered ("(none)\n");
2046 printf_filtered (" }\n");
2050 if (printed_objfile_start
)
2051 printf_filtered ("}\n");
2055 /* Check consistency of currently expanded psymtabs vs symtabs. */
2058 maintenance_check_psymtabs (const char *ignore
, int from_tty
)
2061 struct compunit_symtab
*cust
= NULL
;
2062 const struct blockvector
*bv
;
2063 const struct block
*b
;
2066 for (objfile
*objfile
: current_program_space
->objfiles ())
2067 for (partial_symtab
*ps
: require_partial_symbols (objfile
, 1))
2069 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2071 /* We don't call psymtab_to_symtab here because that may cause symtab
2072 expansion. When debugging a problem it helps if checkers leave
2073 things unchanged. */
2074 cust
= ps
->compunit_symtab
;
2076 /* First do some checks that don't require the associated symtab. */
2077 if (ps
->text_high (objfile
) < ps
->text_low (objfile
))
2079 printf_filtered ("Psymtab ");
2080 puts_filtered (ps
->filename
);
2081 printf_filtered (" covers bad range ");
2082 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
2084 printf_filtered (" - ");
2085 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
2087 printf_filtered ("\n");
2091 /* Now do checks requiring the associated symtab. */
2094 bv
= COMPUNIT_BLOCKVECTOR (cust
);
2095 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
2096 partial_symbol
**psym
2097 = &objfile
->partial_symtabs
->static_psymbols
[ps
->statics_offset
];
2098 length
= ps
->n_static_syms
;
2101 sym
= block_lookup_symbol (b
, symbol_search_name (&(*psym
)->ginfo
),
2102 symbol_name_match_type::SEARCH_NAME
,
2106 printf_filtered ("Static symbol `");
2107 puts_filtered ((*psym
)->ginfo
.name
);
2108 printf_filtered ("' only found in ");
2109 puts_filtered (ps
->filename
);
2110 printf_filtered (" psymtab\n");
2114 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2115 psym
= &objfile
->partial_symtabs
->global_psymbols
[ps
->globals_offset
];
2116 length
= ps
->n_global_syms
;
2119 sym
= block_lookup_symbol (b
, symbol_search_name (&(*psym
)->ginfo
),
2120 symbol_name_match_type::SEARCH_NAME
,
2124 printf_filtered ("Global symbol `");
2125 puts_filtered ((*psym
)->ginfo
.name
);
2126 printf_filtered ("' only found in ");
2127 puts_filtered (ps
->filename
);
2128 printf_filtered (" psymtab\n");
2132 if (ps
->raw_text_high () != 0
2133 && (ps
->text_low (objfile
) < BLOCK_START (b
)
2134 || ps
->text_high (objfile
) > BLOCK_END (b
)))
2136 printf_filtered ("Psymtab ");
2137 puts_filtered (ps
->filename
);
2138 printf_filtered (" covers ");
2139 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
2141 printf_filtered (" - ");
2142 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
2144 printf_filtered (" but symtab covers only ");
2145 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
2146 printf_filtered (" - ");
2147 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
2148 printf_filtered ("\n");
2154 _initialize_psymtab (void)
2156 add_cmd ("psymbols", class_maintenance
, maintenance_print_psymbols
, _("\
2157 Print dump of current partial symbol definitions.\n\
2158 Usage: mt print psymbols [-objfile OBJFILE] [-pc ADDRESS] [--] [OUTFILE]\n\
2159 mt print psymbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
2160 Entries in the partial symbol table are dumped to file OUTFILE,\n\
2161 or the terminal if OUTFILE is unspecified.\n\
2162 If ADDRESS is provided, dump only the file for that address.\n\
2163 If SOURCE is provided, dump only that file's symbols.\n\
2164 If OBJFILE is provided, dump only that file's minimal symbols."),
2165 &maintenanceprintlist
);
2167 add_cmd ("psymtabs", class_maintenance
, maintenance_info_psymtabs
, _("\
2168 List the partial symbol tables for all object files.\n\
2169 This does not include information about individual partial symbols,\n\
2170 just the symbol table structures themselves."),
2171 &maintenanceinfolist
);
2173 add_cmd ("check-psymtabs", class_maintenance
, maintenance_check_psymtabs
,
2175 Check consistency of currently expanded psymtabs versus symtabs."),