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 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better
305 granularity than the later used TEXTLOW/TEXTHIGH one. However, we need
306 to take care as the PSYMTABS_ADDRMAP can hold things other than partial
307 symtabs in some cases.
309 This function should only be called for objfiles that are using partial
310 symtabs, not for objfiles that are using indexes (.gdb_index or
311 .debug_names), however 'maintenance print psymbols' calls this function
312 directly for all objfiles. If we assume that PSYMTABS_ADDRMAP contains
313 partial symtabs then we will end up returning a pointer to an object
314 that is not a partial_symtab, which doesn't end well. */
316 if (objfile
->partial_symtabs
->psymtabs
!= NULL
317 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
319 CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
320 SECT_OFF_TEXT (objfile
));
322 struct partial_symtab
*pst
323 = ((struct partial_symtab
*)
324 addrmap_find (objfile
->partial_symtabs
->psymtabs_addrmap
,
328 /* FIXME: addrmaps currently do not handle overlayed sections,
329 so fall back to the non-addrmap case if we're debugging
330 overlays and the addrmap returned the wrong section. */
331 if (overlay_debugging
&& msymbol
.minsym
!= NULL
&& section
!= NULL
)
333 struct partial_symbol
*p
;
335 /* NOTE: This assumes that every psymbol has a
336 corresponding msymbol, which is not necessarily
337 true; the debug info might be much richer than the
338 object's symbol table. */
339 p
= find_pc_sect_psymbol (objfile
, pst
, pc
, section
);
341 || (p
->address (objfile
)
342 != BMSYMBOL_VALUE_ADDRESS (msymbol
)))
346 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
347 PSYMTABS_ADDRMAP we used has already the best 1-byte
348 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
349 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
358 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
359 which still have no corresponding full SYMTABs read. But it is not
360 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
363 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
364 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
365 debug info type in single OBJFILE. */
367 for (partial_symtab
*pst
: require_partial_symbols (objfile
, 1))
368 if (!pst
->psymtabs_addrmap_supported
369 && pc
>= pst
->text_low (objfile
) && pc
< pst
->text_high (objfile
))
371 struct partial_symtab
*best_pst
;
373 best_pst
= find_pc_sect_psymtab_closer (objfile
, pc
, section
, pst
,
375 if (best_pst
!= NULL
)
382 /* Psymtab version of find_pc_sect_compunit_symtab. See its definition in
383 the definition of quick_symbol_functions in symfile.h. */
385 static struct compunit_symtab
*
386 psym_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
387 struct bound_minimal_symbol msymbol
,
389 struct obj_section
*section
,
392 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
, section
,
396 if (warn_if_readin
&& ps
->readin
)
397 /* Might want to error() here (in case symtab is corrupt and
398 will cause a core dump), but maybe we can successfully
399 continue, so let's not. */
401 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
402 paddress (get_objfile_arch (objfile
), pc
));
403 psymtab_to_symtab (objfile
, ps
);
404 return ps
->compunit_symtab
;
409 /* Find which partial symbol within a psymtab matches PC and SECTION.
410 Return NULL if none. */
412 static struct partial_symbol
*
413 find_pc_sect_psymbol (struct objfile
*objfile
,
414 struct partial_symtab
*psymtab
, CORE_ADDR pc
,
415 struct obj_section
*section
)
417 struct partial_symbol
*best
= NULL
;
419 const CORE_ADDR textlow
= psymtab
->text_low (objfile
);
421 gdb_assert (psymtab
!= NULL
);
423 /* Cope with programs that start at address 0. */
424 best_pc
= (textlow
!= 0) ? textlow
- 1 : 0;
426 /* Search the global symbols as well as the static symbols, so that
427 find_pc_partial_function doesn't use a minimal symbol and thus
428 cache a bad endaddr. */
429 for (int i
= 0; i
< psymtab
->n_global_syms
; i
++)
432 = objfile
->partial_symtabs
->global_psymbols
[psymtab
->globals_offset
435 if (p
->domain
== VAR_DOMAIN
436 && p
->aclass
== LOC_BLOCK
437 && pc
>= p
->address (objfile
)
438 && (p
->address (objfile
) > best_pc
439 || (psymtab
->text_low (objfile
) == 0
440 && best_pc
== 0 && p
->address (objfile
) == 0)))
442 if (section
!= NULL
) /* Match on a specific section. */
444 if (!matching_obj_sections (p
->obj_section (objfile
),
448 best_pc
= p
->address (objfile
);
453 for (int i
= 0; i
< psymtab
->n_static_syms
; i
++)
456 = objfile
->partial_symtabs
->static_psymbols
[psymtab
->statics_offset
459 if (p
->domain
== VAR_DOMAIN
460 && p
->aclass
== LOC_BLOCK
461 && pc
>= p
->address (objfile
)
462 && (p
->address (objfile
) > best_pc
463 || (psymtab
->text_low (objfile
) == 0
464 && best_pc
== 0 && p
->address (objfile
) == 0)))
466 if (section
!= NULL
) /* Match on a specific section. */
468 if (!matching_obj_sections (p
->obj_section (objfile
),
472 best_pc
= p
->address (objfile
);
480 /* Psymtab version of lookup_symbol. See its definition in
481 the definition of quick_symbol_functions in symfile.h. */
483 static struct compunit_symtab
*
484 psym_lookup_symbol (struct objfile
*objfile
,
485 block_enum block_index
, const char *name
,
486 const domain_enum domain
)
488 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
489 struct compunit_symtab
*stab_best
= NULL
;
491 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
493 for (partial_symtab
*ps
: require_partial_symbols (objfile
, 1))
495 if (!ps
->readin
&& lookup_partial_symbol (objfile
, ps
, name
,
496 psymtab_index
, domain
))
498 struct symbol
*sym
, *with_opaque
= NULL
;
499 struct compunit_symtab
*stab
= psymtab_to_symtab (objfile
, ps
);
500 /* Note: While psymtab_to_symtab can return NULL if the
501 partial symtab is empty, we can assume it won't here
502 because lookup_partial_symbol succeeded. */
503 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
504 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
506 sym
= block_find_symbol (block
, name
, domain
,
507 block_find_non_opaque_type_preferred
,
510 /* Some caution must be observed with overloaded functions
511 and methods, since the index will not contain any overload
512 information (but NAME might contain it). */
515 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
517 if (with_opaque
!= NULL
518 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
521 /* Keep looking through other psymtabs. */
528 /* Returns true if PSYM matches LOOKUP_NAME. */
531 psymbol_name_matches (partial_symbol
*psym
,
532 const lookup_name_info
&lookup_name
)
534 const language_defn
*lang
= language_def (psym
->ginfo
.language
);
535 symbol_name_matcher_ftype
*name_match
536 = get_symbol_name_matcher (lang
, lookup_name
);
537 return name_match (symbol_search_name (&psym
->ginfo
), lookup_name
, NULL
);
540 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
541 the global block of PST if GLOBAL, and otherwise the static block.
542 MATCH is the comparison operation that returns true iff MATCH (s,
543 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
544 non-null, the symbols in the block are assumed to be ordered
545 according to it (allowing binary search). It must be compatible
546 with MATCH. Returns the symbol, if found, and otherwise NULL. */
548 static struct partial_symbol
*
549 match_partial_symbol (struct objfile
*objfile
,
550 struct partial_symtab
*pst
, int global
,
551 const lookup_name_info
&name
, domain_enum domain
,
552 symbol_compare_ftype
*ordered_compare
)
554 struct partial_symbol
**start
, **psym
;
555 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
556 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
557 int do_linear_search
= 1;
563 &objfile
->partial_symtabs
->global_psymbols
[pst
->globals_offset
] :
564 &objfile
->partial_symtabs
->static_psymbols
[pst
->statics_offset
]);
566 if (global
&& ordered_compare
) /* Can use a binary search. */
568 do_linear_search
= 0;
570 /* Binary search. This search is guaranteed to end with center
571 pointing at the earliest partial symbol whose name might be
572 correct. At that point *all* partial symbols with an
573 appropriate name will be checked against the correct
577 top
= start
+ length
- 1;
581 center
= bottom
+ (top
- bottom
) / 2;
582 gdb_assert (center
< top
);
584 enum language lang
= (*center
)->ginfo
.language
;
586 = name
.language_lookup_name (lang
).c_str ();
588 if (ordered_compare (symbol_search_name (&(*center
)->ginfo
),
594 gdb_assert (top
== bottom
);
596 while (top
<= real_top
597 && psymbol_name_matches (*top
, name
))
599 if (symbol_matches_domain ((*top
)->ginfo
.language
,
600 (*top
)->domain
, domain
))
606 /* Can't use a binary search or else we found during the binary search that
607 we should also do a linear search. */
609 if (do_linear_search
)
611 for (psym
= start
; psym
< start
+ length
; psym
++)
613 if (symbol_matches_domain ((*psym
)->ginfo
.language
,
614 (*psym
)->domain
, domain
)
615 && psymbol_name_matches (*psym
, name
))
623 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
624 not contain any method/function instance information (since this would
625 force reading type information while reading psymtabs). Therefore,
626 if NAME contains overload information, it must be stripped before searching
629 static gdb::unique_xmalloc_ptr
<char>
630 psymtab_search_name (const char *name
)
632 switch (current_language
->la_language
)
636 if (strchr (name
, '('))
638 gdb::unique_xmalloc_ptr
<char> ret
= cp_remove_params (name
);
650 return make_unique_xstrdup (name
);
653 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
654 Check the global symbols if GLOBAL, the static symbols if not. */
656 static struct partial_symbol
*
657 lookup_partial_symbol (struct objfile
*objfile
,
658 struct partial_symtab
*pst
, const char *name
,
659 int global
, domain_enum domain
)
661 struct partial_symbol
**start
, **psym
;
662 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
663 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
664 int do_linear_search
= 1;
669 gdb::unique_xmalloc_ptr
<char> search_name
= psymtab_search_name (name
);
671 lookup_name_info
lookup_name (search_name
.get (), symbol_name_match_type::FULL
);
674 &objfile
->partial_symtabs
->global_psymbols
[pst
->globals_offset
] :
675 &objfile
->partial_symtabs
->static_psymbols
[pst
->statics_offset
]);
677 if (global
) /* This means we can use a binary search. */
679 do_linear_search
= 0;
681 /* Binary search. This search is guaranteed to end with center
682 pointing at the earliest partial symbol whose name might be
683 correct. At that point *all* partial symbols with an
684 appropriate name will be checked against the correct
688 top
= start
+ length
- 1;
692 center
= bottom
+ (top
- bottom
) / 2;
694 internal_error (__FILE__
, __LINE__
,
695 _("failed internal consistency check"));
696 if (strcmp_iw_ordered (symbol_search_name (&(*center
)->ginfo
),
697 search_name
.get ()) >= 0)
706 if (!(top
== bottom
))
707 internal_error (__FILE__
, __LINE__
,
708 _("failed internal consistency check"));
710 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
711 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
712 while (top
>= start
&& symbol_matches_search_name (&(*top
)->ginfo
,
716 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
719 while (top
<= real_top
&& symbol_matches_search_name (&(*top
)->ginfo
,
722 if (symbol_matches_domain ((*top
)->ginfo
.language
,
723 (*top
)->domain
, domain
))
729 /* Can't use a binary search or else we found during the binary search that
730 we should also do a linear search. */
732 if (do_linear_search
)
734 for (psym
= start
; psym
< start
+ length
; psym
++)
736 if (symbol_matches_domain ((*psym
)->ginfo
.language
,
737 (*psym
)->domain
, domain
)
738 && symbol_matches_search_name (&(*psym
)->ginfo
, lookup_name
))
746 /* Get the symbol table that corresponds to a partial_symtab.
747 This is fast after the first time you do it.
748 The result will be NULL if the primary symtab has no symbols,
749 which can happen. Otherwise the result is the primary symtab
750 that contains PST. */
752 static struct compunit_symtab
*
753 psymtab_to_symtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
755 /* If it is a shared psymtab, find an unshared psymtab that includes
756 it. Any such psymtab will do. */
757 while (pst
->user
!= NULL
)
760 /* If it's been looked up before, return it. */
761 if (pst
->compunit_symtab
)
762 return pst
->compunit_symtab
;
764 /* If it has not yet been read in, read it. */
767 scoped_restore decrementer
= increment_reading_symtab ();
769 (*pst
->read_symtab
) (pst
, objfile
);
772 return pst
->compunit_symtab
;
775 /* Psymtab version of find_last_source_symtab. See its definition in
776 the definition of quick_symbol_functions in symfile.h. */
778 static struct symtab
*
779 psym_find_last_source_symtab (struct objfile
*ofp
)
781 struct partial_symtab
*cs_pst
= NULL
;
783 for (partial_symtab
*ps
: require_partial_symbols (ofp
, 1))
785 const char *name
= ps
->filename
;
786 int len
= strlen (name
);
788 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
789 || strcmp (name
, "<<C++-namespaces>>") == 0)))
797 internal_error (__FILE__
, __LINE__
,
798 _("select_source_symtab: "
799 "readin pst found and no symtabs."));
803 struct compunit_symtab
*cust
= psymtab_to_symtab (ofp
, cs_pst
);
807 return compunit_primary_filetab (cust
);
813 /* Psymtab version of forget_cached_source_info. See its definition in
814 the definition of quick_symbol_functions in symfile.h. */
817 psym_forget_cached_source_info (struct objfile
*objfile
)
819 for (partial_symtab
*pst
: require_partial_symbols (objfile
, 1))
821 if (pst
->fullname
!= NULL
)
823 xfree (pst
->fullname
);
824 pst
->fullname
= NULL
;
830 print_partial_symbols (struct gdbarch
*gdbarch
, struct objfile
*objfile
,
831 struct partial_symbol
**p
, int count
, const char *what
,
832 struct ui_file
*outfile
)
834 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
838 fprintf_filtered (outfile
, " `%s'", (*p
)->ginfo
.name
);
839 if (symbol_demangled_name (&(*p
)->ginfo
) != NULL
)
841 fprintf_filtered (outfile
, " `%s'",
842 symbol_demangled_name (&(*p
)->ginfo
));
844 fputs_filtered (", ", outfile
);
845 switch ((*p
)->domain
)
848 fputs_filtered ("undefined domain, ", outfile
);
851 /* This is the usual thing -- don't print it. */
854 fputs_filtered ("struct domain, ", outfile
);
857 fputs_filtered ("module domain, ", outfile
);
860 fputs_filtered ("label domain, ", outfile
);
862 case COMMON_BLOCK_DOMAIN
:
863 fputs_filtered ("common block domain, ", outfile
);
866 fputs_filtered ("<invalid domain>, ", outfile
);
869 switch ((*p
)->aclass
)
872 fputs_filtered ("undefined", outfile
);
875 fputs_filtered ("constant int", outfile
);
878 fputs_filtered ("static", outfile
);
881 fputs_filtered ("register", outfile
);
884 fputs_filtered ("pass by value", outfile
);
887 fputs_filtered ("pass by reference", outfile
);
889 case LOC_REGPARM_ADDR
:
890 fputs_filtered ("register address parameter", outfile
);
893 fputs_filtered ("stack parameter", outfile
);
896 fputs_filtered ("type", outfile
);
899 fputs_filtered ("label", outfile
);
902 fputs_filtered ("function", outfile
);
904 case LOC_CONST_BYTES
:
905 fputs_filtered ("constant bytes", outfile
);
908 fputs_filtered ("unresolved", outfile
);
910 case LOC_OPTIMIZED_OUT
:
911 fputs_filtered ("optimized out", outfile
);
914 fputs_filtered ("computed at runtime", outfile
);
917 fputs_filtered ("<invalid location>", outfile
);
920 fputs_filtered (", ", outfile
);
921 fputs_filtered (paddress (gdbarch
, (*p
)->unrelocated_address ()), outfile
);
922 fprintf_filtered (outfile
, "\n");
928 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
929 struct ui_file
*outfile
)
931 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
934 if (psymtab
->anonymous
)
936 fprintf_filtered (outfile
, "\nAnonymous partial symtab (%s) ",
941 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
944 fprintf_filtered (outfile
, "(object ");
945 gdb_print_host_address (psymtab
, outfile
);
946 fprintf_filtered (outfile
, ")\n\n");
947 fprintf_filtered (outfile
, " Read from object file %s (",
948 objfile_name (objfile
));
949 gdb_print_host_address (objfile
, outfile
);
950 fprintf_filtered (outfile
, ")\n");
954 fprintf_filtered (outfile
,
955 " Full symtab was read (at ");
956 gdb_print_host_address (psymtab
->compunit_symtab
, outfile
);
957 fprintf_filtered (outfile
, " by function at ");
958 gdb_print_host_address (psymtab
->read_symtab
, outfile
);
959 fprintf_filtered (outfile
, ")\n");
962 fprintf_filtered (outfile
, " Symbols cover text addresses ");
963 fputs_filtered (paddress (gdbarch
, psymtab
->text_low (objfile
)), outfile
);
964 fprintf_filtered (outfile
, "-");
965 fputs_filtered (paddress (gdbarch
, psymtab
->text_high (objfile
)), outfile
);
966 fprintf_filtered (outfile
, "\n");
967 fprintf_filtered (outfile
, " Address map supported - %s.\n",
968 psymtab
->psymtabs_addrmap_supported
? "yes" : "no");
969 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
970 psymtab
->number_of_dependencies
);
971 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
973 fprintf_filtered (outfile
, " %d ", i
);
974 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
975 fprintf_filtered (outfile
, " %s\n",
976 psymtab
->dependencies
[i
]->filename
);
978 if (psymtab
->user
!= NULL
)
980 fprintf_filtered (outfile
, " Shared partial symtab with user ");
981 gdb_print_host_address (psymtab
->user
, outfile
);
982 fprintf_filtered (outfile
, "\n");
984 if (psymtab
->n_global_syms
> 0)
986 print_partial_symbols
988 &objfile
->partial_symtabs
->global_psymbols
[psymtab
->globals_offset
],
989 psymtab
->n_global_syms
, "Global", outfile
);
991 if (psymtab
->n_static_syms
> 0)
993 print_partial_symbols
995 &objfile
->partial_symtabs
->static_psymbols
[psymtab
->statics_offset
],
996 psymtab
->n_static_syms
, "Static", outfile
);
998 fprintf_filtered (outfile
, "\n");
1001 /* Psymtab version of print_stats. See its definition in
1002 the definition of quick_symbol_functions in symfile.h. */
1005 psym_print_stats (struct objfile
*objfile
)
1010 for (partial_symtab
*ps
: require_partial_symbols (objfile
, 1))
1012 if (ps
->readin
== 0)
1015 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i
);
1018 /* Psymtab version of dump. See its definition in
1019 the definition of quick_symbol_functions in symfile.h. */
1022 psym_dump (struct objfile
*objfile
)
1024 struct partial_symtab
*psymtab
;
1026 if (objfile
->partial_symtabs
->psymtabs
)
1028 printf_filtered ("Psymtabs:\n");
1029 for (psymtab
= objfile
->partial_symtabs
->psymtabs
;
1031 psymtab
= psymtab
->next
)
1033 printf_filtered ("%s at ",
1035 gdb_print_host_address (psymtab
, gdb_stdout
);
1036 printf_filtered (", ");
1039 printf_filtered ("\n\n");
1043 /* Psymtab version of expand_symtabs_for_function. See its definition in
1044 the definition of quick_symbol_functions in symfile.h. */
1047 psym_expand_symtabs_for_function (struct objfile
*objfile
,
1048 const char *func_name
)
1050 for (partial_symtab
*ps
: require_partial_symbols (objfile
, 1))
1055 if ((lookup_partial_symbol (objfile
, ps
, func_name
, 1, VAR_DOMAIN
)
1057 || (lookup_partial_symbol (objfile
, ps
, func_name
, 0, VAR_DOMAIN
)
1059 psymtab_to_symtab (objfile
, ps
);
1063 /* Psymtab version of expand_all_symtabs. See its definition in
1064 the definition of quick_symbol_functions in symfile.h. */
1067 psym_expand_all_symtabs (struct objfile
*objfile
)
1069 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
, 1))
1070 psymtab_to_symtab (objfile
, psymtab
);
1073 /* Psymtab version of expand_symtabs_with_fullname. See its definition in
1074 the definition of quick_symbol_functions in symfile.h. */
1077 psym_expand_symtabs_with_fullname (struct objfile
*objfile
,
1078 const char *fullname
)
1080 for (partial_symtab
*p
: require_partial_symbols (objfile
, 1))
1082 /* Anonymous psymtabs don't have a name of a source file. */
1086 /* psymtab_to_fullname tries to open the file which is slow.
1087 Don't call it if we know the basenames don't match. */
1088 if ((basenames_may_differ
1089 || filename_cmp (lbasename (fullname
), lbasename (p
->filename
)) == 0)
1090 && filename_cmp (fullname
, psymtab_to_fullname (p
)) == 0)
1091 psymtab_to_symtab (objfile
, p
);
1095 /* Psymtab version of map_symbol_filenames. See its definition in
1096 the definition of quick_symbol_functions in symfile.h. */
1099 psym_map_symbol_filenames (struct objfile
*objfile
,
1100 symbol_filename_ftype
*fun
, void *data
,
1103 for (partial_symtab
*ps
: require_partial_symbols (objfile
, 1))
1105 const char *fullname
;
1110 /* We can skip shared psymtabs here, because any file name will be
1111 attached to the unshared psymtab. */
1112 if (ps
->user
!= NULL
)
1115 /* Anonymous psymtabs don't have a file name. */
1121 fullname
= psymtab_to_fullname (ps
);
1124 (*fun
) (ps
->filename
, fullname
, data
);
1128 /* Finds the fullname that a partial_symtab represents.
1130 If this functions finds the fullname, it will save it in ps->fullname
1131 and it will also return the value.
1133 If this function fails to find the file that this partial_symtab represents,
1134 NULL will be returned and ps->fullname will be set to NULL. */
1137 psymtab_to_fullname (struct partial_symtab
*ps
)
1139 gdb_assert (!ps
->anonymous
);
1141 /* Use cached copy if we have it.
1142 We rely on forget_cached_source_info being called appropriately
1143 to handle cases like the file being moved. */
1144 if (ps
->fullname
== NULL
)
1146 gdb::unique_xmalloc_ptr
<char> fullname
;
1147 scoped_fd fd
= find_and_open_source (ps
->filename
, ps
->dirname
,
1149 ps
->fullname
= fullname
.release ();
1153 /* rewrite_source_path would be applied by find_and_open_source, we
1154 should report the pathname where GDB tried to find the file. */
1156 if (ps
->dirname
== NULL
|| IS_ABSOLUTE_PATH (ps
->filename
))
1157 fullname
.reset (xstrdup (ps
->filename
));
1159 fullname
.reset (concat (ps
->dirname
, SLASH_STRING
,
1160 ps
->filename
, (char *) NULL
));
1162 ps
->fullname
= rewrite_source_path (fullname
.get ()).release ();
1163 if (ps
->fullname
== NULL
)
1164 ps
->fullname
= fullname
.release ();
1168 return ps
->fullname
;
1171 /* Psymtab version of map_matching_symbols. See its definition in
1172 the definition of quick_symbol_functions in symfile.h. */
1175 psym_map_matching_symbols
1176 (struct objfile
*objfile
,
1177 const lookup_name_info
&name
, domain_enum domain
,
1179 gdb::function_view
<symbol_found_callback_ftype
> callback
,
1180 symbol_compare_ftype
*ordered_compare
)
1182 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
1184 for (partial_symtab
*ps
: require_partial_symbols (objfile
, 1))
1188 || match_partial_symbol (objfile
, ps
, global
, name
, domain
,
1191 struct compunit_symtab
*cust
= psymtab_to_symtab (objfile
, ps
);
1192 const struct block
*block
;
1196 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
1197 if (!iterate_over_symbols_terminated (block
, name
,
1204 /* A helper for psym_expand_symtabs_matching that handles searching
1205 included psymtabs. This returns true if a symbol is found, and
1206 false otherwise. It also updates the 'searched_flag' on the
1207 various psymtabs that it searches. */
1210 recursively_search_psymtabs
1211 (struct partial_symtab
*ps
,
1212 struct objfile
*objfile
,
1213 enum search_domain domain
,
1214 const lookup_name_info
&lookup_name
,
1215 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> sym_matcher
)
1218 enum psymtab_search_status result
= PST_SEARCHED_AND_NOT_FOUND
;
1221 if (ps
->searched_flag
!= PST_NOT_SEARCHED
)
1222 return ps
->searched_flag
== PST_SEARCHED_AND_FOUND
;
1224 /* Recurse into shared psymtabs first, because they may have already
1225 been searched, and this could save some time. */
1226 for (i
= 0; i
< ps
->number_of_dependencies
; ++i
)
1230 /* Skip non-shared dependencies, these are handled elsewhere. */
1231 if (ps
->dependencies
[i
]->user
== NULL
)
1234 r
= recursively_search_psymtabs (ps
->dependencies
[i
],
1235 objfile
, domain
, lookup_name
,
1239 ps
->searched_flag
= PST_SEARCHED_AND_FOUND
;
1244 partial_symbol
**gbound
1245 = (objfile
->partial_symtabs
->global_psymbols
.data ()
1246 + ps
->globals_offset
+ ps
->n_global_syms
);
1247 partial_symbol
**sbound
1248 = (objfile
->partial_symtabs
->static_psymbols
.data ()
1249 + ps
->statics_offset
+ ps
->n_static_syms
);
1250 partial_symbol
**bound
= gbound
;
1252 /* Go through all of the symbols stored in a partial
1253 symtab in one loop. */
1254 partial_symbol
**psym
= (objfile
->partial_symtabs
->global_psymbols
.data ()
1255 + ps
->globals_offset
);
1260 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
1262 psym
= (objfile
->partial_symtabs
->static_psymbols
.data ()
1263 + ps
->statics_offset
);
1274 if ((domain
== ALL_DOMAIN
1275 || (domain
== VARIABLES_DOMAIN
1276 && (*psym
)->aclass
!= LOC_TYPEDEF
1277 && (*psym
)->aclass
!= LOC_BLOCK
)
1278 || (domain
== FUNCTIONS_DOMAIN
1279 && (*psym
)->aclass
== LOC_BLOCK
)
1280 || (domain
== TYPES_DOMAIN
1281 && (*psym
)->aclass
== LOC_TYPEDEF
))
1282 && psymbol_name_matches (*psym
, lookup_name
)
1283 && (sym_matcher
== NULL
1284 || sym_matcher (symbol_search_name (&(*psym
)->ginfo
))))
1286 /* Found a match, so notify our caller. */
1287 result
= PST_SEARCHED_AND_FOUND
;
1294 ps
->searched_flag
= result
;
1295 return result
== PST_SEARCHED_AND_FOUND
;
1298 /* Psymtab version of expand_symtabs_matching. See its definition in
1299 the definition of quick_symbol_functions in symfile.h. */
1302 psym_expand_symtabs_matching
1303 (struct objfile
*objfile
,
1304 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
1305 const lookup_name_info
&lookup_name_in
,
1306 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
1307 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
1308 enum search_domain domain
)
1310 lookup_name_info lookup_name
= lookup_name_in
.make_ignore_params ();
1312 /* Clear the search flags. */
1313 for (partial_symtab
*ps
: require_partial_symbols (objfile
, 1))
1314 ps
->searched_flag
= PST_NOT_SEARCHED
;
1316 for (partial_symtab
*ps
: objfile
->psymtabs ())
1323 /* We skip shared psymtabs because file-matching doesn't apply
1324 to them; but we search them later in the loop. */
1325 if (ps
->user
!= NULL
)
1335 match
= file_matcher (ps
->filename
, false);
1338 /* Before we invoke realpath, which can get expensive when many
1339 files are involved, do a quick comparison of the basenames. */
1340 if (basenames_may_differ
1341 || file_matcher (lbasename (ps
->filename
), true))
1342 match
= file_matcher (psymtab_to_fullname (ps
), false);
1348 if (recursively_search_psymtabs (ps
, objfile
, domain
,
1349 lookup_name
, symbol_matcher
))
1351 struct compunit_symtab
*symtab
=
1352 psymtab_to_symtab (objfile
, ps
);
1354 if (expansion_notify
!= NULL
)
1355 expansion_notify (symtab
);
1360 /* Psymtab version of has_symbols. See its definition in
1361 the definition of quick_symbol_functions in symfile.h. */
1364 psym_has_symbols (struct objfile
*objfile
)
1366 return objfile
->partial_symtabs
->psymtabs
!= NULL
;
1369 /* Helper function for psym_find_compunit_symtab_by_address that fills
1370 in psymbol_map for a given range of psymbols. */
1373 psym_fill_psymbol_map (struct objfile
*objfile
,
1374 struct partial_symtab
*psymtab
,
1375 std::set
<CORE_ADDR
> *seen_addrs
,
1376 const std::vector
<partial_symbol
*> &symbols
,
1380 for (int i
= 0; i
< length
; ++i
)
1382 struct partial_symbol
*psym
= symbols
[start
+ i
];
1384 if (psym
->aclass
== LOC_STATIC
)
1386 CORE_ADDR addr
= psym
->address (objfile
);
1387 if (seen_addrs
->find (addr
) == seen_addrs
->end ())
1389 seen_addrs
->insert (addr
);
1390 objfile
->psymbol_map
.emplace_back (addr
, psymtab
);
1396 /* See find_compunit_symtab_by_address in quick_symbol_functions, in
1399 static compunit_symtab
*
1400 psym_find_compunit_symtab_by_address (struct objfile
*objfile
,
1403 if (objfile
->psymbol_map
.empty ())
1405 std::set
<CORE_ADDR
> seen_addrs
;
1407 for (partial_symtab
*pst
: require_partial_symbols (objfile
, 1))
1409 psym_fill_psymbol_map (objfile
, pst
,
1411 objfile
->partial_symtabs
->global_psymbols
,
1412 pst
->globals_offset
,
1413 pst
->n_global_syms
);
1414 psym_fill_psymbol_map (objfile
, pst
,
1416 objfile
->partial_symtabs
->static_psymbols
,
1417 pst
->statics_offset
,
1418 pst
->n_static_syms
);
1421 objfile
->psymbol_map
.shrink_to_fit ();
1423 std::sort (objfile
->psymbol_map
.begin (), objfile
->psymbol_map
.end (),
1424 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1425 const std::pair
<CORE_ADDR
, partial_symtab
*> &b
)
1427 return a
.first
< b
.first
;
1431 auto iter
= std::lower_bound
1432 (objfile
->psymbol_map
.begin (), objfile
->psymbol_map
.end (), address
,
1433 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1439 if (iter
== objfile
->psymbol_map
.end () || iter
->first
!= address
)
1442 return psymtab_to_symtab (objfile
, iter
->second
);
1445 const struct quick_symbol_functions psym_functions
=
1448 psym_find_last_source_symtab
,
1449 psym_forget_cached_source_info
,
1450 psym_map_symtabs_matching_filename
,
1454 psym_expand_symtabs_for_function
,
1455 psym_expand_all_symtabs
,
1456 psym_expand_symtabs_with_fullname
,
1457 psym_map_matching_symbols
,
1458 psym_expand_symtabs_matching
,
1459 psym_find_pc_sect_compunit_symtab
,
1460 psym_find_compunit_symtab_by_address
,
1461 psym_map_symbol_filenames
1467 sort_pst_symbols (struct objfile
*objfile
, struct partial_symtab
*pst
)
1469 /* Sort the global list; don't sort the static list. */
1470 auto begin
= objfile
->partial_symtabs
->global_psymbols
.begin ();
1471 std::advance (begin
, pst
->globals_offset
);
1473 /* The psymbols for this partial_symtab are currently at the end of the
1475 auto end
= objfile
->partial_symtabs
->global_psymbols
.end ();
1477 std::sort (begin
, end
, [] (partial_symbol
*s1
, partial_symbol
*s2
)
1479 return strcmp_iw_ordered (symbol_search_name (&s1
->ginfo
),
1480 symbol_search_name (&s2
->ginfo
)) < 0;
1484 /* Allocate and partially fill a partial symtab. It will be
1485 completely filled at the end of the symbol list.
1487 FILENAME is the name of the symbol-file we are reading from. */
1489 struct partial_symtab
*
1490 start_psymtab_common (struct objfile
*objfile
,
1491 const char *filename
,
1494 struct partial_symtab
*psymtab
;
1496 psymtab
= allocate_psymtab (filename
, objfile
);
1497 psymtab
->set_text_low (textlow
);
1498 psymtab
->set_text_high (psymtab
->raw_text_low ()); /* default */
1499 psymtab
->globals_offset
= objfile
->partial_symtabs
->global_psymbols
.size ();
1500 psymtab
->statics_offset
= objfile
->partial_symtabs
->static_psymbols
.size ();
1504 /* Perform "finishing up" operations of a partial symtab. */
1507 end_psymtab_common (struct objfile
*objfile
, struct partial_symtab
*pst
)
1509 pst
->n_global_syms
= (objfile
->partial_symtabs
->global_psymbols
.size ()
1510 - pst
->globals_offset
);
1511 pst
->n_static_syms
= (objfile
->partial_symtabs
->static_psymbols
.size ()
1512 - pst
->statics_offset
);
1514 sort_pst_symbols (objfile
, pst
);
1517 /* Calculate a hash code for the given partial symbol. The hash is
1518 calculated using the symbol's value, language, domain, class
1519 and name. These are the values which are set by
1520 add_psymbol_to_bcache. */
1522 static unsigned long
1523 psymbol_hash (const void *addr
, int length
)
1525 unsigned long h
= 0;
1526 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1527 unsigned int lang
= psymbol
->ginfo
.language
;
1528 unsigned int domain
= psymbol
->domain
;
1529 unsigned int theclass
= psymbol
->aclass
;
1531 h
= hash_continue (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1532 h
= hash_continue (&lang
, sizeof (unsigned int), h
);
1533 h
= hash_continue (&domain
, sizeof (unsigned int), h
);
1534 h
= hash_continue (&theclass
, sizeof (unsigned int), h
);
1535 /* Note that psymbol names are interned via symbol_set_names, so
1536 there's no need to hash the contents of the name here. */
1537 h
= hash_continue (&psymbol
->ginfo
.name
,
1538 sizeof (psymbol
->ginfo
.name
), h
);
1543 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1544 For the comparison this function uses a symbols value,
1545 language, domain, class and name. */
1548 psymbol_compare (const void *addr1
, const void *addr2
, int length
)
1550 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1551 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1553 return (memcmp (&sym1
->ginfo
.value
, &sym2
->ginfo
.value
,
1554 sizeof (sym1
->ginfo
.value
)) == 0
1555 && sym1
->ginfo
.language
== sym2
->ginfo
.language
1556 && sym1
->domain
== sym2
->domain
1557 && sym1
->aclass
== sym2
->aclass
1558 /* Note that psymbol names are interned via
1559 symbol_set_names, so there's no need to compare the
1560 contents of the name here. */
1561 && sym1
->ginfo
.name
== sym2
->ginfo
.name
);
1564 /* Helper function, initialises partial symbol structure and stashes
1565 it into objfile's bcache. Note that our caching mechanism will
1566 use all fields of struct partial_symbol to determine hash value of the
1567 structure. In other words, having two symbols with the same name but
1568 different domain (or address) is possible and correct. */
1570 static struct partial_symbol
*
1571 add_psymbol_to_bcache (const char *name
, int namelength
, bool copy_name
,
1573 enum address_class theclass
,
1576 enum language language
, struct objfile
*objfile
,
1579 struct partial_symbol psymbol
;
1580 memset (&psymbol
, 0, sizeof (psymbol
));
1582 psymbol
.set_unrelocated_address (coreaddr
);
1583 psymbol
.ginfo
.section
= section
;
1584 psymbol
.domain
= domain
;
1585 psymbol
.aclass
= theclass
;
1586 symbol_set_language (&psymbol
.ginfo
, language
,
1587 objfile
->partial_symtabs
->obstack ());
1588 symbol_set_names (&psymbol
.ginfo
, name
, namelength
, copy_name
,
1591 /* Stash the partial symbol away in the cache. */
1592 return ((struct partial_symbol
*)
1593 objfile
->partial_symtabs
->psymbol_cache
.insert
1594 (&psymbol
, sizeof (struct partial_symbol
), added
));
1597 /* Helper function, adds partial symbol to the given partial symbol list. */
1600 append_psymbol_to_list (std::vector
<partial_symbol
*> *list
,
1601 struct partial_symbol
*psym
,
1602 struct objfile
*objfile
)
1604 list
->push_back (psym
);
1605 OBJSTAT (objfile
, n_psyms
++);
1608 /* See psympriv.h. */
1611 add_psymbol_to_list (const char *name
, int namelength
, bool copy_name
,
1613 enum address_class theclass
,
1615 psymbol_placement where
,
1617 enum language language
, struct objfile
*objfile
)
1619 struct partial_symbol
*psym
;
1623 /* Stash the partial symbol away in the cache. */
1624 psym
= add_psymbol_to_bcache (name
, namelength
, copy_name
, domain
, theclass
,
1625 section
, coreaddr
, language
, objfile
, &added
);
1627 /* Do not duplicate global partial symbols. */
1628 if (where
== psymbol_placement::GLOBAL
&& !added
)
1631 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1632 std::vector
<partial_symbol
*> *list
1633 = (where
== psymbol_placement::STATIC
1634 ? &objfile
->partial_symtabs
->static_psymbols
1635 : &objfile
->partial_symtabs
->global_psymbols
);
1636 append_psymbol_to_list (list
, psym
, objfile
);
1639 /* See psympriv.h. */
1642 init_psymbol_list (struct objfile
*objfile
, int total_symbols
)
1644 if (objfile
->partial_symtabs
->global_psymbols
.capacity () == 0
1645 && objfile
->partial_symtabs
->static_psymbols
.capacity () == 0)
1647 /* Current best guess is that approximately a twentieth of the
1648 total symbols (in a debugging file) are global or static
1649 oriented symbols, then multiply that by slop factor of
1651 objfile
->partial_symtabs
->global_psymbols
.reserve (total_symbols
/ 10);
1652 objfile
->partial_symtabs
->static_psymbols
.reserve (total_symbols
/ 10);
1656 /* See psympriv.h. */
1658 struct partial_symtab
*
1659 allocate_psymtab (const char *filename
, struct objfile
*objfile
)
1661 struct partial_symtab
*psymtab
1662 = objfile
->partial_symtabs
->allocate_psymtab ();
1665 = ((const char *) objfile
->per_bfd
->filename_cache
.insert
1666 (filename
, strlen (filename
) + 1));
1667 psymtab
->compunit_symtab
= NULL
;
1669 if (symtab_create_debug
)
1671 /* Be a bit clever with debugging messages, and don't print objfile
1672 every time, only when it changes. */
1673 static char *last_objfile_name
= NULL
;
1675 if (last_objfile_name
== NULL
1676 || strcmp (last_objfile_name
, objfile_name (objfile
)) != 0)
1678 xfree (last_objfile_name
);
1679 last_objfile_name
= xstrdup (objfile_name (objfile
));
1680 fprintf_filtered (gdb_stdlog
,
1681 "Creating one or more psymtabs for objfile %s ...\n",
1684 fprintf_filtered (gdb_stdlog
,
1685 "Created psymtab %s for module %s.\n",
1686 host_address_to_string (psymtab
), filename
);
1693 psymtab_storage::discard_psymtab (struct partial_symtab
*pst
)
1695 struct partial_symtab
**prev_pst
;
1698 Empty psymtabs happen as a result of header files which don't
1699 have any symbols in them. There can be a lot of them. But this
1700 check is wrong, in that a psymtab with N_SLINE entries but
1701 nothing else is not empty, but we don't realize that. Fixing
1702 that without slowing things down might be tricky. */
1704 /* First, snip it out of the psymtab chain. */
1706 prev_pst
= &psymtabs
;
1707 while ((*prev_pst
) != pst
)
1708 prev_pst
= &((*prev_pst
)->next
);
1709 (*prev_pst
) = pst
->next
;
1711 /* Next, put it on a free list for recycling. */
1713 pst
->next
= free_psymtabs
;
1714 free_psymtabs
= pst
;
1719 /* We need to pass a couple of items to the addrmap_foreach function,
1722 struct dump_psymtab_addrmap_data
1724 struct objfile
*objfile
;
1725 struct partial_symtab
*psymtab
;
1726 struct ui_file
*outfile
;
1728 /* Non-zero if the previously printed addrmap entry was for PSYMTAB.
1729 If so, we want to print the next one as well (since the next addrmap
1730 entry defines the end of the range). */
1731 int previous_matched
;
1734 /* Helper function for dump_psymtab_addrmap to print an addrmap entry. */
1737 dump_psymtab_addrmap_1 (void *datap
, CORE_ADDR start_addr
, void *obj
)
1739 struct dump_psymtab_addrmap_data
*data
1740 = (struct dump_psymtab_addrmap_data
*) datap
;
1741 struct gdbarch
*gdbarch
= get_objfile_arch (data
->objfile
);
1742 struct partial_symtab
*addrmap_psymtab
= (struct partial_symtab
*) obj
;
1743 const char *psymtab_address_or_end
= NULL
;
1747 if (data
->psymtab
== NULL
1748 || data
->psymtab
== addrmap_psymtab
)
1749 psymtab_address_or_end
= host_address_to_string (addrmap_psymtab
);
1750 else if (data
->previous_matched
)
1751 psymtab_address_or_end
= "<ends here>";
1753 if (data
->psymtab
== NULL
1754 || data
->psymtab
== addrmap_psymtab
1755 || data
->previous_matched
)
1757 fprintf_filtered (data
->outfile
, " %s%s %s\n",
1758 data
->psymtab
!= NULL
? " " : "",
1759 paddress (gdbarch
, start_addr
),
1760 psymtab_address_or_end
);
1763 data
->previous_matched
= (data
->psymtab
== NULL
1764 || data
->psymtab
== addrmap_psymtab
);
1769 /* Helper function for maintenance_print_psymbols to print the addrmap
1770 of PSYMTAB. If PSYMTAB is NULL print the entire addrmap. */
1773 dump_psymtab_addrmap (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
1774 struct ui_file
*outfile
)
1776 struct dump_psymtab_addrmap_data addrmap_dump_data
;
1778 if ((psymtab
== NULL
1779 || psymtab
->psymtabs_addrmap_supported
)
1780 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
1782 addrmap_dump_data
.objfile
= objfile
;
1783 addrmap_dump_data
.psymtab
= psymtab
;
1784 addrmap_dump_data
.outfile
= outfile
;
1785 addrmap_dump_data
.previous_matched
= 0;
1786 fprintf_filtered (outfile
, "%sddress map:\n",
1787 psymtab
== NULL
? "Entire a" : " A");
1788 addrmap_foreach (objfile
->partial_symtabs
->psymtabs_addrmap
,
1789 dump_psymtab_addrmap_1
, &addrmap_dump_data
);
1794 maintenance_print_psymbols (const char *args
, int from_tty
)
1796 struct ui_file
*outfile
= gdb_stdout
;
1797 char *address_arg
= NULL
, *source_arg
= NULL
, *objfile_arg
= NULL
;
1798 int i
, outfile_idx
, found
;
1800 struct obj_section
*section
= NULL
;
1804 gdb_argv
argv (args
);
1806 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
1808 if (strcmp (argv
[i
], "-pc") == 0)
1810 if (argv
[i
+ 1] == NULL
)
1811 error (_("Missing pc value"));
1812 address_arg
= argv
[++i
];
1814 else if (strcmp (argv
[i
], "-source") == 0)
1816 if (argv
[i
+ 1] == NULL
)
1817 error (_("Missing source file"));
1818 source_arg
= argv
[++i
];
1820 else if (strcmp (argv
[i
], "-objfile") == 0)
1822 if (argv
[i
+ 1] == NULL
)
1823 error (_("Missing objfile name"));
1824 objfile_arg
= argv
[++i
];
1826 else if (strcmp (argv
[i
], "--") == 0)
1828 /* End of options. */
1832 else if (argv
[i
][0] == '-')
1834 /* Future proofing: Don't allow OUTFILE to begin with "-". */
1835 error (_("Unknown option: %s"), argv
[i
]);
1842 if (address_arg
!= NULL
&& source_arg
!= NULL
)
1843 error (_("Must specify at most one of -pc and -source"));
1845 stdio_file arg_outfile
;
1847 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
1849 if (argv
[outfile_idx
+ 1] != NULL
)
1850 error (_("Junk at end of command"));
1851 gdb::unique_xmalloc_ptr
<char> outfile_name
1852 (tilde_expand (argv
[outfile_idx
]));
1853 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
1854 perror_with_name (outfile_name
.get ());
1855 outfile
= &arg_outfile
;
1858 if (address_arg
!= NULL
)
1860 pc
= parse_and_eval_address (address_arg
);
1861 /* If we fail to find a section, that's ok, try the lookup anyway. */
1862 section
= find_pc_section (pc
);
1866 for (objfile
*objfile
: current_program_space
->objfiles ())
1868 int printed_objfile_header
= 0;
1869 int print_for_objfile
= 1;
1872 if (objfile_arg
!= NULL
)
1874 = compare_filenames_for_search (objfile_name (objfile
),
1876 if (!print_for_objfile
)
1879 if (address_arg
!= NULL
)
1881 struct bound_minimal_symbol msymbol
= { NULL
, NULL
};
1883 /* We don't assume each pc has a unique objfile (this is for
1885 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
,
1889 if (!printed_objfile_header
)
1891 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1892 objfile_name (objfile
));
1893 printed_objfile_header
= 1;
1895 dump_psymtab (objfile
, ps
, outfile
);
1896 dump_psymtab_addrmap (objfile
, ps
, outfile
);
1902 for (partial_symtab
*ps
: require_partial_symbols (objfile
, 1))
1904 int print_for_source
= 0;
1907 if (source_arg
!= NULL
)
1910 = compare_filenames_for_search (ps
->filename
, source_arg
);
1913 if (source_arg
== NULL
1914 || print_for_source
)
1916 if (!printed_objfile_header
)
1918 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1919 objfile_name (objfile
));
1920 printed_objfile_header
= 1;
1922 dump_psymtab (objfile
, ps
, outfile
);
1923 dump_psymtab_addrmap (objfile
, ps
, outfile
);
1928 /* If we're printing all the objfile's symbols dump the full addrmap. */
1930 if (address_arg
== NULL
1931 && source_arg
== NULL
1932 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
1934 outfile
->puts ("\n");
1935 dump_psymtab_addrmap (objfile
, NULL
, outfile
);
1941 if (address_arg
!= NULL
)
1942 error (_("No partial symtab for address: %s"), address_arg
);
1943 if (source_arg
!= NULL
)
1944 error (_("No partial symtab for source file: %s"), source_arg
);
1948 /* List all the partial symbol tables whose names match REGEXP (optional). */
1951 maintenance_info_psymtabs (const char *regexp
, int from_tty
)
1953 struct program_space
*pspace
;
1958 ALL_PSPACES (pspace
)
1959 for (objfile
*objfile
: pspace
->objfiles ())
1961 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1963 /* We don't want to print anything for this objfile until we
1964 actually find a symtab whose name matches. */
1965 int printed_objfile_start
= 0;
1967 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
, 1))
1972 || re_exec (psymtab
->filename
))
1974 if (! printed_objfile_start
)
1976 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
1978 printf_filtered ("((struct objfile *) %s)\n",
1979 host_address_to_string (objfile
));
1980 printed_objfile_start
= 1;
1983 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1985 printf_filtered ("((struct partial_symtab *) %s)\n",
1986 host_address_to_string (psymtab
));
1988 printf_filtered (" readin %s\n",
1989 psymtab
->readin
? "yes" : "no");
1990 printf_filtered (" fullname %s\n",
1992 ? psymtab
->fullname
: "(null)");
1993 printf_filtered (" text addresses ");
1994 fputs_filtered (paddress (gdbarch
,
1995 psymtab
->text_low (objfile
)),
1997 printf_filtered (" -- ");
1998 fputs_filtered (paddress (gdbarch
,
1999 psymtab
->text_high (objfile
)),
2001 printf_filtered ("\n");
2002 printf_filtered (" psymtabs_addrmap_supported %s\n",
2003 (psymtab
->psymtabs_addrmap_supported
2005 printf_filtered (" globals ");
2006 if (psymtab
->n_global_syms
)
2008 auto p
= &(objfile
->partial_symtabs
2009 ->global_psymbols
[psymtab
->globals_offset
]);
2012 ("(* (struct partial_symbol **) %s @ %d)\n",
2013 host_address_to_string (p
),
2014 psymtab
->n_global_syms
);
2017 printf_filtered ("(none)\n");
2018 printf_filtered (" statics ");
2019 if (psymtab
->n_static_syms
)
2021 auto p
= &(objfile
->partial_symtabs
2022 ->static_psymbols
[psymtab
->statics_offset
]);
2025 ("(* (struct partial_symbol **) %s @ %d)\n",
2026 host_address_to_string (p
),
2027 psymtab
->n_static_syms
);
2030 printf_filtered ("(none)\n");
2031 printf_filtered (" dependencies ");
2032 if (psymtab
->number_of_dependencies
)
2036 printf_filtered ("{\n");
2037 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
2039 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
2041 /* Note the string concatenation there --- no
2043 printf_filtered (" psymtab %s "
2044 "((struct partial_symtab *) %s)\n",
2046 host_address_to_string (dep
));
2048 printf_filtered (" }\n");
2051 printf_filtered ("(none)\n");
2052 printf_filtered (" }\n");
2056 if (printed_objfile_start
)
2057 printf_filtered ("}\n");
2061 /* Check consistency of currently expanded psymtabs vs symtabs. */
2064 maintenance_check_psymtabs (const char *ignore
, int from_tty
)
2067 struct compunit_symtab
*cust
= NULL
;
2068 const struct blockvector
*bv
;
2069 const struct block
*b
;
2072 for (objfile
*objfile
: current_program_space
->objfiles ())
2073 for (partial_symtab
*ps
: require_partial_symbols (objfile
, 1))
2075 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2077 /* We don't call psymtab_to_symtab here because that may cause symtab
2078 expansion. When debugging a problem it helps if checkers leave
2079 things unchanged. */
2080 cust
= ps
->compunit_symtab
;
2082 /* First do some checks that don't require the associated symtab. */
2083 if (ps
->text_high (objfile
) < ps
->text_low (objfile
))
2085 printf_filtered ("Psymtab ");
2086 puts_filtered (ps
->filename
);
2087 printf_filtered (" covers bad range ");
2088 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
2090 printf_filtered (" - ");
2091 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
2093 printf_filtered ("\n");
2097 /* Now do checks requiring the associated symtab. */
2100 bv
= COMPUNIT_BLOCKVECTOR (cust
);
2101 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
2102 partial_symbol
**psym
2103 = &objfile
->partial_symtabs
->static_psymbols
[ps
->statics_offset
];
2104 length
= ps
->n_static_syms
;
2107 sym
= block_lookup_symbol (b
, symbol_search_name (&(*psym
)->ginfo
),
2108 symbol_name_match_type::SEARCH_NAME
,
2112 printf_filtered ("Static symbol `");
2113 puts_filtered ((*psym
)->ginfo
.name
);
2114 printf_filtered ("' only found in ");
2115 puts_filtered (ps
->filename
);
2116 printf_filtered (" psymtab\n");
2120 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2121 psym
= &objfile
->partial_symtabs
->global_psymbols
[ps
->globals_offset
];
2122 length
= ps
->n_global_syms
;
2125 sym
= block_lookup_symbol (b
, symbol_search_name (&(*psym
)->ginfo
),
2126 symbol_name_match_type::SEARCH_NAME
,
2130 printf_filtered ("Global symbol `");
2131 puts_filtered ((*psym
)->ginfo
.name
);
2132 printf_filtered ("' only found in ");
2133 puts_filtered (ps
->filename
);
2134 printf_filtered (" psymtab\n");
2138 if (ps
->raw_text_high () != 0
2139 && (ps
->text_low (objfile
) < BLOCK_START (b
)
2140 || ps
->text_high (objfile
) > BLOCK_END (b
)))
2142 printf_filtered ("Psymtab ");
2143 puts_filtered (ps
->filename
);
2144 printf_filtered (" covers ");
2145 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
2147 printf_filtered (" - ");
2148 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
2150 printf_filtered (" but symtab covers only ");
2151 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
2152 printf_filtered (" - ");
2153 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
2154 printf_filtered ("\n");
2160 _initialize_psymtab (void)
2162 add_cmd ("psymbols", class_maintenance
, maintenance_print_psymbols
, _("\
2163 Print dump of current partial symbol definitions.\n\
2164 Usage: mt print psymbols [-objfile OBJFILE] [-pc ADDRESS] [--] [OUTFILE]\n\
2165 mt print psymbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
2166 Entries in the partial symbol table are dumped to file OUTFILE,\n\
2167 or the terminal if OUTFILE is unspecified.\n\
2168 If ADDRESS is provided, dump only the file for that address.\n\
2169 If SOURCE is provided, dump only that file's symbols.\n\
2170 If OBJFILE is provided, dump only that file's minimal symbols."),
2171 &maintenanceprintlist
);
2173 add_cmd ("psymtabs", class_maintenance
, maintenance_info_psymtabs
, _("\
2174 List the partial symbol tables for all object files.\n\
2175 This does not include information about individual partial symbols,\n\
2176 just the symbol table structures themselves."),
2177 &maintenanceinfolist
);
2179 add_cmd ("check-psymtabs", class_maintenance
, maintenance_check_psymtabs
,
2181 Check consistency of currently expanded psymtabs versus symtabs."),