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 /* 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);
168 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
170 if (FILENAME_CMP (name, pst->filename) == 0)
172 if (partial_map_expand_apply (objfile, name, full_path, real_path,
173 pst, callback, data))
177 /* Before we invoke realpath, which can get expensive when many
178 files are involved, do a quick comparison of the basenames. */
179 if (! basenames_may_differ
180 && FILENAME_CMP (name_basename, lbasename (pst->filename)) != 0)
183 /* If the user gave us an absolute path, try to find the file in
184 this symtab and use its absolute path. */
185 if (full_path != NULL)
187 psymtab_to_fullname (pst);
188 if (pst->fullname != NULL
189 && FILENAME_CMP (full_path, pst->fullname) == 0)
191 if (partial_map_expand_apply (objfile, name, full_path, real_path,
192 pst, callback, data))
197 if (real_path != NULL)
200 psymtab_to_fullname (pst);
201 if (pst->fullname != NULL)
203 rp = gdb_realpath (pst->fullname);
204 make_cleanup (xfree, rp);
206 if (rp != NULL && FILENAME_CMP (real_path, rp) == 0)
208 if (partial_map_expand_apply (objfile, name, full_path, real_path,
209 pst, callback, data))
215 /* Now, search for a matching tail (only if name doesn't have any dirs). */
217 if (name_basename == name)
218 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
220 if (FILENAME_CMP (lbasename (pst->filename), name) == 0)
221 if (partial_map_expand_apply (objfile, name, full_path, real_path, pst,
229 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
230 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
232 static struct partial_symtab *
233 find_pc_sect_psymtab_closer (CORE_ADDR pc, struct obj_section *section,
234 struct partial_symtab *pst,
235 struct minimal_symbol *msymbol)
237 struct objfile *objfile = pst->objfile;
238 struct partial_symtab *tpst;
239 struct partial_symtab *best_pst = pst;
240 CORE_ADDR best_addr = pst->textlow;
242 gdb_assert (!pst->psymtabs_addrmap_supported);
244 /* An objfile that has its functions reordered might have
245 many partial symbol tables containing the PC, but
246 we want the partial symbol table that contains the
247 function containing the PC. */
248 if (!(objfile->flags & OBJF_REORDERED) &&
249 section == 0) /* Can't validate section this way. */
255 /* The code range of partial symtabs sometimes overlap, so, in
256 the loop below, we need to check all partial symtabs and
257 find the one that fits better for the given PC address. We
258 select the partial symtab that contains a symbol whose
259 address is closest to the PC address. By closest we mean
260 that find_pc_sect_symbol returns the symbol with address
261 that is closest and still less than the given PC. */
262 for (tpst = pst; tpst != NULL; tpst = tpst->next)
264 if (pc >= tpst->textlow && pc < tpst->texthigh)
266 struct partial_symbol *p;
269 /* NOTE: This assumes that every psymbol has a
270 corresponding msymbol, which is not necessarily
271 true; the debug info might be much richer than the
272 object's symbol table. */
273 p = find_pc_sect_psymbol (tpst, pc, section);
275 && SYMBOL_VALUE_ADDRESS (p)
276 == SYMBOL_VALUE_ADDRESS (msymbol))
279 /* Also accept the textlow value of a psymtab as a
280 "symbol", to provide some support for partial
281 symbol tables with line information but no debug
282 symbols (e.g. those produced by an assembler). */
284 this_addr = SYMBOL_VALUE_ADDRESS (p);
286 this_addr = tpst->textlow;
288 /* Check whether it is closer than our current
289 BEST_ADDR. Since this symbol address is
290 necessarily lower or equal to PC, the symbol closer
291 to PC is the symbol which address is the highest.
292 This way we return the psymtab which contains such
293 best match symbol. This can help in cases where the
294 symbol information/debuginfo is not complete, like
295 for instance on IRIX6 with gcc, where no debug info
296 is emitted for statics. (See also the nodebug.exp
298 if (this_addr > best_addr)
300 best_addr = this_addr;
308 /* Find which partial symtab contains PC and SECTION. Return 0 if
309 none. We return the psymtab that contains a symbol whose address
310 exactly matches PC, or, if we cannot find an exact match, the
311 psymtab that contains a symbol whose address is closest to PC. */
312 static struct partial_symtab *
313 find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
314 struct obj_section *section,
315 struct minimal_symbol *msymbol)
317 struct partial_symtab *pst;
319 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
320 than the later used TEXTLOW/TEXTHIGH one. */
322 if (objfile->psymtabs_addrmap != NULL)
324 pst = addrmap_find (objfile->psymtabs_addrmap, pc);
327 /* FIXME: addrmaps currently do not handle overlayed sections,
328 so fall back to the non-addrmap case if we're debugging
329 overlays and the addrmap returned the wrong section. */
330 if (overlay_debugging && msymbol && section)
332 struct partial_symbol *p;
334 /* NOTE: This assumes that every psymbol has a
335 corresponding msymbol, which is not necessarily
336 true; the debug info might be much richer than the
337 object's symbol table. */
338 p = find_pc_sect_psymbol (pst, pc, section);
340 || SYMBOL_VALUE_ADDRESS (p)
341 != SYMBOL_VALUE_ADDRESS (msymbol))
345 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
346 PSYMTABS_ADDRMAP we used has already the best 1-byte
347 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
348 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
357 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
358 which still have no corresponding full SYMTABs read. But it is not
359 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
362 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
363 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
364 debug info type in single OBJFILE. */
366 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
367 if (!pst->psymtabs_addrmap_supported
368 && pc >= pst->textlow && pc < pst->texthigh)
370 struct partial_symtab *best_pst;
372 best_pst = find_pc_sect_psymtab_closer (pc, section, pst, msymbol);
373 if (best_pst != NULL)
380 static struct symtab *
381 find_pc_sect_symtab_from_partial (struct objfile *objfile,
382 struct minimal_symbol *msymbol,
383 CORE_ADDR pc, struct obj_section *section,
386 struct partial_symtab *ps = find_pc_sect_psymtab (objfile, pc, section,
390 if (warn_if_readin && ps->readin)
391 /* Might want to error() here (in case symtab is corrupt and
392 will cause a core dump), but maybe we can successfully
393 continue, so let's not. */
395 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
396 paddress (get_objfile_arch (ps->objfile), pc));
397 return PSYMTAB_TO_SYMTAB (ps);
402 /* Find which partial symbol within a psymtab matches PC and SECTION.
405 static struct partial_symbol *
406 find_pc_sect_psymbol (struct partial_symtab *psymtab, CORE_ADDR pc,
407 struct obj_section *section)
409 struct partial_symbol *best = NULL, *p, **pp;
412 gdb_assert (psymtab != NULL);
414 /* Cope with programs that start at address 0. */
415 best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0;
417 /* Search the global symbols as well as the static symbols, so that
418 find_pc_partial_function doesn't use a minimal symbol and thus
419 cache a bad endaddr. */
420 for (pp = psymtab->objfile->global_psymbols.list + psymtab->globals_offset;
421 (pp - (psymtab->objfile->global_psymbols.list + psymtab->globals_offset)
422 < psymtab->n_global_syms);
426 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
427 && SYMBOL_CLASS (p) == LOC_BLOCK
428 && pc >= SYMBOL_VALUE_ADDRESS (p)
429 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
430 || (psymtab->textlow == 0
431 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
433 if (section) /* Match on a specific section. */
435 fixup_psymbol_section (p, psymtab->objfile);
436 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
439 best_pc = SYMBOL_VALUE_ADDRESS (p);
444 for (pp = psymtab->objfile->static_psymbols.list + psymtab->statics_offset;
445 (pp - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset)
446 < psymtab->n_static_syms);
450 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
451 && SYMBOL_CLASS (p) == LOC_BLOCK
452 && pc >= SYMBOL_VALUE_ADDRESS (p)
453 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
454 || (psymtab->textlow == 0
455 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
457 if (section) /* Match on a specific section. */
459 fixup_psymbol_section (p, psymtab->objfile);
460 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
463 best_pc = SYMBOL_VALUE_ADDRESS (p);
471 static struct partial_symbol *
472 fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
479 if (SYMBOL_OBJ_SECTION (psym))
482 gdb_assert (objfile);
484 switch (SYMBOL_CLASS (psym))
489 addr = SYMBOL_VALUE_ADDRESS (psym);
492 /* Nothing else will be listed in the minsyms -- no use looking
497 fixup_section (&psym->ginfo, addr, objfile);
502 static struct symtab *
503 lookup_symbol_aux_psymtabs (struct objfile *objfile,
504 int block_index, const char *name,
505 const domain_enum domain)
507 struct partial_symtab *ps;
508 const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
510 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
512 if (!ps->readin && lookup_partial_symbol (ps, name, psymtab_index, domain))
514 struct symbol *sym = NULL;
515 struct symtab *stab = PSYMTAB_TO_SYMTAB (ps);
517 /* Some caution must be observed with overloaded functions
518 and methods, since the psymtab will not contain any overload
519 information (but NAME might contain it). */
522 struct blockvector *bv = BLOCKVECTOR (stab);
523 struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
525 sym = lookup_block_symbol (block, name, domain);
528 if (sym && strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0)
531 /* Keep looking through other psymtabs. */
538 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
539 the global block of PST if GLOBAL, and otherwise the static block.
540 MATCH is the comparison operation that returns true iff MATCH (s,
541 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
542 non-null, the symbols in the block are assumed to be ordered
543 according to it (allowing binary search). It must be compatible
544 with MATCH. Returns the symbol, if found, and otherwise NULL. */
546 static struct partial_symbol *
547 match_partial_symbol (struct partial_symtab *pst, int global,
548 const char *name, domain_enum domain,
549 symbol_compare_ftype *match,
550 symbol_compare_ftype *ordered_compare)
552 struct partial_symbol **start, **psym;
553 struct partial_symbol **top, **real_top, **bottom, **center;
554 int length = (global ? pst->n_global_syms : pst->n_static_syms);
555 int do_linear_search = 1;
560 pst->objfile->global_psymbols.list + pst->globals_offset :
561 pst->objfile->static_psymbols.list + pst->statics_offset);
563 if (global && ordered_compare) /* Can use a binary search. */
565 do_linear_search = 0;
567 /* Binary search. This search is guaranteed to end with center
568 pointing at the earliest partial symbol whose name might be
569 correct. At that point *all* partial symbols with an
570 appropriate name will be checked against the correct
574 top = start + length - 1;
578 center = bottom + (top - bottom) / 2;
579 gdb_assert (center < top);
580 if (!do_linear_search
581 && (SYMBOL_LANGUAGE (*center) == language_java))
582 do_linear_search = 1;
583 if (ordered_compare (SYMBOL_SEARCH_NAME (*center), name) >= 0)
588 gdb_assert (top == bottom);
590 while (top <= real_top
591 && match (SYMBOL_SEARCH_NAME (*top), name) == 0)
593 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
594 SYMBOL_DOMAIN (*top), domain))
600 /* Can't use a binary search or else we found during the binary search that
601 we should also do a linear search. */
603 if (do_linear_search)
605 for (psym = start; psym < start + length; psym++)
607 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
608 SYMBOL_DOMAIN (*psym), domain)
609 && match (SYMBOL_SEARCH_NAME (*psym), name) == 0)
618 pre_expand_symtabs_matching_psymtabs (struct objfile *objfile,
619 enum block_enum block_kind,
626 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
627 not contain any method/function instance information (since this would
628 force reading type information while reading psymtabs). Therefore,
629 if NAME contains overload information, it must be stripped before searching
632 The caller is responsible for freeing the return result. */
635 psymtab_search_name (const char *name)
637 switch (current_language->la_language)
642 if (strchr (name, '('))
644 char *ret = cp_remove_params (name);
656 return xstrdup (name);
659 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
660 Check the global symbols if GLOBAL, the static symbols if not. */
662 static struct partial_symbol *
663 lookup_partial_symbol (struct partial_symtab *pst, const char *name,
664 int global, domain_enum domain)
666 struct partial_symbol **start, **psym;
667 struct partial_symbol **top, **real_top, **bottom, **center;
668 int length = (global ? pst->n_global_syms : pst->n_static_syms);
669 int do_linear_search = 1;
671 struct cleanup *cleanup;
678 search_name = psymtab_search_name (name);
679 cleanup = make_cleanup (xfree, search_name);
681 pst->objfile->global_psymbols.list + pst->globals_offset :
682 pst->objfile->static_psymbols.list + pst->statics_offset);
684 if (global) /* This means we can use a binary search. */
686 do_linear_search = 0;
688 /* Binary search. This search is guaranteed to end with center
689 pointing at the earliest partial symbol whose name might be
690 correct. At that point *all* partial symbols with an
691 appropriate name will be checked against the correct
695 top = start + length - 1;
699 center = bottom + (top - bottom) / 2;
701 internal_error (__FILE__, __LINE__,
702 _("failed internal consistency check"));
703 if (!do_linear_search
704 && SYMBOL_LANGUAGE (*center) == language_java)
706 do_linear_search = 1;
708 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center),
718 if (!(top == bottom))
719 internal_error (__FILE__, __LINE__,
720 _("failed internal consistency check"));
722 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
723 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
724 while (top >= start && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
727 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
730 while (top <= real_top && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
732 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
733 SYMBOL_DOMAIN (*top), domain))
735 do_cleanups (cleanup);
742 /* Can't use a binary search or else we found during the binary search that
743 we should also do a linear search. */
745 if (do_linear_search)
747 for (psym = start; psym < start + length; psym++)
749 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
750 SYMBOL_DOMAIN (*psym), domain)
751 && SYMBOL_MATCHES_SEARCH_NAME (*psym, search_name))
753 do_cleanups (cleanup);
759 do_cleanups (cleanup);
763 /* Get the symbol table that corresponds to a partial_symtab.
764 This is fast after the first time you do it. In fact, there
765 is an even faster macro PSYMTAB_TO_SYMTAB that does the fast
768 static struct symtab *
769 psymtab_to_symtab (struct partial_symtab *pst)
771 /* If it's been looked up before, return it. */
775 /* If it has not yet been read in, read it. */
778 struct cleanup *back_to = increment_reading_symtab ();
780 (*pst->read_symtab) (pst);
781 do_cleanups (back_to);
788 relocate_psymtabs (struct objfile *objfile,
789 struct section_offsets *new_offsets,
790 struct section_offsets *delta)
792 struct partial_symbol **psym;
793 struct partial_symtab *p;
795 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
797 p->textlow += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
798 p->texthigh += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
801 for (psym = objfile->global_psymbols.list;
802 psym < objfile->global_psymbols.next;
805 fixup_psymbol_section (*psym, objfile);
806 if (SYMBOL_SECTION (*psym) >= 0)
807 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
808 SYMBOL_SECTION (*psym));
810 for (psym = objfile->static_psymbols.list;
811 psym < objfile->static_psymbols.next;
814 fixup_psymbol_section (*psym, objfile);
815 if (SYMBOL_SECTION (*psym) >= 0)
816 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
817 SYMBOL_SECTION (*psym));
821 static struct symtab *
822 find_last_source_symtab_from_partial (struct objfile *ofp)
824 struct partial_symtab *ps;
825 struct partial_symtab *cs_pst = 0;
827 ALL_OBJFILE_PSYMTABS_REQUIRED (ofp, ps)
829 const char *name = ps->filename;
830 int len = strlen (name);
832 if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0
833 || strcmp (name, "<<C++-namespaces>>") == 0)))
841 internal_error (__FILE__, __LINE__,
842 _("select_source_symtab: "
843 "readin pst found and no symtabs."));
846 return PSYMTAB_TO_SYMTAB (cs_pst);
852 forget_cached_source_info_partial (struct objfile *objfile)
854 struct partial_symtab *pst;
856 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
858 if (pst->fullname != NULL)
860 xfree (pst->fullname);
861 pst->fullname = NULL;
867 print_partial_symbols (struct gdbarch *gdbarch,
868 struct partial_symbol **p, int count, char *what,
869 struct ui_file *outfile)
871 fprintf_filtered (outfile, " %s partial symbols:\n", what);
874 fprintf_filtered (outfile, " `%s'", SYMBOL_LINKAGE_NAME (*p));
875 if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
877 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
879 fputs_filtered (", ", outfile);
880 switch (SYMBOL_DOMAIN (*p))
883 fputs_filtered ("undefined domain, ", outfile);
886 /* This is the usual thing -- don't print it. */
889 fputs_filtered ("struct domain, ", outfile);
892 fputs_filtered ("label domain, ", outfile);
895 fputs_filtered ("<invalid domain>, ", outfile);
898 switch (SYMBOL_CLASS (*p))
901 fputs_filtered ("undefined", outfile);
904 fputs_filtered ("constant int", outfile);
907 fputs_filtered ("static", outfile);
910 fputs_filtered ("register", outfile);
913 fputs_filtered ("pass by value", outfile);
916 fputs_filtered ("pass by reference", outfile);
918 case LOC_REGPARM_ADDR:
919 fputs_filtered ("register address parameter", outfile);
922 fputs_filtered ("stack parameter", outfile);
925 fputs_filtered ("type", outfile);
928 fputs_filtered ("label", outfile);
931 fputs_filtered ("function", outfile);
933 case LOC_CONST_BYTES:
934 fputs_filtered ("constant bytes", outfile);
937 fputs_filtered ("unresolved", outfile);
939 case LOC_OPTIMIZED_OUT:
940 fputs_filtered ("optimized out", outfile);
943 fputs_filtered ("computed at runtime", outfile);
946 fputs_filtered ("<invalid location>", outfile);
949 fputs_filtered (", ", outfile);
950 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (*p)), outfile);
951 fprintf_filtered (outfile, "\n");
957 dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
958 struct ui_file *outfile)
960 struct gdbarch *gdbarch = get_objfile_arch (objfile);
963 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
965 fprintf_filtered (outfile, "(object ");
966 gdb_print_host_address (psymtab, outfile);
967 fprintf_filtered (outfile, ")\n\n");
968 fprintf_unfiltered (outfile, " Read from object file %s (",
970 gdb_print_host_address (objfile, outfile);
971 fprintf_unfiltered (outfile, ")\n");
975 fprintf_filtered (outfile,
976 " Full symtab was read (at ");
977 gdb_print_host_address (psymtab->symtab, outfile);
978 fprintf_filtered (outfile, " by function at ");
979 gdb_print_host_address (psymtab->read_symtab, outfile);
980 fprintf_filtered (outfile, ")\n");
983 fprintf_filtered (outfile, " Relocate symbols by ");
984 for (i = 0; i < psymtab->objfile->num_sections; ++i)
987 fprintf_filtered (outfile, ", ");
989 fputs_filtered (paddress (gdbarch,
990 ANOFFSET (psymtab->section_offsets, i)),
993 fprintf_filtered (outfile, "\n");
995 fprintf_filtered (outfile, " Symbols cover text addresses ");
996 fputs_filtered (paddress (gdbarch, psymtab->textlow), outfile);
997 fprintf_filtered (outfile, "-");
998 fputs_filtered (paddress (gdbarch, psymtab->texthigh), outfile);
999 fprintf_filtered (outfile, "\n");
1000 fprintf_filtered (outfile, " Address map supported - %s.\n",
1001 psymtab->psymtabs_addrmap_supported ? "yes" : "no");
1002 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
1003 psymtab->number_of_dependencies);
1004 for (i = 0; i < psymtab->number_of_dependencies; i++)
1006 fprintf_filtered (outfile, " %d ", i);
1007 gdb_print_host_address (psymtab->dependencies[i], outfile);
1008 fprintf_filtered (outfile, " %s\n",
1009 psymtab->dependencies[i]->filename);
1011 if (psymtab->n_global_syms > 0)
1013 print_partial_symbols (gdbarch,
1014 objfile->global_psymbols.list
1015 + psymtab->globals_offset,
1016 psymtab->n_global_syms, "Global", outfile);
1018 if (psymtab->n_static_syms > 0)
1020 print_partial_symbols (gdbarch,
1021 objfile->static_psymbols.list
1022 + psymtab->statics_offset,
1023 psymtab->n_static_syms, "Static", outfile);
1025 fprintf_filtered (outfile, "\n");
1029 print_psymtab_stats_for_objfile (struct objfile *objfile)
1032 struct partial_symtab *ps;
1035 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1037 if (ps->readin == 0)
1040 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i);
1044 dump_psymtabs_for_objfile (struct objfile *objfile)
1046 struct partial_symtab *psymtab;
1048 if (objfile->psymtabs)
1050 printf_filtered ("Psymtabs:\n");
1051 for (psymtab = objfile->psymtabs;
1053 psymtab = psymtab->next)
1055 printf_filtered ("%s at ",
1057 gdb_print_host_address (psymtab, gdb_stdout);
1058 printf_filtered (", ");
1059 if (psymtab->objfile != objfile)
1061 printf_filtered ("NOT ON CHAIN! ");
1065 printf_filtered ("\n\n");
1069 /* Look through the partial symtabs for all symbols which begin
1070 by matching FUNC_NAME. Make sure we read that symbol table in. */
1073 read_symtabs_for_function (struct objfile *objfile, const char *func_name)
1075 struct partial_symtab *ps;
1077 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1082 if ((lookup_partial_symbol (ps, func_name, 1, VAR_DOMAIN)
1084 || (lookup_partial_symbol (ps, func_name, 0, VAR_DOMAIN)
1086 psymtab_to_symtab (ps);
1091 expand_partial_symbol_tables (struct objfile *objfile)
1093 struct partial_symtab *psymtab;
1095 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
1097 psymtab_to_symtab (psymtab);
1102 read_psymtabs_with_filename (struct objfile *objfile, const char *filename)
1104 struct partial_symtab *p;
1106 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
1108 if (filename_cmp (filename, p->filename) == 0)
1109 PSYMTAB_TO_SYMTAB (p);
1114 map_symbol_filenames_psymtab (struct objfile *objfile,
1115 symbol_filename_ftype *fun, void *data,
1118 struct partial_symtab *ps;
1120 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1122 const char *fullname;
1129 fullname = psymtab_to_fullname (ps);
1132 (*fun) (ps->filename, fullname, data);
1136 int find_and_open_source (const char *filename,
1137 const char *dirname,
1140 /* Finds the fullname that a partial_symtab represents.
1142 If this functions finds the fullname, it will save it in ps->fullname
1143 and it will also return the value.
1145 If this function fails to find the file that this partial_symtab represents,
1146 NULL will be returned and ps->fullname will be set to NULL. */
1149 psymtab_to_fullname (struct partial_symtab *ps)
1156 /* Use cached copy if we have it.
1157 We rely on forget_cached_source_info being called appropriately
1158 to handle cases like the file being moved. */
1160 return ps->fullname;
1162 r = find_and_open_source (ps->filename, ps->dirname, &ps->fullname);
1167 return ps->fullname;
1174 find_symbol_file_from_partial (struct objfile *objfile, const char *name)
1176 struct partial_symtab *pst;
1178 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
1180 if (lookup_partial_symbol (pst, name, 1, VAR_DOMAIN))
1181 return pst->filename;
1186 /* For all symbols, s, in BLOCK that are in NAMESPACE and match NAME
1187 according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
1188 BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK
1189 ever returns non-zero, and otherwise returns 0. */
1192 map_block (const char *name, domain_enum namespace, struct objfile *objfile,
1193 struct block *block,
1194 int (*callback) (struct block *, struct symbol *, void *),
1195 void *data, symbol_compare_ftype *match)
1197 struct dict_iterator iter;
1200 for (sym = dict_iter_match_first (BLOCK_DICT (block), name, match, &iter);
1201 sym != NULL; sym = dict_iter_match_next (name, match, &iter))
1203 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
1204 SYMBOL_DOMAIN (sym), namespace))
1206 if (callback (block, sym, data))
1214 /* Psymtab version of map_matching_symbols. See its definition in
1215 the definition of quick_symbol_functions in symfile.h. */
1218 map_matching_symbols_psymtab (const char *name, domain_enum namespace,
1219 struct objfile *objfile, int global,
1220 int (*callback) (struct block *,
1221 struct symbol *, void *),
1223 symbol_compare_ftype *match,
1224 symbol_compare_ftype *ordered_compare)
1226 const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
1227 struct partial_symtab *ps;
1229 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1233 || match_partial_symbol (ps, global, name, namespace, match,
1236 struct symtab *s = PSYMTAB_TO_SYMTAB (ps);
1237 struct block *block;
1239 if (s == NULL || !s->primary)
1241 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), block_kind);
1242 if (map_block (name, namespace, objfile, block,
1243 callback, data, match))
1245 if (callback (block, NULL, data))
1252 expand_symtabs_matching_via_partial
1253 (struct objfile *objfile,
1254 int (*file_matcher) (const char *, void *),
1255 int (*name_matcher) (const struct language_defn *, const char *, void *),
1256 enum search_domain kind,
1259 struct partial_symtab *ps;
1261 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1263 struct partial_symbol **psym;
1264 struct partial_symbol **bound, **gbound, **sbound;
1270 if (file_matcher && ! (*file_matcher) (ps->filename, data))
1273 gbound = objfile->global_psymbols.list
1274 + ps->globals_offset + ps->n_global_syms;
1275 sbound = objfile->static_psymbols.list
1276 + ps->statics_offset + ps->n_static_syms;
1279 /* Go through all of the symbols stored in a partial
1280 symtab in one loop. */
1281 psym = objfile->global_psymbols.list + ps->globals_offset;
1286 if (bound == gbound && ps->n_static_syms != 0)
1288 psym = objfile->static_psymbols.list + ps->statics_offset;
1299 if ((kind == ALL_DOMAIN
1300 || (kind == VARIABLES_DOMAIN
1301 && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
1302 && SYMBOL_CLASS (*psym) != LOC_BLOCK)
1303 || (kind == FUNCTIONS_DOMAIN
1304 && SYMBOL_CLASS (*psym) == LOC_BLOCK)
1305 || (kind == TYPES_DOMAIN
1306 && SYMBOL_CLASS (*psym) == LOC_TYPEDEF))
1307 && (*name_matcher) (current_language,
1308 SYMBOL_SEARCH_NAME (*psym), data))
1310 PSYMTAB_TO_SYMTAB (ps);
1320 objfile_has_psyms (struct objfile *objfile)
1322 return objfile->psymtabs != NULL;
1325 const struct quick_symbol_functions psym_functions =
1328 find_last_source_symtab_from_partial,
1329 forget_cached_source_info_partial,
1330 partial_map_symtabs_matching_filename,
1331 lookup_symbol_aux_psymtabs,
1332 pre_expand_symtabs_matching_psymtabs,
1333 print_psymtab_stats_for_objfile,
1334 dump_psymtabs_for_objfile,
1336 read_symtabs_for_function,
1337 expand_partial_symbol_tables,
1338 read_psymtabs_with_filename,
1339 find_symbol_file_from_partial,
1340 map_matching_symbols_psymtab,
1341 expand_symtabs_matching_via_partial,
1342 find_pc_sect_symtab_from_partial,
1343 map_symbol_filenames_psymtab
1348 /* This compares two partial symbols by names, using strcmp_iw_ordered
1349 for the comparison. */
1352 compare_psymbols (const void *s1p, const void *s2p)
1354 struct partial_symbol *const *s1 = s1p;
1355 struct partial_symbol *const *s2 = s2p;
1357 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1),
1358 SYMBOL_SEARCH_NAME (*s2));
1362 sort_pst_symbols (struct partial_symtab *pst)
1364 /* Sort the global list; don't sort the static list. */
1366 qsort (pst->objfile->global_psymbols.list + pst->globals_offset,
1367 pst->n_global_syms, sizeof (struct partial_symbol *),
1371 /* Allocate and partially fill a partial symtab. It will be
1372 completely filled at the end of the symbol list.
1374 FILENAME is the name of the symbol-file we are reading from. */
1376 struct partial_symtab *
1377 start_psymtab_common (struct objfile *objfile,
1378 struct section_offsets *section_offsets,
1379 const char *filename,
1380 CORE_ADDR textlow, struct partial_symbol **global_syms,
1381 struct partial_symbol **static_syms)
1383 struct partial_symtab *psymtab;
1385 psymtab = allocate_psymtab (filename, objfile);
1386 psymtab->section_offsets = section_offsets;
1387 psymtab->textlow = textlow;
1388 psymtab->texthigh = psymtab->textlow; /* default */
1389 psymtab->globals_offset = global_syms - objfile->global_psymbols.list;
1390 psymtab->statics_offset = static_syms - objfile->static_psymbols.list;
1394 /* Calculate a hash code for the given partial symbol. The hash is
1395 calculated using the symbol's value, language, domain, class
1396 and name. These are the values which are set by
1397 add_psymbol_to_bcache. */
1399 static unsigned long
1400 psymbol_hash (const void *addr, int length)
1402 unsigned long h = 0;
1403 struct partial_symbol *psymbol = (struct partial_symbol *) addr;
1404 unsigned int lang = psymbol->ginfo.language;
1405 unsigned int domain = PSYMBOL_DOMAIN (psymbol);
1406 unsigned int class = PSYMBOL_CLASS (psymbol);
1408 h = hash_continue (&psymbol->ginfo.value, sizeof (psymbol->ginfo.value), h);
1409 h = hash_continue (&lang, sizeof (unsigned int), h);
1410 h = hash_continue (&domain, sizeof (unsigned int), h);
1411 h = hash_continue (&class, sizeof (unsigned int), h);
1412 h = hash_continue (psymbol->ginfo.name, strlen (psymbol->ginfo.name), h);
1417 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1418 For the comparison this function uses a symbols value,
1419 language, domain, class and name. */
1422 psymbol_compare (const void *addr1, const void *addr2, int length)
1424 struct partial_symbol *sym1 = (struct partial_symbol *) addr1;
1425 struct partial_symbol *sym2 = (struct partial_symbol *) addr2;
1427 return (memcmp (&sym1->ginfo.value, &sym1->ginfo.value,
1428 sizeof (sym1->ginfo.value)) == 0
1429 && sym1->ginfo.language == sym2->ginfo.language
1430 && PSYMBOL_DOMAIN (sym1) == PSYMBOL_DOMAIN (sym2)
1431 && PSYMBOL_CLASS (sym1) == PSYMBOL_CLASS (sym2)
1432 && sym1->ginfo.name == sym2->ginfo.name);
1435 /* Initialize a partial symbol bcache. */
1437 struct psymbol_bcache *
1438 psymbol_bcache_init (void)
1440 struct psymbol_bcache *bcache = XCALLOC (1, struct psymbol_bcache);
1441 bcache->bcache = bcache_xmalloc (psymbol_hash, psymbol_compare);
1445 /* Free a partial symbol bcache. */
1447 psymbol_bcache_free (struct psymbol_bcache *bcache)
1452 bcache_xfree (bcache->bcache);
1456 /* Return the internal bcache of the psymbol_bcache BCACHE. */
1459 psymbol_bcache_get_bcache (struct psymbol_bcache *bcache)
1461 return bcache->bcache;
1464 /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1465 symbol before, add a copy to BCACHE. In either case, return a pointer
1466 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1467 1 in case of new entry or 0 if returning an old entry. */
1469 static const struct partial_symbol *
1470 psymbol_bcache_full (struct partial_symbol *sym,
1471 struct psymbol_bcache *bcache,
1474 return bcache_full (sym,
1475 sizeof (struct partial_symbol),
1480 /* Helper function, initialises partial symbol structure and stashes
1481 it into objfile's bcache. Note that our caching mechanism will
1482 use all fields of struct partial_symbol to determine hash value of the
1483 structure. In other words, having two symbols with the same name but
1484 different domain (or address) is possible and correct. */
1486 static const struct partial_symbol *
1487 add_psymbol_to_bcache (const char *name, int namelength, int copy_name,
1489 enum address_class class,
1490 long val, /* Value as a long */
1491 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1492 enum language language, struct objfile *objfile,
1495 struct partial_symbol psymbol;
1497 /* We must ensure that the entire 'value' field has been zeroed
1498 before assigning to it, because an assignment may not write the
1500 memset (&psymbol.ginfo.value, 0, sizeof (psymbol.ginfo.value));
1502 /* val and coreaddr are mutually exclusive, one of them *will* be zero. */
1505 SYMBOL_VALUE (&psymbol) = val;
1509 SYMBOL_VALUE_ADDRESS (&psymbol) = coreaddr;
1511 SYMBOL_SECTION (&psymbol) = 0;
1512 SYMBOL_OBJ_SECTION (&psymbol) = NULL;
1513 SYMBOL_SET_LANGUAGE (&psymbol, language);
1514 PSYMBOL_DOMAIN (&psymbol) = domain;
1515 PSYMBOL_CLASS (&psymbol) = class;
1517 SYMBOL_SET_NAMES (&psymbol, name, namelength, copy_name, objfile);
1519 /* Stash the partial symbol away in the cache. */
1520 return psymbol_bcache_full (&psymbol,
1521 objfile->psymbol_cache,
1525 /* Increase the space allocated for LISTP, which is probably
1526 global_psymbols or static_psymbols. This space will eventually
1527 be freed in free_objfile(). */
1530 extend_psymbol_list (struct psymbol_allocation_list *listp,
1531 struct objfile *objfile)
1535 if (listp->size == 0)
1538 listp->list = (struct partial_symbol **)
1539 xmalloc (new_size * sizeof (struct partial_symbol *));
1543 new_size = listp->size * 2;
1544 listp->list = (struct partial_symbol **)
1545 xrealloc ((char *) listp->list,
1546 new_size * sizeof (struct partial_symbol *));
1548 /* Next assumes we only went one over. Should be good if
1549 program works correctly. */
1550 listp->next = listp->list + listp->size;
1551 listp->size = new_size;
1554 /* Helper function, adds partial symbol to the given partial symbol
1558 append_psymbol_to_list (struct psymbol_allocation_list *list,
1559 const struct partial_symbol *psym,
1560 struct objfile *objfile)
1562 if (list->next >= list->list + list->size)
1563 extend_psymbol_list (list, objfile);
1564 *list->next++ = (struct partial_symbol *) psym;
1565 OBJSTAT (objfile, n_psyms++);
1568 /* Add a symbol with a long value to a psymtab.
1569 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1570 Return the partial symbol that has been added. */
1572 /* NOTE: carlton/2003-09-11: The reason why we return the partial
1573 symbol is so that callers can get access to the symbol's demangled
1574 name, which they don't have any cheap way to determine otherwise.
1575 (Currenly, dwarf2read.c is the only file who uses that information,
1576 though it's possible that other readers might in the future.)
1577 Elena wasn't thrilled about that, and I don't blame her, but we
1578 couldn't come up with a better way to get that information. If
1579 it's needed in other situations, we could consider breaking up
1580 SYMBOL_SET_NAMES to provide access to the demangled name lookup
1583 const struct partial_symbol *
1584 add_psymbol_to_list (const char *name, int namelength, int copy_name,
1586 enum address_class class,
1587 struct psymbol_allocation_list *list,
1588 long val, /* Value as a long */
1589 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1590 enum language language, struct objfile *objfile)
1592 const struct partial_symbol *psym;
1596 /* Stash the partial symbol away in the cache. */
1597 psym = add_psymbol_to_bcache (name, namelength, copy_name, domain, class,
1598 val, coreaddr, language, objfile, &added);
1600 /* Do not duplicate global partial symbols. */
1601 if (list == &objfile->global_psymbols
1605 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1606 append_psymbol_to_list (list, psym, objfile);
1610 /* Initialize storage for partial symbols. */
1613 init_psymbol_list (struct objfile *objfile, int total_symbols)
1615 /* Free any previously allocated psymbol lists. */
1617 if (objfile->global_psymbols.list)
1619 xfree (objfile->global_psymbols.list);
1621 if (objfile->static_psymbols.list)
1623 xfree (objfile->static_psymbols.list);
1626 /* Current best guess is that approximately a twentieth
1627 of the total symbols (in a debugging file) are global or static
1628 oriented symbols. */
1630 objfile->global_psymbols.size = total_symbols / 10;
1631 objfile->static_psymbols.size = total_symbols / 10;
1633 if (objfile->global_psymbols.size > 0)
1635 objfile->global_psymbols.next =
1636 objfile->global_psymbols.list = (struct partial_symbol **)
1637 xmalloc ((objfile->global_psymbols.size
1638 * sizeof (struct partial_symbol *)));
1640 if (objfile->static_psymbols.size > 0)
1642 objfile->static_psymbols.next =
1643 objfile->static_psymbols.list = (struct partial_symbol **)
1644 xmalloc ((objfile->static_psymbols.size
1645 * sizeof (struct partial_symbol *)));
1649 struct partial_symtab *
1650 allocate_psymtab (const char *filename, struct objfile *objfile)
1652 struct partial_symtab *psymtab;
1654 if (objfile->free_psymtabs)
1656 psymtab = objfile->free_psymtabs;
1657 objfile->free_psymtabs = psymtab->next;
1660 psymtab = (struct partial_symtab *)
1661 obstack_alloc (&objfile->objfile_obstack,
1662 sizeof (struct partial_symtab));
1664 memset (psymtab, 0, sizeof (struct partial_symtab));
1665 psymtab->filename = obsavestring (filename, strlen (filename),
1666 &objfile->objfile_obstack);
1667 psymtab->symtab = NULL;
1669 /* Prepend it to the psymtab list for the objfile it belongs to.
1670 Psymtabs are searched in most recent inserted -> least recent
1673 psymtab->objfile = objfile;
1674 psymtab->next = objfile->psymtabs;
1675 objfile->psymtabs = psymtab;
1681 discard_psymtab (struct partial_symtab *pst)
1683 struct partial_symtab **prev_pst;
1686 Empty psymtabs happen as a result of header files which don't
1687 have any symbols in them. There can be a lot of them. But this
1688 check is wrong, in that a psymtab with N_SLINE entries but
1689 nothing else is not empty, but we don't realize that. Fixing
1690 that without slowing things down might be tricky. */
1692 /* First, snip it out of the psymtab chain. */
1694 prev_pst = &(pst->objfile->psymtabs);
1695 while ((*prev_pst) != pst)
1696 prev_pst = &((*prev_pst)->next);
1697 (*prev_pst) = pst->next;
1699 /* Next, put it on a free list for recycling. */
1701 pst->next = pst->objfile->free_psymtabs;
1702 pst->objfile->free_psymtabs = pst;
1708 maintenance_print_psymbols (char *args, int from_tty)
1711 struct ui_file *outfile;
1712 struct cleanup *cleanups;
1713 char *symname = NULL;
1714 char *filename = DEV_TTY;
1715 struct objfile *objfile;
1716 struct partial_symtab *ps;
1723 print-psymbols takes an output file name and optional symbol file name"));
1725 argv = gdb_buildargv (args);
1726 cleanups = make_cleanup_freeargv (argv);
1728 if (argv[0] != NULL)
1731 /* If a second arg is supplied, it is a source file name to match on. */
1732 if (argv[1] != NULL)
1738 filename = tilde_expand (filename);
1739 make_cleanup (xfree, filename);
1741 outfile = gdb_fopen (filename, FOPEN_WT);
1743 perror_with_name (filename);
1744 make_cleanup_ui_file_delete (outfile);
1747 ALL_PSYMTABS (objfile, ps)
1748 if (symname == NULL || filename_cmp (symname, ps->filename) == 0)
1749 dump_psymtab (objfile, ps, outfile);
1751 do_cleanups (cleanups);
1754 /* List all the partial symbol tables whose names match REGEXP (optional). */
1756 maintenance_info_psymtabs (char *regexp, int from_tty)
1758 struct program_space *pspace;
1759 struct objfile *objfile;
1764 ALL_PSPACES (pspace)
1765 ALL_PSPACE_OBJFILES (pspace, objfile)
1767 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1768 struct partial_symtab *psymtab;
1770 /* We don't want to print anything for this objfile until we
1771 actually find a symtab whose name matches. */
1772 int printed_objfile_start = 0;
1774 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
1779 || re_exec (psymtab->filename))
1781 if (! printed_objfile_start)
1783 printf_filtered ("{ objfile %s ", objfile->name);
1785 printf_filtered ("((struct objfile *) %s)\n",
1786 host_address_to_string (objfile));
1787 printed_objfile_start = 1;
1790 printf_filtered (" { psymtab %s ", psymtab->filename);
1792 printf_filtered ("((struct partial_symtab *) %s)\n",
1793 host_address_to_string (psymtab));
1795 printf_filtered (" readin %s\n",
1796 psymtab->readin ? "yes" : "no");
1797 printf_filtered (" fullname %s\n",
1799 ? psymtab->fullname : "(null)");
1800 printf_filtered (" text addresses ");
1801 fputs_filtered (paddress (gdbarch, psymtab->textlow),
1803 printf_filtered (" -- ");
1804 fputs_filtered (paddress (gdbarch, psymtab->texthigh),
1806 printf_filtered ("\n");
1807 printf_filtered (" psymtabs_addrmap_supported %s\n",
1808 (psymtab->psymtabs_addrmap_supported
1810 printf_filtered (" globals ");
1811 if (psymtab->n_global_syms)
1813 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1814 host_address_to_string (psymtab->objfile->global_psymbols.list
1815 + psymtab->globals_offset),
1816 psymtab->n_global_syms);
1819 printf_filtered ("(none)\n");
1820 printf_filtered (" statics ");
1821 if (psymtab->n_static_syms)
1823 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1824 host_address_to_string (psymtab->objfile->static_psymbols.list
1825 + psymtab->statics_offset),
1826 psymtab->n_static_syms);
1829 printf_filtered ("(none)\n");
1830 printf_filtered (" dependencies ");
1831 if (psymtab->number_of_dependencies)
1835 printf_filtered ("{\n");
1836 for (i = 0; i < psymtab->number_of_dependencies; i++)
1838 struct partial_symtab *dep = psymtab->dependencies[i];
1840 /* Note the string concatenation there --- no comma. */
1841 printf_filtered (" psymtab %s "
1842 "((struct partial_symtab *) %s)\n",
1844 host_address_to_string (dep));
1846 printf_filtered (" }\n");
1849 printf_filtered ("(none)\n");
1850 printf_filtered (" }\n");
1854 if (printed_objfile_start)
1855 printf_filtered ("}\n");
1859 /* Check consistency of psymtabs and symtabs. */
1862 maintenance_check_symtabs (char *ignore, int from_tty)
1865 struct partial_symbol **psym;
1866 struct symtab *s = NULL;
1867 struct partial_symtab *ps;
1868 struct blockvector *bv;
1869 struct objfile *objfile;
1873 ALL_PSYMTABS (objfile, ps)
1875 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1877 s = PSYMTAB_TO_SYMTAB (ps);
1880 bv = BLOCKVECTOR (s);
1881 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1882 psym = ps->objfile->static_psymbols.list + ps->statics_offset;
1883 length = ps->n_static_syms;
1886 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1887 SYMBOL_DOMAIN (*psym));
1890 printf_filtered ("Static symbol `");
1891 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1892 printf_filtered ("' only found in ");
1893 puts_filtered (ps->filename);
1894 printf_filtered (" psymtab\n");
1898 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1899 psym = ps->objfile->global_psymbols.list + ps->globals_offset;
1900 length = ps->n_global_syms;
1903 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1904 SYMBOL_DOMAIN (*psym));
1907 printf_filtered ("Global symbol `");
1908 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1909 printf_filtered ("' only found in ");
1910 puts_filtered (ps->filename);
1911 printf_filtered (" psymtab\n");
1915 if (ps->texthigh < ps->textlow)
1917 printf_filtered ("Psymtab ");
1918 puts_filtered (ps->filename);
1919 printf_filtered (" covers bad range ");
1920 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
1921 printf_filtered (" - ");
1922 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
1923 printf_filtered ("\n");
1926 if (ps->texthigh == 0)
1928 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
1930 printf_filtered ("Psymtab ");
1931 puts_filtered (ps->filename);
1932 printf_filtered (" covers ");
1933 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
1934 printf_filtered (" - ");
1935 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
1936 printf_filtered (" but symtab covers only ");
1937 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
1938 printf_filtered (" - ");
1939 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout);
1940 printf_filtered ("\n");
1948 expand_partial_symbol_names (int (*fun) (const struct language_defn *,
1949 const char *, void *),
1952 struct objfile *objfile;
1954 ALL_OBJFILES (objfile)
1957 objfile->sf->qf->expand_symtabs_matching (objfile, NULL, fun,
1963 map_partial_symbol_filenames (symbol_filename_ftype *fun, void *data,
1966 struct objfile *objfile;
1968 ALL_OBJFILES (objfile)
1971 objfile->sf->qf->map_symbol_filenames (objfile, fun, data,