1e93f7393Sniklas /* Support routines for decoding "stabs" debugging information format.
2b725ae77Skettenis
3b725ae77Skettenis Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4b725ae77Skettenis 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free
5b725ae77Skettenis Software Foundation, Inc.
6e93f7393Sniklas
7e93f7393Sniklas This file is part of GDB.
8e93f7393Sniklas
9e93f7393Sniklas This program is free software; you can redistribute it and/or modify
10e93f7393Sniklas it under the terms of the GNU General Public License as published by
11e93f7393Sniklas the Free Software Foundation; either version 2 of the License, or
12e93f7393Sniklas (at your option) any later version.
13e93f7393Sniklas
14e93f7393Sniklas This program is distributed in the hope that it will be useful,
15e93f7393Sniklas but WITHOUT ANY WARRANTY; without even the implied warranty of
16e93f7393Sniklas MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17e93f7393Sniklas GNU General Public License for more details.
18e93f7393Sniklas
19e93f7393Sniklas You should have received a copy of the GNU General Public License
20e93f7393Sniklas along with this program; if not, write to the Free Software
21b725ae77Skettenis Foundation, Inc., 59 Temple Place - Suite 330,
22b725ae77Skettenis Boston, MA 02111-1307, USA. */
23e93f7393Sniklas
24e93f7393Sniklas /* Support routines for reading and decoding debugging information in
25e93f7393Sniklas the "stabs" format. This format is used with many systems that use
26e93f7393Sniklas the a.out object file format, as well as some systems that use
27e93f7393Sniklas COFF or ELF where the stabs data is placed in a special section.
28e93f7393Sniklas Avoid placing any object file format specific code in this file. */
29e93f7393Sniklas
30e93f7393Sniklas #include "defs.h"
31e93f7393Sniklas #include "gdb_string.h"
32e93f7393Sniklas #include "bfd.h"
33b725ae77Skettenis #include "gdb_obstack.h"
34e93f7393Sniklas #include "symtab.h"
35e93f7393Sniklas #include "gdbtypes.h"
36e93f7393Sniklas #include "expression.h"
37e93f7393Sniklas #include "symfile.h"
38e93f7393Sniklas #include "objfiles.h"
39e93f7393Sniklas #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
40e93f7393Sniklas #include "libaout.h"
41e93f7393Sniklas #include "aout/aout64.h"
42e93f7393Sniklas #include "gdb-stabs.h"
43e93f7393Sniklas #include "buildsym.h"
44e93f7393Sniklas #include "complaints.h"
45e93f7393Sniklas #include "demangle.h"
46e93f7393Sniklas #include "language.h"
47b725ae77Skettenis #include "doublest.h"
48b725ae77Skettenis #include "cp-abi.h"
49b725ae77Skettenis #include "cp-support.h"
50e93f7393Sniklas
51e93f7393Sniklas #include <ctype.h>
52e93f7393Sniklas
53e93f7393Sniklas /* Ask stabsread.h to define the vars it normally declares `extern'. */
54b725ae77Skettenis #define EXTERN
55b725ae77Skettenis /**/
56e93f7393Sniklas #include "stabsread.h" /* Our own declarations */
57e93f7393Sniklas #undef EXTERN
58e93f7393Sniklas
59b725ae77Skettenis extern void _initialize_stabsread (void);
60b725ae77Skettenis
61e93f7393Sniklas /* The routines that read and process a complete stabs for a C struct or
62e93f7393Sniklas C++ class pass lists of data member fields and lists of member function
63e93f7393Sniklas fields in an instance of a field_info structure, as defined below.
64e93f7393Sniklas This is part of some reorganization of low level C++ support and is
65e93f7393Sniklas expected to eventually go away... (FIXME) */
66e93f7393Sniklas
67e93f7393Sniklas struct field_info
68e93f7393Sniklas {
69e93f7393Sniklas struct nextfield
70e93f7393Sniklas {
71e93f7393Sniklas struct nextfield *next;
72e93f7393Sniklas
73e93f7393Sniklas /* This is the raw visibility from the stab. It is not checked
74e93f7393Sniklas for being one of the visibilities we recognize, so code which
75e93f7393Sniklas examines this field better be able to deal. */
76e93f7393Sniklas int visibility;
77e93f7393Sniklas
78e93f7393Sniklas struct field field;
79b725ae77Skettenis }
80b725ae77Skettenis *list;
81e93f7393Sniklas struct next_fnfieldlist
82e93f7393Sniklas {
83e93f7393Sniklas struct next_fnfieldlist *next;
84e93f7393Sniklas struct fn_fieldlist fn_fieldlist;
85b725ae77Skettenis }
86b725ae77Skettenis *fnlist;
87e93f7393Sniklas };
88e93f7393Sniklas
89e93f7393Sniklas static void
90b725ae77Skettenis read_one_struct_field (struct field_info *, char **, char *,
91b725ae77Skettenis struct type *, struct objfile *);
92e93f7393Sniklas
93b725ae77Skettenis static struct type *dbx_alloc_type (int[2], struct objfile *);
94e93f7393Sniklas
95b725ae77Skettenis static long read_huge_number (char **, int, int *);
96e93f7393Sniklas
97b725ae77Skettenis static struct type *error_type (char **, struct objfile *);
98e93f7393Sniklas
99e93f7393Sniklas static void
100b725ae77Skettenis patch_block_stabs (struct pending *, struct pending_stabs *,
101b725ae77Skettenis struct objfile *);
102e93f7393Sniklas
103b725ae77Skettenis static void fix_common_block (struct symbol *, int);
104b725ae77Skettenis
105b725ae77Skettenis static int read_type_number (char **, int *);
106b725ae77Skettenis
107b725ae77Skettenis static struct type *read_type (char **, struct objfile *);
108b725ae77Skettenis
109b725ae77Skettenis static struct type *read_range_type (char **, int[2], struct objfile *);
110b725ae77Skettenis
111b725ae77Skettenis static struct type *read_sun_builtin_type (char **, int[2], struct objfile *);
112b725ae77Skettenis
113b725ae77Skettenis static struct type *read_sun_floating_type (char **, int[2],
114b725ae77Skettenis struct objfile *);
115b725ae77Skettenis
116b725ae77Skettenis static struct type *read_enum_type (char **, struct type *, struct objfile *);
117b725ae77Skettenis
118b725ae77Skettenis static struct type *rs6000_builtin_type (int);
119e93f7393Sniklas
120e93f7393Sniklas static int
121b725ae77Skettenis read_member_functions (struct field_info *, char **, struct type *,
122b725ae77Skettenis struct objfile *);
123e93f7393Sniklas
124e93f7393Sniklas static int
125b725ae77Skettenis read_struct_fields (struct field_info *, char **, struct type *,
126b725ae77Skettenis struct objfile *);
127e93f7393Sniklas
128e93f7393Sniklas static int
129b725ae77Skettenis read_baseclasses (struct field_info *, char **, struct type *,
130b725ae77Skettenis struct objfile *);
131e93f7393Sniklas
132e93f7393Sniklas static int
133b725ae77Skettenis read_tilde_fields (struct field_info *, char **, struct type *,
134b725ae77Skettenis struct objfile *);
135b725ae77Skettenis
136b725ae77Skettenis static int attach_fn_fields_to_type (struct field_info *, struct type *);
137b725ae77Skettenis
138b725ae77Skettenis static int attach_fields_to_type (struct field_info *, struct type *,
139b725ae77Skettenis struct objfile *);
140b725ae77Skettenis
141b725ae77Skettenis static struct type *read_struct_type (char **, struct type *,
142b725ae77Skettenis enum type_code,
143b725ae77Skettenis struct objfile *);
144b725ae77Skettenis
145b725ae77Skettenis static struct type *read_array_type (char **, struct type *,
146b725ae77Skettenis struct objfile *);
147b725ae77Skettenis
148b725ae77Skettenis static struct field *read_args (char **, int, struct objfile *, int *, int *);
149b725ae77Skettenis
150b725ae77Skettenis static void add_undefined_type (struct type *);
151e93f7393Sniklas
152e93f7393Sniklas static int
153b725ae77Skettenis read_cpp_abbrev (struct field_info *, char **, struct type *,
154b725ae77Skettenis struct objfile *);
155e93f7393Sniklas
156b725ae77Skettenis static char *find_name_end (char *name);
157e93f7393Sniklas
158b725ae77Skettenis static int process_reference (char **string);
159e93f7393Sniklas
160b725ae77Skettenis void stabsread_clear_cache (void);
161e93f7393Sniklas
162b725ae77Skettenis static const char vptr_name[] = "_vptr$";
163b725ae77Skettenis static const char vb_name[] = "_vb$";
164e93f7393Sniklas
165e93f7393Sniklas /* Define this as 1 if a pcc declaration of a char or short argument
166e93f7393Sniklas gives the correct address. Otherwise assume pcc gives the
167e93f7393Sniklas address of the corresponding int, which is not the same on a
168e93f7393Sniklas big-endian machine. */
169e93f7393Sniklas
170b725ae77Skettenis #if !defined (BELIEVE_PCC_PROMOTION)
171e93f7393Sniklas #define BELIEVE_PCC_PROMOTION 0
172e93f7393Sniklas #endif
173e93f7393Sniklas
174b725ae77Skettenis static void
invalid_cpp_abbrev_complaint(const char * arg1)175b725ae77Skettenis invalid_cpp_abbrev_complaint (const char *arg1)
176b725ae77Skettenis {
177b725ae77Skettenis complaint (&symfile_complaints, "invalid C++ abbreviation `%s'", arg1);
178b725ae77Skettenis }
179e93f7393Sniklas
180b725ae77Skettenis static void
reg_value_complaint(int regnum,int num_regs,const char * sym)181*63addd46Skettenis reg_value_complaint (int regnum, int num_regs, const char *sym)
182b725ae77Skettenis {
183b725ae77Skettenis complaint (&symfile_complaints,
184*63addd46Skettenis "register number %d too large (max %d) in symbol %s",
185*63addd46Skettenis regnum, num_regs - 1, sym);
186b725ae77Skettenis }
187e93f7393Sniklas
188b725ae77Skettenis static void
stabs_general_complaint(const char * arg1)189b725ae77Skettenis stabs_general_complaint (const char *arg1)
190b725ae77Skettenis {
191b725ae77Skettenis complaint (&symfile_complaints, "%s", arg1);
192b725ae77Skettenis }
193e93f7393Sniklas
194e93f7393Sniklas /* Make a list of forward references which haven't been defined. */
195e93f7393Sniklas
196e93f7393Sniklas static struct type **undef_types;
197e93f7393Sniklas static int undef_types_allocated;
198e93f7393Sniklas static int undef_types_length;
199e93f7393Sniklas static struct symbol *current_symbol = NULL;
200e93f7393Sniklas
201e93f7393Sniklas /* Check for and handle cretinous stabs symbol name continuation! */
202e93f7393Sniklas #define STABS_CONTINUE(pp,objfile) \
203e93f7393Sniklas do { \
204e93f7393Sniklas if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
205e93f7393Sniklas *(pp) = next_symbol_text (objfile); \
206e93f7393Sniklas } while (0)
207e93f7393Sniklas
208e93f7393Sniklas
209e93f7393Sniklas /* Look up a dbx type-number pair. Return the address of the slot
210e93f7393Sniklas where the type for that number-pair is stored.
211e93f7393Sniklas The number-pair is in TYPENUMS.
212e93f7393Sniklas
213e93f7393Sniklas This can be used for finding the type associated with that pair
214e93f7393Sniklas or for associating a new type with the pair. */
215e93f7393Sniklas
216b725ae77Skettenis static struct type **
dbx_lookup_type(int typenums[2])217b725ae77Skettenis dbx_lookup_type (int typenums[2])
218e93f7393Sniklas {
219b725ae77Skettenis int filenum = typenums[0];
220b725ae77Skettenis int index = typenums[1];
221e93f7393Sniklas unsigned old_len;
222b725ae77Skettenis int real_filenum;
223b725ae77Skettenis struct header_file *f;
224e93f7393Sniklas int f_orig_length;
225e93f7393Sniklas
226e93f7393Sniklas if (filenum == -1) /* -1,-1 is for temporary types. */
227e93f7393Sniklas return 0;
228e93f7393Sniklas
229e93f7393Sniklas if (filenum < 0 || filenum >= n_this_object_header_files)
230e93f7393Sniklas {
231b725ae77Skettenis complaint (&symfile_complaints,
232b725ae77Skettenis "Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
233b725ae77Skettenis filenum, index, symnum);
234e93f7393Sniklas goto error_return;
235e93f7393Sniklas }
236e93f7393Sniklas
237e93f7393Sniklas if (filenum == 0)
238e93f7393Sniklas {
239e93f7393Sniklas if (index < 0)
240e93f7393Sniklas {
241e93f7393Sniklas /* Caller wants address of address of type. We think
242e93f7393Sniklas that negative (rs6k builtin) types will never appear as
243e93f7393Sniklas "lvalues", (nor should they), so we stuff the real type
244e93f7393Sniklas pointer into a temp, and return its address. If referenced,
245e93f7393Sniklas this will do the right thing. */
246e93f7393Sniklas static struct type *temp_type;
247e93f7393Sniklas
248e93f7393Sniklas temp_type = rs6000_builtin_type (index);
249e93f7393Sniklas return &temp_type;
250e93f7393Sniklas }
251e93f7393Sniklas
252e93f7393Sniklas /* Type is defined outside of header files.
253e93f7393Sniklas Find it in this object file's type vector. */
254e93f7393Sniklas if (index >= type_vector_length)
255e93f7393Sniklas {
256e93f7393Sniklas old_len = type_vector_length;
257e93f7393Sniklas if (old_len == 0)
258e93f7393Sniklas {
259e93f7393Sniklas type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
260e93f7393Sniklas type_vector = (struct type **)
261e93f7393Sniklas xmalloc (type_vector_length * sizeof (struct type *));
262e93f7393Sniklas }
263e93f7393Sniklas while (index >= type_vector_length)
264e93f7393Sniklas {
265e93f7393Sniklas type_vector_length *= 2;
266e93f7393Sniklas }
267e93f7393Sniklas type_vector = (struct type **)
268e93f7393Sniklas xrealloc ((char *) type_vector,
269e93f7393Sniklas (type_vector_length * sizeof (struct type *)));
270e93f7393Sniklas memset (&type_vector[old_len], 0,
271e93f7393Sniklas (type_vector_length - old_len) * sizeof (struct type *));
272e93f7393Sniklas }
273e93f7393Sniklas return (&type_vector[index]);
274e93f7393Sniklas }
275e93f7393Sniklas else
276e93f7393Sniklas {
277e93f7393Sniklas real_filenum = this_object_header_files[filenum];
278e93f7393Sniklas
279e93f7393Sniklas if (real_filenum >= N_HEADER_FILES (current_objfile))
280e93f7393Sniklas {
281e93f7393Sniklas struct type *temp_type;
282e93f7393Sniklas struct type **temp_type_p;
283e93f7393Sniklas
284e93f7393Sniklas warning ("GDB internal error: bad real_filenum");
285e93f7393Sniklas
286e93f7393Sniklas error_return:
287e93f7393Sniklas temp_type = init_type (TYPE_CODE_ERROR, 0, 0, NULL, NULL);
288e93f7393Sniklas temp_type_p = (struct type **) xmalloc (sizeof (struct type *));
289e93f7393Sniklas *temp_type_p = temp_type;
290e93f7393Sniklas return temp_type_p;
291e93f7393Sniklas }
292e93f7393Sniklas
293e93f7393Sniklas f = HEADER_FILES (current_objfile) + real_filenum;
294e93f7393Sniklas
295e93f7393Sniklas f_orig_length = f->length;
296e93f7393Sniklas if (index >= f_orig_length)
297e93f7393Sniklas {
298e93f7393Sniklas while (index >= f->length)
299e93f7393Sniklas {
300e93f7393Sniklas f->length *= 2;
301e93f7393Sniklas }
302e93f7393Sniklas f->vector = (struct type **)
303e93f7393Sniklas xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
304e93f7393Sniklas memset (&f->vector[f_orig_length], 0,
305e93f7393Sniklas (f->length - f_orig_length) * sizeof (struct type *));
306e93f7393Sniklas }
307e93f7393Sniklas return (&f->vector[index]);
308e93f7393Sniklas }
309e93f7393Sniklas }
310e93f7393Sniklas
311e93f7393Sniklas /* Make sure there is a type allocated for type numbers TYPENUMS
312e93f7393Sniklas and return the type object.
313e93f7393Sniklas This can create an empty (zeroed) type object.
314e93f7393Sniklas TYPENUMS may be (-1, -1) to return a new type object that is not
315e93f7393Sniklas put into the type vector, and so may not be referred to by number. */
316e93f7393Sniklas
317e93f7393Sniklas static struct type *
dbx_alloc_type(int typenums[2],struct objfile * objfile)318b725ae77Skettenis dbx_alloc_type (int typenums[2], struct objfile *objfile)
319e93f7393Sniklas {
320b725ae77Skettenis struct type **type_addr;
321e93f7393Sniklas
322e93f7393Sniklas if (typenums[0] == -1)
323e93f7393Sniklas {
324e93f7393Sniklas return (alloc_type (objfile));
325e93f7393Sniklas }
326e93f7393Sniklas
327e93f7393Sniklas type_addr = dbx_lookup_type (typenums);
328e93f7393Sniklas
329e93f7393Sniklas /* If we are referring to a type not known at all yet,
330e93f7393Sniklas allocate an empty type for it.
331e93f7393Sniklas We will fill it in later if we find out how. */
332e93f7393Sniklas if (*type_addr == 0)
333e93f7393Sniklas {
334e93f7393Sniklas *type_addr = alloc_type (objfile);
335e93f7393Sniklas }
336e93f7393Sniklas
337e93f7393Sniklas return (*type_addr);
338e93f7393Sniklas }
339e93f7393Sniklas
340e93f7393Sniklas /* for all the stabs in a given stab vector, build appropriate types
341e93f7393Sniklas and fix their symbols in given symbol vector. */
342e93f7393Sniklas
343e93f7393Sniklas static void
patch_block_stabs(struct pending * symbols,struct pending_stabs * stabs,struct objfile * objfile)344b725ae77Skettenis patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
345b725ae77Skettenis struct objfile *objfile)
346e93f7393Sniklas {
347e93f7393Sniklas int ii;
348e93f7393Sniklas char *name;
349e93f7393Sniklas char *pp;
350e93f7393Sniklas struct symbol *sym;
351e93f7393Sniklas
352e93f7393Sniklas if (stabs)
353e93f7393Sniklas {
354e93f7393Sniklas
355e93f7393Sniklas /* for all the stab entries, find their corresponding symbols and
356e93f7393Sniklas patch their types! */
357e93f7393Sniklas
358e93f7393Sniklas for (ii = 0; ii < stabs->count; ++ii)
359e93f7393Sniklas {
360e93f7393Sniklas name = stabs->stab[ii];
361e93f7393Sniklas pp = (char *) strchr (name, ':');
362e93f7393Sniklas while (pp[1] == ':')
363e93f7393Sniklas {
364e93f7393Sniklas pp += 2;
365e93f7393Sniklas pp = (char *) strchr (pp, ':');
366e93f7393Sniklas }
367e93f7393Sniklas sym = find_symbol_in_list (symbols, name, pp - name);
368e93f7393Sniklas if (!sym)
369e93f7393Sniklas {
370e93f7393Sniklas /* FIXME-maybe: it would be nice if we noticed whether
371e93f7393Sniklas the variable was defined *anywhere*, not just whether
372e93f7393Sniklas it is defined in this compilation unit. But neither
373e93f7393Sniklas xlc or GCC seem to need such a definition, and until
374e93f7393Sniklas we do psymtabs (so that the minimal symbols from all
375e93f7393Sniklas compilation units are available now), I'm not sure
376e93f7393Sniklas how to get the information. */
377e93f7393Sniklas
378e93f7393Sniklas /* On xcoff, if a global is defined and never referenced,
379e93f7393Sniklas ld will remove it from the executable. There is then
380e93f7393Sniklas a N_GSYM stab for it, but no regular (C_EXT) symbol. */
381e93f7393Sniklas sym = (struct symbol *)
382b725ae77Skettenis obstack_alloc (&objfile->objfile_obstack,
383e93f7393Sniklas sizeof (struct symbol));
384e93f7393Sniklas
385e93f7393Sniklas memset (sym, 0, sizeof (struct symbol));
386b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
387e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
388b725ae77Skettenis DEPRECATED_SYMBOL_NAME (sym) =
389b725ae77Skettenis obsavestring (name, pp - name, &objfile->objfile_obstack);
390e93f7393Sniklas pp += 2;
391e93f7393Sniklas if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
392e93f7393Sniklas {
393e93f7393Sniklas /* I don't think the linker does this with functions,
394e93f7393Sniklas so as far as I know this is never executed.
395e93f7393Sniklas But it doesn't hurt to check. */
396e93f7393Sniklas SYMBOL_TYPE (sym) =
397e93f7393Sniklas lookup_function_type (read_type (&pp, objfile));
398e93f7393Sniklas }
399e93f7393Sniklas else
400e93f7393Sniklas {
401e93f7393Sniklas SYMBOL_TYPE (sym) = read_type (&pp, objfile);
402e93f7393Sniklas }
403e93f7393Sniklas add_symbol_to_list (sym, &global_symbols);
404e93f7393Sniklas }
405e93f7393Sniklas else
406e93f7393Sniklas {
407e93f7393Sniklas pp += 2;
408e93f7393Sniklas if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
409e93f7393Sniklas {
410e93f7393Sniklas SYMBOL_TYPE (sym) =
411e93f7393Sniklas lookup_function_type (read_type (&pp, objfile));
412e93f7393Sniklas }
413e93f7393Sniklas else
414e93f7393Sniklas {
415e93f7393Sniklas SYMBOL_TYPE (sym) = read_type (&pp, objfile);
416e93f7393Sniklas }
417e93f7393Sniklas }
418e93f7393Sniklas }
419e93f7393Sniklas }
420e93f7393Sniklas }
421e93f7393Sniklas
422b725ae77Skettenis
423e93f7393Sniklas /* Read a number by which a type is referred to in dbx data,
424e93f7393Sniklas or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
425e93f7393Sniklas Just a single number N is equivalent to (0,N).
426e93f7393Sniklas Return the two numbers by storing them in the vector TYPENUMS.
427e93f7393Sniklas TYPENUMS will then be used as an argument to dbx_lookup_type.
428e93f7393Sniklas
429e93f7393Sniklas Returns 0 for success, -1 for error. */
430e93f7393Sniklas
431e93f7393Sniklas static int
read_type_number(char ** pp,int * typenums)432b725ae77Skettenis read_type_number (char **pp, int *typenums)
433e93f7393Sniklas {
434e93f7393Sniklas int nbits;
435e93f7393Sniklas if (**pp == '(')
436e93f7393Sniklas {
437e93f7393Sniklas (*pp)++;
438e93f7393Sniklas typenums[0] = read_huge_number (pp, ',', &nbits);
439b725ae77Skettenis if (nbits != 0)
440b725ae77Skettenis return -1;
441e93f7393Sniklas typenums[1] = read_huge_number (pp, ')', &nbits);
442b725ae77Skettenis if (nbits != 0)
443b725ae77Skettenis return -1;
444e93f7393Sniklas }
445e93f7393Sniklas else
446e93f7393Sniklas {
447e93f7393Sniklas typenums[0] = 0;
448e93f7393Sniklas typenums[1] = read_huge_number (pp, 0, &nbits);
449b725ae77Skettenis if (nbits != 0)
450b725ae77Skettenis return -1;
451e93f7393Sniklas }
452e93f7393Sniklas return 0;
453e93f7393Sniklas }
454e93f7393Sniklas
455e93f7393Sniklas
456e93f7393Sniklas #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
457e93f7393Sniklas #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
458e93f7393Sniklas #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
459e93f7393Sniklas #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
460e93f7393Sniklas
461b725ae77Skettenis /* Structure for storing pointers to reference definitions for fast lookup
462b725ae77Skettenis during "process_later". */
463e93f7393Sniklas
464b725ae77Skettenis struct ref_map
465e93f7393Sniklas {
466b725ae77Skettenis char *stabs;
467b725ae77Skettenis CORE_ADDR value;
468e93f7393Sniklas struct symbol *sym;
469b725ae77Skettenis };
470b725ae77Skettenis
471b725ae77Skettenis #define MAX_CHUNK_REFS 100
472b725ae77Skettenis #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map))
473b725ae77Skettenis #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE)
474b725ae77Skettenis
475b725ae77Skettenis static struct ref_map *ref_map;
476b725ae77Skettenis
477b725ae77Skettenis /* Ptr to free cell in chunk's linked list. */
478b725ae77Skettenis static int ref_count = 0;
479b725ae77Skettenis
480b725ae77Skettenis /* Number of chunks malloced. */
481b725ae77Skettenis static int ref_chunk = 0;
482b725ae77Skettenis
483b725ae77Skettenis /* This file maintains a cache of stabs aliases found in the symbol
484b725ae77Skettenis table. If the symbol table changes, this cache must be cleared
485b725ae77Skettenis or we are left holding onto data in invalid obstacks. */
486b725ae77Skettenis void
stabsread_clear_cache(void)487b725ae77Skettenis stabsread_clear_cache (void)
488e93f7393Sniklas {
489b725ae77Skettenis ref_count = 0;
490b725ae77Skettenis ref_chunk = 0;
491e93f7393Sniklas }
492e93f7393Sniklas
493b725ae77Skettenis /* Create array of pointers mapping refids to symbols and stab strings.
494b725ae77Skettenis Add pointers to reference definition symbols and/or their values as we
495b725ae77Skettenis find them, using their reference numbers as our index.
496b725ae77Skettenis These will be used later when we resolve references. */
497b725ae77Skettenis void
ref_add(int refnum,struct symbol * sym,char * stabs,CORE_ADDR value)498b725ae77Skettenis ref_add (int refnum, struct symbol *sym, char *stabs, CORE_ADDR value)
499b725ae77Skettenis {
500b725ae77Skettenis if (ref_count == 0)
501b725ae77Skettenis ref_chunk = 0;
502b725ae77Skettenis if (refnum >= ref_count)
503b725ae77Skettenis ref_count = refnum + 1;
504b725ae77Skettenis if (ref_count > ref_chunk * MAX_CHUNK_REFS)
505b725ae77Skettenis {
506b725ae77Skettenis int new_slots = ref_count - ref_chunk * MAX_CHUNK_REFS;
507b725ae77Skettenis int new_chunks = new_slots / MAX_CHUNK_REFS + 1;
508b725ae77Skettenis ref_map = (struct ref_map *)
509b725ae77Skettenis xrealloc (ref_map, REF_MAP_SIZE (ref_chunk + new_chunks));
510b725ae77Skettenis memset (ref_map + ref_chunk * MAX_CHUNK_REFS, 0, new_chunks * REF_CHUNK_SIZE);
511b725ae77Skettenis ref_chunk += new_chunks;
512e93f7393Sniklas }
513b725ae77Skettenis ref_map[refnum].stabs = stabs;
514b725ae77Skettenis ref_map[refnum].sym = sym;
515b725ae77Skettenis ref_map[refnum].value = value;
516b725ae77Skettenis }
517e93f7393Sniklas
518b725ae77Skettenis /* Return defined sym for the reference REFNUM. */
519e93f7393Sniklas struct symbol *
ref_search(int refnum)520b725ae77Skettenis ref_search (int refnum)
521e93f7393Sniklas {
522b725ae77Skettenis if (refnum < 0 || refnum > ref_count)
523b725ae77Skettenis return 0;
524b725ae77Skettenis return ref_map[refnum].sym;
525b725ae77Skettenis }
526b725ae77Skettenis
527b725ae77Skettenis /* Parse a reference id in STRING and return the resulting
528b725ae77Skettenis reference number. Move STRING beyond the reference id. */
529b725ae77Skettenis
530b725ae77Skettenis static int
process_reference(char ** string)531b725ae77Skettenis process_reference (char **string)
532b725ae77Skettenis {
533b725ae77Skettenis char *p;
534b725ae77Skettenis int refnum = 0;
535b725ae77Skettenis
536b725ae77Skettenis if (**string != '#')
537b725ae77Skettenis return 0;
538b725ae77Skettenis
539b725ae77Skettenis /* Advance beyond the initial '#'. */
540b725ae77Skettenis p = *string + 1;
541b725ae77Skettenis
542b725ae77Skettenis /* Read number as reference id. */
543b725ae77Skettenis while (*p && isdigit (*p))
544b725ae77Skettenis {
545b725ae77Skettenis refnum = refnum * 10 + *p - '0';
546b725ae77Skettenis p++;
547b725ae77Skettenis }
548b725ae77Skettenis *string = p;
549b725ae77Skettenis return refnum;
550b725ae77Skettenis }
551b725ae77Skettenis
552b725ae77Skettenis /* If STRING defines a reference, store away a pointer to the reference
553b725ae77Skettenis definition for later use. Return the reference number. */
554b725ae77Skettenis
555b725ae77Skettenis int
symbol_reference_defined(char ** string)556b725ae77Skettenis symbol_reference_defined (char **string)
557b725ae77Skettenis {
558b725ae77Skettenis char *p = *string;
559b725ae77Skettenis int refnum = 0;
560b725ae77Skettenis
561b725ae77Skettenis refnum = process_reference (&p);
562b725ae77Skettenis
563b725ae77Skettenis /* Defining symbols end in '=' */
564b725ae77Skettenis if (*p == '=')
565b725ae77Skettenis {
566b725ae77Skettenis /* Symbol is being defined here. */
567b725ae77Skettenis *string = p + 1;
568b725ae77Skettenis return refnum;
569b725ae77Skettenis }
570b725ae77Skettenis else
571b725ae77Skettenis {
572b725ae77Skettenis /* Must be a reference. Either the symbol has already been defined,
573b725ae77Skettenis or this is a forward reference to it. */
574b725ae77Skettenis *string = p;
575b725ae77Skettenis return -1;
576b725ae77Skettenis }
577b725ae77Skettenis }
578b725ae77Skettenis
579b725ae77Skettenis struct symbol *
define_symbol(CORE_ADDR valu,char * string,int desc,int type,struct objfile * objfile)580b725ae77Skettenis define_symbol (CORE_ADDR valu, char *string, int desc, int type,
581b725ae77Skettenis struct objfile *objfile)
582b725ae77Skettenis {
583b725ae77Skettenis struct symbol *sym;
584b725ae77Skettenis char *p = (char *) find_name_end (string);
585e93f7393Sniklas int deftype;
586e93f7393Sniklas int synonym = 0;
587b725ae77Skettenis int i;
588e93f7393Sniklas
589e93f7393Sniklas /* We would like to eliminate nameless symbols, but keep their types.
590e93f7393Sniklas E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
591e93f7393Sniklas to type 2, but, should not create a symbol to address that type. Since
592e93f7393Sniklas the symbol will be nameless, there is no way any user can refer to it. */
593e93f7393Sniklas
594e93f7393Sniklas int nameless;
595e93f7393Sniklas
596e93f7393Sniklas /* Ignore syms with empty names. */
597e93f7393Sniklas if (string[0] == 0)
598e93f7393Sniklas return 0;
599e93f7393Sniklas
600e93f7393Sniklas /* Ignore old-style symbols from cc -go */
601e93f7393Sniklas if (p == 0)
602e93f7393Sniklas return 0;
603e93f7393Sniklas
604e93f7393Sniklas while (p[1] == ':')
605e93f7393Sniklas {
606e93f7393Sniklas p += 2;
607e93f7393Sniklas p = strchr (p, ':');
608e93f7393Sniklas }
609e93f7393Sniklas
610e93f7393Sniklas /* If a nameless stab entry, all we need is the type, not the symbol.
611e93f7393Sniklas e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
612e93f7393Sniklas nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
613e93f7393Sniklas
614e93f7393Sniklas current_symbol = sym = (struct symbol *)
615b725ae77Skettenis obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol));
616e93f7393Sniklas memset (sym, 0, sizeof (struct symbol));
617e93f7393Sniklas
618e93f7393Sniklas switch (type & N_TYPE)
619e93f7393Sniklas {
620e93f7393Sniklas case N_TEXT:
621b725ae77Skettenis SYMBOL_SECTION (sym) = SECT_OFF_TEXT (objfile);
622e93f7393Sniklas break;
623e93f7393Sniklas case N_DATA:
624b725ae77Skettenis SYMBOL_SECTION (sym) = SECT_OFF_DATA (objfile);
625e93f7393Sniklas break;
626e93f7393Sniklas case N_BSS:
627b725ae77Skettenis SYMBOL_SECTION (sym) = SECT_OFF_BSS (objfile);
628e93f7393Sniklas break;
629e93f7393Sniklas }
630e93f7393Sniklas
631e93f7393Sniklas if (processing_gcc_compilation)
632e93f7393Sniklas {
633e93f7393Sniklas /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
634e93f7393Sniklas number of bytes occupied by a type or object, which we ignore. */
635e93f7393Sniklas SYMBOL_LINE (sym) = desc;
636e93f7393Sniklas }
637e93f7393Sniklas else
638e93f7393Sniklas {
639e93f7393Sniklas SYMBOL_LINE (sym) = 0; /* unknown */
640e93f7393Sniklas }
641e93f7393Sniklas
642e93f7393Sniklas if (is_cplus_marker (string[0]))
643e93f7393Sniklas {
644e93f7393Sniklas /* Special GNU C++ names. */
645e93f7393Sniklas switch (string[1])
646e93f7393Sniklas {
647e93f7393Sniklas case 't':
648b725ae77Skettenis DEPRECATED_SYMBOL_NAME (sym) = obsavestring ("this", strlen ("this"),
649b725ae77Skettenis &objfile->objfile_obstack);
650e93f7393Sniklas break;
651e93f7393Sniklas
652e93f7393Sniklas case 'v': /* $vtbl_ptr_type */
653b725ae77Skettenis /* Was: DEPRECATED_SYMBOL_NAME (sym) = "vptr"; */
654e93f7393Sniklas goto normal;
655e93f7393Sniklas
656e93f7393Sniklas case 'e':
657b725ae77Skettenis DEPRECATED_SYMBOL_NAME (sym) = obsavestring ("eh_throw", strlen ("eh_throw"),
658b725ae77Skettenis &objfile->objfile_obstack);
659e93f7393Sniklas break;
660e93f7393Sniklas
661e93f7393Sniklas case '_':
662e93f7393Sniklas /* This was an anonymous type that was never fixed up. */
663e93f7393Sniklas goto normal;
664e93f7393Sniklas
665e93f7393Sniklas #ifdef STATIC_TRANSFORM_NAME
666e93f7393Sniklas case 'X':
667e93f7393Sniklas /* SunPRO (3.0 at least) static variable encoding. */
668e93f7393Sniklas goto normal;
669e93f7393Sniklas #endif
670e93f7393Sniklas
671e93f7393Sniklas default:
672b725ae77Skettenis complaint (&symfile_complaints, "Unknown C++ symbol name `%s'",
673b725ae77Skettenis string);
674e93f7393Sniklas goto normal; /* Do *something* with it */
675e93f7393Sniklas }
676e93f7393Sniklas }
677e93f7393Sniklas else
678e93f7393Sniklas {
679e93f7393Sniklas normal:
680e93f7393Sniklas SYMBOL_LANGUAGE (sym) = current_subfile->language;
681b725ae77Skettenis SYMBOL_SET_NAMES (sym, string, p - string, objfile);
682e93f7393Sniklas }
683e93f7393Sniklas p++;
684e93f7393Sniklas
685e93f7393Sniklas /* Determine the type of name being defined. */
686e93f7393Sniklas #if 0
687e93f7393Sniklas /* Getting GDB to correctly skip the symbol on an undefined symbol
688e93f7393Sniklas descriptor and not ever dump core is a very dodgy proposition if
689e93f7393Sniklas we do things this way. I say the acorn RISC machine can just
690e93f7393Sniklas fix their compiler. */
691e93f7393Sniklas /* The Acorn RISC machine's compiler can put out locals that don't
692e93f7393Sniklas start with "234=" or "(3,4)=", so assume anything other than the
693e93f7393Sniklas deftypes we know how to handle is a local. */
694e93f7393Sniklas if (!strchr ("cfFGpPrStTvVXCR", *p))
695e93f7393Sniklas #else
696e93f7393Sniklas if (isdigit (*p) || *p == '(' || *p == '-')
697e93f7393Sniklas #endif
698e93f7393Sniklas deftype = 'l';
699e93f7393Sniklas else
700e93f7393Sniklas deftype = *p++;
701e93f7393Sniklas
702e93f7393Sniklas switch (deftype)
703e93f7393Sniklas {
704e93f7393Sniklas case 'c':
705e93f7393Sniklas /* c is a special case, not followed by a type-number.
706e93f7393Sniklas SYMBOL:c=iVALUE for an integer constant symbol.
707e93f7393Sniklas SYMBOL:c=rVALUE for a floating constant symbol.
708e93f7393Sniklas SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
709e93f7393Sniklas e.g. "b:c=e6,0" for "const b = blob1"
710e93f7393Sniklas (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
711e93f7393Sniklas if (*p != '=')
712e93f7393Sniklas {
713e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_CONST;
714e93f7393Sniklas SYMBOL_TYPE (sym) = error_type (&p, objfile);
715b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
716e93f7393Sniklas add_symbol_to_list (sym, &file_symbols);
717e93f7393Sniklas return sym;
718e93f7393Sniklas }
719e93f7393Sniklas ++p;
720e93f7393Sniklas switch (*p++)
721e93f7393Sniklas {
722e93f7393Sniklas case 'r':
723e93f7393Sniklas {
724e93f7393Sniklas double d = atof (p);
725e93f7393Sniklas char *dbl_valu;
726e93f7393Sniklas
727e93f7393Sniklas /* FIXME-if-picky-about-floating-accuracy: Should be using
728e93f7393Sniklas target arithmetic to get the value. real.c in GCC
729e93f7393Sniklas probably has the necessary code. */
730e93f7393Sniklas
731e93f7393Sniklas /* FIXME: lookup_fundamental_type is a hack. We should be
732e93f7393Sniklas creating a type especially for the type of float constants.
733e93f7393Sniklas Problem is, what type should it be?
734e93f7393Sniklas
735e93f7393Sniklas Also, what should the name of this type be? Should we
736e93f7393Sniklas be using 'S' constants (see stabs.texinfo) instead? */
737e93f7393Sniklas
738e93f7393Sniklas SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
739e93f7393Sniklas FT_DBL_PREC_FLOAT);
740e93f7393Sniklas dbl_valu = (char *)
741b725ae77Skettenis obstack_alloc (&objfile->objfile_obstack,
742e93f7393Sniklas TYPE_LENGTH (SYMBOL_TYPE (sym)));
743b725ae77Skettenis store_typed_floating (dbl_valu, SYMBOL_TYPE (sym), d);
744e93f7393Sniklas SYMBOL_VALUE_BYTES (sym) = dbl_valu;
745e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
746e93f7393Sniklas }
747e93f7393Sniklas break;
748e93f7393Sniklas case 'i':
749e93f7393Sniklas {
750e93f7393Sniklas /* Defining integer constants this way is kind of silly,
751e93f7393Sniklas since 'e' constants allows the compiler to give not
752e93f7393Sniklas only the value, but the type as well. C has at least
753e93f7393Sniklas int, long, unsigned int, and long long as constant
754e93f7393Sniklas types; other languages probably should have at least
755e93f7393Sniklas unsigned as well as signed constants. */
756e93f7393Sniklas
757e93f7393Sniklas /* We just need one int constant type for all objfiles.
758e93f7393Sniklas It doesn't depend on languages or anything (arguably its
759e93f7393Sniklas name should be a language-specific name for a type of
760e93f7393Sniklas that size, but I'm inclined to say that if the compiler
761e93f7393Sniklas wants a nice name for the type, it can use 'e'). */
762e93f7393Sniklas static struct type *int_const_type;
763e93f7393Sniklas
764e93f7393Sniklas /* Yes, this is as long as a *host* int. That is because we
765e93f7393Sniklas use atoi. */
766e93f7393Sniklas if (int_const_type == NULL)
767e93f7393Sniklas int_const_type =
768e93f7393Sniklas init_type (TYPE_CODE_INT,
769e93f7393Sniklas sizeof (int) * HOST_CHAR_BIT / TARGET_CHAR_BIT, 0,
770e93f7393Sniklas "integer constant",
771e93f7393Sniklas (struct objfile *) NULL);
772e93f7393Sniklas SYMBOL_TYPE (sym) = int_const_type;
773e93f7393Sniklas SYMBOL_VALUE (sym) = atoi (p);
774e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_CONST;
775e93f7393Sniklas }
776e93f7393Sniklas break;
777e93f7393Sniklas case 'e':
778e93f7393Sniklas /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
779e93f7393Sniklas can be represented as integral.
780e93f7393Sniklas e.g. "b:c=e6,0" for "const b = blob1"
781e93f7393Sniklas (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
782e93f7393Sniklas {
783e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_CONST;
784e93f7393Sniklas SYMBOL_TYPE (sym) = read_type (&p, objfile);
785e93f7393Sniklas
786e93f7393Sniklas if (*p != ',')
787e93f7393Sniklas {
788e93f7393Sniklas SYMBOL_TYPE (sym) = error_type (&p, objfile);
789e93f7393Sniklas break;
790e93f7393Sniklas }
791e93f7393Sniklas ++p;
792e93f7393Sniklas
793e93f7393Sniklas /* If the value is too big to fit in an int (perhaps because
794e93f7393Sniklas it is unsigned), or something like that, we silently get
795e93f7393Sniklas a bogus value. The type and everything else about it is
796e93f7393Sniklas correct. Ideally, we should be using whatever we have
797e93f7393Sniklas available for parsing unsigned and long long values,
798e93f7393Sniklas however. */
799e93f7393Sniklas SYMBOL_VALUE (sym) = atoi (p);
800e93f7393Sniklas }
801e93f7393Sniklas break;
802e93f7393Sniklas default:
803e93f7393Sniklas {
804e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_CONST;
805e93f7393Sniklas SYMBOL_TYPE (sym) = error_type (&p, objfile);
806e93f7393Sniklas }
807e93f7393Sniklas }
808b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
809e93f7393Sniklas add_symbol_to_list (sym, &file_symbols);
810e93f7393Sniklas return sym;
811e93f7393Sniklas
812e93f7393Sniklas case 'C':
813e93f7393Sniklas /* The name of a caught exception. */
814e93f7393Sniklas SYMBOL_TYPE (sym) = read_type (&p, objfile);
815e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_LABEL;
816b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
817e93f7393Sniklas SYMBOL_VALUE_ADDRESS (sym) = valu;
818e93f7393Sniklas add_symbol_to_list (sym, &local_symbols);
819e93f7393Sniklas break;
820e93f7393Sniklas
821e93f7393Sniklas case 'f':
822e93f7393Sniklas /* A static function definition. */
823e93f7393Sniklas SYMBOL_TYPE (sym) = read_type (&p, objfile);
824e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_BLOCK;
825b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
826e93f7393Sniklas add_symbol_to_list (sym, &file_symbols);
827e93f7393Sniklas /* fall into process_function_types. */
828e93f7393Sniklas
829e93f7393Sniklas process_function_types:
830e93f7393Sniklas /* Function result types are described as the result type in stabs.
831e93f7393Sniklas We need to convert this to the function-returning-type-X type
832e93f7393Sniklas in GDB. E.g. "int" is converted to "function returning int". */
833e93f7393Sniklas if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC)
834e93f7393Sniklas SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
835b725ae77Skettenis
836b725ae77Skettenis /* All functions in C++ have prototypes. Stabs does not offer an
837b725ae77Skettenis explicit way to identify prototyped or unprototyped functions,
838b725ae77Skettenis but both GCC and Sun CC emit stabs for the "call-as" type rather
839b725ae77Skettenis than the "declared-as" type for unprototyped functions, so
840b725ae77Skettenis we treat all functions as if they were prototyped. This is used
841b725ae77Skettenis primarily for promotion when calling the function from GDB. */
842b725ae77Skettenis TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED;
843b725ae77Skettenis
844e93f7393Sniklas /* fall into process_prototype_types */
845e93f7393Sniklas
846e93f7393Sniklas process_prototype_types:
847b725ae77Skettenis /* Sun acc puts declared types of arguments here. */
848b725ae77Skettenis if (*p == ';')
849b725ae77Skettenis {
850b725ae77Skettenis struct type *ftype = SYMBOL_TYPE (sym);
851b725ae77Skettenis int nsemi = 0;
852b725ae77Skettenis int nparams = 0;
853b725ae77Skettenis char *p1 = p;
854b725ae77Skettenis
855b725ae77Skettenis /* Obtain a worst case guess for the number of arguments
856b725ae77Skettenis by counting the semicolons. */
857b725ae77Skettenis while (*p1)
858b725ae77Skettenis {
859b725ae77Skettenis if (*p1++ == ';')
860b725ae77Skettenis nsemi++;
861b725ae77Skettenis }
862b725ae77Skettenis
863b725ae77Skettenis /* Allocate parameter information fields and fill them in. */
864b725ae77Skettenis TYPE_FIELDS (ftype) = (struct field *)
865b725ae77Skettenis TYPE_ALLOC (ftype, nsemi * sizeof (struct field));
866b725ae77Skettenis while (*p++ == ';')
867b725ae77Skettenis {
868b725ae77Skettenis struct type *ptype;
869b725ae77Skettenis
870b725ae77Skettenis /* A type number of zero indicates the start of varargs.
871b725ae77Skettenis FIXME: GDB currently ignores vararg functions. */
872b725ae77Skettenis if (p[0] == '0' && p[1] == '\0')
873b725ae77Skettenis break;
874b725ae77Skettenis ptype = read_type (&p, objfile);
875b725ae77Skettenis
876b725ae77Skettenis /* The Sun compilers mark integer arguments, which should
877b725ae77Skettenis be promoted to the width of the calling conventions, with
878b725ae77Skettenis a type which references itself. This type is turned into
879b725ae77Skettenis a TYPE_CODE_VOID type by read_type, and we have to turn
880b725ae77Skettenis it back into builtin_type_int here.
881b725ae77Skettenis FIXME: Do we need a new builtin_type_promoted_int_arg ? */
882b725ae77Skettenis if (TYPE_CODE (ptype) == TYPE_CODE_VOID)
883b725ae77Skettenis ptype = builtin_type_int;
884b725ae77Skettenis TYPE_FIELD_TYPE (ftype, nparams) = ptype;
885b725ae77Skettenis TYPE_FIELD_ARTIFICIAL (ftype, nparams++) = 0;
886b725ae77Skettenis }
887b725ae77Skettenis TYPE_NFIELDS (ftype) = nparams;
888b725ae77Skettenis TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
889e93f7393Sniklas }
890e93f7393Sniklas break;
891e93f7393Sniklas
892e93f7393Sniklas case 'F':
893e93f7393Sniklas /* A global function definition. */
894e93f7393Sniklas SYMBOL_TYPE (sym) = read_type (&p, objfile);
895e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_BLOCK;
896b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
897e93f7393Sniklas add_symbol_to_list (sym, &global_symbols);
898e93f7393Sniklas goto process_function_types;
899e93f7393Sniklas
900e93f7393Sniklas case 'G':
901e93f7393Sniklas /* For a class G (global) symbol, it appears that the
902e93f7393Sniklas value is not correct. It is necessary to search for the
903e93f7393Sniklas corresponding linker definition to find the value.
904e93f7393Sniklas These definitions appear at the end of the namelist. */
905e93f7393Sniklas SYMBOL_TYPE (sym) = read_type (&p, objfile);
906b725ae77Skettenis SYMBOL_CLASS (sym) = LOC_STATIC;
907b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
908b725ae77Skettenis /* Don't add symbol references to global_sym_chain.
909b725ae77Skettenis Symbol references don't have valid names and wont't match up with
910b725ae77Skettenis minimal symbols when the global_sym_chain is relocated.
911b725ae77Skettenis We'll fixup symbol references when we fixup the defining symbol. */
912b725ae77Skettenis if (DEPRECATED_SYMBOL_NAME (sym) && DEPRECATED_SYMBOL_NAME (sym)[0] != '#')
913b725ae77Skettenis {
914b725ae77Skettenis i = hashname (DEPRECATED_SYMBOL_NAME (sym));
915e93f7393Sniklas SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
916e93f7393Sniklas global_sym_chain[i] = sym;
917b725ae77Skettenis }
918e93f7393Sniklas add_symbol_to_list (sym, &global_symbols);
919e93f7393Sniklas break;
920e93f7393Sniklas
921e93f7393Sniklas /* This case is faked by a conditional above,
922e93f7393Sniklas when there is no code letter in the dbx data.
923e93f7393Sniklas Dbx data never actually contains 'l'. */
924e93f7393Sniklas case 's':
925e93f7393Sniklas case 'l':
926e93f7393Sniklas SYMBOL_TYPE (sym) = read_type (&p, objfile);
927e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_LOCAL;
928e93f7393Sniklas SYMBOL_VALUE (sym) = valu;
929b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
930e93f7393Sniklas add_symbol_to_list (sym, &local_symbols);
931e93f7393Sniklas break;
932e93f7393Sniklas
933e93f7393Sniklas case 'p':
934e93f7393Sniklas if (*p == 'F')
935e93f7393Sniklas /* pF is a two-letter code that means a function parameter in Fortran.
936e93f7393Sniklas The type-number specifies the type of the return value.
937e93f7393Sniklas Translate it into a pointer-to-function type. */
938e93f7393Sniklas {
939e93f7393Sniklas p++;
940e93f7393Sniklas SYMBOL_TYPE (sym)
941e93f7393Sniklas = lookup_pointer_type
942e93f7393Sniklas (lookup_function_type (read_type (&p, objfile)));
943e93f7393Sniklas }
944e93f7393Sniklas else
945e93f7393Sniklas SYMBOL_TYPE (sym) = read_type (&p, objfile);
946e93f7393Sniklas
947b725ae77Skettenis SYMBOL_CLASS (sym) = LOC_ARG;
948e93f7393Sniklas SYMBOL_VALUE (sym) = valu;
949b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
950e93f7393Sniklas add_symbol_to_list (sym, &local_symbols);
951e93f7393Sniklas
952b725ae77Skettenis if (TARGET_BYTE_ORDER != BFD_ENDIAN_BIG)
953e93f7393Sniklas {
954e93f7393Sniklas /* On little-endian machines, this crud is never necessary,
955e93f7393Sniklas and, if the extra bytes contain garbage, is harmful. */
956e93f7393Sniklas break;
957e93f7393Sniklas }
958e93f7393Sniklas
959e93f7393Sniklas /* If it's gcc-compiled, if it says `short', believe it. */
960e93f7393Sniklas if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
961e93f7393Sniklas break;
962e93f7393Sniklas
963b725ae77Skettenis if (!BELIEVE_PCC_PROMOTION)
964e93f7393Sniklas {
965e93f7393Sniklas /* This is the signed type which arguments get promoted to. */
966e93f7393Sniklas static struct type *pcc_promotion_type;
967e93f7393Sniklas /* This is the unsigned type which arguments get promoted to. */
968e93f7393Sniklas static struct type *pcc_unsigned_promotion_type;
969e93f7393Sniklas
970e93f7393Sniklas /* Call it "int" because this is mainly C lossage. */
971e93f7393Sniklas if (pcc_promotion_type == NULL)
972e93f7393Sniklas pcc_promotion_type =
973e93f7393Sniklas init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
974e93f7393Sniklas 0, "int", NULL);
975e93f7393Sniklas
976e93f7393Sniklas if (pcc_unsigned_promotion_type == NULL)
977e93f7393Sniklas pcc_unsigned_promotion_type =
978e93f7393Sniklas init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
979e93f7393Sniklas TYPE_FLAG_UNSIGNED, "unsigned int", NULL);
980e93f7393Sniklas
981*63addd46Skettenis /* If PCC says a parameter is a short or a char, it is
982*63addd46Skettenis really an int. */
983e93f7393Sniklas if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
984e93f7393Sniklas && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
985e93f7393Sniklas {
986e93f7393Sniklas SYMBOL_TYPE (sym) =
987e93f7393Sniklas TYPE_UNSIGNED (SYMBOL_TYPE (sym))
988e93f7393Sniklas ? pcc_unsigned_promotion_type
989e93f7393Sniklas : pcc_promotion_type;
990e93f7393Sniklas }
991e93f7393Sniklas break;
992e93f7393Sniklas }
993e93f7393Sniklas
994e93f7393Sniklas case 'P':
995e93f7393Sniklas /* acc seems to use P to declare the prototypes of functions that
996e93f7393Sniklas are referenced by this file. gdb is not prepared to deal
997e93f7393Sniklas with this extra information. FIXME, it ought to. */
998e93f7393Sniklas if (type == N_FUN)
999e93f7393Sniklas {
1000e93f7393Sniklas SYMBOL_TYPE (sym) = read_type (&p, objfile);
1001e93f7393Sniklas goto process_prototype_types;
1002e93f7393Sniklas }
1003e93f7393Sniklas /*FALLTHROUGH */
1004e93f7393Sniklas
1005e93f7393Sniklas case 'R':
1006e93f7393Sniklas /* Parameter which is in a register. */
1007e93f7393Sniklas SYMBOL_TYPE (sym) = read_type (&p, objfile);
1008e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_REGPARM;
1009e93f7393Sniklas SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1010b725ae77Skettenis if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
1011e93f7393Sniklas {
1012b725ae77Skettenis reg_value_complaint (SYMBOL_VALUE (sym),
1013b725ae77Skettenis NUM_REGS + NUM_PSEUDO_REGS,
1014b725ae77Skettenis SYMBOL_PRINT_NAME (sym));
1015e93f7393Sniklas SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1016e93f7393Sniklas }
1017b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
1018e93f7393Sniklas add_symbol_to_list (sym, &local_symbols);
1019e93f7393Sniklas break;
1020e93f7393Sniklas
1021e93f7393Sniklas case 'r':
1022e93f7393Sniklas /* Register variable (either global or local). */
1023e93f7393Sniklas SYMBOL_TYPE (sym) = read_type (&p, objfile);
1024e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_REGISTER;
1025e93f7393Sniklas SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1026b725ae77Skettenis if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
1027e93f7393Sniklas {
1028b725ae77Skettenis reg_value_complaint (SYMBOL_VALUE (sym),
1029b725ae77Skettenis NUM_REGS + NUM_PSEUDO_REGS,
1030b725ae77Skettenis SYMBOL_PRINT_NAME (sym));
1031e93f7393Sniklas SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1032e93f7393Sniklas }
1033b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
1034e93f7393Sniklas if (within_function)
1035e93f7393Sniklas {
1036b725ae77Skettenis /* Sun cc uses a pair of symbols, one 'p' and one 'r', with
1037b725ae77Skettenis the same name to represent an argument passed in a
1038b725ae77Skettenis register. GCC uses 'P' for the same case. So if we find
1039b725ae77Skettenis such a symbol pair we combine it into one 'P' symbol.
1040b725ae77Skettenis For Sun cc we need to do this regardless of
1041b725ae77Skettenis stabs_argument_has_addr, because the compiler puts out
1042b725ae77Skettenis the 'p' symbol even if it never saves the argument onto
1043b725ae77Skettenis the stack.
1044e93f7393Sniklas
1045b725ae77Skettenis On most machines, we want to preserve both symbols, so
1046b725ae77Skettenis that we can still get information about what is going on
1047b725ae77Skettenis with the stack (VAX for computing args_printed, using
1048b725ae77Skettenis stack slots instead of saved registers in backtraces,
1049b725ae77Skettenis etc.).
1050e93f7393Sniklas
1051e93f7393Sniklas Note that this code illegally combines
1052e93f7393Sniklas main(argc) struct foo argc; { register struct foo argc; }
1053e93f7393Sniklas but this case is considered pathological and causes a warning
1054e93f7393Sniklas from a decent compiler. */
1055e93f7393Sniklas
1056e93f7393Sniklas if (local_symbols
1057e93f7393Sniklas && local_symbols->nsyms > 0
1058b725ae77Skettenis && gdbarch_stabs_argument_has_addr (current_gdbarch,
1059b725ae77Skettenis SYMBOL_TYPE (sym)))
1060e93f7393Sniklas {
1061e93f7393Sniklas struct symbol *prev_sym;
1062e93f7393Sniklas prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
1063e93f7393Sniklas if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG
1064e93f7393Sniklas || SYMBOL_CLASS (prev_sym) == LOC_ARG)
1065b725ae77Skettenis && strcmp (DEPRECATED_SYMBOL_NAME (prev_sym),
1066b725ae77Skettenis DEPRECATED_SYMBOL_NAME (sym)) == 0)
1067e93f7393Sniklas {
1068e93f7393Sniklas SYMBOL_CLASS (prev_sym) = LOC_REGPARM;
1069e93f7393Sniklas /* Use the type from the LOC_REGISTER; that is the type
1070e93f7393Sniklas that is actually in that register. */
1071e93f7393Sniklas SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym);
1072e93f7393Sniklas SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym);
1073e93f7393Sniklas sym = prev_sym;
1074e93f7393Sniklas break;
1075e93f7393Sniklas }
1076e93f7393Sniklas }
1077e93f7393Sniklas add_symbol_to_list (sym, &local_symbols);
1078e93f7393Sniklas }
1079e93f7393Sniklas else
1080e93f7393Sniklas add_symbol_to_list (sym, &file_symbols);
1081e93f7393Sniklas break;
1082e93f7393Sniklas
1083e93f7393Sniklas case 'S':
1084e93f7393Sniklas /* Static symbol at top level of file */
1085e93f7393Sniklas SYMBOL_TYPE (sym) = read_type (&p, objfile);
1086e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_STATIC;
1087e93f7393Sniklas SYMBOL_VALUE_ADDRESS (sym) = valu;
1088e93f7393Sniklas #ifdef STATIC_TRANSFORM_NAME
1089b725ae77Skettenis if (IS_STATIC_TRANSFORM_NAME (DEPRECATED_SYMBOL_NAME (sym)))
1090e93f7393Sniklas {
1091e93f7393Sniklas struct minimal_symbol *msym;
1092b725ae77Skettenis msym = lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (sym), NULL, objfile);
1093e93f7393Sniklas if (msym != NULL)
1094e93f7393Sniklas {
1095b725ae77Skettenis DEPRECATED_SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (DEPRECATED_SYMBOL_NAME (sym));
1096e93f7393Sniklas SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
1097e93f7393Sniklas }
1098e93f7393Sniklas }
1099e93f7393Sniklas #endif
1100b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
1101e93f7393Sniklas add_symbol_to_list (sym, &file_symbols);
1102e93f7393Sniklas break;
1103e93f7393Sniklas
1104e93f7393Sniklas case 't':
1105b725ae77Skettenis /* Typedef */
1106e93f7393Sniklas SYMBOL_TYPE (sym) = read_type (&p, objfile);
1107e93f7393Sniklas
1108e93f7393Sniklas /* For a nameless type, we don't want a create a symbol, thus we
1109e93f7393Sniklas did not use `sym'. Return without further processing. */
1110b725ae77Skettenis if (nameless)
1111b725ae77Skettenis return NULL;
1112e93f7393Sniklas
1113e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1114e93f7393Sniklas SYMBOL_VALUE (sym) = valu;
1115b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
1116e93f7393Sniklas /* C++ vagaries: we may have a type which is derived from
1117e93f7393Sniklas a base type which did not have its name defined when the
1118e93f7393Sniklas derived class was output. We fill in the derived class's
1119e93f7393Sniklas base part member's name here in that case. */
1120e93f7393Sniklas if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
1121e93f7393Sniklas if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1122e93f7393Sniklas || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1123e93f7393Sniklas && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
1124e93f7393Sniklas {
1125e93f7393Sniklas int j;
1126e93f7393Sniklas for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
1127e93f7393Sniklas if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
1128e93f7393Sniklas TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
1129e93f7393Sniklas type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
1130e93f7393Sniklas }
1131e93f7393Sniklas
1132e93f7393Sniklas if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL)
1133e93f7393Sniklas {
1134e93f7393Sniklas /* gcc-2.6 or later (when using -fvtable-thunks)
1135e93f7393Sniklas emits a unique named type for a vtable entry.
1136e93f7393Sniklas Some gdb code depends on that specific name. */
1137e93f7393Sniklas extern const char vtbl_ptr_name[];
1138e93f7393Sniklas
1139e93f7393Sniklas if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
1140b725ae77Skettenis && strcmp (DEPRECATED_SYMBOL_NAME (sym), vtbl_ptr_name))
1141e93f7393Sniklas || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
1142e93f7393Sniklas {
1143e93f7393Sniklas /* If we are giving a name to a type such as "pointer to
1144e93f7393Sniklas foo" or "function returning foo", we better not set
1145e93f7393Sniklas the TYPE_NAME. If the program contains "typedef char
1146e93f7393Sniklas *caddr_t;", we don't want all variables of type char
1147e93f7393Sniklas * to print as caddr_t. This is not just a
1148e93f7393Sniklas consequence of GDB's type management; PCC and GCC (at
1149e93f7393Sniklas least through version 2.4) both output variables of
1150e93f7393Sniklas either type char * or caddr_t with the type number
1151e93f7393Sniklas defined in the 't' symbol for caddr_t. If a future
1152e93f7393Sniklas compiler cleans this up it GDB is not ready for it
1153e93f7393Sniklas yet, but if it becomes ready we somehow need to
1154e93f7393Sniklas disable this check (without breaking the PCC/GCC2.4
1155e93f7393Sniklas case).
1156e93f7393Sniklas
1157e93f7393Sniklas Sigh.
1158e93f7393Sniklas
1159e93f7393Sniklas Fortunately, this check seems not to be necessary
1160e93f7393Sniklas for anything except pointers or functions. */
1161b725ae77Skettenis /* ezannoni: 2000-10-26. This seems to apply for
1162b725ae77Skettenis versions of gcc older than 2.8. This was the original
1163b725ae77Skettenis problem: with the following code gdb would tell that
1164b725ae77Skettenis the type for name1 is caddr_t, and func is char()
1165b725ae77Skettenis typedef char *caddr_t;
1166b725ae77Skettenis char *name2;
1167b725ae77Skettenis struct x
1168b725ae77Skettenis {
1169b725ae77Skettenis char *name1;
1170b725ae77Skettenis } xx;
1171b725ae77Skettenis char *func()
1172b725ae77Skettenis {
1173b725ae77Skettenis }
1174b725ae77Skettenis main () {}
1175b725ae77Skettenis */
1176b725ae77Skettenis
1177b725ae77Skettenis /* Pascal accepts names for pointer types. */
1178b725ae77Skettenis if (current_subfile->language == language_pascal)
1179b725ae77Skettenis {
1180b725ae77Skettenis TYPE_NAME (SYMBOL_TYPE (sym)) = DEPRECATED_SYMBOL_NAME (sym);
1181b725ae77Skettenis }
1182e93f7393Sniklas }
1183e93f7393Sniklas else
1184b725ae77Skettenis TYPE_NAME (SYMBOL_TYPE (sym)) = DEPRECATED_SYMBOL_NAME (sym);
1185e93f7393Sniklas }
1186e93f7393Sniklas
1187e93f7393Sniklas add_symbol_to_list (sym, &file_symbols);
1188e93f7393Sniklas break;
1189e93f7393Sniklas
1190e93f7393Sniklas case 'T':
1191e93f7393Sniklas /* Struct, union, or enum tag. For GNU C++, this can be be followed
1192e93f7393Sniklas by 't' which means we are typedef'ing it as well. */
1193e93f7393Sniklas synonym = *p == 't';
1194e93f7393Sniklas
1195e93f7393Sniklas if (synonym)
1196e93f7393Sniklas p++;
1197e93f7393Sniklas
1198e93f7393Sniklas SYMBOL_TYPE (sym) = read_type (&p, objfile);
1199e93f7393Sniklas
1200e93f7393Sniklas /* For a nameless type, we don't want a create a symbol, thus we
1201e93f7393Sniklas did not use `sym'. Return without further processing. */
1202b725ae77Skettenis if (nameless)
1203b725ae77Skettenis return NULL;
1204e93f7393Sniklas
1205e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1206e93f7393Sniklas SYMBOL_VALUE (sym) = valu;
1207b725ae77Skettenis SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
1208e93f7393Sniklas if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
1209e93f7393Sniklas TYPE_TAG_NAME (SYMBOL_TYPE (sym))
1210b725ae77Skettenis = obconcat (&objfile->objfile_obstack, "", "", DEPRECATED_SYMBOL_NAME (sym));
1211e93f7393Sniklas add_symbol_to_list (sym, &file_symbols);
1212e93f7393Sniklas
1213e93f7393Sniklas if (synonym)
1214e93f7393Sniklas {
1215e93f7393Sniklas /* Clone the sym and then modify it. */
1216b725ae77Skettenis struct symbol *typedef_sym = (struct symbol *)
1217b725ae77Skettenis obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol));
1218e93f7393Sniklas *typedef_sym = *sym;
1219e93f7393Sniklas SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
1220e93f7393Sniklas SYMBOL_VALUE (typedef_sym) = valu;
1221b725ae77Skettenis SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN;
1222e93f7393Sniklas if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
1223e93f7393Sniklas TYPE_NAME (SYMBOL_TYPE (sym))
1224b725ae77Skettenis = obconcat (&objfile->objfile_obstack, "", "", DEPRECATED_SYMBOL_NAME (sym));
1225e93f7393Sniklas add_symbol_to_list (typedef_sym, &file_symbols);
1226e93f7393Sniklas }
1227e93f7393Sniklas break;
1228e93f7393Sniklas
1229e93f7393Sniklas case 'V':
1230e93f7393Sniklas /* Static symbol of local scope */
1231e93f7393Sniklas SYMBOL_TYPE (sym) = read_type (&p, objfile);
1232e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_STATIC;
1233e93f7393Sniklas SYMBOL_VALUE_ADDRESS (sym) = valu;
1234e93f7393Sniklas #ifdef STATIC_TRANSFORM_NAME
1235b725ae77Skettenis if (IS_STATIC_TRANSFORM_NAME (DEPRECATED_SYMBOL_NAME (sym)))
1236e93f7393Sniklas {
1237e93f7393Sniklas struct minimal_symbol *msym;
1238b725ae77Skettenis msym = lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (sym), NULL, objfile);
1239e93f7393Sniklas if (msym != NULL)
1240e93f7393Sniklas {
1241b725ae77Skettenis DEPRECATED_SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (DEPRECATED_SYMBOL_NAME (sym));
1242e93f7393Sniklas SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
1243e93f7393Sniklas }
1244e93f7393Sniklas }
1245e93f7393Sniklas #endif
1246b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
1247e93f7393Sniklas add_symbol_to_list (sym, &local_symbols);
1248e93f7393Sniklas break;
1249e93f7393Sniklas
1250e93f7393Sniklas case 'v':
1251e93f7393Sniklas /* Reference parameter */
1252e93f7393Sniklas SYMBOL_TYPE (sym) = read_type (&p, objfile);
1253e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_REF_ARG;
1254e93f7393Sniklas SYMBOL_VALUE (sym) = valu;
1255b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
1256e93f7393Sniklas add_symbol_to_list (sym, &local_symbols);
1257e93f7393Sniklas break;
1258e93f7393Sniklas
1259e93f7393Sniklas case 'a':
1260e93f7393Sniklas /* Reference parameter which is in a register. */
1261e93f7393Sniklas SYMBOL_TYPE (sym) = read_type (&p, objfile);
1262e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1263e93f7393Sniklas SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1264b725ae77Skettenis if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
1265e93f7393Sniklas {
1266b725ae77Skettenis reg_value_complaint (SYMBOL_VALUE (sym),
1267b725ae77Skettenis NUM_REGS + NUM_PSEUDO_REGS,
1268b725ae77Skettenis SYMBOL_PRINT_NAME (sym));
1269e93f7393Sniklas SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1270e93f7393Sniklas }
1271b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
1272e93f7393Sniklas add_symbol_to_list (sym, &local_symbols);
1273e93f7393Sniklas break;
1274e93f7393Sniklas
1275e93f7393Sniklas case 'X':
1276e93f7393Sniklas /* This is used by Sun FORTRAN for "function result value".
1277e93f7393Sniklas Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1278e93f7393Sniklas that Pascal uses it too, but when I tried it Pascal used
1279e93f7393Sniklas "x:3" (local symbol) instead. */
1280e93f7393Sniklas SYMBOL_TYPE (sym) = read_type (&p, objfile);
1281e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_LOCAL;
1282e93f7393Sniklas SYMBOL_VALUE (sym) = valu;
1283b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
1284e93f7393Sniklas add_symbol_to_list (sym, &local_symbols);
1285e93f7393Sniklas break;
1286e93f7393Sniklas
1287e93f7393Sniklas default:
1288e93f7393Sniklas SYMBOL_TYPE (sym) = error_type (&p, objfile);
1289e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_CONST;
1290e93f7393Sniklas SYMBOL_VALUE (sym) = 0;
1291b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
1292e93f7393Sniklas add_symbol_to_list (sym, &file_symbols);
1293e93f7393Sniklas break;
1294e93f7393Sniklas }
1295e93f7393Sniklas
1296b725ae77Skettenis /* Some systems pass variables of certain types by reference instead
1297b725ae77Skettenis of by value, i.e. they will pass the address of a structure (in a
1298b725ae77Skettenis register or on the stack) instead of the structure itself. */
1299e93f7393Sniklas
1300b725ae77Skettenis if (gdbarch_stabs_argument_has_addr (current_gdbarch, SYMBOL_TYPE (sym))
1301e93f7393Sniklas && (SYMBOL_CLASS (sym) == LOC_REGPARM || SYMBOL_CLASS (sym) == LOC_ARG))
1302e93f7393Sniklas {
1303b725ae77Skettenis /* We have to convert LOC_REGPARM to LOC_REGPARM_ADDR (for
1304b725ae77Skettenis variables passed in a register). */
1305e93f7393Sniklas if (SYMBOL_CLASS (sym) == LOC_REGPARM)
1306e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1307e93f7393Sniklas /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
1308b725ae77Skettenis and subsequent arguments on SPARC, for example). */
1309e93f7393Sniklas else if (SYMBOL_CLASS (sym) == LOC_ARG)
1310e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_REF_ARG;
1311e93f7393Sniklas }
1312e93f7393Sniklas
1313e93f7393Sniklas return sym;
1314e93f7393Sniklas }
1315e93f7393Sniklas
1316e93f7393Sniklas /* Skip rest of this symbol and return an error type.
1317e93f7393Sniklas
1318e93f7393Sniklas General notes on error recovery: error_type always skips to the
1319e93f7393Sniklas end of the symbol (modulo cretinous dbx symbol name continuation).
1320e93f7393Sniklas Thus code like this:
1321e93f7393Sniklas
1322e93f7393Sniklas if (*(*pp)++ != ';')
1323e93f7393Sniklas return error_type (pp, objfile);
1324e93f7393Sniklas
1325e93f7393Sniklas is wrong because if *pp starts out pointing at '\0' (typically as the
1326e93f7393Sniklas result of an earlier error), it will be incremented to point to the
1327e93f7393Sniklas start of the next symbol, which might produce strange results, at least
1328e93f7393Sniklas if you run off the end of the string table. Instead use
1329e93f7393Sniklas
1330e93f7393Sniklas if (**pp != ';')
1331e93f7393Sniklas return error_type (pp, objfile);
1332e93f7393Sniklas ++*pp;
1333e93f7393Sniklas
1334e93f7393Sniklas or
1335e93f7393Sniklas
1336e93f7393Sniklas if (**pp != ';')
1337e93f7393Sniklas foo = error_type (pp, objfile);
1338e93f7393Sniklas else
1339e93f7393Sniklas ++*pp;
1340e93f7393Sniklas
1341e93f7393Sniklas And in case it isn't obvious, the point of all this hair is so the compiler
1342e93f7393Sniklas can define new types and new syntaxes, and old versions of the
1343e93f7393Sniklas debugger will be able to read the new symbol tables. */
1344e93f7393Sniklas
1345e93f7393Sniklas static struct type *
error_type(char ** pp,struct objfile * objfile)1346b725ae77Skettenis error_type (char **pp, struct objfile *objfile)
1347e93f7393Sniklas {
1348b725ae77Skettenis complaint (&symfile_complaints, "couldn't parse type; debugger out of date?");
1349e93f7393Sniklas while (1)
1350e93f7393Sniklas {
1351e93f7393Sniklas /* Skip to end of symbol. */
1352e93f7393Sniklas while (**pp != '\0')
1353e93f7393Sniklas {
1354e93f7393Sniklas (*pp)++;
1355e93f7393Sniklas }
1356e93f7393Sniklas
1357e93f7393Sniklas /* Check for and handle cretinous dbx symbol name continuation! */
1358e93f7393Sniklas if ((*pp)[-1] == '\\' || (*pp)[-1] == '?')
1359e93f7393Sniklas {
1360e93f7393Sniklas *pp = next_symbol_text (objfile);
1361e93f7393Sniklas }
1362e93f7393Sniklas else
1363e93f7393Sniklas {
1364e93f7393Sniklas break;
1365e93f7393Sniklas }
1366e93f7393Sniklas }
1367e93f7393Sniklas return (builtin_type_error);
1368e93f7393Sniklas }
1369e93f7393Sniklas
1370b725ae77Skettenis
1371e93f7393Sniklas /* Read type information or a type definition; return the type. Even
1372e93f7393Sniklas though this routine accepts either type information or a type
1373e93f7393Sniklas definition, the distinction is relevant--some parts of stabsread.c
1374e93f7393Sniklas assume that type information starts with a digit, '-', or '(' in
1375e93f7393Sniklas deciding whether to call read_type. */
1376e93f7393Sniklas
1377b725ae77Skettenis static struct type *
read_type(char ** pp,struct objfile * objfile)1378b725ae77Skettenis read_type (char **pp, struct objfile *objfile)
1379e93f7393Sniklas {
1380b725ae77Skettenis struct type *type = 0;
1381e93f7393Sniklas struct type *type1;
1382e93f7393Sniklas int typenums[2];
1383e93f7393Sniklas char type_descriptor;
1384e93f7393Sniklas
1385e93f7393Sniklas /* Size in bits of type if specified by a type attribute, or -1 if
1386e93f7393Sniklas there is no size attribute. */
1387e93f7393Sniklas int type_size = -1;
1388e93f7393Sniklas
1389e93f7393Sniklas /* Used to distinguish string and bitstring from char-array and set. */
1390e93f7393Sniklas int is_string = 0;
1391e93f7393Sniklas
1392b725ae77Skettenis /* Used to distinguish vector from array. */
1393b725ae77Skettenis int is_vector = 0;
1394b725ae77Skettenis
1395e93f7393Sniklas /* Read type number if present. The type number may be omitted.
1396e93f7393Sniklas for instance in a two-dimensional array declared with type
1397e93f7393Sniklas "ar1;1;10;ar1;1;10;4". */
1398e93f7393Sniklas if ((**pp >= '0' && **pp <= '9')
1399e93f7393Sniklas || **pp == '('
1400e93f7393Sniklas || **pp == '-')
1401e93f7393Sniklas {
1402e93f7393Sniklas if (read_type_number (pp, typenums) != 0)
1403e93f7393Sniklas return error_type (pp, objfile);
1404e93f7393Sniklas
1405e93f7393Sniklas if (**pp != '=')
1406b725ae77Skettenis {
1407b725ae77Skettenis /* Type is not being defined here. Either it already
1408b725ae77Skettenis exists, or this is a forward reference to it.
1409b725ae77Skettenis dbx_alloc_type handles both cases. */
1410b725ae77Skettenis type = dbx_alloc_type (typenums, objfile);
1411b725ae77Skettenis
1412b725ae77Skettenis /* If this is a forward reference, arrange to complain if it
1413b725ae77Skettenis doesn't get patched up by the time we're done
1414b725ae77Skettenis reading. */
1415b725ae77Skettenis if (TYPE_CODE (type) == TYPE_CODE_UNDEF)
1416b725ae77Skettenis add_undefined_type (type);
1417b725ae77Skettenis
1418b725ae77Skettenis return type;
1419b725ae77Skettenis }
1420e93f7393Sniklas
1421e93f7393Sniklas /* Type is being defined here. */
1422e93f7393Sniklas /* Skip the '='.
1423e93f7393Sniklas Also skip the type descriptor - we get it below with (*pp)[-1]. */
1424e93f7393Sniklas (*pp) += 2;
1425e93f7393Sniklas }
1426e93f7393Sniklas else
1427e93f7393Sniklas {
1428e93f7393Sniklas /* 'typenums=' not present, type is anonymous. Read and return
1429e93f7393Sniklas the definition, but don't put it in the type vector. */
1430e93f7393Sniklas typenums[0] = typenums[1] = -1;
1431e93f7393Sniklas (*pp)++;
1432e93f7393Sniklas }
1433e93f7393Sniklas
1434e93f7393Sniklas again:
1435e93f7393Sniklas type_descriptor = (*pp)[-1];
1436e93f7393Sniklas switch (type_descriptor)
1437e93f7393Sniklas {
1438e93f7393Sniklas case 'x':
1439e93f7393Sniklas {
1440e93f7393Sniklas enum type_code code;
1441e93f7393Sniklas
1442e93f7393Sniklas /* Used to index through file_symbols. */
1443e93f7393Sniklas struct pending *ppt;
1444e93f7393Sniklas int i;
1445e93f7393Sniklas
1446e93f7393Sniklas /* Name including "struct", etc. */
1447e93f7393Sniklas char *type_name;
1448e93f7393Sniklas
1449e93f7393Sniklas {
1450e93f7393Sniklas char *from, *to, *p, *q1, *q2;
1451e93f7393Sniklas
1452e93f7393Sniklas /* Set the type code according to the following letter. */
1453e93f7393Sniklas switch ((*pp)[0])
1454e93f7393Sniklas {
1455e93f7393Sniklas case 's':
1456e93f7393Sniklas code = TYPE_CODE_STRUCT;
1457e93f7393Sniklas break;
1458e93f7393Sniklas case 'u':
1459e93f7393Sniklas code = TYPE_CODE_UNION;
1460e93f7393Sniklas break;
1461e93f7393Sniklas case 'e':
1462e93f7393Sniklas code = TYPE_CODE_ENUM;
1463e93f7393Sniklas break;
1464e93f7393Sniklas default:
1465e93f7393Sniklas {
1466e93f7393Sniklas /* Complain and keep going, so compilers can invent new
1467e93f7393Sniklas cross-reference types. */
1468b725ae77Skettenis complaint (&symfile_complaints,
1469b725ae77Skettenis "Unrecognized cross-reference type `%c'", (*pp)[0]);
1470e93f7393Sniklas code = TYPE_CODE_STRUCT;
1471e93f7393Sniklas break;
1472e93f7393Sniklas }
1473e93f7393Sniklas }
1474e93f7393Sniklas
1475e93f7393Sniklas q1 = strchr (*pp, '<');
1476e93f7393Sniklas p = strchr (*pp, ':');
1477e93f7393Sniklas if (p == NULL)
1478e93f7393Sniklas return error_type (pp, objfile);
1479b725ae77Skettenis if (q1 && p > q1 && p[1] == ':')
1480e93f7393Sniklas {
1481b725ae77Skettenis int nesting_level = 0;
1482b725ae77Skettenis for (q2 = q1; *q2; q2++)
1483b725ae77Skettenis {
1484b725ae77Skettenis if (*q2 == '<')
1485b725ae77Skettenis nesting_level++;
1486b725ae77Skettenis else if (*q2 == '>')
1487b725ae77Skettenis nesting_level--;
1488b725ae77Skettenis else if (*q2 == ':' && nesting_level == 0)
1489e93f7393Sniklas break;
1490b725ae77Skettenis }
1491b725ae77Skettenis p = q2;
1492b725ae77Skettenis if (*p != ':')
1493e93f7393Sniklas return error_type (pp, objfile);
1494e93f7393Sniklas }
1495e93f7393Sniklas to = type_name =
1496b725ae77Skettenis (char *) obstack_alloc (&objfile->objfile_obstack, p - *pp + 1);
1497e93f7393Sniklas
1498e93f7393Sniklas /* Copy the name. */
1499e93f7393Sniklas from = *pp + 1;
1500e93f7393Sniklas while (from < p)
1501e93f7393Sniklas *to++ = *from++;
1502e93f7393Sniklas *to = '\0';
1503e93f7393Sniklas
1504e93f7393Sniklas /* Set the pointer ahead of the name which we just read, and
1505e93f7393Sniklas the colon. */
1506e93f7393Sniklas *pp = from + 1;
1507e93f7393Sniklas }
1508e93f7393Sniklas
1509b725ae77Skettenis /* If this type has already been declared, then reuse the same
1510b725ae77Skettenis type, rather than allocating a new one. This saves some
1511b725ae77Skettenis memory. */
1512e93f7393Sniklas
1513e93f7393Sniklas for (ppt = file_symbols; ppt; ppt = ppt->next)
1514e93f7393Sniklas for (i = 0; i < ppt->nsyms; i++)
1515e93f7393Sniklas {
1516e93f7393Sniklas struct symbol *sym = ppt->symbol[i];
1517e93f7393Sniklas
1518e93f7393Sniklas if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1519b725ae77Skettenis && SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN
1520e93f7393Sniklas && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
1521b725ae77Skettenis && strcmp (DEPRECATED_SYMBOL_NAME (sym), type_name) == 0)
1522e93f7393Sniklas {
1523b725ae77Skettenis obstack_free (&objfile->objfile_obstack, type_name);
1524e93f7393Sniklas type = SYMBOL_TYPE (sym);
1525b725ae77Skettenis if (typenums[0] != -1)
1526b725ae77Skettenis *dbx_lookup_type (typenums) = type;
1527e93f7393Sniklas return type;
1528e93f7393Sniklas }
1529e93f7393Sniklas }
1530e93f7393Sniklas
1531e93f7393Sniklas /* Didn't find the type to which this refers, so we must
1532e93f7393Sniklas be dealing with a forward reference. Allocate a type
1533e93f7393Sniklas structure for it, and keep track of it so we can
1534e93f7393Sniklas fill in the rest of the fields when we get the full
1535e93f7393Sniklas type. */
1536e93f7393Sniklas type = dbx_alloc_type (typenums, objfile);
1537e93f7393Sniklas TYPE_CODE (type) = code;
1538e93f7393Sniklas TYPE_TAG_NAME (type) = type_name;
1539e93f7393Sniklas INIT_CPLUS_SPECIFIC (type);
1540e93f7393Sniklas TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
1541e93f7393Sniklas
1542e93f7393Sniklas add_undefined_type (type);
1543e93f7393Sniklas return type;
1544e93f7393Sniklas }
1545e93f7393Sniklas
1546e93f7393Sniklas case '-': /* RS/6000 built-in type */
1547e93f7393Sniklas case '0':
1548e93f7393Sniklas case '1':
1549e93f7393Sniklas case '2':
1550e93f7393Sniklas case '3':
1551e93f7393Sniklas case '4':
1552e93f7393Sniklas case '5':
1553e93f7393Sniklas case '6':
1554e93f7393Sniklas case '7':
1555e93f7393Sniklas case '8':
1556e93f7393Sniklas case '9':
1557e93f7393Sniklas case '(':
1558e93f7393Sniklas (*pp)--;
1559e93f7393Sniklas
1560e93f7393Sniklas /* We deal with something like t(1,2)=(3,4)=... which
1561e93f7393Sniklas the Lucid compiler and recent gcc versions (post 2.7.3) use. */
1562e93f7393Sniklas
1563e93f7393Sniklas /* Allocate and enter the typedef type first.
1564e93f7393Sniklas This handles recursive types. */
1565e93f7393Sniklas type = dbx_alloc_type (typenums, objfile);
1566e93f7393Sniklas TYPE_CODE (type) = TYPE_CODE_TYPEDEF;
1567b725ae77Skettenis {
1568b725ae77Skettenis struct type *xtype = read_type (pp, objfile);
1569e93f7393Sniklas if (type == xtype)
1570e93f7393Sniklas {
1571e93f7393Sniklas /* It's being defined as itself. That means it is "void". */
1572e93f7393Sniklas TYPE_CODE (type) = TYPE_CODE_VOID;
1573e93f7393Sniklas TYPE_LENGTH (type) = 1;
1574e93f7393Sniklas }
1575e93f7393Sniklas else if (type_size >= 0 || is_string)
1576e93f7393Sniklas {
1577b725ae77Skettenis /* This is the absolute wrong way to construct types. Every
1578b725ae77Skettenis other debug format has found a way around this problem and
1579b725ae77Skettenis the related problems with unnecessarily stubbed types;
1580b725ae77Skettenis someone motivated should attempt to clean up the issue
1581b725ae77Skettenis here as well. Once a type pointed to has been created it
1582b725ae77Skettenis should not be modified.
1583b725ae77Skettenis
1584b725ae77Skettenis Well, it's not *absolutely* wrong. Constructing recursive
1585b725ae77Skettenis types (trees, linked lists) necessarily entails modifying
1586b725ae77Skettenis types after creating them. Constructing any loop structure
1587b725ae77Skettenis entails side effects. The Dwarf 2 reader does handle this
1588b725ae77Skettenis more gracefully (it never constructs more than once
1589b725ae77Skettenis instance of a type object, so it doesn't have to copy type
1590b725ae77Skettenis objects wholesale), but it still mutates type objects after
1591b725ae77Skettenis other folks have references to them.
1592b725ae77Skettenis
1593b725ae77Skettenis Keep in mind that this circularity/mutation issue shows up
1594b725ae77Skettenis at the source language level, too: C's "incomplete types",
1595b725ae77Skettenis for example. So the proper cleanup, I think, would be to
1596b725ae77Skettenis limit GDB's type smashing to match exactly those required
1597b725ae77Skettenis by the source language. So GDB could have a
1598b725ae77Skettenis "complete_this_type" function, but never create unnecessary
1599b725ae77Skettenis copies of a type otherwise. */
1600b725ae77Skettenis replace_type (type, xtype);
1601e93f7393Sniklas TYPE_NAME (type) = NULL;
1602e93f7393Sniklas TYPE_TAG_NAME (type) = NULL;
1603e93f7393Sniklas }
1604e93f7393Sniklas else
1605e93f7393Sniklas {
1606e93f7393Sniklas TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB;
1607e93f7393Sniklas TYPE_TARGET_TYPE (type) = xtype;
1608e93f7393Sniklas }
1609e93f7393Sniklas }
1610e93f7393Sniklas break;
1611e93f7393Sniklas
1612e93f7393Sniklas /* In the following types, we must be sure to overwrite any existing
1613e93f7393Sniklas type that the typenums refer to, rather than allocating a new one
1614e93f7393Sniklas and making the typenums point to the new one. This is because there
1615e93f7393Sniklas may already be pointers to the existing type (if it had been
1616e93f7393Sniklas forward-referenced), and we must change it to a pointer, function,
1617e93f7393Sniklas reference, or whatever, *in-place*. */
1618e93f7393Sniklas
1619b725ae77Skettenis case '*': /* Pointer to another type */
1620e93f7393Sniklas type1 = read_type (pp, objfile);
1621e93f7393Sniklas type = make_pointer_type (type1, dbx_lookup_type (typenums));
1622e93f7393Sniklas break;
1623e93f7393Sniklas
1624e93f7393Sniklas case '&': /* Reference to another type */
1625e93f7393Sniklas type1 = read_type (pp, objfile);
1626e93f7393Sniklas type = make_reference_type (type1, dbx_lookup_type (typenums));
1627e93f7393Sniklas break;
1628e93f7393Sniklas
1629e93f7393Sniklas case 'f': /* Function returning another type */
1630e93f7393Sniklas type1 = read_type (pp, objfile);
1631e93f7393Sniklas type = make_function_type (type1, dbx_lookup_type (typenums));
1632e93f7393Sniklas break;
1633e93f7393Sniklas
1634b725ae77Skettenis case 'g': /* Prototyped function. (Sun) */
1635b725ae77Skettenis {
1636b725ae77Skettenis /* Unresolved questions:
1637b725ae77Skettenis
1638b725ae77Skettenis - According to Sun's ``STABS Interface Manual'', for 'f'
1639b725ae77Skettenis and 'F' symbol descriptors, a `0' in the argument type list
1640b725ae77Skettenis indicates a varargs function. But it doesn't say how 'g'
1641b725ae77Skettenis type descriptors represent that info. Someone with access
1642b725ae77Skettenis to Sun's toolchain should try it out.
1643b725ae77Skettenis
1644b725ae77Skettenis - According to the comment in define_symbol (search for
1645b725ae77Skettenis `process_prototype_types:'), Sun emits integer arguments as
1646b725ae77Skettenis types which ref themselves --- like `void' types. Do we
1647b725ae77Skettenis have to deal with that here, too? Again, someone with
1648b725ae77Skettenis access to Sun's toolchain should try it out and let us
1649b725ae77Skettenis know. */
1650b725ae77Skettenis
1651b725ae77Skettenis const char *type_start = (*pp) - 1;
1652b725ae77Skettenis struct type *return_type = read_type (pp, objfile);
1653b725ae77Skettenis struct type *func_type
1654b725ae77Skettenis = make_function_type (return_type, dbx_lookup_type (typenums));
1655b725ae77Skettenis struct type_list {
1656b725ae77Skettenis struct type *type;
1657b725ae77Skettenis struct type_list *next;
1658b725ae77Skettenis } *arg_types = 0;
1659b725ae77Skettenis int num_args = 0;
1660b725ae77Skettenis
1661b725ae77Skettenis while (**pp && **pp != '#')
1662b725ae77Skettenis {
1663b725ae77Skettenis struct type *arg_type = read_type (pp, objfile);
1664b725ae77Skettenis struct type_list *new = alloca (sizeof (*new));
1665b725ae77Skettenis new->type = arg_type;
1666b725ae77Skettenis new->next = arg_types;
1667b725ae77Skettenis arg_types = new;
1668b725ae77Skettenis num_args++;
1669b725ae77Skettenis }
1670b725ae77Skettenis if (**pp == '#')
1671b725ae77Skettenis ++*pp;
1672b725ae77Skettenis else
1673b725ae77Skettenis {
1674b725ae77Skettenis complaint (&symfile_complaints,
1675b725ae77Skettenis "Prototyped function type didn't end arguments with `#':\n%s",
1676b725ae77Skettenis type_start);
1677b725ae77Skettenis }
1678b725ae77Skettenis
1679b725ae77Skettenis /* If there is just one argument whose type is `void', then
1680b725ae77Skettenis that's just an empty argument list. */
1681b725ae77Skettenis if (arg_types
1682b725ae77Skettenis && ! arg_types->next
1683b725ae77Skettenis && TYPE_CODE (arg_types->type) == TYPE_CODE_VOID)
1684b725ae77Skettenis num_args = 0;
1685b725ae77Skettenis
1686b725ae77Skettenis TYPE_FIELDS (func_type)
1687b725ae77Skettenis = (struct field *) TYPE_ALLOC (func_type,
1688b725ae77Skettenis num_args * sizeof (struct field));
1689b725ae77Skettenis memset (TYPE_FIELDS (func_type), 0, num_args * sizeof (struct field));
1690b725ae77Skettenis {
1691b725ae77Skettenis int i;
1692b725ae77Skettenis struct type_list *t;
1693b725ae77Skettenis
1694b725ae77Skettenis /* We stuck each argument type onto the front of the list
1695b725ae77Skettenis when we read it, so the list is reversed. Build the
1696b725ae77Skettenis fields array right-to-left. */
1697b725ae77Skettenis for (t = arg_types, i = num_args - 1; t; t = t->next, i--)
1698b725ae77Skettenis TYPE_FIELD_TYPE (func_type, i) = t->type;
1699b725ae77Skettenis }
1700b725ae77Skettenis TYPE_NFIELDS (func_type) = num_args;
1701b725ae77Skettenis TYPE_FLAGS (func_type) |= TYPE_FLAG_PROTOTYPED;
1702b725ae77Skettenis
1703b725ae77Skettenis type = func_type;
1704b725ae77Skettenis break;
1705b725ae77Skettenis }
1706b725ae77Skettenis
1707e93f7393Sniklas case 'k': /* Const qualifier on some type (Sun) */
1708e93f7393Sniklas type = read_type (pp, objfile);
1709b725ae77Skettenis type = make_cv_type (1, TYPE_VOLATILE (type), type,
1710b725ae77Skettenis dbx_lookup_type (typenums));
1711e93f7393Sniklas break;
1712e93f7393Sniklas
1713e93f7393Sniklas case 'B': /* Volatile qual on some type (Sun) */
1714e93f7393Sniklas type = read_type (pp, objfile);
1715b725ae77Skettenis type = make_cv_type (TYPE_CONST (type), 1, type,
1716b725ae77Skettenis dbx_lookup_type (typenums));
1717e93f7393Sniklas break;
1718e93f7393Sniklas
1719e93f7393Sniklas case '@':
1720e93f7393Sniklas if (isdigit (**pp) || **pp == '(' || **pp == '-')
1721e93f7393Sniklas { /* Member (class & variable) type */
1722e93f7393Sniklas /* FIXME -- we should be doing smash_to_XXX types here. */
1723e93f7393Sniklas
1724e93f7393Sniklas struct type *domain = read_type (pp, objfile);
1725e93f7393Sniklas struct type *memtype;
1726e93f7393Sniklas
1727e93f7393Sniklas if (**pp != ',')
1728e93f7393Sniklas /* Invalid member type data format. */
1729e93f7393Sniklas return error_type (pp, objfile);
1730e93f7393Sniklas ++*pp;
1731e93f7393Sniklas
1732e93f7393Sniklas memtype = read_type (pp, objfile);
1733e93f7393Sniklas type = dbx_alloc_type (typenums, objfile);
1734e93f7393Sniklas smash_to_member_type (type, domain, memtype);
1735e93f7393Sniklas }
1736b725ae77Skettenis else
1737b725ae77Skettenis /* type attribute */
1738e93f7393Sniklas {
1739e93f7393Sniklas char *attr = *pp;
1740e93f7393Sniklas /* Skip to the semicolon. */
1741e93f7393Sniklas while (**pp != ';' && **pp != '\0')
1742e93f7393Sniklas ++(*pp);
1743e93f7393Sniklas if (**pp == '\0')
1744e93f7393Sniklas return error_type (pp, objfile);
1745e93f7393Sniklas else
1746e93f7393Sniklas ++ * pp; /* Skip the semicolon. */
1747e93f7393Sniklas
1748e93f7393Sniklas switch (*attr)
1749e93f7393Sniklas {
1750b725ae77Skettenis case 's': /* Size attribute */
1751e93f7393Sniklas type_size = atoi (attr + 1);
1752e93f7393Sniklas if (type_size <= 0)
1753e93f7393Sniklas type_size = -1;
1754e93f7393Sniklas break;
1755e93f7393Sniklas
1756b725ae77Skettenis case 'S': /* String attribute */
1757b725ae77Skettenis /* FIXME: check to see if following type is array? */
1758e93f7393Sniklas is_string = 1;
1759e93f7393Sniklas break;
1760e93f7393Sniklas
1761b725ae77Skettenis case 'V': /* Vector attribute */
1762b725ae77Skettenis /* FIXME: check to see if following type is array? */
1763b725ae77Skettenis is_vector = 1;
1764b725ae77Skettenis break;
1765b725ae77Skettenis
1766e93f7393Sniklas default:
1767e93f7393Sniklas /* Ignore unrecognized type attributes, so future compilers
1768e93f7393Sniklas can invent new ones. */
1769e93f7393Sniklas break;
1770e93f7393Sniklas }
1771e93f7393Sniklas ++*pp;
1772e93f7393Sniklas goto again;
1773e93f7393Sniklas }
1774e93f7393Sniklas break;
1775e93f7393Sniklas
1776e93f7393Sniklas case '#': /* Method (class & fn) type */
1777e93f7393Sniklas if ((*pp)[0] == '#')
1778e93f7393Sniklas {
1779e93f7393Sniklas /* We'll get the parameter types from the name. */
1780e93f7393Sniklas struct type *return_type;
1781e93f7393Sniklas
1782e93f7393Sniklas (*pp)++;
1783e93f7393Sniklas return_type = read_type (pp, objfile);
1784e93f7393Sniklas if (*(*pp)++ != ';')
1785b725ae77Skettenis complaint (&symfile_complaints,
1786b725ae77Skettenis "invalid (minimal) member type data format at symtab pos %d.",
1787b725ae77Skettenis symnum);
1788e93f7393Sniklas type = allocate_stub_method (return_type);
1789e93f7393Sniklas if (typenums[0] != -1)
1790e93f7393Sniklas *dbx_lookup_type (typenums) = type;
1791e93f7393Sniklas }
1792e93f7393Sniklas else
1793e93f7393Sniklas {
1794e93f7393Sniklas struct type *domain = read_type (pp, objfile);
1795e93f7393Sniklas struct type *return_type;
1796b725ae77Skettenis struct field *args;
1797b725ae77Skettenis int nargs, varargs;
1798e93f7393Sniklas
1799e93f7393Sniklas if (**pp != ',')
1800e93f7393Sniklas /* Invalid member type data format. */
1801e93f7393Sniklas return error_type (pp, objfile);
1802e93f7393Sniklas else
1803e93f7393Sniklas ++(*pp);
1804e93f7393Sniklas
1805e93f7393Sniklas return_type = read_type (pp, objfile);
1806b725ae77Skettenis args = read_args (pp, ';', objfile, &nargs, &varargs);
1807e93f7393Sniklas type = dbx_alloc_type (typenums, objfile);
1808b725ae77Skettenis smash_to_method_type (type, domain, return_type, args,
1809b725ae77Skettenis nargs, varargs);
1810e93f7393Sniklas }
1811e93f7393Sniklas break;
1812e93f7393Sniklas
1813e93f7393Sniklas case 'r': /* Range type */
1814e93f7393Sniklas type = read_range_type (pp, typenums, objfile);
1815e93f7393Sniklas if (typenums[0] != -1)
1816e93f7393Sniklas *dbx_lookup_type (typenums) = type;
1817e93f7393Sniklas break;
1818e93f7393Sniklas
1819e93f7393Sniklas case 'b':
1820e93f7393Sniklas {
1821e93f7393Sniklas /* Sun ACC builtin int type */
1822e93f7393Sniklas type = read_sun_builtin_type (pp, typenums, objfile);
1823e93f7393Sniklas if (typenums[0] != -1)
1824e93f7393Sniklas *dbx_lookup_type (typenums) = type;
1825e93f7393Sniklas }
1826e93f7393Sniklas break;
1827e93f7393Sniklas
1828e93f7393Sniklas case 'R': /* Sun ACC builtin float type */
1829e93f7393Sniklas type = read_sun_floating_type (pp, typenums, objfile);
1830e93f7393Sniklas if (typenums[0] != -1)
1831e93f7393Sniklas *dbx_lookup_type (typenums) = type;
1832e93f7393Sniklas break;
1833e93f7393Sniklas
1834e93f7393Sniklas case 'e': /* Enumeration type */
1835e93f7393Sniklas type = dbx_alloc_type (typenums, objfile);
1836e93f7393Sniklas type = read_enum_type (pp, type, objfile);
1837e93f7393Sniklas if (typenums[0] != -1)
1838e93f7393Sniklas *dbx_lookup_type (typenums) = type;
1839e93f7393Sniklas break;
1840e93f7393Sniklas
1841e93f7393Sniklas case 's': /* Struct type */
1842e93f7393Sniklas case 'u': /* Union type */
1843b725ae77Skettenis {
1844b725ae77Skettenis enum type_code type_code = TYPE_CODE_UNDEF;
1845e93f7393Sniklas type = dbx_alloc_type (typenums, objfile);
1846e93f7393Sniklas switch (type_descriptor)
1847e93f7393Sniklas {
1848e93f7393Sniklas case 's':
1849b725ae77Skettenis type_code = TYPE_CODE_STRUCT;
1850e93f7393Sniklas break;
1851e93f7393Sniklas case 'u':
1852b725ae77Skettenis type_code = TYPE_CODE_UNION;
1853e93f7393Sniklas break;
1854e93f7393Sniklas }
1855b725ae77Skettenis type = read_struct_type (pp, type, type_code, objfile);
1856e93f7393Sniklas break;
1857b725ae77Skettenis }
1858e93f7393Sniklas
1859e93f7393Sniklas case 'a': /* Array type */
1860e93f7393Sniklas if (**pp != 'r')
1861e93f7393Sniklas return error_type (pp, objfile);
1862e93f7393Sniklas ++*pp;
1863e93f7393Sniklas
1864e93f7393Sniklas type = dbx_alloc_type (typenums, objfile);
1865e93f7393Sniklas type = read_array_type (pp, type, objfile);
1866e93f7393Sniklas if (is_string)
1867e93f7393Sniklas TYPE_CODE (type) = TYPE_CODE_STRING;
1868b725ae77Skettenis if (is_vector)
1869b725ae77Skettenis TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR;
1870e93f7393Sniklas break;
1871e93f7393Sniklas
1872b725ae77Skettenis case 'S': /* Set or bitstring type */
1873e93f7393Sniklas type1 = read_type (pp, objfile);
1874e93f7393Sniklas type = create_set_type ((struct type *) NULL, type1);
1875e93f7393Sniklas if (is_string)
1876e93f7393Sniklas TYPE_CODE (type) = TYPE_CODE_BITSTRING;
1877e93f7393Sniklas if (typenums[0] != -1)
1878e93f7393Sniklas *dbx_lookup_type (typenums) = type;
1879e93f7393Sniklas break;
1880e93f7393Sniklas
1881e93f7393Sniklas default:
1882e93f7393Sniklas --*pp; /* Go back to the symbol in error */
1883e93f7393Sniklas /* Particularly important if it was \0! */
1884e93f7393Sniklas return error_type (pp, objfile);
1885e93f7393Sniklas }
1886e93f7393Sniklas
1887e93f7393Sniklas if (type == 0)
1888e93f7393Sniklas {
1889e93f7393Sniklas warning ("GDB internal error, type is NULL in stabsread.c\n");
1890e93f7393Sniklas return error_type (pp, objfile);
1891e93f7393Sniklas }
1892e93f7393Sniklas
1893e93f7393Sniklas /* Size specified in a type attribute overrides any other size. */
1894e93f7393Sniklas if (type_size != -1)
1895e93f7393Sniklas TYPE_LENGTH (type) = (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
1896e93f7393Sniklas
1897e93f7393Sniklas return type;
1898e93f7393Sniklas }
1899e93f7393Sniklas
1900e93f7393Sniklas /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
1901e93f7393Sniklas Return the proper type node for a given builtin type number. */
1902e93f7393Sniklas
1903e93f7393Sniklas static struct type *
rs6000_builtin_type(int typenum)1904b725ae77Skettenis rs6000_builtin_type (int typenum)
1905e93f7393Sniklas {
1906e93f7393Sniklas /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
1907e93f7393Sniklas #define NUMBER_RECOGNIZED 34
1908e93f7393Sniklas /* This includes an empty slot for type number -0. */
1909e93f7393Sniklas static struct type *negative_types[NUMBER_RECOGNIZED + 1];
1910e93f7393Sniklas struct type *rettype = NULL;
1911e93f7393Sniklas
1912e93f7393Sniklas if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED)
1913e93f7393Sniklas {
1914b725ae77Skettenis complaint (&symfile_complaints, "Unknown builtin type %d", typenum);
1915e93f7393Sniklas return builtin_type_error;
1916e93f7393Sniklas }
1917e93f7393Sniklas if (negative_types[-typenum] != NULL)
1918e93f7393Sniklas return negative_types[-typenum];
1919e93f7393Sniklas
1920e93f7393Sniklas #if TARGET_CHAR_BIT != 8
1921e93f7393Sniklas #error This code wrong for TARGET_CHAR_BIT not 8
1922e93f7393Sniklas /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
1923e93f7393Sniklas that if that ever becomes not true, the correct fix will be to
1924e93f7393Sniklas make the size in the struct type to be in bits, not in units of
1925e93f7393Sniklas TARGET_CHAR_BIT. */
1926e93f7393Sniklas #endif
1927e93f7393Sniklas
1928e93f7393Sniklas switch (-typenum)
1929e93f7393Sniklas {
1930e93f7393Sniklas case 1:
1931e93f7393Sniklas /* The size of this and all the other types are fixed, defined
1932e93f7393Sniklas by the debugging format. If there is a type called "int" which
1933e93f7393Sniklas is other than 32 bits, then it should use a new negative type
1934e93f7393Sniklas number (or avoid negative type numbers for that case).
1935e93f7393Sniklas See stabs.texinfo. */
1936e93f7393Sniklas rettype = init_type (TYPE_CODE_INT, 4, 0, "int", NULL);
1937e93f7393Sniklas break;
1938e93f7393Sniklas case 2:
1939e93f7393Sniklas rettype = init_type (TYPE_CODE_INT, 1, 0, "char", NULL);
1940e93f7393Sniklas break;
1941e93f7393Sniklas case 3:
1942e93f7393Sniklas rettype = init_type (TYPE_CODE_INT, 2, 0, "short", NULL);
1943e93f7393Sniklas break;
1944e93f7393Sniklas case 4:
1945e93f7393Sniklas rettype = init_type (TYPE_CODE_INT, 4, 0, "long", NULL);
1946e93f7393Sniklas break;
1947e93f7393Sniklas case 5:
1948e93f7393Sniklas rettype = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED,
1949e93f7393Sniklas "unsigned char", NULL);
1950e93f7393Sniklas break;
1951e93f7393Sniklas case 6:
1952e93f7393Sniklas rettype = init_type (TYPE_CODE_INT, 1, 0, "signed char", NULL);
1953e93f7393Sniklas break;
1954e93f7393Sniklas case 7:
1955e93f7393Sniklas rettype = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED,
1956e93f7393Sniklas "unsigned short", NULL);
1957e93f7393Sniklas break;
1958e93f7393Sniklas case 8:
1959e93f7393Sniklas rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
1960e93f7393Sniklas "unsigned int", NULL);
1961e93f7393Sniklas break;
1962e93f7393Sniklas case 9:
1963e93f7393Sniklas rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
1964e93f7393Sniklas "unsigned", NULL);
1965e93f7393Sniklas case 10:
1966e93f7393Sniklas rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
1967e93f7393Sniklas "unsigned long", NULL);
1968e93f7393Sniklas break;
1969e93f7393Sniklas case 11:
1970e93f7393Sniklas rettype = init_type (TYPE_CODE_VOID, 1, 0, "void", NULL);
1971e93f7393Sniklas break;
1972e93f7393Sniklas case 12:
1973e93f7393Sniklas /* IEEE single precision (32 bit). */
1974e93f7393Sniklas rettype = init_type (TYPE_CODE_FLT, 4, 0, "float", NULL);
1975e93f7393Sniklas break;
1976e93f7393Sniklas case 13:
1977e93f7393Sniklas /* IEEE double precision (64 bit). */
1978e93f7393Sniklas rettype = init_type (TYPE_CODE_FLT, 8, 0, "double", NULL);
1979e93f7393Sniklas break;
1980e93f7393Sniklas case 14:
1981e93f7393Sniklas /* This is an IEEE double on the RS/6000, and different machines with
1982e93f7393Sniklas different sizes for "long double" should use different negative
1983e93f7393Sniklas type numbers. See stabs.texinfo. */
1984e93f7393Sniklas rettype = init_type (TYPE_CODE_FLT, 8, 0, "long double", NULL);
1985e93f7393Sniklas break;
1986e93f7393Sniklas case 15:
1987e93f7393Sniklas rettype = init_type (TYPE_CODE_INT, 4, 0, "integer", NULL);
1988e93f7393Sniklas break;
1989e93f7393Sniklas case 16:
1990e93f7393Sniklas rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
1991e93f7393Sniklas "boolean", NULL);
1992e93f7393Sniklas break;
1993e93f7393Sniklas case 17:
1994e93f7393Sniklas rettype = init_type (TYPE_CODE_FLT, 4, 0, "short real", NULL);
1995e93f7393Sniklas break;
1996e93f7393Sniklas case 18:
1997e93f7393Sniklas rettype = init_type (TYPE_CODE_FLT, 8, 0, "real", NULL);
1998e93f7393Sniklas break;
1999e93f7393Sniklas case 19:
2000e93f7393Sniklas rettype = init_type (TYPE_CODE_ERROR, 0, 0, "stringptr", NULL);
2001e93f7393Sniklas break;
2002e93f7393Sniklas case 20:
2003e93f7393Sniklas rettype = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED,
2004e93f7393Sniklas "character", NULL);
2005e93f7393Sniklas break;
2006e93f7393Sniklas case 21:
2007e93f7393Sniklas rettype = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED,
2008e93f7393Sniklas "logical*1", NULL);
2009e93f7393Sniklas break;
2010e93f7393Sniklas case 22:
2011e93f7393Sniklas rettype = init_type (TYPE_CODE_BOOL, 2, TYPE_FLAG_UNSIGNED,
2012e93f7393Sniklas "logical*2", NULL);
2013e93f7393Sniklas break;
2014e93f7393Sniklas case 23:
2015e93f7393Sniklas rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
2016e93f7393Sniklas "logical*4", NULL);
2017e93f7393Sniklas break;
2018e93f7393Sniklas case 24:
2019e93f7393Sniklas rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
2020e93f7393Sniklas "logical", NULL);
2021e93f7393Sniklas break;
2022e93f7393Sniklas case 25:
2023e93f7393Sniklas /* Complex type consisting of two IEEE single precision values. */
2024b725ae77Skettenis rettype = init_type (TYPE_CODE_COMPLEX, 8, 0, "complex", NULL);
2025b725ae77Skettenis TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 4, 0, "float",
2026b725ae77Skettenis NULL);
2027e93f7393Sniklas break;
2028e93f7393Sniklas case 26:
2029e93f7393Sniklas /* Complex type consisting of two IEEE double precision values. */
2030b725ae77Skettenis rettype = init_type (TYPE_CODE_COMPLEX, 16, 0, "double complex", NULL);
2031b725ae77Skettenis TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 8, 0, "double",
2032b725ae77Skettenis NULL);
2033e93f7393Sniklas break;
2034e93f7393Sniklas case 27:
2035e93f7393Sniklas rettype = init_type (TYPE_CODE_INT, 1, 0, "integer*1", NULL);
2036e93f7393Sniklas break;
2037e93f7393Sniklas case 28:
2038e93f7393Sniklas rettype = init_type (TYPE_CODE_INT, 2, 0, "integer*2", NULL);
2039e93f7393Sniklas break;
2040e93f7393Sniklas case 29:
2041e93f7393Sniklas rettype = init_type (TYPE_CODE_INT, 4, 0, "integer*4", NULL);
2042e93f7393Sniklas break;
2043e93f7393Sniklas case 30:
2044e93f7393Sniklas rettype = init_type (TYPE_CODE_CHAR, 2, 0, "wchar", NULL);
2045e93f7393Sniklas break;
2046e93f7393Sniklas case 31:
2047e93f7393Sniklas rettype = init_type (TYPE_CODE_INT, 8, 0, "long long", NULL);
2048e93f7393Sniklas break;
2049e93f7393Sniklas case 32:
2050e93f7393Sniklas rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
2051e93f7393Sniklas "unsigned long long", NULL);
2052e93f7393Sniklas break;
2053e93f7393Sniklas case 33:
2054e93f7393Sniklas rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
2055e93f7393Sniklas "logical*8", NULL);
2056e93f7393Sniklas break;
2057e93f7393Sniklas case 34:
2058e93f7393Sniklas rettype = init_type (TYPE_CODE_INT, 8, 0, "integer*8", NULL);
2059e93f7393Sniklas break;
2060e93f7393Sniklas }
2061e93f7393Sniklas negative_types[-typenum] = rettype;
2062e93f7393Sniklas return rettype;
2063e93f7393Sniklas }
2064e93f7393Sniklas
2065e93f7393Sniklas /* This page contains subroutines of read_type. */
2066e93f7393Sniklas
2067b725ae77Skettenis /* Replace *OLD_NAME with the method name portion of PHYSNAME. */
2068b725ae77Skettenis
2069b725ae77Skettenis static void
update_method_name_from_physname(char ** old_name,char * physname)2070b725ae77Skettenis update_method_name_from_physname (char **old_name, char *physname)
2071b725ae77Skettenis {
2072b725ae77Skettenis char *method_name;
2073b725ae77Skettenis
2074b725ae77Skettenis method_name = method_name_from_physname (physname);
2075b725ae77Skettenis
2076b725ae77Skettenis if (method_name == NULL)
2077b725ae77Skettenis {
2078b725ae77Skettenis complaint (&symfile_complaints,
2079b725ae77Skettenis "Method has bad physname %s\n", physname);
2080b725ae77Skettenis return;
2081b725ae77Skettenis }
2082b725ae77Skettenis
2083b725ae77Skettenis if (strcmp (*old_name, method_name) != 0)
2084b725ae77Skettenis {
2085b725ae77Skettenis xfree (*old_name);
2086b725ae77Skettenis *old_name = method_name;
2087b725ae77Skettenis }
2088b725ae77Skettenis else
2089b725ae77Skettenis xfree (method_name);
2090b725ae77Skettenis }
2091b725ae77Skettenis
2092e93f7393Sniklas /* Read member function stabs info for C++ classes. The form of each member
2093e93f7393Sniklas function data is:
2094e93f7393Sniklas
2095e93f7393Sniklas NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2096e93f7393Sniklas
2097e93f7393Sniklas An example with two member functions is:
2098e93f7393Sniklas
2099e93f7393Sniklas afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2100e93f7393Sniklas
2101e93f7393Sniklas For the case of overloaded operators, the format is op$::*.funcs, where
2102e93f7393Sniklas $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2103e93f7393Sniklas name (such as `+=') and `.' marks the end of the operator name.
2104e93f7393Sniklas
2105e93f7393Sniklas Returns 1 for success, 0 for failure. */
2106e93f7393Sniklas
2107e93f7393Sniklas static int
read_member_functions(struct field_info * fip,char ** pp,struct type * type,struct objfile * objfile)2108b725ae77Skettenis read_member_functions (struct field_info *fip, char **pp, struct type *type,
2109b725ae77Skettenis struct objfile *objfile)
2110e93f7393Sniklas {
2111e93f7393Sniklas int nfn_fields = 0;
2112e93f7393Sniklas int length = 0;
2113e93f7393Sniklas /* Total number of member functions defined in this class. If the class
2114e93f7393Sniklas defines two `f' functions, and one `g' function, then this will have
2115e93f7393Sniklas the value 3. */
2116e93f7393Sniklas int total_length = 0;
2117e93f7393Sniklas int i;
2118e93f7393Sniklas struct next_fnfield
2119e93f7393Sniklas {
2120e93f7393Sniklas struct next_fnfield *next;
2121e93f7393Sniklas struct fn_field fn_field;
2122b725ae77Skettenis }
2123b725ae77Skettenis *sublist;
2124e93f7393Sniklas struct type *look_ahead_type;
2125e93f7393Sniklas struct next_fnfieldlist *new_fnlist;
2126e93f7393Sniklas struct next_fnfield *new_sublist;
2127e93f7393Sniklas char *main_fn_name;
2128b725ae77Skettenis char *p;
2129e93f7393Sniklas
2130e93f7393Sniklas /* Process each list until we find something that is not a member function
2131e93f7393Sniklas or find the end of the functions. */
2132e93f7393Sniklas
2133e93f7393Sniklas while (**pp != ';')
2134e93f7393Sniklas {
2135e93f7393Sniklas /* We should be positioned at the start of the function name.
2136e93f7393Sniklas Scan forward to find the first ':' and if it is not the
2137e93f7393Sniklas first of a "::" delimiter, then this is not a member function. */
2138e93f7393Sniklas p = *pp;
2139e93f7393Sniklas while (*p != ':')
2140e93f7393Sniklas {
2141e93f7393Sniklas p++;
2142e93f7393Sniklas }
2143e93f7393Sniklas if (p[1] != ':')
2144e93f7393Sniklas {
2145e93f7393Sniklas break;
2146e93f7393Sniklas }
2147e93f7393Sniklas
2148e93f7393Sniklas sublist = NULL;
2149e93f7393Sniklas look_ahead_type = NULL;
2150e93f7393Sniklas length = 0;
2151e93f7393Sniklas
2152e93f7393Sniklas new_fnlist = (struct next_fnfieldlist *)
2153e93f7393Sniklas xmalloc (sizeof (struct next_fnfieldlist));
2154b725ae77Skettenis make_cleanup (xfree, new_fnlist);
2155e93f7393Sniklas memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
2156e93f7393Sniklas
2157e93f7393Sniklas if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2]))
2158e93f7393Sniklas {
2159e93f7393Sniklas /* This is a completely wierd case. In order to stuff in the
2160e93f7393Sniklas names that might contain colons (the usual name delimiter),
2161e93f7393Sniklas Mike Tiemann defined a different name format which is
2162e93f7393Sniklas signalled if the identifier is "op$". In that case, the
2163e93f7393Sniklas format is "op$::XXXX." where XXXX is the name. This is
2164e93f7393Sniklas used for names like "+" or "=". YUUUUUUUK! FIXME! */
2165e93f7393Sniklas /* This lets the user type "break operator+".
2166e93f7393Sniklas We could just put in "+" as the name, but that wouldn't
2167e93f7393Sniklas work for "*". */
2168b725ae77Skettenis static char opname[32] = "op$";
2169e93f7393Sniklas char *o = opname + 3;
2170e93f7393Sniklas
2171e93f7393Sniklas /* Skip past '::'. */
2172e93f7393Sniklas *pp = p + 2;
2173e93f7393Sniklas
2174e93f7393Sniklas STABS_CONTINUE (pp, objfile);
2175e93f7393Sniklas p = *pp;
2176e93f7393Sniklas while (*p != '.')
2177e93f7393Sniklas {
2178e93f7393Sniklas *o++ = *p++;
2179e93f7393Sniklas }
2180e93f7393Sniklas main_fn_name = savestring (opname, o - opname);
2181e93f7393Sniklas /* Skip past '.' */
2182e93f7393Sniklas *pp = p + 1;
2183e93f7393Sniklas }
2184e93f7393Sniklas else
2185e93f7393Sniklas {
2186e93f7393Sniklas main_fn_name = savestring (*pp, p - *pp);
2187e93f7393Sniklas /* Skip past '::'. */
2188e93f7393Sniklas *pp = p + 2;
2189e93f7393Sniklas }
2190e93f7393Sniklas new_fnlist->fn_fieldlist.name = main_fn_name;
2191e93f7393Sniklas
2192e93f7393Sniklas do
2193e93f7393Sniklas {
2194e93f7393Sniklas new_sublist =
2195e93f7393Sniklas (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
2196b725ae77Skettenis make_cleanup (xfree, new_sublist);
2197e93f7393Sniklas memset (new_sublist, 0, sizeof (struct next_fnfield));
2198e93f7393Sniklas
2199e93f7393Sniklas /* Check for and handle cretinous dbx symbol name continuation! */
2200e93f7393Sniklas if (look_ahead_type == NULL)
2201e93f7393Sniklas {
2202e93f7393Sniklas /* Normal case. */
2203e93f7393Sniklas STABS_CONTINUE (pp, objfile);
2204e93f7393Sniklas
2205e93f7393Sniklas new_sublist->fn_field.type = read_type (pp, objfile);
2206e93f7393Sniklas if (**pp != ':')
2207e93f7393Sniklas {
2208e93f7393Sniklas /* Invalid symtab info for member function. */
2209e93f7393Sniklas return 0;
2210e93f7393Sniklas }
2211e93f7393Sniklas }
2212e93f7393Sniklas else
2213e93f7393Sniklas {
2214e93f7393Sniklas /* g++ version 1 kludge */
2215e93f7393Sniklas new_sublist->fn_field.type = look_ahead_type;
2216e93f7393Sniklas look_ahead_type = NULL;
2217e93f7393Sniklas }
2218e93f7393Sniklas
2219e93f7393Sniklas (*pp)++;
2220e93f7393Sniklas p = *pp;
2221e93f7393Sniklas while (*p != ';')
2222e93f7393Sniklas {
2223e93f7393Sniklas p++;
2224e93f7393Sniklas }
2225e93f7393Sniklas
2226e93f7393Sniklas /* If this is just a stub, then we don't have the real name here. */
2227e93f7393Sniklas
2228b725ae77Skettenis if (TYPE_STUB (new_sublist->fn_field.type))
2229e93f7393Sniklas {
2230e93f7393Sniklas if (!TYPE_DOMAIN_TYPE (new_sublist->fn_field.type))
2231e93f7393Sniklas TYPE_DOMAIN_TYPE (new_sublist->fn_field.type) = type;
2232e93f7393Sniklas new_sublist->fn_field.is_stub = 1;
2233e93f7393Sniklas }
2234e93f7393Sniklas new_sublist->fn_field.physname = savestring (*pp, p - *pp);
2235e93f7393Sniklas *pp = p + 1;
2236e93f7393Sniklas
2237e93f7393Sniklas /* Set this member function's visibility fields. */
2238e93f7393Sniklas switch (*(*pp)++)
2239e93f7393Sniklas {
2240e93f7393Sniklas case VISIBILITY_PRIVATE:
2241e93f7393Sniklas new_sublist->fn_field.is_private = 1;
2242e93f7393Sniklas break;
2243e93f7393Sniklas case VISIBILITY_PROTECTED:
2244e93f7393Sniklas new_sublist->fn_field.is_protected = 1;
2245e93f7393Sniklas break;
2246e93f7393Sniklas }
2247e93f7393Sniklas
2248e93f7393Sniklas STABS_CONTINUE (pp, objfile);
2249e93f7393Sniklas switch (**pp)
2250e93f7393Sniklas {
2251e93f7393Sniklas case 'A': /* Normal functions. */
2252e93f7393Sniklas new_sublist->fn_field.is_const = 0;
2253e93f7393Sniklas new_sublist->fn_field.is_volatile = 0;
2254e93f7393Sniklas (*pp)++;
2255e93f7393Sniklas break;
2256e93f7393Sniklas case 'B': /* `const' member functions. */
2257e93f7393Sniklas new_sublist->fn_field.is_const = 1;
2258e93f7393Sniklas new_sublist->fn_field.is_volatile = 0;
2259e93f7393Sniklas (*pp)++;
2260e93f7393Sniklas break;
2261e93f7393Sniklas case 'C': /* `volatile' member function. */
2262e93f7393Sniklas new_sublist->fn_field.is_const = 0;
2263e93f7393Sniklas new_sublist->fn_field.is_volatile = 1;
2264e93f7393Sniklas (*pp)++;
2265e93f7393Sniklas break;
2266e93f7393Sniklas case 'D': /* `const volatile' member function. */
2267e93f7393Sniklas new_sublist->fn_field.is_const = 1;
2268e93f7393Sniklas new_sublist->fn_field.is_volatile = 1;
2269e93f7393Sniklas (*pp)++;
2270e93f7393Sniklas break;
2271e93f7393Sniklas case '*': /* File compiled with g++ version 1 -- no info */
2272e93f7393Sniklas case '?':
2273e93f7393Sniklas case '.':
2274e93f7393Sniklas break;
2275e93f7393Sniklas default:
2276b725ae77Skettenis complaint (&symfile_complaints,
2277b725ae77Skettenis "const/volatile indicator missing, got '%c'", **pp);
2278e93f7393Sniklas break;
2279e93f7393Sniklas }
2280e93f7393Sniklas
2281e93f7393Sniklas switch (*(*pp)++)
2282e93f7393Sniklas {
2283e93f7393Sniklas case '*':
2284e93f7393Sniklas {
2285e93f7393Sniklas int nbits;
2286e93f7393Sniklas /* virtual member function, followed by index.
2287e93f7393Sniklas The sign bit is set to distinguish pointers-to-methods
2288e93f7393Sniklas from virtual function indicies. Since the array is
2289e93f7393Sniklas in words, the quantity must be shifted left by 1
2290e93f7393Sniklas on 16 bit machine, and by 2 on 32 bit machine, forcing
2291e93f7393Sniklas the sign bit out, and usable as a valid index into
2292e93f7393Sniklas the array. Remove the sign bit here. */
2293e93f7393Sniklas new_sublist->fn_field.voffset =
2294e93f7393Sniklas (0x7fffffff & read_huge_number (pp, ';', &nbits)) + 2;
2295e93f7393Sniklas if (nbits != 0)
2296e93f7393Sniklas return 0;
2297e93f7393Sniklas
2298e93f7393Sniklas STABS_CONTINUE (pp, objfile);
2299e93f7393Sniklas if (**pp == ';' || **pp == '\0')
2300e93f7393Sniklas {
2301e93f7393Sniklas /* Must be g++ version 1. */
2302e93f7393Sniklas new_sublist->fn_field.fcontext = 0;
2303e93f7393Sniklas }
2304e93f7393Sniklas else
2305e93f7393Sniklas {
2306e93f7393Sniklas /* Figure out from whence this virtual function came.
2307e93f7393Sniklas It may belong to virtual function table of
2308e93f7393Sniklas one of its baseclasses. */
2309e93f7393Sniklas look_ahead_type = read_type (pp, objfile);
2310e93f7393Sniklas if (**pp == ':')
2311e93f7393Sniklas {
2312e93f7393Sniklas /* g++ version 1 overloaded methods. */
2313e93f7393Sniklas }
2314e93f7393Sniklas else
2315e93f7393Sniklas {
2316e93f7393Sniklas new_sublist->fn_field.fcontext = look_ahead_type;
2317e93f7393Sniklas if (**pp != ';')
2318e93f7393Sniklas {
2319e93f7393Sniklas return 0;
2320e93f7393Sniklas }
2321e93f7393Sniklas else
2322e93f7393Sniklas {
2323e93f7393Sniklas ++*pp;
2324e93f7393Sniklas }
2325e93f7393Sniklas look_ahead_type = NULL;
2326e93f7393Sniklas }
2327e93f7393Sniklas }
2328e93f7393Sniklas break;
2329e93f7393Sniklas }
2330e93f7393Sniklas case '?':
2331e93f7393Sniklas /* static member function. */
2332b725ae77Skettenis {
2333b725ae77Skettenis int slen = strlen (main_fn_name);
2334b725ae77Skettenis
2335e93f7393Sniklas new_sublist->fn_field.voffset = VOFFSET_STATIC;
2336b725ae77Skettenis
2337b725ae77Skettenis /* For static member functions, we can't tell if they
2338b725ae77Skettenis are stubbed, as they are put out as functions, and not as
2339b725ae77Skettenis methods.
2340b725ae77Skettenis GCC v2 emits the fully mangled name if
2341b725ae77Skettenis dbxout.c:flag_minimal_debug is not set, so we have to
2342b725ae77Skettenis detect a fully mangled physname here and set is_stub
2343b725ae77Skettenis accordingly. Fully mangled physnames in v2 start with
2344b725ae77Skettenis the member function name, followed by two underscores.
2345b725ae77Skettenis GCC v3 currently always emits stubbed member functions,
2346b725ae77Skettenis but with fully mangled physnames, which start with _Z. */
2347b725ae77Skettenis if (!(strncmp (new_sublist->fn_field.physname,
2348b725ae77Skettenis main_fn_name, slen) == 0
2349b725ae77Skettenis && new_sublist->fn_field.physname[slen] == '_'
2350b725ae77Skettenis && new_sublist->fn_field.physname[slen + 1] == '_'))
2351e93f7393Sniklas {
2352e93f7393Sniklas new_sublist->fn_field.is_stub = 1;
2353e93f7393Sniklas }
2354e93f7393Sniklas break;
2355b725ae77Skettenis }
2356e93f7393Sniklas
2357e93f7393Sniklas default:
2358e93f7393Sniklas /* error */
2359b725ae77Skettenis complaint (&symfile_complaints,
2360b725ae77Skettenis "member function type missing, got '%c'", (*pp)[-1]);
2361e93f7393Sniklas /* Fall through into normal member function. */
2362e93f7393Sniklas
2363e93f7393Sniklas case '.':
2364e93f7393Sniklas /* normal member function. */
2365e93f7393Sniklas new_sublist->fn_field.voffset = 0;
2366e93f7393Sniklas new_sublist->fn_field.fcontext = 0;
2367e93f7393Sniklas break;
2368e93f7393Sniklas }
2369e93f7393Sniklas
2370e93f7393Sniklas new_sublist->next = sublist;
2371e93f7393Sniklas sublist = new_sublist;
2372e93f7393Sniklas length++;
2373e93f7393Sniklas STABS_CONTINUE (pp, objfile);
2374e93f7393Sniklas }
2375e93f7393Sniklas while (**pp != ';' && **pp != '\0');
2376e93f7393Sniklas
2377e93f7393Sniklas (*pp)++;
2378b725ae77Skettenis STABS_CONTINUE (pp, objfile);
2379b725ae77Skettenis
2380b725ae77Skettenis /* Skip GCC 3.X member functions which are duplicates of the callable
2381b725ae77Skettenis constructor/destructor. */
2382b725ae77Skettenis if (strcmp (main_fn_name, "__base_ctor") == 0
2383b725ae77Skettenis || strcmp (main_fn_name, "__base_dtor") == 0
2384b725ae77Skettenis || strcmp (main_fn_name, "__deleting_dtor") == 0)
2385b725ae77Skettenis {
2386b725ae77Skettenis xfree (main_fn_name);
2387b725ae77Skettenis }
2388b725ae77Skettenis else
2389b725ae77Skettenis {
2390b725ae77Skettenis int has_stub = 0;
2391b725ae77Skettenis int has_destructor = 0, has_other = 0;
2392b725ae77Skettenis int is_v3 = 0;
2393b725ae77Skettenis struct next_fnfield *tmp_sublist;
2394b725ae77Skettenis
2395b725ae77Skettenis /* Various versions of GCC emit various mostly-useless
2396b725ae77Skettenis strings in the name field for special member functions.
2397b725ae77Skettenis
2398b725ae77Skettenis For stub methods, we need to defer correcting the name
2399b725ae77Skettenis until we are ready to unstub the method, because the current
2400b725ae77Skettenis name string is used by gdb_mangle_name. The only stub methods
2401b725ae77Skettenis of concern here are GNU v2 operators; other methods have their
2402b725ae77Skettenis names correct (see caveat below).
2403b725ae77Skettenis
2404b725ae77Skettenis For non-stub methods, in GNU v3, we have a complete physname.
2405b725ae77Skettenis Therefore we can safely correct the name now. This primarily
2406b725ae77Skettenis affects constructors and destructors, whose name will be
2407b725ae77Skettenis __comp_ctor or __comp_dtor instead of Foo or ~Foo. Cast
2408b725ae77Skettenis operators will also have incorrect names; for instance,
2409b725ae77Skettenis "operator int" will be named "operator i" (i.e. the type is
2410b725ae77Skettenis mangled).
2411b725ae77Skettenis
2412b725ae77Skettenis For non-stub methods in GNU v2, we have no easy way to
2413b725ae77Skettenis know if we have a complete physname or not. For most
2414b725ae77Skettenis methods the result depends on the platform (if CPLUS_MARKER
2415b725ae77Skettenis can be `$' or `.', it will use minimal debug information, or
2416b725ae77Skettenis otherwise the full physname will be included).
2417b725ae77Skettenis
2418b725ae77Skettenis Rather than dealing with this, we take a different approach.
2419b725ae77Skettenis For v3 mangled names, we can use the full physname; for v2,
2420b725ae77Skettenis we use cplus_demangle_opname (which is actually v2 specific),
2421b725ae77Skettenis because the only interesting names are all operators - once again
2422b725ae77Skettenis barring the caveat below. Skip this process if any method in the
2423b725ae77Skettenis group is a stub, to prevent our fouling up the workings of
2424b725ae77Skettenis gdb_mangle_name.
2425b725ae77Skettenis
2426b725ae77Skettenis The caveat: GCC 2.95.x (and earlier?) put constructors and
2427b725ae77Skettenis destructors in the same method group. We need to split this
2428b725ae77Skettenis into two groups, because they should have different names.
2429b725ae77Skettenis So for each method group we check whether it contains both
2430b725ae77Skettenis routines whose physname appears to be a destructor (the physnames
2431b725ae77Skettenis for and destructors are always provided, due to quirks in v2
2432b725ae77Skettenis mangling) and routines whose physname does not appear to be a
2433b725ae77Skettenis destructor. If so then we break up the list into two halves.
2434b725ae77Skettenis Even if the constructors and destructors aren't in the same group
2435b725ae77Skettenis the destructor will still lack the leading tilde, so that also
2436b725ae77Skettenis needs to be fixed.
2437b725ae77Skettenis
2438b725ae77Skettenis So, to summarize what we expect and handle here:
2439b725ae77Skettenis
2440b725ae77Skettenis Given Given Real Real Action
2441b725ae77Skettenis method name physname physname method name
2442b725ae77Skettenis
2443b725ae77Skettenis __opi [none] __opi__3Foo operator int opname
2444b725ae77Skettenis [now or later]
2445b725ae77Skettenis Foo _._3Foo _._3Foo ~Foo separate and
2446b725ae77Skettenis rename
2447b725ae77Skettenis operator i _ZN3FoocviEv _ZN3FoocviEv operator int demangle
2448b725ae77Skettenis __comp_ctor _ZN3FooC1ERKS_ _ZN3FooC1ERKS_ Foo demangle
2449b725ae77Skettenis */
2450b725ae77Skettenis
2451b725ae77Skettenis tmp_sublist = sublist;
2452b725ae77Skettenis while (tmp_sublist != NULL)
2453b725ae77Skettenis {
2454b725ae77Skettenis if (tmp_sublist->fn_field.is_stub)
2455b725ae77Skettenis has_stub = 1;
2456b725ae77Skettenis if (tmp_sublist->fn_field.physname[0] == '_'
2457b725ae77Skettenis && tmp_sublist->fn_field.physname[1] == 'Z')
2458b725ae77Skettenis is_v3 = 1;
2459b725ae77Skettenis
2460b725ae77Skettenis if (is_destructor_name (tmp_sublist->fn_field.physname))
2461b725ae77Skettenis has_destructor++;
2462b725ae77Skettenis else
2463b725ae77Skettenis has_other++;
2464b725ae77Skettenis
2465b725ae77Skettenis tmp_sublist = tmp_sublist->next;
2466b725ae77Skettenis }
2467b725ae77Skettenis
2468b725ae77Skettenis if (has_destructor && has_other)
2469b725ae77Skettenis {
2470b725ae77Skettenis struct next_fnfieldlist *destr_fnlist;
2471b725ae77Skettenis struct next_fnfield *last_sublist;
2472b725ae77Skettenis
2473b725ae77Skettenis /* Create a new fn_fieldlist for the destructors. */
2474b725ae77Skettenis
2475b725ae77Skettenis destr_fnlist = (struct next_fnfieldlist *)
2476b725ae77Skettenis xmalloc (sizeof (struct next_fnfieldlist));
2477b725ae77Skettenis make_cleanup (xfree, destr_fnlist);
2478b725ae77Skettenis memset (destr_fnlist, 0, sizeof (struct next_fnfieldlist));
2479b725ae77Skettenis destr_fnlist->fn_fieldlist.name
2480b725ae77Skettenis = obconcat (&objfile->objfile_obstack, "", "~",
2481b725ae77Skettenis new_fnlist->fn_fieldlist.name);
2482b725ae77Skettenis
2483b725ae77Skettenis destr_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
2484b725ae77Skettenis obstack_alloc (&objfile->objfile_obstack,
2485b725ae77Skettenis sizeof (struct fn_field) * has_destructor);
2486b725ae77Skettenis memset (destr_fnlist->fn_fieldlist.fn_fields, 0,
2487b725ae77Skettenis sizeof (struct fn_field) * has_destructor);
2488b725ae77Skettenis tmp_sublist = sublist;
2489b725ae77Skettenis last_sublist = NULL;
2490b725ae77Skettenis i = 0;
2491b725ae77Skettenis while (tmp_sublist != NULL)
2492b725ae77Skettenis {
2493b725ae77Skettenis if (!is_destructor_name (tmp_sublist->fn_field.physname))
2494b725ae77Skettenis {
2495b725ae77Skettenis tmp_sublist = tmp_sublist->next;
2496b725ae77Skettenis continue;
2497b725ae77Skettenis }
2498b725ae77Skettenis
2499b725ae77Skettenis destr_fnlist->fn_fieldlist.fn_fields[i++]
2500b725ae77Skettenis = tmp_sublist->fn_field;
2501b725ae77Skettenis if (last_sublist)
2502b725ae77Skettenis last_sublist->next = tmp_sublist->next;
2503b725ae77Skettenis else
2504b725ae77Skettenis sublist = tmp_sublist->next;
2505b725ae77Skettenis last_sublist = tmp_sublist;
2506b725ae77Skettenis tmp_sublist = tmp_sublist->next;
2507b725ae77Skettenis }
2508b725ae77Skettenis
2509b725ae77Skettenis destr_fnlist->fn_fieldlist.length = has_destructor;
2510b725ae77Skettenis destr_fnlist->next = fip->fnlist;
2511b725ae77Skettenis fip->fnlist = destr_fnlist;
2512b725ae77Skettenis nfn_fields++;
2513b725ae77Skettenis total_length += has_destructor;
2514b725ae77Skettenis length -= has_destructor;
2515b725ae77Skettenis }
2516b725ae77Skettenis else if (is_v3)
2517b725ae77Skettenis {
2518b725ae77Skettenis /* v3 mangling prevents the use of abbreviated physnames,
2519b725ae77Skettenis so we can do this here. There are stubbed methods in v3
2520b725ae77Skettenis only:
2521b725ae77Skettenis - in -gstabs instead of -gstabs+
2522b725ae77Skettenis - or for static methods, which are output as a function type
2523b725ae77Skettenis instead of a method type. */
2524b725ae77Skettenis
2525b725ae77Skettenis update_method_name_from_physname (&new_fnlist->fn_fieldlist.name,
2526b725ae77Skettenis sublist->fn_field.physname);
2527b725ae77Skettenis }
2528b725ae77Skettenis else if (has_destructor && new_fnlist->fn_fieldlist.name[0] != '~')
2529b725ae77Skettenis {
2530b725ae77Skettenis new_fnlist->fn_fieldlist.name = concat ("~", main_fn_name, NULL);
2531b725ae77Skettenis xfree (main_fn_name);
2532b725ae77Skettenis }
2533b725ae77Skettenis else if (!has_stub)
2534b725ae77Skettenis {
2535b725ae77Skettenis char dem_opname[256];
2536b725ae77Skettenis int ret;
2537b725ae77Skettenis ret = cplus_demangle_opname (new_fnlist->fn_fieldlist.name,
2538b725ae77Skettenis dem_opname, DMGL_ANSI);
2539b725ae77Skettenis if (!ret)
2540b725ae77Skettenis ret = cplus_demangle_opname (new_fnlist->fn_fieldlist.name,
2541b725ae77Skettenis dem_opname, 0);
2542b725ae77Skettenis if (ret)
2543b725ae77Skettenis new_fnlist->fn_fieldlist.name
2544b725ae77Skettenis = obsavestring (dem_opname, strlen (dem_opname),
2545b725ae77Skettenis &objfile->objfile_obstack);
2546b725ae77Skettenis }
2547e93f7393Sniklas
2548e93f7393Sniklas new_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
2549b725ae77Skettenis obstack_alloc (&objfile->objfile_obstack,
2550e93f7393Sniklas sizeof (struct fn_field) * length);
2551e93f7393Sniklas memset (new_fnlist->fn_fieldlist.fn_fields, 0,
2552e93f7393Sniklas sizeof (struct fn_field) * length);
2553e93f7393Sniklas for (i = length; (i--, sublist); sublist = sublist->next)
2554e93f7393Sniklas {
2555e93f7393Sniklas new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
2556e93f7393Sniklas }
2557e93f7393Sniklas
2558e93f7393Sniklas new_fnlist->fn_fieldlist.length = length;
2559e93f7393Sniklas new_fnlist->next = fip->fnlist;
2560e93f7393Sniklas fip->fnlist = new_fnlist;
2561e93f7393Sniklas nfn_fields++;
2562e93f7393Sniklas total_length += length;
2563b725ae77Skettenis }
2564e93f7393Sniklas }
2565e93f7393Sniklas
2566e93f7393Sniklas if (nfn_fields)
2567e93f7393Sniklas {
2568e93f7393Sniklas ALLOCATE_CPLUS_STRUCT_TYPE (type);
2569e93f7393Sniklas TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
2570e93f7393Sniklas TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
2571e93f7393Sniklas memset (TYPE_FN_FIELDLISTS (type), 0,
2572e93f7393Sniklas sizeof (struct fn_fieldlist) * nfn_fields);
2573e93f7393Sniklas TYPE_NFN_FIELDS (type) = nfn_fields;
2574e93f7393Sniklas TYPE_NFN_FIELDS_TOTAL (type) = total_length;
2575e93f7393Sniklas }
2576e93f7393Sniklas
2577e93f7393Sniklas return 1;
2578e93f7393Sniklas }
2579e93f7393Sniklas
2580e93f7393Sniklas /* Special GNU C++ name.
2581e93f7393Sniklas
2582e93f7393Sniklas Returns 1 for success, 0 for failure. "failure" means that we can't
2583e93f7393Sniklas keep parsing and it's time for error_type(). */
2584e93f7393Sniklas
2585e93f7393Sniklas static int
read_cpp_abbrev(struct field_info * fip,char ** pp,struct type * type,struct objfile * objfile)2586b725ae77Skettenis read_cpp_abbrev (struct field_info *fip, char **pp, struct type *type,
2587b725ae77Skettenis struct objfile *objfile)
2588e93f7393Sniklas {
2589b725ae77Skettenis char *p;
2590e93f7393Sniklas char *name;
2591e93f7393Sniklas char cpp_abbrev;
2592e93f7393Sniklas struct type *context;
2593e93f7393Sniklas
2594e93f7393Sniklas p = *pp;
2595e93f7393Sniklas if (*++p == 'v')
2596e93f7393Sniklas {
2597e93f7393Sniklas name = NULL;
2598e93f7393Sniklas cpp_abbrev = *++p;
2599e93f7393Sniklas
2600e93f7393Sniklas *pp = p + 1;
2601e93f7393Sniklas
2602e93f7393Sniklas /* At this point, *pp points to something like "22:23=*22...",
2603e93f7393Sniklas where the type number before the ':' is the "context" and
2604e93f7393Sniklas everything after is a regular type definition. Lookup the
2605e93f7393Sniklas type, find it's name, and construct the field name. */
2606e93f7393Sniklas
2607e93f7393Sniklas context = read_type (pp, objfile);
2608e93f7393Sniklas
2609e93f7393Sniklas switch (cpp_abbrev)
2610e93f7393Sniklas {
2611e93f7393Sniklas case 'f': /* $vf -- a virtual function table pointer */
2612b725ae77Skettenis name = type_name_no_tag (context);
2613b725ae77Skettenis if (name == NULL)
2614b725ae77Skettenis {
2615b725ae77Skettenis name = "";
2616b725ae77Skettenis }
2617e93f7393Sniklas fip->list->field.name =
2618b725ae77Skettenis obconcat (&objfile->objfile_obstack, vptr_name, name, "");
2619e93f7393Sniklas break;
2620e93f7393Sniklas
2621e93f7393Sniklas case 'b': /* $vb -- a virtual bsomethingorother */
2622e93f7393Sniklas name = type_name_no_tag (context);
2623e93f7393Sniklas if (name == NULL)
2624e93f7393Sniklas {
2625b725ae77Skettenis complaint (&symfile_complaints,
2626b725ae77Skettenis "C++ abbreviated type name unknown at symtab pos %d",
2627b725ae77Skettenis symnum);
2628e93f7393Sniklas name = "FOO";
2629e93f7393Sniklas }
2630e93f7393Sniklas fip->list->field.name =
2631b725ae77Skettenis obconcat (&objfile->objfile_obstack, vb_name, name, "");
2632e93f7393Sniklas break;
2633e93f7393Sniklas
2634e93f7393Sniklas default:
2635b725ae77Skettenis invalid_cpp_abbrev_complaint (*pp);
2636e93f7393Sniklas fip->list->field.name =
2637b725ae77Skettenis obconcat (&objfile->objfile_obstack,
2638e93f7393Sniklas "INVALID_CPLUSPLUS_ABBREV", "", "");
2639e93f7393Sniklas break;
2640e93f7393Sniklas }
2641e93f7393Sniklas
2642e93f7393Sniklas /* At this point, *pp points to the ':'. Skip it and read the
2643e93f7393Sniklas field type. */
2644e93f7393Sniklas
2645e93f7393Sniklas p = ++(*pp);
2646e93f7393Sniklas if (p[-1] != ':')
2647e93f7393Sniklas {
2648b725ae77Skettenis invalid_cpp_abbrev_complaint (*pp);
2649e93f7393Sniklas return 0;
2650e93f7393Sniklas }
2651e93f7393Sniklas fip->list->field.type = read_type (pp, objfile);
2652e93f7393Sniklas if (**pp == ',')
2653e93f7393Sniklas (*pp)++; /* Skip the comma. */
2654e93f7393Sniklas else
2655e93f7393Sniklas return 0;
2656e93f7393Sniklas
2657e93f7393Sniklas {
2658e93f7393Sniklas int nbits;
2659b725ae77Skettenis FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ';', &nbits);
2660e93f7393Sniklas if (nbits != 0)
2661e93f7393Sniklas return 0;
2662e93f7393Sniklas }
2663e93f7393Sniklas /* This field is unpacked. */
2664b725ae77Skettenis FIELD_BITSIZE (fip->list->field) = 0;
2665e93f7393Sniklas fip->list->visibility = VISIBILITY_PRIVATE;
2666e93f7393Sniklas }
2667e93f7393Sniklas else
2668e93f7393Sniklas {
2669b725ae77Skettenis invalid_cpp_abbrev_complaint (*pp);
2670e93f7393Sniklas /* We have no idea what syntax an unrecognized abbrev would have, so
2671e93f7393Sniklas better return 0. If we returned 1, we would need to at least advance
2672e93f7393Sniklas *pp to avoid an infinite loop. */
2673e93f7393Sniklas return 0;
2674e93f7393Sniklas }
2675e93f7393Sniklas return 1;
2676e93f7393Sniklas }
2677e93f7393Sniklas
2678e93f7393Sniklas static void
read_one_struct_field(struct field_info * fip,char ** pp,char * p,struct type * type,struct objfile * objfile)2679b725ae77Skettenis read_one_struct_field (struct field_info *fip, char **pp, char *p,
2680b725ae77Skettenis struct type *type, struct objfile *objfile)
2681e93f7393Sniklas {
2682e93f7393Sniklas fip->list->field.name =
2683b725ae77Skettenis obsavestring (*pp, p - *pp, &objfile->objfile_obstack);
2684e93f7393Sniklas *pp = p + 1;
2685e93f7393Sniklas
2686e93f7393Sniklas /* This means we have a visibility for a field coming. */
2687e93f7393Sniklas if (**pp == '/')
2688e93f7393Sniklas {
2689e93f7393Sniklas (*pp)++;
2690e93f7393Sniklas fip->list->visibility = *(*pp)++;
2691e93f7393Sniklas }
2692e93f7393Sniklas else
2693e93f7393Sniklas {
2694e93f7393Sniklas /* normal dbx-style format, no explicit visibility */
2695e93f7393Sniklas fip->list->visibility = VISIBILITY_PUBLIC;
2696e93f7393Sniklas }
2697e93f7393Sniklas
2698e93f7393Sniklas fip->list->field.type = read_type (pp, objfile);
2699e93f7393Sniklas if (**pp == ':')
2700e93f7393Sniklas {
2701e93f7393Sniklas p = ++(*pp);
2702e93f7393Sniklas #if 0
2703e93f7393Sniklas /* Possible future hook for nested types. */
2704e93f7393Sniklas if (**pp == '!')
2705e93f7393Sniklas {
2706e93f7393Sniklas fip->list->field.bitpos = (long) -2; /* nested type */
2707e93f7393Sniklas p = ++(*pp);
2708e93f7393Sniklas }
2709e93f7393Sniklas else
2710b725ae77Skettenis ...;
2711e93f7393Sniklas #endif
2712e93f7393Sniklas while (*p != ';')
2713e93f7393Sniklas {
2714e93f7393Sniklas p++;
2715e93f7393Sniklas }
2716b725ae77Skettenis /* Static class member. */
2717b725ae77Skettenis SET_FIELD_PHYSNAME (fip->list->field, savestring (*pp, p - *pp));
2718e93f7393Sniklas *pp = p + 1;
2719e93f7393Sniklas return;
2720e93f7393Sniklas }
2721e93f7393Sniklas else if (**pp != ',')
2722e93f7393Sniklas {
2723e93f7393Sniklas /* Bad structure-type format. */
2724b725ae77Skettenis stabs_general_complaint ("bad structure-type format");
2725e93f7393Sniklas return;
2726e93f7393Sniklas }
2727e93f7393Sniklas
2728e93f7393Sniklas (*pp)++; /* Skip the comma. */
2729e93f7393Sniklas
2730e93f7393Sniklas {
2731e93f7393Sniklas int nbits;
2732b725ae77Skettenis FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ',', &nbits);
2733e93f7393Sniklas if (nbits != 0)
2734e93f7393Sniklas {
2735b725ae77Skettenis stabs_general_complaint ("bad structure-type format");
2736e93f7393Sniklas return;
2737e93f7393Sniklas }
2738b725ae77Skettenis FIELD_BITSIZE (fip->list->field) = read_huge_number (pp, ';', &nbits);
2739e93f7393Sniklas if (nbits != 0)
2740e93f7393Sniklas {
2741b725ae77Skettenis stabs_general_complaint ("bad structure-type format");
2742e93f7393Sniklas return;
2743e93f7393Sniklas }
2744e93f7393Sniklas }
2745e93f7393Sniklas
2746b725ae77Skettenis if (FIELD_BITPOS (fip->list->field) == 0
2747b725ae77Skettenis && FIELD_BITSIZE (fip->list->field) == 0)
2748e93f7393Sniklas {
2749e93f7393Sniklas /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
2750e93f7393Sniklas it is a field which has been optimized out. The correct stab for
2751e93f7393Sniklas this case is to use VISIBILITY_IGNORE, but that is a recent
2752e93f7393Sniklas invention. (2) It is a 0-size array. For example
2753e93f7393Sniklas union { int num; char str[0]; } foo. Printing "<no value>" for
2754e93f7393Sniklas str in "p foo" is OK, since foo.str (and thus foo.str[3])
2755e93f7393Sniklas will continue to work, and a 0-size array as a whole doesn't
2756e93f7393Sniklas have any contents to print.
2757e93f7393Sniklas
2758e93f7393Sniklas I suspect this probably could also happen with gcc -gstabs (not
2759e93f7393Sniklas -gstabs+) for static fields, and perhaps other C++ extensions.
2760e93f7393Sniklas Hopefully few people use -gstabs with gdb, since it is intended
2761e93f7393Sniklas for dbx compatibility. */
2762e93f7393Sniklas
2763e93f7393Sniklas /* Ignore this field. */
2764e93f7393Sniklas fip->list->visibility = VISIBILITY_IGNORE;
2765e93f7393Sniklas }
2766e93f7393Sniklas else
2767e93f7393Sniklas {
2768e93f7393Sniklas /* Detect an unpacked field and mark it as such.
2769e93f7393Sniklas dbx gives a bit size for all fields.
2770e93f7393Sniklas Note that forward refs cannot be packed,
2771e93f7393Sniklas and treat enums as if they had the width of ints. */
2772e93f7393Sniklas
2773b725ae77Skettenis struct type *field_type = check_typedef (FIELD_TYPE (fip->list->field));
2774b725ae77Skettenis
2775b725ae77Skettenis if (TYPE_CODE (field_type) != TYPE_CODE_INT
2776b725ae77Skettenis && TYPE_CODE (field_type) != TYPE_CODE_RANGE
2777b725ae77Skettenis && TYPE_CODE (field_type) != TYPE_CODE_BOOL
2778b725ae77Skettenis && TYPE_CODE (field_type) != TYPE_CODE_ENUM)
2779e93f7393Sniklas {
2780b725ae77Skettenis FIELD_BITSIZE (fip->list->field) = 0;
2781e93f7393Sniklas }
2782b725ae77Skettenis if ((FIELD_BITSIZE (fip->list->field)
2783b725ae77Skettenis == TARGET_CHAR_BIT * TYPE_LENGTH (field_type)
2784b725ae77Skettenis || (TYPE_CODE (field_type) == TYPE_CODE_ENUM
2785b725ae77Skettenis && FIELD_BITSIZE (fip->list->field) == TARGET_INT_BIT)
2786e93f7393Sniklas )
2787e93f7393Sniklas &&
2788b725ae77Skettenis FIELD_BITPOS (fip->list->field) % 8 == 0)
2789e93f7393Sniklas {
2790b725ae77Skettenis FIELD_BITSIZE (fip->list->field) = 0;
2791e93f7393Sniklas }
2792e93f7393Sniklas }
2793e93f7393Sniklas }
2794e93f7393Sniklas
2795e93f7393Sniklas
2796e93f7393Sniklas /* Read struct or class data fields. They have the form:
2797e93f7393Sniklas
2798e93f7393Sniklas NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2799e93f7393Sniklas
2800e93f7393Sniklas At the end, we see a semicolon instead of a field.
2801e93f7393Sniklas
2802e93f7393Sniklas In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2803e93f7393Sniklas a static field.
2804e93f7393Sniklas
2805e93f7393Sniklas The optional VISIBILITY is one of:
2806e93f7393Sniklas
2807e93f7393Sniklas '/0' (VISIBILITY_PRIVATE)
2808e93f7393Sniklas '/1' (VISIBILITY_PROTECTED)
2809e93f7393Sniklas '/2' (VISIBILITY_PUBLIC)
2810e93f7393Sniklas '/9' (VISIBILITY_IGNORE)
2811e93f7393Sniklas
2812e93f7393Sniklas or nothing, for C style fields with public visibility.
2813e93f7393Sniklas
2814e93f7393Sniklas Returns 1 for success, 0 for failure. */
2815e93f7393Sniklas
2816e93f7393Sniklas static int
read_struct_fields(struct field_info * fip,char ** pp,struct type * type,struct objfile * objfile)2817b725ae77Skettenis read_struct_fields (struct field_info *fip, char **pp, struct type *type,
2818b725ae77Skettenis struct objfile *objfile)
2819e93f7393Sniklas {
2820b725ae77Skettenis char *p;
2821e93f7393Sniklas struct nextfield *new;
2822e93f7393Sniklas
2823e93f7393Sniklas /* We better set p right now, in case there are no fields at all... */
2824e93f7393Sniklas
2825e93f7393Sniklas p = *pp;
2826e93f7393Sniklas
2827e93f7393Sniklas /* Read each data member type until we find the terminating ';' at the end of
2828e93f7393Sniklas the data member list, or break for some other reason such as finding the
2829e93f7393Sniklas start of the member function list. */
2830b725ae77Skettenis /* Stab string for structure/union does not end with two ';' in
2831b725ae77Skettenis SUN C compiler 5.3 i.e. F6U2, hence check for end of string. */
2832e93f7393Sniklas
2833b725ae77Skettenis while (**pp != ';' && **pp != '\0')
2834e93f7393Sniklas {
2835e93f7393Sniklas STABS_CONTINUE (pp, objfile);
2836e93f7393Sniklas /* Get space to record the next field's data. */
2837e93f7393Sniklas new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
2838b725ae77Skettenis make_cleanup (xfree, new);
2839e93f7393Sniklas memset (new, 0, sizeof (struct nextfield));
2840e93f7393Sniklas new->next = fip->list;
2841e93f7393Sniklas fip->list = new;
2842e93f7393Sniklas
2843e93f7393Sniklas /* Get the field name. */
2844e93f7393Sniklas p = *pp;
2845e93f7393Sniklas
2846e93f7393Sniklas /* If is starts with CPLUS_MARKER it is a special abbreviation,
2847e93f7393Sniklas unless the CPLUS_MARKER is followed by an underscore, in
2848e93f7393Sniklas which case it is just the name of an anonymous type, which we
2849e93f7393Sniklas should handle like any other type name. */
2850e93f7393Sniklas
2851e93f7393Sniklas if (is_cplus_marker (p[0]) && p[1] != '_')
2852e93f7393Sniklas {
2853e93f7393Sniklas if (!read_cpp_abbrev (fip, pp, type, objfile))
2854e93f7393Sniklas return 0;
2855e93f7393Sniklas continue;
2856e93f7393Sniklas }
2857e93f7393Sniklas
2858e93f7393Sniklas /* Look for the ':' that separates the field name from the field
2859e93f7393Sniklas values. Data members are delimited by a single ':', while member
2860e93f7393Sniklas functions are delimited by a pair of ':'s. When we hit the member
2861e93f7393Sniklas functions (if any), terminate scan loop and return. */
2862e93f7393Sniklas
2863e93f7393Sniklas while (*p != ':' && *p != '\0')
2864e93f7393Sniklas {
2865e93f7393Sniklas p++;
2866e93f7393Sniklas }
2867e93f7393Sniklas if (*p == '\0')
2868e93f7393Sniklas return 0;
2869e93f7393Sniklas
2870e93f7393Sniklas /* Check to see if we have hit the member functions yet. */
2871e93f7393Sniklas if (p[1] == ':')
2872e93f7393Sniklas {
2873e93f7393Sniklas break;
2874e93f7393Sniklas }
2875e93f7393Sniklas read_one_struct_field (fip, pp, p, type, objfile);
2876e93f7393Sniklas }
2877e93f7393Sniklas if (p[0] == ':' && p[1] == ':')
2878e93f7393Sniklas {
2879b725ae77Skettenis /* (the deleted) chill the list of fields: the last entry (at
2880b725ae77Skettenis the head) is a partially constructed entry which we now
2881b725ae77Skettenis scrub. */
2882e93f7393Sniklas fip->list = fip->list->next;
2883e93f7393Sniklas }
2884e93f7393Sniklas return 1;
2885e93f7393Sniklas }
2886b725ae77Skettenis /* *INDENT-OFF* */
2887e93f7393Sniklas /* The stabs for C++ derived classes contain baseclass information which
2888e93f7393Sniklas is marked by a '!' character after the total size. This function is
2889e93f7393Sniklas called when we encounter the baseclass marker, and slurps up all the
2890e93f7393Sniklas baseclass information.
2891e93f7393Sniklas
2892e93f7393Sniklas Immediately following the '!' marker is the number of base classes that
2893e93f7393Sniklas the class is derived from, followed by information for each base class.
2894e93f7393Sniklas For each base class, there are two visibility specifiers, a bit offset
2895e93f7393Sniklas to the base class information within the derived class, a reference to
2896e93f7393Sniklas the type for the base class, and a terminating semicolon.
2897e93f7393Sniklas
2898e93f7393Sniklas A typical example, with two base classes, would be "!2,020,19;0264,21;".
2899e93f7393Sniklas ^^ ^ ^ ^ ^ ^ ^
2900e93f7393Sniklas Baseclass information marker __________________|| | | | | | |
2901e93f7393Sniklas Number of baseclasses __________________________| | | | | | |
2902e93f7393Sniklas Visibility specifiers (2) ________________________| | | | | |
2903e93f7393Sniklas Offset in bits from start of class _________________| | | | |
2904e93f7393Sniklas Type number for base class ___________________________| | | |
2905e93f7393Sniklas Visibility specifiers (2) _______________________________| | |
2906e93f7393Sniklas Offset in bits from start of class ________________________| |
2907e93f7393Sniklas Type number of base class ____________________________________|
2908e93f7393Sniklas
2909e93f7393Sniklas Return 1 for success, 0 for (error-type-inducing) failure. */
2910b725ae77Skettenis /* *INDENT-ON* */
2911b725ae77Skettenis
2912b725ae77Skettenis
2913e93f7393Sniklas
2914e93f7393Sniklas static int
read_baseclasses(struct field_info * fip,char ** pp,struct type * type,struct objfile * objfile)2915b725ae77Skettenis read_baseclasses (struct field_info *fip, char **pp, struct type *type,
2916b725ae77Skettenis struct objfile *objfile)
2917e93f7393Sniklas {
2918e93f7393Sniklas int i;
2919e93f7393Sniklas struct nextfield *new;
2920e93f7393Sniklas
2921e93f7393Sniklas if (**pp != '!')
2922e93f7393Sniklas {
2923e93f7393Sniklas return 1;
2924e93f7393Sniklas }
2925e93f7393Sniklas else
2926e93f7393Sniklas {
2927e93f7393Sniklas /* Skip the '!' baseclass information marker. */
2928e93f7393Sniklas (*pp)++;
2929e93f7393Sniklas }
2930e93f7393Sniklas
2931e93f7393Sniklas ALLOCATE_CPLUS_STRUCT_TYPE (type);
2932e93f7393Sniklas {
2933e93f7393Sniklas int nbits;
2934e93f7393Sniklas TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits);
2935e93f7393Sniklas if (nbits != 0)
2936e93f7393Sniklas return 0;
2937e93f7393Sniklas }
2938e93f7393Sniklas
2939e93f7393Sniklas #if 0
2940e93f7393Sniklas /* Some stupid compilers have trouble with the following, so break
2941e93f7393Sniklas it up into simpler expressions. */
2942e93f7393Sniklas TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
2943e93f7393Sniklas TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
2944e93f7393Sniklas #else
2945e93f7393Sniklas {
2946e93f7393Sniklas int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
2947e93f7393Sniklas char *pointer;
2948e93f7393Sniklas
2949e93f7393Sniklas pointer = (char *) TYPE_ALLOC (type, num_bytes);
2950e93f7393Sniklas TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
2951e93f7393Sniklas }
2952e93f7393Sniklas #endif /* 0 */
2953e93f7393Sniklas
2954e93f7393Sniklas B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
2955e93f7393Sniklas
2956e93f7393Sniklas for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
2957e93f7393Sniklas {
2958e93f7393Sniklas new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
2959b725ae77Skettenis make_cleanup (xfree, new);
2960e93f7393Sniklas memset (new, 0, sizeof (struct nextfield));
2961e93f7393Sniklas new->next = fip->list;
2962e93f7393Sniklas fip->list = new;
2963b725ae77Skettenis FIELD_BITSIZE (new->field) = 0; /* this should be an unpacked field! */
2964e93f7393Sniklas
2965e93f7393Sniklas STABS_CONTINUE (pp, objfile);
2966e93f7393Sniklas switch (**pp)
2967e93f7393Sniklas {
2968e93f7393Sniklas case '0':
2969e93f7393Sniklas /* Nothing to do. */
2970e93f7393Sniklas break;
2971e93f7393Sniklas case '1':
2972e93f7393Sniklas SET_TYPE_FIELD_VIRTUAL (type, i);
2973e93f7393Sniklas break;
2974e93f7393Sniklas default:
2975e93f7393Sniklas /* Unknown character. Complain and treat it as non-virtual. */
2976e93f7393Sniklas {
2977b725ae77Skettenis complaint (&symfile_complaints,
2978b725ae77Skettenis "Unknown virtual character `%c' for baseclass", **pp);
2979e93f7393Sniklas }
2980e93f7393Sniklas }
2981e93f7393Sniklas ++(*pp);
2982e93f7393Sniklas
2983e93f7393Sniklas new->visibility = *(*pp)++;
2984e93f7393Sniklas switch (new->visibility)
2985e93f7393Sniklas {
2986e93f7393Sniklas case VISIBILITY_PRIVATE:
2987e93f7393Sniklas case VISIBILITY_PROTECTED:
2988e93f7393Sniklas case VISIBILITY_PUBLIC:
2989e93f7393Sniklas break;
2990e93f7393Sniklas default:
2991e93f7393Sniklas /* Bad visibility format. Complain and treat it as
2992e93f7393Sniklas public. */
2993e93f7393Sniklas {
2994b725ae77Skettenis complaint (&symfile_complaints,
2995b725ae77Skettenis "Unknown visibility `%c' for baseclass",
2996b725ae77Skettenis new->visibility);
2997e93f7393Sniklas new->visibility = VISIBILITY_PUBLIC;
2998e93f7393Sniklas }
2999e93f7393Sniklas }
3000e93f7393Sniklas
3001e93f7393Sniklas {
3002e93f7393Sniklas int nbits;
3003e93f7393Sniklas
3004e93f7393Sniklas /* The remaining value is the bit offset of the portion of the object
3005e93f7393Sniklas corresponding to this baseclass. Always zero in the absence of
3006e93f7393Sniklas multiple inheritance. */
3007e93f7393Sniklas
3008b725ae77Skettenis FIELD_BITPOS (new->field) = read_huge_number (pp, ',', &nbits);
3009e93f7393Sniklas if (nbits != 0)
3010e93f7393Sniklas return 0;
3011e93f7393Sniklas }
3012e93f7393Sniklas
3013e93f7393Sniklas /* The last piece of baseclass information is the type of the
3014e93f7393Sniklas base class. Read it, and remember it's type name as this
3015e93f7393Sniklas field's name. */
3016e93f7393Sniklas
3017e93f7393Sniklas new->field.type = read_type (pp, objfile);
3018e93f7393Sniklas new->field.name = type_name_no_tag (new->field.type);
3019e93f7393Sniklas
3020e93f7393Sniklas /* skip trailing ';' and bump count of number of fields seen */
3021e93f7393Sniklas if (**pp == ';')
3022e93f7393Sniklas (*pp)++;
3023e93f7393Sniklas else
3024e93f7393Sniklas return 0;
3025e93f7393Sniklas }
3026e93f7393Sniklas return 1;
3027e93f7393Sniklas }
3028e93f7393Sniklas
3029e93f7393Sniklas /* The tail end of stabs for C++ classes that contain a virtual function
3030e93f7393Sniklas pointer contains a tilde, a %, and a type number.
3031e93f7393Sniklas The type number refers to the base class (possibly this class itself) which
3032e93f7393Sniklas contains the vtable pointer for the current class.
3033e93f7393Sniklas
3034e93f7393Sniklas This function is called when we have parsed all the method declarations,
3035e93f7393Sniklas so we can look for the vptr base class info. */
3036e93f7393Sniklas
3037e93f7393Sniklas static int
read_tilde_fields(struct field_info * fip,char ** pp,struct type * type,struct objfile * objfile)3038b725ae77Skettenis read_tilde_fields (struct field_info *fip, char **pp, struct type *type,
3039b725ae77Skettenis struct objfile *objfile)
3040e93f7393Sniklas {
3041b725ae77Skettenis char *p;
3042e93f7393Sniklas
3043e93f7393Sniklas STABS_CONTINUE (pp, objfile);
3044e93f7393Sniklas
3045e93f7393Sniklas /* If we are positioned at a ';', then skip it. */
3046e93f7393Sniklas if (**pp == ';')
3047e93f7393Sniklas {
3048e93f7393Sniklas (*pp)++;
3049e93f7393Sniklas }
3050e93f7393Sniklas
3051e93f7393Sniklas if (**pp == '~')
3052e93f7393Sniklas {
3053e93f7393Sniklas (*pp)++;
3054e93f7393Sniklas
3055e93f7393Sniklas if (**pp == '=' || **pp == '+' || **pp == '-')
3056e93f7393Sniklas {
3057e93f7393Sniklas /* Obsolete flags that used to indicate the presence
3058e93f7393Sniklas of constructors and/or destructors. */
3059e93f7393Sniklas (*pp)++;
3060e93f7393Sniklas }
3061e93f7393Sniklas
3062e93f7393Sniklas /* Read either a '%' or the final ';'. */
3063e93f7393Sniklas if (*(*pp)++ == '%')
3064e93f7393Sniklas {
3065e93f7393Sniklas /* The next number is the type number of the base class
3066e93f7393Sniklas (possibly our own class) which supplies the vtable for
3067e93f7393Sniklas this class. Parse it out, and search that class to find
3068e93f7393Sniklas its vtable pointer, and install those into TYPE_VPTR_BASETYPE
3069e93f7393Sniklas and TYPE_VPTR_FIELDNO. */
3070e93f7393Sniklas
3071e93f7393Sniklas struct type *t;
3072e93f7393Sniklas int i;
3073e93f7393Sniklas
3074e93f7393Sniklas t = read_type (pp, objfile);
3075e93f7393Sniklas p = (*pp)++;
3076e93f7393Sniklas while (*p != '\0' && *p != ';')
3077e93f7393Sniklas {
3078e93f7393Sniklas p++;
3079e93f7393Sniklas }
3080e93f7393Sniklas if (*p == '\0')
3081e93f7393Sniklas {
3082e93f7393Sniklas /* Premature end of symbol. */
3083e93f7393Sniklas return 0;
3084e93f7393Sniklas }
3085e93f7393Sniklas
3086e93f7393Sniklas TYPE_VPTR_BASETYPE (type) = t;
3087e93f7393Sniklas if (type == t) /* Our own class provides vtbl ptr */
3088e93f7393Sniklas {
3089e93f7393Sniklas for (i = TYPE_NFIELDS (t) - 1;
3090e93f7393Sniklas i >= TYPE_N_BASECLASSES (t);
3091e93f7393Sniklas --i)
3092e93f7393Sniklas {
3093b725ae77Skettenis char *name = TYPE_FIELD_NAME (t, i);
3094b725ae77Skettenis if (!strncmp (name, vptr_name, sizeof (vptr_name) - 2)
3095b725ae77Skettenis && is_cplus_marker (name[sizeof (vptr_name) - 2]))
3096e93f7393Sniklas {
3097e93f7393Sniklas TYPE_VPTR_FIELDNO (type) = i;
3098e93f7393Sniklas goto gotit;
3099e93f7393Sniklas }
3100e93f7393Sniklas }
3101e93f7393Sniklas /* Virtual function table field not found. */
3102b725ae77Skettenis complaint (&symfile_complaints,
3103b725ae77Skettenis "virtual function table pointer not found when defining class `%s'",
3104b725ae77Skettenis TYPE_NAME (type));
3105e93f7393Sniklas return 0;
3106e93f7393Sniklas }
3107e93f7393Sniklas else
3108e93f7393Sniklas {
3109e93f7393Sniklas TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
3110e93f7393Sniklas }
3111e93f7393Sniklas
3112e93f7393Sniklas gotit:
3113e93f7393Sniklas *pp = p + 1;
3114e93f7393Sniklas }
3115e93f7393Sniklas }
3116e93f7393Sniklas return 1;
3117e93f7393Sniklas }
3118e93f7393Sniklas
3119e93f7393Sniklas static int
attach_fn_fields_to_type(struct field_info * fip,struct type * type)3120b725ae77Skettenis attach_fn_fields_to_type (struct field_info *fip, struct type *type)
3121e93f7393Sniklas {
3122b725ae77Skettenis int n;
3123e93f7393Sniklas
3124e93f7393Sniklas for (n = TYPE_NFN_FIELDS (type);
3125e93f7393Sniklas fip->fnlist != NULL;
3126e93f7393Sniklas fip->fnlist = fip->fnlist->next)
3127e93f7393Sniklas {
3128e93f7393Sniklas --n; /* Circumvent Sun3 compiler bug */
3129e93f7393Sniklas TYPE_FN_FIELDLISTS (type)[n] = fip->fnlist->fn_fieldlist;
3130e93f7393Sniklas }
3131e93f7393Sniklas return 1;
3132e93f7393Sniklas }
3133e93f7393Sniklas
3134e93f7393Sniklas /* Create the vector of fields, and record how big it is.
3135e93f7393Sniklas We need this info to record proper virtual function table information
3136e93f7393Sniklas for this class's virtual functions. */
3137e93f7393Sniklas
3138e93f7393Sniklas static int
attach_fields_to_type(struct field_info * fip,struct type * type,struct objfile * objfile)3139b725ae77Skettenis attach_fields_to_type (struct field_info *fip, struct type *type,
3140b725ae77Skettenis struct objfile *objfile)
3141e93f7393Sniklas {
3142b725ae77Skettenis int nfields = 0;
3143b725ae77Skettenis int non_public_fields = 0;
3144b725ae77Skettenis struct nextfield *scan;
3145e93f7393Sniklas
3146e93f7393Sniklas /* Count up the number of fields that we have, as well as taking note of
3147e93f7393Sniklas whether or not there are any non-public fields, which requires us to
3148e93f7393Sniklas allocate and build the private_field_bits and protected_field_bits
3149e93f7393Sniklas bitfields. */
3150e93f7393Sniklas
3151e93f7393Sniklas for (scan = fip->list; scan != NULL; scan = scan->next)
3152e93f7393Sniklas {
3153e93f7393Sniklas nfields++;
3154e93f7393Sniklas if (scan->visibility != VISIBILITY_PUBLIC)
3155e93f7393Sniklas {
3156e93f7393Sniklas non_public_fields++;
3157e93f7393Sniklas }
3158e93f7393Sniklas }
3159e93f7393Sniklas
3160e93f7393Sniklas /* Now we know how many fields there are, and whether or not there are any
3161e93f7393Sniklas non-public fields. Record the field count, allocate space for the
3162e93f7393Sniklas array of fields, and create blank visibility bitfields if necessary. */
3163e93f7393Sniklas
3164e93f7393Sniklas TYPE_NFIELDS (type) = nfields;
3165e93f7393Sniklas TYPE_FIELDS (type) = (struct field *)
3166e93f7393Sniklas TYPE_ALLOC (type, sizeof (struct field) * nfields);
3167e93f7393Sniklas memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
3168e93f7393Sniklas
3169e93f7393Sniklas if (non_public_fields)
3170e93f7393Sniklas {
3171e93f7393Sniklas ALLOCATE_CPLUS_STRUCT_TYPE (type);
3172e93f7393Sniklas
3173e93f7393Sniklas TYPE_FIELD_PRIVATE_BITS (type) =
3174e93f7393Sniklas (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3175e93f7393Sniklas B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
3176e93f7393Sniklas
3177e93f7393Sniklas TYPE_FIELD_PROTECTED_BITS (type) =
3178e93f7393Sniklas (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3179e93f7393Sniklas B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
3180e93f7393Sniklas
3181e93f7393Sniklas TYPE_FIELD_IGNORE_BITS (type) =
3182e93f7393Sniklas (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3183e93f7393Sniklas B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
3184e93f7393Sniklas }
3185e93f7393Sniklas
3186e93f7393Sniklas /* Copy the saved-up fields into the field vector. Start from the head
3187e93f7393Sniklas of the list, adding to the tail of the field array, so that they end
3188e93f7393Sniklas up in the same order in the array in which they were added to the list. */
3189e93f7393Sniklas
3190e93f7393Sniklas while (nfields-- > 0)
3191e93f7393Sniklas {
3192e93f7393Sniklas TYPE_FIELD (type, nfields) = fip->list->field;
3193e93f7393Sniklas switch (fip->list->visibility)
3194e93f7393Sniklas {
3195e93f7393Sniklas case VISIBILITY_PRIVATE:
3196e93f7393Sniklas SET_TYPE_FIELD_PRIVATE (type, nfields);
3197e93f7393Sniklas break;
3198e93f7393Sniklas
3199e93f7393Sniklas case VISIBILITY_PROTECTED:
3200e93f7393Sniklas SET_TYPE_FIELD_PROTECTED (type, nfields);
3201e93f7393Sniklas break;
3202e93f7393Sniklas
3203e93f7393Sniklas case VISIBILITY_IGNORE:
3204e93f7393Sniklas SET_TYPE_FIELD_IGNORE (type, nfields);
3205e93f7393Sniklas break;
3206e93f7393Sniklas
3207e93f7393Sniklas case VISIBILITY_PUBLIC:
3208e93f7393Sniklas break;
3209e93f7393Sniklas
3210e93f7393Sniklas default:
3211e93f7393Sniklas /* Unknown visibility. Complain and treat it as public. */
3212e93f7393Sniklas {
3213b725ae77Skettenis complaint (&symfile_complaints, "Unknown visibility `%c' for field",
3214b725ae77Skettenis fip->list->visibility);
3215e93f7393Sniklas }
3216e93f7393Sniklas break;
3217e93f7393Sniklas }
3218e93f7393Sniklas fip->list = fip->list->next;
3219e93f7393Sniklas }
3220e93f7393Sniklas return 1;
3221e93f7393Sniklas }
3222e93f7393Sniklas
3223b725ae77Skettenis
3224b725ae77Skettenis /* Complain that the compiler has emitted more than one definition for the
3225b725ae77Skettenis structure type TYPE. */
3226b725ae77Skettenis static void
complain_about_struct_wipeout(struct type * type)3227b725ae77Skettenis complain_about_struct_wipeout (struct type *type)
3228b725ae77Skettenis {
3229b725ae77Skettenis char *name = "";
3230b725ae77Skettenis char *kind = "";
3231b725ae77Skettenis
3232b725ae77Skettenis if (TYPE_TAG_NAME (type))
3233b725ae77Skettenis {
3234b725ae77Skettenis name = TYPE_TAG_NAME (type);
3235b725ae77Skettenis switch (TYPE_CODE (type))
3236b725ae77Skettenis {
3237b725ae77Skettenis case TYPE_CODE_STRUCT: kind = "struct "; break;
3238b725ae77Skettenis case TYPE_CODE_UNION: kind = "union "; break;
3239b725ae77Skettenis case TYPE_CODE_ENUM: kind = "enum "; break;
3240b725ae77Skettenis default: kind = "";
3241b725ae77Skettenis }
3242b725ae77Skettenis }
3243b725ae77Skettenis else if (TYPE_NAME (type))
3244b725ae77Skettenis {
3245b725ae77Skettenis name = TYPE_NAME (type);
3246b725ae77Skettenis kind = "";
3247b725ae77Skettenis }
3248b725ae77Skettenis else
3249b725ae77Skettenis {
3250b725ae77Skettenis name = "<unknown>";
3251b725ae77Skettenis kind = "";
3252b725ae77Skettenis }
3253b725ae77Skettenis
3254b725ae77Skettenis complaint (&symfile_complaints,
3255b725ae77Skettenis "struct/union type gets multiply defined: %s%s", kind, name);
3256b725ae77Skettenis }
3257b725ae77Skettenis
3258b725ae77Skettenis
3259e93f7393Sniklas /* Read the description of a structure (or union type) and return an object
3260e93f7393Sniklas describing the type.
3261e93f7393Sniklas
3262e93f7393Sniklas PP points to a character pointer that points to the next unconsumed token
3263e93f7393Sniklas in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
3264e93f7393Sniklas *PP will point to "4a:1,0,32;;".
3265e93f7393Sniklas
3266e93f7393Sniklas TYPE points to an incomplete type that needs to be filled in.
3267e93f7393Sniklas
3268e93f7393Sniklas OBJFILE points to the current objfile from which the stabs information is
3269e93f7393Sniklas being read. (Note that it is redundant in that TYPE also contains a pointer
3270e93f7393Sniklas to this same objfile, so it might be a good idea to eliminate it. FIXME).
3271e93f7393Sniklas */
3272e93f7393Sniklas
3273e93f7393Sniklas static struct type *
read_struct_type(char ** pp,struct type * type,enum type_code type_code,struct objfile * objfile)3274b725ae77Skettenis read_struct_type (char **pp, struct type *type, enum type_code type_code,
3275b725ae77Skettenis struct objfile *objfile)
3276e93f7393Sniklas {
3277e93f7393Sniklas struct cleanup *back_to;
3278e93f7393Sniklas struct field_info fi;
3279e93f7393Sniklas
3280e93f7393Sniklas fi.list = NULL;
3281e93f7393Sniklas fi.fnlist = NULL;
3282e93f7393Sniklas
3283b725ae77Skettenis /* When describing struct/union/class types in stabs, G++ always drops
3284b725ae77Skettenis all qualifications from the name. So if you've got:
3285b725ae77Skettenis struct A { ... struct B { ... }; ... };
3286b725ae77Skettenis then G++ will emit stabs for `struct A::B' that call it simply
3287b725ae77Skettenis `struct B'. Obviously, if you've got a real top-level definition for
3288b725ae77Skettenis `struct B', or other nested definitions, this is going to cause
3289b725ae77Skettenis problems.
3290b725ae77Skettenis
3291b725ae77Skettenis Obviously, GDB can't fix this by itself, but it can at least avoid
3292b725ae77Skettenis scribbling on existing structure type objects when new definitions
3293b725ae77Skettenis appear. */
3294b725ae77Skettenis if (! (TYPE_CODE (type) == TYPE_CODE_UNDEF
3295b725ae77Skettenis || TYPE_STUB (type)))
3296b725ae77Skettenis {
3297b725ae77Skettenis complain_about_struct_wipeout (type);
3298b725ae77Skettenis
3299b725ae77Skettenis /* It's probably best to return the type unchanged. */
3300b725ae77Skettenis return type;
3301b725ae77Skettenis }
3302b725ae77Skettenis
3303e93f7393Sniklas back_to = make_cleanup (null_cleanup, 0);
3304e93f7393Sniklas
3305e93f7393Sniklas INIT_CPLUS_SPECIFIC (type);
3306b725ae77Skettenis TYPE_CODE (type) = type_code;
3307e93f7393Sniklas TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
3308e93f7393Sniklas
3309e93f7393Sniklas /* First comes the total size in bytes. */
3310e93f7393Sniklas
3311e93f7393Sniklas {
3312e93f7393Sniklas int nbits;
3313e93f7393Sniklas TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits);
3314e93f7393Sniklas if (nbits != 0)
3315e93f7393Sniklas return error_type (pp, objfile);
3316e93f7393Sniklas }
3317e93f7393Sniklas
3318e93f7393Sniklas /* Now read the baseclasses, if any, read the regular C struct or C++
3319e93f7393Sniklas class member fields, attach the fields to the type, read the C++
3320e93f7393Sniklas member functions, attach them to the type, and then read any tilde
3321e93f7393Sniklas field (baseclass specifier for the class holding the main vtable). */
3322e93f7393Sniklas
3323e93f7393Sniklas if (!read_baseclasses (&fi, pp, type, objfile)
3324e93f7393Sniklas || !read_struct_fields (&fi, pp, type, objfile)
3325e93f7393Sniklas || !attach_fields_to_type (&fi, type, objfile)
3326e93f7393Sniklas || !read_member_functions (&fi, pp, type, objfile)
3327e93f7393Sniklas || !attach_fn_fields_to_type (&fi, type)
3328e93f7393Sniklas || !read_tilde_fields (&fi, pp, type, objfile))
3329e93f7393Sniklas {
3330e93f7393Sniklas type = error_type (pp, objfile);
3331e93f7393Sniklas }
3332e93f7393Sniklas
3333e93f7393Sniklas do_cleanups (back_to);
3334e93f7393Sniklas return (type);
3335e93f7393Sniklas }
3336e93f7393Sniklas
3337e93f7393Sniklas /* Read a definition of an array type,
3338e93f7393Sniklas and create and return a suitable type object.
3339e93f7393Sniklas Also creates a range type which represents the bounds of that
3340e93f7393Sniklas array. */
3341e93f7393Sniklas
3342e93f7393Sniklas static struct type *
read_array_type(char ** pp,struct type * type,struct objfile * objfile)3343b725ae77Skettenis read_array_type (char **pp, struct type *type,
3344b725ae77Skettenis struct objfile *objfile)
3345e93f7393Sniklas {
3346e93f7393Sniklas struct type *index_type, *element_type, *range_type;
3347e93f7393Sniklas int lower, upper;
3348e93f7393Sniklas int adjustable = 0;
3349e93f7393Sniklas int nbits;
3350e93f7393Sniklas
3351e93f7393Sniklas /* Format of an array type:
3352e93f7393Sniklas "ar<index type>;lower;upper;<array_contents_type>".
3353e93f7393Sniklas OS9000: "arlower,upper;<array_contents_type>".
3354e93f7393Sniklas
3355e93f7393Sniklas Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3356e93f7393Sniklas for these, produce a type like float[][]. */
3357e93f7393Sniklas
3358e93f7393Sniklas {
3359e93f7393Sniklas index_type = read_type (pp, objfile);
3360e93f7393Sniklas if (**pp != ';')
3361e93f7393Sniklas /* Improper format of array type decl. */
3362e93f7393Sniklas return error_type (pp, objfile);
3363e93f7393Sniklas ++*pp;
3364e93f7393Sniklas }
3365e93f7393Sniklas
3366e93f7393Sniklas if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
3367e93f7393Sniklas {
3368e93f7393Sniklas (*pp)++;
3369e93f7393Sniklas adjustable = 1;
3370e93f7393Sniklas }
3371b725ae77Skettenis lower = read_huge_number (pp, ';', &nbits);
3372b725ae77Skettenis
3373e93f7393Sniklas if (nbits != 0)
3374e93f7393Sniklas return error_type (pp, objfile);
3375e93f7393Sniklas
3376e93f7393Sniklas if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
3377e93f7393Sniklas {
3378e93f7393Sniklas (*pp)++;
3379e93f7393Sniklas adjustable = 1;
3380e93f7393Sniklas }
3381e93f7393Sniklas upper = read_huge_number (pp, ';', &nbits);
3382e93f7393Sniklas if (nbits != 0)
3383e93f7393Sniklas return error_type (pp, objfile);
3384e93f7393Sniklas
3385e93f7393Sniklas element_type = read_type (pp, objfile);
3386e93f7393Sniklas
3387e93f7393Sniklas if (adjustable)
3388e93f7393Sniklas {
3389e93f7393Sniklas lower = 0;
3390e93f7393Sniklas upper = -1;
3391e93f7393Sniklas }
3392e93f7393Sniklas
3393e93f7393Sniklas range_type =
3394e93f7393Sniklas create_range_type ((struct type *) NULL, index_type, lower, upper);
3395e93f7393Sniklas type = create_array_type (type, element_type, range_type);
3396e93f7393Sniklas
3397e93f7393Sniklas return type;
3398e93f7393Sniklas }
3399e93f7393Sniklas
3400e93f7393Sniklas
3401e93f7393Sniklas /* Read a definition of an enumeration type,
3402e93f7393Sniklas and create and return a suitable type object.
3403e93f7393Sniklas Also defines the symbols that represent the values of the type. */
3404e93f7393Sniklas
3405e93f7393Sniklas static struct type *
read_enum_type(char ** pp,struct type * type,struct objfile * objfile)3406b725ae77Skettenis read_enum_type (char **pp, struct type *type,
3407b725ae77Skettenis struct objfile *objfile)
3408e93f7393Sniklas {
3409b725ae77Skettenis char *p;
3410e93f7393Sniklas char *name;
3411b725ae77Skettenis long n;
3412b725ae77Skettenis struct symbol *sym;
3413e93f7393Sniklas int nsyms = 0;
3414e93f7393Sniklas struct pending **symlist;
3415e93f7393Sniklas struct pending *osyms, *syms;
3416e93f7393Sniklas int o_nsyms;
3417e93f7393Sniklas int nbits;
3418e93f7393Sniklas int unsigned_enum = 1;
3419e93f7393Sniklas
3420e93f7393Sniklas #if 0
3421e93f7393Sniklas /* FIXME! The stabs produced by Sun CC merrily define things that ought
3422e93f7393Sniklas to be file-scope, between N_FN entries, using N_LSYM. What's a mother
3423e93f7393Sniklas to do? For now, force all enum values to file scope. */
3424e93f7393Sniklas if (within_function)
3425e93f7393Sniklas symlist = &local_symbols;
3426e93f7393Sniklas else
3427e93f7393Sniklas #endif
3428e93f7393Sniklas symlist = &file_symbols;
3429e93f7393Sniklas osyms = *symlist;
3430e93f7393Sniklas o_nsyms = osyms ? osyms->nsyms : 0;
3431e93f7393Sniklas
3432e93f7393Sniklas /* The aix4 compiler emits an extra field before the enum members;
3433e93f7393Sniklas my guess is it's a type of some sort. Just ignore it. */
3434e93f7393Sniklas if (**pp == '-')
3435e93f7393Sniklas {
3436e93f7393Sniklas /* Skip over the type. */
3437e93f7393Sniklas while (**pp != ':')
3438e93f7393Sniklas (*pp)++;
3439e93f7393Sniklas
3440e93f7393Sniklas /* Skip over the colon. */
3441e93f7393Sniklas (*pp)++;
3442e93f7393Sniklas }
3443e93f7393Sniklas
3444e93f7393Sniklas /* Read the value-names and their values.
3445e93f7393Sniklas The input syntax is NAME:VALUE,NAME:VALUE, and so on.
3446e93f7393Sniklas A semicolon or comma instead of a NAME means the end. */
3447e93f7393Sniklas while (**pp && **pp != ';' && **pp != ',')
3448e93f7393Sniklas {
3449e93f7393Sniklas STABS_CONTINUE (pp, objfile);
3450e93f7393Sniklas p = *pp;
3451b725ae77Skettenis while (*p != ':')
3452b725ae77Skettenis p++;
3453b725ae77Skettenis name = obsavestring (*pp, p - *pp, &objfile->objfile_obstack);
3454e93f7393Sniklas *pp = p + 1;
3455e93f7393Sniklas n = read_huge_number (pp, ',', &nbits);
3456e93f7393Sniklas if (nbits != 0)
3457e93f7393Sniklas return error_type (pp, objfile);
3458e93f7393Sniklas
3459e93f7393Sniklas sym = (struct symbol *)
3460b725ae77Skettenis obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol));
3461e93f7393Sniklas memset (sym, 0, sizeof (struct symbol));
3462b725ae77Skettenis DEPRECATED_SYMBOL_NAME (sym) = name;
3463e93f7393Sniklas SYMBOL_LANGUAGE (sym) = current_subfile->language;
3464e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_CONST;
3465b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
3466e93f7393Sniklas SYMBOL_VALUE (sym) = n;
3467e93f7393Sniklas if (n < 0)
3468e93f7393Sniklas unsigned_enum = 0;
3469e93f7393Sniklas add_symbol_to_list (sym, symlist);
3470e93f7393Sniklas nsyms++;
3471e93f7393Sniklas }
3472e93f7393Sniklas
3473e93f7393Sniklas if (**pp == ';')
3474e93f7393Sniklas (*pp)++; /* Skip the semicolon. */
3475e93f7393Sniklas
3476e93f7393Sniklas /* Now fill in the fields of the type-structure. */
3477e93f7393Sniklas
3478e93f7393Sniklas TYPE_LENGTH (type) = TARGET_INT_BIT / HOST_CHAR_BIT;
3479e93f7393Sniklas TYPE_CODE (type) = TYPE_CODE_ENUM;
3480e93f7393Sniklas TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
3481e93f7393Sniklas if (unsigned_enum)
3482e93f7393Sniklas TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
3483e93f7393Sniklas TYPE_NFIELDS (type) = nsyms;
3484e93f7393Sniklas TYPE_FIELDS (type) = (struct field *)
3485e93f7393Sniklas TYPE_ALLOC (type, sizeof (struct field) * nsyms);
3486e93f7393Sniklas memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
3487e93f7393Sniklas
3488e93f7393Sniklas /* Find the symbols for the values and put them into the type.
3489e93f7393Sniklas The symbols can be found in the symlist that we put them on
3490e93f7393Sniklas to cause them to be defined. osyms contains the old value
3491e93f7393Sniklas of that symlist; everything up to there was defined by us. */
3492e93f7393Sniklas /* Note that we preserve the order of the enum constants, so
3493e93f7393Sniklas that in something like "enum {FOO, LAST_THING=FOO}" we print
3494e93f7393Sniklas FOO, not LAST_THING. */
3495e93f7393Sniklas
3496e93f7393Sniklas for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next)
3497e93f7393Sniklas {
3498e93f7393Sniklas int last = syms == osyms ? o_nsyms : 0;
3499e93f7393Sniklas int j = syms->nsyms;
3500e93f7393Sniklas for (; --j >= last; --n)
3501e93f7393Sniklas {
3502e93f7393Sniklas struct symbol *xsym = syms->symbol[j];
3503e93f7393Sniklas SYMBOL_TYPE (xsym) = type;
3504b725ae77Skettenis TYPE_FIELD_NAME (type, n) = DEPRECATED_SYMBOL_NAME (xsym);
3505e93f7393Sniklas TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
3506e93f7393Sniklas TYPE_FIELD_BITSIZE (type, n) = 0;
3507e93f7393Sniklas }
3508e93f7393Sniklas if (syms == osyms)
3509e93f7393Sniklas break;
3510e93f7393Sniklas }
3511e93f7393Sniklas
3512e93f7393Sniklas return type;
3513e93f7393Sniklas }
3514e93f7393Sniklas
3515e93f7393Sniklas /* Sun's ACC uses a somewhat saner method for specifying the builtin
3516e93f7393Sniklas typedefs in every file (for int, long, etc):
3517e93f7393Sniklas
3518b725ae77Skettenis type = b <signed> <width> <format type>; <offset>; <nbits>
3519b725ae77Skettenis signed = u or s.
3520b725ae77Skettenis optional format type = c or b for char or boolean.
3521e93f7393Sniklas offset = offset from high order bit to start bit of type.
3522e93f7393Sniklas width is # bytes in object of this type, nbits is # bits in type.
3523e93f7393Sniklas
3524e93f7393Sniklas The width/offset stuff appears to be for small objects stored in
3525e93f7393Sniklas larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
3526e93f7393Sniklas FIXME. */
3527e93f7393Sniklas
3528e93f7393Sniklas static struct type *
read_sun_builtin_type(char ** pp,int typenums[2],struct objfile * objfile)3529b725ae77Skettenis read_sun_builtin_type (char **pp, int typenums[2], struct objfile *objfile)
3530e93f7393Sniklas {
3531e93f7393Sniklas int type_bits;
3532e93f7393Sniklas int nbits;
3533e93f7393Sniklas int signed_type;
3534b725ae77Skettenis enum type_code code = TYPE_CODE_INT;
3535e93f7393Sniklas
3536e93f7393Sniklas switch (**pp)
3537e93f7393Sniklas {
3538e93f7393Sniklas case 's':
3539e93f7393Sniklas signed_type = 1;
3540e93f7393Sniklas break;
3541e93f7393Sniklas case 'u':
3542e93f7393Sniklas signed_type = 0;
3543e93f7393Sniklas break;
3544e93f7393Sniklas default:
3545e93f7393Sniklas return error_type (pp, objfile);
3546e93f7393Sniklas }
3547e93f7393Sniklas (*pp)++;
3548e93f7393Sniklas
3549e93f7393Sniklas /* For some odd reason, all forms of char put a c here. This is strange
3550e93f7393Sniklas because no other type has this honor. We can safely ignore this because
3551e93f7393Sniklas we actually determine 'char'acterness by the number of bits specified in
3552b725ae77Skettenis the descriptor.
3553b725ae77Skettenis Boolean forms, e.g Fortran logical*X, put a b here. */
3554e93f7393Sniklas
3555e93f7393Sniklas if (**pp == 'c')
3556e93f7393Sniklas (*pp)++;
3557b725ae77Skettenis else if (**pp == 'b')
3558b725ae77Skettenis {
3559b725ae77Skettenis code = TYPE_CODE_BOOL;
3560b725ae77Skettenis (*pp)++;
3561b725ae77Skettenis }
3562e93f7393Sniklas
3563e93f7393Sniklas /* The first number appears to be the number of bytes occupied
3564e93f7393Sniklas by this type, except that unsigned short is 4 instead of 2.
3565e93f7393Sniklas Since this information is redundant with the third number,
3566e93f7393Sniklas we will ignore it. */
3567e93f7393Sniklas read_huge_number (pp, ';', &nbits);
3568e93f7393Sniklas if (nbits != 0)
3569e93f7393Sniklas return error_type (pp, objfile);
3570e93f7393Sniklas
3571e93f7393Sniklas /* The second number is always 0, so ignore it too. */
3572e93f7393Sniklas read_huge_number (pp, ';', &nbits);
3573e93f7393Sniklas if (nbits != 0)
3574e93f7393Sniklas return error_type (pp, objfile);
3575e93f7393Sniklas
3576e93f7393Sniklas /* The third number is the number of bits for this type. */
3577e93f7393Sniklas type_bits = read_huge_number (pp, 0, &nbits);
3578e93f7393Sniklas if (nbits != 0)
3579e93f7393Sniklas return error_type (pp, objfile);
3580e93f7393Sniklas /* The type *should* end with a semicolon. If it are embedded
3581e93f7393Sniklas in a larger type the semicolon may be the only way to know where
3582e93f7393Sniklas the type ends. If this type is at the end of the stabstring we
3583e93f7393Sniklas can deal with the omitted semicolon (but we don't have to like
3584e93f7393Sniklas it). Don't bother to complain(), Sun's compiler omits the semicolon
3585e93f7393Sniklas for "void". */
3586e93f7393Sniklas if (**pp == ';')
3587e93f7393Sniklas ++(*pp);
3588e93f7393Sniklas
3589e93f7393Sniklas if (type_bits == 0)
3590e93f7393Sniklas return init_type (TYPE_CODE_VOID, 1,
3591e93f7393Sniklas signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
3592e93f7393Sniklas objfile);
3593e93f7393Sniklas else
3594b725ae77Skettenis return init_type (code,
3595e93f7393Sniklas type_bits / TARGET_CHAR_BIT,
3596e93f7393Sniklas signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
3597e93f7393Sniklas objfile);
3598e93f7393Sniklas }
3599e93f7393Sniklas
3600e93f7393Sniklas static struct type *
read_sun_floating_type(char ** pp,int typenums[2],struct objfile * objfile)3601b725ae77Skettenis read_sun_floating_type (char **pp, int typenums[2], struct objfile *objfile)
3602e93f7393Sniklas {
3603e93f7393Sniklas int nbits;
3604e93f7393Sniklas int details;
3605e93f7393Sniklas int nbytes;
3606b725ae77Skettenis struct type *rettype;
3607e93f7393Sniklas
3608e93f7393Sniklas /* The first number has more details about the type, for example
3609e93f7393Sniklas FN_COMPLEX. */
3610e93f7393Sniklas details = read_huge_number (pp, ';', &nbits);
3611e93f7393Sniklas if (nbits != 0)
3612e93f7393Sniklas return error_type (pp, objfile);
3613e93f7393Sniklas
3614e93f7393Sniklas /* The second number is the number of bytes occupied by this type */
3615e93f7393Sniklas nbytes = read_huge_number (pp, ';', &nbits);
3616e93f7393Sniklas if (nbits != 0)
3617e93f7393Sniklas return error_type (pp, objfile);
3618e93f7393Sniklas
3619e93f7393Sniklas if (details == NF_COMPLEX || details == NF_COMPLEX16
3620e93f7393Sniklas || details == NF_COMPLEX32)
3621b725ae77Skettenis {
3622b725ae77Skettenis rettype = init_type (TYPE_CODE_COMPLEX, nbytes, 0, NULL, objfile);
3623b725ae77Skettenis TYPE_TARGET_TYPE (rettype)
3624b725ae77Skettenis = init_type (TYPE_CODE_FLT, nbytes / 2, 0, NULL, objfile);
3625b725ae77Skettenis return rettype;
3626b725ae77Skettenis }
3627e93f7393Sniklas
3628e93f7393Sniklas return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile);
3629e93f7393Sniklas }
3630e93f7393Sniklas
3631e93f7393Sniklas /* Read a number from the string pointed to by *PP.
3632e93f7393Sniklas The value of *PP is advanced over the number.
3633e93f7393Sniklas If END is nonzero, the character that ends the
3634e93f7393Sniklas number must match END, or an error happens;
3635e93f7393Sniklas and that character is skipped if it does match.
3636e93f7393Sniklas If END is zero, *PP is left pointing to that character.
3637e93f7393Sniklas
3638e93f7393Sniklas If the number fits in a long, set *BITS to 0 and return the value.
3639e93f7393Sniklas If not, set *BITS to be the number of bits in the number and return 0.
3640e93f7393Sniklas
3641e93f7393Sniklas If encounter garbage, set *BITS to -1 and return 0. */
3642e93f7393Sniklas
3643e93f7393Sniklas static long
read_huge_number(char ** pp,int end,int * bits)3644b725ae77Skettenis read_huge_number (char **pp, int end, int *bits)
3645e93f7393Sniklas {
3646e93f7393Sniklas char *p = *pp;
3647e93f7393Sniklas int sign = 1;
3648e93f7393Sniklas long n = 0;
3649e93f7393Sniklas int radix = 10;
3650e93f7393Sniklas char overflow = 0;
3651e93f7393Sniklas int nbits = 0;
3652e93f7393Sniklas int c;
3653e93f7393Sniklas long upper_limit;
3654e93f7393Sniklas
3655e93f7393Sniklas if (*p == '-')
3656e93f7393Sniklas {
3657e93f7393Sniklas sign = -1;
3658e93f7393Sniklas p++;
3659e93f7393Sniklas }
3660e93f7393Sniklas
3661e93f7393Sniklas /* Leading zero means octal. GCC uses this to output values larger
3662e93f7393Sniklas than an int (because that would be hard in decimal). */
3663e93f7393Sniklas if (*p == '0')
3664e93f7393Sniklas {
3665e93f7393Sniklas radix = 8;
3666e93f7393Sniklas p++;
3667e93f7393Sniklas }
3668e93f7393Sniklas
3669e93f7393Sniklas upper_limit = LONG_MAX / radix;
3670e93f7393Sniklas
3671e93f7393Sniklas while ((c = *p++) >= '0' && c < ('0' + radix))
3672e93f7393Sniklas {
3673e93f7393Sniklas if (n <= upper_limit)
3674e93f7393Sniklas {
3675e93f7393Sniklas n *= radix;
3676e93f7393Sniklas n += c - '0'; /* FIXME this overflows anyway */
3677e93f7393Sniklas }
3678e93f7393Sniklas else
3679e93f7393Sniklas overflow = 1;
3680e93f7393Sniklas
3681e93f7393Sniklas /* This depends on large values being output in octal, which is
3682e93f7393Sniklas what GCC does. */
3683e93f7393Sniklas if (radix == 8)
3684e93f7393Sniklas {
3685e93f7393Sniklas if (nbits == 0)
3686e93f7393Sniklas {
3687e93f7393Sniklas if (c == '0')
3688e93f7393Sniklas /* Ignore leading zeroes. */
3689e93f7393Sniklas ;
3690e93f7393Sniklas else if (c == '1')
3691e93f7393Sniklas nbits = 1;
3692e93f7393Sniklas else if (c == '2' || c == '3')
3693e93f7393Sniklas nbits = 2;
3694e93f7393Sniklas else
3695e93f7393Sniklas nbits = 3;
3696e93f7393Sniklas }
3697e93f7393Sniklas else
3698e93f7393Sniklas nbits += 3;
3699e93f7393Sniklas }
3700e93f7393Sniklas }
3701e93f7393Sniklas if (end)
3702e93f7393Sniklas {
3703e93f7393Sniklas if (c && c != end)
3704e93f7393Sniklas {
3705e93f7393Sniklas if (bits != NULL)
3706e93f7393Sniklas *bits = -1;
3707e93f7393Sniklas return 0;
3708e93f7393Sniklas }
3709e93f7393Sniklas }
3710e93f7393Sniklas else
3711e93f7393Sniklas --p;
3712e93f7393Sniklas
3713e93f7393Sniklas *pp = p;
3714e93f7393Sniklas if (overflow)
3715e93f7393Sniklas {
3716e93f7393Sniklas if (nbits == 0)
3717e93f7393Sniklas {
3718e93f7393Sniklas /* Large decimal constants are an error (because it is hard to
3719e93f7393Sniklas count how many bits are in them). */
3720e93f7393Sniklas if (bits != NULL)
3721e93f7393Sniklas *bits = -1;
3722e93f7393Sniklas return 0;
3723e93f7393Sniklas }
3724e93f7393Sniklas
3725e93f7393Sniklas /* -0x7f is the same as 0x80. So deal with it by adding one to
3726e93f7393Sniklas the number of bits. */
3727e93f7393Sniklas if (sign == -1)
3728e93f7393Sniklas ++nbits;
3729e93f7393Sniklas if (bits)
3730e93f7393Sniklas *bits = nbits;
3731e93f7393Sniklas }
3732e93f7393Sniklas else
3733e93f7393Sniklas {
3734e93f7393Sniklas if (bits)
3735e93f7393Sniklas *bits = 0;
3736e93f7393Sniklas return n * sign;
3737e93f7393Sniklas }
3738e93f7393Sniklas /* It's *BITS which has the interesting information. */
3739e93f7393Sniklas return 0;
3740e93f7393Sniklas }
3741e93f7393Sniklas
3742e93f7393Sniklas static struct type *
read_range_type(char ** pp,int typenums[2],struct objfile * objfile)3743b725ae77Skettenis read_range_type (char **pp, int typenums[2], struct objfile *objfile)
3744e93f7393Sniklas {
3745e93f7393Sniklas char *orig_pp = *pp;
3746e93f7393Sniklas int rangenums[2];
3747e93f7393Sniklas long n2, n3;
3748e93f7393Sniklas int n2bits, n3bits;
3749e93f7393Sniklas int self_subrange;
3750e93f7393Sniklas struct type *result_type;
3751e93f7393Sniklas struct type *index_type = NULL;
3752e93f7393Sniklas
3753e93f7393Sniklas /* First comes a type we are a subrange of.
3754e93f7393Sniklas In C it is usually 0, 1 or the type being defined. */
3755e93f7393Sniklas if (read_type_number (pp, rangenums) != 0)
3756e93f7393Sniklas return error_type (pp, objfile);
3757e93f7393Sniklas self_subrange = (rangenums[0] == typenums[0] &&
3758e93f7393Sniklas rangenums[1] == typenums[1]);
3759e93f7393Sniklas
3760e93f7393Sniklas if (**pp == '=')
3761e93f7393Sniklas {
3762e93f7393Sniklas *pp = orig_pp;
3763e93f7393Sniklas index_type = read_type (pp, objfile);
3764e93f7393Sniklas }
3765e93f7393Sniklas
3766e93f7393Sniklas /* A semicolon should now follow; skip it. */
3767e93f7393Sniklas if (**pp == ';')
3768e93f7393Sniklas (*pp)++;
3769e93f7393Sniklas
3770e93f7393Sniklas /* The remaining two operands are usually lower and upper bounds
3771e93f7393Sniklas of the range. But in some special cases they mean something else. */
3772e93f7393Sniklas n2 = read_huge_number (pp, ';', &n2bits);
3773e93f7393Sniklas n3 = read_huge_number (pp, ';', &n3bits);
3774e93f7393Sniklas
3775e93f7393Sniklas if (n2bits == -1 || n3bits == -1)
3776e93f7393Sniklas return error_type (pp, objfile);
3777e93f7393Sniklas
3778e93f7393Sniklas if (index_type)
3779e93f7393Sniklas goto handle_true_range;
3780e93f7393Sniklas
3781e93f7393Sniklas /* If limits are huge, must be large integral type. */
3782e93f7393Sniklas if (n2bits != 0 || n3bits != 0)
3783e93f7393Sniklas {
3784e93f7393Sniklas char got_signed = 0;
3785e93f7393Sniklas char got_unsigned = 0;
3786e93f7393Sniklas /* Number of bits in the type. */
3787e93f7393Sniklas int nbits = 0;
3788e93f7393Sniklas
3789e93f7393Sniklas /* Range from 0 to <large number> is an unsigned large integral type. */
3790e93f7393Sniklas if ((n2bits == 0 && n2 == 0) && n3bits != 0)
3791e93f7393Sniklas {
3792e93f7393Sniklas got_unsigned = 1;
3793e93f7393Sniklas nbits = n3bits;
3794e93f7393Sniklas }
3795e93f7393Sniklas /* Range from <large number> to <large number>-1 is a large signed
3796e93f7393Sniklas integral type. Take care of the case where <large number> doesn't
3797e93f7393Sniklas fit in a long but <large number>-1 does. */
3798e93f7393Sniklas else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
3799e93f7393Sniklas || (n2bits != 0 && n3bits == 0
3800e93f7393Sniklas && (n2bits == sizeof (long) * HOST_CHAR_BIT)
3801e93f7393Sniklas && n3 == LONG_MAX))
3802e93f7393Sniklas {
3803e93f7393Sniklas got_signed = 1;
3804e93f7393Sniklas nbits = n2bits;
3805e93f7393Sniklas }
3806e93f7393Sniklas
3807e93f7393Sniklas if (got_signed || got_unsigned)
3808e93f7393Sniklas {
3809e93f7393Sniklas return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT,
3810e93f7393Sniklas got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL,
3811e93f7393Sniklas objfile);
3812e93f7393Sniklas }
3813e93f7393Sniklas else
3814e93f7393Sniklas return error_type (pp, objfile);
3815e93f7393Sniklas }
3816e93f7393Sniklas
3817e93f7393Sniklas /* A type defined as a subrange of itself, with bounds both 0, is void. */
3818e93f7393Sniklas if (self_subrange && n2 == 0 && n3 == 0)
3819e93f7393Sniklas return init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
3820e93f7393Sniklas
3821b725ae77Skettenis /* If n3 is zero and n2 is positive, we want a floating type, and n2
3822b725ae77Skettenis is the width in bytes.
3823e93f7393Sniklas
3824b725ae77Skettenis Fortran programs appear to use this for complex types also. To
3825b725ae77Skettenis distinguish between floats and complex, g77 (and others?) seem
3826b725ae77Skettenis to use self-subranges for the complexes, and subranges of int for
3827b725ae77Skettenis the floats.
3828e93f7393Sniklas
3829b725ae77Skettenis Also note that for complexes, g77 sets n2 to the size of one of
3830b725ae77Skettenis the member floats, not the whole complex beast. My guess is that
3831b725ae77Skettenis this was to work well with pre-COMPLEX versions of gdb. */
3832e93f7393Sniklas
3833e93f7393Sniklas if (n3 == 0 && n2 > 0)
3834e93f7393Sniklas {
3835b725ae77Skettenis struct type *float_type
3836b725ae77Skettenis = init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile);
3837b725ae77Skettenis
3838b725ae77Skettenis if (self_subrange)
3839b725ae77Skettenis {
3840b725ae77Skettenis struct type *complex_type =
3841b725ae77Skettenis init_type (TYPE_CODE_COMPLEX, 2 * n2, 0, NULL, objfile);
3842b725ae77Skettenis TYPE_TARGET_TYPE (complex_type) = float_type;
3843b725ae77Skettenis return complex_type;
3844b725ae77Skettenis }
3845b725ae77Skettenis else
3846b725ae77Skettenis return float_type;
3847e93f7393Sniklas }
3848e93f7393Sniklas
3849e93f7393Sniklas /* If the upper bound is -1, it must really be an unsigned int. */
3850e93f7393Sniklas
3851e93f7393Sniklas else if (n2 == 0 && n3 == -1)
3852e93f7393Sniklas {
3853e93f7393Sniklas /* It is unsigned int or unsigned long. */
3854e93f7393Sniklas /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
3855e93f7393Sniklas compatibility hack. */
3856e93f7393Sniklas return init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3857e93f7393Sniklas TYPE_FLAG_UNSIGNED, NULL, objfile);
3858e93f7393Sniklas }
3859e93f7393Sniklas
3860e93f7393Sniklas /* Special case: char is defined (Who knows why) as a subrange of
3861e93f7393Sniklas itself with range 0-127. */
3862e93f7393Sniklas else if (self_subrange && n2 == 0 && n3 == 127)
3863b725ae77Skettenis return init_type (TYPE_CODE_INT, 1, TYPE_FLAG_NOSIGN, NULL, objfile);
3864e93f7393Sniklas
3865e93f7393Sniklas /* We used to do this only for subrange of self or subrange of int. */
3866e93f7393Sniklas else if (n2 == 0)
3867e93f7393Sniklas {
3868b725ae77Skettenis /* -1 is used for the upper bound of (4 byte) "unsigned int" and
3869b725ae77Skettenis "unsigned long", and we already checked for that,
3870b725ae77Skettenis so don't need to test for it here. */
3871b725ae77Skettenis
3872e93f7393Sniklas if (n3 < 0)
3873e93f7393Sniklas /* n3 actually gives the size. */
3874e93f7393Sniklas return init_type (TYPE_CODE_INT, -n3, TYPE_FLAG_UNSIGNED,
3875e93f7393Sniklas NULL, objfile);
3876e93f7393Sniklas
3877b725ae77Skettenis /* Is n3 == 2**(8n)-1 for some integer n? Then it's an
3878b725ae77Skettenis unsigned n-byte integer. But do require n to be a power of
3879b725ae77Skettenis two; we don't want 3- and 5-byte integers flying around. */
3880b725ae77Skettenis {
3881b725ae77Skettenis int bytes;
3882b725ae77Skettenis unsigned long bits;
3883b725ae77Skettenis
3884b725ae77Skettenis bits = n3;
3885b725ae77Skettenis for (bytes = 0; (bits & 0xff) == 0xff; bytes++)
3886b725ae77Skettenis bits >>= 8;
3887b725ae77Skettenis if (bits == 0
3888b725ae77Skettenis && ((bytes - 1) & bytes) == 0) /* "bytes is a power of two" */
3889b725ae77Skettenis return init_type (TYPE_CODE_INT, bytes, TYPE_FLAG_UNSIGNED, NULL,
3890b725ae77Skettenis objfile);
3891b725ae77Skettenis }
3892e93f7393Sniklas }
3893e93f7393Sniklas /* I think this is for Convex "long long". Since I don't know whether
3894e93f7393Sniklas Convex sets self_subrange, I also accept that particular size regardless
3895e93f7393Sniklas of self_subrange. */
3896e93f7393Sniklas else if (n3 == 0 && n2 < 0
3897e93f7393Sniklas && (self_subrange
3898e93f7393Sniklas || n2 == -TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT))
3899e93f7393Sniklas return init_type (TYPE_CODE_INT, -n2, 0, NULL, objfile);
3900e93f7393Sniklas else if (n2 == -n3 - 1)
3901e93f7393Sniklas {
3902e93f7393Sniklas if (n3 == 0x7f)
3903e93f7393Sniklas return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
3904e93f7393Sniklas if (n3 == 0x7fff)
3905e93f7393Sniklas return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile);
3906e93f7393Sniklas if (n3 == 0x7fffffff)
3907e93f7393Sniklas return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile);
3908e93f7393Sniklas }
3909e93f7393Sniklas
3910e93f7393Sniklas /* We have a real range type on our hands. Allocate space and
3911e93f7393Sniklas return a real pointer. */
3912e93f7393Sniklas handle_true_range:
3913e93f7393Sniklas
3914e93f7393Sniklas if (self_subrange)
3915e93f7393Sniklas index_type = builtin_type_int;
3916e93f7393Sniklas else
3917e93f7393Sniklas index_type = *dbx_lookup_type (rangenums);
3918e93f7393Sniklas if (index_type == NULL)
3919e93f7393Sniklas {
3920e93f7393Sniklas /* Does this actually ever happen? Is that why we are worrying
3921e93f7393Sniklas about dealing with it rather than just calling error_type? */
3922e93f7393Sniklas
3923e93f7393Sniklas static struct type *range_type_index;
3924e93f7393Sniklas
3925b725ae77Skettenis complaint (&symfile_complaints,
3926b725ae77Skettenis "base type %d of range type is not defined", rangenums[1]);
3927e93f7393Sniklas if (range_type_index == NULL)
3928e93f7393Sniklas range_type_index =
3929e93f7393Sniklas init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3930e93f7393Sniklas 0, "range type index type", NULL);
3931e93f7393Sniklas index_type = range_type_index;
3932e93f7393Sniklas }
3933e93f7393Sniklas
3934e93f7393Sniklas result_type = create_range_type ((struct type *) NULL, index_type, n2, n3);
3935e93f7393Sniklas return (result_type);
3936e93f7393Sniklas }
3937e93f7393Sniklas
3938e93f7393Sniklas /* Read in an argument list. This is a list of types, separated by commas
3939e93f7393Sniklas and terminated with END. Return the list of types read in, or (struct type
3940e93f7393Sniklas **)-1 if there is an error. */
3941e93f7393Sniklas
3942b725ae77Skettenis static struct field *
read_args(char ** pp,int end,struct objfile * objfile,int * nargsp,int * varargsp)3943b725ae77Skettenis read_args (char **pp, int end, struct objfile *objfile, int *nargsp,
3944b725ae77Skettenis int *varargsp)
3945e93f7393Sniklas {
3946e93f7393Sniklas /* FIXME! Remove this arbitrary limit! */
3947b725ae77Skettenis struct type *types[1024]; /* allow for fns of 1023 parameters */
3948b725ae77Skettenis int n = 0, i;
3949b725ae77Skettenis struct field *rval;
3950e93f7393Sniklas
3951e93f7393Sniklas while (**pp != end)
3952e93f7393Sniklas {
3953e93f7393Sniklas if (**pp != ',')
3954e93f7393Sniklas /* Invalid argument list: no ','. */
3955b725ae77Skettenis return (struct field *) -1;
3956e93f7393Sniklas (*pp)++;
3957e93f7393Sniklas STABS_CONTINUE (pp, objfile);
3958e93f7393Sniklas types[n++] = read_type (pp, objfile);
3959e93f7393Sniklas }
3960e93f7393Sniklas (*pp)++; /* get past `end' (the ':' character) */
3961e93f7393Sniklas
3962b725ae77Skettenis if (TYPE_CODE (types[n - 1]) != TYPE_CODE_VOID)
3963b725ae77Skettenis *varargsp = 1;
3964e93f7393Sniklas else
3965e93f7393Sniklas {
3966b725ae77Skettenis n--;
3967b725ae77Skettenis *varargsp = 0;
3968e93f7393Sniklas }
3969b725ae77Skettenis
3970b725ae77Skettenis rval = (struct field *) xmalloc (n * sizeof (struct field));
3971b725ae77Skettenis memset (rval, 0, n * sizeof (struct field));
3972b725ae77Skettenis for (i = 0; i < n; i++)
3973b725ae77Skettenis rval[i].type = types[i];
3974b725ae77Skettenis *nargsp = n;
3975e93f7393Sniklas return rval;
3976e93f7393Sniklas }
3977e93f7393Sniklas
3978e93f7393Sniklas /* Common block handling. */
3979e93f7393Sniklas
3980e93f7393Sniklas /* List of symbols declared since the last BCOMM. This list is a tail
3981e93f7393Sniklas of local_symbols. When ECOMM is seen, the symbols on the list
3982e93f7393Sniklas are noted so their proper addresses can be filled in later,
3983e93f7393Sniklas using the common block base address gotten from the assembler
3984e93f7393Sniklas stabs. */
3985e93f7393Sniklas
3986e93f7393Sniklas static struct pending *common_block;
3987e93f7393Sniklas static int common_block_i;
3988e93f7393Sniklas
3989e93f7393Sniklas /* Name of the current common block. We get it from the BCOMM instead of the
3990e93f7393Sniklas ECOMM to match IBM documentation (even though IBM puts the name both places
3991e93f7393Sniklas like everyone else). */
3992e93f7393Sniklas static char *common_block_name;
3993e93f7393Sniklas
3994e93f7393Sniklas /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
3995e93f7393Sniklas to remain after this function returns. */
3996e93f7393Sniklas
3997e93f7393Sniklas void
common_block_start(char * name,struct objfile * objfile)3998b725ae77Skettenis common_block_start (char *name, struct objfile *objfile)
3999e93f7393Sniklas {
4000e93f7393Sniklas if (common_block_name != NULL)
4001e93f7393Sniklas {
4002b725ae77Skettenis complaint (&symfile_complaints,
4003b725ae77Skettenis "Invalid symbol data: common block within common block");
4004e93f7393Sniklas }
4005e93f7393Sniklas common_block = local_symbols;
4006e93f7393Sniklas common_block_i = local_symbols ? local_symbols->nsyms : 0;
4007e93f7393Sniklas common_block_name = obsavestring (name, strlen (name),
4008b725ae77Skettenis &objfile->objfile_obstack);
4009e93f7393Sniklas }
4010e93f7393Sniklas
4011e93f7393Sniklas /* Process a N_ECOMM symbol. */
4012e93f7393Sniklas
4013e93f7393Sniklas void
common_block_end(struct objfile * objfile)4014b725ae77Skettenis common_block_end (struct objfile *objfile)
4015e93f7393Sniklas {
4016e93f7393Sniklas /* Symbols declared since the BCOMM are to have the common block
4017e93f7393Sniklas start address added in when we know it. common_block and
4018e93f7393Sniklas common_block_i point to the first symbol after the BCOMM in
4019e93f7393Sniklas the local_symbols list; copy the list and hang it off the
4020e93f7393Sniklas symbol for the common block name for later fixup. */
4021e93f7393Sniklas int i;
4022e93f7393Sniklas struct symbol *sym;
4023e93f7393Sniklas struct pending *new = 0;
4024e93f7393Sniklas struct pending *next;
4025e93f7393Sniklas int j;
4026e93f7393Sniklas
4027e93f7393Sniklas if (common_block_name == NULL)
4028e93f7393Sniklas {
4029b725ae77Skettenis complaint (&symfile_complaints, "ECOMM symbol unmatched by BCOMM");
4030e93f7393Sniklas return;
4031e93f7393Sniklas }
4032e93f7393Sniklas
4033e93f7393Sniklas sym = (struct symbol *)
4034b725ae77Skettenis obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol));
4035e93f7393Sniklas memset (sym, 0, sizeof (struct symbol));
4036b725ae77Skettenis /* Note: common_block_name already saved on objfile_obstack */
4037b725ae77Skettenis DEPRECATED_SYMBOL_NAME (sym) = common_block_name;
4038e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_BLOCK;
4039e93f7393Sniklas
4040e93f7393Sniklas /* Now we copy all the symbols which have been defined since the BCOMM. */
4041e93f7393Sniklas
4042e93f7393Sniklas /* Copy all the struct pendings before common_block. */
4043e93f7393Sniklas for (next = local_symbols;
4044e93f7393Sniklas next != NULL && next != common_block;
4045e93f7393Sniklas next = next->next)
4046e93f7393Sniklas {
4047e93f7393Sniklas for (j = 0; j < next->nsyms; j++)
4048e93f7393Sniklas add_symbol_to_list (next->symbol[j], &new);
4049e93f7393Sniklas }
4050e93f7393Sniklas
4051e93f7393Sniklas /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
4052e93f7393Sniklas NULL, it means copy all the local symbols (which we already did
4053e93f7393Sniklas above). */
4054e93f7393Sniklas
4055e93f7393Sniklas if (common_block != NULL)
4056e93f7393Sniklas for (j = common_block_i; j < common_block->nsyms; j++)
4057e93f7393Sniklas add_symbol_to_list (common_block->symbol[j], &new);
4058e93f7393Sniklas
4059e93f7393Sniklas SYMBOL_TYPE (sym) = (struct type *) new;
4060e93f7393Sniklas
4061e93f7393Sniklas /* Should we be putting local_symbols back to what it was?
4062e93f7393Sniklas Does it matter? */
4063e93f7393Sniklas
4064b725ae77Skettenis i = hashname (DEPRECATED_SYMBOL_NAME (sym));
4065e93f7393Sniklas SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
4066e93f7393Sniklas global_sym_chain[i] = sym;
4067e93f7393Sniklas common_block_name = NULL;
4068e93f7393Sniklas }
4069e93f7393Sniklas
4070e93f7393Sniklas /* Add a common block's start address to the offset of each symbol
4071e93f7393Sniklas declared to be in it (by being between a BCOMM/ECOMM pair that uses
4072e93f7393Sniklas the common block name). */
4073e93f7393Sniklas
4074e93f7393Sniklas static void
fix_common_block(struct symbol * sym,int valu)4075b725ae77Skettenis fix_common_block (struct symbol *sym, int valu)
4076e93f7393Sniklas {
4077e93f7393Sniklas struct pending *next = (struct pending *) SYMBOL_TYPE (sym);
4078e93f7393Sniklas for (; next; next = next->next)
4079e93f7393Sniklas {
4080b725ae77Skettenis int j;
4081e93f7393Sniklas for (j = next->nsyms - 1; j >= 0; j--)
4082e93f7393Sniklas SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
4083e93f7393Sniklas }
4084e93f7393Sniklas }
4085e93f7393Sniklas
4086b725ae77Skettenis
4087b725ae77Skettenis
4088e93f7393Sniklas /* What about types defined as forward references inside of a small lexical
4089e93f7393Sniklas scope? */
4090e93f7393Sniklas /* Add a type to the list of undefined types to be checked through
4091e93f7393Sniklas once this file has been read in. */
4092e93f7393Sniklas
4093b725ae77Skettenis static void
add_undefined_type(struct type * type)4094b725ae77Skettenis add_undefined_type (struct type *type)
4095e93f7393Sniklas {
4096e93f7393Sniklas if (undef_types_length == undef_types_allocated)
4097e93f7393Sniklas {
4098e93f7393Sniklas undef_types_allocated *= 2;
4099e93f7393Sniklas undef_types = (struct type **)
4100e93f7393Sniklas xrealloc ((char *) undef_types,
4101e93f7393Sniklas undef_types_allocated * sizeof (struct type *));
4102e93f7393Sniklas }
4103e93f7393Sniklas undef_types[undef_types_length++] = type;
4104e93f7393Sniklas }
4105e93f7393Sniklas
4106e93f7393Sniklas /* Go through each undefined type, see if it's still undefined, and fix it
4107e93f7393Sniklas up if possible. We have two kinds of undefined types:
4108e93f7393Sniklas
4109e93f7393Sniklas TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
4110e93f7393Sniklas Fix: update array length using the element bounds
4111e93f7393Sniklas and the target type's length.
4112e93f7393Sniklas TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
4113e93f7393Sniklas yet defined at the time a pointer to it was made.
4114e93f7393Sniklas Fix: Do a full lookup on the struct/union tag. */
4115e93f7393Sniklas void
cleanup_undefined_types(void)4116b725ae77Skettenis cleanup_undefined_types (void)
4117e93f7393Sniklas {
4118e93f7393Sniklas struct type **type;
4119e93f7393Sniklas
4120e93f7393Sniklas for (type = undef_types; type < undef_types + undef_types_length; type++)
4121e93f7393Sniklas {
4122e93f7393Sniklas switch (TYPE_CODE (*type))
4123e93f7393Sniklas {
4124e93f7393Sniklas
4125e93f7393Sniklas case TYPE_CODE_STRUCT:
4126e93f7393Sniklas case TYPE_CODE_UNION:
4127e93f7393Sniklas case TYPE_CODE_ENUM:
4128e93f7393Sniklas {
4129e93f7393Sniklas /* Check if it has been defined since. Need to do this here
4130e93f7393Sniklas as well as in check_typedef to deal with the (legitimate in
4131e93f7393Sniklas C though not C++) case of several types with the same name
4132e93f7393Sniklas in different source files. */
4133b725ae77Skettenis if (TYPE_STUB (*type))
4134e93f7393Sniklas {
4135e93f7393Sniklas struct pending *ppt;
4136e93f7393Sniklas int i;
4137e93f7393Sniklas /* Name of the type, without "struct" or "union" */
4138e93f7393Sniklas char *typename = TYPE_TAG_NAME (*type);
4139e93f7393Sniklas
4140e93f7393Sniklas if (typename == NULL)
4141e93f7393Sniklas {
4142b725ae77Skettenis complaint (&symfile_complaints, "need a type name");
4143e93f7393Sniklas break;
4144e93f7393Sniklas }
4145e93f7393Sniklas for (ppt = file_symbols; ppt; ppt = ppt->next)
4146e93f7393Sniklas {
4147e93f7393Sniklas for (i = 0; i < ppt->nsyms; i++)
4148e93f7393Sniklas {
4149e93f7393Sniklas struct symbol *sym = ppt->symbol[i];
4150e93f7393Sniklas
4151e93f7393Sniklas if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
4152b725ae77Skettenis && SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN
4153e93f7393Sniklas && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
4154e93f7393Sniklas TYPE_CODE (*type))
4155b725ae77Skettenis && strcmp (DEPRECATED_SYMBOL_NAME (sym), typename) == 0)
4156b725ae77Skettenis replace_type (*type, SYMBOL_TYPE (sym));
4157e93f7393Sniklas }
4158e93f7393Sniklas }
4159e93f7393Sniklas }
4160e93f7393Sniklas }
4161e93f7393Sniklas break;
4162e93f7393Sniklas
4163e93f7393Sniklas default:
4164e93f7393Sniklas {
4165b725ae77Skettenis complaint (&symfile_complaints,
4166b725ae77Skettenis "forward-referenced types left unresolved, "
4167b725ae77Skettenis "type code %d.",
4168b725ae77Skettenis TYPE_CODE (*type));
4169e93f7393Sniklas }
4170e93f7393Sniklas break;
4171e93f7393Sniklas }
4172e93f7393Sniklas }
4173e93f7393Sniklas
4174e93f7393Sniklas undef_types_length = 0;
4175e93f7393Sniklas }
4176e93f7393Sniklas
4177e93f7393Sniklas /* Scan through all of the global symbols defined in the object file,
4178e93f7393Sniklas assigning values to the debugging symbols that need to be assigned
4179e93f7393Sniklas to. Get these symbols from the minimal symbol table. */
4180e93f7393Sniklas
4181e93f7393Sniklas void
scan_file_globals(struct objfile * objfile)4182b725ae77Skettenis scan_file_globals (struct objfile *objfile)
4183e93f7393Sniklas {
4184e93f7393Sniklas int hash;
4185e93f7393Sniklas struct minimal_symbol *msymbol;
4186e93f7393Sniklas struct symbol *sym, *prev;
4187e93f7393Sniklas struct objfile *resolve_objfile;
4188e93f7393Sniklas
4189e93f7393Sniklas /* SVR4 based linkers copy referenced global symbols from shared
4190e93f7393Sniklas libraries to the main executable.
4191e93f7393Sniklas If we are scanning the symbols for a shared library, try to resolve
4192e93f7393Sniklas them from the minimal symbols of the main executable first. */
4193e93f7393Sniklas
4194e93f7393Sniklas if (symfile_objfile && objfile != symfile_objfile)
4195e93f7393Sniklas resolve_objfile = symfile_objfile;
4196e93f7393Sniklas else
4197e93f7393Sniklas resolve_objfile = objfile;
4198e93f7393Sniklas
4199e93f7393Sniklas while (1)
4200e93f7393Sniklas {
4201e93f7393Sniklas /* Avoid expensive loop through all minimal symbols if there are
4202e93f7393Sniklas no unresolved symbols. */
4203e93f7393Sniklas for (hash = 0; hash < HASHSIZE; hash++)
4204e93f7393Sniklas {
4205e93f7393Sniklas if (global_sym_chain[hash])
4206e93f7393Sniklas break;
4207e93f7393Sniklas }
4208e93f7393Sniklas if (hash >= HASHSIZE)
4209e93f7393Sniklas return;
4210e93f7393Sniklas
4211e93f7393Sniklas for (msymbol = resolve_objfile->msymbols;
4212b725ae77Skettenis msymbol && DEPRECATED_SYMBOL_NAME (msymbol) != NULL;
4213e93f7393Sniklas msymbol++)
4214e93f7393Sniklas {
4215e93f7393Sniklas QUIT;
4216e93f7393Sniklas
4217e93f7393Sniklas /* Skip static symbols. */
4218e93f7393Sniklas switch (MSYMBOL_TYPE (msymbol))
4219e93f7393Sniklas {
4220e93f7393Sniklas case mst_file_text:
4221e93f7393Sniklas case mst_file_data:
4222e93f7393Sniklas case mst_file_bss:
4223e93f7393Sniklas continue;
4224e93f7393Sniklas default:
4225e93f7393Sniklas break;
4226e93f7393Sniklas }
4227e93f7393Sniklas
4228e93f7393Sniklas prev = NULL;
4229e93f7393Sniklas
4230e93f7393Sniklas /* Get the hash index and check all the symbols
4231e93f7393Sniklas under that hash index. */
4232e93f7393Sniklas
4233b725ae77Skettenis hash = hashname (DEPRECATED_SYMBOL_NAME (msymbol));
4234e93f7393Sniklas
4235e93f7393Sniklas for (sym = global_sym_chain[hash]; sym;)
4236e93f7393Sniklas {
4237b725ae77Skettenis if (DEPRECATED_SYMBOL_NAME (msymbol)[0] == DEPRECATED_SYMBOL_NAME (sym)[0] &&
4238b725ae77Skettenis strcmp (DEPRECATED_SYMBOL_NAME (msymbol) + 1, DEPRECATED_SYMBOL_NAME (sym) + 1) == 0)
4239e93f7393Sniklas {
4240e93f7393Sniklas /* Splice this symbol out of the hash chain and
4241e93f7393Sniklas assign the value we have to it. */
4242e93f7393Sniklas if (prev)
4243e93f7393Sniklas {
4244e93f7393Sniklas SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
4245e93f7393Sniklas }
4246e93f7393Sniklas else
4247e93f7393Sniklas {
4248e93f7393Sniklas global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
4249e93f7393Sniklas }
4250e93f7393Sniklas
4251e93f7393Sniklas /* Check to see whether we need to fix up a common block. */
4252e93f7393Sniklas /* Note: this code might be executed several times for
4253e93f7393Sniklas the same symbol if there are multiple references. */
4254b725ae77Skettenis if (sym)
4255b725ae77Skettenis {
4256e93f7393Sniklas if (SYMBOL_CLASS (sym) == LOC_BLOCK)
4257e93f7393Sniklas {
4258b725ae77Skettenis fix_common_block (sym,
4259b725ae77Skettenis SYMBOL_VALUE_ADDRESS (msymbol));
4260e93f7393Sniklas }
4261e93f7393Sniklas else
4262e93f7393Sniklas {
4263e93f7393Sniklas SYMBOL_VALUE_ADDRESS (sym)
4264e93f7393Sniklas = SYMBOL_VALUE_ADDRESS (msymbol);
4265e93f7393Sniklas }
4266e93f7393Sniklas SYMBOL_SECTION (sym) = SYMBOL_SECTION (msymbol);
4267b725ae77Skettenis }
4268e93f7393Sniklas
4269e93f7393Sniklas if (prev)
4270e93f7393Sniklas {
4271e93f7393Sniklas sym = SYMBOL_VALUE_CHAIN (prev);
4272e93f7393Sniklas }
4273e93f7393Sniklas else
4274e93f7393Sniklas {
4275e93f7393Sniklas sym = global_sym_chain[hash];
4276e93f7393Sniklas }
4277e93f7393Sniklas }
4278e93f7393Sniklas else
4279e93f7393Sniklas {
4280e93f7393Sniklas prev = sym;
4281e93f7393Sniklas sym = SYMBOL_VALUE_CHAIN (sym);
4282e93f7393Sniklas }
4283e93f7393Sniklas }
4284e93f7393Sniklas }
4285e93f7393Sniklas if (resolve_objfile == objfile)
4286e93f7393Sniklas break;
4287e93f7393Sniklas resolve_objfile = objfile;
4288e93f7393Sniklas }
4289e93f7393Sniklas
4290e93f7393Sniklas /* Change the storage class of any remaining unresolved globals to
4291e93f7393Sniklas LOC_UNRESOLVED and remove them from the chain. */
4292e93f7393Sniklas for (hash = 0; hash < HASHSIZE; hash++)
4293e93f7393Sniklas {
4294e93f7393Sniklas sym = global_sym_chain[hash];
4295e93f7393Sniklas while (sym)
4296e93f7393Sniklas {
4297e93f7393Sniklas prev = sym;
4298e93f7393Sniklas sym = SYMBOL_VALUE_CHAIN (sym);
4299e93f7393Sniklas
4300e93f7393Sniklas /* Change the symbol address from the misleading chain value
4301e93f7393Sniklas to address zero. */
4302e93f7393Sniklas SYMBOL_VALUE_ADDRESS (prev) = 0;
4303e93f7393Sniklas
4304e93f7393Sniklas /* Complain about unresolved common block symbols. */
4305e93f7393Sniklas if (SYMBOL_CLASS (prev) == LOC_STATIC)
4306e93f7393Sniklas SYMBOL_CLASS (prev) = LOC_UNRESOLVED;
4307e93f7393Sniklas else
4308b725ae77Skettenis complaint (&symfile_complaints,
4309b725ae77Skettenis "%s: common block `%s' from global_sym_chain unresolved",
4310b725ae77Skettenis objfile->name, DEPRECATED_SYMBOL_NAME (prev));
4311e93f7393Sniklas }
4312e93f7393Sniklas }
4313e93f7393Sniklas memset (global_sym_chain, 0, sizeof (global_sym_chain));
4314e93f7393Sniklas }
4315e93f7393Sniklas
4316e93f7393Sniklas /* Initialize anything that needs initializing when starting to read
4317e93f7393Sniklas a fresh piece of a symbol file, e.g. reading in the stuff corresponding
4318e93f7393Sniklas to a psymtab. */
4319e93f7393Sniklas
4320e93f7393Sniklas void
stabsread_init(void)4321b725ae77Skettenis stabsread_init (void)
4322e93f7393Sniklas {
4323e93f7393Sniklas }
4324e93f7393Sniklas
4325e93f7393Sniklas /* Initialize anything that needs initializing when a completely new
4326e93f7393Sniklas symbol file is specified (not just adding some symbols from another
4327e93f7393Sniklas file, e.g. a shared library). */
4328e93f7393Sniklas
4329e93f7393Sniklas void
stabsread_new_init(void)4330b725ae77Skettenis stabsread_new_init (void)
4331e93f7393Sniklas {
4332e93f7393Sniklas /* Empty the hash table of global syms looking for values. */
4333e93f7393Sniklas memset (global_sym_chain, 0, sizeof (global_sym_chain));
4334e93f7393Sniklas }
4335e93f7393Sniklas
4336e93f7393Sniklas /* Initialize anything that needs initializing at the same time as
4337e93f7393Sniklas start_symtab() is called. */
4338e93f7393Sniklas
4339b725ae77Skettenis void
start_stabs(void)4340b725ae77Skettenis start_stabs (void)
4341e93f7393Sniklas {
4342e93f7393Sniklas global_stabs = NULL; /* AIX COFF */
4343e93f7393Sniklas /* Leave FILENUM of 0 free for builtin types and this file's types. */
4344e93f7393Sniklas n_this_object_header_files = 1;
4345e93f7393Sniklas type_vector_length = 0;
4346e93f7393Sniklas type_vector = (struct type **) 0;
4347e93f7393Sniklas
4348e93f7393Sniklas /* FIXME: If common_block_name is not already NULL, we should complain(). */
4349e93f7393Sniklas common_block_name = NULL;
4350e93f7393Sniklas }
4351e93f7393Sniklas
4352e93f7393Sniklas /* Call after end_symtab() */
4353e93f7393Sniklas
4354b725ae77Skettenis void
end_stabs(void)4355b725ae77Skettenis end_stabs (void)
4356e93f7393Sniklas {
4357e93f7393Sniklas if (type_vector)
4358e93f7393Sniklas {
4359b725ae77Skettenis xfree (type_vector);
4360e93f7393Sniklas }
4361e93f7393Sniklas type_vector = 0;
4362e93f7393Sniklas type_vector_length = 0;
4363e93f7393Sniklas previous_stab_code = 0;
4364e93f7393Sniklas }
4365e93f7393Sniklas
4366e93f7393Sniklas void
finish_global_stabs(struct objfile * objfile)4367b725ae77Skettenis finish_global_stabs (struct objfile *objfile)
4368e93f7393Sniklas {
4369e93f7393Sniklas if (global_stabs)
4370e93f7393Sniklas {
4371e93f7393Sniklas patch_block_stabs (global_symbols, global_stabs, objfile);
4372b725ae77Skettenis xfree (global_stabs);
4373e93f7393Sniklas global_stabs = NULL;
4374e93f7393Sniklas }
4375e93f7393Sniklas }
4376e93f7393Sniklas
4377b725ae77Skettenis /* Find the end of the name, delimited by a ':', but don't match
4378b725ae77Skettenis ObjC symbols which look like -[Foo bar::]:bla. */
4379b725ae77Skettenis static char *
find_name_end(char * name)4380b725ae77Skettenis find_name_end (char *name)
4381b725ae77Skettenis {
4382b725ae77Skettenis char *s = name;
4383b725ae77Skettenis if (s[0] == '-' || *s == '+')
4384b725ae77Skettenis {
4385b725ae77Skettenis /* Must be an ObjC method symbol. */
4386b725ae77Skettenis if (s[1] != '[')
4387b725ae77Skettenis {
4388b725ae77Skettenis error ("invalid symbol name \"%s\"", name);
4389b725ae77Skettenis }
4390b725ae77Skettenis s = strchr (s, ']');
4391b725ae77Skettenis if (s == NULL)
4392b725ae77Skettenis {
4393b725ae77Skettenis error ("invalid symbol name \"%s\"", name);
4394b725ae77Skettenis }
4395b725ae77Skettenis return strchr (s, ':');
4396b725ae77Skettenis }
4397b725ae77Skettenis else
4398b725ae77Skettenis {
4399b725ae77Skettenis return strchr (s, ':');
4400b725ae77Skettenis }
4401b725ae77Skettenis }
4402b725ae77Skettenis
4403e93f7393Sniklas /* Initializer for this module */
4404e93f7393Sniklas
4405e93f7393Sniklas void
_initialize_stabsread(void)4406b725ae77Skettenis _initialize_stabsread (void)
4407e93f7393Sniklas {
4408e93f7393Sniklas undef_types_allocated = 20;
4409e93f7393Sniklas undef_types_length = 0;
4410e93f7393Sniklas undef_types = (struct type **)
4411e93f7393Sniklas xmalloc (undef_types_allocated * sizeof (struct type *));
4412e93f7393Sniklas }
4413