* elfread.c (elf_symtab_read): Update.
[platform/upstream/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->per_bfd->filename_cache,
97                              "file name cache");
98   }
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   ALL_PSPACES (pspace)
110     ALL_PSPACE_OBJFILES (pspace, objfile)
111   {
112     QUIT;
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 BFD obstack: %d\n"),
152                      obstack_memory_used (&objfile->per_bfd->storage_obstack));
153     printf_filtered (_("  Total memory used for psymbol cache: %d\n"),
154                      bcache_memory_used (psymbol_bcache_get_bcache
155                                           (objfile->psymbol_cache)));
156     printf_filtered (_("  Total memory used for macro cache: %d\n"),
157                      bcache_memory_used (objfile->macro_cache));
158     printf_filtered (_("  Total memory used for file name cache: %d\n"),
159                      bcache_memory_used (objfile->per_bfd->filename_cache));
160   }
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).  Note that we only want this
358              block, not any blocks from included symtabs.  */
359           ALL_DICT_SYMBOLS (BLOCK_DICT (b), iter, sym)
360             {
361               struct print_symbol_args s;
362
363               s.gdbarch = gdbarch;
364               s.symbol = sym;
365               s.depth = depth + 1;
366               s.outfile = outfile;
367               catch_errors (print_symbol, &s, "Error printing symbol:\n",
368                             RETURN_MASK_ERROR);
369             }
370         }
371       fprintf_filtered (outfile, "\n");
372     }
373   else
374     {
375       fprintf_filtered (outfile, "\nBlockvector same as previous symtab\n\n");
376     }
377 }
378
379 static void
380 dump_symtab (struct objfile *objfile, struct symtab *symtab,
381              struct ui_file *outfile)
382 {
383   /* Set the current language to the language of the symtab we're dumping
384      because certain routines used during dump_symtab() use the current
385      language to print an image of the symbol.  We'll restore it later.
386      But use only real languages, not placeholders.  */
387   if (symtab->language != language_unknown
388       && symtab->language != language_auto)
389     {
390       enum language saved_lang;
391
392       saved_lang = set_language (symtab->language);
393
394       dump_symtab_1 (objfile, symtab, outfile);
395
396       set_language (saved_lang);
397     }
398   else
399     dump_symtab_1 (objfile, symtab, outfile);
400 }
401
402 void
403 maintenance_print_symbols (char *args, int from_tty)
404 {
405   char **argv;
406   struct ui_file *outfile;
407   struct cleanup *cleanups;
408   char *symname = NULL;
409   char *filename = DEV_TTY;
410   struct objfile *objfile;
411   struct symtab *s;
412
413   dont_repeat ();
414
415   if (args == NULL)
416     {
417       error (_("Arguments missing: an output file name "
418                "and an optional symbol file name"));
419     }
420   argv = gdb_buildargv (args);
421   cleanups = make_cleanup_freeargv (argv);
422
423   if (argv[0] != NULL)
424     {
425       filename = argv[0];
426       /* If a second arg is supplied, it is a source file name to match on.  */
427       if (argv[1] != NULL)
428         {
429           symname = argv[1];
430         }
431     }
432
433   filename = tilde_expand (filename);
434   make_cleanup (xfree, filename);
435
436   outfile = gdb_fopen (filename, FOPEN_WT);
437   if (outfile == 0)
438     perror_with_name (filename);
439   make_cleanup_ui_file_delete (outfile);
440
441   ALL_SYMTABS (objfile, s)
442     {
443       QUIT;
444       if (symname == NULL || filename_cmp (symname, s->filename) == 0)
445         dump_symtab (objfile, s, outfile);
446     }
447   do_cleanups (cleanups);
448 }
449
450 /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE.  ARGS->DEPTH says how
451    far to indent.  ARGS is really a struct print_symbol_args *, but is
452    declared as char * to get it past catch_errors.  Returns 0 for error,
453    1 for success.  */
454
455 static int
456 print_symbol (void *args)
457 {
458   struct gdbarch *gdbarch = ((struct print_symbol_args *) args)->gdbarch;
459   struct symbol *symbol = ((struct print_symbol_args *) args)->symbol;
460   int depth = ((struct print_symbol_args *) args)->depth;
461   struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile;
462   struct obj_section *section = SYMBOL_OBJ_SECTION (symbol);
463
464   print_spaces (depth, outfile);
465   if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN)
466     {
467       fprintf_filtered (outfile, "label %s at ", SYMBOL_PRINT_NAME (symbol));
468       fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
469                       outfile);
470       if (section)
471         fprintf_filtered (outfile, " section %s\n",
472                           bfd_section_name (section->the_bfd_section->owner,
473                                             section->the_bfd_section));
474       else
475         fprintf_filtered (outfile, "\n");
476       return 1;
477     }
478   if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN)
479     {
480       if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
481         {
482           LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
483         }
484       else
485         {
486           fprintf_filtered (outfile, "%s %s = ",
487                          (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
488                           ? "enum"
489                      : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
490                         ? "struct" : "union")),
491                             SYMBOL_LINKAGE_NAME (symbol));
492           LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
493         }
494       fprintf_filtered (outfile, ";\n");
495     }
496   else
497     {
498       if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
499         fprintf_filtered (outfile, "typedef ");
500       if (SYMBOL_TYPE (symbol))
501         {
502           /* Print details of types, except for enums where it's clutter.  */
503           LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_PRINT_NAME (symbol),
504                          outfile,
505                          TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
506                          depth);
507           fprintf_filtered (outfile, "; ");
508         }
509       else
510         fprintf_filtered (outfile, "%s ", SYMBOL_PRINT_NAME (symbol));
511
512       switch (SYMBOL_CLASS (symbol))
513         {
514         case LOC_CONST:
515           fprintf_filtered (outfile, "const %s (%s)",
516                             plongest (SYMBOL_VALUE (symbol)),
517                             hex_string (SYMBOL_VALUE (symbol)));
518           break;
519
520         case LOC_CONST_BYTES:
521           {
522             unsigned i;
523             struct type *type = check_typedef (SYMBOL_TYPE (symbol));
524
525             fprintf_filtered (outfile, "const %u hex bytes:",
526                               TYPE_LENGTH (type));
527             for (i = 0; i < TYPE_LENGTH (type); i++)
528               fprintf_filtered (outfile, " %02x",
529                                 (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]);
530           }
531           break;
532
533         case LOC_STATIC:
534           fprintf_filtered (outfile, "static at ");
535           fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
536                           outfile);
537           if (section)
538             fprintf_filtered (outfile, " section %s",
539                               bfd_section_name (section->the_bfd_section->owner,
540                                                 section->the_bfd_section));
541           break;
542
543         case LOC_REGISTER:
544           if (SYMBOL_IS_ARGUMENT (symbol))
545             fprintf_filtered (outfile, "parameter register %s",
546                               plongest (SYMBOL_VALUE (symbol)));
547           else
548             fprintf_filtered (outfile, "register %s",
549                               plongest (SYMBOL_VALUE (symbol)));
550           break;
551
552         case LOC_ARG:
553           fprintf_filtered (outfile, "arg at offset %s",
554                             hex_string (SYMBOL_VALUE (symbol)));
555           break;
556
557         case LOC_REF_ARG:
558           fprintf_filtered (outfile, "reference arg at %s",
559                             hex_string (SYMBOL_VALUE (symbol)));
560           break;
561
562         case LOC_REGPARM_ADDR:
563           fprintf_filtered (outfile, "address parameter register %s",
564                             plongest (SYMBOL_VALUE (symbol)));
565           break;
566
567         case LOC_LOCAL:
568           fprintf_filtered (outfile, "local at offset %s",
569                             hex_string (SYMBOL_VALUE (symbol)));
570           break;
571
572         case LOC_TYPEDEF:
573           break;
574
575         case LOC_LABEL:
576           fprintf_filtered (outfile, "label at ");
577           fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
578                           outfile);
579           if (section)
580             fprintf_filtered (outfile, " section %s",
581                               bfd_section_name (section->the_bfd_section->owner,
582                                                 section->the_bfd_section));
583           break;
584
585         case LOC_BLOCK:
586           fprintf_filtered (outfile, "block object ");
587           gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
588           fprintf_filtered (outfile, ", ");
589           fputs_filtered (paddress (gdbarch,
590                                     BLOCK_START (SYMBOL_BLOCK_VALUE (symbol))),
591                           outfile);
592           fprintf_filtered (outfile, "..");
593           fputs_filtered (paddress (gdbarch,
594                                     BLOCK_END (SYMBOL_BLOCK_VALUE (symbol))),
595                           outfile);
596           if (section)
597             fprintf_filtered (outfile, " section %s",
598                               bfd_section_name (section->the_bfd_section->owner,
599                                                 section->the_bfd_section));
600           break;
601
602         case LOC_COMPUTED:
603           fprintf_filtered (outfile, "computed at runtime");
604           break;
605
606         case LOC_UNRESOLVED:
607           fprintf_filtered (outfile, "unresolved");
608           break;
609
610         case LOC_OPTIMIZED_OUT:
611           fprintf_filtered (outfile, "optimized out");
612           break;
613
614         default:
615           fprintf_filtered (outfile, "botched symbol class %x",
616                             SYMBOL_CLASS (symbol));
617           break;
618         }
619     }
620   fprintf_filtered (outfile, "\n");
621   return 1;
622 }
623
624 void
625 maintenance_print_msymbols (char *args, int from_tty)
626 {
627   char **argv;
628   struct ui_file *outfile;
629   struct cleanup *cleanups;
630   char *filename = DEV_TTY;
631   char *symname = NULL;
632   struct program_space *pspace;
633   struct objfile *objfile;
634
635   struct stat sym_st, obj_st;
636
637   dont_repeat ();
638
639   if (args == NULL)
640     {
641       error (_("print-msymbols takes an output file "
642                "name and optional symbol file name"));
643     }
644   argv = gdb_buildargv (args);
645   cleanups = make_cleanup_freeargv (argv);
646
647   if (argv[0] != NULL)
648     {
649       filename = argv[0];
650       /* If a second arg is supplied, it is a source file name to match on.  */
651       if (argv[1] != NULL)
652         {
653           symname = xfullpath (argv[1]);
654           make_cleanup (xfree, symname);
655           if (symname && stat (symname, &sym_st))
656             perror_with_name (symname);
657         }
658     }
659
660   filename = tilde_expand (filename);
661   make_cleanup (xfree, filename);
662
663   outfile = gdb_fopen (filename, FOPEN_WT);
664   if (outfile == 0)
665     perror_with_name (filename);
666   make_cleanup_ui_file_delete (outfile);
667
668   ALL_PSPACES (pspace)
669     ALL_PSPACE_OBJFILES (pspace, objfile)
670       {
671         QUIT;
672         if (symname == NULL || (!stat (objfile->name, &obj_st)
673                                 && sym_st.st_ino == obj_st.st_ino))
674           dump_msymbols (objfile, outfile);
675       }
676   fprintf_filtered (outfile, "\n\n");
677   do_cleanups (cleanups);
678 }
679
680 void
681 maintenance_print_objfiles (char *ignore, int from_tty)
682 {
683   struct program_space *pspace;
684   struct objfile *objfile;
685
686   dont_repeat ();
687
688   ALL_PSPACES (pspace)
689     ALL_PSPACE_OBJFILES (pspace, objfile)
690       {
691         QUIT;
692         dump_objfile (objfile);
693       }
694 }
695
696
697 /* List all the symbol tables whose names match REGEXP (optional).  */
698 void
699 maintenance_info_symtabs (char *regexp, int from_tty)
700 {
701   struct program_space *pspace;
702   struct objfile *objfile;
703
704   if (regexp)
705     re_comp (regexp);
706
707   ALL_PSPACES (pspace)
708     ALL_PSPACE_OBJFILES (pspace, objfile)
709     {
710       struct symtab *symtab;
711       
712       /* We don't want to print anything for this objfile until we
713          actually find a symtab whose name matches.  */
714       int printed_objfile_start = 0;
715
716       ALL_OBJFILE_SYMTABS (objfile, symtab)
717         {
718           QUIT;
719
720           if (! regexp
721               || re_exec (symtab->filename))
722             {
723               if (! printed_objfile_start)
724                 {
725                   printf_filtered ("{ objfile %s ", objfile->name);
726                   wrap_here ("  ");
727                   printf_filtered ("((struct objfile *) %s)\n", 
728                                    host_address_to_string (objfile));
729                   printed_objfile_start = 1;
730                 }
731
732               printf_filtered ("        { symtab %s ", symtab->filename);
733               wrap_here ("    ");
734               printf_filtered ("((struct symtab *) %s)\n", 
735                                host_address_to_string (symtab));
736               printf_filtered ("          dirname %s\n",
737                                symtab->dirname ? symtab->dirname : "(null)");
738               printf_filtered ("          fullname %s\n",
739                                symtab->fullname ? symtab->fullname : "(null)");
740               printf_filtered ("          "
741                                "blockvector ((struct blockvector *) %s)%s\n",
742                                host_address_to_string (symtab->blockvector),
743                                symtab->primary ? " (primary)" : "");
744               printf_filtered ("          "
745                                "linetable ((struct linetable *) %s)\n",
746                                host_address_to_string (symtab->linetable));
747               printf_filtered ("          debugformat %s\n",
748                                symtab->debugformat);
749               printf_filtered ("        }\n");
750             }
751         }
752
753       if (printed_objfile_start)
754         printf_filtered ("}\n");
755     }
756 }
757 \f
758
759 /* Return the nexting depth of a block within other blocks in its symtab.  */
760
761 static int
762 block_depth (struct block *block)
763 {
764   int i = 0;
765
766   while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
767     {
768       i++;
769     }
770   return i;
771 }
772 \f
773
774 /* Do early runtime initializations.  */
775 void
776 _initialize_symmisc (void)
777 {
778   std_in = stdin;
779   std_out = stdout;
780   std_err = stderr;
781 }