1 /* Support routines for decoding "stabs" debugging information format.
3 Copyright (C) 1986-2025 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
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
28 #include "event-top.h"
29 #include "gdbsupport/gdb_obstack.h"
32 #include "expression.h"
35 #include "aout/stab_gnu.h"
38 #include "aout/aout64.h"
39 #include "gdb-stabs.h"
40 #include "buildsym-legacy.h"
41 #include "complaints.h"
43 #include "gdb-demangle.h"
45 #include "target-float.h"
48 #include "cp-support.h"
51 #include "filenames.h"
53 #include "stabsread.h"
55 /* See stabsread.h for these globals. */
57 const char *(*next_symbol_text_func
) (struct objfile
*);
58 unsigned char processing_gcc_compilation
;
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
;
67 /* See stabsread.h. */
69 const registry
<objfile
>::key
<dbx_symfile_info
> dbx_objfile_data_key
;
71 dbx_symfile_info::~dbx_symfile_info ()
73 if (header_files
!= NULL
)
75 int i
= n_header_files
;
76 struct header_file
*hfiles
= header_files
;
80 xfree (hfiles
[i
].name
);
81 xfree (hfiles
[i
].vector
);
87 struct stabs_nextfield
89 struct stabs_nextfield
*next
;
94 struct next_fnfieldlist
96 struct next_fnfieldlist
*next
;
97 struct fn_fieldlist fn_fieldlist
;
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) */
106 struct stab_field_info
108 struct stabs_nextfield
*list
= nullptr;
109 struct next_fnfieldlist
*fnlist
= nullptr;
111 auto_obstack obstack
;
115 read_one_struct_field (struct stab_field_info
*, const char **, const char *,
116 struct type
*, struct objfile
*);
118 static struct type
*dbx_alloc_type (int[2], struct objfile
*);
120 static long read_huge_number (const char **, int, int *, int);
122 static struct type
*error_type (const char **, struct objfile
*);
125 patch_block_stabs (struct pending
*, struct pending_stabs
*,
128 static int read_type_number (const char **, int *);
130 static struct type
*read_type (const char **, struct objfile
*);
132 static struct type
*read_range_type (const char **, int[2],
133 int, struct objfile
*);
135 static struct type
*read_sun_builtin_type (const char **,
136 int[2], struct objfile
*);
138 static struct type
*read_sun_floating_type (const char **, int[2],
141 static struct type
*read_enum_type (const char **, struct type
*, struct objfile
*);
143 static struct type
*rs6000_builtin_type (int, struct objfile
*);
146 read_member_functions (struct stab_field_info
*, const char **, struct type
*,
150 read_struct_fields (struct stab_field_info
*, const char **, struct type
*,
154 read_baseclasses (struct stab_field_info
*, const char **, struct type
*,
158 read_tilde_fields (struct stab_field_info
*, const char **, struct type
*,
161 static int attach_fn_fields_to_type (struct stab_field_info
*, struct type
*);
163 static int attach_fields_to_type (struct stab_field_info
*, struct type
*,
166 static struct type
*read_struct_type (const char **, struct type
*,
170 static struct type
*read_array_type (const char **, struct type
*,
173 static struct field
*read_args (const char **, int, struct objfile
*,
176 static void add_undefined_type (struct type
*, int[2]);
179 read_cpp_abbrev (struct stab_field_info
*, const char **, struct type
*,
182 static const char *find_name_end (const char *name
);
184 static int process_reference (const char **string
);
186 void stabsread_clear_cache (void);
188 static const char vptr_name
[] = "_vptr$";
189 static const char vb_name
[] = "_vb$";
192 unknown_symtype_complaint (const char *arg1
)
194 complaint (_("unknown symbol type %s"), arg1
);
198 lbrac_mismatch_complaint (int arg1
)
200 complaint (_("N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d"), arg1
);
204 repeated_header_complaint (const char *arg1
, int arg2
)
206 complaint (_("\"repeated\" header file %s not "
207 "previously seen, at symtab pos %d"),
212 invalid_cpp_abbrev_complaint (const char *arg1
)
214 complaint (_("invalid C++ abbreviation `%s'"), arg1
);
218 reg_value_complaint (int regnum
, int num_regs
, const char *sym
)
220 complaint (_("bad register number %d (max %d) in symbol %s"),
221 regnum
, num_regs
- 1, sym
);
225 stabs_general_complaint (const char *arg1
)
227 complaint ("%s", arg1
);
231 function_outside_compilation_unit_complaint (const char *arg1
)
233 complaint (_("function `%s' appears to be defined "
234 "outside of all compilation units"),
238 /* Make a list of forward references which haven't been defined. */
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
;
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. */
255 static struct nat
*noname_undefs
;
256 static int noname_undefs_allocated
;
257 static int noname_undefs_length
;
259 /* Check for and handle cretinous stabs symbol name continuation! */
260 #define STABS_CONTINUE(pp,objfile) \
262 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
263 *(pp) = next_symbol_text (objfile); \
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.) */
272 static struct type
**type_vector
;
274 /* Number of elements allocated for type_vector currently. */
276 static int type_vector_length
;
278 /* Initial size of type vector. Is realloc'd larger if needed, and
279 realloc'd down to the size actually used, when completed. */
281 #define INITIAL_TYPE_VECTOR_LENGTH 160
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.
288 This can be used for finding the type associated with that pair
289 or for associating a new type with the pair. */
291 static struct type
**
292 dbx_lookup_type (int typenums
[2], struct objfile
*objfile
)
294 int filenum
= typenums
[0];
295 int index
= typenums
[1];
298 struct header_file
*f
;
301 if (filenum
== -1) /* -1,-1 is for temporary types. */
304 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
306 complaint (_("Invalid symbol data: type number "
307 "(%d,%d) out of range at symtab pos %d."),
308 filenum
, index
, symnum
);
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
;
323 temp_type
= rs6000_builtin_type (index
, objfile
);
327 /* Type is defined outside of header files.
328 Find it in this object file's type vector. */
329 if (index
>= type_vector_length
)
331 old_len
= type_vector_length
;
334 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
335 type_vector
= XNEWVEC (struct type
*, type_vector_length
);
337 while (index
>= type_vector_length
)
339 type_vector_length
*= 2;
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
*));
347 return (&type_vector
[index
]);
351 real_filenum
= this_object_header_files
[filenum
];
353 if (real_filenum
>= N_HEADER_FILES (objfile
))
355 static struct type
*temp_type
;
357 warning (_("GDB internal error: bad real_filenum"));
360 temp_type
= builtin_type (objfile
)->builtin_error
;
364 f
= HEADER_FILES (objfile
) + real_filenum
;
366 f_orig_length
= f
->length
;
367 if (index
>= f_orig_length
)
369 while (index
>= f
->length
)
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
*));
378 return (&f
->vector
[index
]);
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. */
389 dbx_alloc_type (int typenums
[2], struct objfile
*objfile
)
391 struct type
**type_addr
;
393 if (typenums
[0] == -1)
395 return type_allocator (objfile
,
396 get_current_subfile ()->language
).new_type ();
399 type_addr
= dbx_lookup_type (typenums
, objfile
);
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. */
406 *type_addr
= type_allocator (objfile
,
407 get_current_subfile ()->language
).new_type ();
413 /* Allocate a floating-point type of size BITS. */
416 dbx_init_float_type (struct objfile
*objfile
, int bits
)
418 struct gdbarch
*gdbarch
= objfile
->arch ();
419 const struct floatformat
**format
;
422 format
= gdbarch_floatformat_for_type (gdbarch
, NULL
, bits
);
423 type_allocator
alloc (objfile
, get_current_subfile ()->language
);
425 type
= init_float_type (alloc
, bits
, NULL
, format
);
427 type
= alloc
.new_type (TYPE_CODE_ERROR
, bits
, NULL
);
432 /* for all the stabs in a given stab vector, build appropriate types
433 and fix their symbols in given symbol vector. */
436 patch_block_stabs (struct pending
*symbols
, struct pending_stabs
*stabs
,
437 struct objfile
*objfile
)
446 /* for all the stab entries, find their corresponding symbols and
447 patch their types! */
449 for (ii
= 0; ii
< stabs
->count
; ++ii
)
451 name
= stabs
->stab
[ii
];
452 pp
= (char *) strchr (name
, ':');
453 gdb_assert (pp
); /* Must find a ':' or game's over. */
457 pp
= (char *) strchr (pp
, ':');
459 sym
= find_symbol_in_list (symbols
, name
, pp
- name
);
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. */
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
));
479 if (*(pp
- 1) == 'F' || *(pp
- 1) == 'f')
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. */
485 (lookup_function_type (read_type (&pp
, objfile
)));
489 sym
->set_type (read_type (&pp
, objfile
));
491 add_symbol_to_list (sym
, get_global_symbols ());
496 if (*(pp
- 1) == 'F' || *(pp
- 1) == 'f')
499 (lookup_function_type (read_type (&pp
, objfile
)));
503 sym
->set_type (read_type (&pp
, objfile
));
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.
517 Returns 0 for success, -1 for error. */
520 read_type_number (const char **pp
, int *typenums
)
527 typenums
[0] = read_huge_number (pp
, ',', &nbits
, 0);
530 typenums
[1] = read_huge_number (pp
, ')', &nbits
, 0);
537 typenums
[1] = read_huge_number (pp
, 0, &nbits
, 0);
545 /* Free up old header file tables. */
548 free_header_files (void)
550 if (this_object_header_files
)
552 xfree (this_object_header_files
);
553 this_object_header_files
= NULL
;
555 n_allocated_this_object_header_files
= 0;
558 /* Allocate new header file tables. */
561 init_header_files (void)
563 n_allocated_this_object_header_files
= 10;
564 this_object_header_files
= XNEWVEC (int, 10);
567 /* Close off the current usage of PST.
568 Returns PST or NULL if the partial symtab was empty and thrown away.
570 FIXME: List variables and peculiarities of same. */
573 stabs_end_psymtab (struct objfile
*objfile
, psymtab_storage
*partial_symtabs
,
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
,
582 struct gdbarch
*gdbarch
= objfile
->arch ();
583 dbx_symfile_info
*key
= dbx_objfile_data_key
. get (objfile
);
585 if (capping_symbol_offset
!= -1)
586 LDSYMLEN (pst
) = capping_symbol_offset
- LDSYMOFF (pst
);
587 pst
->set_text_high (capping_text
);
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. */
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. */
604 if (!pst
->text_high_valid
&& key
->ctx
.last_function_name
605 && gdbarch_sofun_address_maybe_missing (gdbarch
))
609 const char *colon
= strchr (key
->ctx
.last_function_name
, ':');
613 n
= colon
- key
->ctx
.last_function_name
;
614 char *p
= (char *) alloca (n
+ 2);
615 strncpy (p
, key
->ctx
.last_function_name
, n
);
618 bound_minimal_symbol minsym
619 = lookup_minimal_symbol (current_program_space
, p
, objfile
,
621 if (minsym
.minsym
== NULL
)
623 /* Sun Fortran appends an underscore to the minimal symbol name,
624 try again with an appended underscore if the minimal symbol
628 minsym
= lookup_minimal_symbol (current_program_space
, p
, objfile
,
634 (unrelocated_addr (CORE_ADDR (minsym
.minsym
->unrelocated_address ())
635 + minsym
.minsym
->size ()));
637 key
->ctx
.last_function_name
= NULL
;
640 if (!gdbarch_sofun_address_maybe_missing (gdbarch
))
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 ());
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. */
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 ());
657 /* End of kludge for patching Solaris textlow and texthigh. */
661 pst
->number_of_dependencies
= number_dependencies
;
662 if (number_dependencies
)
665 = partial_symtabs
->allocate_dependencies (number_dependencies
);
666 memcpy (pst
->dependencies
, dependency_list
,
667 number_dependencies
* sizeof (legacy_psymtab
*));
670 pst
->dependencies
= 0;
672 for (i
= 0; i
< num_includes
; i
++)
674 legacy_psymtab
*subpst
=
675 new legacy_psymtab (include_list
[i
], partial_symtabs
, objfile
->per_bfd
);
677 subpst
->read_symtab_private
=
678 XOBNEW (&objfile
->objfile_obstack
, struct symloc
);
680 LDSYMLEN (subpst
) = 0;
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;
689 subpst
->legacy_read_symtab
= pst
->legacy_read_symtab
;
690 subpst
->legacy_expand_psymtab
= pst
->legacy_expand_psymtab
;
693 if (num_includes
== 0
694 && number_dependencies
== 0
696 && key
->ctx
.has_line_numbers
== 0)
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. */
705 partial_symtabs
->discard_psymtab (pst
);
707 /* Indicate that psymtab was thrown away. */
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. */
718 set_namestring (struct objfile
*objfile
, const struct internal_nlist
*nlist
)
720 const char *namestring
;
721 struct dbx_symfile_info
*key
= dbx_objfile_data_key
.get (objfile
);
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
)
727 complaint (_("bad string table offset in symbol %d"),
729 namestring
= "<bad string table offset>";
732 namestring
= (nlist
->n_strx
+ key
->ctx
.file_string_table_offset
733 + DBX_STRINGTAB (objfile
));
738 stabs_seek (int sym_offset
, struct objfile
*objfile
)
740 dbx_symfile_info
*key
= dbx_objfile_data_key
.get (objfile
);
741 if (key
->ctx
.stabs_data
)
743 key
->ctx
.symbuf_read
+= sym_offset
;
744 key
->ctx
.symbuf_left
-= sym_offset
;
747 if (bfd_seek (objfile
->obfd
.get (), sym_offset
, SEEK_CUR
) != 0)
748 perror_with_name (bfd_get_filename (objfile
->obfd
.get ()));
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
;
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. */
763 fill_symbuf (bfd
*sym_bfd
, struct objfile
*objfile
)
767 struct dbx_symfile_info
*key
= dbx_objfile_data_key
.get (objfile
);
769 if (key
->ctx
.stabs_data
)
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
);
776 else if (key
->ctx
.symbuf_sections
== NULL
)
778 count
= sizeof (symbuf
);
779 nbytes
= bfd_read (symbuf
, count
, sym_bfd
);
783 if (key
->ctx
.symbuf_left
<= 0)
785 file_ptr filepos
= (*key
->ctx
.symbuf_sections
)[key
->ctx
.sect_idx
]->filepos
;
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
;
794 count
= key
->ctx
.symbuf_left
;
795 if (count
> sizeof (symbuf
))
796 count
= sizeof (symbuf
);
797 nbytes
= bfd_read (symbuf
, count
, sym_bfd
);
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
;
806 key
->ctx
.symbuf_left
-= nbytes
;
807 key
->ctx
.symbuf_read
+= nbytes
;
810 /* Read in a defined section of a specific object file's symbols. */
813 read_ofile_symtab (struct objfile
*objfile
, legacy_psymtab
*pst
)
815 const char *namestring
;
816 struct external_nlist
*bufp
;
817 struct internal_nlist nlist
;
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
);
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
§ion_offsets
= objfile
->section_offsets
;
833 key
->ctx
.stringtab_global
= DBX_STRINGTAB (objfile
);
834 set_last_source_file (NULL
);
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
;
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.
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
)
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
++);
855 namestring
= set_namestring (objfile
, &nlist
);
857 processing_gcc_compilation
= 0;
858 if (nlist
.n_type
== N_TEXT
)
860 const char *tempstring
= namestring
;
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 ()))
869 if (startswith (tempstring
, "__gnu_compiled"))
870 processing_gcc_compilation
= 2;
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;
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"));
888 max_symnum
= sym_size
/ key
->ctx
.symbol_size
;
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
++);
901 type
= bfd_h_get_8 (abfd
, bufp
->e_type
);
903 namestring
= set_namestring (objfile
, &nlist
);
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
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
,
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
)
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. */
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;
939 else if (type
& N_EXT
|| type
== (unsigned char) N_TEXT
940 || type
== (unsigned char) N_NBTEXT
)
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
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
);
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
);
967 pst
->compunit_symtab
= end_compunit_symtab (text_offset
+ text_size
);
974 dbx_expand_psymtab (legacy_psymtab
*pst
, struct objfile
*objfile
)
976 gdb_assert (!pst
->readin
);
977 struct dbx_symfile_info
*key
= dbx_objfile_data_key
.get (objfile
);
979 /* Read in all partial symtabs on which this one is dependent. */
980 pst
->expand_dependencies (objfile
);
982 if (LDSYMLEN (pst
)) /* Otherwise it's a dummy. */
984 /* Init stuff necessary for reading in symbols */
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
);
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
);
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. */
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. */
1008 dbx_next_symbol_text (struct objfile
*objfile
)
1010 struct internal_nlist nlist
;
1011 dbx_symfile_info
*key
= dbx_objfile_data_key
.get (objfile
);
1013 if (symbuf_idx
== symbuf_end
)
1014 fill_symbuf (objfile
->obfd
.get (), objfile
);
1017 INTERNALIZE_SYMBOL (nlist
, &symbuf
[symbuf_idx
], objfile
->obfd
.get ());
1018 OBJSTAT (objfile
, n_stabs
++);
1022 return nlist
.n_strx
+ key
->ctx
.stringtab_global
1023 + key
->ctx
.file_string_table_offset
;
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. */
1030 stabs_read_symtab (legacy_psymtab
*self
, struct objfile
*objfile
)
1032 gdb_assert (!self
->readin
);
1034 if (LDSYMLEN (self
) || self
->number_of_dependencies
)
1036 next_symbol_text_func
= dbx_next_symbol_text
;
1037 dbx_symfile_info
*key
= dbx_objfile_data_key
.get (objfile
);
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
))
1045 = symfile_relocate_debug_section (objfile
,
1046 DBX_STAB_SECTION (objfile
),
1048 data_holder
.reset (key
->ctx
.stabs_data
);
1051 self
->expand_psymtab (objfile
);
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
);
1061 record_minimal_symbol (minimal_symbol_reader
&reader
,
1062 const char *name
, unrelocated_addr address
, int type
,
1063 struct objfile
*objfile
)
1065 enum minimal_symbol_type ms_type
;
1067 struct dbx_symfile_info
*key
= dbx_objfile_data_key
.get (objfile
);
1071 case N_TEXT
| N_EXT
:
1073 section
= SECT_OFF_TEXT (objfile
);
1075 case N_DATA
| N_EXT
:
1077 section
= SECT_OFF_DATA (objfile
);
1081 section
= SECT_OFF_BSS (objfile
);
1088 case N_SETV
| N_EXT
:
1090 section
= SECT_OFF_DATA (objfile
);
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
1096 ms_type
= mst_file_data
;
1097 section
= SECT_OFF_DATA (objfile
);
1104 ms_type
= mst_file_text
;
1105 section
= SECT_OFF_TEXT (objfile
);
1108 ms_type
= mst_file_data
;
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)
1117 /* Same with virtual function tables, both global and static. */
1119 const char *tempstring
= name
;
1121 if (*tempstring
!= '\0'
1122 && *tempstring
== bfd_get_symbol_leading_char (objfile
->obfd
.get ()))
1124 if (is_vtable_name (tempstring
))
1127 section
= SECT_OFF_DATA (objfile
);
1130 ms_type
= mst_file_bss
;
1131 section
= SECT_OFF_BSS (objfile
);
1134 ms_type
= mst_unknown
;
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
;
1143 reader
.record_with_info (name
, address
, ms_type
, section
);
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. */
1150 static legacy_psymtab
*
1151 find_corresponding_bincl_psymtab (const char *name
, int instance
,
1152 struct objfile
* objfile
)
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)
1160 repeated_header_complaint (name
, symnum
);
1161 return (legacy_psymtab
*) 0;
1164 /* Allocate and partially fill a partial symtab. It will be
1165 completely filled at the end of the symbol list.
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
1171 static legacy_psymtab
*
1172 start_psymtab (psymtab_storage
*partial_symtabs
, struct objfile
*objfile
,
1173 const char *filename
, unrelocated_addr textlow
, int ldsymoff
)
1175 legacy_psymtab
*result
= new legacy_psymtab (filename
, partial_symtabs
,
1176 objfile
->per_bfd
, textlow
);
1178 struct dbx_symfile_info
*key
= dbx_objfile_data_key
.get(objfile
);
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
;
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
;
1197 /* See stabsread.h. */
1200 read_stabs_symtab_1 (minimal_symbol_reader
&reader
,
1201 psymtab_storage
*partial_symtabs
,
1202 struct objfile
*objfile
)
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
;
1209 const char *sym_name
;
1211 unsigned int next_file_string_table_offset
= 0;
1212 struct dbx_symfile_info
*dbx
= dbx_objfile_data_key
.get(objfile
);
1214 const char *namestring
;
1216 int past_first_source_file
= 0;
1217 CORE_ADDR last_function_start
= 0;
1219 int textlow_not_set
;
1220 int data_sect_index
;
1222 /* Current partial symtab. */
1223 legacy_psymtab
*pst
;
1225 /* List of current psymtab's include files. */
1226 const char **psymtab_include_list
;
1227 int includes_allocated
;
1230 /* Index within current psymtab dependency list. */
1231 legacy_psymtab
**dependency_list
;
1232 int dependencies_used
, dependencies_allocated
;
1234 text_addr
= DBX_TEXT_ADDR (objfile
);
1235 text_size
= DBX_TEXT_SIZE (objfile
);
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;
1241 dbx
->ctx
.stringtab_global
= DBX_STRINGTAB (objfile
);
1243 pst
= (legacy_psymtab
*) 0;
1245 includes_allocated
= 30;
1247 psymtab_include_list
= (const char **) alloca (includes_allocated
*
1248 sizeof (const char *));
1250 dependencies_allocated
= 30;
1251 dependencies_used
= 0;
1253 (legacy_psymtab
**) alloca (dependencies_allocated
*
1254 sizeof (legacy_psymtab
*));
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
);
1261 set_last_source_file (NULL
);
1263 dbx
->ctx
.lowest_text_address
= (unrelocated_addr
) -1;
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;
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
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.
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
);
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. */
1301 for (symnum
= 0; symnum
< DBX_SYMCOUNT (objfile
); symnum
++)
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
++];
1310 * Special case to speed up readin.
1312 if (bfd_h_get_8 (abfd
, bufp
->e_type
) == N_SLINE
)
1314 dbx
->ctx
.has_line_numbers
= 1;
1318 INTERNALIZE_SYMBOL (nlist
, bufp
, abfd
);
1319 OBJSTAT (objfile
, n_stabs
++);
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:
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. */
1332 switch (nlist
.n_type
)
1335 * Standard, external, non-debugger, symbols
1338 case N_TEXT
| N_EXT
:
1339 case N_NBTEXT
| N_EXT
:
1342 case N_DATA
| N_EXT
:
1343 case N_NBDATA
| N_EXT
:
1348 case N_NBBSS
| N_EXT
:
1349 case N_SETV
| N_EXT
: /* FIXME, is this in BSS? */
1354 namestring
= set_namestring (objfile
, &nlist
);
1356 record_minimal_symbol (reader
, namestring
,
1357 unrelocated_addr (nlist
.n_value
),
1358 nlist
.n_type
, objfile
); /* Always */
1361 /* Standard, local, non-debugger, symbols. */
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. */
1373 namestring
= set_namestring (objfile
, &nlist
);
1375 if ((namestring
[0] == '-' && namestring
[1] == 'l')
1376 || (namestring
[(nsl
= strlen (namestring
)) - 1] == 'o'
1377 && namestring
[nsl
- 2] == '.'))
1379 unrelocated_addr unrel_val
= unrelocated_addr (nlist
.n_value
);
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 ())
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
,
1393 pst
= (legacy_psymtab
*) 0;
1395 dependencies_used
= 0;
1396 dbx
->ctx
.has_line_numbers
= 0;
1399 past_first_source_file
= 1;
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.
1416 All other symbols (with nlist.n_value == 0), are really
1417 undefined, and so we ignore them too. */
1421 if (dbx
->ctx
.processing_acc_compilation
&& nlist
.n_strx
== 1)
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. */
1439 /* Lots of symbol types we can just ignore. */
1446 /* Keep going . . . */
1449 * Special symbol types for GNU
1452 case N_INDR
| N_EXT
:
1454 case N_SETA
| N_EXT
:
1456 case N_SETT
| N_EXT
:
1458 case N_SETD
| N_EXT
:
1460 case N_SETB
| N_EXT
:
1471 static int prev_so_symnum
= -10;
1472 static int first_so_symnum
;
1474 static const char *dirname_nso
;
1475 int prev_textlow_not_set
;
1477 valu
= nlist
.n_value
;
1479 prev_textlow_not_set
= textlow_not_set
;
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. */
1485 if (nlist
.n_value
== 0
1486 && gdbarch_sofun_address_maybe_missing (gdbarch
))
1488 textlow_not_set
= 1;
1492 textlow_not_set
= 0;
1494 past_first_source_file
= 1;
1496 if (prev_so_symnum
!= symnum
- 1)
1497 { /* Here if prev stab wasn't N_SO. */
1498 first_so_symnum
= symnum
;
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 ()
1508 : pst
->unrelocated_text_high (),
1509 dependency_list
, dependencies_used
,
1510 prev_textlow_not_set
);
1511 pst
= (legacy_psymtab
*) 0;
1513 dependencies_used
= 0;
1514 dbx
->ctx
.has_line_numbers
= 0;
1518 prev_so_symnum
= symnum
;
1520 /* End the current partial symtab and start a new one. */
1522 namestring
= set_namestring (objfile
, &nlist
);
1524 /* Null name means end of .o file. Don't start a new one. */
1525 if (*namestring
== '\000')
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. */
1533 p
= lbasename (namestring
);
1534 if (p
!= namestring
&& *p
== '\000')
1536 /* Save the directory name SOs locally, then save it into
1537 the psymtab when it's created below. */
1538 dirname_nso
= namestring
;
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. */
1548 pst
= start_psymtab (partial_symtabs
, objfile
,
1550 unrelocated_addr (valu
),
1551 first_so_symnum
* dbx
->ctx
.symbol_size
);
1552 pst
->dirname
= dirname_nso
;
1560 enum language tmp_language
;
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. */
1566 namestring
= set_namestring (objfile
, &nlist
);
1567 tmp_language
= deduce_language_from_filename (namestring
);
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
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
;
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
);
1587 dbx
->ctx
.bincl_list
.emplace_back (namestring
, nlist
.n_value
, pst
);
1589 /* Mark down an include file in the current psymtab. */
1591 goto record_include_file
;
1596 enum language tmp_language
;
1598 /* Mark down an include file in the current psymtab. */
1599 namestring
= set_namestring (objfile
, &nlist
);
1600 tmp_language
= deduce_language_from_filename (namestring
);
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
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
;
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.
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)
1626 for (i
= 0; i
< includes_used
; i
++)
1627 if (filename_cmp (namestring
, psymtab_include_list
[i
]) == 0)
1636 record_include_file
:
1638 psymtab_include_list
[includes_used
++] = namestring
;
1639 if (includes_used
>= includes_allocated
)
1641 const char **orig
= psymtab_include_list
;
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 *));
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. */
1657 case N_GSYM
: /* Global (extern) variable; can be
1658 data or bss (sigh FIXME). */
1660 /* Following may probably be ignored; I'll leave them here
1661 for now (until I do Pascal and Modula 2 extensions). */
1663 case N_PC
: /* I may or may not need this; I
1665 case N_M2C
: /* I suspect that I can ignore this here. */
1666 case N_SCOPE
: /* Same. */
1670 namestring
= set_namestring (objfile
, &nlist
);
1672 /* See if this is an end of function stab. */
1673 if (pst
&& nlist
.n_type
== N_FUN
&& *namestring
== '\000')
1675 unrelocated_addr valu
;
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
);
1687 p
= (char *) strchr (namestring
, ':');
1689 continue; /* Not a debugging symbol. */
1692 sym_name
= NULL
; /* pacify "gcc -Werror" */
1693 if (dbx
->ctx
.psymtab_language
== language_cplus
)
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)
1700 sym_len
= strlen (new_name
.get ());
1701 sym_name
= obstack_strdup (&objfile
->objfile_obstack
,
1705 else if (dbx
->ctx
.psymtab_language
== language_c
)
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)
1712 sym_len
= strlen (new_name
.get ());
1713 sym_name
= obstack_strdup (&objfile
->objfile_obstack
,
1720 sym_name
= namestring
;
1721 sym_len
= p
- namestring
;
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. */
1735 pst
->add_psymbol (std::string_view (sym_name
, sym_len
), true,
1736 VAR_DOMAIN
, LOC_STATIC
,
1738 psymbol_placement::STATIC
,
1739 unrelocated_addr (nlist
.n_value
),
1740 dbx
->ctx
.psymtab_language
,
1741 partial_symtabs
, objfile
);
1743 complaint (_("static `%*s' appears to be defined "
1744 "outside of all compilation units"),
1749 /* The addresses in these entries are reported to be
1750 wrong. See the code that reads 'G's for symtabs. */
1752 pst
->add_psymbol (std::string_view (sym_name
, sym_len
), true,
1753 VAR_DOMAIN
, LOC_STATIC
,
1755 psymbol_placement::GLOBAL
,
1756 unrelocated_addr (nlist
.n_value
),
1757 dbx
->ctx
.psymtab_language
,
1758 partial_symtabs
, objfile
);
1760 complaint (_("global `%*s' appears to be defined "
1761 "outside of all compilation units"),
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] != ' '))
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
);
1784 complaint (_("enum, struct, or union `%*s' appears "
1785 "to be defined outside of all "
1786 "compilation units"),
1790 /* Also a typedef with the same name. */
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
);
1799 complaint (_("typedef `%*s' appears to be defined "
1800 "outside of all compilation units"),
1808 if (p
!= namestring
) /* a name is there, not just :T... */
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
);
1818 complaint (_("typename `%*s' appears to be defined "
1819 "outside of all compilation units"),
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. */
1832 /* We are looking for something of the form
1833 <name> ":" ("t" | "T") [<number> "="] "e"
1834 {<constant> ":" <value> ","} ";". */
1836 /* Skip over the colon and the 't' or 'T'. */
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
== ')'
1847 /* The aix4 compiler emits extra crud before the members. */
1850 /* Skip over the type (?). */
1854 /* Skip over the colon. */
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.
1863 while (*p
&& *p
!= ';' && *p
!= ',')
1867 /* Check for and handle cretinous dbx symbol name
1869 if (*p
== '\\' || (*p
== '?' && p
[1] == '\0'))
1870 p
= next_symbol_text (objfile
);
1872 /* Point to the character after the name
1873 of the enum constant. */
1874 for (q
= p
; *q
&& *q
!= ':'; q
++)
1876 /* Note that the value doesn't matter for
1877 enum constants in psymtabs, just in symtabs. */
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
);
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. */
1891 /* Skip over the value. */
1892 while (*p
&& *p
!= ',')
1894 /* Advance past the comma. */
1902 /* Constant, e.g. from "const" in Pascal. */
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
);
1911 complaint (_("constant `%*s' appears to be defined "
1912 "outside of all compilation units"),
1920 std::string
name (namestring
, (p
- namestring
));
1921 function_outside_compilation_unit_complaint (name
.c_str ());
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
))
1930 bound_minimal_symbol minsym
1931 = find_stab_function (namestring
,
1932 pst
? pst
->filename
: NULL
, objfile
);
1933 if (minsym
.minsym
!= NULL
)
1935 = CORE_ADDR (minsym
.minsym
->unrelocated_address ());
1937 if (pst
&& textlow_not_set
1938 && gdbarch_sofun_address_maybe_missing (gdbarch
))
1940 pst
->set_text_low (unrelocated_addr (nlist
.n_value
));
1941 textlow_not_set
= 0;
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
;
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. */
1955 || (unrelocated_addr (nlist
.n_value
)
1956 < pst
->unrelocated_text_low ()
1957 && (nlist
.n_value
!= 0))))
1959 pst
->set_text_low (unrelocated_addr (nlist
.n_value
));
1960 textlow_not_set
= 0;
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
);
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. */
1978 std::string
name (namestring
, (p
- namestring
));
1979 function_outside_compilation_unit_complaint (name
.c_str ());
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
))
1988 bound_minimal_symbol minsym
1989 = find_stab_function (namestring
,
1990 pst
? pst
->filename
: NULL
, objfile
);
1991 if (minsym
.minsym
!= NULL
)
1993 = CORE_ADDR (minsym
.minsym
->unrelocated_address ());
1995 if (pst
&& textlow_not_set
1996 && gdbarch_sofun_address_maybe_missing (gdbarch
))
1998 pst
->set_text_low (unrelocated_addr (nlist
.n_value
));
1999 textlow_not_set
= 0;
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
;
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. */
2013 || (unrelocated_addr (nlist
.n_value
)
2014 < pst
->unrelocated_text_low ()
2015 && (nlist
.n_value
!= 0))))
2017 pst
->set_text_low (unrelocated_addr (nlist
.n_value
));
2018 textlow_not_set
= 0;
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
);
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. */
2046 case '#': /* For symbol identification (used in live ranges). */
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 ':'. */
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
2067 complaint (_("unknown symbol descriptor `%c'"),
2070 /* Ignore it; perhaps it is an extension that we don't
2078 namestring
= set_namestring (objfile
, &nlist
);
2080 /* Find the corresponding bincl and mark that psymtab on the
2081 psymtab dependency list. */
2083 legacy_psymtab
*needed_pst
=
2084 find_corresponding_bincl_psymtab (namestring
, nlist
.n_value
, objfile
);
2086 /* If this include file was defined earlier in this file,
2088 if (needed_pst
== pst
)
2096 for (i
= 0; i
< dependencies_used
; i
++)
2097 if (dependency_list
[i
] == needed_pst
)
2103 /* If it's already in the list, skip the rest. */
2107 dependency_list
[dependencies_used
++] = needed_pst
;
2108 if (dependencies_used
>= dependencies_allocated
)
2110 legacy_psymtab
**orig
= dependency_list
;
2114 alloca ((dependencies_allocated
*= 2)
2115 * sizeof (legacy_psymtab
*));
2116 memcpy (dependency_list
, orig
,
2118 * sizeof (legacy_psymtab
*)));
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
);
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
))
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;
2146 dependencies_used
= 0;
2147 dbx
->ctx
.has_line_numbers
= 0;
2153 HANDLE_RBRAC (nlist
.n_value
);
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. */
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. */
2180 case N_OBJ
: /* Useless types from Solaris. */
2183 /* These symbols aren't interesting; don't worry about them. */
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
));
2194 /* If there's stuff to be cleaned up, clean it up. */
2197 /* Don't set high text address of PST lower than it already
2199 unrelocated_addr text_end
2201 ((dbx
->ctx
.lowest_text_address
== (unrelocated_addr
) -1
2203 : CORE_ADDR (dbx
->ctx
.lowest_text_address
))
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
);
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. */
2221 read_stabs_symtab (struct objfile
*objfile
, symfile_add_flags symfile_flags
)
2225 struct dbx_symfile_info
*key
= dbx_objfile_data_key
.get (objfile
);
2227 sym_bfd
= objfile
->obfd
.get ();
2229 stabs_deprecated_warning ();
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. */
2235 key
->ctx
.symfile_relocatable
= bfd_get_file_flags (sym_bfd
) & HAS_RELOC
;
2237 val
= bfd_seek (sym_bfd
, DBX_SYMTAB_OFFSET (objfile
), SEEK_SET
);
2239 perror_with_name (objfile_name (objfile
));
2241 key
->ctx
.symbol_size
= DBX_SYMBOL_SIZE (objfile
);
2242 key
->ctx
.symbol_table_offset
= DBX_SYMTAB_OFFSET (objfile
);
2244 scoped_free_pendings free_pending
;
2246 minimal_symbol_reader
reader (objfile
);
2248 /* Read stabs data from executable file and define symbols. */
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
);
2255 /* Install any minimal symbols that have been collected as the current
2256 minimal symbols for this objfile. */
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. */
2266 cp_set_block_scope (const struct symbol
*symbol
,
2267 struct block
*block
,
2268 struct obstack
*obstack
)
2270 if (symbol
->demangled_name () != NULL
)
2272 /* Try to figure out the appropriate namespace from the
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. */
2280 const char *name
= symbol
->demangled_name ();
2281 unsigned int prefix_len
= cp_entire_prefix_len (name
);
2283 block
->set_scope (obstack_strndup (obstack
, name
, prefix_len
),
2288 bound_minimal_symbol
2289 find_stab_function (const char *namestring
, const char *filename
,
2290 struct objfile
*objfile
)
2294 const char *colon
= strchr (namestring
, ':');
2298 n
= colon
- namestring
;
2300 char *p
= (char *) alloca (n
+ 2);
2301 strncpy (p
, namestring
, n
);
2304 bound_minimal_symbol msym
2305 = lookup_minimal_symbol (current_program_space
, p
, objfile
, filename
);
2306 if (msym
.minsym
== NULL
)
2308 /* Sun Fortran appends an underscore to the minimal symbol name,
2309 try again with an appended underscore if the minimal symbol
2314 = lookup_minimal_symbol (current_program_space
, p
, objfile
, filename
);
2317 if (msym
.minsym
== NULL
&& filename
!= NULL
)
2319 /* Try again without the filename. */
2321 msym
= lookup_minimal_symbol (current_program_space
, p
, objfile
);
2323 if (msym
.minsym
== NULL
&& filename
!= NULL
)
2325 /* And try again for Sun Fortran, but without the filename. */
2328 msym
= lookup_minimal_symbol (current_program_space
, p
, objfile
);
2334 /* Add header file number I for this object file
2335 at the next successive FILENUM. */
2338 add_this_object_header_file (int i
)
2340 if (n_this_object_header_files
== n_allocated_this_object_header_files
)
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));
2348 this_object_header_files
[n_this_object_header_files
++] = i
;
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. */
2357 add_old_header_file (const char *name
, int instance
, struct objfile
*objfile
)
2359 struct header_file
*p
= HEADER_FILES (objfile
);
2362 for (i
= 0; i
< N_HEADER_FILES (objfile
); i
++)
2363 if (filename_cmp (p
[i
].name
, name
) == 0 && instance
== p
[i
].instance
)
2365 add_this_object_header_file (i
);
2368 repeated_header_complaint (name
, symnum
);
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.
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". */
2383 add_new_header_file (const char *name
, int instance
, struct objfile
*objfile
)
2386 struct header_file
*hfile
;
2388 /* Make sure there is room for one more header file. */
2390 i
= N_ALLOCATED_HEADER_FILES (objfile
);
2392 if (N_HEADER_FILES (objfile
) == i
)
2396 N_ALLOCATED_HEADER_FILES (objfile
) = 10;
2397 HEADER_FILES (objfile
) = (struct header_file
*)
2398 xmalloc (10 * sizeof (struct header_file
));
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
)));
2410 /* Create an entry for this header file. */
2412 i
= N_HEADER_FILES (objfile
)++;
2413 hfile
= HEADER_FILES (objfile
) + i
;
2414 hfile
->name
= xstrdup (name
);
2415 hfile
->instance
= instance
;
2417 hfile
->vector
= XCNEWVEC (struct type
*, 10);
2419 add_this_object_header_file (i
);
2422 /* See stabsread.h. */
2425 process_one_symbol (int type
, int desc
, CORE_ADDR valu
, const char *name
,
2426 const section_offsets
§ion_offsets
,
2427 struct objfile
*objfile
, enum language language
)
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
2438 static CORE_ADDR function_start_offset
;
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
;
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
2448 static int sline_found_in_function
= 1;
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
;
2454 /* The section index for this symbol. */
2455 int section_index
= -1;
2457 struct dbx_symfile_info
*key
= dbx_objfile_data_key
.get (objfile
);
2459 /* Something is wrong if we see real data before seeing a source
2462 if (get_last_source_file () == NULL
&& type
!= (unsigned char) N_SO
)
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 (). */
2476 if (*name
== '\000')
2478 /* This N_FUN marks the end of a function. This closes off
2479 the current block. */
2480 struct block
*block
;
2482 if (outermost_context_p ())
2484 lbrac_mismatch_complaint (symnum
);
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
)
2494 CORE_ADDR addr
= last_function_start
+ valu
;
2497 (get_current_subfile (), 0,
2498 unrelocated_addr (gdbarch_addr_bits_remove (gdbarch
, addr
)
2499 - objfile
->text_section_offset ()));
2502 within_function
= 0;
2503 cstk
= pop_context ();
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
);
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
);
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;
2521 sline_found_in_function
= 0;
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
;
2529 goto define_a_symbol
;
2532 /* This "symbol" just indicates the start of an inner lexical
2533 context within a function. */
2535 /* Ignore extra outermost context from SunPRO cc and acc. */
2536 if (n_opt_found
&& desc
== 1)
2539 valu
+= function_start_offset
;
2541 push_context (desc
, valu
);
2545 /* This "symbol" just indicates the end of an inner lexical
2546 context that was started with N_LBRAC. */
2548 /* Ignore extra outermost context from SunPRO cc and acc. */
2549 if (n_opt_found
&& desc
== 1)
2552 valu
+= function_start_offset
;
2554 if (outermost_context_p ())
2556 lbrac_mismatch_complaint (symnum
);
2560 cstk
= pop_context ();
2561 if (desc
!= cstk
.depth
)
2562 lbrac_mismatch_complaint (symnum
);
2564 if (*get_local_symbols () != NULL
)
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"));
2573 *get_local_symbols () = cstk
.locals
;
2575 if (get_context_stack_depth () > 1)
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
)
2585 /* Muzzle a compiler bug that makes end < start.
2587 ??? Which compilers? Is this ever harmful?. */
2588 if (cstk
.start_addr
> valu
)
2590 complaint (_("block start larger than block end"));
2591 cstk
.start_addr
= valu
;
2593 /* Make a block for the local symbols within. */
2594 finish_block (0, cstk
.old_blocks
, NULL
,
2595 cstk
.start_addr
, valu
);
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;
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
)];
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
)];
2627 if (get_last_source_file ())
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
)
2635 patch_subfile_names (get_current_subfile (), name
);
2636 break; /* Ignore repeated SOs. */
2638 end_compunit_symtab (valu
);
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')
2647 function_start_offset
= 0;
2650 start_compunit_symtab (objfile
, name
, NULL
, valu
, language
);
2651 record_debugformat ("stabs");
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
);
2666 add_new_header_file (name
, valu
, objfile
);
2667 start_subfile (name
);
2671 start_subfile (pop_subfile ());
2675 add_old_header_file (name
, valu
, objfile
);
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. */
2683 /* Relocate for dynamic loading and for ELF acc
2684 function-relative symbols. */
2685 valu
+= function_start_offset
;
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.
2698 So for now, keep adjusting the address of the first N_SLINE
2699 stab, but only for code compiled with GCC. */
2701 if (within_function
&& sline_found_in_function
== 0)
2703 CORE_ADDR addr
= processing_gcc_compilation
== 2 ?
2704 last_function_start
: valu
;
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;
2714 (get_current_subfile (), desc
,
2715 unrelocated_addr (gdbarch_addr_bits_remove (gdbarch
, valu
)
2716 - objfile
->text_section_offset ()));
2720 common_block_start (name
, objfile
);
2724 common_block_end (objfile
);
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. */
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
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
2753 if (!key
->ctx
.symfile_relocatable
)
2755 p
= strchr (name
, ':');
2756 if (p
!= 0 && p
[1] == 'S')
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
;
2769 /* Since it's not the kludge case, re-dispatch to the right
2780 internal_error (_("failed internal consistency check"));
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
;
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
;
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
;
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
;
2808 /* The following symbol types we don't know how to process.
2809 Handle them in a "default" way, but complain to people who
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??? */
2824 unknown_symtype_complaint (hex_string (type
));
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. */
2842 const char *colon_pos
= strchr (name
, ':');
2844 if (colon_pos
== NULL
)
2847 deftype
= colon_pos
[1];
2853 /* Deal with the SunPRO 3.0 compiler which omits the
2854 address from N_FUN symbols. */
2856 && valu
== section_offsets
[SECT_OFF_TEXT (objfile
)]
2857 && gdbarch_sofun_address_maybe_missing (gdbarch
))
2859 bound_minimal_symbol minsym
2860 = find_stab_function (name
, get_last_source_file (),
2862 if (minsym
.minsym
!= NULL
)
2863 valu
= minsym
.value_address ();
2866 /* These addresses are absolute. */
2867 function_start_offset
= valu
;
2869 within_function
= 1;
2871 if (get_context_stack_depth () > 1)
2873 complaint (_("unmatched N_LBRAC before symtab pos %d"),
2878 if (!outermost_context_p ())
2880 struct block
*block
;
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
);
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
);
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
);
2902 struct symbol
*sym
= define_symbol (valu
, name
, desc
, type
,
2905 sym
->set_section_index (section_index
);
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. */
2918 if (strcmp (name
, GCC2_COMPILED_FLAG_SYMBOL
) == 0)
2920 processing_gcc_compilation
= 2;
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) */
2937 set_objfile_main_name (objfile
, name
, language_unknown
);
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. */
2951 /* '#' is a GNU C extension to allow one symbol to refer to another
2954 Generally this is used so that an alias can refer to its main
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. */
2963 const char *s
= name
;
2966 /* If this stab defines a new reference ID that is not on the
2967 reference list, then put it on the reference list.
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
);
2973 if (!ref_search (refnum
))
2974 ref_add (refnum
, 0, name
, valu
);
2978 previous_stab_code
= type
;
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 */
2986 /* Structure for storing pointers to reference definitions for fast lookup
2987 during "process_later". */
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)
3000 static struct ref_map
*ref_map
;
3002 /* Ptr to free cell in chunk's linked list. */
3003 static int ref_count
= 0;
3005 /* Number of chunks malloced. */
3006 static int ref_chunk
= 0;
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. */
3012 stabsread_clear_cache (void)
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. */
3023 ref_add (int refnum
, struct symbol
*sym
, const char *stabs
, CORE_ADDR value
)
3027 if (refnum
>= ref_count
)
3028 ref_count
= refnum
+ 1;
3029 if (ref_count
> ref_chunk
* MAX_CHUNK_REFS
)
3031 int new_slots
= ref_count
- ref_chunk
* MAX_CHUNK_REFS
;
3032 int new_chunks
= new_slots
/ MAX_CHUNK_REFS
+ 1;
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
;
3040 ref_map
[refnum
].stabs
= stabs
;
3041 ref_map
[refnum
].sym
= sym
;
3042 ref_map
[refnum
].value
= value
;
3045 /* Return defined sym for the reference REFNUM. */
3047 ref_search (int refnum
)
3049 if (refnum
< 0 || refnum
> ref_count
)
3051 return ref_map
[refnum
].sym
;
3054 /* Parse a reference id in STRING and return the resulting
3055 reference number. Move STRING beyond the reference id. */
3058 process_reference (const char **string
)
3063 if (**string
!= '#')
3066 /* Advance beyond the initial '#'. */
3069 /* Read number as reference id. */
3070 while (*p
&& isdigit (*p
))
3072 refnum
= refnum
* 10 + *p
- '0';
3079 /* If STRING defines a reference, store away a pointer to the reference
3080 definition for later use. Return the reference number. */
3083 symbol_reference_defined (const char **string
)
3085 const char *p
= *string
;
3088 refnum
= process_reference (&p
);
3090 /* Defining symbols end in '='. */
3093 /* Symbol is being defined here. */
3099 /* Must be a reference. Either the symbol has already been defined,
3100 or this is a forward reference to it. */
3107 stab_reg_to_regnum (struct symbol
*sym
, struct gdbarch
*gdbarch
)
3109 int regno
= gdbarch_stab_reg_to_regnum (gdbarch
, sym
->value_longest ());
3111 if (regno
< 0 || regno
>= gdbarch_num_cooked_regs (gdbarch
))
3113 reg_value_complaint (regno
, gdbarch_num_cooked_regs (gdbarch
),
3114 sym
->print_name ());
3116 regno
= gdbarch_sp_regnum (gdbarch
); /* Known safe, though useless. */
3122 static const struct symbol_register_ops stab_register_funcs
= {
3126 /* The "aclass" indices for computed symbols. */
3128 static int stab_register_index
;
3129 static int stab_regparm_index
;
3132 define_symbol (CORE_ADDR valu
, const char *string
, int desc
, int type
,
3133 struct objfile
*objfile
)
3135 struct gdbarch
*gdbarch
= objfile
->arch ();
3137 const char *p
= find_name_end (string
);
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. */
3149 /* Ignore syms with empty names. */
3153 /* Ignore old-style symbols from cc -go. */
3160 p
= strchr (p
, ':');
3164 _("Bad stabs string '%s'"), string
);
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] == ':')));
3173 current_symbol
= sym
= new (&objfile
->objfile_obstack
) symbol
;
3175 if (processing_gcc_compilation
)
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
);
3183 sym
->set_line (0); /* unknown */
3186 sym
->set_language (get_current_subfile ()->language
,
3187 &objfile
->objfile_obstack
);
3189 if (is_cplus_marker (string
[0]))
3191 /* Special GNU C++ names. */
3195 sym
->set_linkage_name ("this");
3198 case 'v': /* $vtbl_ptr_type */
3202 sym
->set_linkage_name ("eh_throw");
3206 /* This was an anonymous type that was never fixed up. */
3210 complaint (_("Unknown C++ symbol name `%s'"),
3212 goto normal
; /* Do *something* with it. */
3218 gdb::unique_xmalloc_ptr
<char> new_name
;
3220 if (sym
->language () == language_cplus
)
3222 std::string
name (string
, p
- string
);
3223 new_name
= cp_canonicalize_string (name
.c_str ());
3225 else if (sym
->language () == language_c
)
3227 std::string
name (string
, p
- string
);
3228 new_name
= c_canonicalize_name (name
.c_str ());
3230 if (new_name
!= nullptr)
3231 sym
->compute_and_set_names (new_name
.get (), true, objfile
->per_bfd
);
3233 sym
->compute_and_set_names (std::string_view (string
, p
- string
), true,
3236 if (sym
->language () == language_cplus
)
3237 cp_scan_for_anonymous_namespaces (get_buildsym_compunit (), sym
,
3243 /* Determine the type of name being defined. */
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
))
3254 if (isdigit (*p
) || *p
== '(' || *p
== '-')
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,;"). */
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 ());
3283 struct type
*dbl_type
;
3285 dbl_type
= builtin_type (objfile
)->builtin_double
;
3287 = (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
,
3288 dbl_type
->length ());
3290 target_float_from_string (dbl_valu
, dbl_type
, std::string (p
));
3292 sym
->set_type (dbl_type
);
3293 sym
->set_value_bytes (dbl_valu
);
3294 sym
->set_aclass_index (LOC_CONST_BYTES
);
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. */
3306 sym
->set_type (builtin_type (objfile
)->builtin_long
);
3307 sym
->set_value_longest (atoi (p
));
3308 sym
->set_aclass_index (LOC_CONST
);
3314 sym
->set_type (builtin_type (objfile
)->builtin_char
);
3315 sym
->set_value_longest (atoi (p
));
3316 sym
->set_aclass_index (LOC_CONST
);
3322 struct type
*range_type
;
3325 gdb_byte
*string_local
= (gdb_byte
*) alloca (strlen (p
));
3326 gdb_byte
*string_value
;
3328 if (quote
!= '\'' && quote
!= '"')
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 ());
3337 /* Find matching quote, rejecting escaped quotes. */
3338 while (*p
&& *p
!= quote
)
3340 if (*p
== '\\' && p
[1] == quote
)
3342 string_local
[ind
] = (gdb_byte
) quote
;
3348 string_local
[ind
] = (gdb_byte
) (*p
);
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 ());
3362 /* NULL terminate the string. */
3363 string_local
[ind
] = 0;
3364 type_allocator
alloc (objfile
, get_current_subfile ()->language
);
3366 = create_static_range_type (alloc
,
3367 builtin_type (objfile
)->builtin_int
,
3370 (create_array_type (alloc
, builtin_type (objfile
)->builtin_char
,
3373 = (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, ind
+ 1);
3374 memcpy (string_value
, string_local
, ind
+ 1);
3377 sym
->set_value_bytes (string_value
);
3378 sym
->set_aclass_index (LOC_CONST_BYTES
);
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,;"). */
3388 sym
->set_aclass_index (LOC_CONST
);
3389 sym
->set_type (read_type (&p
, objfile
));
3393 sym
->set_type (error_type (&p
, objfile
));
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,
3404 sym
->set_value_longest (atoi (p
));
3409 sym
->set_aclass_index (LOC_CONST
);
3410 sym
->set_type (error_type (&p
, objfile
));
3413 sym
->set_domain (VAR_DOMAIN
);
3414 add_symbol_to_list (sym
, get_file_symbols ());
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 ());
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. */
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 ()));
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);
3449 /* fall into process_prototype_types. */
3451 process_prototype_types
:
3452 /* Sun acc puts declared types of arguments here. */
3455 struct type
*ftype
= sym
->type ();
3460 /* Obtain a worst case guess for the number of arguments
3461 by counting the semicolons. */
3468 /* Allocate parameter information fields and fill them in. */
3469 ftype
->alloc_fields (nsemi
);
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')
3478 ptype
= read_type (&p
, objfile
);
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);
3492 ftype
->set_num_fields (nparams
);
3493 ftype
->set_is_prototyped (true);
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
;
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] != '#')
3519 i
= hashname (sym
->linkage_name ());
3520 sym
->set_value_chain (global_sym_chain
[i
]);
3521 global_sym_chain
[i
] = sym
;
3523 add_symbol_to_list (sym
, get_global_symbols ());
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'. */
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 ());
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. */
3546 (lookup_pointer_type
3547 (lookup_function_type (read_type (&p
, objfile
))));
3550 sym
->set_type (read_type (&p
, objfile
));
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 ());
3558 if (gdbarch_byte_order (gdbarch
) != BFD_ENDIAN_BIG
)
3560 /* On little-endian machines, this crud is never necessary,
3561 and, if the extra bytes contain garbage, is harmful. */
3565 /* If it's gcc-compiled, if it says `short', believe it. */
3566 if (processing_gcc_compilation
3567 || gdbarch_believe_pcc_promotion (gdbarch
))
3570 if (!gdbarch_believe_pcc_promotion (gdbarch
))
3572 /* If PCC says a parameter is a short or a char, it is
3574 if (sym
->type ()->length ()
3575 < gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
3576 && sym
->type ()->code () == TYPE_CODE_INT
)
3579 (sym
->type ()->is_unsigned ()
3580 ? builtin_type (objfile
)->builtin_unsigned_int
3581 : builtin_type (objfile
)->builtin_int
);
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. */
3593 sym
->set_type (read_type (&p
, objfile
));
3594 goto process_prototype_types
;
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 ());
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
)
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
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,
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. */
3635 struct pending
*local_symbols
= *get_local_symbols ();
3637 && local_symbols
->nsyms
> 0
3638 && gdbarch_stabs_argument_has_addr (gdbarch
, sym
->type ()))
3640 struct symbol
*prev_sym
;
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)
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 ());
3657 add_symbol_to_list (sym
, get_local_symbols ());
3660 add_symbol_to_list (sym
, get_file_symbols ());
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 ());
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'.
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.
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');
3690 sym
->set_type (read_type (&p
, objfile
));
3692 /* For a nameless type, we don't want a create a symbol, thus we
3693 did not use `sym'. Return without further processing. */
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 ()))
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 ());
3717 if (sym
->type ()->name () == NULL
)
3719 if ((sym
->type ()->code () == TYPE_CODE_PTR
3720 && strcmp (sym
->linkage_name (), vtbl_ptr_name
))
3721 || sym
->type ()->code () == TYPE_CODE_FUNC
)
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
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().
3746 typedef char *caddr_t;
3758 /* Pascal accepts names for pointer types. */
3759 if (get_current_subfile ()->language
== language_pascal
)
3760 sym
->type ()->set_name (sym
->linkage_name ());
3763 sym
->type ()->set_name (sym
->linkage_name ());
3766 add_symbol_to_list (sym
, get_file_symbols ());
3770 /* Create the STRUCT_DOMAIN clone. */
3771 struct symbol
*struct_sym
= new (&objfile
->objfile_obstack
) symbol
;
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 (),
3781 add_symbol_to_list (struct_sym
, get_file_symbols ());
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';
3794 sym
->set_type (read_type (&p
, objfile
));
3796 /* For a nameless type, we don't want a create a symbol, thus we
3797 did not use `sym'. Return without further processing. */
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 (),
3808 add_symbol_to_list (sym
, get_file_symbols ());
3812 /* Clone the sym and then modify it. */
3813 struct symbol
*typedef_sym
= new (&objfile
->objfile_obstack
) symbol
;
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 (),
3823 add_symbol_to_list (typedef_sym
, get_file_symbols ());
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 ());
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 ());
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 ());
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 ());
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 ());
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. */
3881 if (gdbarch_stabs_argument_has_addr (gdbarch
, sym
->type ())
3882 && sym
->is_argument ())
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
);
3897 /* Skip rest of this symbol and return an error type.
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:
3903 if (*(*pp)++ != ';')
3904 return error_type (pp, objfile);
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
3912 return error_type (pp, objfile);
3918 foo = error_type (pp, objfile);
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. */
3926 static struct type
*
3927 error_type (const char **pp
, struct objfile
*objfile
)
3929 complaint (_("couldn't parse type; debugger out of date?"));
3932 /* Skip to end of symbol. */
3933 while (**pp
!= '\0')
3938 /* Check for and handle cretinous dbx symbol name continuation! */
3939 if ((*pp
)[-1] == '\\' || (*pp
)[-1] == '?')
3941 *pp
= next_symbol_text (objfile
);
3948 return builtin_type (objfile
)->builtin_error
;
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
3958 static struct type
*
3959 allocate_stub_method (struct type
*type
)
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 */
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. */
3978 static struct type
*
3979 read_type (const char **pp
, struct objfile
*objfile
)
3981 struct type
*type
= 0;
3984 char type_descriptor
;
3986 /* Size in bits of type if specified by a type attribute, or -1 if
3987 there is no size attribute. */
3990 /* Used to distinguish string and bitstring from char-array and set. */
3993 /* Used to distinguish vector from array. */
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')
4003 if (read_type_number (pp
, typenums
) != 0)
4004 return error_type (pp
, objfile
);
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
);
4013 /* If this is a forward reference, arrange to complain if it
4014 doesn't get patched up by the time we're done
4016 if (type
->code () == TYPE_CODE_UNDEF
)
4017 add_undefined_type (type
, typenums
);
4022 /* Type is being defined here. */
4024 Also skip the type descriptor - we get it below with (*pp)[-1]. */
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;
4036 type_descriptor
= (*pp
)[-1];
4037 switch (type_descriptor
)
4041 enum type_code code
;
4043 /* Used to index through file_symbols. */
4044 struct pending
*ppt
;
4047 /* Name including "struct", etc. */
4051 const char *from
, *p
, *q1
, *q2
;
4053 /* Set the type code according to the following letter. */
4057 code
= TYPE_CODE_STRUCT
;
4060 code
= TYPE_CODE_UNION
;
4063 code
= TYPE_CODE_ENUM
;
4067 /* Complain and keep going, so compilers can invent new
4068 cross-reference types. */
4069 complaint (_("Unrecognized cross-reference type `%c'"),
4071 code
= TYPE_CODE_STRUCT
;
4076 q1
= strchr (*pp
, '<');
4077 p
= strchr (*pp
, ':');
4079 return error_type (pp
, objfile
);
4080 if (q1
&& p
> q1
&& p
[1] == ':')
4082 int nesting_level
= 0;
4084 for (q2
= q1
; *q2
; q2
++)
4088 else if (*q2
== '>')
4090 else if (*q2
== ':' && nesting_level
== 0)
4095 return error_type (pp
, objfile
);
4098 if (get_current_subfile ()->language
== language_cplus
)
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
,
4107 else if (get_current_subfile ()->language
== language_c
)
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
,
4116 if (type_name
== NULL
)
4118 char *to
= type_name
= (char *)
4119 obstack_alloc (&objfile
->objfile_obstack
, p
- *pp
+ 1);
4121 /* Copy the name. */
4128 /* Set the pointer ahead of the name which we just read, and
4133 /* If this type has already been declared, then reuse the same
4134 type, rather than allocating a new one. This saves some
4137 for (ppt
= *get_file_symbols (); ppt
; ppt
= ppt
->next
)
4138 for (i
= 0; i
< ppt
->nsyms
; i
++)
4140 struct symbol
*sym
= ppt
->symbol
[i
];
4142 if (sym
->aclass () == LOC_TYPEDEF
4143 && sym
->domain () == STRUCT_DOMAIN
4144 && (sym
->type ()->code () == code
)
4145 && strcmp (sym
->linkage_name (), type_name
) == 0)
4147 obstack_free (&objfile
->objfile_obstack
, type_name
);
4148 type
= sym
->type ();
4149 if (typenums
[0] != -1)
4150 *dbx_lookup_type (typenums
, objfile
) = type
;
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
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);
4166 add_undefined_type (type
, typenums
);
4170 case '-': /* RS/6000 built-in type */
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. */
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
);
4192 struct type
*xtype
= read_type (pp
, objfile
);
4196 /* It's being defined as itself. That means it is "void". */
4197 type
->set_code (TYPE_CODE_VOID
);
4198 type
->set_length (1);
4200 else if (type_size
>= 0 || is_string
)
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.
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.
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
);
4230 type
->set_target_is_stub (true);
4231 type
->set_target_type (xtype
);
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*. */
4243 case '*': /* Pointer to another type */
4244 type1
= read_type (pp
, objfile
);
4245 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
, objfile
));
4248 case '&': /* Reference to another type */
4249 type1
= read_type (pp
, objfile
);
4250 type
= make_reference_type (type1
, dbx_lookup_type (typenums
, objfile
),
4254 case 'f': /* Function returning another type */
4255 type1
= read_type (pp
, objfile
);
4256 type
= make_function_type (type1
, dbx_lookup_type (typenums
, objfile
));
4259 case 'g': /* Prototyped function. (Sun) */
4261 /* Unresolved questions:
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.
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
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
));
4283 struct type_list
*next
;
4287 while (**pp
&& **pp
!= '#')
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
;
4300 complaint (_("Prototyped function type didn't "
4301 "end arguments with `#':\n%s"),
4305 /* If there is just one argument whose type is `void', then
4306 that's just an empty argument list. */
4308 && ! arg_types
->next
4309 && arg_types
->type
->code () == TYPE_CODE_VOID
)
4312 func_type
->alloc_fields (num_args
);
4315 struct type_list
*t
;
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
);
4323 func_type
->set_num_fields (num_args
);
4324 func_type
->set_is_prototyped (true);
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
));
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
));
4343 if (isdigit (**pp
) || **pp
== '(' || **pp
== '-')
4344 { /* Member (class & variable) type */
4345 /* FIXME -- we should be doing smash_to_XXX types here. */
4347 struct type
*domain
= read_type (pp
, objfile
);
4348 struct type
*memtype
;
4351 /* Invalid member type data format. */
4352 return error_type (pp
, objfile
);
4355 memtype
= read_type (pp
, objfile
);
4356 type
= dbx_alloc_type (typenums
, objfile
);
4357 smash_to_memberptr_type (type
, domain
, memtype
);
4360 /* type attribute */
4362 const char *attr
= *pp
;
4364 /* Skip to the semicolon. */
4365 while (**pp
!= ';' && **pp
!= '\0')
4368 return error_type (pp
, objfile
);
4370 ++ * pp
; /* Skip the semicolon. */
4374 case 's': /* Size attribute */
4375 type_size
= atoi (attr
+ 1);
4380 case 'S': /* String attribute */
4381 /* FIXME: check to see if following type is array? */
4385 case 'V': /* Vector attribute */
4386 /* FIXME: check to see if following type is array? */
4391 /* Ignore unrecognized type attributes, so future compilers
4392 can invent new ones. */
4400 case '#': /* Method (class & fn) type */
4401 if ((*pp
)[0] == '#')
4403 /* We'll get the parameter types from the name. */
4404 struct type
*return_type
;
4407 return_type
= read_type (pp
, objfile
);
4408 if (*(*pp
)++ != ';')
4409 complaint (_("invalid (minimal) member type "
4410 "data format at symtab pos %d."),
4412 type
= allocate_stub_method (return_type
);
4413 if (typenums
[0] != -1)
4414 *dbx_lookup_type (typenums
, objfile
) = type
;
4418 struct type
*domain
= read_type (pp
, objfile
);
4419 struct type
*return_type
;
4424 /* Invalid member type data format. */
4425 return error_type (pp
, objfile
);
4429 return_type
= read_type (pp
, objfile
);
4430 args
= read_args (pp
, ';', objfile
, &nargs
, &varargs
);
4432 return error_type (pp
, objfile
);
4433 type
= dbx_alloc_type (typenums
, objfile
);
4434 smash_to_method_type (type
, domain
, return_type
, args
,
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
;
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
;
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
;
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
;
4467 case 's': /* Struct type */
4468 case 'u': /* Union type */
4470 enum type_code type_code
= TYPE_CODE_UNDEF
;
4471 type
= dbx_alloc_type (typenums
, objfile
);
4472 switch (type_descriptor
)
4475 type_code
= TYPE_CODE_STRUCT
;
4478 type_code
= TYPE_CODE_UNION
;
4481 type
= read_struct_type (pp
, type
, type_code
, objfile
);
4485 case 'a': /* Array type */
4487 return error_type (pp
, objfile
);
4490 type
= dbx_alloc_type (typenums
, objfile
);
4491 type
= read_array_type (pp
, type
, objfile
);
4493 type
->set_code (TYPE_CODE_STRING
);
4495 make_vector_type (type
);
4498 case 'S': /* Set type */
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
;
4509 --*pp
; /* Go back to the symbol in error. */
4510 /* Particularly important if it was \0! */
4511 return error_type (pp
, objfile
);
4516 warning (_("GDB internal error, type is NULL in stabsread.c."));
4517 return error_type (pp
, objfile
);
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
);
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. */
4530 static const registry
<objfile
>::key
<struct type
*,
4531 gdb::noop_deleter
<struct type
*>>
4532 rs6000_builtin_type_data
;
4534 static struct type
*
4535 rs6000_builtin_type (int typenum
, struct objfile
*objfile
)
4537 struct type
**negative_types
= rs6000_builtin_type_data
.get (objfile
);
4539 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
4540 #define NUMBER_RECOGNIZED 34
4541 struct type
*rettype
= NULL
;
4543 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
4545 complaint (_("Unknown builtin type %d"), typenum
);
4546 return builtin_type (objfile
)->builtin_error
;
4549 if (!negative_types
)
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
);
4557 if (negative_types
[-typenum
] != NULL
)
4558 return negative_types
[-typenum
];
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
4568 type_allocator
alloc (objfile
, get_current_subfile ()->language
);
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");
4580 rettype
= init_integer_type (alloc
, 8, 0, "char");
4581 rettype
->set_has_no_signedness (true);
4584 rettype
= init_integer_type (alloc
, 16, 0, "short");
4587 rettype
= init_integer_type (alloc
, 32, 0, "long");
4590 rettype
= init_integer_type (alloc
, 8, 1, "unsigned char");
4593 rettype
= init_integer_type (alloc
, 8, 0, "signed char");
4596 rettype
= init_integer_type (alloc
, 16, 1, "unsigned short");
4599 rettype
= init_integer_type (alloc
, 32, 1, "unsigned int");
4602 rettype
= init_integer_type (alloc
, 32, 1, "unsigned");
4605 rettype
= init_integer_type (alloc
, 32, 1, "unsigned long");
4608 rettype
= alloc
.new_type (TYPE_CODE_VOID
, TARGET_CHAR_BIT
, "void");
4611 /* IEEE single precision (32 bit). */
4612 rettype
= init_float_type (alloc
, 32, "float",
4613 floatformats_ieee_single
);
4616 /* IEEE double precision (64 bit). */
4617 rettype
= init_float_type (alloc
, 64, "double",
4618 floatformats_ieee_double
);
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
);
4628 rettype
= init_integer_type (alloc
, 32, 0, "integer");
4631 rettype
= init_boolean_type (alloc
, 32, 1, "boolean");
4634 rettype
= init_float_type (alloc
, 32, "short real",
4635 floatformats_ieee_single
);
4638 rettype
= init_float_type (alloc
, 64, "real",
4639 floatformats_ieee_double
);
4642 rettype
= alloc
.new_type (TYPE_CODE_ERROR
, 0, "stringptr");
4645 rettype
= init_character_type (alloc
, 8, 1, "character");
4648 rettype
= init_boolean_type (alloc
, 8, 1, "logical*1");
4651 rettype
= init_boolean_type (alloc
, 16, 1, "logical*2");
4654 rettype
= init_boolean_type (alloc
, 32, 1, "logical*4");
4657 rettype
= init_boolean_type (alloc
, 32, 1, "logical");
4660 /* Complex type consisting of two IEEE single precision values. */
4661 rettype
= init_complex_type ("complex",
4662 rs6000_builtin_type (12, objfile
));
4665 /* Complex type consisting of two IEEE double precision values. */
4666 rettype
= init_complex_type ("double complex",
4667 rs6000_builtin_type (13, objfile
));
4670 rettype
= init_integer_type (alloc
, 8, 0, "integer*1");
4673 rettype
= init_integer_type (alloc
, 16, 0, "integer*2");
4676 rettype
= init_integer_type (alloc
, 32, 0, "integer*4");
4679 rettype
= init_character_type (alloc
, 16, 0, "wchar");
4682 rettype
= init_integer_type (alloc
, 64, 0, "long long");
4685 rettype
= init_integer_type (alloc
, 64, 1, "unsigned long long");
4688 rettype
= init_integer_type (alloc
, 64, 1, "logical*8");
4691 rettype
= init_integer_type (alloc
, 64, 0, "integer*8");
4694 negative_types
[-typenum
] = rettype
;
4698 /* This page contains subroutines of read_type. */
4700 /* Wrapper around method_name_from_physname to flag a complaint
4701 if there is an error. */
4704 stabs_method_name_from_physname (const char *physname
)
4708 method_name
= method_name_from_physname (physname
);
4710 if (method_name
== NULL
)
4712 complaint (_("Method has bad physname %s\n"), physname
);
4719 /* Read member function stabs info for C++ classes. The form of each member
4722 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
4724 An example with two member functions is:
4726 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
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.
4732 Returns 1 for success, 0 for failure. */
4735 read_member_functions (struct stab_field_info
*fip
, const char **pp
,
4736 struct type
*type
, struct objfile
*objfile
)
4743 struct next_fnfield
*next
;
4744 struct fn_field fn_field
;
4747 struct type
*look_ahead_type
;
4748 struct next_fnfieldlist
*new_fnlist
;
4749 struct next_fnfield
*new_sublist
;
4753 /* Process each list until we find something that is not a member function
4754 or find the end of the functions. */
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. */
4772 look_ahead_type
= NULL
;
4775 new_fnlist
= OBSTACK_ZALLOC (&fip
->obstack
, struct next_fnfieldlist
);
4777 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && is_cplus_marker ((*pp
)[2]))
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
4788 static char opname
[32] = "op$";
4789 char *o
= opname
+ 3;
4791 /* Skip past '::'. */
4794 STABS_CONTINUE (pp
, objfile
);
4800 main_fn_name
= savestring (opname
, o
- opname
);
4806 main_fn_name
= savestring (*pp
, p
- *pp
);
4807 /* Skip past '::'. */
4810 new_fnlist
->fn_fieldlist
.name
= main_fn_name
;
4814 new_sublist
= OBSTACK_ZALLOC (&fip
->obstack
, struct next_fnfield
);
4816 /* Check for and handle cretinous dbx symbol name continuation! */
4817 if (look_ahead_type
== NULL
)
4820 STABS_CONTINUE (pp
, objfile
);
4822 new_sublist
->fn_field
.type
= read_type (pp
, objfile
);
4825 /* Invalid symtab info for member function. */
4831 /* g++ version 1 kludge */
4832 new_sublist
->fn_field
.type
= look_ahead_type
;
4833 look_ahead_type
= NULL
;
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
);
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 ())
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;
4855 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
4858 /* Set this member function's visibility fields. */
4861 case VISIBILITY_PRIVATE
:
4862 new_sublist
->fn_field
.accessibility
= accessibility::PRIVATE
;
4864 case VISIBILITY_PROTECTED
:
4865 new_sublist
->fn_field
.accessibility
= accessibility::PROTECTED
;
4869 STABS_CONTINUE (pp
, objfile
);
4872 case 'A': /* Normal functions. */
4873 new_sublist
->fn_field
.is_const
= 0;
4874 new_sublist
->fn_field
.is_volatile
= 0;
4877 case 'B': /* `const' member functions. */
4878 new_sublist
->fn_field
.is_const
= 1;
4879 new_sublist
->fn_field
.is_volatile
= 0;
4882 case 'C': /* `volatile' member function. */
4883 new_sublist
->fn_field
.is_const
= 0;
4884 new_sublist
->fn_field
.is_volatile
= 1;
4887 case 'D': /* `const volatile' member function. */
4888 new_sublist
->fn_field
.is_const
= 1;
4889 new_sublist
->fn_field
.is_volatile
= 1;
4892 case '*': /* File compiled with g++ version 1 --
4898 complaint (_("const/volatile indicator missing, got '%c'"),
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;
4920 STABS_CONTINUE (pp
, objfile
);
4921 if (**pp
== ';' || **pp
== '\0')
4923 /* Must be g++ version 1. */
4924 new_sublist
->fn_field
.fcontext
= 0;
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
);
4934 /* g++ version 1 overloaded methods. */
4938 new_sublist
->fn_field
.fcontext
= look_ahead_type
;
4947 look_ahead_type
= NULL
;
4953 /* static member function. */
4955 int slen
= strlen (main_fn_name
);
4957 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
4959 /* For static member functions, we can't tell if they
4960 are stubbed, as they are put out as functions, and not as
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] == '_'))
4974 new_sublist
->fn_field
.is_stub
= 1;
4981 complaint (_("member function type missing, got '%c'"),
4983 /* Normal member function. */
4987 /* normal member function. */
4988 new_sublist
->fn_field
.voffset
= 0;
4989 new_sublist
->fn_field
.fcontext
= 0;
4993 new_sublist
->next
= sublist
;
4994 sublist
= new_sublist
;
4996 STABS_CONTINUE (pp
, objfile
);
4998 while (**pp
!= ';' && **pp
!= '\0');
5001 STABS_CONTINUE (pp
, objfile
);
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)
5009 xfree (main_fn_name
);
5013 int has_destructor
= 0, has_other
= 0;
5015 struct next_fnfield
*tmp_sublist
;
5017 /* Various versions of GCC emit various mostly-useless
5018 strings in the name field for special member functions.
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).
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
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).
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
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
5060 So, to summarize what we expect and handle here:
5062 Given Given Real Real Action
5063 method name physname physname method name
5065 __opi [none] __opi__3Foo operator int opname
5067 Foo _._3Foo _._3Foo ~Foo separate and
5069 operator i _ZN3FoocviEv _ZN3FoocviEv operator int demangle
5070 __comp_ctor _ZN3FooC1ERKS_ _ZN3FooC1ERKS_ Foo demangle
5073 tmp_sublist
= sublist
;
5074 while (tmp_sublist
!= NULL
)
5076 if (tmp_sublist
->fn_field
.physname
[0] == '_'
5077 && tmp_sublist
->fn_field
.physname
[1] == 'Z')
5080 if (is_destructor_name (tmp_sublist
->fn_field
.physname
))
5085 tmp_sublist
= tmp_sublist
->next
;
5088 if (has_destructor
&& has_other
)
5090 struct next_fnfieldlist
*destr_fnlist
;
5091 struct next_fnfield
*last_sublist
;
5093 /* Create a new fn_fieldlist for the destructors. */
5095 destr_fnlist
= OBSTACK_ZALLOC (&fip
->obstack
,
5096 struct next_fnfieldlist
);
5098 destr_fnlist
->fn_fieldlist
.name
5099 = obconcat (&objfile
->objfile_obstack
, "~",
5100 new_fnlist
->fn_fieldlist
.name
, (char *) NULL
);
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
;
5110 while (tmp_sublist
!= NULL
)
5112 if (!is_destructor_name (tmp_sublist
->fn_field
.physname
))
5114 tmp_sublist
= tmp_sublist
->next
;
5118 destr_fnlist
->fn_fieldlist
.fn_fields
[i
++]
5119 = tmp_sublist
->fn_field
;
5121 last_sublist
->next
= tmp_sublist
->next
;
5123 sublist
= tmp_sublist
->next
;
5124 last_sublist
= tmp_sublist
;
5125 tmp_sublist
= tmp_sublist
->next
;
5128 destr_fnlist
->fn_fieldlist
.length
= has_destructor
;
5129 destr_fnlist
->next
= fip
->fnlist
;
5130 fip
->fnlist
= destr_fnlist
;
5132 length
-= has_destructor
;
5136 /* v3 mangling prevents the use of abbreviated physnames,
5137 so we can do this here. There are stubbed methods in v3
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
);
5145 if (new_method_name
!= NULL
5146 && strcmp (new_method_name
,
5147 new_fnlist
->fn_fieldlist
.name
) != 0)
5149 new_fnlist
->fn_fieldlist
.name
= new_method_name
;
5150 xfree (main_fn_name
);
5153 xfree (new_method_name
);
5155 else if (has_destructor
&& new_fnlist
->fn_fieldlist
.name
[0] != '~')
5157 new_fnlist
->fn_fieldlist
.name
=
5158 obconcat (&objfile
->objfile_obstack
,
5159 "~", main_fn_name
, (char *)NULL
);
5160 xfree (main_fn_name
);
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
)
5167 new_fnlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
5170 new_fnlist
->fn_fieldlist
.length
= length
;
5171 new_fnlist
->next
= fip
->fnlist
;
5172 fip
->fnlist
= new_fnlist
;
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
;
5188 /* Special GNU C++ name.
5190 Returns 1 for success, 0 for failure. "failure" means that we can't
5191 keep parsing and it's time for error_type(). */
5194 read_cpp_abbrev (struct stab_field_info
*fip
, const char **pp
,
5195 struct type
*type
, struct objfile
*objfile
)
5200 struct type
*context
;
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. */
5215 context
= read_type (pp
, objfile
);
5219 case 'f': /* $vf -- a virtual function table pointer */
5220 name
= context
->name ();
5225 fip
->list
->field
.set_name (obconcat (&objfile
->objfile_obstack
,
5226 vptr_name
, name
, (char *) NULL
));
5229 case 'b': /* $vb -- a virtual bsomethingorother */
5230 name
= context
->name ();
5233 complaint (_("C++ abbreviated type name "
5234 "unknown at symtab pos %d"),
5238 fip
->list
->field
.set_name (obconcat (&objfile
->objfile_obstack
,
5239 vb_name
, name
, (char *) NULL
));
5243 invalid_cpp_abbrev_complaint (*pp
);
5244 fip
->list
->field
.set_name (obconcat (&objfile
->objfile_obstack
,
5245 "INVALID_CPLUSPLUS_ABBREV",
5250 /* At this point, *pp points to the ':'. Skip it and read the
5256 invalid_cpp_abbrev_complaint (*pp
);
5259 fip
->list
->field
.set_type (read_type (pp
, objfile
));
5261 (*pp
)++; /* Skip the comma. */
5268 fip
->list
->field
.set_loc_bitpos (read_huge_number (pp
, ';', &nbits
, 0));
5272 /* This field is unpacked. */
5273 fip
->list
->field
.set_bitsize (0);
5274 fip
->list
->field
.set_accessibility (accessibility::PRIVATE
);
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. */
5288 read_one_struct_field (struct stab_field_info
*fip
, const char **pp
,
5289 const char *p
, struct type
*type
,
5290 struct objfile
*objfile
)
5292 struct gdbarch
*gdbarch
= objfile
->arch ();
5294 fip
->list
->field
.set_name
5295 (obstack_strndup (&objfile
->objfile_obstack
, *pp
, p
- *pp
));
5298 /* This means we have a visibility for a field coming. */
5303 visibility
= *(*pp
)++;
5307 /* normal dbx-style format, no explicit visibility */
5308 visibility
= VISIBILITY_PUBLIC
;
5313 case VISIBILITY_PRIVATE
:
5314 fip
->list
->field
.set_accessibility (accessibility::PRIVATE
);
5317 case VISIBILITY_PROTECTED
:
5318 fip
->list
->field
.set_accessibility (accessibility::PROTECTED
);
5321 case VISIBILITY_IGNORE
:
5322 fip
->list
->field
.set_ignored ();
5325 case VISIBILITY_PUBLIC
:
5329 /* Unknown visibility. Complain and treat it as public. */
5331 complaint (_("Unknown visibility `%c' for field"),
5337 fip
->list
->field
.set_type (read_type (pp
, objfile
));
5342 /* Possible future hook for nested types. */
5345 fip
->list
->field
.bitpos
= (long) -2; /* nested type */
5355 /* Static class member. */
5356 fip
->list
->field
.set_loc_physname (savestring (*pp
, p
- *pp
));
5360 else if (**pp
!= ',')
5362 /* Bad structure-type format. */
5363 stabs_general_complaint ("bad structure-type format");
5367 (*pp
)++; /* Skip the comma. */
5372 fip
->list
->field
.set_loc_bitpos (read_huge_number (pp
, ',', &nbits
, 0));
5375 stabs_general_complaint ("bad structure-type format");
5378 fip
->list
->field
.set_bitsize (read_huge_number (pp
, ';', &nbits
, 0));
5381 stabs_general_complaint ("bad structure-type format");
5386 if (fip
->list
->field
.loc_bitpos () == 0
5387 && fip
->list
->field
.bitsize () == 0)
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.
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. */
5403 /* Ignore this field. */
5404 fip
->list
->field
.set_ignored ();
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. */
5413 struct type
*field_type
= check_typedef (fip
->list
->field
.type ());
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
)
5420 fip
->list
->field
.set_bitsize (0);
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
)))
5429 fip
->list
->field
.loc_bitpos () % 8 == 0)
5431 fip
->list
->field
.set_bitsize (0);
5437 /* Read struct or class data fields. They have the form:
5439 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
5441 At the end, we see a semicolon instead of a field.
5443 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
5446 The optional VISIBILITY is one of:
5448 '/0' (VISIBILITY_PRIVATE)
5449 '/1' (VISIBILITY_PROTECTED)
5450 '/2' (VISIBILITY_PUBLIC)
5451 '/9' (VISIBILITY_IGNORE)
5453 or nothing, for C style fields with public visibility.
5455 Returns 1 for success, 0 for failure. */
5458 read_struct_fields (struct stab_field_info
*fip
, const char **pp
,
5459 struct type
*type
, struct objfile
*objfile
)
5462 struct stabs_nextfield
*newobj
;
5464 /* We better set p right now, in case there are no fields at all... */
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. */
5474 while (**pp
!= ';' && **pp
!= '\0')
5476 STABS_CONTINUE (pp
, objfile
);
5477 /* Get space to record the next field's data. */
5478 newobj
= OBSTACK_ZALLOC (&fip
->obstack
, struct stabs_nextfield
);
5480 newobj
->next
= fip
->list
;
5483 /* Get the field name. */
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. */
5491 if (is_cplus_marker (p
[0]) && p
[1] != '_')
5493 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
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. */
5503 while (*p
!= ':' && *p
!= '\0')
5510 /* Check to see if we have hit the member functions yet. */
5515 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
5517 if (p
[0] == ':' && p
[1] == ':')
5519 /* (the deleted) chill the list of fields: the last entry (at
5520 the head) is a partially constructed entry which we now
5522 fip
->list
= fip
->list
->next
;
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.
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.
5537 A typical example, with two base classes, would be "!2,020,19;0264,21;".
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 ____________________________________|
5548 Return 1 for success, 0 for (error-type-inducing) failure. */
5553 read_baseclasses (struct stab_field_info
*fip
, const char **pp
,
5554 struct type
*type
, struct objfile
*objfile
)
5557 struct stabs_nextfield
*newobj
;
5565 /* Skip the '!' baseclass information marker. */
5569 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
5573 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
, 0);
5578 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
5580 newobj
= OBSTACK_ZALLOC (&fip
->obstack
, struct stabs_nextfield
);
5582 newobj
->next
= fip
->list
;
5584 newobj
->field
.set_bitsize (0); /* This should be an unpacked
5587 STABS_CONTINUE (pp
, objfile
);
5591 /* Nothing to do. */
5594 newobj
->field
.set_virtual ();
5597 /* Unknown character. Complain and treat it as non-virtual. */
5599 complaint (_("Unknown virtual character `%c' for baseclass"),
5605 int visibility
= *(*pp
)++;
5608 case VISIBILITY_PRIVATE
:
5609 newobj
->field
.set_accessibility (accessibility::PRIVATE
);
5611 case VISIBILITY_PROTECTED
:
5612 newobj
->field
.set_accessibility (accessibility::PROTECTED
);
5614 case VISIBILITY_PUBLIC
:
5617 /* Bad visibility format. Complain and treat it as
5620 complaint (_("Unknown visibility `%c' for baseclass"),
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. */
5632 newobj
->field
.set_loc_bitpos (read_huge_number (pp
, ',', &nbits
, 0));
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
5641 newobj
->field
.set_type (read_type (pp
, objfile
));
5642 newobj
->field
.set_name (newobj
->field
.type ()->name ());
5644 /* Skip trailing ';' and bump count of number of fields seen. */
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.
5658 This function is called when we have parsed all the method declarations,
5659 so we can look for the vptr base class info. */
5662 read_tilde_fields (struct stab_field_info
*fip
, const char **pp
,
5663 struct type
*type
, struct objfile
*objfile
)
5667 STABS_CONTINUE (pp
, objfile
);
5669 /* If we are positioned at a ';', then skip it. */
5679 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
5681 /* Obsolete flags that used to indicate the presence
5682 of constructors and/or destructors. */
5686 /* Read either a '%' or the final ';'. */
5687 if (*(*pp
)++ == '%')
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. */
5698 t
= read_type (pp
, objfile
);
5700 while (*p
!= '\0' && *p
!= ';')
5706 /* Premature end of symbol. */
5710 set_type_vptr_basetype (type
, t
);
5711 if (type
== t
) /* Our own class provides vtbl ptr. */
5713 for (i
= t
->num_fields () - 1;
5714 i
>= TYPE_N_BASECLASSES (t
);
5717 const char *name
= t
->field (i
).name ();
5719 if (!strncmp (name
, vptr_name
, sizeof (vptr_name
) - 2)
5720 && is_cplus_marker (name
[sizeof (vptr_name
) - 2]))
5722 set_type_vptr_fieldno (type
, i
);
5726 /* Virtual function table field not found. */
5727 complaint (_("virtual function table pointer "
5728 "not found when defining class `%s'"),
5734 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
5745 attach_fn_fields_to_type (struct stab_field_info
*fip
, struct type
*type
)
5749 for (n
= TYPE_NFN_FIELDS (type
);
5750 fip
->fnlist
!= NULL
;
5751 fip
->fnlist
= fip
->fnlist
->next
)
5753 --n
; /* Circumvent Sun3 compiler bug. */
5754 TYPE_FN_FIELDLISTS (type
)[n
] = fip
->fnlist
->fn_fieldlist
;
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. */
5764 attach_fields_to_type (struct stab_field_info
*fip
, struct type
*type
,
5765 struct objfile
*objfile
)
5768 struct stabs_nextfield
*scan
;
5770 /* Count up the number of fields that we have. */
5772 for (scan
= fip
->list
; scan
!= NULL
; scan
= scan
->next
)
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
5779 type
->alloc_fields (nfields
);
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. */
5786 while (nfields
-- > 0)
5788 type
->field (nfields
) = fip
->list
->field
;
5789 fip
->list
= fip
->list
->next
;
5795 /* Complain that the compiler has emitted more than one definition for the
5796 structure type TYPE. */
5798 complain_about_struct_wipeout (struct type
*type
)
5800 const char *name
= "";
5801 const char *kind
= "";
5805 name
= type
->name ();
5806 switch (type
->code ())
5808 case TYPE_CODE_STRUCT
: kind
= "struct "; break;
5809 case TYPE_CODE_UNION
: kind
= "union "; break;
5810 case TYPE_CODE_ENUM
: kind
= "enum "; break;
5820 complaint (_("struct/union type gets multiply defined: %s%s"), kind
, name
);
5823 /* Set the length for all variants of a same main_type, which are
5824 connected in the closed chain.
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
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[...]"
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
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... */
5846 set_length_in_type_chain (struct type
*type
)
5848 struct type
*ntype
= TYPE_CHAIN (type
);
5850 while (ntype
!= type
)
5852 if (ntype
->length () == 0)
5853 ntype
->set_length (type
->length ());
5855 complain_about_struct_wipeout (ntype
);
5856 ntype
= TYPE_CHAIN (ntype
);
5860 /* Read the description of a structure (or union type) and return an object
5861 describing the type.
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;;".
5867 TYPE points to an incomplete type that needs to be filled in.
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).
5874 static struct type
*
5875 read_struct_type (const char **pp
, struct type
*type
, enum type_code type_code
,
5876 struct objfile
*objfile
)
5878 struct stab_field_info fi
;
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
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
5891 if (! (type
->code () == TYPE_CODE_UNDEF
5892 || type
->is_stub ()))
5894 complain_about_struct_wipeout (type
);
5896 /* It's probably best to return the type unchanged. */
5900 INIT_CPLUS_SPECIFIC (type
);
5901 type
->set_code (type_code
);
5902 type
->set_is_stub (false);
5904 /* First comes the total size in bytes. */
5909 type
->set_length (read_huge_number (pp
, 0, &nbits
, 0));
5911 return error_type (pp
, objfile
);
5912 set_length_in_type_chain (type
);
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). */
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
))
5927 type
= error_type (pp
, objfile
);
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
5938 static struct type
*
5939 read_array_type (const char **pp
, struct type
*type
,
5940 struct objfile
*objfile
)
5942 struct type
*index_type
, *element_type
, *range_type
;
5947 /* Format of an array type:
5948 "ar<index type>;lower;upper;<array_contents_type>".
5949 OS9000: "arlower,upper;<array_contents_type>".
5951 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
5952 for these, produce a type like float[][]. */
5955 index_type
= read_type (pp
, objfile
);
5957 /* Improper format of array type decl. */
5958 return error_type (pp
, objfile
);
5962 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
5967 lower
= read_huge_number (pp
, ';', &nbits
, 0);
5970 return error_type (pp
, objfile
);
5972 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
5977 upper
= read_huge_number (pp
, ';', &nbits
, 0);
5979 return error_type (pp
, objfile
);
5981 element_type
= read_type (pp
, objfile
);
5989 type_allocator
alloc (objfile
, get_current_subfile ()->language
);
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
);
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. */
6003 static struct type
*
6004 read_enum_type (const char **pp
, struct type
*type
,
6005 struct objfile
*objfile
)
6007 struct gdbarch
*gdbarch
= objfile
->arch ();
6013 struct pending
**symlist
;
6014 struct pending
*osyms
, *syms
;
6017 int unsigned_enum
= 1;
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 ();
6027 symlist
= get_file_symbols ();
6029 o_nsyms
= osyms
? osyms
->nsyms
: 0;
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. */
6035 /* Skip over the type. */
6039 /* Skip over the colon. */
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
!= ',')
6048 STABS_CONTINUE (pp
, objfile
);
6052 name
= obstack_strndup (&objfile
->objfile_obstack
, *pp
, p
- *pp
);
6054 n
= read_huge_number (pp
, ',', &nbits
, 0);
6056 return error_type (pp
, objfile
);
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
);
6067 add_symbol_to_list (sym
, symlist
);
6072 (*pp
)++; /* Skip the semicolon. */
6074 /* Now fill in the fields of the type-structure. */
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);
6081 type
->set_is_unsigned (true);
6082 type
->alloc_fields (nsyms
);
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. */
6092 for (syms
= *symlist
, n
= nsyms
- 1; syms
; syms
= syms
->next
)
6094 int last
= syms
== osyms
? o_nsyms
: 0;
6095 int j
= syms
->nsyms
;
6097 for (; --j
>= last
; --n
)
6099 struct symbol
*xsym
= syms
->symbol
[j
];
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);
6113 /* Sun's ACC uses a somewhat saner method for specifying the builtin
6114 typedefs in every file (for int, long, etc):
6116 type = b <signed> <width> <format type>; <offset>; <nbits>
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.
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,
6126 static struct type
*
6127 read_sun_builtin_type (const char **pp
, int typenums
[2], struct objfile
*objfile
)
6132 int boolean_type
= 0;
6143 return error_type (pp
, objfile
);
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
6151 Boolean forms, e.g Fortran logical*X, put a b here. */
6155 else if (**pp
== 'b')
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);
6167 return error_type (pp
, objfile
);
6169 /* The second number is always 0, so ignore it too. */
6170 read_huge_number (pp
, ';', &nbits
, 0);
6172 return error_type (pp
, objfile
);
6174 /* The third number is the number of bits for this type. */
6175 type_bits
= read_huge_number (pp
, 0, &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
6187 type_allocator
alloc (objfile
, get_current_subfile ()->language
);
6190 struct type
*type
= alloc
.new_type (TYPE_CODE_VOID
,
6191 TARGET_CHAR_BIT
, nullptr);
6193 type
->set_is_unsigned (true);
6199 return init_boolean_type (alloc
, type_bits
, unsigned_type
, NULL
);
6201 return init_integer_type (alloc
, type_bits
, unsigned_type
, NULL
);
6204 static struct type
*
6205 read_sun_floating_type (const char **pp
, int typenums
[2],
6206 struct objfile
*objfile
)
6211 struct type
*rettype
;
6213 /* The first number has more details about the type, for example
6215 details
= read_huge_number (pp
, ';', &nbits
, 0);
6217 return error_type (pp
, objfile
);
6219 /* The second number is the number of bytes occupied by this type. */
6220 nbytes
= read_huge_number (pp
, ';', &nbits
, 0);
6222 return error_type (pp
, objfile
);
6224 nbits
= nbytes
* TARGET_CHAR_BIT
;
6226 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
6227 || details
== NF_COMPLEX32
)
6229 rettype
= dbx_init_float_type (objfile
, nbits
/ 2);
6230 return init_complex_type (NULL
, rettype
);
6233 return dbx_init_float_type (objfile
, nbits
);
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.
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.
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.
6251 If encounter garbage, set *BITS to -1 and return 0. */
6254 read_huge_number (const char **pp
, int end
, int *bits
,
6255 int twos_complement_bits
)
6257 const char *p
= *pp
;
6266 int twos_complement_representation
= 0;
6274 /* Leading zero means octal. GCC uses this to output values larger
6275 than an int (because that would be hard in decimal). */
6282 /* Skip extra zeros. */
6286 if (sign
> 0 && radix
== 8 && twos_complement_bits
> 0)
6288 /* Octal, possibly signed. Check if we have enough chars for a
6294 while ((c
= *p1
) >= '0' && c
< '8')
6298 if (len
> twos_complement_bits
/ 3
6299 || (twos_complement_bits
% 3 == 0
6300 && len
== twos_complement_bits
/ 3))
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;
6306 if (c
& (1 << sign_bit
))
6308 /* Definitely signed. */
6309 twos_complement_representation
= 1;
6315 upper_limit
= LONG_MAX
/ radix
;
6317 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
6319 if (n
<= upper_limit
)
6321 if (twos_complement_representation
)
6323 /* Octal, signed, twos complement representation. In
6324 this case, n is the corresponding absolute value. */
6327 long sn
= c
- '0' - ((2 * (c
- '0')) | (2 << sign_bit
));
6339 /* unsigned representation */
6341 n
+= c
- '0'; /* FIXME this overflows anyway. */
6347 /* This depends on large values being output in octal, which is
6354 /* Ignore leading zeroes. */
6358 else if (c
== '2' || c
== '3')
6379 if (radix
== 8 && twos_complement_bits
> 0 && nbits
> twos_complement_bits
)
6381 /* We were supposed to parse a number with maximum
6382 TWOS_COMPLEMENT_BITS bits, but something went wrong. */
6393 /* Large decimal constants are an error (because it is hard to
6394 count how many bits are in them). */
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
)
6414 /* It's *BITS which has the interesting information. */
6418 static struct type
*
6419 read_range_type (const char **pp
, int typenums
[2], int type_size
,
6420 struct objfile
*objfile
)
6422 struct gdbarch
*gdbarch
= objfile
->arch ();
6423 const char *orig_pp
= *pp
;
6428 struct type
*result_type
;
6429 struct type
*index_type
= NULL
;
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]);
6441 index_type
= read_type (pp
, objfile
);
6444 /* A semicolon should now follow; skip it. */
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
);
6453 if (n2bits
== -1 || n3bits
== -1)
6454 return error_type (pp
, objfile
);
6456 type_allocator
alloc (objfile
, get_current_subfile ()->language
);
6459 goto handle_true_range
;
6461 /* If limits are huge, must be large integral type. */
6462 if (n2bits
!= 0 || n3bits
!= 0)
6464 char got_signed
= 0;
6465 char got_unsigned
= 0;
6466 /* Number of bits in the type. */
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
)
6474 if (n2bits
== type_size
&& n2bits
> n3bits
)
6480 /* Range from 0 to <large number> is an unsigned large integral type. */
6481 else if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
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
)
6498 if (got_signed
|| got_unsigned
)
6499 return init_integer_type (alloc
, nbits
, got_unsigned
, NULL
);
6501 return error_type (pp
, objfile
);
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);
6508 /* If n3 is zero and n2 is positive, we want a floating type, and n2
6509 is the width in bytes.
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
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. */
6520 if (n3
== 0 && n2
> 0)
6522 struct type
*float_type
6523 = dbx_init_float_type (objfile
, n2
* TARGET_CHAR_BIT
);
6526 return init_complex_type (NULL
, float_type
);
6531 /* If the upper bound is -1, it must really be an unsigned integral. */
6533 else if (n2
== 0 && n3
== -1)
6535 int bits
= type_size
;
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
);
6545 return init_integer_type (alloc
, bits
, 1, NULL
);
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)
6552 struct type
*type
= init_integer_type (alloc
, TARGET_CHAR_BIT
,
6554 type
->set_has_no_signedness (true);
6557 /* We used to do this only for subrange of self or subrange of int. */
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. */
6565 /* n3 actually gives the size. */
6566 return init_integer_type (alloc
, -n3
* TARGET_CHAR_BIT
, 1, NULL
);
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. */
6576 for (bytes
= 0; (bits
& 0xff) == 0xff; bytes
++)
6579 && ((bytes
- 1) & bytes
) == 0) /* "bytes is a power of two" */
6580 return init_integer_type (alloc
, bytes
* TARGET_CHAR_BIT
, 1, NULL
);
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
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)
6594 return init_integer_type (alloc
, 8, 0, NULL
);
6596 return init_integer_type (alloc
, 16, 0, NULL
);
6597 if (n3
== 0x7fffffff)
6598 return init_integer_type (alloc
, 32, 0, NULL
);
6601 /* We have a real range type on our hands. Allocate space and
6602 return a real pointer. */
6606 index_type
= builtin_type (objfile
)->builtin_int
;
6608 index_type
= *dbx_lookup_type (rangenums
, objfile
);
6609 if (index_type
== NULL
)
6611 /* Does this actually ever happen? Is that why we are worrying
6612 about dealing with it rather than just calling error_type? */
6614 complaint (_("base type %d of range type is not defined"), rangenums
[1]);
6616 index_type
= builtin_type (objfile
)->builtin_int
;
6620 = create_static_range_type (alloc
, index_type
, n2
, n3
);
6621 return (result_type
);
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. */
6628 static struct field
*
6629 read_args (const char **pp
, int end
, struct objfile
*objfile
, int *nargsp
,
6632 /* FIXME! Remove this arbitrary limit! */
6633 struct type
*types
[1024]; /* Allow for fns of 1023 parameters. */
6640 /* Invalid argument list: no ','. */
6643 STABS_CONTINUE (pp
, objfile
);
6644 types
[n
++] = read_type (pp
, objfile
);
6646 (*pp
)++; /* get past `end' (the ':' character). */
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. */
6655 complaint (_("Invalid (empty) method arguments"));
6658 else if (types
[n
- 1]->code () != TYPE_CODE_VOID
)
6666 rval
= XCNEWVEC (struct field
, n
);
6667 for (i
= 0; i
< n
; i
++)
6668 rval
[i
].set_type (types
[i
]);
6673 /* Common block handling. */
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
6681 static struct pending
*common_block
;
6682 static int common_block_i
;
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
;
6689 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
6690 to remain after this function returns. */
6693 common_block_start (const char *name
, struct objfile
*objfile
)
6695 if (common_block_name
!= NULL
)
6697 complaint (_("Invalid symbol data: common block within common block"));
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
);
6704 /* Process a N_ECOMM symbol. */
6707 common_block_end (struct objfile
*objfile
)
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. */
6716 struct pending
*newobj
= 0;
6717 struct pending
*next
;
6720 if (common_block_name
== NULL
)
6722 complaint (_("ECOMM symbol unmatched by BCOMM"));
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
);
6731 /* Now we copy all the symbols which have been defined since the BCOMM. */
6733 /* Copy all the struct pendings before common_block. */
6734 for (next
= *get_local_symbols ();
6735 next
!= NULL
&& next
!= common_block
;
6738 for (j
= 0; j
< next
->nsyms
; j
++)
6739 add_symbol_to_list (next
->symbol
[j
], &newobj
);
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
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
);
6750 sym
->set_type ((struct type
*) newobj
);
6752 /* Should we be putting local_symbols back to what it was?
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
;
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). */
6766 fix_common_block (struct symbol
*sym
, CORE_ADDR valu
, int section_index
)
6768 struct pending
*next
= (struct pending
*) sym
->type ();
6770 for (; next
; next
= next
->next
)
6774 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
6776 next
->symbol
[j
]->set_value_address
6777 (next
->symbol
[j
]->value_address () + valu
);
6778 next
->symbol
[j
]->set_section_index (section_index
);
6785 /* Add {TYPE, TYPENUMS} to the NONAME_UNDEFS vector.
6786 See add_undefined_type for more details. */
6789 add_undefined_type_noname (struct type
*type
, int typenums
[2])
6793 nat
.typenums
[0] = typenums
[0];
6794 nat
.typenums
[1] = typenums
[1];
6797 if (noname_undefs_length
== noname_undefs_allocated
)
6799 noname_undefs_allocated
*= 2;
6800 noname_undefs
= (struct nat
*)
6801 xrealloc ((char *) noname_undefs
,
6802 noname_undefs_allocated
* sizeof (struct nat
));
6804 noname_undefs
[noname_undefs_length
++] = nat
;
6807 /* Add TYPE to the UNDEF_TYPES vector.
6808 See add_undefined_type for more details. */
6811 add_undefined_type_1 (struct type
*type
)
6813 if (undef_types_length
== undef_types_allocated
)
6815 undef_types_allocated
*= 2;
6816 undef_types
= (struct type
**)
6817 xrealloc ((char *) undef_types
,
6818 undef_types_allocated
* sizeof (struct type
*));
6820 undef_types
[undef_types_length
++] = type
;
6823 /* What about types defined as forward references inside of a small lexical
6825 /* Add a type to the list of undefined types to be checked through
6826 once this file has been read in.
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. */
6837 add_undefined_type (struct type
*type
, int typenums
[2])
6839 if (type
->name () == NULL
)
6840 add_undefined_type_noname (type
, typenums
);
6842 add_undefined_type_1 (type
);
6845 /* Try to fix all undefined types pushed on the UNDEF_TYPES vector. */
6848 cleanup_undefined_types_noname (struct objfile
*objfile
)
6852 for (i
= 0; i
< noname_undefs_length
; i
++)
6854 struct nat nat
= noname_undefs
[i
];
6857 type
= dbx_lookup_type (nat
.typenums
, objfile
);
6858 if (nat
.type
!= *type
&& (*type
)->code () != TYPE_CODE_UNDEF
)
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
);
6869 noname_undefs_length
= 0;
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:
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. */
6883 cleanup_undefined_types_1 (void)
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.
6893 It is important to check the instance flags, because we have seen
6894 examples where the debug info contained definitions such as:
6896 "foo_t:t30=B31=xefoo_t:"
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. */
6906 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
6908 switch ((*type
)->code ())
6911 case TYPE_CODE_STRUCT
:
6912 case TYPE_CODE_UNION
:
6913 case TYPE_CODE_ENUM
:
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 ())
6921 struct pending
*ppt
;
6923 /* Name of the type, without "struct" or "union". */
6924 const char *type_name
= (*type
)->name ();
6926 if (type_name
== NULL
)
6928 complaint (_("need a type name"));
6931 for (ppt
= *get_file_symbols (); ppt
; ppt
= ppt
->next
)
6933 for (i
= 0; i
< ppt
->nsyms
; i
++)
6935 struct symbol
*sym
= ppt
->symbol
[i
];
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 ());
6952 complaint (_("forward-referenced types left unresolved, "
6960 undef_types_length
= 0;
6963 /* Try to fix all the undefined types we encountered while processing
6967 cleanup_undefined_stabs_types (struct objfile
*objfile
)
6969 cleanup_undefined_types_1 ();
6970 cleanup_undefined_types_noname (objfile
);
6973 /* See stabsread.h. */
6976 scan_file_globals (struct objfile
*objfile
)
6979 struct symbol
*sym
, *prev
;
6980 struct objfile
*resolve_objfile
;
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. */
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
;
6991 resolve_objfile
= objfile
;
6995 /* Avoid expensive loop through all minimal symbols if there are
6996 no unresolved symbols. */
6997 for (hash
= 0; hash
< HASHSIZE
; hash
++)
6999 if (global_sym_chain
[hash
])
7002 if (hash
>= HASHSIZE
)
7005 for (minimal_symbol
*msymbol
: resolve_objfile
->msymbols ())
7009 /* Skip static symbols. */
7010 switch (msymbol
->type ())
7022 /* Get the hash index and check all the symbols
7023 under that hash index. */
7025 hash
= hashname (msymbol
->linkage_name ());
7027 for (sym
= global_sym_chain
[hash
]; sym
;)
7029 if (strcmp (msymbol
->linkage_name (), sym
->linkage_name ()) == 0)
7031 /* Splice this symbol out of the hash chain and
7032 assign the value we have to it. */
7035 prev
->set_value_chain (sym
->value_chain ());
7039 global_sym_chain
[hash
] = sym
->value_chain ();
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. */
7047 if (sym
->aclass () == LOC_BLOCK
)
7049 (sym
, msymbol
->value_address (resolve_objfile
),
7050 msymbol
->section_index ());
7052 sym
->set_value_address
7053 (msymbol
->value_address (resolve_objfile
));
7054 sym
->set_section_index (msymbol
->section_index ());
7059 sym
= prev
->value_chain ();
7063 sym
= global_sym_chain
[hash
];
7069 sym
= sym
->value_chain ();
7073 if (resolve_objfile
== objfile
)
7075 resolve_objfile
= objfile
;
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
++)
7082 sym
= global_sym_chain
[hash
];
7086 sym
= sym
->value_chain ();
7088 /* Change the symbol address from the misleading chain value
7090 prev
->set_value_address (0);
7092 /* Complain about unresolved common block symbols. */
7093 if (prev
->aclass () == LOC_STATIC
)
7094 prev
->set_aclass_index (LOC_UNRESOLVED
);
7096 complaint (_("%s: common block `%s' from "
7097 "global_sym_chain unresolved"),
7098 objfile_name (objfile
), prev
->print_name ());
7101 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
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
7109 stabsread_init (void)
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). */
7118 stabsread_new_init (void)
7120 /* Empty the hash table of global syms looking for values. */
7121 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
7124 /* Initialize anything that needs initializing at the same time as
7125 start_compunit_symtab() is called. */
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;
7137 /* FIXME: If common_block_name is not already NULL, we should complain(). */
7138 common_block_name
= NULL
;
7141 /* Call after end_compunit_symtab(). */
7148 xfree (type_vector
);
7151 type_vector_length
= 0;
7152 previous_stab_code
= 0;
7156 finish_global_stabs (struct objfile
*objfile
)
7160 patch_block_stabs (*get_global_symbols (), global_stabs
, objfile
);
7161 xfree (global_stabs
);
7162 global_stabs
= NULL
;
7166 /* Find the end of the name, delimited by a ':', but don't match
7167 ObjC symbols which look like -[Foo bar::]:bla. */
7169 find_name_end (const char *name
)
7171 const char *s
= name
;
7173 if (s
[0] == '-' || *s
== '+')
7175 /* Must be an ObjC method symbol. */
7178 error (_("invalid symbol name \"%s\""), name
);
7180 s
= strchr (s
, ']');
7183 error (_("invalid symbol name \"%s\""), name
);
7185 return strchr (s
, ':');
7189 return strchr (s
, ':');
7193 /* See stabsread.h. */
7196 hashname (const char *name
)
7198 return fast_hash (name
, strlen (name
)) % HASHSIZE
;
7201 /* Initializer for this module. */
7203 INIT_GDB_FILE (stabsread
)
7205 undef_types_allocated
= 20;
7206 undef_types_length
= 0;
7207 undef_types
= XNEWVEC (struct type
*, undef_types_allocated
);
7209 noname_undefs_allocated
= 20;
7210 noname_undefs_length
= 0;
7211 noname_undefs
= XNEWVEC (struct nat
, noname_undefs_allocated
);
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
);