Thread language through c_type_print_args
[deliverable/binutils-gdb.git] / gdb / symmisc.c
CommitLineData
c906108c 1/* Do various things to symbol tables (other than lookup), for GDB.
af5f3db6 2
e2882c85 3 Copyright (C) 1986-2018 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"
c906108c
SS
30#include "language.h"
31#include "bcache.h"
fe898f56 32#include "block.h"
44ea7b70 33#include "gdb_regex.h"
53ce3c39 34#include <sys/stat.h>
de4f826b 35#include "dictionary.h"
79d43c61 36#include "typeprint.h"
80480540 37#include "gdbcmd.h"
05cba821 38#include "source.h"
dbda9972 39#include "readline/readline.h"
c906108c 40
ccefe4c4
TT
41#include "psymtab.h"
42
c906108c
SS
43/* Unfortunately for debugging, stderr is usually a macro. This is painful
44 when calling functions that take FILE *'s from the debugger.
45 So we make a variable which has the same value and which is accessible when
46 debugging GDB with itself. Because stdin et al need not be constants,
47 we initialize them in the _initialize_symmisc function at the bottom
48 of the file. */
49FILE *std_in;
50FILE *std_out;
51FILE *std_err;
52
53/* Prototypes for local functions */
54
a14ed312 55static int block_depth (struct block *);
c906108c 56
bf469271
PA
57static void print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
58 int depth, ui_file *outfile);
c906108c 59\f
c906108c 60
c906108c 61void
fba45db2 62print_symbol_bcache_statistics (void)
c906108c 63{
6c95b8df 64 struct program_space *pspace;
c906108c
SS
65 struct objfile *objfile;
66
6c95b8df
PA
67 ALL_PSPACES (pspace)
68 ALL_PSPACE_OBJFILES (pspace, objfile)
c5aa993b 69 {
27618ce4 70 QUIT;
4262abfb
JK
71 printf_filtered (_("Byte cache statistics for '%s':\n"),
72 objfile_name (objfile));
710e1a31
SW
73 print_bcache_statistics (psymbol_bcache_get_bcache (objfile->psymbol_cache),
74 "partial symbol cache");
6532ff36
TT
75 print_bcache_statistics (objfile->per_bfd->macro_cache,
76 "preprocessor macro cache");
706e3705
TT
77 print_bcache_statistics (objfile->per_bfd->filename_cache,
78 "file name cache");
c5aa993b 79 }
c906108c
SS
80}
81
82void
fba45db2 83print_objfile_statistics (void)
c906108c 84{
6c95b8df 85 struct program_space *pspace;
c906108c 86 struct objfile *objfile;
43f3e411 87 struct compunit_symtab *cu;
c4f90d87 88 struct symtab *s;
c4f90d87 89 int i, linetables, blockvectors;
c906108c 90
6c95b8df
PA
91 ALL_PSPACES (pspace)
92 ALL_PSPACE_OBJFILES (pspace, objfile)
c5aa993b 93 {
27618ce4 94 QUIT;
4262abfb 95 printf_filtered (_("Statistics for '%s':\n"), objfile_name (objfile));
c5aa993b 96 if (OBJSTAT (objfile, n_stabs) > 0)
a3f17187 97 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
c5aa993b 98 OBJSTAT (objfile, n_stabs));
5f6cac40 99 if (objfile->per_bfd->n_minsyms > 0)
a3f17187 100 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
5f6cac40 101 objfile->per_bfd->n_minsyms);
c5aa993b 102 if (OBJSTAT (objfile, n_psyms) > 0)
a3f17187 103 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
c5aa993b
JM
104 OBJSTAT (objfile, n_psyms));
105 if (OBJSTAT (objfile, n_syms) > 0)
a3f17187 106 printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
c5aa993b
JM
107 OBJSTAT (objfile, n_syms));
108 if (OBJSTAT (objfile, n_types) > 0)
a3f17187 109 printf_filtered (_(" Number of \"types\" defined: %d\n"),
c5aa993b 110 OBJSTAT (objfile, n_types));
ccefe4c4
TT
111 if (objfile->sf)
112 objfile->sf->qf->print_stats (objfile);
c4f90d87 113 i = linetables = blockvectors = 0;
43f3e411 114 ALL_OBJFILE_FILETABS (objfile, cu, s)
c4f90d87
JM
115 {
116 i++;
8435453b 117 if (SYMTAB_LINETABLE (s) != NULL)
c4f90d87 118 linetables++;
c4f90d87 119 }
43f3e411
DE
120 ALL_OBJFILE_COMPUNITS (objfile, cu)
121 blockvectors++;
a3f17187 122 printf_filtered (_(" Number of symbol tables: %d\n"), i);
26a84859 123 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
c4f90d87 124 linetables);
26a84859 125 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
c4f90d87 126 blockvectors);
26a84859 127
c5aa993b 128 if (OBJSTAT (objfile, sz_strtab) > 0)
1736a7bd 129 printf_filtered (_(" Space used by string tables: %d\n"),
c5aa993b 130 OBJSTAT (objfile, sz_strtab));
241fd515
AM
131 printf_filtered (_(" Total memory used for objfile obstack: %s\n"),
132 pulongest (obstack_memory_used (&objfile
133 ->objfile_obstack)));
134 printf_filtered (_(" Total memory used for BFD obstack: %s\n"),
135 pulongest (obstack_memory_used (&objfile->per_bfd
136 ->storage_obstack)));
a3f17187 137 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
710e1a31
SW
138 bcache_memory_used (psymbol_bcache_get_bcache
139 (objfile->psymbol_cache)));
a3f17187 140 printf_filtered (_(" Total memory used for macro cache: %d\n"),
6532ff36 141 bcache_memory_used (objfile->per_bfd->macro_cache));
10abe6bf 142 printf_filtered (_(" Total memory used for file name cache: %d\n"),
706e3705 143 bcache_memory_used (objfile->per_bfd->filename_cache));
c5aa993b 144 }
c906108c
SS
145}
146
c5aa993b 147static void
fba45db2 148dump_objfile (struct objfile *objfile)
c906108c 149{
43f3e411 150 struct compunit_symtab *cust;
c906108c 151 struct symtab *symtab;
c906108c 152
4262abfb 153 printf_filtered ("\nObject file %s: ", objfile_name (objfile));
c906108c 154 printf_filtered ("Objfile at ");
d4f3574e 155 gdb_print_host_address (objfile, gdb_stdout);
c906108c 156 printf_filtered (", bfd at ");
d4f3574e 157 gdb_print_host_address (objfile->obfd, gdb_stdout);
c906108c 158 printf_filtered (", %d minsyms\n\n",
34643a32 159 objfile->per_bfd->minimal_symbol_count);
c906108c 160
ccefe4c4
TT
161 if (objfile->sf)
162 objfile->sf->qf->dump (objfile);
c906108c 163
43f3e411 164 if (objfile->compunit_symtabs != NULL)
c906108c
SS
165 {
166 printf_filtered ("Symtabs:\n");
43f3e411 167 ALL_OBJFILE_FILETABS (objfile, cust, symtab)
c906108c 168 {
05cba821 169 printf_filtered ("%s at ", symtab_to_filename_for_display (symtab));
d4f3574e 170 gdb_print_host_address (symtab, gdb_stdout);
c906108c 171 printf_filtered (", ");
eb822aa6 172 if (SYMTAB_OBJFILE (symtab) != objfile)
c906108c
SS
173 {
174 printf_filtered ("NOT ON CHAIN! ");
175 }
176 wrap_here (" ");
177 }
178 printf_filtered ("\n\n");
179 }
180}
181
182/* Print minimal symbols from this objfile. */
c5aa993b
JM
183
184static void
fba45db2 185dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
c906108c 186{
5af949e3 187 struct gdbarch *gdbarch = get_objfile_arch (objfile);
c906108c
SS
188 struct minimal_symbol *msymbol;
189 int index;
190 char ms_type;
c5aa993b 191
4262abfb 192 fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile_name (objfile));
34643a32 193 if (objfile->per_bfd->minimal_symbol_count == 0)
c906108c
SS
194 {
195 fprintf_filtered (outfile, "No minimal symbols found.\n");
196 return;
197 }
3567439c
DJ
198 index = 0;
199 ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
c906108c 200 {
efd66ac6 201 struct obj_section *section = MSYMBOL_OBJ_SECTION (objfile, msymbol);
714835d5 202
712f90be 203 switch (MSYMBOL_TYPE (msymbol))
c906108c 204 {
c5aa993b
JM
205 case mst_unknown:
206 ms_type = 'u';
207 break;
208 case mst_text:
209 ms_type = 'T';
210 break;
0875794a 211 case mst_text_gnu_ifunc:
f50776aa 212 case mst_data_gnu_ifunc:
0875794a
JK
213 ms_type = 'i';
214 break;
c5aa993b
JM
215 case mst_solib_trampoline:
216 ms_type = 'S';
217 break;
218 case mst_data:
219 ms_type = 'D';
220 break;
221 case mst_bss:
222 ms_type = 'B';
223 break;
224 case mst_abs:
225 ms_type = 'A';
226 break;
227 case mst_file_text:
228 ms_type = 't';
229 break;
230 case mst_file_data:
231 ms_type = 'd';
232 break;
233 case mst_file_bss:
234 ms_type = 'b';
235 break;
236 default:
237 ms_type = '?';
238 break;
c906108c
SS
239 }
240 fprintf_filtered (outfile, "[%2d] %c ", index, ms_type);
77e371c0
TT
241 fputs_filtered (paddress (gdbarch, MSYMBOL_VALUE_ADDRESS (objfile,
242 msymbol)),
5af949e3 243 outfile);
efd66ac6 244 fprintf_filtered (outfile, " %s", MSYMBOL_LINKAGE_NAME (msymbol));
714835d5 245 if (section)
8625fc1b
TT
246 {
247 if (section->the_bfd_section != NULL)
248 fprintf_filtered (outfile, " section %s",
249 bfd_section_name (objfile->obfd,
250 section->the_bfd_section));
251 else
252 fprintf_filtered (outfile, " spurious section %ld",
4c8429ef 253 (long) (section - objfile->sections));
8625fc1b 254 }
efd66ac6 255 if (MSYMBOL_DEMANGLED_NAME (msymbol) != NULL)
c906108c 256 {
efd66ac6 257 fprintf_filtered (outfile, " %s", MSYMBOL_DEMANGLED_NAME (msymbol));
c906108c 258 }
c906108c
SS
259 if (msymbol->filename)
260 fprintf_filtered (outfile, " %s", msymbol->filename);
c906108c 261 fputs_filtered ("\n", outfile);
3567439c 262 index++;
c906108c 263 }
34643a32 264 if (objfile->per_bfd->minimal_symbol_count != index)
c906108c 265 {
8a3fe4f8 266 warning (_("internal error: minimal symbol count %d != %d"),
34643a32 267 objfile->per_bfd->minimal_symbol_count, index);
c906108c
SS
268 }
269 fprintf_filtered (outfile, "\n");
270}
271
c5aa993b 272static void
d04c1a59 273dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
c906108c 274{
d04c1a59 275 struct objfile *objfile = SYMTAB_OBJFILE (symtab);
5af949e3 276 struct gdbarch *gdbarch = get_objfile_arch (objfile);
de4f826b
DC
277 int i;
278 struct dict_iterator iter;
952a6d41 279 int len;
de4f826b 280 struct linetable *l;
346d1dfe 281 const struct blockvector *bv;
e88c90f2 282 struct symbol *sym;
de4f826b 283 struct block *b;
c906108c
SS
284 int depth;
285
05cba821
JK
286 fprintf_filtered (outfile, "\nSymtab for file %s\n",
287 symtab_to_filename_for_display (symtab));
ee6f8984 288 if (SYMTAB_DIRNAME (symtab) != NULL)
c906108c 289 fprintf_filtered (outfile, "Compilation directory is %s\n",
ee6f8984 290 SYMTAB_DIRNAME (symtab));
4262abfb
JK
291 fprintf_filtered (outfile, "Read from object file %s (",
292 objfile_name (objfile));
d4f3574e 293 gdb_print_host_address (objfile, outfile);
c906108c 294 fprintf_filtered (outfile, ")\n");
3e43a32a
MS
295 fprintf_filtered (outfile, "Language: %s\n",
296 language_str (symtab->language));
c906108c
SS
297
298 /* First print the line table. */
8435453b 299 l = SYMTAB_LINETABLE (symtab);
c906108c
SS
300 if (l)
301 {
302 fprintf_filtered (outfile, "\nLine table:\n\n");
303 len = l->nitems;
304 for (i = 0; i < len; i++)
305 {
306 fprintf_filtered (outfile, " line %d at ", l->item[i].line);
5af949e3 307 fputs_filtered (paddress (gdbarch, l->item[i].pc), outfile);
c906108c
SS
308 fprintf_filtered (outfile, "\n");
309 }
310 }
43f3e411 311 /* Now print the block info, but only for compunit symtabs since we will
c378eb4e 312 print lots of duplicate info otherwise. */
43f3e411 313 if (symtab == COMPUNIT_FILETABS (SYMTAB_COMPUNIT (symtab)))
c906108c
SS
314 {
315 fprintf_filtered (outfile, "\nBlockvector:\n\n");
439247b6 316 bv = SYMTAB_BLOCKVECTOR (symtab);
c906108c
SS
317 len = BLOCKVECTOR_NBLOCKS (bv);
318 for (i = 0; i < len; i++)
319 {
320 b = BLOCKVECTOR_BLOCK (bv, i);
321 depth = block_depth (b) * 2;
322 print_spaces (depth, outfile);
323 fprintf_filtered (outfile, "block #%03d, object at ", i);
d4f3574e 324 gdb_print_host_address (b, outfile);
c906108c
SS
325 if (BLOCK_SUPERBLOCK (b))
326 {
327 fprintf_filtered (outfile, " under ");
d4f3574e 328 gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile);
c906108c 329 }
261397f8
DJ
330 /* drow/2002-07-10: We could save the total symbols count
331 even if we're using a hashtable, but nothing else but this message
332 wants it. */
de4f826b
DC
333 fprintf_filtered (outfile, ", %d syms/buckets in ",
334 dict_size (BLOCK_DICT (b)));
5af949e3 335 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), outfile);
c906108c 336 fprintf_filtered (outfile, "..");
5af949e3 337 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), outfile);
c906108c
SS
338 if (BLOCK_FUNCTION (b))
339 {
3567439c
DJ
340 fprintf_filtered (outfile, ", function %s",
341 SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b)));
c906108c
SS
342 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
343 {
344 fprintf_filtered (outfile, ", %s",
c5aa993b 345 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
c906108c
SS
346 }
347 }
c906108c 348 fprintf_filtered (outfile, "\n");
261397f8 349 /* Now print each symbol in this block (in no particular order, if
8157b174
TT
350 we're using a hashtable). Note that we only want this
351 block, not any blocks from included symtabs. */
352 ALL_DICT_SYMBOLS (BLOCK_DICT (b), iter, sym)
c906108c 353 {
bf469271
PA
354 TRY
355 {
356 print_symbol (gdbarch, sym, depth + 1, outfile);
357 }
358 CATCH (ex, RETURN_MASK_ERROR)
359 {
360 exception_fprintf (gdb_stderr, ex,
361 "Error printing symbol:\n");
362 }
363 END_CATCH
c906108c
SS
364 }
365 }
366 fprintf_filtered (outfile, "\n");
367 }
368 else
369 {
6c739336
DE
370 const char *compunit_filename
371 = symtab_to_filename_for_display (COMPUNIT_FILETABS (SYMTAB_COMPUNIT (symtab)));
372
373 fprintf_filtered (outfile,
374 "\nBlockvector same as owning compunit: %s\n\n",
375 compunit_filename);
c906108c
SS
376 }
377}
378
44b164c5 379static void
d04c1a59 380dump_symtab (struct symtab *symtab, struct ui_file *outfile)
44b164c5 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
d04c1a59 393 dump_symtab_1 (symtab, outfile);
44b164c5 394
969107c5
EZ
395 set_language (saved_lang);
396 }
397 else
d04c1a59 398 dump_symtab_1 (symtab, outfile);
44b164c5
JB
399}
400
80480540 401static void
e99c83e7 402maintenance_print_symbols (const char *args, int from_tty)
c906108c 403{
34c41c68 404 struct ui_file *outfile = gdb_stdout;
34c41c68
DE
405 char *address_arg = NULL, *source_arg = NULL, *objfile_arg = NULL;
406 int i, outfile_idx;
c906108c
SS
407
408 dont_repeat ();
409
773a1edc 410 gdb_argv argv (args);
c906108c 411
99e8a4f9 412 for (i = 0; argv != NULL && argv[i] != NULL; ++i)
c906108c 413 {
34c41c68
DE
414 if (strcmp (argv[i], "-pc") == 0)
415 {
416 if (argv[i + 1] == NULL)
417 error (_("Missing pc value"));
418 address_arg = argv[++i];
419 }
420 else if (strcmp (argv[i], "-source") == 0)
421 {
422 if (argv[i + 1] == NULL)
423 error (_("Missing source file"));
424 source_arg = argv[++i];
425 }
426 else if (strcmp (argv[i], "-objfile") == 0)
427 {
428 if (argv[i + 1] == NULL)
429 error (_("Missing objfile name"));
430 objfile_arg = argv[++i];
431 }
432 else if (strcmp (argv[i], "--") == 0)
433 {
434 /* End of options. */
435 ++i;
436 break;
437 }
438 else if (argv[i][0] == '-')
c906108c 439 {
34c41c68
DE
440 /* Future proofing: Don't allow OUTFILE to begin with "-". */
441 error (_("Unknown option: %s"), argv[i]);
c906108c 442 }
34c41c68
DE
443 else
444 break;
c906108c 445 }
34c41c68 446 outfile_idx = i;
c906108c 447
34c41c68
DE
448 if (address_arg != NULL && source_arg != NULL)
449 error (_("Must specify at most one of -pc and -source"));
c5aa993b 450
d7e74731
PA
451 stdio_file arg_outfile;
452
99e8a4f9 453 if (argv != NULL && argv[outfile_idx] != NULL)
34c41c68 454 {
34c41c68
DE
455 if (argv[outfile_idx + 1] != NULL)
456 error (_("Junk at end of command"));
ee0c3293
TT
457 gdb::unique_xmalloc_ptr<char> outfile_name
458 (tilde_expand (argv[outfile_idx]));
459 if (!arg_outfile.open (outfile_name.get (), FOPEN_WT))
460 perror_with_name (outfile_name.get ());
d7e74731 461 outfile = &arg_outfile;
34c41c68 462 }
c906108c 463
34c41c68 464 if (address_arg != NULL)
27618ce4 465 {
34c41c68
DE
466 CORE_ADDR pc = parse_and_eval_address (address_arg);
467 struct symtab *s = find_pc_line_symtab (pc);
468
469 if (s == NULL)
470 error (_("No symtab for address: %s"), address_arg);
471 dump_symtab (s, outfile);
27618ce4 472 }
34c41c68
DE
473 else
474 {
475 struct objfile *objfile;
476 struct compunit_symtab *cu;
477 struct symtab *s;
478 int found = 0;
479
480 ALL_OBJFILES (objfile)
481 {
482 int print_for_objfile = 1;
483
484 if (objfile_arg != NULL)
485 print_for_objfile
486 = compare_filenames_for_search (objfile_name (objfile),
487 objfile_arg);
488 if (!print_for_objfile)
489 continue;
490
491 ALL_OBJFILE_FILETABS (objfile, cu, s)
492 {
493 int print_for_source = 0;
494
495 QUIT;
496 if (source_arg != NULL)
497 {
498 print_for_source
499 = compare_filenames_for_search
500 (symtab_to_filename_for_display (s), source_arg);
501 found = 1;
502 }
503 if (source_arg == NULL
504 || print_for_source)
505 dump_symtab (s, outfile);
506 }
507 }
508
509 if (source_arg != NULL && !found)
510 error (_("No symtab for source file: %s"), source_arg);
511 }
c906108c
SS
512}
513
bf469271 514/* Print symbol SYMBOL on OUTFILE. DEPTH says how far to indent. */
c906108c 515
bf469271
PA
516static void
517print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
518 int depth, ui_file *outfile)
c906108c 519{
1994afbf
DE
520 struct obj_section *section;
521
522 if (SYMBOL_OBJFILE_OWNED (symbol))
523 section = SYMBOL_OBJ_SECTION (symbol_objfile (symbol), symbol);
524 else
525 section = NULL;
c906108c
SS
526
527 print_spaces (depth, outfile);
176620f1 528 if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN)
c906108c 529 {
de5ad195 530 fprintf_filtered (outfile, "label %s at ", SYMBOL_PRINT_NAME (symbol));
5af949e3
UW
531 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
532 outfile);
714835d5 533 if (section)
c906108c 534 fprintf_filtered (outfile, " section %s\n",
714835d5
UW
535 bfd_section_name (section->the_bfd_section->owner,
536 section->the_bfd_section));
c906108c
SS
537 else
538 fprintf_filtered (outfile, "\n");
bf469271 539 return;
c906108c 540 }
bf469271 541
176620f1 542 if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN)
c906108c
SS
543 {
544 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
545 {
79d43c61
TT
546 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth,
547 &type_print_raw_options);
c906108c
SS
548 }
549 else
550 {
551 fprintf_filtered (outfile, "%s %s = ",
c5aa993b
JM
552 (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
553 ? "enum"
554 : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
555 ? "struct" : "union")),
3567439c 556 SYMBOL_LINKAGE_NAME (symbol));
79d43c61
TT
557 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth,
558 &type_print_raw_options);
c906108c
SS
559 }
560 fprintf_filtered (outfile, ";\n");
561 }
562 else
563 {
564 if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
565 fprintf_filtered (outfile, "typedef ");
566 if (SYMBOL_TYPE (symbol))
567 {
568 /* Print details of types, except for enums where it's clutter. */
de5ad195 569 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_PRINT_NAME (symbol),
c906108c
SS
570 outfile,
571 TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
79d43c61
TT
572 depth,
573 &type_print_raw_options);
c906108c
SS
574 fprintf_filtered (outfile, "; ");
575 }
576 else
de5ad195 577 fprintf_filtered (outfile, "%s ", SYMBOL_PRINT_NAME (symbol));
c906108c
SS
578
579 switch (SYMBOL_CLASS (symbol))
580 {
581 case LOC_CONST:
12df843f
JK
582 fprintf_filtered (outfile, "const %s (%s)",
583 plongest (SYMBOL_VALUE (symbol)),
584 hex_string (SYMBOL_VALUE (symbol)));
c906108c
SS
585 break;
586
587 case LOC_CONST_BYTES:
588 {
589 unsigned i;
590 struct type *type = check_typedef (SYMBOL_TYPE (symbol));
433759f7 591
c906108c
SS
592 fprintf_filtered (outfile, "const %u hex bytes:",
593 TYPE_LENGTH (type));
594 for (i = 0; i < TYPE_LENGTH (type); i++)
595 fprintf_filtered (outfile, " %02x",
c5aa993b 596 (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]);
c906108c
SS
597 }
598 break;
599
600 case LOC_STATIC:
601 fprintf_filtered (outfile, "static at ");
5af949e3
UW
602 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
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
c906108c 610 case LOC_REGISTER:
2a2d4dc3 611 if (SYMBOL_IS_ARGUMENT (symbol))
12df843f
JK
612 fprintf_filtered (outfile, "parameter register %s",
613 plongest (SYMBOL_VALUE (symbol)));
2a2d4dc3 614 else
12df843f
JK
615 fprintf_filtered (outfile, "register %s",
616 plongest (SYMBOL_VALUE (symbol)));
c906108c
SS
617 break;
618
619 case LOC_ARG:
12df843f
JK
620 fprintf_filtered (outfile, "arg at offset %s",
621 hex_string (SYMBOL_VALUE (symbol)));
c906108c
SS
622 break;
623
c906108c 624 case LOC_REF_ARG:
12df843f
JK
625 fprintf_filtered (outfile, "reference arg at %s",
626 hex_string (SYMBOL_VALUE (symbol)));
c906108c
SS
627 break;
628
c906108c 629 case LOC_REGPARM_ADDR:
12df843f
JK
630 fprintf_filtered (outfile, "address parameter register %s",
631 plongest (SYMBOL_VALUE (symbol)));
c906108c
SS
632 break;
633
634 case LOC_LOCAL:
12df843f
JK
635 fprintf_filtered (outfile, "local at offset %s",
636 hex_string (SYMBOL_VALUE (symbol)));
c906108c
SS
637 break;
638
c906108c
SS
639 case LOC_TYPEDEF:
640 break;
641
642 case LOC_LABEL:
643 fprintf_filtered (outfile, "label at ");
5af949e3
UW
644 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
645 outfile);
714835d5 646 if (section)
c906108c 647 fprintf_filtered (outfile, " section %s",
714835d5
UW
648 bfd_section_name (section->the_bfd_section->owner,
649 section->the_bfd_section));
c906108c
SS
650 break;
651
652 case LOC_BLOCK:
653 fprintf_filtered (outfile, "block object ");
d4f3574e 654 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
c906108c 655 fprintf_filtered (outfile, ", ");
5af949e3
UW
656 fputs_filtered (paddress (gdbarch,
657 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol))),
ed49a04f 658 outfile);
c906108c 659 fprintf_filtered (outfile, "..");
5af949e3
UW
660 fputs_filtered (paddress (gdbarch,
661 BLOCK_END (SYMBOL_BLOCK_VALUE (symbol))),
ed49a04f 662 outfile);
714835d5 663 if (section)
c906108c 664 fprintf_filtered (outfile, " section %s",
714835d5
UW
665 bfd_section_name (section->the_bfd_section->owner,
666 section->the_bfd_section));
c906108c
SS
667 break;
668
4c2df51b 669 case LOC_COMPUTED:
4c2df51b
DJ
670 fprintf_filtered (outfile, "computed at runtime");
671 break;
672
c906108c
SS
673 case LOC_UNRESOLVED:
674 fprintf_filtered (outfile, "unresolved");
675 break;
676
677 case LOC_OPTIMIZED_OUT:
678 fprintf_filtered (outfile, "optimized out");
679 break;
680
c5aa993b 681 default:
c906108c
SS
682 fprintf_filtered (outfile, "botched symbol class %x",
683 SYMBOL_CLASS (symbol));
684 break;
685 }
686 }
687 fprintf_filtered (outfile, "\n");
c906108c
SS
688}
689
80480540 690static void
e99c83e7 691maintenance_print_msymbols (const char *args, int from_tty)
c906108c 692{
34c41c68 693 struct ui_file *outfile = gdb_stdout;
34c41c68 694 char *objfile_arg = NULL;
c906108c 695 struct objfile *objfile;
34c41c68 696 int i, outfile_idx;
07318b29 697
c906108c
SS
698 dont_repeat ();
699
773a1edc 700 gdb_argv argv (args);
c906108c 701
99e8a4f9 702 for (i = 0; argv != NULL && argv[i] != NULL; ++i)
c906108c 703 {
34c41c68 704 if (strcmp (argv[i], "-objfile") == 0)
c906108c 705 {
34c41c68
DE
706 if (argv[i + 1] == NULL)
707 error (_("Missing objfile name"));
708 objfile_arg = argv[++i];
709 }
710 else if (strcmp (argv[i], "--") == 0)
711 {
712 /* End of options. */
713 ++i;
714 break;
c906108c 715 }
34c41c68
DE
716 else if (argv[i][0] == '-')
717 {
718 /* Future proofing: Don't allow OUTFILE to begin with "-". */
719 error (_("Unknown option: %s"), argv[i]);
720 }
721 else
722 break;
c906108c 723 }
34c41c68 724 outfile_idx = i;
c906108c 725
d7e74731
PA
726 stdio_file arg_outfile;
727
99e8a4f9 728 if (argv != NULL && argv[outfile_idx] != NULL)
34c41c68 729 {
34c41c68
DE
730 if (argv[outfile_idx + 1] != NULL)
731 error (_("Junk at end of command"));
ee0c3293
TT
732 gdb::unique_xmalloc_ptr<char> outfile_name
733 (tilde_expand (argv[outfile_idx]));
734 if (!arg_outfile.open (outfile_name.get (), FOPEN_WT))
735 perror_with_name (outfile_name.get ());
d7e74731 736 outfile = &arg_outfile;
34c41c68 737 }
c5aa993b 738
34c41c68
DE
739 ALL_OBJFILES (objfile)
740 {
741 QUIT;
742 if (objfile_arg == NULL
743 || compare_filenames_for_search (objfile_name (objfile), objfile_arg))
744 dump_msymbols (objfile, outfile);
745 }
c906108c
SS
746}
747
80480540 748static void
e99c83e7 749maintenance_print_objfiles (const char *regexp, int from_tty)
c906108c 750{
6c95b8df 751 struct program_space *pspace;
c906108c
SS
752 struct objfile *objfile;
753
754 dont_repeat ();
755
52e260a3
DE
756 if (regexp)
757 re_comp (regexp);
758
6c95b8df
PA
759 ALL_PSPACES (pspace)
760 ALL_PSPACE_OBJFILES (pspace, objfile)
27618ce4
TT
761 {
762 QUIT;
52e260a3 763 if (! regexp
4262abfb 764 || re_exec (objfile_name (objfile)))
52e260a3 765 dump_objfile (objfile);
27618ce4 766 }
c906108c
SS
767}
768
5e7b2f39 769/* List all the symbol tables whose names match REGEXP (optional). */
b5ebcee6 770
80480540 771static void
e99c83e7 772maintenance_info_symtabs (const char *regexp, int from_tty)
44ea7b70 773{
6c95b8df 774 struct program_space *pspace;
44ea7b70
JB
775 struct objfile *objfile;
776
db68bbae
DE
777 dont_repeat ();
778
44ea7b70
JB
779 if (regexp)
780 re_comp (regexp);
781
6c95b8df
PA
782 ALL_PSPACES (pspace)
783 ALL_PSPACE_OBJFILES (pspace, objfile)
44ea7b70 784 {
43f3e411 785 struct compunit_symtab *cust;
44ea7b70 786 struct symtab *symtab;
26a84859 787
44ea7b70
JB
788 /* We don't want to print anything for this objfile until we
789 actually find a symtab whose name matches. */
790 int printed_objfile_start = 0;
791
43f3e411 792 ALL_OBJFILE_COMPUNITS (objfile, cust)
8a498d38 793 {
43f3e411 794 int printed_compunit_symtab_start = 0;
8a498d38 795
43f3e411 796 ALL_COMPUNIT_FILETABS (cust, symtab)
8a498d38 797 {
43f3e411
DE
798 QUIT;
799
800 if (! regexp
801 || re_exec (symtab_to_filename_for_display (symtab)))
8a498d38 802 {
43f3e411
DE
803 if (! printed_objfile_start)
804 {
805 printf_filtered ("{ objfile %s ", objfile_name (objfile));
806 wrap_here (" ");
807 printf_filtered ("((struct objfile *) %s)\n",
808 host_address_to_string (objfile));
809 printed_objfile_start = 1;
810 }
811 if (! printed_compunit_symtab_start)
812 {
813 printf_filtered (" { ((struct compunit_symtab *) %s)\n",
814 host_address_to_string (cust));
815 printf_filtered (" debugformat %s\n",
816 COMPUNIT_DEBUGFORMAT (cust));
817 printf_filtered (" producer %s\n",
818 COMPUNIT_PRODUCER (cust) != NULL
819 ? COMPUNIT_PRODUCER (cust)
820 : "(null)");
821 printf_filtered (" dirname %s\n",
822 COMPUNIT_DIRNAME (cust) != NULL
823 ? COMPUNIT_DIRNAME (cust)
824 : "(null)");
825 printf_filtered (" blockvector"
826 " ((struct blockvector *) %s)\n",
827 host_address_to_string
828 (COMPUNIT_BLOCKVECTOR (cust)));
829 printed_compunit_symtab_start = 1;
830 }
831
832 printf_filtered ("\t{ symtab %s ",
833 symtab_to_filename_for_display (symtab));
834 wrap_here (" ");
835 printf_filtered ("((struct symtab *) %s)\n",
836 host_address_to_string (symtab));
837 printf_filtered ("\t fullname %s\n",
838 symtab->fullname != NULL
839 ? symtab->fullname
840 : "(null)");
841 printf_filtered ("\t "
842 "linetable ((struct linetable *) %s)\n",
843 host_address_to_string (symtab->linetable));
844 printf_filtered ("\t}\n");
8a498d38 845 }
8a498d38 846 }
43f3e411
DE
847
848 if (printed_compunit_symtab_start)
849 printf_filtered (" }\n");
8a498d38 850 }
44ea7b70
JB
851
852 if (printed_objfile_start)
853 printf_filtered ("}\n");
854 }
855}
7d0c9981
DE
856
857/* Check consistency of symtabs.
858 An example of what this checks for is NULL blockvectors.
859 They can happen if there's a bug during debug info reading.
860 GDB assumes they are always non-NULL.
861
862 Note: This does not check for psymtab vs symtab consistency.
863 Use "maint check-psymtabs" for that. */
864
865static void
e99c83e7 866maintenance_check_symtabs (const char *ignore, int from_tty)
7d0c9981
DE
867{
868 struct program_space *pspace;
869 struct objfile *objfile;
870
871 ALL_PSPACES (pspace)
872 ALL_PSPACE_OBJFILES (pspace, objfile)
873 {
43f3e411 874 struct compunit_symtab *cust;
7d0c9981
DE
875
876 /* We don't want to print anything for this objfile until we
877 actually find something worth printing. */
878 int printed_objfile_start = 0;
879
43f3e411 880 ALL_OBJFILE_COMPUNITS (objfile, cust)
7d0c9981
DE
881 {
882 int found_something = 0;
43f3e411 883 struct symtab *symtab = compunit_primary_filetab (cust);
7d0c9981
DE
884
885 QUIT;
886
43f3e411 887 if (COMPUNIT_BLOCKVECTOR (cust) == NULL)
7d0c9981
DE
888 found_something = 1;
889 /* Add more checks here. */
890
891 if (found_something)
892 {
893 if (! printed_objfile_start)
894 {
4262abfb 895 printf_filtered ("{ objfile %s ", objfile_name (objfile));
7d0c9981 896 wrap_here (" ");
26a84859 897 printf_filtered ("((struct objfile *) %s)\n",
7d0c9981
DE
898 host_address_to_string (objfile));
899 printed_objfile_start = 1;
900 }
901 printf_filtered (" { symtab %s\n",
902 symtab_to_filename_for_display (symtab));
43f3e411 903 if (COMPUNIT_BLOCKVECTOR (cust) == NULL)
7d0c9981
DE
904 printf_filtered (" NULL blockvector\n");
905 printf_filtered (" }\n");
906 }
907 }
908
909 if (printed_objfile_start)
910 printf_filtered ("}\n");
911 }
912}
913
7d0c9981
DE
914/* Expand all symbol tables whose name matches an optional regexp. */
915
916static void
e99c83e7 917maintenance_expand_symtabs (const char *args, int from_tty)
7d0c9981
DE
918{
919 struct program_space *pspace;
920 struct objfile *objfile;
7d0c9981
DE
921 char *regexp = NULL;
922
923 /* We use buildargv here so that we handle spaces in the regexp
924 in a way that allows adding more arguments later. */
773a1edc 925 gdb_argv argv (args);
7d0c9981
DE
926
927 if (argv != NULL)
928 {
929 if (argv[0] != NULL)
930 {
931 regexp = argv[0];
932 if (argv[1] != NULL)
933 error (_("Extra arguments after regexp."));
934 }
935 }
936
937 if (regexp)
938 re_comp (regexp);
939
940 ALL_PSPACES (pspace)
941 ALL_PSPACE_OBJFILES (pspace, objfile)
942 {
943 if (objfile->sf)
944 {
945 objfile->sf->qf->expand_symtabs_matching
14bc53a8
PA
946 (objfile,
947 [&] (const char *filename, bool basenames)
948 {
949 /* KISS: Only apply the regexp to the complete file name. */
950 return (!basenames
951 && (regexp == NULL || re_exec (filename)));
952 },
b5ec771e 953 lookup_name_info::match_any (),
14bc53a8
PA
954 [] (const char *symname)
955 {
956 /* Since we're not searching on symbols, just return true. */
957 return true;
958 },
959 NULL,
960 ALL_DOMAIN);
7d0c9981
DE
961 }
962 }
963}
c906108c 964\f
c5aa993b 965
c906108c
SS
966/* Return the nexting depth of a block within other blocks in its symtab. */
967
968static int
fba45db2 969block_depth (struct block *block)
c906108c 970{
52f0bd74 971 int i = 0;
433759f7 972
c5aa993b 973 while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
c906108c
SS
974 {
975 i++;
976 }
977 return i;
978}
c906108c 979\f
c5aa993b 980
f2403c39
AB
981/* Used by MAINTENANCE_INFO_LINE_TABLES to print the information about a
982 single line table. */
983
984static int
985maintenance_print_one_line_table (struct symtab *symtab, void *data)
986{
987 struct linetable *linetable;
988 struct objfile *objfile;
989
990 objfile = symtab->compunit_symtab->objfile;
991 printf_filtered (_("objfile: %s ((struct objfile *) %s)\n"),
992 objfile_name (objfile),
993 host_address_to_string (objfile));
994 printf_filtered (_("compunit_symtab: ((struct compunit_symtab *) %s)\n"),
995 host_address_to_string (symtab->compunit_symtab));
996 printf_filtered (_("symtab: %s ((struct symtab *) %s)\n"),
997 symtab_to_fullname (symtab),
998 host_address_to_string (symtab));
999 linetable = SYMTAB_LINETABLE (symtab);
1000 printf_filtered (_("linetable: ((struct linetable *) %s):\n"),
1001 host_address_to_string (linetable));
1002
1003 if (linetable == NULL)
1004 printf_filtered (_("No line table.\n"));
1005 else if (linetable->nitems <= 0)
1006 printf_filtered (_("Line table has no lines.\n"));
1007 else
1008 {
1009 int i;
1010
1011 /* Leave space for 6 digits of index and line number. After that the
1012 tables will just not format as well. */
1013 printf_filtered (_("%-6s %6s %s\n"),
1014 _("INDEX"), _("LINE"), _("ADDRESS"));
1015
1016 for (i = 0; i < linetable->nitems; ++i)
1017 {
1018 struct linetable_entry *item;
f2403c39
AB
1019
1020 item = &linetable->item [i];
1021 printf_filtered (_("%-6d %6d %s\n"), i, item->line,
1022 core_addr_to_string (item->pc));
1023 }
1024 }
1025
1026 return 0;
1027}
1028
1029/* Implement the 'maint info line-table' command. */
1030
1031static void
e99c83e7 1032maintenance_info_line_tables (const char *regexp, int from_tty)
f2403c39
AB
1033{
1034 struct program_space *pspace;
1035 struct objfile *objfile;
1036
1037 dont_repeat ();
1038
1039 if (regexp != NULL)
1040 re_comp (regexp);
1041
1042 ALL_PSPACES (pspace)
1043 ALL_PSPACE_OBJFILES (pspace, objfile)
1044 {
1045 struct compunit_symtab *cust;
1046 struct symtab *symtab;
1047
1048 ALL_OBJFILE_COMPUNITS (objfile, cust)
1049 {
1050 ALL_COMPUNIT_FILETABS (cust, symtab)
1051 {
1052 QUIT;
1053
1054 if (regexp == NULL
1055 || re_exec (symtab_to_filename_for_display (symtab)))
1056 maintenance_print_one_line_table (symtab, NULL);
1057 }
1058 }
1059 }
1060}
1061
1062\f
1063
c378eb4e 1064/* Do early runtime initializations. */
b5ebcee6 1065
c906108c 1066void
fba45db2 1067_initialize_symmisc (void)
c906108c 1068{
c5aa993b 1069 std_in = stdin;
c906108c
SS
1070 std_out = stdout;
1071 std_err = stderr;
80480540
YQ
1072
1073 add_cmd ("symbols", class_maintenance, maintenance_print_symbols, _("\
1074Print dump of current symbol definitions.\n\
34c41c68
DE
1075Usage: mt print symbols [-pc address] [--] [outfile]\n\
1076 mt print symbols [-objfile objfile] [-source source] [--] [outfile]\n\
1077Entries in the full symbol table are dumped to file OUTFILE,\n\
1078or the terminal if OUTFILE is unspecified.\n\
1079If ADDRESS is provided, dump only the file for that address.\n\
1080If SOURCE is provided, dump only that file's symbols.\n\
1081If OBJFILE is provided, dump only that file's minimal symbols."),
80480540
YQ
1082 &maintenanceprintlist);
1083
1084 add_cmd ("msymbols", class_maintenance, maintenance_print_msymbols, _("\
1085Print dump of current minimal symbol definitions.\n\
34c41c68
DE
1086Usage: mt print msymbols [-objfile objfile] [--] [outfile]\n\
1087Entries in the minimal symbol table are dumped to file OUTFILE,\n\
1088or the terminal if OUTFILE is unspecified.\n\
1089If OBJFILE is provided, dump only that file's minimal symbols."),
80480540
YQ
1090 &maintenanceprintlist);
1091
1092 add_cmd ("objfiles", class_maintenance, maintenance_print_objfiles,
52e260a3
DE
1093 _("Print dump of current object file definitions.\n\
1094With an argument REGEXP, list the object files with matching names."),
80480540
YQ
1095 &maintenanceprintlist);
1096
1097 add_cmd ("symtabs", class_maintenance, maintenance_info_symtabs, _("\
1098List the full symbol tables for all object files.\n\
1099This does not include information about individual symbols, blocks, or\n\
1100linetables --- just the symbol table structures themselves.\n\
db68bbae 1101With an argument REGEXP, list the symbol tables with matching names."),
80480540 1102 &maintenanceinfolist);
7d0c9981 1103
f2403c39
AB
1104 add_cmd ("line-table", class_maintenance, maintenance_info_line_tables, _("\
1105List the contents of all line tables, from all symbol tables.\n\
1106With an argument REGEXP, list just the line tables for the symbol\n\
1107tables with matching names."),
1108 &maintenanceinfolist);
1109
7d0c9981
DE
1110 add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs,
1111 _("\
1112Check consistency of currently expanded symtabs."),
1113 &maintenancelist);
1114
1115 add_cmd ("expand-symtabs", class_maintenance, maintenance_expand_symtabs,
1116 _("Expand symbol tables.\n\
1117With an argument REGEXP, only expand the symbol tables with matching names."),
1118 &maintenancelist);
c906108c 1119}
This page took 1.872069 seconds and 4 git commands to generate.