binutils/
[binutils-gdb.git] / gdb / symmisc.c
blob842c16f76ca9965144c410eaceb31feaa83d9847
1 /* Do various things to symbol tables (other than lookup), for GDB.
3 Copyright (C) 1986-2013 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "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 "exceptions.h"
31 #include "language.h"
32 #include "bcache.h"
33 #include "block.h"
34 #include "gdb_regex.h"
35 #include "gdb_stat.h"
36 #include "dictionary.h"
37 #include "typeprint.h"
38 #include "gdbcmd.h"
39 #include "source.h"
41 #include "gdb_string.h"
42 #include "readline/readline.h"
44 #include "psymtab.h"
46 #ifndef DEV_TTY
47 #define DEV_TTY "/dev/tty"
48 #endif
50 /* Unfortunately for debugging, stderr is usually a macro. This is painful
51 when calling functions that take FILE *'s from the debugger.
52 So we make a variable which has the same value and which is accessible when
53 debugging GDB with itself. Because stdin et al need not be constants,
54 we initialize them in the _initialize_symmisc function at the bottom
55 of the file. */
56 FILE *std_in;
57 FILE *std_out;
58 FILE *std_err;
60 /* Prototypes for local functions */
62 static int block_depth (struct block *);
64 void _initialize_symmisc (void);
66 struct print_symbol_args
68 struct gdbarch *gdbarch;
69 struct symbol *symbol;
70 int depth;
71 struct ui_file *outfile;
74 static int print_symbol (void *);
77 void
78 print_symbol_bcache_statistics (void)
80 struct program_space *pspace;
81 struct objfile *objfile;
83 ALL_PSPACES (pspace)
84 ALL_PSPACE_OBJFILES (pspace, objfile)
86 QUIT;
87 printf_filtered (_("Byte cache statistics for '%s':\n"), objfile->name);
88 print_bcache_statistics (psymbol_bcache_get_bcache (objfile->psymbol_cache),
89 "partial symbol cache");
90 print_bcache_statistics (objfile->per_bfd->macro_cache,
91 "preprocessor macro cache");
92 print_bcache_statistics (objfile->per_bfd->filename_cache,
93 "file name cache");
97 void
98 print_objfile_statistics (void)
100 struct program_space *pspace;
101 struct objfile *objfile;
102 struct symtab *s;
103 int i, linetables, blockvectors;
105 ALL_PSPACES (pspace)
106 ALL_PSPACE_OBJFILES (pspace, objfile)
108 QUIT;
109 printf_filtered (_("Statistics for '%s':\n"), objfile->name);
110 if (OBJSTAT (objfile, n_stabs) > 0)
111 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
112 OBJSTAT (objfile, n_stabs));
113 if (OBJSTAT (objfile, n_minsyms) > 0)
114 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
115 OBJSTAT (objfile, n_minsyms));
116 if (OBJSTAT (objfile, n_psyms) > 0)
117 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
118 OBJSTAT (objfile, n_psyms));
119 if (OBJSTAT (objfile, n_syms) > 0)
120 printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
121 OBJSTAT (objfile, n_syms));
122 if (OBJSTAT (objfile, n_types) > 0)
123 printf_filtered (_(" Number of \"types\" defined: %d\n"),
124 OBJSTAT (objfile, n_types));
125 if (objfile->sf)
126 objfile->sf->qf->print_stats (objfile);
127 i = linetables = blockvectors = 0;
128 ALL_OBJFILE_SYMTABS (objfile, s)
130 i++;
131 if (s->linetable != NULL)
132 linetables++;
133 if (s->primary == 1)
134 blockvectors++;
136 printf_filtered (_(" Number of symbol tables: %d\n"), i);
137 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
138 linetables);
139 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
140 blockvectors);
142 if (OBJSTAT (objfile, sz_strtab) > 0)
143 printf_filtered (_(" Space used by a.out string tables: %d\n"),
144 OBJSTAT (objfile, sz_strtab));
145 printf_filtered (_(" Total memory used for objfile obstack: %d\n"),
146 obstack_memory_used (&objfile->objfile_obstack));
147 printf_filtered (_(" Total memory used for BFD obstack: %d\n"),
148 obstack_memory_used (&objfile->per_bfd->storage_obstack));
149 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
150 bcache_memory_used (psymbol_bcache_get_bcache
151 (objfile->psymbol_cache)));
152 printf_filtered (_(" Total memory used for macro cache: %d\n"),
153 bcache_memory_used (objfile->per_bfd->macro_cache));
154 printf_filtered (_(" Total memory used for file name cache: %d\n"),
155 bcache_memory_used (objfile->per_bfd->filename_cache));
159 static void
160 dump_objfile (struct objfile *objfile)
162 struct symtab *symtab;
164 printf_filtered ("\nObject file %s: ", objfile->name);
165 printf_filtered ("Objfile at ");
166 gdb_print_host_address (objfile, gdb_stdout);
167 printf_filtered (", bfd at ");
168 gdb_print_host_address (objfile->obfd, gdb_stdout);
169 printf_filtered (", %d minsyms\n\n",
170 objfile->minimal_symbol_count);
172 if (objfile->sf)
173 objfile->sf->qf->dump (objfile);
175 if (objfile->symtabs)
177 printf_filtered ("Symtabs:\n");
178 for (symtab = objfile->symtabs;
179 symtab != NULL;
180 symtab = symtab->next)
182 printf_filtered ("%s at ", symtab_to_filename_for_display (symtab));
183 gdb_print_host_address (symtab, gdb_stdout);
184 printf_filtered (", ");
185 if (symtab->objfile != objfile)
187 printf_filtered ("NOT ON CHAIN! ");
189 wrap_here (" ");
191 printf_filtered ("\n\n");
195 /* Print minimal symbols from this objfile. */
197 static void
198 dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
200 struct gdbarch *gdbarch = get_objfile_arch (objfile);
201 struct minimal_symbol *msymbol;
202 int index;
203 char ms_type;
205 fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile->name);
206 if (objfile->minimal_symbol_count == 0)
208 fprintf_filtered (outfile, "No minimal symbols found.\n");
209 return;
211 index = 0;
212 ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
214 struct obj_section *section = SYMBOL_OBJ_SECTION (objfile, msymbol);
216 switch (MSYMBOL_TYPE (msymbol))
218 case mst_unknown:
219 ms_type = 'u';
220 break;
221 case mst_text:
222 ms_type = 'T';
223 break;
224 case mst_text_gnu_ifunc:
225 ms_type = 'i';
226 break;
227 case mst_solib_trampoline:
228 ms_type = 'S';
229 break;
230 case mst_data:
231 ms_type = 'D';
232 break;
233 case mst_bss:
234 ms_type = 'B';
235 break;
236 case mst_abs:
237 ms_type = 'A';
238 break;
239 case mst_file_text:
240 ms_type = 't';
241 break;
242 case mst_file_data:
243 ms_type = 'd';
244 break;
245 case mst_file_bss:
246 ms_type = 'b';
247 break;
248 default:
249 ms_type = '?';
250 break;
252 fprintf_filtered (outfile, "[%2d] %c ", index, ms_type);
253 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (msymbol)),
254 outfile);
255 fprintf_filtered (outfile, " %s", SYMBOL_LINKAGE_NAME (msymbol));
256 if (section)
258 if (section->the_bfd_section != NULL)
259 fprintf_filtered (outfile, " section %s",
260 bfd_section_name (objfile->obfd,
261 section->the_bfd_section));
262 else
263 fprintf_filtered (outfile, " spurious section %ld",
264 (long) (section - objfile->sections));
266 if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
268 fprintf_filtered (outfile, " %s", SYMBOL_DEMANGLED_NAME (msymbol));
270 if (msymbol->filename)
271 fprintf_filtered (outfile, " %s", msymbol->filename);
272 fputs_filtered ("\n", outfile);
273 index++;
275 if (objfile->minimal_symbol_count != index)
277 warning (_("internal error: minimal symbol count %d != %d"),
278 objfile->minimal_symbol_count, index);
280 fprintf_filtered (outfile, "\n");
283 static void
284 dump_symtab_1 (struct objfile *objfile, struct symtab *symtab,
285 struct ui_file *outfile)
287 struct gdbarch *gdbarch = get_objfile_arch (objfile);
288 int i;
289 struct dict_iterator iter;
290 int len;
291 struct linetable *l;
292 struct blockvector *bv;
293 struct symbol *sym;
294 struct block *b;
295 int depth;
297 fprintf_filtered (outfile, "\nSymtab for file %s\n",
298 symtab_to_filename_for_display (symtab));
299 if (symtab->dirname)
300 fprintf_filtered (outfile, "Compilation directory is %s\n",
301 symtab->dirname);
302 fprintf_filtered (outfile, "Read from object file %s (", objfile->name);
303 gdb_print_host_address (objfile, outfile);
304 fprintf_filtered (outfile, ")\n");
305 fprintf_filtered (outfile, "Language: %s\n",
306 language_str (symtab->language));
308 /* First print the line table. */
309 l = LINETABLE (symtab);
310 if (l)
312 fprintf_filtered (outfile, "\nLine table:\n\n");
313 len = l->nitems;
314 for (i = 0; i < len; i++)
316 fprintf_filtered (outfile, " line %d at ", l->item[i].line);
317 fputs_filtered (paddress (gdbarch, l->item[i].pc), outfile);
318 fprintf_filtered (outfile, "\n");
321 /* Now print the block info, but only for primary symtabs since we will
322 print lots of duplicate info otherwise. */
323 if (symtab->primary)
325 fprintf_filtered (outfile, "\nBlockvector:\n\n");
326 bv = BLOCKVECTOR (symtab);
327 len = BLOCKVECTOR_NBLOCKS (bv);
328 for (i = 0; i < len; i++)
330 b = BLOCKVECTOR_BLOCK (bv, i);
331 depth = block_depth (b) * 2;
332 print_spaces (depth, outfile);
333 fprintf_filtered (outfile, "block #%03d, object at ", i);
334 gdb_print_host_address (b, outfile);
335 if (BLOCK_SUPERBLOCK (b))
337 fprintf_filtered (outfile, " under ");
338 gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile);
340 /* drow/2002-07-10: We could save the total symbols count
341 even if we're using a hashtable, but nothing else but this message
342 wants it. */
343 fprintf_filtered (outfile, ", %d syms/buckets in ",
344 dict_size (BLOCK_DICT (b)));
345 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), outfile);
346 fprintf_filtered (outfile, "..");
347 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), outfile);
348 if (BLOCK_FUNCTION (b))
350 fprintf_filtered (outfile, ", function %s",
351 SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b)));
352 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
354 fprintf_filtered (outfile, ", %s",
355 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
358 fprintf_filtered (outfile, "\n");
359 /* Now print each symbol in this block (in no particular order, if
360 we're using a hashtable). Note that we only want this
361 block, not any blocks from included symtabs. */
362 ALL_DICT_SYMBOLS (BLOCK_DICT (b), iter, sym)
364 struct print_symbol_args s;
366 s.gdbarch = gdbarch;
367 s.symbol = sym;
368 s.depth = depth + 1;
369 s.outfile = outfile;
370 catch_errors (print_symbol, &s, "Error printing symbol:\n",
371 RETURN_MASK_ERROR);
374 fprintf_filtered (outfile, "\n");
376 else
378 fprintf_filtered (outfile, "\nBlockvector same as previous symtab\n\n");
382 static void
383 dump_symtab (struct objfile *objfile, struct symtab *symtab,
384 struct ui_file *outfile)
386 /* Set the current language to the language of the symtab we're dumping
387 because certain routines used during dump_symtab() use the current
388 language to print an image of the symbol. We'll restore it later.
389 But use only real languages, not placeholders. */
390 if (symtab->language != language_unknown
391 && symtab->language != language_auto)
393 enum language saved_lang;
395 saved_lang = set_language (symtab->language);
397 dump_symtab_1 (objfile, symtab, outfile);
399 set_language (saved_lang);
401 else
402 dump_symtab_1 (objfile, symtab, outfile);
405 static void
406 maintenance_print_symbols (char *args, int from_tty)
408 char **argv;
409 struct ui_file *outfile;
410 struct cleanup *cleanups;
411 char *symname = NULL;
412 char *filename = DEV_TTY;
413 struct objfile *objfile;
414 struct symtab *s;
416 dont_repeat ();
418 if (args == NULL)
420 error (_("Arguments missing: an output file name "
421 "and an optional symbol file name"));
423 argv = gdb_buildargv (args);
424 cleanups = make_cleanup_freeargv (argv);
426 if (argv[0] != NULL)
428 filename = argv[0];
429 /* If a second arg is supplied, it is a source file name to match on. */
430 if (argv[1] != NULL)
432 symname = argv[1];
436 filename = tilde_expand (filename);
437 make_cleanup (xfree, filename);
439 outfile = gdb_fopen (filename, FOPEN_WT);
440 if (outfile == 0)
441 perror_with_name (filename);
442 make_cleanup_ui_file_delete (outfile);
444 ALL_SYMTABS (objfile, s)
446 QUIT;
447 if (symname == NULL
448 || filename_cmp (symname, symtab_to_filename_for_display (s)) == 0)
449 dump_symtab (objfile, s, outfile);
451 do_cleanups (cleanups);
454 /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
455 far to indent. ARGS is really a struct print_symbol_args *, but is
456 declared as char * to get it past catch_errors. Returns 0 for error,
457 1 for success. */
459 static int
460 print_symbol (void *args)
462 struct gdbarch *gdbarch = ((struct print_symbol_args *) args)->gdbarch;
463 struct symbol *symbol = ((struct print_symbol_args *) args)->symbol;
464 int depth = ((struct print_symbol_args *) args)->depth;
465 struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile;
466 struct obj_section *section = SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (symbol),
467 symbol);
469 print_spaces (depth, outfile);
470 if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN)
472 fprintf_filtered (outfile, "label %s at ", SYMBOL_PRINT_NAME (symbol));
473 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
474 outfile);
475 if (section)
476 fprintf_filtered (outfile, " section %s\n",
477 bfd_section_name (section->the_bfd_section->owner,
478 section->the_bfd_section));
479 else
480 fprintf_filtered (outfile, "\n");
481 return 1;
483 if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN)
485 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
487 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth,
488 &type_print_raw_options);
490 else
492 fprintf_filtered (outfile, "%s %s = ",
493 (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
494 ? "enum"
495 : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
496 ? "struct" : "union")),
497 SYMBOL_LINKAGE_NAME (symbol));
498 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth,
499 &type_print_raw_options);
501 fprintf_filtered (outfile, ";\n");
503 else
505 if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
506 fprintf_filtered (outfile, "typedef ");
507 if (SYMBOL_TYPE (symbol))
509 /* Print details of types, except for enums where it's clutter. */
510 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_PRINT_NAME (symbol),
511 outfile,
512 TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
513 depth,
514 &type_print_raw_options);
515 fprintf_filtered (outfile, "; ");
517 else
518 fprintf_filtered (outfile, "%s ", SYMBOL_PRINT_NAME (symbol));
520 switch (SYMBOL_CLASS (symbol))
522 case LOC_CONST:
523 fprintf_filtered (outfile, "const %s (%s)",
524 plongest (SYMBOL_VALUE (symbol)),
525 hex_string (SYMBOL_VALUE (symbol)));
526 break;
528 case LOC_CONST_BYTES:
530 unsigned i;
531 struct type *type = check_typedef (SYMBOL_TYPE (symbol));
533 fprintf_filtered (outfile, "const %u hex bytes:",
534 TYPE_LENGTH (type));
535 for (i = 0; i < TYPE_LENGTH (type); i++)
536 fprintf_filtered (outfile, " %02x",
537 (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]);
539 break;
541 case LOC_STATIC:
542 fprintf_filtered (outfile, "static at ");
543 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
544 outfile);
545 if (section)
546 fprintf_filtered (outfile, " section %s",
547 bfd_section_name (section->the_bfd_section->owner,
548 section->the_bfd_section));
549 break;
551 case LOC_REGISTER:
552 if (SYMBOL_IS_ARGUMENT (symbol))
553 fprintf_filtered (outfile, "parameter register %s",
554 plongest (SYMBOL_VALUE (symbol)));
555 else
556 fprintf_filtered (outfile, "register %s",
557 plongest (SYMBOL_VALUE (symbol)));
558 break;
560 case LOC_ARG:
561 fprintf_filtered (outfile, "arg at offset %s",
562 hex_string (SYMBOL_VALUE (symbol)));
563 break;
565 case LOC_REF_ARG:
566 fprintf_filtered (outfile, "reference arg at %s",
567 hex_string (SYMBOL_VALUE (symbol)));
568 break;
570 case LOC_REGPARM_ADDR:
571 fprintf_filtered (outfile, "address parameter register %s",
572 plongest (SYMBOL_VALUE (symbol)));
573 break;
575 case LOC_LOCAL:
576 fprintf_filtered (outfile, "local at offset %s",
577 hex_string (SYMBOL_VALUE (symbol)));
578 break;
580 case LOC_TYPEDEF:
581 break;
583 case LOC_LABEL:
584 fprintf_filtered (outfile, "label at ");
585 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
586 outfile);
587 if (section)
588 fprintf_filtered (outfile, " section %s",
589 bfd_section_name (section->the_bfd_section->owner,
590 section->the_bfd_section));
591 break;
593 case LOC_BLOCK:
594 fprintf_filtered (outfile, "block object ");
595 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
596 fprintf_filtered (outfile, ", ");
597 fputs_filtered (paddress (gdbarch,
598 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol))),
599 outfile);
600 fprintf_filtered (outfile, "..");
601 fputs_filtered (paddress (gdbarch,
602 BLOCK_END (SYMBOL_BLOCK_VALUE (symbol))),
603 outfile);
604 if (section)
605 fprintf_filtered (outfile, " section %s",
606 bfd_section_name (section->the_bfd_section->owner,
607 section->the_bfd_section));
608 break;
610 case LOC_COMPUTED:
611 fprintf_filtered (outfile, "computed at runtime");
612 break;
614 case LOC_UNRESOLVED:
615 fprintf_filtered (outfile, "unresolved");
616 break;
618 case LOC_OPTIMIZED_OUT:
619 fprintf_filtered (outfile, "optimized out");
620 break;
622 default:
623 fprintf_filtered (outfile, "botched symbol class %x",
624 SYMBOL_CLASS (symbol));
625 break;
628 fprintf_filtered (outfile, "\n");
629 return 1;
632 static void
633 maintenance_print_msymbols (char *args, int from_tty)
635 char **argv;
636 struct ui_file *outfile;
637 struct cleanup *cleanups;
638 char *filename = DEV_TTY;
639 char *symname = NULL;
640 struct program_space *pspace;
641 struct objfile *objfile;
643 struct stat sym_st, obj_st;
645 dont_repeat ();
647 if (args == NULL)
649 error (_("print-msymbols takes an output file "
650 "name and optional symbol file name"));
652 argv = gdb_buildargv (args);
653 cleanups = make_cleanup_freeargv (argv);
655 if (argv[0] != NULL)
657 filename = argv[0];
658 /* If a second arg is supplied, it is a source file name to match on. */
659 if (argv[1] != NULL)
661 symname = gdb_realpath (argv[1]);
662 make_cleanup (xfree, symname);
663 if (symname && stat (symname, &sym_st))
664 perror_with_name (symname);
668 filename = tilde_expand (filename);
669 make_cleanup (xfree, filename);
671 outfile = gdb_fopen (filename, FOPEN_WT);
672 if (outfile == 0)
673 perror_with_name (filename);
674 make_cleanup_ui_file_delete (outfile);
676 ALL_PSPACES (pspace)
677 ALL_PSPACE_OBJFILES (pspace, objfile)
679 QUIT;
680 if (symname == NULL || (!stat (objfile->name, &obj_st)
681 && sym_st.st_dev == obj_st.st_dev
682 && sym_st.st_ino == obj_st.st_ino))
683 dump_msymbols (objfile, outfile);
685 fprintf_filtered (outfile, "\n\n");
686 do_cleanups (cleanups);
689 static void
690 maintenance_print_objfiles (char *regexp, int from_tty)
692 struct program_space *pspace;
693 struct objfile *objfile;
695 dont_repeat ();
697 if (regexp)
698 re_comp (regexp);
700 ALL_PSPACES (pspace)
701 ALL_PSPACE_OBJFILES (pspace, objfile)
703 QUIT;
704 if (! regexp
705 || re_exec (objfile->name))
706 dump_objfile (objfile);
710 /* List all the symbol tables whose names match REGEXP (optional). */
712 static void
713 maintenance_info_symtabs (char *regexp, int from_tty)
715 struct program_space *pspace;
716 struct objfile *objfile;
718 dont_repeat ();
720 if (regexp)
721 re_comp (regexp);
723 ALL_PSPACES (pspace)
724 ALL_PSPACE_OBJFILES (pspace, objfile)
726 struct symtab *symtab;
728 /* We don't want to print anything for this objfile until we
729 actually find a symtab whose name matches. */
730 int printed_objfile_start = 0;
732 ALL_OBJFILE_SYMTABS (objfile, symtab)
734 QUIT;
736 if (! regexp
737 || re_exec (symtab_to_filename_for_display (symtab)))
739 if (! printed_objfile_start)
741 printf_filtered ("{ objfile %s ", objfile->name);
742 wrap_here (" ");
743 printf_filtered ("((struct objfile *) %s)\n",
744 host_address_to_string (objfile));
745 printed_objfile_start = 1;
748 printf_filtered (" { symtab %s ",
749 symtab_to_filename_for_display (symtab));
750 wrap_here (" ");
751 printf_filtered ("((struct symtab *) %s)\n",
752 host_address_to_string (symtab));
753 printf_filtered (" dirname %s\n",
754 symtab->dirname ? symtab->dirname : "(null)");
755 printf_filtered (" fullname %s\n",
756 symtab->fullname ? symtab->fullname : "(null)");
757 printf_filtered (" "
758 "blockvector ((struct blockvector *) %s)%s\n",
759 host_address_to_string (symtab->blockvector),
760 symtab->primary ? " (primary)" : "");
761 printf_filtered (" "
762 "linetable ((struct linetable *) %s)\n",
763 host_address_to_string (symtab->linetable));
764 printf_filtered (" debugformat %s\n",
765 symtab->debugformat);
766 printf_filtered (" }\n");
770 if (printed_objfile_start)
771 printf_filtered ("}\n");
775 /* Check consistency of symtabs.
776 An example of what this checks for is NULL blockvectors.
777 They can happen if there's a bug during debug info reading.
778 GDB assumes they are always non-NULL.
780 Note: This does not check for psymtab vs symtab consistency.
781 Use "maint check-psymtabs" for that. */
783 static void
784 maintenance_check_symtabs (char *ignore, int from_tty)
786 struct program_space *pspace;
787 struct objfile *objfile;
789 ALL_PSPACES (pspace)
790 ALL_PSPACE_OBJFILES (pspace, objfile)
792 struct symtab *symtab;
794 /* We don't want to print anything for this objfile until we
795 actually find something worth printing. */
796 int printed_objfile_start = 0;
798 ALL_OBJFILE_SYMTABS (objfile, symtab)
800 int found_something = 0;
802 QUIT;
804 if (symtab->blockvector == NULL)
805 found_something = 1;
806 /* Add more checks here. */
808 if (found_something)
810 if (! printed_objfile_start)
812 printf_filtered ("{ objfile %s ", objfile->name);
813 wrap_here (" ");
814 printf_filtered ("((struct objfile *) %s)\n",
815 host_address_to_string (objfile));
816 printed_objfile_start = 1;
818 printf_filtered (" { symtab %s\n",
819 symtab_to_filename_for_display (symtab));
820 if (symtab->blockvector == NULL)
821 printf_filtered (" NULL blockvector\n");
822 printf_filtered (" }\n");
826 if (printed_objfile_start)
827 printf_filtered ("}\n");
831 /* Helper function for maintenance_expand_symtabs.
832 This is the name_matcher function for expand_symtabs_matching. */
834 static int
835 maintenance_expand_name_matcher (const char *symname, void *data)
837 /* Since we're not searching on symbols, just return TRUE. */
838 return 1;
841 /* Helper function for maintenance_expand_symtabs.
842 This is the file_matcher function for expand_symtabs_matching. */
844 static int
845 maintenance_expand_file_matcher (const char *filename, void *data,
846 int basenames)
848 const char *regexp = data;
850 QUIT;
852 /* KISS: Only apply the regexp to the complete file name. */
853 if (basenames)
854 return 0;
856 if (regexp == NULL || re_exec (filename))
857 return 1;
859 return 0;
862 /* Expand all symbol tables whose name matches an optional regexp. */
864 static void
865 maintenance_expand_symtabs (char *args, int from_tty)
867 struct program_space *pspace;
868 struct objfile *objfile;
869 struct cleanup *cleanups;
870 char **argv;
871 char *regexp = NULL;
873 /* We use buildargv here so that we handle spaces in the regexp
874 in a way that allows adding more arguments later. */
875 argv = gdb_buildargv (args);
876 cleanups = make_cleanup_freeargv (argv);
878 if (argv != NULL)
880 if (argv[0] != NULL)
882 regexp = argv[0];
883 if (argv[1] != NULL)
884 error (_("Extra arguments after regexp."));
888 if (regexp)
889 re_comp (regexp);
891 ALL_PSPACES (pspace)
892 ALL_PSPACE_OBJFILES (pspace, objfile)
894 if (objfile->sf)
896 objfile->sf->qf->expand_symtabs_matching
897 (objfile, maintenance_expand_file_matcher,
898 maintenance_expand_name_matcher, ALL_DOMAIN, regexp);
902 do_cleanups (cleanups);
906 /* Return the nexting depth of a block within other blocks in its symtab. */
908 static int
909 block_depth (struct block *block)
911 int i = 0;
913 while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
915 i++;
917 return i;
921 /* Do early runtime initializations. */
923 void
924 _initialize_symmisc (void)
926 std_in = stdin;
927 std_out = stdout;
928 std_err = stderr;
930 add_cmd ("symbols", class_maintenance, maintenance_print_symbols, _("\
931 Print dump of current symbol definitions.\n\
932 Entries in the full symbol table are dumped to file OUTFILE.\n\
933 If a SOURCE file is specified, dump only that file's symbols."),
934 &maintenanceprintlist);
936 add_cmd ("msymbols", class_maintenance, maintenance_print_msymbols, _("\
937 Print dump of current minimal symbol definitions.\n\
938 Entries in the minimal symbol table are dumped to file OUTFILE.\n\
939 If a SOURCE file is specified, dump only that file's minimal symbols."),
940 &maintenanceprintlist);
942 add_cmd ("objfiles", class_maintenance, maintenance_print_objfiles,
943 _("Print dump of current object file definitions.\n\
944 With an argument REGEXP, list the object files with matching names."),
945 &maintenanceprintlist);
947 add_cmd ("symtabs", class_maintenance, maintenance_info_symtabs, _("\
948 List the full symbol tables for all object files.\n\
949 This does not include information about individual symbols, blocks, or\n\
950 linetables --- just the symbol table structures themselves.\n\
951 With an argument REGEXP, list the symbol tables with matching names."),
952 &maintenanceinfolist);
954 add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs,
955 _("\
956 Check consistency of currently expanded symtabs."),
957 &maintenancelist);
959 add_cmd ("expand-symtabs", class_maintenance, maintenance_expand_symtabs,
960 _("Expand symbol tables.\n\
961 With an argument REGEXP, only expand the symbol tables with matching names."),
962 &maintenancelist);