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