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);
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 (compare_filenames_for_search (pst->filename, name))
183 if (partial_map_expand_apply (objfile, name, real_path,
184 pst, callback, data))
188 /* Before we invoke realpath, which can get expensive when many
189 files are involved, do a quick comparison of the basenames. */
190 if (! basenames_may_differ
191 && FILENAME_CMP (name_basename, lbasename (pst->filename)) != 0)
194 if (compare_filenames_for_search (psymtab_to_fullname (pst), name))
196 if (partial_map_expand_apply (objfile, name, real_path,
197 pst, callback, data))
201 /* If the user gave us an absolute path, try to find the file in
202 this symtab and use its absolute path. */
203 if (real_path != NULL)
205 gdb_assert (IS_ABSOLUTE_PATH (real_path));
206 gdb_assert (IS_ABSOLUTE_PATH (name));
207 if (filename_cmp (psymtab_to_fullname (pst), real_path) == 0)
209 if (partial_map_expand_apply (objfile, name, real_path,
210 pst, callback, data))
219 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
220 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
222 static struct partial_symtab *
223 find_pc_sect_psymtab_closer (struct objfile *objfile,
224 CORE_ADDR pc, struct obj_section *section,
225 struct partial_symtab *pst,
226 struct minimal_symbol *msymbol)
228 struct partial_symtab *tpst;
229 struct partial_symtab *best_pst = pst;
230 CORE_ADDR best_addr = pst->textlow;
232 gdb_assert (!pst->psymtabs_addrmap_supported);
234 /* An objfile that has its functions reordered might have
235 many partial symbol tables containing the PC, but
236 we want the partial symbol table that contains the
237 function containing the PC. */
238 if (!(objfile->flags & OBJF_REORDERED) &&
239 section == 0) /* Can't validate section this way. */
245 /* The code range of partial symtabs sometimes overlap, so, in
246 the loop below, we need to check all partial symtabs and
247 find the one that fits better for the given PC address. We
248 select the partial symtab that contains a symbol whose
249 address is closest to the PC address. By closest we mean
250 that find_pc_sect_symbol returns the symbol with address
251 that is closest and still less than the given PC. */
252 for (tpst = pst; tpst != NULL; tpst = tpst->next)
254 if (pc >= tpst->textlow && pc < tpst->texthigh)
256 struct partial_symbol *p;
259 /* NOTE: This assumes that every psymbol has a
260 corresponding msymbol, which is not necessarily
261 true; the debug info might be much richer than the
262 object's symbol table. */
263 p = find_pc_sect_psymbol (objfile, tpst, pc, section);
265 && SYMBOL_VALUE_ADDRESS (p)
266 == SYMBOL_VALUE_ADDRESS (msymbol))
269 /* Also accept the textlow value of a psymtab as a
270 "symbol", to provide some support for partial
271 symbol tables with line information but no debug
272 symbols (e.g. those produced by an assembler). */
274 this_addr = SYMBOL_VALUE_ADDRESS (p);
276 this_addr = tpst->textlow;
278 /* Check whether it is closer than our current
279 BEST_ADDR. Since this symbol address is
280 necessarily lower or equal to PC, the symbol closer
281 to PC is the symbol which address is the highest.
282 This way we return the psymtab which contains such
283 best match symbol. This can help in cases where the
284 symbol information/debuginfo is not complete, like
285 for instance on IRIX6 with gcc, where no debug info
286 is emitted for statics. (See also the nodebug.exp
288 if (this_addr > best_addr)
290 best_addr = this_addr;
298 /* Find which partial symtab contains PC and SECTION. Return 0 if
299 none. We return the psymtab that contains a symbol whose address
300 exactly matches PC, or, if we cannot find an exact match, the
301 psymtab that contains a symbol whose address is closest to PC. */
302 static struct partial_symtab *
303 find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
304 struct obj_section *section,
305 struct minimal_symbol *msymbol)
307 struct partial_symtab *pst;
309 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
310 than the later used TEXTLOW/TEXTHIGH one. */
312 if (objfile->psymtabs_addrmap != NULL)
314 pst = addrmap_find (objfile->psymtabs_addrmap, pc);
317 /* FIXME: addrmaps currently do not handle overlayed sections,
318 so fall back to the non-addrmap case if we're debugging
319 overlays and the addrmap returned the wrong section. */
320 if (overlay_debugging && msymbol && section)
322 struct partial_symbol *p;
324 /* NOTE: This assumes that every psymbol has a
325 corresponding msymbol, which is not necessarily
326 true; the debug info might be much richer than the
327 object's symbol table. */
328 p = find_pc_sect_psymbol (objfile, pst, pc, section);
330 || SYMBOL_VALUE_ADDRESS (p)
331 != SYMBOL_VALUE_ADDRESS (msymbol))
335 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
336 PSYMTABS_ADDRMAP we used has already the best 1-byte
337 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
338 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
347 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
348 which still have no corresponding full SYMTABs read. But it is not
349 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
352 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
353 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
354 debug info type in single OBJFILE. */
356 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
357 if (!pst->psymtabs_addrmap_supported
358 && pc >= pst->textlow && pc < pst->texthigh)
360 struct partial_symtab *best_pst;
362 best_pst = find_pc_sect_psymtab_closer (objfile, pc, section, pst,
364 if (best_pst != NULL)
371 static struct symtab *
372 find_pc_sect_symtab_from_partial (struct objfile *objfile,
373 struct minimal_symbol *msymbol,
374 CORE_ADDR pc, struct obj_section *section,
377 struct partial_symtab *ps = find_pc_sect_psymtab (objfile, pc, section,
381 if (warn_if_readin && ps->readin)
382 /* Might want to error() here (in case symtab is corrupt and
383 will cause a core dump), but maybe we can successfully
384 continue, so let's not. */
386 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
387 paddress (get_objfile_arch (objfile), pc));
388 psymtab_to_symtab (objfile, ps);
394 /* Find which partial symbol within a psymtab matches PC and SECTION.
397 static struct partial_symbol *
398 find_pc_sect_psymbol (struct objfile *objfile,
399 struct partial_symtab *psymtab, CORE_ADDR pc,
400 struct obj_section *section)
402 struct partial_symbol *best = NULL, *p, **pp;
405 gdb_assert (psymtab != NULL);
407 /* Cope with programs that start at address 0. */
408 best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0;
410 /* Search the global symbols as well as the static symbols, so that
411 find_pc_partial_function doesn't use a minimal symbol and thus
412 cache a bad endaddr. */
413 for (pp = objfile->global_psymbols.list + psymtab->globals_offset;
414 (pp - (objfile->global_psymbols.list + psymtab->globals_offset)
415 < psymtab->n_global_syms);
419 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
420 && SYMBOL_CLASS (p) == LOC_BLOCK
421 && pc >= SYMBOL_VALUE_ADDRESS (p)
422 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
423 || (psymtab->textlow == 0
424 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
426 if (section) /* Match on a specific section. */
428 fixup_psymbol_section (p, objfile);
429 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
432 best_pc = SYMBOL_VALUE_ADDRESS (p);
437 for (pp = objfile->static_psymbols.list + psymtab->statics_offset;
438 (pp - (objfile->static_psymbols.list + psymtab->statics_offset)
439 < psymtab->n_static_syms);
443 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
444 && SYMBOL_CLASS (p) == LOC_BLOCK
445 && pc >= SYMBOL_VALUE_ADDRESS (p)
446 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
447 || (psymtab->textlow == 0
448 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
450 if (section) /* Match on a specific section. */
452 fixup_psymbol_section (p, objfile);
453 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
456 best_pc = SYMBOL_VALUE_ADDRESS (p);
465 fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
469 if (psym == NULL || SYMBOL_OBJ_SECTION (psym) != NULL)
472 gdb_assert (objfile);
474 switch (SYMBOL_CLASS (psym))
479 addr = SYMBOL_VALUE_ADDRESS (psym);
482 /* Nothing else will be listed in the minsyms -- no use looking
487 fixup_section (&psym->ginfo, addr, objfile);
490 static struct symtab *
491 lookup_symbol_aux_psymtabs (struct objfile *objfile,
492 int block_index, const char *name,
493 const domain_enum domain)
495 struct partial_symtab *ps;
496 const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
497 struct symtab *stab_best = NULL;
499 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
501 if (!ps->readin && lookup_partial_symbol (objfile, ps, name,
502 psymtab_index, domain))
504 struct symbol *sym = NULL;
505 struct symtab *stab = psymtab_to_symtab (objfile, ps);
507 /* Some caution must be observed with overloaded functions
508 and methods, since the psymtab will not contain any overload
509 information (but NAME might contain it). */
512 struct blockvector *bv = BLOCKVECTOR (stab);
513 struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
515 sym = lookup_block_symbol (block, name, domain);
518 if (sym && strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0)
520 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
526 /* Keep looking through other psymtabs. */
533 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
534 the global block of PST if GLOBAL, and otherwise the static block.
535 MATCH is the comparison operation that returns true iff MATCH (s,
536 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
537 non-null, the symbols in the block are assumed to be ordered
538 according to it (allowing binary search). It must be compatible
539 with MATCH. Returns the symbol, if found, and otherwise NULL. */
541 static struct partial_symbol *
542 match_partial_symbol (struct objfile *objfile,
543 struct partial_symtab *pst, int global,
544 const char *name, domain_enum domain,
545 symbol_compare_ftype *match,
546 symbol_compare_ftype *ordered_compare)
548 struct partial_symbol **start, **psym;
549 struct partial_symbol **top, **real_top, **bottom, **center;
550 int length = (global ? pst->n_global_syms : pst->n_static_syms);
551 int do_linear_search = 1;
556 objfile->global_psymbols.list + pst->globals_offset :
557 objfile->static_psymbols.list + pst->statics_offset);
559 if (global && ordered_compare) /* Can use a binary search. */
561 do_linear_search = 0;
563 /* Binary search. This search is guaranteed to end with center
564 pointing at the earliest partial symbol whose name might be
565 correct. At that point *all* partial symbols with an
566 appropriate name will be checked against the correct
570 top = start + length - 1;
574 center = bottom + (top - bottom) / 2;
575 gdb_assert (center < top);
576 if (!do_linear_search
577 && (SYMBOL_LANGUAGE (*center) == language_java))
578 do_linear_search = 1;
579 if (ordered_compare (SYMBOL_SEARCH_NAME (*center), name) >= 0)
584 gdb_assert (top == bottom);
586 while (top <= real_top
587 && match (SYMBOL_SEARCH_NAME (*top), name) == 0)
589 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
590 SYMBOL_DOMAIN (*top), domain))
596 /* Can't use a binary search or else we found during the binary search that
597 we should also do a linear search. */
599 if (do_linear_search)
601 for (psym = start; psym < start + length; psym++)
603 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
604 SYMBOL_DOMAIN (*psym), domain)
605 && match (SYMBOL_SEARCH_NAME (*psym), name) == 0)
613 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
614 not contain any method/function instance information (since this would
615 force reading type information while reading psymtabs). Therefore,
616 if NAME contains overload information, it must be stripped before searching
619 The caller is responsible for freeing the return result. */
622 psymtab_search_name (const char *name)
624 switch (current_language->la_language)
629 if (strchr (name, '('))
631 char *ret = cp_remove_params (name);
643 return xstrdup (name);
646 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
647 Check the global symbols if GLOBAL, the static symbols if not. */
649 static struct partial_symbol *
650 lookup_partial_symbol (struct objfile *objfile,
651 struct partial_symtab *pst, const char *name,
652 int global, domain_enum domain)
654 struct partial_symbol **start, **psym;
655 struct partial_symbol **top, **real_top, **bottom, **center;
656 int length = (global ? pst->n_global_syms : pst->n_static_syms);
657 int do_linear_search = 1;
659 struct cleanup *cleanup;
666 search_name = psymtab_search_name (name);
667 cleanup = make_cleanup (xfree, search_name);
669 objfile->global_psymbols.list + pst->globals_offset :
670 objfile->static_psymbols.list + pst->statics_offset);
672 if (global) /* This means we can use a binary search. */
674 do_linear_search = 0;
676 /* Binary search. This search is guaranteed to end with center
677 pointing at the earliest partial symbol whose name might be
678 correct. At that point *all* partial symbols with an
679 appropriate name will be checked against the correct
683 top = start + length - 1;
687 center = bottom + (top - bottom) / 2;
689 internal_error (__FILE__, __LINE__,
690 _("failed internal consistency check"));
691 if (!do_linear_search
692 && SYMBOL_LANGUAGE (*center) == language_java)
694 do_linear_search = 1;
696 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center),
706 if (!(top == bottom))
707 internal_error (__FILE__, __LINE__,
708 _("failed internal consistency check"));
710 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
711 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
712 while (top >= start && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
715 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
718 while (top <= real_top && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
720 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
721 SYMBOL_DOMAIN (*top), domain))
723 do_cleanups (cleanup);
730 /* Can't use a binary search or else we found during the binary search that
731 we should also do a linear search. */
733 if (do_linear_search)
735 for (psym = start; psym < start + length; psym++)
737 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
738 SYMBOL_DOMAIN (*psym), domain)
739 && SYMBOL_MATCHES_SEARCH_NAME (*psym, search_name))
741 do_cleanups (cleanup);
747 do_cleanups (cleanup);
751 /* Get the symbol table that corresponds to a partial_symtab.
752 This is fast after the first time you do it. */
754 static struct symtab *
755 psymtab_to_symtab (struct objfile *objfile, struct partial_symtab *pst)
757 /* If it is a shared psymtab, find an unshared psymtab that includes
758 it. Any such psymtab will do. */
759 while (pst->user != NULL)
762 /* If it's been looked up before, return it. */
766 /* If it has not yet been read in, read it. */
769 struct cleanup *back_to = increment_reading_symtab ();
771 (*pst->read_symtab) (pst, objfile);
772 do_cleanups (back_to);
779 relocate_psymtabs (struct objfile *objfile,
780 struct section_offsets *new_offsets,
781 struct section_offsets *delta)
783 struct partial_symbol **psym;
784 struct partial_symtab *p;
786 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
788 p->textlow += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
789 p->texthigh += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
792 for (psym = objfile->global_psymbols.list;
793 psym < objfile->global_psymbols.next;
796 fixup_psymbol_section (*psym, objfile);
797 if (SYMBOL_SECTION (*psym) >= 0)
798 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
799 SYMBOL_SECTION (*psym));
801 for (psym = objfile->static_psymbols.list;
802 psym < objfile->static_psymbols.next;
805 fixup_psymbol_section (*psym, objfile);
806 if (SYMBOL_SECTION (*psym) >= 0)
807 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
808 SYMBOL_SECTION (*psym));
812 static struct symtab *
813 find_last_source_symtab_from_partial (struct objfile *ofp)
815 struct partial_symtab *ps;
816 struct partial_symtab *cs_pst = 0;
818 ALL_OBJFILE_PSYMTABS_REQUIRED (ofp, ps)
820 const char *name = ps->filename;
821 int len = strlen (name);
823 if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0
824 || strcmp (name, "<<C++-namespaces>>") == 0)))
832 internal_error (__FILE__, __LINE__,
833 _("select_source_symtab: "
834 "readin pst found and no symtabs."));
837 return psymtab_to_symtab (ofp, cs_pst);
843 forget_cached_source_info_partial (struct objfile *objfile)
845 struct partial_symtab *pst;
847 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
849 if (pst->fullname != NULL)
851 xfree (pst->fullname);
852 pst->fullname = NULL;
858 print_partial_symbols (struct gdbarch *gdbarch,
859 struct partial_symbol **p, int count, char *what,
860 struct ui_file *outfile)
862 fprintf_filtered (outfile, " %s partial symbols:\n", what);
866 fprintf_filtered (outfile, " `%s'", SYMBOL_LINKAGE_NAME (*p));
867 if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
869 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
871 fputs_filtered (", ", outfile);
872 switch (SYMBOL_DOMAIN (*p))
875 fputs_filtered ("undefined domain, ", outfile);
878 /* This is the usual thing -- don't print it. */
881 fputs_filtered ("struct domain, ", outfile);
884 fputs_filtered ("label domain, ", outfile);
887 fputs_filtered ("<invalid domain>, ", outfile);
890 switch (SYMBOL_CLASS (*p))
893 fputs_filtered ("undefined", outfile);
896 fputs_filtered ("constant int", outfile);
899 fputs_filtered ("static", outfile);
902 fputs_filtered ("register", outfile);
905 fputs_filtered ("pass by value", outfile);
908 fputs_filtered ("pass by reference", outfile);
910 case LOC_REGPARM_ADDR:
911 fputs_filtered ("register address parameter", outfile);
914 fputs_filtered ("stack parameter", outfile);
917 fputs_filtered ("type", outfile);
920 fputs_filtered ("label", outfile);
923 fputs_filtered ("function", outfile);
925 case LOC_CONST_BYTES:
926 fputs_filtered ("constant bytes", outfile);
929 fputs_filtered ("unresolved", outfile);
931 case LOC_OPTIMIZED_OUT:
932 fputs_filtered ("optimized out", outfile);
935 fputs_filtered ("computed at runtime", outfile);
938 fputs_filtered ("<invalid location>", outfile);
941 fputs_filtered (", ", outfile);
942 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (*p)), outfile);
943 fprintf_filtered (outfile, "\n");
949 dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
950 struct ui_file *outfile)
952 struct gdbarch *gdbarch = get_objfile_arch (objfile);
955 if (psymtab->anonymous)
957 fprintf_filtered (outfile, "\nAnonymous partial symtab (%s) ",
962 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
965 fprintf_filtered (outfile, "(object ");
966 gdb_print_host_address (psymtab, outfile);
967 fprintf_filtered (outfile, ")\n\n");
968 fprintf_unfiltered (outfile, " Read from object file %s (",
970 gdb_print_host_address (objfile, outfile);
971 fprintf_unfiltered (outfile, ")\n");
975 fprintf_filtered (outfile,
976 " Full symtab was read (at ");
977 gdb_print_host_address (psymtab->symtab, outfile);
978 fprintf_filtered (outfile, " by function at ");
979 gdb_print_host_address (psymtab->read_symtab, outfile);
980 fprintf_filtered (outfile, ")\n");
983 fprintf_filtered (outfile, " Relocate symbols by ");
984 for (i = 0; i < objfile->num_sections; ++i)
987 fprintf_filtered (outfile, ", ");
989 fputs_filtered (paddress (gdbarch,
990 ANOFFSET (psymtab->section_offsets, i)),
993 fprintf_filtered (outfile, "\n");
995 fprintf_filtered (outfile, " Symbols cover text addresses ");
996 fputs_filtered (paddress (gdbarch, psymtab->textlow), outfile);
997 fprintf_filtered (outfile, "-");
998 fputs_filtered (paddress (gdbarch, psymtab->texthigh), outfile);
999 fprintf_filtered (outfile, "\n");
1000 fprintf_filtered (outfile, " Address map supported - %s.\n",
1001 psymtab->psymtabs_addrmap_supported ? "yes" : "no");
1002 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
1003 psymtab->number_of_dependencies);
1004 for (i = 0; i < psymtab->number_of_dependencies; i++)
1006 fprintf_filtered (outfile, " %d ", i);
1007 gdb_print_host_address (psymtab->dependencies[i], outfile);
1008 fprintf_filtered (outfile, " %s\n",
1009 psymtab->dependencies[i]->filename);
1011 if (psymtab->user != NULL)
1013 fprintf_filtered (outfile, " Shared partial symtab with user ");
1014 gdb_print_host_address (psymtab->user, outfile);
1015 fprintf_filtered (outfile, "\n");
1017 if (psymtab->n_global_syms > 0)
1019 print_partial_symbols (gdbarch,
1020 objfile->global_psymbols.list
1021 + psymtab->globals_offset,
1022 psymtab->n_global_syms, "Global", outfile);
1024 if (psymtab->n_static_syms > 0)
1026 print_partial_symbols (gdbarch,
1027 objfile->static_psymbols.list
1028 + psymtab->statics_offset,
1029 psymtab->n_static_syms, "Static", outfile);
1031 fprintf_filtered (outfile, "\n");
1035 print_psymtab_stats_for_objfile (struct objfile *objfile)
1038 struct partial_symtab *ps;
1041 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1043 if (ps->readin == 0)
1046 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i);
1050 dump_psymtabs_for_objfile (struct objfile *objfile)
1052 struct partial_symtab *psymtab;
1054 if (objfile->psymtabs)
1056 printf_filtered ("Psymtabs:\n");
1057 for (psymtab = objfile->psymtabs;
1059 psymtab = psymtab->next)
1061 printf_filtered ("%s at ",
1063 gdb_print_host_address (psymtab, gdb_stdout);
1064 printf_filtered (", ");
1067 printf_filtered ("\n\n");
1071 /* Look through the partial symtabs for all symbols which begin
1072 by matching FUNC_NAME. Make sure we read that symbol table in. */
1075 read_symtabs_for_function (struct objfile *objfile, const char *func_name)
1077 struct partial_symtab *ps;
1079 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1084 if ((lookup_partial_symbol (objfile, ps, func_name, 1, VAR_DOMAIN)
1086 || (lookup_partial_symbol (objfile, ps, func_name, 0, VAR_DOMAIN)
1088 psymtab_to_symtab (objfile, ps);
1093 expand_partial_symbol_tables (struct objfile *objfile)
1095 struct partial_symtab *psymtab;
1097 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
1099 psymtab_to_symtab (objfile, psymtab);
1104 read_psymtabs_with_fullname (struct objfile *objfile, const char *fullname)
1106 struct partial_symtab *p;
1108 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
1110 /* Anonymous psymtabs don't have a name of a source file. */
1114 /* psymtab_to_fullname tries to open the file which is slow.
1115 Don't call it if we know the basenames don't match. */
1116 if ((basenames_may_differ
1117 || filename_cmp (lbasename (fullname), lbasename (p->filename)) == 0)
1118 && filename_cmp (fullname, psymtab_to_fullname (p)) == 0)
1119 psymtab_to_symtab (objfile, p);
1124 map_symbol_filenames_psymtab (struct objfile *objfile,
1125 symbol_filename_ftype *fun, void *data,
1128 struct partial_symtab *ps;
1130 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1132 const char *fullname;
1137 /* We can skip shared psymtabs here, because any file name will be
1138 attached to the unshared psymtab. */
1139 if (ps->user != NULL)
1142 /* Anonymous psymtabs don't have a file name. */
1148 fullname = psymtab_to_fullname (ps);
1151 (*fun) (ps->filename, fullname, data);
1155 /* Finds the fullname that a partial_symtab represents.
1157 If this functions finds the fullname, it will save it in ps->fullname
1158 and it will also return the value.
1160 If this function fails to find the file that this partial_symtab represents,
1161 NULL will be returned and ps->fullname will be set to NULL. */
1164 psymtab_to_fullname (struct partial_symtab *ps)
1166 gdb_assert (!ps->anonymous);
1168 /* Use cached copy if we have it.
1169 We rely on forget_cached_source_info being called appropriately
1170 to handle cases like the file being moved. */
1171 if (ps->fullname == NULL)
1173 int fd = find_and_open_source (ps->filename, ps->dirname, &ps->fullname);
1180 struct cleanup *back_to;
1182 /* rewrite_source_path would be applied by find_and_open_source, we
1183 should report the pathname where GDB tried to find the file. */
1185 if (ps->dirname == NULL || IS_ABSOLUTE_PATH (ps->filename))
1186 fullname = xstrdup (ps->filename);
1188 fullname = concat (ps->dirname, SLASH_STRING, ps->filename, NULL);
1190 back_to = make_cleanup (xfree, fullname);
1191 ps->fullname = rewrite_source_path (fullname);
1192 if (ps->fullname == NULL)
1193 ps->fullname = xstrdup (fullname);
1194 do_cleanups (back_to);
1198 return ps->fullname;
1202 find_symbol_file_from_partial (struct objfile *objfile, const char *name)
1204 struct partial_symtab *pst;
1206 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
1208 if (lookup_partial_symbol (objfile, pst, name, 1, VAR_DOMAIN))
1209 return pst->filename;
1214 /* For all symbols, s, in BLOCK that are in NAMESPACE and match NAME
1215 according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
1216 BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK
1217 ever returns non-zero, and otherwise returns 0. */
1220 map_block (const char *name, domain_enum namespace, struct objfile *objfile,
1221 struct block *block,
1222 int (*callback) (struct block *, struct symbol *, void *),
1223 void *data, symbol_compare_ftype *match)
1225 struct block_iterator iter;
1228 for (sym = block_iter_match_first (block, name, match, &iter);
1229 sym != NULL; sym = block_iter_match_next (name, match, &iter))
1231 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
1232 SYMBOL_DOMAIN (sym), namespace))
1234 if (callback (block, sym, data))
1242 /* Psymtab version of map_matching_symbols. See its definition in
1243 the definition of quick_symbol_functions in symfile.h. */
1246 map_matching_symbols_psymtab (const char *name, domain_enum namespace,
1247 struct objfile *objfile, int global,
1248 int (*callback) (struct block *,
1249 struct symbol *, void *),
1251 symbol_compare_ftype *match,
1252 symbol_compare_ftype *ordered_compare)
1254 const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
1255 struct partial_symtab *ps;
1257 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1261 || match_partial_symbol (objfile, ps, global, name, namespace, match,
1264 struct symtab *s = psymtab_to_symtab (objfile, ps);
1265 struct block *block;
1267 if (s == NULL || !s->primary)
1269 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), block_kind);
1270 if (map_block (name, namespace, objfile, block,
1271 callback, data, match))
1273 if (callback (block, NULL, data))
1279 /* A helper for expand_symtabs_matching_via_partial that handles
1280 searching included psymtabs. This returns 1 if a symbol is found,
1281 and zero otherwise. It also updates the 'searched_flag' on the
1282 various psymtabs that it searches. */
1285 recursively_search_psymtabs (struct partial_symtab *ps,
1286 struct objfile *objfile,
1287 enum search_domain kind,
1288 int (*name_matcher) (const char *, void *),
1291 struct partial_symbol **psym;
1292 struct partial_symbol **bound, **gbound, **sbound;
1294 int result = PST_SEARCHED_AND_NOT_FOUND;
1297 if (ps->searched_flag != PST_NOT_SEARCHED)
1298 return ps->searched_flag == PST_SEARCHED_AND_FOUND;
1300 /* Recurse into shared psymtabs first, because they may have already
1301 been searched, and this could save some time. */
1302 for (i = 0; i < ps->number_of_dependencies; ++i)
1306 /* Skip non-shared dependencies, these are handled elsewhere. */
1307 if (ps->dependencies[i]->user == NULL)
1310 r = recursively_search_psymtabs (ps->dependencies[i],
1311 objfile, kind, name_matcher, data);
1314 ps->searched_flag = PST_SEARCHED_AND_FOUND;
1319 gbound = (objfile->global_psymbols.list
1320 + ps->globals_offset + ps->n_global_syms);
1321 sbound = (objfile->static_psymbols.list
1322 + ps->statics_offset + ps->n_static_syms);
1325 /* Go through all of the symbols stored in a partial
1326 symtab in one loop. */
1327 psym = objfile->global_psymbols.list + ps->globals_offset;
1332 if (bound == gbound && ps->n_static_syms != 0)
1334 psym = objfile->static_psymbols.list + ps->statics_offset;
1345 if ((kind == ALL_DOMAIN
1346 || (kind == VARIABLES_DOMAIN
1347 && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
1348 && SYMBOL_CLASS (*psym) != LOC_BLOCK)
1349 || (kind == FUNCTIONS_DOMAIN
1350 && SYMBOL_CLASS (*psym) == LOC_BLOCK)
1351 || (kind == TYPES_DOMAIN
1352 && SYMBOL_CLASS (*psym) == LOC_TYPEDEF))
1353 && (*name_matcher) (SYMBOL_SEARCH_NAME (*psym), data))
1355 /* Found a match, so notify our caller. */
1356 result = PST_SEARCHED_AND_FOUND;
1363 ps->searched_flag = result;
1364 return result == PST_SEARCHED_AND_FOUND;
1368 expand_symtabs_matching_via_partial
1369 (struct objfile *objfile,
1370 int (*file_matcher) (const char *, void *, int basenames),
1371 int (*name_matcher) (const char *, void *),
1372 enum search_domain kind,
1375 struct partial_symtab *ps;
1377 /* Clear the search flags. */
1378 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1380 ps->searched_flag = PST_NOT_SEARCHED;
1383 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1388 /* We skip shared psymtabs because file-matching doesn't apply
1389 to them; but we search them later in the loop. */
1390 if (ps->user != NULL)
1398 /* Before we invoke realpath, which can get expensive when many
1399 files are involved, do a quick comparison of the basenames. */
1400 if (!(*file_matcher) (ps->filename, data, 0)
1401 && (basenames_may_differ
1402 || (*file_matcher) (lbasename (ps->filename), data, 1))
1403 && !(*file_matcher) (psymtab_to_fullname (ps), data, 0))
1407 if (recursively_search_psymtabs (ps, objfile, kind, name_matcher, data))
1408 psymtab_to_symtab (objfile, ps);
1413 objfile_has_psyms (struct objfile *objfile)
1415 return objfile->psymtabs != NULL;
1418 const struct quick_symbol_functions psym_functions =
1421 find_last_source_symtab_from_partial,
1422 forget_cached_source_info_partial,
1423 partial_map_symtabs_matching_filename,
1424 lookup_symbol_aux_psymtabs,
1425 print_psymtab_stats_for_objfile,
1426 dump_psymtabs_for_objfile,
1428 read_symtabs_for_function,
1429 expand_partial_symbol_tables,
1430 read_psymtabs_with_fullname,
1431 find_symbol_file_from_partial,
1432 map_matching_symbols_psymtab,
1433 expand_symtabs_matching_via_partial,
1434 find_pc_sect_symtab_from_partial,
1435 map_symbol_filenames_psymtab
1440 /* This compares two partial symbols by names, using strcmp_iw_ordered
1441 for the comparison. */
1444 compare_psymbols (const void *s1p, const void *s2p)
1446 struct partial_symbol *const *s1 = s1p;
1447 struct partial_symbol *const *s2 = s2p;
1449 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1),
1450 SYMBOL_SEARCH_NAME (*s2));
1454 sort_pst_symbols (struct objfile *objfile, struct partial_symtab *pst)
1456 /* Sort the global list; don't sort the static list. */
1458 qsort (objfile->global_psymbols.list + pst->globals_offset,
1459 pst->n_global_syms, sizeof (struct partial_symbol *),
1463 /* Allocate and partially fill a partial symtab. It will be
1464 completely filled at the end of the symbol list.
1466 FILENAME is the name of the symbol-file we are reading from. */
1468 struct partial_symtab *
1469 start_psymtab_common (struct objfile *objfile,
1470 struct section_offsets *section_offsets,
1471 const char *filename,
1472 CORE_ADDR textlow, struct partial_symbol **global_syms,
1473 struct partial_symbol **static_syms)
1475 struct partial_symtab *psymtab;
1477 psymtab = allocate_psymtab (filename, objfile);
1478 psymtab->section_offsets = section_offsets;
1479 psymtab->textlow = textlow;
1480 psymtab->texthigh = psymtab->textlow; /* default */
1481 psymtab->globals_offset = global_syms - objfile->global_psymbols.list;
1482 psymtab->statics_offset = static_syms - objfile->static_psymbols.list;
1486 /* Calculate a hash code for the given partial symbol. The hash is
1487 calculated using the symbol's value, language, domain, class
1488 and name. These are the values which are set by
1489 add_psymbol_to_bcache. */
1491 static unsigned long
1492 psymbol_hash (const void *addr, int length)
1494 unsigned long h = 0;
1495 struct partial_symbol *psymbol = (struct partial_symbol *) addr;
1496 unsigned int lang = psymbol->ginfo.language;
1497 unsigned int domain = PSYMBOL_DOMAIN (psymbol);
1498 unsigned int class = PSYMBOL_CLASS (psymbol);
1500 h = hash_continue (&psymbol->ginfo.value, sizeof (psymbol->ginfo.value), h);
1501 h = hash_continue (&lang, sizeof (unsigned int), h);
1502 h = hash_continue (&domain, sizeof (unsigned int), h);
1503 h = hash_continue (&class, sizeof (unsigned int), h);
1504 h = hash_continue (psymbol->ginfo.name, strlen (psymbol->ginfo.name), h);
1509 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1510 For the comparison this function uses a symbols value,
1511 language, domain, class and name. */
1514 psymbol_compare (const void *addr1, const void *addr2, int length)
1516 struct partial_symbol *sym1 = (struct partial_symbol *) addr1;
1517 struct partial_symbol *sym2 = (struct partial_symbol *) addr2;
1519 return (memcmp (&sym1->ginfo.value, &sym1->ginfo.value,
1520 sizeof (sym1->ginfo.value)) == 0
1521 && sym1->ginfo.language == sym2->ginfo.language
1522 && PSYMBOL_DOMAIN (sym1) == PSYMBOL_DOMAIN (sym2)
1523 && PSYMBOL_CLASS (sym1) == PSYMBOL_CLASS (sym2)
1524 && sym1->ginfo.name == sym2->ginfo.name);
1527 /* Initialize a partial symbol bcache. */
1529 struct psymbol_bcache *
1530 psymbol_bcache_init (void)
1532 struct psymbol_bcache *bcache = XCALLOC (1, struct psymbol_bcache);
1533 bcache->bcache = bcache_xmalloc (psymbol_hash, psymbol_compare);
1537 /* Free a partial symbol bcache. */
1539 psymbol_bcache_free (struct psymbol_bcache *bcache)
1544 bcache_xfree (bcache->bcache);
1548 /* Return the internal bcache of the psymbol_bcache BCACHE. */
1551 psymbol_bcache_get_bcache (struct psymbol_bcache *bcache)
1553 return bcache->bcache;
1556 /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1557 symbol before, add a copy to BCACHE. In either case, return a pointer
1558 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1559 1 in case of new entry or 0 if returning an old entry. */
1561 static const struct partial_symbol *
1562 psymbol_bcache_full (struct partial_symbol *sym,
1563 struct psymbol_bcache *bcache,
1566 return bcache_full (sym,
1567 sizeof (struct partial_symbol),
1572 /* Helper function, initialises partial symbol structure and stashes
1573 it into objfile's bcache. Note that our caching mechanism will
1574 use all fields of struct partial_symbol to determine hash value of the
1575 structure. In other words, having two symbols with the same name but
1576 different domain (or address) is possible and correct. */
1578 static const struct partial_symbol *
1579 add_psymbol_to_bcache (const char *name, int namelength, int copy_name,
1581 enum address_class class,
1582 long val, /* Value as a long */
1583 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1584 enum language language, struct objfile *objfile,
1587 struct partial_symbol psymbol;
1589 /* We must ensure that the entire 'value' field has been zeroed
1590 before assigning to it, because an assignment may not write the
1592 memset (&psymbol.ginfo.value, 0, sizeof (psymbol.ginfo.value));
1594 /* val and coreaddr are mutually exclusive, one of them *will* be zero. */
1597 SYMBOL_VALUE (&psymbol) = val;
1601 SYMBOL_VALUE_ADDRESS (&psymbol) = coreaddr;
1603 SYMBOL_SECTION (&psymbol) = 0;
1604 SYMBOL_OBJ_SECTION (&psymbol) = NULL;
1605 SYMBOL_SET_LANGUAGE (&psymbol, language);
1606 PSYMBOL_DOMAIN (&psymbol) = domain;
1607 PSYMBOL_CLASS (&psymbol) = class;
1609 SYMBOL_SET_NAMES (&psymbol, name, namelength, copy_name, objfile);
1611 /* Stash the partial symbol away in the cache. */
1612 return psymbol_bcache_full (&psymbol,
1613 objfile->psymbol_cache,
1617 /* Increase the space allocated for LISTP, which is probably
1618 global_psymbols or static_psymbols. This space will eventually
1619 be freed in free_objfile(). */
1622 extend_psymbol_list (struct psymbol_allocation_list *listp,
1623 struct objfile *objfile)
1627 if (listp->size == 0)
1630 listp->list = (struct partial_symbol **)
1631 xmalloc (new_size * sizeof (struct partial_symbol *));
1635 new_size = listp->size * 2;
1636 listp->list = (struct partial_symbol **)
1637 xrealloc ((char *) listp->list,
1638 new_size * sizeof (struct partial_symbol *));
1640 /* Next assumes we only went one over. Should be good if
1641 program works correctly. */
1642 listp->next = listp->list + listp->size;
1643 listp->size = new_size;
1646 /* Helper function, adds partial symbol to the given partial symbol
1650 append_psymbol_to_list (struct psymbol_allocation_list *list,
1651 const struct partial_symbol *psym,
1652 struct objfile *objfile)
1654 if (list->next >= list->list + list->size)
1655 extend_psymbol_list (list, objfile);
1656 *list->next++ = (struct partial_symbol *) psym;
1657 OBJSTAT (objfile, n_psyms++);
1660 /* Add a symbol with a long value to a psymtab.
1661 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1662 Return the partial symbol that has been added. */
1665 add_psymbol_to_list (const char *name, int namelength, int copy_name,
1667 enum address_class class,
1668 struct psymbol_allocation_list *list,
1669 long val, /* Value as a long */
1670 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1671 enum language language, struct objfile *objfile)
1673 const struct partial_symbol *psym;
1677 /* Stash the partial symbol away in the cache. */
1678 psym = add_psymbol_to_bcache (name, namelength, copy_name, domain, class,
1679 val, coreaddr, language, objfile, &added);
1681 /* Do not duplicate global partial symbols. */
1682 if (list == &objfile->global_psymbols
1686 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1687 append_psymbol_to_list (list, psym, objfile);
1690 /* Initialize storage for partial symbols. */
1693 init_psymbol_list (struct objfile *objfile, int total_symbols)
1695 /* Free any previously allocated psymbol lists. */
1697 if (objfile->global_psymbols.list)
1699 xfree (objfile->global_psymbols.list);
1701 if (objfile->static_psymbols.list)
1703 xfree (objfile->static_psymbols.list);
1706 /* Current best guess is that approximately a twentieth
1707 of the total symbols (in a debugging file) are global or static
1708 oriented symbols, then multiply that by slop factor of two. */
1710 objfile->global_psymbols.size = total_symbols / 10;
1711 objfile->static_psymbols.size = total_symbols / 10;
1713 if (objfile->global_psymbols.size > 0)
1715 objfile->global_psymbols.next =
1716 objfile->global_psymbols.list = (struct partial_symbol **)
1717 xmalloc ((objfile->global_psymbols.size
1718 * sizeof (struct partial_symbol *)));
1720 if (objfile->static_psymbols.size > 0)
1722 objfile->static_psymbols.next =
1723 objfile->static_psymbols.list = (struct partial_symbol **)
1724 xmalloc ((objfile->static_psymbols.size
1725 * sizeof (struct partial_symbol *)));
1729 struct partial_symtab *
1730 allocate_psymtab (const char *filename, struct objfile *objfile)
1732 struct partial_symtab *psymtab;
1734 if (objfile->free_psymtabs)
1736 psymtab = objfile->free_psymtabs;
1737 objfile->free_psymtabs = psymtab->next;
1740 psymtab = (struct partial_symtab *)
1741 obstack_alloc (&objfile->objfile_obstack,
1742 sizeof (struct partial_symtab));
1744 memset (psymtab, 0, sizeof (struct partial_symtab));
1745 psymtab->filename = obstack_copy0 (&objfile->objfile_obstack,
1746 filename, strlen (filename));
1747 psymtab->symtab = NULL;
1749 /* Prepend it to the psymtab list for the objfile it belongs to.
1750 Psymtabs are searched in most recent inserted -> least recent
1753 psymtab->next = objfile->psymtabs;
1754 objfile->psymtabs = psymtab;
1756 if (symtab_create_debug)
1758 /* Be a bit clever with debugging messages, and don't print objfile
1759 every time, only when it changes. */
1760 static char *last_objfile_name = NULL;
1762 if (last_objfile_name == NULL
1763 || strcmp (last_objfile_name, objfile->name) != 0)
1765 xfree (last_objfile_name);
1766 last_objfile_name = xstrdup (objfile->name);
1767 fprintf_unfiltered (gdb_stdlog,
1768 "Creating one or more psymtabs for objfile %s ...\n",
1771 fprintf_unfiltered (gdb_stdlog,
1772 "Created psymtab %s for module %s.\n",
1773 host_address_to_string (psymtab), filename);
1780 discard_psymtab (struct objfile *objfile, struct partial_symtab *pst)
1782 struct partial_symtab **prev_pst;
1785 Empty psymtabs happen as a result of header files which don't
1786 have any symbols in them. There can be a lot of them. But this
1787 check is wrong, in that a psymtab with N_SLINE entries but
1788 nothing else is not empty, but we don't realize that. Fixing
1789 that without slowing things down might be tricky. */
1791 /* First, snip it out of the psymtab chain. */
1793 prev_pst = &(objfile->psymtabs);
1794 while ((*prev_pst) != pst)
1795 prev_pst = &((*prev_pst)->next);
1796 (*prev_pst) = pst->next;
1798 /* Next, put it on a free list for recycling. */
1800 pst->next = objfile->free_psymtabs;
1801 objfile->free_psymtabs = pst;
1804 /* An object of this type is passed to discard_psymtabs_upto. */
1806 struct psymtab_state
1808 /* The objfile where psymtabs are discarded. */
1810 struct objfile *objfile;
1812 /* The first psymtab to save. */
1814 struct partial_symtab *save;
1817 /* A cleanup function used by make_cleanup_discard_psymtabs. */
1820 discard_psymtabs_upto (void *arg)
1822 struct psymtab_state *state = arg;
1824 while (state->objfile->psymtabs != state->save)
1825 discard_psymtab (state->objfile, state->objfile->psymtabs);
1828 /* Return a new cleanup that discards all psymtabs created in OBJFILE
1829 after this function is called. */
1832 make_cleanup_discard_psymtabs (struct objfile *objfile)
1834 struct psymtab_state *state = XNEW (struct psymtab_state);
1836 state->objfile = objfile;
1837 state->save = objfile->psymtabs;
1839 return make_cleanup_dtor (discard_psymtabs_upto, state, xfree);
1845 maintenance_print_psymbols (char *args, int from_tty)
1848 struct ui_file *outfile;
1849 struct cleanup *cleanups;
1850 char *symname = NULL;
1851 char *filename = DEV_TTY;
1852 struct objfile *objfile;
1853 struct partial_symtab *ps;
1860 print-psymbols takes an output file name and optional symbol file name"));
1862 argv = gdb_buildargv (args);
1863 cleanups = make_cleanup_freeargv (argv);
1865 if (argv[0] != NULL)
1868 /* If a second arg is supplied, it is a source file name to match on. */
1869 if (argv[1] != NULL)
1875 filename = tilde_expand (filename);
1876 make_cleanup (xfree, filename);
1878 outfile = gdb_fopen (filename, FOPEN_WT);
1880 perror_with_name (filename);
1881 make_cleanup_ui_file_delete (outfile);
1883 ALL_PSYMTABS (objfile, ps)
1886 if (symname == NULL || filename_cmp (symname, ps->filename) == 0)
1887 dump_psymtab (objfile, ps, outfile);
1889 do_cleanups (cleanups);
1892 /* List all the partial symbol tables whose names match REGEXP (optional). */
1894 maintenance_info_psymtabs (char *regexp, int from_tty)
1896 struct program_space *pspace;
1897 struct objfile *objfile;
1902 ALL_PSPACES (pspace)
1903 ALL_PSPACE_OBJFILES (pspace, objfile)
1905 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1906 struct partial_symtab *psymtab;
1908 /* We don't want to print anything for this objfile until we
1909 actually find a symtab whose name matches. */
1910 int printed_objfile_start = 0;
1912 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
1917 || re_exec (psymtab->filename))
1919 if (! printed_objfile_start)
1921 printf_filtered ("{ objfile %s ", objfile->name);
1923 printf_filtered ("((struct objfile *) %s)\n",
1924 host_address_to_string (objfile));
1925 printed_objfile_start = 1;
1928 printf_filtered (" { psymtab %s ", psymtab->filename);
1930 printf_filtered ("((struct partial_symtab *) %s)\n",
1931 host_address_to_string (psymtab));
1933 printf_filtered (" readin %s\n",
1934 psymtab->readin ? "yes" : "no");
1935 printf_filtered (" fullname %s\n",
1937 ? psymtab->fullname : "(null)");
1938 printf_filtered (" text addresses ");
1939 fputs_filtered (paddress (gdbarch, psymtab->textlow),
1941 printf_filtered (" -- ");
1942 fputs_filtered (paddress (gdbarch, psymtab->texthigh),
1944 printf_filtered ("\n");
1945 printf_filtered (" psymtabs_addrmap_supported %s\n",
1946 (psymtab->psymtabs_addrmap_supported
1948 printf_filtered (" globals ");
1949 if (psymtab->n_global_syms)
1951 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1952 host_address_to_string (objfile->global_psymbols.list
1953 + psymtab->globals_offset),
1954 psymtab->n_global_syms);
1957 printf_filtered ("(none)\n");
1958 printf_filtered (" statics ");
1959 if (psymtab->n_static_syms)
1961 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1962 host_address_to_string (objfile->static_psymbols.list
1963 + psymtab->statics_offset),
1964 psymtab->n_static_syms);
1967 printf_filtered ("(none)\n");
1968 printf_filtered (" dependencies ");
1969 if (psymtab->number_of_dependencies)
1973 printf_filtered ("{\n");
1974 for (i = 0; i < psymtab->number_of_dependencies; i++)
1976 struct partial_symtab *dep = psymtab->dependencies[i];
1978 /* Note the string concatenation there --- no comma. */
1979 printf_filtered (" psymtab %s "
1980 "((struct partial_symtab *) %s)\n",
1982 host_address_to_string (dep));
1984 printf_filtered (" }\n");
1987 printf_filtered ("(none)\n");
1988 printf_filtered (" }\n");
1992 if (printed_objfile_start)
1993 printf_filtered ("}\n");
1997 /* Check consistency of psymtabs and symtabs. */
2000 maintenance_check_symtabs (char *ignore, int from_tty)
2003 struct partial_symbol **psym;
2004 struct symtab *s = NULL;
2005 struct partial_symtab *ps;
2006 struct blockvector *bv;
2007 struct objfile *objfile;
2011 ALL_PSYMTABS (objfile, ps)
2013 struct gdbarch *gdbarch = get_objfile_arch (objfile);
2015 s = psymtab_to_symtab (objfile, ps);
2018 bv = BLOCKVECTOR (s);
2019 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
2020 psym = objfile->static_psymbols.list + ps->statics_offset;
2021 length = ps->n_static_syms;
2024 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
2025 SYMBOL_DOMAIN (*psym));
2028 printf_filtered ("Static symbol `");
2029 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
2030 printf_filtered ("' only found in ");
2031 puts_filtered (ps->filename);
2032 printf_filtered (" psymtab\n");
2036 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
2037 psym = objfile->global_psymbols.list + ps->globals_offset;
2038 length = ps->n_global_syms;
2041 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
2042 SYMBOL_DOMAIN (*psym));
2045 printf_filtered ("Global symbol `");
2046 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
2047 printf_filtered ("' only found in ");
2048 puts_filtered (ps->filename);
2049 printf_filtered (" psymtab\n");
2053 if (ps->texthigh < ps->textlow)
2055 printf_filtered ("Psymtab ");
2056 puts_filtered (ps->filename);
2057 printf_filtered (" covers bad range ");
2058 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
2059 printf_filtered (" - ");
2060 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
2061 printf_filtered ("\n");
2064 if (ps->texthigh == 0)
2066 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
2068 printf_filtered ("Psymtab ");
2069 puts_filtered (ps->filename);
2070 printf_filtered (" covers ");
2071 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
2072 printf_filtered (" - ");
2073 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
2074 printf_filtered (" but symtab covers only ");
2075 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
2076 printf_filtered (" - ");
2077 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout);
2078 printf_filtered ("\n");
2086 expand_partial_symbol_names (int (*fun) (const char *, void *),
2089 struct objfile *objfile;
2091 ALL_OBJFILES (objfile)
2094 objfile->sf->qf->expand_symtabs_matching (objfile, NULL, fun,
2100 map_partial_symbol_filenames (symbol_filename_ftype *fun, void *data,
2103 struct objfile *objfile;
2105 ALL_OBJFILES (objfile)
2108 objfile->sf->qf->map_symbol_filenames (objfile, fun, data,
2113 extern initialize_file_ftype _initialize_psymtab;
2116 _initialize_psymtab (void)
2118 add_cmd ("psymbols", class_maintenance, maintenance_print_psymbols, _("\
2119 Print dump of current partial symbol definitions.\n\
2120 Entries in the partial symbol table are dumped to file OUTFILE.\n\
2121 If a SOURCE file is specified, dump only that file's partial symbols."),
2122 &maintenanceprintlist);
2124 add_cmd ("psymtabs", class_maintenance, maintenance_info_psymtabs, _("\
2125 List the partial symbol tables for all object files.\n\
2126 This does not include information about individual partial symbols,\n\
2127 just the symbol table structures themselves."),
2128 &maintenanceinfolist);
2130 add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs,
2131 _("Check consistency of psymtabs and symtabs."),