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
);
58 static unsigned long psymbol_hash (const void *addr
, int length
);
59 static int psymbol_compare (const void *addr1
, const void *addr2
, int length
);
61 psymtab_storage::psymtab_storage ()
62 : psymbol_cache (psymbol_hash
, psymbol_compare
)
66 psymtab_storage::~psymtab_storage ()
68 partial_symtab
*iter
= psymtabs
;
69 while (iter
!= nullptr)
71 partial_symtab
*next
= iter
->next
;
80 psymtab_storage::install_psymtab (partial_symtab
*pst
)
90 psymtab_storage::partial_symtab_range
91 require_partial_symbols (struct objfile
*objfile
, bool verbose
)
93 if ((objfile
->flags
& OBJF_PSYMTABS_READ
) == 0)
95 objfile
->flags
|= OBJF_PSYMTABS_READ
;
97 if (objfile
->sf
->sym_read_psymbols
)
100 printf_filtered (_("Reading symbols from %s...\n"),
101 objfile_name (objfile
));
102 (*objfile
->sf
->sym_read_psymbols
) (objfile
);
104 /* Partial symbols list are not expected to changed after this
106 objfile
->partial_symtabs
->global_psymbols
.shrink_to_fit ();
107 objfile
->partial_symtabs
->static_psymbols
.shrink_to_fit ();
109 if (verbose
&& !objfile_has_symbols (objfile
))
110 printf_filtered (_("(No debugging symbols found in %s)\n"),
111 objfile_name (objfile
));
115 return objfile
->psymtabs ();
118 /* Helper function for psym_map_symtabs_matching_filename that
119 expands the symtabs and calls the iterator. */
122 partial_map_expand_apply (struct objfile
*objfile
,
124 const char *real_path
,
125 struct partial_symtab
*pst
,
126 gdb::function_view
<bool (symtab
*)> callback
)
128 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
130 /* Shared psymtabs should never be seen here. Instead they should
131 be handled properly by the caller. */
132 gdb_assert (pst
->user
== NULL
);
134 /* Don't visit already-expanded psymtabs. */
135 if (pst
->readin_p (objfile
))
138 /* This may expand more than one symtab, and we want to iterate over
140 psymtab_to_symtab (objfile
, pst
);
142 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
143 last_made
, callback
);
146 /* Psymtab version of map_symtabs_matching_filename. See its definition in
147 the definition of quick_symbol_functions in symfile.h. */
150 psym_map_symtabs_matching_filename
151 (struct objfile
*objfile
,
153 const char *real_path
,
154 gdb::function_view
<bool (symtab
*)> callback
)
156 const char *name_basename
= lbasename (name
);
158 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
160 /* Anonymous psymtabs don't have a file name. */
164 if (compare_filenames_for_search (pst
->filename
, name
))
169 if (partial_map_expand_apply (objfile
, name
, real_path
,
175 /* Before we invoke realpath, which can get expensive when many
176 files are involved, do a quick comparison of the basenames. */
177 if (! basenames_may_differ
178 && FILENAME_CMP (name_basename
, lbasename (pst
->filename
)) != 0)
181 if (compare_filenames_for_search (psymtab_to_fullname (pst
), name
))
183 if (partial_map_expand_apply (objfile
, name
, real_path
,
189 /* If the user gave us an absolute path, try to find the file in
190 this symtab and use its absolute path. */
191 if (real_path
!= NULL
)
193 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
194 gdb_assert (IS_ABSOLUTE_PATH (name
));
195 if (filename_cmp (psymtab_to_fullname (pst
), real_path
) == 0)
197 if (partial_map_expand_apply (objfile
, name
, real_path
,
208 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
209 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
211 static struct partial_symtab
*
212 find_pc_sect_psymtab_closer (struct objfile
*objfile
,
213 CORE_ADDR pc
, struct obj_section
*section
,
214 struct partial_symtab
*pst
,
215 struct bound_minimal_symbol msymbol
)
217 struct partial_symtab
*tpst
;
218 struct partial_symtab
*best_pst
= pst
;
219 CORE_ADDR best_addr
= pst
->text_low (objfile
);
221 gdb_assert (!pst
->psymtabs_addrmap_supported
);
223 /* An objfile that has its functions reordered might have
224 many partial symbol tables containing the PC, but
225 we want the partial symbol table that contains the
226 function containing the PC. */
227 if (!(objfile
->flags
& OBJF_REORDERED
)
228 && section
== NULL
) /* Can't validate section this way. */
231 if (msymbol
.minsym
== NULL
)
234 /* The code range of partial symtabs sometimes overlap, so, in
235 the loop below, we need to check all partial symtabs and
236 find the one that fits better for the given PC address. We
237 select the partial symtab that contains a symbol whose
238 address is closest to the PC address. By closest we mean
239 that find_pc_sect_symbol returns the symbol with address
240 that is closest and still less than the given PC. */
241 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
243 if (pc
>= tpst
->text_low (objfile
) && pc
< tpst
->text_high (objfile
))
245 struct partial_symbol
*p
;
248 /* NOTE: This assumes that every psymbol has a
249 corresponding msymbol, which is not necessarily
250 true; the debug info might be much richer than the
251 object's symbol table. */
252 p
= find_pc_sect_psymbol (objfile
, tpst
, pc
, section
);
254 && (p
->address (objfile
) == BMSYMBOL_VALUE_ADDRESS (msymbol
)))
257 /* Also accept the textlow value of a psymtab as a
258 "symbol", to provide some support for partial
259 symbol tables with line information but no debug
260 symbols (e.g. those produced by an assembler). */
262 this_addr
= p
->address (objfile
);
264 this_addr
= tpst
->text_low (objfile
);
266 /* Check whether it is closer than our current
267 BEST_ADDR. Since this symbol address is
268 necessarily lower or equal to PC, the symbol closer
269 to PC is the symbol which address is the highest.
270 This way we return the psymtab which contains such
271 best match symbol. This can help in cases where the
272 symbol information/debuginfo is not complete, like
273 for instance on IRIX6 with gcc, where no debug info
274 is emitted for statics. (See also the nodebug.exp
276 if (this_addr
> best_addr
)
278 best_addr
= this_addr
;
286 /* Find which partial symtab contains PC and SECTION. Return NULL if
287 none. We return the psymtab that contains a symbol whose address
288 exactly matches PC, or, if we cannot find an exact match, the
289 psymtab that contains a symbol whose address is closest to PC. */
291 static struct partial_symtab
*
292 find_pc_sect_psymtab (struct objfile
*objfile
, CORE_ADDR pc
,
293 struct obj_section
*section
,
294 struct bound_minimal_symbol msymbol
)
296 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better
297 granularity than the later used TEXTLOW/TEXTHIGH one. However, we need
298 to take care as the PSYMTABS_ADDRMAP can hold things other than partial
299 symtabs in some cases.
301 This function should only be called for objfiles that are using partial
302 symtabs, not for objfiles that are using indexes (.gdb_index or
303 .debug_names), however 'maintenance print psymbols' calls this function
304 directly for all objfiles. If we assume that PSYMTABS_ADDRMAP contains
305 partial symtabs then we will end up returning a pointer to an object
306 that is not a partial_symtab, which doesn't end well. */
308 if (objfile
->partial_symtabs
->psymtabs
!= NULL
309 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
311 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
313 struct partial_symtab
*pst
314 = ((struct partial_symtab
*)
315 addrmap_find (objfile
->partial_symtabs
->psymtabs_addrmap
,
319 /* FIXME: addrmaps currently do not handle overlayed sections,
320 so fall back to the non-addrmap case if we're debugging
321 overlays and the addrmap returned the wrong section. */
322 if (overlay_debugging
&& msymbol
.minsym
!= NULL
&& section
!= NULL
)
324 struct partial_symbol
*p
;
326 /* NOTE: This assumes that every psymbol has a
327 corresponding msymbol, which is not necessarily
328 true; the debug info might be much richer than the
329 object's symbol table. */
330 p
= find_pc_sect_psymbol (objfile
, pst
, pc
, section
);
332 || (p
->address (objfile
)
333 != BMSYMBOL_VALUE_ADDRESS (msymbol
)))
337 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
338 PSYMTABS_ADDRMAP we used has already the best 1-byte
339 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
340 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
349 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
350 which still have no corresponding full SYMTABs read. But it is not
351 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
354 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
355 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
356 debug info type in single OBJFILE. */
358 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
359 if (!pst
->psymtabs_addrmap_supported
360 && pc
>= pst
->text_low (objfile
) && pc
< pst
->text_high (objfile
))
362 struct partial_symtab
*best_pst
;
364 best_pst
= find_pc_sect_psymtab_closer (objfile
, pc
, section
, pst
,
366 if (best_pst
!= NULL
)
373 /* Psymtab version of find_pc_sect_compunit_symtab. See its definition in
374 the definition of quick_symbol_functions in symfile.h. */
376 static struct compunit_symtab
*
377 psym_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
378 struct bound_minimal_symbol msymbol
,
380 struct obj_section
*section
,
383 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
, section
,
387 if (warn_if_readin
&& ps
->readin_p (objfile
))
388 /* Might want to error() here (in case symtab is corrupt and
389 will cause a core dump), but maybe we can successfully
390 continue, so let's not. */
392 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
393 paddress (objfile
->arch (), pc
));
394 psymtab_to_symtab (objfile
, ps
);
395 return ps
->get_compunit_symtab (objfile
);
400 /* Find which partial symbol within a psymtab matches PC and SECTION.
401 Return NULL if none. */
403 static struct partial_symbol
*
404 find_pc_sect_psymbol (struct objfile
*objfile
,
405 struct partial_symtab
*psymtab
, CORE_ADDR pc
,
406 struct obj_section
*section
)
408 struct partial_symbol
*best
= NULL
;
410 const CORE_ADDR textlow
= psymtab
->text_low (objfile
);
412 gdb_assert (psymtab
!= NULL
);
414 /* Cope with programs that start at address 0. */
415 best_pc
= (textlow
!= 0) ? textlow
- 1 : 0;
417 /* Search the global symbols as well as the static symbols, so that
418 find_pc_partial_function doesn't use a minimal symbol and thus
419 cache a bad endaddr. */
420 for (int i
= 0; i
< psymtab
->n_global_syms
; i
++)
423 = objfile
->partial_symtabs
->global_psymbols
[psymtab
->globals_offset
426 if (p
->domain
== VAR_DOMAIN
427 && p
->aclass
== LOC_BLOCK
428 && pc
>= p
->address (objfile
)
429 && (p
->address (objfile
) > best_pc
430 || (psymtab
->text_low (objfile
) == 0
431 && best_pc
== 0 && p
->address (objfile
) == 0)))
433 if (section
!= NULL
) /* Match on a specific section. */
435 if (!matching_obj_sections (p
->obj_section (objfile
),
439 best_pc
= p
->address (objfile
);
444 for (int i
= 0; i
< psymtab
->n_static_syms
; i
++)
447 = objfile
->partial_symtabs
->static_psymbols
[psymtab
->statics_offset
450 if (p
->domain
== VAR_DOMAIN
451 && p
->aclass
== LOC_BLOCK
452 && pc
>= p
->address (objfile
)
453 && (p
->address (objfile
) > best_pc
454 || (psymtab
->text_low (objfile
) == 0
455 && best_pc
== 0 && p
->address (objfile
) == 0)))
457 if (section
!= NULL
) /* Match on a specific section. */
459 if (!matching_obj_sections (p
->obj_section (objfile
),
463 best_pc
= p
->address (objfile
);
471 /* Psymtab version of lookup_symbol. See its definition in
472 the definition of quick_symbol_functions in symfile.h. */
474 static struct compunit_symtab
*
475 psym_lookup_symbol (struct objfile
*objfile
,
476 block_enum block_index
, const char *name
,
477 const domain_enum domain
)
479 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
480 struct compunit_symtab
*stab_best
= NULL
;
482 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
484 lookup_name_info psym_lookup_name
= lookup_name
.make_ignore_params ();
486 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
488 if (!ps
->readin_p (objfile
)
489 && lookup_partial_symbol (objfile
, ps
, psym_lookup_name
,
490 psymtab_index
, domain
))
492 struct symbol
*sym
, *with_opaque
= NULL
;
493 struct compunit_symtab
*stab
= psymtab_to_symtab (objfile
, ps
);
494 /* Note: While psymtab_to_symtab can return NULL if the
495 partial symtab is empty, we can assume it won't here
496 because lookup_partial_symbol succeeded. */
497 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
498 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
500 sym
= block_find_symbol (block
, name
, domain
,
501 block_find_non_opaque_type_preferred
,
504 /* Some caution must be observed with overloaded functions
505 and methods, since the index will not contain any overload
506 information (but NAME might contain it). */
509 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
511 if (with_opaque
!= NULL
512 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
515 /* Keep looking through other psymtabs. */
522 /* Psymtab version of lookup_global_symbol_language. See its definition in
523 the definition of quick_symbol_functions in symfile.h. */
526 psym_lookup_global_symbol_language (struct objfile
*objfile
, const char *name
,
527 domain_enum domain
, bool *symbol_found_p
)
529 *symbol_found_p
= false;
530 if (objfile
->sf
== NULL
)
531 return language_unknown
;
533 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
535 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
537 struct partial_symbol
*psym
;
538 if (ps
->readin_p (objfile
))
541 psym
= lookup_partial_symbol (objfile
, ps
, lookup_name
, 1, domain
);
544 *symbol_found_p
= true;
545 return psym
->ginfo
.language ();
549 return language_unknown
;
552 /* Returns true if PSYM matches LOOKUP_NAME. */
555 psymbol_name_matches (partial_symbol
*psym
,
556 const lookup_name_info
&lookup_name
)
558 const language_defn
*lang
= language_def (psym
->ginfo
.language ());
559 symbol_name_matcher_ftype
*name_match
560 = lang
->get_symbol_name_matcher (lookup_name
);
561 return name_match (psym
->ginfo
.search_name (), lookup_name
, NULL
);
564 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
565 the global block of PST if GLOBAL, and otherwise the static block.
566 MATCH is the comparison operation that returns true iff MATCH (s,
567 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
568 non-null, the symbols in the block are assumed to be ordered
569 according to it (allowing binary search). It must be compatible
570 with MATCH. Returns the symbol, if found, and otherwise NULL. */
572 static struct partial_symbol
*
573 match_partial_symbol (struct objfile
*objfile
,
574 struct partial_symtab
*pst
, int global
,
575 const lookup_name_info
&name
, domain_enum domain
,
576 symbol_compare_ftype
*ordered_compare
)
578 struct partial_symbol
**start
, **psym
;
579 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
580 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
581 int do_linear_search
= 1;
587 &objfile
->partial_symtabs
->global_psymbols
[pst
->globals_offset
] :
588 &objfile
->partial_symtabs
->static_psymbols
[pst
->statics_offset
]);
590 if (global
&& ordered_compare
) /* Can use a binary search. */
592 do_linear_search
= 0;
594 /* Binary search. This search is guaranteed to end with center
595 pointing at the earliest partial symbol whose name might be
596 correct. At that point *all* partial symbols with an
597 appropriate name will be checked against the correct
601 top
= start
+ length
- 1;
605 center
= bottom
+ (top
- bottom
) / 2;
606 gdb_assert (center
< top
);
608 enum language lang
= (*center
)->ginfo
.language ();
609 const char *lang_ln
= name
.language_lookup_name (lang
);
611 if (ordered_compare ((*center
)->ginfo
.search_name (),
617 gdb_assert (top
== bottom
);
619 while (top
<= real_top
620 && psymbol_name_matches (*top
, name
))
622 if (symbol_matches_domain ((*top
)->ginfo
.language (),
623 (*top
)->domain
, domain
))
629 /* Can't use a binary search or else we found during the binary search that
630 we should also do a linear search. */
632 if (do_linear_search
)
634 for (psym
= start
; psym
< start
+ length
; psym
++)
636 if (symbol_matches_domain ((*psym
)->ginfo
.language (),
637 (*psym
)->domain
, domain
)
638 && psymbol_name_matches (*psym
, name
))
646 /* Look, in partial_symtab PST, for symbol whose natural name is
647 LOOKUP_NAME. Check the global symbols if GLOBAL, the static
650 static struct partial_symbol
*
651 lookup_partial_symbol (struct objfile
*objfile
,
652 struct partial_symtab
*pst
,
653 const lookup_name_info
&lookup_name
,
654 int global
, domain_enum domain
)
656 struct partial_symbol
**start
, **psym
;
657 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
658 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
659 int do_linear_search
= 1;
665 &objfile
->partial_symtabs
->global_psymbols
[pst
->globals_offset
] :
666 &objfile
->partial_symtabs
->static_psymbols
[pst
->statics_offset
]);
668 if (global
) /* This means we can use a binary search. */
670 do_linear_search
= 0;
672 /* Binary search. This search is guaranteed to end with center
673 pointing at the earliest partial symbol whose name might be
674 correct. At that point *all* partial symbols with an
675 appropriate name will be checked against the correct
679 top
= start
+ length
- 1;
683 center
= bottom
+ (top
- bottom
) / 2;
685 gdb_assert (center
< top
);
687 if (strcmp_iw_ordered ((*center
)->ginfo
.search_name (),
688 lookup_name
.c_str ()) >= 0)
698 gdb_assert (top
== bottom
);
700 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
701 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
702 while (top
>= start
&& symbol_matches_search_name (&(*top
)->ginfo
,
706 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
709 while (top
<= real_top
&& symbol_matches_search_name (&(*top
)->ginfo
,
712 if (symbol_matches_domain ((*top
)->ginfo
.language (),
713 (*top
)->domain
, domain
))
719 /* Can't use a binary search or else we found during the binary search that
720 we should also do a linear search. */
722 if (do_linear_search
)
724 for (psym
= start
; psym
< start
+ length
; psym
++)
726 if (symbol_matches_domain ((*psym
)->ginfo
.language (),
727 (*psym
)->domain
, domain
)
728 && symbol_matches_search_name (&(*psym
)->ginfo
, lookup_name
))
736 /* Get the symbol table that corresponds to a partial_symtab.
737 This is fast after the first time you do it.
738 The result will be NULL if the primary symtab has no symbols,
739 which can happen. Otherwise the result is the primary symtab
740 that contains PST. */
742 static struct compunit_symtab
*
743 psymtab_to_symtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
745 /* If it is a shared psymtab, find an unshared psymtab that includes
746 it. Any such psymtab will do. */
747 while (pst
->user
!= NULL
)
750 /* If it's been looked up before, return it. */
751 if (pst
->get_compunit_symtab (objfile
))
752 return pst
->get_compunit_symtab (objfile
);
754 /* If it has not yet been read in, read it. */
755 if (!pst
->readin_p (objfile
))
757 scoped_restore decrementer
= increment_reading_symtab ();
761 printf_filtered (_("Reading in symbols for %s...\n"),
763 gdb_flush (gdb_stdout
);
766 pst
->read_symtab (objfile
);
769 return pst
->get_compunit_symtab (objfile
);
772 /* Psymtab version of find_last_source_symtab. See its definition in
773 the definition of quick_symbol_functions in symfile.h. */
775 static struct symtab
*
776 psym_find_last_source_symtab (struct objfile
*ofp
)
778 struct partial_symtab
*cs_pst
= NULL
;
780 for (partial_symtab
*ps
: require_partial_symbols (ofp
, true))
782 const char *name
= ps
->filename
;
783 int len
= strlen (name
);
785 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
786 || strcmp (name
, "<<C++-namespaces>>") == 0)))
792 if (cs_pst
->readin_p (ofp
))
794 internal_error (__FILE__
, __LINE__
,
795 _("select_source_symtab: "
796 "readin pst found and no symtabs."));
800 struct compunit_symtab
*cust
= psymtab_to_symtab (ofp
, cs_pst
);
804 return compunit_primary_filetab (cust
);
810 /* Psymtab version of forget_cached_source_info. See its definition in
811 the definition of quick_symbol_functions in symfile.h. */
814 psym_forget_cached_source_info (struct objfile
*objfile
)
816 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
818 if (pst
->fullname
!= NULL
)
820 xfree (pst
->fullname
);
821 pst
->fullname
= NULL
;
827 print_partial_symbols (struct gdbarch
*gdbarch
, struct objfile
*objfile
,
828 struct partial_symbol
**p
, int count
, const char *what
,
829 struct ui_file
*outfile
)
831 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
835 fprintf_filtered (outfile
, " `%s'", (*p
)->ginfo
.linkage_name ());
836 if ((*p
)->ginfo
.demangled_name () != NULL
)
838 fprintf_filtered (outfile
, " `%s'",
839 (*p
)->ginfo
.demangled_name ());
841 fputs_filtered (", ", outfile
);
842 switch ((*p
)->domain
)
845 fputs_filtered ("undefined domain, ", outfile
);
848 /* This is the usual thing -- don't print it. */
851 fputs_filtered ("struct domain, ", outfile
);
854 fputs_filtered ("module domain, ", outfile
);
857 fputs_filtered ("label domain, ", outfile
);
859 case COMMON_BLOCK_DOMAIN
:
860 fputs_filtered ("common block domain, ", outfile
);
863 fputs_filtered ("<invalid domain>, ", outfile
);
866 switch ((*p
)->aclass
)
869 fputs_filtered ("undefined", outfile
);
872 fputs_filtered ("constant int", outfile
);
875 fputs_filtered ("static", outfile
);
878 fputs_filtered ("register", outfile
);
881 fputs_filtered ("pass by value", outfile
);
884 fputs_filtered ("pass by reference", outfile
);
886 case LOC_REGPARM_ADDR
:
887 fputs_filtered ("register address parameter", outfile
);
890 fputs_filtered ("stack parameter", outfile
);
893 fputs_filtered ("type", outfile
);
896 fputs_filtered ("label", outfile
);
899 fputs_filtered ("function", outfile
);
901 case LOC_CONST_BYTES
:
902 fputs_filtered ("constant bytes", outfile
);
905 fputs_filtered ("unresolved", outfile
);
907 case LOC_OPTIMIZED_OUT
:
908 fputs_filtered ("optimized out", outfile
);
911 fputs_filtered ("computed at runtime", outfile
);
914 fputs_filtered ("<invalid location>", outfile
);
917 fputs_filtered (", ", outfile
);
918 fputs_filtered (paddress (gdbarch
, (*p
)->unrelocated_address ()), outfile
);
919 fprintf_filtered (outfile
, "\n");
925 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
926 struct ui_file
*outfile
)
928 struct gdbarch
*gdbarch
= objfile
->arch ();
931 if (psymtab
->anonymous
)
933 fprintf_filtered (outfile
, "\nAnonymous partial symtab (%s) ",
938 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
941 fprintf_filtered (outfile
, "(object ");
942 gdb_print_host_address (psymtab
, outfile
);
943 fprintf_filtered (outfile
, ")\n\n");
944 fprintf_filtered (outfile
, " Read from object file %s (",
945 objfile_name (objfile
));
946 gdb_print_host_address (objfile
, outfile
);
947 fprintf_filtered (outfile
, ")\n");
949 if (psymtab
->readin_p (objfile
))
951 fprintf_filtered (outfile
,
952 " Full symtab was read (at ");
953 gdb_print_host_address (psymtab
->get_compunit_symtab (objfile
), outfile
);
954 fprintf_filtered (outfile
, ")\n");
957 fprintf_filtered (outfile
, " Symbols cover text addresses ");
958 fputs_filtered (paddress (gdbarch
, psymtab
->text_low (objfile
)), outfile
);
959 fprintf_filtered (outfile
, "-");
960 fputs_filtered (paddress (gdbarch
, psymtab
->text_high (objfile
)), outfile
);
961 fprintf_filtered (outfile
, "\n");
962 fprintf_filtered (outfile
, " Address map supported - %s.\n",
963 psymtab
->psymtabs_addrmap_supported
? "yes" : "no");
964 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
965 psymtab
->number_of_dependencies
);
966 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
968 fprintf_filtered (outfile
, " %d ", i
);
969 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
970 fprintf_filtered (outfile
, " %s\n",
971 psymtab
->dependencies
[i
]->filename
);
973 if (psymtab
->user
!= NULL
)
975 fprintf_filtered (outfile
, " Shared partial symtab with user ");
976 gdb_print_host_address (psymtab
->user
, outfile
);
977 fprintf_filtered (outfile
, "\n");
979 if (psymtab
->n_global_syms
> 0)
981 print_partial_symbols
983 &objfile
->partial_symtabs
->global_psymbols
[psymtab
->globals_offset
],
984 psymtab
->n_global_syms
, "Global", outfile
);
986 if (psymtab
->n_static_syms
> 0)
988 print_partial_symbols
990 &objfile
->partial_symtabs
->static_psymbols
[psymtab
->statics_offset
],
991 psymtab
->n_static_syms
, "Static", outfile
);
993 fprintf_filtered (outfile
, "\n");
996 /* Psymtab version of print_stats. See its definition in
997 the definition of quick_symbol_functions in symfile.h. */
1000 psym_print_stats (struct objfile
*objfile
)
1005 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1007 if (!ps
->readin_p (objfile
))
1010 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i
);
1013 /* Psymtab version of dump. See its definition in
1014 the definition of quick_symbol_functions in symfile.h. */
1017 psym_dump (struct objfile
*objfile
)
1019 struct partial_symtab
*psymtab
;
1021 if (objfile
->partial_symtabs
->psymtabs
)
1023 printf_filtered ("Psymtabs:\n");
1024 for (psymtab
= objfile
->partial_symtabs
->psymtabs
;
1026 psymtab
= psymtab
->next
)
1028 printf_filtered ("%s at ",
1030 gdb_print_host_address (psymtab
, gdb_stdout
);
1031 printf_filtered (", ");
1034 printf_filtered ("\n\n");
1038 /* Psymtab version of expand_symtabs_for_function. See its definition in
1039 the definition of quick_symbol_functions in symfile.h. */
1042 psym_expand_symtabs_for_function (struct objfile
*objfile
,
1043 const char *func_name
)
1045 lookup_name_info
base_lookup (func_name
, symbol_name_match_type::FULL
);
1046 lookup_name_info lookup_name
= base_lookup
.make_ignore_params ();
1048 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1050 if (ps
->readin_p (objfile
))
1053 if ((lookup_partial_symbol (objfile
, ps
, lookup_name
, 1, VAR_DOMAIN
)
1055 || (lookup_partial_symbol (objfile
, ps
, lookup_name
, 0, VAR_DOMAIN
)
1057 psymtab_to_symtab (objfile
, ps
);
1061 /* Psymtab version of expand_all_symtabs. See its definition in
1062 the definition of quick_symbol_functions in symfile.h. */
1065 psym_expand_all_symtabs (struct objfile
*objfile
)
1067 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
, true))
1068 psymtab_to_symtab (objfile
, psymtab
);
1071 /* Psymtab version of expand_symtabs_with_fullname. See its definition in
1072 the definition of quick_symbol_functions in symfile.h. */
1075 psym_expand_symtabs_with_fullname (struct objfile
*objfile
,
1076 const char *fullname
)
1078 for (partial_symtab
*p
: require_partial_symbols (objfile
, true))
1080 /* Anonymous psymtabs don't have a name of a source file. */
1084 /* psymtab_to_fullname tries to open the file which is slow.
1085 Don't call it if we know the basenames don't match. */
1086 if ((basenames_may_differ
1087 || filename_cmp (lbasename (fullname
), lbasename (p
->filename
)) == 0)
1088 && filename_cmp (fullname
, psymtab_to_fullname (p
)) == 0)
1089 psymtab_to_symtab (objfile
, p
);
1093 /* Psymtab version of map_symbol_filenames. See its definition in
1094 the definition of quick_symbol_functions in symfile.h. */
1097 psym_map_symbol_filenames (struct objfile
*objfile
,
1098 symbol_filename_ftype
*fun
, void *data
,
1101 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1103 const char *fullname
;
1105 if (ps
->readin_p (objfile
))
1108 /* We can skip shared psymtabs here, because any file name will be
1109 attached to the unshared psymtab. */
1110 if (ps
->user
!= NULL
)
1113 /* Anonymous psymtabs don't have a file name. */
1119 fullname
= psymtab_to_fullname (ps
);
1122 (*fun
) (ps
->filename
, fullname
, data
);
1126 /* Finds the fullname that a partial_symtab represents.
1128 If this functions finds the fullname, it will save it in ps->fullname
1129 and it will also return the value.
1131 If this function fails to find the file that this partial_symtab represents,
1132 NULL will be returned and ps->fullname will be set to NULL. */
1135 psymtab_to_fullname (struct partial_symtab
*ps
)
1137 gdb_assert (!ps
->anonymous
);
1139 /* Use cached copy if we have it.
1140 We rely on forget_cached_source_info being called appropriately
1141 to handle cases like the file being moved. */
1142 if (ps
->fullname
== NULL
)
1144 gdb::unique_xmalloc_ptr
<char> fullname
;
1145 scoped_fd fd
= find_and_open_source (ps
->filename
, ps
->dirname
,
1147 ps
->fullname
= fullname
.release ();
1151 /* rewrite_source_path would be applied by find_and_open_source, we
1152 should report the pathname where GDB tried to find the file. */
1154 if (ps
->dirname
== NULL
|| IS_ABSOLUTE_PATH (ps
->filename
))
1155 fullname
.reset (xstrdup (ps
->filename
));
1157 fullname
.reset (concat (ps
->dirname
, SLASH_STRING
,
1158 ps
->filename
, (char *) NULL
));
1160 ps
->fullname
= rewrite_source_path (fullname
.get ()).release ();
1161 if (ps
->fullname
== NULL
)
1162 ps
->fullname
= fullname
.release ();
1166 return ps
->fullname
;
1169 /* Psymtab version of map_matching_symbols. See its definition in
1170 the definition of quick_symbol_functions in symfile.h. */
1173 psym_map_matching_symbols
1174 (struct objfile
*objfile
,
1175 const lookup_name_info
&name
, domain_enum domain
,
1177 gdb::function_view
<symbol_found_callback_ftype
> callback
,
1178 symbol_compare_ftype
*ordered_compare
)
1180 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
1182 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1185 if (ps
->readin_p (objfile
)
1186 || match_partial_symbol (objfile
, ps
, global
, name
, domain
,
1189 struct compunit_symtab
*cust
= psymtab_to_symtab (objfile
, ps
);
1190 const struct block
*block
;
1194 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
1195 if (!iterate_over_symbols_terminated (block
, name
,
1202 /* A helper for psym_expand_symtabs_matching that handles searching
1203 included psymtabs. This returns true if a symbol is found, and
1204 false otherwise. It also updates the 'searched_flag' on the
1205 various psymtabs that it searches. */
1208 recursively_search_psymtabs
1209 (struct partial_symtab
*ps
,
1210 struct objfile
*objfile
,
1211 enum search_domain domain
,
1212 const lookup_name_info
&lookup_name
,
1213 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> sym_matcher
)
1216 enum psymtab_search_status result
= PST_SEARCHED_AND_NOT_FOUND
;
1219 if (ps
->searched_flag
!= PST_NOT_SEARCHED
)
1220 return ps
->searched_flag
== PST_SEARCHED_AND_FOUND
;
1222 /* Recurse into shared psymtabs first, because they may have already
1223 been searched, and this could save some time. */
1224 for (i
= 0; i
< ps
->number_of_dependencies
; ++i
)
1228 /* Skip non-shared dependencies, these are handled elsewhere. */
1229 if (ps
->dependencies
[i
]->user
== NULL
)
1232 r
= recursively_search_psymtabs (ps
->dependencies
[i
],
1233 objfile
, domain
, lookup_name
,
1237 ps
->searched_flag
= PST_SEARCHED_AND_FOUND
;
1242 partial_symbol
**gbound
1243 = (objfile
->partial_symtabs
->global_psymbols
.data ()
1244 + ps
->globals_offset
+ ps
->n_global_syms
);
1245 partial_symbol
**sbound
1246 = (objfile
->partial_symtabs
->static_psymbols
.data ()
1247 + ps
->statics_offset
+ ps
->n_static_syms
);
1248 partial_symbol
**bound
= gbound
;
1250 /* Go through all of the symbols stored in a partial
1251 symtab in one loop. */
1252 partial_symbol
**psym
= (objfile
->partial_symtabs
->global_psymbols
.data ()
1253 + ps
->globals_offset
);
1258 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
1260 psym
= (objfile
->partial_symtabs
->static_psymbols
.data ()
1261 + ps
->statics_offset
);
1272 if ((domain
== ALL_DOMAIN
1273 || (domain
== MODULES_DOMAIN
1274 && (*psym
)->domain
== MODULE_DOMAIN
)
1275 || (domain
== VARIABLES_DOMAIN
1276 && (*psym
)->aclass
!= LOC_TYPEDEF
1277 && (*psym
)->aclass
!= LOC_BLOCK
)
1278 || (domain
== FUNCTIONS_DOMAIN
1279 && (*psym
)->aclass
== LOC_BLOCK
)
1280 || (domain
== TYPES_DOMAIN
1281 && (*psym
)->aclass
== LOC_TYPEDEF
))
1282 && psymbol_name_matches (*psym
, lookup_name
)
1283 && (sym_matcher
== NULL
1284 || sym_matcher ((*psym
)->ginfo
.search_name ())))
1286 /* Found a match, so notify our caller. */
1287 result
= PST_SEARCHED_AND_FOUND
;
1294 ps
->searched_flag
= result
;
1295 return result
== PST_SEARCHED_AND_FOUND
;
1298 /* Psymtab version of expand_symtabs_matching. See its definition in
1299 the definition of quick_symbol_functions in symfile.h. */
1302 psym_expand_symtabs_matching
1303 (struct objfile
*objfile
,
1304 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
1305 const lookup_name_info
*lookup_name
,
1306 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
1307 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
1308 enum search_domain domain
)
1310 /* Clear the search flags. */
1311 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1312 ps
->searched_flag
= PST_NOT_SEARCHED
;
1314 for (partial_symtab
*ps
: objfile
->psymtabs ())
1318 if (ps
->readin_p (objfile
))
1321 /* We skip shared psymtabs because file-matching doesn't apply
1322 to them; but we search them later in the loop. */
1323 if (ps
->user
!= NULL
)
1333 match
= file_matcher (ps
->filename
, false);
1336 /* Before we invoke realpath, which can get expensive when many
1337 files are involved, do a quick comparison of the basenames. */
1338 if (basenames_may_differ
1339 || file_matcher (lbasename (ps
->filename
), true))
1340 match
= file_matcher (psymtab_to_fullname (ps
), false);
1346 if ((symbol_matcher
== NULL
&& lookup_name
== NULL
)
1347 || recursively_search_psymtabs (ps
, objfile
, domain
,
1348 lookup_name
->make_ignore_params (),
1351 struct compunit_symtab
*symtab
=
1352 psymtab_to_symtab (objfile
, ps
);
1354 if (expansion_notify
!= NULL
)
1355 expansion_notify (symtab
);
1360 /* Psymtab version of has_symbols. See its definition in
1361 the definition of quick_symbol_functions in symfile.h. */
1364 psym_has_symbols (struct objfile
*objfile
)
1366 return objfile
->partial_symtabs
->psymtabs
!= NULL
;
1369 /* Helper function for psym_find_compunit_symtab_by_address that fills
1370 in psymbol_map for a given range of psymbols. */
1373 psym_fill_psymbol_map (struct objfile
*objfile
,
1374 struct partial_symtab
*psymtab
,
1375 std::set
<CORE_ADDR
> *seen_addrs
,
1376 const std::vector
<partial_symbol
*> &symbols
,
1380 for (int i
= 0; i
< length
; ++i
)
1382 struct partial_symbol
*psym
= symbols
[start
+ i
];
1384 if (psym
->aclass
== LOC_STATIC
)
1386 CORE_ADDR addr
= psym
->address (objfile
);
1387 if (seen_addrs
->find (addr
) == seen_addrs
->end ())
1389 seen_addrs
->insert (addr
);
1390 objfile
->psymbol_map
.emplace_back (addr
, psymtab
);
1396 /* See find_compunit_symtab_by_address in quick_symbol_functions, in
1399 static compunit_symtab
*
1400 psym_find_compunit_symtab_by_address (struct objfile
*objfile
,
1403 if (objfile
->psymbol_map
.empty ())
1405 std::set
<CORE_ADDR
> seen_addrs
;
1407 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
1409 psym_fill_psymbol_map (objfile
, pst
,
1411 objfile
->partial_symtabs
->global_psymbols
,
1412 pst
->globals_offset
,
1413 pst
->n_global_syms
);
1414 psym_fill_psymbol_map (objfile
, pst
,
1416 objfile
->partial_symtabs
->static_psymbols
,
1417 pst
->statics_offset
,
1418 pst
->n_static_syms
);
1421 objfile
->psymbol_map
.shrink_to_fit ();
1423 std::sort (objfile
->psymbol_map
.begin (), objfile
->psymbol_map
.end (),
1424 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1425 const std::pair
<CORE_ADDR
, partial_symtab
*> &b
)
1427 return a
.first
< b
.first
;
1431 auto iter
= std::lower_bound
1432 (objfile
->psymbol_map
.begin (), objfile
->psymbol_map
.end (), address
,
1433 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1439 if (iter
== objfile
->psymbol_map
.end () || iter
->first
!= address
)
1442 return psymtab_to_symtab (objfile
, iter
->second
);
1445 const struct quick_symbol_functions psym_functions
=
1448 psym_find_last_source_symtab
,
1449 psym_forget_cached_source_info
,
1450 psym_map_symtabs_matching_filename
,
1452 psym_lookup_global_symbol_language
,
1455 psym_expand_symtabs_for_function
,
1456 psym_expand_all_symtabs
,
1457 psym_expand_symtabs_with_fullname
,
1458 psym_map_matching_symbols
,
1459 psym_expand_symtabs_matching
,
1460 psym_find_pc_sect_compunit_symtab
,
1461 psym_find_compunit_symtab_by_address
,
1462 psym_map_symbol_filenames
1468 sort_pst_symbols (struct objfile
*objfile
, struct partial_symtab
*pst
)
1470 /* Sort the global list; don't sort the static list. */
1471 auto begin
= objfile
->partial_symtabs
->global_psymbols
.begin ();
1472 std::advance (begin
, pst
->globals_offset
);
1474 /* The psymbols for this partial_symtab are currently at the end of the
1476 auto end
= objfile
->partial_symtabs
->global_psymbols
.end ();
1478 std::sort (begin
, end
, [] (partial_symbol
*s1
, partial_symbol
*s2
)
1480 return strcmp_iw_ordered (s1
->ginfo
.search_name (),
1481 s2
->ginfo
.search_name ()) < 0;
1485 /* Partially fill a partial symtab. It will be completely filled at
1486 the end of the symbol list. */
1488 partial_symtab::partial_symtab (const char *filename
,
1489 struct objfile
*objfile
,
1491 : partial_symtab (filename
, objfile
)
1493 set_text_low (textlow
);
1494 set_text_high (raw_text_low ()); /* default */
1496 auto *v1
= new std::vector
<partial_symbol
*>;
1497 objfile
->partial_symtabs
->current_global_psymbols
.push_back (v1
);
1498 auto *v2
= new std::vector
<partial_symbol
*>;
1499 objfile
->partial_symtabs
->current_static_psymbols
.push_back (v2
);
1502 /* Concat vectors V1 and V2. */
1505 concat (std::vector
<partial_symbol
*> *v1
, std::vector
<partial_symbol
*> *v2
)
1507 v1
->insert (v1
->end (), v2
->begin (), v2
->end ());
1511 /* Perform "finishing up" operations of a partial symtab. */
1514 end_psymtab_common (struct objfile
*objfile
, struct partial_symtab
*pst
)
1516 pst
->globals_offset
= objfile
->partial_symtabs
->global_psymbols
.size ();
1517 pst
->statics_offset
= objfile
->partial_symtabs
->static_psymbols
.size ();
1519 auto *current_global_psymbols
1520 = objfile
->partial_symtabs
->current_global_psymbols
.back ();
1521 auto *current_static_psymbols
1522 = objfile
->partial_symtabs
->current_static_psymbols
.back ();
1523 objfile
->partial_symtabs
->current_global_psymbols
.pop_back ();
1524 objfile
->partial_symtabs
->current_static_psymbols
.pop_back ();
1527 = current_global_psymbols
->size ();
1529 = current_static_psymbols
->size ();
1531 concat (&objfile
->partial_symtabs
->global_psymbols
, current_global_psymbols
);
1532 concat (&objfile
->partial_symtabs
->static_psymbols
, current_static_psymbols
);
1534 delete current_global_psymbols
;
1535 delete current_static_psymbols
;
1537 sort_pst_symbols (objfile
, pst
);
1540 /* Calculate a hash code for the given partial symbol. The hash is
1541 calculated using the symbol's value, language, domain, class
1542 and name. These are the values which are set by
1543 add_psymbol_to_bcache. */
1545 static unsigned long
1546 psymbol_hash (const void *addr
, int length
)
1548 unsigned long h
= 0;
1549 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1550 unsigned int lang
= psymbol
->ginfo
.language ();
1551 unsigned int domain
= psymbol
->domain
;
1552 unsigned int theclass
= psymbol
->aclass
;
1554 h
= fast_hash (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1555 h
= fast_hash (&lang
, sizeof (unsigned int), h
);
1556 h
= fast_hash (&domain
, sizeof (unsigned int), h
);
1557 h
= fast_hash (&theclass
, sizeof (unsigned int), h
);
1558 /* Note that psymbol names are interned via compute_and_set_names, so
1559 there's no need to hash the contents of the name here. */
1560 h
= fast_hash (&psymbol
->ginfo
.m_name
, sizeof (psymbol
->ginfo
.m_name
), h
);
1565 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1566 For the comparison this function uses a symbols value,
1567 language, domain, class and name. */
1570 psymbol_compare (const void *addr1
, const void *addr2
, int length
)
1572 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1573 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1575 return (memcmp (&sym1
->ginfo
.value
, &sym2
->ginfo
.value
,
1576 sizeof (sym1
->ginfo
.value
)) == 0
1577 && sym1
->ginfo
.language () == sym2
->ginfo
.language ()
1578 && sym1
->domain
== sym2
->domain
1579 && sym1
->aclass
== sym2
->aclass
1580 /* Note that psymbol names are interned via
1581 compute_and_set_names, so there's no need to compare the
1582 contents of the name here. */
1583 && sym1
->ginfo
.linkage_name () == sym2
->ginfo
.linkage_name ());
1586 /* Helper function, initialises partial symbol structure and stashes
1587 it into objfile's bcache. Note that our caching mechanism will
1588 use all fields of struct partial_symbol to determine hash value of the
1589 structure. In other words, having two symbols with the same name but
1590 different domain (or address) is possible and correct. */
1592 static struct partial_symbol
*
1593 add_psymbol_to_bcache (const partial_symbol
&psymbol
, struct objfile
*objfile
,
1596 /* Stash the partial symbol away in the cache. */
1597 return ((struct partial_symbol
*)
1598 objfile
->partial_symtabs
->psymbol_cache
.insert
1599 (&psymbol
, sizeof (struct partial_symbol
), added
));
1602 /* Helper function, adds partial symbol to the given partial symbol list. */
1605 append_psymbol_to_list (std::vector
<partial_symbol
*> *list
,
1606 struct partial_symbol
*psym
,
1607 struct objfile
*objfile
)
1609 list
->push_back (psym
);
1610 OBJSTAT (objfile
, n_psyms
++);
1613 /* See psympriv.h. */
1616 add_psymbol_to_list (const partial_symbol
&psymbol
,
1617 psymbol_placement where
,
1618 struct objfile
*objfile
)
1622 /* Stash the partial symbol away in the cache. */
1623 partial_symbol
*psym
= add_psymbol_to_bcache (psymbol
, objfile
, &added
);
1625 /* Do not duplicate global partial symbols. */
1626 if (where
== psymbol_placement::GLOBAL
&& !added
)
1629 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1630 std::vector
<partial_symbol
*> *list
1631 = (where
== psymbol_placement::STATIC
1632 ? objfile
->partial_symtabs
->current_static_psymbols
.back ()
1633 : objfile
->partial_symtabs
->current_global_psymbols
.back ());
1634 append_psymbol_to_list (list
, psym
, objfile
);
1637 /* See psympriv.h. */
1640 add_psymbol_to_list (gdb::string_view name
, bool copy_name
,
1642 enum address_class theclass
,
1644 psymbol_placement where
,
1646 enum language language
, struct objfile
*objfile
)
1648 struct partial_symbol psymbol
;
1649 memset (&psymbol
, 0, sizeof (psymbol
));
1651 psymbol
.set_unrelocated_address (coreaddr
);
1652 psymbol
.ginfo
.section
= section
;
1653 psymbol
.domain
= domain
;
1654 psymbol
.aclass
= theclass
;
1655 psymbol
.ginfo
.set_language (language
, objfile
->partial_symtabs
->obstack ());
1656 psymbol
.ginfo
.compute_and_set_names (name
, copy_name
, objfile
->per_bfd
);
1658 add_psymbol_to_list (psymbol
, where
, objfile
);
1661 /* See psympriv.h. */
1664 init_psymbol_list (struct objfile
*objfile
, int total_symbols
)
1666 if (objfile
->partial_symtabs
->global_psymbols
.capacity () == 0
1667 && objfile
->partial_symtabs
->static_psymbols
.capacity () == 0)
1669 /* Current best guess is that approximately a twentieth of the
1670 total symbols (in a debugging file) are global or static
1671 oriented symbols, then multiply that by slop factor of
1673 objfile
->partial_symtabs
->global_psymbols
.reserve (total_symbols
/ 10);
1674 objfile
->partial_symtabs
->static_psymbols
.reserve (total_symbols
/ 10);
1678 /* See psympriv.h. */
1680 partial_symtab::partial_symtab (const char *filename_
, struct objfile
*objfile
)
1681 : searched_flag (PST_NOT_SEARCHED
),
1685 objfile
->partial_symtabs
->install_psymtab (this);
1687 filename
= objfile
->intern (filename_
);
1689 if (symtab_create_debug
)
1691 /* Be a bit clever with debugging messages, and don't print objfile
1692 every time, only when it changes. */
1693 static char *last_objfile_name
= NULL
;
1695 if (last_objfile_name
== NULL
1696 || strcmp (last_objfile_name
, objfile_name (objfile
)) != 0)
1698 xfree (last_objfile_name
);
1699 last_objfile_name
= xstrdup (objfile_name (objfile
));
1700 fprintf_filtered (gdb_stdlog
,
1701 "Creating one or more psymtabs for objfile %s ...\n",
1704 fprintf_filtered (gdb_stdlog
,
1705 "Created psymtab %s for module %s.\n",
1706 host_address_to_string (this), filename
);
1710 /* See psympriv.h. */
1713 partial_symtab::expand_dependencies (struct objfile
*objfile
)
1715 for (int i
= 0; i
< number_of_dependencies
; ++i
)
1717 if (!dependencies
[i
]->readin_p (objfile
)
1718 && dependencies
[i
]->user
== NULL
)
1720 /* Inform about additional files to be read in. */
1723 fputs_filtered (" ", gdb_stdout
);
1725 fputs_filtered ("and ", gdb_stdout
);
1727 printf_filtered ("%s...", dependencies
[i
]->filename
);
1728 wrap_here (""); /* Flush output */
1729 gdb_flush (gdb_stdout
);
1731 dependencies
[i
]->expand_psymtab (objfile
);
1738 psymtab_storage::discard_psymtab (struct partial_symtab
*pst
)
1740 struct partial_symtab
**prev_pst
;
1743 Empty psymtabs happen as a result of header files which don't
1744 have any symbols in them. There can be a lot of them. But this
1745 check is wrong, in that a psymtab with N_SLINE entries but
1746 nothing else is not empty, but we don't realize that. Fixing
1747 that without slowing things down might be tricky. */
1749 /* First, snip it out of the psymtab chain. */
1751 prev_pst
= &psymtabs
;
1752 while ((*prev_pst
) != pst
)
1753 prev_pst
= &((*prev_pst
)->next
);
1754 (*prev_pst
) = pst
->next
;
1760 /* We need to pass a couple of items to the addrmap_foreach function,
1763 struct dump_psymtab_addrmap_data
1765 struct objfile
*objfile
;
1766 struct partial_symtab
*psymtab
;
1767 struct ui_file
*outfile
;
1769 /* Non-zero if the previously printed addrmap entry was for PSYMTAB.
1770 If so, we want to print the next one as well (since the next addrmap
1771 entry defines the end of the range). */
1772 int previous_matched
;
1775 /* Helper function for dump_psymtab_addrmap to print an addrmap entry. */
1778 dump_psymtab_addrmap_1 (void *datap
, CORE_ADDR start_addr
, void *obj
)
1780 struct dump_psymtab_addrmap_data
*data
1781 = (struct dump_psymtab_addrmap_data
*) datap
;
1782 struct gdbarch
*gdbarch
= data
->objfile
->arch ();
1783 struct partial_symtab
*addrmap_psymtab
= (struct partial_symtab
*) obj
;
1784 const char *psymtab_address_or_end
= NULL
;
1788 if (data
->psymtab
== NULL
1789 || data
->psymtab
== addrmap_psymtab
)
1790 psymtab_address_or_end
= host_address_to_string (addrmap_psymtab
);
1791 else if (data
->previous_matched
)
1792 psymtab_address_or_end
= "<ends here>";
1794 if (data
->psymtab
== NULL
1795 || data
->psymtab
== addrmap_psymtab
1796 || data
->previous_matched
)
1798 fprintf_filtered (data
->outfile
, " %s%s %s\n",
1799 data
->psymtab
!= NULL
? " " : "",
1800 paddress (gdbarch
, start_addr
),
1801 psymtab_address_or_end
);
1804 data
->previous_matched
= (data
->psymtab
== NULL
1805 || data
->psymtab
== addrmap_psymtab
);
1810 /* Helper function for maintenance_print_psymbols to print the addrmap
1811 of PSYMTAB. If PSYMTAB is NULL print the entire addrmap. */
1814 dump_psymtab_addrmap (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
1815 struct ui_file
*outfile
)
1817 struct dump_psymtab_addrmap_data addrmap_dump_data
;
1819 if ((psymtab
== NULL
1820 || psymtab
->psymtabs_addrmap_supported
)
1821 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
1823 addrmap_dump_data
.objfile
= objfile
;
1824 addrmap_dump_data
.psymtab
= psymtab
;
1825 addrmap_dump_data
.outfile
= outfile
;
1826 addrmap_dump_data
.previous_matched
= 0;
1827 fprintf_filtered (outfile
, "%sddress map:\n",
1828 psymtab
== NULL
? "Entire a" : " A");
1829 addrmap_foreach (objfile
->partial_symtabs
->psymtabs_addrmap
,
1830 dump_psymtab_addrmap_1
, &addrmap_dump_data
);
1835 maintenance_print_psymbols (const char *args
, int from_tty
)
1837 struct ui_file
*outfile
= gdb_stdout
;
1838 char *address_arg
= NULL
, *source_arg
= NULL
, *objfile_arg
= NULL
;
1839 int i
, outfile_idx
, found
;
1841 struct obj_section
*section
= NULL
;
1845 gdb_argv
argv (args
);
1847 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
1849 if (strcmp (argv
[i
], "-pc") == 0)
1851 if (argv
[i
+ 1] == NULL
)
1852 error (_("Missing pc value"));
1853 address_arg
= argv
[++i
];
1855 else if (strcmp (argv
[i
], "-source") == 0)
1857 if (argv
[i
+ 1] == NULL
)
1858 error (_("Missing source file"));
1859 source_arg
= argv
[++i
];
1861 else if (strcmp (argv
[i
], "-objfile") == 0)
1863 if (argv
[i
+ 1] == NULL
)
1864 error (_("Missing objfile name"));
1865 objfile_arg
= argv
[++i
];
1867 else if (strcmp (argv
[i
], "--") == 0)
1869 /* End of options. */
1873 else if (argv
[i
][0] == '-')
1875 /* Future proofing: Don't allow OUTFILE to begin with "-". */
1876 error (_("Unknown option: %s"), argv
[i
]);
1883 if (address_arg
!= NULL
&& source_arg
!= NULL
)
1884 error (_("Must specify at most one of -pc and -source"));
1886 stdio_file arg_outfile
;
1888 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
1890 if (argv
[outfile_idx
+ 1] != NULL
)
1891 error (_("Junk at end of command"));
1892 gdb::unique_xmalloc_ptr
<char> outfile_name
1893 (tilde_expand (argv
[outfile_idx
]));
1894 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
1895 perror_with_name (outfile_name
.get ());
1896 outfile
= &arg_outfile
;
1899 if (address_arg
!= NULL
)
1901 pc
= parse_and_eval_address (address_arg
);
1902 /* If we fail to find a section, that's ok, try the lookup anyway. */
1903 section
= find_pc_section (pc
);
1907 for (objfile
*objfile
: current_program_space
->objfiles ())
1909 int printed_objfile_header
= 0;
1910 int print_for_objfile
= 1;
1913 if (objfile_arg
!= NULL
)
1915 = compare_filenames_for_search (objfile_name (objfile
),
1917 if (!print_for_objfile
)
1920 if (address_arg
!= NULL
)
1922 struct bound_minimal_symbol msymbol
= { NULL
, NULL
};
1924 /* We don't assume each pc has a unique objfile (this is for
1926 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
,
1930 if (!printed_objfile_header
)
1932 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1933 objfile_name (objfile
));
1934 printed_objfile_header
= 1;
1936 dump_psymtab (objfile
, ps
, outfile
);
1937 dump_psymtab_addrmap (objfile
, ps
, outfile
);
1943 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1945 int print_for_source
= 0;
1948 if (source_arg
!= NULL
)
1951 = compare_filenames_for_search (ps
->filename
, source_arg
);
1954 if (source_arg
== NULL
1955 || print_for_source
)
1957 if (!printed_objfile_header
)
1959 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1960 objfile_name (objfile
));
1961 printed_objfile_header
= 1;
1963 dump_psymtab (objfile
, ps
, outfile
);
1964 dump_psymtab_addrmap (objfile
, ps
, outfile
);
1969 /* If we're printing all the objfile's symbols dump the full addrmap. */
1971 if (address_arg
== NULL
1972 && source_arg
== NULL
1973 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
1975 outfile
->puts ("\n");
1976 dump_psymtab_addrmap (objfile
, NULL
, outfile
);
1982 if (address_arg
!= NULL
)
1983 error (_("No partial symtab for address: %s"), address_arg
);
1984 if (source_arg
!= NULL
)
1985 error (_("No partial symtab for source file: %s"), source_arg
);
1989 /* List all the partial symbol tables whose names match REGEXP (optional). */
1992 maintenance_info_psymtabs (const char *regexp
, int from_tty
)
1997 for (struct program_space
*pspace
: program_spaces
)
1998 for (objfile
*objfile
: pspace
->objfiles ())
2000 struct gdbarch
*gdbarch
= objfile
->arch ();
2002 /* We don't want to print anything for this objfile until we
2003 actually find a symtab whose name matches. */
2004 int printed_objfile_start
= 0;
2006 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
, true))
2011 || re_exec (psymtab
->filename
))
2013 if (! printed_objfile_start
)
2015 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
2017 printf_filtered ("((struct objfile *) %s)\n",
2018 host_address_to_string (objfile
));
2019 printed_objfile_start
= 1;
2022 printf_filtered (" { psymtab %s ", psymtab
->filename
);
2024 printf_filtered ("((struct partial_symtab *) %s)\n",
2025 host_address_to_string (psymtab
));
2027 printf_filtered (" readin %s\n",
2028 psymtab
->readin_p (objfile
) ? "yes" : "no");
2029 printf_filtered (" fullname %s\n",
2031 ? psymtab
->fullname
: "(null)");
2032 printf_filtered (" text addresses ");
2033 fputs_filtered (paddress (gdbarch
,
2034 psymtab
->text_low (objfile
)),
2036 printf_filtered (" -- ");
2037 fputs_filtered (paddress (gdbarch
,
2038 psymtab
->text_high (objfile
)),
2040 printf_filtered ("\n");
2041 printf_filtered (" psymtabs_addrmap_supported %s\n",
2042 (psymtab
->psymtabs_addrmap_supported
2044 printf_filtered (" globals ");
2045 if (psymtab
->n_global_syms
)
2047 auto p
= &(objfile
->partial_symtabs
2048 ->global_psymbols
[psymtab
->globals_offset
]);
2051 ("(* (struct partial_symbol **) %s @ %d)\n",
2052 host_address_to_string (p
),
2053 psymtab
->n_global_syms
);
2056 printf_filtered ("(none)\n");
2057 printf_filtered (" statics ");
2058 if (psymtab
->n_static_syms
)
2060 auto p
= &(objfile
->partial_symtabs
2061 ->static_psymbols
[psymtab
->statics_offset
]);
2064 ("(* (struct partial_symbol **) %s @ %d)\n",
2065 host_address_to_string (p
),
2066 psymtab
->n_static_syms
);
2069 printf_filtered ("(none)\n");
2071 printf_filtered (" user %s "
2072 "((struct partial_symtab *) %s)\n",
2073 psymtab
->user
->filename
,
2074 host_address_to_string (psymtab
->user
));
2075 printf_filtered (" dependencies ");
2076 if (psymtab
->number_of_dependencies
)
2080 printf_filtered ("{\n");
2081 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
2083 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
2085 /* Note the string concatenation there --- no
2087 printf_filtered (" psymtab %s "
2088 "((struct partial_symtab *) %s)\n",
2090 host_address_to_string (dep
));
2092 printf_filtered (" }\n");
2095 printf_filtered ("(none)\n");
2096 printf_filtered (" }\n");
2100 if (printed_objfile_start
)
2101 printf_filtered ("}\n");
2105 /* Check consistency of currently expanded psymtabs vs symtabs. */
2108 maintenance_check_psymtabs (const char *ignore
, int from_tty
)
2111 struct compunit_symtab
*cust
= NULL
;
2112 const struct blockvector
*bv
;
2113 const struct block
*b
;
2116 for (objfile
*objfile
: current_program_space
->objfiles ())
2117 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
2119 struct gdbarch
*gdbarch
= objfile
->arch ();
2121 /* We don't call psymtab_to_symtab here because that may cause symtab
2122 expansion. When debugging a problem it helps if checkers leave
2123 things unchanged. */
2124 cust
= ps
->get_compunit_symtab (objfile
);
2126 /* First do some checks that don't require the associated symtab. */
2127 if (ps
->text_high (objfile
) < ps
->text_low (objfile
))
2129 printf_filtered ("Psymtab ");
2130 puts_filtered (ps
->filename
);
2131 printf_filtered (" covers bad range ");
2132 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
2134 printf_filtered (" - ");
2135 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
2137 printf_filtered ("\n");
2141 /* Now do checks requiring the associated symtab. */
2144 bv
= COMPUNIT_BLOCKVECTOR (cust
);
2145 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
2146 partial_symbol
**psym
2147 = &objfile
->partial_symtabs
->static_psymbols
[ps
->statics_offset
];
2148 for (i
= 0; i
< ps
->n_static_syms
; psym
++, i
++)
2150 /* Skip symbols for inlined functions without address. These may
2151 or may not have a match in the full symtab. */
2152 if ((*psym
)->aclass
== LOC_BLOCK
2153 && (*psym
)->ginfo
.value
.address
== 0)
2156 sym
= block_lookup_symbol (b
, (*psym
)->ginfo
.search_name (),
2157 symbol_name_match_type::SEARCH_NAME
,
2161 printf_filtered ("Static symbol `");
2162 puts_filtered ((*psym
)->ginfo
.linkage_name ());
2163 printf_filtered ("' only found in ");
2164 puts_filtered (ps
->filename
);
2165 printf_filtered (" psymtab\n");
2168 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2169 psym
= &objfile
->partial_symtabs
->global_psymbols
[ps
->globals_offset
];
2170 for (i
= 0; i
< ps
->n_global_syms
; psym
++, i
++)
2172 sym
= block_lookup_symbol (b
, (*psym
)->ginfo
.search_name (),
2173 symbol_name_match_type::SEARCH_NAME
,
2177 printf_filtered ("Global symbol `");
2178 puts_filtered ((*psym
)->ginfo
.linkage_name ());
2179 printf_filtered ("' only found in ");
2180 puts_filtered (ps
->filename
);
2181 printf_filtered (" psymtab\n");
2184 if (ps
->raw_text_high () != 0
2185 && (ps
->text_low (objfile
) < BLOCK_START (b
)
2186 || ps
->text_high (objfile
) > BLOCK_END (b
)))
2188 printf_filtered ("Psymtab ");
2189 puts_filtered (ps
->filename
);
2190 printf_filtered (" covers ");
2191 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
2193 printf_filtered (" - ");
2194 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
2196 printf_filtered (" but symtab covers only ");
2197 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
2198 printf_filtered (" - ");
2199 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
2200 printf_filtered ("\n");
2205 void _initialize_psymtab ();
2207 _initialize_psymtab ()
2209 add_cmd ("psymbols", class_maintenance
, maintenance_print_psymbols
, _("\
2210 Print dump of current partial symbol definitions.\n\
2211 Usage: mt print psymbols [-objfile OBJFILE] [-pc ADDRESS] [--] [OUTFILE]\n\
2212 mt print psymbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
2213 Entries in the partial symbol table are dumped to file OUTFILE,\n\
2214 or the terminal if OUTFILE is unspecified.\n\
2215 If ADDRESS is provided, dump only the file for that address.\n\
2216 If SOURCE is provided, dump only that file's symbols.\n\
2217 If OBJFILE is provided, dump only that file's minimal symbols."),
2218 &maintenanceprintlist
);
2220 add_cmd ("psymtabs", class_maintenance
, maintenance_info_psymtabs
, _("\
2221 List the partial symbol tables for all object files.\n\
2222 This does not include information about individual partial symbols,\n\
2223 just the symbol table structures themselves."),
2224 &maintenanceinfolist
);
2226 add_cmd ("check-psymtabs", class_maintenance
, maintenance_check_psymtabs
,
2228 Check consistency of currently expanded psymtabs versus symtabs."),