1 /* Do various things to symbol tables (other than lookup), for GDB.
2 Copyright 1986, 1987, 1989, 1991, 1992, 1993 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. This is painful
38 when calling functions that take FILE *'s from the debugger.
39 So we make a variable which has the same value and which is accessible when
40 debugging GDB with itself. Because stdin et al need not be constants,
41 we initialize them in the _initialize_symmisc function at the bottom
47 /* Prototypes for local functions */
50 dump_symtab
PARAMS ((struct objfile
*, struct symtab
*, FILE *));
53 dump_psymtab
PARAMS ((struct objfile
*, struct partial_symtab
*, FILE *));
56 dump_msymbols
PARAMS ((struct objfile
*, FILE *));
59 dump_objfile
PARAMS ((struct objfile
*));
62 block_depth
PARAMS ((struct block
*));
65 print_partial_symbol
PARAMS ((struct partial_symbol
*, int, char *, FILE *));
68 print_symbol
PARAMS ((struct symbol
*, int, FILE *));
71 free_symtab_block
PARAMS ((struct objfile
*, struct block
*));
74 /* Free a struct block <- B and all the symbols defined in that block. */
77 free_symtab_block (objfile
, b
)
78 struct objfile
*objfile
;
83 for (i
= 0; i
< n
; i
++)
85 mfree (objfile
-> md
, SYMBOL_NAME (BLOCK_SYM (b
, i
)));
86 mfree (objfile
-> md
, (PTR
) BLOCK_SYM (b
, i
));
88 mfree (objfile
-> md
, (PTR
) b
);
91 /* Free all the storage associated with the struct symtab <- S.
92 Note that some symtabs have contents malloc'ed structure by structure,
93 while some have contents that all live inside one big block of memory,
94 and some share the contents of another symbol table and so you should
95 not free the contents on their behalf (except sometimes the linetable,
96 which maybe per symtab even when the rest is not).
97 It is s->free_code that says which alternative to use. */
101 register struct symtab
*s
;
104 register struct blockvector
*bv
;
106 switch (s
->free_code
)
109 /* All the contents are part of a big block of memory (an obstack),
110 and some other symtab is in charge of freeing that block.
111 Therefore, do nothing. */
115 /* Here all the contents were malloc'ed structure by structure
116 and must be freed that way. */
117 /* First free the blocks (and their symbols. */
118 bv
= BLOCKVECTOR (s
);
119 n
= BLOCKVECTOR_NBLOCKS (bv
);
120 for (i
= 0; i
< n
; i
++)
121 free_symtab_block (s
-> objfile
, BLOCKVECTOR_BLOCK (bv
, i
));
122 /* Free the blockvector itself. */
123 mfree (s
-> objfile
-> md
, (PTR
) bv
);
124 /* Also free the linetable. */
127 /* Everything will be freed either by our `free_ptr'
128 or by some other symtab, except for our linetable.
131 mfree (s
-> objfile
-> md
, (PTR
) LINETABLE (s
));
135 /* If there is a single block of memory to free, free it. */
136 if (s
-> free_ptr
!= NULL
)
137 mfree (s
-> objfile
-> md
, s
-> free_ptr
);
139 /* Free source-related stuff */
140 if (s
-> line_charpos
!= NULL
)
141 mfree (s
-> objfile
-> md
, (PTR
) s
-> line_charpos
);
142 if (s
-> fullname
!= NULL
)
143 mfree (s
-> objfile
-> md
, s
-> fullname
);
144 mfree (s
-> objfile
-> md
, (PTR
) s
);
150 dump_objfile (objfile
)
151 struct objfile
*objfile
;
153 struct symtab
*symtab
;
154 struct partial_symtab
*psymtab
;
156 printf_filtered ("\nObject file %s: ", objfile
-> name
);
157 printf_filtered ("Objfile at %x, bfd at %x, %d minsyms\n\n",
158 objfile
, objfile
-> obfd
, objfile
->minimal_symbol_count
);
160 if (objfile
-> psymtabs
)
162 printf_filtered ("Psymtabs:\n");
163 for (psymtab
= objfile
-> psymtabs
;
165 psymtab
= psymtab
-> next
)
167 printf_filtered ("%s at %x, ", psymtab
-> filename
, psymtab
);
168 if (psymtab
-> objfile
!= objfile
)
170 printf_filtered ("NOT ON CHAIN! ");
174 printf_filtered ("\n\n");
177 if (objfile
-> symtabs
)
179 printf_filtered ("Symtabs:\n");
180 for (symtab
= objfile
-> symtabs
;
182 symtab
= symtab
->next
)
184 printf_filtered ("%s at %x, ", symtab
-> filename
, symtab
);
185 if (symtab
-> objfile
!= objfile
)
187 printf_filtered ("NOT ON CHAIN! ");
191 printf_filtered ("\n\n");
195 /* Print minimal symbols from this objfile. */
198 dump_msymbols (objfile
, outfile
)
199 struct objfile
*objfile
;
202 struct minimal_symbol
*msymbol
;
206 fprintf_filtered (outfile
, "\nObject file %s:\n\n", objfile
-> name
);
207 if (objfile
-> minimal_symbol_count
== 0)
209 fprintf_filtered (outfile
, "No minimal symbols found.\n");
212 for (index
= 0, msymbol
= objfile
-> msymbols
;
213 SYMBOL_NAME (msymbol
) != NULL
; msymbol
++, index
++)
215 switch (msymbol
-> type
)
245 fprintf_filtered (outfile
, "[%2d] %c %#10x %s", index
, ms_type
,
246 SYMBOL_VALUE_ADDRESS (msymbol
), SYMBOL_NAME (msymbol
));
247 if (SYMBOL_DEMANGLED_NAME (msymbol
) != NULL
)
249 fprintf_filtered (outfile
, " %s", SYMBOL_DEMANGLED_NAME (msymbol
));
251 fputs_filtered ("\n", outfile
);
253 if (objfile
-> minimal_symbol_count
!= index
)
255 warning ("internal error: minimal symbol count %d != %d",
256 objfile
-> minimal_symbol_count
, index
);
258 fprintf_filtered (outfile
, "\n");
262 dump_psymtab (objfile
, psymtab
, outfile
)
263 struct objfile
*objfile
;
264 struct partial_symtab
*psymtab
;
268 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
269 psymtab
-> filename
);
270 fprintf_filtered (outfile
, "(object 0x%x)\n\n", psymtab
);
271 fprintf (outfile
, " Read from object file %s (0x%x)\n",
272 objfile
-> name
, (unsigned int) objfile
);
274 if (psymtab
-> readin
)
276 fprintf_filtered (outfile
,
277 " Full symtab was read (at 0x%x by function at 0x%x)\n",
278 psymtab
-> symtab
, psymtab
-> read_symtab
);
281 /* FIXME, we need to be able to print the relocation stuff. */
282 /* This prints some garbage for anything but stabs right now. FIXME. */
283 if (psymtab
->section_offsets
)
284 fprintf_filtered (outfile
, " Relocate symbols by 0x%x, 0x%x, 0x%x, 0x%x.\n",
285 ANOFFSET (psymtab
->section_offsets
, 0),
286 ANOFFSET (psymtab
->section_offsets
, 1),
287 ANOFFSET (psymtab
->section_offsets
, 2),
288 ANOFFSET (psymtab
->section_offsets
, 3));
290 fprintf_filtered (outfile
, " Symbols cover text addresses 0x%x-0x%x\n",
291 psymtab
-> textlow
, psymtab
-> texthigh
);
292 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
293 psymtab
-> number_of_dependencies
);
294 if (psymtab
-> n_global_syms
> 0)
296 print_partial_symbol (objfile
-> global_psymbols
.list
297 + psymtab
-> globals_offset
,
298 psymtab
-> n_global_syms
, "Global", outfile
);
300 if (psymtab
-> n_static_syms
> 0)
302 print_partial_symbol (objfile
-> static_psymbols
.list
303 + psymtab
-> statics_offset
,
304 psymtab
-> n_static_syms
, "Static", outfile
);
306 fprintf_filtered (outfile
, "\n");
310 dump_symtab (objfile
, symtab
, outfile
)
311 struct objfile
*objfile
;
312 struct symtab
*symtab
;
317 register struct linetable
*l
;
318 struct blockvector
*bv
;
319 register struct block
*b
;
322 fprintf (outfile
, "\nSymtab for file %s\n", symtab
->filename
);
323 fprintf (outfile
, "Read from object file %s (%x)\n", objfile
->name
,
324 (unsigned int) objfile
);
325 fprintf (outfile
, "Language: %s\n", language_str (symtab
-> language
));
327 /* First print the line table. */
328 l
= LINETABLE (symtab
);
330 fprintf (outfile
, "\nLine table:\n\n");
332 for (i
= 0; i
< len
; i
++)
333 fprintf (outfile
, " line %d at %x\n", l
->item
[i
].line
,
336 /* Now print the block info. */
337 fprintf (outfile
, "\nBlockvector:\n\n");
338 bv
= BLOCKVECTOR (symtab
);
339 len
= BLOCKVECTOR_NBLOCKS (bv
);
340 for (i
= 0; i
< len
; i
++)
342 b
= BLOCKVECTOR_BLOCK (bv
, i
);
343 depth
= block_depth (b
) * 2;
344 print_spaces (depth
, outfile
);
345 fprintf (outfile
, "block #%03d (object 0x%x) ", i
, (unsigned int) b
);
346 fprintf (outfile
, "[0x%x..0x%x]", BLOCK_START (b
), BLOCK_END (b
));
347 if (BLOCK_SUPERBLOCK (b
))
348 fprintf (outfile
, " (under 0x%x)", (unsigned int) BLOCK_SUPERBLOCK (b
));
349 if (BLOCK_FUNCTION (b
))
351 fprintf (outfile
, " %s", SYMBOL_NAME (BLOCK_FUNCTION (b
)));
352 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b
)) != NULL
)
354 fprintf (outfile
, " %s",
355 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b
)));
358 if (BLOCK_GCC_COMPILED(b
))
359 fprintf (outfile
, " gcc%d compiled", BLOCK_GCC_COMPILED(b
));
360 fputc ('\n', outfile
);
361 blen
= BLOCK_NSYMS (b
);
362 for (j
= 0; j
< blen
; j
++)
364 print_symbol (BLOCK_SYM (b
, j
), depth
+ 1, outfile
);
367 fprintf (outfile
, "\n");
371 maintenance_print_symbols (args
, from_tty
)
377 struct cleanup
*cleanups
;
378 char *symname
= NULL
;
379 char *filename
= DEV_TTY
;
380 struct objfile
*objfile
;
387 error ("print-symbols takes an output file name and optional symbol file name");
389 else if ((argv
= buildargv (args
)) == NULL
)
393 cleanups
= make_cleanup (freeargv
, (char *) argv
);
398 /* If a second arg is supplied, it is a source file name to match on */
405 filename
= tilde_expand (filename
);
406 make_cleanup (free
, filename
);
408 outfile
= fopen (filename
, FOPEN_WT
);
410 perror_with_name (filename
);
411 make_cleanup (fclose
, (char *) outfile
);
414 ALL_SYMTABS (objfile
, s
)
415 if (symname
== NULL
|| (STREQ (symname
, s
-> filename
)))
416 dump_symtab (objfile
, s
, outfile
);
418 do_cleanups (cleanups
);
422 print_symbol (symbol
, depth
, outfile
)
423 struct symbol
*symbol
;
427 print_spaces (depth
, outfile
);
428 if (SYMBOL_NAMESPACE (symbol
) == LABEL_NAMESPACE
)
430 fprintf (outfile
, "label %s at 0x%x\n", SYMBOL_SOURCE_NAME (symbol
),
431 SYMBOL_VALUE_ADDRESS (symbol
));
434 if (SYMBOL_NAMESPACE (symbol
) == STRUCT_NAMESPACE
)
436 if (TYPE_NAME (SYMBOL_TYPE (symbol
)))
438 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
);
442 fprintf (outfile
, "%s %s = ",
443 (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_ENUM
445 : (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_STRUCT
446 ? "struct" : "union")),
447 SYMBOL_NAME (symbol
));
448 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
);
450 fprintf (outfile
, ";\n");
454 if (SYMBOL_CLASS (symbol
) == LOC_TYPEDEF
)
455 fprintf (outfile
, "typedef ");
456 if (SYMBOL_TYPE (symbol
))
458 /* Print details of types, except for enums where it's clutter. */
459 LA_PRINT_TYPE (SYMBOL_TYPE (symbol
), SYMBOL_SOURCE_NAME (symbol
),
461 TYPE_CODE (SYMBOL_TYPE (symbol
)) != TYPE_CODE_ENUM
,
463 fprintf (outfile
, "; ");
466 fprintf (outfile
, "%s ", SYMBOL_SOURCE_NAME (symbol
));
468 switch (SYMBOL_CLASS (symbol
))
471 fprintf (outfile
, "const %ld (0x%lx),",
472 SYMBOL_VALUE (symbol
), SYMBOL_VALUE (symbol
));
475 case LOC_CONST_BYTES
:
476 fprintf (outfile
, "const %u hex bytes:",
477 TYPE_LENGTH (SYMBOL_TYPE (symbol
)));
480 for (i
= 0; i
< TYPE_LENGTH (SYMBOL_TYPE (symbol
)); i
++)
481 fprintf (outfile
, " %2x",
482 (unsigned)SYMBOL_VALUE_BYTES (symbol
) [i
]);
483 fprintf (outfile
, ",");
488 fprintf (outfile
, "static at 0x%x,", SYMBOL_VALUE_ADDRESS (symbol
));
492 fprintf (outfile
, "register %ld,", SYMBOL_VALUE (symbol
));
496 if (SYMBOL_BASEREG_VALID (symbol
))
498 fprintf (outfile
, "arg at 0x%lx from register %d,",
499 SYMBOL_VALUE (symbol
), SYMBOL_BASEREG (symbol
));
503 fprintf (outfile
, "arg at 0x%lx,", SYMBOL_VALUE (symbol
));
508 if (SYMBOL_BASEREG_VALID (symbol
))
510 fprintf (outfile
, "arg at offset 0x%lx from register %d,",
511 SYMBOL_VALUE (symbol
), SYMBOL_BASEREG (symbol
));
515 fprintf (outfile
, "arg at offset 0x%lx from fp,",
516 SYMBOL_VALUE (symbol
));
520 fprintf (outfile
, "reference arg at 0x%lx,", SYMBOL_VALUE (symbol
));
524 fprintf (outfile
, "parameter register %ld,", SYMBOL_VALUE (symbol
));
527 case LOC_REGPARM_ADDR
:
528 fprintf (outfile
, "address parameter register %ld,", SYMBOL_VALUE (symbol
));
532 if (SYMBOL_BASEREG_VALID (symbol
))
534 fprintf (outfile
, "local at 0x%lx from register %d",
535 SYMBOL_VALUE (symbol
), SYMBOL_BASEREG (symbol
));
539 fprintf (outfile
, "local at 0x%lx,", SYMBOL_VALUE (symbol
));
547 fprintf (outfile
, "label at 0x%lx", SYMBOL_VALUE_ADDRESS (symbol
));
551 fprintf (outfile
, "block (object 0x%x) starting at 0x%x,",
552 (unsigned int) SYMBOL_BLOCK_VALUE (symbol
),
553 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
)));
556 case LOC_OPTIMIZED_OUT
:
557 fprintf (outfile
, "optimized out");
561 fprintf (outfile
, "botched symbol class %x", SYMBOL_CLASS (symbol
));
565 fprintf (outfile
, "\n");
569 maintenance_print_psymbols (args
, from_tty
)
575 struct cleanup
*cleanups
;
576 char *symname
= NULL
;
577 char *filename
= DEV_TTY
;
578 struct objfile
*objfile
;
579 struct partial_symtab
*ps
;
585 error ("print-psymbols takes an output file name and optional symbol file name");
587 else if ((argv
= buildargv (args
)) == NULL
)
591 cleanups
= make_cleanup (freeargv
, (char *) argv
);
596 /* If a second arg is supplied, it is a source file name to match on */
603 filename
= tilde_expand (filename
);
604 make_cleanup (free
, filename
);
606 outfile
= fopen (filename
, FOPEN_WT
);
608 perror_with_name (filename
);
609 make_cleanup (fclose
, outfile
);
612 ALL_PSYMTABS (objfile
, ps
)
613 if (symname
== NULL
|| (STREQ (symname
, ps
-> filename
)))
614 dump_psymtab (objfile
, ps
, outfile
);
616 do_cleanups (cleanups
);
620 print_partial_symbol (p
, count
, what
, outfile
)
621 struct partial_symbol
*p
;
627 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
630 fprintf_filtered (outfile
, " `%s'", SYMBOL_NAME(p
));
631 if (SYMBOL_DEMANGLED_NAME (p
) != NULL
)
633 fprintf_filtered (outfile
, " `%s'", SYMBOL_DEMANGLED_NAME (p
));
635 fputs_filtered (", ", outfile
);
636 switch (SYMBOL_NAMESPACE (p
))
638 case UNDEF_NAMESPACE
:
639 fputs_filtered ("undefined namespace, ", outfile
);
642 /* This is the usual thing -- don't print it */
644 case STRUCT_NAMESPACE
:
645 fputs_filtered ("struct namespace, ", outfile
);
647 case LABEL_NAMESPACE
:
648 fputs_filtered ("label namespace, ", outfile
);
651 fputs_filtered ("<invalid namespace>, ", outfile
);
654 switch (SYMBOL_CLASS (p
))
657 fputs_filtered ("undefined", outfile
);
660 fputs_filtered ("constant int", outfile
);
663 fputs_filtered ("static", outfile
);
666 fputs_filtered ("register", outfile
);
669 fputs_filtered ("pass by value", outfile
);
672 fputs_filtered ("pass by reference", outfile
);
675 fputs_filtered ("register parameter", outfile
);
677 case LOC_REGPARM_ADDR
:
678 fputs_filtered ("register address parameter", outfile
);
681 fputs_filtered ("stack parameter", outfile
);
684 fputs_filtered ("type", outfile
);
687 fputs_filtered ("label", outfile
);
690 fputs_filtered ("function", outfile
);
692 case LOC_CONST_BYTES
:
693 fputs_filtered ("constant bytes", outfile
);
696 fputs_filtered ("shuffled arg", outfile
);
698 case LOC_OPTIMIZED_OUT
:
699 fputs_filtered ("optimized out", outfile
);
702 fputs_filtered ("<invalid location>", outfile
);
705 fputs_filtered (", ", outfile
);
706 fprintf_filtered (outfile
, "0x%x\n", SYMBOL_VALUE (p
));
712 maintenance_print_msymbols (args
, from_tty
)
718 struct cleanup
*cleanups
;
719 char *filename
= DEV_TTY
;
720 char *symname
= NULL
;
721 struct objfile
*objfile
;
727 error ("print-msymbols takes an output file name and optional symbol file name");
729 else if ((argv
= buildargv (args
)) == NULL
)
733 cleanups
= make_cleanup (freeargv
, argv
);
738 /* If a second arg is supplied, it is a source file name to match on */
745 filename
= tilde_expand (filename
);
746 make_cleanup (free
, filename
);
748 outfile
= fopen (filename
, FOPEN_WT
);
750 perror_with_name (filename
);
751 make_cleanup (fclose
, outfile
);
754 ALL_OBJFILES (objfile
)
755 if (symname
== NULL
|| (STREQ (symname
, objfile
-> name
)))
756 dump_msymbols (objfile
, outfile
);
758 fprintf_filtered (outfile
, "\n\n");
759 do_cleanups (cleanups
);
763 maintenance_print_objfiles (ignore
, from_tty
)
767 struct objfile
*objfile
;
772 ALL_OBJFILES (objfile
)
773 dump_objfile (objfile
);
778 /* Return the nexting depth of a block within other blocks in its symtab. */
785 while ((block
= BLOCK_SUPERBLOCK (block
)) != NULL
)
792 #endif /* MAINTENANCE_CMDS */
795 /* Increase the space allocated for LISTP, which is probably
796 global_psymbol_list or static_psymbol_list. This space will eventually
797 be freed in free_objfile(). */
800 extend_psymbol_list (listp
, objfile
)
801 register struct psymbol_allocation_list
*listp
;
802 struct objfile
*objfile
;
805 if (listp
->size
== 0)
808 listp
->list
= (struct partial_symbol
*)
809 xmmalloc (objfile
-> md
, new_size
* sizeof (struct partial_symbol
));
813 new_size
= listp
->size
* 2;
814 listp
->list
= (struct partial_symbol
*)
815 xmrealloc (objfile
-> md
, (char *) listp
->list
,
816 new_size
* sizeof (struct partial_symbol
));
818 /* Next assumes we only went one over. Should be good if
819 program works correctly */
820 listp
->next
= listp
->list
+ listp
->size
;
821 listp
->size
= new_size
;
825 /* Do early runtime initializations. */
827 _initialize_symmisc ()
This page took 0.065664 seconds and 4 git commands to generate.