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