gas/
[deliverable/binutils-gdb.git] / gdb / symmisc.c
... / ...
CommitLineData
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
5 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#ifndef DEV_TTY
43#define DEV_TTY "/dev/tty"
44#endif
45
46/* Unfortunately for debugging, stderr is usually a macro. This is painful
47 when calling functions that take FILE *'s from the debugger.
48 So we make a variable which has the same value and which is accessible when
49 debugging GDB with itself. Because stdin et al need not be constants,
50 we initialize them in the _initialize_symmisc function at the bottom
51 of the file. */
52FILE *std_in;
53FILE *std_out;
54FILE *std_err;
55
56/* Prototypes for local functions */
57
58static void dump_symtab (struct objfile *, struct symtab *,
59 struct ui_file *);
60
61static void dump_psymtab (struct objfile *, struct partial_symtab *,
62 struct ui_file *);
63
64static void dump_msymbols (struct objfile *, struct ui_file *);
65
66static void dump_objfile (struct objfile *);
67
68static int block_depth (struct block *);
69
70static void print_partial_symbols (struct partial_symbol **, int,
71 char *, struct ui_file *);
72
73void _initialize_symmisc (void);
74
75struct print_symbol_args
76 {
77 struct symbol *symbol;
78 int depth;
79 struct ui_file *outfile;
80 };
81
82static int print_symbol (void *);
83\f
84/* Free all the storage associated with the struct symtab <- S.
85 Note that some symtabs have contents that all live inside one big block of
86 memory, and some share the contents of another symbol table and so you
87 should not free the contents on their behalf (except sometimes the
88 linetable, which maybe per symtab even when the rest is not).
89 It is s->free_code that says which alternative to use. */
90
91void
92free_symtab (struct symtab *s)
93{
94 int i, n;
95 struct blockvector *bv;
96
97 switch (s->free_code)
98 {
99 case free_nothing:
100 /* All the contents are part of a big block of memory (an obstack),
101 and some other symtab is in charge of freeing that block.
102 Therefore, do nothing. */
103 break;
104
105 case free_linetable:
106 /* Everything will be freed either by our `free_func'
107 or by some other symtab, except for our linetable.
108 Free that now. */
109 if (LINETABLE (s))
110 xfree (LINETABLE (s));
111 break;
112 }
113
114 /* If there is a single block of memory to free, free it. */
115 if (s->free_func != NULL)
116 s->free_func (s);
117
118 /* Free source-related stuff */
119 if (s->line_charpos != NULL)
120 xfree (s->line_charpos);
121 if (s->fullname != NULL)
122 xfree (s->fullname);
123 if (s->debugformat != NULL)
124 xfree (s->debugformat);
125 xfree (s);
126}
127
128void
129print_symbol_bcache_statistics (void)
130{
131 struct objfile *objfile;
132
133 immediate_quit++;
134 ALL_OBJFILES (objfile)
135 {
136 printf_filtered (_("Byte cache statistics for '%s':\n"), objfile->name);
137 print_bcache_statistics (objfile->psymbol_cache, "partial symbol cache");
138 print_bcache_statistics (objfile->macro_cache, "preprocessor macro cache");
139 }
140 immediate_quit--;
141}
142
143void
144print_objfile_statistics (void)
145{
146 struct objfile *objfile;
147 struct symtab *s;
148 struct partial_symtab *ps;
149 int i, linetables, blockvectors;
150
151 immediate_quit++;
152 ALL_OBJFILES (objfile)
153 {
154 printf_filtered (_("Statistics for '%s':\n"), objfile->name);
155 if (OBJSTAT (objfile, n_stabs) > 0)
156 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
157 OBJSTAT (objfile, n_stabs));
158 if (OBJSTAT (objfile, n_minsyms) > 0)
159 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
160 OBJSTAT (objfile, n_minsyms));
161 if (OBJSTAT (objfile, n_psyms) > 0)
162 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
163 OBJSTAT (objfile, n_psyms));
164 if (OBJSTAT (objfile, n_syms) > 0)
165 printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
166 OBJSTAT (objfile, n_syms));
167 if (OBJSTAT (objfile, n_types) > 0)
168 printf_filtered (_(" Number of \"types\" defined: %d\n"),
169 OBJSTAT (objfile, n_types));
170 i = 0;
171 ALL_OBJFILE_PSYMTABS (objfile, ps)
172 {
173 if (ps->readin == 0)
174 i++;
175 }
176 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i);
177 i = linetables = blockvectors = 0;
178 ALL_OBJFILE_SYMTABS (objfile, s)
179 {
180 i++;
181 if (s->linetable != NULL)
182 linetables++;
183 if (s->primary == 1)
184 blockvectors++;
185 }
186 printf_filtered (_(" Number of symbol tables: %d\n"), i);
187 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
188 linetables);
189 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
190 blockvectors);
191
192 if (OBJSTAT (objfile, sz_strtab) > 0)
193 printf_filtered (_(" Space used by a.out string tables: %d\n"),
194 OBJSTAT (objfile, sz_strtab));
195 printf_filtered (_(" Total memory used for objfile obstack: %d\n"),
196 obstack_memory_used (&objfile->objfile_obstack));
197 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
198 bcache_memory_used (objfile->psymbol_cache));
199 printf_filtered (_(" Total memory used for macro cache: %d\n"),
200 bcache_memory_used (objfile->macro_cache));
201 }
202 immediate_quit--;
203}
204
205static void
206dump_objfile (struct objfile *objfile)
207{
208 struct symtab *symtab;
209 struct partial_symtab *psymtab;
210
211 printf_filtered ("\nObject file %s: ", objfile->name);
212 printf_filtered ("Objfile at ");
213 gdb_print_host_address (objfile, gdb_stdout);
214 printf_filtered (", bfd at ");
215 gdb_print_host_address (objfile->obfd, gdb_stdout);
216 printf_filtered (", %d minsyms\n\n",
217 objfile->minimal_symbol_count);
218
219 if (objfile->psymtabs)
220 {
221 printf_filtered ("Psymtabs:\n");
222 for (psymtab = objfile->psymtabs;
223 psymtab != NULL;
224 psymtab = psymtab->next)
225 {
226 printf_filtered ("%s at ",
227 psymtab->filename);
228 gdb_print_host_address (psymtab, gdb_stdout);
229 printf_filtered (", ");
230 if (psymtab->objfile != objfile)
231 {
232 printf_filtered ("NOT ON CHAIN! ");
233 }
234 wrap_here (" ");
235 }
236 printf_filtered ("\n\n");
237 }
238
239 if (objfile->symtabs)
240 {
241 printf_filtered ("Symtabs:\n");
242 for (symtab = objfile->symtabs;
243 symtab != NULL;
244 symtab = symtab->next)
245 {
246 printf_filtered ("%s at ", symtab->filename);
247 gdb_print_host_address (symtab, gdb_stdout);
248 printf_filtered (", ");
249 if (symtab->objfile != objfile)
250 {
251 printf_filtered ("NOT ON CHAIN! ");
252 }
253 wrap_here (" ");
254 }
255 printf_filtered ("\n\n");
256 }
257}
258
259/* Print minimal symbols from this objfile. */
260
261static void
262dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
263{
264 struct minimal_symbol *msymbol;
265 int index;
266 char ms_type;
267
268 fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile->name);
269 if (objfile->minimal_symbol_count == 0)
270 {
271 fprintf_filtered (outfile, "No minimal symbols found.\n");
272 return;
273 }
274 index = 0;
275 ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
276 {
277 struct obj_section *section = SYMBOL_OBJ_SECTION (msymbol);
278
279 switch (MSYMBOL_TYPE (msymbol))
280 {
281 case mst_unknown:
282 ms_type = 'u';
283 break;
284 case mst_text:
285 ms_type = 'T';
286 break;
287 case mst_solib_trampoline:
288 ms_type = 'S';
289 break;
290 case mst_data:
291 ms_type = 'D';
292 break;
293 case mst_bss:
294 ms_type = 'B';
295 break;
296 case mst_abs:
297 ms_type = 'A';
298 break;
299 case mst_file_text:
300 ms_type = 't';
301 break;
302 case mst_file_data:
303 ms_type = 'd';
304 break;
305 case mst_file_bss:
306 ms_type = 'b';
307 break;
308 default:
309 ms_type = '?';
310 break;
311 }
312 fprintf_filtered (outfile, "[%2d] %c ", index, ms_type);
313 fputs_filtered (paddress (SYMBOL_VALUE_ADDRESS (msymbol)), outfile);
314 fprintf_filtered (outfile, " %s", SYMBOL_LINKAGE_NAME (msymbol));
315 if (section)
316 fprintf_filtered (outfile, " section %s",
317 bfd_section_name (objfile->obfd,
318 section->the_bfd_section));
319 if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
320 {
321 fprintf_filtered (outfile, " %s", SYMBOL_DEMANGLED_NAME (msymbol));
322 }
323 if (msymbol->filename)
324 fprintf_filtered (outfile, " %s", msymbol->filename);
325 fputs_filtered ("\n", outfile);
326 index++;
327 }
328 if (objfile->minimal_symbol_count != index)
329 {
330 warning (_("internal error: minimal symbol count %d != %d"),
331 objfile->minimal_symbol_count, index);
332 }
333 fprintf_filtered (outfile, "\n");
334}
335
336static void
337dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
338 struct ui_file *outfile)
339{
340 int i;
341
342 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
343 psymtab->filename);
344 fprintf_filtered (outfile, "(object ");
345 gdb_print_host_address (psymtab, outfile);
346 fprintf_filtered (outfile, ")\n\n");
347 fprintf_unfiltered (outfile, " Read from object file %s (",
348 objfile->name);
349 gdb_print_host_address (objfile, outfile);
350 fprintf_unfiltered (outfile, ")\n");
351
352 if (psymtab->readin)
353 {
354 fprintf_filtered (outfile,
355 " Full symtab was read (at ");
356 gdb_print_host_address (psymtab->symtab, outfile);
357 fprintf_filtered (outfile, " by function at ");
358 gdb_print_host_address (psymtab->read_symtab, outfile);
359 fprintf_filtered (outfile, ")\n");
360 }
361
362 fprintf_filtered (outfile, " Relocate symbols by ");
363 for (i = 0; i < psymtab->objfile->num_sections; ++i)
364 {
365 if (i != 0)
366 fprintf_filtered (outfile, ", ");
367 wrap_here (" ");
368 fputs_filtered (paddress (ANOFFSET (psymtab->section_offsets, i)),
369 outfile);
370 }
371 fprintf_filtered (outfile, "\n");
372
373 fprintf_filtered (outfile, " Symbols cover text addresses ");
374 fputs_filtered (paddress (psymtab->textlow), outfile);
375 fprintf_filtered (outfile, "-");
376 fputs_filtered (paddress (psymtab->texthigh), outfile);
377 fprintf_filtered (outfile, "\n");
378 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
379 psymtab->number_of_dependencies);
380 for (i = 0; i < psymtab->number_of_dependencies; i++)
381 {
382 fprintf_filtered (outfile, " %d ", i);
383 gdb_print_host_address (psymtab->dependencies[i], outfile);
384 fprintf_filtered (outfile, " %s\n",
385 psymtab->dependencies[i]->filename);
386 }
387 if (psymtab->n_global_syms > 0)
388 {
389 print_partial_symbols (objfile->global_psymbols.list
390 + psymtab->globals_offset,
391 psymtab->n_global_syms, "Global", outfile);
392 }
393 if (psymtab->n_static_syms > 0)
394 {
395 print_partial_symbols (objfile->static_psymbols.list
396 + psymtab->statics_offset,
397 psymtab->n_static_syms, "Static", outfile);
398 }
399 fprintf_filtered (outfile, "\n");
400}
401
402static void
403dump_symtab_1 (struct objfile *objfile, struct symtab *symtab,
404 struct ui_file *outfile)
405{
406 int i;
407 struct dict_iterator iter;
408 int len, blen;
409 struct linetable *l;
410 struct blockvector *bv;
411 struct symbol *sym;
412 struct block *b;
413 int depth;
414
415 fprintf_filtered (outfile, "\nSymtab for file %s\n", symtab->filename);
416 if (symtab->dirname)
417 fprintf_filtered (outfile, "Compilation directory is %s\n",
418 symtab->dirname);
419 fprintf_filtered (outfile, "Read from object file %s (", objfile->name);
420 gdb_print_host_address (objfile, outfile);
421 fprintf_filtered (outfile, ")\n");
422 fprintf_filtered (outfile, "Language: %s\n", language_str (symtab->language));
423
424 /* First print the line table. */
425 l = LINETABLE (symtab);
426 if (l)
427 {
428 fprintf_filtered (outfile, "\nLine table:\n\n");
429 len = l->nitems;
430 for (i = 0; i < len; i++)
431 {
432 fprintf_filtered (outfile, " line %d at ", l->item[i].line);
433 fputs_filtered (paddress (l->item[i].pc), outfile);
434 fprintf_filtered (outfile, "\n");
435 }
436 }
437 /* Now print the block info, but only for primary symtabs since we will
438 print lots of duplicate info otherwise. */
439 if (symtab->primary)
440 {
441 fprintf_filtered (outfile, "\nBlockvector:\n\n");
442 bv = BLOCKVECTOR (symtab);
443 len = BLOCKVECTOR_NBLOCKS (bv);
444 for (i = 0; i < len; i++)
445 {
446 b = BLOCKVECTOR_BLOCK (bv, i);
447 depth = block_depth (b) * 2;
448 print_spaces (depth, outfile);
449 fprintf_filtered (outfile, "block #%03d, object at ", i);
450 gdb_print_host_address (b, outfile);
451 if (BLOCK_SUPERBLOCK (b))
452 {
453 fprintf_filtered (outfile, " under ");
454 gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile);
455 }
456 /* drow/2002-07-10: We could save the total symbols count
457 even if we're using a hashtable, but nothing else but this message
458 wants it. */
459 fprintf_filtered (outfile, ", %d syms/buckets in ",
460 dict_size (BLOCK_DICT (b)));
461 fputs_filtered (paddress (BLOCK_START (b)), outfile);
462 fprintf_filtered (outfile, "..");
463 fputs_filtered (paddress (BLOCK_END (b)), outfile);
464 if (BLOCK_FUNCTION (b))
465 {
466 fprintf_filtered (outfile, ", function %s",
467 SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b)));
468 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
469 {
470 fprintf_filtered (outfile, ", %s",
471 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
472 }
473 }
474 fprintf_filtered (outfile, "\n");
475 /* Now print each symbol in this block (in no particular order, if
476 we're using a hashtable). */
477 ALL_BLOCK_SYMBOLS (b, iter, sym)
478 {
479 struct print_symbol_args s;
480 s.symbol = sym;
481 s.depth = depth + 1;
482 s.outfile = outfile;
483 catch_errors (print_symbol, &s, "Error printing symbol:\n",
484 RETURN_MASK_ERROR);
485 }
486 }
487 fprintf_filtered (outfile, "\n");
488 }
489 else
490 {
491 fprintf_filtered (outfile, "\nBlockvector same as previous symtab\n\n");
492 }
493}
494
495static void
496dump_symtab (struct objfile *objfile, struct symtab *symtab,
497 struct ui_file *outfile)
498{
499 enum language saved_lang;
500
501 /* Set the current language to the language of the symtab we're dumping
502 because certain routines used during dump_symtab() use the current
503 language to print an image of the symbol. We'll restore it later. */
504 saved_lang = set_language (symtab->language);
505
506 dump_symtab_1 (objfile, symtab, outfile);
507
508 set_language (saved_lang);
509}
510
511void
512maintenance_print_symbols (char *args, int from_tty)
513{
514 char **argv;
515 struct ui_file *outfile;
516 struct cleanup *cleanups;
517 char *symname = NULL;
518 char *filename = DEV_TTY;
519 struct objfile *objfile;
520 struct symtab *s;
521
522 dont_repeat ();
523
524 if (args == NULL)
525 {
526 error (_("\
527Arguments missing: an output file name and an optional symbol file name"));
528 }
529 argv = gdb_buildargv (args);
530 cleanups = make_cleanup_freeargv (argv);
531
532 if (argv[0] != NULL)
533 {
534 filename = argv[0];
535 /* If a second arg is supplied, it is a source file name to match on */
536 if (argv[1] != NULL)
537 {
538 symname = argv[1];
539 }
540 }
541
542 filename = tilde_expand (filename);
543 make_cleanup (xfree, filename);
544
545 outfile = gdb_fopen (filename, FOPEN_WT);
546 if (outfile == 0)
547 perror_with_name (filename);
548 make_cleanup_ui_file_delete (outfile);
549
550 immediate_quit++;
551 ALL_SYMTABS (objfile, s)
552 if (symname == NULL || strcmp (symname, s->filename) == 0)
553 dump_symtab (objfile, s, outfile);
554 immediate_quit--;
555 do_cleanups (cleanups);
556}
557
558/* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
559 far to indent. ARGS is really a struct print_symbol_args *, but is
560 declared as char * to get it past catch_errors. Returns 0 for error,
561 1 for success. */
562
563static int
564print_symbol (void *args)
565{
566 struct symbol *symbol = ((struct print_symbol_args *) args)->symbol;
567 int depth = ((struct print_symbol_args *) args)->depth;
568 struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile;
569 struct obj_section *section = SYMBOL_OBJ_SECTION (symbol);
570
571 print_spaces (depth, outfile);
572 if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN)
573 {
574 fprintf_filtered (outfile, "label %s at ", SYMBOL_PRINT_NAME (symbol));
575 fputs_filtered (paddress (SYMBOL_VALUE_ADDRESS (symbol)), outfile);
576 if (section)
577 fprintf_filtered (outfile, " section %s\n",
578 bfd_section_name (section->the_bfd_section->owner,
579 section->the_bfd_section));
580 else
581 fprintf_filtered (outfile, "\n");
582 return 1;
583 }
584 if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN)
585 {
586 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
587 {
588 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
589 }
590 else
591 {
592 fprintf_filtered (outfile, "%s %s = ",
593 (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
594 ? "enum"
595 : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
596 ? "struct" : "union")),
597 SYMBOL_LINKAGE_NAME (symbol));
598 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
599 }
600 fprintf_filtered (outfile, ";\n");
601 }
602 else
603 {
604 if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
605 fprintf_filtered (outfile, "typedef ");
606 if (SYMBOL_TYPE (symbol))
607 {
608 /* Print details of types, except for enums where it's clutter. */
609 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_PRINT_NAME (symbol),
610 outfile,
611 TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
612 depth);
613 fprintf_filtered (outfile, "; ");
614 }
615 else
616 fprintf_filtered (outfile, "%s ", SYMBOL_PRINT_NAME (symbol));
617
618 switch (SYMBOL_CLASS (symbol))
619 {
620 case LOC_CONST:
621 fprintf_filtered (outfile, "const %ld (0x%lx)",
622 SYMBOL_VALUE (symbol),
623 SYMBOL_VALUE (symbol));
624 break;
625
626 case LOC_CONST_BYTES:
627 {
628 unsigned i;
629 struct type *type = check_typedef (SYMBOL_TYPE (symbol));
630 fprintf_filtered (outfile, "const %u hex bytes:",
631 TYPE_LENGTH (type));
632 for (i = 0; i < TYPE_LENGTH (type); i++)
633 fprintf_filtered (outfile, " %02x",
634 (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]);
635 }
636 break;
637
638 case LOC_STATIC:
639 fprintf_filtered (outfile, "static at ");
640 fputs_filtered (paddress (SYMBOL_VALUE_ADDRESS (symbol)), outfile);
641 if (section)
642 fprintf_filtered (outfile, " section %s",
643 bfd_section_name (section->the_bfd_section->owner,
644 section->the_bfd_section));
645 break;
646
647 case LOC_REGISTER:
648 if (SYMBOL_IS_ARGUMENT (symbol))
649 fprintf_filtered (outfile, "parameter register %ld",
650 SYMBOL_VALUE (symbol));
651 else
652 fprintf_filtered (outfile, "register %ld", SYMBOL_VALUE (symbol));
653 break;
654
655 case LOC_ARG:
656 fprintf_filtered (outfile, "arg at offset 0x%lx",
657 SYMBOL_VALUE (symbol));
658 break;
659
660 case LOC_REF_ARG:
661 fprintf_filtered (outfile, "reference arg at 0x%lx", SYMBOL_VALUE (symbol));
662 break;
663
664 case LOC_REGPARM_ADDR:
665 fprintf_filtered (outfile, "address parameter register %ld", SYMBOL_VALUE (symbol));
666 break;
667
668 case LOC_LOCAL:
669 fprintf_filtered (outfile, "local at offset 0x%lx",
670 SYMBOL_VALUE (symbol));
671 break;
672
673 case LOC_TYPEDEF:
674 break;
675
676 case LOC_LABEL:
677 fprintf_filtered (outfile, "label at ");
678 fputs_filtered (paddress (SYMBOL_VALUE_ADDRESS (symbol)), outfile);
679 if (section)
680 fprintf_filtered (outfile, " section %s",
681 bfd_section_name (section->the_bfd_section->owner,
682 section->the_bfd_section));
683 break;
684
685 case LOC_BLOCK:
686 fprintf_filtered (outfile, "block object ");
687 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
688 fprintf_filtered (outfile, ", ");
689 fputs_filtered (paddress (BLOCK_START (SYMBOL_BLOCK_VALUE (symbol))),
690 outfile);
691 fprintf_filtered (outfile, "..");
692 fputs_filtered (paddress (BLOCK_END (SYMBOL_BLOCK_VALUE (symbol))),
693 outfile);
694 if (section)
695 fprintf_filtered (outfile, " section %s",
696 bfd_section_name (section->the_bfd_section->owner,
697 section->the_bfd_section));
698 break;
699
700 case LOC_COMPUTED:
701 fprintf_filtered (outfile, "computed at runtime");
702 break;
703
704 case LOC_UNRESOLVED:
705 fprintf_filtered (outfile, "unresolved");
706 break;
707
708 case LOC_OPTIMIZED_OUT:
709 fprintf_filtered (outfile, "optimized out");
710 break;
711
712 default:
713 fprintf_filtered (outfile, "botched symbol class %x",
714 SYMBOL_CLASS (symbol));
715 break;
716 }
717 }
718 fprintf_filtered (outfile, "\n");
719 return 1;
720}
721
722void
723maintenance_print_psymbols (char *args, int from_tty)
724{
725 char **argv;
726 struct ui_file *outfile;
727 struct cleanup *cleanups;
728 char *symname = NULL;
729 char *filename = DEV_TTY;
730 struct objfile *objfile;
731 struct partial_symtab *ps;
732
733 dont_repeat ();
734
735 if (args == NULL)
736 {
737 error (_("print-psymbols takes an output file name and optional symbol file name"));
738 }
739 argv = gdb_buildargv (args);
740 cleanups = make_cleanup_freeargv (argv);
741
742 if (argv[0] != NULL)
743 {
744 filename = argv[0];
745 /* If a second arg is supplied, it is a source file name to match on */
746 if (argv[1] != NULL)
747 {
748 symname = argv[1];
749 }
750 }
751
752 filename = tilde_expand (filename);
753 make_cleanup (xfree, filename);
754
755 outfile = gdb_fopen (filename, FOPEN_WT);
756 if (outfile == 0)
757 perror_with_name (filename);
758 make_cleanup_ui_file_delete (outfile);
759
760 immediate_quit++;
761 ALL_PSYMTABS (objfile, ps)
762 if (symname == NULL || strcmp (symname, ps->filename) == 0)
763 dump_psymtab (objfile, ps, outfile);
764 immediate_quit--;
765 do_cleanups (cleanups);
766}
767
768static void
769print_partial_symbols (struct partial_symbol **p, int count, char *what,
770 struct ui_file *outfile)
771{
772 fprintf_filtered (outfile, " %s partial symbols:\n", what);
773 while (count-- > 0)
774 {
775 fprintf_filtered (outfile, " `%s'", SYMBOL_LINKAGE_NAME (*p));
776 if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
777 {
778 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
779 }
780 fputs_filtered (", ", outfile);
781 switch (SYMBOL_DOMAIN (*p))
782 {
783 case UNDEF_DOMAIN:
784 fputs_filtered ("undefined domain, ", outfile);
785 break;
786 case VAR_DOMAIN:
787 /* This is the usual thing -- don't print it */
788 break;
789 case STRUCT_DOMAIN:
790 fputs_filtered ("struct domain, ", outfile);
791 break;
792 case LABEL_DOMAIN:
793 fputs_filtered ("label domain, ", outfile);
794 break;
795 default:
796 fputs_filtered ("<invalid domain>, ", outfile);
797 break;
798 }
799 switch (SYMBOL_CLASS (*p))
800 {
801 case LOC_UNDEF:
802 fputs_filtered ("undefined", outfile);
803 break;
804 case LOC_CONST:
805 fputs_filtered ("constant int", outfile);
806 break;
807 case LOC_STATIC:
808 fputs_filtered ("static", outfile);
809 break;
810 case LOC_REGISTER:
811 fputs_filtered ("register", outfile);
812 break;
813 case LOC_ARG:
814 fputs_filtered ("pass by value", outfile);
815 break;
816 case LOC_REF_ARG:
817 fputs_filtered ("pass by reference", outfile);
818 break;
819 case LOC_REGPARM_ADDR:
820 fputs_filtered ("register address parameter", outfile);
821 break;
822 case LOC_LOCAL:
823 fputs_filtered ("stack parameter", outfile);
824 break;
825 case LOC_TYPEDEF:
826 fputs_filtered ("type", outfile);
827 break;
828 case LOC_LABEL:
829 fputs_filtered ("label", outfile);
830 break;
831 case LOC_BLOCK:
832 fputs_filtered ("function", outfile);
833 break;
834 case LOC_CONST_BYTES:
835 fputs_filtered ("constant bytes", outfile);
836 break;
837 case LOC_UNRESOLVED:
838 fputs_filtered ("unresolved", outfile);
839 break;
840 case LOC_OPTIMIZED_OUT:
841 fputs_filtered ("optimized out", outfile);
842 break;
843 case LOC_COMPUTED:
844 fputs_filtered ("computed at runtime", outfile);
845 break;
846 default:
847 fputs_filtered ("<invalid location>", outfile);
848 break;
849 }
850 fputs_filtered (", ", outfile);
851 fputs_filtered (paddress (SYMBOL_VALUE_ADDRESS (*p)), outfile);
852 fprintf_filtered (outfile, "\n");
853 p++;
854 }
855}
856
857void
858maintenance_print_msymbols (char *args, int from_tty)
859{
860 char **argv;
861 struct ui_file *outfile;
862 struct cleanup *cleanups;
863 char *filename = DEV_TTY;
864 char *symname = NULL;
865 struct objfile *objfile;
866
867 struct stat sym_st, obj_st;
868
869 dont_repeat ();
870
871 if (args == NULL)
872 {
873 error (_("print-msymbols takes an output file name and optional symbol file name"));
874 }
875 argv = gdb_buildargv (args);
876 cleanups = make_cleanup_freeargv (argv);
877
878 if (argv[0] != NULL)
879 {
880 filename = argv[0];
881 /* If a second arg is supplied, it is a source file name to match on */
882 if (argv[1] != NULL)
883 {
884 symname = xfullpath (argv[1]);
885 make_cleanup (xfree, symname);
886 if (symname && stat (symname, &sym_st))
887 perror_with_name (symname);
888 }
889 }
890
891 filename = tilde_expand (filename);
892 make_cleanup (xfree, filename);
893
894 outfile = gdb_fopen (filename, FOPEN_WT);
895 if (outfile == 0)
896 perror_with_name (filename);
897 make_cleanup_ui_file_delete (outfile);
898
899 immediate_quit++;
900 ALL_OBJFILES (objfile)
901 if (symname == NULL
902 || (!stat (objfile->name, &obj_st) && sym_st.st_ino == obj_st.st_ino))
903 dump_msymbols (objfile, outfile);
904 immediate_quit--;
905 fprintf_filtered (outfile, "\n\n");
906 do_cleanups (cleanups);
907}
908
909void
910maintenance_print_objfiles (char *ignore, int from_tty)
911{
912 struct objfile *objfile;
913
914 dont_repeat ();
915
916 immediate_quit++;
917 ALL_OBJFILES (objfile)
918 dump_objfile (objfile);
919 immediate_quit--;
920}
921
922
923/* List all the symbol tables whose names match REGEXP (optional). */
924void
925maintenance_info_symtabs (char *regexp, int from_tty)
926{
927 struct objfile *objfile;
928
929 if (regexp)
930 re_comp (regexp);
931
932 ALL_OBJFILES (objfile)
933 {
934 struct symtab *symtab;
935
936 /* We don't want to print anything for this objfile until we
937 actually find a symtab whose name matches. */
938 int printed_objfile_start = 0;
939
940 ALL_OBJFILE_SYMTABS (objfile, symtab)
941 {
942 QUIT;
943
944 if (! regexp
945 || re_exec (symtab->filename))
946 {
947 if (! printed_objfile_start)
948 {
949 printf_filtered ("{ objfile %s ", objfile->name);
950 wrap_here (" ");
951 printf_filtered ("((struct objfile *) %s)\n",
952 host_address_to_string (objfile));
953 printed_objfile_start = 1;
954 }
955
956 printf_filtered (" { symtab %s ", symtab->filename);
957 wrap_here (" ");
958 printf_filtered ("((struct symtab *) %s)\n",
959 host_address_to_string (symtab));
960 printf_filtered (" dirname %s\n",
961 symtab->dirname ? symtab->dirname : "(null)");
962 printf_filtered (" fullname %s\n",
963 symtab->fullname ? symtab->fullname : "(null)");
964 printf_filtered (" blockvector ((struct blockvector *) %s)%s\n",
965 host_address_to_string (symtab->blockvector),
966 symtab->primary ? " (primary)" : "");
967 printf_filtered (" linetable ((struct linetable *) %s)\n",
968 host_address_to_string (symtab->linetable));
969 printf_filtered (" debugformat %s\n", symtab->debugformat);
970 printf_filtered (" }\n");
971 }
972 }
973
974 if (printed_objfile_start)
975 printf_filtered ("}\n");
976 }
977}
978
979
980/* List all the partial symbol tables whose names match REGEXP (optional). */
981void
982maintenance_info_psymtabs (char *regexp, int from_tty)
983{
984 struct objfile *objfile;
985
986 if (regexp)
987 re_comp (regexp);
988
989 ALL_OBJFILES (objfile)
990 {
991 struct partial_symtab *psymtab;
992
993 /* We don't want to print anything for this objfile until we
994 actually find a symtab whose name matches. */
995 int printed_objfile_start = 0;
996
997 ALL_OBJFILE_PSYMTABS (objfile, psymtab)
998 {
999 QUIT;
1000
1001 if (! regexp
1002 || re_exec (psymtab->filename))
1003 {
1004 if (! printed_objfile_start)
1005 {
1006 printf_filtered ("{ objfile %s ", objfile->name);
1007 wrap_here (" ");
1008 printf_filtered ("((struct objfile *) %s)\n",
1009 host_address_to_string (objfile));
1010 printed_objfile_start = 1;
1011 }
1012
1013 printf_filtered (" { psymtab %s ", psymtab->filename);
1014 wrap_here (" ");
1015 printf_filtered ("((struct partial_symtab *) %s)\n",
1016 host_address_to_string (psymtab));
1017
1018 printf_filtered (" readin %s\n",
1019 psymtab->readin ? "yes" : "no");
1020 printf_filtered (" fullname %s\n",
1021 psymtab->fullname ? psymtab->fullname : "(null)");
1022 printf_filtered (" text addresses ");
1023 fputs_filtered (paddress (psymtab->textlow), gdb_stdout);
1024 printf_filtered (" -- ");
1025 fputs_filtered (paddress (psymtab->texthigh), gdb_stdout);
1026 printf_filtered ("\n");
1027 printf_filtered (" globals ");
1028 if (psymtab->n_global_syms)
1029 {
1030 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1031 host_address_to_string (psymtab->objfile->global_psymbols.list
1032 + psymtab->globals_offset),
1033 psymtab->n_global_syms);
1034 }
1035 else
1036 printf_filtered ("(none)\n");
1037 printf_filtered (" statics ");
1038 if (psymtab->n_static_syms)
1039 {
1040 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1041 host_address_to_string (psymtab->objfile->static_psymbols.list
1042 + psymtab->statics_offset),
1043 psymtab->n_static_syms);
1044 }
1045 else
1046 printf_filtered ("(none)\n");
1047 printf_filtered (" dependencies ");
1048 if (psymtab->number_of_dependencies)
1049 {
1050 int i;
1051
1052 printf_filtered ("{\n");
1053 for (i = 0; i < psymtab->number_of_dependencies; i++)
1054 {
1055 struct partial_symtab *dep = psymtab->dependencies[i];
1056
1057 /* Note the string concatenation there --- no comma. */
1058 printf_filtered (" psymtab %s "
1059 "((struct partial_symtab *) %s)\n",
1060 dep->filename,
1061 host_address_to_string (dep));
1062 }
1063 printf_filtered (" }\n");
1064 }
1065 else
1066 printf_filtered ("(none)\n");
1067 printf_filtered (" }\n");
1068 }
1069 }
1070
1071 if (printed_objfile_start)
1072 printf_filtered ("}\n");
1073 }
1074}
1075
1076
1077/* Check consistency of psymtabs and symtabs. */
1078
1079void
1080maintenance_check_symtabs (char *ignore, int from_tty)
1081{
1082 struct symbol *sym;
1083 struct partial_symbol **psym;
1084 struct symtab *s = NULL;
1085 struct partial_symtab *ps;
1086 struct blockvector *bv;
1087 struct objfile *objfile;
1088 struct block *b;
1089 int length;
1090
1091 ALL_PSYMTABS (objfile, ps)
1092 {
1093 s = PSYMTAB_TO_SYMTAB (ps);
1094 if (s == NULL)
1095 continue;
1096 bv = BLOCKVECTOR (s);
1097 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1098 psym = ps->objfile->static_psymbols.list + ps->statics_offset;
1099 length = ps->n_static_syms;
1100 while (length--)
1101 {
1102 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1103 NULL, SYMBOL_DOMAIN (*psym));
1104 if (!sym)
1105 {
1106 printf_filtered ("Static symbol `");
1107 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1108 printf_filtered ("' only found in ");
1109 puts_filtered (ps->filename);
1110 printf_filtered (" psymtab\n");
1111 }
1112 psym++;
1113 }
1114 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1115 psym = ps->objfile->global_psymbols.list + ps->globals_offset;
1116 length = ps->n_global_syms;
1117 while (length--)
1118 {
1119 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1120 NULL, SYMBOL_DOMAIN (*psym));
1121 if (!sym)
1122 {
1123 printf_filtered ("Global symbol `");
1124 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1125 printf_filtered ("' only found in ");
1126 puts_filtered (ps->filename);
1127 printf_filtered (" psymtab\n");
1128 }
1129 psym++;
1130 }
1131 if (ps->texthigh < ps->textlow)
1132 {
1133 printf_filtered ("Psymtab ");
1134 puts_filtered (ps->filename);
1135 printf_filtered (" covers bad range ");
1136 fputs_filtered (paddress (ps->textlow), gdb_stdout);
1137 printf_filtered (" - ");
1138 fputs_filtered (paddress (ps->texthigh), gdb_stdout);
1139 printf_filtered ("\n");
1140 continue;
1141 }
1142 if (ps->texthigh == 0)
1143 continue;
1144 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
1145 {
1146 printf_filtered ("Psymtab ");
1147 puts_filtered (ps->filename);
1148 printf_filtered (" covers ");
1149 fputs_filtered (paddress (ps->textlow), gdb_stdout);
1150 printf_filtered (" - ");
1151 fputs_filtered (paddress (ps->texthigh), gdb_stdout);
1152 printf_filtered (" but symtab covers only ");
1153 fputs_filtered (paddress (BLOCK_START (b)), gdb_stdout);
1154 printf_filtered (" - ");
1155 fputs_filtered (paddress (BLOCK_END (b)), gdb_stdout);
1156 printf_filtered ("\n");
1157 }
1158 }
1159}
1160\f
1161
1162/* Return the nexting depth of a block within other blocks in its symtab. */
1163
1164static int
1165block_depth (struct block *block)
1166{
1167 int i = 0;
1168 while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
1169 {
1170 i++;
1171 }
1172 return i;
1173}
1174\f
1175
1176/* Increase the space allocated for LISTP, which is probably
1177 global_psymbols or static_psymbols. This space will eventually
1178 be freed in free_objfile(). */
1179
1180void
1181extend_psymbol_list (struct psymbol_allocation_list *listp,
1182 struct objfile *objfile)
1183{
1184 int new_size;
1185 if (listp->size == 0)
1186 {
1187 new_size = 255;
1188 listp->list = (struct partial_symbol **)
1189 xmalloc (new_size * sizeof (struct partial_symbol *));
1190 }
1191 else
1192 {
1193 new_size = listp->size * 2;
1194 listp->list = (struct partial_symbol **)
1195 xrealloc ((char *) listp->list,
1196 new_size * sizeof (struct partial_symbol *));
1197 }
1198 /* Next assumes we only went one over. Should be good if
1199 program works correctly */
1200 listp->next = listp->list + listp->size;
1201 listp->size = new_size;
1202}
1203
1204
1205/* Do early runtime initializations. */
1206void
1207_initialize_symmisc (void)
1208{
1209 std_in = stdin;
1210 std_out = stdout;
1211 std_err = stderr;
1212}
This page took 0.026539 seconds and 4 git commands to generate.