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
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 partial_symbol
**, int,
71 char *, struct ui_file
*);
73 void _initialize_symmisc (void);
75 struct print_symbol_args
77 struct symbol
*symbol
;
79 struct ui_file
*outfile
;
82 static int print_symbol (void *);
84 /* Free all the storage associated with the struct symtab <- S.
85 Note that some symtabs have contents that all live inside one big block of
86 memory, and some share the contents of another symbol table and so you
87 should not free the contents on their behalf (except sometimes the
88 linetable, which maybe per symtab even when the rest is not).
89 It is s->free_code that says which alternative to use. */
92 free_symtab (struct symtab
*s
)
95 struct blockvector
*bv
;
100 /* All the contents are part of a big block of memory (an obstack),
101 and some other symtab is in charge of freeing that block.
102 Therefore, do nothing. */
106 /* Everything will be freed either by our `free_func'
107 or by some other symtab, except for our linetable.
110 xfree (LINETABLE (s
));
114 /* If there is a single block of memory to free, free it. */
115 if (s
->free_func
!= NULL
)
118 /* Free source-related stuff */
119 if (s
->line_charpos
!= NULL
)
120 xfree (s
->line_charpos
);
121 if (s
->fullname
!= NULL
)
123 if (s
->debugformat
!= NULL
)
124 xfree (s
->debugformat
);
129 print_symbol_bcache_statistics (void)
131 struct objfile
*objfile
;
134 ALL_OBJFILES (objfile
)
136 printf_filtered (_("Byte cache statistics for '%s':\n"), objfile
->name
);
137 print_bcache_statistics (objfile
->psymbol_cache
, "partial symbol cache");
138 print_bcache_statistics (objfile
->macro_cache
, "preprocessor macro cache");
144 print_objfile_statistics (void)
146 struct objfile
*objfile
;
148 struct partial_symtab
*ps
;
149 int i
, linetables
, blockvectors
;
152 ALL_OBJFILES (objfile
)
154 printf_filtered (_("Statistics for '%s':\n"), objfile
->name
);
155 if (OBJSTAT (objfile
, n_stabs
) > 0)
156 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
157 OBJSTAT (objfile
, n_stabs
));
158 if (OBJSTAT (objfile
, n_minsyms
) > 0)
159 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
160 OBJSTAT (objfile
, n_minsyms
));
161 if (OBJSTAT (objfile
, n_psyms
) > 0)
162 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
163 OBJSTAT (objfile
, n_psyms
));
164 if (OBJSTAT (objfile
, n_syms
) > 0)
165 printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
166 OBJSTAT (objfile
, n_syms
));
167 if (OBJSTAT (objfile
, n_types
) > 0)
168 printf_filtered (_(" Number of \"types\" defined: %d\n"),
169 OBJSTAT (objfile
, n_types
));
171 ALL_OBJFILE_PSYMTABS (objfile
, ps
)
176 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i
);
177 i
= linetables
= blockvectors
= 0;
178 ALL_OBJFILE_SYMTABS (objfile
, s
)
181 if (s
->linetable
!= NULL
)
186 printf_filtered (_(" Number of symbol tables: %d\n"), i
);
187 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
189 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
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 objfile obstack: %d\n"),
196 obstack_memory_used (&objfile
->objfile_obstack
));
197 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
198 bcache_memory_used (objfile
->psymbol_cache
));
199 printf_filtered (_(" Total memory used for macro cache: %d\n"),
200 bcache_memory_used (objfile
->macro_cache
));
206 dump_objfile (struct objfile
*objfile
)
208 struct symtab
*symtab
;
209 struct partial_symtab
*psymtab
;
211 printf_filtered ("\nObject file %s: ", objfile
->name
);
212 printf_filtered ("Objfile at ");
213 gdb_print_host_address (objfile
, gdb_stdout
);
214 printf_filtered (", bfd at ");
215 gdb_print_host_address (objfile
->obfd
, gdb_stdout
);
216 printf_filtered (", %d minsyms\n\n",
217 objfile
->minimal_symbol_count
);
219 if (objfile
->psymtabs
)
221 printf_filtered ("Psymtabs:\n");
222 for (psymtab
= objfile
->psymtabs
;
224 psymtab
= psymtab
->next
)
226 printf_filtered ("%s at ",
228 gdb_print_host_address (psymtab
, gdb_stdout
);
229 printf_filtered (", ");
230 if (psymtab
->objfile
!= objfile
)
232 printf_filtered ("NOT ON CHAIN! ");
236 printf_filtered ("\n\n");
239 if (objfile
->symtabs
)
241 printf_filtered ("Symtabs:\n");
242 for (symtab
= objfile
->symtabs
;
244 symtab
= symtab
->next
)
246 printf_filtered ("%s at ", symtab
->filename
);
247 gdb_print_host_address (symtab
, gdb_stdout
);
248 printf_filtered (", ");
249 if (symtab
->objfile
!= objfile
)
251 printf_filtered ("NOT ON CHAIN! ");
255 printf_filtered ("\n\n");
259 /* Print minimal symbols from this objfile. */
262 dump_msymbols (struct objfile
*objfile
, struct ui_file
*outfile
)
264 struct minimal_symbol
*msymbol
;
268 fprintf_filtered (outfile
, "\nObject file %s:\n\n", objfile
->name
);
269 if (objfile
->minimal_symbol_count
== 0)
271 fprintf_filtered (outfile
, "No minimal symbols found.\n");
275 ALL_OBJFILE_MSYMBOLS (objfile
, msymbol
)
277 switch (msymbol
->type
)
285 case mst_solib_trampoline
:
310 fprintf_filtered (outfile
, "[%2d] %c ", index
, ms_type
);
311 fputs_filtered (paddress (SYMBOL_VALUE_ADDRESS (msymbol
)), outfile
);
312 fprintf_filtered (outfile
, " %s", SYMBOL_LINKAGE_NAME (msymbol
));
313 if (SYMBOL_BFD_SECTION (msymbol
))
314 fprintf_filtered (outfile
, " section %s",
315 bfd_section_name (objfile
->obfd
,
316 SYMBOL_BFD_SECTION (msymbol
)));
317 if (SYMBOL_DEMANGLED_NAME (msymbol
) != NULL
)
319 fprintf_filtered (outfile
, " %s", SYMBOL_DEMANGLED_NAME (msymbol
));
321 if (msymbol
->filename
)
322 fprintf_filtered (outfile
, " %s", msymbol
->filename
);
323 fputs_filtered ("\n", outfile
);
326 if (objfile
->minimal_symbol_count
!= index
)
328 warning (_("internal error: minimal symbol count %d != %d"),
329 objfile
->minimal_symbol_count
, index
);
331 fprintf_filtered (outfile
, "\n");
335 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
336 struct ui_file
*outfile
)
340 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
342 fprintf_filtered (outfile
, "(object ");
343 gdb_print_host_address (psymtab
, outfile
);
344 fprintf_filtered (outfile
, ")\n\n");
345 fprintf_unfiltered (outfile
, " Read from object file %s (",
347 gdb_print_host_address (objfile
, outfile
);
348 fprintf_unfiltered (outfile
, ")\n");
352 fprintf_filtered (outfile
,
353 " Full symtab was read (at ");
354 gdb_print_host_address (psymtab
->symtab
, outfile
);
355 fprintf_filtered (outfile
, " by function at ");
356 gdb_print_host_address (psymtab
->read_symtab
, outfile
);
357 fprintf_filtered (outfile
, ")\n");
360 fprintf_filtered (outfile
, " Relocate symbols by ");
361 for (i
= 0; i
< psymtab
->objfile
->num_sections
; ++i
)
364 fprintf_filtered (outfile
, ", ");
366 fputs_filtered (paddress (ANOFFSET (psymtab
->section_offsets
, i
)),
369 fprintf_filtered (outfile
, "\n");
371 fprintf_filtered (outfile
, " Symbols cover text addresses ");
372 fputs_filtered (paddress (psymtab
->textlow
), outfile
);
373 fprintf_filtered (outfile
, "-");
374 fputs_filtered (paddress (psymtab
->texthigh
), outfile
);
375 fprintf_filtered (outfile
, "\n");
376 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
377 psymtab
->number_of_dependencies
);
378 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
380 fprintf_filtered (outfile
, " %d ", i
);
381 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
382 fprintf_filtered (outfile
, " %s\n",
383 psymtab
->dependencies
[i
]->filename
);
385 if (psymtab
->n_global_syms
> 0)
387 print_partial_symbols (objfile
->global_psymbols
.list
388 + psymtab
->globals_offset
,
389 psymtab
->n_global_syms
, "Global", outfile
);
391 if (psymtab
->n_static_syms
> 0)
393 print_partial_symbols (objfile
->static_psymbols
.list
394 + psymtab
->statics_offset
,
395 psymtab
->n_static_syms
, "Static", outfile
);
397 fprintf_filtered (outfile
, "\n");
401 dump_symtab_1 (struct objfile
*objfile
, struct symtab
*symtab
,
402 struct ui_file
*outfile
)
405 struct dict_iterator iter
;
408 struct blockvector
*bv
;
413 fprintf_filtered (outfile
, "\nSymtab for file %s\n", symtab
->filename
);
415 fprintf_filtered (outfile
, "Compilation directory is %s\n",
417 fprintf_filtered (outfile
, "Read from object file %s (", objfile
->name
);
418 gdb_print_host_address (objfile
, outfile
);
419 fprintf_filtered (outfile
, ")\n");
420 fprintf_filtered (outfile
, "Language: %s\n", language_str (symtab
->language
));
422 /* First print the line table. */
423 l
= LINETABLE (symtab
);
426 fprintf_filtered (outfile
, "\nLine table:\n\n");
428 for (i
= 0; i
< len
; i
++)
430 fprintf_filtered (outfile
, " line %d at ", l
->item
[i
].line
);
431 fputs_filtered (paddress (l
->item
[i
].pc
), outfile
);
432 fprintf_filtered (outfile
, "\n");
435 /* Now print the block info, but only for primary symtabs since we will
436 print lots of duplicate info otherwise. */
439 fprintf_filtered (outfile
, "\nBlockvector:\n\n");
440 bv
= BLOCKVECTOR (symtab
);
441 len
= BLOCKVECTOR_NBLOCKS (bv
);
442 for (i
= 0; i
< len
; i
++)
444 b
= BLOCKVECTOR_BLOCK (bv
, i
);
445 depth
= block_depth (b
) * 2;
446 print_spaces (depth
, outfile
);
447 fprintf_filtered (outfile
, "block #%03d, object at ", i
);
448 gdb_print_host_address (b
, outfile
);
449 if (BLOCK_SUPERBLOCK (b
))
451 fprintf_filtered (outfile
, " under ");
452 gdb_print_host_address (BLOCK_SUPERBLOCK (b
), outfile
);
454 /* drow/2002-07-10: We could save the total symbols count
455 even if we're using a hashtable, but nothing else but this message
457 fprintf_filtered (outfile
, ", %d syms/buckets in ",
458 dict_size (BLOCK_DICT (b
)));
459 fputs_filtered (paddress (BLOCK_START (b
)), outfile
);
460 fprintf_filtered (outfile
, "..");
461 fputs_filtered (paddress (BLOCK_END (b
)), outfile
);
462 if (BLOCK_FUNCTION (b
))
464 fprintf_filtered (outfile
, ", function %s",
465 SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b
)));
466 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b
)) != NULL
)
468 fprintf_filtered (outfile
, ", %s",
469 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b
)));
472 fprintf_filtered (outfile
, "\n");
473 /* Now print each symbol in this block (in no particular order, if
474 we're using a hashtable). */
475 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
477 struct print_symbol_args s
;
481 catch_errors (print_symbol
, &s
, "Error printing symbol:\n",
485 fprintf_filtered (outfile
, "\n");
489 fprintf_filtered (outfile
, "\nBlockvector same as previous symtab\n\n");
494 dump_symtab (struct objfile
*objfile
, struct symtab
*symtab
,
495 struct ui_file
*outfile
)
497 enum language saved_lang
;
499 /* Set the current language to the language of the symtab we're dumping
500 because certain routines used during dump_symtab() use the current
501 language to print an image of the symbol. We'll restore it later. */
502 saved_lang
= set_language (symtab
->language
);
504 dump_symtab_1 (objfile
, symtab
, outfile
);
506 set_language (saved_lang
);
510 maintenance_print_symbols (char *args
, int from_tty
)
513 struct ui_file
*outfile
;
514 struct cleanup
*cleanups
;
515 char *symname
= NULL
;
516 char *filename
= DEV_TTY
;
517 struct objfile
*objfile
;
525 Arguments missing: an output file name and an optional symbol file name"));
527 else if ((argv
= buildargv (args
)) == NULL
)
531 cleanups
= make_cleanup_freeargv (argv
);
536 /* If a second arg is supplied, it is a source file name to match on */
543 filename
= tilde_expand (filename
);
544 make_cleanup (xfree
, filename
);
546 outfile
= gdb_fopen (filename
, FOPEN_WT
);
548 perror_with_name (filename
);
549 make_cleanup_ui_file_delete (outfile
);
552 ALL_SYMTABS (objfile
, s
)
553 if (symname
== NULL
|| strcmp (symname
, s
->filename
) == 0)
554 dump_symtab (objfile
, s
, outfile
);
556 do_cleanups (cleanups
);
559 /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
560 far to indent. ARGS is really a struct print_symbol_args *, but is
561 declared as char * to get it past catch_errors. Returns 0 for error,
565 print_symbol (void *args
)
567 struct symbol
*symbol
= ((struct print_symbol_args
*) args
)->symbol
;
568 int depth
= ((struct print_symbol_args
*) args
)->depth
;
569 struct ui_file
*outfile
= ((struct print_symbol_args
*) args
)->outfile
;
571 print_spaces (depth
, outfile
);
572 if (SYMBOL_DOMAIN (symbol
) == LABEL_DOMAIN
)
574 fprintf_filtered (outfile
, "label %s at ", SYMBOL_PRINT_NAME (symbol
));
575 fputs_filtered (paddress (SYMBOL_VALUE_ADDRESS (symbol
)), outfile
);
576 if (SYMBOL_BFD_SECTION (symbol
))
577 fprintf_filtered (outfile
, " section %s\n",
578 bfd_section_name (SYMBOL_BFD_SECTION (symbol
)->owner
,
579 SYMBOL_BFD_SECTION (symbol
)));
581 fprintf_filtered (outfile
, "\n");
584 if (SYMBOL_DOMAIN (symbol
) == STRUCT_DOMAIN
)
586 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol
)))
588 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
);
592 fprintf_filtered (outfile
, "%s %s = ",
593 (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_ENUM
595 : (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_STRUCT
596 ? "struct" : "union")),
597 SYMBOL_LINKAGE_NAME (symbol
));
598 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
);
600 fprintf_filtered (outfile
, ";\n");
604 if (SYMBOL_CLASS (symbol
) == LOC_TYPEDEF
)
605 fprintf_filtered (outfile
, "typedef ");
606 if (SYMBOL_TYPE (symbol
))
608 /* Print details of types, except for enums where it's clutter. */
609 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), SYMBOL_PRINT_NAME (symbol
),
611 TYPE_CODE (SYMBOL_TYPE (symbol
)) != TYPE_CODE_ENUM
,
613 fprintf_filtered (outfile
, "; ");
616 fprintf_filtered (outfile
, "%s ", SYMBOL_PRINT_NAME (symbol
));
618 switch (SYMBOL_CLASS (symbol
))
621 fprintf_filtered (outfile
, "const %ld (0x%lx)",
622 SYMBOL_VALUE (symbol
),
623 SYMBOL_VALUE (symbol
));
626 case LOC_CONST_BYTES
:
629 struct type
*type
= check_typedef (SYMBOL_TYPE (symbol
));
630 fprintf_filtered (outfile
, "const %u hex bytes:",
632 for (i
= 0; i
< TYPE_LENGTH (type
); i
++)
633 fprintf_filtered (outfile
, " %02x",
634 (unsigned) SYMBOL_VALUE_BYTES (symbol
)[i
]);
639 fprintf_filtered (outfile
, "static at ");
640 fputs_filtered (paddress (SYMBOL_VALUE_ADDRESS (symbol
)), outfile
);
641 if (SYMBOL_BFD_SECTION (symbol
))
642 fprintf_filtered (outfile
, " section %s",
644 (SYMBOL_BFD_SECTION (symbol
)->owner
,
645 SYMBOL_BFD_SECTION (symbol
)));
649 if (SYMBOL_IS_ARGUMENT (symbol
))
650 fprintf_filtered (outfile
, "parameter register %ld",
651 SYMBOL_VALUE (symbol
));
653 fprintf_filtered (outfile
, "register %ld", SYMBOL_VALUE (symbol
));
657 fprintf_filtered (outfile
, "arg at offset 0x%lx",
658 SYMBOL_VALUE (symbol
));
662 fprintf_filtered (outfile
, "reference arg at 0x%lx", SYMBOL_VALUE (symbol
));
665 case LOC_REGPARM_ADDR
:
666 fprintf_filtered (outfile
, "address parameter register %ld", SYMBOL_VALUE (symbol
));
670 fprintf_filtered (outfile
, "local at offset 0x%lx",
671 SYMBOL_VALUE (symbol
));
678 fprintf_filtered (outfile
, "label at ");
679 fputs_filtered (paddress (SYMBOL_VALUE_ADDRESS (symbol
)), outfile
);
680 if (SYMBOL_BFD_SECTION (symbol
))
681 fprintf_filtered (outfile
, " section %s",
683 (SYMBOL_BFD_SECTION (symbol
)->owner
,
684 SYMBOL_BFD_SECTION (symbol
)));
688 fprintf_filtered (outfile
, "block object ");
689 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol
), outfile
);
690 fprintf_filtered (outfile
, ", ");
691 fputs_filtered (paddress (BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
))),
693 fprintf_filtered (outfile
, "..");
694 fputs_filtered (paddress (BLOCK_END (SYMBOL_BLOCK_VALUE (symbol
))),
696 if (SYMBOL_BFD_SECTION (symbol
))
697 fprintf_filtered (outfile
, " section %s",
699 (SYMBOL_BFD_SECTION (symbol
)->owner
,
700 SYMBOL_BFD_SECTION (symbol
)));
704 fprintf_filtered (outfile
, "computed at runtime");
708 fprintf_filtered (outfile
, "unresolved");
711 case LOC_OPTIMIZED_OUT
:
712 fprintf_filtered (outfile
, "optimized out");
716 fprintf_filtered (outfile
, "botched symbol class %x",
717 SYMBOL_CLASS (symbol
));
721 fprintf_filtered (outfile
, "\n");
726 maintenance_print_psymbols (char *args
, int from_tty
)
729 struct ui_file
*outfile
;
730 struct cleanup
*cleanups
;
731 char *symname
= NULL
;
732 char *filename
= DEV_TTY
;
733 struct objfile
*objfile
;
734 struct partial_symtab
*ps
;
740 error (_("print-psymbols takes an output file name and optional symbol file name"));
742 else if ((argv
= buildargv (args
)) == NULL
)
746 cleanups
= make_cleanup_freeargv (argv
);
751 /* If a second arg is supplied, it is a source file name to match on */
758 filename
= tilde_expand (filename
);
759 make_cleanup (xfree
, filename
);
761 outfile
= gdb_fopen (filename
, FOPEN_WT
);
763 perror_with_name (filename
);
764 make_cleanup_ui_file_delete (outfile
);
767 ALL_PSYMTABS (objfile
, ps
)
768 if (symname
== NULL
|| strcmp (symname
, ps
->filename
) == 0)
769 dump_psymtab (objfile
, ps
, outfile
);
771 do_cleanups (cleanups
);
775 print_partial_symbols (struct partial_symbol
**p
, int count
, char *what
,
776 struct ui_file
*outfile
)
778 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
781 fprintf_filtered (outfile
, " `%s'", SYMBOL_LINKAGE_NAME (*p
));
782 if (SYMBOL_DEMANGLED_NAME (*p
) != NULL
)
784 fprintf_filtered (outfile
, " `%s'", SYMBOL_DEMANGLED_NAME (*p
));
786 fputs_filtered (", ", outfile
);
787 switch (SYMBOL_DOMAIN (*p
))
790 fputs_filtered ("undefined domain, ", outfile
);
793 /* This is the usual thing -- don't print it */
796 fputs_filtered ("struct domain, ", outfile
);
799 fputs_filtered ("label domain, ", outfile
);
802 fputs_filtered ("<invalid domain>, ", outfile
);
805 switch (SYMBOL_CLASS (*p
))
808 fputs_filtered ("undefined", outfile
);
811 fputs_filtered ("constant int", outfile
);
814 fputs_filtered ("static", outfile
);
817 fputs_filtered ("register", outfile
);
820 fputs_filtered ("pass by value", outfile
);
823 fputs_filtered ("pass by reference", outfile
);
825 case LOC_REGPARM_ADDR
:
826 fputs_filtered ("register address parameter", outfile
);
829 fputs_filtered ("stack parameter", outfile
);
832 fputs_filtered ("type", outfile
);
835 fputs_filtered ("label", outfile
);
838 fputs_filtered ("function", outfile
);
840 case LOC_CONST_BYTES
:
841 fputs_filtered ("constant bytes", outfile
);
844 fputs_filtered ("unresolved", outfile
);
846 case LOC_OPTIMIZED_OUT
:
847 fputs_filtered ("optimized out", outfile
);
850 fputs_filtered ("computed at runtime", outfile
);
853 fputs_filtered ("<invalid location>", outfile
);
856 fputs_filtered (", ", outfile
);
857 fputs_filtered (paddress (SYMBOL_VALUE_ADDRESS (*p
)), outfile
);
858 fprintf_filtered (outfile
, "\n");
864 maintenance_print_msymbols (char *args
, int from_tty
)
867 struct ui_file
*outfile
;
868 struct cleanup
*cleanups
;
869 char *filename
= DEV_TTY
;
870 char *symname
= NULL
;
871 struct objfile
*objfile
;
873 struct stat sym_st
, obj_st
;
879 error (_("print-msymbols takes an output file name and optional symbol file name"));
881 else if ((argv
= buildargv (args
)) == NULL
)
885 cleanups
= make_cleanup_freeargv (argv
);
890 /* If a second arg is supplied, it is a source file name to match on */
893 symname
= xfullpath (argv
[1]);
894 make_cleanup (xfree
, symname
);
895 if (symname
&& stat (symname
, &sym_st
))
896 perror_with_name (symname
);
900 filename
= tilde_expand (filename
);
901 make_cleanup (xfree
, filename
);
903 outfile
= gdb_fopen (filename
, FOPEN_WT
);
905 perror_with_name (filename
);
906 make_cleanup_ui_file_delete (outfile
);
909 ALL_OBJFILES (objfile
)
911 || (!stat (objfile
->name
, &obj_st
) && sym_st
.st_ino
== obj_st
.st_ino
))
912 dump_msymbols (objfile
, outfile
);
914 fprintf_filtered (outfile
, "\n\n");
915 do_cleanups (cleanups
);
919 maintenance_print_objfiles (char *ignore
, int from_tty
)
921 struct objfile
*objfile
;
926 ALL_OBJFILES (objfile
)
927 dump_objfile (objfile
);
932 /* List all the symbol tables whose names match REGEXP (optional). */
934 maintenance_info_symtabs (char *regexp
, int from_tty
)
936 struct objfile
*objfile
;
941 ALL_OBJFILES (objfile
)
943 struct symtab
*symtab
;
945 /* We don't want to print anything for this objfile until we
946 actually find a symtab whose name matches. */
947 int printed_objfile_start
= 0;
949 ALL_OBJFILE_SYMTABS (objfile
, symtab
)
951 || re_exec (symtab
->filename
))
953 if (! printed_objfile_start
)
955 printf_filtered ("{ objfile %s ", objfile
->name
);
957 printf_filtered ("((struct objfile *) %p)\n", objfile
);
958 printed_objfile_start
= 1;
961 printf_filtered (" { symtab %s ", symtab
->filename
);
963 printf_filtered ("((struct symtab *) %p)\n", symtab
);
964 printf_filtered (" dirname %s\n",
965 symtab
->dirname
? symtab
->dirname
: "(null)");
966 printf_filtered (" fullname %s\n",
967 symtab
->fullname
? symtab
->fullname
: "(null)");
968 printf_filtered (" blockvector ((struct blockvector *) %p)%s\n",
970 symtab
->primary
? " (primary)" : "");
971 printf_filtered (" linetable ((struct linetable *) %p)\n",
973 printf_filtered (" debugformat %s\n", symtab
->debugformat
);
974 printf_filtered (" }\n");
977 if (printed_objfile_start
)
978 printf_filtered ("}\n");
983 /* List all the partial symbol tables whose names match REGEXP (optional). */
985 maintenance_info_psymtabs (char *regexp
, int from_tty
)
987 struct objfile
*objfile
;
992 ALL_OBJFILES (objfile
)
994 struct partial_symtab
*psymtab
;
996 /* We don't want to print anything for this objfile until we
997 actually find a symtab whose name matches. */
998 int printed_objfile_start
= 0;
1000 ALL_OBJFILE_PSYMTABS (objfile
, psymtab
)
1002 || re_exec (psymtab
->filename
))
1004 if (! printed_objfile_start
)
1006 printf_filtered ("{ objfile %s ", objfile
->name
);
1008 printf_filtered ("((struct objfile *) %p)\n", objfile
);
1009 printed_objfile_start
= 1;
1012 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1014 printf_filtered ("((struct partial_symtab *) %p)\n", psymtab
);
1015 printf_filtered (" readin %s\n",
1016 psymtab
->readin
? "yes" : "no");
1017 printf_filtered (" fullname %s\n",
1018 psymtab
->fullname
? psymtab
->fullname
: "(null)");
1019 printf_filtered (" text addresses ");
1020 fputs_filtered (paddress (psymtab
->textlow
), gdb_stdout
);
1021 printf_filtered (" -- ");
1022 fputs_filtered (paddress (psymtab
->texthigh
), gdb_stdout
);
1023 printf_filtered ("\n");
1024 printf_filtered (" globals ");
1025 if (psymtab
->n_global_syms
)
1027 printf_filtered ("(* (struct partial_symbol **) %p @ %d)\n",
1028 (psymtab
->objfile
->global_psymbols
.list
1029 + psymtab
->globals_offset
),
1030 psymtab
->n_global_syms
);
1033 printf_filtered ("(none)\n");
1034 printf_filtered (" statics ");
1035 if (psymtab
->n_static_syms
)
1037 printf_filtered ("(* (struct partial_symbol **) %p @ %d)\n",
1038 (psymtab
->objfile
->static_psymbols
.list
1039 + psymtab
->statics_offset
),
1040 psymtab
->n_static_syms
);
1043 printf_filtered ("(none)\n");
1044 printf_filtered (" dependencies ");
1045 if (psymtab
->number_of_dependencies
)
1049 printf_filtered ("{\n");
1050 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1052 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
1054 /* Note the string concatenation there --- no comma. */
1055 printf_filtered (" psymtab %s "
1056 "((struct partial_symtab *) %p)\n",
1057 dep
->filename
, dep
);
1059 printf_filtered (" }\n");
1062 printf_filtered ("(none)\n");
1063 printf_filtered (" }\n");
1066 if (printed_objfile_start
)
1067 printf_filtered ("}\n");
1072 /* Check consistency of psymtabs and symtabs. */
1075 maintenance_check_symtabs (char *ignore
, int from_tty
)
1078 struct partial_symbol
**psym
;
1079 struct symtab
*s
= NULL
;
1080 struct partial_symtab
*ps
;
1081 struct blockvector
*bv
;
1082 struct objfile
*objfile
;
1086 ALL_PSYMTABS (objfile
, ps
)
1088 s
= PSYMTAB_TO_SYMTAB (ps
);
1091 bv
= BLOCKVECTOR (s
);
1092 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1093 psym
= ps
->objfile
->static_psymbols
.list
+ ps
->statics_offset
;
1094 length
= ps
->n_static_syms
;
1097 sym
= lookup_block_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
1098 NULL
, SYMBOL_DOMAIN (*psym
));
1101 printf_filtered ("Static symbol `");
1102 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
1103 printf_filtered ("' only found in ");
1104 puts_filtered (ps
->filename
);
1105 printf_filtered (" psymtab\n");
1109 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1110 psym
= ps
->objfile
->global_psymbols
.list
+ ps
->globals_offset
;
1111 length
= ps
->n_global_syms
;
1114 sym
= lookup_block_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
1115 NULL
, SYMBOL_DOMAIN (*psym
));
1118 printf_filtered ("Global symbol `");
1119 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
1120 printf_filtered ("' only found in ");
1121 puts_filtered (ps
->filename
);
1122 printf_filtered (" psymtab\n");
1126 if (ps
->texthigh
< ps
->textlow
)
1128 printf_filtered ("Psymtab ");
1129 puts_filtered (ps
->filename
);
1130 printf_filtered (" covers bad range ");
1131 fputs_filtered (paddress (ps
->textlow
), gdb_stdout
);
1132 printf_filtered (" - ");
1133 fputs_filtered (paddress (ps
->texthigh
), gdb_stdout
);
1134 printf_filtered ("\n");
1137 if (ps
->texthigh
== 0)
1139 if (ps
->textlow
< BLOCK_START (b
) || ps
->texthigh
> BLOCK_END (b
))
1141 printf_filtered ("Psymtab ");
1142 puts_filtered (ps
->filename
);
1143 printf_filtered (" covers ");
1144 fputs_filtered (paddress (ps
->textlow
), gdb_stdout
);
1145 printf_filtered (" - ");
1146 fputs_filtered (paddress (ps
->texthigh
), gdb_stdout
);
1147 printf_filtered (" but symtab covers only ");
1148 fputs_filtered (paddress (BLOCK_START (b
)), gdb_stdout
);
1149 printf_filtered (" - ");
1150 fputs_filtered (paddress (BLOCK_END (b
)), gdb_stdout
);
1151 printf_filtered ("\n");
1157 /* Return the nexting depth of a block within other blocks in its symtab. */
1160 block_depth (struct block
*block
)
1163 while ((block
= BLOCK_SUPERBLOCK (block
)) != NULL
)
1171 /* Increase the space allocated for LISTP, which is probably
1172 global_psymbols or static_psymbols. This space will eventually
1173 be freed in free_objfile(). */
1176 extend_psymbol_list (struct psymbol_allocation_list
*listp
,
1177 struct objfile
*objfile
)
1180 if (listp
->size
== 0)
1183 listp
->list
= (struct partial_symbol
**)
1184 xmalloc (new_size
* sizeof (struct partial_symbol
*));
1188 new_size
= listp
->size
* 2;
1189 listp
->list
= (struct partial_symbol
**)
1190 xrealloc ((char *) listp
->list
,
1191 new_size
* sizeof (struct partial_symbol
*));
1193 /* Next assumes we only went one over. Should be good if
1194 program works correctly */
1195 listp
->next
= listp
->list
+ listp
->size
;
1196 listp
->size
= new_size
;
1200 /* Do early runtime initializations. */
1202 _initialize_symmisc (void)
This page took 0.063898 seconds and 4 git commands to generate.