* xcoffread.c (read_xcoff_symtab): Make `debugfmt' const.
[binutils-gdb.git] / gdb / symmisc.c
1 /* Do various things to symbol tables (other than lookup), for GDB.
2
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2007, 2008, 2009, 2010,
5 2011 Free Software Foundation, Inc.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22 #include "defs.h"
23 #include "symtab.h"
24 #include "gdbtypes.h"
25 #include "bfd.h"
26 #include "filenames.h"
27 #include "symfile.h"
28 #include "objfiles.h"
29 #include "breakpoint.h"
30 #include "command.h"
31 #include "gdb_obstack.h"
32 #include "exceptions.h"
33 #include "language.h"
34 #include "bcache.h"
35 #include "block.h"
36 #include "gdb_regex.h"
37 #include "gdb_stat.h"
38 #include "dictionary.h"
39
40 #include "gdb_string.h"
41 #include "readline/readline.h"
42
43 #include "psymtab.h"
44
45 #ifndef DEV_TTY
46 #define DEV_TTY "/dev/tty"
47 #endif
48
49 /* Unfortunately for debugging, stderr is usually a macro. This is painful
50 when calling functions that take FILE *'s from the debugger.
51 So we make a variable which has the same value and which is accessible when
52 debugging GDB with itself. Because stdin et al need not be constants,
53 we initialize them in the _initialize_symmisc function at the bottom
54 of the file. */
55 FILE *std_in;
56 FILE *std_out;
57 FILE *std_err;
58
59 /* Prototypes for local functions */
60
61 static void dump_symtab (struct objfile *, struct symtab *,
62 struct ui_file *);
63
64 static void dump_msymbols (struct objfile *, struct ui_file *);
65
66 static void dump_objfile (struct objfile *);
67
68 static int block_depth (struct block *);
69
70 void _initialize_symmisc (void);
71
72 struct print_symbol_args
73 {
74 struct gdbarch *gdbarch;
75 struct symbol *symbol;
76 int depth;
77 struct ui_file *outfile;
78 };
79
80 static int print_symbol (void *);
81 \f
82 /* Free all the storage associated with the struct symtab <- S.
83 Note that some symtabs have contents that all live inside one big block of
84 memory, and some share the contents of another symbol table and so you
85 should not free the contents on their behalf (except sometimes the
86 linetable, which maybe per symtab even when the rest is not).
87 It is s->free_code that says which alternative to use. */
88
89 void
90 free_symtab (struct symtab *s)
91 {
92 switch (s->free_code)
93 {
94 case free_nothing:
95 /* All the contents are part of a big block of memory (an obstack),
96 and some other symtab is in charge of freeing that block.
97 Therefore, do nothing. */
98 break;
99
100 case free_linetable:
101 /* Everything will be freed either by our `free_func'
102 or by some other symtab, except for our linetable.
103 Free that now. */
104 if (LINETABLE (s))
105 xfree (LINETABLE (s));
106 break;
107 }
108
109 /* If there is a single block of memory to free, free it. */
110 if (s->free_func != NULL)
111 s->free_func (s);
112
113 /* Free source-related stuff. */
114 if (s->line_charpos != NULL)
115 xfree (s->line_charpos);
116 if (s->fullname != NULL)
117 xfree (s->fullname);
118 xfree (s);
119 }
120
121 void
122 print_symbol_bcache_statistics (void)
123 {
124 struct program_space *pspace;
125 struct objfile *objfile;
126
127 immediate_quit++;
128 ALL_PSPACES (pspace)
129 ALL_PSPACE_OBJFILES (pspace, objfile)
130 {
131 printf_filtered (_("Byte cache statistics for '%s':\n"), objfile->name);
132 print_bcache_statistics (psymbol_bcache_get_bcache (objfile->psymbol_cache),
133 "partial symbol cache");
134 print_bcache_statistics (objfile->macro_cache, "preprocessor macro cache");
135 print_bcache_statistics (objfile->filename_cache, "file name cache");
136 }
137 immediate_quit--;
138 }
139
140 void
141 print_objfile_statistics (void)
142 {
143 struct program_space *pspace;
144 struct objfile *objfile;
145 struct symtab *s;
146 int i, linetables, blockvectors;
147
148 immediate_quit++;
149 ALL_PSPACES (pspace)
150 ALL_PSPACE_OBJFILES (pspace, objfile)
151 {
152 printf_filtered (_("Statistics for '%s':\n"), objfile->name);
153 if (OBJSTAT (objfile, n_stabs) > 0)
154 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
155 OBJSTAT (objfile, n_stabs));
156 if (OBJSTAT (objfile, n_minsyms) > 0)
157 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
158 OBJSTAT (objfile, n_minsyms));
159 if (OBJSTAT (objfile, n_psyms) > 0)
160 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
161 OBJSTAT (objfile, n_psyms));
162 if (OBJSTAT (objfile, n_syms) > 0)
163 printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
164 OBJSTAT (objfile, n_syms));
165 if (OBJSTAT (objfile, n_types) > 0)
166 printf_filtered (_(" Number of \"types\" defined: %d\n"),
167 OBJSTAT (objfile, n_types));
168 if (objfile->sf)
169 objfile->sf->qf->print_stats (objfile);
170 i = linetables = blockvectors = 0;
171 ALL_OBJFILE_SYMTABS (objfile, s)
172 {
173 i++;
174 if (s->linetable != NULL)
175 linetables++;
176 if (s->primary == 1)
177 blockvectors++;
178 }
179 printf_filtered (_(" Number of symbol tables: %d\n"), i);
180 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
181 linetables);
182 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
183 blockvectors);
184
185 if (OBJSTAT (objfile, sz_strtab) > 0)
186 printf_filtered (_(" Space used by a.out string tables: %d\n"),
187 OBJSTAT (objfile, sz_strtab));
188 printf_filtered (_(" Total memory used for objfile obstack: %d\n"),
189 obstack_memory_used (&objfile->objfile_obstack));
190 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
191 bcache_memory_used (psymbol_bcache_get_bcache
192 (objfile->psymbol_cache)));
193 printf_filtered (_(" Total memory used for macro cache: %d\n"),
194 bcache_memory_used (objfile->macro_cache));
195 printf_filtered (_(" Total memory used for file name cache: %d\n"),
196 bcache_memory_used (objfile->filename_cache));
197 }
198 immediate_quit--;
199 }
200
201 static void
202 dump_objfile (struct objfile *objfile)
203 {
204 struct symtab *symtab;
205
206 printf_filtered ("\nObject file %s: ", objfile->name);
207 printf_filtered ("Objfile at ");
208 gdb_print_host_address (objfile, gdb_stdout);
209 printf_filtered (", bfd at ");
210 gdb_print_host_address (objfile->obfd, gdb_stdout);
211 printf_filtered (", %d minsyms\n\n",
212 objfile->minimal_symbol_count);
213
214 if (objfile->sf)
215 objfile->sf->qf->dump (objfile);
216
217 if (objfile->symtabs)
218 {
219 printf_filtered ("Symtabs:\n");
220 for (symtab = objfile->symtabs;
221 symtab != NULL;
222 symtab = symtab->next)
223 {
224 printf_filtered ("%s at ", symtab->filename);
225 gdb_print_host_address (symtab, gdb_stdout);
226 printf_filtered (", ");
227 if (symtab->objfile != objfile)
228 {
229 printf_filtered ("NOT ON CHAIN! ");
230 }
231 wrap_here (" ");
232 }
233 printf_filtered ("\n\n");
234 }
235 }
236
237 /* Print minimal symbols from this objfile. */
238
239 static void
240 dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
241 {
242 struct gdbarch *gdbarch = get_objfile_arch (objfile);
243 struct minimal_symbol *msymbol;
244 int index;
245 char ms_type;
246
247 fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile->name);
248 if (objfile->minimal_symbol_count == 0)
249 {
250 fprintf_filtered (outfile, "No minimal symbols found.\n");
251 return;
252 }
253 index = 0;
254 ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
255 {
256 struct obj_section *section = SYMBOL_OBJ_SECTION (msymbol);
257
258 switch (MSYMBOL_TYPE (msymbol))
259 {
260 case mst_unknown:
261 ms_type = 'u';
262 break;
263 case mst_text:
264 ms_type = 'T';
265 break;
266 case mst_text_gnu_ifunc:
267 ms_type = 'i';
268 break;
269 case mst_solib_trampoline:
270 ms_type = 'S';
271 break;
272 case mst_data:
273 ms_type = 'D';
274 break;
275 case mst_bss:
276 ms_type = 'B';
277 break;
278 case mst_abs:
279 ms_type = 'A';
280 break;
281 case mst_file_text:
282 ms_type = 't';
283 break;
284 case mst_file_data:
285 ms_type = 'd';
286 break;
287 case mst_file_bss:
288 ms_type = 'b';
289 break;
290 default:
291 ms_type = '?';
292 break;
293 }
294 fprintf_filtered (outfile, "[%2d] %c ", index, ms_type);
295 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (msymbol)),
296 outfile);
297 fprintf_filtered (outfile, " %s", SYMBOL_LINKAGE_NAME (msymbol));
298 if (section)
299 fprintf_filtered (outfile, " section %s",
300 bfd_section_name (objfile->obfd,
301 section->the_bfd_section));
302 if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
303 {
304 fprintf_filtered (outfile, " %s", SYMBOL_DEMANGLED_NAME (msymbol));
305 }
306 if (msymbol->filename)
307 fprintf_filtered (outfile, " %s", msymbol->filename);
308 fputs_filtered ("\n", outfile);
309 index++;
310 }
311 if (objfile->minimal_symbol_count != index)
312 {
313 warning (_("internal error: minimal symbol count %d != %d"),
314 objfile->minimal_symbol_count, index);
315 }
316 fprintf_filtered (outfile, "\n");
317 }
318
319 static void
320 dump_symtab_1 (struct objfile *objfile, struct symtab *symtab,
321 struct ui_file *outfile)
322 {
323 struct gdbarch *gdbarch = get_objfile_arch (objfile);
324 int i;
325 struct dict_iterator iter;
326 int len;
327 struct linetable *l;
328 struct blockvector *bv;
329 struct symbol *sym;
330 struct block *b;
331 int depth;
332
333 fprintf_filtered (outfile, "\nSymtab for file %s\n", symtab->filename);
334 if (symtab->dirname)
335 fprintf_filtered (outfile, "Compilation directory is %s\n",
336 symtab->dirname);
337 fprintf_filtered (outfile, "Read from object file %s (", objfile->name);
338 gdb_print_host_address (objfile, outfile);
339 fprintf_filtered (outfile, ")\n");
340 fprintf_filtered (outfile, "Language: %s\n",
341 language_str (symtab->language));
342
343 /* First print the line table. */
344 l = LINETABLE (symtab);
345 if (l)
346 {
347 fprintf_filtered (outfile, "\nLine table:\n\n");
348 len = l->nitems;
349 for (i = 0; i < len; i++)
350 {
351 fprintf_filtered (outfile, " line %d at ", l->item[i].line);
352 fputs_filtered (paddress (gdbarch, l->item[i].pc), outfile);
353 fprintf_filtered (outfile, "\n");
354 }
355 }
356 /* Now print the block info, but only for primary symtabs since we will
357 print lots of duplicate info otherwise. */
358 if (symtab->primary)
359 {
360 fprintf_filtered (outfile, "\nBlockvector:\n\n");
361 bv = BLOCKVECTOR (symtab);
362 len = BLOCKVECTOR_NBLOCKS (bv);
363 for (i = 0; i < len; i++)
364 {
365 b = BLOCKVECTOR_BLOCK (bv, i);
366 depth = block_depth (b) * 2;
367 print_spaces (depth, outfile);
368 fprintf_filtered (outfile, "block #%03d, object at ", i);
369 gdb_print_host_address (b, outfile);
370 if (BLOCK_SUPERBLOCK (b))
371 {
372 fprintf_filtered (outfile, " under ");
373 gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile);
374 }
375 /* drow/2002-07-10: We could save the total symbols count
376 even if we're using a hashtable, but nothing else but this message
377 wants it. */
378 fprintf_filtered (outfile, ", %d syms/buckets in ",
379 dict_size (BLOCK_DICT (b)));
380 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), outfile);
381 fprintf_filtered (outfile, "..");
382 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), outfile);
383 if (BLOCK_FUNCTION (b))
384 {
385 fprintf_filtered (outfile, ", function %s",
386 SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b)));
387 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
388 {
389 fprintf_filtered (outfile, ", %s",
390 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
391 }
392 }
393 fprintf_filtered (outfile, "\n");
394 /* Now print each symbol in this block (in no particular order, if
395 we're using a hashtable). */
396 ALL_BLOCK_SYMBOLS (b, iter, sym)
397 {
398 struct print_symbol_args s;
399
400 s.gdbarch = gdbarch;
401 s.symbol = sym;
402 s.depth = depth + 1;
403 s.outfile = outfile;
404 catch_errors (print_symbol, &s, "Error printing symbol:\n",
405 RETURN_MASK_ERROR);
406 }
407 }
408 fprintf_filtered (outfile, "\n");
409 }
410 else
411 {
412 fprintf_filtered (outfile, "\nBlockvector same as previous symtab\n\n");
413 }
414 }
415
416 static void
417 dump_symtab (struct objfile *objfile, struct symtab *symtab,
418 struct ui_file *outfile)
419 {
420 /* Set the current language to the language of the symtab we're dumping
421 because certain routines used during dump_symtab() use the current
422 language to print an image of the symbol. We'll restore it later.
423 But use only real languages, not placeholders. */
424 if (symtab->language != language_unknown
425 && symtab->language != language_auto)
426 {
427 enum language saved_lang;
428
429 saved_lang = set_language (symtab->language);
430
431 dump_symtab_1 (objfile, symtab, outfile);
432
433 set_language (saved_lang);
434 }
435 else
436 dump_symtab_1 (objfile, symtab, outfile);
437 }
438
439 void
440 maintenance_print_symbols (char *args, int from_tty)
441 {
442 char **argv;
443 struct ui_file *outfile;
444 struct cleanup *cleanups;
445 char *symname = NULL;
446 char *filename = DEV_TTY;
447 struct objfile *objfile;
448 struct symtab *s;
449
450 dont_repeat ();
451
452 if (args == NULL)
453 {
454 error (_("Arguments missing: an output file name "
455 "and an optional symbol file name"));
456 }
457 argv = gdb_buildargv (args);
458 cleanups = make_cleanup_freeargv (argv);
459
460 if (argv[0] != NULL)
461 {
462 filename = argv[0];
463 /* If a second arg is supplied, it is a source file name to match on. */
464 if (argv[1] != NULL)
465 {
466 symname = argv[1];
467 }
468 }
469
470 filename = tilde_expand (filename);
471 make_cleanup (xfree, filename);
472
473 outfile = gdb_fopen (filename, FOPEN_WT);
474 if (outfile == 0)
475 perror_with_name (filename);
476 make_cleanup_ui_file_delete (outfile);
477
478 immediate_quit++;
479 ALL_SYMTABS (objfile, s)
480 if (symname == NULL || filename_cmp (symname, s->filename) == 0)
481 dump_symtab (objfile, s, outfile);
482 immediate_quit--;
483 do_cleanups (cleanups);
484 }
485
486 /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
487 far to indent. ARGS is really a struct print_symbol_args *, but is
488 declared as char * to get it past catch_errors. Returns 0 for error,
489 1 for success. */
490
491 static int
492 print_symbol (void *args)
493 {
494 struct gdbarch *gdbarch = ((struct print_symbol_args *) args)->gdbarch;
495 struct symbol *symbol = ((struct print_symbol_args *) args)->symbol;
496 int depth = ((struct print_symbol_args *) args)->depth;
497 struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile;
498 struct obj_section *section = SYMBOL_OBJ_SECTION (symbol);
499
500 print_spaces (depth, outfile);
501 if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN)
502 {
503 fprintf_filtered (outfile, "label %s at ", SYMBOL_PRINT_NAME (symbol));
504 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
505 outfile);
506 if (section)
507 fprintf_filtered (outfile, " section %s\n",
508 bfd_section_name (section->the_bfd_section->owner,
509 section->the_bfd_section));
510 else
511 fprintf_filtered (outfile, "\n");
512 return 1;
513 }
514 if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN)
515 {
516 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
517 {
518 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
519 }
520 else
521 {
522 fprintf_filtered (outfile, "%s %s = ",
523 (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
524 ? "enum"
525 : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
526 ? "struct" : "union")),
527 SYMBOL_LINKAGE_NAME (symbol));
528 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
529 }
530 fprintf_filtered (outfile, ";\n");
531 }
532 else
533 {
534 if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
535 fprintf_filtered (outfile, "typedef ");
536 if (SYMBOL_TYPE (symbol))
537 {
538 /* Print details of types, except for enums where it's clutter. */
539 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_PRINT_NAME (symbol),
540 outfile,
541 TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
542 depth);
543 fprintf_filtered (outfile, "; ");
544 }
545 else
546 fprintf_filtered (outfile, "%s ", SYMBOL_PRINT_NAME (symbol));
547
548 switch (SYMBOL_CLASS (symbol))
549 {
550 case LOC_CONST:
551 fprintf_filtered (outfile, "const %ld (0x%lx)",
552 SYMBOL_VALUE (symbol),
553 SYMBOL_VALUE (symbol));
554 break;
555
556 case LOC_CONST_BYTES:
557 {
558 unsigned i;
559 struct type *type = check_typedef (SYMBOL_TYPE (symbol));
560
561 fprintf_filtered (outfile, "const %u hex bytes:",
562 TYPE_LENGTH (type));
563 for (i = 0; i < TYPE_LENGTH (type); i++)
564 fprintf_filtered (outfile, " %02x",
565 (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]);
566 }
567 break;
568
569 case LOC_STATIC:
570 fprintf_filtered (outfile, "static at ");
571 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
572 outfile);
573 if (section)
574 fprintf_filtered (outfile, " section %s",
575 bfd_section_name (section->the_bfd_section->owner,
576 section->the_bfd_section));
577 break;
578
579 case LOC_REGISTER:
580 if (SYMBOL_IS_ARGUMENT (symbol))
581 fprintf_filtered (outfile, "parameter register %ld",
582 SYMBOL_VALUE (symbol));
583 else
584 fprintf_filtered (outfile, "register %ld", SYMBOL_VALUE (symbol));
585 break;
586
587 case LOC_ARG:
588 fprintf_filtered (outfile, "arg at offset 0x%lx",
589 SYMBOL_VALUE (symbol));
590 break;
591
592 case LOC_REF_ARG:
593 fprintf_filtered (outfile, "reference arg at 0x%lx", SYMBOL_VALUE (symbol));
594 break;
595
596 case LOC_REGPARM_ADDR:
597 fprintf_filtered (outfile, "address parameter register %ld", SYMBOL_VALUE (symbol));
598 break;
599
600 case LOC_LOCAL:
601 fprintf_filtered (outfile, "local at offset 0x%lx",
602 SYMBOL_VALUE (symbol));
603 break;
604
605 case LOC_TYPEDEF:
606 break;
607
608 case LOC_LABEL:
609 fprintf_filtered (outfile, "label at ");
610 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
611 outfile);
612 if (section)
613 fprintf_filtered (outfile, " section %s",
614 bfd_section_name (section->the_bfd_section->owner,
615 section->the_bfd_section));
616 break;
617
618 case LOC_BLOCK:
619 fprintf_filtered (outfile, "block object ");
620 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
621 fprintf_filtered (outfile, ", ");
622 fputs_filtered (paddress (gdbarch,
623 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol))),
624 outfile);
625 fprintf_filtered (outfile, "..");
626 fputs_filtered (paddress (gdbarch,
627 BLOCK_END (SYMBOL_BLOCK_VALUE (symbol))),
628 outfile);
629 if (section)
630 fprintf_filtered (outfile, " section %s",
631 bfd_section_name (section->the_bfd_section->owner,
632 section->the_bfd_section));
633 break;
634
635 case LOC_COMPUTED:
636 fprintf_filtered (outfile, "computed at runtime");
637 break;
638
639 case LOC_UNRESOLVED:
640 fprintf_filtered (outfile, "unresolved");
641 break;
642
643 case LOC_OPTIMIZED_OUT:
644 fprintf_filtered (outfile, "optimized out");
645 break;
646
647 default:
648 fprintf_filtered (outfile, "botched symbol class %x",
649 SYMBOL_CLASS (symbol));
650 break;
651 }
652 }
653 fprintf_filtered (outfile, "\n");
654 return 1;
655 }
656
657 void
658 maintenance_print_msymbols (char *args, int from_tty)
659 {
660 char **argv;
661 struct ui_file *outfile;
662 struct cleanup *cleanups;
663 char *filename = DEV_TTY;
664 char *symname = NULL;
665 struct program_space *pspace;
666 struct objfile *objfile;
667
668 struct stat sym_st, obj_st;
669
670 dont_repeat ();
671
672 if (args == NULL)
673 {
674 error (_("print-msymbols takes an output file "
675 "name and optional symbol file name"));
676 }
677 argv = gdb_buildargv (args);
678 cleanups = make_cleanup_freeargv (argv);
679
680 if (argv[0] != NULL)
681 {
682 filename = argv[0];
683 /* If a second arg is supplied, it is a source file name to match on. */
684 if (argv[1] != NULL)
685 {
686 symname = xfullpath (argv[1]);
687 make_cleanup (xfree, symname);
688 if (symname && stat (symname, &sym_st))
689 perror_with_name (symname);
690 }
691 }
692
693 filename = tilde_expand (filename);
694 make_cleanup (xfree, filename);
695
696 outfile = gdb_fopen (filename, FOPEN_WT);
697 if (outfile == 0)
698 perror_with_name (filename);
699 make_cleanup_ui_file_delete (outfile);
700
701 immediate_quit++;
702 ALL_PSPACES (pspace)
703 ALL_PSPACE_OBJFILES (pspace, objfile)
704 if (symname == NULL || (!stat (objfile->name, &obj_st)
705 && sym_st.st_ino == obj_st.st_ino))
706 dump_msymbols (objfile, outfile);
707 immediate_quit--;
708 fprintf_filtered (outfile, "\n\n");
709 do_cleanups (cleanups);
710 }
711
712 void
713 maintenance_print_objfiles (char *ignore, int from_tty)
714 {
715 struct program_space *pspace;
716 struct objfile *objfile;
717
718 dont_repeat ();
719
720 immediate_quit++;
721 ALL_PSPACES (pspace)
722 ALL_PSPACE_OBJFILES (pspace, objfile)
723 dump_objfile (objfile);
724 immediate_quit--;
725 }
726
727
728 /* List all the symbol tables whose names match REGEXP (optional). */
729 void
730 maintenance_info_symtabs (char *regexp, int from_tty)
731 {
732 struct program_space *pspace;
733 struct objfile *objfile;
734
735 if (regexp)
736 re_comp (regexp);
737
738 ALL_PSPACES (pspace)
739 ALL_PSPACE_OBJFILES (pspace, objfile)
740 {
741 struct symtab *symtab;
742
743 /* We don't want to print anything for this objfile until we
744 actually find a symtab whose name matches. */
745 int printed_objfile_start = 0;
746
747 ALL_OBJFILE_SYMTABS (objfile, symtab)
748 {
749 QUIT;
750
751 if (! regexp
752 || re_exec (symtab->filename))
753 {
754 if (! printed_objfile_start)
755 {
756 printf_filtered ("{ objfile %s ", objfile->name);
757 wrap_here (" ");
758 printf_filtered ("((struct objfile *) %s)\n",
759 host_address_to_string (objfile));
760 printed_objfile_start = 1;
761 }
762
763 printf_filtered (" { symtab %s ", symtab->filename);
764 wrap_here (" ");
765 printf_filtered ("((struct symtab *) %s)\n",
766 host_address_to_string (symtab));
767 printf_filtered (" dirname %s\n",
768 symtab->dirname ? symtab->dirname : "(null)");
769 printf_filtered (" fullname %s\n",
770 symtab->fullname ? symtab->fullname : "(null)");
771 printf_filtered (" "
772 "blockvector ((struct blockvector *) %s)%s\n",
773 host_address_to_string (symtab->blockvector),
774 symtab->primary ? " (primary)" : "");
775 printf_filtered (" "
776 "linetable ((struct linetable *) %s)\n",
777 host_address_to_string (symtab->linetable));
778 printf_filtered (" debugformat %s\n",
779 symtab->debugformat);
780 printf_filtered (" }\n");
781 }
782 }
783
784 if (printed_objfile_start)
785 printf_filtered ("}\n");
786 }
787 }
788 \f
789
790 /* Return the nexting depth of a block within other blocks in its symtab. */
791
792 static int
793 block_depth (struct block *block)
794 {
795 int i = 0;
796
797 while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
798 {
799 i++;
800 }
801 return i;
802 }
803 \f
804
805 /* Do early runtime initializations. */
806 void
807 _initialize_symmisc (void)
808 {
809 std_in = stdin;
810 std_out = stdout;
811 std_err = stderr;
812 }