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;
137 const char *name_basename = lbasename (name);
139 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
141 if (FILENAME_CMP (name, pst->filename) == 0)
146 /* Before we invoke realpath, which can get expensive when many
147 files are involved, do a quick comparison of the basenames. */
148 if (! basenames_may_differ
149 && FILENAME_CMP (name_basename, lbasename (pst->filename)) != 0)
152 /* If the user gave us an absolute path, try to find the file in
153 this symtab and use its absolute path. */
154 if (full_path != NULL)
156 psymtab_to_fullname (pst);
157 if (pst->fullname != NULL
158 && FILENAME_CMP (full_path, pst->fullname) == 0)
164 if (real_path != NULL)
167 psymtab_to_fullname (pst);
168 if (pst->fullname != NULL)
170 rp = gdb_realpath (pst->fullname);
171 make_cleanup (xfree, rp);
173 if (rp != NULL && FILENAME_CMP (real_path, rp) == 0)
180 /* Now, search for a matching tail (only if name doesn't have any dirs). */
182 if (name_basename == name)
183 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
185 if (FILENAME_CMP (lbasename (pst->filename), name) == 0)
193 lookup_symtab_via_partial_symtab (struct objfile *objfile, const char *name,
194 const char *full_path, const char *real_path,
195 struct symtab **result)
197 struct partial_symtab *ps;
199 ps = lookup_partial_symtab (objfile, name, full_path, real_path);
204 error (_("Internal: readin %s pst for `%s' found when no symtab found."),
207 *result = PSYMTAB_TO_SYMTAB (ps);
211 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
212 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
214 static struct partial_symtab *
215 find_pc_sect_psymtab_closer (CORE_ADDR pc, struct obj_section *section,
216 struct partial_symtab *pst,
217 struct minimal_symbol *msymbol)
219 struct objfile *objfile = pst->objfile;
220 struct partial_symtab *tpst;
221 struct partial_symtab *best_pst = pst;
222 CORE_ADDR best_addr = pst->textlow;
224 gdb_assert (!pst->psymtabs_addrmap_supported);
226 /* An objfile that has its functions reordered might have
227 many partial symbol tables containing the PC, but
228 we want the partial symbol table that contains the
229 function containing the PC. */
230 if (!(objfile->flags & OBJF_REORDERED) &&
231 section == 0) /* Can't validate section this way. */
237 /* The code range of partial symtabs sometimes overlap, so, in
238 the loop below, we need to check all partial symtabs and
239 find the one that fits better for the given PC address. We
240 select the partial symtab that contains a symbol whose
241 address is closest to the PC address. By closest we mean
242 that find_pc_sect_symbol returns the symbol with address
243 that is closest and still less than the given PC. */
244 for (tpst = pst; tpst != NULL; tpst = tpst->next)
246 if (pc >= tpst->textlow && pc < tpst->texthigh)
248 struct partial_symbol *p;
251 /* NOTE: This assumes that every psymbol has a
252 corresponding msymbol, which is not necessarily
253 true; the debug info might be much richer than the
254 object's symbol table. */
255 p = find_pc_sect_psymbol (tpst, pc, section);
257 && SYMBOL_VALUE_ADDRESS (p)
258 == SYMBOL_VALUE_ADDRESS (msymbol))
261 /* Also accept the textlow value of a psymtab as a
262 "symbol", to provide some support for partial
263 symbol tables with line information but no debug
264 symbols (e.g. those produced by an assembler). */
266 this_addr = SYMBOL_VALUE_ADDRESS (p);
268 this_addr = tpst->textlow;
270 /* Check whether it is closer than our current
271 BEST_ADDR. Since this symbol address is
272 necessarily lower or equal to PC, the symbol closer
273 to PC is the symbol which address is the highest.
274 This way we return the psymtab which contains such
275 best match symbol. This can help in cases where the
276 symbol information/debuginfo is not complete, like
277 for instance on IRIX6 with gcc, where no debug info
278 is emitted for statics. (See also the nodebug.exp
280 if (this_addr > best_addr)
282 best_addr = this_addr;
290 /* Find which partial symtab contains PC and SECTION. Return 0 if
291 none. We return the psymtab that contains a symbol whose address
292 exactly matches PC, or, if we cannot find an exact match, the
293 psymtab that contains a symbol whose address is closest to PC. */
294 static struct partial_symtab *
295 find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
296 struct obj_section *section,
297 struct minimal_symbol *msymbol)
299 struct partial_symtab *pst;
301 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
302 than the later used TEXTLOW/TEXTHIGH one. */
304 if (objfile->psymtabs_addrmap != NULL)
306 pst = addrmap_find (objfile->psymtabs_addrmap, pc);
309 /* FIXME: addrmaps currently do not handle overlayed sections,
310 so fall back to the non-addrmap case if we're debugging
311 overlays and the addrmap returned the wrong section. */
312 if (overlay_debugging && msymbol && section)
314 struct partial_symbol *p;
316 /* NOTE: This assumes that every psymbol has a
317 corresponding msymbol, which is not necessarily
318 true; the debug info might be much richer than the
319 object's symbol table. */
320 p = find_pc_sect_psymbol (pst, pc, section);
322 || SYMBOL_VALUE_ADDRESS (p)
323 != SYMBOL_VALUE_ADDRESS (msymbol))
327 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
328 PSYMTABS_ADDRMAP we used has already the best 1-byte
329 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
330 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
339 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
340 which still have no corresponding full SYMTABs read. But it is not
341 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
344 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
345 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
346 debug info type in single OBJFILE. */
348 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
349 if (!pst->psymtabs_addrmap_supported
350 && pc >= pst->textlow && pc < pst->texthigh)
352 struct partial_symtab *best_pst;
354 best_pst = find_pc_sect_psymtab_closer (pc, section, pst, msymbol);
355 if (best_pst != NULL)
362 static struct symtab *
363 find_pc_sect_symtab_from_partial (struct objfile *objfile,
364 struct minimal_symbol *msymbol,
365 CORE_ADDR pc, struct obj_section *section,
368 struct partial_symtab *ps = find_pc_sect_psymtab (objfile, pc, section,
372 if (warn_if_readin && ps->readin)
373 /* Might want to error() here (in case symtab is corrupt and
374 will cause a core dump), but maybe we can successfully
375 continue, so let's not. */
377 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
378 paddress (get_objfile_arch (ps->objfile), pc));
379 return PSYMTAB_TO_SYMTAB (ps);
384 /* Find which partial symbol within a psymtab matches PC and SECTION.
387 static struct partial_symbol *
388 find_pc_sect_psymbol (struct partial_symtab *psymtab, CORE_ADDR pc,
389 struct obj_section *section)
391 struct partial_symbol *best = NULL, *p, **pp;
394 gdb_assert (psymtab != NULL);
396 /* Cope with programs that start at address 0. */
397 best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0;
399 /* Search the global symbols as well as the static symbols, so that
400 find_pc_partial_function doesn't use a minimal symbol and thus
401 cache a bad endaddr. */
402 for (pp = psymtab->objfile->global_psymbols.list + psymtab->globals_offset;
403 (pp - (psymtab->objfile->global_psymbols.list + psymtab->globals_offset)
404 < psymtab->n_global_syms);
408 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
409 && SYMBOL_CLASS (p) == LOC_BLOCK
410 && pc >= SYMBOL_VALUE_ADDRESS (p)
411 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
412 || (psymtab->textlow == 0
413 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
415 if (section) /* Match on a specific section. */
417 fixup_psymbol_section (p, psymtab->objfile);
418 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
421 best_pc = SYMBOL_VALUE_ADDRESS (p);
426 for (pp = psymtab->objfile->static_psymbols.list + psymtab->statics_offset;
427 (pp - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset)
428 < psymtab->n_static_syms);
432 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
433 && SYMBOL_CLASS (p) == LOC_BLOCK
434 && pc >= SYMBOL_VALUE_ADDRESS (p)
435 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
436 || (psymtab->textlow == 0
437 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
439 if (section) /* Match on a specific section. */
441 fixup_psymbol_section (p, psymtab->objfile);
442 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
445 best_pc = SYMBOL_VALUE_ADDRESS (p);
453 static struct partial_symbol *
454 fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
461 if (SYMBOL_OBJ_SECTION (psym))
464 gdb_assert (objfile);
466 switch (SYMBOL_CLASS (psym))
471 addr = SYMBOL_VALUE_ADDRESS (psym);
474 /* Nothing else will be listed in the minsyms -- no use looking
479 fixup_section (&psym->ginfo, addr, objfile);
484 static struct symtab *
485 lookup_symbol_aux_psymtabs (struct objfile *objfile,
486 int block_index, const char *name,
487 const domain_enum domain)
489 struct partial_symtab *ps;
490 const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
492 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
494 if (!ps->readin && lookup_partial_symbol (ps, name, psymtab_index, domain))
496 struct symbol *sym = NULL;
497 struct symtab *stab = PSYMTAB_TO_SYMTAB (ps);
499 /* Some caution must be observed with overloaded functions
500 and methods, since the psymtab will not contain any overload
501 information (but NAME might contain it). */
504 struct blockvector *bv = BLOCKVECTOR (stab);
505 struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
507 sym = lookup_block_symbol (block, name, domain);
510 if (sym && strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0)
513 /* Keep looking through other psymtabs. */
520 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
521 the global block of PST if GLOBAL, and otherwise the static block.
522 MATCH is the comparison operation that returns true iff MATCH (s,
523 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
524 non-null, the symbols in the block are assumed to be ordered
525 according to it (allowing binary search). It must be compatible
526 with MATCH. Returns the symbol, if found, and otherwise NULL. */
528 static struct partial_symbol *
529 match_partial_symbol (struct partial_symtab *pst, int global,
530 const char *name, domain_enum domain,
531 symbol_compare_ftype *match,
532 symbol_compare_ftype *ordered_compare)
534 struct partial_symbol **start, **psym;
535 struct partial_symbol **top, **real_top, **bottom, **center;
536 int length = (global ? pst->n_global_syms : pst->n_static_syms);
537 int do_linear_search = 1;
542 pst->objfile->global_psymbols.list + pst->globals_offset :
543 pst->objfile->static_psymbols.list + pst->statics_offset);
545 if (global && ordered_compare) /* Can use a binary search. */
547 do_linear_search = 0;
549 /* Binary search. This search is guaranteed to end with center
550 pointing at the earliest partial symbol whose name might be
551 correct. At that point *all* partial symbols with an
552 appropriate name will be checked against the correct
556 top = start + length - 1;
560 center = bottom + (top - bottom) / 2;
561 gdb_assert (center < top);
562 if (!do_linear_search
563 && (SYMBOL_LANGUAGE (*center) == language_java))
564 do_linear_search = 1;
565 if (ordered_compare (SYMBOL_SEARCH_NAME (*center), name) >= 0)
570 gdb_assert (top == bottom);
572 while (top <= real_top
573 && match (SYMBOL_SEARCH_NAME (*top), name) == 0)
575 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
576 SYMBOL_DOMAIN (*top), domain))
582 /* Can't use a binary search or else we found during the binary search that
583 we should also do a linear search. */
585 if (do_linear_search)
587 for (psym = start; psym < start + length; psym++)
589 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
590 SYMBOL_DOMAIN (*psym), domain)
591 && match (SYMBOL_SEARCH_NAME (*psym), name) == 0)
600 pre_expand_symtabs_matching_psymtabs (struct objfile *objfile,
601 enum block_enum block_kind,
608 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
609 not contain any method/function instance information (since this would
610 force reading type information while reading psymtabs). Therefore,
611 if NAME contains overload information, it must be stripped before searching
614 The caller is responsible for freeing the return result. */
617 psymtab_search_name (const char *name)
619 switch (current_language->la_language)
624 if (strchr (name, '('))
626 char *ret = cp_remove_params (name);
638 return xstrdup (name);
641 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
642 Check the global symbols if GLOBAL, the static symbols if not. */
644 static struct partial_symbol *
645 lookup_partial_symbol (struct partial_symtab *pst, const char *name,
646 int global, domain_enum domain)
648 struct partial_symbol **start, **psym;
649 struct partial_symbol **top, **real_top, **bottom, **center;
650 int length = (global ? pst->n_global_syms : pst->n_static_syms);
651 int do_linear_search = 1;
653 struct cleanup *cleanup;
660 search_name = psymtab_search_name (name);
661 cleanup = make_cleanup (xfree, search_name);
663 pst->objfile->global_psymbols.list + pst->globals_offset :
664 pst->objfile->static_psymbols.list + pst->statics_offset);
666 if (global) /* This means we can use a binary search. */
668 do_linear_search = 0;
670 /* Binary search. This search is guaranteed to end with center
671 pointing at the earliest partial symbol whose name might be
672 correct. At that point *all* partial symbols with an
673 appropriate name will be checked against the correct
677 top = start + length - 1;
681 center = bottom + (top - bottom) / 2;
683 internal_error (__FILE__, __LINE__,
684 _("failed internal consistency check"));
685 if (!do_linear_search
686 && SYMBOL_LANGUAGE (*center) == language_java)
688 do_linear_search = 1;
690 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center),
700 if (!(top == bottom))
701 internal_error (__FILE__, __LINE__,
702 _("failed internal consistency check"));
704 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
705 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
706 while (top >= start && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
709 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
712 while (top <= real_top && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
714 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
715 SYMBOL_DOMAIN (*top), domain))
717 do_cleanups (cleanup);
724 /* Can't use a binary search or else we found during the binary search that
725 we should also do a linear search. */
727 if (do_linear_search)
729 for (psym = start; psym < start + length; psym++)
731 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
732 SYMBOL_DOMAIN (*psym), domain)
733 && SYMBOL_MATCHES_SEARCH_NAME (*psym, search_name))
735 do_cleanups (cleanup);
741 do_cleanups (cleanup);
745 /* Get the symbol table that corresponds to a partial_symtab.
746 This is fast after the first time you do it. In fact, there
747 is an even faster macro PSYMTAB_TO_SYMTAB that does the fast
750 static struct symtab *
751 psymtab_to_symtab (struct partial_symtab *pst)
753 /* If it's been looked up before, return it. */
757 /* If it has not yet been read in, read it. */
760 struct cleanup *back_to = increment_reading_symtab ();
762 (*pst->read_symtab) (pst);
763 do_cleanups (back_to);
770 relocate_psymtabs (struct objfile *objfile,
771 struct section_offsets *new_offsets,
772 struct section_offsets *delta)
774 struct partial_symbol **psym;
775 struct partial_symtab *p;
777 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
779 p->textlow += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
780 p->texthigh += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
783 for (psym = objfile->global_psymbols.list;
784 psym < objfile->global_psymbols.next;
787 fixup_psymbol_section (*psym, objfile);
788 if (SYMBOL_SECTION (*psym) >= 0)
789 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
790 SYMBOL_SECTION (*psym));
792 for (psym = objfile->static_psymbols.list;
793 psym < objfile->static_psymbols.next;
796 fixup_psymbol_section (*psym, objfile);
797 if (SYMBOL_SECTION (*psym) >= 0)
798 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
799 SYMBOL_SECTION (*psym));
803 static struct symtab *
804 find_last_source_symtab_from_partial (struct objfile *ofp)
806 struct partial_symtab *ps;
807 struct partial_symtab *cs_pst = 0;
809 ALL_OBJFILE_PSYMTABS_REQUIRED (ofp, ps)
811 const char *name = ps->filename;
812 int len = strlen (name);
814 if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0
815 || strcmp (name, "<<C++-namespaces>>") == 0)))
823 internal_error (__FILE__, __LINE__,
824 _("select_source_symtab: "
825 "readin pst found and no symtabs."));
828 return PSYMTAB_TO_SYMTAB (cs_pst);
834 forget_cached_source_info_partial (struct objfile *objfile)
836 struct partial_symtab *pst;
838 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
840 if (pst->fullname != NULL)
842 xfree (pst->fullname);
843 pst->fullname = NULL;
849 print_partial_symbols (struct gdbarch *gdbarch,
850 struct partial_symbol **p, int count, char *what,
851 struct ui_file *outfile)
853 fprintf_filtered (outfile, " %s partial symbols:\n", what);
856 fprintf_filtered (outfile, " `%s'", SYMBOL_LINKAGE_NAME (*p));
857 if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
859 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
861 fputs_filtered (", ", outfile);
862 switch (SYMBOL_DOMAIN (*p))
865 fputs_filtered ("undefined domain, ", outfile);
868 /* This is the usual thing -- don't print it. */
871 fputs_filtered ("struct domain, ", outfile);
874 fputs_filtered ("label domain, ", outfile);
877 fputs_filtered ("<invalid domain>, ", outfile);
880 switch (SYMBOL_CLASS (*p))
883 fputs_filtered ("undefined", outfile);
886 fputs_filtered ("constant int", outfile);
889 fputs_filtered ("static", outfile);
892 fputs_filtered ("register", outfile);
895 fputs_filtered ("pass by value", outfile);
898 fputs_filtered ("pass by reference", outfile);
900 case LOC_REGPARM_ADDR:
901 fputs_filtered ("register address parameter", outfile);
904 fputs_filtered ("stack parameter", outfile);
907 fputs_filtered ("type", outfile);
910 fputs_filtered ("label", outfile);
913 fputs_filtered ("function", outfile);
915 case LOC_CONST_BYTES:
916 fputs_filtered ("constant bytes", outfile);
919 fputs_filtered ("unresolved", outfile);
921 case LOC_OPTIMIZED_OUT:
922 fputs_filtered ("optimized out", outfile);
925 fputs_filtered ("computed at runtime", outfile);
928 fputs_filtered ("<invalid location>", outfile);
931 fputs_filtered (", ", outfile);
932 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (*p)), outfile);
933 fprintf_filtered (outfile, "\n");
939 dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
940 struct ui_file *outfile)
942 struct gdbarch *gdbarch = get_objfile_arch (objfile);
945 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
947 fprintf_filtered (outfile, "(object ");
948 gdb_print_host_address (psymtab, outfile);
949 fprintf_filtered (outfile, ")\n\n");
950 fprintf_unfiltered (outfile, " Read from object file %s (",
952 gdb_print_host_address (objfile, outfile);
953 fprintf_unfiltered (outfile, ")\n");
957 fprintf_filtered (outfile,
958 " Full symtab was read (at ");
959 gdb_print_host_address (psymtab->symtab, outfile);
960 fprintf_filtered (outfile, " by function at ");
961 gdb_print_host_address (psymtab->read_symtab, outfile);
962 fprintf_filtered (outfile, ")\n");
965 fprintf_filtered (outfile, " Relocate symbols by ");
966 for (i = 0; i < psymtab->objfile->num_sections; ++i)
969 fprintf_filtered (outfile, ", ");
971 fputs_filtered (paddress (gdbarch,
972 ANOFFSET (psymtab->section_offsets, i)),
975 fprintf_filtered (outfile, "\n");
977 fprintf_filtered (outfile, " Symbols cover text addresses ");
978 fputs_filtered (paddress (gdbarch, psymtab->textlow), outfile);
979 fprintf_filtered (outfile, "-");
980 fputs_filtered (paddress (gdbarch, psymtab->texthigh), outfile);
981 fprintf_filtered (outfile, "\n");
982 fprintf_filtered (outfile, " Address map supported - %s.\n",
983 psymtab->psymtabs_addrmap_supported ? "yes" : "no");
984 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
985 psymtab->number_of_dependencies);
986 for (i = 0; i < psymtab->number_of_dependencies; i++)
988 fprintf_filtered (outfile, " %d ", i);
989 gdb_print_host_address (psymtab->dependencies[i], outfile);
990 fprintf_filtered (outfile, " %s\n",
991 psymtab->dependencies[i]->filename);
993 if (psymtab->n_global_syms > 0)
995 print_partial_symbols (gdbarch,
996 objfile->global_psymbols.list
997 + psymtab->globals_offset,
998 psymtab->n_global_syms, "Global", outfile);
1000 if (psymtab->n_static_syms > 0)
1002 print_partial_symbols (gdbarch,
1003 objfile->static_psymbols.list
1004 + psymtab->statics_offset,
1005 psymtab->n_static_syms, "Static", outfile);
1007 fprintf_filtered (outfile, "\n");
1011 print_psymtab_stats_for_objfile (struct objfile *objfile)
1014 struct partial_symtab *ps;
1017 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1019 if (ps->readin == 0)
1022 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i);
1026 dump_psymtabs_for_objfile (struct objfile *objfile)
1028 struct partial_symtab *psymtab;
1030 if (objfile->psymtabs)
1032 printf_filtered ("Psymtabs:\n");
1033 for (psymtab = objfile->psymtabs;
1035 psymtab = psymtab->next)
1037 printf_filtered ("%s at ",
1039 gdb_print_host_address (psymtab, gdb_stdout);
1040 printf_filtered (", ");
1041 if (psymtab->objfile != objfile)
1043 printf_filtered ("NOT ON CHAIN! ");
1047 printf_filtered ("\n\n");
1051 /* Look through the partial symtabs for all symbols which begin
1052 by matching FUNC_NAME. Make sure we read that symbol table in. */
1055 read_symtabs_for_function (struct objfile *objfile, const char *func_name)
1057 struct partial_symtab *ps;
1059 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1064 if ((lookup_partial_symbol (ps, func_name, 1, VAR_DOMAIN)
1066 || (lookup_partial_symbol (ps, func_name, 0, VAR_DOMAIN)
1068 psymtab_to_symtab (ps);
1073 expand_partial_symbol_tables (struct objfile *objfile)
1075 struct partial_symtab *psymtab;
1077 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
1079 psymtab_to_symtab (psymtab);
1084 read_psymtabs_with_filename (struct objfile *objfile, const char *filename)
1086 struct partial_symtab *p;
1088 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
1090 if (filename_cmp (filename, p->filename) == 0)
1091 PSYMTAB_TO_SYMTAB (p);
1096 map_symbol_filenames_psymtab (struct objfile *objfile,
1097 symbol_filename_ftype *fun, void *data,
1100 struct partial_symtab *ps;
1102 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1104 const char *fullname;
1111 fullname = psymtab_to_fullname (ps);
1114 (*fun) (ps->filename, fullname, data);
1118 int find_and_open_source (const char *filename,
1119 const char *dirname,
1122 /* Finds the fullname that a partial_symtab represents.
1124 If this functions finds the fullname, it will save it in ps->fullname
1125 and it will also return the value.
1127 If this function fails to find the file that this partial_symtab represents,
1128 NULL will be returned and ps->fullname will be set to NULL. */
1131 psymtab_to_fullname (struct partial_symtab *ps)
1138 /* Use cached copy if we have it.
1139 We rely on forget_cached_source_info being called appropriately
1140 to handle cases like the file being moved. */
1142 return ps->fullname;
1144 r = find_and_open_source (ps->filename, ps->dirname, &ps->fullname);
1149 return ps->fullname;
1156 find_symbol_file_from_partial (struct objfile *objfile, const char *name)
1158 struct partial_symtab *pst;
1160 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
1162 if (lookup_partial_symbol (pst, name, 1, VAR_DOMAIN))
1163 return pst->filename;
1168 /* For all symbols, s, in BLOCK that are in NAMESPACE and match NAME
1169 according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
1170 BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK
1171 ever returns non-zero, and otherwise returns 0. */
1174 map_block (const char *name, domain_enum namespace, struct objfile *objfile,
1175 struct block *block,
1176 int (*callback) (struct block *, struct symbol *, void *),
1177 void *data, symbol_compare_ftype *match)
1179 struct dict_iterator iter;
1182 for (sym = dict_iter_match_first (BLOCK_DICT (block), name, match, &iter);
1183 sym != NULL; sym = dict_iter_match_next (name, match, &iter))
1185 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
1186 SYMBOL_DOMAIN (sym), namespace))
1188 if (callback (block, sym, data))
1196 /* Psymtab version of map_matching_symbols. See its definition in
1197 the definition of quick_symbol_functions in symfile.h. */
1200 map_matching_symbols_psymtab (const char *name, domain_enum namespace,
1201 struct objfile *objfile, int global,
1202 int (*callback) (struct block *,
1203 struct symbol *, void *),
1205 symbol_compare_ftype *match,
1206 symbol_compare_ftype *ordered_compare)
1208 const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
1209 struct partial_symtab *ps;
1211 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1215 || match_partial_symbol (ps, global, name, namespace, match,
1218 struct symtab *s = PSYMTAB_TO_SYMTAB (ps);
1219 struct block *block;
1221 if (s == NULL || !s->primary)
1223 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), block_kind);
1224 if (map_block (name, namespace, objfile, block,
1225 callback, data, match))
1227 if (callback (block, NULL, data))
1234 expand_symtabs_matching_via_partial (struct objfile *objfile,
1235 int (*file_matcher) (const char *,
1237 int (*name_matcher) (const char *,
1239 enum search_domain kind,
1242 struct partial_symtab *ps;
1244 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1246 struct partial_symbol **psym;
1247 struct partial_symbol **bound, **gbound, **sbound;
1253 if (file_matcher && ! (*file_matcher) (ps->filename, data))
1256 gbound = objfile->global_psymbols.list
1257 + ps->globals_offset + ps->n_global_syms;
1258 sbound = objfile->static_psymbols.list
1259 + ps->statics_offset + ps->n_static_syms;
1262 /* Go through all of the symbols stored in a partial
1263 symtab in one loop. */
1264 psym = objfile->global_psymbols.list + ps->globals_offset;
1269 if (bound == gbound && ps->n_static_syms != 0)
1271 psym = objfile->static_psymbols.list + ps->statics_offset;
1282 if ((kind == ALL_DOMAIN
1283 || (kind == VARIABLES_DOMAIN
1284 && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
1285 && SYMBOL_CLASS (*psym) != LOC_BLOCK)
1286 || (kind == FUNCTIONS_DOMAIN
1287 && SYMBOL_CLASS (*psym) == LOC_BLOCK)
1288 || (kind == TYPES_DOMAIN
1289 && SYMBOL_CLASS (*psym) == LOC_TYPEDEF))
1290 && (*name_matcher) (SYMBOL_NATURAL_NAME (*psym), data))
1292 PSYMTAB_TO_SYMTAB (ps);
1302 objfile_has_psyms (struct objfile *objfile)
1304 return objfile->psymtabs != NULL;
1307 const struct quick_symbol_functions psym_functions =
1310 find_last_source_symtab_from_partial,
1311 forget_cached_source_info_partial,
1312 lookup_symtab_via_partial_symtab,
1313 lookup_symbol_aux_psymtabs,
1314 pre_expand_symtabs_matching_psymtabs,
1315 print_psymtab_stats_for_objfile,
1316 dump_psymtabs_for_objfile,
1318 read_symtabs_for_function,
1319 expand_partial_symbol_tables,
1320 read_psymtabs_with_filename,
1321 find_symbol_file_from_partial,
1322 map_matching_symbols_psymtab,
1323 expand_symtabs_matching_via_partial,
1324 find_pc_sect_symtab_from_partial,
1325 map_symbol_filenames_psymtab
1330 /* This compares two partial symbols by names, using strcmp_iw_ordered
1331 for the comparison. */
1334 compare_psymbols (const void *s1p, const void *s2p)
1336 struct partial_symbol *const *s1 = s1p;
1337 struct partial_symbol *const *s2 = s2p;
1339 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1),
1340 SYMBOL_SEARCH_NAME (*s2));
1344 sort_pst_symbols (struct partial_symtab *pst)
1346 /* Sort the global list; don't sort the static list. */
1348 qsort (pst->objfile->global_psymbols.list + pst->globals_offset,
1349 pst->n_global_syms, sizeof (struct partial_symbol *),
1353 /* Allocate and partially fill a partial symtab. It will be
1354 completely filled at the end of the symbol list.
1356 FILENAME is the name of the symbol-file we are reading from. */
1358 struct partial_symtab *
1359 start_psymtab_common (struct objfile *objfile,
1360 struct section_offsets *section_offsets,
1361 const char *filename,
1362 CORE_ADDR textlow, struct partial_symbol **global_syms,
1363 struct partial_symbol **static_syms)
1365 struct partial_symtab *psymtab;
1367 psymtab = allocate_psymtab (filename, objfile);
1368 psymtab->section_offsets = section_offsets;
1369 psymtab->textlow = textlow;
1370 psymtab->texthigh = psymtab->textlow; /* default */
1371 psymtab->globals_offset = global_syms - objfile->global_psymbols.list;
1372 psymtab->statics_offset = static_syms - objfile->static_psymbols.list;
1376 /* Calculate a hash code for the given partial symbol. The hash is
1377 calculated using the symbol's value, language, domain, class
1378 and name. These are the values which are set by
1379 add_psymbol_to_bcache. */
1381 static unsigned long
1382 psymbol_hash (const void *addr, int length)
1384 unsigned long h = 0;
1385 struct partial_symbol *psymbol = (struct partial_symbol *) addr;
1386 unsigned int lang = psymbol->ginfo.language;
1387 unsigned int domain = PSYMBOL_DOMAIN (psymbol);
1388 unsigned int class = PSYMBOL_CLASS (psymbol);
1390 h = hash_continue (&psymbol->ginfo.value, sizeof (psymbol->ginfo.value), h);
1391 h = hash_continue (&lang, sizeof (unsigned int), h);
1392 h = hash_continue (&domain, sizeof (unsigned int), h);
1393 h = hash_continue (&class, sizeof (unsigned int), h);
1394 h = hash_continue (psymbol->ginfo.name, strlen (psymbol->ginfo.name), h);
1399 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1400 For the comparison this function uses a symbols value,
1401 language, domain, class and name. */
1404 psymbol_compare (const void *addr1, const void *addr2, int length)
1406 struct partial_symbol *sym1 = (struct partial_symbol *) addr1;
1407 struct partial_symbol *sym2 = (struct partial_symbol *) addr2;
1409 return (memcmp (&sym1->ginfo.value, &sym1->ginfo.value,
1410 sizeof (sym1->ginfo.value)) == 0
1411 && sym1->ginfo.language == sym2->ginfo.language
1412 && PSYMBOL_DOMAIN (sym1) == PSYMBOL_DOMAIN (sym2)
1413 && PSYMBOL_CLASS (sym1) == PSYMBOL_CLASS (sym2)
1414 && sym1->ginfo.name == sym2->ginfo.name);
1417 /* Initialize a partial symbol bcache. */
1419 struct psymbol_bcache *
1420 psymbol_bcache_init (void)
1422 struct psymbol_bcache *bcache = XCALLOC (1, struct psymbol_bcache);
1423 bcache->bcache = bcache_xmalloc (psymbol_hash, psymbol_compare);
1427 /* Free a partial symbol bcache. */
1429 psymbol_bcache_free (struct psymbol_bcache *bcache)
1434 bcache_xfree (bcache->bcache);
1438 /* Return the internal bcache of the psymbol_bcache BCACHE. */
1441 psymbol_bcache_get_bcache (struct psymbol_bcache *bcache)
1443 return bcache->bcache;
1446 /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1447 symbol before, add a copy to BCACHE. In either case, return a pointer
1448 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1449 1 in case of new entry or 0 if returning an old entry. */
1451 static const struct partial_symbol *
1452 psymbol_bcache_full (struct partial_symbol *sym,
1453 struct psymbol_bcache *bcache,
1456 return bcache_full (sym,
1457 sizeof (struct partial_symbol),
1462 /* Helper function, initialises partial symbol structure and stashes
1463 it into objfile's bcache. Note that our caching mechanism will
1464 use all fields of struct partial_symbol to determine hash value of the
1465 structure. In other words, having two symbols with the same name but
1466 different domain (or address) is possible and correct. */
1468 static const struct partial_symbol *
1469 add_psymbol_to_bcache (const char *name, int namelength, int copy_name,
1471 enum address_class class,
1472 long val, /* Value as a long */
1473 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1474 enum language language, struct objfile *objfile,
1477 struct partial_symbol psymbol;
1479 /* We must ensure that the entire 'value' field has been zeroed
1480 before assigning to it, because an assignment may not write the
1482 memset (&psymbol.ginfo.value, 0, sizeof (psymbol.ginfo.value));
1484 /* val and coreaddr are mutually exclusive, one of them *will* be zero. */
1487 SYMBOL_VALUE (&psymbol) = val;
1491 SYMBOL_VALUE_ADDRESS (&psymbol) = coreaddr;
1493 SYMBOL_SECTION (&psymbol) = 0;
1494 SYMBOL_OBJ_SECTION (&psymbol) = NULL;
1495 SYMBOL_SET_LANGUAGE (&psymbol, language);
1496 PSYMBOL_DOMAIN (&psymbol) = domain;
1497 PSYMBOL_CLASS (&psymbol) = class;
1499 SYMBOL_SET_NAMES (&psymbol, name, namelength, copy_name, objfile);
1501 /* Stash the partial symbol away in the cache. */
1502 return psymbol_bcache_full (&psymbol,
1503 objfile->psymbol_cache,
1507 /* Increase the space allocated for LISTP, which is probably
1508 global_psymbols or static_psymbols. This space will eventually
1509 be freed in free_objfile(). */
1512 extend_psymbol_list (struct psymbol_allocation_list *listp,
1513 struct objfile *objfile)
1517 if (listp->size == 0)
1520 listp->list = (struct partial_symbol **)
1521 xmalloc (new_size * sizeof (struct partial_symbol *));
1525 new_size = listp->size * 2;
1526 listp->list = (struct partial_symbol **)
1527 xrealloc ((char *) listp->list,
1528 new_size * sizeof (struct partial_symbol *));
1530 /* Next assumes we only went one over. Should be good if
1531 program works correctly. */
1532 listp->next = listp->list + listp->size;
1533 listp->size = new_size;
1536 /* Helper function, adds partial symbol to the given partial symbol
1540 append_psymbol_to_list (struct psymbol_allocation_list *list,
1541 const struct partial_symbol *psym,
1542 struct objfile *objfile)
1544 if (list->next >= list->list + list->size)
1545 extend_psymbol_list (list, objfile);
1546 *list->next++ = (struct partial_symbol *) psym;
1547 OBJSTAT (objfile, n_psyms++);
1550 /* Add a symbol with a long value to a psymtab.
1551 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1552 Return the partial symbol that has been added. */
1554 /* NOTE: carlton/2003-09-11: The reason why we return the partial
1555 symbol is so that callers can get access to the symbol's demangled
1556 name, which they don't have any cheap way to determine otherwise.
1557 (Currenly, dwarf2read.c is the only file who uses that information,
1558 though it's possible that other readers might in the future.)
1559 Elena wasn't thrilled about that, and I don't blame her, but we
1560 couldn't come up with a better way to get that information. If
1561 it's needed in other situations, we could consider breaking up
1562 SYMBOL_SET_NAMES to provide access to the demangled name lookup
1565 const struct partial_symbol *
1566 add_psymbol_to_list (const char *name, int namelength, int copy_name,
1568 enum address_class class,
1569 struct psymbol_allocation_list *list,
1570 long val, /* Value as a long */
1571 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1572 enum language language, struct objfile *objfile)
1574 const struct partial_symbol *psym;
1578 /* Stash the partial symbol away in the cache. */
1579 psym = add_psymbol_to_bcache (name, namelength, copy_name, domain, class,
1580 val, coreaddr, language, objfile, &added);
1582 /* Do not duplicate global partial symbols. */
1583 if (list == &objfile->global_psymbols
1587 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1588 append_psymbol_to_list (list, psym, objfile);
1592 /* Initialize storage for partial symbols. */
1595 init_psymbol_list (struct objfile *objfile, int total_symbols)
1597 /* Free any previously allocated psymbol lists. */
1599 if (objfile->global_psymbols.list)
1601 xfree (objfile->global_psymbols.list);
1603 if (objfile->static_psymbols.list)
1605 xfree (objfile->static_psymbols.list);
1608 /* Current best guess is that approximately a twentieth
1609 of the total symbols (in a debugging file) are global or static
1610 oriented symbols. */
1612 objfile->global_psymbols.size = total_symbols / 10;
1613 objfile->static_psymbols.size = total_symbols / 10;
1615 if (objfile->global_psymbols.size > 0)
1617 objfile->global_psymbols.next =
1618 objfile->global_psymbols.list = (struct partial_symbol **)
1619 xmalloc ((objfile->global_psymbols.size
1620 * sizeof (struct partial_symbol *)));
1622 if (objfile->static_psymbols.size > 0)
1624 objfile->static_psymbols.next =
1625 objfile->static_psymbols.list = (struct partial_symbol **)
1626 xmalloc ((objfile->static_psymbols.size
1627 * sizeof (struct partial_symbol *)));
1631 struct partial_symtab *
1632 allocate_psymtab (const char *filename, struct objfile *objfile)
1634 struct partial_symtab *psymtab;
1636 if (objfile->free_psymtabs)
1638 psymtab = objfile->free_psymtabs;
1639 objfile->free_psymtabs = psymtab->next;
1642 psymtab = (struct partial_symtab *)
1643 obstack_alloc (&objfile->objfile_obstack,
1644 sizeof (struct partial_symtab));
1646 memset (psymtab, 0, sizeof (struct partial_symtab));
1647 psymtab->filename = obsavestring (filename, strlen (filename),
1648 &objfile->objfile_obstack);
1649 psymtab->symtab = NULL;
1651 /* Prepend it to the psymtab list for the objfile it belongs to.
1652 Psymtabs are searched in most recent inserted -> least recent
1655 psymtab->objfile = objfile;
1656 psymtab->next = objfile->psymtabs;
1657 objfile->psymtabs = psymtab;
1663 discard_psymtab (struct partial_symtab *pst)
1665 struct partial_symtab **prev_pst;
1668 Empty psymtabs happen as a result of header files which don't
1669 have any symbols in them. There can be a lot of them. But this
1670 check is wrong, in that a psymtab with N_SLINE entries but
1671 nothing else is not empty, but we don't realize that. Fixing
1672 that without slowing things down might be tricky. */
1674 /* First, snip it out of the psymtab chain. */
1676 prev_pst = &(pst->objfile->psymtabs);
1677 while ((*prev_pst) != pst)
1678 prev_pst = &((*prev_pst)->next);
1679 (*prev_pst) = pst->next;
1681 /* Next, put it on a free list for recycling. */
1683 pst->next = pst->objfile->free_psymtabs;
1684 pst->objfile->free_psymtabs = pst;
1690 maintenance_print_psymbols (char *args, int from_tty)
1693 struct ui_file *outfile;
1694 struct cleanup *cleanups;
1695 char *symname = NULL;
1696 char *filename = DEV_TTY;
1697 struct objfile *objfile;
1698 struct partial_symtab *ps;
1705 print-psymbols takes an output file name and optional symbol file name"));
1707 argv = gdb_buildargv (args);
1708 cleanups = make_cleanup_freeargv (argv);
1710 if (argv[0] != NULL)
1713 /* If a second arg is supplied, it is a source file name to match on. */
1714 if (argv[1] != NULL)
1720 filename = tilde_expand (filename);
1721 make_cleanup (xfree, filename);
1723 outfile = gdb_fopen (filename, FOPEN_WT);
1725 perror_with_name (filename);
1726 make_cleanup_ui_file_delete (outfile);
1729 ALL_PSYMTABS (objfile, ps)
1730 if (symname == NULL || filename_cmp (symname, ps->filename) == 0)
1731 dump_psymtab (objfile, ps, outfile);
1733 do_cleanups (cleanups);
1736 /* List all the partial symbol tables whose names match REGEXP (optional). */
1738 maintenance_info_psymtabs (char *regexp, int from_tty)
1740 struct program_space *pspace;
1741 struct objfile *objfile;
1746 ALL_PSPACES (pspace)
1747 ALL_PSPACE_OBJFILES (pspace, objfile)
1749 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1750 struct partial_symtab *psymtab;
1752 /* We don't want to print anything for this objfile until we
1753 actually find a symtab whose name matches. */
1754 int printed_objfile_start = 0;
1756 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
1761 || re_exec (psymtab->filename))
1763 if (! printed_objfile_start)
1765 printf_filtered ("{ objfile %s ", objfile->name);
1767 printf_filtered ("((struct objfile *) %s)\n",
1768 host_address_to_string (objfile));
1769 printed_objfile_start = 1;
1772 printf_filtered (" { psymtab %s ", psymtab->filename);
1774 printf_filtered ("((struct partial_symtab *) %s)\n",
1775 host_address_to_string (psymtab));
1777 printf_filtered (" readin %s\n",
1778 psymtab->readin ? "yes" : "no");
1779 printf_filtered (" fullname %s\n",
1781 ? psymtab->fullname : "(null)");
1782 printf_filtered (" text addresses ");
1783 fputs_filtered (paddress (gdbarch, psymtab->textlow),
1785 printf_filtered (" -- ");
1786 fputs_filtered (paddress (gdbarch, psymtab->texthigh),
1788 printf_filtered ("\n");
1789 printf_filtered (" psymtabs_addrmap_supported %s\n",
1790 (psymtab->psymtabs_addrmap_supported
1792 printf_filtered (" globals ");
1793 if (psymtab->n_global_syms)
1795 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1796 host_address_to_string (psymtab->objfile->global_psymbols.list
1797 + psymtab->globals_offset),
1798 psymtab->n_global_syms);
1801 printf_filtered ("(none)\n");
1802 printf_filtered (" statics ");
1803 if (psymtab->n_static_syms)
1805 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1806 host_address_to_string (psymtab->objfile->static_psymbols.list
1807 + psymtab->statics_offset),
1808 psymtab->n_static_syms);
1811 printf_filtered ("(none)\n");
1812 printf_filtered (" dependencies ");
1813 if (psymtab->number_of_dependencies)
1817 printf_filtered ("{\n");
1818 for (i = 0; i < psymtab->number_of_dependencies; i++)
1820 struct partial_symtab *dep = psymtab->dependencies[i];
1822 /* Note the string concatenation there --- no comma. */
1823 printf_filtered (" psymtab %s "
1824 "((struct partial_symtab *) %s)\n",
1826 host_address_to_string (dep));
1828 printf_filtered (" }\n");
1831 printf_filtered ("(none)\n");
1832 printf_filtered (" }\n");
1836 if (printed_objfile_start)
1837 printf_filtered ("}\n");
1841 /* Check consistency of psymtabs and symtabs. */
1844 maintenance_check_symtabs (char *ignore, int from_tty)
1847 struct partial_symbol **psym;
1848 struct symtab *s = NULL;
1849 struct partial_symtab *ps;
1850 struct blockvector *bv;
1851 struct objfile *objfile;
1855 ALL_PSYMTABS (objfile, ps)
1857 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1859 s = PSYMTAB_TO_SYMTAB (ps);
1862 bv = BLOCKVECTOR (s);
1863 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1864 psym = ps->objfile->static_psymbols.list + ps->statics_offset;
1865 length = ps->n_static_syms;
1868 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1869 SYMBOL_DOMAIN (*psym));
1872 printf_filtered ("Static symbol `");
1873 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1874 printf_filtered ("' only found in ");
1875 puts_filtered (ps->filename);
1876 printf_filtered (" psymtab\n");
1880 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1881 psym = ps->objfile->global_psymbols.list + ps->globals_offset;
1882 length = ps->n_global_syms;
1885 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1886 SYMBOL_DOMAIN (*psym));
1889 printf_filtered ("Global symbol `");
1890 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1891 printf_filtered ("' only found in ");
1892 puts_filtered (ps->filename);
1893 printf_filtered (" psymtab\n");
1897 if (ps->texthigh < ps->textlow)
1899 printf_filtered ("Psymtab ");
1900 puts_filtered (ps->filename);
1901 printf_filtered (" covers bad range ");
1902 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
1903 printf_filtered (" - ");
1904 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
1905 printf_filtered ("\n");
1908 if (ps->texthigh == 0)
1910 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
1912 printf_filtered ("Psymtab ");
1913 puts_filtered (ps->filename);
1914 printf_filtered (" covers ");
1915 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
1916 printf_filtered (" - ");
1917 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
1918 printf_filtered (" but symtab covers only ");
1919 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
1920 printf_filtered (" - ");
1921 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout);
1922 printf_filtered ("\n");
1930 expand_partial_symbol_names (int (*fun) (const char *, void *), void *data)
1932 struct objfile *objfile;
1934 ALL_OBJFILES (objfile)
1937 objfile->sf->qf->expand_symtabs_matching (objfile, NULL, fun,
1943 map_partial_symbol_filenames (symbol_filename_ftype *fun, void *data,
1946 struct objfile *objfile;
1948 ALL_OBJFILES (objfile)
1951 objfile->sf->qf->map_symbol_filenames (objfile, fun, data,