1 /* Do various things to symbol tables (other than lookup), for GDB.
3 Copyright (C) 1986-2024 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/>. */
20 #include "event-top.h"
21 #include "exceptions.h"
25 #include "filenames.h"
28 #include "breakpoint.h"
30 #include "gdbsupport/gdb_obstack.h"
34 #include "gdbsupport/gdb_regex.h"
36 #include "dictionary.h"
37 #include "typeprint.h"
38 #include "cli/cli-cmds.h"
40 #include "readline/tilde.h"
41 #include <cli/cli-style.h>
42 #include "gdbsupport/buildargv.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_objfile_statistics (void)
55 int i
, linetables
, blockvectors
;
57 for (struct program_space
*pspace
: program_spaces
)
58 for (objfile
*objfile
: pspace
->objfiles ())
61 gdb_printf (_("Statistics for '%s':\n"), objfile_name (objfile
));
62 if (OBJSTAT (objfile
, n_stabs
) > 0)
63 gdb_printf (_(" Number of \"stab\" symbols read: %d\n"),
64 OBJSTAT (objfile
, n_stabs
));
65 if (objfile
->per_bfd
->n_minsyms
> 0)
66 gdb_printf (_(" Number of \"minimal\" symbols read: %d\n"),
67 objfile
->per_bfd
->n_minsyms
);
68 if (OBJSTAT (objfile
, n_syms
) > 0)
69 gdb_printf (_(" Number of \"full\" symbols read: %d\n"),
70 OBJSTAT (objfile
, n_syms
));
71 if (OBJSTAT (objfile
, n_types
) > 0)
72 gdb_printf (_(" Number of \"types\" defined: %d\n"),
73 OBJSTAT (objfile
, n_types
));
76 for (compunit_symtab
*cu
: objfile
->compunits ())
78 for (symtab
*s
: cu
->filetabs ())
81 if (s
->linetable () != NULL
)
85 blockvectors
= std::distance (objfile
->compunits ().begin (),
86 objfile
->compunits ().end ());
87 gdb_printf (_(" Number of symbol tables: %d\n"), i
);
88 gdb_printf (_(" Number of symbol tables with line tables: %d\n"),
90 gdb_printf (_(" Number of symbol tables with blockvectors: %d\n"),
93 objfile
->print_stats (false);
95 if (OBJSTAT (objfile
, sz_strtab
) > 0)
96 gdb_printf (_(" Space used by string tables: %d\n"),
97 OBJSTAT (objfile
, sz_strtab
));
98 gdb_printf (_(" Total memory used for objfile obstack: %s\n"),
99 pulongest (obstack_memory_used (&objfile
100 ->objfile_obstack
)));
101 gdb_printf (_(" Total memory used for BFD obstack: %s\n"),
102 pulongest (obstack_memory_used (&objfile
->per_bfd
103 ->storage_obstack
)));
105 gdb_printf (_(" Total memory used for string cache: %d\n"),
106 objfile
->per_bfd
->string_cache
.memory_used ());
107 gdb_printf (_("Byte cache statistics for '%s':\n"),
108 objfile_name (objfile
));
109 objfile
->per_bfd
->string_cache
.print_statistics ("string cache");
110 objfile
->print_stats (true);
115 dump_objfile (struct objfile
*objfile
)
117 gdb_printf ("\nObject file %s: ", objfile_name (objfile
));
118 gdb_printf ("Objfile at %s, bfd at %s, %d minsyms\n\n",
119 host_address_to_string (objfile
),
120 host_address_to_string (objfile
->obfd
.get ()),
121 objfile
->per_bfd
->minimal_symbol_count
);
125 if (objfile
->compunit_symtabs
!= NULL
)
127 gdb_printf ("Symtabs:\n");
128 for (compunit_symtab
*cu
: objfile
->compunits ())
130 for (symtab
*symtab
: cu
->filetabs ())
132 gdb_printf ("%s at %s",
133 symtab_to_filename_for_display (symtab
),
134 host_address_to_string (symtab
));
135 if (symtab
->compunit ()->objfile () != objfile
)
136 gdb_printf (", NOT ON CHAIN!");
144 /* Print minimal symbols from this objfile. */
147 dump_msymbols (struct objfile
*objfile
, struct ui_file
*outfile
)
149 struct gdbarch
*gdbarch
= objfile
->arch ();
153 gdb_printf (outfile
, "\nObject file %s:\n\n", objfile_name (objfile
));
154 if (objfile
->per_bfd
->minimal_symbol_count
== 0)
156 gdb_printf (outfile
, "No minimal symbols found.\n");
160 for (minimal_symbol
*msymbol
: objfile
->msymbols ())
162 struct obj_section
*section
= msymbol
->obj_section (objfile
);
164 switch (msymbol
->type ())
172 case mst_text_gnu_ifunc
:
173 case mst_data_gnu_ifunc
:
176 case mst_solib_trampoline
:
201 gdb_printf (outfile
, "[%2d] %c ", index
, ms_type
);
203 /* Use the relocated address as shown in the symbol here -- do
204 not try to respect copy relocations. */
205 CORE_ADDR addr
= (CORE_ADDR (msymbol
->unrelocated_address ())
206 + objfile
->section_offsets
[msymbol
->section_index ()]);
207 gdb_puts (paddress (gdbarch
, addr
), outfile
);
208 gdb_printf (outfile
, " %s", msymbol
->linkage_name ());
211 if (section
->the_bfd_section
!= NULL
)
212 gdb_printf (outfile
, " section %s",
213 bfd_section_name (section
->the_bfd_section
));
215 gdb_printf (outfile
, " spurious section %ld",
216 (long) (section
- objfile
->sections_start
));
218 if (msymbol
->demangled_name () != NULL
)
220 gdb_printf (outfile
, " %s", msymbol
->demangled_name ());
222 if (msymbol
->filename
)
223 gdb_printf (outfile
, " %s", msymbol
->filename
);
224 gdb_puts ("\n", outfile
);
227 if (objfile
->per_bfd
->minimal_symbol_count
!= index
)
229 warning (_("internal error: minimal symbol count %d != %d"),
230 objfile
->per_bfd
->minimal_symbol_count
, index
);
232 gdb_printf (outfile
, "\n");
236 dump_symtab_1 (struct symtab
*symtab
, struct ui_file
*outfile
)
238 struct objfile
*objfile
= symtab
->compunit ()->objfile ();
239 struct gdbarch
*gdbarch
= objfile
->arch ();
240 const struct linetable
*l
;
243 gdb_printf (outfile
, "\nSymtab for file %s at %s\n",
244 symtab_to_filename_for_display (symtab
),
245 host_address_to_string (symtab
));
247 if (symtab
->compunit ()->dirname () != NULL
)
248 gdb_printf (outfile
, "Compilation directory is %s\n",
249 symtab
->compunit ()->dirname ());
250 gdb_printf (outfile
, "Read from object file %s (%s)\n",
251 objfile_name (objfile
),
252 host_address_to_string (objfile
));
253 gdb_printf (outfile
, "Language: %s\n",
254 language_str (symtab
->language ()));
256 /* First print the line table. */
257 l
= symtab
->linetable ();
260 gdb_printf (outfile
, "\nLine table:\n\n");
262 for (int i
= 0; i
< len
; i
++)
264 gdb_printf (outfile
, " line %d at ", l
->item
[i
].line
);
265 gdb_puts (paddress (gdbarch
, l
->item
[i
].pc (objfile
)), outfile
);
266 if (l
->item
[i
].is_stmt
)
267 gdb_printf (outfile
, "\t(stmt)");
268 gdb_printf (outfile
, "\n");
271 /* Now print the block info, but only for compunit symtabs since we will
272 print lots of duplicate info otherwise. */
273 if (is_main_symtab_of_compunit_symtab (symtab
))
275 gdb_printf (outfile
, "\nBlockvector:\n\n");
276 const blockvector
*bv
= symtab
->compunit ()->blockvector ();
277 for (int i
= 0; i
< bv
->num_blocks (); i
++)
279 const block
*b
= bv
->block (i
);
280 depth
= block_depth (b
) * 2;
281 gdb_printf (outfile
, "%*sblock #%03d, object at %s",
283 host_address_to_string (b
));
284 if (b
->superblock ())
285 gdb_printf (outfile
, " under %s",
286 host_address_to_string (b
->superblock ()));
287 /* drow/2002-07-10: We could save the total symbols count
288 even if we're using a hashtable, but nothing else but this message
290 gdb_printf (outfile
, ", %d symbols in ",
291 mdict_size (b
->multidict ()));
292 gdb_puts (paddress (gdbarch
, b
->start ()), outfile
);
293 gdb_printf (outfile
, "..");
294 gdb_puts (paddress (gdbarch
, b
->end ()), outfile
);
297 gdb_printf (outfile
, ", function %s",
298 b
->function ()->linkage_name ());
299 if (b
->function ()->demangled_name () != NULL
)
301 gdb_printf (outfile
, ", %s",
302 b
->function ()->demangled_name ());
305 gdb_printf (outfile
, "\n");
306 /* Now print each symbol in this block (in no particular order, if
307 we're using a hashtable). Note that we only want this
308 block, not any blocks from included symtabs. */
309 for (struct symbol
*sym
: b
->multidict_symbols ())
313 print_symbol (gdbarch
, sym
, depth
+ 1, outfile
);
315 catch (const gdb_exception_error
&ex
)
317 exception_fprintf (gdb_stderr
, ex
,
318 "Error printing symbol:\n");
322 gdb_printf (outfile
, "\n");
326 compunit_symtab
*compunit
= symtab
->compunit ();
327 const char *compunit_filename
328 = symtab_to_filename_for_display (compunit
->primary_filetab ());
331 "\nBlockvector same as owning compunit: %s\n\n",
335 /* Print info about the user of this compunit_symtab, and the
336 compunit_symtabs included by this one. */
337 if (is_main_symtab_of_compunit_symtab (symtab
))
339 struct compunit_symtab
*cust
= symtab
->compunit ();
341 if (cust
->user
!= nullptr)
344 = host_address_to_string (cust
->user
->primary_filetab ());
345 gdb_printf (outfile
, "Compunit user: %s\n", addr
);
347 if (cust
->includes
!= nullptr)
348 for (int i
= 0; ; ++i
)
350 struct compunit_symtab
*include
= cust
->includes
[i
];
351 if (include
== nullptr)
354 = host_address_to_string (include
->primary_filetab ());
355 gdb_printf (outfile
, "Compunit include: %s\n", addr
);
361 dump_symtab (struct symtab
*symtab
, struct ui_file
*outfile
)
363 /* Set the current language to the language of the symtab we're dumping
364 because certain routines used during dump_symtab() use the current
365 language to print an image of the symbol. We'll restore it later.
366 But use only real languages, not placeholders. */
367 if (symtab
->language () != language_unknown
)
369 scoped_restore_current_language
save_lang (symtab
->language ());
370 dump_symtab_1 (symtab
, outfile
);
373 dump_symtab_1 (symtab
, outfile
);
377 maintenance_print_symbols (const char *args
, int from_tty
)
379 struct ui_file
*outfile
= gdb_stdout
;
380 char *address_arg
= NULL
, *source_arg
= NULL
, *objfile_arg
= NULL
;
385 gdb_argv
argv (args
);
387 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
389 if (strcmp (argv
[i
], "-pc") == 0)
391 if (argv
[i
+ 1] == NULL
)
392 error (_("Missing pc value"));
393 address_arg
= argv
[++i
];
395 else if (strcmp (argv
[i
], "-source") == 0)
397 if (argv
[i
+ 1] == NULL
)
398 error (_("Missing source file"));
399 source_arg
= argv
[++i
];
401 else if (strcmp (argv
[i
], "-objfile") == 0)
403 if (argv
[i
+ 1] == NULL
)
404 error (_("Missing objfile name"));
405 objfile_arg
= argv
[++i
];
407 else if (strcmp (argv
[i
], "--") == 0)
409 /* End of options. */
413 else if (argv
[i
][0] == '-')
415 /* Future proofing: Don't allow OUTFILE to begin with "-". */
416 error (_("Unknown option: %s"), argv
[i
]);
423 if (address_arg
!= NULL
&& source_arg
!= NULL
)
424 error (_("Must specify at most one of -pc and -source"));
426 stdio_file arg_outfile
;
428 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
430 if (argv
[outfile_idx
+ 1] != NULL
)
431 error (_("Junk at end of command"));
432 gdb::unique_xmalloc_ptr
<char> outfile_name
433 (tilde_expand (argv
[outfile_idx
]));
434 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
435 perror_with_name (outfile_name
.get ());
436 outfile
= &arg_outfile
;
439 if (address_arg
!= NULL
)
441 CORE_ADDR pc
= parse_and_eval_address (address_arg
);
442 struct symtab
*s
= find_pc_line_symtab (pc
);
445 error (_("No symtab for address: %s"), address_arg
);
446 dump_symtab (s
, outfile
);
452 for (objfile
*objfile
: current_program_space
->objfiles ())
454 int print_for_objfile
= 1;
456 if (objfile_arg
!= NULL
)
458 = compare_filenames_for_search (objfile_name (objfile
),
460 if (!print_for_objfile
)
463 for (compunit_symtab
*cu
: objfile
->compunits ())
465 for (symtab
*s
: cu
->filetabs ())
467 int print_for_source
= 0;
470 if (source_arg
!= NULL
)
473 = compare_filenames_for_search
474 (symtab_to_filename_for_display (s
), source_arg
);
477 if (source_arg
== NULL
479 dump_symtab (s
, outfile
);
484 if (source_arg
!= NULL
&& !found
)
485 error (_("No symtab for source file: %s"), source_arg
);
489 /* Print symbol SYMBOL on OUTFILE. DEPTH says how far to indent. */
492 print_symbol (struct gdbarch
*gdbarch
, struct symbol
*symbol
,
493 int depth
, ui_file
*outfile
)
495 struct obj_section
*section
;
497 if (symbol
->is_objfile_owned ())
498 section
= symbol
->obj_section (symbol
->objfile ());
502 print_spaces (depth
, outfile
);
503 if (symbol
->domain () == LABEL_DOMAIN
)
505 gdb_printf (outfile
, "label %s at ", symbol
->print_name ());
506 gdb_puts (paddress (gdbarch
, symbol
->value_address ()),
509 gdb_printf (outfile
, " section %s\n",
510 bfd_section_name (section
->the_bfd_section
));
512 gdb_printf (outfile
, "\n");
516 if (symbol
->domain () == STRUCT_DOMAIN
)
518 if (symbol
->type ()->name ())
520 current_language
->print_type (symbol
->type (), "", outfile
, 1, depth
,
521 &type_print_raw_options
);
525 gdb_printf (outfile
, "%s %s = ",
526 (symbol
->type ()->code () == TYPE_CODE_ENUM
528 : (symbol
->type ()->code () == TYPE_CODE_STRUCT
529 ? "struct" : "union")),
530 symbol
->linkage_name ());
531 current_language
->print_type (symbol
->type (), "", outfile
, 1, depth
,
532 &type_print_raw_options
);
534 gdb_printf (outfile
, ";\n");
538 if (symbol
->aclass () == LOC_TYPEDEF
)
539 gdb_printf (outfile
, "typedef ");
542 /* Print details of types, except for enums where it's clutter. */
543 current_language
->print_type (symbol
->type (), symbol
->print_name (),
545 symbol
->type ()->code () != TYPE_CODE_ENUM
,
547 &type_print_raw_options
);
548 gdb_printf (outfile
, "; ");
551 gdb_printf (outfile
, "%s ", symbol
->print_name ());
553 switch (symbol
->aclass ())
556 gdb_printf (outfile
, "const %s (%s)",
557 plongest (symbol
->value_longest ()),
558 hex_string (symbol
->value_longest ()));
561 case LOC_CONST_BYTES
:
564 struct type
*type
= check_typedef (symbol
->type ());
566 gdb_printf (outfile
, "const %s hex bytes:",
567 pulongest (type
->length ()));
568 for (i
= 0; i
< type
->length (); i
++)
569 gdb_printf (outfile
, " %02x",
570 (unsigned) symbol
->value_bytes ()[i
]);
575 gdb_printf (outfile
, "static at ");
576 gdb_puts (paddress (gdbarch
, symbol
->value_address ()), outfile
);
578 gdb_printf (outfile
, " section %s",
579 bfd_section_name (section
->the_bfd_section
));
583 if (symbol
->is_argument ())
584 gdb_printf (outfile
, "parameter register %s",
585 plongest (symbol
->value_longest ()));
587 gdb_printf (outfile
, "register %s",
588 plongest (symbol
->value_longest ()));
592 gdb_printf (outfile
, "arg at offset %s",
593 hex_string (symbol
->value_longest ()));
597 gdb_printf (outfile
, "reference arg at %s",
598 hex_string (symbol
->value_longest ()));
601 case LOC_REGPARM_ADDR
:
602 gdb_printf (outfile
, "address parameter register %s",
603 plongest (symbol
->value_longest ()));
607 gdb_printf (outfile
, "local at offset %s",
608 hex_string (symbol
->value_longest ()));
615 gdb_printf (outfile
, "label at ");
616 gdb_puts (paddress (gdbarch
, symbol
->value_address ()), outfile
);
618 gdb_printf (outfile
, " section %s",
619 bfd_section_name (section
->the_bfd_section
));
624 (outfile
, "block object %s, %s..%s",
625 host_address_to_string (symbol
->value_block ()),
626 paddress (gdbarch
, symbol
->value_block()->start ()),
627 paddress (gdbarch
, symbol
->value_block()->end ()));
629 gdb_printf (outfile
, " section %s",
630 bfd_section_name (section
->the_bfd_section
));
634 gdb_printf (outfile
, "computed at runtime");
638 gdb_printf (outfile
, "unresolved");
641 case LOC_OPTIMIZED_OUT
:
642 gdb_printf (outfile
, "optimized out");
646 gdb_printf (outfile
, "botched symbol class %x",
651 gdb_printf (outfile
, "\n");
655 maintenance_print_msymbols (const char *args
, int from_tty
)
657 struct ui_file
*outfile
= gdb_stdout
;
658 char *objfile_arg
= NULL
;
663 gdb_argv
argv (args
);
665 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
667 if (strcmp (argv
[i
], "-objfile") == 0)
669 if (argv
[i
+ 1] == NULL
)
670 error (_("Missing objfile name"));
671 objfile_arg
= argv
[++i
];
673 else if (strcmp (argv
[i
], "--") == 0)
675 /* End of options. */
679 else if (argv
[i
][0] == '-')
681 /* Future proofing: Don't allow OUTFILE to begin with "-". */
682 error (_("Unknown option: %s"), argv
[i
]);
689 stdio_file arg_outfile
;
691 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
693 if (argv
[outfile_idx
+ 1] != NULL
)
694 error (_("Junk at end of command"));
695 gdb::unique_xmalloc_ptr
<char> outfile_name
696 (tilde_expand (argv
[outfile_idx
]));
697 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
698 perror_with_name (outfile_name
.get ());
699 outfile
= &arg_outfile
;
702 for (objfile
*objfile
: current_program_space
->objfiles ())
705 if (objfile_arg
== NULL
706 || compare_filenames_for_search (objfile_name (objfile
), objfile_arg
))
707 dump_msymbols (objfile
, outfile
);
712 maintenance_print_objfiles (const char *regexp
, int from_tty
)
719 for (struct program_space
*pspace
: program_spaces
)
720 for (objfile
*objfile
: pspace
->objfiles ())
724 || re_exec (objfile_name (objfile
)))
725 dump_objfile (objfile
);
729 /* List all the symbol tables whose names match REGEXP (optional). */
732 maintenance_info_symtabs (const char *regexp
, int from_tty
)
739 for (struct program_space
*pspace
: program_spaces
)
740 for (objfile
*objfile
: pspace
->objfiles ())
742 /* We don't want to print anything for this objfile until we
743 actually find a symtab whose name matches. */
744 int printed_objfile_start
= 0;
746 for (compunit_symtab
*cust
: objfile
->compunits ())
748 int printed_compunit_symtab_start
= 0;
750 for (symtab
*symtab
: cust
->filetabs ())
755 || re_exec (symtab_to_filename_for_display (symtab
)))
757 if (! printed_objfile_start
)
759 gdb_printf ("{ objfile %s ", objfile_name (objfile
));
760 gdb_stdout
->wrap_here (2);
761 gdb_printf ("((struct objfile *) %s)\n",
762 host_address_to_string (objfile
));
763 printed_objfile_start
= 1;
765 if (! printed_compunit_symtab_start
)
767 gdb_printf (" { ((struct compunit_symtab *) %s)\n",
768 host_address_to_string (cust
));
769 gdb_printf (" debugformat %s\n",
770 cust
->debugformat ());
771 gdb_printf (" producer %s\n",
772 (cust
->producer () != nullptr
773 ? cust
->producer () : "(null)"));
774 gdb_printf (" name %s\n", cust
->name
);
775 gdb_printf (" dirname %s\n",
776 (cust
->dirname () != NULL
777 ? cust
->dirname () : "(null)"));
778 gdb_printf (" blockvector"
779 " ((struct blockvector *) %s)\n",
780 host_address_to_string
781 (cust
->blockvector ()));
783 " ((struct compunit_symtab *) %s)\n",
784 cust
->user
!= nullptr
785 ? host_address_to_string (cust
->user
)
787 if (cust
->includes
!= nullptr)
789 gdb_printf (" ( includes\n");
790 for (int i
= 0; ; ++i
)
792 struct compunit_symtab
*include
794 if (include
== nullptr)
797 = host_address_to_string (include
);
798 gdb_printf (" (%s %s)\n",
799 "(struct compunit_symtab *)",
804 printed_compunit_symtab_start
= 1;
807 gdb_printf ("\t{ symtab %s ",
808 symtab_to_filename_for_display (symtab
));
809 gdb_stdout
->wrap_here (4);
810 gdb_printf ("((struct symtab *) %s)\n",
811 host_address_to_string (symtab
));
812 gdb_printf ("\t fullname %s\n",
813 symtab
->fullname () != nullptr
814 ? symtab
->fullname ()
817 "linetable ((struct linetable *) %s)\n",
818 host_address_to_string
819 (symtab
->linetable ()));
820 gdb_printf ("\t}\n");
824 if (printed_compunit_symtab_start
)
828 if (printed_objfile_start
)
833 /* Check consistency of symtabs.
834 An example of what this checks for is NULL blockvectors.
835 They can happen if there's a bug during debug info reading.
836 GDB assumes they are always non-NULL.
838 Note: This does not check for psymtab vs symtab consistency.
839 Use "maint check-psymtabs" for that. */
842 maintenance_check_symtabs (const char *ignore
, int from_tty
)
844 for (struct program_space
*pspace
: program_spaces
)
845 for (objfile
*objfile
: pspace
->objfiles ())
847 /* We don't want to print anything for this objfile until we
848 actually find something worth printing. */
849 int printed_objfile_start
= 0;
851 for (compunit_symtab
*cust
: objfile
->compunits ())
853 int found_something
= 0;
854 struct symtab
*symtab
= cust
->primary_filetab ();
858 if (cust
->blockvector () == NULL
)
860 /* Add more checks here. */
864 if (! printed_objfile_start
)
866 gdb_printf ("{ objfile %s ", objfile_name (objfile
));
867 gdb_stdout
->wrap_here (2);
868 gdb_printf ("((struct objfile *) %s)\n",
869 host_address_to_string (objfile
));
870 printed_objfile_start
= 1;
872 gdb_printf (" { symtab %s\n",
873 symtab_to_filename_for_display (symtab
));
874 if (cust
->blockvector () == NULL
)
875 gdb_printf (" NULL blockvector\n");
880 if (printed_objfile_start
)
885 /* Expand all symbol tables whose name matches an optional regexp. */
888 maintenance_expand_symtabs (const char *args
, int from_tty
)
892 /* We use buildargv here so that we handle spaces in the regexp
893 in a way that allows adding more arguments later. */
894 gdb_argv
argv (args
);
902 error (_("Extra arguments after regexp."));
909 for (struct program_space
*pspace
: program_spaces
)
910 for (objfile
*objfile
: pspace
->objfiles ())
911 objfile
->expand_symtabs_matching
912 ([&] (const char *filename
, bool basenames
)
914 /* KISS: Only apply the regexp to the complete file name. */
916 && (regexp
== NULL
|| re_exec (filename
)));
921 SEARCH_GLOBAL_BLOCK
| SEARCH_STATIC_BLOCK
,
926 /* Return the nexting depth of a block within other blocks in its symtab. */
929 block_depth (const struct block
*block
)
933 while ((block
= block
->superblock ()) != NULL
)
941 /* Used by MAINTENANCE_INFO_LINE_TABLES to print the information about a
942 single line table. */
945 maintenance_print_one_line_table (struct symtab
*symtab
, void *data
)
947 const struct linetable
*linetable
;
948 struct objfile
*objfile
;
950 objfile
= symtab
->compunit ()->objfile ();
951 gdb_printf (_("objfile: %ps ((struct objfile *) %s)\n"),
952 styled_string (file_name_style
.style (),
953 objfile_name (objfile
)),
954 host_address_to_string (objfile
));
955 gdb_printf (_("compunit_symtab: %s ((struct compunit_symtab *) %s)\n"),
956 symtab
->compunit ()->name
,
957 host_address_to_string (symtab
->compunit ()));
958 gdb_printf (_("symtab: %ps ((struct symtab *) %s)\n"),
959 styled_string (file_name_style
.style (),
960 symtab_to_fullname (symtab
)),
961 host_address_to_string (symtab
));
962 linetable
= symtab
->linetable ();
963 gdb_printf (_("linetable: ((struct linetable *) %s):\n"),
964 host_address_to_string (linetable
));
966 if (linetable
== NULL
)
967 gdb_printf (_("No line table.\n"));
968 else if (linetable
->nitems
<= 0)
969 gdb_printf (_("Line table has no lines.\n"));
972 /* Leave space for 6 digits of index and line number. After that the
973 tables will just not format as well. */
974 struct ui_out
*uiout
= current_uiout
;
975 ui_out_emit_table
table_emitter (uiout
, 7, -1, "line-table");
976 uiout
->table_header (6, ui_left
, "index", _("INDEX"));
977 uiout
->table_header (6, ui_left
, "line", _("LINE"));
978 uiout
->table_header (18, ui_left
, "rel-address", _("REL-ADDRESS"));
979 uiout
->table_header (18, ui_left
, "unrel-address", _("UNREL-ADDRESS"));
980 uiout
->table_header (7, ui_left
, "is-stmt", _("IS-STMT"));
981 uiout
->table_header (12, ui_left
, "prologue-end", _("PROLOGUE-END"));
982 uiout
->table_header (14, ui_left
, "epilogue-begin", _("EPILOGUE-BEGIN"));
983 uiout
->table_body ();
985 for (int i
= 0; i
< linetable
->nitems
; ++i
)
987 const linetable_entry
*item
;
989 item
= &linetable
->item
[i
];
990 ui_out_emit_tuple
tuple_emitter (uiout
, nullptr);
991 uiout
->field_signed ("index", i
);
993 uiout
->field_signed ("line", item
->line
);
995 uiout
->field_string ("line", _("END"));
996 uiout
->field_core_addr ("rel-address", objfile
->arch (),
998 uiout
->field_core_addr ("unrel-address", objfile
->arch (),
999 CORE_ADDR (item
->unrelocated_pc ()));
1000 uiout
->field_string ("is-stmt", item
->is_stmt
? "Y" : "");
1001 uiout
->field_string ("prologue-end", item
->prologue_end
? "Y" : "");
1002 uiout
->field_string ("epilogue-begin", item
->epilogue_begin
? "Y" : "");
1010 /* Implement the 'maint info line-table' command. */
1013 maintenance_info_line_tables (const char *regexp
, int from_tty
)
1020 for (struct program_space
*pspace
: program_spaces
)
1021 for (objfile
*objfile
: pspace
->objfiles ())
1023 for (compunit_symtab
*cust
: objfile
->compunits ())
1025 for (symtab
*symtab
: cust
->filetabs ())
1030 || re_exec (symtab_to_filename_for_display (symtab
)))
1032 maintenance_print_one_line_table (symtab
, NULL
);
1042 /* Do early runtime initializations. */
1044 void _initialize_symmisc ();
1046 _initialize_symmisc ()
1048 add_cmd ("symbols", class_maintenance
, maintenance_print_symbols
, _("\
1049 Print dump of current symbol definitions.\n\
1050 Usage: mt print symbols [-pc ADDRESS] [--] [OUTFILE]\n\
1051 mt print symbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
1052 Entries in the full symbol table are dumped to file OUTFILE,\n\
1053 or the terminal if OUTFILE is unspecified.\n\
1054 If ADDRESS is provided, dump only the symbols for the file with code at that address.\n\
1055 If SOURCE is provided, dump only that file's symbols.\n\
1056 If OBJFILE is provided, dump only that object file's symbols."),
1057 &maintenanceprintlist
);
1059 add_cmd ("msymbols", class_maintenance
, maintenance_print_msymbols
, _("\
1060 Print dump of current minimal symbol definitions.\n\
1061 Usage: mt print msymbols [-objfile OBJFILE] [--] [OUTFILE]\n\
1062 Entries in the minimal symbol table are dumped to file OUTFILE,\n\
1063 or the terminal if OUTFILE is unspecified.\n\
1064 If OBJFILE is provided, dump only that file's minimal symbols."),
1065 &maintenanceprintlist
);
1067 add_cmd ("objfiles", class_maintenance
, maintenance_print_objfiles
,
1068 _("Print dump of current object file definitions.\n\
1069 With an argument REGEXP, list the object files with matching names."),
1070 &maintenanceprintlist
);
1072 add_cmd ("symtabs", class_maintenance
, maintenance_info_symtabs
, _("\
1073 List the full symbol tables for all object files.\n\
1074 This does not include information about individual symbols, blocks, or\n\
1075 linetables --- just the symbol table structures themselves.\n\
1076 With an argument REGEXP, list the symbol tables with matching names."),
1077 &maintenanceinfolist
);
1079 add_cmd ("line-table", class_maintenance
, maintenance_info_line_tables
, _("\
1080 List the contents of all line tables, from all symbol tables.\n\
1081 With an argument REGEXP, list just the line tables for the symbol\n\
1082 tables with matching names."),
1083 &maintenanceinfolist
);
1085 add_cmd ("check-symtabs", class_maintenance
, maintenance_check_symtabs
,
1087 Check consistency of currently expanded symtabs."),
1090 add_cmd ("expand-symtabs", class_maintenance
, maintenance_expand_symtabs
,
1091 _("Expand symbol tables.\n\
1092 With an argument REGEXP, only expand the symbol tables with matching names."),