1 /* Do various things to symbol tables (other than lookup), for GDB.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2002 Free Software Foundation,
7 This file is part of GDB.
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.
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.
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. */
30 #include "breakpoint.h"
32 #include "gdb_obstack.h"
36 #include "gdb_string.h"
39 #define DEV_TTY "/dev/tty"
42 /* Unfortunately for debugging, stderr is usually a macro. This is painful
43 when calling functions that take FILE *'s from the debugger.
44 So we make a variable which has the same value and which is accessible when
45 debugging GDB with itself. Because stdin et al need not be constants,
46 we initialize them in the _initialize_symmisc function at the bottom
52 /* Prototypes for local functions */
54 static void dump_symtab (struct objfile
*, struct symtab
*,
57 static void dump_psymtab (struct objfile
*, struct partial_symtab
*,
60 static void dump_msymbols (struct objfile
*, struct ui_file
*);
62 static void dump_objfile (struct objfile
*);
64 static int block_depth (struct block
*);
66 static void print_partial_symbols (struct partial_symbol
**, int,
67 char *, struct ui_file
*);
69 static void free_symtab_block (struct objfile
*, struct block
*);
71 void _initialize_symmisc (void);
73 struct print_symbol_args
75 struct symbol
*symbol
;
77 struct ui_file
*outfile
;
80 static int print_symbol (PTR
);
82 static void free_symtab_block (struct objfile
*, struct block
*);
85 /* Free a struct block <- B and all the symbols defined in that block. */
88 free_symtab_block (struct objfile
*objfile
, struct block
*b
)
91 struct symbol
*sym
, *next_sym
;
93 n
= BLOCK_BUCKETS (b
);
94 for (i
= 0; i
< n
; i
++)
96 for (sym
= BLOCK_BUCKET (b
, i
); sym
; sym
= next_sym
)
98 next_sym
= sym
->hash_next
;
99 xmfree (objfile
->md
, SYMBOL_NAME (sym
));
100 xmfree (objfile
->md
, (PTR
) sym
);
103 xmfree (objfile
->md
, (PTR
) b
);
106 /* Free all the storage associated with the struct symtab <- S.
107 Note that some symtabs have contents malloc'ed structure by structure,
108 while some have contents that all live inside one big block of memory,
109 and some share the contents of another symbol table and so you should
110 not free the contents on their behalf (except sometimes the linetable,
111 which maybe per symtab even when the rest is not).
112 It is s->free_code that says which alternative to use. */
115 free_symtab (register struct symtab
*s
)
118 register struct blockvector
*bv
;
120 switch (s
->free_code
)
123 /* All the contents are part of a big block of memory (an obstack),
124 and some other symtab is in charge of freeing that block.
125 Therefore, do nothing. */
129 /* Here all the contents were malloc'ed structure by structure
130 and must be freed that way. */
131 /* First free the blocks (and their symbols. */
132 bv
= BLOCKVECTOR (s
);
133 n
= BLOCKVECTOR_NBLOCKS (bv
);
134 for (i
= 0; i
< n
; i
++)
135 free_symtab_block (s
->objfile
, BLOCKVECTOR_BLOCK (bv
, i
));
136 /* Free the blockvector itself. */
137 xmfree (s
->objfile
->md
, (PTR
) bv
);
138 /* Also free the linetable. */
141 /* Everything will be freed either by our `free_ptr'
142 or by some other symtab, except for our linetable.
145 xmfree (s
->objfile
->md
, (PTR
) LINETABLE (s
));
149 /* If there is a single block of memory to free, free it. */
150 if (s
->free_ptr
!= NULL
)
151 xmfree (s
->objfile
->md
, s
->free_ptr
);
153 /* Free source-related stuff */
154 if (s
->line_charpos
!= NULL
)
155 xmfree (s
->objfile
->md
, (PTR
) s
->line_charpos
);
156 if (s
->fullname
!= NULL
)
157 xmfree (s
->objfile
->md
, s
->fullname
);
158 if (s
->debugformat
!= NULL
)
159 xmfree (s
->objfile
->md
, s
->debugformat
);
160 xmfree (s
->objfile
->md
, (PTR
) s
);
164 print_symbol_bcache_statistics (void)
166 struct objfile
*objfile
;
169 ALL_OBJFILES (objfile
)
171 printf_filtered ("Byte cache statistics for '%s':\n", objfile
->name
);
172 print_bcache_statistics (objfile
->psymbol_cache
, "partial symbol cache");
178 print_objfile_statistics (void)
180 struct objfile
*objfile
;
183 ALL_OBJFILES (objfile
)
185 printf_filtered ("Statistics for '%s':\n", objfile
->name
);
186 if (OBJSTAT (objfile
, n_stabs
) > 0)
187 printf_filtered (" Number of \"stab\" symbols read: %d\n",
188 OBJSTAT (objfile
, n_stabs
));
189 if (OBJSTAT (objfile
, n_minsyms
) > 0)
190 printf_filtered (" Number of \"minimal\" symbols read: %d\n",
191 OBJSTAT (objfile
, n_minsyms
));
192 if (OBJSTAT (objfile
, n_psyms
) > 0)
193 printf_filtered (" Number of \"partial\" symbols read: %d\n",
194 OBJSTAT (objfile
, n_psyms
));
195 if (OBJSTAT (objfile
, n_syms
) > 0)
196 printf_filtered (" Number of \"full\" symbols read: %d\n",
197 OBJSTAT (objfile
, n_syms
));
198 if (OBJSTAT (objfile
, n_types
) > 0)
199 printf_filtered (" Number of \"types\" defined: %d\n",
200 OBJSTAT (objfile
, n_types
));
201 if (OBJSTAT (objfile
, sz_strtab
) > 0)
202 printf_filtered (" Space used by a.out string tables: %d\n",
203 OBJSTAT (objfile
, sz_strtab
));
204 printf_filtered (" Total memory used for psymbol obstack: %d\n",
205 obstack_memory_used (&objfile
->psymbol_obstack
));
206 printf_filtered (" Total memory used for psymbol cache: %d\n",
207 bcache_memory_used (objfile
->psymbol_cache
));
208 printf_filtered (" Total memory used for macro cache: %d\n",
209 bcache_memory_used (objfile
->macro_cache
));
210 printf_filtered (" Total memory used for symbol obstack: %d\n",
211 obstack_memory_used (&objfile
->symbol_obstack
));
212 printf_filtered (" Total memory used for type obstack: %d\n",
213 obstack_memory_used (&objfile
->type_obstack
));
219 dump_objfile (struct objfile
*objfile
)
221 struct symtab
*symtab
;
222 struct partial_symtab
*psymtab
;
224 printf_filtered ("\nObject file %s: ", objfile
->name
);
225 printf_filtered ("Objfile at ");
226 gdb_print_host_address (objfile
, gdb_stdout
);
227 printf_filtered (", bfd at ");
228 gdb_print_host_address (objfile
->obfd
, gdb_stdout
);
229 printf_filtered (", %d minsyms\n\n",
230 objfile
->minimal_symbol_count
);
232 if (objfile
->psymtabs
)
234 printf_filtered ("Psymtabs:\n");
235 for (psymtab
= objfile
->psymtabs
;
237 psymtab
= psymtab
->next
)
239 printf_filtered ("%s at ",
241 gdb_print_host_address (psymtab
, gdb_stdout
);
242 printf_filtered (", ");
243 if (psymtab
->objfile
!= objfile
)
245 printf_filtered ("NOT ON CHAIN! ");
249 printf_filtered ("\n\n");
252 if (objfile
->symtabs
)
254 printf_filtered ("Symtabs:\n");
255 for (symtab
= objfile
->symtabs
;
257 symtab
= symtab
->next
)
259 printf_filtered ("%s at ", symtab
->filename
);
260 gdb_print_host_address (symtab
, gdb_stdout
);
261 printf_filtered (", ");
262 if (symtab
->objfile
!= objfile
)
264 printf_filtered ("NOT ON CHAIN! ");
268 printf_filtered ("\n\n");
272 /* Print minimal symbols from this objfile. */
275 dump_msymbols (struct objfile
*objfile
, struct ui_file
*outfile
)
277 struct minimal_symbol
*msymbol
;
281 fprintf_filtered (outfile
, "\nObject file %s:\n\n", objfile
->name
);
282 if (objfile
->minimal_symbol_count
== 0)
284 fprintf_filtered (outfile
, "No minimal symbols found.\n");
287 for (index
= 0, msymbol
= objfile
->msymbols
;
288 SYMBOL_NAME (msymbol
) != NULL
; msymbol
++, index
++)
290 switch (msymbol
->type
)
298 case mst_solib_trampoline
:
323 fprintf_filtered (outfile
, "[%2d] %c ", index
, ms_type
);
324 print_address_numeric (SYMBOL_VALUE_ADDRESS (msymbol
), 1, outfile
);
325 fprintf_filtered (outfile
, " %s", SYMBOL_NAME (msymbol
));
326 if (SYMBOL_BFD_SECTION (msymbol
))
327 fprintf_filtered (outfile
, " section %s",
328 bfd_section_name (objfile
->obfd
,
329 SYMBOL_BFD_SECTION (msymbol
)));
330 if (SYMBOL_DEMANGLED_NAME (msymbol
) != NULL
)
332 fprintf_filtered (outfile
, " %s", SYMBOL_DEMANGLED_NAME (msymbol
));
334 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
335 if (msymbol
->filename
)
336 fprintf_filtered (outfile
, " %s", msymbol
->filename
);
338 fputs_filtered ("\n", outfile
);
340 if (objfile
->minimal_symbol_count
!= index
)
342 warning ("internal error: minimal symbol count %d != %d",
343 objfile
->minimal_symbol_count
, index
);
345 fprintf_filtered (outfile
, "\n");
349 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
350 struct ui_file
*outfile
)
354 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
356 fprintf_filtered (outfile
, "(object ");
357 gdb_print_host_address (psymtab
, outfile
);
358 fprintf_filtered (outfile
, ")\n\n");
359 fprintf_unfiltered (outfile
, " Read from object file %s (",
361 gdb_print_host_address (objfile
, outfile
);
362 fprintf_unfiltered (outfile
, ")\n");
366 fprintf_filtered (outfile
,
367 " Full symtab was read (at ");
368 gdb_print_host_address (psymtab
->symtab
, outfile
);
369 fprintf_filtered (outfile
, " by function at ");
370 gdb_print_host_address ((PTR
) psymtab
->read_symtab
, outfile
);
371 fprintf_filtered (outfile
, ")\n");
374 fprintf_filtered (outfile
, " Relocate symbols by ");
375 for (i
= 0; i
< psymtab
->objfile
->num_sections
; ++i
)
378 fprintf_filtered (outfile
, ", ");
380 print_address_numeric (ANOFFSET (psymtab
->section_offsets
, i
),
384 fprintf_filtered (outfile
, "\n");
386 fprintf_filtered (outfile
, " Symbols cover text addresses ");
387 print_address_numeric (psymtab
->textlow
, 1, outfile
);
388 fprintf_filtered (outfile
, "-");
389 print_address_numeric (psymtab
->texthigh
, 1, outfile
);
390 fprintf_filtered (outfile
, "\n");
391 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
392 psymtab
->number_of_dependencies
);
393 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
395 fprintf_filtered (outfile
, " %d ", i
);
396 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
397 fprintf_filtered (outfile
, " %s\n",
398 psymtab
->dependencies
[i
]->filename
);
400 if (psymtab
->n_global_syms
> 0)
402 print_partial_symbols (objfile
->global_psymbols
.list
403 + psymtab
->globals_offset
,
404 psymtab
->n_global_syms
, "Global", outfile
);
406 if (psymtab
->n_static_syms
> 0)
408 print_partial_symbols (objfile
->static_psymbols
.list
409 + psymtab
->statics_offset
,
410 psymtab
->n_static_syms
, "Static", outfile
);
412 fprintf_filtered (outfile
, "\n");
416 dump_symtab (struct objfile
*objfile
, struct symtab
*symtab
,
417 struct ui_file
*outfile
)
421 register struct linetable
*l
;
422 struct blockvector
*bv
;
424 register struct block
*b
;
427 fprintf_filtered (outfile
, "\nSymtab for file %s\n", symtab
->filename
);
429 fprintf_filtered (outfile
, "Compilation directory is %s\n",
431 fprintf_filtered (outfile
, "Read from object file %s (", objfile
->name
);
432 gdb_print_host_address (objfile
, outfile
);
433 fprintf_filtered (outfile
, ")\n");
434 fprintf_filtered (outfile
, "Language: %s\n", language_str (symtab
->language
));
436 /* First print the line table. */
437 l
= LINETABLE (symtab
);
440 fprintf_filtered (outfile
, "\nLine table:\n\n");
442 for (i
= 0; i
< len
; i
++)
444 fprintf_filtered (outfile
, " line %d at ", l
->item
[i
].line
);
445 print_address_numeric (l
->item
[i
].pc
, 1, outfile
);
446 fprintf_filtered (outfile
, "\n");
449 /* Now print the block info, but only for primary symtabs since we will
450 print lots of duplicate info otherwise. */
453 fprintf_filtered (outfile
, "\nBlockvector:\n\n");
454 bv
= BLOCKVECTOR (symtab
);
455 len
= BLOCKVECTOR_NBLOCKS (bv
);
456 for (i
= 0; i
< len
; i
++)
458 b
= BLOCKVECTOR_BLOCK (bv
, i
);
459 depth
= block_depth (b
) * 2;
460 print_spaces (depth
, outfile
);
461 fprintf_filtered (outfile
, "block #%03d, object at ", i
);
462 gdb_print_host_address (b
, outfile
);
463 if (BLOCK_SUPERBLOCK (b
))
465 fprintf_filtered (outfile
, " under ");
466 gdb_print_host_address (BLOCK_SUPERBLOCK (b
), outfile
);
468 /* drow/2002-07-10: We could save the total symbols count
469 even if we're using a hashtable, but nothing else but this message
471 blen
= BLOCK_BUCKETS (b
);
472 if (BLOCK_HASHTABLE (b
))
473 fprintf_filtered (outfile
, ", %d buckets in ", blen
);
475 fprintf_filtered (outfile
, ", %d syms in ", blen
);
476 print_address_numeric (BLOCK_START (b
), 1, outfile
);
477 fprintf_filtered (outfile
, "..");
478 print_address_numeric (BLOCK_END (b
), 1, outfile
);
479 if (BLOCK_FUNCTION (b
))
481 fprintf_filtered (outfile
, ", function %s", SYMBOL_NAME (BLOCK_FUNCTION (b
)));
482 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b
)) != NULL
)
484 fprintf_filtered (outfile
, ", %s",
485 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b
)));
488 if (BLOCK_GCC_COMPILED (b
))
489 fprintf_filtered (outfile
, ", compiled with gcc%d", BLOCK_GCC_COMPILED (b
));
490 fprintf_filtered (outfile
, "\n");
491 /* Now print each symbol in this block (in no particular order, if
492 we're using a hashtable). */
493 ALL_BLOCK_SYMBOLS (b
, j
, sym
)
495 struct print_symbol_args s
;
499 catch_errors (print_symbol
, &s
, "Error printing symbol:\n",
503 fprintf_filtered (outfile
, "\n");
507 fprintf_filtered (outfile
, "\nBlockvector same as previous symtab\n\n");
512 maintenance_print_symbols (char *args
, int from_tty
)
515 struct ui_file
*outfile
;
516 struct cleanup
*cleanups
;
517 char *symname
= NULL
;
518 char *filename
= DEV_TTY
;
519 struct objfile
*objfile
;
527 Arguments missing: an output file name and an optional symbol file name");
529 else if ((argv
= buildargv (args
)) == NULL
)
533 cleanups
= make_cleanup_freeargv (argv
);
538 /* If a second arg is supplied, it is a source file name to match on */
545 filename
= tilde_expand (filename
);
546 make_cleanup (xfree
, filename
);
548 outfile
= gdb_fopen (filename
, FOPEN_WT
);
550 perror_with_name (filename
);
551 make_cleanup_ui_file_delete (outfile
);
554 ALL_SYMTABS (objfile
, s
)
555 if (symname
== NULL
|| (STREQ (symname
, s
->filename
)))
556 dump_symtab (objfile
, s
, outfile
);
558 do_cleanups (cleanups
);
561 /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
562 far to indent. ARGS is really a struct print_symbol_args *, but is
563 declared as char * to get it past catch_errors. Returns 0 for error,
567 print_symbol (PTR args
)
569 struct symbol
*symbol
= ((struct print_symbol_args
*) args
)->symbol
;
570 int depth
= ((struct print_symbol_args
*) args
)->depth
;
571 struct ui_file
*outfile
= ((struct print_symbol_args
*) args
)->outfile
;
573 print_spaces (depth
, outfile
);
574 if (SYMBOL_NAMESPACE (symbol
) == LABEL_NAMESPACE
)
576 fprintf_filtered (outfile
, "label %s at ", SYMBOL_SOURCE_NAME (symbol
));
577 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol
), 1, outfile
);
578 if (SYMBOL_BFD_SECTION (symbol
))
579 fprintf_filtered (outfile
, " section %s\n",
580 bfd_section_name (SYMBOL_BFD_SECTION (symbol
)->owner
,
581 SYMBOL_BFD_SECTION (symbol
)));
583 fprintf_filtered (outfile
, "\n");
586 if (SYMBOL_NAMESPACE (symbol
) == STRUCT_NAMESPACE
)
588 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol
)))
590 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
);
594 fprintf_filtered (outfile
, "%s %s = ",
595 (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_ENUM
597 : (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_STRUCT
598 ? "struct" : "union")),
599 SYMBOL_NAME (symbol
));
600 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
);
602 fprintf_filtered (outfile
, ";\n");
606 if (SYMBOL_CLASS (symbol
) == LOC_TYPEDEF
)
607 fprintf_filtered (outfile
, "typedef ");
608 if (SYMBOL_TYPE (symbol
))
610 /* Print details of types, except for enums where it's clutter. */
611 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), SYMBOL_SOURCE_NAME (symbol
),
613 TYPE_CODE (SYMBOL_TYPE (symbol
)) != TYPE_CODE_ENUM
,
615 fprintf_filtered (outfile
, "; ");
618 fprintf_filtered (outfile
, "%s ", SYMBOL_SOURCE_NAME (symbol
));
620 switch (SYMBOL_CLASS (symbol
))
623 fprintf_filtered (outfile
, "const %ld (0x%lx)",
624 SYMBOL_VALUE (symbol
),
625 SYMBOL_VALUE (symbol
));
628 case LOC_CONST_BYTES
:
631 struct type
*type
= check_typedef (SYMBOL_TYPE (symbol
));
632 fprintf_filtered (outfile
, "const %u hex bytes:",
634 for (i
= 0; i
< TYPE_LENGTH (type
); i
++)
635 fprintf_filtered (outfile
, " %02x",
636 (unsigned) SYMBOL_VALUE_BYTES (symbol
)[i
]);
641 fprintf_filtered (outfile
, "static at ");
642 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol
), 1, outfile
);
643 if (SYMBOL_BFD_SECTION (symbol
))
644 fprintf_filtered (outfile
, " section %s",
646 (SYMBOL_BFD_SECTION (symbol
)->owner
,
647 SYMBOL_BFD_SECTION (symbol
)));
651 fprintf_filtered (outfile
, "extern global at *(");
652 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol
), 1, outfile
);
653 fprintf_filtered (outfile
, "),");
657 fprintf_filtered (outfile
, "register %ld", SYMBOL_VALUE (symbol
));
661 fprintf_filtered (outfile
, "arg at offset 0x%lx",
662 SYMBOL_VALUE (symbol
));
666 fprintf_filtered (outfile
, "arg at offset 0x%lx from fp",
667 SYMBOL_VALUE (symbol
));
671 fprintf_filtered (outfile
, "reference arg at 0x%lx", SYMBOL_VALUE (symbol
));
675 fprintf_filtered (outfile
, "parameter register %ld", SYMBOL_VALUE (symbol
));
678 case LOC_REGPARM_ADDR
:
679 fprintf_filtered (outfile
, "address parameter register %ld", SYMBOL_VALUE (symbol
));
683 fprintf_filtered (outfile
, "local at offset 0x%lx",
684 SYMBOL_VALUE (symbol
));
688 fprintf_filtered (outfile
, "local at 0x%lx from register %d",
689 SYMBOL_VALUE (symbol
), SYMBOL_BASEREG (symbol
));
692 case LOC_BASEREG_ARG
:
693 fprintf_filtered (outfile
, "arg at 0x%lx from register %d",
694 SYMBOL_VALUE (symbol
), SYMBOL_BASEREG (symbol
));
701 fprintf_filtered (outfile
, "label at ");
702 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol
), 1, outfile
);
703 if (SYMBOL_BFD_SECTION (symbol
))
704 fprintf_filtered (outfile
, " section %s",
706 (SYMBOL_BFD_SECTION (symbol
)->owner
,
707 SYMBOL_BFD_SECTION (symbol
)));
711 fprintf_filtered (outfile
, "block object ");
712 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol
), outfile
);
713 fprintf_filtered (outfile
, ", ");
714 print_address_numeric (BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
)),
717 fprintf_filtered (outfile
, "..");
718 print_address_numeric (BLOCK_END (SYMBOL_BLOCK_VALUE (symbol
)),
721 if (SYMBOL_BFD_SECTION (symbol
))
722 fprintf_filtered (outfile
, " section %s",
724 (SYMBOL_BFD_SECTION (symbol
)->owner
,
725 SYMBOL_BFD_SECTION (symbol
)));
729 fprintf_filtered (outfile
, "unresolved");
732 case LOC_OPTIMIZED_OUT
:
733 fprintf_filtered (outfile
, "optimized out");
737 fprintf_filtered (outfile
, "botched symbol class %x",
738 SYMBOL_CLASS (symbol
));
742 fprintf_filtered (outfile
, "\n");
747 maintenance_print_psymbols (char *args
, int from_tty
)
750 struct ui_file
*outfile
;
751 struct cleanup
*cleanups
;
752 char *symname
= NULL
;
753 char *filename
= DEV_TTY
;
754 struct objfile
*objfile
;
755 struct partial_symtab
*ps
;
761 error ("print-psymbols takes an output file name and optional symbol file name");
763 else if ((argv
= buildargv (args
)) == NULL
)
767 cleanups
= make_cleanup_freeargv (argv
);
772 /* If a second arg is supplied, it is a source file name to match on */
779 filename
= tilde_expand (filename
);
780 make_cleanup (xfree
, filename
);
782 outfile
= gdb_fopen (filename
, FOPEN_WT
);
784 perror_with_name (filename
);
785 make_cleanup_ui_file_delete (outfile
);
788 ALL_PSYMTABS (objfile
, ps
)
789 if (symname
== NULL
|| (STREQ (symname
, ps
->filename
)))
790 dump_psymtab (objfile
, ps
, outfile
);
792 do_cleanups (cleanups
);
796 print_partial_symbols (struct partial_symbol
**p
, int count
, char *what
,
797 struct ui_file
*outfile
)
799 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
802 fprintf_filtered (outfile
, " `%s'", SYMBOL_NAME (*p
));
803 if (SYMBOL_DEMANGLED_NAME (*p
) != NULL
)
805 fprintf_filtered (outfile
, " `%s'", SYMBOL_DEMANGLED_NAME (*p
));
807 fputs_filtered (", ", outfile
);
808 switch (SYMBOL_NAMESPACE (*p
))
810 case UNDEF_NAMESPACE
:
811 fputs_filtered ("undefined namespace, ", outfile
);
814 /* This is the usual thing -- don't print it */
816 case STRUCT_NAMESPACE
:
817 fputs_filtered ("struct namespace, ", outfile
);
819 case LABEL_NAMESPACE
:
820 fputs_filtered ("label namespace, ", outfile
);
823 fputs_filtered ("<invalid namespace>, ", outfile
);
826 switch (SYMBOL_CLASS (*p
))
829 fputs_filtered ("undefined", outfile
);
832 fputs_filtered ("constant int", outfile
);
835 fputs_filtered ("static", outfile
);
838 fputs_filtered ("extern global", outfile
);
841 fputs_filtered ("register", outfile
);
844 fputs_filtered ("pass by value", outfile
);
847 fputs_filtered ("pass by reference", outfile
);
850 fputs_filtered ("register parameter", outfile
);
852 case LOC_REGPARM_ADDR
:
853 fputs_filtered ("register address parameter", outfile
);
856 fputs_filtered ("stack parameter", outfile
);
859 fputs_filtered ("type", outfile
);
862 fputs_filtered ("label", outfile
);
865 fputs_filtered ("function", outfile
);
867 case LOC_CONST_BYTES
:
868 fputs_filtered ("constant bytes", outfile
);
871 fputs_filtered ("shuffled arg", outfile
);
874 fputs_filtered ("unresolved", outfile
);
876 case LOC_OPTIMIZED_OUT
:
877 fputs_filtered ("optimized out", outfile
);
880 fputs_filtered ("<invalid location>", outfile
);
883 fputs_filtered (", ", outfile
);
884 print_address_numeric (SYMBOL_VALUE_ADDRESS (*p
), 1, outfile
);
885 fprintf_filtered (outfile
, "\n");
891 maintenance_print_msymbols (char *args
, int from_tty
)
894 struct ui_file
*outfile
;
895 struct cleanup
*cleanups
;
896 char *filename
= DEV_TTY
;
897 char *symname
= NULL
;
898 struct objfile
*objfile
;
904 error ("print-msymbols takes an output file name and optional symbol file name");
906 else if ((argv
= buildargv (args
)) == NULL
)
910 cleanups
= make_cleanup_freeargv (argv
);
915 /* If a second arg is supplied, it is a source file name to match on */
922 filename
= tilde_expand (filename
);
923 make_cleanup (xfree
, filename
);
925 outfile
= gdb_fopen (filename
, FOPEN_WT
);
927 perror_with_name (filename
);
928 make_cleanup_ui_file_delete (outfile
);
931 ALL_OBJFILES (objfile
)
932 if (symname
== NULL
|| (STREQ (symname
, objfile
->name
)))
933 dump_msymbols (objfile
, outfile
);
935 fprintf_filtered (outfile
, "\n\n");
936 do_cleanups (cleanups
);
940 maintenance_print_objfiles (char *ignore
, int from_tty
)
942 struct objfile
*objfile
;
947 ALL_OBJFILES (objfile
)
948 dump_objfile (objfile
);
952 /* Check consistency of psymtabs and symtabs. */
955 maintenance_check_symtabs (char *ignore
, int from_tty
)
957 register struct symbol
*sym
;
958 register struct partial_symbol
**psym
;
959 register struct symtab
*s
= NULL
;
960 register struct partial_symtab
*ps
;
961 struct blockvector
*bv
;
962 register struct objfile
*objfile
;
963 register struct block
*b
;
966 ALL_PSYMTABS (objfile
, ps
)
968 s
= PSYMTAB_TO_SYMTAB (ps
);
971 bv
= BLOCKVECTOR (s
);
972 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
973 psym
= ps
->objfile
->static_psymbols
.list
+ ps
->statics_offset
;
974 length
= ps
->n_static_syms
;
977 sym
= lookup_block_symbol (b
, SYMBOL_NAME (*psym
),
978 NULL
, SYMBOL_NAMESPACE (*psym
));
981 printf_filtered ("Static symbol `");
982 puts_filtered (SYMBOL_NAME (*psym
));
983 printf_filtered ("' only found in ");
984 puts_filtered (ps
->filename
);
985 printf_filtered (" psymtab\n");
989 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
990 psym
= ps
->objfile
->global_psymbols
.list
+ ps
->globals_offset
;
991 length
= ps
->n_global_syms
;
994 sym
= lookup_block_symbol (b
, SYMBOL_NAME (*psym
),
995 NULL
, SYMBOL_NAMESPACE (*psym
));
998 printf_filtered ("Global symbol `");
999 puts_filtered (SYMBOL_NAME (*psym
));
1000 printf_filtered ("' only found in ");
1001 puts_filtered (ps
->filename
);
1002 printf_filtered (" psymtab\n");
1006 if (ps
->texthigh
< ps
->textlow
)
1008 printf_filtered ("Psymtab ");
1009 puts_filtered (ps
->filename
);
1010 printf_filtered (" covers bad range ");
1011 print_address_numeric (ps
->textlow
, 1, gdb_stdout
);
1012 printf_filtered (" - ");
1013 print_address_numeric (ps
->texthigh
, 1, gdb_stdout
);
1014 printf_filtered ("\n");
1017 if (ps
->texthigh
== 0)
1019 if (ps
->textlow
< BLOCK_START (b
) || ps
->texthigh
> BLOCK_END (b
))
1021 printf_filtered ("Psymtab ");
1022 puts_filtered (ps
->filename
);
1023 printf_filtered (" covers ");
1024 print_address_numeric (ps
->textlow
, 1, gdb_stdout
);
1025 printf_filtered (" - ");
1026 print_address_numeric (ps
->texthigh
, 1, gdb_stdout
);
1027 printf_filtered (" but symtab covers only ");
1028 print_address_numeric (BLOCK_START (b
), 1, gdb_stdout
);
1029 printf_filtered (" - ");
1030 print_address_numeric (BLOCK_END (b
), 1, gdb_stdout
);
1031 printf_filtered ("\n");
1037 /* Return the nexting depth of a block within other blocks in its symtab. */
1040 block_depth (struct block
*block
)
1043 while ((block
= BLOCK_SUPERBLOCK (block
)) != NULL
)
1051 /* Increase the space allocated for LISTP, which is probably
1052 global_psymbols or static_psymbols. This space will eventually
1053 be freed in free_objfile(). */
1056 extend_psymbol_list (register struct psymbol_allocation_list
*listp
,
1057 struct objfile
*objfile
)
1060 if (listp
->size
== 0)
1063 listp
->list
= (struct partial_symbol
**)
1064 xmmalloc (objfile
->md
, new_size
* sizeof (struct partial_symbol
*));
1068 new_size
= listp
->size
* 2;
1069 listp
->list
= (struct partial_symbol
**)
1070 xmrealloc (objfile
->md
, (char *) listp
->list
,
1071 new_size
* sizeof (struct partial_symbol
*));
1073 /* Next assumes we only went one over. Should be good if
1074 program works correctly */
1075 listp
->next
= listp
->list
+ listp
->size
;
1076 listp
->size
= new_size
;
1080 /* Do early runtime initializations. */
1082 _initialize_symmisc (void)
This page took 0.050741 seconds and 4 git commands to generate.