* mn10300.igen (OP_F0F4): Need to load contents of register AN0
[platform/upstream/binutils.git] / gdb / symmisc.c
1 /* Do various things to symbol tables (other than lookup), for GDB.
2    Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996
3    Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
20
21 #include "defs.h"
22 #include "symtab.h"
23 #include "gdbtypes.h"
24 #include "bfd.h"
25 #include "symfile.h"
26 #include "objfiles.h"
27 #include "breakpoint.h"
28 #include "command.h"
29 #include "obstack.h"
30 #include "language.h"
31 #include "bcache.h"
32
33 #include "gdb_string.h"
34
35 #ifndef DEV_TTY
36 #define DEV_TTY "/dev/tty"
37 #endif
38
39 /* Unfortunately for debugging, stderr is usually a macro.  This is painful
40    when calling functions that take FILE *'s from the debugger.
41    So we make a variable which has the same value and which is accessible when
42    debugging GDB with itself.  Because stdin et al need not be constants,
43    we initialize them in the _initialize_symmisc function at the bottom
44    of the file.  */
45 FILE *std_in;
46 FILE *std_out;
47 FILE *std_err;
48
49 /* Prototypes for local functions */
50
51 static void 
52 dump_symtab PARAMS ((struct objfile *, struct symtab *, GDB_FILE *));
53
54 static void 
55 dump_psymtab PARAMS ((struct objfile *, struct partial_symtab *, GDB_FILE *));
56
57 static void 
58 dump_msymbols PARAMS ((struct objfile *, GDB_FILE *));
59
60 static void 
61 dump_objfile PARAMS ((struct objfile *));
62
63 static int
64 block_depth PARAMS ((struct block *));
65
66 static void
67 print_partial_symbols PARAMS ((struct partial_symbol **, int, char *, GDB_FILE *));
68
69 struct print_symbol_args {
70   struct symbol *symbol;
71   int depth;
72   GDB_FILE *outfile;
73 };
74
75 static int print_symbol PARAMS ((char *));
76
77 static void
78 free_symtab_block PARAMS ((struct objfile *, struct block *));
79
80 \f
81 /* Free a struct block <- B and all the symbols defined in that block.  */
82
83 static void
84 free_symtab_block (objfile, b)
85      struct objfile *objfile;
86      struct block *b;
87 {
88   register int i, n;
89   n = BLOCK_NSYMS (b);
90   for (i = 0; i < n; i++)
91     {
92       mfree (objfile -> md, SYMBOL_NAME (BLOCK_SYM (b, i)));
93       mfree (objfile -> md, (PTR) BLOCK_SYM (b, i));
94     }
95   mfree (objfile -> md, (PTR) b);
96 }
97
98 /* Free all the storage associated with the struct symtab <- S.
99    Note that some symtabs have contents malloc'ed structure by structure,
100    while some have contents that all live inside one big block of memory,
101    and some share the contents of another symbol table and so you should
102    not free the contents on their behalf (except sometimes the linetable,
103    which maybe per symtab even when the rest is not).
104    It is s->free_code that says which alternative to use.  */
105
106 void
107 free_symtab (s)
108      register struct symtab *s;
109 {
110   register int i, n;
111   register struct blockvector *bv;
112
113   switch (s->free_code)
114     {
115     case free_nothing:
116       /* All the contents are part of a big block of memory (an obstack),
117          and some other symtab is in charge of freeing that block.
118          Therefore, do nothing.  */
119       break;
120
121     case free_contents:
122       /* Here all the contents were malloc'ed structure by structure
123          and must be freed that way.  */
124       /* First free the blocks (and their symbols.  */
125       bv = BLOCKVECTOR (s);
126       n = BLOCKVECTOR_NBLOCKS (bv);
127       for (i = 0; i < n; i++)
128         free_symtab_block (s -> objfile, BLOCKVECTOR_BLOCK (bv, i));
129       /* Free the blockvector itself.  */
130       mfree (s -> objfile -> md, (PTR) bv);
131       /* Also free the linetable.  */
132       
133     case free_linetable:
134       /* Everything will be freed either by our `free_ptr'
135          or by some other symtab, except for our linetable.
136          Free that now.  */
137       if (LINETABLE (s))
138         mfree (s -> objfile -> md, (PTR) LINETABLE (s));
139       break;
140     }
141
142   /* If there is a single block of memory to free, free it.  */
143   if (s -> free_ptr != NULL)
144     mfree (s -> objfile -> md, s -> free_ptr);
145
146   /* Free source-related stuff */
147   if (s -> line_charpos != NULL)
148     mfree (s -> objfile -> md, (PTR) s -> line_charpos);
149   if (s -> fullname != NULL)
150     mfree (s -> objfile -> md, s -> fullname);
151   mfree (s -> objfile -> md, (PTR) s);
152 }
153
154 #if MAINTENANCE_CMDS
155
156 void
157 print_symbol_bcache_statistics ()
158 {
159   struct objfile *objfile;
160
161   immediate_quit++;
162   ALL_OBJFILES (objfile)
163     {
164       printf_filtered ("Byte cache statistics for '%s':\n", objfile -> name);
165       print_bcache_statistics (&objfile -> psymbol_cache, "partial symbol cache");
166     }
167   immediate_quit--;
168 }
169
170 void
171 print_objfile_statistics ()
172 {
173   struct objfile *objfile;
174
175   immediate_quit++;
176   ALL_OBJFILES (objfile)
177     {
178       printf_filtered ("Statistics for '%s':\n", objfile -> name);
179       if (OBJSTAT (objfile, n_stabs) > 0)
180         printf_filtered ("  Number of \"stab\" symbols read: %d\n",
181                          OBJSTAT (objfile, n_stabs));
182       if (OBJSTAT (objfile, n_minsyms) > 0)
183         printf_filtered ("  Number of \"minimal symbols read: %d\n",
184                          OBJSTAT (objfile, n_minsyms));
185       if (OBJSTAT (objfile, n_psyms) > 0)
186         printf_filtered ("  Number of \"partial symbols read: %d\n",
187                          OBJSTAT (objfile, n_psyms));
188       if (OBJSTAT (objfile, n_syms) > 0)
189         printf_filtered ("  Number of \"full symbols read: %d\n",
190                          OBJSTAT (objfile, n_syms));
191       if (OBJSTAT (objfile, n_types) > 0)
192         printf_filtered ("  Number of \"types defined: %d\n",
193                          OBJSTAT (objfile, n_types));
194       if (OBJSTAT (objfile, sz_strtab) > 0)
195         printf_filtered ("  Space used by a.out string tables: %d\n",
196                          OBJSTAT (objfile, sz_strtab));
197       printf_filtered ("  Total memory used for psymbol obstack: %d\n",
198                        obstack_memory_used (&objfile -> psymbol_obstack));
199       printf_filtered ("  Total memory used for symbol obstack: %d\n",
200                        obstack_memory_used (&objfile -> symbol_obstack));
201       printf_filtered ("  Total memory used for type obstack: %d\n",
202                        obstack_memory_used (&objfile -> type_obstack));
203     }
204   immediate_quit--;
205 }
206
207 static void 
208 dump_objfile (objfile)
209      struct objfile *objfile;
210 {
211   struct symtab *symtab;
212   struct partial_symtab *psymtab;
213
214   printf_filtered ("\nObject file %s:  ", objfile -> name);
215   printf_filtered ("Objfile at ");
216   gdb_print_address (objfile, gdb_stdout);
217   printf_filtered (", bfd at ");
218   gdb_print_address (objfile->obfd, gdb_stdout);
219   printf_filtered (", %d minsyms\n\n",
220                    objfile->minimal_symbol_count);
221
222   if (objfile -> psymtabs)
223     {
224       printf_filtered ("Psymtabs:\n");
225       for (psymtab = objfile -> psymtabs;
226            psymtab != NULL;
227            psymtab = psymtab -> next)
228         {
229           printf_filtered ("%s at ",
230                            psymtab -> filename);
231           gdb_print_address (psymtab, gdb_stdout);
232           printf_filtered (", ");
233           if (psymtab -> objfile != objfile)
234             {
235               printf_filtered ("NOT ON CHAIN!  ");
236             }
237           wrap_here ("  ");
238         }
239       printf_filtered ("\n\n");
240     }
241
242   if (objfile -> symtabs)
243     {
244       printf_filtered ("Symtabs:\n");
245       for (symtab = objfile -> symtabs;
246            symtab != NULL;
247            symtab = symtab->next)
248         {
249           printf_filtered ("%s at ", symtab -> filename);
250           gdb_print_address (symtab, gdb_stdout);
251           printf_filtered (", ");
252           if (symtab -> objfile != objfile)
253             {
254               printf_filtered ("NOT ON CHAIN!  ");
255             }
256           wrap_here ("  ");
257         }
258       printf_filtered ("\n\n");
259     }
260 }
261
262 /* Print minimal symbols from this objfile.  */
263  
264 static void 
265 dump_msymbols (objfile, outfile)
266      struct objfile *objfile;
267      GDB_FILE *outfile;
268 {
269   struct minimal_symbol *msymbol;
270   int index;
271   char ms_type;
272   
273   fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile -> name);
274   if (objfile -> minimal_symbol_count == 0)
275     {
276       fprintf_filtered (outfile, "No minimal symbols found.\n");
277       return;
278     }
279   for (index = 0, msymbol = objfile -> msymbols;
280        SYMBOL_NAME (msymbol) != NULL; msymbol++, index++)
281     {
282       switch (msymbol -> type)
283         {
284           case mst_unknown:
285             ms_type = 'u';
286             break;
287           case mst_text:
288             ms_type = 'T';
289             break;
290           case mst_solib_trampoline:
291             ms_type = 'S';
292             break;
293           case mst_data:
294             ms_type = 'D';
295             break;
296           case mst_bss:
297             ms_type = 'B';
298             break;
299           case mst_abs:
300             ms_type = 'A';
301             break;
302           case mst_file_text:
303             ms_type = 't';
304             break;
305           case mst_file_data:
306             ms_type = 'd';
307             break;
308           case mst_file_bss:
309             ms_type = 'b';
310             break;
311           default:
312             ms_type = '?';
313             break;
314         }
315       fprintf_filtered (outfile, "[%2d] %c %#10lx %s", index, ms_type,
316                         SYMBOL_VALUE_ADDRESS (msymbol), SYMBOL_NAME (msymbol));
317       if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
318         {
319           fprintf_filtered (outfile, "  %s", SYMBOL_DEMANGLED_NAME (msymbol));
320         }
321 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
322       if (msymbol->filename)
323         fprintf_filtered (outfile, "  %s", msymbol->filename);
324 #endif
325       fputs_filtered ("\n", outfile);
326     }
327   if (objfile -> minimal_symbol_count != index)
328     {
329       warning ("internal error:  minimal symbol count %d != %d",
330                objfile -> minimal_symbol_count, index);
331     }
332   fprintf_filtered (outfile, "\n");
333 }
334
335 static void
336 dump_psymtab (objfile, psymtab, outfile)
337      struct objfile *objfile;
338      struct partial_symtab *psymtab;
339      GDB_FILE *outfile;
340 {
341   int i;
342
343   fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
344                     psymtab -> filename);
345   fprintf_filtered (outfile, "(object ");
346   gdb_print_address (psymtab, outfile);
347   fprintf_filtered (outfile, ")\n\n");
348   fprintf_unfiltered (outfile, "  Read from object file %s (",
349                       objfile -> name);
350   gdb_print_address (objfile, outfile);
351   fprintf_unfiltered (outfile, ")\n");
352
353   if (psymtab -> readin)
354     {
355       fprintf_filtered (outfile,
356                 "  Full symtab was read (at ");
357       gdb_print_address (psymtab->symtab, outfile);
358       fprintf_filtered (outfile, " by function at ");
359       gdb_print_address ((PTR)psymtab->read_symtab, outfile);
360       fprintf_filtered (outfile, ")\n");
361     }
362
363   fprintf_filtered (outfile, "  Relocate symbols by ");
364   for (i = 0; i < psymtab->objfile->num_sections; ++i)
365     {
366       if (i != 0)
367         fprintf_filtered (outfile, ", ");
368       wrap_here ("    ");
369       print_address_numeric (ANOFFSET (psymtab->section_offsets, i),
370                              1,
371                              outfile);
372     }
373   fprintf_filtered (outfile, "\n");
374
375   fprintf_filtered (outfile, "  Symbols cover text addresses ");
376   print_address_numeric (psymtab->textlow, 1, outfile);
377   fprintf_filtered (outfile, "-");
378   print_address_numeric (psymtab->texthigh, 1, outfile);
379   fprintf_filtered (outfile, "\n");
380   fprintf_filtered (outfile, "  Depends on %d other partial symtabs.\n",
381                     psymtab -> number_of_dependencies);
382   for (i = 0; i < psymtab -> number_of_dependencies; i++)
383     {
384       fprintf_filtered (outfile, "    %d ", i);
385       gdb_print_address (psymtab -> dependencies[i], outfile);
386       fprintf_filtered (outfile, " %s\n",
387                         psymtab -> dependencies[i] -> filename);
388     }
389   if (psymtab -> n_global_syms > 0)
390     {
391       print_partial_symbols (objfile -> global_psymbols.list
392                             + psymtab -> globals_offset,
393                             psymtab -> n_global_syms, "Global", outfile);
394     }
395   if (psymtab -> n_static_syms > 0)
396     {
397       print_partial_symbols (objfile -> static_psymbols.list
398                             + psymtab -> statics_offset,
399                             psymtab -> n_static_syms, "Static", outfile);
400     }
401   fprintf_filtered (outfile, "\n");
402 }
403
404 static void 
405 dump_symtab (objfile, symtab, outfile)
406      struct objfile *objfile;
407      struct symtab *symtab;
408      GDB_FILE *outfile;
409 {
410   register int i, j;
411   int len, blen;
412   register struct linetable *l;
413   struct blockvector *bv;
414   register struct block *b;
415   int depth;
416
417   fprintf_filtered (outfile, "\nSymtab for file %s\n", symtab->filename);
418   fprintf_filtered (outfile, "Read from object file %s (", objfile->name);
419   gdb_print_address (objfile, outfile);
420   fprintf_filtered (outfile, ")\n");
421   fprintf_filtered (outfile, "Language: %s\n", language_str (symtab -> language));
422
423   /* First print the line table.  */
424   l = LINETABLE (symtab);
425   if (l)
426     {
427       fprintf_filtered (outfile, "\nLine table:\n\n");
428       len = l->nitems;
429       for (i = 0; i < len; i++)
430         {
431           fprintf_filtered (outfile, " line %d at ", l->item[i].line);
432           print_address_numeric (l->item[i].pc, 1, outfile);
433           fprintf_filtered (outfile, "\n");
434         }
435     }
436   /* Now print the block info.  */
437   fprintf_filtered (outfile, "\nBlockvector:\n\n");
438   bv = BLOCKVECTOR (symtab);
439   len = BLOCKVECTOR_NBLOCKS (bv);
440   for (i = 0; i < len; i++)
441     {
442       b = BLOCKVECTOR_BLOCK (bv, i);
443       depth = block_depth (b) * 2;
444       print_spaces (depth, outfile);
445       fprintf_filtered (outfile, "block #%03d (object ", i);
446       gdb_print_address (b, outfile);
447       fprintf_filtered (outfile, ") ");
448       fprintf_filtered (outfile, "[");
449       print_address_numeric (BLOCK_START (b), 1, outfile);
450       fprintf_filtered (outfile, "..");
451       print_address_numeric (BLOCK_END (b), 1, outfile);
452       fprintf_filtered (outfile, "]");
453       if (BLOCK_SUPERBLOCK (b))
454         {
455           fprintf_filtered (outfile, " (under ");
456           gdb_print_address (BLOCK_SUPERBLOCK (b), outfile);
457           fprintf_filtered (outfile, ")");
458         }
459       if (BLOCK_FUNCTION (b))
460         {
461           fprintf_filtered (outfile, " %s", SYMBOL_NAME (BLOCK_FUNCTION (b)));
462           if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
463             {
464               fprintf_filtered (outfile, " %s",
465                        SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
466             }
467         }
468       if (BLOCK_GCC_COMPILED(b))
469         fprintf_filtered (outfile, " gcc%d compiled", BLOCK_GCC_COMPILED(b));
470       fprintf_filtered (outfile, "\n");
471       blen = BLOCK_NSYMS (b);
472       for (j = 0; j < blen; j++)
473         {
474           struct print_symbol_args s;
475           s.symbol = BLOCK_SYM (b, j);
476           s.depth = depth + 1;
477           s.outfile = outfile;
478           catch_errors (print_symbol, &s, "Error printing symbol:\n",
479                         RETURN_MASK_ALL);
480         }
481     }
482   fprintf_filtered (outfile, "\n");
483 }
484
485 void
486 maintenance_print_symbols (args, from_tty)
487      char *args;
488      int from_tty;
489 {
490   char **argv;
491   GDB_FILE *outfile;
492   struct cleanup *cleanups;
493   char *symname = NULL;
494   char *filename = DEV_TTY;
495   struct objfile *objfile;
496   struct symtab *s;
497
498   dont_repeat ();
499
500   if (args == NULL)
501     {
502       error ("\
503 Arguments missing: an output file name and an optional symbol file name");
504     }
505   else if ((argv = buildargv (args)) == NULL)
506     {
507       nomem (0);
508     }
509   cleanups = make_cleanup (freeargv, (char *) argv);
510
511   if (argv[0] != NULL)
512     {
513       filename = argv[0];
514       /* If a second arg is supplied, it is a source file name to match on */
515       if (argv[1] != NULL)
516         {
517           symname = argv[1];
518         }
519     }
520
521   filename = tilde_expand (filename);
522   make_cleanup (free, filename);
523   
524   outfile = gdb_fopen (filename, FOPEN_WT);
525   if (outfile == 0)
526     perror_with_name (filename);
527   make_cleanup (fclose, (char *) outfile);
528
529   immediate_quit++;
530   ALL_SYMTABS (objfile, s)
531     if (symname == NULL || (STREQ (symname, s -> filename)))
532       dump_symtab (objfile, s, outfile);
533   immediate_quit--;
534   do_cleanups (cleanups);
535 }
536
537 /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE.  ARGS->DEPTH says how
538    far to indent.  ARGS is really a struct print_symbol_args *, but is
539    declared as char * to get it past catch_errors.  Returns 0 for error,
540    1 for success.  */
541
542 static int
543 print_symbol (args)
544      char *args;
545 {
546   struct symbol *symbol = ((struct print_symbol_args *)args)->symbol;
547   int depth = ((struct print_symbol_args *)args)->depth;
548   GDB_FILE *outfile = ((struct print_symbol_args *)args)->outfile;
549
550   print_spaces (depth, outfile);
551   if (SYMBOL_NAMESPACE (symbol) == LABEL_NAMESPACE)
552     {
553       fprintf_filtered (outfile, "label %s at ", SYMBOL_SOURCE_NAME (symbol));
554       print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
555       fprintf_filtered (outfile, "\n");
556       return 1;
557     }
558   if (SYMBOL_NAMESPACE (symbol) == STRUCT_NAMESPACE)
559     {
560       if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
561         {
562           LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
563         }
564       else
565         {
566           fprintf_filtered (outfile, "%s %s = ",
567                (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
568                 ? "enum"
569                 : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
570                    ? "struct" : "union")),
571                SYMBOL_NAME (symbol));
572           LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
573         }
574       fprintf_filtered (outfile, ";\n");
575     }
576   else
577     {
578       if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
579         fprintf_filtered (outfile, "typedef ");
580       if (SYMBOL_TYPE (symbol))
581         {
582           /* Print details of types, except for enums where it's clutter.  */
583           LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_SOURCE_NAME (symbol),
584                          outfile,
585                          TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
586                          depth);
587           fprintf_filtered (outfile, "; ");
588         }
589       else
590         fprintf_filtered (outfile, "%s ", SYMBOL_SOURCE_NAME (symbol));
591
592       switch (SYMBOL_CLASS (symbol))
593         {
594         case LOC_CONST:
595           fprintf_filtered (outfile, "const %ld (0x%lx),",
596                             SYMBOL_VALUE (symbol),
597                             SYMBOL_VALUE (symbol));
598           break;
599
600         case LOC_CONST_BYTES:
601           {
602             unsigned i;
603             struct type *type = check_typedef (SYMBOL_TYPE (symbol));
604             fprintf_filtered (outfile, "const %u hex bytes:",
605                               TYPE_LENGTH (type));
606             for (i = 0; i < TYPE_LENGTH (type); i++)
607               fprintf_filtered (outfile, " %02x",
608                                 (unsigned)SYMBOL_VALUE_BYTES (symbol) [i]);
609             fprintf_filtered (outfile, ",");
610           }
611           break;
612
613         case LOC_STATIC:
614           fprintf_filtered (outfile, "static at ");
615           print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1,outfile);
616           fprintf_filtered (outfile, ",");
617           break;
618
619         case LOC_REGISTER:
620           fprintf_filtered (outfile, "register %ld,", SYMBOL_VALUE (symbol));
621           break;
622
623         case LOC_ARG:
624           fprintf_filtered (outfile, "arg at offset 0x%lx,",
625                             SYMBOL_VALUE (symbol));
626           break;
627
628         case LOC_LOCAL_ARG:
629           fprintf_filtered (outfile, "arg at offset 0x%lx from fp,",
630                    SYMBOL_VALUE (symbol));
631           break;
632
633         case LOC_REF_ARG:
634           fprintf_filtered (outfile, "reference arg at 0x%lx,", SYMBOL_VALUE (symbol));
635           break;
636
637         case LOC_REGPARM:
638           fprintf_filtered (outfile, "parameter register %ld,", SYMBOL_VALUE (symbol));
639           break;
640
641         case LOC_REGPARM_ADDR:
642           fprintf_filtered (outfile, "address parameter register %ld,", SYMBOL_VALUE (symbol));
643           break;
644
645         case LOC_LOCAL:
646           fprintf_filtered (outfile, "local at offset 0x%lx,",
647                             SYMBOL_VALUE (symbol));
648           break;
649
650         case LOC_BASEREG:
651           fprintf_filtered (outfile, "local at 0x%lx from register %d",
652                    SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
653           break;
654
655         case LOC_BASEREG_ARG:
656           fprintf_filtered (outfile, "arg at 0x%lx from register %d,",
657                    SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
658           break;
659
660         case LOC_TYPEDEF:
661           break;
662
663         case LOC_LABEL:
664           fprintf_filtered (outfile, "label at ");
665           print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
666           break;
667
668         case LOC_BLOCK:
669           fprintf_filtered (outfile, "block (object ");
670           gdb_print_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
671           fprintf_filtered (outfile, ") starting at ");
672           print_address_numeric (BLOCK_START (SYMBOL_BLOCK_VALUE (symbol)),
673                                  1,
674                                  outfile);
675           fprintf_filtered (outfile, ",");
676           break;
677
678         case LOC_UNRESOLVED:
679           fprintf_filtered (outfile, "unresolved");
680           break;
681
682         case LOC_OPTIMIZED_OUT:
683           fprintf_filtered (outfile, "optimized out");
684           break;
685
686         default:
687           fprintf_filtered (outfile, "botched symbol class %x",
688                             SYMBOL_CLASS (symbol));
689           break;
690         }
691     }
692   fprintf_filtered (outfile, "\n");
693   return 1;
694 }
695
696 void
697 maintenance_print_psymbols (args, from_tty)
698      char *args;
699      int from_tty;
700 {
701   char **argv;
702   GDB_FILE *outfile;
703   struct cleanup *cleanups;
704   char *symname = NULL;
705   char *filename = DEV_TTY;
706   struct objfile *objfile;
707   struct partial_symtab *ps;
708
709   dont_repeat ();
710
711   if (args == NULL)
712     {
713       error ("print-psymbols takes an output file name and optional symbol file name");
714     }
715   else if ((argv = buildargv (args)) == NULL)
716     {
717       nomem (0);
718     }
719   cleanups = make_cleanup (freeargv, (char *) argv);
720
721   if (argv[0] != NULL)
722     {
723       filename = argv[0];
724       /* If a second arg is supplied, it is a source file name to match on */
725       if (argv[1] != NULL)
726         {
727           symname = argv[1];
728         }
729     }
730
731   filename = tilde_expand (filename);
732   make_cleanup (free, filename);
733   
734   outfile = gdb_fopen (filename, FOPEN_WT);
735   if (outfile == 0)
736     perror_with_name (filename);
737   make_cleanup (fclose, outfile);
738
739   immediate_quit++;
740   ALL_PSYMTABS (objfile, ps)
741     if (symname == NULL || (STREQ (symname, ps -> filename)))
742       dump_psymtab (objfile, ps, outfile);
743   immediate_quit--;
744   do_cleanups (cleanups);
745 }
746
747 static void
748 print_partial_symbols (p, count, what, outfile)
749      struct partial_symbol **p;
750      int count;
751      char *what;
752      GDB_FILE *outfile;
753 {
754   fprintf_filtered (outfile, "  %s partial symbols:\n", what);
755   while (count-- > 0)
756     {
757       fprintf_filtered (outfile, "    `%s'", SYMBOL_NAME(*p));
758       if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
759         {
760           fprintf_filtered (outfile, "  `%s'", SYMBOL_DEMANGLED_NAME (*p));
761         }
762       fputs_filtered (", ", outfile);
763       switch (SYMBOL_NAMESPACE (*p))
764         {
765         case UNDEF_NAMESPACE:
766           fputs_filtered ("undefined namespace, ", outfile);
767           break;
768         case VAR_NAMESPACE:
769           /* This is the usual thing -- don't print it */
770           break;
771         case STRUCT_NAMESPACE:
772           fputs_filtered ("struct namespace, ", outfile);
773           break;
774         case LABEL_NAMESPACE:
775           fputs_filtered ("label namespace, ", outfile);
776           break;
777         default:
778           fputs_filtered ("<invalid namespace>, ", outfile);
779           break;
780         }
781       switch (SYMBOL_CLASS (*p))
782         {
783         case LOC_UNDEF:
784           fputs_filtered ("undefined", outfile);
785           break;
786         case LOC_CONST:
787           fputs_filtered ("constant int", outfile);
788           break;
789         case LOC_STATIC:
790           fputs_filtered ("static", outfile);
791           break;
792         case LOC_REGISTER:
793           fputs_filtered ("register", outfile);
794           break;
795         case LOC_ARG:
796           fputs_filtered ("pass by value", outfile);
797           break;
798         case LOC_REF_ARG:
799           fputs_filtered ("pass by reference", outfile);
800           break;
801         case LOC_REGPARM:
802           fputs_filtered ("register parameter", outfile);
803           break;
804         case LOC_REGPARM_ADDR:
805           fputs_filtered ("register address parameter", outfile);
806           break;
807         case LOC_LOCAL:
808           fputs_filtered ("stack parameter", outfile);
809           break;
810         case LOC_TYPEDEF:
811           fputs_filtered ("type", outfile);
812           break;
813         case LOC_LABEL:
814           fputs_filtered ("label", outfile);
815           break;
816         case LOC_BLOCK:
817           fputs_filtered ("function", outfile);
818           break;
819         case LOC_CONST_BYTES:
820           fputs_filtered ("constant bytes", outfile);
821           break;
822         case LOC_LOCAL_ARG:
823           fputs_filtered ("shuffled arg", outfile);
824           break;
825         case LOC_UNRESOLVED:
826           fputs_filtered ("unresolved", outfile);
827           break;
828         case LOC_OPTIMIZED_OUT:
829           fputs_filtered ("optimized out", outfile);
830           break;
831         default:
832           fputs_filtered ("<invalid location>", outfile);
833           break;
834         }
835       fputs_filtered (", ", outfile);
836       /* FIXME-32x64: Need to use SYMBOL_VALUE_ADDRESS, etc.; this
837          could be 32 bits when some of the other fields in the union
838          are 64.  */
839       fprintf_filtered (outfile, "0x%lx\n", SYMBOL_VALUE (*p));
840       p++;
841     }
842 }
843
844 void
845 maintenance_print_msymbols (args, from_tty)
846      char *args;
847      int from_tty;
848 {
849   char **argv;
850   GDB_FILE *outfile;
851   struct cleanup *cleanups;
852   char *filename = DEV_TTY;
853   char *symname = NULL;
854   struct objfile *objfile;
855
856   dont_repeat ();
857
858   if (args == NULL)
859     {
860       error ("print-msymbols takes an output file name and optional symbol file name");
861     }
862   else if ((argv = buildargv (args)) == NULL)
863     {
864       nomem (0);
865     }
866   cleanups = make_cleanup (freeargv, argv);
867
868   if (argv[0] != NULL)
869     {
870       filename = argv[0];
871       /* If a second arg is supplied, it is a source file name to match on */
872       if (argv[1] != NULL)
873         {
874           symname = argv[1];
875         }
876     }
877
878   filename = tilde_expand (filename);
879   make_cleanup (free, filename);
880   
881   outfile = gdb_fopen (filename, FOPEN_WT);
882   if (outfile == 0)
883     perror_with_name (filename);
884   make_cleanup (fclose, outfile);
885
886   immediate_quit++;
887   ALL_OBJFILES (objfile)
888     if (symname == NULL || (STREQ (symname, objfile -> name)))
889       dump_msymbols (objfile, outfile);
890   immediate_quit--;
891   fprintf_filtered (outfile, "\n\n");
892   do_cleanups (cleanups);
893 }
894
895 void
896 maintenance_print_objfiles (ignore, from_tty)
897      char *ignore;
898      int from_tty;
899 {
900   struct objfile *objfile;
901
902   dont_repeat ();
903
904   immediate_quit++;
905   ALL_OBJFILES (objfile)
906     dump_objfile (objfile);
907   immediate_quit--;
908 }
909
910 /* Check consistency of psymtabs and symtabs.  */
911
912 void
913 maintenance_check_symtabs (ignore, from_tty)
914      char *ignore;
915      int from_tty;
916 {
917   register struct symbol *sym;
918   register struct partial_symbol **psym;
919   register struct symtab *s = NULL;
920   register struct partial_symtab *ps;
921   struct blockvector *bv;
922   register struct objfile *objfile;
923   register struct block *b;
924   int length;
925
926   ALL_PSYMTABS (objfile, ps)
927     {
928       s = PSYMTAB_TO_SYMTAB(ps);
929       if (s == NULL)
930         continue;
931       bv = BLOCKVECTOR (s);
932       b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
933       psym = ps->objfile->static_psymbols.list + ps->statics_offset;
934       length = ps->n_static_syms;
935       while (length--)
936         {
937           sym = lookup_block_symbol (b, SYMBOL_NAME (*psym),
938                                      SYMBOL_NAMESPACE (*psym));
939           if (!sym)
940             {
941               printf_filtered ("Static symbol `");
942               puts_filtered (SYMBOL_NAME (*psym));
943               printf_filtered ("' only found in ");
944               puts_filtered (ps->filename);
945               printf_filtered (" psymtab\n");
946             }
947           psym++;
948         }
949       b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
950       psym = ps->objfile->global_psymbols.list + ps->globals_offset;
951       length = ps->n_global_syms;
952       while (length--)
953         {
954           sym = lookup_block_symbol (b, SYMBOL_NAME (*psym),
955                                      SYMBOL_NAMESPACE (*psym));
956           if (!sym)
957             {
958               printf_filtered ("Global symbol `");
959               puts_filtered (SYMBOL_NAME (*psym));
960               printf_filtered ("' only found in ");
961               puts_filtered (ps->filename);
962               printf_filtered (" psymtab\n");
963             }
964           psym++;
965         }
966       if (ps->texthigh < ps->textlow)
967         {
968           printf_filtered ("Psymtab ");
969           puts_filtered (ps->filename);
970           printf_filtered (" covers bad range ");
971           print_address_numeric (ps->textlow, 1, stdout);
972           printf_filtered (" - ");
973           print_address_numeric (ps->texthigh, 1, stdout);
974           printf_filtered ("\n");
975           continue;
976         }
977       if (ps->texthigh == 0)
978         continue;
979       if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
980         {
981           printf_filtered ("Psymtab ");
982           puts_filtered (ps->filename);
983           printf_filtered (" covers ");
984           print_address_numeric (ps->textlow, 1, stdout);
985           printf_filtered (" - ");
986           print_address_numeric (ps->texthigh, 1, stdout);
987           printf_filtered (" but symtab covers only ");
988           print_address_numeric (BLOCK_START (b), 1, stdout);
989           printf_filtered (" - ");
990           print_address_numeric (BLOCK_END (b), 1, stdout);
991           printf_filtered ("\n");
992         }
993     }
994 }
995
996 \f
997 /* Return the nexting depth of a block within other blocks in its symtab.  */
998
999 static int
1000 block_depth (block)
1001      struct block *block;
1002 {
1003   register int i = 0;
1004   while ((block = BLOCK_SUPERBLOCK (block)) != NULL) 
1005     {
1006       i++;
1007     }
1008   return i;
1009 }
1010
1011 #endif  /* MAINTENANCE_CMDS */
1012
1013 \f
1014 /* Increase the space allocated for LISTP, which is probably
1015    global_psymbols or static_psymbols. This space will eventually
1016    be freed in free_objfile().  */
1017
1018 void
1019 extend_psymbol_list (listp, objfile)
1020      register struct psymbol_allocation_list *listp;
1021      struct objfile *objfile;
1022 {
1023   int new_size;
1024   if (listp->size == 0)
1025     {
1026       new_size = 255;
1027       listp->list = (struct partial_symbol **)
1028         xmmalloc (objfile -> md, new_size * sizeof (struct partial_symbol *));
1029     }
1030   else
1031     {
1032       new_size = listp->size * 2;
1033       listp->list = (struct partial_symbol **)
1034         xmrealloc (objfile -> md, (char *) listp->list,
1035                    new_size * sizeof (struct partial_symbol *));
1036     }
1037   /* Next assumes we only went one over.  Should be good if
1038      program works correctly */
1039   listp->next = listp->list + listp->size;
1040   listp->size = new_size;
1041 }
1042
1043
1044 /* Do early runtime initializations. */
1045 void
1046 _initialize_symmisc ()
1047 {
1048   std_in  = stdin;
1049   std_out = stdout;
1050   std_err = stderr;
1051 }