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 | { |
c906108c SS |
91 | switch (s->free_code) |
92 | { | |
93 | case free_nothing: | |
94 | /* All the contents are part of a big block of memory (an obstack), | |
c5aa993b JM |
95 | and some other symtab is in charge of freeing that block. |
96 | Therefore, do nothing. */ | |
c906108c SS |
97 | break; |
98 | ||
c906108c | 99 | case free_linetable: |
de4f826b | 100 | /* Everything will be freed either by our `free_func' |
c5aa993b JM |
101 | or by some other symtab, except for our linetable. |
102 | Free that now. */ | |
c906108c | 103 | if (LINETABLE (s)) |
2dc74dc1 | 104 | xfree (LINETABLE (s)); |
c906108c SS |
105 | break; |
106 | } | |
107 | ||
108 | /* If there is a single block of memory to free, free it. */ | |
de4f826b DC |
109 | if (s->free_func != NULL) |
110 | s->free_func (s); | |
c906108c SS |
111 | |
112 | /* Free source-related stuff */ | |
c5aa993b | 113 | if (s->line_charpos != NULL) |
2dc74dc1 | 114 | xfree (s->line_charpos); |
c5aa993b | 115 | if (s->fullname != NULL) |
2dc74dc1 | 116 | xfree (s->fullname); |
c5aa993b | 117 | if (s->debugformat != NULL) |
2dc74dc1 AC |
118 | xfree (s->debugformat); |
119 | xfree (s); | |
c906108c SS |
120 | } |
121 | ||
c906108c | 122 | void |
fba45db2 | 123 | print_symbol_bcache_statistics (void) |
c906108c | 124 | { |
6c95b8df | 125 | struct program_space *pspace; |
c906108c SS |
126 | struct objfile *objfile; |
127 | ||
128 | immediate_quit++; | |
6c95b8df PA |
129 | ALL_PSPACES (pspace) |
130 | ALL_PSPACE_OBJFILES (pspace, objfile) | |
c5aa993b | 131 | { |
a3f17187 | 132 | printf_filtered (_("Byte cache statistics for '%s':\n"), objfile->name); |
710e1a31 SW |
133 | print_bcache_statistics (psymbol_bcache_get_bcache (objfile->psymbol_cache), |
134 | "partial symbol cache"); | |
d4ce0d3f | 135 | print_bcache_statistics (objfile->macro_cache, "preprocessor macro cache"); |
10abe6bf | 136 | print_bcache_statistics (objfile->filename_cache, "file name cache"); |
c5aa993b | 137 | } |
c906108c SS |
138 | immediate_quit--; |
139 | } | |
140 | ||
141 | void | |
fba45db2 | 142 | print_objfile_statistics (void) |
c906108c | 143 | { |
6c95b8df | 144 | struct program_space *pspace; |
c906108c | 145 | struct objfile *objfile; |
c4f90d87 | 146 | struct symtab *s; |
c4f90d87 | 147 | int i, linetables, blockvectors; |
c906108c SS |
148 | |
149 | immediate_quit++; | |
6c95b8df PA |
150 | ALL_PSPACES (pspace) |
151 | ALL_PSPACE_OBJFILES (pspace, objfile) | |
c5aa993b | 152 | { |
a3f17187 | 153 | printf_filtered (_("Statistics for '%s':\n"), objfile->name); |
c5aa993b | 154 | if (OBJSTAT (objfile, n_stabs) > 0) |
a3f17187 | 155 | printf_filtered (_(" Number of \"stab\" symbols read: %d\n"), |
c5aa993b JM |
156 | OBJSTAT (objfile, n_stabs)); |
157 | if (OBJSTAT (objfile, n_minsyms) > 0) | |
a3f17187 | 158 | printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"), |
c5aa993b JM |
159 | OBJSTAT (objfile, n_minsyms)); |
160 | if (OBJSTAT (objfile, n_psyms) > 0) | |
a3f17187 | 161 | printf_filtered (_(" Number of \"partial\" symbols read: %d\n"), |
c5aa993b JM |
162 | OBJSTAT (objfile, n_psyms)); |
163 | if (OBJSTAT (objfile, n_syms) > 0) | |
a3f17187 | 164 | printf_filtered (_(" Number of \"full\" symbols read: %d\n"), |
c5aa993b JM |
165 | OBJSTAT (objfile, n_syms)); |
166 | if (OBJSTAT (objfile, n_types) > 0) | |
a3f17187 | 167 | printf_filtered (_(" Number of \"types\" defined: %d\n"), |
c5aa993b | 168 | OBJSTAT (objfile, n_types)); |
ccefe4c4 TT |
169 | if (objfile->sf) |
170 | objfile->sf->qf->print_stats (objfile); | |
c4f90d87 JM |
171 | i = linetables = blockvectors = 0; |
172 | ALL_OBJFILE_SYMTABS (objfile, s) | |
173 | { | |
174 | i++; | |
175 | if (s->linetable != NULL) | |
176 | linetables++; | |
177 | if (s->primary == 1) | |
178 | blockvectors++; | |
179 | } | |
a3f17187 AC |
180 | printf_filtered (_(" Number of symbol tables: %d\n"), i); |
181 | printf_filtered (_(" Number of symbol tables with line tables: %d\n"), | |
c4f90d87 | 182 | linetables); |
a3f17187 | 183 | printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"), |
c4f90d87 JM |
184 | blockvectors); |
185 | ||
c5aa993b | 186 | if (OBJSTAT (objfile, sz_strtab) > 0) |
a3f17187 | 187 | printf_filtered (_(" Space used by a.out string tables: %d\n"), |
c5aa993b | 188 | OBJSTAT (objfile, sz_strtab)); |
a3f17187 | 189 | printf_filtered (_(" Total memory used for objfile obstack: %d\n"), |
4a146b47 | 190 | obstack_memory_used (&objfile->objfile_obstack)); |
a3f17187 | 191 | printf_filtered (_(" Total memory used for psymbol cache: %d\n"), |
710e1a31 SW |
192 | bcache_memory_used (psymbol_bcache_get_bcache |
193 | (objfile->psymbol_cache))); | |
a3f17187 | 194 | printf_filtered (_(" Total memory used for macro cache: %d\n"), |
af5f3db6 | 195 | bcache_memory_used (objfile->macro_cache)); |
10abe6bf TT |
196 | printf_filtered (_(" Total memory used for file name cache: %d\n"), |
197 | bcache_memory_used (objfile->filename_cache)); | |
c5aa993b | 198 | } |
c906108c SS |
199 | immediate_quit--; |
200 | } | |
201 | ||
c5aa993b | 202 | static void |
fba45db2 | 203 | dump_objfile (struct objfile *objfile) |
c906108c SS |
204 | { |
205 | struct symtab *symtab; | |
c906108c | 206 | |
c5aa993b | 207 | printf_filtered ("\nObject file %s: ", objfile->name); |
c906108c | 208 | printf_filtered ("Objfile at "); |
d4f3574e | 209 | gdb_print_host_address (objfile, gdb_stdout); |
c906108c | 210 | printf_filtered (", bfd at "); |
d4f3574e | 211 | gdb_print_host_address (objfile->obfd, gdb_stdout); |
c906108c SS |
212 | printf_filtered (", %d minsyms\n\n", |
213 | objfile->minimal_symbol_count); | |
214 | ||
ccefe4c4 TT |
215 | if (objfile->sf) |
216 | objfile->sf->qf->dump (objfile); | |
c906108c | 217 | |
c5aa993b | 218 | if (objfile->symtabs) |
c906108c SS |
219 | { |
220 | printf_filtered ("Symtabs:\n"); | |
c5aa993b | 221 | for (symtab = objfile->symtabs; |
c906108c SS |
222 | symtab != NULL; |
223 | symtab = symtab->next) | |
224 | { | |
c5aa993b | 225 | printf_filtered ("%s at ", symtab->filename); |
d4f3574e | 226 | gdb_print_host_address (symtab, gdb_stdout); |
c906108c | 227 | printf_filtered (", "); |
c5aa993b | 228 | if (symtab->objfile != objfile) |
c906108c SS |
229 | { |
230 | printf_filtered ("NOT ON CHAIN! "); | |
231 | } | |
232 | wrap_here (" "); | |
233 | } | |
234 | printf_filtered ("\n\n"); | |
235 | } | |
236 | } | |
237 | ||
238 | /* Print minimal symbols from this objfile. */ | |
c5aa993b JM |
239 | |
240 | static void | |
fba45db2 | 241 | dump_msymbols (struct objfile *objfile, struct ui_file *outfile) |
c906108c | 242 | { |
5af949e3 | 243 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
244 | struct minimal_symbol *msymbol; |
245 | int index; | |
246 | char ms_type; | |
c5aa993b JM |
247 | |
248 | fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile->name); | |
249 | if (objfile->minimal_symbol_count == 0) | |
c906108c SS |
250 | { |
251 | fprintf_filtered (outfile, "No minimal symbols found.\n"); | |
252 | return; | |
253 | } | |
3567439c DJ |
254 | index = 0; |
255 | ALL_OBJFILE_MSYMBOLS (objfile, msymbol) | |
c906108c | 256 | { |
714835d5 UW |
257 | struct obj_section *section = SYMBOL_OBJ_SECTION (msymbol); |
258 | ||
712f90be | 259 | switch (MSYMBOL_TYPE (msymbol)) |
c906108c | 260 | { |
c5aa993b JM |
261 | case mst_unknown: |
262 | ms_type = 'u'; | |
263 | break; | |
264 | case mst_text: | |
265 | ms_type = 'T'; | |
266 | break; | |
267 | case mst_solib_trampoline: | |
268 | ms_type = 'S'; | |
269 | break; | |
270 | case mst_data: | |
271 | ms_type = 'D'; | |
272 | break; | |
273 | case mst_bss: | |
274 | ms_type = 'B'; | |
275 | break; | |
276 | case mst_abs: | |
277 | ms_type = 'A'; | |
278 | break; | |
279 | case mst_file_text: | |
280 | ms_type = 't'; | |
281 | break; | |
282 | case mst_file_data: | |
283 | ms_type = 'd'; | |
284 | break; | |
285 | case mst_file_bss: | |
286 | ms_type = 'b'; | |
287 | break; | |
288 | default: | |
289 | ms_type = '?'; | |
290 | break; | |
c906108c SS |
291 | } |
292 | fprintf_filtered (outfile, "[%2d] %c ", index, ms_type); | |
5af949e3 UW |
293 | fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (msymbol)), |
294 | outfile); | |
3567439c | 295 | fprintf_filtered (outfile, " %s", SYMBOL_LINKAGE_NAME (msymbol)); |
714835d5 | 296 | if (section) |
c906108c SS |
297 | fprintf_filtered (outfile, " section %s", |
298 | bfd_section_name (objfile->obfd, | |
714835d5 | 299 | section->the_bfd_section)); |
c906108c SS |
300 | if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL) |
301 | { | |
302 | fprintf_filtered (outfile, " %s", SYMBOL_DEMANGLED_NAME (msymbol)); | |
303 | } | |
c906108c SS |
304 | if (msymbol->filename) |
305 | fprintf_filtered (outfile, " %s", msymbol->filename); | |
c906108c | 306 | fputs_filtered ("\n", outfile); |
3567439c | 307 | index++; |
c906108c | 308 | } |
c5aa993b | 309 | if (objfile->minimal_symbol_count != index) |
c906108c | 310 | { |
8a3fe4f8 | 311 | warning (_("internal error: minimal symbol count %d != %d"), |
c5aa993b | 312 | objfile->minimal_symbol_count, index); |
c906108c SS |
313 | } |
314 | fprintf_filtered (outfile, "\n"); | |
315 | } | |
316 | ||
c5aa993b | 317 | static void |
44b164c5 JB |
318 | dump_symtab_1 (struct objfile *objfile, struct symtab *symtab, |
319 | struct ui_file *outfile) | |
c906108c | 320 | { |
5af949e3 | 321 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
de4f826b DC |
322 | int i; |
323 | struct dict_iterator iter; | |
952a6d41 | 324 | int len; |
de4f826b | 325 | struct linetable *l; |
c906108c | 326 | struct blockvector *bv; |
e88c90f2 | 327 | struct symbol *sym; |
de4f826b | 328 | struct block *b; |
c906108c SS |
329 | int depth; |
330 | ||
331 | fprintf_filtered (outfile, "\nSymtab for file %s\n", symtab->filename); | |
332 | if (symtab->dirname) | |
333 | fprintf_filtered (outfile, "Compilation directory is %s\n", | |
334 | symtab->dirname); | |
335 | fprintf_filtered (outfile, "Read from object file %s (", objfile->name); | |
d4f3574e | 336 | gdb_print_host_address (objfile, outfile); |
c906108c SS |
337 | fprintf_filtered (outfile, ")\n"); |
338 | fprintf_filtered (outfile, "Language: %s\n", language_str (symtab->language)); | |
339 | ||
340 | /* First print the line table. */ | |
341 | l = LINETABLE (symtab); | |
342 | if (l) | |
343 | { | |
344 | fprintf_filtered (outfile, "\nLine table:\n\n"); | |
345 | len = l->nitems; | |
346 | for (i = 0; i < len; i++) | |
347 | { | |
348 | fprintf_filtered (outfile, " line %d at ", l->item[i].line); | |
5af949e3 | 349 | fputs_filtered (paddress (gdbarch, l->item[i].pc), outfile); |
c906108c SS |
350 | fprintf_filtered (outfile, "\n"); |
351 | } | |
352 | } | |
353 | /* Now print the block info, but only for primary symtabs since we will | |
354 | print lots of duplicate info otherwise. */ | |
c5aa993b | 355 | if (symtab->primary) |
c906108c SS |
356 | { |
357 | fprintf_filtered (outfile, "\nBlockvector:\n\n"); | |
358 | bv = BLOCKVECTOR (symtab); | |
359 | len = BLOCKVECTOR_NBLOCKS (bv); | |
360 | for (i = 0; i < len; i++) | |
361 | { | |
362 | b = BLOCKVECTOR_BLOCK (bv, i); | |
363 | depth = block_depth (b) * 2; | |
364 | print_spaces (depth, outfile); | |
365 | fprintf_filtered (outfile, "block #%03d, object at ", i); | |
d4f3574e | 366 | gdb_print_host_address (b, outfile); |
c906108c SS |
367 | if (BLOCK_SUPERBLOCK (b)) |
368 | { | |
369 | fprintf_filtered (outfile, " under "); | |
d4f3574e | 370 | gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile); |
c906108c | 371 | } |
261397f8 DJ |
372 | /* drow/2002-07-10: We could save the total symbols count |
373 | even if we're using a hashtable, but nothing else but this message | |
374 | wants it. */ | |
de4f826b DC |
375 | fprintf_filtered (outfile, ", %d syms/buckets in ", |
376 | dict_size (BLOCK_DICT (b))); | |
5af949e3 | 377 | fputs_filtered (paddress (gdbarch, BLOCK_START (b)), outfile); |
c906108c | 378 | fprintf_filtered (outfile, ".."); |
5af949e3 | 379 | fputs_filtered (paddress (gdbarch, BLOCK_END (b)), outfile); |
c906108c SS |
380 | if (BLOCK_FUNCTION (b)) |
381 | { | |
3567439c DJ |
382 | fprintf_filtered (outfile, ", function %s", |
383 | SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b))); | |
c906108c SS |
384 | if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL) |
385 | { | |
386 | fprintf_filtered (outfile, ", %s", | |
c5aa993b | 387 | SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b))); |
c906108c SS |
388 | } |
389 | } | |
c906108c | 390 | fprintf_filtered (outfile, "\n"); |
261397f8 DJ |
391 | /* Now print each symbol in this block (in no particular order, if |
392 | we're using a hashtable). */ | |
de4f826b | 393 | ALL_BLOCK_SYMBOLS (b, iter, sym) |
c906108c SS |
394 | { |
395 | struct print_symbol_args s; | |
433759f7 | 396 | |
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)); | |
433759f7 | 557 | |
c906108c SS |
558 | fprintf_filtered (outfile, "const %u hex bytes:", |
559 | TYPE_LENGTH (type)); | |
560 | for (i = 0; i < TYPE_LENGTH (type); i++) | |
561 | fprintf_filtered (outfile, " %02x", | |
c5aa993b | 562 | (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]); |
c906108c SS |
563 | } |
564 | break; | |
565 | ||
566 | case LOC_STATIC: | |
567 | fprintf_filtered (outfile, "static at "); | |
5af949e3 UW |
568 | fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)), |
569 | outfile); | |
714835d5 | 570 | if (section) |
c906108c | 571 | fprintf_filtered (outfile, " section %s", |
714835d5 UW |
572 | bfd_section_name (section->the_bfd_section->owner, |
573 | section->the_bfd_section)); | |
c906108c SS |
574 | break; |
575 | ||
c906108c | 576 | case LOC_REGISTER: |
2a2d4dc3 AS |
577 | if (SYMBOL_IS_ARGUMENT (symbol)) |
578 | fprintf_filtered (outfile, "parameter register %ld", | |
579 | SYMBOL_VALUE (symbol)); | |
580 | else | |
581 | fprintf_filtered (outfile, "register %ld", SYMBOL_VALUE (symbol)); | |
c906108c SS |
582 | break; |
583 | ||
584 | case LOC_ARG: | |
585 | fprintf_filtered (outfile, "arg at offset 0x%lx", | |
586 | SYMBOL_VALUE (symbol)); | |
587 | break; | |
588 | ||
c906108c SS |
589 | case LOC_REF_ARG: |
590 | fprintf_filtered (outfile, "reference arg at 0x%lx", SYMBOL_VALUE (symbol)); | |
591 | break; | |
592 | ||
c906108c SS |
593 | case LOC_REGPARM_ADDR: |
594 | fprintf_filtered (outfile, "address parameter register %ld", SYMBOL_VALUE (symbol)); | |
595 | break; | |
596 | ||
597 | case LOC_LOCAL: | |
598 | fprintf_filtered (outfile, "local at offset 0x%lx", | |
599 | SYMBOL_VALUE (symbol)); | |
600 | break; | |
601 | ||
c906108c SS |
602 | case LOC_TYPEDEF: |
603 | break; | |
604 | ||
605 | case LOC_LABEL: | |
606 | fprintf_filtered (outfile, "label at "); | |
5af949e3 UW |
607 | fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)), |
608 | outfile); | |
714835d5 | 609 | if (section) |
c906108c | 610 | fprintf_filtered (outfile, " section %s", |
714835d5 UW |
611 | bfd_section_name (section->the_bfd_section->owner, |
612 | section->the_bfd_section)); | |
c906108c SS |
613 | break; |
614 | ||
615 | case LOC_BLOCK: | |
616 | fprintf_filtered (outfile, "block object "); | |
d4f3574e | 617 | gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile); |
c906108c | 618 | fprintf_filtered (outfile, ", "); |
5af949e3 UW |
619 | fputs_filtered (paddress (gdbarch, |
620 | BLOCK_START (SYMBOL_BLOCK_VALUE (symbol))), | |
ed49a04f | 621 | outfile); |
c906108c | 622 | fprintf_filtered (outfile, ".."); |
5af949e3 UW |
623 | fputs_filtered (paddress (gdbarch, |
624 | BLOCK_END (SYMBOL_BLOCK_VALUE (symbol))), | |
ed49a04f | 625 | outfile); |
714835d5 | 626 | if (section) |
c906108c | 627 | fprintf_filtered (outfile, " section %s", |
714835d5 UW |
628 | bfd_section_name (section->the_bfd_section->owner, |
629 | section->the_bfd_section)); | |
c906108c SS |
630 | break; |
631 | ||
4c2df51b | 632 | case LOC_COMPUTED: |
4c2df51b DJ |
633 | fprintf_filtered (outfile, "computed at runtime"); |
634 | break; | |
635 | ||
c906108c SS |
636 | case LOC_UNRESOLVED: |
637 | fprintf_filtered (outfile, "unresolved"); | |
638 | break; | |
639 | ||
640 | case LOC_OPTIMIZED_OUT: | |
641 | fprintf_filtered (outfile, "optimized out"); | |
642 | break; | |
643 | ||
c5aa993b | 644 | default: |
c906108c SS |
645 | fprintf_filtered (outfile, "botched symbol class %x", |
646 | SYMBOL_CLASS (symbol)); | |
647 | break; | |
648 | } | |
649 | } | |
650 | fprintf_filtered (outfile, "\n"); | |
651 | return 1; | |
652 | } | |
653 | ||
c906108c | 654 | void |
fba45db2 | 655 | maintenance_print_msymbols (char *args, int from_tty) |
c906108c SS |
656 | { |
657 | char **argv; | |
d9fcf2fb | 658 | struct ui_file *outfile; |
c906108c SS |
659 | struct cleanup *cleanups; |
660 | char *filename = DEV_TTY; | |
661 | char *symname = NULL; | |
6c95b8df | 662 | struct program_space *pspace; |
c906108c SS |
663 | struct objfile *objfile; |
664 | ||
07318b29 CV |
665 | struct stat sym_st, obj_st; |
666 | ||
c906108c SS |
667 | dont_repeat (); |
668 | ||
669 | if (args == NULL) | |
670 | { | |
8a3fe4f8 | 671 | error (_("print-msymbols takes an output file name and optional symbol file name")); |
c906108c | 672 | } |
d1a41061 | 673 | argv = gdb_buildargv (args); |
7a292a7a | 674 | cleanups = make_cleanup_freeargv (argv); |
c906108c SS |
675 | |
676 | if (argv[0] != NULL) | |
677 | { | |
678 | filename = argv[0]; | |
679 | /* If a second arg is supplied, it is a source file name to match on */ | |
680 | if (argv[1] != NULL) | |
681 | { | |
07318b29 CV |
682 | symname = xfullpath (argv[1]); |
683 | make_cleanup (xfree, symname); | |
684 | if (symname && stat (symname, &sym_st)) | |
685 | perror_with_name (symname); | |
c906108c SS |
686 | } |
687 | } | |
688 | ||
689 | filename = tilde_expand (filename); | |
b8c9b27d | 690 | make_cleanup (xfree, filename); |
c5aa993b | 691 | |
c906108c SS |
692 | outfile = gdb_fopen (filename, FOPEN_WT); |
693 | if (outfile == 0) | |
694 | perror_with_name (filename); | |
d9fcf2fb | 695 | make_cleanup_ui_file_delete (outfile); |
c906108c SS |
696 | |
697 | immediate_quit++; | |
6c95b8df PA |
698 | ALL_PSPACES (pspace) |
699 | ALL_PSPACE_OBJFILES (pspace, objfile) | |
700 | if (symname == NULL | |
701 | || (!stat (objfile->name, &obj_st) && sym_st.st_ino == obj_st.st_ino)) | |
702 | dump_msymbols (objfile, outfile); | |
c906108c SS |
703 | immediate_quit--; |
704 | fprintf_filtered (outfile, "\n\n"); | |
705 | do_cleanups (cleanups); | |
706 | } | |
707 | ||
708 | void | |
fba45db2 | 709 | maintenance_print_objfiles (char *ignore, int from_tty) |
c906108c | 710 | { |
6c95b8df | 711 | struct program_space *pspace; |
c906108c SS |
712 | struct objfile *objfile; |
713 | ||
714 | dont_repeat (); | |
715 | ||
716 | immediate_quit++; | |
6c95b8df PA |
717 | ALL_PSPACES (pspace) |
718 | ALL_PSPACE_OBJFILES (pspace, objfile) | |
719 | dump_objfile (objfile); | |
c906108c SS |
720 | immediate_quit--; |
721 | } | |
722 | ||
44ea7b70 | 723 | |
5e7b2f39 | 724 | /* List all the symbol tables whose names match REGEXP (optional). */ |
44ea7b70 | 725 | void |
5e7b2f39 | 726 | maintenance_info_symtabs (char *regexp, int from_tty) |
44ea7b70 | 727 | { |
6c95b8df | 728 | struct program_space *pspace; |
44ea7b70 JB |
729 | struct objfile *objfile; |
730 | ||
731 | if (regexp) | |
732 | re_comp (regexp); | |
733 | ||
6c95b8df PA |
734 | ALL_PSPACES (pspace) |
735 | ALL_PSPACE_OBJFILES (pspace, objfile) | |
44ea7b70 JB |
736 | { |
737 | struct symtab *symtab; | |
738 | ||
739 | /* We don't want to print anything for this objfile until we | |
740 | actually find a symtab whose name matches. */ | |
741 | int printed_objfile_start = 0; | |
742 | ||
743 | ALL_OBJFILE_SYMTABS (objfile, symtab) | |
8a498d38 DE |
744 | { |
745 | QUIT; | |
746 | ||
747 | if (! regexp | |
748 | || re_exec (symtab->filename)) | |
749 | { | |
750 | if (! printed_objfile_start) | |
751 | { | |
752 | printf_filtered ("{ objfile %s ", objfile->name); | |
753 | wrap_here (" "); | |
a74ce742 PM |
754 | printf_filtered ("((struct objfile *) %s)\n", |
755 | host_address_to_string (objfile)); | |
8a498d38 DE |
756 | printed_objfile_start = 1; |
757 | } | |
758 | ||
759 | printf_filtered (" { symtab %s ", symtab->filename); | |
760 | wrap_here (" "); | |
a74ce742 PM |
761 | printf_filtered ("((struct symtab *) %s)\n", |
762 | host_address_to_string (symtab)); | |
8a498d38 DE |
763 | printf_filtered (" dirname %s\n", |
764 | symtab->dirname ? symtab->dirname : "(null)"); | |
765 | printf_filtered (" fullname %s\n", | |
766 | symtab->fullname ? symtab->fullname : "(null)"); | |
a74ce742 PM |
767 | printf_filtered (" blockvector ((struct blockvector *) %s)%s\n", |
768 | host_address_to_string (symtab->blockvector), | |
8a498d38 | 769 | symtab->primary ? " (primary)" : ""); |
a74ce742 PM |
770 | printf_filtered (" linetable ((struct linetable *) %s)\n", |
771 | host_address_to_string (symtab->linetable)); | |
8a498d38 DE |
772 | printf_filtered (" debugformat %s\n", symtab->debugformat); |
773 | printf_filtered (" }\n"); | |
774 | } | |
775 | } | |
44ea7b70 JB |
776 | |
777 | if (printed_objfile_start) | |
778 | printf_filtered ("}\n"); | |
779 | } | |
780 | } | |
c906108c | 781 | \f |
c5aa993b | 782 | |
c906108c SS |
783 | /* Return the nexting depth of a block within other blocks in its symtab. */ |
784 | ||
785 | static int | |
fba45db2 | 786 | block_depth (struct block *block) |
c906108c | 787 | { |
52f0bd74 | 788 | int i = 0; |
433759f7 | 789 | |
c5aa993b | 790 | while ((block = BLOCK_SUPERBLOCK (block)) != NULL) |
c906108c SS |
791 | { |
792 | i++; | |
793 | } | |
794 | return i; | |
795 | } | |
c906108c | 796 | \f |
c5aa993b | 797 | |
c906108c SS |
798 | /* Do early runtime initializations. */ |
799 | void | |
fba45db2 | 800 | _initialize_symmisc (void) |
c906108c | 801 | { |
c5aa993b | 802 | std_in = stdin; |
c906108c SS |
803 | std_out = stdout; |
804 | std_err = stderr; | |
805 | } |