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
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 partial_symbol **, int,
71 char *, struct ui_file *);
73 void _initialize_symmisc (void);
75 struct print_symbol_args
77 struct symbol *symbol;
79 struct ui_file *outfile;
82 static int print_symbol (void *);
84 /* Free all the storage associated with the struct symtab <- S.
85 Note that some symtabs have contents that all live inside one big block of
86 memory, and some share the contents of another symbol table and so you
87 should not free the contents on their behalf (except sometimes the
88 linetable, which maybe per symtab even when the rest is not).
89 It is s->free_code that says which alternative to use. */
92 free_symtab (struct symtab *s)
95 struct blockvector *bv;
100 /* All the contents are part of a big block of memory (an obstack),
101 and some other symtab is in charge of freeing that block.
102 Therefore, do nothing. */
106 /* Everything will be freed either by our `free_func'
107 or by some other symtab, except for our linetable.
110 xfree (LINETABLE (s));
114 /* If there is a single block of memory to free, free it. */
115 if (s->free_func != NULL)
118 /* Free source-related stuff */
119 if (s->line_charpos != NULL)
120 xfree (s->line_charpos);
121 if (s->fullname != NULL)
123 if (s->debugformat != NULL)
124 xfree (s->debugformat);
129 print_symbol_bcache_statistics (void)
131 struct objfile *objfile;
134 ALL_OBJFILES (objfile)
136 printf_filtered (_("Byte cache statistics for '%s':\n"), objfile->name);
137 print_bcache_statistics (objfile->psymbol_cache, "partial symbol cache");
138 print_bcache_statistics (objfile->macro_cache, "preprocessor macro cache");
144 print_objfile_statistics (void)
146 struct objfile *objfile;
148 struct partial_symtab *ps;
149 int i, linetables, blockvectors;
152 ALL_OBJFILES (objfile)
154 printf_filtered (_("Statistics for '%s':\n"), objfile->name);
155 if (OBJSTAT (objfile, n_stabs) > 0)
156 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
157 OBJSTAT (objfile, n_stabs));
158 if (OBJSTAT (objfile, n_minsyms) > 0)
159 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
160 OBJSTAT (objfile, n_minsyms));
161 if (OBJSTAT (objfile, n_psyms) > 0)
162 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
163 OBJSTAT (objfile, n_psyms));
164 if (OBJSTAT (objfile, n_syms) > 0)
165 printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
166 OBJSTAT (objfile, n_syms));
167 if (OBJSTAT (objfile, n_types) > 0)
168 printf_filtered (_(" Number of \"types\" defined: %d\n"),
169 OBJSTAT (objfile, n_types));
171 ALL_OBJFILE_PSYMTABS (objfile, ps)
176 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i);
177 i = linetables = blockvectors = 0;
178 ALL_OBJFILE_SYMTABS (objfile, s)
181 if (s->linetable != NULL)
186 printf_filtered (_(" Number of symbol tables: %d\n"), i);
187 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
189 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
192 if (OBJSTAT (objfile, sz_strtab) > 0)
193 printf_filtered (_(" Space used by a.out string tables: %d\n"),
194 OBJSTAT (objfile, sz_strtab));
195 printf_filtered (_(" Total memory used for objfile obstack: %d\n"),
196 obstack_memory_used (&objfile->objfile_obstack));
197 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
198 bcache_memory_used (objfile->psymbol_cache));
199 printf_filtered (_(" Total memory used for macro cache: %d\n"),
200 bcache_memory_used (objfile->macro_cache));
206 dump_objfile (struct objfile *objfile)
208 struct symtab *symtab;
209 struct partial_symtab *psymtab;
211 printf_filtered ("\nObject file %s: ", objfile->name);
212 printf_filtered ("Objfile at ");
213 gdb_print_host_address (objfile, gdb_stdout);
214 printf_filtered (", bfd at ");
215 gdb_print_host_address (objfile->obfd, gdb_stdout);
216 printf_filtered (", %d minsyms\n\n",
217 objfile->minimal_symbol_count);
219 if (objfile->psymtabs)
221 printf_filtered ("Psymtabs:\n");
222 for (psymtab = objfile->psymtabs;
224 psymtab = psymtab->next)
226 printf_filtered ("%s at ",
228 gdb_print_host_address (psymtab, gdb_stdout);
229 printf_filtered (", ");
230 if (psymtab->objfile != objfile)
232 printf_filtered ("NOT ON CHAIN! ");
236 printf_filtered ("\n\n");
239 if (objfile->symtabs)
241 printf_filtered ("Symtabs:\n");
242 for (symtab = objfile->symtabs;
244 symtab = symtab->next)
246 printf_filtered ("%s at ", symtab->filename);
247 gdb_print_host_address (symtab, gdb_stdout);
248 printf_filtered (", ");
249 if (symtab->objfile != objfile)
251 printf_filtered ("NOT ON CHAIN! ");
255 printf_filtered ("\n\n");
259 /* Print minimal symbols from this objfile. */
262 dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
264 struct minimal_symbol *msymbol;
268 fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile->name);
269 if (objfile->minimal_symbol_count == 0)
271 fprintf_filtered (outfile, "No minimal symbols found.\n");
275 ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
277 struct obj_section *section = SYMBOL_OBJ_SECTION (msymbol);
279 switch (MSYMBOL_TYPE (msymbol))
287 case mst_solib_trampoline:
312 fprintf_filtered (outfile, "[%2d] %c ", index, ms_type);
313 fputs_filtered (paddress (SYMBOL_VALUE_ADDRESS (msymbol)), outfile);
314 fprintf_filtered (outfile, " %s", SYMBOL_LINKAGE_NAME (msymbol));
316 fprintf_filtered (outfile, " section %s",
317 bfd_section_name (objfile->obfd,
318 section->the_bfd_section));
319 if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
321 fprintf_filtered (outfile, " %s", SYMBOL_DEMANGLED_NAME (msymbol));
323 if (msymbol->filename)
324 fprintf_filtered (outfile, " %s", msymbol->filename);
325 fputs_filtered ("\n", outfile);
328 if (objfile->minimal_symbol_count != index)
330 warning (_("internal error: minimal symbol count %d != %d"),
331 objfile->minimal_symbol_count, index);
333 fprintf_filtered (outfile, "\n");
337 dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
338 struct ui_file *outfile)
342 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
344 fprintf_filtered (outfile, "(object ");
345 gdb_print_host_address (psymtab, outfile);
346 fprintf_filtered (outfile, ")\n\n");
347 fprintf_unfiltered (outfile, " Read from object file %s (",
349 gdb_print_host_address (objfile, outfile);
350 fprintf_unfiltered (outfile, ")\n");
354 fprintf_filtered (outfile,
355 " Full symtab was read (at ");
356 gdb_print_host_address (psymtab->symtab, outfile);
357 fprintf_filtered (outfile, " by function at ");
358 gdb_print_host_address (psymtab->read_symtab, outfile);
359 fprintf_filtered (outfile, ")\n");
362 fprintf_filtered (outfile, " Relocate symbols by ");
363 for (i = 0; i < psymtab->objfile->num_sections; ++i)
366 fprintf_filtered (outfile, ", ");
368 fputs_filtered (paddress (ANOFFSET (psymtab->section_offsets, i)),
371 fprintf_filtered (outfile, "\n");
373 fprintf_filtered (outfile, " Symbols cover text addresses ");
374 fputs_filtered (paddress (psymtab->textlow), outfile);
375 fprintf_filtered (outfile, "-");
376 fputs_filtered (paddress (psymtab->texthigh), outfile);
377 fprintf_filtered (outfile, "\n");
378 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
379 psymtab->number_of_dependencies);
380 for (i = 0; i < psymtab->number_of_dependencies; i++)
382 fprintf_filtered (outfile, " %d ", i);
383 gdb_print_host_address (psymtab->dependencies[i], outfile);
384 fprintf_filtered (outfile, " %s\n",
385 psymtab->dependencies[i]->filename);
387 if (psymtab->n_global_syms > 0)
389 print_partial_symbols (objfile->global_psymbols.list
390 + psymtab->globals_offset,
391 psymtab->n_global_syms, "Global", outfile);
393 if (psymtab->n_static_syms > 0)
395 print_partial_symbols (objfile->static_psymbols.list
396 + psymtab->statics_offset,
397 psymtab->n_static_syms, "Static", outfile);
399 fprintf_filtered (outfile, "\n");
403 dump_symtab_1 (struct objfile *objfile, struct symtab *symtab,
404 struct ui_file *outfile)
407 struct dict_iterator iter;
410 struct blockvector *bv;
415 fprintf_filtered (outfile, "\nSymtab for file %s\n", symtab->filename);
417 fprintf_filtered (outfile, "Compilation directory is %s\n",
419 fprintf_filtered (outfile, "Read from object file %s (", objfile->name);
420 gdb_print_host_address (objfile, outfile);
421 fprintf_filtered (outfile, ")\n");
422 fprintf_filtered (outfile, "Language: %s\n", language_str (symtab->language));
424 /* First print the line table. */
425 l = LINETABLE (symtab);
428 fprintf_filtered (outfile, "\nLine table:\n\n");
430 for (i = 0; i < len; i++)
432 fprintf_filtered (outfile, " line %d at ", l->item[i].line);
433 fputs_filtered (paddress (l->item[i].pc), outfile);
434 fprintf_filtered (outfile, "\n");
437 /* Now print the block info, but only for primary symtabs since we will
438 print lots of duplicate info otherwise. */
441 fprintf_filtered (outfile, "\nBlockvector:\n\n");
442 bv = BLOCKVECTOR (symtab);
443 len = BLOCKVECTOR_NBLOCKS (bv);
444 for (i = 0; i < len; i++)
446 b = BLOCKVECTOR_BLOCK (bv, i);
447 depth = block_depth (b) * 2;
448 print_spaces (depth, outfile);
449 fprintf_filtered (outfile, "block #%03d, object at ", i);
450 gdb_print_host_address (b, outfile);
451 if (BLOCK_SUPERBLOCK (b))
453 fprintf_filtered (outfile, " under ");
454 gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile);
456 /* drow/2002-07-10: We could save the total symbols count
457 even if we're using a hashtable, but nothing else but this message
459 fprintf_filtered (outfile, ", %d syms/buckets in ",
460 dict_size (BLOCK_DICT (b)));
461 fputs_filtered (paddress (BLOCK_START (b)), outfile);
462 fprintf_filtered (outfile, "..");
463 fputs_filtered (paddress (BLOCK_END (b)), outfile);
464 if (BLOCK_FUNCTION (b))
466 fprintf_filtered (outfile, ", function %s",
467 SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b)));
468 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
470 fprintf_filtered (outfile, ", %s",
471 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
474 fprintf_filtered (outfile, "\n");
475 /* Now print each symbol in this block (in no particular order, if
476 we're using a hashtable). */
477 ALL_BLOCK_SYMBOLS (b, iter, sym)
479 struct print_symbol_args s;
483 catch_errors (print_symbol, &s, "Error printing symbol:\n",
487 fprintf_filtered (outfile, "\n");
491 fprintf_filtered (outfile, "\nBlockvector same as previous symtab\n\n");
496 dump_symtab (struct objfile *objfile, struct symtab *symtab,
497 struct ui_file *outfile)
499 /* Set the current language to the language of the symtab we're dumping
500 because certain routines used during dump_symtab() use the current
501 language to print an image of the symbol. We'll restore it later.
502 But use only real languages, not placeholders. */
503 if (symtab->language != language_unknown
504 && symtab->language != language_auto)
506 enum language saved_lang;
508 saved_lang = set_language (symtab->language);
510 dump_symtab_1 (objfile, symtab, outfile);
512 set_language (saved_lang);
515 dump_symtab_1 (objfile, symtab, outfile);
519 maintenance_print_symbols (char *args, int from_tty)
522 struct ui_file *outfile;
523 struct cleanup *cleanups;
524 char *symname = NULL;
525 char *filename = DEV_TTY;
526 struct objfile *objfile;
534 Arguments missing: an output file name and an optional symbol file name"));
536 argv = gdb_buildargv (args);
537 cleanups = make_cleanup_freeargv (argv);
542 /* If a second arg is supplied, it is a source file name to match on */
549 filename = tilde_expand (filename);
550 make_cleanup (xfree, filename);
552 outfile = gdb_fopen (filename, FOPEN_WT);
554 perror_with_name (filename);
555 make_cleanup_ui_file_delete (outfile);
558 ALL_SYMTABS (objfile, s)
559 if (symname == NULL || strcmp (symname, s->filename) == 0)
560 dump_symtab (objfile, s, outfile);
562 do_cleanups (cleanups);
565 /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
566 far to indent. ARGS is really a struct print_symbol_args *, but is
567 declared as char * to get it past catch_errors. Returns 0 for error,
571 print_symbol (void *args)
573 struct symbol *symbol = ((struct print_symbol_args *) args)->symbol;
574 int depth = ((struct print_symbol_args *) args)->depth;
575 struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile;
576 struct obj_section *section = SYMBOL_OBJ_SECTION (symbol);
578 print_spaces (depth, outfile);
579 if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN)
581 fprintf_filtered (outfile, "label %s at ", SYMBOL_PRINT_NAME (symbol));
582 fputs_filtered (paddress (SYMBOL_VALUE_ADDRESS (symbol)), outfile);
584 fprintf_filtered (outfile, " section %s\n",
585 bfd_section_name (section->the_bfd_section->owner,
586 section->the_bfd_section));
588 fprintf_filtered (outfile, "\n");
591 if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN)
593 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
595 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
599 fprintf_filtered (outfile, "%s %s = ",
600 (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
602 : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
603 ? "struct" : "union")),
604 SYMBOL_LINKAGE_NAME (symbol));
605 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
607 fprintf_filtered (outfile, ";\n");
611 if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
612 fprintf_filtered (outfile, "typedef ");
613 if (SYMBOL_TYPE (symbol))
615 /* Print details of types, except for enums where it's clutter. */
616 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_PRINT_NAME (symbol),
618 TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
620 fprintf_filtered (outfile, "; ");
623 fprintf_filtered (outfile, "%s ", SYMBOL_PRINT_NAME (symbol));
625 switch (SYMBOL_CLASS (symbol))
628 fprintf_filtered (outfile, "const %ld (0x%lx)",
629 SYMBOL_VALUE (symbol),
630 SYMBOL_VALUE (symbol));
633 case LOC_CONST_BYTES:
636 struct type *type = check_typedef (SYMBOL_TYPE (symbol));
637 fprintf_filtered (outfile, "const %u hex bytes:",
639 for (i = 0; i < TYPE_LENGTH (type); i++)
640 fprintf_filtered (outfile, " %02x",
641 (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]);
646 fprintf_filtered (outfile, "static at ");
647 fputs_filtered (paddress (SYMBOL_VALUE_ADDRESS (symbol)), outfile);
649 fprintf_filtered (outfile, " section %s",
650 bfd_section_name (section->the_bfd_section->owner,
651 section->the_bfd_section));
655 if (SYMBOL_IS_ARGUMENT (symbol))
656 fprintf_filtered (outfile, "parameter register %ld",
657 SYMBOL_VALUE (symbol));
659 fprintf_filtered (outfile, "register %ld", SYMBOL_VALUE (symbol));
663 fprintf_filtered (outfile, "arg at offset 0x%lx",
664 SYMBOL_VALUE (symbol));
668 fprintf_filtered (outfile, "reference arg at 0x%lx", SYMBOL_VALUE (symbol));
671 case LOC_REGPARM_ADDR:
672 fprintf_filtered (outfile, "address parameter register %ld", SYMBOL_VALUE (symbol));
676 fprintf_filtered (outfile, "local at offset 0x%lx",
677 SYMBOL_VALUE (symbol));
684 fprintf_filtered (outfile, "label at ");
685 fputs_filtered (paddress (SYMBOL_VALUE_ADDRESS (symbol)), outfile);
687 fprintf_filtered (outfile, " section %s",
688 bfd_section_name (section->the_bfd_section->owner,
689 section->the_bfd_section));
693 fprintf_filtered (outfile, "block object ");
694 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
695 fprintf_filtered (outfile, ", ");
696 fputs_filtered (paddress (BLOCK_START (SYMBOL_BLOCK_VALUE (symbol))),
698 fprintf_filtered (outfile, "..");
699 fputs_filtered (paddress (BLOCK_END (SYMBOL_BLOCK_VALUE (symbol))),
702 fprintf_filtered (outfile, " section %s",
703 bfd_section_name (section->the_bfd_section->owner,
704 section->the_bfd_section));
708 fprintf_filtered (outfile, "computed at runtime");
712 fprintf_filtered (outfile, "unresolved");
715 case LOC_OPTIMIZED_OUT:
716 fprintf_filtered (outfile, "optimized out");
720 fprintf_filtered (outfile, "botched symbol class %x",
721 SYMBOL_CLASS (symbol));
725 fprintf_filtered (outfile, "\n");
730 maintenance_print_psymbols (char *args, int from_tty)
733 struct ui_file *outfile;
734 struct cleanup *cleanups;
735 char *symname = NULL;
736 char *filename = DEV_TTY;
737 struct objfile *objfile;
738 struct partial_symtab *ps;
744 error (_("print-psymbols takes an output file name and optional symbol file name"));
746 argv = gdb_buildargv (args);
747 cleanups = make_cleanup_freeargv (argv);
752 /* If a second arg is supplied, it is a source file name to match on */
759 filename = tilde_expand (filename);
760 make_cleanup (xfree, filename);
762 outfile = gdb_fopen (filename, FOPEN_WT);
764 perror_with_name (filename);
765 make_cleanup_ui_file_delete (outfile);
768 ALL_PSYMTABS (objfile, ps)
769 if (symname == NULL || strcmp (symname, ps->filename) == 0)
770 dump_psymtab (objfile, ps, outfile);
772 do_cleanups (cleanups);
776 print_partial_symbols (struct partial_symbol **p, int count, char *what,
777 struct ui_file *outfile)
779 fprintf_filtered (outfile, " %s partial symbols:\n", what);
782 fprintf_filtered (outfile, " `%s'", SYMBOL_LINKAGE_NAME (*p));
783 if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
785 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
787 fputs_filtered (", ", outfile);
788 switch (SYMBOL_DOMAIN (*p))
791 fputs_filtered ("undefined domain, ", outfile);
794 /* This is the usual thing -- don't print it */
797 fputs_filtered ("struct domain, ", outfile);
800 fputs_filtered ("label domain, ", outfile);
803 fputs_filtered ("<invalid domain>, ", outfile);
806 switch (SYMBOL_CLASS (*p))
809 fputs_filtered ("undefined", outfile);
812 fputs_filtered ("constant int", outfile);
815 fputs_filtered ("static", outfile);
818 fputs_filtered ("register", outfile);
821 fputs_filtered ("pass by value", outfile);
824 fputs_filtered ("pass by reference", outfile);
826 case LOC_REGPARM_ADDR:
827 fputs_filtered ("register address parameter", outfile);
830 fputs_filtered ("stack parameter", outfile);
833 fputs_filtered ("type", outfile);
836 fputs_filtered ("label", outfile);
839 fputs_filtered ("function", outfile);
841 case LOC_CONST_BYTES:
842 fputs_filtered ("constant bytes", outfile);
845 fputs_filtered ("unresolved", outfile);
847 case LOC_OPTIMIZED_OUT:
848 fputs_filtered ("optimized out", outfile);
851 fputs_filtered ("computed at runtime", outfile);
854 fputs_filtered ("<invalid location>", outfile);
857 fputs_filtered (", ", outfile);
858 fputs_filtered (paddress (SYMBOL_VALUE_ADDRESS (*p)), outfile);
859 fprintf_filtered (outfile, "\n");
865 maintenance_print_msymbols (char *args, int from_tty)
868 struct ui_file *outfile;
869 struct cleanup *cleanups;
870 char *filename = DEV_TTY;
871 char *symname = NULL;
872 struct objfile *objfile;
874 struct stat sym_st, obj_st;
880 error (_("print-msymbols takes an output file name and optional symbol file name"));
882 argv = gdb_buildargv (args);
883 cleanups = make_cleanup_freeargv (argv);
888 /* If a second arg is supplied, it is a source file name to match on */
891 symname = xfullpath (argv[1]);
892 make_cleanup (xfree, symname);
893 if (symname && stat (symname, &sym_st))
894 perror_with_name (symname);
898 filename = tilde_expand (filename);
899 make_cleanup (xfree, filename);
901 outfile = gdb_fopen (filename, FOPEN_WT);
903 perror_with_name (filename);
904 make_cleanup_ui_file_delete (outfile);
907 ALL_OBJFILES (objfile)
909 || (!stat (objfile->name, &obj_st) && sym_st.st_ino == obj_st.st_ino))
910 dump_msymbols (objfile, outfile);
912 fprintf_filtered (outfile, "\n\n");
913 do_cleanups (cleanups);
917 maintenance_print_objfiles (char *ignore, int from_tty)
919 struct objfile *objfile;
924 ALL_OBJFILES (objfile)
925 dump_objfile (objfile);
930 /* List all the symbol tables whose names match REGEXP (optional). */
932 maintenance_info_symtabs (char *regexp, int from_tty)
934 struct objfile *objfile;
939 ALL_OBJFILES (objfile)
941 struct symtab *symtab;
943 /* We don't want to print anything for this objfile until we
944 actually find a symtab whose name matches. */
945 int printed_objfile_start = 0;
947 ALL_OBJFILE_SYMTABS (objfile, symtab)
952 || re_exec (symtab->filename))
954 if (! printed_objfile_start)
956 printf_filtered ("{ objfile %s ", objfile->name);
958 printf_filtered ("((struct objfile *) %s)\n",
959 host_address_to_string (objfile));
960 printed_objfile_start = 1;
963 printf_filtered (" { symtab %s ", symtab->filename);
965 printf_filtered ("((struct symtab *) %s)\n",
966 host_address_to_string (symtab));
967 printf_filtered (" dirname %s\n",
968 symtab->dirname ? symtab->dirname : "(null)");
969 printf_filtered (" fullname %s\n",
970 symtab->fullname ? symtab->fullname : "(null)");
971 printf_filtered (" blockvector ((struct blockvector *) %s)%s\n",
972 host_address_to_string (symtab->blockvector),
973 symtab->primary ? " (primary)" : "");
974 printf_filtered (" linetable ((struct linetable *) %s)\n",
975 host_address_to_string (symtab->linetable));
976 printf_filtered (" debugformat %s\n", symtab->debugformat);
977 printf_filtered (" }\n");
981 if (printed_objfile_start)
982 printf_filtered ("}\n");
987 /* List all the partial symbol tables whose names match REGEXP (optional). */
989 maintenance_info_psymtabs (char *regexp, int from_tty)
991 struct objfile *objfile;
996 ALL_OBJFILES (objfile)
998 struct partial_symtab *psymtab;
1000 /* We don't want to print anything for this objfile until we
1001 actually find a symtab whose name matches. */
1002 int printed_objfile_start = 0;
1004 ALL_OBJFILE_PSYMTABS (objfile, psymtab)
1009 || re_exec (psymtab->filename))
1011 if (! printed_objfile_start)
1013 printf_filtered ("{ objfile %s ", objfile->name);
1015 printf_filtered ("((struct objfile *) %s)\n",
1016 host_address_to_string (objfile));
1017 printed_objfile_start = 1;
1020 printf_filtered (" { psymtab %s ", psymtab->filename);
1022 printf_filtered ("((struct partial_symtab *) %s)\n",
1023 host_address_to_string (psymtab));
1025 printf_filtered (" readin %s\n",
1026 psymtab->readin ? "yes" : "no");
1027 printf_filtered (" fullname %s\n",
1028 psymtab->fullname ? psymtab->fullname : "(null)");
1029 printf_filtered (" text addresses ");
1030 fputs_filtered (paddress (psymtab->textlow), gdb_stdout);
1031 printf_filtered (" -- ");
1032 fputs_filtered (paddress (psymtab->texthigh), gdb_stdout);
1033 printf_filtered ("\n");
1034 printf_filtered (" globals ");
1035 if (psymtab->n_global_syms)
1037 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1038 host_address_to_string (psymtab->objfile->global_psymbols.list
1039 + psymtab->globals_offset),
1040 psymtab->n_global_syms);
1043 printf_filtered ("(none)\n");
1044 printf_filtered (" statics ");
1045 if (psymtab->n_static_syms)
1047 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1048 host_address_to_string (psymtab->objfile->static_psymbols.list
1049 + psymtab->statics_offset),
1050 psymtab->n_static_syms);
1053 printf_filtered ("(none)\n");
1054 printf_filtered (" dependencies ");
1055 if (psymtab->number_of_dependencies)
1059 printf_filtered ("{\n");
1060 for (i = 0; i < psymtab->number_of_dependencies; i++)
1062 struct partial_symtab *dep = psymtab->dependencies[i];
1064 /* Note the string concatenation there --- no comma. */
1065 printf_filtered (" psymtab %s "
1066 "((struct partial_symtab *) %s)\n",
1068 host_address_to_string (dep));
1070 printf_filtered (" }\n");
1073 printf_filtered ("(none)\n");
1074 printf_filtered (" }\n");
1078 if (printed_objfile_start)
1079 printf_filtered ("}\n");
1084 /* Check consistency of psymtabs and symtabs. */
1087 maintenance_check_symtabs (char *ignore, int from_tty)
1090 struct partial_symbol **psym;
1091 struct symtab *s = NULL;
1092 struct partial_symtab *ps;
1093 struct blockvector *bv;
1094 struct objfile *objfile;
1098 ALL_PSYMTABS (objfile, ps)
1100 s = PSYMTAB_TO_SYMTAB (ps);
1103 bv = BLOCKVECTOR (s);
1104 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1105 psym = ps->objfile->static_psymbols.list + ps->statics_offset;
1106 length = ps->n_static_syms;
1109 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1110 NULL, SYMBOL_DOMAIN (*psym));
1113 printf_filtered ("Static symbol `");
1114 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1115 printf_filtered ("' only found in ");
1116 puts_filtered (ps->filename);
1117 printf_filtered (" psymtab\n");
1121 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1122 psym = ps->objfile->global_psymbols.list + ps->globals_offset;
1123 length = ps->n_global_syms;
1126 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1127 NULL, SYMBOL_DOMAIN (*psym));
1130 printf_filtered ("Global symbol `");
1131 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1132 printf_filtered ("' only found in ");
1133 puts_filtered (ps->filename);
1134 printf_filtered (" psymtab\n");
1138 if (ps->texthigh < ps->textlow)
1140 printf_filtered ("Psymtab ");
1141 puts_filtered (ps->filename);
1142 printf_filtered (" covers bad range ");
1143 fputs_filtered (paddress (ps->textlow), gdb_stdout);
1144 printf_filtered (" - ");
1145 fputs_filtered (paddress (ps->texthigh), gdb_stdout);
1146 printf_filtered ("\n");
1149 if (ps->texthigh == 0)
1151 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
1153 printf_filtered ("Psymtab ");
1154 puts_filtered (ps->filename);
1155 printf_filtered (" covers ");
1156 fputs_filtered (paddress (ps->textlow), gdb_stdout);
1157 printf_filtered (" - ");
1158 fputs_filtered (paddress (ps->texthigh), gdb_stdout);
1159 printf_filtered (" but symtab covers only ");
1160 fputs_filtered (paddress (BLOCK_START (b)), gdb_stdout);
1161 printf_filtered (" - ");
1162 fputs_filtered (paddress (BLOCK_END (b)), gdb_stdout);
1163 printf_filtered ("\n");
1169 /* Return the nexting depth of a block within other blocks in its symtab. */
1172 block_depth (struct block *block)
1175 while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
1183 /* Increase the space allocated for LISTP, which is probably
1184 global_psymbols or static_psymbols. This space will eventually
1185 be freed in free_objfile(). */
1188 extend_psymbol_list (struct psymbol_allocation_list *listp,
1189 struct objfile *objfile)
1192 if (listp->size == 0)
1195 listp->list = (struct partial_symbol **)
1196 xmalloc (new_size * sizeof (struct partial_symbol *));
1200 new_size = listp->size * 2;
1201 listp->list = (struct partial_symbol **)
1202 xrealloc ((char *) listp->list,
1203 new_size * sizeof (struct partial_symbol *));
1205 /* Next assumes we only went one over. Should be good if
1206 program works correctly */
1207 listp->next = listp->list + listp->size;
1208 listp->size = new_size;
1212 /* Do early runtime initializations. */
1214 _initialize_symmisc (void)