1a9fa9459Szrj /* stabs.c -- Parse stabs debugging information
2a9fa9459Szrj Copyright (C) 1995-2016 Free Software Foundation, Inc.
3a9fa9459Szrj Written by Ian Lance Taylor <ian@cygnus.com>.
4a9fa9459Szrj
5a9fa9459Szrj This file is part of GNU Binutils.
6a9fa9459Szrj
7a9fa9459Szrj This program is free software; you can redistribute it and/or modify
8a9fa9459Szrj it under the terms of the GNU General Public License as published by
9a9fa9459Szrj the Free Software Foundation; either version 3 of the License, or
10a9fa9459Szrj (at your option) any later version.
11a9fa9459Szrj
12a9fa9459Szrj This program is distributed in the hope that it will be useful,
13a9fa9459Szrj but WITHOUT ANY WARRANTY; without even the implied warranty of
14a9fa9459Szrj MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15a9fa9459Szrj GNU General Public License for more details.
16a9fa9459Szrj
17a9fa9459Szrj You should have received a copy of the GNU General Public License
18a9fa9459Szrj along with this program; if not, write to the Free Software
19a9fa9459Szrj Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
20a9fa9459Szrj 02110-1301, USA. */
21a9fa9459Szrj
22a9fa9459Szrj /* This file contains code which parses stabs debugging information.
23a9fa9459Szrj The organization of this code is based on the gdb stabs reading
24a9fa9459Szrj code. The job it does is somewhat different, because it is not
25a9fa9459Szrj trying to identify the correct address for anything. */
26a9fa9459Szrj
27a9fa9459Szrj #include "sysdep.h"
28a9fa9459Szrj #include "bfd.h"
29a9fa9459Szrj #include "libiberty.h"
30a9fa9459Szrj #include "safe-ctype.h"
31a9fa9459Szrj #include "demangle.h"
32a9fa9459Szrj #include "debug.h"
33a9fa9459Szrj #include "budbg.h"
34a9fa9459Szrj #include "filenames.h"
35a9fa9459Szrj #include "aout/aout64.h"
36a9fa9459Szrj #include "aout/stab_gnu.h"
37a9fa9459Szrj
38a9fa9459Szrj /* The number of predefined XCOFF types. */
39a9fa9459Szrj
40a9fa9459Szrj #define XCOFF_TYPE_COUNT 34
41a9fa9459Szrj
42a9fa9459Szrj /* This structure is used as a handle so that the stab parsing doesn't
43a9fa9459Szrj need to use any static variables. */
44a9fa9459Szrj
45a9fa9459Szrj struct stab_handle
46a9fa9459Szrj {
47a9fa9459Szrj /* The BFD. */
48a9fa9459Szrj bfd *abfd;
49a9fa9459Szrj /* TRUE if this is stabs in sections. */
50a9fa9459Szrj bfd_boolean sections;
51a9fa9459Szrj /* The symbol table. */
52a9fa9459Szrj asymbol **syms;
53a9fa9459Szrj /* The number of symbols. */
54a9fa9459Szrj long symcount;
55a9fa9459Szrj /* The accumulated file name string. */
56a9fa9459Szrj char *so_string;
57a9fa9459Szrj /* The value of the last N_SO symbol. */
58a9fa9459Szrj bfd_vma so_value;
59a9fa9459Szrj /* The value of the start of the file, so that we can handle file
60a9fa9459Szrj relative N_LBRAC and N_RBRAC symbols. */
61a9fa9459Szrj bfd_vma file_start_offset;
62a9fa9459Szrj /* The offset of the start of the function, so that we can handle
63a9fa9459Szrj function relative N_LBRAC and N_RBRAC symbols. */
64a9fa9459Szrj bfd_vma function_start_offset;
65a9fa9459Szrj /* The version number of gcc which compiled the current compilation
66a9fa9459Szrj unit, 0 if not compiled by gcc. */
67a9fa9459Szrj int gcc_compiled;
68a9fa9459Szrj /* Whether an N_OPT symbol was seen that was not generated by gcc,
69a9fa9459Szrj so that we can detect the SunPRO compiler. */
70a9fa9459Szrj bfd_boolean n_opt_found;
71a9fa9459Szrj /* The main file name. */
72a9fa9459Szrj char *main_filename;
73a9fa9459Szrj /* A stack of unfinished N_BINCL files. */
74a9fa9459Szrj struct bincl_file *bincl_stack;
75a9fa9459Szrj /* A list of finished N_BINCL files. */
76a9fa9459Szrj struct bincl_file *bincl_list;
77a9fa9459Szrj /* Whether we are inside a function or not. */
78a9fa9459Szrj bfd_boolean within_function;
79a9fa9459Szrj /* The address of the end of the function, used if we have seen an
80a9fa9459Szrj N_FUN symbol while in a function. This is -1 if we have not seen
81a9fa9459Szrj an N_FUN (the normal case). */
82a9fa9459Szrj bfd_vma function_end;
83a9fa9459Szrj /* The depth of block nesting. */
84a9fa9459Szrj int block_depth;
85a9fa9459Szrj /* List of pending variable definitions. */
86a9fa9459Szrj struct stab_pending_var *pending;
87a9fa9459Szrj /* Number of files for which we have types. */
88a9fa9459Szrj unsigned int files;
89a9fa9459Szrj /* Lists of types per file. */
90a9fa9459Szrj struct stab_types **file_types;
91a9fa9459Szrj /* Predefined XCOFF types. */
92a9fa9459Szrj debug_type xcoff_types[XCOFF_TYPE_COUNT];
93a9fa9459Szrj /* Undefined tags. */
94a9fa9459Szrj struct stab_tag *tags;
95a9fa9459Szrj /* Set by parse_stab_type if it sees a structure defined as a cross
96a9fa9459Szrj reference to itself. Reset by parse_stab_type otherwise. */
97a9fa9459Szrj bfd_boolean self_crossref;
98a9fa9459Szrj };
99a9fa9459Szrj
100a9fa9459Szrj /* A list of these structures is used to hold pending variable
101a9fa9459Szrj definitions seen before the N_LBRAC of a block. */
102a9fa9459Szrj
103a9fa9459Szrj struct stab_pending_var
104a9fa9459Szrj {
105a9fa9459Szrj /* Next pending variable definition. */
106a9fa9459Szrj struct stab_pending_var *next;
107a9fa9459Szrj /* Name. */
108a9fa9459Szrj const char *name;
109a9fa9459Szrj /* Type. */
110a9fa9459Szrj debug_type type;
111a9fa9459Szrj /* Kind. */
112a9fa9459Szrj enum debug_var_kind kind;
113a9fa9459Szrj /* Value. */
114a9fa9459Szrj bfd_vma val;
115a9fa9459Szrj };
116a9fa9459Szrj
117a9fa9459Szrj /* A list of these structures is used to hold the types for a single
118a9fa9459Szrj file. */
119a9fa9459Szrj
120a9fa9459Szrj struct stab_types
121a9fa9459Szrj {
122a9fa9459Szrj /* Next set of slots for this file. */
123a9fa9459Szrj struct stab_types *next;
124a9fa9459Szrj /* Types indexed by type number. */
125a9fa9459Szrj #define STAB_TYPES_SLOTS (16)
126a9fa9459Szrj debug_type types[STAB_TYPES_SLOTS];
127a9fa9459Szrj };
128a9fa9459Szrj
129a9fa9459Szrj /* We keep a list of undefined tags that we encounter, so that we can
130a9fa9459Szrj fill them in if the tag is later defined. */
131a9fa9459Szrj
132a9fa9459Szrj struct stab_tag
133a9fa9459Szrj {
134a9fa9459Szrj /* Next undefined tag. */
135a9fa9459Szrj struct stab_tag *next;
136a9fa9459Szrj /* Tag name. */
137a9fa9459Szrj const char *name;
138a9fa9459Szrj /* Type kind. */
139a9fa9459Szrj enum debug_type_kind kind;
140a9fa9459Szrj /* Slot to hold real type when we discover it. If we don't, we fill
141a9fa9459Szrj in an undefined tag type. */
142a9fa9459Szrj debug_type slot;
143a9fa9459Szrj /* Indirect type we have created to point at slot. */
144a9fa9459Szrj debug_type type;
145a9fa9459Szrj };
146a9fa9459Szrj
147a9fa9459Szrj static char *savestring (const char *, int);
148a9fa9459Szrj static bfd_vma parse_number (const char **, bfd_boolean *);
149a9fa9459Szrj static void bad_stab (const char *);
150a9fa9459Szrj static void warn_stab (const char *, const char *);
151a9fa9459Szrj static bfd_boolean parse_stab_string
152a9fa9459Szrj (void *, struct stab_handle *, int, int, bfd_vma, const char *);
153a9fa9459Szrj static debug_type parse_stab_type
154a9fa9459Szrj (void *, struct stab_handle *, const char *, const char **, debug_type **);
155a9fa9459Szrj static bfd_boolean parse_stab_type_number (const char **, int *);
156a9fa9459Szrj static debug_type parse_stab_range_type
157a9fa9459Szrj (void *, struct stab_handle *, const char *, const char **, const int *);
158a9fa9459Szrj static debug_type parse_stab_sun_builtin_type (void *, const char **);
159a9fa9459Szrj static debug_type parse_stab_sun_floating_type (void *, const char **);
160a9fa9459Szrj static debug_type parse_stab_enum_type (void *, const char **);
161a9fa9459Szrj static debug_type parse_stab_struct_type
162a9fa9459Szrj (void *, struct stab_handle *, const char *, const char **,
163a9fa9459Szrj bfd_boolean, const int *);
164a9fa9459Szrj static bfd_boolean parse_stab_baseclasses
165a9fa9459Szrj (void *, struct stab_handle *, const char **, debug_baseclass **);
166a9fa9459Szrj static bfd_boolean parse_stab_struct_fields
167a9fa9459Szrj (void *, struct stab_handle *, const char **, debug_field **, bfd_boolean *);
168a9fa9459Szrj static bfd_boolean parse_stab_cpp_abbrev
169a9fa9459Szrj (void *, struct stab_handle *, const char **, debug_field *);
170a9fa9459Szrj static bfd_boolean parse_stab_one_struct_field
171a9fa9459Szrj (void *, struct stab_handle *, const char **, const char *,
172a9fa9459Szrj debug_field *, bfd_boolean *);
173a9fa9459Szrj static bfd_boolean parse_stab_members
174a9fa9459Szrj (void *, struct stab_handle *, const char *, const char **, const int *,
175a9fa9459Szrj debug_method **);
176a9fa9459Szrj static debug_type parse_stab_argtypes
177a9fa9459Szrj (void *, struct stab_handle *, debug_type, const char *, const char *,
178a9fa9459Szrj debug_type, const char *, bfd_boolean, bfd_boolean, const char **);
179a9fa9459Szrj static bfd_boolean parse_stab_tilde_field
180a9fa9459Szrj (void *, struct stab_handle *, const char **, const int *, debug_type *,
181a9fa9459Szrj bfd_boolean *);
182a9fa9459Szrj static debug_type parse_stab_array_type
183a9fa9459Szrj (void *, struct stab_handle *, const char **, bfd_boolean);
184a9fa9459Szrj static void push_bincl (struct stab_handle *, const char *, bfd_vma);
185a9fa9459Szrj static const char *pop_bincl (struct stab_handle *);
186a9fa9459Szrj static bfd_boolean find_excl (struct stab_handle *, const char *, bfd_vma);
187a9fa9459Szrj static bfd_boolean stab_record_variable
188a9fa9459Szrj (void *, struct stab_handle *, const char *, debug_type,
189a9fa9459Szrj enum debug_var_kind, bfd_vma);
190a9fa9459Szrj static bfd_boolean stab_emit_pending_vars (void *, struct stab_handle *);
191a9fa9459Szrj static debug_type *stab_find_slot (struct stab_handle *, const int *);
192a9fa9459Szrj static debug_type stab_find_type (void *, struct stab_handle *, const int *);
193a9fa9459Szrj static bfd_boolean stab_record_type
194a9fa9459Szrj (void *, struct stab_handle *, const int *, debug_type);
195a9fa9459Szrj static debug_type stab_xcoff_builtin_type
196a9fa9459Szrj (void *, struct stab_handle *, int);
197a9fa9459Szrj static debug_type stab_find_tagged_type
198a9fa9459Szrj (void *, struct stab_handle *, const char *, int, enum debug_type_kind);
199a9fa9459Szrj static debug_type *stab_demangle_argtypes
200a9fa9459Szrj (void *, struct stab_handle *, const char *, bfd_boolean *, unsigned int);
201a9fa9459Szrj static debug_type *stab_demangle_v3_argtypes
202a9fa9459Szrj (void *, struct stab_handle *, const char *, bfd_boolean *);
203a9fa9459Szrj static debug_type *stab_demangle_v3_arglist
204a9fa9459Szrj (void *, struct stab_handle *, struct demangle_component *, bfd_boolean *);
205a9fa9459Szrj static debug_type stab_demangle_v3_arg
206a9fa9459Szrj (void *, struct stab_handle *, struct demangle_component *, debug_type,
207a9fa9459Szrj bfd_boolean *);
208a9fa9459Szrj
209a9fa9459Szrj /* Save a string in memory. */
210a9fa9459Szrj
211a9fa9459Szrj static char *
savestring(const char * start,int len)212a9fa9459Szrj savestring (const char *start, int len)
213a9fa9459Szrj {
214a9fa9459Szrj char *ret;
215a9fa9459Szrj
216a9fa9459Szrj ret = (char *) xmalloc (len + 1);
217a9fa9459Szrj memcpy (ret, start, len);
218a9fa9459Szrj ret[len] = '\0';
219a9fa9459Szrj return ret;
220a9fa9459Szrj }
221a9fa9459Szrj
222a9fa9459Szrj /* Read a number from a string. */
223a9fa9459Szrj
224a9fa9459Szrj static bfd_vma
parse_number(const char ** pp,bfd_boolean * poverflow)225a9fa9459Szrj parse_number (const char **pp, bfd_boolean *poverflow)
226a9fa9459Szrj {
227a9fa9459Szrj unsigned long ul;
228a9fa9459Szrj const char *orig;
229a9fa9459Szrj
230a9fa9459Szrj if (poverflow != NULL)
231a9fa9459Szrj *poverflow = FALSE;
232a9fa9459Szrj
233a9fa9459Szrj orig = *pp;
234a9fa9459Szrj
235a9fa9459Szrj errno = 0;
236a9fa9459Szrj ul = strtoul (*pp, (char **) pp, 0);
237a9fa9459Szrj if (ul + 1 != 0 || errno == 0)
238a9fa9459Szrj {
239a9fa9459Szrj /* If bfd_vma is larger than unsigned long, and the number is
240a9fa9459Szrj meant to be negative, we have to make sure that we sign
241a9fa9459Szrj extend properly. */
242a9fa9459Szrj if (*orig == '-')
243a9fa9459Szrj return (bfd_vma) (bfd_signed_vma) (long) ul;
244a9fa9459Szrj return (bfd_vma) ul;
245a9fa9459Szrj }
246a9fa9459Szrj
247a9fa9459Szrj /* Note that even though strtoul overflowed, it should have set *pp
248a9fa9459Szrj to the end of the number, which is where we want it. */
249a9fa9459Szrj if (sizeof (bfd_vma) > sizeof (unsigned long))
250a9fa9459Szrj {
251a9fa9459Szrj const char *p;
252a9fa9459Szrj bfd_boolean neg;
253a9fa9459Szrj int base;
254a9fa9459Szrj bfd_vma over, lastdig;
255a9fa9459Szrj bfd_boolean overflow;
256a9fa9459Szrj bfd_vma v;
257a9fa9459Szrj
258a9fa9459Szrj /* Our own version of strtoul, for a bfd_vma. */
259a9fa9459Szrj p = orig;
260a9fa9459Szrj
261a9fa9459Szrj neg = FALSE;
262a9fa9459Szrj if (*p == '+')
263a9fa9459Szrj ++p;
264a9fa9459Szrj else if (*p == '-')
265a9fa9459Szrj {
266a9fa9459Szrj neg = TRUE;
267a9fa9459Szrj ++p;
268a9fa9459Szrj }
269a9fa9459Szrj
270a9fa9459Szrj base = 10;
271a9fa9459Szrj if (*p == '0')
272a9fa9459Szrj {
273a9fa9459Szrj if (p[1] == 'x' || p[1] == 'X')
274a9fa9459Szrj {
275a9fa9459Szrj base = 16;
276a9fa9459Szrj p += 2;
277a9fa9459Szrj }
278a9fa9459Szrj else
279a9fa9459Szrj {
280a9fa9459Szrj base = 8;
281a9fa9459Szrj ++p;
282a9fa9459Szrj }
283a9fa9459Szrj }
284a9fa9459Szrj
285a9fa9459Szrj over = ((bfd_vma) (bfd_signed_vma) -1) / (bfd_vma) base;
286a9fa9459Szrj lastdig = ((bfd_vma) (bfd_signed_vma) -1) % (bfd_vma) base;
287a9fa9459Szrj
288a9fa9459Szrj overflow = FALSE;
289a9fa9459Szrj v = 0;
290a9fa9459Szrj while (1)
291a9fa9459Szrj {
292a9fa9459Szrj int d;
293a9fa9459Szrj
294a9fa9459Szrj d = *p++;
295a9fa9459Szrj if (ISDIGIT (d))
296a9fa9459Szrj d -= '0';
297a9fa9459Szrj else if (ISUPPER (d))
298a9fa9459Szrj d -= 'A';
299a9fa9459Szrj else if (ISLOWER (d))
300a9fa9459Szrj d -= 'a';
301a9fa9459Szrj else
302a9fa9459Szrj break;
303a9fa9459Szrj
304a9fa9459Szrj if (d >= base)
305a9fa9459Szrj break;
306a9fa9459Szrj
307a9fa9459Szrj if (v > over || (v == over && (bfd_vma) d > lastdig))
308a9fa9459Szrj {
309a9fa9459Szrj overflow = TRUE;
310a9fa9459Szrj break;
311a9fa9459Szrj }
312a9fa9459Szrj }
313a9fa9459Szrj
314a9fa9459Szrj if (! overflow)
315a9fa9459Szrj {
316a9fa9459Szrj if (neg)
317a9fa9459Szrj v = - v;
318a9fa9459Szrj return v;
319a9fa9459Szrj }
320a9fa9459Szrj }
321a9fa9459Szrj
322a9fa9459Szrj /* If we get here, the number is too large to represent in a
323a9fa9459Szrj bfd_vma. */
324a9fa9459Szrj if (poverflow != NULL)
325a9fa9459Szrj *poverflow = TRUE;
326a9fa9459Szrj else
327a9fa9459Szrj warn_stab (orig, _("numeric overflow"));
328a9fa9459Szrj
329a9fa9459Szrj return 0;
330a9fa9459Szrj }
331a9fa9459Szrj
332a9fa9459Szrj /* Give an error for a bad stab string. */
333a9fa9459Szrj
334a9fa9459Szrj static void
bad_stab(const char * p)335a9fa9459Szrj bad_stab (const char *p)
336a9fa9459Szrj {
337a9fa9459Szrj fprintf (stderr, _("Bad stab: %s\n"), p);
338a9fa9459Szrj }
339a9fa9459Szrj
340a9fa9459Szrj /* Warn about something in a stab string. */
341a9fa9459Szrj
342a9fa9459Szrj static void
warn_stab(const char * p,const char * err)343a9fa9459Szrj warn_stab (const char *p, const char *err)
344a9fa9459Szrj {
345a9fa9459Szrj fprintf (stderr, _("Warning: %s: %s\n"), err, p);
346a9fa9459Szrj }
347a9fa9459Szrj
348a9fa9459Szrj /* Create a handle to parse stabs symbols with. */
349a9fa9459Szrj
350a9fa9459Szrj void *
start_stab(void * dhandle ATTRIBUTE_UNUSED,bfd * abfd,bfd_boolean sections,asymbol ** syms,long symcount)351a9fa9459Szrj start_stab (void *dhandle ATTRIBUTE_UNUSED, bfd *abfd, bfd_boolean sections,
352a9fa9459Szrj asymbol **syms, long symcount)
353a9fa9459Szrj {
354a9fa9459Szrj struct stab_handle *ret;
355a9fa9459Szrj
356a9fa9459Szrj ret = (struct stab_handle *) xmalloc (sizeof *ret);
357a9fa9459Szrj memset (ret, 0, sizeof *ret);
358a9fa9459Szrj ret->abfd = abfd;
359a9fa9459Szrj ret->sections = sections;
360a9fa9459Szrj ret->syms = syms;
361a9fa9459Szrj ret->symcount = symcount;
362a9fa9459Szrj ret->files = 1;
363a9fa9459Szrj ret->file_types = (struct stab_types **) xmalloc (sizeof *ret->file_types);
364a9fa9459Szrj ret->file_types[0] = NULL;
365a9fa9459Szrj ret->function_end = (bfd_vma) -1;
366a9fa9459Szrj return (void *) ret;
367a9fa9459Szrj }
368a9fa9459Szrj
369a9fa9459Szrj /* When we have processed all the stabs information, we need to go
370a9fa9459Szrj through and fill in all the undefined tags. */
371a9fa9459Szrj
372a9fa9459Szrj bfd_boolean
finish_stab(void * dhandle,void * handle)373a9fa9459Szrj finish_stab (void *dhandle, void *handle)
374a9fa9459Szrj {
375a9fa9459Szrj struct stab_handle *info = (struct stab_handle *) handle;
376a9fa9459Szrj struct stab_tag *st;
377a9fa9459Szrj
378a9fa9459Szrj if (info->within_function)
379a9fa9459Szrj {
380a9fa9459Szrj if (! stab_emit_pending_vars (dhandle, info)
381a9fa9459Szrj || ! debug_end_function (dhandle, info->function_end))
382a9fa9459Szrj return FALSE;
383a9fa9459Szrj info->within_function = FALSE;
384a9fa9459Szrj info->function_end = (bfd_vma) -1;
385a9fa9459Szrj }
386a9fa9459Szrj
387a9fa9459Szrj for (st = info->tags; st != NULL; st = st->next)
388a9fa9459Szrj {
389a9fa9459Szrj enum debug_type_kind kind;
390a9fa9459Szrj
391a9fa9459Szrj kind = st->kind;
392a9fa9459Szrj if (kind == DEBUG_KIND_ILLEGAL)
393a9fa9459Szrj kind = DEBUG_KIND_STRUCT;
394a9fa9459Szrj st->slot = debug_make_undefined_tagged_type (dhandle, st->name, kind);
395a9fa9459Szrj if (st->slot == DEBUG_TYPE_NULL)
396a9fa9459Szrj return FALSE;
397a9fa9459Szrj }
398a9fa9459Szrj
399a9fa9459Szrj return TRUE;
400a9fa9459Szrj }
401a9fa9459Szrj
402a9fa9459Szrj /* Handle a single stabs symbol. */
403a9fa9459Szrj
404a9fa9459Szrj bfd_boolean
parse_stab(void * dhandle,void * handle,int type,int desc,bfd_vma value,const char * string)405a9fa9459Szrj parse_stab (void *dhandle, void *handle, int type, int desc, bfd_vma value,
406a9fa9459Szrj const char *string)
407a9fa9459Szrj {
408a9fa9459Szrj struct stab_handle *info = (struct stab_handle *) handle;
409a9fa9459Szrj
410a9fa9459Szrj /* gcc will emit two N_SO strings per compilation unit, one for the
411a9fa9459Szrj directory name and one for the file name. We just collect N_SO
412a9fa9459Szrj strings as we see them, and start the new compilation unit when
413a9fa9459Szrj we see a non N_SO symbol. */
414a9fa9459Szrj if (info->so_string != NULL
415a9fa9459Szrj && (type != N_SO || *string == '\0' || value != info->so_value))
416a9fa9459Szrj {
417a9fa9459Szrj if (! debug_set_filename (dhandle, info->so_string))
418a9fa9459Szrj return FALSE;
419a9fa9459Szrj info->main_filename = info->so_string;
420a9fa9459Szrj
421a9fa9459Szrj info->gcc_compiled = 0;
422a9fa9459Szrj info->n_opt_found = FALSE;
423a9fa9459Szrj
424a9fa9459Szrj /* Generally, for stabs in the symbol table, the N_LBRAC and
425a9fa9459Szrj N_RBRAC symbols are relative to the N_SO symbol value. */
426a9fa9459Szrj if (! info->sections)
427a9fa9459Szrj info->file_start_offset = info->so_value;
428a9fa9459Szrj
429a9fa9459Szrj /* We need to reset the mapping from type numbers to types. We
430a9fa9459Szrj can't free the old mapping, because of the use of
431a9fa9459Szrj debug_make_indirect_type. */
432a9fa9459Szrj info->files = 1;
433a9fa9459Szrj info->file_types = ((struct stab_types **)
434a9fa9459Szrj xmalloc (sizeof *info->file_types));
435a9fa9459Szrj info->file_types[0] = NULL;
436a9fa9459Szrj
437a9fa9459Szrj info->so_string = NULL;
438a9fa9459Szrj
439a9fa9459Szrj /* Now process whatever type we just got. */
440a9fa9459Szrj }
441a9fa9459Szrj
442a9fa9459Szrj switch (type)
443a9fa9459Szrj {
444a9fa9459Szrj case N_FN:
445a9fa9459Szrj case N_FN_SEQ:
446a9fa9459Szrj break;
447a9fa9459Szrj
448a9fa9459Szrj case N_LBRAC:
449a9fa9459Szrj /* Ignore extra outermost context from SunPRO cc and acc. */
450a9fa9459Szrj if (info->n_opt_found && desc == 1)
451a9fa9459Szrj break;
452a9fa9459Szrj
453a9fa9459Szrj if (! info->within_function)
454a9fa9459Szrj {
455a9fa9459Szrj fprintf (stderr, _("N_LBRAC not within function\n"));
456a9fa9459Szrj return FALSE;
457a9fa9459Szrj }
458a9fa9459Szrj
459a9fa9459Szrj /* Start an inner lexical block. */
460a9fa9459Szrj if (! debug_start_block (dhandle,
461a9fa9459Szrj (value
462a9fa9459Szrj + info->file_start_offset
463a9fa9459Szrj + info->function_start_offset)))
464a9fa9459Szrj return FALSE;
465a9fa9459Szrj
466a9fa9459Szrj /* Emit any pending variable definitions. */
467a9fa9459Szrj if (! stab_emit_pending_vars (dhandle, info))
468a9fa9459Szrj return FALSE;
469a9fa9459Szrj
470a9fa9459Szrj ++info->block_depth;
471a9fa9459Szrj break;
472a9fa9459Szrj
473a9fa9459Szrj case N_RBRAC:
474a9fa9459Szrj /* Ignore extra outermost context from SunPRO cc and acc. */
475a9fa9459Szrj if (info->n_opt_found && desc == 1)
476a9fa9459Szrj break;
477a9fa9459Szrj
478a9fa9459Szrj /* We shouldn't have any pending variable definitions here, but,
479a9fa9459Szrj if we do, we probably need to emit them before closing the
480a9fa9459Szrj block. */
481a9fa9459Szrj if (! stab_emit_pending_vars (dhandle, info))
482a9fa9459Szrj return FALSE;
483a9fa9459Szrj
484a9fa9459Szrj /* End an inner lexical block. */
485a9fa9459Szrj if (! debug_end_block (dhandle,
486a9fa9459Szrj (value
487a9fa9459Szrj + info->file_start_offset
488a9fa9459Szrj + info->function_start_offset)))
489a9fa9459Szrj return FALSE;
490a9fa9459Szrj
491a9fa9459Szrj --info->block_depth;
492a9fa9459Szrj if (info->block_depth < 0)
493a9fa9459Szrj {
494a9fa9459Szrj fprintf (stderr, _("Too many N_RBRACs\n"));
495a9fa9459Szrj return FALSE;
496a9fa9459Szrj }
497a9fa9459Szrj break;
498a9fa9459Szrj
499a9fa9459Szrj case N_SO:
500a9fa9459Szrj /* This always ends a function. */
501a9fa9459Szrj if (info->within_function)
502a9fa9459Szrj {
503a9fa9459Szrj bfd_vma endval;
504a9fa9459Szrj
505a9fa9459Szrj endval = value;
506a9fa9459Szrj if (*string != '\0'
507a9fa9459Szrj && info->function_end != (bfd_vma) -1
508a9fa9459Szrj && info->function_end < endval)
509a9fa9459Szrj endval = info->function_end;
510a9fa9459Szrj if (! stab_emit_pending_vars (dhandle, info)
511a9fa9459Szrj || ! debug_end_function (dhandle, endval))
512a9fa9459Szrj return FALSE;
513a9fa9459Szrj info->within_function = FALSE;
514a9fa9459Szrj info->function_end = (bfd_vma) -1;
515a9fa9459Szrj }
516a9fa9459Szrj
517a9fa9459Szrj /* An empty string is emitted by gcc at the end of a compilation
518a9fa9459Szrj unit. */
519a9fa9459Szrj if (*string == '\0')
520a9fa9459Szrj return TRUE;
521a9fa9459Szrj
522a9fa9459Szrj /* Just accumulate strings until we see a non N_SO symbol. If
523a9fa9459Szrj the string starts with a directory separator or some other
524a9fa9459Szrj form of absolute path specification, we discard the previously
525a9fa9459Szrj accumulated strings. */
526a9fa9459Szrj if (info->so_string == NULL)
527a9fa9459Szrj info->so_string = xstrdup (string);
528a9fa9459Szrj else
529a9fa9459Szrj {
530a9fa9459Szrj char *f;
531a9fa9459Szrj
532a9fa9459Szrj f = info->so_string;
533a9fa9459Szrj
534a9fa9459Szrj if (IS_ABSOLUTE_PATH (string))
535a9fa9459Szrj info->so_string = xstrdup (string);
536a9fa9459Szrj else
537a9fa9459Szrj info->so_string = concat (info->so_string, string,
538a9fa9459Szrj (const char *) NULL);
539a9fa9459Szrj free (f);
540a9fa9459Szrj }
541a9fa9459Szrj
542a9fa9459Szrj info->so_value = value;
543a9fa9459Szrj
544a9fa9459Szrj break;
545a9fa9459Szrj
546a9fa9459Szrj case N_SOL:
547a9fa9459Szrj /* Start an include file. */
548a9fa9459Szrj if (! debug_start_source (dhandle, string))
549a9fa9459Szrj return FALSE;
550a9fa9459Szrj break;
551a9fa9459Szrj
552a9fa9459Szrj case N_BINCL:
553a9fa9459Szrj /* Start an include file which may be replaced. */
554a9fa9459Szrj push_bincl (info, string, value);
555a9fa9459Szrj if (! debug_start_source (dhandle, string))
556a9fa9459Szrj return FALSE;
557a9fa9459Szrj break;
558a9fa9459Szrj
559a9fa9459Szrj case N_EINCL:
560a9fa9459Szrj /* End an N_BINCL include. */
561a9fa9459Szrj if (! debug_start_source (dhandle, pop_bincl (info)))
562a9fa9459Szrj return FALSE;
563a9fa9459Szrj break;
564a9fa9459Szrj
565a9fa9459Szrj case N_EXCL:
566a9fa9459Szrj /* This is a duplicate of a header file named by N_BINCL which
567a9fa9459Szrj was eliminated by the linker. */
568a9fa9459Szrj if (! find_excl (info, string, value))
569a9fa9459Szrj return FALSE;
570a9fa9459Szrj break;
571a9fa9459Szrj
572a9fa9459Szrj case N_SLINE:
573a9fa9459Szrj if (! debug_record_line (dhandle, desc,
574a9fa9459Szrj value + (info->within_function
575a9fa9459Szrj ? info->function_start_offset : 0)))
576a9fa9459Szrj return FALSE;
577a9fa9459Szrj break;
578a9fa9459Szrj
579a9fa9459Szrj case N_BCOMM:
580a9fa9459Szrj if (! debug_start_common_block (dhandle, string))
581a9fa9459Szrj return FALSE;
582a9fa9459Szrj break;
583a9fa9459Szrj
584a9fa9459Szrj case N_ECOMM:
585a9fa9459Szrj if (! debug_end_common_block (dhandle, string))
586a9fa9459Szrj return FALSE;
587a9fa9459Szrj break;
588a9fa9459Szrj
589a9fa9459Szrj case N_FUN:
590a9fa9459Szrj if (*string == '\0')
591a9fa9459Szrj {
592a9fa9459Szrj if (info->within_function)
593a9fa9459Szrj {
594a9fa9459Szrj /* This always marks the end of a function; we don't
595a9fa9459Szrj need to worry about info->function_end. */
596a9fa9459Szrj if (info->sections)
597a9fa9459Szrj value += info->function_start_offset;
598a9fa9459Szrj if (! stab_emit_pending_vars (dhandle, info)
599a9fa9459Szrj || ! debug_end_function (dhandle, value))
600a9fa9459Szrj return FALSE;
601a9fa9459Szrj info->within_function = FALSE;
602a9fa9459Szrj info->function_end = (bfd_vma) -1;
603a9fa9459Szrj }
604a9fa9459Szrj break;
605a9fa9459Szrj }
606a9fa9459Szrj
607a9fa9459Szrj /* A const static symbol in the .text section will have an N_FUN
608a9fa9459Szrj entry. We need to use these to mark the end of the function,
609a9fa9459Szrj in case we are looking at gcc output before it was changed to
610a9fa9459Szrj always emit an empty N_FUN. We can't call debug_end_function
611a9fa9459Szrj here, because it might be a local static symbol. */
612a9fa9459Szrj if (info->within_function
613a9fa9459Szrj && (info->function_end == (bfd_vma) -1
614a9fa9459Szrj || value < info->function_end))
615a9fa9459Szrj info->function_end = value;
616a9fa9459Szrj
617a9fa9459Szrj /* Fall through. */
618a9fa9459Szrj /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM
619a9fa9459Szrj symbols, and if it does not start with :S, gdb relocates the
620a9fa9459Szrj value to the start of the section. gcc always seems to use
621a9fa9459Szrj :S, so we don't worry about this. */
622a9fa9459Szrj /* Fall through. */
623a9fa9459Szrj default:
624a9fa9459Szrj {
625a9fa9459Szrj const char *colon;
626a9fa9459Szrj
627a9fa9459Szrj colon = strchr (string, ':');
628a9fa9459Szrj if (colon != NULL
629a9fa9459Szrj && (colon[1] == 'f' || colon[1] == 'F'))
630a9fa9459Szrj {
631a9fa9459Szrj if (info->within_function)
632a9fa9459Szrj {
633a9fa9459Szrj bfd_vma endval;
634a9fa9459Szrj
635a9fa9459Szrj endval = value;
636a9fa9459Szrj if (info->function_end != (bfd_vma) -1
637a9fa9459Szrj && info->function_end < endval)
638a9fa9459Szrj endval = info->function_end;
639a9fa9459Szrj if (! stab_emit_pending_vars (dhandle, info)
640a9fa9459Szrj || ! debug_end_function (dhandle, endval))
641a9fa9459Szrj return FALSE;
642a9fa9459Szrj info->function_end = (bfd_vma) -1;
643a9fa9459Szrj }
644a9fa9459Szrj /* For stabs in sections, line numbers and block addresses
645a9fa9459Szrj are offsets from the start of the function. */
646a9fa9459Szrj if (info->sections)
647a9fa9459Szrj info->function_start_offset = value;
648a9fa9459Szrj info->within_function = TRUE;
649a9fa9459Szrj }
650a9fa9459Szrj
651a9fa9459Szrj if (! parse_stab_string (dhandle, info, type, desc, value, string))
652a9fa9459Szrj return FALSE;
653a9fa9459Szrj }
654a9fa9459Szrj break;
655a9fa9459Szrj
656a9fa9459Szrj case N_OPT:
657a9fa9459Szrj if (string != NULL && strcmp (string, "gcc2_compiled.") == 0)
658a9fa9459Szrj info->gcc_compiled = 2;
659a9fa9459Szrj else if (string != NULL && strcmp (string, "gcc_compiled.") == 0)
660a9fa9459Szrj info->gcc_compiled = 1;
661a9fa9459Szrj else
662a9fa9459Szrj info->n_opt_found = TRUE;
663a9fa9459Szrj break;
664a9fa9459Szrj
665a9fa9459Szrj case N_OBJ:
666a9fa9459Szrj case N_ENDM:
667a9fa9459Szrj case N_MAIN:
668a9fa9459Szrj case N_WARNING:
669a9fa9459Szrj break;
670a9fa9459Szrj }
671a9fa9459Szrj
672a9fa9459Szrj return TRUE;
673a9fa9459Szrj }
674a9fa9459Szrj
675a9fa9459Szrj /* Parse the stabs string. */
676a9fa9459Szrj
677a9fa9459Szrj static bfd_boolean
parse_stab_string(void * dhandle,struct stab_handle * info,int stabtype,int desc ATTRIBUTE_UNUSED,bfd_vma value,const char * string)678a9fa9459Szrj parse_stab_string (void *dhandle, struct stab_handle *info, int stabtype,
679a9fa9459Szrj int desc ATTRIBUTE_UNUSED, bfd_vma value, const char *string)
680a9fa9459Szrj {
681a9fa9459Szrj const char *p;
682a9fa9459Szrj char *name;
683a9fa9459Szrj int type;
684a9fa9459Szrj debug_type dtype;
685a9fa9459Szrj bfd_boolean synonym;
686a9fa9459Szrj bfd_boolean self_crossref;
687a9fa9459Szrj debug_type *slot;
688a9fa9459Szrj
689a9fa9459Szrj p = strchr (string, ':');
690a9fa9459Szrj if (p == NULL)
691a9fa9459Szrj return TRUE;
692a9fa9459Szrj
693a9fa9459Szrj while (p[1] == ':')
694a9fa9459Szrj {
695a9fa9459Szrj p += 2;
696a9fa9459Szrj p = strchr (p, ':');
697a9fa9459Szrj if (p == NULL)
698a9fa9459Szrj {
699a9fa9459Szrj bad_stab (string);
700a9fa9459Szrj return FALSE;
701a9fa9459Szrj }
702a9fa9459Szrj }
703a9fa9459Szrj
704a9fa9459Szrj /* FIXME: Sometimes the special C++ names start with '.'. */
705a9fa9459Szrj name = NULL;
706a9fa9459Szrj if (string[0] == '$')
707a9fa9459Szrj {
708a9fa9459Szrj switch (string[1])
709a9fa9459Szrj {
710a9fa9459Szrj case 't':
711a9fa9459Szrj name = "this";
712a9fa9459Szrj break;
713a9fa9459Szrj case 'v':
714a9fa9459Szrj /* Was: name = "vptr"; */
715a9fa9459Szrj break;
716a9fa9459Szrj case 'e':
717a9fa9459Szrj name = "eh_throw";
718a9fa9459Szrj break;
719a9fa9459Szrj case '_':
720a9fa9459Szrj /* This was an anonymous type that was never fixed up. */
721a9fa9459Szrj break;
722a9fa9459Szrj case 'X':
723a9fa9459Szrj /* SunPRO (3.0 at least) static variable encoding. */
724a9fa9459Szrj break;
725a9fa9459Szrj default:
726a9fa9459Szrj warn_stab (string, _("unknown C++ encoded name"));
727a9fa9459Szrj break;
728a9fa9459Szrj }
729a9fa9459Szrj }
730a9fa9459Szrj
731a9fa9459Szrj if (name == NULL)
732a9fa9459Szrj {
733a9fa9459Szrj if (p == string || (string[0] == ' ' && p == string + 1))
734a9fa9459Szrj name = NULL;
735a9fa9459Szrj else
736a9fa9459Szrj name = savestring (string, p - string);
737a9fa9459Szrj }
738a9fa9459Szrj
739a9fa9459Szrj ++p;
740a9fa9459Szrj if (ISDIGIT (*p) || *p == '(' || *p == '-')
741a9fa9459Szrj type = 'l';
742a9fa9459Szrj else
743a9fa9459Szrj type = *p++;
744a9fa9459Szrj
745a9fa9459Szrj switch (type)
746a9fa9459Szrj {
747a9fa9459Szrj case 'c':
748a9fa9459Szrj /* c is a special case, not followed by a type-number.
749a9fa9459Szrj SYMBOL:c=iVALUE for an integer constant symbol.
750a9fa9459Szrj SYMBOL:c=rVALUE for a floating constant symbol.
751a9fa9459Szrj SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
752a9fa9459Szrj e.g. "b:c=e6,0" for "const b = blob1"
753a9fa9459Szrj (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
754a9fa9459Szrj if (*p != '=')
755a9fa9459Szrj {
756a9fa9459Szrj bad_stab (string);
757a9fa9459Szrj return FALSE;
758a9fa9459Szrj }
759a9fa9459Szrj ++p;
760a9fa9459Szrj switch (*p++)
761a9fa9459Szrj {
762a9fa9459Szrj case 'r':
763a9fa9459Szrj /* Floating point constant. */
764a9fa9459Szrj if (! debug_record_float_const (dhandle, name, atof (p)))
765a9fa9459Szrj return FALSE;
766a9fa9459Szrj break;
767a9fa9459Szrj case 'i':
768a9fa9459Szrj /* Integer constant. */
769a9fa9459Szrj /* Defining integer constants this way is kind of silly,
770a9fa9459Szrj since 'e' constants allows the compiler to give not only
771a9fa9459Szrj the value, but the type as well. C has at least int,
772a9fa9459Szrj long, unsigned int, and long long as constant types;
773a9fa9459Szrj other languages probably should have at least unsigned as
774a9fa9459Szrj well as signed constants. */
775a9fa9459Szrj if (! debug_record_int_const (dhandle, name, atoi (p)))
776a9fa9459Szrj return FALSE;
777a9fa9459Szrj break;
778a9fa9459Szrj case 'e':
779a9fa9459Szrj /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
780a9fa9459Szrj can be represented as integral.
781a9fa9459Szrj e.g. "b:c=e6,0" for "const b = blob1"
782a9fa9459Szrj (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
783a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL,
784a9fa9459Szrj &p, (debug_type **) NULL);
785a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL)
786a9fa9459Szrj return FALSE;
787a9fa9459Szrj if (*p != ',')
788a9fa9459Szrj {
789a9fa9459Szrj bad_stab (string);
790a9fa9459Szrj return FALSE;
791a9fa9459Szrj }
792a9fa9459Szrj if (! debug_record_typed_const (dhandle, name, dtype, atoi (p)))
793a9fa9459Szrj return FALSE;
794a9fa9459Szrj break;
795a9fa9459Szrj default:
796a9fa9459Szrj bad_stab (string);
797a9fa9459Szrj return FALSE;
798a9fa9459Szrj }
799a9fa9459Szrj
800a9fa9459Szrj break;
801a9fa9459Szrj
802a9fa9459Szrj case 'C':
803a9fa9459Szrj /* The name of a caught exception. */
804a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL,
805a9fa9459Szrj &p, (debug_type **) NULL);
806a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL)
807a9fa9459Szrj return FALSE;
808a9fa9459Szrj if (! debug_record_label (dhandle, name, dtype, value))
809a9fa9459Szrj return FALSE;
810a9fa9459Szrj break;
811a9fa9459Szrj
812a9fa9459Szrj case 'f':
813a9fa9459Szrj case 'F':
814a9fa9459Szrj /* A function definition. */
815a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
816a9fa9459Szrj (debug_type **) NULL);
817a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL)
818a9fa9459Szrj return FALSE;
819a9fa9459Szrj if (! debug_record_function (dhandle, name, dtype, type == 'F', value))
820a9fa9459Szrj return FALSE;
821a9fa9459Szrj
822a9fa9459Szrj /* Sun acc puts declared types of arguments here. We don't care
823a9fa9459Szrj about their actual types (FIXME -- we should remember the whole
824a9fa9459Szrj function prototype), but the list may define some new types
825a9fa9459Szrj that we have to remember, so we must scan it now. */
826a9fa9459Szrj while (*p == ';')
827a9fa9459Szrj {
828a9fa9459Szrj ++p;
829a9fa9459Szrj if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
830a9fa9459Szrj (debug_type **) NULL)
831a9fa9459Szrj == DEBUG_TYPE_NULL)
832a9fa9459Szrj return FALSE;
833a9fa9459Szrj }
834a9fa9459Szrj
835a9fa9459Szrj break;
836a9fa9459Szrj
837a9fa9459Szrj case 'G':
838a9fa9459Szrj {
839a9fa9459Szrj asymbol **ps;
840a9fa9459Szrj
841a9fa9459Szrj /* A global symbol. The value must be extracted from the
842a9fa9459Szrj symbol table. */
843a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
844a9fa9459Szrj (debug_type **) NULL);
845a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL)
846a9fa9459Szrj return FALSE;
847a9fa9459Szrj if (name != NULL)
848a9fa9459Szrj {
849a9fa9459Szrj char leading;
850a9fa9459Szrj long c;
851a9fa9459Szrj
852a9fa9459Szrj leading = bfd_get_symbol_leading_char (info->abfd);
853a9fa9459Szrj for (c = info->symcount, ps = info->syms; c > 0; --c, ++ps)
854a9fa9459Szrj {
855a9fa9459Szrj const char *n;
856a9fa9459Szrj
857a9fa9459Szrj n = bfd_asymbol_name (*ps);
858a9fa9459Szrj if (leading != '\0' && *n == leading)
859a9fa9459Szrj ++n;
860a9fa9459Szrj if (*n == *name && strcmp (n, name) == 0)
861a9fa9459Szrj break;
862a9fa9459Szrj }
863a9fa9459Szrj
864a9fa9459Szrj if (c > 0)
865a9fa9459Szrj value = bfd_asymbol_value (*ps);
866a9fa9459Szrj }
867a9fa9459Szrj
868a9fa9459Szrj if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_GLOBAL,
869a9fa9459Szrj value))
870a9fa9459Szrj return FALSE;
871a9fa9459Szrj }
872a9fa9459Szrj break;
873a9fa9459Szrj
874a9fa9459Szrj /* This case is faked by a conditional above, when there is no
875a9fa9459Szrj code letter in the dbx data. Dbx data never actually
876a9fa9459Szrj contains 'l'. */
877a9fa9459Szrj case 'l':
878a9fa9459Szrj case 's':
879a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
880a9fa9459Szrj (debug_type **) NULL);
881a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL)
882a9fa9459Szrj return FALSE;
883a9fa9459Szrj if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
884a9fa9459Szrj value))
885a9fa9459Szrj return FALSE;
886a9fa9459Szrj break;
887a9fa9459Szrj
888a9fa9459Szrj case 'p':
889a9fa9459Szrj /* A function parameter. */
890a9fa9459Szrj if (*p != 'F')
891a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
892a9fa9459Szrj (debug_type **) NULL);
893a9fa9459Szrj else
894a9fa9459Szrj {
895a9fa9459Szrj /* pF is a two-letter code that means a function parameter in
896a9fa9459Szrj Fortran. The type-number specifies the type of the return
897a9fa9459Szrj value. Translate it into a pointer-to-function type. */
898a9fa9459Szrj ++p;
899a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
900a9fa9459Szrj (debug_type **) NULL);
901a9fa9459Szrj if (dtype != DEBUG_TYPE_NULL)
902a9fa9459Szrj {
903a9fa9459Szrj debug_type ftype;
904a9fa9459Szrj
905a9fa9459Szrj ftype = debug_make_function_type (dhandle, dtype,
906a9fa9459Szrj (debug_type *) NULL, FALSE);
907a9fa9459Szrj dtype = debug_make_pointer_type (dhandle, ftype);
908a9fa9459Szrj }
909a9fa9459Szrj }
910a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL)
911a9fa9459Szrj return FALSE;
912a9fa9459Szrj if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_STACK,
913a9fa9459Szrj value))
914a9fa9459Szrj return FALSE;
915a9fa9459Szrj
916a9fa9459Szrj /* FIXME: At this point gdb considers rearranging the parameter
917a9fa9459Szrj address on a big endian machine if it is smaller than an int.
918a9fa9459Szrj We have no way to do that, since we don't really know much
919a9fa9459Szrj about the target. */
920a9fa9459Szrj break;
921a9fa9459Szrj
922a9fa9459Szrj case 'P':
923a9fa9459Szrj if (stabtype == N_FUN)
924a9fa9459Szrj {
925a9fa9459Szrj /* Prototype of a function referenced by this file. */
926a9fa9459Szrj while (*p == ';')
927a9fa9459Szrj {
928a9fa9459Szrj ++p;
929a9fa9459Szrj if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
930a9fa9459Szrj (debug_type **) NULL)
931a9fa9459Szrj == DEBUG_TYPE_NULL)
932a9fa9459Szrj return FALSE;
933a9fa9459Szrj }
934a9fa9459Szrj break;
935a9fa9459Szrj }
936a9fa9459Szrj /* Fall through. */
937a9fa9459Szrj case 'R':
938a9fa9459Szrj /* Parameter which is in a register. */
939a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
940a9fa9459Szrj (debug_type **) NULL);
941a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL)
942a9fa9459Szrj return FALSE;
943a9fa9459Szrj if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REG,
944a9fa9459Szrj value))
945a9fa9459Szrj return FALSE;
946a9fa9459Szrj break;
947a9fa9459Szrj
948a9fa9459Szrj case 'r':
949a9fa9459Szrj /* Register variable (either global or local). */
950a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
951a9fa9459Szrj (debug_type **) NULL);
952a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL)
953a9fa9459Szrj return FALSE;
954a9fa9459Szrj if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_REGISTER,
955a9fa9459Szrj value))
956a9fa9459Szrj return FALSE;
957a9fa9459Szrj
958a9fa9459Szrj /* FIXME: At this point gdb checks to combine pairs of 'p' and
959a9fa9459Szrj 'r' stabs into a single 'P' stab. */
960a9fa9459Szrj break;
961a9fa9459Szrj
962a9fa9459Szrj case 'S':
963a9fa9459Szrj /* Static symbol at top level of file. */
964a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
965a9fa9459Szrj (debug_type **) NULL);
966a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL)
967a9fa9459Szrj return FALSE;
968a9fa9459Szrj if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_STATIC,
969a9fa9459Szrj value))
970a9fa9459Szrj return FALSE;
971a9fa9459Szrj break;
972a9fa9459Szrj
973a9fa9459Szrj case 't':
974a9fa9459Szrj /* A typedef. */
975a9fa9459Szrj dtype = parse_stab_type (dhandle, info, name, &p, &slot);
976a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL)
977a9fa9459Szrj return FALSE;
978a9fa9459Szrj if (name == NULL)
979a9fa9459Szrj {
980a9fa9459Szrj /* A nameless type. Nothing to do. */
981a9fa9459Szrj return TRUE;
982a9fa9459Szrj }
983a9fa9459Szrj
984a9fa9459Szrj dtype = debug_name_type (dhandle, name, dtype);
985a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL)
986a9fa9459Szrj return FALSE;
987a9fa9459Szrj
988a9fa9459Szrj if (slot != NULL)
989a9fa9459Szrj *slot = dtype;
990a9fa9459Szrj
991a9fa9459Szrj break;
992a9fa9459Szrj
993a9fa9459Szrj case 'T':
994a9fa9459Szrj /* Struct, union, or enum tag. For GNU C++, this can be be followed
995a9fa9459Szrj by 't' which means we are typedef'ing it as well. */
996a9fa9459Szrj if (*p != 't')
997a9fa9459Szrj {
998a9fa9459Szrj synonym = FALSE;
999a9fa9459Szrj /* FIXME: gdb sets synonym to TRUE if the current language
1000a9fa9459Szrj is C++. */
1001a9fa9459Szrj }
1002a9fa9459Szrj else
1003a9fa9459Szrj {
1004a9fa9459Szrj synonym = TRUE;
1005a9fa9459Szrj ++p;
1006a9fa9459Szrj }
1007a9fa9459Szrj
1008a9fa9459Szrj dtype = parse_stab_type (dhandle, info, name, &p, &slot);
1009a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL)
1010a9fa9459Szrj return FALSE;
1011a9fa9459Szrj if (name == NULL)
1012a9fa9459Szrj return TRUE;
1013a9fa9459Szrj
1014a9fa9459Szrj /* INFO->SELF_CROSSREF is set by parse_stab_type if this type is
1015a9fa9459Szrj a cross reference to itself. These are generated by some
1016a9fa9459Szrj versions of g++. */
1017a9fa9459Szrj self_crossref = info->self_crossref;
1018a9fa9459Szrj
1019a9fa9459Szrj dtype = debug_tag_type (dhandle, name, dtype);
1020a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL)
1021a9fa9459Szrj return FALSE;
1022a9fa9459Szrj if (slot != NULL)
1023a9fa9459Szrj *slot = dtype;
1024a9fa9459Szrj
1025a9fa9459Szrj /* See if we have a cross reference to this tag which we can now
1026a9fa9459Szrj fill in. Avoid filling in a cross reference to ourselves,
1027a9fa9459Szrj because that would lead to circular debugging information. */
1028a9fa9459Szrj if (! self_crossref)
1029a9fa9459Szrj {
1030a9fa9459Szrj register struct stab_tag **pst;
1031a9fa9459Szrj
1032a9fa9459Szrj for (pst = &info->tags; *pst != NULL; pst = &(*pst)->next)
1033a9fa9459Szrj {
1034a9fa9459Szrj if ((*pst)->name[0] == name[0]
1035a9fa9459Szrj && strcmp ((*pst)->name, name) == 0)
1036a9fa9459Szrj {
1037a9fa9459Szrj (*pst)->slot = dtype;
1038a9fa9459Szrj *pst = (*pst)->next;
1039a9fa9459Szrj break;
1040a9fa9459Szrj }
1041a9fa9459Szrj }
1042a9fa9459Szrj }
1043a9fa9459Szrj
1044a9fa9459Szrj if (synonym)
1045a9fa9459Szrj {
1046a9fa9459Szrj dtype = debug_name_type (dhandle, name, dtype);
1047a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL)
1048a9fa9459Szrj return FALSE;
1049a9fa9459Szrj
1050a9fa9459Szrj if (slot != NULL)
1051a9fa9459Szrj *slot = dtype;
1052a9fa9459Szrj }
1053a9fa9459Szrj
1054a9fa9459Szrj break;
1055a9fa9459Szrj
1056a9fa9459Szrj case 'V':
1057a9fa9459Szrj /* Static symbol of local scope */
1058a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1059a9fa9459Szrj (debug_type **) NULL);
1060a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL)
1061a9fa9459Szrj return FALSE;
1062a9fa9459Szrj /* FIXME: gdb checks os9k_stabs here. */
1063a9fa9459Szrj if (! stab_record_variable (dhandle, info, name, dtype,
1064a9fa9459Szrj DEBUG_LOCAL_STATIC, value))
1065a9fa9459Szrj return FALSE;
1066a9fa9459Szrj break;
1067a9fa9459Szrj
1068a9fa9459Szrj case 'v':
1069a9fa9459Szrj /* Reference parameter. */
1070a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1071a9fa9459Szrj (debug_type **) NULL);
1072a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL)
1073a9fa9459Szrj return FALSE;
1074a9fa9459Szrj if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REFERENCE,
1075a9fa9459Szrj value))
1076a9fa9459Szrj return FALSE;
1077a9fa9459Szrj break;
1078a9fa9459Szrj
1079a9fa9459Szrj case 'a':
1080a9fa9459Szrj /* Reference parameter which is in a register. */
1081a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1082a9fa9459Szrj (debug_type **) NULL);
1083a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL)
1084a9fa9459Szrj return FALSE;
1085a9fa9459Szrj if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REF_REG,
1086a9fa9459Szrj value))
1087a9fa9459Szrj return FALSE;
1088a9fa9459Szrj break;
1089a9fa9459Szrj
1090a9fa9459Szrj case 'X':
1091a9fa9459Szrj /* This is used by Sun FORTRAN for "function result value".
1092a9fa9459Szrj Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1093a9fa9459Szrj that Pascal uses it too, but when I tried it Pascal used
1094a9fa9459Szrj "x:3" (local symbol) instead. */
1095a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1096a9fa9459Szrj (debug_type **) NULL);
1097a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL)
1098a9fa9459Szrj return FALSE;
1099a9fa9459Szrj if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
1100a9fa9459Szrj value))
1101a9fa9459Szrj return FALSE;
1102a9fa9459Szrj break;
1103a9fa9459Szrj
1104a9fa9459Szrj case 'Y':
1105a9fa9459Szrj /* SUNPro C++ Namespace =Yn0. */
1106a9fa9459Szrj /* Skip the namespace mapping, as it is not used now. */
1107a9fa9459Szrj if (*(++p) == 'n' && *(++p) == '0')
1108a9fa9459Szrj {
1109a9fa9459Szrj /* =Yn0name; */
1110a9fa9459Szrj while (*p != ';')
1111a9fa9459Szrj ++p;
1112a9fa9459Szrj ++p;
1113a9fa9459Szrj return TRUE;
1114a9fa9459Szrj }
1115a9fa9459Szrj /* TODO SUNPro C++ support:
1116a9fa9459Szrj Support default arguments after F,P parameters
1117a9fa9459Szrj Ya = Anonymous unions
1118a9fa9459Szrj YM,YD = Pointers to class members
1119a9fa9459Szrj YT,YI = Templates
1120a9fa9459Szrj YR = Run-time type information (RTTI) */
1121a9fa9459Szrj
1122a9fa9459Szrj /* Fall through. */
1123a9fa9459Szrj
1124a9fa9459Szrj default:
1125a9fa9459Szrj bad_stab (string);
1126a9fa9459Szrj return FALSE;
1127a9fa9459Szrj }
1128a9fa9459Szrj
1129a9fa9459Szrj /* FIXME: gdb converts structure values to structure pointers in a
1130a9fa9459Szrj couple of cases, depending upon the target. */
1131a9fa9459Szrj
1132a9fa9459Szrj return TRUE;
1133a9fa9459Szrj }
1134a9fa9459Szrj
1135a9fa9459Szrj /* Parse a stabs type. The typename argument is non-NULL if this is a
1136a9fa9459Szrj typedef or a tag definition. The pp argument points to the stab
1137a9fa9459Szrj string, and is updated. The slotp argument points to a place to
1138a9fa9459Szrj store the slot used if the type is being defined. */
1139a9fa9459Szrj
1140a9fa9459Szrj static debug_type
parse_stab_type(void * dhandle,struct stab_handle * info,const char * type_name,const char ** pp,debug_type ** slotp)1141a9fa9459Szrj parse_stab_type (void *dhandle, struct stab_handle *info, const char *type_name, const char **pp, debug_type **slotp)
1142a9fa9459Szrj {
1143a9fa9459Szrj const char *orig;
1144a9fa9459Szrj int typenums[2];
1145a9fa9459Szrj int size;
1146a9fa9459Szrj bfd_boolean stringp;
1147a9fa9459Szrj int descriptor;
1148a9fa9459Szrj debug_type dtype;
1149a9fa9459Szrj
1150a9fa9459Szrj if (slotp != NULL)
1151a9fa9459Szrj *slotp = NULL;
1152a9fa9459Szrj
1153a9fa9459Szrj orig = *pp;
1154a9fa9459Szrj
1155a9fa9459Szrj size = -1;
1156a9fa9459Szrj stringp = FALSE;
1157a9fa9459Szrj
1158a9fa9459Szrj info->self_crossref = FALSE;
1159a9fa9459Szrj
1160a9fa9459Szrj /* Read type number if present. The type number may be omitted.
1161a9fa9459Szrj for instance in a two-dimensional array declared with type
1162a9fa9459Szrj "ar1;1;10;ar1;1;10;4". */
1163a9fa9459Szrj if (! ISDIGIT (**pp) && **pp != '(' && **pp != '-')
1164a9fa9459Szrj {
1165a9fa9459Szrj /* 'typenums=' not present, type is anonymous. Read and return
1166a9fa9459Szrj the definition, but don't put it in the type vector. */
1167a9fa9459Szrj typenums[0] = typenums[1] = -1;
1168a9fa9459Szrj }
1169a9fa9459Szrj else
1170a9fa9459Szrj {
1171a9fa9459Szrj if (! parse_stab_type_number (pp, typenums))
1172a9fa9459Szrj return DEBUG_TYPE_NULL;
1173a9fa9459Szrj
1174a9fa9459Szrj if (**pp != '=')
1175a9fa9459Szrj /* Type is not being defined here. Either it already
1176a9fa9459Szrj exists, or this is a forward reference to it. */
1177a9fa9459Szrj return stab_find_type (dhandle, info, typenums);
1178a9fa9459Szrj
1179a9fa9459Szrj /* Only set the slot if the type is being defined. This means
1180a9fa9459Szrj that the mapping from type numbers to types will only record
1181a9fa9459Szrj the name of the typedef which defines a type. If we don't do
1182a9fa9459Szrj this, then something like
1183a9fa9459Szrj typedef int foo;
1184a9fa9459Szrj int i;
1185a9fa9459Szrj will record that i is of type foo. Unfortunately, stabs
1186a9fa9459Szrj information is ambiguous about variable types. For this code,
1187a9fa9459Szrj typedef int foo;
1188a9fa9459Szrj int i;
1189a9fa9459Szrj foo j;
1190a9fa9459Szrj the stabs information records both i and j as having the same
1191a9fa9459Szrj type. This could be fixed by patching the compiler. */
1192a9fa9459Szrj if (slotp != NULL && typenums[0] >= 0 && typenums[1] >= 0)
1193a9fa9459Szrj *slotp = stab_find_slot (info, typenums);
1194a9fa9459Szrj
1195a9fa9459Szrj /* Type is being defined here. */
1196a9fa9459Szrj /* Skip the '='. */
1197a9fa9459Szrj ++*pp;
1198a9fa9459Szrj
1199a9fa9459Szrj while (**pp == '@')
1200a9fa9459Szrj {
1201a9fa9459Szrj const char *p = *pp + 1;
1202a9fa9459Szrj const char *attr;
1203a9fa9459Szrj
1204a9fa9459Szrj if (ISDIGIT (*p) || *p == '(' || *p == '-')
1205a9fa9459Szrj /* Member type. */
1206a9fa9459Szrj break;
1207a9fa9459Szrj
1208a9fa9459Szrj /* Type attributes. */
1209a9fa9459Szrj attr = p;
1210a9fa9459Szrj
1211a9fa9459Szrj for (; *p != ';'; ++p)
1212a9fa9459Szrj {
1213a9fa9459Szrj if (*p == '\0')
1214a9fa9459Szrj {
1215a9fa9459Szrj bad_stab (orig);
1216a9fa9459Szrj return DEBUG_TYPE_NULL;
1217a9fa9459Szrj }
1218a9fa9459Szrj }
1219a9fa9459Szrj *pp = p + 1;
1220a9fa9459Szrj
1221a9fa9459Szrj switch (*attr)
1222a9fa9459Szrj {
1223a9fa9459Szrj case 's':
1224a9fa9459Szrj size = atoi (attr + 1);
1225a9fa9459Szrj size /= 8; /* Size is in bits. We store it in bytes. */
1226a9fa9459Szrj if (size <= 0)
1227a9fa9459Szrj size = -1;
1228a9fa9459Szrj break;
1229a9fa9459Szrj
1230a9fa9459Szrj case 'S':
1231a9fa9459Szrj stringp = TRUE;
1232a9fa9459Szrj break;
1233a9fa9459Szrj
1234a9fa9459Szrj default:
1235a9fa9459Szrj /* Ignore unrecognized type attributes, so future
1236a9fa9459Szrj compilers can invent new ones. */
1237a9fa9459Szrj break;
1238a9fa9459Szrj }
1239a9fa9459Szrj }
1240a9fa9459Szrj }
1241a9fa9459Szrj
1242a9fa9459Szrj descriptor = **pp;
1243a9fa9459Szrj ++*pp;
1244a9fa9459Szrj
1245a9fa9459Szrj switch (descriptor)
1246a9fa9459Szrj {
1247a9fa9459Szrj case 'x':
1248a9fa9459Szrj {
1249a9fa9459Szrj enum debug_type_kind code;
1250a9fa9459Szrj const char *q1, *q2, *p;
1251a9fa9459Szrj
1252a9fa9459Szrj /* A cross reference to another type. */
1253a9fa9459Szrj switch (**pp)
1254a9fa9459Szrj {
1255a9fa9459Szrj case 's':
1256a9fa9459Szrj code = DEBUG_KIND_STRUCT;
1257a9fa9459Szrj break;
1258a9fa9459Szrj case 'u':
1259a9fa9459Szrj code = DEBUG_KIND_UNION;
1260a9fa9459Szrj break;
1261a9fa9459Szrj case 'e':
1262a9fa9459Szrj code = DEBUG_KIND_ENUM;
1263a9fa9459Szrj break;
1264a9fa9459Szrj default:
1265a9fa9459Szrj /* Complain and keep going, so compilers can invent new
1266a9fa9459Szrj cross-reference types. */
1267a9fa9459Szrj warn_stab (orig, _("unrecognized cross reference type"));
1268a9fa9459Szrj code = DEBUG_KIND_STRUCT;
1269a9fa9459Szrj break;
1270a9fa9459Szrj }
1271a9fa9459Szrj ++*pp;
1272a9fa9459Szrj
1273a9fa9459Szrj q1 = strchr (*pp, '<');
1274a9fa9459Szrj p = strchr (*pp, ':');
1275a9fa9459Szrj if (p == NULL)
1276a9fa9459Szrj {
1277a9fa9459Szrj bad_stab (orig);
1278a9fa9459Szrj return DEBUG_TYPE_NULL;
1279a9fa9459Szrj }
1280a9fa9459Szrj if (q1 != NULL && p > q1 && p[1] == ':')
1281a9fa9459Szrj {
1282a9fa9459Szrj int nest = 0;
1283a9fa9459Szrj
1284a9fa9459Szrj for (q2 = q1; *q2 != '\0'; ++q2)
1285a9fa9459Szrj {
1286a9fa9459Szrj if (*q2 == '<')
1287a9fa9459Szrj ++nest;
1288a9fa9459Szrj else if (*q2 == '>')
1289a9fa9459Szrj --nest;
1290a9fa9459Szrj else if (*q2 == ':' && nest == 0)
1291a9fa9459Szrj break;
1292a9fa9459Szrj }
1293a9fa9459Szrj p = q2;
1294a9fa9459Szrj if (*p != ':')
1295a9fa9459Szrj {
1296a9fa9459Szrj bad_stab (orig);
1297a9fa9459Szrj return DEBUG_TYPE_NULL;
1298a9fa9459Szrj }
1299a9fa9459Szrj }
1300a9fa9459Szrj
1301a9fa9459Szrj /* Some versions of g++ can emit stabs like
1302a9fa9459Szrj fleep:T20=xsfleep:
1303a9fa9459Szrj which define structures in terms of themselves. We need to
1304a9fa9459Szrj tell the caller to avoid building a circular structure. */
1305a9fa9459Szrj if (type_name != NULL
1306a9fa9459Szrj && strncmp (type_name, *pp, p - *pp) == 0
1307a9fa9459Szrj && type_name[p - *pp] == '\0')
1308a9fa9459Szrj info->self_crossref = TRUE;
1309a9fa9459Szrj
1310a9fa9459Szrj dtype = stab_find_tagged_type (dhandle, info, *pp, p - *pp, code);
1311a9fa9459Szrj
1312a9fa9459Szrj *pp = p + 1;
1313a9fa9459Szrj }
1314a9fa9459Szrj break;
1315a9fa9459Szrj
1316a9fa9459Szrj case '-':
1317a9fa9459Szrj case '0':
1318a9fa9459Szrj case '1':
1319a9fa9459Szrj case '2':
1320a9fa9459Szrj case '3':
1321a9fa9459Szrj case '4':
1322a9fa9459Szrj case '5':
1323a9fa9459Szrj case '6':
1324a9fa9459Szrj case '7':
1325a9fa9459Szrj case '8':
1326a9fa9459Szrj case '9':
1327a9fa9459Szrj case '(':
1328a9fa9459Szrj {
1329a9fa9459Szrj const char *hold;
1330a9fa9459Szrj int xtypenums[2];
1331a9fa9459Szrj
1332a9fa9459Szrj /* This type is defined as another type. */
1333a9fa9459Szrj (*pp)--;
1334a9fa9459Szrj hold = *pp;
1335a9fa9459Szrj
1336a9fa9459Szrj /* Peek ahead at the number to detect void. */
1337a9fa9459Szrj if (! parse_stab_type_number (pp, xtypenums))
1338a9fa9459Szrj return DEBUG_TYPE_NULL;
1339a9fa9459Szrj
1340a9fa9459Szrj if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1])
1341a9fa9459Szrj {
1342a9fa9459Szrj /* This type is being defined as itself, which means that
1343a9fa9459Szrj it is void. */
1344a9fa9459Szrj dtype = debug_make_void_type (dhandle);
1345a9fa9459Szrj }
1346a9fa9459Szrj else
1347a9fa9459Szrj {
1348a9fa9459Szrj *pp = hold;
1349a9fa9459Szrj
1350a9fa9459Szrj /* Go back to the number and have parse_stab_type get it.
1351a9fa9459Szrj This means that we can deal with something like
1352a9fa9459Szrj t(1,2)=(3,4)=... which the Lucid compiler uses. */
1353a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL,
1354a9fa9459Szrj pp, (debug_type **) NULL);
1355a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL)
1356a9fa9459Szrj return DEBUG_TYPE_NULL;
1357a9fa9459Szrj }
1358a9fa9459Szrj
1359a9fa9459Szrj if (typenums[0] != -1)
1360a9fa9459Szrj {
1361a9fa9459Szrj if (! stab_record_type (dhandle, info, typenums, dtype))
1362a9fa9459Szrj return DEBUG_TYPE_NULL;
1363a9fa9459Szrj }
1364a9fa9459Szrj
1365a9fa9459Szrj break;
1366a9fa9459Szrj }
1367a9fa9459Szrj
1368a9fa9459Szrj case '*':
1369a9fa9459Szrj dtype = debug_make_pointer_type (dhandle,
1370a9fa9459Szrj parse_stab_type (dhandle, info,
1371a9fa9459Szrj (const char *) NULL,
1372a9fa9459Szrj pp,
1373a9fa9459Szrj (debug_type **) NULL));
1374a9fa9459Szrj break;
1375a9fa9459Szrj
1376a9fa9459Szrj case '&':
1377a9fa9459Szrj /* Reference to another type. */
1378a9fa9459Szrj dtype = (debug_make_reference_type
1379a9fa9459Szrj (dhandle,
1380a9fa9459Szrj parse_stab_type (dhandle, info, (const char *) NULL, pp,
1381a9fa9459Szrj (debug_type **) NULL)));
1382a9fa9459Szrj break;
1383a9fa9459Szrj
1384a9fa9459Szrj case 'f':
1385a9fa9459Szrj /* Function returning another type. */
1386a9fa9459Szrj /* FIXME: gdb checks os9k_stabs here. */
1387a9fa9459Szrj dtype = (debug_make_function_type
1388a9fa9459Szrj (dhandle,
1389a9fa9459Szrj parse_stab_type (dhandle, info, (const char *) NULL, pp,
1390a9fa9459Szrj (debug_type **) NULL),
1391a9fa9459Szrj (debug_type *) NULL, FALSE));
1392a9fa9459Szrj break;
1393a9fa9459Szrj
1394a9fa9459Szrj case 'k':
1395a9fa9459Szrj /* Const qualifier on some type (Sun). */
1396a9fa9459Szrj /* FIXME: gdb accepts 'c' here if os9k_stabs. */
1397a9fa9459Szrj dtype = debug_make_const_type (dhandle,
1398a9fa9459Szrj parse_stab_type (dhandle, info,
1399a9fa9459Szrj (const char *) NULL,
1400a9fa9459Szrj pp,
1401a9fa9459Szrj (debug_type **) NULL));
1402a9fa9459Szrj break;
1403a9fa9459Szrj
1404a9fa9459Szrj case 'B':
1405a9fa9459Szrj /* Volatile qual on some type (Sun). */
1406a9fa9459Szrj /* FIXME: gdb accepts 'i' here if os9k_stabs. */
1407a9fa9459Szrj dtype = (debug_make_volatile_type
1408a9fa9459Szrj (dhandle,
1409a9fa9459Szrj parse_stab_type (dhandle, info, (const char *) NULL, pp,
1410a9fa9459Szrj (debug_type **) NULL)));
1411a9fa9459Szrj break;
1412a9fa9459Szrj
1413a9fa9459Szrj case '@':
1414a9fa9459Szrj /* Offset (class & variable) type. This is used for a pointer
1415a9fa9459Szrj relative to an object. */
1416a9fa9459Szrj {
1417a9fa9459Szrj debug_type domain;
1418a9fa9459Szrj debug_type memtype;
1419a9fa9459Szrj
1420a9fa9459Szrj /* Member type. */
1421a9fa9459Szrj
1422a9fa9459Szrj domain = parse_stab_type (dhandle, info, (const char *) NULL, pp,
1423a9fa9459Szrj (debug_type **) NULL);
1424a9fa9459Szrj if (domain == DEBUG_TYPE_NULL)
1425a9fa9459Szrj return DEBUG_TYPE_NULL;
1426a9fa9459Szrj
1427a9fa9459Szrj if (**pp != ',')
1428a9fa9459Szrj {
1429a9fa9459Szrj bad_stab (orig);
1430a9fa9459Szrj return DEBUG_TYPE_NULL;
1431a9fa9459Szrj }
1432a9fa9459Szrj ++*pp;
1433a9fa9459Szrj
1434a9fa9459Szrj memtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
1435a9fa9459Szrj (debug_type **) NULL);
1436a9fa9459Szrj if (memtype == DEBUG_TYPE_NULL)
1437a9fa9459Szrj return DEBUG_TYPE_NULL;
1438a9fa9459Szrj
1439a9fa9459Szrj dtype = debug_make_offset_type (dhandle, domain, memtype);
1440a9fa9459Szrj }
1441a9fa9459Szrj break;
1442a9fa9459Szrj
1443a9fa9459Szrj case '#':
1444a9fa9459Szrj /* Method (class & fn) type. */
1445a9fa9459Szrj if (**pp == '#')
1446a9fa9459Szrj {
1447a9fa9459Szrj debug_type return_type;
1448a9fa9459Szrj
1449a9fa9459Szrj ++*pp;
1450a9fa9459Szrj return_type = parse_stab_type (dhandle, info, (const char *) NULL,
1451a9fa9459Szrj pp, (debug_type **) NULL);
1452a9fa9459Szrj if (return_type == DEBUG_TYPE_NULL)
1453a9fa9459Szrj return DEBUG_TYPE_NULL;
1454a9fa9459Szrj if (**pp != ';')
1455a9fa9459Szrj {
1456a9fa9459Szrj bad_stab (orig);
1457a9fa9459Szrj return DEBUG_TYPE_NULL;
1458a9fa9459Szrj }
1459a9fa9459Szrj ++*pp;
1460a9fa9459Szrj dtype = debug_make_method_type (dhandle, return_type,
1461a9fa9459Szrj DEBUG_TYPE_NULL,
1462a9fa9459Szrj (debug_type *) NULL, FALSE);
1463a9fa9459Szrj }
1464a9fa9459Szrj else
1465a9fa9459Szrj {
1466a9fa9459Szrj debug_type domain;
1467a9fa9459Szrj debug_type return_type;
1468a9fa9459Szrj debug_type *args;
1469a9fa9459Szrj unsigned int n;
1470a9fa9459Szrj unsigned int alloc;
1471a9fa9459Szrj bfd_boolean varargs;
1472a9fa9459Szrj
1473a9fa9459Szrj domain = parse_stab_type (dhandle, info, (const char *) NULL,
1474a9fa9459Szrj pp, (debug_type **) NULL);
1475a9fa9459Szrj if (domain == DEBUG_TYPE_NULL)
1476a9fa9459Szrj return DEBUG_TYPE_NULL;
1477a9fa9459Szrj
1478a9fa9459Szrj if (**pp != ',')
1479a9fa9459Szrj {
1480a9fa9459Szrj bad_stab (orig);
1481a9fa9459Szrj return DEBUG_TYPE_NULL;
1482a9fa9459Szrj }
1483a9fa9459Szrj ++*pp;
1484a9fa9459Szrj
1485a9fa9459Szrj return_type = parse_stab_type (dhandle, info, (const char *) NULL,
1486a9fa9459Szrj pp, (debug_type **) NULL);
1487a9fa9459Szrj if (return_type == DEBUG_TYPE_NULL)
1488a9fa9459Szrj return DEBUG_TYPE_NULL;
1489a9fa9459Szrj
1490a9fa9459Szrj alloc = 10;
1491a9fa9459Szrj args = (debug_type *) xmalloc (alloc * sizeof *args);
1492a9fa9459Szrj n = 0;
1493a9fa9459Szrj while (**pp != ';')
1494a9fa9459Szrj {
1495a9fa9459Szrj if (**pp != ',')
1496a9fa9459Szrj {
1497a9fa9459Szrj bad_stab (orig);
1498a9fa9459Szrj return DEBUG_TYPE_NULL;
1499a9fa9459Szrj }
1500a9fa9459Szrj ++*pp;
1501a9fa9459Szrj
1502a9fa9459Szrj if (n + 1 >= alloc)
1503a9fa9459Szrj {
1504a9fa9459Szrj alloc += 10;
1505a9fa9459Szrj args = ((debug_type *)
1506a9fa9459Szrj xrealloc (args, alloc * sizeof *args));
1507a9fa9459Szrj }
1508a9fa9459Szrj
1509a9fa9459Szrj args[n] = parse_stab_type (dhandle, info, (const char *) NULL,
1510a9fa9459Szrj pp, (debug_type **) NULL);
1511a9fa9459Szrj if (args[n] == DEBUG_TYPE_NULL)
1512a9fa9459Szrj return DEBUG_TYPE_NULL;
1513a9fa9459Szrj ++n;
1514a9fa9459Szrj }
1515a9fa9459Szrj ++*pp;
1516a9fa9459Szrj
1517a9fa9459Szrj /* If the last type is not void, then this function takes a
1518a9fa9459Szrj variable number of arguments. Otherwise, we must strip
1519a9fa9459Szrj the void type. */
1520a9fa9459Szrj if (n == 0
1521a9fa9459Szrj || debug_get_type_kind (dhandle, args[n - 1]) != DEBUG_KIND_VOID)
1522a9fa9459Szrj varargs = TRUE;
1523a9fa9459Szrj else
1524a9fa9459Szrj {
1525a9fa9459Szrj --n;
1526a9fa9459Szrj varargs = FALSE;
1527a9fa9459Szrj }
1528a9fa9459Szrj
1529a9fa9459Szrj args[n] = DEBUG_TYPE_NULL;
1530a9fa9459Szrj
1531a9fa9459Szrj dtype = debug_make_method_type (dhandle, return_type, domain, args,
1532a9fa9459Szrj varargs);
1533a9fa9459Szrj }
1534a9fa9459Szrj break;
1535a9fa9459Szrj
1536a9fa9459Szrj case 'r':
1537a9fa9459Szrj /* Range type. */
1538a9fa9459Szrj dtype = parse_stab_range_type (dhandle, info, type_name, pp, typenums);
1539a9fa9459Szrj break;
1540a9fa9459Szrj
1541a9fa9459Szrj case 'b':
1542a9fa9459Szrj /* FIXME: gdb checks os9k_stabs here. */
1543a9fa9459Szrj /* Sun ACC builtin int type. */
1544a9fa9459Szrj dtype = parse_stab_sun_builtin_type (dhandle, pp);
1545a9fa9459Szrj break;
1546a9fa9459Szrj
1547a9fa9459Szrj case 'R':
1548a9fa9459Szrj /* Sun ACC builtin float type. */
1549a9fa9459Szrj dtype = parse_stab_sun_floating_type (dhandle, pp);
1550a9fa9459Szrj break;
1551a9fa9459Szrj
1552a9fa9459Szrj case 'e':
1553a9fa9459Szrj /* Enumeration type. */
1554a9fa9459Szrj dtype = parse_stab_enum_type (dhandle, pp);
1555a9fa9459Szrj break;
1556a9fa9459Szrj
1557a9fa9459Szrj case 's':
1558a9fa9459Szrj case 'u':
1559a9fa9459Szrj /* Struct or union type. */
1560a9fa9459Szrj dtype = parse_stab_struct_type (dhandle, info, type_name, pp,
1561a9fa9459Szrj descriptor == 's', typenums);
1562a9fa9459Szrj break;
1563a9fa9459Szrj
1564a9fa9459Szrj case 'a':
1565a9fa9459Szrj /* Array type. */
1566a9fa9459Szrj if (**pp != 'r')
1567a9fa9459Szrj {
1568a9fa9459Szrj bad_stab (orig);
1569a9fa9459Szrj return DEBUG_TYPE_NULL;
1570a9fa9459Szrj }
1571a9fa9459Szrj ++*pp;
1572a9fa9459Szrj
1573a9fa9459Szrj dtype = parse_stab_array_type (dhandle, info, pp, stringp);
1574a9fa9459Szrj break;
1575a9fa9459Szrj
1576a9fa9459Szrj case 'S':
1577a9fa9459Szrj dtype = debug_make_set_type (dhandle,
1578a9fa9459Szrj parse_stab_type (dhandle, info,
1579a9fa9459Szrj (const char *) NULL,
1580a9fa9459Szrj pp,
1581a9fa9459Szrj (debug_type **) NULL),
1582a9fa9459Szrj stringp);
1583a9fa9459Szrj break;
1584a9fa9459Szrj
1585a9fa9459Szrj default:
1586a9fa9459Szrj bad_stab (orig);
1587a9fa9459Szrj return DEBUG_TYPE_NULL;
1588a9fa9459Szrj }
1589a9fa9459Szrj
1590a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL)
1591a9fa9459Szrj return DEBUG_TYPE_NULL;
1592a9fa9459Szrj
1593a9fa9459Szrj if (typenums[0] != -1)
1594a9fa9459Szrj {
1595a9fa9459Szrj if (! stab_record_type (dhandle, info, typenums, dtype))
1596a9fa9459Szrj return DEBUG_TYPE_NULL;
1597a9fa9459Szrj }
1598a9fa9459Szrj
1599a9fa9459Szrj if (size != -1)
1600a9fa9459Szrj {
1601a9fa9459Szrj if (! debug_record_type_size (dhandle, dtype, (unsigned int) size))
1602a9fa9459Szrj return DEBUG_TYPE_NULL;
1603a9fa9459Szrj }
1604a9fa9459Szrj
1605a9fa9459Szrj return dtype;
1606a9fa9459Szrj }
1607a9fa9459Szrj
1608a9fa9459Szrj /* Read a number by which a type is referred to in dbx data, or
1609a9fa9459Szrj perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a
1610a9fa9459Szrj single number N is equivalent to (0,N). Return the two numbers by
1611a9fa9459Szrj storing them in the vector TYPENUMS. */
1612a9fa9459Szrj
1613a9fa9459Szrj static bfd_boolean
parse_stab_type_number(const char ** pp,int * typenums)1614a9fa9459Szrj parse_stab_type_number (const char **pp, int *typenums)
1615a9fa9459Szrj {
1616a9fa9459Szrj const char *orig;
1617a9fa9459Szrj
1618a9fa9459Szrj orig = *pp;
1619a9fa9459Szrj
1620a9fa9459Szrj if (**pp != '(')
1621a9fa9459Szrj {
1622a9fa9459Szrj typenums[0] = 0;
1623a9fa9459Szrj typenums[1] = (int) parse_number (pp, (bfd_boolean *) NULL);
1624a9fa9459Szrj }
1625a9fa9459Szrj else
1626a9fa9459Szrj {
1627a9fa9459Szrj ++*pp;
1628a9fa9459Szrj typenums[0] = (int) parse_number (pp, (bfd_boolean *) NULL);
1629a9fa9459Szrj if (**pp != ',')
1630a9fa9459Szrj {
1631a9fa9459Szrj bad_stab (orig);
1632a9fa9459Szrj return FALSE;
1633a9fa9459Szrj }
1634a9fa9459Szrj ++*pp;
1635a9fa9459Szrj typenums[1] = (int) parse_number (pp, (bfd_boolean *) NULL);
1636a9fa9459Szrj if (**pp != ')')
1637a9fa9459Szrj {
1638a9fa9459Szrj bad_stab (orig);
1639a9fa9459Szrj return FALSE;
1640a9fa9459Szrj }
1641a9fa9459Szrj ++*pp;
1642a9fa9459Szrj }
1643a9fa9459Szrj
1644a9fa9459Szrj return TRUE;
1645a9fa9459Szrj }
1646a9fa9459Szrj
1647a9fa9459Szrj /* Parse a range type. */
1648a9fa9459Szrj
1649a9fa9459Szrj static debug_type
parse_stab_range_type(void * dhandle,struct stab_handle * info,const char * type_name,const char ** pp,const int * typenums)1650a9fa9459Szrj parse_stab_range_type (void *dhandle, struct stab_handle *info, const char *type_name, const char **pp, const int *typenums)
1651a9fa9459Szrj {
1652a9fa9459Szrj const char *orig;
1653a9fa9459Szrj int rangenums[2];
1654a9fa9459Szrj bfd_boolean self_subrange;
1655a9fa9459Szrj debug_type index_type;
1656a9fa9459Szrj const char *s2, *s3;
1657a9fa9459Szrj bfd_signed_vma n2, n3;
1658a9fa9459Szrj bfd_boolean ov2, ov3;
1659a9fa9459Szrj
1660a9fa9459Szrj orig = *pp;
1661a9fa9459Szrj
1662a9fa9459Szrj index_type = DEBUG_TYPE_NULL;
1663a9fa9459Szrj
1664a9fa9459Szrj /* First comes a type we are a subrange of.
1665a9fa9459Szrj In C it is usually 0, 1 or the type being defined. */
1666a9fa9459Szrj if (! parse_stab_type_number (pp, rangenums))
1667a9fa9459Szrj return DEBUG_TYPE_NULL;
1668a9fa9459Szrj
1669a9fa9459Szrj self_subrange = (rangenums[0] == typenums[0]
1670a9fa9459Szrj && rangenums[1] == typenums[1]);
1671a9fa9459Szrj
1672a9fa9459Szrj if (**pp == '=')
1673a9fa9459Szrj {
1674a9fa9459Szrj *pp = orig;
1675a9fa9459Szrj index_type = parse_stab_type (dhandle, info, (const char *) NULL,
1676a9fa9459Szrj pp, (debug_type **) NULL);
1677a9fa9459Szrj if (index_type == DEBUG_TYPE_NULL)
1678a9fa9459Szrj return DEBUG_TYPE_NULL;
1679a9fa9459Szrj }
1680a9fa9459Szrj
1681a9fa9459Szrj if (**pp == ';')
1682a9fa9459Szrj ++*pp;
1683a9fa9459Szrj
1684a9fa9459Szrj /* The remaining two operands are usually lower and upper bounds of
1685a9fa9459Szrj the range. But in some special cases they mean something else. */
1686a9fa9459Szrj s2 = *pp;
1687a9fa9459Szrj n2 = parse_number (pp, &ov2);
1688a9fa9459Szrj if (**pp != ';')
1689a9fa9459Szrj {
1690a9fa9459Szrj bad_stab (orig);
1691a9fa9459Szrj return DEBUG_TYPE_NULL;
1692a9fa9459Szrj }
1693a9fa9459Szrj ++*pp;
1694a9fa9459Szrj
1695a9fa9459Szrj s3 = *pp;
1696a9fa9459Szrj n3 = parse_number (pp, &ov3);
1697a9fa9459Szrj if (**pp != ';')
1698a9fa9459Szrj {
1699a9fa9459Szrj bad_stab (orig);
1700a9fa9459Szrj return DEBUG_TYPE_NULL;
1701a9fa9459Szrj }
1702a9fa9459Szrj ++*pp;
1703a9fa9459Szrj
1704a9fa9459Szrj if (ov2 || ov3)
1705a9fa9459Szrj {
1706a9fa9459Szrj /* gcc will emit range stabs for long long types. Handle this
1707a9fa9459Szrj as a special case. FIXME: This needs to be more general. */
1708a9fa9459Szrj #define LLLOW "01000000000000000000000;"
1709a9fa9459Szrj #define LLHIGH "0777777777777777777777;"
1710a9fa9459Szrj #define ULLHIGH "01777777777777777777777;"
1711a9fa9459Szrj if (index_type == DEBUG_TYPE_NULL)
1712a9fa9459Szrj {
1713a9fa9459Szrj if (CONST_STRNEQ (s2, LLLOW)
1714a9fa9459Szrj && CONST_STRNEQ (s3, LLHIGH))
1715a9fa9459Szrj return debug_make_int_type (dhandle, 8, FALSE);
1716a9fa9459Szrj if (! ov2
1717a9fa9459Szrj && n2 == 0
1718a9fa9459Szrj && CONST_STRNEQ (s3, ULLHIGH))
1719a9fa9459Szrj return debug_make_int_type (dhandle, 8, TRUE);
1720a9fa9459Szrj }
1721a9fa9459Szrj
1722a9fa9459Szrj warn_stab (orig, _("numeric overflow"));
1723a9fa9459Szrj }
1724a9fa9459Szrj
1725a9fa9459Szrj if (index_type == DEBUG_TYPE_NULL)
1726a9fa9459Szrj {
1727a9fa9459Szrj /* A type defined as a subrange of itself, with both bounds 0,
1728a9fa9459Szrj is void. */
1729a9fa9459Szrj if (self_subrange && n2 == 0 && n3 == 0)
1730a9fa9459Szrj return debug_make_void_type (dhandle);
1731a9fa9459Szrj
1732a9fa9459Szrj /* A type defined as a subrange of itself, with n2 positive and
1733a9fa9459Szrj n3 zero, is a complex type, and n2 is the number of bytes. */
1734a9fa9459Szrj if (self_subrange && n3 == 0 && n2 > 0)
1735a9fa9459Szrj return debug_make_complex_type (dhandle, n2);
1736a9fa9459Szrj
1737a9fa9459Szrj /* If n3 is zero and n2 is positive, this is a floating point
1738a9fa9459Szrj type, and n2 is the number of bytes. */
1739a9fa9459Szrj if (n3 == 0 && n2 > 0)
1740a9fa9459Szrj return debug_make_float_type (dhandle, n2);
1741a9fa9459Szrj
1742a9fa9459Szrj /* If the upper bound is -1, this is an unsigned int. */
1743a9fa9459Szrj if (n2 == 0 && n3 == -1)
1744a9fa9459Szrj {
1745a9fa9459Szrj /* When gcc is used with -gstabs, but not -gstabs+, it will emit
1746a9fa9459Szrj long long int:t6=r1;0;-1;
1747a9fa9459Szrj long long unsigned int:t7=r1;0;-1;
1748a9fa9459Szrj We hack here to handle this reasonably. */
1749a9fa9459Szrj if (type_name != NULL)
1750a9fa9459Szrj {
1751a9fa9459Szrj if (strcmp (type_name, "long long int") == 0)
1752a9fa9459Szrj return debug_make_int_type (dhandle, 8, FALSE);
1753a9fa9459Szrj else if (strcmp (type_name, "long long unsigned int") == 0)
1754a9fa9459Szrj return debug_make_int_type (dhandle, 8, TRUE);
1755a9fa9459Szrj }
1756a9fa9459Szrj /* FIXME: The size here really depends upon the target. */
1757a9fa9459Szrj return debug_make_int_type (dhandle, 4, TRUE);
1758a9fa9459Szrj }
1759a9fa9459Szrj
1760a9fa9459Szrj /* A range of 0 to 127 is char. */
1761a9fa9459Szrj if (self_subrange && n2 == 0 && n3 == 127)
1762a9fa9459Szrj return debug_make_int_type (dhandle, 1, FALSE);
1763a9fa9459Szrj
1764a9fa9459Szrj /* FIXME: gdb checks for the language CHILL here. */
1765a9fa9459Szrj
1766a9fa9459Szrj if (n2 == 0)
1767a9fa9459Szrj {
1768a9fa9459Szrj if (n3 < 0)
1769a9fa9459Szrj return debug_make_int_type (dhandle, - n3, TRUE);
1770a9fa9459Szrj else if (n3 == 0xff)
1771a9fa9459Szrj return debug_make_int_type (dhandle, 1, TRUE);
1772a9fa9459Szrj else if (n3 == 0xffff)
1773a9fa9459Szrj return debug_make_int_type (dhandle, 2, TRUE);
1774a9fa9459Szrj else if (n3 == (bfd_signed_vma) 0xffffffff)
1775a9fa9459Szrj return debug_make_int_type (dhandle, 4, TRUE);
1776a9fa9459Szrj #ifdef BFD64
1777a9fa9459Szrj else if (n3 == (bfd_signed_vma) 0xffffffffffffffffLL)
1778a9fa9459Szrj return debug_make_int_type (dhandle, 8, TRUE);
1779a9fa9459Szrj #endif
1780a9fa9459Szrj }
1781a9fa9459Szrj else if (n3 == 0
1782a9fa9459Szrj && n2 < 0
1783a9fa9459Szrj && (self_subrange || n2 == -8))
1784a9fa9459Szrj return debug_make_int_type (dhandle, - n2, TRUE);
1785a9fa9459Szrj else if (n2 == - n3 - 1 || n2 == n3 + 1)
1786a9fa9459Szrj {
1787a9fa9459Szrj if (n3 == 0x7f)
1788a9fa9459Szrj return debug_make_int_type (dhandle, 1, FALSE);
1789a9fa9459Szrj else if (n3 == 0x7fff)
1790a9fa9459Szrj return debug_make_int_type (dhandle, 2, FALSE);
1791a9fa9459Szrj else if (n3 == 0x7fffffff)
1792a9fa9459Szrj return debug_make_int_type (dhandle, 4, FALSE);
1793a9fa9459Szrj #ifdef BFD64
1794a9fa9459Szrj else if (n3 == ((((bfd_vma) 0x7fffffff) << 32) | 0xffffffff))
1795a9fa9459Szrj return debug_make_int_type (dhandle, 8, FALSE);
1796a9fa9459Szrj #endif
1797a9fa9459Szrj }
1798a9fa9459Szrj }
1799a9fa9459Szrj
1800a9fa9459Szrj /* At this point I don't have the faintest idea how to deal with a
1801a9fa9459Szrj self_subrange type; I'm going to assume that this is used as an
1802a9fa9459Szrj idiom, and that all of them are special cases. So . . . */
1803a9fa9459Szrj if (self_subrange)
1804a9fa9459Szrj {
1805a9fa9459Szrj bad_stab (orig);
1806a9fa9459Szrj return DEBUG_TYPE_NULL;
1807a9fa9459Szrj }
1808a9fa9459Szrj
1809a9fa9459Szrj index_type = stab_find_type (dhandle, info, rangenums);
1810a9fa9459Szrj if (index_type == DEBUG_TYPE_NULL)
1811a9fa9459Szrj {
1812a9fa9459Szrj /* Does this actually ever happen? Is that why we are worrying
1813a9fa9459Szrj about dealing with it rather than just calling error_type? */
1814a9fa9459Szrj warn_stab (orig, _("missing index type"));
1815a9fa9459Szrj index_type = debug_make_int_type (dhandle, 4, FALSE);
1816a9fa9459Szrj }
1817a9fa9459Szrj
1818a9fa9459Szrj return debug_make_range_type (dhandle, index_type, n2, n3);
1819a9fa9459Szrj }
1820a9fa9459Szrj
1821a9fa9459Szrj /* Sun's ACC uses a somewhat saner method for specifying the builtin
1822a9fa9459Szrj typedefs in every file (for int, long, etc):
1823a9fa9459Szrj
1824a9fa9459Szrj type = b <signed> <width>; <offset>; <nbits>
1825a9fa9459Szrj signed = u or s. Possible c in addition to u or s (for char?).
1826a9fa9459Szrj offset = offset from high order bit to start bit of type.
1827a9fa9459Szrj width is # bytes in object of this type, nbits is # bits in type.
1828a9fa9459Szrj
1829a9fa9459Szrj The width/offset stuff appears to be for small objects stored in
1830a9fa9459Szrj larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
1831a9fa9459Szrj FIXME. */
1832a9fa9459Szrj
1833a9fa9459Szrj static debug_type
parse_stab_sun_builtin_type(void * dhandle,const char ** pp)1834a9fa9459Szrj parse_stab_sun_builtin_type (void *dhandle, const char **pp)
1835a9fa9459Szrj {
1836a9fa9459Szrj const char *orig;
1837a9fa9459Szrj bfd_boolean unsignedp;
1838a9fa9459Szrj bfd_vma bits;
1839a9fa9459Szrj
1840a9fa9459Szrj orig = *pp;
1841a9fa9459Szrj
1842a9fa9459Szrj switch (**pp)
1843a9fa9459Szrj {
1844a9fa9459Szrj case 's':
1845a9fa9459Szrj unsignedp = FALSE;
1846a9fa9459Szrj break;
1847a9fa9459Szrj case 'u':
1848a9fa9459Szrj unsignedp = TRUE;
1849a9fa9459Szrj break;
1850a9fa9459Szrj default:
1851a9fa9459Szrj bad_stab (orig);
1852a9fa9459Szrj return DEBUG_TYPE_NULL;
1853a9fa9459Szrj }
1854a9fa9459Szrj ++*pp;
1855a9fa9459Szrj
1856a9fa9459Szrj /* OpenSolaris source code indicates that one of "cbv" characters
1857a9fa9459Szrj can come next and specify the intrinsic 'iformat' encoding.
1858a9fa9459Szrj 'c' is character encoding, 'b' is boolean encoding, and 'v' is
1859a9fa9459Szrj varargs encoding. This field can be safely ignored because
1860a9fa9459Szrj the type of the field is determined from the bitwidth extracted
1861a9fa9459Szrj below. */
1862a9fa9459Szrj if (**pp == 'c' || **pp == 'b' || **pp == 'v')
1863a9fa9459Szrj ++*pp;
1864a9fa9459Szrj
1865a9fa9459Szrj /* The first number appears to be the number of bytes occupied
1866a9fa9459Szrj by this type, except that unsigned short is 4 instead of 2.
1867a9fa9459Szrj Since this information is redundant with the third number,
1868a9fa9459Szrj we will ignore it. */
1869a9fa9459Szrj (void) parse_number (pp, (bfd_boolean *) NULL);
1870a9fa9459Szrj if (**pp != ';')
1871a9fa9459Szrj {
1872a9fa9459Szrj bad_stab (orig);
1873a9fa9459Szrj return DEBUG_TYPE_NULL;
1874a9fa9459Szrj }
1875a9fa9459Szrj ++*pp;
1876a9fa9459Szrj
1877a9fa9459Szrj /* The second number is always 0, so ignore it too. */
1878a9fa9459Szrj (void) parse_number (pp, (bfd_boolean *) NULL);
1879a9fa9459Szrj if (**pp != ';')
1880a9fa9459Szrj {
1881a9fa9459Szrj bad_stab (orig);
1882a9fa9459Szrj return DEBUG_TYPE_NULL;
1883a9fa9459Szrj }
1884a9fa9459Szrj ++*pp;
1885a9fa9459Szrj
1886a9fa9459Szrj /* The third number is the number of bits for this type. */
1887a9fa9459Szrj bits = parse_number (pp, (bfd_boolean *) NULL);
1888a9fa9459Szrj
1889a9fa9459Szrj /* The type *should* end with a semicolon. If it are embedded
1890a9fa9459Szrj in a larger type the semicolon may be the only way to know where
1891a9fa9459Szrj the type ends. If this type is at the end of the stabstring we
1892a9fa9459Szrj can deal with the omitted semicolon (but we don't have to like
1893a9fa9459Szrj it). Don't bother to complain(), Sun's compiler omits the semicolon
1894a9fa9459Szrj for "void". */
1895a9fa9459Szrj if (**pp == ';')
1896a9fa9459Szrj ++*pp;
1897a9fa9459Szrj
1898a9fa9459Szrj if (bits == 0)
1899a9fa9459Szrj return debug_make_void_type (dhandle);
1900a9fa9459Szrj
1901a9fa9459Szrj return debug_make_int_type (dhandle, bits / 8, unsignedp);
1902a9fa9459Szrj }
1903a9fa9459Szrj
1904a9fa9459Szrj /* Parse a builtin floating type generated by the Sun compiler. */
1905a9fa9459Szrj
1906a9fa9459Szrj static debug_type
parse_stab_sun_floating_type(void * dhandle,const char ** pp)1907a9fa9459Szrj parse_stab_sun_floating_type (void *dhandle, const char **pp)
1908a9fa9459Szrj {
1909a9fa9459Szrj const char *orig;
1910a9fa9459Szrj bfd_vma details;
1911a9fa9459Szrj bfd_vma bytes;
1912a9fa9459Szrj
1913a9fa9459Szrj orig = *pp;
1914a9fa9459Szrj
1915a9fa9459Szrj /* The first number has more details about the type, for example
1916a9fa9459Szrj FN_COMPLEX. */
1917a9fa9459Szrj details = parse_number (pp, (bfd_boolean *) NULL);
1918a9fa9459Szrj if (**pp != ';')
1919a9fa9459Szrj {
1920a9fa9459Szrj bad_stab (orig);
1921a9fa9459Szrj return DEBUG_TYPE_NULL;
1922a9fa9459Szrj }
1923a9fa9459Szrj
1924a9fa9459Szrj /* The second number is the number of bytes occupied by this type */
1925a9fa9459Szrj bytes = parse_number (pp, (bfd_boolean *) NULL);
1926a9fa9459Szrj if (**pp != ';')
1927a9fa9459Szrj {
1928a9fa9459Szrj bad_stab (orig);
1929a9fa9459Szrj return DEBUG_TYPE_NULL;
1930a9fa9459Szrj }
1931a9fa9459Szrj
1932a9fa9459Szrj if (details == NF_COMPLEX
1933a9fa9459Szrj || details == NF_COMPLEX16
1934a9fa9459Szrj || details == NF_COMPLEX32)
1935a9fa9459Szrj return debug_make_complex_type (dhandle, bytes);
1936a9fa9459Szrj
1937a9fa9459Szrj return debug_make_float_type (dhandle, bytes);
1938a9fa9459Szrj }
1939a9fa9459Szrj
1940a9fa9459Szrj /* Handle an enum type. */
1941a9fa9459Szrj
1942a9fa9459Szrj static debug_type
parse_stab_enum_type(void * dhandle,const char ** pp)1943a9fa9459Szrj parse_stab_enum_type (void *dhandle, const char **pp)
1944a9fa9459Szrj {
1945a9fa9459Szrj const char *orig;
1946a9fa9459Szrj const char **names;
1947a9fa9459Szrj bfd_signed_vma *values;
1948a9fa9459Szrj unsigned int n;
1949a9fa9459Szrj unsigned int alloc;
1950a9fa9459Szrj
1951a9fa9459Szrj orig = *pp;
1952a9fa9459Szrj
1953a9fa9459Szrj /* FIXME: gdb checks os9k_stabs here. */
1954a9fa9459Szrj
1955a9fa9459Szrj /* The aix4 compiler emits an extra field before the enum members;
1956a9fa9459Szrj my guess is it's a type of some sort. Just ignore it. */
1957a9fa9459Szrj if (**pp == '-')
1958a9fa9459Szrj {
1959a9fa9459Szrj while (**pp != ':')
1960a9fa9459Szrj ++*pp;
1961a9fa9459Szrj ++*pp;
1962a9fa9459Szrj }
1963a9fa9459Szrj
1964a9fa9459Szrj /* Read the value-names and their values.
1965a9fa9459Szrj The input syntax is NAME:VALUE,NAME:VALUE, and so on.
1966a9fa9459Szrj A semicolon or comma instead of a NAME means the end. */
1967a9fa9459Szrj alloc = 10;
1968a9fa9459Szrj names = (const char **) xmalloc (alloc * sizeof *names);
1969a9fa9459Szrj values = (bfd_signed_vma *) xmalloc (alloc * sizeof *values);
1970a9fa9459Szrj n = 0;
1971a9fa9459Szrj while (**pp != '\0' && **pp != ';' && **pp != ',')
1972a9fa9459Szrj {
1973a9fa9459Szrj const char *p;
1974a9fa9459Szrj char *name;
1975a9fa9459Szrj bfd_signed_vma val;
1976a9fa9459Szrj
1977a9fa9459Szrj p = *pp;
1978a9fa9459Szrj while (*p != ':')
1979a9fa9459Szrj ++p;
1980a9fa9459Szrj
1981a9fa9459Szrj name = savestring (*pp, p - *pp);
1982a9fa9459Szrj
1983a9fa9459Szrj *pp = p + 1;
1984a9fa9459Szrj val = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL);
1985a9fa9459Szrj if (**pp != ',')
1986a9fa9459Szrj {
1987a9fa9459Szrj bad_stab (orig);
1988a9fa9459Szrj free (name);
1989a9fa9459Szrj free (names);
1990a9fa9459Szrj free (values);
1991a9fa9459Szrj return DEBUG_TYPE_NULL;
1992a9fa9459Szrj }
1993a9fa9459Szrj ++*pp;
1994a9fa9459Szrj
1995a9fa9459Szrj if (n + 1 >= alloc)
1996a9fa9459Szrj {
1997a9fa9459Szrj alloc += 10;
1998a9fa9459Szrj names = ((const char **)
1999a9fa9459Szrj xrealloc (names, alloc * sizeof *names));
2000a9fa9459Szrj values = ((bfd_signed_vma *)
2001a9fa9459Szrj xrealloc (values, alloc * sizeof *values));
2002a9fa9459Szrj }
2003a9fa9459Szrj
2004a9fa9459Szrj names[n] = name;
2005a9fa9459Szrj values[n] = val;
2006a9fa9459Szrj ++n;
2007a9fa9459Szrj }
2008a9fa9459Szrj
2009a9fa9459Szrj names[n] = NULL;
2010a9fa9459Szrj values[n] = 0;
2011a9fa9459Szrj
2012a9fa9459Szrj if (**pp == ';')
2013a9fa9459Szrj ++*pp;
2014a9fa9459Szrj
2015a9fa9459Szrj return debug_make_enum_type (dhandle, names, values);
2016a9fa9459Szrj }
2017a9fa9459Szrj
2018a9fa9459Szrj /* Read the description of a structure (or union type) and return an object
2019a9fa9459Szrj describing the type.
2020a9fa9459Szrj
2021a9fa9459Szrj PP points to a character pointer that points to the next unconsumed token
2022a9fa9459Szrj in the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2023a9fa9459Szrj *PP will point to "4a:1,0,32;;". */
2024a9fa9459Szrj
2025a9fa9459Szrj static debug_type
parse_stab_struct_type(void * dhandle,struct stab_handle * info,const char * tagname,const char ** pp,bfd_boolean structp,const int * typenums)2026a9fa9459Szrj parse_stab_struct_type (void *dhandle, struct stab_handle *info,
2027a9fa9459Szrj const char *tagname, const char **pp,
2028a9fa9459Szrj bfd_boolean structp, const int *typenums)
2029a9fa9459Szrj {
2030a9fa9459Szrj bfd_vma size;
2031a9fa9459Szrj debug_baseclass *baseclasses;
2032a9fa9459Szrj debug_field *fields = NULL;
2033a9fa9459Szrj bfd_boolean statics;
2034a9fa9459Szrj debug_method *methods;
2035a9fa9459Szrj debug_type vptrbase;
2036a9fa9459Szrj bfd_boolean ownvptr;
2037a9fa9459Szrj
2038a9fa9459Szrj /* Get the size. */
2039a9fa9459Szrj size = parse_number (pp, (bfd_boolean *) NULL);
2040a9fa9459Szrj
2041a9fa9459Szrj /* Get the other information. */
2042a9fa9459Szrj if (! parse_stab_baseclasses (dhandle, info, pp, &baseclasses)
2043a9fa9459Szrj || ! parse_stab_struct_fields (dhandle, info, pp, &fields, &statics)
2044a9fa9459Szrj || ! parse_stab_members (dhandle, info, tagname, pp, typenums, &methods)
2045a9fa9459Szrj || ! parse_stab_tilde_field (dhandle, info, pp, typenums, &vptrbase,
2046a9fa9459Szrj &ownvptr))
2047a9fa9459Szrj {
2048a9fa9459Szrj if (fields != NULL)
2049a9fa9459Szrj free (fields);
2050a9fa9459Szrj return DEBUG_TYPE_NULL;
2051a9fa9459Szrj }
2052a9fa9459Szrj
2053a9fa9459Szrj if (! statics
2054a9fa9459Szrj && baseclasses == NULL
2055a9fa9459Szrj && methods == NULL
2056a9fa9459Szrj && vptrbase == DEBUG_TYPE_NULL
2057a9fa9459Szrj && ! ownvptr)
2058a9fa9459Szrj return debug_make_struct_type (dhandle, structp, size, fields);
2059a9fa9459Szrj
2060a9fa9459Szrj return debug_make_object_type (dhandle, structp, size, fields, baseclasses,
2061a9fa9459Szrj methods, vptrbase, ownvptr);
2062a9fa9459Szrj }
2063a9fa9459Szrj
2064a9fa9459Szrj /* The stabs for C++ derived classes contain baseclass information which
2065a9fa9459Szrj is marked by a '!' character after the total size. This function is
2066a9fa9459Szrj called when we encounter the baseclass marker, and slurps up all the
2067a9fa9459Szrj baseclass information.
2068a9fa9459Szrj
2069a9fa9459Szrj Immediately following the '!' marker is the number of base classes that
2070a9fa9459Szrj the class is derived from, followed by information for each base class.
2071a9fa9459Szrj For each base class, there are two visibility specifiers, a bit offset
2072a9fa9459Szrj to the base class information within the derived class, a reference to
2073a9fa9459Szrj the type for the base class, and a terminating semicolon.
2074a9fa9459Szrj
2075a9fa9459Szrj A typical example, with two base classes, would be "!2,020,19;0264,21;".
2076a9fa9459Szrj ^^ ^ ^ ^ ^ ^ ^
2077a9fa9459Szrj Baseclass information marker __________________|| | | | | | |
2078a9fa9459Szrj Number of baseclasses __________________________| | | | | | |
2079a9fa9459Szrj Visibility specifiers (2) ________________________| | | | | |
2080a9fa9459Szrj Offset in bits from start of class _________________| | | | |
2081a9fa9459Szrj Type number for base class ___________________________| | | |
2082a9fa9459Szrj Visibility specifiers (2) _______________________________| | |
2083a9fa9459Szrj Offset in bits from start of class ________________________| |
2084a9fa9459Szrj Type number of base class ____________________________________|
2085a9fa9459Szrj
2086a9fa9459Szrj Return TRUE for success, FALSE for failure. */
2087a9fa9459Szrj
2088a9fa9459Szrj static bfd_boolean
parse_stab_baseclasses(void * dhandle,struct stab_handle * info,const char ** pp,debug_baseclass ** retp)2089a9fa9459Szrj parse_stab_baseclasses (void *dhandle, struct stab_handle *info,
2090a9fa9459Szrj const char **pp, debug_baseclass **retp)
2091a9fa9459Szrj {
2092a9fa9459Szrj const char *orig;
2093a9fa9459Szrj unsigned int c, i;
2094a9fa9459Szrj debug_baseclass *classes;
2095a9fa9459Szrj
2096a9fa9459Szrj *retp = NULL;
2097a9fa9459Szrj
2098a9fa9459Szrj orig = *pp;
2099a9fa9459Szrj
2100a9fa9459Szrj if (**pp != '!')
2101a9fa9459Szrj {
2102a9fa9459Szrj /* No base classes. */
2103a9fa9459Szrj return TRUE;
2104a9fa9459Szrj }
2105a9fa9459Szrj ++*pp;
2106a9fa9459Szrj
2107a9fa9459Szrj c = (unsigned int) parse_number (pp, (bfd_boolean *) NULL);
2108a9fa9459Szrj
2109a9fa9459Szrj if (**pp != ',')
2110a9fa9459Szrj {
2111a9fa9459Szrj bad_stab (orig);
2112a9fa9459Szrj return FALSE;
2113a9fa9459Szrj }
2114a9fa9459Szrj ++*pp;
2115a9fa9459Szrj
2116a9fa9459Szrj classes = (debug_baseclass *) xmalloc ((c + 1) * sizeof (**retp));
2117a9fa9459Szrj
2118a9fa9459Szrj for (i = 0; i < c; i++)
2119a9fa9459Szrj {
2120a9fa9459Szrj bfd_boolean is_virtual;
2121a9fa9459Szrj enum debug_visibility visibility;
2122a9fa9459Szrj bfd_vma bitpos;
2123a9fa9459Szrj debug_type type;
2124a9fa9459Szrj
2125a9fa9459Szrj switch (**pp)
2126a9fa9459Szrj {
2127a9fa9459Szrj case '0':
2128a9fa9459Szrj is_virtual = FALSE;
2129a9fa9459Szrj break;
2130a9fa9459Szrj case '1':
2131a9fa9459Szrj is_virtual = TRUE;
2132a9fa9459Szrj break;
2133a9fa9459Szrj default:
2134a9fa9459Szrj warn_stab (orig, _("unknown virtual character for baseclass"));
2135a9fa9459Szrj is_virtual = FALSE;
2136a9fa9459Szrj break;
2137a9fa9459Szrj }
2138a9fa9459Szrj ++*pp;
2139a9fa9459Szrj
2140a9fa9459Szrj switch (**pp)
2141a9fa9459Szrj {
2142a9fa9459Szrj case '0':
2143a9fa9459Szrj visibility = DEBUG_VISIBILITY_PRIVATE;
2144a9fa9459Szrj break;
2145a9fa9459Szrj case '1':
2146a9fa9459Szrj visibility = DEBUG_VISIBILITY_PROTECTED;
2147a9fa9459Szrj break;
2148a9fa9459Szrj case '2':
2149a9fa9459Szrj visibility = DEBUG_VISIBILITY_PUBLIC;
2150a9fa9459Szrj break;
2151a9fa9459Szrj default:
2152a9fa9459Szrj warn_stab (orig, _("unknown visibility character for baseclass"));
2153a9fa9459Szrj visibility = DEBUG_VISIBILITY_PUBLIC;
2154a9fa9459Szrj break;
2155a9fa9459Szrj }
2156a9fa9459Szrj ++*pp;
2157a9fa9459Szrj
2158a9fa9459Szrj /* The remaining value is the bit offset of the portion of the
2159a9fa9459Szrj object corresponding to this baseclass. Always zero in the
2160a9fa9459Szrj absence of multiple inheritance. */
2161a9fa9459Szrj bitpos = parse_number (pp, (bfd_boolean *) NULL);
2162a9fa9459Szrj if (**pp != ',')
2163a9fa9459Szrj {
2164a9fa9459Szrj bad_stab (orig);
2165a9fa9459Szrj return FALSE;
2166a9fa9459Szrj }
2167a9fa9459Szrj ++*pp;
2168a9fa9459Szrj
2169a9fa9459Szrj type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2170a9fa9459Szrj (debug_type **) NULL);
2171a9fa9459Szrj if (type == DEBUG_TYPE_NULL)
2172a9fa9459Szrj return FALSE;
2173a9fa9459Szrj
2174a9fa9459Szrj classes[i] = debug_make_baseclass (dhandle, type, bitpos, is_virtual,
2175a9fa9459Szrj visibility);
2176a9fa9459Szrj if (classes[i] == DEBUG_BASECLASS_NULL)
2177a9fa9459Szrj return FALSE;
2178a9fa9459Szrj
2179a9fa9459Szrj if (**pp != ';')
2180a9fa9459Szrj return FALSE;
2181a9fa9459Szrj ++*pp;
2182a9fa9459Szrj }
2183a9fa9459Szrj
2184a9fa9459Szrj classes[i] = DEBUG_BASECLASS_NULL;
2185a9fa9459Szrj
2186a9fa9459Szrj *retp = classes;
2187a9fa9459Szrj
2188a9fa9459Szrj return TRUE;
2189a9fa9459Szrj }
2190a9fa9459Szrj
2191a9fa9459Szrj /* Read struct or class data fields. They have the form:
2192a9fa9459Szrj
2193a9fa9459Szrj NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2194a9fa9459Szrj
2195a9fa9459Szrj At the end, we see a semicolon instead of a field.
2196a9fa9459Szrj
2197a9fa9459Szrj In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2198a9fa9459Szrj a static field.
2199a9fa9459Szrj
2200a9fa9459Szrj The optional VISIBILITY is one of:
2201a9fa9459Szrj
2202a9fa9459Szrj '/0' (VISIBILITY_PRIVATE)
2203a9fa9459Szrj '/1' (VISIBILITY_PROTECTED)
2204a9fa9459Szrj '/2' (VISIBILITY_PUBLIC)
2205a9fa9459Szrj '/9' (VISIBILITY_IGNORE)
2206a9fa9459Szrj
2207a9fa9459Szrj or nothing, for C style fields with public visibility.
2208a9fa9459Szrj
2209a9fa9459Szrj Returns 1 for success, 0 for failure. */
2210a9fa9459Szrj
2211a9fa9459Szrj static bfd_boolean
parse_stab_struct_fields(void * dhandle,struct stab_handle * info,const char ** pp,debug_field ** retp,bfd_boolean * staticsp)2212a9fa9459Szrj parse_stab_struct_fields (void *dhandle, struct stab_handle *info,
2213a9fa9459Szrj const char **pp, debug_field **retp,
2214a9fa9459Szrj bfd_boolean *staticsp)
2215a9fa9459Szrj {
2216a9fa9459Szrj const char *orig;
2217a9fa9459Szrj const char *p;
2218a9fa9459Szrj debug_field *fields;
2219a9fa9459Szrj unsigned int c;
2220a9fa9459Szrj unsigned int alloc;
2221a9fa9459Szrj
2222a9fa9459Szrj *retp = NULL;
2223a9fa9459Szrj *staticsp = FALSE;
2224a9fa9459Szrj
2225a9fa9459Szrj orig = *pp;
2226a9fa9459Szrj
2227a9fa9459Szrj c = 0;
2228a9fa9459Szrj alloc = 10;
2229a9fa9459Szrj fields = (debug_field *) xmalloc (alloc * sizeof *fields);
2230a9fa9459Szrj while (**pp != ';')
2231a9fa9459Szrj {
2232a9fa9459Szrj /* FIXME: gdb checks os9k_stabs here. */
2233a9fa9459Szrj
2234a9fa9459Szrj p = *pp;
2235a9fa9459Szrj
2236a9fa9459Szrj /* Add 1 to c to leave room for NULL pointer at end. */
2237a9fa9459Szrj if (c + 1 >= alloc)
2238a9fa9459Szrj {
2239a9fa9459Szrj alloc += 10;
2240a9fa9459Szrj fields = ((debug_field *)
2241a9fa9459Szrj xrealloc (fields, alloc * sizeof *fields));
2242a9fa9459Szrj }
2243a9fa9459Szrj
2244a9fa9459Szrj /* If it starts with CPLUS_MARKER it is a special abbreviation,
2245a9fa9459Szrj unless the CPLUS_MARKER is followed by an underscore, in
2246a9fa9459Szrj which case it is just the name of an anonymous type, which we
2247a9fa9459Szrj should handle like any other type name. We accept either '$'
2248a9fa9459Szrj or '.', because a field name can never contain one of these
2249a9fa9459Szrj characters except as a CPLUS_MARKER. */
2250a9fa9459Szrj
2251a9fa9459Szrj if ((*p == '$' || *p == '.') && p[1] != '_')
2252a9fa9459Szrj {
2253a9fa9459Szrj ++*pp;
2254a9fa9459Szrj if (! parse_stab_cpp_abbrev (dhandle, info, pp, fields + c))
2255a9fa9459Szrj {
2256a9fa9459Szrj free (fields);
2257a9fa9459Szrj return FALSE;
2258a9fa9459Szrj }
2259a9fa9459Szrj ++c;
2260a9fa9459Szrj continue;
2261a9fa9459Szrj }
2262a9fa9459Szrj
2263a9fa9459Szrj /* Look for the ':' that separates the field name from the field
2264a9fa9459Szrj values. Data members are delimited by a single ':', while member
2265a9fa9459Szrj functions are delimited by a pair of ':'s. When we hit the member
2266a9fa9459Szrj functions (if any), terminate scan loop and return. */
2267a9fa9459Szrj
2268a9fa9459Szrj p = strchr (p, ':');
2269a9fa9459Szrj if (p == NULL)
2270a9fa9459Szrj {
2271a9fa9459Szrj bad_stab (orig);
2272a9fa9459Szrj free (fields);
2273a9fa9459Szrj return FALSE;
2274a9fa9459Szrj }
2275a9fa9459Szrj
2276a9fa9459Szrj if (p[1] == ':')
2277a9fa9459Szrj break;
2278a9fa9459Szrj
2279a9fa9459Szrj if (! parse_stab_one_struct_field (dhandle, info, pp, p, fields + c,
2280a9fa9459Szrj staticsp))
2281a9fa9459Szrj return FALSE;
2282a9fa9459Szrj
2283a9fa9459Szrj ++c;
2284a9fa9459Szrj }
2285a9fa9459Szrj
2286a9fa9459Szrj fields[c] = DEBUG_FIELD_NULL;
2287a9fa9459Szrj
2288a9fa9459Szrj *retp = fields;
2289a9fa9459Szrj
2290a9fa9459Szrj return TRUE;
2291a9fa9459Szrj }
2292a9fa9459Szrj
2293a9fa9459Szrj /* Special GNU C++ name. */
2294a9fa9459Szrj
2295a9fa9459Szrj static bfd_boolean
parse_stab_cpp_abbrev(void * dhandle,struct stab_handle * info,const char ** pp,debug_field * retp)2296a9fa9459Szrj parse_stab_cpp_abbrev (void *dhandle, struct stab_handle *info,
2297a9fa9459Szrj const char **pp, debug_field *retp)
2298a9fa9459Szrj {
2299a9fa9459Szrj const char *orig;
2300a9fa9459Szrj int cpp_abbrev;
2301a9fa9459Szrj debug_type context;
2302a9fa9459Szrj const char *name;
2303a9fa9459Szrj const char *type_name;
2304a9fa9459Szrj debug_type type;
2305a9fa9459Szrj bfd_vma bitpos;
2306a9fa9459Szrj
2307a9fa9459Szrj *retp = DEBUG_FIELD_NULL;
2308a9fa9459Szrj
2309a9fa9459Szrj orig = *pp;
2310a9fa9459Szrj
2311a9fa9459Szrj if (**pp != 'v')
2312a9fa9459Szrj {
2313a9fa9459Szrj bad_stab (*pp);
2314a9fa9459Szrj return FALSE;
2315a9fa9459Szrj }
2316a9fa9459Szrj ++*pp;
2317a9fa9459Szrj
2318a9fa9459Szrj cpp_abbrev = **pp;
2319a9fa9459Szrj ++*pp;
2320a9fa9459Szrj
2321a9fa9459Szrj /* At this point, *pp points to something like "22:23=*22...", where
2322a9fa9459Szrj the type number before the ':' is the "context" and everything
2323a9fa9459Szrj after is a regular type definition. Lookup the type, find it's
2324a9fa9459Szrj name, and construct the field name. */
2325a9fa9459Szrj
2326a9fa9459Szrj context = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2327a9fa9459Szrj (debug_type **) NULL);
2328a9fa9459Szrj if (context == DEBUG_TYPE_NULL)
2329a9fa9459Szrj return FALSE;
2330a9fa9459Szrj
2331a9fa9459Szrj switch (cpp_abbrev)
2332a9fa9459Szrj {
2333a9fa9459Szrj case 'f':
2334a9fa9459Szrj /* $vf -- a virtual function table pointer. */
2335a9fa9459Szrj name = "_vptr$";
2336a9fa9459Szrj break;
2337a9fa9459Szrj case 'b':
2338a9fa9459Szrj /* $vb -- a virtual bsomethingorother */
2339a9fa9459Szrj type_name = debug_get_type_name (dhandle, context);
2340a9fa9459Szrj if (type_name == NULL)
2341a9fa9459Szrj {
2342a9fa9459Szrj warn_stab (orig, _("unnamed $vb type"));
2343a9fa9459Szrj type_name = "FOO";
2344a9fa9459Szrj }
2345a9fa9459Szrj name = concat ("_vb$", type_name, (const char *) NULL);
2346a9fa9459Szrj break;
2347a9fa9459Szrj default:
2348a9fa9459Szrj warn_stab (orig, _("unrecognized C++ abbreviation"));
2349a9fa9459Szrj name = "INVALID_CPLUSPLUS_ABBREV";
2350a9fa9459Szrj break;
2351a9fa9459Szrj }
2352a9fa9459Szrj
2353a9fa9459Szrj if (**pp != ':')
2354a9fa9459Szrj {
2355a9fa9459Szrj bad_stab (orig);
2356a9fa9459Szrj return FALSE;
2357a9fa9459Szrj }
2358a9fa9459Szrj ++*pp;
2359a9fa9459Szrj
2360a9fa9459Szrj type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2361a9fa9459Szrj (debug_type **) NULL);
2362a9fa9459Szrj if (**pp != ',')
2363a9fa9459Szrj {
2364a9fa9459Szrj bad_stab (orig);
2365a9fa9459Szrj return FALSE;
2366a9fa9459Szrj }
2367a9fa9459Szrj ++*pp;
2368a9fa9459Szrj
2369a9fa9459Szrj bitpos = parse_number (pp, (bfd_boolean *) NULL);
2370a9fa9459Szrj if (**pp != ';')
2371a9fa9459Szrj {
2372a9fa9459Szrj bad_stab (orig);
2373a9fa9459Szrj return FALSE;
2374a9fa9459Szrj }
2375a9fa9459Szrj ++*pp;
2376a9fa9459Szrj
2377a9fa9459Szrj *retp = debug_make_field (dhandle, name, type, bitpos, 0,
2378a9fa9459Szrj DEBUG_VISIBILITY_PRIVATE);
2379a9fa9459Szrj if (*retp == DEBUG_FIELD_NULL)
2380a9fa9459Szrj return FALSE;
2381a9fa9459Szrj
2382a9fa9459Szrj return TRUE;
2383a9fa9459Szrj }
2384a9fa9459Szrj
2385a9fa9459Szrj /* Parse a single field in a struct or union. */
2386a9fa9459Szrj
2387a9fa9459Szrj static bfd_boolean
parse_stab_one_struct_field(void * dhandle,struct stab_handle * info,const char ** pp,const char * p,debug_field * retp,bfd_boolean * staticsp)2388a9fa9459Szrj parse_stab_one_struct_field (void *dhandle, struct stab_handle *info,
2389a9fa9459Szrj const char **pp, const char *p,
2390a9fa9459Szrj debug_field *retp, bfd_boolean *staticsp)
2391a9fa9459Szrj {
2392a9fa9459Szrj const char *orig;
2393a9fa9459Szrj char *name;
2394a9fa9459Szrj enum debug_visibility visibility;
2395a9fa9459Szrj debug_type type;
2396a9fa9459Szrj bfd_vma bitpos;
2397a9fa9459Szrj bfd_vma bitsize;
2398a9fa9459Szrj
2399a9fa9459Szrj orig = *pp;
2400a9fa9459Szrj
2401a9fa9459Szrj /* FIXME: gdb checks ARM_DEMANGLING here. */
2402a9fa9459Szrj
2403a9fa9459Szrj name = savestring (*pp, p - *pp);
2404a9fa9459Szrj
2405a9fa9459Szrj *pp = p + 1;
2406a9fa9459Szrj
2407a9fa9459Szrj if (**pp != '/')
2408a9fa9459Szrj visibility = DEBUG_VISIBILITY_PUBLIC;
2409a9fa9459Szrj else
2410a9fa9459Szrj {
2411a9fa9459Szrj ++*pp;
2412a9fa9459Szrj switch (**pp)
2413a9fa9459Szrj {
2414a9fa9459Szrj case '0':
2415a9fa9459Szrj visibility = DEBUG_VISIBILITY_PRIVATE;
2416a9fa9459Szrj break;
2417a9fa9459Szrj case '1':
2418a9fa9459Szrj visibility = DEBUG_VISIBILITY_PROTECTED;
2419a9fa9459Szrj break;
2420a9fa9459Szrj case '2':
2421a9fa9459Szrj visibility = DEBUG_VISIBILITY_PUBLIC;
2422a9fa9459Szrj break;
2423a9fa9459Szrj default:
2424a9fa9459Szrj warn_stab (orig, _("unknown visibility character for field"));
2425a9fa9459Szrj visibility = DEBUG_VISIBILITY_PUBLIC;
2426a9fa9459Szrj break;
2427a9fa9459Szrj }
2428a9fa9459Szrj ++*pp;
2429a9fa9459Szrj }
2430a9fa9459Szrj
2431a9fa9459Szrj type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2432a9fa9459Szrj (debug_type **) NULL);
2433a9fa9459Szrj if (type == DEBUG_TYPE_NULL)
2434a9fa9459Szrj {
2435a9fa9459Szrj free (name);
2436a9fa9459Szrj return FALSE;
2437a9fa9459Szrj }
2438a9fa9459Szrj
2439a9fa9459Szrj if (**pp == ':')
2440a9fa9459Szrj {
2441a9fa9459Szrj char *varname;
2442a9fa9459Szrj
2443a9fa9459Szrj /* This is a static class member. */
2444a9fa9459Szrj ++*pp;
2445a9fa9459Szrj p = strchr (*pp, ';');
2446a9fa9459Szrj if (p == NULL)
2447a9fa9459Szrj {
2448a9fa9459Szrj bad_stab (orig);
2449a9fa9459Szrj free (name);
2450a9fa9459Szrj return FALSE;
2451a9fa9459Szrj }
2452a9fa9459Szrj
2453a9fa9459Szrj varname = savestring (*pp, p - *pp);
2454a9fa9459Szrj
2455a9fa9459Szrj *pp = p + 1;
2456a9fa9459Szrj
2457a9fa9459Szrj *retp = debug_make_static_member (dhandle, name, type, varname,
2458a9fa9459Szrj visibility);
2459a9fa9459Szrj *staticsp = TRUE;
2460a9fa9459Szrj
2461a9fa9459Szrj return TRUE;
2462a9fa9459Szrj }
2463a9fa9459Szrj
2464a9fa9459Szrj if (**pp != ',')
2465a9fa9459Szrj {
2466a9fa9459Szrj bad_stab (orig);
2467a9fa9459Szrj free (name);
2468a9fa9459Szrj return FALSE;
2469a9fa9459Szrj }
2470a9fa9459Szrj ++*pp;
2471a9fa9459Szrj
2472a9fa9459Szrj bitpos = parse_number (pp, (bfd_boolean *) NULL);
2473a9fa9459Szrj if (**pp != ',')
2474a9fa9459Szrj {
2475a9fa9459Szrj bad_stab (orig);
2476a9fa9459Szrj free (name);
2477a9fa9459Szrj return FALSE;
2478a9fa9459Szrj }
2479a9fa9459Szrj ++*pp;
2480a9fa9459Szrj
2481a9fa9459Szrj bitsize = parse_number (pp, (bfd_boolean *) NULL);
2482a9fa9459Szrj if (**pp != ';')
2483a9fa9459Szrj {
2484a9fa9459Szrj bad_stab (orig);
2485a9fa9459Szrj free (name);
2486a9fa9459Szrj return FALSE;
2487a9fa9459Szrj }
2488a9fa9459Szrj ++*pp;
2489a9fa9459Szrj
2490a9fa9459Szrj if (bitpos == 0 && bitsize == 0)
2491a9fa9459Szrj {
2492a9fa9459Szrj /* This can happen in two cases: (1) at least for gcc 2.4.5 or
2493a9fa9459Szrj so, it is a field which has been optimized out. The correct
2494a9fa9459Szrj stab for this case is to use VISIBILITY_IGNORE, but that is a
2495a9fa9459Szrj recent invention. (2) It is a 0-size array. For example
2496a9fa9459Szrj union { int num; char str[0]; } foo. Printing "<no value>"
2497a9fa9459Szrj for str in "p foo" is OK, since foo.str (and thus foo.str[3])
2498a9fa9459Szrj will continue to work, and a 0-size array as a whole doesn't
2499a9fa9459Szrj have any contents to print.
2500a9fa9459Szrj
2501a9fa9459Szrj I suspect this probably could also happen with gcc -gstabs
2502a9fa9459Szrj (not -gstabs+) for static fields, and perhaps other C++
2503a9fa9459Szrj extensions. Hopefully few people use -gstabs with gdb, since
2504a9fa9459Szrj it is intended for dbx compatibility. */
2505a9fa9459Szrj visibility = DEBUG_VISIBILITY_IGNORE;
2506a9fa9459Szrj }
2507a9fa9459Szrj
2508a9fa9459Szrj /* FIXME: gdb does some stuff here to mark fields as unpacked. */
2509a9fa9459Szrj
2510a9fa9459Szrj *retp = debug_make_field (dhandle, name, type, bitpos, bitsize, visibility);
2511a9fa9459Szrj
2512a9fa9459Szrj return TRUE;
2513a9fa9459Szrj }
2514a9fa9459Szrj
2515a9fa9459Szrj /* Read member function stabs info for C++ classes. The form of each member
2516a9fa9459Szrj function data is:
2517a9fa9459Szrj
2518a9fa9459Szrj NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2519a9fa9459Szrj
2520a9fa9459Szrj An example with two member functions is:
2521a9fa9459Szrj
2522a9fa9459Szrj afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2523a9fa9459Szrj
2524a9fa9459Szrj For the case of overloaded operators, the format is op$::*.funcs, where
2525a9fa9459Szrj $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2526a9fa9459Szrj name (such as `+=') and `.' marks the end of the operator name. */
2527a9fa9459Szrj
2528a9fa9459Szrj static bfd_boolean
parse_stab_members(void * dhandle,struct stab_handle * info,const char * tagname,const char ** pp,const int * typenums,debug_method ** retp)2529a9fa9459Szrj parse_stab_members (void *dhandle, struct stab_handle *info,
2530a9fa9459Szrj const char *tagname, const char **pp,
2531a9fa9459Szrj const int *typenums, debug_method **retp)
2532a9fa9459Szrj {
2533a9fa9459Szrj const char *orig;
2534a9fa9459Szrj debug_method *methods;
2535a9fa9459Szrj unsigned int c;
2536a9fa9459Szrj unsigned int alloc;
2537a9fa9459Szrj char *name = NULL;
2538a9fa9459Szrj debug_method_variant *variants = NULL;
2539a9fa9459Szrj char *argtypes = NULL;
2540a9fa9459Szrj
2541a9fa9459Szrj *retp = NULL;
2542a9fa9459Szrj
2543a9fa9459Szrj orig = *pp;
2544a9fa9459Szrj
2545a9fa9459Szrj alloc = 0;
2546a9fa9459Szrj methods = NULL;
2547a9fa9459Szrj c = 0;
2548a9fa9459Szrj
2549a9fa9459Szrj while (**pp != ';')
2550a9fa9459Szrj {
2551a9fa9459Szrj const char *p;
2552a9fa9459Szrj unsigned int cvars;
2553a9fa9459Szrj unsigned int allocvars;
2554a9fa9459Szrj debug_type look_ahead_type;
2555a9fa9459Szrj
2556a9fa9459Szrj p = strchr (*pp, ':');
2557a9fa9459Szrj if (p == NULL || p[1] != ':')
2558a9fa9459Szrj break;
2559a9fa9459Szrj
2560a9fa9459Szrj /* FIXME: Some systems use something other than '$' here. */
2561a9fa9459Szrj if ((*pp)[0] != 'o' || (*pp)[1] != 'p' || (*pp)[2] != '$')
2562a9fa9459Szrj {
2563a9fa9459Szrj name = savestring (*pp, p - *pp);
2564a9fa9459Szrj *pp = p + 2;
2565a9fa9459Szrj }
2566a9fa9459Szrj else
2567a9fa9459Szrj {
2568a9fa9459Szrj /* This is a completely weird case. In order to stuff in the
2569a9fa9459Szrj names that might contain colons (the usual name delimiter),
2570a9fa9459Szrj Mike Tiemann defined a different name format which is
2571a9fa9459Szrj signalled if the identifier is "op$". In that case, the
2572a9fa9459Szrj format is "op$::XXXX." where XXXX is the name. This is
2573a9fa9459Szrj used for names like "+" or "=". YUUUUUUUK! FIXME! */
2574a9fa9459Szrj *pp = p + 2;
2575a9fa9459Szrj for (p = *pp; *p != '.' && *p != '\0'; p++)
2576a9fa9459Szrj ;
2577a9fa9459Szrj if (*p != '.')
2578a9fa9459Szrj {
2579a9fa9459Szrj bad_stab (orig);
2580a9fa9459Szrj goto fail;
2581a9fa9459Szrj }
2582a9fa9459Szrj name = savestring (*pp, p - *pp);
2583a9fa9459Szrj *pp = p + 1;
2584a9fa9459Szrj }
2585a9fa9459Szrj
2586a9fa9459Szrj allocvars = 10;
2587a9fa9459Szrj variants = ((debug_method_variant *)
2588a9fa9459Szrj xmalloc (allocvars * sizeof *variants));
2589a9fa9459Szrj cvars = 0;
2590a9fa9459Szrj
2591a9fa9459Szrj look_ahead_type = DEBUG_TYPE_NULL;
2592a9fa9459Szrj
2593a9fa9459Szrj do
2594a9fa9459Szrj {
2595a9fa9459Szrj debug_type type;
2596a9fa9459Szrj bfd_boolean stub;
2597a9fa9459Szrj enum debug_visibility visibility;
2598a9fa9459Szrj bfd_boolean constp, volatilep, staticp;
2599a9fa9459Szrj bfd_vma voffset;
2600a9fa9459Szrj debug_type context;
2601a9fa9459Szrj const char *physname;
2602a9fa9459Szrj bfd_boolean varargs;
2603a9fa9459Szrj
2604a9fa9459Szrj if (look_ahead_type != DEBUG_TYPE_NULL)
2605a9fa9459Szrj {
2606a9fa9459Szrj /* g++ version 1 kludge */
2607a9fa9459Szrj type = look_ahead_type;
2608a9fa9459Szrj look_ahead_type = DEBUG_TYPE_NULL;
2609a9fa9459Szrj }
2610a9fa9459Szrj else
2611a9fa9459Szrj {
2612a9fa9459Szrj type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2613a9fa9459Szrj (debug_type **) NULL);
2614a9fa9459Szrj if (type == DEBUG_TYPE_NULL)
2615a9fa9459Szrj goto fail;
2616a9fa9459Szrj
2617a9fa9459Szrj if (**pp != ':')
2618a9fa9459Szrj {
2619a9fa9459Szrj bad_stab (orig);
2620a9fa9459Szrj goto fail;
2621a9fa9459Szrj }
2622a9fa9459Szrj }
2623a9fa9459Szrj
2624a9fa9459Szrj ++*pp;
2625a9fa9459Szrj p = strchr (*pp, ';');
2626a9fa9459Szrj if (p == NULL)
2627a9fa9459Szrj {
2628a9fa9459Szrj bad_stab (orig);
2629a9fa9459Szrj goto fail;
2630a9fa9459Szrj }
2631a9fa9459Szrj
2632a9fa9459Szrj stub = FALSE;
2633a9fa9459Szrj if (debug_get_type_kind (dhandle, type) == DEBUG_KIND_METHOD
2634a9fa9459Szrj && debug_get_parameter_types (dhandle, type, &varargs) == NULL)
2635a9fa9459Szrj stub = TRUE;
2636a9fa9459Szrj
2637a9fa9459Szrj argtypes = savestring (*pp, p - *pp);
2638a9fa9459Szrj *pp = p + 1;
2639a9fa9459Szrj
2640a9fa9459Szrj switch (**pp)
2641a9fa9459Szrj {
2642a9fa9459Szrj case '0':
2643a9fa9459Szrj visibility = DEBUG_VISIBILITY_PRIVATE;
2644a9fa9459Szrj break;
2645a9fa9459Szrj case '1':
2646a9fa9459Szrj visibility = DEBUG_VISIBILITY_PROTECTED;
2647a9fa9459Szrj break;
2648a9fa9459Szrj default:
2649a9fa9459Szrj visibility = DEBUG_VISIBILITY_PUBLIC;
2650a9fa9459Szrj break;
2651a9fa9459Szrj }
2652a9fa9459Szrj ++*pp;
2653a9fa9459Szrj
2654a9fa9459Szrj constp = FALSE;
2655a9fa9459Szrj volatilep = FALSE;
2656a9fa9459Szrj switch (**pp)
2657a9fa9459Szrj {
2658a9fa9459Szrj case 'A':
2659a9fa9459Szrj /* Normal function. */
2660a9fa9459Szrj ++*pp;
2661a9fa9459Szrj break;
2662a9fa9459Szrj case 'B':
2663a9fa9459Szrj /* const member function. */
2664a9fa9459Szrj constp = TRUE;
2665a9fa9459Szrj ++*pp;
2666a9fa9459Szrj break;
2667a9fa9459Szrj case 'C':
2668a9fa9459Szrj /* volatile member function. */
2669a9fa9459Szrj volatilep = TRUE;
2670a9fa9459Szrj ++*pp;
2671a9fa9459Szrj break;
2672a9fa9459Szrj case 'D':
2673a9fa9459Szrj /* const volatile member function. */
2674a9fa9459Szrj constp = TRUE;
2675a9fa9459Szrj volatilep = TRUE;
2676a9fa9459Szrj ++*pp;
2677a9fa9459Szrj break;
2678a9fa9459Szrj case '*':
2679a9fa9459Szrj case '?':
2680a9fa9459Szrj case '.':
2681a9fa9459Szrj /* File compiled with g++ version 1; no information. */
2682a9fa9459Szrj break;
2683a9fa9459Szrj default:
2684a9fa9459Szrj warn_stab (orig, _("const/volatile indicator missing"));
2685a9fa9459Szrj break;
2686a9fa9459Szrj }
2687a9fa9459Szrj
2688a9fa9459Szrj staticp = FALSE;
2689a9fa9459Szrj switch (**pp)
2690a9fa9459Szrj {
2691a9fa9459Szrj case '*':
2692a9fa9459Szrj /* virtual member function, followed by index. The sign
2693a9fa9459Szrj bit is supposedly set to distinguish
2694a9fa9459Szrj pointers-to-methods from virtual function indicies. */
2695a9fa9459Szrj ++*pp;
2696a9fa9459Szrj voffset = parse_number (pp, (bfd_boolean *) NULL);
2697a9fa9459Szrj if (**pp != ';')
2698a9fa9459Szrj {
2699a9fa9459Szrj bad_stab (orig);
2700a9fa9459Szrj goto fail;
2701a9fa9459Szrj }
2702a9fa9459Szrj ++*pp;
2703a9fa9459Szrj voffset &= 0x7fffffff;
2704a9fa9459Szrj
2705*68cbe23bSzrj if (**pp == ';' || **pp == '\0')
2706a9fa9459Szrj {
2707a9fa9459Szrj /* Must be g++ version 1. */
2708a9fa9459Szrj context = DEBUG_TYPE_NULL;
2709a9fa9459Szrj }
2710a9fa9459Szrj else
2711a9fa9459Szrj {
2712a9fa9459Szrj /* Figure out from whence this virtual function
2713a9fa9459Szrj came. It may belong to virtual function table of
2714a9fa9459Szrj one of its baseclasses. */
2715a9fa9459Szrj look_ahead_type = parse_stab_type (dhandle, info,
2716a9fa9459Szrj (const char *) NULL,
2717a9fa9459Szrj pp,
2718a9fa9459Szrj (debug_type **) NULL);
2719a9fa9459Szrj if (**pp == ':')
2720a9fa9459Szrj {
2721a9fa9459Szrj /* g++ version 1 overloaded methods. */
2722a9fa9459Szrj context = DEBUG_TYPE_NULL;
2723a9fa9459Szrj }
2724a9fa9459Szrj else
2725a9fa9459Szrj {
2726a9fa9459Szrj context = look_ahead_type;
2727a9fa9459Szrj look_ahead_type = DEBUG_TYPE_NULL;
2728a9fa9459Szrj if (**pp != ';')
2729a9fa9459Szrj {
2730a9fa9459Szrj bad_stab (orig);
2731a9fa9459Szrj goto fail;
2732a9fa9459Szrj }
2733a9fa9459Szrj ++*pp;
2734a9fa9459Szrj }
2735a9fa9459Szrj }
2736a9fa9459Szrj break;
2737a9fa9459Szrj
2738a9fa9459Szrj case '?':
2739a9fa9459Szrj /* static member function. */
2740a9fa9459Szrj ++*pp;
2741a9fa9459Szrj staticp = TRUE;
2742a9fa9459Szrj voffset = 0;
2743a9fa9459Szrj context = DEBUG_TYPE_NULL;
2744a9fa9459Szrj if (strncmp (argtypes, name, strlen (name)) != 0)
2745a9fa9459Szrj stub = TRUE;
2746a9fa9459Szrj break;
2747a9fa9459Szrj
2748a9fa9459Szrj default:
2749a9fa9459Szrj warn_stab (orig, "member function type missing");
2750a9fa9459Szrj voffset = 0;
2751a9fa9459Szrj context = DEBUG_TYPE_NULL;
2752a9fa9459Szrj break;
2753a9fa9459Szrj
2754a9fa9459Szrj case '.':
2755a9fa9459Szrj ++*pp;
2756a9fa9459Szrj voffset = 0;
2757a9fa9459Szrj context = DEBUG_TYPE_NULL;
2758a9fa9459Szrj break;
2759a9fa9459Szrj }
2760a9fa9459Szrj
2761a9fa9459Szrj /* If the type is not a stub, then the argtypes string is
2762a9fa9459Szrj the physical name of the function. Otherwise the
2763a9fa9459Szrj argtypes string is the mangled form of the argument
2764a9fa9459Szrj types, and the full type and the physical name must be
2765a9fa9459Szrj extracted from them. */
2766a9fa9459Szrj physname = argtypes;
2767a9fa9459Szrj if (stub)
2768a9fa9459Szrj {
2769a9fa9459Szrj debug_type class_type, return_type;
2770a9fa9459Szrj
2771a9fa9459Szrj class_type = stab_find_type (dhandle, info, typenums);
2772a9fa9459Szrj if (class_type == DEBUG_TYPE_NULL)
2773a9fa9459Szrj goto fail;
2774a9fa9459Szrj return_type = debug_get_return_type (dhandle, type);
2775a9fa9459Szrj if (return_type == DEBUG_TYPE_NULL)
2776a9fa9459Szrj {
2777a9fa9459Szrj bad_stab (orig);
2778a9fa9459Szrj goto fail;
2779a9fa9459Szrj }
2780a9fa9459Szrj type = parse_stab_argtypes (dhandle, info, class_type, name,
2781a9fa9459Szrj tagname, return_type, argtypes,
2782a9fa9459Szrj constp, volatilep, &physname);
2783a9fa9459Szrj if (type == DEBUG_TYPE_NULL)
2784a9fa9459Szrj goto fail;
2785a9fa9459Szrj }
2786a9fa9459Szrj
2787a9fa9459Szrj if (cvars + 1 >= allocvars)
2788a9fa9459Szrj {
2789a9fa9459Szrj allocvars += 10;
2790a9fa9459Szrj variants = ((debug_method_variant *)
2791a9fa9459Szrj xrealloc (variants,
2792a9fa9459Szrj allocvars * sizeof *variants));
2793a9fa9459Szrj }
2794a9fa9459Szrj
2795a9fa9459Szrj if (! staticp)
2796a9fa9459Szrj variants[cvars] = debug_make_method_variant (dhandle, physname,
2797a9fa9459Szrj type, visibility,
2798a9fa9459Szrj constp, volatilep,
2799a9fa9459Szrj voffset, context);
2800a9fa9459Szrj else
2801a9fa9459Szrj variants[cvars] = debug_make_static_method_variant (dhandle,
2802a9fa9459Szrj physname,
2803a9fa9459Szrj type,
2804a9fa9459Szrj visibility,
2805a9fa9459Szrj constp,
2806a9fa9459Szrj volatilep);
2807a9fa9459Szrj if (variants[cvars] == DEBUG_METHOD_VARIANT_NULL)
2808a9fa9459Szrj goto fail;
2809a9fa9459Szrj
2810a9fa9459Szrj ++cvars;
2811a9fa9459Szrj }
2812a9fa9459Szrj while (**pp != ';' && **pp != '\0');
2813a9fa9459Szrj
2814a9fa9459Szrj variants[cvars] = DEBUG_METHOD_VARIANT_NULL;
2815a9fa9459Szrj
2816a9fa9459Szrj if (**pp != '\0')
2817a9fa9459Szrj ++*pp;
2818a9fa9459Szrj
2819a9fa9459Szrj if (c + 1 >= alloc)
2820a9fa9459Szrj {
2821a9fa9459Szrj alloc += 10;
2822a9fa9459Szrj methods = ((debug_method *)
2823a9fa9459Szrj xrealloc (methods, alloc * sizeof *methods));
2824a9fa9459Szrj }
2825a9fa9459Szrj
2826a9fa9459Szrj methods[c] = debug_make_method (dhandle, name, variants);
2827a9fa9459Szrj
2828a9fa9459Szrj ++c;
2829a9fa9459Szrj }
2830a9fa9459Szrj
2831a9fa9459Szrj if (methods != NULL)
2832a9fa9459Szrj methods[c] = DEBUG_METHOD_NULL;
2833a9fa9459Szrj
2834a9fa9459Szrj *retp = methods;
2835a9fa9459Szrj
2836a9fa9459Szrj return TRUE;
2837a9fa9459Szrj
2838a9fa9459Szrj fail:
2839a9fa9459Szrj if (name != NULL)
2840a9fa9459Szrj free (name);
2841a9fa9459Szrj if (variants != NULL)
2842a9fa9459Szrj free (variants);
2843a9fa9459Szrj if (argtypes != NULL)
2844a9fa9459Szrj free (argtypes);
2845a9fa9459Szrj return FALSE;
2846a9fa9459Szrj }
2847a9fa9459Szrj
2848a9fa9459Szrj /* Parse a string representing argument types for a method. Stabs
2849a9fa9459Szrj tries to save space by packing argument types into a mangled
2850a9fa9459Szrj string. This string should give us enough information to extract
2851a9fa9459Szrj both argument types and the physical name of the function, given
2852a9fa9459Szrj the tag name. */
2853a9fa9459Szrj
2854a9fa9459Szrj static debug_type
parse_stab_argtypes(void * dhandle,struct stab_handle * info,debug_type class_type,const char * fieldname,const char * tagname,debug_type return_type,const char * argtypes,bfd_boolean constp,bfd_boolean volatilep,const char ** pphysname)2855a9fa9459Szrj parse_stab_argtypes (void *dhandle, struct stab_handle *info,
2856a9fa9459Szrj debug_type class_type, const char *fieldname,
2857a9fa9459Szrj const char *tagname, debug_type return_type,
2858a9fa9459Szrj const char *argtypes, bfd_boolean constp,
2859a9fa9459Szrj bfd_boolean volatilep, const char **pphysname)
2860a9fa9459Szrj {
2861a9fa9459Szrj bfd_boolean is_full_physname_constructor;
2862a9fa9459Szrj bfd_boolean is_constructor;
2863a9fa9459Szrj bfd_boolean is_destructor;
2864a9fa9459Szrj bfd_boolean is_v3;
2865a9fa9459Szrj debug_type *args;
2866a9fa9459Szrj bfd_boolean varargs;
2867a9fa9459Szrj unsigned int physname_len = 0;
2868a9fa9459Szrj
2869a9fa9459Szrj /* Constructors are sometimes handled specially. */
2870a9fa9459Szrj is_full_physname_constructor = ((argtypes[0] == '_'
2871a9fa9459Szrj && argtypes[1] == '_'
2872a9fa9459Szrj && (ISDIGIT (argtypes[2])
2873a9fa9459Szrj || argtypes[2] == 'Q'
2874a9fa9459Szrj || argtypes[2] == 't'))
2875a9fa9459Szrj || CONST_STRNEQ (argtypes, "__ct"));
2876a9fa9459Szrj
2877a9fa9459Szrj is_constructor = (is_full_physname_constructor
2878a9fa9459Szrj || (tagname != NULL
2879a9fa9459Szrj && strcmp (fieldname, tagname) == 0));
2880a9fa9459Szrj is_destructor = ((argtypes[0] == '_'
2881a9fa9459Szrj && (argtypes[1] == '$' || argtypes[1] == '.')
2882a9fa9459Szrj && argtypes[2] == '_')
2883a9fa9459Szrj || CONST_STRNEQ (argtypes, "__dt"));
2884a9fa9459Szrj is_v3 = argtypes[0] == '_' && argtypes[1] == 'Z';
2885a9fa9459Szrj
2886a9fa9459Szrj if (!(is_destructor || is_full_physname_constructor || is_v3))
2887a9fa9459Szrj {
2888a9fa9459Szrj unsigned int len;
2889a9fa9459Szrj const char *const_prefix;
2890a9fa9459Szrj const char *volatile_prefix;
2891a9fa9459Szrj char buf[20];
2892a9fa9459Szrj unsigned int mangled_name_len;
2893a9fa9459Szrj char *physname;
2894a9fa9459Szrj
2895a9fa9459Szrj len = tagname == NULL ? 0 : strlen (tagname);
2896a9fa9459Szrj const_prefix = constp ? "C" : "";
2897a9fa9459Szrj volatile_prefix = volatilep ? "V" : "";
2898a9fa9459Szrj
2899a9fa9459Szrj if (len == 0)
2900a9fa9459Szrj sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
2901a9fa9459Szrj else if (tagname != NULL && strchr (tagname, '<') != NULL)
2902a9fa9459Szrj {
2903a9fa9459Szrj /* Template methods are fully mangled. */
2904a9fa9459Szrj sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
2905a9fa9459Szrj tagname = NULL;
2906a9fa9459Szrj len = 0;
2907a9fa9459Szrj }
2908a9fa9459Szrj else
2909a9fa9459Szrj sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
2910a9fa9459Szrj
2911a9fa9459Szrj mangled_name_len = ((is_constructor ? 0 : strlen (fieldname))
2912a9fa9459Szrj + strlen (buf)
2913a9fa9459Szrj + len
2914a9fa9459Szrj + strlen (argtypes)
2915a9fa9459Szrj + 1);
2916a9fa9459Szrj
2917a9fa9459Szrj if (fieldname[0] == 'o'
2918a9fa9459Szrj && fieldname[1] == 'p'
2919a9fa9459Szrj && (fieldname[2] == '$' || fieldname[2] == '.'))
2920a9fa9459Szrj {
2921a9fa9459Szrj const char *opname;
2922a9fa9459Szrj
2923a9fa9459Szrj opname = cplus_mangle_opname (fieldname + 3, 0);
2924a9fa9459Szrj if (opname == NULL)
2925a9fa9459Szrj {
2926a9fa9459Szrj fprintf (stderr, _("No mangling for \"%s\"\n"), fieldname);
2927a9fa9459Szrj return DEBUG_TYPE_NULL;
2928a9fa9459Szrj }
2929a9fa9459Szrj mangled_name_len += strlen (opname);
2930a9fa9459Szrj physname = (char *) xmalloc (mangled_name_len);
2931a9fa9459Szrj strncpy (physname, fieldname, 3);
2932a9fa9459Szrj strcpy (physname + 3, opname);
2933a9fa9459Szrj }
2934a9fa9459Szrj else
2935a9fa9459Szrj {
2936a9fa9459Szrj physname = (char *) xmalloc (mangled_name_len);
2937a9fa9459Szrj if (is_constructor)
2938a9fa9459Szrj physname[0] = '\0';
2939a9fa9459Szrj else
2940a9fa9459Szrj strcpy (physname, fieldname);
2941a9fa9459Szrj }
2942a9fa9459Szrj
2943a9fa9459Szrj physname_len = strlen (physname);
2944a9fa9459Szrj strcat (physname, buf);
2945a9fa9459Szrj if (tagname != NULL)
2946a9fa9459Szrj strcat (physname, tagname);
2947a9fa9459Szrj strcat (physname, argtypes);
2948a9fa9459Szrj
2949a9fa9459Szrj *pphysname = physname;
2950a9fa9459Szrj }
2951a9fa9459Szrj
2952a9fa9459Szrj if (*argtypes == '\0' || is_destructor)
2953a9fa9459Szrj {
2954a9fa9459Szrj args = (debug_type *) xmalloc (sizeof *args);
2955a9fa9459Szrj *args = NULL;
2956a9fa9459Szrj return debug_make_method_type (dhandle, return_type, class_type, args,
2957a9fa9459Szrj FALSE);
2958a9fa9459Szrj }
2959a9fa9459Szrj
2960a9fa9459Szrj args = stab_demangle_argtypes (dhandle, info, *pphysname, &varargs, physname_len);
2961a9fa9459Szrj if (args == NULL)
2962a9fa9459Szrj return DEBUG_TYPE_NULL;
2963a9fa9459Szrj
2964a9fa9459Szrj return debug_make_method_type (dhandle, return_type, class_type, args,
2965a9fa9459Szrj varargs);
2966a9fa9459Szrj }
2967a9fa9459Szrj
2968a9fa9459Szrj /* The tail end of stabs for C++ classes that contain a virtual function
2969a9fa9459Szrj pointer contains a tilde, a %, and a type number.
2970a9fa9459Szrj The type number refers to the base class (possibly this class itself) which
2971a9fa9459Szrj contains the vtable pointer for the current class.
2972a9fa9459Szrj
2973a9fa9459Szrj This function is called when we have parsed all the method declarations,
2974a9fa9459Szrj so we can look for the vptr base class info. */
2975a9fa9459Szrj
2976a9fa9459Szrj static bfd_boolean
parse_stab_tilde_field(void * dhandle,struct stab_handle * info,const char ** pp,const int * typenums,debug_type * retvptrbase,bfd_boolean * retownvptr)2977a9fa9459Szrj parse_stab_tilde_field (void *dhandle, struct stab_handle *info,
2978a9fa9459Szrj const char **pp, const int *typenums,
2979a9fa9459Szrj debug_type *retvptrbase, bfd_boolean *retownvptr)
2980a9fa9459Szrj {
2981a9fa9459Szrj const char *orig;
2982a9fa9459Szrj const char *hold;
2983a9fa9459Szrj int vtypenums[2];
2984a9fa9459Szrj
2985a9fa9459Szrj *retvptrbase = DEBUG_TYPE_NULL;
2986a9fa9459Szrj *retownvptr = FALSE;
2987a9fa9459Szrj
2988a9fa9459Szrj orig = *pp;
2989a9fa9459Szrj
2990a9fa9459Szrj /* If we are positioned at a ';', then skip it. */
2991a9fa9459Szrj if (**pp == ';')
2992a9fa9459Szrj ++*pp;
2993a9fa9459Szrj
2994a9fa9459Szrj if (**pp != '~')
2995a9fa9459Szrj return TRUE;
2996a9fa9459Szrj
2997a9fa9459Szrj ++*pp;
2998a9fa9459Szrj
2999a9fa9459Szrj if (**pp == '=' || **pp == '+' || **pp == '-')
3000a9fa9459Szrj {
3001a9fa9459Szrj /* Obsolete flags that used to indicate the presence of
3002a9fa9459Szrj constructors and/or destructors. */
3003a9fa9459Szrj ++*pp;
3004a9fa9459Szrj }
3005a9fa9459Szrj
3006a9fa9459Szrj if (**pp != '%')
3007a9fa9459Szrj return TRUE;
3008a9fa9459Szrj
3009a9fa9459Szrj ++*pp;
3010a9fa9459Szrj
3011a9fa9459Szrj hold = *pp;
3012a9fa9459Szrj
3013a9fa9459Szrj /* The next number is the type number of the base class (possibly
3014a9fa9459Szrj our own class) which supplies the vtable for this class. */
3015a9fa9459Szrj if (! parse_stab_type_number (pp, vtypenums))
3016a9fa9459Szrj return FALSE;
3017a9fa9459Szrj
3018a9fa9459Szrj if (vtypenums[0] == typenums[0]
3019a9fa9459Szrj && vtypenums[1] == typenums[1])
3020a9fa9459Szrj *retownvptr = TRUE;
3021a9fa9459Szrj else
3022a9fa9459Szrj {
3023a9fa9459Szrj debug_type vtype;
3024a9fa9459Szrj const char *p;
3025a9fa9459Szrj
3026a9fa9459Szrj *pp = hold;
3027a9fa9459Szrj
3028a9fa9459Szrj vtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
3029a9fa9459Szrj (debug_type **) NULL);
3030a9fa9459Szrj for (p = *pp; *p != ';' && *p != '\0'; p++)
3031a9fa9459Szrj ;
3032a9fa9459Szrj if (*p != ';')
3033a9fa9459Szrj {
3034a9fa9459Szrj bad_stab (orig);
3035a9fa9459Szrj return FALSE;
3036a9fa9459Szrj }
3037a9fa9459Szrj
3038a9fa9459Szrj *retvptrbase = vtype;
3039a9fa9459Szrj
3040a9fa9459Szrj *pp = p + 1;
3041a9fa9459Szrj }
3042a9fa9459Szrj
3043a9fa9459Szrj return TRUE;
3044a9fa9459Szrj }
3045a9fa9459Szrj
3046a9fa9459Szrj /* Read a definition of an array type. */
3047a9fa9459Szrj
3048a9fa9459Szrj static debug_type
parse_stab_array_type(void * dhandle,struct stab_handle * info,const char ** pp,bfd_boolean stringp)3049a9fa9459Szrj parse_stab_array_type (void *dhandle, struct stab_handle *info,
3050a9fa9459Szrj const char **pp, bfd_boolean stringp)
3051a9fa9459Szrj {
3052a9fa9459Szrj const char *orig;
3053a9fa9459Szrj const char *p;
3054a9fa9459Szrj int typenums[2];
3055a9fa9459Szrj debug_type index_type;
3056a9fa9459Szrj bfd_boolean adjustable;
3057a9fa9459Szrj bfd_signed_vma lower, upper;
3058a9fa9459Szrj debug_type element_type;
3059a9fa9459Szrj
3060a9fa9459Szrj /* Format of an array type:
3061a9fa9459Szrj "ar<index type>;lower;upper;<array_contents_type>".
3062a9fa9459Szrj OS9000: "arlower,upper;<array_contents_type>".
3063a9fa9459Szrj
3064a9fa9459Szrj Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3065a9fa9459Szrj for these, produce a type like float[][]. */
3066a9fa9459Szrj
3067a9fa9459Szrj orig = *pp;
3068a9fa9459Szrj
3069a9fa9459Szrj /* FIXME: gdb checks os9k_stabs here. */
3070a9fa9459Szrj
3071a9fa9459Szrj /* If the index type is type 0, we take it as int. */
3072a9fa9459Szrj p = *pp;
3073a9fa9459Szrj if (! parse_stab_type_number (&p, typenums))
3074a9fa9459Szrj return DEBUG_TYPE_NULL;
3075a9fa9459Szrj if (typenums[0] == 0 && typenums[1] == 0 && **pp != '=')
3076a9fa9459Szrj {
3077a9fa9459Szrj index_type = debug_find_named_type (dhandle, "int");
3078a9fa9459Szrj if (index_type == DEBUG_TYPE_NULL)
3079a9fa9459Szrj {
3080a9fa9459Szrj index_type = debug_make_int_type (dhandle, 4, FALSE);
3081a9fa9459Szrj if (index_type == DEBUG_TYPE_NULL)
3082a9fa9459Szrj return DEBUG_TYPE_NULL;
3083a9fa9459Szrj }
3084a9fa9459Szrj *pp = p;
3085a9fa9459Szrj }
3086a9fa9459Szrj else
3087a9fa9459Szrj {
3088a9fa9459Szrj index_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
3089a9fa9459Szrj (debug_type **) NULL);
3090a9fa9459Szrj }
3091a9fa9459Szrj
3092a9fa9459Szrj if (**pp != ';')
3093a9fa9459Szrj {
3094a9fa9459Szrj bad_stab (orig);
3095a9fa9459Szrj return DEBUG_TYPE_NULL;
3096a9fa9459Szrj }
3097a9fa9459Szrj ++*pp;
3098a9fa9459Szrj
3099a9fa9459Szrj adjustable = FALSE;
3100a9fa9459Szrj
3101a9fa9459Szrj if (! ISDIGIT (**pp) && **pp != '-')
3102a9fa9459Szrj {
3103a9fa9459Szrj ++*pp;
3104a9fa9459Szrj adjustable = TRUE;
3105a9fa9459Szrj }
3106a9fa9459Szrj
3107a9fa9459Szrj lower = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL);
3108a9fa9459Szrj if (**pp != ';')
3109a9fa9459Szrj {
3110a9fa9459Szrj bad_stab (orig);
3111a9fa9459Szrj return DEBUG_TYPE_NULL;
3112a9fa9459Szrj }
3113a9fa9459Szrj ++*pp;
3114a9fa9459Szrj
3115a9fa9459Szrj if (! ISDIGIT (**pp) && **pp != '-')
3116a9fa9459Szrj {
3117a9fa9459Szrj ++*pp;
3118a9fa9459Szrj adjustable = TRUE;
3119a9fa9459Szrj }
3120a9fa9459Szrj
3121a9fa9459Szrj upper = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL);
3122a9fa9459Szrj if (**pp != ';')
3123a9fa9459Szrj {
3124a9fa9459Szrj bad_stab (orig);
3125a9fa9459Szrj return DEBUG_TYPE_NULL;
3126a9fa9459Szrj }
3127a9fa9459Szrj ++*pp;
3128a9fa9459Szrj
3129a9fa9459Szrj element_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
3130a9fa9459Szrj (debug_type **) NULL);
3131a9fa9459Szrj if (element_type == DEBUG_TYPE_NULL)
3132a9fa9459Szrj return DEBUG_TYPE_NULL;
3133a9fa9459Szrj
3134a9fa9459Szrj if (adjustable)
3135a9fa9459Szrj {
3136a9fa9459Szrj lower = 0;
3137a9fa9459Szrj upper = -1;
3138a9fa9459Szrj }
3139a9fa9459Szrj
3140a9fa9459Szrj return debug_make_array_type (dhandle, element_type, index_type, lower,
3141a9fa9459Szrj upper, stringp);
3142a9fa9459Szrj }
3143a9fa9459Szrj
3144a9fa9459Szrj /* This struct holds information about files we have seen using
3145a9fa9459Szrj N_BINCL. */
3146a9fa9459Szrj
3147a9fa9459Szrj struct bincl_file
3148a9fa9459Szrj {
3149a9fa9459Szrj /* The next N_BINCL file. */
3150a9fa9459Szrj struct bincl_file *next;
3151a9fa9459Szrj /* The next N_BINCL on the stack. */
3152a9fa9459Szrj struct bincl_file *next_stack;
3153a9fa9459Szrj /* The file name. */
3154a9fa9459Szrj const char *name;
3155a9fa9459Szrj /* The hash value. */
3156a9fa9459Szrj bfd_vma hash;
3157a9fa9459Szrj /* The file index. */
3158a9fa9459Szrj unsigned int file;
3159a9fa9459Szrj /* The list of types defined in this file. */
3160a9fa9459Szrj struct stab_types *file_types;
3161a9fa9459Szrj };
3162a9fa9459Szrj
3163a9fa9459Szrj /* Start a new N_BINCL file, pushing it onto the stack. */
3164a9fa9459Szrj
3165a9fa9459Szrj static void
push_bincl(struct stab_handle * info,const char * name,bfd_vma hash)3166a9fa9459Szrj push_bincl (struct stab_handle *info, const char *name, bfd_vma hash)
3167a9fa9459Szrj {
3168a9fa9459Szrj struct bincl_file *n;
3169a9fa9459Szrj
3170a9fa9459Szrj n = (struct bincl_file *) xmalloc (sizeof *n);
3171a9fa9459Szrj n->next = info->bincl_list;
3172a9fa9459Szrj n->next_stack = info->bincl_stack;
3173a9fa9459Szrj n->name = name;
3174a9fa9459Szrj n->hash = hash;
3175a9fa9459Szrj n->file = info->files;
3176a9fa9459Szrj n->file_types = NULL;
3177a9fa9459Szrj info->bincl_list = n;
3178a9fa9459Szrj info->bincl_stack = n;
3179a9fa9459Szrj
3180a9fa9459Szrj ++info->files;
3181a9fa9459Szrj info->file_types = ((struct stab_types **)
3182a9fa9459Szrj xrealloc (info->file_types,
3183a9fa9459Szrj (info->files
3184a9fa9459Szrj * sizeof *info->file_types)));
3185a9fa9459Szrj info->file_types[n->file] = NULL;
3186a9fa9459Szrj }
3187a9fa9459Szrj
3188a9fa9459Szrj /* Finish an N_BINCL file, at an N_EINCL, popping the name off the
3189a9fa9459Szrj stack. */
3190a9fa9459Szrj
3191a9fa9459Szrj static const char *
pop_bincl(struct stab_handle * info)3192a9fa9459Szrj pop_bincl (struct stab_handle *info)
3193a9fa9459Szrj {
3194a9fa9459Szrj struct bincl_file *o;
3195a9fa9459Szrj
3196a9fa9459Szrj o = info->bincl_stack;
3197a9fa9459Szrj if (o == NULL)
3198a9fa9459Szrj return info->main_filename;
3199a9fa9459Szrj info->bincl_stack = o->next_stack;
3200a9fa9459Szrj
3201a9fa9459Szrj o->file_types = info->file_types[o->file];
3202a9fa9459Szrj
3203a9fa9459Szrj if (info->bincl_stack == NULL)
3204a9fa9459Szrj return info->main_filename;
3205a9fa9459Szrj return info->bincl_stack->name;
3206a9fa9459Szrj }
3207a9fa9459Szrj
3208a9fa9459Szrj /* Handle an N_EXCL: get the types from the corresponding N_BINCL. */
3209a9fa9459Szrj
3210a9fa9459Szrj static bfd_boolean
find_excl(struct stab_handle * info,const char * name,bfd_vma hash)3211a9fa9459Szrj find_excl (struct stab_handle *info, const char *name, bfd_vma hash)
3212a9fa9459Szrj {
3213a9fa9459Szrj struct bincl_file *l;
3214a9fa9459Szrj
3215a9fa9459Szrj ++info->files;
3216a9fa9459Szrj info->file_types = ((struct stab_types **)
3217a9fa9459Szrj xrealloc (info->file_types,
3218a9fa9459Szrj (info->files
3219a9fa9459Szrj * sizeof *info->file_types)));
3220a9fa9459Szrj
3221a9fa9459Szrj for (l = info->bincl_list; l != NULL; l = l->next)
3222a9fa9459Szrj if (l->hash == hash && strcmp (l->name, name) == 0)
3223a9fa9459Szrj break;
3224a9fa9459Szrj if (l == NULL)
3225a9fa9459Szrj {
3226a9fa9459Szrj warn_stab (name, _("Undefined N_EXCL"));
3227a9fa9459Szrj info->file_types[info->files - 1] = NULL;
3228a9fa9459Szrj return TRUE;
3229a9fa9459Szrj }
3230a9fa9459Szrj
3231a9fa9459Szrj info->file_types[info->files - 1] = l->file_types;
3232a9fa9459Szrj
3233a9fa9459Szrj return TRUE;
3234a9fa9459Szrj }
3235a9fa9459Szrj
3236a9fa9459Szrj /* Handle a variable definition. gcc emits variable definitions for a
3237a9fa9459Szrj block before the N_LBRAC, so we must hold onto them until we see
3238a9fa9459Szrj it. The SunPRO compiler emits variable definitions after the
3239a9fa9459Szrj N_LBRAC, so we can call debug_record_variable immediately. */
3240a9fa9459Szrj
3241a9fa9459Szrj static bfd_boolean
stab_record_variable(void * dhandle,struct stab_handle * info,const char * name,debug_type type,enum debug_var_kind kind,bfd_vma val)3242a9fa9459Szrj stab_record_variable (void *dhandle, struct stab_handle *info,
3243a9fa9459Szrj const char *name, debug_type type,
3244a9fa9459Szrj enum debug_var_kind kind, bfd_vma val)
3245a9fa9459Szrj {
3246a9fa9459Szrj struct stab_pending_var *v;
3247a9fa9459Szrj
3248a9fa9459Szrj if ((kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
3249a9fa9459Szrj || ! info->within_function
3250a9fa9459Szrj || (info->gcc_compiled == 0 && info->n_opt_found))
3251a9fa9459Szrj return debug_record_variable (dhandle, name, type, kind, val);
3252a9fa9459Szrj
3253a9fa9459Szrj v = (struct stab_pending_var *) xmalloc (sizeof *v);
3254a9fa9459Szrj memset (v, 0, sizeof *v);
3255a9fa9459Szrj
3256a9fa9459Szrj v->next = info->pending;
3257a9fa9459Szrj v->name = name;
3258a9fa9459Szrj v->type = type;
3259a9fa9459Szrj v->kind = kind;
3260a9fa9459Szrj v->val = val;
3261a9fa9459Szrj info->pending = v;
3262a9fa9459Szrj
3263a9fa9459Szrj return TRUE;
3264a9fa9459Szrj }
3265a9fa9459Szrj
3266a9fa9459Szrj /* Emit pending variable definitions. This is called after we see the
3267a9fa9459Szrj N_LBRAC that starts the block. */
3268a9fa9459Szrj
3269a9fa9459Szrj static bfd_boolean
stab_emit_pending_vars(void * dhandle,struct stab_handle * info)3270a9fa9459Szrj stab_emit_pending_vars (void *dhandle, struct stab_handle *info)
3271a9fa9459Szrj {
3272a9fa9459Szrj struct stab_pending_var *v;
3273a9fa9459Szrj
3274a9fa9459Szrj v = info->pending;
3275a9fa9459Szrj while (v != NULL)
3276a9fa9459Szrj {
3277a9fa9459Szrj struct stab_pending_var *next;
3278a9fa9459Szrj
3279a9fa9459Szrj if (! debug_record_variable (dhandle, v->name, v->type, v->kind, v->val))
3280a9fa9459Szrj return FALSE;
3281a9fa9459Szrj
3282a9fa9459Szrj next = v->next;
3283a9fa9459Szrj free (v);
3284a9fa9459Szrj v = next;
3285a9fa9459Szrj }
3286a9fa9459Szrj
3287a9fa9459Szrj info->pending = NULL;
3288a9fa9459Szrj
3289a9fa9459Szrj return TRUE;
3290a9fa9459Szrj }
3291a9fa9459Szrj
3292a9fa9459Szrj /* Find the slot for a type in the database. */
3293a9fa9459Szrj
3294a9fa9459Szrj static debug_type *
stab_find_slot(struct stab_handle * info,const int * typenums)3295a9fa9459Szrj stab_find_slot (struct stab_handle *info, const int *typenums)
3296a9fa9459Szrj {
3297a9fa9459Szrj int filenum;
3298a9fa9459Szrj int tindex;
3299a9fa9459Szrj struct stab_types **ps;
3300a9fa9459Szrj
3301a9fa9459Szrj filenum = typenums[0];
3302a9fa9459Szrj tindex = typenums[1];
3303a9fa9459Szrj
3304a9fa9459Szrj if (filenum < 0 || (unsigned int) filenum >= info->files)
3305a9fa9459Szrj {
3306a9fa9459Szrj fprintf (stderr, _("Type file number %d out of range\n"), filenum);
3307a9fa9459Szrj return NULL;
3308a9fa9459Szrj }
3309a9fa9459Szrj if (tindex < 0)
3310a9fa9459Szrj {
3311a9fa9459Szrj fprintf (stderr, _("Type index number %d out of range\n"), tindex);
3312a9fa9459Szrj return NULL;
3313a9fa9459Szrj }
3314a9fa9459Szrj
3315a9fa9459Szrj ps = info->file_types + filenum;
3316a9fa9459Szrj
3317a9fa9459Szrj while (tindex >= STAB_TYPES_SLOTS)
3318a9fa9459Szrj {
3319a9fa9459Szrj if (*ps == NULL)
3320a9fa9459Szrj {
3321a9fa9459Szrj *ps = (struct stab_types *) xmalloc (sizeof **ps);
3322a9fa9459Szrj memset (*ps, 0, sizeof **ps);
3323a9fa9459Szrj }
3324a9fa9459Szrj ps = &(*ps)->next;
3325a9fa9459Szrj tindex -= STAB_TYPES_SLOTS;
3326a9fa9459Szrj }
3327a9fa9459Szrj if (*ps == NULL)
3328a9fa9459Szrj {
3329a9fa9459Szrj *ps = (struct stab_types *) xmalloc (sizeof **ps);
3330a9fa9459Szrj memset (*ps, 0, sizeof **ps);
3331a9fa9459Szrj }
3332a9fa9459Szrj
3333a9fa9459Szrj return (*ps)->types + tindex;
3334a9fa9459Szrj }
3335a9fa9459Szrj
3336a9fa9459Szrj /* Find a type given a type number. If the type has not been
3337a9fa9459Szrj allocated yet, create an indirect type. */
3338a9fa9459Szrj
3339a9fa9459Szrj static debug_type
stab_find_type(void * dhandle,struct stab_handle * info,const int * typenums)3340a9fa9459Szrj stab_find_type (void *dhandle, struct stab_handle *info, const int *typenums)
3341a9fa9459Szrj {
3342a9fa9459Szrj debug_type *slot;
3343a9fa9459Szrj
3344a9fa9459Szrj if (typenums[0] == 0 && typenums[1] < 0)
3345a9fa9459Szrj {
3346a9fa9459Szrj /* A negative type number indicates an XCOFF builtin type. */
3347a9fa9459Szrj return stab_xcoff_builtin_type (dhandle, info, typenums[1]);
3348a9fa9459Szrj }
3349a9fa9459Szrj
3350a9fa9459Szrj slot = stab_find_slot (info, typenums);
3351a9fa9459Szrj if (slot == NULL)
3352a9fa9459Szrj return DEBUG_TYPE_NULL;
3353a9fa9459Szrj
3354a9fa9459Szrj if (*slot == DEBUG_TYPE_NULL)
3355a9fa9459Szrj return debug_make_indirect_type (dhandle, slot, (const char *) NULL);
3356a9fa9459Szrj
3357a9fa9459Szrj return *slot;
3358a9fa9459Szrj }
3359a9fa9459Szrj
3360a9fa9459Szrj /* Record that a given type number refers to a given type. */
3361a9fa9459Szrj
3362a9fa9459Szrj static bfd_boolean
stab_record_type(void * dhandle ATTRIBUTE_UNUSED,struct stab_handle * info,const int * typenums,debug_type type)3363a9fa9459Szrj stab_record_type (void *dhandle ATTRIBUTE_UNUSED, struct stab_handle *info,
3364a9fa9459Szrj const int *typenums, debug_type type)
3365a9fa9459Szrj {
3366a9fa9459Szrj debug_type *slot;
3367a9fa9459Szrj
3368a9fa9459Szrj slot = stab_find_slot (info, typenums);
3369a9fa9459Szrj if (slot == NULL)
3370a9fa9459Szrj return FALSE;
3371a9fa9459Szrj
3372a9fa9459Szrj /* gdb appears to ignore type redefinitions, so we do as well. */
3373a9fa9459Szrj
3374a9fa9459Szrj *slot = type;
3375a9fa9459Szrj
3376a9fa9459Szrj return TRUE;
3377a9fa9459Szrj }
3378a9fa9459Szrj
3379a9fa9459Szrj /* Return an XCOFF builtin type. */
3380a9fa9459Szrj
3381a9fa9459Szrj static debug_type
stab_xcoff_builtin_type(void * dhandle,struct stab_handle * info,int typenum)3382a9fa9459Szrj stab_xcoff_builtin_type (void *dhandle, struct stab_handle *info,
3383a9fa9459Szrj int typenum)
3384a9fa9459Szrj {
3385a9fa9459Szrj debug_type rettype;
3386a9fa9459Szrj const char *name;
3387a9fa9459Szrj
3388a9fa9459Szrj if (typenum >= 0 || typenum < -XCOFF_TYPE_COUNT)
3389a9fa9459Szrj {
3390a9fa9459Szrj fprintf (stderr, _("Unrecognized XCOFF type %d\n"), typenum);
3391a9fa9459Szrj return DEBUG_TYPE_NULL;
3392a9fa9459Szrj }
3393a9fa9459Szrj if (info->xcoff_types[-typenum] != NULL)
3394a9fa9459Szrj return info->xcoff_types[-typenum];
3395a9fa9459Szrj
3396a9fa9459Szrj switch (-typenum)
3397a9fa9459Szrj {
3398a9fa9459Szrj case 1:
3399a9fa9459Szrj /* The size of this and all the other types are fixed, defined
3400a9fa9459Szrj by the debugging format. */
3401a9fa9459Szrj name = "int";
3402a9fa9459Szrj rettype = debug_make_int_type (dhandle, 4, FALSE);
3403a9fa9459Szrj break;
3404a9fa9459Szrj case 2:
3405a9fa9459Szrj name = "char";
3406a9fa9459Szrj rettype = debug_make_int_type (dhandle, 1, FALSE);
3407a9fa9459Szrj break;
3408a9fa9459Szrj case 3:
3409a9fa9459Szrj name = "short";
3410a9fa9459Szrj rettype = debug_make_int_type (dhandle, 2, FALSE);
3411a9fa9459Szrj break;
3412a9fa9459Szrj case 4:
3413a9fa9459Szrj name = "long";
3414a9fa9459Szrj rettype = debug_make_int_type (dhandle, 4, FALSE);
3415a9fa9459Szrj break;
3416a9fa9459Szrj case 5:
3417a9fa9459Szrj name = "unsigned char";
3418a9fa9459Szrj rettype = debug_make_int_type (dhandle, 1, TRUE);
3419a9fa9459Szrj break;
3420a9fa9459Szrj case 6:
3421a9fa9459Szrj name = "signed char";
3422a9fa9459Szrj rettype = debug_make_int_type (dhandle, 1, FALSE);
3423a9fa9459Szrj break;
3424a9fa9459Szrj case 7:
3425a9fa9459Szrj name = "unsigned short";
3426a9fa9459Szrj rettype = debug_make_int_type (dhandle, 2, TRUE);
3427a9fa9459Szrj break;
3428a9fa9459Szrj case 8:
3429a9fa9459Szrj name = "unsigned int";
3430a9fa9459Szrj rettype = debug_make_int_type (dhandle, 4, TRUE);
3431a9fa9459Szrj break;
3432a9fa9459Szrj case 9:
3433a9fa9459Szrj name = "unsigned";
3434a9fa9459Szrj rettype = debug_make_int_type (dhandle, 4, TRUE);
3435a9fa9459Szrj case 10:
3436a9fa9459Szrj name = "unsigned long";
3437a9fa9459Szrj rettype = debug_make_int_type (dhandle, 4, TRUE);
3438a9fa9459Szrj break;
3439a9fa9459Szrj case 11:
3440a9fa9459Szrj name = "void";
3441a9fa9459Szrj rettype = debug_make_void_type (dhandle);
3442a9fa9459Szrj break;
3443a9fa9459Szrj case 12:
3444a9fa9459Szrj /* IEEE single precision (32 bit). */
3445a9fa9459Szrj name = "float";
3446a9fa9459Szrj rettype = debug_make_float_type (dhandle, 4);
3447a9fa9459Szrj break;
3448a9fa9459Szrj case 13:
3449a9fa9459Szrj /* IEEE double precision (64 bit). */
3450a9fa9459Szrj name = "double";
3451a9fa9459Szrj rettype = debug_make_float_type (dhandle, 8);
3452a9fa9459Szrj break;
3453a9fa9459Szrj case 14:
3454a9fa9459Szrj /* This is an IEEE double on the RS/6000, and different machines
3455a9fa9459Szrj with different sizes for "long double" should use different
3456a9fa9459Szrj negative type numbers. See stabs.texinfo. */
3457a9fa9459Szrj name = "long double";
3458a9fa9459Szrj rettype = debug_make_float_type (dhandle, 8);
3459a9fa9459Szrj break;
3460a9fa9459Szrj case 15:
3461a9fa9459Szrj name = "integer";
3462a9fa9459Szrj rettype = debug_make_int_type (dhandle, 4, FALSE);
3463a9fa9459Szrj break;
3464a9fa9459Szrj case 16:
3465a9fa9459Szrj name = "boolean";
3466a9fa9459Szrj rettype = debug_make_bool_type (dhandle, 4);
3467a9fa9459Szrj break;
3468a9fa9459Szrj case 17:
3469a9fa9459Szrj name = "short real";
3470a9fa9459Szrj rettype = debug_make_float_type (dhandle, 4);
3471a9fa9459Szrj break;
3472a9fa9459Szrj case 18:
3473a9fa9459Szrj name = "real";
3474a9fa9459Szrj rettype = debug_make_float_type (dhandle, 8);
3475a9fa9459Szrj break;
3476a9fa9459Szrj case 19:
3477a9fa9459Szrj /* FIXME */
3478a9fa9459Szrj name = "stringptr";
3479a9fa9459Szrj rettype = NULL;
3480a9fa9459Szrj break;
3481a9fa9459Szrj case 20:
3482a9fa9459Szrj /* FIXME */
3483a9fa9459Szrj name = "character";
3484a9fa9459Szrj rettype = debug_make_int_type (dhandle, 1, TRUE);
3485a9fa9459Szrj break;
3486a9fa9459Szrj case 21:
3487a9fa9459Szrj name = "logical*1";
3488a9fa9459Szrj rettype = debug_make_bool_type (dhandle, 1);
3489a9fa9459Szrj break;
3490a9fa9459Szrj case 22:
3491a9fa9459Szrj name = "logical*2";
3492a9fa9459Szrj rettype = debug_make_bool_type (dhandle, 2);
3493a9fa9459Szrj break;
3494a9fa9459Szrj case 23:
3495a9fa9459Szrj name = "logical*4";
3496a9fa9459Szrj rettype = debug_make_bool_type (dhandle, 4);
3497a9fa9459Szrj break;
3498a9fa9459Szrj case 24:
3499a9fa9459Szrj name = "logical";
3500a9fa9459Szrj rettype = debug_make_bool_type (dhandle, 4);
3501a9fa9459Szrj break;
3502a9fa9459Szrj case 25:
3503a9fa9459Szrj /* Complex type consisting of two IEEE single precision values. */
3504a9fa9459Szrj name = "complex";
3505a9fa9459Szrj rettype = debug_make_complex_type (dhandle, 8);
3506a9fa9459Szrj break;
3507a9fa9459Szrj case 26:
3508a9fa9459Szrj /* Complex type consisting of two IEEE double precision values. */
3509a9fa9459Szrj name = "double complex";
3510a9fa9459Szrj rettype = debug_make_complex_type (dhandle, 16);
3511a9fa9459Szrj break;
3512a9fa9459Szrj case 27:
3513a9fa9459Szrj name = "integer*1";
3514a9fa9459Szrj rettype = debug_make_int_type (dhandle, 1, FALSE);
3515a9fa9459Szrj break;
3516a9fa9459Szrj case 28:
3517a9fa9459Szrj name = "integer*2";
3518a9fa9459Szrj rettype = debug_make_int_type (dhandle, 2, FALSE);
3519a9fa9459Szrj break;
3520a9fa9459Szrj case 29:
3521a9fa9459Szrj name = "integer*4";
3522a9fa9459Szrj rettype = debug_make_int_type (dhandle, 4, FALSE);
3523a9fa9459Szrj break;
3524a9fa9459Szrj case 30:
3525a9fa9459Szrj /* FIXME */
3526a9fa9459Szrj name = "wchar";
3527a9fa9459Szrj rettype = debug_make_int_type (dhandle, 2, FALSE);
3528a9fa9459Szrj break;
3529a9fa9459Szrj case 31:
3530a9fa9459Szrj name = "long long";
3531a9fa9459Szrj rettype = debug_make_int_type (dhandle, 8, FALSE);
3532a9fa9459Szrj break;
3533a9fa9459Szrj case 32:
3534a9fa9459Szrj name = "unsigned long long";
3535a9fa9459Szrj rettype = debug_make_int_type (dhandle, 8, TRUE);
3536a9fa9459Szrj break;
3537a9fa9459Szrj case 33:
3538a9fa9459Szrj name = "logical*8";
3539a9fa9459Szrj rettype = debug_make_bool_type (dhandle, 8);
3540a9fa9459Szrj break;
3541a9fa9459Szrj case 34:
3542a9fa9459Szrj name = "integer*8";
3543a9fa9459Szrj rettype = debug_make_int_type (dhandle, 8, FALSE);
3544a9fa9459Szrj break;
3545a9fa9459Szrj default:
3546a9fa9459Szrj abort ();
3547a9fa9459Szrj }
3548a9fa9459Szrj
3549a9fa9459Szrj rettype = debug_name_type (dhandle, name, rettype);
3550a9fa9459Szrj
3551a9fa9459Szrj info->xcoff_types[-typenum] = rettype;
3552a9fa9459Szrj
3553a9fa9459Szrj return rettype;
3554a9fa9459Szrj }
3555a9fa9459Szrj
3556a9fa9459Szrj /* Find or create a tagged type. */
3557a9fa9459Szrj
3558a9fa9459Szrj static debug_type
stab_find_tagged_type(void * dhandle,struct stab_handle * info,const char * p,int len,enum debug_type_kind kind)3559a9fa9459Szrj stab_find_tagged_type (void *dhandle, struct stab_handle *info,
3560a9fa9459Szrj const char *p, int len, enum debug_type_kind kind)
3561a9fa9459Szrj {
3562a9fa9459Szrj char *name;
3563a9fa9459Szrj debug_type dtype;
3564a9fa9459Szrj struct stab_tag *st;
3565a9fa9459Szrj
3566a9fa9459Szrj name = savestring (p, len);
3567a9fa9459Szrj
3568a9fa9459Szrj /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same
3569a9fa9459Szrj namespace. This is right for C, and I don't know how to handle
3570a9fa9459Szrj other languages. FIXME. */
3571a9fa9459Szrj dtype = debug_find_tagged_type (dhandle, name, DEBUG_KIND_ILLEGAL);
3572a9fa9459Szrj if (dtype != DEBUG_TYPE_NULL)
3573a9fa9459Szrj {
3574a9fa9459Szrj free (name);
3575a9fa9459Szrj return dtype;
3576a9fa9459Szrj }
3577a9fa9459Szrj
3578a9fa9459Szrj /* We need to allocate an entry on the undefined tag list. */
3579a9fa9459Szrj for (st = info->tags; st != NULL; st = st->next)
3580a9fa9459Szrj {
3581a9fa9459Szrj if (st->name[0] == name[0]
3582a9fa9459Szrj && strcmp (st->name, name) == 0)
3583a9fa9459Szrj {
3584a9fa9459Szrj if (st->kind == DEBUG_KIND_ILLEGAL)
3585a9fa9459Szrj st->kind = kind;
3586a9fa9459Szrj free (name);
3587a9fa9459Szrj break;
3588a9fa9459Szrj }
3589a9fa9459Szrj }
3590a9fa9459Szrj if (st == NULL)
3591a9fa9459Szrj {
3592a9fa9459Szrj st = (struct stab_tag *) xmalloc (sizeof *st);
3593a9fa9459Szrj memset (st, 0, sizeof *st);
3594a9fa9459Szrj
3595a9fa9459Szrj st->next = info->tags;
3596a9fa9459Szrj st->name = name;
3597a9fa9459Szrj st->kind = kind;
3598a9fa9459Szrj st->slot = DEBUG_TYPE_NULL;
3599a9fa9459Szrj st->type = debug_make_indirect_type (dhandle, &st->slot, name);
3600a9fa9459Szrj info->tags = st;
3601a9fa9459Szrj }
3602a9fa9459Szrj
3603a9fa9459Szrj return st->type;
3604a9fa9459Szrj }
3605a9fa9459Szrj
3606a9fa9459Szrj /* In order to get the correct argument types for a stubbed method, we
3607a9fa9459Szrj need to extract the argument types from a C++ mangled string.
3608a9fa9459Szrj Since the argument types can refer back to the return type, this
3609a9fa9459Szrj means that we must demangle the entire physical name. In gdb this
3610a9fa9459Szrj is done by calling cplus_demangle and running the results back
3611a9fa9459Szrj through the C++ expression parser. Since we have no expression
3612a9fa9459Szrj parser, we must duplicate much of the work of cplus_demangle here.
3613a9fa9459Szrj
3614a9fa9459Szrj We assume that GNU style demangling is used, since this is only
3615a9fa9459Szrj done for method stubs, and only g++ should output that form of
3616a9fa9459Szrj debugging information. */
3617a9fa9459Szrj
3618a9fa9459Szrj /* This structure is used to hold a pointer to type information which
3619a9fa9459Szrj demangling a string. */
3620a9fa9459Szrj
3621a9fa9459Szrj struct stab_demangle_typestring
3622a9fa9459Szrj {
3623a9fa9459Szrj /* The start of the type. This is not null terminated. */
3624a9fa9459Szrj const char *typestring;
3625a9fa9459Szrj /* The length of the type. */
3626a9fa9459Szrj unsigned int len;
3627a9fa9459Szrj };
3628a9fa9459Szrj
3629a9fa9459Szrj /* This structure is used to hold information while demangling a
3630a9fa9459Szrj string. */
3631a9fa9459Szrj
3632a9fa9459Szrj struct stab_demangle_info
3633a9fa9459Szrj {
3634a9fa9459Szrj /* The debugging information handle. */
3635a9fa9459Szrj void *dhandle;
3636a9fa9459Szrj /* The stab information handle. */
3637a9fa9459Szrj struct stab_handle *info;
3638a9fa9459Szrj /* The array of arguments we are building. */
3639a9fa9459Szrj debug_type *args;
3640a9fa9459Szrj /* Whether the method takes a variable number of arguments. */
3641a9fa9459Szrj bfd_boolean varargs;
3642a9fa9459Szrj /* The array of types we have remembered. */
3643a9fa9459Szrj struct stab_demangle_typestring *typestrings;
3644a9fa9459Szrj /* The number of typestrings. */
3645a9fa9459Szrj unsigned int typestring_count;
3646a9fa9459Szrj /* The number of typestring slots we have allocated. */
3647a9fa9459Szrj unsigned int typestring_alloc;
3648a9fa9459Szrj };
3649a9fa9459Szrj
3650a9fa9459Szrj static void stab_bad_demangle (const char *);
3651a9fa9459Szrj static unsigned int stab_demangle_count (const char **);
3652a9fa9459Szrj static bfd_boolean stab_demangle_get_count (const char **, unsigned int *);
3653a9fa9459Szrj static bfd_boolean stab_demangle_prefix
3654a9fa9459Szrj (struct stab_demangle_info *, const char **, unsigned int);
3655a9fa9459Szrj static bfd_boolean stab_demangle_function_name
3656a9fa9459Szrj (struct stab_demangle_info *, const char **, const char *);
3657a9fa9459Szrj static bfd_boolean stab_demangle_signature
3658a9fa9459Szrj (struct stab_demangle_info *, const char **);
3659a9fa9459Szrj static bfd_boolean stab_demangle_qualified
3660a9fa9459Szrj (struct stab_demangle_info *, const char **, debug_type *);
3661a9fa9459Szrj static bfd_boolean stab_demangle_template
3662a9fa9459Szrj (struct stab_demangle_info *, const char **, char **);
3663a9fa9459Szrj static bfd_boolean stab_demangle_class
3664a9fa9459Szrj (struct stab_demangle_info *, const char **, const char **);
3665a9fa9459Szrj static bfd_boolean stab_demangle_args
3666a9fa9459Szrj (struct stab_demangle_info *, const char **, debug_type **, bfd_boolean *);
3667a9fa9459Szrj static bfd_boolean stab_demangle_arg
3668a9fa9459Szrj (struct stab_demangle_info *, const char **, debug_type **,
3669a9fa9459Szrj unsigned int *, unsigned int *);
3670a9fa9459Szrj static bfd_boolean stab_demangle_type
3671a9fa9459Szrj (struct stab_demangle_info *, const char **, debug_type *);
3672a9fa9459Szrj static bfd_boolean stab_demangle_fund_type
3673a9fa9459Szrj (struct stab_demangle_info *, const char **, debug_type *);
3674a9fa9459Szrj static bfd_boolean stab_demangle_remember_type
3675a9fa9459Szrj (struct stab_demangle_info *, const char *, int);
3676a9fa9459Szrj
3677a9fa9459Szrj /* Warn about a bad demangling. */
3678a9fa9459Szrj
3679a9fa9459Szrj static void
stab_bad_demangle(const char * s)3680a9fa9459Szrj stab_bad_demangle (const char *s)
3681a9fa9459Szrj {
3682a9fa9459Szrj fprintf (stderr, _("bad mangled name `%s'\n"), s);
3683a9fa9459Szrj }
3684a9fa9459Szrj
3685a9fa9459Szrj /* Get a count from a stab string. */
3686a9fa9459Szrj
3687a9fa9459Szrj static unsigned int
stab_demangle_count(const char ** pp)3688a9fa9459Szrj stab_demangle_count (const char **pp)
3689a9fa9459Szrj {
3690a9fa9459Szrj unsigned int count;
3691a9fa9459Szrj
3692a9fa9459Szrj count = 0;
3693a9fa9459Szrj while (ISDIGIT (**pp))
3694a9fa9459Szrj {
3695a9fa9459Szrj count *= 10;
3696a9fa9459Szrj count += **pp - '0';
3697a9fa9459Szrj ++*pp;
3698a9fa9459Szrj }
3699a9fa9459Szrj return count;
3700a9fa9459Szrj }
3701a9fa9459Szrj
3702a9fa9459Szrj /* Require a count in a string. The count may be multiple digits, in
3703a9fa9459Szrj which case it must end in an underscore. */
3704a9fa9459Szrj
3705a9fa9459Szrj static bfd_boolean
stab_demangle_get_count(const char ** pp,unsigned int * pi)3706a9fa9459Szrj stab_demangle_get_count (const char **pp, unsigned int *pi)
3707a9fa9459Szrj {
3708a9fa9459Szrj if (! ISDIGIT (**pp))
3709a9fa9459Szrj return FALSE;
3710a9fa9459Szrj
3711a9fa9459Szrj *pi = **pp - '0';
3712a9fa9459Szrj ++*pp;
3713a9fa9459Szrj if (ISDIGIT (**pp))
3714a9fa9459Szrj {
3715a9fa9459Szrj unsigned int count;
3716a9fa9459Szrj const char *p;
3717a9fa9459Szrj
3718a9fa9459Szrj count = *pi;
3719a9fa9459Szrj p = *pp;
3720a9fa9459Szrj do
3721a9fa9459Szrj {
3722a9fa9459Szrj count *= 10;
3723a9fa9459Szrj count += *p - '0';
3724a9fa9459Szrj ++p;
3725a9fa9459Szrj }
3726a9fa9459Szrj while (ISDIGIT (*p));
3727a9fa9459Szrj if (*p == '_')
3728a9fa9459Szrj {
3729a9fa9459Szrj *pp = p + 1;
3730a9fa9459Szrj *pi = count;
3731a9fa9459Szrj }
3732a9fa9459Szrj }
3733a9fa9459Szrj
3734a9fa9459Szrj return TRUE;
3735a9fa9459Szrj }
3736a9fa9459Szrj
3737a9fa9459Szrj /* This function demangles a physical name, returning a NULL
3738a9fa9459Szrj terminated array of argument types. */
3739a9fa9459Szrj
3740a9fa9459Szrj static debug_type *
stab_demangle_argtypes(void * dhandle,struct stab_handle * info,const char * physname,bfd_boolean * pvarargs,unsigned int physname_len)3741a9fa9459Szrj stab_demangle_argtypes (void *dhandle, struct stab_handle *info,
3742a9fa9459Szrj const char *physname, bfd_boolean *pvarargs,
3743a9fa9459Szrj unsigned int physname_len)
3744a9fa9459Szrj {
3745a9fa9459Szrj struct stab_demangle_info minfo;
3746a9fa9459Szrj
3747a9fa9459Szrj /* Check for the g++ V3 ABI. */
3748a9fa9459Szrj if (physname[0] == '_' && physname[1] == 'Z')
3749a9fa9459Szrj return stab_demangle_v3_argtypes (dhandle, info, physname, pvarargs);
3750a9fa9459Szrj
3751a9fa9459Szrj minfo.dhandle = dhandle;
3752a9fa9459Szrj minfo.info = info;
3753a9fa9459Szrj minfo.args = NULL;
3754a9fa9459Szrj minfo.varargs = FALSE;
3755a9fa9459Szrj minfo.typestring_alloc = 10;
3756a9fa9459Szrj minfo.typestrings = ((struct stab_demangle_typestring *)
3757a9fa9459Szrj xmalloc (minfo.typestring_alloc
3758a9fa9459Szrj * sizeof *minfo.typestrings));
3759a9fa9459Szrj minfo.typestring_count = 0;
3760a9fa9459Szrj
3761a9fa9459Szrj /* cplus_demangle checks for special GNU mangled forms, but we can't
3762a9fa9459Szrj see any of them in mangled method argument types. */
3763a9fa9459Szrj
3764a9fa9459Szrj if (! stab_demangle_prefix (&minfo, &physname, physname_len))
3765a9fa9459Szrj goto error_return;
3766a9fa9459Szrj
3767a9fa9459Szrj if (*physname != '\0')
3768a9fa9459Szrj {
3769a9fa9459Szrj if (! stab_demangle_signature (&minfo, &physname))
3770a9fa9459Szrj goto error_return;
3771a9fa9459Szrj }
3772a9fa9459Szrj
3773a9fa9459Szrj free (minfo.typestrings);
3774a9fa9459Szrj minfo.typestrings = NULL;
3775a9fa9459Szrj
3776a9fa9459Szrj if (minfo.args == NULL)
3777a9fa9459Szrj fprintf (stderr, _("no argument types in mangled string\n"));
3778a9fa9459Szrj
3779a9fa9459Szrj *pvarargs = minfo.varargs;
3780a9fa9459Szrj return minfo.args;
3781a9fa9459Szrj
3782a9fa9459Szrj error_return:
3783a9fa9459Szrj if (minfo.typestrings != NULL)
3784a9fa9459Szrj free (minfo.typestrings);
3785a9fa9459Szrj return NULL;
3786a9fa9459Szrj }
3787a9fa9459Szrj
3788a9fa9459Szrj /* Demangle the prefix of the mangled name. */
3789a9fa9459Szrj
3790a9fa9459Szrj static bfd_boolean
stab_demangle_prefix(struct stab_demangle_info * minfo,const char ** pp,unsigned int physname_len)3791a9fa9459Szrj stab_demangle_prefix (struct stab_demangle_info *minfo, const char **pp,
3792a9fa9459Szrj unsigned int physname_len)
3793a9fa9459Szrj {
3794a9fa9459Szrj const char *scan;
3795a9fa9459Szrj unsigned int i;
3796a9fa9459Szrj
3797a9fa9459Szrj /* cplus_demangle checks for global constructors and destructors,
3798a9fa9459Szrj but we can't see them in mangled argument types. */
3799a9fa9459Szrj
3800a9fa9459Szrj if (physname_len)
3801a9fa9459Szrj scan = *pp + physname_len;
3802a9fa9459Szrj else
3803a9fa9459Szrj {
3804a9fa9459Szrj /* Look for `__'. */
3805a9fa9459Szrj scan = *pp;
3806a9fa9459Szrj do
3807a9fa9459Szrj scan = strchr (scan, '_');
3808a9fa9459Szrj while (scan != NULL && *++scan != '_');
3809a9fa9459Szrj
3810a9fa9459Szrj if (scan == NULL)
3811a9fa9459Szrj {
3812a9fa9459Szrj stab_bad_demangle (*pp);
3813a9fa9459Szrj return FALSE;
3814a9fa9459Szrj }
3815a9fa9459Szrj
3816a9fa9459Szrj --scan;
3817a9fa9459Szrj
3818a9fa9459Szrj /* We found `__'; move ahead to the last contiguous `__' pair. */
3819a9fa9459Szrj i = strspn (scan, "_");
3820a9fa9459Szrj if (i > 2)
3821a9fa9459Szrj scan += i - 2;
3822a9fa9459Szrj }
3823a9fa9459Szrj
3824a9fa9459Szrj if (scan == *pp
3825a9fa9459Szrj && (ISDIGIT (scan[2])
3826a9fa9459Szrj || scan[2] == 'Q'
3827a9fa9459Szrj || scan[2] == 't'))
3828a9fa9459Szrj {
3829a9fa9459Szrj /* This is a GNU style constructor name. */
3830a9fa9459Szrj *pp = scan + 2;
3831a9fa9459Szrj return TRUE;
3832a9fa9459Szrj }
3833a9fa9459Szrj else if (scan == *pp
3834a9fa9459Szrj && ! ISDIGIT (scan[2])
3835a9fa9459Szrj && scan[2] != 't')
3836a9fa9459Szrj {
3837a9fa9459Szrj /* Look for the `__' that separates the prefix from the
3838a9fa9459Szrj signature. */
3839a9fa9459Szrj while (*scan == '_')
3840a9fa9459Szrj ++scan;
3841a9fa9459Szrj scan = strstr (scan, "__");
3842a9fa9459Szrj if (scan == NULL || scan[2] == '\0')
3843a9fa9459Szrj {
3844a9fa9459Szrj stab_bad_demangle (*pp);
3845a9fa9459Szrj return FALSE;
3846a9fa9459Szrj }
3847a9fa9459Szrj
3848a9fa9459Szrj return stab_demangle_function_name (minfo, pp, scan);
3849a9fa9459Szrj }
3850a9fa9459Szrj else if (scan[2] != '\0')
3851a9fa9459Szrj {
3852a9fa9459Szrj /* The name doesn't start with `__', but it does contain `__'. */
3853a9fa9459Szrj return stab_demangle_function_name (minfo, pp, scan);
3854a9fa9459Szrj }
3855a9fa9459Szrj else
3856a9fa9459Szrj {
3857a9fa9459Szrj stab_bad_demangle (*pp);
3858a9fa9459Szrj return FALSE;
3859a9fa9459Szrj }
3860a9fa9459Szrj /*NOTREACHED*/
3861a9fa9459Szrj }
3862a9fa9459Szrj
3863a9fa9459Szrj /* Demangle a function name prefix. The scan argument points to the
3864a9fa9459Szrj double underscore which separates the function name from the
3865a9fa9459Szrj signature. */
3866a9fa9459Szrj
3867a9fa9459Szrj static bfd_boolean
stab_demangle_function_name(struct stab_demangle_info * minfo,const char ** pp,const char * scan)3868a9fa9459Szrj stab_demangle_function_name (struct stab_demangle_info *minfo,
3869a9fa9459Szrj const char **pp, const char *scan)
3870a9fa9459Szrj {
3871a9fa9459Szrj const char *name;
3872a9fa9459Szrj
3873a9fa9459Szrj /* The string from *pp to scan is the name of the function. We
3874a9fa9459Szrj don't care about the name, since we just looking for argument
3875a9fa9459Szrj types. However, for conversion operators, the name may include a
3876a9fa9459Szrj type which we must remember in order to handle backreferences. */
3877a9fa9459Szrj
3878a9fa9459Szrj name = *pp;
3879a9fa9459Szrj *pp = scan + 2;
3880a9fa9459Szrj
3881a9fa9459Szrj if (*pp - name >= 5
3882a9fa9459Szrj && CONST_STRNEQ (name, "type")
3883a9fa9459Szrj && (name[4] == '$' || name[4] == '.'))
3884a9fa9459Szrj {
3885a9fa9459Szrj const char *tem;
3886a9fa9459Szrj
3887a9fa9459Szrj /* This is a type conversion operator. */
3888a9fa9459Szrj tem = name + 5;
3889a9fa9459Szrj if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
3890a9fa9459Szrj return FALSE;
3891a9fa9459Szrj }
3892a9fa9459Szrj else if (name[0] == '_'
3893a9fa9459Szrj && name[1] == '_'
3894a9fa9459Szrj && name[2] == 'o'
3895a9fa9459Szrj && name[3] == 'p')
3896a9fa9459Szrj {
3897a9fa9459Szrj const char *tem;
3898a9fa9459Szrj
3899a9fa9459Szrj /* This is a type conversion operator. */
3900a9fa9459Szrj tem = name + 4;
3901a9fa9459Szrj if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
3902a9fa9459Szrj return FALSE;
3903a9fa9459Szrj }
3904a9fa9459Szrj
3905a9fa9459Szrj return TRUE;
3906a9fa9459Szrj }
3907a9fa9459Szrj
3908a9fa9459Szrj /* Demangle the signature. This is where the argument types are
3909a9fa9459Szrj found. */
3910a9fa9459Szrj
3911a9fa9459Szrj static bfd_boolean
stab_demangle_signature(struct stab_demangle_info * minfo,const char ** pp)3912a9fa9459Szrj stab_demangle_signature (struct stab_demangle_info *minfo, const char **pp)
3913a9fa9459Szrj {
3914a9fa9459Szrj const char *orig;
3915a9fa9459Szrj bfd_boolean expect_func, func_done;
3916a9fa9459Szrj const char *hold;
3917a9fa9459Szrj
3918a9fa9459Szrj orig = *pp;
3919a9fa9459Szrj
3920a9fa9459Szrj expect_func = FALSE;
3921a9fa9459Szrj func_done = FALSE;
3922a9fa9459Szrj hold = NULL;
3923a9fa9459Szrj
3924a9fa9459Szrj while (**pp != '\0')
3925a9fa9459Szrj {
3926a9fa9459Szrj switch (**pp)
3927a9fa9459Szrj {
3928a9fa9459Szrj case 'Q':
3929a9fa9459Szrj hold = *pp;
3930a9fa9459Szrj if (! stab_demangle_qualified (minfo, pp, (debug_type *) NULL)
3931a9fa9459Szrj || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3932a9fa9459Szrj return FALSE;
3933a9fa9459Szrj expect_func = TRUE;
3934a9fa9459Szrj hold = NULL;
3935a9fa9459Szrj break;
3936a9fa9459Szrj
3937a9fa9459Szrj case 'S':
3938a9fa9459Szrj /* Static member function. FIXME: Can this happen? */
3939a9fa9459Szrj if (hold == NULL)
3940a9fa9459Szrj hold = *pp;
3941a9fa9459Szrj ++*pp;
3942a9fa9459Szrj break;
3943a9fa9459Szrj
3944a9fa9459Szrj case 'C':
3945a9fa9459Szrj /* Const member function. */
3946a9fa9459Szrj if (hold == NULL)
3947a9fa9459Szrj hold = *pp;
3948a9fa9459Szrj ++*pp;
3949a9fa9459Szrj break;
3950a9fa9459Szrj
3951a9fa9459Szrj case '0': case '1': case '2': case '3': case '4':
3952a9fa9459Szrj case '5': case '6': case '7': case '8': case '9':
3953a9fa9459Szrj if (hold == NULL)
3954a9fa9459Szrj hold = *pp;
3955a9fa9459Szrj if (! stab_demangle_class (minfo, pp, (const char **) NULL)
3956a9fa9459Szrj || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3957a9fa9459Szrj return FALSE;
3958a9fa9459Szrj expect_func = TRUE;
3959a9fa9459Szrj hold = NULL;
3960a9fa9459Szrj break;
3961a9fa9459Szrj
3962a9fa9459Szrj case 'F':
3963a9fa9459Szrj /* Function. I don't know if this actually happens with g++
3964a9fa9459Szrj output. */
3965a9fa9459Szrj hold = NULL;
3966a9fa9459Szrj func_done = TRUE;
3967a9fa9459Szrj ++*pp;
3968a9fa9459Szrj if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
3969a9fa9459Szrj return FALSE;
3970a9fa9459Szrj break;
3971a9fa9459Szrj
3972a9fa9459Szrj case 't':
3973a9fa9459Szrj /* Template. */
3974a9fa9459Szrj if (hold == NULL)
3975a9fa9459Szrj hold = *pp;
3976a9fa9459Szrj if (! stab_demangle_template (minfo, pp, (char **) NULL)
3977a9fa9459Szrj || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3978a9fa9459Szrj return FALSE;
3979a9fa9459Szrj hold = NULL;
3980a9fa9459Szrj expect_func = TRUE;
3981a9fa9459Szrj break;
3982a9fa9459Szrj
3983a9fa9459Szrj case '_':
3984a9fa9459Szrj /* At the outermost level, we cannot have a return type
3985a9fa9459Szrj specified, so if we run into another '_' at this point we
3986a9fa9459Szrj are dealing with a mangled name that is either bogus, or
3987a9fa9459Szrj has been mangled by some algorithm we don't know how to
3988a9fa9459Szrj deal with. So just reject the entire demangling. */
3989a9fa9459Szrj stab_bad_demangle (orig);
3990a9fa9459Szrj return FALSE;
3991a9fa9459Szrj
3992a9fa9459Szrj default:
3993a9fa9459Szrj /* Assume we have stumbled onto the first outermost function
3994a9fa9459Szrj argument token, and start processing args. */
3995a9fa9459Szrj func_done = TRUE;
3996a9fa9459Szrj if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
3997a9fa9459Szrj return FALSE;
3998a9fa9459Szrj break;
3999a9fa9459Szrj }
4000a9fa9459Szrj
4001a9fa9459Szrj if (expect_func)
4002a9fa9459Szrj {
4003a9fa9459Szrj func_done = TRUE;
4004a9fa9459Szrj if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
4005a9fa9459Szrj return FALSE;
4006a9fa9459Szrj }
4007a9fa9459Szrj }
4008a9fa9459Szrj
4009a9fa9459Szrj if (! func_done)
4010a9fa9459Szrj {
4011a9fa9459Szrj /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and
4012a9fa9459Szrj bar__3fooi is 'foo::bar(int)'. We get here when we find the
4013a9fa9459Szrj first case, and need to ensure that the '(void)' gets added
4014a9fa9459Szrj to the current declp. */
4015a9fa9459Szrj if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
4016a9fa9459Szrj return FALSE;
4017a9fa9459Szrj }
4018a9fa9459Szrj
4019a9fa9459Szrj return TRUE;
4020a9fa9459Szrj }
4021a9fa9459Szrj
4022a9fa9459Szrj /* Demangle a qualified name, such as "Q25Outer5Inner" which is the
4023a9fa9459Szrj mangled form of "Outer::Inner". */
4024a9fa9459Szrj
4025a9fa9459Szrj static bfd_boolean
stab_demangle_qualified(struct stab_demangle_info * minfo,const char ** pp,debug_type * ptype)4026a9fa9459Szrj stab_demangle_qualified (struct stab_demangle_info *minfo, const char **pp,
4027a9fa9459Szrj debug_type *ptype)
4028a9fa9459Szrj {
4029a9fa9459Szrj const char *orig;
4030a9fa9459Szrj const char *p;
4031a9fa9459Szrj unsigned int qualifiers;
4032a9fa9459Szrj debug_type context;
4033a9fa9459Szrj
4034a9fa9459Szrj orig = *pp;
4035a9fa9459Szrj
4036a9fa9459Szrj switch ((*pp)[1])
4037a9fa9459Szrj {
4038a9fa9459Szrj case '_':
4039a9fa9459Szrj /* GNU mangled name with more than 9 classes. The count is
4040a9fa9459Szrj preceded by an underscore (to distinguish it from the <= 9
4041a9fa9459Szrj case) and followed by an underscore. */
4042a9fa9459Szrj p = *pp + 2;
4043a9fa9459Szrj if (! ISDIGIT (*p) || *p == '0')
4044a9fa9459Szrj {
4045a9fa9459Szrj stab_bad_demangle (orig);
4046a9fa9459Szrj return FALSE;
4047a9fa9459Szrj }
4048a9fa9459Szrj qualifiers = atoi (p);
4049a9fa9459Szrj while (ISDIGIT (*p))
4050a9fa9459Szrj ++p;
4051a9fa9459Szrj if (*p != '_')
4052a9fa9459Szrj {
4053a9fa9459Szrj stab_bad_demangle (orig);
4054a9fa9459Szrj return FALSE;
4055a9fa9459Szrj }
4056a9fa9459Szrj *pp = p + 1;
4057a9fa9459Szrj break;
4058a9fa9459Szrj
4059a9fa9459Szrj case '1': case '2': case '3': case '4': case '5':
4060a9fa9459Szrj case '6': case '7': case '8': case '9':
4061a9fa9459Szrj qualifiers = (*pp)[1] - '0';
4062a9fa9459Szrj /* Skip an optional underscore after the count. */
4063a9fa9459Szrj if ((*pp)[2] == '_')
4064a9fa9459Szrj ++*pp;
4065a9fa9459Szrj *pp += 2;
4066a9fa9459Szrj break;
4067a9fa9459Szrj
4068a9fa9459Szrj case '0':
4069a9fa9459Szrj default:
4070a9fa9459Szrj stab_bad_demangle (orig);
4071a9fa9459Szrj return FALSE;
4072a9fa9459Szrj }
4073a9fa9459Szrj
4074a9fa9459Szrj context = DEBUG_TYPE_NULL;
4075a9fa9459Szrj
4076a9fa9459Szrj /* Pick off the names. */
4077a9fa9459Szrj while (qualifiers-- > 0)
4078a9fa9459Szrj {
4079a9fa9459Szrj if (**pp == '_')
4080a9fa9459Szrj ++*pp;
4081a9fa9459Szrj if (**pp == 't')
4082a9fa9459Szrj {
4083a9fa9459Szrj char *name;
4084a9fa9459Szrj
4085a9fa9459Szrj if (! stab_demangle_template (minfo, pp,
4086a9fa9459Szrj ptype != NULL ? &name : NULL))
4087a9fa9459Szrj return FALSE;
4088a9fa9459Szrj
4089a9fa9459Szrj if (ptype != NULL)
4090a9fa9459Szrj {
4091a9fa9459Szrj context = stab_find_tagged_type (minfo->dhandle, minfo->info,
4092a9fa9459Szrj name, strlen (name),
4093a9fa9459Szrj DEBUG_KIND_CLASS);
4094a9fa9459Szrj free (name);
4095a9fa9459Szrj if (context == DEBUG_TYPE_NULL)
4096a9fa9459Szrj return FALSE;
4097a9fa9459Szrj }
4098a9fa9459Szrj }
4099a9fa9459Szrj else
4100a9fa9459Szrj {
4101a9fa9459Szrj unsigned int len;
4102a9fa9459Szrj
4103a9fa9459Szrj len = stab_demangle_count (pp);
4104a9fa9459Szrj if (strlen (*pp) < len)
4105a9fa9459Szrj {
4106a9fa9459Szrj stab_bad_demangle (orig);
4107a9fa9459Szrj return FALSE;
4108a9fa9459Szrj }
4109a9fa9459Szrj
4110a9fa9459Szrj if (ptype != NULL)
4111a9fa9459Szrj {
4112a9fa9459Szrj const debug_field *fields;
4113a9fa9459Szrj
4114a9fa9459Szrj fields = NULL;
4115a9fa9459Szrj if (context != DEBUG_TYPE_NULL)
4116a9fa9459Szrj fields = debug_get_fields (minfo->dhandle, context);
4117a9fa9459Szrj
4118a9fa9459Szrj context = DEBUG_TYPE_NULL;
4119a9fa9459Szrj
4120a9fa9459Szrj if (fields != NULL)
4121a9fa9459Szrj {
4122a9fa9459Szrj char *name;
4123a9fa9459Szrj
4124a9fa9459Szrj /* Try to find the type by looking through the
4125a9fa9459Szrj fields of context until we find a field with the
4126a9fa9459Szrj same type. This ought to work for a class
4127a9fa9459Szrj defined within a class, but it won't work for,
4128a9fa9459Szrj e.g., an enum defined within a class. stabs does
4129a9fa9459Szrj not give us enough information to figure out the
4130a9fa9459Szrj latter case. */
4131a9fa9459Szrj
4132a9fa9459Szrj name = savestring (*pp, len);
4133a9fa9459Szrj
4134a9fa9459Szrj for (; *fields != DEBUG_FIELD_NULL; fields++)
4135a9fa9459Szrj {
4136a9fa9459Szrj debug_type ft;
4137a9fa9459Szrj const char *dn;
4138a9fa9459Szrj
4139a9fa9459Szrj ft = debug_get_field_type (minfo->dhandle, *fields);
4140a9fa9459Szrj if (ft == NULL)
4141a9fa9459Szrj {
4142a9fa9459Szrj free (name);
4143a9fa9459Szrj return FALSE;
4144a9fa9459Szrj }
4145a9fa9459Szrj dn = debug_get_type_name (minfo->dhandle, ft);
4146a9fa9459Szrj if (dn != NULL && strcmp (dn, name) == 0)
4147a9fa9459Szrj {
4148a9fa9459Szrj context = ft;
4149a9fa9459Szrj break;
4150a9fa9459Szrj }
4151a9fa9459Szrj }
4152a9fa9459Szrj
4153a9fa9459Szrj free (name);
4154a9fa9459Szrj }
4155a9fa9459Szrj
4156a9fa9459Szrj if (context == DEBUG_TYPE_NULL)
4157a9fa9459Szrj {
4158a9fa9459Szrj /* We have to fall back on finding the type by name.
4159a9fa9459Szrj If there are more types to come, then this must
4160a9fa9459Szrj be a class. Otherwise, it could be anything. */
4161a9fa9459Szrj
4162a9fa9459Szrj if (qualifiers == 0)
4163a9fa9459Szrj {
4164a9fa9459Szrj char *name;
4165a9fa9459Szrj
4166a9fa9459Szrj name = savestring (*pp, len);
4167a9fa9459Szrj context = debug_find_named_type (minfo->dhandle,
4168a9fa9459Szrj name);
4169a9fa9459Szrj free (name);
4170a9fa9459Szrj }
4171a9fa9459Szrj
4172a9fa9459Szrj if (context == DEBUG_TYPE_NULL)
4173a9fa9459Szrj {
4174a9fa9459Szrj context = stab_find_tagged_type (minfo->dhandle,
4175a9fa9459Szrj minfo->info,
4176a9fa9459Szrj *pp, len,
4177a9fa9459Szrj (qualifiers == 0
4178a9fa9459Szrj ? DEBUG_KIND_ILLEGAL
4179a9fa9459Szrj : DEBUG_KIND_CLASS));
4180a9fa9459Szrj if (context == DEBUG_TYPE_NULL)
4181a9fa9459Szrj return FALSE;
4182a9fa9459Szrj }
4183a9fa9459Szrj }
4184a9fa9459Szrj }
4185a9fa9459Szrj
4186a9fa9459Szrj *pp += len;
4187a9fa9459Szrj }
4188a9fa9459Szrj }
4189a9fa9459Szrj
4190a9fa9459Szrj if (ptype != NULL)
4191a9fa9459Szrj *ptype = context;
4192a9fa9459Szrj
4193a9fa9459Szrj return TRUE;
4194a9fa9459Szrj }
4195a9fa9459Szrj
4196a9fa9459Szrj /* Demangle a template. If PNAME is not NULL, this sets *PNAME to a
4197a9fa9459Szrj string representation of the template. */
4198a9fa9459Szrj
4199a9fa9459Szrj static bfd_boolean
stab_demangle_template(struct stab_demangle_info * minfo,const char ** pp,char ** pname)4200a9fa9459Szrj stab_demangle_template (struct stab_demangle_info *minfo, const char **pp,
4201a9fa9459Szrj char **pname)
4202a9fa9459Szrj {
4203a9fa9459Szrj const char *orig;
4204a9fa9459Szrj unsigned int r, i;
4205a9fa9459Szrj
4206a9fa9459Szrj orig = *pp;
4207a9fa9459Szrj
4208a9fa9459Szrj ++*pp;
4209a9fa9459Szrj
4210a9fa9459Szrj /* Skip the template name. */
4211a9fa9459Szrj r = stab_demangle_count (pp);
4212a9fa9459Szrj if (r == 0 || strlen (*pp) < r)
4213a9fa9459Szrj {
4214a9fa9459Szrj stab_bad_demangle (orig);
4215a9fa9459Szrj return FALSE;
4216a9fa9459Szrj }
4217a9fa9459Szrj *pp += r;
4218a9fa9459Szrj
4219a9fa9459Szrj /* Get the size of the parameter list. */
4220a9fa9459Szrj if (stab_demangle_get_count (pp, &r) == 0)
4221a9fa9459Szrj {
4222a9fa9459Szrj stab_bad_demangle (orig);
4223a9fa9459Szrj return FALSE;
4224a9fa9459Szrj }
4225a9fa9459Szrj
4226a9fa9459Szrj for (i = 0; i < r; i++)
4227a9fa9459Szrj {
4228a9fa9459Szrj if (**pp == 'Z')
4229a9fa9459Szrj {
4230a9fa9459Szrj /* This is a type parameter. */
4231a9fa9459Szrj ++*pp;
4232a9fa9459Szrj if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
4233a9fa9459Szrj return FALSE;
4234a9fa9459Szrj }
4235a9fa9459Szrj else
4236a9fa9459Szrj {
4237a9fa9459Szrj const char *old_p;
4238a9fa9459Szrj bfd_boolean pointerp, realp, integralp, charp, boolp;
4239a9fa9459Szrj bfd_boolean done;
4240a9fa9459Szrj
4241a9fa9459Szrj old_p = *pp;
4242a9fa9459Szrj pointerp = FALSE;
4243a9fa9459Szrj realp = FALSE;
4244a9fa9459Szrj integralp = FALSE;
4245a9fa9459Szrj charp = FALSE;
4246a9fa9459Szrj boolp = FALSE;
4247a9fa9459Szrj done = FALSE;
4248a9fa9459Szrj
4249a9fa9459Szrj /* This is a value parameter. */
4250a9fa9459Szrj
4251a9fa9459Szrj if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
4252a9fa9459Szrj return FALSE;
4253a9fa9459Szrj
4254a9fa9459Szrj while (*old_p != '\0' && ! done)
4255a9fa9459Szrj {
4256a9fa9459Szrj switch (*old_p)
4257a9fa9459Szrj {
4258a9fa9459Szrj case 'P':
4259a9fa9459Szrj case 'p':
4260a9fa9459Szrj case 'R':
4261a9fa9459Szrj pointerp = TRUE;
4262a9fa9459Szrj done = TRUE;
4263a9fa9459Szrj break;
4264a9fa9459Szrj case 'C': /* Const. */
4265a9fa9459Szrj case 'S': /* Signed. */
4266a9fa9459Szrj case 'U': /* Unsigned. */
4267a9fa9459Szrj case 'V': /* Volatile. */
4268a9fa9459Szrj case 'F': /* Function. */
4269a9fa9459Szrj case 'M': /* Member function. */
4270a9fa9459Szrj case 'O': /* ??? */
4271a9fa9459Szrj ++old_p;
4272a9fa9459Szrj break;
4273a9fa9459Szrj case 'Q': /* Qualified name. */
4274a9fa9459Szrj integralp = TRUE;
4275a9fa9459Szrj done = TRUE;
4276a9fa9459Szrj break;
4277a9fa9459Szrj case 'T': /* Remembered type. */
4278a9fa9459Szrj abort ();
4279a9fa9459Szrj case 'v': /* Void. */
4280a9fa9459Szrj abort ();
4281a9fa9459Szrj case 'x': /* Long long. */
4282a9fa9459Szrj case 'l': /* Long. */
4283a9fa9459Szrj case 'i': /* Int. */
4284a9fa9459Szrj case 's': /* Short. */
4285a9fa9459Szrj case 'w': /* Wchar_t. */
4286a9fa9459Szrj integralp = TRUE;
4287a9fa9459Szrj done = TRUE;
4288a9fa9459Szrj break;
4289a9fa9459Szrj case 'b': /* Bool. */
4290a9fa9459Szrj boolp = TRUE;
4291a9fa9459Szrj done = TRUE;
4292a9fa9459Szrj break;
4293a9fa9459Szrj case 'c': /* Char. */
4294a9fa9459Szrj charp = TRUE;
4295a9fa9459Szrj done = TRUE;
4296a9fa9459Szrj break;
4297a9fa9459Szrj case 'r': /* Long double. */
4298a9fa9459Szrj case 'd': /* Double. */
4299a9fa9459Szrj case 'f': /* Float. */
4300a9fa9459Szrj realp = TRUE;
4301a9fa9459Szrj done = TRUE;
4302a9fa9459Szrj break;
4303a9fa9459Szrj default:
4304a9fa9459Szrj /* Assume it's a user defined integral type. */
4305a9fa9459Szrj integralp = TRUE;
4306a9fa9459Szrj done = TRUE;
4307a9fa9459Szrj break;
4308a9fa9459Szrj }
4309a9fa9459Szrj }
4310a9fa9459Szrj
4311a9fa9459Szrj if (integralp)
4312a9fa9459Szrj {
4313a9fa9459Szrj if (**pp == 'm')
4314a9fa9459Szrj ++*pp;
4315a9fa9459Szrj while (ISDIGIT (**pp))
4316a9fa9459Szrj ++*pp;
4317a9fa9459Szrj }
4318a9fa9459Szrj else if (charp)
4319a9fa9459Szrj {
4320a9fa9459Szrj unsigned int val;
4321a9fa9459Szrj
4322a9fa9459Szrj if (**pp == 'm')
4323a9fa9459Szrj ++*pp;
4324a9fa9459Szrj val = stab_demangle_count (pp);
4325a9fa9459Szrj if (val == 0)
4326a9fa9459Szrj {
4327a9fa9459Szrj stab_bad_demangle (orig);
4328a9fa9459Szrj return FALSE;
4329a9fa9459Szrj }
4330a9fa9459Szrj }
4331a9fa9459Szrj else if (boolp)
4332a9fa9459Szrj {
4333a9fa9459Szrj unsigned int val;
4334a9fa9459Szrj
4335a9fa9459Szrj val = stab_demangle_count (pp);
4336a9fa9459Szrj if (val != 0 && val != 1)
4337a9fa9459Szrj {
4338a9fa9459Szrj stab_bad_demangle (orig);
4339a9fa9459Szrj return FALSE;
4340a9fa9459Szrj }
4341a9fa9459Szrj }
4342a9fa9459Szrj else if (realp)
4343a9fa9459Szrj {
4344a9fa9459Szrj if (**pp == 'm')
4345a9fa9459Szrj ++*pp;
4346a9fa9459Szrj while (ISDIGIT (**pp))
4347a9fa9459Szrj ++*pp;
4348a9fa9459Szrj if (**pp == '.')
4349a9fa9459Szrj {
4350a9fa9459Szrj ++*pp;
4351a9fa9459Szrj while (ISDIGIT (**pp))
4352a9fa9459Szrj ++*pp;
4353a9fa9459Szrj }
4354a9fa9459Szrj if (**pp == 'e')
4355a9fa9459Szrj {
4356a9fa9459Szrj ++*pp;
4357a9fa9459Szrj while (ISDIGIT (**pp))
4358a9fa9459Szrj ++*pp;
4359a9fa9459Szrj }
4360a9fa9459Szrj }
4361a9fa9459Szrj else if (pointerp)
4362a9fa9459Szrj {
4363a9fa9459Szrj unsigned int len;
4364a9fa9459Szrj
4365a9fa9459Szrj len = stab_demangle_count (pp);
4366a9fa9459Szrj if (len == 0)
4367a9fa9459Szrj {
4368a9fa9459Szrj stab_bad_demangle (orig);
4369a9fa9459Szrj return FALSE;
4370a9fa9459Szrj }
4371a9fa9459Szrj *pp += len;
4372a9fa9459Szrj }
4373a9fa9459Szrj }
4374a9fa9459Szrj }
4375a9fa9459Szrj
4376a9fa9459Szrj /* We can translate this to a string fairly easily by invoking the
4377a9fa9459Szrj regular demangling routine. */
4378a9fa9459Szrj if (pname != NULL)
4379a9fa9459Szrj {
4380a9fa9459Szrj char *s1, *s2, *s3, *s4 = NULL;
4381a9fa9459Szrj char *from, *to;
4382a9fa9459Szrj
4383a9fa9459Szrj s1 = savestring (orig, *pp - orig);
4384a9fa9459Szrj
4385a9fa9459Szrj s2 = concat ("NoSuchStrinG__", s1, (const char *) NULL);
4386a9fa9459Szrj
4387a9fa9459Szrj free (s1);
4388a9fa9459Szrj
4389a9fa9459Szrj s3 = cplus_demangle (s2, DMGL_ANSI);
4390a9fa9459Szrj
4391a9fa9459Szrj free (s2);
4392a9fa9459Szrj
4393a9fa9459Szrj if (s3 != NULL)
4394a9fa9459Szrj s4 = strstr (s3, "::NoSuchStrinG");
4395a9fa9459Szrj if (s3 == NULL || s4 == NULL)
4396a9fa9459Szrj {
4397a9fa9459Szrj stab_bad_demangle (orig);
4398a9fa9459Szrj if (s3 != NULL)
4399a9fa9459Szrj free (s3);
4400a9fa9459Szrj return FALSE;
4401a9fa9459Szrj }
4402a9fa9459Szrj
4403a9fa9459Szrj /* Eliminating all spaces, except those between > characters,
4404a9fa9459Szrj makes it more likely that the demangled name will match the
4405a9fa9459Szrj name which g++ used as the structure name. */
4406a9fa9459Szrj for (from = to = s3; from != s4; ++from)
4407a9fa9459Szrj if (*from != ' '
4408a9fa9459Szrj || (from[1] == '>' && from > s3 && from[-1] == '>'))
4409a9fa9459Szrj *to++ = *from;
4410a9fa9459Szrj
4411a9fa9459Szrj *pname = savestring (s3, to - s3);
4412a9fa9459Szrj
4413a9fa9459Szrj free (s3);
4414a9fa9459Szrj }
4415a9fa9459Szrj
4416a9fa9459Szrj return TRUE;
4417a9fa9459Szrj }
4418a9fa9459Szrj
4419a9fa9459Szrj /* Demangle a class name. */
4420a9fa9459Szrj
4421a9fa9459Szrj static bfd_boolean
stab_demangle_class(struct stab_demangle_info * minfo ATTRIBUTE_UNUSED,const char ** pp,const char ** pstart)4422a9fa9459Szrj stab_demangle_class (struct stab_demangle_info *minfo ATTRIBUTE_UNUSED,
4423a9fa9459Szrj const char **pp, const char **pstart)
4424a9fa9459Szrj {
4425a9fa9459Szrj const char *orig;
4426a9fa9459Szrj unsigned int n;
4427a9fa9459Szrj
4428a9fa9459Szrj orig = *pp;
4429a9fa9459Szrj
4430a9fa9459Szrj n = stab_demangle_count (pp);
4431a9fa9459Szrj if (strlen (*pp) < n)
4432a9fa9459Szrj {
4433a9fa9459Szrj stab_bad_demangle (orig);
4434a9fa9459Szrj return FALSE;
4435a9fa9459Szrj }
4436a9fa9459Szrj
4437a9fa9459Szrj if (pstart != NULL)
4438a9fa9459Szrj *pstart = *pp;
4439a9fa9459Szrj
4440a9fa9459Szrj *pp += n;
4441a9fa9459Szrj
4442a9fa9459Szrj return TRUE;
4443a9fa9459Szrj }
4444a9fa9459Szrj
4445a9fa9459Szrj /* Demangle function arguments. If the pargs argument is not NULL, it
4446a9fa9459Szrj is set to a NULL terminated array holding the arguments. */
4447a9fa9459Szrj
4448a9fa9459Szrj static bfd_boolean
stab_demangle_args(struct stab_demangle_info * minfo,const char ** pp,debug_type ** pargs,bfd_boolean * pvarargs)4449a9fa9459Szrj stab_demangle_args (struct stab_demangle_info *minfo, const char **pp,
4450a9fa9459Szrj debug_type **pargs, bfd_boolean *pvarargs)
4451a9fa9459Szrj {
4452a9fa9459Szrj const char *orig;
4453a9fa9459Szrj unsigned int alloc, count;
4454a9fa9459Szrj
4455a9fa9459Szrj orig = *pp;
4456a9fa9459Szrj
4457a9fa9459Szrj alloc = 10;
4458a9fa9459Szrj if (pargs != NULL)
4459a9fa9459Szrj {
4460a9fa9459Szrj *pargs = (debug_type *) xmalloc (alloc * sizeof **pargs);
4461a9fa9459Szrj *pvarargs = FALSE;
4462a9fa9459Szrj }
4463a9fa9459Szrj count = 0;
4464a9fa9459Szrj
4465a9fa9459Szrj while (**pp != '_' && **pp != '\0' && **pp != 'e')
4466a9fa9459Szrj {
4467a9fa9459Szrj if (**pp == 'N' || **pp == 'T')
4468a9fa9459Szrj {
4469a9fa9459Szrj char temptype;
4470a9fa9459Szrj unsigned int r, t;
4471a9fa9459Szrj
4472a9fa9459Szrj temptype = **pp;
4473a9fa9459Szrj ++*pp;
4474a9fa9459Szrj
4475a9fa9459Szrj if (temptype == 'T')
4476a9fa9459Szrj r = 1;
4477a9fa9459Szrj else
4478a9fa9459Szrj {
4479a9fa9459Szrj if (! stab_demangle_get_count (pp, &r))
4480a9fa9459Szrj {
4481a9fa9459Szrj stab_bad_demangle (orig);
4482a9fa9459Szrj return FALSE;
4483a9fa9459Szrj }
4484a9fa9459Szrj }
4485a9fa9459Szrj
4486a9fa9459Szrj if (! stab_demangle_get_count (pp, &t))
4487a9fa9459Szrj {
4488a9fa9459Szrj stab_bad_demangle (orig);
4489a9fa9459Szrj return FALSE;
4490a9fa9459Szrj }
4491a9fa9459Szrj
4492a9fa9459Szrj if (t >= minfo->typestring_count)
4493a9fa9459Szrj {
4494a9fa9459Szrj stab_bad_demangle (orig);
4495a9fa9459Szrj return FALSE;
4496a9fa9459Szrj }
4497a9fa9459Szrj while (r-- > 0)
4498a9fa9459Szrj {
4499a9fa9459Szrj const char *tem;
4500a9fa9459Szrj
4501a9fa9459Szrj tem = minfo->typestrings[t].typestring;
4502a9fa9459Szrj if (! stab_demangle_arg (minfo, &tem, pargs, &count, &alloc))
4503a9fa9459Szrj return FALSE;
4504a9fa9459Szrj }
4505a9fa9459Szrj }
4506a9fa9459Szrj else
4507a9fa9459Szrj {
4508a9fa9459Szrj if (! stab_demangle_arg (minfo, pp, pargs, &count, &alloc))
4509a9fa9459Szrj return FALSE;
4510a9fa9459Szrj }
4511a9fa9459Szrj }
4512a9fa9459Szrj
4513a9fa9459Szrj if (pargs != NULL)
4514a9fa9459Szrj (*pargs)[count] = DEBUG_TYPE_NULL;
4515a9fa9459Szrj
4516a9fa9459Szrj if (**pp == 'e')
4517a9fa9459Szrj {
4518a9fa9459Szrj if (pargs != NULL)
4519a9fa9459Szrj *pvarargs = TRUE;
4520a9fa9459Szrj ++*pp;
4521a9fa9459Szrj }
4522a9fa9459Szrj
4523a9fa9459Szrj return TRUE;
4524a9fa9459Szrj }
4525a9fa9459Szrj
4526a9fa9459Szrj /* Demangle a single argument. */
4527a9fa9459Szrj
4528a9fa9459Szrj static bfd_boolean
stab_demangle_arg(struct stab_demangle_info * minfo,const char ** pp,debug_type ** pargs,unsigned int * pcount,unsigned int * palloc)4529a9fa9459Szrj stab_demangle_arg (struct stab_demangle_info *minfo, const char **pp,
4530a9fa9459Szrj debug_type **pargs, unsigned int *pcount,
4531a9fa9459Szrj unsigned int *palloc)
4532a9fa9459Szrj {
4533a9fa9459Szrj const char *start;
4534a9fa9459Szrj debug_type type;
4535a9fa9459Szrj
4536a9fa9459Szrj start = *pp;
4537a9fa9459Szrj if (! stab_demangle_type (minfo, pp,
4538a9fa9459Szrj pargs == NULL ? (debug_type *) NULL : &type)
4539a9fa9459Szrj || ! stab_demangle_remember_type (minfo, start, *pp - start))
4540a9fa9459Szrj return FALSE;
4541a9fa9459Szrj
4542a9fa9459Szrj if (pargs != NULL)
4543a9fa9459Szrj {
4544a9fa9459Szrj if (type == DEBUG_TYPE_NULL)
4545a9fa9459Szrj return FALSE;
4546a9fa9459Szrj
4547a9fa9459Szrj if (*pcount + 1 >= *palloc)
4548a9fa9459Szrj {
4549a9fa9459Szrj *palloc += 10;
4550a9fa9459Szrj *pargs = ((debug_type *)
4551a9fa9459Szrj xrealloc (*pargs, *palloc * sizeof **pargs));
4552a9fa9459Szrj }
4553a9fa9459Szrj (*pargs)[*pcount] = type;
4554a9fa9459Szrj ++*pcount;
4555a9fa9459Szrj }
4556a9fa9459Szrj
4557a9fa9459Szrj return TRUE;
4558a9fa9459Szrj }
4559a9fa9459Szrj
4560a9fa9459Szrj /* Demangle a type. If the ptype argument is not NULL, *ptype is set
4561a9fa9459Szrj to the newly allocated type. */
4562a9fa9459Szrj
4563a9fa9459Szrj static bfd_boolean
stab_demangle_type(struct stab_demangle_info * minfo,const char ** pp,debug_type * ptype)4564a9fa9459Szrj stab_demangle_type (struct stab_demangle_info *minfo, const char **pp,
4565a9fa9459Szrj debug_type *ptype)
4566a9fa9459Szrj {
4567a9fa9459Szrj const char *orig;
4568a9fa9459Szrj
4569a9fa9459Szrj orig = *pp;
4570a9fa9459Szrj
4571a9fa9459Szrj switch (**pp)
4572a9fa9459Szrj {
4573a9fa9459Szrj case 'P':
4574a9fa9459Szrj case 'p':
4575a9fa9459Szrj /* A pointer type. */
4576a9fa9459Szrj ++*pp;
4577a9fa9459Szrj if (! stab_demangle_type (minfo, pp, ptype))
4578a9fa9459Szrj return FALSE;
4579a9fa9459Szrj if (ptype != NULL)
4580a9fa9459Szrj *ptype = debug_make_pointer_type (minfo->dhandle, *ptype);
4581a9fa9459Szrj break;
4582a9fa9459Szrj
4583a9fa9459Szrj case 'R':
4584a9fa9459Szrj /* A reference type. */
4585a9fa9459Szrj ++*pp;
4586a9fa9459Szrj if (! stab_demangle_type (minfo, pp, ptype))
4587a9fa9459Szrj return FALSE;
4588a9fa9459Szrj if (ptype != NULL)
4589a9fa9459Szrj *ptype = debug_make_reference_type (minfo->dhandle, *ptype);
4590a9fa9459Szrj break;
4591a9fa9459Szrj
4592a9fa9459Szrj case 'A':
4593a9fa9459Szrj /* An array. */
4594a9fa9459Szrj {
4595a9fa9459Szrj unsigned long high;
4596a9fa9459Szrj
4597a9fa9459Szrj ++*pp;
4598a9fa9459Szrj high = 0;
4599a9fa9459Szrj while (**pp != '\0' && **pp != '_')
4600a9fa9459Szrj {
4601a9fa9459Szrj if (! ISDIGIT (**pp))
4602a9fa9459Szrj {
4603a9fa9459Szrj stab_bad_demangle (orig);
4604a9fa9459Szrj return FALSE;
4605a9fa9459Szrj }
4606a9fa9459Szrj high *= 10;
4607a9fa9459Szrj high += **pp - '0';
4608a9fa9459Szrj ++*pp;
4609a9fa9459Szrj }
4610a9fa9459Szrj if (**pp != '_')
4611a9fa9459Szrj {
4612a9fa9459Szrj stab_bad_demangle (orig);
4613a9fa9459Szrj return FALSE;
4614a9fa9459Szrj }
4615a9fa9459Szrj ++*pp;
4616a9fa9459Szrj
4617a9fa9459Szrj if (! stab_demangle_type (minfo, pp, ptype))
4618a9fa9459Szrj return FALSE;
4619a9fa9459Szrj if (ptype != NULL)
4620a9fa9459Szrj {
4621a9fa9459Szrj debug_type int_type;
4622a9fa9459Szrj
4623a9fa9459Szrj int_type = debug_find_named_type (minfo->dhandle, "int");
4624a9fa9459Szrj if (int_type == NULL)
4625a9fa9459Szrj int_type = debug_make_int_type (minfo->dhandle, 4, FALSE);
4626a9fa9459Szrj *ptype = debug_make_array_type (minfo->dhandle, *ptype, int_type,
4627a9fa9459Szrj 0, high, FALSE);
4628a9fa9459Szrj }
4629a9fa9459Szrj }
4630a9fa9459Szrj break;
4631a9fa9459Szrj
4632a9fa9459Szrj case 'T':
4633a9fa9459Szrj /* A back reference to a remembered type. */
4634a9fa9459Szrj {
4635a9fa9459Szrj unsigned int i;
4636a9fa9459Szrj const char *p;
4637a9fa9459Szrj
4638a9fa9459Szrj ++*pp;
4639a9fa9459Szrj if (! stab_demangle_get_count (pp, &i))
4640a9fa9459Szrj {
4641a9fa9459Szrj stab_bad_demangle (orig);
4642a9fa9459Szrj return FALSE;
4643a9fa9459Szrj }
4644a9fa9459Szrj if (i >= minfo->typestring_count)
4645a9fa9459Szrj {
4646a9fa9459Szrj stab_bad_demangle (orig);
4647a9fa9459Szrj return FALSE;
4648a9fa9459Szrj }
4649a9fa9459Szrj p = minfo->typestrings[i].typestring;
4650a9fa9459Szrj if (! stab_demangle_type (minfo, &p, ptype))
4651a9fa9459Szrj return FALSE;
4652a9fa9459Szrj }
4653a9fa9459Szrj break;
4654a9fa9459Szrj
4655a9fa9459Szrj case 'F':
4656a9fa9459Szrj /* A function. */
4657a9fa9459Szrj {
4658a9fa9459Szrj debug_type *args;
4659a9fa9459Szrj bfd_boolean varargs;
4660a9fa9459Szrj
4661a9fa9459Szrj ++*pp;
4662a9fa9459Szrj if (! stab_demangle_args (minfo, pp,
4663a9fa9459Szrj (ptype == NULL
4664a9fa9459Szrj ? (debug_type **) NULL
4665a9fa9459Szrj : &args),
4666a9fa9459Szrj (ptype == NULL
4667a9fa9459Szrj ? (bfd_boolean *) NULL
4668a9fa9459Szrj : &varargs)))
4669a9fa9459Szrj return FALSE;
4670a9fa9459Szrj if (**pp != '_')
4671a9fa9459Szrj {
4672a9fa9459Szrj /* cplus_demangle will accept a function without a return
4673a9fa9459Szrj type, but I don't know when that will happen, or what
4674a9fa9459Szrj to do if it does. */
4675a9fa9459Szrj stab_bad_demangle (orig);
4676a9fa9459Szrj return FALSE;
4677a9fa9459Szrj }
4678a9fa9459Szrj ++*pp;
4679a9fa9459Szrj if (! stab_demangle_type (minfo, pp, ptype))
4680a9fa9459Szrj return FALSE;
4681a9fa9459Szrj if (ptype != NULL)
4682a9fa9459Szrj *ptype = debug_make_function_type (minfo->dhandle, *ptype, args,
4683a9fa9459Szrj varargs);
4684a9fa9459Szrj
4685a9fa9459Szrj }
4686a9fa9459Szrj break;
4687a9fa9459Szrj
4688a9fa9459Szrj case 'M':
4689a9fa9459Szrj case 'O':
4690a9fa9459Szrj {
4691a9fa9459Szrj bfd_boolean memberp;
4692a9fa9459Szrj debug_type class_type = DEBUG_TYPE_NULL;
4693a9fa9459Szrj debug_type *args;
4694a9fa9459Szrj bfd_boolean varargs;
4695a9fa9459Szrj unsigned int n;
4696a9fa9459Szrj const char *name;
4697a9fa9459Szrj
4698a9fa9459Szrj memberp = **pp == 'M';
4699a9fa9459Szrj args = NULL;
4700a9fa9459Szrj varargs = FALSE;
4701a9fa9459Szrj
4702a9fa9459Szrj ++*pp;
4703a9fa9459Szrj if (ISDIGIT (**pp))
4704a9fa9459Szrj {
4705a9fa9459Szrj n = stab_demangle_count (pp);
4706a9fa9459Szrj if (strlen (*pp) < n)
4707a9fa9459Szrj {
4708a9fa9459Szrj stab_bad_demangle (orig);
4709a9fa9459Szrj return FALSE;
4710a9fa9459Szrj }
4711a9fa9459Szrj name = *pp;
4712a9fa9459Szrj *pp += n;
4713a9fa9459Szrj
4714a9fa9459Szrj if (ptype != NULL)
4715a9fa9459Szrj {
4716a9fa9459Szrj class_type = stab_find_tagged_type (minfo->dhandle,
4717a9fa9459Szrj minfo->info,
4718a9fa9459Szrj name, (int) n,
4719a9fa9459Szrj DEBUG_KIND_CLASS);
4720a9fa9459Szrj if (class_type == DEBUG_TYPE_NULL)
4721a9fa9459Szrj return FALSE;
4722a9fa9459Szrj }
4723a9fa9459Szrj }
4724a9fa9459Szrj else if (**pp == 'Q')
4725a9fa9459Szrj {
4726a9fa9459Szrj if (! stab_demangle_qualified (minfo, pp,
4727a9fa9459Szrj (ptype == NULL
4728a9fa9459Szrj ? (debug_type *) NULL
4729a9fa9459Szrj : &class_type)))
4730a9fa9459Szrj return FALSE;
4731a9fa9459Szrj }
4732a9fa9459Szrj else
4733a9fa9459Szrj {
4734a9fa9459Szrj stab_bad_demangle (orig);
4735a9fa9459Szrj return FALSE;
4736a9fa9459Szrj }
4737a9fa9459Szrj
4738a9fa9459Szrj if (memberp)
4739a9fa9459Szrj {
4740a9fa9459Szrj if (**pp == 'C')
4741a9fa9459Szrj {
4742a9fa9459Szrj ++*pp;
4743a9fa9459Szrj }
4744a9fa9459Szrj else if (**pp == 'V')
4745a9fa9459Szrj {
4746a9fa9459Szrj ++*pp;
4747a9fa9459Szrj }
4748a9fa9459Szrj if (**pp != 'F')
4749a9fa9459Szrj {
4750a9fa9459Szrj stab_bad_demangle (orig);
4751a9fa9459Szrj return FALSE;
4752a9fa9459Szrj }
4753a9fa9459Szrj ++*pp;
4754a9fa9459Szrj if (! stab_demangle_args (minfo, pp,
4755a9fa9459Szrj (ptype == NULL
4756a9fa9459Szrj ? (debug_type **) NULL
4757a9fa9459Szrj : &args),
4758a9fa9459Szrj (ptype == NULL
4759a9fa9459Szrj ? (bfd_boolean *) NULL
4760a9fa9459Szrj : &varargs)))
4761a9fa9459Szrj return FALSE;
4762a9fa9459Szrj }
4763a9fa9459Szrj
4764a9fa9459Szrj if (**pp != '_')
4765a9fa9459Szrj {
4766a9fa9459Szrj stab_bad_demangle (orig);
4767a9fa9459Szrj return FALSE;
4768a9fa9459Szrj }
4769a9fa9459Szrj ++*pp;
4770a9fa9459Szrj
4771a9fa9459Szrj if (! stab_demangle_type (minfo, pp, ptype))
4772a9fa9459Szrj return FALSE;
4773a9fa9459Szrj
4774a9fa9459Szrj if (ptype != NULL)
4775a9fa9459Szrj {
4776a9fa9459Szrj if (! memberp)
4777a9fa9459Szrj *ptype = debug_make_offset_type (minfo->dhandle, class_type,
4778a9fa9459Szrj *ptype);
4779a9fa9459Szrj else
4780a9fa9459Szrj {
4781a9fa9459Szrj /* FIXME: We have no way to record constp or
4782a9fa9459Szrj volatilep. */
4783a9fa9459Szrj *ptype = debug_make_method_type (minfo->dhandle, *ptype,
4784a9fa9459Szrj class_type, args, varargs);
4785a9fa9459Szrj }
4786a9fa9459Szrj }
4787a9fa9459Szrj }
4788a9fa9459Szrj break;
4789a9fa9459Szrj
4790a9fa9459Szrj case 'G':
4791a9fa9459Szrj ++*pp;
4792a9fa9459Szrj if (! stab_demangle_type (minfo, pp, ptype))
4793a9fa9459Szrj return FALSE;
4794a9fa9459Szrj break;
4795a9fa9459Szrj
4796a9fa9459Szrj case 'C':
4797a9fa9459Szrj ++*pp;
4798a9fa9459Szrj if (! stab_demangle_type (minfo, pp, ptype))
4799a9fa9459Szrj return FALSE;
4800a9fa9459Szrj if (ptype != NULL)
4801a9fa9459Szrj *ptype = debug_make_const_type (minfo->dhandle, *ptype);
4802a9fa9459Szrj break;
4803a9fa9459Szrj
4804a9fa9459Szrj case 'Q':
4805a9fa9459Szrj {
4806a9fa9459Szrj if (! stab_demangle_qualified (minfo, pp, ptype))
4807a9fa9459Szrj return FALSE;
4808a9fa9459Szrj }
4809a9fa9459Szrj break;
4810a9fa9459Szrj
4811a9fa9459Szrj default:
4812a9fa9459Szrj if (! stab_demangle_fund_type (minfo, pp, ptype))
4813a9fa9459Szrj return FALSE;
4814a9fa9459Szrj break;
4815a9fa9459Szrj }
4816a9fa9459Szrj
4817a9fa9459Szrj return TRUE;
4818a9fa9459Szrj }
4819a9fa9459Szrj
4820a9fa9459Szrj /* Demangle a fundamental type. If the ptype argument is not NULL,
4821a9fa9459Szrj *ptype is set to the newly allocated type. */
4822a9fa9459Szrj
4823a9fa9459Szrj static bfd_boolean
stab_demangle_fund_type(struct stab_demangle_info * minfo,const char ** pp,debug_type * ptype)4824a9fa9459Szrj stab_demangle_fund_type (struct stab_demangle_info *minfo, const char **pp,
4825a9fa9459Szrj debug_type *ptype)
4826a9fa9459Szrj {
4827a9fa9459Szrj const char *orig;
4828a9fa9459Szrj bfd_boolean constp, volatilep, unsignedp, signedp;
4829a9fa9459Szrj bfd_boolean done;
4830a9fa9459Szrj
4831a9fa9459Szrj orig = *pp;
4832a9fa9459Szrj
4833a9fa9459Szrj constp = FALSE;
4834a9fa9459Szrj volatilep = FALSE;
4835a9fa9459Szrj unsignedp = FALSE;
4836a9fa9459Szrj signedp = FALSE;
4837a9fa9459Szrj
4838a9fa9459Szrj done = FALSE;
4839a9fa9459Szrj while (! done)
4840a9fa9459Szrj {
4841a9fa9459Szrj switch (**pp)
4842a9fa9459Szrj {
4843a9fa9459Szrj case 'C':
4844a9fa9459Szrj constp = TRUE;
4845a9fa9459Szrj ++*pp;
4846a9fa9459Szrj break;
4847a9fa9459Szrj
4848a9fa9459Szrj case 'U':
4849a9fa9459Szrj unsignedp = TRUE;
4850a9fa9459Szrj ++*pp;
4851a9fa9459Szrj break;
4852a9fa9459Szrj
4853a9fa9459Szrj case 'S':
4854a9fa9459Szrj signedp = TRUE;
4855a9fa9459Szrj ++*pp;
4856a9fa9459Szrj break;
4857a9fa9459Szrj
4858a9fa9459Szrj case 'V':
4859a9fa9459Szrj volatilep = TRUE;
4860a9fa9459Szrj ++*pp;
4861a9fa9459Szrj break;
4862a9fa9459Szrj
4863a9fa9459Szrj default:
4864a9fa9459Szrj done = TRUE;
4865a9fa9459Szrj break;
4866a9fa9459Szrj }
4867a9fa9459Szrj }
4868a9fa9459Szrj
4869a9fa9459Szrj switch (**pp)
4870a9fa9459Szrj {
4871a9fa9459Szrj case '\0':
4872a9fa9459Szrj case '_':
4873a9fa9459Szrj /* cplus_demangle permits this, but I don't know what it means. */
4874a9fa9459Szrj stab_bad_demangle (orig);
4875a9fa9459Szrj break;
4876a9fa9459Szrj
4877a9fa9459Szrj case 'v': /* void */
4878a9fa9459Szrj if (ptype != NULL)
4879a9fa9459Szrj {
4880a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle, "void");
4881a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL)
4882a9fa9459Szrj *ptype = debug_make_void_type (minfo->dhandle);
4883a9fa9459Szrj }
4884a9fa9459Szrj ++*pp;
4885a9fa9459Szrj break;
4886a9fa9459Szrj
4887a9fa9459Szrj case 'x': /* long long */
4888a9fa9459Szrj if (ptype != NULL)
4889a9fa9459Szrj {
4890a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle,
4891a9fa9459Szrj (unsignedp
4892a9fa9459Szrj ? "long long unsigned int"
4893a9fa9459Szrj : "long long int"));
4894a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL)
4895a9fa9459Szrj *ptype = debug_make_int_type (minfo->dhandle, 8, unsignedp);
4896a9fa9459Szrj }
4897a9fa9459Szrj ++*pp;
4898a9fa9459Szrj break;
4899a9fa9459Szrj
4900a9fa9459Szrj case 'l': /* long */
4901a9fa9459Szrj if (ptype != NULL)
4902a9fa9459Szrj {
4903a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle,
4904a9fa9459Szrj (unsignedp
4905a9fa9459Szrj ? "long unsigned int"
4906a9fa9459Szrj : "long int"));
4907a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL)
4908a9fa9459Szrj *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
4909a9fa9459Szrj }
4910a9fa9459Szrj ++*pp;
4911a9fa9459Szrj break;
4912a9fa9459Szrj
4913a9fa9459Szrj case 'i': /* int */
4914a9fa9459Szrj if (ptype != NULL)
4915a9fa9459Szrj {
4916a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle,
4917a9fa9459Szrj (unsignedp
4918a9fa9459Szrj ? "unsigned int"
4919a9fa9459Szrj : "int"));
4920a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL)
4921a9fa9459Szrj *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
4922a9fa9459Szrj }
4923a9fa9459Szrj ++*pp;
4924a9fa9459Szrj break;
4925a9fa9459Szrj
4926a9fa9459Szrj case 's': /* short */
4927a9fa9459Szrj if (ptype != NULL)
4928a9fa9459Szrj {
4929a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle,
4930a9fa9459Szrj (unsignedp
4931a9fa9459Szrj ? "short unsigned int"
4932a9fa9459Szrj : "short int"));
4933a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL)
4934a9fa9459Szrj *ptype = debug_make_int_type (minfo->dhandle, 2, unsignedp);
4935a9fa9459Szrj }
4936a9fa9459Szrj ++*pp;
4937a9fa9459Szrj break;
4938a9fa9459Szrj
4939a9fa9459Szrj case 'b': /* bool */
4940a9fa9459Szrj if (ptype != NULL)
4941a9fa9459Szrj {
4942a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle, "bool");
4943a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL)
4944a9fa9459Szrj *ptype = debug_make_bool_type (minfo->dhandle, 4);
4945a9fa9459Szrj }
4946a9fa9459Szrj ++*pp;
4947a9fa9459Szrj break;
4948a9fa9459Szrj
4949a9fa9459Szrj case 'c': /* char */
4950a9fa9459Szrj if (ptype != NULL)
4951a9fa9459Szrj {
4952a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle,
4953a9fa9459Szrj (unsignedp
4954a9fa9459Szrj ? "unsigned char"
4955a9fa9459Szrj : (signedp
4956a9fa9459Szrj ? "signed char"
4957a9fa9459Szrj : "char")));
4958a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL)
4959a9fa9459Szrj *ptype = debug_make_int_type (minfo->dhandle, 1, unsignedp);
4960a9fa9459Szrj }
4961a9fa9459Szrj ++*pp;
4962a9fa9459Szrj break;
4963a9fa9459Szrj
4964a9fa9459Szrj case 'w': /* wchar_t */
4965a9fa9459Szrj if (ptype != NULL)
4966a9fa9459Szrj {
4967a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle, "__wchar_t");
4968a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL)
4969a9fa9459Szrj *ptype = debug_make_int_type (minfo->dhandle, 2, TRUE);
4970a9fa9459Szrj }
4971a9fa9459Szrj ++*pp;
4972a9fa9459Szrj break;
4973a9fa9459Szrj
4974a9fa9459Szrj case 'r': /* long double */
4975a9fa9459Szrj if (ptype != NULL)
4976a9fa9459Szrj {
4977a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle, "long double");
4978a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL)
4979a9fa9459Szrj *ptype = debug_make_float_type (minfo->dhandle, 8);
4980a9fa9459Szrj }
4981a9fa9459Szrj ++*pp;
4982a9fa9459Szrj break;
4983a9fa9459Szrj
4984a9fa9459Szrj case 'd': /* double */
4985a9fa9459Szrj if (ptype != NULL)
4986a9fa9459Szrj {
4987a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle, "double");
4988a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL)
4989a9fa9459Szrj *ptype = debug_make_float_type (minfo->dhandle, 8);
4990a9fa9459Szrj }
4991a9fa9459Szrj ++*pp;
4992a9fa9459Szrj break;
4993a9fa9459Szrj
4994a9fa9459Szrj case 'f': /* float */
4995a9fa9459Szrj if (ptype != NULL)
4996a9fa9459Szrj {
4997a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle, "float");
4998a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL)
4999a9fa9459Szrj *ptype = debug_make_float_type (minfo->dhandle, 4);
5000a9fa9459Szrj }
5001a9fa9459Szrj ++*pp;
5002a9fa9459Szrj break;
5003a9fa9459Szrj
5004a9fa9459Szrj case 'G':
5005a9fa9459Szrj ++*pp;
5006a9fa9459Szrj if (! ISDIGIT (**pp))
5007a9fa9459Szrj {
5008a9fa9459Szrj stab_bad_demangle (orig);
5009a9fa9459Szrj return FALSE;
5010a9fa9459Szrj }
5011a9fa9459Szrj /* Fall through. */
5012a9fa9459Szrj case '0': case '1': case '2': case '3': case '4':
5013a9fa9459Szrj case '5': case '6': case '7': case '8': case '9':
5014a9fa9459Szrj {
5015a9fa9459Szrj const char *hold;
5016a9fa9459Szrj
5017a9fa9459Szrj if (! stab_demangle_class (minfo, pp, &hold))
5018a9fa9459Szrj return FALSE;
5019a9fa9459Szrj if (ptype != NULL)
5020a9fa9459Szrj {
5021a9fa9459Szrj char *name;
5022a9fa9459Szrj
5023a9fa9459Szrj name = savestring (hold, *pp - hold);
5024a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle, name);
5025a9fa9459Szrj free (name);
5026a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL)
5027a9fa9459Szrj {
5028a9fa9459Szrj /* FIXME: It is probably incorrect to assume that
5029a9fa9459Szrj undefined types are tagged types. */
5030a9fa9459Szrj *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info,
5031a9fa9459Szrj hold, *pp - hold,
5032a9fa9459Szrj DEBUG_KIND_ILLEGAL);
5033a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL)
5034a9fa9459Szrj return FALSE;
5035a9fa9459Szrj }
5036a9fa9459Szrj }
5037a9fa9459Szrj }
5038a9fa9459Szrj break;
5039a9fa9459Szrj
5040a9fa9459Szrj case 't':
5041a9fa9459Szrj {
5042a9fa9459Szrj char *name;
5043a9fa9459Szrj
5044a9fa9459Szrj if (! stab_demangle_template (minfo, pp,
5045a9fa9459Szrj ptype != NULL ? &name : NULL))
5046a9fa9459Szrj return FALSE;
5047a9fa9459Szrj if (ptype != NULL)
5048a9fa9459Szrj {
5049a9fa9459Szrj *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info,
5050a9fa9459Szrj name, strlen (name),
5051a9fa9459Szrj DEBUG_KIND_CLASS);
5052a9fa9459Szrj free (name);
5053a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL)
5054a9fa9459Szrj return FALSE;
5055a9fa9459Szrj }
5056a9fa9459Szrj }
5057a9fa9459Szrj break;
5058a9fa9459Szrj
5059a9fa9459Szrj default:
5060a9fa9459Szrj stab_bad_demangle (orig);
5061a9fa9459Szrj return FALSE;
5062a9fa9459Szrj }
5063a9fa9459Szrj
5064a9fa9459Szrj if (ptype != NULL)
5065a9fa9459Szrj {
5066a9fa9459Szrj if (constp)
5067a9fa9459Szrj *ptype = debug_make_const_type (minfo->dhandle, *ptype);
5068a9fa9459Szrj if (volatilep)
5069a9fa9459Szrj *ptype = debug_make_volatile_type (minfo->dhandle, *ptype);
5070a9fa9459Szrj }
5071a9fa9459Szrj
5072a9fa9459Szrj return TRUE;
5073a9fa9459Szrj }
5074a9fa9459Szrj
5075a9fa9459Szrj /* Remember a type string in a demangled string. */
5076a9fa9459Szrj
5077a9fa9459Szrj static bfd_boolean
stab_demangle_remember_type(struct stab_demangle_info * minfo,const char * p,int len)5078a9fa9459Szrj stab_demangle_remember_type (struct stab_demangle_info *minfo,
5079a9fa9459Szrj const char *p, int len)
5080a9fa9459Szrj {
5081a9fa9459Szrj if (minfo->typestring_count >= minfo->typestring_alloc)
5082a9fa9459Szrj {
5083a9fa9459Szrj minfo->typestring_alloc += 10;
5084a9fa9459Szrj minfo->typestrings = ((struct stab_demangle_typestring *)
5085a9fa9459Szrj xrealloc (minfo->typestrings,
5086a9fa9459Szrj (minfo->typestring_alloc
5087a9fa9459Szrj * sizeof *minfo->typestrings)));
5088a9fa9459Szrj }
5089a9fa9459Szrj
5090a9fa9459Szrj minfo->typestrings[minfo->typestring_count].typestring = p;
5091a9fa9459Szrj minfo->typestrings[minfo->typestring_count].len = (unsigned int) len;
5092a9fa9459Szrj ++minfo->typestring_count;
5093a9fa9459Szrj
5094a9fa9459Szrj return TRUE;
5095a9fa9459Szrj }
5096a9fa9459Szrj
5097a9fa9459Szrj /* Demangle names encoded using the g++ V3 ABI. The newer versions of
5098a9fa9459Szrj g++ which use this ABI do not encode ordinary method argument types
5099a9fa9459Szrj in a mangled name; they simply output the argument types. However,
5100a9fa9459Szrj for a static method, g++ simply outputs the return type and the
5101a9fa9459Szrj physical name. So in that case we need to demangle the name here.
5102a9fa9459Szrj Here PHYSNAME is the physical name of the function, and we set the
5103a9fa9459Szrj variable pointed at by PVARARGS to indicate whether this function
5104a9fa9459Szrj is varargs. This returns NULL, or a NULL terminated array of
5105a9fa9459Szrj argument types. */
5106a9fa9459Szrj
5107a9fa9459Szrj static debug_type *
stab_demangle_v3_argtypes(void * dhandle,struct stab_handle * info,const char * physname,bfd_boolean * pvarargs)5108a9fa9459Szrj stab_demangle_v3_argtypes (void *dhandle, struct stab_handle *info,
5109a9fa9459Szrj const char *physname, bfd_boolean *pvarargs)
5110a9fa9459Szrj {
5111a9fa9459Szrj struct demangle_component *dc;
5112a9fa9459Szrj void *mem;
5113a9fa9459Szrj debug_type *pargs;
5114a9fa9459Szrj
5115a9fa9459Szrj dc = cplus_demangle_v3_components (physname, DMGL_PARAMS | DMGL_ANSI, &mem);
5116a9fa9459Szrj if (dc == NULL)
5117a9fa9459Szrj {
5118a9fa9459Szrj stab_bad_demangle (physname);
5119a9fa9459Szrj return NULL;
5120a9fa9459Szrj }
5121a9fa9459Szrj
5122a9fa9459Szrj /* We expect to see TYPED_NAME, and the right subtree describes the
5123a9fa9459Szrj function type. */
5124a9fa9459Szrj if (dc->type != DEMANGLE_COMPONENT_TYPED_NAME
5125a9fa9459Szrj || dc->u.s_binary.right->type != DEMANGLE_COMPONENT_FUNCTION_TYPE)
5126a9fa9459Szrj {
5127a9fa9459Szrj fprintf (stderr, _("Demangled name is not a function\n"));
5128a9fa9459Szrj free (mem);
5129a9fa9459Szrj return NULL;
5130a9fa9459Szrj }
5131a9fa9459Szrj
5132a9fa9459Szrj pargs = stab_demangle_v3_arglist (dhandle, info,
5133a9fa9459Szrj dc->u.s_binary.right->u.s_binary.right,
5134a9fa9459Szrj pvarargs);
5135a9fa9459Szrj
5136a9fa9459Szrj free (mem);
5137a9fa9459Szrj
5138a9fa9459Szrj return pargs;
5139a9fa9459Szrj }
5140a9fa9459Szrj
5141a9fa9459Szrj /* Demangle an argument list in a struct demangle_component tree.
5142a9fa9459Szrj Returns a DEBUG_TYPE_NULL terminated array of argument types, and
5143a9fa9459Szrj sets *PVARARGS to indicate whether this is a varargs function. */
5144a9fa9459Szrj
5145a9fa9459Szrj static debug_type *
stab_demangle_v3_arglist(void * dhandle,struct stab_handle * info,struct demangle_component * arglist,bfd_boolean * pvarargs)5146a9fa9459Szrj stab_demangle_v3_arglist (void *dhandle, struct stab_handle *info,
5147a9fa9459Szrj struct demangle_component *arglist,
5148a9fa9459Szrj bfd_boolean *pvarargs)
5149a9fa9459Szrj {
5150a9fa9459Szrj struct demangle_component *dc;
5151a9fa9459Szrj unsigned int alloc, count;
5152a9fa9459Szrj debug_type *pargs;
5153a9fa9459Szrj
5154a9fa9459Szrj alloc = 10;
5155a9fa9459Szrj pargs = (debug_type *) xmalloc (alloc * sizeof *pargs);
5156a9fa9459Szrj *pvarargs = FALSE;
5157a9fa9459Szrj
5158a9fa9459Szrj count = 0;
5159a9fa9459Szrj
5160a9fa9459Szrj for (dc = arglist;
5161a9fa9459Szrj dc != NULL;
5162a9fa9459Szrj dc = dc->u.s_binary.right)
5163a9fa9459Szrj {
5164a9fa9459Szrj debug_type arg;
5165a9fa9459Szrj bfd_boolean varargs;
5166a9fa9459Szrj
5167a9fa9459Szrj if (dc->type != DEMANGLE_COMPONENT_ARGLIST)
5168a9fa9459Szrj {
5169a9fa9459Szrj fprintf (stderr, _("Unexpected type in v3 arglist demangling\n"));
5170a9fa9459Szrj free (pargs);
5171a9fa9459Szrj return NULL;
5172a9fa9459Szrj }
5173a9fa9459Szrj
5174a9fa9459Szrj /* PR 13925: Cope if the demangler returns an empty
5175a9fa9459Szrj context for a function with no arguments. */
5176a9fa9459Szrj if (dc->u.s_binary.left == NULL)
5177a9fa9459Szrj break;
5178a9fa9459Szrj
5179a9fa9459Szrj arg = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left,
5180a9fa9459Szrj NULL, &varargs);
5181a9fa9459Szrj if (arg == NULL)
5182a9fa9459Szrj {
5183a9fa9459Szrj if (varargs)
5184a9fa9459Szrj {
5185a9fa9459Szrj *pvarargs = TRUE;
5186a9fa9459Szrj continue;
5187a9fa9459Szrj }
5188a9fa9459Szrj free (pargs);
5189a9fa9459Szrj return NULL;
5190a9fa9459Szrj }
5191a9fa9459Szrj
5192a9fa9459Szrj if (count + 1 >= alloc)
5193a9fa9459Szrj {
5194a9fa9459Szrj alloc += 10;
5195a9fa9459Szrj pargs = (debug_type *) xrealloc (pargs, alloc * sizeof *pargs);
5196a9fa9459Szrj }
5197a9fa9459Szrj
5198a9fa9459Szrj pargs[count] = arg;
5199a9fa9459Szrj ++count;
5200a9fa9459Szrj }
5201a9fa9459Szrj
5202a9fa9459Szrj pargs[count] = DEBUG_TYPE_NULL;
5203a9fa9459Szrj
5204a9fa9459Szrj return pargs;
5205a9fa9459Szrj }
5206a9fa9459Szrj
5207a9fa9459Szrj /* Convert a struct demangle_component tree describing an argument
5208a9fa9459Szrj type into a debug_type. */
5209a9fa9459Szrj
5210a9fa9459Szrj static debug_type
stab_demangle_v3_arg(void * dhandle,struct stab_handle * info,struct demangle_component * dc,debug_type context,bfd_boolean * pvarargs)5211a9fa9459Szrj stab_demangle_v3_arg (void *dhandle, struct stab_handle *info,
5212a9fa9459Szrj struct demangle_component *dc, debug_type context,
5213a9fa9459Szrj bfd_boolean *pvarargs)
5214a9fa9459Szrj {
5215a9fa9459Szrj debug_type dt;
5216a9fa9459Szrj
5217a9fa9459Szrj if (pvarargs != NULL)
5218a9fa9459Szrj *pvarargs = FALSE;
5219a9fa9459Szrj
5220a9fa9459Szrj switch (dc->type)
5221a9fa9459Szrj {
5222a9fa9459Szrj /* FIXME: These are demangle component types which we probably
5223a9fa9459Szrj need to handle one way or another. */
5224a9fa9459Szrj case DEMANGLE_COMPONENT_LOCAL_NAME:
5225a9fa9459Szrj case DEMANGLE_COMPONENT_TYPED_NAME:
5226a9fa9459Szrj case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
5227a9fa9459Szrj case DEMANGLE_COMPONENT_CTOR:
5228a9fa9459Szrj case DEMANGLE_COMPONENT_DTOR:
5229a9fa9459Szrj case DEMANGLE_COMPONENT_JAVA_CLASS:
5230a9fa9459Szrj case DEMANGLE_COMPONENT_RESTRICT_THIS:
5231a9fa9459Szrj case DEMANGLE_COMPONENT_VOLATILE_THIS:
5232a9fa9459Szrj case DEMANGLE_COMPONENT_CONST_THIS:
5233a9fa9459Szrj case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
5234a9fa9459Szrj case DEMANGLE_COMPONENT_COMPLEX:
5235a9fa9459Szrj case DEMANGLE_COMPONENT_IMAGINARY:
5236a9fa9459Szrj case DEMANGLE_COMPONENT_VENDOR_TYPE:
5237a9fa9459Szrj case DEMANGLE_COMPONENT_ARRAY_TYPE:
5238a9fa9459Szrj case DEMANGLE_COMPONENT_PTRMEM_TYPE:
5239a9fa9459Szrj case DEMANGLE_COMPONENT_ARGLIST:
5240a9fa9459Szrj default:
5241a9fa9459Szrj fprintf (stderr, _("Unrecognized demangle component %d\n"),
5242a9fa9459Szrj (int) dc->type);
5243a9fa9459Szrj return NULL;
5244a9fa9459Szrj
5245a9fa9459Szrj case DEMANGLE_COMPONENT_NAME:
5246a9fa9459Szrj if (context != NULL)
5247a9fa9459Szrj {
5248a9fa9459Szrj const debug_field *fields;
5249a9fa9459Szrj
5250a9fa9459Szrj fields = debug_get_fields (dhandle, context);
5251a9fa9459Szrj if (fields != NULL)
5252a9fa9459Szrj {
5253a9fa9459Szrj /* Try to find this type by looking through the context
5254a9fa9459Szrj class. */
5255a9fa9459Szrj for (; *fields != DEBUG_FIELD_NULL; fields++)
5256a9fa9459Szrj {
5257a9fa9459Szrj debug_type ft;
5258a9fa9459Szrj const char *dn;
5259a9fa9459Szrj
5260a9fa9459Szrj ft = debug_get_field_type (dhandle, *fields);
5261a9fa9459Szrj if (ft == NULL)
5262a9fa9459Szrj return NULL;
5263a9fa9459Szrj dn = debug_get_type_name (dhandle, ft);
5264a9fa9459Szrj if (dn != NULL
5265a9fa9459Szrj && (int) strlen (dn) == dc->u.s_name.len
5266a9fa9459Szrj && strncmp (dn, dc->u.s_name.s, dc->u.s_name.len) == 0)
5267a9fa9459Szrj return ft;
5268a9fa9459Szrj }
5269a9fa9459Szrj }
5270a9fa9459Szrj }
5271a9fa9459Szrj return stab_find_tagged_type (dhandle, info, dc->u.s_name.s,
5272a9fa9459Szrj dc->u.s_name.len, DEBUG_KIND_ILLEGAL);
5273a9fa9459Szrj
5274a9fa9459Szrj case DEMANGLE_COMPONENT_QUAL_NAME:
5275a9fa9459Szrj context = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left,
5276a9fa9459Szrj context, NULL);
5277a9fa9459Szrj if (context == NULL)
5278a9fa9459Szrj return NULL;
5279a9fa9459Szrj return stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.right,
5280a9fa9459Szrj context, NULL);
5281a9fa9459Szrj
5282a9fa9459Szrj case DEMANGLE_COMPONENT_TEMPLATE:
5283a9fa9459Szrj {
5284a9fa9459Szrj char *p;
5285a9fa9459Szrj size_t alc;
5286a9fa9459Szrj
5287a9fa9459Szrj /* We print this component to get a class name which we can
5288a9fa9459Szrj use. FIXME: This probably won't work if the template uses
5289a9fa9459Szrj template parameters which refer to an outer template. */
5290a9fa9459Szrj p = cplus_demangle_print (DMGL_PARAMS | DMGL_ANSI, dc, 20, &alc);
5291a9fa9459Szrj if (p == NULL)
5292a9fa9459Szrj {
5293a9fa9459Szrj fprintf (stderr, _("Failed to print demangled template\n"));
5294a9fa9459Szrj return NULL;
5295a9fa9459Szrj }
5296a9fa9459Szrj dt = stab_find_tagged_type (dhandle, info, p, strlen (p),
5297a9fa9459Szrj DEBUG_KIND_CLASS);
5298a9fa9459Szrj free (p);
5299a9fa9459Szrj return dt;
5300a9fa9459Szrj }
5301a9fa9459Szrj
5302a9fa9459Szrj case DEMANGLE_COMPONENT_SUB_STD:
5303a9fa9459Szrj return stab_find_tagged_type (dhandle, info, dc->u.s_string.string,
5304a9fa9459Szrj dc->u.s_string.len, DEBUG_KIND_ILLEGAL);
5305a9fa9459Szrj
5306a9fa9459Szrj case DEMANGLE_COMPONENT_RESTRICT:
5307a9fa9459Szrj case DEMANGLE_COMPONENT_VOLATILE:
5308a9fa9459Szrj case DEMANGLE_COMPONENT_CONST:
5309a9fa9459Szrj case DEMANGLE_COMPONENT_POINTER:
5310a9fa9459Szrj case DEMANGLE_COMPONENT_REFERENCE:
5311a9fa9459Szrj dt = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left, NULL,
5312a9fa9459Szrj NULL);
5313a9fa9459Szrj if (dt == NULL)
5314a9fa9459Szrj return NULL;
5315a9fa9459Szrj
5316a9fa9459Szrj switch (dc->type)
5317a9fa9459Szrj {
5318a9fa9459Szrj default:
5319a9fa9459Szrj abort ();
5320a9fa9459Szrj case DEMANGLE_COMPONENT_RESTRICT:
5321a9fa9459Szrj /* FIXME: We have no way to represent restrict. */
5322a9fa9459Szrj return dt;
5323a9fa9459Szrj case DEMANGLE_COMPONENT_VOLATILE:
5324a9fa9459Szrj return debug_make_volatile_type (dhandle, dt);
5325a9fa9459Szrj case DEMANGLE_COMPONENT_CONST:
5326a9fa9459Szrj return debug_make_const_type (dhandle, dt);
5327a9fa9459Szrj case DEMANGLE_COMPONENT_POINTER:
5328a9fa9459Szrj return debug_make_pointer_type (dhandle, dt);
5329a9fa9459Szrj case DEMANGLE_COMPONENT_REFERENCE:
5330a9fa9459Szrj return debug_make_reference_type (dhandle, dt);
5331a9fa9459Szrj }
5332a9fa9459Szrj
5333a9fa9459Szrj case DEMANGLE_COMPONENT_FUNCTION_TYPE:
5334a9fa9459Szrj {
5335a9fa9459Szrj debug_type *pargs;
5336a9fa9459Szrj bfd_boolean varargs;
5337a9fa9459Szrj
5338a9fa9459Szrj if (dc->u.s_binary.left == NULL)
5339a9fa9459Szrj {
5340a9fa9459Szrj /* In this case the return type is actually unknown.
5341a9fa9459Szrj However, I'm not sure this will ever arise in practice;
5342a9fa9459Szrj normally an unknown return type would only appear at
5343a9fa9459Szrj the top level, which is handled above. */
5344a9fa9459Szrj dt = debug_make_void_type (dhandle);
5345a9fa9459Szrj }
5346a9fa9459Szrj else
5347a9fa9459Szrj dt = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left, NULL,
5348a9fa9459Szrj NULL);
5349a9fa9459Szrj if (dt == NULL)
5350a9fa9459Szrj return NULL;
5351a9fa9459Szrj
5352a9fa9459Szrj pargs = stab_demangle_v3_arglist (dhandle, info,
5353a9fa9459Szrj dc->u.s_binary.right,
5354a9fa9459Szrj &varargs);
5355a9fa9459Szrj if (pargs == NULL)
5356a9fa9459Szrj return NULL;
5357a9fa9459Szrj
5358a9fa9459Szrj return debug_make_function_type (dhandle, dt, pargs, varargs);
5359a9fa9459Szrj }
5360a9fa9459Szrj
5361a9fa9459Szrj case DEMANGLE_COMPONENT_BUILTIN_TYPE:
5362a9fa9459Szrj {
5363a9fa9459Szrj char *p;
5364a9fa9459Szrj size_t alc;
5365a9fa9459Szrj debug_type ret;
5366a9fa9459Szrj
5367a9fa9459Szrj /* We print this component in order to find out the type name.
5368a9fa9459Szrj FIXME: Should we instead expose the
5369a9fa9459Szrj demangle_builtin_type_info structure? */
5370a9fa9459Szrj p = cplus_demangle_print (DMGL_PARAMS | DMGL_ANSI, dc, 20, &alc);
5371a9fa9459Szrj if (p == NULL)
5372a9fa9459Szrj {
5373a9fa9459Szrj fprintf (stderr, _("Couldn't get demangled builtin type\n"));
5374a9fa9459Szrj return NULL;
5375a9fa9459Szrj }
5376a9fa9459Szrj
5377a9fa9459Szrj /* The mangling is based on the type, but does not itself
5378a9fa9459Szrj indicate what the sizes are. So we have to guess. */
5379a9fa9459Szrj if (strcmp (p, "signed char") == 0)
5380a9fa9459Szrj ret = debug_make_int_type (dhandle, 1, FALSE);
5381a9fa9459Szrj else if (strcmp (p, "bool") == 0)
5382a9fa9459Szrj ret = debug_make_bool_type (dhandle, 1);
5383a9fa9459Szrj else if (strcmp (p, "char") == 0)
5384a9fa9459Szrj ret = debug_make_int_type (dhandle, 1, FALSE);
5385a9fa9459Szrj else if (strcmp (p, "double") == 0)
5386a9fa9459Szrj ret = debug_make_float_type (dhandle, 8);
5387a9fa9459Szrj else if (strcmp (p, "long double") == 0)
5388a9fa9459Szrj ret = debug_make_float_type (dhandle, 8);
5389a9fa9459Szrj else if (strcmp (p, "float") == 0)
5390a9fa9459Szrj ret = debug_make_float_type (dhandle, 4);
5391a9fa9459Szrj else if (strcmp (p, "__float128") == 0)
5392a9fa9459Szrj ret = debug_make_float_type (dhandle, 16);
5393a9fa9459Szrj else if (strcmp (p, "unsigned char") == 0)
5394a9fa9459Szrj ret = debug_make_int_type (dhandle, 1, TRUE);
5395a9fa9459Szrj else if (strcmp (p, "int") == 0)
5396a9fa9459Szrj ret = debug_make_int_type (dhandle, 4, FALSE);
5397a9fa9459Szrj else if (strcmp (p, "unsigned int") == 0)
5398a9fa9459Szrj ret = debug_make_int_type (dhandle, 4, TRUE);
5399a9fa9459Szrj else if (strcmp (p, "long") == 0)
5400a9fa9459Szrj ret = debug_make_int_type (dhandle, 4, FALSE);
5401a9fa9459Szrj else if (strcmp (p, "unsigned long") == 0)
5402a9fa9459Szrj ret = debug_make_int_type (dhandle, 4, TRUE);
5403a9fa9459Szrj else if (strcmp (p, "__int128") == 0)
5404a9fa9459Szrj ret = debug_make_int_type (dhandle, 16, FALSE);
5405a9fa9459Szrj else if (strcmp (p, "unsigned __int128") == 0)
5406a9fa9459Szrj ret = debug_make_int_type (dhandle, 16, TRUE);
5407a9fa9459Szrj else if (strcmp (p, "short") == 0)
5408a9fa9459Szrj ret = debug_make_int_type (dhandle, 2, FALSE);
5409a9fa9459Szrj else if (strcmp (p, "unsigned short") == 0)
5410a9fa9459Szrj ret = debug_make_int_type (dhandle, 2, TRUE);
5411a9fa9459Szrj else if (strcmp (p, "void") == 0)
5412a9fa9459Szrj ret = debug_make_void_type (dhandle);
5413a9fa9459Szrj else if (strcmp (p, "wchar_t") == 0)
5414a9fa9459Szrj ret = debug_make_int_type (dhandle, 4, TRUE);
5415a9fa9459Szrj else if (strcmp (p, "long long") == 0)
5416a9fa9459Szrj ret = debug_make_int_type (dhandle, 8, FALSE);
5417a9fa9459Szrj else if (strcmp (p, "unsigned long long") == 0)
5418a9fa9459Szrj ret = debug_make_int_type (dhandle, 8, TRUE);
5419a9fa9459Szrj else if (strcmp (p, "...") == 0)
5420a9fa9459Szrj {
5421a9fa9459Szrj if (pvarargs == NULL)
5422a9fa9459Szrj fprintf (stderr, _("Unexpected demangled varargs\n"));
5423a9fa9459Szrj else
5424a9fa9459Szrj *pvarargs = TRUE;
5425a9fa9459Szrj ret = NULL;
5426a9fa9459Szrj }
5427a9fa9459Szrj else
5428a9fa9459Szrj {
5429a9fa9459Szrj fprintf (stderr, _("Unrecognized demangled builtin type\n"));
5430a9fa9459Szrj ret = NULL;
5431a9fa9459Szrj }
5432a9fa9459Szrj
5433a9fa9459Szrj free (p);
5434a9fa9459Szrj
5435a9fa9459Szrj return ret;
5436a9fa9459Szrj }
5437a9fa9459Szrj }
5438a9fa9459Szrj }
5439