1 /* Partial symbol tables.
3 Copyright (C) 2009-2013 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"
41 #define DEV_TTY "/dev/tty"
46 struct bcache *bcache;
49 static struct partial_symbol *match_partial_symbol (struct objfile *,
50 struct partial_symtab *,
52 const char *, domain_enum,
53 symbol_compare_ftype *,
54 symbol_compare_ftype *);
56 static struct partial_symbol *lookup_partial_symbol (struct objfile *,
57 struct partial_symtab *,
61 static const char *psymtab_to_fullname (struct partial_symtab *ps);
63 static struct partial_symbol *find_pc_sect_psymbol (struct objfile *,
64 struct partial_symtab *,
66 struct obj_section *);
68 static void fixup_psymbol_section (struct partial_symbol *psym,
69 struct objfile *objfile);
71 static struct symtab *psymtab_to_symtab (struct objfile *objfile,
72 struct partial_symtab *pst);
74 /* Ensure that the partial symbols for OBJFILE have been loaded. This
75 function always returns its argument, as a convenience. */
78 require_partial_symbols (struct objfile *objfile, int verbose)
80 if ((objfile->flags & OBJF_PSYMTABS_READ) == 0)
82 objfile->flags |= OBJF_PSYMTABS_READ;
84 if (objfile->sf->sym_read_psymbols)
88 printf_unfiltered (_("Reading symbols from %s..."),
90 gdb_flush (gdb_stdout);
92 (*objfile->sf->sym_read_psymbols) (objfile);
95 if (!objfile_has_symbols (objfile))
98 printf_unfiltered (_("(no debugging symbols found)..."));
102 printf_unfiltered (_("done.\n"));
110 /* Traverse all psymtabs in one objfile, requiring that the psymtabs
113 #define ALL_OBJFILE_PSYMTABS_REQUIRED(objfile, p) \
114 for ((p) = require_partial_symbols (objfile, 1)->psymtabs; \
118 /* We want to make sure this file always requires psymtabs. */
120 #undef ALL_OBJFILE_PSYMTABS
122 /* Traverse all psymtabs in all objfiles. */
124 #define ALL_PSYMTABS(objfile, p) \
125 ALL_OBJFILES (objfile) \
126 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
128 /* Helper function for partial_map_symtabs_matching_filename that
129 expands the symtabs and calls the iterator. */
132 partial_map_expand_apply (struct objfile *objfile,
134 const char *real_path,
135 struct partial_symtab *pst,
136 int (*callback) (struct symtab *, void *),
139 struct symtab *last_made = objfile->symtabs;
141 /* Shared psymtabs should never be seen here. Instead they should
142 be handled properly by the caller. */
143 gdb_assert (pst->user == NULL);
145 /* Don't visit already-expanded psymtabs. */
149 /* This may expand more than one symtab, and we want to iterate over
151 psymtab_to_symtab (objfile, pst);
153 return iterate_over_some_symtabs (name, real_path, callback, data,
154 objfile->symtabs, last_made);
157 /* Implementation of the map_symtabs_matching_filename method. */
160 partial_map_symtabs_matching_filename (struct objfile *objfile,
162 const char *real_path,
163 int (*callback) (struct symtab *,
167 struct partial_symtab *pst;
168 const char *name_basename = lbasename (name);
169 int is_abs = IS_ABSOLUTE_PATH (name);
171 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
173 /* We can skip shared psymtabs here, because any file name will be
174 attached to the unshared psymtab. */
175 if (pst->user != NULL)
178 /* Anonymous psymtabs don't have a file name. */
182 if (FILENAME_CMP (name, pst->filename) == 0
183 || (!is_abs && compare_filenames_for_search (pst->filename, name)))
185 if (partial_map_expand_apply (objfile, name, real_path,
186 pst, callback, data))
190 /* Before we invoke realpath, which can get expensive when many
191 files are involved, do a quick comparison of the basenames. */
192 if (! basenames_may_differ
193 && FILENAME_CMP (name_basename, lbasename (pst->filename)) != 0)
196 /* If the user gave us an absolute path, try to find the file in
197 this symtab and use its absolute path. */
198 if (real_path != NULL)
200 psymtab_to_fullname (pst);
201 if (pst->fullname != NULL
202 && (FILENAME_CMP (real_path, pst->fullname) == 0
203 || (!is_abs && compare_filenames_for_search (real_path, name))))
205 if (partial_map_expand_apply (objfile, name, real_path,
206 pst, callback, data))
215 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
216 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
218 static struct partial_symtab *
219 find_pc_sect_psymtab_closer (struct objfile *objfile,
220 CORE_ADDR pc, struct obj_section *section,
221 struct partial_symtab *pst,
222 struct minimal_symbol *msymbol)
224 struct partial_symtab *tpst;
225 struct partial_symtab *best_pst = pst;
226 CORE_ADDR best_addr = pst->textlow;
228 gdb_assert (!pst->psymtabs_addrmap_supported);
230 /* An objfile that has its functions reordered might have
231 many partial symbol tables containing the PC, but
232 we want the partial symbol table that contains the
233 function containing the PC. */
234 if (!(objfile->flags & OBJF_REORDERED) &&
235 section == 0) /* Can't validate section this way. */
241 /* The code range of partial symtabs sometimes overlap, so, in
242 the loop below, we need to check all partial symtabs and
243 find the one that fits better for the given PC address. We
244 select the partial symtab that contains a symbol whose
245 address is closest to the PC address. By closest we mean
246 that find_pc_sect_symbol returns the symbol with address
247 that is closest and still less than the given PC. */
248 for (tpst = pst; tpst != NULL; tpst = tpst->next)
250 if (pc >= tpst->textlow && pc < tpst->texthigh)
252 struct partial_symbol *p;
255 /* NOTE: This assumes that every psymbol has a
256 corresponding msymbol, which is not necessarily
257 true; the debug info might be much richer than the
258 object's symbol table. */
259 p = find_pc_sect_psymbol (objfile, tpst, pc, section);
261 && SYMBOL_VALUE_ADDRESS (p)
262 == SYMBOL_VALUE_ADDRESS (msymbol))
265 /* Also accept the textlow value of a psymtab as a
266 "symbol", to provide some support for partial
267 symbol tables with line information but no debug
268 symbols (e.g. those produced by an assembler). */
270 this_addr = SYMBOL_VALUE_ADDRESS (p);
272 this_addr = tpst->textlow;
274 /* Check whether it is closer than our current
275 BEST_ADDR. Since this symbol address is
276 necessarily lower or equal to PC, the symbol closer
277 to PC is the symbol which address is the highest.
278 This way we return the psymtab which contains such
279 best match symbol. This can help in cases where the
280 symbol information/debuginfo is not complete, like
281 for instance on IRIX6 with gcc, where no debug info
282 is emitted for statics. (See also the nodebug.exp
284 if (this_addr > best_addr)
286 best_addr = this_addr;
294 /* Find which partial symtab contains PC and SECTION. Return 0 if
295 none. We return the psymtab that contains a symbol whose address
296 exactly matches PC, or, if we cannot find an exact match, the
297 psymtab that contains a symbol whose address is closest to PC. */
298 static struct partial_symtab *
299 find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
300 struct obj_section *section,
301 struct minimal_symbol *msymbol)
303 struct partial_symtab *pst;
305 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
306 than the later used TEXTLOW/TEXTHIGH one. */
308 if (objfile->psymtabs_addrmap != NULL)
310 pst = addrmap_find (objfile->psymtabs_addrmap, pc);
313 /* FIXME: addrmaps currently do not handle overlayed sections,
314 so fall back to the non-addrmap case if we're debugging
315 overlays and the addrmap returned the wrong section. */
316 if (overlay_debugging && msymbol && section)
318 struct partial_symbol *p;
320 /* NOTE: This assumes that every psymbol has a
321 corresponding msymbol, which is not necessarily
322 true; the debug info might be much richer than the
323 object's symbol table. */
324 p = find_pc_sect_psymbol (objfile, pst, pc, section);
326 || SYMBOL_VALUE_ADDRESS (p)
327 != SYMBOL_VALUE_ADDRESS (msymbol))
331 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
332 PSYMTABS_ADDRMAP we used has already the best 1-byte
333 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
334 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
343 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
344 which still have no corresponding full SYMTABs read. But it is not
345 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
348 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
349 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
350 debug info type in single OBJFILE. */
352 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
353 if (!pst->psymtabs_addrmap_supported
354 && pc >= pst->textlow && pc < pst->texthigh)
356 struct partial_symtab *best_pst;
358 best_pst = find_pc_sect_psymtab_closer (objfile, pc, section, pst,
360 if (best_pst != NULL)
367 static struct symtab *
368 find_pc_sect_symtab_from_partial (struct objfile *objfile,
369 struct minimal_symbol *msymbol,
370 CORE_ADDR pc, struct obj_section *section,
373 struct partial_symtab *ps = find_pc_sect_psymtab (objfile, pc, section,
377 if (warn_if_readin && ps->readin)
378 /* Might want to error() here (in case symtab is corrupt and
379 will cause a core dump), but maybe we can successfully
380 continue, so let's not. */
382 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
383 paddress (get_objfile_arch (objfile), pc));
384 psymtab_to_symtab (objfile, ps);
390 /* Find which partial symbol within a psymtab matches PC and SECTION.
393 static struct partial_symbol *
394 find_pc_sect_psymbol (struct objfile *objfile,
395 struct partial_symtab *psymtab, CORE_ADDR pc,
396 struct obj_section *section)
398 struct partial_symbol *best = NULL, *p, **pp;
401 gdb_assert (psymtab != NULL);
403 /* Cope with programs that start at address 0. */
404 best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0;
406 /* Search the global symbols as well as the static symbols, so that
407 find_pc_partial_function doesn't use a minimal symbol and thus
408 cache a bad endaddr. */
409 for (pp = objfile->global_psymbols.list + psymtab->globals_offset;
410 (pp - (objfile->global_psymbols.list + psymtab->globals_offset)
411 < psymtab->n_global_syms);
415 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
416 && SYMBOL_CLASS (p) == LOC_BLOCK
417 && pc >= SYMBOL_VALUE_ADDRESS (p)
418 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
419 || (psymtab->textlow == 0
420 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
422 if (section) /* Match on a specific section. */
424 fixup_psymbol_section (p, objfile);
425 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
428 best_pc = SYMBOL_VALUE_ADDRESS (p);
433 for (pp = objfile->static_psymbols.list + psymtab->statics_offset;
434 (pp - (objfile->static_psymbols.list + psymtab->statics_offset)
435 < psymtab->n_static_syms);
439 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
440 && SYMBOL_CLASS (p) == LOC_BLOCK
441 && pc >= SYMBOL_VALUE_ADDRESS (p)
442 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
443 || (psymtab->textlow == 0
444 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
446 if (section) /* Match on a specific section. */
448 fixup_psymbol_section (p, objfile);
449 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
452 best_pc = SYMBOL_VALUE_ADDRESS (p);
461 fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
465 if (psym == NULL || SYMBOL_OBJ_SECTION (psym) != NULL)
468 gdb_assert (objfile);
470 switch (SYMBOL_CLASS (psym))
475 addr = SYMBOL_VALUE_ADDRESS (psym);
478 /* Nothing else will be listed in the minsyms -- no use looking
483 fixup_section (&psym->ginfo, addr, objfile);
486 static struct symtab *
487 lookup_symbol_aux_psymtabs (struct objfile *objfile,
488 int block_index, const char *name,
489 const domain_enum domain)
491 struct partial_symtab *ps;
492 const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
493 struct symtab *stab_best = NULL;
495 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
497 if (!ps->readin && lookup_partial_symbol (objfile, ps, name,
498 psymtab_index, domain))
500 struct symbol *sym = NULL;
501 struct symtab *stab = psymtab_to_symtab (objfile, ps);
503 /* Some caution must be observed with overloaded functions
504 and methods, since the psymtab will not contain any overload
505 information (but NAME might contain it). */
508 struct blockvector *bv = BLOCKVECTOR (stab);
509 struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
511 sym = lookup_block_symbol (block, name, domain);
514 if (sym && strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0)
516 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
522 /* Keep looking through other psymtabs. */
529 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
530 the global block of PST if GLOBAL, and otherwise the static block.
531 MATCH is the comparison operation that returns true iff MATCH (s,
532 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
533 non-null, the symbols in the block are assumed to be ordered
534 according to it (allowing binary search). It must be compatible
535 with MATCH. Returns the symbol, if found, and otherwise NULL. */
537 static struct partial_symbol *
538 match_partial_symbol (struct objfile *objfile,
539 struct partial_symtab *pst, int global,
540 const char *name, domain_enum domain,
541 symbol_compare_ftype *match,
542 symbol_compare_ftype *ordered_compare)
544 struct partial_symbol **start, **psym;
545 struct partial_symbol **top, **real_top, **bottom, **center;
546 int length = (global ? pst->n_global_syms : pst->n_static_syms);
547 int do_linear_search = 1;
552 objfile->global_psymbols.list + pst->globals_offset :
553 objfile->static_psymbols.list + pst->statics_offset);
555 if (global && ordered_compare) /* Can use a binary search. */
557 do_linear_search = 0;
559 /* Binary search. This search is guaranteed to end with center
560 pointing at the earliest partial symbol whose name might be
561 correct. At that point *all* partial symbols with an
562 appropriate name will be checked against the correct
566 top = start + length - 1;
570 center = bottom + (top - bottom) / 2;
571 gdb_assert (center < top);
572 if (!do_linear_search
573 && (SYMBOL_LANGUAGE (*center) == language_java))
574 do_linear_search = 1;
575 if (ordered_compare (SYMBOL_SEARCH_NAME (*center), name) >= 0)
580 gdb_assert (top == bottom);
582 while (top <= real_top
583 && match (SYMBOL_SEARCH_NAME (*top), name) == 0)
585 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
586 SYMBOL_DOMAIN (*top), domain))
592 /* Can't use a binary search or else we found during the binary search that
593 we should also do a linear search. */
595 if (do_linear_search)
597 for (psym = start; psym < start + length; psym++)
599 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
600 SYMBOL_DOMAIN (*psym), domain)
601 && match (SYMBOL_SEARCH_NAME (*psym), name) == 0)
609 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
610 not contain any method/function instance information (since this would
611 force reading type information while reading psymtabs). Therefore,
612 if NAME contains overload information, it must be stripped before searching
615 The caller is responsible for freeing the return result. */
618 psymtab_search_name (const char *name)
620 switch (current_language->la_language)
625 if (strchr (name, '('))
627 char *ret = cp_remove_params (name);
639 return xstrdup (name);
642 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
643 Check the global symbols if GLOBAL, the static symbols if not. */
645 static struct partial_symbol *
646 lookup_partial_symbol (struct objfile *objfile,
647 struct partial_symtab *pst, const char *name,
648 int global, domain_enum domain)
650 struct partial_symbol **start, **psym;
651 struct partial_symbol **top, **real_top, **bottom, **center;
652 int length = (global ? pst->n_global_syms : pst->n_static_syms);
653 int do_linear_search = 1;
655 struct cleanup *cleanup;
662 search_name = psymtab_search_name (name);
663 cleanup = make_cleanup (xfree, search_name);
665 objfile->global_psymbols.list + pst->globals_offset :
666 objfile->static_psymbols.list + pst->statics_offset);
668 if (global) /* This means we can use a binary search. */
670 do_linear_search = 0;
672 /* Binary search. This search is guaranteed to end with center
673 pointing at the earliest partial symbol whose name might be
674 correct. At that point *all* partial symbols with an
675 appropriate name will be checked against the correct
679 top = start + length - 1;
683 center = bottom + (top - bottom) / 2;
685 internal_error (__FILE__, __LINE__,
686 _("failed internal consistency check"));
687 if (!do_linear_search
688 && SYMBOL_LANGUAGE (*center) == language_java)
690 do_linear_search = 1;
692 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center),
702 if (!(top == bottom))
703 internal_error (__FILE__, __LINE__,
704 _("failed internal consistency check"));
706 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
707 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
708 while (top >= start && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
711 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
714 while (top <= real_top && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
716 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
717 SYMBOL_DOMAIN (*top), domain))
719 do_cleanups (cleanup);
726 /* Can't use a binary search or else we found during the binary search that
727 we should also do a linear search. */
729 if (do_linear_search)
731 for (psym = start; psym < start + length; psym++)
733 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
734 SYMBOL_DOMAIN (*psym), domain)
735 && SYMBOL_MATCHES_SEARCH_NAME (*psym, search_name))
737 do_cleanups (cleanup);
743 do_cleanups (cleanup);
747 /* Get the symbol table that corresponds to a partial_symtab.
748 This is fast after the first time you do it. */
750 static struct symtab *
751 psymtab_to_symtab (struct objfile *objfile, struct partial_symtab *pst)
753 /* If it is a shared psymtab, find an unshared psymtab that includes
754 it. Any such psymtab will do. */
755 while (pst->user != NULL)
758 /* If it's been looked up before, return it. */
762 /* If it has not yet been read in, read it. */
765 struct cleanup *back_to = increment_reading_symtab ();
767 (*pst->read_symtab) (pst, objfile);
768 do_cleanups (back_to);
775 relocate_psymtabs (struct objfile *objfile,
776 struct section_offsets *new_offsets,
777 struct section_offsets *delta)
779 struct partial_symbol **psym;
780 struct partial_symtab *p;
782 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
784 p->textlow += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
785 p->texthigh += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
788 for (psym = objfile->global_psymbols.list;
789 psym < objfile->global_psymbols.next;
792 fixup_psymbol_section (*psym, objfile);
793 if (SYMBOL_SECTION (*psym) >= 0)
794 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
795 SYMBOL_SECTION (*psym));
797 for (psym = objfile->static_psymbols.list;
798 psym < objfile->static_psymbols.next;
801 fixup_psymbol_section (*psym, objfile);
802 if (SYMBOL_SECTION (*psym) >= 0)
803 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
804 SYMBOL_SECTION (*psym));
808 static struct symtab *
809 find_last_source_symtab_from_partial (struct objfile *ofp)
811 struct partial_symtab *ps;
812 struct partial_symtab *cs_pst = 0;
814 ALL_OBJFILE_PSYMTABS_REQUIRED (ofp, ps)
816 const char *name = ps->filename;
817 int len = strlen (name);
819 if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0
820 || strcmp (name, "<<C++-namespaces>>") == 0)))
828 internal_error (__FILE__, __LINE__,
829 _("select_source_symtab: "
830 "readin pst found and no symtabs."));
833 return psymtab_to_symtab (ofp, cs_pst);
839 forget_cached_source_info_partial (struct objfile *objfile)
841 struct partial_symtab *pst;
843 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
845 if (pst->fullname != NULL)
847 xfree (pst->fullname);
848 pst->fullname = NULL;
854 print_partial_symbols (struct gdbarch *gdbarch,
855 struct partial_symbol **p, int count, char *what,
856 struct ui_file *outfile)
858 fprintf_filtered (outfile, " %s partial symbols:\n", what);
862 fprintf_filtered (outfile, " `%s'", SYMBOL_LINKAGE_NAME (*p));
863 if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
865 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
867 fputs_filtered (", ", outfile);
868 switch (SYMBOL_DOMAIN (*p))
871 fputs_filtered ("undefined domain, ", outfile);
874 /* This is the usual thing -- don't print it. */
877 fputs_filtered ("struct domain, ", outfile);
880 fputs_filtered ("label domain, ", outfile);
883 fputs_filtered ("<invalid domain>, ", outfile);
886 switch (SYMBOL_CLASS (*p))
889 fputs_filtered ("undefined", outfile);
892 fputs_filtered ("constant int", outfile);
895 fputs_filtered ("static", outfile);
898 fputs_filtered ("register", outfile);
901 fputs_filtered ("pass by value", outfile);
904 fputs_filtered ("pass by reference", outfile);
906 case LOC_REGPARM_ADDR:
907 fputs_filtered ("register address parameter", outfile);
910 fputs_filtered ("stack parameter", outfile);
913 fputs_filtered ("type", outfile);
916 fputs_filtered ("label", outfile);
919 fputs_filtered ("function", outfile);
921 case LOC_CONST_BYTES:
922 fputs_filtered ("constant bytes", outfile);
925 fputs_filtered ("unresolved", outfile);
927 case LOC_OPTIMIZED_OUT:
928 fputs_filtered ("optimized out", outfile);
931 fputs_filtered ("computed at runtime", outfile);
934 fputs_filtered ("<invalid location>", outfile);
937 fputs_filtered (", ", outfile);
938 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (*p)), outfile);
939 fprintf_filtered (outfile, "\n");
945 dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
946 struct ui_file *outfile)
948 struct gdbarch *gdbarch = get_objfile_arch (objfile);
951 if (psymtab->anonymous)
953 fprintf_filtered (outfile, "\nAnonymous partial symtab (%s) ",
958 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
961 fprintf_filtered (outfile, "(object ");
962 gdb_print_host_address (psymtab, outfile);
963 fprintf_filtered (outfile, ")\n\n");
964 fprintf_unfiltered (outfile, " Read from object file %s (",
966 gdb_print_host_address (objfile, outfile);
967 fprintf_unfiltered (outfile, ")\n");
971 fprintf_filtered (outfile,
972 " Full symtab was read (at ");
973 gdb_print_host_address (psymtab->symtab, outfile);
974 fprintf_filtered (outfile, " by function at ");
975 gdb_print_host_address (psymtab->read_symtab, outfile);
976 fprintf_filtered (outfile, ")\n");
979 fprintf_filtered (outfile, " Relocate symbols by ");
980 for (i = 0; i < objfile->num_sections; ++i)
983 fprintf_filtered (outfile, ", ");
985 fputs_filtered (paddress (gdbarch,
986 ANOFFSET (psymtab->section_offsets, i)),
989 fprintf_filtered (outfile, "\n");
991 fprintf_filtered (outfile, " Symbols cover text addresses ");
992 fputs_filtered (paddress (gdbarch, psymtab->textlow), outfile);
993 fprintf_filtered (outfile, "-");
994 fputs_filtered (paddress (gdbarch, psymtab->texthigh), outfile);
995 fprintf_filtered (outfile, "\n");
996 fprintf_filtered (outfile, " Address map supported - %s.\n",
997 psymtab->psymtabs_addrmap_supported ? "yes" : "no");
998 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
999 psymtab->number_of_dependencies);
1000 for (i = 0; i < psymtab->number_of_dependencies; i++)
1002 fprintf_filtered (outfile, " %d ", i);
1003 gdb_print_host_address (psymtab->dependencies[i], outfile);
1004 fprintf_filtered (outfile, " %s\n",
1005 psymtab->dependencies[i]->filename);
1007 if (psymtab->user != NULL)
1009 fprintf_filtered (outfile, " Shared partial symtab with user ");
1010 gdb_print_host_address (psymtab->user, outfile);
1011 fprintf_filtered (outfile, "\n");
1013 if (psymtab->n_global_syms > 0)
1015 print_partial_symbols (gdbarch,
1016 objfile->global_psymbols.list
1017 + psymtab->globals_offset,
1018 psymtab->n_global_syms, "Global", outfile);
1020 if (psymtab->n_static_syms > 0)
1022 print_partial_symbols (gdbarch,
1023 objfile->static_psymbols.list
1024 + psymtab->statics_offset,
1025 psymtab->n_static_syms, "Static", outfile);
1027 fprintf_filtered (outfile, "\n");
1031 print_psymtab_stats_for_objfile (struct objfile *objfile)
1034 struct partial_symtab *ps;
1037 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1039 if (ps->readin == 0)
1042 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i);
1046 dump_psymtabs_for_objfile (struct objfile *objfile)
1048 struct partial_symtab *psymtab;
1050 if (objfile->psymtabs)
1052 printf_filtered ("Psymtabs:\n");
1053 for (psymtab = objfile->psymtabs;
1055 psymtab = psymtab->next)
1057 printf_filtered ("%s at ",
1059 gdb_print_host_address (psymtab, gdb_stdout);
1060 printf_filtered (", ");
1063 printf_filtered ("\n\n");
1067 /* Look through the partial symtabs for all symbols which begin
1068 by matching FUNC_NAME. Make sure we read that symbol table in. */
1071 read_symtabs_for_function (struct objfile *objfile, const char *func_name)
1073 struct partial_symtab *ps;
1075 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1080 if ((lookup_partial_symbol (objfile, ps, func_name, 1, VAR_DOMAIN)
1082 || (lookup_partial_symbol (objfile, ps, func_name, 0, VAR_DOMAIN)
1084 psymtab_to_symtab (objfile, ps);
1089 expand_partial_symbol_tables (struct objfile *objfile)
1091 struct partial_symtab *psymtab;
1093 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
1095 psymtab_to_symtab (objfile, psymtab);
1100 read_psymtabs_with_filename (struct objfile *objfile, const char *filename)
1102 struct partial_symtab *p;
1104 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
1106 /* Anonymous psymtabs don't have a name of a source file. */
1110 if (filename_cmp (filename, p->filename) == 0)
1111 psymtab_to_symtab (objfile, p);
1116 map_symbol_filenames_psymtab (struct objfile *objfile,
1117 symbol_filename_ftype *fun, void *data,
1120 struct partial_symtab *ps;
1122 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1124 const char *fullname;
1129 /* We can skip shared psymtabs here, because any file name will be
1130 attached to the unshared psymtab. */
1131 if (ps->user != NULL)
1134 /* Anonymous psymtabs don't have a file name. */
1140 fullname = psymtab_to_fullname (ps);
1143 (*fun) (ps->filename, fullname, data);
1147 /* Finds the fullname that a partial_symtab represents.
1149 If this functions finds the fullname, it will save it in ps->fullname
1150 and it will also return the value.
1152 If this function fails to find the file that this partial_symtab represents,
1153 NULL will be returned and ps->fullname will be set to NULL. */
1156 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 (objfile, 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 (objfile, ps, global, name, namespace, match,
1245 struct symtab *s = psymtab_to_symtab (objfile, 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)
1378 if (! (*file_matcher) (ps->filename, data))
1382 if (recursively_search_psymtabs (ps, objfile, kind, name_matcher, data))
1383 psymtab_to_symtab (objfile, ps);
1388 objfile_has_psyms (struct objfile *objfile)
1390 return objfile->psymtabs != NULL;
1393 const struct quick_symbol_functions psym_functions =
1396 find_last_source_symtab_from_partial,
1397 forget_cached_source_info_partial,
1398 partial_map_symtabs_matching_filename,
1399 lookup_symbol_aux_psymtabs,
1400 print_psymtab_stats_for_objfile,
1401 dump_psymtabs_for_objfile,
1403 read_symtabs_for_function,
1404 expand_partial_symbol_tables,
1405 read_psymtabs_with_filename,
1406 find_symbol_file_from_partial,
1407 map_matching_symbols_psymtab,
1408 expand_symtabs_matching_via_partial,
1409 find_pc_sect_symtab_from_partial,
1410 map_symbol_filenames_psymtab
1415 /* This compares two partial symbols by names, using strcmp_iw_ordered
1416 for the comparison. */
1419 compare_psymbols (const void *s1p, const void *s2p)
1421 struct partial_symbol *const *s1 = s1p;
1422 struct partial_symbol *const *s2 = s2p;
1424 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1),
1425 SYMBOL_SEARCH_NAME (*s2));
1429 sort_pst_symbols (struct objfile *objfile, struct partial_symtab *pst)
1431 /* Sort the global list; don't sort the static list. */
1433 qsort (objfile->global_psymbols.list + pst->globals_offset,
1434 pst->n_global_syms, sizeof (struct partial_symbol *),
1438 /* Allocate and partially fill a partial symtab. It will be
1439 completely filled at the end of the symbol list.
1441 FILENAME is the name of the symbol-file we are reading from. */
1443 struct partial_symtab *
1444 start_psymtab_common (struct objfile *objfile,
1445 struct section_offsets *section_offsets,
1446 const char *filename,
1447 CORE_ADDR textlow, struct partial_symbol **global_syms,
1448 struct partial_symbol **static_syms)
1450 struct partial_symtab *psymtab;
1452 psymtab = allocate_psymtab (filename, objfile);
1453 psymtab->section_offsets = section_offsets;
1454 psymtab->textlow = textlow;
1455 psymtab->texthigh = psymtab->textlow; /* default */
1456 psymtab->globals_offset = global_syms - objfile->global_psymbols.list;
1457 psymtab->statics_offset = static_syms - objfile->static_psymbols.list;
1461 /* Calculate a hash code for the given partial symbol. The hash is
1462 calculated using the symbol's value, language, domain, class
1463 and name. These are the values which are set by
1464 add_psymbol_to_bcache. */
1466 static unsigned long
1467 psymbol_hash (const void *addr, int length)
1469 unsigned long h = 0;
1470 struct partial_symbol *psymbol = (struct partial_symbol *) addr;
1471 unsigned int lang = psymbol->ginfo.language;
1472 unsigned int domain = PSYMBOL_DOMAIN (psymbol);
1473 unsigned int class = PSYMBOL_CLASS (psymbol);
1475 h = hash_continue (&psymbol->ginfo.value, sizeof (psymbol->ginfo.value), h);
1476 h = hash_continue (&lang, sizeof (unsigned int), h);
1477 h = hash_continue (&domain, sizeof (unsigned int), h);
1478 h = hash_continue (&class, sizeof (unsigned int), h);
1479 h = hash_continue (psymbol->ginfo.name, strlen (psymbol->ginfo.name), h);
1484 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1485 For the comparison this function uses a symbols value,
1486 language, domain, class and name. */
1489 psymbol_compare (const void *addr1, const void *addr2, int length)
1491 struct partial_symbol *sym1 = (struct partial_symbol *) addr1;
1492 struct partial_symbol *sym2 = (struct partial_symbol *) addr2;
1494 return (memcmp (&sym1->ginfo.value, &sym1->ginfo.value,
1495 sizeof (sym1->ginfo.value)) == 0
1496 && sym1->ginfo.language == sym2->ginfo.language
1497 && PSYMBOL_DOMAIN (sym1) == PSYMBOL_DOMAIN (sym2)
1498 && PSYMBOL_CLASS (sym1) == PSYMBOL_CLASS (sym2)
1499 && sym1->ginfo.name == sym2->ginfo.name);
1502 /* Initialize a partial symbol bcache. */
1504 struct psymbol_bcache *
1505 psymbol_bcache_init (void)
1507 struct psymbol_bcache *bcache = XCALLOC (1, struct psymbol_bcache);
1508 bcache->bcache = bcache_xmalloc (psymbol_hash, psymbol_compare);
1512 /* Free a partial symbol bcache. */
1514 psymbol_bcache_free (struct psymbol_bcache *bcache)
1519 bcache_xfree (bcache->bcache);
1523 /* Return the internal bcache of the psymbol_bcache BCACHE. */
1526 psymbol_bcache_get_bcache (struct psymbol_bcache *bcache)
1528 return bcache->bcache;
1531 /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1532 symbol before, add a copy to BCACHE. In either case, return a pointer
1533 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1534 1 in case of new entry or 0 if returning an old entry. */
1536 static const struct partial_symbol *
1537 psymbol_bcache_full (struct partial_symbol *sym,
1538 struct psymbol_bcache *bcache,
1541 return bcache_full (sym,
1542 sizeof (struct partial_symbol),
1547 /* Helper function, initialises partial symbol structure and stashes
1548 it into objfile's bcache. Note that our caching mechanism will
1549 use all fields of struct partial_symbol to determine hash value of the
1550 structure. In other words, having two symbols with the same name but
1551 different domain (or address) is possible and correct. */
1553 static const struct partial_symbol *
1554 add_psymbol_to_bcache (const char *name, int namelength, int copy_name,
1556 enum address_class class,
1557 long val, /* Value as a long */
1558 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1559 enum language language, struct objfile *objfile,
1562 struct partial_symbol psymbol;
1564 /* We must ensure that the entire 'value' field has been zeroed
1565 before assigning to it, because an assignment may not write the
1567 memset (&psymbol.ginfo.value, 0, sizeof (psymbol.ginfo.value));
1569 /* val and coreaddr are mutually exclusive, one of them *will* be zero. */
1572 SYMBOL_VALUE (&psymbol) = val;
1576 SYMBOL_VALUE_ADDRESS (&psymbol) = coreaddr;
1578 SYMBOL_SECTION (&psymbol) = 0;
1579 SYMBOL_OBJ_SECTION (&psymbol) = NULL;
1580 SYMBOL_SET_LANGUAGE (&psymbol, language);
1581 PSYMBOL_DOMAIN (&psymbol) = domain;
1582 PSYMBOL_CLASS (&psymbol) = class;
1584 SYMBOL_SET_NAMES (&psymbol, name, namelength, copy_name, objfile);
1586 /* Stash the partial symbol away in the cache. */
1587 return psymbol_bcache_full (&psymbol,
1588 objfile->psymbol_cache,
1592 /* Increase the space allocated for LISTP, which is probably
1593 global_psymbols or static_psymbols. This space will eventually
1594 be freed in free_objfile(). */
1597 extend_psymbol_list (struct psymbol_allocation_list *listp,
1598 struct objfile *objfile)
1602 if (listp->size == 0)
1605 listp->list = (struct partial_symbol **)
1606 xmalloc (new_size * sizeof (struct partial_symbol *));
1610 new_size = listp->size * 2;
1611 listp->list = (struct partial_symbol **)
1612 xrealloc ((char *) listp->list,
1613 new_size * sizeof (struct partial_symbol *));
1615 /* Next assumes we only went one over. Should be good if
1616 program works correctly. */
1617 listp->next = listp->list + listp->size;
1618 listp->size = new_size;
1621 /* Helper function, adds partial symbol to the given partial symbol
1625 append_psymbol_to_list (struct psymbol_allocation_list *list,
1626 const struct partial_symbol *psym,
1627 struct objfile *objfile)
1629 if (list->next >= list->list + list->size)
1630 extend_psymbol_list (list, objfile);
1631 *list->next++ = (struct partial_symbol *) psym;
1632 OBJSTAT (objfile, n_psyms++);
1635 /* Add a symbol with a long value to a psymtab.
1636 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1637 Return the partial symbol that has been added. */
1640 add_psymbol_to_list (const char *name, int namelength, int copy_name,
1642 enum address_class class,
1643 struct psymbol_allocation_list *list,
1644 long val, /* Value as a long */
1645 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1646 enum language language, struct objfile *objfile)
1648 const struct partial_symbol *psym;
1652 /* Stash the partial symbol away in the cache. */
1653 psym = add_psymbol_to_bcache (name, namelength, copy_name, domain, class,
1654 val, coreaddr, language, objfile, &added);
1656 /* Do not duplicate global partial symbols. */
1657 if (list == &objfile->global_psymbols
1661 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1662 append_psymbol_to_list (list, psym, objfile);
1665 /* Initialize storage for partial symbols. */
1668 init_psymbol_list (struct objfile *objfile, int total_symbols)
1670 /* Free any previously allocated psymbol lists. */
1672 if (objfile->global_psymbols.list)
1674 xfree (objfile->global_psymbols.list);
1676 if (objfile->static_psymbols.list)
1678 xfree (objfile->static_psymbols.list);
1681 /* Current best guess is that approximately a twentieth
1682 of the total symbols (in a debugging file) are global or static
1683 oriented symbols, then multiply that by slop factor of two. */
1685 objfile->global_psymbols.size = total_symbols / 10;
1686 objfile->static_psymbols.size = total_symbols / 10;
1688 if (objfile->global_psymbols.size > 0)
1690 objfile->global_psymbols.next =
1691 objfile->global_psymbols.list = (struct partial_symbol **)
1692 xmalloc ((objfile->global_psymbols.size
1693 * sizeof (struct partial_symbol *)));
1695 if (objfile->static_psymbols.size > 0)
1697 objfile->static_psymbols.next =
1698 objfile->static_psymbols.list = (struct partial_symbol **)
1699 xmalloc ((objfile->static_psymbols.size
1700 * sizeof (struct partial_symbol *)));
1704 struct partial_symtab *
1705 allocate_psymtab (const char *filename, struct objfile *objfile)
1707 struct partial_symtab *psymtab;
1709 if (objfile->free_psymtabs)
1711 psymtab = objfile->free_psymtabs;
1712 objfile->free_psymtabs = psymtab->next;
1715 psymtab = (struct partial_symtab *)
1716 obstack_alloc (&objfile->objfile_obstack,
1717 sizeof (struct partial_symtab));
1719 memset (psymtab, 0, sizeof (struct partial_symtab));
1720 psymtab->filename = obstack_copy0 (&objfile->objfile_obstack,
1721 filename, strlen (filename));
1722 psymtab->symtab = NULL;
1724 /* Prepend it to the psymtab list for the objfile it belongs to.
1725 Psymtabs are searched in most recent inserted -> least recent
1728 psymtab->next = objfile->psymtabs;
1729 objfile->psymtabs = psymtab;
1731 if (symtab_create_debug)
1733 /* Be a bit clever with debugging messages, and don't print objfile
1734 every time, only when it changes. */
1735 static char *last_objfile_name = NULL;
1737 if (last_objfile_name == NULL
1738 || strcmp (last_objfile_name, objfile->name) != 0)
1740 xfree (last_objfile_name);
1741 last_objfile_name = xstrdup (objfile->name);
1742 fprintf_unfiltered (gdb_stdlog,
1743 "Creating one or more psymtabs for objfile %s ...\n",
1746 fprintf_unfiltered (gdb_stdlog,
1747 "Created psymtab %s for module %s.\n",
1748 host_address_to_string (psymtab), filename);
1755 discard_psymtab (struct objfile *objfile, struct partial_symtab *pst)
1757 struct partial_symtab **prev_pst;
1760 Empty psymtabs happen as a result of header files which don't
1761 have any symbols in them. There can be a lot of them. But this
1762 check is wrong, in that a psymtab with N_SLINE entries but
1763 nothing else is not empty, but we don't realize that. Fixing
1764 that without slowing things down might be tricky. */
1766 /* First, snip it out of the psymtab chain. */
1768 prev_pst = &(objfile->psymtabs);
1769 while ((*prev_pst) != pst)
1770 prev_pst = &((*prev_pst)->next);
1771 (*prev_pst) = pst->next;
1773 /* Next, put it on a free list for recycling. */
1775 pst->next = objfile->free_psymtabs;
1776 objfile->free_psymtabs = pst;
1779 /* An object of this type is passed to discard_psymtabs_upto. */
1781 struct psymtab_state
1783 /* The objfile where psymtabs are discarded. */
1785 struct objfile *objfile;
1787 /* The first psymtab to save. */
1789 struct partial_symtab *save;
1792 /* A cleanup function used by make_cleanup_discard_psymtabs. */
1795 discard_psymtabs_upto (void *arg)
1797 struct psymtab_state *state = arg;
1799 while (state->objfile->psymtabs != state->save)
1800 discard_psymtab (state->objfile, state->objfile->psymtabs);
1803 /* Return a new cleanup that discards all psymtabs created in OBJFILE
1804 after this function is called. */
1807 make_cleanup_discard_psymtabs (struct objfile *objfile)
1809 struct psymtab_state *state = XNEW (struct psymtab_state);
1811 state->objfile = objfile;
1812 state->save = objfile->psymtabs;
1814 return make_cleanup_dtor (discard_psymtabs_upto, state, xfree);
1820 maintenance_print_psymbols (char *args, int from_tty)
1823 struct ui_file *outfile;
1824 struct cleanup *cleanups;
1825 char *symname = NULL;
1826 char *filename = DEV_TTY;
1827 struct objfile *objfile;
1828 struct partial_symtab *ps;
1835 print-psymbols takes an output file name and optional symbol file name"));
1837 argv = gdb_buildargv (args);
1838 cleanups = make_cleanup_freeargv (argv);
1840 if (argv[0] != NULL)
1843 /* If a second arg is supplied, it is a source file name to match on. */
1844 if (argv[1] != NULL)
1850 filename = tilde_expand (filename);
1851 make_cleanup (xfree, filename);
1853 outfile = gdb_fopen (filename, FOPEN_WT);
1855 perror_with_name (filename);
1856 make_cleanup_ui_file_delete (outfile);
1858 ALL_PSYMTABS (objfile, ps)
1861 if (symname == NULL || filename_cmp (symname, ps->filename) == 0)
1862 dump_psymtab (objfile, ps, outfile);
1864 do_cleanups (cleanups);
1867 /* List all the partial symbol tables whose names match REGEXP (optional). */
1869 maintenance_info_psymtabs (char *regexp, int from_tty)
1871 struct program_space *pspace;
1872 struct objfile *objfile;
1877 ALL_PSPACES (pspace)
1878 ALL_PSPACE_OBJFILES (pspace, objfile)
1880 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1881 struct partial_symtab *psymtab;
1883 /* We don't want to print anything for this objfile until we
1884 actually find a symtab whose name matches. */
1885 int printed_objfile_start = 0;
1887 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
1892 || re_exec (psymtab->filename))
1894 if (! printed_objfile_start)
1896 printf_filtered ("{ objfile %s ", objfile->name);
1898 printf_filtered ("((struct objfile *) %s)\n",
1899 host_address_to_string (objfile));
1900 printed_objfile_start = 1;
1903 printf_filtered (" { psymtab %s ", psymtab->filename);
1905 printf_filtered ("((struct partial_symtab *) %s)\n",
1906 host_address_to_string (psymtab));
1908 printf_filtered (" readin %s\n",
1909 psymtab->readin ? "yes" : "no");
1910 printf_filtered (" fullname %s\n",
1912 ? psymtab->fullname : "(null)");
1913 printf_filtered (" text addresses ");
1914 fputs_filtered (paddress (gdbarch, psymtab->textlow),
1916 printf_filtered (" -- ");
1917 fputs_filtered (paddress (gdbarch, psymtab->texthigh),
1919 printf_filtered ("\n");
1920 printf_filtered (" psymtabs_addrmap_supported %s\n",
1921 (psymtab->psymtabs_addrmap_supported
1923 printf_filtered (" globals ");
1924 if (psymtab->n_global_syms)
1926 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1927 host_address_to_string (objfile->global_psymbols.list
1928 + psymtab->globals_offset),
1929 psymtab->n_global_syms);
1932 printf_filtered ("(none)\n");
1933 printf_filtered (" statics ");
1934 if (psymtab->n_static_syms)
1936 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1937 host_address_to_string (objfile->static_psymbols.list
1938 + psymtab->statics_offset),
1939 psymtab->n_static_syms);
1942 printf_filtered ("(none)\n");
1943 printf_filtered (" dependencies ");
1944 if (psymtab->number_of_dependencies)
1948 printf_filtered ("{\n");
1949 for (i = 0; i < psymtab->number_of_dependencies; i++)
1951 struct partial_symtab *dep = psymtab->dependencies[i];
1953 /* Note the string concatenation there --- no comma. */
1954 printf_filtered (" psymtab %s "
1955 "((struct partial_symtab *) %s)\n",
1957 host_address_to_string (dep));
1959 printf_filtered (" }\n");
1962 printf_filtered ("(none)\n");
1963 printf_filtered (" }\n");
1967 if (printed_objfile_start)
1968 printf_filtered ("}\n");
1972 /* Check consistency of psymtabs and symtabs. */
1975 maintenance_check_symtabs (char *ignore, int from_tty)
1978 struct partial_symbol **psym;
1979 struct symtab *s = NULL;
1980 struct partial_symtab *ps;
1981 struct blockvector *bv;
1982 struct objfile *objfile;
1986 ALL_PSYMTABS (objfile, ps)
1988 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1990 s = psymtab_to_symtab (objfile, ps);
1993 bv = BLOCKVECTOR (s);
1994 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1995 psym = objfile->static_psymbols.list + ps->statics_offset;
1996 length = ps->n_static_syms;
1999 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
2000 SYMBOL_DOMAIN (*psym));
2003 printf_filtered ("Static symbol `");
2004 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
2005 printf_filtered ("' only found in ");
2006 puts_filtered (ps->filename);
2007 printf_filtered (" psymtab\n");
2011 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
2012 psym = objfile->global_psymbols.list + ps->globals_offset;
2013 length = ps->n_global_syms;
2016 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
2017 SYMBOL_DOMAIN (*psym));
2020 printf_filtered ("Global symbol `");
2021 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
2022 printf_filtered ("' only found in ");
2023 puts_filtered (ps->filename);
2024 printf_filtered (" psymtab\n");
2028 if (ps->texthigh < ps->textlow)
2030 printf_filtered ("Psymtab ");
2031 puts_filtered (ps->filename);
2032 printf_filtered (" covers bad range ");
2033 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
2034 printf_filtered (" - ");
2035 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
2036 printf_filtered ("\n");
2039 if (ps->texthigh == 0)
2041 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
2043 printf_filtered ("Psymtab ");
2044 puts_filtered (ps->filename);
2045 printf_filtered (" covers ");
2046 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
2047 printf_filtered (" - ");
2048 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
2049 printf_filtered (" but symtab covers only ");
2050 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
2051 printf_filtered (" - ");
2052 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout);
2053 printf_filtered ("\n");
2061 expand_partial_symbol_names (int (*fun) (const char *, void *),
2064 struct objfile *objfile;
2066 ALL_OBJFILES (objfile)
2069 objfile->sf->qf->expand_symtabs_matching (objfile, NULL, fun,
2075 map_partial_symbol_filenames (symbol_filename_ftype *fun, void *data,
2078 struct objfile *objfile;
2080 ALL_OBJFILES (objfile)
2083 objfile->sf->qf->map_symbol_filenames (objfile, fun, data,
2088 extern initialize_file_ftype _initialize_psymtab;
2091 _initialize_psymtab (void)
2093 add_cmd ("psymbols", class_maintenance, maintenance_print_psymbols, _("\
2094 Print dump of current partial symbol definitions.\n\
2095 Entries in the partial symbol table are dumped to file OUTFILE.\n\
2096 If a SOURCE file is specified, dump only that file's partial symbols."),
2097 &maintenanceprintlist);
2099 add_cmd ("psymtabs", class_maintenance, maintenance_info_psymtabs, _("\
2100 List the partial symbol tables for all object files.\n\
2101 This does not include information about individual partial symbols,\n\
2102 just the symbol table structures themselves."),
2103 &maintenanceinfolist);
2105 add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs,
2106 _("Check consistency of psymtabs and symtabs."),