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