1 /* Do various things to symbol tables (other than lookup), for GDB.
3 Copyright (C) 1986-2016 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"
44 #define DEV_TTY "/dev/tty"
47 /* Unfortunately for debugging, stderr is usually a macro. This is painful
48 when calling functions that take FILE *'s from the debugger.
49 So we make a variable which has the same value and which is accessible when
50 debugging GDB with itself. Because stdin et al need not be constants,
51 we initialize them in the _initialize_symmisc function at the bottom
57 /* Prototypes for local functions */
59 static int block_depth (struct block
*);
61 void _initialize_symmisc (void);
63 struct print_symbol_args
65 struct gdbarch
*gdbarch
;
66 struct symbol
*symbol
;
68 struct ui_file
*outfile
;
71 static int print_symbol (void *);
75 print_symbol_bcache_statistics (void)
77 struct program_space
*pspace
;
78 struct objfile
*objfile
;
81 ALL_PSPACE_OBJFILES (pspace
, objfile
)
84 printf_filtered (_("Byte cache statistics for '%s':\n"),
85 objfile_name (objfile
));
86 print_bcache_statistics (psymbol_bcache_get_bcache (objfile
->psymbol_cache
),
87 "partial symbol cache");
88 print_bcache_statistics (objfile
->per_bfd
->macro_cache
,
89 "preprocessor macro cache");
90 print_bcache_statistics (objfile
->per_bfd
->filename_cache
,
96 print_objfile_statistics (void)
98 struct program_space
*pspace
;
99 struct objfile
*objfile
;
100 struct compunit_symtab
*cu
;
102 int i
, linetables
, blockvectors
;
105 ALL_PSPACE_OBJFILES (pspace
, objfile
)
108 printf_filtered (_("Statistics for '%s':\n"), objfile_name (objfile
));
109 if (OBJSTAT (objfile
, n_stabs
) > 0)
110 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
111 OBJSTAT (objfile
, n_stabs
));
112 if (objfile
->per_bfd
->n_minsyms
> 0)
113 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
114 objfile
->per_bfd
->n_minsyms
);
115 if (OBJSTAT (objfile
, n_psyms
) > 0)
116 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
117 OBJSTAT (objfile
, n_psyms
));
118 if (OBJSTAT (objfile
, n_syms
) > 0)
119 printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
120 OBJSTAT (objfile
, n_syms
));
121 if (OBJSTAT (objfile
, n_types
) > 0)
122 printf_filtered (_(" Number of \"types\" defined: %d\n"),
123 OBJSTAT (objfile
, n_types
));
125 objfile
->sf
->qf
->print_stats (objfile
);
126 i
= linetables
= blockvectors
= 0;
127 ALL_OBJFILE_FILETABS (objfile
, cu
, s
)
130 if (SYMTAB_LINETABLE (s
) != NULL
)
133 ALL_OBJFILE_COMPUNITS (objfile
, cu
)
135 printf_filtered (_(" Number of symbol tables: %d\n"), i
);
136 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
138 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
141 if (OBJSTAT (objfile
, sz_strtab
) > 0)
142 printf_filtered (_(" Space used by a.out string tables: %d\n"),
143 OBJSTAT (objfile
, sz_strtab
));
144 printf_filtered (_(" Total memory used for objfile obstack: %s\n"),
145 pulongest (obstack_memory_used (&objfile
146 ->objfile_obstack
)));
147 printf_filtered (_(" Total memory used for BFD obstack: %s\n"),
148 pulongest (obstack_memory_used (&objfile
->per_bfd
149 ->storage_obstack
)));
150 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
151 bcache_memory_used (psymbol_bcache_get_bcache
152 (objfile
->psymbol_cache
)));
153 printf_filtered (_(" Total memory used for macro cache: %d\n"),
154 bcache_memory_used (objfile
->per_bfd
->macro_cache
));
155 printf_filtered (_(" Total memory used for file name cache: %d\n"),
156 bcache_memory_used (objfile
->per_bfd
->filename_cache
));
161 dump_objfile (struct objfile
*objfile
)
163 struct compunit_symtab
*cust
;
164 struct symtab
*symtab
;
166 printf_filtered ("\nObject file %s: ", objfile_name (objfile
));
167 printf_filtered ("Objfile at ");
168 gdb_print_host_address (objfile
, gdb_stdout
);
169 printf_filtered (", bfd at ");
170 gdb_print_host_address (objfile
->obfd
, gdb_stdout
);
171 printf_filtered (", %d minsyms\n\n",
172 objfile
->per_bfd
->minimal_symbol_count
);
175 objfile
->sf
->qf
->dump (objfile
);
177 if (objfile
->compunit_symtabs
!= NULL
)
179 printf_filtered ("Symtabs:\n");
180 ALL_OBJFILE_FILETABS (objfile
, cust
, symtab
)
182 printf_filtered ("%s at ", symtab_to_filename_for_display (symtab
));
183 gdb_print_host_address (symtab
, gdb_stdout
);
184 printf_filtered (", ");
185 if (SYMTAB_OBJFILE (symtab
) != objfile
)
187 printf_filtered ("NOT ON CHAIN! ");
191 printf_filtered ("\n\n");
195 /* Print minimal symbols from this objfile. */
198 dump_msymbols (struct objfile
*objfile
, struct ui_file
*outfile
)
200 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
201 struct minimal_symbol
*msymbol
;
205 fprintf_filtered (outfile
, "\nObject file %s:\n\n", objfile_name (objfile
));
206 if (objfile
->per_bfd
->minimal_symbol_count
== 0)
208 fprintf_filtered (outfile
, "No minimal symbols found.\n");
212 ALL_OBJFILE_MSYMBOLS (objfile
, msymbol
)
214 struct obj_section
*section
= MSYMBOL_OBJ_SECTION (objfile
, msymbol
);
216 switch (MSYMBOL_TYPE (msymbol
))
224 case mst_text_gnu_ifunc
:
227 case mst_solib_trampoline
:
252 fprintf_filtered (outfile
, "[%2d] %c ", index
, ms_type
);
253 fputs_filtered (paddress (gdbarch
, MSYMBOL_VALUE_ADDRESS (objfile
,
256 fprintf_filtered (outfile
, " %s", MSYMBOL_LINKAGE_NAME (msymbol
));
259 if (section
->the_bfd_section
!= NULL
)
260 fprintf_filtered (outfile
, " section %s",
261 bfd_section_name (objfile
->obfd
,
262 section
->the_bfd_section
));
264 fprintf_filtered (outfile
, " spurious section %ld",
265 (long) (section
- objfile
->sections
));
267 if (MSYMBOL_DEMANGLED_NAME (msymbol
) != NULL
)
269 fprintf_filtered (outfile
, " %s", MSYMBOL_DEMANGLED_NAME (msymbol
));
271 if (msymbol
->filename
)
272 fprintf_filtered (outfile
, " %s", msymbol
->filename
);
273 fputs_filtered ("\n", outfile
);
276 if (objfile
->per_bfd
->minimal_symbol_count
!= index
)
278 warning (_("internal error: minimal symbol count %d != %d"),
279 objfile
->per_bfd
->minimal_symbol_count
, index
);
281 fprintf_filtered (outfile
, "\n");
285 dump_symtab_1 (struct objfile
*objfile
, struct symtab
*symtab
,
286 struct ui_file
*outfile
)
288 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
290 struct dict_iterator iter
;
293 const struct blockvector
*bv
;
298 fprintf_filtered (outfile
, "\nSymtab for file %s\n",
299 symtab_to_filename_for_display (symtab
));
300 if (SYMTAB_DIRNAME (symtab
) != NULL
)
301 fprintf_filtered (outfile
, "Compilation directory is %s\n",
302 SYMTAB_DIRNAME (symtab
));
303 fprintf_filtered (outfile
, "Read from object file %s (",
304 objfile_name (objfile
));
305 gdb_print_host_address (objfile
, outfile
);
306 fprintf_filtered (outfile
, ")\n");
307 fprintf_filtered (outfile
, "Language: %s\n",
308 language_str (symtab
->language
));
310 /* First print the line table. */
311 l
= SYMTAB_LINETABLE (symtab
);
314 fprintf_filtered (outfile
, "\nLine table:\n\n");
316 for (i
= 0; i
< len
; i
++)
318 fprintf_filtered (outfile
, " line %d at ", l
->item
[i
].line
);
319 fputs_filtered (paddress (gdbarch
, l
->item
[i
].pc
), outfile
);
320 fprintf_filtered (outfile
, "\n");
323 /* Now print the block info, but only for compunit symtabs since we will
324 print lots of duplicate info otherwise. */
325 if (symtab
== COMPUNIT_FILETABS (SYMTAB_COMPUNIT (symtab
)))
327 fprintf_filtered (outfile
, "\nBlockvector:\n\n");
328 bv
= SYMTAB_BLOCKVECTOR (symtab
);
329 len
= BLOCKVECTOR_NBLOCKS (bv
);
330 for (i
= 0; i
< len
; i
++)
332 b
= BLOCKVECTOR_BLOCK (bv
, i
);
333 depth
= block_depth (b
) * 2;
334 print_spaces (depth
, outfile
);
335 fprintf_filtered (outfile
, "block #%03d, object at ", i
);
336 gdb_print_host_address (b
, outfile
);
337 if (BLOCK_SUPERBLOCK (b
))
339 fprintf_filtered (outfile
, " under ");
340 gdb_print_host_address (BLOCK_SUPERBLOCK (b
), outfile
);
342 /* drow/2002-07-10: We could save the total symbols count
343 even if we're using a hashtable, but nothing else but this message
345 fprintf_filtered (outfile
, ", %d syms/buckets in ",
346 dict_size (BLOCK_DICT (b
)));
347 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), outfile
);
348 fprintf_filtered (outfile
, "..");
349 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), outfile
);
350 if (BLOCK_FUNCTION (b
))
352 fprintf_filtered (outfile
, ", function %s",
353 SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b
)));
354 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b
)) != NULL
)
356 fprintf_filtered (outfile
, ", %s",
357 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b
)));
360 fprintf_filtered (outfile
, "\n");
361 /* Now print each symbol in this block (in no particular order, if
362 we're using a hashtable). Note that we only want this
363 block, not any blocks from included symtabs. */
364 ALL_DICT_SYMBOLS (BLOCK_DICT (b
), iter
, sym
)
366 struct print_symbol_args s
;
372 catch_errors (print_symbol
, &s
, "Error printing symbol:\n",
376 fprintf_filtered (outfile
, "\n");
380 fprintf_filtered (outfile
, "\nBlockvector same as previous symtab\n\n");
385 dump_symtab (struct objfile
*objfile
, struct symtab
*symtab
,
386 struct ui_file
*outfile
)
388 /* Set the current language to the language of the symtab we're dumping
389 because certain routines used during dump_symtab() use the current
390 language to print an image of the symbol. We'll restore it later.
391 But use only real languages, not placeholders. */
392 if (symtab
->language
!= language_unknown
393 && symtab
->language
!= language_auto
)
395 enum language saved_lang
;
397 saved_lang
= set_language (symtab
->language
);
399 dump_symtab_1 (objfile
, symtab
, outfile
);
401 set_language (saved_lang
);
404 dump_symtab_1 (objfile
, symtab
, outfile
);
408 maintenance_print_symbols (char *args
, int from_tty
)
411 struct ui_file
*outfile
;
412 struct cleanup
*cleanups
;
413 char *symname
= NULL
;
414 char *filename
= DEV_TTY
;
415 struct objfile
*objfile
;
416 struct compunit_symtab
*cu
;
423 error (_("Arguments missing: an output file name "
424 "and an optional symbol file name"));
426 argv
= gdb_buildargv (args
);
427 cleanups
= make_cleanup_freeargv (argv
);
432 /* If a second arg is supplied, it is a source file name to match on. */
439 filename
= tilde_expand (filename
);
440 make_cleanup (xfree
, filename
);
442 outfile
= gdb_fopen (filename
, FOPEN_WT
);
444 perror_with_name (filename
);
445 make_cleanup_ui_file_delete (outfile
);
447 ALL_FILETABS (objfile
, cu
, s
)
451 || filename_cmp (symname
, symtab_to_filename_for_display (s
)) == 0)
452 dump_symtab (objfile
, s
, outfile
);
454 do_cleanups (cleanups
);
457 /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
458 far to indent. ARGS is really a struct print_symbol_args *, but is
459 declared as char * to get it past catch_errors. Returns 0 for error,
463 print_symbol (void *args
)
465 struct gdbarch
*gdbarch
= ((struct print_symbol_args
*) args
)->gdbarch
;
466 struct symbol
*symbol
= ((struct print_symbol_args
*) args
)->symbol
;
467 int depth
= ((struct print_symbol_args
*) args
)->depth
;
468 struct ui_file
*outfile
= ((struct print_symbol_args
*) args
)->outfile
;
469 struct obj_section
*section
;
471 if (SYMBOL_OBJFILE_OWNED (symbol
))
472 section
= SYMBOL_OBJ_SECTION (symbol_objfile (symbol
), symbol
);
476 print_spaces (depth
, outfile
);
477 if (SYMBOL_DOMAIN (symbol
) == LABEL_DOMAIN
)
479 fprintf_filtered (outfile
, "label %s at ", SYMBOL_PRINT_NAME (symbol
));
480 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
483 fprintf_filtered (outfile
, " section %s\n",
484 bfd_section_name (section
->the_bfd_section
->owner
,
485 section
->the_bfd_section
));
487 fprintf_filtered (outfile
, "\n");
490 if (SYMBOL_DOMAIN (symbol
) == STRUCT_DOMAIN
)
492 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol
)))
494 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
,
495 &type_print_raw_options
);
499 fprintf_filtered (outfile
, "%s %s = ",
500 (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_ENUM
502 : (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_STRUCT
503 ? "struct" : "union")),
504 SYMBOL_LINKAGE_NAME (symbol
));
505 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
,
506 &type_print_raw_options
);
508 fprintf_filtered (outfile
, ";\n");
512 if (SYMBOL_CLASS (symbol
) == LOC_TYPEDEF
)
513 fprintf_filtered (outfile
, "typedef ");
514 if (SYMBOL_TYPE (symbol
))
516 /* Print details of types, except for enums where it's clutter. */
517 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), SYMBOL_PRINT_NAME (symbol
),
519 TYPE_CODE (SYMBOL_TYPE (symbol
)) != TYPE_CODE_ENUM
,
521 &type_print_raw_options
);
522 fprintf_filtered (outfile
, "; ");
525 fprintf_filtered (outfile
, "%s ", SYMBOL_PRINT_NAME (symbol
));
527 switch (SYMBOL_CLASS (symbol
))
530 fprintf_filtered (outfile
, "const %s (%s)",
531 plongest (SYMBOL_VALUE (symbol
)),
532 hex_string (SYMBOL_VALUE (symbol
)));
535 case LOC_CONST_BYTES
:
538 struct type
*type
= check_typedef (SYMBOL_TYPE (symbol
));
540 fprintf_filtered (outfile
, "const %u hex bytes:",
542 for (i
= 0; i
< TYPE_LENGTH (type
); i
++)
543 fprintf_filtered (outfile
, " %02x",
544 (unsigned) SYMBOL_VALUE_BYTES (symbol
)[i
]);
549 fprintf_filtered (outfile
, "static at ");
550 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
553 fprintf_filtered (outfile
, " section %s",
554 bfd_section_name (section
->the_bfd_section
->owner
,
555 section
->the_bfd_section
));
559 if (SYMBOL_IS_ARGUMENT (symbol
))
560 fprintf_filtered (outfile
, "parameter register %s",
561 plongest (SYMBOL_VALUE (symbol
)));
563 fprintf_filtered (outfile
, "register %s",
564 plongest (SYMBOL_VALUE (symbol
)));
568 fprintf_filtered (outfile
, "arg at offset %s",
569 hex_string (SYMBOL_VALUE (symbol
)));
573 fprintf_filtered (outfile
, "reference arg at %s",
574 hex_string (SYMBOL_VALUE (symbol
)));
577 case LOC_REGPARM_ADDR
:
578 fprintf_filtered (outfile
, "address parameter register %s",
579 plongest (SYMBOL_VALUE (symbol
)));
583 fprintf_filtered (outfile
, "local at offset %s",
584 hex_string (SYMBOL_VALUE (symbol
)));
591 fprintf_filtered (outfile
, "label at ");
592 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
595 fprintf_filtered (outfile
, " section %s",
596 bfd_section_name (section
->the_bfd_section
->owner
,
597 section
->the_bfd_section
));
601 fprintf_filtered (outfile
, "block object ");
602 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol
), outfile
);
603 fprintf_filtered (outfile
, ", ");
604 fputs_filtered (paddress (gdbarch
,
605 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
))),
607 fprintf_filtered (outfile
, "..");
608 fputs_filtered (paddress (gdbarch
,
609 BLOCK_END (SYMBOL_BLOCK_VALUE (symbol
))),
612 fprintf_filtered (outfile
, " section %s",
613 bfd_section_name (section
->the_bfd_section
->owner
,
614 section
->the_bfd_section
));
618 fprintf_filtered (outfile
, "computed at runtime");
622 fprintf_filtered (outfile
, "unresolved");
625 case LOC_OPTIMIZED_OUT
:
626 fprintf_filtered (outfile
, "optimized out");
630 fprintf_filtered (outfile
, "botched symbol class %x",
631 SYMBOL_CLASS (symbol
));
635 fprintf_filtered (outfile
, "\n");
640 maintenance_print_msymbols (char *args
, int from_tty
)
643 struct ui_file
*outfile
;
644 struct cleanup
*cleanups
;
645 char *filename
= DEV_TTY
;
646 char *symname
= NULL
;
647 struct program_space
*pspace
;
648 struct objfile
*objfile
;
650 struct stat sym_st
, obj_st
;
656 error (_("print-msymbols takes an output file "
657 "name and optional symbol file name"));
659 argv
= gdb_buildargv (args
);
660 cleanups
= make_cleanup_freeargv (argv
);
665 /* If a second arg is supplied, it is a source file name to match on. */
668 symname
= gdb_realpath (argv
[1]);
669 make_cleanup (xfree
, symname
);
670 if (symname
&& stat (symname
, &sym_st
))
671 perror_with_name (symname
);
675 filename
= tilde_expand (filename
);
676 make_cleanup (xfree
, filename
);
678 outfile
= gdb_fopen (filename
, FOPEN_WT
);
680 perror_with_name (filename
);
681 make_cleanup_ui_file_delete (outfile
);
684 ALL_PSPACE_OBJFILES (pspace
, objfile
)
687 if (symname
== NULL
|| (!stat (objfile_name (objfile
), &obj_st
)
688 && sym_st
.st_dev
== obj_st
.st_dev
689 && sym_st
.st_ino
== obj_st
.st_ino
))
690 dump_msymbols (objfile
, outfile
);
692 fprintf_filtered (outfile
, "\n\n");
693 do_cleanups (cleanups
);
697 maintenance_print_objfiles (char *regexp
, int from_tty
)
699 struct program_space
*pspace
;
700 struct objfile
*objfile
;
708 ALL_PSPACE_OBJFILES (pspace
, objfile
)
712 || re_exec (objfile_name (objfile
)))
713 dump_objfile (objfile
);
717 /* List all the symbol tables whose names match REGEXP (optional). */
720 maintenance_info_symtabs (char *regexp
, int from_tty
)
722 struct program_space
*pspace
;
723 struct objfile
*objfile
;
731 ALL_PSPACE_OBJFILES (pspace
, objfile
)
733 struct compunit_symtab
*cust
;
734 struct symtab
*symtab
;
736 /* We don't want to print anything for this objfile until we
737 actually find a symtab whose name matches. */
738 int printed_objfile_start
= 0;
740 ALL_OBJFILE_COMPUNITS (objfile
, cust
)
742 int printed_compunit_symtab_start
= 0;
744 ALL_COMPUNIT_FILETABS (cust
, symtab
)
749 || re_exec (symtab_to_filename_for_display (symtab
)))
751 if (! printed_objfile_start
)
753 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
755 printf_filtered ("((struct objfile *) %s)\n",
756 host_address_to_string (objfile
));
757 printed_objfile_start
= 1;
759 if (! printed_compunit_symtab_start
)
761 printf_filtered (" { ((struct compunit_symtab *) %s)\n",
762 host_address_to_string (cust
));
763 printf_filtered (" debugformat %s\n",
764 COMPUNIT_DEBUGFORMAT (cust
));
765 printf_filtered (" producer %s\n",
766 COMPUNIT_PRODUCER (cust
) != NULL
767 ? COMPUNIT_PRODUCER (cust
)
769 printf_filtered (" dirname %s\n",
770 COMPUNIT_DIRNAME (cust
) != NULL
771 ? COMPUNIT_DIRNAME (cust
)
773 printf_filtered (" blockvector"
774 " ((struct blockvector *) %s)\n",
775 host_address_to_string
776 (COMPUNIT_BLOCKVECTOR (cust
)));
777 printed_compunit_symtab_start
= 1;
780 printf_filtered ("\t{ symtab %s ",
781 symtab_to_filename_for_display (symtab
));
783 printf_filtered ("((struct symtab *) %s)\n",
784 host_address_to_string (symtab
));
785 printf_filtered ("\t fullname %s\n",
786 symtab
->fullname
!= NULL
789 printf_filtered ("\t "
790 "linetable ((struct linetable *) %s)\n",
791 host_address_to_string (symtab
->linetable
));
792 printf_filtered ("\t}\n");
796 if (printed_compunit_symtab_start
)
797 printf_filtered (" }\n");
800 if (printed_objfile_start
)
801 printf_filtered ("}\n");
805 /* Check consistency of symtabs.
806 An example of what this checks for is NULL blockvectors.
807 They can happen if there's a bug during debug info reading.
808 GDB assumes they are always non-NULL.
810 Note: This does not check for psymtab vs symtab consistency.
811 Use "maint check-psymtabs" for that. */
814 maintenance_check_symtabs (char *ignore
, int from_tty
)
816 struct program_space
*pspace
;
817 struct objfile
*objfile
;
820 ALL_PSPACE_OBJFILES (pspace
, objfile
)
822 struct compunit_symtab
*cust
;
824 /* We don't want to print anything for this objfile until we
825 actually find something worth printing. */
826 int printed_objfile_start
= 0;
828 ALL_OBJFILE_COMPUNITS (objfile
, cust
)
830 int found_something
= 0;
831 struct symtab
*symtab
= compunit_primary_filetab (cust
);
835 if (COMPUNIT_BLOCKVECTOR (cust
) == NULL
)
837 /* Add more checks here. */
841 if (! printed_objfile_start
)
843 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
845 printf_filtered ("((struct objfile *) %s)\n",
846 host_address_to_string (objfile
));
847 printed_objfile_start
= 1;
849 printf_filtered (" { symtab %s\n",
850 symtab_to_filename_for_display (symtab
));
851 if (COMPUNIT_BLOCKVECTOR (cust
) == NULL
)
852 printf_filtered (" NULL blockvector\n");
853 printf_filtered (" }\n");
857 if (printed_objfile_start
)
858 printf_filtered ("}\n");
862 /* Helper function for maintenance_expand_symtabs.
863 This is the name_matcher function for expand_symtabs_matching. */
866 maintenance_expand_name_matcher (const char *symname
, void *data
)
868 /* Since we're not searching on symbols, just return TRUE. */
872 /* Helper function for maintenance_expand_symtabs.
873 This is the file_matcher function for expand_symtabs_matching. */
876 maintenance_expand_file_matcher (const char *filename
, void *data
,
879 const char *regexp
= (const char *) data
;
883 /* KISS: Only apply the regexp to the complete file name. */
887 if (regexp
== NULL
|| re_exec (filename
))
893 /* Expand all symbol tables whose name matches an optional regexp. */
896 maintenance_expand_symtabs (char *args
, int from_tty
)
898 struct program_space
*pspace
;
899 struct objfile
*objfile
;
900 struct cleanup
*cleanups
;
904 /* We use buildargv here so that we handle spaces in the regexp
905 in a way that allows adding more arguments later. */
906 argv
= gdb_buildargv (args
);
907 cleanups
= make_cleanup_freeargv (argv
);
915 error (_("Extra arguments after regexp."));
923 ALL_PSPACE_OBJFILES (pspace
, objfile
)
927 objfile
->sf
->qf
->expand_symtabs_matching
928 (objfile
, maintenance_expand_file_matcher
,
929 maintenance_expand_name_matcher
, NULL
, ALL_DOMAIN
, regexp
);
933 do_cleanups (cleanups
);
937 /* Return the nexting depth of a block within other blocks in its symtab. */
940 block_depth (struct block
*block
)
944 while ((block
= BLOCK_SUPERBLOCK (block
)) != NULL
)
952 /* Used by MAINTENANCE_INFO_LINE_TABLES to print the information about a
953 single line table. */
956 maintenance_print_one_line_table (struct symtab
*symtab
, void *data
)
958 struct linetable
*linetable
;
959 struct objfile
*objfile
;
961 objfile
= symtab
->compunit_symtab
->objfile
;
962 printf_filtered (_("objfile: %s ((struct objfile *) %s)\n"),
963 objfile_name (objfile
),
964 host_address_to_string (objfile
));
965 printf_filtered (_("compunit_symtab: ((struct compunit_symtab *) %s)\n"),
966 host_address_to_string (symtab
->compunit_symtab
));
967 printf_filtered (_("symtab: %s ((struct symtab *) %s)\n"),
968 symtab_to_fullname (symtab
),
969 host_address_to_string (symtab
));
970 linetable
= SYMTAB_LINETABLE (symtab
);
971 printf_filtered (_("linetable: ((struct linetable *) %s):\n"),
972 host_address_to_string (linetable
));
974 if (linetable
== NULL
)
975 printf_filtered (_("No line table.\n"));
976 else if (linetable
->nitems
<= 0)
977 printf_filtered (_("Line table has no lines.\n"));
982 /* Leave space for 6 digits of index and line number. After that the
983 tables will just not format as well. */
984 printf_filtered (_("%-6s %6s %s\n"),
985 _("INDEX"), _("LINE"), _("ADDRESS"));
987 for (i
= 0; i
< linetable
->nitems
; ++i
)
989 struct linetable_entry
*item
;
990 struct cleanup
*row_cleanup
;
992 item
= &linetable
->item
[i
];
993 printf_filtered (_("%-6d %6d %s\n"), i
, item
->line
,
994 core_addr_to_string (item
->pc
));
1001 /* Implement the 'maint info line-table' command. */
1004 maintenance_info_line_tables (char *regexp
, int from_tty
)
1006 struct program_space
*pspace
;
1007 struct objfile
*objfile
;
1014 ALL_PSPACES (pspace
)
1015 ALL_PSPACE_OBJFILES (pspace
, objfile
)
1017 struct compunit_symtab
*cust
;
1018 struct symtab
*symtab
;
1020 ALL_OBJFILE_COMPUNITS (objfile
, cust
)
1022 ALL_COMPUNIT_FILETABS (cust
, symtab
)
1027 || re_exec (symtab_to_filename_for_display (symtab
)))
1028 maintenance_print_one_line_table (symtab
, NULL
);
1036 /* Do early runtime initializations. */
1039 _initialize_symmisc (void)
1045 add_cmd ("symbols", class_maintenance
, maintenance_print_symbols
, _("\
1046 Print dump of current symbol definitions.\n\
1047 Entries in the full symbol table are dumped to file OUTFILE.\n\
1048 If a SOURCE file is specified, dump only that file's symbols."),
1049 &maintenanceprintlist
);
1051 add_cmd ("msymbols", class_maintenance
, maintenance_print_msymbols
, _("\
1052 Print dump of current minimal symbol definitions.\n\
1053 Entries in the minimal symbol table are dumped to file OUTFILE.\n\
1054 If a SOURCE file is specified, dump only that file's minimal symbols."),
1055 &maintenanceprintlist
);
1057 add_cmd ("objfiles", class_maintenance
, maintenance_print_objfiles
,
1058 _("Print dump of current object file definitions.\n\
1059 With an argument REGEXP, list the object files with matching names."),
1060 &maintenanceprintlist
);
1062 add_cmd ("symtabs", class_maintenance
, maintenance_info_symtabs
, _("\
1063 List the full symbol tables for all object files.\n\
1064 This does not include information about individual symbols, blocks, or\n\
1065 linetables --- just the symbol table structures themselves.\n\
1066 With an argument REGEXP, list the symbol tables with matching names."),
1067 &maintenanceinfolist
);
1069 add_cmd ("line-table", class_maintenance
, maintenance_info_line_tables
, _("\
1070 List the contents of all line tables, from all symbol tables.\n\
1071 With an argument REGEXP, list just the line tables for the symbol\n\
1072 tables with matching names."),
1073 &maintenanceinfolist
);
1075 add_cmd ("check-symtabs", class_maintenance
, maintenance_check_symtabs
,
1077 Check consistency of currently expanded symtabs."),
1080 add_cmd ("expand-symtabs", class_maintenance
, maintenance_expand_symtabs
,
1081 _("Expand symbol tables.\n\
1082 With an argument REGEXP, only expand the symbol tables with matching names."),