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