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