1 /* Partial symbol tables.
3 Copyright (C) 2009-2012 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 /* Helper function for partial_map_symtabs_matching_filename that
129 expands the symtabs and calls the iterator. */
132 partial_map_expand_apply (struct objfile *objfile,
134 const char *full_path,
135 const char *real_path,
136 struct partial_symtab *pst,
137 int (*callback) (struct symtab *, void *),
140 struct symtab *last_made = objfile->symtabs;
142 /* Don't visit already-expanded psymtabs. */
146 /* This may expand more than one symtab, and we want to iterate over
148 psymtab_to_symtab (pst);
150 return iterate_over_some_symtabs (name, full_path, real_path, callback, data,
151 objfile->symtabs, last_made);
154 /* Implementation of the map_symtabs_matching_filename method. */
157 partial_map_symtabs_matching_filename (struct objfile *objfile,
159 const char *full_path,
160 const char *real_path,
161 int (*callback) (struct symtab *,
165 struct partial_symtab *pst;
166 const char *name_basename = lbasename (name);
167 int name_len = strlen (name);
168 int is_abs = IS_ABSOLUTE_PATH (name);
170 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
172 if (FILENAME_CMP (name, pst->filename) == 0
173 || (!is_abs && compare_filenames_for_search (pst->filename,
176 if (partial_map_expand_apply (objfile, name, full_path, real_path,
177 pst, callback, data))
181 /* Before we invoke realpath, which can get expensive when many
182 files are involved, do a quick comparison of the basenames. */
183 if (! basenames_may_differ
184 && FILENAME_CMP (name_basename, lbasename (pst->filename)) != 0)
187 /* If the user gave us an absolute path, try to find the file in
188 this symtab and use its absolute path. */
189 if (full_path != NULL)
191 psymtab_to_fullname (pst);
192 if (pst->fullname != NULL
193 && (FILENAME_CMP (full_path, pst->fullname) == 0
194 || (!is_abs && compare_filenames_for_search (pst->fullname,
197 if (partial_map_expand_apply (objfile, name, full_path, real_path,
198 pst, callback, data))
203 if (real_path != NULL)
206 psymtab_to_fullname (pst);
207 if (pst->fullname != NULL)
209 rp = gdb_realpath (pst->fullname);
210 make_cleanup (xfree, rp);
213 && (FILENAME_CMP (real_path, rp) == 0
214 || (!is_abs && compare_filenames_for_search (real_path,
217 if (partial_map_expand_apply (objfile, name, full_path, real_path,
218 pst, callback, data))
227 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
228 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
230 static struct partial_symtab *
231 find_pc_sect_psymtab_closer (CORE_ADDR pc, struct obj_section *section,
232 struct partial_symtab *pst,
233 struct minimal_symbol *msymbol)
235 struct objfile *objfile = pst->objfile;
236 struct partial_symtab *tpst;
237 struct partial_symtab *best_pst = pst;
238 CORE_ADDR best_addr = pst->textlow;
240 gdb_assert (!pst->psymtabs_addrmap_supported);
242 /* An objfile that has its functions reordered might have
243 many partial symbol tables containing the PC, but
244 we want the partial symbol table that contains the
245 function containing the PC. */
246 if (!(objfile->flags & OBJF_REORDERED) &&
247 section == 0) /* Can't validate section this way. */
253 /* The code range of partial symtabs sometimes overlap, so, in
254 the loop below, we need to check all partial symtabs and
255 find the one that fits better for the given PC address. We
256 select the partial symtab that contains a symbol whose
257 address is closest to the PC address. By closest we mean
258 that find_pc_sect_symbol returns the symbol with address
259 that is closest and still less than the given PC. */
260 for (tpst = pst; tpst != NULL; tpst = tpst->next)
262 if (pc >= tpst->textlow && pc < tpst->texthigh)
264 struct partial_symbol *p;
267 /* NOTE: This assumes that every psymbol has a
268 corresponding msymbol, which is not necessarily
269 true; the debug info might be much richer than the
270 object's symbol table. */
271 p = find_pc_sect_psymbol (tpst, pc, section);
273 && SYMBOL_VALUE_ADDRESS (p)
274 == SYMBOL_VALUE_ADDRESS (msymbol))
277 /* Also accept the textlow value of a psymtab as a
278 "symbol", to provide some support for partial
279 symbol tables with line information but no debug
280 symbols (e.g. those produced by an assembler). */
282 this_addr = SYMBOL_VALUE_ADDRESS (p);
284 this_addr = tpst->textlow;
286 /* Check whether it is closer than our current
287 BEST_ADDR. Since this symbol address is
288 necessarily lower or equal to PC, the symbol closer
289 to PC is the symbol which address is the highest.
290 This way we return the psymtab which contains such
291 best match symbol. This can help in cases where the
292 symbol information/debuginfo is not complete, like
293 for instance on IRIX6 with gcc, where no debug info
294 is emitted for statics. (See also the nodebug.exp
296 if (this_addr > best_addr)
298 best_addr = this_addr;
306 /* Find which partial symtab contains PC and SECTION. Return 0 if
307 none. We return the psymtab that contains a symbol whose address
308 exactly matches PC, or, if we cannot find an exact match, the
309 psymtab that contains a symbol whose address is closest to PC. */
310 static struct partial_symtab *
311 find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
312 struct obj_section *section,
313 struct minimal_symbol *msymbol)
315 struct partial_symtab *pst;
317 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
318 than the later used TEXTLOW/TEXTHIGH one. */
320 if (objfile->psymtabs_addrmap != NULL)
322 pst = addrmap_find (objfile->psymtabs_addrmap, pc);
325 /* FIXME: addrmaps currently do not handle overlayed sections,
326 so fall back to the non-addrmap case if we're debugging
327 overlays and the addrmap returned the wrong section. */
328 if (overlay_debugging && msymbol && section)
330 struct partial_symbol *p;
332 /* NOTE: This assumes that every psymbol has a
333 corresponding msymbol, which is not necessarily
334 true; the debug info might be much richer than the
335 object's symbol table. */
336 p = find_pc_sect_psymbol (pst, pc, section);
338 || SYMBOL_VALUE_ADDRESS (p)
339 != SYMBOL_VALUE_ADDRESS (msymbol))
343 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
344 PSYMTABS_ADDRMAP we used has already the best 1-byte
345 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
346 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
355 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
356 which still have no corresponding full SYMTABs read. But it is not
357 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
360 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
361 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
362 debug info type in single OBJFILE. */
364 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
365 if (!pst->psymtabs_addrmap_supported
366 && pc >= pst->textlow && pc < pst->texthigh)
368 struct partial_symtab *best_pst;
370 best_pst = find_pc_sect_psymtab_closer (pc, section, pst, msymbol);
371 if (best_pst != NULL)
378 static struct symtab *
379 find_pc_sect_symtab_from_partial (struct objfile *objfile,
380 struct minimal_symbol *msymbol,
381 CORE_ADDR pc, struct obj_section *section,
384 struct partial_symtab *ps = find_pc_sect_psymtab (objfile, pc, section,
388 if (warn_if_readin && ps->readin)
389 /* Might want to error() here (in case symtab is corrupt and
390 will cause a core dump), but maybe we can successfully
391 continue, so let's not. */
393 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
394 paddress (get_objfile_arch (ps->objfile), pc));
395 return PSYMTAB_TO_SYMTAB (ps);
400 /* Find which partial symbol within a psymtab matches PC and SECTION.
403 static struct partial_symbol *
404 find_pc_sect_psymbol (struct partial_symtab *psymtab, CORE_ADDR pc,
405 struct obj_section *section)
407 struct partial_symbol *best = NULL, *p, **pp;
410 gdb_assert (psymtab != NULL);
412 /* Cope with programs that start at address 0. */
413 best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0;
415 /* Search the global symbols as well as the static symbols, so that
416 find_pc_partial_function doesn't use a minimal symbol and thus
417 cache a bad endaddr. */
418 for (pp = psymtab->objfile->global_psymbols.list + psymtab->globals_offset;
419 (pp - (psymtab->objfile->global_psymbols.list + psymtab->globals_offset)
420 < psymtab->n_global_syms);
424 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
425 && SYMBOL_CLASS (p) == LOC_BLOCK
426 && pc >= SYMBOL_VALUE_ADDRESS (p)
427 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
428 || (psymtab->textlow == 0
429 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
431 if (section) /* Match on a specific section. */
433 fixup_psymbol_section (p, psymtab->objfile);
434 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
437 best_pc = SYMBOL_VALUE_ADDRESS (p);
442 for (pp = psymtab->objfile->static_psymbols.list + psymtab->statics_offset;
443 (pp - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset)
444 < psymtab->n_static_syms);
448 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
449 && SYMBOL_CLASS (p) == LOC_BLOCK
450 && pc >= SYMBOL_VALUE_ADDRESS (p)
451 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
452 || (psymtab->textlow == 0
453 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
455 if (section) /* Match on a specific section. */
457 fixup_psymbol_section (p, psymtab->objfile);
458 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
461 best_pc = SYMBOL_VALUE_ADDRESS (p);
469 static struct partial_symbol *
470 fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
477 if (SYMBOL_OBJ_SECTION (psym))
480 gdb_assert (objfile);
482 switch (SYMBOL_CLASS (psym))
487 addr = SYMBOL_VALUE_ADDRESS (psym);
490 /* Nothing else will be listed in the minsyms -- no use looking
495 fixup_section (&psym->ginfo, addr, objfile);
500 static struct symtab *
501 lookup_symbol_aux_psymtabs (struct objfile *objfile,
502 int block_index, const char *name,
503 const domain_enum domain)
505 struct partial_symtab *ps;
506 const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
508 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
510 if (!ps->readin && lookup_partial_symbol (ps, name, psymtab_index, domain))
512 struct symbol *sym = NULL;
513 struct symtab *stab = PSYMTAB_TO_SYMTAB (ps);
515 /* Some caution must be observed with overloaded functions
516 and methods, since the psymtab will not contain any overload
517 information (but NAME might contain it). */
520 struct blockvector *bv = BLOCKVECTOR (stab);
521 struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
523 sym = lookup_block_symbol (block, name, domain);
526 if (sym && strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0)
529 /* Keep looking through other psymtabs. */
536 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
537 the global block of PST if GLOBAL, and otherwise the static block.
538 MATCH is the comparison operation that returns true iff MATCH (s,
539 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
540 non-null, the symbols in the block are assumed to be ordered
541 according to it (allowing binary search). It must be compatible
542 with MATCH. Returns the symbol, if found, and otherwise NULL. */
544 static struct partial_symbol *
545 match_partial_symbol (struct partial_symtab *pst, int global,
546 const char *name, domain_enum domain,
547 symbol_compare_ftype *match,
548 symbol_compare_ftype *ordered_compare)
550 struct partial_symbol **start, **psym;
551 struct partial_symbol **top, **real_top, **bottom, **center;
552 int length = (global ? pst->n_global_syms : pst->n_static_syms);
553 int do_linear_search = 1;
558 pst->objfile->global_psymbols.list + pst->globals_offset :
559 pst->objfile->static_psymbols.list + pst->statics_offset);
561 if (global && ordered_compare) /* Can use a binary search. */
563 do_linear_search = 0;
565 /* Binary search. This search is guaranteed to end with center
566 pointing at the earliest partial symbol whose name might be
567 correct. At that point *all* partial symbols with an
568 appropriate name will be checked against the correct
572 top = start + length - 1;
576 center = bottom + (top - bottom) / 2;
577 gdb_assert (center < top);
578 if (!do_linear_search
579 && (SYMBOL_LANGUAGE (*center) == language_java))
580 do_linear_search = 1;
581 if (ordered_compare (SYMBOL_SEARCH_NAME (*center), name) >= 0)
586 gdb_assert (top == bottom);
588 while (top <= real_top
589 && match (SYMBOL_SEARCH_NAME (*top), name) == 0)
591 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
592 SYMBOL_DOMAIN (*top), domain))
598 /* Can't use a binary search or else we found during the binary search that
599 we should also do a linear search. */
601 if (do_linear_search)
603 for (psym = start; psym < start + length; psym++)
605 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
606 SYMBOL_DOMAIN (*psym), domain)
607 && match (SYMBOL_SEARCH_NAME (*psym), name) == 0)
616 pre_expand_symtabs_matching_psymtabs (struct objfile *objfile,
617 enum block_enum block_kind,
624 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
625 not contain any method/function instance information (since this would
626 force reading type information while reading psymtabs). Therefore,
627 if NAME contains overload information, it must be stripped before searching
630 The caller is responsible for freeing the return result. */
633 psymtab_search_name (const char *name)
635 switch (current_language->la_language)
640 if (strchr (name, '('))
642 char *ret = cp_remove_params (name);
654 return xstrdup (name);
657 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
658 Check the global symbols if GLOBAL, the static symbols if not. */
660 static struct partial_symbol *
661 lookup_partial_symbol (struct partial_symtab *pst, const char *name,
662 int global, domain_enum domain)
664 struct partial_symbol **start, **psym;
665 struct partial_symbol **top, **real_top, **bottom, **center;
666 int length = (global ? pst->n_global_syms : pst->n_static_syms);
667 int do_linear_search = 1;
669 struct cleanup *cleanup;
676 search_name = psymtab_search_name (name);
677 cleanup = make_cleanup (xfree, search_name);
679 pst->objfile->global_psymbols.list + pst->globals_offset :
680 pst->objfile->static_psymbols.list + pst->statics_offset);
682 if (global) /* This means we can use a binary search. */
684 do_linear_search = 0;
686 /* Binary search. This search is guaranteed to end with center
687 pointing at the earliest partial symbol whose name might be
688 correct. At that point *all* partial symbols with an
689 appropriate name will be checked against the correct
693 top = start + length - 1;
697 center = bottom + (top - bottom) / 2;
699 internal_error (__FILE__, __LINE__,
700 _("failed internal consistency check"));
701 if (!do_linear_search
702 && SYMBOL_LANGUAGE (*center) == language_java)
704 do_linear_search = 1;
706 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center),
716 if (!(top == bottom))
717 internal_error (__FILE__, __LINE__,
718 _("failed internal consistency check"));
720 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
721 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
722 while (top >= start && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
725 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
728 while (top <= real_top && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
730 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
731 SYMBOL_DOMAIN (*top), domain))
733 do_cleanups (cleanup);
740 /* Can't use a binary search or else we found during the binary search that
741 we should also do a linear search. */
743 if (do_linear_search)
745 for (psym = start; psym < start + length; psym++)
747 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
748 SYMBOL_DOMAIN (*psym), domain)
749 && SYMBOL_MATCHES_SEARCH_NAME (*psym, search_name))
751 do_cleanups (cleanup);
757 do_cleanups (cleanup);
761 /* Get the symbol table that corresponds to a partial_symtab.
762 This is fast after the first time you do it. In fact, there
763 is an even faster macro PSYMTAB_TO_SYMTAB that does the fast
766 static struct symtab *
767 psymtab_to_symtab (struct partial_symtab *pst)
769 /* If it's been looked up before, return it. */
773 /* If it has not yet been read in, read it. */
776 struct cleanup *back_to = increment_reading_symtab ();
778 (*pst->read_symtab) (pst);
779 do_cleanups (back_to);
786 relocate_psymtabs (struct objfile *objfile,
787 struct section_offsets *new_offsets,
788 struct section_offsets *delta)
790 struct partial_symbol **psym;
791 struct partial_symtab *p;
793 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
795 p->textlow += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
796 p->texthigh += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
799 for (psym = objfile->global_psymbols.list;
800 psym < objfile->global_psymbols.next;
803 fixup_psymbol_section (*psym, objfile);
804 if (SYMBOL_SECTION (*psym) >= 0)
805 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
806 SYMBOL_SECTION (*psym));
808 for (psym = objfile->static_psymbols.list;
809 psym < objfile->static_psymbols.next;
812 fixup_psymbol_section (*psym, objfile);
813 if (SYMBOL_SECTION (*psym) >= 0)
814 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
815 SYMBOL_SECTION (*psym));
819 static struct symtab *
820 find_last_source_symtab_from_partial (struct objfile *ofp)
822 struct partial_symtab *ps;
823 struct partial_symtab *cs_pst = 0;
825 ALL_OBJFILE_PSYMTABS_REQUIRED (ofp, ps)
827 const char *name = ps->filename;
828 int len = strlen (name);
830 if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0
831 || strcmp (name, "<<C++-namespaces>>") == 0)))
839 internal_error (__FILE__, __LINE__,
840 _("select_source_symtab: "
841 "readin pst found and no symtabs."));
844 return PSYMTAB_TO_SYMTAB (cs_pst);
850 forget_cached_source_info_partial (struct objfile *objfile)
852 struct partial_symtab *pst;
854 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
856 if (pst->fullname != NULL)
858 xfree (pst->fullname);
859 pst->fullname = NULL;
865 print_partial_symbols (struct gdbarch *gdbarch,
866 struct partial_symbol **p, int count, char *what,
867 struct ui_file *outfile)
869 fprintf_filtered (outfile, " %s partial symbols:\n", what);
872 fprintf_filtered (outfile, " `%s'", SYMBOL_LINKAGE_NAME (*p));
873 if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
875 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
877 fputs_filtered (", ", outfile);
878 switch (SYMBOL_DOMAIN (*p))
881 fputs_filtered ("undefined domain, ", outfile);
884 /* This is the usual thing -- don't print it. */
887 fputs_filtered ("struct domain, ", outfile);
890 fputs_filtered ("label domain, ", outfile);
893 fputs_filtered ("<invalid domain>, ", outfile);
896 switch (SYMBOL_CLASS (*p))
899 fputs_filtered ("undefined", outfile);
902 fputs_filtered ("constant int", outfile);
905 fputs_filtered ("static", outfile);
908 fputs_filtered ("register", outfile);
911 fputs_filtered ("pass by value", outfile);
914 fputs_filtered ("pass by reference", outfile);
916 case LOC_REGPARM_ADDR:
917 fputs_filtered ("register address parameter", outfile);
920 fputs_filtered ("stack parameter", outfile);
923 fputs_filtered ("type", outfile);
926 fputs_filtered ("label", outfile);
929 fputs_filtered ("function", outfile);
931 case LOC_CONST_BYTES:
932 fputs_filtered ("constant bytes", outfile);
935 fputs_filtered ("unresolved", outfile);
937 case LOC_OPTIMIZED_OUT:
938 fputs_filtered ("optimized out", outfile);
941 fputs_filtered ("computed at runtime", outfile);
944 fputs_filtered ("<invalid location>", outfile);
947 fputs_filtered (", ", outfile);
948 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (*p)), outfile);
949 fprintf_filtered (outfile, "\n");
955 dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
956 struct ui_file *outfile)
958 struct gdbarch *gdbarch = get_objfile_arch (objfile);
961 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
963 fprintf_filtered (outfile, "(object ");
964 gdb_print_host_address (psymtab, outfile);
965 fprintf_filtered (outfile, ")\n\n");
966 fprintf_unfiltered (outfile, " Read from object file %s (",
968 gdb_print_host_address (objfile, outfile);
969 fprintf_unfiltered (outfile, ")\n");
973 fprintf_filtered (outfile,
974 " Full symtab was read (at ");
975 gdb_print_host_address (psymtab->symtab, outfile);
976 fprintf_filtered (outfile, " by function at ");
977 gdb_print_host_address (psymtab->read_symtab, outfile);
978 fprintf_filtered (outfile, ")\n");
981 fprintf_filtered (outfile, " Relocate symbols by ");
982 for (i = 0; i < psymtab->objfile->num_sections; ++i)
985 fprintf_filtered (outfile, ", ");
987 fputs_filtered (paddress (gdbarch,
988 ANOFFSET (psymtab->section_offsets, i)),
991 fprintf_filtered (outfile, "\n");
993 fprintf_filtered (outfile, " Symbols cover text addresses ");
994 fputs_filtered (paddress (gdbarch, psymtab->textlow), outfile);
995 fprintf_filtered (outfile, "-");
996 fputs_filtered (paddress (gdbarch, psymtab->texthigh), outfile);
997 fprintf_filtered (outfile, "\n");
998 fprintf_filtered (outfile, " Address map supported - %s.\n",
999 psymtab->psymtabs_addrmap_supported ? "yes" : "no");
1000 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
1001 psymtab->number_of_dependencies);
1002 for (i = 0; i < psymtab->number_of_dependencies; i++)
1004 fprintf_filtered (outfile, " %d ", i);
1005 gdb_print_host_address (psymtab->dependencies[i], outfile);
1006 fprintf_filtered (outfile, " %s\n",
1007 psymtab->dependencies[i]->filename);
1009 if (psymtab->n_global_syms > 0)
1011 print_partial_symbols (gdbarch,
1012 objfile->global_psymbols.list
1013 + psymtab->globals_offset,
1014 psymtab->n_global_syms, "Global", outfile);
1016 if (psymtab->n_static_syms > 0)
1018 print_partial_symbols (gdbarch,
1019 objfile->static_psymbols.list
1020 + psymtab->statics_offset,
1021 psymtab->n_static_syms, "Static", outfile);
1023 fprintf_filtered (outfile, "\n");
1027 print_psymtab_stats_for_objfile (struct objfile *objfile)
1030 struct partial_symtab *ps;
1033 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1035 if (ps->readin == 0)
1038 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i);
1042 dump_psymtabs_for_objfile (struct objfile *objfile)
1044 struct partial_symtab *psymtab;
1046 if (objfile->psymtabs)
1048 printf_filtered ("Psymtabs:\n");
1049 for (psymtab = objfile->psymtabs;
1051 psymtab = psymtab->next)
1053 printf_filtered ("%s at ",
1055 gdb_print_host_address (psymtab, gdb_stdout);
1056 printf_filtered (", ");
1057 if (psymtab->objfile != objfile)
1059 printf_filtered ("NOT ON CHAIN! ");
1063 printf_filtered ("\n\n");
1067 /* Look through the partial symtabs for all symbols which begin
1068 by matching FUNC_NAME. Make sure we read that symbol table in. */
1071 read_symtabs_for_function (struct objfile *objfile, const char *func_name)
1073 struct partial_symtab *ps;
1075 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1080 if ((lookup_partial_symbol (ps, func_name, 1, VAR_DOMAIN)
1082 || (lookup_partial_symbol (ps, func_name, 0, VAR_DOMAIN)
1084 psymtab_to_symtab (ps);
1089 expand_partial_symbol_tables (struct objfile *objfile)
1091 struct partial_symtab *psymtab;
1093 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
1095 psymtab_to_symtab (psymtab);
1100 read_psymtabs_with_filename (struct objfile *objfile, const char *filename)
1102 struct partial_symtab *p;
1104 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
1106 if (filename_cmp (filename, p->filename) == 0)
1107 PSYMTAB_TO_SYMTAB (p);
1112 map_symbol_filenames_psymtab (struct objfile *objfile,
1113 symbol_filename_ftype *fun, void *data,
1116 struct partial_symtab *ps;
1118 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1120 const char *fullname;
1127 fullname = psymtab_to_fullname (ps);
1130 (*fun) (ps->filename, fullname, data);
1134 int find_and_open_source (const char *filename,
1135 const char *dirname,
1138 /* Finds the fullname that a partial_symtab represents.
1140 If this functions finds the fullname, it will save it in ps->fullname
1141 and it will also return the value.
1143 If this function fails to find the file that this partial_symtab represents,
1144 NULL will be returned and ps->fullname will be set to NULL. */
1147 psymtab_to_fullname (struct partial_symtab *ps)
1154 /* Use cached copy if we have it.
1155 We rely on forget_cached_source_info being called appropriately
1156 to handle cases like the file being moved. */
1158 return ps->fullname;
1160 r = find_and_open_source (ps->filename, ps->dirname, &ps->fullname);
1165 return ps->fullname;
1172 find_symbol_file_from_partial (struct objfile *objfile, const char *name)
1174 struct partial_symtab *pst;
1176 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
1178 if (lookup_partial_symbol (pst, name, 1, VAR_DOMAIN))
1179 return pst->filename;
1184 /* For all symbols, s, in BLOCK that are in NAMESPACE and match NAME
1185 according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
1186 BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK
1187 ever returns non-zero, and otherwise returns 0. */
1190 map_block (const char *name, domain_enum namespace, struct objfile *objfile,
1191 struct block *block,
1192 int (*callback) (struct block *, struct symbol *, void *),
1193 void *data, symbol_compare_ftype *match)
1195 struct dict_iterator iter;
1198 for (sym = dict_iter_match_first (BLOCK_DICT (block), name, match, &iter);
1199 sym != NULL; sym = dict_iter_match_next (name, match, &iter))
1201 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
1202 SYMBOL_DOMAIN (sym), namespace))
1204 if (callback (block, sym, data))
1212 /* Psymtab version of map_matching_symbols. See its definition in
1213 the definition of quick_symbol_functions in symfile.h. */
1216 map_matching_symbols_psymtab (const char *name, domain_enum namespace,
1217 struct objfile *objfile, int global,
1218 int (*callback) (struct block *,
1219 struct symbol *, void *),
1221 symbol_compare_ftype *match,
1222 symbol_compare_ftype *ordered_compare)
1224 const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
1225 struct partial_symtab *ps;
1227 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1231 || match_partial_symbol (ps, global, name, namespace, match,
1234 struct symtab *s = PSYMTAB_TO_SYMTAB (ps);
1235 struct block *block;
1237 if (s == NULL || !s->primary)
1239 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), block_kind);
1240 if (map_block (name, namespace, objfile, block,
1241 callback, data, match))
1243 if (callback (block, NULL, data))
1250 expand_symtabs_matching_via_partial
1251 (struct objfile *objfile,
1252 int (*file_matcher) (const char *, void *),
1253 int (*name_matcher) (const struct language_defn *, const char *, void *),
1254 enum search_domain kind,
1257 struct partial_symtab *ps;
1259 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1261 struct partial_symbol **psym;
1262 struct partial_symbol **bound, **gbound, **sbound;
1268 if (file_matcher && ! (*file_matcher) (ps->filename, data))
1271 gbound = objfile->global_psymbols.list
1272 + ps->globals_offset + ps->n_global_syms;
1273 sbound = objfile->static_psymbols.list
1274 + ps->statics_offset + ps->n_static_syms;
1277 /* Go through all of the symbols stored in a partial
1278 symtab in one loop. */
1279 psym = objfile->global_psymbols.list + ps->globals_offset;
1284 if (bound == gbound && ps->n_static_syms != 0)
1286 psym = objfile->static_psymbols.list + ps->statics_offset;
1297 if ((kind == ALL_DOMAIN
1298 || (kind == VARIABLES_DOMAIN
1299 && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
1300 && SYMBOL_CLASS (*psym) != LOC_BLOCK)
1301 || (kind == FUNCTIONS_DOMAIN
1302 && SYMBOL_CLASS (*psym) == LOC_BLOCK)
1303 || (kind == TYPES_DOMAIN
1304 && SYMBOL_CLASS (*psym) == LOC_TYPEDEF))
1305 && (*name_matcher) (current_language,
1306 SYMBOL_SEARCH_NAME (*psym), data))
1308 PSYMTAB_TO_SYMTAB (ps);
1318 objfile_has_psyms (struct objfile *objfile)
1320 return objfile->psymtabs != NULL;
1323 const struct quick_symbol_functions psym_functions =
1326 find_last_source_symtab_from_partial,
1327 forget_cached_source_info_partial,
1328 partial_map_symtabs_matching_filename,
1329 lookup_symbol_aux_psymtabs,
1330 pre_expand_symtabs_matching_psymtabs,
1331 print_psymtab_stats_for_objfile,
1332 dump_psymtabs_for_objfile,
1334 read_symtabs_for_function,
1335 expand_partial_symbol_tables,
1336 read_psymtabs_with_filename,
1337 find_symbol_file_from_partial,
1338 map_matching_symbols_psymtab,
1339 expand_symtabs_matching_via_partial,
1340 find_pc_sect_symtab_from_partial,
1341 map_symbol_filenames_psymtab
1346 /* This compares two partial symbols by names, using strcmp_iw_ordered
1347 for the comparison. */
1350 compare_psymbols (const void *s1p, const void *s2p)
1352 struct partial_symbol *const *s1 = s1p;
1353 struct partial_symbol *const *s2 = s2p;
1355 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1),
1356 SYMBOL_SEARCH_NAME (*s2));
1360 sort_pst_symbols (struct partial_symtab *pst)
1362 /* Sort the global list; don't sort the static list. */
1364 qsort (pst->objfile->global_psymbols.list + pst->globals_offset,
1365 pst->n_global_syms, sizeof (struct partial_symbol *),
1369 /* Allocate and partially fill a partial symtab. It will be
1370 completely filled at the end of the symbol list.
1372 FILENAME is the name of the symbol-file we are reading from. */
1374 struct partial_symtab *
1375 start_psymtab_common (struct objfile *objfile,
1376 struct section_offsets *section_offsets,
1377 const char *filename,
1378 CORE_ADDR textlow, struct partial_symbol **global_syms,
1379 struct partial_symbol **static_syms)
1381 struct partial_symtab *psymtab;
1383 psymtab = allocate_psymtab (filename, objfile);
1384 psymtab->section_offsets = section_offsets;
1385 psymtab->textlow = textlow;
1386 psymtab->texthigh = psymtab->textlow; /* default */
1387 psymtab->globals_offset = global_syms - objfile->global_psymbols.list;
1388 psymtab->statics_offset = static_syms - objfile->static_psymbols.list;
1392 /* Calculate a hash code for the given partial symbol. The hash is
1393 calculated using the symbol's value, language, domain, class
1394 and name. These are the values which are set by
1395 add_psymbol_to_bcache. */
1397 static unsigned long
1398 psymbol_hash (const void *addr, int length)
1400 unsigned long h = 0;
1401 struct partial_symbol *psymbol = (struct partial_symbol *) addr;
1402 unsigned int lang = psymbol->ginfo.language;
1403 unsigned int domain = PSYMBOL_DOMAIN (psymbol);
1404 unsigned int class = PSYMBOL_CLASS (psymbol);
1406 h = hash_continue (&psymbol->ginfo.value, sizeof (psymbol->ginfo.value), h);
1407 h = hash_continue (&lang, sizeof (unsigned int), h);
1408 h = hash_continue (&domain, sizeof (unsigned int), h);
1409 h = hash_continue (&class, sizeof (unsigned int), h);
1410 h = hash_continue (psymbol->ginfo.name, strlen (psymbol->ginfo.name), h);
1415 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1416 For the comparison this function uses a symbols value,
1417 language, domain, class and name. */
1420 psymbol_compare (const void *addr1, const void *addr2, int length)
1422 struct partial_symbol *sym1 = (struct partial_symbol *) addr1;
1423 struct partial_symbol *sym2 = (struct partial_symbol *) addr2;
1425 return (memcmp (&sym1->ginfo.value, &sym1->ginfo.value,
1426 sizeof (sym1->ginfo.value)) == 0
1427 && sym1->ginfo.language == sym2->ginfo.language
1428 && PSYMBOL_DOMAIN (sym1) == PSYMBOL_DOMAIN (sym2)
1429 && PSYMBOL_CLASS (sym1) == PSYMBOL_CLASS (sym2)
1430 && sym1->ginfo.name == sym2->ginfo.name);
1433 /* Initialize a partial symbol bcache. */
1435 struct psymbol_bcache *
1436 psymbol_bcache_init (void)
1438 struct psymbol_bcache *bcache = XCALLOC (1, struct psymbol_bcache);
1439 bcache->bcache = bcache_xmalloc (psymbol_hash, psymbol_compare);
1443 /* Free a partial symbol bcache. */
1445 psymbol_bcache_free (struct psymbol_bcache *bcache)
1450 bcache_xfree (bcache->bcache);
1454 /* Return the internal bcache of the psymbol_bcache BCACHE. */
1457 psymbol_bcache_get_bcache (struct psymbol_bcache *bcache)
1459 return bcache->bcache;
1462 /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1463 symbol before, add a copy to BCACHE. In either case, return a pointer
1464 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1465 1 in case of new entry or 0 if returning an old entry. */
1467 static const struct partial_symbol *
1468 psymbol_bcache_full (struct partial_symbol *sym,
1469 struct psymbol_bcache *bcache,
1472 return bcache_full (sym,
1473 sizeof (struct partial_symbol),
1478 /* Helper function, initialises partial symbol structure and stashes
1479 it into objfile's bcache. Note that our caching mechanism will
1480 use all fields of struct partial_symbol to determine hash value of the
1481 structure. In other words, having two symbols with the same name but
1482 different domain (or address) is possible and correct. */
1484 static const struct partial_symbol *
1485 add_psymbol_to_bcache (const char *name, int namelength, int copy_name,
1487 enum address_class class,
1488 long val, /* Value as a long */
1489 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1490 enum language language, struct objfile *objfile,
1493 struct partial_symbol psymbol;
1495 /* We must ensure that the entire 'value' field has been zeroed
1496 before assigning to it, because an assignment may not write the
1498 memset (&psymbol.ginfo.value, 0, sizeof (psymbol.ginfo.value));
1500 /* val and coreaddr are mutually exclusive, one of them *will* be zero. */
1503 SYMBOL_VALUE (&psymbol) = val;
1507 SYMBOL_VALUE_ADDRESS (&psymbol) = coreaddr;
1509 SYMBOL_SECTION (&psymbol) = 0;
1510 SYMBOL_OBJ_SECTION (&psymbol) = NULL;
1511 SYMBOL_SET_LANGUAGE (&psymbol, language);
1512 PSYMBOL_DOMAIN (&psymbol) = domain;
1513 PSYMBOL_CLASS (&psymbol) = class;
1515 SYMBOL_SET_NAMES (&psymbol, name, namelength, copy_name, objfile);
1517 /* Stash the partial symbol away in the cache. */
1518 return psymbol_bcache_full (&psymbol,
1519 objfile->psymbol_cache,
1523 /* Increase the space allocated for LISTP, which is probably
1524 global_psymbols or static_psymbols. This space will eventually
1525 be freed in free_objfile(). */
1528 extend_psymbol_list (struct psymbol_allocation_list *listp,
1529 struct objfile *objfile)
1533 if (listp->size == 0)
1536 listp->list = (struct partial_symbol **)
1537 xmalloc (new_size * sizeof (struct partial_symbol *));
1541 new_size = listp->size * 2;
1542 listp->list = (struct partial_symbol **)
1543 xrealloc ((char *) listp->list,
1544 new_size * sizeof (struct partial_symbol *));
1546 /* Next assumes we only went one over. Should be good if
1547 program works correctly. */
1548 listp->next = listp->list + listp->size;
1549 listp->size = new_size;
1552 /* Helper function, adds partial symbol to the given partial symbol
1556 append_psymbol_to_list (struct psymbol_allocation_list *list,
1557 const struct partial_symbol *psym,
1558 struct objfile *objfile)
1560 if (list->next >= list->list + list->size)
1561 extend_psymbol_list (list, objfile);
1562 *list->next++ = (struct partial_symbol *) psym;
1563 OBJSTAT (objfile, n_psyms++);
1566 /* Add a symbol with a long value to a psymtab.
1567 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1568 Return the partial symbol that has been added. */
1570 /* NOTE: carlton/2003-09-11: The reason why we return the partial
1571 symbol is so that callers can get access to the symbol's demangled
1572 name, which they don't have any cheap way to determine otherwise.
1573 (Currenly, dwarf2read.c is the only file who uses that information,
1574 though it's possible that other readers might in the future.)
1575 Elena wasn't thrilled about that, and I don't blame her, but we
1576 couldn't come up with a better way to get that information. If
1577 it's needed in other situations, we could consider breaking up
1578 SYMBOL_SET_NAMES to provide access to the demangled name lookup
1581 const struct partial_symbol *
1582 add_psymbol_to_list (const char *name, int namelength, int copy_name,
1584 enum address_class class,
1585 struct psymbol_allocation_list *list,
1586 long val, /* Value as a long */
1587 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1588 enum language language, struct objfile *objfile)
1590 const struct partial_symbol *psym;
1594 /* Stash the partial symbol away in the cache. */
1595 psym = add_psymbol_to_bcache (name, namelength, copy_name, domain, class,
1596 val, coreaddr, language, objfile, &added);
1598 /* Do not duplicate global partial symbols. */
1599 if (list == &objfile->global_psymbols
1603 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1604 append_psymbol_to_list (list, psym, objfile);
1608 /* Initialize storage for partial symbols. */
1611 init_psymbol_list (struct objfile *objfile, int total_symbols)
1613 /* Free any previously allocated psymbol lists. */
1615 if (objfile->global_psymbols.list)
1617 xfree (objfile->global_psymbols.list);
1619 if (objfile->static_psymbols.list)
1621 xfree (objfile->static_psymbols.list);
1624 /* Current best guess is that approximately a twentieth
1625 of the total symbols (in a debugging file) are global or static
1626 oriented symbols. */
1628 objfile->global_psymbols.size = total_symbols / 10;
1629 objfile->static_psymbols.size = total_symbols / 10;
1631 if (objfile->global_psymbols.size > 0)
1633 objfile->global_psymbols.next =
1634 objfile->global_psymbols.list = (struct partial_symbol **)
1635 xmalloc ((objfile->global_psymbols.size
1636 * sizeof (struct partial_symbol *)));
1638 if (objfile->static_psymbols.size > 0)
1640 objfile->static_psymbols.next =
1641 objfile->static_psymbols.list = (struct partial_symbol **)
1642 xmalloc ((objfile->static_psymbols.size
1643 * sizeof (struct partial_symbol *)));
1647 struct partial_symtab *
1648 allocate_psymtab (const char *filename, struct objfile *objfile)
1650 struct partial_symtab *psymtab;
1652 if (objfile->free_psymtabs)
1654 psymtab = objfile->free_psymtabs;
1655 objfile->free_psymtabs = psymtab->next;
1658 psymtab = (struct partial_symtab *)
1659 obstack_alloc (&objfile->objfile_obstack,
1660 sizeof (struct partial_symtab));
1662 memset (psymtab, 0, sizeof (struct partial_symtab));
1663 psymtab->filename = obsavestring (filename, strlen (filename),
1664 &objfile->objfile_obstack);
1665 psymtab->symtab = NULL;
1667 /* Prepend it to the psymtab list for the objfile it belongs to.
1668 Psymtabs are searched in most recent inserted -> least recent
1671 psymtab->objfile = objfile;
1672 psymtab->next = objfile->psymtabs;
1673 objfile->psymtabs = psymtab;
1679 discard_psymtab (struct partial_symtab *pst)
1681 struct partial_symtab **prev_pst;
1684 Empty psymtabs happen as a result of header files which don't
1685 have any symbols in them. There can be a lot of them. But this
1686 check is wrong, in that a psymtab with N_SLINE entries but
1687 nothing else is not empty, but we don't realize that. Fixing
1688 that without slowing things down might be tricky. */
1690 /* First, snip it out of the psymtab chain. */
1692 prev_pst = &(pst->objfile->psymtabs);
1693 while ((*prev_pst) != pst)
1694 prev_pst = &((*prev_pst)->next);
1695 (*prev_pst) = pst->next;
1697 /* Next, put it on a free list for recycling. */
1699 pst->next = pst->objfile->free_psymtabs;
1700 pst->objfile->free_psymtabs = pst;
1706 maintenance_print_psymbols (char *args, int from_tty)
1709 struct ui_file *outfile;
1710 struct cleanup *cleanups;
1711 char *symname = NULL;
1712 char *filename = DEV_TTY;
1713 struct objfile *objfile;
1714 struct partial_symtab *ps;
1721 print-psymbols takes an output file name and optional symbol file name"));
1723 argv = gdb_buildargv (args);
1724 cleanups = make_cleanup_freeargv (argv);
1726 if (argv[0] != NULL)
1729 /* If a second arg is supplied, it is a source file name to match on. */
1730 if (argv[1] != NULL)
1736 filename = tilde_expand (filename);
1737 make_cleanup (xfree, filename);
1739 outfile = gdb_fopen (filename, FOPEN_WT);
1741 perror_with_name (filename);
1742 make_cleanup_ui_file_delete (outfile);
1745 ALL_PSYMTABS (objfile, ps)
1746 if (symname == NULL || filename_cmp (symname, ps->filename) == 0)
1747 dump_psymtab (objfile, ps, outfile);
1749 do_cleanups (cleanups);
1752 /* List all the partial symbol tables whose names match REGEXP (optional). */
1754 maintenance_info_psymtabs (char *regexp, int from_tty)
1756 struct program_space *pspace;
1757 struct objfile *objfile;
1762 ALL_PSPACES (pspace)
1763 ALL_PSPACE_OBJFILES (pspace, objfile)
1765 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1766 struct partial_symtab *psymtab;
1768 /* We don't want to print anything for this objfile until we
1769 actually find a symtab whose name matches. */
1770 int printed_objfile_start = 0;
1772 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
1777 || re_exec (psymtab->filename))
1779 if (! printed_objfile_start)
1781 printf_filtered ("{ objfile %s ", objfile->name);
1783 printf_filtered ("((struct objfile *) %s)\n",
1784 host_address_to_string (objfile));
1785 printed_objfile_start = 1;
1788 printf_filtered (" { psymtab %s ", psymtab->filename);
1790 printf_filtered ("((struct partial_symtab *) %s)\n",
1791 host_address_to_string (psymtab));
1793 printf_filtered (" readin %s\n",
1794 psymtab->readin ? "yes" : "no");
1795 printf_filtered (" fullname %s\n",
1797 ? psymtab->fullname : "(null)");
1798 printf_filtered (" text addresses ");
1799 fputs_filtered (paddress (gdbarch, psymtab->textlow),
1801 printf_filtered (" -- ");
1802 fputs_filtered (paddress (gdbarch, psymtab->texthigh),
1804 printf_filtered ("\n");
1805 printf_filtered (" psymtabs_addrmap_supported %s\n",
1806 (psymtab->psymtabs_addrmap_supported
1808 printf_filtered (" globals ");
1809 if (psymtab->n_global_syms)
1811 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1812 host_address_to_string (psymtab->objfile->global_psymbols.list
1813 + psymtab->globals_offset),
1814 psymtab->n_global_syms);
1817 printf_filtered ("(none)\n");
1818 printf_filtered (" statics ");
1819 if (psymtab->n_static_syms)
1821 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1822 host_address_to_string (psymtab->objfile->static_psymbols.list
1823 + psymtab->statics_offset),
1824 psymtab->n_static_syms);
1827 printf_filtered ("(none)\n");
1828 printf_filtered (" dependencies ");
1829 if (psymtab->number_of_dependencies)
1833 printf_filtered ("{\n");
1834 for (i = 0; i < psymtab->number_of_dependencies; i++)
1836 struct partial_symtab *dep = psymtab->dependencies[i];
1838 /* Note the string concatenation there --- no comma. */
1839 printf_filtered (" psymtab %s "
1840 "((struct partial_symtab *) %s)\n",
1842 host_address_to_string (dep));
1844 printf_filtered (" }\n");
1847 printf_filtered ("(none)\n");
1848 printf_filtered (" }\n");
1852 if (printed_objfile_start)
1853 printf_filtered ("}\n");
1857 /* Check consistency of psymtabs and symtabs. */
1860 maintenance_check_symtabs (char *ignore, int from_tty)
1863 struct partial_symbol **psym;
1864 struct symtab *s = NULL;
1865 struct partial_symtab *ps;
1866 struct blockvector *bv;
1867 struct objfile *objfile;
1871 ALL_PSYMTABS (objfile, ps)
1873 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1875 s = PSYMTAB_TO_SYMTAB (ps);
1878 bv = BLOCKVECTOR (s);
1879 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1880 psym = ps->objfile->static_psymbols.list + ps->statics_offset;
1881 length = ps->n_static_syms;
1884 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1885 SYMBOL_DOMAIN (*psym));
1888 printf_filtered ("Static symbol `");
1889 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1890 printf_filtered ("' only found in ");
1891 puts_filtered (ps->filename);
1892 printf_filtered (" psymtab\n");
1896 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1897 psym = ps->objfile->global_psymbols.list + ps->globals_offset;
1898 length = ps->n_global_syms;
1901 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1902 SYMBOL_DOMAIN (*psym));
1905 printf_filtered ("Global symbol `");
1906 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1907 printf_filtered ("' only found in ");
1908 puts_filtered (ps->filename);
1909 printf_filtered (" psymtab\n");
1913 if (ps->texthigh < ps->textlow)
1915 printf_filtered ("Psymtab ");
1916 puts_filtered (ps->filename);
1917 printf_filtered (" covers bad range ");
1918 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
1919 printf_filtered (" - ");
1920 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
1921 printf_filtered ("\n");
1924 if (ps->texthigh == 0)
1926 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
1928 printf_filtered ("Psymtab ");
1929 puts_filtered (ps->filename);
1930 printf_filtered (" covers ");
1931 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
1932 printf_filtered (" - ");
1933 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
1934 printf_filtered (" but symtab covers only ");
1935 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
1936 printf_filtered (" - ");
1937 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout);
1938 printf_filtered ("\n");
1946 expand_partial_symbol_names (int (*fun) (const struct language_defn *,
1947 const char *, void *),
1950 struct objfile *objfile;
1952 ALL_OBJFILES (objfile)
1955 objfile->sf->qf->expand_symtabs_matching (objfile, NULL, fun,
1961 map_partial_symbol_filenames (symbol_filename_ftype *fun, void *data,
1964 struct objfile *objfile;
1966 ALL_OBJFILES (objfile)
1969 objfile->sf->qf->map_symbol_filenames (objfile, fun, data,