1 /* Do various things to symbol tables (other than lookup), for GDB.
3 Copyright (C) 1986-2018 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
;
65 struct objfile
*objfile
;
68 ALL_PSPACE_OBJFILES (pspace
, objfile
)
71 printf_filtered (_("Byte cache statistics for '%s':\n"),
72 objfile_name (objfile
));
73 print_bcache_statistics (psymbol_bcache_get_bcache (objfile
->psymbol_cache
),
74 "partial symbol cache");
75 print_bcache_statistics (objfile
->per_bfd
->macro_cache
,
76 "preprocessor macro cache");
77 print_bcache_statistics (objfile
->per_bfd
->filename_cache
,
83 print_objfile_statistics (void)
85 struct program_space
*pspace
;
86 struct objfile
*objfile
;
87 struct compunit_symtab
*cu
;
89 int i
, linetables
, blockvectors
;
92 ALL_PSPACE_OBJFILES (pspace
, objfile
)
95 printf_filtered (_("Statistics for '%s':\n"), objfile_name (objfile
));
96 if (OBJSTAT (objfile
, n_stabs
) > 0)
97 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
98 OBJSTAT (objfile
, n_stabs
));
99 if (objfile
->per_bfd
->n_minsyms
> 0)
100 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
101 objfile
->per_bfd
->n_minsyms
);
102 if (OBJSTAT (objfile
, n_psyms
) > 0)
103 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
104 OBJSTAT (objfile
, n_psyms
));
105 if (OBJSTAT (objfile
, n_syms
) > 0)
106 printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
107 OBJSTAT (objfile
, n_syms
));
108 if (OBJSTAT (objfile
, n_types
) > 0)
109 printf_filtered (_(" Number of \"types\" defined: %d\n"),
110 OBJSTAT (objfile
, n_types
));
112 objfile
->sf
->qf
->print_stats (objfile
);
113 i
= linetables
= blockvectors
= 0;
114 ALL_OBJFILE_FILETABS (objfile
, cu
, s
)
117 if (SYMTAB_LINETABLE (s
) != NULL
)
120 ALL_OBJFILE_COMPUNITS (objfile
, cu
)
122 printf_filtered (_(" Number of symbol tables: %d\n"), i
);
123 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
125 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
128 if (OBJSTAT (objfile
, sz_strtab
) > 0)
129 printf_filtered (_(" Space used by string tables: %d\n"),
130 OBJSTAT (objfile
, sz_strtab
));
131 printf_filtered (_(" Total memory used for objfile obstack: %s\n"),
132 pulongest (obstack_memory_used (&objfile
133 ->objfile_obstack
)));
134 printf_filtered (_(" Total memory used for BFD obstack: %s\n"),
135 pulongest (obstack_memory_used (&objfile
->per_bfd
136 ->storage_obstack
)));
137 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
138 bcache_memory_used (psymbol_bcache_get_bcache
139 (objfile
->psymbol_cache
)));
140 printf_filtered (_(" Total memory used for macro cache: %d\n"),
141 bcache_memory_used (objfile
->per_bfd
->macro_cache
));
142 printf_filtered (_(" Total memory used for file name cache: %d\n"),
143 bcache_memory_used (objfile
->per_bfd
->filename_cache
));
148 dump_objfile (struct objfile
*objfile
)
150 struct compunit_symtab
*cust
;
151 struct symtab
*symtab
;
153 printf_filtered ("\nObject file %s: ", objfile_name (objfile
));
154 printf_filtered ("Objfile at ");
155 gdb_print_host_address (objfile
, gdb_stdout
);
156 printf_filtered (", bfd at ");
157 gdb_print_host_address (objfile
->obfd
, gdb_stdout
);
158 printf_filtered (", %d minsyms\n\n",
159 objfile
->per_bfd
->minimal_symbol_count
);
162 objfile
->sf
->qf
->dump (objfile
);
164 if (objfile
->compunit_symtabs
!= NULL
)
166 printf_filtered ("Symtabs:\n");
167 ALL_OBJFILE_FILETABS (objfile
, cust
, symtab
)
169 printf_filtered ("%s at ", symtab_to_filename_for_display (symtab
));
170 gdb_print_host_address (symtab
, gdb_stdout
);
171 printf_filtered (", ");
172 if (SYMTAB_OBJFILE (symtab
) != objfile
)
174 printf_filtered ("NOT ON CHAIN! ");
178 printf_filtered ("\n\n");
182 /* Print minimal symbols from this objfile. */
185 dump_msymbols (struct objfile
*objfile
, struct ui_file
*outfile
)
187 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
188 struct minimal_symbol
*msymbol
;
192 fprintf_filtered (outfile
, "\nObject file %s:\n\n", objfile_name (objfile
));
193 if (objfile
->per_bfd
->minimal_symbol_count
== 0)
195 fprintf_filtered (outfile
, "No minimal symbols found.\n");
199 ALL_OBJFILE_MSYMBOLS (objfile
, msymbol
)
201 struct obj_section
*section
= MSYMBOL_OBJ_SECTION (objfile
, msymbol
);
203 switch (MSYMBOL_TYPE (msymbol
))
211 case mst_text_gnu_ifunc
:
212 case mst_data_gnu_ifunc
:
215 case mst_solib_trampoline
:
240 fprintf_filtered (outfile
, "[%2d] %c ", index
, ms_type
);
241 fputs_filtered (paddress (gdbarch
, MSYMBOL_VALUE_ADDRESS (objfile
,
244 fprintf_filtered (outfile
, " %s", MSYMBOL_LINKAGE_NAME (msymbol
));
247 if (section
->the_bfd_section
!= NULL
)
248 fprintf_filtered (outfile
, " section %s",
249 bfd_section_name (objfile
->obfd
,
250 section
->the_bfd_section
));
252 fprintf_filtered (outfile
, " spurious section %ld",
253 (long) (section
- objfile
->sections
));
255 if (MSYMBOL_DEMANGLED_NAME (msymbol
) != NULL
)
257 fprintf_filtered (outfile
, " %s", MSYMBOL_DEMANGLED_NAME (msymbol
));
259 if (msymbol
->filename
)
260 fprintf_filtered (outfile
, " %s", msymbol
->filename
);
261 fputs_filtered ("\n", outfile
);
264 if (objfile
->per_bfd
->minimal_symbol_count
!= index
)
266 warning (_("internal error: minimal symbol count %d != %d"),
267 objfile
->per_bfd
->minimal_symbol_count
, index
);
269 fprintf_filtered (outfile
, "\n");
273 dump_symtab_1 (struct symtab
*symtab
, struct ui_file
*outfile
)
275 struct objfile
*objfile
= SYMTAB_OBJFILE (symtab
);
276 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
278 struct dict_iterator iter
;
281 const struct blockvector
*bv
;
286 fprintf_filtered (outfile
, "\nSymtab for file %s\n",
287 symtab_to_filename_for_display (symtab
));
288 if (SYMTAB_DIRNAME (symtab
) != NULL
)
289 fprintf_filtered (outfile
, "Compilation directory is %s\n",
290 SYMTAB_DIRNAME (symtab
));
291 fprintf_filtered (outfile
, "Read from object file %s (",
292 objfile_name (objfile
));
293 gdb_print_host_address (objfile
, outfile
);
294 fprintf_filtered (outfile
, ")\n");
295 fprintf_filtered (outfile
, "Language: %s\n",
296 language_str (symtab
->language
));
298 /* First print the line table. */
299 l
= SYMTAB_LINETABLE (symtab
);
302 fprintf_filtered (outfile
, "\nLine table:\n\n");
304 for (i
= 0; i
< len
; i
++)
306 fprintf_filtered (outfile
, " line %d at ", l
->item
[i
].line
);
307 fputs_filtered (paddress (gdbarch
, l
->item
[i
].pc
), outfile
);
308 fprintf_filtered (outfile
, "\n");
311 /* Now print the block info, but only for compunit symtabs since we will
312 print lots of duplicate info otherwise. */
313 if (symtab
== COMPUNIT_FILETABS (SYMTAB_COMPUNIT (symtab
)))
315 fprintf_filtered (outfile
, "\nBlockvector:\n\n");
316 bv
= SYMTAB_BLOCKVECTOR (symtab
);
317 len
= BLOCKVECTOR_NBLOCKS (bv
);
318 for (i
= 0; i
< len
; i
++)
320 b
= BLOCKVECTOR_BLOCK (bv
, i
);
321 depth
= block_depth (b
) * 2;
322 print_spaces (depth
, outfile
);
323 fprintf_filtered (outfile
, "block #%03d, object at ", i
);
324 gdb_print_host_address (b
, outfile
);
325 if (BLOCK_SUPERBLOCK (b
))
327 fprintf_filtered (outfile
, " under ");
328 gdb_print_host_address (BLOCK_SUPERBLOCK (b
), outfile
);
330 /* drow/2002-07-10: We could save the total symbols count
331 even if we're using a hashtable, but nothing else but this message
333 fprintf_filtered (outfile
, ", %d syms/buckets in ",
334 dict_size (BLOCK_DICT (b
)));
335 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), outfile
);
336 fprintf_filtered (outfile
, "..");
337 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), outfile
);
338 if (BLOCK_FUNCTION (b
))
340 fprintf_filtered (outfile
, ", function %s",
341 SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b
)));
342 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b
)) != NULL
)
344 fprintf_filtered (outfile
, ", %s",
345 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b
)));
348 fprintf_filtered (outfile
, "\n");
349 /* Now print each symbol in this block (in no particular order, if
350 we're using a hashtable). Note that we only want this
351 block, not any blocks from included symtabs. */
352 ALL_DICT_SYMBOLS (BLOCK_DICT (b
), iter
, sym
)
356 print_symbol (gdbarch
, sym
, depth
+ 1, outfile
);
358 CATCH (ex
, RETURN_MASK_ERROR
)
360 exception_fprintf (gdb_stderr
, ex
,
361 "Error printing symbol:\n");
366 fprintf_filtered (outfile
, "\n");
370 const char *compunit_filename
371 = symtab_to_filename_for_display (COMPUNIT_FILETABS (SYMTAB_COMPUNIT (symtab
)));
373 fprintf_filtered (outfile
,
374 "\nBlockvector same as owning compunit: %s\n\n",
380 dump_symtab (struct symtab
*symtab
, struct ui_file
*outfile
)
382 /* Set the current language to the language of the symtab we're dumping
383 because certain routines used during dump_symtab() use the current
384 language to print an image of the symbol. We'll restore it later.
385 But use only real languages, not placeholders. */
386 if (symtab
->language
!= language_unknown
387 && symtab
->language
!= language_auto
)
389 enum language saved_lang
;
391 saved_lang
= set_language (symtab
->language
);
393 dump_symtab_1 (symtab
, outfile
);
395 set_language (saved_lang
);
398 dump_symtab_1 (symtab
, outfile
);
402 maintenance_print_symbols (const char *args
, int from_tty
)
404 struct ui_file
*outfile
= gdb_stdout
;
405 char *address_arg
= NULL
, *source_arg
= NULL
, *objfile_arg
= NULL
;
410 gdb_argv
argv (args
);
412 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
414 if (strcmp (argv
[i
], "-pc") == 0)
416 if (argv
[i
+ 1] == NULL
)
417 error (_("Missing pc value"));
418 address_arg
= argv
[++i
];
420 else if (strcmp (argv
[i
], "-source") == 0)
422 if (argv
[i
+ 1] == NULL
)
423 error (_("Missing source file"));
424 source_arg
= argv
[++i
];
426 else if (strcmp (argv
[i
], "-objfile") == 0)
428 if (argv
[i
+ 1] == NULL
)
429 error (_("Missing objfile name"));
430 objfile_arg
= argv
[++i
];
432 else if (strcmp (argv
[i
], "--") == 0)
434 /* End of options. */
438 else if (argv
[i
][0] == '-')
440 /* Future proofing: Don't allow OUTFILE to begin with "-". */
441 error (_("Unknown option: %s"), argv
[i
]);
448 if (address_arg
!= NULL
&& source_arg
!= NULL
)
449 error (_("Must specify at most one of -pc and -source"));
451 stdio_file arg_outfile
;
453 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
455 if (argv
[outfile_idx
+ 1] != NULL
)
456 error (_("Junk at end of command"));
457 gdb::unique_xmalloc_ptr
<char> outfile_name
458 (tilde_expand (argv
[outfile_idx
]));
459 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
460 perror_with_name (outfile_name
.get ());
461 outfile
= &arg_outfile
;
464 if (address_arg
!= NULL
)
466 CORE_ADDR pc
= parse_and_eval_address (address_arg
);
467 struct symtab
*s
= find_pc_line_symtab (pc
);
470 error (_("No symtab for address: %s"), address_arg
);
471 dump_symtab (s
, outfile
);
475 struct objfile
*objfile
;
476 struct compunit_symtab
*cu
;
480 ALL_OBJFILES (objfile
)
482 int print_for_objfile
= 1;
484 if (objfile_arg
!= NULL
)
486 = compare_filenames_for_search (objfile_name (objfile
),
488 if (!print_for_objfile
)
491 ALL_OBJFILE_FILETABS (objfile
, cu
, s
)
493 int print_for_source
= 0;
496 if (source_arg
!= NULL
)
499 = compare_filenames_for_search
500 (symtab_to_filename_for_display (s
), source_arg
);
503 if (source_arg
== NULL
505 dump_symtab (s
, outfile
);
509 if (source_arg
!= NULL
&& !found
)
510 error (_("No symtab for source file: %s"), source_arg
);
514 /* Print symbol SYMBOL on OUTFILE. DEPTH says how far to indent. */
517 print_symbol (struct gdbarch
*gdbarch
, struct symbol
*symbol
,
518 int depth
, ui_file
*outfile
)
520 struct obj_section
*section
;
522 if (SYMBOL_OBJFILE_OWNED (symbol
))
523 section
= SYMBOL_OBJ_SECTION (symbol_objfile (symbol
), symbol
);
527 print_spaces (depth
, outfile
);
528 if (SYMBOL_DOMAIN (symbol
) == LABEL_DOMAIN
)
530 fprintf_filtered (outfile
, "label %s at ", SYMBOL_PRINT_NAME (symbol
));
531 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
534 fprintf_filtered (outfile
, " section %s\n",
535 bfd_section_name (section
->the_bfd_section
->owner
,
536 section
->the_bfd_section
));
538 fprintf_filtered (outfile
, "\n");
542 if (SYMBOL_DOMAIN (symbol
) == STRUCT_DOMAIN
)
544 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol
)))
546 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
,
547 &type_print_raw_options
);
551 fprintf_filtered (outfile
, "%s %s = ",
552 (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_ENUM
554 : (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_STRUCT
555 ? "struct" : "union")),
556 SYMBOL_LINKAGE_NAME (symbol
));
557 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
,
558 &type_print_raw_options
);
560 fprintf_filtered (outfile
, ";\n");
564 if (SYMBOL_CLASS (symbol
) == LOC_TYPEDEF
)
565 fprintf_filtered (outfile
, "typedef ");
566 if (SYMBOL_TYPE (symbol
))
568 /* Print details of types, except for enums where it's clutter. */
569 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), SYMBOL_PRINT_NAME (symbol
),
571 TYPE_CODE (SYMBOL_TYPE (symbol
)) != TYPE_CODE_ENUM
,
573 &type_print_raw_options
);
574 fprintf_filtered (outfile
, "; ");
577 fprintf_filtered (outfile
, "%s ", SYMBOL_PRINT_NAME (symbol
));
579 switch (SYMBOL_CLASS (symbol
))
582 fprintf_filtered (outfile
, "const %s (%s)",
583 plongest (SYMBOL_VALUE (symbol
)),
584 hex_string (SYMBOL_VALUE (symbol
)));
587 case LOC_CONST_BYTES
:
590 struct type
*type
= check_typedef (SYMBOL_TYPE (symbol
));
592 fprintf_filtered (outfile
, "const %u hex bytes:",
594 for (i
= 0; i
< TYPE_LENGTH (type
); i
++)
595 fprintf_filtered (outfile
, " %02x",
596 (unsigned) SYMBOL_VALUE_BYTES (symbol
)[i
]);
601 fprintf_filtered (outfile
, "static at ");
602 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
605 fprintf_filtered (outfile
, " section %s",
606 bfd_section_name (section
->the_bfd_section
->owner
,
607 section
->the_bfd_section
));
611 if (SYMBOL_IS_ARGUMENT (symbol
))
612 fprintf_filtered (outfile
, "parameter register %s",
613 plongest (SYMBOL_VALUE (symbol
)));
615 fprintf_filtered (outfile
, "register %s",
616 plongest (SYMBOL_VALUE (symbol
)));
620 fprintf_filtered (outfile
, "arg at offset %s",
621 hex_string (SYMBOL_VALUE (symbol
)));
625 fprintf_filtered (outfile
, "reference arg at %s",
626 hex_string (SYMBOL_VALUE (symbol
)));
629 case LOC_REGPARM_ADDR
:
630 fprintf_filtered (outfile
, "address parameter register %s",
631 plongest (SYMBOL_VALUE (symbol
)));
635 fprintf_filtered (outfile
, "local at offset %s",
636 hex_string (SYMBOL_VALUE (symbol
)));
643 fprintf_filtered (outfile
, "label at ");
644 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
647 fprintf_filtered (outfile
, " section %s",
648 bfd_section_name (section
->the_bfd_section
->owner
,
649 section
->the_bfd_section
));
653 fprintf_filtered (outfile
, "block object ");
654 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol
), outfile
);
655 fprintf_filtered (outfile
, ", ");
656 fputs_filtered (paddress (gdbarch
,
657 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
))),
659 fprintf_filtered (outfile
, "..");
660 fputs_filtered (paddress (gdbarch
,
661 BLOCK_END (SYMBOL_BLOCK_VALUE (symbol
))),
664 fprintf_filtered (outfile
, " section %s",
665 bfd_section_name (section
->the_bfd_section
->owner
,
666 section
->the_bfd_section
));
670 fprintf_filtered (outfile
, "computed at runtime");
674 fprintf_filtered (outfile
, "unresolved");
677 case LOC_OPTIMIZED_OUT
:
678 fprintf_filtered (outfile
, "optimized out");
682 fprintf_filtered (outfile
, "botched symbol class %x",
683 SYMBOL_CLASS (symbol
));
687 fprintf_filtered (outfile
, "\n");
691 maintenance_print_msymbols (const char *args
, int from_tty
)
693 struct ui_file
*outfile
= gdb_stdout
;
694 char *objfile_arg
= NULL
;
695 struct objfile
*objfile
;
700 gdb_argv
argv (args
);
702 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
704 if (strcmp (argv
[i
], "-objfile") == 0)
706 if (argv
[i
+ 1] == NULL
)
707 error (_("Missing objfile name"));
708 objfile_arg
= argv
[++i
];
710 else if (strcmp (argv
[i
], "--") == 0)
712 /* End of options. */
716 else if (argv
[i
][0] == '-')
718 /* Future proofing: Don't allow OUTFILE to begin with "-". */
719 error (_("Unknown option: %s"), argv
[i
]);
726 stdio_file arg_outfile
;
728 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
730 if (argv
[outfile_idx
+ 1] != NULL
)
731 error (_("Junk at end of command"));
732 gdb::unique_xmalloc_ptr
<char> outfile_name
733 (tilde_expand (argv
[outfile_idx
]));
734 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
735 perror_with_name (outfile_name
.get ());
736 outfile
= &arg_outfile
;
739 ALL_OBJFILES (objfile
)
742 if (objfile_arg
== NULL
743 || compare_filenames_for_search (objfile_name (objfile
), objfile_arg
))
744 dump_msymbols (objfile
, outfile
);
749 maintenance_print_objfiles (const char *regexp
, int from_tty
)
751 struct program_space
*pspace
;
752 struct objfile
*objfile
;
760 ALL_PSPACE_OBJFILES (pspace
, objfile
)
764 || re_exec (objfile_name (objfile
)))
765 dump_objfile (objfile
);
769 /* List all the symbol tables whose names match REGEXP (optional). */
772 maintenance_info_symtabs (const char *regexp
, int from_tty
)
774 struct program_space
*pspace
;
775 struct objfile
*objfile
;
783 ALL_PSPACE_OBJFILES (pspace
, objfile
)
785 struct compunit_symtab
*cust
;
786 struct symtab
*symtab
;
788 /* We don't want to print anything for this objfile until we
789 actually find a symtab whose name matches. */
790 int printed_objfile_start
= 0;
792 ALL_OBJFILE_COMPUNITS (objfile
, cust
)
794 int printed_compunit_symtab_start
= 0;
796 ALL_COMPUNIT_FILETABS (cust
, symtab
)
801 || re_exec (symtab_to_filename_for_display (symtab
)))
803 if (! printed_objfile_start
)
805 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
807 printf_filtered ("((struct objfile *) %s)\n",
808 host_address_to_string (objfile
));
809 printed_objfile_start
= 1;
811 if (! printed_compunit_symtab_start
)
813 printf_filtered (" { ((struct compunit_symtab *) %s)\n",
814 host_address_to_string (cust
));
815 printf_filtered (" debugformat %s\n",
816 COMPUNIT_DEBUGFORMAT (cust
));
817 printf_filtered (" producer %s\n",
818 COMPUNIT_PRODUCER (cust
) != NULL
819 ? COMPUNIT_PRODUCER (cust
)
821 printf_filtered (" dirname %s\n",
822 COMPUNIT_DIRNAME (cust
) != NULL
823 ? COMPUNIT_DIRNAME (cust
)
825 printf_filtered (" blockvector"
826 " ((struct blockvector *) %s)\n",
827 host_address_to_string
828 (COMPUNIT_BLOCKVECTOR (cust
)));
829 printed_compunit_symtab_start
= 1;
832 printf_filtered ("\t{ symtab %s ",
833 symtab_to_filename_for_display (symtab
));
835 printf_filtered ("((struct symtab *) %s)\n",
836 host_address_to_string (symtab
));
837 printf_filtered ("\t fullname %s\n",
838 symtab
->fullname
!= NULL
841 printf_filtered ("\t "
842 "linetable ((struct linetable *) %s)\n",
843 host_address_to_string (symtab
->linetable
));
844 printf_filtered ("\t}\n");
848 if (printed_compunit_symtab_start
)
849 printf_filtered (" }\n");
852 if (printed_objfile_start
)
853 printf_filtered ("}\n");
857 /* Check consistency of symtabs.
858 An example of what this checks for is NULL blockvectors.
859 They can happen if there's a bug during debug info reading.
860 GDB assumes they are always non-NULL.
862 Note: This does not check for psymtab vs symtab consistency.
863 Use "maint check-psymtabs" for that. */
866 maintenance_check_symtabs (const char *ignore
, int from_tty
)
868 struct program_space
*pspace
;
869 struct objfile
*objfile
;
872 ALL_PSPACE_OBJFILES (pspace
, objfile
)
874 struct compunit_symtab
*cust
;
876 /* We don't want to print anything for this objfile until we
877 actually find something worth printing. */
878 int printed_objfile_start
= 0;
880 ALL_OBJFILE_COMPUNITS (objfile
, cust
)
882 int found_something
= 0;
883 struct symtab
*symtab
= compunit_primary_filetab (cust
);
887 if (COMPUNIT_BLOCKVECTOR (cust
) == NULL
)
889 /* Add more checks here. */
893 if (! printed_objfile_start
)
895 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
897 printf_filtered ("((struct objfile *) %s)\n",
898 host_address_to_string (objfile
));
899 printed_objfile_start
= 1;
901 printf_filtered (" { symtab %s\n",
902 symtab_to_filename_for_display (symtab
));
903 if (COMPUNIT_BLOCKVECTOR (cust
) == NULL
)
904 printf_filtered (" NULL blockvector\n");
905 printf_filtered (" }\n");
909 if (printed_objfile_start
)
910 printf_filtered ("}\n");
914 /* Expand all symbol tables whose name matches an optional regexp. */
917 maintenance_expand_symtabs (const char *args
, int from_tty
)
919 struct program_space
*pspace
;
920 struct objfile
*objfile
;
923 /* We use buildargv here so that we handle spaces in the regexp
924 in a way that allows adding more arguments later. */
925 gdb_argv
argv (args
);
933 error (_("Extra arguments after regexp."));
941 ALL_PSPACE_OBJFILES (pspace
, objfile
)
945 objfile
->sf
->qf
->expand_symtabs_matching
947 [&] (const char *filename
, bool basenames
)
949 /* KISS: Only apply the regexp to the complete file name. */
951 && (regexp
== NULL
|| re_exec (filename
)));
953 lookup_name_info::match_any (),
954 [] (const char *symname
)
956 /* Since we're not searching on symbols, just return true. */
966 /* Return the nexting depth of a block within other blocks in its symtab. */
969 block_depth (struct block
*block
)
973 while ((block
= BLOCK_SUPERBLOCK (block
)) != NULL
)
981 /* Used by MAINTENANCE_INFO_LINE_TABLES to print the information about a
982 single line table. */
985 maintenance_print_one_line_table (struct symtab
*symtab
, void *data
)
987 struct linetable
*linetable
;
988 struct objfile
*objfile
;
990 objfile
= symtab
->compunit_symtab
->objfile
;
991 printf_filtered (_("objfile: %s ((struct objfile *) %s)\n"),
992 objfile_name (objfile
),
993 host_address_to_string (objfile
));
994 printf_filtered (_("compunit_symtab: ((struct compunit_symtab *) %s)\n"),
995 host_address_to_string (symtab
->compunit_symtab
));
996 printf_filtered (_("symtab: %s ((struct symtab *) %s)\n"),
997 symtab_to_fullname (symtab
),
998 host_address_to_string (symtab
));
999 linetable
= SYMTAB_LINETABLE (symtab
);
1000 printf_filtered (_("linetable: ((struct linetable *) %s):\n"),
1001 host_address_to_string (linetable
));
1003 if (linetable
== NULL
)
1004 printf_filtered (_("No line table.\n"));
1005 else if (linetable
->nitems
<= 0)
1006 printf_filtered (_("Line table has no lines.\n"));
1011 /* Leave space for 6 digits of index and line number. After that the
1012 tables will just not format as well. */
1013 printf_filtered (_("%-6s %6s %s\n"),
1014 _("INDEX"), _("LINE"), _("ADDRESS"));
1016 for (i
= 0; i
< linetable
->nitems
; ++i
)
1018 struct linetable_entry
*item
;
1020 item
= &linetable
->item
[i
];
1021 printf_filtered (_("%-6d %6d %s\n"), i
, item
->line
,
1022 core_addr_to_string (item
->pc
));
1029 /* Implement the 'maint info line-table' command. */
1032 maintenance_info_line_tables (const char *regexp
, int from_tty
)
1034 struct program_space
*pspace
;
1035 struct objfile
*objfile
;
1042 ALL_PSPACES (pspace
)
1043 ALL_PSPACE_OBJFILES (pspace
, objfile
)
1045 struct compunit_symtab
*cust
;
1046 struct symtab
*symtab
;
1048 ALL_OBJFILE_COMPUNITS (objfile
, cust
)
1050 ALL_COMPUNIT_FILETABS (cust
, symtab
)
1055 || re_exec (symtab_to_filename_for_display (symtab
)))
1056 maintenance_print_one_line_table (symtab
, NULL
);
1064 /* Do early runtime initializations. */
1067 _initialize_symmisc (void)
1073 add_cmd ("symbols", class_maintenance
, maintenance_print_symbols
, _("\
1074 Print dump of current symbol definitions.\n\
1075 Usage: mt print symbols [-pc address] [--] [outfile]\n\
1076 mt print symbols [-objfile objfile] [-source source] [--] [outfile]\n\
1077 Entries in the full symbol table are dumped to file OUTFILE,\n\
1078 or the terminal if OUTFILE is unspecified.\n\
1079 If ADDRESS is provided, dump only the file for that address.\n\
1080 If SOURCE is provided, dump only that file's symbols.\n\
1081 If OBJFILE is provided, dump only that file's minimal symbols."),
1082 &maintenanceprintlist
);
1084 add_cmd ("msymbols", class_maintenance
, maintenance_print_msymbols
, _("\
1085 Print dump of current minimal symbol definitions.\n\
1086 Usage: mt print msymbols [-objfile objfile] [--] [outfile]\n\
1087 Entries in the minimal symbol table are dumped to file OUTFILE,\n\
1088 or the terminal if OUTFILE is unspecified.\n\
1089 If OBJFILE is provided, dump only that file's minimal symbols."),
1090 &maintenanceprintlist
);
1092 add_cmd ("objfiles", class_maintenance
, maintenance_print_objfiles
,
1093 _("Print dump of current object file definitions.\n\
1094 With an argument REGEXP, list the object files with matching names."),
1095 &maintenanceprintlist
);
1097 add_cmd ("symtabs", class_maintenance
, maintenance_info_symtabs
, _("\
1098 List the full symbol tables for all object files.\n\
1099 This does not include information about individual symbols, blocks, or\n\
1100 linetables --- just the symbol table structures themselves.\n\
1101 With an argument REGEXP, list the symbol tables with matching names."),
1102 &maintenanceinfolist
);
1104 add_cmd ("line-table", class_maintenance
, maintenance_info_line_tables
, _("\
1105 List the contents of all line tables, from all symbol tables.\n\
1106 With an argument REGEXP, list just the line tables for the symbol\n\
1107 tables with matching names."),
1108 &maintenanceinfolist
);
1110 add_cmd ("check-symtabs", class_maintenance
, maintenance_check_symtabs
,
1112 Check consistency of currently expanded symtabs."),
1115 add_cmd ("expand-symtabs", class_maintenance
, maintenance_expand_symtabs
,
1116 _("Expand symbol tables.\n\
1117 With an argument REGEXP, only expand the symbol tables with matching names."),