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