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