Lint and some rs/6000 port.
[deliverable/binutils-gdb.git] / gdb / buildsym.c
CommitLineData
c0302457
JG
1/* Build symbol tables in GDB's internal format.
2 Copyright (C) 1986-1991 Free Software Foundation, Inc.
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
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
17along with this program; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20/* This module provides subroutines used for creating and adding to
21 the symbol table. These routines are called from various symbol-
22 file-reading routines.
23
24 They originated in dbxread.c of gdb-4.2, and were split out to
25 make xcoffread.c more maintainable by sharing code. */
26
27#include "defs.h"
28#include "param.h"
29#include "obstack.h"
30#include "symtab.h"
31#include "breakpoint.h"
32#include "gdbcore.h" /* for bfd stuff for symfile.h */
33#include "symfile.h" /* Needed for "struct complaint" */
34#include "stab.gnu.h" /* We always use GNU stabs, not native */
35#include <stdio.h>
36#include <string.h>
37#include <ctype.h>
38
39/* Ask buildsym.h to define the vars it normally declares `extern'. */
40#define EXTERN /**/
41#include "buildsym.h" /* Our own declarations */
42#undef EXTERN
43
44extern void qsort ();
45extern double atof ();
46
47/* Things we export from outside, and probably shouldn't. FIXME. */
48extern void new_object_header_files ();
c0302457
JG
49extern char *next_symbol_text ();
50extern int hashname ();
4137c5fc
JG
51extern void patch_block_stabs (); /* AIX xcoffread.c */
52#define patch_block_stabs abort /* FIXME scaffolding */
c0302457 53\f
abefb1f1 54
c0302457
JG
55static void cleanup_undefined_types ();
56static void fix_common_block ();
57
58static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER,'\0' };
59static const char vb_name[] = { '_','v','b',CPLUS_MARKER,'\0' };
60
61/* Define this as 1 if a pcc declaration of a char or short argument
62 gives the correct address. Otherwise assume pcc gives the
63 address of the corresponding int, which is not the same on a
64 big-endian machine. */
65
66#ifndef BELIEVE_PCC_PROMOTION
67#define BELIEVE_PCC_PROMOTION 0
68#endif
69
70/* Make a list of forward references which haven't been defined. */
71static struct type **undef_types;
72static int undef_types_allocated, undef_types_length;
73
4137c5fc
JG
74/* Initial sizes of data structures. These are realloc'd larger if needed,
75 and realloc'd down to the size actually used, when completed. */
76
77#define INITIAL_CONTEXT_STACK_SIZE 10
78#define INITIAL_TYPE_VECTOR_LENGTH 160
79#define INITIAL_LINE_VECTOR_LENGTH 1000
c0302457
JG
80\f
81/* Complaints about the symbols we have encountered. */
82
83struct complaint innerblock_complaint =
84 {"inner block not inside outer block in %s", 0, 0};
85
86struct complaint blockvector_complaint =
87 {"block at %x out of order", 0, 0};
88
89#if 0
90struct complaint dbx_class_complaint =
91 {"encountered DBX-style class variable debugging information.\n\
92You seem to have compiled your program with \
93\"g++ -g0\" instead of \"g++ -g\".\n\
94Therefore GDB will not know about your class variables", 0, 0};
95#endif
96
97struct complaint const_vol_complaint =
98 {"const/volatile indicator missing (ok if using g++ v1.x), got '%c'", 0, 0};
99
100struct complaint error_type_complaint =
101 {"debug info mismatch between compiler and debugger", 0, 0};
102
103struct complaint invalid_member_complaint =
104 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
105
106struct complaint range_type_base_complaint =
107 {"base type %d of range type is not defined", 0, 0};
108\f
109/* Look up a dbx type-number pair. Return the address of the slot
110 where the type for that number-pair is stored.
111 The number-pair is in TYPENUMS.
112
113 This can be used for finding the type associated with that pair
114 or for associating a new type with the pair. */
115
116struct type **
117dbx_lookup_type (typenums)
118 int typenums[2];
119{
120 register int filenum = typenums[0], index = typenums[1];
121
122 if (filenum < 0 || filenum >= n_this_object_header_files)
123 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
124 filenum, index, symnum);
125
126 if (filenum == 0)
127 {
128 /* Type is defined outside of header files.
129 Find it in this object file's type vector. */
130 while (index >= type_vector_length)
131 {
132 type_vector_length *= 2;
133 type_vector = (struct type **)
134 xrealloc (type_vector,
135 (type_vector_length * sizeof (struct type *)));
136 bzero (&type_vector[type_vector_length / 2],
137 type_vector_length * sizeof (struct type *) / 2);
138 }
139 return &type_vector[index];
140 }
141 else
142 {
143 register int real_filenum = this_object_header_files[filenum];
144 register struct header_file *f;
145 int f_orig_length;
146
147 if (real_filenum >= n_header_files)
148 abort ();
149
150 f = &header_files[real_filenum];
151
152 f_orig_length = f->length;
153 if (index >= f_orig_length)
154 {
155 while (index >= f->length)
156 f->length *= 2;
157 f->vector = (struct type **)
158 xrealloc (f->vector, f->length * sizeof (struct type *));
159 bzero (&f->vector[f_orig_length],
160 (f->length - f_orig_length) * sizeof (struct type *));
161 }
162 return &f->vector[index];
163 }
164}
165
166/* Create a type object. Occaisionally used when you need a type
167 which isn't going to be given a type number. */
168
169struct type *
170dbx_create_type ()
171{
172 register struct type *type =
173 (struct type *) obstack_alloc (symbol_obstack, sizeof (struct type));
174
175 bzero (type, sizeof (struct type));
176 TYPE_VPTR_FIELDNO (type) = -1;
177 TYPE_VPTR_BASETYPE (type) = 0;
178 return type;
179}
180
181/* Make sure there is a type allocated for type numbers TYPENUMS
182 and return the type object.
183 This can create an empty (zeroed) type object.
4137c5fc 184OBSOLETE -- call dbx_create_type instead -- FIXME:
c0302457
JG
185 TYPENUMS may be (-1, -1) to return a new type object that is not
186 put into the type vector, and so may not be referred to by number. */
187
188struct type *
189dbx_alloc_type (typenums)
190 int typenums[2];
191{
192 register struct type **type_addr;
193 register struct type *type;
194
195 if (typenums[1] != -1)
196 {
197 type_addr = dbx_lookup_type (typenums);
198 type = *type_addr;
199 }
200 else
201 {
4137c5fc 202 abort(); /* FIXME -- Must give a real type number now */
c0302457
JG
203 type_addr = 0;
204 type = 0;
205 }
206
207 /* If we are referring to a type not known at all yet,
208 allocate an empty type for it.
209 We will fill it in later if we find out how. */
210 if (type == 0)
211 {
212 type = dbx_create_type ();
213 if (type_addr)
214 *type_addr = type;
215 }
216
217 return type;
218}
219\f
220/* maintain the lists of symbols and blocks */
221
222/* Add a symbol to one of the lists of symbols. */
223void
224add_symbol_to_list (symbol, listhead)
225 struct symbol *symbol;
226 struct pending **listhead;
227{
228 /* We keep PENDINGSIZE symbols in each link of the list.
229 If we don't have a link with room in it, add a new link. */
230 if (*listhead == 0 || (*listhead)->nsyms == PENDINGSIZE)
231 {
232 register struct pending *link;
233 if (free_pendings)
234 {
235 link = free_pendings;
236 free_pendings = link->next;
237 }
238 else
239 link = (struct pending *) xmalloc (sizeof (struct pending));
240
241 link->next = *listhead;
242 *listhead = link;
243 link->nsyms = 0;
244 }
245
246 (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
247}
248
249/* At end of reading syms, or in case of quit,
250 really free as many `struct pending's as we can easily find. */
251
252/* ARGSUSED */
253void
254really_free_pendings (foo)
255 int foo;
256{
257 struct pending *next, *next1;
258#if 0
259 struct pending_block *bnext, *bnext1;
260#endif
261
262 for (next = free_pendings; next; next = next1)
263 {
264 next1 = next->next;
265 free (next);
266 }
267 free_pendings = 0;
268
269#if 0 /* Now we make the links in the symbol_obstack, so don't free them. */
270 for (bnext = pending_blocks; bnext; bnext = bnext1)
271 {
272 bnext1 = bnext->next;
273 free (bnext);
274 }
275#endif
276 pending_blocks = 0;
277
278 for (next = file_symbols; next; next = next1)
279 {
280 next1 = next->next;
281 free (next);
282 }
283 file_symbols = 0;
284
285 for (next = global_symbols; next; next = next1)
286 {
287 next1 = next->next;
288 free (next);
289 }
290 global_symbols = 0;
291}
292
293/* Take one of the lists of symbols and make a block from it.
294 Keep the order the symbols have in the list (reversed from the input file).
295 Put the block on the list of pending blocks. */
296
297void
298finish_block (symbol, listhead, old_blocks, start, end)
299 struct symbol *symbol;
300 struct pending **listhead;
301 struct pending_block *old_blocks;
302 CORE_ADDR start, end;
303{
304 register struct pending *next, *next1;
305 register struct block *block;
306 register struct pending_block *pblock;
307 struct pending_block *opblock;
308 register int i;
309
310 /* Count the length of the list of symbols. */
311
312 for (next = *listhead, i = 0; next; i += next->nsyms, next = next->next)
313 /*EMPTY*/;
314
315 block = (struct block *) obstack_alloc (symbol_obstack,
316 (sizeof (struct block)
317 + ((i - 1)
318 * sizeof (struct symbol *))));
319
320 /* Copy the symbols into the block. */
321
322 BLOCK_NSYMS (block) = i;
323 for (next = *listhead; next; next = next->next)
324 {
325 register int j;
326 for (j = next->nsyms - 1; j >= 0; j--)
327 BLOCK_SYM (block, --i) = next->symbol[j];
328 }
329
330 BLOCK_START (block) = start;
331 BLOCK_END (block) = end;
332 BLOCK_SUPERBLOCK (block) = 0; /* Filled in when containing block is made */
333 BLOCK_GCC_COMPILED (block) = processing_gcc_compilation;
334
335 /* Put the block in as the value of the symbol that names it. */
336
337 if (symbol)
338 {
339 SYMBOL_BLOCK_VALUE (symbol) = block;
340 BLOCK_FUNCTION (block) = symbol;
341 }
342 else
343 BLOCK_FUNCTION (block) = 0;
344
345 /* Now "free" the links of the list, and empty the list. */
346
347 for (next = *listhead; next; next = next1)
348 {
349 next1 = next->next;
350 next->next = free_pendings;
351 free_pendings = next;
352 }
353 *listhead = 0;
354
355 /* Install this block as the superblock
356 of all blocks made since the start of this scope
357 that don't have superblocks yet. */
358
359 opblock = 0;
360 for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next)
361 {
362 if (BLOCK_SUPERBLOCK (pblock->block) == 0) {
363#if 1
364 /* Check to be sure the blocks are nested as we receive them.
365 If the compiler/assembler/linker work, this just burns a small
366 amount of time. */
367 if (BLOCK_START (pblock->block) < BLOCK_START (block)
368 || BLOCK_END (pblock->block) > BLOCK_END (block)) {
369 complain(&innerblock_complaint, symbol? SYMBOL_NAME (symbol):
370 "(don't know)");
371 BLOCK_START (pblock->block) = BLOCK_START (block);
372 BLOCK_END (pblock->block) = BLOCK_END (block);
373 }
374#endif
375 BLOCK_SUPERBLOCK (pblock->block) = block;
376 }
377 opblock = pblock;
378 }
379
380 /* Record this block on the list of all blocks in the file.
381 Put it after opblock, or at the beginning if opblock is 0.
382 This puts the block in the list after all its subblocks. */
383
384 /* Allocate in the symbol_obstack to save time.
385 It wastes a little space. */
386 pblock = (struct pending_block *)
387 obstack_alloc (symbol_obstack,
388 sizeof (struct pending_block));
389 pblock->block = block;
390 if (opblock)
391 {
392 pblock->next = opblock->next;
393 opblock->next = pblock;
394 }
395 else
396 {
397 pblock->next = pending_blocks;
398 pending_blocks = pblock;
399 }
400}
401
402struct blockvector *
403make_blockvector ()
404{
405 register struct pending_block *next;
406 register struct blockvector *blockvector;
407 register int i;
408
409 /* Count the length of the list of blocks. */
410
411 for (next = pending_blocks, i = 0; next; next = next->next, i++);
412
413 blockvector = (struct blockvector *)
414 obstack_alloc (symbol_obstack,
415 (sizeof (struct blockvector)
416 + (i - 1) * sizeof (struct block *)));
417
418 /* Copy the blocks into the blockvector.
419 This is done in reverse order, which happens to put
420 the blocks into the proper order (ascending starting address).
421 finish_block has hair to insert each block into the list
422 after its subblocks in order to make sure this is true. */
423
424 BLOCKVECTOR_NBLOCKS (blockvector) = i;
425 for (next = pending_blocks; next; next = next->next) {
426 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
427 }
428
429#if 0 /* Now we make the links in the obstack, so don't free them. */
430 /* Now free the links of the list, and empty the list. */
431
432 for (next = pending_blocks; next; next = next1)
433 {
434 next1 = next->next;
435 free (next);
436 }
437#endif
438 pending_blocks = 0;
439
440#if 1 /* FIXME, shut this off after a while to speed up symbol reading. */
441 /* Some compilers output blocks in the wrong order, but we depend
442 on their being in the right order so we can binary search.
443 Check the order and moan about it. FIXME. */
444 if (BLOCKVECTOR_NBLOCKS (blockvector) > 1)
445 for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++) {
446 if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i-1))
447 > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i))) {
448 complain (&blockvector_complaint,
449 BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i)));
450 }
451 }
452#endif
453
454 return blockvector;
455}
456\f
4137c5fc
JG
457/* Start recording information about source code that came from an included
458 (or otherwise merged-in) source file with a different name. */
c0302457
JG
459
460void
4137c5fc
JG
461start_subfile (name, dirname)
462 char *name;
463 char *dirname;
464{
465 register struct subfile *subfile;
466
467 /* See if this subfile is already known as a subfile of the
468 current main source file. */
469
470 for (subfile = subfiles; subfile; subfile = subfile->next)
471 {
472 if (!strcmp (subfile->name, name))
473 {
474 current_subfile = subfile;
475 return;
476 }
477 }
478
479 /* This subfile is not known. Add an entry for it.
480 Make an entry for this subfile in the list of all subfiles
481 of the current main source file. */
482
483 subfile = (struct subfile *) xmalloc (sizeof (struct subfile));
484 subfile->next = subfiles;
485 subfiles = subfile;
486 current_subfile = subfile;
487
488 /* Save its name and compilation directory name */
489 subfile->name = obsavestring (name, strlen (name));
490 if (dirname == NULL)
491 subfile->dirname = NULL;
492 else
493 subfile->dirname = obsavestring (dirname, strlen (dirname));
494
495 /* Initialize line-number recording for this subfile. */
496 subfile->line_vector = 0;
497}
498\f
499/* Manage the vector of line numbers for each subfile. */
500
501void
502record_line (subfile, line, pc)
503 register struct subfile *subfile;
c0302457
JG
504 int line;
505 CORE_ADDR pc;
506{
507 struct linetable_entry *e;
508 /* Ignore the dummy line number in libg.o */
509
510 if (line == 0xffff)
511 return;
512
4137c5fc
JG
513 /* Make sure line vector exists and is big enough. */
514 if (!subfile->line_vector) {
515 subfile->line_vector_length = INITIAL_LINE_VECTOR_LENGTH;
516 subfile->line_vector = (struct linetable *)
517 xmalloc (sizeof (struct linetable)
518 + subfile->line_vector_length * sizeof (struct linetable_entry));
519 subfile->line_vector->nitems = 0;
520 }
c0302457 521
4137c5fc 522 if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length)
c0302457 523 {
4137c5fc
JG
524 subfile->line_vector_length *= 2;
525 subfile->line_vector = (struct linetable *)
526 xrealloc (subfile->line_vector, (sizeof (struct linetable)
527 + subfile->line_vector_length * sizeof (struct linetable_entry)));
c0302457
JG
528 }
529
4137c5fc 530 e = subfile->line_vector->item + subfile->line_vector->nitems++;
c0302457
JG
531 e->line = line; e->pc = pc;
532}
4137c5fc
JG
533
534
535/* Needed in order to sort line tables from IBM xcoff files. Sigh! */
536
537/* static */
538int
539compare_line_numbers (ln1, ln2)
540 struct linetable_entry *ln1, *ln2;
541{
542 return ln1->line - ln2->line;
543}
c0302457
JG
544\f
545/* Start a new symtab for a new source file.
546 This is called when a dbx symbol of type N_SO is seen;
547 it indicates the start of data for one original source file. */
548
549void
550start_symtab (name, dirname, start_addr)
551 char *name;
552 char *dirname;
553 CORE_ADDR start_addr;
554{
555
556 last_source_file = name;
557 last_source_start_addr = start_addr;
558 file_symbols = 0;
559 global_symbols = 0;
4137c5fc
JG
560 global_stabs = 0; /* AIX COFF */
561 file_stabs = 0; /* AIX COFF */
c0302457
JG
562 within_function = 0;
563
564 /* Context stack is initially empty, with room for 10 levels. */
4137c5fc
JG
565 context_stack_size = INITIAL_CONTEXT_STACK_SIZE;
566 context_stack = (struct context_stack *)
567 xmalloc (context_stack_size * sizeof (struct context_stack));
c0302457
JG
568 context_stack_depth = 0;
569
570 new_object_header_files ();
571
4137c5fc 572 type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
c0302457
JG
573 type_vector = (struct type **)
574 xmalloc (type_vector_length * sizeof (struct type *));
575 bzero (type_vector, type_vector_length * sizeof (struct type *));
576
577 /* Initialize the list of sub source files with one entry
578 for this file (the top-level source file). */
579
580 subfiles = 0;
581 current_subfile = 0;
582 start_subfile (name, dirname);
583}
584
585/* Finish the symbol definitions for one main source file,
586 close off all the lexical contexts for that file
587 (creating struct block's for them), then make the struct symtab
588 for that file and put it in the list of all such.
589
590 END_ADDR is the address of the end of the file's text. */
591
592struct symtab *
4137c5fc 593end_symtab (end_addr, sort_pending, sort_linevec)
c0302457 594 CORE_ADDR end_addr;
4137c5fc
JG
595 int sort_pending;
596 int sort_linevec;
c0302457
JG
597{
598 register struct symtab *symtab;
599 register struct blockvector *blockvector;
600 register struct subfile *subfile;
601 register struct linetable *lv;
602 struct subfile *nextsub;
603
604 /* Finish the lexical context of the last function in the file;
605 pop the context stack. */
606
607 if (context_stack_depth > 0)
608 {
609 register struct context_stack *cstk;
610 context_stack_depth--;
611 cstk = &context_stack[context_stack_depth];
612 /* Make a block for the local symbols within. */
613 finish_block (cstk->name, &local_symbols, cstk->old_blocks,
614 cstk->start_addr, end_addr);
615 }
616
4137c5fc
JG
617 /* It is unfortunate that in aixcoff, pending blocks might not be ordered
618 in this stage. Especially, blocks for static functions will show up at
619 the end. We need to sort them, so tools like `find_pc_function' and
620 `find_pc_block' can work reliably. */
621 if (sort_pending) {
622 /* FIXME! Remove this horrid bubble sort and use qsort!!! */
623 int swapped;
624 do {
625 struct pending_block *pb, *pbnext;
626
627 pb = pending_blocks, pbnext = pb->next;
628 swapped = 0;
629
630 while ( pbnext ) {
631
632 /* swap blocks if unordered! */
633
634 if (BLOCK_START(pb->block) < BLOCK_START(pbnext->block)) {
635 struct block *tmp = pb->block;
636 pb->block = pbnext->block;
637 pbnext->block = tmp;
638 swapped = 1;
639 }
640 pb = pbnext;
641 pbnext = pbnext->next;
642 }
643 } while (swapped);
644 }
645
c0302457
JG
646 /* Cleanup any undefined types that have been left hanging around
647 (this needs to be done before the finish_blocks so that
648 file_symbols is still good). */
649 cleanup_undefined_types ();
650
4137c5fc
JG
651 if (file_stabs) {
652 patch_block_stabs (file_symbols, file_stabs);
653 free (file_stabs);
654 file_stabs = 0;
655 }
656
657 if (global_stabs) {
658 patch_block_stabs (global_symbols, global_stabs);
659 free (global_stabs);
660 global_stabs = 0;
661 }
662
c0302457
JG
663 /* Define the STATIC_BLOCK and GLOBAL_BLOCK, and build the blockvector. */
664 finish_block (0, &file_symbols, 0, last_source_start_addr, end_addr);
665 finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr);
666 blockvector = make_blockvector ();
667
c0302457
JG
668 /* Now create the symtab objects proper, one for each subfile. */
669 /* (The main file is the last one on the chain.) */
670
671 for (subfile = subfiles; subfile; subfile = nextsub)
672 {
4137c5fc
JG
673 if (subfile->line_vector) {
674 /* First, shrink the linetable to make more memory. */
675 subfile->line_vector = (struct linetable *)
676 xrealloc (subfile->line_vector, (sizeof (struct linetable)
677 + subfile->line_vector->nitems * sizeof (struct linetable_entry)));
678
679 if (sort_linevec)
680 qsort (subfile->line_vector->item, subfile->line_vector->nitems,
681 sizeof (struct linetable_entry), compare_line_numbers);
682 }
683
684 /* Now, allocate a symbol table. */
c0302457
JG
685 symtab = allocate_symtab (subfile->name);
686
687 /* Fill in its components. */
688 symtab->blockvector = blockvector;
4137c5fc 689 symtab->linetable = subfile->line_vector;
c0302457 690 symtab->dirname = subfile->dirname;
c0302457
JG
691 symtab->free_code = free_linetable;
692 symtab->free_ptr = 0;
693
c0302457
JG
694 /* Link the new symtab into the list of such. */
695 symtab->next = symtab_list;
696 symtab_list = symtab;
697
698 nextsub = subfile->next;
699 free (subfile);
700 }
701
702 free ((char *) type_vector);
703 type_vector = 0;
704 type_vector_length = -1;
4137c5fc 705
c0302457 706 last_source_file = 0;
4137c5fc 707 current_subfile = 0;
c0302457
JG
708
709 return symtab;
710}
711\f
712/* Initialize anything that needs initializing when starting to read
713 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
714 to a psymtab. */
715
716void
717buildsym_init ()
718{
719 free_pendings = 0;
720 file_symbols = 0;
721 global_symbols = 0;
722 pending_blocks = 0;
723}
724
725/* Initialize anything that needs initializing when a completely new
726 symbol file is specified (not just adding some symbols from another
727 file, e.g. a shared library). */
728
729void
730buildsym_new_init ()
731{
732 /* Empty the hash table of global syms looking for values. */
733 bzero (global_sym_chain, sizeof global_sym_chain);
734
735 buildsym_init ();
736}
737
738/* Scan through all of the global symbols defined in the object file,
739 assigning values to the debugging symbols that need to be assigned
740 to. Get these symbols from the misc function list. */
741
742void
743scan_file_globals ()
744{
745 int hash;
746 int mf;
747
748 for (mf = 0; mf < misc_function_count; mf++)
749 {
750 char *namestring = misc_function_vector[mf].name;
751 struct symbol *sym, *prev;
752
753 QUIT;
754
755 prev = (struct symbol *) 0;
756
757 /* Get the hash index and check all the symbols
758 under that hash index. */
759
760 hash = hashname (namestring);
761
762 for (sym = global_sym_chain[hash]; sym;)
763 {
764 if (*namestring == SYMBOL_NAME (sym)[0]
765 && !strcmp(namestring + 1, SYMBOL_NAME (sym) + 1))
766 {
767 /* Splice this symbol out of the hash chain and
768 assign the value we have to it. */
769 if (prev)
770 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
771 else
772 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
773
774 /* Check to see whether we need to fix up a common block. */
775 /* Note: this code might be executed several times for
776 the same symbol if there are multiple references. */
777 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
778 fix_common_block (sym, misc_function_vector[mf].address);
779 else
780 SYMBOL_VALUE_ADDRESS (sym) = misc_function_vector[mf].address;
781
782 if (prev)
783 sym = SYMBOL_VALUE_CHAIN (prev);
784 else
785 sym = global_sym_chain[hash];
786 }
787 else
788 {
789 prev = sym;
790 sym = SYMBOL_VALUE_CHAIN (sym);
791 }
792 }
793 }
794}
795
796\f
797/* Read a number by which a type is referred to in dbx data,
798 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
799 Just a single number N is equivalent to (0,N).
800 Return the two numbers by storing them in the vector TYPENUMS.
801 TYPENUMS will then be used as an argument to dbx_lookup_type. */
802
803void
804read_type_number (pp, typenums)
805 register char **pp;
806 register int *typenums;
807{
808 if (**pp == '(')
809 {
810 (*pp)++;
811 typenums[0] = read_number (pp, ',');
812 typenums[1] = read_number (pp, ')');
813 }
814 else
815 {
816 typenums[0] = 0;
817 typenums[1] = read_number (pp, 0);
818 }
819}
820\f
821/* To handle GNU C++ typename abbreviation, we need to be able to
822 fill in a type's name as soon as space for that type is allocated.
823 `type_synonym_name' is the name of the type being allocated.
824 It is cleared as soon as it is used (lest all allocated types
825 get this name). */
826static char *type_synonym_name;
827
828/* ARGSUSED */
abefb1f1 829struct symbol *
c0302457
JG
830define_symbol (valu, string, desc, type)
831 unsigned int valu;
832 char *string;
833 int desc;
834 int type;
835{
836 register struct symbol *sym;
837 char *p = (char *) strchr (string, ':');
838 int deftype;
839 int synonym = 0;
840 register int i;
841
842 /* Ignore syms with empty names. */
843 if (string[0] == 0)
844 return 0;
845
846 /* Ignore old-style symbols from cc -go */
847 if (p == 0)
848 return 0;
849
850 sym = (struct symbol *)obstack_alloc (symbol_obstack, sizeof (struct symbol));
851
852 if (processing_gcc_compilation) {
853 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
854 number of bytes occupied by a type or object, which we ignore. */
855 SYMBOL_LINE(sym) = desc;
856 } else {
857 SYMBOL_LINE(sym) = 0; /* unknown */
858 }
859
860 if (string[0] == CPLUS_MARKER)
861 {
862 /* Special GNU C++ names. */
863 switch (string[1])
864 {
865 case 't':
866 SYMBOL_NAME (sym) = "this";
867 break;
868 case 'v': /* $vtbl_ptr_type */
869 /* Was: SYMBOL_NAME (sym) = "vptr"; */
870 goto normal;
871 case 'e':
872 SYMBOL_NAME (sym) = "eh_throw";
873 break;
874
875 case '_':
876 /* This was an anonymous type that was never fixed up. */
877 goto normal;
878
879 default:
880 abort ();
881 }
882 }
883 else
884 {
885 normal:
886 SYMBOL_NAME (sym)
887 = (char *) obstack_alloc (symbol_obstack, ((p - string) + 1));
888 /* Open-coded bcopy--saves function call time. */
889 {
890 register char *p1 = string;
891 register char *p2 = SYMBOL_NAME (sym);
892 while (p1 != p)
893 *p2++ = *p1++;
894 *p2++ = '\0';
895 }
896 }
897 p++;
898 /* Determine the type of name being defined. */
899 /* The Acorn RISC machine's compiler can put out locals that don't
900 start with "234=" or "(3,4)=", so assume anything other than the
901 deftypes we know how to handle is a local. */
902 /* (Peter Watkins @ Computervision)
903 Handle Sun-style local fortran array types 'ar...' .
904 (gnu@cygnus.com) -- this strchr() handles them properly?
905 (tiemann@cygnus.com) -- 'C' is for catch. */
906 if (!strchr ("cfFGpPrStTvVXC", *p))
907 deftype = 'l';
908 else
909 deftype = *p++;
910
911 /* c is a special case, not followed by a type-number.
912 SYMBOL:c=iVALUE for an integer constant symbol.
913 SYMBOL:c=rVALUE for a floating constant symbol.
914 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
915 e.g. "b:c=e6,0" for "const b = blob1"
916 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
917 if (deftype == 'c')
918 {
919 if (*p++ != '=')
920 error ("Invalid symbol data at symtab pos %d.", symnum);
921 switch (*p++)
922 {
923 case 'r':
924 {
925 double d = atof (p);
926 char *dbl_valu;
927
928 SYMBOL_TYPE (sym) = builtin_type_double;
929 dbl_valu =
930 (char *) obstack_alloc (symbol_obstack, sizeof (double));
931 bcopy (&d, dbl_valu, sizeof (double));
932 SWAP_TARGET_AND_HOST (dbl_valu, sizeof (double));
933 SYMBOL_VALUE_BYTES (sym) = dbl_valu;
934 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
935 }
936 break;
937 case 'i':
938 {
939 SYMBOL_TYPE (sym) = builtin_type_int;
940 SYMBOL_VALUE (sym) = atoi (p);
941 SYMBOL_CLASS (sym) = LOC_CONST;
942 }
943 break;
944 case 'e':
945 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
946 e.g. "b:c=e6,0" for "const b = blob1"
947 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
948 {
949 int typenums[2];
950
951 read_type_number (&p, typenums);
952 if (*p++ != ',')
953 error ("Invalid symbol data: no comma in enum const symbol");
954
955 SYMBOL_TYPE (sym) = *dbx_lookup_type (typenums);
956 SYMBOL_VALUE (sym) = atoi (p);
957 SYMBOL_CLASS (sym) = LOC_CONST;
958 }
959 break;
960 default:
961 error ("Invalid symbol data at symtab pos %d.", symnum);
962 }
963 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
964 add_symbol_to_list (sym, &file_symbols);
965 return sym;
966 }
967
968 /* Now usually comes a number that says which data type,
969 and possibly more stuff to define the type
970 (all of which is handled by read_type) */
971
972 if (deftype == 'p' && *p == 'F')
973 /* pF is a two-letter code that means a function parameter in Fortran.
974 The type-number specifies the type of the return value.
975 Translate it into a pointer-to-function type. */
976 {
977 p++;
978 SYMBOL_TYPE (sym)
979 = lookup_pointer_type (lookup_function_type (read_type (&p)));
980 }
981 else
982 {
983 struct type *type_read;
984 synonym = *p == 't';
985
986 if (synonym)
987 {
988 p += 1;
989 type_synonym_name = obsavestring (SYMBOL_NAME (sym),
990 strlen (SYMBOL_NAME (sym)));
991 }
992
993 type_read = read_type (&p);
994
995 if ((deftype == 'F' || deftype == 'f')
996 && TYPE_CODE (type_read) != TYPE_CODE_FUNC)
997 {
998#if 0
999/* This code doesn't work -- it needs to realloc and can't. */
1000 struct type *new = (struct type *)
1001 obstack_alloc (symbol_obstack, sizeof (struct type));
1002
1003 /* Generate a template for the type of this function. The
1004 types of the arguments will be added as we read the symbol
1005 table. */
1006 *new = *lookup_function_type (type_read);
1007 SYMBOL_TYPE(sym) = new;
1008 in_function_type = new;
1009#else
1010 SYMBOL_TYPE (sym) = lookup_function_type (type_read);
1011#endif
1012 }
1013 else
1014 SYMBOL_TYPE (sym) = type_read;
1015 }
1016
1017 switch (deftype)
1018 {
1019 case 'C':
1020 /* The name of a caught exception. */
1021 SYMBOL_CLASS (sym) = LOC_LABEL;
1022 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1023 SYMBOL_VALUE_ADDRESS (sym) = valu;
1024 add_symbol_to_list (sym, &local_symbols);
1025 break;
1026
1027 case 'f':
1028 SYMBOL_CLASS (sym) = LOC_BLOCK;
1029 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1030 add_symbol_to_list (sym, &file_symbols);
1031 break;
1032
1033 case 'F':
1034 SYMBOL_CLASS (sym) = LOC_BLOCK;
1035 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1036 add_symbol_to_list (sym, &global_symbols);
1037 break;
1038
1039 case 'G':
1040 /* For a class G (global) symbol, it appears that the
1041 value is not correct. It is necessary to search for the
1042 corresponding linker definition to find the value.
1043 These definitions appear at the end of the namelist. */
1044 i = hashname (SYMBOL_NAME (sym));
1045 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
1046 global_sym_chain[i] = sym;
1047 SYMBOL_CLASS (sym) = LOC_STATIC;
1048 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1049 add_symbol_to_list (sym, &global_symbols);
1050 break;
1051
1052 /* This case is faked by a conditional above,
1053 when there is no code letter in the dbx data.
1054 Dbx data never actually contains 'l'. */
1055 case 'l':
1056 SYMBOL_CLASS (sym) = LOC_LOCAL;
1057 SYMBOL_VALUE (sym) = valu;
1058 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1059 add_symbol_to_list (sym, &local_symbols);
1060 break;
1061
1062 case 'p':
1063 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1064 can also be a LOC_LOCAL_ARG depending on symbol type. */
1065#ifndef DBX_PARM_SYMBOL_CLASS
1066#define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1067#endif
1068 SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
1069 SYMBOL_VALUE (sym) = valu;
1070 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1071#if 0
1072 /* This doesn't work yet. */
1073 add_param_to_type (&in_function_type, sym);
1074#endif
1075 add_symbol_to_list (sym, &local_symbols);
1076
1077 /* If it's gcc-compiled, if it says `short', believe it. */
1078 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
1079 break;
1080
1081#if defined(BELIEVE_PCC_PROMOTION_TYPE)
1082 /* This macro is defined on machines (e.g. sparc) where
1083 we should believe the type of a PCC 'short' argument,
1084 but shouldn't believe the address (the address is
1085 the address of the corresponding int). Note that
1086 this is only different from the BELIEVE_PCC_PROMOTION
1087 case on big-endian machines.
1088
1089 My guess is that this correction, as opposed to changing
1090 the parameter to an 'int' (as done below, for PCC
1091 on most machines), is the right thing to do
1092 on all machines, but I don't want to risk breaking
1093 something that already works. On most PCC machines,
1094 the sparc problem doesn't come up because the calling
1095 function has to zero the top bytes (not knowing whether
1096 the called function wants an int or a short), so there
1097 is no practical difference between an int and a short
1098 (except perhaps what happens when the GDB user types
1099 "print short_arg = 0x10000;").
1100
1101 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
1102 actually produces the correct address (we don't need to fix it
1103 up). I made this code adapt so that it will offset the symbol
1104 if it was pointing at an int-aligned location and not
1105 otherwise. This way you can use the same gdb for 4.0.x and
1106 4.1 systems. */
1107
1108 if (0 == SYMBOL_VALUE (sym) % sizeof (int))
1109 {
1110 if (SYMBOL_TYPE (sym) == builtin_type_char
1111 || SYMBOL_TYPE (sym) == builtin_type_unsigned_char)
1112 SYMBOL_VALUE (sym) += 3;
1113 else if (SYMBOL_TYPE (sym) == builtin_type_short
1114 || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
1115 SYMBOL_VALUE (sym) += 2;
1116 }
1117 break;
1118
1119#else /* no BELIEVE_PCC_PROMOTION_TYPE. */
1120
1121 /* If PCC says a parameter is a short or a char,
1122 it is really an int. */
1123 if (SYMBOL_TYPE (sym) == builtin_type_char
1124 || SYMBOL_TYPE (sym) == builtin_type_short)
1125 SYMBOL_TYPE (sym) = builtin_type_int;
1126 else if (SYMBOL_TYPE (sym) == builtin_type_unsigned_char
1127 || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
1128 SYMBOL_TYPE (sym) = builtin_type_unsigned_int;
1129 break;
1130
1131#endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
1132
1133 case 'P':
1134 SYMBOL_CLASS (sym) = LOC_REGPARM;
1135 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1136 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1137 add_symbol_to_list (sym, &local_symbols);
1138 break;
1139
1140 case 'r':
1141 SYMBOL_CLASS (sym) = LOC_REGISTER;
1142 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1143 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1144 add_symbol_to_list (sym, &local_symbols);
1145 break;
1146
1147 case 'S':
1148 /* Static symbol at top level of file */
1149 SYMBOL_CLASS (sym) = LOC_STATIC;
1150 SYMBOL_VALUE_ADDRESS (sym) = valu;
1151 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1152 add_symbol_to_list (sym, &file_symbols);
1153 break;
1154
1155 case 't':
1156 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1157 SYMBOL_VALUE (sym) = valu;
1158 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1159 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
1160 && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
1161 TYPE_NAME (SYMBOL_TYPE (sym)) =
1162 obsavestring (SYMBOL_NAME (sym),
1163 strlen (SYMBOL_NAME (sym)));
1164 /* C++ vagaries: we may have a type which is derived from
1165 a base type which did not have its name defined when the
1166 derived class was output. We fill in the derived class's
1167 base part member's name here in that case. */
1168 else if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1169 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1170 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
1171 {
1172 int j;
1173 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
1174 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
1175 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
1176 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
1177 }
1178
1179 add_symbol_to_list (sym, &file_symbols);
1180 break;
1181
1182 case 'T':
1183 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1184 SYMBOL_VALUE (sym) = valu;
1185 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1186 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
1187 && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
1188 TYPE_NAME (SYMBOL_TYPE (sym))
1189 = obconcat ("",
1190 (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_ENUM
1191 ? "enum "
1192 : (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1193 ? "struct " : "union ")),
1194 SYMBOL_NAME (sym));
1195 add_symbol_to_list (sym, &file_symbols);
1196
1197 if (synonym)
1198 {
1199 register struct symbol *typedef_sym
1200 = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol));
1201 SYMBOL_NAME (typedef_sym) = SYMBOL_NAME (sym);
1202 SYMBOL_TYPE (typedef_sym) = SYMBOL_TYPE (sym);
1203
1204 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
1205 SYMBOL_VALUE (typedef_sym) = valu;
1206 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
1207 add_symbol_to_list (typedef_sym, &file_symbols);
1208 }
1209 break;
1210
1211 case 'V':
1212 /* Static symbol of local scope */
1213 SYMBOL_CLASS (sym) = LOC_STATIC;
1214 SYMBOL_VALUE_ADDRESS (sym) = valu;
1215 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1216 add_symbol_to_list (sym, &local_symbols);
1217 break;
1218
1219 case 'v':
1220 /* Reference parameter */
1221 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1222 SYMBOL_VALUE (sym) = valu;
1223 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1224 add_symbol_to_list (sym, &local_symbols);
1225 break;
1226
1227 case 'X':
1228 /* This is used by Sun FORTRAN for "function result value".
1229 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1230 that Pascal uses it too, but when I tried it Pascal used
1231 "x:3" (local symbol) instead. */
1232 SYMBOL_CLASS (sym) = LOC_LOCAL;
1233 SYMBOL_VALUE (sym) = valu;
1234 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1235 add_symbol_to_list (sym, &local_symbols);
1236 break;
1237
1238 default:
1239 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype, symnum);
1240 }
1241 return sym;
1242}
1243\f
1244/* What about types defined as forward references inside of a small lexical
1245 scope? */
1246/* Add a type to the list of undefined types to be checked through
1247 once this file has been read in. */
1248static void
1249add_undefined_type (type)
1250 struct type *type;
1251{
1252 if (undef_types_length == undef_types_allocated)
1253 {
1254 undef_types_allocated *= 2;
1255 undef_types = (struct type **)
1256 xrealloc (undef_types,
1257 undef_types_allocated * sizeof (struct type *));
1258 }
1259 undef_types[undef_types_length++] = type;
1260}
1261
1262/* Add here something to go through each undefined type, see if it's
1263 still undefined, and do a full lookup if so. */
1264static void
1265cleanup_undefined_types ()
1266{
1267 struct type **type;
1268
1269 for (type = undef_types; type < undef_types + undef_types_length; type++)
1270 {
1271 /* Reasonable test to see if it's been defined since. */
1272 if (TYPE_NFIELDS (*type) == 0)
1273 {
1274 struct pending *ppt;
1275 int i;
1276 /* Name of the type, without "struct" or "union" */
1277 char *typename = TYPE_NAME (*type);
1278
1279 if (!strncmp (typename, "struct ", 7))
1280 typename += 7;
1281 if (!strncmp (typename, "union ", 6))
1282 typename += 6;
1283
1284 for (ppt = file_symbols; ppt; ppt = ppt->next)
1285 for (i = 0; i < ppt->nsyms; i++)
1286 {
1287 struct symbol *sym = ppt->symbol[i];
1288
1289 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1290 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
1291 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
1292 TYPE_CODE (*type))
1293 && !strcmp (SYMBOL_NAME (sym), typename))
1294 bcopy (SYMBOL_TYPE (sym), *type, sizeof (struct type));
1295 }
1296 }
1297 else
1298 /* It has been defined; don't mark it as a stub. */
1299 TYPE_FLAGS (*type) &= ~TYPE_FLAG_STUB;
1300 }
1301 undef_types_length = 0;
1302}
1303\f
1304/* Skip rest of this symbol and return an error type.
1305
1306 General notes on error recovery: error_type always skips to the
1307 end of the symbol (modulo cretinous dbx symbol name continuation).
1308 Thus code like this:
1309
1310 if (*(*pp)++ != ';')
1311 return error_type (pp);
1312
1313 is wrong because if *pp starts out pointing at '\0' (typically as the
1314 result of an earlier error), it will be incremented to point to the
1315 start of the next symbol, which might produce strange results, at least
1316 if you run off the end of the string table. Instead use
1317
1318 if (**pp != ';')
1319 return error_type (pp);
1320 ++*pp;
1321
1322 or
1323
1324 if (**pp != ';')
1325 foo = error_type (pp);
1326 else
1327 ++*pp;
1328
1329 And in case it isn't obvious, the point of all this hair is so the compiler
1330 can define new types and new syntaxes, and old versions of the
1331 debugger will be able to read the new symbol tables. */
1332
1333struct type *
1334error_type (pp)
1335 char **pp;
1336{
1337 complain (&error_type_complaint, 0);
1338 while (1)
1339 {
1340 /* Skip to end of symbol. */
1341 while (**pp != '\0')
1342 (*pp)++;
1343
1344 /* Check for and handle cretinous dbx symbol name continuation! */
1345 if ((*pp)[-1] == '\\')
1346 *pp = next_symbol_text ();
1347 else
1348 break;
1349 }
1350 return builtin_type_error;
1351}
1352\f
1353/* Read a dbx type reference or definition;
1354 return the type that is meant.
1355 This can be just a number, in which case it references
1356 a type already defined and placed in type_vector.
1357 Or the number can be followed by an =, in which case
1358 it means to define a new type according to the text that
1359 follows the =. */
1360
1361struct type *
1362read_type (pp)
1363 register char **pp;
1364{
1365 register struct type *type = 0;
1366 struct type *type1;
1367 int typenums[2];
1368 int xtypenums[2];
1369
1370 /* Read type number if present. The type number may be omitted.
1371 for instance in a two-dimensional array declared with type
1372 "ar1;1;10;ar1;1;10;4". */
1373 if ((**pp >= '0' && **pp <= '9')
1374 || **pp == '(')
1375 {
1376 read_type_number (pp, typenums);
1377
1378 /* Detect random reference to type not yet defined.
1379 Allocate a type object but leave it zeroed. */
1380 if (**pp != '=')
1381 return dbx_alloc_type (typenums);
1382
1383 *pp += 2;
1384 }
1385 else
1386 {
1387 /* 'typenums=' not present, type is anonymous. Read and return
1388 the definition, but don't put it in the type vector. */
1389 typenums[0] = typenums[1] = -1;
1390 *pp += 1;
1391 }
1392
1393 switch ((*pp)[-1])
1394 {
1395 case 'x':
1396 {
1397 enum type_code code;
1398
1399 /* Used to index through file_symbols. */
1400 struct pending *ppt;
1401 int i;
1402
1403 /* Name including "struct", etc. */
1404 char *type_name;
1405
1406 /* Name without "struct", etc. */
1407 char *type_name_only;
1408
1409 {
1410 char *prefix;
1411 char *from, *to;
1412
1413 /* Set the type code according to the following letter. */
1414 switch ((*pp)[0])
1415 {
1416 case 's':
1417 code = TYPE_CODE_STRUCT;
1418 prefix = "struct ";
1419 break;
1420 case 'u':
1421 code = TYPE_CODE_UNION;
1422 prefix = "union ";
1423 break;
1424 case 'e':
1425 code = TYPE_CODE_ENUM;
1426 prefix = "enum ";
1427 break;
1428 default:
1429 return error_type (pp);
1430 }
1431
1432 to = type_name = (char *)
1433 obstack_alloc (symbol_obstack,
1434 (strlen (prefix) +
1435 ((char *) strchr (*pp, ':') - (*pp)) + 1));
1436
1437 /* Copy the prefix. */
1438 from = prefix;
1439 while (*to++ = *from++)
1440 ;
1441 to--;
1442
1443 type_name_only = to;
1444
1445 /* Copy the name. */
1446 from = *pp + 1;
1447 while ((*to++ = *from++) != ':')
1448 ;
1449 *--to = '\0';
1450
1451 /* Set the pointer ahead of the name which we just read. */
1452 *pp = from;
1453
1454#if 0
1455 /* The following hack is clearly wrong, because it doesn't
1456 check whether we are in a baseclass. I tried to reproduce
1457 the case that it is trying to fix, but I couldn't get
1458 g++ to put out a cross reference to a basetype. Perhaps
1459 it doesn't do it anymore. */
1460 /* Note: for C++, the cross reference may be to a base type which
1461 has not yet been seen. In this case, we skip to the comma,
1462 which will mark the end of the base class name. (The ':'
1463 at the end of the base class name will be skipped as well.)
1464 But sometimes (ie. when the cross ref is the last thing on
1465 the line) there will be no ','. */
1466 from = (char *) strchr (*pp, ',');
1467 if (from)
1468 *pp = from;
1469#endif /* 0 */
1470 }
1471
1472 /* Now check to see whether the type has already been declared. */
1473 /* This is necessary at least in the case where the
1474 program says something like
1475 struct foo bar[5];
1476 The compiler puts out a cross-reference; we better find
1477 set the length of the structure correctly so we can
1478 set the length of the array. */
1479 for (ppt = file_symbols; ppt; ppt = ppt->next)
1480 for (i = 0; i < ppt->nsyms; i++)
1481 {
1482 struct symbol *sym = ppt->symbol[i];
1483
1484 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1485 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
1486 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
1487 && !strcmp (SYMBOL_NAME (sym), type_name_only))
1488 {
1489 obstack_free (symbol_obstack, type_name);
1490 type = SYMBOL_TYPE (sym);
1491 return type;
1492 }
1493 }
1494
1495 /* Didn't find the type to which this refers, so we must
1496 be dealing with a forward reference. Allocate a type
1497 structure for it, and keep track of it so we can
1498 fill in the rest of the fields when we get the full
1499 type. */
1500 type = dbx_alloc_type (typenums);
1501 TYPE_CODE (type) = code;
1502 TYPE_NAME (type) = type_name;
1503
1504 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
1505
1506 add_undefined_type (type);
1507 return type;
1508 }
1509
1510 case '0':
1511 case '1':
1512 case '2':
1513 case '3':
1514 case '4':
1515 case '5':
1516 case '6':
1517 case '7':
1518 case '8':
1519 case '9':
1520 case '(':
1521 (*pp)--;
1522 read_type_number (pp, xtypenums);
1523 type = *dbx_lookup_type (xtypenums);
1524 if (type == 0)
1525 type = builtin_type_void;
1526 if (typenums[0] != -1)
1527 *dbx_lookup_type (typenums) = type;
1528 break;
1529
1530 case '*':
1531 type1 = read_type (pp);
1532 type = lookup_pointer_type (type1);
1533 if (typenums[0] != -1)
1534 *dbx_lookup_type (typenums) = type;
1535 break;
1536
1537 case '@':
1538 {
1539 struct type *domain = read_type (pp);
1540 struct type *memtype;
1541
1542 if (**pp != ',')
1543 /* Invalid member type data format. */
1544 return error_type (pp);
1545 ++*pp;
1546
1547 memtype = read_type (pp);
1548 type = dbx_alloc_type (typenums);
1549 smash_to_member_type (type, domain, memtype);
1550 }
1551 break;
1552
1553 case '#':
1554 if ((*pp)[0] == '#')
1555 {
1556 /* We'll get the parameter types from the name. */
1557 struct type *return_type;
1558
1559 *pp += 1;
1560 return_type = read_type (pp);
1561 if (*(*pp)++ != ';')
1562 complain (&invalid_member_complaint, symnum);
1563 type = allocate_stub_method (return_type);
1564 if (typenums[0] != -1)
1565 *dbx_lookup_type (typenums) = type;
1566 }
1567 else
1568 {
1569 struct type *domain = read_type (pp);
1570 struct type *return_type;
1571 struct type **args;
1572
1573 if (*(*pp)++ != ',')
1574 error ("invalid member type data format, at symtab pos %d.",
1575 symnum);
1576
1577 return_type = read_type (pp);
1578 args = read_args (pp, ';');
1579 type = dbx_alloc_type (typenums);
1580 smash_to_method_type (type, domain, return_type, args);
1581 }
1582 break;
1583
1584 case '&':
1585 type1 = read_type (pp);
1586 type = lookup_reference_type (type1);
1587 if (typenums[0] != -1)
1588 *dbx_lookup_type (typenums) = type;
1589 break;
1590
1591 case 'f':
1592 type1 = read_type (pp);
1593 type = lookup_function_type (type1);
1594 if (typenums[0] != -1)
1595 *dbx_lookup_type (typenums) = type;
1596 break;
1597
1598 case 'r':
1599 type = read_range_type (pp, typenums);
1600 if (typenums[0] != -1)
1601 *dbx_lookup_type (typenums) = type;
1602 break;
1603
1604 case 'e':
1605 type = dbx_alloc_type (typenums);
1606 type = read_enum_type (pp, type);
1607 *dbx_lookup_type (typenums) = type;
1608 break;
1609
1610 case 's':
1611 type = dbx_alloc_type (typenums);
1612 TYPE_NAME (type) = type_synonym_name;
1613 type_synonym_name = 0;
1614 type = read_struct_type (pp, type);
1615 break;
1616
1617 case 'u':
1618 type = dbx_alloc_type (typenums);
1619 TYPE_NAME (type) = type_synonym_name;
1620 type_synonym_name = 0;
1621 type = read_struct_type (pp, type);
1622 TYPE_CODE (type) = TYPE_CODE_UNION;
1623 break;
1624
1625 case 'a':
1626 if (**pp != 'r')
1627 return error_type (pp);
1628 ++*pp;
1629
1630 type = dbx_alloc_type (typenums);
1631 type = read_array_type (pp, type);
1632 break;
1633
1634 default:
1635 --*pp; /* Go back to the symbol in error */
1636 /* Particularly important if it was \0! */
1637 return error_type (pp);
1638 }
1639
1640 if (type == 0)
1641 abort ();
1642
1643#if 0
1644 /* If this is an overriding temporary alteration for a header file's
1645 contents, and this type number is unknown in the global definition,
1646 put this type into the global definition at this type number. */
1647 if (header_file_prev_index >= 0)
1648 {
1649 register struct type **tp
1650 = explicit_lookup_type (header_file_prev_index, typenums[1]);
1651 if (*tp == 0)
1652 *tp = type;
1653 }
1654#endif
1655 return type;
1656}
1657\f
1658/* This page contains subroutines of read_type. */
1659
1660/* Read the description of a structure (or union type)
1661 and return an object describing the type. */
1662
1663struct type *
1664read_struct_type (pp, type)
1665 char **pp;
1666 register struct type *type;
1667{
1668 /* Total number of methods defined in this class.
1669 If the class defines two `f' methods, and one `g' method,
1670 then this will have the value 3. */
1671 int total_length = 0;
1672
1673 struct nextfield
1674 {
1675 struct nextfield *next;
1676 int visibility; /* 0=public, 1=protected, 2=public */
1677 struct field field;
1678 };
1679
1680 struct next_fnfield
1681 {
1682 struct next_fnfield *next;
1683 int visibility; /* 0=public, 1=protected, 2=public */
1684 struct fn_field fn_field;
1685 };
1686
1687 struct next_fnfieldlist
1688 {
1689 struct next_fnfieldlist *next;
1690 struct fn_fieldlist fn_fieldlist;
1691 };
1692
1693 register struct nextfield *list = 0;
1694 struct nextfield *new;
1695 register char *p;
1696 int nfields = 0;
1697 register int n;
1698
1699 register struct next_fnfieldlist *mainlist = 0;
1700 int nfn_fields = 0;
1701
1702 if (TYPE_MAIN_VARIANT (type) == 0)
1703 {
1704 TYPE_MAIN_VARIANT (type) = type;
1705 }
1706
1707 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1708
1709 /* First comes the total size in bytes. */
1710
1711 TYPE_LENGTH (type) = read_number (pp, 0);
1712
1713 /* C++: Now, if the class is a derived class, then the next character
1714 will be a '!', followed by the number of base classes derived from.
1715 Each element in the list contains visibility information,
1716 the offset of this base class in the derived structure,
1717 and then the base type. */
1718 if (**pp == '!')
1719 {
1720 int i, n_baseclasses, offset;
1721 struct type *baseclass;
1722 int via_public;
1723
1724 /* Nonzero if it is a virtual baseclass, i.e.,
1725
1726 struct A{};
1727 struct B{};
1728 struct C : public B, public virtual A {};
1729
1730 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
1731 2.0 language feature. */
1732 int via_virtual;
1733
1734 *pp += 1;
1735
1736 n_baseclasses = read_number (pp, ',');
1737 TYPE_FIELD_VIRTUAL_BITS (type) =
1738 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (n_baseclasses));
1739 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), n_baseclasses);
1740
1741 for (i = 0; i < n_baseclasses; i++)
1742 {
1743 if (**pp == '\\')
1744 *pp = next_symbol_text ();
1745
1746 switch (**pp)
1747 {
1748 case '0':
1749 via_virtual = 0;
1750 break;
1751 case '1':
1752 via_virtual = 1;
1753 break;
1754 default:
1755 /* Bad visibility format. */
1756 return error_type (pp);
1757 }
1758 ++*pp;
1759
1760 switch (**pp)
1761 {
1762 case '0':
1763 via_public = 0;
1764 break;
1765 case '2':
1766 via_public = 2;
1767 break;
1768 default:
1769 /* Bad visibility format. */
1770 return error_type (pp);
1771 }
1772 if (via_virtual)
1773 SET_TYPE_FIELD_VIRTUAL (type, i);
1774 ++*pp;
1775
1776 /* Offset of the portion of the object corresponding to
1777 this baseclass. Always zero in the absence of
1778 multiple inheritance. */
1779 offset = read_number (pp, ',');
1780 baseclass = read_type (pp);
1781 *pp += 1; /* skip trailing ';' */
1782
1783 /* Make this baseclass visible for structure-printing purposes. */
1784 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1785 new->next = list;
1786 list = new;
1787 list->visibility = via_public;
1788 list->field.type = baseclass;
1789 list->field.name = type_name_no_tag (baseclass);
1790 list->field.bitpos = offset;
1791 list->field.bitsize = 0; /* this should be an unpacked field! */
1792 nfields++;
1793 }
1794 TYPE_N_BASECLASSES (type) = n_baseclasses;
1795 }
1796
1797 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
1798 At the end, we see a semicolon instead of a field.
1799
1800 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
1801 a static field.
1802
1803 The `?' is a placeholder for one of '/2' (public visibility),
1804 '/1' (protected visibility), '/0' (private visibility), or nothing
1805 (C style symbol table, public visibility). */
1806
1807 /* We better set p right now, in case there are no fields at all... */
1808 p = *pp;
1809
1810 while (**pp != ';')
1811 {
1812 /* Check for and handle cretinous dbx symbol name continuation! */
1813 if (**pp == '\\') *pp = next_symbol_text ();
1814
1815 /* Get space to record the next field's data. */
1816 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1817 new->next = list;
1818 list = new;
1819
1820 /* Get the field name. */
1821 p = *pp;
1822 if (*p == CPLUS_MARKER)
1823 {
1824 /* Special GNU C++ name. */
1825 if (*++p == 'v')
1826 {
1827 const char *prefix;
1828 char *name = 0;
1829 struct type *context;
1830
1831 switch (*++p)
1832 {
1833 case 'f':
1834 prefix = vptr_name;
1835 break;
1836 case 'b':
1837 prefix = vb_name;
1838 break;
1839 default:
1840 error ("invalid abbreviation at symtab pos %d.", symnum);
1841 }
1842 *pp = p + 1;
1843 context = read_type (pp);
abefb1f1
PB
1844 name = type_name_no_tag (context);
1845 if (name == 0)
c0302457 1846 {
abefb1f1
PB
1847 error ("type name unknown at symtab pos %d.", symnum);
1848 TYPE_NAME (context) = name;
c0302457 1849 }
abefb1f1 1850 list->field.name = obconcat (prefix, name, "");
c0302457
JG
1851 p = ++(*pp);
1852 if (p[-1] != ':')
1853 error ("invalid abbreviation at symtab pos %d.", symnum);
1854 list->field.type = read_type (pp);
1855 (*pp)++; /* Skip the comma. */
1856 list->field.bitpos = read_number (pp, ';');
1857 /* This field is unpacked. */
1858 list->field.bitsize = 0;
1859 }
1860 /* GNU C++ anonymous type. */
1861 else if (*p == '_')
1862 break;
1863 else
1864 error ("invalid abbreviation at symtab pos %d.", symnum);
1865
1866 nfields++;
1867 continue;
1868 }
1869
1870 while (*p != ':') p++;
1871 list->field.name = obsavestring (*pp, p - *pp);
1872
1873 /* C++: Check to see if we have hit the methods yet. */
1874 if (p[1] == ':')
1875 break;
1876
1877 *pp = p + 1;
1878
1879 /* This means we have a visibility for a field coming. */
1880 if (**pp == '/')
1881 {
1882 switch (*++*pp)
1883 {
1884 case '0':
1885 list->visibility = 0; /* private */
1886 *pp += 1;
1887 break;
1888
1889 case '1':
1890 list->visibility = 1; /* protected */
1891 *pp += 1;
1892 break;
1893
1894 case '2':
1895 list->visibility = 2; /* public */
1896 *pp += 1;
1897 break;
1898 }
1899 }
1900 else /* normal dbx-style format. */
1901 list->visibility = 2; /* public */
1902
1903 list->field.type = read_type (pp);
1904 if (**pp == ':')
1905 {
1906 /* Static class member. */
1907 list->field.bitpos = (long)-1;
1908 p = ++(*pp);
1909 while (*p != ';') p++;
1910 list->field.bitsize = (long) savestring (*pp, p - *pp);
1911 *pp = p + 1;
1912 nfields++;
1913 continue;
1914 }
1915 else if (**pp != ',')
1916 /* Bad structure-type format. */
1917 return error_type (pp);
1918
1919 (*pp)++; /* Skip the comma. */
1920 list->field.bitpos = read_number (pp, ',');
1921 list->field.bitsize = read_number (pp, ';');
1922
1923#if 0
1924 /* FIXME-tiemann: Can't the compiler put out something which
1925 lets us distinguish these? (or maybe just not put out anything
1926 for the field). What is the story here? What does the compiler
1927 really do? Also, patch gdb.texinfo for this case; I document
1928 it as a possible problem there. Search for "DBX-style". */
1929
1930 /* This is wrong because this is identical to the symbols
1931 produced for GCC 0-size arrays. For example:
1932 typedef union {
1933 int num;
1934 char str[0];
1935 } foo;
1936 The code which dumped core in such circumstances should be
1937 fixed not to dump core. */
1938
1939 /* g++ -g0 can put out bitpos & bitsize zero for a static
1940 field. This does not give us any way of getting its
1941 class, so we can't know its name. But we can just
1942 ignore the field so we don't dump core and other nasty
1943 stuff. */
1944 if (list->field.bitpos == 0
1945 && list->field.bitsize == 0)
1946 {
1947 complain (&dbx_class_complaint, 0);
1948 /* Ignore this field. */
1949 list = list->next;
1950 }
1951 else
1952#endif /* 0 */
1953 {
1954 /* Detect an unpacked field and mark it as such.
1955 dbx gives a bit size for all fields.
1956 Note that forward refs cannot be packed,
1957 and treat enums as if they had the width of ints. */
1958 if (TYPE_CODE (list->field.type) != TYPE_CODE_INT
1959 && TYPE_CODE (list->field.type) != TYPE_CODE_ENUM)
1960 list->field.bitsize = 0;
1961 if ((list->field.bitsize == 8 * TYPE_LENGTH (list->field.type)
1962 || (TYPE_CODE (list->field.type) == TYPE_CODE_ENUM
1963 && (list->field.bitsize
1964 == 8 * TYPE_LENGTH (builtin_type_int))
1965 )
1966 )
1967 &&
1968 list->field.bitpos % 8 == 0)
1969 list->field.bitsize = 0;
1970 nfields++;
1971 }
1972 }
1973
1974 if (p[1] == ':')
1975 /* chill the list of fields: the last entry (at the head)
1976 is a partially constructed entry which we now scrub. */
1977 list = list->next;
1978
1979 /* Now create the vector of fields, and record how big it is.
1980 We need this info to record proper virtual function table information
1981 for this class's virtual functions. */
1982
1983 TYPE_NFIELDS (type) = nfields;
1984 TYPE_FIELDS (type) = (struct field *) obstack_alloc (symbol_obstack,
1985 sizeof (struct field) * nfields);
1986
1987 TYPE_FIELD_PRIVATE_BITS (type) =
1988 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (nfields));
1989 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
1990
1991 TYPE_FIELD_PROTECTED_BITS (type) =
1992 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (nfields));
1993 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
1994
1995 /* Copy the saved-up fields into the field vector. */
1996
1997 for (n = nfields; list; list = list->next)
1998 {
1999 n -= 1;
2000 TYPE_FIELD (type, n) = list->field;
2001 if (list->visibility == 0)
2002 SET_TYPE_FIELD_PRIVATE (type, n);
2003 else if (list->visibility == 1)
2004 SET_TYPE_FIELD_PROTECTED (type, n);
2005 }
2006
2007 /* Now come the method fields, as NAME::methods
2008 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
2009 At the end, we see a semicolon instead of a field.
2010
2011 For the case of overloaded operators, the format is
2012 OPERATOR::*.methods, where OPERATOR is the string "operator",
2013 `*' holds the place for an operator name (such as `+=')
2014 and `.' marks the end of the operator name. */
2015 if (p[1] == ':')
2016 {
2017 /* Now, read in the methods. To simplify matters, we
2018 "unread" the name that has been read, so that we can
2019 start from the top. */
2020
2021 /* For each list of method lists... */
2022 do
2023 {
2024 int i;
2025 struct next_fnfield *sublist = 0;
2026 struct type *look_ahead_type = NULL;
2027 int length = 0;
2028 struct next_fnfieldlist *new_mainlist =
2029 (struct next_fnfieldlist *)alloca (sizeof (struct next_fnfieldlist));
2030 char *main_fn_name;
2031
2032 p = *pp;
2033
2034 /* read in the name. */
2035 while (*p != ':') p++;
abefb1f1 2036#if 0
c0302457
JG
2037 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == CPLUS_MARKER)
2038 {
2039 /* This lets the user type "break operator+".
2040 We could just put in "+" as the name, but that wouldn't
2041 work for "*". */
abefb1f1
PB
2042 /* I don't understand what this is trying to do.
2043 It seems completely bogus. -Per Bothner. */
c0302457
JG
2044 static char opname[32] = {'o', 'p', CPLUS_MARKER};
2045 char *o = opname + 3;
2046
2047 /* Skip past '::'. */
abefb1f1
PB
2048 *pp = p + 2;
2049 if (**pp == '\\') *pp = next_symbol_text ();
2050 p = *pp;
c0302457
JG
2051 while (*p != '.')
2052 *o++ = *p++;
abefb1f1 2053 main_fn_name = savestring (opname, o - opname);
c0302457
JG
2054 /* Skip past '.' */
2055 *pp = p + 1;
2056 }
2057 else
abefb1f1 2058#endif
c0302457 2059 main_fn_name = savestring (*pp, p - *pp);
abefb1f1
PB
2060 /* Skip past '::'. */
2061 *pp = p + 2;
c0302457
JG
2062 new_mainlist->fn_fieldlist.name = main_fn_name;
2063
2064 do
2065 {
2066 struct next_fnfield *new_sublist =
2067 (struct next_fnfield *)alloca (sizeof (struct next_fnfield));
2068
2069 /* Check for and handle cretinous dbx symbol name continuation! */
2070 if (look_ahead_type == NULL) /* Normal case. */
2071 {
2072 if (**pp == '\\') *pp = next_symbol_text ();
2073
2074 new_sublist->fn_field.type = read_type (pp);
2075 if (**pp != ':')
2076 /* Invalid symtab info for method. */
2077 return error_type (pp);
2078 }
2079 else
2080 { /* g++ version 1 kludge */
2081 new_sublist->fn_field.type = look_ahead_type;
2082 look_ahead_type = NULL;
2083 }
2084
2085 *pp += 1;
2086 p = *pp;
2087 while (*p != ';') p++;
2088 /* If this is just a stub, then we don't have the
2089 real name here. */
2090 new_sublist->fn_field.physname = savestring (*pp, p - *pp);
2091 *pp = p + 1;
2092 new_sublist->visibility = *(*pp)++ - '0';
2093 if (**pp == '\\') *pp = next_symbol_text ();
2094 switch (**pp)
2095 {
2096 case 'A': /* Normal functions. */
2097 new_sublist->fn_field.is_const = 0;
2098 new_sublist->fn_field.is_volatile = 0;
2099 (*pp)++;
2100 break;
2101 case 'B': /* `const' member functions. */
2102 new_sublist->fn_field.is_const = 1;
2103 new_sublist->fn_field.is_volatile = 0;
2104 (*pp)++;
2105 break;
2106 case 'C': /* `volatile' member function. */
2107 new_sublist->fn_field.is_const = 0;
2108 new_sublist->fn_field.is_volatile = 1;
2109 (*pp)++;
2110 break;
2111 case 'D': /* `const volatile' member function. */
2112 new_sublist->fn_field.is_const = 1;
2113 new_sublist->fn_field.is_volatile = 1;
2114 (*pp)++;
2115 break;
2116 default:
2117 /* This probably just means we're processing a file compiled
2118 with g++ version 1. */
2119 complain(&const_vol_complaint, **pp);
2120 }
2121
2122 switch (*(*pp)++)
2123 {
2124 case '*':
2125 /* virtual member function, followed by index. */
2126 /* The sign bit is set to distinguish pointers-to-methods
2127 from virtual function indicies. Since the array is
2128 in words, the quantity must be shifted left by 1
2129 on 16 bit machine, and by 2 on 32 bit machine, forcing
2130 the sign bit out, and usable as a valid index into
2131 the array. Remove the sign bit here. */
2132 new_sublist->fn_field.voffset =
2133 (0x7fffffff & read_number (pp, ';')) + 2;
2134
2135 if (**pp == '\\') *pp = next_symbol_text ();
2136
2137 if (**pp == ';' || **pp == '\0')
2138 /* Must be g++ version 1. */
2139 new_sublist->fn_field.fcontext = 0;
2140 else
2141 {
2142 /* Figure out from whence this virtual function came.
2143 It may belong to virtual function table of
2144 one of its baseclasses. */
2145 look_ahead_type = read_type (pp);
2146 if (**pp == ':')
2147 { /* g++ version 1 overloaded methods. */ }
2148 else
2149 {
2150 new_sublist->fn_field.fcontext = look_ahead_type;
2151 if (**pp != ';')
2152 return error_type (pp);
2153 else
2154 ++*pp;
2155 look_ahead_type = NULL;
2156 }
2157 }
2158 break;
2159
2160 case '?':
2161 /* static member function. */
2162 new_sublist->fn_field.voffset = VOFFSET_STATIC;
2163 break;
2164 default:
2165 /* **pp == '.'. */
2166 /* normal member function. */
2167 new_sublist->fn_field.voffset = 0;
2168 new_sublist->fn_field.fcontext = 0;
2169 break;
2170 }
2171
2172 new_sublist->next = sublist;
2173 sublist = new_sublist;
2174 length++;
2175 if (**pp == '\\') *pp = next_symbol_text ();
2176 }
2177 while (**pp != ';' && **pp != '\0');
2178
2179 *pp += 1;
2180
2181 new_mainlist->fn_fieldlist.fn_fields =
2182 (struct fn_field *) obstack_alloc (symbol_obstack,
2183 sizeof (struct fn_field) * length);
2184 TYPE_FN_PRIVATE_BITS (new_mainlist->fn_fieldlist) =
2185 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (length));
2186 B_CLRALL (TYPE_FN_PRIVATE_BITS (new_mainlist->fn_fieldlist), length);
2187
2188 TYPE_FN_PROTECTED_BITS (new_mainlist->fn_fieldlist) =
2189 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (length));
2190 B_CLRALL (TYPE_FN_PROTECTED_BITS (new_mainlist->fn_fieldlist), length);
2191
2192 for (i = length; (i--, sublist); sublist = sublist->next)
2193 {
2194 new_mainlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
2195 if (sublist->visibility == 0)
2196 B_SET (new_mainlist->fn_fieldlist.private_fn_field_bits, i);
2197 else if (sublist->visibility == 1)
2198 B_SET (new_mainlist->fn_fieldlist.protected_fn_field_bits, i);
2199 }
2200
2201 new_mainlist->fn_fieldlist.length = length;
2202 new_mainlist->next = mainlist;
2203 mainlist = new_mainlist;
2204 nfn_fields++;
2205 total_length += length;
2206 }
2207 while (**pp != ';');
2208 }
2209
2210 *pp += 1;
2211
2212 TYPE_FN_FIELDLISTS (type) =
2213 (struct fn_fieldlist *) obstack_alloc (symbol_obstack,
2214 sizeof (struct fn_fieldlist) * nfn_fields);
2215
2216 TYPE_NFN_FIELDS (type) = nfn_fields;
2217 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
2218
2219 {
2220 int i;
2221 for (i = 0; i < TYPE_N_BASECLASSES (type); ++i)
2222 TYPE_NFN_FIELDS_TOTAL (type) +=
2223 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type, i));
2224 }
2225
2226 for (n = nfn_fields; mainlist; mainlist = mainlist->next)
2227 TYPE_FN_FIELDLISTS (type)[--n] = mainlist->fn_fieldlist;
2228
2229 if (**pp == '~')
2230 {
2231 *pp += 1;
2232
2233 if (**pp == '=')
2234 {
2235 TYPE_FLAGS (type)
2236 |= TYPE_FLAG_HAS_CONSTRUCTOR | TYPE_FLAG_HAS_DESTRUCTOR;
2237 *pp += 1;
2238 }
2239 else if (**pp == '+')
2240 {
2241 TYPE_FLAGS (type) |= TYPE_FLAG_HAS_CONSTRUCTOR;
2242 *pp += 1;
2243 }
2244 else if (**pp == '-')
2245 {
2246 TYPE_FLAGS (type) |= TYPE_FLAG_HAS_DESTRUCTOR;
2247 *pp += 1;
2248 }
2249
2250 /* Read either a '%' or the final ';'. */
2251 if (*(*pp)++ == '%')
2252 {
2253 /* Now we must record the virtual function table pointer's
2254 field information. */
2255
2256 struct type *t;
2257 int i;
2258
2259 t = read_type (pp);
2260 p = (*pp)++;
2261 while (*p != '\0' && *p != ';')
2262 p++;
2263 if (*p == '\0')
2264 /* Premature end of symbol. */
2265 return error_type (pp);
2266
2267 TYPE_VPTR_BASETYPE (type) = t;
2268 if (type == t)
2269 {
2270 if (TYPE_FIELD_NAME (t, TYPE_N_BASECLASSES (t)) == 0)
2271 {
2272 /* FIXME-tiemann: what's this? */
2273#if 0
2274 TYPE_VPTR_FIELDNO (type) = i = TYPE_N_BASECLASSES (t);
2275#else
2276 error_type (pp);
2277#endif
2278 }
2279 else for (i = TYPE_NFIELDS (t) - 1; i >= TYPE_N_BASECLASSES (t); --i)
2280 if (! strncmp (TYPE_FIELD_NAME (t, i), vptr_name,
2281 sizeof (vptr_name) -1))
2282 {
2283 TYPE_VPTR_FIELDNO (type) = i;
2284 break;
2285 }
2286 if (i < 0)
2287 /* Virtual function table field not found. */
2288 return error_type (pp);
2289 }
2290 else
2291 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
2292 *pp = p + 1;
2293 }
2294 }
2295
2296 return type;
2297}
2298
2299/* Read a definition of an array type,
2300 and create and return a suitable type object.
2301 Also creates a range type which represents the bounds of that
2302 array. */
2303struct type *
2304read_array_type (pp, type)
2305 register char **pp;
2306 register struct type *type;
2307{
2308 struct type *index_type, *element_type, *range_type;
2309 int lower, upper;
2310 int adjustable = 0;
2311
2312 /* Format of an array type:
2313 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2314 to handle this.
2315
2316 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2317 for these, produce a type like float[][]. */
2318
2319 index_type = read_type (pp);
2320 if (**pp != ';')
2321 /* Improper format of array type decl. */
2322 return error_type (pp);
2323 ++*pp;
2324
2325 if (!(**pp >= '0' && **pp <= '9'))
2326 {
2327 *pp += 1;
2328 adjustable = 1;
2329 }
2330 lower = read_number (pp, ';');
2331
2332 if (!(**pp >= '0' && **pp <= '9'))
2333 {
2334 *pp += 1;
2335 adjustable = 1;
2336 }
2337 upper = read_number (pp, ';');
2338
2339 element_type = read_type (pp);
2340
2341 if (adjustable)
2342 {
2343 lower = 0;
2344 upper = -1;
2345 }
2346
2347 {
2348 /* Create range type. */
2349 range_type = (struct type *) obstack_alloc (symbol_obstack,
2350 sizeof (struct type));
2351 TYPE_CODE (range_type) = TYPE_CODE_RANGE;
2352 TYPE_TARGET_TYPE (range_type) = index_type;
2353
2354 /* This should never be needed. */
2355 TYPE_LENGTH (range_type) = sizeof (int);
2356
2357 TYPE_NFIELDS (range_type) = 2;
2358 TYPE_FIELDS (range_type) =
2359 (struct field *) obstack_alloc (symbol_obstack,
2360 2 * sizeof (struct field));
2361 TYPE_FIELD_BITPOS (range_type, 0) = lower;
2362 TYPE_FIELD_BITPOS (range_type, 1) = upper;
2363 }
2364
2365 TYPE_CODE (type) = TYPE_CODE_ARRAY;
2366 TYPE_TARGET_TYPE (type) = element_type;
2367 TYPE_LENGTH (type) = (upper - lower + 1) * TYPE_LENGTH (element_type);
2368 TYPE_NFIELDS (type) = 1;
2369 TYPE_FIELDS (type) =
2370 (struct field *) obstack_alloc (symbol_obstack,
2371 sizeof (struct field));
2372 TYPE_FIELD_TYPE (type, 0) = range_type;
2373
2374 return type;
2375}
2376
2377
2378/* Read a definition of an enumeration type,
2379 and create and return a suitable type object.
2380 Also defines the symbols that represent the values of the type. */
2381
2382struct type *
2383read_enum_type (pp, type)
2384 register char **pp;
2385 register struct type *type;
2386{
2387 register char *p;
2388 char *name;
2389 register long n;
2390 register struct symbol *sym;
2391 int nsyms = 0;
2392 struct pending **symlist;
2393 struct pending *osyms, *syms;
2394 int o_nsyms;
2395
2396 if (within_function)
2397 symlist = &local_symbols;
2398 else
2399 symlist = &file_symbols;
2400 osyms = *symlist;
2401 o_nsyms = osyms ? osyms->nsyms : 0;
2402
2403 /* Read the value-names and their values.
2404 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2405 A semicolon or comman instead of a NAME means the end. */
2406 while (**pp && **pp != ';' && **pp != ',')
2407 {
2408 /* Check for and handle cretinous dbx symbol name continuation! */
2409 if (**pp == '\\') *pp = next_symbol_text ();
2410
2411 p = *pp;
2412 while (*p != ':') p++;
2413 name = obsavestring (*pp, p - *pp);
2414 *pp = p + 1;
2415 n = read_number (pp, ',');
2416
2417 sym = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol));
2418 bzero (sym, sizeof (struct symbol));
2419 SYMBOL_NAME (sym) = name;
2420 SYMBOL_CLASS (sym) = LOC_CONST;
2421 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2422 SYMBOL_VALUE (sym) = n;
2423 add_symbol_to_list (sym, symlist);
2424 nsyms++;
2425 }
2426
2427 if (**pp == ';')
2428 (*pp)++; /* Skip the semicolon. */
2429
2430 /* Now fill in the fields of the type-structure. */
2431
2432 TYPE_LENGTH (type) = sizeof (int);
2433 TYPE_CODE (type) = TYPE_CODE_ENUM;
2434 TYPE_NFIELDS (type) = nsyms;
2435 TYPE_FIELDS (type) = (struct field *) obstack_alloc (symbol_obstack, sizeof (struct field) * nsyms);
2436
2437 /* Find the symbols for the values and put them into the type.
2438 The symbols can be found in the symlist that we put them on
2439 to cause them to be defined. osyms contains the old value
2440 of that symlist; everything up to there was defined by us. */
2441 /* Note that we preserve the order of the enum constants, so
2442 that in something like "enum {FOO, LAST_THING=FOO}" we print
2443 FOO, not LAST_THING. */
2444
2445 for (syms = *symlist, n = 0; syms; syms = syms->next)
2446 {
2447 int j = 0;
2448 if (syms == osyms)
2449 j = o_nsyms;
2450 for (; j < syms->nsyms; j++,n++)
2451 {
2452 struct symbol *xsym = syms->symbol[j];
2453 SYMBOL_TYPE (xsym) = type;
2454 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
2455 TYPE_FIELD_VALUE (type, n) = 0;
2456 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
2457 TYPE_FIELD_BITSIZE (type, n) = 0;
2458 }
2459 if (syms == osyms)
2460 break;
2461 }
2462
2463#if 0
2464 /* This screws up perfectly good C programs with enums. FIXME. */
2465 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2466 if(TYPE_NFIELDS(type) == 2 &&
2467 ((!strcmp(TYPE_FIELD_NAME(type,0),"TRUE") &&
2468 !strcmp(TYPE_FIELD_NAME(type,1),"FALSE")) ||
2469 (!strcmp(TYPE_FIELD_NAME(type,1),"TRUE") &&
2470 !strcmp(TYPE_FIELD_NAME(type,0),"FALSE"))))
2471 TYPE_CODE(type) = TYPE_CODE_BOOL;
2472#endif
2473
2474 return type;
2475}
2476
2477/* Read a number from the string pointed to by *PP.
2478 The value of *PP is advanced over the number.
2479 If END is nonzero, the character that ends the
2480 number must match END, or an error happens;
2481 and that character is skipped if it does match.
2482 If END is zero, *PP is left pointing to that character.
2483
2484 If the number fits in a long, set *VALUE and set *BITS to 0.
2485 If not, set *BITS to be the number of bits in the number.
2486
2487 If encounter garbage, set *BITS to -1. */
2488
2489void
2490read_huge_number (pp, end, valu, bits)
2491 char **pp;
2492 int end;
2493 long *valu;
2494 int *bits;
2495{
2496 char *p = *pp;
2497 int sign = 1;
2498 long n = 0;
2499 int radix = 10;
2500 char overflow = 0;
2501 int nbits = 0;
2502 int c;
2503 long upper_limit;
2504
2505 if (*p == '-')
2506 {
2507 sign = -1;
2508 p++;
2509 }
2510
2511 /* Leading zero means octal. GCC uses this to output values larger
2512 than an int (because that would be hard in decimal). */
2513 if (*p == '0')
2514 {
2515 radix = 8;
2516 p++;
2517 }
2518
2519 upper_limit = LONG_MAX / radix;
2520 while ((c = *p++) >= '0' && c <= ('0' + radix))
2521 {
2522 if (n <= upper_limit)
2523 {
2524 n *= radix;
2525 n += c - '0'; /* FIXME this overflows anyway */
2526 }
2527 else
2528 overflow = 1;
2529
2530 /* This depends on large values being output in octal, which is
2531 what GCC does. */
2532 if (radix == 8)
2533 {
2534 if (nbits == 0)
2535 {
2536 if (c == '0')
2537 /* Ignore leading zeroes. */
2538 ;
2539 else if (c == '1')
2540 nbits = 1;
2541 else if (c == '2' || c == '3')
2542 nbits = 2;
2543 else
2544 nbits = 3;
2545 }
2546 else
2547 nbits += 3;
2548 }
2549 }
2550 if (end)
2551 {
2552 if (c && c != end)
2553 {
2554 if (bits != NULL)
2555 *bits = -1;
2556 return;
2557 }
2558 }
2559 else
2560 --p;
2561
2562 *pp = p;
2563 if (overflow)
2564 {
2565 if (nbits == 0)
2566 {
2567 /* Large decimal constants are an error (because it is hard to
2568 count how many bits are in them). */
2569 if (bits != NULL)
2570 *bits = -1;
2571 return;
2572 }
2573
2574 /* -0x7f is the same as 0x80. So deal with it by adding one to
2575 the number of bits. */
2576 if (sign == -1)
2577 ++nbits;
2578 if (bits)
2579 *bits = nbits;
2580 }
2581 else
2582 {
2583 if (valu)
2584 *valu = n * sign;
2585 if (bits)
2586 *bits = 0;
2587 }
2588}
2589
2590#define MAX_OF_C_TYPE(t) ((1 << (sizeof (t)*8 - 1)) - 1)
2591#define MIN_OF_C_TYPE(t) (-(1 << (sizeof (t)*8 - 1)))
2592
2593struct type *
2594read_range_type (pp, typenums)
2595 char **pp;
2596 int typenums[2];
2597{
2598 int rangenums[2];
2599 long n2, n3;
2600 int n2bits, n3bits;
2601 int self_subrange;
2602 struct type *result_type;
2603
2604 /* First comes a type we are a subrange of.
2605 In C it is usually 0, 1 or the type being defined. */
2606 read_type_number (pp, rangenums);
2607 self_subrange = (rangenums[0] == typenums[0] &&
2608 rangenums[1] == typenums[1]);
2609
2610 /* A semicolon should now follow; skip it. */
2611 if (**pp == ';')
2612 (*pp)++;
2613
2614 /* The remaining two operands are usually lower and upper bounds
2615 of the range. But in some special cases they mean something else. */
2616 read_huge_number (pp, ';', &n2, &n2bits);
2617 read_huge_number (pp, ';', &n3, &n3bits);
2618
2619 if (n2bits == -1 || n3bits == -1)
2620 return error_type (pp);
2621
2622 /* If limits are huge, must be large integral type. */
2623 if (n2bits != 0 || n3bits != 0)
2624 {
2625 char got_signed = 0;
2626 char got_unsigned = 0;
2627 /* Number of bits in the type. */
2628 int nbits;
2629
2630 /* Range from 0 to <large number> is an unsigned large integral type. */
2631 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
2632 {
2633 got_unsigned = 1;
2634 nbits = n3bits;
2635 }
2636 /* Range from <large number> to <large number>-1 is a large signed
2637 integral type. */
2638 else if (n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
2639 {
2640 got_signed = 1;
2641 nbits = n2bits;
2642 }
2643
2644 /* Check for "long long". */
2645 if (got_signed && nbits == TARGET_LONG_LONG_BIT)
2646 return builtin_type_long_long;
2647 if (got_unsigned && nbits == TARGET_LONG_LONG_BIT)
2648 return builtin_type_unsigned_long_long;
2649
2650 if (got_signed || got_unsigned)
2651 {
2652 result_type = (struct type *) obstack_alloc (symbol_obstack,
2653 sizeof (struct type));
2654 bzero (result_type, sizeof (struct type));
2655 TYPE_LENGTH (result_type) = nbits / TARGET_CHAR_BIT;
2656 TYPE_MAIN_VARIANT (result_type) = result_type;
2657 TYPE_CODE (result_type) = TYPE_CODE_INT;
2658 if (got_unsigned)
2659 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
2660 return result_type;
2661 }
2662 else
2663 return error_type (pp);
2664 }
2665
2666 /* A type defined as a subrange of itself, with bounds both 0, is void. */
2667 if (self_subrange && n2 == 0 && n3 == 0)
2668 return builtin_type_void;
2669
2670 /* If n3 is zero and n2 is not, we want a floating type,
2671 and n2 is the width in bytes.
2672
2673 Fortran programs appear to use this for complex types also,
2674 and they give no way to distinguish between double and single-complex!
2675 We don't have complex types, so we would lose on all fortran files!
2676 So return type `double' for all of those. It won't work right
2677 for the complex values, but at least it makes the file loadable. */
2678
2679 if (n3 == 0 && n2 > 0)
2680 {
2681 if (n2 == sizeof (float))
2682 return builtin_type_float;
2683 return builtin_type_double;
2684 }
2685
2686 /* If the upper bound is -1, it must really be an unsigned int. */
2687
2688 else if (n2 == 0 && n3 == -1)
2689 {
2690 if (sizeof (int) == sizeof (long))
2691 return builtin_type_unsigned_int;
2692 else
2693 return builtin_type_unsigned_long;
2694 }
2695
2696 /* Special case: char is defined (Who knows why) as a subrange of
2697 itself with range 0-127. */
2698 else if (self_subrange && n2 == 0 && n3 == 127)
2699 return builtin_type_char;
2700
2701 /* Assumptions made here: Subrange of self is equivalent to subrange
2702 of int. */
2703 else if (n2 == 0
2704 && (self_subrange ||
2705 *dbx_lookup_type (rangenums) == builtin_type_int))
2706 {
2707 /* an unsigned type */
2708#ifdef LONG_LONG
2709 if (n3 == - sizeof (long long))
2710 return builtin_type_unsigned_long_long;
2711#endif
2712 if (n3 == (unsigned int)~0L)
2713 return builtin_type_unsigned_int;
2714 if (n3 == (unsigned long)~0L)
2715 return builtin_type_unsigned_long;
2716 if (n3 == (unsigned short)~0L)
2717 return builtin_type_unsigned_short;
2718 if (n3 == (unsigned char)~0L)
2719 return builtin_type_unsigned_char;
2720 }
2721#ifdef LONG_LONG
2722 else if (n3 == 0 && n2 == -sizeof (long long))
2723 return builtin_type_long_long;
2724#endif
2725 else if (n2 == -n3 -1)
2726 {
2727 /* a signed type */
2728 if (n3 == (1 << (8 * sizeof (int) - 1)) - 1)
2729 return builtin_type_int;
2730 if (n3 == (1 << (8 * sizeof (long) - 1)) - 1)
2731 return builtin_type_long;
2732 if (n3 == (1 << (8 * sizeof (short) - 1)) - 1)
2733 return builtin_type_short;
2734 if (n3 == (1 << (8 * sizeof (char) - 1)) - 1)
2735 return builtin_type_char;
2736 }
2737
2738 /* We have a real range type on our hands. Allocate space and
2739 return a real pointer. */
2740
2741 /* At this point I don't have the faintest idea how to deal with
2742 a self_subrange type; I'm going to assume that this is used
2743 as an idiom, and that all of them are special cases. So . . . */
2744 if (self_subrange)
2745 return error_type (pp);
2746
2747 result_type = (struct type *) obstack_alloc (symbol_obstack,
2748 sizeof (struct type));
2749 bzero (result_type, sizeof (struct type));
2750
2751 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
2752
2753 TYPE_TARGET_TYPE (result_type) = *dbx_lookup_type(rangenums);
2754 if (TYPE_TARGET_TYPE (result_type) == 0) {
2755 complain (&range_type_base_complaint, rangenums[1]);
2756 TYPE_TARGET_TYPE (result_type) = builtin_type_int;
2757 }
2758
2759 TYPE_NFIELDS (result_type) = 2;
2760 TYPE_FIELDS (result_type) =
2761 (struct field *) obstack_alloc (symbol_obstack,
2762 2 * sizeof (struct field));
2763 bzero (TYPE_FIELDS (result_type), 2 * sizeof (struct field));
2764 TYPE_FIELD_BITPOS (result_type, 0) = n2;
2765 TYPE_FIELD_BITPOS (result_type, 1) = n3;
2766
2767#if 0
2768/* Note that TYPE_LENGTH (result_type) is just overridden a few
2769 statements down. What do we really need here? */
2770 /* We have to figure out how many bytes it takes to hold this
2771 range type. I'm going to assume that anything that is pushing
2772 the bounds of a long was taken care of above. */
2773 if (n2 >= MIN_OF_C_TYPE(char) && n3 <= MAX_OF_C_TYPE(char))
2774 TYPE_LENGTH (result_type) = 1;
2775 else if (n2 >= MIN_OF_C_TYPE(short) && n3 <= MAX_OF_C_TYPE(short))
2776 TYPE_LENGTH (result_type) = sizeof (short);
2777 else if (n2 >= MIN_OF_C_TYPE(int) && n3 <= MAX_OF_C_TYPE(int))
2778 TYPE_LENGTH (result_type) = sizeof (int);
2779 else if (n2 >= MIN_OF_C_TYPE(long) && n3 <= MAX_OF_C_TYPE(long))
2780 TYPE_LENGTH (result_type) = sizeof (long);
2781 else
2782 /* Ranged type doesn't fit within known sizes. */
2783 /* FIXME -- use "long long" here. */
2784 return error_type (pp);
2785#endif
2786
2787 TYPE_LENGTH (result_type) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type));
2788
2789 return result_type;
2790}
2791
2792/* Read a number from the string pointed to by *PP.
2793 The value of *PP is advanced over the number.
2794 If END is nonzero, the character that ends the
2795 number must match END, or an error happens;
2796 and that character is skipped if it does match.
2797 If END is zero, *PP is left pointing to that character. */
2798
2799long
2800read_number (pp, end)
2801 char **pp;
2802 int end;
2803{
2804 register char *p = *pp;
2805 register long n = 0;
2806 register int c;
2807 int sign = 1;
2808
2809 /* Handle an optional leading minus sign. */
2810
2811 if (*p == '-')
2812 {
2813 sign = -1;
2814 p++;
2815 }
2816
2817 /* Read the digits, as far as they go. */
2818
2819 while ((c = *p++) >= '0' && c <= '9')
2820 {
2821 n *= 10;
2822 n += c - '0';
2823 }
2824 if (end)
2825 {
2826 if (c && c != end)
2827 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c, symnum);
2828 }
2829 else
2830 --p;
2831
2832 *pp = p;
2833 return n * sign;
2834}
2835
2836/* Read in an argument list. This is a list of types, separated by commas
2837 and terminated with END. Return the list of types read in, or (struct type
2838 **)-1 if there is an error. */
2839struct type **
2840read_args (pp, end)
2841 char **pp;
2842 int end;
2843{
2844 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
2845 int n = 0;
2846
2847 while (**pp != end)
2848 {
2849 if (**pp != ',')
2850 /* Invalid argument list: no ','. */
2851 return (struct type **)-1;
2852 *pp += 1;
2853
2854 /* Check for and handle cretinous dbx symbol name continuation! */
2855 if (**pp == '\\')
2856 *pp = next_symbol_text ();
2857
2858 types[n++] = read_type (pp);
2859 }
2860 *pp += 1; /* get past `end' (the ':' character) */
2861
2862 if (n == 1)
2863 {
2864 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
2865 }
2866 else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID)
2867 {
2868 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
2869 bzero (rval + n, sizeof (struct type *));
2870 }
2871 else
2872 {
2873 rval = (struct type **) xmalloc (n * sizeof (struct type *));
2874 }
2875 bcopy (types, rval, n * sizeof (struct type *));
2876 return rval;
2877}
2878
2879/* Add a common block's start address to the offset of each symbol
2880 declared to be in it (by being between a BCOMM/ECOMM pair that uses
2881 the common block name). */
2882
2883static void
2884fix_common_block (sym, valu)
2885 struct symbol *sym;
2886 int valu;
2887{
2888 struct pending *next = (struct pending *) SYMBOL_NAMESPACE (sym);
2889 for ( ; next; next = next->next)
2890 {
2891 register int j;
2892 for (j = next->nsyms - 1; j >= 0; j--)
2893 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
2894 }
2895}
2896
2897/* Initializer for this module */
2898void
2899_initialize_buildsym ()
2900{
2901 undef_types_allocated = 20;
2902 undef_types_length = 0;
2903 undef_types = (struct type **) xmalloc (undef_types_allocated *
2904 sizeof (struct type *));
2905}
This page took 0.129944 seconds and 4 git commands to generate.