1 /* Partial symbol tables.
3 Copyright (C) 2009-2014 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 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 partial_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 symtab
*last_made
= objfile
->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
->symtabs
, last_made
);
156 /* Implementation of the map_symtabs_matching_filename method. */
159 partial_map_symtabs_matching_filename (struct objfile
*objfile
,
161 const char *real_path
,
162 int (*callback
) (struct symtab
*,
166 struct partial_symtab
*pst
;
167 const char *name_basename
= lbasename (name
);
169 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
171 /* We can skip shared psymtabs here, because any file name will be
172 attached to the unshared psymtab. */
173 if (pst
->user
!= NULL
)
176 /* Anonymous psymtabs don't have a file name. */
180 if (compare_filenames_for_search (pst
->filename
, name
))
182 if (partial_map_expand_apply (objfile
, name
, real_path
,
183 pst
, callback
, data
))
188 /* Before we invoke realpath, which can get expensive when many
189 files are involved, do a quick comparison of the basenames. */
190 if (! basenames_may_differ
191 && FILENAME_CMP (name_basename
, lbasename (pst
->filename
)) != 0)
194 if (compare_filenames_for_search (psymtab_to_fullname (pst
), name
))
196 if (partial_map_expand_apply (objfile
, name
, real_path
,
197 pst
, callback
, data
))
202 /* If the user gave us an absolute path, try to find the file in
203 this symtab and use its absolute path. */
204 if (real_path
!= NULL
)
206 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
207 gdb_assert (IS_ABSOLUTE_PATH (name
));
208 if (filename_cmp (psymtab_to_fullname (pst
), real_path
) == 0)
210 if (partial_map_expand_apply (objfile
, name
, real_path
,
211 pst
, callback
, data
))
221 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
222 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
224 static struct partial_symtab
*
225 find_pc_sect_psymtab_closer (struct objfile
*objfile
,
226 CORE_ADDR pc
, struct obj_section
*section
,
227 struct partial_symtab
*pst
,
228 struct bound_minimal_symbol msymbol
)
230 struct partial_symtab
*tpst
;
231 struct partial_symtab
*best_pst
= pst
;
232 CORE_ADDR best_addr
= pst
->textlow
;
234 gdb_assert (!pst
->psymtabs_addrmap_supported
);
236 /* An objfile that has its functions reordered might have
237 many partial symbol tables containing the PC, but
238 we want the partial symbol table that contains the
239 function containing the PC. */
240 if (!(objfile
->flags
& OBJF_REORDERED
) &&
241 section
== 0) /* Can't validate section this way. */
244 if (msymbol
.minsym
== NULL
)
247 /* The code range of partial symtabs sometimes overlap, so, in
248 the loop below, we need to check all partial symtabs and
249 find the one that fits better for the given PC address. We
250 select the partial symtab that contains a symbol whose
251 address is closest to the PC address. By closest we mean
252 that find_pc_sect_symbol returns the symbol with address
253 that is closest and still less than the given PC. */
254 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
256 if (pc
>= tpst
->textlow
&& pc
< tpst
->texthigh
)
258 struct partial_symbol
*p
;
261 /* NOTE: This assumes that every psymbol has a
262 corresponding msymbol, which is not necessarily
263 true; the debug info might be much richer than the
264 object's symbol table. */
265 p
= find_pc_sect_psymbol (objfile
, tpst
, pc
, section
);
267 && SYMBOL_VALUE_ADDRESS (p
)
268 == BMSYMBOL_VALUE_ADDRESS (msymbol
))
271 /* Also accept the textlow value of a psymtab as a
272 "symbol", to provide some support for partial
273 symbol tables with line information but no debug
274 symbols (e.g. those produced by an assembler). */
276 this_addr
= SYMBOL_VALUE_ADDRESS (p
);
278 this_addr
= tpst
->textlow
;
280 /* Check whether it is closer than our current
281 BEST_ADDR. Since this symbol address is
282 necessarily lower or equal to PC, the symbol closer
283 to PC is the symbol which address is the highest.
284 This way we return the psymtab which contains such
285 best match symbol. This can help in cases where the
286 symbol information/debuginfo is not complete, like
287 for instance on IRIX6 with gcc, where no debug info
288 is emitted for statics. (See also the nodebug.exp
290 if (this_addr
> best_addr
)
292 best_addr
= this_addr
;
300 /* Find which partial symtab contains PC and SECTION. Return 0 if
301 none. We return the psymtab that contains a symbol whose address
302 exactly matches PC, or, if we cannot find an exact match, the
303 psymtab that contains a symbol whose address is closest to PC. */
304 static struct partial_symtab
*
305 find_pc_sect_psymtab (struct objfile
*objfile
, CORE_ADDR pc
,
306 struct obj_section
*section
,
307 struct bound_minimal_symbol msymbol
)
309 struct partial_symtab
*pst
;
311 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
312 than the later used TEXTLOW/TEXTHIGH one. */
314 if (objfile
->psymtabs_addrmap
!= NULL
)
316 pst
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
319 /* FIXME: addrmaps currently do not handle overlayed sections,
320 so fall back to the non-addrmap case if we're debugging
321 overlays and the addrmap returned the wrong section. */
322 if (overlay_debugging
&& msymbol
.minsym
&& section
)
324 struct partial_symbol
*p
;
326 /* NOTE: This assumes that every psymbol has a
327 corresponding msymbol, which is not necessarily
328 true; the debug info might be much richer than the
329 object's symbol table. */
330 p
= find_pc_sect_psymbol (objfile
, pst
, pc
, section
);
332 || SYMBOL_VALUE_ADDRESS (p
)
333 != BMSYMBOL_VALUE_ADDRESS (msymbol
))
337 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
338 PSYMTABS_ADDRMAP we used has already the best 1-byte
339 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
340 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
349 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
350 which still have no corresponding full SYMTABs read. But it is not
351 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
354 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
355 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
356 debug info type in single OBJFILE. */
358 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
359 if (!pst
->psymtabs_addrmap_supported
360 && pc
>= pst
->textlow
&& pc
< pst
->texthigh
)
362 struct partial_symtab
*best_pst
;
364 best_pst
= find_pc_sect_psymtab_closer (objfile
, pc
, section
, pst
,
366 if (best_pst
!= NULL
)
373 static struct symtab
*
374 find_pc_sect_symtab_from_partial (struct objfile
*objfile
,
375 struct bound_minimal_symbol msymbol
,
376 CORE_ADDR pc
, struct obj_section
*section
,
379 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
, section
,
383 if (warn_if_readin
&& ps
->readin
)
384 /* Might want to error() here (in case symtab is corrupt and
385 will cause a core dump), but maybe we can successfully
386 continue, so let's not. */
388 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
389 paddress (get_objfile_arch (objfile
), pc
));
390 psymtab_to_symtab (objfile
, ps
);
396 /* Find which partial symbol within a psymtab matches PC and SECTION.
399 static struct partial_symbol
*
400 find_pc_sect_psymbol (struct objfile
*objfile
,
401 struct partial_symtab
*psymtab
, CORE_ADDR pc
,
402 struct obj_section
*section
)
404 struct partial_symbol
*best
= NULL
, *p
, **pp
;
407 gdb_assert (psymtab
!= NULL
);
409 /* Cope with programs that start at address 0. */
410 best_pc
= (psymtab
->textlow
!= 0) ? psymtab
->textlow
- 1 : 0;
412 /* Search the global symbols as well as the static symbols, so that
413 find_pc_partial_function doesn't use a minimal symbol and thus
414 cache a bad endaddr. */
415 for (pp
= objfile
->global_psymbols
.list
+ psymtab
->globals_offset
;
416 (pp
- (objfile
->global_psymbols
.list
+ psymtab
->globals_offset
)
417 < psymtab
->n_global_syms
);
421 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
422 && PSYMBOL_CLASS (p
) == LOC_BLOCK
423 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
424 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
425 || (psymtab
->textlow
== 0
426 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
428 if (section
) /* Match on a specific section. */
430 fixup_psymbol_section (p
, objfile
);
431 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (objfile
, p
),
435 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
440 for (pp
= objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
441 (pp
- (objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
442 < psymtab
->n_static_syms
);
446 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
447 && PSYMBOL_CLASS (p
) == LOC_BLOCK
448 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
449 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
450 || (psymtab
->textlow
== 0
451 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
453 if (section
) /* Match on a specific section. */
455 fixup_psymbol_section (p
, objfile
);
456 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (objfile
, p
),
460 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
469 fixup_psymbol_section (struct partial_symbol
*psym
, struct objfile
*objfile
)
476 if (SYMBOL_SECTION (psym
) >= 0)
479 gdb_assert (objfile
);
481 switch (PSYMBOL_CLASS (psym
))
486 addr
= SYMBOL_VALUE_ADDRESS (psym
);
489 /* Nothing else will be listed in the minsyms -- no use looking
494 fixup_section (&psym
->ginfo
, addr
, objfile
);
497 static struct symtab
*
498 lookup_symbol_aux_psymtabs (struct objfile
*objfile
,
499 int block_index
, const char *name
,
500 const domain_enum domain
)
502 struct partial_symtab
*ps
;
503 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
504 struct symtab
*stab_best
= NULL
;
506 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
508 if (!ps
->readin
&& lookup_partial_symbol (objfile
, ps
, name
,
509 psymtab_index
, domain
))
511 struct symbol
*sym
= NULL
;
512 struct symtab
*stab
= psymtab_to_symtab (objfile
, ps
);
514 /* Some caution must be observed with overloaded functions
515 and methods, since the psymtab will not contain any overload
516 information (but NAME might contain it). */
519 const struct blockvector
*bv
= BLOCKVECTOR (stab
);
520 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
522 sym
= lookup_block_symbol (block
, name
, domain
);
525 if (sym
&& strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
527 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
533 /* Keep looking through other psymtabs. */
540 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
541 the global block of PST if GLOBAL, and otherwise the static block.
542 MATCH is the comparison operation that returns true iff MATCH (s,
543 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
544 non-null, the symbols in the block are assumed to be ordered
545 according to it (allowing binary search). It must be compatible
546 with MATCH. Returns the symbol, if found, and otherwise NULL. */
548 static struct partial_symbol
*
549 match_partial_symbol (struct objfile
*objfile
,
550 struct partial_symtab
*pst
, int global
,
551 const char *name
, domain_enum domain
,
552 symbol_compare_ftype
*match
,
553 symbol_compare_ftype
*ordered_compare
)
555 struct partial_symbol
**start
, **psym
;
556 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
557 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
558 int do_linear_search
= 1;
563 objfile
->global_psymbols
.list
+ pst
->globals_offset
:
564 objfile
->static_psymbols
.list
+ pst
->statics_offset
);
566 if (global
&& ordered_compare
) /* Can use a binary search. */
568 do_linear_search
= 0;
570 /* Binary search. This search is guaranteed to end with center
571 pointing at the earliest partial symbol whose name might be
572 correct. At that point *all* partial symbols with an
573 appropriate name will be checked against the correct
577 top
= start
+ length
- 1;
581 center
= bottom
+ (top
- bottom
) / 2;
582 gdb_assert (center
< top
);
583 if (!do_linear_search
584 && (SYMBOL_LANGUAGE (*center
) == language_java
))
585 do_linear_search
= 1;
586 if (ordered_compare (SYMBOL_SEARCH_NAME (*center
), name
) >= 0)
591 gdb_assert (top
== bottom
);
593 while (top
<= real_top
594 && match (SYMBOL_SEARCH_NAME (*top
), name
) == 0)
596 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top
),
597 SYMBOL_DOMAIN (*top
), domain
))
603 /* Can't use a binary search or else we found during the binary search that
604 we should also do a linear search. */
606 if (do_linear_search
)
608 for (psym
= start
; psym
< start
+ length
; psym
++)
610 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym
),
611 SYMBOL_DOMAIN (*psym
), domain
)
612 && match (SYMBOL_SEARCH_NAME (*psym
), name
) == 0)
620 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
621 not contain any method/function instance information (since this would
622 force reading type information while reading psymtabs). Therefore,
623 if NAME contains overload information, it must be stripped before searching
626 The caller is responsible for freeing the return result. */
629 psymtab_search_name (const char *name
)
631 switch (current_language
->la_language
)
636 if (strchr (name
, '('))
638 char *ret
= cp_remove_params (name
);
650 return xstrdup (name
);
653 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
654 Check the global symbols if GLOBAL, the static symbols if not. */
656 static struct partial_symbol
*
657 lookup_partial_symbol (struct objfile
*objfile
,
658 struct partial_symtab
*pst
, const char *name
,
659 int global
, domain_enum domain
)
661 struct partial_symbol
**start
, **psym
;
662 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
663 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
664 int do_linear_search
= 1;
666 struct cleanup
*cleanup
;
673 search_name
= psymtab_search_name (name
);
674 cleanup
= make_cleanup (xfree
, search_name
);
676 objfile
->global_psymbols
.list
+ pst
->globals_offset
:
677 objfile
->static_psymbols
.list
+ pst
->statics_offset
);
679 if (global
) /* This means we can use a binary search. */
681 do_linear_search
= 0;
683 /* Binary search. This search is guaranteed to end with center
684 pointing at the earliest partial symbol whose name might be
685 correct. At that point *all* partial symbols with an
686 appropriate name will be checked against the correct
690 top
= start
+ length
- 1;
694 center
= bottom
+ (top
- bottom
) / 2;
696 internal_error (__FILE__
, __LINE__
,
697 _("failed internal consistency check"));
698 if (!do_linear_search
699 && SYMBOL_LANGUAGE (*center
) == language_java
)
701 do_linear_search
= 1;
703 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center
),
713 if (!(top
== bottom
))
714 internal_error (__FILE__
, __LINE__
,
715 _("failed internal consistency check"));
717 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
718 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
719 while (top
>= start
&& SYMBOL_MATCHES_SEARCH_NAME (*top
, search_name
))
722 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
725 while (top
<= real_top
&& SYMBOL_MATCHES_SEARCH_NAME (*top
, search_name
))
727 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top
),
728 SYMBOL_DOMAIN (*top
), domain
))
730 do_cleanups (cleanup
);
737 /* Can't use a binary search or else we found during the binary search that
738 we should also do a linear search. */
740 if (do_linear_search
)
742 for (psym
= start
; psym
< start
+ length
; psym
++)
744 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym
),
745 SYMBOL_DOMAIN (*psym
), domain
)
746 && SYMBOL_MATCHES_SEARCH_NAME (*psym
, search_name
))
748 do_cleanups (cleanup
);
754 do_cleanups (cleanup
);
758 /* Get the symbol table that corresponds to a partial_symtab.
759 This is fast after the first time you do it. */
761 static struct symtab
*
762 psymtab_to_symtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
764 /* If it is a shared psymtab, find an unshared psymtab that includes
765 it. Any such psymtab will do. */
766 while (pst
->user
!= NULL
)
769 /* If it's been looked up before, return it. */
773 /* If it has not yet been read in, read it. */
776 struct cleanup
*back_to
= increment_reading_symtab ();
778 (*pst
->read_symtab
) (pst
, objfile
);
779 do_cleanups (back_to
);
786 relocate_psymtabs (struct objfile
*objfile
,
787 const struct section_offsets
*new_offsets
,
788 const struct section_offsets
*delta
)
790 struct partial_symbol
**psym
;
791 struct partial_symtab
*p
;
793 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, p
)
795 p
->textlow
+= ANOFFSET (delta
, SECT_OFF_TEXT (objfile
));
796 p
->texthigh
+= ANOFFSET (delta
, SECT_OFF_TEXT (objfile
));
799 for (psym
= objfile
->global_psymbols
.list
;
800 psym
< objfile
->global_psymbols
.next
;
803 fixup_psymbol_section (*psym
, objfile
);
804 if (SYMBOL_SECTION (*psym
) >= 0)
805 SYMBOL_VALUE_ADDRESS (*psym
) += ANOFFSET (delta
,
806 SYMBOL_SECTION (*psym
));
808 for (psym
= objfile
->static_psymbols
.list
;
809 psym
< objfile
->static_psymbols
.next
;
812 fixup_psymbol_section (*psym
, objfile
);
813 if (SYMBOL_SECTION (*psym
) >= 0)
814 SYMBOL_VALUE_ADDRESS (*psym
) += ANOFFSET (delta
,
815 SYMBOL_SECTION (*psym
));
819 static struct symtab
*
820 find_last_source_symtab_from_partial (struct objfile
*ofp
)
822 struct partial_symtab
*ps
;
823 struct partial_symtab
*cs_pst
= 0;
825 ALL_OBJFILE_PSYMTABS_REQUIRED (ofp
, ps
)
827 const char *name
= ps
->filename
;
828 int len
= strlen (name
);
830 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
831 || strcmp (name
, "<<C++-namespaces>>") == 0)))
839 internal_error (__FILE__
, __LINE__
,
840 _("select_source_symtab: "
841 "readin pst found and no symtabs."));
844 return psymtab_to_symtab (ofp
, cs_pst
);
850 forget_cached_source_info_partial (struct objfile
*objfile
)
852 struct partial_symtab
*pst
;
854 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
856 if (pst
->fullname
!= NULL
)
858 xfree (pst
->fullname
);
859 pst
->fullname
= NULL
;
865 print_partial_symbols (struct gdbarch
*gdbarch
,
866 struct partial_symbol
**p
, int count
, char *what
,
867 struct ui_file
*outfile
)
869 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
873 fprintf_filtered (outfile
, " `%s'", SYMBOL_LINKAGE_NAME (*p
));
874 if (SYMBOL_DEMANGLED_NAME (*p
) != NULL
)
876 fprintf_filtered (outfile
, " `%s'", SYMBOL_DEMANGLED_NAME (*p
));
878 fputs_filtered (", ", outfile
);
879 switch (SYMBOL_DOMAIN (*p
))
882 fputs_filtered ("undefined domain, ", outfile
);
885 /* This is the usual thing -- don't print it. */
888 fputs_filtered ("struct domain, ", outfile
);
891 fputs_filtered ("label domain, ", outfile
);
894 fputs_filtered ("<invalid domain>, ", outfile
);
897 switch (PSYMBOL_CLASS (*p
))
900 fputs_filtered ("undefined", outfile
);
903 fputs_filtered ("constant int", outfile
);
906 fputs_filtered ("static", outfile
);
909 fputs_filtered ("register", outfile
);
912 fputs_filtered ("pass by value", outfile
);
915 fputs_filtered ("pass by reference", outfile
);
917 case LOC_REGPARM_ADDR
:
918 fputs_filtered ("register address parameter", outfile
);
921 fputs_filtered ("stack parameter", outfile
);
924 fputs_filtered ("type", outfile
);
927 fputs_filtered ("label", outfile
);
930 fputs_filtered ("function", outfile
);
932 case LOC_CONST_BYTES
:
933 fputs_filtered ("constant bytes", outfile
);
936 fputs_filtered ("unresolved", outfile
);
938 case LOC_OPTIMIZED_OUT
:
939 fputs_filtered ("optimized out", outfile
);
942 fputs_filtered ("computed at runtime", outfile
);
945 fputs_filtered ("<invalid location>", outfile
);
948 fputs_filtered (", ", outfile
);
949 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (*p
)), outfile
);
950 fprintf_filtered (outfile
, "\n");
956 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
957 struct ui_file
*outfile
)
959 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
962 if (psymtab
->anonymous
)
964 fprintf_filtered (outfile
, "\nAnonymous partial symtab (%s) ",
969 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
972 fprintf_filtered (outfile
, "(object ");
973 gdb_print_host_address (psymtab
, outfile
);
974 fprintf_filtered (outfile
, ")\n\n");
975 fprintf_unfiltered (outfile
, " Read from object file %s (",
976 objfile_name (objfile
));
977 gdb_print_host_address (objfile
, outfile
);
978 fprintf_unfiltered (outfile
, ")\n");
982 fprintf_filtered (outfile
,
983 " Full symtab was read (at ");
984 gdb_print_host_address (psymtab
->symtab
, outfile
);
985 fprintf_filtered (outfile
, " by function at ");
986 gdb_print_host_address (psymtab
->read_symtab
, outfile
);
987 fprintf_filtered (outfile
, ")\n");
990 fprintf_filtered (outfile
, " Relocate symbols by ");
991 for (i
= 0; i
< objfile
->num_sections
; ++i
)
994 fprintf_filtered (outfile
, ", ");
996 fputs_filtered (paddress (gdbarch
,
997 ANOFFSET (psymtab
->section_offsets
, i
)),
1000 fprintf_filtered (outfile
, "\n");
1002 fprintf_filtered (outfile
, " Symbols cover text addresses ");
1003 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
), outfile
);
1004 fprintf_filtered (outfile
, "-");
1005 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
), outfile
);
1006 fprintf_filtered (outfile
, "\n");
1007 fprintf_filtered (outfile
, " Address map supported - %s.\n",
1008 psymtab
->psymtabs_addrmap_supported
? "yes" : "no");
1009 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
1010 psymtab
->number_of_dependencies
);
1011 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1013 fprintf_filtered (outfile
, " %d ", i
);
1014 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
1015 fprintf_filtered (outfile
, " %s\n",
1016 psymtab
->dependencies
[i
]->filename
);
1018 if (psymtab
->user
!= NULL
)
1020 fprintf_filtered (outfile
, " Shared partial symtab with user ");
1021 gdb_print_host_address (psymtab
->user
, outfile
);
1022 fprintf_filtered (outfile
, "\n");
1024 if (psymtab
->n_global_syms
> 0)
1026 print_partial_symbols (gdbarch
,
1027 objfile
->global_psymbols
.list
1028 + psymtab
->globals_offset
,
1029 psymtab
->n_global_syms
, "Global", outfile
);
1031 if (psymtab
->n_static_syms
> 0)
1033 print_partial_symbols (gdbarch
,
1034 objfile
->static_psymbols
.list
1035 + psymtab
->statics_offset
,
1036 psymtab
->n_static_syms
, "Static", outfile
);
1038 fprintf_filtered (outfile
, "\n");
1042 print_psymtab_stats_for_objfile (struct objfile
*objfile
)
1045 struct partial_symtab
*ps
;
1048 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1050 if (ps
->readin
== 0)
1053 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i
);
1057 dump_psymtabs_for_objfile (struct objfile
*objfile
)
1059 struct partial_symtab
*psymtab
;
1061 if (objfile
->psymtabs
)
1063 printf_filtered ("Psymtabs:\n");
1064 for (psymtab
= objfile
->psymtabs
;
1066 psymtab
= psymtab
->next
)
1068 printf_filtered ("%s at ",
1070 gdb_print_host_address (psymtab
, gdb_stdout
);
1071 printf_filtered (", ");
1074 printf_filtered ("\n\n");
1078 /* Look through the partial symtabs for all symbols which begin
1079 by matching FUNC_NAME. Make sure we read that symbol table in. */
1082 read_symtabs_for_function (struct objfile
*objfile
, const char *func_name
)
1084 struct partial_symtab
*ps
;
1086 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1091 if ((lookup_partial_symbol (objfile
, ps
, func_name
, 1, VAR_DOMAIN
)
1093 || (lookup_partial_symbol (objfile
, ps
, func_name
, 0, VAR_DOMAIN
)
1095 psymtab_to_symtab (objfile
, ps
);
1100 expand_partial_symbol_tables (struct objfile
*objfile
)
1102 struct partial_symtab
*psymtab
;
1104 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, psymtab
)
1106 psymtab_to_symtab (objfile
, psymtab
);
1111 read_psymtabs_with_fullname (struct objfile
*objfile
, const char *fullname
)
1113 struct partial_symtab
*p
;
1115 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, p
)
1117 /* Anonymous psymtabs don't have a name of a source file. */
1121 /* psymtab_to_fullname tries to open the file which is slow.
1122 Don't call it if we know the basenames don't match. */
1123 if ((basenames_may_differ
1124 || filename_cmp (lbasename (fullname
), lbasename (p
->filename
)) == 0)
1125 && filename_cmp (fullname
, psymtab_to_fullname (p
)) == 0)
1126 psymtab_to_symtab (objfile
, p
);
1131 map_symbol_filenames_psymtab (struct objfile
*objfile
,
1132 symbol_filename_ftype
*fun
, void *data
,
1135 struct partial_symtab
*ps
;
1137 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1139 const char *fullname
;
1144 /* We can skip shared psymtabs here, because any file name will be
1145 attached to the unshared psymtab. */
1146 if (ps
->user
!= NULL
)
1149 /* Anonymous psymtabs don't have a file name. */
1155 fullname
= psymtab_to_fullname (ps
);
1158 (*fun
) (ps
->filename
, fullname
, data
);
1162 /* Finds the fullname that a partial_symtab represents.
1164 If this functions finds the fullname, it will save it in ps->fullname
1165 and it will also return the value.
1167 If this function fails to find the file that this partial_symtab represents,
1168 NULL will be returned and ps->fullname will be set to NULL. */
1171 psymtab_to_fullname (struct partial_symtab
*ps
)
1173 gdb_assert (!ps
->anonymous
);
1175 /* Use cached copy if we have it.
1176 We rely on forget_cached_source_info being called appropriately
1177 to handle cases like the file being moved. */
1178 if (ps
->fullname
== NULL
)
1180 int fd
= find_and_open_source (ps
->filename
, ps
->dirname
, &ps
->fullname
);
1187 struct cleanup
*back_to
;
1189 /* rewrite_source_path would be applied by find_and_open_source, we
1190 should report the pathname where GDB tried to find the file. */
1192 if (ps
->dirname
== NULL
|| IS_ABSOLUTE_PATH (ps
->filename
))
1193 fullname
= xstrdup (ps
->filename
);
1195 fullname
= concat (ps
->dirname
, SLASH_STRING
, ps
->filename
, NULL
);
1197 back_to
= make_cleanup (xfree
, fullname
);
1198 ps
->fullname
= rewrite_source_path (fullname
);
1199 if (ps
->fullname
== NULL
)
1200 ps
->fullname
= xstrdup (fullname
);
1201 do_cleanups (back_to
);
1205 return ps
->fullname
;
1208 /* For all symbols, s, in BLOCK that are in NAMESPACE and match NAME
1209 according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
1210 BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK
1211 ever returns non-zero, and otherwise returns 0. */
1214 map_block (const char *name
, domain_enum
namespace, struct objfile
*objfile
,
1215 struct block
*block
,
1216 int (*callback
) (struct block
*, struct symbol
*, void *),
1217 void *data
, symbol_compare_ftype
*match
)
1219 struct block_iterator iter
;
1222 for (sym
= block_iter_match_first (block
, name
, match
, &iter
);
1223 sym
!= NULL
; sym
= block_iter_match_next (name
, match
, &iter
))
1225 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym
),
1226 SYMBOL_DOMAIN (sym
), namespace))
1228 if (callback (block
, sym
, data
))
1236 /* Psymtab version of map_matching_symbols. See its definition in
1237 the definition of quick_symbol_functions in symfile.h. */
1240 map_matching_symbols_psymtab (struct objfile
*objfile
,
1241 const char *name
, domain_enum
namespace,
1243 int (*callback
) (struct block
*,
1244 struct symbol
*, void *),
1246 symbol_compare_ftype
*match
,
1247 symbol_compare_ftype
*ordered_compare
)
1249 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
1250 struct partial_symtab
*ps
;
1252 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1256 || match_partial_symbol (objfile
, ps
, global
, name
, namespace, match
,
1259 struct symtab
*s
= psymtab_to_symtab (objfile
, ps
);
1260 struct block
*block
;
1262 if (s
== NULL
|| !s
->primary
)
1264 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), block_kind
);
1265 if (map_block (name
, namespace, objfile
, block
,
1266 callback
, data
, match
))
1268 if (callback (block
, NULL
, data
))
1274 /* A helper for expand_symtabs_matching_via_partial that handles
1275 searching included psymtabs. This returns 1 if a symbol is found,
1276 and zero otherwise. It also updates the 'searched_flag' on the
1277 various psymtabs that it searches. */
1280 recursively_search_psymtabs (struct partial_symtab
*ps
,
1281 struct objfile
*objfile
,
1282 enum search_domain kind
,
1283 expand_symtabs_symbol_matcher_ftype
*sym_matcher
,
1286 struct partial_symbol
**psym
;
1287 struct partial_symbol
**bound
, **gbound
, **sbound
;
1289 int result
= PST_SEARCHED_AND_NOT_FOUND
;
1292 if (ps
->searched_flag
!= PST_NOT_SEARCHED
)
1293 return ps
->searched_flag
== PST_SEARCHED_AND_FOUND
;
1295 /* Recurse into shared psymtabs first, because they may have already
1296 been searched, and this could save some time. */
1297 for (i
= 0; i
< ps
->number_of_dependencies
; ++i
)
1301 /* Skip non-shared dependencies, these are handled elsewhere. */
1302 if (ps
->dependencies
[i
]->user
== NULL
)
1305 r
= recursively_search_psymtabs (ps
->dependencies
[i
],
1306 objfile
, kind
, sym_matcher
, data
);
1309 ps
->searched_flag
= PST_SEARCHED_AND_FOUND
;
1314 gbound
= (objfile
->global_psymbols
.list
1315 + ps
->globals_offset
+ ps
->n_global_syms
);
1316 sbound
= (objfile
->static_psymbols
.list
1317 + ps
->statics_offset
+ ps
->n_static_syms
);
1320 /* Go through all of the symbols stored in a partial
1321 symtab in one loop. */
1322 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
1327 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
1329 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
1340 if ((kind
== ALL_DOMAIN
1341 || (kind
== VARIABLES_DOMAIN
1342 && PSYMBOL_CLASS (*psym
) != LOC_TYPEDEF
1343 && PSYMBOL_CLASS (*psym
) != LOC_BLOCK
)
1344 || (kind
== FUNCTIONS_DOMAIN
1345 && PSYMBOL_CLASS (*psym
) == LOC_BLOCK
)
1346 || (kind
== TYPES_DOMAIN
1347 && PSYMBOL_CLASS (*psym
) == LOC_TYPEDEF
))
1348 && (*sym_matcher
) (SYMBOL_SEARCH_NAME (*psym
), data
))
1350 /* Found a match, so notify our caller. */
1351 result
= PST_SEARCHED_AND_FOUND
;
1358 ps
->searched_flag
= result
;
1359 return result
== PST_SEARCHED_AND_FOUND
;
1363 expand_symtabs_matching_via_partial
1364 (struct objfile
*objfile
,
1365 expand_symtabs_file_matcher_ftype
*file_matcher
,
1366 expand_symtabs_symbol_matcher_ftype
*symbol_matcher
,
1367 enum search_domain kind
,
1370 struct partial_symtab
*ps
;
1372 /* Clear the search flags. */
1373 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1375 ps
->searched_flag
= PST_NOT_SEARCHED
;
1378 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1383 /* We skip shared psymtabs because file-matching doesn't apply
1384 to them; but we search them later in the loop. */
1385 if (ps
->user
!= NULL
)
1395 match
= (*file_matcher
) (ps
->filename
, data
, 0);
1398 /* Before we invoke realpath, which can get expensive when many
1399 files are involved, do a quick comparison of the basenames. */
1400 if (basenames_may_differ
1401 || (*file_matcher
) (lbasename (ps
->filename
), data
, 1))
1402 match
= (*file_matcher
) (psymtab_to_fullname (ps
), data
, 0);
1408 if (recursively_search_psymtabs (ps
, objfile
, kind
, symbol_matcher
, data
))
1409 psymtab_to_symtab (objfile
, ps
);
1414 objfile_has_psyms (struct objfile
*objfile
)
1416 return objfile
->psymtabs
!= NULL
;
1419 const struct quick_symbol_functions psym_functions
=
1422 find_last_source_symtab_from_partial
,
1423 forget_cached_source_info_partial
,
1424 partial_map_symtabs_matching_filename
,
1425 lookup_symbol_aux_psymtabs
,
1426 print_psymtab_stats_for_objfile
,
1427 dump_psymtabs_for_objfile
,
1429 read_symtabs_for_function
,
1430 expand_partial_symbol_tables
,
1431 read_psymtabs_with_fullname
,
1432 map_matching_symbols_psymtab
,
1433 expand_symtabs_matching_via_partial
,
1434 find_pc_sect_symtab_from_partial
,
1435 map_symbol_filenames_psymtab
1440 /* This compares two partial symbols by names, using strcmp_iw_ordered
1441 for the comparison. */
1444 compare_psymbols (const void *s1p
, const void *s2p
)
1446 struct partial_symbol
*const *s1
= s1p
;
1447 struct partial_symbol
*const *s2
= s2p
;
1449 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1
),
1450 SYMBOL_SEARCH_NAME (*s2
));
1454 sort_pst_symbols (struct objfile
*objfile
, struct partial_symtab
*pst
)
1456 /* Sort the global list; don't sort the static list. */
1458 qsort (objfile
->global_psymbols
.list
+ pst
->globals_offset
,
1459 pst
->n_global_syms
, sizeof (struct partial_symbol
*),
1463 /* Allocate and partially fill a partial symtab. It will be
1464 completely filled at the end of the symbol list.
1466 FILENAME is the name of the symbol-file we are reading from. */
1468 struct partial_symtab
*
1469 start_psymtab_common (struct objfile
*objfile
,
1470 struct section_offsets
*section_offsets
,
1471 const char *filename
,
1472 CORE_ADDR textlow
, struct partial_symbol
**global_syms
,
1473 struct partial_symbol
**static_syms
)
1475 struct partial_symtab
*psymtab
;
1477 psymtab
= allocate_psymtab (filename
, objfile
);
1478 psymtab
->section_offsets
= section_offsets
;
1479 psymtab
->textlow
= textlow
;
1480 psymtab
->texthigh
= psymtab
->textlow
; /* default */
1481 psymtab
->globals_offset
= global_syms
- objfile
->global_psymbols
.list
;
1482 psymtab
->statics_offset
= static_syms
- objfile
->static_psymbols
.list
;
1486 /* Calculate a hash code for the given partial symbol. The hash is
1487 calculated using the symbol's value, language, domain, class
1488 and name. These are the values which are set by
1489 add_psymbol_to_bcache. */
1491 static unsigned long
1492 psymbol_hash (const void *addr
, int length
)
1494 unsigned long h
= 0;
1495 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1496 unsigned int lang
= psymbol
->ginfo
.language
;
1497 unsigned int domain
= PSYMBOL_DOMAIN (psymbol
);
1498 unsigned int class = PSYMBOL_CLASS (psymbol
);
1500 h
= hash_continue (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1501 h
= hash_continue (&lang
, sizeof (unsigned int), h
);
1502 h
= hash_continue (&domain
, sizeof (unsigned int), h
);
1503 h
= hash_continue (&class, sizeof (unsigned int), h
);
1504 h
= hash_continue (psymbol
->ginfo
.name
, strlen (psymbol
->ginfo
.name
), h
);
1509 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1510 For the comparison this function uses a symbols value,
1511 language, domain, class and name. */
1514 psymbol_compare (const void *addr1
, const void *addr2
, int length
)
1516 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1517 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1519 return (memcmp (&sym1
->ginfo
.value
, &sym1
->ginfo
.value
,
1520 sizeof (sym1
->ginfo
.value
)) == 0
1521 && sym1
->ginfo
.language
== sym2
->ginfo
.language
1522 && PSYMBOL_DOMAIN (sym1
) == PSYMBOL_DOMAIN (sym2
)
1523 && PSYMBOL_CLASS (sym1
) == PSYMBOL_CLASS (sym2
)
1524 && sym1
->ginfo
.name
== sym2
->ginfo
.name
);
1527 /* Initialize a partial symbol bcache. */
1529 struct psymbol_bcache
*
1530 psymbol_bcache_init (void)
1532 struct psymbol_bcache
*bcache
= XCNEW (struct psymbol_bcache
);
1533 bcache
->bcache
= bcache_xmalloc (psymbol_hash
, psymbol_compare
);
1537 /* Free a partial symbol bcache. */
1539 psymbol_bcache_free (struct psymbol_bcache
*bcache
)
1544 bcache_xfree (bcache
->bcache
);
1548 /* Return the internal bcache of the psymbol_bcache BCACHE. */
1551 psymbol_bcache_get_bcache (struct psymbol_bcache
*bcache
)
1553 return bcache
->bcache
;
1556 /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1557 symbol before, add a copy to BCACHE. In either case, return a pointer
1558 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1559 1 in case of new entry or 0 if returning an old entry. */
1561 static const struct partial_symbol
*
1562 psymbol_bcache_full (struct partial_symbol
*sym
,
1563 struct psymbol_bcache
*bcache
,
1566 return bcache_full (sym
,
1567 sizeof (struct partial_symbol
),
1572 /* Helper function, initialises partial symbol structure and stashes
1573 it into objfile's bcache. Note that our caching mechanism will
1574 use all fields of struct partial_symbol to determine hash value of the
1575 structure. In other words, having two symbols with the same name but
1576 different domain (or address) is possible and correct. */
1578 static const struct partial_symbol
*
1579 add_psymbol_to_bcache (const char *name
, int namelength
, int copy_name
,
1581 enum address_class
class,
1582 long val
, /* Value as a long */
1583 CORE_ADDR coreaddr
, /* Value as a CORE_ADDR */
1584 enum language language
, struct objfile
*objfile
,
1587 struct partial_symbol psymbol
;
1589 /* We must ensure that the entire struct has been zeroed before
1590 assigning to it, because an assignment may not touch some of the
1592 memset (&psymbol
, 0, sizeof (psymbol
));
1594 /* val and coreaddr are mutually exclusive, one of them *will* be zero. */
1597 SYMBOL_VALUE (&psymbol
) = val
;
1601 SYMBOL_VALUE_ADDRESS (&psymbol
) = coreaddr
;
1603 SYMBOL_SECTION (&psymbol
) = -1;
1604 SYMBOL_SET_LANGUAGE (&psymbol
, language
, &objfile
->objfile_obstack
);
1605 PSYMBOL_DOMAIN (&psymbol
) = domain
;
1606 PSYMBOL_CLASS (&psymbol
) = class;
1608 SYMBOL_SET_NAMES (&psymbol
, name
, namelength
, copy_name
, objfile
);
1610 /* Stash the partial symbol away in the cache. */
1611 return psymbol_bcache_full (&psymbol
,
1612 objfile
->psymbol_cache
,
1616 /* Increase the space allocated for LISTP, which is probably
1617 global_psymbols or static_psymbols. This space will eventually
1618 be freed in free_objfile(). */
1621 extend_psymbol_list (struct psymbol_allocation_list
*listp
,
1622 struct objfile
*objfile
)
1626 if (listp
->size
== 0)
1629 listp
->list
= (struct partial_symbol
**)
1630 xmalloc (new_size
* sizeof (struct partial_symbol
*));
1634 new_size
= listp
->size
* 2;
1635 listp
->list
= (struct partial_symbol
**)
1636 xrealloc ((char *) listp
->list
,
1637 new_size
* sizeof (struct partial_symbol
*));
1639 /* Next assumes we only went one over. Should be good if
1640 program works correctly. */
1641 listp
->next
= listp
->list
+ listp
->size
;
1642 listp
->size
= new_size
;
1645 /* Helper function, adds partial symbol to the given partial symbol
1649 append_psymbol_to_list (struct psymbol_allocation_list
*list
,
1650 const struct partial_symbol
*psym
,
1651 struct objfile
*objfile
)
1653 if (list
->next
>= list
->list
+ list
->size
)
1654 extend_psymbol_list (list
, objfile
);
1655 *list
->next
++ = (struct partial_symbol
*) psym
;
1656 OBJSTAT (objfile
, n_psyms
++);
1659 /* Add a symbol with a long value to a psymtab.
1660 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1661 Return the partial symbol that has been added. */
1664 add_psymbol_to_list (const char *name
, int namelength
, int copy_name
,
1666 enum address_class
class,
1667 struct psymbol_allocation_list
*list
,
1668 long val
, /* Value as a long */
1669 CORE_ADDR coreaddr
, /* Value as a CORE_ADDR */
1670 enum language language
, struct objfile
*objfile
)
1672 const struct partial_symbol
*psym
;
1676 /* Stash the partial symbol away in the cache. */
1677 psym
= add_psymbol_to_bcache (name
, namelength
, copy_name
, domain
, class,
1678 val
, coreaddr
, language
, objfile
, &added
);
1680 /* Do not duplicate global partial symbols. */
1681 if (list
== &objfile
->global_psymbols
1685 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1686 append_psymbol_to_list (list
, psym
, objfile
);
1689 /* Initialize storage for partial symbols. */
1692 init_psymbol_list (struct objfile
*objfile
, int total_symbols
)
1694 /* Free any previously allocated psymbol lists. */
1696 if (objfile
->global_psymbols
.list
)
1698 xfree (objfile
->global_psymbols
.list
);
1700 if (objfile
->static_psymbols
.list
)
1702 xfree (objfile
->static_psymbols
.list
);
1705 /* Current best guess is that approximately a twentieth
1706 of the total symbols (in a debugging file) are global or static
1707 oriented symbols, then multiply that by slop factor of two. */
1709 objfile
->global_psymbols
.size
= total_symbols
/ 10;
1710 objfile
->static_psymbols
.size
= total_symbols
/ 10;
1712 if (objfile
->global_psymbols
.size
> 0)
1714 objfile
->global_psymbols
.next
=
1715 objfile
->global_psymbols
.list
= (struct partial_symbol
**)
1716 xmalloc ((objfile
->global_psymbols
.size
1717 * sizeof (struct partial_symbol
*)));
1719 if (objfile
->static_psymbols
.size
> 0)
1721 objfile
->static_psymbols
.next
=
1722 objfile
->static_psymbols
.list
= (struct partial_symbol
**)
1723 xmalloc ((objfile
->static_psymbols
.size
1724 * sizeof (struct partial_symbol
*)));
1728 struct partial_symtab
*
1729 allocate_psymtab (const char *filename
, struct objfile
*objfile
)
1731 struct partial_symtab
*psymtab
;
1733 if (objfile
->free_psymtabs
)
1735 psymtab
= objfile
->free_psymtabs
;
1736 objfile
->free_psymtabs
= psymtab
->next
;
1739 psymtab
= (struct partial_symtab
*)
1740 obstack_alloc (&objfile
->objfile_obstack
,
1741 sizeof (struct partial_symtab
));
1743 memset (psymtab
, 0, sizeof (struct partial_symtab
));
1744 psymtab
->filename
= bcache (filename
, strlen (filename
) + 1,
1745 objfile
->per_bfd
->filename_cache
);
1746 psymtab
->symtab
= NULL
;
1748 /* Prepend it to the psymtab list for the objfile it belongs to.
1749 Psymtabs are searched in most recent inserted -> least recent
1752 psymtab
->next
= objfile
->psymtabs
;
1753 objfile
->psymtabs
= psymtab
;
1755 if (symtab_create_debug
)
1757 /* Be a bit clever with debugging messages, and don't print objfile
1758 every time, only when it changes. */
1759 static char *last_objfile_name
= NULL
;
1761 if (last_objfile_name
== NULL
1762 || strcmp (last_objfile_name
, objfile_name (objfile
)) != 0)
1764 xfree (last_objfile_name
);
1765 last_objfile_name
= xstrdup (objfile_name (objfile
));
1766 fprintf_unfiltered (gdb_stdlog
,
1767 "Creating one or more psymtabs for objfile %s ...\n",
1770 fprintf_unfiltered (gdb_stdlog
,
1771 "Created psymtab %s for module %s.\n",
1772 host_address_to_string (psymtab
), filename
);
1779 discard_psymtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
1781 struct partial_symtab
**prev_pst
;
1784 Empty psymtabs happen as a result of header files which don't
1785 have any symbols in them. There can be a lot of them. But this
1786 check is wrong, in that a psymtab with N_SLINE entries but
1787 nothing else is not empty, but we don't realize that. Fixing
1788 that without slowing things down might be tricky. */
1790 /* First, snip it out of the psymtab chain. */
1792 prev_pst
= &(objfile
->psymtabs
);
1793 while ((*prev_pst
) != pst
)
1794 prev_pst
= &((*prev_pst
)->next
);
1795 (*prev_pst
) = pst
->next
;
1797 /* Next, put it on a free list for recycling. */
1799 pst
->next
= objfile
->free_psymtabs
;
1800 objfile
->free_psymtabs
= pst
;
1803 /* An object of this type is passed to discard_psymtabs_upto. */
1805 struct psymtab_state
1807 /* The objfile where psymtabs are discarded. */
1809 struct objfile
*objfile
;
1811 /* The first psymtab to save. */
1813 struct partial_symtab
*save
;
1816 /* A cleanup function used by make_cleanup_discard_psymtabs. */
1819 discard_psymtabs_upto (void *arg
)
1821 struct psymtab_state
*state
= arg
;
1823 while (state
->objfile
->psymtabs
!= state
->save
)
1824 discard_psymtab (state
->objfile
, state
->objfile
->psymtabs
);
1827 /* Return a new cleanup that discards all psymtabs created in OBJFILE
1828 after this function is called. */
1831 make_cleanup_discard_psymtabs (struct objfile
*objfile
)
1833 struct psymtab_state
*state
= XNEW (struct psymtab_state
);
1835 state
->objfile
= objfile
;
1836 state
->save
= objfile
->psymtabs
;
1838 return make_cleanup_dtor (discard_psymtabs_upto
, state
, xfree
);
1844 maintenance_print_psymbols (char *args
, int from_tty
)
1847 struct ui_file
*outfile
;
1848 struct cleanup
*cleanups
;
1849 char *symname
= NULL
;
1850 char *filename
= DEV_TTY
;
1851 struct objfile
*objfile
;
1852 struct partial_symtab
*ps
;
1859 print-psymbols takes an output file name and optional symbol file name"));
1861 argv
= gdb_buildargv (args
);
1862 cleanups
= make_cleanup_freeargv (argv
);
1864 if (argv
[0] != NULL
)
1867 /* If a second arg is supplied, it is a source file name to match on. */
1868 if (argv
[1] != NULL
)
1874 filename
= tilde_expand (filename
);
1875 make_cleanup (xfree
, filename
);
1877 outfile
= gdb_fopen (filename
, FOPEN_WT
);
1879 perror_with_name (filename
);
1880 make_cleanup_ui_file_delete (outfile
);
1882 ALL_PSYMTABS (objfile
, ps
)
1885 if (symname
== NULL
|| filename_cmp (symname
, ps
->filename
) == 0)
1886 dump_psymtab (objfile
, ps
, outfile
);
1888 do_cleanups (cleanups
);
1891 /* List all the partial symbol tables whose names match REGEXP (optional). */
1893 maintenance_info_psymtabs (char *regexp
, int from_tty
)
1895 struct program_space
*pspace
;
1896 struct objfile
*objfile
;
1901 ALL_PSPACES (pspace
)
1902 ALL_PSPACE_OBJFILES (pspace
, objfile
)
1904 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1905 struct partial_symtab
*psymtab
;
1907 /* We don't want to print anything for this objfile until we
1908 actually find a symtab whose name matches. */
1909 int printed_objfile_start
= 0;
1911 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, psymtab
)
1916 || re_exec (psymtab
->filename
))
1918 if (! printed_objfile_start
)
1920 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
1922 printf_filtered ("((struct objfile *) %s)\n",
1923 host_address_to_string (objfile
));
1924 printed_objfile_start
= 1;
1927 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1929 printf_filtered ("((struct partial_symtab *) %s)\n",
1930 host_address_to_string (psymtab
));
1932 printf_filtered (" readin %s\n",
1933 psymtab
->readin
? "yes" : "no");
1934 printf_filtered (" fullname %s\n",
1936 ? psymtab
->fullname
: "(null)");
1937 printf_filtered (" text addresses ");
1938 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
),
1940 printf_filtered (" -- ");
1941 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
),
1943 printf_filtered ("\n");
1944 printf_filtered (" psymtabs_addrmap_supported %s\n",
1945 (psymtab
->psymtabs_addrmap_supported
1947 printf_filtered (" globals ");
1948 if (psymtab
->n_global_syms
)
1950 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1951 host_address_to_string (objfile
->global_psymbols
.list
1952 + psymtab
->globals_offset
),
1953 psymtab
->n_global_syms
);
1956 printf_filtered ("(none)\n");
1957 printf_filtered (" statics ");
1958 if (psymtab
->n_static_syms
)
1960 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1961 host_address_to_string (objfile
->static_psymbols
.list
1962 + psymtab
->statics_offset
),
1963 psymtab
->n_static_syms
);
1966 printf_filtered ("(none)\n");
1967 printf_filtered (" dependencies ");
1968 if (psymtab
->number_of_dependencies
)
1972 printf_filtered ("{\n");
1973 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1975 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
1977 /* Note the string concatenation there --- no comma. */
1978 printf_filtered (" psymtab %s "
1979 "((struct partial_symtab *) %s)\n",
1981 host_address_to_string (dep
));
1983 printf_filtered (" }\n");
1986 printf_filtered ("(none)\n");
1987 printf_filtered (" }\n");
1991 if (printed_objfile_start
)
1992 printf_filtered ("}\n");
1996 /* Check consistency of currently expanded psymtabs vs symtabs. */
1999 maintenance_check_psymtabs (char *ignore
, int from_tty
)
2002 struct partial_symbol
**psym
;
2003 struct symtab
*s
= NULL
;
2004 struct partial_symtab
*ps
;
2005 const struct blockvector
*bv
;
2006 struct objfile
*objfile
;
2010 ALL_PSYMTABS (objfile
, ps
)
2012 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2014 /* We don't call psymtab_to_symtab here because that may cause symtab
2015 expansion. When debugging a problem it helps if checkers leave
2016 things unchanged. */
2019 /* First do some checks that don't require the associated symtab. */
2020 if (ps
->texthigh
< ps
->textlow
)
2022 printf_filtered ("Psymtab ");
2023 puts_filtered (ps
->filename
);
2024 printf_filtered (" covers bad range ");
2025 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
2026 printf_filtered (" - ");
2027 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
2028 printf_filtered ("\n");
2032 /* Now do checks requiring the associated symtab. */
2035 bv
= BLOCKVECTOR (s
);
2036 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
2037 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2038 length
= ps
->n_static_syms
;
2041 sym
= lookup_block_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
2042 SYMBOL_DOMAIN (*psym
));
2045 printf_filtered ("Static symbol `");
2046 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
2047 printf_filtered ("' only found in ");
2048 puts_filtered (ps
->filename
);
2049 printf_filtered (" psymtab\n");
2053 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2054 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2055 length
= ps
->n_global_syms
;
2058 sym
= lookup_block_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
2059 SYMBOL_DOMAIN (*psym
));
2062 printf_filtered ("Global symbol `");
2063 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
2064 printf_filtered ("' only found in ");
2065 puts_filtered (ps
->filename
);
2066 printf_filtered (" psymtab\n");
2070 if (ps
->texthigh
!= 0
2071 && (ps
->textlow
< BLOCK_START (b
) || ps
->texthigh
> BLOCK_END (b
)))
2073 printf_filtered ("Psymtab ");
2074 puts_filtered (ps
->filename
);
2075 printf_filtered (" covers ");
2076 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
2077 printf_filtered (" - ");
2078 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
2079 printf_filtered (" but symtab covers only ");
2080 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
2081 printf_filtered (" - ");
2082 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
2083 printf_filtered ("\n");
2090 extern initialize_file_ftype _initialize_psymtab
;
2093 _initialize_psymtab (void)
2095 add_cmd ("psymbols", class_maintenance
, maintenance_print_psymbols
, _("\
2096 Print dump of current partial symbol definitions.\n\
2097 Entries in the partial symbol table are dumped to file OUTFILE.\n\
2098 If a SOURCE file is specified, dump only that file's partial symbols."),
2099 &maintenanceprintlist
);
2101 add_cmd ("psymtabs", class_maintenance
, maintenance_info_psymtabs
, _("\
2102 List the partial symbol tables for all object files.\n\
2103 This does not include information about individual partial symbols,\n\
2104 just the symbol table structures themselves."),
2105 &maintenanceinfolist
);
2107 add_cmd ("check-psymtabs", class_maintenance
, maintenance_check_psymtabs
,
2109 Check consistency of currently expanded psymtabs versus symtabs."),