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