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 for (struct program_space
*pspace
: program_spaces
)
65 for (objfile
*objfile
: pspace
->objfiles ())
68 printf_filtered (_("Byte cache statistics for '%s':\n"),
69 objfile_name (objfile
));
70 objfile
->partial_symtabs
->psymbol_cache
.print_statistics
71 ("partial symbol cache");
72 objfile
->per_bfd
->string_cache
.print_statistics ("string cache");
77 print_objfile_statistics (void)
79 int i
, linetables
, blockvectors
;
81 for (struct program_space
*pspace
: program_spaces
)
82 for (objfile
*objfile
: pspace
->objfiles ())
85 printf_filtered (_("Statistics for '%s':\n"), objfile_name (objfile
));
86 if (OBJSTAT (objfile
, n_stabs
) > 0)
87 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
88 OBJSTAT (objfile
, n_stabs
));
89 if (objfile
->per_bfd
->n_minsyms
> 0)
90 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
91 objfile
->per_bfd
->n_minsyms
);
92 if (OBJSTAT (objfile
, n_psyms
) > 0)
93 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
94 OBJSTAT (objfile
, n_psyms
));
95 if (OBJSTAT (objfile
, n_syms
) > 0)
96 printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
97 OBJSTAT (objfile
, n_syms
));
98 if (OBJSTAT (objfile
, n_types
) > 0)
99 printf_filtered (_(" Number of \"types\" defined: %d\n"),
100 OBJSTAT (objfile
, n_types
));
102 objfile
->sf
->qf
->print_stats (objfile
);
104 for (compunit_symtab
*cu
: objfile
->compunits ())
106 for (symtab
*s
: compunit_filetabs (cu
))
109 if (SYMTAB_LINETABLE (s
) != NULL
)
113 blockvectors
= std::distance (objfile
->compunits ().begin (),
114 objfile
->compunits ().end ());
115 printf_filtered (_(" Number of symbol tables: %d\n"), i
);
116 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
118 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
121 if (OBJSTAT (objfile
, sz_strtab
) > 0)
122 printf_filtered (_(" Space used by string tables: %d\n"),
123 OBJSTAT (objfile
, sz_strtab
));
124 printf_filtered (_(" Total memory used for objfile obstack: %s\n"),
125 pulongest (obstack_memory_used (&objfile
126 ->objfile_obstack
)));
127 printf_filtered (_(" Total memory used for BFD obstack: %s\n"),
128 pulongest (obstack_memory_used (&objfile
->per_bfd
129 ->storage_obstack
)));
131 (_(" Total memory used for psymbol cache: %d\n"),
132 objfile
->partial_symtabs
->psymbol_cache
.memory_used ());
133 printf_filtered (_(" Total memory used for string cache: %d\n"),
134 objfile
->per_bfd
->string_cache
.memory_used ());
139 dump_objfile (struct objfile
*objfile
)
141 printf_filtered ("\nObject file %s: ", objfile_name (objfile
));
142 printf_filtered ("Objfile at ");
143 gdb_print_host_address (objfile
, gdb_stdout
);
144 printf_filtered (", bfd at ");
145 gdb_print_host_address (objfile
->obfd
, gdb_stdout
);
146 printf_filtered (", %d minsyms\n\n",
147 objfile
->per_bfd
->minimal_symbol_count
);
150 objfile
->sf
->qf
->dump (objfile
);
152 if (objfile
->compunit_symtabs
!= NULL
)
154 printf_filtered ("Symtabs:\n");
155 for (compunit_symtab
*cu
: objfile
->compunits ())
157 for (symtab
*symtab
: compunit_filetabs (cu
))
159 printf_filtered ("%s at ",
160 symtab_to_filename_for_display (symtab
));
161 gdb_print_host_address (symtab
, gdb_stdout
);
162 printf_filtered (", ");
163 if (SYMTAB_OBJFILE (symtab
) != objfile
)
165 printf_filtered ("NOT ON CHAIN! ");
170 printf_filtered ("\n\n");
174 /* Print minimal symbols from this objfile. */
177 dump_msymbols (struct objfile
*objfile
, struct ui_file
*outfile
)
179 struct gdbarch
*gdbarch
= objfile
->arch ();
183 fprintf_filtered (outfile
, "\nObject file %s:\n\n", objfile_name (objfile
));
184 if (objfile
->per_bfd
->minimal_symbol_count
== 0)
186 fprintf_filtered (outfile
, "No minimal symbols found.\n");
190 for (minimal_symbol
*msymbol
: objfile
->msymbols ())
192 struct obj_section
*section
= MSYMBOL_OBJ_SECTION (objfile
, msymbol
);
194 switch (MSYMBOL_TYPE (msymbol
))
202 case mst_text_gnu_ifunc
:
203 case mst_data_gnu_ifunc
:
206 case mst_solib_trampoline
:
231 fprintf_filtered (outfile
, "[%2d] %c ", index
, ms_type
);
233 /* Use the relocated address as shown in the symbol here -- do
234 not try to respect copy relocations. */
235 CORE_ADDR addr
= (msymbol
->value
.address
236 + objfile
->section_offsets
[msymbol
->section
]);
237 fputs_filtered (paddress (gdbarch
, addr
), outfile
);
238 fprintf_filtered (outfile
, " %s", msymbol
->linkage_name ());
241 if (section
->the_bfd_section
!= NULL
)
242 fprintf_filtered (outfile
, " section %s",
243 bfd_section_name (section
->the_bfd_section
));
245 fprintf_filtered (outfile
, " spurious section %ld",
246 (long) (section
- objfile
->sections
));
248 if (msymbol
->demangled_name () != NULL
)
250 fprintf_filtered (outfile
, " %s", msymbol
->demangled_name ());
252 if (msymbol
->filename
)
253 fprintf_filtered (outfile
, " %s", msymbol
->filename
);
254 fputs_filtered ("\n", outfile
);
257 if (objfile
->per_bfd
->minimal_symbol_count
!= index
)
259 warning (_("internal error: minimal symbol count %d != %d"),
260 objfile
->per_bfd
->minimal_symbol_count
, index
);
262 fprintf_filtered (outfile
, "\n");
266 dump_symtab_1 (struct symtab
*symtab
, struct ui_file
*outfile
)
268 struct objfile
*objfile
= SYMTAB_OBJFILE (symtab
);
269 struct gdbarch
*gdbarch
= objfile
->arch ();
271 struct mdict_iterator miter
;
274 const struct blockvector
*bv
;
276 const struct block
*b
;
279 fprintf_filtered (outfile
, "\nSymtab for file %s at %s\n",
280 symtab_to_filename_for_display (symtab
),
281 host_address_to_string (symtab
));
283 if (SYMTAB_DIRNAME (symtab
) != NULL
)
284 fprintf_filtered (outfile
, "Compilation directory is %s\n",
285 SYMTAB_DIRNAME (symtab
));
286 fprintf_filtered (outfile
, "Read from object file %s (",
287 objfile_name (objfile
));
288 gdb_print_host_address (objfile
, outfile
);
289 fprintf_filtered (outfile
, ")\n");
290 fprintf_filtered (outfile
, "Language: %s\n",
291 language_str (symtab
->language
));
293 /* First print the line table. */
294 l
= SYMTAB_LINETABLE (symtab
);
297 fprintf_filtered (outfile
, "\nLine table:\n\n");
299 for (i
= 0; i
< len
; i
++)
301 fprintf_filtered (outfile
, " line %d at ", l
->item
[i
].line
);
302 fputs_filtered (paddress (gdbarch
, l
->item
[i
].pc
), outfile
);
303 if (l
->item
[i
].is_stmt
)
304 fprintf_filtered (outfile
, "\t(stmt)");
305 fprintf_filtered (outfile
, "\n");
308 /* Now print the block info, but only for compunit symtabs since we will
309 print lots of duplicate info otherwise. */
310 if (is_main_symtab_of_compunit_symtab (symtab
))
312 fprintf_filtered (outfile
, "\nBlockvector:\n\n");
313 bv
= SYMTAB_BLOCKVECTOR (symtab
);
314 len
= BLOCKVECTOR_NBLOCKS (bv
);
315 for (i
= 0; i
< len
; i
++)
317 b
= BLOCKVECTOR_BLOCK (bv
, i
);
318 depth
= block_depth (b
) * 2;
319 print_spaces (depth
, outfile
);
320 fprintf_filtered (outfile
, "block #%03d, object at ", i
);
321 gdb_print_host_address (b
, outfile
);
322 if (BLOCK_SUPERBLOCK (b
))
324 fprintf_filtered (outfile
, " under ");
325 gdb_print_host_address (BLOCK_SUPERBLOCK (b
), outfile
);
327 /* drow/2002-07-10: We could save the total symbols count
328 even if we're using a hashtable, but nothing else but this message
330 fprintf_filtered (outfile
, ", %d syms/buckets in ",
331 mdict_size (BLOCK_MULTIDICT (b
)));
332 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), outfile
);
333 fprintf_filtered (outfile
, "..");
334 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), outfile
);
335 if (BLOCK_FUNCTION (b
))
337 fprintf_filtered (outfile
, ", function %s",
338 BLOCK_FUNCTION (b
)->linkage_name ());
339 if (BLOCK_FUNCTION (b
)->demangled_name () != NULL
)
341 fprintf_filtered (outfile
, ", %s",
342 BLOCK_FUNCTION (b
)->demangled_name ());
345 fprintf_filtered (outfile
, "\n");
346 /* Now print each symbol in this block (in no particular order, if
347 we're using a hashtable). Note that we only want this
348 block, not any blocks from included symtabs. */
349 ALL_DICT_SYMBOLS (BLOCK_MULTIDICT (b
), miter
, sym
)
353 print_symbol (gdbarch
, sym
, depth
+ 1, outfile
);
355 catch (const gdb_exception_error
&ex
)
357 exception_fprintf (gdb_stderr
, ex
,
358 "Error printing symbol:\n");
362 fprintf_filtered (outfile
, "\n");
366 const char *compunit_filename
367 = symtab_to_filename_for_display (COMPUNIT_FILETABS (SYMTAB_COMPUNIT (symtab
)));
369 fprintf_filtered (outfile
,
370 "\nBlockvector same as owning compunit: %s\n\n",
374 /* Print info about the user of this compunit_symtab, and the
375 compunit_symtabs included by this one. */
376 if (is_main_symtab_of_compunit_symtab (symtab
))
378 struct compunit_symtab
*cust
= SYMTAB_COMPUNIT (symtab
);
380 if (cust
->user
!= nullptr)
383 = host_address_to_string (COMPUNIT_FILETABS (cust
->user
));
384 fprintf_filtered (outfile
, "Compunit user: %s\n", addr
);
386 if (cust
->includes
!= nullptr)
389 struct compunit_symtab
*include
= cust
->includes
[i
];
390 if (include
== nullptr)
393 = host_address_to_string (COMPUNIT_FILETABS (include
));
394 fprintf_filtered (outfile
, "Compunit include: %s\n", addr
);
400 dump_symtab (struct symtab
*symtab
, struct ui_file
*outfile
)
402 /* Set the current language to the language of the symtab we're dumping
403 because certain routines used during dump_symtab() use the current
404 language to print an image of the symbol. We'll restore it later.
405 But use only real languages, not placeholders. */
406 if (symtab
->language
!= language_unknown
407 && symtab
->language
!= language_auto
)
409 scoped_restore_current_language save_lang
;
410 set_language (symtab
->language
);
411 dump_symtab_1 (symtab
, outfile
);
414 dump_symtab_1 (symtab
, outfile
);
418 maintenance_print_symbols (const char *args
, int from_tty
)
420 struct ui_file
*outfile
= gdb_stdout
;
421 char *address_arg
= NULL
, *source_arg
= NULL
, *objfile_arg
= NULL
;
426 gdb_argv
argv (args
);
428 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
430 if (strcmp (argv
[i
], "-pc") == 0)
432 if (argv
[i
+ 1] == NULL
)
433 error (_("Missing pc value"));
434 address_arg
= argv
[++i
];
436 else if (strcmp (argv
[i
], "-source") == 0)
438 if (argv
[i
+ 1] == NULL
)
439 error (_("Missing source file"));
440 source_arg
= argv
[++i
];
442 else if (strcmp (argv
[i
], "-objfile") == 0)
444 if (argv
[i
+ 1] == NULL
)
445 error (_("Missing objfile name"));
446 objfile_arg
= argv
[++i
];
448 else if (strcmp (argv
[i
], "--") == 0)
450 /* End of options. */
454 else if (argv
[i
][0] == '-')
456 /* Future proofing: Don't allow OUTFILE to begin with "-". */
457 error (_("Unknown option: %s"), argv
[i
]);
464 if (address_arg
!= NULL
&& source_arg
!= NULL
)
465 error (_("Must specify at most one of -pc and -source"));
467 stdio_file arg_outfile
;
469 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
471 if (argv
[outfile_idx
+ 1] != NULL
)
472 error (_("Junk at end of command"));
473 gdb::unique_xmalloc_ptr
<char> outfile_name
474 (tilde_expand (argv
[outfile_idx
]));
475 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
476 perror_with_name (outfile_name
.get ());
477 outfile
= &arg_outfile
;
480 if (address_arg
!= NULL
)
482 CORE_ADDR pc
= parse_and_eval_address (address_arg
);
483 struct symtab
*s
= find_pc_line_symtab (pc
);
486 error (_("No symtab for address: %s"), address_arg
);
487 dump_symtab (s
, outfile
);
493 for (objfile
*objfile
: current_program_space
->objfiles ())
495 int print_for_objfile
= 1;
497 if (objfile_arg
!= NULL
)
499 = compare_filenames_for_search (objfile_name (objfile
),
501 if (!print_for_objfile
)
504 for (compunit_symtab
*cu
: objfile
->compunits ())
506 for (symtab
*s
: compunit_filetabs (cu
))
508 int print_for_source
= 0;
511 if (source_arg
!= NULL
)
514 = compare_filenames_for_search
515 (symtab_to_filename_for_display (s
), source_arg
);
518 if (source_arg
== NULL
520 dump_symtab (s
, outfile
);
525 if (source_arg
!= NULL
&& !found
)
526 error (_("No symtab for source file: %s"), source_arg
);
530 /* Print symbol SYMBOL on OUTFILE. DEPTH says how far to indent. */
533 print_symbol (struct gdbarch
*gdbarch
, struct symbol
*symbol
,
534 int depth
, ui_file
*outfile
)
536 struct obj_section
*section
;
538 if (SYMBOL_OBJFILE_OWNED (symbol
))
539 section
= SYMBOL_OBJ_SECTION (symbol_objfile (symbol
), symbol
);
543 print_spaces (depth
, outfile
);
544 if (SYMBOL_DOMAIN (symbol
) == LABEL_DOMAIN
)
546 fprintf_filtered (outfile
, "label %s at ", symbol
->print_name ());
547 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
550 fprintf_filtered (outfile
, " section %s\n",
551 bfd_section_name (section
->the_bfd_section
));
553 fprintf_filtered (outfile
, "\n");
557 if (SYMBOL_DOMAIN (symbol
) == STRUCT_DOMAIN
)
559 if (TYPE_NAME (SYMBOL_TYPE (symbol
)))
561 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
,
562 &type_print_raw_options
);
566 fprintf_filtered (outfile
, "%s %s = ",
567 (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_ENUM
569 : (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_STRUCT
570 ? "struct" : "union")),
571 symbol
->linkage_name ());
572 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
,
573 &type_print_raw_options
);
575 fprintf_filtered (outfile
, ";\n");
579 if (SYMBOL_CLASS (symbol
) == LOC_TYPEDEF
)
580 fprintf_filtered (outfile
, "typedef ");
581 if (SYMBOL_TYPE (symbol
))
583 /* Print details of types, except for enums where it's clutter. */
584 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), symbol
->print_name (),
586 TYPE_CODE (SYMBOL_TYPE (symbol
)) != TYPE_CODE_ENUM
,
588 &type_print_raw_options
);
589 fprintf_filtered (outfile
, "; ");
592 fprintf_filtered (outfile
, "%s ", symbol
->print_name ());
594 switch (SYMBOL_CLASS (symbol
))
597 fprintf_filtered (outfile
, "const %s (%s)",
598 plongest (SYMBOL_VALUE (symbol
)),
599 hex_string (SYMBOL_VALUE (symbol
)));
602 case LOC_CONST_BYTES
:
605 struct type
*type
= check_typedef (SYMBOL_TYPE (symbol
));
607 fprintf_filtered (outfile
, "const %s hex bytes:",
608 pulongest (TYPE_LENGTH (type
)));
609 for (i
= 0; i
< TYPE_LENGTH (type
); i
++)
610 fprintf_filtered (outfile
, " %02x",
611 (unsigned) SYMBOL_VALUE_BYTES (symbol
)[i
]);
616 fprintf_filtered (outfile
, "static at ");
617 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
620 fprintf_filtered (outfile
, " section %s",
621 bfd_section_name (section
->the_bfd_section
));
625 if (SYMBOL_IS_ARGUMENT (symbol
))
626 fprintf_filtered (outfile
, "parameter register %s",
627 plongest (SYMBOL_VALUE (symbol
)));
629 fprintf_filtered (outfile
, "register %s",
630 plongest (SYMBOL_VALUE (symbol
)));
634 fprintf_filtered (outfile
, "arg at offset %s",
635 hex_string (SYMBOL_VALUE (symbol
)));
639 fprintf_filtered (outfile
, "reference arg at %s",
640 hex_string (SYMBOL_VALUE (symbol
)));
643 case LOC_REGPARM_ADDR
:
644 fprintf_filtered (outfile
, "address parameter register %s",
645 plongest (SYMBOL_VALUE (symbol
)));
649 fprintf_filtered (outfile
, "local at offset %s",
650 hex_string (SYMBOL_VALUE (symbol
)));
657 fprintf_filtered (outfile
, "label at ");
658 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
661 fprintf_filtered (outfile
, " section %s",
662 bfd_section_name (section
->the_bfd_section
));
666 fprintf_filtered (outfile
, "block object ");
667 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol
), outfile
);
668 fprintf_filtered (outfile
, ", ");
669 fputs_filtered (paddress (gdbarch
,
670 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
))),
672 fprintf_filtered (outfile
, "..");
673 fputs_filtered (paddress (gdbarch
,
674 BLOCK_END (SYMBOL_BLOCK_VALUE (symbol
))),
677 fprintf_filtered (outfile
, " section %s",
678 bfd_section_name (section
->the_bfd_section
));
682 fprintf_filtered (outfile
, "computed at runtime");
686 fprintf_filtered (outfile
, "unresolved");
689 case LOC_OPTIMIZED_OUT
:
690 fprintf_filtered (outfile
, "optimized out");
694 fprintf_filtered (outfile
, "botched symbol class %x",
695 SYMBOL_CLASS (symbol
));
699 fprintf_filtered (outfile
, "\n");
703 maintenance_print_msymbols (const char *args
, int from_tty
)
705 struct ui_file
*outfile
= gdb_stdout
;
706 char *objfile_arg
= NULL
;
711 gdb_argv
argv (args
);
713 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
715 if (strcmp (argv
[i
], "-objfile") == 0)
717 if (argv
[i
+ 1] == NULL
)
718 error (_("Missing objfile name"));
719 objfile_arg
= argv
[++i
];
721 else if (strcmp (argv
[i
], "--") == 0)
723 /* End of options. */
727 else if (argv
[i
][0] == '-')
729 /* Future proofing: Don't allow OUTFILE to begin with "-". */
730 error (_("Unknown option: %s"), argv
[i
]);
737 stdio_file arg_outfile
;
739 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
741 if (argv
[outfile_idx
+ 1] != NULL
)
742 error (_("Junk at end of command"));
743 gdb::unique_xmalloc_ptr
<char> outfile_name
744 (tilde_expand (argv
[outfile_idx
]));
745 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
746 perror_with_name (outfile_name
.get ());
747 outfile
= &arg_outfile
;
750 for (objfile
*objfile
: current_program_space
->objfiles ())
753 if (objfile_arg
== NULL
754 || compare_filenames_for_search (objfile_name (objfile
), objfile_arg
))
755 dump_msymbols (objfile
, outfile
);
760 maintenance_print_objfiles (const char *regexp
, int from_tty
)
767 for (struct program_space
*pspace
: program_spaces
)
768 for (objfile
*objfile
: pspace
->objfiles ())
772 || re_exec (objfile_name (objfile
)))
773 dump_objfile (objfile
);
777 /* List all the symbol tables whose names match REGEXP (optional). */
780 maintenance_info_symtabs (const char *regexp
, int from_tty
)
787 for (struct program_space
*pspace
: program_spaces
)
788 for (objfile
*objfile
: pspace
->objfiles ())
790 /* We don't want to print anything for this objfile until we
791 actually find a symtab whose name matches. */
792 int printed_objfile_start
= 0;
794 for (compunit_symtab
*cust
: objfile
->compunits ())
796 int printed_compunit_symtab_start
= 0;
798 for (symtab
*symtab
: compunit_filetabs (cust
))
803 || re_exec (symtab_to_filename_for_display (symtab
)))
805 if (! printed_objfile_start
)
807 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
809 printf_filtered ("((struct objfile *) %s)\n",
810 host_address_to_string (objfile
));
811 printed_objfile_start
= 1;
813 if (! printed_compunit_symtab_start
)
815 printf_filtered (" { ((struct compunit_symtab *) %s)\n",
816 host_address_to_string (cust
));
817 printf_filtered (" debugformat %s\n",
818 COMPUNIT_DEBUGFORMAT (cust
));
819 printf_filtered (" producer %s\n",
820 COMPUNIT_PRODUCER (cust
) != NULL
821 ? COMPUNIT_PRODUCER (cust
)
823 printf_filtered (" dirname %s\n",
824 COMPUNIT_DIRNAME (cust
) != NULL
825 ? COMPUNIT_DIRNAME (cust
)
827 printf_filtered (" blockvector"
828 " ((struct blockvector *) %s)\n",
829 host_address_to_string
830 (COMPUNIT_BLOCKVECTOR (cust
)));
831 printf_filtered (" user"
832 " ((struct compunit_symtab *) %s)\n",
833 cust
->user
!= nullptr
834 ? host_address_to_string (cust
->user
)
836 if (cust
->includes
!= nullptr)
838 printf_filtered (" ( includes\n");
839 for (int i
= 0; ; ++i
)
841 struct compunit_symtab
*include
843 if (include
== nullptr)
846 = host_address_to_string (include
);
847 printf_filtered (" (%s %s)\n",
848 "(struct compunit_symtab *)",
851 printf_filtered (" )\n");
853 printed_compunit_symtab_start
= 1;
856 printf_filtered ("\t{ symtab %s ",
857 symtab_to_filename_for_display (symtab
));
859 printf_filtered ("((struct symtab *) %s)\n",
860 host_address_to_string (symtab
));
861 printf_filtered ("\t fullname %s\n",
862 symtab
->fullname
!= NULL
865 printf_filtered ("\t "
866 "linetable ((struct linetable *) %s)\n",
867 host_address_to_string (symtab
->linetable
));
868 printf_filtered ("\t}\n");
872 if (printed_compunit_symtab_start
)
873 printf_filtered (" }\n");
876 if (printed_objfile_start
)
877 printf_filtered ("}\n");
881 /* Check consistency of symtabs.
882 An example of what this checks for is NULL blockvectors.
883 They can happen if there's a bug during debug info reading.
884 GDB assumes they are always non-NULL.
886 Note: This does not check for psymtab vs symtab consistency.
887 Use "maint check-psymtabs" for that. */
890 maintenance_check_symtabs (const char *ignore
, int from_tty
)
892 for (struct program_space
*pspace
: program_spaces
)
893 for (objfile
*objfile
: pspace
->objfiles ())
895 /* We don't want to print anything for this objfile until we
896 actually find something worth printing. */
897 int printed_objfile_start
= 0;
899 for (compunit_symtab
*cust
: objfile
->compunits ())
901 int found_something
= 0;
902 struct symtab
*symtab
= compunit_primary_filetab (cust
);
906 if (COMPUNIT_BLOCKVECTOR (cust
) == NULL
)
908 /* Add more checks here. */
912 if (! printed_objfile_start
)
914 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
916 printf_filtered ("((struct objfile *) %s)\n",
917 host_address_to_string (objfile
));
918 printed_objfile_start
= 1;
920 printf_filtered (" { symtab %s\n",
921 symtab_to_filename_for_display (symtab
));
922 if (COMPUNIT_BLOCKVECTOR (cust
) == NULL
)
923 printf_filtered (" NULL blockvector\n");
924 printf_filtered (" }\n");
928 if (printed_objfile_start
)
929 printf_filtered ("}\n");
933 /* Expand all symbol tables whose name matches an optional regexp. */
936 maintenance_expand_symtabs (const char *args
, int from_tty
)
940 /* We use buildargv here so that we handle spaces in the regexp
941 in a way that allows adding more arguments later. */
942 gdb_argv
argv (args
);
950 error (_("Extra arguments after regexp."));
957 for (struct program_space
*pspace
: program_spaces
)
958 for (objfile
*objfile
: pspace
->objfiles ())
962 objfile
->sf
->qf
->expand_symtabs_matching
964 [&] (const char *filename
, bool basenames
)
966 /* KISS: Only apply the regexp to the complete file name. */
968 && (regexp
== NULL
|| re_exec (filename
)));
979 /* Return the nexting depth of a block within other blocks in its symtab. */
982 block_depth (const struct block
*block
)
986 while ((block
= BLOCK_SUPERBLOCK (block
)) != NULL
)
994 /* Used by MAINTENANCE_INFO_LINE_TABLES to print the information about a
995 single line table. */
998 maintenance_print_one_line_table (struct symtab
*symtab
, void *data
)
1000 struct linetable
*linetable
;
1001 struct objfile
*objfile
;
1003 objfile
= symtab
->compunit_symtab
->objfile
;
1004 printf_filtered (_("objfile: %s ((struct objfile *) %s)\n"),
1005 objfile_name (objfile
),
1006 host_address_to_string (objfile
));
1007 printf_filtered (_("compunit_symtab: ((struct compunit_symtab *) %s)\n"),
1008 host_address_to_string (symtab
->compunit_symtab
));
1009 printf_filtered (_("symtab: %s ((struct symtab *) %s)\n"),
1010 symtab_to_fullname (symtab
),
1011 host_address_to_string (symtab
));
1012 linetable
= SYMTAB_LINETABLE (symtab
);
1013 printf_filtered (_("linetable: ((struct linetable *) %s):\n"),
1014 host_address_to_string (linetable
));
1016 if (linetable
== NULL
)
1017 printf_filtered (_("No line table.\n"));
1018 else if (linetable
->nitems
<= 0)
1019 printf_filtered (_("Line table has no lines.\n"));
1022 /* Leave space for 6 digits of index and line number. After that the
1023 tables will just not format as well. */
1024 struct ui_out
*uiout
= current_uiout
;
1025 ui_out_emit_table
table_emitter (uiout
, 4, -1, "line-table");
1026 uiout
->table_header (6, ui_left
, "index", _("INDEX"));
1027 uiout
->table_header (6, ui_left
, "line", _("LINE"));
1028 uiout
->table_header (18, ui_left
, "address", _("ADDRESS"));
1029 uiout
->table_header (1, ui_left
, "is-stmt", _("IS-STMT"));
1030 uiout
->table_body ();
1032 for (int i
= 0; i
< linetable
->nitems
; ++i
)
1034 struct linetable_entry
*item
;
1036 item
= &linetable
->item
[i
];
1037 ui_out_emit_tuple
tuple_emitter (uiout
, nullptr);
1038 uiout
->field_signed ("index", i
);
1040 uiout
->field_signed ("line", item
->line
);
1042 uiout
->field_string ("line", _("END"));
1043 uiout
->field_core_addr ("address", objfile
->arch (),
1045 uiout
->field_string ("is-stmt", item
->is_stmt
? "Y" : "");
1053 /* Implement the 'maint info line-table' command. */
1056 maintenance_info_line_tables (const char *regexp
, int from_tty
)
1063 for (struct program_space
*pspace
: program_spaces
)
1064 for (objfile
*objfile
: pspace
->objfiles ())
1066 for (compunit_symtab
*cust
: objfile
->compunits ())
1068 for (symtab
*symtab
: compunit_filetabs (cust
))
1073 || re_exec (symtab_to_filename_for_display (symtab
)))
1074 maintenance_print_one_line_table (symtab
, NULL
);
1082 /* Do early runtime initializations. */
1084 void _initialize_symmisc ();
1086 _initialize_symmisc ()
1092 add_cmd ("symbols", class_maintenance
, maintenance_print_symbols
, _("\
1093 Print dump of current symbol definitions.\n\
1094 Usage: mt print symbols [-pc ADDRESS] [--] [OUTFILE]\n\
1095 mt print symbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
1096 Entries in the full symbol table are dumped to file OUTFILE,\n\
1097 or the terminal if OUTFILE is unspecified.\n\
1098 If ADDRESS is provided, dump only the file for that address.\n\
1099 If SOURCE is provided, dump only that file's symbols.\n\
1100 If OBJFILE is provided, dump only that file's minimal symbols."),
1101 &maintenanceprintlist
);
1103 add_cmd ("msymbols", class_maintenance
, maintenance_print_msymbols
, _("\
1104 Print dump of current minimal symbol definitions.\n\
1105 Usage: mt print msymbols [-objfile OBJFILE] [--] [OUTFILE]\n\
1106 Entries in the minimal symbol table are dumped to file OUTFILE,\n\
1107 or the terminal if OUTFILE is unspecified.\n\
1108 If OBJFILE is provided, dump only that file's minimal symbols."),
1109 &maintenanceprintlist
);
1111 add_cmd ("objfiles", class_maintenance
, maintenance_print_objfiles
,
1112 _("Print dump of current object file definitions.\n\
1113 With an argument REGEXP, list the object files with matching names."),
1114 &maintenanceprintlist
);
1116 add_cmd ("symtabs", class_maintenance
, maintenance_info_symtabs
, _("\
1117 List the full symbol tables for all object files.\n\
1118 This does not include information about individual symbols, blocks, or\n\
1119 linetables --- just the symbol table structures themselves.\n\
1120 With an argument REGEXP, list the symbol tables with matching names."),
1121 &maintenanceinfolist
);
1123 add_cmd ("line-table", class_maintenance
, maintenance_info_line_tables
, _("\
1124 List the contents of all line tables, from all symbol tables.\n\
1125 With an argument REGEXP, list just the line tables for the symbol\n\
1126 tables with matching names."),
1127 &maintenanceinfolist
);
1129 add_cmd ("check-symtabs", class_maintenance
, maintenance_check_symtabs
,
1131 Check consistency of currently expanded symtabs."),
1134 add_cmd ("expand-symtabs", class_maintenance
, maintenance_expand_symtabs
,
1135 _("Expand symbol tables.\n\
1136 With an argument REGEXP, only expand the symbol tables with matching names."),