gdb/
[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 void dump_symtab (struct objfile *, struct symtab *,
63 struct ui_file *);
64
65 static void dump_msymbols (struct objfile *, struct ui_file *);
66
67 static void dump_objfile (struct objfile *);
68
69 static int block_depth (struct block *);
70
71 void _initialize_symmisc (void);
72
73 struct print_symbol_args
74 {
75 struct gdbarch *gdbarch;
76 struct symbol *symbol;
77 int depth;
78 struct ui_file *outfile;
79 };
80
81 static int print_symbol (void *);
82 \f
83
84 void
85 print_symbol_bcache_statistics (void)
86 {
87 struct program_space *pspace;
88 struct objfile *objfile;
89
90 ALL_PSPACES (pspace)
91 ALL_PSPACE_OBJFILES (pspace, objfile)
92 {
93 QUIT;
94 printf_filtered (_("Byte cache statistics for '%s':\n"), objfile->name);
95 print_bcache_statistics (psymbol_bcache_get_bcache (objfile->psymbol_cache),
96 "partial symbol cache");
97 print_bcache_statistics (objfile->per_bfd->macro_cache,
98 "preprocessor macro cache");
99 print_bcache_statistics (objfile->per_bfd->filename_cache,
100 "file name cache");
101 }
102 }
103
104 void
105 print_objfile_statistics (void)
106 {
107 struct program_space *pspace;
108 struct objfile *objfile;
109 struct symtab *s;
110 int i, linetables, blockvectors;
111
112 ALL_PSPACES (pspace)
113 ALL_PSPACE_OBJFILES (pspace, objfile)
114 {
115 QUIT;
116 printf_filtered (_("Statistics for '%s':\n"), objfile->name);
117 if (OBJSTAT (objfile, n_stabs) > 0)
118 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
119 OBJSTAT (objfile, n_stabs));
120 if (OBJSTAT (objfile, n_minsyms) > 0)
121 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
122 OBJSTAT (objfile, n_minsyms));
123 if (OBJSTAT (objfile, n_psyms) > 0)
124 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
125 OBJSTAT (objfile, n_psyms));
126 if (OBJSTAT (objfile, n_syms) > 0)
127 printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
128 OBJSTAT (objfile, n_syms));
129 if (OBJSTAT (objfile, n_types) > 0)
130 printf_filtered (_(" Number of \"types\" defined: %d\n"),
131 OBJSTAT (objfile, n_types));
132 if (objfile->sf)
133 objfile->sf->qf->print_stats (objfile);
134 i = linetables = blockvectors = 0;
135 ALL_OBJFILE_SYMTABS (objfile, s)
136 {
137 i++;
138 if (s->linetable != NULL)
139 linetables++;
140 if (s->primary == 1)
141 blockvectors++;
142 }
143 printf_filtered (_(" Number of symbol tables: %d\n"), i);
144 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
145 linetables);
146 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
147 blockvectors);
148
149 if (OBJSTAT (objfile, sz_strtab) > 0)
150 printf_filtered (_(" Space used by a.out string tables: %d\n"),
151 OBJSTAT (objfile, sz_strtab));
152 printf_filtered (_(" Total memory used for objfile obstack: %d\n"),
153 obstack_memory_used (&objfile->objfile_obstack));
154 printf_filtered (_(" Total memory used for BFD obstack: %d\n"),
155 obstack_memory_used (&objfile->per_bfd->storage_obstack));
156 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
157 bcache_memory_used (psymbol_bcache_get_bcache
158 (objfile->psymbol_cache)));
159 printf_filtered (_(" Total memory used for macro cache: %d\n"),
160 bcache_memory_used (objfile->per_bfd->macro_cache));
161 printf_filtered (_(" Total memory used for file name cache: %d\n"),
162 bcache_memory_used (objfile->per_bfd->filename_cache));
163 }
164 }
165
166 static void
167 dump_objfile (struct objfile *objfile)
168 {
169 struct symtab *symtab;
170
171 printf_filtered ("\nObject file %s: ", objfile->name);
172 printf_filtered ("Objfile at ");
173 gdb_print_host_address (objfile, gdb_stdout);
174 printf_filtered (", bfd at ");
175 gdb_print_host_address (objfile->obfd, gdb_stdout);
176 printf_filtered (", %d minsyms\n\n",
177 objfile->minimal_symbol_count);
178
179 if (objfile->sf)
180 objfile->sf->qf->dump (objfile);
181
182 if (objfile->symtabs)
183 {
184 printf_filtered ("Symtabs:\n");
185 for (symtab = objfile->symtabs;
186 symtab != NULL;
187 symtab = symtab->next)
188 {
189 printf_filtered ("%s at ", symtab_to_filename_for_display (symtab));
190 gdb_print_host_address (symtab, gdb_stdout);
191 printf_filtered (", ");
192 if (symtab->objfile != objfile)
193 {
194 printf_filtered ("NOT ON CHAIN! ");
195 }
196 wrap_here (" ");
197 }
198 printf_filtered ("\n\n");
199 }
200 }
201
202 /* Print minimal symbols from this objfile. */
203
204 static void
205 dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
206 {
207 struct gdbarch *gdbarch = get_objfile_arch (objfile);
208 struct minimal_symbol *msymbol;
209 int index;
210 char ms_type;
211
212 fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile->name);
213 if (objfile->minimal_symbol_count == 0)
214 {
215 fprintf_filtered (outfile, "No minimal symbols found.\n");
216 return;
217 }
218 index = 0;
219 ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
220 {
221 struct obj_section *section = SYMBOL_OBJ_SECTION (msymbol);
222
223 switch (MSYMBOL_TYPE (msymbol))
224 {
225 case mst_unknown:
226 ms_type = 'u';
227 break;
228 case mst_text:
229 ms_type = 'T';
230 break;
231 case mst_text_gnu_ifunc:
232 ms_type = 'i';
233 break;
234 case mst_solib_trampoline:
235 ms_type = 'S';
236 break;
237 case mst_data:
238 ms_type = 'D';
239 break;
240 case mst_bss:
241 ms_type = 'B';
242 break;
243 case mst_abs:
244 ms_type = 'A';
245 break;
246 case mst_file_text:
247 ms_type = 't';
248 break;
249 case mst_file_data:
250 ms_type = 'd';
251 break;
252 case mst_file_bss:
253 ms_type = 'b';
254 break;
255 default:
256 ms_type = '?';
257 break;
258 }
259 fprintf_filtered (outfile, "[%2d] %c ", index, ms_type);
260 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (msymbol)),
261 outfile);
262 fprintf_filtered (outfile, " %s", SYMBOL_LINKAGE_NAME (msymbol));
263 if (section)
264 fprintf_filtered (outfile, " section %s",
265 bfd_section_name (objfile->obfd,
266 section->the_bfd_section));
267 if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
268 {
269 fprintf_filtered (outfile, " %s", SYMBOL_DEMANGLED_NAME (msymbol));
270 }
271 if (msymbol->filename)
272 fprintf_filtered (outfile, " %s", msymbol->filename);
273 fputs_filtered ("\n", outfile);
274 index++;
275 }
276 if (objfile->minimal_symbol_count != index)
277 {
278 warning (_("internal error: minimal symbol count %d != %d"),
279 objfile->minimal_symbol_count, index);
280 }
281 fprintf_filtered (outfile, "\n");
282 }
283
284 static void
285 dump_symtab_1 (struct objfile *objfile, struct symtab *symtab,
286 struct ui_file *outfile)
287 {
288 struct gdbarch *gdbarch = get_objfile_arch (objfile);
289 int i;
290 struct dict_iterator iter;
291 int len;
292 struct linetable *l;
293 struct blockvector *bv;
294 struct symbol *sym;
295 struct block *b;
296 int depth;
297
298 fprintf_filtered (outfile, "\nSymtab for file %s\n",
299 symtab_to_filename_for_display (symtab));
300 if (symtab->dirname)
301 fprintf_filtered (outfile, "Compilation directory is %s\n",
302 symtab->dirname);
303 fprintf_filtered (outfile, "Read from object file %s (", objfile->name);
304 gdb_print_host_address (objfile, outfile);
305 fprintf_filtered (outfile, ")\n");
306 fprintf_filtered (outfile, "Language: %s\n",
307 language_str (symtab->language));
308
309 /* First print the line table. */
310 l = LINETABLE (symtab);
311 if (l)
312 {
313 fprintf_filtered (outfile, "\nLine table:\n\n");
314 len = l->nitems;
315 for (i = 0; i < len; i++)
316 {
317 fprintf_filtered (outfile, " line %d at ", l->item[i].line);
318 fputs_filtered (paddress (gdbarch, l->item[i].pc), outfile);
319 fprintf_filtered (outfile, "\n");
320 }
321 }
322 /* Now print the block info, but only for primary symtabs since we will
323 print lots of duplicate info otherwise. */
324 if (symtab->primary)
325 {
326 fprintf_filtered (outfile, "\nBlockvector:\n\n");
327 bv = BLOCKVECTOR (symtab);
328 len = BLOCKVECTOR_NBLOCKS (bv);
329 for (i = 0; i < len; i++)
330 {
331 b = BLOCKVECTOR_BLOCK (bv, i);
332 depth = block_depth (b) * 2;
333 print_spaces (depth, outfile);
334 fprintf_filtered (outfile, "block #%03d, object at ", i);
335 gdb_print_host_address (b, outfile);
336 if (BLOCK_SUPERBLOCK (b))
337 {
338 fprintf_filtered (outfile, " under ");
339 gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile);
340 }
341 /* drow/2002-07-10: We could save the total symbols count
342 even if we're using a hashtable, but nothing else but this message
343 wants it. */
344 fprintf_filtered (outfile, ", %d syms/buckets in ",
345 dict_size (BLOCK_DICT (b)));
346 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), outfile);
347 fprintf_filtered (outfile, "..");
348 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), outfile);
349 if (BLOCK_FUNCTION (b))
350 {
351 fprintf_filtered (outfile, ", function %s",
352 SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b)));
353 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
354 {
355 fprintf_filtered (outfile, ", %s",
356 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
357 }
358 }
359 fprintf_filtered (outfile, "\n");
360 /* Now print each symbol in this block (in no particular order, if
361 we're using a hashtable). Note that we only want this
362 block, not any blocks from included symtabs. */
363 ALL_DICT_SYMBOLS (BLOCK_DICT (b), iter, sym)
364 {
365 struct print_symbol_args s;
366
367 s.gdbarch = gdbarch;
368 s.symbol = sym;
369 s.depth = depth + 1;
370 s.outfile = outfile;
371 catch_errors (print_symbol, &s, "Error printing symbol:\n",
372 RETURN_MASK_ERROR);
373 }
374 }
375 fprintf_filtered (outfile, "\n");
376 }
377 else
378 {
379 fprintf_filtered (outfile, "\nBlockvector same as previous symtab\n\n");
380 }
381 }
382
383 static void
384 dump_symtab (struct objfile *objfile, struct symtab *symtab,
385 struct ui_file *outfile)
386 {
387 /* Set the current language to the language of the symtab we're dumping
388 because certain routines used during dump_symtab() use the current
389 language to print an image of the symbol. We'll restore it later.
390 But use only real languages, not placeholders. */
391 if (symtab->language != language_unknown
392 && symtab->language != language_auto)
393 {
394 enum language saved_lang;
395
396 saved_lang = set_language (symtab->language);
397
398 dump_symtab_1 (objfile, symtab, outfile);
399
400 set_language (saved_lang);
401 }
402 else
403 dump_symtab_1 (objfile, symtab, outfile);
404 }
405
406 static void
407 maintenance_print_symbols (char *args, int from_tty)
408 {
409 char **argv;
410 struct ui_file *outfile;
411 struct cleanup *cleanups;
412 char *symname = NULL;
413 char *filename = DEV_TTY;
414 struct objfile *objfile;
415 struct symtab *s;
416
417 dont_repeat ();
418
419 if (args == NULL)
420 {
421 error (_("Arguments missing: an output file name "
422 "and an optional symbol file name"));
423 }
424 argv = gdb_buildargv (args);
425 cleanups = make_cleanup_freeargv (argv);
426
427 if (argv[0] != NULL)
428 {
429 filename = argv[0];
430 /* If a second arg is supplied, it is a source file name to match on. */
431 if (argv[1] != NULL)
432 {
433 symname = argv[1];
434 }
435 }
436
437 filename = tilde_expand (filename);
438 make_cleanup (xfree, filename);
439
440 outfile = gdb_fopen (filename, FOPEN_WT);
441 if (outfile == 0)
442 perror_with_name (filename);
443 make_cleanup_ui_file_delete (outfile);
444
445 ALL_SYMTABS (objfile, s)
446 {
447 QUIT;
448 if (symname == NULL
449 || filename_cmp (symname, symtab_to_filename_for_display (s)) == 0)
450 dump_symtab (objfile, s, outfile);
451 }
452 do_cleanups (cleanups);
453 }
454
455 /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
456 far to indent. ARGS is really a struct print_symbol_args *, but is
457 declared as char * to get it past catch_errors. Returns 0 for error,
458 1 for success. */
459
460 static int
461 print_symbol (void *args)
462 {
463 struct gdbarch *gdbarch = ((struct print_symbol_args *) args)->gdbarch;
464 struct symbol *symbol = ((struct print_symbol_args *) args)->symbol;
465 int depth = ((struct print_symbol_args *) args)->depth;
466 struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile;
467 struct obj_section *section = SYMBOL_OBJ_SECTION (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 *ignore, int from_tty)
691 {
692 struct program_space *pspace;
693 struct objfile *objfile;
694
695 dont_repeat ();
696
697 ALL_PSPACES (pspace)
698 ALL_PSPACE_OBJFILES (pspace, objfile)
699 {
700 QUIT;
701 dump_objfile (objfile);
702 }
703 }
704
705 /* List all the symbol tables whose names match REGEXP (optional). */
706
707 static void
708 maintenance_info_symtabs (char *regexp, int from_tty)
709 {
710 struct program_space *pspace;
711 struct objfile *objfile;
712
713 if (regexp)
714 re_comp (regexp);
715
716 ALL_PSPACES (pspace)
717 ALL_PSPACE_OBJFILES (pspace, objfile)
718 {
719 struct symtab *symtab;
720
721 /* We don't want to print anything for this objfile until we
722 actually find a symtab whose name matches. */
723 int printed_objfile_start = 0;
724
725 ALL_OBJFILE_SYMTABS (objfile, symtab)
726 {
727 QUIT;
728
729 if (! regexp
730 || re_exec (symtab_to_filename_for_display (symtab)))
731 {
732 if (! printed_objfile_start)
733 {
734 printf_filtered ("{ objfile %s ", objfile->name);
735 wrap_here (" ");
736 printf_filtered ("((struct objfile *) %s)\n",
737 host_address_to_string (objfile));
738 printed_objfile_start = 1;
739 }
740
741 printf_filtered (" { symtab %s ",
742 symtab_to_filename_for_display (symtab));
743 wrap_here (" ");
744 printf_filtered ("((struct symtab *) %s)\n",
745 host_address_to_string (symtab));
746 printf_filtered (" dirname %s\n",
747 symtab->dirname ? symtab->dirname : "(null)");
748 printf_filtered (" fullname %s\n",
749 symtab->fullname ? symtab->fullname : "(null)");
750 printf_filtered (" "
751 "blockvector ((struct blockvector *) %s)%s\n",
752 host_address_to_string (symtab->blockvector),
753 symtab->primary ? " (primary)" : "");
754 printf_filtered (" "
755 "linetable ((struct linetable *) %s)\n",
756 host_address_to_string (symtab->linetable));
757 printf_filtered (" debugformat %s\n",
758 symtab->debugformat);
759 printf_filtered (" }\n");
760 }
761 }
762
763 if (printed_objfile_start)
764 printf_filtered ("}\n");
765 }
766 }
767 \f
768
769 /* Return the nexting depth of a block within other blocks in its symtab. */
770
771 static int
772 block_depth (struct block *block)
773 {
774 int i = 0;
775
776 while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
777 {
778 i++;
779 }
780 return i;
781 }
782 \f
783
784 /* Do early runtime initializations. */
785
786 void
787 _initialize_symmisc (void)
788 {
789 std_in = stdin;
790 std_out = stdout;
791 std_err = stderr;
792
793 add_cmd ("symbols", class_maintenance, maintenance_print_symbols, _("\
794 Print dump of current symbol definitions.\n\
795 Entries in the full symbol table are dumped to file OUTFILE.\n\
796 If a SOURCE file is specified, dump only that file's symbols."),
797 &maintenanceprintlist);
798
799 add_cmd ("msymbols", class_maintenance, maintenance_print_msymbols, _("\
800 Print dump of current minimal symbol definitions.\n\
801 Entries in the minimal symbol table are dumped to file OUTFILE.\n\
802 If a SOURCE file is specified, dump only that file's minimal symbols."),
803 &maintenanceprintlist);
804
805 add_cmd ("objfiles", class_maintenance, maintenance_print_objfiles,
806 _("Print dump of current object file definitions."),
807 &maintenanceprintlist);
808
809 add_cmd ("symtabs", class_maintenance, maintenance_info_symtabs, _("\
810 List the full symbol tables for all object files.\n\
811 This does not include information about individual symbols, blocks, or\n\
812 linetables --- just the symbol table structures themselves.\n\
813 With an argument REGEXP, list the symbol tables whose names that match that."),
814 &maintenanceinfolist);
815 }
This page took 0.045549 seconds and 5 git commands to generate.