xref: /dflybsd-src/contrib/gdb-7/gdb/symmisc.c (revision c50c785cb49e9377ca78104c5540c7b33f768771)
15796c8dcSSimon Schubert /* Do various things to symbol tables (other than lookup), for GDB.
25796c8dcSSimon Schubert 
35796c8dcSSimon Schubert    Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4*c50c785cSJohn Marino    1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2007, 2008, 2009, 2010,
5*c50c785cSJohn Marino    2011 Free Software Foundation, Inc.
65796c8dcSSimon Schubert 
75796c8dcSSimon Schubert    This file is part of GDB.
85796c8dcSSimon Schubert 
95796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
105796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
115796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
125796c8dcSSimon Schubert    (at your option) any later version.
135796c8dcSSimon Schubert 
145796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
155796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
165796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
175796c8dcSSimon Schubert    GNU General Public License for more details.
185796c8dcSSimon Schubert 
195796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
205796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
215796c8dcSSimon Schubert 
225796c8dcSSimon Schubert #include "defs.h"
235796c8dcSSimon Schubert #include "symtab.h"
245796c8dcSSimon Schubert #include "gdbtypes.h"
255796c8dcSSimon Schubert #include "bfd.h"
26*c50c785cSJohn Marino #include "filenames.h"
275796c8dcSSimon Schubert #include "symfile.h"
285796c8dcSSimon Schubert #include "objfiles.h"
295796c8dcSSimon Schubert #include "breakpoint.h"
305796c8dcSSimon Schubert #include "command.h"
315796c8dcSSimon Schubert #include "gdb_obstack.h"
325796c8dcSSimon Schubert #include "exceptions.h"
335796c8dcSSimon Schubert #include "language.h"
345796c8dcSSimon Schubert #include "bcache.h"
355796c8dcSSimon Schubert #include "block.h"
365796c8dcSSimon Schubert #include "gdb_regex.h"
375796c8dcSSimon Schubert #include "gdb_stat.h"
385796c8dcSSimon Schubert #include "dictionary.h"
395796c8dcSSimon Schubert 
405796c8dcSSimon Schubert #include "gdb_string.h"
415796c8dcSSimon Schubert #include "readline/readline.h"
425796c8dcSSimon Schubert 
43cf7f2e2dSJohn Marino #include "psymtab.h"
44cf7f2e2dSJohn Marino 
455796c8dcSSimon Schubert #ifndef DEV_TTY
465796c8dcSSimon Schubert #define DEV_TTY "/dev/tty"
475796c8dcSSimon Schubert #endif
485796c8dcSSimon Schubert 
495796c8dcSSimon Schubert /* Unfortunately for debugging, stderr is usually a macro.  This is painful
505796c8dcSSimon Schubert    when calling functions that take FILE *'s from the debugger.
515796c8dcSSimon Schubert    So we make a variable which has the same value and which is accessible when
525796c8dcSSimon Schubert    debugging GDB with itself.  Because stdin et al need not be constants,
535796c8dcSSimon Schubert    we initialize them in the _initialize_symmisc function at the bottom
545796c8dcSSimon Schubert    of the file.  */
555796c8dcSSimon Schubert FILE *std_in;
565796c8dcSSimon Schubert FILE *std_out;
575796c8dcSSimon Schubert FILE *std_err;
585796c8dcSSimon Schubert 
595796c8dcSSimon Schubert /* Prototypes for local functions */
605796c8dcSSimon Schubert 
615796c8dcSSimon Schubert static void dump_symtab (struct objfile *, struct symtab *,
625796c8dcSSimon Schubert 			 struct ui_file *);
635796c8dcSSimon Schubert 
645796c8dcSSimon Schubert static void dump_msymbols (struct objfile *, struct ui_file *);
655796c8dcSSimon Schubert 
665796c8dcSSimon Schubert static void dump_objfile (struct objfile *);
675796c8dcSSimon Schubert 
685796c8dcSSimon Schubert static int block_depth (struct block *);
695796c8dcSSimon Schubert 
705796c8dcSSimon Schubert void _initialize_symmisc (void);
715796c8dcSSimon Schubert 
725796c8dcSSimon Schubert struct print_symbol_args
735796c8dcSSimon Schubert   {
745796c8dcSSimon Schubert     struct gdbarch *gdbarch;
755796c8dcSSimon Schubert     struct symbol *symbol;
765796c8dcSSimon Schubert     int depth;
775796c8dcSSimon Schubert     struct ui_file *outfile;
785796c8dcSSimon Schubert   };
795796c8dcSSimon Schubert 
805796c8dcSSimon Schubert static int print_symbol (void *);
815796c8dcSSimon Schubert 
825796c8dcSSimon Schubert /* Free all the storage associated with the struct symtab <- S.
835796c8dcSSimon Schubert    Note that some symtabs have contents that all live inside one big block of
845796c8dcSSimon Schubert    memory, and some share the contents of another symbol table and so you
855796c8dcSSimon Schubert    should not free the contents on their behalf (except sometimes the
865796c8dcSSimon Schubert    linetable, which maybe per symtab even when the rest is not).
875796c8dcSSimon Schubert    It is s->free_code that says which alternative to use.  */
885796c8dcSSimon Schubert 
895796c8dcSSimon Schubert void
905796c8dcSSimon Schubert free_symtab (struct symtab *s)
915796c8dcSSimon Schubert {
925796c8dcSSimon Schubert   switch (s->free_code)
935796c8dcSSimon Schubert     {
945796c8dcSSimon Schubert     case free_nothing:
955796c8dcSSimon Schubert       /* All the contents are part of a big block of memory (an obstack),
965796c8dcSSimon Schubert          and some other symtab is in charge of freeing that block.
975796c8dcSSimon Schubert          Therefore, do nothing.  */
985796c8dcSSimon Schubert       break;
995796c8dcSSimon Schubert 
1005796c8dcSSimon Schubert     case free_linetable:
1015796c8dcSSimon Schubert       /* Everything will be freed either by our `free_func'
1025796c8dcSSimon Schubert          or by some other symtab, except for our linetable.
1035796c8dcSSimon Schubert          Free that now.  */
1045796c8dcSSimon Schubert       if (LINETABLE (s))
1055796c8dcSSimon Schubert 	xfree (LINETABLE (s));
1065796c8dcSSimon Schubert       break;
1075796c8dcSSimon Schubert     }
1085796c8dcSSimon Schubert 
1095796c8dcSSimon Schubert   /* If there is a single block of memory to free, free it.  */
1105796c8dcSSimon Schubert   if (s->free_func != NULL)
1115796c8dcSSimon Schubert     s->free_func (s);
1125796c8dcSSimon Schubert 
113*c50c785cSJohn Marino   /* Free source-related stuff.  */
1145796c8dcSSimon Schubert   if (s->line_charpos != NULL)
1155796c8dcSSimon Schubert     xfree (s->line_charpos);
1165796c8dcSSimon Schubert   if (s->fullname != NULL)
1175796c8dcSSimon Schubert     xfree (s->fullname);
1185796c8dcSSimon Schubert   if (s->debugformat != NULL)
1195796c8dcSSimon Schubert     xfree (s->debugformat);
1205796c8dcSSimon Schubert   xfree (s);
1215796c8dcSSimon Schubert }
1225796c8dcSSimon Schubert 
1235796c8dcSSimon Schubert void
1245796c8dcSSimon Schubert print_symbol_bcache_statistics (void)
1255796c8dcSSimon Schubert {
126cf7f2e2dSJohn Marino   struct program_space *pspace;
1275796c8dcSSimon Schubert   struct objfile *objfile;
1285796c8dcSSimon Schubert 
1295796c8dcSSimon Schubert   immediate_quit++;
130cf7f2e2dSJohn Marino   ALL_PSPACES (pspace)
131cf7f2e2dSJohn Marino     ALL_PSPACE_OBJFILES (pspace, objfile)
1325796c8dcSSimon Schubert   {
1335796c8dcSSimon Schubert     printf_filtered (_("Byte cache statistics for '%s':\n"), objfile->name);
134*c50c785cSJohn Marino     print_bcache_statistics (psymbol_bcache_get_bcache (objfile->psymbol_cache),
135*c50c785cSJohn Marino                              "partial symbol cache");
1365796c8dcSSimon Schubert     print_bcache_statistics (objfile->macro_cache, "preprocessor macro cache");
137cf7f2e2dSJohn Marino     print_bcache_statistics (objfile->filename_cache, "file name cache");
1385796c8dcSSimon Schubert   }
1395796c8dcSSimon Schubert   immediate_quit--;
1405796c8dcSSimon Schubert }
1415796c8dcSSimon Schubert 
1425796c8dcSSimon Schubert void
1435796c8dcSSimon Schubert print_objfile_statistics (void)
1445796c8dcSSimon Schubert {
145cf7f2e2dSJohn Marino   struct program_space *pspace;
1465796c8dcSSimon Schubert   struct objfile *objfile;
1475796c8dcSSimon Schubert   struct symtab *s;
1485796c8dcSSimon Schubert   int i, linetables, blockvectors;
1495796c8dcSSimon Schubert 
1505796c8dcSSimon Schubert   immediate_quit++;
151cf7f2e2dSJohn Marino   ALL_PSPACES (pspace)
152cf7f2e2dSJohn Marino     ALL_PSPACE_OBJFILES (pspace, objfile)
1535796c8dcSSimon Schubert   {
1545796c8dcSSimon Schubert     printf_filtered (_("Statistics for '%s':\n"), objfile->name);
1555796c8dcSSimon Schubert     if (OBJSTAT (objfile, n_stabs) > 0)
1565796c8dcSSimon Schubert       printf_filtered (_("  Number of \"stab\" symbols read: %d\n"),
1575796c8dcSSimon Schubert 		       OBJSTAT (objfile, n_stabs));
1585796c8dcSSimon Schubert     if (OBJSTAT (objfile, n_minsyms) > 0)
1595796c8dcSSimon Schubert       printf_filtered (_("  Number of \"minimal\" symbols read: %d\n"),
1605796c8dcSSimon Schubert 		       OBJSTAT (objfile, n_minsyms));
1615796c8dcSSimon Schubert     if (OBJSTAT (objfile, n_psyms) > 0)
1625796c8dcSSimon Schubert       printf_filtered (_("  Number of \"partial\" symbols read: %d\n"),
1635796c8dcSSimon Schubert 		       OBJSTAT (objfile, n_psyms));
1645796c8dcSSimon Schubert     if (OBJSTAT (objfile, n_syms) > 0)
1655796c8dcSSimon Schubert       printf_filtered (_("  Number of \"full\" symbols read: %d\n"),
1665796c8dcSSimon Schubert 		       OBJSTAT (objfile, n_syms));
1675796c8dcSSimon Schubert     if (OBJSTAT (objfile, n_types) > 0)
1685796c8dcSSimon Schubert       printf_filtered (_("  Number of \"types\" defined: %d\n"),
1695796c8dcSSimon Schubert 		       OBJSTAT (objfile, n_types));
170cf7f2e2dSJohn Marino     if (objfile->sf)
171cf7f2e2dSJohn Marino       objfile->sf->qf->print_stats (objfile);
1725796c8dcSSimon Schubert     i = linetables = blockvectors = 0;
1735796c8dcSSimon Schubert     ALL_OBJFILE_SYMTABS (objfile, s)
1745796c8dcSSimon Schubert       {
1755796c8dcSSimon Schubert         i++;
1765796c8dcSSimon Schubert         if (s->linetable != NULL)
1775796c8dcSSimon Schubert           linetables++;
1785796c8dcSSimon Schubert         if (s->primary == 1)
1795796c8dcSSimon Schubert           blockvectors++;
1805796c8dcSSimon Schubert       }
1815796c8dcSSimon Schubert     printf_filtered (_("  Number of symbol tables: %d\n"), i);
1825796c8dcSSimon Schubert     printf_filtered (_("  Number of symbol tables with line tables: %d\n"),
1835796c8dcSSimon Schubert                      linetables);
1845796c8dcSSimon Schubert     printf_filtered (_("  Number of symbol tables with blockvectors: %d\n"),
1855796c8dcSSimon Schubert                      blockvectors);
1865796c8dcSSimon Schubert 
1875796c8dcSSimon Schubert     if (OBJSTAT (objfile, sz_strtab) > 0)
1885796c8dcSSimon Schubert       printf_filtered (_("  Space used by a.out string tables: %d\n"),
1895796c8dcSSimon Schubert 		       OBJSTAT (objfile, sz_strtab));
1905796c8dcSSimon Schubert     printf_filtered (_("  Total memory used for objfile obstack: %d\n"),
1915796c8dcSSimon Schubert 		     obstack_memory_used (&objfile->objfile_obstack));
1925796c8dcSSimon Schubert     printf_filtered (_("  Total memory used for psymbol cache: %d\n"),
193*c50c785cSJohn Marino 		     bcache_memory_used (psymbol_bcache_get_bcache
194*c50c785cSJohn Marino 		                          (objfile->psymbol_cache)));
1955796c8dcSSimon Schubert     printf_filtered (_("  Total memory used for macro cache: %d\n"),
1965796c8dcSSimon Schubert 		     bcache_memory_used (objfile->macro_cache));
197cf7f2e2dSJohn Marino     printf_filtered (_("  Total memory used for file name cache: %d\n"),
198cf7f2e2dSJohn Marino 		     bcache_memory_used (objfile->filename_cache));
1995796c8dcSSimon Schubert   }
2005796c8dcSSimon Schubert   immediate_quit--;
2015796c8dcSSimon Schubert }
2025796c8dcSSimon Schubert 
2035796c8dcSSimon Schubert static void
2045796c8dcSSimon Schubert dump_objfile (struct objfile *objfile)
2055796c8dcSSimon Schubert {
2065796c8dcSSimon Schubert   struct symtab *symtab;
2075796c8dcSSimon Schubert 
2085796c8dcSSimon Schubert   printf_filtered ("\nObject file %s:  ", objfile->name);
2095796c8dcSSimon Schubert   printf_filtered ("Objfile at ");
2105796c8dcSSimon Schubert   gdb_print_host_address (objfile, gdb_stdout);
2115796c8dcSSimon Schubert   printf_filtered (", bfd at ");
2125796c8dcSSimon Schubert   gdb_print_host_address (objfile->obfd, gdb_stdout);
2135796c8dcSSimon Schubert   printf_filtered (", %d minsyms\n\n",
2145796c8dcSSimon Schubert 		   objfile->minimal_symbol_count);
2155796c8dcSSimon Schubert 
216cf7f2e2dSJohn Marino   if (objfile->sf)
217cf7f2e2dSJohn Marino     objfile->sf->qf->dump (objfile);
2185796c8dcSSimon Schubert 
2195796c8dcSSimon Schubert   if (objfile->symtabs)
2205796c8dcSSimon Schubert     {
2215796c8dcSSimon Schubert       printf_filtered ("Symtabs:\n");
2225796c8dcSSimon Schubert       for (symtab = objfile->symtabs;
2235796c8dcSSimon Schubert 	   symtab != NULL;
2245796c8dcSSimon Schubert 	   symtab = symtab->next)
2255796c8dcSSimon Schubert 	{
2265796c8dcSSimon Schubert 	  printf_filtered ("%s at ", symtab->filename);
2275796c8dcSSimon Schubert 	  gdb_print_host_address (symtab, gdb_stdout);
2285796c8dcSSimon Schubert 	  printf_filtered (", ");
2295796c8dcSSimon Schubert 	  if (symtab->objfile != objfile)
2305796c8dcSSimon Schubert 	    {
2315796c8dcSSimon Schubert 	      printf_filtered ("NOT ON CHAIN!  ");
2325796c8dcSSimon Schubert 	    }
2335796c8dcSSimon Schubert 	  wrap_here ("  ");
2345796c8dcSSimon Schubert 	}
2355796c8dcSSimon Schubert       printf_filtered ("\n\n");
2365796c8dcSSimon Schubert     }
2375796c8dcSSimon Schubert }
2385796c8dcSSimon Schubert 
2395796c8dcSSimon Schubert /* Print minimal symbols from this objfile.  */
2405796c8dcSSimon Schubert 
2415796c8dcSSimon Schubert static void
2425796c8dcSSimon Schubert dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
2435796c8dcSSimon Schubert {
2445796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_objfile_arch (objfile);
2455796c8dcSSimon Schubert   struct minimal_symbol *msymbol;
2465796c8dcSSimon Schubert   int index;
2475796c8dcSSimon Schubert   char ms_type;
2485796c8dcSSimon Schubert 
2495796c8dcSSimon Schubert   fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile->name);
2505796c8dcSSimon Schubert   if (objfile->minimal_symbol_count == 0)
2515796c8dcSSimon Schubert     {
2525796c8dcSSimon Schubert       fprintf_filtered (outfile, "No minimal symbols found.\n");
2535796c8dcSSimon Schubert       return;
2545796c8dcSSimon Schubert     }
2555796c8dcSSimon Schubert   index = 0;
2565796c8dcSSimon Schubert   ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
2575796c8dcSSimon Schubert     {
2585796c8dcSSimon Schubert       struct obj_section *section = SYMBOL_OBJ_SECTION (msymbol);
2595796c8dcSSimon Schubert 
2605796c8dcSSimon Schubert       switch (MSYMBOL_TYPE (msymbol))
2615796c8dcSSimon Schubert 	{
2625796c8dcSSimon Schubert 	case mst_unknown:
2635796c8dcSSimon Schubert 	  ms_type = 'u';
2645796c8dcSSimon Schubert 	  break;
2655796c8dcSSimon Schubert 	case mst_text:
2665796c8dcSSimon Schubert 	  ms_type = 'T';
2675796c8dcSSimon Schubert 	  break;
268*c50c785cSJohn Marino 	case mst_text_gnu_ifunc:
269*c50c785cSJohn Marino 	  ms_type = 'i';
270*c50c785cSJohn Marino 	  break;
2715796c8dcSSimon Schubert 	case mst_solib_trampoline:
2725796c8dcSSimon Schubert 	  ms_type = 'S';
2735796c8dcSSimon Schubert 	  break;
2745796c8dcSSimon Schubert 	case mst_data:
2755796c8dcSSimon Schubert 	  ms_type = 'D';
2765796c8dcSSimon Schubert 	  break;
2775796c8dcSSimon Schubert 	case mst_bss:
2785796c8dcSSimon Schubert 	  ms_type = 'B';
2795796c8dcSSimon Schubert 	  break;
2805796c8dcSSimon Schubert 	case mst_abs:
2815796c8dcSSimon Schubert 	  ms_type = 'A';
2825796c8dcSSimon Schubert 	  break;
2835796c8dcSSimon Schubert 	case mst_file_text:
2845796c8dcSSimon Schubert 	  ms_type = 't';
2855796c8dcSSimon Schubert 	  break;
2865796c8dcSSimon Schubert 	case mst_file_data:
2875796c8dcSSimon Schubert 	  ms_type = 'd';
2885796c8dcSSimon Schubert 	  break;
2895796c8dcSSimon Schubert 	case mst_file_bss:
2905796c8dcSSimon Schubert 	  ms_type = 'b';
2915796c8dcSSimon Schubert 	  break;
2925796c8dcSSimon Schubert 	default:
2935796c8dcSSimon Schubert 	  ms_type = '?';
2945796c8dcSSimon Schubert 	  break;
2955796c8dcSSimon Schubert 	}
2965796c8dcSSimon Schubert       fprintf_filtered (outfile, "[%2d] %c ", index, ms_type);
2975796c8dcSSimon Schubert       fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (msymbol)),
2985796c8dcSSimon Schubert 		      outfile);
2995796c8dcSSimon Schubert       fprintf_filtered (outfile, " %s", SYMBOL_LINKAGE_NAME (msymbol));
3005796c8dcSSimon Schubert       if (section)
3015796c8dcSSimon Schubert 	fprintf_filtered (outfile, " section %s",
3025796c8dcSSimon Schubert 			  bfd_section_name (objfile->obfd,
3035796c8dcSSimon Schubert 					    section->the_bfd_section));
3045796c8dcSSimon Schubert       if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
3055796c8dcSSimon Schubert 	{
3065796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "  %s", SYMBOL_DEMANGLED_NAME (msymbol));
3075796c8dcSSimon Schubert 	}
3085796c8dcSSimon Schubert       if (msymbol->filename)
3095796c8dcSSimon Schubert 	fprintf_filtered (outfile, "  %s", msymbol->filename);
3105796c8dcSSimon Schubert       fputs_filtered ("\n", outfile);
3115796c8dcSSimon Schubert       index++;
3125796c8dcSSimon Schubert     }
3135796c8dcSSimon Schubert   if (objfile->minimal_symbol_count != index)
3145796c8dcSSimon Schubert     {
3155796c8dcSSimon Schubert       warning (_("internal error:  minimal symbol count %d != %d"),
3165796c8dcSSimon Schubert 	       objfile->minimal_symbol_count, index);
3175796c8dcSSimon Schubert     }
3185796c8dcSSimon Schubert   fprintf_filtered (outfile, "\n");
3195796c8dcSSimon Schubert }
3205796c8dcSSimon Schubert 
3215796c8dcSSimon Schubert static void
3225796c8dcSSimon Schubert dump_symtab_1 (struct objfile *objfile, struct symtab *symtab,
3235796c8dcSSimon Schubert 	       struct ui_file *outfile)
3245796c8dcSSimon Schubert {
3255796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_objfile_arch (objfile);
3265796c8dcSSimon Schubert   int i;
3275796c8dcSSimon Schubert   struct dict_iterator iter;
328cf7f2e2dSJohn Marino   int len;
3295796c8dcSSimon Schubert   struct linetable *l;
3305796c8dcSSimon Schubert   struct blockvector *bv;
3315796c8dcSSimon Schubert   struct symbol *sym;
3325796c8dcSSimon Schubert   struct block *b;
3335796c8dcSSimon Schubert   int depth;
3345796c8dcSSimon Schubert 
3355796c8dcSSimon Schubert   fprintf_filtered (outfile, "\nSymtab for file %s\n", symtab->filename);
3365796c8dcSSimon Schubert   if (symtab->dirname)
3375796c8dcSSimon Schubert     fprintf_filtered (outfile, "Compilation directory is %s\n",
3385796c8dcSSimon Schubert 		      symtab->dirname);
3395796c8dcSSimon Schubert   fprintf_filtered (outfile, "Read from object file %s (", objfile->name);
3405796c8dcSSimon Schubert   gdb_print_host_address (objfile, outfile);
3415796c8dcSSimon Schubert   fprintf_filtered (outfile, ")\n");
342*c50c785cSJohn Marino   fprintf_filtered (outfile, "Language: %s\n",
343*c50c785cSJohn Marino 		    language_str (symtab->language));
3445796c8dcSSimon Schubert 
3455796c8dcSSimon Schubert   /* First print the line table.  */
3465796c8dcSSimon Schubert   l = LINETABLE (symtab);
3475796c8dcSSimon Schubert   if (l)
3485796c8dcSSimon Schubert     {
3495796c8dcSSimon Schubert       fprintf_filtered (outfile, "\nLine table:\n\n");
3505796c8dcSSimon Schubert       len = l->nitems;
3515796c8dcSSimon Schubert       for (i = 0; i < len; i++)
3525796c8dcSSimon Schubert 	{
3535796c8dcSSimon Schubert 	  fprintf_filtered (outfile, " line %d at ", l->item[i].line);
3545796c8dcSSimon Schubert 	  fputs_filtered (paddress (gdbarch, l->item[i].pc), outfile);
3555796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "\n");
3565796c8dcSSimon Schubert 	}
3575796c8dcSSimon Schubert     }
3585796c8dcSSimon Schubert   /* Now print the block info, but only for primary symtabs since we will
3595796c8dcSSimon Schubert      print lots of duplicate info otherwise.  */
3605796c8dcSSimon Schubert   if (symtab->primary)
3615796c8dcSSimon Schubert     {
3625796c8dcSSimon Schubert       fprintf_filtered (outfile, "\nBlockvector:\n\n");
3635796c8dcSSimon Schubert       bv = BLOCKVECTOR (symtab);
3645796c8dcSSimon Schubert       len = BLOCKVECTOR_NBLOCKS (bv);
3655796c8dcSSimon Schubert       for (i = 0; i < len; i++)
3665796c8dcSSimon Schubert 	{
3675796c8dcSSimon Schubert 	  b = BLOCKVECTOR_BLOCK (bv, i);
3685796c8dcSSimon Schubert 	  depth = block_depth (b) * 2;
3695796c8dcSSimon Schubert 	  print_spaces (depth, outfile);
3705796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "block #%03d, object at ", i);
3715796c8dcSSimon Schubert 	  gdb_print_host_address (b, outfile);
3725796c8dcSSimon Schubert 	  if (BLOCK_SUPERBLOCK (b))
3735796c8dcSSimon Schubert 	    {
3745796c8dcSSimon Schubert 	      fprintf_filtered (outfile, " under ");
3755796c8dcSSimon Schubert 	      gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile);
3765796c8dcSSimon Schubert 	    }
3775796c8dcSSimon Schubert 	  /* drow/2002-07-10: We could save the total symbols count
3785796c8dcSSimon Schubert 	     even if we're using a hashtable, but nothing else but this message
3795796c8dcSSimon Schubert 	     wants it.  */
3805796c8dcSSimon Schubert 	  fprintf_filtered (outfile, ", %d syms/buckets in ",
3815796c8dcSSimon Schubert 			    dict_size (BLOCK_DICT (b)));
3825796c8dcSSimon Schubert 	  fputs_filtered (paddress (gdbarch, BLOCK_START (b)), outfile);
3835796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "..");
3845796c8dcSSimon Schubert 	  fputs_filtered (paddress (gdbarch, BLOCK_END (b)), outfile);
3855796c8dcSSimon Schubert 	  if (BLOCK_FUNCTION (b))
3865796c8dcSSimon Schubert 	    {
3875796c8dcSSimon Schubert 	      fprintf_filtered (outfile, ", function %s",
3885796c8dcSSimon Schubert 				SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b)));
3895796c8dcSSimon Schubert 	      if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
3905796c8dcSSimon Schubert 		{
3915796c8dcSSimon Schubert 		  fprintf_filtered (outfile, ", %s",
3925796c8dcSSimon Schubert 				SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
3935796c8dcSSimon Schubert 		}
3945796c8dcSSimon Schubert 	    }
3955796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "\n");
3965796c8dcSSimon Schubert 	  /* Now print each symbol in this block (in no particular order, if
3975796c8dcSSimon Schubert 	     we're using a hashtable).  */
3985796c8dcSSimon Schubert 	  ALL_BLOCK_SYMBOLS (b, iter, sym)
3995796c8dcSSimon Schubert 	    {
4005796c8dcSSimon Schubert 	      struct print_symbol_args s;
401cf7f2e2dSJohn Marino 
4025796c8dcSSimon Schubert 	      s.gdbarch = gdbarch;
4035796c8dcSSimon Schubert 	      s.symbol = sym;
4045796c8dcSSimon Schubert 	      s.depth = depth + 1;
4055796c8dcSSimon Schubert 	      s.outfile = outfile;
4065796c8dcSSimon Schubert 	      catch_errors (print_symbol, &s, "Error printing symbol:\n",
4075796c8dcSSimon Schubert 			    RETURN_MASK_ERROR);
4085796c8dcSSimon Schubert 	    }
4095796c8dcSSimon Schubert 	}
4105796c8dcSSimon Schubert       fprintf_filtered (outfile, "\n");
4115796c8dcSSimon Schubert     }
4125796c8dcSSimon Schubert   else
4135796c8dcSSimon Schubert     {
4145796c8dcSSimon Schubert       fprintf_filtered (outfile, "\nBlockvector same as previous symtab\n\n");
4155796c8dcSSimon Schubert     }
4165796c8dcSSimon Schubert }
4175796c8dcSSimon Schubert 
4185796c8dcSSimon Schubert static void
4195796c8dcSSimon Schubert dump_symtab (struct objfile *objfile, struct symtab *symtab,
4205796c8dcSSimon Schubert 	     struct ui_file *outfile)
4215796c8dcSSimon Schubert {
4225796c8dcSSimon Schubert   /* Set the current language to the language of the symtab we're dumping
4235796c8dcSSimon Schubert      because certain routines used during dump_symtab() use the current
4245796c8dcSSimon Schubert      language to print an image of the symbol.  We'll restore it later.
4255796c8dcSSimon Schubert      But use only real languages, not placeholders.  */
4265796c8dcSSimon Schubert   if (symtab->language != language_unknown
4275796c8dcSSimon Schubert       && symtab->language != language_auto)
4285796c8dcSSimon Schubert     {
4295796c8dcSSimon Schubert       enum language saved_lang;
4305796c8dcSSimon Schubert 
4315796c8dcSSimon Schubert       saved_lang = set_language (symtab->language);
4325796c8dcSSimon Schubert 
4335796c8dcSSimon Schubert       dump_symtab_1 (objfile, symtab, outfile);
4345796c8dcSSimon Schubert 
4355796c8dcSSimon Schubert       set_language (saved_lang);
4365796c8dcSSimon Schubert     }
4375796c8dcSSimon Schubert   else
4385796c8dcSSimon Schubert     dump_symtab_1 (objfile, symtab, outfile);
4395796c8dcSSimon Schubert }
4405796c8dcSSimon Schubert 
4415796c8dcSSimon Schubert void
4425796c8dcSSimon Schubert maintenance_print_symbols (char *args, int from_tty)
4435796c8dcSSimon Schubert {
4445796c8dcSSimon Schubert   char **argv;
4455796c8dcSSimon Schubert   struct ui_file *outfile;
4465796c8dcSSimon Schubert   struct cleanup *cleanups;
4475796c8dcSSimon Schubert   char *symname = NULL;
4485796c8dcSSimon Schubert   char *filename = DEV_TTY;
4495796c8dcSSimon Schubert   struct objfile *objfile;
4505796c8dcSSimon Schubert   struct symtab *s;
4515796c8dcSSimon Schubert 
4525796c8dcSSimon Schubert   dont_repeat ();
4535796c8dcSSimon Schubert 
4545796c8dcSSimon Schubert   if (args == NULL)
4555796c8dcSSimon Schubert     {
456*c50c785cSJohn Marino       error (_("Arguments missing: an output file name "
457*c50c785cSJohn Marino 	       "and an optional symbol file name"));
4585796c8dcSSimon Schubert     }
4595796c8dcSSimon Schubert   argv = gdb_buildargv (args);
4605796c8dcSSimon Schubert   cleanups = make_cleanup_freeargv (argv);
4615796c8dcSSimon Schubert 
4625796c8dcSSimon Schubert   if (argv[0] != NULL)
4635796c8dcSSimon Schubert     {
4645796c8dcSSimon Schubert       filename = argv[0];
465*c50c785cSJohn Marino       /* If a second arg is supplied, it is a source file name to match on.  */
4665796c8dcSSimon Schubert       if (argv[1] != NULL)
4675796c8dcSSimon Schubert 	{
4685796c8dcSSimon Schubert 	  symname = argv[1];
4695796c8dcSSimon Schubert 	}
4705796c8dcSSimon Schubert     }
4715796c8dcSSimon Schubert 
4725796c8dcSSimon Schubert   filename = tilde_expand (filename);
4735796c8dcSSimon Schubert   make_cleanup (xfree, filename);
4745796c8dcSSimon Schubert 
4755796c8dcSSimon Schubert   outfile = gdb_fopen (filename, FOPEN_WT);
4765796c8dcSSimon Schubert   if (outfile == 0)
4775796c8dcSSimon Schubert     perror_with_name (filename);
4785796c8dcSSimon Schubert   make_cleanup_ui_file_delete (outfile);
4795796c8dcSSimon Schubert 
4805796c8dcSSimon Schubert   immediate_quit++;
4815796c8dcSSimon Schubert   ALL_SYMTABS (objfile, s)
482*c50c785cSJohn Marino     if (symname == NULL || filename_cmp (symname, s->filename) == 0)
4835796c8dcSSimon Schubert     dump_symtab (objfile, s, outfile);
4845796c8dcSSimon Schubert   immediate_quit--;
4855796c8dcSSimon Schubert   do_cleanups (cleanups);
4865796c8dcSSimon Schubert }
4875796c8dcSSimon Schubert 
4885796c8dcSSimon Schubert /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE.  ARGS->DEPTH says how
4895796c8dcSSimon Schubert    far to indent.  ARGS is really a struct print_symbol_args *, but is
4905796c8dcSSimon Schubert    declared as char * to get it past catch_errors.  Returns 0 for error,
4915796c8dcSSimon Schubert    1 for success.  */
4925796c8dcSSimon Schubert 
4935796c8dcSSimon Schubert static int
4945796c8dcSSimon Schubert print_symbol (void *args)
4955796c8dcSSimon Schubert {
4965796c8dcSSimon Schubert   struct gdbarch *gdbarch = ((struct print_symbol_args *) args)->gdbarch;
4975796c8dcSSimon Schubert   struct symbol *symbol = ((struct print_symbol_args *) args)->symbol;
4985796c8dcSSimon Schubert   int depth = ((struct print_symbol_args *) args)->depth;
4995796c8dcSSimon Schubert   struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile;
5005796c8dcSSimon Schubert   struct obj_section *section = SYMBOL_OBJ_SECTION (symbol);
5015796c8dcSSimon Schubert 
5025796c8dcSSimon Schubert   print_spaces (depth, outfile);
5035796c8dcSSimon Schubert   if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN)
5045796c8dcSSimon Schubert     {
5055796c8dcSSimon Schubert       fprintf_filtered (outfile, "label %s at ", SYMBOL_PRINT_NAME (symbol));
5065796c8dcSSimon Schubert       fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
5075796c8dcSSimon Schubert 		      outfile);
5085796c8dcSSimon Schubert       if (section)
5095796c8dcSSimon Schubert 	fprintf_filtered (outfile, " section %s\n",
5105796c8dcSSimon Schubert 			  bfd_section_name (section->the_bfd_section->owner,
5115796c8dcSSimon Schubert 					    section->the_bfd_section));
5125796c8dcSSimon Schubert       else
5135796c8dcSSimon Schubert 	fprintf_filtered (outfile, "\n");
5145796c8dcSSimon Schubert       return 1;
5155796c8dcSSimon Schubert     }
5165796c8dcSSimon Schubert   if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN)
5175796c8dcSSimon Schubert     {
5185796c8dcSSimon Schubert       if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
5195796c8dcSSimon Schubert 	{
5205796c8dcSSimon Schubert 	  LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
5215796c8dcSSimon Schubert 	}
5225796c8dcSSimon Schubert       else
5235796c8dcSSimon Schubert 	{
5245796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "%s %s = ",
5255796c8dcSSimon Schubert 			 (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
5265796c8dcSSimon Schubert 			  ? "enum"
5275796c8dcSSimon Schubert 		     : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
5285796c8dcSSimon Schubert 			? "struct" : "union")),
5295796c8dcSSimon Schubert 			    SYMBOL_LINKAGE_NAME (symbol));
5305796c8dcSSimon Schubert 	  LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
5315796c8dcSSimon Schubert 	}
5325796c8dcSSimon Schubert       fprintf_filtered (outfile, ";\n");
5335796c8dcSSimon Schubert     }
5345796c8dcSSimon Schubert   else
5355796c8dcSSimon Schubert     {
5365796c8dcSSimon Schubert       if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
5375796c8dcSSimon Schubert 	fprintf_filtered (outfile, "typedef ");
5385796c8dcSSimon Schubert       if (SYMBOL_TYPE (symbol))
5395796c8dcSSimon Schubert 	{
5405796c8dcSSimon Schubert 	  /* Print details of types, except for enums where it's clutter.  */
5415796c8dcSSimon Schubert 	  LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_PRINT_NAME (symbol),
5425796c8dcSSimon Schubert 			 outfile,
5435796c8dcSSimon Schubert 			 TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
5445796c8dcSSimon Schubert 			 depth);
5455796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "; ");
5465796c8dcSSimon Schubert 	}
5475796c8dcSSimon Schubert       else
5485796c8dcSSimon Schubert 	fprintf_filtered (outfile, "%s ", SYMBOL_PRINT_NAME (symbol));
5495796c8dcSSimon Schubert 
5505796c8dcSSimon Schubert       switch (SYMBOL_CLASS (symbol))
5515796c8dcSSimon Schubert 	{
5525796c8dcSSimon Schubert 	case LOC_CONST:
5535796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "const %ld (0x%lx)",
5545796c8dcSSimon Schubert 			    SYMBOL_VALUE (symbol),
5555796c8dcSSimon Schubert 			    SYMBOL_VALUE (symbol));
5565796c8dcSSimon Schubert 	  break;
5575796c8dcSSimon Schubert 
5585796c8dcSSimon Schubert 	case LOC_CONST_BYTES:
5595796c8dcSSimon Schubert 	  {
5605796c8dcSSimon Schubert 	    unsigned i;
5615796c8dcSSimon Schubert 	    struct type *type = check_typedef (SYMBOL_TYPE (symbol));
562cf7f2e2dSJohn Marino 
5635796c8dcSSimon Schubert 	    fprintf_filtered (outfile, "const %u hex bytes:",
5645796c8dcSSimon Schubert 			      TYPE_LENGTH (type));
5655796c8dcSSimon Schubert 	    for (i = 0; i < TYPE_LENGTH (type); i++)
5665796c8dcSSimon Schubert 	      fprintf_filtered (outfile, " %02x",
5675796c8dcSSimon Schubert 				(unsigned) SYMBOL_VALUE_BYTES (symbol)[i]);
5685796c8dcSSimon Schubert 	  }
5695796c8dcSSimon Schubert 	  break;
5705796c8dcSSimon Schubert 
5715796c8dcSSimon Schubert 	case LOC_STATIC:
5725796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "static at ");
5735796c8dcSSimon Schubert 	  fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
5745796c8dcSSimon Schubert 			  outfile);
5755796c8dcSSimon Schubert 	  if (section)
5765796c8dcSSimon Schubert 	    fprintf_filtered (outfile, " section %s",
5775796c8dcSSimon Schubert 			      bfd_section_name (section->the_bfd_section->owner,
5785796c8dcSSimon Schubert 						section->the_bfd_section));
5795796c8dcSSimon Schubert 	  break;
5805796c8dcSSimon Schubert 
5815796c8dcSSimon Schubert 	case LOC_REGISTER:
5825796c8dcSSimon Schubert 	  if (SYMBOL_IS_ARGUMENT (symbol))
5835796c8dcSSimon Schubert 	    fprintf_filtered (outfile, "parameter register %ld",
5845796c8dcSSimon Schubert 			      SYMBOL_VALUE (symbol));
5855796c8dcSSimon Schubert 	  else
5865796c8dcSSimon Schubert 	    fprintf_filtered (outfile, "register %ld", SYMBOL_VALUE (symbol));
5875796c8dcSSimon Schubert 	  break;
5885796c8dcSSimon Schubert 
5895796c8dcSSimon Schubert 	case LOC_ARG:
5905796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "arg at offset 0x%lx",
5915796c8dcSSimon Schubert 			    SYMBOL_VALUE (symbol));
5925796c8dcSSimon Schubert 	  break;
5935796c8dcSSimon Schubert 
5945796c8dcSSimon Schubert 	case LOC_REF_ARG:
5955796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "reference arg at 0x%lx", SYMBOL_VALUE (symbol));
5965796c8dcSSimon Schubert 	  break;
5975796c8dcSSimon Schubert 
5985796c8dcSSimon Schubert 	case LOC_REGPARM_ADDR:
5995796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "address parameter register %ld", SYMBOL_VALUE (symbol));
6005796c8dcSSimon Schubert 	  break;
6015796c8dcSSimon Schubert 
6025796c8dcSSimon Schubert 	case LOC_LOCAL:
6035796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "local at offset 0x%lx",
6045796c8dcSSimon Schubert 			    SYMBOL_VALUE (symbol));
6055796c8dcSSimon Schubert 	  break;
6065796c8dcSSimon Schubert 
6075796c8dcSSimon Schubert 	case LOC_TYPEDEF:
6085796c8dcSSimon Schubert 	  break;
6095796c8dcSSimon Schubert 
6105796c8dcSSimon Schubert 	case LOC_LABEL:
6115796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "label at ");
6125796c8dcSSimon Schubert 	  fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
6135796c8dcSSimon Schubert 			  outfile);
6145796c8dcSSimon Schubert 	  if (section)
6155796c8dcSSimon Schubert 	    fprintf_filtered (outfile, " section %s",
6165796c8dcSSimon Schubert 			      bfd_section_name (section->the_bfd_section->owner,
6175796c8dcSSimon Schubert 						section->the_bfd_section));
6185796c8dcSSimon Schubert 	  break;
6195796c8dcSSimon Schubert 
6205796c8dcSSimon Schubert 	case LOC_BLOCK:
6215796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "block object ");
6225796c8dcSSimon Schubert 	  gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
6235796c8dcSSimon Schubert 	  fprintf_filtered (outfile, ", ");
6245796c8dcSSimon Schubert 	  fputs_filtered (paddress (gdbarch,
6255796c8dcSSimon Schubert 				    BLOCK_START (SYMBOL_BLOCK_VALUE (symbol))),
6265796c8dcSSimon Schubert 			  outfile);
6275796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "..");
6285796c8dcSSimon Schubert 	  fputs_filtered (paddress (gdbarch,
6295796c8dcSSimon Schubert 				    BLOCK_END (SYMBOL_BLOCK_VALUE (symbol))),
6305796c8dcSSimon Schubert 			  outfile);
6315796c8dcSSimon Schubert 	  if (section)
6325796c8dcSSimon Schubert 	    fprintf_filtered (outfile, " section %s",
6335796c8dcSSimon Schubert 			      bfd_section_name (section->the_bfd_section->owner,
6345796c8dcSSimon Schubert 						section->the_bfd_section));
6355796c8dcSSimon Schubert 	  break;
6365796c8dcSSimon Schubert 
6375796c8dcSSimon Schubert 	case LOC_COMPUTED:
6385796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "computed at runtime");
6395796c8dcSSimon Schubert 	  break;
6405796c8dcSSimon Schubert 
6415796c8dcSSimon Schubert 	case LOC_UNRESOLVED:
6425796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "unresolved");
6435796c8dcSSimon Schubert 	  break;
6445796c8dcSSimon Schubert 
6455796c8dcSSimon Schubert 	case LOC_OPTIMIZED_OUT:
6465796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "optimized out");
6475796c8dcSSimon Schubert 	  break;
6485796c8dcSSimon Schubert 
6495796c8dcSSimon Schubert 	default:
6505796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "botched symbol class %x",
6515796c8dcSSimon Schubert 			    SYMBOL_CLASS (symbol));
6525796c8dcSSimon Schubert 	  break;
6535796c8dcSSimon Schubert 	}
6545796c8dcSSimon Schubert     }
6555796c8dcSSimon Schubert   fprintf_filtered (outfile, "\n");
6565796c8dcSSimon Schubert   return 1;
6575796c8dcSSimon Schubert }
6585796c8dcSSimon Schubert 
6595796c8dcSSimon Schubert void
6605796c8dcSSimon Schubert maintenance_print_msymbols (char *args, int from_tty)
6615796c8dcSSimon Schubert {
6625796c8dcSSimon Schubert   char **argv;
6635796c8dcSSimon Schubert   struct ui_file *outfile;
6645796c8dcSSimon Schubert   struct cleanup *cleanups;
6655796c8dcSSimon Schubert   char *filename = DEV_TTY;
6665796c8dcSSimon Schubert   char *symname = NULL;
667cf7f2e2dSJohn Marino   struct program_space *pspace;
6685796c8dcSSimon Schubert   struct objfile *objfile;
6695796c8dcSSimon Schubert 
6705796c8dcSSimon Schubert   struct stat sym_st, obj_st;
6715796c8dcSSimon Schubert 
6725796c8dcSSimon Schubert   dont_repeat ();
6735796c8dcSSimon Schubert 
6745796c8dcSSimon Schubert   if (args == NULL)
6755796c8dcSSimon Schubert     {
676*c50c785cSJohn Marino       error (_("print-msymbols takes an output file "
677*c50c785cSJohn Marino 	       "name and optional symbol file name"));
6785796c8dcSSimon Schubert     }
6795796c8dcSSimon Schubert   argv = gdb_buildargv (args);
6805796c8dcSSimon Schubert   cleanups = make_cleanup_freeargv (argv);
6815796c8dcSSimon Schubert 
6825796c8dcSSimon Schubert   if (argv[0] != NULL)
6835796c8dcSSimon Schubert     {
6845796c8dcSSimon Schubert       filename = argv[0];
685*c50c785cSJohn Marino       /* If a second arg is supplied, it is a source file name to match on.  */
6865796c8dcSSimon Schubert       if (argv[1] != NULL)
6875796c8dcSSimon Schubert 	{
6885796c8dcSSimon Schubert 	  symname = xfullpath (argv[1]);
6895796c8dcSSimon Schubert 	  make_cleanup (xfree, symname);
6905796c8dcSSimon Schubert 	  if (symname && stat (symname, &sym_st))
6915796c8dcSSimon Schubert 	    perror_with_name (symname);
6925796c8dcSSimon Schubert 	}
6935796c8dcSSimon Schubert     }
6945796c8dcSSimon Schubert 
6955796c8dcSSimon Schubert   filename = tilde_expand (filename);
6965796c8dcSSimon Schubert   make_cleanup (xfree, filename);
6975796c8dcSSimon Schubert 
6985796c8dcSSimon Schubert   outfile = gdb_fopen (filename, FOPEN_WT);
6995796c8dcSSimon Schubert   if (outfile == 0)
7005796c8dcSSimon Schubert     perror_with_name (filename);
7015796c8dcSSimon Schubert   make_cleanup_ui_file_delete (outfile);
7025796c8dcSSimon Schubert 
7035796c8dcSSimon Schubert   immediate_quit++;
704cf7f2e2dSJohn Marino   ALL_PSPACES (pspace)
705cf7f2e2dSJohn Marino     ALL_PSPACE_OBJFILES (pspace, objfile)
706*c50c785cSJohn Marino       if (symname == NULL || (!stat (objfile->name, &obj_st)
707*c50c785cSJohn Marino 			      && sym_st.st_ino == obj_st.st_ino))
7085796c8dcSSimon Schubert 	dump_msymbols (objfile, outfile);
7095796c8dcSSimon Schubert   immediate_quit--;
7105796c8dcSSimon Schubert   fprintf_filtered (outfile, "\n\n");
7115796c8dcSSimon Schubert   do_cleanups (cleanups);
7125796c8dcSSimon Schubert }
7135796c8dcSSimon Schubert 
7145796c8dcSSimon Schubert void
7155796c8dcSSimon Schubert maintenance_print_objfiles (char *ignore, int from_tty)
7165796c8dcSSimon Schubert {
717cf7f2e2dSJohn Marino   struct program_space *pspace;
7185796c8dcSSimon Schubert   struct objfile *objfile;
7195796c8dcSSimon Schubert 
7205796c8dcSSimon Schubert   dont_repeat ();
7215796c8dcSSimon Schubert 
7225796c8dcSSimon Schubert   immediate_quit++;
723cf7f2e2dSJohn Marino   ALL_PSPACES (pspace)
724cf7f2e2dSJohn Marino     ALL_PSPACE_OBJFILES (pspace, objfile)
7255796c8dcSSimon Schubert       dump_objfile (objfile);
7265796c8dcSSimon Schubert   immediate_quit--;
7275796c8dcSSimon Schubert }
7285796c8dcSSimon Schubert 
7295796c8dcSSimon Schubert 
7305796c8dcSSimon Schubert /* List all the symbol tables whose names match REGEXP (optional).  */
7315796c8dcSSimon Schubert void
7325796c8dcSSimon Schubert maintenance_info_symtabs (char *regexp, int from_tty)
7335796c8dcSSimon Schubert {
734cf7f2e2dSJohn Marino   struct program_space *pspace;
7355796c8dcSSimon Schubert   struct objfile *objfile;
7365796c8dcSSimon Schubert 
7375796c8dcSSimon Schubert   if (regexp)
7385796c8dcSSimon Schubert     re_comp (regexp);
7395796c8dcSSimon Schubert 
740cf7f2e2dSJohn Marino   ALL_PSPACES (pspace)
741cf7f2e2dSJohn Marino     ALL_PSPACE_OBJFILES (pspace, objfile)
7425796c8dcSSimon Schubert     {
7435796c8dcSSimon Schubert       struct symtab *symtab;
7445796c8dcSSimon Schubert 
7455796c8dcSSimon Schubert       /* We don't want to print anything for this objfile until we
7465796c8dcSSimon Schubert          actually find a symtab whose name matches.  */
7475796c8dcSSimon Schubert       int printed_objfile_start = 0;
7485796c8dcSSimon Schubert 
7495796c8dcSSimon Schubert       ALL_OBJFILE_SYMTABS (objfile, symtab)
7505796c8dcSSimon Schubert 	{
7515796c8dcSSimon Schubert 	  QUIT;
7525796c8dcSSimon Schubert 
7535796c8dcSSimon Schubert 	  if (! regexp
7545796c8dcSSimon Schubert 	      || re_exec (symtab->filename))
7555796c8dcSSimon Schubert 	    {
7565796c8dcSSimon Schubert 	      if (! printed_objfile_start)
7575796c8dcSSimon Schubert 		{
7585796c8dcSSimon Schubert 		  printf_filtered ("{ objfile %s ", objfile->name);
7595796c8dcSSimon Schubert 		  wrap_here ("  ");
7605796c8dcSSimon Schubert 		  printf_filtered ("((struct objfile *) %s)\n",
7615796c8dcSSimon Schubert 				   host_address_to_string (objfile));
7625796c8dcSSimon Schubert 		  printed_objfile_start = 1;
7635796c8dcSSimon Schubert 		}
7645796c8dcSSimon Schubert 
7655796c8dcSSimon Schubert 	      printf_filtered ("	{ symtab %s ", symtab->filename);
7665796c8dcSSimon Schubert 	      wrap_here ("    ");
7675796c8dcSSimon Schubert 	      printf_filtered ("((struct symtab *) %s)\n",
7685796c8dcSSimon Schubert 			       host_address_to_string (symtab));
7695796c8dcSSimon Schubert 	      printf_filtered ("	  dirname %s\n",
7705796c8dcSSimon Schubert 			       symtab->dirname ? symtab->dirname : "(null)");
7715796c8dcSSimon Schubert 	      printf_filtered ("	  fullname %s\n",
7725796c8dcSSimon Schubert 			       symtab->fullname ? symtab->fullname : "(null)");
773*c50c785cSJohn Marino 	      printf_filtered ("	  "
774*c50c785cSJohn Marino 			       "blockvector ((struct blockvector *) %s)%s\n",
7755796c8dcSSimon Schubert 			       host_address_to_string (symtab->blockvector),
7765796c8dcSSimon Schubert 			       symtab->primary ? " (primary)" : "");
777*c50c785cSJohn Marino 	      printf_filtered ("	  "
778*c50c785cSJohn Marino 			       "linetable ((struct linetable *) %s)\n",
7795796c8dcSSimon Schubert 			       host_address_to_string (symtab->linetable));
780*c50c785cSJohn Marino 	      printf_filtered ("	  debugformat %s\n",
781*c50c785cSJohn Marino 			       symtab->debugformat);
7825796c8dcSSimon Schubert 	      printf_filtered ("	}\n");
7835796c8dcSSimon Schubert 	    }
7845796c8dcSSimon Schubert 	}
7855796c8dcSSimon Schubert 
7865796c8dcSSimon Schubert       if (printed_objfile_start)
7875796c8dcSSimon Schubert         printf_filtered ("}\n");
7885796c8dcSSimon Schubert     }
7895796c8dcSSimon Schubert }
7905796c8dcSSimon Schubert 
7915796c8dcSSimon Schubert 
7925796c8dcSSimon Schubert /* Return the nexting depth of a block within other blocks in its symtab.  */
7935796c8dcSSimon Schubert 
7945796c8dcSSimon Schubert static int
7955796c8dcSSimon Schubert block_depth (struct block *block)
7965796c8dcSSimon Schubert {
7975796c8dcSSimon Schubert   int i = 0;
798cf7f2e2dSJohn Marino 
7995796c8dcSSimon Schubert   while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
8005796c8dcSSimon Schubert     {
8015796c8dcSSimon Schubert       i++;
8025796c8dcSSimon Schubert     }
8035796c8dcSSimon Schubert   return i;
8045796c8dcSSimon Schubert }
8055796c8dcSSimon Schubert 
8065796c8dcSSimon Schubert 
8075796c8dcSSimon Schubert /* Do early runtime initializations.  */
8085796c8dcSSimon Schubert void
8095796c8dcSSimon Schubert _initialize_symmisc (void)
8105796c8dcSSimon Schubert {
8115796c8dcSSimon Schubert   std_in = stdin;
8125796c8dcSSimon Schubert   std_out = stdout;
8135796c8dcSSimon Schubert   std_err = stderr;
8145796c8dcSSimon Schubert }
815