2013-08-30 Phil Muldoon <pmuldoon@redhat.com>
[deliverable/binutils-gdb.git] / gdb / symmisc.c
1 /* Do various things to symbol tables (other than lookup), for GDB.
2
3 Copyright (C) 1986-2013 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 "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"
40
41 #include "gdb_string.h"
42 #include "readline/readline.h"
43
44 #include "psymtab.h"
45
46 #ifndef DEV_TTY
47 #define DEV_TTY "/dev/tty"
48 #endif
49
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;
59
60 /* Prototypes for local functions */
61
62 static int block_depth (struct block *);
63
64 void _initialize_symmisc (void);
65
66 struct print_symbol_args
67 {
68 struct gdbarch *gdbarch;
69 struct symbol *symbol;
70 int depth;
71 struct ui_file *outfile;
72 };
73
74 static int print_symbol (void *);
75 \f
76
77 void
78 print_symbol_bcache_statistics (void)
79 {
80 struct program_space *pspace;
81 struct objfile *objfile;
82
83 ALL_PSPACES (pspace)
84 ALL_PSPACE_OBJFILES (pspace, objfile)
85 {
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");
94 }
95 }
96
97 void
98 print_objfile_statistics (void)
99 {
100 struct program_space *pspace;
101 struct objfile *objfile;
102 struct symtab *s;
103 int i, linetables, blockvectors;
104
105 ALL_PSPACES (pspace)
106 ALL_PSPACE_OBJFILES (pspace, objfile)
107 {
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)
129 {
130 i++;
131 if (s->linetable != NULL)
132 linetables++;
133 if (s->primary == 1)
134 blockvectors++;
135 }
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);
141
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));
156 }
157 }
158
159 static void
160 dump_objfile (struct objfile *objfile)
161 {
162 struct symtab *symtab;
163
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);
171
172 if (objfile->sf)
173 objfile->sf->qf->dump (objfile);
174
175 if (objfile->symtabs)
176 {
177 printf_filtered ("Symtabs:\n");
178 for (symtab = objfile->symtabs;
179 symtab != NULL;
180 symtab = symtab->next)
181 {
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)
186 {
187 printf_filtered ("NOT ON CHAIN! ");
188 }
189 wrap_here (" ");
190 }
191 printf_filtered ("\n\n");
192 }
193 }
194
195 /* Print minimal symbols from this objfile. */
196
197 static void
198 dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
199 {
200 struct gdbarch *gdbarch = get_objfile_arch (objfile);
201 struct minimal_symbol *msymbol;
202 int index;
203 char ms_type;
204
205 fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile->name);
206 if (objfile->minimal_symbol_count == 0)
207 {
208 fprintf_filtered (outfile, "No minimal symbols found.\n");
209 return;
210 }
211 index = 0;
212 ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
213 {
214 struct obj_section *section = SYMBOL_OBJ_SECTION (objfile, msymbol);
215
216 switch (MSYMBOL_TYPE (msymbol))
217 {
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;
251 }
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)
257 {
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));
265 }
266 if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
267 {
268 fprintf_filtered (outfile, " %s", SYMBOL_DEMANGLED_NAME (msymbol));
269 }
270 if (msymbol->filename)
271 fprintf_filtered (outfile, " %s", msymbol->filename);
272 fputs_filtered ("\n", outfile);
273 index++;
274 }
275 if (objfile->minimal_symbol_count != index)
276 {
277 warning (_("internal error: minimal symbol count %d != %d"),
278 objfile->minimal_symbol_count, index);
279 }
280 fprintf_filtered (outfile, "\n");
281 }
282
283 static void
284 dump_symtab_1 (struct objfile *objfile, struct symtab *symtab,
285 struct ui_file *outfile)
286 {
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;
296
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));
307
308 /* First print the line table. */
309 l = LINETABLE (symtab);
310 if (l)
311 {
312 fprintf_filtered (outfile, "\nLine table:\n\n");
313 len = l->nitems;
314 for (i = 0; i < len; i++)
315 {
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");
319 }
320 }
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)
324 {
325 fprintf_filtered (outfile, "\nBlockvector:\n\n");
326 bv = BLOCKVECTOR (symtab);
327 len = BLOCKVECTOR_NBLOCKS (bv);
328 for (i = 0; i < len; i++)
329 {
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))
336 {
337 fprintf_filtered (outfile, " under ");
338 gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile);
339 }
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))
349 {
350 fprintf_filtered (outfile, ", function %s",
351 SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b)));
352 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
353 {
354 fprintf_filtered (outfile, ", %s",
355 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
356 }
357 }
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)
363 {
364 struct print_symbol_args s;
365
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);
372 }
373 }
374 fprintf_filtered (outfile, "\n");
375 }
376 else
377 {
378 fprintf_filtered (outfile, "\nBlockvector same as previous symtab\n\n");
379 }
380 }
381
382 static void
383 dump_symtab (struct objfile *objfile, struct symtab *symtab,
384 struct ui_file *outfile)
385 {
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)
392 {
393 enum language saved_lang;
394
395 saved_lang = set_language (symtab->language);
396
397 dump_symtab_1 (objfile, symtab, outfile);
398
399 set_language (saved_lang);
400 }
401 else
402 dump_symtab_1 (objfile, symtab, outfile);
403 }
404
405 static void
406 maintenance_print_symbols (char *args, int from_tty)
407 {
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;
415
416 dont_repeat ();
417
418 if (args == NULL)
419 {
420 error (_("Arguments missing: an output file name "
421 "and an optional symbol file name"));
422 }
423 argv = gdb_buildargv (args);
424 cleanups = make_cleanup_freeargv (argv);
425
426 if (argv[0] != NULL)
427 {
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)
431 {
432 symname = argv[1];
433 }
434 }
435
436 filename = tilde_expand (filename);
437 make_cleanup (xfree, filename);
438
439 outfile = gdb_fopen (filename, FOPEN_WT);
440 if (outfile == 0)
441 perror_with_name (filename);
442 make_cleanup_ui_file_delete (outfile);
443
444 ALL_SYMTABS (objfile, s)
445 {
446 QUIT;
447 if (symname == NULL
448 || filename_cmp (symname, symtab_to_filename_for_display (s)) == 0)
449 dump_symtab (objfile, s, outfile);
450 }
451 do_cleanups (cleanups);
452 }
453
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. */
458
459 static int
460 print_symbol (void *args)
461 {
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);
468
469 print_spaces (depth, outfile);
470 if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN)
471 {
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;
482 }
483 if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN)
484 {
485 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
486 {
487 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth,
488 &type_print_raw_options);
489 }
490 else
491 {
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);
500 }
501 fprintf_filtered (outfile, ";\n");
502 }
503 else
504 {
505 if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
506 fprintf_filtered (outfile, "typedef ");
507 if (SYMBOL_TYPE (symbol))
508 {
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, "; ");
516 }
517 else
518 fprintf_filtered (outfile, "%s ", SYMBOL_PRINT_NAME (symbol));
519
520 switch (SYMBOL_CLASS (symbol))
521 {
522 case LOC_CONST:
523 fprintf_filtered (outfile, "const %s (%s)",
524 plongest (SYMBOL_VALUE (symbol)),
525 hex_string (SYMBOL_VALUE (symbol)));
526 break;
527
528 case LOC_CONST_BYTES:
529 {
530 unsigned i;
531 struct type *type = check_typedef (SYMBOL_TYPE (symbol));
532
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]);
538 }
539 break;
540
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;
550
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;
559
560 case LOC_ARG:
561 fprintf_filtered (outfile, "arg at offset %s",
562 hex_string (SYMBOL_VALUE (symbol)));
563 break;
564
565 case LOC_REF_ARG:
566 fprintf_filtered (outfile, "reference arg at %s",
567 hex_string (SYMBOL_VALUE (symbol)));
568 break;
569
570 case LOC_REGPARM_ADDR:
571 fprintf_filtered (outfile, "address parameter register %s",
572 plongest (SYMBOL_VALUE (symbol)));
573 break;
574
575 case LOC_LOCAL:
576 fprintf_filtered (outfile, "local at offset %s",
577 hex_string (SYMBOL_VALUE (symbol)));
578 break;
579
580 case LOC_TYPEDEF:
581 break;
582
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;
592
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;
609
610 case LOC_COMPUTED:
611 fprintf_filtered (outfile, "computed at runtime");
612 break;
613
614 case LOC_UNRESOLVED:
615 fprintf_filtered (outfile, "unresolved");
616 break;
617
618 case LOC_OPTIMIZED_OUT:
619 fprintf_filtered (outfile, "optimized out");
620 break;
621
622 default:
623 fprintf_filtered (outfile, "botched symbol class %x",
624 SYMBOL_CLASS (symbol));
625 break;
626 }
627 }
628 fprintf_filtered (outfile, "\n");
629 return 1;
630 }
631
632 static void
633 maintenance_print_msymbols (char *args, int from_tty)
634 {
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;
642
643 struct stat sym_st, obj_st;
644
645 dont_repeat ();
646
647 if (args == NULL)
648 {
649 error (_("print-msymbols takes an output file "
650 "name and optional symbol file name"));
651 }
652 argv = gdb_buildargv (args);
653 cleanups = make_cleanup_freeargv (argv);
654
655 if (argv[0] != NULL)
656 {
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)
660 {
661 symname = gdb_realpath (argv[1]);
662 make_cleanup (xfree, symname);
663 if (symname && stat (symname, &sym_st))
664 perror_with_name (symname);
665 }
666 }
667
668 filename = tilde_expand (filename);
669 make_cleanup (xfree, filename);
670
671 outfile = gdb_fopen (filename, FOPEN_WT);
672 if (outfile == 0)
673 perror_with_name (filename);
674 make_cleanup_ui_file_delete (outfile);
675
676 ALL_PSPACES (pspace)
677 ALL_PSPACE_OBJFILES (pspace, objfile)
678 {
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);
684 }
685 fprintf_filtered (outfile, "\n\n");
686 do_cleanups (cleanups);
687 }
688
689 static void
690 maintenance_print_objfiles (char *regexp, int from_tty)
691 {
692 struct program_space *pspace;
693 struct objfile *objfile;
694
695 dont_repeat ();
696
697 if (regexp)
698 re_comp (regexp);
699
700 ALL_PSPACES (pspace)
701 ALL_PSPACE_OBJFILES (pspace, objfile)
702 {
703 QUIT;
704 if (! regexp
705 || re_exec (objfile->name))
706 dump_objfile (objfile);
707 }
708 }
709
710 /* List all the symbol tables whose names match REGEXP (optional). */
711
712 static void
713 maintenance_info_symtabs (char *regexp, int from_tty)
714 {
715 struct program_space *pspace;
716 struct objfile *objfile;
717
718 dont_repeat ();
719
720 if (regexp)
721 re_comp (regexp);
722
723 ALL_PSPACES (pspace)
724 ALL_PSPACE_OBJFILES (pspace, objfile)
725 {
726 struct symtab *symtab;
727
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;
731
732 ALL_OBJFILE_SYMTABS (objfile, symtab)
733 {
734 QUIT;
735
736 if (! regexp
737 || re_exec (symtab_to_filename_for_display (symtab)))
738 {
739 if (! printed_objfile_start)
740 {
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;
746 }
747
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");
767 }
768 }
769
770 if (printed_objfile_start)
771 printf_filtered ("}\n");
772 }
773 }
774
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.
779
780 Note: This does not check for psymtab vs symtab consistency.
781 Use "maint check-psymtabs" for that. */
782
783 static void
784 maintenance_check_symtabs (char *ignore, int from_tty)
785 {
786 struct program_space *pspace;
787 struct objfile *objfile;
788
789 ALL_PSPACES (pspace)
790 ALL_PSPACE_OBJFILES (pspace, objfile)
791 {
792 struct symtab *symtab;
793
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;
797
798 ALL_OBJFILE_SYMTABS (objfile, symtab)
799 {
800 int found_something = 0;
801
802 QUIT;
803
804 if (symtab->blockvector == NULL)
805 found_something = 1;
806 /* Add more checks here. */
807
808 if (found_something)
809 {
810 if (! printed_objfile_start)
811 {
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;
817 }
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");
823 }
824 }
825
826 if (printed_objfile_start)
827 printf_filtered ("}\n");
828 }
829 }
830
831 /* Helper function for maintenance_expand_symtabs.
832 This is the name_matcher function for expand_symtabs_matching. */
833
834 static int
835 maintenance_expand_name_matcher (const char *symname, void *data)
836 {
837 /* Since we're not searching on symbols, just return TRUE. */
838 return 1;
839 }
840
841 /* Helper function for maintenance_expand_symtabs.
842 This is the file_matcher function for expand_symtabs_matching. */
843
844 static int
845 maintenance_expand_file_matcher (const char *filename, void *data,
846 int basenames)
847 {
848 const char *regexp = data;
849
850 QUIT;
851
852 /* KISS: Only apply the regexp to the complete file name. */
853 if (basenames)
854 return 0;
855
856 if (regexp == NULL || re_exec (filename))
857 return 1;
858
859 return 0;
860 }
861
862 /* Expand all symbol tables whose name matches an optional regexp. */
863
864 static void
865 maintenance_expand_symtabs (char *args, int from_tty)
866 {
867 struct program_space *pspace;
868 struct objfile *objfile;
869 struct cleanup *cleanups;
870 char **argv;
871 char *regexp = NULL;
872
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);
877
878 if (argv != NULL)
879 {
880 if (argv[0] != NULL)
881 {
882 regexp = argv[0];
883 if (argv[1] != NULL)
884 error (_("Extra arguments after regexp."));
885 }
886 }
887
888 if (regexp)
889 re_comp (regexp);
890
891 ALL_PSPACES (pspace)
892 ALL_PSPACE_OBJFILES (pspace, objfile)
893 {
894 if (objfile->sf)
895 {
896 objfile->sf->qf->expand_symtabs_matching
897 (objfile, maintenance_expand_file_matcher,
898 maintenance_expand_name_matcher, ALL_DOMAIN, regexp);
899 }
900 }
901
902 do_cleanups (cleanups);
903 }
904 \f
905
906 /* Return the nexting depth of a block within other blocks in its symtab. */
907
908 static int
909 block_depth (struct block *block)
910 {
911 int i = 0;
912
913 while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
914 {
915 i++;
916 }
917 return i;
918 }
919 \f
920
921 /* Do early runtime initializations. */
922
923 void
924 _initialize_symmisc (void)
925 {
926 std_in = stdin;
927 std_out = stdout;
928 std_err = stderr;
929
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);
935
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);
941
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);
946
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);
953
954 add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs,
955 _("\
956 Check consistency of currently expanded symtabs."),
957 &maintenancelist);
958
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);
963 }
This page took 0.098301 seconds and 4 git commands to generate.