1 /* Partial symbol tables.
3 Copyright (C) 2009-2016 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"
32 #include "readline/readline.h"
33 #include "gdb_regex.h"
34 #include "dictionary.h"
36 #include "cp-support.h"
40 #define DEV_TTY "/dev/tty"
45 struct bcache
*bcache
;
48 static struct partial_symbol
*match_partial_symbol (struct objfile
*,
49 struct partial_symtab
*,
51 const char *, domain_enum
,
52 symbol_compare_ftype
*,
53 symbol_compare_ftype
*);
55 static struct partial_symbol
*lookup_partial_symbol (struct objfile
*,
56 struct partial_symtab
*,
60 static const char *psymtab_to_fullname (struct partial_symtab
*ps
);
62 static struct partial_symbol
*find_pc_sect_psymbol (struct objfile
*,
63 struct partial_symtab
*,
65 struct obj_section
*);
67 static void fixup_psymbol_section (struct partial_symbol
*psym
,
68 struct objfile
*objfile
);
70 static struct compunit_symtab
*psymtab_to_symtab (struct objfile
*objfile
,
71 struct partial_symtab
*pst
);
73 /* Ensure that the partial symbols for OBJFILE have been loaded. This
74 function always returns its argument, as a convenience. */
77 require_partial_symbols (struct objfile
*objfile
, int verbose
)
79 if ((objfile
->flags
& OBJF_PSYMTABS_READ
) == 0)
81 objfile
->flags
|= OBJF_PSYMTABS_READ
;
83 if (objfile
->sf
->sym_read_psymbols
)
87 printf_unfiltered (_("Reading symbols from %s..."),
88 objfile_name (objfile
));
89 gdb_flush (gdb_stdout
);
91 (*objfile
->sf
->sym_read_psymbols
) (objfile
);
94 if (!objfile_has_symbols (objfile
))
97 printf_unfiltered (_("(no debugging symbols found)..."));
101 printf_unfiltered (_("done.\n"));
109 /* Traverse all psymtabs in one objfile, requiring that the psymtabs
112 #define ALL_OBJFILE_PSYMTABS_REQUIRED(objfile, p) \
113 for ((p) = require_partial_symbols (objfile, 1)->psymtabs; \
117 /* We want to make sure this file always requires psymtabs. */
119 #undef ALL_OBJFILE_PSYMTABS
121 /* Traverse all psymtabs in all objfiles. */
123 #define ALL_PSYMTABS(objfile, p) \
124 ALL_OBJFILES (objfile) \
125 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
127 /* Helper function for psym_map_symtabs_matching_filename that
128 expands the symtabs and calls the iterator. */
131 partial_map_expand_apply (struct objfile
*objfile
,
133 const char *real_path
,
134 struct partial_symtab
*pst
,
135 int (*callback
) (struct symtab
*, void *),
138 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
140 /* Shared psymtabs should never be seen here. Instead they should
141 be handled properly by the caller. */
142 gdb_assert (pst
->user
== NULL
);
144 /* Don't visit already-expanded psymtabs. */
148 /* This may expand more than one symtab, and we want to iterate over
150 psymtab_to_symtab (objfile
, pst
);
152 return iterate_over_some_symtabs (name
, real_path
, callback
, data
,
153 objfile
->compunit_symtabs
, last_made
);
156 /* Psymtab version of map_symtabs_matching_filename. See its definition in
157 the definition of quick_symbol_functions in symfile.h. */
160 psym_map_symtabs_matching_filename (struct objfile
*objfile
,
162 const char *real_path
,
163 int (*callback
) (struct symtab
*,
167 struct partial_symtab
*pst
;
168 const char *name_basename
= lbasename (name
);
170 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
172 /* We can skip shared psymtabs here, because any file name will be
173 attached to the unshared psymtab. */
174 if (pst
->user
!= NULL
)
177 /* Anonymous psymtabs don't have a file name. */
181 if (compare_filenames_for_search (pst
->filename
, name
))
183 if (partial_map_expand_apply (objfile
, name
, real_path
,
184 pst
, callback
, data
))
189 /* Before we invoke realpath, which can get expensive when many
190 files are involved, do a quick comparison of the basenames. */
191 if (! basenames_may_differ
192 && FILENAME_CMP (name_basename
, lbasename (pst
->filename
)) != 0)
195 if (compare_filenames_for_search (psymtab_to_fullname (pst
), name
))
197 if (partial_map_expand_apply (objfile
, name
, real_path
,
198 pst
, callback
, data
))
203 /* If the user gave us an absolute path, try to find the file in
204 this symtab and use its absolute path. */
205 if (real_path
!= NULL
)
207 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
208 gdb_assert (IS_ABSOLUTE_PATH (name
));
209 if (filename_cmp (psymtab_to_fullname (pst
), real_path
) == 0)
211 if (partial_map_expand_apply (objfile
, name
, real_path
,
212 pst
, callback
, data
))
222 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
223 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
225 static struct partial_symtab
*
226 find_pc_sect_psymtab_closer (struct objfile
*objfile
,
227 CORE_ADDR pc
, struct obj_section
*section
,
228 struct partial_symtab
*pst
,
229 struct bound_minimal_symbol msymbol
)
231 struct partial_symtab
*tpst
;
232 struct partial_symtab
*best_pst
= pst
;
233 CORE_ADDR best_addr
= pst
->textlow
;
235 gdb_assert (!pst
->psymtabs_addrmap_supported
);
237 /* An objfile that has its functions reordered might have
238 many partial symbol tables containing the PC, but
239 we want the partial symbol table that contains the
240 function containing the PC. */
241 if (!(objfile
->flags
& OBJF_REORDERED
)
242 && section
== NULL
) /* Can't validate section this way. */
245 if (msymbol
.minsym
== NULL
)
248 /* The code range of partial symtabs sometimes overlap, so, in
249 the loop below, we need to check all partial symtabs and
250 find the one that fits better for the given PC address. We
251 select the partial symtab that contains a symbol whose
252 address is closest to the PC address. By closest we mean
253 that find_pc_sect_symbol returns the symbol with address
254 that is closest and still less than the given PC. */
255 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
257 if (pc
>= tpst
->textlow
&& pc
< tpst
->texthigh
)
259 struct partial_symbol
*p
;
262 /* NOTE: This assumes that every psymbol has a
263 corresponding msymbol, which is not necessarily
264 true; the debug info might be much richer than the
265 object's symbol table. */
266 p
= find_pc_sect_psymbol (objfile
, tpst
, pc
, section
);
268 && (SYMBOL_VALUE_ADDRESS (p
)
269 == BMSYMBOL_VALUE_ADDRESS (msymbol
)))
272 /* Also accept the textlow value of a psymtab as a
273 "symbol", to provide some support for partial
274 symbol tables with line information but no debug
275 symbols (e.g. those produced by an assembler). */
277 this_addr
= SYMBOL_VALUE_ADDRESS (p
);
279 this_addr
= tpst
->textlow
;
281 /* Check whether it is closer than our current
282 BEST_ADDR. Since this symbol address is
283 necessarily lower or equal to PC, the symbol closer
284 to PC is the symbol which address is the highest.
285 This way we return the psymtab which contains such
286 best match symbol. This can help in cases where the
287 symbol information/debuginfo is not complete, like
288 for instance on IRIX6 with gcc, where no debug info
289 is emitted for statics. (See also the nodebug.exp
291 if (this_addr
> best_addr
)
293 best_addr
= this_addr
;
301 /* Find which partial symtab contains PC and SECTION. Return NULL if
302 none. We return the psymtab that contains a symbol whose address
303 exactly matches PC, or, if we cannot find an exact match, the
304 psymtab that contains a symbol whose address is closest to PC. */
306 static struct partial_symtab
*
307 find_pc_sect_psymtab (struct objfile
*objfile
, CORE_ADDR pc
,
308 struct obj_section
*section
,
309 struct bound_minimal_symbol msymbol
)
311 struct partial_symtab
*pst
;
313 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
314 than the later used TEXTLOW/TEXTHIGH one. */
316 if (objfile
->psymtabs_addrmap
!= NULL
)
318 pst
= ((struct partial_symtab
*)
319 addrmap_find (objfile
->psymtabs_addrmap
, pc
));
322 /* FIXME: addrmaps currently do not handle overlayed sections,
323 so fall back to the non-addrmap case if we're debugging
324 overlays and the addrmap returned the wrong section. */
325 if (overlay_debugging
&& msymbol
.minsym
!= NULL
&& section
!= NULL
)
327 struct partial_symbol
*p
;
329 /* NOTE: This assumes that every psymbol has a
330 corresponding msymbol, which is not necessarily
331 true; the debug info might be much richer than the
332 object's symbol table. */
333 p
= find_pc_sect_psymbol (objfile
, pst
, pc
, section
);
335 || (SYMBOL_VALUE_ADDRESS (p
)
336 != BMSYMBOL_VALUE_ADDRESS (msymbol
)))
340 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
341 PSYMTABS_ADDRMAP we used has already the best 1-byte
342 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
343 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
352 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
353 which still have no corresponding full SYMTABs read. But it is not
354 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
357 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
358 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
359 debug info type in single OBJFILE. */
361 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
362 if (!pst
->psymtabs_addrmap_supported
363 && pc
>= pst
->textlow
&& pc
< pst
->texthigh
)
365 struct partial_symtab
*best_pst
;
367 best_pst
= find_pc_sect_psymtab_closer (objfile
, pc
, section
, pst
,
369 if (best_pst
!= NULL
)
376 /* Psymtab version of find_pc_sect_compunit_symtab. See its definition in
377 the definition of quick_symbol_functions in symfile.h. */
379 static struct compunit_symtab
*
380 psym_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
381 struct bound_minimal_symbol msymbol
,
383 struct obj_section
*section
,
386 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
, section
,
390 if (warn_if_readin
&& ps
->readin
)
391 /* Might want to error() here (in case symtab is corrupt and
392 will cause a core dump), but maybe we can successfully
393 continue, so let's not. */
395 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
396 paddress (get_objfile_arch (objfile
), pc
));
397 psymtab_to_symtab (objfile
, ps
);
398 return ps
->compunit_symtab
;
403 /* Find which partial symbol within a psymtab matches PC and SECTION.
404 Return NULL if none. */
406 static struct partial_symbol
*
407 find_pc_sect_psymbol (struct objfile
*objfile
,
408 struct partial_symtab
*psymtab
, CORE_ADDR pc
,
409 struct obj_section
*section
)
411 struct partial_symbol
*best
= NULL
, *p
, **pp
;
414 gdb_assert (psymtab
!= NULL
);
416 /* Cope with programs that start at address 0. */
417 best_pc
= (psymtab
->textlow
!= 0) ? psymtab
->textlow
- 1 : 0;
419 /* Search the global symbols as well as the static symbols, so that
420 find_pc_partial_function doesn't use a minimal symbol and thus
421 cache a bad endaddr. */
422 for (pp
= objfile
->global_psymbols
.list
+ psymtab
->globals_offset
;
423 (pp
- (objfile
->global_psymbols
.list
+ psymtab
->globals_offset
)
424 < psymtab
->n_global_syms
);
428 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
429 && PSYMBOL_CLASS (p
) == LOC_BLOCK
430 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
431 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
432 || (psymtab
->textlow
== 0
433 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
435 if (section
!= NULL
) /* Match on a specific section. */
437 fixup_psymbol_section (p
, objfile
);
438 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (objfile
, p
),
442 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
447 for (pp
= objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
448 (pp
- (objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
449 < psymtab
->n_static_syms
);
453 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
454 && PSYMBOL_CLASS (p
) == LOC_BLOCK
455 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
456 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
457 || (psymtab
->textlow
== 0
458 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
460 if (section
!= NULL
) /* Match on a specific section. */
462 fixup_psymbol_section (p
, objfile
);
463 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (objfile
, p
),
467 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
476 fixup_psymbol_section (struct partial_symbol
*psym
, struct objfile
*objfile
)
483 if (SYMBOL_SECTION (psym
) >= 0)
486 gdb_assert (objfile
);
488 switch (PSYMBOL_CLASS (psym
))
493 addr
= SYMBOL_VALUE_ADDRESS (psym
);
496 /* Nothing else will be listed in the minsyms -- no use looking
501 fixup_section (&psym
->ginfo
, addr
, objfile
);
504 /* Psymtab version of lookup_symbol. See its definition in
505 the definition of quick_symbol_functions in symfile.h. */
507 static struct compunit_symtab
*
508 psym_lookup_symbol (struct objfile
*objfile
,
509 int block_index
, const char *name
,
510 const domain_enum domain
)
512 struct partial_symtab
*ps
;
513 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
514 struct compunit_symtab
*stab_best
= NULL
;
516 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
518 if (!ps
->readin
&& lookup_partial_symbol (objfile
, ps
, name
,
519 psymtab_index
, domain
))
521 struct symbol
*sym
, *with_opaque
= NULL
;
522 struct compunit_symtab
*stab
= psymtab_to_symtab (objfile
, ps
);
523 /* Note: While psymtab_to_symtab can return NULL if the partial symtab
524 is empty, we can assume it won't here because lookup_partial_symbol
526 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
527 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
529 sym
= block_find_symbol (block
, name
, domain
,
530 block_find_non_opaque_type_preferred
,
533 /* Some caution must be observed with overloaded functions
534 and methods, since the index will not contain any overload
535 information (but NAME might contain it). */
538 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
540 if (with_opaque
!= NULL
541 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
544 /* Keep looking through other psymtabs. */
551 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
552 the global block of PST if GLOBAL, and otherwise the static block.
553 MATCH is the comparison operation that returns true iff MATCH (s,
554 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
555 non-null, the symbols in the block are assumed to be ordered
556 according to it (allowing binary search). It must be compatible
557 with MATCH. Returns the symbol, if found, and otherwise NULL. */
559 static struct partial_symbol
*
560 match_partial_symbol (struct objfile
*objfile
,
561 struct partial_symtab
*pst
, int global
,
562 const char *name
, domain_enum domain
,
563 symbol_compare_ftype
*match
,
564 symbol_compare_ftype
*ordered_compare
)
566 struct partial_symbol
**start
, **psym
;
567 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
568 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
569 int do_linear_search
= 1;
574 objfile
->global_psymbols
.list
+ pst
->globals_offset
:
575 objfile
->static_psymbols
.list
+ pst
->statics_offset
);
577 if (global
&& ordered_compare
) /* Can use a binary search. */
579 do_linear_search
= 0;
581 /* Binary search. This search is guaranteed to end with center
582 pointing at the earliest partial symbol whose name might be
583 correct. At that point *all* partial symbols with an
584 appropriate name will be checked against the correct
588 top
= start
+ length
- 1;
592 center
= bottom
+ (top
- bottom
) / 2;
593 gdb_assert (center
< top
);
594 if (!do_linear_search
595 && (SYMBOL_LANGUAGE (*center
) == language_java
))
596 do_linear_search
= 1;
597 if (ordered_compare (SYMBOL_SEARCH_NAME (*center
), name
) >= 0)
602 gdb_assert (top
== bottom
);
604 while (top
<= real_top
605 && match (SYMBOL_SEARCH_NAME (*top
), name
) == 0)
607 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top
),
608 SYMBOL_DOMAIN (*top
), domain
))
614 /* Can't use a binary search or else we found during the binary search that
615 we should also do a linear search. */
617 if (do_linear_search
)
619 for (psym
= start
; psym
< start
+ length
; psym
++)
621 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym
),
622 SYMBOL_DOMAIN (*psym
), domain
)
623 && match (SYMBOL_SEARCH_NAME (*psym
), name
) == 0)
631 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
632 not contain any method/function instance information (since this would
633 force reading type information while reading psymtabs). Therefore,
634 if NAME contains overload information, it must be stripped before searching
637 The caller is responsible for freeing the return result. */
640 psymtab_search_name (const char *name
)
642 switch (current_language
->la_language
)
647 if (strchr (name
, '('))
649 char *ret
= cp_remove_params (name
);
661 return xstrdup (name
);
664 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
665 Check the global symbols if GLOBAL, the static symbols if not. */
667 static struct partial_symbol
*
668 lookup_partial_symbol (struct objfile
*objfile
,
669 struct partial_symtab
*pst
, const char *name
,
670 int global
, domain_enum domain
)
672 struct partial_symbol
**start
, **psym
;
673 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
674 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
675 int do_linear_search
= 1;
677 struct cleanup
*cleanup
;
682 search_name
= psymtab_search_name (name
);
683 cleanup
= make_cleanup (xfree
, search_name
);
685 objfile
->global_psymbols
.list
+ pst
->globals_offset
:
686 objfile
->static_psymbols
.list
+ pst
->statics_offset
);
688 if (global
) /* This means we can use a binary search. */
690 do_linear_search
= 0;
692 /* Binary search. This search is guaranteed to end with center
693 pointing at the earliest partial symbol whose name might be
694 correct. At that point *all* partial symbols with an
695 appropriate name will be checked against the correct
699 top
= start
+ length
- 1;
703 center
= bottom
+ (top
- bottom
) / 2;
705 internal_error (__FILE__
, __LINE__
,
706 _("failed internal consistency check"));
707 if (!do_linear_search
708 && SYMBOL_LANGUAGE (*center
) == language_java
)
710 do_linear_search
= 1;
712 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center
),
722 if (!(top
== bottom
))
723 internal_error (__FILE__
, __LINE__
,
724 _("failed internal consistency check"));
726 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
727 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
728 while (top
>= start
&& SYMBOL_MATCHES_SEARCH_NAME (*top
, search_name
))
731 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
734 while (top
<= real_top
&& SYMBOL_MATCHES_SEARCH_NAME (*top
, search_name
))
736 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top
),
737 SYMBOL_DOMAIN (*top
), domain
))
739 do_cleanups (cleanup
);
746 /* Can't use a binary search or else we found during the binary search that
747 we should also do a linear search. */
749 if (do_linear_search
)
751 for (psym
= start
; psym
< start
+ length
; psym
++)
753 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym
),
754 SYMBOL_DOMAIN (*psym
), domain
)
755 && SYMBOL_MATCHES_SEARCH_NAME (*psym
, search_name
))
757 do_cleanups (cleanup
);
763 do_cleanups (cleanup
);
767 /* Get the symbol table that corresponds to a partial_symtab.
768 This is fast after the first time you do it.
769 The result will be NULL if the primary symtab has no symbols,
770 which can happen. Otherwise the result is the primary symtab
771 that contains PST. */
773 static struct compunit_symtab
*
774 psymtab_to_symtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
776 /* If it is a shared psymtab, find an unshared psymtab that includes
777 it. Any such psymtab will do. */
778 while (pst
->user
!= NULL
)
781 /* If it's been looked up before, return it. */
782 if (pst
->compunit_symtab
)
783 return pst
->compunit_symtab
;
785 /* If it has not yet been read in, read it. */
788 struct cleanup
*back_to
= increment_reading_symtab ();
790 (*pst
->read_symtab
) (pst
, objfile
);
791 do_cleanups (back_to
);
794 return pst
->compunit_symtab
;
797 /* Psymtab version of relocate. See its definition in
798 the definition of quick_symbol_functions in symfile.h. */
801 psym_relocate (struct objfile
*objfile
,
802 const struct section_offsets
*new_offsets
,
803 const struct section_offsets
*delta
)
805 struct partial_symbol
**psym
;
806 struct partial_symtab
*p
;
808 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, p
)
810 p
->textlow
+= ANOFFSET (delta
, SECT_OFF_TEXT (objfile
));
811 p
->texthigh
+= ANOFFSET (delta
, SECT_OFF_TEXT (objfile
));
814 for (psym
= objfile
->global_psymbols
.list
;
815 psym
< objfile
->global_psymbols
.next
;
818 fixup_psymbol_section (*psym
, objfile
);
819 if (SYMBOL_SECTION (*psym
) >= 0)
820 SYMBOL_VALUE_ADDRESS (*psym
) += ANOFFSET (delta
,
821 SYMBOL_SECTION (*psym
));
823 for (psym
= objfile
->static_psymbols
.list
;
824 psym
< objfile
->static_psymbols
.next
;
827 fixup_psymbol_section (*psym
, objfile
);
828 if (SYMBOL_SECTION (*psym
) >= 0)
829 SYMBOL_VALUE_ADDRESS (*psym
) += ANOFFSET (delta
,
830 SYMBOL_SECTION (*psym
));
834 /* Psymtab version of find_last_source_symtab. See its definition in
835 the definition of quick_symbol_functions in symfile.h. */
837 static struct symtab
*
838 psym_find_last_source_symtab (struct objfile
*ofp
)
840 struct partial_symtab
*ps
;
841 struct partial_symtab
*cs_pst
= NULL
;
843 ALL_OBJFILE_PSYMTABS_REQUIRED (ofp
, ps
)
845 const char *name
= ps
->filename
;
846 int len
= strlen (name
);
848 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
849 || strcmp (name
, "<<C++-namespaces>>") == 0)))
857 internal_error (__FILE__
, __LINE__
,
858 _("select_source_symtab: "
859 "readin pst found and no symtabs."));
863 struct compunit_symtab
*cust
= psymtab_to_symtab (ofp
, cs_pst
);
867 return compunit_primary_filetab (cust
);
873 /* Psymtab version of forget_cached_source_info. See its definition in
874 the definition of quick_symbol_functions in symfile.h. */
877 psym_forget_cached_source_info (struct objfile
*objfile
)
879 struct partial_symtab
*pst
;
881 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
883 if (pst
->fullname
!= NULL
)
885 xfree (pst
->fullname
);
886 pst
->fullname
= NULL
;
892 print_partial_symbols (struct gdbarch
*gdbarch
,
893 struct partial_symbol
**p
, int count
, char *what
,
894 struct ui_file
*outfile
)
896 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
900 fprintf_filtered (outfile
, " `%s'", SYMBOL_LINKAGE_NAME (*p
));
901 if (SYMBOL_DEMANGLED_NAME (*p
) != NULL
)
903 fprintf_filtered (outfile
, " `%s'", SYMBOL_DEMANGLED_NAME (*p
));
905 fputs_filtered (", ", outfile
);
906 switch (SYMBOL_DOMAIN (*p
))
909 fputs_filtered ("undefined domain, ", outfile
);
912 /* This is the usual thing -- don't print it. */
915 fputs_filtered ("struct domain, ", outfile
);
918 fputs_filtered ("label domain, ", outfile
);
921 fputs_filtered ("<invalid domain>, ", outfile
);
924 switch (PSYMBOL_CLASS (*p
))
927 fputs_filtered ("undefined", outfile
);
930 fputs_filtered ("constant int", outfile
);
933 fputs_filtered ("static", outfile
);
936 fputs_filtered ("register", outfile
);
939 fputs_filtered ("pass by value", outfile
);
942 fputs_filtered ("pass by reference", outfile
);
944 case LOC_REGPARM_ADDR
:
945 fputs_filtered ("register address parameter", outfile
);
948 fputs_filtered ("stack parameter", outfile
);
951 fputs_filtered ("type", outfile
);
954 fputs_filtered ("label", outfile
);
957 fputs_filtered ("function", outfile
);
959 case LOC_CONST_BYTES
:
960 fputs_filtered ("constant bytes", outfile
);
963 fputs_filtered ("unresolved", outfile
);
965 case LOC_OPTIMIZED_OUT
:
966 fputs_filtered ("optimized out", outfile
);
969 fputs_filtered ("computed at runtime", outfile
);
972 fputs_filtered ("<invalid location>", outfile
);
975 fputs_filtered (", ", outfile
);
976 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (*p
)), outfile
);
977 fprintf_filtered (outfile
, "\n");
983 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
984 struct ui_file
*outfile
)
986 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
989 if (psymtab
->anonymous
)
991 fprintf_filtered (outfile
, "\nAnonymous partial symtab (%s) ",
996 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
999 fprintf_filtered (outfile
, "(object ");
1000 gdb_print_host_address (psymtab
, outfile
);
1001 fprintf_filtered (outfile
, ")\n\n");
1002 fprintf_unfiltered (outfile
, " Read from object file %s (",
1003 objfile_name (objfile
));
1004 gdb_print_host_address (objfile
, outfile
);
1005 fprintf_unfiltered (outfile
, ")\n");
1007 if (psymtab
->readin
)
1009 fprintf_filtered (outfile
,
1010 " Full symtab was read (at ");
1011 gdb_print_host_address (psymtab
->compunit_symtab
, outfile
);
1012 fprintf_filtered (outfile
, " by function at ");
1013 gdb_print_host_address (psymtab
->read_symtab
, outfile
);
1014 fprintf_filtered (outfile
, ")\n");
1017 fprintf_filtered (outfile
, " Symbols cover text addresses ");
1018 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
), outfile
);
1019 fprintf_filtered (outfile
, "-");
1020 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
), outfile
);
1021 fprintf_filtered (outfile
, "\n");
1022 fprintf_filtered (outfile
, " Address map supported - %s.\n",
1023 psymtab
->psymtabs_addrmap_supported
? "yes" : "no");
1024 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
1025 psymtab
->number_of_dependencies
);
1026 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1028 fprintf_filtered (outfile
, " %d ", i
);
1029 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
1030 fprintf_filtered (outfile
, " %s\n",
1031 psymtab
->dependencies
[i
]->filename
);
1033 if (psymtab
->user
!= NULL
)
1035 fprintf_filtered (outfile
, " Shared partial symtab with user ");
1036 gdb_print_host_address (psymtab
->user
, outfile
);
1037 fprintf_filtered (outfile
, "\n");
1039 if (psymtab
->n_global_syms
> 0)
1041 print_partial_symbols (gdbarch
,
1042 objfile
->global_psymbols
.list
1043 + psymtab
->globals_offset
,
1044 psymtab
->n_global_syms
, "Global", outfile
);
1046 if (psymtab
->n_static_syms
> 0)
1048 print_partial_symbols (gdbarch
,
1049 objfile
->static_psymbols
.list
1050 + psymtab
->statics_offset
,
1051 psymtab
->n_static_syms
, "Static", outfile
);
1053 fprintf_filtered (outfile
, "\n");
1056 /* Psymtab version of print_stats. See its definition in
1057 the definition of quick_symbol_functions in symfile.h. */
1060 psym_print_stats (struct objfile
*objfile
)
1063 struct partial_symtab
*ps
;
1066 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1068 if (ps
->readin
== 0)
1071 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i
);
1074 /* Psymtab version of dump. See its definition in
1075 the definition of quick_symbol_functions in symfile.h. */
1078 psym_dump (struct objfile
*objfile
)
1080 struct partial_symtab
*psymtab
;
1082 if (objfile
->psymtabs
)
1084 printf_filtered ("Psymtabs:\n");
1085 for (psymtab
= objfile
->psymtabs
;
1087 psymtab
= psymtab
->next
)
1089 printf_filtered ("%s at ",
1091 gdb_print_host_address (psymtab
, gdb_stdout
);
1092 printf_filtered (", ");
1095 printf_filtered ("\n\n");
1099 /* Psymtab version of expand_symtabs_for_function. See its definition in
1100 the definition of quick_symbol_functions in symfile.h. */
1103 psym_expand_symtabs_for_function (struct objfile
*objfile
,
1104 const char *func_name
)
1106 struct partial_symtab
*ps
;
1108 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1113 if ((lookup_partial_symbol (objfile
, ps
, func_name
, 1, VAR_DOMAIN
)
1115 || (lookup_partial_symbol (objfile
, ps
, func_name
, 0, VAR_DOMAIN
)
1117 psymtab_to_symtab (objfile
, ps
);
1121 /* Psymtab version of expand_all_symtabs. See its definition in
1122 the definition of quick_symbol_functions in symfile.h. */
1125 psym_expand_all_symtabs (struct objfile
*objfile
)
1127 struct partial_symtab
*psymtab
;
1129 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, psymtab
)
1131 psymtab_to_symtab (objfile
, psymtab
);
1135 /* Psymtab version of expand_symtabs_with_fullname. See its definition in
1136 the definition of quick_symbol_functions in symfile.h. */
1139 psym_expand_symtabs_with_fullname (struct objfile
*objfile
,
1140 const char *fullname
)
1142 struct partial_symtab
*p
;
1144 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, p
)
1146 /* Anonymous psymtabs don't have a name of a source file. */
1150 /* psymtab_to_fullname tries to open the file which is slow.
1151 Don't call it if we know the basenames don't match. */
1152 if ((basenames_may_differ
1153 || filename_cmp (lbasename (fullname
), lbasename (p
->filename
)) == 0)
1154 && filename_cmp (fullname
, psymtab_to_fullname (p
)) == 0)
1155 psymtab_to_symtab (objfile
, p
);
1159 /* Psymtab version of map_symbol_filenames. See its definition in
1160 the definition of quick_symbol_functions in symfile.h. */
1163 psym_map_symbol_filenames (struct objfile
*objfile
,
1164 symbol_filename_ftype
*fun
, void *data
,
1167 struct partial_symtab
*ps
;
1169 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1171 const char *fullname
;
1176 /* We can skip shared psymtabs here, because any file name will be
1177 attached to the unshared psymtab. */
1178 if (ps
->user
!= NULL
)
1181 /* Anonymous psymtabs don't have a file name. */
1187 fullname
= psymtab_to_fullname (ps
);
1190 (*fun
) (ps
->filename
, fullname
, data
);
1194 /* Finds the fullname that a partial_symtab represents.
1196 If this functions finds the fullname, it will save it in ps->fullname
1197 and it will also return the value.
1199 If this function fails to find the file that this partial_symtab represents,
1200 NULL will be returned and ps->fullname will be set to NULL. */
1203 psymtab_to_fullname (struct partial_symtab
*ps
)
1205 gdb_assert (!ps
->anonymous
);
1207 /* Use cached copy if we have it.
1208 We rely on forget_cached_source_info being called appropriately
1209 to handle cases like the file being moved. */
1210 if (ps
->fullname
== NULL
)
1212 int fd
= find_and_open_source (ps
->filename
, ps
->dirname
, &ps
->fullname
);
1219 struct cleanup
*back_to
;
1221 /* rewrite_source_path would be applied by find_and_open_source, we
1222 should report the pathname where GDB tried to find the file. */
1224 if (ps
->dirname
== NULL
|| IS_ABSOLUTE_PATH (ps
->filename
))
1225 fullname
= xstrdup (ps
->filename
);
1227 fullname
= concat (ps
->dirname
, SLASH_STRING
, ps
->filename
, NULL
);
1229 back_to
= make_cleanup (xfree
, fullname
);
1230 ps
->fullname
= rewrite_source_path (fullname
);
1231 if (ps
->fullname
== NULL
)
1232 ps
->fullname
= xstrdup (fullname
);
1233 do_cleanups (back_to
);
1237 return ps
->fullname
;
1240 /* For all symbols, s, in BLOCK that are in DOMAIN and match NAME
1241 according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
1242 BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK
1243 ever returns non-zero, and otherwise returns 0. */
1246 map_block (const char *name
, domain_enum domain
, struct objfile
*objfile
,
1247 struct block
*block
,
1248 int (*callback
) (struct block
*, struct symbol
*, void *),
1249 void *data
, symbol_compare_ftype
*match
)
1251 struct block_iterator iter
;
1254 for (sym
= block_iter_match_first (block
, name
, match
, &iter
);
1255 sym
!= NULL
; sym
= block_iter_match_next (name
, match
, &iter
))
1257 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym
),
1258 SYMBOL_DOMAIN (sym
), domain
))
1260 if (callback (block
, sym
, data
))
1268 /* Psymtab version of map_matching_symbols. See its definition in
1269 the definition of quick_symbol_functions in symfile.h. */
1272 psym_map_matching_symbols (struct objfile
*objfile
,
1273 const char *name
, domain_enum domain
,
1275 int (*callback
) (struct block
*,
1276 struct symbol
*, void *),
1278 symbol_compare_ftype
*match
,
1279 symbol_compare_ftype
*ordered_compare
)
1281 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
1282 struct partial_symtab
*ps
;
1284 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1288 || match_partial_symbol (objfile
, ps
, global
, name
, domain
, match
,
1291 struct compunit_symtab
*cust
= psymtab_to_symtab (objfile
, ps
);
1292 struct block
*block
;
1296 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
1297 if (map_block (name
, domain
, objfile
, block
,
1298 callback
, data
, match
))
1300 if (callback (block
, NULL
, data
))
1306 /* A helper for psym_expand_symtabs_matching that handles
1307 searching included psymtabs. This returns 1 if a symbol is found,
1308 and zero otherwise. It also updates the 'searched_flag' on the
1309 various psymtabs that it searches. */
1312 recursively_search_psymtabs (struct partial_symtab
*ps
,
1313 struct objfile
*objfile
,
1314 enum search_domain kind
,
1315 expand_symtabs_symbol_matcher_ftype
*sym_matcher
,
1318 struct partial_symbol
**psym
;
1319 struct partial_symbol
**bound
, **gbound
, **sbound
;
1321 enum psymtab_search_status result
= PST_SEARCHED_AND_NOT_FOUND
;
1324 if (ps
->searched_flag
!= PST_NOT_SEARCHED
)
1325 return ps
->searched_flag
== PST_SEARCHED_AND_FOUND
;
1327 /* Recurse into shared psymtabs first, because they may have already
1328 been searched, and this could save some time. */
1329 for (i
= 0; i
< ps
->number_of_dependencies
; ++i
)
1333 /* Skip non-shared dependencies, these are handled elsewhere. */
1334 if (ps
->dependencies
[i
]->user
== NULL
)
1337 r
= recursively_search_psymtabs (ps
->dependencies
[i
],
1338 objfile
, kind
, sym_matcher
, data
);
1341 ps
->searched_flag
= PST_SEARCHED_AND_FOUND
;
1346 gbound
= (objfile
->global_psymbols
.list
1347 + ps
->globals_offset
+ ps
->n_global_syms
);
1348 sbound
= (objfile
->static_psymbols
.list
1349 + ps
->statics_offset
+ ps
->n_static_syms
);
1352 /* Go through all of the symbols stored in a partial
1353 symtab in one loop. */
1354 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
1359 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
1361 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
1372 if ((kind
== ALL_DOMAIN
1373 || (kind
== VARIABLES_DOMAIN
1374 && PSYMBOL_CLASS (*psym
) != LOC_TYPEDEF
1375 && PSYMBOL_CLASS (*psym
) != LOC_BLOCK
)
1376 || (kind
== FUNCTIONS_DOMAIN
1377 && PSYMBOL_CLASS (*psym
) == LOC_BLOCK
)
1378 || (kind
== TYPES_DOMAIN
1379 && PSYMBOL_CLASS (*psym
) == LOC_TYPEDEF
))
1380 && (*sym_matcher
) (SYMBOL_SEARCH_NAME (*psym
), data
))
1382 /* Found a match, so notify our caller. */
1383 result
= PST_SEARCHED_AND_FOUND
;
1390 ps
->searched_flag
= result
;
1391 return result
== PST_SEARCHED_AND_FOUND
;
1394 /* Psymtab version of expand_symtabs_matching. See its definition in
1395 the definition of quick_symbol_functions in symfile.h. */
1398 psym_expand_symtabs_matching
1399 (struct objfile
*objfile
,
1400 expand_symtabs_file_matcher_ftype
*file_matcher
,
1401 expand_symtabs_symbol_matcher_ftype
*symbol_matcher
,
1402 expand_symtabs_exp_notify_ftype
*expansion_notify
,
1403 enum search_domain kind
,
1406 struct partial_symtab
*ps
;
1408 /* Clear the search flags. */
1409 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1411 ps
->searched_flag
= PST_NOT_SEARCHED
;
1414 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1421 /* We skip shared psymtabs because file-matching doesn't apply
1422 to them; but we search them later in the loop. */
1423 if (ps
->user
!= NULL
)
1433 match
= (*file_matcher
) (ps
->filename
, data
, 0);
1436 /* Before we invoke realpath, which can get expensive when many
1437 files are involved, do a quick comparison of the basenames. */
1438 if (basenames_may_differ
1439 || (*file_matcher
) (lbasename (ps
->filename
), data
, 1))
1440 match
= (*file_matcher
) (psymtab_to_fullname (ps
), data
, 0);
1446 if (recursively_search_psymtabs (ps
, objfile
, kind
, symbol_matcher
, data
))
1448 struct compunit_symtab
*symtab
=
1449 psymtab_to_symtab (objfile
, ps
);
1451 if (expansion_notify
!= NULL
)
1452 expansion_notify (symtab
, data
);
1457 /* Psymtab version of has_symbols. See its definition in
1458 the definition of quick_symbol_functions in symfile.h. */
1461 psym_has_symbols (struct objfile
*objfile
)
1463 return objfile
->psymtabs
!= NULL
;
1466 const struct quick_symbol_functions psym_functions
=
1469 psym_find_last_source_symtab
,
1470 psym_forget_cached_source_info
,
1471 psym_map_symtabs_matching_filename
,
1476 psym_expand_symtabs_for_function
,
1477 psym_expand_all_symtabs
,
1478 psym_expand_symtabs_with_fullname
,
1479 psym_map_matching_symbols
,
1480 psym_expand_symtabs_matching
,
1481 psym_find_pc_sect_compunit_symtab
,
1482 psym_map_symbol_filenames
1487 /* This compares two partial symbols by names, using strcmp_iw_ordered
1488 for the comparison. */
1491 compare_psymbols (const void *s1p
, const void *s2p
)
1493 struct partial_symbol
*const *s1
= (struct partial_symbol
* const*) s1p
;
1494 struct partial_symbol
*const *s2
= (struct partial_symbol
* const*) s2p
;
1496 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1
),
1497 SYMBOL_SEARCH_NAME (*s2
));
1501 sort_pst_symbols (struct objfile
*objfile
, struct partial_symtab
*pst
)
1503 /* Sort the global list; don't sort the static list. */
1505 qsort (objfile
->global_psymbols
.list
+ pst
->globals_offset
,
1506 pst
->n_global_syms
, sizeof (struct partial_symbol
*),
1510 /* Allocate and partially fill a partial symtab. It will be
1511 completely filled at the end of the symbol list.
1513 FILENAME is the name of the symbol-file we are reading from. */
1515 struct partial_symtab
*
1516 start_psymtab_common (struct objfile
*objfile
,
1517 const char *filename
,
1518 CORE_ADDR textlow
, struct partial_symbol
**global_syms
,
1519 struct partial_symbol
**static_syms
)
1521 struct partial_symtab
*psymtab
;
1523 psymtab
= allocate_psymtab (filename
, objfile
);
1524 psymtab
->textlow
= textlow
;
1525 psymtab
->texthigh
= psymtab
->textlow
; /* default */
1526 psymtab
->globals_offset
= global_syms
- objfile
->global_psymbols
.list
;
1527 psymtab
->statics_offset
= static_syms
- objfile
->static_psymbols
.list
;
1531 /* Perform "finishing up" operations of a partial symtab. */
1534 end_psymtab_common (struct objfile
*objfile
, struct partial_symtab
*pst
)
1537 = objfile
->global_psymbols
.next
- (objfile
->global_psymbols
.list
1538 + pst
->globals_offset
);
1540 = objfile
->static_psymbols
.next
- (objfile
->static_psymbols
.list
1541 + pst
->statics_offset
);
1543 sort_pst_symbols (objfile
, pst
);
1546 /* Calculate a hash code for the given partial symbol. The hash is
1547 calculated using the symbol's value, language, domain, class
1548 and name. These are the values which are set by
1549 add_psymbol_to_bcache. */
1551 static unsigned long
1552 psymbol_hash (const void *addr
, int length
)
1554 unsigned long h
= 0;
1555 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1556 unsigned int lang
= psymbol
->ginfo
.language
;
1557 unsigned int domain
= PSYMBOL_DOMAIN (psymbol
);
1558 unsigned int theclass
= PSYMBOL_CLASS (psymbol
);
1560 h
= hash_continue (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1561 h
= hash_continue (&lang
, sizeof (unsigned int), h
);
1562 h
= hash_continue (&domain
, sizeof (unsigned int), h
);
1563 h
= hash_continue (&theclass
, sizeof (unsigned int), h
);
1564 h
= hash_continue (psymbol
->ginfo
.name
, strlen (psymbol
->ginfo
.name
), h
);
1569 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1570 For the comparison this function uses a symbols value,
1571 language, domain, class and name. */
1574 psymbol_compare (const void *addr1
, const void *addr2
, int length
)
1576 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1577 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1579 return (memcmp (&sym1
->ginfo
.value
, &sym1
->ginfo
.value
,
1580 sizeof (sym1
->ginfo
.value
)) == 0
1581 && sym1
->ginfo
.language
== sym2
->ginfo
.language
1582 && PSYMBOL_DOMAIN (sym1
) == PSYMBOL_DOMAIN (sym2
)
1583 && PSYMBOL_CLASS (sym1
) == PSYMBOL_CLASS (sym2
)
1584 && sym1
->ginfo
.name
== sym2
->ginfo
.name
);
1587 /* Initialize a partial symbol bcache. */
1589 struct psymbol_bcache
*
1590 psymbol_bcache_init (void)
1592 struct psymbol_bcache
*bcache
= XCNEW (struct psymbol_bcache
);
1594 bcache
->bcache
= bcache_xmalloc (psymbol_hash
, psymbol_compare
);
1598 /* Free a partial symbol bcache. */
1601 psymbol_bcache_free (struct psymbol_bcache
*bcache
)
1606 bcache_xfree (bcache
->bcache
);
1610 /* Return the internal bcache of the psymbol_bcache BCACHE. */
1613 psymbol_bcache_get_bcache (struct psymbol_bcache
*bcache
)
1615 return bcache
->bcache
;
1618 /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1619 symbol before, add a copy to BCACHE. In either case, return a pointer
1620 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1621 1 in case of new entry or 0 if returning an old entry. */
1623 static const struct partial_symbol
*
1624 psymbol_bcache_full (struct partial_symbol
*sym
,
1625 struct psymbol_bcache
*bcache
,
1628 return ((const struct partial_symbol
*)
1629 bcache_full (sym
, sizeof (struct partial_symbol
), bcache
->bcache
,
1633 /* Helper function, initialises partial symbol structure and stashes
1634 it into objfile's bcache. Note that our caching mechanism will
1635 use all fields of struct partial_symbol to determine hash value of the
1636 structure. In other words, having two symbols with the same name but
1637 different domain (or address) is possible and correct. */
1639 static const struct partial_symbol
*
1640 add_psymbol_to_bcache (const char *name
, int namelength
, int copy_name
,
1642 enum address_class theclass
,
1644 enum language language
, struct objfile
*objfile
,
1647 struct partial_symbol psymbol
;
1649 /* We must ensure that the entire struct has been zeroed before
1650 assigning to it, because an assignment may not touch some of the
1652 memset (&psymbol
, 0, sizeof (psymbol
));
1654 SYMBOL_VALUE_ADDRESS (&psymbol
) = coreaddr
;
1655 SYMBOL_SECTION (&psymbol
) = -1;
1656 SYMBOL_SET_LANGUAGE (&psymbol
, language
, &objfile
->objfile_obstack
);
1657 PSYMBOL_DOMAIN (&psymbol
) = domain
;
1658 PSYMBOL_CLASS (&psymbol
) = theclass
;
1660 SYMBOL_SET_NAMES (&psymbol
, name
, namelength
, copy_name
, objfile
);
1662 /* Stash the partial symbol away in the cache. */
1663 return psymbol_bcache_full (&psymbol
, objfile
->psymbol_cache
, added
);
1666 /* Increase the space allocated for LISTP, which is probably
1667 global_psymbols or static_psymbols. This space will eventually
1668 be freed in free_objfile(). */
1671 extend_psymbol_list (struct psymbol_allocation_list
*listp
,
1672 struct objfile
*objfile
)
1676 if (listp
->size
== 0)
1679 listp
->list
= XNEWVEC (struct partial_symbol
*, new_size
);
1683 new_size
= listp
->size
* 2;
1684 listp
->list
= (struct partial_symbol
**)
1685 xrealloc ((char *) listp
->list
,
1686 new_size
* sizeof (struct partial_symbol
*));
1688 /* Next assumes we only went one over. Should be good if
1689 program works correctly. */
1690 listp
->next
= listp
->list
+ listp
->size
;
1691 listp
->size
= new_size
;
1694 /* Helper function, adds partial symbol to the given partial symbol list. */
1697 append_psymbol_to_list (struct psymbol_allocation_list
*list
,
1698 const struct partial_symbol
*psym
,
1699 struct objfile
*objfile
)
1701 if (list
->next
>= list
->list
+ list
->size
)
1702 extend_psymbol_list (list
, objfile
);
1703 *list
->next
++ = (struct partial_symbol
*) psym
;
1704 OBJSTAT (objfile
, n_psyms
++);
1707 /* Add a symbol with a long value to a psymtab.
1708 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1709 The only value we need to store for psyms is an address.
1710 For all other psyms pass zero for COREADDR.
1711 Return the partial symbol that has been added. */
1714 add_psymbol_to_list (const char *name
, int namelength
, int copy_name
,
1716 enum address_class theclass
,
1717 struct psymbol_allocation_list
*list
,
1719 enum language language
, struct objfile
*objfile
)
1721 const struct partial_symbol
*psym
;
1725 /* Stash the partial symbol away in the cache. */
1726 psym
= add_psymbol_to_bcache (name
, namelength
, copy_name
, domain
, theclass
,
1727 coreaddr
, language
, objfile
, &added
);
1729 /* Do not duplicate global partial symbols. */
1730 if (list
== &objfile
->global_psymbols
1734 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1735 append_psymbol_to_list (list
, psym
, objfile
);
1738 /* Initialize storage for partial symbols. */
1741 init_psymbol_list (struct objfile
*objfile
, int total_symbols
)
1743 /* Free any previously allocated psymbol lists. */
1745 if (objfile
->global_psymbols
.list
)
1746 xfree (objfile
->global_psymbols
.list
);
1747 if (objfile
->static_psymbols
.list
)
1748 xfree (objfile
->static_psymbols
.list
);
1750 /* Current best guess is that approximately a twentieth
1751 of the total symbols (in a debugging file) are global or static
1752 oriented symbols, then multiply that by slop factor of two. */
1754 objfile
->global_psymbols
.size
= total_symbols
/ 10;
1755 objfile
->static_psymbols
.size
= total_symbols
/ 10;
1757 if (objfile
->global_psymbols
.size
> 0)
1759 objfile
->global_psymbols
.next
=
1760 objfile
->global_psymbols
.list
=
1761 XNEWVEC (struct partial_symbol
*, objfile
->global_psymbols
.size
);
1763 if (objfile
->static_psymbols
.size
> 0)
1765 objfile
->static_psymbols
.next
=
1766 objfile
->static_psymbols
.list
=
1767 XNEWVEC (struct partial_symbol
*, objfile
->static_psymbols
.size
);
1771 struct partial_symtab
*
1772 allocate_psymtab (const char *filename
, struct objfile
*objfile
)
1774 struct partial_symtab
*psymtab
;
1776 if (objfile
->free_psymtabs
)
1778 psymtab
= objfile
->free_psymtabs
;
1779 objfile
->free_psymtabs
= psymtab
->next
;
1782 psymtab
= (struct partial_symtab
*)
1783 obstack_alloc (&objfile
->objfile_obstack
,
1784 sizeof (struct partial_symtab
));
1786 memset (psymtab
, 0, sizeof (struct partial_symtab
));
1788 = (const char *) bcache (filename
, strlen (filename
) + 1,
1789 objfile
->per_bfd
->filename_cache
);
1790 psymtab
->compunit_symtab
= NULL
;
1792 /* Prepend it to the psymtab list for the objfile it belongs to.
1793 Psymtabs are searched in most recent inserted -> least recent
1796 psymtab
->next
= objfile
->psymtabs
;
1797 objfile
->psymtabs
= psymtab
;
1799 if (symtab_create_debug
)
1801 /* Be a bit clever with debugging messages, and don't print objfile
1802 every time, only when it changes. */
1803 static char *last_objfile_name
= NULL
;
1805 if (last_objfile_name
== NULL
1806 || strcmp (last_objfile_name
, objfile_name (objfile
)) != 0)
1808 xfree (last_objfile_name
);
1809 last_objfile_name
= xstrdup (objfile_name (objfile
));
1810 fprintf_unfiltered (gdb_stdlog
,
1811 "Creating one or more psymtabs for objfile %s ...\n",
1814 fprintf_unfiltered (gdb_stdlog
,
1815 "Created psymtab %s for module %s.\n",
1816 host_address_to_string (psymtab
), filename
);
1823 discard_psymtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
1825 struct partial_symtab
**prev_pst
;
1828 Empty psymtabs happen as a result of header files which don't
1829 have any symbols in them. There can be a lot of them. But this
1830 check is wrong, in that a psymtab with N_SLINE entries but
1831 nothing else is not empty, but we don't realize that. Fixing
1832 that without slowing things down might be tricky. */
1834 /* First, snip it out of the psymtab chain. */
1836 prev_pst
= &(objfile
->psymtabs
);
1837 while ((*prev_pst
) != pst
)
1838 prev_pst
= &((*prev_pst
)->next
);
1839 (*prev_pst
) = pst
->next
;
1841 /* Next, put it on a free list for recycling. */
1843 pst
->next
= objfile
->free_psymtabs
;
1844 objfile
->free_psymtabs
= pst
;
1847 /* An object of this type is passed to discard_psymtabs_upto. */
1849 struct psymtab_state
1851 /* The objfile where psymtabs are discarded. */
1853 struct objfile
*objfile
;
1855 /* The first psymtab to save. */
1857 struct partial_symtab
*save
;
1860 /* A cleanup function used by make_cleanup_discard_psymtabs. */
1863 discard_psymtabs_upto (void *arg
)
1865 struct psymtab_state
*state
= (struct psymtab_state
*) arg
;
1867 while (state
->objfile
->psymtabs
!= state
->save
)
1868 discard_psymtab (state
->objfile
, state
->objfile
->psymtabs
);
1871 /* Return a new cleanup that discards all psymtabs created in OBJFILE
1872 after this function is called. */
1875 make_cleanup_discard_psymtabs (struct objfile
*objfile
)
1877 struct psymtab_state
*state
= XNEW (struct psymtab_state
);
1879 state
->objfile
= objfile
;
1880 state
->save
= objfile
->psymtabs
;
1882 return make_cleanup_dtor (discard_psymtabs_upto
, state
, xfree
);
1887 /* We need to pass a couple of items to the addrmap_foreach function,
1890 struct dump_psymtab_addrmap_data
1892 struct objfile
*objfile
;
1893 struct partial_symtab
*psymtab
;
1894 struct ui_file
*outfile
;
1896 /* Non-zero if the previously printed addrmap entry was for PSYMTAB.
1897 If so, we want to print the next one as well (since the next addrmap
1898 entry defines the end of the range). */
1899 int previous_matched
;
1902 /* Helper function for dump_psymtab_addrmap to print an addrmap entry. */
1905 dump_psymtab_addrmap_1 (void *datap
, CORE_ADDR start_addr
, void *obj
)
1907 struct dump_psymtab_addrmap_data
*data
1908 = (struct dump_psymtab_addrmap_data
*) datap
;
1909 struct gdbarch
*gdbarch
= get_objfile_arch (data
->objfile
);
1910 struct partial_symtab
*addrmap_psymtab
= (struct partial_symtab
*) obj
;
1911 const char *psymtab_address_or_end
= NULL
;
1915 if (data
->psymtab
== NULL
1916 || data
->psymtab
== addrmap_psymtab
)
1917 psymtab_address_or_end
= host_address_to_string (addrmap_psymtab
);
1918 else if (data
->previous_matched
)
1919 psymtab_address_or_end
= "<ends here>";
1921 if (data
->psymtab
== NULL
1922 || data
->psymtab
== addrmap_psymtab
1923 || data
->previous_matched
)
1925 fprintf_filtered (data
->outfile
, " %s%s %s\n",
1926 data
->psymtab
!= NULL
? " " : "",
1927 paddress (gdbarch
, start_addr
),
1928 psymtab_address_or_end
);
1931 data
->previous_matched
= (data
->psymtab
== NULL
1932 || data
->psymtab
== addrmap_psymtab
);
1937 /* Helper function for maintenance_print_psymbols to print the addrmap
1938 of PSYMTAB. If PSYMTAB is NULL print the entire addrmap. */
1941 dump_psymtab_addrmap (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
1942 struct ui_file
*outfile
)
1944 struct dump_psymtab_addrmap_data addrmap_dump_data
;
1947 || psymtab
->psymtabs_addrmap_supported
)
1949 addrmap_dump_data
.objfile
= objfile
;
1950 addrmap_dump_data
.psymtab
= psymtab
;
1951 addrmap_dump_data
.outfile
= outfile
;
1952 addrmap_dump_data
.previous_matched
= 0;
1953 fprintf_filtered (outfile
, "%sddress map:\n",
1954 psymtab
== NULL
? "Entire a" : " A");
1955 addrmap_foreach (objfile
->psymtabs_addrmap
, dump_psymtab_addrmap_1
,
1956 &addrmap_dump_data
);
1961 maintenance_print_psymbols (char *args
, int from_tty
)
1964 struct ui_file
*outfile
;
1965 struct cleanup
*cleanups
;
1966 char *symname
= NULL
;
1967 char *filename
= DEV_TTY
;
1968 struct objfile
*objfile
;
1969 struct partial_symtab
*ps
;
1976 print-psymbols takes an output file name and optional symbol file name"));
1978 argv
= gdb_buildargv (args
);
1979 cleanups
= make_cleanup_freeargv (argv
);
1981 if (argv
[0] != NULL
)
1984 /* If a second arg is supplied, it is a source file name to match on. */
1985 if (argv
[1] != NULL
)
1991 filename
= tilde_expand (filename
);
1992 make_cleanup (xfree
, filename
);
1994 outfile
= gdb_fopen (filename
, FOPEN_WT
);
1995 if (outfile
== NULL
)
1996 perror_with_name (filename
);
1997 make_cleanup_ui_file_delete (outfile
);
1999 ALL_OBJFILES (objfile
)
2001 fprintf_filtered (outfile
, "\nPartial symtabs for objfile %s\n",
2002 objfile_name (objfile
));
2004 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
2007 if (symname
== NULL
|| filename_cmp (symname
, ps
->filename
) == 0)
2009 dump_psymtab (objfile
, ps
, outfile
);
2010 dump_psymtab_addrmap (objfile
, ps
, outfile
);
2014 /* If we're printing all symbols dump the full addrmap. */
2016 if (symname
== NULL
)
2018 fprintf_filtered (outfile
, "\n");
2019 dump_psymtab_addrmap (objfile
, NULL
, outfile
);
2023 do_cleanups (cleanups
);
2026 /* List all the partial symbol tables whose names match REGEXP (optional). */
2029 maintenance_info_psymtabs (char *regexp
, int from_tty
)
2031 struct program_space
*pspace
;
2032 struct objfile
*objfile
;
2037 ALL_PSPACES (pspace
)
2038 ALL_PSPACE_OBJFILES (pspace
, objfile
)
2040 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2041 struct partial_symtab
*psymtab
;
2043 /* We don't want to print anything for this objfile until we
2044 actually find a symtab whose name matches. */
2045 int printed_objfile_start
= 0;
2047 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, psymtab
)
2052 || re_exec (psymtab
->filename
))
2054 if (! printed_objfile_start
)
2056 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
2058 printf_filtered ("((struct objfile *) %s)\n",
2059 host_address_to_string (objfile
));
2060 printed_objfile_start
= 1;
2063 printf_filtered (" { psymtab %s ", psymtab
->filename
);
2065 printf_filtered ("((struct partial_symtab *) %s)\n",
2066 host_address_to_string (psymtab
));
2068 printf_filtered (" readin %s\n",
2069 psymtab
->readin
? "yes" : "no");
2070 printf_filtered (" fullname %s\n",
2072 ? psymtab
->fullname
: "(null)");
2073 printf_filtered (" text addresses ");
2074 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
),
2076 printf_filtered (" -- ");
2077 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
),
2079 printf_filtered ("\n");
2080 printf_filtered (" psymtabs_addrmap_supported %s\n",
2081 (psymtab
->psymtabs_addrmap_supported
2083 printf_filtered (" globals ");
2084 if (psymtab
->n_global_syms
)
2086 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
2087 host_address_to_string (objfile
->global_psymbols
.list
2088 + psymtab
->globals_offset
),
2089 psymtab
->n_global_syms
);
2092 printf_filtered ("(none)\n");
2093 printf_filtered (" statics ");
2094 if (psymtab
->n_static_syms
)
2096 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
2097 host_address_to_string (objfile
->static_psymbols
.list
2098 + psymtab
->statics_offset
),
2099 psymtab
->n_static_syms
);
2102 printf_filtered ("(none)\n");
2103 printf_filtered (" dependencies ");
2104 if (psymtab
->number_of_dependencies
)
2108 printf_filtered ("{\n");
2109 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
2111 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
2113 /* Note the string concatenation there --- no comma. */
2114 printf_filtered (" psymtab %s "
2115 "((struct partial_symtab *) %s)\n",
2117 host_address_to_string (dep
));
2119 printf_filtered (" }\n");
2122 printf_filtered ("(none)\n");
2123 printf_filtered (" }\n");
2127 if (printed_objfile_start
)
2128 printf_filtered ("}\n");
2132 /* Check consistency of currently expanded psymtabs vs symtabs. */
2135 maintenance_check_psymtabs (char *ignore
, int from_tty
)
2138 struct partial_symbol
**psym
;
2139 struct compunit_symtab
*cust
= NULL
;
2140 struct partial_symtab
*ps
;
2141 const struct blockvector
*bv
;
2142 struct objfile
*objfile
;
2146 ALL_PSYMTABS (objfile
, ps
)
2148 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2150 /* We don't call psymtab_to_symtab here because that may cause symtab
2151 expansion. When debugging a problem it helps if checkers leave
2152 things unchanged. */
2153 cust
= ps
->compunit_symtab
;
2155 /* First do some checks that don't require the associated symtab. */
2156 if (ps
->texthigh
< ps
->textlow
)
2158 printf_filtered ("Psymtab ");
2159 puts_filtered (ps
->filename
);
2160 printf_filtered (" covers bad range ");
2161 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
2162 printf_filtered (" - ");
2163 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
2164 printf_filtered ("\n");
2168 /* Now do checks requiring the associated symtab. */
2171 bv
= COMPUNIT_BLOCKVECTOR (cust
);
2172 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
2173 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2174 length
= ps
->n_static_syms
;
2177 sym
= block_lookup_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
2178 SYMBOL_DOMAIN (*psym
));
2181 printf_filtered ("Static symbol `");
2182 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
2183 printf_filtered ("' only found in ");
2184 puts_filtered (ps
->filename
);
2185 printf_filtered (" psymtab\n");
2189 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2190 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2191 length
= ps
->n_global_syms
;
2194 sym
= block_lookup_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
2195 SYMBOL_DOMAIN (*psym
));
2198 printf_filtered ("Global symbol `");
2199 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
2200 printf_filtered ("' only found in ");
2201 puts_filtered (ps
->filename
);
2202 printf_filtered (" psymtab\n");
2206 if (ps
->texthigh
!= 0
2207 && (ps
->textlow
< BLOCK_START (b
) || ps
->texthigh
> BLOCK_END (b
)))
2209 printf_filtered ("Psymtab ");
2210 puts_filtered (ps
->filename
);
2211 printf_filtered (" covers ");
2212 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
2213 printf_filtered (" - ");
2214 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
2215 printf_filtered (" but symtab covers only ");
2216 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
2217 printf_filtered (" - ");
2218 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
2219 printf_filtered ("\n");
2226 extern initialize_file_ftype _initialize_psymtab
;
2229 _initialize_psymtab (void)
2231 add_cmd ("psymbols", class_maintenance
, maintenance_print_psymbols
, _("\
2232 Print dump of current partial symbol definitions.\n\
2233 Entries in the partial symbol table are dumped to file OUTFILE.\n\
2234 If a SOURCE file is specified, dump only that file's partial symbols."),
2235 &maintenanceprintlist
);
2237 add_cmd ("psymtabs", class_maintenance
, maintenance_info_psymtabs
, _("\
2238 List the partial symbol tables for all object files.\n\
2239 This does not include information about individual partial symbols,\n\
2240 just the symbol table structures themselves."),
2241 &maintenanceinfolist
);
2243 add_cmd ("check-psymtabs", class_maintenance
, maintenance_check_psymtabs
,
2245 Check consistency of currently expanded psymtabs versus symtabs."),