1 /* Do various things to symbol tables (other than lookup), for GDB.
3 Copyright (C) 1986-2020 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/tilde.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 (const 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
: pspace
->objfiles ())
70 printf_filtered (_("Byte cache statistics for '%s':\n"),
71 objfile_name (objfile
));
72 objfile
->partial_symtabs
->psymbol_cache
.print_statistics
73 ("partial symbol cache");
74 objfile
->per_bfd
->string_cache
.print_statistics ("string cache");
79 print_objfile_statistics (void)
81 struct program_space
*pspace
;
82 int i
, linetables
, blockvectors
;
85 for (objfile
*objfile
: pspace
->objfiles ())
88 printf_filtered (_("Statistics for '%s':\n"), objfile_name (objfile
));
89 if (OBJSTAT (objfile
, n_stabs
) > 0)
90 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
91 OBJSTAT (objfile
, n_stabs
));
92 if (objfile
->per_bfd
->n_minsyms
> 0)
93 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
94 objfile
->per_bfd
->n_minsyms
);
95 if (OBJSTAT (objfile
, n_psyms
) > 0)
96 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
97 OBJSTAT (objfile
, n_psyms
));
98 if (OBJSTAT (objfile
, n_syms
) > 0)
99 printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
100 OBJSTAT (objfile
, n_syms
));
101 if (OBJSTAT (objfile
, n_types
) > 0)
102 printf_filtered (_(" Number of \"types\" defined: %d\n"),
103 OBJSTAT (objfile
, n_types
));
105 objfile
->sf
->qf
->print_stats (objfile
);
107 for (compunit_symtab
*cu
: objfile
->compunits ())
109 for (symtab
*s
: compunit_filetabs (cu
))
112 if (SYMTAB_LINETABLE (s
) != NULL
)
116 blockvectors
= std::distance (objfile
->compunits ().begin (),
117 objfile
->compunits ().end ());
118 printf_filtered (_(" Number of symbol tables: %d\n"), i
);
119 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
121 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
124 if (OBJSTAT (objfile
, sz_strtab
) > 0)
125 printf_filtered (_(" Space used by string tables: %d\n"),
126 OBJSTAT (objfile
, sz_strtab
));
127 printf_filtered (_(" Total memory used for objfile obstack: %s\n"),
128 pulongest (obstack_memory_used (&objfile
129 ->objfile_obstack
)));
130 printf_filtered (_(" Total memory used for BFD obstack: %s\n"),
131 pulongest (obstack_memory_used (&objfile
->per_bfd
132 ->storage_obstack
)));
134 (_(" Total memory used for psymbol cache: %d\n"),
135 objfile
->partial_symtabs
->psymbol_cache
.memory_used ());
136 printf_filtered (_(" Total memory used for string cache: %d\n"),
137 objfile
->per_bfd
->string_cache
.memory_used ());
142 dump_objfile (struct objfile
*objfile
)
144 printf_filtered ("\nObject file %s: ", objfile_name (objfile
));
145 printf_filtered ("Objfile at ");
146 gdb_print_host_address (objfile
, gdb_stdout
);
147 printf_filtered (", bfd at ");
148 gdb_print_host_address (objfile
->obfd
, gdb_stdout
);
149 printf_filtered (", %d minsyms\n\n",
150 objfile
->per_bfd
->minimal_symbol_count
);
153 objfile
->sf
->qf
->dump (objfile
);
155 if (objfile
->compunit_symtabs
!= NULL
)
157 printf_filtered ("Symtabs:\n");
158 for (compunit_symtab
*cu
: objfile
->compunits ())
160 for (symtab
*symtab
: compunit_filetabs (cu
))
162 printf_filtered ("%s at ",
163 symtab_to_filename_for_display (symtab
));
164 gdb_print_host_address (symtab
, gdb_stdout
);
165 printf_filtered (", ");
166 if (SYMTAB_OBJFILE (symtab
) != objfile
)
168 printf_filtered ("NOT ON CHAIN! ");
173 printf_filtered ("\n\n");
177 /* Print minimal symbols from this objfile. */
180 dump_msymbols (struct objfile
*objfile
, struct ui_file
*outfile
)
182 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
186 fprintf_filtered (outfile
, "\nObject file %s:\n\n", objfile_name (objfile
));
187 if (objfile
->per_bfd
->minimal_symbol_count
== 0)
189 fprintf_filtered (outfile
, "No minimal symbols found.\n");
193 for (minimal_symbol
*msymbol
: objfile
->msymbols ())
195 struct obj_section
*section
= MSYMBOL_OBJ_SECTION (objfile
, msymbol
);
197 switch (MSYMBOL_TYPE (msymbol
))
205 case mst_text_gnu_ifunc
:
206 case mst_data_gnu_ifunc
:
209 case mst_solib_trampoline
:
234 fprintf_filtered (outfile
, "[%2d] %c ", index
, ms_type
);
236 /* Use the relocated address as shown in the symbol here -- do
237 not try to respect copy relocations. */
238 CORE_ADDR addr
= (msymbol
->value
.address
239 + objfile
->section_offsets
[msymbol
->section
]);
240 fputs_filtered (paddress (gdbarch
, addr
), outfile
);
241 fprintf_filtered (outfile
, " %s", msymbol
->linkage_name ());
244 if (section
->the_bfd_section
!= NULL
)
245 fprintf_filtered (outfile
, " section %s",
246 bfd_section_name (section
->the_bfd_section
));
248 fprintf_filtered (outfile
, " spurious section %ld",
249 (long) (section
- objfile
->sections
));
251 if (msymbol
->demangled_name () != NULL
)
253 fprintf_filtered (outfile
, " %s", msymbol
->demangled_name ());
255 if (msymbol
->filename
)
256 fprintf_filtered (outfile
, " %s", msymbol
->filename
);
257 fputs_filtered ("\n", outfile
);
260 if (objfile
->per_bfd
->minimal_symbol_count
!= index
)
262 warning (_("internal error: minimal symbol count %d != %d"),
263 objfile
->per_bfd
->minimal_symbol_count
, index
);
265 fprintf_filtered (outfile
, "\n");
269 dump_symtab_1 (struct symtab
*symtab
, struct ui_file
*outfile
)
271 struct objfile
*objfile
= SYMTAB_OBJFILE (symtab
);
272 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
274 struct mdict_iterator miter
;
277 const struct blockvector
*bv
;
279 const struct block
*b
;
282 fprintf_filtered (outfile
, "\nSymtab for file %s\n",
283 symtab_to_filename_for_display (symtab
));
284 if (SYMTAB_DIRNAME (symtab
) != NULL
)
285 fprintf_filtered (outfile
, "Compilation directory is %s\n",
286 SYMTAB_DIRNAME (symtab
));
287 fprintf_filtered (outfile
, "Read from object file %s (",
288 objfile_name (objfile
));
289 gdb_print_host_address (objfile
, outfile
);
290 fprintf_filtered (outfile
, ")\n");
291 fprintf_filtered (outfile
, "Language: %s\n",
292 language_str (symtab
->language
));
294 /* First print the line table. */
295 l
= SYMTAB_LINETABLE (symtab
);
298 fprintf_filtered (outfile
, "\nLine table:\n\n");
300 for (i
= 0; i
< len
; i
++)
302 fprintf_filtered (outfile
, " line %d at ", l
->item
[i
].line
);
303 fputs_filtered (paddress (gdbarch
, l
->item
[i
].pc
), outfile
);
304 fprintf_filtered (outfile
, "\n");
307 /* Now print the block info, but only for compunit symtabs since we will
308 print lots of duplicate info otherwise. */
309 if (symtab
== COMPUNIT_FILETABS (SYMTAB_COMPUNIT (symtab
)))
311 fprintf_filtered (outfile
, "\nBlockvector:\n\n");
312 bv
= SYMTAB_BLOCKVECTOR (symtab
);
313 len
= BLOCKVECTOR_NBLOCKS (bv
);
314 for (i
= 0; i
< len
; i
++)
316 b
= BLOCKVECTOR_BLOCK (bv
, i
);
317 depth
= block_depth (b
) * 2;
318 print_spaces (depth
, outfile
);
319 fprintf_filtered (outfile
, "block #%03d, object at ", i
);
320 gdb_print_host_address (b
, outfile
);
321 if (BLOCK_SUPERBLOCK (b
))
323 fprintf_filtered (outfile
, " under ");
324 gdb_print_host_address (BLOCK_SUPERBLOCK (b
), outfile
);
326 /* drow/2002-07-10: We could save the total symbols count
327 even if we're using a hashtable, but nothing else but this message
329 fprintf_filtered (outfile
, ", %d syms/buckets in ",
330 mdict_size (BLOCK_MULTIDICT (b
)));
331 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), outfile
);
332 fprintf_filtered (outfile
, "..");
333 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), outfile
);
334 if (BLOCK_FUNCTION (b
))
336 fprintf_filtered (outfile
, ", function %s",
337 BLOCK_FUNCTION (b
)->linkage_name ());
338 if (BLOCK_FUNCTION (b
)->demangled_name () != NULL
)
340 fprintf_filtered (outfile
, ", %s",
341 BLOCK_FUNCTION (b
)->demangled_name ());
344 fprintf_filtered (outfile
, "\n");
345 /* Now print each symbol in this block (in no particular order, if
346 we're using a hashtable). Note that we only want this
347 block, not any blocks from included symtabs. */
348 ALL_DICT_SYMBOLS (BLOCK_MULTIDICT (b
), miter
, sym
)
352 print_symbol (gdbarch
, sym
, depth
+ 1, outfile
);
354 catch (const gdb_exception_error
&ex
)
356 exception_fprintf (gdb_stderr
, ex
,
357 "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 scoped_restore_current_language save_lang
;
385 set_language (symtab
->language
);
386 dump_symtab_1 (symtab
, outfile
);
389 dump_symtab_1 (symtab
, outfile
);
393 maintenance_print_symbols (const char *args
, int from_tty
)
395 struct ui_file
*outfile
= gdb_stdout
;
396 char *address_arg
= NULL
, *source_arg
= NULL
, *objfile_arg
= NULL
;
401 gdb_argv
argv (args
);
403 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
405 if (strcmp (argv
[i
], "-pc") == 0)
407 if (argv
[i
+ 1] == NULL
)
408 error (_("Missing pc value"));
409 address_arg
= argv
[++i
];
411 else if (strcmp (argv
[i
], "-source") == 0)
413 if (argv
[i
+ 1] == NULL
)
414 error (_("Missing source file"));
415 source_arg
= argv
[++i
];
417 else if (strcmp (argv
[i
], "-objfile") == 0)
419 if (argv
[i
+ 1] == NULL
)
420 error (_("Missing objfile name"));
421 objfile_arg
= argv
[++i
];
423 else if (strcmp (argv
[i
], "--") == 0)
425 /* End of options. */
429 else if (argv
[i
][0] == '-')
431 /* Future proofing: Don't allow OUTFILE to begin with "-". */
432 error (_("Unknown option: %s"), argv
[i
]);
439 if (address_arg
!= NULL
&& source_arg
!= NULL
)
440 error (_("Must specify at most one of -pc and -source"));
442 stdio_file arg_outfile
;
444 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
446 if (argv
[outfile_idx
+ 1] != NULL
)
447 error (_("Junk at end of command"));
448 gdb::unique_xmalloc_ptr
<char> outfile_name
449 (tilde_expand (argv
[outfile_idx
]));
450 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
451 perror_with_name (outfile_name
.get ());
452 outfile
= &arg_outfile
;
455 if (address_arg
!= NULL
)
457 CORE_ADDR pc
= parse_and_eval_address (address_arg
);
458 struct symtab
*s
= find_pc_line_symtab (pc
);
461 error (_("No symtab for address: %s"), address_arg
);
462 dump_symtab (s
, outfile
);
468 for (objfile
*objfile
: current_program_space
->objfiles ())
470 int print_for_objfile
= 1;
472 if (objfile_arg
!= NULL
)
474 = compare_filenames_for_search (objfile_name (objfile
),
476 if (!print_for_objfile
)
479 for (compunit_symtab
*cu
: objfile
->compunits ())
481 for (symtab
*s
: compunit_filetabs (cu
))
483 int print_for_source
= 0;
486 if (source_arg
!= NULL
)
489 = compare_filenames_for_search
490 (symtab_to_filename_for_display (s
), source_arg
);
493 if (source_arg
== NULL
495 dump_symtab (s
, outfile
);
500 if (source_arg
!= NULL
&& !found
)
501 error (_("No symtab for source file: %s"), source_arg
);
505 /* Print symbol SYMBOL on OUTFILE. DEPTH says how far to indent. */
508 print_symbol (struct gdbarch
*gdbarch
, struct symbol
*symbol
,
509 int depth
, ui_file
*outfile
)
511 struct obj_section
*section
;
513 if (SYMBOL_OBJFILE_OWNED (symbol
))
514 section
= SYMBOL_OBJ_SECTION (symbol_objfile (symbol
), symbol
);
518 print_spaces (depth
, outfile
);
519 if (SYMBOL_DOMAIN (symbol
) == LABEL_DOMAIN
)
521 fprintf_filtered (outfile
, "label %s at ", symbol
->print_name ());
522 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
525 fprintf_filtered (outfile
, " section %s\n",
526 bfd_section_name (section
->the_bfd_section
));
528 fprintf_filtered (outfile
, "\n");
532 if (SYMBOL_DOMAIN (symbol
) == STRUCT_DOMAIN
)
534 if (TYPE_NAME (SYMBOL_TYPE (symbol
)))
536 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
,
537 &type_print_raw_options
);
541 fprintf_filtered (outfile
, "%s %s = ",
542 (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_ENUM
544 : (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_STRUCT
545 ? "struct" : "union")),
546 symbol
->linkage_name ());
547 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
,
548 &type_print_raw_options
);
550 fprintf_filtered (outfile
, ";\n");
554 if (SYMBOL_CLASS (symbol
) == LOC_TYPEDEF
)
555 fprintf_filtered (outfile
, "typedef ");
556 if (SYMBOL_TYPE (symbol
))
558 /* Print details of types, except for enums where it's clutter. */
559 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), symbol
->print_name (),
561 TYPE_CODE (SYMBOL_TYPE (symbol
)) != TYPE_CODE_ENUM
,
563 &type_print_raw_options
);
564 fprintf_filtered (outfile
, "; ");
567 fprintf_filtered (outfile
, "%s ", symbol
->print_name ());
569 switch (SYMBOL_CLASS (symbol
))
572 fprintf_filtered (outfile
, "const %s (%s)",
573 plongest (SYMBOL_VALUE (symbol
)),
574 hex_string (SYMBOL_VALUE (symbol
)));
577 case LOC_CONST_BYTES
:
580 struct type
*type
= check_typedef (SYMBOL_TYPE (symbol
));
582 fprintf_filtered (outfile
, "const %s hex bytes:",
583 pulongest (TYPE_LENGTH (type
)));
584 for (i
= 0; i
< TYPE_LENGTH (type
); i
++)
585 fprintf_filtered (outfile
, " %02x",
586 (unsigned) SYMBOL_VALUE_BYTES (symbol
)[i
]);
591 fprintf_filtered (outfile
, "static at ");
592 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
595 fprintf_filtered (outfile
, " section %s",
596 bfd_section_name (section
->the_bfd_section
));
600 if (SYMBOL_IS_ARGUMENT (symbol
))
601 fprintf_filtered (outfile
, "parameter register %s",
602 plongest (SYMBOL_VALUE (symbol
)));
604 fprintf_filtered (outfile
, "register %s",
605 plongest (SYMBOL_VALUE (symbol
)));
609 fprintf_filtered (outfile
, "arg at offset %s",
610 hex_string (SYMBOL_VALUE (symbol
)));
614 fprintf_filtered (outfile
, "reference arg at %s",
615 hex_string (SYMBOL_VALUE (symbol
)));
618 case LOC_REGPARM_ADDR
:
619 fprintf_filtered (outfile
, "address parameter register %s",
620 plongest (SYMBOL_VALUE (symbol
)));
624 fprintf_filtered (outfile
, "local at offset %s",
625 hex_string (SYMBOL_VALUE (symbol
)));
632 fprintf_filtered (outfile
, "label at ");
633 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
636 fprintf_filtered (outfile
, " section %s",
637 bfd_section_name (section
->the_bfd_section
));
641 fprintf_filtered (outfile
, "block object ");
642 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol
), outfile
);
643 fprintf_filtered (outfile
, ", ");
644 fputs_filtered (paddress (gdbarch
,
645 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
))),
647 fprintf_filtered (outfile
, "..");
648 fputs_filtered (paddress (gdbarch
,
649 BLOCK_END (SYMBOL_BLOCK_VALUE (symbol
))),
652 fprintf_filtered (outfile
, " section %s",
653 bfd_section_name (section
->the_bfd_section
));
657 fprintf_filtered (outfile
, "computed at runtime");
661 fprintf_filtered (outfile
, "unresolved");
664 case LOC_OPTIMIZED_OUT
:
665 fprintf_filtered (outfile
, "optimized out");
669 fprintf_filtered (outfile
, "botched symbol class %x",
670 SYMBOL_CLASS (symbol
));
674 fprintf_filtered (outfile
, "\n");
678 maintenance_print_msymbols (const char *args
, int from_tty
)
680 struct ui_file
*outfile
= gdb_stdout
;
681 char *objfile_arg
= NULL
;
686 gdb_argv
argv (args
);
688 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
690 if (strcmp (argv
[i
], "-objfile") == 0)
692 if (argv
[i
+ 1] == NULL
)
693 error (_("Missing objfile name"));
694 objfile_arg
= argv
[++i
];
696 else if (strcmp (argv
[i
], "--") == 0)
698 /* End of options. */
702 else if (argv
[i
][0] == '-')
704 /* Future proofing: Don't allow OUTFILE to begin with "-". */
705 error (_("Unknown option: %s"), argv
[i
]);
712 stdio_file arg_outfile
;
714 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
716 if (argv
[outfile_idx
+ 1] != NULL
)
717 error (_("Junk at end of command"));
718 gdb::unique_xmalloc_ptr
<char> outfile_name
719 (tilde_expand (argv
[outfile_idx
]));
720 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
721 perror_with_name (outfile_name
.get ());
722 outfile
= &arg_outfile
;
725 for (objfile
*objfile
: current_program_space
->objfiles ())
728 if (objfile_arg
== NULL
729 || compare_filenames_for_search (objfile_name (objfile
), objfile_arg
))
730 dump_msymbols (objfile
, outfile
);
735 maintenance_print_objfiles (const char *regexp
, int from_tty
)
737 struct program_space
*pspace
;
745 for (objfile
*objfile
: pspace
->objfiles ())
749 || re_exec (objfile_name (objfile
)))
750 dump_objfile (objfile
);
754 /* List all the symbol tables whose names match REGEXP (optional). */
757 maintenance_info_symtabs (const char *regexp
, int from_tty
)
759 struct program_space
*pspace
;
767 for (objfile
*objfile
: pspace
->objfiles ())
769 /* We don't want to print anything for this objfile until we
770 actually find a symtab whose name matches. */
771 int printed_objfile_start
= 0;
773 for (compunit_symtab
*cust
: objfile
->compunits ())
775 int printed_compunit_symtab_start
= 0;
777 for (symtab
*symtab
: compunit_filetabs (cust
))
782 || re_exec (symtab_to_filename_for_display (symtab
)))
784 if (! printed_objfile_start
)
786 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
788 printf_filtered ("((struct objfile *) %s)\n",
789 host_address_to_string (objfile
));
790 printed_objfile_start
= 1;
792 if (! printed_compunit_symtab_start
)
794 printf_filtered (" { ((struct compunit_symtab *) %s)\n",
795 host_address_to_string (cust
));
796 printf_filtered (" debugformat %s\n",
797 COMPUNIT_DEBUGFORMAT (cust
));
798 printf_filtered (" producer %s\n",
799 COMPUNIT_PRODUCER (cust
) != NULL
800 ? COMPUNIT_PRODUCER (cust
)
802 printf_filtered (" dirname %s\n",
803 COMPUNIT_DIRNAME (cust
) != NULL
804 ? COMPUNIT_DIRNAME (cust
)
806 printf_filtered (" blockvector"
807 " ((struct blockvector *) %s)\n",
808 host_address_to_string
809 (COMPUNIT_BLOCKVECTOR (cust
)));
810 printed_compunit_symtab_start
= 1;
813 printf_filtered ("\t{ symtab %s ",
814 symtab_to_filename_for_display (symtab
));
816 printf_filtered ("((struct symtab *) %s)\n",
817 host_address_to_string (symtab
));
818 printf_filtered ("\t fullname %s\n",
819 symtab
->fullname
!= NULL
822 printf_filtered ("\t "
823 "linetable ((struct linetable *) %s)\n",
824 host_address_to_string (symtab
->linetable
));
825 printf_filtered ("\t}\n");
829 if (printed_compunit_symtab_start
)
830 printf_filtered (" }\n");
833 if (printed_objfile_start
)
834 printf_filtered ("}\n");
838 /* Check consistency of symtabs.
839 An example of what this checks for is NULL blockvectors.
840 They can happen if there's a bug during debug info reading.
841 GDB assumes they are always non-NULL.
843 Note: This does not check for psymtab vs symtab consistency.
844 Use "maint check-psymtabs" for that. */
847 maintenance_check_symtabs (const char *ignore
, int from_tty
)
849 struct program_space
*pspace
;
852 for (objfile
*objfile
: pspace
->objfiles ())
854 /* We don't want to print anything for this objfile until we
855 actually find something worth printing. */
856 int printed_objfile_start
= 0;
858 for (compunit_symtab
*cust
: objfile
->compunits ())
860 int found_something
= 0;
861 struct symtab
*symtab
= compunit_primary_filetab (cust
);
865 if (COMPUNIT_BLOCKVECTOR (cust
) == NULL
)
867 /* Add more checks here. */
871 if (! printed_objfile_start
)
873 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
875 printf_filtered ("((struct objfile *) %s)\n",
876 host_address_to_string (objfile
));
877 printed_objfile_start
= 1;
879 printf_filtered (" { symtab %s\n",
880 symtab_to_filename_for_display (symtab
));
881 if (COMPUNIT_BLOCKVECTOR (cust
) == NULL
)
882 printf_filtered (" NULL blockvector\n");
883 printf_filtered (" }\n");
887 if (printed_objfile_start
)
888 printf_filtered ("}\n");
892 /* Expand all symbol tables whose name matches an optional regexp. */
895 maintenance_expand_symtabs (const char *args
, int from_tty
)
897 struct program_space
*pspace
;
900 /* We use buildargv here so that we handle spaces in the regexp
901 in a way that allows adding more arguments later. */
902 gdb_argv
argv (args
);
910 error (_("Extra arguments after regexp."));
918 for (objfile
*objfile
: pspace
->objfiles ())
922 objfile
->sf
->qf
->expand_symtabs_matching
924 [&] (const char *filename
, bool basenames
)
926 /* KISS: Only apply the regexp to the complete file name. */
928 && (regexp
== NULL
|| re_exec (filename
)));
930 lookup_name_info::match_any (),
931 [] (const char *symname
)
933 /* Since we're not searching on symbols, just return true. */
943 /* Return the nexting depth of a block within other blocks in its symtab. */
946 block_depth (const struct block
*block
)
950 while ((block
= BLOCK_SUPERBLOCK (block
)) != NULL
)
958 /* Used by MAINTENANCE_INFO_LINE_TABLES to print the information about a
959 single line table. */
962 maintenance_print_one_line_table (struct symtab
*symtab
, void *data
)
964 struct linetable
*linetable
;
965 struct objfile
*objfile
;
967 objfile
= symtab
->compunit_symtab
->objfile
;
968 printf_filtered (_("objfile: %s ((struct objfile *) %s)\n"),
969 objfile_name (objfile
),
970 host_address_to_string (objfile
));
971 printf_filtered (_("compunit_symtab: ((struct compunit_symtab *) %s)\n"),
972 host_address_to_string (symtab
->compunit_symtab
));
973 printf_filtered (_("symtab: %s ((struct symtab *) %s)\n"),
974 symtab_to_fullname (symtab
),
975 host_address_to_string (symtab
));
976 linetable
= SYMTAB_LINETABLE (symtab
);
977 printf_filtered (_("linetable: ((struct linetable *) %s):\n"),
978 host_address_to_string (linetable
));
980 if (linetable
== NULL
)
981 printf_filtered (_("No line table.\n"));
982 else if (linetable
->nitems
<= 0)
983 printf_filtered (_("Line table has no lines.\n"));
988 /* Leave space for 6 digits of index and line number. After that the
989 tables will just not format as well. */
990 printf_filtered (_("%-6s %6s %s\n"),
991 _("INDEX"), _("LINE"), _("ADDRESS"));
993 for (i
= 0; i
< linetable
->nitems
; ++i
)
995 struct linetable_entry
*item
;
997 item
= &linetable
->item
[i
];
998 printf_filtered ("%-6d ", i
);
1000 printf_filtered ("%6d ", item
->line
);
1002 printf_filtered ("%6s ", _("END"));
1003 printf_filtered ("%s\n", core_addr_to_string (item
->pc
));
1010 /* Implement the 'maint info line-table' command. */
1013 maintenance_info_line_tables (const char *regexp
, int from_tty
)
1015 struct program_space
*pspace
;
1022 ALL_PSPACES (pspace
)
1023 for (objfile
*objfile
: pspace
->objfiles ())
1025 for (compunit_symtab
*cust
: objfile
->compunits ())
1027 for (symtab
*symtab
: compunit_filetabs (cust
))
1032 || re_exec (symtab_to_filename_for_display (symtab
)))
1033 maintenance_print_one_line_table (symtab
, NULL
);
1041 /* Do early runtime initializations. */
1043 void _initialize_symmisc ();
1045 _initialize_symmisc ()
1051 add_cmd ("symbols", class_maintenance
, maintenance_print_symbols
, _("\
1052 Print dump of current symbol definitions.\n\
1053 Usage: mt print symbols [-pc ADDRESS] [--] [OUTFILE]\n\
1054 mt print symbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
1055 Entries in the full symbol table are dumped to file OUTFILE,\n\
1056 or the terminal if OUTFILE is unspecified.\n\
1057 If ADDRESS is provided, dump only the file for that address.\n\
1058 If SOURCE is provided, dump only that file's symbols.\n\
1059 If OBJFILE is provided, dump only that file's minimal symbols."),
1060 &maintenanceprintlist
);
1062 add_cmd ("msymbols", class_maintenance
, maintenance_print_msymbols
, _("\
1063 Print dump of current minimal symbol definitions.\n\
1064 Usage: mt print msymbols [-objfile OBJFILE] [--] [OUTFILE]\n\
1065 Entries in the minimal symbol table are dumped to file OUTFILE,\n\
1066 or the terminal if OUTFILE is unspecified.\n\
1067 If OBJFILE is provided, dump only that file's minimal symbols."),
1068 &maintenanceprintlist
);
1070 add_cmd ("objfiles", class_maintenance
, maintenance_print_objfiles
,
1071 _("Print dump of current object file definitions.\n\
1072 With an argument REGEXP, list the object files with matching names."),
1073 &maintenanceprintlist
);
1075 add_cmd ("symtabs", class_maintenance
, maintenance_info_symtabs
, _("\
1076 List the full symbol tables for all object files.\n\
1077 This does not include information about individual symbols, blocks, or\n\
1078 linetables --- just the symbol table structures themselves.\n\
1079 With an argument REGEXP, list the symbol tables with matching names."),
1080 &maintenanceinfolist
);
1082 add_cmd ("line-table", class_maintenance
, maintenance_info_line_tables
, _("\
1083 List the contents of all line tables, from all symbol tables.\n\
1084 With an argument REGEXP, list just the line tables for the symbol\n\
1085 tables with matching names."),
1086 &maintenanceinfolist
);
1088 add_cmd ("check-symtabs", class_maintenance
, maintenance_check_symtabs
,
1090 Check consistency of currently expanded symtabs."),
1093 add_cmd ("expand-symtabs", class_maintenance
, maintenance_expand_symtabs
,
1094 _("Expand symbol tables.\n\
1095 With an argument REGEXP, only expand the symbol tables with matching names."),