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