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
1433 /* Partially fill a partial symtab. It will be completely filled at
1434 the end of the symbol list. */
1436 partial_symtab::partial_symtab (const char *filename
,
1437 struct objfile
*objfile
,
1439 : partial_symtab (filename
, objfile
)
1441 set_text_low (textlow
);
1442 set_text_high (raw_text_low ()); /* default */
1445 /* Perform "finishing up" operations of a partial symtab. */
1448 partial_symtab::end ()
1450 global_psymbols
.shrink_to_fit ();
1451 static_psymbols
.shrink_to_fit ();
1453 /* Sort the global list; don't sort the static list. */
1454 std::sort (global_psymbols
.begin (),
1455 global_psymbols
.end (),
1456 [] (partial_symbol
*s1
, partial_symbol
*s2
)
1458 return strcmp_iw_ordered (s1
->ginfo
.search_name (),
1459 s2
->ginfo
.search_name ()) < 0;
1463 /* See psymtab.h. */
1466 psymbol_bcache::hash (const void *addr
, int length
)
1468 unsigned long h
= 0;
1469 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1470 unsigned int lang
= psymbol
->ginfo
.language ();
1471 unsigned int domain
= psymbol
->domain
;
1472 unsigned int theclass
= psymbol
->aclass
;
1474 h
= fast_hash (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1475 h
= fast_hash (&lang
, sizeof (unsigned int), h
);
1476 h
= fast_hash (&domain
, sizeof (unsigned int), h
);
1477 h
= fast_hash (&theclass
, sizeof (unsigned int), h
);
1478 /* Note that psymbol names are interned via compute_and_set_names, so
1479 there's no need to hash the contents of the name here. */
1480 h
= fast_hash (&psymbol
->ginfo
.m_name
, sizeof (psymbol
->ginfo
.m_name
), h
);
1485 /* See psymtab.h. */
1488 psymbol_bcache::compare (const void *addr1
, const void *addr2
, int length
)
1490 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1491 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1493 return (memcmp (&sym1
->ginfo
.value
, &sym2
->ginfo
.value
,
1494 sizeof (sym1
->ginfo
.value
)) == 0
1495 && sym1
->ginfo
.language () == sym2
->ginfo
.language ()
1496 && sym1
->domain
== sym2
->domain
1497 && sym1
->aclass
== sym2
->aclass
1498 /* Note that psymbol names are interned via
1499 compute_and_set_names, so there's no need to compare the
1500 contents of the name here. */
1501 && sym1
->ginfo
.linkage_name () == sym2
->ginfo
.linkage_name ());
1504 /* Helper function, initialises partial symbol structure and stashes
1505 it into objfile's bcache. Note that our caching mechanism will
1506 use all fields of struct partial_symbol to determine hash value of the
1507 structure. In other words, having two symbols with the same name but
1508 different domain (or address) is possible and correct. */
1510 static struct partial_symbol
*
1511 add_psymbol_to_bcache (const partial_symbol
&psymbol
, struct objfile
*objfile
,
1514 /* Stash the partial symbol away in the cache. */
1515 return ((struct partial_symbol
*)
1516 objfile
->partial_symtabs
->psymbol_cache
.insert
1517 (&psymbol
, sizeof (struct partial_symbol
), added
));
1520 /* See psympriv.h. */
1523 partial_symtab::add_psymbol (const partial_symbol
&psymbol
,
1524 psymbol_placement where
,
1525 struct objfile
*objfile
)
1529 /* Stash the partial symbol away in the cache. */
1530 partial_symbol
*psym
= add_psymbol_to_bcache (psymbol
, objfile
, &added
);
1532 /* Do not duplicate global partial symbols. */
1533 if (where
== psymbol_placement::GLOBAL
&& !added
)
1536 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1537 std::vector
<partial_symbol
*> &list
1538 = (where
== psymbol_placement::STATIC
1541 list
.push_back (psym
);
1544 /* See psympriv.h. */
1547 partial_symtab::add_psymbol (gdb::string_view name
, bool copy_name
,
1549 enum address_class theclass
,
1551 psymbol_placement where
,
1553 enum language language
, struct objfile
*objfile
)
1555 struct partial_symbol psymbol
;
1556 memset (&psymbol
, 0, sizeof (psymbol
));
1558 psymbol
.set_unrelocated_address (coreaddr
);
1559 psymbol
.ginfo
.section
= section
;
1560 psymbol
.domain
= domain
;
1561 psymbol
.aclass
= theclass
;
1562 psymbol
.ginfo
.set_language (language
, objfile
->partial_symtabs
->obstack ());
1563 psymbol
.ginfo
.compute_and_set_names (name
, copy_name
, objfile
->per_bfd
);
1565 add_psymbol (psymbol
, where
, objfile
);
1568 /* See psympriv.h. */
1570 partial_symtab::partial_symtab (const char *filename_
, struct objfile
*objfile
)
1571 : searched_flag (PST_NOT_SEARCHED
),
1575 objfile
->partial_symtabs
->install_psymtab (this);
1577 filename
= objfile
->intern (filename_
);
1579 if (symtab_create_debug
)
1581 /* Be a bit clever with debugging messages, and don't print objfile
1582 every time, only when it changes. */
1583 static char *last_objfile_name
= NULL
;
1585 if (last_objfile_name
== NULL
1586 || strcmp (last_objfile_name
, objfile_name (objfile
)) != 0)
1588 xfree (last_objfile_name
);
1589 last_objfile_name
= xstrdup (objfile_name (objfile
));
1590 fprintf_filtered (gdb_stdlog
,
1591 "Creating one or more psymtabs for objfile %s ...\n",
1594 fprintf_filtered (gdb_stdlog
,
1595 "Created psymtab %s for module %s.\n",
1596 host_address_to_string (this), filename
);
1600 /* See psympriv.h. */
1603 partial_symtab::expand_dependencies (struct objfile
*objfile
)
1605 for (int i
= 0; i
< number_of_dependencies
; ++i
)
1607 if (!dependencies
[i
]->readin_p (objfile
)
1608 && dependencies
[i
]->user
== NULL
)
1610 /* Inform about additional files to be read in. */
1613 fputs_filtered (" ", gdb_stdout
);
1615 fputs_filtered ("and ", gdb_stdout
);
1617 printf_filtered ("%s...", dependencies
[i
]->filename
);
1618 wrap_here (""); /* Flush output */
1619 gdb_flush (gdb_stdout
);
1621 dependencies
[i
]->expand_psymtab (objfile
);
1628 psymtab_storage::discard_psymtab (struct partial_symtab
*pst
)
1630 struct partial_symtab
**prev_pst
;
1633 Empty psymtabs happen as a result of header files which don't
1634 have any symbols in them. There can be a lot of them. But this
1635 check is wrong, in that a psymtab with N_SLINE entries but
1636 nothing else is not empty, but we don't realize that. Fixing
1637 that without slowing things down might be tricky. */
1639 /* First, snip it out of the psymtab chain. */
1641 prev_pst
= &psymtabs
;
1642 while ((*prev_pst
) != pst
)
1643 prev_pst
= &((*prev_pst
)->next
);
1644 (*prev_pst
) = pst
->next
;
1650 /* We need to pass a couple of items to the addrmap_foreach function,
1653 struct dump_psymtab_addrmap_data
1655 struct objfile
*objfile
;
1656 struct partial_symtab
*psymtab
;
1657 struct ui_file
*outfile
;
1659 /* Non-zero if the previously printed addrmap entry was for PSYMTAB.
1660 If so, we want to print the next one as well (since the next addrmap
1661 entry defines the end of the range). */
1662 int previous_matched
;
1665 /* Helper function for dump_psymtab_addrmap to print an addrmap entry. */
1668 dump_psymtab_addrmap_1 (void *datap
, CORE_ADDR start_addr
, void *obj
)
1670 struct dump_psymtab_addrmap_data
*data
1671 = (struct dump_psymtab_addrmap_data
*) datap
;
1672 struct gdbarch
*gdbarch
= data
->objfile
->arch ();
1673 struct partial_symtab
*addrmap_psymtab
= (struct partial_symtab
*) obj
;
1674 const char *psymtab_address_or_end
= NULL
;
1678 if (data
->psymtab
== NULL
1679 || data
->psymtab
== addrmap_psymtab
)
1680 psymtab_address_or_end
= host_address_to_string (addrmap_psymtab
);
1681 else if (data
->previous_matched
)
1682 psymtab_address_or_end
= "<ends here>";
1684 if (data
->psymtab
== NULL
1685 || data
->psymtab
== addrmap_psymtab
1686 || data
->previous_matched
)
1688 fprintf_filtered (data
->outfile
, " %s%s %s\n",
1689 data
->psymtab
!= NULL
? " " : "",
1690 paddress (gdbarch
, start_addr
),
1691 psymtab_address_or_end
);
1694 data
->previous_matched
= (data
->psymtab
== NULL
1695 || data
->psymtab
== addrmap_psymtab
);
1700 /* Helper function for maintenance_print_psymbols to print the addrmap
1701 of PSYMTAB. If PSYMTAB is NULL print the entire addrmap. */
1704 dump_psymtab_addrmap (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
1705 struct ui_file
*outfile
)
1707 struct dump_psymtab_addrmap_data addrmap_dump_data
;
1709 if ((psymtab
== NULL
1710 || psymtab
->psymtabs_addrmap_supported
)
1711 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
1713 addrmap_dump_data
.objfile
= objfile
;
1714 addrmap_dump_data
.psymtab
= psymtab
;
1715 addrmap_dump_data
.outfile
= outfile
;
1716 addrmap_dump_data
.previous_matched
= 0;
1717 fprintf_filtered (outfile
, "%sddress map:\n",
1718 psymtab
== NULL
? "Entire a" : " A");
1719 addrmap_foreach (objfile
->partial_symtabs
->psymtabs_addrmap
,
1720 dump_psymtab_addrmap_1
, &addrmap_dump_data
);
1725 maintenance_print_psymbols (const char *args
, int from_tty
)
1727 struct ui_file
*outfile
= gdb_stdout
;
1728 char *address_arg
= NULL
, *source_arg
= NULL
, *objfile_arg
= NULL
;
1729 int i
, outfile_idx
, found
;
1731 struct obj_section
*section
= NULL
;
1735 gdb_argv
argv (args
);
1737 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
1739 if (strcmp (argv
[i
], "-pc") == 0)
1741 if (argv
[i
+ 1] == NULL
)
1742 error (_("Missing pc value"));
1743 address_arg
= argv
[++i
];
1745 else if (strcmp (argv
[i
], "-source") == 0)
1747 if (argv
[i
+ 1] == NULL
)
1748 error (_("Missing source file"));
1749 source_arg
= argv
[++i
];
1751 else if (strcmp (argv
[i
], "-objfile") == 0)
1753 if (argv
[i
+ 1] == NULL
)
1754 error (_("Missing objfile name"));
1755 objfile_arg
= argv
[++i
];
1757 else if (strcmp (argv
[i
], "--") == 0)
1759 /* End of options. */
1763 else if (argv
[i
][0] == '-')
1765 /* Future proofing: Don't allow OUTFILE to begin with "-". */
1766 error (_("Unknown option: %s"), argv
[i
]);
1773 if (address_arg
!= NULL
&& source_arg
!= NULL
)
1774 error (_("Must specify at most one of -pc and -source"));
1776 stdio_file arg_outfile
;
1778 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
1780 if (argv
[outfile_idx
+ 1] != NULL
)
1781 error (_("Junk at end of command"));
1782 gdb::unique_xmalloc_ptr
<char> outfile_name
1783 (tilde_expand (argv
[outfile_idx
]));
1784 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
1785 perror_with_name (outfile_name
.get ());
1786 outfile
= &arg_outfile
;
1789 if (address_arg
!= NULL
)
1791 pc
= parse_and_eval_address (address_arg
);
1792 /* If we fail to find a section, that's ok, try the lookup anyway. */
1793 section
= find_pc_section (pc
);
1797 for (objfile
*objfile
: current_program_space
->objfiles ())
1799 int printed_objfile_header
= 0;
1800 int print_for_objfile
= 1;
1803 if (objfile_arg
!= NULL
)
1805 = compare_filenames_for_search (objfile_name (objfile
),
1807 if (!print_for_objfile
)
1810 if (address_arg
!= NULL
)
1812 struct bound_minimal_symbol msymbol
= { NULL
, NULL
};
1814 /* We don't assume each pc has a unique objfile (this is for
1816 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
,
1820 if (!printed_objfile_header
)
1822 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1823 objfile_name (objfile
));
1824 printed_objfile_header
= 1;
1826 dump_psymtab (objfile
, ps
, outfile
);
1827 dump_psymtab_addrmap (objfile
, ps
, outfile
);
1833 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1835 int print_for_source
= 0;
1838 if (source_arg
!= NULL
)
1841 = compare_filenames_for_search (ps
->filename
, source_arg
);
1844 if (source_arg
== NULL
1845 || print_for_source
)
1847 if (!printed_objfile_header
)
1849 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1850 objfile_name (objfile
));
1851 printed_objfile_header
= 1;
1853 dump_psymtab (objfile
, ps
, outfile
);
1854 dump_psymtab_addrmap (objfile
, ps
, outfile
);
1859 /* If we're printing all the objfile's symbols dump the full addrmap. */
1861 if (address_arg
== NULL
1862 && source_arg
== NULL
1863 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
1865 outfile
->puts ("\n");
1866 dump_psymtab_addrmap (objfile
, NULL
, outfile
);
1872 if (address_arg
!= NULL
)
1873 error (_("No partial symtab for address: %s"), address_arg
);
1874 if (source_arg
!= NULL
)
1875 error (_("No partial symtab for source file: %s"), source_arg
);
1879 /* List all the partial symbol tables whose names match REGEXP (optional). */
1882 maintenance_info_psymtabs (const char *regexp
, int from_tty
)
1887 for (struct program_space
*pspace
: program_spaces
)
1888 for (objfile
*objfile
: pspace
->objfiles ())
1890 struct gdbarch
*gdbarch
= objfile
->arch ();
1892 /* We don't want to print anything for this objfile until we
1893 actually find a symtab whose name matches. */
1894 int printed_objfile_start
= 0;
1896 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
, true))
1901 || re_exec (psymtab
->filename
))
1903 if (! printed_objfile_start
)
1905 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
1907 printf_filtered ("((struct objfile *) %s)\n",
1908 host_address_to_string (objfile
));
1909 printed_objfile_start
= 1;
1912 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1914 printf_filtered ("((struct partial_symtab *) %s)\n",
1915 host_address_to_string (psymtab
));
1917 printf_filtered (" readin %s\n",
1918 psymtab
->readin_p (objfile
) ? "yes" : "no");
1919 printf_filtered (" fullname %s\n",
1921 ? psymtab
->fullname
: "(null)");
1922 printf_filtered (" text addresses ");
1923 fputs_filtered (paddress (gdbarch
,
1924 psymtab
->text_low (objfile
)),
1926 printf_filtered (" -- ");
1927 fputs_filtered (paddress (gdbarch
,
1928 psymtab
->text_high (objfile
)),
1930 printf_filtered ("\n");
1931 printf_filtered (" psymtabs_addrmap_supported %s\n",
1932 (psymtab
->psymtabs_addrmap_supported
1934 printf_filtered (" globals ");
1935 if (!psymtab
->global_psymbols
.empty ())
1937 ("(* (struct partial_symbol **) %s @ %d)\n",
1938 host_address_to_string (psymtab
->global_psymbols
.data ()),
1939 (int) psymtab
->global_psymbols
.size ());
1941 printf_filtered ("(none)\n");
1942 printf_filtered (" statics ");
1943 if (!psymtab
->static_psymbols
.empty ())
1945 ("(* (struct partial_symbol **) %s @ %d)\n",
1946 host_address_to_string (psymtab
->static_psymbols
.data ()),
1947 (int) psymtab
->static_psymbols
.size ());
1949 printf_filtered ("(none)\n");
1951 printf_filtered (" user %s "
1952 "((struct partial_symtab *) %s)\n",
1953 psymtab
->user
->filename
,
1954 host_address_to_string (psymtab
->user
));
1955 printf_filtered (" dependencies ");
1956 if (psymtab
->number_of_dependencies
)
1960 printf_filtered ("{\n");
1961 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1963 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
1965 /* Note the string concatenation there --- no
1967 printf_filtered (" psymtab %s "
1968 "((struct partial_symtab *) %s)\n",
1970 host_address_to_string (dep
));
1972 printf_filtered (" }\n");
1975 printf_filtered ("(none)\n");
1976 printf_filtered (" }\n");
1980 if (printed_objfile_start
)
1981 printf_filtered ("}\n");
1985 /* Check consistency of currently expanded psymtabs vs symtabs. */
1988 maintenance_check_psymtabs (const char *ignore
, int from_tty
)
1991 struct compunit_symtab
*cust
= NULL
;
1992 const struct blockvector
*bv
;
1993 const struct block
*b
;
1995 for (objfile
*objfile
: current_program_space
->objfiles ())
1996 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1998 struct gdbarch
*gdbarch
= objfile
->arch ();
2000 /* We don't call psymtab_to_symtab here because that may cause symtab
2001 expansion. When debugging a problem it helps if checkers leave
2002 things unchanged. */
2003 cust
= ps
->get_compunit_symtab (objfile
);
2005 /* First do some checks that don't require the associated symtab. */
2006 if (ps
->text_high (objfile
) < ps
->text_low (objfile
))
2008 printf_filtered ("Psymtab ");
2009 puts_filtered (ps
->filename
);
2010 printf_filtered (" covers bad range ");
2011 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
2013 printf_filtered (" - ");
2014 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
2016 printf_filtered ("\n");
2020 /* Now do checks requiring the associated symtab. */
2023 bv
= COMPUNIT_BLOCKVECTOR (cust
);
2024 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
2025 for (partial_symbol
*psym
: ps
->static_psymbols
)
2027 /* Skip symbols for inlined functions without address. These may
2028 or may not have a match in the full symtab. */
2029 if (psym
->aclass
== LOC_BLOCK
2030 && psym
->ginfo
.value
.address
== 0)
2033 sym
= block_lookup_symbol (b
, psym
->ginfo
.search_name (),
2034 symbol_name_match_type::SEARCH_NAME
,
2038 printf_filtered ("Static symbol `");
2039 puts_filtered (psym
->ginfo
.linkage_name ());
2040 printf_filtered ("' only found in ");
2041 puts_filtered (ps
->filename
);
2042 printf_filtered (" psymtab\n");
2045 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2046 for (partial_symbol
*psym
: ps
->global_psymbols
)
2048 sym
= block_lookup_symbol (b
, psym
->ginfo
.search_name (),
2049 symbol_name_match_type::SEARCH_NAME
,
2053 printf_filtered ("Global symbol `");
2054 puts_filtered (psym
->ginfo
.linkage_name ());
2055 printf_filtered ("' only found in ");
2056 puts_filtered (ps
->filename
);
2057 printf_filtered (" psymtab\n");
2060 if (ps
->raw_text_high () != 0
2061 && (ps
->text_low (objfile
) < BLOCK_START (b
)
2062 || ps
->text_high (objfile
) > BLOCK_END (b
)))
2064 printf_filtered ("Psymtab ");
2065 puts_filtered (ps
->filename
);
2066 printf_filtered (" covers ");
2067 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
2069 printf_filtered (" - ");
2070 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
2072 printf_filtered (" but symtab covers only ");
2073 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
2074 printf_filtered (" - ");
2075 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
2076 printf_filtered ("\n");
2081 void _initialize_psymtab ();
2083 _initialize_psymtab ()
2085 add_cmd ("psymbols", class_maintenance
, maintenance_print_psymbols
, _("\
2086 Print dump of current partial symbol definitions.\n\
2087 Usage: mt print psymbols [-objfile OBJFILE] [-pc ADDRESS] [--] [OUTFILE]\n\
2088 mt print psymbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
2089 Entries in the partial symbol table are dumped to file OUTFILE,\n\
2090 or the terminal if OUTFILE is unspecified.\n\
2091 If ADDRESS is provided, dump only the file for that address.\n\
2092 If SOURCE is provided, dump only that file's symbols.\n\
2093 If OBJFILE is provided, dump only that file's minimal symbols."),
2094 &maintenanceprintlist
);
2096 add_cmd ("psymtabs", class_maintenance
, maintenance_info_psymtabs
, _("\
2097 List the partial symbol tables for all object files.\n\
2098 This does not include information about individual partial symbols,\n\
2099 just the symbol table structures themselves."),
2100 &maintenanceinfolist
);
2102 add_cmd ("check-psymtabs", class_maintenance
, maintenance_check_psymtabs
,
2104 Check consistency of currently expanded psymtabs versus symtabs."),