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"
36 #include "gdb_regex.h"
38 #include "gdb_string.h"
39 #include <readline/readline.h>
42 #define DEV_TTY "/dev/tty"
45 /* Unfortunately for debugging, stderr is usually a macro. This is painful
46 when calling functions that take FILE *'s from the debugger.
47 So we make a variable which has the same value and which is accessible when
48 debugging GDB with itself. Because stdin et al need not be constants,
49 we initialize them in the _initialize_symmisc function at the bottom
55 /* Prototypes for local functions */
57 static void dump_symtab (struct objfile *, struct symtab *,
60 static void dump_psymtab (struct objfile *, struct partial_symtab *,
63 static void dump_msymbols (struct objfile *, struct ui_file *);
65 static void dump_objfile (struct objfile *);
67 static int block_depth (struct block *);
69 static void print_partial_symbols (struct partial_symbol **, int,
70 char *, struct ui_file *);
72 static void free_symtab_block (struct objfile *, struct block *);
74 void _initialize_symmisc (void);
76 struct print_symbol_args
78 struct symbol *symbol;
80 struct ui_file *outfile;
83 static int print_symbol (void *);
85 static void free_symtab_block (struct objfile *, struct block *);
88 /* Free a struct block <- B and all the symbols defined in that block. */
91 free_symtab_block (struct objfile *objfile, struct block *b)
94 struct symbol *sym, *next_sym;
96 n = BLOCK_BUCKETS (b);
97 for (i = 0; i < n; i++)
99 for (sym = BLOCK_BUCKET (b, i); sym; sym = next_sym)
101 next_sym = sym->hash_next;
102 xmfree (objfile->md, DEPRECATED_SYMBOL_NAME (sym));
103 xmfree (objfile->md, sym);
106 xmfree (objfile->md, b);
109 /* Free all the storage associated with the struct symtab <- S.
110 Note that some symtabs have contents malloc'ed structure by structure,
111 while some have contents that all live inside one big block of memory,
112 and some share the contents of another symbol table and so you should
113 not free the contents on their behalf (except sometimes the linetable,
114 which maybe per symtab even when the rest is not).
115 It is s->free_code that says which alternative to use. */
118 free_symtab (register struct symtab *s)
121 register struct blockvector *bv;
123 switch (s->free_code)
126 /* All the contents are part of a big block of memory (an obstack),
127 and some other symtab is in charge of freeing that block.
128 Therefore, do nothing. */
132 /* Here all the contents were malloc'ed structure by structure
133 and must be freed that way. */
134 /* First free the blocks (and their symbols. */
135 bv = BLOCKVECTOR (s);
136 n = BLOCKVECTOR_NBLOCKS (bv);
137 for (i = 0; i < n; i++)
138 free_symtab_block (s->objfile, BLOCKVECTOR_BLOCK (bv, i));
139 /* Free the blockvector itself. */
140 xmfree (s->objfile->md, bv);
141 /* Also free the linetable. */
144 /* Everything will be freed either by our `free_ptr'
145 or by some other symtab, except for our linetable.
148 xmfree (s->objfile->md, LINETABLE (s));
152 /* If there is a single block of memory to free, free it. */
153 if (s->free_ptr != NULL)
154 xmfree (s->objfile->md, s->free_ptr);
156 /* Free source-related stuff */
157 if (s->line_charpos != NULL)
158 xmfree (s->objfile->md, s->line_charpos);
159 if (s->fullname != NULL)
160 xmfree (s->objfile->md, s->fullname);
161 if (s->debugformat != NULL)
162 xmfree (s->objfile->md, s->debugformat);
163 xmfree (s->objfile->md, s);
167 print_symbol_bcache_statistics (void)
169 struct objfile *objfile;
172 ALL_OBJFILES (objfile)
174 printf_filtered ("Byte cache statistics for '%s':\n", objfile->name);
175 print_bcache_statistics (objfile->psymbol_cache, "partial symbol cache");
181 print_objfile_statistics (void)
183 struct objfile *objfile;
185 struct partial_symtab *ps;
186 int i, linetables, blockvectors;
189 ALL_OBJFILES (objfile)
191 printf_filtered ("Statistics for '%s':\n", objfile->name);
192 if (OBJSTAT (objfile, n_stabs) > 0)
193 printf_filtered (" Number of \"stab\" symbols read: %d\n",
194 OBJSTAT (objfile, n_stabs));
195 if (OBJSTAT (objfile, n_minsyms) > 0)
196 printf_filtered (" Number of \"minimal\" symbols read: %d\n",
197 OBJSTAT (objfile, n_minsyms));
198 if (OBJSTAT (objfile, n_psyms) > 0)
199 printf_filtered (" Number of \"partial\" symbols read: %d\n",
200 OBJSTAT (objfile, n_psyms));
201 if (OBJSTAT (objfile, n_syms) > 0)
202 printf_filtered (" Number of \"full\" symbols read: %d\n",
203 OBJSTAT (objfile, n_syms));
204 if (OBJSTAT (objfile, n_types) > 0)
205 printf_filtered (" Number of \"types\" defined: %d\n",
206 OBJSTAT (objfile, n_types));
208 ALL_OBJFILE_PSYMTABS (objfile, ps)
213 printf_filtered (" Number of psym tables (not yet expanded): %d\n", i);
214 i = linetables = blockvectors = 0;
215 ALL_OBJFILE_SYMTABS (objfile, s)
218 if (s->linetable != NULL)
223 printf_filtered (" Number of symbol tables: %d\n", i);
224 printf_filtered (" Number of symbol tables with line tables: %d\n",
226 printf_filtered (" Number of symbol tables with blockvectors: %d\n",
229 if (OBJSTAT (objfile, sz_strtab) > 0)
230 printf_filtered (" Space used by a.out string tables: %d\n",
231 OBJSTAT (objfile, sz_strtab));
232 printf_filtered (" Total memory used for psymbol obstack: %d\n",
233 obstack_memory_used (&objfile->psymbol_obstack));
234 printf_filtered (" Total memory used for psymbol cache: %d\n",
235 bcache_memory_used (objfile->psymbol_cache));
236 printf_filtered (" Total memory used for macro cache: %d\n",
237 bcache_memory_used (objfile->macro_cache));
238 printf_filtered (" Total memory used for symbol obstack: %d\n",
239 obstack_memory_used (&objfile->symbol_obstack));
240 printf_filtered (" Total memory used for type obstack: %d\n",
241 obstack_memory_used (&objfile->type_obstack));
247 dump_objfile (struct objfile *objfile)
249 struct symtab *symtab;
250 struct partial_symtab *psymtab;
252 printf_filtered ("\nObject file %s: ", objfile->name);
253 printf_filtered ("Objfile at ");
254 gdb_print_host_address (objfile, gdb_stdout);
255 printf_filtered (", bfd at ");
256 gdb_print_host_address (objfile->obfd, gdb_stdout);
257 printf_filtered (", %d minsyms\n\n",
258 objfile->minimal_symbol_count);
260 if (objfile->psymtabs)
262 printf_filtered ("Psymtabs:\n");
263 for (psymtab = objfile->psymtabs;
265 psymtab = psymtab->next)
267 printf_filtered ("%s at ",
269 gdb_print_host_address (psymtab, gdb_stdout);
270 printf_filtered (", ");
271 if (psymtab->objfile != objfile)
273 printf_filtered ("NOT ON CHAIN! ");
277 printf_filtered ("\n\n");
280 if (objfile->symtabs)
282 printf_filtered ("Symtabs:\n");
283 for (symtab = objfile->symtabs;
285 symtab = symtab->next)
287 printf_filtered ("%s at ", symtab->filename);
288 gdb_print_host_address (symtab, gdb_stdout);
289 printf_filtered (", ");
290 if (symtab->objfile != objfile)
292 printf_filtered ("NOT ON CHAIN! ");
296 printf_filtered ("\n\n");
300 /* Print minimal symbols from this objfile. */
303 dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
305 struct minimal_symbol *msymbol;
309 fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile->name);
310 if (objfile->minimal_symbol_count == 0)
312 fprintf_filtered (outfile, "No minimal symbols found.\n");
315 for (index = 0, msymbol = objfile->msymbols;
316 DEPRECATED_SYMBOL_NAME (msymbol) != NULL; msymbol++, index++)
318 switch (msymbol->type)
326 case mst_solib_trampoline:
351 fprintf_filtered (outfile, "[%2d] %c ", index, ms_type);
352 print_address_numeric (SYMBOL_VALUE_ADDRESS (msymbol), 1, outfile);
353 fprintf_filtered (outfile, " %s", DEPRECATED_SYMBOL_NAME (msymbol));
354 if (SYMBOL_BFD_SECTION (msymbol))
355 fprintf_filtered (outfile, " section %s",
356 bfd_section_name (objfile->obfd,
357 SYMBOL_BFD_SECTION (msymbol)));
358 if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
360 fprintf_filtered (outfile, " %s", SYMBOL_DEMANGLED_NAME (msymbol));
362 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
363 if (msymbol->filename)
364 fprintf_filtered (outfile, " %s", msymbol->filename);
366 fputs_filtered ("\n", outfile);
368 if (objfile->minimal_symbol_count != index)
370 warning ("internal error: minimal symbol count %d != %d",
371 objfile->minimal_symbol_count, index);
373 fprintf_filtered (outfile, "\n");
377 dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
378 struct ui_file *outfile)
382 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
384 fprintf_filtered (outfile, "(object ");
385 gdb_print_host_address (psymtab, outfile);
386 fprintf_filtered (outfile, ")\n\n");
387 fprintf_unfiltered (outfile, " Read from object file %s (",
389 gdb_print_host_address (objfile, outfile);
390 fprintf_unfiltered (outfile, ")\n");
394 fprintf_filtered (outfile,
395 " Full symtab was read (at ");
396 gdb_print_host_address (psymtab->symtab, outfile);
397 fprintf_filtered (outfile, " by function at ");
398 gdb_print_host_address (psymtab->read_symtab, outfile);
399 fprintf_filtered (outfile, ")\n");
402 fprintf_filtered (outfile, " Relocate symbols by ");
403 for (i = 0; i < psymtab->objfile->num_sections; ++i)
406 fprintf_filtered (outfile, ", ");
408 print_address_numeric (ANOFFSET (psymtab->section_offsets, i),
412 fprintf_filtered (outfile, "\n");
414 fprintf_filtered (outfile, " Symbols cover text addresses ");
415 print_address_numeric (psymtab->textlow, 1, outfile);
416 fprintf_filtered (outfile, "-");
417 print_address_numeric (psymtab->texthigh, 1, outfile);
418 fprintf_filtered (outfile, "\n");
419 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
420 psymtab->number_of_dependencies);
421 for (i = 0; i < psymtab->number_of_dependencies; i++)
423 fprintf_filtered (outfile, " %d ", i);
424 gdb_print_host_address (psymtab->dependencies[i], outfile);
425 fprintf_filtered (outfile, " %s\n",
426 psymtab->dependencies[i]->filename);
428 if (psymtab->n_global_syms > 0)
430 print_partial_symbols (objfile->global_psymbols.list
431 + psymtab->globals_offset,
432 psymtab->n_global_syms, "Global", outfile);
434 if (psymtab->n_static_syms > 0)
436 print_partial_symbols (objfile->static_psymbols.list
437 + psymtab->statics_offset,
438 psymtab->n_static_syms, "Static", outfile);
440 fprintf_filtered (outfile, "\n");
444 dump_symtab (struct objfile *objfile, struct symtab *symtab,
445 struct ui_file *outfile)
449 register struct linetable *l;
450 struct blockvector *bv;
452 register struct block *b;
455 fprintf_filtered (outfile, "\nSymtab for file %s\n", symtab->filename);
457 fprintf_filtered (outfile, "Compilation directory is %s\n",
459 fprintf_filtered (outfile, "Read from object file %s (", objfile->name);
460 gdb_print_host_address (objfile, outfile);
461 fprintf_filtered (outfile, ")\n");
462 fprintf_filtered (outfile, "Language: %s\n", language_str (symtab->language));
464 /* First print the line table. */
465 l = LINETABLE (symtab);
468 fprintf_filtered (outfile, "\nLine table:\n\n");
470 for (i = 0; i < len; i++)
472 fprintf_filtered (outfile, " line %d at ", l->item[i].line);
473 print_address_numeric (l->item[i].pc, 1, outfile);
474 fprintf_filtered (outfile, "\n");
477 /* Now print the block info, but only for primary symtabs since we will
478 print lots of duplicate info otherwise. */
481 fprintf_filtered (outfile, "\nBlockvector:\n\n");
482 bv = BLOCKVECTOR (symtab);
483 len = BLOCKVECTOR_NBLOCKS (bv);
484 for (i = 0; i < len; i++)
486 b = BLOCKVECTOR_BLOCK (bv, i);
487 depth = block_depth (b) * 2;
488 print_spaces (depth, outfile);
489 fprintf_filtered (outfile, "block #%03d, object at ", i);
490 gdb_print_host_address (b, outfile);
491 if (BLOCK_SUPERBLOCK (b))
493 fprintf_filtered (outfile, " under ");
494 gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile);
496 /* drow/2002-07-10: We could save the total symbols count
497 even if we're using a hashtable, but nothing else but this message
499 blen = BLOCK_BUCKETS (b);
500 if (BLOCK_HASHTABLE (b))
501 fprintf_filtered (outfile, ", %d buckets in ", blen);
503 fprintf_filtered (outfile, ", %d syms in ", blen);
504 print_address_numeric (BLOCK_START (b), 1, outfile);
505 fprintf_filtered (outfile, "..");
506 print_address_numeric (BLOCK_END (b), 1, outfile);
507 if (BLOCK_FUNCTION (b))
509 fprintf_filtered (outfile, ", function %s", DEPRECATED_SYMBOL_NAME (BLOCK_FUNCTION (b)));
510 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
512 fprintf_filtered (outfile, ", %s",
513 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
516 if (BLOCK_GCC_COMPILED (b))
517 fprintf_filtered (outfile, ", compiled with gcc%d", BLOCK_GCC_COMPILED (b));
518 fprintf_filtered (outfile, "\n");
519 /* Now print each symbol in this block (in no particular order, if
520 we're using a hashtable). */
521 ALL_BLOCK_SYMBOLS (b, j, sym)
523 struct print_symbol_args s;
527 catch_errors (print_symbol, &s, "Error printing symbol:\n",
531 fprintf_filtered (outfile, "\n");
535 fprintf_filtered (outfile, "\nBlockvector same as previous symtab\n\n");
540 maintenance_print_symbols (char *args, int from_tty)
543 struct ui_file *outfile;
544 struct cleanup *cleanups;
545 char *symname = NULL;
546 char *filename = DEV_TTY;
547 struct objfile *objfile;
555 Arguments missing: an output file name and an optional symbol file name");
557 else if ((argv = buildargv (args)) == NULL)
561 cleanups = make_cleanup_freeargv (argv);
566 /* If a second arg is supplied, it is a source file name to match on */
573 filename = tilde_expand (filename);
574 make_cleanup (xfree, filename);
576 outfile = gdb_fopen (filename, FOPEN_WT);
578 perror_with_name (filename);
579 make_cleanup_ui_file_delete (outfile);
582 ALL_SYMTABS (objfile, s)
583 if (symname == NULL || (STREQ (symname, s->filename)))
584 dump_symtab (objfile, s, outfile);
586 do_cleanups (cleanups);
589 /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
590 far to indent. ARGS is really a struct print_symbol_args *, but is
591 declared as char * to get it past catch_errors. Returns 0 for error,
595 print_symbol (void *args)
597 struct symbol *symbol = ((struct print_symbol_args *) args)->symbol;
598 int depth = ((struct print_symbol_args *) args)->depth;
599 struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile;
601 print_spaces (depth, outfile);
602 if (SYMBOL_NAMESPACE (symbol) == LABEL_NAMESPACE)
604 fprintf_filtered (outfile, "label %s at ", SYMBOL_PRINT_NAME (symbol));
605 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
606 if (SYMBOL_BFD_SECTION (symbol))
607 fprintf_filtered (outfile, " section %s\n",
608 bfd_section_name (SYMBOL_BFD_SECTION (symbol)->owner,
609 SYMBOL_BFD_SECTION (symbol)));
611 fprintf_filtered (outfile, "\n");
614 if (SYMBOL_NAMESPACE (symbol) == STRUCT_NAMESPACE)
616 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
618 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
622 fprintf_filtered (outfile, "%s %s = ",
623 (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
625 : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
626 ? "struct" : "union")),
627 DEPRECATED_SYMBOL_NAME (symbol));
628 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
630 fprintf_filtered (outfile, ";\n");
634 if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
635 fprintf_filtered (outfile, "typedef ");
636 if (SYMBOL_TYPE (symbol))
638 /* Print details of types, except for enums where it's clutter. */
639 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_PRINT_NAME (symbol),
641 TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
643 fprintf_filtered (outfile, "; ");
646 fprintf_filtered (outfile, "%s ", SYMBOL_PRINT_NAME (symbol));
648 switch (SYMBOL_CLASS (symbol))
651 fprintf_filtered (outfile, "const %ld (0x%lx)",
652 SYMBOL_VALUE (symbol),
653 SYMBOL_VALUE (symbol));
656 case LOC_CONST_BYTES:
659 struct type *type = check_typedef (SYMBOL_TYPE (symbol));
660 fprintf_filtered (outfile, "const %u hex bytes:",
662 for (i = 0; i < TYPE_LENGTH (type); i++)
663 fprintf_filtered (outfile, " %02x",
664 (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]);
669 fprintf_filtered (outfile, "static at ");
670 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
671 if (SYMBOL_BFD_SECTION (symbol))
672 fprintf_filtered (outfile, " section %s",
674 (SYMBOL_BFD_SECTION (symbol)->owner,
675 SYMBOL_BFD_SECTION (symbol)));
679 fprintf_filtered (outfile, "extern global at *(");
680 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
681 fprintf_filtered (outfile, "),");
685 fprintf_filtered (outfile, "register %ld", SYMBOL_VALUE (symbol));
689 fprintf_filtered (outfile, "arg at offset 0x%lx",
690 SYMBOL_VALUE (symbol));
694 fprintf_filtered (outfile, "arg at offset 0x%lx from fp",
695 SYMBOL_VALUE (symbol));
699 fprintf_filtered (outfile, "reference arg at 0x%lx", SYMBOL_VALUE (symbol));
703 fprintf_filtered (outfile, "parameter register %ld", SYMBOL_VALUE (symbol));
706 case LOC_REGPARM_ADDR:
707 fprintf_filtered (outfile, "address parameter register %ld", SYMBOL_VALUE (symbol));
711 fprintf_filtered (outfile, "local at offset 0x%lx",
712 SYMBOL_VALUE (symbol));
716 fprintf_filtered (outfile, "local at 0x%lx from register %d",
717 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
720 case LOC_BASEREG_ARG:
721 fprintf_filtered (outfile, "arg at 0x%lx from register %d",
722 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
729 fprintf_filtered (outfile, "label at ");
730 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
731 if (SYMBOL_BFD_SECTION (symbol))
732 fprintf_filtered (outfile, " section %s",
734 (SYMBOL_BFD_SECTION (symbol)->owner,
735 SYMBOL_BFD_SECTION (symbol)));
739 fprintf_filtered (outfile, "block object ");
740 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
741 fprintf_filtered (outfile, ", ");
742 print_address_numeric (BLOCK_START (SYMBOL_BLOCK_VALUE (symbol)),
745 fprintf_filtered (outfile, "..");
746 print_address_numeric (BLOCK_END (SYMBOL_BLOCK_VALUE (symbol)),
749 if (SYMBOL_BFD_SECTION (symbol))
750 fprintf_filtered (outfile, " section %s",
752 (SYMBOL_BFD_SECTION (symbol)->owner,
753 SYMBOL_BFD_SECTION (symbol)));
757 case LOC_COMPUTED_ARG:
758 fprintf_filtered (outfile, "computed at runtime");
762 fprintf_filtered (outfile, "unresolved");
765 case LOC_OPTIMIZED_OUT:
766 fprintf_filtered (outfile, "optimized out");
770 fprintf_filtered (outfile, "botched symbol class %x",
771 SYMBOL_CLASS (symbol));
775 fprintf_filtered (outfile, "\n");
780 maintenance_print_psymbols (char *args, int from_tty)
783 struct ui_file *outfile;
784 struct cleanup *cleanups;
785 char *symname = NULL;
786 char *filename = DEV_TTY;
787 struct objfile *objfile;
788 struct partial_symtab *ps;
794 error ("print-psymbols takes an output file name and optional symbol file name");
796 else if ((argv = buildargv (args)) == NULL)
800 cleanups = make_cleanup_freeargv (argv);
805 /* If a second arg is supplied, it is a source file name to match on */
812 filename = tilde_expand (filename);
813 make_cleanup (xfree, filename);
815 outfile = gdb_fopen (filename, FOPEN_WT);
817 perror_with_name (filename);
818 make_cleanup_ui_file_delete (outfile);
821 ALL_PSYMTABS (objfile, ps)
822 if (symname == NULL || (STREQ (symname, ps->filename)))
823 dump_psymtab (objfile, ps, outfile);
825 do_cleanups (cleanups);
829 print_partial_symbols (struct partial_symbol **p, int count, char *what,
830 struct ui_file *outfile)
832 fprintf_filtered (outfile, " %s partial symbols:\n", what);
835 fprintf_filtered (outfile, " `%s'", DEPRECATED_SYMBOL_NAME (*p));
836 if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
838 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
840 fputs_filtered (", ", outfile);
841 switch (SYMBOL_NAMESPACE (*p))
843 case UNDEF_NAMESPACE:
844 fputs_filtered ("undefined namespace, ", outfile);
847 /* This is the usual thing -- don't print it */
849 case STRUCT_NAMESPACE:
850 fputs_filtered ("struct namespace, ", outfile);
852 case LABEL_NAMESPACE:
853 fputs_filtered ("label namespace, ", outfile);
856 fputs_filtered ("<invalid namespace>, ", outfile);
859 switch (SYMBOL_CLASS (*p))
862 fputs_filtered ("undefined", outfile);
865 fputs_filtered ("constant int", outfile);
868 fputs_filtered ("static", outfile);
871 fputs_filtered ("extern global", outfile);
874 fputs_filtered ("register", outfile);
877 fputs_filtered ("pass by value", outfile);
880 fputs_filtered ("pass by reference", outfile);
883 fputs_filtered ("register parameter", outfile);
885 case LOC_REGPARM_ADDR:
886 fputs_filtered ("register address parameter", outfile);
889 fputs_filtered ("stack parameter", outfile);
892 fputs_filtered ("type", outfile);
895 fputs_filtered ("label", outfile);
898 fputs_filtered ("function", outfile);
900 case LOC_CONST_BYTES:
901 fputs_filtered ("constant bytes", outfile);
904 fputs_filtered ("shuffled arg", outfile);
907 fputs_filtered ("unresolved", outfile);
909 case LOC_OPTIMIZED_OUT:
910 fputs_filtered ("optimized out", outfile);
913 case LOC_COMPUTED_ARG:
914 fputs_filtered ("computed at runtime", outfile);
917 fputs_filtered ("<invalid location>", outfile);
920 fputs_filtered (", ", outfile);
921 print_address_numeric (SYMBOL_VALUE_ADDRESS (*p), 1, outfile);
922 fprintf_filtered (outfile, "\n");
928 maintenance_print_msymbols (char *args, int from_tty)
931 struct ui_file *outfile;
932 struct cleanup *cleanups;
933 char *filename = DEV_TTY;
934 char *symname = NULL;
935 struct objfile *objfile;
941 error ("print-msymbols takes an output file name and optional symbol file name");
943 else if ((argv = buildargv (args)) == NULL)
947 cleanups = make_cleanup_freeargv (argv);
952 /* If a second arg is supplied, it is a source file name to match on */
959 filename = tilde_expand (filename);
960 make_cleanup (xfree, filename);
962 outfile = gdb_fopen (filename, FOPEN_WT);
964 perror_with_name (filename);
965 make_cleanup_ui_file_delete (outfile);
968 ALL_OBJFILES (objfile)
969 if (symname == NULL || (STREQ (symname, objfile->name)))
970 dump_msymbols (objfile, outfile);
972 fprintf_filtered (outfile, "\n\n");
973 do_cleanups (cleanups);
977 maintenance_print_objfiles (char *ignore, int from_tty)
979 struct objfile *objfile;
984 ALL_OBJFILES (objfile)
985 dump_objfile (objfile);
990 /* List all the symbol tables. */
992 maintenance_list_symtabs (char *regexp, int from_tty)
994 struct objfile *objfile;
999 ALL_OBJFILES (objfile)
1001 struct symtab *symtab;
1003 /* We don't want to print anything for this objfile until we
1004 actually find a symtab whose name matches. */
1005 int printed_objfile_start = 0;
1007 ALL_OBJFILE_SYMTABS (objfile, symtab)
1009 || re_exec (symtab->filename))
1011 if (! printed_objfile_start)
1013 printf_filtered ("{ objfile %s ", objfile->name);
1015 printf_filtered ("((struct objfile *) %p)\n", objfile);
1016 printed_objfile_start = 1;
1019 printf_filtered (" { symtab %s ", symtab->filename);
1021 printf_filtered ("((struct symtab *) %p)\n", symtab);
1022 printf_filtered (" dirname %s\n",
1023 symtab->dirname ? symtab->dirname : "(null)");
1024 printf_filtered (" fullname %s\n",
1025 symtab->fullname ? symtab->fullname : "(null)");
1026 printf_filtered (" blockvector ((struct blockvector *) %p)%s\n",
1027 symtab->blockvector,
1028 symtab->primary ? " (primary)" : "");
1029 printf_filtered (" debugformat %s\n", symtab->debugformat);
1030 printf_filtered (" }\n");
1033 if (printed_objfile_start)
1034 printf_filtered ("}\n");
1039 /* List all the partial symbol tables. */
1041 maintenance_list_psymtabs (char *regexp, int from_tty)
1043 struct objfile *objfile;
1048 ALL_OBJFILES (objfile)
1050 struct partial_symtab *psymtab;
1052 /* We don't want to print anything for this objfile until we
1053 actually find a symtab whose name matches. */
1054 int printed_objfile_start = 0;
1056 ALL_OBJFILE_PSYMTABS (objfile, psymtab)
1058 || re_exec (psymtab->filename))
1060 if (! printed_objfile_start)
1062 printf_filtered ("{ objfile %s ", objfile->name);
1064 printf_filtered ("((struct objfile *) %p)\n", objfile);
1065 printed_objfile_start = 1;
1068 printf_filtered (" { psymtab %s ", psymtab->filename);
1070 printf_filtered ("((struct partial_symtab *) %p)\n", psymtab);
1071 printf_filtered (" readin %s\n",
1072 psymtab->readin ? "yes" : "no");
1073 printf_filtered (" fullname %s\n",
1074 psymtab->fullname ? psymtab->fullname : "(null)");
1075 printf_filtered (" text addresses ");
1076 print_address_numeric (psymtab->textlow, 1, gdb_stdout);
1077 printf_filtered (" -- ");
1078 print_address_numeric (psymtab->texthigh, 1, gdb_stdout);
1079 printf_filtered ("\n");
1080 printf_filtered (" globals ");
1081 if (psymtab->n_global_syms)
1083 printf_filtered ("(* (struct partial_symbol **) %p @ %d)\n",
1084 (psymtab->objfile->global_psymbols.list
1085 + psymtab->globals_offset),
1086 psymtab->n_global_syms);
1089 printf_filtered ("(none)\n");
1090 printf_filtered (" statics ");
1091 if (psymtab->n_static_syms)
1093 printf_filtered ("(* (struct partial_symbol **) %p @ %d)\n",
1094 (psymtab->objfile->static_psymbols.list
1095 + psymtab->statics_offset),
1096 psymtab->n_static_syms);
1099 printf_filtered ("(none)\n");
1100 printf_filtered (" dependencies ");
1101 if (psymtab->number_of_dependencies)
1105 printf_filtered ("{\n");
1106 for (i = 0; i < psymtab->number_of_dependencies; i++)
1108 struct partial_symtab *dep = psymtab->dependencies[i];
1110 /* Note the string concatenation there --- no comma. */
1111 printf_filtered (" psymtab %s "
1112 "((struct partial_symtab *) %p)\n",
1113 dep->filename, dep);
1115 printf_filtered (" }\n");
1118 printf_filtered ("(none)\n");
1119 printf_filtered (" }\n");
1122 if (printed_objfile_start)
1123 printf_filtered ("}\n");
1128 /* Check consistency of psymtabs and symtabs. */
1131 maintenance_check_symtabs (char *ignore, int from_tty)
1133 register struct symbol *sym;
1134 register struct partial_symbol **psym;
1135 register struct symtab *s = NULL;
1136 register struct partial_symtab *ps;
1137 struct blockvector *bv;
1138 register struct objfile *objfile;
1139 register struct block *b;
1142 ALL_PSYMTABS (objfile, ps)
1144 s = PSYMTAB_TO_SYMTAB (ps);
1147 bv = BLOCKVECTOR (s);
1148 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1149 psym = ps->objfile->static_psymbols.list + ps->statics_offset;
1150 length = ps->n_static_syms;
1153 sym = lookup_block_symbol (b, DEPRECATED_SYMBOL_NAME (*psym),
1154 NULL, SYMBOL_NAMESPACE (*psym));
1157 printf_filtered ("Static symbol `");
1158 puts_filtered (DEPRECATED_SYMBOL_NAME (*psym));
1159 printf_filtered ("' only found in ");
1160 puts_filtered (ps->filename);
1161 printf_filtered (" psymtab\n");
1165 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1166 psym = ps->objfile->global_psymbols.list + ps->globals_offset;
1167 length = ps->n_global_syms;
1170 sym = lookup_block_symbol (b, DEPRECATED_SYMBOL_NAME (*psym),
1171 NULL, SYMBOL_NAMESPACE (*psym));
1174 printf_filtered ("Global symbol `");
1175 puts_filtered (DEPRECATED_SYMBOL_NAME (*psym));
1176 printf_filtered ("' only found in ");
1177 puts_filtered (ps->filename);
1178 printf_filtered (" psymtab\n");
1182 if (ps->texthigh < ps->textlow)
1184 printf_filtered ("Psymtab ");
1185 puts_filtered (ps->filename);
1186 printf_filtered (" covers bad range ");
1187 print_address_numeric (ps->textlow, 1, gdb_stdout);
1188 printf_filtered (" - ");
1189 print_address_numeric (ps->texthigh, 1, gdb_stdout);
1190 printf_filtered ("\n");
1193 if (ps->texthigh == 0)
1195 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
1197 printf_filtered ("Psymtab ");
1198 puts_filtered (ps->filename);
1199 printf_filtered (" covers ");
1200 print_address_numeric (ps->textlow, 1, gdb_stdout);
1201 printf_filtered (" - ");
1202 print_address_numeric (ps->texthigh, 1, gdb_stdout);
1203 printf_filtered (" but symtab covers only ");
1204 print_address_numeric (BLOCK_START (b), 1, gdb_stdout);
1205 printf_filtered (" - ");
1206 print_address_numeric (BLOCK_END (b), 1, gdb_stdout);
1207 printf_filtered ("\n");
1213 /* Return the nexting depth of a block within other blocks in its symtab. */
1216 block_depth (struct block *block)
1219 while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
1227 /* Increase the space allocated for LISTP, which is probably
1228 global_psymbols or static_psymbols. This space will eventually
1229 be freed in free_objfile(). */
1232 extend_psymbol_list (register struct psymbol_allocation_list *listp,
1233 struct objfile *objfile)
1236 if (listp->size == 0)
1239 listp->list = (struct partial_symbol **)
1240 xmmalloc (objfile->md, new_size * sizeof (struct partial_symbol *));
1244 new_size = listp->size * 2;
1245 listp->list = (struct partial_symbol **)
1246 xmrealloc (objfile->md, (char *) listp->list,
1247 new_size * sizeof (struct partial_symbol *));
1249 /* Next assumes we only went one over. Should be good if
1250 program works correctly */
1251 listp->next = listp->list + listp->size;
1252 listp->size = new_size;
1256 /* Do early runtime initializations. */
1258 _initialize_symmisc (void)