Remove dup inftarg.o from NATDEPFILES.
[deliverable/binutils-gdb.git] / gdb / symmisc.c
CommitLineData
7e258d18 1/* Do various things to symbol tables (other than lookup), for GDB.
318bf84f 2 Copyright 1986, 1987, 1989, 1991, 1992 Free Software Foundation, Inc.
bd5635a1
RP
3
4This file is part of GDB.
5
4a35d6e9 6This program is free software; you can redistribute it and/or modify
bd5635a1 7it under the terms of the GNU General Public License as published by
4a35d6e9
FF
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
bd5635a1 10
4a35d6e9 11This program is distributed in the hope that it will be useful,
bd5635a1
RP
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
4a35d6e9
FF
17along with this program; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
bd5635a1 19
bd5635a1 20#include "defs.h"
bd5635a1 21#include "symtab.h"
318bf84f 22#include "gdbtypes.h"
4a35d6e9
FF
23#include "bfd.h"
24#include "symfile.h"
d630b615 25#include "objfiles.h"
bd5635a1
RP
26#include "breakpoint.h"
27#include "command.h"
7e258d18 28#include "obstack.h"
51b57ded 29#include "language.h"
bd5635a1 30
7e258d18 31#include <string.h>
318bf84f
FF
32
33#ifndef DEV_TTY
34#define DEV_TTY "/dev/tty"
35#endif
36
d630b615
FF
37/* Unfortunately for debugging, stderr is usually a macro. Better if we
38 make a variable which has the same value and which is accessible when
39 debugging GDB with itself. */
40FILE *std_in = stdin;
41FILE *std_out = stdout;
42FILE *std_err = stderr;
43
318bf84f
FF
44/* Prototypes for local functions */
45
d630b615
FF
46static void
47dump_symtab PARAMS ((struct objfile *, struct symtab *, FILE *));
318bf84f 48
d630b615
FF
49static void
50dump_psymtab PARAMS ((struct objfile *, struct partial_symtab *, FILE *));
318bf84f 51
d630b615
FF
52static void
53dump_msymbols PARAMS ((struct objfile *, FILE *));
318bf84f 54
d630b615
FF
55static void
56dump_objfile PARAMS ((struct objfile *));
318bf84f
FF
57
58static void
d630b615 59printobjfiles_command PARAMS ((char *, int));
318bf84f
FF
60
61static int
62block_depth PARAMS ((struct block *));
63
64static void
65print_partial_symbol PARAMS ((struct partial_symbol *, int, char *, FILE *));
66
67static void
68printpsyms_command PARAMS ((char *, int));
69
70static void
71print_symbol PARAMS ((struct symbol *, int, FILE *));
72
73static void
74printsyms_command PARAMS ((char *, int));
75
76static void
77free_symtab_block PARAMS ((struct objfile *, struct block *));
78
79static void
80printmsyms_command PARAMS ((char *, int));
bd5635a1 81\f
bd5635a1
RP
82/* Free a struct block <- B and all the symbols defined in that block. */
83
84static void
318bf84f
FF
85free_symtab_block (objfile, b)
86 struct objfile *objfile;
bd5635a1
RP
87 struct block *b;
88{
89 register int i, n;
90 n = BLOCK_NSYMS (b);
91 for (i = 0; i < n; i++)
92 {
318bf84f 93 mfree (objfile -> md, SYMBOL_NAME (BLOCK_SYM (b, i)));
d630b615 94 mfree (objfile -> md, (PTR) BLOCK_SYM (b, i));
bd5635a1 95 }
d630b615 96 mfree (objfile -> md, (PTR) b);
bd5635a1
RP
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
029981e2 107void
bd5635a1
RP
108free_symtab (s)
109 register struct symtab *s;
110{
111 register int i, n;
112 register struct blockvector *bv;
bd5635a1
RP
113
114 switch (s->free_code)
115 {
116 case free_nothing:
029981e2 117 /* All the contents are part of a big block of memory (an obstack),
bd5635a1
RP
118 and some other symtab is in charge of freeing that block.
119 Therefore, do nothing. */
120 break;
121
122 case free_contents:
123 /* Here all the contents were malloc'ed structure by structure
124 and must be freed that way. */
125 /* First free the blocks (and their symbols. */
126 bv = BLOCKVECTOR (s);
127 n = BLOCKVECTOR_NBLOCKS (bv);
128 for (i = 0; i < n; i++)
318bf84f 129 free_symtab_block (s -> objfile, BLOCKVECTOR_BLOCK (bv, i));
bd5635a1 130 /* Free the blockvector itself. */
d630b615 131 mfree (s -> objfile -> md, (PTR) bv);
bd5635a1
RP
132 /* Also free the linetable. */
133
134 case free_linetable:
135 /* Everything will be freed either by our `free_ptr'
7e258d18 136 or by some other symtab, except for our linetable.
bd5635a1 137 Free that now. */
7e258d18 138 if (LINETABLE (s))
d630b615 139 mfree (s -> objfile -> md, (PTR) LINETABLE (s));
bd5635a1
RP
140 break;
141 }
142
143 /* If there is a single block of memory to free, free it. */
318bf84f
FF
144 if (s -> free_ptr != NULL)
145 mfree (s -> objfile -> md, s -> free_ptr);
bd5635a1
RP
146
147 /* Free source-related stuff */
318bf84f 148 if (s -> line_charpos != NULL)
d630b615 149 mfree (s -> objfile -> md, (PTR) s -> line_charpos);
318bf84f
FF
150 if (s -> fullname != NULL)
151 mfree (s -> objfile -> md, s -> fullname);
d630b615 152 mfree (s -> objfile -> md, (PTR) s);
bd5635a1 153}
bd5635a1 154
d630b615
FF
155static void
156dump_objfile (objfile)
318bf84f 157 struct objfile *objfile;
bd5635a1 158{
318bf84f
FF
159 struct symtab *symtab;
160 struct partial_symtab *psymtab;
bd5635a1 161
318bf84f
FF
162 printf_filtered ("\nObject file %s: ", objfile -> name);
163 printf_filtered ("Objfile at %x, bfd at %x, %d minsyms\n\n",
164 objfile, objfile -> obfd, objfile->minimal_symbol_count);
bd5635a1 165
318bf84f
FF
166 if (objfile -> psymtabs)
167 {
168 printf_filtered ("Psymtabs:\n");
169 for (psymtab = objfile -> psymtabs;
170 psymtab != NULL;
171 psymtab = psymtab -> next)
172 {
173 printf_filtered ("%s at %x, ", psymtab -> filename, psymtab);
174 if (psymtab -> objfile != objfile)
175 {
176 printf_filtered ("NOT ON CHAIN! ");
177 }
178 wrap_here (" ");
179 }
180 printf_filtered ("\n\n");
181 }
7e258d18 182
318bf84f
FF
183 if (objfile -> symtabs)
184 {
185 printf_filtered ("Symtabs:\n");
186 for (symtab = objfile -> symtabs;
187 symtab != NULL;
188 symtab = symtab->next)
189 {
190 printf_filtered ("%s at %x, ", symtab -> filename, symtab);
191 if (symtab -> objfile != objfile)
192 {
193 printf_filtered ("NOT ON CHAIN! ");
194 }
195 wrap_here (" ");
196 }
197 printf_filtered ("\n\n");
198 }
318bf84f
FF
199}
200
d630b615
FF
201/* Print minimal symbols from this objfile. */
202
203static void
204dump_msymbols (objfile, outfile)
318bf84f 205 struct objfile *objfile;
d630b615 206 FILE *outfile;
318bf84f 207{
318bf84f
FF
208 struct minimal_symbol *msymbol;
209 int index;
210 char ms_type;
bd5635a1 211
d630b615
FF
212 fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile -> name);
213 for (index = 0, msymbol = objfile -> msymbols;
214 msymbol -> name != NULL; msymbol++, index++)
318bf84f 215 {
d630b615 216 switch (msymbol -> type)
318bf84f 217 {
d630b615
FF
218 case mst_unknown:
219 ms_type = 'u';
220 break;
221 case mst_text:
222 ms_type = 't';
223 break;
224 case mst_data:
225 ms_type = 'd';
226 break;
227 case mst_bss:
228 ms_type = 'b';
229 break;
230 case mst_abs:
231 ms_type = 'a';
232 break;
233 default:
234 ms_type = '?';
235 break;
318bf84f 236 }
d630b615
FF
237 fprintf_filtered (outfile, "[%2d] %c %#10x %s\n", index, ms_type,
238 msymbol -> address, msymbol -> name);
239 }
240 if (objfile -> minimal_symbol_count != index)
241 {
242 warning ("internal error: minimal symbol count %d != %d",
243 objfile -> minimal_symbol_count, index);
318bf84f 244 }
d630b615 245 fprintf_filtered (outfile, "\n");
318bf84f 246}
bd5635a1 247
d630b615
FF
248static void
249dump_psymtab (objfile, psymtab, outfile)
318bf84f
FF
250 struct objfile *objfile;
251 struct partial_symtab *psymtab;
d630b615 252 FILE *outfile;
318bf84f 253{
bd5635a1 254
d630b615
FF
255 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
256 psymtab -> filename);
257 fprintf_filtered (outfile, "(object 0x%x)\n\n", psymtab);
258 fprintf (outfile, " Read from object file %s (0x%x)\n",
51b57ded 259 objfile -> name, (unsigned int) objfile);
d630b615
FF
260
261 if (psymtab -> readin)
bd5635a1 262 {
d630b615
FF
263 fprintf_filtered (outfile,
264 " Full symtab was read (at 0x%x by function at 0x%x)\n",
265 psymtab -> symtab, psymtab -> read_symtab);
318bf84f 266 }
2670f34d
JG
267
268 /* FIXME, we need to be able to print the relocation stuff. */
269 /* This prints some garbage for anything but stabs right now. FIXME. */
270 fprintf_filtered (outfile, " Relocate symbols by 0x%x, 0x%x, 0x%x, 0x%x.\n",
271 ANOFFSET (psymtab->section_offsets, 0),
272 ANOFFSET (psymtab->section_offsets, 1),
273 ANOFFSET (psymtab->section_offsets, 2),
274 ANOFFSET (psymtab->section_offsets, 3));
275
d630b615
FF
276 fprintf_filtered (outfile, " Symbols cover text addresses 0x%x-0x%x\n",
277 psymtab -> textlow, psymtab -> texthigh);
278 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
279 psymtab -> number_of_dependencies);
280 if (psymtab -> n_global_syms > 0)
281 {
282 print_partial_symbol (objfile -> global_psymbols.list
283 + psymtab -> globals_offset,
284 psymtab -> n_global_syms, "Global", outfile);
285 }
286 if (psymtab -> n_static_syms > 0)
287 {
288 print_partial_symbol (objfile -> static_psymbols.list
289 + psymtab -> statics_offset,
290 psymtab -> n_static_syms, "Static", outfile);
291 }
292 fprintf_filtered (outfile, "\n");
318bf84f 293}
7e258d18 294
d630b615
FF
295static void
296dump_symtab (objfile, symtab, outfile)
318bf84f
FF
297 struct objfile *objfile;
298 struct symtab *symtab;
d630b615 299 FILE *outfile;
318bf84f 300{
318bf84f
FF
301 register int i, j;
302 int len, blen;
303 register struct linetable *l;
304 struct blockvector *bv;
305 register struct block *b;
306 int depth;
7e258d18 307
d630b615
FF
308 fprintf (outfile, "\nSymtab for file %s\n", symtab->filename);
309 fprintf (outfile, "Read from object file %s (%x)\n", objfile->name,
51b57ded 310 (unsigned int) objfile);
d630b615
FF
311 fprintf (outfile, "Language: %s\n", language_str (symtab -> language));
312
313 /* First print the line table. */
314 l = LINETABLE (symtab);
315 if (l) {
316 fprintf (outfile, "\nLine table:\n\n");
317 len = l->nitems;
318 for (i = 0; i < len; i++)
319 fprintf (outfile, " line %d at %x\n", l->item[i].line,
320 l->item[i].pc);
321 }
322 /* Now print the block info. */
323 fprintf (outfile, "\nBlockvector:\n\n");
324 bv = BLOCKVECTOR (symtab);
325 len = BLOCKVECTOR_NBLOCKS (bv);
326 for (i = 0; i < len; i++)
318bf84f 327 {
d630b615
FF
328 b = BLOCKVECTOR_BLOCK (bv, i);
329 depth = block_depth (b) * 2;
330 print_spaces (depth, outfile);
51b57ded 331 fprintf (outfile, "block #%03d (object 0x%x) ", i, (unsigned int) b);
d630b615
FF
332 fprintf (outfile, "[0x%x..0x%x]", BLOCK_START (b), BLOCK_END (b));
333 if (BLOCK_SUPERBLOCK (b))
51b57ded 334 fprintf (outfile, " (under 0x%x)", (unsigned int) BLOCK_SUPERBLOCK (b));
d630b615
FF
335 if (BLOCK_FUNCTION (b))
336 fprintf (outfile, " %s", SYMBOL_NAME (BLOCK_FUNCTION (b)));
337 fputc ('\n', outfile);
338 blen = BLOCK_NSYMS (b);
339 for (j = 0; j < blen; j++)
bd5635a1 340 {
d630b615 341 print_symbol (BLOCK_SYM (b, j), depth + 1, outfile);
bd5635a1 342 }
318bf84f 343 }
d630b615 344 fprintf (outfile, "\n");
318bf84f 345}
bd5635a1 346
318bf84f
FF
347static void
348printsyms_command (args, from_tty)
349 char *args;
350 int from_tty;
351{
352 char **argv;
353 FILE *outfile;
354 struct cleanup *cleanups;
355 char *symname = NULL;
356 char *filename = DEV_TTY;
d630b615
FF
357 struct objfile *objfile;
358 struct symtab *s;
318bf84f
FF
359
360 dont_repeat ();
361
362 if (args == NULL)
363 {
364 error ("printsyms takes an output file name and optional symbol file name");
365 }
366 else if ((argv = buildargv (args)) == NULL)
367 {
368 nomem (0);
369 }
370 cleanups = make_cleanup (freeargv, (char *) argv);
371
372 if (argv[0] != NULL)
373 {
374 filename = argv[0];
375 /* If a second arg is supplied, it is a source file name to match on */
376 if (argv[1] != NULL)
377 {
378 symname = argv[1];
379 }
bd5635a1
RP
380 }
381
318bf84f
FF
382 filename = tilde_expand (filename);
383 make_cleanup (free, filename);
384
385 outfile = fopen (filename, "w");
386 if (outfile == 0)
387 perror_with_name (filename);
388 make_cleanup (fclose, (char *) outfile);
389
390 immediate_quit++;
d630b615
FF
391 ALL_SYMTABS (objfile, s)
392 if (symname == NULL || (strcmp (symname, s -> filename) == 0))
393 dump_symtab (objfile, s, outfile);
bd5635a1
RP
394 immediate_quit--;
395 do_cleanups (cleanups);
396}
397
398static void
399print_symbol (symbol, depth, outfile)
400 struct symbol *symbol;
401 int depth;
402 FILE *outfile;
403{
404 print_spaces (depth, outfile);
405 if (SYMBOL_NAMESPACE (symbol) == LABEL_NAMESPACE)
406 {
407 fprintf (outfile, "label %s at 0x%x\n", SYMBOL_NAME (symbol),
408 SYMBOL_VALUE_ADDRESS (symbol));
409 return;
410 }
411 if (SYMBOL_NAMESPACE (symbol) == STRUCT_NAMESPACE)
412 {
413 if (TYPE_NAME (SYMBOL_TYPE (symbol)))
414 {
415 type_print_1 (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
416 }
417 else
418 {
419 fprintf (outfile, "%s %s = ",
420 (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
421 ? "enum"
422 : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
423 ? "struct" : "union")),
424 SYMBOL_NAME (symbol));
425 type_print_1 (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
426 }
427 fprintf (outfile, ";\n");
428 }
429 else
430 {
431 if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
432 fprintf (outfile, "typedef ");
433 if (SYMBOL_TYPE (symbol))
434 {
d630b615
FF
435 /* Print details of types, except for enums where it's clutter. */
436 type_print_1 (SYMBOL_TYPE (symbol), SYMBOL_NAME (symbol), outfile,
437 TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
438 depth);
bd5635a1
RP
439 fprintf (outfile, "; ");
440 }
441 else
442 fprintf (outfile, "%s ", SYMBOL_NAME (symbol));
443
444 switch (SYMBOL_CLASS (symbol))
445 {
446 case LOC_CONST:
447 fprintf (outfile, "const %ld (0x%lx),",
448 SYMBOL_VALUE (symbol), SYMBOL_VALUE (symbol));
449 break;
450
451 case LOC_CONST_BYTES:
452 fprintf (outfile, "const %u hex bytes:",
453 TYPE_LENGTH (SYMBOL_TYPE (symbol)));
454 {
455 unsigned i;
456 for (i = 0; i < TYPE_LENGTH (SYMBOL_TYPE (symbol)); i++)
457 fprintf (outfile, " %2x",
458 (unsigned)SYMBOL_VALUE_BYTES (symbol) [i]);
459 fprintf (outfile, ",");
460 }
461 break;
462
463 case LOC_STATIC:
464 fprintf (outfile, "static at 0x%x,", SYMBOL_VALUE_ADDRESS (symbol));
465 break;
466
467 case LOC_REGISTER:
468 fprintf (outfile, "register %ld,", SYMBOL_VALUE (symbol));
469 break;
470
471 case LOC_ARG:
51b57ded
FF
472 if (SYMBOL_BASEREG_VALID (symbol))
473 {
474 fprintf (outfile, "arg at 0x%lx from register %d,",
475 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
476 }
477 else
478 {
479 fprintf (outfile, "arg at 0x%lx,", SYMBOL_VALUE (symbol));
480 }
bd5635a1
RP
481 break;
482
483 case LOC_LOCAL_ARG:
51b57ded
FF
484 if (SYMBOL_BASEREG_VALID (symbol))
485 {
486 fprintf (outfile, "arg at offset 0x%lx from register %d,",
487 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
488 }
489 else
490 {
491 fprintf (outfile, "arg at offset 0x%lx from fp,",
492 SYMBOL_VALUE (symbol));
493 }
bd5635a1
RP
494
495 case LOC_REF_ARG:
496 fprintf (outfile, "reference arg at 0x%lx,", SYMBOL_VALUE (symbol));
497 break;
498
499 case LOC_REGPARM:
500 fprintf (outfile, "parameter register %ld,", SYMBOL_VALUE (symbol));
501 break;
502
503 case LOC_LOCAL:
51b57ded
FF
504 if (SYMBOL_BASEREG_VALID (symbol))
505 {
506 fprintf (outfile, "local at 0x%lx from register %d",
507 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
508 }
509 else
510 {
511 fprintf (outfile, "local at 0x%lx,", SYMBOL_VALUE (symbol));
512 }
bd5635a1
RP
513 break;
514
515 case LOC_TYPEDEF:
516 break;
517
518 case LOC_LABEL:
519 fprintf (outfile, "label at 0x%lx", SYMBOL_VALUE_ADDRESS (symbol));
520 break;
521
522 case LOC_BLOCK:
523 fprintf (outfile, "block (object 0x%x) starting at 0x%x,",
51b57ded 524 (unsigned int) SYMBOL_BLOCK_VALUE (symbol),
bd5635a1
RP
525 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol)));
526 break;
527
bd5635a1
RP
528 default:
529 fprintf (outfile, "botched symbol class %x", SYMBOL_CLASS (symbol));
530 break;
531 }
532 }
533 fprintf (outfile, "\n");
534}
535
318bf84f
FF
536static void
537printpsyms_command (args, from_tty)
538 char *args;
539 int from_tty;
4a35d6e9 540{
318bf84f 541 char **argv;
4a35d6e9 542 FILE *outfile;
4a35d6e9 543 struct cleanup *cleanups;
318bf84f
FF
544 char *symname = NULL;
545 char *filename = DEV_TTY;
d630b615
FF
546 struct objfile *objfile;
547 struct partial_symtab *ps;
4a35d6e9 548
318bf84f 549 dont_repeat ();
4a35d6e9 550
318bf84f
FF
551 if (args == NULL)
552 {
553 error ("printpsyms takes an output file name and optional symbol file name");
554 }
555 else if ((argv = buildargv (args)) == NULL)
556 {
557 nomem (0);
558 }
559 cleanups = make_cleanup (freeargv, (char *) argv);
560
561 if (argv[0] != NULL)
562 {
563 filename = argv[0];
564 /* If a second arg is supplied, it is a source file name to match on */
565 if (argv[1] != NULL)
566 {
567 symname = argv[1];
568 }
569 }
7e258d18 570
4a35d6e9
FF
571 filename = tilde_expand (filename);
572 make_cleanup (free, filename);
573
574 outfile = fopen (filename, "w");
575 if (outfile == 0)
576 perror_with_name (filename);
318bf84f 577 make_cleanup (fclose, outfile);
4a35d6e9 578
4a35d6e9 579 immediate_quit++;
d630b615
FF
580 ALL_PSYMTABS (objfile, ps)
581 if (symname == NULL || (strcmp (symname, ps -> filename) == 0))
582 dump_psymtab (objfile, ps, outfile);
4a35d6e9
FF
583 immediate_quit--;
584 do_cleanups (cleanups);
585}
586
587static void
588print_partial_symbol (p, count, what, outfile)
318bf84f
FF
589 struct partial_symbol *p;
590 int count;
591 char *what;
592 FILE *outfile;
4a35d6e9 593{
4a35d6e9
FF
594
595 fprintf_filtered (outfile, " %s partial symbols:\n", what);
596 while (count-- > 0)
597 {
598 fprintf_filtered (outfile, " `%s', ", SYMBOL_NAME(p));
599 switch (SYMBOL_NAMESPACE (p))
600 {
601 case UNDEF_NAMESPACE:
602 fputs_filtered ("undefined namespace, ", outfile);
603 break;
604 case VAR_NAMESPACE:
605 /* This is the usual thing -- don't print it */
606 break;
607 case STRUCT_NAMESPACE:
608 fputs_filtered ("struct namespace, ", outfile);
609 break;
610 case LABEL_NAMESPACE:
611 fputs_filtered ("label namespace, ", outfile);
612 break;
613 default:
614 fputs_filtered ("<invalid namespace>, ", outfile);
615 break;
616 }
617 switch (SYMBOL_CLASS (p))
618 {
619 case LOC_UNDEF:
620 fputs_filtered ("undefined", outfile);
621 break;
622 case LOC_CONST:
623 fputs_filtered ("constant int", outfile);
624 break;
625 case LOC_STATIC:
626 fputs_filtered ("static", outfile);
627 break;
628 case LOC_REGISTER:
629 fputs_filtered ("register", outfile);
630 break;
631 case LOC_ARG:
632 fputs_filtered ("pass by value", outfile);
633 break;
634 case LOC_REF_ARG:
635 fputs_filtered ("pass by reference", outfile);
636 break;
637 case LOC_REGPARM:
638 fputs_filtered ("register parameter", outfile);
639 break;
640 case LOC_LOCAL:
641 fputs_filtered ("stack parameter", outfile);
642 break;
643 case LOC_TYPEDEF:
644 fputs_filtered ("type", outfile);
645 break;
646 case LOC_LABEL:
647 fputs_filtered ("label", outfile);
648 break;
649 case LOC_BLOCK:
650 fputs_filtered ("function", outfile);
651 break;
652 case LOC_CONST_BYTES:
653 fputs_filtered ("constant bytes", outfile);
654 break;
655 case LOC_LOCAL_ARG:
656 fputs_filtered ("shuffled arg", outfile);
657 break;
658 default:
659 fputs_filtered ("<invalid location>", outfile);
660 break;
661 }
662 fputs_filtered (", ", outfile);
663 fprintf_filtered (outfile, "0x%x\n", SYMBOL_VALUE (p));
664 p++;
665 }
666}
667
318bf84f
FF
668static void
669printmsyms_command (args, from_tty)
670 char *args;
671 int from_tty;
672{
673 char **argv;
674 FILE *outfile;
675 struct cleanup *cleanups;
676 char *filename = DEV_TTY;
677 char *symname = NULL;
d630b615 678 struct objfile *objfile;
bd5635a1 679
318bf84f
FF
680 dont_repeat ();
681
682 if (args == NULL)
683 {
684 error ("printmsyms takes an output file name and optional symbol file name");
685 }
686 else if ((argv = buildargv (args)) == NULL)
687 {
688 nomem (0);
689 }
690 cleanups = make_cleanup (freeargv, argv);
691
692 if (argv[0] != NULL)
693 {
694 filename = argv[0];
695 /* If a second arg is supplied, it is a source file name to match on */
696 if (argv[1] != NULL)
697 {
698 symname = argv[1];
699 }
700 }
701
702 filename = tilde_expand (filename);
703 make_cleanup (free, filename);
704
705 outfile = fopen (filename, "w");
706 if (outfile == 0)
707 perror_with_name (filename);
708 make_cleanup (fclose, outfile);
709
710 immediate_quit++;
d630b615
FF
711 ALL_OBJFILES (objfile)
712 if (symname == NULL || (strcmp (symname, objfile -> name) == 0))
713 dump_msymbols (objfile, outfile);
318bf84f
FF
714 immediate_quit--;
715 fprintf_filtered (outfile, "\n\n");
716 do_cleanups (cleanups);
717}
718
719static void
d630b615
FF
720printobjfiles_command (ignore, from_tty)
721 char *ignore;
722 int from_tty;
bd5635a1 723{
d630b615
FF
724 struct objfile *objfile;
725
318bf84f
FF
726 dont_repeat ();
727
728 immediate_quit++;
d630b615
FF
729 ALL_OBJFILES (objfile)
730 dump_objfile (objfile);
318bf84f 731 immediate_quit--;
bd5635a1 732}
bd5635a1 733\f
318bf84f 734/* Return the nexting depth of a block within other blocks in its symtab. */
7e258d18 735
318bf84f
FF
736static int
737block_depth (block)
738 struct block *block;
7e258d18 739{
318bf84f
FF
740 register int i = 0;
741 while (block = BLOCK_SUPERBLOCK (block)) i++;
742 return i;
7e258d18
PB
743}
744
318bf84f 745\f
346168a2
JG
746/* Increase the space allocated for LISTP, which is probably
747 global_psymbol_list or static_psymbol_list. This space will eventually
748 be freed in free_objfile(). */
7e258d18
PB
749
750void
318bf84f 751extend_psymbol_list (listp, objfile)
7e258d18 752 register struct psymbol_allocation_list *listp;
318bf84f 753 struct objfile *objfile;
7e258d18
PB
754{
755 int new_size;
756 if (listp->size == 0)
757 {
758 new_size = 255;
759 listp->list = (struct partial_symbol *)
318bf84f 760 xmmalloc (objfile -> md, new_size * sizeof (struct partial_symbol));
7e258d18
PB
761 }
762 else
763 {
764 new_size = listp->size * 2;
765 listp->list = (struct partial_symbol *)
318bf84f
FF
766 xmrealloc (objfile -> md, (char *) listp->list,
767 new_size * sizeof (struct partial_symbol));
7e258d18
PB
768 }
769 /* Next assumes we only went one over. Should be good if
770 program works correctly */
771 listp->next = listp->list + listp->size;
772 listp->size = new_size;
773}
774
b440b1e9
FF
775#ifdef DEBUG
776
777/* The work performed by this function is normally done by the macro
778 ADD_PSYMBOL_TO_LIST defined in symfile.h. When debugging gdb, this
779 function makes things easier. */
780
781void
782add_psymbol_to_list (name, namelength, namespace, class, listp, psymval)
783 char *name;
784 int namelength;
785 enum namespace namespace;
786 enum address_class class;
787 struct psymbol_allocation_list *listp;
788 unsigned long psymval;
789{
790 register struct partial_symbol *psym;
791
792 if (listp -> next >= listp -> list + listp -> size)
318bf84f 793 extend_psymbol_list (listp, objfile);
b440b1e9 794 psym = listp -> next++;
318bf84f 795 SYMBOL_NAME (psym) = (char *) obstack_alloc (&objfile->psymbol_obstack,
b440b1e9
FF
796 namelength + 1);
797 memcpy (SYMBOL_NAME (psym), name, namelength);
798 SYMBOL_NAME (psym)[namelength] = '\0';
799 SYMBOL_NAMESPACE (psym) = namespace;
800 SYMBOL_CLASS (psym) = class;
801 SYMBOL_VALUE (psym) = psymval;
802}
803
804/* The work performed by this function is normally done by the macro
805 ADD_PSYMBOL_ADDR_TO_LIST defined in symfile.h. When debugging gdb, this
806 function makes things easier. */
807
808void
809add_psymbol_addr_to_list (name, namelength, namespace, class, listp, psymval)
810 char *name;
811 int namelength;
812 enum namespace namespace;
813 enum address_class class;
814 struct psymbol_allocation_list *listp;
815 CORE_ADDR psymval;
816{
817 register struct partial_symbol *psym;
818
819 if (listp -> next >= listp -> list + listp -> size)
318bf84f 820 extend_psymbol_list (listp, objfile);
b440b1e9 821 psym = listp -> next++;
318bf84f 822 SYMBOL_NAME (psym) = (char *) obstack_alloc (&objfile->psymbol_obstack,
b440b1e9
FF
823 namelength + 1);
824 memcpy (SYMBOL_NAME (psym), name, namelength);
825 SYMBOL_NAME (psym)[namelength] = '\0';
826 SYMBOL_NAMESPACE (psym) = namespace;
827 SYMBOL_CLASS (psym) = class;
828 SYMBOL_VALUE_ADDRESS (psym) = psymval;
829}
830
831#endif /* DEBUG */
832
bd5635a1
RP
833void
834_initialize_symmisc ()
835{
318bf84f
FF
836 add_com ("printmsyms", class_obscure, printmsyms_command,
837 "Print dump of current minimal symbol definitions to file OUTFILE.\n\
7e258d18
PB
838If a SOURCE file is specified, dump only that file's symbols.");
839 add_com ("printpsyms", class_obscure, printpsyms_command,
840 "Print dump of current partial symbol definitions to file OUTFILE.\n\
841If a SOURCE file is specified, dump only that file's partial symbols.");
318bf84f
FF
842 add_com ("printsyms", class_obscure, printsyms_command,
843 "Print dump of current symbol definitions to file OUTFILE.\n\
844If a SOURCE file is specified, dump only that file's symbols.");
7e258d18
PB
845 add_com ("printobjfiles", class_obscure, printobjfiles_command,
846 "Print dump of current object file definitions.");
bd5635a1
RP
847}
848
This page took 0.117495 seconds and 4 git commands to generate.