]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/stabsread.c
6ee61e0a1174a8ca021e3f9e2ce2d723d59a0e35
[thirdparty/binutils-gdb.git] / gdb / stabsread.c
1 /* Support routines for decoding "stabs" debugging information format.
2
3 Copyright (C) 1986-2025 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 /* Support routines for reading and decoding debugging information in
21 the "stabs" format. This format is used by some systems that use
22 COFF or ELF where the stabs data is placed in a special section (as
23 well as with many old systems that used the a.out object file
24 format). Avoid placing any object file format specific code in
25 this file. */
26
27 #include "bfd.h"
28 #include "event-top.h"
29 #include "gdbsupport/gdb_obstack.h"
30 #include "symtab.h"
31 #include "gdbtypes.h"
32 #include "expression.h"
33 #include "symfile.h"
34 #include "objfiles.h"
35 #include "aout/stab_gnu.h"
36 #include "psymtab.h"
37 #include "libaout.h"
38 #include "aout/aout64.h"
39 #include "gdb-stabs.h"
40 #include "buildsym-legacy.h"
41 #include "complaints.h"
42 #include "demangle.h"
43 #include "gdb-demangle.h"
44 #include "language.h"
45 #include "target-float.h"
46 #include "c-lang.h"
47 #include "cp-abi.h"
48 #include "cp-support.h"
49 #include <ctype.h>
50 #include "block.h"
51 #include "filenames.h"
52
53 #include "stabsread.h"
54
55 /* See stabsread.h for these globals. */
56 unsigned int symnum;
57 const char *(*next_symbol_text_func) (struct objfile *);
58 unsigned char processing_gcc_compilation;
59 int within_function;
60 struct symbol *global_sym_chain[HASHSIZE];
61 struct pending_stabs *global_stabs;
62 int previous_stab_code;
63 int *this_object_header_files;
64 int n_this_object_header_files;
65 int n_allocated_this_object_header_files;
66
67 /* See stabsread.h. */
68
69 const registry<objfile>::key<dbx_symfile_info> dbx_objfile_data_key;
70
71 dbx_symfile_info::~dbx_symfile_info ()
72 {
73 if (header_files != NULL)
74 {
75 int i = n_header_files;
76 struct header_file *hfiles = header_files;
77
78 while (--i >= 0)
79 {
80 xfree (hfiles[i].name);
81 xfree (hfiles[i].vector);
82 }
83 xfree (hfiles);
84 }
85 }
86
87 struct stabs_nextfield
88 {
89 struct stabs_nextfield *next;
90
91 struct field field;
92 };
93
94 struct next_fnfieldlist
95 {
96 struct next_fnfieldlist *next;
97 struct fn_fieldlist fn_fieldlist;
98 };
99
100 /* The routines that read and process a complete stabs for a C struct or
101 C++ class pass lists of data member fields and lists of member function
102 fields in an instance of a field_info structure, as defined below.
103 This is part of some reorganization of low level C++ support and is
104 expected to eventually go away... (FIXME) */
105
106 struct stab_field_info
107 {
108 struct stabs_nextfield *list = nullptr;
109 struct next_fnfieldlist *fnlist = nullptr;
110
111 auto_obstack obstack;
112 };
113
114 static void
115 read_one_struct_field (struct stab_field_info *, const char **, const char *,
116 struct type *, struct objfile *);
117
118 static struct type *dbx_alloc_type (int[2], struct objfile *);
119
120 static long read_huge_number (const char **, int, int *, int);
121
122 static struct type *error_type (const char **, struct objfile *);
123
124 static void
125 patch_block_stabs (struct pending *, struct pending_stabs *,
126 struct objfile *);
127
128 static int read_type_number (const char **, int *);
129
130 static struct type *read_type (const char **, struct objfile *);
131
132 static struct type *read_range_type (const char **, int[2],
133 int, struct objfile *);
134
135 static struct type *read_sun_builtin_type (const char **,
136 int[2], struct objfile *);
137
138 static struct type *read_sun_floating_type (const char **, int[2],
139 struct objfile *);
140
141 static struct type *read_enum_type (const char **, struct type *, struct objfile *);
142
143 static struct type *rs6000_builtin_type (int, struct objfile *);
144
145 static int
146 read_member_functions (struct stab_field_info *, const char **, struct type *,
147 struct objfile *);
148
149 static int
150 read_struct_fields (struct stab_field_info *, const char **, struct type *,
151 struct objfile *);
152
153 static int
154 read_baseclasses (struct stab_field_info *, const char **, struct type *,
155 struct objfile *);
156
157 static int
158 read_tilde_fields (struct stab_field_info *, const char **, struct type *,
159 struct objfile *);
160
161 static int attach_fn_fields_to_type (struct stab_field_info *, struct type *);
162
163 static int attach_fields_to_type (struct stab_field_info *, struct type *,
164 struct objfile *);
165
166 static struct type *read_struct_type (const char **, struct type *,
167 enum type_code,
168 struct objfile *);
169
170 static struct type *read_array_type (const char **, struct type *,
171 struct objfile *);
172
173 static struct field *read_args (const char **, int, struct objfile *,
174 int *, int *);
175
176 static void add_undefined_type (struct type *, int[2]);
177
178 static int
179 read_cpp_abbrev (struct stab_field_info *, const char **, struct type *,
180 struct objfile *);
181
182 static const char *find_name_end (const char *name);
183
184 static int process_reference (const char **string);
185
186 void stabsread_clear_cache (void);
187
188 static const char vptr_name[] = "_vptr$";
189 static const char vb_name[] = "_vb$";
190
191 void
192 unknown_symtype_complaint (const char *arg1)
193 {
194 complaint (_("unknown symbol type %s"), arg1);
195 }
196
197 void
198 lbrac_mismatch_complaint (int arg1)
199 {
200 complaint (_("N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d"), arg1);
201 }
202
203 void
204 repeated_header_complaint (const char *arg1, int arg2)
205 {
206 complaint (_("\"repeated\" header file %s not "
207 "previously seen, at symtab pos %d"),
208 arg1, arg2);
209 }
210
211 static void
212 invalid_cpp_abbrev_complaint (const char *arg1)
213 {
214 complaint (_("invalid C++ abbreviation `%s'"), arg1);
215 }
216
217 static void
218 reg_value_complaint (int regnum, int num_regs, const char *sym)
219 {
220 complaint (_("bad register number %d (max %d) in symbol %s"),
221 regnum, num_regs - 1, sym);
222 }
223
224 static void
225 stabs_general_complaint (const char *arg1)
226 {
227 complaint ("%s", arg1);
228 }
229
230 static void
231 function_outside_compilation_unit_complaint (const char *arg1)
232 {
233 complaint (_("function `%s' appears to be defined "
234 "outside of all compilation units"),
235 arg1);
236 }
237
238 /* Make a list of forward references which haven't been defined. */
239
240 static struct type **undef_types;
241 static int undef_types_allocated;
242 static int undef_types_length;
243 static struct symbol *current_symbol = NULL;
244
245 /* Make a list of nameless types that are undefined.
246 This happens when another type is referenced by its number
247 before this type is actually defined. For instance "t(0,1)=k(0,2)"
248 and type (0,2) is defined only later. */
249
250 struct nat
251 {
252 int typenums[2];
253 struct type *type;
254 };
255 static struct nat *noname_undefs;
256 static int noname_undefs_allocated;
257 static int noname_undefs_length;
258
259 /* Check for and handle cretinous stabs symbol name continuation! */
260 #define STABS_CONTINUE(pp,objfile) \
261 do { \
262 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
263 *(pp) = next_symbol_text (objfile); \
264 } while (0)
265
266 /* Vector of types defined so far, indexed by their type numbers.
267 (In newer sun systems, dbx uses a pair of numbers in parens,
268 as in "(SUBFILENUM,NUMWITHINSUBFILE)".
269 Then these numbers must be translated through the type_translations
270 hash table to get the index into the type vector.) */
271
272 static struct type **type_vector;
273
274 /* Number of elements allocated for type_vector currently. */
275
276 static int type_vector_length;
277
278 /* Initial size of type vector. Is realloc'd larger if needed, and
279 realloc'd down to the size actually used, when completed. */
280
281 #define INITIAL_TYPE_VECTOR_LENGTH 160
282 \f
283
284 /* Look up a dbx type-number pair. Return the address of the slot
285 where the type for that number-pair is stored.
286 The number-pair is in TYPENUMS.
287
288 This can be used for finding the type associated with that pair
289 or for associating a new type with the pair. */
290
291 static struct type **
292 dbx_lookup_type (int typenums[2], struct objfile *objfile)
293 {
294 int filenum = typenums[0];
295 int index = typenums[1];
296 unsigned old_len;
297 int real_filenum;
298 struct header_file *f;
299 int f_orig_length;
300
301 if (filenum == -1) /* -1,-1 is for temporary types. */
302 return 0;
303
304 if (filenum < 0 || filenum >= n_this_object_header_files)
305 {
306 complaint (_("Invalid symbol data: type number "
307 "(%d,%d) out of range at symtab pos %d."),
308 filenum, index, symnum);
309 goto error_return;
310 }
311
312 if (filenum == 0)
313 {
314 if (index < 0)
315 {
316 /* Caller wants address of address of type. We think
317 that negative (rs6k builtin) types will never appear as
318 "lvalues", (nor should they), so we stuff the real type
319 pointer into a temp, and return its address. If referenced,
320 this will do the right thing. */
321 static struct type *temp_type;
322
323 temp_type = rs6000_builtin_type (index, objfile);
324 return &temp_type;
325 }
326
327 /* Type is defined outside of header files.
328 Find it in this object file's type vector. */
329 if (index >= type_vector_length)
330 {
331 old_len = type_vector_length;
332 if (old_len == 0)
333 {
334 type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
335 type_vector = XNEWVEC (struct type *, type_vector_length);
336 }
337 while (index >= type_vector_length)
338 {
339 type_vector_length *= 2;
340 }
341 type_vector = (struct type **)
342 xrealloc ((char *) type_vector,
343 (type_vector_length * sizeof (struct type *)));
344 memset (&type_vector[old_len], 0,
345 (type_vector_length - old_len) * sizeof (struct type *));
346 }
347 return (&type_vector[index]);
348 }
349 else
350 {
351 real_filenum = this_object_header_files[filenum];
352
353 if (real_filenum >= N_HEADER_FILES (objfile))
354 {
355 static struct type *temp_type;
356
357 warning (_("GDB internal error: bad real_filenum"));
358
359 error_return:
360 temp_type = builtin_type (objfile)->builtin_error;
361 return &temp_type;
362 }
363
364 f = HEADER_FILES (objfile) + real_filenum;
365
366 f_orig_length = f->length;
367 if (index >= f_orig_length)
368 {
369 while (index >= f->length)
370 {
371 f->length *= 2;
372 }
373 f->vector = (struct type **)
374 xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
375 memset (&f->vector[f_orig_length], 0,
376 (f->length - f_orig_length) * sizeof (struct type *));
377 }
378 return (&f->vector[index]);
379 }
380 }
381
382 /* Make sure there is a type allocated for type numbers TYPENUMS
383 and return the type object.
384 This can create an empty (zeroed) type object.
385 TYPENUMS may be (-1, -1) to return a new type object that is not
386 put into the type vector, and so may not be referred to by number. */
387
388 static struct type *
389 dbx_alloc_type (int typenums[2], struct objfile *objfile)
390 {
391 struct type **type_addr;
392
393 if (typenums[0] == -1)
394 {
395 return type_allocator (objfile,
396 get_current_subfile ()->language).new_type ();
397 }
398
399 type_addr = dbx_lookup_type (typenums, objfile);
400
401 /* If we are referring to a type not known at all yet,
402 allocate an empty type for it.
403 We will fill it in later if we find out how. */
404 if (*type_addr == 0)
405 {
406 *type_addr = type_allocator (objfile,
407 get_current_subfile ()->language).new_type ();
408 }
409
410 return (*type_addr);
411 }
412
413 /* Allocate a floating-point type of size BITS. */
414
415 static struct type *
416 dbx_init_float_type (struct objfile *objfile, int bits)
417 {
418 struct gdbarch *gdbarch = objfile->arch ();
419 const struct floatformat **format;
420 struct type *type;
421
422 format = gdbarch_floatformat_for_type (gdbarch, NULL, bits);
423 type_allocator alloc (objfile, get_current_subfile ()->language);
424 if (format)
425 type = init_float_type (alloc, bits, NULL, format);
426 else
427 type = alloc.new_type (TYPE_CODE_ERROR, bits, NULL);
428
429 return type;
430 }
431
432 /* for all the stabs in a given stab vector, build appropriate types
433 and fix their symbols in given symbol vector. */
434
435 static void
436 patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
437 struct objfile *objfile)
438 {
439 int ii;
440 char *name;
441 const char *pp;
442 struct symbol *sym;
443
444 if (stabs)
445 {
446 /* for all the stab entries, find their corresponding symbols and
447 patch their types! */
448
449 for (ii = 0; ii < stabs->count; ++ii)
450 {
451 name = stabs->stab[ii];
452 pp = (char *) strchr (name, ':');
453 gdb_assert (pp); /* Must find a ':' or game's over. */
454 while (pp[1] == ':')
455 {
456 pp += 2;
457 pp = (char *) strchr (pp, ':');
458 }
459 sym = find_symbol_in_list (symbols, name, pp - name);
460 if (!sym)
461 {
462 /* FIXME-maybe: it would be nice if we noticed whether
463 the variable was defined *anywhere*, not just whether
464 it is defined in this compilation unit. But neither
465 xlc or GCC seem to need such a definition, and until
466 we do psymtabs (so that the minimal symbols from all
467 compilation units are available now), I'm not sure
468 how to get the information. */
469
470 /* On xcoff, if a global is defined and never referenced,
471 ld will remove it from the executable. There is then
472 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
473 sym = new (&objfile->objfile_obstack) symbol;
474 sym->set_domain (VAR_DOMAIN);
475 sym->set_aclass_index (LOC_OPTIMIZED_OUT);
476 sym->set_linkage_name
477 (obstack_strndup (&objfile->objfile_obstack, name, pp - name));
478 pp += 2;
479 if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
480 {
481 /* I don't think the linker does this with functions,
482 so as far as I know this is never executed.
483 But it doesn't hurt to check. */
484 sym->set_type
485 (lookup_function_type (read_type (&pp, objfile)));
486 }
487 else
488 {
489 sym->set_type (read_type (&pp, objfile));
490 }
491 add_symbol_to_list (sym, get_global_symbols ());
492 }
493 else
494 {
495 pp += 2;
496 if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
497 {
498 sym->set_type
499 (lookup_function_type (read_type (&pp, objfile)));
500 }
501 else
502 {
503 sym->set_type (read_type (&pp, objfile));
504 }
505 }
506 }
507 }
508 }
509 \f
510
511 /* Read a number by which a type is referred to in dbx data,
512 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
513 Just a single number N is equivalent to (0,N).
514 Return the two numbers by storing them in the vector TYPENUMS.
515 TYPENUMS will then be used as an argument to dbx_lookup_type.
516
517 Returns 0 for success, -1 for error. */
518
519 static int
520 read_type_number (const char **pp, int *typenums)
521 {
522 int nbits;
523
524 if (**pp == '(')
525 {
526 (*pp)++;
527 typenums[0] = read_huge_number (pp, ',', &nbits, 0);
528 if (nbits != 0)
529 return -1;
530 typenums[1] = read_huge_number (pp, ')', &nbits, 0);
531 if (nbits != 0)
532 return -1;
533 }
534 else
535 {
536 typenums[0] = 0;
537 typenums[1] = read_huge_number (pp, 0, &nbits, 0);
538 if (nbits != 0)
539 return -1;
540 }
541 return 0;
542 }
543 \f
544
545 /* Free up old header file tables. */
546
547 void
548 free_header_files (void)
549 {
550 if (this_object_header_files)
551 {
552 xfree (this_object_header_files);
553 this_object_header_files = NULL;
554 }
555 n_allocated_this_object_header_files = 0;
556 }
557
558 /* Allocate new header file tables. */
559
560 void
561 init_header_files (void)
562 {
563 n_allocated_this_object_header_files = 10;
564 this_object_header_files = XNEWVEC (int, 10);
565 }
566
567 /* Close off the current usage of PST.
568 Returns PST or NULL if the partial symtab was empty and thrown away.
569
570 FIXME: List variables and peculiarities of same. */
571
572 legacy_psymtab *
573 stabs_end_psymtab (struct objfile *objfile, psymtab_storage *partial_symtabs,
574 legacy_psymtab *pst,
575 const char **include_list, int num_includes,
576 int capping_symbol_offset, unrelocated_addr capping_text,
577 legacy_psymtab **dependency_list,
578 int number_dependencies,
579 int textlow_not_set)
580 {
581 int i;
582 struct gdbarch *gdbarch = objfile->arch ();
583 dbx_symfile_info *key = dbx_objfile_data_key. get (objfile);
584
585 if (capping_symbol_offset != -1)
586 LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
587 pst->set_text_high (capping_text);
588
589 /* Under Solaris, the N_SO symbols always have a value of 0,
590 instead of the usual address of the .o file. Therefore,
591 we have to do some tricks to fill in texthigh and textlow.
592 The first trick is: if we see a static
593 or global function, and the textlow for the current pst
594 is not set (ie: textlow_not_set), then we use that function's
595 address for the textlow of the pst. */
596
597 /* Now, to fill in texthigh, we remember the last function seen
598 in the .o file. Also, there's a hack in
599 bfd/elf.c and gdb/elfread.c to pass the ELF st_size field
600 to here via the misc_info field. Therefore, we can fill in
601 a reliable texthigh by taking the address plus size of the
602 last function in the file. */
603
604 if (!pst->text_high_valid && key->ctx.last_function_name
605 && gdbarch_sofun_address_maybe_missing (gdbarch))
606 {
607 int n;
608
609 const char *colon = strchr (key->ctx.last_function_name, ':');
610 if (colon == NULL)
611 n = 0;
612 else
613 n = colon - key->ctx.last_function_name;
614 char *p = (char *) alloca (n + 2);
615 strncpy (p, key->ctx.last_function_name, n);
616 p[n] = 0;
617
618 bound_minimal_symbol minsym
619 = lookup_minimal_symbol (current_program_space, p, objfile,
620 pst->filename);
621 if (minsym.minsym == NULL)
622 {
623 /* Sun Fortran appends an underscore to the minimal symbol name,
624 try again with an appended underscore if the minimal symbol
625 was not found. */
626 p[n] = '_';
627 p[n + 1] = 0;
628 minsym = lookup_minimal_symbol (current_program_space, p, objfile,
629 pst->filename);
630 }
631
632 if (minsym.minsym)
633 pst->set_text_high
634 (unrelocated_addr (CORE_ADDR (minsym.minsym->unrelocated_address ())
635 + minsym.minsym->size ()));
636
637 key->ctx.last_function_name = NULL;
638 }
639
640 if (!gdbarch_sofun_address_maybe_missing (gdbarch))
641 ;
642 /* This test will be true if the last .o file is only data. */
643 else if (textlow_not_set)
644 pst->set_text_low (pst->unrelocated_text_high ());
645 else
646 {
647 /* If we know our own starting text address, then walk through all other
648 psymtabs for this objfile, and if any didn't know their ending text
649 address, set it to our starting address. Take care to not set our
650 own ending address to our starting address. */
651
652 for (partial_symtab *p1 : partial_symtabs->range ())
653 if (!p1->text_high_valid && p1->text_low_valid && p1 != pst)
654 p1->set_text_high (pst->unrelocated_text_low ());
655 }
656
657 /* End of kludge for patching Solaris textlow and texthigh. */
658
659 pst->end ();
660
661 pst->number_of_dependencies = number_dependencies;
662 if (number_dependencies)
663 {
664 pst->dependencies
665 = partial_symtabs->allocate_dependencies (number_dependencies);
666 memcpy (pst->dependencies, dependency_list,
667 number_dependencies * sizeof (legacy_psymtab *));
668 }
669 else
670 pst->dependencies = 0;
671
672 for (i = 0; i < num_includes; i++)
673 {
674 legacy_psymtab *subpst =
675 new legacy_psymtab (include_list[i], partial_symtabs, objfile->per_bfd);
676
677 subpst->read_symtab_private =
678 XOBNEW (&objfile->objfile_obstack, struct symloc);
679 LDSYMOFF (subpst) =
680 LDSYMLEN (subpst) = 0;
681
682 /* We could save slight bits of space by only making one of these,
683 shared by the entire set of include files. FIXME-someday. */
684 subpst->dependencies =
685 partial_symtabs->allocate_dependencies (1);
686 subpst->dependencies[0] = pst;
687 subpst->number_of_dependencies = 1;
688
689 subpst->legacy_read_symtab = pst->legacy_read_symtab;
690 subpst->legacy_expand_psymtab = pst->legacy_expand_psymtab;
691 }
692
693 if (num_includes == 0
694 && number_dependencies == 0
695 && pst->empty ()
696 && key->ctx.has_line_numbers == 0)
697 {
698 /* Throw away this psymtab, it's empty. */
699 /* Empty psymtabs happen as a result of header files which don't have
700 any symbols in them. There can be a lot of them. But this check
701 is wrong, in that a psymtab with N_SLINE entries but nothing else
702 is not empty, but we don't realize that. Fixing that without slowing
703 things down might be tricky. */
704
705 partial_symtabs->discard_psymtab (pst);
706
707 /* Indicate that psymtab was thrown away. */
708 pst = NULL;
709 }
710 return pst;
711 }
712
713 /* Set namestring based on nlist. If the string table index is invalid,
714 give a fake name, and print a single error message per symbol file read,
715 rather than abort the symbol reading or flood the user with messages. */
716
717 static const char *
718 set_namestring (struct objfile *objfile, const struct internal_nlist *nlist)
719 {
720 const char *namestring;
721 struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
722
723 if (nlist->n_strx + key->ctx.file_string_table_offset
724 >= DBX_STRINGTAB_SIZE (objfile)
725 || nlist->n_strx + key->ctx.file_string_table_offset < nlist->n_strx)
726 {
727 complaint (_("bad string table offset in symbol %d"),
728 symnum);
729 namestring = "<bad string table offset>";
730 }
731 else
732 namestring = (nlist->n_strx + key->ctx.file_string_table_offset
733 + DBX_STRINGTAB (objfile));
734 return namestring;
735 }
736
737 static void
738 stabs_seek (int sym_offset, struct objfile *objfile)
739 {
740 dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
741 if (key->ctx.stabs_data)
742 {
743 key->ctx.symbuf_read += sym_offset;
744 key->ctx.symbuf_left -= sym_offset;
745 }
746 else
747 if (bfd_seek (objfile->obfd.get (), sym_offset, SEEK_CUR) != 0)
748 perror_with_name (bfd_get_filename (objfile->obfd.get ()));
749 }
750
751 /* Buffer for reading the symbol table entries. */
752 static struct external_nlist symbuf[4096];
753 static int symbuf_idx;
754 static int symbuf_end;
755
756 /* Refill the symbol table input buffer
757 and set the variables that control fetching entries from it.
758 Reports an error if no data available.
759 This function can read past the end of the symbol table
760 (into the string table) but this does no harm. */
761
762 static void
763 fill_symbuf (bfd *sym_bfd, struct objfile *objfile)
764 {
765 unsigned int count;
766 int nbytes;
767 struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
768
769 if (key->ctx.stabs_data)
770 {
771 nbytes = sizeof (symbuf);
772 if (nbytes > key->ctx.symbuf_left)
773 nbytes = key->ctx.symbuf_left;
774 memcpy (symbuf, key->ctx.stabs_data + key->ctx.symbuf_read, nbytes);
775 }
776 else if (key->ctx.symbuf_sections == NULL)
777 {
778 count = sizeof (symbuf);
779 nbytes = bfd_read (symbuf, count, sym_bfd);
780 }
781 else
782 {
783 if (key->ctx.symbuf_left <= 0)
784 {
785 file_ptr filepos = (*key->ctx.symbuf_sections)[key->ctx.sect_idx]->filepos;
786
787 if (bfd_seek (sym_bfd, filepos, SEEK_SET) != 0)
788 perror_with_name (bfd_get_filename (sym_bfd));
789 key->ctx.symbuf_left = bfd_section_size ((*key->ctx.symbuf_sections)[key->ctx.sect_idx]);
790 key->ctx.symbol_table_offset = filepos - key->ctx.symbuf_read;
791 ++key->ctx.sect_idx;
792 }
793
794 count = key->ctx.symbuf_left;
795 if (count > sizeof (symbuf))
796 count = sizeof (symbuf);
797 nbytes = bfd_read (symbuf, count, sym_bfd);
798 }
799
800 if (nbytes < 0)
801 perror_with_name (bfd_get_filename (sym_bfd));
802 else if (nbytes == 0)
803 error (_("Premature end of file reading symbol table"));
804 symbuf_end = nbytes / key->ctx.symbol_size;
805 symbuf_idx = 0;
806 key->ctx.symbuf_left -= nbytes;
807 key->ctx.symbuf_read += nbytes;
808 }
809
810 /* Read in a defined section of a specific object file's symbols. */
811
812 static void
813 read_ofile_symtab (struct objfile *objfile, legacy_psymtab *pst)
814 {
815 const char *namestring;
816 struct external_nlist *bufp;
817 struct internal_nlist nlist;
818 unsigned char type;
819 unsigned max_symnum;
820 bfd *abfd;
821 int sym_offset; /* Offset to start of symbols to read */
822 int sym_size; /* Size of symbols to read */
823 CORE_ADDR text_offset; /* Start of text segment for symbols */
824 int text_size; /* Size of text segment for symbols */
825 struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
826
827 sym_offset = LDSYMOFF (pst);
828 sym_size = LDSYMLEN (pst);
829 text_offset = pst->text_low (objfile);
830 text_size = pst->text_high (objfile) - pst->text_low (objfile);
831 const section_offsets &section_offsets = objfile->section_offsets;
832
833 key->ctx.stringtab_global = DBX_STRINGTAB (objfile);
834 set_last_source_file (NULL);
835
836 abfd = objfile->obfd.get ();
837 symbuf_end = symbuf_idx = 0;
838 key->ctx.symbuf_read = 0;
839 key->ctx.symbuf_left = sym_offset + sym_size;
840
841 /* It is necessary to actually read one symbol *before* the start
842 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
843 occurs before the N_SO symbol.
844
845 Detecting this in read_stabs_symtab
846 would slow down initial readin, so we look for it here instead. */
847 if (!key->ctx.processing_acc_compilation && sym_offset >= (int) key->ctx.symbol_size)
848 {
849 stabs_seek (sym_offset - key->ctx.symbol_size, objfile);
850 fill_symbuf (abfd, objfile);
851 bufp = &symbuf[symbuf_idx++];
852 INTERNALIZE_SYMBOL (nlist, bufp, abfd);
853 OBJSTAT (objfile, n_stabs++);
854
855 namestring = set_namestring (objfile, &nlist);
856
857 processing_gcc_compilation = 0;
858 if (nlist.n_type == N_TEXT)
859 {
860 const char *tempstring = namestring;
861
862 if (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0)
863 processing_gcc_compilation = 1;
864 else if (strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0)
865 processing_gcc_compilation = 2;
866 if (*tempstring != '\0'
867 && *tempstring == bfd_get_symbol_leading_char (objfile->obfd.get ()))
868 ++tempstring;
869 if (startswith (tempstring, "__gnu_compiled"))
870 processing_gcc_compilation = 2;
871 }
872 }
873 else
874 {
875 /* The N_SO starting this symtab is the first symbol, so we
876 better not check the symbol before it. I'm not this can
877 happen, but it doesn't hurt to check for it. */
878 stabs_seek (sym_offset, objfile);
879 processing_gcc_compilation = 0;
880 }
881
882 if (symbuf_idx == symbuf_end)
883 fill_symbuf (abfd, objfile);
884 bufp = &symbuf[symbuf_idx];
885 if (bfd_h_get_8 (abfd, bufp->e_type) != N_SO)
886 error (_("First symbol in segment of executable not a source symbol"));
887
888 max_symnum = sym_size / key->ctx.symbol_size;
889
890 for (symnum = 0;
891 symnum < max_symnum;
892 symnum++)
893 {
894 QUIT; /* Allow this to be interruptible. */
895 if (symbuf_idx == symbuf_end)
896 fill_symbuf (abfd, objfile);
897 bufp = &symbuf[symbuf_idx++];
898 INTERNALIZE_SYMBOL (nlist, bufp, abfd);
899 OBJSTAT (objfile, n_stabs++);
900
901 type = bfd_h_get_8 (abfd, bufp->e_type);
902
903 namestring = set_namestring (objfile, &nlist);
904
905 if (type & N_STAB)
906 {
907 if (sizeof (nlist.n_value) > 4
908 /* We are a 64-bit debugger debugging a 32-bit program. */
909 && (type == N_LSYM || type == N_PSYM))
910 /* We have to be careful with the n_value in the case of N_LSYM
911 and N_PSYM entries, because they are signed offsets from frame
912 pointer, but we actually read them as unsigned 32-bit values.
913 This is not a problem for 32-bit debuggers, for which negative
914 values end up being interpreted correctly (as negative
915 offsets) due to integer overflow.
916 But we need to sign-extend the value for 64-bit debuggers,
917 or we'll end up interpreting negative values as very large
918 positive offsets. */
919 nlist.n_value = (nlist.n_value ^ 0x80000000) - 0x80000000;
920 process_one_symbol (type, nlist.n_desc, nlist.n_value,
921 namestring, section_offsets, objfile,
922 PST_LANGUAGE (pst));
923 }
924 /* We skip checking for a new .o or -l file; that should never
925 happen in this routine. */
926 else if (type == N_TEXT)
927 {
928 /* I don't think this code will ever be executed, because
929 the GCC_COMPILED_FLAG_SYMBOL usually is right before
930 the N_SO symbol which starts this source file.
931 However, there is no reason not to accept
932 the GCC_COMPILED_FLAG_SYMBOL anywhere. */
933
934 if (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0)
935 processing_gcc_compilation = 1;
936 else if (strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0)
937 processing_gcc_compilation = 2;
938 }
939 else if (type & N_EXT || type == (unsigned char) N_TEXT
940 || type == (unsigned char) N_NBTEXT)
941 {
942 /* Global symbol: see if we came across a dbx definition for
943 a corresponding symbol. If so, store the value. Remove
944 syms from the chain when their values are stored, but
945 search the whole chain, as there may be several syms from
946 different files with the same name. */
947 /* This is probably not true. Since the files will be read
948 in one at a time, each reference to a global symbol will
949 be satisfied in each file as it appears. So we skip this
950 section. */
951 ;
952 }
953 }
954
955 /* In a Solaris elf file, this variable, which comes from the value
956 of the N_SO symbol, will still be 0. Luckily, text_offset, which
957 comes from low text address of PST, is correct. */
958 if (get_last_source_start_addr () == 0)
959 set_last_source_start_addr (text_offset);
960
961 /* In reordered executables last_source_start_addr may not be the
962 lower bound for this symtab, instead use text_offset which comes
963 from the low text address of PST, which is correct. */
964 if (get_last_source_start_addr () > text_offset)
965 set_last_source_start_addr (text_offset);
966
967 pst->compunit_symtab = end_compunit_symtab (text_offset + text_size);
968
969 end_stabs ();
970
971 }
972
973 static void
974 dbx_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile)
975 {
976 gdb_assert (!pst->readin);
977 struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
978
979 /* Read in all partial symtabs on which this one is dependent. */
980 pst->expand_dependencies (objfile);
981
982 if (LDSYMLEN (pst)) /* Otherwise it's a dummy. */
983 {
984 /* Init stuff necessary for reading in symbols */
985 stabsread_init ();
986 scoped_free_pendings free_pending;
987 key->ctx.file_string_table_offset = FILE_STRING_OFFSET (pst);
988 key->ctx.symbol_size = SYMBOL_SIZE (pst);
989
990 /* Read in this file's symbols. */
991 if (bfd_seek (objfile->obfd.get (), SYMBOL_OFFSET (pst), SEEK_SET) == 0)
992 read_ofile_symtab (objfile, pst);
993 }
994
995 pst->readin = true;
996 }
997
998 /* Invariant: The symbol pointed to by symbuf_idx is the first one
999 that hasn't been swapped. Swap the symbol at the same time
1000 that symbuf_idx is incremented. */
1001
1002 /* dbx allows the text of a symbol name to be continued into the
1003 next symbol name! When such a continuation is encountered
1004 (a \ at the end of the text of a name)
1005 call this function to get the continuation. */
1006
1007 static const char *
1008 dbx_next_symbol_text (struct objfile *objfile)
1009 {
1010 struct internal_nlist nlist;
1011 dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
1012
1013 if (symbuf_idx == symbuf_end)
1014 fill_symbuf (objfile->obfd.get (), objfile);
1015
1016 symnum++;
1017 INTERNALIZE_SYMBOL (nlist, &symbuf[symbuf_idx], objfile->obfd.get ());
1018 OBJSTAT (objfile, n_stabs++);
1019
1020 symbuf_idx++;
1021
1022 return nlist.n_strx + key->ctx.stringtab_global
1023 + key->ctx.file_string_table_offset;
1024 }
1025
1026 /* Read in all of the symbols for a given psymtab for real.
1027 Be verbose about it if the user wants that. SELF is not NULL. */
1028
1029 static void
1030 stabs_read_symtab (legacy_psymtab *self, struct objfile *objfile)
1031 {
1032 gdb_assert (!self->readin);
1033
1034 if (LDSYMLEN (self) || self->number_of_dependencies)
1035 {
1036 next_symbol_text_func = dbx_next_symbol_text;
1037 dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
1038
1039 {
1040 scoped_restore restore_stabs_data = make_scoped_restore (&key->ctx.stabs_data);
1041 gdb::unique_xmalloc_ptr<gdb_byte> data_holder;
1042 if (DBX_STAB_SECTION (objfile))
1043 {
1044 key->ctx.stabs_data
1045 = symfile_relocate_debug_section (objfile,
1046 DBX_STAB_SECTION (objfile),
1047 NULL);
1048 data_holder.reset (key->ctx.stabs_data);
1049 }
1050
1051 self->expand_psymtab (objfile);
1052 }
1053
1054 /* Match with global symbols. This only needs to be done once,
1055 after all of the symtabs and dependencies have been read in. */
1056 scan_file_globals (objfile);
1057 }
1058 }
1059
1060 static void
1061 record_minimal_symbol (minimal_symbol_reader &reader,
1062 const char *name, unrelocated_addr address, int type,
1063 struct objfile *objfile)
1064 {
1065 enum minimal_symbol_type ms_type;
1066 int section;
1067 struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
1068
1069 switch (type)
1070 {
1071 case N_TEXT | N_EXT:
1072 ms_type = mst_text;
1073 section = SECT_OFF_TEXT (objfile);
1074 break;
1075 case N_DATA | N_EXT:
1076 ms_type = mst_data;
1077 section = SECT_OFF_DATA (objfile);
1078 break;
1079 case N_BSS | N_EXT:
1080 ms_type = mst_bss;
1081 section = SECT_OFF_BSS (objfile);
1082 break;
1083 case N_ABS | N_EXT:
1084 ms_type = mst_abs;
1085 section = -1;
1086 break;
1087 #ifdef N_SETV
1088 case N_SETV | N_EXT:
1089 ms_type = mst_data;
1090 section = SECT_OFF_DATA (objfile);
1091 break;
1092 case N_SETV:
1093 /* I don't think this type actually exists; since a N_SETV is the result
1094 of going over many .o files, it doesn't make sense to have one
1095 file local. */
1096 ms_type = mst_file_data;
1097 section = SECT_OFF_DATA (objfile);
1098 break;
1099 #endif
1100 case N_TEXT:
1101 case N_NBTEXT:
1102 case N_FN:
1103 case N_FN_SEQ:
1104 ms_type = mst_file_text;
1105 section = SECT_OFF_TEXT (objfile);
1106 break;
1107 case N_DATA:
1108 ms_type = mst_file_data;
1109
1110 /* Check for __DYNAMIC, which is used by Sun shared libraries.
1111 Record it as global even if it's local, not global, so
1112 lookup_minimal_symbol can find it. We don't check symbol_leading_char
1113 because for SunOS4 it always is '_'. */
1114 if (strcmp ("__DYNAMIC", name) == 0)
1115 ms_type = mst_data;
1116
1117 /* Same with virtual function tables, both global and static. */
1118 {
1119 const char *tempstring = name;
1120
1121 if (*tempstring != '\0'
1122 && *tempstring == bfd_get_symbol_leading_char (objfile->obfd.get ()))
1123 ++tempstring;
1124 if (is_vtable_name (tempstring))
1125 ms_type = mst_data;
1126 }
1127 section = SECT_OFF_DATA (objfile);
1128 break;
1129 case N_BSS:
1130 ms_type = mst_file_bss;
1131 section = SECT_OFF_BSS (objfile);
1132 break;
1133 default:
1134 ms_type = mst_unknown;
1135 section = -1;
1136 break;
1137 }
1138
1139 if ((ms_type == mst_file_text || ms_type == mst_text)
1140 && address < key->ctx.lowest_text_address)
1141 key->ctx.lowest_text_address = address;
1142
1143 reader.record_with_info (name, address, ms_type, section);
1144 }
1145
1146 /* Given a name, value pair, find the corresponding
1147 bincl in the list. Return the partial symtab associated
1148 with that header_file_location. */
1149
1150 static legacy_psymtab *
1151 find_corresponding_bincl_psymtab (const char *name, int instance,
1152 struct objfile* objfile)
1153 {
1154 stabsread_context ctx = dbx_objfile_data_key.get (objfile) -> ctx;
1155 for (const header_file_location &bincl : ctx.bincl_list)
1156 if (bincl.instance == instance
1157 && strcmp (name, bincl.name) == 0)
1158 return bincl.pst;
1159
1160 repeated_header_complaint (name, symnum);
1161 return (legacy_psymtab *) 0;
1162 }
1163
1164 /* Allocate and partially fill a partial symtab. It will be
1165 completely filled at the end of the symbol list.
1166
1167 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1168 is the address relative to which its symbols are (incremental) or 0
1169 (normal). */
1170
1171 static legacy_psymtab *
1172 start_psymtab (psymtab_storage *partial_symtabs, struct objfile *objfile,
1173 const char *filename, unrelocated_addr textlow, int ldsymoff)
1174 {
1175 legacy_psymtab *result = new legacy_psymtab (filename, partial_symtabs,
1176 objfile->per_bfd, textlow);
1177
1178 struct dbx_symfile_info *key = dbx_objfile_data_key.get(objfile);
1179
1180 result->read_symtab_private =
1181 XOBNEW (&objfile->objfile_obstack, struct symloc);
1182 LDSYMOFF (result) = ldsymoff;
1183 result->legacy_read_symtab = stabs_read_symtab;
1184 result->legacy_expand_psymtab = dbx_expand_psymtab;
1185 SYMBOL_SIZE (result) = key->ctx.symbol_size;
1186 SYMBOL_OFFSET (result) = key->ctx.symbol_table_offset;
1187 STRING_OFFSET (result) = 0; /* This used to be an uninitialized global. */
1188 FILE_STRING_OFFSET (result) = key->ctx.file_string_table_offset;
1189
1190 /* Deduce the source language from the filename for this psymtab. */
1191 key->ctx.psymtab_language = deduce_language_from_filename (filename);
1192 PST_LANGUAGE (result) = key->ctx.psymtab_language;
1193
1194 return result;
1195 }
1196
1197 /* See stabsread.h. */
1198
1199 static void
1200 read_stabs_symtab_1 (minimal_symbol_reader &reader,
1201 psymtab_storage *partial_symtabs,
1202 struct objfile *objfile)
1203 {
1204 struct gdbarch *gdbarch = objfile->arch ();
1205 struct external_nlist *bufp = 0; /* =0 avoids gcc -Wall glitch. */
1206 struct internal_nlist nlist;
1207 CORE_ADDR text_addr;
1208 int text_size;
1209 const char *sym_name;
1210 int sym_len;
1211 unsigned int next_file_string_table_offset = 0;
1212 struct dbx_symfile_info *dbx = dbx_objfile_data_key.get(objfile);
1213
1214 const char *namestring;
1215 int nsl;
1216 int past_first_source_file = 0;
1217 CORE_ADDR last_function_start = 0;
1218 bfd *abfd;
1219 int textlow_not_set;
1220 int data_sect_index;
1221
1222 /* Current partial symtab. */
1223 legacy_psymtab *pst;
1224
1225 /* List of current psymtab's include files. */
1226 const char **psymtab_include_list;
1227 int includes_allocated;
1228 int includes_used;
1229
1230 /* Index within current psymtab dependency list. */
1231 legacy_psymtab **dependency_list;
1232 int dependencies_used, dependencies_allocated;
1233
1234 text_addr = DBX_TEXT_ADDR (objfile);
1235 text_size = DBX_TEXT_SIZE (objfile);
1236
1237 /* FIXME. We probably want to change stringtab_global rather than add this
1238 while processing every symbol entry. FIXME. */
1239 dbx->ctx.file_string_table_offset = 0;
1240
1241 dbx->ctx.stringtab_global = DBX_STRINGTAB (objfile);
1242
1243 pst = (legacy_psymtab *) 0;
1244
1245 includes_allocated = 30;
1246 includes_used = 0;
1247 psymtab_include_list = (const char **) alloca (includes_allocated *
1248 sizeof (const char *));
1249
1250 dependencies_allocated = 30;
1251 dependencies_used = 0;
1252 dependency_list =
1253 (legacy_psymtab **) alloca (dependencies_allocated *
1254 sizeof (legacy_psymtab *));
1255
1256 /* Init bincl list */
1257 std::vector<struct header_file_location> bincl_storage;
1258 scoped_restore restore_bincl_global
1259 = make_scoped_restore (&(dbx->ctx.bincl_list), bincl_storage);
1260
1261 set_last_source_file (NULL);
1262
1263 dbx->ctx.lowest_text_address = (unrelocated_addr) -1;
1264
1265 abfd = objfile->obfd.get ();
1266 symbuf_end = symbuf_idx = 0;
1267 next_symbol_text_func = dbx_next_symbol_text;
1268 textlow_not_set = 1;
1269 dbx->ctx.has_line_numbers = 0;
1270
1271 /* FIXME: jimb/2003-09-12: We don't apply the right section's offset
1272 to global and static variables. The stab for a global or static
1273 variable doesn't give us any indication of which section it's in,
1274 so we can't tell immediately which offset in
1275 objfile->section_offsets we should apply to the variable's
1276 address.
1277
1278 We could certainly find out which section contains the variable
1279 by looking up the variable's unrelocated address with
1280 find_pc_section, but that would be expensive; this is the
1281 function that constructs the partial symbol tables by examining
1282 every symbol in the entire executable, and it's
1283 performance-critical. So that expense would not be welcome. I'm
1284 not sure what to do about this at the moment.
1285
1286 What we have done for years is to simply assume that the .data
1287 section's offset is appropriate for all global and static
1288 variables. Recently, this was expanded to fall back to the .bss
1289 section's offset if there is no .data section, and then to the
1290 .rodata section's offset. */
1291 data_sect_index = objfile->sect_index_data;
1292 if (data_sect_index == -1)
1293 data_sect_index = SECT_OFF_BSS (objfile);
1294 if (data_sect_index == -1)
1295 data_sect_index = SECT_OFF_RODATA (objfile);
1296
1297 /* If data_sect_index is still -1, that's okay. It's perfectly fine
1298 for the file to have no .data, no .bss, and no .text at all, if
1299 it also has no global or static variables. */
1300
1301 for (symnum = 0; symnum < DBX_SYMCOUNT (objfile); symnum++)
1302 {
1303 /* Get the symbol for this run and pull out some info. */
1304 QUIT; /* Allow this to be interruptible. */
1305 if (symbuf_idx == symbuf_end)
1306 fill_symbuf (abfd, objfile);
1307 bufp = &symbuf[symbuf_idx++];
1308
1309 /*
1310 * Special case to speed up readin.
1311 */
1312 if (bfd_h_get_8 (abfd, bufp->e_type) == N_SLINE)
1313 {
1314 dbx->ctx.has_line_numbers = 1;
1315 continue;
1316 }
1317
1318 INTERNALIZE_SYMBOL (nlist, bufp, abfd);
1319 OBJSTAT (objfile, n_stabs++);
1320
1321 /* Ok. There is a lot of code duplicated in the rest of this
1322 switch statement (for efficiency reasons). Since I don't
1323 like duplicating code, I will do my penance here, and
1324 describe the code which is duplicated:
1325
1326 *) The assignment to namestring.
1327 *) The call to strchr.
1328 *) The addition of a partial symbol the two partial
1329 symbol lists. This last is a large section of code, so
1330 I've embedded it in the following macro. */
1331
1332 switch (nlist.n_type)
1333 {
1334 /*
1335 * Standard, external, non-debugger, symbols
1336 */
1337
1338 case N_TEXT | N_EXT:
1339 case N_NBTEXT | N_EXT:
1340 goto record_it;
1341
1342 case N_DATA | N_EXT:
1343 case N_NBDATA | N_EXT:
1344 goto record_it;
1345
1346 case N_BSS:
1347 case N_BSS | N_EXT:
1348 case N_NBBSS | N_EXT:
1349 case N_SETV | N_EXT: /* FIXME, is this in BSS? */
1350 goto record_it;
1351
1352 case N_ABS | N_EXT:
1353 record_it:
1354 namestring = set_namestring (objfile, &nlist);
1355
1356 record_minimal_symbol (reader, namestring,
1357 unrelocated_addr (nlist.n_value),
1358 nlist.n_type, objfile); /* Always */
1359 continue;
1360
1361 /* Standard, local, non-debugger, symbols. */
1362
1363 case N_NBTEXT:
1364
1365 /* We need to be able to deal with both N_FN or N_TEXT,
1366 because we have no way of knowing whether the sys-supplied ld
1367 or GNU ld was used to make the executable. Sequents throw
1368 in another wrinkle -- they renumbered N_FN. */
1369
1370 case N_FN:
1371 case N_FN_SEQ:
1372 case N_TEXT:
1373 namestring = set_namestring (objfile, &nlist);
1374
1375 if ((namestring[0] == '-' && namestring[1] == 'l')
1376 || (namestring[(nsl = strlen (namestring)) - 1] == 'o'
1377 && namestring[nsl - 2] == '.'))
1378 {
1379 unrelocated_addr unrel_val = unrelocated_addr (nlist.n_value);
1380
1381 if (past_first_source_file && pst
1382 /* The gould NP1 uses low values for .o and -l symbols
1383 which are not the address. */
1384 && unrel_val >= pst->unrelocated_text_low ())
1385 {
1386 stabs_end_psymtab (objfile, partial_symtabs,
1387 pst, psymtab_include_list,
1388 includes_used, symnum * dbx->ctx.symbol_size,
1389 unrel_val > pst->unrelocated_text_high ()
1390 ? unrel_val : pst->unrelocated_text_high (),
1391 dependency_list, dependencies_used,
1392 textlow_not_set);
1393 pst = (legacy_psymtab *) 0;
1394 includes_used = 0;
1395 dependencies_used = 0;
1396 dbx->ctx.has_line_numbers = 0;
1397 }
1398 else
1399 past_first_source_file = 1;
1400 }
1401 else
1402 goto record_it;
1403 continue;
1404
1405 case N_DATA:
1406 goto record_it;
1407
1408 case N_UNDF | N_EXT:
1409 /* The case (nlist.n_value != 0) is a "Fortran COMMON" symbol.
1410 We used to rely on the target to tell us whether it knows
1411 where the symbol has been relocated to, but none of the
1412 target implementations actually provided that operation.
1413 So we just ignore the symbol, the same way we would do if
1414 we had a target-side symbol lookup which returned no match.
1415
1416 All other symbols (with nlist.n_value == 0), are really
1417 undefined, and so we ignore them too. */
1418 continue;
1419
1420 case N_UNDF:
1421 if (dbx->ctx.processing_acc_compilation && nlist.n_strx == 1)
1422 {
1423 /* Deal with relative offsets in the string table
1424 used in ELF+STAB under Solaris. If we want to use the
1425 n_strx field, which contains the name of the file,
1426 we must adjust file_string_table_offset *before* calling
1427 set_namestring(). */
1428 past_first_source_file = 1;
1429 dbx->ctx.file_string_table_offset = next_file_string_table_offset;
1430 next_file_string_table_offset =
1431 dbx->ctx.file_string_table_offset + nlist.n_value;
1432 if (next_file_string_table_offset < dbx->ctx.file_string_table_offset)
1433 error (_("string table offset backs up at %d"), symnum);
1434 /* FIXME -- replace error() with complaint. */
1435 continue;
1436 }
1437 continue;
1438
1439 /* Lots of symbol types we can just ignore. */
1440
1441 case N_ABS:
1442 case N_NBDATA:
1443 case N_NBBSS:
1444 continue;
1445
1446 /* Keep going . . . */
1447
1448 /*
1449 * Special symbol types for GNU
1450 */
1451 case N_INDR:
1452 case N_INDR | N_EXT:
1453 case N_SETA:
1454 case N_SETA | N_EXT:
1455 case N_SETT:
1456 case N_SETT | N_EXT:
1457 case N_SETD:
1458 case N_SETD | N_EXT:
1459 case N_SETB:
1460 case N_SETB | N_EXT:
1461 case N_SETV:
1462 continue;
1463
1464 /*
1465 * Debugger symbols
1466 */
1467
1468 case N_SO:
1469 {
1470 CORE_ADDR valu;
1471 static int prev_so_symnum = -10;
1472 static int first_so_symnum;
1473 const char *p;
1474 static const char *dirname_nso;
1475 int prev_textlow_not_set;
1476
1477 valu = nlist.n_value;
1478
1479 prev_textlow_not_set = textlow_not_set;
1480
1481 /* A zero value is probably an indication for the SunPRO 3.0
1482 compiler. stabs_end_psymtab explicitly tests for zero, so
1483 don't relocate it. */
1484
1485 if (nlist.n_value == 0
1486 && gdbarch_sofun_address_maybe_missing (gdbarch))
1487 {
1488 textlow_not_set = 1;
1489 valu = 0;
1490 }
1491 else
1492 textlow_not_set = 0;
1493
1494 past_first_source_file = 1;
1495
1496 if (prev_so_symnum != symnum - 1)
1497 { /* Here if prev stab wasn't N_SO. */
1498 first_so_symnum = symnum;
1499
1500 if (pst)
1501 {
1502 unrelocated_addr unrel_value = unrelocated_addr (valu);
1503 stabs_end_psymtab (objfile, partial_symtabs,
1504 pst, psymtab_include_list,
1505 includes_used, symnum * dbx->ctx.symbol_size,
1506 unrel_value > pst->unrelocated_text_high ()
1507 ? unrel_value
1508 : pst->unrelocated_text_high (),
1509 dependency_list, dependencies_used,
1510 prev_textlow_not_set);
1511 pst = (legacy_psymtab *) 0;
1512 includes_used = 0;
1513 dependencies_used = 0;
1514 dbx->ctx.has_line_numbers = 0;
1515 }
1516 }
1517
1518 prev_so_symnum = symnum;
1519
1520 /* End the current partial symtab and start a new one. */
1521
1522 namestring = set_namestring (objfile, &nlist);
1523
1524 /* Null name means end of .o file. Don't start a new one. */
1525 if (*namestring == '\000')
1526 continue;
1527
1528 /* Some compilers (including gcc) emit a pair of initial N_SOs.
1529 The first one is a directory name; the second the file name.
1530 If pst exists, is empty, and has a filename ending in '/',
1531 we assume the previous N_SO was a directory name. */
1532
1533 p = lbasename (namestring);
1534 if (p != namestring && *p == '\000')
1535 {
1536 /* Save the directory name SOs locally, then save it into
1537 the psymtab when it's created below. */
1538 dirname_nso = namestring;
1539 continue;
1540 }
1541
1542 /* Some other compilers (C++ ones in particular) emit useless
1543 SOs for non-existent .c files. We ignore all subsequent SOs
1544 that immediately follow the first. */
1545
1546 if (!pst)
1547 {
1548 pst = start_psymtab (partial_symtabs, objfile,
1549 namestring,
1550 unrelocated_addr (valu),
1551 first_so_symnum * dbx->ctx.symbol_size);
1552 pst->dirname = dirname_nso;
1553 dirname_nso = NULL;
1554 }
1555 continue;
1556 }
1557
1558 case N_BINCL:
1559 {
1560 enum language tmp_language;
1561
1562 /* Add this bincl to the bincl_list for future EXCLs. No
1563 need to save the string; it'll be around until
1564 read_stabs_symtab function returns. */
1565
1566 namestring = set_namestring (objfile, &nlist);
1567 tmp_language = deduce_language_from_filename (namestring);
1568
1569 /* Only change the psymtab's language if we've learned
1570 something useful (eg. tmp_language is not language_unknown).
1571 In addition, to match what start_subfile does, never change
1572 from C++ to C. */
1573 if (tmp_language != language_unknown
1574 && (tmp_language != language_c
1575 || dbx->ctx.psymtab_language != language_cplus))
1576 dbx->ctx.psymtab_language = tmp_language;
1577
1578 if (pst == NULL)
1579 {
1580 /* FIXME: we should not get here without a PST to work on.
1581 Attempt to recover. */
1582 complaint (_("N_BINCL %s not in entries for "
1583 "any file, at symtab pos %d"),
1584 namestring, symnum);
1585 continue;
1586 }
1587 dbx->ctx.bincl_list.emplace_back (namestring, nlist.n_value, pst);
1588
1589 /* Mark down an include file in the current psymtab. */
1590
1591 goto record_include_file;
1592 }
1593
1594 case N_SOL:
1595 {
1596 enum language tmp_language;
1597
1598 /* Mark down an include file in the current psymtab. */
1599 namestring = set_namestring (objfile, &nlist);
1600 tmp_language = deduce_language_from_filename (namestring);
1601
1602 /* Only change the psymtab's language if we've learned
1603 something useful (eg. tmp_language is not language_unknown).
1604 In addition, to match what start_subfile does, never change
1605 from C++ to C. */
1606 if (tmp_language != language_unknown
1607 && (tmp_language != language_c
1608 || dbx->ctx.psymtab_language != language_cplus))
1609 dbx->ctx.psymtab_language = tmp_language;
1610
1611 /* In C++, one may expect the same filename to come round many
1612 times, when code is coming alternately from the main file
1613 and from inline functions in other files. So I check to see
1614 if this is a file we've seen before -- either the main
1615 source file, or a previously included file.
1616
1617 This seems to be a lot of time to be spending on N_SOL, but
1618 things like "break c-exp.y:435" need to work (I
1619 suppose the psymtab_include_list could be hashed or put
1620 in a binary tree, if profiling shows this is a major hog). */
1621 if (pst && filename_cmp (namestring, pst->filename) == 0)
1622 continue;
1623 {
1624 int i;
1625
1626 for (i = 0; i < includes_used; i++)
1627 if (filename_cmp (namestring, psymtab_include_list[i]) == 0)
1628 {
1629 i = -1;
1630 break;
1631 }
1632 if (i == -1)
1633 continue;
1634 }
1635
1636 record_include_file:
1637
1638 psymtab_include_list[includes_used++] = namestring;
1639 if (includes_used >= includes_allocated)
1640 {
1641 const char **orig = psymtab_include_list;
1642
1643 psymtab_include_list = (const char **)
1644 alloca ((includes_allocated *= 2) * sizeof (const char *));
1645 memcpy (psymtab_include_list, orig,
1646 includes_used * sizeof (const char *));
1647 }
1648 continue;
1649 }
1650 case N_LSYM: /* Typedef or automatic variable. */
1651 case N_STSYM: /* Data seg var -- static. */
1652 case N_LCSYM: /* BSS " */
1653 case N_ROSYM: /* Read-only data seg var -- static. */
1654 case N_NBSTS: /* Gould nobase. */
1655 case N_NBLCS: /* symbols. */
1656 case N_FUN:
1657 case N_GSYM: /* Global (extern) variable; can be
1658 data or bss (sigh FIXME). */
1659
1660 /* Following may probably be ignored; I'll leave them here
1661 for now (until I do Pascal and Modula 2 extensions). */
1662
1663 case N_PC: /* I may or may not need this; I
1664 suspect not. */
1665 case N_M2C: /* I suspect that I can ignore this here. */
1666 case N_SCOPE: /* Same. */
1667 {
1668 const char *p;
1669
1670 namestring = set_namestring (objfile, &nlist);
1671
1672 /* See if this is an end of function stab. */
1673 if (pst && nlist.n_type == N_FUN && *namestring == '\000')
1674 {
1675 unrelocated_addr valu;
1676
1677 /* It's value is the size (in bytes) of the function for
1678 function relative stabs, or the address of the function's
1679 end for old style stabs. */
1680 valu = unrelocated_addr (nlist.n_value + last_function_start);
1681 if (pst->unrelocated_text_high () == unrelocated_addr (0)
1682 || valu > pst->unrelocated_text_high ())
1683 pst->set_text_high (valu);
1684 break;
1685 }
1686
1687 p = (char *) strchr (namestring, ':');
1688 if (!p)
1689 continue; /* Not a debugging symbol. */
1690
1691 sym_len = 0;
1692 sym_name = NULL; /* pacify "gcc -Werror" */
1693 if (dbx->ctx.psymtab_language == language_cplus)
1694 {
1695 std::string name (namestring, p - namestring);
1696 gdb::unique_xmalloc_ptr<char> new_name
1697 = cp_canonicalize_string (name.c_str ());
1698 if (new_name != nullptr)
1699 {
1700 sym_len = strlen (new_name.get ());
1701 sym_name = obstack_strdup (&objfile->objfile_obstack,
1702 new_name.get ());
1703 }
1704 }
1705 else if (dbx->ctx.psymtab_language == language_c)
1706 {
1707 std::string name (namestring, p - namestring);
1708 gdb::unique_xmalloc_ptr<char> new_name
1709 = c_canonicalize_name (name.c_str ());
1710 if (new_name != nullptr)
1711 {
1712 sym_len = strlen (new_name.get ());
1713 sym_name = obstack_strdup (&objfile->objfile_obstack,
1714 new_name.get ());
1715 }
1716 }
1717
1718 if (sym_len == 0)
1719 {
1720 sym_name = namestring;
1721 sym_len = p - namestring;
1722 }
1723
1724 /* Main processing section for debugging symbols which
1725 the initial read through the symbol tables needs to worry
1726 about. If we reach this point, the symbol which we are
1727 considering is definitely one we are interested in.
1728 p must also contain the (valid) index into the namestring
1729 which indicates the debugging type symbol. */
1730
1731 switch (p[1])
1732 {
1733 case 'S':
1734 if (pst != nullptr)
1735 pst->add_psymbol (std::string_view (sym_name, sym_len), true,
1736 VAR_DOMAIN, LOC_STATIC,
1737 data_sect_index,
1738 psymbol_placement::STATIC,
1739 unrelocated_addr (nlist.n_value),
1740 dbx->ctx.psymtab_language,
1741 partial_symtabs, objfile);
1742 else
1743 complaint (_("static `%*s' appears to be defined "
1744 "outside of all compilation units"),
1745 sym_len, sym_name);
1746 continue;
1747
1748 case 'G':
1749 /* The addresses in these entries are reported to be
1750 wrong. See the code that reads 'G's for symtabs. */
1751 if (pst != nullptr)
1752 pst->add_psymbol (std::string_view (sym_name, sym_len), true,
1753 VAR_DOMAIN, LOC_STATIC,
1754 data_sect_index,
1755 psymbol_placement::GLOBAL,
1756 unrelocated_addr (nlist.n_value),
1757 dbx->ctx.psymtab_language,
1758 partial_symtabs, objfile);
1759 else
1760 complaint (_("global `%*s' appears to be defined "
1761 "outside of all compilation units"),
1762 sym_len, sym_name);
1763 continue;
1764
1765 case 'T':
1766 /* When a 'T' entry is defining an anonymous enum, it
1767 may have a name which is the empty string, or a
1768 single space. Since they're not really defining a
1769 symbol, those shouldn't go in the partial symbol
1770 table. We do pick up the elements of such enums at
1771 'check_enum:', below. */
1772 if (p >= namestring + 2
1773 || (p == namestring + 1
1774 && namestring[0] != ' '))
1775 {
1776 if (pst != nullptr)
1777 pst->add_psymbol (std::string_view (sym_name, sym_len),
1778 true, STRUCT_DOMAIN, LOC_TYPEDEF, -1,
1779 psymbol_placement::STATIC,
1780 unrelocated_addr (0),
1781 dbx->ctx.psymtab_language,
1782 partial_symtabs, objfile);
1783 else
1784 complaint (_("enum, struct, or union `%*s' appears "
1785 "to be defined outside of all "
1786 "compilation units"),
1787 sym_len, sym_name);
1788 if (p[2] == 't')
1789 {
1790 /* Also a typedef with the same name. */
1791 if (pst != nullptr)
1792 pst->add_psymbol (std::string_view (sym_name, sym_len),
1793 true, VAR_DOMAIN, LOC_TYPEDEF, -1,
1794 psymbol_placement::STATIC,
1795 unrelocated_addr (0),
1796 dbx->ctx.psymtab_language,
1797 partial_symtabs, objfile);
1798 else
1799 complaint (_("typedef `%*s' appears to be defined "
1800 "outside of all compilation units"),
1801 sym_len, sym_name);
1802 p += 1;
1803 }
1804 }
1805 goto check_enum;
1806
1807 case 't':
1808 if (p != namestring) /* a name is there, not just :T... */
1809 {
1810 if (pst != nullptr)
1811 pst->add_psymbol (std::string_view (sym_name, sym_len),
1812 true, VAR_DOMAIN, LOC_TYPEDEF, -1,
1813 psymbol_placement::STATIC,
1814 unrelocated_addr (0),
1815 dbx->ctx.psymtab_language,
1816 partial_symtabs, objfile);
1817 else
1818 complaint (_("typename `%*s' appears to be defined "
1819 "outside of all compilation units"),
1820 sym_len, sym_name);
1821 }
1822 check_enum:
1823 /* If this is an enumerated type, we need to
1824 add all the enum constants to the partial symbol
1825 table. This does not cover enums without names, e.g.
1826 "enum {a, b} c;" in C, but fortunately those are
1827 rare. There is no way for GDB to find those from the
1828 enum type without spending too much time on it. Thus
1829 to solve this problem, the compiler needs to put out the
1830 enum in a nameless type. GCC2 does this. */
1831
1832 /* We are looking for something of the form
1833 <name> ":" ("t" | "T") [<number> "="] "e"
1834 {<constant> ":" <value> ","} ";". */
1835
1836 /* Skip over the colon and the 't' or 'T'. */
1837 p += 2;
1838 /* This type may be given a number. Also, numbers can come
1839 in pairs like (0,26). Skip over it. */
1840 while ((*p >= '0' && *p <= '9')
1841 || *p == '(' || *p == ',' || *p == ')'
1842 || *p == '=')
1843 p++;
1844
1845 if (*p++ == 'e')
1846 {
1847 /* The aix4 compiler emits extra crud before the members. */
1848 if (*p == '-')
1849 {
1850 /* Skip over the type (?). */
1851 while (*p != ':')
1852 p++;
1853
1854 /* Skip over the colon. */
1855 p++;
1856 }
1857
1858 /* We have found an enumerated type. */
1859 /* According to comments in read_enum_type
1860 a comma could end it instead of a semicolon.
1861 I don't know where that happens.
1862 Accept either. */
1863 while (*p && *p != ';' && *p != ',')
1864 {
1865 const char *q;
1866
1867 /* Check for and handle cretinous dbx symbol name
1868 continuation! */
1869 if (*p == '\\' || (*p == '?' && p[1] == '\0'))
1870 p = next_symbol_text (objfile);
1871
1872 /* Point to the character after the name
1873 of the enum constant. */
1874 for (q = p; *q && *q != ':'; q++)
1875 ;
1876 /* Note that the value doesn't matter for
1877 enum constants in psymtabs, just in symtabs. */
1878 if (pst != nullptr)
1879 pst->add_psymbol (std::string_view (p, q - p), true,
1880 VAR_DOMAIN, LOC_CONST, -1,
1881 psymbol_placement::STATIC,
1882 unrelocated_addr (0),
1883 dbx->ctx.psymtab_language,
1884 partial_symtabs, objfile);
1885 else
1886 complaint (_("enum constant `%*s' appears to be defined "
1887 "outside of all compilation units"),
1888 ((int) (q - p)), p);
1889 /* Point past the name. */
1890 p = q;
1891 /* Skip over the value. */
1892 while (*p && *p != ',')
1893 p++;
1894 /* Advance past the comma. */
1895 if (*p)
1896 p++;
1897 }
1898 }
1899 continue;
1900
1901 case 'c':
1902 /* Constant, e.g. from "const" in Pascal. */
1903 if (pst != nullptr)
1904 pst->add_psymbol (std::string_view (sym_name, sym_len), true,
1905 VAR_DOMAIN, LOC_CONST, -1,
1906 psymbol_placement::STATIC,
1907 unrelocated_addr (0),
1908 dbx->ctx.psymtab_language,
1909 partial_symtabs, objfile);
1910 else
1911 complaint (_("constant `%*s' appears to be defined "
1912 "outside of all compilation units"),
1913 sym_len, sym_name);
1914
1915 continue;
1916
1917 case 'f':
1918 if (! pst)
1919 {
1920 std::string name (namestring, (p - namestring));
1921 function_outside_compilation_unit_complaint (name.c_str ());
1922 }
1923 /* Kludges for ELF/STABS with Sun ACC. */
1924 dbx->ctx.last_function_name = namestring;
1925 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
1926 value for the bottom of the text seg in those cases. */
1927 if (nlist.n_value == 0
1928 && gdbarch_sofun_address_maybe_missing (gdbarch))
1929 {
1930 bound_minimal_symbol minsym
1931 = find_stab_function (namestring,
1932 pst ? pst->filename : NULL, objfile);
1933 if (minsym.minsym != NULL)
1934 nlist.n_value
1935 = CORE_ADDR (minsym.minsym->unrelocated_address ());
1936 }
1937 if (pst && textlow_not_set
1938 && gdbarch_sofun_address_maybe_missing (gdbarch))
1939 {
1940 pst->set_text_low (unrelocated_addr (nlist.n_value));
1941 textlow_not_set = 0;
1942 }
1943 /* End kludge. */
1944
1945 /* Keep track of the start of the last function so we
1946 can handle end of function symbols. */
1947 last_function_start = nlist.n_value;
1948
1949 /* In reordered executables this function may lie outside
1950 the bounds created by N_SO symbols. If that's the case
1951 use the address of this function as the low bound for
1952 the partial symbol table. */
1953 if (pst
1954 && (textlow_not_set
1955 || (unrelocated_addr (nlist.n_value)
1956 < pst->unrelocated_text_low ()
1957 && (nlist.n_value != 0))))
1958 {
1959 pst->set_text_low (unrelocated_addr (nlist.n_value));
1960 textlow_not_set = 0;
1961 }
1962 if (pst != nullptr)
1963 pst->add_psymbol (std::string_view (sym_name, sym_len), true,
1964 VAR_DOMAIN, LOC_BLOCK,
1965 SECT_OFF_TEXT (objfile),
1966 psymbol_placement::STATIC,
1967 unrelocated_addr (nlist.n_value),
1968 dbx->ctx.psymtab_language,
1969 partial_symtabs, objfile);
1970 continue;
1971
1972 /* Global functions were ignored here, but now they
1973 are put into the global psymtab like one would expect.
1974 They're also in the minimal symbol table. */
1975 case 'F':
1976 if (! pst)
1977 {
1978 std::string name (namestring, (p - namestring));
1979 function_outside_compilation_unit_complaint (name.c_str ());
1980 }
1981 /* Kludges for ELF/STABS with Sun ACC. */
1982 dbx->ctx.last_function_name = namestring;
1983 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
1984 value for the bottom of the text seg in those cases. */
1985 if (nlist.n_value == 0
1986 && gdbarch_sofun_address_maybe_missing (gdbarch))
1987 {
1988 bound_minimal_symbol minsym
1989 = find_stab_function (namestring,
1990 pst ? pst->filename : NULL, objfile);
1991 if (minsym.minsym != NULL)
1992 nlist.n_value
1993 = CORE_ADDR (minsym.minsym->unrelocated_address ());
1994 }
1995 if (pst && textlow_not_set
1996 && gdbarch_sofun_address_maybe_missing (gdbarch))
1997 {
1998 pst->set_text_low (unrelocated_addr (nlist.n_value));
1999 textlow_not_set = 0;
2000 }
2001 /* End kludge. */
2002
2003 /* Keep track of the start of the last function so we
2004 can handle end of function symbols. */
2005 last_function_start = nlist.n_value;
2006
2007 /* In reordered executables this function may lie outside
2008 the bounds created by N_SO symbols. If that's the case
2009 use the address of this function as the low bound for
2010 the partial symbol table. */
2011 if (pst
2012 && (textlow_not_set
2013 || (unrelocated_addr (nlist.n_value)
2014 < pst->unrelocated_text_low ()
2015 && (nlist.n_value != 0))))
2016 {
2017 pst->set_text_low (unrelocated_addr (nlist.n_value));
2018 textlow_not_set = 0;
2019 }
2020 if (pst != nullptr)
2021 pst->add_psymbol (std::string_view (sym_name, sym_len), true,
2022 VAR_DOMAIN, LOC_BLOCK,
2023 SECT_OFF_TEXT (objfile),
2024 psymbol_placement::GLOBAL,
2025 unrelocated_addr (nlist.n_value),
2026 dbx->ctx.psymtab_language,
2027 partial_symtabs, objfile);
2028 continue;
2029
2030 /* Two things show up here (hopefully); static symbols of
2031 local scope (static used inside braces) or extensions
2032 of structure symbols. We can ignore both. */
2033 case 'V':
2034 case '(':
2035 case '0':
2036 case '1':
2037 case '2':
2038 case '3':
2039 case '4':
2040 case '5':
2041 case '6':
2042 case '7':
2043 case '8':
2044 case '9':
2045 case '-':
2046 case '#': /* For symbol identification (used in live ranges). */
2047 continue;
2048
2049 case ':':
2050 /* It is a C++ nested symbol. We don't need to record it
2051 (I don't think); if we try to look up foo::bar::baz,
2052 then symbols for the symtab containing foo should get
2053 read in, I think. */
2054 /* Someone says sun cc puts out symbols like
2055 /foo/baz/maclib::/usr/local/bin/maclib,
2056 which would get here with a symbol type of ':'. */
2057 continue;
2058
2059 default:
2060 /* Unexpected symbol descriptor. The second and subsequent stabs
2061 of a continued stab can show up here. The question is
2062 whether they ever can mimic a normal stab--it would be
2063 nice if not, since we certainly don't want to spend the
2064 time searching to the end of every string looking for
2065 a backslash. */
2066
2067 complaint (_("unknown symbol descriptor `%c'"),
2068 p[1]);
2069
2070 /* Ignore it; perhaps it is an extension that we don't
2071 know about. */
2072 continue;
2073 }
2074 }
2075
2076 case N_EXCL:
2077
2078 namestring = set_namestring (objfile, &nlist);
2079
2080 /* Find the corresponding bincl and mark that psymtab on the
2081 psymtab dependency list. */
2082 {
2083 legacy_psymtab *needed_pst =
2084 find_corresponding_bincl_psymtab (namestring, nlist.n_value, objfile);
2085
2086 /* If this include file was defined earlier in this file,
2087 leave it alone. */
2088 if (needed_pst == pst)
2089 continue;
2090
2091 if (needed_pst)
2092 {
2093 int i;
2094 int found = 0;
2095
2096 for (i = 0; i < dependencies_used; i++)
2097 if (dependency_list[i] == needed_pst)
2098 {
2099 found = 1;
2100 break;
2101 }
2102
2103 /* If it's already in the list, skip the rest. */
2104 if (found)
2105 continue;
2106
2107 dependency_list[dependencies_used++] = needed_pst;
2108 if (dependencies_used >= dependencies_allocated)
2109 {
2110 legacy_psymtab **orig = dependency_list;
2111
2112 dependency_list =
2113 (legacy_psymtab **)
2114 alloca ((dependencies_allocated *= 2)
2115 * sizeof (legacy_psymtab *));
2116 memcpy (dependency_list, orig,
2117 (dependencies_used
2118 * sizeof (legacy_psymtab *)));
2119 #ifdef DEBUG_INFO
2120 gdb_printf (gdb_stderr,
2121 "Had to reallocate "
2122 "dependency list.\n");
2123 gdb_printf (gdb_stderr,
2124 "New dependencies allocated: %d\n",
2125 dependencies_allocated);
2126 #endif
2127 }
2128 }
2129 }
2130 continue;
2131
2132 case N_ENDM:
2133 /* Solaris 2 end of module, finish current partial symbol
2134 table. stabs_end_psymtab will set the high text address of
2135 PST to the proper value, which is necessary if a module
2136 compiled without debugging info follows this module. */
2137 if (pst && gdbarch_sofun_address_maybe_missing (gdbarch))
2138 {
2139 stabs_end_psymtab (objfile, partial_symtabs, pst,
2140 psymtab_include_list, includes_used,
2141 symnum * dbx->ctx.symbol_size,
2142 (unrelocated_addr) 0, dependency_list,
2143 dependencies_used, textlow_not_set);
2144 pst = (legacy_psymtab *) 0;
2145 includes_used = 0;
2146 dependencies_used = 0;
2147 dbx->ctx.has_line_numbers = 0;
2148 }
2149 continue;
2150
2151 case N_RBRAC:
2152 #ifdef HANDLE_RBRAC
2153 HANDLE_RBRAC (nlist.n_value);
2154 continue;
2155 #endif
2156 case N_EINCL:
2157 case N_DSLINE:
2158 case N_BSLINE:
2159 case N_SSYM: /* Claim: Structure or union element.
2160 Hopefully, I can ignore this. */
2161 case N_ENTRY: /* Alternate entry point; can ignore. */
2162 case N_MAIN: /* Can definitely ignore this. */
2163 case N_CATCH: /* These are GNU C++ extensions */
2164 case N_EHDECL: /* that can safely be ignored here. */
2165 case N_LENG:
2166 case N_BCOMM:
2167 case N_ECOMM:
2168 case N_ECOML:
2169 case N_FNAME:
2170 case N_SLINE:
2171 case N_RSYM:
2172 case N_PSYM:
2173 case N_BNSYM:
2174 case N_ENSYM:
2175 case N_LBRAC:
2176 case N_NSYMS: /* Ultrix 4.0: symbol count */
2177 case N_DEFD: /* GNU Modula-2 */
2178 case N_ALIAS: /* SunPro F77: alias name, ignore for now. */
2179
2180 case N_OBJ: /* Useless types from Solaris. */
2181 case N_OPT:
2182 case N_PATCH:
2183 /* These symbols aren't interesting; don't worry about them. */
2184 continue;
2185
2186 default:
2187 /* If we haven't found it yet, ignore it. It's probably some
2188 new type we don't know about yet. */
2189 unknown_symtype_complaint (hex_string (nlist.n_type));
2190 continue;
2191 }
2192 }
2193
2194 /* If there's stuff to be cleaned up, clean it up. */
2195 if (pst)
2196 {
2197 /* Don't set high text address of PST lower than it already
2198 is. */
2199 unrelocated_addr text_end
2200 = (unrelocated_addr
2201 ((dbx->ctx.lowest_text_address == (unrelocated_addr) -1
2202 ? text_addr
2203 : CORE_ADDR (dbx->ctx.lowest_text_address))
2204 + text_size));
2205
2206 stabs_end_psymtab (objfile, partial_symtabs,
2207 pst, psymtab_include_list, includes_used,
2208 symnum * dbx->ctx.symbol_size,
2209 (text_end > pst->unrelocated_text_high ()
2210 ? text_end : pst->unrelocated_text_high ()),
2211 dependency_list, dependencies_used, textlow_not_set);
2212 }
2213 }
2214
2215 /* Scan and build partial symbols for a symbol file.
2216 We have been initialized by a call to dbx_symfile_init, which
2217 put all the relevant info into a "struct dbx_symfile_info",
2218 hung off the objfile structure. */
2219
2220 void
2221 read_stabs_symtab (struct objfile *objfile, symfile_add_flags symfile_flags)
2222 {
2223 bfd *sym_bfd;
2224 int val;
2225 struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
2226
2227 sym_bfd = objfile->obfd.get ();
2228
2229 stabs_deprecated_warning ();
2230
2231 /* .o and .nlm files are relocatables with text, data and bss segs based at
2232 0. This flag disables special (Solaris stabs-in-elf only) fixups for
2233 symbols with a value of 0. */
2234
2235 key->ctx.symfile_relocatable = bfd_get_file_flags (sym_bfd) & HAS_RELOC;
2236
2237 val = bfd_seek (sym_bfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET);
2238 if (val < 0)
2239 perror_with_name (objfile_name (objfile));
2240
2241 key->ctx.symbol_size = DBX_SYMBOL_SIZE (objfile);
2242 key->ctx.symbol_table_offset = DBX_SYMTAB_OFFSET (objfile);
2243
2244 scoped_free_pendings free_pending;
2245
2246 minimal_symbol_reader reader (objfile);
2247
2248 /* Read stabs data from executable file and define symbols. */
2249
2250 psymbol_functions *psf = new psymbol_functions ();
2251 psymtab_storage *partial_symtabs = psf->get_partial_symtabs ().get ();
2252 objfile->qf.emplace_front (psf);
2253 read_stabs_symtab_1 (reader, partial_symtabs, objfile);
2254
2255 /* Install any minimal symbols that have been collected as the current
2256 minimal symbols for this objfile. */
2257
2258 reader.install ();
2259 }
2260
2261 /* Record the namespace that the function defined by SYMBOL was
2262 defined in, if necessary. BLOCK is the associated block; use
2263 OBSTACK for allocation. */
2264
2265 static void
2266 cp_set_block_scope (const struct symbol *symbol,
2267 struct block *block,
2268 struct obstack *obstack)
2269 {
2270 if (symbol->demangled_name () != NULL)
2271 {
2272 /* Try to figure out the appropriate namespace from the
2273 demangled name. */
2274
2275 /* FIXME: carlton/2003-04-15: If the function in question is
2276 a method of a class, the name will actually include the
2277 name of the class as well. This should be harmless, but
2278 is a little unfortunate. */
2279
2280 const char *name = symbol->demangled_name ();
2281 unsigned int prefix_len = cp_entire_prefix_len (name);
2282
2283 block->set_scope (obstack_strndup (obstack, name, prefix_len),
2284 obstack);
2285 }
2286 }
2287
2288 bound_minimal_symbol
2289 find_stab_function (const char *namestring, const char *filename,
2290 struct objfile *objfile)
2291 {
2292 int n;
2293
2294 const char *colon = strchr (namestring, ':');
2295 if (colon == NULL)
2296 n = 0;
2297 else
2298 n = colon - namestring;
2299
2300 char *p = (char *) alloca (n + 2);
2301 strncpy (p, namestring, n);
2302 p[n] = 0;
2303
2304 bound_minimal_symbol msym
2305 = lookup_minimal_symbol (current_program_space, p, objfile, filename);
2306 if (msym.minsym == NULL)
2307 {
2308 /* Sun Fortran appends an underscore to the minimal symbol name,
2309 try again with an appended underscore if the minimal symbol
2310 was not found. */
2311 p[n] = '_';
2312 p[n + 1] = 0;
2313 msym
2314 = lookup_minimal_symbol (current_program_space, p, objfile, filename);
2315 }
2316
2317 if (msym.minsym == NULL && filename != NULL)
2318 {
2319 /* Try again without the filename. */
2320 p[n] = 0;
2321 msym = lookup_minimal_symbol (current_program_space, p, objfile);
2322 }
2323 if (msym.minsym == NULL && filename != NULL)
2324 {
2325 /* And try again for Sun Fortran, but without the filename. */
2326 p[n] = '_';
2327 p[n + 1] = 0;
2328 msym = lookup_minimal_symbol (current_program_space, p, objfile);
2329 }
2330
2331 return msym;
2332 }
2333
2334 /* Add header file number I for this object file
2335 at the next successive FILENUM. */
2336
2337 static void
2338 add_this_object_header_file (int i)
2339 {
2340 if (n_this_object_header_files == n_allocated_this_object_header_files)
2341 {
2342 n_allocated_this_object_header_files *= 2;
2343 this_object_header_files
2344 = (int *) xrealloc ((char *) this_object_header_files,
2345 n_allocated_this_object_header_files * sizeof (int));
2346 }
2347
2348 this_object_header_files[n_this_object_header_files++] = i;
2349 }
2350
2351 /* Add to this file an "old" header file, one already seen in
2352 a previous object file. NAME is the header file's name.
2353 INSTANCE is its instance code, to select among multiple
2354 symbol tables for the same header file. */
2355
2356 static void
2357 add_old_header_file (const char *name, int instance, struct objfile *objfile)
2358 {
2359 struct header_file *p = HEADER_FILES (objfile);
2360 int i;
2361
2362 for (i = 0; i < N_HEADER_FILES (objfile); i++)
2363 if (filename_cmp (p[i].name, name) == 0 && instance == p[i].instance)
2364 {
2365 add_this_object_header_file (i);
2366 return;
2367 }
2368 repeated_header_complaint (name, symnum);
2369 }
2370
2371 /* Add to this file a "new" header file: definitions for its types follow.
2372 NAME is the header file's name.
2373 Most often this happens only once for each distinct header file,
2374 but not necessarily. If it happens more than once, INSTANCE has
2375 a different value each time, and references to the header file
2376 use INSTANCE values to select among them.
2377
2378 dbx output contains "begin" and "end" markers for each new header file,
2379 but at this level we just need to know which files there have been;
2380 so we record the file when its "begin" is seen and ignore the "end". */
2381
2382 static void
2383 add_new_header_file (const char *name, int instance, struct objfile *objfile)
2384 {
2385 int i;
2386 struct header_file *hfile;
2387
2388 /* Make sure there is room for one more header file. */
2389
2390 i = N_ALLOCATED_HEADER_FILES (objfile);
2391
2392 if (N_HEADER_FILES (objfile) == i)
2393 {
2394 if (i == 0)
2395 {
2396 N_ALLOCATED_HEADER_FILES (objfile) = 10;
2397 HEADER_FILES (objfile) = (struct header_file *)
2398 xmalloc (10 * sizeof (struct header_file));
2399 }
2400 else
2401 {
2402 i *= 2;
2403 N_ALLOCATED_HEADER_FILES (objfile) = i;
2404 HEADER_FILES (objfile) = (struct header_file *)
2405 xrealloc ((char *) HEADER_FILES (objfile),
2406 (i * sizeof (struct header_file)));
2407 }
2408 }
2409
2410 /* Create an entry for this header file. */
2411
2412 i = N_HEADER_FILES (objfile)++;
2413 hfile = HEADER_FILES (objfile) + i;
2414 hfile->name = xstrdup (name);
2415 hfile->instance = instance;
2416 hfile->length = 10;
2417 hfile->vector = XCNEWVEC (struct type *, 10);
2418
2419 add_this_object_header_file (i);
2420 }
2421
2422 /* See stabsread.h. */
2423
2424 void
2425 process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name,
2426 const section_offsets &section_offsets,
2427 struct objfile *objfile, enum language language)
2428 {
2429 struct gdbarch *gdbarch = objfile->arch ();
2430 struct context_stack *newobj;
2431 struct context_stack cstk;
2432 /* This remembers the address of the start of a function. It is
2433 used because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries
2434 are relative to the current function's start address. On systems
2435 other than Solaris 2, this just holds the SECT_OFF_TEXT value,
2436 and is used to relocate these symbol types rather than
2437 SECTION_OFFSETS. */
2438 static CORE_ADDR function_start_offset;
2439
2440 /* This holds the address of the start of a function, without the
2441 system peculiarities of function_start_offset. */
2442 static CORE_ADDR last_function_start;
2443
2444 /* If this is nonzero, we've seen an N_SLINE since the start of the
2445 current function. We use this to tell us to move the first sline
2446 to the beginning of the function regardless of what its given
2447 value is. */
2448 static int sline_found_in_function = 1;
2449
2450 /* If this is nonzero, we've seen a non-gcc N_OPT symbol for this
2451 source file. Used to detect the SunPRO solaris compiler. */
2452 static int n_opt_found;
2453
2454 /* The section index for this symbol. */
2455 int section_index = -1;
2456
2457 struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
2458
2459 /* Something is wrong if we see real data before seeing a source
2460 file name. */
2461
2462 if (get_last_source_file () == NULL && type != (unsigned char) N_SO)
2463 {
2464 /* Ignore any symbols which appear before an N_SO symbol.
2465 Currently no one puts symbols there, but we should deal
2466 gracefully with the case. A complain()t might be in order,
2467 but this should not be an error (). */
2468 return;
2469 }
2470
2471 switch (type)
2472 {
2473 case N_FUN:
2474 case N_FNAME:
2475
2476 if (*name == '\000')
2477 {
2478 /* This N_FUN marks the end of a function. This closes off
2479 the current block. */
2480 struct block *block;
2481
2482 if (outermost_context_p ())
2483 {
2484 lbrac_mismatch_complaint (symnum);
2485 break;
2486 }
2487
2488 /* The following check is added before recording line 0 at
2489 end of function so as to handle hand-generated stabs
2490 which may have an N_FUN stabs at the end of the function,
2491 but no N_SLINE stabs. */
2492 if (sline_found_in_function)
2493 {
2494 CORE_ADDR addr = last_function_start + valu;
2495
2496 record_line
2497 (get_current_subfile (), 0,
2498 unrelocated_addr (gdbarch_addr_bits_remove (gdbarch, addr)
2499 - objfile->text_section_offset ()));
2500 }
2501
2502 within_function = 0;
2503 cstk = pop_context ();
2504
2505 /* Make a block for the local symbols within. */
2506 block = finish_block (cstk.name,
2507 cstk.old_blocks, NULL,
2508 cstk.start_addr, cstk.start_addr + valu);
2509
2510 /* For C++, set the block's scope. */
2511 if (cstk.name->language () == language_cplus)
2512 cp_set_block_scope (cstk.name, block, &objfile->objfile_obstack);
2513
2514 /* May be switching to an assembler file which may not be using
2515 block relative stabs, so reset the offset. */
2516 function_start_offset = 0;
2517
2518 break;
2519 }
2520
2521 sline_found_in_function = 0;
2522
2523 /* Relocate for dynamic loading. */
2524 section_index = SECT_OFF_TEXT (objfile);
2525 valu += section_offsets[SECT_OFF_TEXT (objfile)];
2526 valu = gdbarch_addr_bits_remove (gdbarch, valu);
2527 last_function_start = valu;
2528
2529 goto define_a_symbol;
2530
2531 case N_LBRAC:
2532 /* This "symbol" just indicates the start of an inner lexical
2533 context within a function. */
2534
2535 /* Ignore extra outermost context from SunPRO cc and acc. */
2536 if (n_opt_found && desc == 1)
2537 break;
2538
2539 valu += function_start_offset;
2540
2541 push_context (desc, valu);
2542 break;
2543
2544 case N_RBRAC:
2545 /* This "symbol" just indicates the end of an inner lexical
2546 context that was started with N_LBRAC. */
2547
2548 /* Ignore extra outermost context from SunPRO cc and acc. */
2549 if (n_opt_found && desc == 1)
2550 break;
2551
2552 valu += function_start_offset;
2553
2554 if (outermost_context_p ())
2555 {
2556 lbrac_mismatch_complaint (symnum);
2557 break;
2558 }
2559
2560 cstk = pop_context ();
2561 if (desc != cstk.depth)
2562 lbrac_mismatch_complaint (symnum);
2563
2564 if (*get_local_symbols () != NULL)
2565 {
2566 /* GCC development snapshots from March to December of
2567 2000 would output N_LSYM entries after N_LBRAC
2568 entries. As a consequence, these symbols are simply
2569 discarded. Complain if this is the case. */
2570 complaint (_("misplaced N_LBRAC entry; discarding local "
2571 "symbols which have no enclosing block"));
2572 }
2573 *get_local_symbols () = cstk.locals;
2574
2575 if (get_context_stack_depth () > 1)
2576 {
2577 /* This is not the outermost LBRAC...RBRAC pair in the
2578 function, its local symbols preceded it, and are the ones
2579 just recovered from the context stack. Define the block
2580 for them (but don't bother if the block contains no
2581 symbols. Should we complain on blocks without symbols?
2582 I can't think of any useful purpose for them). */
2583 if (*get_local_symbols () != NULL)
2584 {
2585 /* Muzzle a compiler bug that makes end < start.
2586
2587 ??? Which compilers? Is this ever harmful?. */
2588 if (cstk.start_addr > valu)
2589 {
2590 complaint (_("block start larger than block end"));
2591 cstk.start_addr = valu;
2592 }
2593 /* Make a block for the local symbols within. */
2594 finish_block (0, cstk.old_blocks, NULL,
2595 cstk.start_addr, valu);
2596 }
2597 }
2598 else
2599 {
2600 /* This is the outermost LBRAC...RBRAC pair. There is no
2601 need to do anything; leave the symbols that preceded it
2602 to be attached to the function's own block. We need to
2603 indicate that we just moved outside of the function. */
2604 within_function = 0;
2605 }
2606
2607 break;
2608
2609 case N_FN:
2610 case N_FN_SEQ:
2611 /* This kind of symbol indicates the start of an object file.
2612 Relocate for dynamic loading. */
2613 section_index = SECT_OFF_TEXT (objfile);
2614 valu += section_offsets[SECT_OFF_TEXT (objfile)];
2615 break;
2616
2617 case N_SO:
2618 /* This type of symbol indicates the start of data for one
2619 source file. Finish the symbol table of the previous source
2620 file (if any) and start accumulating a new symbol table.
2621 Relocate for dynamic loading. */
2622 section_index = SECT_OFF_TEXT (objfile);
2623 valu += section_offsets[SECT_OFF_TEXT (objfile)];
2624
2625 n_opt_found = 0;
2626
2627 if (get_last_source_file ())
2628 {
2629 /* Check if previous symbol was also an N_SO (with some
2630 sanity checks). If so, that one was actually the
2631 directory name, and the current one is the real file
2632 name. Patch things up. */
2633 if (previous_stab_code == (unsigned char) N_SO)
2634 {
2635 patch_subfile_names (get_current_subfile (), name);
2636 break; /* Ignore repeated SOs. */
2637 }
2638 end_compunit_symtab (valu);
2639 end_stabs ();
2640 }
2641
2642 /* Null name means this just marks the end of text for this .o
2643 file. Don't start a new symtab in this case. */
2644 if (*name == '\000')
2645 break;
2646
2647 function_start_offset = 0;
2648
2649 start_stabs ();
2650 start_compunit_symtab (objfile, name, NULL, valu, language);
2651 record_debugformat ("stabs");
2652 break;
2653
2654 case N_SOL:
2655 /* This type of symbol indicates the start of data for a
2656 sub-source-file, one whose contents were copied or included
2657 in the compilation of the main source file (whose name was
2658 given in the N_SO symbol). Relocate for dynamic loading. */
2659 section_index = SECT_OFF_TEXT (objfile);
2660 valu += section_offsets[SECT_OFF_TEXT (objfile)];
2661 start_subfile (name);
2662 break;
2663
2664 case N_BINCL:
2665 push_subfile ();
2666 add_new_header_file (name, valu, objfile);
2667 start_subfile (name);
2668 break;
2669
2670 case N_EINCL:
2671 start_subfile (pop_subfile ());
2672 break;
2673
2674 case N_EXCL:
2675 add_old_header_file (name, valu, objfile);
2676 break;
2677
2678 case N_SLINE:
2679 /* This type of "symbol" really just records one line-number --
2680 core-address correspondence. Enter it in the line list for
2681 this symbol table. */
2682
2683 /* Relocate for dynamic loading and for ELF acc
2684 function-relative symbols. */
2685 valu += function_start_offset;
2686
2687 /* GCC 2.95.3 emits the first N_SLINE stab somewhere in the
2688 middle of the prologue instead of right at the start of the
2689 function. To deal with this we record the address for the
2690 first N_SLINE stab to be the start of the function instead of
2691 the listed location. We really shouldn't to this. When
2692 compiling with optimization, this first N_SLINE stab might be
2693 optimized away. Other (non-GCC) compilers don't emit this
2694 stab at all. There is no real harm in having an extra
2695 numbered line, although it can be a bit annoying for the
2696 user. However, it totally screws up our testsuite.
2697
2698 So for now, keep adjusting the address of the first N_SLINE
2699 stab, but only for code compiled with GCC. */
2700
2701 if (within_function && sline_found_in_function == 0)
2702 {
2703 CORE_ADDR addr = processing_gcc_compilation == 2 ?
2704 last_function_start : valu;
2705
2706 record_line
2707 (get_current_subfile (), desc,
2708 unrelocated_addr (gdbarch_addr_bits_remove (gdbarch, addr)
2709 - objfile->text_section_offset ()));
2710 sline_found_in_function = 1;
2711 }
2712 else
2713 record_line
2714 (get_current_subfile (), desc,
2715 unrelocated_addr (gdbarch_addr_bits_remove (gdbarch, valu)
2716 - objfile->text_section_offset ()));
2717 break;
2718
2719 case N_BCOMM:
2720 common_block_start (name, objfile);
2721 break;
2722
2723 case N_ECOMM:
2724 common_block_end (objfile);
2725 break;
2726
2727 /* The following symbol types need to have the appropriate
2728 offset added to their value; then we process symbol
2729 definitions in the name. */
2730
2731 case N_STSYM: /* Static symbol in data segment. */
2732 case N_LCSYM: /* Static symbol in BSS segment. */
2733 case N_ROSYM: /* Static symbol in read-only data segment. */
2734 /* HORRID HACK DEPT. However, it's Sun's furgin' fault.
2735 Solaris 2's stabs-in-elf makes *most* symbols relative but
2736 leaves a few absolute (at least for Solaris 2.1 and version
2737 2.0.1 of the SunPRO compiler). N_STSYM and friends sit on
2738 the fence. .stab "foo:S...",N_STSYM is absolute (ld
2739 relocates it) .stab "foo:V...",N_STSYM is relative (section
2740 base subtracted). This leaves us no choice but to search for
2741 the 'S' or 'V'... (or pass the whole section_offsets stuff
2742 down ONE MORE function call level, which we really don't want
2743 to do). */
2744 {
2745 const char *p;
2746
2747 /* Normal object file and NLMs have non-zero text seg offsets,
2748 but don't need their static syms offset in this fashion.
2749 XXX - This is really a crock that should be fixed in the
2750 solib handling code so that I don't have to work around it
2751 here. */
2752
2753 if (!key->ctx.symfile_relocatable)
2754 {
2755 p = strchr (name, ':');
2756 if (p != 0 && p[1] == 'S')
2757 {
2758 /* The linker relocated it. We don't want to add a
2759 Sun-stabs Tfoo.foo-like offset, but we *do*
2760 want to add whatever solib.c passed to
2761 symbol_file_add as addr (this is known to affect
2762 SunOS 4, and I suspect ELF too). Since there is no
2763 Ttext.text symbol, we can get addr from the text offset. */
2764 section_index = SECT_OFF_TEXT (objfile);
2765 valu += section_offsets[SECT_OFF_TEXT (objfile)];
2766 goto define_a_symbol;
2767 }
2768 }
2769 /* Since it's not the kludge case, re-dispatch to the right
2770 handler. */
2771 switch (type)
2772 {
2773 case N_STSYM:
2774 goto case_N_STSYM;
2775 case N_LCSYM:
2776 goto case_N_LCSYM;
2777 case N_ROSYM:
2778 goto case_N_ROSYM;
2779 default:
2780 internal_error (_("failed internal consistency check"));
2781 }
2782 }
2783
2784 case_N_STSYM: /* Static symbol in data segment. */
2785 case N_DSLINE: /* Source line number, data segment. */
2786 section_index = SECT_OFF_DATA (objfile);
2787 valu += section_offsets[SECT_OFF_DATA (objfile)];
2788 goto define_a_symbol;
2789
2790 case_N_LCSYM: /* Static symbol in BSS segment. */
2791 case N_BSLINE: /* Source line number, BSS segment. */
2792 /* N_BROWS: overlaps with N_BSLINE. */
2793 section_index = SECT_OFF_BSS (objfile);
2794 valu += section_offsets[SECT_OFF_BSS (objfile)];
2795 goto define_a_symbol;
2796
2797 case_N_ROSYM: /* Static symbol in read-only data segment. */
2798 section_index = SECT_OFF_RODATA (objfile);
2799 valu += section_offsets[SECT_OFF_RODATA (objfile)];
2800 goto define_a_symbol;
2801
2802 case N_ENTRY: /* Alternate entry point. */
2803 /* Relocate for dynamic loading. */
2804 section_index = SECT_OFF_TEXT (objfile);
2805 valu += section_offsets[SECT_OFF_TEXT (objfile)];
2806 goto define_a_symbol;
2807
2808 /* The following symbol types we don't know how to process.
2809 Handle them in a "default" way, but complain to people who
2810 care. */
2811 default:
2812 case N_CATCH: /* Exception handler catcher. */
2813 case N_EHDECL: /* Exception handler name. */
2814 case N_PC: /* Global symbol in Pascal. */
2815 case N_M2C: /* Modula-2 compilation unit. */
2816 /* N_MOD2: overlaps with N_EHDECL. */
2817 case N_SCOPE: /* Modula-2 scope information. */
2818 case N_ECOML: /* End common (local name). */
2819 case N_NBTEXT: /* Gould Non-Base-Register symbols??? */
2820 case N_NBDATA:
2821 case N_NBBSS:
2822 case N_NBSTS:
2823 case N_NBLCS:
2824 unknown_symtype_complaint (hex_string (type));
2825
2826 define_a_symbol:
2827 [[fallthrough]];
2828 /* These symbol types don't need the address field relocated,
2829 since it is either unused, or is absolute. */
2830 case N_GSYM: /* Global variable. */
2831 case N_NSYMS: /* Number of symbols (Ultrix). */
2832 case N_NOMAP: /* No map? (Ultrix). */
2833 case N_RSYM: /* Register variable. */
2834 case N_DEFD: /* Modula-2 GNU module dependency. */
2835 case N_SSYM: /* Struct or union element. */
2836 case N_LSYM: /* Local symbol in stack. */
2837 case N_PSYM: /* Parameter variable. */
2838 case N_LENG: /* Length of preceding symbol type. */
2839 if (name)
2840 {
2841 int deftype;
2842 const char *colon_pos = strchr (name, ':');
2843
2844 if (colon_pos == NULL)
2845 deftype = '\0';
2846 else
2847 deftype = colon_pos[1];
2848
2849 switch (deftype)
2850 {
2851 case 'f':
2852 case 'F':
2853 /* Deal with the SunPRO 3.0 compiler which omits the
2854 address from N_FUN symbols. */
2855 if (type == N_FUN
2856 && valu == section_offsets[SECT_OFF_TEXT (objfile)]
2857 && gdbarch_sofun_address_maybe_missing (gdbarch))
2858 {
2859 bound_minimal_symbol minsym
2860 = find_stab_function (name, get_last_source_file (),
2861 objfile);
2862 if (minsym.minsym != NULL)
2863 valu = minsym.value_address ();
2864 }
2865
2866 /* These addresses are absolute. */
2867 function_start_offset = valu;
2868
2869 within_function = 1;
2870
2871 if (get_context_stack_depth () > 1)
2872 {
2873 complaint (_("unmatched N_LBRAC before symtab pos %d"),
2874 symnum);
2875 break;
2876 }
2877
2878 if (!outermost_context_p ())
2879 {
2880 struct block *block;
2881
2882 cstk = pop_context ();
2883 /* Make a block for the local symbols within. */
2884 block = finish_block (cstk.name,
2885 cstk.old_blocks, NULL,
2886 cstk.start_addr, valu);
2887
2888 /* For C++, set the block's scope. */
2889 if (cstk.name->language () == language_cplus)
2890 cp_set_block_scope (cstk.name, block,
2891 &objfile->objfile_obstack);
2892 }
2893
2894 newobj = push_context (0, valu);
2895 newobj->name = define_symbol (valu, name, desc, type, objfile);
2896 if (newobj->name != nullptr)
2897 newobj->name->set_section_index (section_index);
2898 break;
2899
2900 default:
2901 {
2902 struct symbol *sym = define_symbol (valu, name, desc, type,
2903 objfile);
2904 if (sym != nullptr)
2905 sym->set_section_index (section_index);
2906 }
2907 break;
2908 }
2909 }
2910 break;
2911
2912 /* We use N_OPT to carry the gcc2_compiled flag. Sun uses it
2913 for a bunch of other flags, too. Someday we may parse their
2914 flags; for now we ignore theirs and hope they'll ignore ours. */
2915 case N_OPT: /* Solaris 2: Compiler options. */
2916 if (name)
2917 {
2918 if (strcmp (name, GCC2_COMPILED_FLAG_SYMBOL) == 0)
2919 {
2920 processing_gcc_compilation = 2;
2921 }
2922 else
2923 n_opt_found = 1;
2924 }
2925 break;
2926
2927 case N_MAIN: /* Name of main routine. */
2928 /* FIXME: If one has a symbol file with N_MAIN and then replaces
2929 it with a symbol file with "main" and without N_MAIN. I'm
2930 not sure exactly what rule to follow but probably something
2931 like: N_MAIN takes precedence over "main" no matter what
2932 objfile it is in; If there is more than one N_MAIN, choose
2933 the one in the symfile_objfile; If there is more than one
2934 N_MAIN within a given objfile, complain() and choose
2935 arbitrarily. (kingdon) */
2936 if (name != NULL)
2937 set_objfile_main_name (objfile, name, language_unknown);
2938 break;
2939
2940 /* The following symbol types can be ignored. */
2941 case N_OBJ: /* Solaris 2: Object file dir and name. */
2942 case N_PATCH: /* Solaris 2: Patch Run Time Checker. */
2943 /* N_UNDF: Solaris 2: File separator mark. */
2944 /* N_UNDF: -- we will never encounter it, since we only process
2945 one file's symbols at once. */
2946 case N_ENDM: /* Solaris 2: End of module. */
2947 case N_ALIAS: /* SunPro F77: alias name, ignore for now. */
2948 break;
2949 }
2950
2951 /* '#' is a GNU C extension to allow one symbol to refer to another
2952 related symbol.
2953
2954 Generally this is used so that an alias can refer to its main
2955 symbol. */
2956 gdb_assert (name);
2957 if (name[0] == '#')
2958 {
2959 /* Initialize symbol reference names and determine if this is a
2960 definition. If a symbol reference is being defined, go ahead
2961 and add it. Otherwise, just return. */
2962
2963 const char *s = name;
2964 int refnum;
2965
2966 /* If this stab defines a new reference ID that is not on the
2967 reference list, then put it on the reference list.
2968
2969 We go ahead and advance NAME past the reference, even though
2970 it is not strictly necessary at this time. */
2971 refnum = symbol_reference_defined (&s);
2972 if (refnum >= 0)
2973 if (!ref_search (refnum))
2974 ref_add (refnum, 0, name, valu);
2975 name = s;
2976 }
2977
2978 previous_stab_code = type;
2979 }
2980
2981 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
2982 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
2983 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
2984 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
2985
2986 /* Structure for storing pointers to reference definitions for fast lookup
2987 during "process_later". */
2988
2989 struct ref_map
2990 {
2991 const char *stabs;
2992 CORE_ADDR value;
2993 struct symbol *sym;
2994 };
2995
2996 #define MAX_CHUNK_REFS 100
2997 #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map))
2998 #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE)
2999
3000 static struct ref_map *ref_map;
3001
3002 /* Ptr to free cell in chunk's linked list. */
3003 static int ref_count = 0;
3004
3005 /* Number of chunks malloced. */
3006 static int ref_chunk = 0;
3007
3008 /* This file maintains a cache of stabs aliases found in the symbol
3009 table. If the symbol table changes, this cache must be cleared
3010 or we are left holding onto data in invalid obstacks. */
3011 void
3012 stabsread_clear_cache (void)
3013 {
3014 ref_count = 0;
3015 ref_chunk = 0;
3016 }
3017
3018 /* Create array of pointers mapping refids to symbols and stab strings.
3019 Add pointers to reference definition symbols and/or their values as we
3020 find them, using their reference numbers as our index.
3021 These will be used later when we resolve references. */
3022 void
3023 ref_add (int refnum, struct symbol *sym, const char *stabs, CORE_ADDR value)
3024 {
3025 if (ref_count == 0)
3026 ref_chunk = 0;
3027 if (refnum >= ref_count)
3028 ref_count = refnum + 1;
3029 if (ref_count > ref_chunk * MAX_CHUNK_REFS)
3030 {
3031 int new_slots = ref_count - ref_chunk * MAX_CHUNK_REFS;
3032 int new_chunks = new_slots / MAX_CHUNK_REFS + 1;
3033
3034 ref_map = (struct ref_map *)
3035 xrealloc (ref_map, REF_MAP_SIZE (ref_chunk + new_chunks));
3036 memset (ref_map + ref_chunk * MAX_CHUNK_REFS, 0,
3037 new_chunks * REF_CHUNK_SIZE);
3038 ref_chunk += new_chunks;
3039 }
3040 ref_map[refnum].stabs = stabs;
3041 ref_map[refnum].sym = sym;
3042 ref_map[refnum].value = value;
3043 }
3044
3045 /* Return defined sym for the reference REFNUM. */
3046 struct symbol *
3047 ref_search (int refnum)
3048 {
3049 if (refnum < 0 || refnum > ref_count)
3050 return 0;
3051 return ref_map[refnum].sym;
3052 }
3053
3054 /* Parse a reference id in STRING and return the resulting
3055 reference number. Move STRING beyond the reference id. */
3056
3057 static int
3058 process_reference (const char **string)
3059 {
3060 const char *p;
3061 int refnum = 0;
3062
3063 if (**string != '#')
3064 return 0;
3065
3066 /* Advance beyond the initial '#'. */
3067 p = *string + 1;
3068
3069 /* Read number as reference id. */
3070 while (*p && isdigit (*p))
3071 {
3072 refnum = refnum * 10 + *p - '0';
3073 p++;
3074 }
3075 *string = p;
3076 return refnum;
3077 }
3078
3079 /* If STRING defines a reference, store away a pointer to the reference
3080 definition for later use. Return the reference number. */
3081
3082 int
3083 symbol_reference_defined (const char **string)
3084 {
3085 const char *p = *string;
3086 int refnum = 0;
3087
3088 refnum = process_reference (&p);
3089
3090 /* Defining symbols end in '='. */
3091 if (*p == '=')
3092 {
3093 /* Symbol is being defined here. */
3094 *string = p + 1;
3095 return refnum;
3096 }
3097 else
3098 {
3099 /* Must be a reference. Either the symbol has already been defined,
3100 or this is a forward reference to it. */
3101 *string = p;
3102 return -1;
3103 }
3104 }
3105
3106 static int
3107 stab_reg_to_regnum (struct symbol *sym, struct gdbarch *gdbarch)
3108 {
3109 int regno = gdbarch_stab_reg_to_regnum (gdbarch, sym->value_longest ());
3110
3111 if (regno < 0 || regno >= gdbarch_num_cooked_regs (gdbarch))
3112 {
3113 reg_value_complaint (regno, gdbarch_num_cooked_regs (gdbarch),
3114 sym->print_name ());
3115
3116 regno = gdbarch_sp_regnum (gdbarch); /* Known safe, though useless. */
3117 }
3118
3119 return regno;
3120 }
3121
3122 static const struct symbol_register_ops stab_register_funcs = {
3123 stab_reg_to_regnum
3124 };
3125
3126 /* The "aclass" indices for computed symbols. */
3127
3128 static int stab_register_index;
3129 static int stab_regparm_index;
3130
3131 struct symbol *
3132 define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
3133 struct objfile *objfile)
3134 {
3135 struct gdbarch *gdbarch = objfile->arch ();
3136 struct symbol *sym;
3137 const char *p = find_name_end (string);
3138 int deftype;
3139 int synonym = 0;
3140 int i;
3141
3142 /* We would like to eliminate nameless symbols, but keep their types.
3143 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
3144 to type 2, but, should not create a symbol to address that type. Since
3145 the symbol will be nameless, there is no way any user can refer to it. */
3146
3147 int nameless;
3148
3149 /* Ignore syms with empty names. */
3150 if (string[0] == 0)
3151 return 0;
3152
3153 /* Ignore old-style symbols from cc -go. */
3154 if (p == 0)
3155 return 0;
3156
3157 while (p[1] == ':')
3158 {
3159 p += 2;
3160 p = strchr (p, ':');
3161 if (p == NULL)
3162 {
3163 complaint (
3164 _("Bad stabs string '%s'"), string);
3165 return NULL;
3166 }
3167 }
3168
3169 /* If a nameless stab entry, all we need is the type, not the symbol.
3170 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
3171 nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
3172
3173 current_symbol = sym = new (&objfile->objfile_obstack) symbol;
3174
3175 if (processing_gcc_compilation)
3176 {
3177 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
3178 number of bytes occupied by a type or object, which we ignore. */
3179 sym->set_line (desc);
3180 }
3181 else
3182 {
3183 sym->set_line (0); /* unknown */
3184 }
3185
3186 sym->set_language (get_current_subfile ()->language,
3187 &objfile->objfile_obstack);
3188
3189 if (is_cplus_marker (string[0]))
3190 {
3191 /* Special GNU C++ names. */
3192 switch (string[1])
3193 {
3194 case 't':
3195 sym->set_linkage_name ("this");
3196 break;
3197
3198 case 'v': /* $vtbl_ptr_type */
3199 goto normal;
3200
3201 case 'e':
3202 sym->set_linkage_name ("eh_throw");
3203 break;
3204
3205 case '_':
3206 /* This was an anonymous type that was never fixed up. */
3207 goto normal;
3208
3209 default:
3210 complaint (_("Unknown C++ symbol name `%s'"),
3211 string);
3212 goto normal; /* Do *something* with it. */
3213 }
3214 }
3215 else
3216 {
3217 normal:
3218 gdb::unique_xmalloc_ptr<char> new_name;
3219
3220 if (sym->language () == language_cplus)
3221 {
3222 std::string name (string, p - string);
3223 new_name = cp_canonicalize_string (name.c_str ());
3224 }
3225 else if (sym->language () == language_c)
3226 {
3227 std::string name (string, p - string);
3228 new_name = c_canonicalize_name (name.c_str ());
3229 }
3230 if (new_name != nullptr)
3231 sym->compute_and_set_names (new_name.get (), true, objfile->per_bfd);
3232 else
3233 sym->compute_and_set_names (std::string_view (string, p - string), true,
3234 objfile->per_bfd);
3235
3236 if (sym->language () == language_cplus)
3237 cp_scan_for_anonymous_namespaces (get_buildsym_compunit (), sym,
3238 objfile);
3239
3240 }
3241 p++;
3242
3243 /* Determine the type of name being defined. */
3244 #if 0
3245 /* Getting GDB to correctly skip the symbol on an undefined symbol
3246 descriptor and not ever dump core is a very dodgy proposition if
3247 we do things this way. I say the acorn RISC machine can just
3248 fix their compiler. */
3249 /* The Acorn RISC machine's compiler can put out locals that don't
3250 start with "234=" or "(3,4)=", so assume anything other than the
3251 deftypes we know how to handle is a local. */
3252 if (!strchr ("cfFGpPrStTvVXCR", *p))
3253 #else
3254 if (isdigit (*p) || *p == '(' || *p == '-')
3255 #endif
3256 deftype = 'l';
3257 else
3258 deftype = *p++;
3259
3260 switch (deftype)
3261 {
3262 case 'c':
3263 /* c is a special case, not followed by a type-number.
3264 SYMBOL:c=iVALUE for an integer constant symbol.
3265 SYMBOL:c=rVALUE for a floating constant symbol.
3266 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
3267 e.g. "b:c=e6,0" for "const b = blob1"
3268 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
3269 if (*p != '=')
3270 {
3271 sym->set_aclass_index (LOC_CONST);
3272 sym->set_type (error_type (&p, objfile));
3273 sym->set_domain (VAR_DOMAIN);
3274 add_symbol_to_list (sym, get_file_symbols ());
3275 return sym;
3276 }
3277 ++p;
3278 switch (*p++)
3279 {
3280 case 'r':
3281 {
3282 gdb_byte *dbl_valu;
3283 struct type *dbl_type;
3284
3285 dbl_type = builtin_type (objfile)->builtin_double;
3286 dbl_valu
3287 = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack,
3288 dbl_type->length ());
3289
3290 target_float_from_string (dbl_valu, dbl_type, std::string (p));
3291
3292 sym->set_type (dbl_type);
3293 sym->set_value_bytes (dbl_valu);
3294 sym->set_aclass_index (LOC_CONST_BYTES);
3295 }
3296 break;
3297 case 'i':
3298 {
3299 /* Defining integer constants this way is kind of silly,
3300 since 'e' constants allows the compiler to give not
3301 only the value, but the type as well. C has at least
3302 int, long, unsigned int, and long long as constant
3303 types; other languages probably should have at least
3304 unsigned as well as signed constants. */
3305
3306 sym->set_type (builtin_type (objfile)->builtin_long);
3307 sym->set_value_longest (atoi (p));
3308 sym->set_aclass_index (LOC_CONST);
3309 }
3310 break;
3311
3312 case 'c':
3313 {
3314 sym->set_type (builtin_type (objfile)->builtin_char);
3315 sym->set_value_longest (atoi (p));
3316 sym->set_aclass_index (LOC_CONST);
3317 }
3318 break;
3319
3320 case 's':
3321 {
3322 struct type *range_type;
3323 int ind = 0;
3324 char quote = *p++;
3325 gdb_byte *string_local = (gdb_byte *) alloca (strlen (p));
3326 gdb_byte *string_value;
3327
3328 if (quote != '\'' && quote != '"')
3329 {
3330 sym->set_aclass_index (LOC_CONST);
3331 sym->set_type (error_type (&p, objfile));
3332 sym->set_domain (VAR_DOMAIN);
3333 add_symbol_to_list (sym, get_file_symbols ());
3334 return sym;
3335 }
3336
3337 /* Find matching quote, rejecting escaped quotes. */
3338 while (*p && *p != quote)
3339 {
3340 if (*p == '\\' && p[1] == quote)
3341 {
3342 string_local[ind] = (gdb_byte) quote;
3343 ind++;
3344 p += 2;
3345 }
3346 else if (*p)
3347 {
3348 string_local[ind] = (gdb_byte) (*p);
3349 ind++;
3350 p++;
3351 }
3352 }
3353 if (*p != quote)
3354 {
3355 sym->set_aclass_index (LOC_CONST);
3356 sym->set_type (error_type (&p, objfile));
3357 sym->set_domain (VAR_DOMAIN);
3358 add_symbol_to_list (sym, get_file_symbols ());
3359 return sym;
3360 }
3361
3362 /* NULL terminate the string. */
3363 string_local[ind] = 0;
3364 type_allocator alloc (objfile, get_current_subfile ()->language);
3365 range_type
3366 = create_static_range_type (alloc,
3367 builtin_type (objfile)->builtin_int,
3368 0, ind);
3369 sym->set_type
3370 (create_array_type (alloc, builtin_type (objfile)->builtin_char,
3371 range_type));
3372 string_value
3373 = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack, ind + 1);
3374 memcpy (string_value, string_local, ind + 1);
3375 p++;
3376
3377 sym->set_value_bytes (string_value);
3378 sym->set_aclass_index (LOC_CONST_BYTES);
3379 }
3380 break;
3381
3382 case 'e':
3383 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
3384 can be represented as integral.
3385 e.g. "b:c=e6,0" for "const b = blob1"
3386 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
3387 {
3388 sym->set_aclass_index (LOC_CONST);
3389 sym->set_type (read_type (&p, objfile));
3390
3391 if (*p != ',')
3392 {
3393 sym->set_type (error_type (&p, objfile));
3394 break;
3395 }
3396 ++p;
3397
3398 /* If the value is too big to fit in an int (perhaps because
3399 it is unsigned), or something like that, we silently get
3400 a bogus value. The type and everything else about it is
3401 correct. Ideally, we should be using whatever we have
3402 available for parsing unsigned and long long values,
3403 however. */
3404 sym->set_value_longest (atoi (p));
3405 }
3406 break;
3407 default:
3408 {
3409 sym->set_aclass_index (LOC_CONST);
3410 sym->set_type (error_type (&p, objfile));
3411 }
3412 }
3413 sym->set_domain (VAR_DOMAIN);
3414 add_symbol_to_list (sym, get_file_symbols ());
3415 return sym;
3416
3417 case 'C':
3418 /* The name of a caught exception. */
3419 sym->set_type (read_type (&p, objfile));
3420 sym->set_aclass_index (LOC_LABEL);
3421 sym->set_domain (VAR_DOMAIN);
3422 sym->set_value_address (valu);
3423 add_symbol_to_list (sym, get_local_symbols ());
3424 break;
3425
3426 case 'f':
3427 /* A static function definition. */
3428 sym->set_type (read_type (&p, objfile));
3429 sym->set_aclass_index (LOC_BLOCK);
3430 sym->set_domain (FUNCTION_DOMAIN);
3431 add_symbol_to_list (sym, get_file_symbols ());
3432 /* fall into process_function_types. */
3433
3434 process_function_types:
3435 /* Function result types are described as the result type in stabs.
3436 We need to convert this to the function-returning-type-X type
3437 in GDB. E.g. "int" is converted to "function returning int". */
3438 if (sym->type ()->code () != TYPE_CODE_FUNC)
3439 sym->set_type (lookup_function_type (sym->type ()));
3440
3441 /* All functions in C++ have prototypes. Stabs does not offer an
3442 explicit way to identify prototyped or unprototyped functions,
3443 but both GCC and Sun CC emit stabs for the "call-as" type rather
3444 than the "declared-as" type for unprototyped functions, so
3445 we treat all functions as if they were prototyped. This is used
3446 primarily for promotion when calling the function from GDB. */
3447 sym->type ()->set_is_prototyped (true);
3448
3449 /* fall into process_prototype_types. */
3450
3451 process_prototype_types:
3452 /* Sun acc puts declared types of arguments here. */
3453 if (*p == ';')
3454 {
3455 struct type *ftype = sym->type ();
3456 int nsemi = 0;
3457 int nparams = 0;
3458 const char *p1 = p;
3459
3460 /* Obtain a worst case guess for the number of arguments
3461 by counting the semicolons. */
3462 while (*p1)
3463 {
3464 if (*p1++ == ';')
3465 nsemi++;
3466 }
3467
3468 /* Allocate parameter information fields and fill them in. */
3469 ftype->alloc_fields (nsemi);
3470 while (*p++ == ';')
3471 {
3472 struct type *ptype;
3473
3474 /* A type number of zero indicates the start of varargs.
3475 FIXME: GDB currently ignores vararg functions. */
3476 if (p[0] == '0' && p[1] == '\0')
3477 break;
3478 ptype = read_type (&p, objfile);
3479
3480 /* The Sun compilers mark integer arguments, which should
3481 be promoted to the width of the calling conventions, with
3482 a type which references itself. This type is turned into
3483 a TYPE_CODE_VOID type by read_type, and we have to turn
3484 it back into builtin_int here.
3485 FIXME: Do we need a new builtin_promoted_int_arg ? */
3486 if (ptype->code () == TYPE_CODE_VOID)
3487 ptype = builtin_type (objfile)->builtin_int;
3488 ftype->field (nparams).set_type (ptype);
3489 ftype->field (nparams).set_is_artificial (false);
3490 nparams++;
3491 }
3492 ftype->set_num_fields (nparams);
3493 ftype->set_is_prototyped (true);
3494 }
3495 break;
3496
3497 case 'F':
3498 /* A global function definition. */
3499 sym->set_type (read_type (&p, objfile));
3500 sym->set_aclass_index (LOC_BLOCK);
3501 sym->set_domain (FUNCTION_DOMAIN);
3502 add_symbol_to_list (sym, get_global_symbols ());
3503 goto process_function_types;
3504
3505 case 'G':
3506 /* For a class G (global) symbol, it appears that the
3507 value is not correct. It is necessary to search for the
3508 corresponding linker definition to find the value.
3509 These definitions appear at the end of the namelist. */
3510 sym->set_type (read_type (&p, objfile));
3511 sym->set_aclass_index (LOC_STATIC);
3512 sym->set_domain (VAR_DOMAIN);
3513 /* Don't add symbol references to global_sym_chain.
3514 Symbol references don't have valid names and won't match up with
3515 minimal symbols when the global_sym_chain is relocated.
3516 We'll fixup symbol references when we fixup the defining symbol. */
3517 if (sym->linkage_name () && sym->linkage_name ()[0] != '#')
3518 {
3519 i = hashname (sym->linkage_name ());
3520 sym->set_value_chain (global_sym_chain[i]);
3521 global_sym_chain[i] = sym;
3522 }
3523 add_symbol_to_list (sym, get_global_symbols ());
3524 break;
3525
3526 /* This case is faked by a conditional above,
3527 when there is no code letter in the dbx data.
3528 Dbx data never actually contains 'l'. */
3529 case 's':
3530 case 'l':
3531 sym->set_type (read_type (&p, objfile));
3532 sym->set_aclass_index (LOC_LOCAL);
3533 sym->set_value_longest (valu);
3534 sym->set_domain (VAR_DOMAIN);
3535 add_symbol_to_list (sym, get_local_symbols ());
3536 break;
3537
3538 case 'p':
3539 if (*p == 'F')
3540 /* pF is a two-letter code that means a function parameter in Fortran.
3541 The type-number specifies the type of the return value.
3542 Translate it into a pointer-to-function type. */
3543 {
3544 p++;
3545 sym->set_type
3546 (lookup_pointer_type
3547 (lookup_function_type (read_type (&p, objfile))));
3548 }
3549 else
3550 sym->set_type (read_type (&p, objfile));
3551
3552 sym->set_aclass_index (LOC_ARG);
3553 sym->set_value_longest (valu);
3554 sym->set_domain (VAR_DOMAIN);
3555 sym->set_is_argument (1);
3556 add_symbol_to_list (sym, get_local_symbols ());
3557
3558 if (gdbarch_byte_order (gdbarch) != BFD_ENDIAN_BIG)
3559 {
3560 /* On little-endian machines, this crud is never necessary,
3561 and, if the extra bytes contain garbage, is harmful. */
3562 break;
3563 }
3564
3565 /* If it's gcc-compiled, if it says `short', believe it. */
3566 if (processing_gcc_compilation
3567 || gdbarch_believe_pcc_promotion (gdbarch))
3568 break;
3569
3570 if (!gdbarch_believe_pcc_promotion (gdbarch))
3571 {
3572 /* If PCC says a parameter is a short or a char, it is
3573 really an int. */
3574 if (sym->type ()->length ()
3575 < gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT
3576 && sym->type ()->code () == TYPE_CODE_INT)
3577 {
3578 sym->set_type
3579 (sym->type ()->is_unsigned ()
3580 ? builtin_type (objfile)->builtin_unsigned_int
3581 : builtin_type (objfile)->builtin_int);
3582 }
3583 break;
3584 }
3585 [[fallthrough]];
3586
3587 case 'P':
3588 /* acc seems to use P to declare the prototypes of functions that
3589 are referenced by this file. gdb is not prepared to deal
3590 with this extra information. FIXME, it ought to. */
3591 if (type == N_FUN)
3592 {
3593 sym->set_type (read_type (&p, objfile));
3594 goto process_prototype_types;
3595 }
3596 [[fallthrough]];
3597
3598 case 'R':
3599 /* Parameter which is in a register. */
3600 sym->set_type (read_type (&p, objfile));
3601 sym->set_aclass_index (stab_register_index);
3602 sym->set_is_argument (1);
3603 sym->set_value_longest (valu);
3604 sym->set_domain (VAR_DOMAIN);
3605 add_symbol_to_list (sym, get_local_symbols ());
3606 break;
3607
3608 case 'r':
3609 /* Register variable (either global or local). */
3610 sym->set_type (read_type (&p, objfile));
3611 sym->set_aclass_index (stab_register_index);
3612 sym->set_value_longest (valu);
3613 sym->set_domain (VAR_DOMAIN);
3614 if (within_function)
3615 {
3616 /* Sun cc uses a pair of symbols, one 'p' and one 'r', with
3617 the same name to represent an argument passed in a
3618 register. GCC uses 'P' for the same case. So if we find
3619 such a symbol pair we combine it into one 'P' symbol.
3620 For Sun cc we need to do this regardless of stabs_argument_has_addr, because the compiler puts out
3621 the 'p' symbol even if it never saves the argument onto
3622 the stack.
3623
3624 On most machines, we want to preserve both symbols, so
3625 that we can still get information about what is going on
3626 with the stack (VAX for computing args_printed, using
3627 stack slots instead of saved registers in backtraces,
3628 etc.).
3629
3630 Note that this code illegally combines
3631 main(argc) struct foo argc; { register struct foo argc; }
3632 but this case is considered pathological and causes a warning
3633 from a decent compiler. */
3634
3635 struct pending *local_symbols = *get_local_symbols ();
3636 if (local_symbols
3637 && local_symbols->nsyms > 0
3638 && gdbarch_stabs_argument_has_addr (gdbarch, sym->type ()))
3639 {
3640 struct symbol *prev_sym;
3641
3642 prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
3643 if ((prev_sym->aclass () == LOC_REF_ARG
3644 || prev_sym->aclass () == LOC_ARG)
3645 && strcmp (prev_sym->linkage_name (),
3646 sym->linkage_name ()) == 0)
3647 {
3648 prev_sym->set_aclass_index (stab_register_index);
3649 /* Use the type from the LOC_REGISTER; that is the type
3650 that is actually in that register. */
3651 prev_sym->set_type (sym->type ());
3652 prev_sym->set_value_longest (sym->value_longest ());
3653 sym = prev_sym;
3654 break;
3655 }
3656 }
3657 add_symbol_to_list (sym, get_local_symbols ());
3658 }
3659 else
3660 add_symbol_to_list (sym, get_file_symbols ());
3661 break;
3662
3663 case 'S':
3664 /* Static symbol at top level of file. */
3665 sym->set_type (read_type (&p, objfile));
3666 sym->set_aclass_index (LOC_STATIC);
3667 sym->set_value_address (valu);
3668 sym->set_domain (VAR_DOMAIN);
3669 add_symbol_to_list (sym, get_file_symbols ());
3670 break;
3671
3672 case 't':
3673 /* In Ada, there is no distinction between typedef and non-typedef;
3674 any type declaration implicitly has the equivalent of a typedef,
3675 and thus 't' is in fact equivalent to 'Tt'.
3676
3677 Therefore, for Ada units, we check the character immediately
3678 before the 't', and if we do not find a 'T', then make sure to
3679 create the associated symbol in the STRUCT_DOMAIN ('t' definitions
3680 will be stored in the VAR_DOMAIN). If the symbol was indeed
3681 defined as 'Tt' then the STRUCT_DOMAIN symbol will be created
3682 elsewhere, so we don't need to take care of that.
3683
3684 This is important to do, because of forward references:
3685 The cleanup of undefined types stored in undef_types only uses
3686 STRUCT_DOMAIN symbols to perform the replacement. */
3687 synonym = (sym->language () == language_ada && p[-2] != 'T');
3688
3689 /* Typedef */
3690 sym->set_type (read_type (&p, objfile));
3691
3692 /* For a nameless type, we don't want a create a symbol, thus we
3693 did not use `sym'. Return without further processing. */
3694 if (nameless)
3695 return NULL;
3696
3697 sym->set_aclass_index (LOC_TYPEDEF);
3698 sym->set_value_longest (valu);
3699 sym->set_domain (TYPE_DOMAIN);
3700 /* C++ vagaries: we may have a type which is derived from
3701 a base type which did not have its name defined when the
3702 derived class was output. We fill in the derived class's
3703 base part member's name here in that case. */
3704 if (sym->type ()->name () != NULL)
3705 if ((sym->type ()->code () == TYPE_CODE_STRUCT
3706 || sym->type ()->code () == TYPE_CODE_UNION)
3707 && TYPE_N_BASECLASSES (sym->type ()))
3708 {
3709 int j;
3710
3711 for (j = TYPE_N_BASECLASSES (sym->type ()) - 1; j >= 0; j--)
3712 if (TYPE_BASECLASS_NAME (sym->type (), j) == 0)
3713 sym->type ()->field (j).set_name
3714 (TYPE_BASECLASS (sym->type (), j)->name ());
3715 }
3716
3717 if (sym->type ()->name () == NULL)
3718 {
3719 if ((sym->type ()->code () == TYPE_CODE_PTR
3720 && strcmp (sym->linkage_name (), vtbl_ptr_name))
3721 || sym->type ()->code () == TYPE_CODE_FUNC)
3722 {
3723 /* If we are giving a name to a type such as "pointer to
3724 foo" or "function returning foo", we better not set
3725 the TYPE_NAME. If the program contains "typedef char
3726 *caddr_t;", we don't want all variables of type char
3727 * to print as caddr_t. This is not just a
3728 consequence of GDB's type management; PCC and GCC (at
3729 least through version 2.4) both output variables of
3730 either type char * or caddr_t with the type number
3731 defined in the 't' symbol for caddr_t. If a future
3732 compiler cleans this up it GDB is not ready for it
3733 yet, but if it becomes ready we somehow need to
3734 disable this check (without breaking the PCC/GCC2.4
3735 case).
3736
3737 Sigh.
3738
3739 Fortunately, this check seems not to be necessary
3740 for anything except pointers or functions. */
3741 /* ezannoni: 2000-10-26. This seems to apply for
3742 versions of gcc older than 2.8. This was the original
3743 problem: with the following code gdb would tell that
3744 the type for name1 is caddr_t, and func is char().
3745
3746 typedef char *caddr_t;
3747 char *name2;
3748 struct x
3749 {
3750 char *name1;
3751 } xx;
3752 char *func()
3753 {
3754 }
3755 main () {}
3756 */
3757
3758 /* Pascal accepts names for pointer types. */
3759 if (get_current_subfile ()->language == language_pascal)
3760 sym->type ()->set_name (sym->linkage_name ());
3761 }
3762 else
3763 sym->type ()->set_name (sym->linkage_name ());
3764 }
3765
3766 add_symbol_to_list (sym, get_file_symbols ());
3767
3768 if (synonym)
3769 {
3770 /* Create the STRUCT_DOMAIN clone. */
3771 struct symbol *struct_sym = new (&objfile->objfile_obstack) symbol;
3772
3773 *struct_sym = *sym;
3774 struct_sym->set_aclass_index (LOC_TYPEDEF);
3775 struct_sym->set_value_longest (valu);
3776 struct_sym->set_domain (STRUCT_DOMAIN);
3777 if (sym->type ()->name () == 0)
3778 sym->type ()->set_name
3779 (obconcat (&objfile->objfile_obstack, sym->linkage_name (),
3780 (char *) NULL));
3781 add_symbol_to_list (struct_sym, get_file_symbols ());
3782 }
3783
3784 break;
3785
3786 case 'T':
3787 /* Struct, union, or enum tag. For GNU C++, this can be be followed
3788 by 't' which means we are typedef'ing it as well. */
3789 synonym = *p == 't';
3790
3791 if (synonym)
3792 p++;
3793
3794 sym->set_type (read_type (&p, objfile));
3795
3796 /* For a nameless type, we don't want a create a symbol, thus we
3797 did not use `sym'. Return without further processing. */
3798 if (nameless)
3799 return NULL;
3800
3801 sym->set_aclass_index (LOC_TYPEDEF);
3802 sym->set_value_longest (valu);
3803 sym->set_domain (STRUCT_DOMAIN);
3804 if (sym->type ()->name () == 0)
3805 sym->type ()->set_name
3806 (obconcat (&objfile->objfile_obstack, sym->linkage_name (),
3807 (char *) NULL));
3808 add_symbol_to_list (sym, get_file_symbols ());
3809
3810 if (synonym)
3811 {
3812 /* Clone the sym and then modify it. */
3813 struct symbol *typedef_sym = new (&objfile->objfile_obstack) symbol;
3814
3815 *typedef_sym = *sym;
3816 typedef_sym->set_aclass_index (LOC_TYPEDEF);
3817 typedef_sym->set_value_longest (valu);
3818 typedef_sym->set_domain (TYPE_DOMAIN);
3819 if (sym->type ()->name () == 0)
3820 sym->type ()->set_name
3821 (obconcat (&objfile->objfile_obstack, sym->linkage_name (),
3822 (char *) NULL));
3823 add_symbol_to_list (typedef_sym, get_file_symbols ());
3824 }
3825 break;
3826
3827 case 'V':
3828 /* Static symbol of local scope. */
3829 sym->set_type (read_type (&p, objfile));
3830 sym->set_aclass_index (LOC_STATIC);
3831 sym->set_value_address (valu);
3832 sym->set_domain (VAR_DOMAIN);
3833 add_symbol_to_list (sym, get_local_symbols ());
3834 break;
3835
3836 case 'v':
3837 /* Reference parameter */
3838 sym->set_type (read_type (&p, objfile));
3839 sym->set_aclass_index (LOC_REF_ARG);
3840 sym->set_is_argument (1);
3841 sym->set_value_longest (valu);
3842 sym->set_domain (VAR_DOMAIN);
3843 add_symbol_to_list (sym, get_local_symbols ());
3844 break;
3845
3846 case 'a':
3847 /* Reference parameter which is in a register. */
3848 sym->set_type (read_type (&p, objfile));
3849 sym->set_aclass_index (stab_regparm_index);
3850 sym->set_is_argument (1);
3851 sym->set_value_longest (valu);
3852 sym->set_domain (VAR_DOMAIN);
3853 add_symbol_to_list (sym, get_local_symbols ());
3854 break;
3855
3856 case 'X':
3857 /* This is used by Sun FORTRAN for "function result value".
3858 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
3859 that Pascal uses it too, but when I tried it Pascal used
3860 "x:3" (local symbol) instead. */
3861 sym->set_type (read_type (&p, objfile));
3862 sym->set_aclass_index (LOC_LOCAL);
3863 sym->set_value_longest (valu);
3864 sym->set_domain (VAR_DOMAIN);
3865 add_symbol_to_list (sym, get_local_symbols ());
3866 break;
3867
3868 default:
3869 sym->set_type (error_type (&p, objfile));
3870 sym->set_aclass_index (LOC_CONST);
3871 sym->set_value_longest (0);
3872 sym->set_domain (VAR_DOMAIN);
3873 add_symbol_to_list (sym, get_file_symbols ());
3874 break;
3875 }
3876
3877 /* Some systems pass variables of certain types by reference instead
3878 of by value, i.e. they will pass the address of a structure (in a
3879 register or on the stack) instead of the structure itself. */
3880
3881 if (gdbarch_stabs_argument_has_addr (gdbarch, sym->type ())
3882 && sym->is_argument ())
3883 {
3884 /* We have to convert LOC_REGISTER to LOC_REGPARM_ADDR (for
3885 variables passed in a register). */
3886 if (sym->aclass () == LOC_REGISTER)
3887 sym->set_aclass_index (LOC_REGPARM_ADDR);
3888 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
3889 and subsequent arguments on SPARC, for example). */
3890 else if (sym->aclass () == LOC_ARG)
3891 sym->set_aclass_index (LOC_REF_ARG);
3892 }
3893
3894 return sym;
3895 }
3896
3897 /* Skip rest of this symbol and return an error type.
3898
3899 General notes on error recovery: error_type always skips to the
3900 end of the symbol (modulo cretinous dbx symbol name continuation).
3901 Thus code like this:
3902
3903 if (*(*pp)++ != ';')
3904 return error_type (pp, objfile);
3905
3906 is wrong because if *pp starts out pointing at '\0' (typically as the
3907 result of an earlier error), it will be incremented to point to the
3908 start of the next symbol, which might produce strange results, at least
3909 if you run off the end of the string table. Instead use
3910
3911 if (**pp != ';')
3912 return error_type (pp, objfile);
3913 ++*pp;
3914
3915 or
3916
3917 if (**pp != ';')
3918 foo = error_type (pp, objfile);
3919 else
3920 ++*pp;
3921
3922 And in case it isn't obvious, the point of all this hair is so the compiler
3923 can define new types and new syntaxes, and old versions of the
3924 debugger will be able to read the new symbol tables. */
3925
3926 static struct type *
3927 error_type (const char **pp, struct objfile *objfile)
3928 {
3929 complaint (_("couldn't parse type; debugger out of date?"));
3930 while (1)
3931 {
3932 /* Skip to end of symbol. */
3933 while (**pp != '\0')
3934 {
3935 (*pp)++;
3936 }
3937
3938 /* Check for and handle cretinous dbx symbol name continuation! */
3939 if ((*pp)[-1] == '\\' || (*pp)[-1] == '?')
3940 {
3941 *pp = next_symbol_text (objfile);
3942 }
3943 else
3944 {
3945 break;
3946 }
3947 }
3948 return builtin_type (objfile)->builtin_error;
3949 }
3950 \f
3951
3952 /* Allocate a stub method whose return type is TYPE. This apparently
3953 happens for speed of symbol reading, since parsing out the
3954 arguments to the method is cpu-intensive, the way we are doing it.
3955 So, we will fill in arguments later. This always returns a fresh
3956 type. */
3957
3958 static struct type *
3959 allocate_stub_method (struct type *type)
3960 {
3961 struct type *mtype;
3962
3963 mtype = type_allocator (type).new_type ();
3964 mtype->set_code (TYPE_CODE_METHOD);
3965 mtype->set_length (1);
3966 mtype->set_is_stub (true);
3967 mtype->set_target_type (type);
3968 /* TYPE_SELF_TYPE (mtype) = unknown yet */
3969 return mtype;
3970 }
3971
3972 /* Read type information or a type definition; return the type. Even
3973 though this routine accepts either type information or a type
3974 definition, the distinction is relevant--some parts of stabsread.c
3975 assume that type information starts with a digit, '-', or '(' in
3976 deciding whether to call read_type. */
3977
3978 static struct type *
3979 read_type (const char **pp, struct objfile *objfile)
3980 {
3981 struct type *type = 0;
3982 struct type *type1;
3983 int typenums[2];
3984 char type_descriptor;
3985
3986 /* Size in bits of type if specified by a type attribute, or -1 if
3987 there is no size attribute. */
3988 int type_size = -1;
3989
3990 /* Used to distinguish string and bitstring from char-array and set. */
3991 int is_string = 0;
3992
3993 /* Used to distinguish vector from array. */
3994 int is_vector = 0;
3995
3996 /* Read type number if present. The type number may be omitted.
3997 for instance in a two-dimensional array declared with type
3998 "ar1;1;10;ar1;1;10;4". */
3999 if ((**pp >= '0' && **pp <= '9')
4000 || **pp == '('
4001 || **pp == '-')
4002 {
4003 if (read_type_number (pp, typenums) != 0)
4004 return error_type (pp, objfile);
4005
4006 if (**pp != '=')
4007 {
4008 /* Type is not being defined here. Either it already
4009 exists, or this is a forward reference to it.
4010 dbx_alloc_type handles both cases. */
4011 type = dbx_alloc_type (typenums, objfile);
4012
4013 /* If this is a forward reference, arrange to complain if it
4014 doesn't get patched up by the time we're done
4015 reading. */
4016 if (type->code () == TYPE_CODE_UNDEF)
4017 add_undefined_type (type, typenums);
4018
4019 return type;
4020 }
4021
4022 /* Type is being defined here. */
4023 /* Skip the '='.
4024 Also skip the type descriptor - we get it below with (*pp)[-1]. */
4025 (*pp) += 2;
4026 }
4027 else
4028 {
4029 /* 'typenums=' not present, type is anonymous. Read and return
4030 the definition, but don't put it in the type vector. */
4031 typenums[0] = typenums[1] = -1;
4032 (*pp)++;
4033 }
4034
4035 again:
4036 type_descriptor = (*pp)[-1];
4037 switch (type_descriptor)
4038 {
4039 case 'x':
4040 {
4041 enum type_code code;
4042
4043 /* Used to index through file_symbols. */
4044 struct pending *ppt;
4045 int i;
4046
4047 /* Name including "struct", etc. */
4048 char *type_name;
4049
4050 {
4051 const char *from, *p, *q1, *q2;
4052
4053 /* Set the type code according to the following letter. */
4054 switch ((*pp)[0])
4055 {
4056 case 's':
4057 code = TYPE_CODE_STRUCT;
4058 break;
4059 case 'u':
4060 code = TYPE_CODE_UNION;
4061 break;
4062 case 'e':
4063 code = TYPE_CODE_ENUM;
4064 break;
4065 default:
4066 {
4067 /* Complain and keep going, so compilers can invent new
4068 cross-reference types. */
4069 complaint (_("Unrecognized cross-reference type `%c'"),
4070 (*pp)[0]);
4071 code = TYPE_CODE_STRUCT;
4072 break;
4073 }
4074 }
4075
4076 q1 = strchr (*pp, '<');
4077 p = strchr (*pp, ':');
4078 if (p == NULL)
4079 return error_type (pp, objfile);
4080 if (q1 && p > q1 && p[1] == ':')
4081 {
4082 int nesting_level = 0;
4083
4084 for (q2 = q1; *q2; q2++)
4085 {
4086 if (*q2 == '<')
4087 nesting_level++;
4088 else if (*q2 == '>')
4089 nesting_level--;
4090 else if (*q2 == ':' && nesting_level == 0)
4091 break;
4092 }
4093 p = q2;
4094 if (*p != ':')
4095 return error_type (pp, objfile);
4096 }
4097 type_name = NULL;
4098 if (get_current_subfile ()->language == language_cplus)
4099 {
4100 std::string name (*pp, p - *pp);
4101 gdb::unique_xmalloc_ptr<char> new_name
4102 = cp_canonicalize_string (name.c_str ());
4103 if (new_name != nullptr)
4104 type_name = obstack_strdup (&objfile->objfile_obstack,
4105 new_name.get ());
4106 }
4107 else if (get_current_subfile ()->language == language_c)
4108 {
4109 std::string name (*pp, p - *pp);
4110 gdb::unique_xmalloc_ptr<char> new_name
4111 = c_canonicalize_name (name.c_str ());
4112 if (new_name != nullptr)
4113 type_name = obstack_strdup (&objfile->objfile_obstack,
4114 new_name.get ());
4115 }
4116 if (type_name == NULL)
4117 {
4118 char *to = type_name = (char *)
4119 obstack_alloc (&objfile->objfile_obstack, p - *pp + 1);
4120
4121 /* Copy the name. */
4122 from = *pp + 1;
4123 while (from < p)
4124 *to++ = *from++;
4125 *to = '\0';
4126 }
4127
4128 /* Set the pointer ahead of the name which we just read, and
4129 the colon. */
4130 *pp = p + 1;
4131 }
4132
4133 /* If this type has already been declared, then reuse the same
4134 type, rather than allocating a new one. This saves some
4135 memory. */
4136
4137 for (ppt = *get_file_symbols (); ppt; ppt = ppt->next)
4138 for (i = 0; i < ppt->nsyms; i++)
4139 {
4140 struct symbol *sym = ppt->symbol[i];
4141
4142 if (sym->aclass () == LOC_TYPEDEF
4143 && sym->domain () == STRUCT_DOMAIN
4144 && (sym->type ()->code () == code)
4145 && strcmp (sym->linkage_name (), type_name) == 0)
4146 {
4147 obstack_free (&objfile->objfile_obstack, type_name);
4148 type = sym->type ();
4149 if (typenums[0] != -1)
4150 *dbx_lookup_type (typenums, objfile) = type;
4151 return type;
4152 }
4153 }
4154
4155 /* Didn't find the type to which this refers, so we must
4156 be dealing with a forward reference. Allocate a type
4157 structure for it, and keep track of it so we can
4158 fill in the rest of the fields when we get the full
4159 type. */
4160 type = dbx_alloc_type (typenums, objfile);
4161 type->set_code (code);
4162 type->set_name (type_name);
4163 INIT_CPLUS_SPECIFIC (type);
4164 type->set_is_stub (true);
4165
4166 add_undefined_type (type, typenums);
4167 return type;
4168 }
4169
4170 case '-': /* RS/6000 built-in type */
4171 case '0':
4172 case '1':
4173 case '2':
4174 case '3':
4175 case '4':
4176 case '5':
4177 case '6':
4178 case '7':
4179 case '8':
4180 case '9':
4181 case '(':
4182 (*pp)--;
4183
4184 /* We deal with something like t(1,2)=(3,4)=... which
4185 the Lucid compiler and recent gcc versions (post 2.7.3) use. */
4186
4187 /* Allocate and enter the typedef type first.
4188 This handles recursive types. */
4189 type = dbx_alloc_type (typenums, objfile);
4190 type->set_code (TYPE_CODE_TYPEDEF);
4191 {
4192 struct type *xtype = read_type (pp, objfile);
4193
4194 if (type == xtype)
4195 {
4196 /* It's being defined as itself. That means it is "void". */
4197 type->set_code (TYPE_CODE_VOID);
4198 type->set_length (1);
4199 }
4200 else if (type_size >= 0 || is_string)
4201 {
4202 /* This is the absolute wrong way to construct types. Every
4203 other debug format has found a way around this problem and
4204 the related problems with unnecessarily stubbed types;
4205 someone motivated should attempt to clean up the issue
4206 here as well. Once a type pointed to has been created it
4207 should not be modified.
4208
4209 Well, it's not *absolutely* wrong. Constructing recursive
4210 types (trees, linked lists) necessarily entails modifying
4211 types after creating them. Constructing any loop structure
4212 entails side effects. The Dwarf 2 reader does handle this
4213 more gracefully (it never constructs more than once
4214 instance of a type object, so it doesn't have to copy type
4215 objects wholesale), but it still mutates type objects after
4216 other folks have references to them.
4217
4218 Keep in mind that this circularity/mutation issue shows up
4219 at the source language level, too: C's "incomplete types",
4220 for example. So the proper cleanup, I think, would be to
4221 limit GDB's type smashing to match exactly those required
4222 by the source language. So GDB could have a
4223 "complete_this_type" function, but never create unnecessary
4224 copies of a type otherwise. */
4225 replace_type (type, xtype);
4226 type->set_name (NULL);
4227 }
4228 else
4229 {
4230 type->set_target_is_stub (true);
4231 type->set_target_type (xtype);
4232 }
4233 }
4234 break;
4235
4236 /* In the following types, we must be sure to overwrite any existing
4237 type that the typenums refer to, rather than allocating a new one
4238 and making the typenums point to the new one. This is because there
4239 may already be pointers to the existing type (if it had been
4240 forward-referenced), and we must change it to a pointer, function,
4241 reference, or whatever, *in-place*. */
4242
4243 case '*': /* Pointer to another type */
4244 type1 = read_type (pp, objfile);
4245 type = make_pointer_type (type1, dbx_lookup_type (typenums, objfile));
4246 break;
4247
4248 case '&': /* Reference to another type */
4249 type1 = read_type (pp, objfile);
4250 type = make_reference_type (type1, dbx_lookup_type (typenums, objfile),
4251 TYPE_CODE_REF);
4252 break;
4253
4254 case 'f': /* Function returning another type */
4255 type1 = read_type (pp, objfile);
4256 type = make_function_type (type1, dbx_lookup_type (typenums, objfile));
4257 break;
4258
4259 case 'g': /* Prototyped function. (Sun) */
4260 {
4261 /* Unresolved questions:
4262
4263 - According to Sun's ``STABS Interface Manual'', for 'f'
4264 and 'F' symbol descriptors, a `0' in the argument type list
4265 indicates a varargs function. But it doesn't say how 'g'
4266 type descriptors represent that info. Someone with access
4267 to Sun's toolchain should try it out.
4268
4269 - According to the comment in define_symbol (search for
4270 `process_prototype_types:'), Sun emits integer arguments as
4271 types which ref themselves --- like `void' types. Do we
4272 have to deal with that here, too? Again, someone with
4273 access to Sun's toolchain should try it out and let us
4274 know. */
4275
4276 const char *type_start = (*pp) - 1;
4277 struct type *return_type = read_type (pp, objfile);
4278 struct type *func_type
4279 = make_function_type (return_type,
4280 dbx_lookup_type (typenums, objfile));
4281 struct type_list {
4282 struct type *type;
4283 struct type_list *next;
4284 } *arg_types = 0;
4285 int num_args = 0;
4286
4287 while (**pp && **pp != '#')
4288 {
4289 struct type *arg_type = read_type (pp, objfile);
4290 struct type_list *newobj = XALLOCA (struct type_list);
4291 newobj->type = arg_type;
4292 newobj->next = arg_types;
4293 arg_types = newobj;
4294 num_args++;
4295 }
4296 if (**pp == '#')
4297 ++*pp;
4298 else
4299 {
4300 complaint (_("Prototyped function type didn't "
4301 "end arguments with `#':\n%s"),
4302 type_start);
4303 }
4304
4305 /* If there is just one argument whose type is `void', then
4306 that's just an empty argument list. */
4307 if (arg_types
4308 && ! arg_types->next
4309 && arg_types->type->code () == TYPE_CODE_VOID)
4310 num_args = 0;
4311
4312 func_type->alloc_fields (num_args);
4313 {
4314 int i;
4315 struct type_list *t;
4316
4317 /* We stuck each argument type onto the front of the list
4318 when we read it, so the list is reversed. Build the
4319 fields array right-to-left. */
4320 for (t = arg_types, i = num_args - 1; t; t = t->next, i--)
4321 func_type->field (i).set_type (t->type);
4322 }
4323 func_type->set_num_fields (num_args);
4324 func_type->set_is_prototyped (true);
4325
4326 type = func_type;
4327 break;
4328 }
4329
4330 case 'k': /* Const qualifier on some type (Sun) */
4331 type = read_type (pp, objfile);
4332 type = make_cv_type (1, TYPE_VOLATILE (type), type,
4333 dbx_lookup_type (typenums, objfile));
4334 break;
4335
4336 case 'B': /* Volatile qual on some type (Sun) */
4337 type = read_type (pp, objfile);
4338 type = make_cv_type (TYPE_CONST (type), 1, type,
4339 dbx_lookup_type (typenums, objfile));
4340 break;
4341
4342 case '@':
4343 if (isdigit (**pp) || **pp == '(' || **pp == '-')
4344 { /* Member (class & variable) type */
4345 /* FIXME -- we should be doing smash_to_XXX types here. */
4346
4347 struct type *domain = read_type (pp, objfile);
4348 struct type *memtype;
4349
4350 if (**pp != ',')
4351 /* Invalid member type data format. */
4352 return error_type (pp, objfile);
4353 ++*pp;
4354
4355 memtype = read_type (pp, objfile);
4356 type = dbx_alloc_type (typenums, objfile);
4357 smash_to_memberptr_type (type, domain, memtype);
4358 }
4359 else
4360 /* type attribute */
4361 {
4362 const char *attr = *pp;
4363
4364 /* Skip to the semicolon. */
4365 while (**pp != ';' && **pp != '\0')
4366 ++(*pp);
4367 if (**pp == '\0')
4368 return error_type (pp, objfile);
4369 else
4370 ++ * pp; /* Skip the semicolon. */
4371
4372 switch (*attr)
4373 {
4374 case 's': /* Size attribute */
4375 type_size = atoi (attr + 1);
4376 if (type_size <= 0)
4377 type_size = -1;
4378 break;
4379
4380 case 'S': /* String attribute */
4381 /* FIXME: check to see if following type is array? */
4382 is_string = 1;
4383 break;
4384
4385 case 'V': /* Vector attribute */
4386 /* FIXME: check to see if following type is array? */
4387 is_vector = 1;
4388 break;
4389
4390 default:
4391 /* Ignore unrecognized type attributes, so future compilers
4392 can invent new ones. */
4393 break;
4394 }
4395 ++*pp;
4396 goto again;
4397 }
4398 break;
4399
4400 case '#': /* Method (class & fn) type */
4401 if ((*pp)[0] == '#')
4402 {
4403 /* We'll get the parameter types from the name. */
4404 struct type *return_type;
4405
4406 (*pp)++;
4407 return_type = read_type (pp, objfile);
4408 if (*(*pp)++ != ';')
4409 complaint (_("invalid (minimal) member type "
4410 "data format at symtab pos %d."),
4411 symnum);
4412 type = allocate_stub_method (return_type);
4413 if (typenums[0] != -1)
4414 *dbx_lookup_type (typenums, objfile) = type;
4415 }
4416 else
4417 {
4418 struct type *domain = read_type (pp, objfile);
4419 struct type *return_type;
4420 struct field *args;
4421 int nargs, varargs;
4422
4423 if (**pp != ',')
4424 /* Invalid member type data format. */
4425 return error_type (pp, objfile);
4426 else
4427 ++(*pp);
4428
4429 return_type = read_type (pp, objfile);
4430 args = read_args (pp, ';', objfile, &nargs, &varargs);
4431 if (args == NULL)
4432 return error_type (pp, objfile);
4433 type = dbx_alloc_type (typenums, objfile);
4434 smash_to_method_type (type, domain, return_type, args,
4435 nargs, varargs);
4436 }
4437 break;
4438
4439 case 'r': /* Range type */
4440 type = read_range_type (pp, typenums, type_size, objfile);
4441 if (typenums[0] != -1)
4442 *dbx_lookup_type (typenums, objfile) = type;
4443 break;
4444
4445 case 'b':
4446 {
4447 /* Sun ACC builtin int type */
4448 type = read_sun_builtin_type (pp, typenums, objfile);
4449 if (typenums[0] != -1)
4450 *dbx_lookup_type (typenums, objfile) = type;
4451 }
4452 break;
4453
4454 case 'R': /* Sun ACC builtin float type */
4455 type = read_sun_floating_type (pp, typenums, objfile);
4456 if (typenums[0] != -1)
4457 *dbx_lookup_type (typenums, objfile) = type;
4458 break;
4459
4460 case 'e': /* Enumeration type */
4461 type = dbx_alloc_type (typenums, objfile);
4462 type = read_enum_type (pp, type, objfile);
4463 if (typenums[0] != -1)
4464 *dbx_lookup_type (typenums, objfile) = type;
4465 break;
4466
4467 case 's': /* Struct type */
4468 case 'u': /* Union type */
4469 {
4470 enum type_code type_code = TYPE_CODE_UNDEF;
4471 type = dbx_alloc_type (typenums, objfile);
4472 switch (type_descriptor)
4473 {
4474 case 's':
4475 type_code = TYPE_CODE_STRUCT;
4476 break;
4477 case 'u':
4478 type_code = TYPE_CODE_UNION;
4479 break;
4480 }
4481 type = read_struct_type (pp, type, type_code, objfile);
4482 break;
4483 }
4484
4485 case 'a': /* Array type */
4486 if (**pp != 'r')
4487 return error_type (pp, objfile);
4488 ++*pp;
4489
4490 type = dbx_alloc_type (typenums, objfile);
4491 type = read_array_type (pp, type, objfile);
4492 if (is_string)
4493 type->set_code (TYPE_CODE_STRING);
4494 if (is_vector)
4495 make_vector_type (type);
4496 break;
4497
4498 case 'S': /* Set type */
4499 {
4500 type1 = read_type (pp, objfile);
4501 type_allocator alloc (objfile, get_current_subfile ()->language);
4502 type = create_set_type (alloc, type1);
4503 if (typenums[0] != -1)
4504 *dbx_lookup_type (typenums, objfile) = type;
4505 }
4506 break;
4507
4508 default:
4509 --*pp; /* Go back to the symbol in error. */
4510 /* Particularly important if it was \0! */
4511 return error_type (pp, objfile);
4512 }
4513
4514 if (type == 0)
4515 {
4516 warning (_("GDB internal error, type is NULL in stabsread.c."));
4517 return error_type (pp, objfile);
4518 }
4519
4520 /* Size specified in a type attribute overrides any other size. */
4521 if (type_size != -1)
4522 type->set_length ((type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT);
4523
4524 return type;
4525 }
4526 \f
4527 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
4528 Return the proper type node for a given builtin type number. */
4529
4530 static const registry<objfile>::key<struct type *,
4531 gdb::noop_deleter<struct type *>>
4532 rs6000_builtin_type_data;
4533
4534 static struct type *
4535 rs6000_builtin_type (int typenum, struct objfile *objfile)
4536 {
4537 struct type **negative_types = rs6000_builtin_type_data.get (objfile);
4538
4539 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
4540 #define NUMBER_RECOGNIZED 34
4541 struct type *rettype = NULL;
4542
4543 if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED)
4544 {
4545 complaint (_("Unknown builtin type %d"), typenum);
4546 return builtin_type (objfile)->builtin_error;
4547 }
4548
4549 if (!negative_types)
4550 {
4551 /* This includes an empty slot for type number -0. */
4552 negative_types = OBSTACK_CALLOC (&objfile->objfile_obstack,
4553 NUMBER_RECOGNIZED + 1, struct type *);
4554 rs6000_builtin_type_data.set (objfile, negative_types);
4555 }
4556
4557 if (negative_types[-typenum] != NULL)
4558 return negative_types[-typenum];
4559
4560 #if TARGET_CHAR_BIT != 8
4561 #error This code wrong for TARGET_CHAR_BIT not 8
4562 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
4563 that if that ever becomes not true, the correct fix will be to
4564 make the size in the struct type to be in bits, not in units of
4565 TARGET_CHAR_BIT. */
4566 #endif
4567
4568 type_allocator alloc (objfile, get_current_subfile ()->language);
4569 switch (-typenum)
4570 {
4571 case 1:
4572 /* The size of this and all the other types are fixed, defined
4573 by the debugging format. If there is a type called "int" which
4574 is other than 32 bits, then it should use a new negative type
4575 number (or avoid negative type numbers for that case).
4576 See stabs.texinfo. */
4577 rettype = init_integer_type (alloc, 32, 0, "int");
4578 break;
4579 case 2:
4580 rettype = init_integer_type (alloc, 8, 0, "char");
4581 rettype->set_has_no_signedness (true);
4582 break;
4583 case 3:
4584 rettype = init_integer_type (alloc, 16, 0, "short");
4585 break;
4586 case 4:
4587 rettype = init_integer_type (alloc, 32, 0, "long");
4588 break;
4589 case 5:
4590 rettype = init_integer_type (alloc, 8, 1, "unsigned char");
4591 break;
4592 case 6:
4593 rettype = init_integer_type (alloc, 8, 0, "signed char");
4594 break;
4595 case 7:
4596 rettype = init_integer_type (alloc, 16, 1, "unsigned short");
4597 break;
4598 case 8:
4599 rettype = init_integer_type (alloc, 32, 1, "unsigned int");
4600 break;
4601 case 9:
4602 rettype = init_integer_type (alloc, 32, 1, "unsigned");
4603 break;
4604 case 10:
4605 rettype = init_integer_type (alloc, 32, 1, "unsigned long");
4606 break;
4607 case 11:
4608 rettype = alloc.new_type (TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
4609 break;
4610 case 12:
4611 /* IEEE single precision (32 bit). */
4612 rettype = init_float_type (alloc, 32, "float",
4613 floatformats_ieee_single);
4614 break;
4615 case 13:
4616 /* IEEE double precision (64 bit). */
4617 rettype = init_float_type (alloc, 64, "double",
4618 floatformats_ieee_double);
4619 break;
4620 case 14:
4621 /* This is an IEEE double on the RS/6000, and different machines with
4622 different sizes for "long double" should use different negative
4623 type numbers. See stabs.texinfo. */
4624 rettype = init_float_type (alloc, 64, "long double",
4625 floatformats_ieee_double);
4626 break;
4627 case 15:
4628 rettype = init_integer_type (alloc, 32, 0, "integer");
4629 break;
4630 case 16:
4631 rettype = init_boolean_type (alloc, 32, 1, "boolean");
4632 break;
4633 case 17:
4634 rettype = init_float_type (alloc, 32, "short real",
4635 floatformats_ieee_single);
4636 break;
4637 case 18:
4638 rettype = init_float_type (alloc, 64, "real",
4639 floatformats_ieee_double);
4640 break;
4641 case 19:
4642 rettype = alloc.new_type (TYPE_CODE_ERROR, 0, "stringptr");
4643 break;
4644 case 20:
4645 rettype = init_character_type (alloc, 8, 1, "character");
4646 break;
4647 case 21:
4648 rettype = init_boolean_type (alloc, 8, 1, "logical*1");
4649 break;
4650 case 22:
4651 rettype = init_boolean_type (alloc, 16, 1, "logical*2");
4652 break;
4653 case 23:
4654 rettype = init_boolean_type (alloc, 32, 1, "logical*4");
4655 break;
4656 case 24:
4657 rettype = init_boolean_type (alloc, 32, 1, "logical");
4658 break;
4659 case 25:
4660 /* Complex type consisting of two IEEE single precision values. */
4661 rettype = init_complex_type ("complex",
4662 rs6000_builtin_type (12, objfile));
4663 break;
4664 case 26:
4665 /* Complex type consisting of two IEEE double precision values. */
4666 rettype = init_complex_type ("double complex",
4667 rs6000_builtin_type (13, objfile));
4668 break;
4669 case 27:
4670 rettype = init_integer_type (alloc, 8, 0, "integer*1");
4671 break;
4672 case 28:
4673 rettype = init_integer_type (alloc, 16, 0, "integer*2");
4674 break;
4675 case 29:
4676 rettype = init_integer_type (alloc, 32, 0, "integer*4");
4677 break;
4678 case 30:
4679 rettype = init_character_type (alloc, 16, 0, "wchar");
4680 break;
4681 case 31:
4682 rettype = init_integer_type (alloc, 64, 0, "long long");
4683 break;
4684 case 32:
4685 rettype = init_integer_type (alloc, 64, 1, "unsigned long long");
4686 break;
4687 case 33:
4688 rettype = init_integer_type (alloc, 64, 1, "logical*8");
4689 break;
4690 case 34:
4691 rettype = init_integer_type (alloc, 64, 0, "integer*8");
4692 break;
4693 }
4694 negative_types[-typenum] = rettype;
4695 return rettype;
4696 }
4697 \f
4698 /* This page contains subroutines of read_type. */
4699
4700 /* Wrapper around method_name_from_physname to flag a complaint
4701 if there is an error. */
4702
4703 static char *
4704 stabs_method_name_from_physname (const char *physname)
4705 {
4706 char *method_name;
4707
4708 method_name = method_name_from_physname (physname);
4709
4710 if (method_name == NULL)
4711 {
4712 complaint (_("Method has bad physname %s\n"), physname);
4713 return NULL;
4714 }
4715
4716 return method_name;
4717 }
4718
4719 /* Read member function stabs info for C++ classes. The form of each member
4720 function data is:
4721
4722 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
4723
4724 An example with two member functions is:
4725
4726 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
4727
4728 For the case of overloaded operators, the format is op$::*.funcs, where
4729 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
4730 name (such as `+=') and `.' marks the end of the operator name.
4731
4732 Returns 1 for success, 0 for failure. */
4733
4734 static int
4735 read_member_functions (struct stab_field_info *fip, const char **pp,
4736 struct type *type, struct objfile *objfile)
4737 {
4738 int nfn_fields = 0;
4739 int length = 0;
4740 int i;
4741 struct next_fnfield
4742 {
4743 struct next_fnfield *next;
4744 struct fn_field fn_field;
4745 }
4746 *sublist;
4747 struct type *look_ahead_type;
4748 struct next_fnfieldlist *new_fnlist;
4749 struct next_fnfield *new_sublist;
4750 char *main_fn_name;
4751 const char *p;
4752
4753 /* Process each list until we find something that is not a member function
4754 or find the end of the functions. */
4755
4756 while (**pp != ';')
4757 {
4758 /* We should be positioned at the start of the function name.
4759 Scan forward to find the first ':' and if it is not the
4760 first of a "::" delimiter, then this is not a member function. */
4761 p = *pp;
4762 while (*p != ':')
4763 {
4764 p++;
4765 }
4766 if (p[1] != ':')
4767 {
4768 break;
4769 }
4770
4771 sublist = NULL;
4772 look_ahead_type = NULL;
4773 length = 0;
4774
4775 new_fnlist = OBSTACK_ZALLOC (&fip->obstack, struct next_fnfieldlist);
4776
4777 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2]))
4778 {
4779 /* This is a completely weird case. In order to stuff in the
4780 names that might contain colons (the usual name delimiter),
4781 Mike Tiemann defined a different name format which is
4782 signalled if the identifier is "op$". In that case, the
4783 format is "op$::XXXX." where XXXX is the name. This is
4784 used for names like "+" or "=". YUUUUUUUK! FIXME! */
4785 /* This lets the user type "break operator+".
4786 We could just put in "+" as the name, but that wouldn't
4787 work for "*". */
4788 static char opname[32] = "op$";
4789 char *o = opname + 3;
4790
4791 /* Skip past '::'. */
4792 *pp = p + 2;
4793
4794 STABS_CONTINUE (pp, objfile);
4795 p = *pp;
4796 while (*p != '.')
4797 {
4798 *o++ = *p++;
4799 }
4800 main_fn_name = savestring (opname, o - opname);
4801 /* Skip past '.' */
4802 *pp = p + 1;
4803 }
4804 else
4805 {
4806 main_fn_name = savestring (*pp, p - *pp);
4807 /* Skip past '::'. */
4808 *pp = p + 2;
4809 }
4810 new_fnlist->fn_fieldlist.name = main_fn_name;
4811
4812 do
4813 {
4814 new_sublist = OBSTACK_ZALLOC (&fip->obstack, struct next_fnfield);
4815
4816 /* Check for and handle cretinous dbx symbol name continuation! */
4817 if (look_ahead_type == NULL)
4818 {
4819 /* Normal case. */
4820 STABS_CONTINUE (pp, objfile);
4821
4822 new_sublist->fn_field.type = read_type (pp, objfile);
4823 if (**pp != ':')
4824 {
4825 /* Invalid symtab info for member function. */
4826 return 0;
4827 }
4828 }
4829 else
4830 {
4831 /* g++ version 1 kludge */
4832 new_sublist->fn_field.type = look_ahead_type;
4833 look_ahead_type = NULL;
4834 }
4835
4836 (*pp)++;
4837 p = *pp;
4838 while (*p != ';')
4839 {
4840 p++;
4841 }
4842
4843 /* These are methods, not functions. */
4844 if (new_sublist->fn_field.type->code () == TYPE_CODE_FUNC)
4845 new_sublist->fn_field.type->set_code (TYPE_CODE_METHOD);
4846
4847 /* If this is just a stub, then we don't have the real name here. */
4848 if (new_sublist->fn_field.type->is_stub ())
4849 {
4850 if (!TYPE_SELF_TYPE (new_sublist->fn_field.type))
4851 set_type_self_type (new_sublist->fn_field.type, type);
4852 new_sublist->fn_field.is_stub = 1;
4853 }
4854
4855 new_sublist->fn_field.physname = savestring (*pp, p - *pp);
4856 *pp = p + 1;
4857
4858 /* Set this member function's visibility fields. */
4859 switch (*(*pp)++)
4860 {
4861 case VISIBILITY_PRIVATE:
4862 new_sublist->fn_field.accessibility = accessibility::PRIVATE;
4863 break;
4864 case VISIBILITY_PROTECTED:
4865 new_sublist->fn_field.accessibility = accessibility::PROTECTED;
4866 break;
4867 }
4868
4869 STABS_CONTINUE (pp, objfile);
4870 switch (**pp)
4871 {
4872 case 'A': /* Normal functions. */
4873 new_sublist->fn_field.is_const = 0;
4874 new_sublist->fn_field.is_volatile = 0;
4875 (*pp)++;
4876 break;
4877 case 'B': /* `const' member functions. */
4878 new_sublist->fn_field.is_const = 1;
4879 new_sublist->fn_field.is_volatile = 0;
4880 (*pp)++;
4881 break;
4882 case 'C': /* `volatile' member function. */
4883 new_sublist->fn_field.is_const = 0;
4884 new_sublist->fn_field.is_volatile = 1;
4885 (*pp)++;
4886 break;
4887 case 'D': /* `const volatile' member function. */
4888 new_sublist->fn_field.is_const = 1;
4889 new_sublist->fn_field.is_volatile = 1;
4890 (*pp)++;
4891 break;
4892 case '*': /* File compiled with g++ version 1 --
4893 no info. */
4894 case '?':
4895 case '.':
4896 break;
4897 default:
4898 complaint (_("const/volatile indicator missing, got '%c'"),
4899 **pp);
4900 break;
4901 }
4902
4903 switch (*(*pp)++)
4904 {
4905 case '*':
4906 {
4907 int nbits;
4908 /* virtual member function, followed by index.
4909 The sign bit is set to distinguish pointers-to-methods
4910 from virtual function indices. Since the array is
4911 in words, the quantity must be shifted left by 1
4912 on 16 bit machine, and by 2 on 32 bit machine, forcing
4913 the sign bit out, and usable as a valid index into
4914 the array. Remove the sign bit here. */
4915 new_sublist->fn_field.voffset =
4916 (0x7fffffff & read_huge_number (pp, ';', &nbits, 0)) + 2;
4917 if (nbits != 0)
4918 return 0;
4919
4920 STABS_CONTINUE (pp, objfile);
4921 if (**pp == ';' || **pp == '\0')
4922 {
4923 /* Must be g++ version 1. */
4924 new_sublist->fn_field.fcontext = 0;
4925 }
4926 else
4927 {
4928 /* Figure out from whence this virtual function came.
4929 It may belong to virtual function table of
4930 one of its baseclasses. */
4931 look_ahead_type = read_type (pp, objfile);
4932 if (**pp == ':')
4933 {
4934 /* g++ version 1 overloaded methods. */
4935 }
4936 else
4937 {
4938 new_sublist->fn_field.fcontext = look_ahead_type;
4939 if (**pp != ';')
4940 {
4941 return 0;
4942 }
4943 else
4944 {
4945 ++*pp;
4946 }
4947 look_ahead_type = NULL;
4948 }
4949 }
4950 break;
4951 }
4952 case '?':
4953 /* static member function. */
4954 {
4955 int slen = strlen (main_fn_name);
4956
4957 new_sublist->fn_field.voffset = VOFFSET_STATIC;
4958
4959 /* For static member functions, we can't tell if they
4960 are stubbed, as they are put out as functions, and not as
4961 methods.
4962 GCC v2 emits the fully mangled name if
4963 dbxout.c:flag_minimal_debug is not set, so we have to
4964 detect a fully mangled physname here and set is_stub
4965 accordingly. Fully mangled physnames in v2 start with
4966 the member function name, followed by two underscores.
4967 GCC v3 currently always emits stubbed member functions,
4968 but with fully mangled physnames, which start with _Z. */
4969 if (!(strncmp (new_sublist->fn_field.physname,
4970 main_fn_name, slen) == 0
4971 && new_sublist->fn_field.physname[slen] == '_'
4972 && new_sublist->fn_field.physname[slen + 1] == '_'))
4973 {
4974 new_sublist->fn_field.is_stub = 1;
4975 }
4976 break;
4977 }
4978
4979 default:
4980 /* error */
4981 complaint (_("member function type missing, got '%c'"),
4982 (*pp)[-1]);
4983 /* Normal member function. */
4984 [[fallthrough]];
4985
4986 case '.':
4987 /* normal member function. */
4988 new_sublist->fn_field.voffset = 0;
4989 new_sublist->fn_field.fcontext = 0;
4990 break;
4991 }
4992
4993 new_sublist->next = sublist;
4994 sublist = new_sublist;
4995 length++;
4996 STABS_CONTINUE (pp, objfile);
4997 }
4998 while (**pp != ';' && **pp != '\0');
4999
5000 (*pp)++;
5001 STABS_CONTINUE (pp, objfile);
5002
5003 /* Skip GCC 3.X member functions which are duplicates of the callable
5004 constructor/destructor. */
5005 if (strcmp_iw (main_fn_name, "__base_ctor ") == 0
5006 || strcmp_iw (main_fn_name, "__base_dtor ") == 0
5007 || strcmp (main_fn_name, "__deleting_dtor") == 0)
5008 {
5009 xfree (main_fn_name);
5010 }
5011 else
5012 {
5013 int has_destructor = 0, has_other = 0;
5014 int is_v3 = 0;
5015 struct next_fnfield *tmp_sublist;
5016
5017 /* Various versions of GCC emit various mostly-useless
5018 strings in the name field for special member functions.
5019
5020 For stub methods, we need to defer correcting the name
5021 until we are ready to unstub the method, because the current
5022 name string is used by gdb_mangle_name. The only stub methods
5023 of concern here are GNU v2 operators; other methods have their
5024 names correct (see caveat below).
5025
5026 For non-stub methods, in GNU v3, we have a complete physname.
5027 Therefore we can safely correct the name now. This primarily
5028 affects constructors and destructors, whose name will be
5029 __comp_ctor or __comp_dtor instead of Foo or ~Foo. Cast
5030 operators will also have incorrect names; for instance,
5031 "operator int" will be named "operator i" (i.e. the type is
5032 mangled).
5033
5034 For non-stub methods in GNU v2, we have no easy way to
5035 know if we have a complete physname or not. For most
5036 methods the result depends on the platform (if CPLUS_MARKER
5037 can be `$' or `.', it will use minimal debug information, or
5038 otherwise the full physname will be included).
5039
5040 Rather than dealing with this, we take a different approach.
5041 For v3 mangled names, we can use the full physname; for v2,
5042 we use cplus_demangle_opname (which is actually v2 specific),
5043 because the only interesting names are all operators - once again
5044 barring the caveat below. Skip this process if any method in the
5045 group is a stub, to prevent our fouling up the workings of
5046 gdb_mangle_name.
5047
5048 The caveat: GCC 2.95.x (and earlier?) put constructors and
5049 destructors in the same method group. We need to split this
5050 into two groups, because they should have different names.
5051 So for each method group we check whether it contains both
5052 routines whose physname appears to be a destructor (the physnames
5053 for and destructors are always provided, due to quirks in v2
5054 mangling) and routines whose physname does not appear to be a
5055 destructor. If so then we break up the list into two halves.
5056 Even if the constructors and destructors aren't in the same group
5057 the destructor will still lack the leading tilde, so that also
5058 needs to be fixed.
5059
5060 So, to summarize what we expect and handle here:
5061
5062 Given Given Real Real Action
5063 method name physname physname method name
5064
5065 __opi [none] __opi__3Foo operator int opname
5066 [now or later]
5067 Foo _._3Foo _._3Foo ~Foo separate and
5068 rename
5069 operator i _ZN3FoocviEv _ZN3FoocviEv operator int demangle
5070 __comp_ctor _ZN3FooC1ERKS_ _ZN3FooC1ERKS_ Foo demangle
5071 */
5072
5073 tmp_sublist = sublist;
5074 while (tmp_sublist != NULL)
5075 {
5076 if (tmp_sublist->fn_field.physname[0] == '_'
5077 && tmp_sublist->fn_field.physname[1] == 'Z')
5078 is_v3 = 1;
5079
5080 if (is_destructor_name (tmp_sublist->fn_field.physname))
5081 has_destructor++;
5082 else
5083 has_other++;
5084
5085 tmp_sublist = tmp_sublist->next;
5086 }
5087
5088 if (has_destructor && has_other)
5089 {
5090 struct next_fnfieldlist *destr_fnlist;
5091 struct next_fnfield *last_sublist;
5092
5093 /* Create a new fn_fieldlist for the destructors. */
5094
5095 destr_fnlist = OBSTACK_ZALLOC (&fip->obstack,
5096 struct next_fnfieldlist);
5097
5098 destr_fnlist->fn_fieldlist.name
5099 = obconcat (&objfile->objfile_obstack, "~",
5100 new_fnlist->fn_fieldlist.name, (char *) NULL);
5101
5102 destr_fnlist->fn_fieldlist.fn_fields =
5103 XOBNEWVEC (&objfile->objfile_obstack,
5104 struct fn_field, has_destructor);
5105 memset (destr_fnlist->fn_fieldlist.fn_fields, 0,
5106 sizeof (struct fn_field) * has_destructor);
5107 tmp_sublist = sublist;
5108 last_sublist = NULL;
5109 i = 0;
5110 while (tmp_sublist != NULL)
5111 {
5112 if (!is_destructor_name (tmp_sublist->fn_field.physname))
5113 {
5114 tmp_sublist = tmp_sublist->next;
5115 continue;
5116 }
5117
5118 destr_fnlist->fn_fieldlist.fn_fields[i++]
5119 = tmp_sublist->fn_field;
5120 if (last_sublist)
5121 last_sublist->next = tmp_sublist->next;
5122 else
5123 sublist = tmp_sublist->next;
5124 last_sublist = tmp_sublist;
5125 tmp_sublist = tmp_sublist->next;
5126 }
5127
5128 destr_fnlist->fn_fieldlist.length = has_destructor;
5129 destr_fnlist->next = fip->fnlist;
5130 fip->fnlist = destr_fnlist;
5131 nfn_fields++;
5132 length -= has_destructor;
5133 }
5134 else if (is_v3)
5135 {
5136 /* v3 mangling prevents the use of abbreviated physnames,
5137 so we can do this here. There are stubbed methods in v3
5138 only:
5139 - in -gstabs instead of -gstabs+
5140 - or for static methods, which are output as a function type
5141 instead of a method type. */
5142 char *new_method_name =
5143 stabs_method_name_from_physname (sublist->fn_field.physname);
5144
5145 if (new_method_name != NULL
5146 && strcmp (new_method_name,
5147 new_fnlist->fn_fieldlist.name) != 0)
5148 {
5149 new_fnlist->fn_fieldlist.name = new_method_name;
5150 xfree (main_fn_name);
5151 }
5152 else
5153 xfree (new_method_name);
5154 }
5155 else if (has_destructor && new_fnlist->fn_fieldlist.name[0] != '~')
5156 {
5157 new_fnlist->fn_fieldlist.name =
5158 obconcat (&objfile->objfile_obstack,
5159 "~", main_fn_name, (char *)NULL);
5160 xfree (main_fn_name);
5161 }
5162
5163 new_fnlist->fn_fieldlist.fn_fields
5164 = OBSTACK_CALLOC (&objfile->objfile_obstack, length, fn_field);
5165 for (i = length; (i--, sublist); sublist = sublist->next)
5166 {
5167 new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
5168 }
5169
5170 new_fnlist->fn_fieldlist.length = length;
5171 new_fnlist->next = fip->fnlist;
5172 fip->fnlist = new_fnlist;
5173 nfn_fields++;
5174 }
5175 }
5176
5177 if (nfn_fields)
5178 {
5179 ALLOCATE_CPLUS_STRUCT_TYPE (type);
5180 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
5181 TYPE_ZALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
5182 TYPE_NFN_FIELDS (type) = nfn_fields;
5183 }
5184
5185 return 1;
5186 }
5187
5188 /* Special GNU C++ name.
5189
5190 Returns 1 for success, 0 for failure. "failure" means that we can't
5191 keep parsing and it's time for error_type(). */
5192
5193 static int
5194 read_cpp_abbrev (struct stab_field_info *fip, const char **pp,
5195 struct type *type, struct objfile *objfile)
5196 {
5197 const char *p;
5198 const char *name;
5199 char cpp_abbrev;
5200 struct type *context;
5201
5202 p = *pp;
5203 if (*++p == 'v')
5204 {
5205 name = NULL;
5206 cpp_abbrev = *++p;
5207
5208 *pp = p + 1;
5209
5210 /* At this point, *pp points to something like "22:23=*22...",
5211 where the type number before the ':' is the "context" and
5212 everything after is a regular type definition. Lookup the
5213 type, find it's name, and construct the field name. */
5214
5215 context = read_type (pp, objfile);
5216
5217 switch (cpp_abbrev)
5218 {
5219 case 'f': /* $vf -- a virtual function table pointer */
5220 name = context->name ();
5221 if (name == NULL)
5222 {
5223 name = "";
5224 }
5225 fip->list->field.set_name (obconcat (&objfile->objfile_obstack,
5226 vptr_name, name, (char *) NULL));
5227 break;
5228
5229 case 'b': /* $vb -- a virtual bsomethingorother */
5230 name = context->name ();
5231 if (name == NULL)
5232 {
5233 complaint (_("C++ abbreviated type name "
5234 "unknown at symtab pos %d"),
5235 symnum);
5236 name = "FOO";
5237 }
5238 fip->list->field.set_name (obconcat (&objfile->objfile_obstack,
5239 vb_name, name, (char *) NULL));
5240 break;
5241
5242 default:
5243 invalid_cpp_abbrev_complaint (*pp);
5244 fip->list->field.set_name (obconcat (&objfile->objfile_obstack,
5245 "INVALID_CPLUSPLUS_ABBREV",
5246 (char *) NULL));
5247 break;
5248 }
5249
5250 /* At this point, *pp points to the ':'. Skip it and read the
5251 field type. */
5252
5253 p = ++(*pp);
5254 if (p[-1] != ':')
5255 {
5256 invalid_cpp_abbrev_complaint (*pp);
5257 return 0;
5258 }
5259 fip->list->field.set_type (read_type (pp, objfile));
5260 if (**pp == ',')
5261 (*pp)++; /* Skip the comma. */
5262 else
5263 return 0;
5264
5265 {
5266 int nbits;
5267
5268 fip->list->field.set_loc_bitpos (read_huge_number (pp, ';', &nbits, 0));
5269 if (nbits != 0)
5270 return 0;
5271 }
5272 /* This field is unpacked. */
5273 fip->list->field.set_bitsize (0);
5274 fip->list->field.set_accessibility (accessibility::PRIVATE);
5275 }
5276 else
5277 {
5278 invalid_cpp_abbrev_complaint (*pp);
5279 /* We have no idea what syntax an unrecognized abbrev would have, so
5280 better return 0. If we returned 1, we would need to at least advance
5281 *pp to avoid an infinite loop. */
5282 return 0;
5283 }
5284 return 1;
5285 }
5286
5287 static void
5288 read_one_struct_field (struct stab_field_info *fip, const char **pp,
5289 const char *p, struct type *type,
5290 struct objfile *objfile)
5291 {
5292 struct gdbarch *gdbarch = objfile->arch ();
5293
5294 fip->list->field.set_name
5295 (obstack_strndup (&objfile->objfile_obstack, *pp, p - *pp));
5296 *pp = p + 1;
5297
5298 /* This means we have a visibility for a field coming. */
5299 int visibility;
5300 if (**pp == '/')
5301 {
5302 (*pp)++;
5303 visibility = *(*pp)++;
5304 }
5305 else
5306 {
5307 /* normal dbx-style format, no explicit visibility */
5308 visibility = VISIBILITY_PUBLIC;
5309 }
5310
5311 switch (visibility)
5312 {
5313 case VISIBILITY_PRIVATE:
5314 fip->list->field.set_accessibility (accessibility::PRIVATE);
5315 break;
5316
5317 case VISIBILITY_PROTECTED:
5318 fip->list->field.set_accessibility (accessibility::PROTECTED);
5319 break;
5320
5321 case VISIBILITY_IGNORE:
5322 fip->list->field.set_ignored ();
5323 break;
5324
5325 case VISIBILITY_PUBLIC:
5326 break;
5327
5328 default:
5329 /* Unknown visibility. Complain and treat it as public. */
5330 {
5331 complaint (_("Unknown visibility `%c' for field"),
5332 visibility);
5333 }
5334 break;
5335 }
5336
5337 fip->list->field.set_type (read_type (pp, objfile));
5338 if (**pp == ':')
5339 {
5340 p = ++(*pp);
5341 #if 0
5342 /* Possible future hook for nested types. */
5343 if (**pp == '!')
5344 {
5345 fip->list->field.bitpos = (long) -2; /* nested type */
5346 p = ++(*pp);
5347 }
5348 else
5349 ...;
5350 #endif
5351 while (*p != ';')
5352 {
5353 p++;
5354 }
5355 /* Static class member. */
5356 fip->list->field.set_loc_physname (savestring (*pp, p - *pp));
5357 *pp = p + 1;
5358 return;
5359 }
5360 else if (**pp != ',')
5361 {
5362 /* Bad structure-type format. */
5363 stabs_general_complaint ("bad structure-type format");
5364 return;
5365 }
5366
5367 (*pp)++; /* Skip the comma. */
5368
5369 {
5370 int nbits;
5371
5372 fip->list->field.set_loc_bitpos (read_huge_number (pp, ',', &nbits, 0));
5373 if (nbits != 0)
5374 {
5375 stabs_general_complaint ("bad structure-type format");
5376 return;
5377 }
5378 fip->list->field.set_bitsize (read_huge_number (pp, ';', &nbits, 0));
5379 if (nbits != 0)
5380 {
5381 stabs_general_complaint ("bad structure-type format");
5382 return;
5383 }
5384 }
5385
5386 if (fip->list->field.loc_bitpos () == 0
5387 && fip->list->field.bitsize () == 0)
5388 {
5389 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
5390 it is a field which has been optimized out. The correct stab for
5391 this case is to use VISIBILITY_IGNORE, but that is a recent
5392 invention. (2) It is a 0-size array. For example
5393 union { int num; char str[0]; } foo. Printing _("<no value>" for
5394 str in "p foo" is OK, since foo.str (and thus foo.str[3])
5395 will continue to work, and a 0-size array as a whole doesn't
5396 have any contents to print.
5397
5398 I suspect this probably could also happen with gcc -gstabs (not
5399 -gstabs+) for static fields, and perhaps other C++ extensions.
5400 Hopefully few people use -gstabs with gdb, since it is intended
5401 for dbx compatibility. */
5402
5403 /* Ignore this field. */
5404 fip->list->field.set_ignored ();
5405 }
5406 else
5407 {
5408 /* Detect an unpacked field and mark it as such.
5409 dbx gives a bit size for all fields.
5410 Note that forward refs cannot be packed,
5411 and treat enums as if they had the width of ints. */
5412
5413 struct type *field_type = check_typedef (fip->list->field.type ());
5414
5415 if (field_type->code () != TYPE_CODE_INT
5416 && field_type->code () != TYPE_CODE_RANGE
5417 && field_type->code () != TYPE_CODE_BOOL
5418 && field_type->code () != TYPE_CODE_ENUM)
5419 {
5420 fip->list->field.set_bitsize (0);
5421 }
5422 if ((fip->list->field.bitsize ()
5423 == TARGET_CHAR_BIT * field_type->length ()
5424 || (field_type->code () == TYPE_CODE_ENUM
5425 && (fip->list->field.bitsize ()
5426 == gdbarch_int_bit (gdbarch)))
5427 )
5428 &&
5429 fip->list->field.loc_bitpos () % 8 == 0)
5430 {
5431 fip->list->field.set_bitsize (0);
5432 }
5433 }
5434 }
5435
5436
5437 /* Read struct or class data fields. They have the form:
5438
5439 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
5440
5441 At the end, we see a semicolon instead of a field.
5442
5443 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
5444 a static field.
5445
5446 The optional VISIBILITY is one of:
5447
5448 '/0' (VISIBILITY_PRIVATE)
5449 '/1' (VISIBILITY_PROTECTED)
5450 '/2' (VISIBILITY_PUBLIC)
5451 '/9' (VISIBILITY_IGNORE)
5452
5453 or nothing, for C style fields with public visibility.
5454
5455 Returns 1 for success, 0 for failure. */
5456
5457 static int
5458 read_struct_fields (struct stab_field_info *fip, const char **pp,
5459 struct type *type, struct objfile *objfile)
5460 {
5461 const char *p;
5462 struct stabs_nextfield *newobj;
5463
5464 /* We better set p right now, in case there are no fields at all... */
5465
5466 p = *pp;
5467
5468 /* Read each data member type until we find the terminating ';' at the end of
5469 the data member list, or break for some other reason such as finding the
5470 start of the member function list. */
5471 /* Stab string for structure/union does not end with two ';' in
5472 SUN C compiler 5.3 i.e. F6U2, hence check for end of string. */
5473
5474 while (**pp != ';' && **pp != '\0')
5475 {
5476 STABS_CONTINUE (pp, objfile);
5477 /* Get space to record the next field's data. */
5478 newobj = OBSTACK_ZALLOC (&fip->obstack, struct stabs_nextfield);
5479
5480 newobj->next = fip->list;
5481 fip->list = newobj;
5482
5483 /* Get the field name. */
5484 p = *pp;
5485
5486 /* If is starts with CPLUS_MARKER it is a special abbreviation,
5487 unless the CPLUS_MARKER is followed by an underscore, in
5488 which case it is just the name of an anonymous type, which we
5489 should handle like any other type name. */
5490
5491 if (is_cplus_marker (p[0]) && p[1] != '_')
5492 {
5493 if (!read_cpp_abbrev (fip, pp, type, objfile))
5494 return 0;
5495 continue;
5496 }
5497
5498 /* Look for the ':' that separates the field name from the field
5499 values. Data members are delimited by a single ':', while member
5500 functions are delimited by a pair of ':'s. When we hit the member
5501 functions (if any), terminate scan loop and return. */
5502
5503 while (*p != ':' && *p != '\0')
5504 {
5505 p++;
5506 }
5507 if (*p == '\0')
5508 return 0;
5509
5510 /* Check to see if we have hit the member functions yet. */
5511 if (p[1] == ':')
5512 {
5513 break;
5514 }
5515 read_one_struct_field (fip, pp, p, type, objfile);
5516 }
5517 if (p[0] == ':' && p[1] == ':')
5518 {
5519 /* (the deleted) chill the list of fields: the last entry (at
5520 the head) is a partially constructed entry which we now
5521 scrub. */
5522 fip->list = fip->list->next;
5523 }
5524 return 1;
5525 }
5526 /* The stabs for C++ derived classes contain baseclass information which
5527 is marked by a '!' character after the total size. This function is
5528 called when we encounter the baseclass marker, and slurps up all the
5529 baseclass information.
5530
5531 Immediately following the '!' marker is the number of base classes that
5532 the class is derived from, followed by information for each base class.
5533 For each base class, there are two visibility specifiers, a bit offset
5534 to the base class information within the derived class, a reference to
5535 the type for the base class, and a terminating semicolon.
5536
5537 A typical example, with two base classes, would be "!2,020,19;0264,21;".
5538 ^^ ^ ^ ^ ^ ^ ^
5539 Baseclass information marker __________________|| | | | | | |
5540 Number of baseclasses __________________________| | | | | | |
5541 Visibility specifiers (2) ________________________| | | | | |
5542 Offset in bits from start of class _________________| | | | |
5543 Type number for base class ___________________________| | | |
5544 Visibility specifiers (2) _______________________________| | |
5545 Offset in bits from start of class ________________________| |
5546 Type number of base class ____________________________________|
5547
5548 Return 1 for success, 0 for (error-type-inducing) failure. */
5549
5550
5551
5552 static int
5553 read_baseclasses (struct stab_field_info *fip, const char **pp,
5554 struct type *type, struct objfile *objfile)
5555 {
5556 int i;
5557 struct stabs_nextfield *newobj;
5558
5559 if (**pp != '!')
5560 {
5561 return 1;
5562 }
5563 else
5564 {
5565 /* Skip the '!' baseclass information marker. */
5566 (*pp)++;
5567 }
5568
5569 ALLOCATE_CPLUS_STRUCT_TYPE (type);
5570 {
5571 int nbits;
5572
5573 TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits, 0);
5574 if (nbits != 0)
5575 return 0;
5576 }
5577
5578 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
5579 {
5580 newobj = OBSTACK_ZALLOC (&fip->obstack, struct stabs_nextfield);
5581
5582 newobj->next = fip->list;
5583 fip->list = newobj;
5584 newobj->field.set_bitsize (0); /* This should be an unpacked
5585 field! */
5586
5587 STABS_CONTINUE (pp, objfile);
5588 switch (**pp)
5589 {
5590 case '0':
5591 /* Nothing to do. */
5592 break;
5593 case '1':
5594 newobj->field.set_virtual ();
5595 break;
5596 default:
5597 /* Unknown character. Complain and treat it as non-virtual. */
5598 {
5599 complaint (_("Unknown virtual character `%c' for baseclass"),
5600 **pp);
5601 }
5602 }
5603 ++(*pp);
5604
5605 int visibility = *(*pp)++;
5606 switch (visibility)
5607 {
5608 case VISIBILITY_PRIVATE:
5609 newobj->field.set_accessibility (accessibility::PRIVATE);
5610 break;
5611 case VISIBILITY_PROTECTED:
5612 newobj->field.set_accessibility (accessibility::PROTECTED);
5613 break;
5614 case VISIBILITY_PUBLIC:
5615 break;
5616 default:
5617 /* Bad visibility format. Complain and treat it as
5618 public. */
5619 {
5620 complaint (_("Unknown visibility `%c' for baseclass"),
5621 visibility);
5622 }
5623 }
5624
5625 {
5626 int nbits;
5627
5628 /* The remaining value is the bit offset of the portion of the object
5629 corresponding to this baseclass. Always zero in the absence of
5630 multiple inheritance. */
5631
5632 newobj->field.set_loc_bitpos (read_huge_number (pp, ',', &nbits, 0));
5633 if (nbits != 0)
5634 return 0;
5635 }
5636
5637 /* The last piece of baseclass information is the type of the
5638 base class. Read it, and remember it's type name as this
5639 field's name. */
5640
5641 newobj->field.set_type (read_type (pp, objfile));
5642 newobj->field.set_name (newobj->field.type ()->name ());
5643
5644 /* Skip trailing ';' and bump count of number of fields seen. */
5645 if (**pp == ';')
5646 (*pp)++;
5647 else
5648 return 0;
5649 }
5650 return 1;
5651 }
5652
5653 /* The tail end of stabs for C++ classes that contain a virtual function
5654 pointer contains a tilde, a %, and a type number.
5655 The type number refers to the base class (possibly this class itself) which
5656 contains the vtable pointer for the current class.
5657
5658 This function is called when we have parsed all the method declarations,
5659 so we can look for the vptr base class info. */
5660
5661 static int
5662 read_tilde_fields (struct stab_field_info *fip, const char **pp,
5663 struct type *type, struct objfile *objfile)
5664 {
5665 const char *p;
5666
5667 STABS_CONTINUE (pp, objfile);
5668
5669 /* If we are positioned at a ';', then skip it. */
5670 if (**pp == ';')
5671 {
5672 (*pp)++;
5673 }
5674
5675 if (**pp == '~')
5676 {
5677 (*pp)++;
5678
5679 if (**pp == '=' || **pp == '+' || **pp == '-')
5680 {
5681 /* Obsolete flags that used to indicate the presence
5682 of constructors and/or destructors. */
5683 (*pp)++;
5684 }
5685
5686 /* Read either a '%' or the final ';'. */
5687 if (*(*pp)++ == '%')
5688 {
5689 /* The next number is the type number of the base class
5690 (possibly our own class) which supplies the vtable for
5691 this class. Parse it out, and search that class to find
5692 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
5693 and TYPE_VPTR_FIELDNO. */
5694
5695 struct type *t;
5696 int i;
5697
5698 t = read_type (pp, objfile);
5699 p = (*pp)++;
5700 while (*p != '\0' && *p != ';')
5701 {
5702 p++;
5703 }
5704 if (*p == '\0')
5705 {
5706 /* Premature end of symbol. */
5707 return 0;
5708 }
5709
5710 set_type_vptr_basetype (type, t);
5711 if (type == t) /* Our own class provides vtbl ptr. */
5712 {
5713 for (i = t->num_fields () - 1;
5714 i >= TYPE_N_BASECLASSES (t);
5715 --i)
5716 {
5717 const char *name = t->field (i).name ();
5718
5719 if (!strncmp (name, vptr_name, sizeof (vptr_name) - 2)
5720 && is_cplus_marker (name[sizeof (vptr_name) - 2]))
5721 {
5722 set_type_vptr_fieldno (type, i);
5723 goto gotit;
5724 }
5725 }
5726 /* Virtual function table field not found. */
5727 complaint (_("virtual function table pointer "
5728 "not found when defining class `%s'"),
5729 type->name ());
5730 return 0;
5731 }
5732 else
5733 {
5734 set_type_vptr_fieldno (type, TYPE_VPTR_FIELDNO (t));
5735 }
5736
5737 gotit:
5738 *pp = p + 1;
5739 }
5740 }
5741 return 1;
5742 }
5743
5744 static int
5745 attach_fn_fields_to_type (struct stab_field_info *fip, struct type *type)
5746 {
5747 int n;
5748
5749 for (n = TYPE_NFN_FIELDS (type);
5750 fip->fnlist != NULL;
5751 fip->fnlist = fip->fnlist->next)
5752 {
5753 --n; /* Circumvent Sun3 compiler bug. */
5754 TYPE_FN_FIELDLISTS (type)[n] = fip->fnlist->fn_fieldlist;
5755 }
5756 return 1;
5757 }
5758
5759 /* Create the vector of fields, and record how big it is.
5760 We need this info to record proper virtual function table information
5761 for this class's virtual functions. */
5762
5763 static int
5764 attach_fields_to_type (struct stab_field_info *fip, struct type *type,
5765 struct objfile *objfile)
5766 {
5767 int nfields = 0;
5768 struct stabs_nextfield *scan;
5769
5770 /* Count up the number of fields that we have. */
5771
5772 for (scan = fip->list; scan != NULL; scan = scan->next)
5773 nfields++;
5774
5775 /* Now we know how many fields there are, and whether or not there are any
5776 non-public fields. Record the field count, allocate space for the
5777 array of fields. */
5778
5779 type->alloc_fields (nfields);
5780
5781 /* Copy the saved-up fields into the field vector. Start from the
5782 head of the list, adding to the tail of the field array, so that
5783 they end up in the same order in the array in which they were
5784 added to the list. */
5785
5786 while (nfields-- > 0)
5787 {
5788 type->field (nfields) = fip->list->field;
5789 fip->list = fip->list->next;
5790 }
5791 return 1;
5792 }
5793
5794
5795 /* Complain that the compiler has emitted more than one definition for the
5796 structure type TYPE. */
5797 static void
5798 complain_about_struct_wipeout (struct type *type)
5799 {
5800 const char *name = "";
5801 const char *kind = "";
5802
5803 if (type->name ())
5804 {
5805 name = type->name ();
5806 switch (type->code ())
5807 {
5808 case TYPE_CODE_STRUCT: kind = "struct "; break;
5809 case TYPE_CODE_UNION: kind = "union "; break;
5810 case TYPE_CODE_ENUM: kind = "enum "; break;
5811 default: kind = "";
5812 }
5813 }
5814 else
5815 {
5816 name = "<unknown>";
5817 kind = "";
5818 }
5819
5820 complaint (_("struct/union type gets multiply defined: %s%s"), kind, name);
5821 }
5822
5823 /* Set the length for all variants of a same main_type, which are
5824 connected in the closed chain.
5825
5826 This is something that needs to be done when a type is defined *after*
5827 some cross references to this type have already been read. Consider
5828 for instance the following scenario where we have the following two
5829 stabs entries:
5830
5831 .stabs "t:p(0,21)=*(0,22)=k(0,23)=xsdummy:",160,0,28,-24
5832 .stabs "dummy:T(0,23)=s16x:(0,1),0,3[...]"
5833
5834 A stubbed version of type dummy is created while processing the first
5835 stabs entry. The length of that type is initially set to zero, since
5836 it is unknown at this point. Also, a "constant" variation of type
5837 "dummy" is created as well (this is the "(0,22)=k(0,23)" section of
5838 the stabs line).
5839
5840 The second stabs entry allows us to replace the stubbed definition
5841 with the real definition. However, we still need to adjust the length
5842 of the "constant" variation of that type, as its length was left
5843 untouched during the main type replacement... */
5844
5845 static void
5846 set_length_in_type_chain (struct type *type)
5847 {
5848 struct type *ntype = TYPE_CHAIN (type);
5849
5850 while (ntype != type)
5851 {
5852 if (ntype->length () == 0)
5853 ntype->set_length (type->length ());
5854 else
5855 complain_about_struct_wipeout (ntype);
5856 ntype = TYPE_CHAIN (ntype);
5857 }
5858 }
5859
5860 /* Read the description of a structure (or union type) and return an object
5861 describing the type.
5862
5863 PP points to a character pointer that points to the next unconsumed token
5864 in the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
5865 *PP will point to "4a:1,0,32;;".
5866
5867 TYPE points to an incomplete type that needs to be filled in.
5868
5869 OBJFILE points to the current objfile from which the stabs information is
5870 being read. (Note that it is redundant in that TYPE also contains a pointer
5871 to this same objfile, so it might be a good idea to eliminate it. FIXME).
5872 */
5873
5874 static struct type *
5875 read_struct_type (const char **pp, struct type *type, enum type_code type_code,
5876 struct objfile *objfile)
5877 {
5878 struct stab_field_info fi;
5879
5880 /* When describing struct/union/class types in stabs, G++ always drops
5881 all qualifications from the name. So if you've got:
5882 struct A { ... struct B { ... }; ... };
5883 then G++ will emit stabs for `struct A::B' that call it simply
5884 `struct B'. Obviously, if you've got a real top-level definition for
5885 `struct B', or other nested definitions, this is going to cause
5886 problems.
5887
5888 Obviously, GDB can't fix this by itself, but it can at least avoid
5889 scribbling on existing structure type objects when new definitions
5890 appear. */
5891 if (! (type->code () == TYPE_CODE_UNDEF
5892 || type->is_stub ()))
5893 {
5894 complain_about_struct_wipeout (type);
5895
5896 /* It's probably best to return the type unchanged. */
5897 return type;
5898 }
5899
5900 INIT_CPLUS_SPECIFIC (type);
5901 type->set_code (type_code);
5902 type->set_is_stub (false);
5903
5904 /* First comes the total size in bytes. */
5905
5906 {
5907 int nbits;
5908
5909 type->set_length (read_huge_number (pp, 0, &nbits, 0));
5910 if (nbits != 0)
5911 return error_type (pp, objfile);
5912 set_length_in_type_chain (type);
5913 }
5914
5915 /* Now read the baseclasses, if any, read the regular C struct or C++
5916 class member fields, attach the fields to the type, read the C++
5917 member functions, attach them to the type, and then read any tilde
5918 field (baseclass specifier for the class holding the main vtable). */
5919
5920 if (!read_baseclasses (&fi, pp, type, objfile)
5921 || !read_struct_fields (&fi, pp, type, objfile)
5922 || !attach_fields_to_type (&fi, type, objfile)
5923 || !read_member_functions (&fi, pp, type, objfile)
5924 || !attach_fn_fields_to_type (&fi, type)
5925 || !read_tilde_fields (&fi, pp, type, objfile))
5926 {
5927 type = error_type (pp, objfile);
5928 }
5929
5930 return (type);
5931 }
5932
5933 /* Read a definition of an array type,
5934 and create and return a suitable type object.
5935 Also creates a range type which represents the bounds of that
5936 array. */
5937
5938 static struct type *
5939 read_array_type (const char **pp, struct type *type,
5940 struct objfile *objfile)
5941 {
5942 struct type *index_type, *element_type, *range_type;
5943 int lower, upper;
5944 int adjustable = 0;
5945 int nbits;
5946
5947 /* Format of an array type:
5948 "ar<index type>;lower;upper;<array_contents_type>".
5949 OS9000: "arlower,upper;<array_contents_type>".
5950
5951 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
5952 for these, produce a type like float[][]. */
5953
5954 {
5955 index_type = read_type (pp, objfile);
5956 if (**pp != ';')
5957 /* Improper format of array type decl. */
5958 return error_type (pp, objfile);
5959 ++*pp;
5960 }
5961
5962 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
5963 {
5964 (*pp)++;
5965 adjustable = 1;
5966 }
5967 lower = read_huge_number (pp, ';', &nbits, 0);
5968
5969 if (nbits != 0)
5970 return error_type (pp, objfile);
5971
5972 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
5973 {
5974 (*pp)++;
5975 adjustable = 1;
5976 }
5977 upper = read_huge_number (pp, ';', &nbits, 0);
5978 if (nbits != 0)
5979 return error_type (pp, objfile);
5980
5981 element_type = read_type (pp, objfile);
5982
5983 if (adjustable)
5984 {
5985 lower = 0;
5986 upper = -1;
5987 }
5988
5989 type_allocator alloc (objfile, get_current_subfile ()->language);
5990 range_type =
5991 create_static_range_type (alloc, index_type, lower, upper);
5992 type_allocator smash_alloc (type, type_allocator::SMASH);
5993 type = create_array_type (smash_alloc, element_type, range_type);
5994
5995 return type;
5996 }
5997
5998
5999 /* Read a definition of an enumeration type,
6000 and create and return a suitable type object.
6001 Also defines the symbols that represent the values of the type. */
6002
6003 static struct type *
6004 read_enum_type (const char **pp, struct type *type,
6005 struct objfile *objfile)
6006 {
6007 struct gdbarch *gdbarch = objfile->arch ();
6008 const char *p;
6009 char *name;
6010 long n;
6011 struct symbol *sym;
6012 int nsyms = 0;
6013 struct pending **symlist;
6014 struct pending *osyms, *syms;
6015 int o_nsyms;
6016 int nbits;
6017 int unsigned_enum = 1;
6018
6019 #if 0
6020 /* FIXME! The stabs produced by Sun CC merrily define things that ought
6021 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
6022 to do? For now, force all enum values to file scope. */
6023 if (within_function)
6024 symlist = get_local_symbols ();
6025 else
6026 #endif
6027 symlist = get_file_symbols ();
6028 osyms = *symlist;
6029 o_nsyms = osyms ? osyms->nsyms : 0;
6030
6031 /* The aix4 compiler emits an extra field before the enum members;
6032 my guess is it's a type of some sort. Just ignore it. */
6033 if (**pp == '-')
6034 {
6035 /* Skip over the type. */
6036 while (**pp != ':')
6037 (*pp)++;
6038
6039 /* Skip over the colon. */
6040 (*pp)++;
6041 }
6042
6043 /* Read the value-names and their values.
6044 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
6045 A semicolon or comma instead of a NAME means the end. */
6046 while (**pp && **pp != ';' && **pp != ',')
6047 {
6048 STABS_CONTINUE (pp, objfile);
6049 p = *pp;
6050 while (*p != ':')
6051 p++;
6052 name = obstack_strndup (&objfile->objfile_obstack, *pp, p - *pp);
6053 *pp = p + 1;
6054 n = read_huge_number (pp, ',', &nbits, 0);
6055 if (nbits != 0)
6056 return error_type (pp, objfile);
6057
6058 sym = new (&objfile->objfile_obstack) symbol;
6059 sym->set_linkage_name (name);
6060 sym->set_language (get_current_subfile ()->language,
6061 &objfile->objfile_obstack);
6062 sym->set_aclass_index (LOC_CONST);
6063 sym->set_domain (VAR_DOMAIN);
6064 sym->set_value_longest (n);
6065 if (n < 0)
6066 unsigned_enum = 0;
6067 add_symbol_to_list (sym, symlist);
6068 nsyms++;
6069 }
6070
6071 if (**pp == ';')
6072 (*pp)++; /* Skip the semicolon. */
6073
6074 /* Now fill in the fields of the type-structure. */
6075
6076 type->set_length (gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT);
6077 set_length_in_type_chain (type);
6078 type->set_code (TYPE_CODE_ENUM);
6079 type->set_is_stub (false);
6080 if (unsigned_enum)
6081 type->set_is_unsigned (true);
6082 type->alloc_fields (nsyms);
6083
6084 /* Find the symbols for the values and put them into the type.
6085 The symbols can be found in the symlist that we put them on
6086 to cause them to be defined. osyms contains the old value
6087 of that symlist; everything up to there was defined by us. */
6088 /* Note that we preserve the order of the enum constants, so
6089 that in something like "enum {FOO, LAST_THING=FOO}" we print
6090 FOO, not LAST_THING. */
6091
6092 for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next)
6093 {
6094 int last = syms == osyms ? o_nsyms : 0;
6095 int j = syms->nsyms;
6096
6097 for (; --j >= last; --n)
6098 {
6099 struct symbol *xsym = syms->symbol[j];
6100
6101 xsym->set_type (type);
6102 type->field (n).set_name (xsym->linkage_name ());
6103 type->field (n).set_loc_enumval (xsym->value_longest ());
6104 type->field (n).set_bitsize (0);
6105 }
6106 if (syms == osyms)
6107 break;
6108 }
6109
6110 return type;
6111 }
6112
6113 /* Sun's ACC uses a somewhat saner method for specifying the builtin
6114 typedefs in every file (for int, long, etc):
6115
6116 type = b <signed> <width> <format type>; <offset>; <nbits>
6117 signed = u or s.
6118 optional format type = c or b for char or boolean.
6119 offset = offset from high order bit to start bit of type.
6120 width is # bytes in object of this type, nbits is # bits in type.
6121
6122 The width/offset stuff appears to be for small objects stored in
6123 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
6124 FIXME. */
6125
6126 static struct type *
6127 read_sun_builtin_type (const char **pp, int typenums[2], struct objfile *objfile)
6128 {
6129 int type_bits;
6130 int nbits;
6131 int unsigned_type;
6132 int boolean_type = 0;
6133
6134 switch (**pp)
6135 {
6136 case 's':
6137 unsigned_type = 0;
6138 break;
6139 case 'u':
6140 unsigned_type = 1;
6141 break;
6142 default:
6143 return error_type (pp, objfile);
6144 }
6145 (*pp)++;
6146
6147 /* For some odd reason, all forms of char put a c here. This is strange
6148 because no other type has this honor. We can safely ignore this because
6149 we actually determine 'char'acterness by the number of bits specified in
6150 the descriptor.
6151 Boolean forms, e.g Fortran logical*X, put a b here. */
6152
6153 if (**pp == 'c')
6154 (*pp)++;
6155 else if (**pp == 'b')
6156 {
6157 boolean_type = 1;
6158 (*pp)++;
6159 }
6160
6161 /* The first number appears to be the number of bytes occupied
6162 by this type, except that unsigned short is 4 instead of 2.
6163 Since this information is redundant with the third number,
6164 we will ignore it. */
6165 read_huge_number (pp, ';', &nbits, 0);
6166 if (nbits != 0)
6167 return error_type (pp, objfile);
6168
6169 /* The second number is always 0, so ignore it too. */
6170 read_huge_number (pp, ';', &nbits, 0);
6171 if (nbits != 0)
6172 return error_type (pp, objfile);
6173
6174 /* The third number is the number of bits for this type. */
6175 type_bits = read_huge_number (pp, 0, &nbits, 0);
6176 if (nbits != 0)
6177 return error_type (pp, objfile);
6178 /* The type *should* end with a semicolon. If it are embedded
6179 in a larger type the semicolon may be the only way to know where
6180 the type ends. If this type is at the end of the stabstring we
6181 can deal with the omitted semicolon (but we don't have to like
6182 it). Don't bother to complain(), Sun's compiler omits the semicolon
6183 for "void". */
6184 if (**pp == ';')
6185 ++(*pp);
6186
6187 type_allocator alloc (objfile, get_current_subfile ()->language);
6188 if (type_bits == 0)
6189 {
6190 struct type *type = alloc.new_type (TYPE_CODE_VOID,
6191 TARGET_CHAR_BIT, nullptr);
6192 if (unsigned_type)
6193 type->set_is_unsigned (true);
6194
6195 return type;
6196 }
6197
6198 if (boolean_type)
6199 return init_boolean_type (alloc, type_bits, unsigned_type, NULL);
6200 else
6201 return init_integer_type (alloc, type_bits, unsigned_type, NULL);
6202 }
6203
6204 static struct type *
6205 read_sun_floating_type (const char **pp, int typenums[2],
6206 struct objfile *objfile)
6207 {
6208 int nbits;
6209 int details;
6210 int nbytes;
6211 struct type *rettype;
6212
6213 /* The first number has more details about the type, for example
6214 FN_COMPLEX. */
6215 details = read_huge_number (pp, ';', &nbits, 0);
6216 if (nbits != 0)
6217 return error_type (pp, objfile);
6218
6219 /* The second number is the number of bytes occupied by this type. */
6220 nbytes = read_huge_number (pp, ';', &nbits, 0);
6221 if (nbits != 0)
6222 return error_type (pp, objfile);
6223
6224 nbits = nbytes * TARGET_CHAR_BIT;
6225
6226 if (details == NF_COMPLEX || details == NF_COMPLEX16
6227 || details == NF_COMPLEX32)
6228 {
6229 rettype = dbx_init_float_type (objfile, nbits / 2);
6230 return init_complex_type (NULL, rettype);
6231 }
6232
6233 return dbx_init_float_type (objfile, nbits);
6234 }
6235
6236 /* Read a number from the string pointed to by *PP.
6237 The value of *PP is advanced over the number.
6238 If END is nonzero, the character that ends the
6239 number must match END, or an error happens;
6240 and that character is skipped if it does match.
6241 If END is zero, *PP is left pointing to that character.
6242
6243 If TWOS_COMPLEMENT_BITS is set to a strictly positive value and if
6244 the number is represented in an octal representation, assume that
6245 it is represented in a 2's complement representation with a size of
6246 TWOS_COMPLEMENT_BITS.
6247
6248 If the number fits in a long, set *BITS to 0 and return the value.
6249 If not, set *BITS to be the number of bits in the number and return 0.
6250
6251 If encounter garbage, set *BITS to -1 and return 0. */
6252
6253 static long
6254 read_huge_number (const char **pp, int end, int *bits,
6255 int twos_complement_bits)
6256 {
6257 const char *p = *pp;
6258 int sign = 1;
6259 int sign_bit = 0;
6260 long n = 0;
6261 int radix = 10;
6262 char overflow = 0;
6263 int nbits = 0;
6264 int c;
6265 long upper_limit;
6266 int twos_complement_representation = 0;
6267
6268 if (*p == '-')
6269 {
6270 sign = -1;
6271 p++;
6272 }
6273
6274 /* Leading zero means octal. GCC uses this to output values larger
6275 than an int (because that would be hard in decimal). */
6276 if (*p == '0')
6277 {
6278 radix = 8;
6279 p++;
6280 }
6281
6282 /* Skip extra zeros. */
6283 while (*p == '0')
6284 p++;
6285
6286 if (sign > 0 && radix == 8 && twos_complement_bits > 0)
6287 {
6288 /* Octal, possibly signed. Check if we have enough chars for a
6289 negative number. */
6290
6291 size_t len;
6292 const char *p1 = p;
6293
6294 while ((c = *p1) >= '0' && c < '8')
6295 p1++;
6296
6297 len = p1 - p;
6298 if (len > twos_complement_bits / 3
6299 || (twos_complement_bits % 3 == 0
6300 && len == twos_complement_bits / 3))
6301 {
6302 /* Ok, we have enough characters for a signed value, check
6303 for signedness by testing if the sign bit is set. */
6304 sign_bit = (twos_complement_bits % 3 + 2) % 3;
6305 c = *p - '0';
6306 if (c & (1 << sign_bit))
6307 {
6308 /* Definitely signed. */
6309 twos_complement_representation = 1;
6310 sign = -1;
6311 }
6312 }
6313 }
6314
6315 upper_limit = LONG_MAX / radix;
6316
6317 while ((c = *p++) >= '0' && c < ('0' + radix))
6318 {
6319 if (n <= upper_limit)
6320 {
6321 if (twos_complement_representation)
6322 {
6323 /* Octal, signed, twos complement representation. In
6324 this case, n is the corresponding absolute value. */
6325 if (n == 0)
6326 {
6327 long sn = c - '0' - ((2 * (c - '0')) | (2 << sign_bit));
6328
6329 n = -sn;
6330 }
6331 else
6332 {
6333 n *= radix;
6334 n -= c - '0';
6335 }
6336 }
6337 else
6338 {
6339 /* unsigned representation */
6340 n *= radix;
6341 n += c - '0'; /* FIXME this overflows anyway. */
6342 }
6343 }
6344 else
6345 overflow = 1;
6346
6347 /* This depends on large values being output in octal, which is
6348 what GCC does. */
6349 if (radix == 8)
6350 {
6351 if (nbits == 0)
6352 {
6353 if (c == '0')
6354 /* Ignore leading zeroes. */
6355 ;
6356 else if (c == '1')
6357 nbits = 1;
6358 else if (c == '2' || c == '3')
6359 nbits = 2;
6360 else
6361 nbits = 3;
6362 }
6363 else
6364 nbits += 3;
6365 }
6366 }
6367 if (end)
6368 {
6369 if (c && c != end)
6370 {
6371 if (bits != NULL)
6372 *bits = -1;
6373 return 0;
6374 }
6375 }
6376 else
6377 --p;
6378
6379 if (radix == 8 && twos_complement_bits > 0 && nbits > twos_complement_bits)
6380 {
6381 /* We were supposed to parse a number with maximum
6382 TWOS_COMPLEMENT_BITS bits, but something went wrong. */
6383 if (bits != NULL)
6384 *bits = -1;
6385 return 0;
6386 }
6387
6388 *pp = p;
6389 if (overflow)
6390 {
6391 if (nbits == 0)
6392 {
6393 /* Large decimal constants are an error (because it is hard to
6394 count how many bits are in them). */
6395 if (bits != NULL)
6396 *bits = -1;
6397 return 0;
6398 }
6399
6400 /* -0x7f is the same as 0x80. So deal with it by adding one to
6401 the number of bits. Two's complement representation octals
6402 can't have a '-' in front. */
6403 if (sign == -1 && !twos_complement_representation)
6404 ++nbits;
6405 if (bits)
6406 *bits = nbits;
6407 }
6408 else
6409 {
6410 if (bits)
6411 *bits = 0;
6412 return n * sign;
6413 }
6414 /* It's *BITS which has the interesting information. */
6415 return 0;
6416 }
6417
6418 static struct type *
6419 read_range_type (const char **pp, int typenums[2], int type_size,
6420 struct objfile *objfile)
6421 {
6422 struct gdbarch *gdbarch = objfile->arch ();
6423 const char *orig_pp = *pp;
6424 int rangenums[2];
6425 long n2, n3;
6426 int n2bits, n3bits;
6427 int self_subrange;
6428 struct type *result_type;
6429 struct type *index_type = NULL;
6430
6431 /* First comes a type we are a subrange of.
6432 In C it is usually 0, 1 or the type being defined. */
6433 if (read_type_number (pp, rangenums) != 0)
6434 return error_type (pp, objfile);
6435 self_subrange = (rangenums[0] == typenums[0] &&
6436 rangenums[1] == typenums[1]);
6437
6438 if (**pp == '=')
6439 {
6440 *pp = orig_pp;
6441 index_type = read_type (pp, objfile);
6442 }
6443
6444 /* A semicolon should now follow; skip it. */
6445 if (**pp == ';')
6446 (*pp)++;
6447
6448 /* The remaining two operands are usually lower and upper bounds
6449 of the range. But in some special cases they mean something else. */
6450 n2 = read_huge_number (pp, ';', &n2bits, type_size);
6451 n3 = read_huge_number (pp, ';', &n3bits, type_size);
6452
6453 if (n2bits == -1 || n3bits == -1)
6454 return error_type (pp, objfile);
6455
6456 type_allocator alloc (objfile, get_current_subfile ()->language);
6457
6458 if (index_type)
6459 goto handle_true_range;
6460
6461 /* If limits are huge, must be large integral type. */
6462 if (n2bits != 0 || n3bits != 0)
6463 {
6464 char got_signed = 0;
6465 char got_unsigned = 0;
6466 /* Number of bits in the type. */
6467 int nbits = 0;
6468
6469 /* If a type size attribute has been specified, the bounds of
6470 the range should fit in this size. If the lower bounds needs
6471 more bits than the upper bound, then the type is signed. */
6472 if (n2bits <= type_size && n3bits <= type_size)
6473 {
6474 if (n2bits == type_size && n2bits > n3bits)
6475 got_signed = 1;
6476 else
6477 got_unsigned = 1;
6478 nbits = type_size;
6479 }
6480 /* Range from 0 to <large number> is an unsigned large integral type. */
6481 else if ((n2bits == 0 && n2 == 0) && n3bits != 0)
6482 {
6483 got_unsigned = 1;
6484 nbits = n3bits;
6485 }
6486 /* Range from <large number> to <large number>-1 is a large signed
6487 integral type. Take care of the case where <large number> doesn't
6488 fit in a long but <large number>-1 does. */
6489 else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
6490 || (n2bits != 0 && n3bits == 0
6491 && (n2bits == sizeof (long) * HOST_CHAR_BIT)
6492 && n3 == LONG_MAX))
6493 {
6494 got_signed = 1;
6495 nbits = n2bits;
6496 }
6497
6498 if (got_signed || got_unsigned)
6499 return init_integer_type (alloc, nbits, got_unsigned, NULL);
6500 else
6501 return error_type (pp, objfile);
6502 }
6503
6504 /* A type defined as a subrange of itself, with bounds both 0, is void. */
6505 if (self_subrange && n2 == 0 && n3 == 0)
6506 return alloc.new_type (TYPE_CODE_VOID, TARGET_CHAR_BIT, nullptr);
6507
6508 /* If n3 is zero and n2 is positive, we want a floating type, and n2
6509 is the width in bytes.
6510
6511 Fortran programs appear to use this for complex types also. To
6512 distinguish between floats and complex, g77 (and others?) seem
6513 to use self-subranges for the complexes, and subranges of int for
6514 the floats.
6515
6516 Also note that for complexes, g77 sets n2 to the size of one of
6517 the member floats, not the whole complex beast. My guess is that
6518 this was to work well with pre-COMPLEX versions of gdb. */
6519
6520 if (n3 == 0 && n2 > 0)
6521 {
6522 struct type *float_type
6523 = dbx_init_float_type (objfile, n2 * TARGET_CHAR_BIT);
6524
6525 if (self_subrange)
6526 return init_complex_type (NULL, float_type);
6527 else
6528 return float_type;
6529 }
6530
6531 /* If the upper bound is -1, it must really be an unsigned integral. */
6532
6533 else if (n2 == 0 && n3 == -1)
6534 {
6535 int bits = type_size;
6536
6537 if (bits <= 0)
6538 {
6539 /* We don't know its size. It is unsigned int or unsigned
6540 long. GCC 2.3.3 uses this for long long too, but that is
6541 just a GDB 3.5 compatibility hack. */
6542 bits = gdbarch_int_bit (gdbarch);
6543 }
6544
6545 return init_integer_type (alloc, bits, 1, NULL);
6546 }
6547
6548 /* Special case: char is defined (Who knows why) as a subrange of
6549 itself with range 0-127. */
6550 else if (self_subrange && n2 == 0 && n3 == 127)
6551 {
6552 struct type *type = init_integer_type (alloc, TARGET_CHAR_BIT,
6553 0, NULL);
6554 type->set_has_no_signedness (true);
6555 return type;
6556 }
6557 /* We used to do this only for subrange of self or subrange of int. */
6558 else if (n2 == 0)
6559 {
6560 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
6561 "unsigned long", and we already checked for that,
6562 so don't need to test for it here. */
6563
6564 if (n3 < 0)
6565 /* n3 actually gives the size. */
6566 return init_integer_type (alloc, -n3 * TARGET_CHAR_BIT, 1, NULL);
6567
6568 /* Is n3 == 2**(8n)-1 for some integer n? Then it's an
6569 unsigned n-byte integer. But do require n to be a power of
6570 two; we don't want 3- and 5-byte integers flying around. */
6571 {
6572 int bytes;
6573 unsigned long bits;
6574
6575 bits = n3;
6576 for (bytes = 0; (bits & 0xff) == 0xff; bytes++)
6577 bits >>= 8;
6578 if (bits == 0
6579 && ((bytes - 1) & bytes) == 0) /* "bytes is a power of two" */
6580 return init_integer_type (alloc, bytes * TARGET_CHAR_BIT, 1, NULL);
6581 }
6582 }
6583 /* I think this is for Convex "long long". Since I don't know whether
6584 Convex sets self_subrange, I also accept that particular size regardless
6585 of self_subrange. */
6586 else if (n3 == 0 && n2 < 0
6587 && (self_subrange
6588 || n2 == -gdbarch_long_long_bit
6589 (gdbarch) / TARGET_CHAR_BIT))
6590 return init_integer_type (alloc, -n2 * TARGET_CHAR_BIT, 0, NULL);
6591 else if (n2 == -n3 - 1)
6592 {
6593 if (n3 == 0x7f)
6594 return init_integer_type (alloc, 8, 0, NULL);
6595 if (n3 == 0x7fff)
6596 return init_integer_type (alloc, 16, 0, NULL);
6597 if (n3 == 0x7fffffff)
6598 return init_integer_type (alloc, 32, 0, NULL);
6599 }
6600
6601 /* We have a real range type on our hands. Allocate space and
6602 return a real pointer. */
6603 handle_true_range:
6604
6605 if (self_subrange)
6606 index_type = builtin_type (objfile)->builtin_int;
6607 else
6608 index_type = *dbx_lookup_type (rangenums, objfile);
6609 if (index_type == NULL)
6610 {
6611 /* Does this actually ever happen? Is that why we are worrying
6612 about dealing with it rather than just calling error_type? */
6613
6614 complaint (_("base type %d of range type is not defined"), rangenums[1]);
6615
6616 index_type = builtin_type (objfile)->builtin_int;
6617 }
6618
6619 result_type
6620 = create_static_range_type (alloc, index_type, n2, n3);
6621 return (result_type);
6622 }
6623
6624 /* Read in an argument list. This is a list of types, separated by commas
6625 and terminated with END. Return the list of types read in, or NULL
6626 if there is an error. */
6627
6628 static struct field *
6629 read_args (const char **pp, int end, struct objfile *objfile, int *nargsp,
6630 int *varargsp)
6631 {
6632 /* FIXME! Remove this arbitrary limit! */
6633 struct type *types[1024]; /* Allow for fns of 1023 parameters. */
6634 int n = 0, i;
6635 struct field *rval;
6636
6637 while (**pp != end)
6638 {
6639 if (**pp != ',')
6640 /* Invalid argument list: no ','. */
6641 return NULL;
6642 (*pp)++;
6643 STABS_CONTINUE (pp, objfile);
6644 types[n++] = read_type (pp, objfile);
6645 }
6646 (*pp)++; /* get past `end' (the ':' character). */
6647
6648 if (n == 0)
6649 {
6650 /* We should read at least the THIS parameter here. Some broken stabs
6651 output contained `(0,41),(0,42)=@s8;-16;,(0,43),(0,1);' where should
6652 have been present ";-16,(0,43)" reference instead. This way the
6653 excessive ";" marker prematurely stops the parameters parsing. */
6654
6655 complaint (_("Invalid (empty) method arguments"));
6656 *varargsp = 0;
6657 }
6658 else if (types[n - 1]->code () != TYPE_CODE_VOID)
6659 *varargsp = 1;
6660 else
6661 {
6662 n--;
6663 *varargsp = 0;
6664 }
6665
6666 rval = XCNEWVEC (struct field, n);
6667 for (i = 0; i < n; i++)
6668 rval[i].set_type (types[i]);
6669 *nargsp = n;
6670 return rval;
6671 }
6672 \f
6673 /* Common block handling. */
6674
6675 /* List of symbols declared since the last BCOMM. This list is a tail
6676 of local_symbols. When ECOMM is seen, the symbols on the list
6677 are noted so their proper addresses can be filled in later,
6678 using the common block base address gotten from the assembler
6679 stabs. */
6680
6681 static struct pending *common_block;
6682 static int common_block_i;
6683
6684 /* Name of the current common block. We get it from the BCOMM instead of the
6685 ECOMM to match IBM documentation (even though IBM puts the name both places
6686 like everyone else). */
6687 static char *common_block_name;
6688
6689 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
6690 to remain after this function returns. */
6691
6692 void
6693 common_block_start (const char *name, struct objfile *objfile)
6694 {
6695 if (common_block_name != NULL)
6696 {
6697 complaint (_("Invalid symbol data: common block within common block"));
6698 }
6699 common_block = *get_local_symbols ();
6700 common_block_i = common_block ? common_block->nsyms : 0;
6701 common_block_name = obstack_strdup (&objfile->objfile_obstack, name);
6702 }
6703
6704 /* Process a N_ECOMM symbol. */
6705
6706 void
6707 common_block_end (struct objfile *objfile)
6708 {
6709 /* Symbols declared since the BCOMM are to have the common block
6710 start address added in when we know it. common_block and
6711 common_block_i point to the first symbol after the BCOMM in
6712 the local_symbols list; copy the list and hang it off the
6713 symbol for the common block name for later fixup. */
6714 int i;
6715 struct symbol *sym;
6716 struct pending *newobj = 0;
6717 struct pending *next;
6718 int j;
6719
6720 if (common_block_name == NULL)
6721 {
6722 complaint (_("ECOMM symbol unmatched by BCOMM"));
6723 return;
6724 }
6725
6726 sym = new (&objfile->objfile_obstack) symbol;
6727 /* Note: common_block_name already saved on objfile_obstack. */
6728 sym->set_linkage_name (common_block_name);
6729 sym->set_aclass_index (LOC_BLOCK);
6730
6731 /* Now we copy all the symbols which have been defined since the BCOMM. */
6732
6733 /* Copy all the struct pendings before common_block. */
6734 for (next = *get_local_symbols ();
6735 next != NULL && next != common_block;
6736 next = next->next)
6737 {
6738 for (j = 0; j < next->nsyms; j++)
6739 add_symbol_to_list (next->symbol[j], &newobj);
6740 }
6741
6742 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
6743 NULL, it means copy all the local symbols (which we already did
6744 above). */
6745
6746 if (common_block != NULL)
6747 for (j = common_block_i; j < common_block->nsyms; j++)
6748 add_symbol_to_list (common_block->symbol[j], &newobj);
6749
6750 sym->set_type ((struct type *) newobj);
6751
6752 /* Should we be putting local_symbols back to what it was?
6753 Does it matter? */
6754
6755 i = hashname (sym->linkage_name ());
6756 sym->set_value_chain (global_sym_chain[i]);
6757 global_sym_chain[i] = sym;
6758 common_block_name = NULL;
6759 }
6760
6761 /* Add a common block's start address to the offset of each symbol
6762 declared to be in it (by being between a BCOMM/ECOMM pair that uses
6763 the common block name). */
6764
6765 static void
6766 fix_common_block (struct symbol *sym, CORE_ADDR valu, int section_index)
6767 {
6768 struct pending *next = (struct pending *) sym->type ();
6769
6770 for (; next; next = next->next)
6771 {
6772 int j;
6773
6774 for (j = next->nsyms - 1; j >= 0; j--)
6775 {
6776 next->symbol[j]->set_value_address
6777 (next->symbol[j]->value_address () + valu);
6778 next->symbol[j]->set_section_index (section_index);
6779 }
6780 }
6781 }
6782 \f
6783
6784
6785 /* Add {TYPE, TYPENUMS} to the NONAME_UNDEFS vector.
6786 See add_undefined_type for more details. */
6787
6788 static void
6789 add_undefined_type_noname (struct type *type, int typenums[2])
6790 {
6791 struct nat nat;
6792
6793 nat.typenums[0] = typenums [0];
6794 nat.typenums[1] = typenums [1];
6795 nat.type = type;
6796
6797 if (noname_undefs_length == noname_undefs_allocated)
6798 {
6799 noname_undefs_allocated *= 2;
6800 noname_undefs = (struct nat *)
6801 xrealloc ((char *) noname_undefs,
6802 noname_undefs_allocated * sizeof (struct nat));
6803 }
6804 noname_undefs[noname_undefs_length++] = nat;
6805 }
6806
6807 /* Add TYPE to the UNDEF_TYPES vector.
6808 See add_undefined_type for more details. */
6809
6810 static void
6811 add_undefined_type_1 (struct type *type)
6812 {
6813 if (undef_types_length == undef_types_allocated)
6814 {
6815 undef_types_allocated *= 2;
6816 undef_types = (struct type **)
6817 xrealloc ((char *) undef_types,
6818 undef_types_allocated * sizeof (struct type *));
6819 }
6820 undef_types[undef_types_length++] = type;
6821 }
6822
6823 /* What about types defined as forward references inside of a small lexical
6824 scope? */
6825 /* Add a type to the list of undefined types to be checked through
6826 once this file has been read in.
6827
6828 In practice, we actually maintain two such lists: The first list
6829 (UNDEF_TYPES) is used for types whose name has been provided, and
6830 concerns forward references (eg 'xs' or 'xu' forward references);
6831 the second list (NONAME_UNDEFS) is used for types whose name is
6832 unknown at creation time, because they were referenced through
6833 their type number before the actual type was declared.
6834 This function actually adds the given type to the proper list. */
6835
6836 static void
6837 add_undefined_type (struct type *type, int typenums[2])
6838 {
6839 if (type->name () == NULL)
6840 add_undefined_type_noname (type, typenums);
6841 else
6842 add_undefined_type_1 (type);
6843 }
6844
6845 /* Try to fix all undefined types pushed on the UNDEF_TYPES vector. */
6846
6847 static void
6848 cleanup_undefined_types_noname (struct objfile *objfile)
6849 {
6850 int i;
6851
6852 for (i = 0; i < noname_undefs_length; i++)
6853 {
6854 struct nat nat = noname_undefs[i];
6855 struct type **type;
6856
6857 type = dbx_lookup_type (nat.typenums, objfile);
6858 if (nat.type != *type && (*type)->code () != TYPE_CODE_UNDEF)
6859 {
6860 /* The instance flags of the undefined type are still unset,
6861 and needs to be copied over from the reference type.
6862 Since replace_type expects them to be identical, we need
6863 to set these flags manually before hand. */
6864 nat.type->set_instance_flags ((*type)->instance_flags ());
6865 replace_type (nat.type, *type);
6866 }
6867 }
6868
6869 noname_undefs_length = 0;
6870 }
6871
6872 /* Go through each undefined type, see if it's still undefined, and fix it
6873 up if possible. We have two kinds of undefined types:
6874
6875 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
6876 Fix: update array length using the element bounds
6877 and the target type's length.
6878 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
6879 yet defined at the time a pointer to it was made.
6880 Fix: Do a full lookup on the struct/union tag. */
6881
6882 static void
6883 cleanup_undefined_types_1 (void)
6884 {
6885 struct type **type;
6886
6887 /* Iterate over every undefined type, and look for a symbol whose type
6888 matches our undefined type. The symbol matches if:
6889 1. It is a typedef in the STRUCT domain;
6890 2. It has the same name, and same type code;
6891 3. The instance flags are identical.
6892
6893 It is important to check the instance flags, because we have seen
6894 examples where the debug info contained definitions such as:
6895
6896 "foo_t:t30=B31=xefoo_t:"
6897
6898 In this case, we have created an undefined type named "foo_t" whose
6899 instance flags is null (when processing "xefoo_t"), and then created
6900 another type with the same name, but with different instance flags
6901 ('B' means volatile). I think that the definition above is wrong,
6902 since the same type cannot be volatile and non-volatile at the same
6903 time, but we need to be able to cope with it when it happens. The
6904 approach taken here is to treat these two types as different. */
6905
6906 for (type = undef_types; type < undef_types + undef_types_length; type++)
6907 {
6908 switch ((*type)->code ())
6909 {
6910
6911 case TYPE_CODE_STRUCT:
6912 case TYPE_CODE_UNION:
6913 case TYPE_CODE_ENUM:
6914 {
6915 /* Check if it has been defined since. Need to do this here
6916 as well as in check_typedef to deal with the (legitimate in
6917 C though not C++) case of several types with the same name
6918 in different source files. */
6919 if ((*type)->is_stub ())
6920 {
6921 struct pending *ppt;
6922 int i;
6923 /* Name of the type, without "struct" or "union". */
6924 const char *type_name = (*type)->name ();
6925
6926 if (type_name == NULL)
6927 {
6928 complaint (_("need a type name"));
6929 break;
6930 }
6931 for (ppt = *get_file_symbols (); ppt; ppt = ppt->next)
6932 {
6933 for (i = 0; i < ppt->nsyms; i++)
6934 {
6935 struct symbol *sym = ppt->symbol[i];
6936
6937 if (sym->aclass () == LOC_TYPEDEF
6938 && sym->domain () == STRUCT_DOMAIN
6939 && (sym->type ()->code () == (*type)->code ())
6940 && ((*type)->instance_flags ()
6941 == sym->type ()->instance_flags ())
6942 && strcmp (sym->linkage_name (), type_name) == 0)
6943 replace_type (*type, sym->type ());
6944 }
6945 }
6946 }
6947 }
6948 break;
6949
6950 default:
6951 {
6952 complaint (_("forward-referenced types left unresolved, "
6953 "type code %d."),
6954 (*type)->code ());
6955 }
6956 break;
6957 }
6958 }
6959
6960 undef_types_length = 0;
6961 }
6962
6963 /* Try to fix all the undefined types we encountered while processing
6964 this unit. */
6965
6966 void
6967 cleanup_undefined_stabs_types (struct objfile *objfile)
6968 {
6969 cleanup_undefined_types_1 ();
6970 cleanup_undefined_types_noname (objfile);
6971 }
6972
6973 /* See stabsread.h. */
6974
6975 void
6976 scan_file_globals (struct objfile *objfile)
6977 {
6978 int hash;
6979 struct symbol *sym, *prev;
6980 struct objfile *resolve_objfile;
6981
6982 /* SVR4 based linkers copy referenced global symbols from shared
6983 libraries to the main executable.
6984 If we are scanning the symbols for a shared library, try to resolve
6985 them from the minimal symbols of the main executable first. */
6986
6987 if (current_program_space->symfile_object_file
6988 && objfile != current_program_space->symfile_object_file)
6989 resolve_objfile = current_program_space->symfile_object_file;
6990 else
6991 resolve_objfile = objfile;
6992
6993 while (1)
6994 {
6995 /* Avoid expensive loop through all minimal symbols if there are
6996 no unresolved symbols. */
6997 for (hash = 0; hash < HASHSIZE; hash++)
6998 {
6999 if (global_sym_chain[hash])
7000 break;
7001 }
7002 if (hash >= HASHSIZE)
7003 return;
7004
7005 for (minimal_symbol *msymbol : resolve_objfile->msymbols ())
7006 {
7007 QUIT;
7008
7009 /* Skip static symbols. */
7010 switch (msymbol->type ())
7011 {
7012 case mst_file_text:
7013 case mst_file_data:
7014 case mst_file_bss:
7015 continue;
7016 default:
7017 break;
7018 }
7019
7020 prev = NULL;
7021
7022 /* Get the hash index and check all the symbols
7023 under that hash index. */
7024
7025 hash = hashname (msymbol->linkage_name ());
7026
7027 for (sym = global_sym_chain[hash]; sym;)
7028 {
7029 if (strcmp (msymbol->linkage_name (), sym->linkage_name ()) == 0)
7030 {
7031 /* Splice this symbol out of the hash chain and
7032 assign the value we have to it. */
7033 if (prev)
7034 {
7035 prev->set_value_chain (sym->value_chain ());
7036 }
7037 else
7038 {
7039 global_sym_chain[hash] = sym->value_chain ();
7040 }
7041
7042 /* Check to see whether we need to fix up a common block. */
7043 /* Note: this code might be executed several times for
7044 the same symbol if there are multiple references. */
7045 if (sym)
7046 {
7047 if (sym->aclass () == LOC_BLOCK)
7048 fix_common_block
7049 (sym, msymbol->value_address (resolve_objfile),
7050 msymbol->section_index ());
7051 else
7052 sym->set_value_address
7053 (msymbol->value_address (resolve_objfile));
7054 sym->set_section_index (msymbol->section_index ());
7055 }
7056
7057 if (prev)
7058 {
7059 sym = prev->value_chain ();
7060 }
7061 else
7062 {
7063 sym = global_sym_chain[hash];
7064 }
7065 }
7066 else
7067 {
7068 prev = sym;
7069 sym = sym->value_chain ();
7070 }
7071 }
7072 }
7073 if (resolve_objfile == objfile)
7074 break;
7075 resolve_objfile = objfile;
7076 }
7077
7078 /* Change the storage class of any remaining unresolved globals to
7079 LOC_UNRESOLVED and remove them from the chain. */
7080 for (hash = 0; hash < HASHSIZE; hash++)
7081 {
7082 sym = global_sym_chain[hash];
7083 while (sym)
7084 {
7085 prev = sym;
7086 sym = sym->value_chain ();
7087
7088 /* Change the symbol address from the misleading chain value
7089 to address zero. */
7090 prev->set_value_address (0);
7091
7092 /* Complain about unresolved common block symbols. */
7093 if (prev->aclass () == LOC_STATIC)
7094 prev->set_aclass_index (LOC_UNRESOLVED);
7095 else
7096 complaint (_("%s: common block `%s' from "
7097 "global_sym_chain unresolved"),
7098 objfile_name (objfile), prev->print_name ());
7099 }
7100 }
7101 memset (global_sym_chain, 0, sizeof (global_sym_chain));
7102 }
7103
7104 /* Initialize anything that needs initializing when starting to read
7105 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
7106 to a psymtab. */
7107
7108 void
7109 stabsread_init (void)
7110 {
7111 }
7112
7113 /* Initialize anything that needs initializing when a completely new
7114 symbol file is specified (not just adding some symbols from another
7115 file, e.g. a shared library). */
7116
7117 void
7118 stabsread_new_init (void)
7119 {
7120 /* Empty the hash table of global syms looking for values. */
7121 memset (global_sym_chain, 0, sizeof (global_sym_chain));
7122 }
7123
7124 /* Initialize anything that needs initializing at the same time as
7125 start_compunit_symtab() is called. */
7126
7127 void
7128 start_stabs (void)
7129 {
7130 global_stabs = NULL; /* AIX COFF */
7131 /* Leave FILENUM of 0 free for builtin types and this file's types. */
7132 n_this_object_header_files = 1;
7133 type_vector_length = 0;
7134 type_vector = (struct type **) 0;
7135 within_function = 0;
7136
7137 /* FIXME: If common_block_name is not already NULL, we should complain(). */
7138 common_block_name = NULL;
7139 }
7140
7141 /* Call after end_compunit_symtab(). */
7142
7143 void
7144 end_stabs (void)
7145 {
7146 if (type_vector)
7147 {
7148 xfree (type_vector);
7149 }
7150 type_vector = 0;
7151 type_vector_length = 0;
7152 previous_stab_code = 0;
7153 }
7154
7155 void
7156 finish_global_stabs (struct objfile *objfile)
7157 {
7158 if (global_stabs)
7159 {
7160 patch_block_stabs (*get_global_symbols (), global_stabs, objfile);
7161 xfree (global_stabs);
7162 global_stabs = NULL;
7163 }
7164 }
7165
7166 /* Find the end of the name, delimited by a ':', but don't match
7167 ObjC symbols which look like -[Foo bar::]:bla. */
7168 static const char *
7169 find_name_end (const char *name)
7170 {
7171 const char *s = name;
7172
7173 if (s[0] == '-' || *s == '+')
7174 {
7175 /* Must be an ObjC method symbol. */
7176 if (s[1] != '[')
7177 {
7178 error (_("invalid symbol name \"%s\""), name);
7179 }
7180 s = strchr (s, ']');
7181 if (s == NULL)
7182 {
7183 error (_("invalid symbol name \"%s\""), name);
7184 }
7185 return strchr (s, ':');
7186 }
7187 else
7188 {
7189 return strchr (s, ':');
7190 }
7191 }
7192
7193 /* See stabsread.h. */
7194
7195 int
7196 hashname (const char *name)
7197 {
7198 return fast_hash (name, strlen (name)) % HASHSIZE;
7199 }
7200
7201 /* Initializer for this module. */
7202
7203 INIT_GDB_FILE (stabsread)
7204 {
7205 undef_types_allocated = 20;
7206 undef_types_length = 0;
7207 undef_types = XNEWVEC (struct type *, undef_types_allocated);
7208
7209 noname_undefs_allocated = 20;
7210 noname_undefs_length = 0;
7211 noname_undefs = XNEWVEC (struct nat, noname_undefs_allocated);
7212
7213 stab_register_index = register_symbol_register_impl (LOC_REGISTER,
7214 &stab_register_funcs);
7215 stab_regparm_index = register_symbol_register_impl (LOC_REGPARM_ADDR,
7216 &stab_register_funcs);
7217 }