]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Do various things to symbol tables (other than lookup), for GDB. |
af5f3db6 AC |
2 | |
3 | Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, | |
b99607ea | 4 | 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004 Free Software |
de5ad195 | 5 | Foundation, Inc. |
c906108c | 6 | |
c5aa993b | 7 | This file is part of GDB. |
c906108c | 8 | |
c5aa993b JM |
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 2 of the License, or | |
12 | (at your option) any later version. | |
c906108c | 13 | |
c5aa993b JM |
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. | |
c906108c | 18 | |
c5aa993b JM |
19 | You should have received a copy of the GNU General Public License |
20 | along with this program; if not, write to the Free Software | |
21 | Foundation, Inc., 59 Temple Place - Suite 330, | |
22 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
23 | |
24 | #include "defs.h" | |
25 | #include "symtab.h" | |
26 | #include "gdbtypes.h" | |
27 | #include "bfd.h" | |
28 | #include "symfile.h" | |
29 | #include "objfiles.h" | |
30 | #include "breakpoint.h" | |
31 | #include "command.h" | |
04ea0df1 | 32 | #include "gdb_obstack.h" |
60250e8b | 33 | #include "exceptions.h" |
c906108c SS |
34 | #include "language.h" |
35 | #include "bcache.h" | |
fe898f56 | 36 | #include "block.h" |
44ea7b70 | 37 | #include "gdb_regex.h" |
de4f826b | 38 | #include "dictionary.h" |
c906108c SS |
39 | |
40 | #include "gdb_string.h" | |
dbda9972 | 41 | #include "readline/readline.h" |
c906108c SS |
42 | |
43 | #ifndef DEV_TTY | |
44 | #define DEV_TTY "/dev/tty" | |
45 | #endif | |
46 | ||
47 | /* Unfortunately for debugging, stderr is usually a macro. This is painful | |
48 | when calling functions that take FILE *'s from the debugger. | |
49 | So we make a variable which has the same value and which is accessible when | |
50 | debugging GDB with itself. Because stdin et al need not be constants, | |
51 | we initialize them in the _initialize_symmisc function at the bottom | |
52 | of the file. */ | |
53 | FILE *std_in; | |
54 | FILE *std_out; | |
55 | FILE *std_err; | |
56 | ||
57 | /* Prototypes for local functions */ | |
58 | ||
d9fcf2fb JM |
59 | static void dump_symtab (struct objfile *, struct symtab *, |
60 | struct ui_file *); | |
c906108c | 61 | |
d9fcf2fb JM |
62 | static void dump_psymtab (struct objfile *, struct partial_symtab *, |
63 | struct ui_file *); | |
c906108c | 64 | |
d9fcf2fb | 65 | static void dump_msymbols (struct objfile *, struct ui_file *); |
c906108c | 66 | |
a14ed312 | 67 | static void dump_objfile (struct objfile *); |
c906108c | 68 | |
a14ed312 | 69 | static int block_depth (struct block *); |
c906108c | 70 | |
d9fcf2fb JM |
71 | static void print_partial_symbols (struct partial_symbol **, int, |
72 | char *, struct ui_file *); | |
c906108c | 73 | |
a14ed312 | 74 | static void free_symtab_block (struct objfile *, struct block *); |
c906108c | 75 | |
a14ed312 | 76 | void _initialize_symmisc (void); |
c906108c | 77 | |
c5aa993b JM |
78 | struct print_symbol_args |
79 | { | |
80 | struct symbol *symbol; | |
81 | int depth; | |
d9fcf2fb | 82 | struct ui_file *outfile; |
c5aa993b | 83 | }; |
c906108c | 84 | |
4efb68b1 | 85 | static int print_symbol (void *); |
c906108c | 86 | |
a14ed312 | 87 | static void free_symtab_block (struct objfile *, struct block *); |
c906108c | 88 | \f |
c5aa993b | 89 | |
c906108c SS |
90 | /* Free a struct block <- B and all the symbols defined in that block. */ |
91 | ||
de4f826b DC |
92 | /* FIXME: carlton/2003-04-28: I don't believe this is currently ever |
93 | used. */ | |
94 | ||
c906108c | 95 | static void |
fba45db2 | 96 | free_symtab_block (struct objfile *objfile, struct block *b) |
c906108c | 97 | { |
de4f826b DC |
98 | struct dict_iterator iter; |
99 | struct symbol *sym; | |
261397f8 | 100 | |
de4f826b | 101 | ALL_BLOCK_SYMBOLS (b, iter, sym) |
c906108c | 102 | { |
2dc74dc1 AC |
103 | xfree (DEPRECATED_SYMBOL_NAME (sym)); |
104 | xfree (sym); | |
c906108c | 105 | } |
de4f826b DC |
106 | |
107 | dict_free (BLOCK_DICT (b)); | |
2dc74dc1 | 108 | xfree (b); |
c906108c SS |
109 | } |
110 | ||
111 | /* Free all the storage associated with the struct symtab <- S. | |
112 | Note that some symtabs have contents malloc'ed structure by structure, | |
113 | while some have contents that all live inside one big block of memory, | |
114 | and some share the contents of another symbol table and so you should | |
115 | not free the contents on their behalf (except sometimes the linetable, | |
116 | which maybe per symtab even when the rest is not). | |
117 | It is s->free_code that says which alternative to use. */ | |
118 | ||
119 | void | |
aa1ee363 | 120 | free_symtab (struct symtab *s) |
c906108c | 121 | { |
52f0bd74 AC |
122 | int i, n; |
123 | struct blockvector *bv; | |
c906108c SS |
124 | |
125 | switch (s->free_code) | |
126 | { | |
127 | case free_nothing: | |
128 | /* All the contents are part of a big block of memory (an obstack), | |
c5aa993b JM |
129 | and some other symtab is in charge of freeing that block. |
130 | Therefore, do nothing. */ | |
c906108c SS |
131 | break; |
132 | ||
133 | case free_contents: | |
134 | /* Here all the contents were malloc'ed structure by structure | |
c5aa993b | 135 | and must be freed that way. */ |
c906108c SS |
136 | /* First free the blocks (and their symbols. */ |
137 | bv = BLOCKVECTOR (s); | |
138 | n = BLOCKVECTOR_NBLOCKS (bv); | |
139 | for (i = 0; i < n; i++) | |
c5aa993b | 140 | free_symtab_block (s->objfile, BLOCKVECTOR_BLOCK (bv, i)); |
c906108c | 141 | /* Free the blockvector itself. */ |
2dc74dc1 | 142 | xfree (bv); |
c906108c | 143 | /* Also free the linetable. */ |
c5aa993b | 144 | |
c906108c | 145 | case free_linetable: |
de4f826b | 146 | /* Everything will be freed either by our `free_func' |
c5aa993b JM |
147 | or by some other symtab, except for our linetable. |
148 | Free that now. */ | |
c906108c | 149 | if (LINETABLE (s)) |
2dc74dc1 | 150 | xfree (LINETABLE (s)); |
c906108c SS |
151 | break; |
152 | } | |
153 | ||
154 | /* If there is a single block of memory to free, free it. */ | |
de4f826b DC |
155 | if (s->free_func != NULL) |
156 | s->free_func (s); | |
c906108c SS |
157 | |
158 | /* Free source-related stuff */ | |
c5aa993b | 159 | if (s->line_charpos != NULL) |
2dc74dc1 | 160 | xfree (s->line_charpos); |
c5aa993b | 161 | if (s->fullname != NULL) |
2dc74dc1 | 162 | xfree (s->fullname); |
c5aa993b | 163 | if (s->debugformat != NULL) |
2dc74dc1 AC |
164 | xfree (s->debugformat); |
165 | xfree (s); | |
c906108c SS |
166 | } |
167 | ||
c906108c | 168 | void |
fba45db2 | 169 | print_symbol_bcache_statistics (void) |
c906108c SS |
170 | { |
171 | struct objfile *objfile; | |
172 | ||
173 | immediate_quit++; | |
174 | ALL_OBJFILES (objfile) | |
c5aa993b JM |
175 | { |
176 | printf_filtered ("Byte cache statistics for '%s':\n", objfile->name); | |
af5f3db6 | 177 | print_bcache_statistics (objfile->psymbol_cache, "partial symbol cache"); |
c5aa993b | 178 | } |
c906108c SS |
179 | immediate_quit--; |
180 | } | |
181 | ||
182 | void | |
fba45db2 | 183 | print_objfile_statistics (void) |
c906108c SS |
184 | { |
185 | struct objfile *objfile; | |
c4f90d87 JM |
186 | struct symtab *s; |
187 | struct partial_symtab *ps; | |
188 | int i, linetables, blockvectors; | |
c906108c SS |
189 | |
190 | immediate_quit++; | |
191 | ALL_OBJFILES (objfile) | |
c5aa993b JM |
192 | { |
193 | printf_filtered ("Statistics for '%s':\n", objfile->name); | |
194 | if (OBJSTAT (objfile, n_stabs) > 0) | |
195 | printf_filtered (" Number of \"stab\" symbols read: %d\n", | |
196 | OBJSTAT (objfile, n_stabs)); | |
197 | if (OBJSTAT (objfile, n_minsyms) > 0) | |
198 | printf_filtered (" Number of \"minimal\" symbols read: %d\n", | |
199 | OBJSTAT (objfile, n_minsyms)); | |
200 | if (OBJSTAT (objfile, n_psyms) > 0) | |
201 | printf_filtered (" Number of \"partial\" symbols read: %d\n", | |
202 | OBJSTAT (objfile, n_psyms)); | |
203 | if (OBJSTAT (objfile, n_syms) > 0) | |
204 | printf_filtered (" Number of \"full\" symbols read: %d\n", | |
205 | OBJSTAT (objfile, n_syms)); | |
206 | if (OBJSTAT (objfile, n_types) > 0) | |
207 | printf_filtered (" Number of \"types\" defined: %d\n", | |
208 | OBJSTAT (objfile, n_types)); | |
c4f90d87 JM |
209 | i = 0; |
210 | ALL_OBJFILE_PSYMTABS (objfile, ps) | |
211 | { | |
212 | if (ps->readin == 0) | |
213 | i++; | |
214 | } | |
215 | printf_filtered (" Number of psym tables (not yet expanded): %d\n", i); | |
216 | i = linetables = blockvectors = 0; | |
217 | ALL_OBJFILE_SYMTABS (objfile, s) | |
218 | { | |
219 | i++; | |
220 | if (s->linetable != NULL) | |
221 | linetables++; | |
222 | if (s->primary == 1) | |
223 | blockvectors++; | |
224 | } | |
225 | printf_filtered (" Number of symbol tables: %d\n", i); | |
226 | printf_filtered (" Number of symbol tables with line tables: %d\n", | |
227 | linetables); | |
228 | printf_filtered (" Number of symbol tables with blockvectors: %d\n", | |
229 | blockvectors); | |
230 | ||
c5aa993b JM |
231 | if (OBJSTAT (objfile, sz_strtab) > 0) |
232 | printf_filtered (" Space used by a.out string tables: %d\n", | |
233 | OBJSTAT (objfile, sz_strtab)); | |
4a146b47 EZ |
234 | printf_filtered (" Total memory used for objfile obstack: %d\n", |
235 | obstack_memory_used (&objfile->objfile_obstack)); | |
c5aa993b | 236 | printf_filtered (" Total memory used for psymbol cache: %d\n", |
af5f3db6 | 237 | bcache_memory_used (objfile->psymbol_cache)); |
99d9066e | 238 | printf_filtered (" Total memory used for macro cache: %d\n", |
af5f3db6 | 239 | bcache_memory_used (objfile->macro_cache)); |
c5aa993b | 240 | } |
c906108c SS |
241 | immediate_quit--; |
242 | } | |
243 | ||
c5aa993b | 244 | static void |
fba45db2 | 245 | dump_objfile (struct objfile *objfile) |
c906108c SS |
246 | { |
247 | struct symtab *symtab; | |
248 | struct partial_symtab *psymtab; | |
249 | ||
c5aa993b | 250 | printf_filtered ("\nObject file %s: ", objfile->name); |
c906108c | 251 | printf_filtered ("Objfile at "); |
d4f3574e | 252 | gdb_print_host_address (objfile, gdb_stdout); |
c906108c | 253 | printf_filtered (", bfd at "); |
d4f3574e | 254 | gdb_print_host_address (objfile->obfd, gdb_stdout); |
c906108c SS |
255 | printf_filtered (", %d minsyms\n\n", |
256 | objfile->minimal_symbol_count); | |
257 | ||
c5aa993b | 258 | if (objfile->psymtabs) |
c906108c SS |
259 | { |
260 | printf_filtered ("Psymtabs:\n"); | |
c5aa993b | 261 | for (psymtab = objfile->psymtabs; |
c906108c | 262 | psymtab != NULL; |
c5aa993b | 263 | psymtab = psymtab->next) |
c906108c SS |
264 | { |
265 | printf_filtered ("%s at ", | |
c5aa993b | 266 | psymtab->filename); |
d4f3574e | 267 | gdb_print_host_address (psymtab, gdb_stdout); |
c906108c | 268 | printf_filtered (", "); |
c5aa993b | 269 | if (psymtab->objfile != objfile) |
c906108c SS |
270 | { |
271 | printf_filtered ("NOT ON CHAIN! "); | |
272 | } | |
273 | wrap_here (" "); | |
274 | } | |
275 | printf_filtered ("\n\n"); | |
276 | } | |
277 | ||
c5aa993b | 278 | if (objfile->symtabs) |
c906108c SS |
279 | { |
280 | printf_filtered ("Symtabs:\n"); | |
c5aa993b | 281 | for (symtab = objfile->symtabs; |
c906108c SS |
282 | symtab != NULL; |
283 | symtab = symtab->next) | |
284 | { | |
c5aa993b | 285 | printf_filtered ("%s at ", symtab->filename); |
d4f3574e | 286 | gdb_print_host_address (symtab, gdb_stdout); |
c906108c | 287 | printf_filtered (", "); |
c5aa993b | 288 | if (symtab->objfile != objfile) |
c906108c SS |
289 | { |
290 | printf_filtered ("NOT ON CHAIN! "); | |
291 | } | |
292 | wrap_here (" "); | |
293 | } | |
294 | printf_filtered ("\n\n"); | |
295 | } | |
296 | } | |
297 | ||
298 | /* Print minimal symbols from this objfile. */ | |
c5aa993b JM |
299 | |
300 | static void | |
fba45db2 | 301 | dump_msymbols (struct objfile *objfile, struct ui_file *outfile) |
c906108c SS |
302 | { |
303 | struct minimal_symbol *msymbol; | |
304 | int index; | |
305 | char ms_type; | |
c5aa993b JM |
306 | |
307 | fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile->name); | |
308 | if (objfile->minimal_symbol_count == 0) | |
c906108c SS |
309 | { |
310 | fprintf_filtered (outfile, "No minimal symbols found.\n"); | |
311 | return; | |
312 | } | |
c5aa993b | 313 | for (index = 0, msymbol = objfile->msymbols; |
22abf04a | 314 | DEPRECATED_SYMBOL_NAME (msymbol) != NULL; msymbol++, index++) |
c906108c | 315 | { |
c5aa993b | 316 | switch (msymbol->type) |
c906108c | 317 | { |
c5aa993b JM |
318 | case mst_unknown: |
319 | ms_type = 'u'; | |
320 | break; | |
321 | case mst_text: | |
322 | ms_type = 'T'; | |
323 | break; | |
324 | case mst_solib_trampoline: | |
325 | ms_type = 'S'; | |
326 | break; | |
327 | case mst_data: | |
328 | ms_type = 'D'; | |
329 | break; | |
330 | case mst_bss: | |
331 | ms_type = 'B'; | |
332 | break; | |
333 | case mst_abs: | |
334 | ms_type = 'A'; | |
335 | break; | |
336 | case mst_file_text: | |
337 | ms_type = 't'; | |
338 | break; | |
339 | case mst_file_data: | |
340 | ms_type = 'd'; | |
341 | break; | |
342 | case mst_file_bss: | |
343 | ms_type = 'b'; | |
344 | break; | |
345 | default: | |
346 | ms_type = '?'; | |
347 | break; | |
c906108c SS |
348 | } |
349 | fprintf_filtered (outfile, "[%2d] %c ", index, ms_type); | |
350 | print_address_numeric (SYMBOL_VALUE_ADDRESS (msymbol), 1, outfile); | |
22abf04a | 351 | fprintf_filtered (outfile, " %s", DEPRECATED_SYMBOL_NAME (msymbol)); |
c906108c SS |
352 | if (SYMBOL_BFD_SECTION (msymbol)) |
353 | fprintf_filtered (outfile, " section %s", | |
354 | bfd_section_name (objfile->obfd, | |
355 | SYMBOL_BFD_SECTION (msymbol))); | |
356 | if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL) | |
357 | { | |
358 | fprintf_filtered (outfile, " %s", SYMBOL_DEMANGLED_NAME (msymbol)); | |
359 | } | |
360 | #ifdef SOFUN_ADDRESS_MAYBE_MISSING | |
361 | if (msymbol->filename) | |
362 | fprintf_filtered (outfile, " %s", msymbol->filename); | |
363 | #endif | |
364 | fputs_filtered ("\n", outfile); | |
365 | } | |
c5aa993b | 366 | if (objfile->minimal_symbol_count != index) |
c906108c SS |
367 | { |
368 | warning ("internal error: minimal symbol count %d != %d", | |
c5aa993b | 369 | objfile->minimal_symbol_count, index); |
c906108c SS |
370 | } |
371 | fprintf_filtered (outfile, "\n"); | |
372 | } | |
373 | ||
374 | static void | |
fba45db2 KB |
375 | dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab, |
376 | struct ui_file *outfile) | |
c906108c SS |
377 | { |
378 | int i; | |
379 | ||
380 | fprintf_filtered (outfile, "\nPartial symtab for source file %s ", | |
c5aa993b | 381 | psymtab->filename); |
c906108c | 382 | fprintf_filtered (outfile, "(object "); |
d4f3574e | 383 | gdb_print_host_address (psymtab, outfile); |
c906108c SS |
384 | fprintf_filtered (outfile, ")\n\n"); |
385 | fprintf_unfiltered (outfile, " Read from object file %s (", | |
c5aa993b | 386 | objfile->name); |
d4f3574e | 387 | gdb_print_host_address (objfile, outfile); |
c906108c SS |
388 | fprintf_unfiltered (outfile, ")\n"); |
389 | ||
c5aa993b | 390 | if (psymtab->readin) |
c906108c SS |
391 | { |
392 | fprintf_filtered (outfile, | |
c5aa993b | 393 | " Full symtab was read (at "); |
d4f3574e | 394 | gdb_print_host_address (psymtab->symtab, outfile); |
c906108c | 395 | fprintf_filtered (outfile, " by function at "); |
4efb68b1 | 396 | gdb_print_host_address (psymtab->read_symtab, outfile); |
c906108c SS |
397 | fprintf_filtered (outfile, ")\n"); |
398 | } | |
399 | ||
400 | fprintf_filtered (outfile, " Relocate symbols by "); | |
401 | for (i = 0; i < psymtab->objfile->num_sections; ++i) | |
402 | { | |
403 | if (i != 0) | |
404 | fprintf_filtered (outfile, ", "); | |
405 | wrap_here (" "); | |
406 | print_address_numeric (ANOFFSET (psymtab->section_offsets, i), | |
407 | 1, | |
408 | outfile); | |
409 | } | |
410 | fprintf_filtered (outfile, "\n"); | |
411 | ||
412 | fprintf_filtered (outfile, " Symbols cover text addresses "); | |
413 | print_address_numeric (psymtab->textlow, 1, outfile); | |
414 | fprintf_filtered (outfile, "-"); | |
415 | print_address_numeric (psymtab->texthigh, 1, outfile); | |
416 | fprintf_filtered (outfile, "\n"); | |
417 | fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n", | |
c5aa993b JM |
418 | psymtab->number_of_dependencies); |
419 | for (i = 0; i < psymtab->number_of_dependencies; i++) | |
c906108c SS |
420 | { |
421 | fprintf_filtered (outfile, " %d ", i); | |
d4f3574e | 422 | gdb_print_host_address (psymtab->dependencies[i], outfile); |
c906108c | 423 | fprintf_filtered (outfile, " %s\n", |
c5aa993b | 424 | psymtab->dependencies[i]->filename); |
c906108c | 425 | } |
c5aa993b | 426 | if (psymtab->n_global_syms > 0) |
c906108c | 427 | { |
c5aa993b JM |
428 | print_partial_symbols (objfile->global_psymbols.list |
429 | + psymtab->globals_offset, | |
430 | psymtab->n_global_syms, "Global", outfile); | |
c906108c | 431 | } |
c5aa993b | 432 | if (psymtab->n_static_syms > 0) |
c906108c | 433 | { |
c5aa993b JM |
434 | print_partial_symbols (objfile->static_psymbols.list |
435 | + psymtab->statics_offset, | |
436 | psymtab->n_static_syms, "Static", outfile); | |
c906108c SS |
437 | } |
438 | fprintf_filtered (outfile, "\n"); | |
439 | } | |
440 | ||
c5aa993b | 441 | static void |
fba45db2 KB |
442 | dump_symtab (struct objfile *objfile, struct symtab *symtab, |
443 | struct ui_file *outfile) | |
c906108c | 444 | { |
de4f826b DC |
445 | int i; |
446 | struct dict_iterator iter; | |
c906108c | 447 | int len, blen; |
de4f826b | 448 | struct linetable *l; |
c906108c | 449 | struct blockvector *bv; |
e88c90f2 | 450 | struct symbol *sym; |
de4f826b | 451 | struct block *b; |
c906108c SS |
452 | int depth; |
453 | ||
454 | fprintf_filtered (outfile, "\nSymtab for file %s\n", symtab->filename); | |
455 | if (symtab->dirname) | |
456 | fprintf_filtered (outfile, "Compilation directory is %s\n", | |
457 | symtab->dirname); | |
458 | fprintf_filtered (outfile, "Read from object file %s (", objfile->name); | |
d4f3574e | 459 | gdb_print_host_address (objfile, outfile); |
c906108c SS |
460 | fprintf_filtered (outfile, ")\n"); |
461 | fprintf_filtered (outfile, "Language: %s\n", language_str (symtab->language)); | |
462 | ||
463 | /* First print the line table. */ | |
464 | l = LINETABLE (symtab); | |
465 | if (l) | |
466 | { | |
467 | fprintf_filtered (outfile, "\nLine table:\n\n"); | |
468 | len = l->nitems; | |
469 | for (i = 0; i < len; i++) | |
470 | { | |
471 | fprintf_filtered (outfile, " line %d at ", l->item[i].line); | |
472 | print_address_numeric (l->item[i].pc, 1, outfile); | |
473 | fprintf_filtered (outfile, "\n"); | |
474 | } | |
475 | } | |
476 | /* Now print the block info, but only for primary symtabs since we will | |
477 | print lots of duplicate info otherwise. */ | |
c5aa993b | 478 | if (symtab->primary) |
c906108c SS |
479 | { |
480 | fprintf_filtered (outfile, "\nBlockvector:\n\n"); | |
481 | bv = BLOCKVECTOR (symtab); | |
482 | len = BLOCKVECTOR_NBLOCKS (bv); | |
483 | for (i = 0; i < len; i++) | |
484 | { | |
485 | b = BLOCKVECTOR_BLOCK (bv, i); | |
486 | depth = block_depth (b) * 2; | |
487 | print_spaces (depth, outfile); | |
488 | fprintf_filtered (outfile, "block #%03d, object at ", i); | |
d4f3574e | 489 | gdb_print_host_address (b, outfile); |
c906108c SS |
490 | if (BLOCK_SUPERBLOCK (b)) |
491 | { | |
492 | fprintf_filtered (outfile, " under "); | |
d4f3574e | 493 | gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile); |
c906108c | 494 | } |
261397f8 DJ |
495 | /* drow/2002-07-10: We could save the total symbols count |
496 | even if we're using a hashtable, but nothing else but this message | |
497 | wants it. */ | |
de4f826b DC |
498 | fprintf_filtered (outfile, ", %d syms/buckets in ", |
499 | dict_size (BLOCK_DICT (b))); | |
c906108c SS |
500 | print_address_numeric (BLOCK_START (b), 1, outfile); |
501 | fprintf_filtered (outfile, ".."); | |
502 | print_address_numeric (BLOCK_END (b), 1, outfile); | |
503 | if (BLOCK_FUNCTION (b)) | |
504 | { | |
22abf04a | 505 | fprintf_filtered (outfile, ", function %s", DEPRECATED_SYMBOL_NAME (BLOCK_FUNCTION (b))); |
c906108c SS |
506 | if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL) |
507 | { | |
508 | fprintf_filtered (outfile, ", %s", | |
c5aa993b | 509 | SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b))); |
c906108c SS |
510 | } |
511 | } | |
c5aa993b JM |
512 | if (BLOCK_GCC_COMPILED (b)) |
513 | fprintf_filtered (outfile, ", compiled with gcc%d", BLOCK_GCC_COMPILED (b)); | |
c906108c | 514 | fprintf_filtered (outfile, "\n"); |
261397f8 DJ |
515 | /* Now print each symbol in this block (in no particular order, if |
516 | we're using a hashtable). */ | |
de4f826b | 517 | ALL_BLOCK_SYMBOLS (b, iter, sym) |
c906108c SS |
518 | { |
519 | struct print_symbol_args s; | |
e88c90f2 | 520 | s.symbol = sym; |
c906108c SS |
521 | s.depth = depth + 1; |
522 | s.outfile = outfile; | |
523 | catch_errors (print_symbol, &s, "Error printing symbol:\n", | |
524 | RETURN_MASK_ALL); | |
525 | } | |
526 | } | |
527 | fprintf_filtered (outfile, "\n"); | |
528 | } | |
529 | else | |
530 | { | |
531 | fprintf_filtered (outfile, "\nBlockvector same as previous symtab\n\n"); | |
532 | } | |
533 | } | |
534 | ||
535 | void | |
fba45db2 | 536 | maintenance_print_symbols (char *args, int from_tty) |
c906108c SS |
537 | { |
538 | char **argv; | |
d9fcf2fb | 539 | struct ui_file *outfile; |
c906108c SS |
540 | struct cleanup *cleanups; |
541 | char *symname = NULL; | |
542 | char *filename = DEV_TTY; | |
543 | struct objfile *objfile; | |
544 | struct symtab *s; | |
545 | ||
546 | dont_repeat (); | |
547 | ||
548 | if (args == NULL) | |
549 | { | |
550 | error ("\ | |
551 | Arguments missing: an output file name and an optional symbol file name"); | |
552 | } | |
553 | else if ((argv = buildargv (args)) == NULL) | |
554 | { | |
555 | nomem (0); | |
556 | } | |
7a292a7a | 557 | cleanups = make_cleanup_freeargv (argv); |
c906108c SS |
558 | |
559 | if (argv[0] != NULL) | |
560 | { | |
561 | filename = argv[0]; | |
562 | /* If a second arg is supplied, it is a source file name to match on */ | |
563 | if (argv[1] != NULL) | |
564 | { | |
565 | symname = argv[1]; | |
566 | } | |
567 | } | |
568 | ||
569 | filename = tilde_expand (filename); | |
b8c9b27d | 570 | make_cleanup (xfree, filename); |
c5aa993b | 571 | |
c906108c SS |
572 | outfile = gdb_fopen (filename, FOPEN_WT); |
573 | if (outfile == 0) | |
574 | perror_with_name (filename); | |
d9fcf2fb | 575 | make_cleanup_ui_file_delete (outfile); |
c906108c SS |
576 | |
577 | immediate_quit++; | |
578 | ALL_SYMTABS (objfile, s) | |
6314a349 | 579 | if (symname == NULL || strcmp (symname, s->filename) == 0) |
c5aa993b | 580 | dump_symtab (objfile, s, outfile); |
c906108c SS |
581 | immediate_quit--; |
582 | do_cleanups (cleanups); | |
583 | } | |
584 | ||
585 | /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how | |
586 | far to indent. ARGS is really a struct print_symbol_args *, but is | |
587 | declared as char * to get it past catch_errors. Returns 0 for error, | |
588 | 1 for success. */ | |
589 | ||
590 | static int | |
4efb68b1 | 591 | print_symbol (void *args) |
c906108c | 592 | { |
c5aa993b JM |
593 | struct symbol *symbol = ((struct print_symbol_args *) args)->symbol; |
594 | int depth = ((struct print_symbol_args *) args)->depth; | |
d9fcf2fb | 595 | struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile; |
c906108c SS |
596 | |
597 | print_spaces (depth, outfile); | |
176620f1 | 598 | if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN) |
c906108c | 599 | { |
de5ad195 | 600 | fprintf_filtered (outfile, "label %s at ", SYMBOL_PRINT_NAME (symbol)); |
c906108c SS |
601 | print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile); |
602 | if (SYMBOL_BFD_SECTION (symbol)) | |
603 | fprintf_filtered (outfile, " section %s\n", | |
c5aa993b JM |
604 | bfd_section_name (SYMBOL_BFD_SECTION (symbol)->owner, |
605 | SYMBOL_BFD_SECTION (symbol))); | |
c906108c SS |
606 | else |
607 | fprintf_filtered (outfile, "\n"); | |
608 | return 1; | |
609 | } | |
176620f1 | 610 | if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN) |
c906108c SS |
611 | { |
612 | if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol))) | |
613 | { | |
614 | LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth); | |
615 | } | |
616 | else | |
617 | { | |
618 | fprintf_filtered (outfile, "%s %s = ", | |
c5aa993b JM |
619 | (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM |
620 | ? "enum" | |
621 | : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT | |
622 | ? "struct" : "union")), | |
22abf04a | 623 | DEPRECATED_SYMBOL_NAME (symbol)); |
c906108c SS |
624 | LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth); |
625 | } | |
626 | fprintf_filtered (outfile, ";\n"); | |
627 | } | |
628 | else | |
629 | { | |
630 | if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF) | |
631 | fprintf_filtered (outfile, "typedef "); | |
632 | if (SYMBOL_TYPE (symbol)) | |
633 | { | |
634 | /* Print details of types, except for enums where it's clutter. */ | |
de5ad195 | 635 | LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_PRINT_NAME (symbol), |
c906108c SS |
636 | outfile, |
637 | TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM, | |
638 | depth); | |
639 | fprintf_filtered (outfile, "; "); | |
640 | } | |
641 | else | |
de5ad195 | 642 | fprintf_filtered (outfile, "%s ", SYMBOL_PRINT_NAME (symbol)); |
c906108c SS |
643 | |
644 | switch (SYMBOL_CLASS (symbol)) | |
645 | { | |
646 | case LOC_CONST: | |
647 | fprintf_filtered (outfile, "const %ld (0x%lx)", | |
648 | SYMBOL_VALUE (symbol), | |
649 | SYMBOL_VALUE (symbol)); | |
650 | break; | |
651 | ||
652 | case LOC_CONST_BYTES: | |
653 | { | |
654 | unsigned i; | |
655 | struct type *type = check_typedef (SYMBOL_TYPE (symbol)); | |
656 | fprintf_filtered (outfile, "const %u hex bytes:", | |
657 | TYPE_LENGTH (type)); | |
658 | for (i = 0; i < TYPE_LENGTH (type); i++) | |
659 | fprintf_filtered (outfile, " %02x", | |
c5aa993b | 660 | (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]); |
c906108c SS |
661 | } |
662 | break; | |
663 | ||
664 | case LOC_STATIC: | |
665 | fprintf_filtered (outfile, "static at "); | |
c5aa993b | 666 | print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile); |
c906108c SS |
667 | if (SYMBOL_BFD_SECTION (symbol)) |
668 | fprintf_filtered (outfile, " section %s", | |
669 | bfd_section_name | |
670 | (SYMBOL_BFD_SECTION (symbol)->owner, | |
671 | SYMBOL_BFD_SECTION (symbol))); | |
672 | break; | |
673 | ||
674 | case LOC_INDIRECT: | |
675 | fprintf_filtered (outfile, "extern global at *("); | |
c5aa993b | 676 | print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile); |
c906108c SS |
677 | fprintf_filtered (outfile, "),"); |
678 | break; | |
679 | ||
680 | case LOC_REGISTER: | |
681 | fprintf_filtered (outfile, "register %ld", SYMBOL_VALUE (symbol)); | |
682 | break; | |
683 | ||
684 | case LOC_ARG: | |
685 | fprintf_filtered (outfile, "arg at offset 0x%lx", | |
686 | SYMBOL_VALUE (symbol)); | |
687 | break; | |
688 | ||
689 | case LOC_LOCAL_ARG: | |
690 | fprintf_filtered (outfile, "arg at offset 0x%lx from fp", | |
c5aa993b | 691 | SYMBOL_VALUE (symbol)); |
c906108c SS |
692 | break; |
693 | ||
694 | case LOC_REF_ARG: | |
695 | fprintf_filtered (outfile, "reference arg at 0x%lx", SYMBOL_VALUE (symbol)); | |
696 | break; | |
697 | ||
698 | case LOC_REGPARM: | |
699 | fprintf_filtered (outfile, "parameter register %ld", SYMBOL_VALUE (symbol)); | |
700 | break; | |
701 | ||
702 | case LOC_REGPARM_ADDR: | |
703 | fprintf_filtered (outfile, "address parameter register %ld", SYMBOL_VALUE (symbol)); | |
704 | break; | |
705 | ||
706 | case LOC_LOCAL: | |
707 | fprintf_filtered (outfile, "local at offset 0x%lx", | |
708 | SYMBOL_VALUE (symbol)); | |
709 | break; | |
710 | ||
711 | case LOC_BASEREG: | |
712 | fprintf_filtered (outfile, "local at 0x%lx from register %d", | |
c5aa993b | 713 | SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol)); |
c906108c SS |
714 | break; |
715 | ||
716 | case LOC_BASEREG_ARG: | |
717 | fprintf_filtered (outfile, "arg at 0x%lx from register %d", | |
c5aa993b | 718 | SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol)); |
c906108c SS |
719 | break; |
720 | ||
721 | case LOC_TYPEDEF: | |
722 | break; | |
723 | ||
724 | case LOC_LABEL: | |
725 | fprintf_filtered (outfile, "label at "); | |
726 | print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile); | |
727 | if (SYMBOL_BFD_SECTION (symbol)) | |
728 | fprintf_filtered (outfile, " section %s", | |
729 | bfd_section_name | |
730 | (SYMBOL_BFD_SECTION (symbol)->owner, | |
731 | SYMBOL_BFD_SECTION (symbol))); | |
732 | break; | |
733 | ||
734 | case LOC_BLOCK: | |
735 | fprintf_filtered (outfile, "block object "); | |
d4f3574e | 736 | gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile); |
c906108c SS |
737 | fprintf_filtered (outfile, ", "); |
738 | print_address_numeric (BLOCK_START (SYMBOL_BLOCK_VALUE (symbol)), | |
739 | 1, | |
740 | outfile); | |
741 | fprintf_filtered (outfile, ".."); | |
742 | print_address_numeric (BLOCK_END (SYMBOL_BLOCK_VALUE (symbol)), | |
743 | 1, | |
744 | outfile); | |
745 | if (SYMBOL_BFD_SECTION (symbol)) | |
746 | fprintf_filtered (outfile, " section %s", | |
747 | bfd_section_name | |
748 | (SYMBOL_BFD_SECTION (symbol)->owner, | |
749 | SYMBOL_BFD_SECTION (symbol))); | |
750 | break; | |
751 | ||
4c2df51b DJ |
752 | case LOC_COMPUTED: |
753 | case LOC_COMPUTED_ARG: | |
754 | fprintf_filtered (outfile, "computed at runtime"); | |
755 | break; | |
756 | ||
c906108c SS |
757 | case LOC_UNRESOLVED: |
758 | fprintf_filtered (outfile, "unresolved"); | |
759 | break; | |
760 | ||
761 | case LOC_OPTIMIZED_OUT: | |
762 | fprintf_filtered (outfile, "optimized out"); | |
763 | break; | |
764 | ||
c5aa993b | 765 | default: |
c906108c SS |
766 | fprintf_filtered (outfile, "botched symbol class %x", |
767 | SYMBOL_CLASS (symbol)); | |
768 | break; | |
769 | } | |
770 | } | |
771 | fprintf_filtered (outfile, "\n"); | |
772 | return 1; | |
773 | } | |
774 | ||
775 | void | |
fba45db2 | 776 | maintenance_print_psymbols (char *args, int from_tty) |
c906108c SS |
777 | { |
778 | char **argv; | |
d9fcf2fb | 779 | struct ui_file *outfile; |
c906108c SS |
780 | struct cleanup *cleanups; |
781 | char *symname = NULL; | |
782 | char *filename = DEV_TTY; | |
783 | struct objfile *objfile; | |
784 | struct partial_symtab *ps; | |
785 | ||
786 | dont_repeat (); | |
787 | ||
788 | if (args == NULL) | |
789 | { | |
790 | error ("print-psymbols takes an output file name and optional symbol file name"); | |
791 | } | |
792 | else if ((argv = buildargv (args)) == NULL) | |
793 | { | |
794 | nomem (0); | |
795 | } | |
7a292a7a | 796 | cleanups = make_cleanup_freeargv (argv); |
c906108c SS |
797 | |
798 | if (argv[0] != NULL) | |
799 | { | |
800 | filename = argv[0]; | |
801 | /* If a second arg is supplied, it is a source file name to match on */ | |
802 | if (argv[1] != NULL) | |
803 | { | |
804 | symname = argv[1]; | |
805 | } | |
806 | } | |
807 | ||
808 | filename = tilde_expand (filename); | |
b8c9b27d | 809 | make_cleanup (xfree, filename); |
c5aa993b | 810 | |
c906108c SS |
811 | outfile = gdb_fopen (filename, FOPEN_WT); |
812 | if (outfile == 0) | |
813 | perror_with_name (filename); | |
d9fcf2fb | 814 | make_cleanup_ui_file_delete (outfile); |
c906108c SS |
815 | |
816 | immediate_quit++; | |
817 | ALL_PSYMTABS (objfile, ps) | |
6314a349 | 818 | if (symname == NULL || strcmp (symname, ps->filename) == 0) |
c5aa993b | 819 | dump_psymtab (objfile, ps, outfile); |
c906108c SS |
820 | immediate_quit--; |
821 | do_cleanups (cleanups); | |
822 | } | |
823 | ||
824 | static void | |
fba45db2 KB |
825 | print_partial_symbols (struct partial_symbol **p, int count, char *what, |
826 | struct ui_file *outfile) | |
c906108c SS |
827 | { |
828 | fprintf_filtered (outfile, " %s partial symbols:\n", what); | |
829 | while (count-- > 0) | |
830 | { | |
22abf04a | 831 | fprintf_filtered (outfile, " `%s'", DEPRECATED_SYMBOL_NAME (*p)); |
c906108c SS |
832 | if (SYMBOL_DEMANGLED_NAME (*p) != NULL) |
833 | { | |
834 | fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p)); | |
835 | } | |
836 | fputs_filtered (", ", outfile); | |
176620f1 | 837 | switch (SYMBOL_DOMAIN (*p)) |
c906108c | 838 | { |
176620f1 EZ |
839 | case UNDEF_DOMAIN: |
840 | fputs_filtered ("undefined domain, ", outfile); | |
c906108c | 841 | break; |
176620f1 | 842 | case VAR_DOMAIN: |
c906108c SS |
843 | /* This is the usual thing -- don't print it */ |
844 | break; | |
176620f1 EZ |
845 | case STRUCT_DOMAIN: |
846 | fputs_filtered ("struct domain, ", outfile); | |
c906108c | 847 | break; |
176620f1 EZ |
848 | case LABEL_DOMAIN: |
849 | fputs_filtered ("label domain, ", outfile); | |
c906108c SS |
850 | break; |
851 | default: | |
176620f1 | 852 | fputs_filtered ("<invalid domain>, ", outfile); |
c906108c SS |
853 | break; |
854 | } | |
855 | switch (SYMBOL_CLASS (*p)) | |
856 | { | |
857 | case LOC_UNDEF: | |
858 | fputs_filtered ("undefined", outfile); | |
859 | break; | |
860 | case LOC_CONST: | |
861 | fputs_filtered ("constant int", outfile); | |
862 | break; | |
863 | case LOC_STATIC: | |
864 | fputs_filtered ("static", outfile); | |
865 | break; | |
866 | case LOC_INDIRECT: | |
867 | fputs_filtered ("extern global", outfile); | |
868 | break; | |
869 | case LOC_REGISTER: | |
870 | fputs_filtered ("register", outfile); | |
871 | break; | |
872 | case LOC_ARG: | |
873 | fputs_filtered ("pass by value", outfile); | |
874 | break; | |
875 | case LOC_REF_ARG: | |
876 | fputs_filtered ("pass by reference", outfile); | |
877 | break; | |
878 | case LOC_REGPARM: | |
879 | fputs_filtered ("register parameter", outfile); | |
880 | break; | |
881 | case LOC_REGPARM_ADDR: | |
882 | fputs_filtered ("register address parameter", outfile); | |
883 | break; | |
884 | case LOC_LOCAL: | |
885 | fputs_filtered ("stack parameter", outfile); | |
886 | break; | |
887 | case LOC_TYPEDEF: | |
888 | fputs_filtered ("type", outfile); | |
889 | break; | |
890 | case LOC_LABEL: | |
891 | fputs_filtered ("label", outfile); | |
892 | break; | |
893 | case LOC_BLOCK: | |
894 | fputs_filtered ("function", outfile); | |
895 | break; | |
896 | case LOC_CONST_BYTES: | |
897 | fputs_filtered ("constant bytes", outfile); | |
898 | break; | |
899 | case LOC_LOCAL_ARG: | |
900 | fputs_filtered ("shuffled arg", outfile); | |
901 | break; | |
902 | case LOC_UNRESOLVED: | |
903 | fputs_filtered ("unresolved", outfile); | |
904 | break; | |
905 | case LOC_OPTIMIZED_OUT: | |
906 | fputs_filtered ("optimized out", outfile); | |
907 | break; | |
4c2df51b DJ |
908 | case LOC_COMPUTED: |
909 | case LOC_COMPUTED_ARG: | |
910 | fputs_filtered ("computed at runtime", outfile); | |
911 | break; | |
c906108c SS |
912 | default: |
913 | fputs_filtered ("<invalid location>", outfile); | |
914 | break; | |
915 | } | |
916 | fputs_filtered (", ", outfile); | |
917 | print_address_numeric (SYMBOL_VALUE_ADDRESS (*p), 1, outfile); | |
918 | fprintf_filtered (outfile, "\n"); | |
919 | p++; | |
920 | } | |
921 | } | |
922 | ||
923 | void | |
fba45db2 | 924 | maintenance_print_msymbols (char *args, int from_tty) |
c906108c SS |
925 | { |
926 | char **argv; | |
d9fcf2fb | 927 | struct ui_file *outfile; |
c906108c SS |
928 | struct cleanup *cleanups; |
929 | char *filename = DEV_TTY; | |
930 | char *symname = NULL; | |
931 | struct objfile *objfile; | |
932 | ||
933 | dont_repeat (); | |
934 | ||
935 | if (args == NULL) | |
936 | { | |
937 | error ("print-msymbols takes an output file name and optional symbol file name"); | |
938 | } | |
939 | else if ((argv = buildargv (args)) == NULL) | |
940 | { | |
941 | nomem (0); | |
942 | } | |
7a292a7a | 943 | cleanups = make_cleanup_freeargv (argv); |
c906108c SS |
944 | |
945 | if (argv[0] != NULL) | |
946 | { | |
947 | filename = argv[0]; | |
948 | /* If a second arg is supplied, it is a source file name to match on */ | |
949 | if (argv[1] != NULL) | |
950 | { | |
951 | symname = argv[1]; | |
952 | } | |
953 | } | |
954 | ||
955 | filename = tilde_expand (filename); | |
b8c9b27d | 956 | make_cleanup (xfree, filename); |
c5aa993b | 957 | |
c906108c SS |
958 | outfile = gdb_fopen (filename, FOPEN_WT); |
959 | if (outfile == 0) | |
960 | perror_with_name (filename); | |
d9fcf2fb | 961 | make_cleanup_ui_file_delete (outfile); |
c906108c SS |
962 | |
963 | immediate_quit++; | |
964 | ALL_OBJFILES (objfile) | |
6314a349 | 965 | if (symname == NULL || strcmp (symname, objfile->name) == 0) |
c5aa993b | 966 | dump_msymbols (objfile, outfile); |
c906108c SS |
967 | immediate_quit--; |
968 | fprintf_filtered (outfile, "\n\n"); | |
969 | do_cleanups (cleanups); | |
970 | } | |
971 | ||
972 | void | |
fba45db2 | 973 | maintenance_print_objfiles (char *ignore, int from_tty) |
c906108c SS |
974 | { |
975 | struct objfile *objfile; | |
976 | ||
977 | dont_repeat (); | |
978 | ||
979 | immediate_quit++; | |
980 | ALL_OBJFILES (objfile) | |
981 | dump_objfile (objfile); | |
982 | immediate_quit--; | |
983 | } | |
984 | ||
44ea7b70 | 985 | |
5e7b2f39 | 986 | /* List all the symbol tables whose names match REGEXP (optional). */ |
44ea7b70 | 987 | void |
5e7b2f39 | 988 | maintenance_info_symtabs (char *regexp, int from_tty) |
44ea7b70 JB |
989 | { |
990 | struct objfile *objfile; | |
991 | ||
992 | if (regexp) | |
993 | re_comp (regexp); | |
994 | ||
995 | ALL_OBJFILES (objfile) | |
996 | { | |
997 | struct symtab *symtab; | |
998 | ||
999 | /* We don't want to print anything for this objfile until we | |
1000 | actually find a symtab whose name matches. */ | |
1001 | int printed_objfile_start = 0; | |
1002 | ||
1003 | ALL_OBJFILE_SYMTABS (objfile, symtab) | |
1004 | if (! regexp | |
1005 | || re_exec (symtab->filename)) | |
1006 | { | |
1007 | if (! printed_objfile_start) | |
1008 | { | |
1009 | printf_filtered ("{ objfile %s ", objfile->name); | |
1010 | wrap_here (" "); | |
1011 | printf_filtered ("((struct objfile *) %p)\n", objfile); | |
1012 | printed_objfile_start = 1; | |
1013 | } | |
1014 | ||
1015 | printf_filtered (" { symtab %s ", symtab->filename); | |
1016 | wrap_here (" "); | |
1017 | printf_filtered ("((struct symtab *) %p)\n", symtab); | |
1018 | printf_filtered (" dirname %s\n", | |
1019 | symtab->dirname ? symtab->dirname : "(null)"); | |
1020 | printf_filtered (" fullname %s\n", | |
1021 | symtab->fullname ? symtab->fullname : "(null)"); | |
1022 | printf_filtered (" blockvector ((struct blockvector *) %p)%s\n", | |
1023 | symtab->blockvector, | |
1024 | symtab->primary ? " (primary)" : ""); | |
1025 | printf_filtered (" debugformat %s\n", symtab->debugformat); | |
1026 | printf_filtered (" }\n"); | |
1027 | } | |
1028 | ||
1029 | if (printed_objfile_start) | |
1030 | printf_filtered ("}\n"); | |
1031 | } | |
1032 | } | |
1033 | ||
1034 | ||
5e7b2f39 | 1035 | /* List all the partial symbol tables whose names match REGEXP (optional). */ |
44ea7b70 | 1036 | void |
5e7b2f39 | 1037 | maintenance_info_psymtabs (char *regexp, int from_tty) |
44ea7b70 JB |
1038 | { |
1039 | struct objfile *objfile; | |
1040 | ||
1041 | if (regexp) | |
1042 | re_comp (regexp); | |
1043 | ||
1044 | ALL_OBJFILES (objfile) | |
1045 | { | |
1046 | struct partial_symtab *psymtab; | |
1047 | ||
1048 | /* We don't want to print anything for this objfile until we | |
1049 | actually find a symtab whose name matches. */ | |
1050 | int printed_objfile_start = 0; | |
1051 | ||
1052 | ALL_OBJFILE_PSYMTABS (objfile, psymtab) | |
1053 | if (! regexp | |
1054 | || re_exec (psymtab->filename)) | |
1055 | { | |
1056 | if (! printed_objfile_start) | |
1057 | { | |
1058 | printf_filtered ("{ objfile %s ", objfile->name); | |
1059 | wrap_here (" "); | |
1060 | printf_filtered ("((struct objfile *) %p)\n", objfile); | |
1061 | printed_objfile_start = 1; | |
1062 | } | |
1063 | ||
1064 | printf_filtered (" { psymtab %s ", psymtab->filename); | |
1065 | wrap_here (" "); | |
1066 | printf_filtered ("((struct partial_symtab *) %p)\n", psymtab); | |
1067 | printf_filtered (" readin %s\n", | |
1068 | psymtab->readin ? "yes" : "no"); | |
1069 | printf_filtered (" fullname %s\n", | |
1070 | psymtab->fullname ? psymtab->fullname : "(null)"); | |
1071 | printf_filtered (" text addresses "); | |
1072 | print_address_numeric (psymtab->textlow, 1, gdb_stdout); | |
1073 | printf_filtered (" -- "); | |
1074 | print_address_numeric (psymtab->texthigh, 1, gdb_stdout); | |
1075 | printf_filtered ("\n"); | |
1076 | printf_filtered (" globals "); | |
1077 | if (psymtab->n_global_syms) | |
1078 | { | |
1079 | printf_filtered ("(* (struct partial_symbol **) %p @ %d)\n", | |
1080 | (psymtab->objfile->global_psymbols.list | |
1081 | + psymtab->globals_offset), | |
1082 | psymtab->n_global_syms); | |
1083 | } | |
1084 | else | |
1085 | printf_filtered ("(none)\n"); | |
1086 | printf_filtered (" statics "); | |
1087 | if (psymtab->n_static_syms) | |
1088 | { | |
1089 | printf_filtered ("(* (struct partial_symbol **) %p @ %d)\n", | |
1090 | (psymtab->objfile->static_psymbols.list | |
1091 | + psymtab->statics_offset), | |
1092 | psymtab->n_static_syms); | |
1093 | } | |
1094 | else | |
1095 | printf_filtered ("(none)\n"); | |
1096 | printf_filtered (" dependencies "); | |
1097 | if (psymtab->number_of_dependencies) | |
1098 | { | |
1099 | int i; | |
1100 | ||
1101 | printf_filtered ("{\n"); | |
1102 | for (i = 0; i < psymtab->number_of_dependencies; i++) | |
1103 | { | |
1104 | struct partial_symtab *dep = psymtab->dependencies[i]; | |
1105 | ||
1106 | /* Note the string concatenation there --- no comma. */ | |
1107 | printf_filtered (" psymtab %s " | |
1108 | "((struct partial_symtab *) %p)\n", | |
1109 | dep->filename, dep); | |
1110 | } | |
1111 | printf_filtered (" }\n"); | |
1112 | } | |
1113 | else | |
1114 | printf_filtered ("(none)\n"); | |
1115 | printf_filtered (" }\n"); | |
1116 | } | |
1117 | ||
1118 | if (printed_objfile_start) | |
1119 | printf_filtered ("}\n"); | |
1120 | } | |
1121 | } | |
1122 | ||
1123 | ||
c906108c SS |
1124 | /* Check consistency of psymtabs and symtabs. */ |
1125 | ||
1126 | void | |
fba45db2 | 1127 | maintenance_check_symtabs (char *ignore, int from_tty) |
c906108c | 1128 | { |
52f0bd74 AC |
1129 | struct symbol *sym; |
1130 | struct partial_symbol **psym; | |
1131 | struct symtab *s = NULL; | |
1132 | struct partial_symtab *ps; | |
c906108c | 1133 | struct blockvector *bv; |
52f0bd74 AC |
1134 | struct objfile *objfile; |
1135 | struct block *b; | |
c906108c SS |
1136 | int length; |
1137 | ||
1138 | ALL_PSYMTABS (objfile, ps) | |
c5aa993b JM |
1139 | { |
1140 | s = PSYMTAB_TO_SYMTAB (ps); | |
1141 | if (s == NULL) | |
1142 | continue; | |
1143 | bv = BLOCKVECTOR (s); | |
1144 | b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
1145 | psym = ps->objfile->static_psymbols.list + ps->statics_offset; | |
1146 | length = ps->n_static_syms; | |
1147 | while (length--) | |
1148 | { | |
22abf04a | 1149 | sym = lookup_block_symbol (b, DEPRECATED_SYMBOL_NAME (*psym), |
176620f1 | 1150 | NULL, SYMBOL_DOMAIN (*psym)); |
c5aa993b JM |
1151 | if (!sym) |
1152 | { | |
1153 | printf_filtered ("Static symbol `"); | |
22abf04a | 1154 | puts_filtered (DEPRECATED_SYMBOL_NAME (*psym)); |
c5aa993b JM |
1155 | printf_filtered ("' only found in "); |
1156 | puts_filtered (ps->filename); | |
1157 | printf_filtered (" psymtab\n"); | |
1158 | } | |
1159 | psym++; | |
1160 | } | |
1161 | b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
1162 | psym = ps->objfile->global_psymbols.list + ps->globals_offset; | |
1163 | length = ps->n_global_syms; | |
1164 | while (length--) | |
1165 | { | |
22abf04a | 1166 | sym = lookup_block_symbol (b, DEPRECATED_SYMBOL_NAME (*psym), |
176620f1 | 1167 | NULL, SYMBOL_DOMAIN (*psym)); |
c5aa993b JM |
1168 | if (!sym) |
1169 | { | |
1170 | printf_filtered ("Global symbol `"); | |
22abf04a | 1171 | puts_filtered (DEPRECATED_SYMBOL_NAME (*psym)); |
c5aa993b JM |
1172 | printf_filtered ("' only found in "); |
1173 | puts_filtered (ps->filename); | |
1174 | printf_filtered (" psymtab\n"); | |
1175 | } | |
1176 | psym++; | |
1177 | } | |
1178 | if (ps->texthigh < ps->textlow) | |
1179 | { | |
1180 | printf_filtered ("Psymtab "); | |
1181 | puts_filtered (ps->filename); | |
1182 | printf_filtered (" covers bad range "); | |
1183 | print_address_numeric (ps->textlow, 1, gdb_stdout); | |
1184 | printf_filtered (" - "); | |
1185 | print_address_numeric (ps->texthigh, 1, gdb_stdout); | |
1186 | printf_filtered ("\n"); | |
c906108c | 1187 | continue; |
c5aa993b JM |
1188 | } |
1189 | if (ps->texthigh == 0) | |
1190 | continue; | |
1191 | if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b)) | |
1192 | { | |
1193 | printf_filtered ("Psymtab "); | |
1194 | puts_filtered (ps->filename); | |
1195 | printf_filtered (" covers "); | |
1196 | print_address_numeric (ps->textlow, 1, gdb_stdout); | |
1197 | printf_filtered (" - "); | |
1198 | print_address_numeric (ps->texthigh, 1, gdb_stdout); | |
1199 | printf_filtered (" but symtab covers only "); | |
1200 | print_address_numeric (BLOCK_START (b), 1, gdb_stdout); | |
1201 | printf_filtered (" - "); | |
1202 | print_address_numeric (BLOCK_END (b), 1, gdb_stdout); | |
1203 | printf_filtered ("\n"); | |
1204 | } | |
1205 | } | |
c906108c | 1206 | } |
c906108c | 1207 | \f |
c5aa993b | 1208 | |
c906108c SS |
1209 | /* Return the nexting depth of a block within other blocks in its symtab. */ |
1210 | ||
1211 | static int | |
fba45db2 | 1212 | block_depth (struct block *block) |
c906108c | 1213 | { |
52f0bd74 | 1214 | int i = 0; |
c5aa993b | 1215 | while ((block = BLOCK_SUPERBLOCK (block)) != NULL) |
c906108c SS |
1216 | { |
1217 | i++; | |
1218 | } | |
1219 | return i; | |
1220 | } | |
c906108c | 1221 | \f |
c5aa993b | 1222 | |
c906108c SS |
1223 | /* Increase the space allocated for LISTP, which is probably |
1224 | global_psymbols or static_psymbols. This space will eventually | |
1225 | be freed in free_objfile(). */ | |
1226 | ||
1227 | void | |
aa1ee363 | 1228 | extend_psymbol_list (struct psymbol_allocation_list *listp, |
fba45db2 | 1229 | struct objfile *objfile) |
c906108c SS |
1230 | { |
1231 | int new_size; | |
1232 | if (listp->size == 0) | |
1233 | { | |
1234 | new_size = 255; | |
1235 | listp->list = (struct partial_symbol **) | |
7936743b | 1236 | xmalloc (new_size * sizeof (struct partial_symbol *)); |
c906108c SS |
1237 | } |
1238 | else | |
1239 | { | |
1240 | new_size = listp->size * 2; | |
1241 | listp->list = (struct partial_symbol **) | |
0efffb96 AC |
1242 | xrealloc ((char *) listp->list, |
1243 | new_size * sizeof (struct partial_symbol *)); | |
c906108c SS |
1244 | } |
1245 | /* Next assumes we only went one over. Should be good if | |
1246 | program works correctly */ | |
1247 | listp->next = listp->list + listp->size; | |
1248 | listp->size = new_size; | |
1249 | } | |
1250 | ||
1251 | ||
1252 | /* Do early runtime initializations. */ | |
1253 | void | |
fba45db2 | 1254 | _initialize_symmisc (void) |
c906108c | 1255 | { |
c5aa993b | 1256 | std_in = stdin; |
c906108c SS |
1257 | std_out = stdout; |
1258 | std_err = stderr; | |
1259 | } |