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