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