1 /* Do various things to symbol tables (other than lookup), for GDB.
3 Copyright (C) 1986-2019 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 static void print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
58 int depth, ui_file *outfile);
62 print_symbol_bcache_statistics (void)
64 struct program_space *pspace;
67 for (objfile *objfile : all_objfiles (pspace))
70 printf_filtered (_("Byte cache statistics for '%s':\n"),
71 objfile_name (objfile));
72 print_bcache_statistics (psymbol_bcache_get_bcache (objfile->psymbol_cache),
73 "partial symbol cache");
74 print_bcache_statistics (objfile->per_bfd->macro_cache,
75 "preprocessor macro cache");
76 print_bcache_statistics (objfile->per_bfd->filename_cache,
82 print_objfile_statistics (void)
84 struct program_space *pspace;
86 int i, linetables, blockvectors;
89 for (objfile *objfile : all_objfiles (pspace))
92 printf_filtered (_("Statistics for '%s':\n"), objfile_name (objfile));
93 if (OBJSTAT (objfile, n_stabs) > 0)
94 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
95 OBJSTAT (objfile, n_stabs));
96 if (objfile->per_bfd->n_minsyms > 0)
97 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
98 objfile->per_bfd->n_minsyms);
99 if (OBJSTAT (objfile, n_psyms) > 0)
100 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
101 OBJSTAT (objfile, n_psyms));
102 if (OBJSTAT (objfile, n_syms) > 0)
103 printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
104 OBJSTAT (objfile, n_syms));
105 if (OBJSTAT (objfile, n_types) > 0)
106 printf_filtered (_(" Number of \"types\" defined: %d\n"),
107 OBJSTAT (objfile, n_types));
109 objfile->sf->qf->print_stats (objfile);
111 ALL_OBJFILE_FILETABS (objfile, cu, s)
114 if (SYMTAB_LINETABLE (s) != NULL)
117 blockvectors = std::distance (objfile_compunits (objfile).begin (),
118 objfile_compunits (objfile).end ());
119 printf_filtered (_(" Number of symbol tables: %d\n"), i);
120 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
122 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
125 if (OBJSTAT (objfile, sz_strtab) > 0)
126 printf_filtered (_(" Space used by string tables: %d\n"),
127 OBJSTAT (objfile, sz_strtab));
128 printf_filtered (_(" Total memory used for objfile obstack: %s\n"),
129 pulongest (obstack_memory_used (&objfile
130 ->objfile_obstack)));
131 printf_filtered (_(" Total memory used for BFD obstack: %s\n"),
132 pulongest (obstack_memory_used (&objfile->per_bfd
133 ->storage_obstack)));
134 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
135 bcache_memory_used (psymbol_bcache_get_bcache
136 (objfile->psymbol_cache)));
137 printf_filtered (_(" Total memory used for macro cache: %d\n"),
138 bcache_memory_used (objfile->per_bfd->macro_cache));
139 printf_filtered (_(" Total memory used for file name cache: %d\n"),
140 bcache_memory_used (objfile->per_bfd->filename_cache));
145 dump_objfile (struct objfile *objfile)
147 struct symtab *symtab;
149 printf_filtered ("\nObject file %s: ", objfile_name (objfile));
150 printf_filtered ("Objfile at ");
151 gdb_print_host_address (objfile, gdb_stdout);
152 printf_filtered (", bfd at ");
153 gdb_print_host_address (objfile->obfd, gdb_stdout);
154 printf_filtered (", %d minsyms\n\n",
155 objfile->per_bfd->minimal_symbol_count);
158 objfile->sf->qf->dump (objfile);
160 if (objfile->compunit_symtabs != NULL)
162 printf_filtered ("Symtabs:\n");
163 ALL_OBJFILE_FILETABS (objfile, cust, symtab)
165 printf_filtered ("%s at ", symtab_to_filename_for_display (symtab));
166 gdb_print_host_address (symtab, gdb_stdout);
167 printf_filtered (", ");
168 if (SYMTAB_OBJFILE (symtab) != objfile)
170 printf_filtered ("NOT ON CHAIN! ");
174 printf_filtered ("\n\n");
178 /* Print minimal symbols from this objfile. */
181 dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
183 struct gdbarch *gdbarch = get_objfile_arch (objfile);
187 fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile_name (objfile));
188 if (objfile->per_bfd->minimal_symbol_count == 0)
190 fprintf_filtered (outfile, "No minimal symbols found.\n");
194 for (minimal_symbol *msymbol : objfile_msymbols (objfile))
196 struct obj_section *section = MSYMBOL_OBJ_SECTION (objfile, msymbol);
198 switch (MSYMBOL_TYPE (msymbol))
206 case mst_text_gnu_ifunc:
207 case mst_data_gnu_ifunc:
210 case mst_solib_trampoline:
235 fprintf_filtered (outfile, "[%2d] %c ", index, ms_type);
236 fputs_filtered (paddress (gdbarch, MSYMBOL_VALUE_ADDRESS (objfile,
239 fprintf_filtered (outfile, " %s", MSYMBOL_LINKAGE_NAME (msymbol));
242 if (section->the_bfd_section != NULL)
243 fprintf_filtered (outfile, " section %s",
244 bfd_section_name (objfile->obfd,
245 section->the_bfd_section));
247 fprintf_filtered (outfile, " spurious section %ld",
248 (long) (section - objfile->sections));
250 if (MSYMBOL_DEMANGLED_NAME (msymbol) != NULL)
252 fprintf_filtered (outfile, " %s", MSYMBOL_DEMANGLED_NAME (msymbol));
254 if (msymbol->filename)
255 fprintf_filtered (outfile, " %s", msymbol->filename);
256 fputs_filtered ("\n", outfile);
259 if (objfile->per_bfd->minimal_symbol_count != index)
261 warning (_("internal error: minimal symbol count %d != %d"),
262 objfile->per_bfd->minimal_symbol_count, index);
264 fprintf_filtered (outfile, "\n");
268 dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
270 struct objfile *objfile = SYMTAB_OBJFILE (symtab);
271 struct gdbarch *gdbarch = get_objfile_arch (objfile);
273 struct dict_iterator iter;
276 const struct blockvector *bv;
281 fprintf_filtered (outfile, "\nSymtab for file %s\n",
282 symtab_to_filename_for_display (symtab));
283 if (SYMTAB_DIRNAME (symtab) != NULL)
284 fprintf_filtered (outfile, "Compilation directory is %s\n",
285 SYMTAB_DIRNAME (symtab));
286 fprintf_filtered (outfile, "Read from object file %s (",
287 objfile_name (objfile));
288 gdb_print_host_address (objfile, outfile);
289 fprintf_filtered (outfile, ")\n");
290 fprintf_filtered (outfile, "Language: %s\n",
291 language_str (symtab->language));
293 /* First print the line table. */
294 l = SYMTAB_LINETABLE (symtab);
297 fprintf_filtered (outfile, "\nLine table:\n\n");
299 for (i = 0; i < len; i++)
301 fprintf_filtered (outfile, " line %d at ", l->item[i].line);
302 fputs_filtered (paddress (gdbarch, l->item[i].pc), outfile);
303 fprintf_filtered (outfile, "\n");
306 /* Now print the block info, but only for compunit symtabs since we will
307 print lots of duplicate info otherwise. */
308 if (symtab == COMPUNIT_FILETABS (SYMTAB_COMPUNIT (symtab)))
310 fprintf_filtered (outfile, "\nBlockvector:\n\n");
311 bv = SYMTAB_BLOCKVECTOR (symtab);
312 len = BLOCKVECTOR_NBLOCKS (bv);
313 for (i = 0; i < len; i++)
315 b = BLOCKVECTOR_BLOCK (bv, i);
316 depth = block_depth (b) * 2;
317 print_spaces (depth, outfile);
318 fprintf_filtered (outfile, "block #%03d, object at ", i);
319 gdb_print_host_address (b, outfile);
320 if (BLOCK_SUPERBLOCK (b))
322 fprintf_filtered (outfile, " under ");
323 gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile);
325 /* drow/2002-07-10: We could save the total symbols count
326 even if we're using a hashtable, but nothing else but this message
328 fprintf_filtered (outfile, ", %d syms/buckets in ",
329 dict_size (BLOCK_DICT (b)));
330 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), outfile);
331 fprintf_filtered (outfile, "..");
332 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), outfile);
333 if (BLOCK_FUNCTION (b))
335 fprintf_filtered (outfile, ", function %s",
336 SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b)));
337 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
339 fprintf_filtered (outfile, ", %s",
340 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
343 fprintf_filtered (outfile, "\n");
344 /* Now print each symbol in this block (in no particular order, if
345 we're using a hashtable). Note that we only want this
346 block, not any blocks from included symtabs. */
347 ALL_DICT_SYMBOLS (BLOCK_DICT (b), iter, sym)
351 print_symbol (gdbarch, sym, depth + 1, outfile);
353 CATCH (ex, RETURN_MASK_ERROR)
355 exception_fprintf (gdb_stderr, ex,
356 "Error printing symbol:\n");
361 fprintf_filtered (outfile, "\n");
365 const char *compunit_filename
366 = symtab_to_filename_for_display (COMPUNIT_FILETABS (SYMTAB_COMPUNIT (symtab)));
368 fprintf_filtered (outfile,
369 "\nBlockvector same as owning compunit: %s\n\n",
375 dump_symtab (struct symtab *symtab, struct ui_file *outfile)
377 /* Set the current language to the language of the symtab we're dumping
378 because certain routines used during dump_symtab() use the current
379 language to print an image of the symbol. We'll restore it later.
380 But use only real languages, not placeholders. */
381 if (symtab->language != language_unknown
382 && symtab->language != language_auto)
384 enum language saved_lang;
386 saved_lang = set_language (symtab->language);
388 dump_symtab_1 (symtab, outfile);
390 set_language (saved_lang);
393 dump_symtab_1 (symtab, outfile);
397 maintenance_print_symbols (const char *args, int from_tty)
399 struct ui_file *outfile = gdb_stdout;
400 char *address_arg = NULL, *source_arg = NULL, *objfile_arg = NULL;
405 gdb_argv argv (args);
407 for (i = 0; argv != NULL && argv[i] != NULL; ++i)
409 if (strcmp (argv[i], "-pc") == 0)
411 if (argv[i + 1] == NULL)
412 error (_("Missing pc value"));
413 address_arg = argv[++i];
415 else if (strcmp (argv[i], "-source") == 0)
417 if (argv[i + 1] == NULL)
418 error (_("Missing source file"));
419 source_arg = argv[++i];
421 else if (strcmp (argv[i], "-objfile") == 0)
423 if (argv[i + 1] == NULL)
424 error (_("Missing objfile name"));
425 objfile_arg = argv[++i];
427 else if (strcmp (argv[i], "--") == 0)
429 /* End of options. */
433 else if (argv[i][0] == '-')
435 /* Future proofing: Don't allow OUTFILE to begin with "-". */
436 error (_("Unknown option: %s"), argv[i]);
443 if (address_arg != NULL && source_arg != NULL)
444 error (_("Must specify at most one of -pc and -source"));
446 stdio_file arg_outfile;
448 if (argv != NULL && argv[outfile_idx] != NULL)
450 if (argv[outfile_idx + 1] != NULL)
451 error (_("Junk at end of command"));
452 gdb::unique_xmalloc_ptr<char> outfile_name
453 (tilde_expand (argv[outfile_idx]));
454 if (!arg_outfile.open (outfile_name.get (), FOPEN_WT))
455 perror_with_name (outfile_name.get ());
456 outfile = &arg_outfile;
459 if (address_arg != NULL)
461 CORE_ADDR pc = parse_and_eval_address (address_arg);
462 struct symtab *s = find_pc_line_symtab (pc);
465 error (_("No symtab for address: %s"), address_arg);
466 dump_symtab (s, outfile);
473 for (objfile *objfile : all_objfiles (current_program_space))
475 int print_for_objfile = 1;
477 if (objfile_arg != NULL)
479 = compare_filenames_for_search (objfile_name (objfile),
481 if (!print_for_objfile)
484 ALL_OBJFILE_FILETABS (objfile, cu, s)
486 int print_for_source = 0;
489 if (source_arg != NULL)
492 = compare_filenames_for_search
493 (symtab_to_filename_for_display (s), source_arg);
496 if (source_arg == NULL
498 dump_symtab (s, outfile);
502 if (source_arg != NULL && !found)
503 error (_("No symtab for source file: %s"), source_arg);
507 /* Print symbol SYMBOL on OUTFILE. DEPTH says how far to indent. */
510 print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
511 int depth, ui_file *outfile)
513 struct obj_section *section;
515 if (SYMBOL_OBJFILE_OWNED (symbol))
516 section = SYMBOL_OBJ_SECTION (symbol_objfile (symbol), symbol);
520 print_spaces (depth, outfile);
521 if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN)
523 fprintf_filtered (outfile, "label %s at ", SYMBOL_PRINT_NAME (symbol));
524 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
527 fprintf_filtered (outfile, " section %s\n",
528 bfd_section_name (section->the_bfd_section->owner,
529 section->the_bfd_section));
531 fprintf_filtered (outfile, "\n");
535 if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN)
537 if (TYPE_NAME (SYMBOL_TYPE (symbol)))
539 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth,
540 &type_print_raw_options);
544 fprintf_filtered (outfile, "%s %s = ",
545 (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
547 : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
548 ? "struct" : "union")),
549 SYMBOL_LINKAGE_NAME (symbol));
550 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth,
551 &type_print_raw_options);
553 fprintf_filtered (outfile, ";\n");
557 if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
558 fprintf_filtered (outfile, "typedef ");
559 if (SYMBOL_TYPE (symbol))
561 /* Print details of types, except for enums where it's clutter. */
562 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_PRINT_NAME (symbol),
564 TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
566 &type_print_raw_options);
567 fprintf_filtered (outfile, "; ");
570 fprintf_filtered (outfile, "%s ", SYMBOL_PRINT_NAME (symbol));
572 switch (SYMBOL_CLASS (symbol))
575 fprintf_filtered (outfile, "const %s (%s)",
576 plongest (SYMBOL_VALUE (symbol)),
577 hex_string (SYMBOL_VALUE (symbol)));
580 case LOC_CONST_BYTES:
583 struct type *type = check_typedef (SYMBOL_TYPE (symbol));
585 fprintf_filtered (outfile, "const %u hex bytes:",
587 for (i = 0; i < TYPE_LENGTH (type); i++)
588 fprintf_filtered (outfile, " %02x",
589 (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]);
594 fprintf_filtered (outfile, "static at ");
595 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
598 fprintf_filtered (outfile, " section %s",
599 bfd_section_name (section->the_bfd_section->owner,
600 section->the_bfd_section));
604 if (SYMBOL_IS_ARGUMENT (symbol))
605 fprintf_filtered (outfile, "parameter register %s",
606 plongest (SYMBOL_VALUE (symbol)));
608 fprintf_filtered (outfile, "register %s",
609 plongest (SYMBOL_VALUE (symbol)));
613 fprintf_filtered (outfile, "arg at offset %s",
614 hex_string (SYMBOL_VALUE (symbol)));
618 fprintf_filtered (outfile, "reference arg at %s",
619 hex_string (SYMBOL_VALUE (symbol)));
622 case LOC_REGPARM_ADDR:
623 fprintf_filtered (outfile, "address parameter register %s",
624 plongest (SYMBOL_VALUE (symbol)));
628 fprintf_filtered (outfile, "local at offset %s",
629 hex_string (SYMBOL_VALUE (symbol)));
636 fprintf_filtered (outfile, "label at ");
637 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
640 fprintf_filtered (outfile, " section %s",
641 bfd_section_name (section->the_bfd_section->owner,
642 section->the_bfd_section));
646 fprintf_filtered (outfile, "block object ");
647 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
648 fprintf_filtered (outfile, ", ");
649 fputs_filtered (paddress (gdbarch,
650 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol))),
652 fprintf_filtered (outfile, "..");
653 fputs_filtered (paddress (gdbarch,
654 BLOCK_END (SYMBOL_BLOCK_VALUE (symbol))),
657 fprintf_filtered (outfile, " section %s",
658 bfd_section_name (section->the_bfd_section->owner,
659 section->the_bfd_section));
663 fprintf_filtered (outfile, "computed at runtime");
667 fprintf_filtered (outfile, "unresolved");
670 case LOC_OPTIMIZED_OUT:
671 fprintf_filtered (outfile, "optimized out");
675 fprintf_filtered (outfile, "botched symbol class %x",
676 SYMBOL_CLASS (symbol));
680 fprintf_filtered (outfile, "\n");
684 maintenance_print_msymbols (const char *args, int from_tty)
686 struct ui_file *outfile = gdb_stdout;
687 char *objfile_arg = NULL;
692 gdb_argv argv (args);
694 for (i = 0; argv != NULL && argv[i] != NULL; ++i)
696 if (strcmp (argv[i], "-objfile") == 0)
698 if (argv[i + 1] == NULL)
699 error (_("Missing objfile name"));
700 objfile_arg = argv[++i];
702 else if (strcmp (argv[i], "--") == 0)
704 /* End of options. */
708 else if (argv[i][0] == '-')
710 /* Future proofing: Don't allow OUTFILE to begin with "-". */
711 error (_("Unknown option: %s"), argv[i]);
718 stdio_file arg_outfile;
720 if (argv != NULL && argv[outfile_idx] != NULL)
722 if (argv[outfile_idx + 1] != NULL)
723 error (_("Junk at end of command"));
724 gdb::unique_xmalloc_ptr<char> outfile_name
725 (tilde_expand (argv[outfile_idx]));
726 if (!arg_outfile.open (outfile_name.get (), FOPEN_WT))
727 perror_with_name (outfile_name.get ());
728 outfile = &arg_outfile;
731 for (objfile *objfile : all_objfiles (current_program_space))
734 if (objfile_arg == NULL
735 || compare_filenames_for_search (objfile_name (objfile), objfile_arg))
736 dump_msymbols (objfile, outfile);
741 maintenance_print_objfiles (const char *regexp, int from_tty)
743 struct program_space *pspace;
751 for (objfile *objfile : all_objfiles (pspace))
755 || re_exec (objfile_name (objfile)))
756 dump_objfile (objfile);
760 /* List all the symbol tables whose names match REGEXP (optional). */
763 maintenance_info_symtabs (const char *regexp, int from_tty)
765 struct program_space *pspace;
773 for (objfile *objfile : all_objfiles (pspace))
775 struct symtab *symtab;
777 /* We don't want to print anything for this objfile until we
778 actually find a symtab whose name matches. */
779 int printed_objfile_start = 0;
781 for (compunit_symtab *cust : objfile_compunits (objfile))
783 int printed_compunit_symtab_start = 0;
785 ALL_COMPUNIT_FILETABS (cust, symtab)
790 || re_exec (symtab_to_filename_for_display (symtab)))
792 if (! printed_objfile_start)
794 printf_filtered ("{ objfile %s ", objfile_name (objfile));
796 printf_filtered ("((struct objfile *) %s)\n",
797 host_address_to_string (objfile));
798 printed_objfile_start = 1;
800 if (! printed_compunit_symtab_start)
802 printf_filtered (" { ((struct compunit_symtab *) %s)\n",
803 host_address_to_string (cust));
804 printf_filtered (" debugformat %s\n",
805 COMPUNIT_DEBUGFORMAT (cust));
806 printf_filtered (" producer %s\n",
807 COMPUNIT_PRODUCER (cust) != NULL
808 ? COMPUNIT_PRODUCER (cust)
810 printf_filtered (" dirname %s\n",
811 COMPUNIT_DIRNAME (cust) != NULL
812 ? COMPUNIT_DIRNAME (cust)
814 printf_filtered (" blockvector"
815 " ((struct blockvector *) %s)\n",
816 host_address_to_string
817 (COMPUNIT_BLOCKVECTOR (cust)));
818 printed_compunit_symtab_start = 1;
821 printf_filtered ("\t{ symtab %s ",
822 symtab_to_filename_for_display (symtab));
824 printf_filtered ("((struct symtab *) %s)\n",
825 host_address_to_string (symtab));
826 printf_filtered ("\t fullname %s\n",
827 symtab->fullname != NULL
830 printf_filtered ("\t "
831 "linetable ((struct linetable *) %s)\n",
832 host_address_to_string (symtab->linetable));
833 printf_filtered ("\t}\n");
837 if (printed_compunit_symtab_start)
838 printf_filtered (" }\n");
841 if (printed_objfile_start)
842 printf_filtered ("}\n");
846 /* Check consistency of symtabs.
847 An example of what this checks for is NULL blockvectors.
848 They can happen if there's a bug during debug info reading.
849 GDB assumes they are always non-NULL.
851 Note: This does not check for psymtab vs symtab consistency.
852 Use "maint check-psymtabs" for that. */
855 maintenance_check_symtabs (const char *ignore, int from_tty)
857 struct program_space *pspace;
860 for (objfile *objfile : all_objfiles (pspace))
862 /* We don't want to print anything for this objfile until we
863 actually find something worth printing. */
864 int printed_objfile_start = 0;
866 for (compunit_symtab *cust : objfile_compunits (objfile))
868 int found_something = 0;
869 struct symtab *symtab = compunit_primary_filetab (cust);
873 if (COMPUNIT_BLOCKVECTOR (cust) == NULL)
875 /* Add more checks here. */
879 if (! printed_objfile_start)
881 printf_filtered ("{ objfile %s ", objfile_name (objfile));
883 printf_filtered ("((struct objfile *) %s)\n",
884 host_address_to_string (objfile));
885 printed_objfile_start = 1;
887 printf_filtered (" { symtab %s\n",
888 symtab_to_filename_for_display (symtab));
889 if (COMPUNIT_BLOCKVECTOR (cust) == NULL)
890 printf_filtered (" NULL blockvector\n");
891 printf_filtered (" }\n");
895 if (printed_objfile_start)
896 printf_filtered ("}\n");
900 /* Expand all symbol tables whose name matches an optional regexp. */
903 maintenance_expand_symtabs (const char *args, int from_tty)
905 struct program_space *pspace;
908 /* We use buildargv here so that we handle spaces in the regexp
909 in a way that allows adding more arguments later. */
910 gdb_argv argv (args);
918 error (_("Extra arguments after regexp."));
926 for (objfile *objfile : all_objfiles (pspace))
930 objfile->sf->qf->expand_symtabs_matching
932 [&] (const char *filename, bool basenames)
934 /* KISS: Only apply the regexp to the complete file name. */
936 && (regexp == NULL || re_exec (filename)));
938 lookup_name_info::match_any (),
939 [] (const char *symname)
941 /* Since we're not searching on symbols, just return true. */
951 /* Return the nexting depth of a block within other blocks in its symtab. */
954 block_depth (struct block *block)
958 while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
966 /* Used by MAINTENANCE_INFO_LINE_TABLES to print the information about a
967 single line table. */
970 maintenance_print_one_line_table (struct symtab *symtab, void *data)
972 struct linetable *linetable;
973 struct objfile *objfile;
975 objfile = symtab->compunit_symtab->objfile;
976 printf_filtered (_("objfile: %s ((struct objfile *) %s)\n"),
977 objfile_name (objfile),
978 host_address_to_string (objfile));
979 printf_filtered (_("compunit_symtab: ((struct compunit_symtab *) %s)\n"),
980 host_address_to_string (symtab->compunit_symtab));
981 printf_filtered (_("symtab: %s ((struct symtab *) %s)\n"),
982 symtab_to_fullname (symtab),
983 host_address_to_string (symtab));
984 linetable = SYMTAB_LINETABLE (symtab);
985 printf_filtered (_("linetable: ((struct linetable *) %s):\n"),
986 host_address_to_string (linetable));
988 if (linetable == NULL)
989 printf_filtered (_("No line table.\n"));
990 else if (linetable->nitems <= 0)
991 printf_filtered (_("Line table has no lines.\n"));
996 /* Leave space for 6 digits of index and line number. After that the
997 tables will just not format as well. */
998 printf_filtered (_("%-6s %6s %s\n"),
999 _("INDEX"), _("LINE"), _("ADDRESS"));
1001 for (i = 0; i < linetable->nitems; ++i)
1003 struct linetable_entry *item;
1005 item = &linetable->item [i];
1006 printf_filtered (_("%-6d %6d %s\n"), i, item->line,
1007 core_addr_to_string (item->pc));
1014 /* Implement the 'maint info line-table' command. */
1017 maintenance_info_line_tables (const char *regexp, int from_tty)
1019 struct program_space *pspace;
1026 ALL_PSPACES (pspace)
1027 for (objfile *objfile : all_objfiles (pspace))
1029 struct symtab *symtab;
1031 for (compunit_symtab *cust : objfile_compunits (objfile))
1033 ALL_COMPUNIT_FILETABS (cust, symtab)
1038 || re_exec (symtab_to_filename_for_display (symtab)))
1039 maintenance_print_one_line_table (symtab, NULL);
1047 /* Do early runtime initializations. */
1050 _initialize_symmisc (void)
1056 add_cmd ("symbols", class_maintenance, maintenance_print_symbols, _("\
1057 Print dump of current symbol definitions.\n\
1058 Usage: mt print symbols [-pc ADDRESS] [--] [OUTFILE]\n\
1059 mt print symbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
1060 Entries in the full symbol table are dumped to file OUTFILE,\n\
1061 or the terminal if OUTFILE is unspecified.\n\
1062 If ADDRESS is provided, dump only the file for that address.\n\
1063 If SOURCE is provided, dump only that file's symbols.\n\
1064 If OBJFILE is provided, dump only that file's minimal symbols."),
1065 &maintenanceprintlist);
1067 add_cmd ("msymbols", class_maintenance, maintenance_print_msymbols, _("\
1068 Print dump of current minimal symbol definitions.\n\
1069 Usage: mt print msymbols [-objfile OBJFILE] [--] [OUTFILE]\n\
1070 Entries in the minimal symbol table are dumped to file OUTFILE,\n\
1071 or the terminal if OUTFILE is unspecified.\n\
1072 If OBJFILE is provided, dump only that file's minimal symbols."),
1073 &maintenanceprintlist);
1075 add_cmd ("objfiles", class_maintenance, maintenance_print_objfiles,
1076 _("Print dump of current object file definitions.\n\
1077 With an argument REGEXP, list the object files with matching names."),
1078 &maintenanceprintlist);
1080 add_cmd ("symtabs", class_maintenance, maintenance_info_symtabs, _("\
1081 List the full symbol tables for all object files.\n\
1082 This does not include information about individual symbols, blocks, or\n\
1083 linetables --- just the symbol table structures themselves.\n\
1084 With an argument REGEXP, list the symbol tables with matching names."),
1085 &maintenanceinfolist);
1087 add_cmd ("line-table", class_maintenance, maintenance_info_line_tables, _("\
1088 List the contents of all line tables, from all symbol tables.\n\
1089 With an argument REGEXP, list just the line tables for the symbol\n\
1090 tables with matching names."),
1091 &maintenanceinfolist);
1093 add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs,
1095 Check consistency of currently expanded symtabs."),
1098 add_cmd ("expand-symtabs", class_maintenance, maintenance_expand_symtabs,
1099 _("Expand symbol tables.\n\
1100 With an argument REGEXP, only expand the symbol tables with matching names."),