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