GDB (xrefs)
/tmp/gdb-8.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-2018 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 "gdb_obstack.h"
30 #include "language.h"
31 #include "bcache.h"
32 #include "block.h"
33 #include "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/readline.h"
40 
41 #include "psymtab.h"
42 
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
48  of the file. */
49 FILE *std_in;
50 FILE *std_out;
51 FILE *std_err;
52 
53 /* Prototypes for local functions */
54 
55 static int block_depth (struct block *);
56 
57 static void print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
58  int depth, ui_file *outfile);
59 
60 
61 void
63 {
64  struct program_space *pspace;
65  struct objfile *objfile;
66 
69  {
70  QUIT;
71  printf_filtered (_("Byte cache statistics for '%s':\n"),
74  "partial symbol cache");
76  "preprocessor macro cache");
78  "file name cache");
79  }
80 }
81 
82 void
84 {
85  struct program_space *pspace;
86  struct objfile *objfile;
87  struct compunit_symtab *cu;
88  struct symtab *s;
89  int i, linetables, blockvectors;
90 
91  ALL_PSPACES (pspace)
93  {
94  QUIT;
95  printf_filtered (_("Statistics for '%s':\n"), objfile_name (objfile));
96  if (OBJSTAT (objfile, n_stabs) > 0)
97  printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
98  OBJSTAT (objfile, n_stabs));
99  if (objfile->per_bfd->n_minsyms > 0)
100  printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
102  if (OBJSTAT (objfile, n_psyms) > 0)
103  printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
104  OBJSTAT (objfile, n_psyms));
105  if (OBJSTAT (objfile, n_syms) > 0)
106  printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
107  OBJSTAT (objfile, n_syms));
108  if (OBJSTAT (objfile, n_types) > 0)
109  printf_filtered (_(" Number of \"types\" defined: %d\n"),
110  OBJSTAT (objfile, n_types));
111  if (objfile->sf)
113  i = linetables = blockvectors = 0;
115  {
116  i++;
117  if (SYMTAB_LINETABLE (s) != NULL)
118  linetables++;
119  }
121  blockvectors++;
122  printf_filtered (_(" Number of symbol tables: %d\n"), i);
123  printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
124  linetables);
125  printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
126  blockvectors);
127 
128  if (OBJSTAT (objfile, sz_strtab) > 0)
129  printf_filtered (_(" Space used by string tables: %d\n"),
130  OBJSTAT (objfile, sz_strtab));
131  printf_filtered (_(" Total memory used for objfile obstack: %s\n"),
132  pulongest (obstack_memory_used (&objfile
133  ->objfile_obstack)));
134  printf_filtered (_(" Total memory used for BFD obstack: %s\n"),
135  pulongest (obstack_memory_used (&objfile->per_bfd
136  ->storage_obstack)));
137  printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
139  (objfile->psymbol_cache)));
140  printf_filtered (_(" Total memory used for macro cache: %d\n"),
142  printf_filtered (_(" Total memory used for file name cache: %d\n"),
144  }
145 }
146 
147 static void
149 {
150  struct compunit_symtab *cust;
151  struct symtab *symtab;
152 
153  printf_filtered ("\nObject file %s: ", objfile_name (objfile));
154  printf_filtered ("Objfile at ");
156  printf_filtered (", bfd at ");
158  printf_filtered (", %d minsyms\n\n",
160 
161  if (objfile->sf)
162  objfile->sf->qf->dump (objfile);
163 
164  if (objfile->compunit_symtabs != NULL)
165  {
166  printf_filtered ("Symtabs:\n");
168  {
171  printf_filtered (", ");
172  if (SYMTAB_OBJFILE (symtab) != objfile)
173  {
174  printf_filtered ("NOT ON CHAIN! ");
175  }
176  wrap_here (" ");
177  }
178  printf_filtered ("\n\n");
179  }
180 }
181 
182 /* Print minimal symbols from this objfile. */
183 
184 static void
185 dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
186 {
188  struct minimal_symbol *msymbol;
189  int index;
190  char ms_type;
191 
192  fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile_name (objfile));
194  {
195  fprintf_filtered (outfile, "No minimal symbols found.\n");
196  return;
197  }
198  index = 0;
199  ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
200  {
201  struct obj_section *section = MSYMBOL_OBJ_SECTION (objfile, msymbol);
202 
203  switch (MSYMBOL_TYPE (msymbol))
204  {
205  case mst_unknown:
206  ms_type = 'u';
207  break;
208  case mst_text:
209  ms_type = 'T';
210  break;
211  case mst_text_gnu_ifunc:
212  ms_type = 'i';
213  break;
215  ms_type = 'S';
216  break;
217  case mst_data:
218  ms_type = 'D';
219  break;
220  case mst_bss:
221  ms_type = 'B';
222  break;
223  case mst_abs:
224  ms_type = 'A';
225  break;
226  case mst_file_text:
227  ms_type = 't';
228  break;
229  case mst_file_data:
230  ms_type = 'd';
231  break;
232  case mst_file_bss:
233  ms_type = 'b';
234  break;
235  default:
236  ms_type = '?';
237  break;
238  }
239  fprintf_filtered (outfile, "[%2d] %c ", index, ms_type);
241  msymbol)),
242  outfile);
243  fprintf_filtered (outfile, " %s", MSYMBOL_LINKAGE_NAME (msymbol));
244  if (section)
245  {
246  if (section->the_bfd_section != NULL)
247  fprintf_filtered (outfile, " section %s",
248  bfd_section_name (objfile->obfd,
249  section->the_bfd_section));
250  else
251  fprintf_filtered (outfile, " spurious section %ld",
252  (long) (section - objfile->sections));
253  }
254  if (MSYMBOL_DEMANGLED_NAME (msymbol) != NULL)
255  {
256  fprintf_filtered (outfile, " %s", MSYMBOL_DEMANGLED_NAME (msymbol));
257  }
258  if (msymbol->filename)
259  fprintf_filtered (outfile, " %s", msymbol->filename);
260  fputs_filtered ("\n", outfile);
261  index++;
262  }
263  if (objfile->per_bfd->minimal_symbol_count != index)
264  {
265  warning (_("internal error: minimal symbol count %d != %d"),
267  }
268  fprintf_filtered (outfile, "\n");
269 }
270 
271 static void
272 dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
273 {
274  struct objfile *objfile = SYMTAB_OBJFILE (symtab);
276  int i;
277  struct dict_iterator iter;
278  int len;
279  struct linetable *l;
280  const struct blockvector *bv;
281  struct symbol *sym;
282  struct block *b;
283  int depth;
284 
285  fprintf_filtered (outfile, "\nSymtab for file %s\n",
287  if (SYMTAB_DIRNAME (symtab) != NULL)
288  fprintf_filtered (outfile, "Compilation directory is %s\n",
290  fprintf_filtered (outfile, "Read from object file %s (",
292  gdb_print_host_address (objfile, outfile);
293  fprintf_filtered (outfile, ")\n");
294  fprintf_filtered (outfile, "Language: %s\n",
296 
297  /* First print the line table. */
298  l = SYMTAB_LINETABLE (symtab);
299  if (l)
300  {
301  fprintf_filtered (outfile, "\nLine table:\n\n");
302  len = l->nitems;
303  for (i = 0; i < len; i++)
304  {
305  fprintf_filtered (outfile, " line %d at ", l->item[i].line);
306  fputs_filtered (paddress (gdbarch, l->item[i].pc), outfile);
307  fprintf_filtered (outfile, "\n");
308  }
309  }
310  /* Now print the block info, but only for compunit symtabs since we will
311  print lots of duplicate info otherwise. */
313  {
314  fprintf_filtered (outfile, "\nBlockvector:\n\n");
315  bv = SYMTAB_BLOCKVECTOR (symtab);
316  len = BLOCKVECTOR_NBLOCKS (bv);
317  for (i = 0; i < len; i++)
318  {
319  b = BLOCKVECTOR_BLOCK (bv, i);
320  depth = block_depth (b) * 2;
321  print_spaces (depth, outfile);
322  fprintf_filtered (outfile, "block #%03d, object at ", i);
323  gdb_print_host_address (b, outfile);
324  if (BLOCK_SUPERBLOCK (b))
325  {
326  fprintf_filtered (outfile, " under ");
328  }
329  /* drow/2002-07-10: We could save the total symbols count
330  even if we're using a hashtable, but nothing else but this message
331  wants it. */
332  fprintf_filtered (outfile, ", %d syms/buckets in ",
333  dict_size (BLOCK_DICT (b)));
334  fputs_filtered (paddress (gdbarch, BLOCK_START (b)), outfile);
335  fprintf_filtered (outfile, "..");
336  fputs_filtered (paddress (gdbarch, BLOCK_END (b)), outfile);
337  if (BLOCK_FUNCTION (b))
338  {
339  fprintf_filtered (outfile, ", function %s",
341  if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
342  {
343  fprintf_filtered (outfile, ", %s",
345  }
346  }
347  fprintf_filtered (outfile, "\n");
348  /* Now print each symbol in this block (in no particular order, if
349  we're using a hashtable). Note that we only want this
350  block, not any blocks from included symtabs. */
351  ALL_DICT_SYMBOLS (BLOCK_DICT (b), iter, sym)
352  {
353  TRY
354  {
355  print_symbol (gdbarch, sym, depth + 1, outfile);
356  }
358  {
360  "Error printing symbol:\n");
361  }
362  END_CATCH
363  }
364  }
365  fprintf_filtered (outfile, "\n");
366  }
367  else
368  {
369  const char *compunit_filename
371 
372  fprintf_filtered (outfile,
373  "\nBlockvector same as owning compunit: %s\n\n",
374  compunit_filename);
375  }
376 }
377 
378 static void
379 dump_symtab (struct symtab *symtab, struct ui_file *outfile)
380 {
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. */
387  {
388  enum language saved_lang;
389 
390  saved_lang = set_language (symtab->language);
391 
392  dump_symtab_1 (symtab, outfile);
393 
394  set_language (saved_lang);
395  }
396  else
397  dump_symtab_1 (symtab, outfile);
398 }
399 
400 static void
401 maintenance_print_symbols (const char *args, int from_tty)
402 {
403  struct ui_file *outfile = gdb_stdout;
404  char *address_arg = NULL, *source_arg = NULL, *objfile_arg = NULL;
405  int i, outfile_idx;
406 
407  dont_repeat ();
408 
409  gdb_argv argv (args);
410 
411  for (i = 0; argv != NULL && argv[i] != NULL; ++i)
412  {
413  if (strcmp (argv[i], "-pc") == 0)
414  {
415  if (argv[i + 1] == NULL)
416  error (_("Missing pc value"));
417  address_arg = argv[++i];
418  }
419  else if (strcmp (argv[i], "-source") == 0)
420  {
421  if (argv[i + 1] == NULL)
422  error (_("Missing source file"));
423  source_arg = argv[++i];
424  }
425  else if (strcmp (argv[i], "-objfile") == 0)
426  {
427  if (argv[i + 1] == NULL)
428  error (_("Missing objfile name"));
429  objfile_arg = argv[++i];
430  }
431  else if (strcmp (argv[i], "--") == 0)
432  {
433  /* End of options. */
434  ++i;
435  break;
436  }
437  else if (argv[i][0] == '-')
438  {
439  /* Future proofing: Don't allow OUTFILE to begin with "-". */
440  error (_("Unknown option: %s"), argv[i]);
441  }
442  else
443  break;
444  }
445  outfile_idx = i;
446 
447  if (address_arg != NULL && source_arg != NULL)
448  error (_("Must specify at most one of -pc and -source"));
449 
450  stdio_file arg_outfile;
451 
452  if (argv != NULL && argv[outfile_idx] != NULL)
453  {
454  if (argv[outfile_idx + 1] != NULL)
455  error (_("Junk at end of command"));
456  gdb::unique_xmalloc_ptr<char> outfile_name
457  (tilde_expand (argv[outfile_idx]));
458  if (!arg_outfile.open (outfile_name.get (), FOPEN_WT))
459  perror_with_name (outfile_name.get ());
460  outfile = &arg_outfile;
461  }
462 
463  if (address_arg != NULL)
464  {
465  CORE_ADDR pc = parse_and_eval_address (address_arg);
466  struct symtab *s = find_pc_line_symtab (pc);
467 
468  if (s == NULL)
469  error (_("No symtab for address: %s"), address_arg);
470  dump_symtab (s, outfile);
471  }
472  else
473  {
474  struct objfile *objfile;
475  struct compunit_symtab *cu;
476  struct symtab *s;
477  int found = 0;
478 
480  {
481  int print_for_objfile = 1;
482 
483  if (objfile_arg != NULL)
484  print_for_objfile
486  objfile_arg);
487  if (!print_for_objfile)
488  continue;
489 
491  {
492  int print_for_source = 0;
493 
494  QUIT;
495  if (source_arg != NULL)
496  {
497  print_for_source
499  (symtab_to_filename_for_display (s), source_arg);
500  found = 1;
501  }
502  if (source_arg == NULL
503  || print_for_source)
504  dump_symtab (s, outfile);
505  }
506  }
507 
508  if (source_arg != NULL && !found)
509  error (_("No symtab for source file: %s"), source_arg);
510  }
511 }
512 
513 /* Print symbol SYMBOL on OUTFILE. DEPTH says how far to indent. */
514 
515 static void
517  int depth, ui_file *outfile)
518 {
519  struct obj_section *section;
520 
523  else
524  section = NULL;
525 
526  print_spaces (depth, outfile);
528  {
529  fprintf_filtered (outfile, "label %s at ", SYMBOL_PRINT_NAME (symbol));
531  outfile);
532  if (section)
533  fprintf_filtered (outfile, " section %s\n",
534  bfd_section_name (section->the_bfd_section->owner,
535  section->the_bfd_section));
536  else
537  fprintf_filtered (outfile, "\n");
538  return;
539  }
540 
542  {
544  {
545  LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth,
547  }
548  else
549  {
550  fprintf_filtered (outfile, "%s %s = ",
552  ? "enum"
554  ? "struct" : "union")),
556  LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth,
558  }
559  fprintf_filtered (outfile, ";\n");
560  }
561  else
562  {
564  fprintf_filtered (outfile, "typedef ");
565  if (SYMBOL_TYPE (symbol))
566  {
567  /* Print details of types, except for enums where it's clutter. */
569  outfile,
571  depth,
573  fprintf_filtered (outfile, "; ");
574  }
575  else
576  fprintf_filtered (outfile, "%s ", SYMBOL_PRINT_NAME (symbol));
577 
578  switch (SYMBOL_CLASS (symbol))
579  {
580  case LOC_CONST:
581  fprintf_filtered (outfile, "const %s (%s)",
584  break;
585 
586  case LOC_CONST_BYTES:
587  {
588  unsigned i;
589  struct type *type = check_typedef (SYMBOL_TYPE (symbol));
590 
591  fprintf_filtered (outfile, "const %u hex bytes:",
592  TYPE_LENGTH (type));
593  for (i = 0; i < TYPE_LENGTH (type); i++)
594  fprintf_filtered (outfile, " %02x",
595  (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]);
596  }
597  break;
598 
599  case LOC_STATIC:
600  fprintf_filtered (outfile, "static at ");
602  outfile);
603  if (section)
604  fprintf_filtered (outfile, " section %s",
605  bfd_section_name (section->the_bfd_section->owner,
606  section->the_bfd_section));
607  break;
608 
609  case LOC_REGISTER:
611  fprintf_filtered (outfile, "parameter register %s",
613  else
614  fprintf_filtered (outfile, "register %s",
616  break;
617 
618  case LOC_ARG:
619  fprintf_filtered (outfile, "arg at offset %s",
621  break;
622 
623  case LOC_REF_ARG:
624  fprintf_filtered (outfile, "reference arg at %s",
626  break;
627 
628  case LOC_REGPARM_ADDR:
629  fprintf_filtered (outfile, "address parameter register %s",
631  break;
632 
633  case LOC_LOCAL:
634  fprintf_filtered (outfile, "local at offset %s",
636  break;
637 
638  case LOC_TYPEDEF:
639  break;
640 
641  case LOC_LABEL:
642  fprintf_filtered (outfile, "label at ");
644  outfile);
645  if (section)
646  fprintf_filtered (outfile, " section %s",
647  bfd_section_name (section->the_bfd_section->owner,
648  section->the_bfd_section));
649  break;
650 
651  case LOC_BLOCK:
652  fprintf_filtered (outfile, "block object ");
654  fprintf_filtered (outfile, ", ");
657  outfile);
658  fprintf_filtered (outfile, "..");
661  outfile);
662  if (section)
663  fprintf_filtered (outfile, " section %s",
664  bfd_section_name (section->the_bfd_section->owner,
665  section->the_bfd_section));
666  break;
667 
668  case LOC_COMPUTED:
669  fprintf_filtered (outfile, "computed at runtime");
670  break;
671 
672  case LOC_UNRESOLVED:
673  fprintf_filtered (outfile, "unresolved");
674  break;
675 
676  case LOC_OPTIMIZED_OUT:
677  fprintf_filtered (outfile, "optimized out");
678  break;
679 
680  default:
681  fprintf_filtered (outfile, "botched symbol class %x",
682  SYMBOL_CLASS (symbol));
683  break;
684  }
685  }
686  fprintf_filtered (outfile, "\n");
687 }
688 
689 static void
690 maintenance_print_msymbols (const char *args, int from_tty)
691 {
692  struct ui_file *outfile = gdb_stdout;
693  char *objfile_arg = NULL;
694  struct objfile *objfile;
695  int i, outfile_idx;
696 
697  dont_repeat ();
698 
699  gdb_argv argv (args);
700 
701  for (i = 0; argv != NULL && argv[i] != NULL; ++i)
702  {
703  if (strcmp (argv[i], "-objfile") == 0)
704  {
705  if (argv[i + 1] == NULL)
706  error (_("Missing objfile name"));
707  objfile_arg = argv[++i];
708  }
709  else if (strcmp (argv[i], "--") == 0)
710  {
711  /* End of options. */
712  ++i;
713  break;
714  }
715  else if (argv[i][0] == '-')
716  {
717  /* Future proofing: Don't allow OUTFILE to begin with "-". */
718  error (_("Unknown option: %s"), argv[i]);
719  }
720  else
721  break;
722  }
723  outfile_idx = i;
724 
725  stdio_file arg_outfile;
726 
727  if (argv != NULL && argv[outfile_idx] != NULL)
728  {
729  if (argv[outfile_idx + 1] != NULL)
730  error (_("Junk at end of command"));
731  gdb::unique_xmalloc_ptr<char> outfile_name
732  (tilde_expand (argv[outfile_idx]));
733  if (!arg_outfile.open (outfile_name.get (), FOPEN_WT))
734  perror_with_name (outfile_name.get ());
735  outfile = &arg_outfile;
736  }
737 
739  {
740  QUIT;
741  if (objfile_arg == NULL
743  dump_msymbols (objfile, outfile);
744  }
745 }
746 
747 static void
748 maintenance_print_objfiles (const char *regexp, int from_tty)
749 {
750  struct program_space *pspace;
751  struct objfile *objfile;
752 
753  dont_repeat ();
754 
755  if (regexp)
756  re_comp (regexp);
757 
760  {
761  QUIT;
762  if (! regexp
763  || re_exec (objfile_name (objfile)))
765  }
766 }
767 
768 /* List all the symbol tables whose names match REGEXP (optional). */
769 
770 static void
771 maintenance_info_symtabs (const char *regexp, int from_tty)
772 {
773  struct program_space *pspace;
774  struct objfile *objfile;
775 
776  dont_repeat ();
777 
778  if (regexp)
779  re_comp (regexp);
780 
783  {
784  struct compunit_symtab *cust;
785  struct symtab *symtab;
786 
787  /* We don't want to print anything for this objfile until we
788  actually find a symtab whose name matches. */
789  int printed_objfile_start = 0;
790 
792  {
793  int printed_compunit_symtab_start = 0;
794 
796  {
797  QUIT;
798 
799  if (! regexp
800  || re_exec (symtab_to_filename_for_display (symtab)))
801  {
802  if (! printed_objfile_start)
803  {
804  printf_filtered ("{ objfile %s ", objfile_name (objfile));
805  wrap_here (" ");
806  printf_filtered ("((struct objfile *) %s)\n",
808  printed_objfile_start = 1;
809  }
810  if (! printed_compunit_symtab_start)
811  {
812  printf_filtered (" { ((struct compunit_symtab *) %s)\n",
813  host_address_to_string (cust));
814  printf_filtered (" debugformat %s\n",
815  COMPUNIT_DEBUGFORMAT (cust));
816  printf_filtered (" producer %s\n",
817  COMPUNIT_PRODUCER (cust) != NULL
818  ? COMPUNIT_PRODUCER (cust)
819  : "(null)");
820  printf_filtered (" dirname %s\n",
821  COMPUNIT_DIRNAME (cust) != NULL
822  ? COMPUNIT_DIRNAME (cust)
823  : "(null)");
824  printf_filtered (" blockvector"
825  " ((struct blockvector *) %s)\n",
827  (COMPUNIT_BLOCKVECTOR (cust)));
828  printed_compunit_symtab_start = 1;
829  }
830 
831  printf_filtered ("\t{ symtab %s ",
833  wrap_here (" ");
834  printf_filtered ("((struct symtab *) %s)\n",
836  printf_filtered ("\t fullname %s\n",
837  symtab->fullname != NULL
838  ? symtab->fullname
839  : "(null)");
840  printf_filtered ("\t "
841  "linetable ((struct linetable *) %s)\n",
843  printf_filtered ("\t}\n");
844  }
845  }
846 
847  if (printed_compunit_symtab_start)
848  printf_filtered (" }\n");
849  }
850 
851  if (printed_objfile_start)
852  printf_filtered ("}\n");
853  }
854 }
855 
856 /* Check consistency of symtabs.
857  An example of what this checks for is NULL blockvectors.
858  They can happen if there's a bug during debug info reading.
859  GDB assumes they are always non-NULL.
860 
861  Note: This does not check for psymtab vs symtab consistency.
862  Use "maint check-psymtabs" for that. */
863 
864 static void
865 maintenance_check_symtabs (const char *ignore, int from_tty)
866 {
867  struct program_space *pspace;
868  struct objfile *objfile;
869 
872  {
873  struct compunit_symtab *cust;
874 
875  /* We don't want to print anything for this objfile until we
876  actually find something worth printing. */
877  int printed_objfile_start = 0;
878 
880  {
881  int found_something = 0;
882  struct symtab *symtab = compunit_primary_filetab (cust);
883 
884  QUIT;
885 
886  if (COMPUNIT_BLOCKVECTOR (cust) == NULL)
887  found_something = 1;
888  /* Add more checks here. */
889 
890  if (found_something)
891  {
892  if (! printed_objfile_start)
893  {
894  printf_filtered ("{ objfile %s ", objfile_name (objfile));
895  wrap_here (" ");
896  printf_filtered ("((struct objfile *) %s)\n",
898  printed_objfile_start = 1;
899  }
900  printf_filtered (" { symtab %s\n",
902  if (COMPUNIT_BLOCKVECTOR (cust) == NULL)
903  printf_filtered (" NULL blockvector\n");
904  printf_filtered (" }\n");
905  }
906  }
907 
908  if (printed_objfile_start)
909  printf_filtered ("}\n");
910  }
911 }
912 
913 /* Expand all symbol tables whose name matches an optional regexp. */
914 
915 static void
916 maintenance_expand_symtabs (const char *args, int from_tty)
917 {
918  struct program_space *pspace;
919  struct objfile *objfile;
920  char *regexp = NULL;
921 
922  /* We use buildargv here so that we handle spaces in the regexp
923  in a way that allows adding more arguments later. */
924  gdb_argv argv (args);
925 
926  if (argv != NULL)
927  {
928  if (argv[0] != NULL)
929  {
930  regexp = argv[0];
931  if (argv[1] != NULL)
932  error (_("Extra arguments after regexp."));
933  }
934  }
935 
936  if (regexp)
937  re_comp (regexp);
938 
941  {
942  if (objfile->sf)
943  {
945  (objfile,
946  [&] (const char *filename, bool basenames)
947  {
948  /* KISS: Only apply the regexp to the complete file name. */
949  return (!basenames
950  && (regexp == NULL || re_exec (filename)));
951  },
953  [] (const char *symname)
954  {
955  /* Since we're not searching on symbols, just return true. */
956  return true;
957  },
958  NULL,
959  ALL_DOMAIN);
960  }
961  }
962 }
963 
964 
965 /* Return the nexting depth of a block within other blocks in its symtab. */
966 
967 static int
969 {
970  int i = 0;
971 
972  while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
973  {
974  i++;
975  }
976  return i;
977 }
978 
979 
980 /* Used by MAINTENANCE_INFO_LINE_TABLES to print the information about a
981  single line table. */
982 
983 static int
985 {
986  struct linetable *linetable;
987  struct objfile *objfile;
988 
990  printf_filtered (_("objfile: %s ((struct objfile *) %s)\n"),
993  printf_filtered (_("compunit_symtab: ((struct compunit_symtab *) %s)\n"),
995  printf_filtered (_("symtab: %s ((struct symtab *) %s)\n"),
999  printf_filtered (_("linetable: ((struct linetable *) %s):\n"),
1001 
1002  if (linetable == NULL)
1003  printf_filtered (_("No line table.\n"));
1004  else if (linetable->nitems <= 0)
1005  printf_filtered (_("Line table has no lines.\n"));
1006  else
1007  {
1008  int i;
1009 
1010  /* Leave space for 6 digits of index and line number. After that the
1011  tables will just not format as well. */
1012  printf_filtered (_("%-6s %6s %s\n"),
1013  _("INDEX"), _("LINE"), _("ADDRESS"));
1014 
1015  for (i = 0; i < linetable->nitems; ++i)
1016  {
1017  struct linetable_entry *item;
1018 
1019  item = &linetable->item [i];
1020  printf_filtered (_("%-6d %6d %s\n"), i, item->line,
1021  core_addr_to_string (item->pc));
1022  }
1023  }
1024 
1025  return 0;
1026 }
1027 
1028 /* Implement the 'maint info line-table' command. */
1029 
1030 static void
1031 maintenance_info_line_tables (const char *regexp, int from_tty)
1032 {
1033  struct program_space *pspace;
1034  struct objfile *objfile;
1035 
1036  dont_repeat ();
1037 
1038  if (regexp != NULL)
1039  re_comp (regexp);
1040 
1043  {
1044  struct compunit_symtab *cust;
1045  struct symtab *symtab;
1046 
1048  {
1050  {
1051  QUIT;
1052 
1053  if (regexp == NULL
1054  || re_exec (symtab_to_filename_for_display (symtab)))
1056  }
1057  }
1058  }
1059 }
1060 
1061 
1062 
1063 /* Do early runtime initializations. */
1064 
1065 void
1067 {
1068  std_in = stdin;
1069  std_out = stdout;
1070  std_err = stderr;
1071 
1073 Print dump of current symbol definitions.\n\
1074 Usage: mt print symbols [-pc address] [--] [outfile]\n\
1075  mt print symbols [-objfile objfile] [-source source] [--] [outfile]\n\
1076 Entries in the full symbol table are dumped to file OUTFILE,\n\
1077 or the terminal if OUTFILE is unspecified.\n\
1078 If ADDRESS is provided, dump only the file for that address.\n\
1079 If SOURCE is provided, dump only that file's symbols.\n\
1080 If OBJFILE is provided, dump only that file's minimal symbols."),
1082 
1084 Print dump of current minimal symbol definitions.\n\
1085 Usage: mt print msymbols [-objfile objfile] [--] [outfile]\n\
1086 Entries in the minimal symbol table are dumped to file OUTFILE,\n\
1087 or the terminal if OUTFILE is unspecified.\n\
1088 If OBJFILE is provided, dump only that file's minimal symbols."),
1090 
1092  _("Print dump of current object file definitions.\n\
1093 With an argument REGEXP, list the object files with matching names."),
1095 
1097 List the full symbol tables for all object files.\n\
1098 This does not include information about individual symbols, blocks, or\n\
1099 linetables --- just the symbol table structures themselves.\n\
1100 With an argument REGEXP, list the symbol tables with matching names."),
1102 
1104 List the contents of all line tables, from all symbol tables.\n\
1105 With an argument REGEXP, list just the line tables for the symbol\n\
1106 tables with matching names."),
1108 
1110  _("\
1111 Check consistency of currently expanded symtabs."),
1112  &maintenancelist);
1113 
1115  _("Expand symbol tables.\n\
1116 With an argument REGEXP, only expand the symbol tables with matching names."),
1117  &maintenancelist);
1118 }
void(* expand_symtabs_matching)(struct objfile *objfile, 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, enum search_domain kind)
Definition: symfile.h:256
static void maintenance_info_line_tables(const char *regexp, int from_tty)
Definition: symmisc.c:1031
const char * symtab_to_filename_for_display(struct symtab *symtab)
Definition: source.c:1168
#define SYMTAB_COMPUNIT(symtab)
Definition: symtab.h:1331
#define SYMTAB_DIRNAME(symtab)
Definition: symtab.h:1339
bfd * obfd
Definition: objfiles.h:342
#define ALL_OBJFILE_FILETABS(objfile, cu, s)
Definition: objfiles.h:594
#define COMPUNIT_DEBUGFORMAT(cust)
Definition: symtab.h:1462
#define SYMBOL_PRINT_NAME(symbol)
Definition: symtab.h:542
void print_objfile_statistics(void)
Definition: symmisc.c:83
#define MSYMBOL_LINKAGE_NAME(symbol)
Definition: symtab.h:707
bfd_vma CORE_ADDR
Definition: common-types.h:41
struct linetable_entry item[1]
Definition: symtab.h:1258
FILE * std_in
Definition: symmisc.c:49
struct bcache * psymbol_bcache_get_bcache(struct psymbol_bcache *bcache)
Definition: psymtab.c:1686
struct bfd_section * the_bfd_section
Definition: objfiles.h:126
void warning(const char *fmt,...)
Definition: errors.c:26
void _initialize_symmisc(void)
Definition: symmisc.c:1066
struct program_space * pspace
Definition: objfiles.h:315
enum language set_language(enum language lang)
Definition: language.c:379
struct cmd_list_element * maintenanceinfolist
Definition: cli-cmds.c:139
int compare_filenames_for_search(const char *filename, const char *search_name)
Definition: symtab.c:318
const struct type_print_options type_print_raw_options
Definition: typeprint.c:40
#define SYMBOL_CLASS(symbol)
Definition: symtab.h:1155
void print_spaces(int n, struct ui_file *file)
Definition: utils.c:810
void(* print_stats)(struct objfile *objfile)
Definition: symfile.h:183
#define ALL_DICT_SYMBOLS(dict, iter, sym)
Definition: dictionary.h:162
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:262
FILE * std_out
Definition: symmisc.c:50
#define BLOCKVECTOR_BLOCK(blocklist, n)
Definition: block.h:125
#define _(String)
Definition: gdb_locale.h:35
#define MSYMBOL_DEMANGLED_NAME(symbol)
Definition: symtab.h:710
#define BLOCK_START(bl)
Definition: block.h:105
#define COMPUNIT_DIRNAME(cust)
Definition: symtab.h:1464
#define END_CATCH
static void maintenance_expand_symtabs(const char *args, int from_tty)
Definition: symmisc.c:916
struct objfile_per_bfd_storage * per_bfd
Definition: objfiles.h:347
struct linetable * linetable
Definition: symtab.h:1305
struct objfile * symbol_objfile(const struct symbol *symbol)
Definition: symtab.c:5784
void printf_filtered(const char *format,...)
Definition: utils.c:2045
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition: utils.c:2745
#define SYMBOL_OBJ_SECTION(objfile, symbol)
Definition: symtab.h:471
#define BLOCK_FUNCTION(bl)
Definition: block.h:107
const char * symtab_to_fullname(struct symtab *s)
Definition: source.c:1131
#define MSYMBOL_OBJ_SECTION(objfile, symbol)
Definition: symtab.h:700
#define TRY
static void dump_msymbols(struct objfile *objfile, struct ui_file *outfile)
Definition: symmisc.c:185
struct objfile * objfile
Definition: symtab.h:1386
#define SYMTAB_BLOCKVECTOR(symtab)
Definition: symtab.h:1334
static void maintenance_check_symtabs(const char *ignore, int from_tty)
Definition: symmisc.c:865
struct type * check_typedef(struct type *type)
Definition: gdbtypes.c:2421
#define SYMBOL_VALUE_ADDRESS(symbol)
Definition: symtab.h:464
#define CATCH(EXCEPTION, MASK)
std::unique_ptr< T, xfree_deleter< T > > unique_xmalloc_ptr
#define SYMBOL_DOMAIN(symbol)
Definition: symtab.h:1152
CORE_ADDR pc
Definition: symtab.h:1231
objfile(bfd *, const char *, objfile_flags)
Definition: objfiles.c:373
void fprintf_filtered(struct ui_file *stream, const char *format,...)
Definition: utils.c:2008
#define SYMBOL_DEMANGLED_NAME(symbol)
Definition: symtab.h:527
#define SYMTAB_OBJFILE(symtab)
Definition: symtab.h:1336
const char * filename
Definition: symtab.h:640
static const lookup_name_info & match_any()
Definition: symtab.c:1794
struct symtab * compunit_primary_filetab(const struct compunit_symtab *cust)
Definition: symtab.c:292
void fputs_filtered(const char *linebuffer, struct ui_file *stream)
Definition: utils.c:1811
static void maintenance_print_symbols(const char *args, int from_tty)
Definition: symmisc.c:401
const struct sym_fns * sf
Definition: objfiles.h:381
struct gdbarch * get_objfile_arch(const struct objfile *objfile)
Definition: objfiles.c:445
struct obj_section * sections
Definition: objfiles.h:423
const char * language_str(enum language lang)
Definition: language.c:502
void print_bcache_statistics(struct bcache *c, const char *type)
Definition: bcache.c:359
Definition: symtab.h:1228
Definition: gdbtypes.h:749
#define BLOCK_SUPERBLOCK(bl)
Definition: block.h:108
enum language language
Definition: symtab.h:1323
void(* dump)(struct objfile *objfile)
Definition: symfile.h:187
#define COMPUNIT_PRODUCER(cust)
Definition: symtab.h:1463
int bcache_memory_used(struct bcache *bcache)
Definition: bcache.c:486
#define SYMBOL_LINKAGE_NAME(symbol)
Definition: symtab.h:523
void exception_fprintf(struct ui_file *file, struct gdb_exception e, const char *prefix,...)
Definition: exceptions.c:119
struct compunit_symtab * compunit_symtabs
Definition: objfiles.h:320
#define BLOCK_END(bl)
Definition: block.h:106
#define BLOCK_DICT(bl)
Definition: block.h:109
const char * objfile_name(const struct objfile *objfile)
Definition: objfiles.c:1557
#define gdb_print_host_address(ADDR, STREAM)
Definition: utils.h:438
struct cmd_list_element * maintenanceprintlist
Definition: cli-cmds.c:143
#define SYMBOL_VALUE(symbol)
Definition: symtab.h:463
Definition: block.h:60
#define ALL_OBJFILE_COMPUNITS(objfile, cu)
Definition: objfiles.h:600
void wrap_here(const char *indent)
Definition: utils.c:1596
static int maintenance_print_one_line_table(struct symtab *symtab, void *data)
Definition: symmisc.c:984
#define SYMBOL_OBJFILE_OWNED(symbol)
Definition: symtab.h:1156
#define LA_PRINT_TYPE(type, varstring, stream, show, level, flags)
Definition: language.h:518
#define COMPUNIT_BLOCKVECTOR(cust)
Definition: symtab.h:1465
#define MSYMBOL_TYPE(msymbol)
Definition: symtab.h:680
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
Definition: utils.c:692
#define ALL_PSPACES(pspace)
Definition: progspace.h:243
#define gdb_stderr
Definition: utils.h:344
#define SYMBOL_BLOCK_VALUE(symbol)
Definition: symtab.h:467
CORE_ADDR parse_and_eval_address(const char *exp)
Definition: eval.c:101
#define TYPE_CODE(thistype)
Definition: gdbtypes.h:1238
bool open(const char *name, const char *mode)
Definition: ui-file.c:171
static void dump_objfile(struct objfile *objfile)
Definition: symmisc.c:148
#define OBJSTAT(objfile, expr)
Definition: objfiles.h:174
static void maintenance_print_objfiles(const char *regexp, int from_tty)
Definition: symmisc.c:748
#define COMPUNIT_FILETABS(cust)
Definition: symtab.h:1461
static void maintenance_info_symtabs(const char *regexp, int from_tty)
Definition: symmisc.c:771
struct compunit_symtab * compunit_symtab
Definition: symtab.h:1300
#define BLOCKVECTOR_NBLOCKS(blocklist)
Definition: block.h:124
#define TYPE_TAG_NAME(type)
Definition: gdbtypes.h:1225
static void dump_symtab(struct symtab *symtab, struct ui_file *outfile)
Definition: symmisc.c:379
#define ALL_OBJFILE_MSYMBOLS(objfile, m)
Definition: objfiles.h:605
EXTERN_C char * re_comp(const char *)
FILE * std_err
Definition: symmisc.c:51
static int ignore(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
Definition: corelow.c:879
static void print_symbol(struct gdbarch *gdbarch, struct symbol *symbol, int depth, ui_file *outfile)
Definition: symmisc.c:516
language
Definition: defs.h:203
int nitems
Definition: symtab.h:1253
#define SYMBOL_TYPE(symbol)
Definition: symtab.h:1161
int dict_size(const struct dictionary *dict)
Definition: dictionary.c:539
struct cmd_list_element * maintenancelist
Definition: cli-cmds.c:135
void print_symbol_bcache_statistics(void)
Definition: symmisc.c:62
#define ALL_COMPUNIT_FILETABS(cu, s)
Definition: symtab.h:1474
argv
Definition: __init__.py:63
#define TYPE_LENGTH(thistype)
Definition: gdbtypes.h:1235
auto_obstack storage_obstack
Definition: objfiles.h:195
char * fullname
Definition: symtab.h:1328
void dont_repeat(void)
Definition: top.c:695
static int block_depth(struct block *)
Definition: symmisc.c:968
#define SYMBOL_VALUE_BYTES(symbol)
Definition: symtab.h:465
int line
Definition: symtab.h:1230
#define ALL_OBJFILES(obj)
Definition: objfiles.h:582
#define QUIT
Definition: defs.h:179
struct symtab * find_pc_line_symtab(CORE_ADDR pc)
Definition: symtab.c:3301
const struct quick_symbol_functions * qf
Definition: symfile.h:369
#define ALL_PSPACE_OBJFILES(ss, obj)
Definition: objfiles.h:579
#define SYMTAB_LINETABLE(symtab)
Definition: symtab.h:1332
struct psymbol_bcache * psymbol_cache
Definition: objfiles.h:362
void error(const char *fmt,...)
Definition: errors.c:38
#define MSYMBOL_VALUE_ADDRESS(objfile, symbol)
Definition: symtab.h:687
#define SYMBOL_IS_ARGUMENT(symbol)
Definition: symtab.h:1157
static void dump_symtab_1(struct symtab *symtab, struct ui_file *outfile)
Definition: symmisc.c:272
#define gdb_stdout
Definition: utils.h:340
static void maintenance_print_msymbols(const char *args, int from_tty)
Definition: symmisc.c:690