1
/* stabs.c -- Parse stabs debugging information
2
Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
3
Written by Ian Lance Taylor <ian@cygnus.com>.
5
This file is part of GNU Binutils.
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22
/* This file contains code which parses stabs debugging information.
23
The organization of this code is based on the gdb stabs reading
24
code. The job it does is somewhat different, because it is not
25
trying to identify the correct address for anything. */
32
#include <libiberty.h>
37
/* Meaningless definition needs by aout64.h. FIXME. */
38
#define BYTES_IN_WORD 4
40
#include "aout/aout64.h"
41
#include "aout/stab_gnu.h"
43
/* The number of predefined XCOFF types. */
45
#define XCOFF_TYPE_COUNT 34
47
/* This structure is used as a handle so that the stab parsing doesn't
48
need to use any static variables. */
54
/* True if this is stabs in sections. */
56
/* The symbol table. */
58
/* The number of symbols. */
60
/* The accumulated file name string. */
62
/* The value of the last N_SO symbol. */
64
/* The value of the start of the file, so that we can handle file
65
relative N_LBRAC and N_RBRAC symbols. */
66
bfd_vma file_start_offset;
67
/* The offset of the start of the function, so that we can handle
68
function relative N_LBRAC and N_RBRAC symbols. */
69
bfd_vma function_start_offset;
70
/* The version number of gcc which compiled the current compilation
71
unit, 0 if not compiled by gcc. */
73
/* Whether an N_OPT symbol was seen that was not generated by gcc,
74
so that we can detect the SunPRO compiler. */
76
/* The main file name. */
78
/* A stack of unfinished N_BINCL files. */
79
struct bincl_file *bincl_stack;
80
/* A list of finished N_BINCL files. */
81
struct bincl_file *bincl_list;
82
/* Whether we are inside a function or not. */
83
boolean within_function;
84
/* The address of the end of the function, used if we have seen an
85
N_FUN symbol while in a function. This is -1 if we have not seen
86
an N_FUN (the normal case). */
88
/* The depth of block nesting. */
90
/* List of pending variable definitions. */
91
struct stab_pending_var *pending;
92
/* Number of files for which we have types. */
94
/* Lists of types per file. */
95
struct stab_types **file_types;
96
/* Predefined XCOFF types. */
97
debug_type xcoff_types[XCOFF_TYPE_COUNT];
99
struct stab_tag *tags;
102
/* A list of these structures is used to hold pending variable
103
definitions seen before the N_LBRAC of a block. */
105
struct stab_pending_var
107
/* Next pending variable definition. */
108
struct stab_pending_var *next;
114
enum debug_var_kind kind;
119
/* A list of these structures is used to hold the types for a single
124
/* Next set of slots for this file. */
125
struct stab_types *next;
126
/* Types indexed by type number. */
127
#define STAB_TYPES_SLOTS (16)
128
debug_type types[STAB_TYPES_SLOTS];
131
/* We keep a list of undefined tags that we encounter, so that we can
132
fill them in if the tag is later defined. */
136
/* Next undefined tag. */
137
struct stab_tag *next;
141
enum debug_type_kind kind;
142
/* Slot to hold real type when we discover it. If we don't, we fill
143
in an undefined tag type. */
145
/* Indirect type we have created to point at slot. */
149
static char *savestring PARAMS ((const char *, int));
150
static bfd_vma parse_number PARAMS ((const char **, boolean *));
151
static void bad_stab PARAMS ((const char *));
152
static void warn_stab PARAMS ((const char *, const char *));
153
static boolean parse_stab_string
154
PARAMS ((PTR, struct stab_handle *, int, int, bfd_vma, const char *));
155
static debug_type parse_stab_type
156
PARAMS ((PTR, struct stab_handle *, const char *, const char **,
158
static boolean parse_stab_type_number
159
PARAMS ((const char **, int *));
160
static debug_type parse_stab_range_type
161
PARAMS ((PTR, struct stab_handle *, const char *, const char **,
163
static debug_type parse_stab_sun_builtin_type PARAMS ((PTR, const char **));
164
static debug_type parse_stab_sun_floating_type
165
PARAMS ((PTR, const char **));
166
static debug_type parse_stab_enum_type PARAMS ((PTR, const char **));
167
static debug_type parse_stab_struct_type
168
PARAMS ((PTR, struct stab_handle *, const char *, const char **, boolean,
170
static boolean parse_stab_baseclasses
171
PARAMS ((PTR, struct stab_handle *, const char **, debug_baseclass **));
172
static boolean parse_stab_struct_fields
173
PARAMS ((PTR, struct stab_handle *, const char **, debug_field **,
175
static boolean parse_stab_cpp_abbrev
176
PARAMS ((PTR, struct stab_handle *, const char **, debug_field *));
177
static boolean parse_stab_one_struct_field
178
PARAMS ((PTR, struct stab_handle *, const char **, const char *,
179
debug_field *, boolean *));
180
static boolean parse_stab_members
181
PARAMS ((PTR, struct stab_handle *, const char *, const char **,
182
const int *, debug_method **));
183
static debug_type parse_stab_argtypes
184
PARAMS ((PTR, struct stab_handle *, debug_type, const char *, const char *,
185
debug_type, const char *, boolean, boolean, const char **));
186
static boolean parse_stab_tilde_field
187
PARAMS ((PTR, struct stab_handle *, const char **, const int *,
188
debug_type *, boolean *));
189
static debug_type parse_stab_array_type
190
PARAMS ((PTR, struct stab_handle *, const char **, boolean));
191
static void push_bincl PARAMS ((struct stab_handle *, const char *, bfd_vma));
192
static const char *pop_bincl PARAMS ((struct stab_handle *));
193
static boolean find_excl
194
PARAMS ((struct stab_handle *, const char *, bfd_vma));
195
static boolean stab_record_variable
196
PARAMS ((PTR, struct stab_handle *, const char *, debug_type,
197
enum debug_var_kind, bfd_vma));
198
static boolean stab_emit_pending_vars PARAMS ((PTR, struct stab_handle *));
199
static debug_type *stab_find_slot
200
PARAMS ((struct stab_handle *, const int *));
201
static debug_type stab_find_type
202
PARAMS ((PTR, struct stab_handle *, const int *));
203
static boolean stab_record_type
204
PARAMS ((PTR, struct stab_handle *, const int *, debug_type));
205
static debug_type stab_xcoff_builtin_type
206
PARAMS ((PTR, struct stab_handle *, int));
207
static debug_type stab_find_tagged_type
208
PARAMS ((PTR, struct stab_handle *, const char *, int,
209
enum debug_type_kind));
210
static debug_type *stab_demangle_argtypes
211
PARAMS ((PTR, struct stab_handle *, const char *, boolean *));
213
/* Save a string in memory. */
216
savestring (start, len)
222
ret = (char *) xmalloc (len + 1);
223
memcpy (ret, start, len);
228
/* Read a number from a string. */
231
parse_number (pp, poverflow)
238
if (poverflow != NULL)
244
ul = strtoul (*pp, (char **) pp, 0);
245
if (ul + 1 != 0 || errno == 0)
248
/* Note that even though strtoul overflowed, it should have set *pp
249
to the end of the number, which is where we want it. */
251
if (sizeof (bfd_vma) > sizeof (unsigned long))
256
bfd_vma over, lastdig;
260
/* Our own version of strtoul, for a bfd_vma. */
276
if (p[1] == 'x' || p[1] == 'X')
288
over = ((bfd_vma) (bfd_signed_vma) -1) / (bfd_vma) base;
289
lastdig = ((bfd_vma) (bfd_signed_vma) -1) % (bfd_vma) base;
298
if (isdigit ((unsigned char) d))
300
else if (isupper ((unsigned char) d))
302
else if (islower ((unsigned char) d))
310
if (v > over || (v == over && (bfd_vma) d > lastdig))
325
/* If we get here, the number is too large to represent in a
328
if (poverflow != NULL)
331
warn_stab (orig, "numeric overflow");
336
/* Give an error for a bad stab string. */
342
fprintf (stderr, "Bad stab: %s\n", p);
345
/* Warn about something in a stab string. */
352
fprintf (stderr, "Warning: %s: %s\n", err, p);
355
/* Create a handle to parse stabs symbols with. */
359
start_stab (dhandle, abfd, sections, syms, symcount)
366
struct stab_handle *ret;
368
ret = (struct stab_handle *) xmalloc (sizeof *ret);
369
memset (ret, 0, sizeof *ret);
371
ret->sections = sections;
373
ret->symcount = symcount;
375
ret->file_types = (struct stab_types **) xmalloc (sizeof *ret->file_types);
376
ret->file_types[0] = NULL;
377
ret->function_end = (bfd_vma) -1;
381
/* When we have processed all the stabs information, we need to go
382
through and fill in all the undefined tags. */
385
finish_stab (dhandle, handle)
389
struct stab_handle *info = (struct stab_handle *) handle;
392
if (info->within_function)
394
if (! stab_emit_pending_vars (dhandle, info)
395
|| ! debug_end_function (dhandle, info->function_end))
397
info->within_function = false;
398
info->function_end = (bfd_vma) -1;
401
for (st = info->tags; st != NULL; st = st->next)
403
enum debug_type_kind kind;
406
if (kind == DEBUG_KIND_ILLEGAL)
407
kind = DEBUG_KIND_STRUCT;
408
st->slot = debug_make_undefined_tagged_type (dhandle, st->name, kind);
409
if (st->slot == DEBUG_TYPE_NULL)
416
/* Handle a single stabs symbol. */
419
parse_stab (dhandle, handle, type, desc, value, string)
427
struct stab_handle *info = (struct stab_handle *) handle;
429
/* gcc will emit two N_SO strings per compilation unit, one for the
430
directory name and one for the file name. We just collect N_SO
431
strings as we see them, and start the new compilation unit when
432
we see a non N_SO symbol. */
433
if (info->so_string != NULL
434
&& (type != N_SO || *string == '\0' || value != info->so_value))
436
if (! debug_set_filename (dhandle, info->so_string))
438
info->main_filename = info->so_string;
440
info->gcc_compiled = 0;
441
info->n_opt_found = false;
443
/* Generally, for stabs in the symbol table, the N_LBRAC and
444
N_RBRAC symbols are relative to the N_SO symbol value. */
445
if (! info->sections)
446
info->file_start_offset = info->so_value;
448
/* We need to reset the mapping from type numbers to types. We
449
can't free the old mapping, because of the use of
450
debug_make_indirect_type. */
452
info->file_types = ((struct stab_types **)
453
xmalloc (sizeof *info->file_types));
454
info->file_types[0] = NULL;
456
info->so_string = NULL;
458
/* Now process whatever type we just got. */
468
/* Ignore extra outermost context from SunPRO cc and acc. */
469
if (info->n_opt_found && desc == 1)
472
if (! info->within_function)
474
fprintf (stderr, "N_LBRAC not within function\n");
478
/* Start an inner lexical block. */
479
if (! debug_start_block (dhandle,
481
+ info->file_start_offset
482
+ info->function_start_offset)))
485
/* Emit any pending variable definitions. */
486
if (! stab_emit_pending_vars (dhandle, info))
493
/* Ignore extra outermost context from SunPRO cc and acc. */
494
if (info->n_opt_found && desc == 1)
497
/* We shouldn't have any pending variable definitions here, but,
498
if we do, we probably need to emit them before closing the
500
if (! stab_emit_pending_vars (dhandle, info))
503
/* End an inner lexical block. */
504
if (! debug_end_block (dhandle,
506
+ info->file_start_offset
507
+ info->function_start_offset)))
511
if (info->block_depth < 0)
513
fprintf (stderr, "Too many N_RBRACs\n");
519
/* This always ends a function. */
520
if (info->within_function)
526
&& info->function_end != (bfd_vma) -1
527
&& info->function_end < endval)
528
endval = info->function_end;
529
if (! stab_emit_pending_vars (dhandle, info)
530
|| ! debug_end_function (dhandle, endval))
532
info->within_function = false;
533
info->function_end = (bfd_vma) -1;
536
/* An empty string is emitted by gcc at the end of a compilation
541
/* Just accumulate strings until we see a non N_SO symbol. If
542
the string starts with '/', we discard the previously
543
accumulated strings. */
544
if (info->so_string == NULL)
545
info->so_string = xstrdup (string);
552
info->so_string = xstrdup (string);
554
info->so_string = concat (info->so_string, string,
555
(const char *) NULL);
559
info->so_value = value;
564
/* Start an include file. */
565
if (! debug_start_source (dhandle, string))
570
/* Start an include file which may be replaced. */
571
push_bincl (info, string, value);
572
if (! debug_start_source (dhandle, string))
577
/* End an N_BINCL include. */
578
if (! debug_start_source (dhandle, pop_bincl (info)))
583
/* This is a duplicate of a header file named by N_BINCL which
584
was eliminated by the linker. */
585
if (! find_excl (info, string, value))
590
if (! debug_record_line (dhandle, desc,
591
value + info->function_start_offset))
596
if (! debug_start_common_block (dhandle, string))
601
if (! debug_end_common_block (dhandle, string))
608
if (info->within_function)
610
/* This always marks the end of a function; we don't
611
need to worry about info->function_end. */
613
value += info->function_start_offset;
614
if (! stab_emit_pending_vars (dhandle, info)
615
|| ! debug_end_function (dhandle, value))
617
info->within_function = false;
618
info->function_end = (bfd_vma) -1;
623
/* A const static symbol in the .text section will have an N_FUN
624
entry. We need to use these to mark the end of the function,
625
in case we are looking at gcc output before it was changed to
626
always emit an empty N_FUN. We can't call debug_end_function
627
here, because it might be a local static symbol. */
628
if (info->within_function
629
&& (info->function_end == (bfd_vma) -1
630
|| value < info->function_end))
631
info->function_end = value;
634
/* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM
635
symbols, and if it does not start with :S, gdb relocates the
636
value to the start of the section. gcc always seems to use
637
:S, so we don't worry about this. */
643
colon = strchr (string, ':');
645
&& (colon[1] == 'f' || colon[1] == 'F'))
647
if (info->within_function)
652
if (info->function_end != (bfd_vma) -1
653
&& info->function_end < endval)
654
endval = info->function_end;
655
if (! stab_emit_pending_vars (dhandle, info)
656
|| ! debug_end_function (dhandle, endval))
658
info->function_end = (bfd_vma) -1;
660
/* For stabs in sections, line numbers and block addresses
661
are offsets from the start of the function. */
663
info->function_start_offset = value;
664
info->within_function = true;
667
if (! parse_stab_string (dhandle, info, type, desc, value, string))
673
if (string != NULL && strcmp (string, "gcc2_compiled.") == 0)
674
info->gcc_compiled = 2;
675
else if (string != NULL && strcmp (string, "gcc_compiled.") == 0)
676
info->gcc_compiled = 1;
678
info->n_opt_found = true;
690
/* Parse the stabs string. */
693
parse_stab_string (dhandle, info, stabtype, desc, value, string)
695
struct stab_handle *info;
709
p = strchr (string, ':');
724
/* GCC 2.x puts the line number in desc. SunOS apparently puts in
725
the number of bytes occupied by a type or object, which we
727
if (info->gcc_compiled >= 2)
732
/* FIXME: Sometimes the special C++ names start with '.'. */
734
if (string[0] == '$')
742
/* Was: name = "vptr"; */
748
/* This was an anonymous type that was never fixed up. */
751
/* SunPRO (3.0 at least) static variable encoding. */
754
warn_stab (string, "unknown C++ encoded name");
761
if (p == string || (string[0] == ' ' && p == string + 1))
764
name = savestring (string, p - string);
768
if (isdigit ((unsigned char) *p) || *p == '(' || *p == '-')
776
/* c is a special case, not followed by a type-number.
777
SYMBOL:c=iVALUE for an integer constant symbol.
778
SYMBOL:c=rVALUE for a floating constant symbol.
779
SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
780
e.g. "b:c=e6,0" for "const b = blob1"
781
(where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
791
/* Floating point constant. */
792
if (! debug_record_float_const (dhandle, name, atof (p)))
796
/* Integer constant. */
797
/* Defining integer constants this way is kind of silly,
798
since 'e' constants allows the compiler to give not only
799
the value, but the type as well. C has at least int,
800
long, unsigned int, and long long as constant types;
801
other languages probably should have at least unsigned as
802
well as signed constants. */
803
if (! debug_record_int_const (dhandle, name, atoi (p)))
807
/* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
808
can be represented as integral.
809
e.g. "b:c=e6,0" for "const b = blob1"
810
(where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
811
dtype = parse_stab_type (dhandle, info, (const char *) NULL,
812
&p, (debug_type **) NULL);
813
if (dtype == DEBUG_TYPE_NULL)
820
if (! debug_record_typed_const (dhandle, name, dtype, atoi (p)))
831
/* The name of a caught exception. */
832
dtype = parse_stab_type (dhandle, info, (const char *) NULL,
833
&p, (debug_type **) NULL);
834
if (dtype == DEBUG_TYPE_NULL)
836
if (! debug_record_label (dhandle, name, dtype, value))
842
/* A function definition. */
843
dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
844
(debug_type **) NULL);
845
if (dtype == DEBUG_TYPE_NULL)
847
if (! debug_record_function (dhandle, name, dtype, type == 'F', value))
850
/* Sun acc puts declared types of arguments here. We don't care
851
about their actual types (FIXME -- we should remember the whole
852
function prototype), but the list may define some new types
853
that we have to remember, so we must scan it now. */
857
if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
858
(debug_type **) NULL)
871
/* A global symbol. The value must be extracted from the
873
dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
874
(debug_type **) NULL);
875
if (dtype == DEBUG_TYPE_NULL)
877
leading = bfd_get_symbol_leading_char (info->abfd);
878
for (c = info->symcount, ps = info->syms; c > 0; --c, ++ps)
882
n = bfd_asymbol_name (*ps);
883
if (leading != '\0' && *n == leading)
885
if (*n == *name && strcmp (n, name) == 0)
889
value = bfd_asymbol_value (*ps);
890
if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_GLOBAL,
896
/* This case is faked by a conditional above, when there is no
897
code letter in the dbx data. Dbx data never actually
901
dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
902
(debug_type **) NULL);
903
if (dtype == DEBUG_TYPE_NULL)
905
if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
911
/* A function parameter. */
913
dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
914
(debug_type **) NULL);
917
/* pF is a two-letter code that means a function parameter in
918
Fortran. The type-number specifies the type of the return
919
value. Translate it into a pointer-to-function type. */
921
dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
922
(debug_type **) NULL);
923
if (dtype != DEBUG_TYPE_NULL)
927
ftype = debug_make_function_type (dhandle, dtype,
928
(debug_type *) NULL, false);
929
dtype = debug_make_pointer_type (dhandle, ftype);
932
if (dtype == DEBUG_TYPE_NULL)
934
if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_STACK,
938
/* FIXME: At this point gdb considers rearranging the parameter
939
address on a big endian machine if it is smaller than an int.
940
We have no way to do that, since we don't really know much
946
if (stabtype == N_FUN)
948
/* Prototype of a function referenced by this file. */
952
if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
953
(debug_type **) NULL)
961
/* Parameter which is in a register. */
962
dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
963
(debug_type **) NULL);
964
if (dtype == DEBUG_TYPE_NULL)
966
if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REG,
972
/* Register variable (either global or local). */
973
dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
974
(debug_type **) NULL);
975
if (dtype == DEBUG_TYPE_NULL)
977
if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_REGISTER,
981
/* FIXME: At this point gdb checks to combine pairs of 'p' and
982
'r' stabs into a single 'P' stab. */
987
/* Static symbol at top level of file */
988
dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
989
(debug_type **) NULL);
990
if (dtype == DEBUG_TYPE_NULL)
992
if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_STATIC,
999
dtype = parse_stab_type (dhandle, info, name, &p, &slot);
1000
if (dtype == DEBUG_TYPE_NULL)
1004
/* A nameless type. Nothing to do. */
1008
dtype = debug_name_type (dhandle, name, dtype);
1009
if (dtype == DEBUG_TYPE_NULL)
1018
/* Struct, union, or enum tag. For GNU C++, this can be be followed
1019
by 't' which means we are typedef'ing it as well. */
1023
/* FIXME: gdb sets synonym to true if the current language
1032
dtype = parse_stab_type (dhandle, info, name, &p, &slot);
1033
if (dtype == DEBUG_TYPE_NULL)
1038
dtype = debug_tag_type (dhandle, name, dtype);
1039
if (dtype == DEBUG_TYPE_NULL)
1044
/* See if we have a cross reference to this tag which we can now
1047
register struct stab_tag **pst;
1049
for (pst = &info->tags; *pst != NULL; pst = &(*pst)->next)
1051
if ((*pst)->name[0] == name[0]
1052
&& strcmp ((*pst)->name, name) == 0)
1054
(*pst)->slot = dtype;
1055
*pst = (*pst)->next;
1063
dtype = debug_name_type (dhandle, name, dtype);
1064
if (dtype == DEBUG_TYPE_NULL)
1074
/* Static symbol of local scope */
1075
dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1076
(debug_type **) NULL);
1077
if (dtype == DEBUG_TYPE_NULL)
1079
/* FIXME: gdb checks os9k_stabs here. */
1080
if (! stab_record_variable (dhandle, info, name, dtype,
1081
DEBUG_LOCAL_STATIC, value))
1086
/* Reference parameter. */
1087
dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1088
(debug_type **) NULL);
1089
if (dtype == DEBUG_TYPE_NULL)
1091
if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REFERENCE,
1097
/* Reference parameter which is in a register. */
1098
dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1099
(debug_type **) NULL);
1100
if (dtype == DEBUG_TYPE_NULL)
1102
if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REF_REG,
1108
/* This is used by Sun FORTRAN for "function result value".
1109
Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1110
that Pascal uses it too, but when I tried it Pascal used
1111
"x:3" (local symbol) instead. */
1112
dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1113
(debug_type **) NULL);
1114
if (dtype == DEBUG_TYPE_NULL)
1116
if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
1126
/* FIXME: gdb converts structure values to structure pointers in a
1127
couple of cases, depending upon the target. */
1132
/* Parse a stabs type. The typename argument is non-NULL if this is a
1133
typedef or a tag definition. The pp argument points to the stab
1134
string, and is updated. The slotp argument points to a place to
1135
store the slot used if the type is being defined. */
1138
parse_stab_type (dhandle, info, typename, pp, slotp)
1140
struct stab_handle *info;
1141
const char *typename;
1160
/* Read type number if present. The type number may be omitted.
1161
for instance in a two-dimensional array declared with type
1162
"ar1;1;10;ar1;1;10;4". */
1163
if (! isdigit ((unsigned char) **pp) && **pp != '(' && **pp != '-')
1165
/* 'typenums=' not present, type is anonymous. Read and return
1166
the definition, but don't put it in the type vector. */
1167
typenums[0] = typenums[1] = -1;
1171
if (! parse_stab_type_number (pp, typenums))
1172
return DEBUG_TYPE_NULL;
1176
/* Type is not being defined here. Either it already
1177
exists, or this is a forward reference to it. */
1178
return stab_find_type (dhandle, info, typenums);
1181
/* Only set the slot if the type is being defined. This means
1182
that the mapping from type numbers to types will only record
1183
the name of the typedef which defines a type. If we don't do
1184
this, then something like
1187
will record that i is of type foo. Unfortunately, stabs
1188
information is ambiguous about variable types. For this code,
1192
the stabs information records both i and j as having the same
1193
type. This could be fixed by patching the compiler. */
1194
if (slotp != NULL && typenums[0] >= 0 && typenums[1] >= 0)
1195
*slotp = stab_find_slot (info, typenums);
1197
/* Type is being defined here. */
1203
const char *p = *pp + 1;
1206
if (isdigit ((unsigned char) *p) || *p == '(' || *p == '-')
1212
/* Type attributes. */
1215
for (; *p != ';'; ++p)
1220
return DEBUG_TYPE_NULL;
1228
size = atoi (attr + 1);
1238
/* Ignore unrecognized type attributes, so future
1239
compilers can invent new ones. */
1252
enum debug_type_kind code;
1253
const char *q1, *q2, *p;
1255
/* A cross reference to another type. */
1260
code = DEBUG_KIND_STRUCT;
1263
code = DEBUG_KIND_UNION;
1266
code = DEBUG_KIND_ENUM;
1269
/* Complain and keep going, so compilers can invent new
1270
cross-reference types. */
1271
warn_stab (orig, "unrecognized cross reference type");
1272
code = DEBUG_KIND_STRUCT;
1277
q1 = strchr (*pp, '<');
1278
p = strchr (*pp, ':');
1282
return DEBUG_TYPE_NULL;
1284
while (q1 != NULL && p > q1 && p[1] == ':')
1286
q2 = strchr (q1, '>');
1287
if (q2 == NULL || q2 < p)
1290
p = strchr (p, ':');
1294
return DEBUG_TYPE_NULL;
1298
dtype = stab_find_tagged_type (dhandle, info, *pp, p - *pp, code);
1320
/* This type is defined as another type. */
1325
/* Peek ahead at the number to detect void. */
1326
if (! parse_stab_type_number (pp, xtypenums))
1327
return DEBUG_TYPE_NULL;
1329
if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1])
1331
/* This type is being defined as itself, which means that
1333
dtype = debug_make_void_type (dhandle);
1339
/* Go back to the number and have parse_stab_type get it.
1340
This means that we can deal with something like
1341
t(1,2)=(3,4)=... which the Lucid compiler uses. */
1342
dtype = parse_stab_type (dhandle, info, (const char *) NULL,
1343
pp, (debug_type **) NULL);
1344
if (dtype == DEBUG_TYPE_NULL)
1345
return DEBUG_TYPE_NULL;
1348
if (typenums[0] != -1)
1350
if (! stab_record_type (dhandle, info, typenums, dtype))
1351
return DEBUG_TYPE_NULL;
1358
dtype = debug_make_pointer_type (dhandle,
1359
parse_stab_type (dhandle, info,
1360
(const char *) NULL,
1362
(debug_type **) NULL));
1366
/* Reference to another type. */
1367
dtype = (debug_make_reference_type
1369
parse_stab_type (dhandle, info, (const char *) NULL, pp,
1370
(debug_type **) NULL)));
1374
/* Function returning another type. */
1375
/* FIXME: gdb checks os9k_stabs here. */
1376
dtype = (debug_make_function_type
1378
parse_stab_type (dhandle, info, (const char *) NULL, pp,
1379
(debug_type **) NULL),
1380
(debug_type *) NULL, false));
1384
/* Const qualifier on some type (Sun). */
1385
/* FIXME: gdb accepts 'c' here if os9k_stabs. */
1386
dtype = debug_make_const_type (dhandle,
1387
parse_stab_type (dhandle, info,
1388
(const char *) NULL,
1390
(debug_type **) NULL));
1394
/* Volatile qual on some type (Sun). */
1395
/* FIXME: gdb accepts 'i' here if os9k_stabs. */
1396
dtype = (debug_make_volatile_type
1398
parse_stab_type (dhandle, info, (const char *) NULL, pp,
1399
(debug_type **) NULL)));
1403
/* Offset (class & variable) type. This is used for a pointer
1404
relative to an object. */
1411
domain = parse_stab_type (dhandle, info, (const char *) NULL, pp,
1412
(debug_type **) NULL);
1413
if (domain == DEBUG_TYPE_NULL)
1414
return DEBUG_TYPE_NULL;
1419
return DEBUG_TYPE_NULL;
1423
memtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
1424
(debug_type **) NULL);
1425
if (memtype == DEBUG_TYPE_NULL)
1426
return DEBUG_TYPE_NULL;
1428
dtype = debug_make_offset_type (dhandle, domain, memtype);
1433
/* Method (class & fn) type. */
1436
debug_type return_type;
1439
return_type = parse_stab_type (dhandle, info, (const char *) NULL,
1440
pp, (debug_type **) NULL);
1441
if (return_type == DEBUG_TYPE_NULL)
1442
return DEBUG_TYPE_NULL;
1446
return DEBUG_TYPE_NULL;
1449
dtype = debug_make_method_type (dhandle, return_type,
1451
(debug_type *) NULL, false);
1456
debug_type return_type;
1462
domain = parse_stab_type (dhandle, info, (const char *) NULL,
1463
pp, (debug_type **) NULL);
1464
if (domain == DEBUG_TYPE_NULL)
1465
return DEBUG_TYPE_NULL;
1470
return DEBUG_TYPE_NULL;
1474
return_type = parse_stab_type (dhandle, info, (const char *) NULL,
1475
pp, (debug_type **) NULL);
1476
if (return_type == DEBUG_TYPE_NULL)
1477
return DEBUG_TYPE_NULL;
1480
args = (debug_type *) xmalloc (alloc * sizeof *args);
1487
return DEBUG_TYPE_NULL;
1494
args = ((debug_type *)
1495
xrealloc ((PTR) args, alloc * sizeof *args));
1498
args[n] = parse_stab_type (dhandle, info, (const char *) NULL,
1499
pp, (debug_type **) NULL);
1500
if (args[n] == DEBUG_TYPE_NULL)
1501
return DEBUG_TYPE_NULL;
1506
/* If the last type is not void, then this function takes a
1507
variable number of arguments. Otherwise, we must strip
1510
|| debug_get_type_kind (dhandle, args[n - 1]) != DEBUG_KIND_VOID)
1518
args[n] = DEBUG_TYPE_NULL;
1520
dtype = debug_make_method_type (dhandle, return_type, domain, args,
1527
dtype = parse_stab_range_type (dhandle, info, typename, pp, typenums);
1531
/* FIXME: gdb checks os9k_stabs here. */
1532
/* Sun ACC builtin int type. */
1533
dtype = parse_stab_sun_builtin_type (dhandle, pp);
1537
/* Sun ACC builtin float type. */
1538
dtype = parse_stab_sun_floating_type (dhandle, pp);
1542
/* Enumeration type. */
1543
dtype = parse_stab_enum_type (dhandle, pp);
1548
/* Struct or union type. */
1549
dtype = parse_stab_struct_type (dhandle, info, typename, pp,
1550
descriptor == 's', typenums);
1558
return DEBUG_TYPE_NULL;
1562
dtype = parse_stab_array_type (dhandle, info, pp, stringp);
1566
dtype = debug_make_set_type (dhandle,
1567
parse_stab_type (dhandle, info,
1568
(const char *) NULL,
1570
(debug_type **) NULL),
1576
return DEBUG_TYPE_NULL;
1579
if (dtype == DEBUG_TYPE_NULL)
1580
return DEBUG_TYPE_NULL;
1582
if (typenums[0] != -1)
1584
if (! stab_record_type (dhandle, info, typenums, dtype))
1585
return DEBUG_TYPE_NULL;
1590
if (! debug_record_type_size (dhandle, dtype, (unsigned int) size))
1591
return DEBUG_TYPE_NULL;
1597
/* Read a number by which a type is referred to in dbx data, or
1598
perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a
1599
single number N is equivalent to (0,N). Return the two numbers by
1600
storing them in the vector TYPENUMS. */
1603
parse_stab_type_number (pp, typenums)
1614
typenums[1] = (int) parse_number (pp, (boolean *) NULL);
1619
typenums[0] = (int) parse_number (pp, (boolean *) NULL);
1626
typenums[1] = (int) parse_number (pp, (boolean *) NULL);
1638
/* Parse a range type. */
1641
parse_stab_range_type (dhandle, info, typename, pp, typenums)
1643
struct stab_handle *info;
1644
const char *typename;
1646
const int *typenums;
1650
boolean self_subrange;
1651
debug_type index_type;
1652
const char *s2, *s3;
1653
bfd_signed_vma n2, n3;
1658
index_type = DEBUG_TYPE_NULL;
1660
/* First comes a type we are a subrange of.
1661
In C it is usually 0, 1 or the type being defined. */
1662
if (! parse_stab_type_number (pp, rangenums))
1663
return DEBUG_TYPE_NULL;
1665
self_subrange = (rangenums[0] == typenums[0]
1666
&& rangenums[1] == typenums[1]);
1671
index_type = parse_stab_type (dhandle, info, (const char *) NULL,
1672
pp, (debug_type **) NULL);
1673
if (index_type == DEBUG_TYPE_NULL)
1674
return DEBUG_TYPE_NULL;
1680
/* The remaining two operands are usually lower and upper bounds of
1681
the range. But in some special cases they mean something else. */
1683
n2 = parse_number (pp, &ov2);
1687
return DEBUG_TYPE_NULL;
1692
n3 = parse_number (pp, &ov3);
1696
return DEBUG_TYPE_NULL;
1702
/* gcc will emit range stabs for long long types. Handle this
1703
as a special case. FIXME: This needs to be more general. */
1704
#define LLLOW "01000000000000000000000;"
1705
#define LLHIGH "0777777777777777777777;"
1706
#define ULLHIGH "01777777777777777777777;"
1707
if (index_type == DEBUG_TYPE_NULL)
1709
if (strncmp (s2, LLLOW, sizeof LLLOW - 1) == 0
1710
&& strncmp (s3, LLHIGH, sizeof LLHIGH - 1) == 0)
1711
return debug_make_int_type (dhandle, 8, false);
1714
&& strncmp (s3, ULLHIGH, sizeof ULLHIGH - 1) == 0)
1715
return debug_make_int_type (dhandle, 8, true);
1718
warn_stab (orig, "numeric overflow");
1721
if (index_type == DEBUG_TYPE_NULL)
1723
/* A type defined as a subrange of itself, with both bounds 0,
1725
if (self_subrange && n2 == 0 && n3 == 0)
1726
return debug_make_void_type (dhandle);
1728
/* A type defined as a subrange of itself, with n2 positive and
1729
n3 zero, is a complex type, and n2 is the number of bytes. */
1730
if (self_subrange && n3 == 0 && n2 > 0)
1731
return debug_make_complex_type (dhandle, n2);
1733
/* If n3 is zero and n2 is positive, this is a floating point
1734
type, and n2 is the number of bytes. */
1735
if (n3 == 0 && n2 > 0)
1736
return debug_make_float_type (dhandle, n2);
1738
/* If the upper bound is -1, this is an unsigned int. */
1739
if (n2 == 0 && n3 == -1)
1741
/* When gcc is used with -gstabs, but not -gstabs+, it will emit
1742
long long int:t6=r1;0;-1;
1743
long long unsigned int:t7=r1;0;-1;
1744
We hack here to handle this reasonably. */
1745
if (typename != NULL)
1747
if (strcmp (typename, "long long int") == 0)
1748
return debug_make_int_type (dhandle, 8, false);
1749
else if (strcmp (typename, "long long unsigned int") == 0)
1750
return debug_make_int_type (dhandle, 8, true);
1752
/* FIXME: The size here really depends upon the target. */
1753
return debug_make_int_type (dhandle, 4, true);
1756
/* A range of 0 to 127 is char. */
1757
if (self_subrange && n2 == 0 && n3 == 127)
1758
return debug_make_int_type (dhandle, 1, false);
1760
/* FIXME: gdb checks for the language CHILL here. */
1765
return debug_make_int_type (dhandle, - n3, true);
1766
else if (n3 == 0xff)
1767
return debug_make_int_type (dhandle, 1, true);
1768
else if (n3 == 0xffff)
1769
return debug_make_int_type (dhandle, 2, true);
1770
/* -1 is used for the upper bound of (4 byte) "unsigned int"
1771
and "unsigned long", and we already checked for that, so
1772
don't need to test for it here. */
1776
&& (self_subrange || n2 == -8))
1777
return debug_make_int_type (dhandle, - n2, true);
1778
else if (n2 == - n3 - 1)
1781
return debug_make_int_type (dhandle, 1, false);
1782
else if (n3 == 0x7fff)
1783
return debug_make_int_type (dhandle, 2, false);
1784
else if (n3 == 0x7fffffff)
1785
return debug_make_int_type (dhandle, 4, false);
1789
/* At this point I don't have the faintest idea how to deal with a
1790
self_subrange type; I'm going to assume that this is used as an
1791
idiom, and that all of them are special cases. So . . . */
1795
return DEBUG_TYPE_NULL;
1798
index_type = stab_find_type (dhandle, info, rangenums);
1799
if (index_type == DEBUG_TYPE_NULL)
1801
/* Does this actually ever happen? Is that why we are worrying
1802
about dealing with it rather than just calling error_type? */
1803
warn_stab (orig, "missing index type");
1804
index_type = debug_make_int_type (dhandle, 4, false);
1807
return debug_make_range_type (dhandle, index_type, n2, n3);
1810
/* Sun's ACC uses a somewhat saner method for specifying the builtin
1811
typedefs in every file (for int, long, etc):
1813
type = b <signed> <width>; <offset>; <nbits>
1814
signed = u or s. Possible c in addition to u or s (for char?).
1815
offset = offset from high order bit to start bit of type.
1816
width is # bytes in object of this type, nbits is # bits in type.
1818
The width/offset stuff appears to be for small objects stored in
1819
larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
1823
parse_stab_sun_builtin_type (dhandle, pp)
1843
return DEBUG_TYPE_NULL;
1847
/* For some odd reason, all forms of char put a c here. This is strange
1848
because no other type has this honor. We can safely ignore this because
1849
we actually determine 'char'acterness by the number of bits specified in
1854
/* The first number appears to be the number of bytes occupied
1855
by this type, except that unsigned short is 4 instead of 2.
1856
Since this information is redundant with the third number,
1857
we will ignore it. */
1858
(void) parse_number (pp, (boolean *) NULL);
1862
return DEBUG_TYPE_NULL;
1866
/* The second number is always 0, so ignore it too. */
1867
(void) parse_number (pp, (boolean *) NULL);
1871
return DEBUG_TYPE_NULL;
1875
/* The third number is the number of bits for this type. */
1876
bits = parse_number (pp, (boolean *) NULL);
1878
/* The type *should* end with a semicolon. If it are embedded
1879
in a larger type the semicolon may be the only way to know where
1880
the type ends. If this type is at the end of the stabstring we
1881
can deal with the omitted semicolon (but we don't have to like
1882
it). Don't bother to complain(), Sun's compiler omits the semicolon
1888
return debug_make_void_type (dhandle);
1890
return debug_make_int_type (dhandle, bits / 8, unsignedp);
1893
/* Parse a builtin floating type generated by the Sun compiler. */
1896
parse_stab_sun_floating_type (dhandle, pp)
1906
/* The first number has more details about the type, for example
1908
details = parse_number (pp, (boolean *) NULL);
1912
return DEBUG_TYPE_NULL;
1915
/* The second number is the number of bytes occupied by this type */
1916
bytes = parse_number (pp, (boolean *) NULL);
1920
return DEBUG_TYPE_NULL;
1923
if (details == NF_COMPLEX
1924
|| details == NF_COMPLEX16
1925
|| details == NF_COMPLEX32)
1926
return debug_make_complex_type (dhandle, bytes);
1928
return debug_make_float_type (dhandle, bytes);
1931
/* Handle an enum type. */
1934
parse_stab_enum_type (dhandle, pp)
1940
bfd_signed_vma *values;
1946
/* FIXME: gdb checks os9k_stabs here. */
1948
/* The aix4 compiler emits an extra field before the enum members;
1949
my guess is it's a type of some sort. Just ignore it. */
1957
/* Read the value-names and their values.
1958
The input syntax is NAME:VALUE,NAME:VALUE, and so on.
1959
A semicolon or comma instead of a NAME means the end. */
1961
names = (const char **) xmalloc (alloc * sizeof *names);
1962
values = (bfd_signed_vma *) xmalloc (alloc * sizeof *values);
1964
while (**pp != '\0' && **pp != ';' && **pp != ',')
1974
name = savestring (*pp, p - *pp);
1977
val = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
1981
return DEBUG_TYPE_NULL;
1988
names = ((const char **)
1989
xrealloc ((PTR) names, alloc * sizeof *names));
1990
values = ((bfd_signed_vma *)
1991
xrealloc ((PTR) values, alloc * sizeof *values));
2005
return debug_make_enum_type (dhandle, names, values);
2008
/* Read the description of a structure (or union type) and return an object
2009
describing the type.
2011
PP points to a character pointer that points to the next unconsumed token
2012
in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2013
*PP will point to "4a:1,0,32;;". */
2016
parse_stab_struct_type (dhandle, info, tagname, pp, structp, typenums)
2018
struct stab_handle *info;
2019
const char *tagname;
2022
const int *typenums;
2026
debug_baseclass *baseclasses;
2027
debug_field *fields;
2029
debug_method *methods;
2030
debug_type vptrbase;
2036
size = parse_number (pp, (boolean *) NULL);
2038
/* Get the other information. */
2039
if (! parse_stab_baseclasses (dhandle, info, pp, &baseclasses)
2040
|| ! parse_stab_struct_fields (dhandle, info, pp, &fields, &statics)
2041
|| ! parse_stab_members (dhandle, info, tagname, pp, typenums, &methods)
2042
|| ! parse_stab_tilde_field (dhandle, info, pp, typenums, &vptrbase,
2044
return DEBUG_TYPE_NULL;
2047
&& baseclasses == NULL
2049
&& vptrbase == DEBUG_TYPE_NULL
2051
return debug_make_struct_type (dhandle, structp, size, fields);
2053
return debug_make_object_type (dhandle, structp, size, fields, baseclasses,
2054
methods, vptrbase, ownvptr);
2057
/* The stabs for C++ derived classes contain baseclass information which
2058
is marked by a '!' character after the total size. This function is
2059
called when we encounter the baseclass marker, and slurps up all the
2060
baseclass information.
2062
Immediately following the '!' marker is the number of base classes that
2063
the class is derived from, followed by information for each base class.
2064
For each base class, there are two visibility specifiers, a bit offset
2065
to the base class information within the derived class, a reference to
2066
the type for the base class, and a terminating semicolon.
2068
A typical example, with two base classes, would be "!2,020,19;0264,21;".
2070
Baseclass information marker __________________|| | | | | | |
2071
Number of baseclasses __________________________| | | | | | |
2072
Visibility specifiers (2) ________________________| | | | | |
2073
Offset in bits from start of class _________________| | | | |
2074
Type number for base class ___________________________| | | |
2075
Visibility specifiers (2) _______________________________| | |
2076
Offset in bits from start of class ________________________| |
2077
Type number of base class ____________________________________|
2079
Return true for success, false for failure. */
2082
parse_stab_baseclasses (dhandle, info, pp, retp)
2084
struct stab_handle *info;
2086
debug_baseclass **retp;
2090
debug_baseclass *classes;
2098
/* No base classes. */
2103
c = (unsigned int) parse_number (pp, (boolean *) NULL);
2112
classes = (debug_baseclass *) xmalloc ((c + 1) * sizeof (**retp));
2114
for (i = 0; i < c; i++)
2117
enum debug_visibility visibility;
2130
warn_stab (orig, "unknown virtual character for baseclass");
2139
visibility = DEBUG_VISIBILITY_PRIVATE;
2142
visibility = DEBUG_VISIBILITY_PROTECTED;
2145
visibility = DEBUG_VISIBILITY_PUBLIC;
2148
warn_stab (orig, "unknown visibility character for baseclass");
2149
visibility = DEBUG_VISIBILITY_PUBLIC;
2154
/* The remaining value is the bit offset of the portion of the
2155
object corresponding to this baseclass. Always zero in the
2156
absence of multiple inheritance. */
2157
bitpos = parse_number (pp, (boolean *) NULL);
2165
type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2166
(debug_type **) NULL);
2167
if (type == DEBUG_TYPE_NULL)
2170
classes[i] = debug_make_baseclass (dhandle, type, bitpos, virtual,
2172
if (classes[i] == DEBUG_BASECLASS_NULL)
2180
classes[i] = DEBUG_BASECLASS_NULL;
2187
/* Read struct or class data fields. They have the form:
2189
NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2191
At the end, we see a semicolon instead of a field.
2193
In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2196
The optional VISIBILITY is one of:
2198
'/0' (VISIBILITY_PRIVATE)
2199
'/1' (VISIBILITY_PROTECTED)
2200
'/2' (VISIBILITY_PUBLIC)
2201
'/9' (VISIBILITY_IGNORE)
2203
or nothing, for C style fields with public visibility.
2205
Returns 1 for success, 0 for failure. */
2208
parse_stab_struct_fields (dhandle, info, pp, retp, staticsp)
2210
struct stab_handle *info;
2217
debug_field *fields;
2228
fields = (debug_field *) xmalloc (alloc * sizeof *fields);
2231
/* FIXME: gdb checks os9k_stabs here. */
2235
/* Add 1 to c to leave room for NULL pointer at end. */
2239
fields = ((debug_field *)
2240
xrealloc ((PTR) fields, alloc * sizeof *fields));
2243
/* If it starts with CPLUS_MARKER it is a special abbreviation,
2244
unless the CPLUS_MARKER is followed by an underscore, in
2245
which case it is just the name of an anonymous type, which we
2246
should handle like any other type name. We accept either '$'
2247
or '.', because a field name can never contain one of these
2248
characters except as a CPLUS_MARKER. */
2250
if ((*p == '$' || *p == '.') && p[1] != '_')
2253
if (! parse_stab_cpp_abbrev (dhandle, info, pp, fields + c))
2259
/* Look for the ':' that separates the field name from the field
2260
values. Data members are delimited by a single ':', while member
2261
functions are delimited by a pair of ':'s. When we hit the member
2262
functions (if any), terminate scan loop and return. */
2264
p = strchr (p, ':');
2274
if (! parse_stab_one_struct_field (dhandle, info, pp, p, fields + c,
2281
fields[c] = DEBUG_FIELD_NULL;
2288
/* Special GNU C++ name. */
2291
parse_stab_cpp_abbrev (dhandle, info, pp, retp)
2293
struct stab_handle *info;
2301
const char *typename;
2305
*retp = DEBUG_FIELD_NULL;
2319
/* At this point, *pp points to something like "22:23=*22...", where
2320
the type number before the ':' is the "context" and everything
2321
after is a regular type definition. Lookup the type, find it's
2322
name, and construct the field name. */
2324
context = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2325
(debug_type **) NULL);
2326
if (context == DEBUG_TYPE_NULL)
2332
/* $vf -- a virtual function table pointer. */
2336
/* $vb -- a virtual bsomethingorother */
2337
typename = debug_get_type_name (dhandle, context);
2338
if (typename == NULL)
2340
warn_stab (orig, "unnamed $vb type");
2343
name = concat ("_vb$", typename, (const char *) NULL);
2346
warn_stab (orig, "unrecognized C++ abbreviation");
2347
name = "INVALID_CPLUSPLUS_ABBREV";
2358
type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2359
(debug_type **) NULL);
2367
bitpos = parse_number (pp, (boolean *) NULL);
2375
*retp = debug_make_field (dhandle, name, type, bitpos, 0,
2376
DEBUG_VISIBILITY_PRIVATE);
2377
if (*retp == DEBUG_FIELD_NULL)
2383
/* Parse a single field in a struct or union. */
2386
parse_stab_one_struct_field (dhandle, info, pp, p, retp, staticsp)
2388
struct stab_handle *info;
2396
enum debug_visibility visibility;
2403
/* FIXME: gdb checks ARM_DEMANGLING here. */
2405
name = savestring (*pp, p - *pp);
2410
visibility = DEBUG_VISIBILITY_PUBLIC;
2417
visibility = DEBUG_VISIBILITY_PRIVATE;
2420
visibility = DEBUG_VISIBILITY_PROTECTED;
2423
visibility = DEBUG_VISIBILITY_PUBLIC;
2426
warn_stab (orig, "unknown visibility character for field");
2427
visibility = DEBUG_VISIBILITY_PUBLIC;
2433
type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2434
(debug_type **) NULL);
2435
if (type == DEBUG_TYPE_NULL)
2442
/* This is a static class member. */
2444
p = strchr (*pp, ';');
2451
varname = savestring (*pp, p - *pp);
2455
*retp = debug_make_static_member (dhandle, name, type, varname,
2469
bitpos = parse_number (pp, (boolean *) NULL);
2477
bitsize = parse_number (pp, (boolean *) NULL);
2485
if (bitpos == 0 && bitsize == 0)
2487
/* This can happen in two cases: (1) at least for gcc 2.4.5 or
2488
so, it is a field which has been optimized out. The correct
2489
stab for this case is to use VISIBILITY_IGNORE, but that is a
2490
recent invention. (2) It is a 0-size array. For example
2491
union { int num; char str[0]; } foo. Printing "<no value>"
2492
for str in "p foo" is OK, since foo.str (and thus foo.str[3])
2493
will continue to work, and a 0-size array as a whole doesn't
2494
have any contents to print.
2496
I suspect this probably could also happen with gcc -gstabs
2497
(not -gstabs+) for static fields, and perhaps other C++
2498
extensions. Hopefully few people use -gstabs with gdb, since
2499
it is intended for dbx compatibility. */
2500
visibility = DEBUG_VISIBILITY_IGNORE;
2503
/* FIXME: gdb does some stuff here to mark fields as unpacked. */
2505
*retp = debug_make_field (dhandle, name, type, bitpos, bitsize, visibility);
2510
/* Read member function stabs info for C++ classes. The form of each member
2513
NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2515
An example with two member functions is:
2517
afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2519
For the case of overloaded operators, the format is op$::*.funcs, where
2520
$ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2521
name (such as `+=') and `.' marks the end of the operator name. */
2524
parse_stab_members (dhandle, info, tagname, pp, typenums, retp)
2526
struct stab_handle *info;
2527
const char *tagname;
2529
const int *typenums;
2530
debug_method **retp;
2533
debug_method *methods;
2549
debug_method_variant *variants;
2551
unsigned int allocvars;
2552
debug_type look_ahead_type;
2554
p = strchr (*pp, ':');
2555
if (p == NULL || p[1] != ':')
2558
/* FIXME: Some systems use something other than '$' here. */
2559
if ((*pp)[0] != 'o' || (*pp)[1] != 'p' || (*pp)[2] != '$')
2561
name = savestring (*pp, p - *pp);
2566
/* This is a completely wierd case. In order to stuff in the
2567
names that might contain colons (the usual name delimiter),
2568
Mike Tiemann defined a different name format which is
2569
signalled if the identifier is "op$". In that case, the
2570
format is "op$::XXXX." where XXXX is the name. This is
2571
used for names like "+" or "=". YUUUUUUUK! FIXME! */
2573
for (p = *pp; *p != '.' && *p != '\0'; p++)
2580
name = savestring (*pp, p - *pp);
2585
variants = ((debug_method_variant *)
2586
xmalloc (allocvars * sizeof *variants));
2589
look_ahead_type = DEBUG_TYPE_NULL;
2596
enum debug_visibility visibility;
2597
boolean constp, volatilep, staticp;
2600
const char *physname;
2603
if (look_ahead_type != DEBUG_TYPE_NULL)
2605
/* g++ version 1 kludge */
2606
type = look_ahead_type;
2607
look_ahead_type = DEBUG_TYPE_NULL;
2611
type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2612
(debug_type **) NULL);
2613
if (type == DEBUG_TYPE_NULL)
2623
p = strchr (*pp, ';');
2631
if (debug_get_type_kind (dhandle, type) == DEBUG_KIND_METHOD
2632
&& debug_get_parameter_types (dhandle, type, &varargs) == NULL)
2635
argtypes = savestring (*pp, p - *pp);
2641
visibility = DEBUG_VISIBILITY_PRIVATE;
2644
visibility = DEBUG_VISIBILITY_PROTECTED;
2647
visibility = DEBUG_VISIBILITY_PUBLIC;
2657
/* Normal function. */
2661
/* const member function. */
2666
/* volatile member function. */
2671
/* const volatile member function. */
2679
/* File compiled with g++ version 1; no information. */
2682
warn_stab (orig, "const/volatile indicator missing");
2690
/* virtual member function, followed by index. The sign
2691
bit is supposedly set to distinguish
2692
pointers-to-methods from virtual function indicies. */
2694
voffset = parse_number (pp, (boolean *) NULL);
2701
voffset &= 0x7fffffff;
2703
if (**pp == ';' || *pp == '\0')
2705
/* Must be g++ version 1. */
2706
context = DEBUG_TYPE_NULL;
2710
/* Figure out from whence this virtual function
2711
came. It may belong to virtual function table of
2712
one of its baseclasses. */
2713
look_ahead_type = parse_stab_type (dhandle, info,
2714
(const char *) NULL,
2716
(debug_type **) NULL);
2719
/* g++ version 1 overloaded methods. */
2720
context = DEBUG_TYPE_NULL;
2724
context = look_ahead_type;
2725
look_ahead_type = DEBUG_TYPE_NULL;
2737
/* static member function. */
2741
context = DEBUG_TYPE_NULL;
2742
if (strncmp (argtypes, name, strlen (name)) != 0)
2747
warn_stab (orig, "member function type missing");
2749
context = DEBUG_TYPE_NULL;
2755
context = DEBUG_TYPE_NULL;
2759
/* If the type is not a stub, then the argtypes string is
2760
the physical name of the function. Otherwise the
2761
argtypes string is the mangled form of the argument
2762
types, and the full type and the physical name must be
2763
extracted from them. */
2765
physname = argtypes;
2768
debug_type class_type, return_type;
2770
class_type = stab_find_type (dhandle, info, typenums);
2771
if (class_type == DEBUG_TYPE_NULL)
2773
return_type = debug_get_return_type (dhandle, type);
2774
if (return_type == DEBUG_TYPE_NULL)
2779
type = parse_stab_argtypes (dhandle, info, class_type, name,
2780
tagname, return_type, argtypes,
2781
constp, volatilep, &physname);
2782
if (type == DEBUG_TYPE_NULL)
2786
if (cvars + 1 >= allocvars)
2789
variants = ((debug_method_variant *)
2790
xrealloc ((PTR) variants,
2791
allocvars * sizeof *variants));
2795
variants[cvars] = debug_make_method_variant (dhandle, physname,
2800
variants[cvars] = debug_make_static_method_variant (dhandle,
2806
if (variants[cvars] == DEBUG_METHOD_VARIANT_NULL)
2811
while (**pp != ';' && **pp != '\0');
2813
variants[cvars] = DEBUG_METHOD_VARIANT_NULL;
2821
methods = ((debug_method *)
2822
xrealloc ((PTR) methods, alloc * sizeof *methods));
2825
methods[c] = debug_make_method (dhandle, name, variants);
2830
if (methods != NULL)
2831
methods[c] = DEBUG_METHOD_NULL;
2838
/* Parse a string representing argument types for a method. Stabs
2839
tries to save space by packing argument types into a mangled
2840
string. This string should give us enough information to extract
2841
both argument types and the physical name of the function, given
2845
parse_stab_argtypes (dhandle, info, class_type, fieldname, tagname,
2846
return_type, argtypes, constp, volatilep, pphysname)
2848
struct stab_handle *info;
2849
debug_type class_type;
2850
const char *fieldname;
2851
const char *tagname;
2852
debug_type return_type;
2853
const char *argtypes;
2856
const char **pphysname;
2858
boolean is_full_physname_constructor;
2859
boolean is_constructor;
2860
boolean is_destructor;
2864
/* Constructors are sometimes handled specially. */
2865
is_full_physname_constructor = ((argtypes[0] == '_'
2866
&& argtypes[1] == '_'
2867
&& (isdigit ((unsigned char) argtypes[2])
2868
|| argtypes[2] == 'Q'
2869
|| argtypes[2] == 't'))
2870
|| strncmp (argtypes, "__ct", 4) == 0);
2872
is_constructor = (is_full_physname_constructor
2874
&& strcmp (fieldname, tagname) == 0));
2875
is_destructor = ((argtypes[0] == '_'
2876
&& (argtypes[1] == '$' || argtypes[1] == '.')
2877
&& argtypes[2] == '_')
2878
|| strncmp (argtypes, "__dt", 4) == 0);
2880
if (is_destructor || is_full_physname_constructor)
2881
*pphysname = argtypes;
2885
const char *const_prefix;
2886
const char *volatile_prefix;
2888
unsigned int mangled_name_len;
2891
len = tagname == NULL ? 0 : strlen (tagname);
2892
const_prefix = constp ? "C" : "";
2893
volatile_prefix = volatilep ? "V" : "";
2896
sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
2897
else if (tagname != NULL && strchr (tagname, '<') != NULL)
2899
/* Template methods are fully mangled. */
2900
sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
2905
sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
2907
mangled_name_len = ((is_constructor ? 0 : strlen (fieldname))
2913
if (fieldname[0] == 'o'
2914
&& fieldname[1] == 'p'
2915
&& (fieldname[2] == '$' || fieldname[2] == '.'))
2919
opname = cplus_mangle_opname (fieldname + 3, 0);
2922
fprintf (stderr, "No mangling for \"%s\"\n", fieldname);
2923
return DEBUG_TYPE_NULL;
2925
mangled_name_len += strlen (opname);
2926
physname = (char *) xmalloc (mangled_name_len);
2927
strncpy (physname, fieldname, 3);
2928
strcpy (physname + 3, opname);
2932
physname = (char *) xmalloc (mangled_name_len);
2936
strcpy (physname, fieldname);
2939
strcat (physname, buf);
2940
if (tagname != NULL)
2941
strcat (physname, tagname);
2942
strcat (physname, argtypes);
2944
*pphysname = physname;
2947
if (*argtypes == '\0' || is_destructor)
2949
args = (debug_type *) xmalloc (sizeof *args);
2951
return debug_make_method_type (dhandle, return_type, class_type, args,
2955
args = stab_demangle_argtypes (dhandle, info, *pphysname, &varargs);
2957
return DEBUG_TYPE_NULL;
2959
return debug_make_method_type (dhandle, return_type, class_type, args,
2963
/* The tail end of stabs for C++ classes that contain a virtual function
2964
pointer contains a tilde, a %, and a type number.
2965
The type number refers to the base class (possibly this class itself) which
2966
contains the vtable pointer for the current class.
2968
This function is called when we have parsed all the method declarations,
2969
so we can look for the vptr base class info. */
2972
parse_stab_tilde_field (dhandle, info, pp, typenums, retvptrbase, retownvptr)
2974
struct stab_handle *info;
2976
const int *typenums;
2977
debug_type *retvptrbase;
2978
boolean *retownvptr;
2984
*retvptrbase = DEBUG_TYPE_NULL;
2985
*retownvptr = false;
2989
/* If we are positioned at a ';', then skip it. */
2998
if (**pp == '=' || **pp == '+' || **pp == '-')
3000
/* Obsolete flags that used to indicate the presence of
3001
constructors and/or destructors. */
3012
/* The next number is the type number of the base class (possibly
3013
our own class) which supplies the vtable for this class. */
3014
if (! parse_stab_type_number (pp, vtypenums))
3017
if (vtypenums[0] == typenums[0]
3018
&& vtypenums[1] == typenums[1])
3027
vtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
3028
(debug_type **) NULL);
3029
for (p = *pp; *p != ';' && *p != '\0'; p++)
3037
*retvptrbase = vtype;
3045
/* Read a definition of an array type. */
3048
parse_stab_array_type (dhandle, info, pp, stringp)
3050
struct stab_handle *info;
3057
debug_type index_type;
3059
bfd_signed_vma lower, upper;
3060
debug_type element_type;
3062
/* Format of an array type:
3063
"ar<index type>;lower;upper;<array_contents_type>".
3064
OS9000: "arlower,upper;<array_contents_type>".
3066
Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3067
for these, produce a type like float[][]. */
3071
/* FIXME: gdb checks os9k_stabs here. */
3073
/* If the index type is type 0, we take it as int. */
3075
if (! parse_stab_type_number (&p, typenums))
3076
return DEBUG_TYPE_NULL;
3077
if (typenums[0] == 0 && typenums[1] == 0 && **pp != '=')
3079
index_type = debug_find_named_type (dhandle, "int");
3080
if (index_type == DEBUG_TYPE_NULL)
3082
index_type = debug_make_int_type (dhandle, 4, false);
3083
if (index_type == DEBUG_TYPE_NULL)
3084
return DEBUG_TYPE_NULL;
3090
index_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
3091
(debug_type **) NULL);
3097
return DEBUG_TYPE_NULL;
3103
if (! isdigit ((unsigned char) **pp) && **pp != '-')
3109
lower = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
3113
return DEBUG_TYPE_NULL;
3117
if (! isdigit ((unsigned char) **pp) && **pp != '-')
3123
upper = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
3127
return DEBUG_TYPE_NULL;
3131
element_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
3132
(debug_type **) NULL);
3133
if (element_type == DEBUG_TYPE_NULL)
3134
return DEBUG_TYPE_NULL;
3142
return debug_make_array_type (dhandle, element_type, index_type, lower,
3146
/* This struct holds information about files we have seen using
3151
/* The next N_BINCL file. */
3152
struct bincl_file *next;
3153
/* The next N_BINCL on the stack. */
3154
struct bincl_file *next_stack;
3155
/* The file name. */
3157
/* The hash value. */
3159
/* The file index. */
3161
/* The list of types defined in this file. */
3162
struct stab_types *file_types;
3165
/* Start a new N_BINCL file, pushing it onto the stack. */
3168
push_bincl (info, name, hash)
3169
struct stab_handle *info;
3173
struct bincl_file *n;
3175
n = (struct bincl_file *) xmalloc (sizeof *n);
3176
n->next = info->bincl_list;
3177
n->next_stack = info->bincl_stack;
3180
n->file = info->files;
3181
n->file_types = NULL;
3182
info->bincl_list = n;
3183
info->bincl_stack = n;
3186
info->file_types = ((struct stab_types **)
3187
xrealloc ((PTR) info->file_types,
3189
* sizeof *info->file_types)));
3190
info->file_types[n->file] = NULL;
3193
/* Finish an N_BINCL file, at an N_EINCL, popping the name off the
3198
struct stab_handle *info;
3200
struct bincl_file *o;
3202
o = info->bincl_stack;
3204
return info->main_filename;
3205
info->bincl_stack = o->next_stack;
3207
o->file_types = info->file_types[o->file];
3209
if (info->bincl_stack == NULL)
3210
return info->main_filename;
3211
return info->bincl_stack->name;
3214
/* Handle an N_EXCL: get the types from the corresponding N_BINCL. */
3217
find_excl (info, name, hash)
3218
struct stab_handle *info;
3222
struct bincl_file *l;
3225
info->file_types = ((struct stab_types **)
3226
xrealloc ((PTR) info->file_types,
3228
* sizeof *info->file_types)));
3230
for (l = info->bincl_list; l != NULL; l = l->next)
3231
if (l->hash == hash && strcmp (l->name, name) == 0)
3235
warn_stab (name, "Undefined N_EXCL");
3236
info->file_types[info->files - 1] = NULL;
3240
info->file_types[info->files - 1] = l->file_types;
3245
/* Handle a variable definition. gcc emits variable definitions for a
3246
block before the N_LBRAC, so we must hold onto them until we see
3247
it. The SunPRO compiler emits variable definitions after the
3248
N_LBRAC, so we can call debug_record_variable immediately. */
3251
stab_record_variable (dhandle, info, name, type, kind, val)
3253
struct stab_handle *info;
3256
enum debug_var_kind kind;
3259
struct stab_pending_var *v;
3261
if ((kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
3262
|| ! info->within_function
3263
|| (info->gcc_compiled == 0 && info->n_opt_found))
3264
return debug_record_variable (dhandle, name, type, kind, val);
3266
v = (struct stab_pending_var *) xmalloc (sizeof *v);
3267
memset (v, 0, sizeof *v);
3269
v->next = info->pending;
3279
/* Emit pending variable definitions. This is called after we see the
3280
N_LBRAC that starts the block. */
3283
stab_emit_pending_vars (dhandle, info)
3285
struct stab_handle *info;
3287
struct stab_pending_var *v;
3292
struct stab_pending_var *next;
3294
if (! debug_record_variable (dhandle, v->name, v->type, v->kind, v->val))
3302
info->pending = NULL;
3307
/* Find the slot for a type in the database. */
3310
stab_find_slot (info, typenums)
3311
struct stab_handle *info;
3312
const int *typenums;
3316
struct stab_types **ps;
3318
filenum = typenums[0];
3319
index = typenums[1];
3321
if (filenum < 0 || (unsigned int) filenum >= info->files)
3323
fprintf (stderr, "Type file number %d out of range\n", filenum);
3328
fprintf (stderr, "Type index number %d out of range\n", index);
3332
ps = info->file_types + filenum;
3334
while (index >= STAB_TYPES_SLOTS)
3338
*ps = (struct stab_types *) xmalloc (sizeof **ps);
3339
memset (*ps, 0, sizeof **ps);
3342
index -= STAB_TYPES_SLOTS;
3346
*ps = (struct stab_types *) xmalloc (sizeof **ps);
3347
memset (*ps, 0, sizeof **ps);
3350
return (*ps)->types + index;
3353
/* Find a type given a type number. If the type has not been
3354
allocated yet, create an indirect type. */
3357
stab_find_type (dhandle, info, typenums)
3359
struct stab_handle *info;
3360
const int *typenums;
3364
if (typenums[0] == 0 && typenums[1] < 0)
3366
/* A negative type number indicates an XCOFF builtin type. */
3367
return stab_xcoff_builtin_type (dhandle, info, typenums[1]);
3370
slot = stab_find_slot (info, typenums);
3372
return DEBUG_TYPE_NULL;
3374
if (*slot == DEBUG_TYPE_NULL)
3375
return debug_make_indirect_type (dhandle, slot, (const char *) NULL);
3380
/* Record that a given type number refers to a given type. */
3383
stab_record_type (dhandle, info, typenums, type)
3385
struct stab_handle *info;
3386
const int *typenums;
3391
slot = stab_find_slot (info, typenums);
3395
/* gdb appears to ignore type redefinitions, so we do as well. */
3402
/* Return an XCOFF builtin type. */
3405
stab_xcoff_builtin_type (dhandle, info, typenum)
3407
struct stab_handle *info;
3413
if (typenum >= 0 || typenum < -XCOFF_TYPE_COUNT)
3415
fprintf (stderr, "Unrecognized XCOFF type %d\n", typenum);
3416
return DEBUG_TYPE_NULL;
3418
if (info->xcoff_types[-typenum] != NULL)
3419
return info->xcoff_types[-typenum];
3424
/* The size of this and all the other types are fixed, defined
3425
by the debugging format. */
3427
rettype = debug_make_int_type (dhandle, 4, false);
3431
rettype = debug_make_int_type (dhandle, 1, false);
3435
rettype = debug_make_int_type (dhandle, 2, false);
3439
rettype = debug_make_int_type (dhandle, 4, false);
3442
name = "unsigned char";
3443
rettype = debug_make_int_type (dhandle, 1, true);
3446
name = "signed char";
3447
rettype = debug_make_int_type (dhandle, 1, false);
3450
name = "unsigned short";
3451
rettype = debug_make_int_type (dhandle, 2, true);
3454
name = "unsigned int";
3455
rettype = debug_make_int_type (dhandle, 4, true);
3459
rettype = debug_make_int_type (dhandle, 4, true);
3461
name = "unsigned long";
3462
rettype = debug_make_int_type (dhandle, 4, true);
3466
rettype = debug_make_void_type (dhandle);
3469
/* IEEE single precision (32 bit). */
3471
rettype = debug_make_float_type (dhandle, 4);
3474
/* IEEE double precision (64 bit). */
3476
rettype = debug_make_float_type (dhandle, 8);
3479
/* This is an IEEE double on the RS/6000, and different machines
3480
with different sizes for "long double" should use different
3481
negative type numbers. See stabs.texinfo. */
3482
name = "long double";
3483
rettype = debug_make_float_type (dhandle, 8);
3487
rettype = debug_make_int_type (dhandle, 4, false);
3491
rettype = debug_make_bool_type (dhandle, 4);
3494
name = "short real";
3495
rettype = debug_make_float_type (dhandle, 4);
3499
rettype = debug_make_float_type (dhandle, 8);
3509
rettype = debug_make_int_type (dhandle, 1, true);
3513
rettype = debug_make_bool_type (dhandle, 1);
3517
rettype = debug_make_bool_type (dhandle, 2);
3521
rettype = debug_make_bool_type (dhandle, 4);
3525
rettype = debug_make_bool_type (dhandle, 4);
3528
/* Complex type consisting of two IEEE single precision values. */
3530
rettype = debug_make_complex_type (dhandle, 8);
3533
/* Complex type consisting of two IEEE double precision values. */
3534
name = "double complex";
3535
rettype = debug_make_complex_type (dhandle, 16);
3539
rettype = debug_make_int_type (dhandle, 1, false);
3543
rettype = debug_make_int_type (dhandle, 2, false);
3547
rettype = debug_make_int_type (dhandle, 4, false);
3552
rettype = debug_make_int_type (dhandle, 2, false);
3556
rettype = debug_make_int_type (dhandle, 8, false);
3559
name = "unsigned long long";
3560
rettype = debug_make_int_type (dhandle, 8, true);
3564
rettype = debug_make_bool_type (dhandle, 8);
3568
rettype = debug_make_int_type (dhandle, 8, false);
3574
rettype = debug_name_type (dhandle, name, rettype);
3576
info->xcoff_types[-typenum] = rettype;
3581
/* Find or create a tagged type. */
3584
stab_find_tagged_type (dhandle, info, p, len, kind)
3586
struct stab_handle *info;
3589
enum debug_type_kind kind;
3593
struct stab_tag *st;
3595
name = savestring (p, len);
3597
/* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same
3598
namespace. This is right for C, and I don't know how to handle
3599
other languages. FIXME. */
3600
dtype = debug_find_tagged_type (dhandle, name, DEBUG_KIND_ILLEGAL);
3601
if (dtype != DEBUG_TYPE_NULL)
3607
/* We need to allocate an entry on the undefined tag list. */
3608
for (st = info->tags; st != NULL; st = st->next)
3610
if (st->name[0] == name[0]
3611
&& strcmp (st->name, name) == 0)
3613
if (st->kind == DEBUG_KIND_ILLEGAL)
3621
st = (struct stab_tag *) xmalloc (sizeof *st);
3622
memset (st, 0, sizeof *st);
3624
st->next = info->tags;
3627
st->slot = DEBUG_TYPE_NULL;
3628
st->type = debug_make_indirect_type (dhandle, &st->slot, name);
3635
/* In order to get the correct argument types for a stubbed method, we
3636
need to extract the argument types from a C++ mangled string.
3637
Since the argument types can refer back to the return type, this
3638
means that we must demangle the entire physical name. In gdb this
3639
is done by calling cplus_demangle and running the results back
3640
through the C++ expression parser. Since we have no expression
3641
parser, we must duplicate much of the work of cplus_demangle here.
3643
We assume that GNU style demangling is used, since this is only
3644
done for method stubs, and only g++ should output that form of
3645
debugging information. */
3647
/* This structure is used to hold a pointer to type information which
3648
demangling a string. */
3650
struct stab_demangle_typestring
3652
/* The start of the type. This is not null terminated. */
3653
const char *typestring;
3654
/* The length of the type. */
3658
/* This structure is used to hold information while demangling a
3661
struct stab_demangle_info
3663
/* The debugging information handle. */
3665
/* The stab information handle. */
3666
struct stab_handle *info;
3667
/* The array of arguments we are building. */
3669
/* Whether the method takes a variable number of arguments. */
3671
/* The array of types we have remembered. */
3672
struct stab_demangle_typestring *typestrings;
3673
/* The number of typestrings. */
3674
unsigned int typestring_count;
3675
/* The number of typestring slots we have allocated. */
3676
unsigned int typestring_alloc;
3679
static void stab_bad_demangle PARAMS ((const char *));
3680
static unsigned int stab_demangle_count PARAMS ((const char **));
3681
static boolean stab_demangle_get_count
3682
PARAMS ((const char **, unsigned int *));
3683
static boolean stab_demangle_prefix
3684
PARAMS ((struct stab_demangle_info *, const char **));
3685
static boolean stab_demangle_function_name
3686
PARAMS ((struct stab_demangle_info *, const char **, const char *));
3687
static boolean stab_demangle_signature
3688
PARAMS ((struct stab_demangle_info *, const char **));
3689
static boolean stab_demangle_qualified
3690
PARAMS ((struct stab_demangle_info *, const char **, debug_type *));
3691
static boolean stab_demangle_template
3692
PARAMS ((struct stab_demangle_info *, const char **));
3693
static boolean stab_demangle_class
3694
PARAMS ((struct stab_demangle_info *, const char **, const char **));
3695
static boolean stab_demangle_args
3696
PARAMS ((struct stab_demangle_info *, const char **, debug_type **,
3698
static boolean stab_demangle_arg
3699
PARAMS ((struct stab_demangle_info *, const char **, debug_type **,
3700
unsigned int *, unsigned int *));
3701
static boolean stab_demangle_type
3702
PARAMS ((struct stab_demangle_info *, const char **, debug_type *));
3703
static boolean stab_demangle_fund_type
3704
PARAMS ((struct stab_demangle_info *, const char **, debug_type *));
3705
static boolean stab_demangle_remember_type
3706
PARAMS ((struct stab_demangle_info *, const char *, int));
3708
/* Warn about a bad demangling. */
3711
stab_bad_demangle (s)
3714
fprintf (stderr, "bad mangled name `%s'\n", s);
3717
/* Get a count from a stab string. */
3720
stab_demangle_count (pp)
3726
while (isdigit ((unsigned char) **pp))
3729
count += **pp - '0';
3735
/* Require a count in a string. The count may be multiple digits, in
3736
which case it must end in an underscore. */
3739
stab_demangle_get_count (pp, pi)
3743
if (! isdigit ((unsigned char) **pp))
3748
if (isdigit ((unsigned char) **pp))
3761
while (isdigit ((unsigned char) *p));
3772
/* This function demangles a physical name, returning a NULL
3773
terminated array of argument types. */
3776
stab_demangle_argtypes (dhandle, info, physname, pvarargs)
3778
struct stab_handle *info;
3779
const char *physname;
3782
struct stab_demangle_info minfo;
3784
minfo.dhandle = dhandle;
3787
minfo.varargs = false;
3788
minfo.typestring_alloc = 10;
3789
minfo.typestrings = ((struct stab_demangle_typestring *)
3790
xmalloc (minfo.typestring_alloc
3791
* sizeof *minfo.typestrings));
3792
minfo.typestring_count = 0;
3794
/* cplus_demangle checks for special GNU mangled forms, but we can't
3795
see any of them in mangled method argument types. */
3797
if (! stab_demangle_prefix (&minfo, &physname))
3800
if (*physname != '\0')
3802
if (! stab_demangle_signature (&minfo, &physname))
3806
free (minfo.typestrings);
3807
minfo.typestrings = NULL;
3809
if (minfo.args == NULL)
3810
fprintf (stderr, "no argument types in mangled string\n");
3812
*pvarargs = minfo.varargs;
3816
if (minfo.typestrings != NULL)
3817
free (minfo.typestrings);
3821
/* Demangle the prefix of the mangled name. */
3824
stab_demangle_prefix (minfo, pp)
3825
struct stab_demangle_info *minfo;
3831
/* cplus_demangle checks for global constructors and destructors,
3832
but we can't see them in mangled argument types. */
3834
/* Look for `__'. */
3838
scan = strchr (scan, '_');
3840
while (scan != NULL && *++scan != '_');
3844
stab_bad_demangle (*pp);
3850
/* We found `__'; move ahead to the last contiguous `__' pair. */
3851
i = strspn (scan, "_");
3856
&& (isdigit ((unsigned char) scan[2])
3860
/* This is a GNU style constructor name. */
3864
else if (scan == *pp
3865
&& ! isdigit ((unsigned char) scan[2])
3868
/* Look for the `__' that separates the prefix from the
3870
while (*scan == '_')
3872
scan = strstr (scan, "__");
3873
if (scan == NULL || scan[2] == '\0')
3875
stab_bad_demangle (*pp);
3879
return stab_demangle_function_name (minfo, pp, scan);
3881
else if (scan[2] != '\0')
3883
/* The name doesn't start with `__', but it does contain `__'. */
3884
return stab_demangle_function_name (minfo, pp, scan);
3888
stab_bad_demangle (*pp);
3894
/* Demangle a function name prefix. The scan argument points to the
3895
double underscore which separates the function name from the
3899
stab_demangle_function_name (minfo, pp, scan)
3900
struct stab_demangle_info *minfo;
3906
/* The string from *pp to scan is the name of the function. We
3907
don't care about the name, since we just looking for argument
3908
types. However, for conversion operators, the name may include a
3909
type which we must remember in order to handle backreferences. */
3915
&& strncmp (name, "type", 4) == 0
3916
&& (name[4] == '$' || name[4] == '.'))
3920
/* This is a type conversion operator. */
3922
if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
3925
else if (name[0] == '_'
3932
/* This is a type conversion operator. */
3934
if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
3941
/* Demangle the signature. This is where the argument types are
3945
stab_demangle_signature (minfo, pp)
3946
struct stab_demangle_info *minfo;
3950
boolean expect_func, func_done;
3955
expect_func = false;
3959
while (**pp != '\0')
3965
if (! stab_demangle_qualified (minfo, pp, (debug_type *) NULL)
3966
|| ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3973
/* Static member function. FIXME: Can this happen? */
3980
/* Const member function. */
3986
case '0': case '1': case '2': case '3': case '4':
3987
case '5': case '6': case '7': case '8': case '9':
3990
if (! stab_demangle_class (minfo, pp, (const char **) NULL)
3991
|| ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3998
/* Function. I don't know if this actually happens with g++
4003
if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
4011
if (! stab_demangle_template (minfo, pp)
4012
|| ! stab_demangle_remember_type (minfo, hold, *pp - hold))
4019
/* At the outermost level, we cannot have a return type
4020
specified, so if we run into another '_' at this point we
4021
are dealing with a mangled name that is either bogus, or
4022
has been mangled by some algorithm we don't know how to
4023
deal with. So just reject the entire demangling. */
4024
stab_bad_demangle (orig);
4028
/* Assume we have stumbled onto the first outermost function
4029
argument token, and start processing args. */
4031
if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
4039
if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
4046
/* With GNU style demangling, bar__3foo is 'foo::bar(void)', and
4047
bar__3fooi is 'foo::bar(int)'. We get here when we find the
4048
first case, and need to ensure that the '(void)' gets added
4049
to the current declp. */
4050
if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
4057
/* Demangle a qualified name, such as "Q25Outer5Inner" which is the
4058
mangled form of "Outer::Inner". */
4061
stab_demangle_qualified (minfo, pp, ptype)
4062
struct stab_demangle_info *minfo;
4068
unsigned int qualifiers;
4076
/* GNU mangled name with more than 9 classes. The count is
4077
preceded by an underscore (to distinguish it from the <= 9
4078
case) and followed by an underscore. */
4080
if (! isdigit ((unsigned char) *p) || *p == '0')
4082
stab_bad_demangle (orig);
4085
qualifiers = atoi (p);
4086
while (isdigit ((unsigned char) *p))
4090
stab_bad_demangle (orig);
4096
case '1': case '2': case '3': case '4': case '5':
4097
case '6': case '7': case '8': case '9':
4098
qualifiers = (*pp)[1] - '0';
4099
/* Skip an optional underscore after the count. */
4100
if ((*pp)[2] == '_')
4107
stab_bad_demangle (orig);
4111
context = DEBUG_TYPE_NULL;
4113
/* Pick off the names. */
4114
while (qualifiers-- > 0)
4120
/* FIXME: I don't know how to handle the ptype != NULL case
4122
if (! stab_demangle_template (minfo, pp))
4129
len = stab_demangle_count (pp);
4130
if (strlen (*pp) < len)
4132
stab_bad_demangle (orig);
4138
const debug_field *fields;
4141
if (context != DEBUG_TYPE_NULL)
4142
fields = debug_get_fields (minfo->dhandle, context);
4144
context = DEBUG_TYPE_NULL;
4150
/* Try to find the type by looking through the
4151
fields of context until we find a field with the
4152
same type. This ought to work for a class
4153
defined within a class, but it won't work for,
4154
e.g., an enum defined within a class. stabs does
4155
not give us enough information to figure out the
4158
name = savestring (*pp, len);
4160
for (; *fields != DEBUG_FIELD_NULL; fields++)
4165
ft = debug_get_field_type (minfo->dhandle, *fields);
4168
dn = debug_get_type_name (minfo->dhandle, ft);
4169
if (dn != NULL && strcmp (dn, name) == 0)
4179
if (context == DEBUG_TYPE_NULL)
4181
/* We have to fall back on finding the type by name.
4182
If there are more types to come, then this must
4183
be a class. Otherwise, it could be anything. */
4185
if (qualifiers == 0)
4189
name = savestring (*pp, len);
4190
context = debug_find_named_type (minfo->dhandle,
4195
if (context == DEBUG_TYPE_NULL)
4197
context = stab_find_tagged_type (minfo->dhandle,
4201
? DEBUG_KIND_ILLEGAL
4202
: DEBUG_KIND_CLASS));
4203
if (context == DEBUG_TYPE_NULL)
4219
/* Demangle a template. */
4222
stab_demangle_template (minfo, pp)
4223
struct stab_demangle_info *minfo;
4233
/* Skip the template name. */
4234
r = stab_demangle_count (pp);
4235
if (r == 0 || strlen (*pp) < r)
4237
stab_bad_demangle (orig);
4242
/* Get the size of the parameter list. */
4243
if (stab_demangle_get_count (pp, &r) == 0)
4245
stab_bad_demangle (orig);
4249
for (i = 0; i < r; i++)
4253
/* This is a type parameter. */
4255
if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
4261
boolean pointerp, realp, integralp, charp, boolp;
4272
/* This is a value parameter. */
4274
if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
4277
while (*old_p != '\0' && ! done)
4287
case 'C': /* Const. */
4288
case 'S': /* Signed. */
4289
case 'U': /* Unsigned. */
4290
case 'V': /* Volatile. */
4291
case 'F': /* Function. */
4292
case 'M': /* Member function. */
4296
case 'Q': /* Qualified name. */
4300
case 'T': /* Remembered type. */
4302
case 'v': /* Void. */
4304
case 'x': /* Long long. */
4305
case 'l': /* Long. */
4306
case 'i': /* Int. */
4307
case 's': /* Short. */
4308
case 'w': /* Wchar_t. */
4312
case 'b': /* Bool. */
4316
case 'c': /* Char. */
4320
case 'r': /* Long double. */
4321
case 'd': /* Double. */
4322
case 'f': /* Float. */
4327
/* Assume it's a user defined integral type. */
4338
while (isdigit ((unsigned char) **pp))
4347
val = stab_demangle_count (pp);
4350
stab_bad_demangle (orig);
4358
val = stab_demangle_count (pp);
4359
if (val != 0 && val != 1)
4361
stab_bad_demangle (orig);
4369
while (isdigit ((unsigned char) **pp))
4374
while (isdigit ((unsigned char) **pp))
4380
while (isdigit ((unsigned char) **pp))
4388
if (! stab_demangle_get_count (pp, &len))
4390
stab_bad_demangle (orig);
4401
/* Demangle a class name. */
4404
stab_demangle_class (minfo, pp, pstart)
4405
struct stab_demangle_info *minfo;
4407
const char **pstart;
4414
n = stab_demangle_count (pp);
4415
if (strlen (*pp) < n)
4417
stab_bad_demangle (orig);
4429
/* Demangle function arguments. If the pargs argument is not NULL, it
4430
is set to a NULL terminated array holding the arguments. */
4433
stab_demangle_args (minfo, pp, pargs, pvarargs)
4434
struct stab_demangle_info *minfo;
4440
unsigned int alloc, count;
4447
*pargs = (debug_type *) xmalloc (alloc * sizeof **pargs);
4452
while (**pp != '_' && **pp != '\0' && **pp != 'e')
4454
if (**pp == 'N' || **pp == 'T')
4462
if (temptype == 'T')
4466
if (! stab_demangle_get_count (pp, &r))
4468
stab_bad_demangle (orig);
4473
if (! stab_demangle_get_count (pp, &t))
4475
stab_bad_demangle (orig);
4479
if (t >= minfo->typestring_count)
4481
stab_bad_demangle (orig);
4488
tem = minfo->typestrings[t].typestring;
4489
if (! stab_demangle_arg (minfo, &tem, pargs, &count, &alloc))
4495
if (! stab_demangle_arg (minfo, pp, pargs, &count, &alloc))
4501
(*pargs)[count] = DEBUG_TYPE_NULL;
4513
/* Demangle a single argument. */
4516
stab_demangle_arg (minfo, pp, pargs, pcount, palloc)
4517
struct stab_demangle_info *minfo;
4520
unsigned int *pcount;
4521
unsigned int *palloc;
4527
if (! stab_demangle_type (minfo, pp,
4528
pargs == NULL ? (debug_type *) NULL : &type)
4529
|| ! stab_demangle_remember_type (minfo, start, *pp - start))
4534
if (type == DEBUG_TYPE_NULL)
4537
if (*pcount + 1 >= *palloc)
4540
*pargs = ((debug_type *)
4541
xrealloc (*pargs, *palloc * sizeof **pargs));
4543
(*pargs)[*pcount] = type;
4550
/* Demangle a type. If the ptype argument is not NULL, *ptype is set
4551
to the newly allocated type. */
4554
stab_demangle_type (minfo, pp, ptype)
4555
struct stab_demangle_info *minfo;
4567
/* A pointer type. */
4569
if (! stab_demangle_type (minfo, pp, ptype))
4572
*ptype = debug_make_pointer_type (minfo->dhandle, *ptype);
4576
/* A reference type. */
4578
if (! stab_demangle_type (minfo, pp, ptype))
4581
*ptype = debug_make_reference_type (minfo->dhandle, *ptype);
4591
while (**pp != '\0' && **pp != '_')
4593
if (! isdigit ((unsigned char) **pp))
4595
stab_bad_demangle (orig);
4604
stab_bad_demangle (orig);
4609
if (! stab_demangle_type (minfo, pp, ptype))
4613
debug_type int_type;
4615
int_type = debug_find_named_type (minfo->dhandle, "int");
4616
if (int_type == NULL)
4617
int_type = debug_make_int_type (minfo->dhandle, 4, false);
4618
*ptype = debug_make_array_type (minfo->dhandle, *ptype, int_type,
4625
/* A back reference to a remembered type. */
4631
if (! stab_demangle_get_count (pp, &i))
4633
stab_bad_demangle (orig);
4636
if (i >= minfo->typestring_count)
4638
stab_bad_demangle (orig);
4641
p = minfo->typestrings[i].typestring;
4642
if (! stab_demangle_type (minfo, &p, ptype))
4654
if (! stab_demangle_args (minfo, pp,
4656
? (debug_type **) NULL
4664
/* cplus_demangle will accept a function without a return
4665
type, but I don't know when that will happen, or what
4666
to do if it does. */
4667
stab_bad_demangle (orig);
4671
if (! stab_demangle_type (minfo, pp, ptype))
4674
*ptype = debug_make_function_type (minfo->dhandle, *ptype, args,
4683
boolean memberp, constp, volatilep;
4689
memberp = **pp == 'M';
4696
if (! isdigit ((unsigned char) **pp))
4698
stab_bad_demangle (orig);
4701
n = stab_demangle_count (pp);
4702
if (strlen (*pp) < n)
4704
stab_bad_demangle (orig);
4717
else if (**pp == 'V')
4724
stab_bad_demangle (orig);
4728
if (! stab_demangle_args (minfo, pp,
4730
? (debug_type **) NULL
4740
stab_bad_demangle (orig);
4745
if (! stab_demangle_type (minfo, pp, ptype))
4750
debug_type class_type;
4752
class_type = stab_find_tagged_type (minfo->dhandle, minfo->info,
4755
if (class_type == DEBUG_TYPE_NULL)
4759
*ptype = debug_make_offset_type (minfo->dhandle, class_type,
4763
/* FIXME: We have no way to record constp or
4765
*ptype = debug_make_method_type (minfo->dhandle, *ptype,
4766
class_type, args, varargs);
4774
if (! stab_demangle_type (minfo, pp, ptype))
4780
if (! stab_demangle_type (minfo, pp, ptype))
4783
*ptype = debug_make_const_type (minfo->dhandle, *ptype);
4791
if (! stab_demangle_qualified (minfo, pp, ptype))
4797
if (! stab_demangle_fund_type (minfo, pp, ptype))
4805
/* Demangle a fundamental type. If the ptype argument is not NULL,
4806
*ptype is set to the newly allocated type. */
4809
stab_demangle_fund_type (minfo, pp, ptype)
4810
struct stab_demangle_info *minfo;
4815
boolean constp, volatilep, unsignedp, signedp;
4860
/* cplus_demangle permits this, but I don't know what it means. */
4861
stab_bad_demangle (orig);
4864
case 'v': /* void */
4867
*ptype = debug_find_named_type (minfo->dhandle, "void");
4868
if (*ptype == DEBUG_TYPE_NULL)
4869
*ptype = debug_make_void_type (minfo->dhandle);
4874
case 'x': /* long long */
4877
*ptype = debug_find_named_type (minfo->dhandle,
4879
? "long long unsigned int"
4880
: "long long int"));
4881
if (*ptype == DEBUG_TYPE_NULL)
4882
*ptype = debug_make_int_type (minfo->dhandle, 8, unsignedp);
4887
case 'l': /* long */
4890
*ptype = debug_find_named_type (minfo->dhandle,
4892
? "long unsigned int"
4894
if (*ptype == DEBUG_TYPE_NULL)
4895
*ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
4903
*ptype = debug_find_named_type (minfo->dhandle,
4907
if (*ptype == DEBUG_TYPE_NULL)
4908
*ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
4913
case 's': /* short */
4916
*ptype = debug_find_named_type (minfo->dhandle,
4918
? "short unsigned int"
4920
if (*ptype == DEBUG_TYPE_NULL)
4921
*ptype = debug_make_int_type (minfo->dhandle, 2, unsignedp);
4926
case 'b': /* bool */
4929
*ptype = debug_find_named_type (minfo->dhandle, "bool");
4930
if (*ptype == DEBUG_TYPE_NULL)
4931
*ptype = debug_make_bool_type (minfo->dhandle, 4);
4936
case 'c': /* char */
4939
*ptype = debug_find_named_type (minfo->dhandle,
4945
if (*ptype == DEBUG_TYPE_NULL)
4946
*ptype = debug_make_int_type (minfo->dhandle, 1, unsignedp);
4951
case 'w': /* wchar_t */
4954
*ptype = debug_find_named_type (minfo->dhandle, "__wchar_t");
4955
if (*ptype == DEBUG_TYPE_NULL)
4956
*ptype = debug_make_int_type (minfo->dhandle, 2, true);
4961
case 'r': /* long double */
4964
*ptype = debug_find_named_type (minfo->dhandle, "long double");
4965
if (*ptype == DEBUG_TYPE_NULL)
4966
*ptype = debug_make_float_type (minfo->dhandle, 8);
4971
case 'd': /* double */
4974
*ptype = debug_find_named_type (minfo->dhandle, "double");
4975
if (*ptype == DEBUG_TYPE_NULL)
4976
*ptype = debug_make_float_type (minfo->dhandle, 8);
4981
case 'f': /* float */
4984
*ptype = debug_find_named_type (minfo->dhandle, "float");
4985
if (*ptype == DEBUG_TYPE_NULL)
4986
*ptype = debug_make_float_type (minfo->dhandle, 4);
4993
if (! isdigit ((unsigned char) **pp))
4995
stab_bad_demangle (orig);
4999
case '0': case '1': case '2': case '3': case '4':
5000
case '5': case '6': case '7': case '8': case '9':
5004
if (! stab_demangle_class (minfo, pp, &hold))
5010
name = savestring (hold, *pp - hold);
5011
*ptype = debug_find_named_type (minfo->dhandle, name);
5012
if (*ptype == DEBUG_TYPE_NULL)
5014
/* FIXME: It is probably incorrect to assume that
5015
undefined types are tagged types. */
5016
*ptype = stab_find_tagged_type (minfo->dhandle, minfo->info,
5018
DEBUG_KIND_ILLEGAL);
5026
if (! stab_demangle_template (minfo, pp))
5032
/* FIXME: I really don't know how a template should be
5033
represented in the current type system. Perhaps the
5034
template should be demangled into a string, and the type
5035
should be represented as a named type. However, I don't
5036
know what the base type of the named type should be. */
5037
t = debug_make_void_type (minfo->dhandle);
5038
t = debug_make_pointer_type (minfo->dhandle, t);
5039
t = debug_name_type (minfo->dhandle, "TEMPLATE", t);
5045
stab_bad_demangle (orig);
5052
*ptype = debug_make_const_type (minfo->dhandle, *ptype);
5054
*ptype = debug_make_volatile_type (minfo->dhandle, *ptype);
5060
/* Remember a type string in a demangled string. */
5063
stab_demangle_remember_type (minfo, p, len)
5064
struct stab_demangle_info *minfo;
5068
if (minfo->typestring_count >= minfo->typestring_alloc)
5070
minfo->typestring_alloc += 10;
5071
minfo->typestrings = ((struct stab_demangle_typestring *)
5072
xrealloc (minfo->typestrings,
5073
(minfo->typestring_alloc
5074
* sizeof *minfo->typestrings)));
5077
minfo->typestrings[minfo->typestring_count].typestring = p;
5078
minfo->typestrings[minfo->typestring_count].len = (unsigned int) len;
5079
++minfo->typestring_count;