1 /* Partial symbol tables.
3 Copyright (C) 2009-2020 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "filenames.h"
31 #include "readline/tilde.h"
32 #include "gdb_regex.h"
33 #include "dictionary.h"
35 #include "cp-support.h"
40 static struct partial_symbol
*lookup_partial_symbol (struct objfile
*,
41 struct partial_symtab
*,
42 const lookup_name_info
&,
46 static const char *psymtab_to_fullname (struct partial_symtab
*ps
);
48 static struct partial_symbol
*find_pc_sect_psymbol (struct objfile
*,
49 struct partial_symtab
*,
51 struct obj_section
*);
53 static struct compunit_symtab
*psymtab_to_symtab (struct objfile
*objfile
,
54 struct partial_symtab
*pst
);
56 psymtab_storage::~psymtab_storage ()
58 partial_symtab
*iter
= psymtabs
;
59 while (iter
!= nullptr)
61 partial_symtab
*next
= iter
->next
;
70 psymtab_storage::install_psymtab (partial_symtab
*pst
)
80 psymtab_storage::partial_symtab_range
81 require_partial_symbols (struct objfile
*objfile
, bool verbose
)
83 if ((objfile
->flags
& OBJF_PSYMTABS_READ
) == 0)
85 objfile
->flags
|= OBJF_PSYMTABS_READ
;
87 if (objfile
->sf
->sym_read_psymbols
)
90 printf_filtered (_("Reading symbols from %s...\n"),
91 objfile_name (objfile
));
92 (*objfile
->sf
->sym_read_psymbols
) (objfile
);
94 /* Partial symbols list are not expected to changed after this
96 objfile
->partial_symtabs
->global_psymbols
.shrink_to_fit ();
97 objfile
->partial_symtabs
->static_psymbols
.shrink_to_fit ();
99 if (verbose
&& !objfile_has_symbols (objfile
))
100 printf_filtered (_("(No debugging symbols found in %s)\n"),
101 objfile_name (objfile
));
105 return objfile
->psymtabs ();
108 /* Helper function for psym_map_symtabs_matching_filename that
109 expands the symtabs and calls the iterator. */
112 partial_map_expand_apply (struct objfile
*objfile
,
114 const char *real_path
,
115 struct partial_symtab
*pst
,
116 gdb::function_view
<bool (symtab
*)> callback
)
118 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
120 /* Shared psymtabs should never be seen here. Instead they should
121 be handled properly by the caller. */
122 gdb_assert (pst
->user
== NULL
);
124 /* Don't visit already-expanded psymtabs. */
125 if (pst
->readin_p (objfile
))
128 /* This may expand more than one symtab, and we want to iterate over
130 psymtab_to_symtab (objfile
, pst
);
132 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
133 last_made
, callback
);
136 /* Psymtab version of map_symtabs_matching_filename. See its definition in
137 the definition of quick_symbol_functions in symfile.h. */
140 psym_map_symtabs_matching_filename
141 (struct objfile
*objfile
,
143 const char *real_path
,
144 gdb::function_view
<bool (symtab
*)> callback
)
146 const char *name_basename
= lbasename (name
);
148 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
150 /* Anonymous psymtabs don't have a file name. */
154 if (compare_filenames_for_search (pst
->filename
, name
))
159 if (partial_map_expand_apply (objfile
, name
, real_path
,
165 /* Before we invoke realpath, which can get expensive when many
166 files are involved, do a quick comparison of the basenames. */
167 if (! basenames_may_differ
168 && FILENAME_CMP (name_basename
, lbasename (pst
->filename
)) != 0)
171 if (compare_filenames_for_search (psymtab_to_fullname (pst
), name
))
173 if (partial_map_expand_apply (objfile
, name
, real_path
,
179 /* If the user gave us an absolute path, try to find the file in
180 this symtab and use its absolute path. */
181 if (real_path
!= NULL
)
183 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
184 gdb_assert (IS_ABSOLUTE_PATH (name
));
185 if (filename_cmp (psymtab_to_fullname (pst
), real_path
) == 0)
187 if (partial_map_expand_apply (objfile
, name
, real_path
,
198 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
199 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
201 static struct partial_symtab
*
202 find_pc_sect_psymtab_closer (struct objfile
*objfile
,
203 CORE_ADDR pc
, struct obj_section
*section
,
204 struct partial_symtab
*pst
,
205 struct bound_minimal_symbol msymbol
)
207 struct partial_symtab
*tpst
;
208 struct partial_symtab
*best_pst
= pst
;
209 CORE_ADDR best_addr
= pst
->text_low (objfile
);
211 gdb_assert (!pst
->psymtabs_addrmap_supported
);
213 /* An objfile that has its functions reordered might have
214 many partial symbol tables containing the PC, but
215 we want the partial symbol table that contains the
216 function containing the PC. */
217 if (!(objfile
->flags
& OBJF_REORDERED
)
218 && section
== NULL
) /* Can't validate section this way. */
221 if (msymbol
.minsym
== NULL
)
224 /* The code range of partial symtabs sometimes overlap, so, in
225 the loop below, we need to check all partial symtabs and
226 find the one that fits better for the given PC address. We
227 select the partial symtab that contains a symbol whose
228 address is closest to the PC address. By closest we mean
229 that find_pc_sect_symbol returns the symbol with address
230 that is closest and still less than the given PC. */
231 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
233 if (pc
>= tpst
->text_low (objfile
) && pc
< tpst
->text_high (objfile
))
235 struct partial_symbol
*p
;
238 /* NOTE: This assumes that every psymbol has a
239 corresponding msymbol, which is not necessarily
240 true; the debug info might be much richer than the
241 object's symbol table. */
242 p
= find_pc_sect_psymbol (objfile
, tpst
, pc
, section
);
244 && (p
->address (objfile
) == BMSYMBOL_VALUE_ADDRESS (msymbol
)))
247 /* Also accept the textlow value of a psymtab as a
248 "symbol", to provide some support for partial
249 symbol tables with line information but no debug
250 symbols (e.g. those produced by an assembler). */
252 this_addr
= p
->address (objfile
);
254 this_addr
= tpst
->text_low (objfile
);
256 /* Check whether it is closer than our current
257 BEST_ADDR. Since this symbol address is
258 necessarily lower or equal to PC, the symbol closer
259 to PC is the symbol which address is the highest.
260 This way we return the psymtab which contains such
261 best match symbol. This can help in cases where the
262 symbol information/debuginfo is not complete, like
263 for instance on IRIX6 with gcc, where no debug info
264 is emitted for statics. (See also the nodebug.exp
266 if (this_addr
> best_addr
)
268 best_addr
= this_addr
;
276 /* Find which partial symtab contains PC and SECTION. Return NULL if
277 none. We return the psymtab that contains a symbol whose address
278 exactly matches PC, or, if we cannot find an exact match, the
279 psymtab that contains a symbol whose address is closest to PC. */
281 static struct partial_symtab
*
282 find_pc_sect_psymtab (struct objfile
*objfile
, CORE_ADDR pc
,
283 struct obj_section
*section
,
284 struct bound_minimal_symbol msymbol
)
286 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better
287 granularity than the later used TEXTLOW/TEXTHIGH one. However, we need
288 to take care as the PSYMTABS_ADDRMAP can hold things other than partial
289 symtabs in some cases.
291 This function should only be called for objfiles that are using partial
292 symtabs, not for objfiles that are using indexes (.gdb_index or
293 .debug_names), however 'maintenance print psymbols' calls this function
294 directly for all objfiles. If we assume that PSYMTABS_ADDRMAP contains
295 partial symtabs then we will end up returning a pointer to an object
296 that is not a partial_symtab, which doesn't end well. */
298 if (objfile
->partial_symtabs
->psymtabs
!= NULL
299 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
301 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
303 struct partial_symtab
*pst
304 = ((struct partial_symtab
*)
305 addrmap_find (objfile
->partial_symtabs
->psymtabs_addrmap
,
309 /* FIXME: addrmaps currently do not handle overlayed sections,
310 so fall back to the non-addrmap case if we're debugging
311 overlays and the addrmap returned the wrong section. */
312 if (overlay_debugging
&& msymbol
.minsym
!= NULL
&& section
!= NULL
)
314 struct partial_symbol
*p
;
316 /* NOTE: This assumes that every psymbol has a
317 corresponding msymbol, which is not necessarily
318 true; the debug info might be much richer than the
319 object's symbol table. */
320 p
= find_pc_sect_psymbol (objfile
, pst
, pc
, section
);
322 || (p
->address (objfile
)
323 != BMSYMBOL_VALUE_ADDRESS (msymbol
)))
327 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
328 PSYMTABS_ADDRMAP we used has already the best 1-byte
329 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
330 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
339 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
340 which still have no corresponding full SYMTABs read. But it is not
341 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
344 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
345 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
346 debug info type in single OBJFILE. */
348 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
349 if (!pst
->psymtabs_addrmap_supported
350 && pc
>= pst
->text_low (objfile
) && pc
< pst
->text_high (objfile
))
352 struct partial_symtab
*best_pst
;
354 best_pst
= find_pc_sect_psymtab_closer (objfile
, pc
, section
, pst
,
356 if (best_pst
!= NULL
)
363 /* Psymtab version of find_pc_sect_compunit_symtab. See its definition in
364 the definition of quick_symbol_functions in symfile.h. */
366 static struct compunit_symtab
*
367 psym_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
368 struct bound_minimal_symbol msymbol
,
370 struct obj_section
*section
,
373 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
, section
,
377 if (warn_if_readin
&& ps
->readin_p (objfile
))
378 /* Might want to error() here (in case symtab is corrupt and
379 will cause a core dump), but maybe we can successfully
380 continue, so let's not. */
382 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
383 paddress (objfile
->arch (), pc
));
384 psymtab_to_symtab (objfile
, ps
);
385 return ps
->get_compunit_symtab (objfile
);
390 /* Find which partial symbol within a psymtab matches PC and SECTION.
391 Return NULL if none. */
393 static struct partial_symbol
*
394 find_pc_sect_psymbol (struct objfile
*objfile
,
395 struct partial_symtab
*psymtab
, CORE_ADDR pc
,
396 struct obj_section
*section
)
398 struct partial_symbol
*best
= NULL
;
400 const CORE_ADDR textlow
= psymtab
->text_low (objfile
);
402 gdb_assert (psymtab
!= NULL
);
404 /* Cope with programs that start at address 0. */
405 best_pc
= (textlow
!= 0) ? textlow
- 1 : 0;
407 /* Search the global symbols as well as the static symbols, so that
408 find_pc_partial_function doesn't use a minimal symbol and thus
409 cache a bad endaddr. */
410 for (int i
= 0; i
< psymtab
->n_global_syms
; i
++)
413 = objfile
->partial_symtabs
->global_psymbols
[psymtab
->globals_offset
416 if (p
->domain
== VAR_DOMAIN
417 && p
->aclass
== LOC_BLOCK
418 && pc
>= p
->address (objfile
)
419 && (p
->address (objfile
) > best_pc
420 || (psymtab
->text_low (objfile
) == 0
421 && best_pc
== 0 && p
->address (objfile
) == 0)))
423 if (section
!= NULL
) /* Match on a specific section. */
425 if (!matching_obj_sections (p
->obj_section (objfile
),
429 best_pc
= p
->address (objfile
);
434 for (int i
= 0; i
< psymtab
->n_static_syms
; i
++)
437 = objfile
->partial_symtabs
->static_psymbols
[psymtab
->statics_offset
440 if (p
->domain
== VAR_DOMAIN
441 && p
->aclass
== LOC_BLOCK
442 && pc
>= p
->address (objfile
)
443 && (p
->address (objfile
) > best_pc
444 || (psymtab
->text_low (objfile
) == 0
445 && best_pc
== 0 && p
->address (objfile
) == 0)))
447 if (section
!= NULL
) /* Match on a specific section. */
449 if (!matching_obj_sections (p
->obj_section (objfile
),
453 best_pc
= p
->address (objfile
);
461 /* Psymtab version of lookup_symbol. See its definition in
462 the definition of quick_symbol_functions in symfile.h. */
464 static struct compunit_symtab
*
465 psym_lookup_symbol (struct objfile
*objfile
,
466 block_enum block_index
, const char *name
,
467 const domain_enum domain
)
469 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
470 struct compunit_symtab
*stab_best
= NULL
;
472 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
474 lookup_name_info psym_lookup_name
= lookup_name
.make_ignore_params ();
476 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
478 if (!ps
->readin_p (objfile
)
479 && lookup_partial_symbol (objfile
, ps
, psym_lookup_name
,
480 psymtab_index
, domain
))
482 struct symbol
*sym
, *with_opaque
= NULL
;
483 struct compunit_symtab
*stab
= psymtab_to_symtab (objfile
, ps
);
484 /* Note: While psymtab_to_symtab can return NULL if the
485 partial symtab is empty, we can assume it won't here
486 because lookup_partial_symbol succeeded. */
487 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
488 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
490 sym
= block_find_symbol (block
, name
, domain
,
491 block_find_non_opaque_type_preferred
,
494 /* Some caution must be observed with overloaded functions
495 and methods, since the index will not contain any overload
496 information (but NAME might contain it). */
499 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
501 if (with_opaque
!= NULL
502 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
505 /* Keep looking through other psymtabs. */
512 /* Psymtab version of lookup_global_symbol_language. See its definition in
513 the definition of quick_symbol_functions in symfile.h. */
516 psym_lookup_global_symbol_language (struct objfile
*objfile
, const char *name
,
517 domain_enum domain
, bool *symbol_found_p
)
519 *symbol_found_p
= false;
520 if (objfile
->sf
== NULL
)
521 return language_unknown
;
523 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
525 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
527 struct partial_symbol
*psym
;
528 if (ps
->readin_p (objfile
))
531 psym
= lookup_partial_symbol (objfile
, ps
, lookup_name
, 1, domain
);
534 *symbol_found_p
= true;
535 return psym
->ginfo
.language ();
539 return language_unknown
;
542 /* Returns true if PSYM matches LOOKUP_NAME. */
545 psymbol_name_matches (partial_symbol
*psym
,
546 const lookup_name_info
&lookup_name
)
548 const language_defn
*lang
= language_def (psym
->ginfo
.language ());
549 symbol_name_matcher_ftype
*name_match
550 = lang
->get_symbol_name_matcher (lookup_name
);
551 return name_match (psym
->ginfo
.search_name (), lookup_name
, NULL
);
554 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
555 the global block of PST if GLOBAL, and otherwise the static block.
556 MATCH is the comparison operation that returns true iff MATCH (s,
557 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
558 non-null, the symbols in the block are assumed to be ordered
559 according to it (allowing binary search). It must be compatible
560 with MATCH. Returns the symbol, if found, and otherwise NULL. */
562 static struct partial_symbol
*
563 match_partial_symbol (struct objfile
*objfile
,
564 struct partial_symtab
*pst
, int global
,
565 const lookup_name_info
&name
, domain_enum domain
,
566 symbol_compare_ftype
*ordered_compare
)
568 struct partial_symbol
**start
, **psym
;
569 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
570 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
571 int do_linear_search
= 1;
577 &objfile
->partial_symtabs
->global_psymbols
[pst
->globals_offset
] :
578 &objfile
->partial_symtabs
->static_psymbols
[pst
->statics_offset
]);
580 if (global
&& ordered_compare
) /* Can use a binary search. */
582 do_linear_search
= 0;
584 /* Binary search. This search is guaranteed to end with center
585 pointing at the earliest partial symbol whose name might be
586 correct. At that point *all* partial symbols with an
587 appropriate name will be checked against the correct
591 top
= start
+ length
- 1;
595 center
= bottom
+ (top
- bottom
) / 2;
596 gdb_assert (center
< top
);
598 enum language lang
= (*center
)->ginfo
.language ();
599 const char *lang_ln
= name
.language_lookup_name (lang
);
601 if (ordered_compare ((*center
)->ginfo
.search_name (),
607 gdb_assert (top
== bottom
);
609 while (top
<= real_top
610 && psymbol_name_matches (*top
, name
))
612 if (symbol_matches_domain ((*top
)->ginfo
.language (),
613 (*top
)->domain
, domain
))
619 /* Can't use a binary search or else we found during the binary search that
620 we should also do a linear search. */
622 if (do_linear_search
)
624 for (psym
= start
; psym
< start
+ length
; psym
++)
626 if (symbol_matches_domain ((*psym
)->ginfo
.language (),
627 (*psym
)->domain
, domain
)
628 && psymbol_name_matches (*psym
, name
))
636 /* Look, in partial_symtab PST, for symbol whose natural name is
637 LOOKUP_NAME. Check the global symbols if GLOBAL, the static
640 static struct partial_symbol
*
641 lookup_partial_symbol (struct objfile
*objfile
,
642 struct partial_symtab
*pst
,
643 const lookup_name_info
&lookup_name
,
644 int global
, domain_enum domain
)
646 struct partial_symbol
**start
, **psym
;
647 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
648 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
649 int do_linear_search
= 1;
655 &objfile
->partial_symtabs
->global_psymbols
[pst
->globals_offset
] :
656 &objfile
->partial_symtabs
->static_psymbols
[pst
->statics_offset
]);
658 if (global
) /* This means we can use a binary search. */
660 do_linear_search
= 0;
662 /* Binary search. This search is guaranteed to end with center
663 pointing at the earliest partial symbol whose name might be
664 correct. At that point *all* partial symbols with an
665 appropriate name will be checked against the correct
669 top
= start
+ length
- 1;
673 center
= bottom
+ (top
- bottom
) / 2;
675 gdb_assert (center
< top
);
677 if (strcmp_iw_ordered ((*center
)->ginfo
.search_name (),
678 lookup_name
.c_str ()) >= 0)
688 gdb_assert (top
== bottom
);
690 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
691 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
692 while (top
>= start
&& symbol_matches_search_name (&(*top
)->ginfo
,
696 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
699 while (top
<= real_top
&& symbol_matches_search_name (&(*top
)->ginfo
,
702 if (symbol_matches_domain ((*top
)->ginfo
.language (),
703 (*top
)->domain
, domain
))
709 /* Can't use a binary search or else we found during the binary search that
710 we should also do a linear search. */
712 if (do_linear_search
)
714 for (psym
= start
; psym
< start
+ length
; psym
++)
716 if (symbol_matches_domain ((*psym
)->ginfo
.language (),
717 (*psym
)->domain
, domain
)
718 && symbol_matches_search_name (&(*psym
)->ginfo
, lookup_name
))
726 /* Get the symbol table that corresponds to a partial_symtab.
727 This is fast after the first time you do it.
728 The result will be NULL if the primary symtab has no symbols,
729 which can happen. Otherwise the result is the primary symtab
730 that contains PST. */
732 static struct compunit_symtab
*
733 psymtab_to_symtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
735 /* If it is a shared psymtab, find an unshared psymtab that includes
736 it. Any such psymtab will do. */
737 while (pst
->user
!= NULL
)
740 /* If it's been looked up before, return it. */
741 if (pst
->get_compunit_symtab (objfile
))
742 return pst
->get_compunit_symtab (objfile
);
744 /* If it has not yet been read in, read it. */
745 if (!pst
->readin_p (objfile
))
747 scoped_restore decrementer
= increment_reading_symtab ();
751 printf_filtered (_("Reading in symbols for %s...\n"),
753 gdb_flush (gdb_stdout
);
756 pst
->read_symtab (objfile
);
759 return pst
->get_compunit_symtab (objfile
);
762 /* Psymtab version of find_last_source_symtab. See its definition in
763 the definition of quick_symbol_functions in symfile.h. */
765 static struct symtab
*
766 psym_find_last_source_symtab (struct objfile
*ofp
)
768 struct partial_symtab
*cs_pst
= NULL
;
770 for (partial_symtab
*ps
: require_partial_symbols (ofp
, true))
772 const char *name
= ps
->filename
;
773 int len
= strlen (name
);
775 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
776 || strcmp (name
, "<<C++-namespaces>>") == 0)))
782 if (cs_pst
->readin_p (ofp
))
784 internal_error (__FILE__
, __LINE__
,
785 _("select_source_symtab: "
786 "readin pst found and no symtabs."));
790 struct compunit_symtab
*cust
= psymtab_to_symtab (ofp
, cs_pst
);
794 return compunit_primary_filetab (cust
);
800 /* Psymtab version of forget_cached_source_info. See its definition in
801 the definition of quick_symbol_functions in symfile.h. */
804 psym_forget_cached_source_info (struct objfile
*objfile
)
806 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
808 if (pst
->fullname
!= NULL
)
810 xfree (pst
->fullname
);
811 pst
->fullname
= NULL
;
817 print_partial_symbols (struct gdbarch
*gdbarch
, struct objfile
*objfile
,
818 struct partial_symbol
**p
, int count
, const char *what
,
819 struct ui_file
*outfile
)
821 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
825 fprintf_filtered (outfile
, " `%s'", (*p
)->ginfo
.linkage_name ());
826 if ((*p
)->ginfo
.demangled_name () != NULL
)
828 fprintf_filtered (outfile
, " `%s'",
829 (*p
)->ginfo
.demangled_name ());
831 fputs_filtered (", ", outfile
);
832 switch ((*p
)->domain
)
835 fputs_filtered ("undefined domain, ", outfile
);
838 /* This is the usual thing -- don't print it. */
841 fputs_filtered ("struct domain, ", outfile
);
844 fputs_filtered ("module domain, ", outfile
);
847 fputs_filtered ("label domain, ", outfile
);
849 case COMMON_BLOCK_DOMAIN
:
850 fputs_filtered ("common block domain, ", outfile
);
853 fputs_filtered ("<invalid domain>, ", outfile
);
856 switch ((*p
)->aclass
)
859 fputs_filtered ("undefined", outfile
);
862 fputs_filtered ("constant int", outfile
);
865 fputs_filtered ("static", outfile
);
868 fputs_filtered ("register", outfile
);
871 fputs_filtered ("pass by value", outfile
);
874 fputs_filtered ("pass by reference", outfile
);
876 case LOC_REGPARM_ADDR
:
877 fputs_filtered ("register address parameter", outfile
);
880 fputs_filtered ("stack parameter", outfile
);
883 fputs_filtered ("type", outfile
);
886 fputs_filtered ("label", outfile
);
889 fputs_filtered ("function", outfile
);
891 case LOC_CONST_BYTES
:
892 fputs_filtered ("constant bytes", outfile
);
895 fputs_filtered ("unresolved", outfile
);
897 case LOC_OPTIMIZED_OUT
:
898 fputs_filtered ("optimized out", outfile
);
901 fputs_filtered ("computed at runtime", outfile
);
904 fputs_filtered ("<invalid location>", outfile
);
907 fputs_filtered (", ", outfile
);
908 fputs_filtered (paddress (gdbarch
, (*p
)->unrelocated_address ()), outfile
);
909 fprintf_filtered (outfile
, "\n");
915 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
916 struct ui_file
*outfile
)
918 struct gdbarch
*gdbarch
= objfile
->arch ();
921 if (psymtab
->anonymous
)
923 fprintf_filtered (outfile
, "\nAnonymous partial symtab (%s) ",
928 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
931 fprintf_filtered (outfile
, "(object ");
932 gdb_print_host_address (psymtab
, outfile
);
933 fprintf_filtered (outfile
, ")\n\n");
934 fprintf_filtered (outfile
, " Read from object file %s (",
935 objfile_name (objfile
));
936 gdb_print_host_address (objfile
, outfile
);
937 fprintf_filtered (outfile
, ")\n");
939 if (psymtab
->readin_p (objfile
))
941 fprintf_filtered (outfile
,
942 " Full symtab was read (at ");
943 gdb_print_host_address (psymtab
->get_compunit_symtab (objfile
), outfile
);
944 fprintf_filtered (outfile
, ")\n");
947 fprintf_filtered (outfile
, " Symbols cover text addresses ");
948 fputs_filtered (paddress (gdbarch
, psymtab
->text_low (objfile
)), outfile
);
949 fprintf_filtered (outfile
, "-");
950 fputs_filtered (paddress (gdbarch
, psymtab
->text_high (objfile
)), outfile
);
951 fprintf_filtered (outfile
, "\n");
952 fprintf_filtered (outfile
, " Address map supported - %s.\n",
953 psymtab
->psymtabs_addrmap_supported
? "yes" : "no");
954 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
955 psymtab
->number_of_dependencies
);
956 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
958 fprintf_filtered (outfile
, " %d ", i
);
959 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
960 fprintf_filtered (outfile
, " %s\n",
961 psymtab
->dependencies
[i
]->filename
);
963 if (psymtab
->user
!= NULL
)
965 fprintf_filtered (outfile
, " Shared partial symtab with user ");
966 gdb_print_host_address (psymtab
->user
, outfile
);
967 fprintf_filtered (outfile
, "\n");
969 if (psymtab
->n_global_syms
> 0)
971 print_partial_symbols
973 &objfile
->partial_symtabs
->global_psymbols
[psymtab
->globals_offset
],
974 psymtab
->n_global_syms
, "Global", outfile
);
976 if (psymtab
->n_static_syms
> 0)
978 print_partial_symbols
980 &objfile
->partial_symtabs
->static_psymbols
[psymtab
->statics_offset
],
981 psymtab
->n_static_syms
, "Static", outfile
);
983 fprintf_filtered (outfile
, "\n");
986 /* Psymtab version of print_stats. See its definition in
987 the definition of quick_symbol_functions in symfile.h. */
990 psym_print_stats (struct objfile
*objfile
)
995 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
997 if (!ps
->readin_p (objfile
))
1000 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i
);
1003 /* Psymtab version of dump. See its definition in
1004 the definition of quick_symbol_functions in symfile.h. */
1007 psym_dump (struct objfile
*objfile
)
1009 struct partial_symtab
*psymtab
;
1011 if (objfile
->partial_symtabs
->psymtabs
)
1013 printf_filtered ("Psymtabs:\n");
1014 for (psymtab
= objfile
->partial_symtabs
->psymtabs
;
1016 psymtab
= psymtab
->next
)
1018 printf_filtered ("%s at ",
1020 gdb_print_host_address (psymtab
, gdb_stdout
);
1021 printf_filtered (", ");
1024 printf_filtered ("\n\n");
1028 /* Psymtab version of expand_symtabs_for_function. See its definition in
1029 the definition of quick_symbol_functions in symfile.h. */
1032 psym_expand_symtabs_for_function (struct objfile
*objfile
,
1033 const char *func_name
)
1035 lookup_name_info
base_lookup (func_name
, symbol_name_match_type::FULL
);
1036 lookup_name_info lookup_name
= base_lookup
.make_ignore_params ();
1038 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1040 if (ps
->readin_p (objfile
))
1043 if ((lookup_partial_symbol (objfile
, ps
, lookup_name
, 1, VAR_DOMAIN
)
1045 || (lookup_partial_symbol (objfile
, ps
, lookup_name
, 0, VAR_DOMAIN
)
1047 psymtab_to_symtab (objfile
, ps
);
1051 /* Psymtab version of expand_all_symtabs. See its definition in
1052 the definition of quick_symbol_functions in symfile.h. */
1055 psym_expand_all_symtabs (struct objfile
*objfile
)
1057 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
, true))
1058 psymtab_to_symtab (objfile
, psymtab
);
1061 /* Psymtab version of expand_symtabs_with_fullname. See its definition in
1062 the definition of quick_symbol_functions in symfile.h. */
1065 psym_expand_symtabs_with_fullname (struct objfile
*objfile
,
1066 const char *fullname
)
1068 for (partial_symtab
*p
: require_partial_symbols (objfile
, true))
1070 /* Anonymous psymtabs don't have a name of a source file. */
1074 /* psymtab_to_fullname tries to open the file which is slow.
1075 Don't call it if we know the basenames don't match. */
1076 if ((basenames_may_differ
1077 || filename_cmp (lbasename (fullname
), lbasename (p
->filename
)) == 0)
1078 && filename_cmp (fullname
, psymtab_to_fullname (p
)) == 0)
1079 psymtab_to_symtab (objfile
, p
);
1083 /* Psymtab version of map_symbol_filenames. See its definition in
1084 the definition of quick_symbol_functions in symfile.h. */
1087 psym_map_symbol_filenames (struct objfile
*objfile
,
1088 symbol_filename_ftype
*fun
, void *data
,
1091 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1093 const char *fullname
;
1095 if (ps
->readin_p (objfile
))
1098 /* We can skip shared psymtabs here, because any file name will be
1099 attached to the unshared psymtab. */
1100 if (ps
->user
!= NULL
)
1103 /* Anonymous psymtabs don't have a file name. */
1109 fullname
= psymtab_to_fullname (ps
);
1112 (*fun
) (ps
->filename
, fullname
, data
);
1116 /* Finds the fullname that a partial_symtab represents.
1118 If this functions finds the fullname, it will save it in ps->fullname
1119 and it will also return the value.
1121 If this function fails to find the file that this partial_symtab represents,
1122 NULL will be returned and ps->fullname will be set to NULL. */
1125 psymtab_to_fullname (struct partial_symtab
*ps
)
1127 gdb_assert (!ps
->anonymous
);
1129 /* Use cached copy if we have it.
1130 We rely on forget_cached_source_info being called appropriately
1131 to handle cases like the file being moved. */
1132 if (ps
->fullname
== NULL
)
1134 gdb::unique_xmalloc_ptr
<char> fullname
;
1135 scoped_fd fd
= find_and_open_source (ps
->filename
, ps
->dirname
,
1137 ps
->fullname
= fullname
.release ();
1141 /* rewrite_source_path would be applied by find_and_open_source, we
1142 should report the pathname where GDB tried to find the file. */
1144 if (ps
->dirname
== NULL
|| IS_ABSOLUTE_PATH (ps
->filename
))
1145 fullname
.reset (xstrdup (ps
->filename
));
1147 fullname
.reset (concat (ps
->dirname
, SLASH_STRING
,
1148 ps
->filename
, (char *) NULL
));
1150 ps
->fullname
= rewrite_source_path (fullname
.get ()).release ();
1151 if (ps
->fullname
== NULL
)
1152 ps
->fullname
= fullname
.release ();
1156 return ps
->fullname
;
1159 /* Psymtab version of map_matching_symbols. See its definition in
1160 the definition of quick_symbol_functions in symfile.h. */
1163 psym_map_matching_symbols
1164 (struct objfile
*objfile
,
1165 const lookup_name_info
&name
, domain_enum domain
,
1167 gdb::function_view
<symbol_found_callback_ftype
> callback
,
1168 symbol_compare_ftype
*ordered_compare
)
1170 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
1172 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1175 if (ps
->readin_p (objfile
)
1176 || match_partial_symbol (objfile
, ps
, global
, name
, domain
,
1179 struct compunit_symtab
*cust
= psymtab_to_symtab (objfile
, ps
);
1180 const struct block
*block
;
1184 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
1185 if (!iterate_over_symbols_terminated (block
, name
,
1192 /* A helper for psym_expand_symtabs_matching that handles searching
1193 included psymtabs. This returns true if a symbol is found, and
1194 false otherwise. It also updates the 'searched_flag' on the
1195 various psymtabs that it searches. */
1198 recursively_search_psymtabs
1199 (struct partial_symtab
*ps
,
1200 struct objfile
*objfile
,
1201 enum search_domain domain
,
1202 const lookup_name_info
&lookup_name
,
1203 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> sym_matcher
)
1206 enum psymtab_search_status result
= PST_SEARCHED_AND_NOT_FOUND
;
1209 if (ps
->searched_flag
!= PST_NOT_SEARCHED
)
1210 return ps
->searched_flag
== PST_SEARCHED_AND_FOUND
;
1212 /* Recurse into shared psymtabs first, because they may have already
1213 been searched, and this could save some time. */
1214 for (i
= 0; i
< ps
->number_of_dependencies
; ++i
)
1218 /* Skip non-shared dependencies, these are handled elsewhere. */
1219 if (ps
->dependencies
[i
]->user
== NULL
)
1222 r
= recursively_search_psymtabs (ps
->dependencies
[i
],
1223 objfile
, domain
, lookup_name
,
1227 ps
->searched_flag
= PST_SEARCHED_AND_FOUND
;
1232 partial_symbol
**gbound
1233 = (objfile
->partial_symtabs
->global_psymbols
.data ()
1234 + ps
->globals_offset
+ ps
->n_global_syms
);
1235 partial_symbol
**sbound
1236 = (objfile
->partial_symtabs
->static_psymbols
.data ()
1237 + ps
->statics_offset
+ ps
->n_static_syms
);
1238 partial_symbol
**bound
= gbound
;
1240 /* Go through all of the symbols stored in a partial
1241 symtab in one loop. */
1242 partial_symbol
**psym
= (objfile
->partial_symtabs
->global_psymbols
.data ()
1243 + ps
->globals_offset
);
1248 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
1250 psym
= (objfile
->partial_symtabs
->static_psymbols
.data ()
1251 + ps
->statics_offset
);
1262 if ((domain
== ALL_DOMAIN
1263 || (domain
== MODULES_DOMAIN
1264 && (*psym
)->domain
== MODULE_DOMAIN
)
1265 || (domain
== VARIABLES_DOMAIN
1266 && (*psym
)->aclass
!= LOC_TYPEDEF
1267 && (*psym
)->aclass
!= LOC_BLOCK
)
1268 || (domain
== FUNCTIONS_DOMAIN
1269 && (*psym
)->aclass
== LOC_BLOCK
)
1270 || (domain
== TYPES_DOMAIN
1271 && (*psym
)->aclass
== LOC_TYPEDEF
))
1272 && psymbol_name_matches (*psym
, lookup_name
)
1273 && (sym_matcher
== NULL
1274 || sym_matcher ((*psym
)->ginfo
.search_name ())))
1276 /* Found a match, so notify our caller. */
1277 result
= PST_SEARCHED_AND_FOUND
;
1284 ps
->searched_flag
= result
;
1285 return result
== PST_SEARCHED_AND_FOUND
;
1288 /* Psymtab version of expand_symtabs_matching. See its definition in
1289 the definition of quick_symbol_functions in symfile.h. */
1292 psym_expand_symtabs_matching
1293 (struct objfile
*objfile
,
1294 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
1295 const lookup_name_info
*lookup_name
,
1296 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
1297 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
1298 enum search_domain domain
)
1300 /* Clear the search flags. */
1301 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1302 ps
->searched_flag
= PST_NOT_SEARCHED
;
1304 for (partial_symtab
*ps
: objfile
->psymtabs ())
1308 if (ps
->readin_p (objfile
))
1311 /* We skip shared psymtabs because file-matching doesn't apply
1312 to them; but we search them later in the loop. */
1313 if (ps
->user
!= NULL
)
1323 match
= file_matcher (ps
->filename
, false);
1326 /* Before we invoke realpath, which can get expensive when many
1327 files are involved, do a quick comparison of the basenames. */
1328 if (basenames_may_differ
1329 || file_matcher (lbasename (ps
->filename
), true))
1330 match
= file_matcher (psymtab_to_fullname (ps
), false);
1336 if ((symbol_matcher
== NULL
&& lookup_name
== NULL
)
1337 || recursively_search_psymtabs (ps
, objfile
, domain
,
1338 lookup_name
->make_ignore_params (),
1341 struct compunit_symtab
*symtab
=
1342 psymtab_to_symtab (objfile
, ps
);
1344 if (expansion_notify
!= NULL
)
1345 expansion_notify (symtab
);
1350 /* Psymtab version of has_symbols. See its definition in
1351 the definition of quick_symbol_functions in symfile.h. */
1354 psym_has_symbols (struct objfile
*objfile
)
1356 return objfile
->partial_symtabs
->psymtabs
!= NULL
;
1359 /* Helper function for psym_find_compunit_symtab_by_address that fills
1360 in psymbol_map for a given range of psymbols. */
1363 psym_fill_psymbol_map (struct objfile
*objfile
,
1364 struct partial_symtab
*psymtab
,
1365 std::set
<CORE_ADDR
> *seen_addrs
,
1366 const std::vector
<partial_symbol
*> &symbols
,
1370 for (int i
= 0; i
< length
; ++i
)
1372 struct partial_symbol
*psym
= symbols
[start
+ i
];
1374 if (psym
->aclass
== LOC_STATIC
)
1376 CORE_ADDR addr
= psym
->address (objfile
);
1377 if (seen_addrs
->find (addr
) == seen_addrs
->end ())
1379 seen_addrs
->insert (addr
);
1380 objfile
->psymbol_map
.emplace_back (addr
, psymtab
);
1386 /* See find_compunit_symtab_by_address in quick_symbol_functions, in
1389 static compunit_symtab
*
1390 psym_find_compunit_symtab_by_address (struct objfile
*objfile
,
1393 if (objfile
->psymbol_map
.empty ())
1395 std::set
<CORE_ADDR
> seen_addrs
;
1397 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
1399 psym_fill_psymbol_map (objfile
, pst
,
1401 objfile
->partial_symtabs
->global_psymbols
,
1402 pst
->globals_offset
,
1403 pst
->n_global_syms
);
1404 psym_fill_psymbol_map (objfile
, pst
,
1406 objfile
->partial_symtabs
->static_psymbols
,
1407 pst
->statics_offset
,
1408 pst
->n_static_syms
);
1411 objfile
->psymbol_map
.shrink_to_fit ();
1413 std::sort (objfile
->psymbol_map
.begin (), objfile
->psymbol_map
.end (),
1414 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1415 const std::pair
<CORE_ADDR
, partial_symtab
*> &b
)
1417 return a
.first
< b
.first
;
1421 auto iter
= std::lower_bound
1422 (objfile
->psymbol_map
.begin (), objfile
->psymbol_map
.end (), address
,
1423 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1429 if (iter
== objfile
->psymbol_map
.end () || iter
->first
!= address
)
1432 return psymtab_to_symtab (objfile
, iter
->second
);
1435 const struct quick_symbol_functions psym_functions
=
1438 psym_find_last_source_symtab
,
1439 psym_forget_cached_source_info
,
1440 psym_map_symtabs_matching_filename
,
1442 psym_lookup_global_symbol_language
,
1445 psym_expand_symtabs_for_function
,
1446 psym_expand_all_symtabs
,
1447 psym_expand_symtabs_with_fullname
,
1448 psym_map_matching_symbols
,
1449 psym_expand_symtabs_matching
,
1450 psym_find_pc_sect_compunit_symtab
,
1451 psym_find_compunit_symtab_by_address
,
1452 psym_map_symbol_filenames
1458 sort_pst_symbols (struct objfile
*objfile
, struct partial_symtab
*pst
)
1460 /* Sort the global list; don't sort the static list. */
1461 auto begin
= objfile
->partial_symtabs
->global_psymbols
.begin ();
1462 std::advance (begin
, pst
->globals_offset
);
1464 /* The psymbols for this partial_symtab are currently at the end of the
1466 auto end
= objfile
->partial_symtabs
->global_psymbols
.end ();
1468 std::sort (begin
, end
, [] (partial_symbol
*s1
, partial_symbol
*s2
)
1470 return strcmp_iw_ordered (s1
->ginfo
.search_name (),
1471 s2
->ginfo
.search_name ()) < 0;
1475 /* Partially fill a partial symtab. It will be completely filled at
1476 the end of the symbol list. */
1478 partial_symtab::partial_symtab (const char *filename
,
1479 struct objfile
*objfile
,
1481 : partial_symtab (filename
, objfile
)
1483 set_text_low (textlow
);
1484 set_text_high (raw_text_low ()); /* default */
1486 auto *v1
= new std::vector
<partial_symbol
*>;
1487 objfile
->partial_symtabs
->current_global_psymbols
.push_back (v1
);
1488 auto *v2
= new std::vector
<partial_symbol
*>;
1489 objfile
->partial_symtabs
->current_static_psymbols
.push_back (v2
);
1492 /* Concat vectors V1 and V2. */
1495 concat (std::vector
<partial_symbol
*> *v1
, std::vector
<partial_symbol
*> *v2
)
1497 v1
->insert (v1
->end (), v2
->begin (), v2
->end ());
1501 /* Perform "finishing up" operations of a partial symtab. */
1504 end_psymtab_common (struct objfile
*objfile
, struct partial_symtab
*pst
)
1506 pst
->globals_offset
= objfile
->partial_symtabs
->global_psymbols
.size ();
1507 pst
->statics_offset
= objfile
->partial_symtabs
->static_psymbols
.size ();
1509 auto *current_global_psymbols
1510 = objfile
->partial_symtabs
->current_global_psymbols
.back ();
1511 auto *current_static_psymbols
1512 = objfile
->partial_symtabs
->current_static_psymbols
.back ();
1513 objfile
->partial_symtabs
->current_global_psymbols
.pop_back ();
1514 objfile
->partial_symtabs
->current_static_psymbols
.pop_back ();
1517 = current_global_psymbols
->size ();
1519 = current_static_psymbols
->size ();
1521 concat (&objfile
->partial_symtabs
->global_psymbols
, current_global_psymbols
);
1522 concat (&objfile
->partial_symtabs
->static_psymbols
, current_static_psymbols
);
1524 delete current_global_psymbols
;
1525 delete current_static_psymbols
;
1527 sort_pst_symbols (objfile
, pst
);
1530 /* See psymtab.h. */
1533 psymbol_bcache::hash (const void *addr
, int length
)
1535 unsigned long h
= 0;
1536 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1537 unsigned int lang
= psymbol
->ginfo
.language ();
1538 unsigned int domain
= psymbol
->domain
;
1539 unsigned int theclass
= psymbol
->aclass
;
1541 h
= fast_hash (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1542 h
= fast_hash (&lang
, sizeof (unsigned int), h
);
1543 h
= fast_hash (&domain
, sizeof (unsigned int), h
);
1544 h
= fast_hash (&theclass
, sizeof (unsigned int), h
);
1545 /* Note that psymbol names are interned via compute_and_set_names, so
1546 there's no need to hash the contents of the name here. */
1547 h
= fast_hash (&psymbol
->ginfo
.m_name
, sizeof (psymbol
->ginfo
.m_name
), h
);
1552 /* See psymtab.h. */
1555 psymbol_bcache::compare (const void *addr1
, const void *addr2
, int length
)
1557 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1558 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1560 return (memcmp (&sym1
->ginfo
.value
, &sym2
->ginfo
.value
,
1561 sizeof (sym1
->ginfo
.value
)) == 0
1562 && sym1
->ginfo
.language () == sym2
->ginfo
.language ()
1563 && sym1
->domain
== sym2
->domain
1564 && sym1
->aclass
== sym2
->aclass
1565 /* Note that psymbol names are interned via
1566 compute_and_set_names, so there's no need to compare the
1567 contents of the name here. */
1568 && sym1
->ginfo
.linkage_name () == sym2
->ginfo
.linkage_name ());
1571 /* Helper function, initialises partial symbol structure and stashes
1572 it into objfile's bcache. Note that our caching mechanism will
1573 use all fields of struct partial_symbol to determine hash value of the
1574 structure. In other words, having two symbols with the same name but
1575 different domain (or address) is possible and correct. */
1577 static struct partial_symbol
*
1578 add_psymbol_to_bcache (const partial_symbol
&psymbol
, struct objfile
*objfile
,
1581 /* Stash the partial symbol away in the cache. */
1582 return ((struct partial_symbol
*)
1583 objfile
->partial_symtabs
->psymbol_cache
.insert
1584 (&psymbol
, sizeof (struct partial_symbol
), added
));
1587 /* Helper function, adds partial symbol to the given partial symbol list. */
1590 append_psymbol_to_list (std::vector
<partial_symbol
*> *list
,
1591 struct partial_symbol
*psym
,
1592 struct objfile
*objfile
)
1594 list
->push_back (psym
);
1595 OBJSTAT (objfile
, n_psyms
++);
1598 /* See psympriv.h. */
1601 add_psymbol_to_list (const partial_symbol
&psymbol
,
1602 psymbol_placement where
,
1603 struct objfile
*objfile
)
1607 /* Stash the partial symbol away in the cache. */
1608 partial_symbol
*psym
= add_psymbol_to_bcache (psymbol
, objfile
, &added
);
1610 /* Do not duplicate global partial symbols. */
1611 if (where
== psymbol_placement::GLOBAL
&& !added
)
1614 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1615 std::vector
<partial_symbol
*> *list
1616 = (where
== psymbol_placement::STATIC
1617 ? objfile
->partial_symtabs
->current_static_psymbols
.back ()
1618 : objfile
->partial_symtabs
->current_global_psymbols
.back ());
1619 append_psymbol_to_list (list
, psym
, objfile
);
1622 /* See psympriv.h. */
1625 add_psymbol_to_list (gdb::string_view name
, bool copy_name
,
1627 enum address_class theclass
,
1629 psymbol_placement where
,
1631 enum language language
, struct objfile
*objfile
)
1633 struct partial_symbol psymbol
;
1634 memset (&psymbol
, 0, sizeof (psymbol
));
1636 psymbol
.set_unrelocated_address (coreaddr
);
1637 psymbol
.ginfo
.section
= section
;
1638 psymbol
.domain
= domain
;
1639 psymbol
.aclass
= theclass
;
1640 psymbol
.ginfo
.set_language (language
, objfile
->partial_symtabs
->obstack ());
1641 psymbol
.ginfo
.compute_and_set_names (name
, copy_name
, objfile
->per_bfd
);
1643 add_psymbol_to_list (psymbol
, where
, objfile
);
1646 /* See psympriv.h. */
1649 init_psymbol_list (struct objfile
*objfile
, int total_symbols
)
1651 if (objfile
->partial_symtabs
->global_psymbols
.capacity () == 0
1652 && objfile
->partial_symtabs
->static_psymbols
.capacity () == 0)
1654 /* Current best guess is that approximately a twentieth of the
1655 total symbols (in a debugging file) are global or static
1656 oriented symbols, then multiply that by slop factor of
1658 objfile
->partial_symtabs
->global_psymbols
.reserve (total_symbols
/ 10);
1659 objfile
->partial_symtabs
->static_psymbols
.reserve (total_symbols
/ 10);
1663 /* See psympriv.h. */
1665 partial_symtab::partial_symtab (const char *filename_
, struct objfile
*objfile
)
1666 : searched_flag (PST_NOT_SEARCHED
),
1670 objfile
->partial_symtabs
->install_psymtab (this);
1672 filename
= objfile
->intern (filename_
);
1674 if (symtab_create_debug
)
1676 /* Be a bit clever with debugging messages, and don't print objfile
1677 every time, only when it changes. */
1678 static char *last_objfile_name
= NULL
;
1680 if (last_objfile_name
== NULL
1681 || strcmp (last_objfile_name
, objfile_name (objfile
)) != 0)
1683 xfree (last_objfile_name
);
1684 last_objfile_name
= xstrdup (objfile_name (objfile
));
1685 fprintf_filtered (gdb_stdlog
,
1686 "Creating one or more psymtabs for objfile %s ...\n",
1689 fprintf_filtered (gdb_stdlog
,
1690 "Created psymtab %s for module %s.\n",
1691 host_address_to_string (this), filename
);
1695 /* See psympriv.h. */
1698 partial_symtab::expand_dependencies (struct objfile
*objfile
)
1700 for (int i
= 0; i
< number_of_dependencies
; ++i
)
1702 if (!dependencies
[i
]->readin_p (objfile
)
1703 && dependencies
[i
]->user
== NULL
)
1705 /* Inform about additional files to be read in. */
1708 fputs_filtered (" ", gdb_stdout
);
1710 fputs_filtered ("and ", gdb_stdout
);
1712 printf_filtered ("%s...", dependencies
[i
]->filename
);
1713 wrap_here (""); /* Flush output */
1714 gdb_flush (gdb_stdout
);
1716 dependencies
[i
]->expand_psymtab (objfile
);
1723 psymtab_storage::discard_psymtab (struct partial_symtab
*pst
)
1725 struct partial_symtab
**prev_pst
;
1728 Empty psymtabs happen as a result of header files which don't
1729 have any symbols in them. There can be a lot of them. But this
1730 check is wrong, in that a psymtab with N_SLINE entries but
1731 nothing else is not empty, but we don't realize that. Fixing
1732 that without slowing things down might be tricky. */
1734 /* First, snip it out of the psymtab chain. */
1736 prev_pst
= &psymtabs
;
1737 while ((*prev_pst
) != pst
)
1738 prev_pst
= &((*prev_pst
)->next
);
1739 (*prev_pst
) = pst
->next
;
1745 /* We need to pass a couple of items to the addrmap_foreach function,
1748 struct dump_psymtab_addrmap_data
1750 struct objfile
*objfile
;
1751 struct partial_symtab
*psymtab
;
1752 struct ui_file
*outfile
;
1754 /* Non-zero if the previously printed addrmap entry was for PSYMTAB.
1755 If so, we want to print the next one as well (since the next addrmap
1756 entry defines the end of the range). */
1757 int previous_matched
;
1760 /* Helper function for dump_psymtab_addrmap to print an addrmap entry. */
1763 dump_psymtab_addrmap_1 (void *datap
, CORE_ADDR start_addr
, void *obj
)
1765 struct dump_psymtab_addrmap_data
*data
1766 = (struct dump_psymtab_addrmap_data
*) datap
;
1767 struct gdbarch
*gdbarch
= data
->objfile
->arch ();
1768 struct partial_symtab
*addrmap_psymtab
= (struct partial_symtab
*) obj
;
1769 const char *psymtab_address_or_end
= NULL
;
1773 if (data
->psymtab
== NULL
1774 || data
->psymtab
== addrmap_psymtab
)
1775 psymtab_address_or_end
= host_address_to_string (addrmap_psymtab
);
1776 else if (data
->previous_matched
)
1777 psymtab_address_or_end
= "<ends here>";
1779 if (data
->psymtab
== NULL
1780 || data
->psymtab
== addrmap_psymtab
1781 || data
->previous_matched
)
1783 fprintf_filtered (data
->outfile
, " %s%s %s\n",
1784 data
->psymtab
!= NULL
? " " : "",
1785 paddress (gdbarch
, start_addr
),
1786 psymtab_address_or_end
);
1789 data
->previous_matched
= (data
->psymtab
== NULL
1790 || data
->psymtab
== addrmap_psymtab
);
1795 /* Helper function for maintenance_print_psymbols to print the addrmap
1796 of PSYMTAB. If PSYMTAB is NULL print the entire addrmap. */
1799 dump_psymtab_addrmap (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
1800 struct ui_file
*outfile
)
1802 struct dump_psymtab_addrmap_data addrmap_dump_data
;
1804 if ((psymtab
== NULL
1805 || psymtab
->psymtabs_addrmap_supported
)
1806 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
1808 addrmap_dump_data
.objfile
= objfile
;
1809 addrmap_dump_data
.psymtab
= psymtab
;
1810 addrmap_dump_data
.outfile
= outfile
;
1811 addrmap_dump_data
.previous_matched
= 0;
1812 fprintf_filtered (outfile
, "%sddress map:\n",
1813 psymtab
== NULL
? "Entire a" : " A");
1814 addrmap_foreach (objfile
->partial_symtabs
->psymtabs_addrmap
,
1815 dump_psymtab_addrmap_1
, &addrmap_dump_data
);
1820 maintenance_print_psymbols (const char *args
, int from_tty
)
1822 struct ui_file
*outfile
= gdb_stdout
;
1823 char *address_arg
= NULL
, *source_arg
= NULL
, *objfile_arg
= NULL
;
1824 int i
, outfile_idx
, found
;
1826 struct obj_section
*section
= NULL
;
1830 gdb_argv
argv (args
);
1832 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
1834 if (strcmp (argv
[i
], "-pc") == 0)
1836 if (argv
[i
+ 1] == NULL
)
1837 error (_("Missing pc value"));
1838 address_arg
= argv
[++i
];
1840 else if (strcmp (argv
[i
], "-source") == 0)
1842 if (argv
[i
+ 1] == NULL
)
1843 error (_("Missing source file"));
1844 source_arg
= argv
[++i
];
1846 else if (strcmp (argv
[i
], "-objfile") == 0)
1848 if (argv
[i
+ 1] == NULL
)
1849 error (_("Missing objfile name"));
1850 objfile_arg
= argv
[++i
];
1852 else if (strcmp (argv
[i
], "--") == 0)
1854 /* End of options. */
1858 else if (argv
[i
][0] == '-')
1860 /* Future proofing: Don't allow OUTFILE to begin with "-". */
1861 error (_("Unknown option: %s"), argv
[i
]);
1868 if (address_arg
!= NULL
&& source_arg
!= NULL
)
1869 error (_("Must specify at most one of -pc and -source"));
1871 stdio_file arg_outfile
;
1873 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
1875 if (argv
[outfile_idx
+ 1] != NULL
)
1876 error (_("Junk at end of command"));
1877 gdb::unique_xmalloc_ptr
<char> outfile_name
1878 (tilde_expand (argv
[outfile_idx
]));
1879 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
1880 perror_with_name (outfile_name
.get ());
1881 outfile
= &arg_outfile
;
1884 if (address_arg
!= NULL
)
1886 pc
= parse_and_eval_address (address_arg
);
1887 /* If we fail to find a section, that's ok, try the lookup anyway. */
1888 section
= find_pc_section (pc
);
1892 for (objfile
*objfile
: current_program_space
->objfiles ())
1894 int printed_objfile_header
= 0;
1895 int print_for_objfile
= 1;
1898 if (objfile_arg
!= NULL
)
1900 = compare_filenames_for_search (objfile_name (objfile
),
1902 if (!print_for_objfile
)
1905 if (address_arg
!= NULL
)
1907 struct bound_minimal_symbol msymbol
= { NULL
, NULL
};
1909 /* We don't assume each pc has a unique objfile (this is for
1911 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
,
1915 if (!printed_objfile_header
)
1917 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1918 objfile_name (objfile
));
1919 printed_objfile_header
= 1;
1921 dump_psymtab (objfile
, ps
, outfile
);
1922 dump_psymtab_addrmap (objfile
, ps
, outfile
);
1928 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1930 int print_for_source
= 0;
1933 if (source_arg
!= NULL
)
1936 = compare_filenames_for_search (ps
->filename
, source_arg
);
1939 if (source_arg
== NULL
1940 || print_for_source
)
1942 if (!printed_objfile_header
)
1944 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1945 objfile_name (objfile
));
1946 printed_objfile_header
= 1;
1948 dump_psymtab (objfile
, ps
, outfile
);
1949 dump_psymtab_addrmap (objfile
, ps
, outfile
);
1954 /* If we're printing all the objfile's symbols dump the full addrmap. */
1956 if (address_arg
== NULL
1957 && source_arg
== NULL
1958 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
1960 outfile
->puts ("\n");
1961 dump_psymtab_addrmap (objfile
, NULL
, outfile
);
1967 if (address_arg
!= NULL
)
1968 error (_("No partial symtab for address: %s"), address_arg
);
1969 if (source_arg
!= NULL
)
1970 error (_("No partial symtab for source file: %s"), source_arg
);
1974 /* List all the partial symbol tables whose names match REGEXP (optional). */
1977 maintenance_info_psymtabs (const char *regexp
, int from_tty
)
1982 for (struct program_space
*pspace
: program_spaces
)
1983 for (objfile
*objfile
: pspace
->objfiles ())
1985 struct gdbarch
*gdbarch
= objfile
->arch ();
1987 /* We don't want to print anything for this objfile until we
1988 actually find a symtab whose name matches. */
1989 int printed_objfile_start
= 0;
1991 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
, true))
1996 || re_exec (psymtab
->filename
))
1998 if (! printed_objfile_start
)
2000 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
2002 printf_filtered ("((struct objfile *) %s)\n",
2003 host_address_to_string (objfile
));
2004 printed_objfile_start
= 1;
2007 printf_filtered (" { psymtab %s ", psymtab
->filename
);
2009 printf_filtered ("((struct partial_symtab *) %s)\n",
2010 host_address_to_string (psymtab
));
2012 printf_filtered (" readin %s\n",
2013 psymtab
->readin_p (objfile
) ? "yes" : "no");
2014 printf_filtered (" fullname %s\n",
2016 ? psymtab
->fullname
: "(null)");
2017 printf_filtered (" text addresses ");
2018 fputs_filtered (paddress (gdbarch
,
2019 psymtab
->text_low (objfile
)),
2021 printf_filtered (" -- ");
2022 fputs_filtered (paddress (gdbarch
,
2023 psymtab
->text_high (objfile
)),
2025 printf_filtered ("\n");
2026 printf_filtered (" psymtabs_addrmap_supported %s\n",
2027 (psymtab
->psymtabs_addrmap_supported
2029 printf_filtered (" globals ");
2030 if (psymtab
->n_global_syms
)
2032 auto p
= &(objfile
->partial_symtabs
2033 ->global_psymbols
[psymtab
->globals_offset
]);
2036 ("(* (struct partial_symbol **) %s @ %d)\n",
2037 host_address_to_string (p
),
2038 psymtab
->n_global_syms
);
2041 printf_filtered ("(none)\n");
2042 printf_filtered (" statics ");
2043 if (psymtab
->n_static_syms
)
2045 auto p
= &(objfile
->partial_symtabs
2046 ->static_psymbols
[psymtab
->statics_offset
]);
2049 ("(* (struct partial_symbol **) %s @ %d)\n",
2050 host_address_to_string (p
),
2051 psymtab
->n_static_syms
);
2054 printf_filtered ("(none)\n");
2056 printf_filtered (" user %s "
2057 "((struct partial_symtab *) %s)\n",
2058 psymtab
->user
->filename
,
2059 host_address_to_string (psymtab
->user
));
2060 printf_filtered (" dependencies ");
2061 if (psymtab
->number_of_dependencies
)
2065 printf_filtered ("{\n");
2066 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
2068 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
2070 /* Note the string concatenation there --- no
2072 printf_filtered (" psymtab %s "
2073 "((struct partial_symtab *) %s)\n",
2075 host_address_to_string (dep
));
2077 printf_filtered (" }\n");
2080 printf_filtered ("(none)\n");
2081 printf_filtered (" }\n");
2085 if (printed_objfile_start
)
2086 printf_filtered ("}\n");
2090 /* Check consistency of currently expanded psymtabs vs symtabs. */
2093 maintenance_check_psymtabs (const char *ignore
, int from_tty
)
2096 struct compunit_symtab
*cust
= NULL
;
2097 const struct blockvector
*bv
;
2098 const struct block
*b
;
2101 for (objfile
*objfile
: current_program_space
->objfiles ())
2102 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
2104 struct gdbarch
*gdbarch
= objfile
->arch ();
2106 /* We don't call psymtab_to_symtab here because that may cause symtab
2107 expansion. When debugging a problem it helps if checkers leave
2108 things unchanged. */
2109 cust
= ps
->get_compunit_symtab (objfile
);
2111 /* First do some checks that don't require the associated symtab. */
2112 if (ps
->text_high (objfile
) < ps
->text_low (objfile
))
2114 printf_filtered ("Psymtab ");
2115 puts_filtered (ps
->filename
);
2116 printf_filtered (" covers bad range ");
2117 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
2119 printf_filtered (" - ");
2120 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
2122 printf_filtered ("\n");
2126 /* Now do checks requiring the associated symtab. */
2129 bv
= COMPUNIT_BLOCKVECTOR (cust
);
2130 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
2131 partial_symbol
**psym
2132 = &objfile
->partial_symtabs
->static_psymbols
[ps
->statics_offset
];
2133 for (i
= 0; i
< ps
->n_static_syms
; psym
++, i
++)
2135 /* Skip symbols for inlined functions without address. These may
2136 or may not have a match in the full symtab. */
2137 if ((*psym
)->aclass
== LOC_BLOCK
2138 && (*psym
)->ginfo
.value
.address
== 0)
2141 sym
= block_lookup_symbol (b
, (*psym
)->ginfo
.search_name (),
2142 symbol_name_match_type::SEARCH_NAME
,
2146 printf_filtered ("Static symbol `");
2147 puts_filtered ((*psym
)->ginfo
.linkage_name ());
2148 printf_filtered ("' only found in ");
2149 puts_filtered (ps
->filename
);
2150 printf_filtered (" psymtab\n");
2153 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2154 psym
= &objfile
->partial_symtabs
->global_psymbols
[ps
->globals_offset
];
2155 for (i
= 0; i
< ps
->n_global_syms
; psym
++, i
++)
2157 sym
= block_lookup_symbol (b
, (*psym
)->ginfo
.search_name (),
2158 symbol_name_match_type::SEARCH_NAME
,
2162 printf_filtered ("Global symbol `");
2163 puts_filtered ((*psym
)->ginfo
.linkage_name ());
2164 printf_filtered ("' only found in ");
2165 puts_filtered (ps
->filename
);
2166 printf_filtered (" psymtab\n");
2169 if (ps
->raw_text_high () != 0
2170 && (ps
->text_low (objfile
) < BLOCK_START (b
)
2171 || ps
->text_high (objfile
) > BLOCK_END (b
)))
2173 printf_filtered ("Psymtab ");
2174 puts_filtered (ps
->filename
);
2175 printf_filtered (" covers ");
2176 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
2178 printf_filtered (" - ");
2179 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
2181 printf_filtered (" but symtab covers only ");
2182 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
2183 printf_filtered (" - ");
2184 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
2185 printf_filtered ("\n");
2190 void _initialize_psymtab ();
2192 _initialize_psymtab ()
2194 add_cmd ("psymbols", class_maintenance
, maintenance_print_psymbols
, _("\
2195 Print dump of current partial symbol definitions.\n\
2196 Usage: mt print psymbols [-objfile OBJFILE] [-pc ADDRESS] [--] [OUTFILE]\n\
2197 mt print psymbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
2198 Entries in the partial symbol table are dumped to file OUTFILE,\n\
2199 or the terminal if OUTFILE is unspecified.\n\
2200 If ADDRESS is provided, dump only the file for that address.\n\
2201 If SOURCE is provided, dump only that file's symbols.\n\
2202 If OBJFILE is provided, dump only that file's minimal symbols."),
2203 &maintenanceprintlist
);
2205 add_cmd ("psymtabs", class_maintenance
, maintenance_info_psymtabs
, _("\
2206 List the partial symbol tables for all object files.\n\
2207 This does not include information about individual partial symbols,\n\
2208 just the symbol table structures themselves."),
2209 &maintenanceinfolist
);
2211 add_cmd ("check-psymtabs", class_maintenance
, maintenance_check_psymtabs
,
2213 Check consistency of currently expanded psymtabs versus symtabs."),