* configure.in, configure: Add `-ldl -lw' for Solaris linking.
[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, 1995, 1996
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 void
156 print_objfile_statistics ()
157 {
158 struct objfile *objfile;
159
160 immediate_quit++;
161 ALL_OBJFILES (objfile)
162 {
163 printf_filtered ("Statistics for '%s':\n", objfile -> name);
164 if (OBJSTAT (objfile, n_stabs) > 0)
165 printf_filtered (" Number of \"stab\" symbols read: %d\n",
166 OBJSTAT (objfile, n_stabs));
167 if (OBJSTAT (objfile, n_minsyms) > 0)
168 printf_filtered (" Number of \"minimal symbols read: %d\n",
169 OBJSTAT (objfile, n_minsyms));
170 if (OBJSTAT (objfile, n_psyms) > 0)
171 printf_filtered (" Number of \"partial symbols read: %d\n",
172 OBJSTAT (objfile, n_psyms));
173 if (OBJSTAT (objfile, n_syms) > 0)
174 printf_filtered (" Number of \"full symbols read: %d\n",
175 OBJSTAT (objfile, n_syms));
176 if (OBJSTAT (objfile, n_types) > 0)
177 printf_filtered (" Number of \"types defined: %d\n",
178 OBJSTAT (objfile, n_types));
179 if (OBJSTAT (objfile, sz_strtab) > 0)
180 printf_filtered (" Space used by a.out string tables: %d\n",
181 OBJSTAT (objfile, sz_strtab));
182 printf_filtered (" Total memory used for psymbol obstack: %d\n",
183 obstack_memory_used (&objfile -> psymbol_obstack));
184 printf_filtered (" Total memory used for symbol obstack: %d\n",
185 obstack_memory_used (&objfile -> symbol_obstack));
186 printf_filtered (" Total memory used for type obstack: %d\n",
187 obstack_memory_used (&objfile -> type_obstack));
188 }
189 immediate_quit--;
190 }
191
192 static void
193 dump_objfile (objfile)
194 struct objfile *objfile;
195 {
196 struct symtab *symtab;
197 struct partial_symtab *psymtab;
198
199 printf_filtered ("\nObject file %s: ", objfile -> name);
200 printf_filtered ("Objfile at ");
201 gdb_print_address (objfile, gdb_stdout);
202 printf_filtered (", bfd at ");
203 gdb_print_address (objfile->obfd, gdb_stdout);
204 printf_filtered (", %d minsyms\n\n",
205 objfile->minimal_symbol_count);
206
207 if (objfile -> psymtabs)
208 {
209 printf_filtered ("Psymtabs:\n");
210 for (psymtab = objfile -> psymtabs;
211 psymtab != NULL;
212 psymtab = psymtab -> next)
213 {
214 printf_filtered ("%s at ",
215 psymtab -> filename);
216 gdb_print_address (psymtab, gdb_stdout);
217 printf_filtered (", ");
218 if (psymtab -> objfile != objfile)
219 {
220 printf_filtered ("NOT ON CHAIN! ");
221 }
222 wrap_here (" ");
223 }
224 printf_filtered ("\n\n");
225 }
226
227 if (objfile -> symtabs)
228 {
229 printf_filtered ("Symtabs:\n");
230 for (symtab = objfile -> symtabs;
231 symtab != NULL;
232 symtab = symtab->next)
233 {
234 printf_filtered ("%s at ", symtab -> filename);
235 gdb_print_address (symtab, gdb_stdout);
236 printf_filtered (", ");
237 if (symtab -> objfile != objfile)
238 {
239 printf_filtered ("NOT ON CHAIN! ");
240 }
241 wrap_here (" ");
242 }
243 printf_filtered ("\n\n");
244 }
245 }
246
247 /* Print minimal symbols from this objfile. */
248
249 static void
250 dump_msymbols (objfile, outfile)
251 struct objfile *objfile;
252 GDB_FILE *outfile;
253 {
254 struct minimal_symbol *msymbol;
255 int index;
256 char ms_type;
257
258 fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile -> name);
259 if (objfile -> minimal_symbol_count == 0)
260 {
261 fprintf_filtered (outfile, "No minimal symbols found.\n");
262 return;
263 }
264 for (index = 0, msymbol = objfile -> msymbols;
265 SYMBOL_NAME (msymbol) != NULL; msymbol++, index++)
266 {
267 switch (msymbol -> type)
268 {
269 case mst_unknown:
270 ms_type = 'u';
271 break;
272 case mst_text:
273 ms_type = 'T';
274 break;
275 case mst_solib_trampoline:
276 ms_type = 'S';
277 break;
278 case mst_data:
279 ms_type = 'D';
280 break;
281 case mst_bss:
282 ms_type = 'B';
283 break;
284 case mst_abs:
285 ms_type = 'A';
286 break;
287 case mst_file_text:
288 ms_type = 't';
289 break;
290 case mst_file_data:
291 ms_type = 'd';
292 break;
293 case mst_file_bss:
294 ms_type = 'b';
295 break;
296 default:
297 ms_type = '?';
298 break;
299 }
300 fprintf_filtered (outfile, "[%2d] %c %#10lx %s", index, ms_type,
301 SYMBOL_VALUE_ADDRESS (msymbol), SYMBOL_NAME (msymbol));
302 if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
303 {
304 fprintf_filtered (outfile, " %s", SYMBOL_DEMANGLED_NAME (msymbol));
305 }
306 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
307 if (msymbol->filename)
308 fprintf_filtered (outfile, " %s", msymbol->filename);
309 #endif
310 fputs_filtered ("\n", outfile);
311 }
312 if (objfile -> minimal_symbol_count != index)
313 {
314 warning ("internal error: minimal symbol count %d != %d",
315 objfile -> minimal_symbol_count, index);
316 }
317 fprintf_filtered (outfile, "\n");
318 }
319
320 static void
321 dump_psymtab (objfile, psymtab, outfile)
322 struct objfile *objfile;
323 struct partial_symtab *psymtab;
324 GDB_FILE *outfile;
325 {
326 int i;
327
328 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
329 psymtab -> filename);
330 fprintf_filtered (outfile, "(object ");
331 gdb_print_address (psymtab, outfile);
332 fprintf_filtered (outfile, ")\n\n");
333 fprintf_unfiltered (outfile, " Read from object file %s (",
334 objfile -> name);
335 gdb_print_address (objfile, outfile);
336 fprintf_unfiltered (outfile, ")\n");
337
338 if (psymtab -> readin)
339 {
340 fprintf_filtered (outfile,
341 " Full symtab was read (at ");
342 gdb_print_address (psymtab->symtab, outfile);
343 fprintf_filtered (outfile, " by function at ");
344 gdb_print_address ((PTR)psymtab->read_symtab, outfile);
345 fprintf_filtered (outfile, ")\n");
346 }
347
348 fprintf_filtered (outfile, " Relocate symbols by ");
349 for (i = 0; i < psymtab->objfile->num_sections; ++i)
350 {
351 if (i != 0)
352 fprintf_filtered (outfile, ", ");
353 wrap_here (" ");
354 print_address_numeric (ANOFFSET (psymtab->section_offsets, i),
355 1,
356 outfile);
357 }
358 fprintf_filtered (outfile, "\n");
359
360 fprintf_filtered (outfile, " Symbols cover text addresses ");
361 print_address_numeric (psymtab->textlow, 1, outfile);
362 fprintf_filtered (outfile, "-");
363 print_address_numeric (psymtab->texthigh, 1, outfile);
364 fprintf_filtered (outfile, "\n");
365 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
366 psymtab -> number_of_dependencies);
367 for (i = 0; i < psymtab -> number_of_dependencies; i++)
368 {
369 fprintf_filtered (outfile, " %d ", i);
370 gdb_print_address (psymtab -> dependencies[i], outfile);
371 fprintf_filtered (outfile, " %s\n",
372 psymtab -> dependencies[i] -> filename);
373 }
374 if (psymtab -> n_global_syms > 0)
375 {
376 print_partial_symbol (objfile -> global_psymbols.list
377 + psymtab -> globals_offset,
378 psymtab -> n_global_syms, "Global", outfile);
379 }
380 if (psymtab -> n_static_syms > 0)
381 {
382 print_partial_symbol (objfile -> static_psymbols.list
383 + psymtab -> statics_offset,
384 psymtab -> n_static_syms, "Static", outfile);
385 }
386 fprintf_filtered (outfile, "\n");
387 }
388
389 static void
390 dump_symtab (objfile, symtab, outfile)
391 struct objfile *objfile;
392 struct symtab *symtab;
393 GDB_FILE *outfile;
394 {
395 register int i, j;
396 int len, blen;
397 register struct linetable *l;
398 struct blockvector *bv;
399 register struct block *b;
400 int depth;
401
402 fprintf_filtered (outfile, "\nSymtab for file %s\n", symtab->filename);
403 fprintf_filtered (outfile, "Read from object file %s (", objfile->name);
404 gdb_print_address (objfile, outfile);
405 fprintf_filtered (outfile, ")\n");
406 fprintf_filtered (outfile, "Language: %s\n", language_str (symtab -> language));
407
408 /* First print the line table. */
409 l = LINETABLE (symtab);
410 if (l)
411 {
412 fprintf_filtered (outfile, "\nLine table:\n\n");
413 len = l->nitems;
414 for (i = 0; i < len; i++)
415 {
416 fprintf_filtered (outfile, " line %d at ", l->item[i].line);
417 print_address_numeric (l->item[i].pc, 1, outfile);
418 fprintf_filtered (outfile, "\n");
419 }
420 }
421 /* Now print the block info. */
422 fprintf_filtered (outfile, "\nBlockvector:\n\n");
423 bv = BLOCKVECTOR (symtab);
424 len = BLOCKVECTOR_NBLOCKS (bv);
425 for (i = 0; i < len; i++)
426 {
427 b = BLOCKVECTOR_BLOCK (bv, i);
428 depth = block_depth (b) * 2;
429 print_spaces (depth, outfile);
430 fprintf_filtered (outfile, "block #%03d (object ", i);
431 gdb_print_address (b, outfile);
432 fprintf_filtered (outfile, ") ");
433 fprintf_filtered (outfile, "[");
434 print_address_numeric (BLOCK_START (b), 1, outfile);
435 fprintf_filtered (outfile, "..");
436 print_address_numeric (BLOCK_END (b), 1, outfile);
437 fprintf_filtered (outfile, "]");
438 if (BLOCK_SUPERBLOCK (b))
439 {
440 fprintf_filtered (outfile, " (under ");
441 gdb_print_address (BLOCK_SUPERBLOCK (b), outfile);
442 fprintf_filtered (outfile, ")");
443 }
444 if (BLOCK_FUNCTION (b))
445 {
446 fprintf_filtered (outfile, " %s", SYMBOL_NAME (BLOCK_FUNCTION (b)));
447 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
448 {
449 fprintf_filtered (outfile, " %s",
450 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
451 }
452 }
453 if (BLOCK_GCC_COMPILED(b))
454 fprintf_filtered (outfile, " gcc%d compiled", BLOCK_GCC_COMPILED(b));
455 fprintf_filtered (outfile, "\n");
456 blen = BLOCK_NSYMS (b);
457 for (j = 0; j < blen; j++)
458 {
459 struct print_symbol_args s;
460 s.symbol = BLOCK_SYM (b, j);
461 s.depth = depth + 1;
462 s.outfile = outfile;
463 catch_errors (print_symbol, &s, "Error printing symbol:\n",
464 RETURN_MASK_ERROR);
465 }
466 }
467 fprintf_filtered (outfile, "\n");
468 }
469
470 void
471 maintenance_print_symbols (args, from_tty)
472 char *args;
473 int from_tty;
474 {
475 char **argv;
476 GDB_FILE *outfile;
477 struct cleanup *cleanups;
478 char *symname = NULL;
479 char *filename = DEV_TTY;
480 struct objfile *objfile;
481 struct symtab *s;
482
483 dont_repeat ();
484
485 if (args == NULL)
486 {
487 error ("\
488 Arguments missing: an output file name and an optional symbol file name");
489 }
490 else if ((argv = buildargv (args)) == NULL)
491 {
492 nomem (0);
493 }
494 cleanups = make_cleanup (freeargv, (char *) argv);
495
496 if (argv[0] != NULL)
497 {
498 filename = argv[0];
499 /* If a second arg is supplied, it is a source file name to match on */
500 if (argv[1] != NULL)
501 {
502 symname = argv[1];
503 }
504 }
505
506 filename = tilde_expand (filename);
507 make_cleanup (free, filename);
508
509 outfile = gdb_fopen (filename, FOPEN_WT);
510 if (outfile == 0)
511 perror_with_name (filename);
512 make_cleanup (fclose, (char *) outfile);
513
514 immediate_quit++;
515 ALL_SYMTABS (objfile, s)
516 if (symname == NULL || (STREQ (symname, s -> filename)))
517 dump_symtab (objfile, s, outfile);
518 immediate_quit--;
519 do_cleanups (cleanups);
520 }
521
522 /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
523 far to indent. ARGS is really a struct print_symbol_args *, but is
524 declared as char * to get it past catch_errors. Returns 0 for error,
525 1 for success. */
526
527 static int
528 print_symbol (args)
529 char *args;
530 {
531 struct symbol *symbol = ((struct print_symbol_args *)args)->symbol;
532 int depth = ((struct print_symbol_args *)args)->depth;
533 GDB_FILE *outfile = ((struct print_symbol_args *)args)->outfile;
534
535 print_spaces (depth, outfile);
536 if (SYMBOL_NAMESPACE (symbol) == LABEL_NAMESPACE)
537 {
538 fprintf_filtered (outfile, "label %s at ", SYMBOL_SOURCE_NAME (symbol));
539 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
540 fprintf_filtered (outfile, "\n");
541 return 1;
542 }
543 if (SYMBOL_NAMESPACE (symbol) == STRUCT_NAMESPACE)
544 {
545 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
546 {
547 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
548 }
549 else
550 {
551 fprintf_filtered (outfile, "%s %s = ",
552 (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
553 ? "enum"
554 : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
555 ? "struct" : "union")),
556 SYMBOL_NAME (symbol));
557 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
558 }
559 fprintf_filtered (outfile, ";\n");
560 }
561 else
562 {
563 if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
564 fprintf_filtered (outfile, "typedef ");
565 if (SYMBOL_TYPE (symbol))
566 {
567 /* Print details of types, except for enums where it's clutter. */
568 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_SOURCE_NAME (symbol),
569 outfile,
570 TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
571 depth);
572 fprintf_filtered (outfile, "; ");
573 }
574 else
575 fprintf_filtered (outfile, "%s ", SYMBOL_SOURCE_NAME (symbol));
576
577 switch (SYMBOL_CLASS (symbol))
578 {
579 case LOC_CONST:
580 fprintf_filtered (outfile, "const %ld (0x%lx),",
581 SYMBOL_VALUE (symbol),
582 SYMBOL_VALUE (symbol));
583 break;
584
585 case LOC_CONST_BYTES:
586 {
587 unsigned i;
588 struct type *type = check_typedef (SYMBOL_TYPE (symbol));
589 fprintf_filtered (outfile, "const %u hex bytes:",
590 TYPE_LENGTH (type));
591 for (i = 0; i < TYPE_LENGTH (type); i++)
592 fprintf_filtered (outfile, " %02x",
593 (unsigned)SYMBOL_VALUE_BYTES (symbol) [i]);
594 fprintf_filtered (outfile, ",");
595 }
596 break;
597
598 case LOC_STATIC:
599 fprintf_filtered (outfile, "static at ");
600 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1,outfile);
601 fprintf_filtered (outfile, ",");
602 break;
603
604 case LOC_REGISTER:
605 fprintf_filtered (outfile, "register %ld,", SYMBOL_VALUE (symbol));
606 break;
607
608 case LOC_ARG:
609 fprintf_filtered (outfile, "arg at offset 0x%lx,",
610 SYMBOL_VALUE (symbol));
611 break;
612
613 case LOC_LOCAL_ARG:
614 fprintf_filtered (outfile, "arg at offset 0x%lx from fp,",
615 SYMBOL_VALUE (symbol));
616 break;
617
618 case LOC_REF_ARG:
619 fprintf_filtered (outfile, "reference arg at 0x%lx,", SYMBOL_VALUE (symbol));
620 break;
621
622 case LOC_REGPARM:
623 fprintf_filtered (outfile, "parameter register %ld,", SYMBOL_VALUE (symbol));
624 break;
625
626 case LOC_REGPARM_ADDR:
627 fprintf_filtered (outfile, "address parameter register %ld,", SYMBOL_VALUE (symbol));
628 break;
629
630 case LOC_LOCAL:
631 fprintf_filtered (outfile, "local at offset 0x%lx,",
632 SYMBOL_VALUE (symbol));
633 break;
634
635 case LOC_BASEREG:
636 fprintf_filtered (outfile, "local at 0x%lx from register %d",
637 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
638 break;
639
640 case LOC_BASEREG_ARG:
641 fprintf_filtered (outfile, "arg at 0x%lx from register %d,",
642 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
643 break;
644
645 case LOC_TYPEDEF:
646 break;
647
648 case LOC_LABEL:
649 fprintf_filtered (outfile, "label at ");
650 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
651 break;
652
653 case LOC_BLOCK:
654 fprintf_filtered (outfile, "block (object ");
655 gdb_print_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
656 fprintf_filtered (outfile, ") starting at ");
657 print_address_numeric (BLOCK_START (SYMBOL_BLOCK_VALUE (symbol)),
658 1,
659 outfile);
660 fprintf_filtered (outfile, ",");
661 break;
662
663 case LOC_UNRESOLVED:
664 fprintf_filtered (outfile, "unresolved");
665 break;
666
667 case LOC_OPTIMIZED_OUT:
668 fprintf_filtered (outfile, "optimized out");
669 break;
670
671 default:
672 fprintf_filtered (outfile, "botched symbol class %x",
673 SYMBOL_CLASS (symbol));
674 break;
675 }
676 }
677 fprintf_filtered (outfile, "\n");
678 return 1;
679 }
680
681 void
682 maintenance_print_psymbols (args, from_tty)
683 char *args;
684 int from_tty;
685 {
686 char **argv;
687 GDB_FILE *outfile;
688 struct cleanup *cleanups;
689 char *symname = NULL;
690 char *filename = DEV_TTY;
691 struct objfile *objfile;
692 struct partial_symtab *ps;
693
694 dont_repeat ();
695
696 if (args == NULL)
697 {
698 error ("print-psymbols takes an output file name and optional symbol file name");
699 }
700 else if ((argv = buildargv (args)) == NULL)
701 {
702 nomem (0);
703 }
704 cleanups = make_cleanup (freeargv, (char *) argv);
705
706 if (argv[0] != NULL)
707 {
708 filename = argv[0];
709 /* If a second arg is supplied, it is a source file name to match on */
710 if (argv[1] != NULL)
711 {
712 symname = argv[1];
713 }
714 }
715
716 filename = tilde_expand (filename);
717 make_cleanup (free, filename);
718
719 outfile = gdb_fopen (filename, FOPEN_WT);
720 if (outfile == 0)
721 perror_with_name (filename);
722 make_cleanup (fclose, outfile);
723
724 immediate_quit++;
725 ALL_PSYMTABS (objfile, ps)
726 if (symname == NULL || (STREQ (symname, ps -> filename)))
727 dump_psymtab (objfile, ps, outfile);
728 immediate_quit--;
729 do_cleanups (cleanups);
730 }
731
732 static void
733 print_partial_symbol (p, count, what, outfile)
734 struct partial_symbol *p;
735 int count;
736 char *what;
737 GDB_FILE *outfile;
738 {
739
740 fprintf_filtered (outfile, " %s partial symbols:\n", what);
741 while (count-- > 0)
742 {
743 fprintf_filtered (outfile, " `%s'", SYMBOL_NAME(p));
744 if (SYMBOL_DEMANGLED_NAME (p) != NULL)
745 {
746 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (p));
747 }
748 fputs_filtered (", ", outfile);
749 switch (SYMBOL_NAMESPACE (p))
750 {
751 case UNDEF_NAMESPACE:
752 fputs_filtered ("undefined namespace, ", outfile);
753 break;
754 case VAR_NAMESPACE:
755 /* This is the usual thing -- don't print it */
756 break;
757 case STRUCT_NAMESPACE:
758 fputs_filtered ("struct namespace, ", outfile);
759 break;
760 case LABEL_NAMESPACE:
761 fputs_filtered ("label namespace, ", outfile);
762 break;
763 default:
764 fputs_filtered ("<invalid namespace>, ", outfile);
765 break;
766 }
767 switch (SYMBOL_CLASS (p))
768 {
769 case LOC_UNDEF:
770 fputs_filtered ("undefined", outfile);
771 break;
772 case LOC_CONST:
773 fputs_filtered ("constant int", outfile);
774 break;
775 case LOC_STATIC:
776 fputs_filtered ("static", outfile);
777 break;
778 case LOC_REGISTER:
779 fputs_filtered ("register", outfile);
780 break;
781 case LOC_ARG:
782 fputs_filtered ("pass by value", outfile);
783 break;
784 case LOC_REF_ARG:
785 fputs_filtered ("pass by reference", outfile);
786 break;
787 case LOC_REGPARM:
788 fputs_filtered ("register parameter", outfile);
789 break;
790 case LOC_REGPARM_ADDR:
791 fputs_filtered ("register address parameter", outfile);
792 break;
793 case LOC_LOCAL:
794 fputs_filtered ("stack parameter", outfile);
795 break;
796 case LOC_TYPEDEF:
797 fputs_filtered ("type", outfile);
798 break;
799 case LOC_LABEL:
800 fputs_filtered ("label", outfile);
801 break;
802 case LOC_BLOCK:
803 fputs_filtered ("function", outfile);
804 break;
805 case LOC_CONST_BYTES:
806 fputs_filtered ("constant bytes", outfile);
807 break;
808 case LOC_LOCAL_ARG:
809 fputs_filtered ("shuffled arg", outfile);
810 break;
811 case LOC_UNRESOLVED:
812 fputs_filtered ("unresolved", outfile);
813 break;
814 case LOC_OPTIMIZED_OUT:
815 fputs_filtered ("optimized out", outfile);
816 break;
817 default:
818 fputs_filtered ("<invalid location>", outfile);
819 break;
820 }
821 fputs_filtered (", ", outfile);
822 /* FIXME-32x64: Need to use SYMBOL_VALUE_ADDRESS, etc.; this
823 could be 32 bits when some of the other fields in the union
824 are 64. */
825 fprintf_filtered (outfile, "0x%lx\n", SYMBOL_VALUE (p));
826 p++;
827 }
828 }
829
830 void
831 maintenance_print_msymbols (args, from_tty)
832 char *args;
833 int from_tty;
834 {
835 char **argv;
836 GDB_FILE *outfile;
837 struct cleanup *cleanups;
838 char *filename = DEV_TTY;
839 char *symname = NULL;
840 struct objfile *objfile;
841
842 dont_repeat ();
843
844 if (args == NULL)
845 {
846 error ("print-msymbols takes an output file name and optional symbol file name");
847 }
848 else if ((argv = buildargv (args)) == NULL)
849 {
850 nomem (0);
851 }
852 cleanups = make_cleanup (freeargv, argv);
853
854 if (argv[0] != NULL)
855 {
856 filename = argv[0];
857 /* If a second arg is supplied, it is a source file name to match on */
858 if (argv[1] != NULL)
859 {
860 symname = argv[1];
861 }
862 }
863
864 filename = tilde_expand (filename);
865 make_cleanup (free, filename);
866
867 outfile = gdb_fopen (filename, FOPEN_WT);
868 if (outfile == 0)
869 perror_with_name (filename);
870 make_cleanup (fclose, outfile);
871
872 immediate_quit++;
873 ALL_OBJFILES (objfile)
874 if (symname == NULL || (STREQ (symname, objfile -> name)))
875 dump_msymbols (objfile, outfile);
876 immediate_quit--;
877 fprintf_filtered (outfile, "\n\n");
878 do_cleanups (cleanups);
879 }
880
881 void
882 maintenance_print_objfiles (ignore, from_tty)
883 char *ignore;
884 int from_tty;
885 {
886 struct objfile *objfile;
887
888 dont_repeat ();
889
890 immediate_quit++;
891 ALL_OBJFILES (objfile)
892 dump_objfile (objfile);
893 immediate_quit--;
894 }
895
896 /* Check consistency of psymtabs and symtabs. */
897
898 void
899 maintenance_check_symtabs (ignore, from_tty)
900 char *ignore;
901 int from_tty;
902 {
903 register struct symbol *sym;
904 register struct partial_symbol *psym;
905 register struct symtab *s = NULL;
906 register struct partial_symtab *ps;
907 struct blockvector *bv;
908 register struct objfile *objfile;
909 register struct block *b;
910 int length;
911
912 ALL_PSYMTABS (objfile, ps)
913 {
914 s = PSYMTAB_TO_SYMTAB(ps);
915 if (s == NULL)
916 continue;
917 bv = BLOCKVECTOR (s);
918 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
919 psym = ps->objfile->static_psymbols.list + ps->statics_offset;
920 length = ps->n_static_syms;
921 while (length--)
922 {
923 sym = lookup_block_symbol (b, SYMBOL_NAME (psym),
924 SYMBOL_NAMESPACE (psym));
925 if (!sym)
926 {
927 printf_filtered ("Static symbol `");
928 puts_filtered (SYMBOL_NAME (psym));
929 printf_filtered ("' only found in ");
930 puts_filtered (ps->filename);
931 printf_filtered (" psymtab\n");
932 }
933 psym++;
934 }
935 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
936 psym = ps->objfile->global_psymbols.list + ps->globals_offset;
937 length = ps->n_global_syms;
938 while (length--)
939 {
940 sym = lookup_block_symbol (b, SYMBOL_NAME (psym),
941 SYMBOL_NAMESPACE (psym));
942 if (!sym)
943 {
944 printf_filtered ("Global symbol `");
945 puts_filtered (SYMBOL_NAME (psym));
946 printf_filtered ("' only found in ");
947 puts_filtered (ps->filename);
948 printf_filtered (" psymtab\n");
949 }
950 psym++;
951 }
952 if (ps->texthigh < ps->textlow)
953 {
954 printf_filtered ("Psymtab ");
955 puts_filtered (ps->filename);
956 printf_filtered (" covers bad range ");
957 print_address_numeric (ps->textlow, 1, stdout);
958 printf_filtered (" - ");
959 print_address_numeric (ps->texthigh, 1, stdout);
960 printf_filtered ("\n");
961 continue;
962 }
963 if (ps->texthigh == 0)
964 continue;
965 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
966 {
967 printf_filtered ("Psymtab ");
968 puts_filtered (ps->filename);
969 printf_filtered (" covers ");
970 print_address_numeric (ps->textlow, 1, stdout);
971 printf_filtered (" - ");
972 print_address_numeric (ps->texthigh, 1, stdout);
973 printf_filtered (" but symtab covers only ");
974 print_address_numeric (BLOCK_START (b), 1, stdout);
975 printf_filtered (" - ");
976 print_address_numeric (BLOCK_END (b), 1, stdout);
977 printf_filtered ("\n");
978 }
979 }
980 }
981
982 \f
983 /* Return the nexting depth of a block within other blocks in its symtab. */
984
985 static int
986 block_depth (block)
987 struct block *block;
988 {
989 register int i = 0;
990 while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
991 {
992 i++;
993 }
994 return i;
995 }
996
997 #endif /* MAINTENANCE_CMDS */
998
999 \f
1000 /* Increase the space allocated for LISTP, which is probably
1001 global_psymbol_list or static_psymbol_list. This space will eventually
1002 be freed in free_objfile(). */
1003
1004 void
1005 extend_psymbol_list (listp, objfile)
1006 register struct psymbol_allocation_list *listp;
1007 struct objfile *objfile;
1008 {
1009 int new_size;
1010 if (listp->size == 0)
1011 {
1012 new_size = 255;
1013 listp->list = (struct partial_symbol *)
1014 xmmalloc (objfile -> md, new_size * sizeof (struct partial_symbol));
1015 }
1016 else
1017 {
1018 new_size = listp->size * 2;
1019 listp->list = (struct partial_symbol *)
1020 xmrealloc (objfile -> md, (char *) listp->list,
1021 new_size * sizeof (struct partial_symbol));
1022 }
1023 /* Next assumes we only went one over. Should be good if
1024 program works correctly */
1025 listp->next = listp->list + listp->size;
1026 listp->size = new_size;
1027 }
1028
1029
1030 /* Do early runtime initializations. */
1031 void
1032 _initialize_symmisc ()
1033 {
1034 std_in = stdin;
1035 std_out = stdout;
1036 std_err = stderr;
1037 }
This page took 0.04957 seconds and 4 git commands to generate.