* mdebugread.c (psymtab_to_symtab_1): Copy linetable to obstack.
[external/binutils.git] / gdb / symmisc.c
1 /* Do various things to symbol tables (other than lookup), for GDB.
2
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    2011 Free Software Foundation, Inc.
6
7    This file is part of GDB.
8
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.
13
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.
18
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/>.  */
21
22 #include "defs.h"
23 #include "symtab.h"
24 #include "gdbtypes.h"
25 #include "bfd.h"
26 #include "filenames.h"
27 #include "symfile.h"
28 #include "objfiles.h"
29 #include "breakpoint.h"
30 #include "command.h"
31 #include "gdb_obstack.h"
32 #include "exceptions.h"
33 #include "language.h"
34 #include "bcache.h"
35 #include "block.h"
36 #include "gdb_regex.h"
37 #include "gdb_stat.h"
38 #include "dictionary.h"
39
40 #include "gdb_string.h"
41 #include "readline/readline.h"
42
43 #include "psymtab.h"
44
45 #ifndef DEV_TTY
46 #define DEV_TTY "/dev/tty"
47 #endif
48
49 /* Unfortunately for debugging, stderr is usually a macro.  This is painful
50    when calling functions that take FILE *'s from the debugger.
51    So we make a variable which has the same value and which is accessible when
52    debugging GDB with itself.  Because stdin et al need not be constants,
53    we initialize them in the _initialize_symmisc function at the bottom
54    of the file.  */
55 FILE *std_in;
56 FILE *std_out;
57 FILE *std_err;
58
59 /* Prototypes for local functions */
60
61 static void dump_symtab (struct objfile *, struct symtab *,
62                          struct ui_file *);
63
64 static void dump_msymbols (struct objfile *, struct ui_file *);
65
66 static void dump_objfile (struct objfile *);
67
68 static int block_depth (struct block *);
69
70 void _initialize_symmisc (void);
71
72 struct print_symbol_args
73   {
74     struct gdbarch *gdbarch;
75     struct symbol *symbol;
76     int depth;
77     struct ui_file *outfile;
78   };
79
80 static int print_symbol (void *);
81 \f
82 /* Free all the storage associated with the struct symtab <- S.  */
83
84 void
85 free_symtab (struct symtab *s)
86 {
87   /* Free source-related stuff.  */
88   if (s->line_charpos != NULL)
89     xfree (s->line_charpos);
90   if (s->fullname != NULL)
91     xfree (s->fullname);
92   xfree (s);
93 }
94
95 void
96 print_symbol_bcache_statistics (void)
97 {
98   struct program_space *pspace;
99   struct objfile *objfile;
100
101   immediate_quit++;
102   ALL_PSPACES (pspace)
103     ALL_PSPACE_OBJFILES (pspace, objfile)
104   {
105     printf_filtered (_("Byte cache statistics for '%s':\n"), objfile->name);
106     print_bcache_statistics (psymbol_bcache_get_bcache (objfile->psymbol_cache),
107                              "partial symbol cache");
108     print_bcache_statistics (objfile->macro_cache, "preprocessor macro cache");
109     print_bcache_statistics (objfile->filename_cache, "file name cache");
110   }
111   immediate_quit--;
112 }
113
114 void
115 print_objfile_statistics (void)
116 {
117   struct program_space *pspace;
118   struct objfile *objfile;
119   struct symtab *s;
120   int i, linetables, blockvectors;
121
122   immediate_quit++;
123   ALL_PSPACES (pspace)
124     ALL_PSPACE_OBJFILES (pspace, objfile)
125   {
126     printf_filtered (_("Statistics for '%s':\n"), objfile->name);
127     if (OBJSTAT (objfile, n_stabs) > 0)
128       printf_filtered (_("  Number of \"stab\" symbols read: %d\n"),
129                        OBJSTAT (objfile, n_stabs));
130     if (OBJSTAT (objfile, n_minsyms) > 0)
131       printf_filtered (_("  Number of \"minimal\" symbols read: %d\n"),
132                        OBJSTAT (objfile, n_minsyms));
133     if (OBJSTAT (objfile, n_psyms) > 0)
134       printf_filtered (_("  Number of \"partial\" symbols read: %d\n"),
135                        OBJSTAT (objfile, n_psyms));
136     if (OBJSTAT (objfile, n_syms) > 0)
137       printf_filtered (_("  Number of \"full\" symbols read: %d\n"),
138                        OBJSTAT (objfile, n_syms));
139     if (OBJSTAT (objfile, n_types) > 0)
140       printf_filtered (_("  Number of \"types\" defined: %d\n"),
141                        OBJSTAT (objfile, n_types));
142     if (objfile->sf)
143       objfile->sf->qf->print_stats (objfile);
144     i = linetables = blockvectors = 0;
145     ALL_OBJFILE_SYMTABS (objfile, s)
146       {
147         i++;
148         if (s->linetable != NULL)
149           linetables++;
150         if (s->primary == 1)
151           blockvectors++;
152       }
153     printf_filtered (_("  Number of symbol tables: %d\n"), i);
154     printf_filtered (_("  Number of symbol tables with line tables: %d\n"), 
155                      linetables);
156     printf_filtered (_("  Number of symbol tables with blockvectors: %d\n"), 
157                      blockvectors);
158     
159     if (OBJSTAT (objfile, sz_strtab) > 0)
160       printf_filtered (_("  Space used by a.out string tables: %d\n"),
161                        OBJSTAT (objfile, sz_strtab));
162     printf_filtered (_("  Total memory used for objfile obstack: %d\n"),
163                      obstack_memory_used (&objfile->objfile_obstack));
164     printf_filtered (_("  Total memory used for psymbol cache: %d\n"),
165                      bcache_memory_used (psymbol_bcache_get_bcache
166                                           (objfile->psymbol_cache)));
167     printf_filtered (_("  Total memory used for macro cache: %d\n"),
168                      bcache_memory_used (objfile->macro_cache));
169     printf_filtered (_("  Total memory used for file name cache: %d\n"),
170                      bcache_memory_used (objfile->filename_cache));
171   }
172   immediate_quit--;
173 }
174
175 static void
176 dump_objfile (struct objfile *objfile)
177 {
178   struct symtab *symtab;
179
180   printf_filtered ("\nObject file %s:  ", objfile->name);
181   printf_filtered ("Objfile at ");
182   gdb_print_host_address (objfile, gdb_stdout);
183   printf_filtered (", bfd at ");
184   gdb_print_host_address (objfile->obfd, gdb_stdout);
185   printf_filtered (", %d minsyms\n\n",
186                    objfile->minimal_symbol_count);
187
188   if (objfile->sf)
189     objfile->sf->qf->dump (objfile);
190
191   if (objfile->symtabs)
192     {
193       printf_filtered ("Symtabs:\n");
194       for (symtab = objfile->symtabs;
195            symtab != NULL;
196            symtab = symtab->next)
197         {
198           printf_filtered ("%s at ", symtab->filename);
199           gdb_print_host_address (symtab, gdb_stdout);
200           printf_filtered (", ");
201           if (symtab->objfile != objfile)
202             {
203               printf_filtered ("NOT ON CHAIN!  ");
204             }
205           wrap_here ("  ");
206         }
207       printf_filtered ("\n\n");
208     }
209 }
210
211 /* Print minimal symbols from this objfile.  */
212
213 static void
214 dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
215 {
216   struct gdbarch *gdbarch = get_objfile_arch (objfile);
217   struct minimal_symbol *msymbol;
218   int index;
219   char ms_type;
220
221   fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile->name);
222   if (objfile->minimal_symbol_count == 0)
223     {
224       fprintf_filtered (outfile, "No minimal symbols found.\n");
225       return;
226     }
227   index = 0;
228   ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
229     {
230       struct obj_section *section = SYMBOL_OBJ_SECTION (msymbol);
231
232       switch (MSYMBOL_TYPE (msymbol))
233         {
234         case mst_unknown:
235           ms_type = 'u';
236           break;
237         case mst_text:
238           ms_type = 'T';
239           break;
240         case mst_text_gnu_ifunc:
241           ms_type = 'i';
242           break;
243         case mst_solib_trampoline:
244           ms_type = 'S';
245           break;
246         case mst_data:
247           ms_type = 'D';
248           break;
249         case mst_bss:
250           ms_type = 'B';
251           break;
252         case mst_abs:
253           ms_type = 'A';
254           break;
255         case mst_file_text:
256           ms_type = 't';
257           break;
258         case mst_file_data:
259           ms_type = 'd';
260           break;
261         case mst_file_bss:
262           ms_type = 'b';
263           break;
264         default:
265           ms_type = '?';
266           break;
267         }
268       fprintf_filtered (outfile, "[%2d] %c ", index, ms_type);
269       fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (msymbol)),
270                       outfile);
271       fprintf_filtered (outfile, " %s", SYMBOL_LINKAGE_NAME (msymbol));
272       if (section)
273         fprintf_filtered (outfile, " section %s",
274                           bfd_section_name (objfile->obfd,
275                                             section->the_bfd_section));
276       if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
277         {
278           fprintf_filtered (outfile, "  %s", SYMBOL_DEMANGLED_NAME (msymbol));
279         }
280       if (msymbol->filename)
281         fprintf_filtered (outfile, "  %s", msymbol->filename);
282       fputs_filtered ("\n", outfile);
283       index++;
284     }
285   if (objfile->minimal_symbol_count != index)
286     {
287       warning (_("internal error:  minimal symbol count %d != %d"),
288                objfile->minimal_symbol_count, index);
289     }
290   fprintf_filtered (outfile, "\n");
291 }
292
293 static void
294 dump_symtab_1 (struct objfile *objfile, struct symtab *symtab,
295                struct ui_file *outfile)
296 {
297   struct gdbarch *gdbarch = get_objfile_arch (objfile);
298   int i;
299   struct dict_iterator iter;
300   int len;
301   struct linetable *l;
302   struct blockvector *bv;
303   struct symbol *sym;
304   struct block *b;
305   int depth;
306
307   fprintf_filtered (outfile, "\nSymtab for file %s\n", symtab->filename);
308   if (symtab->dirname)
309     fprintf_filtered (outfile, "Compilation directory is %s\n",
310                       symtab->dirname);
311   fprintf_filtered (outfile, "Read from object file %s (", objfile->name);
312   gdb_print_host_address (objfile, outfile);
313   fprintf_filtered (outfile, ")\n");
314   fprintf_filtered (outfile, "Language: %s\n",
315                     language_str (symtab->language));
316
317   /* First print the line table.  */
318   l = LINETABLE (symtab);
319   if (l)
320     {
321       fprintf_filtered (outfile, "\nLine table:\n\n");
322       len = l->nitems;
323       for (i = 0; i < len; i++)
324         {
325           fprintf_filtered (outfile, " line %d at ", l->item[i].line);
326           fputs_filtered (paddress (gdbarch, l->item[i].pc), outfile);
327           fprintf_filtered (outfile, "\n");
328         }
329     }
330   /* Now print the block info, but only for primary symtabs since we will
331      print lots of duplicate info otherwise.  */
332   if (symtab->primary)
333     {
334       fprintf_filtered (outfile, "\nBlockvector:\n\n");
335       bv = BLOCKVECTOR (symtab);
336       len = BLOCKVECTOR_NBLOCKS (bv);
337       for (i = 0; i < len; i++)
338         {
339           b = BLOCKVECTOR_BLOCK (bv, i);
340           depth = block_depth (b) * 2;
341           print_spaces (depth, outfile);
342           fprintf_filtered (outfile, "block #%03d, object at ", i);
343           gdb_print_host_address (b, outfile);
344           if (BLOCK_SUPERBLOCK (b))
345             {
346               fprintf_filtered (outfile, " under ");
347               gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile);
348             }
349           /* drow/2002-07-10: We could save the total symbols count
350              even if we're using a hashtable, but nothing else but this message
351              wants it.  */
352           fprintf_filtered (outfile, ", %d syms/buckets in ",
353                             dict_size (BLOCK_DICT (b)));
354           fputs_filtered (paddress (gdbarch, BLOCK_START (b)), outfile);
355           fprintf_filtered (outfile, "..");
356           fputs_filtered (paddress (gdbarch, BLOCK_END (b)), outfile);
357           if (BLOCK_FUNCTION (b))
358             {
359               fprintf_filtered (outfile, ", function %s",
360                                 SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b)));
361               if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
362                 {
363                   fprintf_filtered (outfile, ", %s",
364                                 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
365                 }
366             }
367           fprintf_filtered (outfile, "\n");
368           /* Now print each symbol in this block (in no particular order, if
369              we're using a hashtable).  */
370           ALL_BLOCK_SYMBOLS (b, iter, sym)
371             {
372               struct print_symbol_args s;
373
374               s.gdbarch = gdbarch;
375               s.symbol = sym;
376               s.depth = depth + 1;
377               s.outfile = outfile;
378               catch_errors (print_symbol, &s, "Error printing symbol:\n",
379                             RETURN_MASK_ERROR);
380             }
381         }
382       fprintf_filtered (outfile, "\n");
383     }
384   else
385     {
386       fprintf_filtered (outfile, "\nBlockvector same as previous symtab\n\n");
387     }
388 }
389
390 static void
391 dump_symtab (struct objfile *objfile, struct symtab *symtab,
392              struct ui_file *outfile)
393 {
394   /* Set the current language to the language of the symtab we're dumping
395      because certain routines used during dump_symtab() use the current
396      language to print an image of the symbol.  We'll restore it later.
397      But use only real languages, not placeholders.  */
398   if (symtab->language != language_unknown
399       && symtab->language != language_auto)
400     {
401       enum language saved_lang;
402
403       saved_lang = set_language (symtab->language);
404
405       dump_symtab_1 (objfile, symtab, outfile);
406
407       set_language (saved_lang);
408     }
409   else
410     dump_symtab_1 (objfile, symtab, outfile);
411 }
412
413 void
414 maintenance_print_symbols (char *args, int from_tty)
415 {
416   char **argv;
417   struct ui_file *outfile;
418   struct cleanup *cleanups;
419   char *symname = NULL;
420   char *filename = DEV_TTY;
421   struct objfile *objfile;
422   struct symtab *s;
423
424   dont_repeat ();
425
426   if (args == NULL)
427     {
428       error (_("Arguments missing: an output file name "
429                "and an optional symbol file name"));
430     }
431   argv = gdb_buildargv (args);
432   cleanups = make_cleanup_freeargv (argv);
433
434   if (argv[0] != NULL)
435     {
436       filename = argv[0];
437       /* If a second arg is supplied, it is a source file name to match on.  */
438       if (argv[1] != NULL)
439         {
440           symname = argv[1];
441         }
442     }
443
444   filename = tilde_expand (filename);
445   make_cleanup (xfree, filename);
446
447   outfile = gdb_fopen (filename, FOPEN_WT);
448   if (outfile == 0)
449     perror_with_name (filename);
450   make_cleanup_ui_file_delete (outfile);
451
452   immediate_quit++;
453   ALL_SYMTABS (objfile, s)
454     if (symname == NULL || filename_cmp (symname, s->filename) == 0)
455     dump_symtab (objfile, s, outfile);
456   immediate_quit--;
457   do_cleanups (cleanups);
458 }
459
460 /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE.  ARGS->DEPTH says how
461    far to indent.  ARGS is really a struct print_symbol_args *, but is
462    declared as char * to get it past catch_errors.  Returns 0 for error,
463    1 for success.  */
464
465 static int
466 print_symbol (void *args)
467 {
468   struct gdbarch *gdbarch = ((struct print_symbol_args *) args)->gdbarch;
469   struct symbol *symbol = ((struct print_symbol_args *) args)->symbol;
470   int depth = ((struct print_symbol_args *) args)->depth;
471   struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile;
472   struct obj_section *section = SYMBOL_OBJ_SECTION (symbol);
473
474   print_spaces (depth, outfile);
475   if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN)
476     {
477       fprintf_filtered (outfile, "label %s at ", SYMBOL_PRINT_NAME (symbol));
478       fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
479                       outfile);
480       if (section)
481         fprintf_filtered (outfile, " section %s\n",
482                           bfd_section_name (section->the_bfd_section->owner,
483                                             section->the_bfd_section));
484       else
485         fprintf_filtered (outfile, "\n");
486       return 1;
487     }
488   if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN)
489     {
490       if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
491         {
492           LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
493         }
494       else
495         {
496           fprintf_filtered (outfile, "%s %s = ",
497                          (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
498                           ? "enum"
499                      : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
500                         ? "struct" : "union")),
501                             SYMBOL_LINKAGE_NAME (symbol));
502           LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
503         }
504       fprintf_filtered (outfile, ";\n");
505     }
506   else
507     {
508       if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
509         fprintf_filtered (outfile, "typedef ");
510       if (SYMBOL_TYPE (symbol))
511         {
512           /* Print details of types, except for enums where it's clutter.  */
513           LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_PRINT_NAME (symbol),
514                          outfile,
515                          TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
516                          depth);
517           fprintf_filtered (outfile, "; ");
518         }
519       else
520         fprintf_filtered (outfile, "%s ", SYMBOL_PRINT_NAME (symbol));
521
522       switch (SYMBOL_CLASS (symbol))
523         {
524         case LOC_CONST:
525           fprintf_filtered (outfile, "const %ld (0x%lx)",
526                             SYMBOL_VALUE (symbol),
527                             SYMBOL_VALUE (symbol));
528           break;
529
530         case LOC_CONST_BYTES:
531           {
532             unsigned i;
533             struct type *type = check_typedef (SYMBOL_TYPE (symbol));
534
535             fprintf_filtered (outfile, "const %u hex bytes:",
536                               TYPE_LENGTH (type));
537             for (i = 0; i < TYPE_LENGTH (type); i++)
538               fprintf_filtered (outfile, " %02x",
539                                 (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]);
540           }
541           break;
542
543         case LOC_STATIC:
544           fprintf_filtered (outfile, "static at ");
545           fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
546                           outfile);
547           if (section)
548             fprintf_filtered (outfile, " section %s",
549                               bfd_section_name (section->the_bfd_section->owner,
550                                                 section->the_bfd_section));
551           break;
552
553         case LOC_REGISTER:
554           if (SYMBOL_IS_ARGUMENT (symbol))
555             fprintf_filtered (outfile, "parameter register %ld",
556                               SYMBOL_VALUE (symbol));
557           else
558             fprintf_filtered (outfile, "register %ld", SYMBOL_VALUE (symbol));
559           break;
560
561         case LOC_ARG:
562           fprintf_filtered (outfile, "arg at offset 0x%lx",
563                             SYMBOL_VALUE (symbol));
564           break;
565
566         case LOC_REF_ARG:
567           fprintf_filtered (outfile, "reference arg at 0x%lx", SYMBOL_VALUE (symbol));
568           break;
569
570         case LOC_REGPARM_ADDR:
571           fprintf_filtered (outfile, "address parameter register %ld", SYMBOL_VALUE (symbol));
572           break;
573
574         case LOC_LOCAL:
575           fprintf_filtered (outfile, "local at offset 0x%lx",
576                             SYMBOL_VALUE (symbol));
577           break;
578
579         case LOC_TYPEDEF:
580           break;
581
582         case LOC_LABEL:
583           fprintf_filtered (outfile, "label at ");
584           fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
585                           outfile);
586           if (section)
587             fprintf_filtered (outfile, " section %s",
588                               bfd_section_name (section->the_bfd_section->owner,
589                                                 section->the_bfd_section));
590           break;
591
592         case LOC_BLOCK:
593           fprintf_filtered (outfile, "block object ");
594           gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
595           fprintf_filtered (outfile, ", ");
596           fputs_filtered (paddress (gdbarch,
597                                     BLOCK_START (SYMBOL_BLOCK_VALUE (symbol))),
598                           outfile);
599           fprintf_filtered (outfile, "..");
600           fputs_filtered (paddress (gdbarch,
601                                     BLOCK_END (SYMBOL_BLOCK_VALUE (symbol))),
602                           outfile);
603           if (section)
604             fprintf_filtered (outfile, " section %s",
605                               bfd_section_name (section->the_bfd_section->owner,
606                                                 section->the_bfd_section));
607           break;
608
609         case LOC_COMPUTED:
610           fprintf_filtered (outfile, "computed at runtime");
611           break;
612
613         case LOC_UNRESOLVED:
614           fprintf_filtered (outfile, "unresolved");
615           break;
616
617         case LOC_OPTIMIZED_OUT:
618           fprintf_filtered (outfile, "optimized out");
619           break;
620
621         default:
622           fprintf_filtered (outfile, "botched symbol class %x",
623                             SYMBOL_CLASS (symbol));
624           break;
625         }
626     }
627   fprintf_filtered (outfile, "\n");
628   return 1;
629 }
630
631 void
632 maintenance_print_msymbols (char *args, int from_tty)
633 {
634   char **argv;
635   struct ui_file *outfile;
636   struct cleanup *cleanups;
637   char *filename = DEV_TTY;
638   char *symname = NULL;
639   struct program_space *pspace;
640   struct objfile *objfile;
641
642   struct stat sym_st, obj_st;
643
644   dont_repeat ();
645
646   if (args == NULL)
647     {
648       error (_("print-msymbols takes an output file "
649                "name and optional symbol file name"));
650     }
651   argv = gdb_buildargv (args);
652   cleanups = make_cleanup_freeargv (argv);
653
654   if (argv[0] != NULL)
655     {
656       filename = argv[0];
657       /* If a second arg is supplied, it is a source file name to match on.  */
658       if (argv[1] != NULL)
659         {
660           symname = xfullpath (argv[1]);
661           make_cleanup (xfree, symname);
662           if (symname && stat (symname, &sym_st))
663             perror_with_name (symname);
664         }
665     }
666
667   filename = tilde_expand (filename);
668   make_cleanup (xfree, filename);
669
670   outfile = gdb_fopen (filename, FOPEN_WT);
671   if (outfile == 0)
672     perror_with_name (filename);
673   make_cleanup_ui_file_delete (outfile);
674
675   immediate_quit++;
676   ALL_PSPACES (pspace)
677     ALL_PSPACE_OBJFILES (pspace, objfile)
678       if (symname == NULL || (!stat (objfile->name, &obj_st)
679                               && sym_st.st_ino == obj_st.st_ino))
680         dump_msymbols (objfile, outfile);
681   immediate_quit--;
682   fprintf_filtered (outfile, "\n\n");
683   do_cleanups (cleanups);
684 }
685
686 void
687 maintenance_print_objfiles (char *ignore, int from_tty)
688 {
689   struct program_space *pspace;
690   struct objfile *objfile;
691
692   dont_repeat ();
693
694   immediate_quit++;
695   ALL_PSPACES (pspace)
696     ALL_PSPACE_OBJFILES (pspace, objfile)
697       dump_objfile (objfile);
698   immediate_quit--;
699 }
700
701
702 /* List all the symbol tables whose names match REGEXP (optional).  */
703 void
704 maintenance_info_symtabs (char *regexp, int from_tty)
705 {
706   struct program_space *pspace;
707   struct objfile *objfile;
708
709   if (regexp)
710     re_comp (regexp);
711
712   ALL_PSPACES (pspace)
713     ALL_PSPACE_OBJFILES (pspace, objfile)
714     {
715       struct symtab *symtab;
716       
717       /* We don't want to print anything for this objfile until we
718          actually find a symtab whose name matches.  */
719       int printed_objfile_start = 0;
720
721       ALL_OBJFILE_SYMTABS (objfile, symtab)
722         {
723           QUIT;
724
725           if (! regexp
726               || re_exec (symtab->filename))
727             {
728               if (! printed_objfile_start)
729                 {
730                   printf_filtered ("{ objfile %s ", objfile->name);
731                   wrap_here ("  ");
732                   printf_filtered ("((struct objfile *) %s)\n", 
733                                    host_address_to_string (objfile));
734                   printed_objfile_start = 1;
735                 }
736
737               printf_filtered ("        { symtab %s ", symtab->filename);
738               wrap_here ("    ");
739               printf_filtered ("((struct symtab *) %s)\n", 
740                                host_address_to_string (symtab));
741               printf_filtered ("          dirname %s\n",
742                                symtab->dirname ? symtab->dirname : "(null)");
743               printf_filtered ("          fullname %s\n",
744                                symtab->fullname ? symtab->fullname : "(null)");
745               printf_filtered ("          "
746                                "blockvector ((struct blockvector *) %s)%s\n",
747                                host_address_to_string (symtab->blockvector),
748                                symtab->primary ? " (primary)" : "");
749               printf_filtered ("          "
750                                "linetable ((struct linetable *) %s)\n",
751                                host_address_to_string (symtab->linetable));
752               printf_filtered ("          debugformat %s\n",
753                                symtab->debugformat);
754               printf_filtered ("        }\n");
755             }
756         }
757
758       if (printed_objfile_start)
759         printf_filtered ("}\n");
760     }
761 }
762 \f
763
764 /* Return the nexting depth of a block within other blocks in its symtab.  */
765
766 static int
767 block_depth (struct block *block)
768 {
769   int i = 0;
770
771   while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
772     {
773       i++;
774     }
775   return i;
776 }
777 \f
778
779 /* Do early runtime initializations.  */
780 void
781 _initialize_symmisc (void)
782 {
783   std_in = stdin;
784   std_out = stdout;
785   std_err = stderr;
786 }