* Makefile.in (VERSION): Bump to 4.7.4.
[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;
205 msymbol -> name != 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 }
d630b615
FF
228 fprintf_filtered (outfile, "[%2d] %c %#10x %s\n", index, ms_type,
229 msymbol -> address, msymbol -> name);
230 }
231 if (objfile -> minimal_symbol_count != index)
232 {
233 warning ("internal error: minimal symbol count %d != %d",
234 objfile -> minimal_symbol_count, index);
318bf84f 235 }
d630b615 236 fprintf_filtered (outfile, "\n");
318bf84f 237}
bd5635a1 238
d630b615
FF
239static void
240dump_psymtab (objfile, psymtab, outfile)
318bf84f
FF
241 struct objfile *objfile;
242 struct partial_symtab *psymtab;
d630b615 243 FILE *outfile;
318bf84f 244{
bd5635a1 245
d630b615
FF
246 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
247 psymtab -> filename);
248 fprintf_filtered (outfile, "(object 0x%x)\n\n", psymtab);
249 fprintf (outfile, " Read from object file %s (0x%x)\n",
51b57ded 250 objfile -> name, (unsigned int) objfile);
d630b615
FF
251
252 if (psymtab -> readin)
bd5635a1 253 {
d630b615
FF
254 fprintf_filtered (outfile,
255 " Full symtab was read (at 0x%x by function at 0x%x)\n",
256 psymtab -> symtab, psymtab -> read_symtab);
318bf84f 257 }
2670f34d
JG
258
259 /* FIXME, we need to be able to print the relocation stuff. */
260 /* This prints some garbage for anything but stabs right now. FIXME. */
a8a69e63
FF
261 if (psymtab->section_offsets)
262 fprintf_filtered (outfile, " Relocate symbols by 0x%x, 0x%x, 0x%x, 0x%x.\n",
263 ANOFFSET (psymtab->section_offsets, 0),
264 ANOFFSET (psymtab->section_offsets, 1),
265 ANOFFSET (psymtab->section_offsets, 2),
266 ANOFFSET (psymtab->section_offsets, 3));
2670f34d 267
d630b615
FF
268 fprintf_filtered (outfile, " Symbols cover text addresses 0x%x-0x%x\n",
269 psymtab -> textlow, psymtab -> texthigh);
270 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
271 psymtab -> number_of_dependencies);
272 if (psymtab -> n_global_syms > 0)
273 {
274 print_partial_symbol (objfile -> global_psymbols.list
275 + psymtab -> globals_offset,
276 psymtab -> n_global_syms, "Global", outfile);
277 }
278 if (psymtab -> n_static_syms > 0)
279 {
280 print_partial_symbol (objfile -> static_psymbols.list
281 + psymtab -> statics_offset,
282 psymtab -> n_static_syms, "Static", outfile);
283 }
284 fprintf_filtered (outfile, "\n");
318bf84f 285}
7e258d18 286
d630b615
FF
287static void
288dump_symtab (objfile, symtab, outfile)
318bf84f
FF
289 struct objfile *objfile;
290 struct symtab *symtab;
d630b615 291 FILE *outfile;
318bf84f 292{
318bf84f
FF
293 register int i, j;
294 int len, blen;
295 register struct linetable *l;
296 struct blockvector *bv;
297 register struct block *b;
298 int depth;
7e258d18 299
d630b615
FF
300 fprintf (outfile, "\nSymtab for file %s\n", symtab->filename);
301 fprintf (outfile, "Read from object file %s (%x)\n", objfile->name,
51b57ded 302 (unsigned int) objfile);
d630b615
FF
303 fprintf (outfile, "Language: %s\n", language_str (symtab -> language));
304
305 /* First print the line table. */
306 l = LINETABLE (symtab);
307 if (l) {
308 fprintf (outfile, "\nLine table:\n\n");
309 len = l->nitems;
310 for (i = 0; i < len; i++)
311 fprintf (outfile, " line %d at %x\n", l->item[i].line,
312 l->item[i].pc);
313 }
314 /* Now print the block info. */
315 fprintf (outfile, "\nBlockvector:\n\n");
316 bv = BLOCKVECTOR (symtab);
317 len = BLOCKVECTOR_NBLOCKS (bv);
318 for (i = 0; i < len; i++)
318bf84f 319 {
d630b615
FF
320 b = BLOCKVECTOR_BLOCK (bv, i);
321 depth = block_depth (b) * 2;
322 print_spaces (depth, outfile);
51b57ded 323 fprintf (outfile, "block #%03d (object 0x%x) ", i, (unsigned int) b);
d630b615
FF
324 fprintf (outfile, "[0x%x..0x%x]", BLOCK_START (b), BLOCK_END (b));
325 if (BLOCK_SUPERBLOCK (b))
51b57ded 326 fprintf (outfile, " (under 0x%x)", (unsigned int) BLOCK_SUPERBLOCK (b));
d630b615
FF
327 if (BLOCK_FUNCTION (b))
328 fprintf (outfile, " %s", SYMBOL_NAME (BLOCK_FUNCTION (b)));
a8a69e63
FF
329 if (BLOCK_GCC_COMPILED(b))
330 fprintf (outfile, " gcc%d compiled", BLOCK_GCC_COMPILED(b));
d630b615
FF
331 fputc ('\n', outfile);
332 blen = BLOCK_NSYMS (b);
333 for (j = 0; j < blen; j++)
bd5635a1 334 {
d630b615 335 print_symbol (BLOCK_SYM (b, j), depth + 1, outfile);
bd5635a1 336 }
318bf84f 337 }
d630b615 338 fprintf (outfile, "\n");
318bf84f 339}
bd5635a1 340
a8a69e63
FF
341void
342maintenance_print_symbols (args, from_tty)
318bf84f
FF
343 char *args;
344 int from_tty;
345{
346 char **argv;
347 FILE *outfile;
348 struct cleanup *cleanups;
349 char *symname = NULL;
350 char *filename = DEV_TTY;
d630b615
FF
351 struct objfile *objfile;
352 struct symtab *s;
318bf84f
FF
353
354 dont_repeat ();
355
356 if (args == NULL)
357 {
a8a69e63 358 error ("print-symbols takes an output file name and optional symbol file name");
318bf84f
FF
359 }
360 else if ((argv = buildargv (args)) == NULL)
361 {
362 nomem (0);
363 }
364 cleanups = make_cleanup (freeargv, (char *) argv);
365
366 if (argv[0] != NULL)
367 {
368 filename = argv[0];
369 /* If a second arg is supplied, it is a source file name to match on */
370 if (argv[1] != NULL)
371 {
372 symname = argv[1];
373 }
bd5635a1
RP
374 }
375
318bf84f
FF
376 filename = tilde_expand (filename);
377 make_cleanup (free, filename);
378
379 outfile = fopen (filename, "w");
380 if (outfile == 0)
381 perror_with_name (filename);
382 make_cleanup (fclose, (char *) outfile);
383
384 immediate_quit++;
d630b615
FF
385 ALL_SYMTABS (objfile, s)
386 if (symname == NULL || (strcmp (symname, s -> filename) == 0))
387 dump_symtab (objfile, s, outfile);
bd5635a1
RP
388 immediate_quit--;
389 do_cleanups (cleanups);
390}
391
392static void
393print_symbol (symbol, depth, outfile)
394 struct symbol *symbol;
395 int depth;
396 FILE *outfile;
397{
398 print_spaces (depth, outfile);
399 if (SYMBOL_NAMESPACE (symbol) == LABEL_NAMESPACE)
400 {
401 fprintf (outfile, "label %s at 0x%x\n", SYMBOL_NAME (symbol),
402 SYMBOL_VALUE_ADDRESS (symbol));
403 return;
404 }
405 if (SYMBOL_NAMESPACE (symbol) == STRUCT_NAMESPACE)
406 {
407 if (TYPE_NAME (SYMBOL_TYPE (symbol)))
408 {
a8a69e63 409 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
bd5635a1
RP
410 }
411 else
412 {
413 fprintf (outfile, "%s %s = ",
414 (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
415 ? "enum"
416 : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
417 ? "struct" : "union")),
418 SYMBOL_NAME (symbol));
a8a69e63 419 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
bd5635a1
RP
420 }
421 fprintf (outfile, ";\n");
422 }
423 else
424 {
425 if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
426 fprintf (outfile, "typedef ");
427 if (SYMBOL_TYPE (symbol))
428 {
d630b615 429 /* Print details of types, except for enums where it's clutter. */
a8a69e63
FF
430 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_NAME (symbol), outfile,
431 TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
432 depth);
bd5635a1
RP
433 fprintf (outfile, "; ");
434 }
435 else
436 fprintf (outfile, "%s ", SYMBOL_NAME (symbol));
437
438 switch (SYMBOL_CLASS (symbol))
439 {
440 case LOC_CONST:
441 fprintf (outfile, "const %ld (0x%lx),",
442 SYMBOL_VALUE (symbol), SYMBOL_VALUE (symbol));
443 break;
444
445 case LOC_CONST_BYTES:
446 fprintf (outfile, "const %u hex bytes:",
447 TYPE_LENGTH (SYMBOL_TYPE (symbol)));
448 {
449 unsigned i;
450 for (i = 0; i < TYPE_LENGTH (SYMBOL_TYPE (symbol)); i++)
451 fprintf (outfile, " %2x",
452 (unsigned)SYMBOL_VALUE_BYTES (symbol) [i]);
453 fprintf (outfile, ",");
454 }
455 break;
456
457 case LOC_STATIC:
458 fprintf (outfile, "static at 0x%x,", SYMBOL_VALUE_ADDRESS (symbol));
459 break;
460
461 case LOC_REGISTER:
462 fprintf (outfile, "register %ld,", SYMBOL_VALUE (symbol));
463 break;
464
465 case LOC_ARG:
51b57ded
FF
466 if (SYMBOL_BASEREG_VALID (symbol))
467 {
468 fprintf (outfile, "arg at 0x%lx from register %d,",
469 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
470 }
471 else
472 {
473 fprintf (outfile, "arg at 0x%lx,", SYMBOL_VALUE (symbol));
474 }
bd5635a1
RP
475 break;
476
477 case LOC_LOCAL_ARG:
51b57ded
FF
478 if (SYMBOL_BASEREG_VALID (symbol))
479 {
480 fprintf (outfile, "arg at offset 0x%lx from register %d,",
481 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
482 }
483 else
484 {
485 fprintf (outfile, "arg at offset 0x%lx from fp,",
486 SYMBOL_VALUE (symbol));
487 }
bd5635a1
RP
488
489 case LOC_REF_ARG:
490 fprintf (outfile, "reference arg at 0x%lx,", SYMBOL_VALUE (symbol));
491 break;
492
493 case LOC_REGPARM:
494 fprintf (outfile, "parameter register %ld,", SYMBOL_VALUE (symbol));
495 break;
496
497 case LOC_LOCAL:
51b57ded
FF
498 if (SYMBOL_BASEREG_VALID (symbol))
499 {
500 fprintf (outfile, "local at 0x%lx from register %d",
501 SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
502 }
503 else
504 {
505 fprintf (outfile, "local at 0x%lx,", SYMBOL_VALUE (symbol));
506 }
bd5635a1
RP
507 break;
508
509 case LOC_TYPEDEF:
510 break;
511
512 case LOC_LABEL:
513 fprintf (outfile, "label at 0x%lx", SYMBOL_VALUE_ADDRESS (symbol));
514 break;
515
516 case LOC_BLOCK:
517 fprintf (outfile, "block (object 0x%x) starting at 0x%x,",
51b57ded 518 (unsigned int) SYMBOL_BLOCK_VALUE (symbol),
bd5635a1
RP
519 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol)));
520 break;
521
bd5635a1
RP
522 default:
523 fprintf (outfile, "botched symbol class %x", SYMBOL_CLASS (symbol));
524 break;
525 }
526 }
527 fprintf (outfile, "\n");
528}
529
a8a69e63
FF
530void
531maintenance_print_psymbols (args, from_tty)
318bf84f
FF
532 char *args;
533 int from_tty;
4a35d6e9 534{
318bf84f 535 char **argv;
4a35d6e9 536 FILE *outfile;
4a35d6e9 537 struct cleanup *cleanups;
318bf84f
FF
538 char *symname = NULL;
539 char *filename = DEV_TTY;
d630b615
FF
540 struct objfile *objfile;
541 struct partial_symtab *ps;
4a35d6e9 542
318bf84f 543 dont_repeat ();
4a35d6e9 544
318bf84f
FF
545 if (args == NULL)
546 {
a8a69e63 547 error ("print-psymbols takes an output file name and optional symbol file name");
318bf84f
FF
548 }
549 else if ((argv = buildargv (args)) == NULL)
550 {
551 nomem (0);
552 }
553 cleanups = make_cleanup (freeargv, (char *) argv);
554
555 if (argv[0] != NULL)
556 {
557 filename = argv[0];
558 /* If a second arg is supplied, it is a source file name to match on */
559 if (argv[1] != NULL)
560 {
561 symname = argv[1];
562 }
563 }
7e258d18 564
4a35d6e9
FF
565 filename = tilde_expand (filename);
566 make_cleanup (free, filename);
567
568 outfile = fopen (filename, "w");
569 if (outfile == 0)
570 perror_with_name (filename);
318bf84f 571 make_cleanup (fclose, outfile);
4a35d6e9 572
4a35d6e9 573 immediate_quit++;
d630b615
FF
574 ALL_PSYMTABS (objfile, ps)
575 if (symname == NULL || (strcmp (symname, ps -> filename) == 0))
576 dump_psymtab (objfile, ps, outfile);
4a35d6e9
FF
577 immediate_quit--;
578 do_cleanups (cleanups);
579}
580
581static void
582print_partial_symbol (p, count, what, outfile)
318bf84f
FF
583 struct partial_symbol *p;
584 int count;
585 char *what;
586 FILE *outfile;
4a35d6e9 587{
4a35d6e9
FF
588
589 fprintf_filtered (outfile, " %s partial symbols:\n", what);
590 while (count-- > 0)
591 {
592 fprintf_filtered (outfile, " `%s', ", SYMBOL_NAME(p));
593 switch (SYMBOL_NAMESPACE (p))
594 {
595 case UNDEF_NAMESPACE:
596 fputs_filtered ("undefined namespace, ", outfile);
597 break;
598 case VAR_NAMESPACE:
599 /* This is the usual thing -- don't print it */
600 break;
601 case STRUCT_NAMESPACE:
602 fputs_filtered ("struct namespace, ", outfile);
603 break;
604 case LABEL_NAMESPACE:
605 fputs_filtered ("label namespace, ", outfile);
606 break;
607 default:
608 fputs_filtered ("<invalid namespace>, ", outfile);
609 break;
610 }
611 switch (SYMBOL_CLASS (p))
612 {
613 case LOC_UNDEF:
614 fputs_filtered ("undefined", outfile);
615 break;
616 case LOC_CONST:
617 fputs_filtered ("constant int", outfile);
618 break;
619 case LOC_STATIC:
620 fputs_filtered ("static", outfile);
621 break;
622 case LOC_REGISTER:
623 fputs_filtered ("register", outfile);
624 break;
625 case LOC_ARG:
626 fputs_filtered ("pass by value", outfile);
627 break;
628 case LOC_REF_ARG:
629 fputs_filtered ("pass by reference", outfile);
630 break;
631 case LOC_REGPARM:
632 fputs_filtered ("register parameter", outfile);
633 break;
634 case LOC_LOCAL:
635 fputs_filtered ("stack parameter", outfile);
636 break;
637 case LOC_TYPEDEF:
638 fputs_filtered ("type", outfile);
639 break;
640 case LOC_LABEL:
641 fputs_filtered ("label", outfile);
642 break;
643 case LOC_BLOCK:
644 fputs_filtered ("function", outfile);
645 break;
646 case LOC_CONST_BYTES:
647 fputs_filtered ("constant bytes", outfile);
648 break;
649 case LOC_LOCAL_ARG:
650 fputs_filtered ("shuffled arg", outfile);
651 break;
652 default:
653 fputs_filtered ("<invalid location>", outfile);
654 break;
655 }
656 fputs_filtered (", ", outfile);
657 fprintf_filtered (outfile, "0x%x\n", SYMBOL_VALUE (p));
658 p++;
659 }
660}
661
a8a69e63
FF
662void
663maintenance_print_msymbols (args, from_tty)
318bf84f
FF
664 char *args;
665 int from_tty;
666{
667 char **argv;
668 FILE *outfile;
669 struct cleanup *cleanups;
670 char *filename = DEV_TTY;
671 char *symname = NULL;
d630b615 672 struct objfile *objfile;
bd5635a1 673
318bf84f
FF
674 dont_repeat ();
675
676 if (args == NULL)
677 {
a8a69e63 678 error ("print-msymbols takes an output file name and optional symbol file name");
318bf84f
FF
679 }
680 else if ((argv = buildargv (args)) == NULL)
681 {
682 nomem (0);
683 }
684 cleanups = make_cleanup (freeargv, argv);
685
686 if (argv[0] != NULL)
687 {
688 filename = argv[0];
689 /* If a second arg is supplied, it is a source file name to match on */
690 if (argv[1] != NULL)
691 {
692 symname = argv[1];
693 }
694 }
695
696 filename = tilde_expand (filename);
697 make_cleanup (free, filename);
698
699 outfile = fopen (filename, "w");
700 if (outfile == 0)
701 perror_with_name (filename);
702 make_cleanup (fclose, outfile);
703
704 immediate_quit++;
d630b615
FF
705 ALL_OBJFILES (objfile)
706 if (symname == NULL || (strcmp (symname, objfile -> name) == 0))
707 dump_msymbols (objfile, outfile);
318bf84f
FF
708 immediate_quit--;
709 fprintf_filtered (outfile, "\n\n");
710 do_cleanups (cleanups);
711}
712
a8a69e63
FF
713void
714maintenance_print_objfiles (ignore, from_tty)
d630b615
FF
715 char *ignore;
716 int from_tty;
bd5635a1 717{
d630b615
FF
718 struct objfile *objfile;
719
318bf84f
FF
720 dont_repeat ();
721
722 immediate_quit++;
d630b615
FF
723 ALL_OBJFILES (objfile)
724 dump_objfile (objfile);
318bf84f 725 immediate_quit--;
bd5635a1 726}
a8a69e63 727
bd5635a1 728\f
318bf84f 729/* Return the nexting depth of a block within other blocks in its symtab. */
7e258d18 730
318bf84f
FF
731static int
732block_depth (block)
733 struct block *block;
7e258d18 734{
318bf84f 735 register int i = 0;
a8a69e63
FF
736 while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
737 {
738 i++;
739 }
318bf84f 740 return i;
7e258d18
PB
741}
742
a8a69e63
FF
743#endif /* MAINTENANCE_CMDS */
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 */
This page took 0.125756 seconds and 4 git commands to generate.