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