1 /* Do various things to symbol tables (other than lookup), for GDB.
3 Copyright (C) 1986-2017 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "filenames.h"
27 #include "breakpoint.h"
29 #include "gdb_obstack.h"
33 #include "gdb_regex.h"
35 #include "dictionary.h"
36 #include "typeprint.h"
39 #include "readline/readline.h"
43 /* Unfortunately for debugging, stderr is usually a macro. This is painful
44 when calling functions that take FILE *'s from the debugger.
45 So we make a variable which has the same value and which is accessible when
46 debugging GDB with itself. Because stdin et al need not be constants,
47 we initialize them in the _initialize_symmisc function at the bottom
53 /* Prototypes for local functions */
55 static int block_depth (struct block *);
57 struct print_symbol_args
59 struct gdbarch *gdbarch;
60 struct symbol *symbol;
62 struct ui_file *outfile;
65 static int print_symbol (void *);
69 print_symbol_bcache_statistics (void)
71 struct program_space *pspace;
72 struct objfile *objfile;
75 ALL_PSPACE_OBJFILES (pspace, objfile)
78 printf_filtered (_("Byte cache statistics for '%s':\n"),
79 objfile_name (objfile));
80 print_bcache_statistics (psymbol_bcache_get_bcache (objfile->psymbol_cache),
81 "partial symbol cache");
82 print_bcache_statistics (objfile->per_bfd->macro_cache,
83 "preprocessor macro cache");
84 print_bcache_statistics (objfile->per_bfd->filename_cache,
90 print_objfile_statistics (void)
92 struct program_space *pspace;
93 struct objfile *objfile;
94 struct compunit_symtab *cu;
96 int i, linetables, blockvectors;
99 ALL_PSPACE_OBJFILES (pspace, objfile)
102 printf_filtered (_("Statistics for '%s':\n"), objfile_name (objfile));
103 if (OBJSTAT (objfile, n_stabs) > 0)
104 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
105 OBJSTAT (objfile, n_stabs));
106 if (objfile->per_bfd->n_minsyms > 0)
107 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
108 objfile->per_bfd->n_minsyms);
109 if (OBJSTAT (objfile, n_psyms) > 0)
110 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
111 OBJSTAT (objfile, n_psyms));
112 if (OBJSTAT (objfile, n_syms) > 0)
113 printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
114 OBJSTAT (objfile, n_syms));
115 if (OBJSTAT (objfile, n_types) > 0)
116 printf_filtered (_(" Number of \"types\" defined: %d\n"),
117 OBJSTAT (objfile, n_types));
119 objfile->sf->qf->print_stats (objfile);
120 i = linetables = blockvectors = 0;
121 ALL_OBJFILE_FILETABS (objfile, cu, s)
124 if (SYMTAB_LINETABLE (s) != NULL)
127 ALL_OBJFILE_COMPUNITS (objfile, cu)
129 printf_filtered (_(" Number of symbol tables: %d\n"), i);
130 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
132 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
135 if (OBJSTAT (objfile, sz_strtab) > 0)
136 printf_filtered (_(" Space used by string tables: %d\n"),
137 OBJSTAT (objfile, sz_strtab));
138 printf_filtered (_(" Total memory used for objfile obstack: %s\n"),
139 pulongest (obstack_memory_used (&objfile
140 ->objfile_obstack)));
141 printf_filtered (_(" Total memory used for BFD obstack: %s\n"),
142 pulongest (obstack_memory_used (&objfile->per_bfd
143 ->storage_obstack)));
144 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
145 bcache_memory_used (psymbol_bcache_get_bcache
146 (objfile->psymbol_cache)));
147 printf_filtered (_(" Total memory used for macro cache: %d\n"),
148 bcache_memory_used (objfile->per_bfd->macro_cache));
149 printf_filtered (_(" Total memory used for file name cache: %d\n"),
150 bcache_memory_used (objfile->per_bfd->filename_cache));
155 dump_objfile (struct objfile *objfile)
157 struct compunit_symtab *cust;
158 struct symtab *symtab;
160 printf_filtered ("\nObject file %s: ", objfile_name (objfile));
161 printf_filtered ("Objfile at ");
162 gdb_print_host_address (objfile, gdb_stdout);
163 printf_filtered (", bfd at ");
164 gdb_print_host_address (objfile->obfd, gdb_stdout);
165 printf_filtered (", %d minsyms\n\n",
166 objfile->per_bfd->minimal_symbol_count);
169 objfile->sf->qf->dump (objfile);
171 if (objfile->compunit_symtabs != NULL)
173 printf_filtered ("Symtabs:\n");
174 ALL_OBJFILE_FILETABS (objfile, cust, symtab)
176 printf_filtered ("%s at ", symtab_to_filename_for_display (symtab));
177 gdb_print_host_address (symtab, gdb_stdout);
178 printf_filtered (", ");
179 if (SYMTAB_OBJFILE (symtab) != objfile)
181 printf_filtered ("NOT ON CHAIN! ");
185 printf_filtered ("\n\n");
189 /* Print minimal symbols from this objfile. */
192 dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
194 struct gdbarch *gdbarch = get_objfile_arch (objfile);
195 struct minimal_symbol *msymbol;
199 fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile_name (objfile));
200 if (objfile->per_bfd->minimal_symbol_count == 0)
202 fprintf_filtered (outfile, "No minimal symbols found.\n");
206 ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
208 struct obj_section *section = MSYMBOL_OBJ_SECTION (objfile, msymbol);
210 switch (MSYMBOL_TYPE (msymbol))
218 case mst_text_gnu_ifunc:
221 case mst_solib_trampoline:
246 fprintf_filtered (outfile, "[%2d] %c ", index, ms_type);
247 fputs_filtered (paddress (gdbarch, MSYMBOL_VALUE_ADDRESS (objfile,
250 fprintf_filtered (outfile, " %s", MSYMBOL_LINKAGE_NAME (msymbol));
253 if (section->the_bfd_section != NULL)
254 fprintf_filtered (outfile, " section %s",
255 bfd_section_name (objfile->obfd,
256 section->the_bfd_section));
258 fprintf_filtered (outfile, " spurious section %ld",
259 (long) (section - objfile->sections));
261 if (MSYMBOL_DEMANGLED_NAME (msymbol) != NULL)
263 fprintf_filtered (outfile, " %s", MSYMBOL_DEMANGLED_NAME (msymbol));
265 if (msymbol->filename)
266 fprintf_filtered (outfile, " %s", msymbol->filename);
267 fputs_filtered ("\n", outfile);
270 if (objfile->per_bfd->minimal_symbol_count != index)
272 warning (_("internal error: minimal symbol count %d != %d"),
273 objfile->per_bfd->minimal_symbol_count, index);
275 fprintf_filtered (outfile, "\n");
279 dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
281 struct objfile *objfile = SYMTAB_OBJFILE (symtab);
282 struct gdbarch *gdbarch = get_objfile_arch (objfile);
284 struct dict_iterator iter;
287 const struct blockvector *bv;
292 fprintf_filtered (outfile, "\nSymtab for file %s\n",
293 symtab_to_filename_for_display (symtab));
294 if (SYMTAB_DIRNAME (symtab) != NULL)
295 fprintf_filtered (outfile, "Compilation directory is %s\n",
296 SYMTAB_DIRNAME (symtab));
297 fprintf_filtered (outfile, "Read from object file %s (",
298 objfile_name (objfile));
299 gdb_print_host_address (objfile, outfile);
300 fprintf_filtered (outfile, ")\n");
301 fprintf_filtered (outfile, "Language: %s\n",
302 language_str (symtab->language));
304 /* First print the line table. */
305 l = SYMTAB_LINETABLE (symtab);
308 fprintf_filtered (outfile, "\nLine table:\n\n");
310 for (i = 0; i < len; i++)
312 fprintf_filtered (outfile, " line %d at ", l->item[i].line);
313 fputs_filtered (paddress (gdbarch, l->item[i].pc), outfile);
314 fprintf_filtered (outfile, "\n");
317 /* Now print the block info, but only for compunit symtabs since we will
318 print lots of duplicate info otherwise. */
319 if (symtab == COMPUNIT_FILETABS (SYMTAB_COMPUNIT (symtab)))
321 fprintf_filtered (outfile, "\nBlockvector:\n\n");
322 bv = SYMTAB_BLOCKVECTOR (symtab);
323 len = BLOCKVECTOR_NBLOCKS (bv);
324 for (i = 0; i < len; i++)
326 b = BLOCKVECTOR_BLOCK (bv, i);
327 depth = block_depth (b) * 2;
328 print_spaces (depth, outfile);
329 fprintf_filtered (outfile, "block #%03d, object at ", i);
330 gdb_print_host_address (b, outfile);
331 if (BLOCK_SUPERBLOCK (b))
333 fprintf_filtered (outfile, " under ");
334 gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile);
336 /* drow/2002-07-10: We could save the total symbols count
337 even if we're using a hashtable, but nothing else but this message
339 fprintf_filtered (outfile, ", %d syms/buckets in ",
340 dict_size (BLOCK_DICT (b)));
341 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), outfile);
342 fprintf_filtered (outfile, "..");
343 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), outfile);
344 if (BLOCK_FUNCTION (b))
346 fprintf_filtered (outfile, ", function %s",
347 SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b)));
348 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
350 fprintf_filtered (outfile, ", %s",
351 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
354 fprintf_filtered (outfile, "\n");
355 /* Now print each symbol in this block (in no particular order, if
356 we're using a hashtable). Note that we only want this
357 block, not any blocks from included symtabs. */
358 ALL_DICT_SYMBOLS (BLOCK_DICT (b), iter, sym)
360 struct print_symbol_args s;
366 catch_errors (print_symbol, &s, "Error printing symbol:\n",
370 fprintf_filtered (outfile, "\n");
374 const char *compunit_filename
375 = symtab_to_filename_for_display (COMPUNIT_FILETABS (SYMTAB_COMPUNIT (symtab)));
377 fprintf_filtered (outfile,
378 "\nBlockvector same as owning compunit: %s\n\n",
384 dump_symtab (struct symtab *symtab, struct ui_file *outfile)
386 /* Set the current language to the language of the symtab we're dumping
387 because certain routines used during dump_symtab() use the current
388 language to print an image of the symbol. We'll restore it later.
389 But use only real languages, not placeholders. */
390 if (symtab->language != language_unknown
391 && symtab->language != language_auto)
393 enum language saved_lang;
395 saved_lang = set_language (symtab->language);
397 dump_symtab_1 (symtab, outfile);
399 set_language (saved_lang);
402 dump_symtab_1 (symtab, outfile);
406 maintenance_print_symbols (const char *args, int from_tty)
408 struct ui_file *outfile = gdb_stdout;
409 char *address_arg = NULL, *source_arg = NULL, *objfile_arg = NULL;
414 gdb_argv argv (args);
416 for (i = 0; argv != NULL && argv[i] != NULL; ++i)
418 if (strcmp (argv[i], "-pc") == 0)
420 if (argv[i + 1] == NULL)
421 error (_("Missing pc value"));
422 address_arg = argv[++i];
424 else if (strcmp (argv[i], "-source") == 0)
426 if (argv[i + 1] == NULL)
427 error (_("Missing source file"));
428 source_arg = argv[++i];
430 else if (strcmp (argv[i], "-objfile") == 0)
432 if (argv[i + 1] == NULL)
433 error (_("Missing objfile name"));
434 objfile_arg = argv[++i];
436 else if (strcmp (argv[i], "--") == 0)
438 /* End of options. */
442 else if (argv[i][0] == '-')
444 /* Future proofing: Don't allow OUTFILE to begin with "-". */
445 error (_("Unknown option: %s"), argv[i]);
452 if (address_arg != NULL && source_arg != NULL)
453 error (_("Must specify at most one of -pc and -source"));
455 stdio_file arg_outfile;
457 if (argv != NULL && argv[outfile_idx] != NULL)
459 if (argv[outfile_idx + 1] != NULL)
460 error (_("Junk at end of command"));
461 gdb::unique_xmalloc_ptr<char> outfile_name
462 (tilde_expand (argv[outfile_idx]));
463 if (!arg_outfile.open (outfile_name.get (), FOPEN_WT))
464 perror_with_name (outfile_name.get ());
465 outfile = &arg_outfile;
468 if (address_arg != NULL)
470 CORE_ADDR pc = parse_and_eval_address (address_arg);
471 struct symtab *s = find_pc_line_symtab (pc);
474 error (_("No symtab for address: %s"), address_arg);
475 dump_symtab (s, outfile);
479 struct objfile *objfile;
480 struct compunit_symtab *cu;
484 ALL_OBJFILES (objfile)
486 int print_for_objfile = 1;
488 if (objfile_arg != NULL)
490 = compare_filenames_for_search (objfile_name (objfile),
492 if (!print_for_objfile)
495 ALL_OBJFILE_FILETABS (objfile, cu, s)
497 int print_for_source = 0;
500 if (source_arg != NULL)
503 = compare_filenames_for_search
504 (symtab_to_filename_for_display (s), source_arg);
507 if (source_arg == NULL
509 dump_symtab (s, outfile);
513 if (source_arg != NULL && !found)
514 error (_("No symtab for source file: %s"), source_arg);
518 /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
519 far to indent. ARGS is really a struct print_symbol_args *, but is
520 declared as char * to get it past catch_errors. Returns 0 for error,
524 print_symbol (void *args)
526 struct gdbarch *gdbarch = ((struct print_symbol_args *) args)->gdbarch;
527 struct symbol *symbol = ((struct print_symbol_args *) args)->symbol;
528 int depth = ((struct print_symbol_args *) args)->depth;
529 struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile;
530 struct obj_section *section;
532 if (SYMBOL_OBJFILE_OWNED (symbol))
533 section = SYMBOL_OBJ_SECTION (symbol_objfile (symbol), symbol);
537 print_spaces (depth, outfile);
538 if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN)
540 fprintf_filtered (outfile, "label %s at ", SYMBOL_PRINT_NAME (symbol));
541 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
544 fprintf_filtered (outfile, " section %s\n",
545 bfd_section_name (section->the_bfd_section->owner,
546 section->the_bfd_section));
548 fprintf_filtered (outfile, "\n");
551 if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN)
553 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
555 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth,
556 &type_print_raw_options);
560 fprintf_filtered (outfile, "%s %s = ",
561 (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
563 : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
564 ? "struct" : "union")),
565 SYMBOL_LINKAGE_NAME (symbol));
566 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth,
567 &type_print_raw_options);
569 fprintf_filtered (outfile, ";\n");
573 if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
574 fprintf_filtered (outfile, "typedef ");
575 if (SYMBOL_TYPE (symbol))
577 /* Print details of types, except for enums where it's clutter. */
578 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_PRINT_NAME (symbol),
580 TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
582 &type_print_raw_options);
583 fprintf_filtered (outfile, "; ");
586 fprintf_filtered (outfile, "%s ", SYMBOL_PRINT_NAME (symbol));
588 switch (SYMBOL_CLASS (symbol))
591 fprintf_filtered (outfile, "const %s (%s)",
592 plongest (SYMBOL_VALUE (symbol)),
593 hex_string (SYMBOL_VALUE (symbol)));
596 case LOC_CONST_BYTES:
599 struct type *type = check_typedef (SYMBOL_TYPE (symbol));
601 fprintf_filtered (outfile, "const %u hex bytes:",
603 for (i = 0; i < TYPE_LENGTH (type); i++)
604 fprintf_filtered (outfile, " %02x",
605 (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]);
610 fprintf_filtered (outfile, "static at ");
611 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
614 fprintf_filtered (outfile, " section %s",
615 bfd_section_name (section->the_bfd_section->owner,
616 section->the_bfd_section));
620 if (SYMBOL_IS_ARGUMENT (symbol))
621 fprintf_filtered (outfile, "parameter register %s",
622 plongest (SYMBOL_VALUE (symbol)));
624 fprintf_filtered (outfile, "register %s",
625 plongest (SYMBOL_VALUE (symbol)));
629 fprintf_filtered (outfile, "arg at offset %s",
630 hex_string (SYMBOL_VALUE (symbol)));
634 fprintf_filtered (outfile, "reference arg at %s",
635 hex_string (SYMBOL_VALUE (symbol)));
638 case LOC_REGPARM_ADDR:
639 fprintf_filtered (outfile, "address parameter register %s",
640 plongest (SYMBOL_VALUE (symbol)));
644 fprintf_filtered (outfile, "local at offset %s",
645 hex_string (SYMBOL_VALUE (symbol)));
652 fprintf_filtered (outfile, "label at ");
653 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
656 fprintf_filtered (outfile, " section %s",
657 bfd_section_name (section->the_bfd_section->owner,
658 section->the_bfd_section));
662 fprintf_filtered (outfile, "block object ");
663 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
664 fprintf_filtered (outfile, ", ");
665 fputs_filtered (paddress (gdbarch,
666 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol))),
668 fprintf_filtered (outfile, "..");
669 fputs_filtered (paddress (gdbarch,
670 BLOCK_END (SYMBOL_BLOCK_VALUE (symbol))),
673 fprintf_filtered (outfile, " section %s",
674 bfd_section_name (section->the_bfd_section->owner,
675 section->the_bfd_section));
679 fprintf_filtered (outfile, "computed at runtime");
683 fprintf_filtered (outfile, "unresolved");
686 case LOC_OPTIMIZED_OUT:
687 fprintf_filtered (outfile, "optimized out");
691 fprintf_filtered (outfile, "botched symbol class %x",
692 SYMBOL_CLASS (symbol));
696 fprintf_filtered (outfile, "\n");
701 maintenance_print_msymbols (const char *args, int from_tty)
703 struct ui_file *outfile = gdb_stdout;
704 char *objfile_arg = NULL;
705 struct objfile *objfile;
710 gdb_argv argv (args);
712 for (i = 0; argv != NULL && argv[i] != NULL; ++i)
714 if (strcmp (argv[i], "-objfile") == 0)
716 if (argv[i + 1] == NULL)
717 error (_("Missing objfile name"));
718 objfile_arg = argv[++i];
720 else if (strcmp (argv[i], "--") == 0)
722 /* End of options. */
726 else if (argv[i][0] == '-')
728 /* Future proofing: Don't allow OUTFILE to begin with "-". */
729 error (_("Unknown option: %s"), argv[i]);
736 stdio_file arg_outfile;
738 if (argv != NULL && argv[outfile_idx] != NULL)
740 if (argv[outfile_idx + 1] != NULL)
741 error (_("Junk at end of command"));
742 gdb::unique_xmalloc_ptr<char> outfile_name
743 (tilde_expand (argv[outfile_idx]));
744 if (!arg_outfile.open (outfile_name.get (), FOPEN_WT))
745 perror_with_name (outfile_name.get ());
746 outfile = &arg_outfile;
749 ALL_OBJFILES (objfile)
752 if (objfile_arg == NULL
753 || compare_filenames_for_search (objfile_name (objfile), objfile_arg))
754 dump_msymbols (objfile, outfile);
759 maintenance_print_objfiles (const char *regexp, int from_tty)
761 struct program_space *pspace;
762 struct objfile *objfile;
770 ALL_PSPACE_OBJFILES (pspace, objfile)
774 || re_exec (objfile_name (objfile)))
775 dump_objfile (objfile);
779 /* List all the symbol tables whose names match REGEXP (optional). */
782 maintenance_info_symtabs (const char *regexp, int from_tty)
784 struct program_space *pspace;
785 struct objfile *objfile;
793 ALL_PSPACE_OBJFILES (pspace, objfile)
795 struct compunit_symtab *cust;
796 struct symtab *symtab;
798 /* We don't want to print anything for this objfile until we
799 actually find a symtab whose name matches. */
800 int printed_objfile_start = 0;
802 ALL_OBJFILE_COMPUNITS (objfile, cust)
804 int printed_compunit_symtab_start = 0;
806 ALL_COMPUNIT_FILETABS (cust, symtab)
811 || re_exec (symtab_to_filename_for_display (symtab)))
813 if (! printed_objfile_start)
815 printf_filtered ("{ objfile %s ", objfile_name (objfile));
817 printf_filtered ("((struct objfile *) %s)\n",
818 host_address_to_string (objfile));
819 printed_objfile_start = 1;
821 if (! printed_compunit_symtab_start)
823 printf_filtered (" { ((struct compunit_symtab *) %s)\n",
824 host_address_to_string (cust));
825 printf_filtered (" debugformat %s\n",
826 COMPUNIT_DEBUGFORMAT (cust));
827 printf_filtered (" producer %s\n",
828 COMPUNIT_PRODUCER (cust) != NULL
829 ? COMPUNIT_PRODUCER (cust)
831 printf_filtered (" dirname %s\n",
832 COMPUNIT_DIRNAME (cust) != NULL
833 ? COMPUNIT_DIRNAME (cust)
835 printf_filtered (" blockvector"
836 " ((struct blockvector *) %s)\n",
837 host_address_to_string
838 (COMPUNIT_BLOCKVECTOR (cust)));
839 printed_compunit_symtab_start = 1;
842 printf_filtered ("\t{ symtab %s ",
843 symtab_to_filename_for_display (symtab));
845 printf_filtered ("((struct symtab *) %s)\n",
846 host_address_to_string (symtab));
847 printf_filtered ("\t fullname %s\n",
848 symtab->fullname != NULL
851 printf_filtered ("\t "
852 "linetable ((struct linetable *) %s)\n",
853 host_address_to_string (symtab->linetable));
854 printf_filtered ("\t}\n");
858 if (printed_compunit_symtab_start)
859 printf_filtered (" }\n");
862 if (printed_objfile_start)
863 printf_filtered ("}\n");
867 /* Check consistency of symtabs.
868 An example of what this checks for is NULL blockvectors.
869 They can happen if there's a bug during debug info reading.
870 GDB assumes they are always non-NULL.
872 Note: This does not check for psymtab vs symtab consistency.
873 Use "maint check-psymtabs" for that. */
876 maintenance_check_symtabs (const char *ignore, int from_tty)
878 struct program_space *pspace;
879 struct objfile *objfile;
882 ALL_PSPACE_OBJFILES (pspace, objfile)
884 struct compunit_symtab *cust;
886 /* We don't want to print anything for this objfile until we
887 actually find something worth printing. */
888 int printed_objfile_start = 0;
890 ALL_OBJFILE_COMPUNITS (objfile, cust)
892 int found_something = 0;
893 struct symtab *symtab = compunit_primary_filetab (cust);
897 if (COMPUNIT_BLOCKVECTOR (cust) == NULL)
899 /* Add more checks here. */
903 if (! printed_objfile_start)
905 printf_filtered ("{ objfile %s ", objfile_name (objfile));
907 printf_filtered ("((struct objfile *) %s)\n",
908 host_address_to_string (objfile));
909 printed_objfile_start = 1;
911 printf_filtered (" { symtab %s\n",
912 symtab_to_filename_for_display (symtab));
913 if (COMPUNIT_BLOCKVECTOR (cust) == NULL)
914 printf_filtered (" NULL blockvector\n");
915 printf_filtered (" }\n");
919 if (printed_objfile_start)
920 printf_filtered ("}\n");
924 /* Expand all symbol tables whose name matches an optional regexp. */
927 maintenance_expand_symtabs (const char *args, int from_tty)
929 struct program_space *pspace;
930 struct objfile *objfile;
933 /* We use buildargv here so that we handle spaces in the regexp
934 in a way that allows adding more arguments later. */
935 gdb_argv argv (args);
943 error (_("Extra arguments after regexp."));
951 ALL_PSPACE_OBJFILES (pspace, objfile)
955 objfile->sf->qf->expand_symtabs_matching
957 [&] (const char *filename, bool basenames)
959 /* KISS: Only apply the regexp to the complete file name. */
961 && (regexp == NULL || re_exec (filename)));
963 [] (const char *symname)
965 /* Since we're not searching on symbols, just return true. */
975 /* Return the nexting depth of a block within other blocks in its symtab. */
978 block_depth (struct block *block)
982 while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
990 /* Used by MAINTENANCE_INFO_LINE_TABLES to print the information about a
991 single line table. */
994 maintenance_print_one_line_table (struct symtab *symtab, void *data)
996 struct linetable *linetable;
997 struct objfile *objfile;
999 objfile = symtab->compunit_symtab->objfile;
1000 printf_filtered (_("objfile: %s ((struct objfile *) %s)\n"),
1001 objfile_name (objfile),
1002 host_address_to_string (objfile));
1003 printf_filtered (_("compunit_symtab: ((struct compunit_symtab *) %s)\n"),
1004 host_address_to_string (symtab->compunit_symtab));
1005 printf_filtered (_("symtab: %s ((struct symtab *) %s)\n"),
1006 symtab_to_fullname (symtab),
1007 host_address_to_string (symtab));
1008 linetable = SYMTAB_LINETABLE (symtab);
1009 printf_filtered (_("linetable: ((struct linetable *) %s):\n"),
1010 host_address_to_string (linetable));
1012 if (linetable == NULL)
1013 printf_filtered (_("No line table.\n"));
1014 else if (linetable->nitems <= 0)
1015 printf_filtered (_("Line table has no lines.\n"));
1020 /* Leave space for 6 digits of index and line number. After that the
1021 tables will just not format as well. */
1022 printf_filtered (_("%-6s %6s %s\n"),
1023 _("INDEX"), _("LINE"), _("ADDRESS"));
1025 for (i = 0; i < linetable->nitems; ++i)
1027 struct linetable_entry *item;
1029 item = &linetable->item [i];
1030 printf_filtered (_("%-6d %6d %s\n"), i, item->line,
1031 core_addr_to_string (item->pc));
1038 /* Implement the 'maint info line-table' command. */
1041 maintenance_info_line_tables (const char *regexp, int from_tty)
1043 struct program_space *pspace;
1044 struct objfile *objfile;
1051 ALL_PSPACES (pspace)
1052 ALL_PSPACE_OBJFILES (pspace, objfile)
1054 struct compunit_symtab *cust;
1055 struct symtab *symtab;
1057 ALL_OBJFILE_COMPUNITS (objfile, cust)
1059 ALL_COMPUNIT_FILETABS (cust, symtab)
1064 || re_exec (symtab_to_filename_for_display (symtab)))
1065 maintenance_print_one_line_table (symtab, NULL);
1073 /* Do early runtime initializations. */
1076 _initialize_symmisc (void)
1082 add_cmd ("symbols", class_maintenance, maintenance_print_symbols, _("\
1083 Print dump of current symbol definitions.\n\
1084 Usage: mt print symbols [-pc address] [--] [outfile]\n\
1085 mt print symbols [-objfile objfile] [-source source] [--] [outfile]\n\
1086 Entries in the full symbol table are dumped to file OUTFILE,\n\
1087 or the terminal if OUTFILE is unspecified.\n\
1088 If ADDRESS is provided, dump only the file for that address.\n\
1089 If SOURCE is provided, dump only that file's symbols.\n\
1090 If OBJFILE is provided, dump only that file's minimal symbols."),
1091 &maintenanceprintlist);
1093 add_cmd ("msymbols", class_maintenance, maintenance_print_msymbols, _("\
1094 Print dump of current minimal symbol definitions.\n\
1095 Usage: mt print msymbols [-objfile objfile] [--] [outfile]\n\
1096 Entries in the minimal symbol table are dumped to file OUTFILE,\n\
1097 or the terminal if OUTFILE is unspecified.\n\
1098 If OBJFILE is provided, dump only that file's minimal symbols."),
1099 &maintenanceprintlist);
1101 add_cmd ("objfiles", class_maintenance, maintenance_print_objfiles,
1102 _("Print dump of current object file definitions.\n\
1103 With an argument REGEXP, list the object files with matching names."),
1104 &maintenanceprintlist);
1106 add_cmd ("symtabs", class_maintenance, maintenance_info_symtabs, _("\
1107 List the full symbol tables for all object files.\n\
1108 This does not include information about individual symbols, blocks, or\n\
1109 linetables --- just the symbol table structures themselves.\n\
1110 With an argument REGEXP, list the symbol tables with matching names."),
1111 &maintenanceinfolist);
1113 add_cmd ("line-table", class_maintenance, maintenance_info_line_tables, _("\
1114 List the contents of all line tables, from all symbol tables.\n\
1115 With an argument REGEXP, list just the line tables for the symbol\n\
1116 tables with matching names."),
1117 &maintenanceinfolist);
1119 add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs,
1121 Check consistency of currently expanded symtabs."),
1124 add_cmd ("expand-symtabs", class_maintenance, maintenance_expand_symtabs,
1125 _("Expand symbol tables.\n\
1126 With an argument REGEXP, only expand the symbol tables with matching names."),