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