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);
513 struct symtab *stab_best = NULL;
515 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
517 if (!ps->readin && lookup_partial_symbol (ps, name, psymtab_index, domain))
519 struct symbol *sym = NULL;
520 struct symtab *stab = psymtab_to_symtab (ps);
522 /* Some caution must be observed with overloaded functions
523 and methods, since the psymtab will not contain any overload
524 information (but NAME might contain it). */
527 struct blockvector *bv = BLOCKVECTOR (stab);
528 struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
530 sym = lookup_block_symbol (block, name, domain);
533 if (sym && strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0)
535 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
541 /* Keep looking through other psymtabs. */
548 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
549 the global block of PST if GLOBAL, and otherwise the static block.
550 MATCH is the comparison operation that returns true iff MATCH (s,
551 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
552 non-null, the symbols in the block are assumed to be ordered
553 according to it (allowing binary search). It must be compatible
554 with MATCH. Returns the symbol, if found, and otherwise NULL. */
556 static struct partial_symbol *
557 match_partial_symbol (struct partial_symtab *pst, int global,
558 const char *name, domain_enum domain,
559 symbol_compare_ftype *match,
560 symbol_compare_ftype *ordered_compare)
562 struct partial_symbol **start, **psym;
563 struct partial_symbol **top, **real_top, **bottom, **center;
564 int length = (global ? pst->n_global_syms : pst->n_static_syms);
565 int do_linear_search = 1;
570 pst->objfile->global_psymbols.list + pst->globals_offset :
571 pst->objfile->static_psymbols.list + pst->statics_offset);
573 if (global && ordered_compare) /* Can use a binary search. */
575 do_linear_search = 0;
577 /* Binary search. This search is guaranteed to end with center
578 pointing at the earliest partial symbol whose name might be
579 correct. At that point *all* partial symbols with an
580 appropriate name will be checked against the correct
584 top = start + length - 1;
588 center = bottom + (top - bottom) / 2;
589 gdb_assert (center < top);
590 if (!do_linear_search
591 && (SYMBOL_LANGUAGE (*center) == language_java))
592 do_linear_search = 1;
593 if (ordered_compare (SYMBOL_SEARCH_NAME (*center), name) >= 0)
598 gdb_assert (top == bottom);
600 while (top <= real_top
601 && match (SYMBOL_SEARCH_NAME (*top), name) == 0)
603 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
604 SYMBOL_DOMAIN (*top), domain))
610 /* Can't use a binary search or else we found during the binary search that
611 we should also do a linear search. */
613 if (do_linear_search)
615 for (psym = start; psym < start + length; psym++)
617 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
618 SYMBOL_DOMAIN (*psym), domain)
619 && match (SYMBOL_SEARCH_NAME (*psym), name) == 0)
628 pre_expand_symtabs_matching_psymtabs (struct objfile *objfile,
629 enum block_enum block_kind,
636 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
637 not contain any method/function instance information (since this would
638 force reading type information while reading psymtabs). Therefore,
639 if NAME contains overload information, it must be stripped before searching
642 The caller is responsible for freeing the return result. */
645 psymtab_search_name (const char *name)
647 switch (current_language->la_language)
652 if (strchr (name, '('))
654 char *ret = cp_remove_params (name);
666 return xstrdup (name);
669 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
670 Check the global symbols if GLOBAL, the static symbols if not. */
672 static struct partial_symbol *
673 lookup_partial_symbol (struct partial_symtab *pst, const char *name,
674 int global, domain_enum domain)
676 struct partial_symbol **start, **psym;
677 struct partial_symbol **top, **real_top, **bottom, **center;
678 int length = (global ? pst->n_global_syms : pst->n_static_syms);
679 int do_linear_search = 1;
681 struct cleanup *cleanup;
688 search_name = psymtab_search_name (name);
689 cleanup = make_cleanup (xfree, search_name);
691 pst->objfile->global_psymbols.list + pst->globals_offset :
692 pst->objfile->static_psymbols.list + pst->statics_offset);
694 if (global) /* This means we can use a binary search. */
696 do_linear_search = 0;
698 /* Binary search. This search is guaranteed to end with center
699 pointing at the earliest partial symbol whose name might be
700 correct. At that point *all* partial symbols with an
701 appropriate name will be checked against the correct
705 top = start + length - 1;
709 center = bottom + (top - bottom) / 2;
711 internal_error (__FILE__, __LINE__,
712 _("failed internal consistency check"));
713 if (!do_linear_search
714 && SYMBOL_LANGUAGE (*center) == language_java)
716 do_linear_search = 1;
718 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center),
728 if (!(top == bottom))
729 internal_error (__FILE__, __LINE__,
730 _("failed internal consistency check"));
732 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
733 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
734 while (top >= start && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
737 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
740 while (top <= real_top && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
742 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
743 SYMBOL_DOMAIN (*top), domain))
745 do_cleanups (cleanup);
752 /* Can't use a binary search or else we found during the binary search that
753 we should also do a linear search. */
755 if (do_linear_search)
757 for (psym = start; psym < start + length; psym++)
759 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
760 SYMBOL_DOMAIN (*psym), domain)
761 && SYMBOL_MATCHES_SEARCH_NAME (*psym, search_name))
763 do_cleanups (cleanup);
769 do_cleanups (cleanup);
773 /* Get the symbol table that corresponds to a partial_symtab.
774 This is fast after the first time you do it. */
776 static struct symtab *
777 psymtab_to_symtab (struct partial_symtab *pst)
779 /* If it is a shared psymtab, find an unshared psymtab that includes
780 it. Any such psymtab will do. */
781 while (pst->user != NULL)
784 /* If it's been looked up before, return it. */
788 /* If it has not yet been read in, read it. */
791 struct cleanup *back_to = increment_reading_symtab ();
793 (*pst->read_symtab) (pst);
794 do_cleanups (back_to);
801 relocate_psymtabs (struct objfile *objfile,
802 struct section_offsets *new_offsets,
803 struct section_offsets *delta)
805 struct partial_symbol **psym;
806 struct partial_symtab *p;
808 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
810 p->textlow += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
811 p->texthigh += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
814 for (psym = objfile->global_psymbols.list;
815 psym < objfile->global_psymbols.next;
818 fixup_psymbol_section (*psym, objfile);
819 if (SYMBOL_SECTION (*psym) >= 0)
820 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
821 SYMBOL_SECTION (*psym));
823 for (psym = objfile->static_psymbols.list;
824 psym < objfile->static_psymbols.next;
827 fixup_psymbol_section (*psym, objfile);
828 if (SYMBOL_SECTION (*psym) >= 0)
829 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
830 SYMBOL_SECTION (*psym));
834 static struct symtab *
835 find_last_source_symtab_from_partial (struct objfile *ofp)
837 struct partial_symtab *ps;
838 struct partial_symtab *cs_pst = 0;
840 ALL_OBJFILE_PSYMTABS_REQUIRED (ofp, ps)
842 const char *name = ps->filename;
843 int len = strlen (name);
845 if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0
846 || strcmp (name, "<<C++-namespaces>>") == 0)))
854 internal_error (__FILE__, __LINE__,
855 _("select_source_symtab: "
856 "readin pst found and no symtabs."));
859 return psymtab_to_symtab (cs_pst);
865 forget_cached_source_info_partial (struct objfile *objfile)
867 struct partial_symtab *pst;
869 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
871 if (pst->fullname != NULL)
873 xfree (pst->fullname);
874 pst->fullname = NULL;
880 print_partial_symbols (struct gdbarch *gdbarch,
881 struct partial_symbol **p, int count, char *what,
882 struct ui_file *outfile)
884 fprintf_filtered (outfile, " %s partial symbols:\n", what);
887 fprintf_filtered (outfile, " `%s'", SYMBOL_LINKAGE_NAME (*p));
888 if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
890 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
892 fputs_filtered (", ", outfile);
893 switch (SYMBOL_DOMAIN (*p))
896 fputs_filtered ("undefined domain, ", outfile);
899 /* This is the usual thing -- don't print it. */
902 fputs_filtered ("struct domain, ", outfile);
905 fputs_filtered ("label domain, ", outfile);
908 fputs_filtered ("<invalid domain>, ", outfile);
911 switch (SYMBOL_CLASS (*p))
914 fputs_filtered ("undefined", outfile);
917 fputs_filtered ("constant int", outfile);
920 fputs_filtered ("static", outfile);
923 fputs_filtered ("register", outfile);
926 fputs_filtered ("pass by value", outfile);
929 fputs_filtered ("pass by reference", outfile);
931 case LOC_REGPARM_ADDR:
932 fputs_filtered ("register address parameter", outfile);
935 fputs_filtered ("stack parameter", outfile);
938 fputs_filtered ("type", outfile);
941 fputs_filtered ("label", outfile);
944 fputs_filtered ("function", outfile);
946 case LOC_CONST_BYTES:
947 fputs_filtered ("constant bytes", outfile);
950 fputs_filtered ("unresolved", outfile);
952 case LOC_OPTIMIZED_OUT:
953 fputs_filtered ("optimized out", outfile);
956 fputs_filtered ("computed at runtime", outfile);
959 fputs_filtered ("<invalid location>", outfile);
962 fputs_filtered (", ", outfile);
963 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (*p)), outfile);
964 fprintf_filtered (outfile, "\n");
970 dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
971 struct ui_file *outfile)
973 struct gdbarch *gdbarch = get_objfile_arch (objfile);
976 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
978 fprintf_filtered (outfile, "(object ");
979 gdb_print_host_address (psymtab, outfile);
980 fprintf_filtered (outfile, ")\n\n");
981 fprintf_unfiltered (outfile, " Read from object file %s (",
983 gdb_print_host_address (objfile, outfile);
984 fprintf_unfiltered (outfile, ")\n");
988 fprintf_filtered (outfile,
989 " Full symtab was read (at ");
990 gdb_print_host_address (psymtab->symtab, outfile);
991 fprintf_filtered (outfile, " by function at ");
992 gdb_print_host_address (psymtab->read_symtab, outfile);
993 fprintf_filtered (outfile, ")\n");
996 fprintf_filtered (outfile, " Relocate symbols by ");
997 for (i = 0; i < psymtab->objfile->num_sections; ++i)
1000 fprintf_filtered (outfile, ", ");
1002 fputs_filtered (paddress (gdbarch,
1003 ANOFFSET (psymtab->section_offsets, i)),
1006 fprintf_filtered (outfile, "\n");
1008 fprintf_filtered (outfile, " Symbols cover text addresses ");
1009 fputs_filtered (paddress (gdbarch, psymtab->textlow), outfile);
1010 fprintf_filtered (outfile, "-");
1011 fputs_filtered (paddress (gdbarch, psymtab->texthigh), outfile);
1012 fprintf_filtered (outfile, "\n");
1013 fprintf_filtered (outfile, " Address map supported - %s.\n",
1014 psymtab->psymtabs_addrmap_supported ? "yes" : "no");
1015 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
1016 psymtab->number_of_dependencies);
1017 for (i = 0; i < psymtab->number_of_dependencies; i++)
1019 fprintf_filtered (outfile, " %d ", i);
1020 gdb_print_host_address (psymtab->dependencies[i], outfile);
1021 fprintf_filtered (outfile, " %s\n",
1022 psymtab->dependencies[i]->filename);
1024 if (psymtab->user != NULL)
1026 fprintf_filtered (outfile, " Shared partial symtab with user ");
1027 gdb_print_host_address (psymtab->user, outfile);
1028 fprintf_filtered (outfile, "\n");
1030 if (psymtab->n_global_syms > 0)
1032 print_partial_symbols (gdbarch,
1033 objfile->global_psymbols.list
1034 + psymtab->globals_offset,
1035 psymtab->n_global_syms, "Global", outfile);
1037 if (psymtab->n_static_syms > 0)
1039 print_partial_symbols (gdbarch,
1040 objfile->static_psymbols.list
1041 + psymtab->statics_offset,
1042 psymtab->n_static_syms, "Static", outfile);
1044 fprintf_filtered (outfile, "\n");
1048 print_psymtab_stats_for_objfile (struct objfile *objfile)
1051 struct partial_symtab *ps;
1054 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1056 if (ps->readin == 0)
1059 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i);
1063 dump_psymtabs_for_objfile (struct objfile *objfile)
1065 struct partial_symtab *psymtab;
1067 if (objfile->psymtabs)
1069 printf_filtered ("Psymtabs:\n");
1070 for (psymtab = objfile->psymtabs;
1072 psymtab = psymtab->next)
1074 printf_filtered ("%s at ",
1076 gdb_print_host_address (psymtab, gdb_stdout);
1077 printf_filtered (", ");
1078 if (psymtab->objfile != objfile)
1080 printf_filtered ("NOT ON CHAIN! ");
1084 printf_filtered ("\n\n");
1088 /* Look through the partial symtabs for all symbols which begin
1089 by matching FUNC_NAME. Make sure we read that symbol table in. */
1092 read_symtabs_for_function (struct objfile *objfile, const char *func_name)
1094 struct partial_symtab *ps;
1096 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1101 if ((lookup_partial_symbol (ps, func_name, 1, VAR_DOMAIN)
1103 || (lookup_partial_symbol (ps, func_name, 0, VAR_DOMAIN)
1105 psymtab_to_symtab (ps);
1110 expand_partial_symbol_tables (struct objfile *objfile)
1112 struct partial_symtab *psymtab;
1114 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
1116 psymtab_to_symtab (psymtab);
1121 read_psymtabs_with_filename (struct objfile *objfile, const char *filename)
1123 struct partial_symtab *p;
1125 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
1127 if (filename_cmp (filename, p->filename) == 0)
1128 psymtab_to_symtab (p);
1133 map_symbol_filenames_psymtab (struct objfile *objfile,
1134 symbol_filename_ftype *fun, void *data,
1137 struct partial_symtab *ps;
1139 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1141 const char *fullname;
1148 fullname = psymtab_to_fullname (ps);
1151 (*fun) (ps->filename, fullname, data);
1155 /* Finds the fullname that a partial_symtab represents.
1157 If this functions finds the fullname, it will save it in ps->fullname
1158 and it will also return the value.
1160 If this function fails to find the file that this partial_symtab represents,
1161 NULL will be returned and ps->fullname will be set to NULL. */
1164 psymtab_to_fullname (struct partial_symtab *ps)
1171 /* Use cached copy if we have it.
1172 We rely on forget_cached_source_info being called appropriately
1173 to handle cases like the file being moved. */
1175 return ps->fullname;
1177 r = find_and_open_source (ps->filename, ps->dirname, &ps->fullname);
1182 return ps->fullname;
1189 find_symbol_file_from_partial (struct objfile *objfile, const char *name)
1191 struct partial_symtab *pst;
1193 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
1195 if (lookup_partial_symbol (pst, name, 1, VAR_DOMAIN))
1196 return pst->filename;
1201 /* For all symbols, s, in BLOCK that are in NAMESPACE and match NAME
1202 according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
1203 BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK
1204 ever returns non-zero, and otherwise returns 0. */
1207 map_block (const char *name, domain_enum namespace, struct objfile *objfile,
1208 struct block *block,
1209 int (*callback) (struct block *, struct symbol *, void *),
1210 void *data, symbol_compare_ftype *match)
1212 struct block_iterator iter;
1215 for (sym = block_iter_match_first (block, name, match, &iter);
1216 sym != NULL; sym = block_iter_match_next (name, match, &iter))
1218 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
1219 SYMBOL_DOMAIN (sym), namespace))
1221 if (callback (block, sym, data))
1229 /* Psymtab version of map_matching_symbols. See its definition in
1230 the definition of quick_symbol_functions in symfile.h. */
1233 map_matching_symbols_psymtab (const char *name, domain_enum namespace,
1234 struct objfile *objfile, int global,
1235 int (*callback) (struct block *,
1236 struct symbol *, void *),
1238 symbol_compare_ftype *match,
1239 symbol_compare_ftype *ordered_compare)
1241 const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
1242 struct partial_symtab *ps;
1244 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1248 || match_partial_symbol (ps, global, name, namespace, match,
1251 struct symtab *s = psymtab_to_symtab (ps);
1252 struct block *block;
1254 if (s == NULL || !s->primary)
1256 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), block_kind);
1257 if (map_block (name, namespace, objfile, block,
1258 callback, data, match))
1260 if (callback (block, NULL, data))
1266 /* A helper for expand_symtabs_matching_via_partial that handles
1267 searching included psymtabs. This returns 1 if a symbol is found,
1268 and zero otherwise. It also updates the 'searched_flag' on the
1269 various psymtabs that it searches. */
1272 recursively_search_psymtabs (struct partial_symtab *ps,
1273 struct objfile *objfile,
1274 enum search_domain kind,
1275 int (*name_matcher) (const char *, void *),
1278 struct partial_symbol **psym;
1279 struct partial_symbol **bound, **gbound, **sbound;
1281 int result = PST_SEARCHED_AND_NOT_FOUND;
1284 if (ps->searched_flag != PST_NOT_SEARCHED)
1285 return ps->searched_flag == PST_SEARCHED_AND_FOUND;
1287 /* Recurse into shared psymtabs first, because they may have already
1288 been searched, and this could save some time. */
1289 for (i = 0; i < ps->number_of_dependencies; ++i)
1293 /* Skip non-shared dependencies, these are handled elsewhere. */
1294 if (ps->dependencies[i]->user == NULL)
1297 r = recursively_search_psymtabs (ps->dependencies[i],
1298 objfile, kind, name_matcher, data);
1301 ps->searched_flag = PST_SEARCHED_AND_FOUND;
1306 gbound = (objfile->global_psymbols.list
1307 + ps->globals_offset + ps->n_global_syms);
1308 sbound = (objfile->static_psymbols.list
1309 + ps->statics_offset + ps->n_static_syms);
1312 /* Go through all of the symbols stored in a partial
1313 symtab in one loop. */
1314 psym = objfile->global_psymbols.list + ps->globals_offset;
1319 if (bound == gbound && ps->n_static_syms != 0)
1321 psym = objfile->static_psymbols.list + ps->statics_offset;
1332 if ((kind == ALL_DOMAIN
1333 || (kind == VARIABLES_DOMAIN
1334 && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
1335 && SYMBOL_CLASS (*psym) != LOC_BLOCK)
1336 || (kind == FUNCTIONS_DOMAIN
1337 && SYMBOL_CLASS (*psym) == LOC_BLOCK)
1338 || (kind == TYPES_DOMAIN
1339 && SYMBOL_CLASS (*psym) == LOC_TYPEDEF))
1340 && (*name_matcher) (SYMBOL_SEARCH_NAME (*psym), data))
1342 /* Found a match, so notify our caller. */
1343 result = PST_SEARCHED_AND_FOUND;
1350 ps->searched_flag = result;
1351 return result == PST_SEARCHED_AND_FOUND;
1355 expand_symtabs_matching_via_partial
1356 (struct objfile *objfile,
1357 int (*file_matcher) (const char *, void *),
1358 int (*name_matcher) (const char *, void *),
1359 enum search_domain kind,
1362 struct partial_symtab *ps;
1364 /* Clear the search flags. */
1365 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1367 ps->searched_flag = PST_NOT_SEARCHED;
1370 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1375 /* We skip shared psymtabs because file-matching doesn't apply
1376 to them; but we search them later in the loop. */
1377 if (ps->user != NULL)
1380 if (file_matcher && ! (*file_matcher) (ps->filename, data))
1383 if (recursively_search_psymtabs (ps, objfile, kind, name_matcher, data))
1384 psymtab_to_symtab (ps);
1389 objfile_has_psyms (struct objfile *objfile)
1391 return objfile->psymtabs != NULL;
1394 const struct quick_symbol_functions psym_functions =
1397 find_last_source_symtab_from_partial,
1398 forget_cached_source_info_partial,
1399 partial_map_symtabs_matching_filename,
1400 lookup_symbol_aux_psymtabs,
1401 pre_expand_symtabs_matching_psymtabs,
1402 print_psymtab_stats_for_objfile,
1403 dump_psymtabs_for_objfile,
1405 read_symtabs_for_function,
1406 expand_partial_symbol_tables,
1407 read_psymtabs_with_filename,
1408 find_symbol_file_from_partial,
1409 map_matching_symbols_psymtab,
1410 expand_symtabs_matching_via_partial,
1411 find_pc_sect_symtab_from_partial,
1412 map_symbol_filenames_psymtab
1417 /* This compares two partial symbols by names, using strcmp_iw_ordered
1418 for the comparison. */
1421 compare_psymbols (const void *s1p, const void *s2p)
1423 struct partial_symbol *const *s1 = s1p;
1424 struct partial_symbol *const *s2 = s2p;
1426 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1),
1427 SYMBOL_SEARCH_NAME (*s2));
1431 sort_pst_symbols (struct partial_symtab *pst)
1433 /* Sort the global list; don't sort the static list. */
1435 qsort (pst->objfile->global_psymbols.list + pst->globals_offset,
1436 pst->n_global_syms, sizeof (struct partial_symbol *),
1440 /* Allocate and partially fill a partial symtab. It will be
1441 completely filled at the end of the symbol list.
1443 FILENAME is the name of the symbol-file we are reading from. */
1445 struct partial_symtab *
1446 start_psymtab_common (struct objfile *objfile,
1447 struct section_offsets *section_offsets,
1448 const char *filename,
1449 CORE_ADDR textlow, struct partial_symbol **global_syms,
1450 struct partial_symbol **static_syms)
1452 struct partial_symtab *psymtab;
1454 psymtab = allocate_psymtab (filename, objfile);
1455 psymtab->section_offsets = section_offsets;
1456 psymtab->textlow = textlow;
1457 psymtab->texthigh = psymtab->textlow; /* default */
1458 psymtab->globals_offset = global_syms - objfile->global_psymbols.list;
1459 psymtab->statics_offset = static_syms - objfile->static_psymbols.list;
1463 /* Calculate a hash code for the given partial symbol. The hash is
1464 calculated using the symbol's value, language, domain, class
1465 and name. These are the values which are set by
1466 add_psymbol_to_bcache. */
1468 static unsigned long
1469 psymbol_hash (const void *addr, int length)
1471 unsigned long h = 0;
1472 struct partial_symbol *psymbol = (struct partial_symbol *) addr;
1473 unsigned int lang = psymbol->ginfo.language;
1474 unsigned int domain = PSYMBOL_DOMAIN (psymbol);
1475 unsigned int class = PSYMBOL_CLASS (psymbol);
1477 h = hash_continue (&psymbol->ginfo.value, sizeof (psymbol->ginfo.value), h);
1478 h = hash_continue (&lang, sizeof (unsigned int), h);
1479 h = hash_continue (&domain, sizeof (unsigned int), h);
1480 h = hash_continue (&class, sizeof (unsigned int), h);
1481 h = hash_continue (psymbol->ginfo.name, strlen (psymbol->ginfo.name), h);
1486 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1487 For the comparison this function uses a symbols value,
1488 language, domain, class and name. */
1491 psymbol_compare (const void *addr1, const void *addr2, int length)
1493 struct partial_symbol *sym1 = (struct partial_symbol *) addr1;
1494 struct partial_symbol *sym2 = (struct partial_symbol *) addr2;
1496 return (memcmp (&sym1->ginfo.value, &sym1->ginfo.value,
1497 sizeof (sym1->ginfo.value)) == 0
1498 && sym1->ginfo.language == sym2->ginfo.language
1499 && PSYMBOL_DOMAIN (sym1) == PSYMBOL_DOMAIN (sym2)
1500 && PSYMBOL_CLASS (sym1) == PSYMBOL_CLASS (sym2)
1501 && sym1->ginfo.name == sym2->ginfo.name);
1504 /* Initialize a partial symbol bcache. */
1506 struct psymbol_bcache *
1507 psymbol_bcache_init (void)
1509 struct psymbol_bcache *bcache = XCALLOC (1, struct psymbol_bcache);
1510 bcache->bcache = bcache_xmalloc (psymbol_hash, psymbol_compare);
1514 /* Free a partial symbol bcache. */
1516 psymbol_bcache_free (struct psymbol_bcache *bcache)
1521 bcache_xfree (bcache->bcache);
1525 /* Return the internal bcache of the psymbol_bcache BCACHE. */
1528 psymbol_bcache_get_bcache (struct psymbol_bcache *bcache)
1530 return bcache->bcache;
1533 /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1534 symbol before, add a copy to BCACHE. In either case, return a pointer
1535 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1536 1 in case of new entry or 0 if returning an old entry. */
1538 static const struct partial_symbol *
1539 psymbol_bcache_full (struct partial_symbol *sym,
1540 struct psymbol_bcache *bcache,
1543 return bcache_full (sym,
1544 sizeof (struct partial_symbol),
1549 /* Helper function, initialises partial symbol structure and stashes
1550 it into objfile's bcache. Note that our caching mechanism will
1551 use all fields of struct partial_symbol to determine hash value of the
1552 structure. In other words, having two symbols with the same name but
1553 different domain (or address) is possible and correct. */
1555 static const struct partial_symbol *
1556 add_psymbol_to_bcache (const char *name, int namelength, int copy_name,
1558 enum address_class class,
1559 long val, /* Value as a long */
1560 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1561 enum language language, struct objfile *objfile,
1564 struct partial_symbol psymbol;
1566 /* We must ensure that the entire 'value' field has been zeroed
1567 before assigning to it, because an assignment may not write the
1569 memset (&psymbol.ginfo.value, 0, sizeof (psymbol.ginfo.value));
1571 /* val and coreaddr are mutually exclusive, one of them *will* be zero. */
1574 SYMBOL_VALUE (&psymbol) = val;
1578 SYMBOL_VALUE_ADDRESS (&psymbol) = coreaddr;
1580 SYMBOL_SECTION (&psymbol) = 0;
1581 SYMBOL_OBJ_SECTION (&psymbol) = NULL;
1582 SYMBOL_SET_LANGUAGE (&psymbol, language);
1583 PSYMBOL_DOMAIN (&psymbol) = domain;
1584 PSYMBOL_CLASS (&psymbol) = class;
1586 SYMBOL_SET_NAMES (&psymbol, name, namelength, copy_name, objfile);
1588 /* Stash the partial symbol away in the cache. */
1589 return psymbol_bcache_full (&psymbol,
1590 objfile->psymbol_cache,
1594 /* Increase the space allocated for LISTP, which is probably
1595 global_psymbols or static_psymbols. This space will eventually
1596 be freed in free_objfile(). */
1599 extend_psymbol_list (struct psymbol_allocation_list *listp,
1600 struct objfile *objfile)
1604 if (listp->size == 0)
1607 listp->list = (struct partial_symbol **)
1608 xmalloc (new_size * sizeof (struct partial_symbol *));
1612 new_size = listp->size * 2;
1613 listp->list = (struct partial_symbol **)
1614 xrealloc ((char *) listp->list,
1615 new_size * sizeof (struct partial_symbol *));
1617 /* Next assumes we only went one over. Should be good if
1618 program works correctly. */
1619 listp->next = listp->list + listp->size;
1620 listp->size = new_size;
1623 /* Helper function, adds partial symbol to the given partial symbol
1627 append_psymbol_to_list (struct psymbol_allocation_list *list,
1628 const struct partial_symbol *psym,
1629 struct objfile *objfile)
1631 if (list->next >= list->list + list->size)
1632 extend_psymbol_list (list, objfile);
1633 *list->next++ = (struct partial_symbol *) psym;
1634 OBJSTAT (objfile, n_psyms++);
1637 /* Add a symbol with a long value to a psymtab.
1638 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1639 Return the partial symbol that has been added. */
1642 add_psymbol_to_list (const char *name, int namelength, int copy_name,
1644 enum address_class class,
1645 struct psymbol_allocation_list *list,
1646 long val, /* Value as a long */
1647 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1648 enum language language, struct objfile *objfile)
1650 const struct partial_symbol *psym;
1654 /* Stash the partial symbol away in the cache. */
1655 psym = add_psymbol_to_bcache (name, namelength, copy_name, domain, class,
1656 val, coreaddr, language, objfile, &added);
1658 /* Do not duplicate global partial symbols. */
1659 if (list == &objfile->global_psymbols
1663 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1664 append_psymbol_to_list (list, psym, objfile);
1667 /* Initialize storage for partial symbols. */
1670 init_psymbol_list (struct objfile *objfile, int total_symbols)
1672 /* Free any previously allocated psymbol lists. */
1674 if (objfile->global_psymbols.list)
1676 xfree (objfile->global_psymbols.list);
1678 if (objfile->static_psymbols.list)
1680 xfree (objfile->static_psymbols.list);
1683 /* Current best guess is that approximately a twentieth
1684 of the total symbols (in a debugging file) are global or static
1685 oriented symbols. */
1687 objfile->global_psymbols.size = total_symbols / 10;
1688 objfile->static_psymbols.size = total_symbols / 10;
1690 if (objfile->global_psymbols.size > 0)
1692 objfile->global_psymbols.next =
1693 objfile->global_psymbols.list = (struct partial_symbol **)
1694 xmalloc ((objfile->global_psymbols.size
1695 * sizeof (struct partial_symbol *)));
1697 if (objfile->static_psymbols.size > 0)
1699 objfile->static_psymbols.next =
1700 objfile->static_psymbols.list = (struct partial_symbol **)
1701 xmalloc ((objfile->static_psymbols.size
1702 * sizeof (struct partial_symbol *)));
1706 struct partial_symtab *
1707 allocate_psymtab (const char *filename, struct objfile *objfile)
1709 struct partial_symtab *psymtab;
1711 if (objfile->free_psymtabs)
1713 psymtab = objfile->free_psymtabs;
1714 objfile->free_psymtabs = psymtab->next;
1717 psymtab = (struct partial_symtab *)
1718 obstack_alloc (&objfile->objfile_obstack,
1719 sizeof (struct partial_symtab));
1721 memset (psymtab, 0, sizeof (struct partial_symtab));
1722 psymtab->filename = obsavestring (filename, strlen (filename),
1723 &objfile->objfile_obstack);
1724 psymtab->symtab = NULL;
1726 /* Prepend it to the psymtab list for the objfile it belongs to.
1727 Psymtabs are searched in most recent inserted -> least recent
1730 psymtab->objfile = objfile;
1731 psymtab->next = objfile->psymtabs;
1732 objfile->psymtabs = psymtab;
1738 discard_psymtab (struct partial_symtab *pst)
1740 struct partial_symtab **prev_pst;
1743 Empty psymtabs happen as a result of header files which don't
1744 have any symbols in them. There can be a lot of them. But this
1745 check is wrong, in that a psymtab with N_SLINE entries but
1746 nothing else is not empty, but we don't realize that. Fixing
1747 that without slowing things down might be tricky. */
1749 /* First, snip it out of the psymtab chain. */
1751 prev_pst = &(pst->objfile->psymtabs);
1752 while ((*prev_pst) != pst)
1753 prev_pst = &((*prev_pst)->next);
1754 (*prev_pst) = pst->next;
1756 /* Next, put it on a free list for recycling. */
1758 pst->next = pst->objfile->free_psymtabs;
1759 pst->objfile->free_psymtabs = pst;
1765 maintenance_print_psymbols (char *args, int from_tty)
1768 struct ui_file *outfile;
1769 struct cleanup *cleanups;
1770 char *symname = NULL;
1771 char *filename = DEV_TTY;
1772 struct objfile *objfile;
1773 struct partial_symtab *ps;
1780 print-psymbols takes an output file name and optional symbol file name"));
1782 argv = gdb_buildargv (args);
1783 cleanups = make_cleanup_freeargv (argv);
1785 if (argv[0] != NULL)
1788 /* If a second arg is supplied, it is a source file name to match on. */
1789 if (argv[1] != NULL)
1795 filename = tilde_expand (filename);
1796 make_cleanup (xfree, filename);
1798 outfile = gdb_fopen (filename, FOPEN_WT);
1800 perror_with_name (filename);
1801 make_cleanup_ui_file_delete (outfile);
1804 ALL_PSYMTABS (objfile, ps)
1805 if (symname == NULL || filename_cmp (symname, ps->filename) == 0)
1806 dump_psymtab (objfile, ps, outfile);
1808 do_cleanups (cleanups);
1811 /* List all the partial symbol tables whose names match REGEXP (optional). */
1813 maintenance_info_psymtabs (char *regexp, int from_tty)
1815 struct program_space *pspace;
1816 struct objfile *objfile;
1821 ALL_PSPACES (pspace)
1822 ALL_PSPACE_OBJFILES (pspace, objfile)
1824 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1825 struct partial_symtab *psymtab;
1827 /* We don't want to print anything for this objfile until we
1828 actually find a symtab whose name matches. */
1829 int printed_objfile_start = 0;
1831 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
1836 || re_exec (psymtab->filename))
1838 if (! printed_objfile_start)
1840 printf_filtered ("{ objfile %s ", objfile->name);
1842 printf_filtered ("((struct objfile *) %s)\n",
1843 host_address_to_string (objfile));
1844 printed_objfile_start = 1;
1847 printf_filtered (" { psymtab %s ", psymtab->filename);
1849 printf_filtered ("((struct partial_symtab *) %s)\n",
1850 host_address_to_string (psymtab));
1852 printf_filtered (" readin %s\n",
1853 psymtab->readin ? "yes" : "no");
1854 printf_filtered (" fullname %s\n",
1856 ? psymtab->fullname : "(null)");
1857 printf_filtered (" text addresses ");
1858 fputs_filtered (paddress (gdbarch, psymtab->textlow),
1860 printf_filtered (" -- ");
1861 fputs_filtered (paddress (gdbarch, psymtab->texthigh),
1863 printf_filtered ("\n");
1864 printf_filtered (" psymtabs_addrmap_supported %s\n",
1865 (psymtab->psymtabs_addrmap_supported
1867 printf_filtered (" globals ");
1868 if (psymtab->n_global_syms)
1870 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1871 host_address_to_string (psymtab->objfile->global_psymbols.list
1872 + psymtab->globals_offset),
1873 psymtab->n_global_syms);
1876 printf_filtered ("(none)\n");
1877 printf_filtered (" statics ");
1878 if (psymtab->n_static_syms)
1880 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1881 host_address_to_string (psymtab->objfile->static_psymbols.list
1882 + psymtab->statics_offset),
1883 psymtab->n_static_syms);
1886 printf_filtered ("(none)\n");
1887 printf_filtered (" dependencies ");
1888 if (psymtab->number_of_dependencies)
1892 printf_filtered ("{\n");
1893 for (i = 0; i < psymtab->number_of_dependencies; i++)
1895 struct partial_symtab *dep = psymtab->dependencies[i];
1897 /* Note the string concatenation there --- no comma. */
1898 printf_filtered (" psymtab %s "
1899 "((struct partial_symtab *) %s)\n",
1901 host_address_to_string (dep));
1903 printf_filtered (" }\n");
1906 printf_filtered ("(none)\n");
1907 printf_filtered (" }\n");
1911 if (printed_objfile_start)
1912 printf_filtered ("}\n");
1916 /* Check consistency of psymtabs and symtabs. */
1919 maintenance_check_symtabs (char *ignore, int from_tty)
1922 struct partial_symbol **psym;
1923 struct symtab *s = NULL;
1924 struct partial_symtab *ps;
1925 struct blockvector *bv;
1926 struct objfile *objfile;
1930 ALL_PSYMTABS (objfile, ps)
1932 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1934 s = psymtab_to_symtab (ps);
1937 bv = BLOCKVECTOR (s);
1938 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1939 psym = ps->objfile->static_psymbols.list + ps->statics_offset;
1940 length = ps->n_static_syms;
1943 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1944 SYMBOL_DOMAIN (*psym));
1947 printf_filtered ("Static symbol `");
1948 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1949 printf_filtered ("' only found in ");
1950 puts_filtered (ps->filename);
1951 printf_filtered (" psymtab\n");
1955 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1956 psym = ps->objfile->global_psymbols.list + ps->globals_offset;
1957 length = ps->n_global_syms;
1960 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1961 SYMBOL_DOMAIN (*psym));
1964 printf_filtered ("Global symbol `");
1965 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1966 printf_filtered ("' only found in ");
1967 puts_filtered (ps->filename);
1968 printf_filtered (" psymtab\n");
1972 if (ps->texthigh < ps->textlow)
1974 printf_filtered ("Psymtab ");
1975 puts_filtered (ps->filename);
1976 printf_filtered (" covers bad range ");
1977 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
1978 printf_filtered (" - ");
1979 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
1980 printf_filtered ("\n");
1983 if (ps->texthigh == 0)
1985 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
1987 printf_filtered ("Psymtab ");
1988 puts_filtered (ps->filename);
1989 printf_filtered (" covers ");
1990 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
1991 printf_filtered (" - ");
1992 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
1993 printf_filtered (" but symtab covers only ");
1994 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
1995 printf_filtered (" - ");
1996 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout);
1997 printf_filtered ("\n");
2005 expand_partial_symbol_names (int (*fun) (const char *, void *),
2008 struct objfile *objfile;
2010 ALL_OBJFILES (objfile)
2013 objfile->sf->qf->expand_symtabs_matching (objfile, NULL, fun,
2019 map_partial_symbol_filenames (symbol_filename_ftype *fun, void *data,
2022 struct objfile *objfile;
2024 ALL_OBJFILES (objfile)
2027 objfile->sf->qf->map_symbol_filenames (objfile, fun, data,