* command.c (shell_escape, make_command, _initialze_command):
[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 57
318bf84f
FF
58static int
59block_depth PARAMS ((struct block *));
60
61static void
62print_partial_symbol PARAMS ((struct partial_symbol *, int, char *, FILE *));
63
318bf84f
FF
64static void
65print_symbol PARAMS ((struct symbol *, int, FILE *));
66
318bf84f
FF
67static void
68free_symtab_block PARAMS ((struct objfile *, struct block *));
69
bd5635a1 70\f
bd5635a1
RP
71/* Free a struct block <- B and all the symbols defined in that block. */
72
73static void
318bf84f
FF
74free_symtab_block (objfile, b)
75 struct objfile *objfile;
bd5635a1
RP
76 struct block *b;
77{
78 register int i, n;
79 n = BLOCK_NSYMS (b);
80 for (i = 0; i < n; i++)
81 {
318bf84f 82 mfree (objfile -> md, SYMBOL_NAME (BLOCK_SYM (b, i)));
d630b615 83 mfree (objfile -> md, (PTR) BLOCK_SYM (b, i));
bd5635a1 84 }
d630b615 85 mfree (objfile -> md, (PTR) b);
bd5635a1
RP
86}
87
88/* Free all the storage associated with the struct symtab <- S.
89 Note that some symtabs have contents malloc'ed structure by structure,
90 while some have contents that all live inside one big block of memory,
91 and some share the contents of another symbol table and so you should
92 not free the contents on their behalf (except sometimes the linetable,
93 which maybe per symtab even when the rest is not).
94 It is s->free_code that says which alternative to use. */
95
029981e2 96void
bd5635a1
RP
97free_symtab (s)
98 register struct symtab *s;
99{
100 register int i, n;
101 register struct blockvector *bv;
bd5635a1
RP
102
103 switch (s->free_code)
104 {
105 case free_nothing:
029981e2 106 /* All the contents are part of a big block of memory (an obstack),
bd5635a1
RP
107 and some other symtab is in charge of freeing that block.
108 Therefore, do nothing. */
109 break;
110
111 case free_contents:
112 /* Here all the contents were malloc'ed structure by structure
113 and must be freed that way. */
114 /* First free the blocks (and their symbols. */
115 bv = BLOCKVECTOR (s);
116 n = BLOCKVECTOR_NBLOCKS (bv);
117 for (i = 0; i < n; i++)
318bf84f 118 free_symtab_block (s -> objfile, BLOCKVECTOR_BLOCK (bv, i));
bd5635a1 119 /* Free the blockvector itself. */
d630b615 120 mfree (s -> objfile -> md, (PTR) bv);
bd5635a1
RP
121 /* Also free the linetable. */
122
123 case free_linetable:
124 /* Everything will be freed either by our `free_ptr'
7e258d18 125 or by some other symtab, except for our linetable.
bd5635a1 126 Free that now. */
7e258d18 127 if (LINETABLE (s))
d630b615 128 mfree (s -> objfile -> md, (PTR) LINETABLE (s));
bd5635a1
RP
129 break;
130 }
131
132 /* If there is a single block of memory to free, free it. */
318bf84f
FF
133 if (s -> free_ptr != NULL)
134 mfree (s -> objfile -> md, s -> free_ptr);
bd5635a1
RP
135
136 /* Free source-related stuff */
318bf84f 137 if (s -> line_charpos != NULL)
d630b615 138 mfree (s -> objfile -> md, (PTR) s -> line_charpos);
318bf84f
FF
139 if (s -> fullname != NULL)
140 mfree (s -> objfile -> md, s -> fullname);
d630b615 141 mfree (s -> objfile -> md, (PTR) s);
bd5635a1 142}
bd5635a1 143
a8a69e63
FF
144#if MAINTENANCE_CMDS
145
d630b615
FF
146static void
147dump_objfile (objfile)
318bf84f 148 struct objfile *objfile;
bd5635a1 149{
318bf84f
FF
150 struct symtab *symtab;
151 struct partial_symtab *psymtab;
bd5635a1 152
318bf84f
FF
153 printf_filtered ("\nObject file %s: ", objfile -> name);
154 printf_filtered ("Objfile at %x, bfd at %x, %d minsyms\n\n",
155 objfile, objfile -> obfd, objfile->minimal_symbol_count);
bd5635a1 156
318bf84f
FF
157 if (objfile -> psymtabs)
158 {
159 printf_filtered ("Psymtabs:\n");
160 for (psymtab = objfile -> psymtabs;
161 psymtab != NULL;
162 psymtab = psymtab -> next)
163 {
164 printf_filtered ("%s at %x, ", psymtab -> filename, psymtab);
165 if (psymtab -> objfile != objfile)
166 {
167 printf_filtered ("NOT ON CHAIN! ");
168 }
169 wrap_here (" ");
170 }
171 printf_filtered ("\n\n");
172 }
7e258d18 173
318bf84f
FF
174 if (objfile -> symtabs)
175 {
176 printf_filtered ("Symtabs:\n");
177 for (symtab = objfile -> symtabs;
178 symtab != NULL;
179 symtab = symtab->next)
180 {
181 printf_filtered ("%s at %x, ", symtab -> filename, symtab);
182 if (symtab -> objfile != objfile)
183 {
184 printf_filtered ("NOT ON CHAIN! ");
185 }
186 wrap_here (" ");
187 }
188 printf_filtered ("\n\n");
189 }
318bf84f
FF
190}
191
d630b615
FF
192/* Print minimal symbols from this objfile. */
193
194static void
195dump_msymbols (objfile, outfile)
318bf84f 196 struct objfile *objfile;
d630b615 197 FILE *outfile;
318bf84f 198{
318bf84f
FF
199 struct minimal_symbol *msymbol;
200 int index;
201 char ms_type;
bd5635a1 202
d630b615
FF
203 fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile -> name);
204 for (index = 0, msymbol = objfile -> msymbols;
2e4964ad 205 SYMBOL_NAME (msymbol) != NULL; msymbol++, index++)
318bf84f 206 {
d630b615 207 switch (msymbol -> type)
318bf84f 208 {
d630b615
FF
209 case mst_unknown:
210 ms_type = 'u';
211 break;
212 case mst_text:
213 ms_type = 't';
214 break;
215 case mst_data:
216 ms_type = 'd';
217 break;
218 case mst_bss:
219 ms_type = 'b';
220 break;
221 case mst_abs:
222 ms_type = 'a';
223 break;
224 default:
225 ms_type = '?';
226 break;
318bf84f 227 }
2e4964ad
FF
228 fprintf_filtered (outfile, "[%2d] %c %#10x %s", index, ms_type,
229 SYMBOL_VALUE_ADDRESS (msymbol), SYMBOL_NAME (msymbol));
7532cf10 230 if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
2e4964ad
FF
231 {
232 fprintf_filtered (outfile, " %s", SYMBOL_DEMANGLED_NAME (msymbol));
233 }
234 fputs_filtered ("\n", outfile);
d630b615
FF
235 }
236 if (objfile -> minimal_symbol_count != index)
237 {
238 warning ("internal error: minimal symbol count %d != %d",
239 objfile -> minimal_symbol_count, index);
318bf84f 240 }
d630b615 241 fprintf_filtered (outfile, "\n");
318bf84f 242}
bd5635a1 243
d630b615
FF
244static void
245dump_psymtab (objfile, psymtab, outfile)
318bf84f
FF
246 struct objfile *objfile;
247 struct partial_symtab *psymtab;
d630b615 248 FILE *outfile;
318bf84f 249{
bd5635a1 250
d630b615
FF
251 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
252 psymtab -> filename);
253 fprintf_filtered (outfile, "(object 0x%x)\n\n", psymtab);
254 fprintf (outfile, " Read from object file %s (0x%x)\n",
51b57ded 255 objfile -> name, (unsigned int) objfile);
d630b615
FF
256
257 if (psymtab -> readin)
bd5635a1 258 {
d630b615
FF
259 fprintf_filtered (outfile,
260 " Full symtab was read (at 0x%x by function at 0x%x)\n",
261 psymtab -> symtab, psymtab -> read_symtab);
318bf84f 262 }
2670f34d
JG
263
264 /* FIXME, we need to be able to print the relocation stuff. */
265 /* This prints some garbage for anything but stabs right now. FIXME. */
a8a69e63
FF
266 if (psymtab->section_offsets)
267 fprintf_filtered (outfile, " Relocate symbols by 0x%x, 0x%x, 0x%x, 0x%x.\n",
268 ANOFFSET (psymtab->section_offsets, 0),
269 ANOFFSET (psymtab->section_offsets, 1),
270 ANOFFSET (psymtab->section_offsets, 2),
271 ANOFFSET (psymtab->section_offsets, 3));
2670f34d 272
d630b615
FF
273 fprintf_filtered (outfile, " Symbols cover text addresses 0x%x-0x%x\n",
274 psymtab -> textlow, psymtab -> texthigh);
275 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
276 psymtab -> number_of_dependencies);
277 if (psymtab -> n_global_syms > 0)
278 {
279 print_partial_symbol (objfile -> global_psymbols.list
280 + psymtab -> globals_offset,
281 psymtab -> n_global_syms, "Global", outfile);
282 }
283 if (psymtab -> n_static_syms > 0)
284 {
285 print_partial_symbol (objfile -> static_psymbols.list
286 + psymtab -> statics_offset,
287 psymtab -> n_static_syms, "Static", outfile);
288 }
289 fprintf_filtered (outfile, "\n");
318bf84f 290}
7e258d18 291
d630b615
FF
292static void
293dump_symtab (objfile, symtab, outfile)
318bf84f
FF
294 struct objfile *objfile;
295 struct symtab *symtab;
d630b615 296 FILE *outfile;
318bf84f 297{
318bf84f
FF
298 register int i, j;
299 int len, blen;
300 register struct linetable *l;
301 struct blockvector *bv;
302 register struct block *b;
303 int depth;
7e258d18 304
d630b615
FF
305 fprintf (outfile, "\nSymtab for file %s\n", symtab->filename);
306 fprintf (outfile, "Read from object file %s (%x)\n", objfile->name,
51b57ded 307 (unsigned int) objfile);
d630b615
FF
308 fprintf (outfile, "Language: %s\n", language_str (symtab -> language));
309
310 /* First print the line table. */
311 l = LINETABLE (symtab);
312 if (l) {
313 fprintf (outfile, "\nLine table:\n\n");
314 len = l->nitems;
315 for (i = 0; i < len; i++)
316 fprintf (outfile, " line %d at %x\n", l->item[i].line,
317 l->item[i].pc);
318 }
319 /* Now print the block info. */
320 fprintf (outfile, "\nBlockvector:\n\n");
321 bv = BLOCKVECTOR (symtab);
322 len = BLOCKVECTOR_NBLOCKS (bv);
323 for (i = 0; i < len; i++)
318bf84f 324 {
d630b615
FF
325 b = BLOCKVECTOR_BLOCK (bv, i);
326 depth = block_depth (b) * 2;
327 print_spaces (depth, outfile);
51b57ded 328 fprintf (outfile, "block #%03d (object 0x%x) ", i, (unsigned int) b);
d630b615
FF
329 fprintf (outfile, "[0x%x..0x%x]", BLOCK_START (b), BLOCK_END (b));
330 if (BLOCK_SUPERBLOCK (b))
51b57ded 331 fprintf (outfile, " (under 0x%x)", (unsigned int) BLOCK_SUPERBLOCK (b));
d630b615 332 if (BLOCK_FUNCTION (b))
2e4964ad
FF
333 {
334 fprintf (outfile, " %s", SYMBOL_NAME (BLOCK_FUNCTION (b)));
7532cf10 335 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
2e4964ad
FF
336 {
337 fprintf (outfile, " %s",
338 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
339 }
340 }
a8a69e63
FF
341 if (BLOCK_GCC_COMPILED(b))
342 fprintf (outfile, " gcc%d compiled", BLOCK_GCC_COMPILED(b));
d630b615
FF
343 fputc ('\n', outfile);
344 blen = BLOCK_NSYMS (b);
345 for (j = 0; j < blen; j++)
bd5635a1 346 {
d630b615 347 print_symbol (BLOCK_SYM (b, j), depth + 1, outfile);
bd5635a1 348 }
318bf84f 349 }
d630b615 350 fprintf (outfile, "\n");
318bf84f 351}
bd5635a1 352
a8a69e63
FF
353void
354maintenance_print_symbols (args, from_tty)
318bf84f
FF
355 char *args;
356 int from_tty;
357{
358 char **argv;
359 FILE *outfile;
360 struct cleanup *cleanups;
361 char *symname = NULL;
362 char *filename = DEV_TTY;
d630b615
FF
363 struct objfile *objfile;
364 struct symtab *s;
318bf84f
FF
365
366 dont_repeat ();
367
368 if (args == NULL)
369 {
a8a69e63 370 error ("print-symbols takes an output file name and optional symbol file name");
318bf84f
FF
371 }
372 else if ((argv = buildargv (args)) == NULL)
373 {
374 nomem (0);
375 }
376 cleanups = make_cleanup (freeargv, (char *) argv);
377
378 if (argv[0] != NULL)
379 {
380 filename = argv[0];
381 /* If a second arg is supplied, it is a source file name to match on */
382 if (argv[1] != NULL)
383 {
384 symname = argv[1];
385 }
bd5635a1
RP
386 }
387
318bf84f
FF
388 filename = tilde_expand (filename);
389 make_cleanup (free, filename);
390
391 outfile = fopen (filename, "w");
392 if (outfile == 0)
393 perror_with_name (filename);
394 make_cleanup (fclose, (char *) outfile);
395
396 immediate_quit++;
d630b615 397 ALL_SYMTABS (objfile, s)
2e4964ad 398 if (symname == NULL || (STREQ (symname, s -> filename)))
d630b615 399 dump_symtab (objfile, s, outfile);
bd5635a1
RP
400 immediate_quit--;
401 do_cleanups (cleanups);
402}
403
404static void
405print_symbol (symbol, depth, outfile)
406 struct symbol *symbol;
407 int depth;
408 FILE *outfile;
409{
410 print_spaces (depth, outfile);
411 if (SYMBOL_NAMESPACE (symbol) == LABEL_NAMESPACE)
412 {
2e4964ad 413 fprintf (outfile, "label %s at 0x%x\n", SYMBOL_SOURCE_NAME (symbol),
bd5635a1
RP
414 SYMBOL_VALUE_ADDRESS (symbol));
415 return;
416 }
417 if (SYMBOL_NAMESPACE (symbol) == STRUCT_NAMESPACE)
418 {
419 if (TYPE_NAME (SYMBOL_TYPE (symbol)))
420 {
a8a69e63 421 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
bd5635a1
RP
422 }
423 else
424 {
425 fprintf (outfile, "%s %s = ",
426 (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
427 ? "enum"
428 : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
429 ? "struct" : "union")),
430 SYMBOL_NAME (symbol));
a8a69e63 431 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
bd5635a1
RP
432 }
433 fprintf (outfile, ";\n");
434 }
435 else
436 {
437 if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
438 fprintf (outfile, "typedef ");
439 if (SYMBOL_TYPE (symbol))
440 {
d630b615 441 /* Print details of types, except for enums where it's clutter. */
a8a69e63
FF
442 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_NAME (symbol), outfile,
443 TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
444 depth);
bd5635a1
RP
445 fprintf (outfile, "; ");
446 }
447 else
2e4964ad 448 fprintf (outfile, "%s ", SYMBOL_SOURCE_NAME (symbol));
bd5635a1
RP
449
450 switch (SYMBOL_CLASS (symbol))
451 {
452 case LOC_CONST:
453 fprintf (outfile, "const %ld (0x%lx),",
454 SYMBOL_VALUE (symbol), SYMBOL_VALUE (symbol));
455 break;
456
457 case LOC_CONST_BYTES:
458 fprintf (outfile, "const %u hex bytes:",
459 TYPE_LENGTH (SYMBOL_TYPE (symbol)));
460 {
461 unsigned i;
462 for (i = 0; i < TYPE_LENGTH (SYMBOL_TYPE (symbol)); i++)
463 fprintf (outfile, " %2x",
464 (unsigned)SYMBOL_VALUE_BYTES (symbol) [i]);
465 fprintf (outfile, ",");
466 }
467 break;
468
469 case LOC_STATIC:
470 fprintf (outfile, "static at 0x%x,", SYMBOL_VALUE_ADDRESS (symbol));
471 break;
472
473 case LOC_REGISTER:
474 fprintf (outfile, "register %ld,", SYMBOL_VALUE (symbol));
475 break;
476
477 case LOC_ARG:
51b57ded
FF
478 if (SYMBOL_BASEREG_VALID (symbol))
479 {
480 fprintf (outfile, "arg at 0x%lx from register %d,",
481 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
482 }
483 else
484 {
485 fprintf (outfile, "arg at 0x%lx,", SYMBOL_VALUE (symbol));
486 }
bd5635a1
RP
487 break;
488
489 case LOC_LOCAL_ARG:
51b57ded
FF
490 if (SYMBOL_BASEREG_VALID (symbol))
491 {
492 fprintf (outfile, "arg at offset 0x%lx from register %d,",
493 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
494 }
495 else
496 {
497 fprintf (outfile, "arg at offset 0x%lx from fp,",
498 SYMBOL_VALUE (symbol));
499 }
bd5635a1
RP
500
501 case LOC_REF_ARG:
502 fprintf (outfile, "reference arg at 0x%lx,", SYMBOL_VALUE (symbol));
503 break;
504
505 case LOC_REGPARM:
506 fprintf (outfile, "parameter register %ld,", SYMBOL_VALUE (symbol));
507 break;
508
509 case LOC_LOCAL:
51b57ded
FF
510 if (SYMBOL_BASEREG_VALID (symbol))
511 {
512 fprintf (outfile, "local at 0x%lx from register %d",
513 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
514 }
515 else
516 {
517 fprintf (outfile, "local at 0x%lx,", SYMBOL_VALUE (symbol));
518 }
bd5635a1
RP
519 break;
520
521 case LOC_TYPEDEF:
522 break;
523
524 case LOC_LABEL:
525 fprintf (outfile, "label at 0x%lx", SYMBOL_VALUE_ADDRESS (symbol));
526 break;
527
528 case LOC_BLOCK:
529 fprintf (outfile, "block (object 0x%x) starting at 0x%x,",
51b57ded 530 (unsigned int) SYMBOL_BLOCK_VALUE (symbol),
bd5635a1
RP
531 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol)));
532 break;
533
bd5635a1
RP
534 default:
535 fprintf (outfile, "botched symbol class %x", SYMBOL_CLASS (symbol));
536 break;
537 }
538 }
539 fprintf (outfile, "\n");
540}
541
a8a69e63
FF
542void
543maintenance_print_psymbols (args, from_tty)
318bf84f
FF
544 char *args;
545 int from_tty;
4a35d6e9 546{
318bf84f 547 char **argv;
4a35d6e9 548 FILE *outfile;
4a35d6e9 549 struct cleanup *cleanups;
318bf84f
FF
550 char *symname = NULL;
551 char *filename = DEV_TTY;
d630b615
FF
552 struct objfile *objfile;
553 struct partial_symtab *ps;
4a35d6e9 554
318bf84f 555 dont_repeat ();
4a35d6e9 556
318bf84f
FF
557 if (args == NULL)
558 {
a8a69e63 559 error ("print-psymbols takes an output file name and optional symbol file name");
318bf84f
FF
560 }
561 else if ((argv = buildargv (args)) == NULL)
562 {
563 nomem (0);
564 }
565 cleanups = make_cleanup (freeargv, (char *) argv);
566
567 if (argv[0] != NULL)
568 {
569 filename = argv[0];
570 /* If a second arg is supplied, it is a source file name to match on */
571 if (argv[1] != NULL)
572 {
573 symname = argv[1];
574 }
575 }
7e258d18 576
4a35d6e9
FF
577 filename = tilde_expand (filename);
578 make_cleanup (free, filename);
579
580 outfile = fopen (filename, "w");
581 if (outfile == 0)
582 perror_with_name (filename);
318bf84f 583 make_cleanup (fclose, outfile);
4a35d6e9 584
4a35d6e9 585 immediate_quit++;
d630b615 586 ALL_PSYMTABS (objfile, ps)
2e4964ad 587 if (symname == NULL || (STREQ (symname, ps -> filename)))
d630b615 588 dump_psymtab (objfile, ps, outfile);
4a35d6e9
FF
589 immediate_quit--;
590 do_cleanups (cleanups);
591}
592
593static void
594print_partial_symbol (p, count, what, outfile)
318bf84f
FF
595 struct partial_symbol *p;
596 int count;
597 char *what;
598 FILE *outfile;
4a35d6e9 599{
4a35d6e9
FF
600
601 fprintf_filtered (outfile, " %s partial symbols:\n", what);
602 while (count-- > 0)
603 {
2e4964ad 604 fprintf_filtered (outfile, " `%s'", SYMBOL_NAME(p));
7532cf10 605 if (SYMBOL_DEMANGLED_NAME (p) != NULL)
2e4964ad
FF
606 {
607 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (p));
608 }
609 fputs_filtered (", ", outfile);
4a35d6e9
FF
610 switch (SYMBOL_NAMESPACE (p))
611 {
612 case UNDEF_NAMESPACE:
613 fputs_filtered ("undefined namespace, ", outfile);
614 break;
615 case VAR_NAMESPACE:
616 /* This is the usual thing -- don't print it */
617 break;
618 case STRUCT_NAMESPACE:
619 fputs_filtered ("struct namespace, ", outfile);
620 break;
621 case LABEL_NAMESPACE:
622 fputs_filtered ("label namespace, ", outfile);
623 break;
624 default:
625 fputs_filtered ("<invalid namespace>, ", outfile);
626 break;
627 }
628 switch (SYMBOL_CLASS (p))
629 {
630 case LOC_UNDEF:
631 fputs_filtered ("undefined", outfile);
632 break;
633 case LOC_CONST:
634 fputs_filtered ("constant int", outfile);
635 break;
636 case LOC_STATIC:
637 fputs_filtered ("static", outfile);
638 break;
639 case LOC_REGISTER:
640 fputs_filtered ("register", outfile);
641 break;
642 case LOC_ARG:
643 fputs_filtered ("pass by value", outfile);
644 break;
645 case LOC_REF_ARG:
646 fputs_filtered ("pass by reference", outfile);
647 break;
648 case LOC_REGPARM:
649 fputs_filtered ("register parameter", outfile);
650 break;
651 case LOC_LOCAL:
652 fputs_filtered ("stack parameter", outfile);
653 break;
654 case LOC_TYPEDEF:
655 fputs_filtered ("type", outfile);
656 break;
657 case LOC_LABEL:
658 fputs_filtered ("label", outfile);
659 break;
660 case LOC_BLOCK:
661 fputs_filtered ("function", outfile);
662 break;
663 case LOC_CONST_BYTES:
664 fputs_filtered ("constant bytes", outfile);
665 break;
666 case LOC_LOCAL_ARG:
667 fputs_filtered ("shuffled arg", outfile);
668 break;
669 default:
670 fputs_filtered ("<invalid location>", outfile);
671 break;
672 }
673 fputs_filtered (", ", outfile);
674 fprintf_filtered (outfile, "0x%x\n", SYMBOL_VALUE (p));
675 p++;
676 }
677}
678
a8a69e63
FF
679void
680maintenance_print_msymbols (args, from_tty)
318bf84f
FF
681 char *args;
682 int from_tty;
683{
684 char **argv;
685 FILE *outfile;
686 struct cleanup *cleanups;
687 char *filename = DEV_TTY;
688 char *symname = NULL;
d630b615 689 struct objfile *objfile;
bd5635a1 690
318bf84f
FF
691 dont_repeat ();
692
693 if (args == NULL)
694 {
a8a69e63 695 error ("print-msymbols takes an output file name and optional symbol file name");
318bf84f
FF
696 }
697 else if ((argv = buildargv (args)) == NULL)
698 {
699 nomem (0);
700 }
701 cleanups = make_cleanup (freeargv, argv);
702
703 if (argv[0] != NULL)
704 {
705 filename = argv[0];
706 /* If a second arg is supplied, it is a source file name to match on */
707 if (argv[1] != NULL)
708 {
709 symname = argv[1];
710 }
711 }
712
713 filename = tilde_expand (filename);
714 make_cleanup (free, filename);
715
716 outfile = fopen (filename, "w");
717 if (outfile == 0)
718 perror_with_name (filename);
719 make_cleanup (fclose, outfile);
720
721 immediate_quit++;
d630b615 722 ALL_OBJFILES (objfile)
2e4964ad 723 if (symname == NULL || (STREQ (symname, objfile -> name)))
d630b615 724 dump_msymbols (objfile, outfile);
318bf84f
FF
725 immediate_quit--;
726 fprintf_filtered (outfile, "\n\n");
727 do_cleanups (cleanups);
728}
729
a8a69e63
FF
730void
731maintenance_print_objfiles (ignore, from_tty)
d630b615
FF
732 char *ignore;
733 int from_tty;
bd5635a1 734{
d630b615
FF
735 struct objfile *objfile;
736
318bf84f
FF
737 dont_repeat ();
738
739 immediate_quit++;
d630b615
FF
740 ALL_OBJFILES (objfile)
741 dump_objfile (objfile);
318bf84f 742 immediate_quit--;
bd5635a1 743}
a8a69e63 744
bd5635a1 745\f
318bf84f 746/* Return the nexting depth of a block within other blocks in its symtab. */
7e258d18 747
318bf84f
FF
748static int
749block_depth (block)
750 struct block *block;
7e258d18 751{
318bf84f 752 register int i = 0;
a8a69e63
FF
753 while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
754 {
755 i++;
756 }
318bf84f 757 return i;
7e258d18
PB
758}
759
a8a69e63
FF
760#endif /* MAINTENANCE_CMDS */
761
318bf84f 762\f
346168a2
JG
763/* Increase the space allocated for LISTP, which is probably
764 global_psymbol_list or static_psymbol_list. This space will eventually
765 be freed in free_objfile(). */
7e258d18
PB
766
767void
318bf84f 768extend_psymbol_list (listp, objfile)
7e258d18 769 register struct psymbol_allocation_list *listp;
318bf84f 770 struct objfile *objfile;
7e258d18
PB
771{
772 int new_size;
773 if (listp->size == 0)
774 {
775 new_size = 255;
776 listp->list = (struct partial_symbol *)
318bf84f 777 xmmalloc (objfile -> md, new_size * sizeof (struct partial_symbol));
7e258d18
PB
778 }
779 else
780 {
781 new_size = listp->size * 2;
782 listp->list = (struct partial_symbol *)
318bf84f
FF
783 xmrealloc (objfile -> md, (char *) listp->list,
784 new_size * sizeof (struct partial_symbol));
7e258d18
PB
785 }
786 /* Next assumes we only went one over. Should be good if
787 program works correctly */
788 listp->next = listp->list + listp->size;
789 listp->size = new_size;
790}
This page took 0.116477 seconds and 4 git commands to generate.