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