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