]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Do various things to symbol tables (other than lookup), for GDB. |
af5f3db6 | 2 | |
0b302171 JB |
3 | Copyright (C) 1986-2000, 2002-2004, 2007-2012 Free Software |
4 | Foundation, Inc. | |
c906108c | 5 | |
c5aa993b | 6 | This file is part of GDB. |
c906108c | 7 | |
c5aa993b JM |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 11 | (at your option) any later version. |
c906108c | 12 | |
c5aa993b JM |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
c906108c | 17 | |
c5aa993b | 18 | You should have received a copy of the GNU General Public License |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
20 | |
21 | #include "defs.h" | |
22 | #include "symtab.h" | |
23 | #include "gdbtypes.h" | |
24 | #include "bfd.h" | |
0ba1096a | 25 | #include "filenames.h" |
c906108c SS |
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" |
79d43c61 | 38 | #include "typeprint.h" |
c906108c SS |
39 | |
40 | #include "gdb_string.h" | |
dbda9972 | 41 | #include "readline/readline.h" |
c906108c | 42 | |
ccefe4c4 TT |
43 | #include "psymtab.h" |
44 | ||
c906108c SS |
45 | #ifndef DEV_TTY |
46 | #define DEV_TTY "/dev/tty" | |
47 | #endif | |
48 | ||
49 | /* Unfortunately for debugging, stderr is usually a macro. This is painful | |
50 | when calling functions that take FILE *'s from the debugger. | |
51 | So we make a variable which has the same value and which is accessible when | |
52 | debugging GDB with itself. Because stdin et al need not be constants, | |
53 | we initialize them in the _initialize_symmisc function at the bottom | |
54 | of the file. */ | |
55 | FILE *std_in; | |
56 | FILE *std_out; | |
57 | FILE *std_err; | |
58 | ||
59 | /* Prototypes for local functions */ | |
60 | ||
d9fcf2fb JM |
61 | static void dump_symtab (struct objfile *, struct 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 | |
a14ed312 | 70 | void _initialize_symmisc (void); |
c906108c | 71 | |
c5aa993b JM |
72 | struct print_symbol_args |
73 | { | |
5af949e3 | 74 | struct gdbarch *gdbarch; |
c5aa993b JM |
75 | struct symbol *symbol; |
76 | int depth; | |
d9fcf2fb | 77 | struct ui_file *outfile; |
c5aa993b | 78 | }; |
c906108c | 79 | |
4efb68b1 | 80 | static int print_symbol (void *); |
c906108c | 81 | \f |
c906108c | 82 | |
c906108c | 83 | void |
fba45db2 | 84 | print_symbol_bcache_statistics (void) |
c906108c | 85 | { |
6c95b8df | 86 | struct program_space *pspace; |
c906108c SS |
87 | struct objfile *objfile; |
88 | ||
6c95b8df PA |
89 | ALL_PSPACES (pspace) |
90 | ALL_PSPACE_OBJFILES (pspace, objfile) | |
c5aa993b | 91 | { |
27618ce4 | 92 | QUIT; |
a3f17187 | 93 | printf_filtered (_("Byte cache statistics for '%s':\n"), objfile->name); |
710e1a31 SW |
94 | print_bcache_statistics (psymbol_bcache_get_bcache (objfile->psymbol_cache), |
95 | "partial symbol cache"); | |
6532ff36 TT |
96 | print_bcache_statistics (objfile->per_bfd->macro_cache, |
97 | "preprocessor macro cache"); | |
706e3705 TT |
98 | print_bcache_statistics (objfile->per_bfd->filename_cache, |
99 | "file name cache"); | |
c5aa993b | 100 | } |
c906108c SS |
101 | } |
102 | ||
103 | void | |
fba45db2 | 104 | print_objfile_statistics (void) |
c906108c | 105 | { |
6c95b8df | 106 | struct program_space *pspace; |
c906108c | 107 | struct objfile *objfile; |
c4f90d87 | 108 | struct symtab *s; |
c4f90d87 | 109 | int i, linetables, blockvectors; |
c906108c | 110 | |
6c95b8df PA |
111 | ALL_PSPACES (pspace) |
112 | ALL_PSPACE_OBJFILES (pspace, objfile) | |
c5aa993b | 113 | { |
27618ce4 | 114 | QUIT; |
a3f17187 | 115 | printf_filtered (_("Statistics for '%s':\n"), objfile->name); |
c5aa993b | 116 | if (OBJSTAT (objfile, n_stabs) > 0) |
a3f17187 | 117 | printf_filtered (_(" Number of \"stab\" symbols read: %d\n"), |
c5aa993b JM |
118 | OBJSTAT (objfile, n_stabs)); |
119 | if (OBJSTAT (objfile, n_minsyms) > 0) | |
a3f17187 | 120 | printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"), |
c5aa993b JM |
121 | OBJSTAT (objfile, n_minsyms)); |
122 | if (OBJSTAT (objfile, n_psyms) > 0) | |
a3f17187 | 123 | printf_filtered (_(" Number of \"partial\" symbols read: %d\n"), |
c5aa993b JM |
124 | OBJSTAT (objfile, n_psyms)); |
125 | if (OBJSTAT (objfile, n_syms) > 0) | |
a3f17187 | 126 | printf_filtered (_(" Number of \"full\" symbols read: %d\n"), |
c5aa993b JM |
127 | OBJSTAT (objfile, n_syms)); |
128 | if (OBJSTAT (objfile, n_types) > 0) | |
a3f17187 | 129 | printf_filtered (_(" Number of \"types\" defined: %d\n"), |
c5aa993b | 130 | OBJSTAT (objfile, n_types)); |
ccefe4c4 TT |
131 | if (objfile->sf) |
132 | objfile->sf->qf->print_stats (objfile); | |
c4f90d87 JM |
133 | i = linetables = blockvectors = 0; |
134 | ALL_OBJFILE_SYMTABS (objfile, s) | |
135 | { | |
136 | i++; | |
137 | if (s->linetable != NULL) | |
138 | linetables++; | |
139 | if (s->primary == 1) | |
140 | blockvectors++; | |
141 | } | |
a3f17187 AC |
142 | printf_filtered (_(" Number of symbol tables: %d\n"), i); |
143 | printf_filtered (_(" Number of symbol tables with line tables: %d\n"), | |
c4f90d87 | 144 | linetables); |
a3f17187 | 145 | printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"), |
c4f90d87 JM |
146 | blockvectors); |
147 | ||
c5aa993b | 148 | if (OBJSTAT (objfile, sz_strtab) > 0) |
a3f17187 | 149 | printf_filtered (_(" Space used by a.out string tables: %d\n"), |
c5aa993b | 150 | OBJSTAT (objfile, sz_strtab)); |
a3f17187 | 151 | printf_filtered (_(" Total memory used for objfile obstack: %d\n"), |
4a146b47 | 152 | obstack_memory_used (&objfile->objfile_obstack)); |
706e3705 TT |
153 | printf_filtered (_(" Total memory used for BFD obstack: %d\n"), |
154 | obstack_memory_used (&objfile->per_bfd->storage_obstack)); | |
a3f17187 | 155 | printf_filtered (_(" Total memory used for psymbol cache: %d\n"), |
710e1a31 SW |
156 | bcache_memory_used (psymbol_bcache_get_bcache |
157 | (objfile->psymbol_cache))); | |
a3f17187 | 158 | printf_filtered (_(" Total memory used for macro cache: %d\n"), |
6532ff36 | 159 | bcache_memory_used (objfile->per_bfd->macro_cache)); |
10abe6bf | 160 | printf_filtered (_(" Total memory used for file name cache: %d\n"), |
706e3705 | 161 | bcache_memory_used (objfile->per_bfd->filename_cache)); |
c5aa993b | 162 | } |
c906108c SS |
163 | } |
164 | ||
c5aa993b | 165 | static void |
fba45db2 | 166 | dump_objfile (struct objfile *objfile) |
c906108c SS |
167 | { |
168 | struct symtab *symtab; | |
c906108c | 169 | |
c5aa993b | 170 | printf_filtered ("\nObject file %s: ", objfile->name); |
c906108c | 171 | printf_filtered ("Objfile at "); |
d4f3574e | 172 | gdb_print_host_address (objfile, gdb_stdout); |
c906108c | 173 | printf_filtered (", bfd at "); |
d4f3574e | 174 | gdb_print_host_address (objfile->obfd, gdb_stdout); |
c906108c SS |
175 | printf_filtered (", %d minsyms\n\n", |
176 | objfile->minimal_symbol_count); | |
177 | ||
ccefe4c4 TT |
178 | if (objfile->sf) |
179 | objfile->sf->qf->dump (objfile); | |
c906108c | 180 | |
c5aa993b | 181 | if (objfile->symtabs) |
c906108c SS |
182 | { |
183 | printf_filtered ("Symtabs:\n"); | |
c5aa993b | 184 | for (symtab = objfile->symtabs; |
c906108c SS |
185 | symtab != NULL; |
186 | symtab = symtab->next) | |
187 | { | |
c5aa993b | 188 | printf_filtered ("%s at ", symtab->filename); |
d4f3574e | 189 | gdb_print_host_address (symtab, gdb_stdout); |
c906108c | 190 | printf_filtered (", "); |
c5aa993b | 191 | if (symtab->objfile != objfile) |
c906108c SS |
192 | { |
193 | printf_filtered ("NOT ON CHAIN! "); | |
194 | } | |
195 | wrap_here (" "); | |
196 | } | |
197 | printf_filtered ("\n\n"); | |
198 | } | |
199 | } | |
200 | ||
201 | /* Print minimal symbols from this objfile. */ | |
c5aa993b JM |
202 | |
203 | static void | |
fba45db2 | 204 | dump_msymbols (struct objfile *objfile, struct ui_file *outfile) |
c906108c | 205 | { |
5af949e3 | 206 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
207 | struct minimal_symbol *msymbol; |
208 | int index; | |
209 | char ms_type; | |
c5aa993b JM |
210 | |
211 | fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile->name); | |
212 | if (objfile->minimal_symbol_count == 0) | |
c906108c SS |
213 | { |
214 | fprintf_filtered (outfile, "No minimal symbols found.\n"); | |
215 | return; | |
216 | } | |
3567439c DJ |
217 | index = 0; |
218 | ALL_OBJFILE_MSYMBOLS (objfile, msymbol) | |
c906108c | 219 | { |
714835d5 UW |
220 | struct obj_section *section = SYMBOL_OBJ_SECTION (msymbol); |
221 | ||
712f90be | 222 | switch (MSYMBOL_TYPE (msymbol)) |
c906108c | 223 | { |
c5aa993b JM |
224 | case mst_unknown: |
225 | ms_type = 'u'; | |
226 | break; | |
227 | case mst_text: | |
228 | ms_type = 'T'; | |
229 | break; | |
0875794a JK |
230 | case mst_text_gnu_ifunc: |
231 | ms_type = 'i'; | |
232 | break; | |
c5aa993b JM |
233 | case mst_solib_trampoline: |
234 | ms_type = 'S'; | |
235 | break; | |
236 | case mst_data: | |
237 | ms_type = 'D'; | |
238 | break; | |
239 | case mst_bss: | |
240 | ms_type = 'B'; | |
241 | break; | |
242 | case mst_abs: | |
243 | ms_type = 'A'; | |
244 | break; | |
245 | case mst_file_text: | |
246 | ms_type = 't'; | |
247 | break; | |
248 | case mst_file_data: | |
249 | ms_type = 'd'; | |
250 | break; | |
251 | case mst_file_bss: | |
252 | ms_type = 'b'; | |
253 | break; | |
254 | default: | |
255 | ms_type = '?'; | |
256 | break; | |
c906108c SS |
257 | } |
258 | fprintf_filtered (outfile, "[%2d] %c ", index, ms_type); | |
5af949e3 UW |
259 | fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (msymbol)), |
260 | outfile); | |
3567439c | 261 | fprintf_filtered (outfile, " %s", SYMBOL_LINKAGE_NAME (msymbol)); |
714835d5 | 262 | if (section) |
c906108c SS |
263 | fprintf_filtered (outfile, " section %s", |
264 | bfd_section_name (objfile->obfd, | |
714835d5 | 265 | section->the_bfd_section)); |
c906108c SS |
266 | if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL) |
267 | { | |
268 | fprintf_filtered (outfile, " %s", SYMBOL_DEMANGLED_NAME (msymbol)); | |
269 | } | |
c906108c SS |
270 | if (msymbol->filename) |
271 | fprintf_filtered (outfile, " %s", msymbol->filename); | |
c906108c | 272 | fputs_filtered ("\n", outfile); |
3567439c | 273 | index++; |
c906108c | 274 | } |
c5aa993b | 275 | if (objfile->minimal_symbol_count != index) |
c906108c | 276 | { |
8a3fe4f8 | 277 | warning (_("internal error: minimal symbol count %d != %d"), |
c5aa993b | 278 | objfile->minimal_symbol_count, index); |
c906108c SS |
279 | } |
280 | fprintf_filtered (outfile, "\n"); | |
281 | } | |
282 | ||
c5aa993b | 283 | static void |
44b164c5 JB |
284 | dump_symtab_1 (struct objfile *objfile, struct symtab *symtab, |
285 | struct ui_file *outfile) | |
c906108c | 286 | { |
5af949e3 | 287 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
de4f826b DC |
288 | int i; |
289 | struct dict_iterator iter; | |
952a6d41 | 290 | int len; |
de4f826b | 291 | struct linetable *l; |
c906108c | 292 | struct blockvector *bv; |
e88c90f2 | 293 | struct symbol *sym; |
de4f826b | 294 | struct block *b; |
c906108c SS |
295 | int depth; |
296 | ||
297 | fprintf_filtered (outfile, "\nSymtab for file %s\n", symtab->filename); | |
298 | if (symtab->dirname) | |
299 | fprintf_filtered (outfile, "Compilation directory is %s\n", | |
300 | symtab->dirname); | |
301 | fprintf_filtered (outfile, "Read from object file %s (", objfile->name); | |
d4f3574e | 302 | gdb_print_host_address (objfile, outfile); |
c906108c | 303 | fprintf_filtered (outfile, ")\n"); |
3e43a32a MS |
304 | fprintf_filtered (outfile, "Language: %s\n", |
305 | language_str (symtab->language)); | |
c906108c SS |
306 | |
307 | /* First print the line table. */ | |
308 | l = LINETABLE (symtab); | |
309 | if (l) | |
310 | { | |
311 | fprintf_filtered (outfile, "\nLine table:\n\n"); | |
312 | len = l->nitems; | |
313 | for (i = 0; i < len; i++) | |
314 | { | |
315 | fprintf_filtered (outfile, " line %d at ", l->item[i].line); | |
5af949e3 | 316 | fputs_filtered (paddress (gdbarch, l->item[i].pc), outfile); |
c906108c SS |
317 | fprintf_filtered (outfile, "\n"); |
318 | } | |
319 | } | |
320 | /* Now print the block info, but only for primary symtabs since we will | |
c378eb4e | 321 | print lots of duplicate info otherwise. */ |
c5aa993b | 322 | if (symtab->primary) |
c906108c SS |
323 | { |
324 | fprintf_filtered (outfile, "\nBlockvector:\n\n"); | |
325 | bv = BLOCKVECTOR (symtab); | |
326 | len = BLOCKVECTOR_NBLOCKS (bv); | |
327 | for (i = 0; i < len; i++) | |
328 | { | |
329 | b = BLOCKVECTOR_BLOCK (bv, i); | |
330 | depth = block_depth (b) * 2; | |
331 | print_spaces (depth, outfile); | |
332 | fprintf_filtered (outfile, "block #%03d, object at ", i); | |
d4f3574e | 333 | gdb_print_host_address (b, outfile); |
c906108c SS |
334 | if (BLOCK_SUPERBLOCK (b)) |
335 | { | |
336 | fprintf_filtered (outfile, " under "); | |
d4f3574e | 337 | gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile); |
c906108c | 338 | } |
261397f8 DJ |
339 | /* drow/2002-07-10: We could save the total symbols count |
340 | even if we're using a hashtable, but nothing else but this message | |
341 | wants it. */ | |
de4f826b DC |
342 | fprintf_filtered (outfile, ", %d syms/buckets in ", |
343 | dict_size (BLOCK_DICT (b))); | |
5af949e3 | 344 | fputs_filtered (paddress (gdbarch, BLOCK_START (b)), outfile); |
c906108c | 345 | fprintf_filtered (outfile, ".."); |
5af949e3 | 346 | fputs_filtered (paddress (gdbarch, BLOCK_END (b)), outfile); |
c906108c SS |
347 | if (BLOCK_FUNCTION (b)) |
348 | { | |
3567439c DJ |
349 | fprintf_filtered (outfile, ", function %s", |
350 | SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b))); | |
c906108c SS |
351 | if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL) |
352 | { | |
353 | fprintf_filtered (outfile, ", %s", | |
c5aa993b | 354 | SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b))); |
c906108c SS |
355 | } |
356 | } | |
c906108c | 357 | fprintf_filtered (outfile, "\n"); |
261397f8 | 358 | /* Now print each symbol in this block (in no particular order, if |
8157b174 TT |
359 | we're using a hashtable). Note that we only want this |
360 | block, not any blocks from included symtabs. */ | |
361 | ALL_DICT_SYMBOLS (BLOCK_DICT (b), iter, sym) | |
c906108c SS |
362 | { |
363 | struct print_symbol_args s; | |
433759f7 | 364 | |
5af949e3 | 365 | s.gdbarch = gdbarch; |
e88c90f2 | 366 | s.symbol = sym; |
c906108c SS |
367 | s.depth = depth + 1; |
368 | s.outfile = outfile; | |
369 | catch_errors (print_symbol, &s, "Error printing symbol:\n", | |
5c3ce3f7 | 370 | RETURN_MASK_ERROR); |
c906108c SS |
371 | } |
372 | } | |
373 | fprintf_filtered (outfile, "\n"); | |
374 | } | |
375 | else | |
376 | { | |
377 | fprintf_filtered (outfile, "\nBlockvector same as previous symtab\n\n"); | |
378 | } | |
379 | } | |
380 | ||
44b164c5 JB |
381 | static void |
382 | dump_symtab (struct objfile *objfile, struct symtab *symtab, | |
383 | struct ui_file *outfile) | |
384 | { | |
44b164c5 JB |
385 | /* Set the current language to the language of the symtab we're dumping |
386 | because certain routines used during dump_symtab() use the current | |
969107c5 EZ |
387 | language to print an image of the symbol. We'll restore it later. |
388 | But use only real languages, not placeholders. */ | |
389 | if (symtab->language != language_unknown | |
390 | && symtab->language != language_auto) | |
391 | { | |
392 | enum language saved_lang; | |
393 | ||
394 | saved_lang = set_language (symtab->language); | |
44b164c5 | 395 | |
969107c5 | 396 | dump_symtab_1 (objfile, symtab, outfile); |
44b164c5 | 397 | |
969107c5 EZ |
398 | set_language (saved_lang); |
399 | } | |
400 | else | |
401 | dump_symtab_1 (objfile, symtab, outfile); | |
44b164c5 JB |
402 | } |
403 | ||
c906108c | 404 | void |
fba45db2 | 405 | maintenance_print_symbols (char *args, int from_tty) |
c906108c SS |
406 | { |
407 | char **argv; | |
d9fcf2fb | 408 | struct ui_file *outfile; |
c906108c SS |
409 | struct cleanup *cleanups; |
410 | char *symname = NULL; | |
411 | char *filename = DEV_TTY; | |
412 | struct objfile *objfile; | |
413 | struct symtab *s; | |
414 | ||
415 | dont_repeat (); | |
416 | ||
417 | if (args == NULL) | |
418 | { | |
3e43a32a MS |
419 | error (_("Arguments missing: an output file name " |
420 | "and an optional symbol file name")); | |
c906108c | 421 | } |
d1a41061 | 422 | argv = gdb_buildargv (args); |
7a292a7a | 423 | cleanups = make_cleanup_freeargv (argv); |
c906108c SS |
424 | |
425 | if (argv[0] != NULL) | |
426 | { | |
427 | filename = argv[0]; | |
c378eb4e | 428 | /* If a second arg is supplied, it is a source file name to match on. */ |
c906108c SS |
429 | if (argv[1] != NULL) |
430 | { | |
431 | symname = argv[1]; | |
432 | } | |
433 | } | |
434 | ||
435 | filename = tilde_expand (filename); | |
b8c9b27d | 436 | make_cleanup (xfree, filename); |
c5aa993b | 437 | |
c906108c SS |
438 | outfile = gdb_fopen (filename, FOPEN_WT); |
439 | if (outfile == 0) | |
440 | perror_with_name (filename); | |
d9fcf2fb | 441 | make_cleanup_ui_file_delete (outfile); |
c906108c | 442 | |
c906108c | 443 | ALL_SYMTABS (objfile, s) |
27618ce4 TT |
444 | { |
445 | QUIT; | |
446 | if (symname == NULL || filename_cmp (symname, s->filename) == 0) | |
447 | dump_symtab (objfile, s, outfile); | |
448 | } | |
c906108c SS |
449 | do_cleanups (cleanups); |
450 | } | |
451 | ||
452 | /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how | |
453 | far to indent. ARGS is really a struct print_symbol_args *, but is | |
454 | declared as char * to get it past catch_errors. Returns 0 for error, | |
455 | 1 for success. */ | |
456 | ||
457 | static int | |
4efb68b1 | 458 | print_symbol (void *args) |
c906108c | 459 | { |
5af949e3 | 460 | struct gdbarch *gdbarch = ((struct print_symbol_args *) args)->gdbarch; |
c5aa993b JM |
461 | struct symbol *symbol = ((struct print_symbol_args *) args)->symbol; |
462 | int depth = ((struct print_symbol_args *) args)->depth; | |
d9fcf2fb | 463 | struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile; |
714835d5 | 464 | struct obj_section *section = SYMBOL_OBJ_SECTION (symbol); |
c906108c SS |
465 | |
466 | print_spaces (depth, outfile); | |
176620f1 | 467 | if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN) |
c906108c | 468 | { |
de5ad195 | 469 | fprintf_filtered (outfile, "label %s at ", SYMBOL_PRINT_NAME (symbol)); |
5af949e3 UW |
470 | fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)), |
471 | outfile); | |
714835d5 | 472 | if (section) |
c906108c | 473 | fprintf_filtered (outfile, " section %s\n", |
714835d5 UW |
474 | bfd_section_name (section->the_bfd_section->owner, |
475 | section->the_bfd_section)); | |
c906108c SS |
476 | else |
477 | fprintf_filtered (outfile, "\n"); | |
478 | return 1; | |
479 | } | |
176620f1 | 480 | if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN) |
c906108c SS |
481 | { |
482 | if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol))) | |
483 | { | |
79d43c61 TT |
484 | LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth, |
485 | &type_print_raw_options); | |
c906108c SS |
486 | } |
487 | else | |
488 | { | |
489 | fprintf_filtered (outfile, "%s %s = ", | |
c5aa993b JM |
490 | (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM |
491 | ? "enum" | |
492 | : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT | |
493 | ? "struct" : "union")), | |
3567439c | 494 | SYMBOL_LINKAGE_NAME (symbol)); |
79d43c61 TT |
495 | LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth, |
496 | &type_print_raw_options); | |
c906108c SS |
497 | } |
498 | fprintf_filtered (outfile, ";\n"); | |
499 | } | |
500 | else | |
501 | { | |
502 | if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF) | |
503 | fprintf_filtered (outfile, "typedef "); | |
504 | if (SYMBOL_TYPE (symbol)) | |
505 | { | |
506 | /* Print details of types, except for enums where it's clutter. */ | |
de5ad195 | 507 | LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_PRINT_NAME (symbol), |
c906108c SS |
508 | outfile, |
509 | TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM, | |
79d43c61 TT |
510 | depth, |
511 | &type_print_raw_options); | |
c906108c SS |
512 | fprintf_filtered (outfile, "; "); |
513 | } | |
514 | else | |
de5ad195 | 515 | fprintf_filtered (outfile, "%s ", SYMBOL_PRINT_NAME (symbol)); |
c906108c SS |
516 | |
517 | switch (SYMBOL_CLASS (symbol)) | |
518 | { | |
519 | case LOC_CONST: | |
12df843f JK |
520 | fprintf_filtered (outfile, "const %s (%s)", |
521 | plongest (SYMBOL_VALUE (symbol)), | |
522 | hex_string (SYMBOL_VALUE (symbol))); | |
c906108c SS |
523 | break; |
524 | ||
525 | case LOC_CONST_BYTES: | |
526 | { | |
527 | unsigned i; | |
528 | struct type *type = check_typedef (SYMBOL_TYPE (symbol)); | |
433759f7 | 529 | |
c906108c SS |
530 | fprintf_filtered (outfile, "const %u hex bytes:", |
531 | TYPE_LENGTH (type)); | |
532 | for (i = 0; i < TYPE_LENGTH (type); i++) | |
533 | fprintf_filtered (outfile, " %02x", | |
c5aa993b | 534 | (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]); |
c906108c SS |
535 | } |
536 | break; | |
537 | ||
538 | case LOC_STATIC: | |
539 | fprintf_filtered (outfile, "static at "); | |
5af949e3 UW |
540 | fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)), |
541 | outfile); | |
714835d5 | 542 | if (section) |
c906108c | 543 | fprintf_filtered (outfile, " section %s", |
714835d5 UW |
544 | bfd_section_name (section->the_bfd_section->owner, |
545 | section->the_bfd_section)); | |
c906108c SS |
546 | break; |
547 | ||
c906108c | 548 | case LOC_REGISTER: |
2a2d4dc3 | 549 | if (SYMBOL_IS_ARGUMENT (symbol)) |
12df843f JK |
550 | fprintf_filtered (outfile, "parameter register %s", |
551 | plongest (SYMBOL_VALUE (symbol))); | |
2a2d4dc3 | 552 | else |
12df843f JK |
553 | fprintf_filtered (outfile, "register %s", |
554 | plongest (SYMBOL_VALUE (symbol))); | |
c906108c SS |
555 | break; |
556 | ||
557 | case LOC_ARG: | |
12df843f JK |
558 | fprintf_filtered (outfile, "arg at offset %s", |
559 | hex_string (SYMBOL_VALUE (symbol))); | |
c906108c SS |
560 | break; |
561 | ||
c906108c | 562 | case LOC_REF_ARG: |
12df843f JK |
563 | fprintf_filtered (outfile, "reference arg at %s", |
564 | hex_string (SYMBOL_VALUE (symbol))); | |
c906108c SS |
565 | break; |
566 | ||
c906108c | 567 | case LOC_REGPARM_ADDR: |
12df843f JK |
568 | fprintf_filtered (outfile, "address parameter register %s", |
569 | plongest (SYMBOL_VALUE (symbol))); | |
c906108c SS |
570 | break; |
571 | ||
572 | case LOC_LOCAL: | |
12df843f JK |
573 | fprintf_filtered (outfile, "local at offset %s", |
574 | hex_string (SYMBOL_VALUE (symbol))); | |
c906108c SS |
575 | break; |
576 | ||
c906108c SS |
577 | case LOC_TYPEDEF: |
578 | break; | |
579 | ||
580 | case LOC_LABEL: | |
581 | fprintf_filtered (outfile, "label at "); | |
5af949e3 UW |
582 | fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)), |
583 | outfile); | |
714835d5 | 584 | if (section) |
c906108c | 585 | fprintf_filtered (outfile, " section %s", |
714835d5 UW |
586 | bfd_section_name (section->the_bfd_section->owner, |
587 | section->the_bfd_section)); | |
c906108c SS |
588 | break; |
589 | ||
590 | case LOC_BLOCK: | |
591 | fprintf_filtered (outfile, "block object "); | |
d4f3574e | 592 | gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile); |
c906108c | 593 | fprintf_filtered (outfile, ", "); |
5af949e3 UW |
594 | fputs_filtered (paddress (gdbarch, |
595 | BLOCK_START (SYMBOL_BLOCK_VALUE (symbol))), | |
ed49a04f | 596 | outfile); |
c906108c | 597 | fprintf_filtered (outfile, ".."); |
5af949e3 UW |
598 | fputs_filtered (paddress (gdbarch, |
599 | BLOCK_END (SYMBOL_BLOCK_VALUE (symbol))), | |
ed49a04f | 600 | outfile); |
714835d5 | 601 | if (section) |
c906108c | 602 | fprintf_filtered (outfile, " section %s", |
714835d5 UW |
603 | bfd_section_name (section->the_bfd_section->owner, |
604 | section->the_bfd_section)); | |
c906108c SS |
605 | break; |
606 | ||
4c2df51b | 607 | case LOC_COMPUTED: |
4c2df51b DJ |
608 | fprintf_filtered (outfile, "computed at runtime"); |
609 | break; | |
610 | ||
c906108c SS |
611 | case LOC_UNRESOLVED: |
612 | fprintf_filtered (outfile, "unresolved"); | |
613 | break; | |
614 | ||
615 | case LOC_OPTIMIZED_OUT: | |
616 | fprintf_filtered (outfile, "optimized out"); | |
617 | break; | |
618 | ||
c5aa993b | 619 | default: |
c906108c SS |
620 | fprintf_filtered (outfile, "botched symbol class %x", |
621 | SYMBOL_CLASS (symbol)); | |
622 | break; | |
623 | } | |
624 | } | |
625 | fprintf_filtered (outfile, "\n"); | |
626 | return 1; | |
627 | } | |
628 | ||
c906108c | 629 | void |
fba45db2 | 630 | maintenance_print_msymbols (char *args, int from_tty) |
c906108c SS |
631 | { |
632 | char **argv; | |
d9fcf2fb | 633 | struct ui_file *outfile; |
c906108c SS |
634 | struct cleanup *cleanups; |
635 | char *filename = DEV_TTY; | |
636 | char *symname = NULL; | |
6c95b8df | 637 | struct program_space *pspace; |
c906108c SS |
638 | struct objfile *objfile; |
639 | ||
07318b29 CV |
640 | struct stat sym_st, obj_st; |
641 | ||
c906108c SS |
642 | dont_repeat (); |
643 | ||
644 | if (args == NULL) | |
645 | { | |
3e43a32a MS |
646 | error (_("print-msymbols takes an output file " |
647 | "name and optional symbol file name")); | |
c906108c | 648 | } |
d1a41061 | 649 | argv = gdb_buildargv (args); |
7a292a7a | 650 | cleanups = make_cleanup_freeargv (argv); |
c906108c SS |
651 | |
652 | if (argv[0] != NULL) | |
653 | { | |
654 | filename = argv[0]; | |
c378eb4e | 655 | /* If a second arg is supplied, it is a source file name to match on. */ |
c906108c SS |
656 | if (argv[1] != NULL) |
657 | { | |
07318b29 CV |
658 | symname = xfullpath (argv[1]); |
659 | make_cleanup (xfree, symname); | |
660 | if (symname && stat (symname, &sym_st)) | |
661 | perror_with_name (symname); | |
c906108c SS |
662 | } |
663 | } | |
664 | ||
665 | filename = tilde_expand (filename); | |
b8c9b27d | 666 | make_cleanup (xfree, filename); |
c5aa993b | 667 | |
c906108c SS |
668 | outfile = gdb_fopen (filename, FOPEN_WT); |
669 | if (outfile == 0) | |
670 | perror_with_name (filename); | |
d9fcf2fb | 671 | make_cleanup_ui_file_delete (outfile); |
c906108c | 672 | |
6c95b8df PA |
673 | ALL_PSPACES (pspace) |
674 | ALL_PSPACE_OBJFILES (pspace, objfile) | |
27618ce4 TT |
675 | { |
676 | QUIT; | |
677 | if (symname == NULL || (!stat (objfile->name, &obj_st) | |
678 | && sym_st.st_ino == obj_st.st_ino)) | |
679 | dump_msymbols (objfile, outfile); | |
680 | } | |
c906108c SS |
681 | fprintf_filtered (outfile, "\n\n"); |
682 | do_cleanups (cleanups); | |
683 | } | |
684 | ||
685 | void | |
fba45db2 | 686 | maintenance_print_objfiles (char *ignore, int from_tty) |
c906108c | 687 | { |
6c95b8df | 688 | struct program_space *pspace; |
c906108c SS |
689 | struct objfile *objfile; |
690 | ||
691 | dont_repeat (); | |
692 | ||
6c95b8df PA |
693 | ALL_PSPACES (pspace) |
694 | ALL_PSPACE_OBJFILES (pspace, objfile) | |
27618ce4 TT |
695 | { |
696 | QUIT; | |
697 | dump_objfile (objfile); | |
698 | } | |
c906108c SS |
699 | } |
700 | ||
5e7b2f39 | 701 | /* List all the symbol tables whose names match REGEXP (optional). */ |
b5ebcee6 | 702 | |
44ea7b70 | 703 | void |
5e7b2f39 | 704 | maintenance_info_symtabs (char *regexp, int from_tty) |
44ea7b70 | 705 | { |
6c95b8df | 706 | struct program_space *pspace; |
44ea7b70 JB |
707 | struct objfile *objfile; |
708 | ||
709 | if (regexp) | |
710 | re_comp (regexp); | |
711 | ||
6c95b8df PA |
712 | ALL_PSPACES (pspace) |
713 | ALL_PSPACE_OBJFILES (pspace, objfile) | |
44ea7b70 JB |
714 | { |
715 | struct symtab *symtab; | |
716 | ||
717 | /* We don't want to print anything for this objfile until we | |
718 | actually find a symtab whose name matches. */ | |
719 | int printed_objfile_start = 0; | |
720 | ||
721 | ALL_OBJFILE_SYMTABS (objfile, symtab) | |
8a498d38 DE |
722 | { |
723 | QUIT; | |
724 | ||
725 | if (! regexp | |
726 | || re_exec (symtab->filename)) | |
727 | { | |
728 | if (! printed_objfile_start) | |
729 | { | |
730 | printf_filtered ("{ objfile %s ", objfile->name); | |
731 | wrap_here (" "); | |
a74ce742 PM |
732 | printf_filtered ("((struct objfile *) %s)\n", |
733 | host_address_to_string (objfile)); | |
8a498d38 DE |
734 | printed_objfile_start = 1; |
735 | } | |
736 | ||
737 | printf_filtered (" { symtab %s ", symtab->filename); | |
738 | wrap_here (" "); | |
a74ce742 PM |
739 | printf_filtered ("((struct symtab *) %s)\n", |
740 | host_address_to_string (symtab)); | |
8a498d38 DE |
741 | printf_filtered (" dirname %s\n", |
742 | symtab->dirname ? symtab->dirname : "(null)"); | |
743 | printf_filtered (" fullname %s\n", | |
744 | symtab->fullname ? symtab->fullname : "(null)"); | |
3e43a32a MS |
745 | printf_filtered (" " |
746 | "blockvector ((struct blockvector *) %s)%s\n", | |
a74ce742 | 747 | host_address_to_string (symtab->blockvector), |
8a498d38 | 748 | symtab->primary ? " (primary)" : ""); |
3e43a32a MS |
749 | printf_filtered (" " |
750 | "linetable ((struct linetable *) %s)\n", | |
a74ce742 | 751 | host_address_to_string (symtab->linetable)); |
3e43a32a MS |
752 | printf_filtered (" debugformat %s\n", |
753 | symtab->debugformat); | |
8a498d38 DE |
754 | printf_filtered (" }\n"); |
755 | } | |
756 | } | |
44ea7b70 JB |
757 | |
758 | if (printed_objfile_start) | |
759 | printf_filtered ("}\n"); | |
760 | } | |
761 | } | |
c906108c | 762 | \f |
c5aa993b | 763 | |
c906108c SS |
764 | /* Return the nexting depth of a block within other blocks in its symtab. */ |
765 | ||
766 | static int | |
fba45db2 | 767 | block_depth (struct block *block) |
c906108c | 768 | { |
52f0bd74 | 769 | int i = 0; |
433759f7 | 770 | |
c5aa993b | 771 | while ((block = BLOCK_SUPERBLOCK (block)) != NULL) |
c906108c SS |
772 | { |
773 | i++; | |
774 | } | |
775 | return i; | |
776 | } | |
c906108c | 777 | \f |
c5aa993b | 778 | |
c378eb4e | 779 | /* Do early runtime initializations. */ |
b5ebcee6 | 780 | |
c906108c | 781 | void |
fba45db2 | 782 | _initialize_symmisc (void) |
c906108c | 783 | { |
c5aa993b | 784 | std_in = stdin; |
c906108c SS |
785 | std_out = stdout; |
786 | std_err = stderr; | |
787 | } |