1 /* Partial symbol tables.
3 Copyright (C) 2009, 2010, 2011 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/>. */
24 #include "gdb_assert.h"
26 #include "filenames.h"
33 #include "readline/readline.h"
34 #include "gdb_regex.h"
35 #include "dictionary.h"
37 #include "cp-support.h"
40 #define DEV_TTY "/dev/tty"
45 struct bcache *bcache;
48 /* A fast way to get from a psymtab to its symtab (after the first time). */
49 #define PSYMTAB_TO_SYMTAB(pst) \
50 ((pst) -> symtab != NULL ? (pst) -> symtab : psymtab_to_symtab (pst))
52 static struct partial_symbol *match_partial_symbol (struct partial_symtab *,
54 const char *, domain_enum,
55 symbol_compare_ftype *,
56 symbol_compare_ftype *);
58 static struct partial_symbol *lookup_partial_symbol (struct partial_symtab *,
62 static char *psymtab_to_fullname (struct partial_symtab *ps);
64 static struct partial_symbol *find_pc_sect_psymbol (struct partial_symtab *,
66 struct obj_section *);
68 static struct partial_symbol *fixup_psymbol_section (struct partial_symbol
70 struct objfile *objfile);
72 static struct symtab *psymtab_to_symtab (struct partial_symtab *pst);
74 /* Ensure that the partial symbols for OBJFILE have been loaded. This
75 function always returns its argument, as a convenience. */
78 require_partial_symbols (struct objfile *objfile, int verbose)
80 if ((objfile->flags & OBJF_PSYMTABS_READ) == 0)
82 objfile->flags |= OBJF_PSYMTABS_READ;
84 if (objfile->sf->sym_read_psymbols)
88 printf_unfiltered (_("Reading symbols from %s..."),
90 gdb_flush (gdb_stdout);
92 (*objfile->sf->sym_read_psymbols) (objfile);
95 if (!objfile_has_symbols (objfile))
98 printf_unfiltered (_("(no debugging symbols found)..."));
102 printf_unfiltered (_("done.\n"));
110 /* Traverse all psymtabs in one objfile, requiring that the psymtabs
113 #define ALL_OBJFILE_PSYMTABS_REQUIRED(objfile, p) \
114 for ((p) = require_partial_symbols (objfile, 1)->psymtabs; \
118 /* We want to make sure this file always requires psymtabs. */
120 #undef ALL_OBJFILE_PSYMTABS
122 /* Traverse all psymtabs in all objfiles. */
124 #define ALL_PSYMTABS(objfile, p) \
125 ALL_OBJFILES (objfile) \
126 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
128 /* Lookup the partial symbol table of a source file named NAME.
129 *If* there is no '/' in the name, a match after a '/'
130 in the psymtab filename will also work. */
132 static struct partial_symtab *
133 lookup_partial_symtab (struct objfile *objfile, const char *name,
134 const char *full_path, const char *real_path)
136 struct partial_symtab *pst;
138 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
140 if (FILENAME_CMP (name, pst->filename) == 0)
145 /* If the user gave us an absolute path, try to find the file in
146 this symtab and use its absolute path. */
147 if (full_path != NULL)
149 psymtab_to_fullname (pst);
150 if (pst->fullname != NULL
151 && FILENAME_CMP (full_path, pst->fullname) == 0)
157 if (real_path != NULL)
160 psymtab_to_fullname (pst);
161 if (pst->fullname != NULL)
163 rp = gdb_realpath (pst->fullname);
164 make_cleanup (xfree, rp);
166 if (rp != NULL && FILENAME_CMP (real_path, rp) == 0)
173 /* Now, search for a matching tail (only if name doesn't have any dirs). */
175 if (lbasename (name) == name)
176 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
178 if (FILENAME_CMP (lbasename (pst->filename), name) == 0)
186 lookup_symtab_via_partial_symtab (struct objfile *objfile, const char *name,
187 const char *full_path, const char *real_path,
188 struct symtab **result)
190 struct partial_symtab *ps;
192 ps = lookup_partial_symtab (objfile, name, full_path, real_path);
197 error (_("Internal: readin %s pst for `%s' found when no symtab found."),
200 *result = PSYMTAB_TO_SYMTAB (ps);
204 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
205 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
207 static struct partial_symtab *
208 find_pc_sect_psymtab_closer (CORE_ADDR pc, struct obj_section *section,
209 struct partial_symtab *pst,
210 struct minimal_symbol *msymbol)
212 struct objfile *objfile = pst->objfile;
213 struct partial_symtab *tpst;
214 struct partial_symtab *best_pst = pst;
215 CORE_ADDR best_addr = pst->textlow;
217 /* An objfile that has its functions reordered might have
218 many partial symbol tables containing the PC, but
219 we want the partial symbol table that contains the
220 function containing the PC. */
221 if (!(objfile->flags & OBJF_REORDERED) &&
222 section == 0) /* Can't validate section this way. */
228 /* The code range of partial symtabs sometimes overlap, so, in
229 the loop below, we need to check all partial symtabs and
230 find the one that fits better for the given PC address. We
231 select the partial symtab that contains a symbol whose
232 address is closest to the PC address. By closest we mean
233 that find_pc_sect_symbol returns the symbol with address
234 that is closest and still less than the given PC. */
235 for (tpst = pst; tpst != NULL; tpst = tpst->next)
237 if (pc >= tpst->textlow && pc < tpst->texthigh)
239 struct partial_symbol *p;
242 /* NOTE: This assumes that every psymbol has a
243 corresponding msymbol, which is not necessarily
244 true; the debug info might be much richer than the
245 object's symbol table. */
246 p = find_pc_sect_psymbol (tpst, pc, section);
248 && SYMBOL_VALUE_ADDRESS (p)
249 == SYMBOL_VALUE_ADDRESS (msymbol))
252 /* Also accept the textlow value of a psymtab as a
253 "symbol", to provide some support for partial
254 symbol tables with line information but no debug
255 symbols (e.g. those produced by an assembler). */
257 this_addr = SYMBOL_VALUE_ADDRESS (p);
259 this_addr = tpst->textlow;
261 /* Check whether it is closer than our current
262 BEST_ADDR. Since this symbol address is
263 necessarily lower or equal to PC, the symbol closer
264 to PC is the symbol which address is the highest.
265 This way we return the psymtab which contains such
266 best match symbol. This can help in cases where the
267 symbol information/debuginfo is not complete, like
268 for instance on IRIX6 with gcc, where no debug info
269 is emitted for statics. (See also the nodebug.exp
271 if (this_addr > best_addr)
273 best_addr = this_addr;
281 /* Find which partial symtab contains PC and SECTION. Return 0 if
282 none. We return the psymtab that contains a symbol whose address
283 exactly matches PC, or, if we cannot find an exact match, the
284 psymtab that contains a symbol whose address is closest to PC. */
285 static struct partial_symtab *
286 find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
287 struct obj_section *section,
288 struct minimal_symbol *msymbol)
290 struct partial_symtab *pst;
292 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
293 than the later used TEXTLOW/TEXTHIGH one. */
295 if (objfile->psymtabs_addrmap != NULL)
297 pst = addrmap_find (objfile->psymtabs_addrmap, pc);
300 /* FIXME: addrmaps currently do not handle overlayed sections,
301 so fall back to the non-addrmap case if we're debugging
302 overlays and the addrmap returned the wrong section. */
303 if (overlay_debugging && msymbol && section)
305 struct partial_symbol *p;
307 /* NOTE: This assumes that every psymbol has a
308 corresponding msymbol, which is not necessarily
309 true; the debug info might be much richer than the
310 object's symbol table. */
311 p = find_pc_sect_psymbol (pst, pc, section);
313 || SYMBOL_VALUE_ADDRESS (p)
314 != SYMBOL_VALUE_ADDRESS (msymbol))
318 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
319 PSYMTABS_ADDRMAP we used has already the best 1-byte
320 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
321 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
330 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
331 which still have no corresponding full SYMTABs read. But it is not
332 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
335 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
336 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
337 debug info type in single OBJFILE. */
339 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
340 if (pc >= pst->textlow && pc < pst->texthigh)
342 struct partial_symtab *best_pst;
344 best_pst = find_pc_sect_psymtab_closer (pc, section, pst, msymbol);
345 if (best_pst != NULL)
352 static struct symtab *
353 find_pc_sect_symtab_from_partial (struct objfile *objfile,
354 struct minimal_symbol *msymbol,
355 CORE_ADDR pc, struct obj_section *section,
358 struct partial_symtab *ps = find_pc_sect_psymtab (objfile, pc, section,
362 if (warn_if_readin && ps->readin)
363 /* Might want to error() here (in case symtab is corrupt and
364 will cause a core dump), but maybe we can successfully
365 continue, so let's not. */
367 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
368 paddress (get_objfile_arch (ps->objfile), pc));
369 return PSYMTAB_TO_SYMTAB (ps);
374 /* Find which partial symbol within a psymtab matches PC and SECTION.
377 static struct partial_symbol *
378 find_pc_sect_psymbol (struct partial_symtab *psymtab, CORE_ADDR pc,
379 struct obj_section *section)
381 struct partial_symbol *best = NULL, *p, **pp;
384 gdb_assert (psymtab != NULL);
386 /* Cope with programs that start at address 0. */
387 best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0;
389 /* Search the global symbols as well as the static symbols, so that
390 find_pc_partial_function doesn't use a minimal symbol and thus
391 cache a bad endaddr. */
392 for (pp = psymtab->objfile->global_psymbols.list + psymtab->globals_offset;
393 (pp - (psymtab->objfile->global_psymbols.list + psymtab->globals_offset)
394 < psymtab->n_global_syms);
398 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
399 && SYMBOL_CLASS (p) == LOC_BLOCK
400 && pc >= SYMBOL_VALUE_ADDRESS (p)
401 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
402 || (psymtab->textlow == 0
403 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
405 if (section) /* Match on a specific section. */
407 fixup_psymbol_section (p, psymtab->objfile);
408 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
411 best_pc = SYMBOL_VALUE_ADDRESS (p);
416 for (pp = psymtab->objfile->static_psymbols.list + psymtab->statics_offset;
417 (pp - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset)
418 < psymtab->n_static_syms);
422 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
423 && SYMBOL_CLASS (p) == LOC_BLOCK
424 && pc >= SYMBOL_VALUE_ADDRESS (p)
425 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
426 || (psymtab->textlow == 0
427 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
429 if (section) /* Match on a specific section. */
431 fixup_psymbol_section (p, psymtab->objfile);
432 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
435 best_pc = SYMBOL_VALUE_ADDRESS (p);
443 static struct partial_symbol *
444 fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
451 if (SYMBOL_OBJ_SECTION (psym))
454 gdb_assert (objfile);
456 switch (SYMBOL_CLASS (psym))
461 addr = SYMBOL_VALUE_ADDRESS (psym);
464 /* Nothing else will be listed in the minsyms -- no use looking
469 fixup_section (&psym->ginfo, addr, objfile);
474 static struct symtab *
475 lookup_symbol_aux_psymtabs (struct objfile *objfile,
476 int block_index, const char *name,
477 const domain_enum domain)
479 struct partial_symtab *ps;
480 const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
482 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
484 if (!ps->readin && lookup_partial_symbol (ps, name, psymtab_index, domain))
486 struct symbol *sym = NULL;
487 struct symtab *stab = PSYMTAB_TO_SYMTAB (ps);
489 /* Some caution must be observed with overloaded functions
490 and methods, since the psymtab will not contain any overload
491 information (but NAME might contain it). */
494 struct blockvector *bv = BLOCKVECTOR (stab);
495 struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
497 sym = lookup_block_symbol (block, name, domain);
500 if (sym && strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0)
503 /* Keep looking through other psymtabs. */
510 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
511 the global block of PST if GLOBAL, and otherwise the static block.
512 MATCH is the comparison operation that returns true iff MATCH (s,
513 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
514 non-null, the symbols in the block are assumed to be ordered
515 according to it (allowing binary search). It must be compatible
516 with MATCH. Returns the symbol, if found, and otherwise NULL. */
518 static struct partial_symbol *
519 match_partial_symbol (struct partial_symtab *pst, int global,
520 const char *name, domain_enum domain,
521 symbol_compare_ftype *match,
522 symbol_compare_ftype *ordered_compare)
524 struct partial_symbol **start, **psym;
525 struct partial_symbol **top, **real_top, **bottom, **center;
526 int length = (global ? pst->n_global_syms : pst->n_static_syms);
527 int do_linear_search = 1;
532 pst->objfile->global_psymbols.list + pst->globals_offset :
533 pst->objfile->static_psymbols.list + pst->statics_offset);
535 if (global && ordered_compare) /* Can use a binary search. */
537 do_linear_search = 0;
539 /* Binary search. This search is guaranteed to end with center
540 pointing at the earliest partial symbol whose name might be
541 correct. At that point *all* partial symbols with an
542 appropriate name will be checked against the correct
546 top = start + length - 1;
550 center = bottom + (top - bottom) / 2;
551 gdb_assert (center < top);
552 if (!do_linear_search
553 && (SYMBOL_LANGUAGE (*center) == language_java))
554 do_linear_search = 1;
555 if (ordered_compare (SYMBOL_SEARCH_NAME (*center), name) >= 0)
560 gdb_assert (top == bottom);
562 while (top <= real_top
563 && match (SYMBOL_SEARCH_NAME (*top), name) == 0)
565 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
566 SYMBOL_DOMAIN (*top), domain))
572 /* Can't use a binary search or else we found during the binary search that
573 we should also do a linear search. */
575 if (do_linear_search)
577 for (psym = start; psym < start + length; psym++)
579 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
580 SYMBOL_DOMAIN (*psym), domain)
581 && match (SYMBOL_SEARCH_NAME (*psym), name) == 0)
590 pre_expand_symtabs_matching_psymtabs (struct objfile *objfile,
591 enum block_enum block_kind,
598 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
599 not contain any method/function instance information (since this would
600 force reading type information while reading psymtabs). Therefore,
601 if NAME contains overload information, it must be stripped before searching
604 The caller is responsible for freeing the return result. */
607 psymtab_search_name (const char *name)
609 switch (current_language->la_language)
614 if (strchr (name, '('))
616 char *ret = cp_remove_params (name);
628 return xstrdup (name);
631 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
632 Check the global symbols if GLOBAL, the static symbols if not. */
634 static struct partial_symbol *
635 lookup_partial_symbol (struct partial_symtab *pst, const char *name,
636 int global, domain_enum domain)
638 struct partial_symbol **start, **psym;
639 struct partial_symbol **top, **real_top, **bottom, **center;
640 int length = (global ? pst->n_global_syms : pst->n_static_syms);
641 int do_linear_search = 1;
643 struct cleanup *cleanup;
650 search_name = psymtab_search_name (name);
651 cleanup = make_cleanup (xfree, search_name);
653 pst->objfile->global_psymbols.list + pst->globals_offset :
654 pst->objfile->static_psymbols.list + pst->statics_offset);
656 if (global) /* This means we can use a binary search. */
658 do_linear_search = 0;
660 /* Binary search. This search is guaranteed to end with center
661 pointing at the earliest partial symbol whose name might be
662 correct. At that point *all* partial symbols with an
663 appropriate name will be checked against the correct
667 top = start + length - 1;
671 center = bottom + (top - bottom) / 2;
673 internal_error (__FILE__, __LINE__,
674 _("failed internal consistency check"));
675 if (!do_linear_search
676 && SYMBOL_LANGUAGE (*center) == language_java)
678 do_linear_search = 1;
680 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center),
690 if (!(top == bottom))
691 internal_error (__FILE__, __LINE__,
692 _("failed internal consistency check"));
694 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
695 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
696 while (top >= start && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
699 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
702 while (top <= real_top && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
704 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
705 SYMBOL_DOMAIN (*top), domain))
707 do_cleanups (cleanup);
714 /* Can't use a binary search or else we found during the binary search that
715 we should also do a linear search. */
717 if (do_linear_search)
719 for (psym = start; psym < start + length; psym++)
721 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
722 SYMBOL_DOMAIN (*psym), domain)
723 && SYMBOL_MATCHES_SEARCH_NAME (*psym, search_name))
725 do_cleanups (cleanup);
731 do_cleanups (cleanup);
735 /* Get the symbol table that corresponds to a partial_symtab.
736 This is fast after the first time you do it. In fact, there
737 is an even faster macro PSYMTAB_TO_SYMTAB that does the fast
740 static struct symtab *
741 psymtab_to_symtab (struct partial_symtab *pst)
743 /* If it's been looked up before, return it. */
747 /* If it has not yet been read in, read it. */
750 struct cleanup *back_to = increment_reading_symtab ();
752 (*pst->read_symtab) (pst);
753 do_cleanups (back_to);
760 relocate_psymtabs (struct objfile *objfile,
761 struct section_offsets *new_offsets,
762 struct section_offsets *delta)
764 struct partial_symbol **psym;
765 struct partial_symtab *p;
767 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
769 p->textlow += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
770 p->texthigh += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
773 for (psym = objfile->global_psymbols.list;
774 psym < objfile->global_psymbols.next;
777 fixup_psymbol_section (*psym, objfile);
778 if (SYMBOL_SECTION (*psym) >= 0)
779 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
780 SYMBOL_SECTION (*psym));
782 for (psym = objfile->static_psymbols.list;
783 psym < objfile->static_psymbols.next;
786 fixup_psymbol_section (*psym, objfile);
787 if (SYMBOL_SECTION (*psym) >= 0)
788 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
789 SYMBOL_SECTION (*psym));
793 static struct symtab *
794 find_last_source_symtab_from_partial (struct objfile *ofp)
796 struct partial_symtab *ps;
797 struct partial_symtab *cs_pst = 0;
799 ALL_OBJFILE_PSYMTABS_REQUIRED (ofp, ps)
801 const char *name = ps->filename;
802 int len = strlen (name);
804 if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0
805 || strcmp (name, "<<C++-namespaces>>") == 0)))
813 internal_error (__FILE__, __LINE__,
814 _("select_source_symtab: "
815 "readin pst found and no symtabs."));
818 return PSYMTAB_TO_SYMTAB (cs_pst);
824 forget_cached_source_info_partial (struct objfile *objfile)
826 struct partial_symtab *pst;
828 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
830 if (pst->fullname != NULL)
832 xfree (pst->fullname);
833 pst->fullname = NULL;
839 print_partial_symbols (struct gdbarch *gdbarch,
840 struct partial_symbol **p, int count, char *what,
841 struct ui_file *outfile)
843 fprintf_filtered (outfile, " %s partial symbols:\n", what);
846 fprintf_filtered (outfile, " `%s'", SYMBOL_LINKAGE_NAME (*p));
847 if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
849 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
851 fputs_filtered (", ", outfile);
852 switch (SYMBOL_DOMAIN (*p))
855 fputs_filtered ("undefined domain, ", outfile);
858 /* This is the usual thing -- don't print it. */
861 fputs_filtered ("struct domain, ", outfile);
864 fputs_filtered ("label domain, ", outfile);
867 fputs_filtered ("<invalid domain>, ", outfile);
870 switch (SYMBOL_CLASS (*p))
873 fputs_filtered ("undefined", outfile);
876 fputs_filtered ("constant int", outfile);
879 fputs_filtered ("static", outfile);
882 fputs_filtered ("register", outfile);
885 fputs_filtered ("pass by value", outfile);
888 fputs_filtered ("pass by reference", outfile);
890 case LOC_REGPARM_ADDR:
891 fputs_filtered ("register address parameter", outfile);
894 fputs_filtered ("stack parameter", outfile);
897 fputs_filtered ("type", outfile);
900 fputs_filtered ("label", outfile);
903 fputs_filtered ("function", outfile);
905 case LOC_CONST_BYTES:
906 fputs_filtered ("constant bytes", outfile);
909 fputs_filtered ("unresolved", outfile);
911 case LOC_OPTIMIZED_OUT:
912 fputs_filtered ("optimized out", outfile);
915 fputs_filtered ("computed at runtime", outfile);
918 fputs_filtered ("<invalid location>", outfile);
921 fputs_filtered (", ", outfile);
922 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (*p)), outfile);
923 fprintf_filtered (outfile, "\n");
929 dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
930 struct ui_file *outfile)
932 struct gdbarch *gdbarch = get_objfile_arch (objfile);
935 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
937 fprintf_filtered (outfile, "(object ");
938 gdb_print_host_address (psymtab, outfile);
939 fprintf_filtered (outfile, ")\n\n");
940 fprintf_unfiltered (outfile, " Read from object file %s (",
942 gdb_print_host_address (objfile, outfile);
943 fprintf_unfiltered (outfile, ")\n");
947 fprintf_filtered (outfile,
948 " Full symtab was read (at ");
949 gdb_print_host_address (psymtab->symtab, outfile);
950 fprintf_filtered (outfile, " by function at ");
951 gdb_print_host_address (psymtab->read_symtab, outfile);
952 fprintf_filtered (outfile, ")\n");
955 fprintf_filtered (outfile, " Relocate symbols by ");
956 for (i = 0; i < psymtab->objfile->num_sections; ++i)
959 fprintf_filtered (outfile, ", ");
961 fputs_filtered (paddress (gdbarch,
962 ANOFFSET (psymtab->section_offsets, i)),
965 fprintf_filtered (outfile, "\n");
967 fprintf_filtered (outfile, " Symbols cover text addresses ");
968 fputs_filtered (paddress (gdbarch, psymtab->textlow), outfile);
969 fprintf_filtered (outfile, "-");
970 fputs_filtered (paddress (gdbarch, psymtab->texthigh), outfile);
971 fprintf_filtered (outfile, "\n");
972 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
973 psymtab->number_of_dependencies);
974 for (i = 0; i < psymtab->number_of_dependencies; i++)
976 fprintf_filtered (outfile, " %d ", i);
977 gdb_print_host_address (psymtab->dependencies[i], outfile);
978 fprintf_filtered (outfile, " %s\n",
979 psymtab->dependencies[i]->filename);
981 if (psymtab->n_global_syms > 0)
983 print_partial_symbols (gdbarch,
984 objfile->global_psymbols.list
985 + psymtab->globals_offset,
986 psymtab->n_global_syms, "Global", outfile);
988 if (psymtab->n_static_syms > 0)
990 print_partial_symbols (gdbarch,
991 objfile->static_psymbols.list
992 + psymtab->statics_offset,
993 psymtab->n_static_syms, "Static", outfile);
995 fprintf_filtered (outfile, "\n");
999 print_psymtab_stats_for_objfile (struct objfile *objfile)
1002 struct partial_symtab *ps;
1005 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1007 if (ps->readin == 0)
1010 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i);
1014 dump_psymtabs_for_objfile (struct objfile *objfile)
1016 struct partial_symtab *psymtab;
1018 if (objfile->psymtabs)
1020 printf_filtered ("Psymtabs:\n");
1021 for (psymtab = objfile->psymtabs;
1023 psymtab = psymtab->next)
1025 printf_filtered ("%s at ",
1027 gdb_print_host_address (psymtab, gdb_stdout);
1028 printf_filtered (", ");
1029 if (psymtab->objfile != objfile)
1031 printf_filtered ("NOT ON CHAIN! ");
1035 printf_filtered ("\n\n");
1039 /* Look through the partial symtabs for all symbols which begin
1040 by matching FUNC_NAME. Make sure we read that symbol table in. */
1043 read_symtabs_for_function (struct objfile *objfile, const char *func_name)
1045 struct partial_symtab *ps;
1047 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1052 if ((lookup_partial_symbol (ps, func_name, 1, VAR_DOMAIN)
1054 || (lookup_partial_symbol (ps, func_name, 0, VAR_DOMAIN)
1056 psymtab_to_symtab (ps);
1061 expand_partial_symbol_tables (struct objfile *objfile)
1063 struct partial_symtab *psymtab;
1065 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
1067 psymtab_to_symtab (psymtab);
1072 read_psymtabs_with_filename (struct objfile *objfile, const char *filename)
1074 struct partial_symtab *p;
1076 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
1078 if (filename_cmp (filename, p->filename) == 0)
1079 PSYMTAB_TO_SYMTAB (p);
1084 map_symbol_filenames_psymtab (struct objfile *objfile,
1085 symbol_filename_ftype *fun, void *data)
1087 struct partial_symtab *ps;
1089 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1091 const char *fullname;
1096 fullname = psymtab_to_fullname (ps);
1097 (*fun) (ps->filename, fullname, data);
1101 int find_and_open_source (const char *filename,
1102 const char *dirname,
1105 /* Finds the fullname that a partial_symtab represents.
1107 If this functions finds the fullname, it will save it in ps->fullname
1108 and it will also return the value.
1110 If this function fails to find the file that this partial_symtab represents,
1111 NULL will be returned and ps->fullname will be set to NULL. */
1113 psymtab_to_fullname (struct partial_symtab *ps)
1120 /* Don't check ps->fullname here, the file could have been
1121 deleted/moved/..., look for it again. */
1122 r = find_and_open_source (ps->filename, ps->dirname, &ps->fullname);
1127 return ps->fullname;
1134 find_symbol_file_from_partial (struct objfile *objfile, const char *name)
1136 struct partial_symtab *pst;
1138 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
1140 if (lookup_partial_symbol (pst, name, 1, VAR_DOMAIN))
1141 return pst->filename;
1146 /* For all symbols, s, in BLOCK that are in NAMESPACE and match NAME
1147 according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
1148 BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK
1149 ever returns non-zero, and otherwise returns 0. */
1152 map_block (const char *name, domain_enum namespace, struct objfile *objfile,
1153 struct block *block,
1154 int (*callback) (struct block *, struct symbol *, void *),
1155 void *data, symbol_compare_ftype *match)
1157 struct dict_iterator iter;
1160 for (sym = dict_iter_match_first (BLOCK_DICT (block), name, match, &iter);
1161 sym != NULL; sym = dict_iter_match_next (name, match, &iter))
1163 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
1164 SYMBOL_DOMAIN (sym), namespace))
1166 if (callback (block, sym, data))
1174 /* Psymtab version of map_matching_symbols. See its definition in
1175 the definition of quick_symbol_functions in symfile.h. */
1178 map_matching_symbols_psymtab (const char *name, domain_enum namespace,
1179 struct objfile *objfile, int global,
1180 int (*callback) (struct block *,
1181 struct symbol *, void *),
1183 symbol_compare_ftype *match,
1184 symbol_compare_ftype *ordered_compare)
1186 const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
1187 struct partial_symtab *ps;
1189 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1193 || match_partial_symbol (ps, global, name, namespace, match,
1196 struct symtab *s = PSYMTAB_TO_SYMTAB (ps);
1197 struct block *block;
1199 if (s == NULL || !s->primary)
1201 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), block_kind);
1202 if (map_block (name, namespace, objfile, block,
1203 callback, data, match))
1205 if (callback (block, NULL, data))
1212 expand_symtabs_matching_via_partial (struct objfile *objfile,
1213 int (*file_matcher) (const char *,
1215 int (*name_matcher) (const char *,
1217 enum search_domain kind,
1220 struct partial_symtab *ps;
1222 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1224 struct partial_symbol **psym;
1225 struct partial_symbol **bound, **gbound, **sbound;
1231 if (file_matcher && ! (*file_matcher) (ps->filename, data))
1234 gbound = objfile->global_psymbols.list
1235 + ps->globals_offset + ps->n_global_syms;
1236 sbound = objfile->static_psymbols.list
1237 + ps->statics_offset + ps->n_static_syms;
1240 /* Go through all of the symbols stored in a partial
1241 symtab in one loop. */
1242 psym = objfile->global_psymbols.list + ps->globals_offset;
1247 if (bound == gbound && ps->n_static_syms != 0)
1249 psym = objfile->static_psymbols.list + ps->statics_offset;
1260 if ((kind == ALL_DOMAIN
1261 || (kind == VARIABLES_DOMAIN
1262 && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
1263 && SYMBOL_CLASS (*psym) != LOC_BLOCK)
1264 || (kind == FUNCTIONS_DOMAIN
1265 && SYMBOL_CLASS (*psym) == LOC_BLOCK)
1266 || (kind == TYPES_DOMAIN
1267 && SYMBOL_CLASS (*psym) == LOC_TYPEDEF))
1268 && (*name_matcher) (SYMBOL_NATURAL_NAME (*psym), data))
1270 PSYMTAB_TO_SYMTAB (ps);
1280 objfile_has_psyms (struct objfile *objfile)
1282 return objfile->psymtabs != NULL;
1285 const struct quick_symbol_functions psym_functions =
1288 find_last_source_symtab_from_partial,
1289 forget_cached_source_info_partial,
1290 lookup_symtab_via_partial_symtab,
1291 lookup_symbol_aux_psymtabs,
1292 pre_expand_symtabs_matching_psymtabs,
1293 print_psymtab_stats_for_objfile,
1294 dump_psymtabs_for_objfile,
1296 read_symtabs_for_function,
1297 expand_partial_symbol_tables,
1298 read_psymtabs_with_filename,
1299 find_symbol_file_from_partial,
1300 map_matching_symbols_psymtab,
1301 expand_symtabs_matching_via_partial,
1302 find_pc_sect_symtab_from_partial,
1303 map_symbol_filenames_psymtab
1308 /* This compares two partial symbols by names, using strcmp_iw_ordered
1309 for the comparison. */
1312 compare_psymbols (const void *s1p, const void *s2p)
1314 struct partial_symbol *const *s1 = s1p;
1315 struct partial_symbol *const *s2 = s2p;
1317 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1),
1318 SYMBOL_SEARCH_NAME (*s2));
1322 sort_pst_symbols (struct partial_symtab *pst)
1324 /* Sort the global list; don't sort the static list. */
1326 qsort (pst->objfile->global_psymbols.list + pst->globals_offset,
1327 pst->n_global_syms, sizeof (struct partial_symbol *),
1331 /* Allocate and partially fill a partial symtab. It will be
1332 completely filled at the end of the symbol list.
1334 FILENAME is the name of the symbol-file we are reading from. */
1336 struct partial_symtab *
1337 start_psymtab_common (struct objfile *objfile,
1338 struct section_offsets *section_offsets,
1339 const char *filename,
1340 CORE_ADDR textlow, struct partial_symbol **global_syms,
1341 struct partial_symbol **static_syms)
1343 struct partial_symtab *psymtab;
1345 psymtab = allocate_psymtab (filename, objfile);
1346 psymtab->section_offsets = section_offsets;
1347 psymtab->textlow = textlow;
1348 psymtab->texthigh = psymtab->textlow; /* default */
1349 psymtab->globals_offset = global_syms - objfile->global_psymbols.list;
1350 psymtab->statics_offset = static_syms - objfile->static_psymbols.list;
1354 /* Calculate a hash code for the given partial symbol. The hash is
1355 calculated using the symbol's value, language, domain, class
1356 and name. These are the values which are set by
1357 add_psymbol_to_bcache. */
1359 static unsigned long
1360 psymbol_hash (const void *addr, int length)
1362 unsigned long h = 0;
1363 struct partial_symbol *psymbol = (struct partial_symbol *) addr;
1364 unsigned int lang = psymbol->ginfo.language;
1365 unsigned int domain = PSYMBOL_DOMAIN (psymbol);
1366 unsigned int class = PSYMBOL_CLASS (psymbol);
1368 h = hash_continue (&psymbol->ginfo.value, sizeof (psymbol->ginfo.value), h);
1369 h = hash_continue (&lang, sizeof (unsigned int), h);
1370 h = hash_continue (&domain, sizeof (unsigned int), h);
1371 h = hash_continue (&class, sizeof (unsigned int), h);
1372 h = hash_continue (psymbol->ginfo.name, strlen (psymbol->ginfo.name), h);
1377 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1378 For the comparison this function uses a symbols value,
1379 language, domain, class and name. */
1382 psymbol_compare (const void *addr1, const void *addr2, int length)
1384 struct partial_symbol *sym1 = (struct partial_symbol *) addr1;
1385 struct partial_symbol *sym2 = (struct partial_symbol *) addr2;
1387 return (memcmp (&sym1->ginfo.value, &sym1->ginfo.value,
1388 sizeof (sym1->ginfo.value)) == 0
1389 && sym1->ginfo.language == sym2->ginfo.language
1390 && PSYMBOL_DOMAIN (sym1) == PSYMBOL_DOMAIN (sym2)
1391 && PSYMBOL_CLASS (sym1) == PSYMBOL_CLASS (sym2)
1392 && sym1->ginfo.name == sym2->ginfo.name);
1395 /* Initialize a partial symbol bcache. */
1397 struct psymbol_bcache *
1398 psymbol_bcache_init (void)
1400 struct psymbol_bcache *bcache = XCALLOC (1, struct psymbol_bcache);
1401 bcache->bcache = bcache_xmalloc (psymbol_hash, psymbol_compare);
1405 /* Free a partial symbol bcache. */
1407 psymbol_bcache_free (struct psymbol_bcache *bcache)
1412 bcache_xfree (bcache->bcache);
1416 /* Return the internal bcache of the psymbol_bcache BCACHE. */
1419 psymbol_bcache_get_bcache (struct psymbol_bcache *bcache)
1421 return bcache->bcache;
1424 /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1425 symbol before, add a copy to BCACHE. In either case, return a pointer
1426 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1427 1 in case of new entry or 0 if returning an old entry. */
1429 static const struct partial_symbol *
1430 psymbol_bcache_full (struct partial_symbol *sym,
1431 struct psymbol_bcache *bcache,
1434 return bcache_full (sym,
1435 sizeof (struct partial_symbol),
1440 /* Helper function, initialises partial symbol structure and stashes
1441 it into objfile's bcache. Note that our caching mechanism will
1442 use all fields of struct partial_symbol to determine hash value of the
1443 structure. In other words, having two symbols with the same name but
1444 different domain (or address) is possible and correct. */
1446 static const struct partial_symbol *
1447 add_psymbol_to_bcache (const char *name, int namelength, int copy_name,
1449 enum address_class class,
1450 long val, /* Value as a long */
1451 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1452 enum language language, struct objfile *objfile,
1455 struct partial_symbol psymbol;
1457 /* We must ensure that the entire 'value' field has been zeroed
1458 before assigning to it, because an assignment may not write the
1460 memset (&psymbol.ginfo.value, 0, sizeof (psymbol.ginfo.value));
1462 /* val and coreaddr are mutually exclusive, one of them *will* be zero. */
1465 SYMBOL_VALUE (&psymbol) = val;
1469 SYMBOL_VALUE_ADDRESS (&psymbol) = coreaddr;
1471 SYMBOL_SECTION (&psymbol) = 0;
1472 SYMBOL_OBJ_SECTION (&psymbol) = NULL;
1473 SYMBOL_SET_LANGUAGE (&psymbol, language);
1474 PSYMBOL_DOMAIN (&psymbol) = domain;
1475 PSYMBOL_CLASS (&psymbol) = class;
1477 SYMBOL_SET_NAMES (&psymbol, name, namelength, copy_name, objfile);
1479 /* Stash the partial symbol away in the cache. */
1480 return psymbol_bcache_full (&psymbol,
1481 objfile->psymbol_cache,
1485 /* Increase the space allocated for LISTP, which is probably
1486 global_psymbols or static_psymbols. This space will eventually
1487 be freed in free_objfile(). */
1490 extend_psymbol_list (struct psymbol_allocation_list *listp,
1491 struct objfile *objfile)
1495 if (listp->size == 0)
1498 listp->list = (struct partial_symbol **)
1499 xmalloc (new_size * sizeof (struct partial_symbol *));
1503 new_size = listp->size * 2;
1504 listp->list = (struct partial_symbol **)
1505 xrealloc ((char *) listp->list,
1506 new_size * sizeof (struct partial_symbol *));
1508 /* Next assumes we only went one over. Should be good if
1509 program works correctly. */
1510 listp->next = listp->list + listp->size;
1511 listp->size = new_size;
1514 /* Helper function, adds partial symbol to the given partial symbol
1518 append_psymbol_to_list (struct psymbol_allocation_list *list,
1519 const struct partial_symbol *psym,
1520 struct objfile *objfile)
1522 if (list->next >= list->list + list->size)
1523 extend_psymbol_list (list, objfile);
1524 *list->next++ = (struct partial_symbol *) psym;
1525 OBJSTAT (objfile, n_psyms++);
1528 /* Add a symbol with a long value to a psymtab.
1529 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1530 Return the partial symbol that has been added. */
1532 /* NOTE: carlton/2003-09-11: The reason why we return the partial
1533 symbol is so that callers can get access to the symbol's demangled
1534 name, which they don't have any cheap way to determine otherwise.
1535 (Currenly, dwarf2read.c is the only file who uses that information,
1536 though it's possible that other readers might in the future.)
1537 Elena wasn't thrilled about that, and I don't blame her, but we
1538 couldn't come up with a better way to get that information. If
1539 it's needed in other situations, we could consider breaking up
1540 SYMBOL_SET_NAMES to provide access to the demangled name lookup
1543 const struct partial_symbol *
1544 add_psymbol_to_list (const char *name, int namelength, int copy_name,
1546 enum address_class class,
1547 struct psymbol_allocation_list *list,
1548 long val, /* Value as a long */
1549 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1550 enum language language, struct objfile *objfile)
1552 const struct partial_symbol *psym;
1556 /* Stash the partial symbol away in the cache. */
1557 psym = add_psymbol_to_bcache (name, namelength, copy_name, domain, class,
1558 val, coreaddr, language, objfile, &added);
1560 /* Do not duplicate global partial symbols. */
1561 if (list == &objfile->global_psymbols
1565 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1566 append_psymbol_to_list (list, psym, objfile);
1570 /* Initialize storage for partial symbols. */
1573 init_psymbol_list (struct objfile *objfile, int total_symbols)
1575 /* Free any previously allocated psymbol lists. */
1577 if (objfile->global_psymbols.list)
1579 xfree (objfile->global_psymbols.list);
1581 if (objfile->static_psymbols.list)
1583 xfree (objfile->static_psymbols.list);
1586 /* Current best guess is that approximately a twentieth
1587 of the total symbols (in a debugging file) are global or static
1588 oriented symbols. */
1590 objfile->global_psymbols.size = total_symbols / 10;
1591 objfile->static_psymbols.size = total_symbols / 10;
1593 if (objfile->global_psymbols.size > 0)
1595 objfile->global_psymbols.next =
1596 objfile->global_psymbols.list = (struct partial_symbol **)
1597 xmalloc ((objfile->global_psymbols.size
1598 * sizeof (struct partial_symbol *)));
1600 if (objfile->static_psymbols.size > 0)
1602 objfile->static_psymbols.next =
1603 objfile->static_psymbols.list = (struct partial_symbol **)
1604 xmalloc ((objfile->static_psymbols.size
1605 * sizeof (struct partial_symbol *)));
1609 struct partial_symtab *
1610 allocate_psymtab (const char *filename, struct objfile *objfile)
1612 struct partial_symtab *psymtab;
1614 if (objfile->free_psymtabs)
1616 psymtab = objfile->free_psymtabs;
1617 objfile->free_psymtabs = psymtab->next;
1620 psymtab = (struct partial_symtab *)
1621 obstack_alloc (&objfile->objfile_obstack,
1622 sizeof (struct partial_symtab));
1624 memset (psymtab, 0, sizeof (struct partial_symtab));
1625 psymtab->filename = obsavestring (filename, strlen (filename),
1626 &objfile->objfile_obstack);
1627 psymtab->symtab = NULL;
1629 /* Prepend it to the psymtab list for the objfile it belongs to.
1630 Psymtabs are searched in most recent inserted -> least recent
1633 psymtab->objfile = objfile;
1634 psymtab->next = objfile->psymtabs;
1635 objfile->psymtabs = psymtab;
1641 discard_psymtab (struct partial_symtab *pst)
1643 struct partial_symtab **prev_pst;
1646 Empty psymtabs happen as a result of header files which don't
1647 have any symbols in them. There can be a lot of them. But this
1648 check is wrong, in that a psymtab with N_SLINE entries but
1649 nothing else is not empty, but we don't realize that. Fixing
1650 that without slowing things down might be tricky. */
1652 /* First, snip it out of the psymtab chain. */
1654 prev_pst = &(pst->objfile->psymtabs);
1655 while ((*prev_pst) != pst)
1656 prev_pst = &((*prev_pst)->next);
1657 (*prev_pst) = pst->next;
1659 /* Next, put it on a free list for recycling. */
1661 pst->next = pst->objfile->free_psymtabs;
1662 pst->objfile->free_psymtabs = pst;
1668 maintenance_print_psymbols (char *args, int from_tty)
1671 struct ui_file *outfile;
1672 struct cleanup *cleanups;
1673 char *symname = NULL;
1674 char *filename = DEV_TTY;
1675 struct objfile *objfile;
1676 struct partial_symtab *ps;
1683 print-psymbols takes an output file name and optional symbol file name"));
1685 argv = gdb_buildargv (args);
1686 cleanups = make_cleanup_freeargv (argv);
1688 if (argv[0] != NULL)
1691 /* If a second arg is supplied, it is a source file name to match on. */
1692 if (argv[1] != NULL)
1698 filename = tilde_expand (filename);
1699 make_cleanup (xfree, filename);
1701 outfile = gdb_fopen (filename, FOPEN_WT);
1703 perror_with_name (filename);
1704 make_cleanup_ui_file_delete (outfile);
1707 ALL_PSYMTABS (objfile, ps)
1708 if (symname == NULL || filename_cmp (symname, ps->filename) == 0)
1709 dump_psymtab (objfile, ps, outfile);
1711 do_cleanups (cleanups);
1714 /* List all the partial symbol tables whose names match REGEXP (optional). */
1716 maintenance_info_psymtabs (char *regexp, int from_tty)
1718 struct program_space *pspace;
1719 struct objfile *objfile;
1724 ALL_PSPACES (pspace)
1725 ALL_PSPACE_OBJFILES (pspace, objfile)
1727 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1728 struct partial_symtab *psymtab;
1730 /* We don't want to print anything for this objfile until we
1731 actually find a symtab whose name matches. */
1732 int printed_objfile_start = 0;
1734 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
1739 || re_exec (psymtab->filename))
1741 if (! printed_objfile_start)
1743 printf_filtered ("{ objfile %s ", objfile->name);
1745 printf_filtered ("((struct objfile *) %s)\n",
1746 host_address_to_string (objfile));
1747 printed_objfile_start = 1;
1750 printf_filtered (" { psymtab %s ", psymtab->filename);
1752 printf_filtered ("((struct partial_symtab *) %s)\n",
1753 host_address_to_string (psymtab));
1755 printf_filtered (" readin %s\n",
1756 psymtab->readin ? "yes" : "no");
1757 printf_filtered (" fullname %s\n",
1759 ? psymtab->fullname : "(null)");
1760 printf_filtered (" text addresses ");
1761 fputs_filtered (paddress (gdbarch, psymtab->textlow),
1763 printf_filtered (" -- ");
1764 fputs_filtered (paddress (gdbarch, psymtab->texthigh),
1766 printf_filtered ("\n");
1767 printf_filtered (" globals ");
1768 if (psymtab->n_global_syms)
1770 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1771 host_address_to_string (psymtab->objfile->global_psymbols.list
1772 + psymtab->globals_offset),
1773 psymtab->n_global_syms);
1776 printf_filtered ("(none)\n");
1777 printf_filtered (" statics ");
1778 if (psymtab->n_static_syms)
1780 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1781 host_address_to_string (psymtab->objfile->static_psymbols.list
1782 + psymtab->statics_offset),
1783 psymtab->n_static_syms);
1786 printf_filtered ("(none)\n");
1787 printf_filtered (" dependencies ");
1788 if (psymtab->number_of_dependencies)
1792 printf_filtered ("{\n");
1793 for (i = 0; i < psymtab->number_of_dependencies; i++)
1795 struct partial_symtab *dep = psymtab->dependencies[i];
1797 /* Note the string concatenation there --- no comma. */
1798 printf_filtered (" psymtab %s "
1799 "((struct partial_symtab *) %s)\n",
1801 host_address_to_string (dep));
1803 printf_filtered (" }\n");
1806 printf_filtered ("(none)\n");
1807 printf_filtered (" }\n");
1811 if (printed_objfile_start)
1812 printf_filtered ("}\n");
1816 /* Check consistency of psymtabs and symtabs. */
1819 maintenance_check_symtabs (char *ignore, int from_tty)
1822 struct partial_symbol **psym;
1823 struct symtab *s = NULL;
1824 struct partial_symtab *ps;
1825 struct blockvector *bv;
1826 struct objfile *objfile;
1830 ALL_PSYMTABS (objfile, ps)
1832 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1834 s = PSYMTAB_TO_SYMTAB (ps);
1837 bv = BLOCKVECTOR (s);
1838 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1839 psym = ps->objfile->static_psymbols.list + ps->statics_offset;
1840 length = ps->n_static_syms;
1843 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1844 SYMBOL_DOMAIN (*psym));
1847 printf_filtered ("Static symbol `");
1848 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1849 printf_filtered ("' only found in ");
1850 puts_filtered (ps->filename);
1851 printf_filtered (" psymtab\n");
1855 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1856 psym = ps->objfile->global_psymbols.list + ps->globals_offset;
1857 length = ps->n_global_syms;
1860 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1861 SYMBOL_DOMAIN (*psym));
1864 printf_filtered ("Global symbol `");
1865 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1866 printf_filtered ("' only found in ");
1867 puts_filtered (ps->filename);
1868 printf_filtered (" psymtab\n");
1872 if (ps->texthigh < ps->textlow)
1874 printf_filtered ("Psymtab ");
1875 puts_filtered (ps->filename);
1876 printf_filtered (" covers bad range ");
1877 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
1878 printf_filtered (" - ");
1879 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
1880 printf_filtered ("\n");
1883 if (ps->texthigh == 0)
1885 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
1887 printf_filtered ("Psymtab ");
1888 puts_filtered (ps->filename);
1889 printf_filtered (" covers ");
1890 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
1891 printf_filtered (" - ");
1892 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
1893 printf_filtered (" but symtab covers only ");
1894 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
1895 printf_filtered (" - ");
1896 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout);
1897 printf_filtered ("\n");
1905 expand_partial_symbol_names (int (*fun) (const char *, void *), void *data)
1907 struct objfile *objfile;
1909 ALL_OBJFILES (objfile)
1912 objfile->sf->qf->expand_symtabs_matching (objfile, NULL, fun,
1918 map_partial_symbol_filenames (symbol_filename_ftype *fun, void *data)
1920 struct objfile *objfile;
1922 ALL_OBJFILES (objfile)
1925 objfile->sf->qf->map_symbol_filenames (objfile, fun, data);