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