Thu Oct 26 10:23:14 1995 steve chamberlain <sac@slash.cygnus.com>
[deliverable/binutils-gdb.git] / gdb / symmisc.c
1 /* Do various things to symbol tables (other than lookup), for GDB.
2 Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994
3 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21 #include "defs.h"
22 #include "symtab.h"
23 #include "gdbtypes.h"
24 #include "bfd.h"
25 #include "symfile.h"
26 #include "objfiles.h"
27 #include "breakpoint.h"
28 #include "command.h"
29 #include "obstack.h"
30 #include "language.h"
31
32 #include "gdb_string.h"
33
34 #ifndef DEV_TTY
35 #define DEV_TTY "/dev/tty"
36 #endif
37
38 /* Unfortunately for debugging, stderr is usually a macro. This is painful
39 when calling functions that take FILE *'s from the debugger.
40 So we make a variable which has the same value and which is accessible when
41 debugging GDB with itself. Because stdin et al need not be constants,
42 we initialize them in the _initialize_symmisc function at the bottom
43 of the file. */
44 FILE *std_in;
45 FILE *std_out;
46 FILE *std_err;
47
48 /* Prototypes for local functions */
49
50 static void
51 dump_symtab PARAMS ((struct objfile *, struct symtab *, GDB_FILE *));
52
53 static void
54 dump_psymtab PARAMS ((struct objfile *, struct partial_symtab *, GDB_FILE *));
55
56 static void
57 dump_msymbols PARAMS ((struct objfile *, GDB_FILE *));
58
59 static void
60 dump_objfile PARAMS ((struct objfile *));
61
62 static int
63 block_depth PARAMS ((struct block *));
64
65 static void
66 print_partial_symbol PARAMS ((struct partial_symbol *, int, char *, GDB_FILE *));
67
68 struct print_symbol_args {
69 struct symbol *symbol;
70 int depth;
71 GDB_FILE *outfile;
72 };
73
74 static int print_symbol PARAMS ((char *));
75
76 static void
77 free_symtab_block PARAMS ((struct objfile *, struct block *));
78
79 \f
80 /* Free a struct block <- B and all the symbols defined in that block. */
81
82 static void
83 free_symtab_block (objfile, b)
84 struct objfile *objfile;
85 struct block *b;
86 {
87 register int i, n;
88 n = BLOCK_NSYMS (b);
89 for (i = 0; i < n; i++)
90 {
91 mfree (objfile -> md, SYMBOL_NAME (BLOCK_SYM (b, i)));
92 mfree (objfile -> md, (PTR) BLOCK_SYM (b, i));
93 }
94 mfree (objfile -> md, (PTR) b);
95 }
96
97 /* Free all the storage associated with the struct symtab <- S.
98 Note that some symtabs have contents malloc'ed structure by structure,
99 while some have contents that all live inside one big block of memory,
100 and some share the contents of another symbol table and so you should
101 not free the contents on their behalf (except sometimes the linetable,
102 which maybe per symtab even when the rest is not).
103 It is s->free_code that says which alternative to use. */
104
105 void
106 free_symtab (s)
107 register struct symtab *s;
108 {
109 register int i, n;
110 register struct blockvector *bv;
111
112 switch (s->free_code)
113 {
114 case free_nothing:
115 /* All the contents are part of a big block of memory (an obstack),
116 and some other symtab is in charge of freeing that block.
117 Therefore, do nothing. */
118 break;
119
120 case free_contents:
121 /* Here all the contents were malloc'ed structure by structure
122 and must be freed that way. */
123 /* First free the blocks (and their symbols. */
124 bv = BLOCKVECTOR (s);
125 n = BLOCKVECTOR_NBLOCKS (bv);
126 for (i = 0; i < n; i++)
127 free_symtab_block (s -> objfile, BLOCKVECTOR_BLOCK (bv, i));
128 /* Free the blockvector itself. */
129 mfree (s -> objfile -> md, (PTR) bv);
130 /* Also free the linetable. */
131
132 case free_linetable:
133 /* Everything will be freed either by our `free_ptr'
134 or by some other symtab, except for our linetable.
135 Free that now. */
136 if (LINETABLE (s))
137 mfree (s -> objfile -> md, (PTR) LINETABLE (s));
138 break;
139 }
140
141 /* If there is a single block of memory to free, free it. */
142 if (s -> free_ptr != NULL)
143 mfree (s -> objfile -> md, s -> free_ptr);
144
145 /* Free source-related stuff */
146 if (s -> line_charpos != NULL)
147 mfree (s -> objfile -> md, (PTR) s -> line_charpos);
148 if (s -> fullname != NULL)
149 mfree (s -> objfile -> md, s -> fullname);
150 mfree (s -> objfile -> md, (PTR) s);
151 }
152
153 #if MAINTENANCE_CMDS
154
155 static void
156 dump_objfile (objfile)
157 struct objfile *objfile;
158 {
159 struct symtab *symtab;
160 struct partial_symtab *psymtab;
161
162 printf_filtered ("\nObject file %s: ", objfile -> name);
163 printf_filtered ("Objfile at ");
164 gdb_print_address (objfile, gdb_stdout);
165 printf_filtered (", bfd at ");
166 gdb_print_address (objfile->obfd, gdb_stdout);
167 printf_filtered (", %d minsyms\n\n",
168 objfile->minimal_symbol_count);
169
170 if (objfile -> psymtabs)
171 {
172 printf_filtered ("Psymtabs:\n");
173 for (psymtab = objfile -> psymtabs;
174 psymtab != NULL;
175 psymtab = psymtab -> next)
176 {
177 printf_filtered ("%s at ",
178 psymtab -> filename);
179 gdb_print_address (psymtab, gdb_stdout);
180 printf_filtered (", ");
181 if (psymtab -> objfile != objfile)
182 {
183 printf_filtered ("NOT ON CHAIN! ");
184 }
185 wrap_here (" ");
186 }
187 printf_filtered ("\n\n");
188 }
189
190 if (objfile -> symtabs)
191 {
192 printf_filtered ("Symtabs:\n");
193 for (symtab = objfile -> symtabs;
194 symtab != NULL;
195 symtab = symtab->next)
196 {
197 printf_filtered ("%s at ", symtab -> filename);
198 gdb_print_address (symtab, gdb_stdout);
199 printf_filtered (", ");
200 if (symtab -> objfile != objfile)
201 {
202 printf_filtered ("NOT ON CHAIN! ");
203 }
204 wrap_here (" ");
205 }
206 printf_filtered ("\n\n");
207 }
208 }
209
210 /* Print minimal symbols from this objfile. */
211
212 static void
213 dump_msymbols (objfile, outfile)
214 struct objfile *objfile;
215 GDB_FILE *outfile;
216 {
217 struct minimal_symbol *msymbol;
218 int index;
219 char ms_type;
220
221 fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile -> name);
222 if (objfile -> minimal_symbol_count == 0)
223 {
224 fprintf_filtered (outfile, "No minimal symbols found.\n");
225 return;
226 }
227 for (index = 0, msymbol = objfile -> msymbols;
228 SYMBOL_NAME (msymbol) != NULL; msymbol++, index++)
229 {
230 switch (msymbol -> type)
231 {
232 case mst_unknown:
233 ms_type = 'u';
234 break;
235 case mst_text:
236 ms_type = 'T';
237 break;
238 case mst_solib_trampoline:
239 ms_type = 'S';
240 break;
241 case mst_data:
242 ms_type = 'D';
243 break;
244 case mst_bss:
245 ms_type = 'B';
246 break;
247 case mst_abs:
248 ms_type = 'A';
249 break;
250 case mst_file_text:
251 ms_type = 't';
252 break;
253 case mst_file_data:
254 ms_type = 'd';
255 break;
256 case mst_file_bss:
257 ms_type = 'b';
258 break;
259 default:
260 ms_type = '?';
261 break;
262 }
263 fprintf_filtered (outfile, "[%2d] %c %#10lx %s", index, ms_type,
264 SYMBOL_VALUE_ADDRESS (msymbol), SYMBOL_NAME (msymbol));
265 if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
266 {
267 fprintf_filtered (outfile, " %s", SYMBOL_DEMANGLED_NAME (msymbol));
268 }
269 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
270 if (msymbol->filename)
271 fprintf_filtered (outfile, " %s", msymbol->filename);
272 #endif
273 fputs_filtered ("\n", outfile);
274 }
275 if (objfile -> minimal_symbol_count != index)
276 {
277 warning ("internal error: minimal symbol count %d != %d",
278 objfile -> minimal_symbol_count, index);
279 }
280 fprintf_filtered (outfile, "\n");
281 }
282
283 static void
284 dump_psymtab (objfile, psymtab, outfile)
285 struct objfile *objfile;
286 struct partial_symtab *psymtab;
287 GDB_FILE *outfile;
288 {
289 int i;
290
291 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
292 psymtab -> filename);
293 fprintf_filtered (outfile, "(object ");
294 gdb_print_address (psymtab, outfile);
295 fprintf_filtered (outfile, ")\n\n");
296 fprintf_unfiltered (outfile, " Read from object file %s (",
297 objfile -> name);
298 gdb_print_address (objfile, outfile);
299 fprintf_unfiltered (outfile, ")\n");
300
301 if (psymtab -> readin)
302 {
303 fprintf_filtered (outfile,
304 " Full symtab was read (at ");
305 gdb_print_address (psymtab->symtab, outfile);
306 fprintf_filtered (outfile, " by function at ");
307 gdb_print_address ((PTR)psymtab->read_symtab, outfile);
308 fprintf_filtered (outfile, ")\n");
309 }
310
311 fprintf_filtered (outfile, " Relocate symbols by ");
312 for (i = 0; i < psymtab->objfile->num_sections; ++i)
313 {
314 if (i != 0)
315 fprintf_filtered (outfile, ", ");
316 wrap_here (" ");
317 print_address_numeric (ANOFFSET (psymtab->section_offsets, i),
318 1,
319 outfile);
320 }
321 fprintf_filtered (outfile, "\n");
322
323 fprintf_filtered (outfile, " Symbols cover text addresses ");
324 print_address_numeric (psymtab->textlow, 1, outfile);
325 fprintf_filtered (outfile, "-");
326 print_address_numeric (psymtab->texthigh, 1, outfile);
327 fprintf_filtered (outfile, "\n");
328 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
329 psymtab -> number_of_dependencies);
330 for (i = 0; i < psymtab -> number_of_dependencies; i++)
331 {
332 fprintf_filtered (outfile, " %d ", i);
333 gdb_print_address (psymtab -> dependencies[i], outfile);
334 fprintf_filtered (outfile, " %s\n",
335 psymtab -> dependencies[i] -> filename);
336 }
337 if (psymtab -> n_global_syms > 0)
338 {
339 print_partial_symbol (objfile -> global_psymbols.list
340 + psymtab -> globals_offset,
341 psymtab -> n_global_syms, "Global", outfile);
342 }
343 if (psymtab -> n_static_syms > 0)
344 {
345 print_partial_symbol (objfile -> static_psymbols.list
346 + psymtab -> statics_offset,
347 psymtab -> n_static_syms, "Static", outfile);
348 }
349 fprintf_filtered (outfile, "\n");
350 }
351
352 static void
353 dump_symtab (objfile, symtab, outfile)
354 struct objfile *objfile;
355 struct symtab *symtab;
356 GDB_FILE *outfile;
357 {
358 register int i, j;
359 int len, blen;
360 register struct linetable *l;
361 struct blockvector *bv;
362 register struct block *b;
363 int depth;
364
365 fprintf_filtered (outfile, "\nSymtab for file %s\n", symtab->filename);
366 fprintf_filtered (outfile, "Read from object file %s (", objfile->name);
367 gdb_print_address (objfile, outfile);
368 fprintf_filtered (outfile, ")\n");
369 fprintf_filtered (outfile, "Language: %s\n", language_str (symtab -> language));
370
371 /* First print the line table. */
372 l = LINETABLE (symtab);
373 if (l)
374 {
375 fprintf_filtered (outfile, "\nLine table:\n\n");
376 len = l->nitems;
377 for (i = 0; i < len; i++)
378 {
379 fprintf_filtered (outfile, " line %d at ", l->item[i].line);
380 print_address_numeric (l->item[i].pc, 1, outfile);
381 fprintf_filtered (outfile, "\n");
382 }
383 }
384 /* Now print the block info. */
385 fprintf_filtered (outfile, "\nBlockvector:\n\n");
386 bv = BLOCKVECTOR (symtab);
387 len = BLOCKVECTOR_NBLOCKS (bv);
388 for (i = 0; i < len; i++)
389 {
390 b = BLOCKVECTOR_BLOCK (bv, i);
391 depth = block_depth (b) * 2;
392 print_spaces (depth, outfile);
393 fprintf_filtered (outfile, "block #%03d (object ", i);
394 gdb_print_address (b, outfile);
395 fprintf_filtered (outfile, ") ");
396 fprintf_filtered (outfile, "[");
397 print_address_numeric (BLOCK_START (b), 1, outfile);
398 fprintf_filtered (outfile, "..");
399 print_address_numeric (BLOCK_END (b), 1, outfile);
400 fprintf_filtered (outfile, "]");
401 if (BLOCK_SUPERBLOCK (b))
402 {
403 fprintf_filtered (outfile, " (under ");
404 gdb_print_address (BLOCK_SUPERBLOCK (b), outfile);
405 fprintf_filtered (outfile, ")");
406 }
407 if (BLOCK_FUNCTION (b))
408 {
409 fprintf_filtered (outfile, " %s", SYMBOL_NAME (BLOCK_FUNCTION (b)));
410 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
411 {
412 fprintf_filtered (outfile, " %s",
413 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
414 }
415 }
416 if (BLOCK_GCC_COMPILED(b))
417 fprintf_filtered (outfile, " gcc%d compiled", BLOCK_GCC_COMPILED(b));
418 fprintf_filtered (outfile, "\n");
419 blen = BLOCK_NSYMS (b);
420 for (j = 0; j < blen; j++)
421 {
422 struct print_symbol_args s;
423 s.symbol = BLOCK_SYM (b, j);
424 s.depth = depth + 1;
425 s.outfile = outfile;
426 catch_errors (print_symbol, &s, "Error printing symbol:\n",
427 RETURN_MASK_ERROR);
428 }
429 }
430 fprintf_filtered (outfile, "\n");
431 }
432
433 void
434 maintenance_print_symbols (args, from_tty)
435 char *args;
436 int from_tty;
437 {
438 char **argv;
439 GDB_FILE *outfile;
440 struct cleanup *cleanups;
441 char *symname = NULL;
442 char *filename = DEV_TTY;
443 struct objfile *objfile;
444 struct symtab *s;
445
446 dont_repeat ();
447
448 if (args == NULL)
449 {
450 error ("\
451 Arguments missing: an output file name and an optional symbol file name");
452 }
453 else if ((argv = buildargv (args)) == NULL)
454 {
455 nomem (0);
456 }
457 cleanups = make_cleanup (freeargv, (char *) argv);
458
459 if (argv[0] != NULL)
460 {
461 filename = argv[0];
462 /* If a second arg is supplied, it is a source file name to match on */
463 if (argv[1] != NULL)
464 {
465 symname = argv[1];
466 }
467 }
468
469 filename = tilde_expand (filename);
470 make_cleanup (free, filename);
471
472 outfile = gdb_fopen (filename, FOPEN_WT);
473 if (outfile == 0)
474 perror_with_name (filename);
475 make_cleanup (fclose, (char *) outfile);
476
477 immediate_quit++;
478 ALL_SYMTABS (objfile, s)
479 if (symname == NULL || (STREQ (symname, s -> filename)))
480 dump_symtab (objfile, s, outfile);
481 immediate_quit--;
482 do_cleanups (cleanups);
483 }
484
485 /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
486 far to indent. ARGS is really a struct print_symbol_args *, but is
487 declared as char * to get it past catch_errors. Returns 0 for error,
488 1 for success. */
489
490 static int
491 print_symbol (args)
492 char *args;
493 {
494 struct symbol *symbol = ((struct print_symbol_args *)args)->symbol;
495 int depth = ((struct print_symbol_args *)args)->depth;
496 GDB_FILE *outfile = ((struct print_symbol_args *)args)->outfile;
497
498 print_spaces (depth, outfile);
499 if (SYMBOL_NAMESPACE (symbol) == LABEL_NAMESPACE)
500 {
501 fprintf_filtered (outfile, "label %s at ", SYMBOL_SOURCE_NAME (symbol));
502 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
503 fprintf_filtered (outfile, "\n");
504 return 1;
505 }
506 if (SYMBOL_NAMESPACE (symbol) == STRUCT_NAMESPACE)
507 {
508 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
509 {
510 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
511 }
512 else
513 {
514 fprintf_filtered (outfile, "%s %s = ",
515 (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
516 ? "enum"
517 : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
518 ? "struct" : "union")),
519 SYMBOL_NAME (symbol));
520 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
521 }
522 fprintf_filtered (outfile, ";\n");
523 }
524 else
525 {
526 if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
527 fprintf_filtered (outfile, "typedef ");
528 if (SYMBOL_TYPE (symbol))
529 {
530 /* Print details of types, except for enums where it's clutter. */
531 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_SOURCE_NAME (symbol),
532 outfile,
533 TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
534 depth);
535 fprintf_filtered (outfile, "; ");
536 }
537 else
538 fprintf_filtered (outfile, "%s ", SYMBOL_SOURCE_NAME (symbol));
539
540 switch (SYMBOL_CLASS (symbol))
541 {
542 case LOC_CONST:
543 fprintf_filtered (outfile, "const %ld (0x%lx),",
544 SYMBOL_VALUE (symbol),
545 SYMBOL_VALUE (symbol));
546 break;
547
548 case LOC_CONST_BYTES:
549 fprintf_filtered (outfile, "const %u hex bytes:",
550 TYPE_LENGTH (SYMBOL_TYPE (symbol)));
551 {
552 unsigned i;
553 for (i = 0; i < TYPE_LENGTH (SYMBOL_TYPE (symbol)); i++)
554 fprintf_filtered (outfile, " %02x",
555 (unsigned)SYMBOL_VALUE_BYTES (symbol) [i]);
556 fprintf_filtered (outfile, ",");
557 }
558 break;
559
560 case LOC_STATIC:
561 fprintf_filtered (outfile, "static at ");
562 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1,outfile);
563 fprintf_filtered (outfile, ",");
564 break;
565
566 case LOC_REGISTER:
567 fprintf_filtered (outfile, "register %ld,", SYMBOL_VALUE (symbol));
568 break;
569
570 case LOC_ARG:
571 fprintf_filtered (outfile, "arg at offset 0x%lx,",
572 SYMBOL_VALUE (symbol));
573 break;
574
575 case LOC_LOCAL_ARG:
576 fprintf_filtered (outfile, "arg at offset 0x%lx from fp,",
577 SYMBOL_VALUE (symbol));
578 break;
579
580 case LOC_REF_ARG:
581 fprintf_filtered (outfile, "reference arg at 0x%lx,", SYMBOL_VALUE (symbol));
582 break;
583
584 case LOC_REGPARM:
585 fprintf_filtered (outfile, "parameter register %ld,", SYMBOL_VALUE (symbol));
586 break;
587
588 case LOC_REGPARM_ADDR:
589 fprintf_filtered (outfile, "address parameter register %ld,", SYMBOL_VALUE (symbol));
590 break;
591
592 case LOC_LOCAL:
593 fprintf_filtered (outfile, "local at offset 0x%lx,",
594 SYMBOL_VALUE (symbol));
595 break;
596
597 case LOC_BASEREG:
598 fprintf_filtered (outfile, "local at 0x%lx from register %d",
599 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
600 break;
601
602 case LOC_BASEREG_ARG:
603 fprintf_filtered (outfile, "arg at 0x%lx from register %d,",
604 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
605 break;
606
607 case LOC_TYPEDEF:
608 break;
609
610 case LOC_LABEL:
611 fprintf_filtered (outfile, "label at ");
612 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
613 break;
614
615 case LOC_BLOCK:
616 fprintf_filtered (outfile, "block (object ");
617 gdb_print_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
618 fprintf_filtered (outfile, ") starting at ");
619 print_address_numeric (BLOCK_START (SYMBOL_BLOCK_VALUE (symbol)),
620 1,
621 outfile);
622 fprintf_filtered (outfile, ",");
623 break;
624
625 case LOC_OPTIMIZED_OUT:
626 fprintf_filtered (outfile, "optimized out");
627 break;
628
629 default:
630 fprintf_filtered (outfile, "botched symbol class %x",
631 SYMBOL_CLASS (symbol));
632 break;
633 }
634 }
635 fprintf_filtered (outfile, "\n");
636 return 1;
637 }
638
639 void
640 maintenance_print_psymbols (args, from_tty)
641 char *args;
642 int from_tty;
643 {
644 char **argv;
645 GDB_FILE *outfile;
646 struct cleanup *cleanups;
647 char *symname = NULL;
648 char *filename = DEV_TTY;
649 struct objfile *objfile;
650 struct partial_symtab *ps;
651
652 dont_repeat ();
653
654 if (args == NULL)
655 {
656 error ("print-psymbols takes an output file name and optional symbol file name");
657 }
658 else if ((argv = buildargv (args)) == NULL)
659 {
660 nomem (0);
661 }
662 cleanups = make_cleanup (freeargv, (char *) argv);
663
664 if (argv[0] != NULL)
665 {
666 filename = argv[0];
667 /* If a second arg is supplied, it is a source file name to match on */
668 if (argv[1] != NULL)
669 {
670 symname = argv[1];
671 }
672 }
673
674 filename = tilde_expand (filename);
675 make_cleanup (free, filename);
676
677 outfile = gdb_fopen (filename, FOPEN_WT);
678 if (outfile == 0)
679 perror_with_name (filename);
680 make_cleanup (fclose, outfile);
681
682 immediate_quit++;
683 ALL_PSYMTABS (objfile, ps)
684 if (symname == NULL || (STREQ (symname, ps -> filename)))
685 dump_psymtab (objfile, ps, outfile);
686 immediate_quit--;
687 do_cleanups (cleanups);
688 }
689
690 static void
691 print_partial_symbol (p, count, what, outfile)
692 struct partial_symbol *p;
693 int count;
694 char *what;
695 GDB_FILE *outfile;
696 {
697
698 fprintf_filtered (outfile, " %s partial symbols:\n", what);
699 while (count-- > 0)
700 {
701 fprintf_filtered (outfile, " `%s'", SYMBOL_NAME(p));
702 if (SYMBOL_DEMANGLED_NAME (p) != NULL)
703 {
704 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (p));
705 }
706 fputs_filtered (", ", outfile);
707 switch (SYMBOL_NAMESPACE (p))
708 {
709 case UNDEF_NAMESPACE:
710 fputs_filtered ("undefined namespace, ", outfile);
711 break;
712 case VAR_NAMESPACE:
713 /* This is the usual thing -- don't print it */
714 break;
715 case STRUCT_NAMESPACE:
716 fputs_filtered ("struct namespace, ", outfile);
717 break;
718 case LABEL_NAMESPACE:
719 fputs_filtered ("label namespace, ", outfile);
720 break;
721 default:
722 fputs_filtered ("<invalid namespace>, ", outfile);
723 break;
724 }
725 switch (SYMBOL_CLASS (p))
726 {
727 case LOC_UNDEF:
728 fputs_filtered ("undefined", outfile);
729 break;
730 case LOC_CONST:
731 fputs_filtered ("constant int", outfile);
732 break;
733 case LOC_STATIC:
734 fputs_filtered ("static", outfile);
735 break;
736 case LOC_REGISTER:
737 fputs_filtered ("register", outfile);
738 break;
739 case LOC_ARG:
740 fputs_filtered ("pass by value", outfile);
741 break;
742 case LOC_REF_ARG:
743 fputs_filtered ("pass by reference", outfile);
744 break;
745 case LOC_REGPARM:
746 fputs_filtered ("register parameter", outfile);
747 break;
748 case LOC_REGPARM_ADDR:
749 fputs_filtered ("register address parameter", outfile);
750 break;
751 case LOC_LOCAL:
752 fputs_filtered ("stack parameter", outfile);
753 break;
754 case LOC_TYPEDEF:
755 fputs_filtered ("type", outfile);
756 break;
757 case LOC_LABEL:
758 fputs_filtered ("label", outfile);
759 break;
760 case LOC_BLOCK:
761 fputs_filtered ("function", outfile);
762 break;
763 case LOC_CONST_BYTES:
764 fputs_filtered ("constant bytes", outfile);
765 break;
766 case LOC_LOCAL_ARG:
767 fputs_filtered ("shuffled arg", outfile);
768 break;
769 case LOC_OPTIMIZED_OUT:
770 fputs_filtered ("optimized out", outfile);
771 break;
772 default:
773 fputs_filtered ("<invalid location>", outfile);
774 break;
775 }
776 fputs_filtered (", ", outfile);
777 /* FIXME-32x64: Need to use SYMBOL_VALUE_ADDRESS, etc.; this
778 could be 32 bits when some of the other fields in the union
779 are 64. */
780 fprintf_filtered (outfile, "0x%lx\n", SYMBOL_VALUE (p));
781 p++;
782 }
783 }
784
785 void
786 maintenance_print_msymbols (args, from_tty)
787 char *args;
788 int from_tty;
789 {
790 char **argv;
791 GDB_FILE *outfile;
792 struct cleanup *cleanups;
793 char *filename = DEV_TTY;
794 char *symname = NULL;
795 struct objfile *objfile;
796
797 dont_repeat ();
798
799 if (args == NULL)
800 {
801 error ("print-msymbols takes an output file name and optional symbol file name");
802 }
803 else if ((argv = buildargv (args)) == NULL)
804 {
805 nomem (0);
806 }
807 cleanups = make_cleanup (freeargv, argv);
808
809 if (argv[0] != NULL)
810 {
811 filename = argv[0];
812 /* If a second arg is supplied, it is a source file name to match on */
813 if (argv[1] != NULL)
814 {
815 symname = argv[1];
816 }
817 }
818
819 filename = tilde_expand (filename);
820 make_cleanup (free, filename);
821
822 outfile = gdb_fopen (filename, FOPEN_WT);
823 if (outfile == 0)
824 perror_with_name (filename);
825 make_cleanup (fclose, outfile);
826
827 immediate_quit++;
828 ALL_OBJFILES (objfile)
829 if (symname == NULL || (STREQ (symname, objfile -> name)))
830 dump_msymbols (objfile, outfile);
831 immediate_quit--;
832 fprintf_filtered (outfile, "\n\n");
833 do_cleanups (cleanups);
834 }
835
836 void
837 maintenance_print_objfiles (ignore, from_tty)
838 char *ignore;
839 int from_tty;
840 {
841 struct objfile *objfile;
842
843 dont_repeat ();
844
845 immediate_quit++;
846 ALL_OBJFILES (objfile)
847 dump_objfile (objfile);
848 immediate_quit--;
849 }
850
851 /* Check consistency of psymtabs and symtabs. */
852
853 void
854 maintenance_check_symtabs (ignore, from_tty)
855 char *ignore;
856 int from_tty;
857 {
858 register struct symbol *sym;
859 register struct partial_symbol *psym;
860 register struct symtab *s = NULL;
861 register struct partial_symtab *ps;
862 struct blockvector *bv;
863 register struct objfile *objfile;
864 register struct block *b;
865 int length;
866
867 ALL_PSYMTABS (objfile, ps)
868 {
869 s = PSYMTAB_TO_SYMTAB(ps);
870 if (s == NULL)
871 continue;
872 bv = BLOCKVECTOR (s);
873 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
874 psym = ps->objfile->static_psymbols.list + ps->statics_offset;
875 length = ps->n_static_syms;
876 while (length--)
877 {
878 sym = lookup_block_symbol (b, SYMBOL_NAME (psym),
879 SYMBOL_NAMESPACE (psym));
880 if (!sym)
881 {
882 printf_filtered ("Static symbol `");
883 puts_filtered (SYMBOL_NAME (psym));
884 printf_filtered ("' only found in ");
885 puts_filtered (ps->filename);
886 printf_filtered (" psymtab\n");
887 }
888 psym++;
889 }
890 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
891 psym = ps->objfile->global_psymbols.list + ps->globals_offset;
892 length = ps->n_global_syms;
893 while (length--)
894 {
895 sym = lookup_block_symbol (b, SYMBOL_NAME (psym),
896 SYMBOL_NAMESPACE (psym));
897 if (!sym)
898 {
899 printf_filtered ("Global symbol `");
900 puts_filtered (SYMBOL_NAME (psym));
901 printf_filtered ("' only found in ");
902 puts_filtered (ps->filename);
903 printf_filtered (" psymtab\n");
904 }
905 psym++;
906 }
907 if (ps->texthigh < ps->textlow)
908 {
909 printf_filtered ("Psymtab ");
910 puts_filtered (ps->filename);
911 printf_filtered (" covers bad range ");
912 print_address_numeric (ps->textlow, 1, stdout);
913 printf_filtered (" - ");
914 print_address_numeric (ps->texthigh, 1, stdout);
915 printf_filtered ("\n");
916 continue;
917 }
918 if (ps->texthigh == 0)
919 continue;
920 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
921 {
922 printf_filtered ("Psymtab ");
923 puts_filtered (ps->filename);
924 printf_filtered (" covers ");
925 print_address_numeric (ps->textlow, 1, stdout);
926 printf_filtered (" - ");
927 print_address_numeric (ps->texthigh, 1, stdout);
928 printf_filtered (" but symtab covers only ");
929 print_address_numeric (BLOCK_START (b), 1, stdout);
930 printf_filtered (" - ");
931 print_address_numeric (BLOCK_END (b), 1, stdout);
932 printf_filtered ("\n");
933 }
934 }
935 }
936
937 \f
938 /* Return the nexting depth of a block within other blocks in its symtab. */
939
940 static int
941 block_depth (block)
942 struct block *block;
943 {
944 register int i = 0;
945 while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
946 {
947 i++;
948 }
949 return i;
950 }
951
952 #endif /* MAINTENANCE_CMDS */
953
954 \f
955 /* Increase the space allocated for LISTP, which is probably
956 global_psymbol_list or static_psymbol_list. This space will eventually
957 be freed in free_objfile(). */
958
959 void
960 extend_psymbol_list (listp, objfile)
961 register struct psymbol_allocation_list *listp;
962 struct objfile *objfile;
963 {
964 int new_size;
965 if (listp->size == 0)
966 {
967 new_size = 255;
968 listp->list = (struct partial_symbol *)
969 xmmalloc (objfile -> md, new_size * sizeof (struct partial_symbol));
970 }
971 else
972 {
973 new_size = listp->size * 2;
974 listp->list = (struct partial_symbol *)
975 xmrealloc (objfile -> md, (char *) listp->list,
976 new_size * sizeof (struct partial_symbol));
977 }
978 /* Next assumes we only went one over. Should be good if
979 program works correctly */
980 listp->next = listp->list + listp->size;
981 listp->size = new_size;
982 }
983
984
985 /* Do early runtime initializations. */
986 void
987 _initialize_symmisc ()
988 {
989 std_in = stdin;
990 std_out = stdout;
991 std_err = stderr;
992 }
This page took 0.049761 seconds and 4 git commands to generate.