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 program_space
*pspace
;
134 struct objfile
*objfile
;
138 ALL_PSPACE_OBJFILES (pspace
, objfile
)
140 printf_filtered (_("Byte cache statistics for '%s':\n"), objfile
->name
);
141 print_bcache_statistics (objfile
->psymbol_cache
, "partial symbol cache");
142 print_bcache_statistics (objfile
->macro_cache
, "preprocessor macro cache");
148 print_objfile_statistics (void)
150 struct program_space
*pspace
;
151 struct objfile
*objfile
;
153 struct partial_symtab
*ps
;
154 int i
, linetables
, blockvectors
;
158 ALL_PSPACE_OBJFILES (pspace
, objfile
)
160 printf_filtered (_("Statistics for '%s':\n"), objfile
->name
);
161 if (OBJSTAT (objfile
, n_stabs
) > 0)
162 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
163 OBJSTAT (objfile
, n_stabs
));
164 if (OBJSTAT (objfile
, n_minsyms
) > 0)
165 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
166 OBJSTAT (objfile
, n_minsyms
));
167 if (OBJSTAT (objfile
, n_psyms
) > 0)
168 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
169 OBJSTAT (objfile
, n_psyms
));
170 if (OBJSTAT (objfile
, n_syms
) > 0)
171 printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
172 OBJSTAT (objfile
, n_syms
));
173 if (OBJSTAT (objfile
, n_types
) > 0)
174 printf_filtered (_(" Number of \"types\" defined: %d\n"),
175 OBJSTAT (objfile
, n_types
));
177 ALL_OBJFILE_PSYMTABS (objfile
, ps
)
182 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i
);
183 i
= linetables
= blockvectors
= 0;
184 ALL_OBJFILE_SYMTABS (objfile
, s
)
187 if (s
->linetable
!= NULL
)
192 printf_filtered (_(" Number of symbol tables: %d\n"), i
);
193 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
195 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
198 if (OBJSTAT (objfile
, sz_strtab
) > 0)
199 printf_filtered (_(" Space used by a.out string tables: %d\n"),
200 OBJSTAT (objfile
, sz_strtab
));
201 printf_filtered (_(" Total memory used for objfile obstack: %d\n"),
202 obstack_memory_used (&objfile
->objfile_obstack
));
203 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
204 bcache_memory_used (objfile
->psymbol_cache
));
205 printf_filtered (_(" Total memory used for macro cache: %d\n"),
206 bcache_memory_used (objfile
->macro_cache
));
212 dump_objfile (struct objfile
*objfile
)
214 struct symtab
*symtab
;
215 struct partial_symtab
*psymtab
;
217 printf_filtered ("\nObject file %s: ", objfile
->name
);
218 printf_filtered ("Objfile at ");
219 gdb_print_host_address (objfile
, gdb_stdout
);
220 printf_filtered (", bfd at ");
221 gdb_print_host_address (objfile
->obfd
, gdb_stdout
);
222 printf_filtered (", %d minsyms\n\n",
223 objfile
->minimal_symbol_count
);
225 if (objfile
->psymtabs
)
227 printf_filtered ("Psymtabs:\n");
228 for (psymtab
= objfile
->psymtabs
;
230 psymtab
= psymtab
->next
)
232 printf_filtered ("%s at ",
234 gdb_print_host_address (psymtab
, gdb_stdout
);
235 printf_filtered (", ");
236 if (psymtab
->objfile
!= objfile
)
238 printf_filtered ("NOT ON CHAIN! ");
242 printf_filtered ("\n\n");
245 if (objfile
->symtabs
)
247 printf_filtered ("Symtabs:\n");
248 for (symtab
= objfile
->symtabs
;
250 symtab
= symtab
->next
)
252 printf_filtered ("%s at ", symtab
->filename
);
253 gdb_print_host_address (symtab
, gdb_stdout
);
254 printf_filtered (", ");
255 if (symtab
->objfile
!= objfile
)
257 printf_filtered ("NOT ON CHAIN! ");
261 printf_filtered ("\n\n");
265 /* Print minimal symbols from this objfile. */
268 dump_msymbols (struct objfile
*objfile
, struct ui_file
*outfile
)
270 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
271 struct minimal_symbol
*msymbol
;
275 fprintf_filtered (outfile
, "\nObject file %s:\n\n", objfile
->name
);
276 if (objfile
->minimal_symbol_count
== 0)
278 fprintf_filtered (outfile
, "No minimal symbols found.\n");
282 ALL_OBJFILE_MSYMBOLS (objfile
, msymbol
)
284 struct obj_section
*section
= SYMBOL_OBJ_SECTION (msymbol
);
286 switch (MSYMBOL_TYPE (msymbol
))
294 case mst_solib_trampoline
:
319 fprintf_filtered (outfile
, "[%2d] %c ", index
, ms_type
);
320 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (msymbol
)),
322 fprintf_filtered (outfile
, " %s", SYMBOL_LINKAGE_NAME (msymbol
));
324 fprintf_filtered (outfile
, " section %s",
325 bfd_section_name (objfile
->obfd
,
326 section
->the_bfd_section
));
327 if (SYMBOL_DEMANGLED_NAME (msymbol
) != NULL
)
329 fprintf_filtered (outfile
, " %s", SYMBOL_DEMANGLED_NAME (msymbol
));
331 if (msymbol
->filename
)
332 fprintf_filtered (outfile
, " %s", msymbol
->filename
);
333 fputs_filtered ("\n", outfile
);
336 if (objfile
->minimal_symbol_count
!= index
)
338 warning (_("internal error: minimal symbol count %d != %d"),
339 objfile
->minimal_symbol_count
, index
);
341 fprintf_filtered (outfile
, "\n");
345 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
346 struct ui_file
*outfile
)
348 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
351 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
353 fprintf_filtered (outfile
, "(object ");
354 gdb_print_host_address (psymtab
, outfile
);
355 fprintf_filtered (outfile
, ")\n\n");
356 fprintf_unfiltered (outfile
, " Read from object file %s (",
358 gdb_print_host_address (objfile
, outfile
);
359 fprintf_unfiltered (outfile
, ")\n");
363 fprintf_filtered (outfile
,
364 " Full symtab was read (at ");
365 gdb_print_host_address (psymtab
->symtab
, outfile
);
366 fprintf_filtered (outfile
, " by function at ");
367 gdb_print_host_address (psymtab
->read_symtab
, outfile
);
368 fprintf_filtered (outfile
, ")\n");
371 fprintf_filtered (outfile
, " Relocate symbols by ");
372 for (i
= 0; i
< psymtab
->objfile
->num_sections
; ++i
)
375 fprintf_filtered (outfile
, ", ");
377 fputs_filtered (paddress (gdbarch
,
378 ANOFFSET (psymtab
->section_offsets
, i
)),
381 fprintf_filtered (outfile
, "\n");
383 fprintf_filtered (outfile
, " Symbols cover text addresses ");
384 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
), outfile
);
385 fprintf_filtered (outfile
, "-");
386 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
), outfile
);
387 fprintf_filtered (outfile
, "\n");
388 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
389 psymtab
->number_of_dependencies
);
390 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
392 fprintf_filtered (outfile
, " %d ", i
);
393 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
394 fprintf_filtered (outfile
, " %s\n",
395 psymtab
->dependencies
[i
]->filename
);
397 if (psymtab
->n_global_syms
> 0)
399 print_partial_symbols (gdbarch
,
400 objfile
->global_psymbols
.list
401 + psymtab
->globals_offset
,
402 psymtab
->n_global_syms
, "Global", outfile
);
404 if (psymtab
->n_static_syms
> 0)
406 print_partial_symbols (gdbarch
,
407 objfile
->static_psymbols
.list
408 + psymtab
->statics_offset
,
409 psymtab
->n_static_syms
, "Static", outfile
);
411 fprintf_filtered (outfile
, "\n");
415 dump_symtab_1 (struct objfile
*objfile
, struct symtab
*symtab
,
416 struct ui_file
*outfile
)
418 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
420 struct dict_iterator iter
;
423 struct blockvector
*bv
;
428 fprintf_filtered (outfile
, "\nSymtab for file %s\n", symtab
->filename
);
430 fprintf_filtered (outfile
, "Compilation directory is %s\n",
432 fprintf_filtered (outfile
, "Read from object file %s (", objfile
->name
);
433 gdb_print_host_address (objfile
, outfile
);
434 fprintf_filtered (outfile
, ")\n");
435 fprintf_filtered (outfile
, "Language: %s\n", language_str (symtab
->language
));
437 /* First print the line table. */
438 l
= LINETABLE (symtab
);
441 fprintf_filtered (outfile
, "\nLine table:\n\n");
443 for (i
= 0; i
< len
; i
++)
445 fprintf_filtered (outfile
, " line %d at ", l
->item
[i
].line
);
446 fputs_filtered (paddress (gdbarch
, l
->item
[i
].pc
), outfile
);
447 fprintf_filtered (outfile
, "\n");
450 /* Now print the block info, but only for primary symtabs since we will
451 print lots of duplicate info otherwise. */
454 fprintf_filtered (outfile
, "\nBlockvector:\n\n");
455 bv
= BLOCKVECTOR (symtab
);
456 len
= BLOCKVECTOR_NBLOCKS (bv
);
457 for (i
= 0; i
< len
; i
++)
459 b
= BLOCKVECTOR_BLOCK (bv
, i
);
460 depth
= block_depth (b
) * 2;
461 print_spaces (depth
, outfile
);
462 fprintf_filtered (outfile
, "block #%03d, object at ", i
);
463 gdb_print_host_address (b
, outfile
);
464 if (BLOCK_SUPERBLOCK (b
))
466 fprintf_filtered (outfile
, " under ");
467 gdb_print_host_address (BLOCK_SUPERBLOCK (b
), outfile
);
469 /* drow/2002-07-10: We could save the total symbols count
470 even if we're using a hashtable, but nothing else but this message
472 fprintf_filtered (outfile
, ", %d syms/buckets in ",
473 dict_size (BLOCK_DICT (b
)));
474 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), outfile
);
475 fprintf_filtered (outfile
, "..");
476 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), outfile
);
477 if (BLOCK_FUNCTION (b
))
479 fprintf_filtered (outfile
, ", function %s",
480 SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b
)));
481 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b
)) != NULL
)
483 fprintf_filtered (outfile
, ", %s",
484 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b
)));
487 fprintf_filtered (outfile
, "\n");
488 /* Now print each symbol in this block (in no particular order, if
489 we're using a hashtable). */
490 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
492 struct print_symbol_args s
;
497 catch_errors (print_symbol
, &s
, "Error printing symbol:\n",
501 fprintf_filtered (outfile
, "\n");
505 fprintf_filtered (outfile
, "\nBlockvector same as previous symtab\n\n");
510 dump_symtab (struct objfile
*objfile
, struct symtab
*symtab
,
511 struct ui_file
*outfile
)
513 /* Set the current language to the language of the symtab we're dumping
514 because certain routines used during dump_symtab() use the current
515 language to print an image of the symbol. We'll restore it later.
516 But use only real languages, not placeholders. */
517 if (symtab
->language
!= language_unknown
518 && symtab
->language
!= language_auto
)
520 enum language saved_lang
;
522 saved_lang
= set_language (symtab
->language
);
524 dump_symtab_1 (objfile
, symtab
, outfile
);
526 set_language (saved_lang
);
529 dump_symtab_1 (objfile
, symtab
, outfile
);
533 maintenance_print_symbols (char *args
, int from_tty
)
536 struct ui_file
*outfile
;
537 struct cleanup
*cleanups
;
538 char *symname
= NULL
;
539 char *filename
= DEV_TTY
;
540 struct objfile
*objfile
;
548 Arguments missing: an output file name and an optional symbol file name"));
550 argv
= gdb_buildargv (args
);
551 cleanups
= make_cleanup_freeargv (argv
);
556 /* If a second arg is supplied, it is a source file name to match on */
563 filename
= tilde_expand (filename
);
564 make_cleanup (xfree
, filename
);
566 outfile
= gdb_fopen (filename
, FOPEN_WT
);
568 perror_with_name (filename
);
569 make_cleanup_ui_file_delete (outfile
);
572 ALL_SYMTABS (objfile
, s
)
573 if (symname
== NULL
|| strcmp (symname
, s
->filename
) == 0)
574 dump_symtab (objfile
, s
, outfile
);
576 do_cleanups (cleanups
);
579 /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
580 far to indent. ARGS is really a struct print_symbol_args *, but is
581 declared as char * to get it past catch_errors. Returns 0 for error,
585 print_symbol (void *args
)
587 struct gdbarch
*gdbarch
= ((struct print_symbol_args
*) args
)->gdbarch
;
588 struct symbol
*symbol
= ((struct print_symbol_args
*) args
)->symbol
;
589 int depth
= ((struct print_symbol_args
*) args
)->depth
;
590 struct ui_file
*outfile
= ((struct print_symbol_args
*) args
)->outfile
;
591 struct obj_section
*section
= SYMBOL_OBJ_SECTION (symbol
);
593 print_spaces (depth
, outfile
);
594 if (SYMBOL_DOMAIN (symbol
) == LABEL_DOMAIN
)
596 fprintf_filtered (outfile
, "label %s at ", SYMBOL_PRINT_NAME (symbol
));
597 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
600 fprintf_filtered (outfile
, " section %s\n",
601 bfd_section_name (section
->the_bfd_section
->owner
,
602 section
->the_bfd_section
));
604 fprintf_filtered (outfile
, "\n");
607 if (SYMBOL_DOMAIN (symbol
) == STRUCT_DOMAIN
)
609 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol
)))
611 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
);
615 fprintf_filtered (outfile
, "%s %s = ",
616 (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_ENUM
618 : (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_STRUCT
619 ? "struct" : "union")),
620 SYMBOL_LINKAGE_NAME (symbol
));
621 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
);
623 fprintf_filtered (outfile
, ";\n");
627 if (SYMBOL_CLASS (symbol
) == LOC_TYPEDEF
)
628 fprintf_filtered (outfile
, "typedef ");
629 if (SYMBOL_TYPE (symbol
))
631 /* Print details of types, except for enums where it's clutter. */
632 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), SYMBOL_PRINT_NAME (symbol
),
634 TYPE_CODE (SYMBOL_TYPE (symbol
)) != TYPE_CODE_ENUM
,
636 fprintf_filtered (outfile
, "; ");
639 fprintf_filtered (outfile
, "%s ", SYMBOL_PRINT_NAME (symbol
));
641 switch (SYMBOL_CLASS (symbol
))
644 fprintf_filtered (outfile
, "const %ld (0x%lx)",
645 SYMBOL_VALUE (symbol
),
646 SYMBOL_VALUE (symbol
));
649 case LOC_CONST_BYTES
:
652 struct type
*type
= check_typedef (SYMBOL_TYPE (symbol
));
653 fprintf_filtered (outfile
, "const %u hex bytes:",
655 for (i
= 0; i
< TYPE_LENGTH (type
); i
++)
656 fprintf_filtered (outfile
, " %02x",
657 (unsigned) SYMBOL_VALUE_BYTES (symbol
)[i
]);
662 fprintf_filtered (outfile
, "static at ");
663 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
666 fprintf_filtered (outfile
, " section %s",
667 bfd_section_name (section
->the_bfd_section
->owner
,
668 section
->the_bfd_section
));
672 if (SYMBOL_IS_ARGUMENT (symbol
))
673 fprintf_filtered (outfile
, "parameter register %ld",
674 SYMBOL_VALUE (symbol
));
676 fprintf_filtered (outfile
, "register %ld", SYMBOL_VALUE (symbol
));
680 fprintf_filtered (outfile
, "arg at offset 0x%lx",
681 SYMBOL_VALUE (symbol
));
685 fprintf_filtered (outfile
, "reference arg at 0x%lx", SYMBOL_VALUE (symbol
));
688 case LOC_REGPARM_ADDR
:
689 fprintf_filtered (outfile
, "address parameter register %ld", SYMBOL_VALUE (symbol
));
693 fprintf_filtered (outfile
, "local at offset 0x%lx",
694 SYMBOL_VALUE (symbol
));
701 fprintf_filtered (outfile
, "label at ");
702 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (symbol
)),
705 fprintf_filtered (outfile
, " section %s",
706 bfd_section_name (section
->the_bfd_section
->owner
,
707 section
->the_bfd_section
));
711 fprintf_filtered (outfile
, "block object ");
712 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol
), outfile
);
713 fprintf_filtered (outfile
, ", ");
714 fputs_filtered (paddress (gdbarch
,
715 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
))),
717 fprintf_filtered (outfile
, "..");
718 fputs_filtered (paddress (gdbarch
,
719 BLOCK_END (SYMBOL_BLOCK_VALUE (symbol
))),
722 fprintf_filtered (outfile
, " section %s",
723 bfd_section_name (section
->the_bfd_section
->owner
,
724 section
->the_bfd_section
));
728 fprintf_filtered (outfile
, "computed at runtime");
732 fprintf_filtered (outfile
, "unresolved");
735 case LOC_OPTIMIZED_OUT
:
736 fprintf_filtered (outfile
, "optimized out");
740 fprintf_filtered (outfile
, "botched symbol class %x",
741 SYMBOL_CLASS (symbol
));
745 fprintf_filtered (outfile
, "\n");
750 maintenance_print_psymbols (char *args
, int from_tty
)
753 struct ui_file
*outfile
;
754 struct cleanup
*cleanups
;
755 char *symname
= NULL
;
756 char *filename
= DEV_TTY
;
757 struct objfile
*objfile
;
758 struct partial_symtab
*ps
;
764 error (_("print-psymbols takes an output file name and optional symbol file name"));
766 argv
= gdb_buildargv (args
);
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
|| strcmp (symname
, ps
->filename
) == 0)
790 dump_psymtab (objfile
, ps
, outfile
);
792 do_cleanups (cleanups
);
796 print_partial_symbols (struct gdbarch
*gdbarch
,
797 struct partial_symbol
**p
, int count
, char *what
,
798 struct ui_file
*outfile
)
800 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
803 fprintf_filtered (outfile
, " `%s'", SYMBOL_LINKAGE_NAME (*p
));
804 if (SYMBOL_DEMANGLED_NAME (*p
) != NULL
)
806 fprintf_filtered (outfile
, " `%s'", SYMBOL_DEMANGLED_NAME (*p
));
808 fputs_filtered (", ", outfile
);
809 switch (SYMBOL_DOMAIN (*p
))
812 fputs_filtered ("undefined domain, ", outfile
);
815 /* This is the usual thing -- don't print it */
818 fputs_filtered ("struct domain, ", outfile
);
821 fputs_filtered ("label domain, ", outfile
);
824 fputs_filtered ("<invalid domain>, ", outfile
);
827 switch (SYMBOL_CLASS (*p
))
830 fputs_filtered ("undefined", outfile
);
833 fputs_filtered ("constant int", outfile
);
836 fputs_filtered ("static", outfile
);
839 fputs_filtered ("register", outfile
);
842 fputs_filtered ("pass by value", outfile
);
845 fputs_filtered ("pass by reference", outfile
);
847 case LOC_REGPARM_ADDR
:
848 fputs_filtered ("register address parameter", outfile
);
851 fputs_filtered ("stack parameter", outfile
);
854 fputs_filtered ("type", outfile
);
857 fputs_filtered ("label", outfile
);
860 fputs_filtered ("function", outfile
);
862 case LOC_CONST_BYTES
:
863 fputs_filtered ("constant bytes", outfile
);
866 fputs_filtered ("unresolved", outfile
);
868 case LOC_OPTIMIZED_OUT
:
869 fputs_filtered ("optimized out", outfile
);
872 fputs_filtered ("computed at runtime", outfile
);
875 fputs_filtered ("<invalid location>", outfile
);
878 fputs_filtered (", ", outfile
);
879 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (*p
)), outfile
);
880 fprintf_filtered (outfile
, "\n");
886 maintenance_print_msymbols (char *args
, int from_tty
)
889 struct ui_file
*outfile
;
890 struct cleanup
*cleanups
;
891 char *filename
= DEV_TTY
;
892 char *symname
= NULL
;
893 struct program_space
*pspace
;
894 struct objfile
*objfile
;
896 struct stat sym_st
, obj_st
;
902 error (_("print-msymbols takes an output file name and optional symbol file name"));
904 argv
= gdb_buildargv (args
);
905 cleanups
= make_cleanup_freeargv (argv
);
910 /* If a second arg is supplied, it is a source file name to match on */
913 symname
= xfullpath (argv
[1]);
914 make_cleanup (xfree
, symname
);
915 if (symname
&& stat (symname
, &sym_st
))
916 perror_with_name (symname
);
920 filename
= tilde_expand (filename
);
921 make_cleanup (xfree
, filename
);
923 outfile
= gdb_fopen (filename
, FOPEN_WT
);
925 perror_with_name (filename
);
926 make_cleanup_ui_file_delete (outfile
);
930 ALL_PSPACE_OBJFILES (pspace
, objfile
)
932 || (!stat (objfile
->name
, &obj_st
) && sym_st
.st_ino
== obj_st
.st_ino
))
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 program_space
*pspace
;
943 struct objfile
*objfile
;
949 ALL_PSPACE_OBJFILES (pspace
, objfile
)
950 dump_objfile (objfile
);
955 /* List all the symbol tables whose names match REGEXP (optional). */
957 maintenance_info_symtabs (char *regexp
, int from_tty
)
959 struct program_space
*pspace
;
960 struct objfile
*objfile
;
966 ALL_PSPACE_OBJFILES (pspace
, objfile
)
968 struct symtab
*symtab
;
970 /* We don't want to print anything for this objfile until we
971 actually find a symtab whose name matches. */
972 int printed_objfile_start
= 0;
974 ALL_OBJFILE_SYMTABS (objfile
, symtab
)
979 || re_exec (symtab
->filename
))
981 if (! printed_objfile_start
)
983 printf_filtered ("{ objfile %s ", objfile
->name
);
985 printf_filtered ("((struct objfile *) %s)\n",
986 host_address_to_string (objfile
));
987 printed_objfile_start
= 1;
990 printf_filtered (" { symtab %s ", symtab
->filename
);
992 printf_filtered ("((struct symtab *) %s)\n",
993 host_address_to_string (symtab
));
994 printf_filtered (" dirname %s\n",
995 symtab
->dirname
? symtab
->dirname
: "(null)");
996 printf_filtered (" fullname %s\n",
997 symtab
->fullname
? symtab
->fullname
: "(null)");
998 printf_filtered (" blockvector ((struct blockvector *) %s)%s\n",
999 host_address_to_string (symtab
->blockvector
),
1000 symtab
->primary
? " (primary)" : "");
1001 printf_filtered (" linetable ((struct linetable *) %s)\n",
1002 host_address_to_string (symtab
->linetable
));
1003 printf_filtered (" debugformat %s\n", symtab
->debugformat
);
1004 printf_filtered (" }\n");
1008 if (printed_objfile_start
)
1009 printf_filtered ("}\n");
1014 /* List all the partial symbol tables whose names match REGEXP (optional). */
1016 maintenance_info_psymtabs (char *regexp
, int from_tty
)
1018 struct program_space
*pspace
;
1019 struct objfile
*objfile
;
1024 ALL_PSPACES (pspace
)
1025 ALL_PSPACE_OBJFILES (pspace
, objfile
)
1027 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1028 struct partial_symtab
*psymtab
;
1030 /* We don't want to print anything for this objfile until we
1031 actually find a symtab whose name matches. */
1032 int printed_objfile_start
= 0;
1034 ALL_OBJFILE_PSYMTABS (objfile
, psymtab
)
1039 || re_exec (psymtab
->filename
))
1041 if (! printed_objfile_start
)
1043 printf_filtered ("{ objfile %s ", objfile
->name
);
1045 printf_filtered ("((struct objfile *) %s)\n",
1046 host_address_to_string (objfile
));
1047 printed_objfile_start
= 1;
1050 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1052 printf_filtered ("((struct partial_symtab *) %s)\n",
1053 host_address_to_string (psymtab
));
1055 printf_filtered (" readin %s\n",
1056 psymtab
->readin
? "yes" : "no");
1057 printf_filtered (" fullname %s\n",
1058 psymtab
->fullname
? psymtab
->fullname
: "(null)");
1059 printf_filtered (" text addresses ");
1060 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
),
1062 printf_filtered (" -- ");
1063 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
),
1065 printf_filtered ("\n");
1066 printf_filtered (" globals ");
1067 if (psymtab
->n_global_syms
)
1069 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1070 host_address_to_string (psymtab
->objfile
->global_psymbols
.list
1071 + psymtab
->globals_offset
),
1072 psymtab
->n_global_syms
);
1075 printf_filtered ("(none)\n");
1076 printf_filtered (" statics ");
1077 if (psymtab
->n_static_syms
)
1079 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1080 host_address_to_string (psymtab
->objfile
->static_psymbols
.list
1081 + psymtab
->statics_offset
),
1082 psymtab
->n_static_syms
);
1085 printf_filtered ("(none)\n");
1086 printf_filtered (" dependencies ");
1087 if (psymtab
->number_of_dependencies
)
1091 printf_filtered ("{\n");
1092 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1094 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
1096 /* Note the string concatenation there --- no comma. */
1097 printf_filtered (" psymtab %s "
1098 "((struct partial_symtab *) %s)\n",
1100 host_address_to_string (dep
));
1102 printf_filtered (" }\n");
1105 printf_filtered ("(none)\n");
1106 printf_filtered (" }\n");
1110 if (printed_objfile_start
)
1111 printf_filtered ("}\n");
1116 /* Check consistency of psymtabs and symtabs. */
1119 maintenance_check_symtabs (char *ignore
, int from_tty
)
1122 struct partial_symbol
**psym
;
1123 struct symtab
*s
= NULL
;
1124 struct partial_symtab
*ps
;
1125 struct blockvector
*bv
;
1126 struct objfile
*objfile
;
1130 ALL_PSYMTABS (objfile
, ps
)
1132 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1133 s
= PSYMTAB_TO_SYMTAB (ps
);
1136 bv
= BLOCKVECTOR (s
);
1137 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1138 psym
= ps
->objfile
->static_psymbols
.list
+ ps
->statics_offset
;
1139 length
= ps
->n_static_syms
;
1142 sym
= lookup_block_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
1143 NULL
, SYMBOL_DOMAIN (*psym
));
1146 printf_filtered ("Static symbol `");
1147 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
1148 printf_filtered ("' only found in ");
1149 puts_filtered (ps
->filename
);
1150 printf_filtered (" psymtab\n");
1154 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1155 psym
= ps
->objfile
->global_psymbols
.list
+ ps
->globals_offset
;
1156 length
= ps
->n_global_syms
;
1159 sym
= lookup_block_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
1160 NULL
, SYMBOL_DOMAIN (*psym
));
1163 printf_filtered ("Global symbol `");
1164 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
1165 printf_filtered ("' only found in ");
1166 puts_filtered (ps
->filename
);
1167 printf_filtered (" psymtab\n");
1171 if (ps
->texthigh
< ps
->textlow
)
1173 printf_filtered ("Psymtab ");
1174 puts_filtered (ps
->filename
);
1175 printf_filtered (" covers bad range ");
1176 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
1177 printf_filtered (" - ");
1178 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
1179 printf_filtered ("\n");
1182 if (ps
->texthigh
== 0)
1184 if (ps
->textlow
< BLOCK_START (b
) || ps
->texthigh
> BLOCK_END (b
))
1186 printf_filtered ("Psymtab ");
1187 puts_filtered (ps
->filename
);
1188 printf_filtered (" covers ");
1189 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
1190 printf_filtered (" - ");
1191 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
1192 printf_filtered (" but symtab covers only ");
1193 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
1194 printf_filtered (" - ");
1195 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
1196 printf_filtered ("\n");
1202 /* Return the nexting depth of a block within other blocks in its symtab. */
1205 block_depth (struct block
*block
)
1208 while ((block
= BLOCK_SUPERBLOCK (block
)) != NULL
)
1216 /* Increase the space allocated for LISTP, which is probably
1217 global_psymbols or static_psymbols. This space will eventually
1218 be freed in free_objfile(). */
1221 extend_psymbol_list (struct psymbol_allocation_list
*listp
,
1222 struct objfile
*objfile
)
1225 if (listp
->size
== 0)
1228 listp
->list
= (struct partial_symbol
**)
1229 xmalloc (new_size
* sizeof (struct partial_symbol
*));
1233 new_size
= listp
->size
* 2;
1234 listp
->list
= (struct partial_symbol
**)
1235 xrealloc ((char *) listp
->list
,
1236 new_size
* sizeof (struct partial_symbol
*));
1238 /* Next assumes we only went one over. Should be good if
1239 program works correctly */
1240 listp
->next
= listp
->list
+ listp
->size
;
1241 listp
->size
= new_size
;
1245 /* Do early runtime initializations. */
1247 _initialize_symmisc (void)
This page took 0.054186 seconds and 4 git commands to generate.