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 /* Anonymous psymtabs don't have a file name. */
181 if (FILENAME_CMP (name, pst->filename) == 0
182 || (!is_abs && compare_filenames_for_search (pst->filename,
185 if (partial_map_expand_apply (objfile, name, full_path, 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 (full_path != NULL)
200 psymtab_to_fullname (pst);
201 if (pst->fullname != NULL
202 && (FILENAME_CMP (full_path, pst->fullname) == 0
203 || (!is_abs && compare_filenames_for_search (pst->fullname,
206 if (partial_map_expand_apply (objfile, name, full_path, real_path,
207 pst, callback, data))
212 if (real_path != NULL)
215 psymtab_to_fullname (pst);
216 if (pst->fullname != NULL)
218 rp = gdb_realpath (pst->fullname);
219 make_cleanup (xfree, rp);
222 && (FILENAME_CMP (real_path, rp) == 0
223 || (!is_abs && compare_filenames_for_search (real_path,
226 if (partial_map_expand_apply (objfile, name, full_path, real_path,
227 pst, callback, data))
236 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
237 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
239 static struct partial_symtab *
240 find_pc_sect_psymtab_closer (CORE_ADDR pc, struct obj_section *section,
241 struct partial_symtab *pst,
242 struct minimal_symbol *msymbol)
244 struct objfile *objfile = pst->objfile;
245 struct partial_symtab *tpst;
246 struct partial_symtab *best_pst = pst;
247 CORE_ADDR best_addr = pst->textlow;
249 gdb_assert (!pst->psymtabs_addrmap_supported);
251 /* An objfile that has its functions reordered might have
252 many partial symbol tables containing the PC, but
253 we want the partial symbol table that contains the
254 function containing the PC. */
255 if (!(objfile->flags & OBJF_REORDERED) &&
256 section == 0) /* Can't validate section this way. */
262 /* The code range of partial symtabs sometimes overlap, so, in
263 the loop below, we need to check all partial symtabs and
264 find the one that fits better for the given PC address. We
265 select the partial symtab that contains a symbol whose
266 address is closest to the PC address. By closest we mean
267 that find_pc_sect_symbol returns the symbol with address
268 that is closest and still less than the given PC. */
269 for (tpst = pst; tpst != NULL; tpst = tpst->next)
271 if (pc >= tpst->textlow && pc < tpst->texthigh)
273 struct partial_symbol *p;
276 /* NOTE: This assumes that every psymbol has a
277 corresponding msymbol, which is not necessarily
278 true; the debug info might be much richer than the
279 object's symbol table. */
280 p = find_pc_sect_psymbol (tpst, pc, section);
282 && SYMBOL_VALUE_ADDRESS (p)
283 == SYMBOL_VALUE_ADDRESS (msymbol))
286 /* Also accept the textlow value of a psymtab as a
287 "symbol", to provide some support for partial
288 symbol tables with line information but no debug
289 symbols (e.g. those produced by an assembler). */
291 this_addr = SYMBOL_VALUE_ADDRESS (p);
293 this_addr = tpst->textlow;
295 /* Check whether it is closer than our current
296 BEST_ADDR. Since this symbol address is
297 necessarily lower or equal to PC, the symbol closer
298 to PC is the symbol which address is the highest.
299 This way we return the psymtab which contains such
300 best match symbol. This can help in cases where the
301 symbol information/debuginfo is not complete, like
302 for instance on IRIX6 with gcc, where no debug info
303 is emitted for statics. (See also the nodebug.exp
305 if (this_addr > best_addr)
307 best_addr = this_addr;
315 /* Find which partial symtab contains PC and SECTION. Return 0 if
316 none. We return the psymtab that contains a symbol whose address
317 exactly matches PC, or, if we cannot find an exact match, the
318 psymtab that contains a symbol whose address is closest to PC. */
319 static struct partial_symtab *
320 find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
321 struct obj_section *section,
322 struct minimal_symbol *msymbol)
324 struct partial_symtab *pst;
326 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
327 than the later used TEXTLOW/TEXTHIGH one. */
329 if (objfile->psymtabs_addrmap != NULL)
331 pst = addrmap_find (objfile->psymtabs_addrmap, pc);
334 /* FIXME: addrmaps currently do not handle overlayed sections,
335 so fall back to the non-addrmap case if we're debugging
336 overlays and the addrmap returned the wrong section. */
337 if (overlay_debugging && msymbol && section)
339 struct partial_symbol *p;
341 /* NOTE: This assumes that every psymbol has a
342 corresponding msymbol, which is not necessarily
343 true; the debug info might be much richer than the
344 object's symbol table. */
345 p = find_pc_sect_psymbol (pst, pc, section);
347 || SYMBOL_VALUE_ADDRESS (p)
348 != SYMBOL_VALUE_ADDRESS (msymbol))
352 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
353 PSYMTABS_ADDRMAP we used has already the best 1-byte
354 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
355 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
364 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
365 which still have no corresponding full SYMTABs read. But it is not
366 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
369 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
370 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
371 debug info type in single OBJFILE. */
373 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
374 if (!pst->psymtabs_addrmap_supported
375 && pc >= pst->textlow && pc < pst->texthigh)
377 struct partial_symtab *best_pst;
379 best_pst = find_pc_sect_psymtab_closer (pc, section, pst, msymbol);
380 if (best_pst != NULL)
387 static struct symtab *
388 find_pc_sect_symtab_from_partial (struct objfile *objfile,
389 struct minimal_symbol *msymbol,
390 CORE_ADDR pc, struct obj_section *section,
393 struct partial_symtab *ps = find_pc_sect_psymtab (objfile, pc, section,
397 if (warn_if_readin && ps->readin)
398 /* Might want to error() here (in case symtab is corrupt and
399 will cause a core dump), but maybe we can successfully
400 continue, so let's not. */
402 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
403 paddress (get_objfile_arch (ps->objfile), pc));
404 psymtab_to_symtab (ps);
410 /* Find which partial symbol within a psymtab matches PC and SECTION.
413 static struct partial_symbol *
414 find_pc_sect_psymbol (struct partial_symtab *psymtab, CORE_ADDR pc,
415 struct obj_section *section)
417 struct partial_symbol *best = NULL, *p, **pp;
420 gdb_assert (psymtab != NULL);
422 /* Cope with programs that start at address 0. */
423 best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0;
425 /* Search the global symbols as well as the static symbols, so that
426 find_pc_partial_function doesn't use a minimal symbol and thus
427 cache a bad endaddr. */
428 for (pp = psymtab->objfile->global_psymbols.list + psymtab->globals_offset;
429 (pp - (psymtab->objfile->global_psymbols.list + psymtab->globals_offset)
430 < psymtab->n_global_syms);
434 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
435 && SYMBOL_CLASS (p) == LOC_BLOCK
436 && pc >= SYMBOL_VALUE_ADDRESS (p)
437 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
438 || (psymtab->textlow == 0
439 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
441 if (section) /* Match on a specific section. */
443 fixup_psymbol_section (p, psymtab->objfile);
444 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
447 best_pc = SYMBOL_VALUE_ADDRESS (p);
452 for (pp = psymtab->objfile->static_psymbols.list + psymtab->statics_offset;
453 (pp - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset)
454 < psymtab->n_static_syms);
458 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
459 && SYMBOL_CLASS (p) == LOC_BLOCK
460 && pc >= SYMBOL_VALUE_ADDRESS (p)
461 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
462 || (psymtab->textlow == 0
463 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
465 if (section) /* Match on a specific section. */
467 fixup_psymbol_section (p, psymtab->objfile);
468 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
471 best_pc = SYMBOL_VALUE_ADDRESS (p);
479 static struct partial_symbol *
480 fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
487 if (SYMBOL_OBJ_SECTION (psym))
490 gdb_assert (objfile);
492 switch (SYMBOL_CLASS (psym))
497 addr = SYMBOL_VALUE_ADDRESS (psym);
500 /* Nothing else will be listed in the minsyms -- no use looking
505 fixup_section (&psym->ginfo, addr, objfile);
510 static struct symtab *
511 lookup_symbol_aux_psymtabs (struct objfile *objfile,
512 int block_index, const char *name,
513 const domain_enum domain)
515 struct partial_symtab *ps;
516 const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
517 struct symtab *stab_best = NULL;
519 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
521 if (!ps->readin && lookup_partial_symbol (ps, name, psymtab_index, domain))
523 struct symbol *sym = NULL;
524 struct symtab *stab = psymtab_to_symtab (ps);
526 /* Some caution must be observed with overloaded functions
527 and methods, since the psymtab will not contain any overload
528 information (but NAME might contain it). */
531 struct blockvector *bv = BLOCKVECTOR (stab);
532 struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
534 sym = lookup_block_symbol (block, name, domain);
537 if (sym && strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0)
539 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
545 /* Keep looking through other psymtabs. */
552 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
553 the global block of PST if GLOBAL, and otherwise the static block.
554 MATCH is the comparison operation that returns true iff MATCH (s,
555 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
556 non-null, the symbols in the block are assumed to be ordered
557 according to it (allowing binary search). It must be compatible
558 with MATCH. Returns the symbol, if found, and otherwise NULL. */
560 static struct partial_symbol *
561 match_partial_symbol (struct partial_symtab *pst, int global,
562 const char *name, domain_enum domain,
563 symbol_compare_ftype *match,
564 symbol_compare_ftype *ordered_compare)
566 struct partial_symbol **start, **psym;
567 struct partial_symbol **top, **real_top, **bottom, **center;
568 int length = (global ? pst->n_global_syms : pst->n_static_syms);
569 int do_linear_search = 1;
574 pst->objfile->global_psymbols.list + pst->globals_offset :
575 pst->objfile->static_psymbols.list + pst->statics_offset);
577 if (global && ordered_compare) /* Can use a binary search. */
579 do_linear_search = 0;
581 /* Binary search. This search is guaranteed to end with center
582 pointing at the earliest partial symbol whose name might be
583 correct. At that point *all* partial symbols with an
584 appropriate name will be checked against the correct
588 top = start + length - 1;
592 center = bottom + (top - bottom) / 2;
593 gdb_assert (center < top);
594 if (!do_linear_search
595 && (SYMBOL_LANGUAGE (*center) == language_java))
596 do_linear_search = 1;
597 if (ordered_compare (SYMBOL_SEARCH_NAME (*center), name) >= 0)
602 gdb_assert (top == bottom);
604 while (top <= real_top
605 && match (SYMBOL_SEARCH_NAME (*top), name) == 0)
607 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
608 SYMBOL_DOMAIN (*top), domain))
614 /* Can't use a binary search or else we found during the binary search that
615 we should also do a linear search. */
617 if (do_linear_search)
619 for (psym = start; psym < start + length; psym++)
621 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
622 SYMBOL_DOMAIN (*psym), domain)
623 && match (SYMBOL_SEARCH_NAME (*psym), name) == 0)
632 pre_expand_symtabs_matching_psymtabs (struct objfile *objfile,
633 enum block_enum block_kind,
640 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
641 not contain any method/function instance information (since this would
642 force reading type information while reading psymtabs). Therefore,
643 if NAME contains overload information, it must be stripped before searching
646 The caller is responsible for freeing the return result. */
649 psymtab_search_name (const char *name)
651 switch (current_language->la_language)
656 if (strchr (name, '('))
658 char *ret = cp_remove_params (name);
670 return xstrdup (name);
673 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
674 Check the global symbols if GLOBAL, the static symbols if not. */
676 static struct partial_symbol *
677 lookup_partial_symbol (struct partial_symtab *pst, const char *name,
678 int global, domain_enum domain)
680 struct partial_symbol **start, **psym;
681 struct partial_symbol **top, **real_top, **bottom, **center;
682 int length = (global ? pst->n_global_syms : pst->n_static_syms);
683 int do_linear_search = 1;
685 struct cleanup *cleanup;
692 search_name = psymtab_search_name (name);
693 cleanup = make_cleanup (xfree, search_name);
695 pst->objfile->global_psymbols.list + pst->globals_offset :
696 pst->objfile->static_psymbols.list + pst->statics_offset);
698 if (global) /* This means we can use a binary search. */
700 do_linear_search = 0;
702 /* Binary search. This search is guaranteed to end with center
703 pointing at the earliest partial symbol whose name might be
704 correct. At that point *all* partial symbols with an
705 appropriate name will be checked against the correct
709 top = start + length - 1;
713 center = bottom + (top - bottom) / 2;
715 internal_error (__FILE__, __LINE__,
716 _("failed internal consistency check"));
717 if (!do_linear_search
718 && SYMBOL_LANGUAGE (*center) == language_java)
720 do_linear_search = 1;
722 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center),
732 if (!(top == bottom))
733 internal_error (__FILE__, __LINE__,
734 _("failed internal consistency check"));
736 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
737 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
738 while (top >= start && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
741 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
744 while (top <= real_top && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
746 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
747 SYMBOL_DOMAIN (*top), domain))
749 do_cleanups (cleanup);
756 /* Can't use a binary search or else we found during the binary search that
757 we should also do a linear search. */
759 if (do_linear_search)
761 for (psym = start; psym < start + length; psym++)
763 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
764 SYMBOL_DOMAIN (*psym), domain)
765 && SYMBOL_MATCHES_SEARCH_NAME (*psym, search_name))
767 do_cleanups (cleanup);
773 do_cleanups (cleanup);
777 /* Get the symbol table that corresponds to a partial_symtab.
778 This is fast after the first time you do it. */
780 static struct symtab *
781 psymtab_to_symtab (struct partial_symtab *pst)
783 /* If it is a shared psymtab, find an unshared psymtab that includes
784 it. Any such psymtab will do. */
785 while (pst->user != NULL)
788 /* If it's been looked up before, return it. */
792 /* If it has not yet been read in, read it. */
795 struct cleanup *back_to = increment_reading_symtab ();
797 (*pst->read_symtab) (pst);
798 do_cleanups (back_to);
805 relocate_psymtabs (struct objfile *objfile,
806 struct section_offsets *new_offsets,
807 struct section_offsets *delta)
809 struct partial_symbol **psym;
810 struct partial_symtab *p;
812 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
814 p->textlow += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
815 p->texthigh += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
818 for (psym = objfile->global_psymbols.list;
819 psym < objfile->global_psymbols.next;
822 fixup_psymbol_section (*psym, objfile);
823 if (SYMBOL_SECTION (*psym) >= 0)
824 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
825 SYMBOL_SECTION (*psym));
827 for (psym = objfile->static_psymbols.list;
828 psym < objfile->static_psymbols.next;
831 fixup_psymbol_section (*psym, objfile);
832 if (SYMBOL_SECTION (*psym) >= 0)
833 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
834 SYMBOL_SECTION (*psym));
838 static struct symtab *
839 find_last_source_symtab_from_partial (struct objfile *ofp)
841 struct partial_symtab *ps;
842 struct partial_symtab *cs_pst = 0;
844 ALL_OBJFILE_PSYMTABS_REQUIRED (ofp, ps)
846 const char *name = ps->filename;
847 int len = strlen (name);
849 if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0
850 || strcmp (name, "<<C++-namespaces>>") == 0)))
858 internal_error (__FILE__, __LINE__,
859 _("select_source_symtab: "
860 "readin pst found and no symtabs."));
863 return psymtab_to_symtab (cs_pst);
869 forget_cached_source_info_partial (struct objfile *objfile)
871 struct partial_symtab *pst;
873 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
875 if (pst->fullname != NULL)
877 xfree (pst->fullname);
878 pst->fullname = NULL;
884 print_partial_symbols (struct gdbarch *gdbarch,
885 struct partial_symbol **p, int count, char *what,
886 struct ui_file *outfile)
888 fprintf_filtered (outfile, " %s partial symbols:\n", what);
891 fprintf_filtered (outfile, " `%s'", SYMBOL_LINKAGE_NAME (*p));
892 if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
894 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
896 fputs_filtered (", ", outfile);
897 switch (SYMBOL_DOMAIN (*p))
900 fputs_filtered ("undefined domain, ", outfile);
903 /* This is the usual thing -- don't print it. */
906 fputs_filtered ("struct domain, ", outfile);
909 fputs_filtered ("label domain, ", outfile);
912 fputs_filtered ("<invalid domain>, ", outfile);
915 switch (SYMBOL_CLASS (*p))
918 fputs_filtered ("undefined", outfile);
921 fputs_filtered ("constant int", outfile);
924 fputs_filtered ("static", outfile);
927 fputs_filtered ("register", outfile);
930 fputs_filtered ("pass by value", outfile);
933 fputs_filtered ("pass by reference", outfile);
935 case LOC_REGPARM_ADDR:
936 fputs_filtered ("register address parameter", outfile);
939 fputs_filtered ("stack parameter", outfile);
942 fputs_filtered ("type", outfile);
945 fputs_filtered ("label", outfile);
948 fputs_filtered ("function", outfile);
950 case LOC_CONST_BYTES:
951 fputs_filtered ("constant bytes", outfile);
954 fputs_filtered ("unresolved", outfile);
956 case LOC_OPTIMIZED_OUT:
957 fputs_filtered ("optimized out", outfile);
960 fputs_filtered ("computed at runtime", outfile);
963 fputs_filtered ("<invalid location>", outfile);
966 fputs_filtered (", ", outfile);
967 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (*p)), outfile);
968 fprintf_filtered (outfile, "\n");
974 dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
975 struct ui_file *outfile)
977 struct gdbarch *gdbarch = get_objfile_arch (objfile);
980 if (psymtab->anonymous)
982 fprintf_filtered (outfile, "\nAnonymous partial symtab (%s) ",
987 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
990 fprintf_filtered (outfile, "(object ");
991 gdb_print_host_address (psymtab, outfile);
992 fprintf_filtered (outfile, ")\n\n");
993 fprintf_unfiltered (outfile, " Read from object file %s (",
995 gdb_print_host_address (objfile, outfile);
996 fprintf_unfiltered (outfile, ")\n");
1000 fprintf_filtered (outfile,
1001 " Full symtab was read (at ");
1002 gdb_print_host_address (psymtab->symtab, outfile);
1003 fprintf_filtered (outfile, " by function at ");
1004 gdb_print_host_address (psymtab->read_symtab, outfile);
1005 fprintf_filtered (outfile, ")\n");
1008 fprintf_filtered (outfile, " Relocate symbols by ");
1009 for (i = 0; i < psymtab->objfile->num_sections; ++i)
1012 fprintf_filtered (outfile, ", ");
1014 fputs_filtered (paddress (gdbarch,
1015 ANOFFSET (psymtab->section_offsets, i)),
1018 fprintf_filtered (outfile, "\n");
1020 fprintf_filtered (outfile, " Symbols cover text addresses ");
1021 fputs_filtered (paddress (gdbarch, psymtab->textlow), outfile);
1022 fprintf_filtered (outfile, "-");
1023 fputs_filtered (paddress (gdbarch, psymtab->texthigh), outfile);
1024 fprintf_filtered (outfile, "\n");
1025 fprintf_filtered (outfile, " Address map supported - %s.\n",
1026 psymtab->psymtabs_addrmap_supported ? "yes" : "no");
1027 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
1028 psymtab->number_of_dependencies);
1029 for (i = 0; i < psymtab->number_of_dependencies; i++)
1031 fprintf_filtered (outfile, " %d ", i);
1032 gdb_print_host_address (psymtab->dependencies[i], outfile);
1033 fprintf_filtered (outfile, " %s\n",
1034 psymtab->dependencies[i]->filename);
1036 if (psymtab->user != NULL)
1038 fprintf_filtered (outfile, " Shared partial symtab with user ");
1039 gdb_print_host_address (psymtab->user, outfile);
1040 fprintf_filtered (outfile, "\n");
1042 if (psymtab->n_global_syms > 0)
1044 print_partial_symbols (gdbarch,
1045 objfile->global_psymbols.list
1046 + psymtab->globals_offset,
1047 psymtab->n_global_syms, "Global", outfile);
1049 if (psymtab->n_static_syms > 0)
1051 print_partial_symbols (gdbarch,
1052 objfile->static_psymbols.list
1053 + psymtab->statics_offset,
1054 psymtab->n_static_syms, "Static", outfile);
1056 fprintf_filtered (outfile, "\n");
1060 print_psymtab_stats_for_objfile (struct objfile *objfile)
1063 struct partial_symtab *ps;
1066 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1068 if (ps->readin == 0)
1071 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i);
1075 dump_psymtabs_for_objfile (struct objfile *objfile)
1077 struct partial_symtab *psymtab;
1079 if (objfile->psymtabs)
1081 printf_filtered ("Psymtabs:\n");
1082 for (psymtab = objfile->psymtabs;
1084 psymtab = psymtab->next)
1086 printf_filtered ("%s at ",
1088 gdb_print_host_address (psymtab, gdb_stdout);
1089 printf_filtered (", ");
1090 if (psymtab->objfile != objfile)
1092 printf_filtered ("NOT ON CHAIN! ");
1096 printf_filtered ("\n\n");
1100 /* Look through the partial symtabs for all symbols which begin
1101 by matching FUNC_NAME. Make sure we read that symbol table in. */
1104 read_symtabs_for_function (struct objfile *objfile, const char *func_name)
1106 struct partial_symtab *ps;
1108 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1113 if ((lookup_partial_symbol (ps, func_name, 1, VAR_DOMAIN)
1115 || (lookup_partial_symbol (ps, func_name, 0, VAR_DOMAIN)
1117 psymtab_to_symtab (ps);
1122 expand_partial_symbol_tables (struct objfile *objfile)
1124 struct partial_symtab *psymtab;
1126 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
1128 psymtab_to_symtab (psymtab);
1133 read_psymtabs_with_filename (struct objfile *objfile, const char *filename)
1135 struct partial_symtab *p;
1137 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
1139 /* Anonymous psymtabs don't have a name of a source file. */
1143 if (filename_cmp (filename, p->filename) == 0)
1144 psymtab_to_symtab (p);
1149 map_symbol_filenames_psymtab (struct objfile *objfile,
1150 symbol_filename_ftype *fun, void *data,
1153 struct partial_symtab *ps;
1155 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1157 const char *fullname;
1162 /* Anonymous psymtabs don't have a file name. */
1168 fullname = psymtab_to_fullname (ps);
1171 (*fun) (ps->filename, fullname, data);
1175 /* Finds the fullname that a partial_symtab represents.
1177 If this functions finds the fullname, it will save it in ps->fullname
1178 and it will also return the value.
1180 If this function fails to find the file that this partial_symtab represents,
1181 NULL will be returned and ps->fullname will be set to NULL. */
1184 psymtab_to_fullname (struct partial_symtab *ps)
1193 /* Use cached copy if we have it.
1194 We rely on forget_cached_source_info being called appropriately
1195 to handle cases like the file being moved. */
1197 return ps->fullname;
1199 r = find_and_open_source (ps->filename, ps->dirname, &ps->fullname);
1204 return ps->fullname;
1211 find_symbol_file_from_partial (struct objfile *objfile, const char *name)
1213 struct partial_symtab *pst;
1215 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
1217 if (lookup_partial_symbol (pst, name, 1, VAR_DOMAIN))
1218 return pst->filename;
1223 /* For all symbols, s, in BLOCK that are in NAMESPACE and match NAME
1224 according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
1225 BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK
1226 ever returns non-zero, and otherwise returns 0. */
1229 map_block (const char *name, domain_enum namespace, struct objfile *objfile,
1230 struct block *block,
1231 int (*callback) (struct block *, struct symbol *, void *),
1232 void *data, symbol_compare_ftype *match)
1234 struct block_iterator iter;
1237 for (sym = block_iter_match_first (block, name, match, &iter);
1238 sym != NULL; sym = block_iter_match_next (name, match, &iter))
1240 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
1241 SYMBOL_DOMAIN (sym), namespace))
1243 if (callback (block, sym, data))
1251 /* Psymtab version of map_matching_symbols. See its definition in
1252 the definition of quick_symbol_functions in symfile.h. */
1255 map_matching_symbols_psymtab (const char *name, domain_enum namespace,
1256 struct objfile *objfile, int global,
1257 int (*callback) (struct block *,
1258 struct symbol *, void *),
1260 symbol_compare_ftype *match,
1261 symbol_compare_ftype *ordered_compare)
1263 const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
1264 struct partial_symtab *ps;
1266 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1270 || match_partial_symbol (ps, global, name, namespace, match,
1273 struct symtab *s = psymtab_to_symtab (ps);
1274 struct block *block;
1276 if (s == NULL || !s->primary)
1278 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), block_kind);
1279 if (map_block (name, namespace, objfile, block,
1280 callback, data, match))
1282 if (callback (block, NULL, data))
1288 /* A helper for expand_symtabs_matching_via_partial that handles
1289 searching included psymtabs. This returns 1 if a symbol is found,
1290 and zero otherwise. It also updates the 'searched_flag' on the
1291 various psymtabs that it searches. */
1294 recursively_search_psymtabs (struct partial_symtab *ps,
1295 struct objfile *objfile,
1296 enum search_domain kind,
1297 int (*name_matcher) (const char *, void *),
1300 struct partial_symbol **psym;
1301 struct partial_symbol **bound, **gbound, **sbound;
1303 int result = PST_SEARCHED_AND_NOT_FOUND;
1306 if (ps->searched_flag != PST_NOT_SEARCHED)
1307 return ps->searched_flag == PST_SEARCHED_AND_FOUND;
1309 /* Recurse into shared psymtabs first, because they may have already
1310 been searched, and this could save some time. */
1311 for (i = 0; i < ps->number_of_dependencies; ++i)
1315 /* Skip non-shared dependencies, these are handled elsewhere. */
1316 if (ps->dependencies[i]->user == NULL)
1319 r = recursively_search_psymtabs (ps->dependencies[i],
1320 objfile, kind, name_matcher, data);
1323 ps->searched_flag = PST_SEARCHED_AND_FOUND;
1328 gbound = (objfile->global_psymbols.list
1329 + ps->globals_offset + ps->n_global_syms);
1330 sbound = (objfile->static_psymbols.list
1331 + ps->statics_offset + ps->n_static_syms);
1334 /* Go through all of the symbols stored in a partial
1335 symtab in one loop. */
1336 psym = objfile->global_psymbols.list + ps->globals_offset;
1341 if (bound == gbound && ps->n_static_syms != 0)
1343 psym = objfile->static_psymbols.list + ps->statics_offset;
1354 if ((kind == ALL_DOMAIN
1355 || (kind == VARIABLES_DOMAIN
1356 && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
1357 && SYMBOL_CLASS (*psym) != LOC_BLOCK)
1358 || (kind == FUNCTIONS_DOMAIN
1359 && SYMBOL_CLASS (*psym) == LOC_BLOCK)
1360 || (kind == TYPES_DOMAIN
1361 && SYMBOL_CLASS (*psym) == LOC_TYPEDEF))
1362 && (*name_matcher) (SYMBOL_SEARCH_NAME (*psym), data))
1364 /* Found a match, so notify our caller. */
1365 result = PST_SEARCHED_AND_FOUND;
1372 ps->searched_flag = result;
1373 return result == PST_SEARCHED_AND_FOUND;
1377 expand_symtabs_matching_via_partial
1378 (struct objfile *objfile,
1379 int (*file_matcher) (const char *, void *),
1380 int (*name_matcher) (const char *, void *),
1381 enum search_domain kind,
1384 struct partial_symtab *ps;
1386 /* Clear the search flags. */
1387 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1389 ps->searched_flag = PST_NOT_SEARCHED;
1392 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1397 /* We skip shared psymtabs because file-matching doesn't apply
1398 to them; but we search them later in the loop. */
1399 if (ps->user != NULL)
1406 if (! (*file_matcher) (ps->filename, data))
1410 if (recursively_search_psymtabs (ps, objfile, kind, name_matcher, data))
1411 psymtab_to_symtab (ps);
1416 objfile_has_psyms (struct objfile *objfile)
1418 return objfile->psymtabs != NULL;
1421 const struct quick_symbol_functions psym_functions =
1424 find_last_source_symtab_from_partial,
1425 forget_cached_source_info_partial,
1426 partial_map_symtabs_matching_filename,
1427 lookup_symbol_aux_psymtabs,
1428 pre_expand_symtabs_matching_psymtabs,
1429 print_psymtab_stats_for_objfile,
1430 dump_psymtabs_for_objfile,
1432 read_symtabs_for_function,
1433 expand_partial_symbol_tables,
1434 read_psymtabs_with_filename,
1435 find_symbol_file_from_partial,
1436 map_matching_symbols_psymtab,
1437 expand_symtabs_matching_via_partial,
1438 find_pc_sect_symtab_from_partial,
1439 map_symbol_filenames_psymtab
1444 /* This compares two partial symbols by names, using strcmp_iw_ordered
1445 for the comparison. */
1448 compare_psymbols (const void *s1p, const void *s2p)
1450 struct partial_symbol *const *s1 = s1p;
1451 struct partial_symbol *const *s2 = s2p;
1453 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1),
1454 SYMBOL_SEARCH_NAME (*s2));
1458 sort_pst_symbols (struct partial_symtab *pst)
1460 /* Sort the global list; don't sort the static list. */
1462 qsort (pst->objfile->global_psymbols.list + pst->globals_offset,
1463 pst->n_global_syms, sizeof (struct partial_symbol *),
1467 /* Allocate and partially fill a partial symtab. It will be
1468 completely filled at the end of the symbol list.
1470 FILENAME is the name of the symbol-file we are reading from. */
1472 struct partial_symtab *
1473 start_psymtab_common (struct objfile *objfile,
1474 struct section_offsets *section_offsets,
1475 const char *filename,
1476 CORE_ADDR textlow, struct partial_symbol **global_syms,
1477 struct partial_symbol **static_syms)
1479 struct partial_symtab *psymtab;
1481 psymtab = allocate_psymtab (filename, objfile);
1482 psymtab->section_offsets = section_offsets;
1483 psymtab->textlow = textlow;
1484 psymtab->texthigh = psymtab->textlow; /* default */
1485 psymtab->globals_offset = global_syms - objfile->global_psymbols.list;
1486 psymtab->statics_offset = static_syms - objfile->static_psymbols.list;
1490 /* Calculate a hash code for the given partial symbol. The hash is
1491 calculated using the symbol's value, language, domain, class
1492 and name. These are the values which are set by
1493 add_psymbol_to_bcache. */
1495 static unsigned long
1496 psymbol_hash (const void *addr, int length)
1498 unsigned long h = 0;
1499 struct partial_symbol *psymbol = (struct partial_symbol *) addr;
1500 unsigned int lang = psymbol->ginfo.language;
1501 unsigned int domain = PSYMBOL_DOMAIN (psymbol);
1502 unsigned int class = PSYMBOL_CLASS (psymbol);
1504 h = hash_continue (&psymbol->ginfo.value, sizeof (psymbol->ginfo.value), h);
1505 h = hash_continue (&lang, sizeof (unsigned int), h);
1506 h = hash_continue (&domain, sizeof (unsigned int), h);
1507 h = hash_continue (&class, sizeof (unsigned int), h);
1508 h = hash_continue (psymbol->ginfo.name, strlen (psymbol->ginfo.name), h);
1513 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1514 For the comparison this function uses a symbols value,
1515 language, domain, class and name. */
1518 psymbol_compare (const void *addr1, const void *addr2, int length)
1520 struct partial_symbol *sym1 = (struct partial_symbol *) addr1;
1521 struct partial_symbol *sym2 = (struct partial_symbol *) addr2;
1523 return (memcmp (&sym1->ginfo.value, &sym1->ginfo.value,
1524 sizeof (sym1->ginfo.value)) == 0
1525 && sym1->ginfo.language == sym2->ginfo.language
1526 && PSYMBOL_DOMAIN (sym1) == PSYMBOL_DOMAIN (sym2)
1527 && PSYMBOL_CLASS (sym1) == PSYMBOL_CLASS (sym2)
1528 && sym1->ginfo.name == sym2->ginfo.name);
1531 /* Initialize a partial symbol bcache. */
1533 struct psymbol_bcache *
1534 psymbol_bcache_init (void)
1536 struct psymbol_bcache *bcache = XCALLOC (1, struct psymbol_bcache);
1537 bcache->bcache = bcache_xmalloc (psymbol_hash, psymbol_compare);
1541 /* Free a partial symbol bcache. */
1543 psymbol_bcache_free (struct psymbol_bcache *bcache)
1548 bcache_xfree (bcache->bcache);
1552 /* Return the internal bcache of the psymbol_bcache BCACHE. */
1555 psymbol_bcache_get_bcache (struct psymbol_bcache *bcache)
1557 return bcache->bcache;
1560 /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1561 symbol before, add a copy to BCACHE. In either case, return a pointer
1562 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1563 1 in case of new entry or 0 if returning an old entry. */
1565 static const struct partial_symbol *
1566 psymbol_bcache_full (struct partial_symbol *sym,
1567 struct psymbol_bcache *bcache,
1570 return bcache_full (sym,
1571 sizeof (struct partial_symbol),
1576 /* Helper function, initialises partial symbol structure and stashes
1577 it into objfile's bcache. Note that our caching mechanism will
1578 use all fields of struct partial_symbol to determine hash value of the
1579 structure. In other words, having two symbols with the same name but
1580 different domain (or address) is possible and correct. */
1582 static const struct partial_symbol *
1583 add_psymbol_to_bcache (const char *name, int namelength, int copy_name,
1585 enum address_class class,
1586 long val, /* Value as a long */
1587 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1588 enum language language, struct objfile *objfile,
1591 struct partial_symbol psymbol;
1593 /* We must ensure that the entire 'value' field has been zeroed
1594 before assigning to it, because an assignment may not write the
1596 memset (&psymbol.ginfo.value, 0, sizeof (psymbol.ginfo.value));
1598 /* val and coreaddr are mutually exclusive, one of them *will* be zero. */
1601 SYMBOL_VALUE (&psymbol) = val;
1605 SYMBOL_VALUE_ADDRESS (&psymbol) = coreaddr;
1607 SYMBOL_SECTION (&psymbol) = 0;
1608 SYMBOL_OBJ_SECTION (&psymbol) = NULL;
1609 SYMBOL_SET_LANGUAGE (&psymbol, language);
1610 PSYMBOL_DOMAIN (&psymbol) = domain;
1611 PSYMBOL_CLASS (&psymbol) = class;
1613 SYMBOL_SET_NAMES (&psymbol, name, namelength, copy_name, objfile);
1615 /* Stash the partial symbol away in the cache. */
1616 return psymbol_bcache_full (&psymbol,
1617 objfile->psymbol_cache,
1621 /* Increase the space allocated for LISTP, which is probably
1622 global_psymbols or static_psymbols. This space will eventually
1623 be freed in free_objfile(). */
1626 extend_psymbol_list (struct psymbol_allocation_list *listp,
1627 struct objfile *objfile)
1631 if (listp->size == 0)
1634 listp->list = (struct partial_symbol **)
1635 xmalloc (new_size * sizeof (struct partial_symbol *));
1639 new_size = listp->size * 2;
1640 listp->list = (struct partial_symbol **)
1641 xrealloc ((char *) listp->list,
1642 new_size * sizeof (struct partial_symbol *));
1644 /* Next assumes we only went one over. Should be good if
1645 program works correctly. */
1646 listp->next = listp->list + listp->size;
1647 listp->size = new_size;
1650 /* Helper function, adds partial symbol to the given partial symbol
1654 append_psymbol_to_list (struct psymbol_allocation_list *list,
1655 const struct partial_symbol *psym,
1656 struct objfile *objfile)
1658 if (list->next >= list->list + list->size)
1659 extend_psymbol_list (list, objfile);
1660 *list->next++ = (struct partial_symbol *) psym;
1661 OBJSTAT (objfile, n_psyms++);
1664 /* Add a symbol with a long value to a psymtab.
1665 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1666 Return the partial symbol that has been added. */
1669 add_psymbol_to_list (const char *name, int namelength, int copy_name,
1671 enum address_class class,
1672 struct psymbol_allocation_list *list,
1673 long val, /* Value as a long */
1674 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1675 enum language language, struct objfile *objfile)
1677 const struct partial_symbol *psym;
1681 /* Stash the partial symbol away in the cache. */
1682 psym = add_psymbol_to_bcache (name, namelength, copy_name, domain, class,
1683 val, coreaddr, language, objfile, &added);
1685 /* Do not duplicate global partial symbols. */
1686 if (list == &objfile->global_psymbols
1690 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1691 append_psymbol_to_list (list, psym, objfile);
1694 /* Initialize storage for partial symbols. */
1697 init_psymbol_list (struct objfile *objfile, int total_symbols)
1699 /* Free any previously allocated psymbol lists. */
1701 if (objfile->global_psymbols.list)
1703 xfree (objfile->global_psymbols.list);
1705 if (objfile->static_psymbols.list)
1707 xfree (objfile->static_psymbols.list);
1710 /* Current best guess is that approximately a twentieth
1711 of the total symbols (in a debugging file) are global or static
1712 oriented symbols. */
1714 objfile->global_psymbols.size = total_symbols / 10;
1715 objfile->static_psymbols.size = total_symbols / 10;
1717 if (objfile->global_psymbols.size > 0)
1719 objfile->global_psymbols.next =
1720 objfile->global_psymbols.list = (struct partial_symbol **)
1721 xmalloc ((objfile->global_psymbols.size
1722 * sizeof (struct partial_symbol *)));
1724 if (objfile->static_psymbols.size > 0)
1726 objfile->static_psymbols.next =
1727 objfile->static_psymbols.list = (struct partial_symbol **)
1728 xmalloc ((objfile->static_psymbols.size
1729 * sizeof (struct partial_symbol *)));
1733 struct partial_symtab *
1734 allocate_psymtab (const char *filename, struct objfile *objfile)
1736 struct partial_symtab *psymtab;
1738 if (objfile->free_psymtabs)
1740 psymtab = objfile->free_psymtabs;
1741 objfile->free_psymtabs = psymtab->next;
1744 psymtab = (struct partial_symtab *)
1745 obstack_alloc (&objfile->objfile_obstack,
1746 sizeof (struct partial_symtab));
1748 memset (psymtab, 0, sizeof (struct partial_symtab));
1749 psymtab->filename = obsavestring (filename, strlen (filename),
1750 &objfile->objfile_obstack);
1751 psymtab->symtab = NULL;
1753 /* Prepend it to the psymtab list for the objfile it belongs to.
1754 Psymtabs are searched in most recent inserted -> least recent
1757 psymtab->objfile = objfile;
1758 psymtab->next = objfile->psymtabs;
1759 objfile->psymtabs = psymtab;
1761 if (symtab_create_debug)
1763 /* Be a bit clever with debugging messages, and don't print objfile
1764 every time, only when it changes. */
1765 static char *last_objfile_name = NULL;
1767 if (last_objfile_name == NULL
1768 || strcmp (last_objfile_name, objfile->name) != 0)
1770 xfree (last_objfile_name);
1771 last_objfile_name = xstrdup (objfile->name);
1772 fprintf_unfiltered (gdb_stdlog,
1773 "Creating one or more psymtabs for objfile %s ...\n",
1776 fprintf_unfiltered (gdb_stdlog,
1777 "Created psymtab %s for module %s.\n",
1778 host_address_to_string (psymtab), filename);
1785 discard_psymtab (struct partial_symtab *pst)
1787 struct partial_symtab **prev_pst;
1790 Empty psymtabs happen as a result of header files which don't
1791 have any symbols in them. There can be a lot of them. But this
1792 check is wrong, in that a psymtab with N_SLINE entries but
1793 nothing else is not empty, but we don't realize that. Fixing
1794 that without slowing things down might be tricky. */
1796 /* First, snip it out of the psymtab chain. */
1798 prev_pst = &(pst->objfile->psymtabs);
1799 while ((*prev_pst) != pst)
1800 prev_pst = &((*prev_pst)->next);
1801 (*prev_pst) = pst->next;
1803 /* Next, put it on a free list for recycling. */
1805 pst->next = pst->objfile->free_psymtabs;
1806 pst->objfile->free_psymtabs = pst;
1812 maintenance_print_psymbols (char *args, int from_tty)
1815 struct ui_file *outfile;
1816 struct cleanup *cleanups;
1817 char *symname = NULL;
1818 char *filename = DEV_TTY;
1819 struct objfile *objfile;
1820 struct partial_symtab *ps;
1827 print-psymbols takes an output file name and optional symbol file name"));
1829 argv = gdb_buildargv (args);
1830 cleanups = make_cleanup_freeargv (argv);
1832 if (argv[0] != NULL)
1835 /* If a second arg is supplied, it is a source file name to match on. */
1836 if (argv[1] != NULL)
1842 filename = tilde_expand (filename);
1843 make_cleanup (xfree, filename);
1845 outfile = gdb_fopen (filename, FOPEN_WT);
1847 perror_with_name (filename);
1848 make_cleanup_ui_file_delete (outfile);
1851 ALL_PSYMTABS (objfile, ps)
1852 if (symname == NULL || filename_cmp (symname, ps->filename) == 0)
1853 dump_psymtab (objfile, ps, outfile);
1855 do_cleanups (cleanups);
1858 /* List all the partial symbol tables whose names match REGEXP (optional). */
1860 maintenance_info_psymtabs (char *regexp, int from_tty)
1862 struct program_space *pspace;
1863 struct objfile *objfile;
1868 ALL_PSPACES (pspace)
1869 ALL_PSPACE_OBJFILES (pspace, objfile)
1871 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1872 struct partial_symtab *psymtab;
1874 /* We don't want to print anything for this objfile until we
1875 actually find a symtab whose name matches. */
1876 int printed_objfile_start = 0;
1878 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
1883 || re_exec (psymtab->filename))
1885 if (! printed_objfile_start)
1887 printf_filtered ("{ objfile %s ", objfile->name);
1889 printf_filtered ("((struct objfile *) %s)\n",
1890 host_address_to_string (objfile));
1891 printed_objfile_start = 1;
1894 printf_filtered (" { psymtab %s ", psymtab->filename);
1896 printf_filtered ("((struct partial_symtab *) %s)\n",
1897 host_address_to_string (psymtab));
1899 printf_filtered (" readin %s\n",
1900 psymtab->readin ? "yes" : "no");
1901 printf_filtered (" fullname %s\n",
1903 ? psymtab->fullname : "(null)");
1904 printf_filtered (" text addresses ");
1905 fputs_filtered (paddress (gdbarch, psymtab->textlow),
1907 printf_filtered (" -- ");
1908 fputs_filtered (paddress (gdbarch, psymtab->texthigh),
1910 printf_filtered ("\n");
1911 printf_filtered (" psymtabs_addrmap_supported %s\n",
1912 (psymtab->psymtabs_addrmap_supported
1914 printf_filtered (" globals ");
1915 if (psymtab->n_global_syms)
1917 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1918 host_address_to_string (psymtab->objfile->global_psymbols.list
1919 + psymtab->globals_offset),
1920 psymtab->n_global_syms);
1923 printf_filtered ("(none)\n");
1924 printf_filtered (" statics ");
1925 if (psymtab->n_static_syms)
1927 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1928 host_address_to_string (psymtab->objfile->static_psymbols.list
1929 + psymtab->statics_offset),
1930 psymtab->n_static_syms);
1933 printf_filtered ("(none)\n");
1934 printf_filtered (" dependencies ");
1935 if (psymtab->number_of_dependencies)
1939 printf_filtered ("{\n");
1940 for (i = 0; i < psymtab->number_of_dependencies; i++)
1942 struct partial_symtab *dep = psymtab->dependencies[i];
1944 /* Note the string concatenation there --- no comma. */
1945 printf_filtered (" psymtab %s "
1946 "((struct partial_symtab *) %s)\n",
1948 host_address_to_string (dep));
1950 printf_filtered (" }\n");
1953 printf_filtered ("(none)\n");
1954 printf_filtered (" }\n");
1958 if (printed_objfile_start)
1959 printf_filtered ("}\n");
1963 /* Check consistency of psymtabs and symtabs. */
1966 maintenance_check_symtabs (char *ignore, int from_tty)
1969 struct partial_symbol **psym;
1970 struct symtab *s = NULL;
1971 struct partial_symtab *ps;
1972 struct blockvector *bv;
1973 struct objfile *objfile;
1977 ALL_PSYMTABS (objfile, ps)
1979 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1981 s = psymtab_to_symtab (ps);
1984 bv = BLOCKVECTOR (s);
1985 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1986 psym = ps->objfile->static_psymbols.list + ps->statics_offset;
1987 length = ps->n_static_syms;
1990 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1991 SYMBOL_DOMAIN (*psym));
1994 printf_filtered ("Static symbol `");
1995 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1996 printf_filtered ("' only found in ");
1997 puts_filtered (ps->filename);
1998 printf_filtered (" psymtab\n");
2002 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
2003 psym = ps->objfile->global_psymbols.list + ps->globals_offset;
2004 length = ps->n_global_syms;
2007 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
2008 SYMBOL_DOMAIN (*psym));
2011 printf_filtered ("Global symbol `");
2012 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
2013 printf_filtered ("' only found in ");
2014 puts_filtered (ps->filename);
2015 printf_filtered (" psymtab\n");
2019 if (ps->texthigh < ps->textlow)
2021 printf_filtered ("Psymtab ");
2022 puts_filtered (ps->filename);
2023 printf_filtered (" covers bad range ");
2024 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
2025 printf_filtered (" - ");
2026 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
2027 printf_filtered ("\n");
2030 if (ps->texthigh == 0)
2032 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
2034 printf_filtered ("Psymtab ");
2035 puts_filtered (ps->filename);
2036 printf_filtered (" covers ");
2037 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
2038 printf_filtered (" - ");
2039 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
2040 printf_filtered (" but symtab covers only ");
2041 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
2042 printf_filtered (" - ");
2043 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout);
2044 printf_filtered ("\n");
2052 expand_partial_symbol_names (int (*fun) (const char *, void *),
2055 struct objfile *objfile;
2057 ALL_OBJFILES (objfile)
2060 objfile->sf->qf->expand_symtabs_matching (objfile, NULL, fun,
2066 map_partial_symbol_filenames (symbol_filename_ftype *fun, void *data,
2069 struct objfile *objfile;
2071 ALL_OBJFILES (objfile)
2074 objfile->sf->qf->map_symbol_filenames (objfile, fun, data,