1 /* Partial symbol tables.
3 Copyright (C) 2009-2017 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"
32 #include "readline/readline.h"
33 #include "gdb_regex.h"
34 #include "dictionary.h"
36 #include "cp-support.h"
43 struct bcache
*bcache
;
46 static struct partial_symbol
*match_partial_symbol (struct objfile
*,
47 struct partial_symtab
*,
49 const char *, domain_enum
,
50 symbol_name_match_type
,
51 symbol_compare_ftype
*);
53 static struct partial_symbol
*lookup_partial_symbol (struct objfile
*,
54 struct partial_symtab
*,
58 static const char *psymtab_to_fullname (struct partial_symtab
*ps
);
60 static struct partial_symbol
*find_pc_sect_psymbol (struct objfile
*,
61 struct partial_symtab
*,
63 struct obj_section
*);
65 static void fixup_psymbol_section (struct partial_symbol
*psym
,
66 struct objfile
*objfile
);
68 static struct compunit_symtab
*psymtab_to_symtab (struct objfile
*objfile
,
69 struct partial_symtab
*pst
);
71 /* Ensure that the partial symbols for OBJFILE have been loaded. This
72 function always returns its argument, as a convenience. */
75 require_partial_symbols (struct objfile
*objfile
, int verbose
)
77 if ((objfile
->flags
& OBJF_PSYMTABS_READ
) == 0)
79 objfile
->flags
|= OBJF_PSYMTABS_READ
;
81 if (objfile
->sf
->sym_read_psymbols
)
85 printf_unfiltered (_("Reading symbols from %s..."),
86 objfile_name (objfile
));
87 gdb_flush (gdb_stdout
);
89 (*objfile
->sf
->sym_read_psymbols
) (objfile
);
91 /* Partial symbols list are not expected to changed after this
93 objfile
->global_psymbols
.shrink_to_fit ();
94 objfile
->static_psymbols
.shrink_to_fit ();
98 if (!objfile_has_symbols (objfile
))
101 printf_unfiltered (_("(no debugging symbols found)..."));
105 printf_unfiltered (_("done.\n"));
113 /* Traverse all psymtabs in one objfile, requiring that the psymtabs
116 #define ALL_OBJFILE_PSYMTABS_REQUIRED(objfile, p) \
117 for ((p) = require_partial_symbols (objfile, 1)->psymtabs; \
121 /* We want to make sure this file always requires psymtabs. */
123 #undef ALL_OBJFILE_PSYMTABS
125 /* Traverse all psymtabs in all objfiles. */
127 #define ALL_PSYMTABS(objfile, p) \
128 ALL_OBJFILES (objfile) \
129 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
131 /* Helper function for psym_map_symtabs_matching_filename that
132 expands the symtabs and calls the iterator. */
135 partial_map_expand_apply (struct objfile
*objfile
,
137 const char *real_path
,
138 struct partial_symtab
*pst
,
139 gdb::function_view
<bool (symtab
*)> callback
)
141 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
143 /* Shared psymtabs should never be seen here. Instead they should
144 be handled properly by the caller. */
145 gdb_assert (pst
->user
== NULL
);
147 /* Don't visit already-expanded psymtabs. */
151 /* This may expand more than one symtab, and we want to iterate over
153 psymtab_to_symtab (objfile
, pst
);
155 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
156 last_made
, callback
);
159 /* Psymtab version of map_symtabs_matching_filename. See its definition in
160 the definition of quick_symbol_functions in symfile.h. */
163 psym_map_symtabs_matching_filename
164 (struct objfile
*objfile
,
166 const char *real_path
,
167 gdb::function_view
<bool (symtab
*)> callback
)
169 struct partial_symtab
*pst
;
170 const char *name_basename
= lbasename (name
);
172 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
174 /* We can skip shared psymtabs here, because any file name will be
175 attached to the unshared psymtab. */
176 if (pst
->user
!= NULL
)
179 /* Anonymous psymtabs don't have a file name. */
183 if (compare_filenames_for_search (pst
->filename
, name
))
185 if (partial_map_expand_apply (objfile
, name
, real_path
,
191 /* Before we invoke realpath, which can get expensive when many
192 files are involved, do a quick comparison of the basenames. */
193 if (! basenames_may_differ
194 && FILENAME_CMP (name_basename
, lbasename (pst
->filename
)) != 0)
197 if (compare_filenames_for_search (psymtab_to_fullname (pst
), name
))
199 if (partial_map_expand_apply (objfile
, name
, real_path
,
205 /* If the user gave us an absolute path, try to find the file in
206 this symtab and use its absolute path. */
207 if (real_path
!= NULL
)
209 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
210 gdb_assert (IS_ABSOLUTE_PATH (name
));
211 if (filename_cmp (psymtab_to_fullname (pst
), real_path
) == 0)
213 if (partial_map_expand_apply (objfile
, name
, real_path
,
224 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
225 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
227 static struct partial_symtab
*
228 find_pc_sect_psymtab_closer (struct objfile
*objfile
,
229 CORE_ADDR pc
, struct obj_section
*section
,
230 struct partial_symtab
*pst
,
231 struct bound_minimal_symbol msymbol
)
233 struct partial_symtab
*tpst
;
234 struct partial_symtab
*best_pst
= pst
;
235 CORE_ADDR best_addr
= pst
->textlow
;
237 gdb_assert (!pst
->psymtabs_addrmap_supported
);
239 /* An objfile that has its functions reordered might have
240 many partial symbol tables containing the PC, but
241 we want the partial symbol table that contains the
242 function containing the PC. */
243 if (!(objfile
->flags
& OBJF_REORDERED
)
244 && section
== NULL
) /* Can't validate section this way. */
247 if (msymbol
.minsym
== NULL
)
250 /* The code range of partial symtabs sometimes overlap, so, in
251 the loop below, we need to check all partial symtabs and
252 find the one that fits better for the given PC address. We
253 select the partial symtab that contains a symbol whose
254 address is closest to the PC address. By closest we mean
255 that find_pc_sect_symbol returns the symbol with address
256 that is closest and still less than the given PC. */
257 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
259 if (pc
>= tpst
->textlow
&& pc
< tpst
->texthigh
)
261 struct partial_symbol
*p
;
264 /* NOTE: This assumes that every psymbol has a
265 corresponding msymbol, which is not necessarily
266 true; the debug info might be much richer than the
267 object's symbol table. */
268 p
= find_pc_sect_psymbol (objfile
, tpst
, pc
, section
);
270 && (SYMBOL_VALUE_ADDRESS (p
)
271 == BMSYMBOL_VALUE_ADDRESS (msymbol
)))
274 /* Also accept the textlow value of a psymtab as a
275 "symbol", to provide some support for partial
276 symbol tables with line information but no debug
277 symbols (e.g. those produced by an assembler). */
279 this_addr
= SYMBOL_VALUE_ADDRESS (p
);
281 this_addr
= tpst
->textlow
;
283 /* Check whether it is closer than our current
284 BEST_ADDR. Since this symbol address is
285 necessarily lower or equal to PC, the symbol closer
286 to PC is the symbol which address is the highest.
287 This way we return the psymtab which contains such
288 best match symbol. This can help in cases where the
289 symbol information/debuginfo is not complete, like
290 for instance on IRIX6 with gcc, where no debug info
291 is emitted for statics. (See also the nodebug.exp
293 if (this_addr
> best_addr
)
295 best_addr
= this_addr
;
303 /* Find which partial symtab contains PC and SECTION. Return NULL if
304 none. We return the psymtab that contains a symbol whose address
305 exactly matches PC, or, if we cannot find an exact match, the
306 psymtab that contains a symbol whose address is closest to PC. */
308 static struct partial_symtab
*
309 find_pc_sect_psymtab (struct objfile
*objfile
, CORE_ADDR pc
,
310 struct obj_section
*section
,
311 struct bound_minimal_symbol msymbol
)
313 struct partial_symtab
*pst
;
315 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
316 than the later used TEXTLOW/TEXTHIGH one. */
318 if (objfile
->psymtabs_addrmap
!= NULL
)
320 pst
= ((struct partial_symtab
*)
321 addrmap_find (objfile
->psymtabs_addrmap
, pc
));
324 /* FIXME: addrmaps currently do not handle overlayed sections,
325 so fall back to the non-addrmap case if we're debugging
326 overlays and the addrmap returned the wrong section. */
327 if (overlay_debugging
&& msymbol
.minsym
!= NULL
&& section
!= NULL
)
329 struct partial_symbol
*p
;
331 /* NOTE: This assumes that every psymbol has a
332 corresponding msymbol, which is not necessarily
333 true; the debug info might be much richer than the
334 object's symbol table. */
335 p
= find_pc_sect_psymbol (objfile
, pst
, pc
, section
);
337 || (SYMBOL_VALUE_ADDRESS (p
)
338 != BMSYMBOL_VALUE_ADDRESS (msymbol
)))
342 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
343 PSYMTABS_ADDRMAP we used has already the best 1-byte
344 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
345 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
354 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
355 which still have no corresponding full SYMTABs read. But it is not
356 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
359 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
360 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
361 debug info type in single OBJFILE. */
363 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
364 if (!pst
->psymtabs_addrmap_supported
365 && pc
>= pst
->textlow
&& pc
< pst
->texthigh
)
367 struct partial_symtab
*best_pst
;
369 best_pst
= find_pc_sect_psymtab_closer (objfile
, pc
, section
, pst
,
371 if (best_pst
!= NULL
)
378 /* Psymtab version of find_pc_sect_compunit_symtab. See its definition in
379 the definition of quick_symbol_functions in symfile.h. */
381 static struct compunit_symtab
*
382 psym_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
383 struct bound_minimal_symbol msymbol
,
385 struct obj_section
*section
,
388 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
, section
,
392 if (warn_if_readin
&& ps
->readin
)
393 /* Might want to error() here (in case symtab is corrupt and
394 will cause a core dump), but maybe we can successfully
395 continue, so let's not. */
397 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
398 paddress (get_objfile_arch (objfile
), pc
));
399 psymtab_to_symtab (objfile
, ps
);
400 return ps
->compunit_symtab
;
405 /* Find which partial symbol within a psymtab matches PC and SECTION.
406 Return NULL if none. */
408 static struct partial_symbol
*
409 find_pc_sect_psymbol (struct objfile
*objfile
,
410 struct partial_symtab
*psymtab
, CORE_ADDR pc
,
411 struct obj_section
*section
)
413 struct partial_symbol
*best
= NULL
;
416 gdb_assert (psymtab
!= NULL
);
418 /* Cope with programs that start at address 0. */
419 best_pc
= (psymtab
->textlow
!= 0) ? psymtab
->textlow
- 1 : 0;
421 /* Search the global symbols as well as the static symbols, so that
422 find_pc_partial_function doesn't use a minimal symbol and thus
423 cache a bad endaddr. */
424 for (int i
= 0; i
< psymtab
->n_global_syms
; i
++)
426 partial_symbol
*p
= objfile
->global_psymbols
[psymtab
->globals_offset
+ i
];
428 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
429 && PSYMBOL_CLASS (p
) == LOC_BLOCK
430 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
431 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
432 || (psymtab
->textlow
== 0
433 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
435 if (section
!= NULL
) /* Match on a specific section. */
437 fixup_psymbol_section (p
, objfile
);
438 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (objfile
, p
),
442 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
447 for (int i
= 0; i
< psymtab
->n_static_syms
; i
++)
449 partial_symbol
*p
= objfile
->static_psymbols
[psymtab
->statics_offset
+ i
];
451 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
452 && PSYMBOL_CLASS (p
) == LOC_BLOCK
453 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
454 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
455 || (psymtab
->textlow
== 0
456 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
458 if (section
!= NULL
) /* Match on a specific section. */
460 fixup_psymbol_section (p
, objfile
);
461 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (objfile
, p
),
465 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
474 fixup_psymbol_section (struct partial_symbol
*psym
, struct objfile
*objfile
)
481 if (SYMBOL_SECTION (psym
) >= 0)
484 gdb_assert (objfile
);
486 switch (PSYMBOL_CLASS (psym
))
491 addr
= SYMBOL_VALUE_ADDRESS (psym
);
494 /* Nothing else will be listed in the minsyms -- no use looking
499 fixup_section (&psym
->ginfo
, addr
, objfile
);
502 /* Psymtab version of lookup_symbol. See its definition in
503 the definition of quick_symbol_functions in symfile.h. */
505 static struct compunit_symtab
*
506 psym_lookup_symbol (struct objfile
*objfile
,
507 int block_index
, const char *name
,
508 const domain_enum domain
)
510 struct partial_symtab
*ps
;
511 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
512 struct compunit_symtab
*stab_best
= NULL
;
514 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
516 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
518 if (!ps
->readin
&& lookup_partial_symbol (objfile
, ps
, name
,
519 psymtab_index
, domain
))
521 struct symbol
*sym
, *with_opaque
= NULL
;
522 struct compunit_symtab
*stab
= psymtab_to_symtab (objfile
, ps
);
523 /* Note: While psymtab_to_symtab can return NULL if the partial symtab
524 is empty, we can assume it won't here because lookup_partial_symbol
526 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
527 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
529 sym
= block_find_symbol (block
, name
, domain
,
530 block_find_non_opaque_type_preferred
,
533 /* Some caution must be observed with overloaded functions
534 and methods, since the index will not contain any overload
535 information (but NAME might contain it). */
538 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
540 if (with_opaque
!= NULL
541 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
544 /* Keep looking through other psymtabs. */
551 /* Returns true if PSYM matches LOOKUP_NAME. */
554 psymbol_name_matches (partial_symbol
*psym
,
555 const lookup_name_info
&lookup_name
)
557 const language_defn
*lang
= language_def (SYMBOL_LANGUAGE (psym
));
558 symbol_name_matcher_ftype
*name_match
559 = language_get_symbol_name_matcher (lang
, lookup_name
);
560 return name_match (SYMBOL_SEARCH_NAME (psym
), lookup_name
, NULL
);
563 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
564 the global block of PST if GLOBAL, and otherwise the static block.
565 MATCH is the comparison operation that returns true iff MATCH (s,
566 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
567 non-null, the symbols in the block are assumed to be ordered
568 according to it (allowing binary search). It must be compatible
569 with MATCH. Returns the symbol, if found, and otherwise NULL. */
571 static struct partial_symbol
*
572 match_partial_symbol (struct objfile
*objfile
,
573 struct partial_symtab
*pst
, int global
,
574 const char *name
, domain_enum domain
,
575 symbol_name_match_type match_type
,
576 symbol_compare_ftype
*ordered_compare
)
578 struct partial_symbol
**start
, **psym
;
579 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
580 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
581 int do_linear_search
= 1;
586 lookup_name_info
lookup_name (name
, match_type
);
589 &objfile
->global_psymbols
[pst
->globals_offset
] :
590 &objfile
->static_psymbols
[pst
->statics_offset
]);
592 if (global
&& ordered_compare
) /* Can use a binary search. */
594 do_linear_search
= 0;
596 /* Binary search. This search is guaranteed to end with center
597 pointing at the earliest partial symbol whose name might be
598 correct. At that point *all* partial symbols with an
599 appropriate name will be checked against the correct
603 top
= start
+ length
- 1;
607 center
= bottom
+ (top
- bottom
) / 2;
608 gdb_assert (center
< top
);
610 enum language lang
= SYMBOL_LANGUAGE (*center
);
612 = lookup_name
.language_lookup_name (lang
).c_str ();
614 if (ordered_compare (SYMBOL_SEARCH_NAME (*center
), lang_ln
) >= 0)
619 gdb_assert (top
== bottom
);
621 while (top
<= real_top
622 && psymbol_name_matches (*top
, lookup_name
))
624 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top
),
625 SYMBOL_DOMAIN (*top
), domain
))
631 /* Can't use a binary search or else we found during the binary search that
632 we should also do a linear search. */
634 if (do_linear_search
)
636 for (psym
= start
; psym
< start
+ length
; psym
++)
638 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym
),
639 SYMBOL_DOMAIN (*psym
), domain
)
640 && psymbol_name_matches (*psym
, lookup_name
))
648 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
649 not contain any method/function instance information (since this would
650 force reading type information while reading psymtabs). Therefore,
651 if NAME contains overload information, it must be stripped before searching
654 static gdb::unique_xmalloc_ptr
<char>
655 psymtab_search_name (const char *name
)
657 switch (current_language
->la_language
)
661 if (strchr (name
, '('))
663 gdb::unique_xmalloc_ptr
<char> ret
= cp_remove_params (name
);
675 return gdb::unique_xmalloc_ptr
<char> (xstrdup (name
));
678 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
679 Check the global symbols if GLOBAL, the static symbols if not. */
681 static struct partial_symbol
*
682 lookup_partial_symbol (struct objfile
*objfile
,
683 struct partial_symtab
*pst
, const char *name
,
684 int global
, domain_enum domain
)
686 struct partial_symbol
**start
, **psym
;
687 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
688 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
689 int do_linear_search
= 1;
694 gdb::unique_xmalloc_ptr
<char> search_name
= psymtab_search_name (name
);
696 lookup_name_info
lookup_name (search_name
.get (), symbol_name_match_type::FULL
);
699 &objfile
->global_psymbols
[pst
->globals_offset
] :
700 &objfile
->static_psymbols
[pst
->statics_offset
]);
702 if (global
) /* This means we can use a binary search. */
704 do_linear_search
= 0;
706 /* Binary search. This search is guaranteed to end with center
707 pointing at the earliest partial symbol whose name might be
708 correct. At that point *all* partial symbols with an
709 appropriate name will be checked against the correct
713 top
= start
+ length
- 1;
717 center
= bottom
+ (top
- bottom
) / 2;
719 internal_error (__FILE__
, __LINE__
,
720 _("failed internal consistency check"));
721 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center
),
722 search_name
.get ()) >= 0)
731 if (!(top
== bottom
))
732 internal_error (__FILE__
, __LINE__
,
733 _("failed internal consistency check"));
735 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
736 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
737 while (top
>= start
&& SYMBOL_MATCHES_SEARCH_NAME (*top
, lookup_name
))
740 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
743 while (top
<= real_top
&& SYMBOL_MATCHES_SEARCH_NAME (*top
, lookup_name
))
745 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top
),
746 SYMBOL_DOMAIN (*top
), domain
))
752 /* Can't use a binary search or else we found during the binary search that
753 we should also do a linear search. */
755 if (do_linear_search
)
757 for (psym
= start
; psym
< start
+ length
; psym
++)
759 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym
),
760 SYMBOL_DOMAIN (*psym
), domain
)
761 && SYMBOL_MATCHES_SEARCH_NAME (*psym
, lookup_name
))
769 /* Get the symbol table that corresponds to a partial_symtab.
770 This is fast after the first time you do it.
771 The result will be NULL if the primary symtab has no symbols,
772 which can happen. Otherwise the result is the primary symtab
773 that contains PST. */
775 static struct compunit_symtab
*
776 psymtab_to_symtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
778 /* If it is a shared psymtab, find an unshared psymtab that includes
779 it. Any such psymtab will do. */
780 while (pst
->user
!= NULL
)
783 /* If it's been looked up before, return it. */
784 if (pst
->compunit_symtab
)
785 return pst
->compunit_symtab
;
787 /* If it has not yet been read in, read it. */
790 scoped_restore decrementer
= increment_reading_symtab ();
792 (*pst
->read_symtab
) (pst
, objfile
);
795 return pst
->compunit_symtab
;
798 /* Psymtab version of relocate. See its definition in
799 the definition of quick_symbol_functions in symfile.h. */
802 psym_relocate (struct objfile
*objfile
,
803 const struct section_offsets
*new_offsets
,
804 const struct section_offsets
*delta
)
806 struct partial_symbol
**psym
;
807 struct partial_symtab
*p
;
809 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, p
)
811 p
->textlow
+= ANOFFSET (delta
, SECT_OFF_TEXT (objfile
));
812 p
->texthigh
+= ANOFFSET (delta
, SECT_OFF_TEXT (objfile
));
815 for (partial_symbol
*psym
: objfile
->global_psymbols
)
817 fixup_psymbol_section (psym
, objfile
);
818 if (SYMBOL_SECTION (psym
) >= 0)
819 SYMBOL_VALUE_ADDRESS (psym
) += ANOFFSET (delta
, SYMBOL_SECTION (psym
));
821 for (partial_symbol
*psym
: objfile
->static_psymbols
)
823 fixup_psymbol_section (psym
, objfile
);
824 if (SYMBOL_SECTION (psym
) >= 0)
825 SYMBOL_VALUE_ADDRESS (psym
) += ANOFFSET (delta
, SYMBOL_SECTION (psym
));
828 objfile
->psymbol_map
.clear ();
831 /* Psymtab version of find_last_source_symtab. See its definition in
832 the definition of quick_symbol_functions in symfile.h. */
834 static struct symtab
*
835 psym_find_last_source_symtab (struct objfile
*ofp
)
837 struct partial_symtab
*ps
;
838 struct partial_symtab
*cs_pst
= NULL
;
840 ALL_OBJFILE_PSYMTABS_REQUIRED (ofp
, ps
)
842 const char *name
= ps
->filename
;
843 int len
= strlen (name
);
845 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
846 || strcmp (name
, "<<C++-namespaces>>") == 0)))
854 internal_error (__FILE__
, __LINE__
,
855 _("select_source_symtab: "
856 "readin pst found and no symtabs."));
860 struct compunit_symtab
*cust
= psymtab_to_symtab (ofp
, cs_pst
);
864 return compunit_primary_filetab (cust
);
870 /* Psymtab version of forget_cached_source_info. See its definition in
871 the definition of quick_symbol_functions in symfile.h. */
874 psym_forget_cached_source_info (struct objfile
*objfile
)
876 struct partial_symtab
*pst
;
878 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
880 if (pst
->fullname
!= NULL
)
882 xfree (pst
->fullname
);
883 pst
->fullname
= NULL
;
889 print_partial_symbols (struct gdbarch
*gdbarch
,
890 struct partial_symbol
**p
, int count
, const char *what
,
891 struct ui_file
*outfile
)
893 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
897 fprintf_filtered (outfile
, " `%s'", SYMBOL_LINKAGE_NAME (*p
));
898 if (SYMBOL_DEMANGLED_NAME (*p
) != NULL
)
900 fprintf_filtered (outfile
, " `%s'", SYMBOL_DEMANGLED_NAME (*p
));
902 fputs_filtered (", ", outfile
);
903 switch (SYMBOL_DOMAIN (*p
))
906 fputs_filtered ("undefined domain, ", outfile
);
909 /* This is the usual thing -- don't print it. */
912 fputs_filtered ("struct domain, ", outfile
);
915 fputs_filtered ("label domain, ", outfile
);
918 fputs_filtered ("<invalid domain>, ", outfile
);
921 switch (PSYMBOL_CLASS (*p
))
924 fputs_filtered ("undefined", outfile
);
927 fputs_filtered ("constant int", outfile
);
930 fputs_filtered ("static", outfile
);
933 fputs_filtered ("register", outfile
);
936 fputs_filtered ("pass by value", outfile
);
939 fputs_filtered ("pass by reference", outfile
);
941 case LOC_REGPARM_ADDR
:
942 fputs_filtered ("register address parameter", outfile
);
945 fputs_filtered ("stack parameter", outfile
);
948 fputs_filtered ("type", outfile
);
951 fputs_filtered ("label", outfile
);
954 fputs_filtered ("function", outfile
);
956 case LOC_CONST_BYTES
:
957 fputs_filtered ("constant bytes", outfile
);
960 fputs_filtered ("unresolved", outfile
);
962 case LOC_OPTIMIZED_OUT
:
963 fputs_filtered ("optimized out", outfile
);
966 fputs_filtered ("computed at runtime", outfile
);
969 fputs_filtered ("<invalid location>", outfile
);
972 fputs_filtered (", ", outfile
);
973 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (*p
)), outfile
);
974 fprintf_filtered (outfile
, "\n");
980 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
981 struct ui_file
*outfile
)
983 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
986 if (psymtab
->anonymous
)
988 fprintf_filtered (outfile
, "\nAnonymous partial symtab (%s) ",
993 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
996 fprintf_filtered (outfile
, "(object ");
997 gdb_print_host_address (psymtab
, outfile
);
998 fprintf_filtered (outfile
, ")\n\n");
999 fprintf_unfiltered (outfile
, " Read from object file %s (",
1000 objfile_name (objfile
));
1001 gdb_print_host_address (objfile
, outfile
);
1002 fprintf_unfiltered (outfile
, ")\n");
1004 if (psymtab
->readin
)
1006 fprintf_filtered (outfile
,
1007 " Full symtab was read (at ");
1008 gdb_print_host_address (psymtab
->compunit_symtab
, outfile
);
1009 fprintf_filtered (outfile
, " by function at ");
1010 gdb_print_host_address (psymtab
->read_symtab
, outfile
);
1011 fprintf_filtered (outfile
, ")\n");
1014 fprintf_filtered (outfile
, " Symbols cover text addresses ");
1015 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
), outfile
);
1016 fprintf_filtered (outfile
, "-");
1017 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
), outfile
);
1018 fprintf_filtered (outfile
, "\n");
1019 fprintf_filtered (outfile
, " Address map supported - %s.\n",
1020 psymtab
->psymtabs_addrmap_supported
? "yes" : "no");
1021 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
1022 psymtab
->number_of_dependencies
);
1023 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1025 fprintf_filtered (outfile
, " %d ", i
);
1026 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
1027 fprintf_filtered (outfile
, " %s\n",
1028 psymtab
->dependencies
[i
]->filename
);
1030 if (psymtab
->user
!= NULL
)
1032 fprintf_filtered (outfile
, " Shared partial symtab with user ");
1033 gdb_print_host_address (psymtab
->user
, outfile
);
1034 fprintf_filtered (outfile
, "\n");
1036 if (psymtab
->n_global_syms
> 0)
1038 print_partial_symbols (gdbarch
,
1039 &objfile
->global_psymbols
[psymtab
->globals_offset
],
1040 psymtab
->n_global_syms
, "Global", outfile
);
1042 if (psymtab
->n_static_syms
> 0)
1044 print_partial_symbols (gdbarch
,
1045 &objfile
->static_psymbols
[psymtab
->statics_offset
],
1046 psymtab
->n_static_syms
, "Static", outfile
);
1048 fprintf_filtered (outfile
, "\n");
1051 /* Psymtab version of print_stats. See its definition in
1052 the definition of quick_symbol_functions in symfile.h. */
1055 psym_print_stats (struct objfile
*objfile
)
1058 struct partial_symtab
*ps
;
1061 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1063 if (ps
->readin
== 0)
1066 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i
);
1069 /* Psymtab version of dump. See its definition in
1070 the definition of quick_symbol_functions in symfile.h. */
1073 psym_dump (struct objfile
*objfile
)
1075 struct partial_symtab
*psymtab
;
1077 if (objfile
->psymtabs
)
1079 printf_filtered ("Psymtabs:\n");
1080 for (psymtab
= objfile
->psymtabs
;
1082 psymtab
= psymtab
->next
)
1084 printf_filtered ("%s at ",
1086 gdb_print_host_address (psymtab
, gdb_stdout
);
1087 printf_filtered (", ");
1090 printf_filtered ("\n\n");
1094 /* Psymtab version of expand_symtabs_for_function. See its definition in
1095 the definition of quick_symbol_functions in symfile.h. */
1098 psym_expand_symtabs_for_function (struct objfile
*objfile
,
1099 const char *func_name
)
1101 struct partial_symtab
*ps
;
1103 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1108 if ((lookup_partial_symbol (objfile
, ps
, func_name
, 1, VAR_DOMAIN
)
1110 || (lookup_partial_symbol (objfile
, ps
, func_name
, 0, VAR_DOMAIN
)
1112 psymtab_to_symtab (objfile
, ps
);
1116 /* Psymtab version of expand_all_symtabs. See its definition in
1117 the definition of quick_symbol_functions in symfile.h. */
1120 psym_expand_all_symtabs (struct objfile
*objfile
)
1122 struct partial_symtab
*psymtab
;
1124 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, psymtab
)
1126 psymtab_to_symtab (objfile
, psymtab
);
1130 /* Psymtab version of expand_symtabs_with_fullname. See its definition in
1131 the definition of quick_symbol_functions in symfile.h. */
1134 psym_expand_symtabs_with_fullname (struct objfile
*objfile
,
1135 const char *fullname
)
1137 struct partial_symtab
*p
;
1139 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, p
)
1141 /* Anonymous psymtabs don't have a name of a source file. */
1145 /* psymtab_to_fullname tries to open the file which is slow.
1146 Don't call it if we know the basenames don't match. */
1147 if ((basenames_may_differ
1148 || filename_cmp (lbasename (fullname
), lbasename (p
->filename
)) == 0)
1149 && filename_cmp (fullname
, psymtab_to_fullname (p
)) == 0)
1150 psymtab_to_symtab (objfile
, p
);
1154 /* Psymtab version of map_symbol_filenames. See its definition in
1155 the definition of quick_symbol_functions in symfile.h. */
1158 psym_map_symbol_filenames (struct objfile
*objfile
,
1159 symbol_filename_ftype
*fun
, void *data
,
1162 struct partial_symtab
*ps
;
1164 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1166 const char *fullname
;
1171 /* We can skip shared psymtabs here, because any file name will be
1172 attached to the unshared psymtab. */
1173 if (ps
->user
!= NULL
)
1176 /* Anonymous psymtabs don't have a file name. */
1182 fullname
= psymtab_to_fullname (ps
);
1185 (*fun
) (ps
->filename
, fullname
, data
);
1189 /* Finds the fullname that a partial_symtab represents.
1191 If this functions finds the fullname, it will save it in ps->fullname
1192 and it will also return the value.
1194 If this function fails to find the file that this partial_symtab represents,
1195 NULL will be returned and ps->fullname will be set to NULL. */
1198 psymtab_to_fullname (struct partial_symtab
*ps
)
1200 gdb_assert (!ps
->anonymous
);
1202 /* Use cached copy if we have it.
1203 We rely on forget_cached_source_info being called appropriately
1204 to handle cases like the file being moved. */
1205 if (ps
->fullname
== NULL
)
1207 int fd
= find_and_open_source (ps
->filename
, ps
->dirname
, &ps
->fullname
);
1213 gdb::unique_xmalloc_ptr
<char> fullname
;
1215 /* rewrite_source_path would be applied by find_and_open_source, we
1216 should report the pathname where GDB tried to find the file. */
1218 if (ps
->dirname
== NULL
|| IS_ABSOLUTE_PATH (ps
->filename
))
1219 fullname
.reset (xstrdup (ps
->filename
));
1221 fullname
.reset (concat (ps
->dirname
, SLASH_STRING
,
1222 ps
->filename
, (char *) NULL
));
1224 ps
->fullname
= rewrite_source_path (fullname
.get ()).release ();
1225 if (ps
->fullname
== NULL
)
1226 ps
->fullname
= fullname
.release ();
1230 return ps
->fullname
;
1233 /* For all symbols, s, in BLOCK that are in DOMAIN and match NAME
1234 according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
1235 BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK
1236 ever returns non-zero, and otherwise returns 0. */
1239 map_block (const char *name
, domain_enum domain
, struct objfile
*objfile
,
1240 struct block
*block
,
1241 int (*callback
) (struct block
*, struct symbol
*, void *),
1242 void *data
, symbol_name_match_type match
)
1244 struct block_iterator iter
;
1247 lookup_name_info
lookup_name (name
, match
);
1249 for (sym
= block_iter_match_first (block
, lookup_name
, &iter
);
1251 sym
= block_iter_match_next (lookup_name
, &iter
))
1253 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym
),
1254 SYMBOL_DOMAIN (sym
), domain
))
1256 if (callback (block
, sym
, data
))
1264 /* Psymtab version of map_matching_symbols. See its definition in
1265 the definition of quick_symbol_functions in symfile.h. */
1268 psym_map_matching_symbols (struct objfile
*objfile
,
1269 const char *name
, domain_enum domain
,
1271 int (*callback
) (struct block
*,
1272 struct symbol
*, void *),
1274 symbol_name_match_type match
,
1275 symbol_compare_ftype
*ordered_compare
)
1277 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
1278 struct partial_symtab
*ps
;
1280 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1284 || match_partial_symbol (objfile
, ps
, global
, name
, domain
, match
,
1287 struct compunit_symtab
*cust
= psymtab_to_symtab (objfile
, ps
);
1288 struct block
*block
;
1292 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
1293 if (map_block (name
, domain
, objfile
, block
,
1294 callback
, data
, match
))
1296 if (callback (block
, NULL
, data
))
1302 /* A helper for psym_expand_symtabs_matching that handles searching
1303 included psymtabs. This returns true if a symbol is found, and
1304 false otherwise. It also updates the 'searched_flag' on the
1305 various psymtabs that it searches. */
1308 recursively_search_psymtabs
1309 (struct partial_symtab
*ps
, struct objfile
*objfile
, enum search_domain domain
,
1310 const lookup_name_info
&lookup_name
,
1311 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> sym_matcher
)
1314 enum psymtab_search_status result
= PST_SEARCHED_AND_NOT_FOUND
;
1317 if (ps
->searched_flag
!= PST_NOT_SEARCHED
)
1318 return ps
->searched_flag
== PST_SEARCHED_AND_FOUND
;
1320 /* Recurse into shared psymtabs first, because they may have already
1321 been searched, and this could save some time. */
1322 for (i
= 0; i
< ps
->number_of_dependencies
; ++i
)
1326 /* Skip non-shared dependencies, these are handled elsewhere. */
1327 if (ps
->dependencies
[i
]->user
== NULL
)
1330 r
= recursively_search_psymtabs (ps
->dependencies
[i
],
1331 objfile
, domain
, lookup_name
,
1335 ps
->searched_flag
= PST_SEARCHED_AND_FOUND
;
1340 partial_symbol
**gbound
1341 = &objfile
->global_psymbols
[ps
->globals_offset
+ ps
->n_global_syms
];
1342 partial_symbol
**sbound
1343 = &objfile
->static_psymbols
[ps
->statics_offset
+ ps
->n_static_syms
];
1344 partial_symbol
**bound
= gbound
;
1346 /* Go through all of the symbols stored in a partial
1347 symtab in one loop. */
1348 partial_symbol
**psym
= &objfile
->global_psymbols
[ps
->globals_offset
];
1353 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
1355 psym
= &objfile
->static_psymbols
[ps
->statics_offset
];
1366 if ((domain
== ALL_DOMAIN
1367 || (domain
== VARIABLES_DOMAIN
1368 && PSYMBOL_CLASS (*psym
) != LOC_TYPEDEF
1369 && PSYMBOL_CLASS (*psym
) != LOC_BLOCK
)
1370 || (domain
== FUNCTIONS_DOMAIN
1371 && PSYMBOL_CLASS (*psym
) == LOC_BLOCK
)
1372 || (domain
== TYPES_DOMAIN
1373 && PSYMBOL_CLASS (*psym
) == LOC_TYPEDEF
))
1374 && psymbol_name_matches (*psym
, lookup_name
)
1375 && (sym_matcher
== NULL
|| sym_matcher (SYMBOL_SEARCH_NAME (*psym
))))
1377 /* Found a match, so notify our caller. */
1378 result
= PST_SEARCHED_AND_FOUND
;
1385 ps
->searched_flag
= result
;
1386 return result
== PST_SEARCHED_AND_FOUND
;
1389 /* Psymtab version of expand_symtabs_matching. See its definition in
1390 the definition of quick_symbol_functions in symfile.h. */
1393 psym_expand_symtabs_matching
1394 (struct objfile
*objfile
,
1395 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
1396 const lookup_name_info
&lookup_name_in
,
1397 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
1398 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
1399 enum search_domain domain
)
1401 struct partial_symtab
*ps
;
1403 lookup_name_info lookup_name
= lookup_name_in
.make_ignore_params ();
1405 /* Clear the search flags. */
1406 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1408 ps
->searched_flag
= PST_NOT_SEARCHED
;
1411 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1418 /* We skip shared psymtabs because file-matching doesn't apply
1419 to them; but we search them later in the loop. */
1420 if (ps
->user
!= NULL
)
1430 match
= file_matcher (ps
->filename
, false);
1433 /* Before we invoke realpath, which can get expensive when many
1434 files are involved, do a quick comparison of the basenames. */
1435 if (basenames_may_differ
1436 || file_matcher (lbasename (ps
->filename
), true))
1437 match
= file_matcher (psymtab_to_fullname (ps
), false);
1443 if (recursively_search_psymtabs (ps
, objfile
, domain
,
1444 lookup_name
, symbol_matcher
))
1446 struct compunit_symtab
*symtab
=
1447 psymtab_to_symtab (objfile
, ps
);
1449 if (expansion_notify
!= NULL
)
1450 expansion_notify (symtab
);
1455 /* Psymtab version of has_symbols. See its definition in
1456 the definition of quick_symbol_functions in symfile.h. */
1459 psym_has_symbols (struct objfile
*objfile
)
1461 return objfile
->psymtabs
!= NULL
;
1464 /* Helper function for psym_find_compunit_symtab_by_address that fills
1465 in psymbol_map for a given range of psymbols. */
1468 psym_fill_psymbol_map (struct objfile
*objfile
,
1469 struct partial_symtab
*psymtab
,
1470 std::set
<CORE_ADDR
> *seen_addrs
,
1471 const std::vector
<partial_symbol
*> &symbols
,
1475 for (int i
= 0; i
< length
; ++i
)
1477 struct partial_symbol
*psym
= symbols
[start
+ i
];
1479 if (PSYMBOL_CLASS (psym
) == LOC_STATIC
)
1481 CORE_ADDR addr
= SYMBOL_VALUE_ADDRESS (psym
);
1482 if (seen_addrs
->find (addr
) == seen_addrs
->end ())
1484 seen_addrs
->insert (addr
);
1485 objfile
->psymbol_map
.emplace_back (addr
, psymtab
);
1491 /* See find_compunit_symtab_by_address in quick_symbol_functions, in
1494 static compunit_symtab
*
1495 psym_find_compunit_symtab_by_address (struct objfile
*objfile
,
1498 if (objfile
->psymbol_map
.empty ())
1500 struct partial_symtab
*pst
;
1502 std::set
<CORE_ADDR
> seen_addrs
;
1504 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
1506 psym_fill_psymbol_map (objfile
, pst
,
1508 objfile
->global_psymbols
,
1509 pst
->globals_offset
,
1510 pst
->n_global_syms
);
1511 psym_fill_psymbol_map (objfile
, pst
,
1513 objfile
->static_psymbols
,
1514 pst
->statics_offset
,
1515 pst
->n_static_syms
);
1518 objfile
->psymbol_map
.shrink_to_fit ();
1520 std::sort (objfile
->psymbol_map
.begin (), objfile
->psymbol_map
.end (),
1521 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1522 const std::pair
<CORE_ADDR
, partial_symtab
*> &b
)
1524 return a
.first
< b
.first
;
1528 auto iter
= std::lower_bound
1529 (objfile
->psymbol_map
.begin (), objfile
->psymbol_map
.end (), address
,
1530 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1536 if (iter
== objfile
->psymbol_map
.end () || iter
->first
!= address
)
1539 return psymtab_to_symtab (objfile
, iter
->second
);
1542 const struct quick_symbol_functions psym_functions
=
1545 psym_find_last_source_symtab
,
1546 psym_forget_cached_source_info
,
1547 psym_map_symtabs_matching_filename
,
1552 psym_expand_symtabs_for_function
,
1553 psym_expand_all_symtabs
,
1554 psym_expand_symtabs_with_fullname
,
1555 psym_map_matching_symbols
,
1556 psym_expand_symtabs_matching
,
1557 psym_find_pc_sect_compunit_symtab
,
1558 psym_find_compunit_symtab_by_address
,
1559 psym_map_symbol_filenames
1565 sort_pst_symbols (struct objfile
*objfile
, struct partial_symtab
*pst
)
1567 /* Sort the global list; don't sort the static list. */
1568 auto begin
= objfile
->global_psymbols
.begin ();
1569 std::advance (begin
, pst
->globals_offset
);
1571 /* The psymbols for this partial_symtab are currently at the end of the
1573 auto end
= objfile
->global_psymbols
.end ();
1575 std::sort (begin
, end
, [] (partial_symbol
*s1
, partial_symbol
*s2
)
1577 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (s1
),
1578 SYMBOL_SEARCH_NAME (s2
)) < 0;
1582 /* Allocate and partially fill a partial symtab. It will be
1583 completely filled at the end of the symbol list.
1585 FILENAME is the name of the symbol-file we are reading from. */
1587 struct partial_symtab
*
1588 start_psymtab_common (struct objfile
*objfile
,
1589 const char *filename
,
1591 std::vector
<partial_symbol
*> &global_psymbols
,
1592 std::vector
<partial_symbol
*> &static_psymbols
)
1594 struct partial_symtab
*psymtab
;
1596 psymtab
= allocate_psymtab (filename
, objfile
);
1597 psymtab
->textlow
= textlow
;
1598 psymtab
->texthigh
= psymtab
->textlow
; /* default */
1599 psymtab
->globals_offset
= global_psymbols
.size ();
1600 psymtab
->statics_offset
= static_psymbols
.size ();
1604 /* Perform "finishing up" operations of a partial symtab. */
1607 end_psymtab_common (struct objfile
*objfile
, struct partial_symtab
*pst
)
1609 pst
->n_global_syms
= objfile
->global_psymbols
.size () - pst
->globals_offset
;
1610 pst
->n_static_syms
= objfile
->static_psymbols
.size () - pst
->statics_offset
;
1612 sort_pst_symbols (objfile
, pst
);
1615 /* Calculate a hash code for the given partial symbol. The hash is
1616 calculated using the symbol's value, language, domain, class
1617 and name. These are the values which are set by
1618 add_psymbol_to_bcache. */
1620 static unsigned long
1621 psymbol_hash (const void *addr
, int length
)
1623 unsigned long h
= 0;
1624 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1625 unsigned int lang
= psymbol
->ginfo
.language
;
1626 unsigned int domain
= PSYMBOL_DOMAIN (psymbol
);
1627 unsigned int theclass
= PSYMBOL_CLASS (psymbol
);
1629 h
= hash_continue (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1630 h
= hash_continue (&lang
, sizeof (unsigned int), h
);
1631 h
= hash_continue (&domain
, sizeof (unsigned int), h
);
1632 h
= hash_continue (&theclass
, sizeof (unsigned int), h
);
1633 /* Note that psymbol names are interned via symbol_set_names, so
1634 there's no need to hash the contents of the name here. */
1635 h
= hash_continue (&psymbol
->ginfo
.name
, sizeof (psymbol
->ginfo
.name
), h
);
1640 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1641 For the comparison this function uses a symbols value,
1642 language, domain, class and name. */
1645 psymbol_compare (const void *addr1
, const void *addr2
, int length
)
1647 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1648 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1650 return (memcmp (&sym1
->ginfo
.value
, &sym2
->ginfo
.value
,
1651 sizeof (sym1
->ginfo
.value
)) == 0
1652 && sym1
->ginfo
.language
== sym2
->ginfo
.language
1653 && PSYMBOL_DOMAIN (sym1
) == PSYMBOL_DOMAIN (sym2
)
1654 && PSYMBOL_CLASS (sym1
) == PSYMBOL_CLASS (sym2
)
1655 /* Note that psymbol names are interned via
1656 symbol_set_names, so there's no need to compare the
1657 contents of the name here. */
1658 && sym1
->ginfo
.name
== sym2
->ginfo
.name
);
1661 /* Initialize a partial symbol bcache. */
1663 struct psymbol_bcache
*
1664 psymbol_bcache_init (void)
1666 struct psymbol_bcache
*bcache
= XCNEW (struct psymbol_bcache
);
1668 bcache
->bcache
= bcache_xmalloc (psymbol_hash
, psymbol_compare
);
1672 /* Free a partial symbol bcache. */
1675 psymbol_bcache_free (struct psymbol_bcache
*bcache
)
1680 bcache_xfree (bcache
->bcache
);
1684 /* Return the internal bcache of the psymbol_bcache BCACHE. */
1687 psymbol_bcache_get_bcache (struct psymbol_bcache
*bcache
)
1689 return bcache
->bcache
;
1692 /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1693 symbol before, add a copy to BCACHE. In either case, return a pointer
1694 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1695 1 in case of new entry or 0 if returning an old entry. */
1697 static struct partial_symbol
*
1698 psymbol_bcache_full (struct partial_symbol
*sym
,
1699 struct psymbol_bcache
*bcache
,
1702 return ((struct partial_symbol
*)
1703 bcache_full (sym
, sizeof (struct partial_symbol
), bcache
->bcache
,
1707 /* Helper function, initialises partial symbol structure and stashes
1708 it into objfile's bcache. Note that our caching mechanism will
1709 use all fields of struct partial_symbol to determine hash value of the
1710 structure. In other words, having two symbols with the same name but
1711 different domain (or address) is possible and correct. */
1713 static struct partial_symbol
*
1714 add_psymbol_to_bcache (const char *name
, int namelength
, int copy_name
,
1716 enum address_class theclass
,
1718 enum language language
, struct objfile
*objfile
,
1721 struct partial_symbol psymbol
;
1723 /* We must ensure that the entire struct has been zeroed before
1724 assigning to it, because an assignment may not touch some of the
1726 memset (&psymbol
, 0, sizeof (psymbol
));
1728 SYMBOL_VALUE_ADDRESS (&psymbol
) = coreaddr
;
1729 SYMBOL_SECTION (&psymbol
) = -1;
1730 SYMBOL_SET_LANGUAGE (&psymbol
, language
, &objfile
->objfile_obstack
);
1731 PSYMBOL_DOMAIN (&psymbol
) = domain
;
1732 PSYMBOL_CLASS (&psymbol
) = theclass
;
1734 SYMBOL_SET_NAMES (&psymbol
, name
, namelength
, copy_name
, objfile
);
1736 /* Stash the partial symbol away in the cache. */
1737 return psymbol_bcache_full (&psymbol
, objfile
->psymbol_cache
, added
);
1740 /* Helper function, adds partial symbol to the given partial symbol list. */
1743 append_psymbol_to_list (std::vector
<partial_symbol
*> *list
,
1744 struct partial_symbol
*psym
,
1745 struct objfile
*objfile
)
1747 list
->push_back (psym
);
1748 OBJSTAT (objfile
, n_psyms
++);
1751 /* Add a symbol with a long value to a psymtab.
1752 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1753 The only value we need to store for psyms is an address.
1754 For all other psyms pass zero for COREADDR.
1755 Return the partial symbol that has been added. */
1758 add_psymbol_to_list (const char *name
, int namelength
, int copy_name
,
1760 enum address_class theclass
,
1761 std::vector
<partial_symbol
*> *list
,
1763 enum language language
, struct objfile
*objfile
)
1765 struct partial_symbol
*psym
;
1769 /* Stash the partial symbol away in the cache. */
1770 psym
= add_psymbol_to_bcache (name
, namelength
, copy_name
, domain
, theclass
,
1771 coreaddr
, language
, objfile
, &added
);
1773 /* Do not duplicate global partial symbols. */
1774 if (list
== &objfile
->global_psymbols
1778 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1779 append_psymbol_to_list (list
, psym
, objfile
);
1782 /* Initialize storage for partial symbols. */
1785 init_psymbol_list (struct objfile
*objfile
, int total_symbols
)
1787 /* Free any previously allocated psymbol lists. */
1788 objfile
->global_psymbols
.clear ();
1789 objfile
->static_psymbols
.clear ();
1791 /* Current best guess is that approximately a twentieth
1792 of the total symbols (in a debugging file) are global or static
1793 oriented symbols, then multiply that by slop factor of two. */
1794 objfile
->global_psymbols
.reserve (total_symbols
/ 10);
1795 objfile
->static_psymbols
.reserve (total_symbols
/ 10);
1798 struct partial_symtab
*
1799 allocate_psymtab (const char *filename
, struct objfile
*objfile
)
1801 struct partial_symtab
*psymtab
;
1803 if (objfile
->free_psymtabs
)
1805 psymtab
= objfile
->free_psymtabs
;
1806 objfile
->free_psymtabs
= psymtab
->next
;
1809 psymtab
= (struct partial_symtab
*)
1810 obstack_alloc (&objfile
->objfile_obstack
,
1811 sizeof (struct partial_symtab
));
1813 memset (psymtab
, 0, sizeof (struct partial_symtab
));
1815 = (const char *) bcache (filename
, strlen (filename
) + 1,
1816 objfile
->per_bfd
->filename_cache
);
1817 psymtab
->compunit_symtab
= NULL
;
1819 /* Prepend it to the psymtab list for the objfile it belongs to.
1820 Psymtabs are searched in most recent inserted -> least recent
1823 psymtab
->next
= objfile
->psymtabs
;
1824 objfile
->psymtabs
= psymtab
;
1826 if (symtab_create_debug
)
1828 /* Be a bit clever with debugging messages, and don't print objfile
1829 every time, only when it changes. */
1830 static char *last_objfile_name
= NULL
;
1832 if (last_objfile_name
== NULL
1833 || strcmp (last_objfile_name
, objfile_name (objfile
)) != 0)
1835 xfree (last_objfile_name
);
1836 last_objfile_name
= xstrdup (objfile_name (objfile
));
1837 fprintf_unfiltered (gdb_stdlog
,
1838 "Creating one or more psymtabs for objfile %s ...\n",
1841 fprintf_unfiltered (gdb_stdlog
,
1842 "Created psymtab %s for module %s.\n",
1843 host_address_to_string (psymtab
), filename
);
1850 discard_psymtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
1852 struct partial_symtab
**prev_pst
;
1855 Empty psymtabs happen as a result of header files which don't
1856 have any symbols in them. There can be a lot of them. But this
1857 check is wrong, in that a psymtab with N_SLINE entries but
1858 nothing else is not empty, but we don't realize that. Fixing
1859 that without slowing things down might be tricky. */
1861 /* First, snip it out of the psymtab chain. */
1863 prev_pst
= &(objfile
->psymtabs
);
1864 while ((*prev_pst
) != pst
)
1865 prev_pst
= &((*prev_pst
)->next
);
1866 (*prev_pst
) = pst
->next
;
1868 /* Next, put it on a free list for recycling. */
1870 pst
->next
= objfile
->free_psymtabs
;
1871 objfile
->free_psymtabs
= pst
;
1876 /* We need to pass a couple of items to the addrmap_foreach function,
1879 struct dump_psymtab_addrmap_data
1881 struct objfile
*objfile
;
1882 struct partial_symtab
*psymtab
;
1883 struct ui_file
*outfile
;
1885 /* Non-zero if the previously printed addrmap entry was for PSYMTAB.
1886 If so, we want to print the next one as well (since the next addrmap
1887 entry defines the end of the range). */
1888 int previous_matched
;
1891 /* Helper function for dump_psymtab_addrmap to print an addrmap entry. */
1894 dump_psymtab_addrmap_1 (void *datap
, CORE_ADDR start_addr
, void *obj
)
1896 struct dump_psymtab_addrmap_data
*data
1897 = (struct dump_psymtab_addrmap_data
*) datap
;
1898 struct gdbarch
*gdbarch
= get_objfile_arch (data
->objfile
);
1899 struct partial_symtab
*addrmap_psymtab
= (struct partial_symtab
*) obj
;
1900 const char *psymtab_address_or_end
= NULL
;
1904 if (data
->psymtab
== NULL
1905 || data
->psymtab
== addrmap_psymtab
)
1906 psymtab_address_or_end
= host_address_to_string (addrmap_psymtab
);
1907 else if (data
->previous_matched
)
1908 psymtab_address_or_end
= "<ends here>";
1910 if (data
->psymtab
== NULL
1911 || data
->psymtab
== addrmap_psymtab
1912 || data
->previous_matched
)
1914 fprintf_filtered (data
->outfile
, " %s%s %s\n",
1915 data
->psymtab
!= NULL
? " " : "",
1916 paddress (gdbarch
, start_addr
),
1917 psymtab_address_or_end
);
1920 data
->previous_matched
= (data
->psymtab
== NULL
1921 || data
->psymtab
== addrmap_psymtab
);
1926 /* Helper function for maintenance_print_psymbols to print the addrmap
1927 of PSYMTAB. If PSYMTAB is NULL print the entire addrmap. */
1930 dump_psymtab_addrmap (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
1931 struct ui_file
*outfile
)
1933 struct dump_psymtab_addrmap_data addrmap_dump_data
;
1935 if ((psymtab
== NULL
1936 || psymtab
->psymtabs_addrmap_supported
)
1937 && objfile
->psymtabs_addrmap
!= NULL
)
1939 addrmap_dump_data
.objfile
= objfile
;
1940 addrmap_dump_data
.psymtab
= psymtab
;
1941 addrmap_dump_data
.outfile
= outfile
;
1942 addrmap_dump_data
.previous_matched
= 0;
1943 fprintf_filtered (outfile
, "%sddress map:\n",
1944 psymtab
== NULL
? "Entire a" : " A");
1945 addrmap_foreach (objfile
->psymtabs_addrmap
, dump_psymtab_addrmap_1
,
1946 &addrmap_dump_data
);
1951 maintenance_print_psymbols (const char *args
, int from_tty
)
1953 struct ui_file
*outfile
= gdb_stdout
;
1954 char *address_arg
= NULL
, *source_arg
= NULL
, *objfile_arg
= NULL
;
1955 struct objfile
*objfile
;
1956 struct partial_symtab
*ps
;
1957 int i
, outfile_idx
, found
;
1959 struct obj_section
*section
= NULL
;
1963 gdb_argv
argv (args
);
1965 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
1967 if (strcmp (argv
[i
], "-pc") == 0)
1969 if (argv
[i
+ 1] == NULL
)
1970 error (_("Missing pc value"));
1971 address_arg
= argv
[++i
];
1973 else if (strcmp (argv
[i
], "-source") == 0)
1975 if (argv
[i
+ 1] == NULL
)
1976 error (_("Missing source file"));
1977 source_arg
= argv
[++i
];
1979 else if (strcmp (argv
[i
], "-objfile") == 0)
1981 if (argv
[i
+ 1] == NULL
)
1982 error (_("Missing objfile name"));
1983 objfile_arg
= argv
[++i
];
1985 else if (strcmp (argv
[i
], "--") == 0)
1987 /* End of options. */
1991 else if (argv
[i
][0] == '-')
1993 /* Future proofing: Don't allow OUTFILE to begin with "-". */
1994 error (_("Unknown option: %s"), argv
[i
]);
2001 if (address_arg
!= NULL
&& source_arg
!= NULL
)
2002 error (_("Must specify at most one of -pc and -source"));
2004 stdio_file arg_outfile
;
2006 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
2008 if (argv
[outfile_idx
+ 1] != NULL
)
2009 error (_("Junk at end of command"));
2010 gdb::unique_xmalloc_ptr
<char> outfile_name
2011 (tilde_expand (argv
[outfile_idx
]));
2012 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
2013 perror_with_name (outfile_name
.get ());
2014 outfile
= &arg_outfile
;
2017 if (address_arg
!= NULL
)
2019 pc
= parse_and_eval_address (address_arg
);
2020 /* If we fail to find a section, that's ok, try the lookup anyway. */
2021 section
= find_pc_section (pc
);
2025 ALL_OBJFILES (objfile
)
2027 int printed_objfile_header
= 0;
2028 int print_for_objfile
= 1;
2031 if (objfile_arg
!= NULL
)
2033 = compare_filenames_for_search (objfile_name (objfile
),
2035 if (!print_for_objfile
)
2038 if (address_arg
!= NULL
)
2040 struct bound_minimal_symbol msymbol
= { NULL
, NULL
};
2042 /* We don't assume each pc has a unique objfile (this is for
2044 ps
= find_pc_sect_psymtab (objfile
, pc
, section
, msymbol
);
2047 if (!printed_objfile_header
)
2049 outfile
->printf ("\nPartial symtabs for objfile %s\n",
2050 objfile_name (objfile
));
2051 printed_objfile_header
= 1;
2053 dump_psymtab (objfile
, ps
, outfile
);
2054 dump_psymtab_addrmap (objfile
, ps
, outfile
);
2060 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
2062 int print_for_source
= 0;
2065 if (source_arg
!= NULL
)
2068 = compare_filenames_for_search (ps
->filename
, source_arg
);
2071 if (source_arg
== NULL
2072 || print_for_source
)
2074 if (!printed_objfile_header
)
2076 outfile
->printf ("\nPartial symtabs for objfile %s\n",
2077 objfile_name (objfile
));
2078 printed_objfile_header
= 1;
2080 dump_psymtab (objfile
, ps
, outfile
);
2081 dump_psymtab_addrmap (objfile
, ps
, outfile
);
2086 /* If we're printing all the objfile's symbols dump the full addrmap. */
2088 if (address_arg
== NULL
2089 && source_arg
== NULL
2090 && objfile
->psymtabs_addrmap
!= NULL
)
2092 outfile
->puts ("\n");
2093 dump_psymtab_addrmap (objfile
, NULL
, outfile
);
2099 if (address_arg
!= NULL
)
2100 error (_("No partial symtab for address: %s"), address_arg
);
2101 if (source_arg
!= NULL
)
2102 error (_("No partial symtab for source file: %s"), source_arg
);
2106 /* List all the partial symbol tables whose names match REGEXP (optional). */
2109 maintenance_info_psymtabs (const char *regexp
, int from_tty
)
2111 struct program_space
*pspace
;
2112 struct objfile
*objfile
;
2117 ALL_PSPACES (pspace
)
2118 ALL_PSPACE_OBJFILES (pspace
, objfile
)
2120 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2121 struct partial_symtab
*psymtab
;
2123 /* We don't want to print anything for this objfile until we
2124 actually find a symtab whose name matches. */
2125 int printed_objfile_start
= 0;
2127 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, psymtab
)
2132 || re_exec (psymtab
->filename
))
2134 if (! printed_objfile_start
)
2136 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
2138 printf_filtered ("((struct objfile *) %s)\n",
2139 host_address_to_string (objfile
));
2140 printed_objfile_start
= 1;
2143 printf_filtered (" { psymtab %s ", psymtab
->filename
);
2145 printf_filtered ("((struct partial_symtab *) %s)\n",
2146 host_address_to_string (psymtab
));
2148 printf_filtered (" readin %s\n",
2149 psymtab
->readin
? "yes" : "no");
2150 printf_filtered (" fullname %s\n",
2152 ? psymtab
->fullname
: "(null)");
2153 printf_filtered (" text addresses ");
2154 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
),
2156 printf_filtered (" -- ");
2157 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
),
2159 printf_filtered ("\n");
2160 printf_filtered (" psymtabs_addrmap_supported %s\n",
2161 (psymtab
->psymtabs_addrmap_supported
2163 printf_filtered (" globals ");
2164 if (psymtab
->n_global_syms
)
2166 auto p
= &objfile
->global_psymbols
[psymtab
->globals_offset
];
2168 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
2169 host_address_to_string (p
),
2170 psymtab
->n_global_syms
);
2173 printf_filtered ("(none)\n");
2174 printf_filtered (" statics ");
2175 if (psymtab
->n_static_syms
)
2177 auto p
= &objfile
->static_psymbols
[psymtab
->statics_offset
];
2179 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
2180 host_address_to_string (p
),
2181 psymtab
->n_static_syms
);
2184 printf_filtered ("(none)\n");
2185 printf_filtered (" dependencies ");
2186 if (psymtab
->number_of_dependencies
)
2190 printf_filtered ("{\n");
2191 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
2193 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
2195 /* Note the string concatenation there --- no comma. */
2196 printf_filtered (" psymtab %s "
2197 "((struct partial_symtab *) %s)\n",
2199 host_address_to_string (dep
));
2201 printf_filtered (" }\n");
2204 printf_filtered ("(none)\n");
2205 printf_filtered (" }\n");
2209 if (printed_objfile_start
)
2210 printf_filtered ("}\n");
2214 /* Check consistency of currently expanded psymtabs vs symtabs. */
2217 maintenance_check_psymtabs (const char *ignore
, int from_tty
)
2220 struct compunit_symtab
*cust
= NULL
;
2221 struct partial_symtab
*ps
;
2222 const struct blockvector
*bv
;
2223 struct objfile
*objfile
;
2227 ALL_PSYMTABS (objfile
, ps
)
2229 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2231 /* We don't call psymtab_to_symtab here because that may cause symtab
2232 expansion. When debugging a problem it helps if checkers leave
2233 things unchanged. */
2234 cust
= ps
->compunit_symtab
;
2236 /* First do some checks that don't require the associated symtab. */
2237 if (ps
->texthigh
< ps
->textlow
)
2239 printf_filtered ("Psymtab ");
2240 puts_filtered (ps
->filename
);
2241 printf_filtered (" covers bad range ");
2242 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
2243 printf_filtered (" - ");
2244 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
2245 printf_filtered ("\n");
2249 /* Now do checks requiring the associated symtab. */
2252 bv
= COMPUNIT_BLOCKVECTOR (cust
);
2253 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
2254 partial_symbol
**psym
= &objfile
->static_psymbols
[ps
->statics_offset
];
2255 length
= ps
->n_static_syms
;
2258 sym
= block_lookup_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
2259 SYMBOL_DOMAIN (*psym
));
2262 printf_filtered ("Static symbol `");
2263 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
2264 printf_filtered ("' only found in ");
2265 puts_filtered (ps
->filename
);
2266 printf_filtered (" psymtab\n");
2270 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2271 psym
= &objfile
->global_psymbols
[ps
->globals_offset
];
2272 length
= ps
->n_global_syms
;
2275 sym
= block_lookup_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
2276 SYMBOL_DOMAIN (*psym
));
2279 printf_filtered ("Global symbol `");
2280 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
2281 printf_filtered ("' only found in ");
2282 puts_filtered (ps
->filename
);
2283 printf_filtered (" psymtab\n");
2287 if (ps
->texthigh
!= 0
2288 && (ps
->textlow
< BLOCK_START (b
) || ps
->texthigh
> BLOCK_END (b
)))
2290 printf_filtered ("Psymtab ");
2291 puts_filtered (ps
->filename
);
2292 printf_filtered (" covers ");
2293 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
2294 printf_filtered (" - ");
2295 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
2296 printf_filtered (" but symtab covers only ");
2297 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
2298 printf_filtered (" - ");
2299 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
2300 printf_filtered ("\n");
2306 _initialize_psymtab (void)
2308 add_cmd ("psymbols", class_maintenance
, maintenance_print_psymbols
, _("\
2309 Print dump of current partial symbol definitions.\n\
2310 Usage: mt print psymbols [-objfile objfile] [-pc address] [--] [outfile]\n\
2311 mt print psymbols [-objfile objfile] [-source source] [--] [outfile]\n\
2312 Entries in the partial symbol table are dumped to file OUTFILE,\n\
2313 or the terminal if OUTFILE is unspecified.\n\
2314 If ADDRESS is provided, dump only the file for that address.\n\
2315 If SOURCE is provided, dump only that file's symbols.\n\
2316 If OBJFILE is provided, dump only that file's minimal symbols."),
2317 &maintenanceprintlist
);
2319 add_cmd ("psymtabs", class_maintenance
, maintenance_info_psymtabs
, _("\
2320 List the partial symbol tables for all object files.\n\
2321 This does not include information about individual partial symbols,\n\
2322 just the symbol table structures themselves."),
2323 &maintenanceinfolist
);
2325 add_cmd ("check-psymtabs", class_maintenance
, maintenance_check_psymtabs
,
2327 Check consistency of currently expanded psymtabs versus symtabs."),