[gdbserver] Move bytecode compilation bits from server.h to ax.h.
[deliverable/binutils-gdb.git] / gdb / symmisc.c
CommitLineData
c906108c 1/* Do various things to symbol tables (other than lookup), for GDB.
af5f3db6 2
28e7fd62 3 Copyright (C) 1986-2013 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
c5aa993b 10 (at your option) any later version.
c906108c 11
c5aa993b
JM
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
c906108c 16
c5aa993b 17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
19
20#include "defs.h"
21#include "symtab.h"
22#include "gdbtypes.h"
23#include "bfd.h"
0ba1096a 24#include "filenames.h"
c906108c
SS
25#include "symfile.h"
26#include "objfiles.h"
27#include "breakpoint.h"
28#include "command.h"
04ea0df1 29#include "gdb_obstack.h"
60250e8b 30#include "exceptions.h"
c906108c
SS
31#include "language.h"
32#include "bcache.h"
fe898f56 33#include "block.h"
44ea7b70 34#include "gdb_regex.h"
07318b29 35#include "gdb_stat.h"
de4f826b 36#include "dictionary.h"
79d43c61 37#include "typeprint.h"
80480540 38#include "gdbcmd.h"
05cba821 39#include "source.h"
c906108c
SS
40
41#include "gdb_string.h"
dbda9972 42#include "readline/readline.h"
c906108c 43
ccefe4c4
TT
44#include "psymtab.h"
45
c906108c
SS
46#ifndef DEV_TTY
47#define DEV_TTY "/dev/tty"
48#endif
49
50/* Unfortunately for debugging, stderr is usually a macro. This is painful
51 when calling functions that take FILE *'s from the debugger.
52 So we make a variable which has the same value and which is accessible when
53 debugging GDB with itself. Because stdin et al need not be constants,
54 we initialize them in the _initialize_symmisc function at the bottom
55 of the file. */
56FILE *std_in;
57FILE *std_out;
58FILE *std_err;
59
60/* Prototypes for local functions */
61
a14ed312 62static int block_depth (struct block *);
c906108c 63
a14ed312 64void _initialize_symmisc (void);
c906108c 65
c5aa993b
JM
66struct print_symbol_args
67 {
5af949e3 68 struct gdbarch *gdbarch;
c5aa993b
JM
69 struct symbol *symbol;
70 int depth;
d9fcf2fb 71 struct ui_file *outfile;
c5aa993b 72 };
c906108c 73
4efb68b1 74static int print_symbol (void *);
c906108c 75\f
c906108c 76
c906108c 77void
fba45db2 78print_symbol_bcache_statistics (void)
c906108c 79{
6c95b8df 80 struct program_space *pspace;
c906108c
SS
81 struct objfile *objfile;
82
6c95b8df
PA
83 ALL_PSPACES (pspace)
84 ALL_PSPACE_OBJFILES (pspace, objfile)
c5aa993b 85 {
27618ce4 86 QUIT;
a3f17187 87 printf_filtered (_("Byte cache statistics for '%s':\n"), objfile->name);
710e1a31
SW
88 print_bcache_statistics (psymbol_bcache_get_bcache (objfile->psymbol_cache),
89 "partial symbol cache");
6532ff36
TT
90 print_bcache_statistics (objfile->per_bfd->macro_cache,
91 "preprocessor macro cache");
706e3705
TT
92 print_bcache_statistics (objfile->per_bfd->filename_cache,
93 "file name cache");
c5aa993b 94 }
c906108c
SS
95}
96
97void
fba45db2 98print_objfile_statistics (void)
c906108c 99{
6c95b8df 100 struct program_space *pspace;
c906108c 101 struct objfile *objfile;
c4f90d87 102 struct symtab *s;
c4f90d87 103 int i, linetables, blockvectors;
c906108c 104
6c95b8df
PA
105 ALL_PSPACES (pspace)
106 ALL_PSPACE_OBJFILES (pspace, objfile)
c5aa993b 107 {
27618ce4 108 QUIT;
a3f17187 109 printf_filtered (_("Statistics for '%s':\n"), objfile->name);
c5aa993b 110 if (OBJSTAT (objfile, n_stabs) > 0)
a3f17187 111 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
c5aa993b
JM
112 OBJSTAT (objfile, n_stabs));
113 if (OBJSTAT (objfile, n_minsyms) > 0)
a3f17187 114 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
c5aa993b
JM
115 OBJSTAT (objfile, n_minsyms));
116 if (OBJSTAT (objfile, n_psyms) > 0)
a3f17187 117 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
c5aa993b
JM
118 OBJSTAT (objfile, n_psyms));
119 if (OBJSTAT (objfile, n_syms) > 0)
a3f17187 120 printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
c5aa993b
JM
121 OBJSTAT (objfile, n_syms));
122 if (OBJSTAT (objfile, n_types) > 0)
a3f17187 123 printf_filtered (_(" Number of \"types\" defined: %d\n"),
c5aa993b 124 OBJSTAT (objfile, n_types));
ccefe4c4
TT
125 if (objfile->sf)
126 objfile->sf->qf->print_stats (objfile);
c4f90d87
JM
127 i = linetables = blockvectors = 0;
128 ALL_OBJFILE_SYMTABS (objfile, s)
129 {
130 i++;
131 if (s->linetable != NULL)
132 linetables++;
133 if (s->primary == 1)
134 blockvectors++;
135 }
a3f17187
AC
136 printf_filtered (_(" Number of symbol tables: %d\n"), i);
137 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
c4f90d87 138 linetables);
a3f17187 139 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
c4f90d87
JM
140 blockvectors);
141
c5aa993b 142 if (OBJSTAT (objfile, sz_strtab) > 0)
a3f17187 143 printf_filtered (_(" Space used by a.out string tables: %d\n"),
c5aa993b 144 OBJSTAT (objfile, sz_strtab));
a3f17187 145 printf_filtered (_(" Total memory used for objfile obstack: %d\n"),
4a146b47 146 obstack_memory_used (&objfile->objfile_obstack));
706e3705
TT
147 printf_filtered (_(" Total memory used for BFD obstack: %d\n"),
148 obstack_memory_used (&objfile->per_bfd->storage_obstack));
a3f17187 149 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
710e1a31
SW
150 bcache_memory_used (psymbol_bcache_get_bcache
151 (objfile->psymbol_cache)));
a3f17187 152 printf_filtered (_(" Total memory used for macro cache: %d\n"),
6532ff36 153 bcache_memory_used (objfile->per_bfd->macro_cache));
10abe6bf 154 printf_filtered (_(" Total memory used for file name cache: %d\n"),
706e3705 155 bcache_memory_used (objfile->per_bfd->filename_cache));
c5aa993b 156 }
c906108c
SS
157}
158
c5aa993b 159static void
fba45db2 160dump_objfile (struct objfile *objfile)
c906108c
SS
161{
162 struct symtab *symtab;
c906108c 163
c5aa993b 164 printf_filtered ("\nObject file %s: ", objfile->name);
c906108c 165 printf_filtered ("Objfile at ");
d4f3574e 166 gdb_print_host_address (objfile, gdb_stdout);
c906108c 167 printf_filtered (", bfd at ");
d4f3574e 168 gdb_print_host_address (objfile->obfd, gdb_stdout);
c906108c
SS
169 printf_filtered (", %d minsyms\n\n",
170 objfile->minimal_symbol_count);
171
ccefe4c4
TT
172 if (objfile->sf)
173 objfile->sf->qf->dump (objfile);
c906108c 174
c5aa993b 175 if (objfile->symtabs)
c906108c
SS
176 {
177 printf_filtered ("Symtabs:\n");
c5aa993b 178 for (symtab = objfile->symtabs;
c906108c
SS
179 symtab != NULL;
180 symtab = symtab->next)
181 {
05cba821 182 printf_filtered ("%s at ", symtab_to_filename_for_display (symtab));
d4f3574e 183 gdb_print_host_address (symtab, gdb_stdout);
c906108c 184 printf_filtered (", ");
c5aa993b 185 if (symtab->objfile != objfile)
c906108c
SS
186 {
187 printf_filtered ("NOT ON CHAIN! ");
188 }
189 wrap_here (" ");
190 }
191 printf_filtered ("\n\n");
192 }
193}
194
195/* Print minimal symbols from this objfile. */
c5aa993b
JM
196
197static void
fba45db2 198dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
c906108c 199{
5af949e3 200 struct gdbarch *gdbarch = get_objfile_arch (objfile);
c906108c
SS
201 struct minimal_symbol *msymbol;
202 int index;
203 char ms_type;
c5aa993b
JM
204
205 fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile->name);
206 if (objfile->minimal_symbol_count == 0)
c906108c
SS
207 {
208 fprintf_filtered (outfile, "No minimal symbols found.\n");
209 return;
210 }
3567439c
DJ
211 index = 0;
212 ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
c906108c 213 {
e27d198c 214 struct obj_section *section = SYMBOL_OBJ_SECTION (objfile, msymbol);
714835d5 215
712f90be 216 switch (MSYMBOL_TYPE (msymbol))
c906108c 217 {
c5aa993b
JM
218 case mst_unknown:
219 ms_type = 'u';
220 break;
221 case mst_text:
222 ms_type = 'T';
223 break;
0875794a
JK
224 case mst_text_gnu_ifunc:
225 ms_type = 'i';
226 break;
c5aa993b
JM
227 case mst_solib_trampoline:
228 ms_type = 'S';
229 break;
230 case mst_data:
231 ms_type = 'D';
232 break;
233 case mst_bss:
234 ms_type = 'B';
235 break;
236 case mst_abs:
237 ms_type = 'A';
238 break;
239 case mst_file_text:
240 ms_type = 't';
241 break;
242 case mst_file_data:
243 ms_type = 'd';
244 break;
245 case mst_file_bss:
246 ms_type = 'b';
247 break;
248 default:
249 ms_type = '?';
250 break;
c906108c
SS
251 }
252 fprintf_filtered (outfile, "[%2d] %c ", index, ms_type);
5af949e3
UW
253 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (msymbol)),
254 outfile);
3567439c 255 fprintf_filtered (outfile, " %s", SYMBOL_LINKAGE_NAME (msymbol));
714835d5 256 if (section)
8625fc1b
TT
257 {
258 if (section->the_bfd_section != NULL)
259 fprintf_filtered (outfile, " section %s",
260 bfd_section_name (objfile->obfd,
261 section->the_bfd_section));
262 else
263 fprintf_filtered (outfile, " spurious section %ld",
4c8429ef 264 (long) (section - objfile->sections));
8625fc1b 265 }
c906108c
SS
266 if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
267 {
268 fprintf_filtered (outfile, " %s", SYMBOL_DEMANGLED_NAME (msymbol));
269 }
c906108c
SS
270 if (msymbol->filename)
271 fprintf_filtered (outfile, " %s", msymbol->filename);
c906108c 272 fputs_filtered ("\n", outfile);
3567439c 273 index++;
c906108c 274 }
c5aa993b 275 if (objfile->minimal_symbol_count != index)
c906108c 276 {
8a3fe4f8 277 warning (_("internal error: minimal symbol count %d != %d"),
c5aa993b 278 objfile->minimal_symbol_count, index);
c906108c
SS
279 }
280 fprintf_filtered (outfile, "\n");
281}
282
c5aa993b 283static void
44b164c5
JB
284dump_symtab_1 (struct objfile *objfile, struct symtab *symtab,
285 struct ui_file *outfile)
c906108c 286{
5af949e3 287 struct gdbarch *gdbarch = get_objfile_arch (objfile);
de4f826b
DC
288 int i;
289 struct dict_iterator iter;
952a6d41 290 int len;
de4f826b 291 struct linetable *l;
c906108c 292 struct blockvector *bv;
e88c90f2 293 struct symbol *sym;
de4f826b 294 struct block *b;
c906108c
SS
295 int depth;
296
05cba821
JK
297 fprintf_filtered (outfile, "\nSymtab for file %s\n",
298 symtab_to_filename_for_display (symtab));
c906108c
SS
299 if (symtab->dirname)
300 fprintf_filtered (outfile, "Compilation directory is %s\n",
301 symtab->dirname);
302 fprintf_filtered (outfile, "Read from object file %s (", objfile->name);
d4f3574e 303 gdb_print_host_address (objfile, outfile);
c906108c 304 fprintf_filtered (outfile, ")\n");
3e43a32a
MS
305 fprintf_filtered (outfile, "Language: %s\n",
306 language_str (symtab->language));
c906108c
SS
307
308 /* First print the line table. */
309 l = LINETABLE (symtab);
310 if (l)
311 {
312 fprintf_filtered (outfile, "\nLine table:\n\n");
313 len = l->nitems;
314 for (i = 0; i < len; i++)
315 {
316 fprintf_filtered (outfile, " line %d at ", l->item[i].line);
5af949e3 317 fputs_filtered (paddress (gdbarch, l->item[i].pc), outfile);
c906108c
SS
318 fprintf_filtered (outfile, "\n");
319 }
320 }
321 /* Now print the block info, but only for primary symtabs since we will
c378eb4e 322 print lots of duplicate info otherwise. */
c5aa993b 323 if (symtab->primary)
c906108c
SS
324 {
325 fprintf_filtered (outfile, "\nBlockvector:\n\n");
326 bv = BLOCKVECTOR (symtab);
327 len = BLOCKVECTOR_NBLOCKS (bv);
328 for (i = 0; i < len; i++)
329 {
330 b = BLOCKVECTOR_BLOCK (bv, i);
331 depth = block_depth (b) * 2;
332 print_spaces (depth, outfile);
333 fprintf_filtered (outfile, "block #%03d, object at ", i);
d4f3574e 334 gdb_print_host_address (b, outfile);
c906108c
SS
335 if (BLOCK_SUPERBLOCK (b))
336 {
337 fprintf_filtered (outfile, " under ");
d4f3574e 338 gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile);
c906108c 339 }
261397f8
DJ
340 /* drow/2002-07-10: We could save the total symbols count
341 even if we're using a hashtable, but nothing else but this message
342 wants it. */
de4f826b
DC
343 fprintf_filtered (outfile, ", %d syms/buckets in ",
344 dict_size (BLOCK_DICT (b)));
5af949e3 345 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), outfile);
c906108c 346 fprintf_filtered (outfile, "..");
5af949e3 347 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), outfile);
c906108c
SS
348 if (BLOCK_FUNCTION (b))
349 {
3567439c
DJ
350 fprintf_filtered (outfile, ", function %s",
351 SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b)));
c906108c
SS
352 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
353 {
354 fprintf_filtered (outfile, ", %s",
c5aa993b 355 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
c906108c
SS
356 }
357 }
c906108c 358 fprintf_filtered (outfile, "\n");
261397f8 359 /* Now print each symbol in this block (in no particular order, if
8157b174
TT
360 we're using a hashtable). Note that we only want this
361 block, not any blocks from included symtabs. */
362 ALL_DICT_SYMBOLS (BLOCK_DICT (b), iter, sym)
c906108c
SS
363 {
364 struct print_symbol_args s;
433759f7 365
5af949e3 366 s.gdbarch = gdbarch;
e88c90f2 367 s.symbol = sym;
c906108c
SS
368 s.depth = depth + 1;
369 s.outfile = outfile;
370 catch_errors (print_symbol, &s, "Error printing symbol:\n",
5c3ce3f7 371 RETURN_MASK_ERROR);
c906108c
SS
372 }
373 }
374 fprintf_filtered (outfile, "\n");
375 }
376 else
377 {
378 fprintf_filtered (outfile, "\nBlockvector same as previous symtab\n\n");
379 }
380}
381
44b164c5
JB
382static void
383dump_symtab (struct objfile *objfile, struct symtab *symtab,
384 struct ui_file *outfile)
385{
44b164c5
JB
386 /* Set the current language to the language of the symtab we're dumping
387 because certain routines used during dump_symtab() use the current
969107c5
EZ
388 language to print an image of the symbol. We'll restore it later.
389 But use only real languages, not placeholders. */
390 if (symtab->language != language_unknown
391 && symtab->language != language_auto)
392 {
393 enum language saved_lang;
394
395 saved_lang = set_language (symtab->language);
44b164c5 396
969107c5 397 dump_symtab_1 (objfile, symtab, outfile);
44b164c5 398
969107c5
EZ
399 set_language (saved_lang);
400 }
401 else
402 dump_symtab_1 (objfile, symtab, outfile);
44b164c5
JB
403}
404
80480540 405static void
fba45db2 406maintenance_print_symbols (char *args, int from_tty)
c906108c
SS
407{
408 char **argv;
d9fcf2fb 409 struct ui_file *outfile;
c906108c
SS
410 struct cleanup *cleanups;
411 char *symname = NULL;
412 char *filename = DEV_TTY;
413 struct objfile *objfile;
414 struct symtab *s;
415
416 dont_repeat ();
417
418 if (args == NULL)
419 {
3e43a32a
MS
420 error (_("Arguments missing: an output file name "
421 "and an optional symbol file name"));
c906108c 422 }
d1a41061 423 argv = gdb_buildargv (args);
7a292a7a 424 cleanups = make_cleanup_freeargv (argv);
c906108c
SS
425
426 if (argv[0] != NULL)
427 {
428 filename = argv[0];
c378eb4e 429 /* If a second arg is supplied, it is a source file name to match on. */
c906108c
SS
430 if (argv[1] != NULL)
431 {
432 symname = argv[1];
433 }
434 }
435
436 filename = tilde_expand (filename);
b8c9b27d 437 make_cleanup (xfree, filename);
c5aa993b 438
c906108c
SS
439 outfile = gdb_fopen (filename, FOPEN_WT);
440 if (outfile == 0)
441 perror_with_name (filename);
d9fcf2fb 442 make_cleanup_ui_file_delete (outfile);
c906108c 443
c906108c 444 ALL_SYMTABS (objfile, s)
27618ce4
TT
445 {
446 QUIT;
05cba821
JK
447 if (symname == NULL
448 || filename_cmp (symname, symtab_to_filename_for_display (s)) == 0)
27618ce4
TT
449 dump_symtab (objfile, s, outfile);
450 }
c906108c
SS
451 do_cleanups (cleanups);
452}
453
454/* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
455 far to indent. ARGS is really a struct print_symbol_args *, but is
456 declared as char * to get it past catch_errors. Returns 0 for error,
457 1 for success. */
458
459static int
4efb68b1 460print_symbol (void *args)
c906108c 461{
5af949e3 462 struct gdbarch *gdbarch = ((struct print_symbol_args *) args)->gdbarch;
c5aa993b
JM
463 struct symbol *symbol = ((struct print_symbol_args *) args)->symbol;
464 int depth = ((struct print_symbol_args *) args)->depth;
d9fcf2fb 465 struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile;
e27d198c
TT
466 struct obj_section *section = SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (symbol),
467 symbol);
c906108c
SS
468
469 print_spaces (depth, outfile);
176620f1 470 if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN)
c906108c 471 {
de5ad195 472 fprintf_filtered (outfile, "label %s at ", SYMBOL_PRINT_NAME (symbol));
5af949e3
UW
473 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
474 outfile);
714835d5 475 if (section)
c906108c 476 fprintf_filtered (outfile, " section %s\n",
714835d5
UW
477 bfd_section_name (section->the_bfd_section->owner,
478 section->the_bfd_section));
c906108c
SS
479 else
480 fprintf_filtered (outfile, "\n");
481 return 1;
482 }
176620f1 483 if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN)
c906108c
SS
484 {
485 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
486 {
79d43c61
TT
487 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth,
488 &type_print_raw_options);
c906108c
SS
489 }
490 else
491 {
492 fprintf_filtered (outfile, "%s %s = ",
c5aa993b
JM
493 (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
494 ? "enum"
495 : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
496 ? "struct" : "union")),
3567439c 497 SYMBOL_LINKAGE_NAME (symbol));
79d43c61
TT
498 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth,
499 &type_print_raw_options);
c906108c
SS
500 }
501 fprintf_filtered (outfile, ";\n");
502 }
503 else
504 {
505 if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
506 fprintf_filtered (outfile, "typedef ");
507 if (SYMBOL_TYPE (symbol))
508 {
509 /* Print details of types, except for enums where it's clutter. */
de5ad195 510 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_PRINT_NAME (symbol),
c906108c
SS
511 outfile,
512 TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
79d43c61
TT
513 depth,
514 &type_print_raw_options);
c906108c
SS
515 fprintf_filtered (outfile, "; ");
516 }
517 else
de5ad195 518 fprintf_filtered (outfile, "%s ", SYMBOL_PRINT_NAME (symbol));
c906108c
SS
519
520 switch (SYMBOL_CLASS (symbol))
521 {
522 case LOC_CONST:
12df843f
JK
523 fprintf_filtered (outfile, "const %s (%s)",
524 plongest (SYMBOL_VALUE (symbol)),
525 hex_string (SYMBOL_VALUE (symbol)));
c906108c
SS
526 break;
527
528 case LOC_CONST_BYTES:
529 {
530 unsigned i;
531 struct type *type = check_typedef (SYMBOL_TYPE (symbol));
433759f7 532
c906108c
SS
533 fprintf_filtered (outfile, "const %u hex bytes:",
534 TYPE_LENGTH (type));
535 for (i = 0; i < TYPE_LENGTH (type); i++)
536 fprintf_filtered (outfile, " %02x",
c5aa993b 537 (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]);
c906108c
SS
538 }
539 break;
540
541 case LOC_STATIC:
542 fprintf_filtered (outfile, "static at ");
5af949e3
UW
543 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
544 outfile);
714835d5 545 if (section)
c906108c 546 fprintf_filtered (outfile, " section %s",
714835d5
UW
547 bfd_section_name (section->the_bfd_section->owner,
548 section->the_bfd_section));
c906108c
SS
549 break;
550
c906108c 551 case LOC_REGISTER:
2a2d4dc3 552 if (SYMBOL_IS_ARGUMENT (symbol))
12df843f
JK
553 fprintf_filtered (outfile, "parameter register %s",
554 plongest (SYMBOL_VALUE (symbol)));
2a2d4dc3 555 else
12df843f
JK
556 fprintf_filtered (outfile, "register %s",
557 plongest (SYMBOL_VALUE (symbol)));
c906108c
SS
558 break;
559
560 case LOC_ARG:
12df843f
JK
561 fprintf_filtered (outfile, "arg at offset %s",
562 hex_string (SYMBOL_VALUE (symbol)));
c906108c
SS
563 break;
564
c906108c 565 case LOC_REF_ARG:
12df843f
JK
566 fprintf_filtered (outfile, "reference arg at %s",
567 hex_string (SYMBOL_VALUE (symbol)));
c906108c
SS
568 break;
569
c906108c 570 case LOC_REGPARM_ADDR:
12df843f
JK
571 fprintf_filtered (outfile, "address parameter register %s",
572 plongest (SYMBOL_VALUE (symbol)));
c906108c
SS
573 break;
574
575 case LOC_LOCAL:
12df843f
JK
576 fprintf_filtered (outfile, "local at offset %s",
577 hex_string (SYMBOL_VALUE (symbol)));
c906108c
SS
578 break;
579
c906108c
SS
580 case LOC_TYPEDEF:
581 break;
582
583 case LOC_LABEL:
584 fprintf_filtered (outfile, "label at ");
5af949e3
UW
585 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
586 outfile);
714835d5 587 if (section)
c906108c 588 fprintf_filtered (outfile, " section %s",
714835d5
UW
589 bfd_section_name (section->the_bfd_section->owner,
590 section->the_bfd_section));
c906108c
SS
591 break;
592
593 case LOC_BLOCK:
594 fprintf_filtered (outfile, "block object ");
d4f3574e 595 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
c906108c 596 fprintf_filtered (outfile, ", ");
5af949e3
UW
597 fputs_filtered (paddress (gdbarch,
598 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol))),
ed49a04f 599 outfile);
c906108c 600 fprintf_filtered (outfile, "..");
5af949e3
UW
601 fputs_filtered (paddress (gdbarch,
602 BLOCK_END (SYMBOL_BLOCK_VALUE (symbol))),
ed49a04f 603 outfile);
714835d5 604 if (section)
c906108c 605 fprintf_filtered (outfile, " section %s",
714835d5
UW
606 bfd_section_name (section->the_bfd_section->owner,
607 section->the_bfd_section));
c906108c
SS
608 break;
609
4c2df51b 610 case LOC_COMPUTED:
4c2df51b
DJ
611 fprintf_filtered (outfile, "computed at runtime");
612 break;
613
c906108c
SS
614 case LOC_UNRESOLVED:
615 fprintf_filtered (outfile, "unresolved");
616 break;
617
618 case LOC_OPTIMIZED_OUT:
619 fprintf_filtered (outfile, "optimized out");
620 break;
621
c5aa993b 622 default:
c906108c
SS
623 fprintf_filtered (outfile, "botched symbol class %x",
624 SYMBOL_CLASS (symbol));
625 break;
626 }
627 }
628 fprintf_filtered (outfile, "\n");
629 return 1;
630}
631
80480540 632static void
fba45db2 633maintenance_print_msymbols (char *args, int from_tty)
c906108c
SS
634{
635 char **argv;
d9fcf2fb 636 struct ui_file *outfile;
c906108c
SS
637 struct cleanup *cleanups;
638 char *filename = DEV_TTY;
639 char *symname = NULL;
6c95b8df 640 struct program_space *pspace;
c906108c
SS
641 struct objfile *objfile;
642
07318b29
CV
643 struct stat sym_st, obj_st;
644
c906108c
SS
645 dont_repeat ();
646
647 if (args == NULL)
648 {
3e43a32a
MS
649 error (_("print-msymbols takes an output file "
650 "name and optional symbol file name"));
c906108c 651 }
d1a41061 652 argv = gdb_buildargv (args);
7a292a7a 653 cleanups = make_cleanup_freeargv (argv);
c906108c
SS
654
655 if (argv[0] != NULL)
656 {
657 filename = argv[0];
c378eb4e 658 /* If a second arg is supplied, it is a source file name to match on. */
c906108c
SS
659 if (argv[1] != NULL)
660 {
f5b95b50 661 symname = gdb_realpath (argv[1]);
07318b29
CV
662 make_cleanup (xfree, symname);
663 if (symname && stat (symname, &sym_st))
664 perror_with_name (symname);
c906108c
SS
665 }
666 }
667
668 filename = tilde_expand (filename);
b8c9b27d 669 make_cleanup (xfree, filename);
c5aa993b 670
c906108c
SS
671 outfile = gdb_fopen (filename, FOPEN_WT);
672 if (outfile == 0)
673 perror_with_name (filename);
d9fcf2fb 674 make_cleanup_ui_file_delete (outfile);
c906108c 675
6c95b8df
PA
676 ALL_PSPACES (pspace)
677 ALL_PSPACE_OBJFILES (pspace, objfile)
27618ce4
TT
678 {
679 QUIT;
680 if (symname == NULL || (!stat (objfile->name, &obj_st)
3b74cdc3 681 && sym_st.st_dev == obj_st.st_dev
27618ce4
TT
682 && sym_st.st_ino == obj_st.st_ino))
683 dump_msymbols (objfile, outfile);
684 }
c906108c
SS
685 fprintf_filtered (outfile, "\n\n");
686 do_cleanups (cleanups);
687}
688
80480540 689static void
52e260a3 690maintenance_print_objfiles (char *regexp, int from_tty)
c906108c 691{
6c95b8df 692 struct program_space *pspace;
c906108c
SS
693 struct objfile *objfile;
694
695 dont_repeat ();
696
52e260a3
DE
697 if (regexp)
698 re_comp (regexp);
699
6c95b8df
PA
700 ALL_PSPACES (pspace)
701 ALL_PSPACE_OBJFILES (pspace, objfile)
27618ce4
TT
702 {
703 QUIT;
52e260a3
DE
704 if (! regexp
705 || re_exec (objfile->name))
706 dump_objfile (objfile);
27618ce4 707 }
c906108c
SS
708}
709
5e7b2f39 710/* List all the symbol tables whose names match REGEXP (optional). */
b5ebcee6 711
80480540 712static void
5e7b2f39 713maintenance_info_symtabs (char *regexp, int from_tty)
44ea7b70 714{
6c95b8df 715 struct program_space *pspace;
44ea7b70
JB
716 struct objfile *objfile;
717
db68bbae
DE
718 dont_repeat ();
719
44ea7b70
JB
720 if (regexp)
721 re_comp (regexp);
722
6c95b8df
PA
723 ALL_PSPACES (pspace)
724 ALL_PSPACE_OBJFILES (pspace, objfile)
44ea7b70
JB
725 {
726 struct symtab *symtab;
727
728 /* We don't want to print anything for this objfile until we
729 actually find a symtab whose name matches. */
730 int printed_objfile_start = 0;
731
732 ALL_OBJFILE_SYMTABS (objfile, symtab)
8a498d38
DE
733 {
734 QUIT;
735
736 if (! regexp
05cba821 737 || re_exec (symtab_to_filename_for_display (symtab)))
8a498d38
DE
738 {
739 if (! printed_objfile_start)
740 {
741 printf_filtered ("{ objfile %s ", objfile->name);
742 wrap_here (" ");
a74ce742
PM
743 printf_filtered ("((struct objfile *) %s)\n",
744 host_address_to_string (objfile));
8a498d38
DE
745 printed_objfile_start = 1;
746 }
747
05cba821
JK
748 printf_filtered (" { symtab %s ",
749 symtab_to_filename_for_display (symtab));
8a498d38 750 wrap_here (" ");
a74ce742
PM
751 printf_filtered ("((struct symtab *) %s)\n",
752 host_address_to_string (symtab));
8a498d38
DE
753 printf_filtered (" dirname %s\n",
754 symtab->dirname ? symtab->dirname : "(null)");
755 printf_filtered (" fullname %s\n",
756 symtab->fullname ? symtab->fullname : "(null)");
3e43a32a
MS
757 printf_filtered (" "
758 "blockvector ((struct blockvector *) %s)%s\n",
a74ce742 759 host_address_to_string (symtab->blockvector),
8a498d38 760 symtab->primary ? " (primary)" : "");
3e43a32a
MS
761 printf_filtered (" "
762 "linetable ((struct linetable *) %s)\n",
a74ce742 763 host_address_to_string (symtab->linetable));
3e43a32a
MS
764 printf_filtered (" debugformat %s\n",
765 symtab->debugformat);
8a498d38
DE
766 printf_filtered (" }\n");
767 }
768 }
44ea7b70
JB
769
770 if (printed_objfile_start)
771 printf_filtered ("}\n");
772 }
773}
7d0c9981
DE
774
775/* Check consistency of symtabs.
776 An example of what this checks for is NULL blockvectors.
777 They can happen if there's a bug during debug info reading.
778 GDB assumes they are always non-NULL.
779
780 Note: This does not check for psymtab vs symtab consistency.
781 Use "maint check-psymtabs" for that. */
782
783static void
784maintenance_check_symtabs (char *ignore, int from_tty)
785{
786 struct program_space *pspace;
787 struct objfile *objfile;
788
789 ALL_PSPACES (pspace)
790 ALL_PSPACE_OBJFILES (pspace, objfile)
791 {
792 struct symtab *symtab;
793
794 /* We don't want to print anything for this objfile until we
795 actually find something worth printing. */
796 int printed_objfile_start = 0;
797
798 ALL_OBJFILE_SYMTABS (objfile, symtab)
799 {
800 int found_something = 0;
801
802 QUIT;
803
804 if (symtab->blockvector == NULL)
805 found_something = 1;
806 /* Add more checks here. */
807
808 if (found_something)
809 {
810 if (! printed_objfile_start)
811 {
812 printf_filtered ("{ objfile %s ", objfile->name);
813 wrap_here (" ");
814 printf_filtered ("((struct objfile *) %s)\n",
815 host_address_to_string (objfile));
816 printed_objfile_start = 1;
817 }
818 printf_filtered (" { symtab %s\n",
819 symtab_to_filename_for_display (symtab));
820 if (symtab->blockvector == NULL)
821 printf_filtered (" NULL blockvector\n");
822 printf_filtered (" }\n");
823 }
824 }
825
826 if (printed_objfile_start)
827 printf_filtered ("}\n");
828 }
829}
830
831/* Helper function for maintenance_expand_symtabs.
832 This is the name_matcher function for expand_symtabs_matching. */
833
834static int
835maintenance_expand_name_matcher (const char *symname, void *data)
836{
837 /* Since we're not searching on symbols, just return TRUE. */
838 return 1;
839}
840
841/* Helper function for maintenance_expand_symtabs.
842 This is the file_matcher function for expand_symtabs_matching. */
843
844static int
845maintenance_expand_file_matcher (const char *filename, void *data,
846 int basenames)
847{
848 const char *regexp = data;
849
850 QUIT;
851
852 /* KISS: Only apply the regexp to the complete file name. */
853 if (basenames)
854 return 0;
855
856 if (regexp == NULL || re_exec (filename))
857 return 1;
858
859 return 0;
860}
861
862/* Expand all symbol tables whose name matches an optional regexp. */
863
864static void
865maintenance_expand_symtabs (char *args, int from_tty)
866{
867 struct program_space *pspace;
868 struct objfile *objfile;
869 struct cleanup *cleanups;
870 char **argv;
871 char *regexp = NULL;
872
873 /* We use buildargv here so that we handle spaces in the regexp
874 in a way that allows adding more arguments later. */
875 argv = gdb_buildargv (args);
876 cleanups = make_cleanup_freeargv (argv);
877
878 if (argv != NULL)
879 {
880 if (argv[0] != NULL)
881 {
882 regexp = argv[0];
883 if (argv[1] != NULL)
884 error (_("Extra arguments after regexp."));
885 }
886 }
887
888 if (regexp)
889 re_comp (regexp);
890
891 ALL_PSPACES (pspace)
892 ALL_PSPACE_OBJFILES (pspace, objfile)
893 {
894 if (objfile->sf)
895 {
896 objfile->sf->qf->expand_symtabs_matching
897 (objfile, maintenance_expand_file_matcher,
898 maintenance_expand_name_matcher, ALL_DOMAIN, regexp);
899 }
900 }
4e993a19
TT
901
902 do_cleanups (cleanups);
7d0c9981 903}
c906108c 904\f
c5aa993b 905
c906108c
SS
906/* Return the nexting depth of a block within other blocks in its symtab. */
907
908static int
fba45db2 909block_depth (struct block *block)
c906108c 910{
52f0bd74 911 int i = 0;
433759f7 912
c5aa993b 913 while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
c906108c
SS
914 {
915 i++;
916 }
917 return i;
918}
c906108c 919\f
c5aa993b 920
c378eb4e 921/* Do early runtime initializations. */
b5ebcee6 922
c906108c 923void
fba45db2 924_initialize_symmisc (void)
c906108c 925{
c5aa993b 926 std_in = stdin;
c906108c
SS
927 std_out = stdout;
928 std_err = stderr;
80480540
YQ
929
930 add_cmd ("symbols", class_maintenance, maintenance_print_symbols, _("\
931Print dump of current symbol definitions.\n\
932Entries in the full symbol table are dumped to file OUTFILE.\n\
933If a SOURCE file is specified, dump only that file's symbols."),
934 &maintenanceprintlist);
935
936 add_cmd ("msymbols", class_maintenance, maintenance_print_msymbols, _("\
937Print dump of current minimal symbol definitions.\n\
938Entries in the minimal symbol table are dumped to file OUTFILE.\n\
939If a SOURCE file is specified, dump only that file's minimal symbols."),
940 &maintenanceprintlist);
941
942 add_cmd ("objfiles", class_maintenance, maintenance_print_objfiles,
52e260a3
DE
943 _("Print dump of current object file definitions.\n\
944With an argument REGEXP, list the object files with matching names."),
80480540
YQ
945 &maintenanceprintlist);
946
947 add_cmd ("symtabs", class_maintenance, maintenance_info_symtabs, _("\
948List the full symbol tables for all object files.\n\
949This does not include information about individual symbols, blocks, or\n\
950linetables --- just the symbol table structures themselves.\n\
db68bbae 951With an argument REGEXP, list the symbol tables with matching names."),
80480540 952 &maintenanceinfolist);
7d0c9981
DE
953
954 add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs,
955 _("\
956Check consistency of currently expanded symtabs."),
957 &maintenancelist);
958
959 add_cmd ("expand-symtabs", class_maintenance, maintenance_expand_symtabs,
960 _("Expand symbol tables.\n\
961With an argument REGEXP, only expand the symbol tables with matching names."),
962 &maintenancelist);
c906108c 963}
This page took 1.415241 seconds and 4 git commands to generate.