1 /* Partial symbol tables.
3 Copyright (C) 2009-2012 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_assert.h"
26 #include "filenames.h"
33 #include "readline/readline.h"
34 #include "gdb_regex.h"
35 #include "dictionary.h"
37 #include "cp-support.h"
40 #define DEV_TTY "/dev/tty"
45 struct bcache *bcache;
48 static struct partial_symbol *match_partial_symbol (struct partial_symtab *,
50 const char *, domain_enum,
51 symbol_compare_ftype *,
52 symbol_compare_ftype *);
54 static struct partial_symbol *lookup_partial_symbol (struct partial_symtab *,
58 static char *psymtab_to_fullname (struct partial_symtab *ps);
60 static struct partial_symbol *find_pc_sect_psymbol (struct partial_symtab *,
62 struct obj_section *);
64 static struct partial_symbol *fixup_psymbol_section (struct partial_symbol
66 struct objfile *objfile);
68 static struct symtab *psymtab_to_symtab (struct partial_symtab *pst);
70 /* Ensure that the partial symbols for OBJFILE have been loaded. This
71 function always returns its argument, as a convenience. */
74 require_partial_symbols (struct objfile *objfile, int verbose)
76 if ((objfile->flags & OBJF_PSYMTABS_READ) == 0)
78 objfile->flags |= OBJF_PSYMTABS_READ;
80 if (objfile->sf->sym_read_psymbols)
84 printf_unfiltered (_("Reading symbols from %s..."),
86 gdb_flush (gdb_stdout);
88 (*objfile->sf->sym_read_psymbols) (objfile);
91 if (!objfile_has_symbols (objfile))
94 printf_unfiltered (_("(no debugging symbols found)..."));
98 printf_unfiltered (_("done.\n"));
106 /* Traverse all psymtabs in one objfile, requiring that the psymtabs
109 #define ALL_OBJFILE_PSYMTABS_REQUIRED(objfile, p) \
110 for ((p) = require_partial_symbols (objfile, 1)->psymtabs; \
114 /* We want to make sure this file always requires psymtabs. */
116 #undef ALL_OBJFILE_PSYMTABS
118 /* Traverse all psymtabs in all objfiles. */
120 #define ALL_PSYMTABS(objfile, p) \
121 ALL_OBJFILES (objfile) \
122 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
124 /* Helper function for partial_map_symtabs_matching_filename that
125 expands the symtabs and calls the iterator. */
128 partial_map_expand_apply (struct objfile *objfile,
130 const char *full_path,
131 const char *real_path,
132 struct partial_symtab *pst,
133 int (*callback) (struct symtab *, void *),
136 struct symtab *last_made = objfile->symtabs;
138 /* Shared psymtabs should never be seen here. Instead they should
139 be handled properly by the caller. */
140 gdb_assert (pst->user == NULL);
142 /* Don't visit already-expanded psymtabs. */
146 /* This may expand more than one symtab, and we want to iterate over
148 psymtab_to_symtab (pst);
150 return iterate_over_some_symtabs (name, full_path, real_path, callback, data,
151 objfile->symtabs, last_made);
154 /* Implementation of the map_symtabs_matching_filename method. */
157 partial_map_symtabs_matching_filename (struct objfile *objfile,
159 const char *full_path,
160 const char *real_path,
161 int (*callback) (struct symtab *,
165 struct partial_symtab *pst;
166 const char *name_basename = lbasename (name);
167 int name_len = strlen (name);
168 int is_abs = IS_ABSOLUTE_PATH (name);
170 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
172 /* We can skip shared psymtabs here, because any file name will be
173 attached to the unshared psymtab. */
174 if (pst->user != NULL)
177 if (FILENAME_CMP (name, pst->filename) == 0
178 || (!is_abs && compare_filenames_for_search (pst->filename,
181 if (partial_map_expand_apply (objfile, name, full_path, real_path,
182 pst, callback, data))
186 /* Before we invoke realpath, which can get expensive when many
187 files are involved, do a quick comparison of the basenames. */
188 if (! basenames_may_differ
189 && FILENAME_CMP (name_basename, lbasename (pst->filename)) != 0)
192 /* If the user gave us an absolute path, try to find the file in
193 this symtab and use its absolute path. */
194 if (full_path != NULL)
196 psymtab_to_fullname (pst);
197 if (pst->fullname != NULL
198 && (FILENAME_CMP (full_path, pst->fullname) == 0
199 || (!is_abs && compare_filenames_for_search (pst->fullname,
202 if (partial_map_expand_apply (objfile, name, full_path, real_path,
203 pst, callback, data))
208 if (real_path != NULL)
211 psymtab_to_fullname (pst);
212 if (pst->fullname != NULL)
214 rp = gdb_realpath (pst->fullname);
215 make_cleanup (xfree, rp);
218 && (FILENAME_CMP (real_path, rp) == 0
219 || (!is_abs && compare_filenames_for_search (real_path,
222 if (partial_map_expand_apply (objfile, name, full_path, real_path,
223 pst, callback, data))
232 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
233 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
235 static struct partial_symtab *
236 find_pc_sect_psymtab_closer (CORE_ADDR pc, struct obj_section *section,
237 struct partial_symtab *pst,
238 struct minimal_symbol *msymbol)
240 struct objfile *objfile = pst->objfile;
241 struct partial_symtab *tpst;
242 struct partial_symtab *best_pst = pst;
243 CORE_ADDR best_addr = pst->textlow;
245 gdb_assert (!pst->psymtabs_addrmap_supported);
247 /* An objfile that has its functions reordered might have
248 many partial symbol tables containing the PC, but
249 we want the partial symbol table that contains the
250 function containing the PC. */
251 if (!(objfile->flags & OBJF_REORDERED) &&
252 section == 0) /* Can't validate section this way. */
258 /* The code range of partial symtabs sometimes overlap, so, in
259 the loop below, we need to check all partial symtabs and
260 find the one that fits better for the given PC address. We
261 select the partial symtab that contains a symbol whose
262 address is closest to the PC address. By closest we mean
263 that find_pc_sect_symbol returns the symbol with address
264 that is closest and still less than the given PC. */
265 for (tpst = pst; tpst != NULL; tpst = tpst->next)
267 if (pc >= tpst->textlow && pc < tpst->texthigh)
269 struct partial_symbol *p;
272 /* NOTE: This assumes that every psymbol has a
273 corresponding msymbol, which is not necessarily
274 true; the debug info might be much richer than the
275 object's symbol table. */
276 p = find_pc_sect_psymbol (tpst, pc, section);
278 && SYMBOL_VALUE_ADDRESS (p)
279 == SYMBOL_VALUE_ADDRESS (msymbol))
282 /* Also accept the textlow value of a psymtab as a
283 "symbol", to provide some support for partial
284 symbol tables with line information but no debug
285 symbols (e.g. those produced by an assembler). */
287 this_addr = SYMBOL_VALUE_ADDRESS (p);
289 this_addr = tpst->textlow;
291 /* Check whether it is closer than our current
292 BEST_ADDR. Since this symbol address is
293 necessarily lower or equal to PC, the symbol closer
294 to PC is the symbol which address is the highest.
295 This way we return the psymtab which contains such
296 best match symbol. This can help in cases where the
297 symbol information/debuginfo is not complete, like
298 for instance on IRIX6 with gcc, where no debug info
299 is emitted for statics. (See also the nodebug.exp
301 if (this_addr > best_addr)
303 best_addr = this_addr;
311 /* Find which partial symtab contains PC and SECTION. Return 0 if
312 none. We return the psymtab that contains a symbol whose address
313 exactly matches PC, or, if we cannot find an exact match, the
314 psymtab that contains a symbol whose address is closest to PC. */
315 static struct partial_symtab *
316 find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
317 struct obj_section *section,
318 struct minimal_symbol *msymbol)
320 struct partial_symtab *pst;
322 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
323 than the later used TEXTLOW/TEXTHIGH one. */
325 if (objfile->psymtabs_addrmap != NULL)
327 pst = addrmap_find (objfile->psymtabs_addrmap, pc);
330 /* FIXME: addrmaps currently do not handle overlayed sections,
331 so fall back to the non-addrmap case if we're debugging
332 overlays and the addrmap returned the wrong section. */
333 if (overlay_debugging && msymbol && section)
335 struct partial_symbol *p;
337 /* NOTE: This assumes that every psymbol has a
338 corresponding msymbol, which is not necessarily
339 true; the debug info might be much richer than the
340 object's symbol table. */
341 p = find_pc_sect_psymbol (pst, pc, section);
343 || SYMBOL_VALUE_ADDRESS (p)
344 != SYMBOL_VALUE_ADDRESS (msymbol))
348 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
349 PSYMTABS_ADDRMAP we used has already the best 1-byte
350 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
351 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
360 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
361 which still have no corresponding full SYMTABs read. But it is not
362 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
365 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
366 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
367 debug info type in single OBJFILE. */
369 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
370 if (!pst->psymtabs_addrmap_supported
371 && pc >= pst->textlow && pc < pst->texthigh)
373 struct partial_symtab *best_pst;
375 best_pst = find_pc_sect_psymtab_closer (pc, section, pst, msymbol);
376 if (best_pst != NULL)
383 static struct symtab *
384 find_pc_sect_symtab_from_partial (struct objfile *objfile,
385 struct minimal_symbol *msymbol,
386 CORE_ADDR pc, struct obj_section *section,
389 struct partial_symtab *ps = find_pc_sect_psymtab (objfile, pc, section,
393 if (warn_if_readin && ps->readin)
394 /* Might want to error() here (in case symtab is corrupt and
395 will cause a core dump), but maybe we can successfully
396 continue, so let's not. */
398 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
399 paddress (get_objfile_arch (ps->objfile), pc));
400 return psymtab_to_symtab (ps);
405 /* Find which partial symbol within a psymtab matches PC and SECTION.
408 static struct partial_symbol *
409 find_pc_sect_psymbol (struct partial_symtab *psymtab, CORE_ADDR pc,
410 struct obj_section *section)
412 struct partial_symbol *best = NULL, *p, **pp;
415 gdb_assert (psymtab != NULL);
417 /* Cope with programs that start at address 0. */
418 best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0;
420 /* Search the global symbols as well as the static symbols, so that
421 find_pc_partial_function doesn't use a minimal symbol and thus
422 cache a bad endaddr. */
423 for (pp = psymtab->objfile->global_psymbols.list + psymtab->globals_offset;
424 (pp - (psymtab->objfile->global_psymbols.list + psymtab->globals_offset)
425 < psymtab->n_global_syms);
429 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
430 && SYMBOL_CLASS (p) == LOC_BLOCK
431 && pc >= SYMBOL_VALUE_ADDRESS (p)
432 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
433 || (psymtab->textlow == 0
434 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
436 if (section) /* Match on a specific section. */
438 fixup_psymbol_section (p, psymtab->objfile);
439 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
442 best_pc = SYMBOL_VALUE_ADDRESS (p);
447 for (pp = psymtab->objfile->static_psymbols.list + psymtab->statics_offset;
448 (pp - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset)
449 < psymtab->n_static_syms);
453 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
454 && SYMBOL_CLASS (p) == LOC_BLOCK
455 && pc >= SYMBOL_VALUE_ADDRESS (p)
456 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
457 || (psymtab->textlow == 0
458 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
460 if (section) /* Match on a specific section. */
462 fixup_psymbol_section (p, psymtab->objfile);
463 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
466 best_pc = SYMBOL_VALUE_ADDRESS (p);
474 static struct partial_symbol *
475 fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
482 if (SYMBOL_OBJ_SECTION (psym))
485 gdb_assert (objfile);
487 switch (SYMBOL_CLASS (psym))
492 addr = SYMBOL_VALUE_ADDRESS (psym);
495 /* Nothing else will be listed in the minsyms -- no use looking
500 fixup_section (&psym->ginfo, addr, objfile);
505 static struct symtab *
506 lookup_symbol_aux_psymtabs (struct objfile *objfile,
507 int block_index, const char *name,
508 const domain_enum domain)
510 struct partial_symtab *ps;
511 const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
513 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
515 if (!ps->readin && lookup_partial_symbol (ps, name, psymtab_index, domain))
517 struct symbol *sym = NULL;
518 struct symtab *stab = psymtab_to_symtab (ps);
520 /* Some caution must be observed with overloaded functions
521 and methods, since the psymtab will not contain any overload
522 information (but NAME might contain it). */
525 struct blockvector *bv = BLOCKVECTOR (stab);
526 struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
528 sym = lookup_block_symbol (block, name, domain);
531 if (sym && strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0)
534 /* Keep looking through other psymtabs. */
541 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
542 the global block of PST if GLOBAL, and otherwise the static block.
543 MATCH is the comparison operation that returns true iff MATCH (s,
544 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
545 non-null, the symbols in the block are assumed to be ordered
546 according to it (allowing binary search). It must be compatible
547 with MATCH. Returns the symbol, if found, and otherwise NULL. */
549 static struct partial_symbol *
550 match_partial_symbol (struct partial_symtab *pst, int global,
551 const char *name, domain_enum domain,
552 symbol_compare_ftype *match,
553 symbol_compare_ftype *ordered_compare)
555 struct partial_symbol **start, **psym;
556 struct partial_symbol **top, **real_top, **bottom, **center;
557 int length = (global ? pst->n_global_syms : pst->n_static_syms);
558 int do_linear_search = 1;
563 pst->objfile->global_psymbols.list + pst->globals_offset :
564 pst->objfile->static_psymbols.list + pst->statics_offset);
566 if (global && ordered_compare) /* Can use a binary search. */
568 do_linear_search = 0;
570 /* Binary search. This search is guaranteed to end with center
571 pointing at the earliest partial symbol whose name might be
572 correct. At that point *all* partial symbols with an
573 appropriate name will be checked against the correct
577 top = start + length - 1;
581 center = bottom + (top - bottom) / 2;
582 gdb_assert (center < top);
583 if (!do_linear_search
584 && (SYMBOL_LANGUAGE (*center) == language_java))
585 do_linear_search = 1;
586 if (ordered_compare (SYMBOL_SEARCH_NAME (*center), name) >= 0)
591 gdb_assert (top == bottom);
593 while (top <= real_top
594 && match (SYMBOL_SEARCH_NAME (*top), name) == 0)
596 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
597 SYMBOL_DOMAIN (*top), domain))
603 /* Can't use a binary search or else we found during the binary search that
604 we should also do a linear search. */
606 if (do_linear_search)
608 for (psym = start; psym < start + length; psym++)
610 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
611 SYMBOL_DOMAIN (*psym), domain)
612 && match (SYMBOL_SEARCH_NAME (*psym), name) == 0)
621 pre_expand_symtabs_matching_psymtabs (struct objfile *objfile,
622 enum block_enum block_kind,
629 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
630 not contain any method/function instance information (since this would
631 force reading type information while reading psymtabs). Therefore,
632 if NAME contains overload information, it must be stripped before searching
635 The caller is responsible for freeing the return result. */
638 psymtab_search_name (const char *name)
640 switch (current_language->la_language)
645 if (strchr (name, '('))
647 char *ret = cp_remove_params (name);
659 return xstrdup (name);
662 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
663 Check the global symbols if GLOBAL, the static symbols if not. */
665 static struct partial_symbol *
666 lookup_partial_symbol (struct partial_symtab *pst, const char *name,
667 int global, domain_enum domain)
669 struct partial_symbol **start, **psym;
670 struct partial_symbol **top, **real_top, **bottom, **center;
671 int length = (global ? pst->n_global_syms : pst->n_static_syms);
672 int do_linear_search = 1;
674 struct cleanup *cleanup;
681 search_name = psymtab_search_name (name);
682 cleanup = make_cleanup (xfree, search_name);
684 pst->objfile->global_psymbols.list + pst->globals_offset :
685 pst->objfile->static_psymbols.list + pst->statics_offset);
687 if (global) /* This means we can use a binary search. */
689 do_linear_search = 0;
691 /* Binary search. This search is guaranteed to end with center
692 pointing at the earliest partial symbol whose name might be
693 correct. At that point *all* partial symbols with an
694 appropriate name will be checked against the correct
698 top = start + length - 1;
702 center = bottom + (top - bottom) / 2;
704 internal_error (__FILE__, __LINE__,
705 _("failed internal consistency check"));
706 if (!do_linear_search
707 && SYMBOL_LANGUAGE (*center) == language_java)
709 do_linear_search = 1;
711 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center),
721 if (!(top == bottom))
722 internal_error (__FILE__, __LINE__,
723 _("failed internal consistency check"));
725 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
726 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
727 while (top >= start && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
730 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
733 while (top <= real_top && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
735 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
736 SYMBOL_DOMAIN (*top), domain))
738 do_cleanups (cleanup);
745 /* Can't use a binary search or else we found during the binary search that
746 we should also do a linear search. */
748 if (do_linear_search)
750 for (psym = start; psym < start + length; psym++)
752 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
753 SYMBOL_DOMAIN (*psym), domain)
754 && SYMBOL_MATCHES_SEARCH_NAME (*psym, search_name))
756 do_cleanups (cleanup);
762 do_cleanups (cleanup);
766 /* Get the symbol table that corresponds to a partial_symtab.
767 This is fast after the first time you do it. */
769 static struct symtab *
770 psymtab_to_symtab (struct partial_symtab *pst)
772 /* If it is a shared psymtab, find an unshared psymtab that includes
773 it. Any such psymtab will do. */
774 while (pst->user != NULL)
777 /* If it's been looked up before, return it. */
781 /* If it has not yet been read in, read it. */
784 struct cleanup *back_to = increment_reading_symtab ();
786 (*pst->read_symtab) (pst);
787 do_cleanups (back_to);
794 relocate_psymtabs (struct objfile *objfile,
795 struct section_offsets *new_offsets,
796 struct section_offsets *delta)
798 struct partial_symbol **psym;
799 struct partial_symtab *p;
801 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
803 p->textlow += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
804 p->texthigh += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
807 for (psym = objfile->global_psymbols.list;
808 psym < objfile->global_psymbols.next;
811 fixup_psymbol_section (*psym, objfile);
812 if (SYMBOL_SECTION (*psym) >= 0)
813 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
814 SYMBOL_SECTION (*psym));
816 for (psym = objfile->static_psymbols.list;
817 psym < objfile->static_psymbols.next;
820 fixup_psymbol_section (*psym, objfile);
821 if (SYMBOL_SECTION (*psym) >= 0)
822 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
823 SYMBOL_SECTION (*psym));
827 static struct symtab *
828 find_last_source_symtab_from_partial (struct objfile *ofp)
830 struct partial_symtab *ps;
831 struct partial_symtab *cs_pst = 0;
833 ALL_OBJFILE_PSYMTABS_REQUIRED (ofp, ps)
835 const char *name = ps->filename;
836 int len = strlen (name);
838 if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0
839 || strcmp (name, "<<C++-namespaces>>") == 0)))
847 internal_error (__FILE__, __LINE__,
848 _("select_source_symtab: "
849 "readin pst found and no symtabs."));
852 return psymtab_to_symtab (cs_pst);
858 forget_cached_source_info_partial (struct objfile *objfile)
860 struct partial_symtab *pst;
862 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
864 if (pst->fullname != NULL)
866 xfree (pst->fullname);
867 pst->fullname = NULL;
873 print_partial_symbols (struct gdbarch *gdbarch,
874 struct partial_symbol **p, int count, char *what,
875 struct ui_file *outfile)
877 fprintf_filtered (outfile, " %s partial symbols:\n", what);
880 fprintf_filtered (outfile, " `%s'", SYMBOL_LINKAGE_NAME (*p));
881 if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
883 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
885 fputs_filtered (", ", outfile);
886 switch (SYMBOL_DOMAIN (*p))
889 fputs_filtered ("undefined domain, ", outfile);
892 /* This is the usual thing -- don't print it. */
895 fputs_filtered ("struct domain, ", outfile);
898 fputs_filtered ("label domain, ", outfile);
901 fputs_filtered ("<invalid domain>, ", outfile);
904 switch (SYMBOL_CLASS (*p))
907 fputs_filtered ("undefined", outfile);
910 fputs_filtered ("constant int", outfile);
913 fputs_filtered ("static", outfile);
916 fputs_filtered ("register", outfile);
919 fputs_filtered ("pass by value", outfile);
922 fputs_filtered ("pass by reference", outfile);
924 case LOC_REGPARM_ADDR:
925 fputs_filtered ("register address parameter", outfile);
928 fputs_filtered ("stack parameter", outfile);
931 fputs_filtered ("type", outfile);
934 fputs_filtered ("label", outfile);
937 fputs_filtered ("function", outfile);
939 case LOC_CONST_BYTES:
940 fputs_filtered ("constant bytes", outfile);
943 fputs_filtered ("unresolved", outfile);
945 case LOC_OPTIMIZED_OUT:
946 fputs_filtered ("optimized out", outfile);
949 fputs_filtered ("computed at runtime", outfile);
952 fputs_filtered ("<invalid location>", outfile);
955 fputs_filtered (", ", outfile);
956 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (*p)), outfile);
957 fprintf_filtered (outfile, "\n");
963 dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
964 struct ui_file *outfile)
966 struct gdbarch *gdbarch = get_objfile_arch (objfile);
969 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
971 fprintf_filtered (outfile, "(object ");
972 gdb_print_host_address (psymtab, outfile);
973 fprintf_filtered (outfile, ")\n\n");
974 fprintf_unfiltered (outfile, " Read from object file %s (",
976 gdb_print_host_address (objfile, outfile);
977 fprintf_unfiltered (outfile, ")\n");
981 fprintf_filtered (outfile,
982 " Full symtab was read (at ");
983 gdb_print_host_address (psymtab->symtab, outfile);
984 fprintf_filtered (outfile, " by function at ");
985 gdb_print_host_address (psymtab->read_symtab, outfile);
986 fprintf_filtered (outfile, ")\n");
989 fprintf_filtered (outfile, " Relocate symbols by ");
990 for (i = 0; i < psymtab->objfile->num_sections; ++i)
993 fprintf_filtered (outfile, ", ");
995 fputs_filtered (paddress (gdbarch,
996 ANOFFSET (psymtab->section_offsets, i)),
999 fprintf_filtered (outfile, "\n");
1001 fprintf_filtered (outfile, " Symbols cover text addresses ");
1002 fputs_filtered (paddress (gdbarch, psymtab->textlow), outfile);
1003 fprintf_filtered (outfile, "-");
1004 fputs_filtered (paddress (gdbarch, psymtab->texthigh), outfile);
1005 fprintf_filtered (outfile, "\n");
1006 fprintf_filtered (outfile, " Address map supported - %s.\n",
1007 psymtab->psymtabs_addrmap_supported ? "yes" : "no");
1008 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
1009 psymtab->number_of_dependencies);
1010 for (i = 0; i < psymtab->number_of_dependencies; i++)
1012 fprintf_filtered (outfile, " %d ", i);
1013 gdb_print_host_address (psymtab->dependencies[i], outfile);
1014 fprintf_filtered (outfile, " %s\n",
1015 psymtab->dependencies[i]->filename);
1017 if (psymtab->user != NULL)
1019 fprintf_filtered (outfile, " Shared partial symtab with user ");
1020 gdb_print_host_address (psymtab->user, outfile);
1021 fprintf_filtered (outfile, "\n");
1023 if (psymtab->n_global_syms > 0)
1025 print_partial_symbols (gdbarch,
1026 objfile->global_psymbols.list
1027 + psymtab->globals_offset,
1028 psymtab->n_global_syms, "Global", outfile);
1030 if (psymtab->n_static_syms > 0)
1032 print_partial_symbols (gdbarch,
1033 objfile->static_psymbols.list
1034 + psymtab->statics_offset,
1035 psymtab->n_static_syms, "Static", outfile);
1037 fprintf_filtered (outfile, "\n");
1041 print_psymtab_stats_for_objfile (struct objfile *objfile)
1044 struct partial_symtab *ps;
1047 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1049 if (ps->readin == 0)
1052 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i);
1056 dump_psymtabs_for_objfile (struct objfile *objfile)
1058 struct partial_symtab *psymtab;
1060 if (objfile->psymtabs)
1062 printf_filtered ("Psymtabs:\n");
1063 for (psymtab = objfile->psymtabs;
1065 psymtab = psymtab->next)
1067 printf_filtered ("%s at ",
1069 gdb_print_host_address (psymtab, gdb_stdout);
1070 printf_filtered (", ");
1071 if (psymtab->objfile != objfile)
1073 printf_filtered ("NOT ON CHAIN! ");
1077 printf_filtered ("\n\n");
1081 /* Look through the partial symtabs for all symbols which begin
1082 by matching FUNC_NAME. Make sure we read that symbol table in. */
1085 read_symtabs_for_function (struct objfile *objfile, const char *func_name)
1087 struct partial_symtab *ps;
1089 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1094 if ((lookup_partial_symbol (ps, func_name, 1, VAR_DOMAIN)
1096 || (lookup_partial_symbol (ps, func_name, 0, VAR_DOMAIN)
1098 psymtab_to_symtab (ps);
1103 expand_partial_symbol_tables (struct objfile *objfile)
1105 struct partial_symtab *psymtab;
1107 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
1109 psymtab_to_symtab (psymtab);
1114 read_psymtabs_with_filename (struct objfile *objfile, const char *filename)
1116 struct partial_symtab *p;
1118 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
1120 if (filename_cmp (filename, p->filename) == 0)
1121 psymtab_to_symtab (p);
1126 map_symbol_filenames_psymtab (struct objfile *objfile,
1127 symbol_filename_ftype *fun, void *data,
1130 struct partial_symtab *ps;
1132 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1134 const char *fullname;
1141 fullname = psymtab_to_fullname (ps);
1144 (*fun) (ps->filename, fullname, data);
1148 /* Finds the fullname that a partial_symtab represents.
1150 If this functions finds the fullname, it will save it in ps->fullname
1151 and it will also return the value.
1153 If this function fails to find the file that this partial_symtab represents,
1154 NULL will be returned and ps->fullname will be set to NULL. */
1157 psymtab_to_fullname (struct partial_symtab *ps)
1164 /* Use cached copy if we have it.
1165 We rely on forget_cached_source_info being called appropriately
1166 to handle cases like the file being moved. */
1168 return ps->fullname;
1170 r = find_and_open_source (ps->filename, ps->dirname, &ps->fullname);
1175 return ps->fullname;
1182 find_symbol_file_from_partial (struct objfile *objfile, const char *name)
1184 struct partial_symtab *pst;
1186 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
1188 if (lookup_partial_symbol (pst, name, 1, VAR_DOMAIN))
1189 return pst->filename;
1194 /* For all symbols, s, in BLOCK that are in NAMESPACE and match NAME
1195 according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
1196 BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK
1197 ever returns non-zero, and otherwise returns 0. */
1200 map_block (const char *name, domain_enum namespace, struct objfile *objfile,
1201 struct block *block,
1202 int (*callback) (struct block *, struct symbol *, void *),
1203 void *data, symbol_compare_ftype *match)
1205 struct block_iterator iter;
1208 for (sym = block_iter_match_first (block, name, match, &iter);
1209 sym != NULL; sym = block_iter_match_next (name, match, &iter))
1211 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
1212 SYMBOL_DOMAIN (sym), namespace))
1214 if (callback (block, sym, data))
1222 /* Psymtab version of map_matching_symbols. See its definition in
1223 the definition of quick_symbol_functions in symfile.h. */
1226 map_matching_symbols_psymtab (const char *name, domain_enum namespace,
1227 struct objfile *objfile, int global,
1228 int (*callback) (struct block *,
1229 struct symbol *, void *),
1231 symbol_compare_ftype *match,
1232 symbol_compare_ftype *ordered_compare)
1234 const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
1235 struct partial_symtab *ps;
1237 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1241 || match_partial_symbol (ps, global, name, namespace, match,
1244 struct symtab *s = psymtab_to_symtab (ps);
1245 struct block *block;
1247 if (s == NULL || !s->primary)
1249 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), block_kind);
1250 if (map_block (name, namespace, objfile, block,
1251 callback, data, match))
1253 if (callback (block, NULL, data))
1259 /* A helper for expand_symtabs_matching_via_partial that handles
1260 searching included psymtabs. This returns 1 if a symbol is found,
1261 and zero otherwise. It also updates the 'searched_flag' on the
1262 various psymtabs that it searches. */
1265 recursively_search_psymtabs (struct partial_symtab *ps,
1266 struct objfile *objfile,
1267 enum search_domain kind,
1268 int (*name_matcher) (const char *, void *),
1271 struct partial_symbol **psym;
1272 struct partial_symbol **bound, **gbound, **sbound;
1274 int result = PST_SEARCHED_AND_NOT_FOUND;
1277 if (ps->searched_flag != PST_NOT_SEARCHED)
1278 return ps->searched_flag == PST_SEARCHED_AND_FOUND;
1280 /* Recurse into shared psymtabs first, because they may have already
1281 been searched, and this could save some time. */
1282 for (i = 0; i < ps->number_of_dependencies; ++i)
1286 /* Skip non-shared dependencies, these are handled elsewhere. */
1287 if (ps->dependencies[i]->user == NULL)
1290 r = recursively_search_psymtabs (ps->dependencies[i],
1291 objfile, kind, name_matcher, data);
1294 ps->searched_flag = PST_SEARCHED_AND_FOUND;
1299 gbound = (objfile->global_psymbols.list
1300 + ps->globals_offset + ps->n_global_syms);
1301 sbound = (objfile->static_psymbols.list
1302 + ps->statics_offset + ps->n_static_syms);
1305 /* Go through all of the symbols stored in a partial
1306 symtab in one loop. */
1307 psym = objfile->global_psymbols.list + ps->globals_offset;
1312 if (bound == gbound && ps->n_static_syms != 0)
1314 psym = objfile->static_psymbols.list + ps->statics_offset;
1325 if ((kind == ALL_DOMAIN
1326 || (kind == VARIABLES_DOMAIN
1327 && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
1328 && SYMBOL_CLASS (*psym) != LOC_BLOCK)
1329 || (kind == FUNCTIONS_DOMAIN
1330 && SYMBOL_CLASS (*psym) == LOC_BLOCK)
1331 || (kind == TYPES_DOMAIN
1332 && SYMBOL_CLASS (*psym) == LOC_TYPEDEF))
1333 && (*name_matcher) (SYMBOL_SEARCH_NAME (*psym), data))
1335 /* Found a match, so notify our caller. */
1336 result = PST_SEARCHED_AND_FOUND;
1343 ps->searched_flag = result;
1344 return result == PST_SEARCHED_AND_FOUND;
1348 expand_symtabs_matching_via_partial
1349 (struct objfile *objfile,
1350 int (*file_matcher) (const char *, void *),
1351 int (*name_matcher) (const char *, void *),
1352 enum search_domain kind,
1355 struct partial_symtab *ps;
1357 /* Clear the search flags. */
1358 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1360 ps->searched_flag = PST_NOT_SEARCHED;
1363 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1368 /* We skip shared psymtabs because file-matching doesn't apply
1369 to them; but we search them later in the loop. */
1370 if (ps->user != NULL)
1373 if (file_matcher && ! (*file_matcher) (ps->filename, data))
1376 if (recursively_search_psymtabs (ps, objfile, kind, name_matcher, data))
1377 psymtab_to_symtab (ps);
1382 objfile_has_psyms (struct objfile *objfile)
1384 return objfile->psymtabs != NULL;
1387 const struct quick_symbol_functions psym_functions =
1390 find_last_source_symtab_from_partial,
1391 forget_cached_source_info_partial,
1392 partial_map_symtabs_matching_filename,
1393 lookup_symbol_aux_psymtabs,
1394 pre_expand_symtabs_matching_psymtabs,
1395 print_psymtab_stats_for_objfile,
1396 dump_psymtabs_for_objfile,
1398 read_symtabs_for_function,
1399 expand_partial_symbol_tables,
1400 read_psymtabs_with_filename,
1401 find_symbol_file_from_partial,
1402 map_matching_symbols_psymtab,
1403 expand_symtabs_matching_via_partial,
1404 find_pc_sect_symtab_from_partial,
1405 map_symbol_filenames_psymtab
1410 /* This compares two partial symbols by names, using strcmp_iw_ordered
1411 for the comparison. */
1414 compare_psymbols (const void *s1p, const void *s2p)
1416 struct partial_symbol *const *s1 = s1p;
1417 struct partial_symbol *const *s2 = s2p;
1419 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1),
1420 SYMBOL_SEARCH_NAME (*s2));
1424 sort_pst_symbols (struct partial_symtab *pst)
1426 /* Sort the global list; don't sort the static list. */
1428 qsort (pst->objfile->global_psymbols.list + pst->globals_offset,
1429 pst->n_global_syms, sizeof (struct partial_symbol *),
1433 /* Allocate and partially fill a partial symtab. It will be
1434 completely filled at the end of the symbol list.
1436 FILENAME is the name of the symbol-file we are reading from. */
1438 struct partial_symtab *
1439 start_psymtab_common (struct objfile *objfile,
1440 struct section_offsets *section_offsets,
1441 const char *filename,
1442 CORE_ADDR textlow, struct partial_symbol **global_syms,
1443 struct partial_symbol **static_syms)
1445 struct partial_symtab *psymtab;
1447 psymtab = allocate_psymtab (filename, objfile);
1448 psymtab->section_offsets = section_offsets;
1449 psymtab->textlow = textlow;
1450 psymtab->texthigh = psymtab->textlow; /* default */
1451 psymtab->globals_offset = global_syms - objfile->global_psymbols.list;
1452 psymtab->statics_offset = static_syms - objfile->static_psymbols.list;
1456 /* Calculate a hash code for the given partial symbol. The hash is
1457 calculated using the symbol's value, language, domain, class
1458 and name. These are the values which are set by
1459 add_psymbol_to_bcache. */
1461 static unsigned long
1462 psymbol_hash (const void *addr, int length)
1464 unsigned long h = 0;
1465 struct partial_symbol *psymbol = (struct partial_symbol *) addr;
1466 unsigned int lang = psymbol->ginfo.language;
1467 unsigned int domain = PSYMBOL_DOMAIN (psymbol);
1468 unsigned int class = PSYMBOL_CLASS (psymbol);
1470 h = hash_continue (&psymbol->ginfo.value, sizeof (psymbol->ginfo.value), h);
1471 h = hash_continue (&lang, sizeof (unsigned int), h);
1472 h = hash_continue (&domain, sizeof (unsigned int), h);
1473 h = hash_continue (&class, sizeof (unsigned int), h);
1474 h = hash_continue (psymbol->ginfo.name, strlen (psymbol->ginfo.name), h);
1479 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1480 For the comparison this function uses a symbols value,
1481 language, domain, class and name. */
1484 psymbol_compare (const void *addr1, const void *addr2, int length)
1486 struct partial_symbol *sym1 = (struct partial_symbol *) addr1;
1487 struct partial_symbol *sym2 = (struct partial_symbol *) addr2;
1489 return (memcmp (&sym1->ginfo.value, &sym1->ginfo.value,
1490 sizeof (sym1->ginfo.value)) == 0
1491 && sym1->ginfo.language == sym2->ginfo.language
1492 && PSYMBOL_DOMAIN (sym1) == PSYMBOL_DOMAIN (sym2)
1493 && PSYMBOL_CLASS (sym1) == PSYMBOL_CLASS (sym2)
1494 && sym1->ginfo.name == sym2->ginfo.name);
1497 /* Initialize a partial symbol bcache. */
1499 struct psymbol_bcache *
1500 psymbol_bcache_init (void)
1502 struct psymbol_bcache *bcache = XCALLOC (1, struct psymbol_bcache);
1503 bcache->bcache = bcache_xmalloc (psymbol_hash, psymbol_compare);
1507 /* Free a partial symbol bcache. */
1509 psymbol_bcache_free (struct psymbol_bcache *bcache)
1514 bcache_xfree (bcache->bcache);
1518 /* Return the internal bcache of the psymbol_bcache BCACHE. */
1521 psymbol_bcache_get_bcache (struct psymbol_bcache *bcache)
1523 return bcache->bcache;
1526 /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1527 symbol before, add a copy to BCACHE. In either case, return a pointer
1528 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1529 1 in case of new entry or 0 if returning an old entry. */
1531 static const struct partial_symbol *
1532 psymbol_bcache_full (struct partial_symbol *sym,
1533 struct psymbol_bcache *bcache,
1536 return bcache_full (sym,
1537 sizeof (struct partial_symbol),
1542 /* Helper function, initialises partial symbol structure and stashes
1543 it into objfile's bcache. Note that our caching mechanism will
1544 use all fields of struct partial_symbol to determine hash value of the
1545 structure. In other words, having two symbols with the same name but
1546 different domain (or address) is possible and correct. */
1548 static const struct partial_symbol *
1549 add_psymbol_to_bcache (const char *name, int namelength, int copy_name,
1551 enum address_class class,
1552 long val, /* Value as a long */
1553 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1554 enum language language, struct objfile *objfile,
1557 struct partial_symbol psymbol;
1559 /* We must ensure that the entire 'value' field has been zeroed
1560 before assigning to it, because an assignment may not write the
1562 memset (&psymbol.ginfo.value, 0, sizeof (psymbol.ginfo.value));
1564 /* val and coreaddr are mutually exclusive, one of them *will* be zero. */
1567 SYMBOL_VALUE (&psymbol) = val;
1571 SYMBOL_VALUE_ADDRESS (&psymbol) = coreaddr;
1573 SYMBOL_SECTION (&psymbol) = 0;
1574 SYMBOL_OBJ_SECTION (&psymbol) = NULL;
1575 SYMBOL_SET_LANGUAGE (&psymbol, language);
1576 PSYMBOL_DOMAIN (&psymbol) = domain;
1577 PSYMBOL_CLASS (&psymbol) = class;
1579 SYMBOL_SET_NAMES (&psymbol, name, namelength, copy_name, objfile);
1581 /* Stash the partial symbol away in the cache. */
1582 return psymbol_bcache_full (&psymbol,
1583 objfile->psymbol_cache,
1587 /* Increase the space allocated for LISTP, which is probably
1588 global_psymbols or static_psymbols. This space will eventually
1589 be freed in free_objfile(). */
1592 extend_psymbol_list (struct psymbol_allocation_list *listp,
1593 struct objfile *objfile)
1597 if (listp->size == 0)
1600 listp->list = (struct partial_symbol **)
1601 xmalloc (new_size * sizeof (struct partial_symbol *));
1605 new_size = listp->size * 2;
1606 listp->list = (struct partial_symbol **)
1607 xrealloc ((char *) listp->list,
1608 new_size * sizeof (struct partial_symbol *));
1610 /* Next assumes we only went one over. Should be good if
1611 program works correctly. */
1612 listp->next = listp->list + listp->size;
1613 listp->size = new_size;
1616 /* Helper function, adds partial symbol to the given partial symbol
1620 append_psymbol_to_list (struct psymbol_allocation_list *list,
1621 const struct partial_symbol *psym,
1622 struct objfile *objfile)
1624 if (list->next >= list->list + list->size)
1625 extend_psymbol_list (list, objfile);
1626 *list->next++ = (struct partial_symbol *) psym;
1627 OBJSTAT (objfile, n_psyms++);
1630 /* Add a symbol with a long value to a psymtab.
1631 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1632 Return the partial symbol that has been added. */
1635 add_psymbol_to_list (const char *name, int namelength, int copy_name,
1637 enum address_class class,
1638 struct psymbol_allocation_list *list,
1639 long val, /* Value as a long */
1640 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1641 enum language language, struct objfile *objfile)
1643 const struct partial_symbol *psym;
1647 /* Stash the partial symbol away in the cache. */
1648 psym = add_psymbol_to_bcache (name, namelength, copy_name, domain, class,
1649 val, coreaddr, language, objfile, &added);
1651 /* Do not duplicate global partial symbols. */
1652 if (list == &objfile->global_psymbols
1656 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1657 append_psymbol_to_list (list, psym, objfile);
1660 /* Initialize storage for partial symbols. */
1663 init_psymbol_list (struct objfile *objfile, int total_symbols)
1665 /* Free any previously allocated psymbol lists. */
1667 if (objfile->global_psymbols.list)
1669 xfree (objfile->global_psymbols.list);
1671 if (objfile->static_psymbols.list)
1673 xfree (objfile->static_psymbols.list);
1676 /* Current best guess is that approximately a twentieth
1677 of the total symbols (in a debugging file) are global or static
1678 oriented symbols. */
1680 objfile->global_psymbols.size = total_symbols / 10;
1681 objfile->static_psymbols.size = total_symbols / 10;
1683 if (objfile->global_psymbols.size > 0)
1685 objfile->global_psymbols.next =
1686 objfile->global_psymbols.list = (struct partial_symbol **)
1687 xmalloc ((objfile->global_psymbols.size
1688 * sizeof (struct partial_symbol *)));
1690 if (objfile->static_psymbols.size > 0)
1692 objfile->static_psymbols.next =
1693 objfile->static_psymbols.list = (struct partial_symbol **)
1694 xmalloc ((objfile->static_psymbols.size
1695 * sizeof (struct partial_symbol *)));
1699 struct partial_symtab *
1700 allocate_psymtab (const char *filename, struct objfile *objfile)
1702 struct partial_symtab *psymtab;
1704 if (objfile->free_psymtabs)
1706 psymtab = objfile->free_psymtabs;
1707 objfile->free_psymtabs = psymtab->next;
1710 psymtab = (struct partial_symtab *)
1711 obstack_alloc (&objfile->objfile_obstack,
1712 sizeof (struct partial_symtab));
1714 memset (psymtab, 0, sizeof (struct partial_symtab));
1715 psymtab->filename = obsavestring (filename, strlen (filename),
1716 &objfile->objfile_obstack);
1717 psymtab->symtab = NULL;
1719 /* Prepend it to the psymtab list for the objfile it belongs to.
1720 Psymtabs are searched in most recent inserted -> least recent
1723 psymtab->objfile = objfile;
1724 psymtab->next = objfile->psymtabs;
1725 objfile->psymtabs = psymtab;
1731 discard_psymtab (struct partial_symtab *pst)
1733 struct partial_symtab **prev_pst;
1736 Empty psymtabs happen as a result of header files which don't
1737 have any symbols in them. There can be a lot of them. But this
1738 check is wrong, in that a psymtab with N_SLINE entries but
1739 nothing else is not empty, but we don't realize that. Fixing
1740 that without slowing things down might be tricky. */
1742 /* First, snip it out of the psymtab chain. */
1744 prev_pst = &(pst->objfile->psymtabs);
1745 while ((*prev_pst) != pst)
1746 prev_pst = &((*prev_pst)->next);
1747 (*prev_pst) = pst->next;
1749 /* Next, put it on a free list for recycling. */
1751 pst->next = pst->objfile->free_psymtabs;
1752 pst->objfile->free_psymtabs = pst;
1758 maintenance_print_psymbols (char *args, int from_tty)
1761 struct ui_file *outfile;
1762 struct cleanup *cleanups;
1763 char *symname = NULL;
1764 char *filename = DEV_TTY;
1765 struct objfile *objfile;
1766 struct partial_symtab *ps;
1773 print-psymbols takes an output file name and optional symbol file name"));
1775 argv = gdb_buildargv (args);
1776 cleanups = make_cleanup_freeargv (argv);
1778 if (argv[0] != NULL)
1781 /* If a second arg is supplied, it is a source file name to match on. */
1782 if (argv[1] != NULL)
1788 filename = tilde_expand (filename);
1789 make_cleanup (xfree, filename);
1791 outfile = gdb_fopen (filename, FOPEN_WT);
1793 perror_with_name (filename);
1794 make_cleanup_ui_file_delete (outfile);
1797 ALL_PSYMTABS (objfile, ps)
1798 if (symname == NULL || filename_cmp (symname, ps->filename) == 0)
1799 dump_psymtab (objfile, ps, outfile);
1801 do_cleanups (cleanups);
1804 /* List all the partial symbol tables whose names match REGEXP (optional). */
1806 maintenance_info_psymtabs (char *regexp, int from_tty)
1808 struct program_space *pspace;
1809 struct objfile *objfile;
1814 ALL_PSPACES (pspace)
1815 ALL_PSPACE_OBJFILES (pspace, objfile)
1817 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1818 struct partial_symtab *psymtab;
1820 /* We don't want to print anything for this objfile until we
1821 actually find a symtab whose name matches. */
1822 int printed_objfile_start = 0;
1824 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
1829 || re_exec (psymtab->filename))
1831 if (! printed_objfile_start)
1833 printf_filtered ("{ objfile %s ", objfile->name);
1835 printf_filtered ("((struct objfile *) %s)\n",
1836 host_address_to_string (objfile));
1837 printed_objfile_start = 1;
1840 printf_filtered (" { psymtab %s ", psymtab->filename);
1842 printf_filtered ("((struct partial_symtab *) %s)\n",
1843 host_address_to_string (psymtab));
1845 printf_filtered (" readin %s\n",
1846 psymtab->readin ? "yes" : "no");
1847 printf_filtered (" fullname %s\n",
1849 ? psymtab->fullname : "(null)");
1850 printf_filtered (" text addresses ");
1851 fputs_filtered (paddress (gdbarch, psymtab->textlow),
1853 printf_filtered (" -- ");
1854 fputs_filtered (paddress (gdbarch, psymtab->texthigh),
1856 printf_filtered ("\n");
1857 printf_filtered (" psymtabs_addrmap_supported %s\n",
1858 (psymtab->psymtabs_addrmap_supported
1860 printf_filtered (" globals ");
1861 if (psymtab->n_global_syms)
1863 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1864 host_address_to_string (psymtab->objfile->global_psymbols.list
1865 + psymtab->globals_offset),
1866 psymtab->n_global_syms);
1869 printf_filtered ("(none)\n");
1870 printf_filtered (" statics ");
1871 if (psymtab->n_static_syms)
1873 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1874 host_address_to_string (psymtab->objfile->static_psymbols.list
1875 + psymtab->statics_offset),
1876 psymtab->n_static_syms);
1879 printf_filtered ("(none)\n");
1880 printf_filtered (" dependencies ");
1881 if (psymtab->number_of_dependencies)
1885 printf_filtered ("{\n");
1886 for (i = 0; i < psymtab->number_of_dependencies; i++)
1888 struct partial_symtab *dep = psymtab->dependencies[i];
1890 /* Note the string concatenation there --- no comma. */
1891 printf_filtered (" psymtab %s "
1892 "((struct partial_symtab *) %s)\n",
1894 host_address_to_string (dep));
1896 printf_filtered (" }\n");
1899 printf_filtered ("(none)\n");
1900 printf_filtered (" }\n");
1904 if (printed_objfile_start)
1905 printf_filtered ("}\n");
1909 /* Check consistency of psymtabs and symtabs. */
1912 maintenance_check_symtabs (char *ignore, int from_tty)
1915 struct partial_symbol **psym;
1916 struct symtab *s = NULL;
1917 struct partial_symtab *ps;
1918 struct blockvector *bv;
1919 struct objfile *objfile;
1923 ALL_PSYMTABS (objfile, ps)
1925 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1927 s = psymtab_to_symtab (ps);
1930 bv = BLOCKVECTOR (s);
1931 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1932 psym = ps->objfile->static_psymbols.list + ps->statics_offset;
1933 length = ps->n_static_syms;
1936 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1937 SYMBOL_DOMAIN (*psym));
1940 printf_filtered ("Static symbol `");
1941 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1942 printf_filtered ("' only found in ");
1943 puts_filtered (ps->filename);
1944 printf_filtered (" psymtab\n");
1948 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1949 psym = ps->objfile->global_psymbols.list + ps->globals_offset;
1950 length = ps->n_global_syms;
1953 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1954 SYMBOL_DOMAIN (*psym));
1957 printf_filtered ("Global symbol `");
1958 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1959 printf_filtered ("' only found in ");
1960 puts_filtered (ps->filename);
1961 printf_filtered (" psymtab\n");
1965 if (ps->texthigh < ps->textlow)
1967 printf_filtered ("Psymtab ");
1968 puts_filtered (ps->filename);
1969 printf_filtered (" covers bad range ");
1970 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
1971 printf_filtered (" - ");
1972 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
1973 printf_filtered ("\n");
1976 if (ps->texthigh == 0)
1978 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
1980 printf_filtered ("Psymtab ");
1981 puts_filtered (ps->filename);
1982 printf_filtered (" covers ");
1983 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
1984 printf_filtered (" - ");
1985 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
1986 printf_filtered (" but symtab covers only ");
1987 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
1988 printf_filtered (" - ");
1989 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout);
1990 printf_filtered ("\n");
1998 expand_partial_symbol_names (int (*fun) (const char *, void *),
2001 struct objfile *objfile;
2003 ALL_OBJFILES (objfile)
2006 objfile->sf->qf->expand_symtabs_matching (objfile, NULL, fun,
2012 map_partial_symbol_filenames (symbol_filename_ftype *fun, void *data,
2015 struct objfile *objfile;
2017 ALL_OBJFILES (objfile)
2020 objfile->sf->qf->map_symbol_filenames (objfile, fun, data,