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 static struct partial_symbol *match_partial_symbol (struct partial_symtab *,
50 const char *, domain_enum,
51 symbol_compare_ftype *,
52 symbol_compare_ftype *);
54 static struct partial_symbol *lookup_partial_symbol (struct partial_symtab *,
58 static char *psymtab_to_fullname (struct partial_symtab *ps);
60 static struct partial_symbol *find_pc_sect_psymbol (struct partial_symtab *,
62 struct obj_section *);
64 static struct partial_symbol *fixup_psymbol_section (struct partial_symbol
66 struct objfile *objfile);
68 static struct symtab *psymtab_to_symtab (struct partial_symtab *pst);
70 /* Ensure that the partial symbols for OBJFILE have been loaded. This
71 function always returns its argument, as a convenience. */
74 require_partial_symbols (struct objfile *objfile, int verbose)
76 if ((objfile->flags & OBJF_PSYMTABS_READ) == 0)
78 objfile->flags |= OBJF_PSYMTABS_READ;
80 if (objfile->sf->sym_read_psymbols)
84 printf_unfiltered (_("Reading symbols from %s..."),
86 gdb_flush (gdb_stdout);
88 (*objfile->sf->sym_read_psymbols) (objfile);
91 if (!objfile_has_symbols (objfile))
94 printf_unfiltered (_("(no debugging symbols found)..."));
98 printf_unfiltered (_("done.\n"));
106 /* Traverse all psymtabs in one objfile, requiring that the psymtabs
109 #define ALL_OBJFILE_PSYMTABS_REQUIRED(objfile, p) \
110 for ((p) = require_partial_symbols (objfile, 1)->psymtabs; \
114 /* We want to make sure this file always requires psymtabs. */
116 #undef ALL_OBJFILE_PSYMTABS
118 /* Traverse all psymtabs in all objfiles. */
120 #define ALL_PSYMTABS(objfile, p) \
121 ALL_OBJFILES (objfile) \
122 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
124 /* Helper function for partial_map_symtabs_matching_filename that
125 expands the symtabs and calls the iterator. */
128 partial_map_expand_apply (struct objfile *objfile,
130 const char *full_path,
131 const char *real_path,
132 struct partial_symtab *pst,
133 int (*callback) (struct symtab *, void *),
136 struct symtab *last_made = objfile->symtabs;
138 /* Shared psymtabs should never be seen here. Instead they should
139 be handled properly by the caller. */
140 gdb_assert (pst->user == NULL);
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 /* We can skip shared psymtabs here, because any file name will be
173 attached to the unshared psymtab. */
174 if (pst->user != NULL)
177 if (FILENAME_CMP (name, pst->filename) == 0
178 || (!is_abs && compare_filenames_for_search (pst->filename,
181 if (partial_map_expand_apply (objfile, name, full_path, real_path,
182 pst, callback, data))
186 /* Before we invoke realpath, which can get expensive when many
187 files are involved, do a quick comparison of the basenames. */
188 if (! basenames_may_differ
189 && FILENAME_CMP (name_basename, lbasename (pst->filename)) != 0)
192 /* If the user gave us an absolute path, try to find the file in
193 this symtab and use its absolute path. */
194 if (full_path != NULL)
196 psymtab_to_fullname (pst);
197 if (pst->fullname != NULL
198 && (FILENAME_CMP (full_path, pst->fullname) == 0
199 || (!is_abs && compare_filenames_for_search (pst->fullname,
202 if (partial_map_expand_apply (objfile, name, full_path, real_path,
203 pst, callback, data))
208 if (real_path != NULL)
211 psymtab_to_fullname (pst);
212 if (pst->fullname != NULL)
214 rp = gdb_realpath (pst->fullname);
215 make_cleanup (xfree, rp);
218 && (FILENAME_CMP (real_path, rp) == 0
219 || (!is_abs && compare_filenames_for_search (real_path,
222 if (partial_map_expand_apply (objfile, name, full_path, real_path,
223 pst, callback, data))
232 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
233 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
235 static struct partial_symtab *
236 find_pc_sect_psymtab_closer (CORE_ADDR pc, struct obj_section *section,
237 struct partial_symtab *pst,
238 struct minimal_symbol *msymbol)
240 struct objfile *objfile = pst->objfile;
241 struct partial_symtab *tpst;
242 struct partial_symtab *best_pst = pst;
243 CORE_ADDR best_addr = pst->textlow;
245 gdb_assert (!pst->psymtabs_addrmap_supported);
247 /* An objfile that has its functions reordered might have
248 many partial symbol tables containing the PC, but
249 we want the partial symbol table that contains the
250 function containing the PC. */
251 if (!(objfile->flags & OBJF_REORDERED) &&
252 section == 0) /* Can't validate section this way. */
258 /* The code range of partial symtabs sometimes overlap, so, in
259 the loop below, we need to check all partial symtabs and
260 find the one that fits better for the given PC address. We
261 select the partial symtab that contains a symbol whose
262 address is closest to the PC address. By closest we mean
263 that find_pc_sect_symbol returns the symbol with address
264 that is closest and still less than the given PC. */
265 for (tpst = pst; tpst != NULL; tpst = tpst->next)
267 if (pc >= tpst->textlow && pc < tpst->texthigh)
269 struct partial_symbol *p;
272 /* NOTE: This assumes that every psymbol has a
273 corresponding msymbol, which is not necessarily
274 true; the debug info might be much richer than the
275 object's symbol table. */
276 p = find_pc_sect_psymbol (tpst, pc, section);
278 && SYMBOL_VALUE_ADDRESS (p)
279 == SYMBOL_VALUE_ADDRESS (msymbol))
282 /* Also accept the textlow value of a psymtab as a
283 "symbol", to provide some support for partial
284 symbol tables with line information but no debug
285 symbols (e.g. those produced by an assembler). */
287 this_addr = SYMBOL_VALUE_ADDRESS (p);
289 this_addr = tpst->textlow;
291 /* Check whether it is closer than our current
292 BEST_ADDR. Since this symbol address is
293 necessarily lower or equal to PC, the symbol closer
294 to PC is the symbol which address is the highest.
295 This way we return the psymtab which contains such
296 best match symbol. This can help in cases where the
297 symbol information/debuginfo is not complete, like
298 for instance on IRIX6 with gcc, where no debug info
299 is emitted for statics. (See also the nodebug.exp
301 if (this_addr > best_addr)
303 best_addr = this_addr;
311 /* Find which partial symtab contains PC and SECTION. Return 0 if
312 none. We return the psymtab that contains a symbol whose address
313 exactly matches PC, or, if we cannot find an exact match, the
314 psymtab that contains a symbol whose address is closest to PC. */
315 static struct partial_symtab *
316 find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
317 struct obj_section *section,
318 struct minimal_symbol *msymbol)
320 struct partial_symtab *pst;
322 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
323 than the later used TEXTLOW/TEXTHIGH one. */
325 if (objfile->psymtabs_addrmap != NULL)
327 pst = addrmap_find (objfile->psymtabs_addrmap, pc);
330 /* FIXME: addrmaps currently do not handle overlayed sections,
331 so fall back to the non-addrmap case if we're debugging
332 overlays and the addrmap returned the wrong section. */
333 if (overlay_debugging && msymbol && section)
335 struct partial_symbol *p;
337 /* NOTE: This assumes that every psymbol has a
338 corresponding msymbol, which is not necessarily
339 true; the debug info might be much richer than the
340 object's symbol table. */
341 p = find_pc_sect_psymbol (pst, pc, section);
343 || SYMBOL_VALUE_ADDRESS (p)
344 != SYMBOL_VALUE_ADDRESS (msymbol))
348 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
349 PSYMTABS_ADDRMAP we used has already the best 1-byte
350 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
351 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
360 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
361 which still have no corresponding full SYMTABs read. But it is not
362 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
365 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
366 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
367 debug info type in single OBJFILE. */
369 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
370 if (!pst->psymtabs_addrmap_supported
371 && pc >= pst->textlow && pc < pst->texthigh)
373 struct partial_symtab *best_pst;
375 best_pst = find_pc_sect_psymtab_closer (pc, section, pst, msymbol);
376 if (best_pst != NULL)
383 static struct symtab *
384 find_pc_sect_symtab_from_partial (struct objfile *objfile,
385 struct minimal_symbol *msymbol,
386 CORE_ADDR pc, struct obj_section *section,
389 struct partial_symtab *ps = find_pc_sect_psymtab (objfile, pc, section,
393 if (warn_if_readin && ps->readin)
394 /* Might want to error() here (in case symtab is corrupt and
395 will cause a core dump), but maybe we can successfully
396 continue, so let's not. */
398 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
399 paddress (get_objfile_arch (ps->objfile), pc));
400 psymtab_to_symtab (ps);
406 /* Find which partial symbol within a psymtab matches PC and SECTION.
409 static struct partial_symbol *
410 find_pc_sect_psymbol (struct partial_symtab *psymtab, CORE_ADDR pc,
411 struct obj_section *section)
413 struct partial_symbol *best = NULL, *p, **pp;
416 gdb_assert (psymtab != NULL);
418 /* Cope with programs that start at address 0. */
419 best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0;
421 /* Search the global symbols as well as the static symbols, so that
422 find_pc_partial_function doesn't use a minimal symbol and thus
423 cache a bad endaddr. */
424 for (pp = psymtab->objfile->global_psymbols.list + psymtab->globals_offset;
425 (pp - (psymtab->objfile->global_psymbols.list + psymtab->globals_offset)
426 < psymtab->n_global_syms);
430 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
431 && SYMBOL_CLASS (p) == LOC_BLOCK
432 && pc >= SYMBOL_VALUE_ADDRESS (p)
433 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
434 || (psymtab->textlow == 0
435 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
437 if (section) /* Match on a specific section. */
439 fixup_psymbol_section (p, psymtab->objfile);
440 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
443 best_pc = SYMBOL_VALUE_ADDRESS (p);
448 for (pp = psymtab->objfile->static_psymbols.list + psymtab->statics_offset;
449 (pp - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset)
450 < psymtab->n_static_syms);
454 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
455 && SYMBOL_CLASS (p) == LOC_BLOCK
456 && pc >= SYMBOL_VALUE_ADDRESS (p)
457 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
458 || (psymtab->textlow == 0
459 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
461 if (section) /* Match on a specific section. */
463 fixup_psymbol_section (p, psymtab->objfile);
464 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
467 best_pc = SYMBOL_VALUE_ADDRESS (p);
475 static struct partial_symbol *
476 fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
483 if (SYMBOL_OBJ_SECTION (psym))
486 gdb_assert (objfile);
488 switch (SYMBOL_CLASS (psym))
493 addr = SYMBOL_VALUE_ADDRESS (psym);
496 /* Nothing else will be listed in the minsyms -- no use looking
501 fixup_section (&psym->ginfo, addr, objfile);
506 static struct symtab *
507 lookup_symbol_aux_psymtabs (struct objfile *objfile,
508 int block_index, const char *name,
509 const domain_enum domain)
511 struct partial_symtab *ps;
512 const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
514 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
516 if (!ps->readin && lookup_partial_symbol (ps, name, psymtab_index, domain))
518 struct symbol *sym = NULL;
519 struct symtab *stab = psymtab_to_symtab (ps);
521 /* Some caution must be observed with overloaded functions
522 and methods, since the psymtab will not contain any overload
523 information (but NAME might contain it). */
526 struct blockvector *bv = BLOCKVECTOR (stab);
527 struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
529 sym = lookup_block_symbol (block, name, domain);
532 if (sym && strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0)
535 /* Keep looking through other psymtabs. */
542 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
543 the global block of PST if GLOBAL, and otherwise the static block.
544 MATCH is the comparison operation that returns true iff MATCH (s,
545 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
546 non-null, the symbols in the block are assumed to be ordered
547 according to it (allowing binary search). It must be compatible
548 with MATCH. Returns the symbol, if found, and otherwise NULL. */
550 static struct partial_symbol *
551 match_partial_symbol (struct partial_symtab *pst, int global,
552 const char *name, domain_enum domain,
553 symbol_compare_ftype *match,
554 symbol_compare_ftype *ordered_compare)
556 struct partial_symbol **start, **psym;
557 struct partial_symbol **top, **real_top, **bottom, **center;
558 int length = (global ? pst->n_global_syms : pst->n_static_syms);
559 int do_linear_search = 1;
564 pst->objfile->global_psymbols.list + pst->globals_offset :
565 pst->objfile->static_psymbols.list + pst->statics_offset);
567 if (global && ordered_compare) /* Can use a binary search. */
569 do_linear_search = 0;
571 /* Binary search. This search is guaranteed to end with center
572 pointing at the earliest partial symbol whose name might be
573 correct. At that point *all* partial symbols with an
574 appropriate name will be checked against the correct
578 top = start + length - 1;
582 center = bottom + (top - bottom) / 2;
583 gdb_assert (center < top);
584 if (!do_linear_search
585 && (SYMBOL_LANGUAGE (*center) == language_java))
586 do_linear_search = 1;
587 if (ordered_compare (SYMBOL_SEARCH_NAME (*center), name) >= 0)
592 gdb_assert (top == bottom);
594 while (top <= real_top
595 && match (SYMBOL_SEARCH_NAME (*top), name) == 0)
597 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
598 SYMBOL_DOMAIN (*top), domain))
604 /* Can't use a binary search or else we found during the binary search that
605 we should also do a linear search. */
607 if (do_linear_search)
609 for (psym = start; psym < start + length; psym++)
611 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
612 SYMBOL_DOMAIN (*psym), domain)
613 && match (SYMBOL_SEARCH_NAME (*psym), name) == 0)
622 pre_expand_symtabs_matching_psymtabs (struct objfile *objfile,
623 enum block_enum block_kind,
630 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
631 not contain any method/function instance information (since this would
632 force reading type information while reading psymtabs). Therefore,
633 if NAME contains overload information, it must be stripped before searching
636 The caller is responsible for freeing the return result. */
639 psymtab_search_name (const char *name)
641 switch (current_language->la_language)
646 if (strchr (name, '('))
648 char *ret = cp_remove_params (name);
660 return xstrdup (name);
663 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
664 Check the global symbols if GLOBAL, the static symbols if not. */
666 static struct partial_symbol *
667 lookup_partial_symbol (struct partial_symtab *pst, const char *name,
668 int global, domain_enum domain)
670 struct partial_symbol **start, **psym;
671 struct partial_symbol **top, **real_top, **bottom, **center;
672 int length = (global ? pst->n_global_syms : pst->n_static_syms);
673 int do_linear_search = 1;
675 struct cleanup *cleanup;
682 search_name = psymtab_search_name (name);
683 cleanup = make_cleanup (xfree, search_name);
685 pst->objfile->global_psymbols.list + pst->globals_offset :
686 pst->objfile->static_psymbols.list + pst->statics_offset);
688 if (global) /* This means we can use a binary search. */
690 do_linear_search = 0;
692 /* Binary search. This search is guaranteed to end with center
693 pointing at the earliest partial symbol whose name might be
694 correct. At that point *all* partial symbols with an
695 appropriate name will be checked against the correct
699 top = start + length - 1;
703 center = bottom + (top - bottom) / 2;
705 internal_error (__FILE__, __LINE__,
706 _("failed internal consistency check"));
707 if (!do_linear_search
708 && SYMBOL_LANGUAGE (*center) == language_java)
710 do_linear_search = 1;
712 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center),
722 if (!(top == bottom))
723 internal_error (__FILE__, __LINE__,
724 _("failed internal consistency check"));
726 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
727 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
728 while (top >= start && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
731 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
734 while (top <= real_top && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
736 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
737 SYMBOL_DOMAIN (*top), domain))
739 do_cleanups (cleanup);
746 /* Can't use a binary search or else we found during the binary search that
747 we should also do a linear search. */
749 if (do_linear_search)
751 for (psym = start; psym < start + length; psym++)
753 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
754 SYMBOL_DOMAIN (*psym), domain)
755 && SYMBOL_MATCHES_SEARCH_NAME (*psym, search_name))
757 do_cleanups (cleanup);
763 do_cleanups (cleanup);
767 /* Get the symbol table that corresponds to a partial_symtab.
768 This is fast after the first time you do it. */
770 static struct symtab *
771 psymtab_to_symtab (struct partial_symtab *pst)
773 /* If it is a shared psymtab, find an unshared psymtab that includes
774 it. Any such psymtab will do. */
775 while (pst->user != NULL)
778 /* If it's been looked up before, return it. */
782 /* If it has not yet been read in, read it. */
785 struct cleanup *back_to = increment_reading_symtab ();
787 (*pst->read_symtab) (pst);
788 do_cleanups (back_to);
795 relocate_psymtabs (struct objfile *objfile,
796 struct section_offsets *new_offsets,
797 struct section_offsets *delta)
799 struct partial_symbol **psym;
800 struct partial_symtab *p;
802 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
804 p->textlow += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
805 p->texthigh += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
808 for (psym = objfile->global_psymbols.list;
809 psym < objfile->global_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));
817 for (psym = objfile->static_psymbols.list;
818 psym < objfile->static_psymbols.next;
821 fixup_psymbol_section (*psym, objfile);
822 if (SYMBOL_SECTION (*psym) >= 0)
823 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
824 SYMBOL_SECTION (*psym));
828 static struct symtab *
829 find_last_source_symtab_from_partial (struct objfile *ofp)
831 struct partial_symtab *ps;
832 struct partial_symtab *cs_pst = 0;
834 ALL_OBJFILE_PSYMTABS_REQUIRED (ofp, ps)
836 const char *name = ps->filename;
837 int len = strlen (name);
839 if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0
840 || strcmp (name, "<<C++-namespaces>>") == 0)))
848 internal_error (__FILE__, __LINE__,
849 _("select_source_symtab: "
850 "readin pst found and no symtabs."));
853 return psymtab_to_symtab (cs_pst);
859 forget_cached_source_info_partial (struct objfile *objfile)
861 struct partial_symtab *pst;
863 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
865 if (pst->fullname != NULL)
867 xfree (pst->fullname);
868 pst->fullname = NULL;
874 print_partial_symbols (struct gdbarch *gdbarch,
875 struct partial_symbol **p, int count, char *what,
876 struct ui_file *outfile)
878 fprintf_filtered (outfile, " %s partial symbols:\n", what);
881 fprintf_filtered (outfile, " `%s'", SYMBOL_LINKAGE_NAME (*p));
882 if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
884 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
886 fputs_filtered (", ", outfile);
887 switch (SYMBOL_DOMAIN (*p))
890 fputs_filtered ("undefined domain, ", outfile);
893 /* This is the usual thing -- don't print it. */
896 fputs_filtered ("struct domain, ", outfile);
899 fputs_filtered ("label domain, ", outfile);
902 fputs_filtered ("<invalid domain>, ", outfile);
905 switch (SYMBOL_CLASS (*p))
908 fputs_filtered ("undefined", outfile);
911 fputs_filtered ("constant int", outfile);
914 fputs_filtered ("static", outfile);
917 fputs_filtered ("register", outfile);
920 fputs_filtered ("pass by value", outfile);
923 fputs_filtered ("pass by reference", outfile);
925 case LOC_REGPARM_ADDR:
926 fputs_filtered ("register address parameter", outfile);
929 fputs_filtered ("stack parameter", outfile);
932 fputs_filtered ("type", outfile);
935 fputs_filtered ("label", outfile);
938 fputs_filtered ("function", outfile);
940 case LOC_CONST_BYTES:
941 fputs_filtered ("constant bytes", outfile);
944 fputs_filtered ("unresolved", outfile);
946 case LOC_OPTIMIZED_OUT:
947 fputs_filtered ("optimized out", outfile);
950 fputs_filtered ("computed at runtime", outfile);
953 fputs_filtered ("<invalid location>", outfile);
956 fputs_filtered (", ", outfile);
957 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (*p)), outfile);
958 fprintf_filtered (outfile, "\n");
964 dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
965 struct ui_file *outfile)
967 struct gdbarch *gdbarch = get_objfile_arch (objfile);
970 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
972 fprintf_filtered (outfile, "(object ");
973 gdb_print_host_address (psymtab, outfile);
974 fprintf_filtered (outfile, ")\n\n");
975 fprintf_unfiltered (outfile, " Read from object file %s (",
977 gdb_print_host_address (objfile, outfile);
978 fprintf_unfiltered (outfile, ")\n");
982 fprintf_filtered (outfile,
983 " Full symtab was read (at ");
984 gdb_print_host_address (psymtab->symtab, outfile);
985 fprintf_filtered (outfile, " by function at ");
986 gdb_print_host_address (psymtab->read_symtab, outfile);
987 fprintf_filtered (outfile, ")\n");
990 fprintf_filtered (outfile, " Relocate symbols by ");
991 for (i = 0; i < psymtab->objfile->num_sections; ++i)
994 fprintf_filtered (outfile, ", ");
996 fputs_filtered (paddress (gdbarch,
997 ANOFFSET (psymtab->section_offsets, i)),
1000 fprintf_filtered (outfile, "\n");
1002 fprintf_filtered (outfile, " Symbols cover text addresses ");
1003 fputs_filtered (paddress (gdbarch, psymtab->textlow), outfile);
1004 fprintf_filtered (outfile, "-");
1005 fputs_filtered (paddress (gdbarch, psymtab->texthigh), outfile);
1006 fprintf_filtered (outfile, "\n");
1007 fprintf_filtered (outfile, " Address map supported - %s.\n",
1008 psymtab->psymtabs_addrmap_supported ? "yes" : "no");
1009 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
1010 psymtab->number_of_dependencies);
1011 for (i = 0; i < psymtab->number_of_dependencies; i++)
1013 fprintf_filtered (outfile, " %d ", i);
1014 gdb_print_host_address (psymtab->dependencies[i], outfile);
1015 fprintf_filtered (outfile, " %s\n",
1016 psymtab->dependencies[i]->filename);
1018 if (psymtab->user != NULL)
1020 fprintf_filtered (outfile, " Shared partial symtab with user ");
1021 gdb_print_host_address (psymtab->user, outfile);
1022 fprintf_filtered (outfile, "\n");
1024 if (psymtab->n_global_syms > 0)
1026 print_partial_symbols (gdbarch,
1027 objfile->global_psymbols.list
1028 + psymtab->globals_offset,
1029 psymtab->n_global_syms, "Global", outfile);
1031 if (psymtab->n_static_syms > 0)
1033 print_partial_symbols (gdbarch,
1034 objfile->static_psymbols.list
1035 + psymtab->statics_offset,
1036 psymtab->n_static_syms, "Static", outfile);
1038 fprintf_filtered (outfile, "\n");
1042 print_psymtab_stats_for_objfile (struct objfile *objfile)
1045 struct partial_symtab *ps;
1048 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1050 if (ps->readin == 0)
1053 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i);
1057 dump_psymtabs_for_objfile (struct objfile *objfile)
1059 struct partial_symtab *psymtab;
1061 if (objfile->psymtabs)
1063 printf_filtered ("Psymtabs:\n");
1064 for (psymtab = objfile->psymtabs;
1066 psymtab = psymtab->next)
1068 printf_filtered ("%s at ",
1070 gdb_print_host_address (psymtab, gdb_stdout);
1071 printf_filtered (", ");
1072 if (psymtab->objfile != objfile)
1074 printf_filtered ("NOT ON CHAIN! ");
1078 printf_filtered ("\n\n");
1082 /* Look through the partial symtabs for all symbols which begin
1083 by matching FUNC_NAME. Make sure we read that symbol table in. */
1086 read_symtabs_for_function (struct objfile *objfile, const char *func_name)
1088 struct partial_symtab *ps;
1090 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1095 if ((lookup_partial_symbol (ps, func_name, 1, VAR_DOMAIN)
1097 || (lookup_partial_symbol (ps, func_name, 0, VAR_DOMAIN)
1099 psymtab_to_symtab (ps);
1104 expand_partial_symbol_tables (struct objfile *objfile)
1106 struct partial_symtab *psymtab;
1108 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
1110 psymtab_to_symtab (psymtab);
1115 read_psymtabs_with_filename (struct objfile *objfile, const char *filename)
1117 struct partial_symtab *p;
1119 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
1121 if (filename_cmp (filename, p->filename) == 0)
1122 psymtab_to_symtab (p);
1127 map_symbol_filenames_psymtab (struct objfile *objfile,
1128 symbol_filename_ftype *fun, void *data,
1131 struct partial_symtab *ps;
1133 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1135 const char *fullname;
1142 fullname = psymtab_to_fullname (ps);
1145 (*fun) (ps->filename, fullname, data);
1149 /* Finds the fullname that a partial_symtab represents.
1151 If this functions finds the fullname, it will save it in ps->fullname
1152 and it will also return the value.
1154 If this function fails to find the file that this partial_symtab represents,
1155 NULL will be returned and ps->fullname will be set to NULL. */
1158 psymtab_to_fullname (struct partial_symtab *ps)
1165 /* Use cached copy if we have it.
1166 We rely on forget_cached_source_info being called appropriately
1167 to handle cases like the file being moved. */
1169 return ps->fullname;
1171 r = find_and_open_source (ps->filename, ps->dirname, &ps->fullname);
1176 return ps->fullname;
1183 find_symbol_file_from_partial (struct objfile *objfile, const char *name)
1185 struct partial_symtab *pst;
1187 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
1189 if (lookup_partial_symbol (pst, name, 1, VAR_DOMAIN))
1190 return pst->filename;
1195 /* For all symbols, s, in BLOCK that are in NAMESPACE and match NAME
1196 according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
1197 BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK
1198 ever returns non-zero, and otherwise returns 0. */
1201 map_block (const char *name, domain_enum namespace, struct objfile *objfile,
1202 struct block *block,
1203 int (*callback) (struct block *, struct symbol *, void *),
1204 void *data, symbol_compare_ftype *match)
1206 struct block_iterator iter;
1209 for (sym = block_iter_match_first (block, name, match, &iter);
1210 sym != NULL; sym = block_iter_match_next (name, match, &iter))
1212 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
1213 SYMBOL_DOMAIN (sym), namespace))
1215 if (callback (block, sym, data))
1223 /* Psymtab version of map_matching_symbols. See its definition in
1224 the definition of quick_symbol_functions in symfile.h. */
1227 map_matching_symbols_psymtab (const char *name, domain_enum namespace,
1228 struct objfile *objfile, int global,
1229 int (*callback) (struct block *,
1230 struct symbol *, void *),
1232 symbol_compare_ftype *match,
1233 symbol_compare_ftype *ordered_compare)
1235 const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
1236 struct partial_symtab *ps;
1238 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1242 || match_partial_symbol (ps, global, name, namespace, match,
1245 struct symtab *s = psymtab_to_symtab (ps);
1246 struct block *block;
1248 if (s == NULL || !s->primary)
1250 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), block_kind);
1251 if (map_block (name, namespace, objfile, block,
1252 callback, data, match))
1254 if (callback (block, NULL, data))
1260 /* A helper for expand_symtabs_matching_via_partial that handles
1261 searching included psymtabs. This returns 1 if a symbol is found,
1262 and zero otherwise. It also updates the 'searched_flag' on the
1263 various psymtabs that it searches. */
1266 recursively_search_psymtabs (struct partial_symtab *ps,
1267 struct objfile *objfile,
1268 enum search_domain kind,
1269 int (*name_matcher) (const char *, void *),
1272 struct partial_symbol **psym;
1273 struct partial_symbol **bound, **gbound, **sbound;
1275 int result = PST_SEARCHED_AND_NOT_FOUND;
1278 if (ps->searched_flag != PST_NOT_SEARCHED)
1279 return ps->searched_flag == PST_SEARCHED_AND_FOUND;
1281 /* Recurse into shared psymtabs first, because they may have already
1282 been searched, and this could save some time. */
1283 for (i = 0; i < ps->number_of_dependencies; ++i)
1287 /* Skip non-shared dependencies, these are handled elsewhere. */
1288 if (ps->dependencies[i]->user == NULL)
1291 r = recursively_search_psymtabs (ps->dependencies[i],
1292 objfile, kind, name_matcher, data);
1295 ps->searched_flag = PST_SEARCHED_AND_FOUND;
1300 gbound = (objfile->global_psymbols.list
1301 + ps->globals_offset + ps->n_global_syms);
1302 sbound = (objfile->static_psymbols.list
1303 + ps->statics_offset + ps->n_static_syms);
1306 /* Go through all of the symbols stored in a partial
1307 symtab in one loop. */
1308 psym = objfile->global_psymbols.list + ps->globals_offset;
1313 if (bound == gbound && ps->n_static_syms != 0)
1315 psym = objfile->static_psymbols.list + ps->statics_offset;
1326 if ((kind == ALL_DOMAIN
1327 || (kind == VARIABLES_DOMAIN
1328 && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
1329 && SYMBOL_CLASS (*psym) != LOC_BLOCK)
1330 || (kind == FUNCTIONS_DOMAIN
1331 && SYMBOL_CLASS (*psym) == LOC_BLOCK)
1332 || (kind == TYPES_DOMAIN
1333 && SYMBOL_CLASS (*psym) == LOC_TYPEDEF))
1334 && (*name_matcher) (SYMBOL_SEARCH_NAME (*psym), data))
1336 /* Found a match, so notify our caller. */
1337 result = PST_SEARCHED_AND_FOUND;
1344 ps->searched_flag = result;
1345 return result == PST_SEARCHED_AND_FOUND;
1349 expand_symtabs_matching_via_partial
1350 (struct objfile *objfile,
1351 int (*file_matcher) (const char *, void *),
1352 int (*name_matcher) (const char *, void *),
1353 enum search_domain kind,
1356 struct partial_symtab *ps;
1358 /* Clear the search flags. */
1359 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1361 ps->searched_flag = PST_NOT_SEARCHED;
1364 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1369 /* We skip shared psymtabs because file-matching doesn't apply
1370 to them; but we search them later in the loop. */
1371 if (ps->user != NULL)
1374 if (file_matcher && ! (*file_matcher) (ps->filename, data))
1377 if (recursively_search_psymtabs (ps, objfile, kind, name_matcher, data))
1378 psymtab_to_symtab (ps);
1383 objfile_has_psyms (struct objfile *objfile)
1385 return objfile->psymtabs != NULL;
1388 const struct quick_symbol_functions psym_functions =
1391 find_last_source_symtab_from_partial,
1392 forget_cached_source_info_partial,
1393 partial_map_symtabs_matching_filename,
1394 lookup_symbol_aux_psymtabs,
1395 pre_expand_symtabs_matching_psymtabs,
1396 print_psymtab_stats_for_objfile,
1397 dump_psymtabs_for_objfile,
1399 read_symtabs_for_function,
1400 expand_partial_symbol_tables,
1401 read_psymtabs_with_filename,
1402 find_symbol_file_from_partial,
1403 map_matching_symbols_psymtab,
1404 expand_symtabs_matching_via_partial,
1405 find_pc_sect_symtab_from_partial,
1406 map_symbol_filenames_psymtab
1411 /* This compares two partial symbols by names, using strcmp_iw_ordered
1412 for the comparison. */
1415 compare_psymbols (const void *s1p, const void *s2p)
1417 struct partial_symbol *const *s1 = s1p;
1418 struct partial_symbol *const *s2 = s2p;
1420 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1),
1421 SYMBOL_SEARCH_NAME (*s2));
1425 sort_pst_symbols (struct partial_symtab *pst)
1427 /* Sort the global list; don't sort the static list. */
1429 qsort (pst->objfile->global_psymbols.list + pst->globals_offset,
1430 pst->n_global_syms, sizeof (struct partial_symbol *),
1434 /* Allocate and partially fill a partial symtab. It will be
1435 completely filled at the end of the symbol list.
1437 FILENAME is the name of the symbol-file we are reading from. */
1439 struct partial_symtab *
1440 start_psymtab_common (struct objfile *objfile,
1441 struct section_offsets *section_offsets,
1442 const char *filename,
1443 CORE_ADDR textlow, struct partial_symbol **global_syms,
1444 struct partial_symbol **static_syms)
1446 struct partial_symtab *psymtab;
1448 psymtab = allocate_psymtab (filename, objfile);
1449 psymtab->section_offsets = section_offsets;
1450 psymtab->textlow = textlow;
1451 psymtab->texthigh = psymtab->textlow; /* default */
1452 psymtab->globals_offset = global_syms - objfile->global_psymbols.list;
1453 psymtab->statics_offset = static_syms - objfile->static_psymbols.list;
1457 /* Calculate a hash code for the given partial symbol. The hash is
1458 calculated using the symbol's value, language, domain, class
1459 and name. These are the values which are set by
1460 add_psymbol_to_bcache. */
1462 static unsigned long
1463 psymbol_hash (const void *addr, int length)
1465 unsigned long h = 0;
1466 struct partial_symbol *psymbol = (struct partial_symbol *) addr;
1467 unsigned int lang = psymbol->ginfo.language;
1468 unsigned int domain = PSYMBOL_DOMAIN (psymbol);
1469 unsigned int class = PSYMBOL_CLASS (psymbol);
1471 h = hash_continue (&psymbol->ginfo.value, sizeof (psymbol->ginfo.value), h);
1472 h = hash_continue (&lang, sizeof (unsigned int), h);
1473 h = hash_continue (&domain, sizeof (unsigned int), h);
1474 h = hash_continue (&class, sizeof (unsigned int), h);
1475 h = hash_continue (psymbol->ginfo.name, strlen (psymbol->ginfo.name), h);
1480 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1481 For the comparison this function uses a symbols value,
1482 language, domain, class and name. */
1485 psymbol_compare (const void *addr1, const void *addr2, int length)
1487 struct partial_symbol *sym1 = (struct partial_symbol *) addr1;
1488 struct partial_symbol *sym2 = (struct partial_symbol *) addr2;
1490 return (memcmp (&sym1->ginfo.value, &sym1->ginfo.value,
1491 sizeof (sym1->ginfo.value)) == 0
1492 && sym1->ginfo.language == sym2->ginfo.language
1493 && PSYMBOL_DOMAIN (sym1) == PSYMBOL_DOMAIN (sym2)
1494 && PSYMBOL_CLASS (sym1) == PSYMBOL_CLASS (sym2)
1495 && sym1->ginfo.name == sym2->ginfo.name);
1498 /* Initialize a partial symbol bcache. */
1500 struct psymbol_bcache *
1501 psymbol_bcache_init (void)
1503 struct psymbol_bcache *bcache = XCALLOC (1, struct psymbol_bcache);
1504 bcache->bcache = bcache_xmalloc (psymbol_hash, psymbol_compare);
1508 /* Free a partial symbol bcache. */
1510 psymbol_bcache_free (struct psymbol_bcache *bcache)
1515 bcache_xfree (bcache->bcache);
1519 /* Return the internal bcache of the psymbol_bcache BCACHE. */
1522 psymbol_bcache_get_bcache (struct psymbol_bcache *bcache)
1524 return bcache->bcache;
1527 /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1528 symbol before, add a copy to BCACHE. In either case, return a pointer
1529 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1530 1 in case of new entry or 0 if returning an old entry. */
1532 static const struct partial_symbol *
1533 psymbol_bcache_full (struct partial_symbol *sym,
1534 struct psymbol_bcache *bcache,
1537 return bcache_full (sym,
1538 sizeof (struct partial_symbol),
1543 /* Helper function, initialises partial symbol structure and stashes
1544 it into objfile's bcache. Note that our caching mechanism will
1545 use all fields of struct partial_symbol to determine hash value of the
1546 structure. In other words, having two symbols with the same name but
1547 different domain (or address) is possible and correct. */
1549 static const struct partial_symbol *
1550 add_psymbol_to_bcache (const char *name, int namelength, int copy_name,
1552 enum address_class class,
1553 long val, /* Value as a long */
1554 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1555 enum language language, struct objfile *objfile,
1558 struct partial_symbol psymbol;
1560 /* We must ensure that the entire 'value' field has been zeroed
1561 before assigning to it, because an assignment may not write the
1563 memset (&psymbol.ginfo.value, 0, sizeof (psymbol.ginfo.value));
1565 /* val and coreaddr are mutually exclusive, one of them *will* be zero. */
1568 SYMBOL_VALUE (&psymbol) = val;
1572 SYMBOL_VALUE_ADDRESS (&psymbol) = coreaddr;
1574 SYMBOL_SECTION (&psymbol) = 0;
1575 SYMBOL_OBJ_SECTION (&psymbol) = NULL;
1576 SYMBOL_SET_LANGUAGE (&psymbol, language);
1577 PSYMBOL_DOMAIN (&psymbol) = domain;
1578 PSYMBOL_CLASS (&psymbol) = class;
1580 SYMBOL_SET_NAMES (&psymbol, name, namelength, copy_name, objfile);
1582 /* Stash the partial symbol away in the cache. */
1583 return psymbol_bcache_full (&psymbol,
1584 objfile->psymbol_cache,
1588 /* Increase the space allocated for LISTP, which is probably
1589 global_psymbols or static_psymbols. This space will eventually
1590 be freed in free_objfile(). */
1593 extend_psymbol_list (struct psymbol_allocation_list *listp,
1594 struct objfile *objfile)
1598 if (listp->size == 0)
1601 listp->list = (struct partial_symbol **)
1602 xmalloc (new_size * sizeof (struct partial_symbol *));
1606 new_size = listp->size * 2;
1607 listp->list = (struct partial_symbol **)
1608 xrealloc ((char *) listp->list,
1609 new_size * sizeof (struct partial_symbol *));
1611 /* Next assumes we only went one over. Should be good if
1612 program works correctly. */
1613 listp->next = listp->list + listp->size;
1614 listp->size = new_size;
1617 /* Helper function, adds partial symbol to the given partial symbol
1621 append_psymbol_to_list (struct psymbol_allocation_list *list,
1622 const struct partial_symbol *psym,
1623 struct objfile *objfile)
1625 if (list->next >= list->list + list->size)
1626 extend_psymbol_list (list, objfile);
1627 *list->next++ = (struct partial_symbol *) psym;
1628 OBJSTAT (objfile, n_psyms++);
1631 /* Add a symbol with a long value to a psymtab.
1632 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1633 Return the partial symbol that has been added. */
1636 add_psymbol_to_list (const char *name, int namelength, int copy_name,
1638 enum address_class class,
1639 struct psymbol_allocation_list *list,
1640 long val, /* Value as a long */
1641 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1642 enum language language, struct objfile *objfile)
1644 const struct partial_symbol *psym;
1648 /* Stash the partial symbol away in the cache. */
1649 psym = add_psymbol_to_bcache (name, namelength, copy_name, domain, class,
1650 val, coreaddr, language, objfile, &added);
1652 /* Do not duplicate global partial symbols. */
1653 if (list == &objfile->global_psymbols
1657 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1658 append_psymbol_to_list (list, psym, objfile);
1661 /* Initialize storage for partial symbols. */
1664 init_psymbol_list (struct objfile *objfile, int total_symbols)
1666 /* Free any previously allocated psymbol lists. */
1668 if (objfile->global_psymbols.list)
1670 xfree (objfile->global_psymbols.list);
1672 if (objfile->static_psymbols.list)
1674 xfree (objfile->static_psymbols.list);
1677 /* Current best guess is that approximately a twentieth
1678 of the total symbols (in a debugging file) are global or static
1679 oriented symbols. */
1681 objfile->global_psymbols.size = total_symbols / 10;
1682 objfile->static_psymbols.size = total_symbols / 10;
1684 if (objfile->global_psymbols.size > 0)
1686 objfile->global_psymbols.next =
1687 objfile->global_psymbols.list = (struct partial_symbol **)
1688 xmalloc ((objfile->global_psymbols.size
1689 * sizeof (struct partial_symbol *)));
1691 if (objfile->static_psymbols.size > 0)
1693 objfile->static_psymbols.next =
1694 objfile->static_psymbols.list = (struct partial_symbol **)
1695 xmalloc ((objfile->static_psymbols.size
1696 * sizeof (struct partial_symbol *)));
1700 struct partial_symtab *
1701 allocate_psymtab (const char *filename, struct objfile *objfile)
1703 struct partial_symtab *psymtab;
1705 if (objfile->free_psymtabs)
1707 psymtab = objfile->free_psymtabs;
1708 objfile->free_psymtabs = psymtab->next;
1711 psymtab = (struct partial_symtab *)
1712 obstack_alloc (&objfile->objfile_obstack,
1713 sizeof (struct partial_symtab));
1715 memset (psymtab, 0, sizeof (struct partial_symtab));
1716 psymtab->filename = obsavestring (filename, strlen (filename),
1717 &objfile->objfile_obstack);
1718 psymtab->symtab = NULL;
1720 /* Prepend it to the psymtab list for the objfile it belongs to.
1721 Psymtabs are searched in most recent inserted -> least recent
1724 psymtab->objfile = objfile;
1725 psymtab->next = objfile->psymtabs;
1726 objfile->psymtabs = psymtab;
1732 discard_psymtab (struct partial_symtab *pst)
1734 struct partial_symtab **prev_pst;
1737 Empty psymtabs happen as a result of header files which don't
1738 have any symbols in them. There can be a lot of them. But this
1739 check is wrong, in that a psymtab with N_SLINE entries but
1740 nothing else is not empty, but we don't realize that. Fixing
1741 that without slowing things down might be tricky. */
1743 /* First, snip it out of the psymtab chain. */
1745 prev_pst = &(pst->objfile->psymtabs);
1746 while ((*prev_pst) != pst)
1747 prev_pst = &((*prev_pst)->next);
1748 (*prev_pst) = pst->next;
1750 /* Next, put it on a free list for recycling. */
1752 pst->next = pst->objfile->free_psymtabs;
1753 pst->objfile->free_psymtabs = pst;
1759 maintenance_print_psymbols (char *args, int from_tty)
1762 struct ui_file *outfile;
1763 struct cleanup *cleanups;
1764 char *symname = NULL;
1765 char *filename = DEV_TTY;
1766 struct objfile *objfile;
1767 struct partial_symtab *ps;
1774 print-psymbols takes an output file name and optional symbol file name"));
1776 argv = gdb_buildargv (args);
1777 cleanups = make_cleanup_freeargv (argv);
1779 if (argv[0] != NULL)
1782 /* If a second arg is supplied, it is a source file name to match on. */
1783 if (argv[1] != NULL)
1789 filename = tilde_expand (filename);
1790 make_cleanup (xfree, filename);
1792 outfile = gdb_fopen (filename, FOPEN_WT);
1794 perror_with_name (filename);
1795 make_cleanup_ui_file_delete (outfile);
1798 ALL_PSYMTABS (objfile, ps)
1799 if (symname == NULL || filename_cmp (symname, ps->filename) == 0)
1800 dump_psymtab (objfile, ps, outfile);
1802 do_cleanups (cleanups);
1805 /* List all the partial symbol tables whose names match REGEXP (optional). */
1807 maintenance_info_psymtabs (char *regexp, int from_tty)
1809 struct program_space *pspace;
1810 struct objfile *objfile;
1815 ALL_PSPACES (pspace)
1816 ALL_PSPACE_OBJFILES (pspace, objfile)
1818 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1819 struct partial_symtab *psymtab;
1821 /* We don't want to print anything for this objfile until we
1822 actually find a symtab whose name matches. */
1823 int printed_objfile_start = 0;
1825 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
1830 || re_exec (psymtab->filename))
1832 if (! printed_objfile_start)
1834 printf_filtered ("{ objfile %s ", objfile->name);
1836 printf_filtered ("((struct objfile *) %s)\n",
1837 host_address_to_string (objfile));
1838 printed_objfile_start = 1;
1841 printf_filtered (" { psymtab %s ", psymtab->filename);
1843 printf_filtered ("((struct partial_symtab *) %s)\n",
1844 host_address_to_string (psymtab));
1846 printf_filtered (" readin %s\n",
1847 psymtab->readin ? "yes" : "no");
1848 printf_filtered (" fullname %s\n",
1850 ? psymtab->fullname : "(null)");
1851 printf_filtered (" text addresses ");
1852 fputs_filtered (paddress (gdbarch, psymtab->textlow),
1854 printf_filtered (" -- ");
1855 fputs_filtered (paddress (gdbarch, psymtab->texthigh),
1857 printf_filtered ("\n");
1858 printf_filtered (" psymtabs_addrmap_supported %s\n",
1859 (psymtab->psymtabs_addrmap_supported
1861 printf_filtered (" globals ");
1862 if (psymtab->n_global_syms)
1864 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1865 host_address_to_string (psymtab->objfile->global_psymbols.list
1866 + psymtab->globals_offset),
1867 psymtab->n_global_syms);
1870 printf_filtered ("(none)\n");
1871 printf_filtered (" statics ");
1872 if (psymtab->n_static_syms)
1874 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1875 host_address_to_string (psymtab->objfile->static_psymbols.list
1876 + psymtab->statics_offset),
1877 psymtab->n_static_syms);
1880 printf_filtered ("(none)\n");
1881 printf_filtered (" dependencies ");
1882 if (psymtab->number_of_dependencies)
1886 printf_filtered ("{\n");
1887 for (i = 0; i < psymtab->number_of_dependencies; i++)
1889 struct partial_symtab *dep = psymtab->dependencies[i];
1891 /* Note the string concatenation there --- no comma. */
1892 printf_filtered (" psymtab %s "
1893 "((struct partial_symtab *) %s)\n",
1895 host_address_to_string (dep));
1897 printf_filtered (" }\n");
1900 printf_filtered ("(none)\n");
1901 printf_filtered (" }\n");
1905 if (printed_objfile_start)
1906 printf_filtered ("}\n");
1910 /* Check consistency of psymtabs and symtabs. */
1913 maintenance_check_symtabs (char *ignore, int from_tty)
1916 struct partial_symbol **psym;
1917 struct symtab *s = NULL;
1918 struct partial_symtab *ps;
1919 struct blockvector *bv;
1920 struct objfile *objfile;
1924 ALL_PSYMTABS (objfile, ps)
1926 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1928 s = psymtab_to_symtab (ps);
1931 bv = BLOCKVECTOR (s);
1932 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1933 psym = ps->objfile->static_psymbols.list + ps->statics_offset;
1934 length = ps->n_static_syms;
1937 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1938 SYMBOL_DOMAIN (*psym));
1941 printf_filtered ("Static symbol `");
1942 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1943 printf_filtered ("' only found in ");
1944 puts_filtered (ps->filename);
1945 printf_filtered (" psymtab\n");
1949 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1950 psym = ps->objfile->global_psymbols.list + ps->globals_offset;
1951 length = ps->n_global_syms;
1954 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1955 SYMBOL_DOMAIN (*psym));
1958 printf_filtered ("Global symbol `");
1959 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1960 printf_filtered ("' only found in ");
1961 puts_filtered (ps->filename);
1962 printf_filtered (" psymtab\n");
1966 if (ps->texthigh < ps->textlow)
1968 printf_filtered ("Psymtab ");
1969 puts_filtered (ps->filename);
1970 printf_filtered (" covers bad range ");
1971 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
1972 printf_filtered (" - ");
1973 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
1974 printf_filtered ("\n");
1977 if (ps->texthigh == 0)
1979 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
1981 printf_filtered ("Psymtab ");
1982 puts_filtered (ps->filename);
1983 printf_filtered (" covers ");
1984 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
1985 printf_filtered (" - ");
1986 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
1987 printf_filtered (" but symtab covers only ");
1988 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
1989 printf_filtered (" - ");
1990 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout);
1991 printf_filtered ("\n");
1999 expand_partial_symbol_names (int (*fun) (const char *, void *),
2002 struct objfile *objfile;
2004 ALL_OBJFILES (objfile)
2007 objfile->sf->qf->expand_symtabs_matching (objfile, NULL, fun,
2013 map_partial_symbol_filenames (symbol_filename_ftype *fun, void *data,
2016 struct objfile *objfile;
2018 ALL_OBJFILES (objfile)
2021 objfile->sf->qf->map_symbol_filenames (objfile, fun, data,