GDB (xrefs)
Loading...
Searching...
No Matches
/tmp/gdb-13.1/gdb/symmisc.c
Go to the documentation of this file.
1/* Do various things to symbol tables (other than lookup), for GDB.
2
3 Copyright (C) 1986-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20#include "defs.h"
21#include "symtab.h"
22#include "gdbtypes.h"
23#include "bfd.h"
24#include "filenames.h"
25#include "symfile.h"
26#include "objfiles.h"
27#include "breakpoint.h"
28#include "command.h"
29#include "gdbsupport/gdb_obstack.h"
30#include "language.h"
31#include "bcache.h"
32#include "block.h"
33#include "gdbsupport/gdb_regex.h"
34#include <sys/stat.h>
35#include "dictionary.h"
36#include "typeprint.h"
37#include "gdbcmd.h"
38#include "source.h"
39#include "readline/tilde.h"
40#include <cli/cli-style.h>
41#include "gdbsupport/buildargv.h"
42
43/* Prototypes for local functions */
44
45static int block_depth (const struct block *);
46
47static void print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
48 int depth, ui_file *outfile);
49
50
51void
53{
54 int i, linetables, blockvectors;
55
56 for (struct program_space *pspace : program_spaces)
57 for (objfile *objfile : pspace->objfiles ())
58 {
59 QUIT;
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"),
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));
73
74 i = linetables = 0;
75 for (compunit_symtab *cu : objfile->compunits ())
76 {
77 for (symtab *s : cu->filetabs ())
78 {
79 i++;
80 if (s->linetable () != NULL)
81 linetables++;
82 }
83 }
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"),
88 linetables);
89 gdb_printf (_(" Number of symbol tables with blockvectors: %d\n"),
90 blockvectors);
91
92 objfile->print_stats (false);
93
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
99 ->objfile_obstack)));
100 gdb_printf (_(" Total memory used for BFD obstack: %s\n"),
101 pulongest (obstack_memory_used (&objfile->per_bfd
102 ->storage_obstack)));
103
104 gdb_printf (_(" Total memory used for string cache: %d\n"),
106 gdb_printf (_("Byte cache statistics for '%s':\n"),
108 objfile->per_bfd->string_cache.print_statistics ("string cache");
109 objfile->print_stats (true);
110 }
111}
112
113static void
115{
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.get ()),
121
122 objfile->dump ();
123
124 if (objfile->compunit_symtabs != NULL)
125 {
126 gdb_printf ("Symtabs:\n");
127 for (compunit_symtab *cu : objfile->compunits ())
128 {
129 for (symtab *symtab : cu->filetabs ())
130 {
131 gdb_printf ("%s at %s",
133 host_address_to_string (symtab));
134 if (symtab->compunit ()->objfile () != objfile)
135 gdb_printf (", NOT ON CHAIN!");
136 gdb_printf ("\n");
137 }
138 }
139 gdb_printf ("\n\n");
140 }
141}
142
143/* Print minimal symbols from this objfile. */
144
145static void
146dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
147{
148 struct gdbarch *gdbarch = objfile->arch ();
149 int index;
150 char ms_type;
151
152 gdb_printf (outfile, "\nObject file %s:\n\n", objfile_name (objfile));
154 {
155 gdb_printf (outfile, "No minimal symbols found.\n");
156 return;
157 }
158 index = 0;
159 for (minimal_symbol *msymbol : objfile->msymbols ())
160 {
161 struct obj_section *section = msymbol->obj_section (objfile);
162
163 switch (msymbol->type ())
164 {
165 case mst_unknown:
166 ms_type = 'u';
167 break;
168 case mst_text:
169 ms_type = 'T';
170 break;
173 ms_type = 'i';
174 break;
176 ms_type = 'S';
177 break;
178 case mst_data:
179 ms_type = 'D';
180 break;
181 case mst_bss:
182 ms_type = 'B';
183 break;
184 case mst_abs:
185 ms_type = 'A';
186 break;
187 case mst_file_text:
188 ms_type = 't';
189 break;
190 case mst_file_data:
191 ms_type = 'd';
192 break;
193 case mst_file_bss:
194 ms_type = 'b';
195 break;
196 default:
197 ms_type = '?';
198 break;
199 }
200 gdb_printf (outfile, "[%2d] %c ", index, ms_type);
201
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 ());
208 if (section)
209 {
210 if (section->the_bfd_section != NULL)
211 gdb_printf (outfile, " section %s",
212 bfd_section_name (section->the_bfd_section));
213 else
214 gdb_printf (outfile, " spurious section %ld",
215 (long) (section - objfile->sections));
216 }
217 if (msymbol->demangled_name () != NULL)
218 {
219 gdb_printf (outfile, " %s", msymbol->demangled_name ());
220 }
221 if (msymbol->filename)
222 gdb_printf (outfile, " %s", msymbol->filename);
223 gdb_puts ("\n", outfile);
224 index++;
225 }
226 if (objfile->per_bfd->minimal_symbol_count != index)
227 {
228 warning (_("internal error: minimal symbol count %d != %d"),
230 }
231 gdb_printf (outfile, "\n");
232}
233
234static void
235dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
236{
237 struct objfile *objfile = symtab->compunit ()->objfile ();
238 struct gdbarch *gdbarch = objfile->arch ();
239 struct mdict_iterator miter;
240 struct linetable *l;
241 struct symbol *sym;
242 int depth;
243
244 gdb_printf (outfile, "\nSymtab for file %s at %s\n",
246 host_address_to_string (symtab));
247
248 if (symtab->compunit ()->dirname () != NULL)
249 gdb_printf (outfile, "Compilation directory is %s\n",
250 symtab->compunit ()->dirname ());
251 gdb_printf (outfile, "Read from object file %s (%s)\n",
253 host_address_to_string (objfile));
254 gdb_printf (outfile, "Language: %s\n",
256
257 /* First print the line table. */
258 l = symtab->linetable ();
259 if (l)
260 {
261 gdb_printf (outfile, "\nLine table:\n\n");
262 int len = l->nitems;
263 for (int i = 0; i < len; i++)
264 {
265 gdb_printf (outfile, " line %d at ", l->item[i].line);
266 gdb_puts (paddress (gdbarch, l->item[i].pc), outfile);
267 if (l->item[i].is_stmt)
268 gdb_printf (outfile, "\t(stmt)");
269 gdb_printf (outfile, "\n");
270 }
271 }
272 /* Now print the block info, but only for compunit symtabs since we will
273 print lots of duplicate info otherwise. */
275 {
276 gdb_printf (outfile, "\nBlockvector:\n\n");
277 const blockvector *bv = symtab->compunit ()->blockvector ();
278 for (int i = 0; i < bv->num_blocks (); i++)
279 {
280 const block *b = bv->block (i);
281 depth = block_depth (b) * 2;
282 gdb_printf (outfile, "%*sblock #%03d, object at %s",
283 depth, "", i,
284 host_address_to_string (b));
285 if (b->superblock ())
286 gdb_printf (outfile, " under %s",
287 host_address_to_string (b->superblock ()));
288 /* drow/2002-07-10: We could save the total symbols count
289 even if we're using a hashtable, but nothing else but this message
290 wants it. */
291 gdb_printf (outfile, ", %d syms/buckets in ",
292 mdict_size (b->multidict ()));
293 gdb_puts (paddress (gdbarch, b->start ()), outfile);
294 gdb_printf (outfile, "..");
295 gdb_puts (paddress (gdbarch, b->end ()), outfile);
296 if (b->function ())
297 {
298 gdb_printf (outfile, ", function %s",
299 b->function ()->linkage_name ());
300 if (b->function ()->demangled_name () != NULL)
301 {
302 gdb_printf (outfile, ", %s",
303 b->function ()->demangled_name ());
304 }
305 }
306 gdb_printf (outfile, "\n");
307 /* Now print each symbol in this block (in no particular order, if
308 we're using a hashtable). Note that we only want this
309 block, not any blocks from included symtabs. */
310 ALL_DICT_SYMBOLS (b->multidict (), miter, sym)
311 {
312 try
313 {
314 print_symbol (gdbarch, sym, depth + 1, outfile);
315 }
316 catch (const gdb_exception_error &ex)
317 {
319 "Error printing symbol:\n");
320 }
321 }
322 }
323 gdb_printf (outfile, "\n");
324 }
325 else
326 {
327 compunit_symtab *compunit = symtab->compunit ();
328 const char *compunit_filename
330
331 gdb_printf (outfile,
332 "\nBlockvector same as owning compunit: %s\n\n",
333 compunit_filename);
334 }
335
336 /* Print info about the user of this compunit_symtab, and the
337 compunit_symtabs included by this one. */
339 {
340 struct compunit_symtab *cust = symtab->compunit ();
341
342 if (cust->user != nullptr)
343 {
344 const char *addr
345 = host_address_to_string (cust->user->primary_filetab ());
346 gdb_printf (outfile, "Compunit user: %s\n", addr);
347 }
348 if (cust->includes != nullptr)
349 for (int i = 0; ; ++i)
350 {
351 struct compunit_symtab *include = cust->includes[i];
352 if (include == nullptr)
353 break;
354 const char *addr
355 = host_address_to_string (include->primary_filetab ());
356 gdb_printf (outfile, "Compunit include: %s\n", addr);
357 }
358 }
359}
360
361static void
362dump_symtab (struct symtab *symtab, struct ui_file *outfile)
363{
364 /* Set the current language to the language of the symtab we're dumping
365 because certain routines used during dump_symtab() use the current
366 language to print an image of the symbol. We'll restore it later.
367 But use only real languages, not placeholders. */
369 && symtab->language () != language_auto)
370 {
373 dump_symtab_1 (symtab, outfile);
374 }
375 else
376 dump_symtab_1 (symtab, outfile);
377}
378
379static void
380maintenance_print_symbols (const char *args, int from_tty)
381{
382 struct ui_file *outfile = gdb_stdout;
383 char *address_arg = NULL, *source_arg = NULL, *objfile_arg = NULL;
384 int i, outfile_idx;
385
386 dont_repeat ();
387
388 gdb_argv argv (args);
389
390 for (i = 0; argv != NULL && argv[i] != NULL; ++i)
391 {
392 if (strcmp (argv[i], "-pc") == 0)
393 {
394 if (argv[i + 1] == NULL)
395 error (_("Missing pc value"));
396 address_arg = argv[++i];
397 }
398 else if (strcmp (argv[i], "-source") == 0)
399 {
400 if (argv[i + 1] == NULL)
401 error (_("Missing source file"));
402 source_arg = argv[++i];
403 }
404 else if (strcmp (argv[i], "-objfile") == 0)
405 {
406 if (argv[i + 1] == NULL)
407 error (_("Missing objfile name"));
408 objfile_arg = argv[++i];
409 }
410 else if (strcmp (argv[i], "--") == 0)
411 {
412 /* End of options. */
413 ++i;
414 break;
415 }
416 else if (argv[i][0] == '-')
417 {
418 /* Future proofing: Don't allow OUTFILE to begin with "-". */
419 error (_("Unknown option: %s"), argv[i]);
420 }
421 else
422 break;
423 }
424 outfile_idx = i;
425
426 if (address_arg != NULL && source_arg != NULL)
427 error (_("Must specify at most one of -pc and -source"));
428
429 stdio_file arg_outfile;
430
431 if (argv != NULL && argv[outfile_idx] != NULL)
432 {
433 if (argv[outfile_idx + 1] != NULL)
434 error (_("Junk at end of command"));
435 gdb::unique_xmalloc_ptr<char> outfile_name
436 (tilde_expand (argv[outfile_idx]));
437 if (!arg_outfile.open (outfile_name.get (), FOPEN_WT))
438 perror_with_name (outfile_name.get ());
439 outfile = &arg_outfile;
440 }
441
442 if (address_arg != NULL)
443 {
444 CORE_ADDR pc = parse_and_eval_address (address_arg);
445 struct symtab *s = find_pc_line_symtab (pc);
446
447 if (s == NULL)
448 error (_("No symtab for address: %s"), address_arg);
449 dump_symtab (s, outfile);
450 }
451 else
452 {
453 int found = 0;
454
456 {
457 int print_for_objfile = 1;
458
459 if (objfile_arg != NULL)
460 print_for_objfile
462 objfile_arg);
463 if (!print_for_objfile)
464 continue;
465
466 for (compunit_symtab *cu : objfile->compunits ())
467 {
468 for (symtab *s : cu->filetabs ())
469 {
470 int print_for_source = 0;
471
472 QUIT;
473 if (source_arg != NULL)
474 {
475 print_for_source
477 (symtab_to_filename_for_display (s), source_arg);
478 found = 1;
479 }
480 if (source_arg == NULL
481 || print_for_source)
482 dump_symtab (s, outfile);
483 }
484 }
485 }
486
487 if (source_arg != NULL && !found)
488 error (_("No symtab for source file: %s"), source_arg);
489 }
490}
491
492/* Print symbol SYMBOL on OUTFILE. DEPTH says how far to indent. */
493
494static void
496 int depth, ui_file *outfile)
497{
498 struct obj_section *section;
499
500 if (symbol->is_objfile_owned ())
501 section = symbol->obj_section (symbol->objfile ());
502 else
503 section = NULL;
504
505 print_spaces (depth, outfile);
506 if (symbol->domain () == LABEL_DOMAIN)
507 {
508 gdb_printf (outfile, "label %s at ", symbol->print_name ());
510 outfile);
511 if (section)
512 gdb_printf (outfile, " section %s\n",
513 bfd_section_name (section->the_bfd_section));
514 else
515 gdb_printf (outfile, "\n");
516 return;
517 }
518
519 if (symbol->domain () == STRUCT_DOMAIN)
520 {
521 if (symbol->type ()->name ())
522 {
523 current_language->print_type (symbol->type (), "", outfile, 1, depth,
525 }
526 else
527 {
528 gdb_printf (outfile, "%s %s = ",
529 (symbol->type ()->code () == TYPE_CODE_ENUM
530 ? "enum"
531 : (symbol->type ()->code () == TYPE_CODE_STRUCT
532 ? "struct" : "union")),
533 symbol->linkage_name ());
534 current_language->print_type (symbol->type (), "", outfile, 1, depth,
536 }
537 gdb_printf (outfile, ";\n");
538 }
539 else
540 {
541 if (symbol->aclass () == LOC_TYPEDEF)
542 gdb_printf (outfile, "typedef ");
543 if (symbol->type ())
544 {
545 /* Print details of types, except for enums where it's clutter. */
547 outfile,
548 symbol->type ()->code () != TYPE_CODE_ENUM,
549 depth,
551 gdb_printf (outfile, "; ");
552 }
553 else
554 gdb_printf (outfile, "%s ", symbol->print_name ());
555
556 switch (symbol->aclass ())
557 {
558 case LOC_CONST:
559 gdb_printf (outfile, "const %s (%s)",
560 plongest (symbol->value_longest ()),
561 hex_string (symbol->value_longest ()));
562 break;
563
564 case LOC_CONST_BYTES:
565 {
566 unsigned i;
567 struct type *type = check_typedef (symbol->type ());
568
569 gdb_printf (outfile, "const %s hex bytes:",
570 pulongest (type->length ()));
571 for (i = 0; i < type->length (); i++)
572 gdb_printf (outfile, " %02x",
573 (unsigned) symbol->value_bytes ()[i]);
574 }
575 break;
576
577 case LOC_STATIC:
578 gdb_printf (outfile, "static at ");
579 gdb_puts (paddress (gdbarch, symbol->value_address ()), outfile);
580 if (section)
581 gdb_printf (outfile, " section %s",
582 bfd_section_name (section->the_bfd_section));
583 break;
584
585 case LOC_REGISTER:
586 if (symbol->is_argument ())
587 gdb_printf (outfile, "parameter register %s",
588 plongest (symbol->value_longest ()));
589 else
590 gdb_printf (outfile, "register %s",
591 plongest (symbol->value_longest ()));
592 break;
593
594 case LOC_ARG:
595 gdb_printf (outfile, "arg at offset %s",
596 hex_string (symbol->value_longest ()));
597 break;
598
599 case LOC_REF_ARG:
600 gdb_printf (outfile, "reference arg at %s",
601 hex_string (symbol->value_longest ()));
602 break;
603
604 case LOC_REGPARM_ADDR:
605 gdb_printf (outfile, "address parameter register %s",
606 plongest (symbol->value_longest ()));
607 break;
608
609 case LOC_LOCAL:
610 gdb_printf (outfile, "local at offset %s",
611 hex_string (symbol->value_longest ()));
612 break;
613
614 case LOC_TYPEDEF:
615 break;
616
617 case LOC_LABEL:
618 gdb_printf (outfile, "label at ");
619 gdb_puts (paddress (gdbarch, symbol->value_address ()), outfile);
620 if (section)
621 gdb_printf (outfile, " section %s",
622 bfd_section_name (section->the_bfd_section));
623 break;
624
625 case LOC_BLOCK:
627 (outfile, "block object %s, %s..%s",
628 host_address_to_string (symbol->value_block ()),
631 if (section)
632 gdb_printf (outfile, " section %s",
633 bfd_section_name (section->the_bfd_section));
634 break;
635
636 case LOC_COMPUTED:
637 gdb_printf (outfile, "computed at runtime");
638 break;
639
640 case LOC_UNRESOLVED:
641 gdb_printf (outfile, "unresolved");
642 break;
643
645 gdb_printf (outfile, "optimized out");
646 break;
647
648 default:
649 gdb_printf (outfile, "botched symbol class %x",
650 symbol->aclass ());
651 break;
652 }
653 }
654 gdb_printf (outfile, "\n");
655}
656
657static void
658maintenance_print_msymbols (const char *args, int from_tty)
659{
660 struct ui_file *outfile = gdb_stdout;
661 char *objfile_arg = NULL;
662 int i, outfile_idx;
663
664 dont_repeat ();
665
666 gdb_argv argv (args);
667
668 for (i = 0; argv != NULL && argv[i] != NULL; ++i)
669 {
670 if (strcmp (argv[i], "-objfile") == 0)
671 {
672 if (argv[i + 1] == NULL)
673 error (_("Missing objfile name"));
674 objfile_arg = argv[++i];
675 }
676 else if (strcmp (argv[i], "--") == 0)
677 {
678 /* End of options. */
679 ++i;
680 break;
681 }
682 else if (argv[i][0] == '-')
683 {
684 /* Future proofing: Don't allow OUTFILE to begin with "-". */
685 error (_("Unknown option: %s"), argv[i]);
686 }
687 else
688 break;
689 }
690 outfile_idx = i;
691
692 stdio_file arg_outfile;
693
694 if (argv != NULL && argv[outfile_idx] != NULL)
695 {
696 if (argv[outfile_idx + 1] != NULL)
697 error (_("Junk at end of command"));
698 gdb::unique_xmalloc_ptr<char> outfile_name
699 (tilde_expand (argv[outfile_idx]));
700 if (!arg_outfile.open (outfile_name.get (), FOPEN_WT))
701 perror_with_name (outfile_name.get ());
702 outfile = &arg_outfile;
703 }
704
706 {
707 QUIT;
708 if (objfile_arg == NULL
710 dump_msymbols (objfile, outfile);
711 }
712}
713
714static void
715maintenance_print_objfiles (const char *regexp, int from_tty)
716{
717 dont_repeat ();
718
719 if (regexp)
720 re_comp (regexp);
721
722 for (struct program_space *pspace : program_spaces)
723 for (objfile *objfile : pspace->objfiles ())
724 {
725 QUIT;
726 if (! regexp
727 || re_exec (objfile_name (objfile)))
729 }
730}
731
732/* List all the symbol tables whose names match REGEXP (optional). */
733
734static void
735maintenance_info_symtabs (const char *regexp, int from_tty)
736{
737 dont_repeat ();
738
739 if (regexp)
740 re_comp (regexp);
741
742 for (struct program_space *pspace : program_spaces)
743 for (objfile *objfile : pspace->objfiles ())
744 {
745 /* We don't want to print anything for this objfile until we
746 actually find a symtab whose name matches. */
747 int printed_objfile_start = 0;
748
749 for (compunit_symtab *cust : objfile->compunits ())
750 {
751 int printed_compunit_symtab_start = 0;
752
753 for (symtab *symtab : cust->filetabs ())
754 {
755 QUIT;
756
757 if (! regexp
759 {
760 if (! printed_objfile_start)
761 {
762 gdb_printf ("{ objfile %s ", objfile_name (objfile));
763 gdb_stdout->wrap_here (2);
764 gdb_printf ("((struct objfile *) %s)\n",
765 host_address_to_string (objfile));
766 printed_objfile_start = 1;
767 }
768 if (! printed_compunit_symtab_start)
769 {
770 gdb_printf (" { ((struct compunit_symtab *) %s)\n",
771 host_address_to_string (cust));
772 gdb_printf (" debugformat %s\n",
773 cust->debugformat ());
774 gdb_printf (" producer %s\n",
775 (cust->producer () != nullptr
776 ? cust->producer () : "(null)"));
777 gdb_printf (" name %s\n", cust->name);
778 gdb_printf (" dirname %s\n",
779 (cust->dirname () != NULL
780 ? cust->dirname () : "(null)"));
781 gdb_printf (" blockvector"
782 " ((struct blockvector *) %s)\n",
783 host_address_to_string
784 (cust->blockvector ()));
785 gdb_printf (" user"
786 " ((struct compunit_symtab *) %s)\n",
787 cust->user != nullptr
788 ? host_address_to_string (cust->user)
789 : "(null)");
790 if (cust->includes != nullptr)
791 {
792 gdb_printf (" ( includes\n");
793 for (int i = 0; ; ++i)
794 {
795 struct compunit_symtab *include
796 = cust->includes[i];
797 if (include == nullptr)
798 break;
799 const char *addr
800 = host_address_to_string (include);
801 gdb_printf (" (%s %s)\n",
802 "(struct compunit_symtab *)",
803 addr);
804 }
805 gdb_printf (" )\n");
806 }
807 printed_compunit_symtab_start = 1;
808 }
809
810 gdb_printf ("\t{ symtab %s ",
812 gdb_stdout->wrap_here (4);
813 gdb_printf ("((struct symtab *) %s)\n",
814 host_address_to_string (symtab));
815 gdb_printf ("\t fullname %s\n",
816 symtab->fullname != NULL
818 : "(null)");
819 gdb_printf ("\t "
820 "linetable ((struct linetable *) %s)\n",
821 host_address_to_string
822 (symtab->linetable ()));
823 gdb_printf ("\t}\n");
824 }
825 }
826
827 if (printed_compunit_symtab_start)
828 gdb_printf (" }\n");
829 }
830
831 if (printed_objfile_start)
832 gdb_printf ("}\n");
833 }
834}
835
836/* Check consistency of symtabs.
837 An example of what this checks for is NULL blockvectors.
838 They can happen if there's a bug during debug info reading.
839 GDB assumes they are always non-NULL.
840
841 Note: This does not check for psymtab vs symtab consistency.
842 Use "maint check-psymtabs" for that. */
843
844static void
845maintenance_check_symtabs (const char *ignore, int from_tty)
846{
847 for (struct program_space *pspace : program_spaces)
848 for (objfile *objfile : pspace->objfiles ())
849 {
850 /* We don't want to print anything for this objfile until we
851 actually find something worth printing. */
852 int printed_objfile_start = 0;
853
854 for (compunit_symtab *cust : objfile->compunits ())
855 {
856 int found_something = 0;
857 struct symtab *symtab = cust->primary_filetab ();
858
859 QUIT;
860
861 if (cust->blockvector () == NULL)
862 found_something = 1;
863 /* Add more checks here. */
864
865 if (found_something)
866 {
867 if (! printed_objfile_start)
868 {
869 gdb_printf ("{ objfile %s ", objfile_name (objfile));
870 gdb_stdout->wrap_here (2);
871 gdb_printf ("((struct objfile *) %s)\n",
872 host_address_to_string (objfile));
873 printed_objfile_start = 1;
874 }
875 gdb_printf (" { symtab %s\n",
877 if (cust->blockvector () == NULL)
878 gdb_printf (" NULL blockvector\n");
879 gdb_printf (" }\n");
880 }
881 }
882
883 if (printed_objfile_start)
884 gdb_printf ("}\n");
885 }
886}
887
888/* Expand all symbol tables whose name matches an optional regexp. */
889
890static void
891maintenance_expand_symtabs (const char *args, int from_tty)
892{
893 char *regexp = NULL;
894
895 /* We use buildargv here so that we handle spaces in the regexp
896 in a way that allows adding more arguments later. */
897 gdb_argv argv (args);
898
899 if (argv != NULL)
900 {
901 if (argv[0] != NULL)
902 {
903 regexp = argv[0];
904 if (argv[1] != NULL)
905 error (_("Extra arguments after regexp."));
906 }
907 }
908
909 if (regexp)
910 re_comp (regexp);
911
912 for (struct program_space *pspace : program_spaces)
913 for (objfile *objfile : pspace->objfiles ())
915 ([&] (const char *filename, bool basenames)
916 {
917 /* KISS: Only apply the regexp to the complete file name. */
918 return (!basenames
919 && (regexp == NULL || re_exec (filename)));
920 },
921 NULL,
922 NULL,
923 NULL,
926 ALL_DOMAIN);
927}
928
929
930/* Return the nexting depth of a block within other blocks in its symtab. */
931
932static int
933block_depth (const struct block *block)
934{
935 int i = 0;
936
937 while ((block = block->superblock ()) != NULL)
938 {
939 i++;
940 }
941 return i;
942}
943
944
945/* Used by MAINTENANCE_INFO_LINE_TABLES to print the information about a
946 single line table. */
947
948static int
950{
951 struct linetable *linetable;
952 struct objfile *objfile;
953
954 objfile = symtab->compunit ()->objfile ();
955 gdb_printf (_("objfile: %ps ((struct objfile *) %s)\n"),
958 host_address_to_string (objfile));
959 gdb_printf (_("compunit_symtab: %s ((struct compunit_symtab *) %s)\n"),
960 symtab->compunit ()->name,
961 host_address_to_string (symtab->compunit ()));
962 gdb_printf (_("symtab: %ps ((struct symtab *) %s)\n"),
965 host_address_to_string (symtab));
967 gdb_printf (_("linetable: ((struct linetable *) %s):\n"),
968 host_address_to_string (linetable));
969
970 if (linetable == NULL)
971 gdb_printf (_("No line table.\n"));
972 else if (linetable->nitems <= 0)
973 gdb_printf (_("Line table has no lines.\n"));
974 else
975 {
976 /* Leave space for 6 digits of index and line number. After that the
977 tables will just not format as well. */
978 struct ui_out *uiout = current_uiout;
979 ui_out_emit_table table_emitter (uiout, 5, -1, "line-table");
980 uiout->table_header (6, ui_left, "index", _("INDEX"));
981 uiout->table_header (6, ui_left, "line", _("LINE"));
982 uiout->table_header (18, ui_left, "address", _("ADDRESS"));
983 uiout->table_header (7, ui_left, "is-stmt", _("IS-STMT"));
984 uiout->table_header (12, ui_left, "prologue-end", _("PROLOGUE-END"));
985 uiout->table_body ();
986
987 for (int i = 0; i < linetable->nitems; ++i)
988 {
989 struct linetable_entry *item;
990
991 item = &linetable->item [i];
992 ui_out_emit_tuple tuple_emitter (uiout, nullptr);
993 uiout->field_signed ("index", i);
994 if (item->line > 0)
995 uiout->field_signed ("line", item->line);
996 else
997 uiout->field_string ("line", _("END"));
998 uiout->field_core_addr ("address", objfile->arch (),
999 item->pc);
1000 uiout->field_string ("is-stmt", item->is_stmt ? "Y" : "");
1001 uiout->field_string ("prologue-end", item->prologue_end ? "Y" : "");
1002 uiout->text ("\n");
1003 }
1004 }
1005
1006 return 0;
1007}
1008
1009/* Implement the 'maint info line-table' command. */
1010
1011static void
1012maintenance_info_line_tables (const char *regexp, int from_tty)
1013{
1014 dont_repeat ();
1015
1016 if (regexp != NULL)
1017 re_comp (regexp);
1018
1019 for (struct program_space *pspace : program_spaces)
1020 for (objfile *objfile : pspace->objfiles ())
1021 {
1022 for (compunit_symtab *cust : objfile->compunits ())
1023 {
1024 for (symtab *symtab : cust->filetabs ())
1025 {
1026 QUIT;
1027
1028 if (regexp == NULL
1030 {
1032 gdb_printf ("\n");
1033 }
1034 }
1035 }
1036 }
1037}
1038
1039
1040
1041/* Do early runtime initializations. */
1042
1043void _initialize_symmisc ();
1044void
1046{
1048Print dump of current symbol definitions.\n\
1049Usage: mt print symbols [-pc ADDRESS] [--] [OUTFILE]\n\
1050 mt print symbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
1051Entries in the full symbol table are dumped to file OUTFILE,\n\
1052or the terminal if OUTFILE is unspecified.\n\
1053If ADDRESS is provided, dump only the file for that address.\n\
1054If SOURCE is provided, dump only that file's symbols.\n\
1055If OBJFILE is provided, dump only that file's minimal symbols."),
1057
1059Print dump of current minimal symbol definitions.\n\
1060Usage: mt print msymbols [-objfile OBJFILE] [--] [OUTFILE]\n\
1061Entries in the minimal symbol table are dumped to file OUTFILE,\n\
1062or the terminal if OUTFILE is unspecified.\n\
1063If OBJFILE is provided, dump only that file's minimal symbols."),
1065
1067 _("Print dump of current object file definitions.\n\
1068With an argument REGEXP, list the object files with matching names."),
1070
1072List the full symbol tables for all object files.\n\
1073This does not include information about individual symbols, blocks, or\n\
1074linetables --- just the symbol table structures themselves.\n\
1075With an argument REGEXP, list the symbol tables with matching names."),
1077
1079List the contents of all line tables, from all symbol tables.\n\
1080With an argument REGEXP, list just the line tables for the symbol\n\
1081tables with matching names."),
1083
1085 _("\
1086Check consistency of currently expanded symtabs."),
1088
1090 _("Expand symbol tables.\n\
1091With an argument REGEXP, only expand the symbol tables with matching names."),
1093}
ui_file_style style() const
Definition: cli-style.c:169
bool open(const char *name, const char *mode)
Definition: ui-file.c:263
Definition: ui-out.h:160
void field_core_addr(const char *fldname, struct gdbarch *gdbarch, CORE_ADDR address)
Definition: ui-out.c:478
void field_string(const char *fldname, const char *string, const ui_file_style &style=ui_file_style())
Definition: ui-out.c:511
void field_signed(const char *fldname, LONGEST value)
Definition: ui-out.c:437
void text(const char *string)
Definition: ui-out.c:566
void table_header(int width, ui_align align, const std::string &col_name, const std::string &col_hdr)
Definition: ui-out.c:363
void table_body()
Definition: ui-out.c:376
struct cmd_list_element * maintenanceprintlist
Definition: cli-cmds.c:149
struct cmd_list_element * maintenancelist
Definition: cli-cmds.c:141
struct cmd_list_element * maintenanceinfolist
Definition: cli-cmds.c:145
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
Definition: cli-decode.c:233
cli_style_option file_name_style
void dont_repeat()
Definition: top.c:809
@ class_maintenance
Definition: command.h:65
EXTERN_C char * re_comp(const char *)
@ language_unknown
Definition: defs.h:212
@ language_auto
Definition: defs.h:213
#define QUIT
Definition: defs.h:186
int mdict_size(const struct multidictionary *mdict)
Definition: dictionary.c:1272
#define ALL_DICT_SYMBOLS(dict, iter, sym)
Definition: dictionary.h:174
CORE_ADDR parse_and_eval_address(const char *exp)
Definition: eval.c:52
void exception_fprintf(struct ui_file *file, const struct gdb_exception &e, const char *prefix,...)
Definition: exceptions.c:115
struct type * check_typedef(struct type *type)
Definition: gdbtypes.c:3010
const char * language_str(enum language lang)
Definition: language.c:452
const struct language_defn * current_language
Definition: language.c:83
enum language set_language(enum language lang)
Definition: language.c:361
const char * objfile_name(const struct objfile *objfile)
Definition: objfiles.c:1308
#define OBJSTAT(objfile, expr)
Definition: objfiles.h:178
struct program_space * current_program_space
Definition: progspace.c:39
std::vector< struct program_space * > program_spaces
Definition: progspace.c:36
@ SEARCH_GLOBAL_BLOCK
Definition: quick-symbol.h:27
@ SEARCH_STATIC_BLOCK
Definition: quick-symbol.h:28
const char * symtab_to_fullname(struct symtab *s)
Definition: source.c:1252
const char * symtab_to_filename_for_display(struct symtab *symtab)
Definition: source.c:1287
Definition: block.h:109
const block * superblock() const
Definition: block.h:135
multidictionary * multidict() const
Definition: block.h:143
CORE_ADDR start() const
Definition: block.h:111
CORE_ADDR end() const
Definition: block.h:119
symbol * function() const
Definition: block.h:127
struct block * block(size_t i)
Definition: block.h:271
int num_blocks() const
Definition: block.h:290
symtab * primary_filetab() const
Definition: symtab.c:397
struct blockvector * blockvector()
Definition: symtab.h:1773
struct compunit_symtab * user
Definition: symtab.h:1921
const char * name
Definition: symtab.h:1855
struct compunit_symtab ** includes
Definition: symtab.h:1915
struct objfile * objfile() const
Definition: symtab.h:1714
const char * dirname() const
Definition: symtab.h:1763
void print_statistics(const char *type)
Definition: bcache.c:259
int memory_used()
Definition: bcache.c:384
const char * demangled_name
Definition: symtab.h:572
const char * print_name() const
Definition: symtab.h:474
struct obj_section * obj_section(const struct objfile *objfile) const
Definition: symtab.c:1088
const char * linkage_name() const
Definition: symtab.h:459
virtual void print_type(struct type *type, const char *varstring, struct ui_file *stream, int show, int level, const struct type_print_options *flags) const =0
Definition: symtab.h:1548
unsigned is_stmt
Definition: symtab.h:1553
int line
Definition: symtab.h:1550
CORE_ADDR pc
Definition: symtab.h:1560
bool prologue_end
Definition: symtab.h:1557
int nitems
Definition: symtab.h:1582
struct linetable_entry item[1]
Definition: symtab.h:1587
CORE_ADDR addr() const
Definition: objfiles.h:822
struct bfd_section * the_bfd_section
Definition: objfiles.h:835
auto_obstack storage_obstack
Definition: objfiles.h:265
gdb::bcache string_cache
Definition: objfiles.h:269
struct compunit_symtab * compunit_symtabs
Definition: objfiles.h:646
struct gdbarch * arch() const
Definition: objfiles.h:482
struct objfile_per_bfd_storage * per_bfd
Definition: objfiles.h:657
bool expand_symtabs_matching(gdb::function_view< expand_symtabs_file_matcher_ftype > file_matcher, const lookup_name_info *lookup_name, gdb::function_view< expand_symtabs_symbol_matcher_ftype > symbol_matcher, gdb::function_view< expand_symtabs_exp_notify_ftype > expansion_notify, block_search_flags search_flags, domain_enum domain, enum search_domain kind)
void print_stats(bool print_bcache)
struct obj_section * sections
Definition: objfiles.h:725
gdb_bfd_ref_ptr obfd
Definition: objfiles.h:653
compunit_symtab_range compunits()
Definition: objfiles.h:426
void dump()
::section_offsets section_offsets
Definition: objfiles.h:699
msymbols_range msymbols()
Definition: objfiles.h:439
objfiles_range objfiles()
Definition: progspace.h:209
const block * value_block() const
Definition: symtab.h:1348
address_class aclass() const
Definition: symtab.h:1235
struct type * type() const
Definition: symtab.h:1285
domain_enum domain() const
Definition: symtab.h:1240
LONGEST value_longest() const
Definition: symtab.h:1305
const gdb_byte * value_bytes() const
Definition: symtab.h:1328
bool is_objfile_owned() const
Definition: symtab.h:1250
bool is_argument() const
Definition: symtab.h:1260
CORE_ADDR value_address() const
Definition: symtab.h:1315
struct objfile * objfile() const
Definition: symtab.c:6477
enum language language() const
Definition: symtab.h:1623
char * fullname
Definition: symtab.h:1670
struct compunit_symtab * compunit() const
Definition: symtab.h:1603
struct linetable * linetable() const
Definition: symtab.h:1613
const char * filename
Definition: symtab.h:1651
Definition: gdbtypes.h:922
type_code code() const
Definition: gdbtypes.h:927
ULONGEST length() const
Definition: gdbtypes.h:954
const char * name() const
Definition: gdbtypes.h:939
static void print_symbol(struct gdbarch *gdbarch, struct symbol *symbol, int depth, ui_file *outfile)
Definition: symmisc.c:495
static void maintenance_expand_symtabs(const char *args, int from_tty)
Definition: symmisc.c:891
static void maintenance_print_msymbols(const char *args, int from_tty)
Definition: symmisc.c:658
static void dump_objfile(struct objfile *objfile)
Definition: symmisc.c:114
static int block_depth(const struct block *)
Definition: symmisc.c:933
static void dump_msymbols(struct objfile *objfile, struct ui_file *outfile)
Definition: symmisc.c:146
void print_objfile_statistics(void)
Definition: symmisc.c:52
static void maintenance_print_symbols(const char *args, int from_tty)
Definition: symmisc.c:380
static void maintenance_check_symtabs(const char *ignore, int from_tty)
Definition: symmisc.c:845
static int maintenance_print_one_line_table(struct symtab *symtab, void *data)
Definition: symmisc.c:949
static void maintenance_print_objfiles(const char *regexp, int from_tty)
Definition: symmisc.c:715
static void dump_symtab_1(struct symtab *symtab, struct ui_file *outfile)
Definition: symmisc.c:235
static void maintenance_info_symtabs(const char *regexp, int from_tty)
Definition: symmisc.c:735
void _initialize_symmisc()
Definition: symmisc.c:1045
static void dump_symtab(struct symtab *symtab, struct ui_file *outfile)
Definition: symmisc.c:362
static void maintenance_info_line_tables(const char *regexp, int from_tty)
Definition: symmisc.c:1012
struct symtab * find_pc_line_symtab(CORE_ADDR pc)
Definition: symtab.c:3319
bool compare_filenames_for_search(const char *filename, const char *search_name)
Definition: symtab.c:461
@ ALL_DOMAIN
Definition: symtab.h:931
static bool is_main_symtab_of_compunit_symtab(struct symtab *symtab)
Definition: symtab.h:1929
@ LOC_STATIC
Definition: symtab.h:950
@ LOC_BLOCK
Definition: symtab.h:999
@ LOC_LABEL
Definition: symtab.h:993
@ LOC_REGISTER
Definition: symtab.h:964
@ LOC_REF_ARG
Definition: symtab.h:972
@ LOC_UNRESOLVED
Definition: symtab.h:1028
@ LOC_LOCAL
Definition: symtab.h:984
@ LOC_CONST
Definition: symtab.h:946
@ LOC_CONST_BYTES
Definition: symtab.h:1004
@ LOC_OPTIMIZED_OUT
Definition: symtab.h:1033
@ LOC_TYPEDEF
Definition: symtab.h:989
@ LOC_REGPARM_ADDR
Definition: symtab.h:980
@ LOC_COMPUTED
Definition: symtab.h:1037
@ LOC_ARG
Definition: symtab.h:968
@ mst_data_gnu_ifunc
Definition: symtab.h:673
@ mst_abs
Definition: symtab.h:679
@ mst_bss
Definition: symtab.h:678
@ mst_data
Definition: symtab.h:677
@ mst_unknown
Definition: symtab.h:654
@ mst_solib_trampoline
Definition: symtab.h:688
@ mst_file_text
Definition: symtab.h:691
@ mst_file_data
Definition: symtab.h:692
@ mst_text
Definition: symtab.h:655
@ mst_text_gnu_ifunc
Definition: symtab.h:664
@ mst_file_bss
Definition: symtab.h:693
@ STRUCT_DOMAIN
Definition: symtab.h:887
@ LABEL_DOMAIN
Definition: symtab.h:895
@ UNDEF_DOMAIN
Definition: symtab.h:876
const struct type_print_options type_print_raw_options
Definition: typeprint.c:41
static styled_string_s * styled_string(const ui_file_style &style, const char *str, styled_string_s &&tmp={})
Definition: ui-out.h:151
@ ui_left
Definition: ui-out.h:45
#define current_uiout
Definition: ui-out.h:40
void perror_with_name(const char *string)
Definition: utils.c:643
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition: utils.c:3114
void print_spaces(int n, struct ui_file *stream)
Definition: utils.c:1947
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition: utils.c:1865
void gdb_puts(const char *linebuffer, struct ui_file *stream)
Definition: utils.c:1788
#define gdb_stderr
Definition: utils.h:193
#define gdb_stdout
Definition: utils.h:188