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