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