1 /* Do various things to symbol tables (other than lookup), for GDB.
2 Copyright 1986, 1987, 1989, 1991, 1992 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
26 #include "breakpoint.h"
34 #define DEV_TTY "/dev/tty"
37 /* Unfortunately for debugging, stderr is usually a macro. Better if we
38 make a variable which has the same value and which is accessible when
39 debugging GDB with itself. */
41 FILE *std_out
= stdout
;
42 FILE *std_err
= stderr
;
44 /* Prototypes for local functions */
47 dump_symtab
PARAMS ((struct objfile
*, struct symtab
*, FILE *));
50 dump_psymtab
PARAMS ((struct objfile
*, struct partial_symtab
*, FILE *));
53 dump_msymbols
PARAMS ((struct objfile
*, FILE *));
56 dump_objfile
PARAMS ((struct objfile
*));
59 block_depth
PARAMS ((struct block
*));
62 print_partial_symbol
PARAMS ((struct partial_symbol
*, int, char *, FILE *));
65 print_symbol
PARAMS ((struct symbol
*, int, FILE *));
68 free_symtab_block
PARAMS ((struct objfile
*, struct block
*));
71 /* Free a struct block <- B and all the symbols defined in that block. */
74 free_symtab_block (objfile
, b
)
75 struct objfile
*objfile
;
80 for (i
= 0; i
< n
; i
++)
82 mfree (objfile
-> md
, SYMBOL_NAME (BLOCK_SYM (b
, i
)));
83 mfree (objfile
-> md
, (PTR
) BLOCK_SYM (b
, i
));
85 mfree (objfile
-> md
, (PTR
) b
);
88 /* Free all the storage associated with the struct symtab <- S.
89 Note that some symtabs have contents malloc'ed structure by structure,
90 while some have contents that all live inside one big block of memory,
91 and some share the contents of another symbol table and so you should
92 not free the contents on their behalf (except sometimes the linetable,
93 which maybe per symtab even when the rest is not).
94 It is s->free_code that says which alternative to use. */
98 register struct symtab
*s
;
101 register struct blockvector
*bv
;
103 switch (s
->free_code
)
106 /* All the contents are part of a big block of memory (an obstack),
107 and some other symtab is in charge of freeing that block.
108 Therefore, do nothing. */
112 /* Here all the contents were malloc'ed structure by structure
113 and must be freed that way. */
114 /* First free the blocks (and their symbols. */
115 bv
= BLOCKVECTOR (s
);
116 n
= BLOCKVECTOR_NBLOCKS (bv
);
117 for (i
= 0; i
< n
; i
++)
118 free_symtab_block (s
-> objfile
, BLOCKVECTOR_BLOCK (bv
, i
));
119 /* Free the blockvector itself. */
120 mfree (s
-> objfile
-> md
, (PTR
) bv
);
121 /* Also free the linetable. */
124 /* Everything will be freed either by our `free_ptr'
125 or by some other symtab, except for our linetable.
128 mfree (s
-> objfile
-> md
, (PTR
) LINETABLE (s
));
132 /* If there is a single block of memory to free, free it. */
133 if (s
-> free_ptr
!= NULL
)
134 mfree (s
-> objfile
-> md
, s
-> free_ptr
);
136 /* Free source-related stuff */
137 if (s
-> line_charpos
!= NULL
)
138 mfree (s
-> objfile
-> md
, (PTR
) s
-> line_charpos
);
139 if (s
-> fullname
!= NULL
)
140 mfree (s
-> objfile
-> md
, s
-> fullname
);
141 mfree (s
-> objfile
-> md
, (PTR
) s
);
147 dump_objfile (objfile
)
148 struct objfile
*objfile
;
150 struct symtab
*symtab
;
151 struct partial_symtab
*psymtab
;
153 printf_filtered ("\nObject file %s: ", objfile
-> name
);
154 printf_filtered ("Objfile at %x, bfd at %x, %d minsyms\n\n",
155 objfile
, objfile
-> obfd
, objfile
->minimal_symbol_count
);
157 if (objfile
-> psymtabs
)
159 printf_filtered ("Psymtabs:\n");
160 for (psymtab
= objfile
-> psymtabs
;
162 psymtab
= psymtab
-> next
)
164 printf_filtered ("%s at %x, ", psymtab
-> filename
, psymtab
);
165 if (psymtab
-> objfile
!= objfile
)
167 printf_filtered ("NOT ON CHAIN! ");
171 printf_filtered ("\n\n");
174 if (objfile
-> symtabs
)
176 printf_filtered ("Symtabs:\n");
177 for (symtab
= objfile
-> symtabs
;
179 symtab
= symtab
->next
)
181 printf_filtered ("%s at %x, ", symtab
-> filename
, symtab
);
182 if (symtab
-> objfile
!= objfile
)
184 printf_filtered ("NOT ON CHAIN! ");
188 printf_filtered ("\n\n");
192 /* Print minimal symbols from this objfile. */
195 dump_msymbols (objfile
, outfile
)
196 struct objfile
*objfile
;
199 struct minimal_symbol
*msymbol
;
203 fprintf_filtered (outfile
, "\nObject file %s:\n\n", objfile
-> name
);
204 for (index
= 0, msymbol
= objfile
-> msymbols
;
205 SYMBOL_NAME (msymbol
) != NULL
; msymbol
++, index
++)
207 switch (msymbol
-> type
)
228 fprintf_filtered (outfile
, "[%2d] %c %#10x %s", index
, ms_type
,
229 SYMBOL_VALUE_ADDRESS (msymbol
), SYMBOL_NAME (msymbol
));
230 if (SYMBOL_DEMANGLED_NAME (msymbol
) != NULL
)
232 fprintf_filtered (outfile
, " %s", SYMBOL_DEMANGLED_NAME (msymbol
));
234 fputs_filtered ("\n", outfile
);
236 if (objfile
-> minimal_symbol_count
!= index
)
238 warning ("internal error: minimal symbol count %d != %d",
239 objfile
-> minimal_symbol_count
, index
);
241 fprintf_filtered (outfile
, "\n");
245 dump_psymtab (objfile
, psymtab
, outfile
)
246 struct objfile
*objfile
;
247 struct partial_symtab
*psymtab
;
251 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
252 psymtab
-> filename
);
253 fprintf_filtered (outfile
, "(object 0x%x)\n\n", psymtab
);
254 fprintf (outfile
, " Read from object file %s (0x%x)\n",
255 objfile
-> name
, (unsigned int) objfile
);
257 if (psymtab
-> readin
)
259 fprintf_filtered (outfile
,
260 " Full symtab was read (at 0x%x by function at 0x%x)\n",
261 psymtab
-> symtab
, psymtab
-> read_symtab
);
264 /* FIXME, we need to be able to print the relocation stuff. */
265 /* This prints some garbage for anything but stabs right now. FIXME. */
266 if (psymtab
->section_offsets
)
267 fprintf_filtered (outfile
, " Relocate symbols by 0x%x, 0x%x, 0x%x, 0x%x.\n",
268 ANOFFSET (psymtab
->section_offsets
, 0),
269 ANOFFSET (psymtab
->section_offsets
, 1),
270 ANOFFSET (psymtab
->section_offsets
, 2),
271 ANOFFSET (psymtab
->section_offsets
, 3));
273 fprintf_filtered (outfile
, " Symbols cover text addresses 0x%x-0x%x\n",
274 psymtab
-> textlow
, psymtab
-> texthigh
);
275 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
276 psymtab
-> number_of_dependencies
);
277 if (psymtab
-> n_global_syms
> 0)
279 print_partial_symbol (objfile
-> global_psymbols
.list
280 + psymtab
-> globals_offset
,
281 psymtab
-> n_global_syms
, "Global", outfile
);
283 if (psymtab
-> n_static_syms
> 0)
285 print_partial_symbol (objfile
-> static_psymbols
.list
286 + psymtab
-> statics_offset
,
287 psymtab
-> n_static_syms
, "Static", outfile
);
289 fprintf_filtered (outfile
, "\n");
293 dump_symtab (objfile
, symtab
, outfile
)
294 struct objfile
*objfile
;
295 struct symtab
*symtab
;
300 register struct linetable
*l
;
301 struct blockvector
*bv
;
302 register struct block
*b
;
305 fprintf (outfile
, "\nSymtab for file %s\n", symtab
->filename
);
306 fprintf (outfile
, "Read from object file %s (%x)\n", objfile
->name
,
307 (unsigned int) objfile
);
308 fprintf (outfile
, "Language: %s\n", language_str (symtab
-> language
));
310 /* First print the line table. */
311 l
= LINETABLE (symtab
);
313 fprintf (outfile
, "\nLine table:\n\n");
315 for (i
= 0; i
< len
; i
++)
316 fprintf (outfile
, " line %d at %x\n", l
->item
[i
].line
,
319 /* Now print the block info. */
320 fprintf (outfile
, "\nBlockvector:\n\n");
321 bv
= BLOCKVECTOR (symtab
);
322 len
= BLOCKVECTOR_NBLOCKS (bv
);
323 for (i
= 0; i
< len
; i
++)
325 b
= BLOCKVECTOR_BLOCK (bv
, i
);
326 depth
= block_depth (b
) * 2;
327 print_spaces (depth
, outfile
);
328 fprintf (outfile
, "block #%03d (object 0x%x) ", i
, (unsigned int) b
);
329 fprintf (outfile
, "[0x%x..0x%x]", BLOCK_START (b
), BLOCK_END (b
));
330 if (BLOCK_SUPERBLOCK (b
))
331 fprintf (outfile
, " (under 0x%x)", (unsigned int) BLOCK_SUPERBLOCK (b
));
332 if (BLOCK_FUNCTION (b
))
334 fprintf (outfile
, " %s", SYMBOL_NAME (BLOCK_FUNCTION (b
)));
335 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b
)) != NULL
)
337 fprintf (outfile
, " %s",
338 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b
)));
341 if (BLOCK_GCC_COMPILED(b
))
342 fprintf (outfile
, " gcc%d compiled", BLOCK_GCC_COMPILED(b
));
343 fputc ('\n', outfile
);
344 blen
= BLOCK_NSYMS (b
);
345 for (j
= 0; j
< blen
; j
++)
347 print_symbol (BLOCK_SYM (b
, j
), depth
+ 1, outfile
);
350 fprintf (outfile
, "\n");
354 maintenance_print_symbols (args
, from_tty
)
360 struct cleanup
*cleanups
;
361 char *symname
= NULL
;
362 char *filename
= DEV_TTY
;
363 struct objfile
*objfile
;
370 error ("print-symbols takes an output file name and optional symbol file name");
372 else if ((argv
= buildargv (args
)) == NULL
)
376 cleanups
= make_cleanup (freeargv
, (char *) argv
);
381 /* If a second arg is supplied, it is a source file name to match on */
388 filename
= tilde_expand (filename
);
389 make_cleanup (free
, filename
);
391 outfile
= fopen (filename
, "w");
393 perror_with_name (filename
);
394 make_cleanup (fclose
, (char *) outfile
);
397 ALL_SYMTABS (objfile
, s
)
398 if (symname
== NULL
|| (STREQ (symname
, s
-> filename
)))
399 dump_symtab (objfile
, s
, outfile
);
401 do_cleanups (cleanups
);
405 print_symbol (symbol
, depth
, outfile
)
406 struct symbol
*symbol
;
410 print_spaces (depth
, outfile
);
411 if (SYMBOL_NAMESPACE (symbol
) == LABEL_NAMESPACE
)
413 fprintf (outfile
, "label %s at 0x%x\n", SYMBOL_SOURCE_NAME (symbol
),
414 SYMBOL_VALUE_ADDRESS (symbol
));
417 if (SYMBOL_NAMESPACE (symbol
) == STRUCT_NAMESPACE
)
419 if (TYPE_NAME (SYMBOL_TYPE (symbol
)))
421 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
);
425 fprintf (outfile
, "%s %s = ",
426 (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_ENUM
428 : (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_STRUCT
429 ? "struct" : "union")),
430 SYMBOL_NAME (symbol
));
431 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
);
433 fprintf (outfile
, ";\n");
437 if (SYMBOL_CLASS (symbol
) == LOC_TYPEDEF
)
438 fprintf (outfile
, "typedef ");
439 if (SYMBOL_TYPE (symbol
))
441 /* Print details of types, except for enums where it's clutter. */
442 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), SYMBOL_NAME (symbol
), outfile
,
443 TYPE_CODE (SYMBOL_TYPE (symbol
)) != TYPE_CODE_ENUM
,
445 fprintf (outfile
, "; ");
448 fprintf (outfile
, "%s ", SYMBOL_SOURCE_NAME (symbol
));
450 switch (SYMBOL_CLASS (symbol
))
453 fprintf (outfile
, "const %ld (0x%lx),",
454 SYMBOL_VALUE (symbol
), SYMBOL_VALUE (symbol
));
457 case LOC_CONST_BYTES
:
458 fprintf (outfile
, "const %u hex bytes:",
459 TYPE_LENGTH (SYMBOL_TYPE (symbol
)));
462 for (i
= 0; i
< TYPE_LENGTH (SYMBOL_TYPE (symbol
)); i
++)
463 fprintf (outfile
, " %2x",
464 (unsigned)SYMBOL_VALUE_BYTES (symbol
) [i
]);
465 fprintf (outfile
, ",");
470 fprintf (outfile
, "static at 0x%x,", SYMBOL_VALUE_ADDRESS (symbol
));
474 fprintf (outfile
, "register %ld,", SYMBOL_VALUE (symbol
));
478 if (SYMBOL_BASEREG_VALID (symbol
))
480 fprintf (outfile
, "arg at 0x%lx from register %d,",
481 SYMBOL_VALUE (symbol
), SYMBOL_BASEREG (symbol
));
485 fprintf (outfile
, "arg at 0x%lx,", SYMBOL_VALUE (symbol
));
490 if (SYMBOL_BASEREG_VALID (symbol
))
492 fprintf (outfile
, "arg at offset 0x%lx from register %d,",
493 SYMBOL_VALUE (symbol
), SYMBOL_BASEREG (symbol
));
497 fprintf (outfile
, "arg at offset 0x%lx from fp,",
498 SYMBOL_VALUE (symbol
));
502 fprintf (outfile
, "reference arg at 0x%lx,", SYMBOL_VALUE (symbol
));
506 fprintf (outfile
, "parameter register %ld,", SYMBOL_VALUE (symbol
));
510 if (SYMBOL_BASEREG_VALID (symbol
))
512 fprintf (outfile
, "local at 0x%lx from register %d",
513 SYMBOL_VALUE (symbol
), SYMBOL_BASEREG (symbol
));
517 fprintf (outfile
, "local at 0x%lx,", SYMBOL_VALUE (symbol
));
525 fprintf (outfile
, "label at 0x%lx", SYMBOL_VALUE_ADDRESS (symbol
));
529 fprintf (outfile
, "block (object 0x%x) starting at 0x%x,",
530 (unsigned int) SYMBOL_BLOCK_VALUE (symbol
),
531 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
)));
535 fprintf (outfile
, "botched symbol class %x", SYMBOL_CLASS (symbol
));
539 fprintf (outfile
, "\n");
543 maintenance_print_psymbols (args
, from_tty
)
549 struct cleanup
*cleanups
;
550 char *symname
= NULL
;
551 char *filename
= DEV_TTY
;
552 struct objfile
*objfile
;
553 struct partial_symtab
*ps
;
559 error ("print-psymbols takes an output file name and optional symbol file name");
561 else if ((argv
= buildargv (args
)) == NULL
)
565 cleanups
= make_cleanup (freeargv
, (char *) argv
);
570 /* If a second arg is supplied, it is a source file name to match on */
577 filename
= tilde_expand (filename
);
578 make_cleanup (free
, filename
);
580 outfile
= fopen (filename
, "w");
582 perror_with_name (filename
);
583 make_cleanup (fclose
, outfile
);
586 ALL_PSYMTABS (objfile
, ps
)
587 if (symname
== NULL
|| (STREQ (symname
, ps
-> filename
)))
588 dump_psymtab (objfile
, ps
, outfile
);
590 do_cleanups (cleanups
);
594 print_partial_symbol (p
, count
, what
, outfile
)
595 struct partial_symbol
*p
;
601 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
604 fprintf_filtered (outfile
, " `%s'", SYMBOL_NAME(p
));
605 if (SYMBOL_DEMANGLED_NAME (p
) != NULL
)
607 fprintf_filtered (outfile
, " `%s'", SYMBOL_DEMANGLED_NAME (p
));
609 fputs_filtered (", ", outfile
);
610 switch (SYMBOL_NAMESPACE (p
))
612 case UNDEF_NAMESPACE
:
613 fputs_filtered ("undefined namespace, ", outfile
);
616 /* This is the usual thing -- don't print it */
618 case STRUCT_NAMESPACE
:
619 fputs_filtered ("struct namespace, ", outfile
);
621 case LABEL_NAMESPACE
:
622 fputs_filtered ("label namespace, ", outfile
);
625 fputs_filtered ("<invalid namespace>, ", outfile
);
628 switch (SYMBOL_CLASS (p
))
631 fputs_filtered ("undefined", outfile
);
634 fputs_filtered ("constant int", outfile
);
637 fputs_filtered ("static", outfile
);
640 fputs_filtered ("register", outfile
);
643 fputs_filtered ("pass by value", outfile
);
646 fputs_filtered ("pass by reference", outfile
);
649 fputs_filtered ("register parameter", outfile
);
652 fputs_filtered ("stack parameter", outfile
);
655 fputs_filtered ("type", outfile
);
658 fputs_filtered ("label", outfile
);
661 fputs_filtered ("function", outfile
);
663 case LOC_CONST_BYTES
:
664 fputs_filtered ("constant bytes", outfile
);
667 fputs_filtered ("shuffled arg", outfile
);
670 fputs_filtered ("<invalid location>", outfile
);
673 fputs_filtered (", ", outfile
);
674 fprintf_filtered (outfile
, "0x%x\n", SYMBOL_VALUE (p
));
680 maintenance_print_msymbols (args
, from_tty
)
686 struct cleanup
*cleanups
;
687 char *filename
= DEV_TTY
;
688 char *symname
= NULL
;
689 struct objfile
*objfile
;
695 error ("print-msymbols takes an output file name and optional symbol file name");
697 else if ((argv
= buildargv (args
)) == NULL
)
701 cleanups
= make_cleanup (freeargv
, argv
);
706 /* If a second arg is supplied, it is a source file name to match on */
713 filename
= tilde_expand (filename
);
714 make_cleanup (free
, filename
);
716 outfile
= fopen (filename
, "w");
718 perror_with_name (filename
);
719 make_cleanup (fclose
, outfile
);
722 ALL_OBJFILES (objfile
)
723 if (symname
== NULL
|| (STREQ (symname
, objfile
-> name
)))
724 dump_msymbols (objfile
, outfile
);
726 fprintf_filtered (outfile
, "\n\n");
727 do_cleanups (cleanups
);
731 maintenance_print_objfiles (ignore
, from_tty
)
735 struct objfile
*objfile
;
740 ALL_OBJFILES (objfile
)
741 dump_objfile (objfile
);
746 /* Return the nexting depth of a block within other blocks in its symtab. */
753 while ((block
= BLOCK_SUPERBLOCK (block
)) != NULL
)
760 #endif /* MAINTENANCE_CMDS */
763 /* Increase the space allocated for LISTP, which is probably
764 global_psymbol_list or static_psymbol_list. This space will eventually
765 be freed in free_objfile(). */
768 extend_psymbol_list (listp
, objfile
)
769 register struct psymbol_allocation_list
*listp
;
770 struct objfile
*objfile
;
773 if (listp
->size
== 0)
776 listp
->list
= (struct partial_symbol
*)
777 xmmalloc (objfile
-> md
, new_size
* sizeof (struct partial_symbol
));
781 new_size
= listp
->size
* 2;
782 listp
->list
= (struct partial_symbol
*)
783 xmrealloc (objfile
-> md
, (char *) listp
->list
,
784 new_size
* sizeof (struct partial_symbol
));
786 /* Next assumes we only went one over. Should be good if
787 program works correctly */
788 listp
->next
= listp
->list
+ listp
->size
;
789 listp
->size
= new_size
;
This page took 0.044334 seconds and 4 git commands to generate.