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