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 psymtab_to_fullname (pst);
208 if (pst->fullname != NULL
209 && FILENAME_CMP (real_path, pst->fullname) == 0)
211 if (partial_map_expand_apply (objfile, name, real_path,
212 pst, callback, data))
221 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
222 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
224 static struct partial_symtab *
225 find_pc_sect_psymtab_closer (struct objfile *objfile,
226 CORE_ADDR pc, struct obj_section *section,
227 struct partial_symtab *pst,
228 struct minimal_symbol *msymbol)
230 struct partial_symtab *tpst;
231 struct partial_symtab *best_pst = pst;
232 CORE_ADDR best_addr = pst->textlow;
234 gdb_assert (!pst->psymtabs_addrmap_supported);
236 /* An objfile that has its functions reordered might have
237 many partial symbol tables containing the PC, but
238 we want the partial symbol table that contains the
239 function containing the PC. */
240 if (!(objfile->flags & OBJF_REORDERED) &&
241 section == 0) /* Can't validate section this way. */
247 /* The code range of partial symtabs sometimes overlap, so, in
248 the loop below, we need to check all partial symtabs and
249 find the one that fits better for the given PC address. We
250 select the partial symtab that contains a symbol whose
251 address is closest to the PC address. By closest we mean
252 that find_pc_sect_symbol returns the symbol with address
253 that is closest and still less than the given PC. */
254 for (tpst = pst; tpst != NULL; tpst = tpst->next)
256 if (pc >= tpst->textlow && pc < tpst->texthigh)
258 struct partial_symbol *p;
261 /* NOTE: This assumes that every psymbol has a
262 corresponding msymbol, which is not necessarily
263 true; the debug info might be much richer than the
264 object's symbol table. */
265 p = find_pc_sect_psymbol (objfile, tpst, pc, section);
267 && SYMBOL_VALUE_ADDRESS (p)
268 == SYMBOL_VALUE_ADDRESS (msymbol))
271 /* Also accept the textlow value of a psymtab as a
272 "symbol", to provide some support for partial
273 symbol tables with line information but no debug
274 symbols (e.g. those produced by an assembler). */
276 this_addr = SYMBOL_VALUE_ADDRESS (p);
278 this_addr = tpst->textlow;
280 /* Check whether it is closer than our current
281 BEST_ADDR. Since this symbol address is
282 necessarily lower or equal to PC, the symbol closer
283 to PC is the symbol which address is the highest.
284 This way we return the psymtab which contains such
285 best match symbol. This can help in cases where the
286 symbol information/debuginfo is not complete, like
287 for instance on IRIX6 with gcc, where no debug info
288 is emitted for statics. (See also the nodebug.exp
290 if (this_addr > best_addr)
292 best_addr = this_addr;
300 /* Find which partial symtab contains PC and SECTION. Return 0 if
301 none. We return the psymtab that contains a symbol whose address
302 exactly matches PC, or, if we cannot find an exact match, the
303 psymtab that contains a symbol whose address is closest to PC. */
304 static struct partial_symtab *
305 find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
306 struct obj_section *section,
307 struct minimal_symbol *msymbol)
309 struct partial_symtab *pst;
311 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
312 than the later used TEXTLOW/TEXTHIGH one. */
314 if (objfile->psymtabs_addrmap != NULL)
316 pst = addrmap_find (objfile->psymtabs_addrmap, pc);
319 /* FIXME: addrmaps currently do not handle overlayed sections,
320 so fall back to the non-addrmap case if we're debugging
321 overlays and the addrmap returned the wrong section. */
322 if (overlay_debugging && msymbol && section)
324 struct partial_symbol *p;
326 /* NOTE: This assumes that every psymbol has a
327 corresponding msymbol, which is not necessarily
328 true; the debug info might be much richer than the
329 object's symbol table. */
330 p = find_pc_sect_psymbol (objfile, pst, pc, section);
332 || SYMBOL_VALUE_ADDRESS (p)
333 != SYMBOL_VALUE_ADDRESS (msymbol))
337 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
338 PSYMTABS_ADDRMAP we used has already the best 1-byte
339 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
340 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
349 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
350 which still have no corresponding full SYMTABs read. But it is not
351 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
354 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
355 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
356 debug info type in single OBJFILE. */
358 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
359 if (!pst->psymtabs_addrmap_supported
360 && pc >= pst->textlow && pc < pst->texthigh)
362 struct partial_symtab *best_pst;
364 best_pst = find_pc_sect_psymtab_closer (objfile, pc, section, pst,
366 if (best_pst != NULL)
373 static struct symtab *
374 find_pc_sect_symtab_from_partial (struct objfile *objfile,
375 struct minimal_symbol *msymbol,
376 CORE_ADDR pc, struct obj_section *section,
379 struct partial_symtab *ps = find_pc_sect_psymtab (objfile, pc, section,
383 if (warn_if_readin && ps->readin)
384 /* Might want to error() here (in case symtab is corrupt and
385 will cause a core dump), but maybe we can successfully
386 continue, so let's not. */
388 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
389 paddress (get_objfile_arch (objfile), pc));
390 psymtab_to_symtab (objfile, ps);
396 /* Find which partial symbol within a psymtab matches PC and SECTION.
399 static struct partial_symbol *
400 find_pc_sect_psymbol (struct objfile *objfile,
401 struct partial_symtab *psymtab, CORE_ADDR pc,
402 struct obj_section *section)
404 struct partial_symbol *best = NULL, *p, **pp;
407 gdb_assert (psymtab != NULL);
409 /* Cope with programs that start at address 0. */
410 best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0;
412 /* Search the global symbols as well as the static symbols, so that
413 find_pc_partial_function doesn't use a minimal symbol and thus
414 cache a bad endaddr. */
415 for (pp = objfile->global_psymbols.list + psymtab->globals_offset;
416 (pp - (objfile->global_psymbols.list + psymtab->globals_offset)
417 < psymtab->n_global_syms);
421 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
422 && SYMBOL_CLASS (p) == LOC_BLOCK
423 && pc >= SYMBOL_VALUE_ADDRESS (p)
424 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
425 || (psymtab->textlow == 0
426 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
428 if (section) /* Match on a specific section. */
430 fixup_psymbol_section (p, objfile);
431 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
434 best_pc = SYMBOL_VALUE_ADDRESS (p);
439 for (pp = objfile->static_psymbols.list + psymtab->statics_offset;
440 (pp - (objfile->static_psymbols.list + psymtab->statics_offset)
441 < psymtab->n_static_syms);
445 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
446 && SYMBOL_CLASS (p) == LOC_BLOCK
447 && pc >= SYMBOL_VALUE_ADDRESS (p)
448 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
449 || (psymtab->textlow == 0
450 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
452 if (section) /* Match on a specific section. */
454 fixup_psymbol_section (p, objfile);
455 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
458 best_pc = SYMBOL_VALUE_ADDRESS (p);
467 fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
471 if (psym == NULL || SYMBOL_OBJ_SECTION (psym) != NULL)
474 gdb_assert (objfile);
476 switch (SYMBOL_CLASS (psym))
481 addr = SYMBOL_VALUE_ADDRESS (psym);
484 /* Nothing else will be listed in the minsyms -- no use looking
489 fixup_section (&psym->ginfo, addr, objfile);
492 static struct symtab *
493 lookup_symbol_aux_psymtabs (struct objfile *objfile,
494 int block_index, const char *name,
495 const domain_enum domain)
497 struct partial_symtab *ps;
498 const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
499 struct symtab *stab_best = NULL;
501 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
503 if (!ps->readin && lookup_partial_symbol (objfile, ps, name,
504 psymtab_index, domain))
506 struct symbol *sym = NULL;
507 struct symtab *stab = psymtab_to_symtab (objfile, ps);
509 /* Some caution must be observed with overloaded functions
510 and methods, since the psymtab will not contain any overload
511 information (but NAME might contain it). */
514 struct blockvector *bv = BLOCKVECTOR (stab);
515 struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
517 sym = lookup_block_symbol (block, name, domain);
520 if (sym && strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0)
522 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
528 /* Keep looking through other psymtabs. */
535 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
536 the global block of PST if GLOBAL, and otherwise the static block.
537 MATCH is the comparison operation that returns true iff MATCH (s,
538 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
539 non-null, the symbols in the block are assumed to be ordered
540 according to it (allowing binary search). It must be compatible
541 with MATCH. Returns the symbol, if found, and otherwise NULL. */
543 static struct partial_symbol *
544 match_partial_symbol (struct objfile *objfile,
545 struct partial_symtab *pst, int global,
546 const char *name, domain_enum domain,
547 symbol_compare_ftype *match,
548 symbol_compare_ftype *ordered_compare)
550 struct partial_symbol **start, **psym;
551 struct partial_symbol **top, **real_top, **bottom, **center;
552 int length = (global ? pst->n_global_syms : pst->n_static_syms);
553 int do_linear_search = 1;
558 objfile->global_psymbols.list + pst->globals_offset :
559 objfile->static_psymbols.list + pst->statics_offset);
561 if (global && ordered_compare) /* Can use a binary search. */
563 do_linear_search = 0;
565 /* Binary search. This search is guaranteed to end with center
566 pointing at the earliest partial symbol whose name might be
567 correct. At that point *all* partial symbols with an
568 appropriate name will be checked against the correct
572 top = start + length - 1;
576 center = bottom + (top - bottom) / 2;
577 gdb_assert (center < top);
578 if (!do_linear_search
579 && (SYMBOL_LANGUAGE (*center) == language_java))
580 do_linear_search = 1;
581 if (ordered_compare (SYMBOL_SEARCH_NAME (*center), name) >= 0)
586 gdb_assert (top == bottom);
588 while (top <= real_top
589 && match (SYMBOL_SEARCH_NAME (*top), name) == 0)
591 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
592 SYMBOL_DOMAIN (*top), domain))
598 /* Can't use a binary search or else we found during the binary search that
599 we should also do a linear search. */
601 if (do_linear_search)
603 for (psym = start; psym < start + length; psym++)
605 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
606 SYMBOL_DOMAIN (*psym), domain)
607 && match (SYMBOL_SEARCH_NAME (*psym), name) == 0)
615 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
616 not contain any method/function instance information (since this would
617 force reading type information while reading psymtabs). Therefore,
618 if NAME contains overload information, it must be stripped before searching
621 The caller is responsible for freeing the return result. */
624 psymtab_search_name (const char *name)
626 switch (current_language->la_language)
631 if (strchr (name, '('))
633 char *ret = cp_remove_params (name);
645 return xstrdup (name);
648 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
649 Check the global symbols if GLOBAL, the static symbols if not. */
651 static struct partial_symbol *
652 lookup_partial_symbol (struct objfile *objfile,
653 struct partial_symtab *pst, const char *name,
654 int global, domain_enum domain)
656 struct partial_symbol **start, **psym;
657 struct partial_symbol **top, **real_top, **bottom, **center;
658 int length = (global ? pst->n_global_syms : pst->n_static_syms);
659 int do_linear_search = 1;
661 struct cleanup *cleanup;
668 search_name = psymtab_search_name (name);
669 cleanup = make_cleanup (xfree, search_name);
671 objfile->global_psymbols.list + pst->globals_offset :
672 objfile->static_psymbols.list + pst->statics_offset);
674 if (global) /* This means we can use a binary search. */
676 do_linear_search = 0;
678 /* Binary search. This search is guaranteed to end with center
679 pointing at the earliest partial symbol whose name might be
680 correct. At that point *all* partial symbols with an
681 appropriate name will be checked against the correct
685 top = start + length - 1;
689 center = bottom + (top - bottom) / 2;
691 internal_error (__FILE__, __LINE__,
692 _("failed internal consistency check"));
693 if (!do_linear_search
694 && SYMBOL_LANGUAGE (*center) == language_java)
696 do_linear_search = 1;
698 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center),
708 if (!(top == bottom))
709 internal_error (__FILE__, __LINE__,
710 _("failed internal consistency check"));
712 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
713 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
714 while (top >= start && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
717 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
720 while (top <= real_top && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
722 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
723 SYMBOL_DOMAIN (*top), domain))
725 do_cleanups (cleanup);
732 /* Can't use a binary search or else we found during the binary search that
733 we should also do a linear search. */
735 if (do_linear_search)
737 for (psym = start; psym < start + length; psym++)
739 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
740 SYMBOL_DOMAIN (*psym), domain)
741 && SYMBOL_MATCHES_SEARCH_NAME (*psym, search_name))
743 do_cleanups (cleanup);
749 do_cleanups (cleanup);
753 /* Get the symbol table that corresponds to a partial_symtab.
754 This is fast after the first time you do it. */
756 static struct symtab *
757 psymtab_to_symtab (struct objfile *objfile, struct partial_symtab *pst)
759 /* If it is a shared psymtab, find an unshared psymtab that includes
760 it. Any such psymtab will do. */
761 while (pst->user != NULL)
764 /* If it's been looked up before, return it. */
768 /* If it has not yet been read in, read it. */
771 struct cleanup *back_to = increment_reading_symtab ();
773 (*pst->read_symtab) (pst, objfile);
774 do_cleanups (back_to);
781 relocate_psymtabs (struct objfile *objfile,
782 struct section_offsets *new_offsets,
783 struct section_offsets *delta)
785 struct partial_symbol **psym;
786 struct partial_symtab *p;
788 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
790 p->textlow += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
791 p->texthigh += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
794 for (psym = objfile->global_psymbols.list;
795 psym < objfile->global_psymbols.next;
798 fixup_psymbol_section (*psym, objfile);
799 if (SYMBOL_SECTION (*psym) >= 0)
800 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
801 SYMBOL_SECTION (*psym));
803 for (psym = objfile->static_psymbols.list;
804 psym < objfile->static_psymbols.next;
807 fixup_psymbol_section (*psym, objfile);
808 if (SYMBOL_SECTION (*psym) >= 0)
809 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
810 SYMBOL_SECTION (*psym));
814 static struct symtab *
815 find_last_source_symtab_from_partial (struct objfile *ofp)
817 struct partial_symtab *ps;
818 struct partial_symtab *cs_pst = 0;
820 ALL_OBJFILE_PSYMTABS_REQUIRED (ofp, ps)
822 const char *name = ps->filename;
823 int len = strlen (name);
825 if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0
826 || strcmp (name, "<<C++-namespaces>>") == 0)))
834 internal_error (__FILE__, __LINE__,
835 _("select_source_symtab: "
836 "readin pst found and no symtabs."));
839 return psymtab_to_symtab (ofp, cs_pst);
845 forget_cached_source_info_partial (struct objfile *objfile)
847 struct partial_symtab *pst;
849 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
851 if (pst->fullname != NULL)
853 xfree (pst->fullname);
854 pst->fullname = NULL;
860 print_partial_symbols (struct gdbarch *gdbarch,
861 struct partial_symbol **p, int count, char *what,
862 struct ui_file *outfile)
864 fprintf_filtered (outfile, " %s partial symbols:\n", what);
868 fprintf_filtered (outfile, " `%s'", SYMBOL_LINKAGE_NAME (*p));
869 if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
871 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
873 fputs_filtered (", ", outfile);
874 switch (SYMBOL_DOMAIN (*p))
877 fputs_filtered ("undefined domain, ", outfile);
880 /* This is the usual thing -- don't print it. */
883 fputs_filtered ("struct domain, ", outfile);
886 fputs_filtered ("label domain, ", outfile);
889 fputs_filtered ("<invalid domain>, ", outfile);
892 switch (SYMBOL_CLASS (*p))
895 fputs_filtered ("undefined", outfile);
898 fputs_filtered ("constant int", outfile);
901 fputs_filtered ("static", outfile);
904 fputs_filtered ("register", outfile);
907 fputs_filtered ("pass by value", outfile);
910 fputs_filtered ("pass by reference", outfile);
912 case LOC_REGPARM_ADDR:
913 fputs_filtered ("register address parameter", outfile);
916 fputs_filtered ("stack parameter", outfile);
919 fputs_filtered ("type", outfile);
922 fputs_filtered ("label", outfile);
925 fputs_filtered ("function", outfile);
927 case LOC_CONST_BYTES:
928 fputs_filtered ("constant bytes", outfile);
931 fputs_filtered ("unresolved", outfile);
933 case LOC_OPTIMIZED_OUT:
934 fputs_filtered ("optimized out", outfile);
937 fputs_filtered ("computed at runtime", outfile);
940 fputs_filtered ("<invalid location>", outfile);
943 fputs_filtered (", ", outfile);
944 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (*p)), outfile);
945 fprintf_filtered (outfile, "\n");
951 dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
952 struct ui_file *outfile)
954 struct gdbarch *gdbarch = get_objfile_arch (objfile);
957 if (psymtab->anonymous)
959 fprintf_filtered (outfile, "\nAnonymous partial symtab (%s) ",
964 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
967 fprintf_filtered (outfile, "(object ");
968 gdb_print_host_address (psymtab, outfile);
969 fprintf_filtered (outfile, ")\n\n");
970 fprintf_unfiltered (outfile, " Read from object file %s (",
972 gdb_print_host_address (objfile, outfile);
973 fprintf_unfiltered (outfile, ")\n");
977 fprintf_filtered (outfile,
978 " Full symtab was read (at ");
979 gdb_print_host_address (psymtab->symtab, outfile);
980 fprintf_filtered (outfile, " by function at ");
981 gdb_print_host_address (psymtab->read_symtab, outfile);
982 fprintf_filtered (outfile, ")\n");
985 fprintf_filtered (outfile, " Relocate symbols by ");
986 for (i = 0; i < objfile->num_sections; ++i)
989 fprintf_filtered (outfile, ", ");
991 fputs_filtered (paddress (gdbarch,
992 ANOFFSET (psymtab->section_offsets, i)),
995 fprintf_filtered (outfile, "\n");
997 fprintf_filtered (outfile, " Symbols cover text addresses ");
998 fputs_filtered (paddress (gdbarch, psymtab->textlow), outfile);
999 fprintf_filtered (outfile, "-");
1000 fputs_filtered (paddress (gdbarch, psymtab->texthigh), outfile);
1001 fprintf_filtered (outfile, "\n");
1002 fprintf_filtered (outfile, " Address map supported - %s.\n",
1003 psymtab->psymtabs_addrmap_supported ? "yes" : "no");
1004 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
1005 psymtab->number_of_dependencies);
1006 for (i = 0; i < psymtab->number_of_dependencies; i++)
1008 fprintf_filtered (outfile, " %d ", i);
1009 gdb_print_host_address (psymtab->dependencies[i], outfile);
1010 fprintf_filtered (outfile, " %s\n",
1011 psymtab->dependencies[i]->filename);
1013 if (psymtab->user != NULL)
1015 fprintf_filtered (outfile, " Shared partial symtab with user ");
1016 gdb_print_host_address (psymtab->user, outfile);
1017 fprintf_filtered (outfile, "\n");
1019 if (psymtab->n_global_syms > 0)
1021 print_partial_symbols (gdbarch,
1022 objfile->global_psymbols.list
1023 + psymtab->globals_offset,
1024 psymtab->n_global_syms, "Global", outfile);
1026 if (psymtab->n_static_syms > 0)
1028 print_partial_symbols (gdbarch,
1029 objfile->static_psymbols.list
1030 + psymtab->statics_offset,
1031 psymtab->n_static_syms, "Static", outfile);
1033 fprintf_filtered (outfile, "\n");
1037 print_psymtab_stats_for_objfile (struct objfile *objfile)
1040 struct partial_symtab *ps;
1043 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1045 if (ps->readin == 0)
1048 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i);
1052 dump_psymtabs_for_objfile (struct objfile *objfile)
1054 struct partial_symtab *psymtab;
1056 if (objfile->psymtabs)
1058 printf_filtered ("Psymtabs:\n");
1059 for (psymtab = objfile->psymtabs;
1061 psymtab = psymtab->next)
1063 printf_filtered ("%s at ",
1065 gdb_print_host_address (psymtab, gdb_stdout);
1066 printf_filtered (", ");
1069 printf_filtered ("\n\n");
1073 /* Look through the partial symtabs for all symbols which begin
1074 by matching FUNC_NAME. Make sure we read that symbol table in. */
1077 read_symtabs_for_function (struct objfile *objfile, const char *func_name)
1079 struct partial_symtab *ps;
1081 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1086 if ((lookup_partial_symbol (objfile, ps, func_name, 1, VAR_DOMAIN)
1088 || (lookup_partial_symbol (objfile, ps, func_name, 0, VAR_DOMAIN)
1090 psymtab_to_symtab (objfile, ps);
1095 expand_partial_symbol_tables (struct objfile *objfile)
1097 struct partial_symtab *psymtab;
1099 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
1101 psymtab_to_symtab (objfile, psymtab);
1106 read_psymtabs_with_fullname (struct objfile *objfile, const char *fullname)
1108 struct partial_symtab *p;
1110 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
1112 /* Anonymous psymtabs don't have a name of a source file. */
1116 if (filename_cmp (fullname, psymtab_to_fullname (p)) == 0)
1117 psymtab_to_symtab (objfile, p);
1122 map_symbol_filenames_psymtab (struct objfile *objfile,
1123 symbol_filename_ftype *fun, void *data,
1126 struct partial_symtab *ps;
1128 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1130 const char *fullname;
1135 /* We can skip shared psymtabs here, because any file name will be
1136 attached to the unshared psymtab. */
1137 if (ps->user != NULL)
1140 /* Anonymous psymtabs don't have a file name. */
1146 fullname = psymtab_to_fullname (ps);
1149 (*fun) (ps->filename, fullname, data);
1153 /* Finds the fullname that a partial_symtab represents.
1155 If this functions finds the fullname, it will save it in ps->fullname
1156 and it will also return the value.
1158 If this function fails to find the file that this partial_symtab represents,
1159 NULL will be returned and ps->fullname will be set to NULL. */
1162 psymtab_to_fullname (struct partial_symtab *ps)
1171 /* Use cached copy if we have it.
1172 We rely on forget_cached_source_info being called appropriately
1173 to handle cases like the file being moved. */
1175 return ps->fullname;
1177 r = find_and_open_source (ps->filename, ps->dirname, &ps->fullname);
1182 return ps->fullname;
1189 find_symbol_file_from_partial (struct objfile *objfile, const char *name)
1191 struct partial_symtab *pst;
1193 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
1195 if (lookup_partial_symbol (objfile, pst, name, 1, VAR_DOMAIN))
1196 return pst->filename;
1201 /* For all symbols, s, in BLOCK that are in NAMESPACE and match NAME
1202 according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
1203 BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK
1204 ever returns non-zero, and otherwise returns 0. */
1207 map_block (const char *name, domain_enum namespace, struct objfile *objfile,
1208 struct block *block,
1209 int (*callback) (struct block *, struct symbol *, void *),
1210 void *data, symbol_compare_ftype *match)
1212 struct block_iterator iter;
1215 for (sym = block_iter_match_first (block, name, match, &iter);
1216 sym != NULL; sym = block_iter_match_next (name, match, &iter))
1218 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
1219 SYMBOL_DOMAIN (sym), namespace))
1221 if (callback (block, sym, data))
1229 /* Psymtab version of map_matching_symbols. See its definition in
1230 the definition of quick_symbol_functions in symfile.h. */
1233 map_matching_symbols_psymtab (const char *name, domain_enum namespace,
1234 struct objfile *objfile, int global,
1235 int (*callback) (struct block *,
1236 struct symbol *, void *),
1238 symbol_compare_ftype *match,
1239 symbol_compare_ftype *ordered_compare)
1241 const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
1242 struct partial_symtab *ps;
1244 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1248 || match_partial_symbol (objfile, ps, global, name, namespace, match,
1251 struct symtab *s = psymtab_to_symtab (objfile, ps);
1252 struct block *block;
1254 if (s == NULL || !s->primary)
1256 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), block_kind);
1257 if (map_block (name, namespace, objfile, block,
1258 callback, data, match))
1260 if (callback (block, NULL, data))
1266 /* A helper for expand_symtabs_matching_via_partial that handles
1267 searching included psymtabs. This returns 1 if a symbol is found,
1268 and zero otherwise. It also updates the 'searched_flag' on the
1269 various psymtabs that it searches. */
1272 recursively_search_psymtabs (struct partial_symtab *ps,
1273 struct objfile *objfile,
1274 enum search_domain kind,
1275 int (*name_matcher) (const char *, void *),
1278 struct partial_symbol **psym;
1279 struct partial_symbol **bound, **gbound, **sbound;
1281 int result = PST_SEARCHED_AND_NOT_FOUND;
1284 if (ps->searched_flag != PST_NOT_SEARCHED)
1285 return ps->searched_flag == PST_SEARCHED_AND_FOUND;
1287 /* Recurse into shared psymtabs first, because they may have already
1288 been searched, and this could save some time. */
1289 for (i = 0; i < ps->number_of_dependencies; ++i)
1293 /* Skip non-shared dependencies, these are handled elsewhere. */
1294 if (ps->dependencies[i]->user == NULL)
1297 r = recursively_search_psymtabs (ps->dependencies[i],
1298 objfile, kind, name_matcher, data);
1301 ps->searched_flag = PST_SEARCHED_AND_FOUND;
1306 gbound = (objfile->global_psymbols.list
1307 + ps->globals_offset + ps->n_global_syms);
1308 sbound = (objfile->static_psymbols.list
1309 + ps->statics_offset + ps->n_static_syms);
1312 /* Go through all of the symbols stored in a partial
1313 symtab in one loop. */
1314 psym = objfile->global_psymbols.list + ps->globals_offset;
1319 if (bound == gbound && ps->n_static_syms != 0)
1321 psym = objfile->static_psymbols.list + ps->statics_offset;
1332 if ((kind == ALL_DOMAIN
1333 || (kind == VARIABLES_DOMAIN
1334 && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
1335 && SYMBOL_CLASS (*psym) != LOC_BLOCK)
1336 || (kind == FUNCTIONS_DOMAIN
1337 && SYMBOL_CLASS (*psym) == LOC_BLOCK)
1338 || (kind == TYPES_DOMAIN
1339 && SYMBOL_CLASS (*psym) == LOC_TYPEDEF))
1340 && (*name_matcher) (SYMBOL_SEARCH_NAME (*psym), data))
1342 /* Found a match, so notify our caller. */
1343 result = PST_SEARCHED_AND_FOUND;
1350 ps->searched_flag = result;
1351 return result == PST_SEARCHED_AND_FOUND;
1355 expand_symtabs_matching_via_partial
1356 (struct objfile *objfile,
1357 int (*file_matcher) (const char *, void *),
1358 int (*name_matcher) (const char *, void *),
1359 enum search_domain kind,
1362 struct partial_symtab *ps;
1364 /* Clear the search flags. */
1365 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1367 ps->searched_flag = PST_NOT_SEARCHED;
1370 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1375 /* We skip shared psymtabs because file-matching doesn't apply
1376 to them; but we search them later in the loop. */
1377 if (ps->user != NULL)
1384 if (! (*file_matcher) (ps->filename, data))
1388 if (recursively_search_psymtabs (ps, objfile, kind, name_matcher, data))
1389 psymtab_to_symtab (objfile, ps);
1394 objfile_has_psyms (struct objfile *objfile)
1396 return objfile->psymtabs != NULL;
1399 const struct quick_symbol_functions psym_functions =
1402 find_last_source_symtab_from_partial,
1403 forget_cached_source_info_partial,
1404 partial_map_symtabs_matching_filename,
1405 lookup_symbol_aux_psymtabs,
1406 print_psymtab_stats_for_objfile,
1407 dump_psymtabs_for_objfile,
1409 read_symtabs_for_function,
1410 expand_partial_symbol_tables,
1411 read_psymtabs_with_fullname,
1412 find_symbol_file_from_partial,
1413 map_matching_symbols_psymtab,
1414 expand_symtabs_matching_via_partial,
1415 find_pc_sect_symtab_from_partial,
1416 map_symbol_filenames_psymtab
1421 /* This compares two partial symbols by names, using strcmp_iw_ordered
1422 for the comparison. */
1425 compare_psymbols (const void *s1p, const void *s2p)
1427 struct partial_symbol *const *s1 = s1p;
1428 struct partial_symbol *const *s2 = s2p;
1430 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1),
1431 SYMBOL_SEARCH_NAME (*s2));
1435 sort_pst_symbols (struct objfile *objfile, struct partial_symtab *pst)
1437 /* Sort the global list; don't sort the static list. */
1439 qsort (objfile->global_psymbols.list + pst->globals_offset,
1440 pst->n_global_syms, sizeof (struct partial_symbol *),
1444 /* Allocate and partially fill a partial symtab. It will be
1445 completely filled at the end of the symbol list.
1447 FILENAME is the name of the symbol-file we are reading from. */
1449 struct partial_symtab *
1450 start_psymtab_common (struct objfile *objfile,
1451 struct section_offsets *section_offsets,
1452 const char *filename,
1453 CORE_ADDR textlow, struct partial_symbol **global_syms,
1454 struct partial_symbol **static_syms)
1456 struct partial_symtab *psymtab;
1458 psymtab = allocate_psymtab (filename, objfile);
1459 psymtab->section_offsets = section_offsets;
1460 psymtab->textlow = textlow;
1461 psymtab->texthigh = psymtab->textlow; /* default */
1462 psymtab->globals_offset = global_syms - objfile->global_psymbols.list;
1463 psymtab->statics_offset = static_syms - objfile->static_psymbols.list;
1467 /* Calculate a hash code for the given partial symbol. The hash is
1468 calculated using the symbol's value, language, domain, class
1469 and name. These are the values which are set by
1470 add_psymbol_to_bcache. */
1472 static unsigned long
1473 psymbol_hash (const void *addr, int length)
1475 unsigned long h = 0;
1476 struct partial_symbol *psymbol = (struct partial_symbol *) addr;
1477 unsigned int lang = psymbol->ginfo.language;
1478 unsigned int domain = PSYMBOL_DOMAIN (psymbol);
1479 unsigned int class = PSYMBOL_CLASS (psymbol);
1481 h = hash_continue (&psymbol->ginfo.value, sizeof (psymbol->ginfo.value), h);
1482 h = hash_continue (&lang, sizeof (unsigned int), h);
1483 h = hash_continue (&domain, sizeof (unsigned int), h);
1484 h = hash_continue (&class, sizeof (unsigned int), h);
1485 h = hash_continue (psymbol->ginfo.name, strlen (psymbol->ginfo.name), h);
1490 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1491 For the comparison this function uses a symbols value,
1492 language, domain, class and name. */
1495 psymbol_compare (const void *addr1, const void *addr2, int length)
1497 struct partial_symbol *sym1 = (struct partial_symbol *) addr1;
1498 struct partial_symbol *sym2 = (struct partial_symbol *) addr2;
1500 return (memcmp (&sym1->ginfo.value, &sym1->ginfo.value,
1501 sizeof (sym1->ginfo.value)) == 0
1502 && sym1->ginfo.language == sym2->ginfo.language
1503 && PSYMBOL_DOMAIN (sym1) == PSYMBOL_DOMAIN (sym2)
1504 && PSYMBOL_CLASS (sym1) == PSYMBOL_CLASS (sym2)
1505 && sym1->ginfo.name == sym2->ginfo.name);
1508 /* Initialize a partial symbol bcache. */
1510 struct psymbol_bcache *
1511 psymbol_bcache_init (void)
1513 struct psymbol_bcache *bcache = XCALLOC (1, struct psymbol_bcache);
1514 bcache->bcache = bcache_xmalloc (psymbol_hash, psymbol_compare);
1518 /* Free a partial symbol bcache. */
1520 psymbol_bcache_free (struct psymbol_bcache *bcache)
1525 bcache_xfree (bcache->bcache);
1529 /* Return the internal bcache of the psymbol_bcache BCACHE. */
1532 psymbol_bcache_get_bcache (struct psymbol_bcache *bcache)
1534 return bcache->bcache;
1537 /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1538 symbol before, add a copy to BCACHE. In either case, return a pointer
1539 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1540 1 in case of new entry or 0 if returning an old entry. */
1542 static const struct partial_symbol *
1543 psymbol_bcache_full (struct partial_symbol *sym,
1544 struct psymbol_bcache *bcache,
1547 return bcache_full (sym,
1548 sizeof (struct partial_symbol),
1553 /* Helper function, initialises partial symbol structure and stashes
1554 it into objfile's bcache. Note that our caching mechanism will
1555 use all fields of struct partial_symbol to determine hash value of the
1556 structure. In other words, having two symbols with the same name but
1557 different domain (or address) is possible and correct. */
1559 static const struct partial_symbol *
1560 add_psymbol_to_bcache (const char *name, int namelength, int copy_name,
1562 enum address_class class,
1563 long val, /* Value as a long */
1564 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1565 enum language language, struct objfile *objfile,
1568 struct partial_symbol psymbol;
1570 /* We must ensure that the entire 'value' field has been zeroed
1571 before assigning to it, because an assignment may not write the
1573 memset (&psymbol.ginfo.value, 0, sizeof (psymbol.ginfo.value));
1575 /* val and coreaddr are mutually exclusive, one of them *will* be zero. */
1578 SYMBOL_VALUE (&psymbol) = val;
1582 SYMBOL_VALUE_ADDRESS (&psymbol) = coreaddr;
1584 SYMBOL_SECTION (&psymbol) = 0;
1585 SYMBOL_OBJ_SECTION (&psymbol) = NULL;
1586 SYMBOL_SET_LANGUAGE (&psymbol, language);
1587 PSYMBOL_DOMAIN (&psymbol) = domain;
1588 PSYMBOL_CLASS (&psymbol) = class;
1590 SYMBOL_SET_NAMES (&psymbol, name, namelength, copy_name, objfile);
1592 /* Stash the partial symbol away in the cache. */
1593 return psymbol_bcache_full (&psymbol,
1594 objfile->psymbol_cache,
1598 /* Increase the space allocated for LISTP, which is probably
1599 global_psymbols or static_psymbols. This space will eventually
1600 be freed in free_objfile(). */
1603 extend_psymbol_list (struct psymbol_allocation_list *listp,
1604 struct objfile *objfile)
1608 if (listp->size == 0)
1611 listp->list = (struct partial_symbol **)
1612 xmalloc (new_size * sizeof (struct partial_symbol *));
1616 new_size = listp->size * 2;
1617 listp->list = (struct partial_symbol **)
1618 xrealloc ((char *) listp->list,
1619 new_size * sizeof (struct partial_symbol *));
1621 /* Next assumes we only went one over. Should be good if
1622 program works correctly. */
1623 listp->next = listp->list + listp->size;
1624 listp->size = new_size;
1627 /* Helper function, adds partial symbol to the given partial symbol
1631 append_psymbol_to_list (struct psymbol_allocation_list *list,
1632 const struct partial_symbol *psym,
1633 struct objfile *objfile)
1635 if (list->next >= list->list + list->size)
1636 extend_psymbol_list (list, objfile);
1637 *list->next++ = (struct partial_symbol *) psym;
1638 OBJSTAT (objfile, n_psyms++);
1641 /* Add a symbol with a long value to a psymtab.
1642 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1643 Return the partial symbol that has been added. */
1646 add_psymbol_to_list (const char *name, int namelength, int copy_name,
1648 enum address_class class,
1649 struct psymbol_allocation_list *list,
1650 long val, /* Value as a long */
1651 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1652 enum language language, struct objfile *objfile)
1654 const struct partial_symbol *psym;
1658 /* Stash the partial symbol away in the cache. */
1659 psym = add_psymbol_to_bcache (name, namelength, copy_name, domain, class,
1660 val, coreaddr, language, objfile, &added);
1662 /* Do not duplicate global partial symbols. */
1663 if (list == &objfile->global_psymbols
1667 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1668 append_psymbol_to_list (list, psym, objfile);
1671 /* Initialize storage for partial symbols. */
1674 init_psymbol_list (struct objfile *objfile, int total_symbols)
1676 /* Free any previously allocated psymbol lists. */
1678 if (objfile->global_psymbols.list)
1680 xfree (objfile->global_psymbols.list);
1682 if (objfile->static_psymbols.list)
1684 xfree (objfile->static_psymbols.list);
1687 /* Current best guess is that approximately a twentieth
1688 of the total symbols (in a debugging file) are global or static
1689 oriented symbols, then multiply that by slop factor of two. */
1691 objfile->global_psymbols.size = total_symbols / 10;
1692 objfile->static_psymbols.size = total_symbols / 10;
1694 if (objfile->global_psymbols.size > 0)
1696 objfile->global_psymbols.next =
1697 objfile->global_psymbols.list = (struct partial_symbol **)
1698 xmalloc ((objfile->global_psymbols.size
1699 * sizeof (struct partial_symbol *)));
1701 if (objfile->static_psymbols.size > 0)
1703 objfile->static_psymbols.next =
1704 objfile->static_psymbols.list = (struct partial_symbol **)
1705 xmalloc ((objfile->static_psymbols.size
1706 * sizeof (struct partial_symbol *)));
1710 struct partial_symtab *
1711 allocate_psymtab (const char *filename, struct objfile *objfile)
1713 struct partial_symtab *psymtab;
1715 if (objfile->free_psymtabs)
1717 psymtab = objfile->free_psymtabs;
1718 objfile->free_psymtabs = psymtab->next;
1721 psymtab = (struct partial_symtab *)
1722 obstack_alloc (&objfile->objfile_obstack,
1723 sizeof (struct partial_symtab));
1725 memset (psymtab, 0, sizeof (struct partial_symtab));
1726 psymtab->filename = obstack_copy0 (&objfile->objfile_obstack,
1727 filename, strlen (filename));
1728 psymtab->symtab = NULL;
1730 /* Prepend it to the psymtab list for the objfile it belongs to.
1731 Psymtabs are searched in most recent inserted -> least recent
1734 psymtab->next = objfile->psymtabs;
1735 objfile->psymtabs = psymtab;
1737 if (symtab_create_debug)
1739 /* Be a bit clever with debugging messages, and don't print objfile
1740 every time, only when it changes. */
1741 static char *last_objfile_name = NULL;
1743 if (last_objfile_name == NULL
1744 || strcmp (last_objfile_name, objfile->name) != 0)
1746 xfree (last_objfile_name);
1747 last_objfile_name = xstrdup (objfile->name);
1748 fprintf_unfiltered (gdb_stdlog,
1749 "Creating one or more psymtabs for objfile %s ...\n",
1752 fprintf_unfiltered (gdb_stdlog,
1753 "Created psymtab %s for module %s.\n",
1754 host_address_to_string (psymtab), filename);
1761 discard_psymtab (struct objfile *objfile, struct partial_symtab *pst)
1763 struct partial_symtab **prev_pst;
1766 Empty psymtabs happen as a result of header files which don't
1767 have any symbols in them. There can be a lot of them. But this
1768 check is wrong, in that a psymtab with N_SLINE entries but
1769 nothing else is not empty, but we don't realize that. Fixing
1770 that without slowing things down might be tricky. */
1772 /* First, snip it out of the psymtab chain. */
1774 prev_pst = &(objfile->psymtabs);
1775 while ((*prev_pst) != pst)
1776 prev_pst = &((*prev_pst)->next);
1777 (*prev_pst) = pst->next;
1779 /* Next, put it on a free list for recycling. */
1781 pst->next = objfile->free_psymtabs;
1782 objfile->free_psymtabs = pst;
1785 /* An object of this type is passed to discard_psymtabs_upto. */
1787 struct psymtab_state
1789 /* The objfile where psymtabs are discarded. */
1791 struct objfile *objfile;
1793 /* The first psymtab to save. */
1795 struct partial_symtab *save;
1798 /* A cleanup function used by make_cleanup_discard_psymtabs. */
1801 discard_psymtabs_upto (void *arg)
1803 struct psymtab_state *state = arg;
1805 while (state->objfile->psymtabs != state->save)
1806 discard_psymtab (state->objfile, state->objfile->psymtabs);
1809 /* Return a new cleanup that discards all psymtabs created in OBJFILE
1810 after this function is called. */
1813 make_cleanup_discard_psymtabs (struct objfile *objfile)
1815 struct psymtab_state *state = XNEW (struct psymtab_state);
1817 state->objfile = objfile;
1818 state->save = objfile->psymtabs;
1820 return make_cleanup_dtor (discard_psymtabs_upto, state, xfree);
1826 maintenance_print_psymbols (char *args, int from_tty)
1829 struct ui_file *outfile;
1830 struct cleanup *cleanups;
1831 char *symname = NULL;
1832 char *filename = DEV_TTY;
1833 struct objfile *objfile;
1834 struct partial_symtab *ps;
1841 print-psymbols takes an output file name and optional symbol file name"));
1843 argv = gdb_buildargv (args);
1844 cleanups = make_cleanup_freeargv (argv);
1846 if (argv[0] != NULL)
1849 /* If a second arg is supplied, it is a source file name to match on. */
1850 if (argv[1] != NULL)
1856 filename = tilde_expand (filename);
1857 make_cleanup (xfree, filename);
1859 outfile = gdb_fopen (filename, FOPEN_WT);
1861 perror_with_name (filename);
1862 make_cleanup_ui_file_delete (outfile);
1864 ALL_PSYMTABS (objfile, ps)
1867 if (symname == NULL || filename_cmp (symname, ps->filename) == 0)
1868 dump_psymtab (objfile, ps, outfile);
1870 do_cleanups (cleanups);
1873 /* List all the partial symbol tables whose names match REGEXP (optional). */
1875 maintenance_info_psymtabs (char *regexp, int from_tty)
1877 struct program_space *pspace;
1878 struct objfile *objfile;
1883 ALL_PSPACES (pspace)
1884 ALL_PSPACE_OBJFILES (pspace, objfile)
1886 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1887 struct partial_symtab *psymtab;
1889 /* We don't want to print anything for this objfile until we
1890 actually find a symtab whose name matches. */
1891 int printed_objfile_start = 0;
1893 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
1898 || re_exec (psymtab->filename))
1900 if (! printed_objfile_start)
1902 printf_filtered ("{ objfile %s ", objfile->name);
1904 printf_filtered ("((struct objfile *) %s)\n",
1905 host_address_to_string (objfile));
1906 printed_objfile_start = 1;
1909 printf_filtered (" { psymtab %s ", psymtab->filename);
1911 printf_filtered ("((struct partial_symtab *) %s)\n",
1912 host_address_to_string (psymtab));
1914 printf_filtered (" readin %s\n",
1915 psymtab->readin ? "yes" : "no");
1916 printf_filtered (" fullname %s\n",
1918 ? psymtab->fullname : "(null)");
1919 printf_filtered (" text addresses ");
1920 fputs_filtered (paddress (gdbarch, psymtab->textlow),
1922 printf_filtered (" -- ");
1923 fputs_filtered (paddress (gdbarch, psymtab->texthigh),
1925 printf_filtered ("\n");
1926 printf_filtered (" psymtabs_addrmap_supported %s\n",
1927 (psymtab->psymtabs_addrmap_supported
1929 printf_filtered (" globals ");
1930 if (psymtab->n_global_syms)
1932 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1933 host_address_to_string (objfile->global_psymbols.list
1934 + psymtab->globals_offset),
1935 psymtab->n_global_syms);
1938 printf_filtered ("(none)\n");
1939 printf_filtered (" statics ");
1940 if (psymtab->n_static_syms)
1942 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1943 host_address_to_string (objfile->static_psymbols.list
1944 + psymtab->statics_offset),
1945 psymtab->n_static_syms);
1948 printf_filtered ("(none)\n");
1949 printf_filtered (" dependencies ");
1950 if (psymtab->number_of_dependencies)
1954 printf_filtered ("{\n");
1955 for (i = 0; i < psymtab->number_of_dependencies; i++)
1957 struct partial_symtab *dep = psymtab->dependencies[i];
1959 /* Note the string concatenation there --- no comma. */
1960 printf_filtered (" psymtab %s "
1961 "((struct partial_symtab *) %s)\n",
1963 host_address_to_string (dep));
1965 printf_filtered (" }\n");
1968 printf_filtered ("(none)\n");
1969 printf_filtered (" }\n");
1973 if (printed_objfile_start)
1974 printf_filtered ("}\n");
1978 /* Check consistency of psymtabs and symtabs. */
1981 maintenance_check_symtabs (char *ignore, int from_tty)
1984 struct partial_symbol **psym;
1985 struct symtab *s = NULL;
1986 struct partial_symtab *ps;
1987 struct blockvector *bv;
1988 struct objfile *objfile;
1992 ALL_PSYMTABS (objfile, ps)
1994 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1996 s = psymtab_to_symtab (objfile, ps);
1999 bv = BLOCKVECTOR (s);
2000 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
2001 psym = objfile->static_psymbols.list + ps->statics_offset;
2002 length = ps->n_static_syms;
2005 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
2006 SYMBOL_DOMAIN (*psym));
2009 printf_filtered ("Static symbol `");
2010 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
2011 printf_filtered ("' only found in ");
2012 puts_filtered (ps->filename);
2013 printf_filtered (" psymtab\n");
2017 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
2018 psym = objfile->global_psymbols.list + ps->globals_offset;
2019 length = ps->n_global_syms;
2022 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
2023 SYMBOL_DOMAIN (*psym));
2026 printf_filtered ("Global symbol `");
2027 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
2028 printf_filtered ("' only found in ");
2029 puts_filtered (ps->filename);
2030 printf_filtered (" psymtab\n");
2034 if (ps->texthigh < ps->textlow)
2036 printf_filtered ("Psymtab ");
2037 puts_filtered (ps->filename);
2038 printf_filtered (" covers bad range ");
2039 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
2040 printf_filtered (" - ");
2041 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
2042 printf_filtered ("\n");
2045 if (ps->texthigh == 0)
2047 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
2049 printf_filtered ("Psymtab ");
2050 puts_filtered (ps->filename);
2051 printf_filtered (" covers ");
2052 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
2053 printf_filtered (" - ");
2054 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
2055 printf_filtered (" but symtab covers only ");
2056 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
2057 printf_filtered (" - ");
2058 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout);
2059 printf_filtered ("\n");
2067 expand_partial_symbol_names (int (*fun) (const char *, void *),
2070 struct objfile *objfile;
2072 ALL_OBJFILES (objfile)
2075 objfile->sf->qf->expand_symtabs_matching (objfile, NULL, fun,
2081 map_partial_symbol_filenames (symbol_filename_ftype *fun, void *data,
2084 struct objfile *objfile;
2086 ALL_OBJFILES (objfile)
2089 objfile->sf->qf->map_symbol_filenames (objfile, fun, data,
2094 extern initialize_file_ftype _initialize_psymtab;
2097 _initialize_psymtab (void)
2099 add_cmd ("psymbols", class_maintenance, maintenance_print_psymbols, _("\
2100 Print dump of current partial symbol definitions.\n\
2101 Entries in the partial symbol table are dumped to file OUTFILE.\n\
2102 If a SOURCE file is specified, dump only that file's partial symbols."),
2103 &maintenanceprintlist);
2105 add_cmd ("psymtabs", class_maintenance, maintenance_info_psymtabs, _("\
2106 List the partial symbol tables for all object files.\n\
2107 This does not include information about individual partial symbols,\n\
2108 just the symbol table structures themselves."),
2109 &maintenanceinfolist);
2111 add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs,
2112 _("Check consistency of psymtabs and symtabs."),