* tracepoint.c (scope_info): Update.
[external/binutils.git] / gdb / symmisc.c
1 /* Do various things to symbol tables (other than lookup), for GDB.
2
3    Copyright (C) 1986-2000, 2002-2004, 2007-2012 Free Software
4    Foundation, Inc.
5
6    This file is part of GDB.
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20
21 #include "defs.h"
22 #include "symtab.h"
23 #include "gdbtypes.h"
24 #include "bfd.h"
25 #include "filenames.h"
26 #include "symfile.h"
27 #include "objfiles.h"
28 #include "breakpoint.h"
29 #include "command.h"
30 #include "gdb_obstack.h"
31 #include "exceptions.h"
32 #include "language.h"
33 #include "bcache.h"
34 #include "block.h"
35 #include "gdb_regex.h"
36 #include "gdb_stat.h"
37 #include "dictionary.h"
38
39 #include "gdb_string.h"
40 #include "readline/readline.h"
41
42 #include "psymtab.h"
43
44 #ifndef DEV_TTY
45 #define DEV_TTY "/dev/tty"
46 #endif
47
48 /* Unfortunately for debugging, stderr is usually a macro.  This is painful
49    when calling functions that take FILE *'s from the debugger.
50    So we make a variable which has the same value and which is accessible when
51    debugging GDB with itself.  Because stdin et al need not be constants,
52    we initialize them in the _initialize_symmisc function at the bottom
53    of the file.  */
54 FILE *std_in;
55 FILE *std_out;
56 FILE *std_err;
57
58 /* Prototypes for local functions */
59
60 static void dump_symtab (struct objfile *, struct symtab *,
61                          struct ui_file *);
62
63 static void dump_msymbols (struct objfile *, struct ui_file *);
64
65 static void dump_objfile (struct objfile *);
66
67 static int block_depth (struct block *);
68
69 void _initialize_symmisc (void);
70
71 struct print_symbol_args
72   {
73     struct gdbarch *gdbarch;
74     struct symbol *symbol;
75     int depth;
76     struct ui_file *outfile;
77   };
78
79 static int print_symbol (void *);
80 \f
81
82 void
83 print_symbol_bcache_statistics (void)
84 {
85   struct program_space *pspace;
86   struct objfile *objfile;
87
88   immediate_quit++;
89   ALL_PSPACES (pspace)
90     ALL_PSPACE_OBJFILES (pspace, objfile)
91   {
92     printf_filtered (_("Byte cache statistics for '%s':\n"), objfile->name);
93     print_bcache_statistics (psymbol_bcache_get_bcache (objfile->psymbol_cache),
94                              "partial symbol cache");
95     print_bcache_statistics (objfile->macro_cache, "preprocessor macro cache");
96     print_bcache_statistics (objfile->filename_cache, "file name cache");
97   }
98   immediate_quit--;
99 }
100
101 void
102 print_objfile_statistics (void)
103 {
104   struct program_space *pspace;
105   struct objfile *objfile;
106   struct symtab *s;
107   int i, linetables, blockvectors;
108
109   immediate_quit++;
110   ALL_PSPACES (pspace)
111     ALL_PSPACE_OBJFILES (pspace, objfile)
112   {
113     printf_filtered (_("Statistics for '%s':\n"), objfile->name);
114     if (OBJSTAT (objfile, n_stabs) > 0)
115       printf_filtered (_("  Number of \"stab\" symbols read: %d\n"),
116                        OBJSTAT (objfile, n_stabs));
117     if (OBJSTAT (objfile, n_minsyms) > 0)
118       printf_filtered (_("  Number of \"minimal\" symbols read: %d\n"),
119                        OBJSTAT (objfile, n_minsyms));
120     if (OBJSTAT (objfile, n_psyms) > 0)
121       printf_filtered (_("  Number of \"partial\" symbols read: %d\n"),
122                        OBJSTAT (objfile, n_psyms));
123     if (OBJSTAT (objfile, n_syms) > 0)
124       printf_filtered (_("  Number of \"full\" symbols read: %d\n"),
125                        OBJSTAT (objfile, n_syms));
126     if (OBJSTAT (objfile, n_types) > 0)
127       printf_filtered (_("  Number of \"types\" defined: %d\n"),
128                        OBJSTAT (objfile, n_types));
129     if (objfile->sf)
130       objfile->sf->qf->print_stats (objfile);
131     i = linetables = blockvectors = 0;
132     ALL_OBJFILE_SYMTABS (objfile, s)
133       {
134         i++;
135         if (s->linetable != NULL)
136           linetables++;
137         if (s->primary == 1)
138           blockvectors++;
139       }
140     printf_filtered (_("  Number of symbol tables: %d\n"), i);
141     printf_filtered (_("  Number of symbol tables with line tables: %d\n"), 
142                      linetables);
143     printf_filtered (_("  Number of symbol tables with blockvectors: %d\n"), 
144                      blockvectors);
145     
146     if (OBJSTAT (objfile, sz_strtab) > 0)
147       printf_filtered (_("  Space used by a.out string tables: %d\n"),
148                        OBJSTAT (objfile, sz_strtab));
149     printf_filtered (_("  Total memory used for objfile obstack: %d\n"),
150                      obstack_memory_used (&objfile->objfile_obstack));
151     printf_filtered (_("  Total memory used for psymbol cache: %d\n"),
152                      bcache_memory_used (psymbol_bcache_get_bcache
153                                           (objfile->psymbol_cache)));
154     printf_filtered (_("  Total memory used for macro cache: %d\n"),
155                      bcache_memory_used (objfile->macro_cache));
156     printf_filtered (_("  Total memory used for file name cache: %d\n"),
157                      bcache_memory_used (objfile->filename_cache));
158   }
159   immediate_quit--;
160 }
161
162 static void
163 dump_objfile (struct objfile *objfile)
164 {
165   struct symtab *symtab;
166
167   printf_filtered ("\nObject file %s:  ", objfile->name);
168   printf_filtered ("Objfile at ");
169   gdb_print_host_address (objfile, gdb_stdout);
170   printf_filtered (", bfd at ");
171   gdb_print_host_address (objfile->obfd, gdb_stdout);
172   printf_filtered (", %d minsyms\n\n",
173                    objfile->minimal_symbol_count);
174
175   if (objfile->sf)
176     objfile->sf->qf->dump (objfile);
177
178   if (objfile->symtabs)
179     {
180       printf_filtered ("Symtabs:\n");
181       for (symtab = objfile->symtabs;
182            symtab != NULL;
183            symtab = symtab->next)
184         {
185           printf_filtered ("%s at ", symtab->filename);
186           gdb_print_host_address (symtab, gdb_stdout);
187           printf_filtered (", ");
188           if (symtab->objfile != objfile)
189             {
190               printf_filtered ("NOT ON CHAIN!  ");
191             }
192           wrap_here ("  ");
193         }
194       printf_filtered ("\n\n");
195     }
196 }
197
198 /* Print minimal symbols from this objfile.  */
199
200 static void
201 dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
202 {
203   struct gdbarch *gdbarch = get_objfile_arch (objfile);
204   struct minimal_symbol *msymbol;
205   int index;
206   char ms_type;
207
208   fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile->name);
209   if (objfile->minimal_symbol_count == 0)
210     {
211       fprintf_filtered (outfile, "No minimal symbols found.\n");
212       return;
213     }
214   index = 0;
215   ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
216     {
217       struct obj_section *section = SYMBOL_OBJ_SECTION (msymbol);
218
219       switch (MSYMBOL_TYPE (msymbol))
220         {
221         case mst_unknown:
222           ms_type = 'u';
223           break;
224         case mst_text:
225           ms_type = 'T';
226           break;
227         case mst_text_gnu_ifunc:
228           ms_type = 'i';
229           break;
230         case mst_solib_trampoline:
231           ms_type = 'S';
232           break;
233         case mst_data:
234           ms_type = 'D';
235           break;
236         case mst_bss:
237           ms_type = 'B';
238           break;
239         case mst_abs:
240           ms_type = 'A';
241           break;
242         case mst_file_text:
243           ms_type = 't';
244           break;
245         case mst_file_data:
246           ms_type = 'd';
247           break;
248         case mst_file_bss:
249           ms_type = 'b';
250           break;
251         default:
252           ms_type = '?';
253           break;
254         }
255       fprintf_filtered (outfile, "[%2d] %c ", index, ms_type);
256       fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (msymbol)),
257                       outfile);
258       fprintf_filtered (outfile, " %s", SYMBOL_LINKAGE_NAME (msymbol));
259       if (section)
260         fprintf_filtered (outfile, " section %s",
261                           bfd_section_name (objfile->obfd,
262                                             section->the_bfd_section));
263       if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
264         {
265           fprintf_filtered (outfile, "  %s", SYMBOL_DEMANGLED_NAME (msymbol));
266         }
267       if (msymbol->filename)
268         fprintf_filtered (outfile, "  %s", msymbol->filename);
269       fputs_filtered ("\n", outfile);
270       index++;
271     }
272   if (objfile->minimal_symbol_count != index)
273     {
274       warning (_("internal error:  minimal symbol count %d != %d"),
275                objfile->minimal_symbol_count, index);
276     }
277   fprintf_filtered (outfile, "\n");
278 }
279
280 static void
281 dump_symtab_1 (struct objfile *objfile, struct symtab *symtab,
282                struct ui_file *outfile)
283 {
284   struct gdbarch *gdbarch = get_objfile_arch (objfile);
285   int i;
286   struct dict_iterator iter;
287   int len;
288   struct linetable *l;
289   struct blockvector *bv;
290   struct symbol *sym;
291   struct block *b;
292   int depth;
293
294   fprintf_filtered (outfile, "\nSymtab for file %s\n", symtab->filename);
295   if (symtab->dirname)
296     fprintf_filtered (outfile, "Compilation directory is %s\n",
297                       symtab->dirname);
298   fprintf_filtered (outfile, "Read from object file %s (", objfile->name);
299   gdb_print_host_address (objfile, outfile);
300   fprintf_filtered (outfile, ")\n");
301   fprintf_filtered (outfile, "Language: %s\n",
302                     language_str (symtab->language));
303
304   /* First print the line table.  */
305   l = LINETABLE (symtab);
306   if (l)
307     {
308       fprintf_filtered (outfile, "\nLine table:\n\n");
309       len = l->nitems;
310       for (i = 0; i < len; i++)
311         {
312           fprintf_filtered (outfile, " line %d at ", l->item[i].line);
313           fputs_filtered (paddress (gdbarch, l->item[i].pc), outfile);
314           fprintf_filtered (outfile, "\n");
315         }
316     }
317   /* Now print the block info, but only for primary symtabs since we will
318      print lots of duplicate info otherwise.  */
319   if (symtab->primary)
320     {
321       fprintf_filtered (outfile, "\nBlockvector:\n\n");
322       bv = BLOCKVECTOR (symtab);
323       len = BLOCKVECTOR_NBLOCKS (bv);
324       for (i = 0; i < len; i++)
325         {
326           b = BLOCKVECTOR_BLOCK (bv, i);
327           depth = block_depth (b) * 2;
328           print_spaces (depth, outfile);
329           fprintf_filtered (outfile, "block #%03d, object at ", i);
330           gdb_print_host_address (b, outfile);
331           if (BLOCK_SUPERBLOCK (b))
332             {
333               fprintf_filtered (outfile, " under ");
334               gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile);
335             }
336           /* drow/2002-07-10: We could save the total symbols count
337              even if we're using a hashtable, but nothing else but this message
338              wants it.  */
339           fprintf_filtered (outfile, ", %d syms/buckets in ",
340                             dict_size (BLOCK_DICT (b)));
341           fputs_filtered (paddress (gdbarch, BLOCK_START (b)), outfile);
342           fprintf_filtered (outfile, "..");
343           fputs_filtered (paddress (gdbarch, BLOCK_END (b)), outfile);
344           if (BLOCK_FUNCTION (b))
345             {
346               fprintf_filtered (outfile, ", function %s",
347                                 SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b)));
348               if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
349                 {
350                   fprintf_filtered (outfile, ", %s",
351                                 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
352                 }
353             }
354           fprintf_filtered (outfile, "\n");
355           /* Now print each symbol in this block (in no particular order, if
356              we're using a hashtable).  Note that we only want this
357              block, not any blocks from included symtabs.  */
358           ALL_DICT_SYMBOLS (BLOCK_DICT (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 %s (%s)",
514                             plongest (SYMBOL_VALUE (symbol)),
515                             hex_string (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 %s",
544                               plongest (SYMBOL_VALUE (symbol)));
545           else
546             fprintf_filtered (outfile, "register %s",
547                               plongest (SYMBOL_VALUE (symbol)));
548           break;
549
550         case LOC_ARG:
551           fprintf_filtered (outfile, "arg at offset %s",
552                             hex_string (SYMBOL_VALUE (symbol)));
553           break;
554
555         case LOC_REF_ARG:
556           fprintf_filtered (outfile, "reference arg at %s",
557                             hex_string (SYMBOL_VALUE (symbol)));
558           break;
559
560         case LOC_REGPARM_ADDR:
561           fprintf_filtered (outfile, "address parameter register %s",
562                             plongest (SYMBOL_VALUE (symbol)));
563           break;
564
565         case LOC_LOCAL:
566           fprintf_filtered (outfile, "local at offset %s",
567                             hex_string (SYMBOL_VALUE (symbol)));
568           break;
569
570         case LOC_TYPEDEF:
571           break;
572
573         case LOC_LABEL:
574           fprintf_filtered (outfile, "label at ");
575           fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
576                           outfile);
577           if (section)
578             fprintf_filtered (outfile, " section %s",
579                               bfd_section_name (section->the_bfd_section->owner,
580                                                 section->the_bfd_section));
581           break;
582
583         case LOC_BLOCK:
584           fprintf_filtered (outfile, "block object ");
585           gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
586           fprintf_filtered (outfile, ", ");
587           fputs_filtered (paddress (gdbarch,
588                                     BLOCK_START (SYMBOL_BLOCK_VALUE (symbol))),
589                           outfile);
590           fprintf_filtered (outfile, "..");
591           fputs_filtered (paddress (gdbarch,
592                                     BLOCK_END (SYMBOL_BLOCK_VALUE (symbol))),
593                           outfile);
594           if (section)
595             fprintf_filtered (outfile, " section %s",
596                               bfd_section_name (section->the_bfd_section->owner,
597                                                 section->the_bfd_section));
598           break;
599
600         case LOC_COMPUTED:
601           fprintf_filtered (outfile, "computed at runtime");
602           break;
603
604         case LOC_UNRESOLVED:
605           fprintf_filtered (outfile, "unresolved");
606           break;
607
608         case LOC_OPTIMIZED_OUT:
609           fprintf_filtered (outfile, "optimized out");
610           break;
611
612         default:
613           fprintf_filtered (outfile, "botched symbol class %x",
614                             SYMBOL_CLASS (symbol));
615           break;
616         }
617     }
618   fprintf_filtered (outfile, "\n");
619   return 1;
620 }
621
622 void
623 maintenance_print_msymbols (char *args, int from_tty)
624 {
625   char **argv;
626   struct ui_file *outfile;
627   struct cleanup *cleanups;
628   char *filename = DEV_TTY;
629   char *symname = NULL;
630   struct program_space *pspace;
631   struct objfile *objfile;
632
633   struct stat sym_st, obj_st;
634
635   dont_repeat ();
636
637   if (args == NULL)
638     {
639       error (_("print-msymbols takes an output file "
640                "name and optional symbol file name"));
641     }
642   argv = gdb_buildargv (args);
643   cleanups = make_cleanup_freeargv (argv);
644
645   if (argv[0] != NULL)
646     {
647       filename = argv[0];
648       /* If a second arg is supplied, it is a source file name to match on.  */
649       if (argv[1] != NULL)
650         {
651           symname = xfullpath (argv[1]);
652           make_cleanup (xfree, symname);
653           if (symname && stat (symname, &sym_st))
654             perror_with_name (symname);
655         }
656     }
657
658   filename = tilde_expand (filename);
659   make_cleanup (xfree, filename);
660
661   outfile = gdb_fopen (filename, FOPEN_WT);
662   if (outfile == 0)
663     perror_with_name (filename);
664   make_cleanup_ui_file_delete (outfile);
665
666   immediate_quit++;
667   ALL_PSPACES (pspace)
668     ALL_PSPACE_OBJFILES (pspace, objfile)
669       if (symname == NULL || (!stat (objfile->name, &obj_st)
670                               && sym_st.st_ino == obj_st.st_ino))
671         dump_msymbols (objfile, outfile);
672   immediate_quit--;
673   fprintf_filtered (outfile, "\n\n");
674   do_cleanups (cleanups);
675 }
676
677 void
678 maintenance_print_objfiles (char *ignore, int from_tty)
679 {
680   struct program_space *pspace;
681   struct objfile *objfile;
682
683   dont_repeat ();
684
685   immediate_quit++;
686   ALL_PSPACES (pspace)
687     ALL_PSPACE_OBJFILES (pspace, objfile)
688       dump_objfile (objfile);
689   immediate_quit--;
690 }
691
692
693 /* List all the symbol tables whose names match REGEXP (optional).  */
694 void
695 maintenance_info_symtabs (char *regexp, int from_tty)
696 {
697   struct program_space *pspace;
698   struct objfile *objfile;
699
700   if (regexp)
701     re_comp (regexp);
702
703   ALL_PSPACES (pspace)
704     ALL_PSPACE_OBJFILES (pspace, objfile)
705     {
706       struct symtab *symtab;
707       
708       /* We don't want to print anything for this objfile until we
709          actually find a symtab whose name matches.  */
710       int printed_objfile_start = 0;
711
712       ALL_OBJFILE_SYMTABS (objfile, symtab)
713         {
714           QUIT;
715
716           if (! regexp
717               || re_exec (symtab->filename))
718             {
719               if (! printed_objfile_start)
720                 {
721                   printf_filtered ("{ objfile %s ", objfile->name);
722                   wrap_here ("  ");
723                   printf_filtered ("((struct objfile *) %s)\n", 
724                                    host_address_to_string (objfile));
725                   printed_objfile_start = 1;
726                 }
727
728               printf_filtered ("        { symtab %s ", symtab->filename);
729               wrap_here ("    ");
730               printf_filtered ("((struct symtab *) %s)\n", 
731                                host_address_to_string (symtab));
732               printf_filtered ("          dirname %s\n",
733                                symtab->dirname ? symtab->dirname : "(null)");
734               printf_filtered ("          fullname %s\n",
735                                symtab->fullname ? symtab->fullname : "(null)");
736               printf_filtered ("          "
737                                "blockvector ((struct blockvector *) %s)%s\n",
738                                host_address_to_string (symtab->blockvector),
739                                symtab->primary ? " (primary)" : "");
740               printf_filtered ("          "
741                                "linetable ((struct linetable *) %s)\n",
742                                host_address_to_string (symtab->linetable));
743               printf_filtered ("          debugformat %s\n",
744                                symtab->debugformat);
745               printf_filtered ("        }\n");
746             }
747         }
748
749       if (printed_objfile_start)
750         printf_filtered ("}\n");
751     }
752 }
753 \f
754
755 /* Return the nexting depth of a block within other blocks in its symtab.  */
756
757 static int
758 block_depth (struct block *block)
759 {
760   int i = 0;
761
762   while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
763     {
764       i++;
765     }
766   return i;
767 }
768 \f
769
770 /* Do early runtime initializations.  */
771 void
772 _initialize_symmisc (void)
773 {
774   std_in = stdin;
775   std_out = stdout;
776   std_err = stderr;
777 }