1 /* Do various things to symbol tables (other than lookup), for GDB.
3 Copyright (C) 1986-2021 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"
44 /* Prototypes for local functions */
46 static int block_depth (const struct block
*);
48 static void print_symbol (struct gdbarch
*gdbarch
, struct symbol
*symbol
,
49 int depth
, ui_file
*outfile
);
53 print_symbol_bcache_statistics (void)
55 for (struct program_space
*pspace
: program_spaces
)
56 for (objfile
*objfile
: pspace
->objfiles ())
59 printf_filtered (_("Byte cache statistics for '%s':\n"),
60 objfile_name (objfile
));
61 objfile
->partial_symtabs
->psymbol_cache
.print_statistics
62 ("partial symbol cache");
63 objfile
->per_bfd
->string_cache
.print_statistics ("string cache");
67 /* Count the number of partial symbols in OBJFILE. */
70 count_psyms (struct objfile
*objfile
)
73 for (partial_symtab
*pst
: objfile
->psymtabs ())
75 count
+= pst
->global_psymbols
.size ();
76 count
+= pst
->static_psymbols
.size ();
82 print_objfile_statistics (void)
84 int i
, linetables
, blockvectors
;
86 for (struct program_space
*pspace
: program_spaces
)
87 for (objfile
*objfile
: pspace
->objfiles ())
90 printf_filtered (_("Statistics for '%s':\n"), objfile_name (objfile
));
91 if (OBJSTAT (objfile
, n_stabs
) > 0)
92 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
93 OBJSTAT (objfile
, n_stabs
));
94 if (objfile
->per_bfd
->n_minsyms
> 0)
95 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
96 objfile
->per_bfd
->n_minsyms
);
98 int n_psyms
= count_psyms (objfile
);
100 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
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
));
108 objfile
->print_stats ();
110 for (compunit_symtab
*cu
: objfile
->compunits ())
112 for (symtab
*s
: compunit_filetabs (cu
))
115 if (SYMTAB_LINETABLE (s
) != NULL
)
119 blockvectors
= std::distance (objfile
->compunits ().begin (),
120 objfile
->compunits ().end ());
121 printf_filtered (_(" Number of symbol tables: %d\n"), i
);
122 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
124 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
127 if (OBJSTAT (objfile
, sz_strtab
) > 0)
128 printf_filtered (_(" Space used by string tables: %d\n"),
129 OBJSTAT (objfile
, sz_strtab
));
130 printf_filtered (_(" Total memory used for objfile obstack: %s\n"),
131 pulongest (obstack_memory_used (&objfile
132 ->objfile_obstack
)));
133 printf_filtered (_(" Total memory used for BFD obstack: %s\n"),
134 pulongest (obstack_memory_used (&objfile
->per_bfd
135 ->storage_obstack
)));
137 (_(" Total memory used for psymbol cache: %d\n"),
138 objfile
->partial_symtabs
->psymbol_cache
.memory_used ());
139 printf_filtered (_(" Total memory used for string cache: %d\n"),
140 objfile
->per_bfd
->string_cache
.memory_used ());
145 dump_objfile (struct objfile
*objfile
)
147 printf_filtered ("\nObject file %s: ", objfile_name (objfile
));
148 printf_filtered ("Objfile at ");
149 gdb_print_host_address (objfile
, gdb_stdout
);
150 printf_filtered (", bfd at ");
151 gdb_print_host_address (objfile
->obfd
, gdb_stdout
);
152 printf_filtered (", %d minsyms\n\n",
153 objfile
->per_bfd
->minimal_symbol_count
);
157 if (objfile
->compunit_symtabs
!= NULL
)
159 printf_filtered ("Symtabs:\n");
160 for (compunit_symtab
*cu
: objfile
->compunits ())
162 for (symtab
*symtab
: compunit_filetabs (cu
))
164 printf_filtered ("%s at ",
165 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! ");
175 printf_filtered ("\n\n");
179 /* Print minimal symbols from this objfile. */
182 dump_msymbols (struct objfile
*objfile
, struct ui_file
*outfile
)
184 struct gdbarch
*gdbarch
= objfile
->arch ();
188 fprintf_filtered (outfile
, "\nObject file %s:\n\n", objfile_name (objfile
));
189 if (objfile
->per_bfd
->minimal_symbol_count
== 0)
191 fprintf_filtered (outfile
, "No minimal symbols found.\n");
195 for (minimal_symbol
*msymbol
: objfile
->msymbols ())
197 struct obj_section
*section
= msymbol
->obj_section (objfile
);
199 switch (MSYMBOL_TYPE (msymbol
))
207 case mst_text_gnu_ifunc
:
208 case mst_data_gnu_ifunc
:
211 case mst_solib_trampoline
:
236 fprintf_filtered (outfile
, "[%2d] %c ", index
, ms_type
);
238 /* Use the relocated address as shown in the symbol here -- do
239 not try to respect copy relocations. */
240 CORE_ADDR addr
= (msymbol
->value
.address
241 + objfile
->section_offsets
[msymbol
->section_index ()]);
242 fputs_filtered (paddress (gdbarch
, addr
), outfile
);
243 fprintf_filtered (outfile
, " %s", msymbol
->linkage_name ());
246 if (section
->the_bfd_section
!= NULL
)
247 fprintf_filtered (outfile
, " section %s",
248 bfd_section_name (section
->the_bfd_section
));
250 fprintf_filtered (outfile
, " spurious section %ld",
251 (long) (section
- objfile
->sections
));
253 if (msymbol
->demangled_name () != NULL
)
255 fprintf_filtered (outfile
, " %s", msymbol
->demangled_name ());
257 if (msymbol
->filename
)
258 fprintf_filtered (outfile
, " %s", msymbol
->filename
);
259 fputs_filtered ("\n", outfile
);
262 if (objfile
->per_bfd
->minimal_symbol_count
!= index
)
264 warning (_("internal error: minimal symbol count %d != %d"),
265 objfile
->per_bfd
->minimal_symbol_count
, index
);
267 fprintf_filtered (outfile
, "\n");
271 dump_symtab_1 (struct symtab
*symtab
, struct ui_file
*outfile
)
273 struct objfile
*objfile
= SYMTAB_OBJFILE (symtab
);
274 struct gdbarch
*gdbarch
= objfile
->arch ();
276 struct mdict_iterator miter
;
279 const struct blockvector
*bv
;
281 const struct block
*b
;
284 fprintf_filtered (outfile
, "\nSymtab for file %s at %s\n",
285 symtab_to_filename_for_display (symtab
),
286 host_address_to_string (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 if (l
->item
[i
].is_stmt
)
309 fprintf_filtered (outfile
, "\t(stmt)");
310 fprintf_filtered (outfile
, "\n");
313 /* Now print the block info, but only for compunit symtabs since we will
314 print lots of duplicate info otherwise. */
315 if (is_main_symtab_of_compunit_symtab (symtab
))
317 fprintf_filtered (outfile
, "\nBlockvector:\n\n");
318 bv
= SYMTAB_BLOCKVECTOR (symtab
);
319 len
= BLOCKVECTOR_NBLOCKS (bv
);
320 for (i
= 0; i
< len
; i
++)
322 b
= BLOCKVECTOR_BLOCK (bv
, i
);
323 depth
= block_depth (b
) * 2;
324 print_spaces (depth
, outfile
);
325 fprintf_filtered (outfile
, "block #%03d, object at ", i
);
326 gdb_print_host_address (b
, outfile
);
327 if (BLOCK_SUPERBLOCK (b
))
329 fprintf_filtered (outfile
, " under ");
330 gdb_print_host_address (BLOCK_SUPERBLOCK (b
), outfile
);
332 /* drow/2002-07-10: We could save the total symbols count
333 even if we're using a hashtable, but nothing else but this message
335 fprintf_filtered (outfile
, ", %d syms/buckets in ",
336 mdict_size (BLOCK_MULTIDICT (b
)));
337 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), outfile
);
338 fprintf_filtered (outfile
, "..");
339 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), outfile
);
340 if (BLOCK_FUNCTION (b
))
342 fprintf_filtered (outfile
, ", function %s",
343 BLOCK_FUNCTION (b
)->linkage_name ());
344 if (BLOCK_FUNCTION (b
)->demangled_name () != NULL
)
346 fprintf_filtered (outfile
, ", %s",
347 BLOCK_FUNCTION (b
)->demangled_name ());
350 fprintf_filtered (outfile
, "\n");
351 /* Now print each symbol in this block (in no particular order, if
352 we're using a hashtable). Note that we only want this
353 block, not any blocks from included symtabs. */
354 ALL_DICT_SYMBOLS (BLOCK_MULTIDICT (b
), miter
, sym
)
358 print_symbol (gdbarch
, sym
, depth
+ 1, outfile
);
360 catch (const gdb_exception_error
&ex
)
362 exception_fprintf (gdb_stderr
, ex
,
363 "Error printing symbol:\n");
367 fprintf_filtered (outfile
, "\n");
371 const char *compunit_filename
372 = symtab_to_filename_for_display (COMPUNIT_FILETABS (SYMTAB_COMPUNIT (symtab
)));
374 fprintf_filtered (outfile
,
375 "\nBlockvector same as owning compunit: %s\n\n",
379 /* Print info about the user of this compunit_symtab, and the
380 compunit_symtabs included by this one. */
381 if (is_main_symtab_of_compunit_symtab (symtab
))
383 struct compunit_symtab
*cust
= SYMTAB_COMPUNIT (symtab
);
385 if (cust
->user
!= nullptr)
388 = host_address_to_string (COMPUNIT_FILETABS (cust
->user
));
389 fprintf_filtered (outfile
, "Compunit user: %s\n", addr
);
391 if (cust
->includes
!= nullptr)
394 struct compunit_symtab
*include
= cust
->includes
[i
];
395 if (include
== nullptr)
398 = host_address_to_string (COMPUNIT_FILETABS (include
));
399 fprintf_filtered (outfile
, "Compunit include: %s\n", addr
);
405 dump_symtab (struct symtab
*symtab
, struct ui_file
*outfile
)
407 /* Set the current language to the language of the symtab we're dumping
408 because certain routines used during dump_symtab() use the current
409 language to print an image of the symbol. We'll restore it later.
410 But use only real languages, not placeholders. */
411 if (symtab
->language
!= language_unknown
412 && symtab
->language
!= language_auto
)
414 scoped_restore_current_language save_lang
;
415 set_language (symtab
->language
);
416 dump_symtab_1 (symtab
, outfile
);
419 dump_symtab_1 (symtab
, outfile
);
423 maintenance_print_symbols (const char *args
, int from_tty
)
425 struct ui_file
*outfile
= gdb_stdout
;
426 char *address_arg
= NULL
, *source_arg
= NULL
, *objfile_arg
= NULL
;
431 gdb_argv
argv (args
);
433 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
435 if (strcmp (argv
[i
], "-pc") == 0)
437 if (argv
[i
+ 1] == NULL
)
438 error (_("Missing pc value"));
439 address_arg
= argv
[++i
];
441 else if (strcmp (argv
[i
], "-source") == 0)
443 if (argv
[i
+ 1] == NULL
)
444 error (_("Missing source file"));
445 source_arg
= argv
[++i
];
447 else if (strcmp (argv
[i
], "-objfile") == 0)
449 if (argv
[i
+ 1] == NULL
)
450 error (_("Missing objfile name"));
451 objfile_arg
= argv
[++i
];
453 else if (strcmp (argv
[i
], "--") == 0)
455 /* End of options. */
459 else if (argv
[i
][0] == '-')
461 /* Future proofing: Don't allow OUTFILE to begin with "-". */
462 error (_("Unknown option: %s"), argv
[i
]);
469 if (address_arg
!= NULL
&& source_arg
!= NULL
)
470 error (_("Must specify at most one of -pc and -source"));
472 stdio_file arg_outfile
;
474 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
476 if (argv
[outfile_idx
+ 1] != NULL
)
477 error (_("Junk at end of command"));
478 gdb::unique_xmalloc_ptr
<char> outfile_name
479 (tilde_expand (argv
[outfile_idx
]));
480 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
481 perror_with_name (outfile_name
.get ());
482 outfile
= &arg_outfile
;
485 if (address_arg
!= NULL
)
487 CORE_ADDR pc
= parse_and_eval_address (address_arg
);
488 struct symtab
*s
= find_pc_line_symtab (pc
);
491 error (_("No symtab for address: %s"), address_arg
);
492 dump_symtab (s
, outfile
);
498 for (objfile
*objfile
: current_program_space
->objfiles ())
500 int print_for_objfile
= 1;
502 if (objfile_arg
!= NULL
)
504 = compare_filenames_for_search (objfile_name (objfile
),
506 if (!print_for_objfile
)
509 for (compunit_symtab
*cu
: objfile
->compunits ())
511 for (symtab
*s
: compunit_filetabs (cu
))
513 int print_for_source
= 0;
516 if (source_arg
!= NULL
)
519 = compare_filenames_for_search
520 (symtab_to_filename_for_display (s
), source_arg
);
523 if (source_arg
== NULL
525 dump_symtab (s
, outfile
);
530 if (source_arg
!= NULL
&& !found
)
531 error (_("No symtab for source file: %s"), source_arg
);
535 /* Print symbol SYMBOL on OUTFILE. DEPTH says how far to indent. */
538 print_symbol (struct gdbarch
*gdbarch
, struct symbol
*symbol
,
539 int depth
, ui_file
*outfile
)
541 struct obj_section
*section
;
543 if (SYMBOL_OBJFILE_OWNED (symbol
))
544 section
= symbol
->obj_section (symbol_objfile (symbol
));
548 print_spaces (depth
, outfile
);
549 if (SYMBOL_DOMAIN (symbol
) == LABEL_DOMAIN
)
551 fprintf_filtered (outfile
, "label %s at ", symbol
->print_name ());
552 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
555 fprintf_filtered (outfile
, " section %s\n",
556 bfd_section_name (section
->the_bfd_section
));
558 fprintf_filtered (outfile
, "\n");
562 if (SYMBOL_DOMAIN (symbol
) == STRUCT_DOMAIN
)
564 if (SYMBOL_TYPE (symbol
)->name ())
566 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
,
567 &type_print_raw_options
);
571 fprintf_filtered (outfile
, "%s %s = ",
572 (SYMBOL_TYPE (symbol
)->code () == TYPE_CODE_ENUM
574 : (SYMBOL_TYPE (symbol
)->code () == TYPE_CODE_STRUCT
575 ? "struct" : "union")),
576 symbol
->linkage_name ());
577 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
,
578 &type_print_raw_options
);
580 fprintf_filtered (outfile
, ";\n");
584 if (SYMBOL_CLASS (symbol
) == LOC_TYPEDEF
)
585 fprintf_filtered (outfile
, "typedef ");
586 if (SYMBOL_TYPE (symbol
))
588 /* Print details of types, except for enums where it's clutter. */
589 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), symbol
->print_name (),
591 SYMBOL_TYPE (symbol
)->code () != TYPE_CODE_ENUM
,
593 &type_print_raw_options
);
594 fprintf_filtered (outfile
, "; ");
597 fprintf_filtered (outfile
, "%s ", symbol
->print_name ());
599 switch (SYMBOL_CLASS (symbol
))
602 fprintf_filtered (outfile
, "const %s (%s)",
603 plongest (SYMBOL_VALUE (symbol
)),
604 hex_string (SYMBOL_VALUE (symbol
)));
607 case LOC_CONST_BYTES
:
610 struct type
*type
= check_typedef (SYMBOL_TYPE (symbol
));
612 fprintf_filtered (outfile
, "const %s hex bytes:",
613 pulongest (TYPE_LENGTH (type
)));
614 for (i
= 0; i
< TYPE_LENGTH (type
); i
++)
615 fprintf_filtered (outfile
, " %02x",
616 (unsigned) SYMBOL_VALUE_BYTES (symbol
)[i
]);
621 fprintf_filtered (outfile
, "static at ");
622 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
625 fprintf_filtered (outfile
, " section %s",
626 bfd_section_name (section
->the_bfd_section
));
630 if (SYMBOL_IS_ARGUMENT (symbol
))
631 fprintf_filtered (outfile
, "parameter register %s",
632 plongest (SYMBOL_VALUE (symbol
)));
634 fprintf_filtered (outfile
, "register %s",
635 plongest (SYMBOL_VALUE (symbol
)));
639 fprintf_filtered (outfile
, "arg at offset %s",
640 hex_string (SYMBOL_VALUE (symbol
)));
644 fprintf_filtered (outfile
, "reference arg at %s",
645 hex_string (SYMBOL_VALUE (symbol
)));
648 case LOC_REGPARM_ADDR
:
649 fprintf_filtered (outfile
, "address parameter register %s",
650 plongest (SYMBOL_VALUE (symbol
)));
654 fprintf_filtered (outfile
, "local at offset %s",
655 hex_string (SYMBOL_VALUE (symbol
)));
662 fprintf_filtered (outfile
, "label at ");
663 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
666 fprintf_filtered (outfile
, " section %s",
667 bfd_section_name (section
->the_bfd_section
));
671 fprintf_filtered (outfile
, "block object ");
672 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol
), outfile
);
673 fprintf_filtered (outfile
, ", ");
674 fputs_filtered (paddress (gdbarch
,
675 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
))),
677 fprintf_filtered (outfile
, "..");
678 fputs_filtered (paddress (gdbarch
,
679 BLOCK_END (SYMBOL_BLOCK_VALUE (symbol
))),
682 fprintf_filtered (outfile
, " section %s",
683 bfd_section_name (section
->the_bfd_section
));
687 fprintf_filtered (outfile
, "computed at runtime");
691 fprintf_filtered (outfile
, "unresolved");
694 case LOC_OPTIMIZED_OUT
:
695 fprintf_filtered (outfile
, "optimized out");
699 fprintf_filtered (outfile
, "botched symbol class %x",
700 SYMBOL_CLASS (symbol
));
704 fprintf_filtered (outfile
, "\n");
708 maintenance_print_msymbols (const char *args
, int from_tty
)
710 struct ui_file
*outfile
= gdb_stdout
;
711 char *objfile_arg
= NULL
;
716 gdb_argv
argv (args
);
718 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
720 if (strcmp (argv
[i
], "-objfile") == 0)
722 if (argv
[i
+ 1] == NULL
)
723 error (_("Missing objfile name"));
724 objfile_arg
= argv
[++i
];
726 else if (strcmp (argv
[i
], "--") == 0)
728 /* End of options. */
732 else if (argv
[i
][0] == '-')
734 /* Future proofing: Don't allow OUTFILE to begin with "-". */
735 error (_("Unknown option: %s"), argv
[i
]);
742 stdio_file arg_outfile
;
744 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
746 if (argv
[outfile_idx
+ 1] != NULL
)
747 error (_("Junk at end of command"));
748 gdb::unique_xmalloc_ptr
<char> outfile_name
749 (tilde_expand (argv
[outfile_idx
]));
750 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
751 perror_with_name (outfile_name
.get ());
752 outfile
= &arg_outfile
;
755 for (objfile
*objfile
: current_program_space
->objfiles ())
758 if (objfile_arg
== NULL
759 || compare_filenames_for_search (objfile_name (objfile
), objfile_arg
))
760 dump_msymbols (objfile
, outfile
);
765 maintenance_print_objfiles (const char *regexp
, int from_tty
)
772 for (struct program_space
*pspace
: program_spaces
)
773 for (objfile
*objfile
: pspace
->objfiles ())
777 || re_exec (objfile_name (objfile
)))
778 dump_objfile (objfile
);
782 /* List all the symbol tables whose names match REGEXP (optional). */
785 maintenance_info_symtabs (const char *regexp
, int from_tty
)
792 for (struct program_space
*pspace
: program_spaces
)
793 for (objfile
*objfile
: pspace
->objfiles ())
795 /* We don't want to print anything for this objfile until we
796 actually find a symtab whose name matches. */
797 int printed_objfile_start
= 0;
799 for (compunit_symtab
*cust
: objfile
->compunits ())
801 int printed_compunit_symtab_start
= 0;
803 for (symtab
*symtab
: compunit_filetabs (cust
))
808 || re_exec (symtab_to_filename_for_display (symtab
)))
810 if (! printed_objfile_start
)
812 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
814 printf_filtered ("((struct objfile *) %s)\n",
815 host_address_to_string (objfile
));
816 printed_objfile_start
= 1;
818 if (! printed_compunit_symtab_start
)
820 printf_filtered (" { ((struct compunit_symtab *) %s)\n",
821 host_address_to_string (cust
));
822 printf_filtered (" debugformat %s\n",
823 COMPUNIT_DEBUGFORMAT (cust
));
824 printf_filtered (" producer %s\n",
825 COMPUNIT_PRODUCER (cust
) != NULL
826 ? COMPUNIT_PRODUCER (cust
)
828 printf_filtered (" dirname %s\n",
829 COMPUNIT_DIRNAME (cust
) != NULL
830 ? COMPUNIT_DIRNAME (cust
)
832 printf_filtered (" blockvector"
833 " ((struct blockvector *) %s)\n",
834 host_address_to_string
835 (COMPUNIT_BLOCKVECTOR (cust
)));
836 printf_filtered (" user"
837 " ((struct compunit_symtab *) %s)\n",
838 cust
->user
!= nullptr
839 ? host_address_to_string (cust
->user
)
841 if (cust
->includes
!= nullptr)
843 printf_filtered (" ( includes\n");
844 for (int i
= 0; ; ++i
)
846 struct compunit_symtab
*include
848 if (include
== nullptr)
851 = host_address_to_string (include
);
852 printf_filtered (" (%s %s)\n",
853 "(struct compunit_symtab *)",
856 printf_filtered (" )\n");
858 printed_compunit_symtab_start
= 1;
861 printf_filtered ("\t{ symtab %s ",
862 symtab_to_filename_for_display (symtab
));
864 printf_filtered ("((struct symtab *) %s)\n",
865 host_address_to_string (symtab
));
866 printf_filtered ("\t fullname %s\n",
867 symtab
->fullname
!= NULL
870 printf_filtered ("\t "
871 "linetable ((struct linetable *) %s)\n",
872 host_address_to_string (symtab
->linetable
));
873 printf_filtered ("\t}\n");
877 if (printed_compunit_symtab_start
)
878 printf_filtered (" }\n");
881 if (printed_objfile_start
)
882 printf_filtered ("}\n");
886 /* Check consistency of symtabs.
887 An example of what this checks for is NULL blockvectors.
888 They can happen if there's a bug during debug info reading.
889 GDB assumes they are always non-NULL.
891 Note: This does not check for psymtab vs symtab consistency.
892 Use "maint check-psymtabs" for that. */
895 maintenance_check_symtabs (const char *ignore
, int from_tty
)
897 for (struct program_space
*pspace
: program_spaces
)
898 for (objfile
*objfile
: pspace
->objfiles ())
900 /* We don't want to print anything for this objfile until we
901 actually find something worth printing. */
902 int printed_objfile_start
= 0;
904 for (compunit_symtab
*cust
: objfile
->compunits ())
906 int found_something
= 0;
907 struct symtab
*symtab
= compunit_primary_filetab (cust
);
911 if (COMPUNIT_BLOCKVECTOR (cust
) == NULL
)
913 /* Add more checks here. */
917 if (! printed_objfile_start
)
919 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
921 printf_filtered ("((struct objfile *) %s)\n",
922 host_address_to_string (objfile
));
923 printed_objfile_start
= 1;
925 printf_filtered (" { symtab %s\n",
926 symtab_to_filename_for_display (symtab
));
927 if (COMPUNIT_BLOCKVECTOR (cust
) == NULL
)
928 printf_filtered (" NULL blockvector\n");
929 printf_filtered (" }\n");
933 if (printed_objfile_start
)
934 printf_filtered ("}\n");
938 /* Expand all symbol tables whose name matches an optional regexp. */
941 maintenance_expand_symtabs (const char *args
, int from_tty
)
945 /* We use buildargv here so that we handle spaces in the regexp
946 in a way that allows adding more arguments later. */
947 gdb_argv
argv (args
);
955 error (_("Extra arguments after regexp."));
962 for (struct program_space
*pspace
: program_spaces
)
963 for (objfile
*objfile
: pspace
->objfiles ())
964 objfile
->expand_symtabs_matching
965 ([&] (const char *filename
, bool basenames
)
967 /* KISS: Only apply the regexp to the complete file name. */
969 && (regexp
== NULL
|| re_exec (filename
)));
978 /* Return the nexting depth of a block within other blocks in its symtab. */
981 block_depth (const struct block
*block
)
985 while ((block
= BLOCK_SUPERBLOCK (block
)) != NULL
)
993 /* Used by MAINTENANCE_INFO_LINE_TABLES to print the information about a
994 single line table. */
997 maintenance_print_one_line_table (struct symtab
*symtab
, void *data
)
999 struct linetable
*linetable
;
1000 struct objfile
*objfile
;
1002 objfile
= symtab
->compunit_symtab
->objfile
;
1003 printf_filtered (_("objfile: %s ((struct objfile *) %s)\n"),
1004 objfile_name (objfile
),
1005 host_address_to_string (objfile
));
1006 printf_filtered (_("compunit_symtab: ((struct compunit_symtab *) %s)\n"),
1007 host_address_to_string (symtab
->compunit_symtab
));
1008 printf_filtered (_("symtab: %s ((struct symtab *) %s)\n"),
1009 symtab_to_fullname (symtab
),
1010 host_address_to_string (symtab
));
1011 linetable
= SYMTAB_LINETABLE (symtab
);
1012 printf_filtered (_("linetable: ((struct linetable *) %s):\n"),
1013 host_address_to_string (linetable
));
1015 if (linetable
== NULL
)
1016 printf_filtered (_("No line table.\n"));
1017 else if (linetable
->nitems
<= 0)
1018 printf_filtered (_("Line table has no lines.\n"));
1021 /* Leave space for 6 digits of index and line number. After that the
1022 tables will just not format as well. */
1023 struct ui_out
*uiout
= current_uiout
;
1024 ui_out_emit_table
table_emitter (uiout
, 4, -1, "line-table");
1025 uiout
->table_header (6, ui_left
, "index", _("INDEX"));
1026 uiout
->table_header (6, ui_left
, "line", _("LINE"));
1027 uiout
->table_header (18, ui_left
, "address", _("ADDRESS"));
1028 uiout
->table_header (1, ui_left
, "is-stmt", _("IS-STMT"));
1029 uiout
->table_body ();
1031 for (int i
= 0; i
< linetable
->nitems
; ++i
)
1033 struct linetable_entry
*item
;
1035 item
= &linetable
->item
[i
];
1036 ui_out_emit_tuple
tuple_emitter (uiout
, nullptr);
1037 uiout
->field_signed ("index", i
);
1039 uiout
->field_signed ("line", item
->line
);
1041 uiout
->field_string ("line", _("END"));
1042 uiout
->field_core_addr ("address", objfile
->arch (),
1044 uiout
->field_string ("is-stmt", item
->is_stmt
? "Y" : "");
1052 /* Implement the 'maint info line-table' command. */
1055 maintenance_info_line_tables (const char *regexp
, int from_tty
)
1062 for (struct program_space
*pspace
: program_spaces
)
1063 for (objfile
*objfile
: pspace
->objfiles ())
1065 for (compunit_symtab
*cust
: objfile
->compunits ())
1067 for (symtab
*symtab
: compunit_filetabs (cust
))
1072 || re_exec (symtab_to_filename_for_display (symtab
)))
1073 maintenance_print_one_line_table (symtab
, NULL
);
1081 /* Do early runtime initializations. */
1083 void _initialize_symmisc ();
1085 _initialize_symmisc ()
1087 add_cmd ("symbols", class_maintenance
, maintenance_print_symbols
, _("\
1088 Print dump of current symbol definitions.\n\
1089 Usage: mt print symbols [-pc ADDRESS] [--] [OUTFILE]\n\
1090 mt print symbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
1091 Entries in the full symbol table are dumped to file OUTFILE,\n\
1092 or the terminal if OUTFILE is unspecified.\n\
1093 If ADDRESS is provided, dump only the file for that address.\n\
1094 If SOURCE is provided, dump only that file's symbols.\n\
1095 If OBJFILE is provided, dump only that file's minimal symbols."),
1096 &maintenanceprintlist
);
1098 add_cmd ("msymbols", class_maintenance
, maintenance_print_msymbols
, _("\
1099 Print dump of current minimal symbol definitions.\n\
1100 Usage: mt print msymbols [-objfile OBJFILE] [--] [OUTFILE]\n\
1101 Entries in the minimal symbol table are dumped to file OUTFILE,\n\
1102 or the terminal if OUTFILE is unspecified.\n\
1103 If OBJFILE is provided, dump only that file's minimal symbols."),
1104 &maintenanceprintlist
);
1106 add_cmd ("objfiles", class_maintenance
, maintenance_print_objfiles
,
1107 _("Print dump of current object file definitions.\n\
1108 With an argument REGEXP, list the object files with matching names."),
1109 &maintenanceprintlist
);
1111 add_cmd ("symtabs", class_maintenance
, maintenance_info_symtabs
, _("\
1112 List the full symbol tables for all object files.\n\
1113 This does not include information about individual symbols, blocks, or\n\
1114 linetables --- just the symbol table structures themselves.\n\
1115 With an argument REGEXP, list the symbol tables with matching names."),
1116 &maintenanceinfolist
);
1118 add_cmd ("line-table", class_maintenance
, maintenance_info_line_tables
, _("\
1119 List the contents of all line tables, from all symbol tables.\n\
1120 With an argument REGEXP, list just the line tables for the symbol\n\
1121 tables with matching names."),
1122 &maintenanceinfolist
);
1124 add_cmd ("check-symtabs", class_maintenance
, maintenance_check_symtabs
,
1126 Check consistency of currently expanded symtabs."),
1129 add_cmd ("expand-symtabs", class_maintenance
, maintenance_expand_symtabs
,
1130 _("Expand symbol tables.\n\
1131 With an argument REGEXP, only expand the symbol tables with matching names."),