1 /* Do various things to symbol tables (other than lookup)), for GDB.
2 Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc.
4 This file is part of GDB.
6 GDB 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 1, or (at your option)
11 GDB 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 GDB; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include "breakpoint.h"
30 /* Free all the symtabs that are currently installed,
31 and all storage associated with them.
32 Leaves us in a consistent state with no symtabs installed. */
37 register struct symtab
*s
, *snext
;
39 /* All values will be invalid because their types will be! */
41 clear_value_history ();
43 clear_internalvars ();
44 #if defined (CLEAR_SOLIB)
47 set_default_breakpoint (0, 0, 0, 0);
49 current_source_symtab
= 0;
51 for (s
= symtab_list
; s
; s
= snext
)
57 obstack_free (symbol_obstack
, 0);
58 obstack_init (symbol_obstack
);
60 if (misc_function_vector
)
61 free (misc_function_vector
);
62 misc_function_count
= 0;
63 misc_function_vector
= 0;
64 clear_pc_function_cache();
67 /* Free a struct block <- B and all the symbols defined in that block. */
75 for (i
= 0; i
< n
; i
++)
77 free (SYMBOL_NAME (BLOCK_SYM (b
, i
)));
78 free (BLOCK_SYM (b
, i
));
83 /* Free all the storage associated with the struct symtab <- S.
84 Note that some symtabs have contents malloc'ed structure by structure,
85 while some have contents that all live inside one big block of memory,
86 and some share the contents of another symbol table and so you should
87 not free the contents on their behalf (except sometimes the linetable,
88 which maybe per symtab even when the rest is not).
89 It is s->free_code that says which alternative to use. */
93 register struct symtab
*s
;
96 register struct blockvector
*bv
;
97 register struct typevector
*tv
;
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 /* Here all the contents were malloc'ed structure by structure
109 and must be freed that way. */
110 /* First free the blocks (and their symbols. */
111 bv
= BLOCKVECTOR (s
);
112 n
= BLOCKVECTOR_NBLOCKS (bv
);
113 for (i
= 0; i
< n
; i
++)
114 free_symtab_block (BLOCKVECTOR_BLOCK (bv
, i
));
115 /* Free the blockvector itself. */
117 /* Free the type vector. */
120 /* Also free the linetable. */
123 /* Everything will be freed either by our `free_ptr'
124 or by some other symbatb, except for our linetable.
126 free (LINETABLE (s
));
130 /* If there is a single block of memory to free, free it. */
134 /* Free source-related stuff */
136 free (s
->line_charpos
);
142 static int block_depth ();
143 static void print_symbol ();
146 print_symtabs (filename
)
150 register struct symtab
*s
;
153 register struct linetable
*l
;
154 struct blockvector
*bv
;
155 register struct block
*b
;
157 struct cleanup
*cleanups
;
161 error_no_arg ("file to write symbol data in");
163 filename
= tilde_expand (filename
);
164 make_cleanup (free
, filename
);
166 outfile
= fopen (filename
, "w");
168 perror_with_name (filename
);
170 cleanups
= make_cleanup (fclose
, outfile
);
173 for (s
= symtab_list
; s
; s
= s
->next
)
175 /* First print the line table. */
176 fprintf (outfile
, "Symtab for file %s\n\n", s
->filename
);
177 fprintf (outfile
, "Line table:\n\n");
180 for (i
= 0; i
< len
; i
++)
181 fprintf (outfile
, " line %d at %x\n", l
->item
[i
].line
,
183 /* Now print the block info. */
184 fprintf (outfile
, "\nBlockvector:\n\n");
185 bv
= BLOCKVECTOR (s
);
186 len
= BLOCKVECTOR_NBLOCKS (bv
);
187 for (i
= 0; i
< len
; i
++)
189 b
= BLOCKVECTOR_BLOCK (bv
, i
);
190 depth
= block_depth (b
) * 2;
191 print_spaces (depth
, outfile
);
192 fprintf (outfile
, "block #%03d (object 0x%x) ", i
, b
);
193 fprintf (outfile
, "[0x%x..0x%x]", BLOCK_START (b
), BLOCK_END (b
));
194 if (BLOCK_SUPERBLOCK (b
))
195 fprintf (outfile
, " (under 0x%x)", BLOCK_SUPERBLOCK (b
));
196 if (BLOCK_FUNCTION (b
))
197 fprintf (outfile
, " %s", SYMBOL_NAME (BLOCK_FUNCTION (b
)));
198 fputc ('\n', outfile
);
199 blen
= BLOCK_NSYMS (b
);
200 for (j
= 0; j
< blen
; j
++)
202 print_symbol (BLOCK_SYM (b
, j
), depth
+ 1, outfile
);
206 fprintf (outfile
, "\n\n");
210 do_cleanups (cleanups
);
214 print_symbol (symbol
, depth
, outfile
)
215 struct symbol
*symbol
;
219 print_spaces (depth
, outfile
);
220 if (SYMBOL_NAMESPACE (symbol
) == LABEL_NAMESPACE
)
222 fprintf (outfile
, "label %s at 0x%x\n", SYMBOL_NAME (symbol
),
223 SYMBOL_VALUE_ADDRESS (symbol
));
226 if (SYMBOL_NAMESPACE (symbol
) == STRUCT_NAMESPACE
)
228 if (TYPE_NAME (SYMBOL_TYPE (symbol
)))
230 type_print_1 (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
);
234 fprintf (outfile
, "%s %s = ",
235 (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_ENUM
237 : (TYPE_CODE (SYMBOL_TYPE (symbol
)) == TYPE_CODE_STRUCT
238 ? "struct" : "union")),
239 SYMBOL_NAME (symbol
));
240 type_print_1 (SYMBOL_TYPE (symbol
), "", outfile
, 1, depth
);
242 fprintf (outfile
, ";\n");
246 if (SYMBOL_CLASS (symbol
) == LOC_TYPEDEF
)
247 fprintf (outfile
, "typedef ");
248 if (SYMBOL_TYPE (symbol
))
250 type_print_1 (SYMBOL_TYPE (symbol
), SYMBOL_NAME (symbol
),
252 fprintf (outfile
, "; ");
255 fprintf (outfile
, "%s ", SYMBOL_NAME (symbol
));
257 switch (SYMBOL_CLASS (symbol
))
260 fprintf (outfile
, "const %ld (0x%lx),",
261 SYMBOL_VALUE (symbol
), SYMBOL_VALUE (symbol
));
264 case LOC_CONST_BYTES
:
265 fprintf (outfile
, "const %u hex bytes:",
266 TYPE_LENGTH (SYMBOL_TYPE (symbol
)));
269 for (i
= 0; i
< TYPE_LENGTH (SYMBOL_TYPE (symbol
)); i
++)
270 fprintf (outfile
, " %2x",
271 (unsigned)SYMBOL_VALUE_BYTES (symbol
) [i
]);
272 fprintf (outfile
, ",");
277 fprintf (outfile
, "static at 0x%x,", SYMBOL_VALUE_ADDRESS (symbol
));
281 fprintf (outfile
, "register %ld,", SYMBOL_VALUE (symbol
));
285 fprintf (outfile
, "arg at 0x%lx,", SYMBOL_VALUE (symbol
));
289 fprintf (outfile
, "arg at offset 0x%x from fp,",
290 SYMBOL_VALUE (symbol
));
293 fprintf (outfile
, "reference arg at 0x%lx,", SYMBOL_VALUE (symbol
));
297 fprintf (outfile
, "parameter register %ld,", SYMBOL_VALUE (symbol
));
301 fprintf (outfile
, "local at 0x%lx,", SYMBOL_VALUE (symbol
));
308 fprintf (outfile
, "label at 0x%lx", SYMBOL_VALUE_ADDRESS (symbol
));
312 fprintf (outfile
, "block (object 0x%x) starting at 0x%x,",
313 SYMBOL_BLOCK_VALUE (symbol
),
314 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol
)));
318 fprintf (outfile
, "external at 0x%x", SYMBOL_VALUE_ADDRESS (symbol
));
322 fprintf (outfile
, "botched symbol class %x", SYMBOL_CLASS (symbol
));
326 fprintf (outfile
, "\n");
329 /* Return the nexting depth of a block within other blocks in its symtab. */
336 while (block
= BLOCK_SUPERBLOCK (block
)) i
++;
341 * Free all partial_symtab storage.
346 obstack_free (psymbol_obstack
, 0);
347 obstack_init (psymbol_obstack
);
348 partial_symtab_list
= (struct partial_symtab
*) 0;
352 _initialize_symmisc ()
354 symtab_list
= (struct symtab
*) 0;
355 partial_symtab_list
= (struct partial_symtab
*) 0;
357 add_com ("printsyms", class_obscure
, print_symtabs
,
358 "Print dump of current symbol definitions to file OUTFILE.");
This page took 0.036053 seconds and 4 git commands to generate.