1 /* Do various things to symbol tables (other than lookup), for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2007, 2008, 2009
5 Free Software Foundation, Inc.
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 3 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, see <http://www.gnu.org/licenses/>. */
28 #include "breakpoint.h"
30 #include "gdb_obstack.h"
31 #include "exceptions.h"
35 #include "gdb_regex.h"
37 #include "dictionary.h"
39 #include "gdb_string.h"
40 #include "readline/readline.h"
43 #define DEV_TTY "/dev/tty"
46 /* Unfortunately for debugging, stderr is usually a macro. This is painful
47 when calling functions that take FILE *'s from the debugger.
48 So we make a variable which has the same value and which is accessible when
49 debugging GDB with itself. Because stdin et al need not be constants,
50 we initialize them in the _initialize_symmisc function at the bottom
56 /* Prototypes for local functions */
58 static void dump_symtab (struct objfile
*, struct symtab
*,
61 static void dump_psymtab (struct objfile
*, struct partial_symtab
*,
64 static void dump_msymbols (struct objfile
*, struct ui_file
*);
66 static void dump_objfile (struct objfile
*);
68 static int block_depth (struct block
*);
70 static void print_partial_symbols (struct gdbarch
*,
71 struct partial_symbol
**, int,
72 char *, struct ui_file
*);
74 void _initialize_symmisc (void);
76 struct print_symbol_args
78 struct gdbarch
*gdbarch
;
79 struct symbol
*symbol
;
81 struct ui_file
*outfile
;
84 static int print_symbol (void *);
86 /* Free all the storage associated with the struct symtab <- S.
87 Note that some symtabs have contents that all live inside one big block of
88 memory, and some share the contents of another symbol table and so you
89 should not free the contents on their behalf (except sometimes the
90 linetable, which maybe per symtab even when the rest is not).
91 It is s->free_code that says which alternative to use. */
94 free_symtab (struct symtab
*s
)
97 struct blockvector
*bv
;
102 /* All the contents are part of a big block of memory (an obstack),
103 and some other symtab is in charge of freeing that block.
104 Therefore, do nothing. */
108 /* Everything will be freed either by our `free_func'
109 or by some other symtab, except for our linetable.
112 xfree (LINETABLE (s
));
116 /* If there is a single block of memory to free, free it. */
117 if (s
->free_func
!= NULL
)
120 /* Free source-related stuff */
121 if (s
->line_charpos
!= NULL
)
122 xfree (s
->line_charpos
);
123 if (s
->fullname
!= NULL
)
125 if (s
->debugformat
!= NULL
)
126 xfree (s
->debugformat
);
131 print_symbol_bcache_statistics (void)
133 struct objfile
*objfile
;
136 ALL_OBJFILES (objfile
)
138 printf_filtered (_("Byte cache statistics for '%s':\n"), objfile
->name
);
139 print_bcache_statistics (objfile
->psymbol_cache
, "partial symbol cache");
140 print_bcache_statistics (objfile
->macro_cache
, "preprocessor macro cache");
146 print_objfile_statistics (void)
148 struct objfile
*objfile
;
150 struct partial_symtab
*ps
;
151 int i
, linetables
, blockvectors
;
154 ALL_OBJFILES (objfile
)
156 printf_filtered (_("Statistics for '%s':\n"), objfile
->name
);
157 if (OBJSTAT (objfile
, n_stabs
) > 0)
158 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
159 OBJSTAT (objfile
, n_stabs
));
160 if (OBJSTAT (objfile
, n_minsyms
) > 0)
161 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
162 OBJSTAT (objfile
, n_minsyms
));
163 if (OBJSTAT (objfile
, n_psyms
) > 0)
164 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
165 OBJSTAT (objfile
, n_psyms
));
166 if (OBJSTAT (objfile
, n_syms
) > 0)
167 printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
168 OBJSTAT (objfile
, n_syms
));
169 if (OBJSTAT (objfile
, n_types
) > 0)
170 printf_filtered (_(" Number of \"types\" defined: %d\n"),
171 OBJSTAT (objfile
, n_types
));
173 ALL_OBJFILE_PSYMTABS (objfile
, ps
)
178 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i
);
179 i
= linetables
= blockvectors
= 0;
180 ALL_OBJFILE_SYMTABS (objfile
, s
)
183 if (s
->linetable
!= NULL
)
188 printf_filtered (_(" Number of symbol tables: %d\n"), i
);
189 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
191 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
194 if (OBJSTAT (objfile
, sz_strtab
) > 0)
195 printf_filtered (_(" Space used by a.out string tables: %d\n"),
196 OBJSTAT (objfile
, sz_strtab
));
197 printf_filtered (_(" Total memory used for objfile obstack: %d\n"),
198 obstack_memory_used (&objfile
->objfile_obstack
));
199 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
200 bcache_memory_used (objfile
->psymbol_cache
));
201 printf_filtered (_(" Total memory used for macro cache: %d\n"),
202 bcache_memory_used (objfile
->macro_cache
));
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 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
267 struct minimal_symbol
*msymbol
;
271 fprintf_filtered (outfile
, "\nObject file %s:\n\n", objfile
->name
);
272 if (objfile
->minimal_symbol_count
== 0)
274 fprintf_filtered (outfile
, "No minimal symbols found.\n");
278 ALL_OBJFILE_MSYMBOLS (objfile
, msymbol
)
280 struct obj_section
*section
= SYMBOL_OBJ_SECTION (msymbol
);
282 switch (MSYMBOL_TYPE (msymbol
))
290 case mst_solib_trampoline
:
315 fprintf_filtered (outfile
, "[%2d] %c ", index
, ms_type
);
316 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (msymbol
)),
318 fprintf_filtered (outfile
, " %s", SYMBOL_LINKAGE_NAME (msymbol
));
320 fprintf_filtered (outfile
, " section %s",
321 bfd_section_name (objfile
->obfd
,
322 section
->the_bfd_section
));
323 if (SYMBOL_DEMANGLED_NAME (msymbol
) != NULL
)
325 fprintf_filtered (outfile
, " %s", SYMBOL_DEMANGLED_NAME (msymbol
));
327 if (msymbol
->filename
)
328 fprintf_filtered (outfile
, " %s", msymbol
->filename
);
329 fputs_filtered ("\n", outfile
);
332 if (objfile
->minimal_symbol_count
!= index
)
334 warning (_("internal error: minimal symbol count %d != %d"),
335 objfile
->minimal_symbol_count
, index
);
337 fprintf_filtered (outfile
, "\n");
341 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
342 struct ui_file
*outfile
)
344 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
347 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
349 fprintf_filtered (outfile
, "(object ");
350 gdb_print_host_address (psymtab
, outfile
);
351 fprintf_filtered (outfile
, ")\n\n");
352 fprintf_unfiltered (outfile
, " Read from object file %s (",
354 gdb_print_host_address (objfile
, outfile
);
355 fprintf_unfiltered (outfile
, ")\n");
359 fprintf_filtered (outfile
,
360 " Full symtab was read (at ");
361 gdb_print_host_address (psymtab
->symtab
, outfile
);
362 fprintf_filtered (outfile
, " by function at ");
363 gdb_print_host_address (psymtab
->read_symtab
, outfile
);
364 fprintf_filtered (outfile
, ")\n");
367 fprintf_filtered (outfile
, " Relocate symbols by ");
368 for (i
= 0; i
< psymtab
->objfile
->num_sections
; ++i
)
371 fprintf_filtered (outfile
, ", ");
373 fputs_filtered (paddress (gdbarch
,
374 ANOFFSET (psymtab
->section_offsets
, i
)),
377 fprintf_filtered (outfile
, "\n");
379 fprintf_filtered (outfile
, " Symbols cover text addresses ");
380 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
), outfile
);
381 fprintf_filtered (outfile
, "-");
382 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
), outfile
);
383 fprintf_filtered (outfile
, "\n");
384 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
385 psymtab
->number_of_dependencies
);
386 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
388 fprintf_filtered (outfile
, " %d ", i
);
389 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
390 fprintf_filtered (outfile
, " %s\n",
391 psymtab
->dependencies
[i
]->filename
);
393 if (psymtab
->n_global_syms
> 0)
395 print_partial_symbols (gdbarch
,
396 objfile
->global_psymbols
.list
397 + psymtab
->globals_offset
,
398 psymtab
->n_global_syms
, "Global", outfile
);
400 if (psymtab
->n_static_syms
> 0)
402 print_partial_symbols (gdbarch
,
403 objfile
->static_psymbols
.list
404 + psymtab
->statics_offset
,
405 psymtab
->n_static_syms
, "Static", outfile
);
407 fprintf_filtered (outfile
, "\n");
411 dump_symtab_1 (struct objfile
*objfile
, struct symtab
*symtab
,
412 struct ui_file
*outfile
)
414 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
416 struct dict_iterator iter
;
419 struct blockvector
*bv
;
424 fprintf_filtered (outfile
, "\nSymtab for file %s\n", symtab
->filename
);
426 fprintf_filtered (outfile
, "Compilation directory is %s\n",
428 fprintf_filtered (outfile
, "Read from object file %s (", objfile
->name
);
429 gdb_print_host_address (objfile
, outfile
);
430 fprintf_filtered (outfile
, ")\n");
431 fprintf_filtered (outfile
, "Language: %s\n", language_str (symtab
->language
));
433 /* First print the line table. */
434 l
= LINETABLE (symtab
);
437 fprintf_filtered (outfile
, "\nLine table:\n\n");
439 for (i
= 0; i
< len
; i
++)
441 fprintf_filtered (outfile
, " line %d at ", l
->item
[i
].line
);
442 fputs_filtered (paddress (gdbarch
, l
->item
[i
].pc
), outfile
);
443 fprintf_filtered (outfile
, "\n");
446 /* Now print the block info, but only for primary symtabs since we will
447 print lots of duplicate info otherwise. */
450 fprintf_filtered (outfile
, "\nBlockvector:\n\n");
451 bv
= BLOCKVECTOR (symtab
);
452 len
= BLOCKVECTOR_NBLOCKS (bv
);
453 for (i
= 0; i
< len
; i
++)
455 b
= BLOCKVECTOR_BLOCK (bv
, i
);
456 depth
= block_depth (b
) * 2;
457 print_spaces (depth
, outfile
);
458 fprintf_filtered (outfile
, "block #%03d, object at ", i
);
459 gdb_print_host_address (b
, outfile
);
460 if (BLOCK_SUPERBLOCK (b
))
462 fprintf_filtered (outfile
, " under ");
463 gdb_print_host_address (BLOCK_SUPERBLOCK (b
), outfile
);
465 /* drow/2002-07-10: We could save the total symbols count
466 even if we're using a hashtable, but nothing else but this message
468 fprintf_filtered (outfile
, ", %d syms/buckets in ",
469 dict_size (BLOCK_DICT (b
)));
470 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), outfile
);
471 fprintf_filtered (outfile
, "..");
472 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), outfile
);
473 if (BLOCK_FUNCTION (b
))
475 fprintf_filtered (outfile
, ", function %s",
476 SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b
)));
477 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b
)) != NULL
)
479 fprintf_filtered (outfile
, ", %s",
480 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b
)));
483 fprintf_filtered (outfile
, "\n");
484 /* Now print each symbol in this block (in no particular order, if
485 we're using a hashtable). */
486 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
488 struct print_symbol_args s
;
493 catch_errors (print_symbol
, &s
, "Error printing symbol:\n",
497 fprintf_filtered (outfile
, "\n");
501 fprintf_filtered (outfile
, "\nBlockvector same as previous symtab\n\n");
506 dump_symtab (struct objfile
*objfile
, struct symtab
*symtab
,
507 struct ui_file
*outfile
)
509 /* Set the current language to the language of the symtab we're dumping
510 because certain routines used during dump_symtab() use the current
511 language to print an image of the symbol. We'll restore it later.
512 But use only real languages, not placeholders. */
513 if (symtab
->language
!= language_unknown
514 && symtab
->language
!= language_auto
)
516 enum language saved_lang
;
518 saved_lang
= set_language (symtab
->language
);
520 dump_symtab_1 (objfile
, symtab
, outfile
);
522 set_language (saved_lang
);
525 dump_symtab_1 (objfile
, symtab
, outfile
);
529 maintenance_print_symbols (char *args
, int from_tty
)
532 struct ui_file
*outfile
;
533 struct cleanup
*cleanups
;
534 char *symname
= NULL
;
535 char *filename
= DEV_TTY
;
536 struct objfile
*objfile
;
544 Arguments missing: an output file name and an optional symbol file name"));
546 argv
= gdb_buildargv (args
);
547 cleanups
= make_cleanup_freeargv (argv
);
552 /* If a second arg is supplied, it is a source file name to match on */
559 filename
= tilde_expand (filename
);
560 make_cleanup (xfree
, filename
);
562 outfile
= gdb_fopen (filename
, FOPEN_WT
);
564 perror_with_name (filename
);
565 make_cleanup_ui_file_delete (outfile
);
568 ALL_SYMTABS (objfile
, s
)
569 if (symname
== NULL
|| strcmp (symname
, s
->filename
) == 0)
570 dump_symtab (objfile
, s
, outfile
);
572 do_cleanups (cleanups
);
575 /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
576 far to indent. ARGS is really a struct print_symbol_args *, but is
577 declared as char * to get it past catch_errors. Returns 0 for error,
581 print_symbol (void *args
)
583 struct gdbarch
*gdbarch
= ((struct print_symbol_args
*) args
)->gdbarch
;
584 struct symbol
*symbol
= ((struct print_symbol_args
*) args
)->symbol
;
585 int depth
= ((struct print_symbol_args
*) args
)->depth
;
586 struct ui_file
*outfile
= ((struct print_symbol_args
*) args
)->outfile
;
587 struct obj_section
*section
= SYMBOL_OBJ_SECTION (symbol
);
589 print_spaces (depth
, outfile
);
590 if (SYMBOL_DOMAIN (symbol
) == LABEL_DOMAIN
)
592 fprintf_filtered (outfile
, "label %s at ", SYMBOL_PRINT_NAME (symbol
));
593 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
596 fprintf_filtered (outfile
, " section %s\n",
597 bfd_section_name (section
->the_bfd_section
->owner
,
598 section
->the_bfd_section
));
600 fprintf_filtered (outfile
, "\n");
603 if (SYMBOL_DOMAIN (symbol
) == STRUCT_DOMAIN
)
605 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol
)))
607 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
);
611 fprintf_filtered (outfile
, "%s %s = ",
612 (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_ENUM
614 : (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_STRUCT
615 ? "struct" : "union")),
616 SYMBOL_LINKAGE_NAME (symbol
));
617 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
);
619 fprintf_filtered (outfile
, ";\n");
623 if (SYMBOL_CLASS (symbol
) == LOC_TYPEDEF
)
624 fprintf_filtered (outfile
, "typedef ");
625 if (SYMBOL_TYPE (symbol
))
627 /* Print details of types, except for enums where it's clutter. */
628 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), SYMBOL_PRINT_NAME (symbol
),
630 TYPE_CODE (SYMBOL_TYPE (symbol
)) != TYPE_CODE_ENUM
,
632 fprintf_filtered (outfile
, "; ");
635 fprintf_filtered (outfile
, "%s ", SYMBOL_PRINT_NAME (symbol
));
637 switch (SYMBOL_CLASS (symbol
))
640 fprintf_filtered (outfile
, "const %ld (0x%lx)",
641 SYMBOL_VALUE (symbol
),
642 SYMBOL_VALUE (symbol
));
645 case LOC_CONST_BYTES
:
648 struct type
*type
= check_typedef (SYMBOL_TYPE (symbol
));
649 fprintf_filtered (outfile
, "const %u hex bytes:",
651 for (i
= 0; i
< TYPE_LENGTH (type
); i
++)
652 fprintf_filtered (outfile
, " %02x",
653 (unsigned) SYMBOL_VALUE_BYTES (symbol
)[i
]);
658 fprintf_filtered (outfile
, "static at ");
659 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
662 fprintf_filtered (outfile
, " section %s",
663 bfd_section_name (section
->the_bfd_section
->owner
,
664 section
->the_bfd_section
));
668 if (SYMBOL_IS_ARGUMENT (symbol
))
669 fprintf_filtered (outfile
, "parameter register %ld",
670 SYMBOL_VALUE (symbol
));
672 fprintf_filtered (outfile
, "register %ld", SYMBOL_VALUE (symbol
));
676 fprintf_filtered (outfile
, "arg at offset 0x%lx",
677 SYMBOL_VALUE (symbol
));
681 fprintf_filtered (outfile
, "reference arg at 0x%lx", SYMBOL_VALUE (symbol
));
684 case LOC_REGPARM_ADDR
:
685 fprintf_filtered (outfile
, "address parameter register %ld", SYMBOL_VALUE (symbol
));
689 fprintf_filtered (outfile
, "local at offset 0x%lx",
690 SYMBOL_VALUE (symbol
));
697 fprintf_filtered (outfile
, "label at ");
698 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
701 fprintf_filtered (outfile
, " section %s",
702 bfd_section_name (section
->the_bfd_section
->owner
,
703 section
->the_bfd_section
));
707 fprintf_filtered (outfile
, "block object ");
708 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol
), outfile
);
709 fprintf_filtered (outfile
, ", ");
710 fputs_filtered (paddress (gdbarch
,
711 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
))),
713 fprintf_filtered (outfile
, "..");
714 fputs_filtered (paddress (gdbarch
,
715 BLOCK_END (SYMBOL_BLOCK_VALUE (symbol
))),
718 fprintf_filtered (outfile
, " section %s",
719 bfd_section_name (section
->the_bfd_section
->owner
,
720 section
->the_bfd_section
));
724 fprintf_filtered (outfile
, "computed at runtime");
728 fprintf_filtered (outfile
, "unresolved");
731 case LOC_OPTIMIZED_OUT
:
732 fprintf_filtered (outfile
, "optimized out");
736 fprintf_filtered (outfile
, "botched symbol class %x",
737 SYMBOL_CLASS (symbol
));
741 fprintf_filtered (outfile
, "\n");
746 maintenance_print_psymbols (char *args
, int from_tty
)
749 struct ui_file
*outfile
;
750 struct cleanup
*cleanups
;
751 char *symname
= NULL
;
752 char *filename
= DEV_TTY
;
753 struct objfile
*objfile
;
754 struct partial_symtab
*ps
;
760 error (_("print-psymbols takes an output file name and optional symbol file name"));
762 argv
= gdb_buildargv (args
);
763 cleanups
= make_cleanup_freeargv (argv
);
768 /* If a second arg is supplied, it is a source file name to match on */
775 filename
= tilde_expand (filename
);
776 make_cleanup (xfree
, filename
);
778 outfile
= gdb_fopen (filename
, FOPEN_WT
);
780 perror_with_name (filename
);
781 make_cleanup_ui_file_delete (outfile
);
784 ALL_PSYMTABS (objfile
, ps
)
785 if (symname
== NULL
|| strcmp (symname
, ps
->filename
) == 0)
786 dump_psymtab (objfile
, ps
, outfile
);
788 do_cleanups (cleanups
);
792 print_partial_symbols (struct gdbarch
*gdbarch
,
793 struct partial_symbol
**p
, int count
, char *what
,
794 struct ui_file
*outfile
)
796 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
799 fprintf_filtered (outfile
, " `%s'", SYMBOL_LINKAGE_NAME (*p
));
800 if (SYMBOL_DEMANGLED_NAME (*p
) != NULL
)
802 fprintf_filtered (outfile
, " `%s'", SYMBOL_DEMANGLED_NAME (*p
));
804 fputs_filtered (", ", outfile
);
805 switch (SYMBOL_DOMAIN (*p
))
808 fputs_filtered ("undefined domain, ", outfile
);
811 /* This is the usual thing -- don't print it */
814 fputs_filtered ("struct domain, ", outfile
);
817 fputs_filtered ("label domain, ", outfile
);
820 fputs_filtered ("<invalid domain>, ", outfile
);
823 switch (SYMBOL_CLASS (*p
))
826 fputs_filtered ("undefined", outfile
);
829 fputs_filtered ("constant int", outfile
);
832 fputs_filtered ("static", outfile
);
835 fputs_filtered ("register", outfile
);
838 fputs_filtered ("pass by value", outfile
);
841 fputs_filtered ("pass by reference", outfile
);
843 case LOC_REGPARM_ADDR
:
844 fputs_filtered ("register address parameter", outfile
);
847 fputs_filtered ("stack parameter", outfile
);
850 fputs_filtered ("type", outfile
);
853 fputs_filtered ("label", outfile
);
856 fputs_filtered ("function", outfile
);
858 case LOC_CONST_BYTES
:
859 fputs_filtered ("constant bytes", outfile
);
862 fputs_filtered ("unresolved", outfile
);
864 case LOC_OPTIMIZED_OUT
:
865 fputs_filtered ("optimized out", outfile
);
868 fputs_filtered ("computed at runtime", outfile
);
871 fputs_filtered ("<invalid location>", outfile
);
874 fputs_filtered (", ", outfile
);
875 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (*p
)), outfile
);
876 fprintf_filtered (outfile
, "\n");
882 maintenance_print_msymbols (char *args
, int from_tty
)
885 struct ui_file
*outfile
;
886 struct cleanup
*cleanups
;
887 char *filename
= DEV_TTY
;
888 char *symname
= NULL
;
889 struct objfile
*objfile
;
891 struct stat sym_st
, obj_st
;
897 error (_("print-msymbols takes an output file name and optional symbol file name"));
899 argv
= gdb_buildargv (args
);
900 cleanups
= make_cleanup_freeargv (argv
);
905 /* If a second arg is supplied, it is a source file name to match on */
908 symname
= xfullpath (argv
[1]);
909 make_cleanup (xfree
, symname
);
910 if (symname
&& stat (symname
, &sym_st
))
911 perror_with_name (symname
);
915 filename
= tilde_expand (filename
);
916 make_cleanup (xfree
, filename
);
918 outfile
= gdb_fopen (filename
, FOPEN_WT
);
920 perror_with_name (filename
);
921 make_cleanup_ui_file_delete (outfile
);
924 ALL_OBJFILES (objfile
)
926 || (!stat (objfile
->name
, &obj_st
) && sym_st
.st_ino
== obj_st
.st_ino
))
927 dump_msymbols (objfile
, outfile
);
929 fprintf_filtered (outfile
, "\n\n");
930 do_cleanups (cleanups
);
934 maintenance_print_objfiles (char *ignore
, int from_tty
)
936 struct objfile
*objfile
;
941 ALL_OBJFILES (objfile
)
942 dump_objfile (objfile
);
947 /* List all the symbol tables whose names match REGEXP (optional). */
949 maintenance_info_symtabs (char *regexp
, int from_tty
)
951 struct objfile
*objfile
;
956 ALL_OBJFILES (objfile
)
958 struct symtab
*symtab
;
960 /* We don't want to print anything for this objfile until we
961 actually find a symtab whose name matches. */
962 int printed_objfile_start
= 0;
964 ALL_OBJFILE_SYMTABS (objfile
, symtab
)
969 || re_exec (symtab
->filename
))
971 if (! printed_objfile_start
)
973 printf_filtered ("{ objfile %s ", objfile
->name
);
975 printf_filtered ("((struct objfile *) %s)\n",
976 host_address_to_string (objfile
));
977 printed_objfile_start
= 1;
980 printf_filtered (" { symtab %s ", symtab
->filename
);
982 printf_filtered ("((struct symtab *) %s)\n",
983 host_address_to_string (symtab
));
984 printf_filtered (" dirname %s\n",
985 symtab
->dirname
? symtab
->dirname
: "(null)");
986 printf_filtered (" fullname %s\n",
987 symtab
->fullname
? symtab
->fullname
: "(null)");
988 printf_filtered (" blockvector ((struct blockvector *) %s)%s\n",
989 host_address_to_string (symtab
->blockvector
),
990 symtab
->primary
? " (primary)" : "");
991 printf_filtered (" linetable ((struct linetable *) %s)\n",
992 host_address_to_string (symtab
->linetable
));
993 printf_filtered (" debugformat %s\n", symtab
->debugformat
);
994 printf_filtered (" }\n");
998 if (printed_objfile_start
)
999 printf_filtered ("}\n");
1004 /* List all the partial symbol tables whose names match REGEXP (optional). */
1006 maintenance_info_psymtabs (char *regexp
, int from_tty
)
1008 struct objfile
*objfile
;
1013 ALL_OBJFILES (objfile
)
1015 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1016 struct partial_symtab
*psymtab
;
1018 /* We don't want to print anything for this objfile until we
1019 actually find a symtab whose name matches. */
1020 int printed_objfile_start
= 0;
1022 ALL_OBJFILE_PSYMTABS (objfile
, psymtab
)
1027 || re_exec (psymtab
->filename
))
1029 if (! printed_objfile_start
)
1031 printf_filtered ("{ objfile %s ", objfile
->name
);
1033 printf_filtered ("((struct objfile *) %s)\n",
1034 host_address_to_string (objfile
));
1035 printed_objfile_start
= 1;
1038 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1040 printf_filtered ("((struct partial_symtab *) %s)\n",
1041 host_address_to_string (psymtab
));
1043 printf_filtered (" readin %s\n",
1044 psymtab
->readin
? "yes" : "no");
1045 printf_filtered (" fullname %s\n",
1046 psymtab
->fullname
? psymtab
->fullname
: "(null)");
1047 printf_filtered (" text addresses ");
1048 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
),
1050 printf_filtered (" -- ");
1051 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
),
1053 printf_filtered ("\n");
1054 printf_filtered (" globals ");
1055 if (psymtab
->n_global_syms
)
1057 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1058 host_address_to_string (psymtab
->objfile
->global_psymbols
.list
1059 + psymtab
->globals_offset
),
1060 psymtab
->n_global_syms
);
1063 printf_filtered ("(none)\n");
1064 printf_filtered (" statics ");
1065 if (psymtab
->n_static_syms
)
1067 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1068 host_address_to_string (psymtab
->objfile
->static_psymbols
.list
1069 + psymtab
->statics_offset
),
1070 psymtab
->n_static_syms
);
1073 printf_filtered ("(none)\n");
1074 printf_filtered (" dependencies ");
1075 if (psymtab
->number_of_dependencies
)
1079 printf_filtered ("{\n");
1080 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1082 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
1084 /* Note the string concatenation there --- no comma. */
1085 printf_filtered (" psymtab %s "
1086 "((struct partial_symtab *) %s)\n",
1088 host_address_to_string (dep
));
1090 printf_filtered (" }\n");
1093 printf_filtered ("(none)\n");
1094 printf_filtered (" }\n");
1098 if (printed_objfile_start
)
1099 printf_filtered ("}\n");
1104 /* Check consistency of psymtabs and symtabs. */
1107 maintenance_check_symtabs (char *ignore
, int from_tty
)
1110 struct partial_symbol
**psym
;
1111 struct symtab
*s
= NULL
;
1112 struct partial_symtab
*ps
;
1113 struct blockvector
*bv
;
1114 struct objfile
*objfile
;
1118 ALL_PSYMTABS (objfile
, ps
)
1120 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1121 s
= PSYMTAB_TO_SYMTAB (ps
);
1124 bv
= BLOCKVECTOR (s
);
1125 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1126 psym
= ps
->objfile
->static_psymbols
.list
+ ps
->statics_offset
;
1127 length
= ps
->n_static_syms
;
1130 sym
= lookup_block_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
1131 NULL
, SYMBOL_DOMAIN (*psym
));
1134 printf_filtered ("Static symbol `");
1135 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
1136 printf_filtered ("' only found in ");
1137 puts_filtered (ps
->filename
);
1138 printf_filtered (" psymtab\n");
1142 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1143 psym
= ps
->objfile
->global_psymbols
.list
+ ps
->globals_offset
;
1144 length
= ps
->n_global_syms
;
1147 sym
= lookup_block_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
1148 NULL
, SYMBOL_DOMAIN (*psym
));
1151 printf_filtered ("Global symbol `");
1152 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
1153 printf_filtered ("' only found in ");
1154 puts_filtered (ps
->filename
);
1155 printf_filtered (" psymtab\n");
1159 if (ps
->texthigh
< ps
->textlow
)
1161 printf_filtered ("Psymtab ");
1162 puts_filtered (ps
->filename
);
1163 printf_filtered (" covers bad range ");
1164 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
1165 printf_filtered (" - ");
1166 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
1167 printf_filtered ("\n");
1170 if (ps
->texthigh
== 0)
1172 if (ps
->textlow
< BLOCK_START (b
) || ps
->texthigh
> BLOCK_END (b
))
1174 printf_filtered ("Psymtab ");
1175 puts_filtered (ps
->filename
);
1176 printf_filtered (" covers ");
1177 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
1178 printf_filtered (" - ");
1179 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
1180 printf_filtered (" but symtab covers only ");
1181 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
1182 printf_filtered (" - ");
1183 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
1184 printf_filtered ("\n");
1190 /* Return the nexting depth of a block within other blocks in its symtab. */
1193 block_depth (struct block
*block
)
1196 while ((block
= BLOCK_SUPERBLOCK (block
)) != NULL
)
1204 /* Increase the space allocated for LISTP, which is probably
1205 global_psymbols or static_psymbols. This space will eventually
1206 be freed in free_objfile(). */
1209 extend_psymbol_list (struct psymbol_allocation_list
*listp
,
1210 struct objfile
*objfile
)
1213 if (listp
->size
== 0)
1216 listp
->list
= (struct partial_symbol
**)
1217 xmalloc (new_size
* sizeof (struct partial_symbol
*));
1221 new_size
= listp
->size
* 2;
1222 listp
->list
= (struct partial_symbol
**)
1223 xrealloc ((char *) listp
->list
,
1224 new_size
* sizeof (struct partial_symbol
*));
1226 /* Next assumes we only went one over. Should be good if
1227 program works correctly */
1228 listp
->next
= listp
->list
+ listp
->size
;
1229 listp
->size
= new_size
;
1233 /* Do early runtime initializations. */
1235 _initialize_symmisc (void)
This page took 0.05456 seconds and 4 git commands to generate.