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