2000-12-06 Fernando Nasser <fnasser@redhat.com>
[deliverable/binutils-gdb.git] / gdb / symmisc.c
CommitLineData
c906108c 1/* Do various things to symbol tables (other than lookup), for GDB.
d9fcf2fb 2 Copyright 1986, 1987, 1989, 1991-1996, 1998, 2000 Free Software Foundation, Inc.
c906108c 3
c5aa993b 4 This file is part of GDB.
c906108c 5
c5aa993b
JM
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
c906108c 10
c5aa993b
JM
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
c906108c 15
c5aa993b
JM
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
c906108c
SS
20
21#include "defs.h"
22#include "symtab.h"
23#include "gdbtypes.h"
24#include "bfd.h"
25#include "symfile.h"
26#include "objfiles.h"
27#include "breakpoint.h"
28#include "command.h"
29#include "obstack.h"
30#include "language.h"
31#include "bcache.h"
32
33#include "gdb_string.h"
34
35#ifndef DEV_TTY
36#define DEV_TTY "/dev/tty"
37#endif
38
39/* Unfortunately for debugging, stderr is usually a macro. This is painful
40 when calling functions that take FILE *'s from the debugger.
41 So we make a variable which has the same value and which is accessible when
42 debugging GDB with itself. Because stdin et al need not be constants,
43 we initialize them in the _initialize_symmisc function at the bottom
44 of the file. */
45FILE *std_in;
46FILE *std_out;
47FILE *std_err;
48
49/* Prototypes for local functions */
50
d9fcf2fb
JM
51static void dump_symtab (struct objfile *, struct symtab *,
52 struct ui_file *);
c906108c 53
d9fcf2fb
JM
54static void dump_psymtab (struct objfile *, struct partial_symtab *,
55 struct ui_file *);
c906108c 56
d9fcf2fb 57static void dump_msymbols (struct objfile *, struct ui_file *);
c906108c 58
a14ed312 59static void dump_objfile (struct objfile *);
c906108c 60
a14ed312 61static int block_depth (struct block *);
c906108c 62
d9fcf2fb
JM
63static void print_partial_symbols (struct partial_symbol **, int,
64 char *, struct ui_file *);
c906108c 65
a14ed312 66static void free_symtab_block (struct objfile *, struct block *);
c906108c 67
a14ed312 68void _initialize_symmisc (void);
c906108c 69
c5aa993b
JM
70struct print_symbol_args
71 {
72 struct symbol *symbol;
73 int depth;
d9fcf2fb 74 struct ui_file *outfile;
c5aa993b 75 };
c906108c 76
a14ed312 77static int print_symbol (PTR);
c906108c 78
a14ed312 79static void free_symtab_block (struct objfile *, struct block *);
c906108c 80\f
c5aa993b 81
c906108c
SS
82/* Free a struct block <- B and all the symbols defined in that block. */
83
84static void
fba45db2 85free_symtab_block (struct objfile *objfile, struct block *b)
c906108c
SS
86{
87 register int i, n;
88 n = BLOCK_NSYMS (b);
89 for (i = 0; i < n; i++)
90 {
c5aa993b
JM
91 mfree (objfile->md, SYMBOL_NAME (BLOCK_SYM (b, i)));
92 mfree (objfile->md, (PTR) BLOCK_SYM (b, i));
c906108c 93 }
c5aa993b 94 mfree (objfile->md, (PTR) b);
c906108c
SS
95}
96
97/* Free all the storage associated with the struct symtab <- S.
98 Note that some symtabs have contents malloc'ed structure by structure,
99 while some have contents that all live inside one big block of memory,
100 and some share the contents of another symbol table and so you should
101 not free the contents on their behalf (except sometimes the linetable,
102 which maybe per symtab even when the rest is not).
103 It is s->free_code that says which alternative to use. */
104
105void
fba45db2 106free_symtab (register struct symtab *s)
c906108c
SS
107{
108 register int i, n;
109 register struct blockvector *bv;
110
111 switch (s->free_code)
112 {
113 case free_nothing:
114 /* All the contents are part of a big block of memory (an obstack),
c5aa993b
JM
115 and some other symtab is in charge of freeing that block.
116 Therefore, do nothing. */
c906108c
SS
117 break;
118
119 case free_contents:
120 /* Here all the contents were malloc'ed structure by structure
c5aa993b 121 and must be freed that way. */
c906108c
SS
122 /* First free the blocks (and their symbols. */
123 bv = BLOCKVECTOR (s);
124 n = BLOCKVECTOR_NBLOCKS (bv);
125 for (i = 0; i < n; i++)
c5aa993b 126 free_symtab_block (s->objfile, BLOCKVECTOR_BLOCK (bv, i));
c906108c 127 /* Free the blockvector itself. */
c5aa993b 128 mfree (s->objfile->md, (PTR) bv);
c906108c 129 /* Also free the linetable. */
c5aa993b 130
c906108c
SS
131 case free_linetable:
132 /* Everything will be freed either by our `free_ptr'
c5aa993b
JM
133 or by some other symtab, except for our linetable.
134 Free that now. */
c906108c 135 if (LINETABLE (s))
c5aa993b 136 mfree (s->objfile->md, (PTR) LINETABLE (s));
c906108c
SS
137 break;
138 }
139
140 /* If there is a single block of memory to free, free it. */
c5aa993b
JM
141 if (s->free_ptr != NULL)
142 mfree (s->objfile->md, s->free_ptr);
c906108c
SS
143
144 /* Free source-related stuff */
c5aa993b
JM
145 if (s->line_charpos != NULL)
146 mfree (s->objfile->md, (PTR) s->line_charpos);
147 if (s->fullname != NULL)
148 mfree (s->objfile->md, s->fullname);
149 if (s->debugformat != NULL)
150 mfree (s->objfile->md, s->debugformat);
151 mfree (s->objfile->md, (PTR) s);
c906108c
SS
152}
153
c906108c 154void
fba45db2 155print_symbol_bcache_statistics (void)
c906108c
SS
156{
157 struct objfile *objfile;
158
159 immediate_quit++;
160 ALL_OBJFILES (objfile)
c5aa993b
JM
161 {
162 printf_filtered ("Byte cache statistics for '%s':\n", objfile->name);
163 print_bcache_statistics (&objfile->psymbol_cache, "partial symbol cache");
164 }
c906108c
SS
165 immediate_quit--;
166}
167
168void
fba45db2 169print_objfile_statistics (void)
c906108c
SS
170{
171 struct objfile *objfile;
172
173 immediate_quit++;
174 ALL_OBJFILES (objfile)
c5aa993b
JM
175 {
176 printf_filtered ("Statistics for '%s':\n", objfile->name);
177 if (OBJSTAT (objfile, n_stabs) > 0)
178 printf_filtered (" Number of \"stab\" symbols read: %d\n",
179 OBJSTAT (objfile, n_stabs));
180 if (OBJSTAT (objfile, n_minsyms) > 0)
181 printf_filtered (" Number of \"minimal\" symbols read: %d\n",
182 OBJSTAT (objfile, n_minsyms));
183 if (OBJSTAT (objfile, n_psyms) > 0)
184 printf_filtered (" Number of \"partial\" symbols read: %d\n",
185 OBJSTAT (objfile, n_psyms));
186 if (OBJSTAT (objfile, n_syms) > 0)
187 printf_filtered (" Number of \"full\" symbols read: %d\n",
188 OBJSTAT (objfile, n_syms));
189 if (OBJSTAT (objfile, n_types) > 0)
190 printf_filtered (" Number of \"types\" defined: %d\n",
191 OBJSTAT (objfile, n_types));
192 if (OBJSTAT (objfile, sz_strtab) > 0)
193 printf_filtered (" Space used by a.out string tables: %d\n",
194 OBJSTAT (objfile, sz_strtab));
195 printf_filtered (" Total memory used for psymbol obstack: %d\n",
196 obstack_memory_used (&objfile->psymbol_obstack));
197 printf_filtered (" Total memory used for psymbol cache: %d\n",
198 obstack_memory_used (&objfile->psymbol_cache.cache));
199 printf_filtered (" Total memory used for symbol obstack: %d\n",
200 obstack_memory_used (&objfile->symbol_obstack));
201 printf_filtered (" Total memory used for type obstack: %d\n",
202 obstack_memory_used (&objfile->type_obstack));
203 }
c906108c
SS
204 immediate_quit--;
205}
206
c5aa993b 207static void
fba45db2 208dump_objfile (struct objfile *objfile)
c906108c
SS
209{
210 struct symtab *symtab;
211 struct partial_symtab *psymtab;
212
c5aa993b 213 printf_filtered ("\nObject file %s: ", objfile->name);
c906108c 214 printf_filtered ("Objfile at ");
d4f3574e 215 gdb_print_host_address (objfile, gdb_stdout);
c906108c 216 printf_filtered (", bfd at ");
d4f3574e 217 gdb_print_host_address (objfile->obfd, gdb_stdout);
c906108c
SS
218 printf_filtered (", %d minsyms\n\n",
219 objfile->minimal_symbol_count);
220
c5aa993b 221 if (objfile->psymtabs)
c906108c
SS
222 {
223 printf_filtered ("Psymtabs:\n");
c5aa993b 224 for (psymtab = objfile->psymtabs;
c906108c 225 psymtab != NULL;
c5aa993b 226 psymtab = psymtab->next)
c906108c
SS
227 {
228 printf_filtered ("%s at ",
c5aa993b 229 psymtab->filename);
d4f3574e 230 gdb_print_host_address (psymtab, gdb_stdout);
c906108c 231 printf_filtered (", ");
c5aa993b 232 if (psymtab->objfile != objfile)
c906108c
SS
233 {
234 printf_filtered ("NOT ON CHAIN! ");
235 }
236 wrap_here (" ");
237 }
238 printf_filtered ("\n\n");
239 }
240
c5aa993b 241 if (objfile->symtabs)
c906108c
SS
242 {
243 printf_filtered ("Symtabs:\n");
c5aa993b 244 for (symtab = objfile->symtabs;
c906108c
SS
245 symtab != NULL;
246 symtab = symtab->next)
247 {
c5aa993b 248 printf_filtered ("%s at ", symtab->filename);
d4f3574e 249 gdb_print_host_address (symtab, gdb_stdout);
c906108c 250 printf_filtered (", ");
c5aa993b 251 if (symtab->objfile != objfile)
c906108c
SS
252 {
253 printf_filtered ("NOT ON CHAIN! ");
254 }
255 wrap_here (" ");
256 }
257 printf_filtered ("\n\n");
258 }
259}
260
261/* Print minimal symbols from this objfile. */
c5aa993b
JM
262
263static void
fba45db2 264dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
c906108c
SS
265{
266 struct minimal_symbol *msymbol;
267 int index;
268 char ms_type;
c5aa993b
JM
269
270 fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile->name);
271 if (objfile->minimal_symbol_count == 0)
c906108c
SS
272 {
273 fprintf_filtered (outfile, "No minimal symbols found.\n");
274 return;
275 }
c5aa993b 276 for (index = 0, msymbol = objfile->msymbols;
c906108c
SS
277 SYMBOL_NAME (msymbol) != NULL; msymbol++, index++)
278 {
c5aa993b 279 switch (msymbol->type)
c906108c 280 {
c5aa993b
JM
281 case mst_unknown:
282 ms_type = 'u';
283 break;
284 case mst_text:
285 ms_type = 'T';
286 break;
287 case mst_solib_trampoline:
288 ms_type = 'S';
289 break;
290 case mst_data:
291 ms_type = 'D';
292 break;
293 case mst_bss:
294 ms_type = 'B';
295 break;
296 case mst_abs:
297 ms_type = 'A';
298 break;
299 case mst_file_text:
300 ms_type = 't';
301 break;
302 case mst_file_data:
303 ms_type = 'd';
304 break;
305 case mst_file_bss:
306 ms_type = 'b';
307 break;
308 default:
309 ms_type = '?';
310 break;
c906108c
SS
311 }
312 fprintf_filtered (outfile, "[%2d] %c ", index, ms_type);
313 print_address_numeric (SYMBOL_VALUE_ADDRESS (msymbol), 1, outfile);
314 fprintf_filtered (outfile, " %s", SYMBOL_NAME (msymbol));
315 if (SYMBOL_BFD_SECTION (msymbol))
316 fprintf_filtered (outfile, " section %s",
317 bfd_section_name (objfile->obfd,
318 SYMBOL_BFD_SECTION (msymbol)));
319 if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
320 {
321 fprintf_filtered (outfile, " %s", SYMBOL_DEMANGLED_NAME (msymbol));
322 }
323#ifdef SOFUN_ADDRESS_MAYBE_MISSING
324 if (msymbol->filename)
325 fprintf_filtered (outfile, " %s", msymbol->filename);
326#endif
327 fputs_filtered ("\n", outfile);
328 }
c5aa993b 329 if (objfile->minimal_symbol_count != index)
c906108c
SS
330 {
331 warning ("internal error: minimal symbol count %d != %d",
c5aa993b 332 objfile->minimal_symbol_count, index);
c906108c
SS
333 }
334 fprintf_filtered (outfile, "\n");
335}
336
337static void
fba45db2
KB
338dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
339 struct ui_file *outfile)
c906108c
SS
340{
341 int i;
342
343 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
c5aa993b 344 psymtab->filename);
c906108c 345 fprintf_filtered (outfile, "(object ");
d4f3574e 346 gdb_print_host_address (psymtab, outfile);
c906108c
SS
347 fprintf_filtered (outfile, ")\n\n");
348 fprintf_unfiltered (outfile, " Read from object file %s (",
c5aa993b 349 objfile->name);
d4f3574e 350 gdb_print_host_address (objfile, outfile);
c906108c
SS
351 fprintf_unfiltered (outfile, ")\n");
352
c5aa993b 353 if (psymtab->readin)
c906108c
SS
354 {
355 fprintf_filtered (outfile,
c5aa993b 356 " Full symtab was read (at ");
d4f3574e 357 gdb_print_host_address (psymtab->symtab, outfile);
c906108c 358 fprintf_filtered (outfile, " by function at ");
d4f3574e 359 gdb_print_host_address ((PTR) psymtab->read_symtab, outfile);
c906108c
SS
360 fprintf_filtered (outfile, ")\n");
361 }
362
363 fprintf_filtered (outfile, " Relocate symbols by ");
364 for (i = 0; i < psymtab->objfile->num_sections; ++i)
365 {
366 if (i != 0)
367 fprintf_filtered (outfile, ", ");
368 wrap_here (" ");
369 print_address_numeric (ANOFFSET (psymtab->section_offsets, i),
370 1,
371 outfile);
372 }
373 fprintf_filtered (outfile, "\n");
374
375 fprintf_filtered (outfile, " Symbols cover text addresses ");
376 print_address_numeric (psymtab->textlow, 1, outfile);
377 fprintf_filtered (outfile, "-");
378 print_address_numeric (psymtab->texthigh, 1, outfile);
379 fprintf_filtered (outfile, "\n");
380 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
c5aa993b
JM
381 psymtab->number_of_dependencies);
382 for (i = 0; i < psymtab->number_of_dependencies; i++)
c906108c
SS
383 {
384 fprintf_filtered (outfile, " %d ", i);
d4f3574e 385 gdb_print_host_address (psymtab->dependencies[i], outfile);
c906108c 386 fprintf_filtered (outfile, " %s\n",
c5aa993b 387 psymtab->dependencies[i]->filename);
c906108c 388 }
c5aa993b 389 if (psymtab->n_global_syms > 0)
c906108c 390 {
c5aa993b
JM
391 print_partial_symbols (objfile->global_psymbols.list
392 + psymtab->globals_offset,
393 psymtab->n_global_syms, "Global", outfile);
c906108c 394 }
c5aa993b 395 if (psymtab->n_static_syms > 0)
c906108c 396 {
c5aa993b
JM
397 print_partial_symbols (objfile->static_psymbols.list
398 + psymtab->statics_offset,
399 psymtab->n_static_syms, "Static", outfile);
c906108c
SS
400 }
401 fprintf_filtered (outfile, "\n");
402}
403
c5aa993b 404static void
fba45db2
KB
405dump_symtab (struct objfile *objfile, struct symtab *symtab,
406 struct ui_file *outfile)
c906108c
SS
407{
408 register int i, j;
409 int len, blen;
410 register struct linetable *l;
411 struct blockvector *bv;
412 register struct block *b;
413 int depth;
414
415 fprintf_filtered (outfile, "\nSymtab for file %s\n", symtab->filename);
416 if (symtab->dirname)
417 fprintf_filtered (outfile, "Compilation directory is %s\n",
418 symtab->dirname);
419 fprintf_filtered (outfile, "Read from object file %s (", objfile->name);
d4f3574e 420 gdb_print_host_address (objfile, outfile);
c906108c
SS
421 fprintf_filtered (outfile, ")\n");
422 fprintf_filtered (outfile, "Language: %s\n", language_str (symtab->language));
423
424 /* First print the line table. */
425 l = LINETABLE (symtab);
426 if (l)
427 {
428 fprintf_filtered (outfile, "\nLine table:\n\n");
429 len = l->nitems;
430 for (i = 0; i < len; i++)
431 {
432 fprintf_filtered (outfile, " line %d at ", l->item[i].line);
433 print_address_numeric (l->item[i].pc, 1, outfile);
434 fprintf_filtered (outfile, "\n");
435 }
436 }
437 /* Now print the block info, but only for primary symtabs since we will
438 print lots of duplicate info otherwise. */
c5aa993b 439 if (symtab->primary)
c906108c
SS
440 {
441 fprintf_filtered (outfile, "\nBlockvector:\n\n");
442 bv = BLOCKVECTOR (symtab);
443 len = BLOCKVECTOR_NBLOCKS (bv);
444 for (i = 0; i < len; i++)
445 {
446 b = BLOCKVECTOR_BLOCK (bv, i);
447 depth = block_depth (b) * 2;
448 print_spaces (depth, outfile);
449 fprintf_filtered (outfile, "block #%03d, object at ", i);
d4f3574e 450 gdb_print_host_address (b, outfile);
c906108c
SS
451 if (BLOCK_SUPERBLOCK (b))
452 {
453 fprintf_filtered (outfile, " under ");
d4f3574e 454 gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile);
c906108c
SS
455 }
456 blen = BLOCK_NSYMS (b);
457 fprintf_filtered (outfile, ", %d syms in ", blen);
458 print_address_numeric (BLOCK_START (b), 1, outfile);
459 fprintf_filtered (outfile, "..");
460 print_address_numeric (BLOCK_END (b), 1, outfile);
461 if (BLOCK_FUNCTION (b))
462 {
463 fprintf_filtered (outfile, ", function %s", SYMBOL_NAME (BLOCK_FUNCTION (b)));
464 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
465 {
466 fprintf_filtered (outfile, ", %s",
c5aa993b 467 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
c906108c
SS
468 }
469 }
c5aa993b
JM
470 if (BLOCK_GCC_COMPILED (b))
471 fprintf_filtered (outfile, ", compiled with gcc%d", BLOCK_GCC_COMPILED (b));
c906108c
SS
472 fprintf_filtered (outfile, "\n");
473 /* Now print each symbol in this block */
474 for (j = 0; j < blen; j++)
475 {
476 struct print_symbol_args s;
477 s.symbol = BLOCK_SYM (b, j);
478 s.depth = depth + 1;
479 s.outfile = outfile;
480 catch_errors (print_symbol, &s, "Error printing symbol:\n",
481 RETURN_MASK_ALL);
482 }
483 }
484 fprintf_filtered (outfile, "\n");
485 }
486 else
487 {
488 fprintf_filtered (outfile, "\nBlockvector same as previous symtab\n\n");
489 }
490}
491
492void
fba45db2 493maintenance_print_symbols (char *args, int from_tty)
c906108c
SS
494{
495 char **argv;
d9fcf2fb 496 struct ui_file *outfile;
c906108c
SS
497 struct cleanup *cleanups;
498 char *symname = NULL;
499 char *filename = DEV_TTY;
500 struct objfile *objfile;
501 struct symtab *s;
502
503 dont_repeat ();
504
505 if (args == NULL)
506 {
507 error ("\
508Arguments missing: an output file name and an optional symbol file name");
509 }
510 else if ((argv = buildargv (args)) == NULL)
511 {
512 nomem (0);
513 }
7a292a7a 514 cleanups = make_cleanup_freeargv (argv);
c906108c
SS
515
516 if (argv[0] != NULL)
517 {
518 filename = argv[0];
519 /* If a second arg is supplied, it is a source file name to match on */
520 if (argv[1] != NULL)
521 {
522 symname = argv[1];
523 }
524 }
525
526 filename = tilde_expand (filename);
527 make_cleanup (free, filename);
c5aa993b 528
c906108c
SS
529 outfile = gdb_fopen (filename, FOPEN_WT);
530 if (outfile == 0)
531 perror_with_name (filename);
d9fcf2fb 532 make_cleanup_ui_file_delete (outfile);
c906108c
SS
533
534 immediate_quit++;
535 ALL_SYMTABS (objfile, s)
c5aa993b
JM
536 if (symname == NULL || (STREQ (symname, s->filename)))
537 dump_symtab (objfile, s, outfile);
c906108c
SS
538 immediate_quit--;
539 do_cleanups (cleanups);
540}
541
542/* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
543 far to indent. ARGS is really a struct print_symbol_args *, but is
544 declared as char * to get it past catch_errors. Returns 0 for error,
545 1 for success. */
546
547static int
fba45db2 548print_symbol (PTR args)
c906108c 549{
c5aa993b
JM
550 struct symbol *symbol = ((struct print_symbol_args *) args)->symbol;
551 int depth = ((struct print_symbol_args *) args)->depth;
d9fcf2fb 552 struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile;
c906108c
SS
553
554 print_spaces (depth, outfile);
555 if (SYMBOL_NAMESPACE (symbol) == LABEL_NAMESPACE)
556 {
557 fprintf_filtered (outfile, "label %s at ", SYMBOL_SOURCE_NAME (symbol));
558 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
559 if (SYMBOL_BFD_SECTION (symbol))
560 fprintf_filtered (outfile, " section %s\n",
c5aa993b
JM
561 bfd_section_name (SYMBOL_BFD_SECTION (symbol)->owner,
562 SYMBOL_BFD_SECTION (symbol)));
c906108c
SS
563 else
564 fprintf_filtered (outfile, "\n");
565 return 1;
566 }
567 if (SYMBOL_NAMESPACE (symbol) == STRUCT_NAMESPACE)
568 {
569 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
570 {
571 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
572 }
573 else
574 {
575 fprintf_filtered (outfile, "%s %s = ",
c5aa993b
JM
576 (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
577 ? "enum"
578 : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
579 ? "struct" : "union")),
580 SYMBOL_NAME (symbol));
c906108c
SS
581 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
582 }
583 fprintf_filtered (outfile, ";\n");
584 }
585 else
586 {
587 if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
588 fprintf_filtered (outfile, "typedef ");
589 if (SYMBOL_TYPE (symbol))
590 {
591 /* Print details of types, except for enums where it's clutter. */
592 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_SOURCE_NAME (symbol),
593 outfile,
594 TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
595 depth);
596 fprintf_filtered (outfile, "; ");
597 }
598 else
599 fprintf_filtered (outfile, "%s ", SYMBOL_SOURCE_NAME (symbol));
600
601 switch (SYMBOL_CLASS (symbol))
602 {
603 case LOC_CONST:
604 fprintf_filtered (outfile, "const %ld (0x%lx)",
605 SYMBOL_VALUE (symbol),
606 SYMBOL_VALUE (symbol));
607 break;
608
609 case LOC_CONST_BYTES:
610 {
611 unsigned i;
612 struct type *type = check_typedef (SYMBOL_TYPE (symbol));
613 fprintf_filtered (outfile, "const %u hex bytes:",
614 TYPE_LENGTH (type));
615 for (i = 0; i < TYPE_LENGTH (type); i++)
616 fprintf_filtered (outfile, " %02x",
c5aa993b 617 (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]);
c906108c
SS
618 }
619 break;
620
621 case LOC_STATIC:
622 fprintf_filtered (outfile, "static at ");
c5aa993b 623 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
c906108c
SS
624 if (SYMBOL_BFD_SECTION (symbol))
625 fprintf_filtered (outfile, " section %s",
626 bfd_section_name
627 (SYMBOL_BFD_SECTION (symbol)->owner,
628 SYMBOL_BFD_SECTION (symbol)));
629 break;
630
631 case LOC_INDIRECT:
632 fprintf_filtered (outfile, "extern global at *(");
c5aa993b 633 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
c906108c
SS
634 fprintf_filtered (outfile, "),");
635 break;
636
637 case LOC_REGISTER:
638 fprintf_filtered (outfile, "register %ld", SYMBOL_VALUE (symbol));
639 break;
640
641 case LOC_ARG:
642 fprintf_filtered (outfile, "arg at offset 0x%lx",
643 SYMBOL_VALUE (symbol));
644 break;
645
646 case LOC_LOCAL_ARG:
647 fprintf_filtered (outfile, "arg at offset 0x%lx from fp",
c5aa993b 648 SYMBOL_VALUE (symbol));
c906108c
SS
649 break;
650
651 case LOC_REF_ARG:
652 fprintf_filtered (outfile, "reference arg at 0x%lx", SYMBOL_VALUE (symbol));
653 break;
654
655 case LOC_REGPARM:
656 fprintf_filtered (outfile, "parameter register %ld", SYMBOL_VALUE (symbol));
657 break;
658
659 case LOC_REGPARM_ADDR:
660 fprintf_filtered (outfile, "address parameter register %ld", SYMBOL_VALUE (symbol));
661 break;
662
663 case LOC_LOCAL:
664 fprintf_filtered (outfile, "local at offset 0x%lx",
665 SYMBOL_VALUE (symbol));
666 break;
667
668 case LOC_BASEREG:
669 fprintf_filtered (outfile, "local at 0x%lx from register %d",
c5aa993b 670 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
c906108c
SS
671 break;
672
673 case LOC_BASEREG_ARG:
674 fprintf_filtered (outfile, "arg at 0x%lx from register %d",
c5aa993b 675 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
c906108c
SS
676 break;
677
678 case LOC_TYPEDEF:
679 break;
680
681 case LOC_LABEL:
682 fprintf_filtered (outfile, "label at ");
683 print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
684 if (SYMBOL_BFD_SECTION (symbol))
685 fprintf_filtered (outfile, " section %s",
686 bfd_section_name
687 (SYMBOL_BFD_SECTION (symbol)->owner,
688 SYMBOL_BFD_SECTION (symbol)));
689 break;
690
691 case LOC_BLOCK:
692 fprintf_filtered (outfile, "block object ");
d4f3574e 693 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
c906108c
SS
694 fprintf_filtered (outfile, ", ");
695 print_address_numeric (BLOCK_START (SYMBOL_BLOCK_VALUE (symbol)),
696 1,
697 outfile);
698 fprintf_filtered (outfile, "..");
699 print_address_numeric (BLOCK_END (SYMBOL_BLOCK_VALUE (symbol)),
700 1,
701 outfile);
702 if (SYMBOL_BFD_SECTION (symbol))
703 fprintf_filtered (outfile, " section %s",
704 bfd_section_name
705 (SYMBOL_BFD_SECTION (symbol)->owner,
706 SYMBOL_BFD_SECTION (symbol)));
707 break;
708
709 case LOC_UNRESOLVED:
710 fprintf_filtered (outfile, "unresolved");
711 break;
712
713 case LOC_OPTIMIZED_OUT:
714 fprintf_filtered (outfile, "optimized out");
715 break;
716
c5aa993b 717 default:
c906108c
SS
718 fprintf_filtered (outfile, "botched symbol class %x",
719 SYMBOL_CLASS (symbol));
720 break;
721 }
722 }
723 fprintf_filtered (outfile, "\n");
724 return 1;
725}
726
727void
fba45db2 728maintenance_print_psymbols (char *args, int from_tty)
c906108c
SS
729{
730 char **argv;
d9fcf2fb 731 struct ui_file *outfile;
c906108c
SS
732 struct cleanup *cleanups;
733 char *symname = NULL;
734 char *filename = DEV_TTY;
735 struct objfile *objfile;
736 struct partial_symtab *ps;
737
738 dont_repeat ();
739
740 if (args == NULL)
741 {
742 error ("print-psymbols takes an output file name and optional symbol file name");
743 }
744 else if ((argv = buildargv (args)) == NULL)
745 {
746 nomem (0);
747 }
7a292a7a 748 cleanups = make_cleanup_freeargv (argv);
c906108c
SS
749
750 if (argv[0] != NULL)
751 {
752 filename = argv[0];
753 /* If a second arg is supplied, it is a source file name to match on */
754 if (argv[1] != NULL)
755 {
756 symname = argv[1];
757 }
758 }
759
760 filename = tilde_expand (filename);
761 make_cleanup (free, filename);
c5aa993b 762
c906108c
SS
763 outfile = gdb_fopen (filename, FOPEN_WT);
764 if (outfile == 0)
765 perror_with_name (filename);
d9fcf2fb 766 make_cleanup_ui_file_delete (outfile);
c906108c
SS
767
768 immediate_quit++;
769 ALL_PSYMTABS (objfile, ps)
c5aa993b
JM
770 if (symname == NULL || (STREQ (symname, ps->filename)))
771 dump_psymtab (objfile, ps, outfile);
c906108c
SS
772 immediate_quit--;
773 do_cleanups (cleanups);
774}
775
776static void
fba45db2
KB
777print_partial_symbols (struct partial_symbol **p, int count, char *what,
778 struct ui_file *outfile)
c906108c
SS
779{
780 fprintf_filtered (outfile, " %s partial symbols:\n", what);
781 while (count-- > 0)
782 {
c5aa993b 783 fprintf_filtered (outfile, " `%s'", SYMBOL_NAME (*p));
c906108c
SS
784 if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
785 {
786 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
787 }
788 fputs_filtered (", ", outfile);
789 switch (SYMBOL_NAMESPACE (*p))
790 {
791 case UNDEF_NAMESPACE:
792 fputs_filtered ("undefined namespace, ", outfile);
793 break;
794 case VAR_NAMESPACE:
795 /* This is the usual thing -- don't print it */
796 break;
797 case STRUCT_NAMESPACE:
798 fputs_filtered ("struct namespace, ", outfile);
799 break;
800 case LABEL_NAMESPACE:
801 fputs_filtered ("label namespace, ", outfile);
802 break;
803 default:
804 fputs_filtered ("<invalid namespace>, ", outfile);
805 break;
806 }
807 switch (SYMBOL_CLASS (*p))
808 {
809 case LOC_UNDEF:
810 fputs_filtered ("undefined", outfile);
811 break;
812 case LOC_CONST:
813 fputs_filtered ("constant int", outfile);
814 break;
815 case LOC_STATIC:
816 fputs_filtered ("static", outfile);
817 break;
818 case LOC_INDIRECT:
819 fputs_filtered ("extern global", outfile);
820 break;
821 case LOC_REGISTER:
822 fputs_filtered ("register", outfile);
823 break;
824 case LOC_ARG:
825 fputs_filtered ("pass by value", outfile);
826 break;
827 case LOC_REF_ARG:
828 fputs_filtered ("pass by reference", outfile);
829 break;
830 case LOC_REGPARM:
831 fputs_filtered ("register parameter", outfile);
832 break;
833 case LOC_REGPARM_ADDR:
834 fputs_filtered ("register address parameter", outfile);
835 break;
836 case LOC_LOCAL:
837 fputs_filtered ("stack parameter", outfile);
838 break;
839 case LOC_TYPEDEF:
840 fputs_filtered ("type", outfile);
841 break;
842 case LOC_LABEL:
843 fputs_filtered ("label", outfile);
844 break;
845 case LOC_BLOCK:
846 fputs_filtered ("function", outfile);
847 break;
848 case LOC_CONST_BYTES:
849 fputs_filtered ("constant bytes", outfile);
850 break;
851 case LOC_LOCAL_ARG:
852 fputs_filtered ("shuffled arg", outfile);
853 break;
854 case LOC_UNRESOLVED:
855 fputs_filtered ("unresolved", outfile);
856 break;
857 case LOC_OPTIMIZED_OUT:
858 fputs_filtered ("optimized out", outfile);
859 break;
860 default:
861 fputs_filtered ("<invalid location>", outfile);
862 break;
863 }
864 fputs_filtered (", ", outfile);
865 print_address_numeric (SYMBOL_VALUE_ADDRESS (*p), 1, outfile);
866 fprintf_filtered (outfile, "\n");
867 p++;
868 }
869}
870
871void
fba45db2 872maintenance_print_msymbols (char *args, int from_tty)
c906108c
SS
873{
874 char **argv;
d9fcf2fb 875 struct ui_file *outfile;
c906108c
SS
876 struct cleanup *cleanups;
877 char *filename = DEV_TTY;
878 char *symname = NULL;
879 struct objfile *objfile;
880
881 dont_repeat ();
882
883 if (args == NULL)
884 {
885 error ("print-msymbols takes an output file name and optional symbol file name");
886 }
887 else if ((argv = buildargv (args)) == NULL)
888 {
889 nomem (0);
890 }
7a292a7a 891 cleanups = make_cleanup_freeargv (argv);
c906108c
SS
892
893 if (argv[0] != NULL)
894 {
895 filename = argv[0];
896 /* If a second arg is supplied, it is a source file name to match on */
897 if (argv[1] != NULL)
898 {
899 symname = argv[1];
900 }
901 }
902
903 filename = tilde_expand (filename);
904 make_cleanup (free, filename);
c5aa993b 905
c906108c
SS
906 outfile = gdb_fopen (filename, FOPEN_WT);
907 if (outfile == 0)
908 perror_with_name (filename);
d9fcf2fb 909 make_cleanup_ui_file_delete (outfile);
c906108c
SS
910
911 immediate_quit++;
912 ALL_OBJFILES (objfile)
c5aa993b
JM
913 if (symname == NULL || (STREQ (symname, objfile->name)))
914 dump_msymbols (objfile, outfile);
c906108c
SS
915 immediate_quit--;
916 fprintf_filtered (outfile, "\n\n");
917 do_cleanups (cleanups);
918}
919
920void
fba45db2 921maintenance_print_objfiles (char *ignore, int from_tty)
c906108c
SS
922{
923 struct objfile *objfile;
924
925 dont_repeat ();
926
927 immediate_quit++;
928 ALL_OBJFILES (objfile)
929 dump_objfile (objfile);
930 immediate_quit--;
931}
932
933/* Check consistency of psymtabs and symtabs. */
934
935void
fba45db2 936maintenance_check_symtabs (char *ignore, int from_tty)
c906108c
SS
937{
938 register struct symbol *sym;
939 register struct partial_symbol **psym;
940 register struct symtab *s = NULL;
941 register struct partial_symtab *ps;
942 struct blockvector *bv;
943 register struct objfile *objfile;
944 register struct block *b;
945 int length;
946
947 ALL_PSYMTABS (objfile, ps)
c5aa993b
JM
948 {
949 s = PSYMTAB_TO_SYMTAB (ps);
950 if (s == NULL)
951 continue;
952 bv = BLOCKVECTOR (s);
953 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
954 psym = ps->objfile->static_psymbols.list + ps->statics_offset;
955 length = ps->n_static_syms;
956 while (length--)
957 {
958 sym = lookup_block_symbol (b, SYMBOL_NAME (*psym),
959 SYMBOL_NAMESPACE (*psym));
960 if (!sym)
961 {
962 printf_filtered ("Static symbol `");
963 puts_filtered (SYMBOL_NAME (*psym));
964 printf_filtered ("' only found in ");
965 puts_filtered (ps->filename);
966 printf_filtered (" psymtab\n");
967 }
968 psym++;
969 }
970 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
971 psym = ps->objfile->global_psymbols.list + ps->globals_offset;
972 length = ps->n_global_syms;
973 while (length--)
974 {
975 sym = lookup_block_symbol (b, SYMBOL_NAME (*psym),
976 SYMBOL_NAMESPACE (*psym));
977 if (!sym)
978 {
979 printf_filtered ("Global symbol `");
980 puts_filtered (SYMBOL_NAME (*psym));
981 printf_filtered ("' only found in ");
982 puts_filtered (ps->filename);
983 printf_filtered (" psymtab\n");
984 }
985 psym++;
986 }
987 if (ps->texthigh < ps->textlow)
988 {
989 printf_filtered ("Psymtab ");
990 puts_filtered (ps->filename);
991 printf_filtered (" covers bad range ");
992 print_address_numeric (ps->textlow, 1, gdb_stdout);
993 printf_filtered (" - ");
994 print_address_numeric (ps->texthigh, 1, gdb_stdout);
995 printf_filtered ("\n");
c906108c 996 continue;
c5aa993b
JM
997 }
998 if (ps->texthigh == 0)
999 continue;
1000 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
1001 {
1002 printf_filtered ("Psymtab ");
1003 puts_filtered (ps->filename);
1004 printf_filtered (" covers ");
1005 print_address_numeric (ps->textlow, 1, gdb_stdout);
1006 printf_filtered (" - ");
1007 print_address_numeric (ps->texthigh, 1, gdb_stdout);
1008 printf_filtered (" but symtab covers only ");
1009 print_address_numeric (BLOCK_START (b), 1, gdb_stdout);
1010 printf_filtered (" - ");
1011 print_address_numeric (BLOCK_END (b), 1, gdb_stdout);
1012 printf_filtered ("\n");
1013 }
1014 }
c906108c 1015}
c906108c 1016\f
c5aa993b 1017
c906108c
SS
1018/* Return the nexting depth of a block within other blocks in its symtab. */
1019
1020static int
fba45db2 1021block_depth (struct block *block)
c906108c
SS
1022{
1023 register int i = 0;
c5aa993b 1024 while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
c906108c
SS
1025 {
1026 i++;
1027 }
1028 return i;
1029}
c906108c 1030\f
c5aa993b 1031
c906108c
SS
1032/* Increase the space allocated for LISTP, which is probably
1033 global_psymbols or static_psymbols. This space will eventually
1034 be freed in free_objfile(). */
1035
1036void
fba45db2
KB
1037extend_psymbol_list (register struct psymbol_allocation_list *listp,
1038 struct objfile *objfile)
c906108c
SS
1039{
1040 int new_size;
1041 if (listp->size == 0)
1042 {
1043 new_size = 255;
1044 listp->list = (struct partial_symbol **)
c5aa993b 1045 xmmalloc (objfile->md, new_size * sizeof (struct partial_symbol *));
c906108c
SS
1046 }
1047 else
1048 {
1049 new_size = listp->size * 2;
1050 listp->list = (struct partial_symbol **)
c5aa993b 1051 xmrealloc (objfile->md, (char *) listp->list,
c906108c
SS
1052 new_size * sizeof (struct partial_symbol *));
1053 }
1054 /* Next assumes we only went one over. Should be good if
1055 program works correctly */
1056 listp->next = listp->list + listp->size;
1057 listp->size = new_size;
1058}
1059
1060
1061/* Do early runtime initializations. */
1062void
fba45db2 1063_initialize_symmisc (void)
c906108c 1064{
c5aa993b 1065 std_in = stdin;
c906108c
SS
1066 std_out = stdout;
1067 std_err = stderr;
1068}
This page took 0.221148 seconds and 4 git commands to generate.