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