1 /* Do various things to symbol tables (other than lookup), for GDB.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003 Free Software
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
30 #include "breakpoint.h"
32 #include "gdb_obstack.h"
37 #include "gdb_string.h"
38 #include <readline/readline.h>
41 #define DEV_TTY "/dev/tty"
44 /* Unfortunately for debugging, stderr is usually a macro. This is painful
45 when calling functions that take FILE *'s from the debugger.
46 So we make a variable which has the same value and which is accessible when
47 debugging GDB with itself. Because stdin et al need not be constants,
48 we initialize them in the _initialize_symmisc function at the bottom
54 /* Prototypes for local functions */
56 static void dump_symtab (struct objfile *, struct symtab *,
59 static void dump_psymtab (struct objfile *, struct partial_symtab *,
62 static void dump_msymbols (struct objfile *, struct ui_file *);
64 static void dump_objfile (struct objfile *);
66 static int block_depth (struct block *);
68 static void print_partial_symbols (struct partial_symbol **, int,
69 char *, struct ui_file *);
71 static void free_symtab_block (struct objfile *, struct block *);
73 void _initialize_symmisc (void);
75 struct print_symbol_args
77 struct symbol *symbol;
79 struct ui_file *outfile;
82 static int print_symbol (void *);
84 static void free_symtab_block (struct objfile *, struct block *);
87 /* Free a struct block <- B and all the symbols defined in that block. */
90 free_symtab_block (struct objfile *objfile, struct block *b)
93 struct symbol *sym, *next_sym;
95 n = BLOCK_BUCKETS (b);
96 for (i = 0; i < n; i++)
98 for (sym = BLOCK_BUCKET (b, i); sym; sym = next_sym)
100 next_sym = sym->hash_next;
101 xmfree (objfile->md, DEPRECATED_SYMBOL_NAME (sym));
102 xmfree (objfile->md, sym);
105 xmfree (objfile->md, b);
108 /* Free all the storage associated with the struct symtab <- S.
109 Note that some symtabs have contents malloc'ed structure by structure,
110 while some have contents that all live inside one big block of memory,
111 and some share the contents of another symbol table and so you should
112 not free the contents on their behalf (except sometimes the linetable,
113 which maybe per symtab even when the rest is not).
114 It is s->free_code that says which alternative to use. */
117 free_symtab (register struct symtab *s)
120 register struct blockvector *bv;
122 switch (s->free_code)
125 /* All the contents are part of a big block of memory (an obstack),
126 and some other symtab is in charge of freeing that block.
127 Therefore, do nothing. */
131 /* Here all the contents were malloc'ed structure by structure
132 and must be freed that way. */
133 /* First free the blocks (and their symbols. */
134 bv = BLOCKVECTOR (s);
135 n = BLOCKVECTOR_NBLOCKS (bv);
136 for (i = 0; i < n; i++)
137 free_symtab_block (s->objfile, BLOCKVECTOR_BLOCK (bv, i));
138 /* Free the blockvector itself. */
139 xmfree (s->objfile->md, bv);
140 /* Also free the linetable. */
143 /* Everything will be freed either by our `free_ptr'
144 or by some other symtab, except for our linetable.
147 xmfree (s->objfile->md, LINETABLE (s));
151 /* If there is a single block of memory to free, free it. */
152 if (s->free_ptr != NULL)
153 xmfree (s->objfile->md, s->free_ptr);
155 /* Free source-related stuff */
156 if (s->line_charpos != NULL)
157 xmfree (s->objfile->md, s->line_charpos);
158 if (s->fullname != NULL)
159 xmfree (s->objfile->md, s->fullname);
160 if (s->debugformat != NULL)
161 xmfree (s->objfile->md, s->debugformat);
162 xmfree (s->objfile->md, s);
166 print_symbol_bcache_statistics (void)
168 struct objfile *objfile;
171 ALL_OBJFILES (objfile)
173 printf_filtered ("Byte cache statistics for '%s':\n", objfile->name);
174 print_bcache_statistics (objfile->psymbol_cache, "partial symbol cache");
180 print_objfile_statistics (void)
182 struct objfile *objfile;
184 struct partial_symtab *ps;
185 int i, linetables, blockvectors;
188 ALL_OBJFILES (objfile)
190 printf_filtered ("Statistics for '%s':\n", objfile->name);
191 if (OBJSTAT (objfile, n_stabs) > 0)
192 printf_filtered (" Number of \"stab\" symbols read: %d\n",
193 OBJSTAT (objfile, n_stabs));
194 if (OBJSTAT (objfile, n_minsyms) > 0)
195 printf_filtered (" Number of \"minimal\" symbols read: %d\n",
196 OBJSTAT (objfile, n_minsyms));
197 if (OBJSTAT (objfile, n_psyms) > 0)
198 printf_filtered (" Number of \"partial\" symbols read: %d\n",
199 OBJSTAT (objfile, n_psyms));
200 if (OBJSTAT (objfile, n_syms) > 0)
201 printf_filtered (" Number of \"full\" symbols read: %d\n",
202 OBJSTAT (objfile, n_syms));
203 if (OBJSTAT (objfile, n_types) > 0)
204 printf_filtered (" Number of \"types\" defined: %d\n",
205 OBJSTAT (objfile, n_types));
207 ALL_OBJFILE_PSYMTABS (objfile, ps)
212 printf_filtered (" Number of psym tables (not yet expanded): %d\n", i);
213 i = linetables = blockvectors = 0;
214 ALL_OBJFILE_SYMTABS (objfile, s)
217 if (s->linetable != NULL)
222 printf_filtered (" Number of symbol tables: %d\n", i);
223 printf_filtered (" Number of symbol tables with line tables: %d\n",
225 printf_filtered (" Number of symbol tables with blockvectors: %d\n",
228 if (OBJSTAT (objfile, sz_strtab) > 0)
229 printf_filtered (" Space used by a.out string tables: %d\n",
230 OBJSTAT (objfile, sz_strtab));
231 printf_filtered (" Total memory used for psymbol obstack: %d\n",
232 obstack_memory_used (&objfile->psymbol_obstack));
233 printf_filtered (" Total memory used for psymbol cache: %d\n",
234 bcache_memory_used (objfile->psymbol_cache));
235 printf_filtered (" Total memory used for macro cache: %d\n",
236 bcache_memory_used (objfile->macro_cache));
237 printf_filtered (" Total memory used for symbol obstack: %d\n",
238 obstack_memory_used (&objfile->symbol_obstack));
239 printf_filtered (" Total memory used for type obstack: %d\n",
240 obstack_memory_used (&objfile->type_obstack));
246 dump_objfile (struct objfile *objfile)
248 struct symtab *symtab;
249 struct partial_symtab *psymtab;
251 printf_filtered ("\nObject file %s: ", objfile->name);
252 printf_filtered ("Objfile at ");
253 gdb_print_host_address (objfile, gdb_stdout);
254 printf_filtered (", bfd at ");
255 gdb_print_host_address (objfile->obfd, gdb_stdout);
256 printf_filtered (", %d minsyms\n\n",
257 objfile->minimal_symbol_count);
259 if (objfile->psymtabs)
261 printf_filtered ("Psymtabs:\n");
262 for (psymtab = objfile->psymtabs;
264 psymtab = psymtab->next)
266 printf_filtered ("%s at ",
268 gdb_print_host_address (psymtab, gdb_stdout);
269 printf_filtered (", ");
270 if (psymtab->objfile != objfile)
272 printf_filtered ("NOT ON CHAIN! ");
276 printf_filtered ("\n\n");
279 if (objfile->symtabs)
281 printf_filtered ("Symtabs:\n");
282 for (symtab = objfile->symtabs;
284 symtab = symtab->next)
286 printf_filtered ("%s at ", symtab->filename);
287 gdb_print_host_address (symtab, gdb_stdout);
288 printf_filtered (", ");
289 if (symtab->objfile != objfile)
291 printf_filtered ("NOT ON CHAIN! ");
295 printf_filtered ("\n\n");
299 /* Print minimal symbols from this objfile. */
302 dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
304 struct minimal_symbol *msymbol;
308 fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile->name);
309 if (objfile->minimal_symbol_count == 0)
311 fprintf_filtered (outfile, "No minimal symbols found.\n");
314 for (index = 0, msymbol = objfile->msymbols;
315 DEPRECATED_SYMBOL_NAME (msymbol) != NULL; msymbol++, index++)
317 switch (msymbol->type)
325 case mst_solib_trampoline:
350 fprintf_filtered (outfile, "[%2d] %c ", index, ms_type);
351 print_address_numeric (SYMBOL_VALUE_ADDRESS (msymbol), 1, outfile);
352 fprintf_filtered (outfile, " %s", DEPRECATED_SYMBOL_NAME (msymbol));
353 if (SYMBOL_BFD_SECTION (msymbol))
354 fprintf_filtered (outfile, " section %s",
355 bfd_section_name (objfile->obfd,
356 SYMBOL_BFD_SECTION (msymbol)));
357 if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
359 fprintf_filtered (outfile, " %s", SYMBOL_DEMANGLED_NAME (msymbol));
361 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
362 if (msymbol->filename)
363 fprintf_filtered (outfile, " %s", msymbol->filename);
365 fputs_filtered ("\n", outfile);
367 if (objfile->minimal_symbol_count != index)
369 warning ("internal error: minimal symbol count %d != %d",
370 objfile->minimal_symbol_count, index);
372 fprintf_filtered (outfile, "\n");
376 dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
377 struct ui_file *outfile)
381 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
383 fprintf_filtered (outfile, "(object ");
384 gdb_print_host_address (psymtab, outfile);
385 fprintf_filtered (outfile, ")\n\n");
386 fprintf_unfiltered (outfile, " Read from object file %s (",
388 gdb_print_host_address (objfile, outfile);
389 fprintf_unfiltered (outfile, ")\n");
393 fprintf_filtered (outfile,
394 " Full symtab was read (at ");
395 gdb_print_host_address (psymtab->symtab, outfile);
396 fprintf_filtered (outfile, " by function at ");
397 gdb_print_host_address (psymtab->read_symtab, outfile);
398 fprintf_filtered (outfile, ")\n");
401 fprintf_filtered (outfile, " Relocate symbols by ");
402 for (i = 0; i < psymtab->objfile->num_sections; ++i)
405 fprintf_filtered (outfile, ", ");
407 print_address_numeric (ANOFFSET (psymtab->section_offsets, i),
411 fprintf_filtered (outfile, "\n");
413 fprintf_filtered (outfile, " Symbols cover text addresses ");
414 print_address_numeric (psymtab->textlow, 1, outfile);
415 fprintf_filtered (outfile, "-");
416 print_address_numeric (psymtab->texthigh, 1, outfile);
417 fprintf_filtered (outfile, "\n");
418 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
419 psymtab->number_of_dependencies);
420 for (i = 0; i < psymtab->number_of_dependencies; i++)
422 fprintf_filtered (outfile, " %d ", i);
423 gdb_print_host_address (psymtab->dependencies[i], outfile);
424 fprintf_filtered (outfile, " %s\n",
425 psymtab->dependencies[i]->filename);
427 if (psymtab->n_global_syms > 0)
429 print_partial_symbols (objfile->global_psymbols.list
430 + psymtab->globals_offset,
431 psymtab->n_global_syms, "Global", outfile);
433 if (psymtab->n_static_syms > 0)
435 print_partial_symbols (objfile->static_psymbols.list
436 + psymtab->statics_offset,
437 psymtab->n_static_syms, "Static", outfile);
439 fprintf_filtered (outfile, "\n");
443 dump_symtab (struct objfile *objfile, struct symtab *symtab,
444 struct ui_file *outfile)
448 register struct linetable *l;
449 struct blockvector *bv;
451 register struct block *b;
454 fprintf_filtered (outfile, "\nSymtab for file %s\n", symtab->filename);
456 fprintf_filtered (outfile, "Compilation directory is %s\n",
458 fprintf_filtered (outfile, "Read from object file %s (", objfile->name);
459 gdb_print_host_address (objfile, outfile);
460 fprintf_filtered (outfile, ")\n");
461 fprintf_filtered (outfile, "Language: %s\n", language_str (symtab->language));
463 /* First print the line table. */
464 l = LINETABLE (symtab);
467 fprintf_filtered (outfile, "\nLine table:\n\n");
469 for (i = 0; i < len; i++)
471 fprintf_filtered (outfile, " line %d at ", l->item[i].line);
472 print_address_numeric (l->item[i].pc, 1, outfile);
473 fprintf_filtered (outfile, "\n");
476 /* Now print the block info, but only for primary symtabs since we will
477 print lots of duplicate info otherwise. */
480 fprintf_filtered (outfile, "\nBlockvector:\n\n");
481 bv = BLOCKVECTOR (symtab);
482 len = BLOCKVECTOR_NBLOCKS (bv);
483 for (i = 0; i < len; i++)
485 b = BLOCKVECTOR_BLOCK (bv, i);
486 depth = block_depth (b) * 2;
487 print_spaces (depth, outfile);
488 fprintf_filtered (outfile, "block #%03d, object at ", i);
489 gdb_print_host_address (b, outfile);
490 if (BLOCK_SUPERBLOCK (b))
492 fprintf_filtered (outfile, " under ");
493 gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile);
495 /* drow/2002-07-10: We could save the total symbols count
496 even if we're using a hashtable, but nothing else but this message
498 blen = BLOCK_BUCKETS (b);
499 if (BLOCK_HASHTABLE (b))
500 fprintf_filtered (outfile, ", %d buckets in ", blen);
502 fprintf_filtered (outfile, ", %d syms in ", blen);
503 print_address_numeric (BLOCK_START (b), 1, outfile);
504 fprintf_filtered (outfile, "..");
505 print_address_numeric (BLOCK_END (b), 1, outfile);
506 if (BLOCK_FUNCTION (b))
508 fprintf_filtered (outfile, ", function %s", DEPRECATED_SYMBOL_NAME (BLOCK_FUNCTION (b)));
509 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
511 fprintf_filtered (outfile, ", %s",
512 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
515 if (BLOCK_GCC_COMPILED (b))
516 fprintf_filtered (outfile, ", compiled with gcc%d", BLOCK_GCC_COMPILED (b));
517 fprintf_filtered (outfile, "\n");
518 /* Now print each symbol in this block (in no particular order, if
519 we're using a hashtable). */
520 ALL_BLOCK_SYMBOLS (b, j, sym)
522 struct print_symbol_args s;
526 catch_errors (print_symbol, &s, "Error printing symbol:\n",
530 fprintf_filtered (outfile, "\n");
534 fprintf_filtered (outfile, "\nBlockvector same as previous symtab\n\n");
539 maintenance_print_symbols (char *args, int from_tty)
542 struct ui_file *outfile;
543 struct cleanup *cleanups;
544 char *symname = NULL;
545 char *filename = DEV_TTY;
546 struct objfile *objfile;
554 Arguments missing: an output file name and an optional symbol file name");
556 else if ((argv = buildargv (args)) == NULL)
560 cleanups = make_cleanup_freeargv (argv);
565 /* If a second arg is supplied, it is a source file name to match on */
572 filename = tilde_expand (filename);
573 make_cleanup (xfree, filename);
575 outfile = gdb_fopen (filename, FOPEN_WT);
577 perror_with_name (filename);
578 make_cleanup_ui_file_delete (outfile);
581 ALL_SYMTABS (objfile, s)
582 if (symname == NULL || (STREQ (symname, s->filename)))
583 dump_symtab (objfile, s, outfile);
585 do_cleanups (cleanups);
588 /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
589 far to indent. ARGS is really a struct print_symbol_args *, but is
590 declared as char * to get it past catch_errors. Returns 0 for error,
594 print_symbol (void *args)
596 struct symbol *symbol = ((struct print_symbol_args *) args)->symbol;
597 int depth = ((struct print_symbol_args *) args)->depth;
598 struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile;
600 print_spaces (depth, outfile);
601 if (SYMBOL_NAMESPACE (symbol) == LABEL_NAMESPACE)
603 fprintf_filtered (outfile, "label %s at ", SYMBOL_PRINT_NAME (symbol));
604 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
605 if (SYMBOL_BFD_SECTION (symbol))
606 fprintf_filtered (outfile, " section %s\n",
607 bfd_section_name (SYMBOL_BFD_SECTION (symbol)->owner,
608 SYMBOL_BFD_SECTION (symbol)));
610 fprintf_filtered (outfile, "\n");
613 if (SYMBOL_NAMESPACE (symbol) == STRUCT_NAMESPACE)
615 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
617 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
621 fprintf_filtered (outfile, "%s %s = ",
622 (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
624 : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
625 ? "struct" : "union")),
626 DEPRECATED_SYMBOL_NAME (symbol));
627 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
629 fprintf_filtered (outfile, ";\n");
633 if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
634 fprintf_filtered (outfile, "typedef ");
635 if (SYMBOL_TYPE (symbol))
637 /* Print details of types, except for enums where it's clutter. */
638 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_PRINT_NAME (symbol),
640 TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
642 fprintf_filtered (outfile, "; ");
645 fprintf_filtered (outfile, "%s ", SYMBOL_PRINT_NAME (symbol));
647 switch (SYMBOL_CLASS (symbol))
650 fprintf_filtered (outfile, "const %ld (0x%lx)",
651 SYMBOL_VALUE (symbol),
652 SYMBOL_VALUE (symbol));
655 case LOC_CONST_BYTES:
658 struct type *type = check_typedef (SYMBOL_TYPE (symbol));
659 fprintf_filtered (outfile, "const %u hex bytes:",
661 for (i = 0; i < TYPE_LENGTH (type); i++)
662 fprintf_filtered (outfile, " %02x",
663 (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]);
668 fprintf_filtered (outfile, "static at ");
669 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
670 if (SYMBOL_BFD_SECTION (symbol))
671 fprintf_filtered (outfile, " section %s",
673 (SYMBOL_BFD_SECTION (symbol)->owner,
674 SYMBOL_BFD_SECTION (symbol)));
678 fprintf_filtered (outfile, "extern global at *(");
679 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
680 fprintf_filtered (outfile, "),");
684 fprintf_filtered (outfile, "register %ld", SYMBOL_VALUE (symbol));
688 fprintf_filtered (outfile, "arg at offset 0x%lx",
689 SYMBOL_VALUE (symbol));
693 fprintf_filtered (outfile, "arg at offset 0x%lx from fp",
694 SYMBOL_VALUE (symbol));
698 fprintf_filtered (outfile, "reference arg at 0x%lx", SYMBOL_VALUE (symbol));
702 fprintf_filtered (outfile, "parameter register %ld", SYMBOL_VALUE (symbol));
705 case LOC_REGPARM_ADDR:
706 fprintf_filtered (outfile, "address parameter register %ld", SYMBOL_VALUE (symbol));
710 fprintf_filtered (outfile, "local at offset 0x%lx",
711 SYMBOL_VALUE (symbol));
715 fprintf_filtered (outfile, "local at 0x%lx from register %d",
716 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
719 case LOC_BASEREG_ARG:
720 fprintf_filtered (outfile, "arg at 0x%lx from register %d",
721 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
728 fprintf_filtered (outfile, "label at ");
729 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
730 if (SYMBOL_BFD_SECTION (symbol))
731 fprintf_filtered (outfile, " section %s",
733 (SYMBOL_BFD_SECTION (symbol)->owner,
734 SYMBOL_BFD_SECTION (symbol)));
738 fprintf_filtered (outfile, "block object ");
739 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
740 fprintf_filtered (outfile, ", ");
741 print_address_numeric (BLOCK_START (SYMBOL_BLOCK_VALUE (symbol)),
744 fprintf_filtered (outfile, "..");
745 print_address_numeric (BLOCK_END (SYMBOL_BLOCK_VALUE (symbol)),
748 if (SYMBOL_BFD_SECTION (symbol))
749 fprintf_filtered (outfile, " section %s",
751 (SYMBOL_BFD_SECTION (symbol)->owner,
752 SYMBOL_BFD_SECTION (symbol)));
756 case LOC_COMPUTED_ARG:
757 fprintf_filtered (outfile, "computed at runtime");
761 fprintf_filtered (outfile, "unresolved");
764 case LOC_OPTIMIZED_OUT:
765 fprintf_filtered (outfile, "optimized out");
769 fprintf_filtered (outfile, "botched symbol class %x",
770 SYMBOL_CLASS (symbol));
774 fprintf_filtered (outfile, "\n");
779 maintenance_print_psymbols (char *args, int from_tty)
782 struct ui_file *outfile;
783 struct cleanup *cleanups;
784 char *symname = NULL;
785 char *filename = DEV_TTY;
786 struct objfile *objfile;
787 struct partial_symtab *ps;
793 error ("print-psymbols takes an output file name and optional symbol file name");
795 else if ((argv = buildargv (args)) == NULL)
799 cleanups = make_cleanup_freeargv (argv);
804 /* If a second arg is supplied, it is a source file name to match on */
811 filename = tilde_expand (filename);
812 make_cleanup (xfree, filename);
814 outfile = gdb_fopen (filename, FOPEN_WT);
816 perror_with_name (filename);
817 make_cleanup_ui_file_delete (outfile);
820 ALL_PSYMTABS (objfile, ps)
821 if (symname == NULL || (STREQ (symname, ps->filename)))
822 dump_psymtab (objfile, ps, outfile);
824 do_cleanups (cleanups);
828 print_partial_symbols (struct partial_symbol **p, int count, char *what,
829 struct ui_file *outfile)
831 fprintf_filtered (outfile, " %s partial symbols:\n", what);
834 fprintf_filtered (outfile, " `%s'", DEPRECATED_SYMBOL_NAME (*p));
835 if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
837 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
839 fputs_filtered (", ", outfile);
840 switch (SYMBOL_NAMESPACE (*p))
842 case UNDEF_NAMESPACE:
843 fputs_filtered ("undefined namespace, ", outfile);
846 /* This is the usual thing -- don't print it */
848 case STRUCT_NAMESPACE:
849 fputs_filtered ("struct namespace, ", outfile);
851 case LABEL_NAMESPACE:
852 fputs_filtered ("label namespace, ", outfile);
855 fputs_filtered ("<invalid namespace>, ", outfile);
858 switch (SYMBOL_CLASS (*p))
861 fputs_filtered ("undefined", outfile);
864 fputs_filtered ("constant int", outfile);
867 fputs_filtered ("static", outfile);
870 fputs_filtered ("extern global", outfile);
873 fputs_filtered ("register", outfile);
876 fputs_filtered ("pass by value", outfile);
879 fputs_filtered ("pass by reference", outfile);
882 fputs_filtered ("register parameter", outfile);
884 case LOC_REGPARM_ADDR:
885 fputs_filtered ("register address parameter", outfile);
888 fputs_filtered ("stack parameter", outfile);
891 fputs_filtered ("type", outfile);
894 fputs_filtered ("label", outfile);
897 fputs_filtered ("function", outfile);
899 case LOC_CONST_BYTES:
900 fputs_filtered ("constant bytes", outfile);
903 fputs_filtered ("shuffled arg", outfile);
906 fputs_filtered ("unresolved", outfile);
908 case LOC_OPTIMIZED_OUT:
909 fputs_filtered ("optimized out", outfile);
912 case LOC_COMPUTED_ARG:
913 fputs_filtered ("computed at runtime", outfile);
916 fputs_filtered ("<invalid location>", outfile);
919 fputs_filtered (", ", outfile);
920 print_address_numeric (SYMBOL_VALUE_ADDRESS (*p), 1, outfile);
921 fprintf_filtered (outfile, "\n");
927 maintenance_print_msymbols (char *args, int from_tty)
930 struct ui_file *outfile;
931 struct cleanup *cleanups;
932 char *filename = DEV_TTY;
933 char *symname = NULL;
934 struct objfile *objfile;
940 error ("print-msymbols takes an output file name and optional symbol file name");
942 else if ((argv = buildargv (args)) == NULL)
946 cleanups = make_cleanup_freeargv (argv);
951 /* If a second arg is supplied, it is a source file name to match on */
958 filename = tilde_expand (filename);
959 make_cleanup (xfree, filename);
961 outfile = gdb_fopen (filename, FOPEN_WT);
963 perror_with_name (filename);
964 make_cleanup_ui_file_delete (outfile);
967 ALL_OBJFILES (objfile)
968 if (symname == NULL || (STREQ (symname, objfile->name)))
969 dump_msymbols (objfile, outfile);
971 fprintf_filtered (outfile, "\n\n");
972 do_cleanups (cleanups);
976 maintenance_print_objfiles (char *ignore, int from_tty)
978 struct objfile *objfile;
983 ALL_OBJFILES (objfile)
984 dump_objfile (objfile);
988 /* Check consistency of psymtabs and symtabs. */
991 maintenance_check_symtabs (char *ignore, int from_tty)
993 register struct symbol *sym;
994 register struct partial_symbol **psym;
995 register struct symtab *s = NULL;
996 register struct partial_symtab *ps;
997 struct blockvector *bv;
998 register struct objfile *objfile;
999 register struct block *b;
1002 ALL_PSYMTABS (objfile, ps)
1004 s = PSYMTAB_TO_SYMTAB (ps);
1007 bv = BLOCKVECTOR (s);
1008 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1009 psym = ps->objfile->static_psymbols.list + ps->statics_offset;
1010 length = ps->n_static_syms;
1013 sym = lookup_block_symbol (b, DEPRECATED_SYMBOL_NAME (*psym),
1014 NULL, SYMBOL_NAMESPACE (*psym));
1017 printf_filtered ("Static symbol `");
1018 puts_filtered (DEPRECATED_SYMBOL_NAME (*psym));
1019 printf_filtered ("' only found in ");
1020 puts_filtered (ps->filename);
1021 printf_filtered (" psymtab\n");
1025 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1026 psym = ps->objfile->global_psymbols.list + ps->globals_offset;
1027 length = ps->n_global_syms;
1030 sym = lookup_block_symbol (b, DEPRECATED_SYMBOL_NAME (*psym),
1031 NULL, SYMBOL_NAMESPACE (*psym));
1034 printf_filtered ("Global symbol `");
1035 puts_filtered (DEPRECATED_SYMBOL_NAME (*psym));
1036 printf_filtered ("' only found in ");
1037 puts_filtered (ps->filename);
1038 printf_filtered (" psymtab\n");
1042 if (ps->texthigh < ps->textlow)
1044 printf_filtered ("Psymtab ");
1045 puts_filtered (ps->filename);
1046 printf_filtered (" covers bad range ");
1047 print_address_numeric (ps->textlow, 1, gdb_stdout);
1048 printf_filtered (" - ");
1049 print_address_numeric (ps->texthigh, 1, gdb_stdout);
1050 printf_filtered ("\n");
1053 if (ps->texthigh == 0)
1055 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
1057 printf_filtered ("Psymtab ");
1058 puts_filtered (ps->filename);
1059 printf_filtered (" covers ");
1060 print_address_numeric (ps->textlow, 1, gdb_stdout);
1061 printf_filtered (" - ");
1062 print_address_numeric (ps->texthigh, 1, gdb_stdout);
1063 printf_filtered (" but symtab covers only ");
1064 print_address_numeric (BLOCK_START (b), 1, gdb_stdout);
1065 printf_filtered (" - ");
1066 print_address_numeric (BLOCK_END (b), 1, gdb_stdout);
1067 printf_filtered ("\n");
1073 /* Return the nexting depth of a block within other blocks in its symtab. */
1076 block_depth (struct block *block)
1079 while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
1087 /* Increase the space allocated for LISTP, which is probably
1088 global_psymbols or static_psymbols. This space will eventually
1089 be freed in free_objfile(). */
1092 extend_psymbol_list (register struct psymbol_allocation_list *listp,
1093 struct objfile *objfile)
1096 if (listp->size == 0)
1099 listp->list = (struct partial_symbol **)
1100 xmmalloc (objfile->md, new_size * sizeof (struct partial_symbol *));
1104 new_size = listp->size * 2;
1105 listp->list = (struct partial_symbol **)
1106 xmrealloc (objfile->md, (char *) listp->list,
1107 new_size * sizeof (struct partial_symbol *));
1109 /* Next assumes we only went one over. Should be good if
1110 program works correctly */
1111 listp->next = listp->list + listp->size;
1112 listp->size = new_size;
1116 /* Do early runtime initializations. */
1118 _initialize_symmisc (void)