1 /* Do various things to symbol tables (other than lookup), for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004 Free Software
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., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
30 #include "breakpoint.h"
32 #include "gdb_obstack.h"
33 #include "exceptions.h"
37 #include "gdb_regex.h"
39 #include "dictionary.h"
41 #include "gdb_string.h"
42 #include "readline/readline.h"
45 #define DEV_TTY "/dev/tty"
48 /* Unfortunately for debugging, stderr is usually a macro. This is painful
49 when calling functions that take FILE *'s from the debugger.
50 So we make a variable which has the same value and which is accessible when
51 debugging GDB with itself. Because stdin et al need not be constants,
52 we initialize them in the _initialize_symmisc function at the bottom
58 /* Prototypes for local functions */
60 static void dump_symtab (struct objfile
*, struct symtab
*,
63 static void dump_psymtab (struct objfile
*, struct partial_symtab
*,
66 static void dump_msymbols (struct objfile
*, struct ui_file
*);
68 static void dump_objfile (struct objfile
*);
70 static int block_depth (struct block
*);
72 static void print_partial_symbols (struct partial_symbol
**, int,
73 char *, struct ui_file
*);
75 static void free_symtab_block (struct objfile
*, struct block
*);
77 void _initialize_symmisc (void);
79 struct print_symbol_args
81 struct symbol
*symbol
;
83 struct ui_file
*outfile
;
86 static int print_symbol (void *);
88 static void free_symtab_block (struct objfile
*, struct block
*);
91 /* Free a struct block <- B and all the symbols defined in that block. */
93 /* FIXME: carlton/2003-04-28: I don't believe this is currently ever
97 free_symtab_block (struct objfile
*objfile
, struct block
*b
)
99 struct dict_iterator iter
;
102 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
104 xfree (DEPRECATED_SYMBOL_NAME (sym
));
108 dict_free (BLOCK_DICT (b
));
112 /* Free all the storage associated with the struct symtab <- S.
113 Note that some symtabs have contents malloc'ed structure by structure,
114 while some have contents that all live inside one big block of memory,
115 and some share the contents of another symbol table and so you should
116 not free the contents on their behalf (except sometimes the linetable,
117 which maybe per symtab even when the rest is not).
118 It is s->free_code that says which alternative to use. */
121 free_symtab (struct symtab
*s
)
124 struct blockvector
*bv
;
126 switch (s
->free_code
)
129 /* All the contents are part of a big block of memory (an obstack),
130 and some other symtab is in charge of freeing that block.
131 Therefore, do nothing. */
135 /* Here all the contents were malloc'ed structure by structure
136 and must be freed that way. */
137 /* First free the blocks (and their symbols. */
138 bv
= BLOCKVECTOR (s
);
139 n
= BLOCKVECTOR_NBLOCKS (bv
);
140 for (i
= 0; i
< n
; i
++)
141 free_symtab_block (s
->objfile
, BLOCKVECTOR_BLOCK (bv
, i
));
142 /* Free the blockvector itself. */
144 /* Also free the linetable. */
147 /* Everything will be freed either by our `free_func'
148 or by some other symtab, except for our linetable.
151 xfree (LINETABLE (s
));
155 /* If there is a single block of memory to free, free it. */
156 if (s
->free_func
!= NULL
)
159 /* Free source-related stuff */
160 if (s
->line_charpos
!= NULL
)
161 xfree (s
->line_charpos
);
162 if (s
->fullname
!= NULL
)
164 if (s
->debugformat
!= NULL
)
165 xfree (s
->debugformat
);
170 print_symbol_bcache_statistics (void)
172 struct objfile
*objfile
;
175 ALL_OBJFILES (objfile
)
177 printf_filtered (_("Byte cache statistics for '%s':\n"), objfile
->name
);
178 print_bcache_statistics (objfile
->psymbol_cache
, "partial symbol cache");
184 print_objfile_statistics (void)
186 struct objfile
*objfile
;
188 struct partial_symtab
*ps
;
189 int i
, linetables
, blockvectors
;
192 ALL_OBJFILES (objfile
)
194 printf_filtered (_("Statistics for '%s':\n"), objfile
->name
);
195 if (OBJSTAT (objfile
, n_stabs
) > 0)
196 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
197 OBJSTAT (objfile
, n_stabs
));
198 if (OBJSTAT (objfile
, n_minsyms
) > 0)
199 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
200 OBJSTAT (objfile
, n_minsyms
));
201 if (OBJSTAT (objfile
, n_psyms
) > 0)
202 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
203 OBJSTAT (objfile
, n_psyms
));
204 if (OBJSTAT (objfile
, n_syms
) > 0)
205 printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
206 OBJSTAT (objfile
, n_syms
));
207 if (OBJSTAT (objfile
, n_types
) > 0)
208 printf_filtered (_(" Number of \"types\" defined: %d\n"),
209 OBJSTAT (objfile
, n_types
));
211 ALL_OBJFILE_PSYMTABS (objfile
, ps
)
216 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i
);
217 i
= linetables
= blockvectors
= 0;
218 ALL_OBJFILE_SYMTABS (objfile
, s
)
221 if (s
->linetable
!= NULL
)
226 printf_filtered (_(" Number of symbol tables: %d\n"), i
);
227 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
229 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
232 if (OBJSTAT (objfile
, sz_strtab
) > 0)
233 printf_filtered (_(" Space used by a.out string tables: %d\n"),
234 OBJSTAT (objfile
, sz_strtab
));
235 printf_filtered (_(" Total memory used for objfile obstack: %d\n"),
236 obstack_memory_used (&objfile
->objfile_obstack
));
237 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
238 bcache_memory_used (objfile
->psymbol_cache
));
239 printf_filtered (_(" Total memory used for macro cache: %d\n"),
240 bcache_memory_used (objfile
->macro_cache
));
246 dump_objfile (struct objfile
*objfile
)
248 struct symtab
*symtab
;
249 struct partial_symtab
*psymtab
;
251 printf_filtered ("\nObject file %s: ", objfile
->name
);
252 printf_filtered ("Objfile at ");
253 gdb_print_host_address (objfile
, gdb_stdout
);
254 printf_filtered (", bfd at ");
255 gdb_print_host_address (objfile
->obfd
, gdb_stdout
);
256 printf_filtered (", %d minsyms\n\n",
257 objfile
->minimal_symbol_count
);
259 if (objfile
->psymtabs
)
261 printf_filtered ("Psymtabs:\n");
262 for (psymtab
= objfile
->psymtabs
;
264 psymtab
= psymtab
->next
)
266 printf_filtered ("%s at ",
268 gdb_print_host_address (psymtab
, gdb_stdout
);
269 printf_filtered (", ");
270 if (psymtab
->objfile
!= objfile
)
272 printf_filtered ("NOT ON CHAIN! ");
276 printf_filtered ("\n\n");
279 if (objfile
->symtabs
)
281 printf_filtered ("Symtabs:\n");
282 for (symtab
= objfile
->symtabs
;
284 symtab
= symtab
->next
)
286 printf_filtered ("%s at ", symtab
->filename
);
287 gdb_print_host_address (symtab
, gdb_stdout
);
288 printf_filtered (", ");
289 if (symtab
->objfile
!= objfile
)
291 printf_filtered ("NOT ON CHAIN! ");
295 printf_filtered ("\n\n");
299 /* Print minimal symbols from this objfile. */
302 dump_msymbols (struct objfile
*objfile
, struct ui_file
*outfile
)
304 struct minimal_symbol
*msymbol
;
308 fprintf_filtered (outfile
, "\nObject file %s:\n\n", objfile
->name
);
309 if (objfile
->minimal_symbol_count
== 0)
311 fprintf_filtered (outfile
, "No minimal symbols found.\n");
314 for (index
= 0, msymbol
= objfile
->msymbols
;
315 DEPRECATED_SYMBOL_NAME (msymbol
) != NULL
; msymbol
++, index
++)
317 switch (msymbol
->type
)
325 case mst_solib_trampoline
:
350 fprintf_filtered (outfile
, "[%2d] %c ", index
, ms_type
);
351 deprecated_print_address_numeric (SYMBOL_VALUE_ADDRESS (msymbol
), 1, outfile
);
352 fprintf_filtered (outfile
, " %s", DEPRECATED_SYMBOL_NAME (msymbol
));
353 if (SYMBOL_BFD_SECTION (msymbol
))
354 fprintf_filtered (outfile
, " section %s",
355 bfd_section_name (objfile
->obfd
,
356 SYMBOL_BFD_SECTION (msymbol
)));
357 if (SYMBOL_DEMANGLED_NAME (msymbol
) != NULL
)
359 fprintf_filtered (outfile
, " %s", SYMBOL_DEMANGLED_NAME (msymbol
));
361 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
362 if (msymbol
->filename
)
363 fprintf_filtered (outfile
, " %s", msymbol
->filename
);
365 fputs_filtered ("\n", outfile
);
367 if (objfile
->minimal_symbol_count
!= index
)
369 warning (_("internal error: minimal symbol count %d != %d"),
370 objfile
->minimal_symbol_count
, index
);
372 fprintf_filtered (outfile
, "\n");
376 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
377 struct ui_file
*outfile
)
381 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
383 fprintf_filtered (outfile
, "(object ");
384 gdb_print_host_address (psymtab
, outfile
);
385 fprintf_filtered (outfile
, ")\n\n");
386 fprintf_unfiltered (outfile
, " Read from object file %s (",
388 gdb_print_host_address (objfile
, outfile
);
389 fprintf_unfiltered (outfile
, ")\n");
393 fprintf_filtered (outfile
,
394 " Full symtab was read (at ");
395 gdb_print_host_address (psymtab
->symtab
, outfile
);
396 fprintf_filtered (outfile
, " by function at ");
397 gdb_print_host_address (psymtab
->read_symtab
, outfile
);
398 fprintf_filtered (outfile
, ")\n");
401 fprintf_filtered (outfile
, " Relocate symbols by ");
402 for (i
= 0; i
< psymtab
->objfile
->num_sections
; ++i
)
405 fprintf_filtered (outfile
, ", ");
407 deprecated_print_address_numeric (ANOFFSET (psymtab
->section_offsets
, i
),
411 fprintf_filtered (outfile
, "\n");
413 fprintf_filtered (outfile
, " Symbols cover text addresses ");
414 deprecated_print_address_numeric (psymtab
->textlow
, 1, outfile
);
415 fprintf_filtered (outfile
, "-");
416 deprecated_print_address_numeric (psymtab
->texthigh
, 1, outfile
);
417 fprintf_filtered (outfile
, "\n");
418 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
419 psymtab
->number_of_dependencies
);
420 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
422 fprintf_filtered (outfile
, " %d ", i
);
423 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
424 fprintf_filtered (outfile
, " %s\n",
425 psymtab
->dependencies
[i
]->filename
);
427 if (psymtab
->n_global_syms
> 0)
429 print_partial_symbols (objfile
->global_psymbols
.list
430 + psymtab
->globals_offset
,
431 psymtab
->n_global_syms
, "Global", outfile
);
433 if (psymtab
->n_static_syms
> 0)
435 print_partial_symbols (objfile
->static_psymbols
.list
436 + psymtab
->statics_offset
,
437 psymtab
->n_static_syms
, "Static", outfile
);
439 fprintf_filtered (outfile
, "\n");
443 dump_symtab_1 (struct objfile
*objfile
, struct symtab
*symtab
,
444 struct ui_file
*outfile
)
447 struct dict_iterator iter
;
450 struct blockvector
*bv
;
455 fprintf_filtered (outfile
, "\nSymtab for file %s\n", symtab
->filename
);
457 fprintf_filtered (outfile
, "Compilation directory is %s\n",
459 fprintf_filtered (outfile
, "Read from object file %s (", objfile
->name
);
460 gdb_print_host_address (objfile
, outfile
);
461 fprintf_filtered (outfile
, ")\n");
462 fprintf_filtered (outfile
, "Language: %s\n", language_str (symtab
->language
));
464 /* First print the line table. */
465 l
= LINETABLE (symtab
);
468 fprintf_filtered (outfile
, "\nLine table:\n\n");
470 for (i
= 0; i
< len
; i
++)
472 fprintf_filtered (outfile
, " line %d at ", l
->item
[i
].line
);
473 deprecated_print_address_numeric (l
->item
[i
].pc
, 1, outfile
);
474 fprintf_filtered (outfile
, "\n");
477 /* Now print the block info, but only for primary symtabs since we will
478 print lots of duplicate info otherwise. */
481 fprintf_filtered (outfile
, "\nBlockvector:\n\n");
482 bv
= BLOCKVECTOR (symtab
);
483 len
= BLOCKVECTOR_NBLOCKS (bv
);
484 for (i
= 0; i
< len
; i
++)
486 b
= BLOCKVECTOR_BLOCK (bv
, i
);
487 depth
= block_depth (b
) * 2;
488 print_spaces (depth
, outfile
);
489 fprintf_filtered (outfile
, "block #%03d, object at ", i
);
490 gdb_print_host_address (b
, outfile
);
491 if (BLOCK_SUPERBLOCK (b
))
493 fprintf_filtered (outfile
, " under ");
494 gdb_print_host_address (BLOCK_SUPERBLOCK (b
), outfile
);
496 /* drow/2002-07-10: We could save the total symbols count
497 even if we're using a hashtable, but nothing else but this message
499 fprintf_filtered (outfile
, ", %d syms/buckets in ",
500 dict_size (BLOCK_DICT (b
)));
501 deprecated_print_address_numeric (BLOCK_START (b
), 1, outfile
);
502 fprintf_filtered (outfile
, "..");
503 deprecated_print_address_numeric (BLOCK_END (b
), 1, outfile
);
504 if (BLOCK_FUNCTION (b
))
506 fprintf_filtered (outfile
, ", function %s", DEPRECATED_SYMBOL_NAME (BLOCK_FUNCTION (b
)));
507 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b
)) != NULL
)
509 fprintf_filtered (outfile
, ", %s",
510 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b
)));
513 if (BLOCK_GCC_COMPILED (b
))
514 fprintf_filtered (outfile
, ", compiled with gcc%d", BLOCK_GCC_COMPILED (b
));
515 fprintf_filtered (outfile
, "\n");
516 /* Now print each symbol in this block (in no particular order, if
517 we're using a hashtable). */
518 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
520 struct print_symbol_args s
;
524 catch_errors (print_symbol
, &s
, "Error printing symbol:\n",
528 fprintf_filtered (outfile
, "\n");
532 fprintf_filtered (outfile
, "\nBlockvector same as previous symtab\n\n");
537 dump_symtab (struct objfile
*objfile
, struct symtab
*symtab
,
538 struct ui_file
*outfile
)
540 enum language saved_lang
;
542 /* Set the current language to the language of the symtab we're dumping
543 because certain routines used during dump_symtab() use the current
544 language to print an image of the symbol. We'll restore it later. */
545 saved_lang
= set_language (symtab
->language
);
547 dump_symtab_1 (objfile
, symtab
, outfile
);
549 set_language (saved_lang
);
553 maintenance_print_symbols (char *args
, int from_tty
)
556 struct ui_file
*outfile
;
557 struct cleanup
*cleanups
;
558 char *symname
= NULL
;
559 char *filename
= DEV_TTY
;
560 struct objfile
*objfile
;
568 Arguments missing: an output file name and an optional symbol file name"));
570 else if ((argv
= buildargv (args
)) == NULL
)
574 cleanups
= make_cleanup_freeargv (argv
);
579 /* If a second arg is supplied, it is a source file name to match on */
586 filename
= tilde_expand (filename
);
587 make_cleanup (xfree
, filename
);
589 outfile
= gdb_fopen (filename
, FOPEN_WT
);
591 perror_with_name (filename
);
592 make_cleanup_ui_file_delete (outfile
);
595 ALL_SYMTABS (objfile
, s
)
596 if (symname
== NULL
|| strcmp (symname
, s
->filename
) == 0)
597 dump_symtab (objfile
, s
, outfile
);
599 do_cleanups (cleanups
);
602 /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
603 far to indent. ARGS is really a struct print_symbol_args *, but is
604 declared as char * to get it past catch_errors. Returns 0 for error,
608 print_symbol (void *args
)
610 struct symbol
*symbol
= ((struct print_symbol_args
*) args
)->symbol
;
611 int depth
= ((struct print_symbol_args
*) args
)->depth
;
612 struct ui_file
*outfile
= ((struct print_symbol_args
*) args
)->outfile
;
614 print_spaces (depth
, outfile
);
615 if (SYMBOL_DOMAIN (symbol
) == LABEL_DOMAIN
)
617 fprintf_filtered (outfile
, "label %s at ", SYMBOL_PRINT_NAME (symbol
));
618 deprecated_print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol
), 1, outfile
);
619 if (SYMBOL_BFD_SECTION (symbol
))
620 fprintf_filtered (outfile
, " section %s\n",
621 bfd_section_name (SYMBOL_BFD_SECTION (symbol
)->owner
,
622 SYMBOL_BFD_SECTION (symbol
)));
624 fprintf_filtered (outfile
, "\n");
627 if (SYMBOL_DOMAIN (symbol
) == STRUCT_DOMAIN
)
629 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol
)))
631 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
);
635 fprintf_filtered (outfile
, "%s %s = ",
636 (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_ENUM
638 : (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_STRUCT
639 ? "struct" : "union")),
640 DEPRECATED_SYMBOL_NAME (symbol
));
641 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
);
643 fprintf_filtered (outfile
, ";\n");
647 if (SYMBOL_CLASS (symbol
) == LOC_TYPEDEF
)
648 fprintf_filtered (outfile
, "typedef ");
649 if (SYMBOL_TYPE (symbol
))
651 /* Print details of types, except for enums where it's clutter. */
652 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), SYMBOL_PRINT_NAME (symbol
),
654 TYPE_CODE (SYMBOL_TYPE (symbol
)) != TYPE_CODE_ENUM
,
656 fprintf_filtered (outfile
, "; ");
659 fprintf_filtered (outfile
, "%s ", SYMBOL_PRINT_NAME (symbol
));
661 switch (SYMBOL_CLASS (symbol
))
664 fprintf_filtered (outfile
, "const %ld (0x%lx)",
665 SYMBOL_VALUE (symbol
),
666 SYMBOL_VALUE (symbol
));
669 case LOC_CONST_BYTES
:
672 struct type
*type
= check_typedef (SYMBOL_TYPE (symbol
));
673 fprintf_filtered (outfile
, "const %u hex bytes:",
675 for (i
= 0; i
< TYPE_LENGTH (type
); i
++)
676 fprintf_filtered (outfile
, " %02x",
677 (unsigned) SYMBOL_VALUE_BYTES (symbol
)[i
]);
682 fprintf_filtered (outfile
, "static at ");
683 deprecated_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
, "extern global at *(");
693 deprecated_print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol
), 1, outfile
);
694 fprintf_filtered (outfile
, "),");
698 fprintf_filtered (outfile
, "register %ld", SYMBOL_VALUE (symbol
));
702 fprintf_filtered (outfile
, "arg at offset 0x%lx",
703 SYMBOL_VALUE (symbol
));
707 fprintf_filtered (outfile
, "arg at offset 0x%lx from fp",
708 SYMBOL_VALUE (symbol
));
712 fprintf_filtered (outfile
, "reference arg at 0x%lx", SYMBOL_VALUE (symbol
));
716 fprintf_filtered (outfile
, "parameter register %ld", SYMBOL_VALUE (symbol
));
719 case LOC_REGPARM_ADDR
:
720 fprintf_filtered (outfile
, "address parameter register %ld", SYMBOL_VALUE (symbol
));
724 fprintf_filtered (outfile
, "local at offset 0x%lx",
725 SYMBOL_VALUE (symbol
));
729 fprintf_filtered (outfile
, "local at 0x%lx from register %d",
730 SYMBOL_VALUE (symbol
), SYMBOL_BASEREG (symbol
));
733 case LOC_BASEREG_ARG
:
734 fprintf_filtered (outfile
, "arg at 0x%lx from register %d",
735 SYMBOL_VALUE (symbol
), SYMBOL_BASEREG (symbol
));
742 fprintf_filtered (outfile
, "label at ");
743 deprecated_print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol
), 1, outfile
);
744 if (SYMBOL_BFD_SECTION (symbol
))
745 fprintf_filtered (outfile
, " section %s",
747 (SYMBOL_BFD_SECTION (symbol
)->owner
,
748 SYMBOL_BFD_SECTION (symbol
)));
752 fprintf_filtered (outfile
, "block object ");
753 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol
), outfile
);
754 fprintf_filtered (outfile
, ", ");
755 deprecated_print_address_numeric (BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
)),
758 fprintf_filtered (outfile
, "..");
759 deprecated_print_address_numeric (BLOCK_END (SYMBOL_BLOCK_VALUE (symbol
)),
762 if (SYMBOL_BFD_SECTION (symbol
))
763 fprintf_filtered (outfile
, " section %s",
765 (SYMBOL_BFD_SECTION (symbol
)->owner
,
766 SYMBOL_BFD_SECTION (symbol
)));
770 case LOC_COMPUTED_ARG
:
771 fprintf_filtered (outfile
, "computed at runtime");
775 fprintf_filtered (outfile
, "unresolved");
778 case LOC_OPTIMIZED_OUT
:
779 fprintf_filtered (outfile
, "optimized out");
783 fprintf_filtered (outfile
, "botched symbol class %x",
784 SYMBOL_CLASS (symbol
));
788 fprintf_filtered (outfile
, "\n");
793 maintenance_print_psymbols (char *args
, int from_tty
)
796 struct ui_file
*outfile
;
797 struct cleanup
*cleanups
;
798 char *symname
= NULL
;
799 char *filename
= DEV_TTY
;
800 struct objfile
*objfile
;
801 struct partial_symtab
*ps
;
807 error (_("print-psymbols takes an output file name and optional symbol file name"));
809 else if ((argv
= buildargv (args
)) == NULL
)
813 cleanups
= make_cleanup_freeargv (argv
);
818 /* If a second arg is supplied, it is a source file name to match on */
825 filename
= tilde_expand (filename
);
826 make_cleanup (xfree
, filename
);
828 outfile
= gdb_fopen (filename
, FOPEN_WT
);
830 perror_with_name (filename
);
831 make_cleanup_ui_file_delete (outfile
);
834 ALL_PSYMTABS (objfile
, ps
)
835 if (symname
== NULL
|| strcmp (symname
, ps
->filename
) == 0)
836 dump_psymtab (objfile
, ps
, outfile
);
838 do_cleanups (cleanups
);
842 print_partial_symbols (struct partial_symbol
**p
, int count
, char *what
,
843 struct ui_file
*outfile
)
845 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
848 fprintf_filtered (outfile
, " `%s'", DEPRECATED_SYMBOL_NAME (*p
));
849 if (SYMBOL_DEMANGLED_NAME (*p
) != NULL
)
851 fprintf_filtered (outfile
, " `%s'", SYMBOL_DEMANGLED_NAME (*p
));
853 fputs_filtered (", ", outfile
);
854 switch (SYMBOL_DOMAIN (*p
))
857 fputs_filtered ("undefined domain, ", outfile
);
860 /* This is the usual thing -- don't print it */
863 fputs_filtered ("struct domain, ", outfile
);
866 fputs_filtered ("label domain, ", outfile
);
869 fputs_filtered ("<invalid domain>, ", outfile
);
872 switch (SYMBOL_CLASS (*p
))
875 fputs_filtered ("undefined", outfile
);
878 fputs_filtered ("constant int", outfile
);
881 fputs_filtered ("static", outfile
);
884 fputs_filtered ("extern global", outfile
);
887 fputs_filtered ("register", outfile
);
890 fputs_filtered ("pass by value", outfile
);
893 fputs_filtered ("pass by reference", outfile
);
896 fputs_filtered ("register parameter", outfile
);
898 case LOC_REGPARM_ADDR
:
899 fputs_filtered ("register address parameter", outfile
);
902 fputs_filtered ("stack parameter", outfile
);
905 fputs_filtered ("type", outfile
);
908 fputs_filtered ("label", outfile
);
911 fputs_filtered ("function", outfile
);
913 case LOC_CONST_BYTES
:
914 fputs_filtered ("constant bytes", outfile
);
917 fputs_filtered ("shuffled arg", outfile
);
920 fputs_filtered ("unresolved", outfile
);
922 case LOC_OPTIMIZED_OUT
:
923 fputs_filtered ("optimized out", outfile
);
926 case LOC_COMPUTED_ARG
:
927 fputs_filtered ("computed at runtime", outfile
);
930 fputs_filtered ("<invalid location>", outfile
);
933 fputs_filtered (", ", outfile
);
934 deprecated_print_address_numeric (SYMBOL_VALUE_ADDRESS (*p
), 1, outfile
);
935 fprintf_filtered (outfile
, "\n");
941 maintenance_print_msymbols (char *args
, int from_tty
)
944 struct ui_file
*outfile
;
945 struct cleanup
*cleanups
;
946 char *filename
= DEV_TTY
;
947 char *symname
= NULL
;
948 struct objfile
*objfile
;
950 struct stat sym_st
, obj_st
;
956 error (_("print-msymbols takes an output file name and optional symbol file name"));
958 else if ((argv
= buildargv (args
)) == NULL
)
962 cleanups
= make_cleanup_freeargv (argv
);
967 /* If a second arg is supplied, it is a source file name to match on */
970 symname
= xfullpath (argv
[1]);
971 make_cleanup (xfree
, symname
);
972 if (symname
&& stat (symname
, &sym_st
))
973 perror_with_name (symname
);
977 filename
= tilde_expand (filename
);
978 make_cleanup (xfree
, filename
);
980 outfile
= gdb_fopen (filename
, FOPEN_WT
);
982 perror_with_name (filename
);
983 make_cleanup_ui_file_delete (outfile
);
986 ALL_OBJFILES (objfile
)
988 || (!stat (objfile
->name
, &obj_st
) && sym_st
.st_ino
== obj_st
.st_ino
))
989 dump_msymbols (objfile
, outfile
);
991 fprintf_filtered (outfile
, "\n\n");
992 do_cleanups (cleanups
);
996 maintenance_print_objfiles (char *ignore
, int from_tty
)
998 struct objfile
*objfile
;
1003 ALL_OBJFILES (objfile
)
1004 dump_objfile (objfile
);
1009 /* List all the symbol tables whose names match REGEXP (optional). */
1011 maintenance_info_symtabs (char *regexp
, int from_tty
)
1013 struct objfile
*objfile
;
1018 ALL_OBJFILES (objfile
)
1020 struct symtab
*symtab
;
1022 /* We don't want to print anything for this objfile until we
1023 actually find a symtab whose name matches. */
1024 int printed_objfile_start
= 0;
1026 ALL_OBJFILE_SYMTABS (objfile
, symtab
)
1028 || re_exec (symtab
->filename
))
1030 if (! printed_objfile_start
)
1032 printf_filtered ("{ objfile %s ", objfile
->name
);
1034 printf_filtered ("((struct objfile *) %p)\n", objfile
);
1035 printed_objfile_start
= 1;
1038 printf_filtered (" { symtab %s ", symtab
->filename
);
1040 printf_filtered ("((struct symtab *) %p)\n", symtab
);
1041 printf_filtered (" dirname %s\n",
1042 symtab
->dirname
? symtab
->dirname
: "(null)");
1043 printf_filtered (" fullname %s\n",
1044 symtab
->fullname
? symtab
->fullname
: "(null)");
1045 printf_filtered (" blockvector ((struct blockvector *) %p)%s\n",
1046 symtab
->blockvector
,
1047 symtab
->primary
? " (primary)" : "");
1048 printf_filtered (" debugformat %s\n", symtab
->debugformat
);
1049 printf_filtered (" }\n");
1052 if (printed_objfile_start
)
1053 printf_filtered ("}\n");
1058 /* List all the partial symbol tables whose names match REGEXP (optional). */
1060 maintenance_info_psymtabs (char *regexp
, int from_tty
)
1062 struct objfile
*objfile
;
1067 ALL_OBJFILES (objfile
)
1069 struct partial_symtab
*psymtab
;
1071 /* We don't want to print anything for this objfile until we
1072 actually find a symtab whose name matches. */
1073 int printed_objfile_start
= 0;
1075 ALL_OBJFILE_PSYMTABS (objfile
, psymtab
)
1077 || re_exec (psymtab
->filename
))
1079 if (! printed_objfile_start
)
1081 printf_filtered ("{ objfile %s ", objfile
->name
);
1083 printf_filtered ("((struct objfile *) %p)\n", objfile
);
1084 printed_objfile_start
= 1;
1087 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1089 printf_filtered ("((struct partial_symtab *) %p)\n", psymtab
);
1090 printf_filtered (" readin %s\n",
1091 psymtab
->readin
? "yes" : "no");
1092 printf_filtered (" fullname %s\n",
1093 psymtab
->fullname
? psymtab
->fullname
: "(null)");
1094 printf_filtered (" text addresses ");
1095 deprecated_print_address_numeric (psymtab
->textlow
, 1, gdb_stdout
);
1096 printf_filtered (" -- ");
1097 deprecated_print_address_numeric (psymtab
->texthigh
, 1, gdb_stdout
);
1098 printf_filtered ("\n");
1099 printf_filtered (" globals ");
1100 if (psymtab
->n_global_syms
)
1102 printf_filtered ("(* (struct partial_symbol **) %p @ %d)\n",
1103 (psymtab
->objfile
->global_psymbols
.list
1104 + psymtab
->globals_offset
),
1105 psymtab
->n_global_syms
);
1108 printf_filtered ("(none)\n");
1109 printf_filtered (" statics ");
1110 if (psymtab
->n_static_syms
)
1112 printf_filtered ("(* (struct partial_symbol **) %p @ %d)\n",
1113 (psymtab
->objfile
->static_psymbols
.list
1114 + psymtab
->statics_offset
),
1115 psymtab
->n_static_syms
);
1118 printf_filtered ("(none)\n");
1119 printf_filtered (" dependencies ");
1120 if (psymtab
->number_of_dependencies
)
1124 printf_filtered ("{\n");
1125 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1127 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
1129 /* Note the string concatenation there --- no comma. */
1130 printf_filtered (" psymtab %s "
1131 "((struct partial_symtab *) %p)\n",
1132 dep
->filename
, dep
);
1134 printf_filtered (" }\n");
1137 printf_filtered ("(none)\n");
1138 printf_filtered (" }\n");
1141 if (printed_objfile_start
)
1142 printf_filtered ("}\n");
1147 /* Check consistency of psymtabs and symtabs. */
1150 maintenance_check_symtabs (char *ignore
, int from_tty
)
1153 struct partial_symbol
**psym
;
1154 struct symtab
*s
= NULL
;
1155 struct partial_symtab
*ps
;
1156 struct blockvector
*bv
;
1157 struct objfile
*objfile
;
1161 ALL_PSYMTABS (objfile
, ps
)
1163 s
= PSYMTAB_TO_SYMTAB (ps
);
1166 bv
= BLOCKVECTOR (s
);
1167 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1168 psym
= ps
->objfile
->static_psymbols
.list
+ ps
->statics_offset
;
1169 length
= ps
->n_static_syms
;
1172 sym
= lookup_block_symbol (b
, DEPRECATED_SYMBOL_NAME (*psym
),
1173 NULL
, SYMBOL_DOMAIN (*psym
));
1176 printf_filtered ("Static symbol `");
1177 puts_filtered (DEPRECATED_SYMBOL_NAME (*psym
));
1178 printf_filtered ("' only found in ");
1179 puts_filtered (ps
->filename
);
1180 printf_filtered (" psymtab\n");
1184 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1185 psym
= ps
->objfile
->global_psymbols
.list
+ ps
->globals_offset
;
1186 length
= ps
->n_global_syms
;
1189 sym
= lookup_block_symbol (b
, DEPRECATED_SYMBOL_NAME (*psym
),
1190 NULL
, SYMBOL_DOMAIN (*psym
));
1193 printf_filtered ("Global symbol `");
1194 puts_filtered (DEPRECATED_SYMBOL_NAME (*psym
));
1195 printf_filtered ("' only found in ");
1196 puts_filtered (ps
->filename
);
1197 printf_filtered (" psymtab\n");
1201 if (ps
->texthigh
< ps
->textlow
)
1203 printf_filtered ("Psymtab ");
1204 puts_filtered (ps
->filename
);
1205 printf_filtered (" covers bad range ");
1206 deprecated_print_address_numeric (ps
->textlow
, 1, gdb_stdout
);
1207 printf_filtered (" - ");
1208 deprecated_print_address_numeric (ps
->texthigh
, 1, gdb_stdout
);
1209 printf_filtered ("\n");
1212 if (ps
->texthigh
== 0)
1214 if (ps
->textlow
< BLOCK_START (b
) || ps
->texthigh
> BLOCK_END (b
))
1216 printf_filtered ("Psymtab ");
1217 puts_filtered (ps
->filename
);
1218 printf_filtered (" covers ");
1219 deprecated_print_address_numeric (ps
->textlow
, 1, gdb_stdout
);
1220 printf_filtered (" - ");
1221 deprecated_print_address_numeric (ps
->texthigh
, 1, gdb_stdout
);
1222 printf_filtered (" but symtab covers only ");
1223 deprecated_print_address_numeric (BLOCK_START (b
), 1, gdb_stdout
);
1224 printf_filtered (" - ");
1225 deprecated_print_address_numeric (BLOCK_END (b
), 1, gdb_stdout
);
1226 printf_filtered ("\n");
1232 /* Return the nexting depth of a block within other blocks in its symtab. */
1235 block_depth (struct block
*block
)
1238 while ((block
= BLOCK_SUPERBLOCK (block
)) != NULL
)
1246 /* Increase the space allocated for LISTP, which is probably
1247 global_psymbols or static_psymbols. This space will eventually
1248 be freed in free_objfile(). */
1251 extend_psymbol_list (struct psymbol_allocation_list
*listp
,
1252 struct objfile
*objfile
)
1255 if (listp
->size
== 0)
1258 listp
->list
= (struct partial_symbol
**)
1259 xmalloc (new_size
* sizeof (struct partial_symbol
*));
1263 new_size
= listp
->size
* 2;
1264 listp
->list
= (struct partial_symbol
**)
1265 xrealloc ((char *) listp
->list
,
1266 new_size
* sizeof (struct partial_symbol
*));
1268 /* Next assumes we only went one over. Should be good if
1269 program works correctly */
1270 listp
->next
= listp
->list
+ listp
->size
;
1271 listp
->size
= new_size
;
1275 /* Do early runtime initializations. */
1277 _initialize_symmisc (void)
This page took 0.054766 seconds and 4 git commands to generate.