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