1 /* Do various things to symbol tables (other than lookup), for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 #include "breakpoint.h"
30 #include "gdb_obstack.h"
31 #include "exceptions.h"
35 #include "gdb_regex.h"
37 #include "dictionary.h"
39 #include "gdb_string.h"
40 #include "readline/readline.h"
43 #define DEV_TTY "/dev/tty"
46 /* Unfortunately for debugging, stderr is usually a macro. This is painful
47 when calling functions that take FILE *'s from the debugger.
48 So we make a variable which has the same value and which is accessible when
49 debugging GDB with itself. Because stdin et al need not be constants,
50 we initialize them in the _initialize_symmisc function at the bottom
56 /* Prototypes for local functions */
58 static void dump_symtab (struct objfile *, struct symtab *,
61 static void dump_psymtab (struct objfile *, struct partial_symtab *,
64 static void dump_msymbols (struct objfile *, struct ui_file *);
66 static void dump_objfile (struct objfile *);
68 static int block_depth (struct block *);
70 static void print_partial_symbols (struct gdbarch *,
71 struct partial_symbol **, int,
72 char *, struct ui_file *);
74 void _initialize_symmisc (void);
76 struct print_symbol_args
78 struct gdbarch *gdbarch;
79 struct symbol *symbol;
81 struct ui_file *outfile;
84 static int print_symbol (void *);
86 /* Free all the storage associated with the struct symtab <- S.
87 Note that some symtabs have contents that all live inside one big block of
88 memory, and some share the contents of another symbol table and so you
89 should not free the contents on their behalf (except sometimes the
90 linetable, which maybe per symtab even when the rest is not).
91 It is s->free_code that says which alternative to use. */
94 free_symtab (struct symtab *s)
97 struct blockvector *bv;
102 /* All the contents are part of a big block of memory (an obstack),
103 and some other symtab is in charge of freeing that block.
104 Therefore, do nothing. */
108 /* Everything will be freed either by our `free_func'
109 or by some other symtab, except for our linetable.
112 xfree (LINETABLE (s));
116 /* If there is a single block of memory to free, free it. */
117 if (s->free_func != NULL)
120 /* Free source-related stuff */
121 if (s->line_charpos != NULL)
122 xfree (s->line_charpos);
123 if (s->fullname != NULL)
125 if (s->debugformat != NULL)
126 xfree (s->debugformat);
131 print_symbol_bcache_statistics (void)
133 struct program_space *pspace;
134 struct objfile *objfile;
138 ALL_PSPACE_OBJFILES (pspace, objfile)
140 printf_filtered (_("Byte cache statistics for '%s':\n"), objfile->name);
141 print_bcache_statistics (objfile->psymbol_cache, "partial symbol cache");
142 print_bcache_statistics (objfile->macro_cache, "preprocessor macro cache");
143 print_bcache_statistics (objfile->filename_cache, "file name cache");
149 print_objfile_statistics (void)
151 struct program_space *pspace;
152 struct objfile *objfile;
154 struct partial_symtab *ps;
155 int i, linetables, blockvectors;
159 ALL_PSPACE_OBJFILES (pspace, objfile)
161 printf_filtered (_("Statistics for '%s':\n"), objfile->name);
162 if (OBJSTAT (objfile, n_stabs) > 0)
163 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
164 OBJSTAT (objfile, n_stabs));
165 if (OBJSTAT (objfile, n_minsyms) > 0)
166 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
167 OBJSTAT (objfile, n_minsyms));
168 if (OBJSTAT (objfile, n_psyms) > 0)
169 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
170 OBJSTAT (objfile, n_psyms));
171 if (OBJSTAT (objfile, n_syms) > 0)
172 printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
173 OBJSTAT (objfile, n_syms));
174 if (OBJSTAT (objfile, n_types) > 0)
175 printf_filtered (_(" Number of \"types\" defined: %d\n"),
176 OBJSTAT (objfile, n_types));
178 ALL_OBJFILE_PSYMTABS (objfile, ps)
183 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i);
184 i = linetables = blockvectors = 0;
185 ALL_OBJFILE_SYMTABS (objfile, s)
188 if (s->linetable != NULL)
193 printf_filtered (_(" Number of symbol tables: %d\n"), i);
194 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
196 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
199 if (OBJSTAT (objfile, sz_strtab) > 0)
200 printf_filtered (_(" Space used by a.out string tables: %d\n"),
201 OBJSTAT (objfile, sz_strtab));
202 printf_filtered (_(" Total memory used for objfile obstack: %d\n"),
203 obstack_memory_used (&objfile->objfile_obstack));
204 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
205 bcache_memory_used (objfile->psymbol_cache));
206 printf_filtered (_(" Total memory used for macro cache: %d\n"),
207 bcache_memory_used (objfile->macro_cache));
208 printf_filtered (_(" Total memory used for file name cache: %d\n"),
209 bcache_memory_used (objfile->filename_cache));
215 dump_objfile (struct objfile *objfile)
217 struct symtab *symtab;
218 struct partial_symtab *psymtab;
220 printf_filtered ("\nObject file %s: ", objfile->name);
221 printf_filtered ("Objfile at ");
222 gdb_print_host_address (objfile, gdb_stdout);
223 printf_filtered (", bfd at ");
224 gdb_print_host_address (objfile->obfd, gdb_stdout);
225 printf_filtered (", %d minsyms\n\n",
226 objfile->minimal_symbol_count);
228 if (objfile->psymtabs)
230 printf_filtered ("Psymtabs:\n");
231 for (psymtab = objfile->psymtabs;
233 psymtab = psymtab->next)
235 printf_filtered ("%s at ",
237 gdb_print_host_address (psymtab, gdb_stdout);
238 printf_filtered (", ");
239 if (psymtab->objfile != objfile)
241 printf_filtered ("NOT ON CHAIN! ");
245 printf_filtered ("\n\n");
248 if (objfile->symtabs)
250 printf_filtered ("Symtabs:\n");
251 for (symtab = objfile->symtabs;
253 symtab = symtab->next)
255 printf_filtered ("%s at ", symtab->filename);
256 gdb_print_host_address (symtab, gdb_stdout);
257 printf_filtered (", ");
258 if (symtab->objfile != objfile)
260 printf_filtered ("NOT ON CHAIN! ");
264 printf_filtered ("\n\n");
268 /* Print minimal symbols from this objfile. */
271 dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
273 struct gdbarch *gdbarch = get_objfile_arch (objfile);
274 struct minimal_symbol *msymbol;
278 fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile->name);
279 if (objfile->minimal_symbol_count == 0)
281 fprintf_filtered (outfile, "No minimal symbols found.\n");
285 ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
287 struct obj_section *section = SYMBOL_OBJ_SECTION (msymbol);
289 switch (MSYMBOL_TYPE (msymbol))
297 case mst_solib_trampoline:
322 fprintf_filtered (outfile, "[%2d] %c ", index, ms_type);
323 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (msymbol)),
325 fprintf_filtered (outfile, " %s", SYMBOL_LINKAGE_NAME (msymbol));
327 fprintf_filtered (outfile, " section %s",
328 bfd_section_name (objfile->obfd,
329 section->the_bfd_section));
330 if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
332 fprintf_filtered (outfile, " %s", SYMBOL_DEMANGLED_NAME (msymbol));
334 if (msymbol->filename)
335 fprintf_filtered (outfile, " %s", msymbol->filename);
336 fputs_filtered ("\n", outfile);
339 if (objfile->minimal_symbol_count != index)
341 warning (_("internal error: minimal symbol count %d != %d"),
342 objfile->minimal_symbol_count, index);
344 fprintf_filtered (outfile, "\n");
348 dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
349 struct ui_file *outfile)
351 struct gdbarch *gdbarch = get_objfile_arch (objfile);
354 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
356 fprintf_filtered (outfile, "(object ");
357 gdb_print_host_address (psymtab, outfile);
358 fprintf_filtered (outfile, ")\n\n");
359 fprintf_unfiltered (outfile, " Read from object file %s (",
361 gdb_print_host_address (objfile, outfile);
362 fprintf_unfiltered (outfile, ")\n");
366 fprintf_filtered (outfile,
367 " Full symtab was read (at ");
368 gdb_print_host_address (psymtab->symtab, outfile);
369 fprintf_filtered (outfile, " by function at ");
370 gdb_print_host_address (psymtab->read_symtab, outfile);
371 fprintf_filtered (outfile, ")\n");
374 fprintf_filtered (outfile, " Relocate symbols by ");
375 for (i = 0; i < psymtab->objfile->num_sections; ++i)
378 fprintf_filtered (outfile, ", ");
380 fputs_filtered (paddress (gdbarch,
381 ANOFFSET (psymtab->section_offsets, i)),
384 fprintf_filtered (outfile, "\n");
386 fprintf_filtered (outfile, " Symbols cover text addresses ");
387 fputs_filtered (paddress (gdbarch, psymtab->textlow), outfile);
388 fprintf_filtered (outfile, "-");
389 fputs_filtered (paddress (gdbarch, psymtab->texthigh), outfile);
390 fprintf_filtered (outfile, "\n");
391 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
392 psymtab->number_of_dependencies);
393 for (i = 0; i < psymtab->number_of_dependencies; i++)
395 fprintf_filtered (outfile, " %d ", i);
396 gdb_print_host_address (psymtab->dependencies[i], outfile);
397 fprintf_filtered (outfile, " %s\n",
398 psymtab->dependencies[i]->filename);
400 if (psymtab->n_global_syms > 0)
402 print_partial_symbols (gdbarch,
403 objfile->global_psymbols.list
404 + psymtab->globals_offset,
405 psymtab->n_global_syms, "Global", outfile);
407 if (psymtab->n_static_syms > 0)
409 print_partial_symbols (gdbarch,
410 objfile->static_psymbols.list
411 + psymtab->statics_offset,
412 psymtab->n_static_syms, "Static", outfile);
414 fprintf_filtered (outfile, "\n");
418 dump_symtab_1 (struct objfile *objfile, struct symtab *symtab,
419 struct ui_file *outfile)
421 struct gdbarch *gdbarch = get_objfile_arch (objfile);
423 struct dict_iterator iter;
426 struct blockvector *bv;
431 fprintf_filtered (outfile, "\nSymtab for file %s\n", symtab->filename);
433 fprintf_filtered (outfile, "Compilation directory is %s\n",
435 fprintf_filtered (outfile, "Read from object file %s (", objfile->name);
436 gdb_print_host_address (objfile, outfile);
437 fprintf_filtered (outfile, ")\n");
438 fprintf_filtered (outfile, "Language: %s\n", language_str (symtab->language));
440 /* First print the line table. */
441 l = LINETABLE (symtab);
444 fprintf_filtered (outfile, "\nLine table:\n\n");
446 for (i = 0; i < len; i++)
448 fprintf_filtered (outfile, " line %d at ", l->item[i].line);
449 fputs_filtered (paddress (gdbarch, l->item[i].pc), outfile);
450 fprintf_filtered (outfile, "\n");
453 /* Now print the block info, but only for primary symtabs since we will
454 print lots of duplicate info otherwise. */
457 fprintf_filtered (outfile, "\nBlockvector:\n\n");
458 bv = BLOCKVECTOR (symtab);
459 len = BLOCKVECTOR_NBLOCKS (bv);
460 for (i = 0; i < len; i++)
462 b = BLOCKVECTOR_BLOCK (bv, i);
463 depth = block_depth (b) * 2;
464 print_spaces (depth, outfile);
465 fprintf_filtered (outfile, "block #%03d, object at ", i);
466 gdb_print_host_address (b, outfile);
467 if (BLOCK_SUPERBLOCK (b))
469 fprintf_filtered (outfile, " under ");
470 gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile);
472 /* drow/2002-07-10: We could save the total symbols count
473 even if we're using a hashtable, but nothing else but this message
475 fprintf_filtered (outfile, ", %d syms/buckets in ",
476 dict_size (BLOCK_DICT (b)));
477 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), outfile);
478 fprintf_filtered (outfile, "..");
479 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), outfile);
480 if (BLOCK_FUNCTION (b))
482 fprintf_filtered (outfile, ", function %s",
483 SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b)));
484 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
486 fprintf_filtered (outfile, ", %s",
487 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
490 fprintf_filtered (outfile, "\n");
491 /* Now print each symbol in this block (in no particular order, if
492 we're using a hashtable). */
493 ALL_BLOCK_SYMBOLS (b, iter, sym)
495 struct print_symbol_args s;
500 catch_errors (print_symbol, &s, "Error printing symbol:\n",
504 fprintf_filtered (outfile, "\n");
508 fprintf_filtered (outfile, "\nBlockvector same as previous symtab\n\n");
513 dump_symtab (struct objfile *objfile, struct symtab *symtab,
514 struct ui_file *outfile)
516 /* Set the current language to the language of the symtab we're dumping
517 because certain routines used during dump_symtab() use the current
518 language to print an image of the symbol. We'll restore it later.
519 But use only real languages, not placeholders. */
520 if (symtab->language != language_unknown
521 && symtab->language != language_auto)
523 enum language saved_lang;
525 saved_lang = set_language (symtab->language);
527 dump_symtab_1 (objfile, symtab, outfile);
529 set_language (saved_lang);
532 dump_symtab_1 (objfile, symtab, outfile);
536 maintenance_print_symbols (char *args, int from_tty)
539 struct ui_file *outfile;
540 struct cleanup *cleanups;
541 char *symname = NULL;
542 char *filename = DEV_TTY;
543 struct objfile *objfile;
551 Arguments missing: an output file name and an optional symbol file name"));
553 argv = gdb_buildargv (args);
554 cleanups = make_cleanup_freeargv (argv);
559 /* If a second arg is supplied, it is a source file name to match on */
566 filename = tilde_expand (filename);
567 make_cleanup (xfree, filename);
569 outfile = gdb_fopen (filename, FOPEN_WT);
571 perror_with_name (filename);
572 make_cleanup_ui_file_delete (outfile);
575 ALL_SYMTABS (objfile, s)
576 if (symname == NULL || strcmp (symname, s->filename) == 0)
577 dump_symtab (objfile, s, outfile);
579 do_cleanups (cleanups);
582 /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
583 far to indent. ARGS is really a struct print_symbol_args *, but is
584 declared as char * to get it past catch_errors. Returns 0 for error,
588 print_symbol (void *args)
590 struct gdbarch *gdbarch = ((struct print_symbol_args *) args)->gdbarch;
591 struct symbol *symbol = ((struct print_symbol_args *) args)->symbol;
592 int depth = ((struct print_symbol_args *) args)->depth;
593 struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile;
594 struct obj_section *section = SYMBOL_OBJ_SECTION (symbol);
596 print_spaces (depth, outfile);
597 if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN)
599 fprintf_filtered (outfile, "label %s at ", SYMBOL_PRINT_NAME (symbol));
600 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
603 fprintf_filtered (outfile, " section %s\n",
604 bfd_section_name (section->the_bfd_section->owner,
605 section->the_bfd_section));
607 fprintf_filtered (outfile, "\n");
610 if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN)
612 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
614 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
618 fprintf_filtered (outfile, "%s %s = ",
619 (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
621 : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
622 ? "struct" : "union")),
623 SYMBOL_LINKAGE_NAME (symbol));
624 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
626 fprintf_filtered (outfile, ";\n");
630 if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
631 fprintf_filtered (outfile, "typedef ");
632 if (SYMBOL_TYPE (symbol))
634 /* Print details of types, except for enums where it's clutter. */
635 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_PRINT_NAME (symbol),
637 TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
639 fprintf_filtered (outfile, "; ");
642 fprintf_filtered (outfile, "%s ", SYMBOL_PRINT_NAME (symbol));
644 switch (SYMBOL_CLASS (symbol))
647 fprintf_filtered (outfile, "const %ld (0x%lx)",
648 SYMBOL_VALUE (symbol),
649 SYMBOL_VALUE (symbol));
652 case LOC_CONST_BYTES:
655 struct type *type = check_typedef (SYMBOL_TYPE (symbol));
656 fprintf_filtered (outfile, "const %u hex bytes:",
658 for (i = 0; i < TYPE_LENGTH (type); i++)
659 fprintf_filtered (outfile, " %02x",
660 (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]);
665 fprintf_filtered (outfile, "static at ");
666 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
669 fprintf_filtered (outfile, " section %s",
670 bfd_section_name (section->the_bfd_section->owner,
671 section->the_bfd_section));
675 if (SYMBOL_IS_ARGUMENT (symbol))
676 fprintf_filtered (outfile, "parameter register %ld",
677 SYMBOL_VALUE (symbol));
679 fprintf_filtered (outfile, "register %ld", SYMBOL_VALUE (symbol));
683 fprintf_filtered (outfile, "arg at offset 0x%lx",
684 SYMBOL_VALUE (symbol));
688 fprintf_filtered (outfile, "reference arg at 0x%lx", SYMBOL_VALUE (symbol));
691 case LOC_REGPARM_ADDR:
692 fprintf_filtered (outfile, "address parameter register %ld", SYMBOL_VALUE (symbol));
696 fprintf_filtered (outfile, "local at offset 0x%lx",
697 SYMBOL_VALUE (symbol));
704 fprintf_filtered (outfile, "label at ");
705 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
708 fprintf_filtered (outfile, " section %s",
709 bfd_section_name (section->the_bfd_section->owner,
710 section->the_bfd_section));
714 fprintf_filtered (outfile, "block object ");
715 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
716 fprintf_filtered (outfile, ", ");
717 fputs_filtered (paddress (gdbarch,
718 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol))),
720 fprintf_filtered (outfile, "..");
721 fputs_filtered (paddress (gdbarch,
722 BLOCK_END (SYMBOL_BLOCK_VALUE (symbol))),
725 fprintf_filtered (outfile, " section %s",
726 bfd_section_name (section->the_bfd_section->owner,
727 section->the_bfd_section));
731 fprintf_filtered (outfile, "computed at runtime");
735 fprintf_filtered (outfile, "unresolved");
738 case LOC_OPTIMIZED_OUT:
739 fprintf_filtered (outfile, "optimized out");
743 fprintf_filtered (outfile, "botched symbol class %x",
744 SYMBOL_CLASS (symbol));
748 fprintf_filtered (outfile, "\n");
753 maintenance_print_psymbols (char *args, int from_tty)
756 struct ui_file *outfile;
757 struct cleanup *cleanups;
758 char *symname = NULL;
759 char *filename = DEV_TTY;
760 struct objfile *objfile;
761 struct partial_symtab *ps;
767 error (_("print-psymbols takes an output file name and optional symbol file name"));
769 argv = gdb_buildargv (args);
770 cleanups = make_cleanup_freeargv (argv);
775 /* If a second arg is supplied, it is a source file name to match on */
782 filename = tilde_expand (filename);
783 make_cleanup (xfree, filename);
785 outfile = gdb_fopen (filename, FOPEN_WT);
787 perror_with_name (filename);
788 make_cleanup_ui_file_delete (outfile);
791 ALL_PSYMTABS (objfile, ps)
792 if (symname == NULL || strcmp (symname, ps->filename) == 0)
793 dump_psymtab (objfile, ps, outfile);
795 do_cleanups (cleanups);
799 print_partial_symbols (struct gdbarch *gdbarch,
800 struct partial_symbol **p, int count, char *what,
801 struct ui_file *outfile)
803 fprintf_filtered (outfile, " %s partial symbols:\n", what);
806 fprintf_filtered (outfile, " `%s'", SYMBOL_LINKAGE_NAME (*p));
807 if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
809 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
811 fputs_filtered (", ", outfile);
812 switch (SYMBOL_DOMAIN (*p))
815 fputs_filtered ("undefined domain, ", outfile);
818 /* This is the usual thing -- don't print it */
821 fputs_filtered ("struct domain, ", outfile);
824 fputs_filtered ("label domain, ", outfile);
827 fputs_filtered ("<invalid domain>, ", outfile);
830 switch (SYMBOL_CLASS (*p))
833 fputs_filtered ("undefined", outfile);
836 fputs_filtered ("constant int", outfile);
839 fputs_filtered ("static", outfile);
842 fputs_filtered ("register", outfile);
845 fputs_filtered ("pass by value", outfile);
848 fputs_filtered ("pass by reference", outfile);
850 case LOC_REGPARM_ADDR:
851 fputs_filtered ("register address parameter", outfile);
854 fputs_filtered ("stack parameter", outfile);
857 fputs_filtered ("type", outfile);
860 fputs_filtered ("label", outfile);
863 fputs_filtered ("function", outfile);
865 case LOC_CONST_BYTES:
866 fputs_filtered ("constant bytes", outfile);
869 fputs_filtered ("unresolved", outfile);
871 case LOC_OPTIMIZED_OUT:
872 fputs_filtered ("optimized out", outfile);
875 fputs_filtered ("computed at runtime", outfile);
878 fputs_filtered ("<invalid location>", outfile);
881 fputs_filtered (", ", outfile);
882 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (*p)), outfile);
883 fprintf_filtered (outfile, "\n");
889 maintenance_print_msymbols (char *args, int from_tty)
892 struct ui_file *outfile;
893 struct cleanup *cleanups;
894 char *filename = DEV_TTY;
895 char *symname = NULL;
896 struct program_space *pspace;
897 struct objfile *objfile;
899 struct stat sym_st, obj_st;
905 error (_("print-msymbols takes an output file name and optional symbol file name"));
907 argv = gdb_buildargv (args);
908 cleanups = make_cleanup_freeargv (argv);
913 /* If a second arg is supplied, it is a source file name to match on */
916 symname = xfullpath (argv[1]);
917 make_cleanup (xfree, symname);
918 if (symname && stat (symname, &sym_st))
919 perror_with_name (symname);
923 filename = tilde_expand (filename);
924 make_cleanup (xfree, filename);
926 outfile = gdb_fopen (filename, FOPEN_WT);
928 perror_with_name (filename);
929 make_cleanup_ui_file_delete (outfile);
933 ALL_PSPACE_OBJFILES (pspace, objfile)
935 || (!stat (objfile->name, &obj_st) && sym_st.st_ino == obj_st.st_ino))
936 dump_msymbols (objfile, outfile);
938 fprintf_filtered (outfile, "\n\n");
939 do_cleanups (cleanups);
943 maintenance_print_objfiles (char *ignore, int from_tty)
945 struct program_space *pspace;
946 struct objfile *objfile;
952 ALL_PSPACE_OBJFILES (pspace, objfile)
953 dump_objfile (objfile);
958 /* List all the symbol tables whose names match REGEXP (optional). */
960 maintenance_info_symtabs (char *regexp, int from_tty)
962 struct program_space *pspace;
963 struct objfile *objfile;
969 ALL_PSPACE_OBJFILES (pspace, objfile)
971 struct symtab *symtab;
973 /* We don't want to print anything for this objfile until we
974 actually find a symtab whose name matches. */
975 int printed_objfile_start = 0;
977 ALL_OBJFILE_SYMTABS (objfile, symtab)
982 || re_exec (symtab->filename))
984 if (! printed_objfile_start)
986 printf_filtered ("{ objfile %s ", objfile->name);
988 printf_filtered ("((struct objfile *) %s)\n",
989 host_address_to_string (objfile));
990 printed_objfile_start = 1;
993 printf_filtered (" { symtab %s ", symtab->filename);
995 printf_filtered ("((struct symtab *) %s)\n",
996 host_address_to_string (symtab));
997 printf_filtered (" dirname %s\n",
998 symtab->dirname ? symtab->dirname : "(null)");
999 printf_filtered (" fullname %s\n",
1000 symtab->fullname ? symtab->fullname : "(null)");
1001 printf_filtered (" blockvector ((struct blockvector *) %s)%s\n",
1002 host_address_to_string (symtab->blockvector),
1003 symtab->primary ? " (primary)" : "");
1004 printf_filtered (" linetable ((struct linetable *) %s)\n",
1005 host_address_to_string (symtab->linetable));
1006 printf_filtered (" debugformat %s\n", symtab->debugformat);
1007 printf_filtered (" }\n");
1011 if (printed_objfile_start)
1012 printf_filtered ("}\n");
1017 /* List all the partial symbol tables whose names match REGEXP (optional). */
1019 maintenance_info_psymtabs (char *regexp, int from_tty)
1021 struct program_space *pspace;
1022 struct objfile *objfile;
1027 ALL_PSPACES (pspace)
1028 ALL_PSPACE_OBJFILES (pspace, objfile)
1030 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1031 struct partial_symtab *psymtab;
1033 /* We don't want to print anything for this objfile until we
1034 actually find a symtab whose name matches. */
1035 int printed_objfile_start = 0;
1037 ALL_OBJFILE_PSYMTABS (objfile, psymtab)
1042 || re_exec (psymtab->filename))
1044 if (! printed_objfile_start)
1046 printf_filtered ("{ objfile %s ", objfile->name);
1048 printf_filtered ("((struct objfile *) %s)\n",
1049 host_address_to_string (objfile));
1050 printed_objfile_start = 1;
1053 printf_filtered (" { psymtab %s ", psymtab->filename);
1055 printf_filtered ("((struct partial_symtab *) %s)\n",
1056 host_address_to_string (psymtab));
1058 printf_filtered (" readin %s\n",
1059 psymtab->readin ? "yes" : "no");
1060 printf_filtered (" fullname %s\n",
1061 psymtab->fullname ? psymtab->fullname : "(null)");
1062 printf_filtered (" text addresses ");
1063 fputs_filtered (paddress (gdbarch, psymtab->textlow),
1065 printf_filtered (" -- ");
1066 fputs_filtered (paddress (gdbarch, psymtab->texthigh),
1068 printf_filtered ("\n");
1069 printf_filtered (" globals ");
1070 if (psymtab->n_global_syms)
1072 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1073 host_address_to_string (psymtab->objfile->global_psymbols.list
1074 + psymtab->globals_offset),
1075 psymtab->n_global_syms);
1078 printf_filtered ("(none)\n");
1079 printf_filtered (" statics ");
1080 if (psymtab->n_static_syms)
1082 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1083 host_address_to_string (psymtab->objfile->static_psymbols.list
1084 + psymtab->statics_offset),
1085 psymtab->n_static_syms);
1088 printf_filtered ("(none)\n");
1089 printf_filtered (" dependencies ");
1090 if (psymtab->number_of_dependencies)
1094 printf_filtered ("{\n");
1095 for (i = 0; i < psymtab->number_of_dependencies; i++)
1097 struct partial_symtab *dep = psymtab->dependencies[i];
1099 /* Note the string concatenation there --- no comma. */
1100 printf_filtered (" psymtab %s "
1101 "((struct partial_symtab *) %s)\n",
1103 host_address_to_string (dep));
1105 printf_filtered (" }\n");
1108 printf_filtered ("(none)\n");
1109 printf_filtered (" }\n");
1113 if (printed_objfile_start)
1114 printf_filtered ("}\n");
1119 /* Check consistency of psymtabs and symtabs. */
1122 maintenance_check_symtabs (char *ignore, int from_tty)
1125 struct partial_symbol **psym;
1126 struct symtab *s = NULL;
1127 struct partial_symtab *ps;
1128 struct blockvector *bv;
1129 struct objfile *objfile;
1133 ALL_PSYMTABS (objfile, ps)
1135 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1136 s = PSYMTAB_TO_SYMTAB (ps);
1139 bv = BLOCKVECTOR (s);
1140 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1141 psym = ps->objfile->static_psymbols.list + ps->statics_offset;
1142 length = ps->n_static_syms;
1145 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1146 SYMBOL_DOMAIN (*psym));
1149 printf_filtered ("Static symbol `");
1150 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1151 printf_filtered ("' only found in ");
1152 puts_filtered (ps->filename);
1153 printf_filtered (" psymtab\n");
1157 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1158 psym = ps->objfile->global_psymbols.list + ps->globals_offset;
1159 length = ps->n_global_syms;
1162 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1163 SYMBOL_DOMAIN (*psym));
1166 printf_filtered ("Global symbol `");
1167 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1168 printf_filtered ("' only found in ");
1169 puts_filtered (ps->filename);
1170 printf_filtered (" psymtab\n");
1174 if (ps->texthigh < ps->textlow)
1176 printf_filtered ("Psymtab ");
1177 puts_filtered (ps->filename);
1178 printf_filtered (" covers bad range ");
1179 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
1180 printf_filtered (" - ");
1181 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
1182 printf_filtered ("\n");
1185 if (ps->texthigh == 0)
1187 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
1189 printf_filtered ("Psymtab ");
1190 puts_filtered (ps->filename);
1191 printf_filtered (" covers ");
1192 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
1193 printf_filtered (" - ");
1194 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
1195 printf_filtered (" but symtab covers only ");
1196 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
1197 printf_filtered (" - ");
1198 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout);
1199 printf_filtered ("\n");
1205 /* Return the nexting depth of a block within other blocks in its symtab. */
1208 block_depth (struct block *block)
1211 while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
1219 /* Increase the space allocated for LISTP, which is probably
1220 global_psymbols or static_psymbols. This space will eventually
1221 be freed in free_objfile(). */
1224 extend_psymbol_list (struct psymbol_allocation_list *listp,
1225 struct objfile *objfile)
1228 if (listp->size == 0)
1231 listp->list = (struct partial_symbol **)
1232 xmalloc (new_size * sizeof (struct partial_symbol *));
1236 new_size = listp->size * 2;
1237 listp->list = (struct partial_symbol **)
1238 xrealloc ((char *) listp->list,
1239 new_size * sizeof (struct partial_symbol *));
1241 /* Next assumes we only went one over. Should be good if
1242 program works correctly */
1243 listp->next = listp->list + listp->size;
1244 listp->size = new_size;
1248 /* Do early runtime initializations. */
1250 _initialize_symmisc (void)