1 /* Partial symbol tables.
3 Copyright (C) 2009-2021 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "filenames.h"
31 #include "readline/tilde.h"
32 #include "gdb_regex.h"
33 #include "dictionary.h"
35 #include "cp-support.h"
40 static struct partial_symbol
*lookup_partial_symbol (struct objfile
*,
41 struct partial_symtab
*,
42 const lookup_name_info
&,
46 static const char *psymtab_to_fullname (struct partial_symtab
*ps
);
48 static struct partial_symbol
*find_pc_sect_psymbol (struct objfile
*,
49 struct partial_symtab
*,
51 struct obj_section
*);
53 static struct compunit_symtab
*psymtab_to_symtab (struct objfile
*objfile
,
54 struct partial_symtab
*pst
);
56 psymtab_storage::~psymtab_storage ()
58 partial_symtab
*iter
= psymtabs
;
59 while (iter
!= nullptr)
61 partial_symtab
*next
= iter
->next
;
70 psymtab_storage::install_psymtab (partial_symtab
*pst
)
80 psymtab_storage::partial_symtab_range
81 require_partial_symbols (struct objfile
*objfile
, bool verbose
)
83 if ((objfile
->flags
& OBJF_PSYMTABS_READ
) == 0)
85 objfile
->flags
|= OBJF_PSYMTABS_READ
;
87 if (objfile
->sf
!= nullptr
88 && objfile
->sf
->sym_read_psymbols
)
91 printf_filtered (_("Reading symbols from %s...\n"),
92 objfile_name (objfile
));
93 (*objfile
->sf
->sym_read_psymbols
) (objfile
);
95 if (verbose
&& !objfile_has_symbols (objfile
))
96 printf_filtered (_("(No debugging symbols found in %s)\n"),
97 objfile_name (objfile
));
101 return objfile
->psymtabs ();
104 /* Helper function for psym_map_symtabs_matching_filename that
105 expands the symtabs and calls the iterator. */
108 partial_map_expand_apply (struct objfile
*objfile
,
110 const char *real_path
,
111 struct partial_symtab
*pst
,
112 gdb::function_view
<bool (symtab
*)> callback
)
114 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
116 /* Shared psymtabs should never be seen here. Instead they should
117 be handled properly by the caller. */
118 gdb_assert (pst
->user
== NULL
);
120 /* Don't visit already-expanded psymtabs. */
121 if (pst
->readin_p (objfile
))
124 /* This may expand more than one symtab, and we want to iterate over
126 psymtab_to_symtab (objfile
, pst
);
128 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
129 last_made
, callback
);
132 /* Psymtab version of map_symtabs_matching_filename. See its definition in
133 the definition of quick_symbol_functions in symfile.h. */
136 psymbol_functions::map_symtabs_matching_filename
137 (struct objfile
*objfile
,
139 const char *real_path
,
140 gdb::function_view
<bool (symtab
*)> callback
)
142 const char *name_basename
= lbasename (name
);
144 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
146 /* Anonymous psymtabs don't have a file name. */
150 if (compare_filenames_for_search (pst
->filename
, name
))
155 if (partial_map_expand_apply (objfile
, name
, real_path
,
161 /* Before we invoke realpath, which can get expensive when many
162 files are involved, do a quick comparison of the basenames. */
163 if (! basenames_may_differ
164 && FILENAME_CMP (name_basename
, lbasename (pst
->filename
)) != 0)
167 if (compare_filenames_for_search (psymtab_to_fullname (pst
), name
))
169 if (partial_map_expand_apply (objfile
, name
, real_path
,
175 /* If the user gave us an absolute path, try to find the file in
176 this symtab and use its absolute path. */
177 if (real_path
!= NULL
)
179 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
180 gdb_assert (IS_ABSOLUTE_PATH (name
));
181 if (filename_cmp (psymtab_to_fullname (pst
), real_path
) == 0)
183 if (partial_map_expand_apply (objfile
, name
, real_path
,
194 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
195 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
197 static struct partial_symtab
*
198 find_pc_sect_psymtab_closer (struct objfile
*objfile
,
199 CORE_ADDR pc
, struct obj_section
*section
,
200 struct partial_symtab
*pst
,
201 struct bound_minimal_symbol msymbol
)
203 struct partial_symtab
*tpst
;
204 struct partial_symtab
*best_pst
= pst
;
205 CORE_ADDR best_addr
= pst
->text_low (objfile
);
207 gdb_assert (!pst
->psymtabs_addrmap_supported
);
209 /* An objfile that has its functions reordered might have
210 many partial symbol tables containing the PC, but
211 we want the partial symbol table that contains the
212 function containing the PC. */
213 if (!(objfile
->flags
& OBJF_REORDERED
)
214 && section
== NULL
) /* Can't validate section this way. */
217 if (msymbol
.minsym
== NULL
)
220 /* The code range of partial symtabs sometimes overlap, so, in
221 the loop below, we need to check all partial symtabs and
222 find the one that fits better for the given PC address. We
223 select the partial symtab that contains a symbol whose
224 address is closest to the PC address. By closest we mean
225 that find_pc_sect_symbol returns the symbol with address
226 that is closest and still less than the given PC. */
227 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
229 if (pc
>= tpst
->text_low (objfile
) && pc
< tpst
->text_high (objfile
))
231 struct partial_symbol
*p
;
234 /* NOTE: This assumes that every psymbol has a
235 corresponding msymbol, which is not necessarily
236 true; the debug info might be much richer than the
237 object's symbol table. */
238 p
= find_pc_sect_psymbol (objfile
, tpst
, pc
, section
);
240 && (p
->address (objfile
) == BMSYMBOL_VALUE_ADDRESS (msymbol
)))
243 /* Also accept the textlow value of a psymtab as a
244 "symbol", to provide some support for partial
245 symbol tables with line information but no debug
246 symbols (e.g. those produced by an assembler). */
248 this_addr
= p
->address (objfile
);
250 this_addr
= tpst
->text_low (objfile
);
252 /* Check whether it is closer than our current
253 BEST_ADDR. Since this symbol address is
254 necessarily lower or equal to PC, the symbol closer
255 to PC is the symbol which address is the highest.
256 This way we return the psymtab which contains such
257 best match symbol. This can help in cases where the
258 symbol information/debuginfo is not complete, like
259 for instance on IRIX6 with gcc, where no debug info
260 is emitted for statics. (See also the nodebug.exp
262 if (this_addr
> best_addr
)
264 best_addr
= this_addr
;
272 /* Find which partial symtab contains PC and SECTION. Return NULL if
273 none. We return the psymtab that contains a symbol whose address
274 exactly matches PC, or, if we cannot find an exact match, the
275 psymtab that contains a symbol whose address is closest to PC. */
277 static struct partial_symtab
*
278 find_pc_sect_psymtab (struct objfile
*objfile
, CORE_ADDR pc
,
279 struct obj_section
*section
,
280 struct bound_minimal_symbol msymbol
)
282 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better
283 granularity than the later used TEXTLOW/TEXTHIGH one. However, we need
284 to take care as the PSYMTABS_ADDRMAP can hold things other than partial
285 symtabs in some cases.
287 This function should only be called for objfiles that are using partial
288 symtabs, not for objfiles that are using indexes (.gdb_index or
289 .debug_names), however 'maintenance print psymbols' calls this function
290 directly for all objfiles. If we assume that PSYMTABS_ADDRMAP contains
291 partial symtabs then we will end up returning a pointer to an object
292 that is not a partial_symtab, which doesn't end well. */
294 if (objfile
->partial_symtabs
->psymtabs
!= NULL
295 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
297 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
299 struct partial_symtab
*pst
300 = ((struct partial_symtab
*)
301 addrmap_find (objfile
->partial_symtabs
->psymtabs_addrmap
,
305 /* FIXME: addrmaps currently do not handle overlayed sections,
306 so fall back to the non-addrmap case if we're debugging
307 overlays and the addrmap returned the wrong section. */
308 if (overlay_debugging
&& msymbol
.minsym
!= NULL
&& section
!= NULL
)
310 struct partial_symbol
*p
;
312 /* NOTE: This assumes that every psymbol has a
313 corresponding msymbol, which is not necessarily
314 true; the debug info might be much richer than the
315 object's symbol table. */
316 p
= find_pc_sect_psymbol (objfile
, pst
, pc
, section
);
318 || (p
->address (objfile
)
319 != BMSYMBOL_VALUE_ADDRESS (msymbol
)))
323 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
324 PSYMTABS_ADDRMAP we used has already the best 1-byte
325 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
326 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
335 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
336 which still have no corresponding full SYMTABs read. But it is not
337 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
340 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
341 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
342 debug info type in single OBJFILE. */
344 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
345 if (!pst
->psymtabs_addrmap_supported
346 && pc
>= pst
->text_low (objfile
) && pc
< pst
->text_high (objfile
))
348 struct partial_symtab
*best_pst
;
350 best_pst
= find_pc_sect_psymtab_closer (objfile
, pc
, section
, pst
,
352 if (best_pst
!= NULL
)
359 /* Psymtab version of find_pc_sect_compunit_symtab. See its definition in
360 the definition of quick_symbol_functions in symfile.h. */
362 struct compunit_symtab
*
363 psymbol_functions::find_pc_sect_compunit_symtab
364 (struct objfile
*objfile
,
365 struct bound_minimal_symbol msymbol
,
367 struct obj_section
*section
,
370 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
, section
,
374 if (warn_if_readin
&& ps
->readin_p (objfile
))
375 /* Might want to error() here (in case symtab is corrupt and
376 will cause a core dump), but maybe we can successfully
377 continue, so let's not. */
379 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
380 paddress (objfile
->arch (), pc
));
381 psymtab_to_symtab (objfile
, ps
);
382 return ps
->get_compunit_symtab (objfile
);
387 /* Find which partial symbol within a psymtab matches PC and SECTION.
388 Return NULL if none. */
390 static struct partial_symbol
*
391 find_pc_sect_psymbol (struct objfile
*objfile
,
392 struct partial_symtab
*psymtab
, CORE_ADDR pc
,
393 struct obj_section
*section
)
395 struct partial_symbol
*best
= NULL
;
397 const CORE_ADDR textlow
= psymtab
->text_low (objfile
);
399 gdb_assert (psymtab
!= NULL
);
401 /* Cope with programs that start at address 0. */
402 best_pc
= (textlow
!= 0) ? textlow
- 1 : 0;
404 /* Search the global symbols as well as the static symbols, so that
405 find_pc_partial_function doesn't use a minimal symbol and thus
406 cache a bad endaddr. */
407 for (partial_symbol
*p
: psymtab
->global_psymbols
)
409 if (p
->domain
== VAR_DOMAIN
410 && p
->aclass
== LOC_BLOCK
411 && pc
>= p
->address (objfile
)
412 && (p
->address (objfile
) > best_pc
413 || (psymtab
->text_low (objfile
) == 0
414 && best_pc
== 0 && p
->address (objfile
) == 0)))
416 if (section
!= NULL
) /* Match on a specific section. */
418 if (!matching_obj_sections (p
->obj_section (objfile
),
422 best_pc
= p
->address (objfile
);
427 for (partial_symbol
*p
: psymtab
->static_psymbols
)
429 if (p
->domain
== VAR_DOMAIN
430 && p
->aclass
== LOC_BLOCK
431 && pc
>= p
->address (objfile
)
432 && (p
->address (objfile
) > best_pc
433 || (psymtab
->text_low (objfile
) == 0
434 && best_pc
== 0 && p
->address (objfile
) == 0)))
436 if (section
!= NULL
) /* Match on a specific section. */
438 if (!matching_obj_sections (p
->obj_section (objfile
),
442 best_pc
= p
->address (objfile
);
450 /* Psymtab version of lookup_symbol. See its definition in
451 the definition of quick_symbol_functions in symfile.h. */
453 struct compunit_symtab
*
454 psymbol_functions::lookup_symbol (struct objfile
*objfile
,
455 block_enum block_index
, const char *name
,
456 const domain_enum domain
)
458 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
459 struct compunit_symtab
*stab_best
= NULL
;
461 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
463 lookup_name_info psym_lookup_name
= lookup_name
.make_ignore_params ();
465 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
467 if (!ps
->readin_p (objfile
)
468 && lookup_partial_symbol (objfile
, ps
, psym_lookup_name
,
469 psymtab_index
, domain
))
471 struct symbol
*sym
, *with_opaque
= NULL
;
472 struct compunit_symtab
*stab
= psymtab_to_symtab (objfile
, ps
);
473 /* Note: While psymtab_to_symtab can return NULL if the
474 partial symtab is empty, we can assume it won't here
475 because lookup_partial_symbol succeeded. */
476 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
477 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
479 sym
= block_find_symbol (block
, name
, domain
,
480 block_find_non_opaque_type_preferred
,
483 /* Some caution must be observed with overloaded functions
484 and methods, since the index will not contain any overload
485 information (but NAME might contain it). */
488 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
490 if (with_opaque
!= NULL
491 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
494 /* Keep looking through other psymtabs. */
501 /* Psymtab version of lookup_global_symbol_language. See its definition in
502 the definition of quick_symbol_functions in symfile.h. */
505 psymbol_functions::lookup_global_symbol_language (struct objfile
*objfile
,
508 bool *symbol_found_p
)
510 *symbol_found_p
= false;
511 if (objfile
->sf
== NULL
)
512 return language_unknown
;
514 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
516 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
518 struct partial_symbol
*psym
;
519 if (ps
->readin_p (objfile
))
522 psym
= lookup_partial_symbol (objfile
, ps
, lookup_name
, 1, domain
);
525 *symbol_found_p
= true;
526 return psym
->ginfo
.language ();
530 return language_unknown
;
533 /* Returns true if PSYM matches LOOKUP_NAME. */
536 psymbol_name_matches (partial_symbol
*psym
,
537 const lookup_name_info
&lookup_name
)
539 const language_defn
*lang
= language_def (psym
->ginfo
.language ());
540 symbol_name_matcher_ftype
*name_match
541 = lang
->get_symbol_name_matcher (lookup_name
);
542 return name_match (psym
->ginfo
.search_name (), lookup_name
, NULL
);
545 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
546 the global block of PST if GLOBAL, and otherwise the static block.
547 MATCH is the comparison operation that returns true iff MATCH (s,
548 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
549 non-null, the symbols in the block are assumed to be ordered
550 according to it (allowing binary search). It must be compatible
551 with MATCH. Returns the symbol, if found, and otherwise NULL. */
553 static struct partial_symbol
*
554 match_partial_symbol (struct objfile
*objfile
,
555 struct partial_symtab
*pst
, int global
,
556 const lookup_name_info
&name
, domain_enum domain
,
557 symbol_compare_ftype
*ordered_compare
)
559 struct partial_symbol
**start
, **psym
;
560 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
562 ? pst
->global_psymbols
.size ()
563 : pst
->static_psymbols
.size ());
564 int do_linear_search
= 1;
570 &pst
->global_psymbols
[0] :
571 &pst
->static_psymbols
[0]);
573 if (global
&& ordered_compare
) /* Can use a binary search. */
575 do_linear_search
= 0;
577 /* Binary search. This search is guaranteed to end with center
578 pointing at the earliest partial symbol whose name might be
579 correct. At that point *all* partial symbols with an
580 appropriate name will be checked against the correct
584 top
= start
+ length
- 1;
588 center
= bottom
+ (top
- bottom
) / 2;
589 gdb_assert (center
< top
);
591 enum language lang
= (*center
)->ginfo
.language ();
592 const char *lang_ln
= name
.language_lookup_name (lang
);
594 if (ordered_compare ((*center
)->ginfo
.search_name (),
600 gdb_assert (top
== bottom
);
602 while (top
<= real_top
603 && psymbol_name_matches (*top
, name
))
605 if (symbol_matches_domain ((*top
)->ginfo
.language (),
606 (*top
)->domain
, domain
))
612 /* Can't use a binary search or else we found during the binary search that
613 we should also do a linear search. */
615 if (do_linear_search
)
617 for (psym
= start
; psym
< start
+ length
; psym
++)
619 if (symbol_matches_domain ((*psym
)->ginfo
.language (),
620 (*psym
)->domain
, domain
)
621 && psymbol_name_matches (*psym
, name
))
629 /* Look, in partial_symtab PST, for symbol whose natural name is
630 LOOKUP_NAME. Check the global symbols if GLOBAL, the static
633 static struct partial_symbol
*
634 lookup_partial_symbol (struct objfile
*objfile
,
635 struct partial_symtab
*pst
,
636 const lookup_name_info
&lookup_name
,
637 int global
, domain_enum domain
)
639 struct partial_symbol
**start
, **psym
;
640 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
642 ? pst
->global_psymbols
.size ()
643 : pst
->static_psymbols
.size ());
644 int do_linear_search
= 1;
650 &pst
->global_psymbols
[0] :
651 &pst
->static_psymbols
[0]);
653 if (global
) /* This means we can use a binary search. */
655 do_linear_search
= 0;
657 /* Binary search. This search is guaranteed to end with center
658 pointing at the earliest partial symbol whose name might be
659 correct. At that point *all* partial symbols with an
660 appropriate name will be checked against the correct
664 top
= start
+ length
- 1;
668 center
= bottom
+ (top
- bottom
) / 2;
670 gdb_assert (center
< top
);
672 if (strcmp_iw_ordered ((*center
)->ginfo
.search_name (),
673 lookup_name
.c_str ()) >= 0)
683 gdb_assert (top
== bottom
);
685 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
686 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
687 while (top
>= start
&& symbol_matches_search_name (&(*top
)->ginfo
,
691 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
694 while (top
<= real_top
&& symbol_matches_search_name (&(*top
)->ginfo
,
697 if (symbol_matches_domain ((*top
)->ginfo
.language (),
698 (*top
)->domain
, domain
))
704 /* Can't use a binary search or else we found during the binary search that
705 we should also do a linear search. */
707 if (do_linear_search
)
709 for (psym
= start
; psym
< start
+ length
; psym
++)
711 if (symbol_matches_domain ((*psym
)->ginfo
.language (),
712 (*psym
)->domain
, domain
)
713 && symbol_matches_search_name (&(*psym
)->ginfo
, lookup_name
))
721 /* Get the symbol table that corresponds to a partial_symtab.
722 This is fast after the first time you do it.
723 The result will be NULL if the primary symtab has no symbols,
724 which can happen. Otherwise the result is the primary symtab
725 that contains PST. */
727 static struct compunit_symtab
*
728 psymtab_to_symtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
730 /* If it is a shared psymtab, find an unshared psymtab that includes
731 it. Any such psymtab will do. */
732 while (pst
->user
!= NULL
)
735 /* If it's been looked up before, return it. */
736 if (pst
->get_compunit_symtab (objfile
))
737 return pst
->get_compunit_symtab (objfile
);
739 /* If it has not yet been read in, read it. */
740 if (!pst
->readin_p (objfile
))
742 scoped_restore decrementer
= increment_reading_symtab ();
746 printf_filtered (_("Reading in symbols for %s...\n"),
748 gdb_flush (gdb_stdout
);
751 pst
->read_symtab (objfile
);
754 return pst
->get_compunit_symtab (objfile
);
757 /* Psymtab version of find_last_source_symtab. See its definition in
758 the definition of quick_symbol_functions in symfile.h. */
761 psymbol_functions::find_last_source_symtab (struct objfile
*ofp
)
763 struct partial_symtab
*cs_pst
= NULL
;
765 for (partial_symtab
*ps
: require_partial_symbols (ofp
, true))
767 const char *name
= ps
->filename
;
768 int len
= strlen (name
);
770 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
771 || strcmp (name
, "<<C++-namespaces>>") == 0)))
777 if (cs_pst
->readin_p (ofp
))
779 internal_error (__FILE__
, __LINE__
,
780 _("select_source_symtab: "
781 "readin pst found and no symtabs."));
785 struct compunit_symtab
*cust
= psymtab_to_symtab (ofp
, cs_pst
);
789 return compunit_primary_filetab (cust
);
795 /* Psymtab version of forget_cached_source_info. See its definition in
796 the definition of quick_symbol_functions in symfile.h. */
799 psymbol_functions::forget_cached_source_info (struct objfile
*objfile
)
801 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
803 if (pst
->fullname
!= NULL
)
805 xfree (pst
->fullname
);
806 pst
->fullname
= NULL
;
812 print_partial_symbols (struct gdbarch
*gdbarch
, struct objfile
*objfile
,
813 const std::vector
<partial_symbol
*> &symbols
,
814 const char *what
, struct ui_file
*outfile
)
816 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
817 for (partial_symbol
*p
: symbols
)
820 fprintf_filtered (outfile
, " `%s'", p
->ginfo
.linkage_name ());
821 if (p
->ginfo
.demangled_name () != NULL
)
823 fprintf_filtered (outfile
, " `%s'",
824 p
->ginfo
.demangled_name ());
826 fputs_filtered (", ", outfile
);
830 fputs_filtered ("undefined domain, ", outfile
);
833 /* This is the usual thing -- don't print it. */
836 fputs_filtered ("struct domain, ", outfile
);
839 fputs_filtered ("module domain, ", outfile
);
842 fputs_filtered ("label domain, ", outfile
);
844 case COMMON_BLOCK_DOMAIN
:
845 fputs_filtered ("common block domain, ", outfile
);
848 fputs_filtered ("<invalid domain>, ", outfile
);
854 fputs_filtered ("undefined", outfile
);
857 fputs_filtered ("constant int", outfile
);
860 fputs_filtered ("static", outfile
);
863 fputs_filtered ("register", outfile
);
866 fputs_filtered ("pass by value", outfile
);
869 fputs_filtered ("pass by reference", outfile
);
871 case LOC_REGPARM_ADDR
:
872 fputs_filtered ("register address parameter", outfile
);
875 fputs_filtered ("stack parameter", outfile
);
878 fputs_filtered ("type", outfile
);
881 fputs_filtered ("label", outfile
);
884 fputs_filtered ("function", outfile
);
886 case LOC_CONST_BYTES
:
887 fputs_filtered ("constant bytes", outfile
);
890 fputs_filtered ("unresolved", outfile
);
892 case LOC_OPTIMIZED_OUT
:
893 fputs_filtered ("optimized out", outfile
);
896 fputs_filtered ("computed at runtime", outfile
);
899 fputs_filtered ("<invalid location>", outfile
);
902 fputs_filtered (", ", outfile
);
903 fputs_filtered (paddress (gdbarch
, p
->unrelocated_address ()), outfile
);
904 fprintf_filtered (outfile
, "\n");
909 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
910 struct ui_file
*outfile
)
912 struct gdbarch
*gdbarch
= objfile
->arch ();
915 if (psymtab
->anonymous
)
917 fprintf_filtered (outfile
, "\nAnonymous partial symtab (%s) ",
922 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
925 fprintf_filtered (outfile
, "(object ");
926 gdb_print_host_address (psymtab
, outfile
);
927 fprintf_filtered (outfile
, ")\n\n");
928 fprintf_filtered (outfile
, " Read from object file %s (",
929 objfile_name (objfile
));
930 gdb_print_host_address (objfile
, outfile
);
931 fprintf_filtered (outfile
, ")\n");
933 if (psymtab
->readin_p (objfile
))
935 fprintf_filtered (outfile
,
936 " Full symtab was read (at ");
937 gdb_print_host_address (psymtab
->get_compunit_symtab (objfile
), outfile
);
938 fprintf_filtered (outfile
, ")\n");
941 fprintf_filtered (outfile
, " Symbols cover text addresses ");
942 fputs_filtered (paddress (gdbarch
, psymtab
->text_low (objfile
)), outfile
);
943 fprintf_filtered (outfile
, "-");
944 fputs_filtered (paddress (gdbarch
, psymtab
->text_high (objfile
)), outfile
);
945 fprintf_filtered (outfile
, "\n");
946 fprintf_filtered (outfile
, " Address map supported - %s.\n",
947 psymtab
->psymtabs_addrmap_supported
? "yes" : "no");
948 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
949 psymtab
->number_of_dependencies
);
950 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
952 fprintf_filtered (outfile
, " %d ", i
);
953 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
954 fprintf_filtered (outfile
, " %s\n",
955 psymtab
->dependencies
[i
]->filename
);
957 if (psymtab
->user
!= NULL
)
959 fprintf_filtered (outfile
, " Shared partial symtab with user ");
960 gdb_print_host_address (psymtab
->user
, outfile
);
961 fprintf_filtered (outfile
, "\n");
963 if (!psymtab
->global_psymbols
.empty ())
965 print_partial_symbols
966 (gdbarch
, objfile
, psymtab
->global_psymbols
,
969 if (!psymtab
->static_psymbols
.empty ())
971 print_partial_symbols
972 (gdbarch
, objfile
, psymtab
->static_psymbols
,
975 fprintf_filtered (outfile
, "\n");
978 /* Count the number of partial symbols in OBJFILE. */
981 count_psyms (struct objfile
*objfile
)
984 for (partial_symtab
*pst
: objfile
->psymtabs ())
986 count
+= pst
->global_psymbols
.size ();
987 count
+= pst
->static_psymbols
.size ();
992 /* Psymtab version of print_stats. See its definition in
993 the definition of quick_symbol_functions in symfile.h. */
996 psymbol_functions::print_stats (struct objfile
*objfile
, bool print_bcache
)
1002 int n_psyms
= count_psyms (objfile
);
1004 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
1008 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1010 if (!ps
->readin_p (objfile
))
1013 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"),
1015 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
1016 objfile
->partial_symtabs
->psymbol_cache
.memory_used ());
1020 printf_filtered (_("Psymbol byte cache statistics:\n"));
1021 objfile
->partial_symtabs
->psymbol_cache
.print_statistics
1022 ("partial symbol cache");
1026 /* Psymtab version of dump. See its definition in
1027 the definition of quick_symbol_functions in symfile.h. */
1030 psymbol_functions::dump (struct objfile
*objfile
)
1032 struct partial_symtab
*psymtab
;
1034 if (objfile
->partial_symtabs
->psymtabs
)
1036 printf_filtered ("Psymtabs:\n");
1037 for (psymtab
= objfile
->partial_symtabs
->psymtabs
;
1039 psymtab
= psymtab
->next
)
1041 printf_filtered ("%s at ",
1043 gdb_print_host_address (psymtab
, gdb_stdout
);
1044 printf_filtered (", ");
1047 printf_filtered ("\n\n");
1051 /* Psymtab version of expand_symtabs_for_function. See its definition in
1052 the definition of quick_symbol_functions in symfile.h. */
1055 psymbol_functions::expand_symtabs_for_function (struct objfile
*objfile
,
1056 const char *func_name
)
1058 lookup_name_info
base_lookup (func_name
, symbol_name_match_type::FULL
);
1059 lookup_name_info lookup_name
= base_lookup
.make_ignore_params ();
1061 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1063 if (ps
->readin_p (objfile
))
1066 if ((lookup_partial_symbol (objfile
, ps
, lookup_name
, 1, VAR_DOMAIN
)
1068 || (lookup_partial_symbol (objfile
, ps
, lookup_name
, 0, VAR_DOMAIN
)
1070 psymtab_to_symtab (objfile
, ps
);
1074 /* Psymtab version of expand_all_symtabs. See its definition in
1075 the definition of quick_symbol_functions in symfile.h. */
1078 psymbol_functions::expand_all_symtabs (struct objfile
*objfile
)
1080 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
, true))
1081 psymtab_to_symtab (objfile
, psymtab
);
1084 /* Psymtab version of expand_symtabs_with_fullname. See its definition in
1085 the definition of quick_symbol_functions in symfile.h. */
1088 psymbol_functions::expand_symtabs_with_fullname (struct objfile
*objfile
,
1089 const char *fullname
)
1091 for (partial_symtab
*p
: require_partial_symbols (objfile
, true))
1093 /* Anonymous psymtabs don't have a name of a source file. */
1097 /* psymtab_to_fullname tries to open the file which is slow.
1098 Don't call it if we know the basenames don't match. */
1099 if ((basenames_may_differ
1100 || filename_cmp (lbasename (fullname
), lbasename (p
->filename
)) == 0)
1101 && filename_cmp (fullname
, psymtab_to_fullname (p
)) == 0)
1102 psymtab_to_symtab (objfile
, p
);
1106 /* Psymtab version of map_symbol_filenames. See its definition in
1107 the definition of quick_symbol_functions in symfile.h. */
1110 psymbol_functions::map_symbol_filenames (struct objfile
*objfile
,
1111 symbol_filename_ftype
*fun
,
1115 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1117 const char *fullname
;
1119 if (ps
->readin_p (objfile
))
1122 /* We can skip shared psymtabs here, because any file name will be
1123 attached to the unshared psymtab. */
1124 if (ps
->user
!= NULL
)
1127 /* Anonymous psymtabs don't have a file name. */
1133 fullname
= psymtab_to_fullname (ps
);
1136 (*fun
) (ps
->filename
, fullname
, data
);
1140 /* Finds the fullname that a partial_symtab represents.
1142 If this functions finds the fullname, it will save it in ps->fullname
1143 and it will also return the value.
1145 If this function fails to find the file that this partial_symtab represents,
1146 NULL will be returned and ps->fullname will be set to NULL. */
1149 psymtab_to_fullname (struct partial_symtab
*ps
)
1151 gdb_assert (!ps
->anonymous
);
1153 /* Use cached copy if we have it.
1154 We rely on forget_cached_source_info being called appropriately
1155 to handle cases like the file being moved. */
1156 if (ps
->fullname
== NULL
)
1158 gdb::unique_xmalloc_ptr
<char> fullname
;
1159 scoped_fd fd
= find_and_open_source (ps
->filename
, ps
->dirname
,
1161 ps
->fullname
= fullname
.release ();
1165 /* rewrite_source_path would be applied by find_and_open_source, we
1166 should report the pathname where GDB tried to find the file. */
1168 if (ps
->dirname
== NULL
|| IS_ABSOLUTE_PATH (ps
->filename
))
1169 fullname
.reset (xstrdup (ps
->filename
));
1171 fullname
.reset (concat (ps
->dirname
, SLASH_STRING
,
1172 ps
->filename
, (char *) NULL
));
1174 ps
->fullname
= rewrite_source_path (fullname
.get ()).release ();
1175 if (ps
->fullname
== NULL
)
1176 ps
->fullname
= fullname
.release ();
1180 return ps
->fullname
;
1183 /* Psymtab version of map_matching_symbols. See its definition in
1184 the definition of quick_symbol_functions in symfile.h. */
1187 psymbol_functions::map_matching_symbols
1188 (struct objfile
*objfile
,
1189 const lookup_name_info
&name
, domain_enum domain
,
1191 gdb::function_view
<symbol_found_callback_ftype
> callback
,
1192 symbol_compare_ftype
*ordered_compare
)
1194 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
1196 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1199 if (ps
->readin_p (objfile
)
1200 || match_partial_symbol (objfile
, ps
, global
, name
, domain
,
1203 struct compunit_symtab
*cust
= psymtab_to_symtab (objfile
, ps
);
1204 const struct block
*block
;
1208 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
1209 if (!iterate_over_symbols_terminated (block
, name
,
1216 /* A helper for psym_expand_symtabs_matching that handles searching
1217 included psymtabs. This returns true if a symbol is found, and
1218 false otherwise. It also updates the 'searched_flag' on the
1219 various psymtabs that it searches. */
1222 recursively_search_psymtabs
1223 (struct partial_symtab
*ps
,
1224 struct objfile
*objfile
,
1225 enum search_domain domain
,
1226 const lookup_name_info
&lookup_name
,
1227 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> sym_matcher
)
1230 enum psymtab_search_status result
= PST_SEARCHED_AND_NOT_FOUND
;
1233 if (ps
->searched_flag
!= PST_NOT_SEARCHED
)
1234 return ps
->searched_flag
== PST_SEARCHED_AND_FOUND
;
1236 /* Recurse into shared psymtabs first, because they may have already
1237 been searched, and this could save some time. */
1238 for (i
= 0; i
< ps
->number_of_dependencies
; ++i
)
1242 /* Skip non-shared dependencies, these are handled elsewhere. */
1243 if (ps
->dependencies
[i
]->user
== NULL
)
1246 r
= recursively_search_psymtabs (ps
->dependencies
[i
],
1247 objfile
, domain
, lookup_name
,
1251 ps
->searched_flag
= PST_SEARCHED_AND_FOUND
;
1256 partial_symbol
**gbound
= (ps
->global_psymbols
.data ()
1257 + ps
->global_psymbols
.size ());
1258 partial_symbol
**sbound
= (ps
->static_psymbols
.data ()
1259 + ps
->static_psymbols
.size ());
1260 partial_symbol
**bound
= gbound
;
1262 /* Go through all of the symbols stored in a partial
1263 symtab in one loop. */
1264 partial_symbol
**psym
= ps
->global_psymbols
.data ();
1269 if (bound
== gbound
&& !ps
->static_psymbols
.empty ())
1271 psym
= ps
->static_psymbols
.data ();
1282 if ((domain
== ALL_DOMAIN
1283 || (domain
== MODULES_DOMAIN
1284 && (*psym
)->domain
== MODULE_DOMAIN
)
1285 || (domain
== VARIABLES_DOMAIN
1286 && (*psym
)->aclass
!= LOC_TYPEDEF
1287 && (*psym
)->aclass
!= LOC_BLOCK
)
1288 || (domain
== FUNCTIONS_DOMAIN
1289 && (*psym
)->aclass
== LOC_BLOCK
)
1290 || (domain
== TYPES_DOMAIN
1291 && (*psym
)->aclass
== LOC_TYPEDEF
))
1292 && psymbol_name_matches (*psym
, lookup_name
)
1293 && (sym_matcher
== NULL
1294 || sym_matcher ((*psym
)->ginfo
.search_name ())))
1296 /* Found a match, so notify our caller. */
1297 result
= PST_SEARCHED_AND_FOUND
;
1304 ps
->searched_flag
= result
;
1305 return result
== PST_SEARCHED_AND_FOUND
;
1308 /* Psymtab version of expand_symtabs_matching. See its definition in
1309 the definition of quick_symbol_functions in symfile.h. */
1312 psymbol_functions::expand_symtabs_matching
1313 (struct objfile
*objfile
,
1314 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
1315 const lookup_name_info
*lookup_name
,
1316 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
1317 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
1318 enum search_domain domain
)
1320 /* Clear the search flags. */
1321 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1322 ps
->searched_flag
= PST_NOT_SEARCHED
;
1324 for (partial_symtab
*ps
: objfile
->psymtabs ())
1328 if (ps
->readin_p (objfile
))
1331 /* We skip shared psymtabs because file-matching doesn't apply
1332 to them; but we search them later in the loop. */
1333 if (ps
->user
!= NULL
)
1343 match
= file_matcher (ps
->filename
, false);
1346 /* Before we invoke realpath, which can get expensive when many
1347 files are involved, do a quick comparison of the basenames. */
1348 if (basenames_may_differ
1349 || file_matcher (lbasename (ps
->filename
), true))
1350 match
= file_matcher (psymtab_to_fullname (ps
), false);
1356 if ((symbol_matcher
== NULL
&& lookup_name
== NULL
)
1357 || recursively_search_psymtabs (ps
, objfile
, domain
,
1358 lookup_name
->make_ignore_params (),
1361 struct compunit_symtab
*symtab
=
1362 psymtab_to_symtab (objfile
, ps
);
1364 if (expansion_notify
!= NULL
)
1365 expansion_notify (symtab
);
1370 /* Psymtab version of has_symbols. See its definition in
1371 the definition of quick_symbol_functions in symfile.h. */
1374 psymbol_functions::has_symbols (struct objfile
*objfile
)
1376 return objfile
->partial_symtabs
->psymtabs
!= NULL
;
1379 /* Helper function for psym_find_compunit_symtab_by_address that fills
1380 in m_psymbol_map for a given range of psymbols. */
1383 psymbol_functions::fill_psymbol_map
1384 (struct objfile
*objfile
,
1385 struct partial_symtab
*psymtab
,
1386 std::set
<CORE_ADDR
> *seen_addrs
,
1387 const std::vector
<partial_symbol
*> &symbols
)
1389 for (partial_symbol
*psym
: symbols
)
1391 if (psym
->aclass
== LOC_STATIC
)
1393 CORE_ADDR addr
= psym
->address (objfile
);
1394 if (seen_addrs
->find (addr
) == seen_addrs
->end ())
1396 seen_addrs
->insert (addr
);
1397 m_psymbol_map
.emplace_back (addr
, psymtab
);
1403 /* See find_compunit_symtab_by_address in quick_symbol_functions, in
1407 psymbol_functions::find_compunit_symtab_by_address (struct objfile
*objfile
,
1410 if (m_psymbol_map
.empty ())
1412 std::set
<CORE_ADDR
> seen_addrs
;
1414 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
1416 fill_psymbol_map (objfile
, pst
,
1418 pst
->global_psymbols
);
1419 fill_psymbol_map (objfile
, pst
,
1421 pst
->static_psymbols
);
1424 m_psymbol_map
.shrink_to_fit ();
1426 std::sort (m_psymbol_map
.begin (), m_psymbol_map
.end (),
1427 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1428 const std::pair
<CORE_ADDR
, partial_symtab
*> &b
)
1430 return a
.first
< b
.first
;
1434 auto iter
= std::lower_bound
1435 (m_psymbol_map
.begin (), m_psymbol_map
.end (), address
,
1436 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1442 if (iter
== m_psymbol_map
.end () || iter
->first
!= address
)
1445 return psymtab_to_symtab (objfile
, iter
->second
);
1448 quick_symbol_functions_up
1449 make_psymbol_functions ()
1451 return quick_symbol_functions_up (new psymbol_functions
);
1456 /* Partially fill a partial symtab. It will be completely filled at
1457 the end of the symbol list. */
1459 partial_symtab::partial_symtab (const char *filename
,
1460 struct objfile
*objfile
,
1462 : partial_symtab (filename
, objfile
)
1464 set_text_low (textlow
);
1465 set_text_high (raw_text_low ()); /* default */
1468 /* Perform "finishing up" operations of a partial symtab. */
1471 partial_symtab::end ()
1473 global_psymbols
.shrink_to_fit ();
1474 static_psymbols
.shrink_to_fit ();
1476 /* Sort the global list; don't sort the static list. */
1477 std::sort (global_psymbols
.begin (),
1478 global_psymbols
.end (),
1479 [] (partial_symbol
*s1
, partial_symbol
*s2
)
1481 return strcmp_iw_ordered (s1
->ginfo
.search_name (),
1482 s2
->ginfo
.search_name ()) < 0;
1486 /* See psymtab.h. */
1489 psymbol_bcache::hash (const void *addr
, int length
)
1491 unsigned long h
= 0;
1492 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1493 unsigned int lang
= psymbol
->ginfo
.language ();
1494 unsigned int domain
= psymbol
->domain
;
1495 unsigned int theclass
= psymbol
->aclass
;
1497 h
= fast_hash (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1498 h
= fast_hash (&lang
, sizeof (unsigned int), h
);
1499 h
= fast_hash (&domain
, sizeof (unsigned int), h
);
1500 h
= fast_hash (&theclass
, sizeof (unsigned int), h
);
1501 /* Note that psymbol names are interned via compute_and_set_names, so
1502 there's no need to hash the contents of the name here. */
1503 h
= fast_hash (&psymbol
->ginfo
.m_name
, sizeof (psymbol
->ginfo
.m_name
), h
);
1508 /* See psymtab.h. */
1511 psymbol_bcache::compare (const void *addr1
, const void *addr2
, int length
)
1513 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1514 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1516 return (memcmp (&sym1
->ginfo
.value
, &sym2
->ginfo
.value
,
1517 sizeof (sym1
->ginfo
.value
)) == 0
1518 && sym1
->ginfo
.language () == sym2
->ginfo
.language ()
1519 && sym1
->domain
== sym2
->domain
1520 && sym1
->aclass
== sym2
->aclass
1521 /* Note that psymbol names are interned via
1522 compute_and_set_names, so there's no need to compare the
1523 contents of the name here. */
1524 && sym1
->ginfo
.linkage_name () == sym2
->ginfo
.linkage_name ());
1527 /* Helper function, initialises partial symbol structure and stashes
1528 it into objfile's bcache. Note that our caching mechanism will
1529 use all fields of struct partial_symbol to determine hash value of the
1530 structure. In other words, having two symbols with the same name but
1531 different domain (or address) is possible and correct. */
1533 static struct partial_symbol
*
1534 add_psymbol_to_bcache (const partial_symbol
&psymbol
, struct objfile
*objfile
,
1537 /* Stash the partial symbol away in the cache. */
1538 return ((struct partial_symbol
*)
1539 objfile
->partial_symtabs
->psymbol_cache
.insert
1540 (&psymbol
, sizeof (struct partial_symbol
), added
));
1543 /* See psympriv.h. */
1546 partial_symtab::add_psymbol (const partial_symbol
&psymbol
,
1547 psymbol_placement where
,
1548 struct objfile
*objfile
)
1552 /* Stash the partial symbol away in the cache. */
1553 partial_symbol
*psym
= add_psymbol_to_bcache (psymbol
, objfile
, &added
);
1555 /* Do not duplicate global partial symbols. */
1556 if (where
== psymbol_placement::GLOBAL
&& !added
)
1559 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1560 std::vector
<partial_symbol
*> &list
1561 = (where
== psymbol_placement::STATIC
1564 list
.push_back (psym
);
1567 /* See psympriv.h. */
1570 partial_symtab::add_psymbol (gdb::string_view name
, bool copy_name
,
1572 enum address_class theclass
,
1574 psymbol_placement where
,
1576 enum language language
, struct objfile
*objfile
)
1578 struct partial_symbol psymbol
;
1579 memset (&psymbol
, 0, sizeof (psymbol
));
1581 psymbol
.set_unrelocated_address (coreaddr
);
1582 psymbol
.ginfo
.set_section_index (section
);
1583 psymbol
.domain
= domain
;
1584 psymbol
.aclass
= theclass
;
1585 psymbol
.ginfo
.set_language (language
, objfile
->partial_symtabs
->obstack ());
1586 psymbol
.ginfo
.compute_and_set_names (name
, copy_name
, objfile
->per_bfd
);
1588 add_psymbol (psymbol
, where
, objfile
);
1591 /* See psympriv.h. */
1593 partial_symtab::partial_symtab (const char *filename_
, struct objfile
*objfile
)
1594 : searched_flag (PST_NOT_SEARCHED
),
1598 objfile
->partial_symtabs
->install_psymtab (this);
1600 filename
= objfile
->intern (filename_
);
1602 if (symtab_create_debug
)
1604 /* Be a bit clever with debugging messages, and don't print objfile
1605 every time, only when it changes. */
1606 static char *last_objfile_name
= NULL
;
1608 if (last_objfile_name
== NULL
1609 || strcmp (last_objfile_name
, objfile_name (objfile
)) != 0)
1611 xfree (last_objfile_name
);
1612 last_objfile_name
= xstrdup (objfile_name (objfile
));
1613 fprintf_filtered (gdb_stdlog
,
1614 "Creating one or more psymtabs for objfile %s ...\n",
1617 fprintf_filtered (gdb_stdlog
,
1618 "Created psymtab %s for module %s.\n",
1619 host_address_to_string (this), filename
);
1623 /* See psympriv.h. */
1626 partial_symtab::expand_dependencies (struct objfile
*objfile
)
1628 for (int i
= 0; i
< number_of_dependencies
; ++i
)
1630 if (!dependencies
[i
]->readin_p (objfile
)
1631 && dependencies
[i
]->user
== NULL
)
1633 /* Inform about additional files to be read in. */
1636 fputs_filtered (" ", gdb_stdout
);
1638 fputs_filtered ("and ", gdb_stdout
);
1640 printf_filtered ("%s...", dependencies
[i
]->filename
);
1641 wrap_here (""); /* Flush output */
1642 gdb_flush (gdb_stdout
);
1644 dependencies
[i
]->expand_psymtab (objfile
);
1651 psymtab_storage::discard_psymtab (struct partial_symtab
*pst
)
1653 struct partial_symtab
**prev_pst
;
1656 Empty psymtabs happen as a result of header files which don't
1657 have any symbols in them. There can be a lot of them. But this
1658 check is wrong, in that a psymtab with N_SLINE entries but
1659 nothing else is not empty, but we don't realize that. Fixing
1660 that without slowing things down might be tricky. */
1662 /* First, snip it out of the psymtab chain. */
1664 prev_pst
= &psymtabs
;
1665 while ((*prev_pst
) != pst
)
1666 prev_pst
= &((*prev_pst
)->next
);
1667 (*prev_pst
) = pst
->next
;
1673 /* We need to pass a couple of items to the addrmap_foreach function,
1676 struct dump_psymtab_addrmap_data
1678 struct objfile
*objfile
;
1679 struct partial_symtab
*psymtab
;
1680 struct ui_file
*outfile
;
1682 /* Non-zero if the previously printed addrmap entry was for PSYMTAB.
1683 If so, we want to print the next one as well (since the next addrmap
1684 entry defines the end of the range). */
1685 int previous_matched
;
1688 /* Helper function for dump_psymtab_addrmap to print an addrmap entry. */
1691 dump_psymtab_addrmap_1 (void *datap
, CORE_ADDR start_addr
, void *obj
)
1693 struct dump_psymtab_addrmap_data
*data
1694 = (struct dump_psymtab_addrmap_data
*) datap
;
1695 struct gdbarch
*gdbarch
= data
->objfile
->arch ();
1696 struct partial_symtab
*addrmap_psymtab
= (struct partial_symtab
*) obj
;
1697 const char *psymtab_address_or_end
= NULL
;
1701 if (data
->psymtab
== NULL
1702 || data
->psymtab
== addrmap_psymtab
)
1703 psymtab_address_or_end
= host_address_to_string (addrmap_psymtab
);
1704 else if (data
->previous_matched
)
1705 psymtab_address_or_end
= "<ends here>";
1707 if (data
->psymtab
== NULL
1708 || data
->psymtab
== addrmap_psymtab
1709 || data
->previous_matched
)
1711 fprintf_filtered (data
->outfile
, " %s%s %s\n",
1712 data
->psymtab
!= NULL
? " " : "",
1713 paddress (gdbarch
, start_addr
),
1714 psymtab_address_or_end
);
1717 data
->previous_matched
= (data
->psymtab
== NULL
1718 || data
->psymtab
== addrmap_psymtab
);
1723 /* Helper function for maintenance_print_psymbols to print the addrmap
1724 of PSYMTAB. If PSYMTAB is NULL print the entire addrmap. */
1727 dump_psymtab_addrmap (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
1728 struct ui_file
*outfile
)
1730 struct dump_psymtab_addrmap_data addrmap_dump_data
;
1732 if ((psymtab
== NULL
1733 || psymtab
->psymtabs_addrmap_supported
)
1734 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
1736 addrmap_dump_data
.objfile
= objfile
;
1737 addrmap_dump_data
.psymtab
= psymtab
;
1738 addrmap_dump_data
.outfile
= outfile
;
1739 addrmap_dump_data
.previous_matched
= 0;
1740 fprintf_filtered (outfile
, "%sddress map:\n",
1741 psymtab
== NULL
? "Entire a" : " A");
1742 addrmap_foreach (objfile
->partial_symtabs
->psymtabs_addrmap
,
1743 dump_psymtab_addrmap_1
, &addrmap_dump_data
);
1748 maintenance_print_psymbols (const char *args
, int from_tty
)
1750 struct ui_file
*outfile
= gdb_stdout
;
1751 char *address_arg
= NULL
, *source_arg
= NULL
, *objfile_arg
= NULL
;
1752 int i
, outfile_idx
, found
;
1754 struct obj_section
*section
= NULL
;
1758 gdb_argv
argv (args
);
1760 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
1762 if (strcmp (argv
[i
], "-pc") == 0)
1764 if (argv
[i
+ 1] == NULL
)
1765 error (_("Missing pc value"));
1766 address_arg
= argv
[++i
];
1768 else if (strcmp (argv
[i
], "-source") == 0)
1770 if (argv
[i
+ 1] == NULL
)
1771 error (_("Missing source file"));
1772 source_arg
= argv
[++i
];
1774 else if (strcmp (argv
[i
], "-objfile") == 0)
1776 if (argv
[i
+ 1] == NULL
)
1777 error (_("Missing objfile name"));
1778 objfile_arg
= argv
[++i
];
1780 else if (strcmp (argv
[i
], "--") == 0)
1782 /* End of options. */
1786 else if (argv
[i
][0] == '-')
1788 /* Future proofing: Don't allow OUTFILE to begin with "-". */
1789 error (_("Unknown option: %s"), argv
[i
]);
1796 if (address_arg
!= NULL
&& source_arg
!= NULL
)
1797 error (_("Must specify at most one of -pc and -source"));
1799 stdio_file arg_outfile
;
1801 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
1803 if (argv
[outfile_idx
+ 1] != NULL
)
1804 error (_("Junk at end of command"));
1805 gdb::unique_xmalloc_ptr
<char> outfile_name
1806 (tilde_expand (argv
[outfile_idx
]));
1807 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
1808 perror_with_name (outfile_name
.get ());
1809 outfile
= &arg_outfile
;
1812 if (address_arg
!= NULL
)
1814 pc
= parse_and_eval_address (address_arg
);
1815 /* If we fail to find a section, that's ok, try the lookup anyway. */
1816 section
= find_pc_section (pc
);
1820 for (objfile
*objfile
: current_program_space
->objfiles ())
1822 int printed_objfile_header
= 0;
1823 int print_for_objfile
= 1;
1826 if (objfile_arg
!= NULL
)
1828 = compare_filenames_for_search (objfile_name (objfile
),
1830 if (!print_for_objfile
)
1833 if (address_arg
!= NULL
)
1835 struct bound_minimal_symbol msymbol
= { NULL
, NULL
};
1837 /* We don't assume each pc has a unique objfile (this is for
1839 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
,
1843 if (!printed_objfile_header
)
1845 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1846 objfile_name (objfile
));
1847 printed_objfile_header
= 1;
1849 dump_psymtab (objfile
, ps
, outfile
);
1850 dump_psymtab_addrmap (objfile
, ps
, outfile
);
1856 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1858 int print_for_source
= 0;
1861 if (source_arg
!= NULL
)
1864 = compare_filenames_for_search (ps
->filename
, source_arg
);
1867 if (source_arg
== NULL
1868 || print_for_source
)
1870 if (!printed_objfile_header
)
1872 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1873 objfile_name (objfile
));
1874 printed_objfile_header
= 1;
1876 dump_psymtab (objfile
, ps
, outfile
);
1877 dump_psymtab_addrmap (objfile
, ps
, outfile
);
1882 /* If we're printing all the objfile's symbols dump the full addrmap. */
1884 if (address_arg
== NULL
1885 && source_arg
== NULL
1886 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
1888 outfile
->puts ("\n");
1889 dump_psymtab_addrmap (objfile
, NULL
, outfile
);
1895 if (address_arg
!= NULL
)
1896 error (_("No partial symtab for address: %s"), address_arg
);
1897 if (source_arg
!= NULL
)
1898 error (_("No partial symtab for source file: %s"), source_arg
);
1902 /* List all the partial symbol tables whose names match REGEXP (optional). */
1905 maintenance_info_psymtabs (const char *regexp
, int from_tty
)
1910 for (struct program_space
*pspace
: program_spaces
)
1911 for (objfile
*objfile
: pspace
->objfiles ())
1913 struct gdbarch
*gdbarch
= objfile
->arch ();
1915 /* We don't want to print anything for this objfile until we
1916 actually find a symtab whose name matches. */
1917 int printed_objfile_start
= 0;
1919 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
, true))
1924 || re_exec (psymtab
->filename
))
1926 if (! printed_objfile_start
)
1928 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
1930 printf_filtered ("((struct objfile *) %s)\n",
1931 host_address_to_string (objfile
));
1932 printed_objfile_start
= 1;
1935 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1937 printf_filtered ("((struct partial_symtab *) %s)\n",
1938 host_address_to_string (psymtab
));
1940 printf_filtered (" readin %s\n",
1941 psymtab
->readin_p (objfile
) ? "yes" : "no");
1942 printf_filtered (" fullname %s\n",
1944 ? psymtab
->fullname
: "(null)");
1945 printf_filtered (" text addresses ");
1946 fputs_filtered (paddress (gdbarch
,
1947 psymtab
->text_low (objfile
)),
1949 printf_filtered (" -- ");
1950 fputs_filtered (paddress (gdbarch
,
1951 psymtab
->text_high (objfile
)),
1953 printf_filtered ("\n");
1954 printf_filtered (" psymtabs_addrmap_supported %s\n",
1955 (psymtab
->psymtabs_addrmap_supported
1957 printf_filtered (" globals ");
1958 if (!psymtab
->global_psymbols
.empty ())
1960 ("(* (struct partial_symbol **) %s @ %d)\n",
1961 host_address_to_string (psymtab
->global_psymbols
.data ()),
1962 (int) psymtab
->global_psymbols
.size ());
1964 printf_filtered ("(none)\n");
1965 printf_filtered (" statics ");
1966 if (!psymtab
->static_psymbols
.empty ())
1968 ("(* (struct partial_symbol **) %s @ %d)\n",
1969 host_address_to_string (psymtab
->static_psymbols
.data ()),
1970 (int) psymtab
->static_psymbols
.size ());
1972 printf_filtered ("(none)\n");
1974 printf_filtered (" user %s "
1975 "((struct partial_symtab *) %s)\n",
1976 psymtab
->user
->filename
,
1977 host_address_to_string (psymtab
->user
));
1978 printf_filtered (" dependencies ");
1979 if (psymtab
->number_of_dependencies
)
1983 printf_filtered ("{\n");
1984 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1986 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
1988 /* Note the string concatenation there --- no
1990 printf_filtered (" psymtab %s "
1991 "((struct partial_symtab *) %s)\n",
1993 host_address_to_string (dep
));
1995 printf_filtered (" }\n");
1998 printf_filtered ("(none)\n");
1999 printf_filtered (" }\n");
2003 if (printed_objfile_start
)
2004 printf_filtered ("}\n");
2008 /* Check consistency of currently expanded psymtabs vs symtabs. */
2011 maintenance_check_psymtabs (const char *ignore
, int from_tty
)
2014 struct compunit_symtab
*cust
= NULL
;
2015 const struct blockvector
*bv
;
2016 const struct block
*b
;
2018 for (objfile
*objfile
: current_program_space
->objfiles ())
2019 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
2021 struct gdbarch
*gdbarch
= objfile
->arch ();
2023 /* We don't call psymtab_to_symtab here because that may cause symtab
2024 expansion. When debugging a problem it helps if checkers leave
2025 things unchanged. */
2026 cust
= ps
->get_compunit_symtab (objfile
);
2028 /* First do some checks that don't require the associated symtab. */
2029 if (ps
->text_high (objfile
) < ps
->text_low (objfile
))
2031 printf_filtered ("Psymtab ");
2032 puts_filtered (ps
->filename
);
2033 printf_filtered (" covers bad range ");
2034 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
2036 printf_filtered (" - ");
2037 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
2039 printf_filtered ("\n");
2043 /* Now do checks requiring the associated symtab. */
2046 bv
= COMPUNIT_BLOCKVECTOR (cust
);
2047 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
2048 for (partial_symbol
*psym
: ps
->static_psymbols
)
2050 /* Skip symbols for inlined functions without address. These may
2051 or may not have a match in the full symtab. */
2052 if (psym
->aclass
== LOC_BLOCK
2053 && psym
->ginfo
.value
.address
== 0)
2056 sym
= block_lookup_symbol (b
, psym
->ginfo
.search_name (),
2057 symbol_name_match_type::SEARCH_NAME
,
2061 printf_filtered ("Static symbol `");
2062 puts_filtered (psym
->ginfo
.linkage_name ());
2063 printf_filtered ("' only found in ");
2064 puts_filtered (ps
->filename
);
2065 printf_filtered (" psymtab\n");
2068 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2069 for (partial_symbol
*psym
: ps
->global_psymbols
)
2071 sym
= block_lookup_symbol (b
, psym
->ginfo
.search_name (),
2072 symbol_name_match_type::SEARCH_NAME
,
2076 printf_filtered ("Global symbol `");
2077 puts_filtered (psym
->ginfo
.linkage_name ());
2078 printf_filtered ("' only found in ");
2079 puts_filtered (ps
->filename
);
2080 printf_filtered (" psymtab\n");
2083 if (ps
->raw_text_high () != 0
2084 && (ps
->text_low (objfile
) < BLOCK_START (b
)
2085 || ps
->text_high (objfile
) > BLOCK_END (b
)))
2087 printf_filtered ("Psymtab ");
2088 puts_filtered (ps
->filename
);
2089 printf_filtered (" covers ");
2090 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
2092 printf_filtered (" - ");
2093 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
2095 printf_filtered (" but symtab covers only ");
2096 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
2097 printf_filtered (" - ");
2098 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
2099 printf_filtered ("\n");
2104 void _initialize_psymtab ();
2106 _initialize_psymtab ()
2108 add_cmd ("psymbols", class_maintenance
, maintenance_print_psymbols
, _("\
2109 Print dump of current partial symbol definitions.\n\
2110 Usage: mt print psymbols [-objfile OBJFILE] [-pc ADDRESS] [--] [OUTFILE]\n\
2111 mt print psymbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
2112 Entries in the partial symbol table are dumped to file OUTFILE,\n\
2113 or the terminal if OUTFILE is unspecified.\n\
2114 If ADDRESS is provided, dump only the file for that address.\n\
2115 If SOURCE is provided, dump only that file's symbols.\n\
2116 If OBJFILE is provided, dump only that file's minimal symbols."),
2117 &maintenanceprintlist
);
2119 add_cmd ("psymtabs", class_maintenance
, maintenance_info_psymtabs
, _("\
2120 List the partial symbol tables for all object files.\n\
2121 This does not include information about individual partial symbols,\n\
2122 just the symbol table structures themselves."),
2123 &maintenanceinfolist
);
2125 add_cmd ("check-psymtabs", class_maintenance
, maintenance_check_psymtabs
,
2127 Check consistency of currently expanded psymtabs versus symtabs."),