1 /* Do various things to symbol tables (other than lookup), for GDB.
3 Copyright (C) 1986-2022 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 "gdbsupport/gdb_obstack.h"
33 #include "gdbsupport/gdb_regex.h"
35 #include "dictionary.h"
36 #include "typeprint.h"
39 #include "readline/tilde.h"
40 #include <cli/cli-style.h>
41 #include "gdbsupport/buildargv.h"
43 /* Prototypes for local functions */
45 static int block_depth (const struct block
*);
47 static void print_symbol (struct gdbarch
*gdbarch
, struct symbol
*symbol
,
48 int depth
, ui_file
*outfile
);
52 print_objfile_statistics (void)
54 int i
, linetables
, blockvectors
;
56 for (struct program_space
*pspace
: program_spaces
)
57 for (objfile
*objfile
: pspace
->objfiles ())
60 gdb_printf (_("Statistics for '%s':\n"), objfile_name (objfile
));
61 if (OBJSTAT (objfile
, n_stabs
) > 0)
62 gdb_printf (_(" Number of \"stab\" symbols read: %d\n"),
63 OBJSTAT (objfile
, n_stabs
));
64 if (objfile
->per_bfd
->n_minsyms
> 0)
65 gdb_printf (_(" Number of \"minimal\" symbols read: %d\n"),
66 objfile
->per_bfd
->n_minsyms
);
67 if (OBJSTAT (objfile
, n_syms
) > 0)
68 gdb_printf (_(" Number of \"full\" symbols read: %d\n"),
69 OBJSTAT (objfile
, n_syms
));
70 if (OBJSTAT (objfile
, n_types
) > 0)
71 gdb_printf (_(" Number of \"types\" defined: %d\n"),
72 OBJSTAT (objfile
, n_types
));
75 for (compunit_symtab
*cu
: objfile
->compunits ())
77 for (symtab
*s
: cu
->filetabs ())
80 if (s
->linetable () != NULL
)
84 blockvectors
= std::distance (objfile
->compunits ().begin (),
85 objfile
->compunits ().end ());
86 gdb_printf (_(" Number of symbol tables: %d\n"), i
);
87 gdb_printf (_(" Number of symbol tables with line tables: %d\n"),
89 gdb_printf (_(" Number of symbol tables with blockvectors: %d\n"),
92 objfile
->print_stats (false);
94 if (OBJSTAT (objfile
, sz_strtab
) > 0)
95 gdb_printf (_(" Space used by string tables: %d\n"),
96 OBJSTAT (objfile
, sz_strtab
));
97 gdb_printf (_(" Total memory used for objfile obstack: %s\n"),
98 pulongest (obstack_memory_used (&objfile
100 gdb_printf (_(" Total memory used for BFD obstack: %s\n"),
101 pulongest (obstack_memory_used (&objfile
->per_bfd
102 ->storage_obstack
)));
104 gdb_printf (_(" Total memory used for string cache: %d\n"),
105 objfile
->per_bfd
->string_cache
.memory_used ());
106 gdb_printf (_("Byte cache statistics for '%s':\n"),
107 objfile_name (objfile
));
108 objfile
->per_bfd
->string_cache
.print_statistics ("string cache");
109 objfile
->print_stats (true);
114 dump_objfile (struct objfile
*objfile
)
116 gdb_printf ("\nObject file %s: ", objfile_name (objfile
));
117 gdb_printf ("Objfile at %s, bfd at %s, %d minsyms\n\n",
118 host_address_to_string (objfile
),
119 host_address_to_string (objfile
->obfd
),
120 objfile
->per_bfd
->minimal_symbol_count
);
124 if (objfile
->compunit_symtabs
!= NULL
)
126 gdb_printf ("Symtabs:\n");
127 for (compunit_symtab
*cu
: objfile
->compunits ())
129 for (symtab
*symtab
: cu
->filetabs ())
131 gdb_printf ("%s at %s",
132 symtab_to_filename_for_display (symtab
),
133 host_address_to_string (symtab
));
134 if (symtab
->compunit ()->objfile () != objfile
)
135 gdb_printf (", NOT ON CHAIN!");
143 /* Print minimal symbols from this objfile. */
146 dump_msymbols (struct objfile
*objfile
, struct ui_file
*outfile
)
148 struct gdbarch
*gdbarch
= objfile
->arch ();
152 gdb_printf (outfile
, "\nObject file %s:\n\n", objfile_name (objfile
));
153 if (objfile
->per_bfd
->minimal_symbol_count
== 0)
155 gdb_printf (outfile
, "No minimal symbols found.\n");
159 for (minimal_symbol
*msymbol
: objfile
->msymbols ())
161 struct obj_section
*section
= msymbol
->obj_section (objfile
);
163 switch (msymbol
->type ())
171 case mst_text_gnu_ifunc
:
172 case mst_data_gnu_ifunc
:
175 case mst_solib_trampoline
:
200 gdb_printf (outfile
, "[%2d] %c ", index
, ms_type
);
202 /* Use the relocated address as shown in the symbol here -- do
203 not try to respect copy relocations. */
204 CORE_ADDR addr
= (msymbol
->value_raw_address ()
205 + objfile
->section_offsets
[msymbol
->section_index ()]);
206 gdb_puts (paddress (gdbarch
, addr
), outfile
);
207 gdb_printf (outfile
, " %s", msymbol
->linkage_name ());
210 if (section
->the_bfd_section
!= NULL
)
211 gdb_printf (outfile
, " section %s",
212 bfd_section_name (section
->the_bfd_section
));
214 gdb_printf (outfile
, " spurious section %ld",
215 (long) (section
- objfile
->sections
));
217 if (msymbol
->demangled_name () != NULL
)
219 gdb_printf (outfile
, " %s", msymbol
->demangled_name ());
221 if (msymbol
->filename
)
222 gdb_printf (outfile
, " %s", msymbol
->filename
);
223 gdb_puts ("\n", outfile
);
226 if (objfile
->per_bfd
->minimal_symbol_count
!= index
)
228 warning (_("internal error: minimal symbol count %d != %d"),
229 objfile
->per_bfd
->minimal_symbol_count
, index
);
231 gdb_printf (outfile
, "\n");
235 dump_symtab_1 (struct symtab
*symtab
, struct ui_file
*outfile
)
237 struct objfile
*objfile
= symtab
->compunit ()->objfile ();
238 struct gdbarch
*gdbarch
= objfile
->arch ();
240 struct mdict_iterator miter
;
243 const struct blockvector
*bv
;
245 const struct block
*b
;
248 gdb_printf (outfile
, "\nSymtab for file %s at %s\n",
249 symtab_to_filename_for_display (symtab
),
250 host_address_to_string (symtab
));
252 if (symtab
->compunit ()->dirname () != NULL
)
253 gdb_printf (outfile
, "Compilation directory is %s\n",
254 symtab
->compunit ()->dirname ());
255 gdb_printf (outfile
, "Read from object file %s (%s)\n",
256 objfile_name (objfile
),
257 host_address_to_string (objfile
));
258 gdb_printf (outfile
, "Language: %s\n",
259 language_str (symtab
->language ()));
261 /* First print the line table. */
262 l
= symtab
->linetable ();
265 gdb_printf (outfile
, "\nLine table:\n\n");
267 for (i
= 0; i
< len
; i
++)
269 gdb_printf (outfile
, " line %d at ", l
->item
[i
].line
);
270 gdb_puts (paddress (gdbarch
, l
->item
[i
].pc
), outfile
);
271 if (l
->item
[i
].is_stmt
)
272 gdb_printf (outfile
, "\t(stmt)");
273 gdb_printf (outfile
, "\n");
276 /* Now print the block info, but only for compunit symtabs since we will
277 print lots of duplicate info otherwise. */
278 if (is_main_symtab_of_compunit_symtab (symtab
))
280 gdb_printf (outfile
, "\nBlockvector:\n\n");
281 bv
= symtab
->compunit ()->blockvector ();
282 len
= BLOCKVECTOR_NBLOCKS (bv
);
283 for (i
= 0; i
< len
; i
++)
285 b
= BLOCKVECTOR_BLOCK (bv
, i
);
286 depth
= block_depth (b
) * 2;
287 gdb_printf (outfile
, "%*sblock #%03d, object at %s",
289 host_address_to_string (b
));
290 if (BLOCK_SUPERBLOCK (b
))
291 gdb_printf (outfile
, " under %s",
292 host_address_to_string (BLOCK_SUPERBLOCK (b
)));
293 /* drow/2002-07-10: We could save the total symbols count
294 even if we're using a hashtable, but nothing else but this message
296 gdb_printf (outfile
, ", %d syms/buckets in ",
297 mdict_size (BLOCK_MULTIDICT (b
)));
298 gdb_puts (paddress (gdbarch
, b
->start ()), outfile
);
299 gdb_printf (outfile
, "..");
300 gdb_puts (paddress (gdbarch
, b
->end ()), outfile
);
301 if (BLOCK_FUNCTION (b
))
303 gdb_printf (outfile
, ", function %s",
304 BLOCK_FUNCTION (b
)->linkage_name ());
305 if (BLOCK_FUNCTION (b
)->demangled_name () != NULL
)
307 gdb_printf (outfile
, ", %s",
308 BLOCK_FUNCTION (b
)->demangled_name ());
311 gdb_printf (outfile
, "\n");
312 /* Now print each symbol in this block (in no particular order, if
313 we're using a hashtable). Note that we only want this
314 block, not any blocks from included symtabs. */
315 ALL_DICT_SYMBOLS (BLOCK_MULTIDICT (b
), miter
, sym
)
319 print_symbol (gdbarch
, sym
, depth
+ 1, outfile
);
321 catch (const gdb_exception_error
&ex
)
323 exception_fprintf (gdb_stderr
, ex
,
324 "Error printing symbol:\n");
328 gdb_printf (outfile
, "\n");
332 compunit_symtab
*compunit
= symtab
->compunit ();
333 const char *compunit_filename
334 = symtab_to_filename_for_display (compunit
->primary_filetab ());
337 "\nBlockvector same as owning compunit: %s\n\n",
341 /* Print info about the user of this compunit_symtab, and the
342 compunit_symtabs included by this one. */
343 if (is_main_symtab_of_compunit_symtab (symtab
))
345 struct compunit_symtab
*cust
= symtab
->compunit ();
347 if (cust
->user
!= nullptr)
350 = host_address_to_string (cust
->user
->primary_filetab ());
351 gdb_printf (outfile
, "Compunit user: %s\n", addr
);
353 if (cust
->includes
!= nullptr)
356 struct compunit_symtab
*include
= cust
->includes
[i
];
357 if (include
== nullptr)
360 = host_address_to_string (include
->primary_filetab ());
361 gdb_printf (outfile
, "Compunit include: %s\n", addr
);
367 dump_symtab (struct symtab
*symtab
, struct ui_file
*outfile
)
369 /* Set the current language to the language of the symtab we're dumping
370 because certain routines used during dump_symtab() use the current
371 language to print an image of the symbol. We'll restore it later.
372 But use only real languages, not placeholders. */
373 if (symtab
->language () != language_unknown
374 && symtab
->language () != language_auto
)
376 scoped_restore_current_language save_lang
;
377 set_language (symtab
->language ());
378 dump_symtab_1 (symtab
, outfile
);
381 dump_symtab_1 (symtab
, outfile
);
385 maintenance_print_symbols (const char *args
, int from_tty
)
387 struct ui_file
*outfile
= gdb_stdout
;
388 char *address_arg
= NULL
, *source_arg
= NULL
, *objfile_arg
= NULL
;
393 gdb_argv
argv (args
);
395 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
397 if (strcmp (argv
[i
], "-pc") == 0)
399 if (argv
[i
+ 1] == NULL
)
400 error (_("Missing pc value"));
401 address_arg
= argv
[++i
];
403 else if (strcmp (argv
[i
], "-source") == 0)
405 if (argv
[i
+ 1] == NULL
)
406 error (_("Missing source file"));
407 source_arg
= argv
[++i
];
409 else if (strcmp (argv
[i
], "-objfile") == 0)
411 if (argv
[i
+ 1] == NULL
)
412 error (_("Missing objfile name"));
413 objfile_arg
= argv
[++i
];
415 else if (strcmp (argv
[i
], "--") == 0)
417 /* End of options. */
421 else if (argv
[i
][0] == '-')
423 /* Future proofing: Don't allow OUTFILE to begin with "-". */
424 error (_("Unknown option: %s"), argv
[i
]);
431 if (address_arg
!= NULL
&& source_arg
!= NULL
)
432 error (_("Must specify at most one of -pc and -source"));
434 stdio_file arg_outfile
;
436 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
438 if (argv
[outfile_idx
+ 1] != NULL
)
439 error (_("Junk at end of command"));
440 gdb::unique_xmalloc_ptr
<char> outfile_name
441 (tilde_expand (argv
[outfile_idx
]));
442 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
443 perror_with_name (outfile_name
.get ());
444 outfile
= &arg_outfile
;
447 if (address_arg
!= NULL
)
449 CORE_ADDR pc
= parse_and_eval_address (address_arg
);
450 struct symtab
*s
= find_pc_line_symtab (pc
);
453 error (_("No symtab for address: %s"), address_arg
);
454 dump_symtab (s
, outfile
);
460 for (objfile
*objfile
: current_program_space
->objfiles ())
462 int print_for_objfile
= 1;
464 if (objfile_arg
!= NULL
)
466 = compare_filenames_for_search (objfile_name (objfile
),
468 if (!print_for_objfile
)
471 for (compunit_symtab
*cu
: objfile
->compunits ())
473 for (symtab
*s
: cu
->filetabs ())
475 int print_for_source
= 0;
478 if (source_arg
!= NULL
)
481 = compare_filenames_for_search
482 (symtab_to_filename_for_display (s
), source_arg
);
485 if (source_arg
== NULL
487 dump_symtab (s
, outfile
);
492 if (source_arg
!= NULL
&& !found
)
493 error (_("No symtab for source file: %s"), source_arg
);
497 /* Print symbol SYMBOL on OUTFILE. DEPTH says how far to indent. */
500 print_symbol (struct gdbarch
*gdbarch
, struct symbol
*symbol
,
501 int depth
, ui_file
*outfile
)
503 struct obj_section
*section
;
505 if (symbol
->is_objfile_owned ())
506 section
= symbol
->obj_section (symbol
->objfile ());
510 print_spaces (depth
, outfile
);
511 if (symbol
->domain () == LABEL_DOMAIN
)
513 gdb_printf (outfile
, "label %s at ", symbol
->print_name ());
514 gdb_puts (paddress (gdbarch
, symbol
->value_address ()),
517 gdb_printf (outfile
, " section %s\n",
518 bfd_section_name (section
->the_bfd_section
));
520 gdb_printf (outfile
, "\n");
524 if (symbol
->domain () == STRUCT_DOMAIN
)
526 if (symbol
->type ()->name ())
528 current_language
->print_type (symbol
->type (), "", outfile
, 1, depth
,
529 &type_print_raw_options
);
533 gdb_printf (outfile
, "%s %s = ",
534 (symbol
->type ()->code () == TYPE_CODE_ENUM
536 : (symbol
->type ()->code () == TYPE_CODE_STRUCT
537 ? "struct" : "union")),
538 symbol
->linkage_name ());
539 current_language
->print_type (symbol
->type (), "", outfile
, 1, depth
,
540 &type_print_raw_options
);
542 gdb_printf (outfile
, ";\n");
546 if (symbol
->aclass () == LOC_TYPEDEF
)
547 gdb_printf (outfile
, "typedef ");
550 /* Print details of types, except for enums where it's clutter. */
551 current_language
->print_type (symbol
->type (), symbol
->print_name (),
553 symbol
->type ()->code () != TYPE_CODE_ENUM
,
555 &type_print_raw_options
);
556 gdb_printf (outfile
, "; ");
559 gdb_printf (outfile
, "%s ", symbol
->print_name ());
561 switch (symbol
->aclass ())
564 gdb_printf (outfile
, "const %s (%s)",
565 plongest (symbol
->value_longest ()),
566 hex_string (symbol
->value_longest ()));
569 case LOC_CONST_BYTES
:
572 struct type
*type
= check_typedef (symbol
->type ());
574 gdb_printf (outfile
, "const %s hex bytes:",
575 pulongest (TYPE_LENGTH (type
)));
576 for (i
= 0; i
< TYPE_LENGTH (type
); i
++)
577 gdb_printf (outfile
, " %02x",
578 (unsigned) symbol
->value_bytes ()[i
]);
583 gdb_printf (outfile
, "static at ");
584 gdb_puts (paddress (gdbarch
, symbol
->value_address ()), outfile
);
586 gdb_printf (outfile
, " section %s",
587 bfd_section_name (section
->the_bfd_section
));
591 if (symbol
->is_argument ())
592 gdb_printf (outfile
, "parameter register %s",
593 plongest (symbol
->value_longest ()));
595 gdb_printf (outfile
, "register %s",
596 plongest (symbol
->value_longest ()));
600 gdb_printf (outfile
, "arg at offset %s",
601 hex_string (symbol
->value_longest ()));
605 gdb_printf (outfile
, "reference arg at %s",
606 hex_string (symbol
->value_longest ()));
609 case LOC_REGPARM_ADDR
:
610 gdb_printf (outfile
, "address parameter register %s",
611 plongest (symbol
->value_longest ()));
615 gdb_printf (outfile
, "local at offset %s",
616 hex_string (symbol
->value_longest ()));
623 gdb_printf (outfile
, "label at ");
624 gdb_puts (paddress (gdbarch
, symbol
->value_address ()), outfile
);
626 gdb_printf (outfile
, " section %s",
627 bfd_section_name (section
->the_bfd_section
));
632 (outfile
, "block object %s, %s..%s",
633 host_address_to_string (symbol
->value_block ()),
634 paddress (gdbarch
, symbol
->value_block()->start ()),
635 paddress (gdbarch
, symbol
->value_block()->end ()));
637 gdb_printf (outfile
, " section %s",
638 bfd_section_name (section
->the_bfd_section
));
642 gdb_printf (outfile
, "computed at runtime");
646 gdb_printf (outfile
, "unresolved");
649 case LOC_OPTIMIZED_OUT
:
650 gdb_printf (outfile
, "optimized out");
654 gdb_printf (outfile
, "botched symbol class %x",
659 gdb_printf (outfile
, "\n");
663 maintenance_print_msymbols (const char *args
, int from_tty
)
665 struct ui_file
*outfile
= gdb_stdout
;
666 char *objfile_arg
= NULL
;
671 gdb_argv
argv (args
);
673 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
675 if (strcmp (argv
[i
], "-objfile") == 0)
677 if (argv
[i
+ 1] == NULL
)
678 error (_("Missing objfile name"));
679 objfile_arg
= argv
[++i
];
681 else if (strcmp (argv
[i
], "--") == 0)
683 /* End of options. */
687 else if (argv
[i
][0] == '-')
689 /* Future proofing: Don't allow OUTFILE to begin with "-". */
690 error (_("Unknown option: %s"), argv
[i
]);
697 stdio_file arg_outfile
;
699 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
701 if (argv
[outfile_idx
+ 1] != NULL
)
702 error (_("Junk at end of command"));
703 gdb::unique_xmalloc_ptr
<char> outfile_name
704 (tilde_expand (argv
[outfile_idx
]));
705 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
706 perror_with_name (outfile_name
.get ());
707 outfile
= &arg_outfile
;
710 for (objfile
*objfile
: current_program_space
->objfiles ())
713 if (objfile_arg
== NULL
714 || compare_filenames_for_search (objfile_name (objfile
), objfile_arg
))
715 dump_msymbols (objfile
, outfile
);
720 maintenance_print_objfiles (const char *regexp
, int from_tty
)
727 for (struct program_space
*pspace
: program_spaces
)
728 for (objfile
*objfile
: pspace
->objfiles ())
732 || re_exec (objfile_name (objfile
)))
733 dump_objfile (objfile
);
737 /* List all the symbol tables whose names match REGEXP (optional). */
740 maintenance_info_symtabs (const char *regexp
, int from_tty
)
747 for (struct program_space
*pspace
: program_spaces
)
748 for (objfile
*objfile
: pspace
->objfiles ())
750 /* We don't want to print anything for this objfile until we
751 actually find a symtab whose name matches. */
752 int printed_objfile_start
= 0;
754 for (compunit_symtab
*cust
: objfile
->compunits ())
756 int printed_compunit_symtab_start
= 0;
758 for (symtab
*symtab
: cust
->filetabs ())
763 || re_exec (symtab_to_filename_for_display (symtab
)))
765 if (! printed_objfile_start
)
767 gdb_printf ("{ objfile %s ", objfile_name (objfile
));
768 gdb_stdout
->wrap_here (2);
769 gdb_printf ("((struct objfile *) %s)\n",
770 host_address_to_string (objfile
));
771 printed_objfile_start
= 1;
773 if (! printed_compunit_symtab_start
)
775 gdb_printf (" { ((struct compunit_symtab *) %s)\n",
776 host_address_to_string (cust
));
777 gdb_printf (" debugformat %s\n",
778 cust
->debugformat ());
779 gdb_printf (" producer %s\n",
780 (cust
->producer () != nullptr
781 ? cust
->producer () : "(null)"));
782 gdb_printf (" name %s\n", cust
->name
);
783 gdb_printf (" dirname %s\n",
784 (cust
->dirname () != NULL
785 ? cust
->dirname () : "(null)"));
786 gdb_printf (" blockvector"
787 " ((struct blockvector *) %s)\n",
788 host_address_to_string
789 (cust
->blockvector ()));
791 " ((struct compunit_symtab *) %s)\n",
792 cust
->user
!= nullptr
793 ? host_address_to_string (cust
->user
)
795 if (cust
->includes
!= nullptr)
797 gdb_printf (" ( includes\n");
798 for (int i
= 0; ; ++i
)
800 struct compunit_symtab
*include
802 if (include
== nullptr)
805 = host_address_to_string (include
);
806 gdb_printf (" (%s %s)\n",
807 "(struct compunit_symtab *)",
812 printed_compunit_symtab_start
= 1;
815 gdb_printf ("\t{ symtab %s ",
816 symtab_to_filename_for_display (symtab
));
817 gdb_stdout
->wrap_here (4);
818 gdb_printf ("((struct symtab *) %s)\n",
819 host_address_to_string (symtab
));
820 gdb_printf ("\t fullname %s\n",
821 symtab
->fullname
!= NULL
825 "linetable ((struct linetable *) %s)\n",
826 host_address_to_string
827 (symtab
->linetable ()));
828 gdb_printf ("\t}\n");
832 if (printed_compunit_symtab_start
)
836 if (printed_objfile_start
)
841 /* Check consistency of symtabs.
842 An example of what this checks for is NULL blockvectors.
843 They can happen if there's a bug during debug info reading.
844 GDB assumes they are always non-NULL.
846 Note: This does not check for psymtab vs symtab consistency.
847 Use "maint check-psymtabs" for that. */
850 maintenance_check_symtabs (const char *ignore
, int from_tty
)
852 for (struct program_space
*pspace
: program_spaces
)
853 for (objfile
*objfile
: pspace
->objfiles ())
855 /* We don't want to print anything for this objfile until we
856 actually find something worth printing. */
857 int printed_objfile_start
= 0;
859 for (compunit_symtab
*cust
: objfile
->compunits ())
861 int found_something
= 0;
862 struct symtab
*symtab
= cust
->primary_filetab ();
866 if (cust
->blockvector () == NULL
)
868 /* Add more checks here. */
872 if (! printed_objfile_start
)
874 gdb_printf ("{ objfile %s ", objfile_name (objfile
));
875 gdb_stdout
->wrap_here (2);
876 gdb_printf ("((struct objfile *) %s)\n",
877 host_address_to_string (objfile
));
878 printed_objfile_start
= 1;
880 gdb_printf (" { symtab %s\n",
881 symtab_to_filename_for_display (symtab
));
882 if (cust
->blockvector () == NULL
)
883 gdb_printf (" NULL blockvector\n");
888 if (printed_objfile_start
)
893 /* Expand all symbol tables whose name matches an optional regexp. */
896 maintenance_expand_symtabs (const char *args
, int from_tty
)
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."));
917 for (struct program_space
*pspace
: program_spaces
)
918 for (objfile
*objfile
: pspace
->objfiles ())
919 objfile
->expand_symtabs_matching
920 ([&] (const char *filename
, bool basenames
)
922 /* KISS: Only apply the regexp to the complete file name. */
924 && (regexp
== NULL
|| re_exec (filename
)));
929 SEARCH_GLOBAL_BLOCK
| SEARCH_STATIC_BLOCK
,
935 /* Return the nexting depth of a block within other blocks in its symtab. */
938 block_depth (const struct block
*block
)
942 while ((block
= BLOCK_SUPERBLOCK (block
)) != NULL
)
950 /* Used by MAINTENANCE_INFO_LINE_TABLES to print the information about a
951 single line table. */
954 maintenance_print_one_line_table (struct symtab
*symtab
, void *data
)
956 struct linetable
*linetable
;
957 struct objfile
*objfile
;
959 objfile
= symtab
->compunit ()->objfile ();
960 gdb_printf (_("objfile: %ps ((struct objfile *) %s)\n"),
961 styled_string (file_name_style
.style (),
962 objfile_name (objfile
)),
963 host_address_to_string (objfile
));
964 gdb_printf (_("compunit_symtab: %s ((struct compunit_symtab *) %s)\n"),
965 symtab
->compunit ()->name
,
966 host_address_to_string (symtab
->compunit ()));
967 gdb_printf (_("symtab: %ps ((struct symtab *) %s)\n"),
968 styled_string (file_name_style
.style (),
969 symtab_to_fullname (symtab
)),
970 host_address_to_string (symtab
));
971 linetable
= symtab
->linetable ();
972 gdb_printf (_("linetable: ((struct linetable *) %s):\n"),
973 host_address_to_string (linetable
));
975 if (linetable
== NULL
)
976 gdb_printf (_("No line table.\n"));
977 else if (linetable
->nitems
<= 0)
978 gdb_printf (_("Line table has no lines.\n"));
981 /* Leave space for 6 digits of index and line number. After that the
982 tables will just not format as well. */
983 struct ui_out
*uiout
= current_uiout
;
984 ui_out_emit_table
table_emitter (uiout
, 5, -1, "line-table");
985 uiout
->table_header (6, ui_left
, "index", _("INDEX"));
986 uiout
->table_header (6, ui_left
, "line", _("LINE"));
987 uiout
->table_header (18, ui_left
, "address", _("ADDRESS"));
988 uiout
->table_header (7, ui_left
, "is-stmt", _("IS-STMT"));
989 uiout
->table_header (12, ui_left
, "prologue-end", _("PROLOGUE-END"));
990 uiout
->table_body ();
992 for (int i
= 0; i
< linetable
->nitems
; ++i
)
994 struct linetable_entry
*item
;
996 item
= &linetable
->item
[i
];
997 ui_out_emit_tuple
tuple_emitter (uiout
, nullptr);
998 uiout
->field_signed ("index", i
);
1000 uiout
->field_signed ("line", item
->line
);
1002 uiout
->field_string ("line", _("END"));
1003 uiout
->field_core_addr ("address", objfile
->arch (),
1005 uiout
->field_string ("is-stmt", item
->is_stmt
? "Y" : "");
1006 uiout
->field_string ("prologue-end", item
->prologue_end
? "Y" : "");
1014 /* Implement the 'maint info line-table' command. */
1017 maintenance_info_line_tables (const char *regexp
, int from_tty
)
1024 for (struct program_space
*pspace
: program_spaces
)
1025 for (objfile
*objfile
: pspace
->objfiles ())
1027 for (compunit_symtab
*cust
: objfile
->compunits ())
1029 for (symtab
*symtab
: cust
->filetabs ())
1034 || re_exec (symtab_to_filename_for_display (symtab
)))
1036 maintenance_print_one_line_table (symtab
, NULL
);
1046 /* Do early runtime initializations. */
1048 void _initialize_symmisc ();
1050 _initialize_symmisc ()
1052 add_cmd ("symbols", class_maintenance
, maintenance_print_symbols
, _("\
1053 Print dump of current symbol definitions.\n\
1054 Usage: mt print symbols [-pc ADDRESS] [--] [OUTFILE]\n\
1055 mt print symbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
1056 Entries in the full symbol table are dumped to file OUTFILE,\n\
1057 or the terminal if OUTFILE is unspecified.\n\
1058 If ADDRESS is provided, dump only the file for that address.\n\
1059 If SOURCE is provided, dump only that file's symbols.\n\
1060 If OBJFILE is provided, dump only that file's minimal symbols."),
1061 &maintenanceprintlist
);
1063 add_cmd ("msymbols", class_maintenance
, maintenance_print_msymbols
, _("\
1064 Print dump of current minimal symbol definitions.\n\
1065 Usage: mt print msymbols [-objfile OBJFILE] [--] [OUTFILE]\n\
1066 Entries in the minimal symbol table are dumped to file OUTFILE,\n\
1067 or the terminal if OUTFILE is unspecified.\n\
1068 If OBJFILE is provided, dump only that file's minimal symbols."),
1069 &maintenanceprintlist
);
1071 add_cmd ("objfiles", class_maintenance
, maintenance_print_objfiles
,
1072 _("Print dump of current object file definitions.\n\
1073 With an argument REGEXP, list the object files with matching names."),
1074 &maintenanceprintlist
);
1076 add_cmd ("symtabs", class_maintenance
, maintenance_info_symtabs
, _("\
1077 List the full symbol tables for all object files.\n\
1078 This does not include information about individual symbols, blocks, or\n\
1079 linetables --- just the symbol table structures themselves.\n\
1080 With an argument REGEXP, list the symbol tables with matching names."),
1081 &maintenanceinfolist
);
1083 add_cmd ("line-table", class_maintenance
, maintenance_info_line_tables
, _("\
1084 List the contents of all line tables, from all symbol tables.\n\
1085 With an argument REGEXP, list just the line tables for the symbol\n\
1086 tables with matching names."),
1087 &maintenanceinfolist
);
1089 add_cmd ("check-symtabs", class_maintenance
, maintenance_check_symtabs
,
1091 Check consistency of currently expanded symtabs."),
1094 add_cmd ("expand-symtabs", class_maintenance
, maintenance_expand_symtabs
,
1095 _("Expand symbol tables.\n\
1096 With an argument REGEXP, only expand the symbol tables with matching names."),