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
*,
45 static const char *psymtab_to_fullname (struct partial_symtab
*ps
);
47 static struct partial_symbol
*find_pc_sect_psymbol (struct objfile
*,
48 struct partial_symtab
*,
50 struct obj_section
*);
52 static struct compunit_symtab
*psymtab_to_symtab (struct objfile
*objfile
,
53 struct partial_symtab
*pst
);
57 static unsigned long psymbol_hash (const void *addr
, int length
);
58 static int psymbol_compare (const void *addr1
, const void *addr2
, int length
);
60 psymtab_storage::psymtab_storage ()
61 : psymbol_cache (psymbol_hash
, psymbol_compare
)
65 psymtab_storage::~psymtab_storage ()
67 partial_symtab
*iter
= psymtabs
;
68 while (iter
!= nullptr)
70 partial_symtab
*next
= iter
->next
;
79 psymtab_storage::install_psymtab (partial_symtab
*pst
)
89 psymtab_storage::partial_symtab_range
90 require_partial_symbols (struct objfile
*objfile
, bool verbose
)
92 if ((objfile
->flags
& OBJF_PSYMTABS_READ
) == 0)
94 objfile
->flags
|= OBJF_PSYMTABS_READ
;
96 if (objfile
->sf
->sym_read_psymbols
)
99 printf_filtered (_("Reading symbols from %s...\n"),
100 objfile_name (objfile
));
101 (*objfile
->sf
->sym_read_psymbols
) (objfile
);
103 /* Partial symbols list are not expected to changed after this
105 objfile
->partial_symtabs
->global_psymbols
.shrink_to_fit ();
106 objfile
->partial_symtabs
->static_psymbols
.shrink_to_fit ();
108 if (verbose
&& !objfile_has_symbols (objfile
))
109 printf_filtered (_("(No debugging symbols found in %s)\n"),
110 objfile_name (objfile
));
114 return objfile
->psymtabs ();
117 /* Helper function for psym_map_symtabs_matching_filename that
118 expands the symtabs and calls the iterator. */
121 partial_map_expand_apply (struct objfile
*objfile
,
123 const char *real_path
,
124 struct partial_symtab
*pst
,
125 gdb::function_view
<bool (symtab
*)> callback
)
127 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
129 /* Shared psymtabs should never be seen here. Instead they should
130 be handled properly by the caller. */
131 gdb_assert (pst
->user
== NULL
);
133 /* Don't visit already-expanded psymtabs. */
134 if (pst
->readin_p ())
137 /* This may expand more than one symtab, and we want to iterate over
139 psymtab_to_symtab (objfile
, pst
);
141 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
142 last_made
, callback
);
145 /* Psymtab version of map_symtabs_matching_filename. See its definition in
146 the definition of quick_symbol_functions in symfile.h. */
149 psym_map_symtabs_matching_filename
150 (struct objfile
*objfile
,
152 const char *real_path
,
153 gdb::function_view
<bool (symtab
*)> callback
)
155 const char *name_basename
= lbasename (name
);
157 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
159 /* We can skip shared psymtabs here, because any file name will be
160 attached to the unshared psymtab. */
161 if (pst
->user
!= NULL
)
164 /* Anonymous psymtabs don't have a file name. */
168 if (compare_filenames_for_search (pst
->filename
, name
))
170 if (partial_map_expand_apply (objfile
, name
, real_path
,
176 /* Before we invoke realpath, which can get expensive when many
177 files are involved, do a quick comparison of the basenames. */
178 if (! basenames_may_differ
179 && FILENAME_CMP (name_basename
, lbasename (pst
->filename
)) != 0)
182 if (compare_filenames_for_search (psymtab_to_fullname (pst
), name
))
184 if (partial_map_expand_apply (objfile
, name
, real_path
,
190 /* If the user gave us an absolute path, try to find the file in
191 this symtab and use its absolute path. */
192 if (real_path
!= NULL
)
194 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
195 gdb_assert (IS_ABSOLUTE_PATH (name
));
196 if (filename_cmp (psymtab_to_fullname (pst
), real_path
) == 0)
198 if (partial_map_expand_apply (objfile
, name
, real_path
,
209 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
210 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
212 static struct partial_symtab
*
213 find_pc_sect_psymtab_closer (struct objfile
*objfile
,
214 CORE_ADDR pc
, struct obj_section
*section
,
215 struct partial_symtab
*pst
,
216 struct bound_minimal_symbol msymbol
)
218 struct partial_symtab
*tpst
;
219 struct partial_symtab
*best_pst
= pst
;
220 CORE_ADDR best_addr
= pst
->text_low (objfile
);
222 gdb_assert (!pst
->psymtabs_addrmap_supported
);
224 /* An objfile that has its functions reordered might have
225 many partial symbol tables containing the PC, but
226 we want the partial symbol table that contains the
227 function containing the PC. */
228 if (!(objfile
->flags
& OBJF_REORDERED
)
229 && section
== NULL
) /* Can't validate section this way. */
232 if (msymbol
.minsym
== NULL
)
235 /* The code range of partial symtabs sometimes overlap, so, in
236 the loop below, we need to check all partial symtabs and
237 find the one that fits better for the given PC address. We
238 select the partial symtab that contains a symbol whose
239 address is closest to the PC address. By closest we mean
240 that find_pc_sect_symbol returns the symbol with address
241 that is closest and still less than the given PC. */
242 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
244 if (pc
>= tpst
->text_low (objfile
) && pc
< tpst
->text_high (objfile
))
246 struct partial_symbol
*p
;
249 /* NOTE: This assumes that every psymbol has a
250 corresponding msymbol, which is not necessarily
251 true; the debug info might be much richer than the
252 object's symbol table. */
253 p
= find_pc_sect_psymbol (objfile
, tpst
, pc
, section
);
255 && (p
->address (objfile
) == BMSYMBOL_VALUE_ADDRESS (msymbol
)))
258 /* Also accept the textlow value of a psymtab as a
259 "symbol", to provide some support for partial
260 symbol tables with line information but no debug
261 symbols (e.g. those produced by an assembler). */
263 this_addr
= p
->address (objfile
);
265 this_addr
= tpst
->text_low (objfile
);
267 /* Check whether it is closer than our current
268 BEST_ADDR. Since this symbol address is
269 necessarily lower or equal to PC, the symbol closer
270 to PC is the symbol which address is the highest.
271 This way we return the psymtab which contains such
272 best match symbol. This can help in cases where the
273 symbol information/debuginfo is not complete, like
274 for instance on IRIX6 with gcc, where no debug info
275 is emitted for statics. (See also the nodebug.exp
277 if (this_addr
> best_addr
)
279 best_addr
= this_addr
;
287 /* Find which partial symtab contains PC and SECTION. Return NULL if
288 none. We return the psymtab that contains a symbol whose address
289 exactly matches PC, or, if we cannot find an exact match, the
290 psymtab that contains a symbol whose address is closest to PC. */
292 static struct partial_symtab
*
293 find_pc_sect_psymtab (struct objfile
*objfile
, CORE_ADDR pc
,
294 struct obj_section
*section
,
295 struct bound_minimal_symbol msymbol
)
297 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better
298 granularity than the later used TEXTLOW/TEXTHIGH one. However, we need
299 to take care as the PSYMTABS_ADDRMAP can hold things other than partial
300 symtabs in some cases.
302 This function should only be called for objfiles that are using partial
303 symtabs, not for objfiles that are using indexes (.gdb_index or
304 .debug_names), however 'maintenance print psymbols' calls this function
305 directly for all objfiles. If we assume that PSYMTABS_ADDRMAP contains
306 partial symtabs then we will end up returning a pointer to an object
307 that is not a partial_symtab, which doesn't end well. */
309 if (objfile
->partial_symtabs
->psymtabs
!= NULL
310 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
312 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
314 struct partial_symtab
*pst
315 = ((struct partial_symtab
*)
316 addrmap_find (objfile
->partial_symtabs
->psymtabs_addrmap
,
320 /* FIXME: addrmaps currently do not handle overlayed sections,
321 so fall back to the non-addrmap case if we're debugging
322 overlays and the addrmap returned the wrong section. */
323 if (overlay_debugging
&& msymbol
.minsym
!= NULL
&& section
!= NULL
)
325 struct partial_symbol
*p
;
327 /* NOTE: This assumes that every psymbol has a
328 corresponding msymbol, which is not necessarily
329 true; the debug info might be much richer than the
330 object's symbol table. */
331 p
= find_pc_sect_psymbol (objfile
, pst
, pc
, section
);
333 || (p
->address (objfile
)
334 != BMSYMBOL_VALUE_ADDRESS (msymbol
)))
338 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
339 PSYMTABS_ADDRMAP we used has already the best 1-byte
340 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
341 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
350 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
351 which still have no corresponding full SYMTABs read. But it is not
352 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
355 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
356 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
357 debug info type in single OBJFILE. */
359 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
360 if (!pst
->psymtabs_addrmap_supported
361 && pc
>= pst
->text_low (objfile
) && pc
< pst
->text_high (objfile
))
363 struct partial_symtab
*best_pst
;
365 best_pst
= find_pc_sect_psymtab_closer (objfile
, pc
, section
, pst
,
367 if (best_pst
!= NULL
)
374 /* Psymtab version of find_pc_sect_compunit_symtab. See its definition in
375 the definition of quick_symbol_functions in symfile.h. */
377 static struct compunit_symtab
*
378 psym_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
379 struct bound_minimal_symbol msymbol
,
381 struct obj_section
*section
,
384 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
, section
,
388 if (warn_if_readin
&& ps
->readin_p ())
389 /* Might want to error() here (in case symtab is corrupt and
390 will cause a core dump), but maybe we can successfully
391 continue, so let's not. */
393 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
394 paddress (get_objfile_arch (objfile
), pc
));
395 psymtab_to_symtab (objfile
, ps
);
396 return ps
->get_compunit_symtab ();
401 /* Find which partial symbol within a psymtab matches PC and SECTION.
402 Return NULL if none. */
404 static struct partial_symbol
*
405 find_pc_sect_psymbol (struct objfile
*objfile
,
406 struct partial_symtab
*psymtab
, CORE_ADDR pc
,
407 struct obj_section
*section
)
409 struct partial_symbol
*best
= NULL
;
411 const CORE_ADDR textlow
= psymtab
->text_low (objfile
);
413 gdb_assert (psymtab
!= NULL
);
415 /* Cope with programs that start at address 0. */
416 best_pc
= (textlow
!= 0) ? textlow
- 1 : 0;
418 /* Search the global symbols as well as the static symbols, so that
419 find_pc_partial_function doesn't use a minimal symbol and thus
420 cache a bad endaddr. */
421 for (int i
= 0; i
< psymtab
->n_global_syms
; i
++)
424 = objfile
->partial_symtabs
->global_psymbols
[psymtab
->globals_offset
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
);
445 for (int i
= 0; i
< psymtab
->n_static_syms
; i
++)
448 = objfile
->partial_symtabs
->static_psymbols
[psymtab
->statics_offset
451 if (p
->domain
== VAR_DOMAIN
452 && p
->aclass
== LOC_BLOCK
453 && pc
>= p
->address (objfile
)
454 && (p
->address (objfile
) > best_pc
455 || (psymtab
->text_low (objfile
) == 0
456 && best_pc
== 0 && p
->address (objfile
) == 0)))
458 if (section
!= NULL
) /* Match on a specific section. */
460 if (!matching_obj_sections (p
->obj_section (objfile
),
464 best_pc
= p
->address (objfile
);
472 /* Psymtab version of lookup_symbol. See its definition in
473 the definition of quick_symbol_functions in symfile.h. */
475 static struct compunit_symtab
*
476 psym_lookup_symbol (struct objfile
*objfile
,
477 block_enum block_index
, const char *name
,
478 const domain_enum domain
)
480 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
481 struct compunit_symtab
*stab_best
= NULL
;
483 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
485 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
487 if (!ps
->readin_p () && lookup_partial_symbol (objfile
, ps
, name
,
488 psymtab_index
, domain
))
490 struct symbol
*sym
, *with_opaque
= NULL
;
491 struct compunit_symtab
*stab
= psymtab_to_symtab (objfile
, ps
);
492 /* Note: While psymtab_to_symtab can return NULL if the
493 partial symtab is empty, we can assume it won't here
494 because lookup_partial_symbol succeeded. */
495 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
496 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
498 sym
= block_find_symbol (block
, name
, domain
,
499 block_find_non_opaque_type_preferred
,
502 /* Some caution must be observed with overloaded functions
503 and methods, since the index will not contain any overload
504 information (but NAME might contain it). */
507 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
509 if (with_opaque
!= NULL
510 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
513 /* Keep looking through other psymtabs. */
520 /* Returns true if PSYM matches LOOKUP_NAME. */
523 psymbol_name_matches (partial_symbol
*psym
,
524 const lookup_name_info
&lookup_name
)
526 const language_defn
*lang
= language_def (psym
->ginfo
.language ());
527 symbol_name_matcher_ftype
*name_match
528 = get_symbol_name_matcher (lang
, lookup_name
);
529 return name_match (psym
->ginfo
.search_name (), lookup_name
, NULL
);
532 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
533 the global block of PST if GLOBAL, and otherwise the static block.
534 MATCH is the comparison operation that returns true iff MATCH (s,
535 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
536 non-null, the symbols in the block are assumed to be ordered
537 according to it (allowing binary search). It must be compatible
538 with MATCH. Returns the symbol, if found, and otherwise NULL. */
540 static struct partial_symbol
*
541 match_partial_symbol (struct objfile
*objfile
,
542 struct partial_symtab
*pst
, int global
,
543 const lookup_name_info
&name
, domain_enum domain
,
544 symbol_compare_ftype
*ordered_compare
)
546 struct partial_symbol
**start
, **psym
;
547 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
548 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
549 int do_linear_search
= 1;
555 &objfile
->partial_symtabs
->global_psymbols
[pst
->globals_offset
] :
556 &objfile
->partial_symtabs
->static_psymbols
[pst
->statics_offset
]);
558 if (global
&& ordered_compare
) /* Can use a binary search. */
560 do_linear_search
= 0;
562 /* Binary search. This search is guaranteed to end with center
563 pointing at the earliest partial symbol whose name might be
564 correct. At that point *all* partial symbols with an
565 appropriate name will be checked against the correct
569 top
= start
+ length
- 1;
573 center
= bottom
+ (top
- bottom
) / 2;
574 gdb_assert (center
< top
);
576 enum language lang
= (*center
)->ginfo
.language ();
578 = name
.language_lookup_name (lang
).c_str ();
580 if (ordered_compare ((*center
)->ginfo
.search_name (),
586 gdb_assert (top
== bottom
);
588 while (top
<= real_top
589 && psymbol_name_matches (*top
, name
))
591 if (symbol_matches_domain ((*top
)->ginfo
.language (),
592 (*top
)->domain
, domain
))
598 /* Can't use a binary search or else we found during the binary search that
599 we should also do a linear search. */
601 if (do_linear_search
)
603 for (psym
= start
; psym
< start
+ length
; psym
++)
605 if (symbol_matches_domain ((*psym
)->ginfo
.language (),
606 (*psym
)->domain
, domain
)
607 && psymbol_name_matches (*psym
, name
))
615 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
616 not contain any method/function instance information (since this would
617 force reading type information while reading psymtabs). Therefore,
618 if NAME contains overload information, it must be stripped before searching
621 static gdb::unique_xmalloc_ptr
<char>
622 psymtab_search_name (const char *name
)
624 switch (current_language
->la_language
)
628 if (strchr (name
, '('))
630 gdb::unique_xmalloc_ptr
<char> ret
= cp_remove_params (name
);
642 return make_unique_xstrdup (name
);
645 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
646 Check the global symbols if GLOBAL, the static symbols if not. */
648 static struct partial_symbol
*
649 lookup_partial_symbol (struct objfile
*objfile
,
650 struct partial_symtab
*pst
, const char *name
,
651 int global
, domain_enum domain
)
653 struct partial_symbol
**start
, **psym
;
654 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
655 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
656 int do_linear_search
= 1;
661 gdb::unique_xmalloc_ptr
<char> search_name
= psymtab_search_name (name
);
663 lookup_name_info
lookup_name (search_name
.get (), symbol_name_match_type::FULL
);
666 &objfile
->partial_symtabs
->global_psymbols
[pst
->globals_offset
] :
667 &objfile
->partial_symtabs
->static_psymbols
[pst
->statics_offset
]);
669 if (global
) /* This means we can use a binary search. */
671 do_linear_search
= 0;
673 /* Binary search. This search is guaranteed to end with center
674 pointing at the earliest partial symbol whose name might be
675 correct. At that point *all* partial symbols with an
676 appropriate name will be checked against the correct
680 top
= start
+ length
- 1;
684 center
= bottom
+ (top
- bottom
) / 2;
686 internal_error (__FILE__
, __LINE__
,
687 _("failed internal consistency check"));
688 if (strcmp_iw_ordered ((*center
)->ginfo
.search_name (),
689 search_name
.get ()) >= 0)
698 if (!(top
== bottom
))
699 internal_error (__FILE__
, __LINE__
,
700 _("failed internal consistency check"));
702 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
703 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
704 while (top
>= start
&& symbol_matches_search_name (&(*top
)->ginfo
,
708 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
711 while (top
<= real_top
&& symbol_matches_search_name (&(*top
)->ginfo
,
714 if (symbol_matches_domain ((*top
)->ginfo
.language (),
715 (*top
)->domain
, domain
))
721 /* Can't use a binary search or else we found during the binary search that
722 we should also do a linear search. */
724 if (do_linear_search
)
726 for (psym
= start
; psym
< start
+ length
; psym
++)
728 if (symbol_matches_domain ((*psym
)->ginfo
.language (),
729 (*psym
)->domain
, domain
)
730 && symbol_matches_search_name (&(*psym
)->ginfo
, lookup_name
))
738 /* Get the symbol table that corresponds to a partial_symtab.
739 This is fast after the first time you do it.
740 The result will be NULL if the primary symtab has no symbols,
741 which can happen. Otherwise the result is the primary symtab
742 that contains PST. */
744 static struct compunit_symtab
*
745 psymtab_to_symtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
747 /* If it is a shared psymtab, find an unshared psymtab that includes
748 it. Any such psymtab will do. */
749 while (pst
->user
!= NULL
)
752 /* If it's been looked up before, return it. */
753 if (pst
->get_compunit_symtab ())
754 return pst
->get_compunit_symtab ();
756 /* If it has not yet been read in, read it. */
757 if (!pst
->readin_p ())
759 scoped_restore decrementer
= increment_reading_symtab ();
763 printf_filtered (_("Reading in symbols for %s...\n"),
765 gdb_flush (gdb_stdout
);
768 pst
->read_symtab (objfile
);
771 return pst
->get_compunit_symtab ();
774 /* Psymtab version of find_last_source_symtab. See its definition in
775 the definition of quick_symbol_functions in symfile.h. */
777 static struct symtab
*
778 psym_find_last_source_symtab (struct objfile
*ofp
)
780 struct partial_symtab
*cs_pst
= NULL
;
782 for (partial_symtab
*ps
: require_partial_symbols (ofp
, true))
784 const char *name
= ps
->filename
;
785 int len
= strlen (name
);
787 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
788 || strcmp (name
, "<<C++-namespaces>>") == 0)))
794 if (cs_pst
->readin_p ())
796 internal_error (__FILE__
, __LINE__
,
797 _("select_source_symtab: "
798 "readin pst found and no symtabs."));
802 struct compunit_symtab
*cust
= psymtab_to_symtab (ofp
, cs_pst
);
806 return compunit_primary_filetab (cust
);
812 /* Psymtab version of forget_cached_source_info. See its definition in
813 the definition of quick_symbol_functions in symfile.h. */
816 psym_forget_cached_source_info (struct objfile
*objfile
)
818 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
820 if (pst
->fullname
!= NULL
)
822 xfree (pst
->fullname
);
823 pst
->fullname
= NULL
;
829 print_partial_symbols (struct gdbarch
*gdbarch
, struct objfile
*objfile
,
830 struct partial_symbol
**p
, int count
, const char *what
,
831 struct ui_file
*outfile
)
833 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
837 fprintf_filtered (outfile
, " `%s'", (*p
)->ginfo
.linkage_name ());
838 if ((*p
)->ginfo
.demangled_name () != NULL
)
840 fprintf_filtered (outfile
, " `%s'",
841 (*p
)->ginfo
.demangled_name ());
843 fputs_filtered (", ", outfile
);
844 switch ((*p
)->domain
)
847 fputs_filtered ("undefined domain, ", outfile
);
850 /* This is the usual thing -- don't print it. */
853 fputs_filtered ("struct domain, ", outfile
);
856 fputs_filtered ("module domain, ", outfile
);
859 fputs_filtered ("label domain, ", outfile
);
861 case COMMON_BLOCK_DOMAIN
:
862 fputs_filtered ("common block domain, ", outfile
);
865 fputs_filtered ("<invalid domain>, ", outfile
);
868 switch ((*p
)->aclass
)
871 fputs_filtered ("undefined", outfile
);
874 fputs_filtered ("constant int", outfile
);
877 fputs_filtered ("static", outfile
);
880 fputs_filtered ("register", outfile
);
883 fputs_filtered ("pass by value", outfile
);
886 fputs_filtered ("pass by reference", outfile
);
888 case LOC_REGPARM_ADDR
:
889 fputs_filtered ("register address parameter", outfile
);
892 fputs_filtered ("stack parameter", outfile
);
895 fputs_filtered ("type", outfile
);
898 fputs_filtered ("label", outfile
);
901 fputs_filtered ("function", outfile
);
903 case LOC_CONST_BYTES
:
904 fputs_filtered ("constant bytes", outfile
);
907 fputs_filtered ("unresolved", outfile
);
909 case LOC_OPTIMIZED_OUT
:
910 fputs_filtered ("optimized out", outfile
);
913 fputs_filtered ("computed at runtime", outfile
);
916 fputs_filtered ("<invalid location>", outfile
);
919 fputs_filtered (", ", outfile
);
920 fputs_filtered (paddress (gdbarch
, (*p
)->unrelocated_address ()), outfile
);
921 fprintf_filtered (outfile
, "\n");
927 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
928 struct ui_file
*outfile
)
930 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
933 if (psymtab
->anonymous
)
935 fprintf_filtered (outfile
, "\nAnonymous partial symtab (%s) ",
940 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
943 fprintf_filtered (outfile
, "(object ");
944 gdb_print_host_address (psymtab
, outfile
);
945 fprintf_filtered (outfile
, ")\n\n");
946 fprintf_filtered (outfile
, " Read from object file %s (",
947 objfile_name (objfile
));
948 gdb_print_host_address (objfile
, outfile
);
949 fprintf_filtered (outfile
, ")\n");
951 if (psymtab
->readin_p ())
953 fprintf_filtered (outfile
,
954 " Full symtab was read (at ");
955 gdb_print_host_address (psymtab
->get_compunit_symtab (), outfile
);
956 fprintf_filtered (outfile
, ")\n");
959 fprintf_filtered (outfile
, " Symbols cover text addresses ");
960 fputs_filtered (paddress (gdbarch
, psymtab
->text_low (objfile
)), outfile
);
961 fprintf_filtered (outfile
, "-");
962 fputs_filtered (paddress (gdbarch
, psymtab
->text_high (objfile
)), outfile
);
963 fprintf_filtered (outfile
, "\n");
964 fprintf_filtered (outfile
, " Address map supported - %s.\n",
965 psymtab
->psymtabs_addrmap_supported
? "yes" : "no");
966 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
967 psymtab
->number_of_dependencies
);
968 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
970 fprintf_filtered (outfile
, " %d ", i
);
971 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
972 fprintf_filtered (outfile
, " %s\n",
973 psymtab
->dependencies
[i
]->filename
);
975 if (psymtab
->user
!= NULL
)
977 fprintf_filtered (outfile
, " Shared partial symtab with user ");
978 gdb_print_host_address (psymtab
->user
, outfile
);
979 fprintf_filtered (outfile
, "\n");
981 if (psymtab
->n_global_syms
> 0)
983 print_partial_symbols
985 &objfile
->partial_symtabs
->global_psymbols
[psymtab
->globals_offset
],
986 psymtab
->n_global_syms
, "Global", outfile
);
988 if (psymtab
->n_static_syms
> 0)
990 print_partial_symbols
992 &objfile
->partial_symtabs
->static_psymbols
[psymtab
->statics_offset
],
993 psymtab
->n_static_syms
, "Static", outfile
);
995 fprintf_filtered (outfile
, "\n");
998 /* Psymtab version of print_stats. See its definition in
999 the definition of quick_symbol_functions in symfile.h. */
1002 psym_print_stats (struct objfile
*objfile
)
1007 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1009 if (!ps
->readin_p ())
1012 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i
);
1015 /* Psymtab version of dump. See its definition in
1016 the definition of quick_symbol_functions in symfile.h. */
1019 psym_dump (struct objfile
*objfile
)
1021 struct partial_symtab
*psymtab
;
1023 if (objfile
->partial_symtabs
->psymtabs
)
1025 printf_filtered ("Psymtabs:\n");
1026 for (psymtab
= objfile
->partial_symtabs
->psymtabs
;
1028 psymtab
= psymtab
->next
)
1030 printf_filtered ("%s at ",
1032 gdb_print_host_address (psymtab
, gdb_stdout
);
1033 printf_filtered (", ");
1036 printf_filtered ("\n\n");
1040 /* Psymtab version of expand_symtabs_for_function. See its definition in
1041 the definition of quick_symbol_functions in symfile.h. */
1044 psym_expand_symtabs_for_function (struct objfile
*objfile
,
1045 const char *func_name
)
1047 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1049 if (ps
->readin_p ())
1052 if ((lookup_partial_symbol (objfile
, ps
, func_name
, 1, VAR_DOMAIN
)
1054 || (lookup_partial_symbol (objfile
, ps
, func_name
, 0, VAR_DOMAIN
)
1056 psymtab_to_symtab (objfile
, ps
);
1060 /* Psymtab version of expand_all_symtabs. See its definition in
1061 the definition of quick_symbol_functions in symfile.h. */
1064 psym_expand_all_symtabs (struct objfile
*objfile
)
1066 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
, true))
1067 psymtab_to_symtab (objfile
, psymtab
);
1070 /* Psymtab version of expand_symtabs_with_fullname. See its definition in
1071 the definition of quick_symbol_functions in symfile.h. */
1074 psym_expand_symtabs_with_fullname (struct objfile
*objfile
,
1075 const char *fullname
)
1077 for (partial_symtab
*p
: require_partial_symbols (objfile
, true))
1079 /* Anonymous psymtabs don't have a name of a source file. */
1083 /* psymtab_to_fullname tries to open the file which is slow.
1084 Don't call it if we know the basenames don't match. */
1085 if ((basenames_may_differ
1086 || filename_cmp (lbasename (fullname
), lbasename (p
->filename
)) == 0)
1087 && filename_cmp (fullname
, psymtab_to_fullname (p
)) == 0)
1088 psymtab_to_symtab (objfile
, p
);
1092 /* Psymtab version of map_symbol_filenames. See its definition in
1093 the definition of quick_symbol_functions in symfile.h. */
1096 psym_map_symbol_filenames (struct objfile
*objfile
,
1097 symbol_filename_ftype
*fun
, void *data
,
1100 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1102 const char *fullname
;
1104 if (ps
->readin_p ())
1107 /* We can skip shared psymtabs here, because any file name will be
1108 attached to the unshared psymtab. */
1109 if (ps
->user
!= NULL
)
1112 /* Anonymous psymtabs don't have a file name. */
1118 fullname
= psymtab_to_fullname (ps
);
1121 (*fun
) (ps
->filename
, fullname
, data
);
1125 /* Finds the fullname that a partial_symtab represents.
1127 If this functions finds the fullname, it will save it in ps->fullname
1128 and it will also return the value.
1130 If this function fails to find the file that this partial_symtab represents,
1131 NULL will be returned and ps->fullname will be set to NULL. */
1134 psymtab_to_fullname (struct partial_symtab
*ps
)
1136 gdb_assert (!ps
->anonymous
);
1138 /* Use cached copy if we have it.
1139 We rely on forget_cached_source_info being called appropriately
1140 to handle cases like the file being moved. */
1141 if (ps
->fullname
== NULL
)
1143 gdb::unique_xmalloc_ptr
<char> fullname
;
1144 scoped_fd fd
= find_and_open_source (ps
->filename
, ps
->dirname
,
1146 ps
->fullname
= fullname
.release ();
1150 /* rewrite_source_path would be applied by find_and_open_source, we
1151 should report the pathname where GDB tried to find the file. */
1153 if (ps
->dirname
== NULL
|| IS_ABSOLUTE_PATH (ps
->filename
))
1154 fullname
.reset (xstrdup (ps
->filename
));
1156 fullname
.reset (concat (ps
->dirname
, SLASH_STRING
,
1157 ps
->filename
, (char *) NULL
));
1159 ps
->fullname
= rewrite_source_path (fullname
.get ()).release ();
1160 if (ps
->fullname
== NULL
)
1161 ps
->fullname
= fullname
.release ();
1165 return ps
->fullname
;
1168 /* Psymtab version of map_matching_symbols. See its definition in
1169 the definition of quick_symbol_functions in symfile.h. */
1172 psym_map_matching_symbols
1173 (struct objfile
*objfile
,
1174 const lookup_name_info
&name
, domain_enum domain
,
1176 gdb::function_view
<symbol_found_callback_ftype
> callback
,
1177 symbol_compare_ftype
*ordered_compare
)
1179 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
1181 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1185 || match_partial_symbol (objfile
, ps
, global
, name
, domain
,
1188 struct compunit_symtab
*cust
= psymtab_to_symtab (objfile
, ps
);
1189 const struct block
*block
;
1193 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
1194 if (!iterate_over_symbols_terminated (block
, name
,
1201 /* A helper for psym_expand_symtabs_matching that handles searching
1202 included psymtabs. This returns true if a symbol is found, and
1203 false otherwise. It also updates the 'searched_flag' on the
1204 various psymtabs that it searches. */
1207 recursively_search_psymtabs
1208 (struct partial_symtab
*ps
,
1209 struct objfile
*objfile
,
1210 enum search_domain domain
,
1211 const lookup_name_info
&lookup_name
,
1212 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> sym_matcher
)
1215 enum psymtab_search_status result
= PST_SEARCHED_AND_NOT_FOUND
;
1218 if (ps
->searched_flag
!= PST_NOT_SEARCHED
)
1219 return ps
->searched_flag
== PST_SEARCHED_AND_FOUND
;
1221 /* Recurse into shared psymtabs first, because they may have already
1222 been searched, and this could save some time. */
1223 for (i
= 0; i
< ps
->number_of_dependencies
; ++i
)
1227 /* Skip non-shared dependencies, these are handled elsewhere. */
1228 if (ps
->dependencies
[i
]->user
== NULL
)
1231 r
= recursively_search_psymtabs (ps
->dependencies
[i
],
1232 objfile
, domain
, lookup_name
,
1236 ps
->searched_flag
= PST_SEARCHED_AND_FOUND
;
1241 partial_symbol
**gbound
1242 = (objfile
->partial_symtabs
->global_psymbols
.data ()
1243 + ps
->globals_offset
+ ps
->n_global_syms
);
1244 partial_symbol
**sbound
1245 = (objfile
->partial_symtabs
->static_psymbols
.data ()
1246 + ps
->statics_offset
+ ps
->n_static_syms
);
1247 partial_symbol
**bound
= gbound
;
1249 /* Go through all of the symbols stored in a partial
1250 symtab in one loop. */
1251 partial_symbol
**psym
= (objfile
->partial_symtabs
->global_psymbols
.data ()
1252 + ps
->globals_offset
);
1257 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
1259 psym
= (objfile
->partial_symtabs
->static_psymbols
.data ()
1260 + ps
->statics_offset
);
1271 if ((domain
== ALL_DOMAIN
1272 || (domain
== MODULES_DOMAIN
1273 && (*psym
)->domain
== MODULE_DOMAIN
)
1274 || (domain
== VARIABLES_DOMAIN
1275 && (*psym
)->aclass
!= LOC_TYPEDEF
1276 && (*psym
)->aclass
!= LOC_BLOCK
)
1277 || (domain
== FUNCTIONS_DOMAIN
1278 && (*psym
)->aclass
== LOC_BLOCK
)
1279 || (domain
== TYPES_DOMAIN
1280 && (*psym
)->aclass
== LOC_TYPEDEF
))
1281 && psymbol_name_matches (*psym
, lookup_name
)
1282 && (sym_matcher
== NULL
1283 || sym_matcher ((*psym
)->ginfo
.search_name ())))
1285 /* Found a match, so notify our caller. */
1286 result
= PST_SEARCHED_AND_FOUND
;
1293 ps
->searched_flag
= result
;
1294 return result
== PST_SEARCHED_AND_FOUND
;
1297 /* Psymtab version of expand_symtabs_matching. See its definition in
1298 the definition of quick_symbol_functions in symfile.h. */
1301 psym_expand_symtabs_matching
1302 (struct objfile
*objfile
,
1303 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
1304 const lookup_name_info
&lookup_name_in
,
1305 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
1306 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
1307 enum search_domain domain
)
1309 lookup_name_info lookup_name
= lookup_name_in
.make_ignore_params ();
1311 /* Clear the search flags. */
1312 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1313 ps
->searched_flag
= PST_NOT_SEARCHED
;
1315 for (partial_symtab
*ps
: objfile
->psymtabs ())
1319 if (ps
->readin_p ())
1322 /* We skip shared psymtabs because file-matching doesn't apply
1323 to them; but we search them later in the loop. */
1324 if (ps
->user
!= NULL
)
1334 match
= file_matcher (ps
->filename
, false);
1337 /* Before we invoke realpath, which can get expensive when many
1338 files are involved, do a quick comparison of the basenames. */
1339 if (basenames_may_differ
1340 || file_matcher (lbasename (ps
->filename
), true))
1341 match
= file_matcher (psymtab_to_fullname (ps
), false);
1347 if (recursively_search_psymtabs (ps
, objfile
, domain
,
1348 lookup_name
, symbol_matcher
))
1350 struct compunit_symtab
*symtab
=
1351 psymtab_to_symtab (objfile
, ps
);
1353 if (expansion_notify
!= NULL
)
1354 expansion_notify (symtab
);
1359 /* Psymtab version of has_symbols. See its definition in
1360 the definition of quick_symbol_functions in symfile.h. */
1363 psym_has_symbols (struct objfile
*objfile
)
1365 return objfile
->partial_symtabs
->psymtabs
!= NULL
;
1368 /* Helper function for psym_find_compunit_symtab_by_address that fills
1369 in psymbol_map for a given range of psymbols. */
1372 psym_fill_psymbol_map (struct objfile
*objfile
,
1373 struct partial_symtab
*psymtab
,
1374 std::set
<CORE_ADDR
> *seen_addrs
,
1375 const std::vector
<partial_symbol
*> &symbols
,
1379 for (int i
= 0; i
< length
; ++i
)
1381 struct partial_symbol
*psym
= symbols
[start
+ i
];
1383 if (psym
->aclass
== LOC_STATIC
)
1385 CORE_ADDR addr
= psym
->address (objfile
);
1386 if (seen_addrs
->find (addr
) == seen_addrs
->end ())
1388 seen_addrs
->insert (addr
);
1389 objfile
->psymbol_map
.emplace_back (addr
, psymtab
);
1395 /* See find_compunit_symtab_by_address in quick_symbol_functions, in
1398 static compunit_symtab
*
1399 psym_find_compunit_symtab_by_address (struct objfile
*objfile
,
1402 if (objfile
->psymbol_map
.empty ())
1404 std::set
<CORE_ADDR
> seen_addrs
;
1406 for (partial_symtab
*pst
: require_partial_symbols (objfile
, true))
1408 psym_fill_psymbol_map (objfile
, pst
,
1410 objfile
->partial_symtabs
->global_psymbols
,
1411 pst
->globals_offset
,
1412 pst
->n_global_syms
);
1413 psym_fill_psymbol_map (objfile
, pst
,
1415 objfile
->partial_symtabs
->static_psymbols
,
1416 pst
->statics_offset
,
1417 pst
->n_static_syms
);
1420 objfile
->psymbol_map
.shrink_to_fit ();
1422 std::sort (objfile
->psymbol_map
.begin (), objfile
->psymbol_map
.end (),
1423 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1424 const std::pair
<CORE_ADDR
, partial_symtab
*> &b
)
1426 return a
.first
< b
.first
;
1430 auto iter
= std::lower_bound
1431 (objfile
->psymbol_map
.begin (), objfile
->psymbol_map
.end (), address
,
1432 [] (const std::pair
<CORE_ADDR
, partial_symtab
*> &a
,
1438 if (iter
== objfile
->psymbol_map
.end () || iter
->first
!= address
)
1441 return psymtab_to_symtab (objfile
, iter
->second
);
1444 const struct quick_symbol_functions psym_functions
=
1447 psym_find_last_source_symtab
,
1448 psym_forget_cached_source_info
,
1449 psym_map_symtabs_matching_filename
,
1453 psym_expand_symtabs_for_function
,
1454 psym_expand_all_symtabs
,
1455 psym_expand_symtabs_with_fullname
,
1456 psym_map_matching_symbols
,
1457 psym_expand_symtabs_matching
,
1458 psym_find_pc_sect_compunit_symtab
,
1459 psym_find_compunit_symtab_by_address
,
1460 psym_map_symbol_filenames
1466 sort_pst_symbols (struct objfile
*objfile
, struct partial_symtab
*pst
)
1468 /* Sort the global list; don't sort the static list. */
1469 auto begin
= objfile
->partial_symtabs
->global_psymbols
.begin ();
1470 std::advance (begin
, pst
->globals_offset
);
1472 /* The psymbols for this partial_symtab are currently at the end of the
1474 auto end
= objfile
->partial_symtabs
->global_psymbols
.end ();
1476 std::sort (begin
, end
, [] (partial_symbol
*s1
, partial_symbol
*s2
)
1478 return strcmp_iw_ordered (s1
->ginfo
.search_name (),
1479 s2
->ginfo
.search_name ()) < 0;
1483 /* Partially fill a partial symtab. It will be completely filled at
1484 the end of the symbol list. */
1486 partial_symtab::partial_symtab (const char *filename
,
1487 struct objfile
*objfile
,
1489 : partial_symtab (filename
, objfile
)
1491 set_text_low (textlow
);
1492 set_text_high (raw_text_low ()); /* default */
1493 globals_offset
= objfile
->partial_symtabs
->global_psymbols
.size ();
1494 statics_offset
= objfile
->partial_symtabs
->static_psymbols
.size ();
1497 /* Perform "finishing up" operations of a partial symtab. */
1500 end_psymtab_common (struct objfile
*objfile
, struct partial_symtab
*pst
)
1502 pst
->n_global_syms
= (objfile
->partial_symtabs
->global_psymbols
.size ()
1503 - pst
->globals_offset
);
1504 pst
->n_static_syms
= (objfile
->partial_symtabs
->static_psymbols
.size ()
1505 - pst
->statics_offset
);
1507 sort_pst_symbols (objfile
, pst
);
1510 /* Calculate a hash code for the given partial symbol. The hash is
1511 calculated using the symbol's value, language, domain, class
1512 and name. These are the values which are set by
1513 add_psymbol_to_bcache. */
1515 static unsigned long
1516 psymbol_hash (const void *addr
, int length
)
1518 unsigned long h
= 0;
1519 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1520 unsigned int lang
= psymbol
->ginfo
.language ();
1521 unsigned int domain
= psymbol
->domain
;
1522 unsigned int theclass
= psymbol
->aclass
;
1524 h
= fast_hash (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1525 h
= fast_hash (&lang
, sizeof (unsigned int), h
);
1526 h
= fast_hash (&domain
, sizeof (unsigned int), h
);
1527 h
= fast_hash (&theclass
, sizeof (unsigned int), h
);
1528 /* Note that psymbol names are interned via compute_and_set_names, so
1529 there's no need to hash the contents of the name here. */
1530 h
= fast_hash (&psymbol
->ginfo
.m_name
, sizeof (psymbol
->ginfo
.m_name
), h
);
1535 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1536 For the comparison this function uses a symbols value,
1537 language, domain, class and name. */
1540 psymbol_compare (const void *addr1
, const void *addr2
, int length
)
1542 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1543 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1545 return (memcmp (&sym1
->ginfo
.value
, &sym2
->ginfo
.value
,
1546 sizeof (sym1
->ginfo
.value
)) == 0
1547 && sym1
->ginfo
.language () == sym2
->ginfo
.language ()
1548 && sym1
->domain
== sym2
->domain
1549 && sym1
->aclass
== sym2
->aclass
1550 /* Note that psymbol names are interned via
1551 compute_and_set_names, so there's no need to compare the
1552 contents of the name here. */
1553 && sym1
->ginfo
.linkage_name () == sym2
->ginfo
.linkage_name ());
1556 /* Helper function, initialises partial symbol structure and stashes
1557 it into objfile's bcache. Note that our caching mechanism will
1558 use all fields of struct partial_symbol to determine hash value of the
1559 structure. In other words, having two symbols with the same name but
1560 different domain (or address) is possible and correct. */
1562 static struct partial_symbol
*
1563 add_psymbol_to_bcache (gdb::string_view name
, bool copy_name
,
1565 enum address_class theclass
,
1568 enum language language
, struct objfile
*objfile
,
1571 struct partial_symbol psymbol
;
1572 memset (&psymbol
, 0, sizeof (psymbol
));
1574 psymbol
.set_unrelocated_address (coreaddr
);
1575 psymbol
.ginfo
.section
= section
;
1576 psymbol
.domain
= domain
;
1577 psymbol
.aclass
= theclass
;
1578 psymbol
.ginfo
.set_language (language
, objfile
->partial_symtabs
->obstack ());
1579 psymbol
.ginfo
.compute_and_set_names (name
, copy_name
, objfile
->per_bfd
);
1581 /* Stash the partial symbol away in the cache. */
1582 return ((struct partial_symbol
*)
1583 objfile
->partial_symtabs
->psymbol_cache
.insert
1584 (&psymbol
, sizeof (struct partial_symbol
), added
));
1587 /* Helper function, adds partial symbol to the given partial symbol list. */
1590 append_psymbol_to_list (std::vector
<partial_symbol
*> *list
,
1591 struct partial_symbol
*psym
,
1592 struct objfile
*objfile
)
1594 list
->push_back (psym
);
1595 OBJSTAT (objfile
, n_psyms
++);
1598 /* See psympriv.h. */
1601 add_psymbol_to_list (gdb::string_view name
, bool copy_name
,
1603 enum address_class theclass
,
1605 psymbol_placement where
,
1607 enum language language
, struct objfile
*objfile
)
1609 struct partial_symbol
*psym
;
1613 /* Stash the partial symbol away in the cache. */
1614 psym
= add_psymbol_to_bcache (name
, copy_name
, domain
, theclass
,
1615 section
, coreaddr
, language
, objfile
, &added
);
1617 /* Do not duplicate global partial symbols. */
1618 if (where
== psymbol_placement::GLOBAL
&& !added
)
1621 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1622 std::vector
<partial_symbol
*> *list
1623 = (where
== psymbol_placement::STATIC
1624 ? &objfile
->partial_symtabs
->static_psymbols
1625 : &objfile
->partial_symtabs
->global_psymbols
);
1626 append_psymbol_to_list (list
, psym
, objfile
);
1629 /* See psympriv.h. */
1632 init_psymbol_list (struct objfile
*objfile
, int total_symbols
)
1634 if (objfile
->partial_symtabs
->global_psymbols
.capacity () == 0
1635 && objfile
->partial_symtabs
->static_psymbols
.capacity () == 0)
1637 /* Current best guess is that approximately a twentieth of the
1638 total symbols (in a debugging file) are global or static
1639 oriented symbols, then multiply that by slop factor of
1641 objfile
->partial_symtabs
->global_psymbols
.reserve (total_symbols
/ 10);
1642 objfile
->partial_symtabs
->static_psymbols
.reserve (total_symbols
/ 10);
1646 /* See psympriv.h. */
1648 partial_symtab::partial_symtab (const char *filename_
, struct objfile
*objfile
)
1649 : searched_flag (PST_NOT_SEARCHED
),
1653 objfile
->partial_symtabs
->install_psymtab (this);
1655 filename
= objfile
->intern (filename_
);
1657 if (symtab_create_debug
)
1659 /* Be a bit clever with debugging messages, and don't print objfile
1660 every time, only when it changes. */
1661 static char *last_objfile_name
= NULL
;
1663 if (last_objfile_name
== NULL
1664 || strcmp (last_objfile_name
, objfile_name (objfile
)) != 0)
1666 xfree (last_objfile_name
);
1667 last_objfile_name
= xstrdup (objfile_name (objfile
));
1668 fprintf_filtered (gdb_stdlog
,
1669 "Creating one or more psymtabs for objfile %s ...\n",
1672 fprintf_filtered (gdb_stdlog
,
1673 "Created psymtab %s for module %s.\n",
1674 host_address_to_string (this), filename
);
1678 /* See psympriv.h. */
1681 partial_symtab::read_dependencies (struct objfile
*objfile
)
1683 for (int i
= 0; i
< number_of_dependencies
; ++i
)
1685 if (!dependencies
[i
]->readin_p ()
1686 && dependencies
[i
]->user
== NULL
)
1688 /* Inform about additional files to be read in. */
1691 fputs_filtered (" ", gdb_stdout
);
1693 fputs_filtered ("and ", gdb_stdout
);
1695 printf_filtered ("%s...", dependencies
[i
]->filename
);
1696 wrap_here (""); /* Flush output */
1697 gdb_flush (gdb_stdout
);
1699 dependencies
[i
]->expand_psymtab (objfile
);
1706 psymtab_storage::discard_psymtab (struct partial_symtab
*pst
)
1708 struct partial_symtab
**prev_pst
;
1711 Empty psymtabs happen as a result of header files which don't
1712 have any symbols in them. There can be a lot of them. But this
1713 check is wrong, in that a psymtab with N_SLINE entries but
1714 nothing else is not empty, but we don't realize that. Fixing
1715 that without slowing things down might be tricky. */
1717 /* First, snip it out of the psymtab chain. */
1719 prev_pst
= &psymtabs
;
1720 while ((*prev_pst
) != pst
)
1721 prev_pst
= &((*prev_pst
)->next
);
1722 (*prev_pst
) = pst
->next
;
1728 /* We need to pass a couple of items to the addrmap_foreach function,
1731 struct dump_psymtab_addrmap_data
1733 struct objfile
*objfile
;
1734 struct partial_symtab
*psymtab
;
1735 struct ui_file
*outfile
;
1737 /* Non-zero if the previously printed addrmap entry was for PSYMTAB.
1738 If so, we want to print the next one as well (since the next addrmap
1739 entry defines the end of the range). */
1740 int previous_matched
;
1743 /* Helper function for dump_psymtab_addrmap to print an addrmap entry. */
1746 dump_psymtab_addrmap_1 (void *datap
, CORE_ADDR start_addr
, void *obj
)
1748 struct dump_psymtab_addrmap_data
*data
1749 = (struct dump_psymtab_addrmap_data
*) datap
;
1750 struct gdbarch
*gdbarch
= get_objfile_arch (data
->objfile
);
1751 struct partial_symtab
*addrmap_psymtab
= (struct partial_symtab
*) obj
;
1752 const char *psymtab_address_or_end
= NULL
;
1756 if (data
->psymtab
== NULL
1757 || data
->psymtab
== addrmap_psymtab
)
1758 psymtab_address_or_end
= host_address_to_string (addrmap_psymtab
);
1759 else if (data
->previous_matched
)
1760 psymtab_address_or_end
= "<ends here>";
1762 if (data
->psymtab
== NULL
1763 || data
->psymtab
== addrmap_psymtab
1764 || data
->previous_matched
)
1766 fprintf_filtered (data
->outfile
, " %s%s %s\n",
1767 data
->psymtab
!= NULL
? " " : "",
1768 paddress (gdbarch
, start_addr
),
1769 psymtab_address_or_end
);
1772 data
->previous_matched
= (data
->psymtab
== NULL
1773 || data
->psymtab
== addrmap_psymtab
);
1778 /* Helper function for maintenance_print_psymbols to print the addrmap
1779 of PSYMTAB. If PSYMTAB is NULL print the entire addrmap. */
1782 dump_psymtab_addrmap (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
1783 struct ui_file
*outfile
)
1785 struct dump_psymtab_addrmap_data addrmap_dump_data
;
1787 if ((psymtab
== NULL
1788 || psymtab
->psymtabs_addrmap_supported
)
1789 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
1791 addrmap_dump_data
.objfile
= objfile
;
1792 addrmap_dump_data
.psymtab
= psymtab
;
1793 addrmap_dump_data
.outfile
= outfile
;
1794 addrmap_dump_data
.previous_matched
= 0;
1795 fprintf_filtered (outfile
, "%sddress map:\n",
1796 psymtab
== NULL
? "Entire a" : " A");
1797 addrmap_foreach (objfile
->partial_symtabs
->psymtabs_addrmap
,
1798 dump_psymtab_addrmap_1
, &addrmap_dump_data
);
1803 maintenance_print_psymbols (const char *args
, int from_tty
)
1805 struct ui_file
*outfile
= gdb_stdout
;
1806 char *address_arg
= NULL
, *source_arg
= NULL
, *objfile_arg
= NULL
;
1807 int i
, outfile_idx
, found
;
1809 struct obj_section
*section
= NULL
;
1813 gdb_argv
argv (args
);
1815 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
1817 if (strcmp (argv
[i
], "-pc") == 0)
1819 if (argv
[i
+ 1] == NULL
)
1820 error (_("Missing pc value"));
1821 address_arg
= argv
[++i
];
1823 else if (strcmp (argv
[i
], "-source") == 0)
1825 if (argv
[i
+ 1] == NULL
)
1826 error (_("Missing source file"));
1827 source_arg
= argv
[++i
];
1829 else if (strcmp (argv
[i
], "-objfile") == 0)
1831 if (argv
[i
+ 1] == NULL
)
1832 error (_("Missing objfile name"));
1833 objfile_arg
= argv
[++i
];
1835 else if (strcmp (argv
[i
], "--") == 0)
1837 /* End of options. */
1841 else if (argv
[i
][0] == '-')
1843 /* Future proofing: Don't allow OUTFILE to begin with "-". */
1844 error (_("Unknown option: %s"), argv
[i
]);
1851 if (address_arg
!= NULL
&& source_arg
!= NULL
)
1852 error (_("Must specify at most one of -pc and -source"));
1854 stdio_file arg_outfile
;
1856 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
1858 if (argv
[outfile_idx
+ 1] != NULL
)
1859 error (_("Junk at end of command"));
1860 gdb::unique_xmalloc_ptr
<char> outfile_name
1861 (tilde_expand (argv
[outfile_idx
]));
1862 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
1863 perror_with_name (outfile_name
.get ());
1864 outfile
= &arg_outfile
;
1867 if (address_arg
!= NULL
)
1869 pc
= parse_and_eval_address (address_arg
);
1870 /* If we fail to find a section, that's ok, try the lookup anyway. */
1871 section
= find_pc_section (pc
);
1875 for (objfile
*objfile
: current_program_space
->objfiles ())
1877 int printed_objfile_header
= 0;
1878 int print_for_objfile
= 1;
1881 if (objfile_arg
!= NULL
)
1883 = compare_filenames_for_search (objfile_name (objfile
),
1885 if (!print_for_objfile
)
1888 if (address_arg
!= NULL
)
1890 struct bound_minimal_symbol msymbol
= { NULL
, NULL
};
1892 /* We don't assume each pc has a unique objfile (this is for
1894 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
,
1898 if (!printed_objfile_header
)
1900 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1901 objfile_name (objfile
));
1902 printed_objfile_header
= 1;
1904 dump_psymtab (objfile
, ps
, outfile
);
1905 dump_psymtab_addrmap (objfile
, ps
, outfile
);
1911 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
1913 int print_for_source
= 0;
1916 if (source_arg
!= NULL
)
1919 = compare_filenames_for_search (ps
->filename
, source_arg
);
1922 if (source_arg
== NULL
1923 || print_for_source
)
1925 if (!printed_objfile_header
)
1927 outfile
->printf ("\nPartial symtabs for objfile %s\n",
1928 objfile_name (objfile
));
1929 printed_objfile_header
= 1;
1931 dump_psymtab (objfile
, ps
, outfile
);
1932 dump_psymtab_addrmap (objfile
, ps
, outfile
);
1937 /* If we're printing all the objfile's symbols dump the full addrmap. */
1939 if (address_arg
== NULL
1940 && source_arg
== NULL
1941 && objfile
->partial_symtabs
->psymtabs_addrmap
!= NULL
)
1943 outfile
->puts ("\n");
1944 dump_psymtab_addrmap (objfile
, NULL
, outfile
);
1950 if (address_arg
!= NULL
)
1951 error (_("No partial symtab for address: %s"), address_arg
);
1952 if (source_arg
!= NULL
)
1953 error (_("No partial symtab for source file: %s"), source_arg
);
1957 /* List all the partial symbol tables whose names match REGEXP (optional). */
1960 maintenance_info_psymtabs (const char *regexp
, int from_tty
)
1962 struct program_space
*pspace
;
1967 ALL_PSPACES (pspace
)
1968 for (objfile
*objfile
: pspace
->objfiles ())
1970 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1972 /* We don't want to print anything for this objfile until we
1973 actually find a symtab whose name matches. */
1974 int printed_objfile_start
= 0;
1976 for (partial_symtab
*psymtab
: require_partial_symbols (objfile
, true))
1981 || re_exec (psymtab
->filename
))
1983 if (! printed_objfile_start
)
1985 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
1987 printf_filtered ("((struct objfile *) %s)\n",
1988 host_address_to_string (objfile
));
1989 printed_objfile_start
= 1;
1992 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1994 printf_filtered ("((struct partial_symtab *) %s)\n",
1995 host_address_to_string (psymtab
));
1997 printf_filtered (" readin %s\n",
1998 psymtab
->readin_p () ? "yes" : "no");
1999 printf_filtered (" fullname %s\n",
2001 ? psymtab
->fullname
: "(null)");
2002 printf_filtered (" text addresses ");
2003 fputs_filtered (paddress (gdbarch
,
2004 psymtab
->text_low (objfile
)),
2006 printf_filtered (" -- ");
2007 fputs_filtered (paddress (gdbarch
,
2008 psymtab
->text_high (objfile
)),
2010 printf_filtered ("\n");
2011 printf_filtered (" psymtabs_addrmap_supported %s\n",
2012 (psymtab
->psymtabs_addrmap_supported
2014 printf_filtered (" globals ");
2015 if (psymtab
->n_global_syms
)
2017 auto p
= &(objfile
->partial_symtabs
2018 ->global_psymbols
[psymtab
->globals_offset
]);
2021 ("(* (struct partial_symbol **) %s @ %d)\n",
2022 host_address_to_string (p
),
2023 psymtab
->n_global_syms
);
2026 printf_filtered ("(none)\n");
2027 printf_filtered (" statics ");
2028 if (psymtab
->n_static_syms
)
2030 auto p
= &(objfile
->partial_symtabs
2031 ->static_psymbols
[psymtab
->statics_offset
]);
2034 ("(* (struct partial_symbol **) %s @ %d)\n",
2035 host_address_to_string (p
),
2036 psymtab
->n_static_syms
);
2039 printf_filtered ("(none)\n");
2040 printf_filtered (" dependencies ");
2041 if (psymtab
->number_of_dependencies
)
2045 printf_filtered ("{\n");
2046 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
2048 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
2050 /* Note the string concatenation there --- no
2052 printf_filtered (" psymtab %s "
2053 "((struct partial_symtab *) %s)\n",
2055 host_address_to_string (dep
));
2057 printf_filtered (" }\n");
2060 printf_filtered ("(none)\n");
2061 printf_filtered (" }\n");
2065 if (printed_objfile_start
)
2066 printf_filtered ("}\n");
2070 /* Check consistency of currently expanded psymtabs vs symtabs. */
2073 maintenance_check_psymtabs (const char *ignore
, int from_tty
)
2076 struct compunit_symtab
*cust
= NULL
;
2077 const struct blockvector
*bv
;
2078 const struct block
*b
;
2081 for (objfile
*objfile
: current_program_space
->objfiles ())
2082 for (partial_symtab
*ps
: require_partial_symbols (objfile
, true))
2084 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2086 /* We don't call psymtab_to_symtab here because that may cause symtab
2087 expansion. When debugging a problem it helps if checkers leave
2088 things unchanged. */
2089 cust
= ps
->get_compunit_symtab ();
2091 /* First do some checks that don't require the associated symtab. */
2092 if (ps
->text_high (objfile
) < ps
->text_low (objfile
))
2094 printf_filtered ("Psymtab ");
2095 puts_filtered (ps
->filename
);
2096 printf_filtered (" covers bad range ");
2097 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
2099 printf_filtered (" - ");
2100 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
2102 printf_filtered ("\n");
2106 /* Now do checks requiring the associated symtab. */
2109 bv
= COMPUNIT_BLOCKVECTOR (cust
);
2110 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
2111 partial_symbol
**psym
2112 = &objfile
->partial_symtabs
->static_psymbols
[ps
->statics_offset
];
2113 length
= ps
->n_static_syms
;
2116 sym
= block_lookup_symbol (b
, (*psym
)->ginfo
.search_name (),
2117 symbol_name_match_type::SEARCH_NAME
,
2121 printf_filtered ("Static symbol `");
2122 puts_filtered ((*psym
)->ginfo
.linkage_name ());
2123 printf_filtered ("' only found in ");
2124 puts_filtered (ps
->filename
);
2125 printf_filtered (" psymtab\n");
2129 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2130 psym
= &objfile
->partial_symtabs
->global_psymbols
[ps
->globals_offset
];
2131 length
= ps
->n_global_syms
;
2134 sym
= block_lookup_symbol (b
, (*psym
)->ginfo
.search_name (),
2135 symbol_name_match_type::SEARCH_NAME
,
2139 printf_filtered ("Global symbol `");
2140 puts_filtered ((*psym
)->ginfo
.linkage_name ());
2141 printf_filtered ("' only found in ");
2142 puts_filtered (ps
->filename
);
2143 printf_filtered (" psymtab\n");
2147 if (ps
->raw_text_high () != 0
2148 && (ps
->text_low (objfile
) < BLOCK_START (b
)
2149 || ps
->text_high (objfile
) > BLOCK_END (b
)))
2151 printf_filtered ("Psymtab ");
2152 puts_filtered (ps
->filename
);
2153 printf_filtered (" covers ");
2154 fputs_filtered (paddress (gdbarch
, ps
->text_low (objfile
)),
2156 printf_filtered (" - ");
2157 fputs_filtered (paddress (gdbarch
, ps
->text_high (objfile
)),
2159 printf_filtered (" but symtab covers only ");
2160 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
2161 printf_filtered (" - ");
2162 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
2163 printf_filtered ("\n");
2168 void _initialize_psymtab ();
2170 _initialize_psymtab ()
2172 add_cmd ("psymbols", class_maintenance
, maintenance_print_psymbols
, _("\
2173 Print dump of current partial symbol definitions.\n\
2174 Usage: mt print psymbols [-objfile OBJFILE] [-pc ADDRESS] [--] [OUTFILE]\n\
2175 mt print psymbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
2176 Entries in the partial symbol table are dumped to file OUTFILE,\n\
2177 or the terminal if OUTFILE is unspecified.\n\
2178 If ADDRESS is provided, dump only the file for that address.\n\
2179 If SOURCE is provided, dump only that file's symbols.\n\
2180 If OBJFILE is provided, dump only that file's minimal symbols."),
2181 &maintenanceprintlist
);
2183 add_cmd ("psymtabs", class_maintenance
, maintenance_info_psymtabs
, _("\
2184 List the partial symbol tables for all object files.\n\
2185 This does not include information about individual partial symbols,\n\
2186 just the symbol table structures themselves."),
2187 &maintenanceinfolist
);
2189 add_cmd ("check-psymtabs", class_maintenance
, maintenance_check_psymtabs
,
2191 Check consistency of currently expanded psymtabs versus symtabs."),