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"
41 /* Prototypes for local functions */
43 static int block_depth (const struct block
*);
45 static void print_symbol (struct gdbarch
*gdbarch
, struct symbol
*symbol
,
46 int depth
, ui_file
*outfile
);
50 print_objfile_statistics (void)
52 int i
, linetables
, blockvectors
;
54 for (struct program_space
*pspace
: program_spaces
)
55 for (objfile
*objfile
: pspace
->objfiles ())
58 printf_filtered (_("Statistics for '%s':\n"), objfile_name (objfile
));
59 if (OBJSTAT (objfile
, n_stabs
) > 0)
60 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
61 OBJSTAT (objfile
, n_stabs
));
62 if (objfile
->per_bfd
->n_minsyms
> 0)
63 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
64 objfile
->per_bfd
->n_minsyms
);
65 if (OBJSTAT (objfile
, n_syms
) > 0)
66 printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
67 OBJSTAT (objfile
, n_syms
));
68 if (OBJSTAT (objfile
, n_types
) > 0)
69 printf_filtered (_(" Number of \"types\" defined: %d\n"),
70 OBJSTAT (objfile
, n_types
));
73 for (compunit_symtab
*cu
: objfile
->compunits ())
75 for (symtab
*s
: compunit_filetabs (cu
))
78 if (SYMTAB_LINETABLE (s
) != NULL
)
82 blockvectors
= std::distance (objfile
->compunits ().begin (),
83 objfile
->compunits ().end ());
84 printf_filtered (_(" Number of symbol tables: %d\n"), i
);
85 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
87 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
90 objfile
->print_stats (false);
92 if (OBJSTAT (objfile
, sz_strtab
) > 0)
93 printf_filtered (_(" Space used by string tables: %d\n"),
94 OBJSTAT (objfile
, sz_strtab
));
95 printf_filtered (_(" Total memory used for objfile obstack: %s\n"),
96 pulongest (obstack_memory_used (&objfile
98 printf_filtered (_(" Total memory used for BFD obstack: %s\n"),
99 pulongest (obstack_memory_used (&objfile
->per_bfd
100 ->storage_obstack
)));
102 printf_filtered (_(" Total memory used for string cache: %d\n"),
103 objfile
->per_bfd
->string_cache
.memory_used ());
104 printf_filtered (_("Byte cache statistics for '%s':\n"),
105 objfile_name (objfile
));
106 objfile
->per_bfd
->string_cache
.print_statistics ("string cache");
107 objfile
->print_stats (true);
112 dump_objfile (struct objfile
*objfile
)
114 printf_filtered ("\nObject file %s: ", objfile_name (objfile
));
115 printf_filtered ("Objfile at ");
116 gdb_print_host_address (objfile
, gdb_stdout
);
117 printf_filtered (", bfd at ");
118 gdb_print_host_address (objfile
->obfd
, gdb_stdout
);
119 printf_filtered (", %d minsyms\n\n",
120 objfile
->per_bfd
->minimal_symbol_count
);
124 if (objfile
->compunit_symtabs
!= NULL
)
126 printf_filtered ("Symtabs:\n");
127 for (compunit_symtab
*cu
: objfile
->compunits ())
129 for (symtab
*symtab
: compunit_filetabs (cu
))
131 printf_filtered ("%s at ",
132 symtab_to_filename_for_display (symtab
));
133 gdb_print_host_address (symtab
, gdb_stdout
);
134 printf_filtered (", ");
135 if (SYMTAB_OBJFILE (symtab
) != objfile
)
137 printf_filtered ("NOT ON CHAIN! ");
142 printf_filtered ("\n\n");
146 /* Print minimal symbols from this objfile. */
149 dump_msymbols (struct objfile
*objfile
, struct ui_file
*outfile
)
151 struct gdbarch
*gdbarch
= objfile
->arch ();
155 fprintf_filtered (outfile
, "\nObject file %s:\n\n", objfile_name (objfile
));
156 if (objfile
->per_bfd
->minimal_symbol_count
== 0)
158 fprintf_filtered (outfile
, "No minimal symbols found.\n");
162 for (minimal_symbol
*msymbol
: objfile
->msymbols ())
164 struct obj_section
*section
= msymbol
->obj_section (objfile
);
166 switch (MSYMBOL_TYPE (msymbol
))
174 case mst_text_gnu_ifunc
:
175 case mst_data_gnu_ifunc
:
178 case mst_solib_trampoline
:
203 fprintf_filtered (outfile
, "[%2d] %c ", index
, ms_type
);
205 /* Use the relocated address as shown in the symbol here -- do
206 not try to respect copy relocations. */
207 CORE_ADDR addr
= (msymbol
->value
.address
208 + objfile
->section_offsets
[msymbol
->section_index ()]);
209 fputs_filtered (paddress (gdbarch
, addr
), outfile
);
210 fprintf_filtered (outfile
, " %s", msymbol
->linkage_name ());
213 if (section
->the_bfd_section
!= NULL
)
214 fprintf_filtered (outfile
, " section %s",
215 bfd_section_name (section
->the_bfd_section
));
217 fprintf_filtered (outfile
, " spurious section %ld",
218 (long) (section
- objfile
->sections
));
220 if (msymbol
->demangled_name () != NULL
)
222 fprintf_filtered (outfile
, " %s", msymbol
->demangled_name ());
224 if (msymbol
->filename
)
225 fprintf_filtered (outfile
, " %s", msymbol
->filename
);
226 fputs_filtered ("\n", outfile
);
229 if (objfile
->per_bfd
->minimal_symbol_count
!= index
)
231 warning (_("internal error: minimal symbol count %d != %d"),
232 objfile
->per_bfd
->minimal_symbol_count
, index
);
234 fprintf_filtered (outfile
, "\n");
238 dump_symtab_1 (struct symtab
*symtab
, struct ui_file
*outfile
)
240 struct objfile
*objfile
= SYMTAB_OBJFILE (symtab
);
241 struct gdbarch
*gdbarch
= objfile
->arch ();
243 struct mdict_iterator miter
;
246 const struct blockvector
*bv
;
248 const struct block
*b
;
251 fprintf_filtered (outfile
, "\nSymtab for file %s at %s\n",
252 symtab_to_filename_for_display (symtab
),
253 host_address_to_string (symtab
));
255 if (SYMTAB_DIRNAME (symtab
) != NULL
)
256 fprintf_filtered (outfile
, "Compilation directory is %s\n",
257 SYMTAB_DIRNAME (symtab
));
258 fprintf_filtered (outfile
, "Read from object file %s (",
259 objfile_name (objfile
));
260 gdb_print_host_address (objfile
, outfile
);
261 fprintf_filtered (outfile
, ")\n");
262 fprintf_filtered (outfile
, "Language: %s\n",
263 language_str (symtab
->language
));
265 /* First print the line table. */
266 l
= SYMTAB_LINETABLE (symtab
);
269 fprintf_filtered (outfile
, "\nLine table:\n\n");
271 for (i
= 0; i
< len
; i
++)
273 fprintf_filtered (outfile
, " line %d at ", l
->item
[i
].line
);
274 fputs_filtered (paddress (gdbarch
, l
->item
[i
].pc
), outfile
);
275 if (l
->item
[i
].is_stmt
)
276 fprintf_filtered (outfile
, "\t(stmt)");
277 fprintf_filtered (outfile
, "\n");
280 /* Now print the block info, but only for compunit symtabs since we will
281 print lots of duplicate info otherwise. */
282 if (is_main_symtab_of_compunit_symtab (symtab
))
284 fprintf_filtered (outfile
, "\nBlockvector:\n\n");
285 bv
= SYMTAB_BLOCKVECTOR (symtab
);
286 len
= BLOCKVECTOR_NBLOCKS (bv
);
287 for (i
= 0; i
< len
; i
++)
289 b
= BLOCKVECTOR_BLOCK (bv
, i
);
290 depth
= block_depth (b
) * 2;
291 print_spaces (depth
, outfile
);
292 fprintf_filtered (outfile
, "block #%03d, object at ", i
);
293 gdb_print_host_address (b
, outfile
);
294 if (BLOCK_SUPERBLOCK (b
))
296 fprintf_filtered (outfile
, " under ");
297 gdb_print_host_address (BLOCK_SUPERBLOCK (b
), outfile
);
299 /* drow/2002-07-10: We could save the total symbols count
300 even if we're using a hashtable, but nothing else but this message
302 fprintf_filtered (outfile
, ", %d syms/buckets in ",
303 mdict_size (BLOCK_MULTIDICT (b
)));
304 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), outfile
);
305 fprintf_filtered (outfile
, "..");
306 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), outfile
);
307 if (BLOCK_FUNCTION (b
))
309 fprintf_filtered (outfile
, ", function %s",
310 BLOCK_FUNCTION (b
)->linkage_name ());
311 if (BLOCK_FUNCTION (b
)->demangled_name () != NULL
)
313 fprintf_filtered (outfile
, ", %s",
314 BLOCK_FUNCTION (b
)->demangled_name ());
317 fprintf_filtered (outfile
, "\n");
318 /* Now print each symbol in this block (in no particular order, if
319 we're using a hashtable). Note that we only want this
320 block, not any blocks from included symtabs. */
321 ALL_DICT_SYMBOLS (BLOCK_MULTIDICT (b
), miter
, sym
)
325 print_symbol (gdbarch
, sym
, depth
+ 1, outfile
);
327 catch (const gdb_exception_error
&ex
)
329 exception_fprintf (gdb_stderr
, ex
,
330 "Error printing symbol:\n");
334 fprintf_filtered (outfile
, "\n");
338 const char *compunit_filename
339 = symtab_to_filename_for_display (COMPUNIT_FILETABS (SYMTAB_COMPUNIT (symtab
)));
341 fprintf_filtered (outfile
,
342 "\nBlockvector same as owning compunit: %s\n\n",
346 /* Print info about the user of this compunit_symtab, and the
347 compunit_symtabs included by this one. */
348 if (is_main_symtab_of_compunit_symtab (symtab
))
350 struct compunit_symtab
*cust
= SYMTAB_COMPUNIT (symtab
);
352 if (cust
->user
!= nullptr)
355 = host_address_to_string (COMPUNIT_FILETABS (cust
->user
));
356 fprintf_filtered (outfile
, "Compunit user: %s\n", addr
);
358 if (cust
->includes
!= nullptr)
361 struct compunit_symtab
*include
= cust
->includes
[i
];
362 if (include
== nullptr)
365 = host_address_to_string (COMPUNIT_FILETABS (include
));
366 fprintf_filtered (outfile
, "Compunit include: %s\n", addr
);
372 dump_symtab (struct symtab
*symtab
, struct ui_file
*outfile
)
374 /* Set the current language to the language of the symtab we're dumping
375 because certain routines used during dump_symtab() use the current
376 language to print an image of the symbol. We'll restore it later.
377 But use only real languages, not placeholders. */
378 if (symtab
->language
!= language_unknown
379 && symtab
->language
!= language_auto
)
381 scoped_restore_current_language save_lang
;
382 set_language (symtab
->language
);
383 dump_symtab_1 (symtab
, outfile
);
386 dump_symtab_1 (symtab
, outfile
);
390 maintenance_print_symbols (const char *args
, int from_tty
)
392 struct ui_file
*outfile
= gdb_stdout
;
393 char *address_arg
= NULL
, *source_arg
= NULL
, *objfile_arg
= NULL
;
398 gdb_argv
argv (args
);
400 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
402 if (strcmp (argv
[i
], "-pc") == 0)
404 if (argv
[i
+ 1] == NULL
)
405 error (_("Missing pc value"));
406 address_arg
= argv
[++i
];
408 else if (strcmp (argv
[i
], "-source") == 0)
410 if (argv
[i
+ 1] == NULL
)
411 error (_("Missing source file"));
412 source_arg
= argv
[++i
];
414 else if (strcmp (argv
[i
], "-objfile") == 0)
416 if (argv
[i
+ 1] == NULL
)
417 error (_("Missing objfile name"));
418 objfile_arg
= argv
[++i
];
420 else if (strcmp (argv
[i
], "--") == 0)
422 /* End of options. */
426 else if (argv
[i
][0] == '-')
428 /* Future proofing: Don't allow OUTFILE to begin with "-". */
429 error (_("Unknown option: %s"), argv
[i
]);
436 if (address_arg
!= NULL
&& source_arg
!= NULL
)
437 error (_("Must specify at most one of -pc and -source"));
439 stdio_file arg_outfile
;
441 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
443 if (argv
[outfile_idx
+ 1] != NULL
)
444 error (_("Junk at end of command"));
445 gdb::unique_xmalloc_ptr
<char> outfile_name
446 (tilde_expand (argv
[outfile_idx
]));
447 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
448 perror_with_name (outfile_name
.get ());
449 outfile
= &arg_outfile
;
452 if (address_arg
!= NULL
)
454 CORE_ADDR pc
= parse_and_eval_address (address_arg
);
455 struct symtab
*s
= find_pc_line_symtab (pc
);
458 error (_("No symtab for address: %s"), address_arg
);
459 dump_symtab (s
, outfile
);
465 for (objfile
*objfile
: current_program_space
->objfiles ())
467 int print_for_objfile
= 1;
469 if (objfile_arg
!= NULL
)
471 = compare_filenames_for_search (objfile_name (objfile
),
473 if (!print_for_objfile
)
476 for (compunit_symtab
*cu
: objfile
->compunits ())
478 for (symtab
*s
: compunit_filetabs (cu
))
480 int print_for_source
= 0;
483 if (source_arg
!= NULL
)
486 = compare_filenames_for_search
487 (symtab_to_filename_for_display (s
), source_arg
);
490 if (source_arg
== NULL
492 dump_symtab (s
, outfile
);
497 if (source_arg
!= NULL
&& !found
)
498 error (_("No symtab for source file: %s"), source_arg
);
502 /* Print symbol SYMBOL on OUTFILE. DEPTH says how far to indent. */
505 print_symbol (struct gdbarch
*gdbarch
, struct symbol
*symbol
,
506 int depth
, ui_file
*outfile
)
508 struct obj_section
*section
;
510 if (SYMBOL_OBJFILE_OWNED (symbol
))
511 section
= symbol
->obj_section (symbol_objfile (symbol
));
515 print_spaces (depth
, outfile
);
516 if (SYMBOL_DOMAIN (symbol
) == LABEL_DOMAIN
)
518 fprintf_filtered (outfile
, "label %s at ", symbol
->print_name ());
519 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
522 fprintf_filtered (outfile
, " section %s\n",
523 bfd_section_name (section
->the_bfd_section
));
525 fprintf_filtered (outfile
, "\n");
529 if (SYMBOL_DOMAIN (symbol
) == STRUCT_DOMAIN
)
531 if (SYMBOL_TYPE (symbol
)->name ())
533 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
,
534 &type_print_raw_options
);
538 fprintf_filtered (outfile
, "%s %s = ",
539 (SYMBOL_TYPE (symbol
)->code () == TYPE_CODE_ENUM
541 : (SYMBOL_TYPE (symbol
)->code () == TYPE_CODE_STRUCT
542 ? "struct" : "union")),
543 symbol
->linkage_name ());
544 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
,
545 &type_print_raw_options
);
547 fprintf_filtered (outfile
, ";\n");
551 if (SYMBOL_CLASS (symbol
) == LOC_TYPEDEF
)
552 fprintf_filtered (outfile
, "typedef ");
553 if (SYMBOL_TYPE (symbol
))
555 /* Print details of types, except for enums where it's clutter. */
556 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), symbol
->print_name (),
558 SYMBOL_TYPE (symbol
)->code () != TYPE_CODE_ENUM
,
560 &type_print_raw_options
);
561 fprintf_filtered (outfile
, "; ");
564 fprintf_filtered (outfile
, "%s ", symbol
->print_name ());
566 switch (SYMBOL_CLASS (symbol
))
569 fprintf_filtered (outfile
, "const %s (%s)",
570 plongest (SYMBOL_VALUE (symbol
)),
571 hex_string (SYMBOL_VALUE (symbol
)));
574 case LOC_CONST_BYTES
:
577 struct type
*type
= check_typedef (SYMBOL_TYPE (symbol
));
579 fprintf_filtered (outfile
, "const %s hex bytes:",
580 pulongest (TYPE_LENGTH (type
)));
581 for (i
= 0; i
< TYPE_LENGTH (type
); i
++)
582 fprintf_filtered (outfile
, " %02x",
583 (unsigned) SYMBOL_VALUE_BYTES (symbol
)[i
]);
588 fprintf_filtered (outfile
, "static at ");
589 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
592 fprintf_filtered (outfile
, " section %s",
593 bfd_section_name (section
->the_bfd_section
));
597 if (SYMBOL_IS_ARGUMENT (symbol
))
598 fprintf_filtered (outfile
, "parameter register %s",
599 plongest (SYMBOL_VALUE (symbol
)));
601 fprintf_filtered (outfile
, "register %s",
602 plongest (SYMBOL_VALUE (symbol
)));
606 fprintf_filtered (outfile
, "arg at offset %s",
607 hex_string (SYMBOL_VALUE (symbol
)));
611 fprintf_filtered (outfile
, "reference arg at %s",
612 hex_string (SYMBOL_VALUE (symbol
)));
615 case LOC_REGPARM_ADDR
:
616 fprintf_filtered (outfile
, "address parameter register %s",
617 plongest (SYMBOL_VALUE (symbol
)));
621 fprintf_filtered (outfile
, "local at offset %s",
622 hex_string (SYMBOL_VALUE (symbol
)));
629 fprintf_filtered (outfile
, "label at ");
630 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
633 fprintf_filtered (outfile
, " section %s",
634 bfd_section_name (section
->the_bfd_section
));
638 fprintf_filtered (outfile
, "block object ");
639 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol
), outfile
);
640 fprintf_filtered (outfile
, ", ");
641 fputs_filtered (paddress (gdbarch
,
642 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
))),
644 fprintf_filtered (outfile
, "..");
645 fputs_filtered (paddress (gdbarch
,
646 BLOCK_END (SYMBOL_BLOCK_VALUE (symbol
))),
649 fprintf_filtered (outfile
, " section %s",
650 bfd_section_name (section
->the_bfd_section
));
654 fprintf_filtered (outfile
, "computed at runtime");
658 fprintf_filtered (outfile
, "unresolved");
661 case LOC_OPTIMIZED_OUT
:
662 fprintf_filtered (outfile
, "optimized out");
666 fprintf_filtered (outfile
, "botched symbol class %x",
667 SYMBOL_CLASS (symbol
));
671 fprintf_filtered (outfile
, "\n");
675 maintenance_print_msymbols (const char *args
, int from_tty
)
677 struct ui_file
*outfile
= gdb_stdout
;
678 char *objfile_arg
= NULL
;
683 gdb_argv
argv (args
);
685 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
687 if (strcmp (argv
[i
], "-objfile") == 0)
689 if (argv
[i
+ 1] == NULL
)
690 error (_("Missing objfile name"));
691 objfile_arg
= argv
[++i
];
693 else if (strcmp (argv
[i
], "--") == 0)
695 /* End of options. */
699 else if (argv
[i
][0] == '-')
701 /* Future proofing: Don't allow OUTFILE to begin with "-". */
702 error (_("Unknown option: %s"), argv
[i
]);
709 stdio_file arg_outfile
;
711 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
713 if (argv
[outfile_idx
+ 1] != NULL
)
714 error (_("Junk at end of command"));
715 gdb::unique_xmalloc_ptr
<char> outfile_name
716 (tilde_expand (argv
[outfile_idx
]));
717 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
718 perror_with_name (outfile_name
.get ());
719 outfile
= &arg_outfile
;
722 for (objfile
*objfile
: current_program_space
->objfiles ())
725 if (objfile_arg
== NULL
726 || compare_filenames_for_search (objfile_name (objfile
), objfile_arg
))
727 dump_msymbols (objfile
, outfile
);
732 maintenance_print_objfiles (const char *regexp
, int from_tty
)
739 for (struct program_space
*pspace
: program_spaces
)
740 for (objfile
*objfile
: pspace
->objfiles ())
744 || re_exec (objfile_name (objfile
)))
745 dump_objfile (objfile
);
749 /* List all the symbol tables whose names match REGEXP (optional). */
752 maintenance_info_symtabs (const char *regexp
, int from_tty
)
759 for (struct program_space
*pspace
: program_spaces
)
760 for (objfile
*objfile
: pspace
->objfiles ())
762 /* We don't want to print anything for this objfile until we
763 actually find a symtab whose name matches. */
764 int printed_objfile_start
= 0;
766 for (compunit_symtab
*cust
: objfile
->compunits ())
768 int printed_compunit_symtab_start
= 0;
770 for (symtab
*symtab
: compunit_filetabs (cust
))
775 || re_exec (symtab_to_filename_for_display (symtab
)))
777 if (! printed_objfile_start
)
779 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
781 printf_filtered ("((struct objfile *) %s)\n",
782 host_address_to_string (objfile
));
783 printed_objfile_start
= 1;
785 if (! printed_compunit_symtab_start
)
787 printf_filtered (" { ((struct compunit_symtab *) %s)\n",
788 host_address_to_string (cust
));
789 printf_filtered (" debugformat %s\n",
790 COMPUNIT_DEBUGFORMAT (cust
));
791 printf_filtered (" producer %s\n",
792 COMPUNIT_PRODUCER (cust
) != NULL
793 ? COMPUNIT_PRODUCER (cust
)
795 printf_filtered (" dirname %s\n",
796 COMPUNIT_DIRNAME (cust
) != NULL
797 ? COMPUNIT_DIRNAME (cust
)
799 printf_filtered (" blockvector"
800 " ((struct blockvector *) %s)\n",
801 host_address_to_string
802 (COMPUNIT_BLOCKVECTOR (cust
)));
803 printf_filtered (" user"
804 " ((struct compunit_symtab *) %s)\n",
805 cust
->user
!= nullptr
806 ? host_address_to_string (cust
->user
)
808 if (cust
->includes
!= nullptr)
810 printf_filtered (" ( includes\n");
811 for (int i
= 0; ; ++i
)
813 struct compunit_symtab
*include
815 if (include
== nullptr)
818 = host_address_to_string (include
);
819 printf_filtered (" (%s %s)\n",
820 "(struct compunit_symtab *)",
823 printf_filtered (" )\n");
825 printed_compunit_symtab_start
= 1;
828 printf_filtered ("\t{ symtab %s ",
829 symtab_to_filename_for_display (symtab
));
831 printf_filtered ("((struct symtab *) %s)\n",
832 host_address_to_string (symtab
));
833 printf_filtered ("\t fullname %s\n",
834 symtab
->fullname
!= NULL
837 printf_filtered ("\t "
838 "linetable ((struct linetable *) %s)\n",
839 host_address_to_string (symtab
->linetable
));
840 printf_filtered ("\t}\n");
844 if (printed_compunit_symtab_start
)
845 printf_filtered (" }\n");
848 if (printed_objfile_start
)
849 printf_filtered ("}\n");
853 /* Check consistency of symtabs.
854 An example of what this checks for is NULL blockvectors.
855 They can happen if there's a bug during debug info reading.
856 GDB assumes they are always non-NULL.
858 Note: This does not check for psymtab vs symtab consistency.
859 Use "maint check-psymtabs" for that. */
862 maintenance_check_symtabs (const char *ignore
, int from_tty
)
864 for (struct program_space
*pspace
: program_spaces
)
865 for (objfile
*objfile
: pspace
->objfiles ())
867 /* We don't want to print anything for this objfile until we
868 actually find something worth printing. */
869 int printed_objfile_start
= 0;
871 for (compunit_symtab
*cust
: objfile
->compunits ())
873 int found_something
= 0;
874 struct symtab
*symtab
= compunit_primary_filetab (cust
);
878 if (COMPUNIT_BLOCKVECTOR (cust
) == NULL
)
880 /* Add more checks here. */
884 if (! printed_objfile_start
)
886 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
888 printf_filtered ("((struct objfile *) %s)\n",
889 host_address_to_string (objfile
));
890 printed_objfile_start
= 1;
892 printf_filtered (" { symtab %s\n",
893 symtab_to_filename_for_display (symtab
));
894 if (COMPUNIT_BLOCKVECTOR (cust
) == NULL
)
895 printf_filtered (" NULL blockvector\n");
896 printf_filtered (" }\n");
900 if (printed_objfile_start
)
901 printf_filtered ("}\n");
905 /* Expand all symbol tables whose name matches an optional regexp. */
908 maintenance_expand_symtabs (const char *args
, int from_tty
)
912 /* We use buildargv here so that we handle spaces in the regexp
913 in a way that allows adding more arguments later. */
914 gdb_argv
argv (args
);
922 error (_("Extra arguments after regexp."));
929 for (struct program_space
*pspace
: program_spaces
)
930 for (objfile
*objfile
: pspace
->objfiles ())
931 objfile
->expand_symtabs_matching
932 ([&] (const char *filename
, bool basenames
)
934 /* KISS: Only apply the regexp to the complete file name. */
936 && (regexp
== NULL
|| re_exec (filename
)));
941 SEARCH_GLOBAL_BLOCK
| SEARCH_STATIC_BLOCK
,
947 /* Return the nexting depth of a block within other blocks in its symtab. */
950 block_depth (const struct block
*block
)
954 while ((block
= BLOCK_SUPERBLOCK (block
)) != NULL
)
962 /* Used by MAINTENANCE_INFO_LINE_TABLES to print the information about a
963 single line table. */
966 maintenance_print_one_line_table (struct symtab
*symtab
, void *data
)
968 struct linetable
*linetable
;
969 struct objfile
*objfile
;
971 objfile
= symtab
->compunit_symtab
->objfile
;
972 printf_filtered (_("objfile: %s ((struct objfile *) %s)\n"),
973 objfile_name (objfile
),
974 host_address_to_string (objfile
));
975 printf_filtered (_("compunit_symtab: ((struct compunit_symtab *) %s)\n"),
976 host_address_to_string (symtab
->compunit_symtab
));
977 printf_filtered (_("symtab: %s ((struct symtab *) %s)\n"),
978 symtab_to_fullname (symtab
),
979 host_address_to_string (symtab
));
980 linetable
= SYMTAB_LINETABLE (symtab
);
981 printf_filtered (_("linetable: ((struct linetable *) %s):\n"),
982 host_address_to_string (linetable
));
984 if (linetable
== NULL
)
985 printf_filtered (_("No line table.\n"));
986 else if (linetable
->nitems
<= 0)
987 printf_filtered (_("Line table has no lines.\n"));
990 /* Leave space for 6 digits of index and line number. After that the
991 tables will just not format as well. */
992 struct ui_out
*uiout
= current_uiout
;
993 ui_out_emit_table
table_emitter (uiout
, 4, -1, "line-table");
994 uiout
->table_header (6, ui_left
, "index", _("INDEX"));
995 uiout
->table_header (6, ui_left
, "line", _("LINE"));
996 uiout
->table_header (18, ui_left
, "address", _("ADDRESS"));
997 uiout
->table_header (1, ui_left
, "is-stmt", _("IS-STMT"));
998 uiout
->table_body ();
1000 for (int i
= 0; i
< linetable
->nitems
; ++i
)
1002 struct linetable_entry
*item
;
1004 item
= &linetable
->item
[i
];
1005 ui_out_emit_tuple
tuple_emitter (uiout
, nullptr);
1006 uiout
->field_signed ("index", i
);
1008 uiout
->field_signed ("line", item
->line
);
1010 uiout
->field_string ("line", _("END"));
1011 uiout
->field_core_addr ("address", objfile
->arch (),
1013 uiout
->field_string ("is-stmt", item
->is_stmt
? "Y" : "");
1021 /* Implement the 'maint info line-table' command. */
1024 maintenance_info_line_tables (const char *regexp
, int from_tty
)
1031 for (struct program_space
*pspace
: program_spaces
)
1032 for (objfile
*objfile
: pspace
->objfiles ())
1034 for (compunit_symtab
*cust
: objfile
->compunits ())
1036 for (symtab
*symtab
: compunit_filetabs (cust
))
1041 || re_exec (symtab_to_filename_for_display (symtab
)))
1042 maintenance_print_one_line_table (symtab
, NULL
);
1050 /* Do early runtime initializations. */
1052 void _initialize_symmisc ();
1054 _initialize_symmisc ()
1056 add_cmd ("symbols", class_maintenance
, maintenance_print_symbols
, _("\
1057 Print dump of current symbol definitions.\n\
1058 Usage: mt print symbols [-pc ADDRESS] [--] [OUTFILE]\n\
1059 mt print symbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
1060 Entries in the full symbol table are dumped to file OUTFILE,\n\
1061 or the terminal if OUTFILE is unspecified.\n\
1062 If ADDRESS is provided, dump only the file for that address.\n\
1063 If SOURCE is provided, dump only that file's symbols.\n\
1064 If OBJFILE is provided, dump only that file's minimal symbols."),
1065 &maintenanceprintlist
);
1067 add_cmd ("msymbols", class_maintenance
, maintenance_print_msymbols
, _("\
1068 Print dump of current minimal symbol definitions.\n\
1069 Usage: mt print msymbols [-objfile OBJFILE] [--] [OUTFILE]\n\
1070 Entries in the minimal symbol table are dumped to file OUTFILE,\n\
1071 or the terminal if OUTFILE is unspecified.\n\
1072 If OBJFILE is provided, dump only that file's minimal symbols."),
1073 &maintenanceprintlist
);
1075 add_cmd ("objfiles", class_maintenance
, maintenance_print_objfiles
,
1076 _("Print dump of current object file definitions.\n\
1077 With an argument REGEXP, list the object files with matching names."),
1078 &maintenanceprintlist
);
1080 add_cmd ("symtabs", class_maintenance
, maintenance_info_symtabs
, _("\
1081 List the full symbol tables for all object files.\n\
1082 This does not include information about individual symbols, blocks, or\n\
1083 linetables --- just the symbol table structures themselves.\n\
1084 With an argument REGEXP, list the symbol tables with matching names."),
1085 &maintenanceinfolist
);
1087 add_cmd ("line-table", class_maintenance
, maintenance_info_line_tables
, _("\
1088 List the contents of all line tables, from all symbol tables.\n\
1089 With an argument REGEXP, list just the line tables for the symbol\n\
1090 tables with matching names."),
1091 &maintenanceinfolist
);
1093 add_cmd ("check-symtabs", class_maintenance
, maintenance_check_symtabs
,
1095 Check consistency of currently expanded symtabs."),
1098 add_cmd ("expand-symtabs", class_maintenance
, maintenance_expand_symtabs
,
1099 _("Expand symbol tables.\n\
1100 With an argument REGEXP, only expand the symbol tables with matching names."),