1 /* Do various things to symbol tables (other than lookup), for GDB.
2 Copyright 1986, 1987, 1989, 1991-1996, 1998, 2000 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
27 #include "breakpoint.h"
33 #include "gdb_string.h"
36 #define DEV_TTY "/dev/tty"
39 /* Unfortunately for debugging, stderr is usually a macro. This is painful
40 when calling functions that take FILE *'s from the debugger.
41 So we make a variable which has the same value and which is accessible when
42 debugging GDB with itself. Because stdin et al need not be constants,
43 we initialize them in the _initialize_symmisc function at the bottom
49 /* Prototypes for local functions */
51 static void dump_symtab (struct objfile
*, struct symtab
*,
54 static void dump_psymtab (struct objfile
*, struct partial_symtab
*,
57 static void dump_msymbols (struct objfile
*, struct ui_file
*);
59 static void dump_objfile (struct objfile
*);
61 static int block_depth (struct block
*);
63 static void print_partial_symbols (struct partial_symbol
**, int,
64 char *, struct ui_file
*);
66 static void free_symtab_block (struct objfile
*, struct block
*);
68 void _initialize_symmisc (void);
70 struct print_symbol_args
72 struct symbol
*symbol
;
74 struct ui_file
*outfile
;
77 static int print_symbol (PTR
);
79 static void free_symtab_block (struct objfile
*, struct block
*);
82 /* Free a struct block <- B and all the symbols defined in that block. */
85 free_symtab_block (struct objfile
*objfile
, struct block
*b
)
89 for (i
= 0; i
< n
; i
++)
91 mfree (objfile
->md
, SYMBOL_NAME (BLOCK_SYM (b
, i
)));
92 mfree (objfile
->md
, (PTR
) BLOCK_SYM (b
, i
));
94 mfree (objfile
->md
, (PTR
) b
);
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. */
106 free_symtab (register struct symtab
*s
)
109 register struct blockvector
*bv
;
111 switch (s
->free_code
)
114 /* All the contents are part of a big block of memory (an obstack),
115 and some other symtab is in charge of freeing that block.
116 Therefore, do nothing. */
120 /* Here all the contents were malloc'ed structure by structure
121 and must be freed that way. */
122 /* First free the blocks (and their symbols. */
123 bv
= BLOCKVECTOR (s
);
124 n
= BLOCKVECTOR_NBLOCKS (bv
);
125 for (i
= 0; i
< n
; i
++)
126 free_symtab_block (s
->objfile
, BLOCKVECTOR_BLOCK (bv
, i
));
127 /* Free the blockvector itself. */
128 mfree (s
->objfile
->md
, (PTR
) bv
);
129 /* Also free the linetable. */
132 /* Everything will be freed either by our `free_ptr'
133 or by some other symtab, except for our linetable.
136 mfree (s
->objfile
->md
, (PTR
) LINETABLE (s
));
140 /* If there is a single block of memory to free, free it. */
141 if (s
->free_ptr
!= NULL
)
142 mfree (s
->objfile
->md
, s
->free_ptr
);
144 /* Free source-related stuff */
145 if (s
->line_charpos
!= NULL
)
146 mfree (s
->objfile
->md
, (PTR
) s
->line_charpos
);
147 if (s
->fullname
!= NULL
)
148 mfree (s
->objfile
->md
, s
->fullname
);
149 if (s
->debugformat
!= NULL
)
150 mfree (s
->objfile
->md
, s
->debugformat
);
151 mfree (s
->objfile
->md
, (PTR
) s
);
155 print_symbol_bcache_statistics (void)
157 struct objfile
*objfile
;
160 ALL_OBJFILES (objfile
)
162 printf_filtered ("Byte cache statistics for '%s':\n", objfile
->name
);
163 print_bcache_statistics (&objfile
->psymbol_cache
, "partial symbol cache");
169 print_objfile_statistics (void)
171 struct objfile
*objfile
;
174 ALL_OBJFILES (objfile
)
176 printf_filtered ("Statistics for '%s':\n", objfile
->name
);
177 if (OBJSTAT (objfile
, n_stabs
) > 0)
178 printf_filtered (" Number of \"stab\" symbols read: %d\n",
179 OBJSTAT (objfile
, n_stabs
));
180 if (OBJSTAT (objfile
, n_minsyms
) > 0)
181 printf_filtered (" Number of \"minimal\" symbols read: %d\n",
182 OBJSTAT (objfile
, n_minsyms
));
183 if (OBJSTAT (objfile
, n_psyms
) > 0)
184 printf_filtered (" Number of \"partial\" symbols read: %d\n",
185 OBJSTAT (objfile
, n_psyms
));
186 if (OBJSTAT (objfile
, n_syms
) > 0)
187 printf_filtered (" Number of \"full\" symbols read: %d\n",
188 OBJSTAT (objfile
, n_syms
));
189 if (OBJSTAT (objfile
, n_types
) > 0)
190 printf_filtered (" Number of \"types\" defined: %d\n",
191 OBJSTAT (objfile
, n_types
));
192 if (OBJSTAT (objfile
, sz_strtab
) > 0)
193 printf_filtered (" Space used by a.out string tables: %d\n",
194 OBJSTAT (objfile
, sz_strtab
));
195 printf_filtered (" Total memory used for psymbol obstack: %d\n",
196 obstack_memory_used (&objfile
->psymbol_obstack
));
197 printf_filtered (" Total memory used for psymbol cache: %d\n",
198 obstack_memory_used (&objfile
->psymbol_cache
.cache
));
199 printf_filtered (" Total memory used for symbol obstack: %d\n",
200 obstack_memory_used (&objfile
->symbol_obstack
));
201 printf_filtered (" Total memory used for type obstack: %d\n",
202 obstack_memory_used (&objfile
->type_obstack
));
208 dump_objfile (struct objfile
*objfile
)
210 struct symtab
*symtab
;
211 struct partial_symtab
*psymtab
;
213 printf_filtered ("\nObject file %s: ", objfile
->name
);
214 printf_filtered ("Objfile at ");
215 gdb_print_host_address (objfile
, gdb_stdout
);
216 printf_filtered (", bfd at ");
217 gdb_print_host_address (objfile
->obfd
, gdb_stdout
);
218 printf_filtered (", %d minsyms\n\n",
219 objfile
->minimal_symbol_count
);
221 if (objfile
->psymtabs
)
223 printf_filtered ("Psymtabs:\n");
224 for (psymtab
= objfile
->psymtabs
;
226 psymtab
= psymtab
->next
)
228 printf_filtered ("%s at ",
230 gdb_print_host_address (psymtab
, gdb_stdout
);
231 printf_filtered (", ");
232 if (psymtab
->objfile
!= objfile
)
234 printf_filtered ("NOT ON CHAIN! ");
238 printf_filtered ("\n\n");
241 if (objfile
->symtabs
)
243 printf_filtered ("Symtabs:\n");
244 for (symtab
= objfile
->symtabs
;
246 symtab
= symtab
->next
)
248 printf_filtered ("%s at ", symtab
->filename
);
249 gdb_print_host_address (symtab
, gdb_stdout
);
250 printf_filtered (", ");
251 if (symtab
->objfile
!= objfile
)
253 printf_filtered ("NOT ON CHAIN! ");
257 printf_filtered ("\n\n");
261 /* Print minimal symbols from this objfile. */
264 dump_msymbols (struct objfile
*objfile
, struct ui_file
*outfile
)
266 struct minimal_symbol
*msymbol
;
270 fprintf_filtered (outfile
, "\nObject file %s:\n\n", objfile
->name
);
271 if (objfile
->minimal_symbol_count
== 0)
273 fprintf_filtered (outfile
, "No minimal symbols found.\n");
276 for (index
= 0, msymbol
= objfile
->msymbols
;
277 SYMBOL_NAME (msymbol
) != NULL
; msymbol
++, index
++)
279 switch (msymbol
->type
)
287 case mst_solib_trampoline
:
312 fprintf_filtered (outfile
, "[%2d] %c ", index
, ms_type
);
313 print_address_numeric (SYMBOL_VALUE_ADDRESS (msymbol
), 1, outfile
);
314 fprintf_filtered (outfile
, " %s", SYMBOL_NAME (msymbol
));
315 if (SYMBOL_BFD_SECTION (msymbol
))
316 fprintf_filtered (outfile
, " section %s",
317 bfd_section_name (objfile
->obfd
,
318 SYMBOL_BFD_SECTION (msymbol
)));
319 if (SYMBOL_DEMANGLED_NAME (msymbol
) != NULL
)
321 fprintf_filtered (outfile
, " %s", SYMBOL_DEMANGLED_NAME (msymbol
));
323 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
324 if (msymbol
->filename
)
325 fprintf_filtered (outfile
, " %s", msymbol
->filename
);
327 fputs_filtered ("\n", outfile
);
329 if (objfile
->minimal_symbol_count
!= index
)
331 warning ("internal error: minimal symbol count %d != %d",
332 objfile
->minimal_symbol_count
, index
);
334 fprintf_filtered (outfile
, "\n");
338 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
339 struct ui_file
*outfile
)
343 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
345 fprintf_filtered (outfile
, "(object ");
346 gdb_print_host_address (psymtab
, outfile
);
347 fprintf_filtered (outfile
, ")\n\n");
348 fprintf_unfiltered (outfile
, " Read from object file %s (",
350 gdb_print_host_address (objfile
, outfile
);
351 fprintf_unfiltered (outfile
, ")\n");
355 fprintf_filtered (outfile
,
356 " Full symtab was read (at ");
357 gdb_print_host_address (psymtab
->symtab
, outfile
);
358 fprintf_filtered (outfile
, " by function at ");
359 gdb_print_host_address ((PTR
) psymtab
->read_symtab
, outfile
);
360 fprintf_filtered (outfile
, ")\n");
363 fprintf_filtered (outfile
, " Relocate symbols by ");
364 for (i
= 0; i
< psymtab
->objfile
->num_sections
; ++i
)
367 fprintf_filtered (outfile
, ", ");
369 print_address_numeric (ANOFFSET (psymtab
->section_offsets
, i
),
373 fprintf_filtered (outfile
, "\n");
375 fprintf_filtered (outfile
, " Symbols cover text addresses ");
376 print_address_numeric (psymtab
->textlow
, 1, outfile
);
377 fprintf_filtered (outfile
, "-");
378 print_address_numeric (psymtab
->texthigh
, 1, outfile
);
379 fprintf_filtered (outfile
, "\n");
380 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
381 psymtab
->number_of_dependencies
);
382 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
384 fprintf_filtered (outfile
, " %d ", i
);
385 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
386 fprintf_filtered (outfile
, " %s\n",
387 psymtab
->dependencies
[i
]->filename
);
389 if (psymtab
->n_global_syms
> 0)
391 print_partial_symbols (objfile
->global_psymbols
.list
392 + psymtab
->globals_offset
,
393 psymtab
->n_global_syms
, "Global", outfile
);
395 if (psymtab
->n_static_syms
> 0)
397 print_partial_symbols (objfile
->static_psymbols
.list
398 + psymtab
->statics_offset
,
399 psymtab
->n_static_syms
, "Static", outfile
);
401 fprintf_filtered (outfile
, "\n");
405 dump_symtab (struct objfile
*objfile
, struct symtab
*symtab
,
406 struct ui_file
*outfile
)
410 register struct linetable
*l
;
411 struct blockvector
*bv
;
412 register struct block
*b
;
415 fprintf_filtered (outfile
, "\nSymtab for file %s\n", symtab
->filename
);
417 fprintf_filtered (outfile
, "Compilation directory is %s\n",
419 fprintf_filtered (outfile
, "Read from object file %s (", objfile
->name
);
420 gdb_print_host_address (objfile
, outfile
);
421 fprintf_filtered (outfile
, ")\n");
422 fprintf_filtered (outfile
, "Language: %s\n", language_str (symtab
->language
));
424 /* First print the line table. */
425 l
= LINETABLE (symtab
);
428 fprintf_filtered (outfile
, "\nLine table:\n\n");
430 for (i
= 0; i
< len
; i
++)
432 fprintf_filtered (outfile
, " line %d at ", l
->item
[i
].line
);
433 print_address_numeric (l
->item
[i
].pc
, 1, outfile
);
434 fprintf_filtered (outfile
, "\n");
437 /* Now print the block info, but only for primary symtabs since we will
438 print lots of duplicate info otherwise. */
441 fprintf_filtered (outfile
, "\nBlockvector:\n\n");
442 bv
= BLOCKVECTOR (symtab
);
443 len
= BLOCKVECTOR_NBLOCKS (bv
);
444 for (i
= 0; i
< len
; i
++)
446 b
= BLOCKVECTOR_BLOCK (bv
, i
);
447 depth
= block_depth (b
) * 2;
448 print_spaces (depth
, outfile
);
449 fprintf_filtered (outfile
, "block #%03d, object at ", i
);
450 gdb_print_host_address (b
, outfile
);
451 if (BLOCK_SUPERBLOCK (b
))
453 fprintf_filtered (outfile
, " under ");
454 gdb_print_host_address (BLOCK_SUPERBLOCK (b
), outfile
);
456 blen
= BLOCK_NSYMS (b
);
457 fprintf_filtered (outfile
, ", %d syms in ", blen
);
458 print_address_numeric (BLOCK_START (b
), 1, outfile
);
459 fprintf_filtered (outfile
, "..");
460 print_address_numeric (BLOCK_END (b
), 1, outfile
);
461 if (BLOCK_FUNCTION (b
))
463 fprintf_filtered (outfile
, ", function %s", SYMBOL_NAME (BLOCK_FUNCTION (b
)));
464 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b
)) != NULL
)
466 fprintf_filtered (outfile
, ", %s",
467 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b
)));
470 if (BLOCK_GCC_COMPILED (b
))
471 fprintf_filtered (outfile
, ", compiled with gcc%d", BLOCK_GCC_COMPILED (b
));
472 fprintf_filtered (outfile
, "\n");
473 /* Now print each symbol in this block */
474 for (j
= 0; j
< blen
; j
++)
476 struct print_symbol_args s
;
477 s
.symbol
= BLOCK_SYM (b
, j
);
480 catch_errors (print_symbol
, &s
, "Error printing symbol:\n",
484 fprintf_filtered (outfile
, "\n");
488 fprintf_filtered (outfile
, "\nBlockvector same as previous symtab\n\n");
493 maintenance_print_symbols (char *args
, int from_tty
)
496 struct ui_file
*outfile
;
497 struct cleanup
*cleanups
;
498 char *symname
= NULL
;
499 char *filename
= DEV_TTY
;
500 struct objfile
*objfile
;
508 Arguments missing: an output file name and an optional symbol file name");
510 else if ((argv
= buildargv (args
)) == NULL
)
514 cleanups
= make_cleanup_freeargv (argv
);
519 /* If a second arg is supplied, it is a source file name to match on */
526 filename
= tilde_expand (filename
);
527 make_cleanup (xfree
, filename
);
529 outfile
= gdb_fopen (filename
, FOPEN_WT
);
531 perror_with_name (filename
);
532 make_cleanup_ui_file_delete (outfile
);
535 ALL_SYMTABS (objfile
, s
)
536 if (symname
== NULL
|| (STREQ (symname
, s
->filename
)))
537 dump_symtab (objfile
, s
, outfile
);
539 do_cleanups (cleanups
);
542 /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
543 far to indent. ARGS is really a struct print_symbol_args *, but is
544 declared as char * to get it past catch_errors. Returns 0 for error,
548 print_symbol (PTR args
)
550 struct symbol
*symbol
= ((struct print_symbol_args
*) args
)->symbol
;
551 int depth
= ((struct print_symbol_args
*) args
)->depth
;
552 struct ui_file
*outfile
= ((struct print_symbol_args
*) args
)->outfile
;
554 print_spaces (depth
, outfile
);
555 if (SYMBOL_NAMESPACE (symbol
) == LABEL_NAMESPACE
)
557 fprintf_filtered (outfile
, "label %s at ", SYMBOL_SOURCE_NAME (symbol
));
558 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol
), 1, outfile
);
559 if (SYMBOL_BFD_SECTION (symbol
))
560 fprintf_filtered (outfile
, " section %s\n",
561 bfd_section_name (SYMBOL_BFD_SECTION (symbol
)->owner
,
562 SYMBOL_BFD_SECTION (symbol
)));
564 fprintf_filtered (outfile
, "\n");
567 if (SYMBOL_NAMESPACE (symbol
) == STRUCT_NAMESPACE
)
569 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol
)))
571 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
);
575 fprintf_filtered (outfile
, "%s %s = ",
576 (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_ENUM
578 : (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_STRUCT
579 ? "struct" : "union")),
580 SYMBOL_NAME (symbol
));
581 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
);
583 fprintf_filtered (outfile
, ";\n");
587 if (SYMBOL_CLASS (symbol
) == LOC_TYPEDEF
)
588 fprintf_filtered (outfile
, "typedef ");
589 if (SYMBOL_TYPE (symbol
))
591 /* Print details of types, except for enums where it's clutter. */
592 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), SYMBOL_SOURCE_NAME (symbol
),
594 TYPE_CODE (SYMBOL_TYPE (symbol
)) != TYPE_CODE_ENUM
,
596 fprintf_filtered (outfile
, "; ");
599 fprintf_filtered (outfile
, "%s ", SYMBOL_SOURCE_NAME (symbol
));
601 switch (SYMBOL_CLASS (symbol
))
604 fprintf_filtered (outfile
, "const %ld (0x%lx)",
605 SYMBOL_VALUE (symbol
),
606 SYMBOL_VALUE (symbol
));
609 case LOC_CONST_BYTES
:
612 struct type
*type
= check_typedef (SYMBOL_TYPE (symbol
));
613 fprintf_filtered (outfile
, "const %u hex bytes:",
615 for (i
= 0; i
< TYPE_LENGTH (type
); i
++)
616 fprintf_filtered (outfile
, " %02x",
617 (unsigned) SYMBOL_VALUE_BYTES (symbol
)[i
]);
622 fprintf_filtered (outfile
, "static at ");
623 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol
), 1, outfile
);
624 if (SYMBOL_BFD_SECTION (symbol
))
625 fprintf_filtered (outfile
, " section %s",
627 (SYMBOL_BFD_SECTION (symbol
)->owner
,
628 SYMBOL_BFD_SECTION (symbol
)));
632 fprintf_filtered (outfile
, "extern global at *(");
633 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol
), 1, outfile
);
634 fprintf_filtered (outfile
, "),");
638 fprintf_filtered (outfile
, "register %ld", SYMBOL_VALUE (symbol
));
642 fprintf_filtered (outfile
, "arg at offset 0x%lx",
643 SYMBOL_VALUE (symbol
));
647 fprintf_filtered (outfile
, "arg at offset 0x%lx from fp",
648 SYMBOL_VALUE (symbol
));
652 fprintf_filtered (outfile
, "reference arg at 0x%lx", SYMBOL_VALUE (symbol
));
656 fprintf_filtered (outfile
, "parameter register %ld", SYMBOL_VALUE (symbol
));
659 case LOC_REGPARM_ADDR
:
660 fprintf_filtered (outfile
, "address parameter register %ld", SYMBOL_VALUE (symbol
));
664 fprintf_filtered (outfile
, "local at offset 0x%lx",
665 SYMBOL_VALUE (symbol
));
669 fprintf_filtered (outfile
, "local at 0x%lx from register %d",
670 SYMBOL_VALUE (symbol
), SYMBOL_BASEREG (symbol
));
673 case LOC_BASEREG_ARG
:
674 fprintf_filtered (outfile
, "arg at 0x%lx from register %d",
675 SYMBOL_VALUE (symbol
), SYMBOL_BASEREG (symbol
));
682 fprintf_filtered (outfile
, "label at ");
683 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol
), 1, outfile
);
684 if (SYMBOL_BFD_SECTION (symbol
))
685 fprintf_filtered (outfile
, " section %s",
687 (SYMBOL_BFD_SECTION (symbol
)->owner
,
688 SYMBOL_BFD_SECTION (symbol
)));
692 fprintf_filtered (outfile
, "block object ");
693 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol
), outfile
);
694 fprintf_filtered (outfile
, ", ");
695 print_address_numeric (BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
)),
698 fprintf_filtered (outfile
, "..");
699 print_address_numeric (BLOCK_END (SYMBOL_BLOCK_VALUE (symbol
)),
702 if (SYMBOL_BFD_SECTION (symbol
))
703 fprintf_filtered (outfile
, " section %s",
705 (SYMBOL_BFD_SECTION (symbol
)->owner
,
706 SYMBOL_BFD_SECTION (symbol
)));
710 fprintf_filtered (outfile
, "unresolved");
713 case LOC_OPTIMIZED_OUT
:
714 fprintf_filtered (outfile
, "optimized out");
718 fprintf_filtered (outfile
, "botched symbol class %x",
719 SYMBOL_CLASS (symbol
));
723 fprintf_filtered (outfile
, "\n");
728 maintenance_print_psymbols (char *args
, int from_tty
)
731 struct ui_file
*outfile
;
732 struct cleanup
*cleanups
;
733 char *symname
= NULL
;
734 char *filename
= DEV_TTY
;
735 struct objfile
*objfile
;
736 struct partial_symtab
*ps
;
742 error ("print-psymbols takes an output file name and optional symbol file name");
744 else if ((argv
= buildargv (args
)) == NULL
)
748 cleanups
= make_cleanup_freeargv (argv
);
753 /* If a second arg is supplied, it is a source file name to match on */
760 filename
= tilde_expand (filename
);
761 make_cleanup (xfree
, filename
);
763 outfile
= gdb_fopen (filename
, FOPEN_WT
);
765 perror_with_name (filename
);
766 make_cleanup_ui_file_delete (outfile
);
769 ALL_PSYMTABS (objfile
, ps
)
770 if (symname
== NULL
|| (STREQ (symname
, ps
->filename
)))
771 dump_psymtab (objfile
, ps
, outfile
);
773 do_cleanups (cleanups
);
777 print_partial_symbols (struct partial_symbol
**p
, int count
, char *what
,
778 struct ui_file
*outfile
)
780 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
783 fprintf_filtered (outfile
, " `%s'", SYMBOL_NAME (*p
));
784 if (SYMBOL_DEMANGLED_NAME (*p
) != NULL
)
786 fprintf_filtered (outfile
, " `%s'", SYMBOL_DEMANGLED_NAME (*p
));
788 fputs_filtered (", ", outfile
);
789 switch (SYMBOL_NAMESPACE (*p
))
791 case UNDEF_NAMESPACE
:
792 fputs_filtered ("undefined namespace, ", outfile
);
795 /* This is the usual thing -- don't print it */
797 case STRUCT_NAMESPACE
:
798 fputs_filtered ("struct namespace, ", outfile
);
800 case LABEL_NAMESPACE
:
801 fputs_filtered ("label namespace, ", outfile
);
804 fputs_filtered ("<invalid namespace>, ", outfile
);
807 switch (SYMBOL_CLASS (*p
))
810 fputs_filtered ("undefined", outfile
);
813 fputs_filtered ("constant int", outfile
);
816 fputs_filtered ("static", outfile
);
819 fputs_filtered ("extern global", outfile
);
822 fputs_filtered ("register", outfile
);
825 fputs_filtered ("pass by value", outfile
);
828 fputs_filtered ("pass by reference", outfile
);
831 fputs_filtered ("register parameter", outfile
);
833 case LOC_REGPARM_ADDR
:
834 fputs_filtered ("register address parameter", outfile
);
837 fputs_filtered ("stack parameter", outfile
);
840 fputs_filtered ("type", outfile
);
843 fputs_filtered ("label", outfile
);
846 fputs_filtered ("function", outfile
);
848 case LOC_CONST_BYTES
:
849 fputs_filtered ("constant bytes", outfile
);
852 fputs_filtered ("shuffled arg", outfile
);
855 fputs_filtered ("unresolved", outfile
);
857 case LOC_OPTIMIZED_OUT
:
858 fputs_filtered ("optimized out", outfile
);
861 fputs_filtered ("<invalid location>", outfile
);
864 fputs_filtered (", ", outfile
);
865 print_address_numeric (SYMBOL_VALUE_ADDRESS (*p
), 1, outfile
);
866 fprintf_filtered (outfile
, "\n");
872 maintenance_print_msymbols (char *args
, int from_tty
)
875 struct ui_file
*outfile
;
876 struct cleanup
*cleanups
;
877 char *filename
= DEV_TTY
;
878 char *symname
= NULL
;
879 struct objfile
*objfile
;
885 error ("print-msymbols takes an output file name and optional symbol file name");
887 else if ((argv
= buildargv (args
)) == NULL
)
891 cleanups
= make_cleanup_freeargv (argv
);
896 /* If a second arg is supplied, it is a source file name to match on */
903 filename
= tilde_expand (filename
);
904 make_cleanup (xfree
, filename
);
906 outfile
= gdb_fopen (filename
, FOPEN_WT
);
908 perror_with_name (filename
);
909 make_cleanup_ui_file_delete (outfile
);
912 ALL_OBJFILES (objfile
)
913 if (symname
== NULL
|| (STREQ (symname
, objfile
->name
)))
914 dump_msymbols (objfile
, outfile
);
916 fprintf_filtered (outfile
, "\n\n");
917 do_cleanups (cleanups
);
921 maintenance_print_objfiles (char *ignore
, int from_tty
)
923 struct objfile
*objfile
;
928 ALL_OBJFILES (objfile
)
929 dump_objfile (objfile
);
933 /* Check consistency of psymtabs and symtabs. */
936 maintenance_check_symtabs (char *ignore
, int from_tty
)
938 register struct symbol
*sym
;
939 register struct partial_symbol
**psym
;
940 register struct symtab
*s
= NULL
;
941 register struct partial_symtab
*ps
;
942 struct blockvector
*bv
;
943 register struct objfile
*objfile
;
944 register struct block
*b
;
947 ALL_PSYMTABS (objfile
, ps
)
949 s
= PSYMTAB_TO_SYMTAB (ps
);
952 bv
= BLOCKVECTOR (s
);
953 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
954 psym
= ps
->objfile
->static_psymbols
.list
+ ps
->statics_offset
;
955 length
= ps
->n_static_syms
;
958 sym
= lookup_block_symbol (b
, SYMBOL_NAME (*psym
),
959 SYMBOL_NAMESPACE (*psym
));
962 printf_filtered ("Static symbol `");
963 puts_filtered (SYMBOL_NAME (*psym
));
964 printf_filtered ("' only found in ");
965 puts_filtered (ps
->filename
);
966 printf_filtered (" psymtab\n");
970 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
971 psym
= ps
->objfile
->global_psymbols
.list
+ ps
->globals_offset
;
972 length
= ps
->n_global_syms
;
975 sym
= lookup_block_symbol (b
, SYMBOL_NAME (*psym
),
976 SYMBOL_NAMESPACE (*psym
));
979 printf_filtered ("Global symbol `");
980 puts_filtered (SYMBOL_NAME (*psym
));
981 printf_filtered ("' only found in ");
982 puts_filtered (ps
->filename
);
983 printf_filtered (" psymtab\n");
987 if (ps
->texthigh
< ps
->textlow
)
989 printf_filtered ("Psymtab ");
990 puts_filtered (ps
->filename
);
991 printf_filtered (" covers bad range ");
992 print_address_numeric (ps
->textlow
, 1, gdb_stdout
);
993 printf_filtered (" - ");
994 print_address_numeric (ps
->texthigh
, 1, gdb_stdout
);
995 printf_filtered ("\n");
998 if (ps
->texthigh
== 0)
1000 if (ps
->textlow
< BLOCK_START (b
) || ps
->texthigh
> BLOCK_END (b
))
1002 printf_filtered ("Psymtab ");
1003 puts_filtered (ps
->filename
);
1004 printf_filtered (" covers ");
1005 print_address_numeric (ps
->textlow
, 1, gdb_stdout
);
1006 printf_filtered (" - ");
1007 print_address_numeric (ps
->texthigh
, 1, gdb_stdout
);
1008 printf_filtered (" but symtab covers only ");
1009 print_address_numeric (BLOCK_START (b
), 1, gdb_stdout
);
1010 printf_filtered (" - ");
1011 print_address_numeric (BLOCK_END (b
), 1, gdb_stdout
);
1012 printf_filtered ("\n");
1018 /* Return the nexting depth of a block within other blocks in its symtab. */
1021 block_depth (struct block
*block
)
1024 while ((block
= BLOCK_SUPERBLOCK (block
)) != NULL
)
1032 /* Increase the space allocated for LISTP, which is probably
1033 global_psymbols or static_psymbols. This space will eventually
1034 be freed in free_objfile(). */
1037 extend_psymbol_list (register struct psymbol_allocation_list
*listp
,
1038 struct objfile
*objfile
)
1041 if (listp
->size
== 0)
1044 listp
->list
= (struct partial_symbol
**)
1045 xmmalloc (objfile
->md
, new_size
* sizeof (struct partial_symbol
*));
1049 new_size
= listp
->size
* 2;
1050 listp
->list
= (struct partial_symbol
**)
1051 xmrealloc (objfile
->md
, (char *) listp
->list
,
1052 new_size
* sizeof (struct partial_symbol
*));
1054 /* Next assumes we only went one over. Should be good if
1055 program works correctly */
1056 listp
->next
= listp
->list
+ listp
->size
;
1057 listp
->size
= new_size
;
1061 /* Do early runtime initializations. */
1063 _initialize_symmisc (void)