Tidy innerblock_complaint and blockvector_complaint.
[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 }
d630b615
FF
267 fprintf_filtered (outfile, " Relocate symbols by 0x%x\n",
268 psymtab -> addr);
269 fprintf_filtered (outfile, " Symbols cover text addresses 0x%x-0x%x\n",
270 psymtab -> textlow, psymtab -> texthigh);
271 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
272 psymtab -> number_of_dependencies);
273 if (psymtab -> n_global_syms > 0)
274 {
275 print_partial_symbol (objfile -> global_psymbols.list
276 + psymtab -> globals_offset,
277 psymtab -> n_global_syms, "Global", outfile);
278 }
279 if (psymtab -> n_static_syms > 0)
280 {
281 print_partial_symbol (objfile -> static_psymbols.list
282 + psymtab -> statics_offset,
283 psymtab -> n_static_syms, "Static", outfile);
284 }
285 fprintf_filtered (outfile, "\n");
318bf84f 286}
7e258d18 287
d630b615
FF
288static void
289dump_symtab (objfile, symtab, outfile)
318bf84f
FF
290 struct objfile *objfile;
291 struct symtab *symtab;
d630b615 292 FILE *outfile;
318bf84f 293{
318bf84f
FF
294 register int i, j;
295 int len, blen;
296 register struct linetable *l;
297 struct blockvector *bv;
298 register struct block *b;
299 int depth;
7e258d18 300
d630b615
FF
301 fprintf (outfile, "\nSymtab for file %s\n", symtab->filename);
302 fprintf (outfile, "Read from object file %s (%x)\n", objfile->name,
51b57ded 303 (unsigned int) objfile);
d630b615
FF
304 fprintf (outfile, "Language: %s\n", language_str (symtab -> language));
305
306 /* First print the line table. */
307 l = LINETABLE (symtab);
308 if (l) {
309 fprintf (outfile, "\nLine table:\n\n");
310 len = l->nitems;
311 for (i = 0; i < len; i++)
312 fprintf (outfile, " line %d at %x\n", l->item[i].line,
313 l->item[i].pc);
314 }
315 /* Now print the block info. */
316 fprintf (outfile, "\nBlockvector:\n\n");
317 bv = BLOCKVECTOR (symtab);
318 len = BLOCKVECTOR_NBLOCKS (bv);
319 for (i = 0; i < len; i++)
318bf84f 320 {
d630b615
FF
321 b = BLOCKVECTOR_BLOCK (bv, i);
322 depth = block_depth (b) * 2;
323 print_spaces (depth, outfile);
51b57ded 324 fprintf (outfile, "block #%03d (object 0x%x) ", i, (unsigned int) b);
d630b615
FF
325 fprintf (outfile, "[0x%x..0x%x]", BLOCK_START (b), BLOCK_END (b));
326 if (BLOCK_SUPERBLOCK (b))
51b57ded 327 fprintf (outfile, " (under 0x%x)", (unsigned int) BLOCK_SUPERBLOCK (b));
d630b615
FF
328 if (BLOCK_FUNCTION (b))
329 fprintf (outfile, " %s", SYMBOL_NAME (BLOCK_FUNCTION (b)));
330 fputc ('\n', outfile);
331 blen = BLOCK_NSYMS (b);
332 for (j = 0; j < blen; j++)
bd5635a1 333 {
d630b615 334 print_symbol (BLOCK_SYM (b, j), depth + 1, outfile);
bd5635a1 335 }
318bf84f 336 }
d630b615 337 fprintf (outfile, "\n");
318bf84f 338}
bd5635a1 339
318bf84f
FF
340static void
341printsyms_command (args, from_tty)
342 char *args;
343 int from_tty;
344{
345 char **argv;
346 FILE *outfile;
347 struct cleanup *cleanups;
348 char *symname = NULL;
349 char *filename = DEV_TTY;
d630b615
FF
350 struct objfile *objfile;
351 struct symtab *s;
318bf84f
FF
352
353 dont_repeat ();
354
355 if (args == NULL)
356 {
357 error ("printsyms takes an output file name and optional symbol file name");
358 }
359 else if ((argv = buildargv (args)) == NULL)
360 {
361 nomem (0);
362 }
363 cleanups = make_cleanup (freeargv, (char *) argv);
364
365 if (argv[0] != NULL)
366 {
367 filename = argv[0];
368 /* If a second arg is supplied, it is a source file name to match on */
369 if (argv[1] != NULL)
370 {
371 symname = argv[1];
372 }
bd5635a1
RP
373 }
374
318bf84f
FF
375 filename = tilde_expand (filename);
376 make_cleanup (free, filename);
377
378 outfile = fopen (filename, "w");
379 if (outfile == 0)
380 perror_with_name (filename);
381 make_cleanup (fclose, (char *) outfile);
382
383 immediate_quit++;
d630b615
FF
384 ALL_SYMTABS (objfile, s)
385 if (symname == NULL || (strcmp (symname, s -> filename) == 0))
386 dump_symtab (objfile, s, outfile);
bd5635a1
RP
387 immediate_quit--;
388 do_cleanups (cleanups);
389}
390
391static void
392print_symbol (symbol, depth, outfile)
393 struct symbol *symbol;
394 int depth;
395 FILE *outfile;
396{
397 print_spaces (depth, outfile);
398 if (SYMBOL_NAMESPACE (symbol) == LABEL_NAMESPACE)
399 {
400 fprintf (outfile, "label %s at 0x%x\n", SYMBOL_NAME (symbol),
401 SYMBOL_VALUE_ADDRESS (symbol));
402 return;
403 }
404 if (SYMBOL_NAMESPACE (symbol) == STRUCT_NAMESPACE)
405 {
406 if (TYPE_NAME (SYMBOL_TYPE (symbol)))
407 {
408 type_print_1 (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
409 }
410 else
411 {
412 fprintf (outfile, "%s %s = ",
413 (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
414 ? "enum"
415 : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
416 ? "struct" : "union")),
417 SYMBOL_NAME (symbol));
418 type_print_1 (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
419 }
420 fprintf (outfile, ";\n");
421 }
422 else
423 {
424 if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
425 fprintf (outfile, "typedef ");
426 if (SYMBOL_TYPE (symbol))
427 {
d630b615
FF
428 /* Print details of types, except for enums where it's clutter. */
429 type_print_1 (SYMBOL_TYPE (symbol), SYMBOL_NAME (symbol), outfile,
430 TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
431 depth);
bd5635a1
RP
432 fprintf (outfile, "; ");
433 }
434 else
435 fprintf (outfile, "%s ", SYMBOL_NAME (symbol));
436
437 switch (SYMBOL_CLASS (symbol))
438 {
439 case LOC_CONST:
440 fprintf (outfile, "const %ld (0x%lx),",
441 SYMBOL_VALUE (symbol), SYMBOL_VALUE (symbol));
442 break;
443
444 case LOC_CONST_BYTES:
445 fprintf (outfile, "const %u hex bytes:",
446 TYPE_LENGTH (SYMBOL_TYPE (symbol)));
447 {
448 unsigned i;
449 for (i = 0; i < TYPE_LENGTH (SYMBOL_TYPE (symbol)); i++)
450 fprintf (outfile, " %2x",
451 (unsigned)SYMBOL_VALUE_BYTES (symbol) [i]);
452 fprintf (outfile, ",");
453 }
454 break;
455
456 case LOC_STATIC:
457 fprintf (outfile, "static at 0x%x,", SYMBOL_VALUE_ADDRESS (symbol));
458 break;
459
460 case LOC_REGISTER:
461 fprintf (outfile, "register %ld,", SYMBOL_VALUE (symbol));
462 break;
463
464 case LOC_ARG:
51b57ded
FF
465 if (SYMBOL_BASEREG_VALID (symbol))
466 {
467 fprintf (outfile, "arg at 0x%lx from register %d,",
468 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
469 }
470 else
471 {
472 fprintf (outfile, "arg at 0x%lx,", SYMBOL_VALUE (symbol));
473 }
bd5635a1
RP
474 break;
475
476 case LOC_LOCAL_ARG:
51b57ded
FF
477 if (SYMBOL_BASEREG_VALID (symbol))
478 {
479 fprintf (outfile, "arg at offset 0x%lx from register %d,",
480 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
481 }
482 else
483 {
484 fprintf (outfile, "arg at offset 0x%lx from fp,",
485 SYMBOL_VALUE (symbol));
486 }
bd5635a1
RP
487
488 case LOC_REF_ARG:
489 fprintf (outfile, "reference arg at 0x%lx,", SYMBOL_VALUE (symbol));
490 break;
491
492 case LOC_REGPARM:
493 fprintf (outfile, "parameter register %ld,", SYMBOL_VALUE (symbol));
494 break;
495
496 case LOC_LOCAL:
51b57ded
FF
497 if (SYMBOL_BASEREG_VALID (symbol))
498 {
499 fprintf (outfile, "local at 0x%lx from register %d",
500 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
501 }
502 else
503 {
504 fprintf (outfile, "local at 0x%lx,", SYMBOL_VALUE (symbol));
505 }
bd5635a1
RP
506 break;
507
508 case LOC_TYPEDEF:
509 break;
510
511 case LOC_LABEL:
512 fprintf (outfile, "label at 0x%lx", SYMBOL_VALUE_ADDRESS (symbol));
513 break;
514
515 case LOC_BLOCK:
516 fprintf (outfile, "block (object 0x%x) starting at 0x%x,",
51b57ded 517 (unsigned int) SYMBOL_BLOCK_VALUE (symbol),
bd5635a1
RP
518 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol)));
519 break;
520
bd5635a1
RP
521 default:
522 fprintf (outfile, "botched symbol class %x", SYMBOL_CLASS (symbol));
523 break;
524 }
525 }
526 fprintf (outfile, "\n");
527}
528
318bf84f
FF
529static void
530printpsyms_command (args, from_tty)
531 char *args;
532 int from_tty;
4a35d6e9 533{
318bf84f 534 char **argv;
4a35d6e9 535 FILE *outfile;
4a35d6e9 536 struct cleanup *cleanups;
318bf84f
FF
537 char *symname = NULL;
538 char *filename = DEV_TTY;
d630b615
FF
539 struct objfile *objfile;
540 struct partial_symtab *ps;
4a35d6e9 541
318bf84f 542 dont_repeat ();
4a35d6e9 543
318bf84f
FF
544 if (args == NULL)
545 {
546 error ("printpsyms takes an output file name and optional symbol file name");
547 }
548 else if ((argv = buildargv (args)) == NULL)
549 {
550 nomem (0);
551 }
552 cleanups = make_cleanup (freeargv, (char *) argv);
553
554 if (argv[0] != NULL)
555 {
556 filename = argv[0];
557 /* If a second arg is supplied, it is a source file name to match on */
558 if (argv[1] != NULL)
559 {
560 symname = argv[1];
561 }
562 }
7e258d18 563
4a35d6e9
FF
564 filename = tilde_expand (filename);
565 make_cleanup (free, filename);
566
567 outfile = fopen (filename, "w");
568 if (outfile == 0)
569 perror_with_name (filename);
318bf84f 570 make_cleanup (fclose, outfile);
4a35d6e9 571
4a35d6e9 572 immediate_quit++;
d630b615
FF
573 ALL_PSYMTABS (objfile, ps)
574 if (symname == NULL || (strcmp (symname, ps -> filename) == 0))
575 dump_psymtab (objfile, ps, outfile);
4a35d6e9
FF
576 immediate_quit--;
577 do_cleanups (cleanups);
578}
579
580static void
581print_partial_symbol (p, count, what, outfile)
318bf84f
FF
582 struct partial_symbol *p;
583 int count;
584 char *what;
585 FILE *outfile;
4a35d6e9 586{
4a35d6e9
FF
587
588 fprintf_filtered (outfile, " %s partial symbols:\n", what);
589 while (count-- > 0)
590 {
591 fprintf_filtered (outfile, " `%s', ", SYMBOL_NAME(p));
592 switch (SYMBOL_NAMESPACE (p))
593 {
594 case UNDEF_NAMESPACE:
595 fputs_filtered ("undefined namespace, ", outfile);
596 break;
597 case VAR_NAMESPACE:
598 /* This is the usual thing -- don't print it */
599 break;
600 case STRUCT_NAMESPACE:
601 fputs_filtered ("struct namespace, ", outfile);
602 break;
603 case LABEL_NAMESPACE:
604 fputs_filtered ("label namespace, ", outfile);
605 break;
606 default:
607 fputs_filtered ("<invalid namespace>, ", outfile);
608 break;
609 }
610 switch (SYMBOL_CLASS (p))
611 {
612 case LOC_UNDEF:
613 fputs_filtered ("undefined", outfile);
614 break;
615 case LOC_CONST:
616 fputs_filtered ("constant int", outfile);
617 break;
618 case LOC_STATIC:
619 fputs_filtered ("static", outfile);
620 break;
621 case LOC_REGISTER:
622 fputs_filtered ("register", outfile);
623 break;
624 case LOC_ARG:
625 fputs_filtered ("pass by value", outfile);
626 break;
627 case LOC_REF_ARG:
628 fputs_filtered ("pass by reference", outfile);
629 break;
630 case LOC_REGPARM:
631 fputs_filtered ("register parameter", outfile);
632 break;
633 case LOC_LOCAL:
634 fputs_filtered ("stack parameter", outfile);
635 break;
636 case LOC_TYPEDEF:
637 fputs_filtered ("type", outfile);
638 break;
639 case LOC_LABEL:
640 fputs_filtered ("label", outfile);
641 break;
642 case LOC_BLOCK:
643 fputs_filtered ("function", outfile);
644 break;
645 case LOC_CONST_BYTES:
646 fputs_filtered ("constant bytes", outfile);
647 break;
648 case LOC_LOCAL_ARG:
649 fputs_filtered ("shuffled arg", outfile);
650 break;
651 default:
652 fputs_filtered ("<invalid location>", outfile);
653 break;
654 }
655 fputs_filtered (", ", outfile);
656 fprintf_filtered (outfile, "0x%x\n", SYMBOL_VALUE (p));
657 p++;
658 }
659}
660
318bf84f
FF
661static void
662printmsyms_command (args, from_tty)
663 char *args;
664 int from_tty;
665{
666 char **argv;
667 FILE *outfile;
668 struct cleanup *cleanups;
669 char *filename = DEV_TTY;
670 char *symname = NULL;
d630b615 671 struct objfile *objfile;
bd5635a1 672
318bf84f
FF
673 dont_repeat ();
674
675 if (args == NULL)
676 {
677 error ("printmsyms takes an output file name and optional symbol file name");
678 }
679 else if ((argv = buildargv (args)) == NULL)
680 {
681 nomem (0);
682 }
683 cleanups = make_cleanup (freeargv, argv);
684
685 if (argv[0] != NULL)
686 {
687 filename = argv[0];
688 /* If a second arg is supplied, it is a source file name to match on */
689 if (argv[1] != NULL)
690 {
691 symname = argv[1];
692 }
693 }
694
695 filename = tilde_expand (filename);
696 make_cleanup (free, filename);
697
698 outfile = fopen (filename, "w");
699 if (outfile == 0)
700 perror_with_name (filename);
701 make_cleanup (fclose, outfile);
702
703 immediate_quit++;
d630b615
FF
704 ALL_OBJFILES (objfile)
705 if (symname == NULL || (strcmp (symname, objfile -> name) == 0))
706 dump_msymbols (objfile, outfile);
318bf84f
FF
707 immediate_quit--;
708 fprintf_filtered (outfile, "\n\n");
709 do_cleanups (cleanups);
710}
711
712static void
d630b615
FF
713printobjfiles_command (ignore, from_tty)
714 char *ignore;
715 int from_tty;
bd5635a1 716{
d630b615
FF
717 struct objfile *objfile;
718
318bf84f
FF
719 dont_repeat ();
720
721 immediate_quit++;
d630b615
FF
722 ALL_OBJFILES (objfile)
723 dump_objfile (objfile);
318bf84f 724 immediate_quit--;
bd5635a1 725}
bd5635a1 726\f
318bf84f 727/* Return the nexting depth of a block within other blocks in its symtab. */
7e258d18 728
318bf84f
FF
729static int
730block_depth (block)
731 struct block *block;
7e258d18 732{
318bf84f
FF
733 register int i = 0;
734 while (block = BLOCK_SUPERBLOCK (block)) i++;
735 return i;
7e258d18
PB
736}
737
318bf84f 738\f
346168a2
JG
739/* Increase the space allocated for LISTP, which is probably
740 global_psymbol_list or static_psymbol_list. This space will eventually
741 be freed in free_objfile(). */
7e258d18
PB
742
743void
318bf84f 744extend_psymbol_list (listp, objfile)
7e258d18 745 register struct psymbol_allocation_list *listp;
318bf84f 746 struct objfile *objfile;
7e258d18
PB
747{
748 int new_size;
749 if (listp->size == 0)
750 {
751 new_size = 255;
752 listp->list = (struct partial_symbol *)
318bf84f 753 xmmalloc (objfile -> md, new_size * sizeof (struct partial_symbol));
7e258d18
PB
754 }
755 else
756 {
757 new_size = listp->size * 2;
758 listp->list = (struct partial_symbol *)
318bf84f
FF
759 xmrealloc (objfile -> md, (char *) listp->list,
760 new_size * sizeof (struct partial_symbol));
7e258d18
PB
761 }
762 /* Next assumes we only went one over. Should be good if
763 program works correctly */
764 listp->next = listp->list + listp->size;
765 listp->size = new_size;
766}
767
b440b1e9
FF
768#ifdef DEBUG
769
770/* The work performed by this function is normally done by the macro
771 ADD_PSYMBOL_TO_LIST defined in symfile.h. When debugging gdb, this
772 function makes things easier. */
773
774void
775add_psymbol_to_list (name, namelength, namespace, class, listp, psymval)
776 char *name;
777 int namelength;
778 enum namespace namespace;
779 enum address_class class;
780 struct psymbol_allocation_list *listp;
781 unsigned long psymval;
782{
783 register struct partial_symbol *psym;
784
785 if (listp -> next >= listp -> list + listp -> size)
318bf84f 786 extend_psymbol_list (listp, objfile);
b440b1e9 787 psym = listp -> next++;
318bf84f 788 SYMBOL_NAME (psym) = (char *) obstack_alloc (&objfile->psymbol_obstack,
b440b1e9
FF
789 namelength + 1);
790 memcpy (SYMBOL_NAME (psym), name, namelength);
791 SYMBOL_NAME (psym)[namelength] = '\0';
792 SYMBOL_NAMESPACE (psym) = namespace;
793 SYMBOL_CLASS (psym) = class;
794 SYMBOL_VALUE (psym) = psymval;
795}
796
797/* The work performed by this function is normally done by the macro
798 ADD_PSYMBOL_ADDR_TO_LIST defined in symfile.h. When debugging gdb, this
799 function makes things easier. */
800
801void
802add_psymbol_addr_to_list (name, namelength, namespace, class, listp, psymval)
803 char *name;
804 int namelength;
805 enum namespace namespace;
806 enum address_class class;
807 struct psymbol_allocation_list *listp;
808 CORE_ADDR psymval;
809{
810 register struct partial_symbol *psym;
811
812 if (listp -> next >= listp -> list + listp -> size)
318bf84f 813 extend_psymbol_list (listp, objfile);
b440b1e9 814 psym = listp -> next++;
318bf84f 815 SYMBOL_NAME (psym) = (char *) obstack_alloc (&objfile->psymbol_obstack,
b440b1e9
FF
816 namelength + 1);
817 memcpy (SYMBOL_NAME (psym), name, namelength);
818 SYMBOL_NAME (psym)[namelength] = '\0';
819 SYMBOL_NAMESPACE (psym) = namespace;
820 SYMBOL_CLASS (psym) = class;
821 SYMBOL_VALUE_ADDRESS (psym) = psymval;
822}
823
824#endif /* DEBUG */
825
bd5635a1
RP
826void
827_initialize_symmisc ()
828{
318bf84f
FF
829 add_com ("printmsyms", class_obscure, printmsyms_command,
830 "Print dump of current minimal symbol definitions to file OUTFILE.\n\
7e258d18
PB
831If a SOURCE file is specified, dump only that file's symbols.");
832 add_com ("printpsyms", class_obscure, printpsyms_command,
833 "Print dump of current partial symbol definitions to file OUTFILE.\n\
834If a SOURCE file is specified, dump only that file's partial symbols.");
318bf84f
FF
835 add_com ("printsyms", class_obscure, printsyms_command,
836 "Print dump of current symbol definitions to file OUTFILE.\n\
837If a SOURCE file is specified, dump only that file's symbols.");
7e258d18
PB
838 add_com ("printobjfiles", class_obscure, printobjfiles_command,
839 "Print dump of current object file definitions.");
bd5635a1
RP
840}
841
This page took 0.098082 seconds and 4 git commands to generate.