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