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