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