xref: /dflybsd-src/contrib/gdb-7/gdb/symmisc.c (revision 5796c8dc12c637f18a1740c26afd8d40ffa9b719)
1*5796c8dcSSimon Schubert /* Do various things to symbol tables (other than lookup), for GDB.
2*5796c8dcSSimon Schubert 
3*5796c8dcSSimon Schubert    Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4*5796c8dcSSimon Schubert    1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2007, 2008, 2009
5*5796c8dcSSimon Schubert    Free Software Foundation, Inc.
6*5796c8dcSSimon Schubert 
7*5796c8dcSSimon Schubert    This file is part of GDB.
8*5796c8dcSSimon Schubert 
9*5796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
10*5796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
11*5796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
12*5796c8dcSSimon Schubert    (at your option) any later version.
13*5796c8dcSSimon Schubert 
14*5796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
15*5796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
16*5796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17*5796c8dcSSimon Schubert    GNU General Public License for more details.
18*5796c8dcSSimon Schubert 
19*5796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
20*5796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
21*5796c8dcSSimon Schubert 
22*5796c8dcSSimon Schubert #include "defs.h"
23*5796c8dcSSimon Schubert #include "symtab.h"
24*5796c8dcSSimon Schubert #include "gdbtypes.h"
25*5796c8dcSSimon Schubert #include "bfd.h"
26*5796c8dcSSimon Schubert #include "symfile.h"
27*5796c8dcSSimon Schubert #include "objfiles.h"
28*5796c8dcSSimon Schubert #include "breakpoint.h"
29*5796c8dcSSimon Schubert #include "command.h"
30*5796c8dcSSimon Schubert #include "gdb_obstack.h"
31*5796c8dcSSimon Schubert #include "exceptions.h"
32*5796c8dcSSimon Schubert #include "language.h"
33*5796c8dcSSimon Schubert #include "bcache.h"
34*5796c8dcSSimon Schubert #include "block.h"
35*5796c8dcSSimon Schubert #include "gdb_regex.h"
36*5796c8dcSSimon Schubert #include "gdb_stat.h"
37*5796c8dcSSimon Schubert #include "dictionary.h"
38*5796c8dcSSimon Schubert 
39*5796c8dcSSimon Schubert #include "gdb_string.h"
40*5796c8dcSSimon Schubert #include "readline/readline.h"
41*5796c8dcSSimon Schubert 
42*5796c8dcSSimon Schubert #ifndef DEV_TTY
43*5796c8dcSSimon Schubert #define DEV_TTY "/dev/tty"
44*5796c8dcSSimon Schubert #endif
45*5796c8dcSSimon Schubert 
46*5796c8dcSSimon Schubert /* Unfortunately for debugging, stderr is usually a macro.  This is painful
47*5796c8dcSSimon Schubert    when calling functions that take FILE *'s from the debugger.
48*5796c8dcSSimon Schubert    So we make a variable which has the same value and which is accessible when
49*5796c8dcSSimon Schubert    debugging GDB with itself.  Because stdin et al need not be constants,
50*5796c8dcSSimon Schubert    we initialize them in the _initialize_symmisc function at the bottom
51*5796c8dcSSimon Schubert    of the file.  */
52*5796c8dcSSimon Schubert FILE *std_in;
53*5796c8dcSSimon Schubert FILE *std_out;
54*5796c8dcSSimon Schubert FILE *std_err;
55*5796c8dcSSimon Schubert 
56*5796c8dcSSimon Schubert /* Prototypes for local functions */
57*5796c8dcSSimon Schubert 
58*5796c8dcSSimon Schubert static void dump_symtab (struct objfile *, struct symtab *,
59*5796c8dcSSimon Schubert 			 struct ui_file *);
60*5796c8dcSSimon Schubert 
61*5796c8dcSSimon Schubert static void dump_psymtab (struct objfile *, struct partial_symtab *,
62*5796c8dcSSimon Schubert 			  struct ui_file *);
63*5796c8dcSSimon Schubert 
64*5796c8dcSSimon Schubert static void dump_msymbols (struct objfile *, struct ui_file *);
65*5796c8dcSSimon Schubert 
66*5796c8dcSSimon Schubert static void dump_objfile (struct objfile *);
67*5796c8dcSSimon Schubert 
68*5796c8dcSSimon Schubert static int block_depth (struct block *);
69*5796c8dcSSimon Schubert 
70*5796c8dcSSimon Schubert static void print_partial_symbols (struct gdbarch *,
71*5796c8dcSSimon Schubert 				   struct partial_symbol **, int,
72*5796c8dcSSimon Schubert 				   char *, struct ui_file *);
73*5796c8dcSSimon Schubert 
74*5796c8dcSSimon Schubert void _initialize_symmisc (void);
75*5796c8dcSSimon Schubert 
76*5796c8dcSSimon Schubert struct print_symbol_args
77*5796c8dcSSimon Schubert   {
78*5796c8dcSSimon Schubert     struct gdbarch *gdbarch;
79*5796c8dcSSimon Schubert     struct symbol *symbol;
80*5796c8dcSSimon Schubert     int depth;
81*5796c8dcSSimon Schubert     struct ui_file *outfile;
82*5796c8dcSSimon Schubert   };
83*5796c8dcSSimon Schubert 
84*5796c8dcSSimon Schubert static int print_symbol (void *);
85*5796c8dcSSimon Schubert 
86*5796c8dcSSimon Schubert /* Free all the storage associated with the struct symtab <- S.
87*5796c8dcSSimon Schubert    Note that some symtabs have contents that all live inside one big block of
88*5796c8dcSSimon Schubert    memory, and some share the contents of another symbol table and so you
89*5796c8dcSSimon Schubert    should not free the contents on their behalf (except sometimes the
90*5796c8dcSSimon Schubert    linetable, which maybe per symtab even when the rest is not).
91*5796c8dcSSimon Schubert    It is s->free_code that says which alternative to use.  */
92*5796c8dcSSimon Schubert 
93*5796c8dcSSimon Schubert void
94*5796c8dcSSimon Schubert free_symtab (struct symtab *s)
95*5796c8dcSSimon Schubert {
96*5796c8dcSSimon Schubert   int i, n;
97*5796c8dcSSimon Schubert   struct blockvector *bv;
98*5796c8dcSSimon Schubert 
99*5796c8dcSSimon Schubert   switch (s->free_code)
100*5796c8dcSSimon Schubert     {
101*5796c8dcSSimon Schubert     case free_nothing:
102*5796c8dcSSimon Schubert       /* All the contents are part of a big block of memory (an obstack),
103*5796c8dcSSimon Schubert          and some other symtab is in charge of freeing that block.
104*5796c8dcSSimon Schubert          Therefore, do nothing.  */
105*5796c8dcSSimon Schubert       break;
106*5796c8dcSSimon Schubert 
107*5796c8dcSSimon Schubert     case free_linetable:
108*5796c8dcSSimon Schubert       /* Everything will be freed either by our `free_func'
109*5796c8dcSSimon Schubert          or by some other symtab, except for our linetable.
110*5796c8dcSSimon Schubert          Free that now.  */
111*5796c8dcSSimon Schubert       if (LINETABLE (s))
112*5796c8dcSSimon Schubert 	xfree (LINETABLE (s));
113*5796c8dcSSimon Schubert       break;
114*5796c8dcSSimon Schubert     }
115*5796c8dcSSimon Schubert 
116*5796c8dcSSimon Schubert   /* If there is a single block of memory to free, free it.  */
117*5796c8dcSSimon Schubert   if (s->free_func != NULL)
118*5796c8dcSSimon Schubert     s->free_func (s);
119*5796c8dcSSimon Schubert 
120*5796c8dcSSimon Schubert   /* Free source-related stuff */
121*5796c8dcSSimon Schubert   if (s->line_charpos != NULL)
122*5796c8dcSSimon Schubert     xfree (s->line_charpos);
123*5796c8dcSSimon Schubert   if (s->fullname != NULL)
124*5796c8dcSSimon Schubert     xfree (s->fullname);
125*5796c8dcSSimon Schubert   if (s->debugformat != NULL)
126*5796c8dcSSimon Schubert     xfree (s->debugformat);
127*5796c8dcSSimon Schubert   xfree (s);
128*5796c8dcSSimon Schubert }
129*5796c8dcSSimon Schubert 
130*5796c8dcSSimon Schubert void
131*5796c8dcSSimon Schubert print_symbol_bcache_statistics (void)
132*5796c8dcSSimon Schubert {
133*5796c8dcSSimon Schubert   struct objfile *objfile;
134*5796c8dcSSimon Schubert 
135*5796c8dcSSimon Schubert   immediate_quit++;
136*5796c8dcSSimon Schubert   ALL_OBJFILES (objfile)
137*5796c8dcSSimon Schubert   {
138*5796c8dcSSimon Schubert     printf_filtered (_("Byte cache statistics for '%s':\n"), objfile->name);
139*5796c8dcSSimon Schubert     print_bcache_statistics (objfile->psymbol_cache, "partial symbol cache");
140*5796c8dcSSimon Schubert     print_bcache_statistics (objfile->macro_cache, "preprocessor macro cache");
141*5796c8dcSSimon Schubert   }
142*5796c8dcSSimon Schubert   immediate_quit--;
143*5796c8dcSSimon Schubert }
144*5796c8dcSSimon Schubert 
145*5796c8dcSSimon Schubert void
146*5796c8dcSSimon Schubert print_objfile_statistics (void)
147*5796c8dcSSimon Schubert {
148*5796c8dcSSimon Schubert   struct objfile *objfile;
149*5796c8dcSSimon Schubert   struct symtab *s;
150*5796c8dcSSimon Schubert   struct partial_symtab *ps;
151*5796c8dcSSimon Schubert   int i, linetables, blockvectors;
152*5796c8dcSSimon Schubert 
153*5796c8dcSSimon Schubert   immediate_quit++;
154*5796c8dcSSimon Schubert   ALL_OBJFILES (objfile)
155*5796c8dcSSimon Schubert   {
156*5796c8dcSSimon Schubert     printf_filtered (_("Statistics for '%s':\n"), objfile->name);
157*5796c8dcSSimon Schubert     if (OBJSTAT (objfile, n_stabs) > 0)
158*5796c8dcSSimon Schubert       printf_filtered (_("  Number of \"stab\" symbols read: %d\n"),
159*5796c8dcSSimon Schubert 		       OBJSTAT (objfile, n_stabs));
160*5796c8dcSSimon Schubert     if (OBJSTAT (objfile, n_minsyms) > 0)
161*5796c8dcSSimon Schubert       printf_filtered (_("  Number of \"minimal\" symbols read: %d\n"),
162*5796c8dcSSimon Schubert 		       OBJSTAT (objfile, n_minsyms));
163*5796c8dcSSimon Schubert     if (OBJSTAT (objfile, n_psyms) > 0)
164*5796c8dcSSimon Schubert       printf_filtered (_("  Number of \"partial\" symbols read: %d\n"),
165*5796c8dcSSimon Schubert 		       OBJSTAT (objfile, n_psyms));
166*5796c8dcSSimon Schubert     if (OBJSTAT (objfile, n_syms) > 0)
167*5796c8dcSSimon Schubert       printf_filtered (_("  Number of \"full\" symbols read: %d\n"),
168*5796c8dcSSimon Schubert 		       OBJSTAT (objfile, n_syms));
169*5796c8dcSSimon Schubert     if (OBJSTAT (objfile, n_types) > 0)
170*5796c8dcSSimon Schubert       printf_filtered (_("  Number of \"types\" defined: %d\n"),
171*5796c8dcSSimon Schubert 		       OBJSTAT (objfile, n_types));
172*5796c8dcSSimon Schubert     i = 0;
173*5796c8dcSSimon Schubert     ALL_OBJFILE_PSYMTABS (objfile, ps)
174*5796c8dcSSimon Schubert       {
175*5796c8dcSSimon Schubert         if (ps->readin == 0)
176*5796c8dcSSimon Schubert           i++;
177*5796c8dcSSimon Schubert       }
178*5796c8dcSSimon Schubert     printf_filtered (_("  Number of psym tables (not yet expanded): %d\n"), i);
179*5796c8dcSSimon Schubert     i = linetables = blockvectors = 0;
180*5796c8dcSSimon Schubert     ALL_OBJFILE_SYMTABS (objfile, s)
181*5796c8dcSSimon Schubert       {
182*5796c8dcSSimon Schubert         i++;
183*5796c8dcSSimon Schubert         if (s->linetable != NULL)
184*5796c8dcSSimon Schubert           linetables++;
185*5796c8dcSSimon Schubert         if (s->primary == 1)
186*5796c8dcSSimon Schubert           blockvectors++;
187*5796c8dcSSimon Schubert       }
188*5796c8dcSSimon Schubert     printf_filtered (_("  Number of symbol tables: %d\n"), i);
189*5796c8dcSSimon Schubert     printf_filtered (_("  Number of symbol tables with line tables: %d\n"),
190*5796c8dcSSimon Schubert                      linetables);
191*5796c8dcSSimon Schubert     printf_filtered (_("  Number of symbol tables with blockvectors: %d\n"),
192*5796c8dcSSimon Schubert                      blockvectors);
193*5796c8dcSSimon Schubert 
194*5796c8dcSSimon Schubert     if (OBJSTAT (objfile, sz_strtab) > 0)
195*5796c8dcSSimon Schubert       printf_filtered (_("  Space used by a.out string tables: %d\n"),
196*5796c8dcSSimon Schubert 		       OBJSTAT (objfile, sz_strtab));
197*5796c8dcSSimon Schubert     printf_filtered (_("  Total memory used for objfile obstack: %d\n"),
198*5796c8dcSSimon Schubert 		     obstack_memory_used (&objfile->objfile_obstack));
199*5796c8dcSSimon Schubert     printf_filtered (_("  Total memory used for psymbol cache: %d\n"),
200*5796c8dcSSimon Schubert 		     bcache_memory_used (objfile->psymbol_cache));
201*5796c8dcSSimon Schubert     printf_filtered (_("  Total memory used for macro cache: %d\n"),
202*5796c8dcSSimon Schubert 		     bcache_memory_used (objfile->macro_cache));
203*5796c8dcSSimon Schubert   }
204*5796c8dcSSimon Schubert   immediate_quit--;
205*5796c8dcSSimon Schubert }
206*5796c8dcSSimon Schubert 
207*5796c8dcSSimon Schubert static void
208*5796c8dcSSimon Schubert dump_objfile (struct objfile *objfile)
209*5796c8dcSSimon Schubert {
210*5796c8dcSSimon Schubert   struct symtab *symtab;
211*5796c8dcSSimon Schubert   struct partial_symtab *psymtab;
212*5796c8dcSSimon Schubert 
213*5796c8dcSSimon Schubert   printf_filtered ("\nObject file %s:  ", objfile->name);
214*5796c8dcSSimon Schubert   printf_filtered ("Objfile at ");
215*5796c8dcSSimon Schubert   gdb_print_host_address (objfile, gdb_stdout);
216*5796c8dcSSimon Schubert   printf_filtered (", bfd at ");
217*5796c8dcSSimon Schubert   gdb_print_host_address (objfile->obfd, gdb_stdout);
218*5796c8dcSSimon Schubert   printf_filtered (", %d minsyms\n\n",
219*5796c8dcSSimon Schubert 		   objfile->minimal_symbol_count);
220*5796c8dcSSimon Schubert 
221*5796c8dcSSimon Schubert   if (objfile->psymtabs)
222*5796c8dcSSimon Schubert     {
223*5796c8dcSSimon Schubert       printf_filtered ("Psymtabs:\n");
224*5796c8dcSSimon Schubert       for (psymtab = objfile->psymtabs;
225*5796c8dcSSimon Schubert 	   psymtab != NULL;
226*5796c8dcSSimon Schubert 	   psymtab = psymtab->next)
227*5796c8dcSSimon Schubert 	{
228*5796c8dcSSimon Schubert 	  printf_filtered ("%s at ",
229*5796c8dcSSimon Schubert 			   psymtab->filename);
230*5796c8dcSSimon Schubert 	  gdb_print_host_address (psymtab, gdb_stdout);
231*5796c8dcSSimon Schubert 	  printf_filtered (", ");
232*5796c8dcSSimon Schubert 	  if (psymtab->objfile != objfile)
233*5796c8dcSSimon Schubert 	    {
234*5796c8dcSSimon Schubert 	      printf_filtered ("NOT ON CHAIN!  ");
235*5796c8dcSSimon Schubert 	    }
236*5796c8dcSSimon Schubert 	  wrap_here ("  ");
237*5796c8dcSSimon Schubert 	}
238*5796c8dcSSimon Schubert       printf_filtered ("\n\n");
239*5796c8dcSSimon Schubert     }
240*5796c8dcSSimon Schubert 
241*5796c8dcSSimon Schubert   if (objfile->symtabs)
242*5796c8dcSSimon Schubert     {
243*5796c8dcSSimon Schubert       printf_filtered ("Symtabs:\n");
244*5796c8dcSSimon Schubert       for (symtab = objfile->symtabs;
245*5796c8dcSSimon Schubert 	   symtab != NULL;
246*5796c8dcSSimon Schubert 	   symtab = symtab->next)
247*5796c8dcSSimon Schubert 	{
248*5796c8dcSSimon Schubert 	  printf_filtered ("%s at ", symtab->filename);
249*5796c8dcSSimon Schubert 	  gdb_print_host_address (symtab, gdb_stdout);
250*5796c8dcSSimon Schubert 	  printf_filtered (", ");
251*5796c8dcSSimon Schubert 	  if (symtab->objfile != objfile)
252*5796c8dcSSimon Schubert 	    {
253*5796c8dcSSimon Schubert 	      printf_filtered ("NOT ON CHAIN!  ");
254*5796c8dcSSimon Schubert 	    }
255*5796c8dcSSimon Schubert 	  wrap_here ("  ");
256*5796c8dcSSimon Schubert 	}
257*5796c8dcSSimon Schubert       printf_filtered ("\n\n");
258*5796c8dcSSimon Schubert     }
259*5796c8dcSSimon Schubert }
260*5796c8dcSSimon Schubert 
261*5796c8dcSSimon Schubert /* Print minimal symbols from this objfile.  */
262*5796c8dcSSimon Schubert 
263*5796c8dcSSimon Schubert static void
264*5796c8dcSSimon Schubert dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
265*5796c8dcSSimon Schubert {
266*5796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_objfile_arch (objfile);
267*5796c8dcSSimon Schubert   struct minimal_symbol *msymbol;
268*5796c8dcSSimon Schubert   int index;
269*5796c8dcSSimon Schubert   char ms_type;
270*5796c8dcSSimon Schubert 
271*5796c8dcSSimon Schubert   fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile->name);
272*5796c8dcSSimon Schubert   if (objfile->minimal_symbol_count == 0)
273*5796c8dcSSimon Schubert     {
274*5796c8dcSSimon Schubert       fprintf_filtered (outfile, "No minimal symbols found.\n");
275*5796c8dcSSimon Schubert       return;
276*5796c8dcSSimon Schubert     }
277*5796c8dcSSimon Schubert   index = 0;
278*5796c8dcSSimon Schubert   ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
279*5796c8dcSSimon Schubert     {
280*5796c8dcSSimon Schubert       struct obj_section *section = SYMBOL_OBJ_SECTION (msymbol);
281*5796c8dcSSimon Schubert 
282*5796c8dcSSimon Schubert       switch (MSYMBOL_TYPE (msymbol))
283*5796c8dcSSimon Schubert 	{
284*5796c8dcSSimon Schubert 	case mst_unknown:
285*5796c8dcSSimon Schubert 	  ms_type = 'u';
286*5796c8dcSSimon Schubert 	  break;
287*5796c8dcSSimon Schubert 	case mst_text:
288*5796c8dcSSimon Schubert 	  ms_type = 'T';
289*5796c8dcSSimon Schubert 	  break;
290*5796c8dcSSimon Schubert 	case mst_solib_trampoline:
291*5796c8dcSSimon Schubert 	  ms_type = 'S';
292*5796c8dcSSimon Schubert 	  break;
293*5796c8dcSSimon Schubert 	case mst_data:
294*5796c8dcSSimon Schubert 	  ms_type = 'D';
295*5796c8dcSSimon Schubert 	  break;
296*5796c8dcSSimon Schubert 	case mst_bss:
297*5796c8dcSSimon Schubert 	  ms_type = 'B';
298*5796c8dcSSimon Schubert 	  break;
299*5796c8dcSSimon Schubert 	case mst_abs:
300*5796c8dcSSimon Schubert 	  ms_type = 'A';
301*5796c8dcSSimon Schubert 	  break;
302*5796c8dcSSimon Schubert 	case mst_file_text:
303*5796c8dcSSimon Schubert 	  ms_type = 't';
304*5796c8dcSSimon Schubert 	  break;
305*5796c8dcSSimon Schubert 	case mst_file_data:
306*5796c8dcSSimon Schubert 	  ms_type = 'd';
307*5796c8dcSSimon Schubert 	  break;
308*5796c8dcSSimon Schubert 	case mst_file_bss:
309*5796c8dcSSimon Schubert 	  ms_type = 'b';
310*5796c8dcSSimon Schubert 	  break;
311*5796c8dcSSimon Schubert 	default:
312*5796c8dcSSimon Schubert 	  ms_type = '?';
313*5796c8dcSSimon Schubert 	  break;
314*5796c8dcSSimon Schubert 	}
315*5796c8dcSSimon Schubert       fprintf_filtered (outfile, "[%2d] %c ", index, ms_type);
316*5796c8dcSSimon Schubert       fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (msymbol)),
317*5796c8dcSSimon Schubert 		      outfile);
318*5796c8dcSSimon Schubert       fprintf_filtered (outfile, " %s", SYMBOL_LINKAGE_NAME (msymbol));
319*5796c8dcSSimon Schubert       if (section)
320*5796c8dcSSimon Schubert 	fprintf_filtered (outfile, " section %s",
321*5796c8dcSSimon Schubert 			  bfd_section_name (objfile->obfd,
322*5796c8dcSSimon Schubert 					    section->the_bfd_section));
323*5796c8dcSSimon Schubert       if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
324*5796c8dcSSimon Schubert 	{
325*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "  %s", SYMBOL_DEMANGLED_NAME (msymbol));
326*5796c8dcSSimon Schubert 	}
327*5796c8dcSSimon Schubert       if (msymbol->filename)
328*5796c8dcSSimon Schubert 	fprintf_filtered (outfile, "  %s", msymbol->filename);
329*5796c8dcSSimon Schubert       fputs_filtered ("\n", outfile);
330*5796c8dcSSimon Schubert       index++;
331*5796c8dcSSimon Schubert     }
332*5796c8dcSSimon Schubert   if (objfile->minimal_symbol_count != index)
333*5796c8dcSSimon Schubert     {
334*5796c8dcSSimon Schubert       warning (_("internal error:  minimal symbol count %d != %d"),
335*5796c8dcSSimon Schubert 	       objfile->minimal_symbol_count, index);
336*5796c8dcSSimon Schubert     }
337*5796c8dcSSimon Schubert   fprintf_filtered (outfile, "\n");
338*5796c8dcSSimon Schubert }
339*5796c8dcSSimon Schubert 
340*5796c8dcSSimon Schubert static void
341*5796c8dcSSimon Schubert dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
342*5796c8dcSSimon Schubert 	      struct ui_file *outfile)
343*5796c8dcSSimon Schubert {
344*5796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_objfile_arch (objfile);
345*5796c8dcSSimon Schubert   int i;
346*5796c8dcSSimon Schubert 
347*5796c8dcSSimon Schubert   fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
348*5796c8dcSSimon Schubert 		    psymtab->filename);
349*5796c8dcSSimon Schubert   fprintf_filtered (outfile, "(object ");
350*5796c8dcSSimon Schubert   gdb_print_host_address (psymtab, outfile);
351*5796c8dcSSimon Schubert   fprintf_filtered (outfile, ")\n\n");
352*5796c8dcSSimon Schubert   fprintf_unfiltered (outfile, "  Read from object file %s (",
353*5796c8dcSSimon Schubert 		      objfile->name);
354*5796c8dcSSimon Schubert   gdb_print_host_address (objfile, outfile);
355*5796c8dcSSimon Schubert   fprintf_unfiltered (outfile, ")\n");
356*5796c8dcSSimon Schubert 
357*5796c8dcSSimon Schubert   if (psymtab->readin)
358*5796c8dcSSimon Schubert     {
359*5796c8dcSSimon Schubert       fprintf_filtered (outfile,
360*5796c8dcSSimon Schubert 			"  Full symtab was read (at ");
361*5796c8dcSSimon Schubert       gdb_print_host_address (psymtab->symtab, outfile);
362*5796c8dcSSimon Schubert       fprintf_filtered (outfile, " by function at ");
363*5796c8dcSSimon Schubert       gdb_print_host_address (psymtab->read_symtab, outfile);
364*5796c8dcSSimon Schubert       fprintf_filtered (outfile, ")\n");
365*5796c8dcSSimon Schubert     }
366*5796c8dcSSimon Schubert 
367*5796c8dcSSimon Schubert   fprintf_filtered (outfile, "  Relocate symbols by ");
368*5796c8dcSSimon Schubert   for (i = 0; i < psymtab->objfile->num_sections; ++i)
369*5796c8dcSSimon Schubert     {
370*5796c8dcSSimon Schubert       if (i != 0)
371*5796c8dcSSimon Schubert 	fprintf_filtered (outfile, ", ");
372*5796c8dcSSimon Schubert       wrap_here ("    ");
373*5796c8dcSSimon Schubert       fputs_filtered (paddress (gdbarch,
374*5796c8dcSSimon Schubert 				ANOFFSET (psymtab->section_offsets, i)),
375*5796c8dcSSimon Schubert 		      outfile);
376*5796c8dcSSimon Schubert     }
377*5796c8dcSSimon Schubert   fprintf_filtered (outfile, "\n");
378*5796c8dcSSimon Schubert 
379*5796c8dcSSimon Schubert   fprintf_filtered (outfile, "  Symbols cover text addresses ");
380*5796c8dcSSimon Schubert   fputs_filtered (paddress (gdbarch, psymtab->textlow), outfile);
381*5796c8dcSSimon Schubert   fprintf_filtered (outfile, "-");
382*5796c8dcSSimon Schubert   fputs_filtered (paddress (gdbarch, psymtab->texthigh), outfile);
383*5796c8dcSSimon Schubert   fprintf_filtered (outfile, "\n");
384*5796c8dcSSimon Schubert   fprintf_filtered (outfile, "  Depends on %d other partial symtabs.\n",
385*5796c8dcSSimon Schubert 		    psymtab->number_of_dependencies);
386*5796c8dcSSimon Schubert   for (i = 0; i < psymtab->number_of_dependencies; i++)
387*5796c8dcSSimon Schubert     {
388*5796c8dcSSimon Schubert       fprintf_filtered (outfile, "    %d ", i);
389*5796c8dcSSimon Schubert       gdb_print_host_address (psymtab->dependencies[i], outfile);
390*5796c8dcSSimon Schubert       fprintf_filtered (outfile, " %s\n",
391*5796c8dcSSimon Schubert 			psymtab->dependencies[i]->filename);
392*5796c8dcSSimon Schubert     }
393*5796c8dcSSimon Schubert   if (psymtab->n_global_syms > 0)
394*5796c8dcSSimon Schubert     {
395*5796c8dcSSimon Schubert       print_partial_symbols (gdbarch,
396*5796c8dcSSimon Schubert 			     objfile->global_psymbols.list
397*5796c8dcSSimon Schubert 			     + psymtab->globals_offset,
398*5796c8dcSSimon Schubert 			     psymtab->n_global_syms, "Global", outfile);
399*5796c8dcSSimon Schubert     }
400*5796c8dcSSimon Schubert   if (psymtab->n_static_syms > 0)
401*5796c8dcSSimon Schubert     {
402*5796c8dcSSimon Schubert       print_partial_symbols (gdbarch,
403*5796c8dcSSimon Schubert 			     objfile->static_psymbols.list
404*5796c8dcSSimon Schubert 			     + psymtab->statics_offset,
405*5796c8dcSSimon Schubert 			     psymtab->n_static_syms, "Static", outfile);
406*5796c8dcSSimon Schubert     }
407*5796c8dcSSimon Schubert   fprintf_filtered (outfile, "\n");
408*5796c8dcSSimon Schubert }
409*5796c8dcSSimon Schubert 
410*5796c8dcSSimon Schubert static void
411*5796c8dcSSimon Schubert dump_symtab_1 (struct objfile *objfile, struct symtab *symtab,
412*5796c8dcSSimon Schubert 	       struct ui_file *outfile)
413*5796c8dcSSimon Schubert {
414*5796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_objfile_arch (objfile);
415*5796c8dcSSimon Schubert   int i;
416*5796c8dcSSimon Schubert   struct dict_iterator iter;
417*5796c8dcSSimon Schubert   int len, blen;
418*5796c8dcSSimon Schubert   struct linetable *l;
419*5796c8dcSSimon Schubert   struct blockvector *bv;
420*5796c8dcSSimon Schubert   struct symbol *sym;
421*5796c8dcSSimon Schubert   struct block *b;
422*5796c8dcSSimon Schubert   int depth;
423*5796c8dcSSimon Schubert 
424*5796c8dcSSimon Schubert   fprintf_filtered (outfile, "\nSymtab for file %s\n", symtab->filename);
425*5796c8dcSSimon Schubert   if (symtab->dirname)
426*5796c8dcSSimon Schubert     fprintf_filtered (outfile, "Compilation directory is %s\n",
427*5796c8dcSSimon Schubert 		      symtab->dirname);
428*5796c8dcSSimon Schubert   fprintf_filtered (outfile, "Read from object file %s (", objfile->name);
429*5796c8dcSSimon Schubert   gdb_print_host_address (objfile, outfile);
430*5796c8dcSSimon Schubert   fprintf_filtered (outfile, ")\n");
431*5796c8dcSSimon Schubert   fprintf_filtered (outfile, "Language: %s\n", language_str (symtab->language));
432*5796c8dcSSimon Schubert 
433*5796c8dcSSimon Schubert   /* First print the line table.  */
434*5796c8dcSSimon Schubert   l = LINETABLE (symtab);
435*5796c8dcSSimon Schubert   if (l)
436*5796c8dcSSimon Schubert     {
437*5796c8dcSSimon Schubert       fprintf_filtered (outfile, "\nLine table:\n\n");
438*5796c8dcSSimon Schubert       len = l->nitems;
439*5796c8dcSSimon Schubert       for (i = 0; i < len; i++)
440*5796c8dcSSimon Schubert 	{
441*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, " line %d at ", l->item[i].line);
442*5796c8dcSSimon Schubert 	  fputs_filtered (paddress (gdbarch, l->item[i].pc), outfile);
443*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "\n");
444*5796c8dcSSimon Schubert 	}
445*5796c8dcSSimon Schubert     }
446*5796c8dcSSimon Schubert   /* Now print the block info, but only for primary symtabs since we will
447*5796c8dcSSimon Schubert      print lots of duplicate info otherwise. */
448*5796c8dcSSimon Schubert   if (symtab->primary)
449*5796c8dcSSimon Schubert     {
450*5796c8dcSSimon Schubert       fprintf_filtered (outfile, "\nBlockvector:\n\n");
451*5796c8dcSSimon Schubert       bv = BLOCKVECTOR (symtab);
452*5796c8dcSSimon Schubert       len = BLOCKVECTOR_NBLOCKS (bv);
453*5796c8dcSSimon Schubert       for (i = 0; i < len; i++)
454*5796c8dcSSimon Schubert 	{
455*5796c8dcSSimon Schubert 	  b = BLOCKVECTOR_BLOCK (bv, i);
456*5796c8dcSSimon Schubert 	  depth = block_depth (b) * 2;
457*5796c8dcSSimon Schubert 	  print_spaces (depth, outfile);
458*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "block #%03d, object at ", i);
459*5796c8dcSSimon Schubert 	  gdb_print_host_address (b, outfile);
460*5796c8dcSSimon Schubert 	  if (BLOCK_SUPERBLOCK (b))
461*5796c8dcSSimon Schubert 	    {
462*5796c8dcSSimon Schubert 	      fprintf_filtered (outfile, " under ");
463*5796c8dcSSimon Schubert 	      gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile);
464*5796c8dcSSimon Schubert 	    }
465*5796c8dcSSimon Schubert 	  /* drow/2002-07-10: We could save the total symbols count
466*5796c8dcSSimon Schubert 	     even if we're using a hashtable, but nothing else but this message
467*5796c8dcSSimon Schubert 	     wants it.  */
468*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, ", %d syms/buckets in ",
469*5796c8dcSSimon Schubert 			    dict_size (BLOCK_DICT (b)));
470*5796c8dcSSimon Schubert 	  fputs_filtered (paddress (gdbarch, BLOCK_START (b)), outfile);
471*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "..");
472*5796c8dcSSimon Schubert 	  fputs_filtered (paddress (gdbarch, BLOCK_END (b)), outfile);
473*5796c8dcSSimon Schubert 	  if (BLOCK_FUNCTION (b))
474*5796c8dcSSimon Schubert 	    {
475*5796c8dcSSimon Schubert 	      fprintf_filtered (outfile, ", function %s",
476*5796c8dcSSimon Schubert 				SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b)));
477*5796c8dcSSimon Schubert 	      if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
478*5796c8dcSSimon Schubert 		{
479*5796c8dcSSimon Schubert 		  fprintf_filtered (outfile, ", %s",
480*5796c8dcSSimon Schubert 				SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
481*5796c8dcSSimon Schubert 		}
482*5796c8dcSSimon Schubert 	    }
483*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "\n");
484*5796c8dcSSimon Schubert 	  /* Now print each symbol in this block (in no particular order, if
485*5796c8dcSSimon Schubert 	     we're using a hashtable).  */
486*5796c8dcSSimon Schubert 	  ALL_BLOCK_SYMBOLS (b, iter, sym)
487*5796c8dcSSimon Schubert 	    {
488*5796c8dcSSimon Schubert 	      struct print_symbol_args s;
489*5796c8dcSSimon Schubert 	      s.gdbarch = gdbarch;
490*5796c8dcSSimon Schubert 	      s.symbol = sym;
491*5796c8dcSSimon Schubert 	      s.depth = depth + 1;
492*5796c8dcSSimon Schubert 	      s.outfile = outfile;
493*5796c8dcSSimon Schubert 	      catch_errors (print_symbol, &s, "Error printing symbol:\n",
494*5796c8dcSSimon Schubert 			    RETURN_MASK_ERROR);
495*5796c8dcSSimon Schubert 	    }
496*5796c8dcSSimon Schubert 	}
497*5796c8dcSSimon Schubert       fprintf_filtered (outfile, "\n");
498*5796c8dcSSimon Schubert     }
499*5796c8dcSSimon Schubert   else
500*5796c8dcSSimon Schubert     {
501*5796c8dcSSimon Schubert       fprintf_filtered (outfile, "\nBlockvector same as previous symtab\n\n");
502*5796c8dcSSimon Schubert     }
503*5796c8dcSSimon Schubert }
504*5796c8dcSSimon Schubert 
505*5796c8dcSSimon Schubert static void
506*5796c8dcSSimon Schubert dump_symtab (struct objfile *objfile, struct symtab *symtab,
507*5796c8dcSSimon Schubert 	     struct ui_file *outfile)
508*5796c8dcSSimon Schubert {
509*5796c8dcSSimon Schubert   /* Set the current language to the language of the symtab we're dumping
510*5796c8dcSSimon Schubert      because certain routines used during dump_symtab() use the current
511*5796c8dcSSimon Schubert      language to print an image of the symbol.  We'll restore it later.
512*5796c8dcSSimon Schubert      But use only real languages, not placeholders.  */
513*5796c8dcSSimon Schubert   if (symtab->language != language_unknown
514*5796c8dcSSimon Schubert       && symtab->language != language_auto)
515*5796c8dcSSimon Schubert     {
516*5796c8dcSSimon Schubert       enum language saved_lang;
517*5796c8dcSSimon Schubert 
518*5796c8dcSSimon Schubert       saved_lang = set_language (symtab->language);
519*5796c8dcSSimon Schubert 
520*5796c8dcSSimon Schubert       dump_symtab_1 (objfile, symtab, outfile);
521*5796c8dcSSimon Schubert 
522*5796c8dcSSimon Schubert       set_language (saved_lang);
523*5796c8dcSSimon Schubert     }
524*5796c8dcSSimon Schubert   else
525*5796c8dcSSimon Schubert     dump_symtab_1 (objfile, symtab, outfile);
526*5796c8dcSSimon Schubert }
527*5796c8dcSSimon Schubert 
528*5796c8dcSSimon Schubert void
529*5796c8dcSSimon Schubert maintenance_print_symbols (char *args, int from_tty)
530*5796c8dcSSimon Schubert {
531*5796c8dcSSimon Schubert   char **argv;
532*5796c8dcSSimon Schubert   struct ui_file *outfile;
533*5796c8dcSSimon Schubert   struct cleanup *cleanups;
534*5796c8dcSSimon Schubert   char *symname = NULL;
535*5796c8dcSSimon Schubert   char *filename = DEV_TTY;
536*5796c8dcSSimon Schubert   struct objfile *objfile;
537*5796c8dcSSimon Schubert   struct symtab *s;
538*5796c8dcSSimon Schubert 
539*5796c8dcSSimon Schubert   dont_repeat ();
540*5796c8dcSSimon Schubert 
541*5796c8dcSSimon Schubert   if (args == NULL)
542*5796c8dcSSimon Schubert     {
543*5796c8dcSSimon Schubert       error (_("\
544*5796c8dcSSimon Schubert Arguments missing: an output file name and an optional symbol file name"));
545*5796c8dcSSimon Schubert     }
546*5796c8dcSSimon Schubert   argv = gdb_buildargv (args);
547*5796c8dcSSimon Schubert   cleanups = make_cleanup_freeargv (argv);
548*5796c8dcSSimon Schubert 
549*5796c8dcSSimon Schubert   if (argv[0] != NULL)
550*5796c8dcSSimon Schubert     {
551*5796c8dcSSimon Schubert       filename = argv[0];
552*5796c8dcSSimon Schubert       /* If a second arg is supplied, it is a source file name to match on */
553*5796c8dcSSimon Schubert       if (argv[1] != NULL)
554*5796c8dcSSimon Schubert 	{
555*5796c8dcSSimon Schubert 	  symname = argv[1];
556*5796c8dcSSimon Schubert 	}
557*5796c8dcSSimon Schubert     }
558*5796c8dcSSimon Schubert 
559*5796c8dcSSimon Schubert   filename = tilde_expand (filename);
560*5796c8dcSSimon Schubert   make_cleanup (xfree, filename);
561*5796c8dcSSimon Schubert 
562*5796c8dcSSimon Schubert   outfile = gdb_fopen (filename, FOPEN_WT);
563*5796c8dcSSimon Schubert   if (outfile == 0)
564*5796c8dcSSimon Schubert     perror_with_name (filename);
565*5796c8dcSSimon Schubert   make_cleanup_ui_file_delete (outfile);
566*5796c8dcSSimon Schubert 
567*5796c8dcSSimon Schubert   immediate_quit++;
568*5796c8dcSSimon Schubert   ALL_SYMTABS (objfile, s)
569*5796c8dcSSimon Schubert     if (symname == NULL || strcmp (symname, s->filename) == 0)
570*5796c8dcSSimon Schubert     dump_symtab (objfile, s, outfile);
571*5796c8dcSSimon Schubert   immediate_quit--;
572*5796c8dcSSimon Schubert   do_cleanups (cleanups);
573*5796c8dcSSimon Schubert }
574*5796c8dcSSimon Schubert 
575*5796c8dcSSimon Schubert /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE.  ARGS->DEPTH says how
576*5796c8dcSSimon Schubert    far to indent.  ARGS is really a struct print_symbol_args *, but is
577*5796c8dcSSimon Schubert    declared as char * to get it past catch_errors.  Returns 0 for error,
578*5796c8dcSSimon Schubert    1 for success.  */
579*5796c8dcSSimon Schubert 
580*5796c8dcSSimon Schubert static int
581*5796c8dcSSimon Schubert print_symbol (void *args)
582*5796c8dcSSimon Schubert {
583*5796c8dcSSimon Schubert   struct gdbarch *gdbarch = ((struct print_symbol_args *) args)->gdbarch;
584*5796c8dcSSimon Schubert   struct symbol *symbol = ((struct print_symbol_args *) args)->symbol;
585*5796c8dcSSimon Schubert   int depth = ((struct print_symbol_args *) args)->depth;
586*5796c8dcSSimon Schubert   struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile;
587*5796c8dcSSimon Schubert   struct obj_section *section = SYMBOL_OBJ_SECTION (symbol);
588*5796c8dcSSimon Schubert 
589*5796c8dcSSimon Schubert   print_spaces (depth, outfile);
590*5796c8dcSSimon Schubert   if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN)
591*5796c8dcSSimon Schubert     {
592*5796c8dcSSimon Schubert       fprintf_filtered (outfile, "label %s at ", SYMBOL_PRINT_NAME (symbol));
593*5796c8dcSSimon Schubert       fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
594*5796c8dcSSimon Schubert 		      outfile);
595*5796c8dcSSimon Schubert       if (section)
596*5796c8dcSSimon Schubert 	fprintf_filtered (outfile, " section %s\n",
597*5796c8dcSSimon Schubert 			  bfd_section_name (section->the_bfd_section->owner,
598*5796c8dcSSimon Schubert 					    section->the_bfd_section));
599*5796c8dcSSimon Schubert       else
600*5796c8dcSSimon Schubert 	fprintf_filtered (outfile, "\n");
601*5796c8dcSSimon Schubert       return 1;
602*5796c8dcSSimon Schubert     }
603*5796c8dcSSimon Schubert   if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN)
604*5796c8dcSSimon Schubert     {
605*5796c8dcSSimon Schubert       if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
606*5796c8dcSSimon Schubert 	{
607*5796c8dcSSimon Schubert 	  LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
608*5796c8dcSSimon Schubert 	}
609*5796c8dcSSimon Schubert       else
610*5796c8dcSSimon Schubert 	{
611*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "%s %s = ",
612*5796c8dcSSimon Schubert 			 (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
613*5796c8dcSSimon Schubert 			  ? "enum"
614*5796c8dcSSimon Schubert 		     : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
615*5796c8dcSSimon Schubert 			? "struct" : "union")),
616*5796c8dcSSimon Schubert 			    SYMBOL_LINKAGE_NAME (symbol));
617*5796c8dcSSimon Schubert 	  LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
618*5796c8dcSSimon Schubert 	}
619*5796c8dcSSimon Schubert       fprintf_filtered (outfile, ";\n");
620*5796c8dcSSimon Schubert     }
621*5796c8dcSSimon Schubert   else
622*5796c8dcSSimon Schubert     {
623*5796c8dcSSimon Schubert       if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
624*5796c8dcSSimon Schubert 	fprintf_filtered (outfile, "typedef ");
625*5796c8dcSSimon Schubert       if (SYMBOL_TYPE (symbol))
626*5796c8dcSSimon Schubert 	{
627*5796c8dcSSimon Schubert 	  /* Print details of types, except for enums where it's clutter.  */
628*5796c8dcSSimon Schubert 	  LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_PRINT_NAME (symbol),
629*5796c8dcSSimon Schubert 			 outfile,
630*5796c8dcSSimon Schubert 			 TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
631*5796c8dcSSimon Schubert 			 depth);
632*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "; ");
633*5796c8dcSSimon Schubert 	}
634*5796c8dcSSimon Schubert       else
635*5796c8dcSSimon Schubert 	fprintf_filtered (outfile, "%s ", SYMBOL_PRINT_NAME (symbol));
636*5796c8dcSSimon Schubert 
637*5796c8dcSSimon Schubert       switch (SYMBOL_CLASS (symbol))
638*5796c8dcSSimon Schubert 	{
639*5796c8dcSSimon Schubert 	case LOC_CONST:
640*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "const %ld (0x%lx)",
641*5796c8dcSSimon Schubert 			    SYMBOL_VALUE (symbol),
642*5796c8dcSSimon Schubert 			    SYMBOL_VALUE (symbol));
643*5796c8dcSSimon Schubert 	  break;
644*5796c8dcSSimon Schubert 
645*5796c8dcSSimon Schubert 	case LOC_CONST_BYTES:
646*5796c8dcSSimon Schubert 	  {
647*5796c8dcSSimon Schubert 	    unsigned i;
648*5796c8dcSSimon Schubert 	    struct type *type = check_typedef (SYMBOL_TYPE (symbol));
649*5796c8dcSSimon Schubert 	    fprintf_filtered (outfile, "const %u hex bytes:",
650*5796c8dcSSimon Schubert 			      TYPE_LENGTH (type));
651*5796c8dcSSimon Schubert 	    for (i = 0; i < TYPE_LENGTH (type); i++)
652*5796c8dcSSimon Schubert 	      fprintf_filtered (outfile, " %02x",
653*5796c8dcSSimon Schubert 				(unsigned) SYMBOL_VALUE_BYTES (symbol)[i]);
654*5796c8dcSSimon Schubert 	  }
655*5796c8dcSSimon Schubert 	  break;
656*5796c8dcSSimon Schubert 
657*5796c8dcSSimon Schubert 	case LOC_STATIC:
658*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "static at ");
659*5796c8dcSSimon Schubert 	  fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
660*5796c8dcSSimon Schubert 			  outfile);
661*5796c8dcSSimon Schubert 	  if (section)
662*5796c8dcSSimon Schubert 	    fprintf_filtered (outfile, " section %s",
663*5796c8dcSSimon Schubert 			      bfd_section_name (section->the_bfd_section->owner,
664*5796c8dcSSimon Schubert 						section->the_bfd_section));
665*5796c8dcSSimon Schubert 	  break;
666*5796c8dcSSimon Schubert 
667*5796c8dcSSimon Schubert 	case LOC_REGISTER:
668*5796c8dcSSimon Schubert 	  if (SYMBOL_IS_ARGUMENT (symbol))
669*5796c8dcSSimon Schubert 	    fprintf_filtered (outfile, "parameter register %ld",
670*5796c8dcSSimon Schubert 			      SYMBOL_VALUE (symbol));
671*5796c8dcSSimon Schubert 	  else
672*5796c8dcSSimon Schubert 	    fprintf_filtered (outfile, "register %ld", SYMBOL_VALUE (symbol));
673*5796c8dcSSimon Schubert 	  break;
674*5796c8dcSSimon Schubert 
675*5796c8dcSSimon Schubert 	case LOC_ARG:
676*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "arg at offset 0x%lx",
677*5796c8dcSSimon Schubert 			    SYMBOL_VALUE (symbol));
678*5796c8dcSSimon Schubert 	  break;
679*5796c8dcSSimon Schubert 
680*5796c8dcSSimon Schubert 	case LOC_REF_ARG:
681*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "reference arg at 0x%lx", SYMBOL_VALUE (symbol));
682*5796c8dcSSimon Schubert 	  break;
683*5796c8dcSSimon Schubert 
684*5796c8dcSSimon Schubert 	case LOC_REGPARM_ADDR:
685*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "address parameter register %ld", SYMBOL_VALUE (symbol));
686*5796c8dcSSimon Schubert 	  break;
687*5796c8dcSSimon Schubert 
688*5796c8dcSSimon Schubert 	case LOC_LOCAL:
689*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "local at offset 0x%lx",
690*5796c8dcSSimon Schubert 			    SYMBOL_VALUE (symbol));
691*5796c8dcSSimon Schubert 	  break;
692*5796c8dcSSimon Schubert 
693*5796c8dcSSimon Schubert 	case LOC_TYPEDEF:
694*5796c8dcSSimon Schubert 	  break;
695*5796c8dcSSimon Schubert 
696*5796c8dcSSimon Schubert 	case LOC_LABEL:
697*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "label at ");
698*5796c8dcSSimon Schubert 	  fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
699*5796c8dcSSimon Schubert 			  outfile);
700*5796c8dcSSimon Schubert 	  if (section)
701*5796c8dcSSimon Schubert 	    fprintf_filtered (outfile, " section %s",
702*5796c8dcSSimon Schubert 			      bfd_section_name (section->the_bfd_section->owner,
703*5796c8dcSSimon Schubert 						section->the_bfd_section));
704*5796c8dcSSimon Schubert 	  break;
705*5796c8dcSSimon Schubert 
706*5796c8dcSSimon Schubert 	case LOC_BLOCK:
707*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "block object ");
708*5796c8dcSSimon Schubert 	  gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
709*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, ", ");
710*5796c8dcSSimon Schubert 	  fputs_filtered (paddress (gdbarch,
711*5796c8dcSSimon Schubert 				    BLOCK_START (SYMBOL_BLOCK_VALUE (symbol))),
712*5796c8dcSSimon Schubert 			  outfile);
713*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "..");
714*5796c8dcSSimon Schubert 	  fputs_filtered (paddress (gdbarch,
715*5796c8dcSSimon Schubert 				    BLOCK_END (SYMBOL_BLOCK_VALUE (symbol))),
716*5796c8dcSSimon Schubert 			  outfile);
717*5796c8dcSSimon Schubert 	  if (section)
718*5796c8dcSSimon Schubert 	    fprintf_filtered (outfile, " section %s",
719*5796c8dcSSimon Schubert 			      bfd_section_name (section->the_bfd_section->owner,
720*5796c8dcSSimon Schubert 						section->the_bfd_section));
721*5796c8dcSSimon Schubert 	  break;
722*5796c8dcSSimon Schubert 
723*5796c8dcSSimon Schubert 	case LOC_COMPUTED:
724*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "computed at runtime");
725*5796c8dcSSimon Schubert 	  break;
726*5796c8dcSSimon Schubert 
727*5796c8dcSSimon Schubert 	case LOC_UNRESOLVED:
728*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "unresolved");
729*5796c8dcSSimon Schubert 	  break;
730*5796c8dcSSimon Schubert 
731*5796c8dcSSimon Schubert 	case LOC_OPTIMIZED_OUT:
732*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "optimized out");
733*5796c8dcSSimon Schubert 	  break;
734*5796c8dcSSimon Schubert 
735*5796c8dcSSimon Schubert 	default:
736*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "botched symbol class %x",
737*5796c8dcSSimon Schubert 			    SYMBOL_CLASS (symbol));
738*5796c8dcSSimon Schubert 	  break;
739*5796c8dcSSimon Schubert 	}
740*5796c8dcSSimon Schubert     }
741*5796c8dcSSimon Schubert   fprintf_filtered (outfile, "\n");
742*5796c8dcSSimon Schubert   return 1;
743*5796c8dcSSimon Schubert }
744*5796c8dcSSimon Schubert 
745*5796c8dcSSimon Schubert void
746*5796c8dcSSimon Schubert maintenance_print_psymbols (char *args, int from_tty)
747*5796c8dcSSimon Schubert {
748*5796c8dcSSimon Schubert   char **argv;
749*5796c8dcSSimon Schubert   struct ui_file *outfile;
750*5796c8dcSSimon Schubert   struct cleanup *cleanups;
751*5796c8dcSSimon Schubert   char *symname = NULL;
752*5796c8dcSSimon Schubert   char *filename = DEV_TTY;
753*5796c8dcSSimon Schubert   struct objfile *objfile;
754*5796c8dcSSimon Schubert   struct partial_symtab *ps;
755*5796c8dcSSimon Schubert 
756*5796c8dcSSimon Schubert   dont_repeat ();
757*5796c8dcSSimon Schubert 
758*5796c8dcSSimon Schubert   if (args == NULL)
759*5796c8dcSSimon Schubert     {
760*5796c8dcSSimon Schubert       error (_("print-psymbols takes an output file name and optional symbol file name"));
761*5796c8dcSSimon Schubert     }
762*5796c8dcSSimon Schubert   argv = gdb_buildargv (args);
763*5796c8dcSSimon Schubert   cleanups = make_cleanup_freeargv (argv);
764*5796c8dcSSimon Schubert 
765*5796c8dcSSimon Schubert   if (argv[0] != NULL)
766*5796c8dcSSimon Schubert     {
767*5796c8dcSSimon Schubert       filename = argv[0];
768*5796c8dcSSimon Schubert       /* If a second arg is supplied, it is a source file name to match on */
769*5796c8dcSSimon Schubert       if (argv[1] != NULL)
770*5796c8dcSSimon Schubert 	{
771*5796c8dcSSimon Schubert 	  symname = argv[1];
772*5796c8dcSSimon Schubert 	}
773*5796c8dcSSimon Schubert     }
774*5796c8dcSSimon Schubert 
775*5796c8dcSSimon Schubert   filename = tilde_expand (filename);
776*5796c8dcSSimon Schubert   make_cleanup (xfree, filename);
777*5796c8dcSSimon Schubert 
778*5796c8dcSSimon Schubert   outfile = gdb_fopen (filename, FOPEN_WT);
779*5796c8dcSSimon Schubert   if (outfile == 0)
780*5796c8dcSSimon Schubert     perror_with_name (filename);
781*5796c8dcSSimon Schubert   make_cleanup_ui_file_delete (outfile);
782*5796c8dcSSimon Schubert 
783*5796c8dcSSimon Schubert   immediate_quit++;
784*5796c8dcSSimon Schubert   ALL_PSYMTABS (objfile, ps)
785*5796c8dcSSimon Schubert     if (symname == NULL || strcmp (symname, ps->filename) == 0)
786*5796c8dcSSimon Schubert     dump_psymtab (objfile, ps, outfile);
787*5796c8dcSSimon Schubert   immediate_quit--;
788*5796c8dcSSimon Schubert   do_cleanups (cleanups);
789*5796c8dcSSimon Schubert }
790*5796c8dcSSimon Schubert 
791*5796c8dcSSimon Schubert static void
792*5796c8dcSSimon Schubert print_partial_symbols (struct gdbarch *gdbarch,
793*5796c8dcSSimon Schubert 		       struct partial_symbol **p, int count, char *what,
794*5796c8dcSSimon Schubert 		       struct ui_file *outfile)
795*5796c8dcSSimon Schubert {
796*5796c8dcSSimon Schubert   fprintf_filtered (outfile, "  %s partial symbols:\n", what);
797*5796c8dcSSimon Schubert   while (count-- > 0)
798*5796c8dcSSimon Schubert     {
799*5796c8dcSSimon Schubert       fprintf_filtered (outfile, "    `%s'", SYMBOL_LINKAGE_NAME (*p));
800*5796c8dcSSimon Schubert       if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
801*5796c8dcSSimon Schubert 	{
802*5796c8dcSSimon Schubert 	  fprintf_filtered (outfile, "  `%s'", SYMBOL_DEMANGLED_NAME (*p));
803*5796c8dcSSimon Schubert 	}
804*5796c8dcSSimon Schubert       fputs_filtered (", ", outfile);
805*5796c8dcSSimon Schubert       switch (SYMBOL_DOMAIN (*p))
806*5796c8dcSSimon Schubert 	{
807*5796c8dcSSimon Schubert 	case UNDEF_DOMAIN:
808*5796c8dcSSimon Schubert 	  fputs_filtered ("undefined domain, ", outfile);
809*5796c8dcSSimon Schubert 	  break;
810*5796c8dcSSimon Schubert 	case VAR_DOMAIN:
811*5796c8dcSSimon Schubert 	  /* This is the usual thing -- don't print it */
812*5796c8dcSSimon Schubert 	  break;
813*5796c8dcSSimon Schubert 	case STRUCT_DOMAIN:
814*5796c8dcSSimon Schubert 	  fputs_filtered ("struct domain, ", outfile);
815*5796c8dcSSimon Schubert 	  break;
816*5796c8dcSSimon Schubert 	case LABEL_DOMAIN:
817*5796c8dcSSimon Schubert 	  fputs_filtered ("label domain, ", outfile);
818*5796c8dcSSimon Schubert 	  break;
819*5796c8dcSSimon Schubert 	default:
820*5796c8dcSSimon Schubert 	  fputs_filtered ("<invalid domain>, ", outfile);
821*5796c8dcSSimon Schubert 	  break;
822*5796c8dcSSimon Schubert 	}
823*5796c8dcSSimon Schubert       switch (SYMBOL_CLASS (*p))
824*5796c8dcSSimon Schubert 	{
825*5796c8dcSSimon Schubert 	case LOC_UNDEF:
826*5796c8dcSSimon Schubert 	  fputs_filtered ("undefined", outfile);
827*5796c8dcSSimon Schubert 	  break;
828*5796c8dcSSimon Schubert 	case LOC_CONST:
829*5796c8dcSSimon Schubert 	  fputs_filtered ("constant int", outfile);
830*5796c8dcSSimon Schubert 	  break;
831*5796c8dcSSimon Schubert 	case LOC_STATIC:
832*5796c8dcSSimon Schubert 	  fputs_filtered ("static", outfile);
833*5796c8dcSSimon Schubert 	  break;
834*5796c8dcSSimon Schubert 	case LOC_REGISTER:
835*5796c8dcSSimon Schubert 	  fputs_filtered ("register", outfile);
836*5796c8dcSSimon Schubert 	  break;
837*5796c8dcSSimon Schubert 	case LOC_ARG:
838*5796c8dcSSimon Schubert 	  fputs_filtered ("pass by value", outfile);
839*5796c8dcSSimon Schubert 	  break;
840*5796c8dcSSimon Schubert 	case LOC_REF_ARG:
841*5796c8dcSSimon Schubert 	  fputs_filtered ("pass by reference", outfile);
842*5796c8dcSSimon Schubert 	  break;
843*5796c8dcSSimon Schubert 	case LOC_REGPARM_ADDR:
844*5796c8dcSSimon Schubert 	  fputs_filtered ("register address parameter", outfile);
845*5796c8dcSSimon Schubert 	  break;
846*5796c8dcSSimon Schubert 	case LOC_LOCAL:
847*5796c8dcSSimon Schubert 	  fputs_filtered ("stack parameter", outfile);
848*5796c8dcSSimon Schubert 	  break;
849*5796c8dcSSimon Schubert 	case LOC_TYPEDEF:
850*5796c8dcSSimon Schubert 	  fputs_filtered ("type", outfile);
851*5796c8dcSSimon Schubert 	  break;
852*5796c8dcSSimon Schubert 	case LOC_LABEL:
853*5796c8dcSSimon Schubert 	  fputs_filtered ("label", outfile);
854*5796c8dcSSimon Schubert 	  break;
855*5796c8dcSSimon Schubert 	case LOC_BLOCK:
856*5796c8dcSSimon Schubert 	  fputs_filtered ("function", outfile);
857*5796c8dcSSimon Schubert 	  break;
858*5796c8dcSSimon Schubert 	case LOC_CONST_BYTES:
859*5796c8dcSSimon Schubert 	  fputs_filtered ("constant bytes", outfile);
860*5796c8dcSSimon Schubert 	  break;
861*5796c8dcSSimon Schubert 	case LOC_UNRESOLVED:
862*5796c8dcSSimon Schubert 	  fputs_filtered ("unresolved", outfile);
863*5796c8dcSSimon Schubert 	  break;
864*5796c8dcSSimon Schubert 	case LOC_OPTIMIZED_OUT:
865*5796c8dcSSimon Schubert 	  fputs_filtered ("optimized out", outfile);
866*5796c8dcSSimon Schubert 	  break;
867*5796c8dcSSimon Schubert 	case LOC_COMPUTED:
868*5796c8dcSSimon Schubert 	  fputs_filtered ("computed at runtime", outfile);
869*5796c8dcSSimon Schubert 	  break;
870*5796c8dcSSimon Schubert 	default:
871*5796c8dcSSimon Schubert 	  fputs_filtered ("<invalid location>", outfile);
872*5796c8dcSSimon Schubert 	  break;
873*5796c8dcSSimon Schubert 	}
874*5796c8dcSSimon Schubert       fputs_filtered (", ", outfile);
875*5796c8dcSSimon Schubert       fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (*p)), outfile);
876*5796c8dcSSimon Schubert       fprintf_filtered (outfile, "\n");
877*5796c8dcSSimon Schubert       p++;
878*5796c8dcSSimon Schubert     }
879*5796c8dcSSimon Schubert }
880*5796c8dcSSimon Schubert 
881*5796c8dcSSimon Schubert void
882*5796c8dcSSimon Schubert maintenance_print_msymbols (char *args, int from_tty)
883*5796c8dcSSimon Schubert {
884*5796c8dcSSimon Schubert   char **argv;
885*5796c8dcSSimon Schubert   struct ui_file *outfile;
886*5796c8dcSSimon Schubert   struct cleanup *cleanups;
887*5796c8dcSSimon Schubert   char *filename = DEV_TTY;
888*5796c8dcSSimon Schubert   char *symname = NULL;
889*5796c8dcSSimon Schubert   struct objfile *objfile;
890*5796c8dcSSimon Schubert 
891*5796c8dcSSimon Schubert   struct stat sym_st, obj_st;
892*5796c8dcSSimon Schubert 
893*5796c8dcSSimon Schubert   dont_repeat ();
894*5796c8dcSSimon Schubert 
895*5796c8dcSSimon Schubert   if (args == NULL)
896*5796c8dcSSimon Schubert     {
897*5796c8dcSSimon Schubert       error (_("print-msymbols takes an output file name and optional symbol file name"));
898*5796c8dcSSimon Schubert     }
899*5796c8dcSSimon Schubert   argv = gdb_buildargv (args);
900*5796c8dcSSimon Schubert   cleanups = make_cleanup_freeargv (argv);
901*5796c8dcSSimon Schubert 
902*5796c8dcSSimon Schubert   if (argv[0] != NULL)
903*5796c8dcSSimon Schubert     {
904*5796c8dcSSimon Schubert       filename = argv[0];
905*5796c8dcSSimon Schubert       /* If a second arg is supplied, it is a source file name to match on */
906*5796c8dcSSimon Schubert       if (argv[1] != NULL)
907*5796c8dcSSimon Schubert 	{
908*5796c8dcSSimon Schubert 	  symname = xfullpath (argv[1]);
909*5796c8dcSSimon Schubert 	  make_cleanup (xfree, symname);
910*5796c8dcSSimon Schubert 	  if (symname && stat (symname, &sym_st))
911*5796c8dcSSimon Schubert 	    perror_with_name (symname);
912*5796c8dcSSimon Schubert 	}
913*5796c8dcSSimon Schubert     }
914*5796c8dcSSimon Schubert 
915*5796c8dcSSimon Schubert   filename = tilde_expand (filename);
916*5796c8dcSSimon Schubert   make_cleanup (xfree, filename);
917*5796c8dcSSimon Schubert 
918*5796c8dcSSimon Schubert   outfile = gdb_fopen (filename, FOPEN_WT);
919*5796c8dcSSimon Schubert   if (outfile == 0)
920*5796c8dcSSimon Schubert     perror_with_name (filename);
921*5796c8dcSSimon Schubert   make_cleanup_ui_file_delete (outfile);
922*5796c8dcSSimon Schubert 
923*5796c8dcSSimon Schubert   immediate_quit++;
924*5796c8dcSSimon Schubert   ALL_OBJFILES (objfile)
925*5796c8dcSSimon Schubert     if (symname == NULL
926*5796c8dcSSimon Schubert 	|| (!stat (objfile->name, &obj_st) && sym_st.st_ino == obj_st.st_ino))
927*5796c8dcSSimon Schubert       dump_msymbols (objfile, outfile);
928*5796c8dcSSimon Schubert   immediate_quit--;
929*5796c8dcSSimon Schubert   fprintf_filtered (outfile, "\n\n");
930*5796c8dcSSimon Schubert   do_cleanups (cleanups);
931*5796c8dcSSimon Schubert }
932*5796c8dcSSimon Schubert 
933*5796c8dcSSimon Schubert void
934*5796c8dcSSimon Schubert maintenance_print_objfiles (char *ignore, int from_tty)
935*5796c8dcSSimon Schubert {
936*5796c8dcSSimon Schubert   struct objfile *objfile;
937*5796c8dcSSimon Schubert 
938*5796c8dcSSimon Schubert   dont_repeat ();
939*5796c8dcSSimon Schubert 
940*5796c8dcSSimon Schubert   immediate_quit++;
941*5796c8dcSSimon Schubert   ALL_OBJFILES (objfile)
942*5796c8dcSSimon Schubert     dump_objfile (objfile);
943*5796c8dcSSimon Schubert   immediate_quit--;
944*5796c8dcSSimon Schubert }
945*5796c8dcSSimon Schubert 
946*5796c8dcSSimon Schubert 
947*5796c8dcSSimon Schubert /* List all the symbol tables whose names match REGEXP (optional).  */
948*5796c8dcSSimon Schubert void
949*5796c8dcSSimon Schubert maintenance_info_symtabs (char *regexp, int from_tty)
950*5796c8dcSSimon Schubert {
951*5796c8dcSSimon Schubert   struct objfile *objfile;
952*5796c8dcSSimon Schubert 
953*5796c8dcSSimon Schubert   if (regexp)
954*5796c8dcSSimon Schubert     re_comp (regexp);
955*5796c8dcSSimon Schubert 
956*5796c8dcSSimon Schubert   ALL_OBJFILES (objfile)
957*5796c8dcSSimon Schubert     {
958*5796c8dcSSimon Schubert       struct symtab *symtab;
959*5796c8dcSSimon Schubert 
960*5796c8dcSSimon Schubert       /* We don't want to print anything for this objfile until we
961*5796c8dcSSimon Schubert          actually find a symtab whose name matches.  */
962*5796c8dcSSimon Schubert       int printed_objfile_start = 0;
963*5796c8dcSSimon Schubert 
964*5796c8dcSSimon Schubert       ALL_OBJFILE_SYMTABS (objfile, symtab)
965*5796c8dcSSimon Schubert 	{
966*5796c8dcSSimon Schubert 	  QUIT;
967*5796c8dcSSimon Schubert 
968*5796c8dcSSimon Schubert 	  if (! regexp
969*5796c8dcSSimon Schubert 	      || re_exec (symtab->filename))
970*5796c8dcSSimon Schubert 	    {
971*5796c8dcSSimon Schubert 	      if (! printed_objfile_start)
972*5796c8dcSSimon Schubert 		{
973*5796c8dcSSimon Schubert 		  printf_filtered ("{ objfile %s ", objfile->name);
974*5796c8dcSSimon Schubert 		  wrap_here ("  ");
975*5796c8dcSSimon Schubert 		  printf_filtered ("((struct objfile *) %s)\n",
976*5796c8dcSSimon Schubert 				   host_address_to_string (objfile));
977*5796c8dcSSimon Schubert 		  printed_objfile_start = 1;
978*5796c8dcSSimon Schubert 		}
979*5796c8dcSSimon Schubert 
980*5796c8dcSSimon Schubert 	      printf_filtered ("	{ symtab %s ", symtab->filename);
981*5796c8dcSSimon Schubert 	      wrap_here ("    ");
982*5796c8dcSSimon Schubert 	      printf_filtered ("((struct symtab *) %s)\n",
983*5796c8dcSSimon Schubert 			       host_address_to_string (symtab));
984*5796c8dcSSimon Schubert 	      printf_filtered ("	  dirname %s\n",
985*5796c8dcSSimon Schubert 			       symtab->dirname ? symtab->dirname : "(null)");
986*5796c8dcSSimon Schubert 	      printf_filtered ("	  fullname %s\n",
987*5796c8dcSSimon Schubert 			       symtab->fullname ? symtab->fullname : "(null)");
988*5796c8dcSSimon Schubert 	      printf_filtered ("	  blockvector ((struct blockvector *) %s)%s\n",
989*5796c8dcSSimon Schubert 			       host_address_to_string (symtab->blockvector),
990*5796c8dcSSimon Schubert 			       symtab->primary ? " (primary)" : "");
991*5796c8dcSSimon Schubert 	      printf_filtered ("	  linetable ((struct linetable *) %s)\n",
992*5796c8dcSSimon Schubert 			       host_address_to_string (symtab->linetable));
993*5796c8dcSSimon Schubert 	      printf_filtered ("	  debugformat %s\n", symtab->debugformat);
994*5796c8dcSSimon Schubert 	      printf_filtered ("	}\n");
995*5796c8dcSSimon Schubert 	    }
996*5796c8dcSSimon Schubert 	}
997*5796c8dcSSimon Schubert 
998*5796c8dcSSimon Schubert       if (printed_objfile_start)
999*5796c8dcSSimon Schubert         printf_filtered ("}\n");
1000*5796c8dcSSimon Schubert     }
1001*5796c8dcSSimon Schubert }
1002*5796c8dcSSimon Schubert 
1003*5796c8dcSSimon Schubert 
1004*5796c8dcSSimon Schubert /* List all the partial symbol tables whose names match REGEXP (optional).  */
1005*5796c8dcSSimon Schubert void
1006*5796c8dcSSimon Schubert maintenance_info_psymtabs (char *regexp, int from_tty)
1007*5796c8dcSSimon Schubert {
1008*5796c8dcSSimon Schubert   struct objfile *objfile;
1009*5796c8dcSSimon Schubert 
1010*5796c8dcSSimon Schubert   if (regexp)
1011*5796c8dcSSimon Schubert     re_comp (regexp);
1012*5796c8dcSSimon Schubert 
1013*5796c8dcSSimon Schubert   ALL_OBJFILES (objfile)
1014*5796c8dcSSimon Schubert     {
1015*5796c8dcSSimon Schubert       struct gdbarch *gdbarch = get_objfile_arch (objfile);
1016*5796c8dcSSimon Schubert       struct partial_symtab *psymtab;
1017*5796c8dcSSimon Schubert 
1018*5796c8dcSSimon Schubert       /* We don't want to print anything for this objfile until we
1019*5796c8dcSSimon Schubert          actually find a symtab whose name matches.  */
1020*5796c8dcSSimon Schubert       int printed_objfile_start = 0;
1021*5796c8dcSSimon Schubert 
1022*5796c8dcSSimon Schubert       ALL_OBJFILE_PSYMTABS (objfile, psymtab)
1023*5796c8dcSSimon Schubert 	{
1024*5796c8dcSSimon Schubert 	  QUIT;
1025*5796c8dcSSimon Schubert 
1026*5796c8dcSSimon Schubert 	  if (! regexp
1027*5796c8dcSSimon Schubert 	      || re_exec (psymtab->filename))
1028*5796c8dcSSimon Schubert 	    {
1029*5796c8dcSSimon Schubert 	      if (! printed_objfile_start)
1030*5796c8dcSSimon Schubert 		{
1031*5796c8dcSSimon Schubert 		  printf_filtered ("{ objfile %s ", objfile->name);
1032*5796c8dcSSimon Schubert 		  wrap_here ("  ");
1033*5796c8dcSSimon Schubert 		  printf_filtered ("((struct objfile *) %s)\n",
1034*5796c8dcSSimon Schubert 				   host_address_to_string (objfile));
1035*5796c8dcSSimon Schubert 		  printed_objfile_start = 1;
1036*5796c8dcSSimon Schubert 		}
1037*5796c8dcSSimon Schubert 
1038*5796c8dcSSimon Schubert 	      printf_filtered ("  { psymtab %s ", psymtab->filename);
1039*5796c8dcSSimon Schubert 	      wrap_here ("    ");
1040*5796c8dcSSimon Schubert 	      printf_filtered ("((struct partial_symtab *) %s)\n",
1041*5796c8dcSSimon Schubert 			       host_address_to_string (psymtab));
1042*5796c8dcSSimon Schubert 
1043*5796c8dcSSimon Schubert 	      printf_filtered ("    readin %s\n",
1044*5796c8dcSSimon Schubert 			       psymtab->readin ? "yes" : "no");
1045*5796c8dcSSimon Schubert 	      printf_filtered ("    fullname %s\n",
1046*5796c8dcSSimon Schubert 			       psymtab->fullname ? psymtab->fullname : "(null)");
1047*5796c8dcSSimon Schubert 	      printf_filtered ("    text addresses ");
1048*5796c8dcSSimon Schubert 	      fputs_filtered (paddress (gdbarch, psymtab->textlow),
1049*5796c8dcSSimon Schubert 			      gdb_stdout);
1050*5796c8dcSSimon Schubert 	      printf_filtered (" -- ");
1051*5796c8dcSSimon Schubert 	      fputs_filtered (paddress (gdbarch, psymtab->texthigh),
1052*5796c8dcSSimon Schubert 			      gdb_stdout);
1053*5796c8dcSSimon Schubert 	      printf_filtered ("\n");
1054*5796c8dcSSimon Schubert 	      printf_filtered ("    globals ");
1055*5796c8dcSSimon Schubert 	      if (psymtab->n_global_syms)
1056*5796c8dcSSimon Schubert 		{
1057*5796c8dcSSimon Schubert 		  printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1058*5796c8dcSSimon Schubert 				   host_address_to_string (psymtab->objfile->global_psymbols.list
1059*5796c8dcSSimon Schubert 				    + psymtab->globals_offset),
1060*5796c8dcSSimon Schubert 				   psymtab->n_global_syms);
1061*5796c8dcSSimon Schubert 		}
1062*5796c8dcSSimon Schubert 	      else
1063*5796c8dcSSimon Schubert 		printf_filtered ("(none)\n");
1064*5796c8dcSSimon Schubert 	      printf_filtered ("    statics ");
1065*5796c8dcSSimon Schubert 	      if (psymtab->n_static_syms)
1066*5796c8dcSSimon Schubert 		{
1067*5796c8dcSSimon Schubert 		  printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1068*5796c8dcSSimon Schubert 				   host_address_to_string (psymtab->objfile->static_psymbols.list
1069*5796c8dcSSimon Schubert 				    + psymtab->statics_offset),
1070*5796c8dcSSimon Schubert 				   psymtab->n_static_syms);
1071*5796c8dcSSimon Schubert 		}
1072*5796c8dcSSimon Schubert 	      else
1073*5796c8dcSSimon Schubert 		printf_filtered ("(none)\n");
1074*5796c8dcSSimon Schubert 	      printf_filtered ("    dependencies ");
1075*5796c8dcSSimon Schubert 	      if (psymtab->number_of_dependencies)
1076*5796c8dcSSimon Schubert 		{
1077*5796c8dcSSimon Schubert 		  int i;
1078*5796c8dcSSimon Schubert 
1079*5796c8dcSSimon Schubert 		  printf_filtered ("{\n");
1080*5796c8dcSSimon Schubert 		  for (i = 0; i < psymtab->number_of_dependencies; i++)
1081*5796c8dcSSimon Schubert 		    {
1082*5796c8dcSSimon Schubert 		      struct partial_symtab *dep = psymtab->dependencies[i];
1083*5796c8dcSSimon Schubert 
1084*5796c8dcSSimon Schubert 		      /* Note the string concatenation there --- no comma.  */
1085*5796c8dcSSimon Schubert 		      printf_filtered ("      psymtab %s "
1086*5796c8dcSSimon Schubert 				       "((struct partial_symtab *) %s)\n",
1087*5796c8dcSSimon Schubert 				       dep->filename,
1088*5796c8dcSSimon Schubert 				       host_address_to_string (dep));
1089*5796c8dcSSimon Schubert 		    }
1090*5796c8dcSSimon Schubert 		  printf_filtered ("    }\n");
1091*5796c8dcSSimon Schubert 		}
1092*5796c8dcSSimon Schubert 	      else
1093*5796c8dcSSimon Schubert 		printf_filtered ("(none)\n");
1094*5796c8dcSSimon Schubert 	      printf_filtered ("  }\n");
1095*5796c8dcSSimon Schubert 	    }
1096*5796c8dcSSimon Schubert 	}
1097*5796c8dcSSimon Schubert 
1098*5796c8dcSSimon Schubert       if (printed_objfile_start)
1099*5796c8dcSSimon Schubert         printf_filtered ("}\n");
1100*5796c8dcSSimon Schubert     }
1101*5796c8dcSSimon Schubert }
1102*5796c8dcSSimon Schubert 
1103*5796c8dcSSimon Schubert 
1104*5796c8dcSSimon Schubert /* Check consistency of psymtabs and symtabs.  */
1105*5796c8dcSSimon Schubert 
1106*5796c8dcSSimon Schubert void
1107*5796c8dcSSimon Schubert maintenance_check_symtabs (char *ignore, int from_tty)
1108*5796c8dcSSimon Schubert {
1109*5796c8dcSSimon Schubert   struct symbol *sym;
1110*5796c8dcSSimon Schubert   struct partial_symbol **psym;
1111*5796c8dcSSimon Schubert   struct symtab *s = NULL;
1112*5796c8dcSSimon Schubert   struct partial_symtab *ps;
1113*5796c8dcSSimon Schubert   struct blockvector *bv;
1114*5796c8dcSSimon Schubert   struct objfile *objfile;
1115*5796c8dcSSimon Schubert   struct block *b;
1116*5796c8dcSSimon Schubert   int length;
1117*5796c8dcSSimon Schubert 
1118*5796c8dcSSimon Schubert   ALL_PSYMTABS (objfile, ps)
1119*5796c8dcSSimon Schubert   {
1120*5796c8dcSSimon Schubert     struct gdbarch *gdbarch = get_objfile_arch (objfile);
1121*5796c8dcSSimon Schubert     s = PSYMTAB_TO_SYMTAB (ps);
1122*5796c8dcSSimon Schubert     if (s == NULL)
1123*5796c8dcSSimon Schubert       continue;
1124*5796c8dcSSimon Schubert     bv = BLOCKVECTOR (s);
1125*5796c8dcSSimon Schubert     b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1126*5796c8dcSSimon Schubert     psym = ps->objfile->static_psymbols.list + ps->statics_offset;
1127*5796c8dcSSimon Schubert     length = ps->n_static_syms;
1128*5796c8dcSSimon Schubert     while (length--)
1129*5796c8dcSSimon Schubert       {
1130*5796c8dcSSimon Schubert 	sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1131*5796c8dcSSimon Schubert 				   NULL, SYMBOL_DOMAIN (*psym));
1132*5796c8dcSSimon Schubert 	if (!sym)
1133*5796c8dcSSimon Schubert 	  {
1134*5796c8dcSSimon Schubert 	    printf_filtered ("Static symbol `");
1135*5796c8dcSSimon Schubert 	    puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1136*5796c8dcSSimon Schubert 	    printf_filtered ("' only found in ");
1137*5796c8dcSSimon Schubert 	    puts_filtered (ps->filename);
1138*5796c8dcSSimon Schubert 	    printf_filtered (" psymtab\n");
1139*5796c8dcSSimon Schubert 	  }
1140*5796c8dcSSimon Schubert 	psym++;
1141*5796c8dcSSimon Schubert       }
1142*5796c8dcSSimon Schubert     b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1143*5796c8dcSSimon Schubert     psym = ps->objfile->global_psymbols.list + ps->globals_offset;
1144*5796c8dcSSimon Schubert     length = ps->n_global_syms;
1145*5796c8dcSSimon Schubert     while (length--)
1146*5796c8dcSSimon Schubert       {
1147*5796c8dcSSimon Schubert 	sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1148*5796c8dcSSimon Schubert 				   NULL, SYMBOL_DOMAIN (*psym));
1149*5796c8dcSSimon Schubert 	if (!sym)
1150*5796c8dcSSimon Schubert 	  {
1151*5796c8dcSSimon Schubert 	    printf_filtered ("Global symbol `");
1152*5796c8dcSSimon Schubert 	    puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1153*5796c8dcSSimon Schubert 	    printf_filtered ("' only found in ");
1154*5796c8dcSSimon Schubert 	    puts_filtered (ps->filename);
1155*5796c8dcSSimon Schubert 	    printf_filtered (" psymtab\n");
1156*5796c8dcSSimon Schubert 	  }
1157*5796c8dcSSimon Schubert 	psym++;
1158*5796c8dcSSimon Schubert       }
1159*5796c8dcSSimon Schubert     if (ps->texthigh < ps->textlow)
1160*5796c8dcSSimon Schubert       {
1161*5796c8dcSSimon Schubert 	printf_filtered ("Psymtab ");
1162*5796c8dcSSimon Schubert 	puts_filtered (ps->filename);
1163*5796c8dcSSimon Schubert 	printf_filtered (" covers bad range ");
1164*5796c8dcSSimon Schubert 	fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
1165*5796c8dcSSimon Schubert 	printf_filtered (" - ");
1166*5796c8dcSSimon Schubert 	fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
1167*5796c8dcSSimon Schubert 	printf_filtered ("\n");
1168*5796c8dcSSimon Schubert 	continue;
1169*5796c8dcSSimon Schubert       }
1170*5796c8dcSSimon Schubert     if (ps->texthigh == 0)
1171*5796c8dcSSimon Schubert       continue;
1172*5796c8dcSSimon Schubert     if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
1173*5796c8dcSSimon Schubert       {
1174*5796c8dcSSimon Schubert 	printf_filtered ("Psymtab ");
1175*5796c8dcSSimon Schubert 	puts_filtered (ps->filename);
1176*5796c8dcSSimon Schubert 	printf_filtered (" covers ");
1177*5796c8dcSSimon Schubert 	fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
1178*5796c8dcSSimon Schubert 	printf_filtered (" - ");
1179*5796c8dcSSimon Schubert 	fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
1180*5796c8dcSSimon Schubert 	printf_filtered (" but symtab covers only ");
1181*5796c8dcSSimon Schubert 	fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
1182*5796c8dcSSimon Schubert 	printf_filtered (" - ");
1183*5796c8dcSSimon Schubert 	fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout);
1184*5796c8dcSSimon Schubert 	printf_filtered ("\n");
1185*5796c8dcSSimon Schubert       }
1186*5796c8dcSSimon Schubert   }
1187*5796c8dcSSimon Schubert }
1188*5796c8dcSSimon Schubert 
1189*5796c8dcSSimon Schubert 
1190*5796c8dcSSimon Schubert /* Return the nexting depth of a block within other blocks in its symtab.  */
1191*5796c8dcSSimon Schubert 
1192*5796c8dcSSimon Schubert static int
1193*5796c8dcSSimon Schubert block_depth (struct block *block)
1194*5796c8dcSSimon Schubert {
1195*5796c8dcSSimon Schubert   int i = 0;
1196*5796c8dcSSimon Schubert   while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
1197*5796c8dcSSimon Schubert     {
1198*5796c8dcSSimon Schubert       i++;
1199*5796c8dcSSimon Schubert     }
1200*5796c8dcSSimon Schubert   return i;
1201*5796c8dcSSimon Schubert }
1202*5796c8dcSSimon Schubert 
1203*5796c8dcSSimon Schubert 
1204*5796c8dcSSimon Schubert /* Increase the space allocated for LISTP, which is probably
1205*5796c8dcSSimon Schubert    global_psymbols or static_psymbols. This space will eventually
1206*5796c8dcSSimon Schubert    be freed in free_objfile().  */
1207*5796c8dcSSimon Schubert 
1208*5796c8dcSSimon Schubert void
1209*5796c8dcSSimon Schubert extend_psymbol_list (struct psymbol_allocation_list *listp,
1210*5796c8dcSSimon Schubert 		     struct objfile *objfile)
1211*5796c8dcSSimon Schubert {
1212*5796c8dcSSimon Schubert   int new_size;
1213*5796c8dcSSimon Schubert   if (listp->size == 0)
1214*5796c8dcSSimon Schubert     {
1215*5796c8dcSSimon Schubert       new_size = 255;
1216*5796c8dcSSimon Schubert       listp->list = (struct partial_symbol **)
1217*5796c8dcSSimon Schubert 	xmalloc (new_size * sizeof (struct partial_symbol *));
1218*5796c8dcSSimon Schubert     }
1219*5796c8dcSSimon Schubert   else
1220*5796c8dcSSimon Schubert     {
1221*5796c8dcSSimon Schubert       new_size = listp->size * 2;
1222*5796c8dcSSimon Schubert       listp->list = (struct partial_symbol **)
1223*5796c8dcSSimon Schubert 	xrealloc ((char *) listp->list,
1224*5796c8dcSSimon Schubert 		  new_size * sizeof (struct partial_symbol *));
1225*5796c8dcSSimon Schubert     }
1226*5796c8dcSSimon Schubert   /* Next assumes we only went one over.  Should be good if
1227*5796c8dcSSimon Schubert      program works correctly */
1228*5796c8dcSSimon Schubert   listp->next = listp->list + listp->size;
1229*5796c8dcSSimon Schubert   listp->size = new_size;
1230*5796c8dcSSimon Schubert }
1231*5796c8dcSSimon Schubert 
1232*5796c8dcSSimon Schubert 
1233*5796c8dcSSimon Schubert /* Do early runtime initializations. */
1234*5796c8dcSSimon Schubert void
1235*5796c8dcSSimon Schubert _initialize_symmisc (void)
1236*5796c8dcSSimon Schubert {
1237*5796c8dcSSimon Schubert   std_in = stdin;
1238*5796c8dcSSimon Schubert   std_out = stdout;
1239*5796c8dcSSimon Schubert   std_err = stderr;
1240*5796c8dcSSimon Schubert }
1241