]> Git Repo - binutils.git/blob - gdb/symmisc.c
* mipsread.c (parse_symbol, parse_type, cross_ref): Pass name of symbol
[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 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 #include "defs.h"
21 #include "symtab.h"
22 #include "gdbtypes.h"
23 #include "bfd.h"
24 #include "symfile.h"
25 #include "objfiles.h"
26 #include "breakpoint.h"
27 #include "command.h"
28 #include "obstack.h"
29 #include "language.h"
30
31 #include <string.h>
32
33 #ifndef DEV_TTY
34 #define DEV_TTY "/dev/tty"
35 #endif
36
37 /* Unfortunately for debugging, stderr is usually a macro.  This is painful
38    when calling functions that take FILE *'s from the debugger.
39    So we make a variable which has the same value and which is accessible when
40    debugging GDB with itself.  Because stdin et al need not be constants,
41    we initialize them in the _initialize_symmisc function at the bottom
42    of the file.  */
43 FILE *std_in;
44 FILE *std_out;
45 FILE *std_err;
46
47 /* Prototypes for local functions */
48
49 static void 
50 dump_symtab PARAMS ((struct objfile *, struct symtab *, FILE *));
51
52 static void 
53 dump_psymtab PARAMS ((struct objfile *, struct partial_symtab *, FILE *));
54
55 static void 
56 dump_msymbols PARAMS ((struct objfile *, FILE *));
57
58 static void 
59 dump_objfile PARAMS ((struct objfile *));
60
61 static int
62 block_depth PARAMS ((struct block *));
63
64 static void
65 print_partial_symbol PARAMS ((struct partial_symbol *, int, char *, FILE *));
66
67 static void
68 print_symbol PARAMS ((struct symbol *, int, FILE *));
69
70 static void
71 free_symtab_block PARAMS ((struct objfile *, struct block *));
72
73 \f
74 /* Free a struct block <- B and all the symbols defined in that block.  */
75
76 static void
77 free_symtab_block (objfile, b)
78      struct objfile *objfile;
79      struct block *b;
80 {
81   register int i, n;
82   n = BLOCK_NSYMS (b);
83   for (i = 0; i < n; i++)
84     {
85       mfree (objfile -> md, SYMBOL_NAME (BLOCK_SYM (b, i)));
86       mfree (objfile -> md, (PTR) BLOCK_SYM (b, i));
87     }
88   mfree (objfile -> md, (PTR) b);
89 }
90
91 /* Free all the storage associated with the struct symtab <- S.
92    Note that some symtabs have contents malloc'ed structure by structure,
93    while some have contents that all live inside one big block of memory,
94    and some share the contents of another symbol table and so you should
95    not free the contents on their behalf (except sometimes the linetable,
96    which maybe per symtab even when the rest is not).
97    It is s->free_code that says which alternative to use.  */
98
99 void
100 free_symtab (s)
101      register struct symtab *s;
102 {
103   register int i, n;
104   register struct blockvector *bv;
105
106   switch (s->free_code)
107     {
108     case free_nothing:
109       /* All the contents are part of a big block of memory (an obstack),
110          and some other symtab is in charge of freeing that block.
111          Therefore, do nothing.  */
112       break;
113
114     case free_contents:
115       /* Here all the contents were malloc'ed structure by structure
116          and must be freed that way.  */
117       /* First free the blocks (and their symbols.  */
118       bv = BLOCKVECTOR (s);
119       n = BLOCKVECTOR_NBLOCKS (bv);
120       for (i = 0; i < n; i++)
121         free_symtab_block (s -> objfile, BLOCKVECTOR_BLOCK (bv, i));
122       /* Free the blockvector itself.  */
123       mfree (s -> objfile -> md, (PTR) bv);
124       /* Also free the linetable.  */
125       
126     case free_linetable:
127       /* Everything will be freed either by our `free_ptr'
128          or by some other symtab, except for our linetable.
129          Free that now.  */
130       if (LINETABLE (s))
131         mfree (s -> objfile -> md, (PTR) LINETABLE (s));
132       break;
133     }
134
135   /* If there is a single block of memory to free, free it.  */
136   if (s -> free_ptr != NULL)
137     mfree (s -> objfile -> md, s -> free_ptr);
138
139   /* Free source-related stuff */
140   if (s -> line_charpos != NULL)
141     mfree (s -> objfile -> md, (PTR) s -> line_charpos);
142   if (s -> fullname != NULL)
143     mfree (s -> objfile -> md, s -> fullname);
144   mfree (s -> objfile -> md, (PTR) s);
145 }
146
147 #if MAINTENANCE_CMDS
148
149 static void 
150 dump_objfile (objfile)
151      struct objfile *objfile;
152 {
153   struct symtab *symtab;
154   struct partial_symtab *psymtab;
155
156   printf_filtered ("\nObject file %s:  ", objfile -> name);
157   printf_filtered ("Objfile at %x, bfd at %x, %d minsyms\n\n",
158                    objfile, objfile -> obfd, objfile->minimal_symbol_count);
159
160   if (objfile -> psymtabs)
161     {
162       printf_filtered ("Psymtabs:\n");
163       for (psymtab = objfile -> psymtabs;
164            psymtab != NULL;
165            psymtab = psymtab -> next)
166         {
167           printf_filtered ("%s at %x, ", psymtab -> filename, psymtab);
168           if (psymtab -> objfile != objfile)
169             {
170               printf_filtered ("NOT ON CHAIN!  ");
171             }
172           wrap_here ("  ");
173         }
174       printf_filtered ("\n\n");
175     }
176
177   if (objfile -> symtabs)
178     {
179       printf_filtered ("Symtabs:\n");
180       for (symtab = objfile -> symtabs;
181            symtab != NULL;
182            symtab = symtab->next)
183         {
184           printf_filtered ("%s at %x, ", symtab -> filename, symtab);
185           if (symtab -> objfile != objfile)
186             {
187               printf_filtered ("NOT ON CHAIN!  ");
188             }
189           wrap_here ("  ");
190         }
191       printf_filtered ("\n\n");
192     }
193 }
194
195 /* Print minimal symbols from this objfile.  */
196  
197 static void 
198 dump_msymbols (objfile, outfile)
199      struct objfile *objfile;
200      FILE *outfile;
201 {
202   struct minimal_symbol *msymbol;
203   int index;
204   char ms_type;
205   
206   fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile -> name);
207   if (objfile -> minimal_symbol_count == 0)
208     {
209       fprintf_filtered (outfile, "No minimal symbols found.\n");
210       return;
211     }
212   for (index = 0, msymbol = objfile -> msymbols;
213        SYMBOL_NAME (msymbol) != NULL; msymbol++, index++)
214     {
215       switch (msymbol -> type)
216         {
217           case mst_unknown:
218             ms_type = 'u';
219             break;
220           case mst_text:
221             ms_type = 'T';
222             break;
223           case mst_data:
224             ms_type = 'D';
225             break;
226           case mst_bss:
227             ms_type = 'B';
228             break;
229           case mst_abs:
230             ms_type = 'A';
231             break;
232           case mst_file_text:
233             ms_type = 't';
234             break;
235           case mst_file_data:
236             ms_type = 'd';
237             break;
238           case mst_file_bss:
239             ms_type = 'b';
240             break;
241           default:
242             ms_type = '?';
243             break;
244         }
245       fprintf_filtered (outfile, "[%2d] %c %#10x %s", index, ms_type,
246                         SYMBOL_VALUE_ADDRESS (msymbol), SYMBOL_NAME (msymbol));
247       if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
248         {
249           fprintf_filtered (outfile, "  %s", SYMBOL_DEMANGLED_NAME (msymbol));
250         }
251       fputs_filtered ("\n", outfile);
252     }
253   if (objfile -> minimal_symbol_count != index)
254     {
255       warning ("internal error:  minimal symbol count %d != %d",
256                objfile -> minimal_symbol_count, index);
257     }
258   fprintf_filtered (outfile, "\n");
259 }
260
261 static void
262 dump_psymtab (objfile, psymtab, outfile)
263      struct objfile *objfile;
264      struct partial_symtab *psymtab;
265      FILE *outfile;
266 {
267   int i;
268
269   fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
270                     psymtab -> filename);
271   fprintf_filtered (outfile, "(object 0x%x)\n\n", psymtab);
272   fprintf (outfile, "  Read from object file %s (0x%x)\n",
273            objfile -> name, (unsigned int) objfile);
274   
275   if (psymtab -> readin)
276     {
277       fprintf_filtered (outfile,
278                 "  Full symtab was read (at 0x%x by function at 0x%x)\n",
279                         psymtab -> symtab, psymtab -> read_symtab);
280     }
281
282   /* FIXME, we need to be able to print the relocation stuff. */
283   /* This prints some garbage for anything but stabs right now.  FIXME.  */
284   if (psymtab->section_offsets)
285     fprintf_filtered (outfile, "  Relocate symbols by 0x%x, 0x%x, 0x%x, 0x%x.\n",
286                       ANOFFSET (psymtab->section_offsets, 0),
287                       ANOFFSET (psymtab->section_offsets, 1),
288                       ANOFFSET (psymtab->section_offsets, 2),
289                       ANOFFSET (psymtab->section_offsets, 3));
290
291   fprintf_filtered (outfile, "  Symbols cover text addresses 0x%x-0x%x\n",
292                     psymtab -> textlow, psymtab -> texthigh);
293   fprintf_filtered (outfile, "  Depends on %d other partial symtabs.\n",
294                     psymtab -> number_of_dependencies);
295   for (i = 0; i < psymtab -> number_of_dependencies; i++)
296     {
297       fprintf_filtered (outfile, "    %d 0x%lx %s\n", i,
298                         (unsigned long) psymtab -> dependencies[i],
299                         psymtab -> dependencies[i] -> filename);
300     }
301   if (psymtab -> n_global_syms > 0)
302     {
303       print_partial_symbol (objfile -> global_psymbols.list
304                             + psymtab -> globals_offset,
305                             psymtab -> n_global_syms, "Global", outfile);
306     }
307   if (psymtab -> n_static_syms > 0)
308     {
309       print_partial_symbol (objfile -> static_psymbols.list
310                             + psymtab -> statics_offset,
311                             psymtab -> n_static_syms, "Static", outfile);
312     }
313   fprintf_filtered (outfile, "\n");
314 }
315
316 static void 
317 dump_symtab (objfile, symtab, outfile)
318      struct objfile *objfile;
319      struct symtab *symtab;
320      FILE *outfile;
321 {
322   register int i, j;
323   int len, blen;
324   register struct linetable *l;
325   struct blockvector *bv;
326   register struct block *b;
327   int depth;
328
329   fprintf (outfile, "\nSymtab for file %s\n", symtab->filename);
330   fprintf (outfile, "Read from object file %s (%x)\n", objfile->name,
331            (unsigned int) objfile);
332   fprintf (outfile, "Language: %s\n", language_str (symtab -> language));
333   
334   /* First print the line table.  */
335   l = LINETABLE (symtab);
336   if (l) {
337     fprintf (outfile, "\nLine table:\n\n");
338     len = l->nitems;
339     for (i = 0; i < len; i++)
340       fprintf (outfile, " line %d at %x\n", l->item[i].line,
341                l->item[i].pc);
342   }
343   /* Now print the block info.  */
344   fprintf (outfile, "\nBlockvector:\n\n");
345   bv = BLOCKVECTOR (symtab);
346   len = BLOCKVECTOR_NBLOCKS (bv);
347   for (i = 0; i < len; i++)
348     {
349       b = BLOCKVECTOR_BLOCK (bv, i);
350       depth = block_depth (b) * 2;
351       print_spaces (depth, outfile);
352       fprintf (outfile, "block #%03d (object 0x%x) ", i, (unsigned int) b);
353       fprintf (outfile, "[0x%x..0x%x]", BLOCK_START (b), BLOCK_END (b));
354       if (BLOCK_SUPERBLOCK (b))
355         fprintf (outfile, " (under 0x%x)", (unsigned int) BLOCK_SUPERBLOCK (b));
356       if (BLOCK_FUNCTION (b))
357         {
358           fprintf (outfile, " %s", SYMBOL_NAME (BLOCK_FUNCTION (b)));
359           if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
360             {
361               fprintf (outfile, " %s",
362                        SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
363             }
364         }
365       if (BLOCK_GCC_COMPILED(b))
366         fprintf (outfile, " gcc%d compiled", BLOCK_GCC_COMPILED(b));
367       fputc ('\n', outfile);
368       blen = BLOCK_NSYMS (b);
369       for (j = 0; j < blen; j++)
370         {
371           print_symbol (BLOCK_SYM (b, j), depth + 1, outfile);
372         }
373     }
374   fprintf (outfile, "\n");
375 }
376
377 void
378 maintenance_print_symbols (args, from_tty)
379      char *args;
380      int from_tty;
381 {
382   char **argv;
383   FILE *outfile;
384   struct cleanup *cleanups;
385   char *symname = NULL;
386   char *filename = DEV_TTY;
387   struct objfile *objfile;
388   struct symtab *s;
389
390   dont_repeat ();
391
392   if (args == NULL)
393     {
394       error ("print-symbols takes an output file name and optional symbol file name");
395     }
396   else if ((argv = buildargv (args)) == NULL)
397     {
398       nomem (0);
399     }
400   cleanups = make_cleanup (freeargv, (char *) argv);
401
402   if (argv[0] != NULL)
403     {
404       filename = argv[0];
405       /* If a second arg is supplied, it is a source file name to match on */
406       if (argv[1] != NULL)
407         {
408           symname = argv[1];
409         }
410     }
411
412   filename = tilde_expand (filename);
413   make_cleanup (free, filename);
414   
415   outfile = fopen (filename, FOPEN_WT);
416   if (outfile == 0)
417     perror_with_name (filename);
418   make_cleanup (fclose, (char *) outfile);
419
420   immediate_quit++;
421   ALL_SYMTABS (objfile, s)
422     if (symname == NULL || (STREQ (symname, s -> filename)))
423       dump_symtab (objfile, s, outfile);
424   immediate_quit--;
425   do_cleanups (cleanups);
426 }
427
428 static void
429 print_symbol (symbol, depth, outfile)
430      struct symbol *symbol;
431      int depth;
432      FILE *outfile;
433 {
434   print_spaces (depth, outfile);
435   if (SYMBOL_NAMESPACE (symbol) == LABEL_NAMESPACE)
436     {
437       fprintf (outfile, "label %s at 0x%x\n", SYMBOL_SOURCE_NAME (symbol),
438                SYMBOL_VALUE_ADDRESS (symbol));
439       return;
440     }
441   if (SYMBOL_NAMESPACE (symbol) == STRUCT_NAMESPACE)
442     {
443       if (TYPE_NAME (SYMBOL_TYPE (symbol)))
444         {
445           LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
446         }
447       else
448         {
449           fprintf (outfile, "%s %s = ",
450                (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
451                 ? "enum"
452                 : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
453                    ? "struct" : "union")),
454                SYMBOL_NAME (symbol));
455           LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
456         }
457       fprintf (outfile, ";\n");
458     }
459   else
460     {
461       if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
462         fprintf (outfile, "typedef ");
463       if (SYMBOL_TYPE (symbol))
464         {
465           /* Print details of types, except for enums where it's clutter.  */
466           LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_SOURCE_NAME (symbol),
467                          outfile,
468                          TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
469                          depth);
470           fprintf (outfile, "; ");
471         }
472       else
473         fprintf (outfile, "%s ", SYMBOL_SOURCE_NAME (symbol));
474
475       switch (SYMBOL_CLASS (symbol))
476         {
477         case LOC_CONST:
478           fprintf (outfile, "const %ld (0x%lx),",
479                    SYMBOL_VALUE (symbol), SYMBOL_VALUE (symbol));
480           break;
481
482         case LOC_CONST_BYTES:
483           fprintf (outfile, "const %u hex bytes:",
484                    TYPE_LENGTH (SYMBOL_TYPE (symbol)));
485           {
486             unsigned i;
487             for (i = 0; i < TYPE_LENGTH (SYMBOL_TYPE (symbol)); i++)
488               fprintf (outfile, " %2x",
489                          (unsigned)SYMBOL_VALUE_BYTES (symbol) [i]);
490             fprintf (outfile, ",");
491           }
492           break;
493
494         case LOC_STATIC:
495           fprintf (outfile, "static at 0x%x,", SYMBOL_VALUE_ADDRESS (symbol));
496           break;
497
498         case LOC_REGISTER:
499           fprintf (outfile, "register %ld,", SYMBOL_VALUE (symbol));
500           break;
501
502         case LOC_ARG:
503           if (SYMBOL_BASEREG_VALID (symbol))
504             {
505               fprintf (outfile, "arg at 0x%lx from register %d,",
506                        SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
507             }
508           else
509             {
510               fprintf (outfile, "arg at 0x%lx,", SYMBOL_VALUE (symbol));
511             }
512           break;
513
514         case LOC_LOCAL_ARG:
515           if (SYMBOL_BASEREG_VALID (symbol))
516             {
517               fprintf (outfile, "arg at offset 0x%lx from register %d,",
518                        SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
519             }
520           else
521             {
522               fprintf (outfile, "arg at offset 0x%lx from fp,",
523                        SYMBOL_VALUE (symbol));
524             }
525
526         case LOC_REF_ARG:
527           fprintf (outfile, "reference arg at 0x%lx,", SYMBOL_VALUE (symbol));
528           break;
529
530         case LOC_REGPARM:
531           fprintf (outfile, "parameter register %ld,", SYMBOL_VALUE (symbol));
532           break;
533
534         case LOC_REGPARM_ADDR:
535           fprintf (outfile, "address parameter register %ld,", SYMBOL_VALUE (symbol));
536           break;
537
538         case LOC_LOCAL:
539           if (SYMBOL_BASEREG_VALID (symbol))
540             {
541               fprintf (outfile, "local at 0x%lx from register %d",
542                        SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
543             }
544           else
545             {
546               fprintf (outfile, "local at 0x%lx,", SYMBOL_VALUE (symbol));
547             }
548           break;
549
550         case LOC_TYPEDEF:
551           break;
552
553         case LOC_LABEL:
554           fprintf (outfile, "label at 0x%lx", SYMBOL_VALUE_ADDRESS (symbol));
555           break;
556
557         case LOC_BLOCK:
558           fprintf (outfile, "block (object 0x%x) starting at 0x%x,",
559                    (unsigned int) SYMBOL_BLOCK_VALUE (symbol),
560                    BLOCK_START (SYMBOL_BLOCK_VALUE (symbol)));
561           break;
562
563         case LOC_OPTIMIZED_OUT:
564           fprintf (outfile, "optimized out");
565           break;
566
567         default:
568           fprintf (outfile, "botched symbol class %x", SYMBOL_CLASS (symbol));
569           break;
570         }
571     }
572   fprintf (outfile, "\n");
573 }
574
575 void
576 maintenance_print_psymbols (args, from_tty)
577      char *args;
578      int from_tty;
579 {
580   char **argv;
581   FILE *outfile;
582   struct cleanup *cleanups;
583   char *symname = NULL;
584   char *filename = DEV_TTY;
585   struct objfile *objfile;
586   struct partial_symtab *ps;
587
588   dont_repeat ();
589
590   if (args == NULL)
591     {
592       error ("print-psymbols takes an output file name and optional symbol file name");
593     }
594   else if ((argv = buildargv (args)) == NULL)
595     {
596       nomem (0);
597     }
598   cleanups = make_cleanup (freeargv, (char *) argv);
599
600   if (argv[0] != NULL)
601     {
602       filename = argv[0];
603       /* If a second arg is supplied, it is a source file name to match on */
604       if (argv[1] != NULL)
605         {
606           symname = argv[1];
607         }
608     }
609
610   filename = tilde_expand (filename);
611   make_cleanup (free, filename);
612   
613   outfile = fopen (filename, FOPEN_WT);
614   if (outfile == 0)
615     perror_with_name (filename);
616   make_cleanup (fclose, outfile);
617
618   immediate_quit++;
619   ALL_PSYMTABS (objfile, ps)
620     if (symname == NULL || (STREQ (symname, ps -> filename)))
621       dump_psymtab (objfile, ps, outfile);
622   immediate_quit--;
623   do_cleanups (cleanups);
624 }
625
626 static void
627 print_partial_symbol (p, count, what, outfile)
628      struct partial_symbol *p;
629      int count;
630      char *what;
631      FILE *outfile;
632 {
633
634   fprintf_filtered (outfile, "  %s partial symbols:\n", what);
635   while (count-- > 0)
636     {
637       fprintf_filtered (outfile, "    `%s'", SYMBOL_NAME(p));
638       if (SYMBOL_DEMANGLED_NAME (p) != NULL)
639         {
640           fprintf_filtered (outfile, "  `%s'", SYMBOL_DEMANGLED_NAME (p));
641         }
642       fputs_filtered (", ", outfile);
643       switch (SYMBOL_NAMESPACE (p))
644         {
645         case UNDEF_NAMESPACE:
646           fputs_filtered ("undefined namespace, ", outfile);
647           break;
648         case VAR_NAMESPACE:
649           /* This is the usual thing -- don't print it */
650           break;
651         case STRUCT_NAMESPACE:
652           fputs_filtered ("struct namespace, ", outfile);
653           break;
654         case LABEL_NAMESPACE:
655           fputs_filtered ("label namespace, ", outfile);
656           break;
657         default:
658           fputs_filtered ("<invalid namespace>, ", outfile);
659           break;
660         }
661       switch (SYMBOL_CLASS (p))
662         {
663         case LOC_UNDEF:
664           fputs_filtered ("undefined", outfile);
665           break;
666         case LOC_CONST:
667           fputs_filtered ("constant int", outfile);
668           break;
669         case LOC_STATIC:
670           fputs_filtered ("static", outfile);
671           break;
672         case LOC_REGISTER:
673           fputs_filtered ("register", outfile);
674           break;
675         case LOC_ARG:
676           fputs_filtered ("pass by value", outfile);
677           break;
678         case LOC_REF_ARG:
679           fputs_filtered ("pass by reference", outfile);
680           break;
681         case LOC_REGPARM:
682           fputs_filtered ("register parameter", outfile);
683           break;
684         case LOC_REGPARM_ADDR:
685           fputs_filtered ("register address parameter", outfile);
686           break;
687         case LOC_LOCAL:
688           fputs_filtered ("stack parameter", outfile);
689           break;
690         case LOC_TYPEDEF:
691           fputs_filtered ("type", outfile);
692           break;
693         case LOC_LABEL:
694           fputs_filtered ("label", outfile);
695           break;
696         case LOC_BLOCK:
697           fputs_filtered ("function", outfile);
698           break;
699         case LOC_CONST_BYTES:
700           fputs_filtered ("constant bytes", outfile);
701           break;
702         case LOC_LOCAL_ARG:
703           fputs_filtered ("shuffled arg", outfile);
704           break;
705         case LOC_OPTIMIZED_OUT:
706           fputs_filtered ("optimized out", outfile);
707           break;
708         default:
709           fputs_filtered ("<invalid location>", outfile);
710           break;
711         }
712       fputs_filtered (", ", outfile);
713       fprintf_filtered (outfile, "0x%x\n", SYMBOL_VALUE (p));
714       p++;
715     }
716 }
717
718 void
719 maintenance_print_msymbols (args, from_tty)
720      char *args;
721      int from_tty;
722 {
723   char **argv;
724   FILE *outfile;
725   struct cleanup *cleanups;
726   char *filename = DEV_TTY;
727   char *symname = NULL;
728   struct objfile *objfile;
729
730   dont_repeat ();
731
732   if (args == NULL)
733     {
734       error ("print-msymbols takes an output file name and optional symbol file name");
735     }
736   else if ((argv = buildargv (args)) == NULL)
737     {
738       nomem (0);
739     }
740   cleanups = make_cleanup (freeargv, argv);
741
742   if (argv[0] != NULL)
743     {
744       filename = argv[0];
745       /* If a second arg is supplied, it is a source file name to match on */
746       if (argv[1] != NULL)
747         {
748           symname = argv[1];
749         }
750     }
751
752   filename = tilde_expand (filename);
753   make_cleanup (free, filename);
754   
755   outfile = fopen (filename, FOPEN_WT);
756   if (outfile == 0)
757     perror_with_name (filename);
758   make_cleanup (fclose, outfile);
759
760   immediate_quit++;
761   ALL_OBJFILES (objfile)
762     if (symname == NULL || (STREQ (symname, objfile -> name)))
763       dump_msymbols (objfile, outfile);
764   immediate_quit--;
765   fprintf_filtered (outfile, "\n\n");
766   do_cleanups (cleanups);
767 }
768
769 void
770 maintenance_print_objfiles (ignore, from_tty)
771      char *ignore;
772      int from_tty;
773 {
774   struct objfile *objfile;
775
776   dont_repeat ();
777
778   immediate_quit++;
779   ALL_OBJFILES (objfile)
780     dump_objfile (objfile);
781   immediate_quit--;
782 }
783
784 \f
785 /* Return the nexting depth of a block within other blocks in its symtab.  */
786
787 static int
788 block_depth (block)
789      struct block *block;
790 {
791   register int i = 0;
792   while ((block = BLOCK_SUPERBLOCK (block)) != NULL) 
793     {
794       i++;
795     }
796   return i;
797 }
798
799 #endif  /* MAINTENANCE_CMDS */
800
801 \f
802 /* Increase the space allocated for LISTP, which is probably
803    global_psymbol_list or static_psymbol_list. This space will eventually
804    be freed in free_objfile().  */
805
806 void
807 extend_psymbol_list (listp, objfile)
808      register struct psymbol_allocation_list *listp;
809      struct objfile *objfile;
810 {
811   int new_size;
812   if (listp->size == 0)
813     {
814       new_size = 255;
815       listp->list = (struct partial_symbol *)
816         xmmalloc (objfile -> md, new_size * sizeof (struct partial_symbol));
817     }
818   else
819     {
820       new_size = listp->size * 2;
821       listp->list = (struct partial_symbol *)
822         xmrealloc (objfile -> md, (char *) listp->list,
823                    new_size * sizeof (struct partial_symbol));
824     }
825   /* Next assumes we only went one over.  Should be good if
826      program works correctly */
827   listp->next = listp->list + listp->size;
828   listp->size = new_size;
829 }
830
831
832 /* Do early runtime initializations. */
833 void
834 _initialize_symmisc ()
835 {
836   std_in  = stdin;
837   std_out = stdout;
838   std_err = stderr;
839 }
This page took 0.070894 seconds and 4 git commands to generate.