1 /* Do various things to symbol tables (other than lookup), for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2007, 2008
5 Free Software Foundation, Inc.
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 3 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, see <http://www.gnu.org/licenses/>. */
28 #include "breakpoint.h"
30 #include "gdb_obstack.h"
31 #include "exceptions.h"
35 #include "gdb_regex.h"
37 #include "dictionary.h"
39 #include "gdb_string.h"
40 #include "readline/readline.h"
43 #define DEV_TTY "/dev/tty"
46 /* Unfortunately for debugging, stderr is usually a macro. This is painful
47 when calling functions that take FILE *'s from the debugger.
48 So we make a variable which has the same value and which is accessible when
49 debugging GDB with itself. Because stdin et al need not be constants,
50 we initialize them in the _initialize_symmisc function at the bottom
56 /* Prototypes for local functions */
58 static void dump_symtab (struct objfile *, struct symtab *,
61 static void dump_psymtab (struct objfile *, struct partial_symtab *,
64 static void dump_msymbols (struct objfile *, struct ui_file *);
66 static void dump_objfile (struct objfile *);
68 static int block_depth (struct block *);
70 static void print_partial_symbols (struct partial_symbol **, int,
71 char *, struct ui_file *);
73 static void free_symtab_block (struct objfile *, struct block *);
75 void _initialize_symmisc (void);
77 struct print_symbol_args
79 struct symbol *symbol;
81 struct ui_file *outfile;
84 static int print_symbol (void *);
86 static void free_symtab_block (struct objfile *, struct block *);
89 /* Free a struct block <- B and all the symbols defined in that block. */
91 /* FIXME: carlton/2003-04-28: I don't believe this is currently ever
95 free_symtab_block (struct objfile *objfile, struct block *b)
97 struct dict_iterator iter;
100 ALL_BLOCK_SYMBOLS (b, iter, sym)
102 xfree (DEPRECATED_SYMBOL_NAME (sym));
106 dict_free (BLOCK_DICT (b));
110 /* Free all the storage associated with the struct symtab <- S.
111 Note that some symtabs have contents malloc'ed structure by structure,
112 while some have contents that all live inside one big block of memory,
113 and some share the contents of another symbol table and so you should
114 not free the contents on their behalf (except sometimes the linetable,
115 which maybe per symtab even when the rest is not).
116 It is s->free_code that says which alternative to use. */
119 free_symtab (struct symtab *s)
122 struct blockvector *bv;
124 switch (s->free_code)
127 /* All the contents are part of a big block of memory (an obstack),
128 and some other symtab is in charge of freeing that block.
129 Therefore, do nothing. */
133 /* Here all the contents were malloc'ed structure by structure
134 and must be freed that way. */
135 /* First free the blocks (and their symbols. */
136 bv = BLOCKVECTOR (s);
137 n = BLOCKVECTOR_NBLOCKS (bv);
138 for (i = 0; i < n; i++)
139 free_symtab_block (s->objfile, BLOCKVECTOR_BLOCK (bv, i));
140 /* Free the blockvector itself. */
142 /* Also free the linetable. */
145 /* Everything will be freed either by our `free_func'
146 or by some other symtab, except for our linetable.
149 xfree (LINETABLE (s));
153 /* If there is a single block of memory to free, free it. */
154 if (s->free_func != NULL)
157 /* Free source-related stuff */
158 if (s->line_charpos != NULL)
159 xfree (s->line_charpos);
160 if (s->fullname != NULL)
162 if (s->debugformat != NULL)
163 xfree (s->debugformat);
168 print_symbol_bcache_statistics (void)
170 struct objfile *objfile;
173 ALL_OBJFILES (objfile)
175 printf_filtered (_("Byte cache statistics for '%s':\n"), objfile->name);
176 print_bcache_statistics (objfile->psymbol_cache, "partial symbol cache");
182 print_objfile_statistics (void)
184 struct objfile *objfile;
186 struct partial_symtab *ps;
187 int i, linetables, blockvectors;
190 ALL_OBJFILES (objfile)
192 printf_filtered (_("Statistics for '%s':\n"), objfile->name);
193 if (OBJSTAT (objfile, n_stabs) > 0)
194 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
195 OBJSTAT (objfile, n_stabs));
196 if (OBJSTAT (objfile, n_minsyms) > 0)
197 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
198 OBJSTAT (objfile, n_minsyms));
199 if (OBJSTAT (objfile, n_psyms) > 0)
200 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
201 OBJSTAT (objfile, n_psyms));
202 if (OBJSTAT (objfile, n_syms) > 0)
203 printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
204 OBJSTAT (objfile, n_syms));
205 if (OBJSTAT (objfile, n_types) > 0)
206 printf_filtered (_(" Number of \"types\" defined: %d\n"),
207 OBJSTAT (objfile, n_types));
209 ALL_OBJFILE_PSYMTABS (objfile, ps)
214 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i);
215 i = linetables = blockvectors = 0;
216 ALL_OBJFILE_SYMTABS (objfile, s)
219 if (s->linetable != NULL)
224 printf_filtered (_(" Number of symbol tables: %d\n"), i);
225 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
227 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
230 if (OBJSTAT (objfile, sz_strtab) > 0)
231 printf_filtered (_(" Space used by a.out string tables: %d\n"),
232 OBJSTAT (objfile, sz_strtab));
233 printf_filtered (_(" Total memory used for objfile obstack: %d\n"),
234 obstack_memory_used (&objfile->objfile_obstack));
235 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
236 bcache_memory_used (objfile->psymbol_cache));
237 printf_filtered (_(" Total memory used for macro cache: %d\n"),
238 bcache_memory_used (objfile->macro_cache));
244 dump_objfile (struct objfile *objfile)
246 struct symtab *symtab;
247 struct partial_symtab *psymtab;
249 printf_filtered ("\nObject file %s: ", objfile->name);
250 printf_filtered ("Objfile at ");
251 gdb_print_host_address (objfile, gdb_stdout);
252 printf_filtered (", bfd at ");
253 gdb_print_host_address (objfile->obfd, gdb_stdout);
254 printf_filtered (", %d minsyms\n\n",
255 objfile->minimal_symbol_count);
257 if (objfile->psymtabs)
259 printf_filtered ("Psymtabs:\n");
260 for (psymtab = objfile->psymtabs;
262 psymtab = psymtab->next)
264 printf_filtered ("%s at ",
266 gdb_print_host_address (psymtab, gdb_stdout);
267 printf_filtered (", ");
268 if (psymtab->objfile != objfile)
270 printf_filtered ("NOT ON CHAIN! ");
274 printf_filtered ("\n\n");
277 if (objfile->symtabs)
279 printf_filtered ("Symtabs:\n");
280 for (symtab = objfile->symtabs;
282 symtab = symtab->next)
284 printf_filtered ("%s at ", symtab->filename);
285 gdb_print_host_address (symtab, gdb_stdout);
286 printf_filtered (", ");
287 if (symtab->objfile != objfile)
289 printf_filtered ("NOT ON CHAIN! ");
293 printf_filtered ("\n\n");
297 /* Print minimal symbols from this objfile. */
300 dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
302 struct minimal_symbol *msymbol;
306 fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile->name);
307 if (objfile->minimal_symbol_count == 0)
309 fprintf_filtered (outfile, "No minimal symbols found.\n");
312 for (index = 0, msymbol = objfile->msymbols;
313 DEPRECATED_SYMBOL_NAME (msymbol) != NULL; msymbol++, index++)
315 switch (msymbol->type)
323 case mst_solib_trampoline:
348 fprintf_filtered (outfile, "[%2d] %c ", index, ms_type);
349 deprecated_print_address_numeric (SYMBOL_VALUE_ADDRESS (msymbol), 1, outfile);
350 fprintf_filtered (outfile, " %s", DEPRECATED_SYMBOL_NAME (msymbol));
351 if (SYMBOL_BFD_SECTION (msymbol))
352 fprintf_filtered (outfile, " section %s",
353 bfd_section_name (objfile->obfd,
354 SYMBOL_BFD_SECTION (msymbol)));
355 if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
357 fprintf_filtered (outfile, " %s", SYMBOL_DEMANGLED_NAME (msymbol));
359 if (msymbol->filename)
360 fprintf_filtered (outfile, " %s", msymbol->filename);
361 fputs_filtered ("\n", outfile);
363 if (objfile->minimal_symbol_count != index)
365 warning (_("internal error: minimal symbol count %d != %d"),
366 objfile->minimal_symbol_count, index);
368 fprintf_filtered (outfile, "\n");
372 dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
373 struct ui_file *outfile)
377 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
379 fprintf_filtered (outfile, "(object ");
380 gdb_print_host_address (psymtab, outfile);
381 fprintf_filtered (outfile, ")\n\n");
382 fprintf_unfiltered (outfile, " Read from object file %s (",
384 gdb_print_host_address (objfile, outfile);
385 fprintf_unfiltered (outfile, ")\n");
389 fprintf_filtered (outfile,
390 " Full symtab was read (at ");
391 gdb_print_host_address (psymtab->symtab, outfile);
392 fprintf_filtered (outfile, " by function at ");
393 gdb_print_host_address (psymtab->read_symtab, outfile);
394 fprintf_filtered (outfile, ")\n");
397 fprintf_filtered (outfile, " Relocate symbols by ");
398 for (i = 0; i < psymtab->objfile->num_sections; ++i)
401 fprintf_filtered (outfile, ", ");
403 deprecated_print_address_numeric (ANOFFSET (psymtab->section_offsets, i),
407 fprintf_filtered (outfile, "\n");
409 fprintf_filtered (outfile, " Symbols cover text addresses ");
410 deprecated_print_address_numeric (psymtab->textlow, 1, outfile);
411 fprintf_filtered (outfile, "-");
412 deprecated_print_address_numeric (psymtab->texthigh, 1, outfile);
413 fprintf_filtered (outfile, "\n");
414 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
415 psymtab->number_of_dependencies);
416 for (i = 0; i < psymtab->number_of_dependencies; i++)
418 fprintf_filtered (outfile, " %d ", i);
419 gdb_print_host_address (psymtab->dependencies[i], outfile);
420 fprintf_filtered (outfile, " %s\n",
421 psymtab->dependencies[i]->filename);
423 if (psymtab->n_global_syms > 0)
425 print_partial_symbols (objfile->global_psymbols.list
426 + psymtab->globals_offset,
427 psymtab->n_global_syms, "Global", outfile);
429 if (psymtab->n_static_syms > 0)
431 print_partial_symbols (objfile->static_psymbols.list
432 + psymtab->statics_offset,
433 psymtab->n_static_syms, "Static", outfile);
435 fprintf_filtered (outfile, "\n");
439 dump_symtab_1 (struct objfile *objfile, struct symtab *symtab,
440 struct ui_file *outfile)
443 struct dict_iterator iter;
446 struct blockvector *bv;
451 fprintf_filtered (outfile, "\nSymtab for file %s\n", symtab->filename);
453 fprintf_filtered (outfile, "Compilation directory is %s\n",
455 fprintf_filtered (outfile, "Read from object file %s (", objfile->name);
456 gdb_print_host_address (objfile, outfile);
457 fprintf_filtered (outfile, ")\n");
458 fprintf_filtered (outfile, "Language: %s\n", language_str (symtab->language));
460 /* First print the line table. */
461 l = LINETABLE (symtab);
464 fprintf_filtered (outfile, "\nLine table:\n\n");
466 for (i = 0; i < len; i++)
468 fprintf_filtered (outfile, " line %d at ", l->item[i].line);
469 deprecated_print_address_numeric (l->item[i].pc, 1, outfile);
470 fprintf_filtered (outfile, "\n");
473 /* Now print the block info, but only for primary symtabs since we will
474 print lots of duplicate info otherwise. */
477 fprintf_filtered (outfile, "\nBlockvector:\n\n");
478 bv = BLOCKVECTOR (symtab);
479 len = BLOCKVECTOR_NBLOCKS (bv);
480 for (i = 0; i < len; i++)
482 b = BLOCKVECTOR_BLOCK (bv, i);
483 depth = block_depth (b) * 2;
484 print_spaces (depth, outfile);
485 fprintf_filtered (outfile, "block #%03d, object at ", i);
486 gdb_print_host_address (b, outfile);
487 if (BLOCK_SUPERBLOCK (b))
489 fprintf_filtered (outfile, " under ");
490 gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile);
492 /* drow/2002-07-10: We could save the total symbols count
493 even if we're using a hashtable, but nothing else but this message
495 fprintf_filtered (outfile, ", %d syms/buckets in ",
496 dict_size (BLOCK_DICT (b)));
497 deprecated_print_address_numeric (BLOCK_START (b), 1, outfile);
498 fprintf_filtered (outfile, "..");
499 deprecated_print_address_numeric (BLOCK_END (b), 1, outfile);
500 if (BLOCK_FUNCTION (b))
502 fprintf_filtered (outfile, ", function %s", DEPRECATED_SYMBOL_NAME (BLOCK_FUNCTION (b)));
503 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
505 fprintf_filtered (outfile, ", %s",
506 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
509 fprintf_filtered (outfile, "\n");
510 /* Now print each symbol in this block (in no particular order, if
511 we're using a hashtable). */
512 ALL_BLOCK_SYMBOLS (b, iter, sym)
514 struct print_symbol_args s;
518 catch_errors (print_symbol, &s, "Error printing symbol:\n",
522 fprintf_filtered (outfile, "\n");
526 fprintf_filtered (outfile, "\nBlockvector same as previous symtab\n\n");
531 dump_symtab (struct objfile *objfile, struct symtab *symtab,
532 struct ui_file *outfile)
534 enum language saved_lang;
536 /* Set the current language to the language of the symtab we're dumping
537 because certain routines used during dump_symtab() use the current
538 language to print an image of the symbol. We'll restore it later. */
539 saved_lang = set_language (symtab->language);
541 dump_symtab_1 (objfile, symtab, outfile);
543 set_language (saved_lang);
547 maintenance_print_symbols (char *args, int from_tty)
550 struct ui_file *outfile;
551 struct cleanup *cleanups;
552 char *symname = NULL;
553 char *filename = DEV_TTY;
554 struct objfile *objfile;
562 Arguments missing: an output file name and an optional symbol file name"));
564 else if ((argv = buildargv (args)) == NULL)
568 cleanups = make_cleanup_freeargv (argv);
573 /* If a second arg is supplied, it is a source file name to match on */
580 filename = tilde_expand (filename);
581 make_cleanup (xfree, filename);
583 outfile = gdb_fopen (filename, FOPEN_WT);
585 perror_with_name (filename);
586 make_cleanup_ui_file_delete (outfile);
589 ALL_SYMTABS (objfile, s)
590 if (symname == NULL || strcmp (symname, s->filename) == 0)
591 dump_symtab (objfile, s, outfile);
593 do_cleanups (cleanups);
596 /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
597 far to indent. ARGS is really a struct print_symbol_args *, but is
598 declared as char * to get it past catch_errors. Returns 0 for error,
602 print_symbol (void *args)
604 struct symbol *symbol = ((struct print_symbol_args *) args)->symbol;
605 int depth = ((struct print_symbol_args *) args)->depth;
606 struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile;
608 print_spaces (depth, outfile);
609 if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN)
611 fprintf_filtered (outfile, "label %s at ", SYMBOL_PRINT_NAME (symbol));
612 deprecated_print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
613 if (SYMBOL_BFD_SECTION (symbol))
614 fprintf_filtered (outfile, " section %s\n",
615 bfd_section_name (SYMBOL_BFD_SECTION (symbol)->owner,
616 SYMBOL_BFD_SECTION (symbol)));
618 fprintf_filtered (outfile, "\n");
621 if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN)
623 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
625 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
629 fprintf_filtered (outfile, "%s %s = ",
630 (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
632 : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
633 ? "struct" : "union")),
634 DEPRECATED_SYMBOL_NAME (symbol));
635 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
637 fprintf_filtered (outfile, ";\n");
641 if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
642 fprintf_filtered (outfile, "typedef ");
643 if (SYMBOL_TYPE (symbol))
645 /* Print details of types, except for enums where it's clutter. */
646 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_PRINT_NAME (symbol),
648 TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
650 fprintf_filtered (outfile, "; ");
653 fprintf_filtered (outfile, "%s ", SYMBOL_PRINT_NAME (symbol));
655 switch (SYMBOL_CLASS (symbol))
658 fprintf_filtered (outfile, "const %ld (0x%lx)",
659 SYMBOL_VALUE (symbol),
660 SYMBOL_VALUE (symbol));
663 case LOC_CONST_BYTES:
666 struct type *type = check_typedef (SYMBOL_TYPE (symbol));
667 fprintf_filtered (outfile, "const %u hex bytes:",
669 for (i = 0; i < TYPE_LENGTH (type); i++)
670 fprintf_filtered (outfile, " %02x",
671 (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]);
676 fprintf_filtered (outfile, "static at ");
677 deprecated_print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
678 if (SYMBOL_BFD_SECTION (symbol))
679 fprintf_filtered (outfile, " section %s",
681 (SYMBOL_BFD_SECTION (symbol)->owner,
682 SYMBOL_BFD_SECTION (symbol)));
686 fprintf_filtered (outfile, "extern global at *(");
687 deprecated_print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
688 fprintf_filtered (outfile, "),");
692 fprintf_filtered (outfile, "register %ld", SYMBOL_VALUE (symbol));
696 fprintf_filtered (outfile, "arg at offset 0x%lx",
697 SYMBOL_VALUE (symbol));
701 fprintf_filtered (outfile, "arg at offset 0x%lx from fp",
702 SYMBOL_VALUE (symbol));
706 fprintf_filtered (outfile, "reference arg at 0x%lx", SYMBOL_VALUE (symbol));
710 fprintf_filtered (outfile, "parameter register %ld", SYMBOL_VALUE (symbol));
713 case LOC_REGPARM_ADDR:
714 fprintf_filtered (outfile, "address parameter register %ld", SYMBOL_VALUE (symbol));
718 fprintf_filtered (outfile, "local at offset 0x%lx",
719 SYMBOL_VALUE (symbol));
723 fprintf_filtered (outfile, "local at 0x%lx from register %d",
724 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
727 case LOC_BASEREG_ARG:
728 fprintf_filtered (outfile, "arg at 0x%lx from register %d",
729 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
736 fprintf_filtered (outfile, "label at ");
737 deprecated_print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
738 if (SYMBOL_BFD_SECTION (symbol))
739 fprintf_filtered (outfile, " section %s",
741 (SYMBOL_BFD_SECTION (symbol)->owner,
742 SYMBOL_BFD_SECTION (symbol)));
746 fprintf_filtered (outfile, "block object ");
747 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
748 fprintf_filtered (outfile, ", ");
749 deprecated_print_address_numeric (BLOCK_START (SYMBOL_BLOCK_VALUE (symbol)),
752 fprintf_filtered (outfile, "..");
753 deprecated_print_address_numeric (BLOCK_END (SYMBOL_BLOCK_VALUE (symbol)),
756 if (SYMBOL_BFD_SECTION (symbol))
757 fprintf_filtered (outfile, " section %s",
759 (SYMBOL_BFD_SECTION (symbol)->owner,
760 SYMBOL_BFD_SECTION (symbol)));
764 case LOC_COMPUTED_ARG:
765 fprintf_filtered (outfile, "computed at runtime");
769 fprintf_filtered (outfile, "unresolved");
772 case LOC_OPTIMIZED_OUT:
773 fprintf_filtered (outfile, "optimized out");
777 fprintf_filtered (outfile, "botched symbol class %x",
778 SYMBOL_CLASS (symbol));
782 fprintf_filtered (outfile, "\n");
787 maintenance_print_psymbols (char *args, int from_tty)
790 struct ui_file *outfile;
791 struct cleanup *cleanups;
792 char *symname = NULL;
793 char *filename = DEV_TTY;
794 struct objfile *objfile;
795 struct partial_symtab *ps;
801 error (_("print-psymbols takes an output file name and optional symbol file name"));
803 else if ((argv = buildargv (args)) == NULL)
807 cleanups = make_cleanup_freeargv (argv);
812 /* If a second arg is supplied, it is a source file name to match on */
819 filename = tilde_expand (filename);
820 make_cleanup (xfree, filename);
822 outfile = gdb_fopen (filename, FOPEN_WT);
824 perror_with_name (filename);
825 make_cleanup_ui_file_delete (outfile);
828 ALL_PSYMTABS (objfile, ps)
829 if (symname == NULL || strcmp (symname, ps->filename) == 0)
830 dump_psymtab (objfile, ps, outfile);
832 do_cleanups (cleanups);
836 print_partial_symbols (struct partial_symbol **p, int count, char *what,
837 struct ui_file *outfile)
839 fprintf_filtered (outfile, " %s partial symbols:\n", what);
842 fprintf_filtered (outfile, " `%s'", DEPRECATED_SYMBOL_NAME (*p));
843 if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
845 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
847 fputs_filtered (", ", outfile);
848 switch (SYMBOL_DOMAIN (*p))
851 fputs_filtered ("undefined domain, ", outfile);
854 /* This is the usual thing -- don't print it */
857 fputs_filtered ("struct domain, ", outfile);
860 fputs_filtered ("label domain, ", outfile);
863 fputs_filtered ("<invalid domain>, ", outfile);
866 switch (SYMBOL_CLASS (*p))
869 fputs_filtered ("undefined", outfile);
872 fputs_filtered ("constant int", outfile);
875 fputs_filtered ("static", outfile);
878 fputs_filtered ("extern global", outfile);
881 fputs_filtered ("register", outfile);
884 fputs_filtered ("pass by value", outfile);
887 fputs_filtered ("pass by reference", outfile);
890 fputs_filtered ("register parameter", outfile);
892 case LOC_REGPARM_ADDR:
893 fputs_filtered ("register address parameter", outfile);
896 fputs_filtered ("stack parameter", outfile);
899 fputs_filtered ("type", outfile);
902 fputs_filtered ("label", outfile);
905 fputs_filtered ("function", outfile);
907 case LOC_CONST_BYTES:
908 fputs_filtered ("constant bytes", outfile);
911 fputs_filtered ("shuffled arg", outfile);
914 fputs_filtered ("unresolved", outfile);
916 case LOC_OPTIMIZED_OUT:
917 fputs_filtered ("optimized out", outfile);
920 case LOC_COMPUTED_ARG:
921 fputs_filtered ("computed at runtime", outfile);
924 fputs_filtered ("<invalid location>", outfile);
927 fputs_filtered (", ", outfile);
928 deprecated_print_address_numeric (SYMBOL_VALUE_ADDRESS (*p), 1, outfile);
929 fprintf_filtered (outfile, "\n");
935 maintenance_print_msymbols (char *args, int from_tty)
938 struct ui_file *outfile;
939 struct cleanup *cleanups;
940 char *filename = DEV_TTY;
941 char *symname = NULL;
942 struct objfile *objfile;
944 struct stat sym_st, obj_st;
950 error (_("print-msymbols takes an output file name and optional symbol file name"));
952 else if ((argv = buildargv (args)) == NULL)
956 cleanups = make_cleanup_freeargv (argv);
961 /* If a second arg is supplied, it is a source file name to match on */
964 symname = xfullpath (argv[1]);
965 make_cleanup (xfree, symname);
966 if (symname && stat (symname, &sym_st))
967 perror_with_name (symname);
971 filename = tilde_expand (filename);
972 make_cleanup (xfree, filename);
974 outfile = gdb_fopen (filename, FOPEN_WT);
976 perror_with_name (filename);
977 make_cleanup_ui_file_delete (outfile);
980 ALL_OBJFILES (objfile)
982 || (!stat (objfile->name, &obj_st) && sym_st.st_ino == obj_st.st_ino))
983 dump_msymbols (objfile, outfile);
985 fprintf_filtered (outfile, "\n\n");
986 do_cleanups (cleanups);
990 maintenance_print_objfiles (char *ignore, int from_tty)
992 struct objfile *objfile;
997 ALL_OBJFILES (objfile)
998 dump_objfile (objfile);
1003 /* List all the symbol tables whose names match REGEXP (optional). */
1005 maintenance_info_symtabs (char *regexp, int from_tty)
1007 struct objfile *objfile;
1012 ALL_OBJFILES (objfile)
1014 struct symtab *symtab;
1016 /* We don't want to print anything for this objfile until we
1017 actually find a symtab whose name matches. */
1018 int printed_objfile_start = 0;
1020 ALL_OBJFILE_SYMTABS (objfile, symtab)
1022 || re_exec (symtab->filename))
1024 if (! printed_objfile_start)
1026 printf_filtered ("{ objfile %s ", objfile->name);
1028 printf_filtered ("((struct objfile *) %p)\n", objfile);
1029 printed_objfile_start = 1;
1032 printf_filtered (" { symtab %s ", symtab->filename);
1034 printf_filtered ("((struct symtab *) %p)\n", symtab);
1035 printf_filtered (" dirname %s\n",
1036 symtab->dirname ? symtab->dirname : "(null)");
1037 printf_filtered (" fullname %s\n",
1038 symtab->fullname ? symtab->fullname : "(null)");
1039 printf_filtered (" blockvector ((struct blockvector *) %p)%s\n",
1040 symtab->blockvector,
1041 symtab->primary ? " (primary)" : "");
1042 printf_filtered (" linetable ((struct linetable *) %p)\n",
1044 printf_filtered (" debugformat %s\n", symtab->debugformat);
1045 printf_filtered (" }\n");
1048 if (printed_objfile_start)
1049 printf_filtered ("}\n");
1054 /* List all the partial symbol tables whose names match REGEXP (optional). */
1056 maintenance_info_psymtabs (char *regexp, int from_tty)
1058 struct objfile *objfile;
1063 ALL_OBJFILES (objfile)
1065 struct partial_symtab *psymtab;
1067 /* We don't want to print anything for this objfile until we
1068 actually find a symtab whose name matches. */
1069 int printed_objfile_start = 0;
1071 ALL_OBJFILE_PSYMTABS (objfile, psymtab)
1073 || re_exec (psymtab->filename))
1075 if (! printed_objfile_start)
1077 printf_filtered ("{ objfile %s ", objfile->name);
1079 printf_filtered ("((struct objfile *) %p)\n", objfile);
1080 printed_objfile_start = 1;
1083 printf_filtered (" { psymtab %s ", psymtab->filename);
1085 printf_filtered ("((struct partial_symtab *) %p)\n", psymtab);
1086 printf_filtered (" readin %s\n",
1087 psymtab->readin ? "yes" : "no");
1088 printf_filtered (" fullname %s\n",
1089 psymtab->fullname ? psymtab->fullname : "(null)");
1090 printf_filtered (" text addresses ");
1091 deprecated_print_address_numeric (psymtab->textlow, 1, gdb_stdout);
1092 printf_filtered (" -- ");
1093 deprecated_print_address_numeric (psymtab->texthigh, 1, gdb_stdout);
1094 printf_filtered ("\n");
1095 printf_filtered (" globals ");
1096 if (psymtab->n_global_syms)
1098 printf_filtered ("(* (struct partial_symbol **) %p @ %d)\n",
1099 (psymtab->objfile->global_psymbols.list
1100 + psymtab->globals_offset),
1101 psymtab->n_global_syms);
1104 printf_filtered ("(none)\n");
1105 printf_filtered (" statics ");
1106 if (psymtab->n_static_syms)
1108 printf_filtered ("(* (struct partial_symbol **) %p @ %d)\n",
1109 (psymtab->objfile->static_psymbols.list
1110 + psymtab->statics_offset),
1111 psymtab->n_static_syms);
1114 printf_filtered ("(none)\n");
1115 printf_filtered (" dependencies ");
1116 if (psymtab->number_of_dependencies)
1120 printf_filtered ("{\n");
1121 for (i = 0; i < psymtab->number_of_dependencies; i++)
1123 struct partial_symtab *dep = psymtab->dependencies[i];
1125 /* Note the string concatenation there --- no comma. */
1126 printf_filtered (" psymtab %s "
1127 "((struct partial_symtab *) %p)\n",
1128 dep->filename, dep);
1130 printf_filtered (" }\n");
1133 printf_filtered ("(none)\n");
1134 printf_filtered (" }\n");
1137 if (printed_objfile_start)
1138 printf_filtered ("}\n");
1143 /* Check consistency of psymtabs and symtabs. */
1146 maintenance_check_symtabs (char *ignore, int from_tty)
1149 struct partial_symbol **psym;
1150 struct symtab *s = NULL;
1151 struct partial_symtab *ps;
1152 struct blockvector *bv;
1153 struct objfile *objfile;
1157 ALL_PSYMTABS (objfile, ps)
1159 s = PSYMTAB_TO_SYMTAB (ps);
1162 bv = BLOCKVECTOR (s);
1163 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1164 psym = ps->objfile->static_psymbols.list + ps->statics_offset;
1165 length = ps->n_static_syms;
1168 sym = lookup_block_symbol (b, DEPRECATED_SYMBOL_NAME (*psym),
1169 NULL, SYMBOL_DOMAIN (*psym));
1172 printf_filtered ("Static symbol `");
1173 puts_filtered (DEPRECATED_SYMBOL_NAME (*psym));
1174 printf_filtered ("' only found in ");
1175 puts_filtered (ps->filename);
1176 printf_filtered (" psymtab\n");
1180 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1181 psym = ps->objfile->global_psymbols.list + ps->globals_offset;
1182 length = ps->n_global_syms;
1185 sym = lookup_block_symbol (b, DEPRECATED_SYMBOL_NAME (*psym),
1186 NULL, SYMBOL_DOMAIN (*psym));
1189 printf_filtered ("Global symbol `");
1190 puts_filtered (DEPRECATED_SYMBOL_NAME (*psym));
1191 printf_filtered ("' only found in ");
1192 puts_filtered (ps->filename);
1193 printf_filtered (" psymtab\n");
1197 if (ps->texthigh < ps->textlow)
1199 printf_filtered ("Psymtab ");
1200 puts_filtered (ps->filename);
1201 printf_filtered (" covers bad range ");
1202 deprecated_print_address_numeric (ps->textlow, 1, gdb_stdout);
1203 printf_filtered (" - ");
1204 deprecated_print_address_numeric (ps->texthigh, 1, gdb_stdout);
1205 printf_filtered ("\n");
1208 if (ps->texthigh == 0)
1210 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
1212 printf_filtered ("Psymtab ");
1213 puts_filtered (ps->filename);
1214 printf_filtered (" covers ");
1215 deprecated_print_address_numeric (ps->textlow, 1, gdb_stdout);
1216 printf_filtered (" - ");
1217 deprecated_print_address_numeric (ps->texthigh, 1, gdb_stdout);
1218 printf_filtered (" but symtab covers only ");
1219 deprecated_print_address_numeric (BLOCK_START (b), 1, gdb_stdout);
1220 printf_filtered (" - ");
1221 deprecated_print_address_numeric (BLOCK_END (b), 1, gdb_stdout);
1222 printf_filtered ("\n");
1228 /* Return the nexting depth of a block within other blocks in its symtab. */
1231 block_depth (struct block *block)
1234 while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
1242 /* Increase the space allocated for LISTP, which is probably
1243 global_psymbols or static_psymbols. This space will eventually
1244 be freed in free_objfile(). */
1247 extend_psymbol_list (struct psymbol_allocation_list *listp,
1248 struct objfile *objfile)
1251 if (listp->size == 0)
1254 listp->list = (struct partial_symbol **)
1255 xmalloc (new_size * sizeof (struct partial_symbol *));
1259 new_size = listp->size * 2;
1260 listp->list = (struct partial_symbol **)
1261 xrealloc ((char *) listp->list,
1262 new_size * sizeof (struct partial_symbol *));
1264 /* Next assumes we only went one over. Should be good if
1265 program works correctly */
1266 listp->next = listp->list + listp->size;
1267 listp->size = new_size;
1271 /* Do early runtime initializations. */
1273 _initialize_symmisc (void)