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 if (verbose
&& !objfile_has_symbols (objfile
))
95 printf_filtered (_("(No debugging symbols found in %s)\n"),
96 objfile_name (objfile
));
100 return objfile
->psymtabs ();
103 /* Helper function for psym_map_symtabs_matching_filename that
104 expands the symtabs and calls the iterator. */
107 partial_map_expand_apply (struct objfile
*objfile
,
109 const char *real_path
,
110 struct partial_symtab
*pst
,
111 gdb::function_view
<bool (symtab
*)> callback
)
113 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
115 /* Shared psymtabs should never be seen here. Instead they should
116 be handled properly by the caller. */
117 gdb_assert (pst
->user
== NULL
);
119 /* Don't visit already-expanded psymtabs. */
120 if (pst
->readin_p (objfile
))
123 /* This may expand more than one symtab, and we want to iterate over
125 psymtab_to_symtab (objfile
, pst
);
127 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
128 last_made
, callback
);
131 /* Psymtab version of map_symtabs_matching_filename. See its definition in
132 the definition of quick_symbol_functions in symfile.h. */
135 psym_map_symtabs_matching_filename
136 (struct objfile
*objfile
,
138 const char *real_path
,
139 gdb::function_view
<bool (symtab
*)> callback
)
141 const char *name_basename
= lbasename (name
);
143 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
145 /* Anonymous psymtabs don't have a file name. */
149 if (compare_filenames_for_search (pst
->filename
, name
))
154 if (partial_map_expand_apply (objfile
, name
, real_path
,
160 /* Before we invoke realpath, which can get expensive when many
161 files are involved, do a quick comparison of the basenames. */
162 if (! basenames_may_differ
163 && FILENAME_CMP (name_basename
, lbasename (pst
->filename
)) != 0)
166 if (compare_filenames_for_search (psymtab_to_fullname (pst
), name
))
168 if (partial_map_expand_apply (objfile
, name
, real_path
,
174 /* If the user gave us an absolute path, try to find the file in
175 this symtab and use its absolute path. */
176 if (real_path
!= NULL
)
178 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
179 gdb_assert (IS_ABSOLUTE_PATH (name
));
180 if (filename_cmp (psymtab_to_fullname (pst
), real_path
) == 0)
182 if (partial_map_expand_apply (objfile
, name
, real_path
,
193 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
194 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
196 static struct partial_symtab
*
197 find_pc_sect_psymtab_closer (struct objfile
*objfile
,
198 CORE_ADDR pc
, struct obj_section
*section
,
199 struct partial_symtab
*pst
,
200 struct bound_minimal_symbol msymbol
)
202 struct partial_symtab
*tpst
;
203 struct partial_symtab
*best_pst
= pst
;
204 CORE_ADDR best_addr
= pst
->text_low (objfile
);
206 gdb_assert (!pst
->psymtabs_addrmap_supported
);
208 /* An objfile that has its functions reordered might have
209 many partial symbol tables containing the PC, but
210 we want the partial symbol table that contains the
211 function containing the PC. */
212 if (!(objfile
->flags
& OBJF_REORDERED
)
213 && section
== NULL
) /* Can't validate section this way. */
216 if (msymbol
.minsym
== NULL
)
219 /* The code range of partial symtabs sometimes overlap, so, in
220 the loop below, we need to check all partial symtabs and
221 find the one that fits better for the given PC address. We
222 select the partial symtab that contains a symbol whose
223 address is closest to the PC address. By closest we mean
224 that find_pc_sect_symbol returns the symbol with address
225 that is closest and still less than the given PC. */
226 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
228 if (pc
>= tpst
->text_low (objfile
) && pc
< tpst
->text_high (objfile
))
230 struct partial_symbol
*p
;
233 /* NOTE: This assumes that every psymbol has a
234 corresponding msymbol, which is not necessarily
235 true; the debug info might be much richer than the
236 object's symbol table. */
237 p
= find_pc_sect_psymbol (objfile
, tpst
, pc
, section
);
239 && (p
->address (objfile
) == BMSYMBOL_VALUE_ADDRESS (msymbol
)))
242 /* Also accept the textlow value of a psymtab as a
243 "symbol", to provide some support for partial
244 symbol tables with line information but no debug
245 symbols (e.g. those produced by an assembler). */
247 this_addr
= p
->address (objfile
);
249 this_addr
= tpst
->text_low (objfile
);
251 /* Check whether it is closer than our current
252 BEST_ADDR. Since this symbol address is
253 necessarily lower or equal to PC, the symbol closer
254 to PC is the symbol which address is the highest.
255 This way we return the psymtab which contains such
256 best match symbol. This can help in cases where the
257 symbol information/debuginfo is not complete, like
258 for instance on IRIX6 with gcc, where no debug info
259 is emitted for statics. (See also the nodebug.exp
261 if (this_addr
> best_addr
)
263 best_addr
= this_addr
;
271 /* Find which partial symtab contains PC and SECTION. Return NULL if
272 none. We return the psymtab that contains a symbol whose address
273 exactly matches PC, or, if we cannot find an exact match, the
274 psymtab that contains a symbol whose address is closest to PC. */
276 static struct partial_symtab
*
277 find_pc_sect_psymtab (struct objfile
*objfile
, CORE_ADDR pc
,
278 struct obj_section
*section
,
279 struct bound_minimal_symbol msymbol
)
281 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better
282 granularity than the later used TEXTLOW/TEXTHIGH one. However, we need
283 to take care as the PSYMTABS_ADDRMAP can hold things other than partial
284 symtabs in some cases.
286 This function should only be called for objfiles that are using partial
287 symtabs, not for objfiles that are using indexes (.gdb_index or
288 .debug_names), however 'maintenance print psymbols' calls this function
289 directly for all objfiles. If we assume that PSYMTABS_ADDRMAP contains
290 partial symtabs then we will end up returning a pointer to an object
291 that is not a partial_symtab, which doesn't end well. */
293 if (objfile
->partial_symtabs
->psymtabs
!= NULL
294 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
296 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
298 struct partial_symtab
*pst
299 = ((struct partial_symtab
*)
300 addrmap_find (objfile
->partial_symtabs
->psymtabs_addrmap
,
304 /* FIXME: addrmaps currently do not handle overlayed sections,
305 so fall back to the non-addrmap case if we're debugging
306 overlays and the addrmap returned the wrong section. */
307 if (overlay_debugging
&& msymbol
.minsym
!= NULL
&& section
!= NULL
)
309 struct partial_symbol
*p
;
311 /* NOTE: This assumes that every psymbol has a
312 corresponding msymbol, which is not necessarily
313 true; the debug info might be much richer than the
314 object's symbol table. */
315 p
= find_pc_sect_psymbol (objfile
, pst
, pc
, section
);
317 || (p
->address (objfile
)
318 != BMSYMBOL_VALUE_ADDRESS (msymbol
)))
322 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
323 PSYMTABS_ADDRMAP we used has already the best 1-byte
324 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
325 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
334 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
335 which still have no corresponding full SYMTABs read. But it is not
336 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
339 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
340 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
341 debug info type in single OBJFILE. */
343 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
344 if (!pst
->psymtabs_addrmap_supported
345 && pc
>= pst
->text_low (objfile
) && pc
< pst
->text_high (objfile
))
347 struct partial_symtab
*best_pst
;
349 best_pst
= find_pc_sect_psymtab_closer (objfile
, pc
, section
, pst
,
351 if (best_pst
!= NULL
)
358 /* Psymtab version of find_pc_sect_compunit_symtab. See its definition in
359 the definition of quick_symbol_functions in symfile.h. */
361 static struct compunit_symtab
*
362 psym_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
363 struct bound_minimal_symbol msymbol
,
365 struct obj_section
*section
,
368 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
, section
,
372 if (warn_if_readin
&& ps
->readin_p (objfile
))
373 /* Might want to error() here (in case symtab is corrupt and
374 will cause a core dump), but maybe we can successfully
375 continue, so let's not. */
377 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
378 paddress (objfile
->arch (), pc
));
379 psymtab_to_symtab (objfile
, ps
);
380 return ps
->get_compunit_symtab (objfile
);
385 /* Find which partial symbol within a psymtab matches PC and SECTION.
386 Return NULL if none. */
388 static struct partial_symbol
*
389 find_pc_sect_psymbol (struct objfile
*objfile
,
390 struct partial_symtab
*psymtab
, CORE_ADDR pc
,
391 struct obj_section
*section
)
393 struct partial_symbol
*best
= NULL
;
395 const CORE_ADDR textlow
= psymtab
->text_low (objfile
);
397 gdb_assert (psymtab
!= NULL
);
399 /* Cope with programs that start at address 0. */
400 best_pc
= (textlow
!= 0) ? textlow
- 1 : 0;
402 /* Search the global symbols as well as the static symbols, so that
403 find_pc_partial_function doesn't use a minimal symbol and thus
404 cache a bad endaddr. */
405 for (partial_symbol
*p
: psymtab
->global_psymbols
)
407 if (p
->domain
== VAR_DOMAIN
408 && p
->aclass
== LOC_BLOCK
409 && pc
>= p
->address (objfile
)
410 && (p
->address (objfile
) > best_pc
411 || (psymtab
->text_low (objfile
) == 0
412 && best_pc
== 0 && p
->address (objfile
) == 0)))
414 if (section
!= NULL
) /* Match on a specific section. */
416 if (!matching_obj_sections (p
->obj_section (objfile
),
420 best_pc
= p
->address (objfile
);
425 for (partial_symbol
*p
: psymtab
->static_psymbols
)
427 if (p
->domain
== VAR_DOMAIN
428 && p
->aclass
== LOC_BLOCK
429 && pc
>= p
->address (objfile
)
430 && (p
->address (objfile
) > best_pc
431 || (psymtab
->text_low (objfile
) == 0
432 && best_pc
== 0 && p
->address (objfile
) == 0)))
434 if (section
!= NULL
) /* Match on a specific section. */
436 if (!matching_obj_sections (p
->obj_section (objfile
),
440 best_pc
= p
->address (objfile
);
448 /* Psymtab version of lookup_symbol. See its definition in
449 the definition of quick_symbol_functions in symfile.h. */
451 static struct compunit_symtab
*
452 psym_lookup_symbol (struct objfile
*objfile
,
453 block_enum block_index
, const char *name
,
454 const domain_enum domain
)
456 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
457 struct compunit_symtab
*stab_best
= NULL
;
459 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
461 lookup_name_info psym_lookup_name
= lookup_name
.make_ignore_params ();
463 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
465 if (!ps
->readin_p (objfile
)
466 && lookup_partial_symbol (objfile
, ps
, psym_lookup_name
,
467 psymtab_index
, domain
))
469 struct symbol
*sym
, *with_opaque
= NULL
;
470 struct compunit_symtab
*stab
= psymtab_to_symtab (objfile
, ps
);
471 /* Note: While psymtab_to_symtab can return NULL if the
472 partial symtab is empty, we can assume it won't here
473 because lookup_partial_symbol succeeded. */
474 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
475 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
477 sym
= block_find_symbol (block
, name
, domain
,
478 block_find_non_opaque_type_preferred
,
481 /* Some caution must be observed with overloaded functions
482 and methods, since the index will not contain any overload
483 information (but NAME might contain it). */
486 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
488 if (with_opaque
!= NULL
489 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
492 /* Keep looking through other psymtabs. */
499 /* Psymtab version of lookup_global_symbol_language. See its definition in
500 the definition of quick_symbol_functions in symfile.h. */
503 psym_lookup_global_symbol_language (struct objfile
*objfile
, const char *name
,
504 domain_enum domain
, bool *symbol_found_p
)
506 *symbol_found_p
= false;
507 if (objfile
->sf
== NULL
)
508 return language_unknown
;
510 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
512 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
514 struct partial_symbol
*psym
;
515 if (ps
->readin_p (objfile
))
518 psym
= lookup_partial_symbol (objfile
, ps
, lookup_name
, 1, domain
);
521 *symbol_found_p
= true;
522 return psym
->ginfo
.language ();
526 return language_unknown
;
529 /* Returns true if PSYM matches LOOKUP_NAME. */
532 psymbol_name_matches (partial_symbol
*psym
,
533 const lookup_name_info
&lookup_name
)
535 const language_defn
*lang
= language_def (psym
->ginfo
.language ());
536 symbol_name_matcher_ftype
*name_match
537 = lang
->get_symbol_name_matcher (lookup_name
);
538 return name_match (psym
->ginfo
.search_name (), lookup_name
, NULL
);
541 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
542 the global block of PST if GLOBAL, and otherwise the static block.
543 MATCH is the comparison operation that returns true iff MATCH (s,
544 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
545 non-null, the symbols in the block are assumed to be ordered
546 according to it (allowing binary search). It must be compatible
547 with MATCH. Returns the symbol, if found, and otherwise NULL. */
549 static struct partial_symbol
*
550 match_partial_symbol (struct objfile
*objfile
,
551 struct partial_symtab
*pst
, int global
,
552 const lookup_name_info
&name
, domain_enum domain
,
553 symbol_compare_ftype
*ordered_compare
)
555 struct partial_symbol
**start
, **psym
;
556 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
558 ? pst
->global_psymbols
.size ()
559 : pst
->static_psymbols
.size ());
560 int do_linear_search
= 1;
566 &pst
->global_psymbols
[0] :
567 &pst
->static_psymbols
[0]);
569 if (global
&& ordered_compare
) /* Can use a binary search. */
571 do_linear_search
= 0;
573 /* Binary search. This search is guaranteed to end with center
574 pointing at the earliest partial symbol whose name might be
575 correct. At that point *all* partial symbols with an
576 appropriate name will be checked against the correct
580 top
= start
+ length
- 1;
584 center
= bottom
+ (top
- bottom
) / 2;
585 gdb_assert (center
< top
);
587 enum language lang
= (*center
)->ginfo
.language ();
588 const char *lang_ln
= name
.language_lookup_name (lang
);
590 if (ordered_compare ((*center
)->ginfo
.search_name (),
596 gdb_assert (top
== bottom
);
598 while (top
<= real_top
599 && psymbol_name_matches (*top
, name
))
601 if (symbol_matches_domain ((*top
)->ginfo
.language (),
602 (*top
)->domain
, domain
))
608 /* Can't use a binary search or else we found during the binary search that
609 we should also do a linear search. */
611 if (do_linear_search
)
613 for (psym
= start
; psym
< start
+ length
; psym
++)
615 if (symbol_matches_domain ((*psym
)->ginfo
.language (),
616 (*psym
)->domain
, domain
)
617 && psymbol_name_matches (*psym
, name
))
625 /* Look, in partial_symtab PST, for symbol whose natural name is
626 LOOKUP_NAME. Check the global symbols if GLOBAL, the static
629 static struct partial_symbol
*
630 lookup_partial_symbol (struct objfile
*objfile
,
631 struct partial_symtab
*pst
,
632 const lookup_name_info
&lookup_name
,
633 int global
, domain_enum domain
)
635 struct partial_symbol
**start
, **psym
;
636 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
638 ? pst
->global_psymbols
.size ()
639 : pst
->static_psymbols
.size ());
640 int do_linear_search
= 1;
646 &pst
->global_psymbols
[0] :
647 &pst
->static_psymbols
[0]);
649 if (global
) /* This means we can use a binary search. */
651 do_linear_search
= 0;
653 /* Binary search. This search is guaranteed to end with center
654 pointing at the earliest partial symbol whose name might be
655 correct. At that point *all* partial symbols with an
656 appropriate name will be checked against the correct
660 top
= start
+ length
- 1;
664 center
= bottom
+ (top
- bottom
) / 2;
666 gdb_assert (center
< top
);
668 if (strcmp_iw_ordered ((*center
)->ginfo
.search_name (),
669 lookup_name
.c_str ()) >= 0)
679 gdb_assert (top
== bottom
);
681 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
682 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
683 while (top
>= start
&& symbol_matches_search_name (&(*top
)->ginfo
,
687 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
690 while (top
<= real_top
&& symbol_matches_search_name (&(*top
)->ginfo
,
693 if (symbol_matches_domain ((*top
)->ginfo
.language (),
694 (*top
)->domain
, domain
))
700 /* Can't use a binary search or else we found during the binary search that
701 we should also do a linear search. */
703 if (do_linear_search
)
705 for (psym
= start
; psym
< start
+ length
; psym
++)
707 if (symbol_matches_domain ((*psym
)->ginfo
.language (),
708 (*psym
)->domain
, domain
)
709 && symbol_matches_search_name (&(*psym
)->ginfo
, lookup_name
))
717 /* Get the symbol table that corresponds to a partial_symtab.
718 This is fast after the first time you do it.
719 The result will be NULL if the primary symtab has no symbols,
720 which can happen. Otherwise the result is the primary symtab
721 that contains PST. */
723 static struct compunit_symtab
*
724 psymtab_to_symtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
726 /* If it is a shared psymtab, find an unshared psymtab that includes
727 it. Any such psymtab will do. */
728 while (pst
->user
!= NULL
)
731 /* If it's been looked up before, return it. */
732 if (pst
->get_compunit_symtab (objfile
))
733 return pst
->get_compunit_symtab (objfile
);
735 /* If it has not yet been read in, read it. */
736 if (!pst
->readin_p (objfile
))
738 scoped_restore decrementer
= increment_reading_symtab ();
742 printf_filtered (_("Reading in symbols for %s...\n"),
744 gdb_flush (gdb_stdout
);
747 pst
->read_symtab (objfile
);
750 return pst
->get_compunit_symtab (objfile
);
753 /* Psymtab version of find_last_source_symtab. See its definition in
754 the definition of quick_symbol_functions in symfile.h. */
756 static struct symtab
*
757 psym_find_last_source_symtab (struct objfile
*ofp
)
759 struct partial_symtab
*cs_pst
= NULL
;
761 for (partial_symtab
*ps
: require_partial_symbols (ofp
, true))
763 const char *name
= ps
->filename
;
764 int len
= strlen (name
);
766 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
767 || strcmp (name
, "<<C++-namespaces>>") == 0)))
773 if (cs_pst
->readin_p (ofp
))
775 internal_error (__FILE__
, __LINE__
,
776 _("select_source_symtab: "
777 "readin pst found and no symtabs."));
781 struct compunit_symtab
*cust
= psymtab_to_symtab (ofp
, cs_pst
);
785 return compunit_primary_filetab (cust
);
791 /* Psymtab version of forget_cached_source_info. See its definition in
792 the definition of quick_symbol_functions in symfile.h. */
795 psym_forget_cached_source_info (struct objfile
*objfile
)
797 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
799 if (pst
->fullname
!= NULL
)
801 xfree (pst
->fullname
);
802 pst
->fullname
= NULL
;
808 print_partial_symbols (struct gdbarch
*gdbarch
, struct objfile
*objfile
,
809 const std::vector
<partial_symbol
*> &symbols
,
810 const char *what
, struct ui_file
*outfile
)
812 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
813 for (partial_symbol
*p
: symbols
)
816 fprintf_filtered (outfile
, " `%s'", p
->ginfo
.linkage_name ());
817 if (p
->ginfo
.demangled_name () != NULL
)
819 fprintf_filtered (outfile
, " `%s'",
820 p
->ginfo
.demangled_name ());
822 fputs_filtered (", ", outfile
);
826 fputs_filtered ("undefined domain, ", outfile
);
829 /* This is the usual thing -- don't print it. */
832 fputs_filtered ("struct domain, ", outfile
);
835 fputs_filtered ("module domain, ", outfile
);
838 fputs_filtered ("label domain, ", outfile
);
840 case COMMON_BLOCK_DOMAIN
:
841 fputs_filtered ("common block domain, ", outfile
);
844 fputs_filtered ("<invalid domain>, ", outfile
);
850 fputs_filtered ("undefined", outfile
);
853 fputs_filtered ("constant int", outfile
);
856 fputs_filtered ("static", outfile
);
859 fputs_filtered ("register", outfile
);
862 fputs_filtered ("pass by value", outfile
);
865 fputs_filtered ("pass by reference", outfile
);
867 case LOC_REGPARM_ADDR
:
868 fputs_filtered ("register address parameter", outfile
);
871 fputs_filtered ("stack parameter", outfile
);
874 fputs_filtered ("type", outfile
);
877 fputs_filtered ("label", outfile
);
880 fputs_filtered ("function", outfile
);
882 case LOC_CONST_BYTES
:
883 fputs_filtered ("constant bytes", outfile
);
886 fputs_filtered ("unresolved", outfile
);
888 case LOC_OPTIMIZED_OUT
:
889 fputs_filtered ("optimized out", outfile
);
892 fputs_filtered ("computed at runtime", outfile
);
895 fputs_filtered ("<invalid location>", outfile
);
898 fputs_filtered (", ", outfile
);
899 fputs_filtered (paddress (gdbarch
, p
->unrelocated_address ()), outfile
);
900 fprintf_filtered (outfile
, "\n");
905 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
906 struct ui_file
*outfile
)
908 struct gdbarch
*gdbarch
= objfile
->arch ();
911 if (psymtab
->anonymous
)
913 fprintf_filtered (outfile
, "\nAnonymous partial symtab (%s) ",
918 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
921 fprintf_filtered (outfile
, "(object ");
922 gdb_print_host_address (psymtab
, outfile
);
923 fprintf_filtered (outfile
, ")\n\n");
924 fprintf_filtered (outfile
, " Read from object file %s (",
925 objfile_name (objfile
));
926 gdb_print_host_address (objfile
, outfile
);
927 fprintf_filtered (outfile
, ")\n");
929 if (psymtab
->readin_p (objfile
))
931 fprintf_filtered (outfile
,
932 " Full symtab was read (at ");
933 gdb_print_host_address (psymtab
->get_compunit_symtab (objfile
), outfile
);
934 fprintf_filtered (outfile
, ")\n");
937 fprintf_filtered (outfile
, " Symbols cover text addresses ");
938 fputs_filtered (paddress (gdbarch
, psymtab
->text_low (objfile
)), outfile
);
939 fprintf_filtered (outfile
, "-");
940 fputs_filtered (paddress (gdbarch
, psymtab
->text_high (objfile
)), outfile
);
941 fprintf_filtered (outfile
, "\n");
942 fprintf_filtered (outfile
, " Address map supported - %s.\n",
943 psymtab
->psymtabs_addrmap_supported
? "yes" : "no");
944 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
945 psymtab
->number_of_dependencies
);
946 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
948 fprintf_filtered (outfile
, " %d ", i
);
949 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
950 fprintf_filtered (outfile
, " %s\n",
951 psymtab
->dependencies
[i
]->filename
);
953 if (psymtab
->user
!= NULL
)
955 fprintf_filtered (outfile
, " Shared partial symtab with user ");
956 gdb_print_host_address (psymtab
->user
, outfile
);
957 fprintf_filtered (outfile
, "\n");
959 if (!psymtab
->global_psymbols
.empty ())
961 print_partial_symbols
962 (gdbarch
, objfile
, psymtab
->global_psymbols
,
965 if (!psymtab
->static_psymbols
.empty ())
967 print_partial_symbols
968 (gdbarch
, objfile
, psymtab
->static_psymbols
,
971 fprintf_filtered (outfile
, "\n");
974 /* Psymtab version of print_stats. See its definition in
975 the definition of quick_symbol_functions in symfile.h. */
978 psym_print_stats (struct objfile
*objfile
)
983 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
985 if (!ps
->readin_p (objfile
))
988 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i
);
991 /* Psymtab version of dump. See its definition in
992 the definition of quick_symbol_functions in symfile.h. */
995 psym_dump (struct objfile
*objfile
)
997 struct partial_symtab
*psymtab
;
999 if (objfile
->partial_symtabs
->psymtabs
)
1001 printf_filtered ("Psymtabs:\n");
1002 for (psymtab
= objfile
->partial_symtabs
->psymtabs
;
1004 psymtab
= psymtab
->next
)
1006 printf_filtered ("%s at ",
1008 gdb_print_host_address (psymtab
, gdb_stdout
);
1009 printf_filtered (", ");
1012 printf_filtered ("\n\n");
1016 /* Psymtab version of expand_symtabs_for_function. See its definition in
1017 the definition of quick_symbol_functions in symfile.h. */
1020 psym_expand_symtabs_for_function (struct objfile
*objfile
,
1021 const char *func_name
)
1023 lookup_name_info
base_lookup (func_name
, symbol_name_match_type::FULL
);
1024 lookup_name_info lookup_name
= base_lookup
.make_ignore_params ();
1026 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1028 if (ps
->readin_p (objfile
))
1031 if ((lookup_partial_symbol (objfile
, ps
, lookup_name
, 1, VAR_DOMAIN
)
1033 || (lookup_partial_symbol (objfile
, ps
, lookup_name
, 0, VAR_DOMAIN
)
1035 psymtab_to_symtab (objfile
, ps
);
1039 /* Psymtab version of expand_all_symtabs. See its definition in
1040 the definition of quick_symbol_functions in symfile.h. */
1043 psym_expand_all_symtabs (struct objfile
*objfile
)
1045 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
, true))
1046 psymtab_to_symtab (objfile
, psymtab
);
1049 /* Psymtab version of expand_symtabs_with_fullname. See its definition in
1050 the definition of quick_symbol_functions in symfile.h. */
1053 psym_expand_symtabs_with_fullname (struct objfile
*objfile
,
1054 const char *fullname
)
1056 for (partial_symtab
*p
: require_partial_symbols (objfile
, true))
1058 /* Anonymous psymtabs don't have a name of a source file. */
1062 /* psymtab_to_fullname tries to open the file which is slow.
1063 Don't call it if we know the basenames don't match. */
1064 if ((basenames_may_differ
1065 || filename_cmp (lbasename (fullname
), lbasename (p
->filename
)) == 0)
1066 && filename_cmp (fullname
, psymtab_to_fullname (p
)) == 0)
1067 psymtab_to_symtab (objfile
, p
);
1071 /* Psymtab version of map_symbol_filenames. See its definition in
1072 the definition of quick_symbol_functions in symfile.h. */
1075 psym_map_symbol_filenames (struct objfile
*objfile
,
1076 symbol_filename_ftype
*fun
, void *data
,
1079 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1081 const char *fullname
;
1083 if (ps
->readin_p (objfile
))
1086 /* We can skip shared psymtabs here, because any file name will be
1087 attached to the unshared psymtab. */
1088 if (ps
->user
!= NULL
)
1091 /* Anonymous psymtabs don't have a file name. */
1097 fullname
= psymtab_to_fullname (ps
);
1100 (*fun
) (ps
->filename
, fullname
, data
);
1104 /* Finds the fullname that a partial_symtab represents.
1106 If this functions finds the fullname, it will save it in ps->fullname
1107 and it will also return the value.
1109 If this function fails to find the file that this partial_symtab represents,
1110 NULL will be returned and ps->fullname will be set to NULL. */
1113 psymtab_to_fullname (struct partial_symtab
*ps
)
1115 gdb_assert (!ps
->anonymous
);
1117 /* Use cached copy if we have it.
1118 We rely on forget_cached_source_info being called appropriately
1119 to handle cases like the file being moved. */
1120 if (ps
->fullname
== NULL
)
1122 gdb::unique_xmalloc_ptr
<char> fullname
;
1123 scoped_fd fd
= find_and_open_source (ps
->filename
, ps
->dirname
,
1125 ps
->fullname
= fullname
.release ();
1129 /* rewrite_source_path would be applied by find_and_open_source, we
1130 should report the pathname where GDB tried to find the file. */
1132 if (ps
->dirname
== NULL
|| IS_ABSOLUTE_PATH (ps
->filename
))
1133 fullname
.reset (xstrdup (ps
->filename
));
1135 fullname
.reset (concat (ps
->dirname
, SLASH_STRING
,
1136 ps
->filename
, (char *) NULL
));
1138 ps
->fullname
= rewrite_source_path (fullname
.get ()).release ();
1139 if (ps
->fullname
== NULL
)
1140 ps
->fullname
= fullname
.release ();
1144 return ps
->fullname
;
1147 /* Psymtab version of map_matching_symbols. See its definition in
1148 the definition of quick_symbol_functions in symfile.h. */
1151 psym_map_matching_symbols
1152 (struct objfile
*objfile
,
1153 const lookup_name_info
&name
, domain_enum domain
,
1155 gdb::function_view
<symbol_found_callback_ftype
> callback
,
1156 symbol_compare_ftype
*ordered_compare
)
1158 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
1160 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1163 if (ps
->readin_p (objfile
)
1164 || match_partial_symbol (objfile
, ps
, global
, name
, domain
,
1167 struct compunit_symtab
*cust
= psymtab_to_symtab (objfile
, ps
);
1168 const struct block
*block
;
1172 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
1173 if (!iterate_over_symbols_terminated (block
, name
,
1180 /* A helper for psym_expand_symtabs_matching that handles searching
1181 included psymtabs. This returns true if a symbol is found, and
1182 false otherwise. It also updates the 'searched_flag' on the
1183 various psymtabs that it searches. */
1186 recursively_search_psymtabs
1187 (struct partial_symtab
*ps
,
1188 struct objfile
*objfile
,
1189 enum search_domain domain
,
1190 const lookup_name_info
&lookup_name
,
1191 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> sym_matcher
)
1194 enum psymtab_search_status result
= PST_SEARCHED_AND_NOT_FOUND
;
1197 if (ps
->searched_flag
!= PST_NOT_SEARCHED
)
1198 return ps
->searched_flag
== PST_SEARCHED_AND_FOUND
;
1200 /* Recurse into shared psymtabs first, because they may have already
1201 been searched, and this could save some time. */
1202 for (i
= 0; i
< ps
->number_of_dependencies
; ++i
)
1206 /* Skip non-shared dependencies, these are handled elsewhere. */
1207 if (ps
->dependencies
[i
]->user
== NULL
)
1210 r
= recursively_search_psymtabs (ps
->dependencies
[i
],
1211 objfile
, domain
, lookup_name
,
1215 ps
->searched_flag
= PST_SEARCHED_AND_FOUND
;
1220 partial_symbol
**gbound
= (ps
->global_psymbols
.data ()
1221 + ps
->global_psymbols
.size ());
1222 partial_symbol
**sbound
= (ps
->static_psymbols
.data ()
1223 + ps
->static_psymbols
.size ());
1224 partial_symbol
**bound
= gbound
;
1226 /* Go through all of the symbols stored in a partial
1227 symtab in one loop. */
1228 partial_symbol
**psym
= ps
->global_psymbols
.data ();
1233 if (bound
== gbound
&& !ps
->static_psymbols
.empty ())
1235 psym
= ps
->static_psymbols
.data ();
1246 if ((domain
== ALL_DOMAIN
1247 || (domain
== MODULES_DOMAIN
1248 && (*psym
)->domain
== MODULE_DOMAIN
)
1249 || (domain
== VARIABLES_DOMAIN
1250 && (*psym
)->aclass
!= LOC_TYPEDEF
1251 && (*psym
)->aclass
!= LOC_BLOCK
)
1252 || (domain
== FUNCTIONS_DOMAIN
1253 && (*psym
)->aclass
== LOC_BLOCK
)
1254 || (domain
== TYPES_DOMAIN
1255 && (*psym
)->aclass
== LOC_TYPEDEF
))
1256 && psymbol_name_matches (*psym
, lookup_name
)
1257 && (sym_matcher
== NULL
1258 || sym_matcher ((*psym
)->ginfo
.search_name ())))
1260 /* Found a match, so notify our caller. */
1261 result
= PST_SEARCHED_AND_FOUND
;
1268 ps
->searched_flag
= result
;
1269 return result
== PST_SEARCHED_AND_FOUND
;
1272 /* Psymtab version of expand_symtabs_matching. See its definition in
1273 the definition of quick_symbol_functions in symfile.h. */
1276 psym_expand_symtabs_matching
1277 (struct objfile
*objfile
,
1278 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
1279 const lookup_name_info
*lookup_name
,
1280 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
1281 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
1282 enum search_domain domain
)
1284 /* Clear the search flags. */
1285 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1286 ps
->searched_flag
= PST_NOT_SEARCHED
;
1288 for (partial_symtab
*ps
: objfile
->psymtabs ())
1292 if (ps
->readin_p (objfile
))
1295 /* We skip shared psymtabs because file-matching doesn't apply
1296 to them; but we search them later in the loop. */
1297 if (ps
->user
!= NULL
)
1307 match
= file_matcher (ps
->filename
, false);
1310 /* Before we invoke realpath, which can get expensive when many
1311 files are involved, do a quick comparison of the basenames. */
1312 if (basenames_may_differ
1313 || file_matcher (lbasename (ps
->filename
), true))
1314 match
= file_matcher (psymtab_to_fullname (ps
), false);
1320 if ((symbol_matcher
== NULL
&& lookup_name
== NULL
)
1321 || recursively_search_psymtabs (ps
, objfile
, domain
,
1322 lookup_name
->make_ignore_params (),
1325 struct compunit_symtab
*symtab
=
1326 psymtab_to_symtab (objfile
, ps
);
1328 if (expansion_notify
!= NULL
)
1329 expansion_notify (symtab
);
1334 /* Psymtab version of has_symbols. See its definition in
1335 the definition of quick_symbol_functions in symfile.h. */
1338 psym_has_symbols (struct objfile
*objfile
)
1340 return objfile
->partial_symtabs
->psymtabs
!= NULL
;
1343 /* Helper function for psym_find_compunit_symtab_by_address that fills
1344 in psymbol_map for a given range of psymbols. */
1347 psym_fill_psymbol_map (struct objfile
*objfile
,
1348 struct partial_symtab
*psymtab
,
1349 std::set
<CORE_ADDR
> *seen_addrs
,
1350 const std::vector
<partial_symbol
*> &symbols
)
1352 for (partial_symbol
*psym
: symbols
)
1354 if (psym
->aclass
== LOC_STATIC
)
1356 CORE_ADDR addr
= psym
->address (objfile
);
1357 if (seen_addrs
->find (addr
) == seen_addrs
->end ())
1359 seen_addrs
->insert (addr
);
1360 objfile
->psymbol_map
.emplace_back (addr
, psymtab
);
1366 /* See find_compunit_symtab_by_address in quick_symbol_functions, in
1369 static compunit_symtab
*
1370 psym_find_compunit_symtab_by_address (struct objfile
*objfile
,
1373 if (objfile
->psymbol_map
.empty ())
1375 std::set
<CORE_ADDR
> seen_addrs
;
1377 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
1379 psym_fill_psymbol_map (objfile
, pst
,
1381 pst
->global_psymbols
);
1382 psym_fill_psymbol_map (objfile
, pst
,
1384 pst
->static_psymbols
);
1387 objfile
->psymbol_map
.shrink_to_fit ();
1389 std::sort (objfile
->psymbol_map
.begin (), objfile
->psymbol_map
.end (),
1390 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1391 const std::pair
<CORE_ADDR
, partial_symtab
*> &b
)
1393 return a
.first
< b
.first
;
1397 auto iter
= std::lower_bound
1398 (objfile
->psymbol_map
.begin (), objfile
->psymbol_map
.end (), address
,
1399 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1405 if (iter
== objfile
->psymbol_map
.end () || iter
->first
!= address
)
1408 return psymtab_to_symtab (objfile
, iter
->second
);
1411 const struct quick_symbol_functions psym_functions
=
1414 psym_find_last_source_symtab
,
1415 psym_forget_cached_source_info
,
1416 psym_map_symtabs_matching_filename
,
1418 psym_lookup_global_symbol_language
,
1421 psym_expand_symtabs_for_function
,
1422 psym_expand_all_symtabs
,
1423 psym_expand_symtabs_with_fullname
,
1424 psym_map_matching_symbols
,
1425 psym_expand_symtabs_matching
,
1426 psym_find_pc_sect_compunit_symtab
,
1427 psym_find_compunit_symtab_by_address
,
1428 psym_map_symbol_filenames
1434 sort_pst_symbols (struct objfile
*objfile
, struct partial_symtab
*pst
)
1436 /* Sort the global list; don't sort the static list. */
1437 std::sort (pst
->global_psymbols
.begin (),
1438 pst
->global_psymbols
.end (),
1439 [] (partial_symbol
*s1
, partial_symbol
*s2
)
1441 return strcmp_iw_ordered (s1
->ginfo
.search_name (),
1442 s2
->ginfo
.search_name ()) < 0;
1446 /* Partially fill a partial symtab. It will be completely filled at
1447 the end of the symbol list. */
1449 partial_symtab::partial_symtab (const char *filename
,
1450 struct objfile
*objfile
,
1452 : partial_symtab (filename
, objfile
)
1454 set_text_low (textlow
);
1455 set_text_high (raw_text_low ()); /* default */
1458 /* Perform "finishing up" operations of a partial symtab. */
1461 end_psymtab_common (struct objfile
*objfile
, struct partial_symtab
*pst
)
1463 pst
->global_psymbols
.shrink_to_fit ();
1464 pst
->static_psymbols
.shrink_to_fit ();
1466 sort_pst_symbols (objfile
, pst
);
1469 /* See psymtab.h. */
1472 psymbol_bcache::hash (const void *addr
, int length
)
1474 unsigned long h
= 0;
1475 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1476 unsigned int lang
= psymbol
->ginfo
.language ();
1477 unsigned int domain
= psymbol
->domain
;
1478 unsigned int theclass
= psymbol
->aclass
;
1480 h
= fast_hash (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1481 h
= fast_hash (&lang
, sizeof (unsigned int), h
);
1482 h
= fast_hash (&domain
, sizeof (unsigned int), h
);
1483 h
= fast_hash (&theclass
, sizeof (unsigned int), h
);
1484 /* Note that psymbol names are interned via compute_and_set_names, so
1485 there's no need to hash the contents of the name here. */
1486 h
= fast_hash (&psymbol
->ginfo
.m_name
, sizeof (psymbol
->ginfo
.m_name
), h
);
1491 /* See psymtab.h. */
1494 psymbol_bcache::compare (const void *addr1
, const void *addr2
, int length
)
1496 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1497 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1499 return (memcmp (&sym1
->ginfo
.value
, &sym2
->ginfo
.value
,
1500 sizeof (sym1
->ginfo
.value
)) == 0
1501 && sym1
->ginfo
.language () == sym2
->ginfo
.language ()
1502 && sym1
->domain
== sym2
->domain
1503 && sym1
->aclass
== sym2
->aclass
1504 /* Note that psymbol names are interned via
1505 compute_and_set_names, so there's no need to compare the
1506 contents of the name here. */
1507 && sym1
->ginfo
.linkage_name () == sym2
->ginfo
.linkage_name ());
1510 /* Helper function, initialises partial symbol structure and stashes
1511 it into objfile's bcache. Note that our caching mechanism will
1512 use all fields of struct partial_symbol to determine hash value of the
1513 structure. In other words, having two symbols with the same name but
1514 different domain (or address) is possible and correct. */
1516 static struct partial_symbol
*
1517 add_psymbol_to_bcache (const partial_symbol
&psymbol
, struct objfile
*objfile
,
1520 /* Stash the partial symbol away in the cache. */
1521 return ((struct partial_symbol
*)
1522 objfile
->partial_symtabs
->psymbol_cache
.insert
1523 (&psymbol
, sizeof (struct partial_symbol
), added
));
1526 /* Helper function, adds partial symbol to the given partial symbol list. */
1529 append_psymbol_to_list (std::vector
<partial_symbol
*> &list
,
1530 struct partial_symbol
*psym
,
1531 struct objfile
*objfile
)
1533 list
.push_back (psym
);
1534 OBJSTAT (objfile
, n_psyms
++);
1537 /* See psympriv.h. */
1540 partial_symtab::add_psymbol (const partial_symbol
&psymbol
,
1541 psymbol_placement where
,
1542 struct objfile
*objfile
)
1546 /* Stash the partial symbol away in the cache. */
1547 partial_symbol
*psym
= add_psymbol_to_bcache (psymbol
, objfile
, &added
);
1549 /* Do not duplicate global partial symbols. */
1550 if (where
== psymbol_placement::GLOBAL
&& !added
)
1553 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1554 std::vector
<partial_symbol
*> &list
1555 = (where
== psymbol_placement::STATIC
1558 append_psymbol_to_list (list
, psym
, objfile
);
1561 /* See psympriv.h. */
1564 partial_symtab::add_psymbol (gdb::string_view name
, bool copy_name
,
1566 enum address_class theclass
,
1568 psymbol_placement where
,
1570 enum language language
, struct objfile
*objfile
)
1572 struct partial_symbol psymbol
;
1573 memset (&psymbol
, 0, sizeof (psymbol
));
1575 psymbol
.set_unrelocated_address (coreaddr
);
1576 psymbol
.ginfo
.section
= section
;
1577 psymbol
.domain
= domain
;
1578 psymbol
.aclass
= theclass
;
1579 psymbol
.ginfo
.set_language (language
, objfile
->partial_symtabs
->obstack ());
1580 psymbol
.ginfo
.compute_and_set_names (name
, copy_name
, objfile
->per_bfd
);
1582 add_psymbol (psymbol
, where
, objfile
);
1585 /* See psympriv.h. */
1588 init_psymbol_list (struct objfile
*objfile
, int total_symbols
)
1592 /* See psympriv.h. */
1594 partial_symtab::partial_symtab (const char *filename_
, struct objfile
*objfile
)
1595 : searched_flag (PST_NOT_SEARCHED
),
1599 objfile
->partial_symtabs
->install_psymtab (this);
1601 filename
= objfile
->intern (filename_
);
1603 if (symtab_create_debug
)
1605 /* Be a bit clever with debugging messages, and don't print objfile
1606 every time, only when it changes. */
1607 static char *last_objfile_name
= NULL
;
1609 if (last_objfile_name
== NULL
1610 || strcmp (last_objfile_name
, objfile_name (objfile
)) != 0)
1612 xfree (last_objfile_name
);
1613 last_objfile_name
= xstrdup (objfile_name (objfile
));
1614 fprintf_filtered (gdb_stdlog
,
1615 "Creating one or more psymtabs for objfile %s ...\n",
1618 fprintf_filtered (gdb_stdlog
,
1619 "Created psymtab %s for module %s.\n",
1620 host_address_to_string (this), filename
);
1624 /* See psympriv.h. */
1627 partial_symtab::expand_dependencies (struct objfile
*objfile
)
1629 for (int i
= 0; i
< number_of_dependencies
; ++i
)
1631 if (!dependencies
[i
]->readin_p (objfile
)
1632 && dependencies
[i
]->user
== NULL
)
1634 /* Inform about additional files to be read in. */
1637 fputs_filtered (" ", gdb_stdout
);
1639 fputs_filtered ("and ", gdb_stdout
);
1641 printf_filtered ("%s...", dependencies
[i
]->filename
);
1642 wrap_here (""); /* Flush output */
1643 gdb_flush (gdb_stdout
);
1645 dependencies
[i
]->expand_psymtab (objfile
);
1652 psymtab_storage::discard_psymtab (struct partial_symtab
*pst
)
1654 struct partial_symtab
**prev_pst
;
1657 Empty psymtabs happen as a result of header files which don't
1658 have any symbols in them. There can be a lot of them. But this
1659 check is wrong, in that a psymtab with N_SLINE entries but
1660 nothing else is not empty, but we don't realize that. Fixing
1661 that without slowing things down might be tricky. */
1663 /* First, snip it out of the psymtab chain. */
1665 prev_pst
= &psymtabs
;
1666 while ((*prev_pst
) != pst
)
1667 prev_pst
= &((*prev_pst
)->next
);
1668 (*prev_pst
) = pst
->next
;
1674 /* We need to pass a couple of items to the addrmap_foreach function,
1677 struct dump_psymtab_addrmap_data
1679 struct objfile
*objfile
;
1680 struct partial_symtab
*psymtab
;
1681 struct ui_file
*outfile
;
1683 /* Non-zero if the previously printed addrmap entry was for PSYMTAB.
1684 If so, we want to print the next one as well (since the next addrmap
1685 entry defines the end of the range). */
1686 int previous_matched
;
1689 /* Helper function for dump_psymtab_addrmap to print an addrmap entry. */
1692 dump_psymtab_addrmap_1 (void *datap
, CORE_ADDR start_addr
, void *obj
)
1694 struct dump_psymtab_addrmap_data
*data
1695 = (struct dump_psymtab_addrmap_data
*) datap
;
1696 struct gdbarch
*gdbarch
= data
->objfile
->arch ();
1697 struct partial_symtab
*addrmap_psymtab
= (struct partial_symtab
*) obj
;
1698 const char *psymtab_address_or_end
= NULL
;
1702 if (data
->psymtab
== NULL
1703 || data
->psymtab
== addrmap_psymtab
)
1704 psymtab_address_or_end
= host_address_to_string (addrmap_psymtab
);
1705 else if (data
->previous_matched
)
1706 psymtab_address_or_end
= "<ends here>";
1708 if (data
->psymtab
== NULL
1709 || data
->psymtab
== addrmap_psymtab
1710 || data
->previous_matched
)
1712 fprintf_filtered (data
->outfile
, " %s%s %s\n",
1713 data
->psymtab
!= NULL
? " " : "",
1714 paddress (gdbarch
, start_addr
),
1715 psymtab_address_or_end
);
1718 data
->previous_matched
= (data
->psymtab
== NULL
1719 || data
->psymtab
== addrmap_psymtab
);
1724 /* Helper function for maintenance_print_psymbols to print the addrmap
1725 of PSYMTAB. If PSYMTAB is NULL print the entire addrmap. */
1728 dump_psymtab_addrmap (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
1729 struct ui_file
*outfile
)
1731 struct dump_psymtab_addrmap_data addrmap_dump_data
;
1733 if ((psymtab
== NULL
1734 || psymtab
->psymtabs_addrmap_supported
)
1735 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
1737 addrmap_dump_data
.objfile
= objfile
;
1738 addrmap_dump_data
.psymtab
= psymtab
;
1739 addrmap_dump_data
.outfile
= outfile
;
1740 addrmap_dump_data
.previous_matched
= 0;
1741 fprintf_filtered (outfile
, "%sddress map:\n",
1742 psymtab
== NULL
? "Entire a" : " A");
1743 addrmap_foreach (objfile
->partial_symtabs
->psymtabs_addrmap
,
1744 dump_psymtab_addrmap_1
, &addrmap_dump_data
);
1749 maintenance_print_psymbols (const char *args
, int from_tty
)
1751 struct ui_file
*outfile
= gdb_stdout
;
1752 char *address_arg
= NULL
, *source_arg
= NULL
, *objfile_arg
= NULL
;
1753 int i
, outfile_idx
, found
;
1755 struct obj_section
*section
= NULL
;
1759 gdb_argv
argv (args
);
1761 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
1763 if (strcmp (argv
[i
], "-pc") == 0)
1765 if (argv
[i
+ 1] == NULL
)
1766 error (_("Missing pc value"));
1767 address_arg
= argv
[++i
];
1769 else if (strcmp (argv
[i
], "-source") == 0)
1771 if (argv
[i
+ 1] == NULL
)
1772 error (_("Missing source file"));
1773 source_arg
= argv
[++i
];
1775 else if (strcmp (argv
[i
], "-objfile") == 0)
1777 if (argv
[i
+ 1] == NULL
)
1778 error (_("Missing objfile name"));
1779 objfile_arg
= argv
[++i
];
1781 else if (strcmp (argv
[i
], "--") == 0)
1783 /* End of options. */
1787 else if (argv
[i
][0] == '-')
1789 /* Future proofing: Don't allow OUTFILE to begin with "-". */
1790 error (_("Unknown option: %s"), argv
[i
]);
1797 if (address_arg
!= NULL
&& source_arg
!= NULL
)
1798 error (_("Must specify at most one of -pc and -source"));
1800 stdio_file arg_outfile
;
1802 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
1804 if (argv
[outfile_idx
+ 1] != NULL
)
1805 error (_("Junk at end of command"));
1806 gdb::unique_xmalloc_ptr
<char> outfile_name
1807 (tilde_expand (argv
[outfile_idx
]));
1808 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
1809 perror_with_name (outfile_name
.get ());
1810 outfile
= &arg_outfile
;
1813 if (address_arg
!= NULL
)
1815 pc
= parse_and_eval_address (address_arg
);
1816 /* If we fail to find a section, that's ok, try the lookup anyway. */
1817 section
= find_pc_section (pc
);
1821 for (objfile
*objfile
: current_program_space
->objfiles ())
1823 int printed_objfile_header
= 0;
1824 int print_for_objfile
= 1;
1827 if (objfile_arg
!= NULL
)
1829 = compare_filenames_for_search (objfile_name (objfile
),
1831 if (!print_for_objfile
)
1834 if (address_arg
!= NULL
)
1836 struct bound_minimal_symbol msymbol
= { NULL
, NULL
};
1838 /* We don't assume each pc has a unique objfile (this is for
1840 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
,
1844 if (!printed_objfile_header
)
1846 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1847 objfile_name (objfile
));
1848 printed_objfile_header
= 1;
1850 dump_psymtab (objfile
, ps
, outfile
);
1851 dump_psymtab_addrmap (objfile
, ps
, outfile
);
1857 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1859 int print_for_source
= 0;
1862 if (source_arg
!= NULL
)
1865 = compare_filenames_for_search (ps
->filename
, source_arg
);
1868 if (source_arg
== NULL
1869 || print_for_source
)
1871 if (!printed_objfile_header
)
1873 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1874 objfile_name (objfile
));
1875 printed_objfile_header
= 1;
1877 dump_psymtab (objfile
, ps
, outfile
);
1878 dump_psymtab_addrmap (objfile
, ps
, outfile
);
1883 /* If we're printing all the objfile's symbols dump the full addrmap. */
1885 if (address_arg
== NULL
1886 && source_arg
== NULL
1887 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
1889 outfile
->puts ("\n");
1890 dump_psymtab_addrmap (objfile
, NULL
, outfile
);
1896 if (address_arg
!= NULL
)
1897 error (_("No partial symtab for address: %s"), address_arg
);
1898 if (source_arg
!= NULL
)
1899 error (_("No partial symtab for source file: %s"), source_arg
);
1903 /* List all the partial symbol tables whose names match REGEXP (optional). */
1906 maintenance_info_psymtabs (const char *regexp
, int from_tty
)
1911 for (struct program_space
*pspace
: program_spaces
)
1912 for (objfile
*objfile
: pspace
->objfiles ())
1914 struct gdbarch
*gdbarch
= objfile
->arch ();
1916 /* We don't want to print anything for this objfile until we
1917 actually find a symtab whose name matches. */
1918 int printed_objfile_start
= 0;
1920 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
, true))
1925 || re_exec (psymtab
->filename
))
1927 if (! printed_objfile_start
)
1929 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
1931 printf_filtered ("((struct objfile *) %s)\n",
1932 host_address_to_string (objfile
));
1933 printed_objfile_start
= 1;
1936 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1938 printf_filtered ("((struct partial_symtab *) %s)\n",
1939 host_address_to_string (psymtab
));
1941 printf_filtered (" readin %s\n",
1942 psymtab
->readin_p (objfile
) ? "yes" : "no");
1943 printf_filtered (" fullname %s\n",
1945 ? psymtab
->fullname
: "(null)");
1946 printf_filtered (" text addresses ");
1947 fputs_filtered (paddress (gdbarch
,
1948 psymtab
->text_low (objfile
)),
1950 printf_filtered (" -- ");
1951 fputs_filtered (paddress (gdbarch
,
1952 psymtab
->text_high (objfile
)),
1954 printf_filtered ("\n");
1955 printf_filtered (" psymtabs_addrmap_supported %s\n",
1956 (psymtab
->psymtabs_addrmap_supported
1958 printf_filtered (" globals ");
1959 if (!psymtab
->global_psymbols
.empty ())
1961 ("(* (struct partial_symbol **) %s @ %d)\n",
1962 host_address_to_string (psymtab
->global_psymbols
.data ()),
1963 (int) psymtab
->global_psymbols
.size ());
1965 printf_filtered ("(none)\n");
1966 printf_filtered (" statics ");
1967 if (!psymtab
->static_psymbols
.empty ())
1969 ("(* (struct partial_symbol **) %s @ %d)\n",
1970 host_address_to_string (psymtab
->static_psymbols
.data ()),
1971 (int) psymtab
->static_psymbols
.size ());
1973 printf_filtered ("(none)\n");
1975 printf_filtered (" user %s "
1976 "((struct partial_symtab *) %s)\n",
1977 psymtab
->user
->filename
,
1978 host_address_to_string (psymtab
->user
));
1979 printf_filtered (" dependencies ");
1980 if (psymtab
->number_of_dependencies
)
1984 printf_filtered ("{\n");
1985 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1987 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
1989 /* Note the string concatenation there --- no
1991 printf_filtered (" psymtab %s "
1992 "((struct partial_symtab *) %s)\n",
1994 host_address_to_string (dep
));
1996 printf_filtered (" }\n");
1999 printf_filtered ("(none)\n");
2000 printf_filtered (" }\n");
2004 if (printed_objfile_start
)
2005 printf_filtered ("}\n");
2009 /* Check consistency of currently expanded psymtabs vs symtabs. */
2012 maintenance_check_psymtabs (const char *ignore
, int from_tty
)
2015 struct compunit_symtab
*cust
= NULL
;
2016 const struct blockvector
*bv
;
2017 const struct block
*b
;
2019 for (objfile
*objfile
: current_program_space
->objfiles ())
2020 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
2022 struct gdbarch
*gdbarch
= objfile
->arch ();
2024 /* We don't call psymtab_to_symtab here because that may cause symtab
2025 expansion. When debugging a problem it helps if checkers leave
2026 things unchanged. */
2027 cust
= ps
->get_compunit_symtab (objfile
);
2029 /* First do some checks that don't require the associated symtab. */
2030 if (ps
->text_high (objfile
) < ps
->text_low (objfile
))
2032 printf_filtered ("Psymtab ");
2033 puts_filtered (ps
->filename
);
2034 printf_filtered (" covers bad range ");
2035 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
2037 printf_filtered (" - ");
2038 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
2040 printf_filtered ("\n");
2044 /* Now do checks requiring the associated symtab. */
2047 bv
= COMPUNIT_BLOCKVECTOR (cust
);
2048 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
2049 for (partial_symbol
*psym
: ps
->static_psymbols
)
2051 /* Skip symbols for inlined functions without address. These may
2052 or may not have a match in the full symtab. */
2053 if (psym
->aclass
== LOC_BLOCK
2054 && psym
->ginfo
.value
.address
== 0)
2057 sym
= block_lookup_symbol (b
, psym
->ginfo
.search_name (),
2058 symbol_name_match_type::SEARCH_NAME
,
2062 printf_filtered ("Static symbol `");
2063 puts_filtered (psym
->ginfo
.linkage_name ());
2064 printf_filtered ("' only found in ");
2065 puts_filtered (ps
->filename
);
2066 printf_filtered (" psymtab\n");
2069 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2070 for (partial_symbol
*psym
: ps
->global_psymbols
)
2072 sym
= block_lookup_symbol (b
, psym
->ginfo
.search_name (),
2073 symbol_name_match_type::SEARCH_NAME
,
2077 printf_filtered ("Global symbol `");
2078 puts_filtered (psym
->ginfo
.linkage_name ());
2079 printf_filtered ("' only found in ");
2080 puts_filtered (ps
->filename
);
2081 printf_filtered (" psymtab\n");
2084 if (ps
->raw_text_high () != 0
2085 && (ps
->text_low (objfile
) < BLOCK_START (b
)
2086 || ps
->text_high (objfile
) > BLOCK_END (b
)))
2088 printf_filtered ("Psymtab ");
2089 puts_filtered (ps
->filename
);
2090 printf_filtered (" covers ");
2091 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
2093 printf_filtered (" - ");
2094 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
2096 printf_filtered (" but symtab covers only ");
2097 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
2098 printf_filtered (" - ");
2099 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
2100 printf_filtered ("\n");
2105 void _initialize_psymtab ();
2107 _initialize_psymtab ()
2109 add_cmd ("psymbols", class_maintenance
, maintenance_print_psymbols
, _("\
2110 Print dump of current partial symbol definitions.\n\
2111 Usage: mt print psymbols [-objfile OBJFILE] [-pc ADDRESS] [--] [OUTFILE]\n\
2112 mt print psymbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
2113 Entries in the partial symbol table are dumped to file OUTFILE,\n\
2114 or the terminal if OUTFILE is unspecified.\n\
2115 If ADDRESS is provided, dump only the file for that address.\n\
2116 If SOURCE is provided, dump only that file's symbols.\n\
2117 If OBJFILE is provided, dump only that file's minimal symbols."),
2118 &maintenanceprintlist
);
2120 add_cmd ("psymtabs", class_maintenance
, maintenance_info_psymtabs
, _("\
2121 List the partial symbol tables for all object files.\n\
2122 This does not include information about individual partial symbols,\n\
2123 just the symbol table structures themselves."),
2124 &maintenanceinfolist
);
2126 add_cmd ("check-psymtabs", class_maintenance
, maintenance_check_psymtabs
,
2128 Check consistency of currently expanded psymtabs versus symtabs."),