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