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