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 struct program_space
*pspace
;
67 for (objfile
*objfile
: pspace
->objfiles ())
70 printf_filtered (_("Byte cache statistics for '%s':\n"),
71 objfile_name (objfile
));
72 objfile
->partial_symtabs
->psymbol_cache
.print_statistics
73 ("partial symbol cache");
74 objfile
->per_bfd
->macro_cache
.print_statistics
75 ("preprocessor macro cache");
76 objfile
->per_bfd
->filename_cache
.print_statistics ("file name cache");
81 print_objfile_statistics (void)
83 struct program_space
*pspace
;
84 int i
, linetables
, blockvectors
;
87 for (objfile
*objfile
: pspace
->objfiles ())
90 printf_filtered (_("Statistics for '%s':\n"), objfile_name (objfile
));
91 if (OBJSTAT (objfile
, n_stabs
) > 0)
92 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
93 OBJSTAT (objfile
, n_stabs
));
94 if (objfile
->per_bfd
->n_minsyms
> 0)
95 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
96 objfile
->per_bfd
->n_minsyms
);
97 if (OBJSTAT (objfile
, n_psyms
) > 0)
98 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
99 OBJSTAT (objfile
, n_psyms
));
100 if (OBJSTAT (objfile
, n_syms
) > 0)
101 printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
102 OBJSTAT (objfile
, n_syms
));
103 if (OBJSTAT (objfile
, n_types
) > 0)
104 printf_filtered (_(" Number of \"types\" defined: %d\n"),
105 OBJSTAT (objfile
, n_types
));
107 objfile
->sf
->qf
->print_stats (objfile
);
109 for (compunit_symtab
*cu
: objfile
->compunits ())
111 for (symtab
*s
: compunit_filetabs (cu
))
114 if (SYMTAB_LINETABLE (s
) != NULL
)
118 blockvectors
= std::distance (objfile
->compunits ().begin (),
119 objfile
->compunits ().end ());
120 printf_filtered (_(" Number of symbol tables: %d\n"), i
);
121 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
123 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
126 if (OBJSTAT (objfile
, sz_strtab
) > 0)
127 printf_filtered (_(" Space used by string tables: %d\n"),
128 OBJSTAT (objfile
, sz_strtab
));
129 printf_filtered (_(" Total memory used for objfile obstack: %s\n"),
130 pulongest (obstack_memory_used (&objfile
131 ->objfile_obstack
)));
132 printf_filtered (_(" Total memory used for BFD obstack: %s\n"),
133 pulongest (obstack_memory_used (&objfile
->per_bfd
134 ->storage_obstack
)));
136 (_(" Total memory used for psymbol cache: %d\n"),
137 objfile
->partial_symtabs
->psymbol_cache
.memory_used ());
138 printf_filtered (_(" Total memory used for macro cache: %d\n"),
139 objfile
->per_bfd
->macro_cache
.memory_used ());
140 printf_filtered (_(" Total memory used for file name cache: %d\n"),
141 objfile
->per_bfd
->filename_cache
.memory_used ());
146 dump_objfile (struct objfile
*objfile
)
148 printf_filtered ("\nObject file %s: ", objfile_name (objfile
));
149 printf_filtered ("Objfile at ");
150 gdb_print_host_address (objfile
, gdb_stdout
);
151 printf_filtered (", bfd at ");
152 gdb_print_host_address (objfile
->obfd
, gdb_stdout
);
153 printf_filtered (", %d minsyms\n\n",
154 objfile
->per_bfd
->minimal_symbol_count
);
157 objfile
->sf
->qf
->dump (objfile
);
159 if (objfile
->compunit_symtabs
!= NULL
)
161 printf_filtered ("Symtabs:\n");
162 for (compunit_symtab
*cu
: objfile
->compunits ())
164 for (symtab
*symtab
: compunit_filetabs (cu
))
166 printf_filtered ("%s at ",
167 symtab_to_filename_for_display (symtab
));
168 gdb_print_host_address (symtab
, gdb_stdout
);
169 printf_filtered (", ");
170 if (SYMTAB_OBJFILE (symtab
) != objfile
)
172 printf_filtered ("NOT ON CHAIN! ");
177 printf_filtered ("\n\n");
181 /* Print minimal symbols from this objfile. */
184 dump_msymbols (struct objfile
*objfile
, struct ui_file
*outfile
)
186 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
190 fprintf_filtered (outfile
, "\nObject file %s:\n\n", objfile_name (objfile
));
191 if (objfile
->per_bfd
->minimal_symbol_count
== 0)
193 fprintf_filtered (outfile
, "No minimal symbols found.\n");
197 for (minimal_symbol
*msymbol
: objfile
->msymbols ())
199 struct obj_section
*section
= MSYMBOL_OBJ_SECTION (objfile
, msymbol
);
201 switch (MSYMBOL_TYPE (msymbol
))
209 case mst_text_gnu_ifunc
:
210 case mst_data_gnu_ifunc
:
213 case mst_solib_trampoline
:
238 fprintf_filtered (outfile
, "[%2d] %c ", index
, ms_type
);
240 /* Use the relocated address as shown in the symbol here -- do
241 not try to respect copy relocations. */
242 CORE_ADDR addr
= (msymbol
->value
.address
243 + objfile
->section_offsets
[msymbol
->section
]);
244 fputs_filtered (paddress (gdbarch
, addr
), outfile
);
245 fprintf_filtered (outfile
, " %s", msymbol
->linkage_name ());
248 if (section
->the_bfd_section
!= NULL
)
249 fprintf_filtered (outfile
, " section %s",
250 bfd_section_name (section
->the_bfd_section
));
252 fprintf_filtered (outfile
, " spurious section %ld",
253 (long) (section
- objfile
->sections
));
255 if (msymbol
->demangled_name () != NULL
)
257 fprintf_filtered (outfile
, " %s", msymbol
->demangled_name ());
259 if (msymbol
->filename
)
260 fprintf_filtered (outfile
, " %s", msymbol
->filename
);
261 fputs_filtered ("\n", outfile
);
264 if (objfile
->per_bfd
->minimal_symbol_count
!= index
)
266 warning (_("internal error: minimal symbol count %d != %d"),
267 objfile
->per_bfd
->minimal_symbol_count
, index
);
269 fprintf_filtered (outfile
, "\n");
273 dump_symtab_1 (struct symtab
*symtab
, struct ui_file
*outfile
)
275 struct objfile
*objfile
= SYMTAB_OBJFILE (symtab
);
276 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
278 struct mdict_iterator miter
;
281 const struct blockvector
*bv
;
283 const struct block
*b
;
286 fprintf_filtered (outfile
, "\nSymtab for file %s\n",
287 symtab_to_filename_for_display (symtab
));
288 if (SYMTAB_DIRNAME (symtab
) != NULL
)
289 fprintf_filtered (outfile
, "Compilation directory is %s\n",
290 SYMTAB_DIRNAME (symtab
));
291 fprintf_filtered (outfile
, "Read from object file %s (",
292 objfile_name (objfile
));
293 gdb_print_host_address (objfile
, outfile
);
294 fprintf_filtered (outfile
, ")\n");
295 fprintf_filtered (outfile
, "Language: %s\n",
296 language_str (symtab
->language
));
298 /* First print the line table. */
299 l
= SYMTAB_LINETABLE (symtab
);
302 fprintf_filtered (outfile
, "\nLine table:\n\n");
304 for (i
= 0; i
< len
; i
++)
306 fprintf_filtered (outfile
, " line %d at ", l
->item
[i
].line
);
307 fputs_filtered (paddress (gdbarch
, l
->item
[i
].pc
), outfile
);
308 fprintf_filtered (outfile
, "\n");
311 /* Now print the block info, but only for compunit symtabs since we will
312 print lots of duplicate info otherwise. */
313 if (symtab
== COMPUNIT_FILETABS (SYMTAB_COMPUNIT (symtab
)))
315 fprintf_filtered (outfile
, "\nBlockvector:\n\n");
316 bv
= SYMTAB_BLOCKVECTOR (symtab
);
317 len
= BLOCKVECTOR_NBLOCKS (bv
);
318 for (i
= 0; i
< len
; i
++)
320 b
= BLOCKVECTOR_BLOCK (bv
, i
);
321 depth
= block_depth (b
) * 2;
322 print_spaces (depth
, outfile
);
323 fprintf_filtered (outfile
, "block #%03d, object at ", i
);
324 gdb_print_host_address (b
, outfile
);
325 if (BLOCK_SUPERBLOCK (b
))
327 fprintf_filtered (outfile
, " under ");
328 gdb_print_host_address (BLOCK_SUPERBLOCK (b
), outfile
);
330 /* drow/2002-07-10: We could save the total symbols count
331 even if we're using a hashtable, but nothing else but this message
333 fprintf_filtered (outfile
, ", %d syms/buckets in ",
334 mdict_size (BLOCK_MULTIDICT (b
)));
335 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), outfile
);
336 fprintf_filtered (outfile
, "..");
337 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), outfile
);
338 if (BLOCK_FUNCTION (b
))
340 fprintf_filtered (outfile
, ", function %s",
341 BLOCK_FUNCTION (b
)->linkage_name ());
342 if (BLOCK_FUNCTION (b
)->demangled_name () != NULL
)
344 fprintf_filtered (outfile
, ", %s",
345 BLOCK_FUNCTION (b
)->demangled_name ());
348 fprintf_filtered (outfile
, "\n");
349 /* Now print each symbol in this block (in no particular order, if
350 we're using a hashtable). Note that we only want this
351 block, not any blocks from included symtabs. */
352 ALL_DICT_SYMBOLS (BLOCK_MULTIDICT (b
), miter
, sym
)
356 print_symbol (gdbarch
, sym
, depth
+ 1, outfile
);
358 catch (const gdb_exception_error
&ex
)
360 exception_fprintf (gdb_stderr
, ex
,
361 "Error printing symbol:\n");
365 fprintf_filtered (outfile
, "\n");
369 const char *compunit_filename
370 = symtab_to_filename_for_display (COMPUNIT_FILETABS (SYMTAB_COMPUNIT (symtab
)));
372 fprintf_filtered (outfile
,
373 "\nBlockvector same as owning compunit: %s\n\n",
379 dump_symtab (struct symtab
*symtab
, struct ui_file
*outfile
)
381 /* Set the current language to the language of the symtab we're dumping
382 because certain routines used during dump_symtab() use the current
383 language to print an image of the symbol. We'll restore it later.
384 But use only real languages, not placeholders. */
385 if (symtab
->language
!= language_unknown
386 && symtab
->language
!= language_auto
)
388 scoped_restore_current_language save_lang
;
389 set_language (symtab
->language
);
390 dump_symtab_1 (symtab
, outfile
);
393 dump_symtab_1 (symtab
, outfile
);
397 maintenance_print_symbols (const char *args
, int from_tty
)
399 struct ui_file
*outfile
= gdb_stdout
;
400 char *address_arg
= NULL
, *source_arg
= NULL
, *objfile_arg
= NULL
;
405 gdb_argv
argv (args
);
407 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
409 if (strcmp (argv
[i
], "-pc") == 0)
411 if (argv
[i
+ 1] == NULL
)
412 error (_("Missing pc value"));
413 address_arg
= argv
[++i
];
415 else if (strcmp (argv
[i
], "-source") == 0)
417 if (argv
[i
+ 1] == NULL
)
418 error (_("Missing source file"));
419 source_arg
= argv
[++i
];
421 else if (strcmp (argv
[i
], "-objfile") == 0)
423 if (argv
[i
+ 1] == NULL
)
424 error (_("Missing objfile name"));
425 objfile_arg
= argv
[++i
];
427 else if (strcmp (argv
[i
], "--") == 0)
429 /* End of options. */
433 else if (argv
[i
][0] == '-')
435 /* Future proofing: Don't allow OUTFILE to begin with "-". */
436 error (_("Unknown option: %s"), argv
[i
]);
443 if (address_arg
!= NULL
&& source_arg
!= NULL
)
444 error (_("Must specify at most one of -pc and -source"));
446 stdio_file arg_outfile
;
448 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
450 if (argv
[outfile_idx
+ 1] != NULL
)
451 error (_("Junk at end of command"));
452 gdb::unique_xmalloc_ptr
<char> outfile_name
453 (tilde_expand (argv
[outfile_idx
]));
454 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
455 perror_with_name (outfile_name
.get ());
456 outfile
= &arg_outfile
;
459 if (address_arg
!= NULL
)
461 CORE_ADDR pc
= parse_and_eval_address (address_arg
);
462 struct symtab
*s
= find_pc_line_symtab (pc
);
465 error (_("No symtab for address: %s"), address_arg
);
466 dump_symtab (s
, outfile
);
472 for (objfile
*objfile
: current_program_space
->objfiles ())
474 int print_for_objfile
= 1;
476 if (objfile_arg
!= NULL
)
478 = compare_filenames_for_search (objfile_name (objfile
),
480 if (!print_for_objfile
)
483 for (compunit_symtab
*cu
: objfile
->compunits ())
485 for (symtab
*s
: compunit_filetabs (cu
))
487 int print_for_source
= 0;
490 if (source_arg
!= NULL
)
493 = compare_filenames_for_search
494 (symtab_to_filename_for_display (s
), source_arg
);
497 if (source_arg
== NULL
499 dump_symtab (s
, outfile
);
504 if (source_arg
!= NULL
&& !found
)
505 error (_("No symtab for source file: %s"), source_arg
);
509 /* Print symbol SYMBOL on OUTFILE. DEPTH says how far to indent. */
512 print_symbol (struct gdbarch
*gdbarch
, struct symbol
*symbol
,
513 int depth
, ui_file
*outfile
)
515 struct obj_section
*section
;
517 if (SYMBOL_OBJFILE_OWNED (symbol
))
518 section
= SYMBOL_OBJ_SECTION (symbol_objfile (symbol
), symbol
);
522 print_spaces (depth
, outfile
);
523 if (SYMBOL_DOMAIN (symbol
) == LABEL_DOMAIN
)
525 fprintf_filtered (outfile
, "label %s at ", symbol
->print_name ());
526 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
529 fprintf_filtered (outfile
, " section %s\n",
530 bfd_section_name (section
->the_bfd_section
));
532 fprintf_filtered (outfile
, "\n");
536 if (SYMBOL_DOMAIN (symbol
) == STRUCT_DOMAIN
)
538 if (TYPE_NAME (SYMBOL_TYPE (symbol
)))
540 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
,
541 &type_print_raw_options
);
545 fprintf_filtered (outfile
, "%s %s = ",
546 (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_ENUM
548 : (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_STRUCT
549 ? "struct" : "union")),
550 symbol
->linkage_name ());
551 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
,
552 &type_print_raw_options
);
554 fprintf_filtered (outfile
, ";\n");
558 if (SYMBOL_CLASS (symbol
) == LOC_TYPEDEF
)
559 fprintf_filtered (outfile
, "typedef ");
560 if (SYMBOL_TYPE (symbol
))
562 /* Print details of types, except for enums where it's clutter. */
563 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), symbol
->print_name (),
565 TYPE_CODE (SYMBOL_TYPE (symbol
)) != TYPE_CODE_ENUM
,
567 &type_print_raw_options
);
568 fprintf_filtered (outfile
, "; ");
571 fprintf_filtered (outfile
, "%s ", symbol
->print_name ());
573 switch (SYMBOL_CLASS (symbol
))
576 fprintf_filtered (outfile
, "const %s (%s)",
577 plongest (SYMBOL_VALUE (symbol
)),
578 hex_string (SYMBOL_VALUE (symbol
)));
581 case LOC_CONST_BYTES
:
584 struct type
*type
= check_typedef (SYMBOL_TYPE (symbol
));
586 fprintf_filtered (outfile
, "const %s hex bytes:",
587 pulongest (TYPE_LENGTH (type
)));
588 for (i
= 0; i
< TYPE_LENGTH (type
); i
++)
589 fprintf_filtered (outfile
, " %02x",
590 (unsigned) SYMBOL_VALUE_BYTES (symbol
)[i
]);
595 fprintf_filtered (outfile
, "static at ");
596 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
599 fprintf_filtered (outfile
, " section %s",
600 bfd_section_name (section
->the_bfd_section
));
604 if (SYMBOL_IS_ARGUMENT (symbol
))
605 fprintf_filtered (outfile
, "parameter register %s",
606 plongest (SYMBOL_VALUE (symbol
)));
608 fprintf_filtered (outfile
, "register %s",
609 plongest (SYMBOL_VALUE (symbol
)));
613 fprintf_filtered (outfile
, "arg at offset %s",
614 hex_string (SYMBOL_VALUE (symbol
)));
618 fprintf_filtered (outfile
, "reference arg at %s",
619 hex_string (SYMBOL_VALUE (symbol
)));
622 case LOC_REGPARM_ADDR
:
623 fprintf_filtered (outfile
, "address parameter register %s",
624 plongest (SYMBOL_VALUE (symbol
)));
628 fprintf_filtered (outfile
, "local at offset %s",
629 hex_string (SYMBOL_VALUE (symbol
)));
636 fprintf_filtered (outfile
, "label at ");
637 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
640 fprintf_filtered (outfile
, " section %s",
641 bfd_section_name (section
->the_bfd_section
));
645 fprintf_filtered (outfile
, "block object ");
646 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol
), outfile
);
647 fprintf_filtered (outfile
, ", ");
648 fputs_filtered (paddress (gdbarch
,
649 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
))),
651 fprintf_filtered (outfile
, "..");
652 fputs_filtered (paddress (gdbarch
,
653 BLOCK_END (SYMBOL_BLOCK_VALUE (symbol
))),
656 fprintf_filtered (outfile
, " section %s",
657 bfd_section_name (section
->the_bfd_section
));
661 fprintf_filtered (outfile
, "computed at runtime");
665 fprintf_filtered (outfile
, "unresolved");
668 case LOC_OPTIMIZED_OUT
:
669 fprintf_filtered (outfile
, "optimized out");
673 fprintf_filtered (outfile
, "botched symbol class %x",
674 SYMBOL_CLASS (symbol
));
678 fprintf_filtered (outfile
, "\n");
682 maintenance_print_msymbols (const char *args
, int from_tty
)
684 struct ui_file
*outfile
= gdb_stdout
;
685 char *objfile_arg
= NULL
;
690 gdb_argv
argv (args
);
692 for (i
= 0; argv
!= NULL
&& argv
[i
] != NULL
; ++i
)
694 if (strcmp (argv
[i
], "-objfile") == 0)
696 if (argv
[i
+ 1] == NULL
)
697 error (_("Missing objfile name"));
698 objfile_arg
= argv
[++i
];
700 else if (strcmp (argv
[i
], "--") == 0)
702 /* End of options. */
706 else if (argv
[i
][0] == '-')
708 /* Future proofing: Don't allow OUTFILE to begin with "-". */
709 error (_("Unknown option: %s"), argv
[i
]);
716 stdio_file arg_outfile
;
718 if (argv
!= NULL
&& argv
[outfile_idx
] != NULL
)
720 if (argv
[outfile_idx
+ 1] != NULL
)
721 error (_("Junk at end of command"));
722 gdb::unique_xmalloc_ptr
<char> outfile_name
723 (tilde_expand (argv
[outfile_idx
]));
724 if (!arg_outfile
.open (outfile_name
.get (), FOPEN_WT
))
725 perror_with_name (outfile_name
.get ());
726 outfile
= &arg_outfile
;
729 for (objfile
*objfile
: current_program_space
->objfiles ())
732 if (objfile_arg
== NULL
733 || compare_filenames_for_search (objfile_name (objfile
), objfile_arg
))
734 dump_msymbols (objfile
, outfile
);
739 maintenance_print_objfiles (const char *regexp
, int from_tty
)
741 struct program_space
*pspace
;
749 for (objfile
*objfile
: pspace
->objfiles ())
753 || re_exec (objfile_name (objfile
)))
754 dump_objfile (objfile
);
758 /* List all the symbol tables whose names match REGEXP (optional). */
761 maintenance_info_symtabs (const char *regexp
, int from_tty
)
763 struct program_space
*pspace
;
771 for (objfile
*objfile
: pspace
->objfiles ())
773 /* We don't want to print anything for this objfile until we
774 actually find a symtab whose name matches. */
775 int printed_objfile_start
= 0;
777 for (compunit_symtab
*cust
: objfile
->compunits ())
779 int printed_compunit_symtab_start
= 0;
781 for (symtab
*symtab
: compunit_filetabs (cust
))
786 || re_exec (symtab_to_filename_for_display (symtab
)))
788 if (! printed_objfile_start
)
790 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
792 printf_filtered ("((struct objfile *) %s)\n",
793 host_address_to_string (objfile
));
794 printed_objfile_start
= 1;
796 if (! printed_compunit_symtab_start
)
798 printf_filtered (" { ((struct compunit_symtab *) %s)\n",
799 host_address_to_string (cust
));
800 printf_filtered (" debugformat %s\n",
801 COMPUNIT_DEBUGFORMAT (cust
));
802 printf_filtered (" producer %s\n",
803 COMPUNIT_PRODUCER (cust
) != NULL
804 ? COMPUNIT_PRODUCER (cust
)
806 printf_filtered (" dirname %s\n",
807 COMPUNIT_DIRNAME (cust
) != NULL
808 ? COMPUNIT_DIRNAME (cust
)
810 printf_filtered (" blockvector"
811 " ((struct blockvector *) %s)\n",
812 host_address_to_string
813 (COMPUNIT_BLOCKVECTOR (cust
)));
814 printed_compunit_symtab_start
= 1;
817 printf_filtered ("\t{ symtab %s ",
818 symtab_to_filename_for_display (symtab
));
820 printf_filtered ("((struct symtab *) %s)\n",
821 host_address_to_string (symtab
));
822 printf_filtered ("\t fullname %s\n",
823 symtab
->fullname
!= NULL
826 printf_filtered ("\t "
827 "linetable ((struct linetable *) %s)\n",
828 host_address_to_string (symtab
->linetable
));
829 printf_filtered ("\t}\n");
833 if (printed_compunit_symtab_start
)
834 printf_filtered (" }\n");
837 if (printed_objfile_start
)
838 printf_filtered ("}\n");
842 /* Check consistency of symtabs.
843 An example of what this checks for is NULL blockvectors.
844 They can happen if there's a bug during debug info reading.
845 GDB assumes they are always non-NULL.
847 Note: This does not check for psymtab vs symtab consistency.
848 Use "maint check-psymtabs" for that. */
851 maintenance_check_symtabs (const char *ignore
, int from_tty
)
853 struct program_space
*pspace
;
856 for (objfile
*objfile
: pspace
->objfiles ())
858 /* We don't want to print anything for this objfile until we
859 actually find something worth printing. */
860 int printed_objfile_start
= 0;
862 for (compunit_symtab
*cust
: objfile
->compunits ())
864 int found_something
= 0;
865 struct symtab
*symtab
= compunit_primary_filetab (cust
);
869 if (COMPUNIT_BLOCKVECTOR (cust
) == NULL
)
871 /* Add more checks here. */
875 if (! printed_objfile_start
)
877 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
879 printf_filtered ("((struct objfile *) %s)\n",
880 host_address_to_string (objfile
));
881 printed_objfile_start
= 1;
883 printf_filtered (" { symtab %s\n",
884 symtab_to_filename_for_display (symtab
));
885 if (COMPUNIT_BLOCKVECTOR (cust
) == NULL
)
886 printf_filtered (" NULL blockvector\n");
887 printf_filtered (" }\n");
891 if (printed_objfile_start
)
892 printf_filtered ("}\n");
896 /* Expand all symbol tables whose name matches an optional regexp. */
899 maintenance_expand_symtabs (const char *args
, int from_tty
)
901 struct program_space
*pspace
;
904 /* We use buildargv here so that we handle spaces in the regexp
905 in a way that allows adding more arguments later. */
906 gdb_argv
argv (args
);
914 error (_("Extra arguments after regexp."));
922 for (objfile
*objfile
: pspace
->objfiles ())
926 objfile
->sf
->qf
->expand_symtabs_matching
928 [&] (const char *filename
, bool basenames
)
930 /* KISS: Only apply the regexp to the complete file name. */
932 && (regexp
== NULL
|| re_exec (filename
)));
934 lookup_name_info::match_any (),
935 [] (const char *symname
)
937 /* Since we're not searching on symbols, just return true. */
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"));
992 /* Leave space for 6 digits of index and line number. After that the
993 tables will just not format as well. */
994 printf_filtered (_("%-6s %6s %s\n"),
995 _("INDEX"), _("LINE"), _("ADDRESS"));
997 for (i
= 0; i
< linetable
->nitems
; ++i
)
999 struct linetable_entry
*item
;
1001 item
= &linetable
->item
[i
];
1002 printf_filtered (_("%-6d %6d %s\n"), i
, item
->line
,
1003 core_addr_to_string (item
->pc
));
1010 /* Implement the 'maint info line-table' command. */
1013 maintenance_info_line_tables (const char *regexp
, int from_tty
)
1015 struct program_space
*pspace
;
1022 ALL_PSPACES (pspace
)
1023 for (objfile
*objfile
: pspace
->objfiles ())
1025 for (compunit_symtab
*cust
: objfile
->compunits ())
1027 for (symtab
*symtab
: compunit_filetabs (cust
))
1032 || re_exec (symtab_to_filename_for_display (symtab
)))
1033 maintenance_print_one_line_table (symtab
, NULL
);
1041 /* Do early runtime initializations. */
1044 _initialize_symmisc (void)
1050 add_cmd ("symbols", class_maintenance
, maintenance_print_symbols
, _("\
1051 Print dump of current symbol definitions.\n\
1052 Usage: mt print symbols [-pc ADDRESS] [--] [OUTFILE]\n\
1053 mt print symbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
1054 Entries in the full symbol table are dumped to file OUTFILE,\n\
1055 or the terminal if OUTFILE is unspecified.\n\
1056 If ADDRESS is provided, dump only the file for that address.\n\
1057 If SOURCE is provided, dump only that file's symbols.\n\
1058 If OBJFILE is provided, dump only that file's minimal symbols."),
1059 &maintenanceprintlist
);
1061 add_cmd ("msymbols", class_maintenance
, maintenance_print_msymbols
, _("\
1062 Print dump of current minimal symbol definitions.\n\
1063 Usage: mt print msymbols [-objfile OBJFILE] [--] [OUTFILE]\n\
1064 Entries in the minimal symbol table are dumped to file OUTFILE,\n\
1065 or the terminal if OUTFILE is unspecified.\n\
1066 If OBJFILE is provided, dump only that file's minimal symbols."),
1067 &maintenanceprintlist
);
1069 add_cmd ("objfiles", class_maintenance
, maintenance_print_objfiles
,
1070 _("Print dump of current object file definitions.\n\
1071 With an argument REGEXP, list the object files with matching names."),
1072 &maintenanceprintlist
);
1074 add_cmd ("symtabs", class_maintenance
, maintenance_info_symtabs
, _("\
1075 List the full symbol tables for all object files.\n\
1076 This does not include information about individual symbols, blocks, or\n\
1077 linetables --- just the symbol table structures themselves.\n\
1078 With an argument REGEXP, list the symbol tables with matching names."),
1079 &maintenanceinfolist
);
1081 add_cmd ("line-table", class_maintenance
, maintenance_info_line_tables
, _("\
1082 List the contents of all line tables, from all symbol tables.\n\
1083 With an argument REGEXP, list just the line tables for the symbol\n\
1084 tables with matching names."),
1085 &maintenanceinfolist
);
1087 add_cmd ("check-symtabs", class_maintenance
, maintenance_check_symtabs
,
1089 Check consistency of currently expanded symtabs."),
1092 add_cmd ("expand-symtabs", class_maintenance
, maintenance_expand_symtabs
,
1093 _("Expand symbol tables.\n\
1094 With an argument REGEXP, only expand the symbol tables with matching names."),