00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <stdio.h>
00028 #include <ctype.h>
00029
00030 #include <bfd.h>
00031 #include "bucomm.h"
00032 #include <libiberty.h>
00033 #include "demangle.h"
00034 #include "debug.h"
00035 #include "budbg.h"
00036
00037
00038 #define BYTES_IN_WORD 4
00039
00040 #include "aout/aout64.h"
00041 #include "aout/stab_gnu.h"
00042
00043
00044
00045 #define XCOFF_TYPE_COUNT 34
00046
00047
00048
00049
00050 struct stab_handle
00051 {
00052
00053 bfd *abfd;
00054
00055 boolean sections;
00056
00057 asymbol **syms;
00058
00059 long symcount;
00060
00061 char *so_string;
00062
00063 bfd_vma so_value;
00064
00065
00066 bfd_vma file_start_offset;
00067
00068
00069 bfd_vma function_start_offset;
00070
00071
00072 int gcc_compiled;
00073
00074
00075 boolean n_opt_found;
00076
00077 char *main_filename;
00078
00079 struct bincl_file *bincl_stack;
00080
00081 struct bincl_file *bincl_list;
00082
00083 boolean within_function;
00084
00085
00086
00087 bfd_vma function_end;
00088
00089 int block_depth;
00090
00091 struct stab_pending_var *pending;
00092
00093 unsigned int files;
00094
00095 struct stab_types **file_types;
00096
00097 debug_type xcoff_types[XCOFF_TYPE_COUNT];
00098
00099 struct stab_tag *tags;
00100 };
00101
00102
00103
00104
00105 struct stab_pending_var
00106 {
00107
00108 struct stab_pending_var *next;
00109
00110 const char *name;
00111
00112 debug_type type;
00113
00114 enum debug_var_kind kind;
00115
00116 bfd_vma val;
00117 };
00118
00119
00120
00121
00122 struct stab_types
00123 {
00124
00125 struct stab_types *next;
00126
00127 #define STAB_TYPES_SLOTS (16)
00128 debug_type types[STAB_TYPES_SLOTS];
00129 };
00130
00131
00132
00133
00134 struct stab_tag
00135 {
00136
00137 struct stab_tag *next;
00138
00139 const char *name;
00140
00141 enum debug_type_kind kind;
00142
00143
00144 debug_type slot;
00145
00146 debug_type type;
00147 };
00148
00149 static char *savestring PARAMS ((const char *, int));
00150 static bfd_vma parse_number PARAMS ((const char **, boolean *));
00151 static void bad_stab PARAMS ((const char *));
00152 static void warn_stab PARAMS ((const char *, const char *));
00153 static boolean parse_stab_string
00154 PARAMS ((PTR, struct stab_handle *, int, int, bfd_vma, const char *));
00155 static debug_type parse_stab_type
00156 PARAMS ((PTR, struct stab_handle *, const char *, const char **,
00157 debug_type **));
00158 static boolean parse_stab_type_number
00159 PARAMS ((const char **, int *));
00160 static debug_type parse_stab_range_type
00161 PARAMS ((PTR, struct stab_handle *, const char *, const char **,
00162 const int *));
00163 static debug_type parse_stab_sun_builtin_type PARAMS ((PTR, const char **));
00164 static debug_type parse_stab_sun_floating_type
00165 PARAMS ((PTR, const char **));
00166 static debug_type parse_stab_enum_type PARAMS ((PTR, const char **));
00167 static debug_type parse_stab_struct_type
00168 PARAMS ((PTR, struct stab_handle *, const char *, const char **, boolean,
00169 const int *));
00170 static boolean parse_stab_baseclasses
00171 PARAMS ((PTR, struct stab_handle *, const char **, debug_baseclass **));
00172 static boolean parse_stab_struct_fields
00173 PARAMS ((PTR, struct stab_handle *, const char **, debug_field **,
00174 boolean *));
00175 static boolean parse_stab_cpp_abbrev
00176 PARAMS ((PTR, struct stab_handle *, const char **, debug_field *));
00177 static boolean parse_stab_one_struct_field
00178 PARAMS ((PTR, struct stab_handle *, const char **, const char *,
00179 debug_field *, boolean *));
00180 static boolean parse_stab_members
00181 PARAMS ((PTR, struct stab_handle *, const char *, const char **,
00182 const int *, debug_method **));
00183 static debug_type parse_stab_argtypes
00184 PARAMS ((PTR, struct stab_handle *, debug_type, const char *, const char *,
00185 debug_type, const char *, boolean, boolean, const char **));
00186 static boolean parse_stab_tilde_field
00187 PARAMS ((PTR, struct stab_handle *, const char **, const int *,
00188 debug_type *, boolean *));
00189 static debug_type parse_stab_array_type
00190 PARAMS ((PTR, struct stab_handle *, const char **, boolean));
00191 static void push_bincl PARAMS ((struct stab_handle *, const char *, bfd_vma));
00192 static const char *pop_bincl PARAMS ((struct stab_handle *));
00193 static boolean find_excl
00194 PARAMS ((struct stab_handle *, const char *, bfd_vma));
00195 static boolean stab_record_variable
00196 PARAMS ((PTR, struct stab_handle *, const char *, debug_type,
00197 enum debug_var_kind, bfd_vma));
00198 static boolean stab_emit_pending_vars PARAMS ((PTR, struct stab_handle *));
00199 static debug_type *stab_find_slot
00200 PARAMS ((struct stab_handle *, const int *));
00201 static debug_type stab_find_type
00202 PARAMS ((PTR, struct stab_handle *, const int *));
00203 static boolean stab_record_type
00204 PARAMS ((PTR, struct stab_handle *, const int *, debug_type));
00205 static debug_type stab_xcoff_builtin_type
00206 PARAMS ((PTR, struct stab_handle *, int));
00207 static debug_type stab_find_tagged_type
00208 PARAMS ((PTR, struct stab_handle *, const char *, int,
00209 enum debug_type_kind));
00210 static debug_type *stab_demangle_argtypes
00211 PARAMS ((PTR, struct stab_handle *, const char *, boolean *));
00212
00213
00214
00215 static char *
00216 savestring (start, len)
00217 const char *start;
00218 int len;
00219 {
00220 char *ret;
00221
00222 ret = (char *) xmalloc (len + 1);
00223 memcpy (ret, start, len);
00224 ret[len] = '\0';
00225 return ret;
00226 }
00227
00228
00229
00230 static bfd_vma
00231 parse_number (pp, poverflow)
00232 const char **pp;
00233 boolean *poverflow;
00234 {
00235 unsigned long ul;
00236 const char *orig;
00237
00238 if (poverflow != NULL)
00239 *poverflow = false;
00240
00241 orig = *pp;
00242
00243 errno = 0;
00244 ul = strtoul (*pp, (char **) pp, 0);
00245 if (ul + 1 != 0 || errno == 0)
00246 return (bfd_vma) ul;
00247
00248
00249
00250
00251 if (sizeof (bfd_vma) > sizeof (unsigned long))
00252 {
00253 const char *p;
00254 boolean neg;
00255 int base;
00256 bfd_vma over, lastdig;
00257 boolean overflow;
00258 bfd_vma v;
00259
00260
00261
00262 p = orig;
00263
00264 neg = false;
00265 if (*p == '+')
00266 ++p;
00267 else if (*p == '-')
00268 {
00269 neg = true;
00270 ++p;
00271 }
00272
00273 base = 10;
00274 if (*p == '0')
00275 {
00276 if (p[1] == 'x' || p[1] == 'X')
00277 {
00278 base = 16;
00279 p += 2;
00280 }
00281 else
00282 {
00283 base = 8;
00284 ++p;
00285 }
00286 }
00287
00288 over = ((bfd_vma) (bfd_signed_vma) -1) / (bfd_vma) base;
00289 lastdig = ((bfd_vma) (bfd_signed_vma) -1) % (bfd_vma) base;
00290
00291 overflow = false;
00292 v = 0;
00293 while (1)
00294 {
00295 int d;
00296
00297 d = *p++;
00298 if (isdigit ((unsigned char) d))
00299 d -= '0';
00300 else if (isupper ((unsigned char) d))
00301 d -= 'A';
00302 else if (islower ((unsigned char) d))
00303 d -= 'a';
00304 else
00305 break;
00306
00307 if (d >= base)
00308 break;
00309
00310 if (v > over || (v == over && (bfd_vma) d > lastdig))
00311 {
00312 overflow = true;
00313 break;
00314 }
00315 }
00316
00317 if (! overflow)
00318 {
00319 if (neg)
00320 v = - v;
00321 return v;
00322 }
00323 }
00324
00325
00326
00327
00328 if (poverflow != NULL)
00329 *poverflow = true;
00330 else
00331 warn_stab (orig, "numeric overflow");
00332
00333 return 0;
00334 }
00335
00336
00337
00338 static void
00339 bad_stab (p)
00340 const char *p;
00341 {
00342 fprintf (stderr, "Bad stab: %s\n", p);
00343 }
00344
00345
00346
00347 static void
00348 warn_stab (p, err)
00349 const char *p;
00350 const char *err;
00351 {
00352 fprintf (stderr, "Warning: %s: %s\n", err, p);
00353 }
00354
00355
00356
00357
00358 PTR
00359 start_stab (dhandle, abfd, sections, syms, symcount)
00360 PTR dhandle;
00361 bfd *abfd;
00362 boolean sections;
00363 asymbol **syms;
00364 long symcount;
00365 {
00366 struct stab_handle *ret;
00367
00368 ret = (struct stab_handle *) xmalloc (sizeof *ret);
00369 memset (ret, 0, sizeof *ret);
00370 ret->abfd = abfd;
00371 ret->sections = sections;
00372 ret->syms = syms;
00373 ret->symcount = symcount;
00374 ret->files = 1;
00375 ret->file_types = (struct stab_types **) xmalloc (sizeof *ret->file_types);
00376 ret->file_types[0] = NULL;
00377 ret->function_end = (bfd_vma) -1;
00378 return (PTR) ret;
00379 }
00380
00381
00382
00383
00384 boolean
00385 finish_stab (dhandle, handle)
00386 PTR dhandle;
00387 PTR handle;
00388 {
00389 struct stab_handle *info = (struct stab_handle *) handle;
00390 struct stab_tag *st;
00391
00392 if (info->within_function)
00393 {
00394 if (! stab_emit_pending_vars (dhandle, info)
00395 || ! debug_end_function (dhandle, info->function_end))
00396 return false;
00397 info->within_function = false;
00398 info->function_end = (bfd_vma) -1;
00399 }
00400
00401 for (st = info->tags; st != NULL; st = st->next)
00402 {
00403 enum debug_type_kind kind;
00404
00405 kind = st->kind;
00406 if (kind == DEBUG_KIND_ILLEGAL)
00407 kind = DEBUG_KIND_STRUCT;
00408 st->slot = debug_make_undefined_tagged_type (dhandle, st->name, kind);
00409 if (st->slot == DEBUG_TYPE_NULL)
00410 return false;
00411 }
00412
00413 return true;
00414 }
00415
00416
00417
00418 boolean
00419 parse_stab (dhandle, handle, type, desc, value, string)
00420 PTR dhandle;
00421 PTR handle;
00422 int type;
00423 int desc;
00424 bfd_vma value;
00425 const char *string;
00426 {
00427 struct stab_handle *info = (struct stab_handle *) handle;
00428
00429
00430
00431
00432
00433 if (info->so_string != NULL
00434 && (type != N_SO || *string == '\0' || value != info->so_value))
00435 {
00436 if (! debug_set_filename (dhandle, info->so_string))
00437 return false;
00438 info->main_filename = info->so_string;
00439
00440 info->gcc_compiled = 0;
00441 info->n_opt_found = false;
00442
00443
00444
00445 if (! info->sections)
00446 info->file_start_offset = info->so_value;
00447
00448
00449
00450
00451 info->files = 1;
00452 info->file_types = ((struct stab_types **)
00453 xmalloc (sizeof *info->file_types));
00454 info->file_types[0] = NULL;
00455
00456 info->so_string = NULL;
00457
00458
00459 }
00460
00461 switch (type)
00462 {
00463 case N_FN:
00464 case N_FN_SEQ:
00465 break;
00466
00467 case N_LBRAC:
00468
00469 if (info->n_opt_found && desc == 1)
00470 break;
00471
00472 if (! info->within_function)
00473 {
00474 fprintf (stderr, "N_LBRAC not within function\n");
00475 return false;
00476 }
00477
00478
00479 if (! debug_start_block (dhandle,
00480 (value
00481 + info->file_start_offset
00482 + info->function_start_offset)))
00483 return false;
00484
00485
00486 if (! stab_emit_pending_vars (dhandle, info))
00487 return false;
00488
00489 ++info->block_depth;
00490 break;
00491
00492 case N_RBRAC:
00493
00494 if (info->n_opt_found && desc == 1)
00495 break;
00496
00497
00498
00499
00500 if (! stab_emit_pending_vars (dhandle, info))
00501 return false;
00502
00503
00504 if (! debug_end_block (dhandle,
00505 (value
00506 + info->file_start_offset
00507 + info->function_start_offset)))
00508 return false;
00509
00510 --info->block_depth;
00511 if (info->block_depth < 0)
00512 {
00513 fprintf (stderr, "Too many N_RBRACs\n");
00514 return false;
00515 }
00516 break;
00517
00518 case N_SO:
00519
00520 if (info->within_function)
00521 {
00522 bfd_vma endval;
00523
00524 endval = value;
00525 if (*string != '\0'
00526 && info->function_end != (bfd_vma) -1
00527 && info->function_end < endval)
00528 endval = info->function_end;
00529 if (! stab_emit_pending_vars (dhandle, info)
00530 || ! debug_end_function (dhandle, endval))
00531 return false;
00532 info->within_function = false;
00533 info->function_end = (bfd_vma) -1;
00534 }
00535
00536
00537
00538 if (*string == '\0')
00539 return true;
00540
00541
00542
00543
00544 if (info->so_string == NULL)
00545 info->so_string = xstrdup (string);
00546 else
00547 {
00548 char *f;
00549
00550 f = info->so_string;
00551 if (*string == '/')
00552 info->so_string = xstrdup (string);
00553 else
00554 info->so_string = concat (info->so_string, string,
00555 (const char *) NULL);
00556 free (f);
00557 }
00558
00559 info->so_value = value;
00560
00561 break;
00562
00563 case N_SOL:
00564
00565 if (! debug_start_source (dhandle, string))
00566 return false;
00567 break;
00568
00569 case N_BINCL:
00570
00571 push_bincl (info, string, value);
00572 if (! debug_start_source (dhandle, string))
00573 return false;
00574 break;
00575
00576 case N_EINCL:
00577
00578 if (! debug_start_source (dhandle, pop_bincl (info)))
00579 return false;
00580 break;
00581
00582 case N_EXCL:
00583
00584
00585 if (! find_excl (info, string, value))
00586 return false;
00587 break;
00588
00589 case N_SLINE:
00590 if (! debug_record_line (dhandle, desc,
00591 value + info->function_start_offset))
00592 return false;
00593 break;
00594
00595 case N_BCOMM:
00596 if (! debug_start_common_block (dhandle, string))
00597 return false;
00598 break;
00599
00600 case N_ECOMM:
00601 if (! debug_end_common_block (dhandle, string))
00602 return false;
00603 break;
00604
00605 case N_FUN:
00606 if (*string == '\0')
00607 {
00608 if (info->within_function)
00609 {
00610
00611
00612 if (info->sections)
00613 value += info->function_start_offset;
00614 if (! stab_emit_pending_vars (dhandle, info)
00615 || ! debug_end_function (dhandle, value))
00616 return false;
00617 info->within_function = false;
00618 info->function_end = (bfd_vma) -1;
00619 }
00620 break;
00621 }
00622
00623
00624
00625
00626
00627
00628 if (info->within_function
00629 && (info->function_end == (bfd_vma) -1
00630 || value < info->function_end))
00631 info->function_end = value;
00632
00633
00634
00635
00636
00637
00638
00639 default:
00640 {
00641 const char *colon;
00642
00643 colon = strchr (string, ':');
00644 if (colon != NULL
00645 && (colon[1] == 'f' || colon[1] == 'F'))
00646 {
00647 if (info->within_function)
00648 {
00649 bfd_vma endval;
00650
00651 endval = value;
00652 if (info->function_end != (bfd_vma) -1
00653 && info->function_end < endval)
00654 endval = info->function_end;
00655 if (! stab_emit_pending_vars (dhandle, info)
00656 || ! debug_end_function (dhandle, endval))
00657 return false;
00658 info->function_end = (bfd_vma) -1;
00659 }
00660
00661
00662 if (info->sections)
00663 info->function_start_offset = value;
00664 info->within_function = true;
00665 }
00666
00667 if (! parse_stab_string (dhandle, info, type, desc, value, string))
00668 return false;
00669 }
00670 break;
00671
00672 case N_OPT:
00673 if (string != NULL && strcmp (string, "gcc2_compiled.") == 0)
00674 info->gcc_compiled = 2;
00675 else if (string != NULL && strcmp (string, "gcc_compiled.") == 0)
00676 info->gcc_compiled = 1;
00677 else
00678 info->n_opt_found = true;
00679 break;
00680
00681 case N_OBJ:
00682 case N_ENDM:
00683 case N_MAIN:
00684 break;
00685 }
00686
00687 return true;
00688 }
00689
00690
00691
00692 static boolean
00693 parse_stab_string (dhandle, info, stabtype, desc, value, string)
00694 PTR dhandle;
00695 struct stab_handle *info;
00696 int stabtype;
00697 int desc;
00698 bfd_vma value;
00699 const char *string;
00700 {
00701 const char *p;
00702 char *name;
00703 int type;
00704 debug_type dtype;
00705 boolean synonym;
00706 unsigned int lineno;
00707 debug_type *slot;
00708
00709 p = strchr (string, ':');
00710 if (p == NULL)
00711 return true;
00712
00713 while (p[1] == ':')
00714 {
00715 p += 2;
00716 p = strchr (p, ':');
00717 if (p == NULL)
00718 {
00719 bad_stab (string);
00720 return false;
00721 }
00722 }
00723
00724
00725
00726
00727 if (info->gcc_compiled >= 2)
00728 lineno = desc;
00729 else
00730 lineno = 0;
00731
00732
00733 name = NULL;
00734 if (string[0] == '$')
00735 {
00736 switch (string[1])
00737 {
00738 case 't':
00739 name = "this";
00740 break;
00741 case 'v':
00742
00743 break;
00744 case 'e':
00745 name = "eh_throw";
00746 break;
00747 case '_':
00748
00749 break;
00750 case 'X':
00751
00752 break;
00753 default:
00754 warn_stab (string, "unknown C++ encoded name");
00755 break;
00756 }
00757 }
00758
00759 if (name == NULL)
00760 {
00761 if (p == string || (string[0] == ' ' && p == string + 1))
00762 name = NULL;
00763 else
00764 name = savestring (string, p - string);
00765 }
00766
00767 ++p;
00768 if (isdigit ((unsigned char) *p) || *p == '(' || *p == '-')
00769 type = 'l';
00770 else
00771 type = *p++;
00772
00773 switch (type)
00774 {
00775 case 'c':
00776
00777
00778
00779
00780
00781
00782 if (*p != '=')
00783 {
00784 bad_stab (string);
00785 return false;
00786 }
00787 ++p;
00788 switch (*p++)
00789 {
00790 case 'r':
00791
00792 if (! debug_record_float_const (dhandle, name, atof (p)))
00793 return false;
00794 break;
00795 case 'i':
00796
00797
00798
00799
00800
00801
00802
00803 if (! debug_record_int_const (dhandle, name, atoi (p)))
00804 return false;
00805 break;
00806 case 'e':
00807
00808
00809
00810
00811 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
00812 &p, (debug_type **) NULL);
00813 if (dtype == DEBUG_TYPE_NULL)
00814 return false;
00815 if (*p != ',')
00816 {
00817 bad_stab (string);
00818 return false;
00819 }
00820 if (! debug_record_typed_const (dhandle, name, dtype, atoi (p)))
00821 return false;
00822 break;
00823 default:
00824 bad_stab (string);
00825 return false;
00826 }
00827
00828 break;
00829
00830 case 'C':
00831
00832 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
00833 &p, (debug_type **) NULL);
00834 if (dtype == DEBUG_TYPE_NULL)
00835 return false;
00836 if (! debug_record_label (dhandle, name, dtype, value))
00837 return false;
00838 break;
00839
00840 case 'f':
00841 case 'F':
00842
00843 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
00844 (debug_type **) NULL);
00845 if (dtype == DEBUG_TYPE_NULL)
00846 return false;
00847 if (! debug_record_function (dhandle, name, dtype, type == 'F', value))
00848 return false;
00849
00850
00851
00852
00853
00854 while (*p == ';')
00855 {
00856 ++p;
00857 if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
00858 (debug_type **) NULL)
00859 == DEBUG_TYPE_NULL)
00860 return false;
00861 }
00862
00863 break;
00864
00865 case 'G':
00866 {
00867 char leading;
00868 long c;
00869 asymbol **ps;
00870
00871
00872
00873 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
00874 (debug_type **) NULL);
00875 if (dtype == DEBUG_TYPE_NULL)
00876 return false;
00877 leading = bfd_get_symbol_leading_char (info->abfd);
00878 for (c = info->symcount, ps = info->syms; c > 0; --c, ++ps)
00879 {
00880 const char *n;
00881
00882 n = bfd_asymbol_name (*ps);
00883 if (leading != '\0' && *n == leading)
00884 ++n;
00885 if (*n == *name && strcmp (n, name) == 0)
00886 break;
00887 }
00888 if (c > 0)
00889 value = bfd_asymbol_value (*ps);
00890 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_GLOBAL,
00891 value))
00892 return false;
00893 }
00894 break;
00895
00896
00897
00898
00899 case 'l':
00900 case 's':
00901 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
00902 (debug_type **) NULL);
00903 if (dtype == DEBUG_TYPE_NULL)
00904 return false;
00905 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
00906 value))
00907 return false;
00908 break;
00909
00910 case 'p':
00911
00912 if (*p != 'F')
00913 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
00914 (debug_type **) NULL);
00915 else
00916 {
00917
00918
00919
00920 ++p;
00921 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
00922 (debug_type **) NULL);
00923 if (dtype != DEBUG_TYPE_NULL)
00924 {
00925 debug_type ftype;
00926
00927 ftype = debug_make_function_type (dhandle, dtype,
00928 (debug_type *) NULL, false);
00929 dtype = debug_make_pointer_type (dhandle, ftype);
00930 }
00931 }
00932 if (dtype == DEBUG_TYPE_NULL)
00933 return false;
00934 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_STACK,
00935 value))
00936 return false;
00937
00938
00939
00940
00941
00942
00943 break;
00944
00945 case 'P':
00946 if (stabtype == N_FUN)
00947 {
00948
00949 while (*p == ';')
00950 {
00951 ++p;
00952 if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
00953 (debug_type **) NULL)
00954 == DEBUG_TYPE_NULL)
00955 return false;
00956 }
00957 break;
00958 }
00959
00960 case 'R':
00961
00962 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
00963 (debug_type **) NULL);
00964 if (dtype == DEBUG_TYPE_NULL)
00965 return false;
00966 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REG,
00967 value))
00968 return false;
00969 break;
00970
00971 case 'r':
00972
00973 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
00974 (debug_type **) NULL);
00975 if (dtype == DEBUG_TYPE_NULL)
00976 return false;
00977 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_REGISTER,
00978 value))
00979 return false;
00980
00981
00982
00983
00984 break;
00985
00986 case 'S':
00987
00988 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
00989 (debug_type **) NULL);
00990 if (dtype == DEBUG_TYPE_NULL)
00991 return false;
00992 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_STATIC,
00993 value))
00994 return false;
00995 break;
00996
00997 case 't':
00998
00999 dtype = parse_stab_type (dhandle, info, name, &p, &slot);
01000 if (dtype == DEBUG_TYPE_NULL)
01001 return false;
01002 if (name == NULL)
01003 {
01004
01005 return true;
01006 }
01007
01008 dtype = debug_name_type (dhandle, name, dtype);
01009 if (dtype == DEBUG_TYPE_NULL)
01010 return false;
01011
01012 if (slot != NULL)
01013 *slot = dtype;
01014
01015 break;
01016
01017 case 'T':
01018
01019
01020 if (*p != 't')
01021 {
01022 synonym = false;
01023
01024
01025 }
01026 else
01027 {
01028 synonym = true;
01029 ++p;
01030 }
01031
01032 dtype = parse_stab_type (dhandle, info, name, &p, &slot);
01033 if (dtype == DEBUG_TYPE_NULL)
01034 return false;
01035 if (name == NULL)
01036 return true;
01037
01038 dtype = debug_tag_type (dhandle, name, dtype);
01039 if (dtype == DEBUG_TYPE_NULL)
01040 return false;
01041 if (slot != NULL)
01042 *slot = dtype;
01043
01044
01045
01046 {
01047 register struct stab_tag **pst;
01048
01049 for (pst = &info->tags; *pst != NULL; pst = &(*pst)->next)
01050 {
01051 if ((*pst)->name[0] == name[0]
01052 && strcmp ((*pst)->name, name) == 0)
01053 {
01054 (*pst)->slot = dtype;
01055 *pst = (*pst)->next;
01056 break;
01057 }
01058 }
01059 }
01060
01061 if (synonym)
01062 {
01063 dtype = debug_name_type (dhandle, name, dtype);
01064 if (dtype == DEBUG_TYPE_NULL)
01065 return false;
01066
01067 if (slot != NULL)
01068 *slot = dtype;
01069 }
01070
01071 break;
01072
01073 case 'V':
01074
01075 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
01076 (debug_type **) NULL);
01077 if (dtype == DEBUG_TYPE_NULL)
01078 return false;
01079
01080 if (! stab_record_variable (dhandle, info, name, dtype,
01081 DEBUG_LOCAL_STATIC, value))
01082 return false;
01083 break;
01084
01085 case 'v':
01086
01087 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
01088 (debug_type **) NULL);
01089 if (dtype == DEBUG_TYPE_NULL)
01090 return false;
01091 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REFERENCE,
01092 value))
01093 return false;
01094 break;
01095
01096 case 'a':
01097
01098 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
01099 (debug_type **) NULL);
01100 if (dtype == DEBUG_TYPE_NULL)
01101 return false;
01102 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REF_REG,
01103 value))
01104 return false;
01105 break;
01106
01107 case 'X':
01108
01109
01110
01111
01112 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
01113 (debug_type **) NULL);
01114 if (dtype == DEBUG_TYPE_NULL)
01115 return false;
01116 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
01117 value))
01118 return false;
01119 break;
01120
01121 default:
01122 bad_stab (string);
01123 return false;
01124 }
01125
01126
01127
01128
01129 return true;
01130 }
01131
01132
01133
01134
01135
01136
01137 static debug_type
01138 parse_stab_type (dhandle, info, typename, pp, slotp)
01139 PTR dhandle;
01140 struct stab_handle *info;
01141 const char *typename;
01142 const char **pp;
01143 debug_type **slotp;
01144 {
01145 const char *orig;
01146 int typenums[2];
01147 int size;
01148 boolean stringp;
01149 int descriptor;
01150 debug_type dtype;
01151
01152 if (slotp != NULL)
01153 *slotp = NULL;
01154
01155 orig = *pp;
01156
01157 size = -1;
01158 stringp = false;
01159
01160
01161
01162
01163 if (! isdigit ((unsigned char) **pp) && **pp != '(' && **pp != '-')
01164 {
01165
01166
01167 typenums[0] = typenums[1] = -1;
01168 }
01169 else
01170 {
01171 if (! parse_stab_type_number (pp, typenums))
01172 return DEBUG_TYPE_NULL;
01173
01174 if (**pp != '=')
01175 {
01176
01177
01178 return stab_find_type (dhandle, info, typenums);
01179 }
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194 if (slotp != NULL && typenums[0] >= 0 && typenums[1] >= 0)
01195 *slotp = stab_find_slot (info, typenums);
01196
01197
01198
01199 ++*pp;
01200
01201 while (**pp == '@')
01202 {
01203 const char *p = *pp + 1;
01204 const char *attr;
01205
01206 if (isdigit ((unsigned char) *p) || *p == '(' || *p == '-')
01207 {
01208
01209 break;
01210 }
01211
01212
01213 attr = p;
01214
01215 for (; *p != ';'; ++p)
01216 {
01217 if (*p == '\0')
01218 {
01219 bad_stab (orig);
01220 return DEBUG_TYPE_NULL;
01221 }
01222 }
01223 *pp = p + 1;
01224
01225 switch (*attr)
01226 {
01227 case 's':
01228 size = atoi (attr + 1);
01229 if (size <= 0)
01230 size = -1;
01231 break;
01232
01233 case 'S':
01234 stringp = true;
01235 break;
01236
01237 default:
01238
01239
01240 break;
01241 }
01242 }
01243 }
01244
01245 descriptor = **pp;
01246 ++*pp;
01247
01248 switch (descriptor)
01249 {
01250 case 'x':
01251 {
01252 enum debug_type_kind code;
01253 const char *q1, *q2, *p;
01254
01255
01256
01257 switch (**pp)
01258 {
01259 case 's':
01260 code = DEBUG_KIND_STRUCT;
01261 break;
01262 case 'u':
01263 code = DEBUG_KIND_UNION;
01264 break;
01265 case 'e':
01266 code = DEBUG_KIND_ENUM;
01267 break;
01268 default:
01269
01270
01271 warn_stab (orig, "unrecognized cross reference type");
01272 code = DEBUG_KIND_STRUCT;
01273 break;
01274 }
01275 ++*pp;
01276
01277 q1 = strchr (*pp, '<');
01278 p = strchr (*pp, ':');
01279 if (p == NULL)
01280 {
01281 bad_stab (orig);
01282 return DEBUG_TYPE_NULL;
01283 }
01284 while (q1 != NULL && p > q1 && p[1] == ':')
01285 {
01286 q2 = strchr (q1, '>');
01287 if (q2 == NULL || q2 < p)
01288 break;
01289 p += 2;
01290 p = strchr (p, ':');
01291 if (p == NULL)
01292 {
01293 bad_stab (orig);
01294 return DEBUG_TYPE_NULL;
01295 }
01296 }
01297
01298 dtype = stab_find_tagged_type (dhandle, info, *pp, p - *pp, code);
01299
01300 *pp = p + 1;
01301 }
01302 break;
01303
01304 case '-':
01305 case '0':
01306 case '1':
01307 case '2':
01308 case '3':
01309 case '4':
01310 case '5':
01311 case '6':
01312 case '7':
01313 case '8':
01314 case '9':
01315 case '(':
01316 {
01317 const char *hold;
01318 int xtypenums[2];
01319
01320
01321
01322 (*pp)--;
01323 hold = *pp;
01324
01325
01326 if (! parse_stab_type_number (pp, xtypenums))
01327 return DEBUG_TYPE_NULL;
01328
01329 if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1])
01330 {
01331
01332
01333 dtype = debug_make_void_type (dhandle);
01334 }
01335 else
01336 {
01337 *pp = hold;
01338
01339
01340
01341
01342 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
01343 pp, (debug_type **) NULL);
01344 if (dtype == DEBUG_TYPE_NULL)
01345 return DEBUG_TYPE_NULL;
01346 }
01347
01348 if (typenums[0] != -1)
01349 {
01350 if (! stab_record_type (dhandle, info, typenums, dtype))
01351 return DEBUG_TYPE_NULL;
01352 }
01353
01354 break;
01355 }
01356
01357 case '*':
01358 dtype = debug_make_pointer_type (dhandle,
01359 parse_stab_type (dhandle, info,
01360 (const char *) NULL,
01361 pp,
01362 (debug_type **) NULL));
01363 break;
01364
01365 case '&':
01366
01367 dtype = (debug_make_reference_type
01368 (dhandle,
01369 parse_stab_type (dhandle, info, (const char *) NULL, pp,
01370 (debug_type **) NULL)));
01371 break;
01372
01373 case 'f':
01374
01375
01376 dtype = (debug_make_function_type
01377 (dhandle,
01378 parse_stab_type (dhandle, info, (const char *) NULL, pp,
01379 (debug_type **) NULL),
01380 (debug_type *) NULL, false));
01381 break;
01382
01383 case 'k':
01384
01385
01386 dtype = debug_make_const_type (dhandle,
01387 parse_stab_type (dhandle, info,
01388 (const char *) NULL,
01389 pp,
01390 (debug_type **) NULL));
01391 break;
01392
01393 case 'B':
01394
01395
01396 dtype = (debug_make_volatile_type
01397 (dhandle,
01398 parse_stab_type (dhandle, info, (const char *) NULL, pp,
01399 (debug_type **) NULL)));
01400 break;
01401
01402 case '@':
01403
01404
01405 {
01406 debug_type domain;
01407 debug_type memtype;
01408
01409
01410
01411 domain = parse_stab_type (dhandle, info, (const char *) NULL, pp,
01412 (debug_type **) NULL);
01413 if (domain == DEBUG_TYPE_NULL)
01414 return DEBUG_TYPE_NULL;
01415
01416 if (**pp != ',')
01417 {
01418 bad_stab (orig);
01419 return DEBUG_TYPE_NULL;
01420 }
01421 ++*pp;
01422
01423 memtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
01424 (debug_type **) NULL);
01425 if (memtype == DEBUG_TYPE_NULL)
01426 return DEBUG_TYPE_NULL;
01427
01428 dtype = debug_make_offset_type (dhandle, domain, memtype);
01429 }
01430 break;
01431
01432 case '#':
01433
01434 if (**pp == '#')
01435 {
01436 debug_type return_type;
01437
01438 ++*pp;
01439 return_type = parse_stab_type (dhandle, info, (const char *) NULL,
01440 pp, (debug_type **) NULL);
01441 if (return_type == DEBUG_TYPE_NULL)
01442 return DEBUG_TYPE_NULL;
01443 if (**pp != ';')
01444 {
01445 bad_stab (orig);
01446 return DEBUG_TYPE_NULL;
01447 }
01448 ++*pp;
01449 dtype = debug_make_method_type (dhandle, return_type,
01450 DEBUG_TYPE_NULL,
01451 (debug_type *) NULL, false);
01452 }
01453 else
01454 {
01455 debug_type domain;
01456 debug_type return_type;
01457 debug_type *args;
01458 unsigned int n;
01459 unsigned int alloc;
01460 boolean varargs;
01461
01462 domain = parse_stab_type (dhandle, info, (const char *) NULL,
01463 pp, (debug_type **) NULL);
01464 if (domain == DEBUG_TYPE_NULL)
01465 return DEBUG_TYPE_NULL;
01466
01467 if (**pp != ',')
01468 {
01469 bad_stab (orig);
01470 return DEBUG_TYPE_NULL;
01471 }
01472 ++*pp;
01473
01474 return_type = parse_stab_type (dhandle, info, (const char *) NULL,
01475 pp, (debug_type **) NULL);
01476 if (return_type == DEBUG_TYPE_NULL)
01477 return DEBUG_TYPE_NULL;
01478
01479 alloc = 10;
01480 args = (debug_type *) xmalloc (alloc * sizeof *args);
01481 n = 0;
01482 while (**pp != ';')
01483 {
01484 if (**pp != ',')
01485 {
01486 bad_stab (orig);
01487 return DEBUG_TYPE_NULL;
01488 }
01489 ++*pp;
01490
01491 if (n + 1 >= alloc)
01492 {
01493 alloc += 10;
01494 args = ((debug_type *)
01495 xrealloc ((PTR) args, alloc * sizeof *args));
01496 }
01497
01498 args[n] = parse_stab_type (dhandle, info, (const char *) NULL,
01499 pp, (debug_type **) NULL);
01500 if (args[n] == DEBUG_TYPE_NULL)
01501 return DEBUG_TYPE_NULL;
01502 ++n;
01503 }
01504 ++*pp;
01505
01506
01507
01508
01509 if (n == 0
01510 || debug_get_type_kind (dhandle, args[n - 1]) != DEBUG_KIND_VOID)
01511 varargs = true;
01512 else
01513 {
01514 --n;
01515 varargs = false;
01516 }
01517
01518 args[n] = DEBUG_TYPE_NULL;
01519
01520 dtype = debug_make_method_type (dhandle, return_type, domain, args,
01521 varargs);
01522 }
01523 break;
01524
01525 case 'r':
01526
01527 dtype = parse_stab_range_type (dhandle, info, typename, pp, typenums);
01528 break;
01529
01530 case 'b':
01531
01532
01533 dtype = parse_stab_sun_builtin_type (dhandle, pp);
01534 break;
01535
01536 case 'R':
01537
01538 dtype = parse_stab_sun_floating_type (dhandle, pp);
01539 break;
01540
01541 case 'e':
01542
01543 dtype = parse_stab_enum_type (dhandle, pp);
01544 break;
01545
01546 case 's':
01547 case 'u':
01548
01549 dtype = parse_stab_struct_type (dhandle, info, typename, pp,
01550 descriptor == 's', typenums);
01551 break;
01552
01553 case 'a':
01554
01555 if (**pp != 'r')
01556 {
01557 bad_stab (orig);
01558 return DEBUG_TYPE_NULL;
01559 }
01560 ++*pp;
01561
01562 dtype = parse_stab_array_type (dhandle, info, pp, stringp);
01563 break;
01564
01565 case 'S':
01566 dtype = debug_make_set_type (dhandle,
01567 parse_stab_type (dhandle, info,
01568 (const char *) NULL,
01569 pp,
01570 (debug_type **) NULL),
01571 stringp);
01572 break;
01573
01574 default:
01575 bad_stab (orig);
01576 return DEBUG_TYPE_NULL;
01577 }
01578
01579 if (dtype == DEBUG_TYPE_NULL)
01580 return DEBUG_TYPE_NULL;
01581
01582 if (typenums[0] != -1)
01583 {
01584 if (! stab_record_type (dhandle, info, typenums, dtype))
01585 return DEBUG_TYPE_NULL;
01586 }
01587
01588 if (size != -1)
01589 {
01590 if (! debug_record_type_size (dhandle, dtype, (unsigned int) size))
01591 return DEBUG_TYPE_NULL;
01592 }
01593
01594 return dtype;
01595 }
01596
01597
01598
01599
01600
01601
01602 static boolean
01603 parse_stab_type_number (pp, typenums)
01604 const char **pp;
01605 int *typenums;
01606 {
01607 const char *orig;
01608
01609 orig = *pp;
01610
01611 if (**pp != '(')
01612 {
01613 typenums[0] = 0;
01614 typenums[1] = (int) parse_number (pp, (boolean *) NULL);
01615 }
01616 else
01617 {
01618 ++*pp;
01619 typenums[0] = (int) parse_number (pp, (boolean *) NULL);
01620 if (**pp != ',')
01621 {
01622 bad_stab (orig);
01623 return false;
01624 }
01625 ++*pp;
01626 typenums[1] = (int) parse_number (pp, (boolean *) NULL);
01627 if (**pp != ')')
01628 {
01629 bad_stab (orig);
01630 return false;
01631 }
01632 ++*pp;
01633 }
01634
01635 return true;
01636 }
01637
01638
01639
01640 static debug_type
01641 parse_stab_range_type (dhandle, info, typename, pp, typenums)
01642 PTR dhandle;
01643 struct stab_handle *info;
01644 const char *typename;
01645 const char **pp;
01646 const int *typenums;
01647 {
01648 const char *orig;
01649 int rangenums[2];
01650 boolean self_subrange;
01651 debug_type index_type;
01652 const char *s2, *s3;
01653 bfd_signed_vma n2, n3;
01654 boolean ov2, ov3;
01655
01656 orig = *pp;
01657
01658 index_type = DEBUG_TYPE_NULL;
01659
01660
01661
01662 if (! parse_stab_type_number (pp, rangenums))
01663 return DEBUG_TYPE_NULL;
01664
01665 self_subrange = (rangenums[0] == typenums[0]
01666 && rangenums[1] == typenums[1]);
01667
01668 if (**pp == '=')
01669 {
01670 *pp = orig;
01671 index_type = parse_stab_type (dhandle, info, (const char *) NULL,
01672 pp, (debug_type **) NULL);
01673 if (index_type == DEBUG_TYPE_NULL)
01674 return DEBUG_TYPE_NULL;
01675 }
01676
01677 if (**pp == ';')
01678 ++*pp;
01679
01680
01681
01682 s2 = *pp;
01683 n2 = parse_number (pp, &ov2);
01684 if (**pp != ';')
01685 {
01686 bad_stab (orig);
01687 return DEBUG_TYPE_NULL;
01688 }
01689 ++*pp;
01690
01691 s3 = *pp;
01692 n3 = parse_number (pp, &ov3);
01693 if (**pp != ';')
01694 {
01695 bad_stab (orig);
01696 return DEBUG_TYPE_NULL;
01697 }
01698 ++*pp;
01699
01700 if (ov2 || ov3)
01701 {
01702
01703
01704 #define LLLOW "01000000000000000000000;"
01705 #define LLHIGH "0777777777777777777777;"
01706 #define ULLHIGH "01777777777777777777777;"
01707 if (index_type == DEBUG_TYPE_NULL)
01708 {
01709 if (strncmp (s2, LLLOW, sizeof LLLOW - 1) == 0
01710 && strncmp (s3, LLHIGH, sizeof LLHIGH - 1) == 0)
01711 return debug_make_int_type (dhandle, 8, false);
01712 if (! ov2
01713 && n2 == 0
01714 && strncmp (s3, ULLHIGH, sizeof ULLHIGH - 1) == 0)
01715 return debug_make_int_type (dhandle, 8, true);
01716 }
01717
01718 warn_stab (orig, "numeric overflow");
01719 }
01720
01721 if (index_type == DEBUG_TYPE_NULL)
01722 {
01723
01724
01725 if (self_subrange && n2 == 0 && n3 == 0)
01726 return debug_make_void_type (dhandle);
01727
01728
01729
01730 if (self_subrange && n3 == 0 && n2 > 0)
01731 return debug_make_complex_type (dhandle, n2);
01732
01733
01734
01735 if (n3 == 0 && n2 > 0)
01736 return debug_make_float_type (dhandle, n2);
01737
01738
01739 if (n2 == 0 && n3 == -1)
01740 {
01741
01742
01743
01744
01745 if (typename != NULL)
01746 {
01747 if (strcmp (typename, "long long int") == 0)
01748 return debug_make_int_type (dhandle, 8, false);
01749 else if (strcmp (typename, "long long unsigned int") == 0)
01750 return debug_make_int_type (dhandle, 8, true);
01751 }
01752
01753 return debug_make_int_type (dhandle, 4, true);
01754 }
01755
01756
01757 if (self_subrange && n2 == 0 && n3 == 127)
01758 return debug_make_int_type (dhandle, 1, false);
01759
01760
01761
01762 if (n2 == 0)
01763 {
01764 if (n3 < 0)
01765 return debug_make_int_type (dhandle, - n3, true);
01766 else if (n3 == 0xff)
01767 return debug_make_int_type (dhandle, 1, true);
01768 else if (n3 == 0xffff)
01769 return debug_make_int_type (dhandle, 2, true);
01770
01771
01772
01773 }
01774 else if (n3 == 0
01775 && n2 < 0
01776 && (self_subrange || n2 == -8))
01777 return debug_make_int_type (dhandle, - n2, true);
01778 else if (n2 == - n3 - 1)
01779 {
01780 if (n3 == 0x7f)
01781 return debug_make_int_type (dhandle, 1, false);
01782 else if (n3 == 0x7fff)
01783 return debug_make_int_type (dhandle, 2, false);
01784 else if (n3 == 0x7fffffff)
01785 return debug_make_int_type (dhandle, 4, false);
01786 }
01787 }
01788
01789
01790
01791
01792 if (self_subrange)
01793 {
01794 bad_stab (orig);
01795 return DEBUG_TYPE_NULL;
01796 }
01797
01798 index_type = stab_find_type (dhandle, info, rangenums);
01799 if (index_type == DEBUG_TYPE_NULL)
01800 {
01801
01802
01803 warn_stab (orig, "missing index type");
01804 index_type = debug_make_int_type (dhandle, 4, false);
01805 }
01806
01807 return debug_make_range_type (dhandle, index_type, n2, n3);
01808 }
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818
01819
01820
01821
01822 static debug_type
01823 parse_stab_sun_builtin_type (dhandle, pp)
01824 PTR dhandle;
01825 const char **pp;
01826 {
01827 const char *orig;
01828 boolean unsignedp;
01829 bfd_vma bits;
01830
01831 orig = *pp;
01832
01833 switch (**pp)
01834 {
01835 case 's':
01836 unsignedp = false;
01837 break;
01838 case 'u':
01839 unsignedp = true;
01840 break;
01841 default:
01842 bad_stab (orig);
01843 return DEBUG_TYPE_NULL;
01844 }
01845 ++*pp;
01846
01847
01848
01849
01850
01851 if (**pp == 'c')
01852 ++*pp;
01853
01854
01855
01856
01857
01858 (void) parse_number (pp, (boolean *) NULL);
01859 if (**pp != ';')
01860 {
01861 bad_stab (orig);
01862 return DEBUG_TYPE_NULL;
01863 }
01864 ++*pp;
01865
01866
01867 (void) parse_number (pp, (boolean *) NULL);
01868 if (**pp != ';')
01869 {
01870 bad_stab (orig);
01871 return DEBUG_TYPE_NULL;
01872 }
01873 ++*pp;
01874
01875
01876 bits = parse_number (pp, (boolean *) NULL);
01877
01878
01879
01880
01881
01882
01883
01884 if (**pp == ';')
01885 ++*pp;
01886
01887 if (bits == 0)
01888 return debug_make_void_type (dhandle);
01889
01890 return debug_make_int_type (dhandle, bits / 8, unsignedp);
01891 }
01892
01893
01894
01895 static debug_type
01896 parse_stab_sun_floating_type (dhandle, pp)
01897 PTR dhandle;
01898 const char **pp;
01899 {
01900 const char *orig;
01901 bfd_vma details;
01902 bfd_vma bytes;
01903
01904 orig = *pp;
01905
01906
01907
01908 details = parse_number (pp, (boolean *) NULL);
01909 if (**pp != ';')
01910 {
01911 bad_stab (orig);
01912 return DEBUG_TYPE_NULL;
01913 }
01914
01915
01916 bytes = parse_number (pp, (boolean *) NULL);
01917 if (**pp != ';')
01918 {
01919 bad_stab (orig);
01920 return DEBUG_TYPE_NULL;
01921 }
01922
01923 if (details == NF_COMPLEX
01924 || details == NF_COMPLEX16
01925 || details == NF_COMPLEX32)
01926 return debug_make_complex_type (dhandle, bytes);
01927
01928 return debug_make_float_type (dhandle, bytes);
01929 }
01930
01931
01932
01933 static debug_type
01934 parse_stab_enum_type (dhandle, pp)
01935 PTR dhandle;
01936 const char **pp;
01937 {
01938 const char *orig;
01939 const char **names;
01940 bfd_signed_vma *values;
01941 unsigned int n;
01942 unsigned int alloc;
01943
01944 orig = *pp;
01945
01946
01947
01948
01949
01950 if (**pp == '-')
01951 {
01952 while (**pp != ':')
01953 ++*pp;
01954 ++*pp;
01955 }
01956
01957
01958
01959
01960 alloc = 10;
01961 names = (const char **) xmalloc (alloc * sizeof *names);
01962 values = (bfd_signed_vma *) xmalloc (alloc * sizeof *values);
01963 n = 0;
01964 while (**pp != '\0' && **pp != ';' && **pp != ',')
01965 {
01966 const char *p;
01967 char *name;
01968 bfd_signed_vma val;
01969
01970 p = *pp;
01971 while (*p != ':')
01972 ++p;
01973
01974 name = savestring (*pp, p - *pp);
01975
01976 *pp = p + 1;
01977 val = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
01978 if (**pp != ',')
01979 {
01980 bad_stab (orig);
01981 return DEBUG_TYPE_NULL;
01982 }
01983 ++*pp;
01984
01985 if (n + 1 >= alloc)
01986 {
01987 alloc += 10;
01988 names = ((const char **)
01989 xrealloc ((PTR) names, alloc * sizeof *names));
01990 values = ((bfd_signed_vma *)
01991 xrealloc ((PTR) values, alloc * sizeof *values));
01992 }
01993
01994 names[n] = name;
01995 values[n] = val;
01996 ++n;
01997 }
01998
01999 names[n] = NULL;
02000 values[n] = 0;
02001
02002 if (**pp == ';')
02003 ++*pp;
02004
02005 return debug_make_enum_type (dhandle, names, values);
02006 }
02007
02008
02009
02010
02011
02012
02013
02014
02015 static debug_type
02016 parse_stab_struct_type (dhandle, info, tagname, pp, structp, typenums)
02017 PTR dhandle;
02018 struct stab_handle *info;
02019 const char *tagname;
02020 const char **pp;
02021 boolean structp;
02022 const int *typenums;
02023 {
02024 const char *orig;
02025 bfd_vma size;
02026 debug_baseclass *baseclasses;
02027 debug_field *fields;
02028 boolean statics;
02029 debug_method *methods;
02030 debug_type vptrbase;
02031 boolean ownvptr;
02032
02033 orig = *pp;
02034
02035
02036 size = parse_number (pp, (boolean *) NULL);
02037
02038
02039 if (! parse_stab_baseclasses (dhandle, info, pp, &baseclasses)
02040 || ! parse_stab_struct_fields (dhandle, info, pp, &fields, &statics)
02041 || ! parse_stab_members (dhandle, info, tagname, pp, typenums, &methods)
02042 || ! parse_stab_tilde_field (dhandle, info, pp, typenums, &vptrbase,
02043 &ownvptr))
02044 return DEBUG_TYPE_NULL;
02045
02046 if (! statics
02047 && baseclasses == NULL
02048 && methods == NULL
02049 && vptrbase == DEBUG_TYPE_NULL
02050 && ! ownvptr)
02051 return debug_make_struct_type (dhandle, structp, size, fields);
02052
02053 return debug_make_object_type (dhandle, structp, size, fields, baseclasses,
02054 methods, vptrbase, ownvptr);
02055 }
02056
02057
02058
02059
02060
02061
02062
02063
02064
02065
02066
02067
02068
02069
02070
02071
02072
02073
02074
02075
02076
02077
02078
02079
02080
02081 static boolean
02082 parse_stab_baseclasses (dhandle, info, pp, retp)
02083 PTR dhandle;
02084 struct stab_handle *info;
02085 const char **pp;
02086 debug_baseclass **retp;
02087 {
02088 const char *orig;
02089 unsigned int c, i;
02090 debug_baseclass *classes;
02091
02092 *retp = NULL;
02093
02094 orig = *pp;
02095
02096 if (**pp != '!')
02097 {
02098
02099 return true;
02100 }
02101 ++*pp;
02102
02103 c = (unsigned int) parse_number (pp, (boolean *) NULL);
02104
02105 if (**pp != ',')
02106 {
02107 bad_stab (orig);
02108 return false;
02109 }
02110 ++*pp;
02111
02112 classes = (debug_baseclass *) xmalloc ((c + 1) * sizeof (**retp));
02113
02114 for (i = 0; i < c; i++)
02115 {
02116 boolean virtual;
02117 enum debug_visibility visibility;
02118 bfd_vma bitpos;
02119 debug_type type;
02120
02121 switch (**pp)
02122 {
02123 case '0':
02124 virtual = false;
02125 break;
02126 case '1':
02127 virtual = true;
02128 break;
02129 default:
02130 warn_stab (orig, "unknown virtual character for baseclass");
02131 virtual = false;
02132 break;
02133 }
02134 ++*pp;
02135
02136 switch (**pp)
02137 {
02138 case '0':
02139 visibility = DEBUG_VISIBILITY_PRIVATE;
02140 break;
02141 case '1':
02142 visibility = DEBUG_VISIBILITY_PROTECTED;
02143 break;
02144 case '2':
02145 visibility = DEBUG_VISIBILITY_PUBLIC;
02146 break;
02147 default:
02148 warn_stab (orig, "unknown visibility character for baseclass");
02149 visibility = DEBUG_VISIBILITY_PUBLIC;
02150 break;
02151 }
02152 ++*pp;
02153
02154
02155
02156
02157 bitpos = parse_number (pp, (boolean *) NULL);
02158 if (**pp != ',')
02159 {
02160 bad_stab (orig);
02161 return false;
02162 }
02163 ++*pp;
02164
02165 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
02166 (debug_type **) NULL);
02167 if (type == DEBUG_TYPE_NULL)
02168 return false;
02169
02170 classes[i] = debug_make_baseclass (dhandle, type, bitpos, virtual,
02171 visibility);
02172 if (classes[i] == DEBUG_BASECLASS_NULL)
02173 return false;
02174
02175 if (**pp != ';')
02176 return false;
02177 ++*pp;
02178 }
02179
02180 classes[i] = DEBUG_BASECLASS_NULL;
02181
02182 *retp = classes;
02183
02184 return true;
02185 }
02186
02187
02188
02189
02190
02191
02192
02193
02194
02195
02196
02197
02198
02199
02200
02201
02202
02203
02204
02205
02206
02207 static boolean
02208 parse_stab_struct_fields (dhandle, info, pp, retp, staticsp)
02209 PTR dhandle;
02210 struct stab_handle *info;
02211 const char **pp;
02212 debug_field **retp;
02213 boolean *staticsp;
02214 {
02215 const char *orig;
02216 const char *p;
02217 debug_field *fields;
02218 unsigned int c;
02219 unsigned int alloc;
02220
02221 *retp = NULL;
02222 *staticsp = false;
02223
02224 orig = *pp;
02225
02226 c = 0;
02227 alloc = 10;
02228 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
02229 while (**pp != ';')
02230 {
02231
02232
02233 p = *pp;
02234
02235
02236 if (c + 1 >= alloc)
02237 {
02238 alloc += 10;
02239 fields = ((debug_field *)
02240 xrealloc ((PTR) fields, alloc * sizeof *fields));
02241 }
02242
02243
02244
02245
02246
02247
02248
02249
02250 if ((*p == '$' || *p == '.') && p[1] != '_')
02251 {
02252 ++*pp;
02253 if (! parse_stab_cpp_abbrev (dhandle, info, pp, fields + c))
02254 return false;
02255 ++c;
02256 continue;
02257 }
02258
02259
02260
02261
02262
02263
02264 p = strchr (p, ':');
02265 if (p == NULL)
02266 {
02267 bad_stab (orig);
02268 return false;
02269 }
02270
02271 if (p[1] == ':')
02272 break;
02273
02274 if (! parse_stab_one_struct_field (dhandle, info, pp, p, fields + c,
02275 staticsp))
02276 return false;
02277
02278 ++c;
02279 }
02280
02281 fields[c] = DEBUG_FIELD_NULL;
02282
02283 *retp = fields;
02284
02285 return true;
02286 }
02287
02288
02289
02290 static boolean
02291 parse_stab_cpp_abbrev (dhandle, info, pp, retp)
02292 PTR dhandle;
02293 struct stab_handle *info;
02294 const char **pp;
02295 debug_field *retp;
02296 {
02297 const char *orig;
02298 int cpp_abbrev;
02299 debug_type context;
02300 const char *name;
02301 const char *typename;
02302 debug_type type;
02303 bfd_vma bitpos;
02304
02305 *retp = DEBUG_FIELD_NULL;
02306
02307 orig = *pp;
02308
02309 if (**pp != 'v')
02310 {
02311 bad_stab (*pp);
02312 return false;
02313 }
02314 ++*pp;
02315
02316 cpp_abbrev = **pp;
02317 ++*pp;
02318
02319
02320
02321
02322
02323
02324 context = parse_stab_type (dhandle, info, (const char *) NULL, pp,
02325 (debug_type **) NULL);
02326 if (context == DEBUG_TYPE_NULL)
02327 return false;
02328
02329 switch (cpp_abbrev)
02330 {
02331 case 'f':
02332
02333 name = "_vptr$";
02334 break;
02335 case 'b':
02336
02337 typename = debug_get_type_name (dhandle, context);
02338 if (typename == NULL)
02339 {
02340 warn_stab (orig, "unnamed $vb type");
02341 typename = "FOO";
02342 }
02343 name = concat ("_vb$", typename, (const char *) NULL);
02344 break;
02345 default:
02346 warn_stab (orig, "unrecognized C++ abbreviation");
02347 name = "INVALID_CPLUSPLUS_ABBREV";
02348 break;
02349 }
02350
02351 if (**pp != ':')
02352 {
02353 bad_stab (orig);
02354 return false;
02355 }
02356 ++*pp;
02357
02358 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
02359 (debug_type **) NULL);
02360 if (**pp != ',')
02361 {
02362 bad_stab (orig);
02363 return false;
02364 }
02365 ++*pp;
02366
02367 bitpos = parse_number (pp, (boolean *) NULL);
02368 if (**pp != ';')
02369 {
02370 bad_stab (orig);
02371 return false;
02372 }
02373 ++*pp;
02374
02375 *retp = debug_make_field (dhandle, name, type, bitpos, 0,
02376 DEBUG_VISIBILITY_PRIVATE);
02377 if (*retp == DEBUG_FIELD_NULL)
02378 return false;
02379
02380 return true;
02381 }
02382
02383
02384
02385 static boolean
02386 parse_stab_one_struct_field (dhandle, info, pp, p, retp, staticsp)
02387 PTR dhandle;
02388 struct stab_handle *info;
02389 const char **pp;
02390 const char *p;
02391 debug_field *retp;
02392 boolean *staticsp;
02393 {
02394 const char *orig;
02395 char *name;
02396 enum debug_visibility visibility;
02397 debug_type type;
02398 bfd_vma bitpos;
02399 bfd_vma bitsize;
02400
02401 orig = *pp;
02402
02403
02404
02405 name = savestring (*pp, p - *pp);
02406
02407 *pp = p + 1;
02408
02409 if (**pp != '/')
02410 visibility = DEBUG_VISIBILITY_PUBLIC;
02411 else
02412 {
02413 ++*pp;
02414 switch (**pp)
02415 {
02416 case '0':
02417 visibility = DEBUG_VISIBILITY_PRIVATE;
02418 break;
02419 case '1':
02420 visibility = DEBUG_VISIBILITY_PROTECTED;
02421 break;
02422 case '2':
02423 visibility = DEBUG_VISIBILITY_PUBLIC;
02424 break;
02425 default:
02426 warn_stab (orig, "unknown visibility character for field");
02427 visibility = DEBUG_VISIBILITY_PUBLIC;
02428 break;
02429 }
02430 ++*pp;
02431 }
02432
02433 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
02434 (debug_type **) NULL);
02435 if (type == DEBUG_TYPE_NULL)
02436 return false;
02437
02438 if (**pp == ':')
02439 {
02440 char *varname;
02441
02442
02443 ++*pp;
02444 p = strchr (*pp, ';');
02445 if (p == NULL)
02446 {
02447 bad_stab (orig);
02448 return false;
02449 }
02450
02451 varname = savestring (*pp, p - *pp);
02452
02453 *pp = p + 1;
02454
02455 *retp = debug_make_static_member (dhandle, name, type, varname,
02456 visibility);
02457 *staticsp = true;
02458
02459 return true;
02460 }
02461
02462 if (**pp != ',')
02463 {
02464 bad_stab (orig);
02465 return false;
02466 }
02467 ++*pp;
02468
02469 bitpos = parse_number (pp, (boolean *) NULL);
02470 if (**pp != ',')
02471 {
02472 bad_stab (orig);
02473 return false;
02474 }
02475 ++*pp;
02476
02477 bitsize = parse_number (pp, (boolean *) NULL);
02478 if (**pp != ';')
02479 {
02480 bad_stab (orig);
02481 return false;
02482 }
02483 ++*pp;
02484
02485 if (bitpos == 0 && bitsize == 0)
02486 {
02487
02488
02489
02490
02491
02492
02493
02494
02495
02496
02497
02498
02499
02500 visibility = DEBUG_VISIBILITY_IGNORE;
02501 }
02502
02503
02504
02505 *retp = debug_make_field (dhandle, name, type, bitpos, bitsize, visibility);
02506
02507 return true;
02508 }
02509
02510
02511
02512
02513
02514
02515
02516
02517
02518
02519
02520
02521
02522
02523 static boolean
02524 parse_stab_members (dhandle, info, tagname, pp, typenums, retp)
02525 PTR dhandle;
02526 struct stab_handle *info;
02527 const char *tagname;
02528 const char **pp;
02529 const int *typenums;
02530 debug_method **retp;
02531 {
02532 const char *orig;
02533 debug_method *methods;
02534 unsigned int c;
02535 unsigned int alloc;
02536
02537 *retp = NULL;
02538
02539 orig = *pp;
02540
02541 alloc = 0;
02542 methods = NULL;
02543 c = 0;
02544
02545 while (**pp != ';')
02546 {
02547 const char *p;
02548 char *name;
02549 debug_method_variant *variants;
02550 unsigned int cvars;
02551 unsigned int allocvars;
02552 debug_type look_ahead_type;
02553
02554 p = strchr (*pp, ':');
02555 if (p == NULL || p[1] != ':')
02556 break;
02557
02558
02559 if ((*pp)[0] != 'o' || (*pp)[1] != 'p' || (*pp)[2] != '$')
02560 {
02561 name = savestring (*pp, p - *pp);
02562 *pp = p + 2;
02563 }
02564 else
02565 {
02566
02567
02568
02569
02570
02571
02572 *pp = p + 2;
02573 for (p = *pp; *p != '.' && *p != '\0'; p++)
02574 ;
02575 if (*p != '.')
02576 {
02577 bad_stab (orig);
02578 return false;
02579 }
02580 name = savestring (*pp, p - *pp);
02581 *pp = p + 1;
02582 }
02583
02584 allocvars = 10;
02585 variants = ((debug_method_variant *)
02586 xmalloc (allocvars * sizeof *variants));
02587 cvars = 0;
02588
02589 look_ahead_type = DEBUG_TYPE_NULL;
02590
02591 do
02592 {
02593 debug_type type;
02594 boolean stub;
02595 char *argtypes;
02596 enum debug_visibility visibility;
02597 boolean constp, volatilep, staticp;
02598 bfd_vma voffset;
02599 debug_type context;
02600 const char *physname;
02601 boolean varargs;
02602
02603 if (look_ahead_type != DEBUG_TYPE_NULL)
02604 {
02605
02606 type = look_ahead_type;
02607 look_ahead_type = DEBUG_TYPE_NULL;
02608 }
02609 else
02610 {
02611 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
02612 (debug_type **) NULL);
02613 if (type == DEBUG_TYPE_NULL)
02614 return false;
02615 if (**pp != ':')
02616 {
02617 bad_stab (orig);
02618 return false;
02619 }
02620 }
02621
02622 ++*pp;
02623 p = strchr (*pp, ';');
02624 if (p == NULL)
02625 {
02626 bad_stab (orig);
02627 return false;
02628 }
02629
02630 stub = false;
02631 if (debug_get_type_kind (dhandle, type) == DEBUG_KIND_METHOD
02632 && debug_get_parameter_types (dhandle, type, &varargs) == NULL)
02633 stub = true;
02634
02635 argtypes = savestring (*pp, p - *pp);
02636 *pp = p + 1;
02637
02638 switch (**pp)
02639 {
02640 case '0':
02641 visibility = DEBUG_VISIBILITY_PRIVATE;
02642 break;
02643 case '1':
02644 visibility = DEBUG_VISIBILITY_PROTECTED;
02645 break;
02646 default:
02647 visibility = DEBUG_VISIBILITY_PUBLIC;
02648 break;
02649 }
02650 ++*pp;
02651
02652 constp = false;
02653 volatilep = false;
02654 switch (**pp)
02655 {
02656 case 'A':
02657
02658 ++*pp;
02659 break;
02660 case 'B':
02661
02662 constp = true;
02663 ++*pp;
02664 break;
02665 case 'C':
02666
02667 volatilep = true;
02668 ++*pp;
02669 break;
02670 case 'D':
02671
02672 constp = true;
02673 volatilep = true;
02674 ++*pp;
02675 break;
02676 case '*':
02677 case '?':
02678 case '.':
02679
02680 break;
02681 default:
02682 warn_stab (orig, "const/volatile indicator missing");
02683 break;
02684 }
02685
02686 staticp = false;
02687 switch (**pp)
02688 {
02689 case '*':
02690
02691
02692
02693 ++*pp;
02694 voffset = parse_number (pp, (boolean *) NULL);
02695 if (**pp != ';')
02696 {
02697 bad_stab (orig);
02698 return false;
02699 }
02700 ++*pp;
02701 voffset &= 0x7fffffff;
02702
02703 if (**pp == ';' || *pp == '\0')
02704 {
02705
02706 context = DEBUG_TYPE_NULL;
02707 }
02708 else
02709 {
02710
02711
02712
02713 look_ahead_type = parse_stab_type (dhandle, info,
02714 (const char *) NULL,
02715 pp,
02716 (debug_type **) NULL);
02717 if (**pp == ':')
02718 {
02719
02720 context = DEBUG_TYPE_NULL;
02721 }
02722 else
02723 {
02724 context = look_ahead_type;
02725 look_ahead_type = DEBUG_TYPE_NULL;
02726 if (**pp != ';')
02727 {
02728 bad_stab (orig);
02729 return false;
02730 }
02731 ++*pp;
02732 }
02733 }
02734 break;
02735
02736 case '?':
02737
02738 ++*pp;
02739 staticp = true;
02740 voffset = 0;
02741 context = DEBUG_TYPE_NULL;
02742 if (strncmp (argtypes, name, strlen (name)) != 0)
02743 stub = true;
02744 break;
02745
02746 default:
02747 warn_stab (orig, "member function type missing");
02748 voffset = 0;
02749 context = DEBUG_TYPE_NULL;
02750 break;
02751
02752 case '.':
02753 ++*pp;
02754 voffset = 0;
02755 context = DEBUG_TYPE_NULL;
02756 break;
02757 }
02758
02759
02760
02761
02762
02763
02764 if (! stub)
02765 physname = argtypes;
02766 else
02767 {
02768 debug_type class_type, return_type;
02769
02770 class_type = stab_find_type (dhandle, info, typenums);
02771 if (class_type == DEBUG_TYPE_NULL)
02772 return false;
02773 return_type = debug_get_return_type (dhandle, type);
02774 if (return_type == DEBUG_TYPE_NULL)
02775 {
02776 bad_stab (orig);
02777 return false;
02778 }
02779 type = parse_stab_argtypes (dhandle, info, class_type, name,
02780 tagname, return_type, argtypes,
02781 constp, volatilep, &physname);
02782 if (type == DEBUG_TYPE_NULL)
02783 return false;
02784 }
02785
02786 if (cvars + 1 >= allocvars)
02787 {
02788 allocvars += 10;
02789 variants = ((debug_method_variant *)
02790 xrealloc ((PTR) variants,
02791 allocvars * sizeof *variants));
02792 }
02793
02794 if (! staticp)
02795 variants[cvars] = debug_make_method_variant (dhandle, physname,
02796 type, visibility,
02797 constp, volatilep,
02798 voffset, context);
02799 else
02800 variants[cvars] = debug_make_static_method_variant (dhandle,
02801 physname,
02802 type,
02803 visibility,
02804 constp,
02805 volatilep);
02806 if (variants[cvars] == DEBUG_METHOD_VARIANT_NULL)
02807 return false;
02808
02809 ++cvars;
02810 }
02811 while (**pp != ';' && **pp != '\0');
02812
02813 variants[cvars] = DEBUG_METHOD_VARIANT_NULL;
02814
02815 if (**pp != '\0')
02816 ++*pp;
02817
02818 if (c + 1 >= alloc)
02819 {
02820 alloc += 10;
02821 methods = ((debug_method *)
02822 xrealloc ((PTR) methods, alloc * sizeof *methods));
02823 }
02824
02825 methods[c] = debug_make_method (dhandle, name, variants);
02826
02827 ++c;
02828 }
02829
02830 if (methods != NULL)
02831 methods[c] = DEBUG_METHOD_NULL;
02832
02833 *retp = methods;
02834
02835 return true;
02836 }
02837
02838
02839
02840
02841
02842
02843
02844 static debug_type
02845 parse_stab_argtypes (dhandle, info, class_type, fieldname, tagname,
02846 return_type, argtypes, constp, volatilep, pphysname)
02847 PTR dhandle;
02848 struct stab_handle *info;
02849 debug_type class_type;
02850 const char *fieldname;
02851 const char *tagname;
02852 debug_type return_type;
02853 const char *argtypes;
02854 boolean constp;
02855 boolean volatilep;
02856 const char **pphysname;
02857 {
02858 boolean is_full_physname_constructor;
02859 boolean is_constructor;
02860 boolean is_destructor;
02861 debug_type *args;
02862 boolean varargs;
02863
02864
02865 is_full_physname_constructor = ((argtypes[0] == '_'
02866 && argtypes[1] == '_'
02867 && (isdigit ((unsigned char) argtypes[2])
02868 || argtypes[2] == 'Q'
02869 || argtypes[2] == 't'))
02870 || strncmp (argtypes, "__ct", 4) == 0);
02871
02872 is_constructor = (is_full_physname_constructor
02873 || (tagname != NULL
02874 && strcmp (fieldname, tagname) == 0));
02875 is_destructor = ((argtypes[0] == '_'
02876 && (argtypes[1] == '$' || argtypes[1] == '.')
02877 && argtypes[2] == '_')
02878 || strncmp (argtypes, "__dt", 4) == 0);
02879
02880 if (is_destructor || is_full_physname_constructor)
02881 *pphysname = argtypes;
02882 else
02883 {
02884 unsigned int len;
02885 const char *const_prefix;
02886 const char *volatile_prefix;
02887 char buf[20];
02888 unsigned int mangled_name_len;
02889 char *physname;
02890
02891 len = tagname == NULL ? 0 : strlen (tagname);
02892 const_prefix = constp ? "C" : "";
02893 volatile_prefix = volatilep ? "V" : "";
02894
02895 if (len == 0)
02896 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
02897 else if (tagname != NULL && strchr (tagname, '<') != NULL)
02898 {
02899
02900 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
02901 tagname = NULL;
02902 len = 0;
02903 }
02904 else
02905 sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
02906
02907 mangled_name_len = ((is_constructor ? 0 : strlen (fieldname))
02908 + strlen (buf)
02909 + len
02910 + strlen (argtypes)
02911 + 1);
02912
02913 if (fieldname[0] == 'o'
02914 && fieldname[1] == 'p'
02915 && (fieldname[2] == '$' || fieldname[2] == '.'))
02916 {
02917 const char *opname;
02918
02919 opname = cplus_mangle_opname (fieldname + 3, 0);
02920 if (opname == NULL)
02921 {
02922 fprintf (stderr, "No mangling for \"%s\"\n", fieldname);
02923 return DEBUG_TYPE_NULL;
02924 }
02925 mangled_name_len += strlen (opname);
02926 physname = (char *) xmalloc (mangled_name_len);
02927 strncpy (physname, fieldname, 3);
02928 strcpy (physname + 3, opname);
02929 }
02930 else
02931 {
02932 physname = (char *) xmalloc (mangled_name_len);
02933 if (is_constructor)
02934 physname[0] = '\0';
02935 else
02936 strcpy (physname, fieldname);
02937 }
02938
02939 strcat (physname, buf);
02940 if (tagname != NULL)
02941 strcat (physname, tagname);
02942 strcat (physname, argtypes);
02943
02944 *pphysname = physname;
02945 }
02946
02947 if (*argtypes == '\0' || is_destructor)
02948 {
02949 args = (debug_type *) xmalloc (sizeof *args);
02950 *args = NULL;
02951 return debug_make_method_type (dhandle, return_type, class_type, args,
02952 false);
02953 }
02954
02955 args = stab_demangle_argtypes (dhandle, info, *pphysname, &varargs);
02956 if (args == NULL)
02957 return DEBUG_TYPE_NULL;
02958
02959 return debug_make_method_type (dhandle, return_type, class_type, args,
02960 varargs);
02961 }
02962
02963
02964
02965
02966
02967
02968
02969
02970
02971 static boolean
02972 parse_stab_tilde_field (dhandle, info, pp, typenums, retvptrbase, retownvptr)
02973 PTR dhandle;
02974 struct stab_handle *info;
02975 const char **pp;
02976 const int *typenums;
02977 debug_type *retvptrbase;
02978 boolean *retownvptr;
02979 {
02980 const char *orig;
02981 const char *hold;
02982 int vtypenums[2];
02983
02984 *retvptrbase = DEBUG_TYPE_NULL;
02985 *retownvptr = false;
02986
02987 orig = *pp;
02988
02989
02990 if (**pp == ';')
02991 ++*pp;
02992
02993 if (**pp != '~')
02994 return true;
02995
02996 ++*pp;
02997
02998 if (**pp == '=' || **pp == '+' || **pp == '-')
02999 {
03000
03001
03002 ++*pp;
03003 }
03004
03005 if (**pp != '%')
03006 return true;
03007
03008 ++*pp;
03009
03010 hold = *pp;
03011
03012
03013
03014 if (! parse_stab_type_number (pp, vtypenums))
03015 return false;
03016
03017 if (vtypenums[0] == typenums[0]
03018 && vtypenums[1] == typenums[1])
03019 *retownvptr = true;
03020 else
03021 {
03022 debug_type vtype;
03023 const char *p;
03024
03025 *pp = hold;
03026
03027 vtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
03028 (debug_type **) NULL);
03029 for (p = *pp; *p != ';' && *p != '\0'; p++)
03030 ;
03031 if (*p != ';')
03032 {
03033 bad_stab (orig);
03034 return false;
03035 }
03036
03037 *retvptrbase = vtype;
03038
03039 *pp = p + 1;
03040 }
03041
03042 return true;
03043 }
03044
03045
03046
03047 static debug_type
03048 parse_stab_array_type (dhandle, info, pp, stringp)
03049 PTR dhandle;
03050 struct stab_handle *info;
03051 const char **pp;
03052 boolean stringp;
03053 {
03054 const char *orig;
03055 const char *p;
03056 int typenums[2];
03057 debug_type index_type;
03058 boolean adjustable;
03059 bfd_signed_vma lower, upper;
03060 debug_type element_type;
03061
03062
03063
03064
03065
03066
03067
03068
03069 orig = *pp;
03070
03071
03072
03073
03074 p = *pp;
03075 if (! parse_stab_type_number (&p, typenums))
03076 return DEBUG_TYPE_NULL;
03077 if (typenums[0] == 0 && typenums[1] == 0 && **pp != '=')
03078 {
03079 index_type = debug_find_named_type (dhandle, "int");
03080 if (index_type == DEBUG_TYPE_NULL)
03081 {
03082 index_type = debug_make_int_type (dhandle, 4, false);
03083 if (index_type == DEBUG_TYPE_NULL)
03084 return DEBUG_TYPE_NULL;
03085 }
03086 *pp = p;
03087 }
03088 else
03089 {
03090 index_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
03091 (debug_type **) NULL);
03092 }
03093
03094 if (**pp != ';')
03095 {
03096 bad_stab (orig);
03097 return DEBUG_TYPE_NULL;
03098 }
03099 ++*pp;
03100
03101 adjustable = false;
03102
03103 if (! isdigit ((unsigned char) **pp) && **pp != '-')
03104 {
03105 ++*pp;
03106 adjustable = true;
03107 }
03108
03109 lower = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
03110 if (**pp != ';')
03111 {
03112 bad_stab (orig);
03113 return DEBUG_TYPE_NULL;
03114 }
03115 ++*pp;
03116
03117 if (! isdigit ((unsigned char) **pp) && **pp != '-')
03118 {
03119 ++*pp;
03120 adjustable = true;
03121 }
03122
03123 upper = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
03124 if (**pp != ';')
03125 {
03126 bad_stab (orig);
03127 return DEBUG_TYPE_NULL;
03128 }
03129 ++*pp;
03130
03131 element_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
03132 (debug_type **) NULL);
03133 if (element_type == DEBUG_TYPE_NULL)
03134 return DEBUG_TYPE_NULL;
03135
03136 if (adjustable)
03137 {
03138 lower = 0;
03139 upper = -1;
03140 }
03141
03142 return debug_make_array_type (dhandle, element_type, index_type, lower,
03143 upper, stringp);
03144 }
03145
03146
03147
03148
03149 struct bincl_file
03150 {
03151
03152 struct bincl_file *next;
03153
03154 struct bincl_file *next_stack;
03155
03156 const char *name;
03157
03158 bfd_vma hash;
03159
03160 unsigned int file;
03161
03162 struct stab_types *file_types;
03163 };
03164
03165
03166
03167 static void
03168 push_bincl (info, name, hash)
03169 struct stab_handle *info;
03170 const char *name;
03171 bfd_vma hash;
03172 {
03173 struct bincl_file *n;
03174
03175 n = (struct bincl_file *) xmalloc (sizeof *n);
03176 n->next = info->bincl_list;
03177 n->next_stack = info->bincl_stack;
03178 n->name = name;
03179 n->hash = hash;
03180 n->file = info->files;
03181 n->file_types = NULL;
03182 info->bincl_list = n;
03183 info->bincl_stack = n;
03184
03185 ++info->files;
03186 info->file_types = ((struct stab_types **)
03187 xrealloc ((PTR) info->file_types,
03188 (info->files
03189 * sizeof *info->file_types)));
03190 info->file_types[n->file] = NULL;
03191 }
03192
03193
03194
03195
03196 static const char *
03197 pop_bincl (info)
03198 struct stab_handle *info;
03199 {
03200 struct bincl_file *o;
03201
03202 o = info->bincl_stack;
03203 if (o == NULL)
03204 return info->main_filename;
03205 info->bincl_stack = o->next_stack;
03206
03207 o->file_types = info->file_types[o->file];
03208
03209 if (info->bincl_stack == NULL)
03210 return info->main_filename;
03211 return info->bincl_stack->name;
03212 }
03213
03214
03215
03216 static boolean
03217 find_excl (info, name, hash)
03218 struct stab_handle *info;
03219 const char *name;
03220 bfd_vma hash;
03221 {
03222 struct bincl_file *l;
03223
03224 ++info->files;
03225 info->file_types = ((struct stab_types **)
03226 xrealloc ((PTR) info->file_types,
03227 (info->files
03228 * sizeof *info->file_types)));
03229
03230 for (l = info->bincl_list; l != NULL; l = l->next)
03231 if (l->hash == hash && strcmp (l->name, name) == 0)
03232 break;
03233 if (l == NULL)
03234 {
03235 warn_stab (name, "Undefined N_EXCL");
03236 info->file_types[info->files - 1] = NULL;
03237 return true;
03238 }
03239
03240 info->file_types[info->files - 1] = l->file_types;
03241
03242 return true;
03243 }
03244
03245
03246
03247
03248
03249
03250 static boolean
03251 stab_record_variable (dhandle, info, name, type, kind, val)
03252 PTR dhandle;
03253 struct stab_handle *info;
03254 const char *name;
03255 debug_type type;
03256 enum debug_var_kind kind;
03257 bfd_vma val;
03258 {
03259 struct stab_pending_var *v;
03260
03261 if ((kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
03262 || ! info->within_function
03263 || (info->gcc_compiled == 0 && info->n_opt_found))
03264 return debug_record_variable (dhandle, name, type, kind, val);
03265
03266 v = (struct stab_pending_var *) xmalloc (sizeof *v);
03267 memset (v, 0, sizeof *v);
03268
03269 v->next = info->pending;
03270 v->name = name;
03271 v->type = type;
03272 v->kind = kind;
03273 v->val = val;
03274 info->pending = v;
03275
03276 return true;
03277 }
03278
03279
03280
03281
03282 static boolean
03283 stab_emit_pending_vars (dhandle, info)
03284 PTR dhandle;
03285 struct stab_handle *info;
03286 {
03287 struct stab_pending_var *v;
03288
03289 v = info->pending;
03290 while (v != NULL)
03291 {
03292 struct stab_pending_var *next;
03293
03294 if (! debug_record_variable (dhandle, v->name, v->type, v->kind, v->val))
03295 return false;
03296
03297 next = v->next;
03298 free (v);
03299 v = next;
03300 }
03301
03302 info->pending = NULL;
03303
03304 return true;
03305 }
03306
03307
03308
03309 static debug_type *
03310 stab_find_slot (info, typenums)
03311 struct stab_handle *info;
03312 const int *typenums;
03313 {
03314 int filenum;
03315 int index;
03316 struct stab_types **ps;
03317
03318 filenum = typenums[0];
03319 index = typenums[1];
03320
03321 if (filenum < 0 || (unsigned int) filenum >= info->files)
03322 {
03323 fprintf (stderr, "Type file number %d out of range\n", filenum);
03324 return NULL;
03325 }
03326 if (index < 0)
03327 {
03328 fprintf (stderr, "Type index number %d out of range\n", index);
03329 return NULL;
03330 }
03331
03332 ps = info->file_types + filenum;
03333
03334 while (index >= STAB_TYPES_SLOTS)
03335 {
03336 if (*ps == NULL)
03337 {
03338 *ps = (struct stab_types *) xmalloc (sizeof **ps);
03339 memset (*ps, 0, sizeof **ps);
03340 }
03341 ps = &(*ps)->next;
03342 index -= STAB_TYPES_SLOTS;
03343 }
03344 if (*ps == NULL)
03345 {
03346 *ps = (struct stab_types *) xmalloc (sizeof **ps);
03347 memset (*ps, 0, sizeof **ps);
03348 }
03349
03350 return (*ps)->types + index;
03351 }
03352
03353
03354
03355
03356 static debug_type
03357 stab_find_type (dhandle, info, typenums)
03358 PTR dhandle;
03359 struct stab_handle *info;
03360 const int *typenums;
03361 {
03362 debug_type *slot;
03363
03364 if (typenums[0] == 0 && typenums[1] < 0)
03365 {
03366
03367 return stab_xcoff_builtin_type (dhandle, info, typenums[1]);
03368 }
03369
03370 slot = stab_find_slot (info, typenums);
03371 if (slot == NULL)
03372 return DEBUG_TYPE_NULL;
03373
03374 if (*slot == DEBUG_TYPE_NULL)
03375 return debug_make_indirect_type (dhandle, slot, (const char *) NULL);
03376
03377 return *slot;
03378 }
03379
03380
03381
03382 static boolean
03383 stab_record_type (dhandle, info, typenums, type)
03384 PTR dhandle;
03385 struct stab_handle *info;
03386 const int *typenums;
03387 debug_type type;
03388 {
03389 debug_type *slot;
03390
03391 slot = stab_find_slot (info, typenums);
03392 if (slot == NULL)
03393 return false;
03394
03395
03396
03397 *slot = type;
03398
03399 return true;
03400 }
03401
03402
03403
03404 static debug_type
03405 stab_xcoff_builtin_type (dhandle, info, typenum)
03406 PTR dhandle;
03407 struct stab_handle *info;
03408 int typenum;
03409 {
03410 debug_type rettype;
03411 const char *name;
03412
03413 if (typenum >= 0 || typenum < -XCOFF_TYPE_COUNT)
03414 {
03415 fprintf (stderr, "Unrecognized XCOFF type %d\n", typenum);
03416 return DEBUG_TYPE_NULL;
03417 }
03418 if (info->xcoff_types[-typenum] != NULL)
03419 return info->xcoff_types[-typenum];
03420
03421 switch (-typenum)
03422 {
03423 case 1:
03424
03425
03426 name = "int";
03427 rettype = debug_make_int_type (dhandle, 4, false);
03428 break;
03429 case 2:
03430 name = "char";
03431 rettype = debug_make_int_type (dhandle, 1, false);
03432 break;
03433 case 3:
03434 name = "short";
03435 rettype = debug_make_int_type (dhandle, 2, false);
03436 break;
03437 case 4:
03438 name = "long";
03439 rettype = debug_make_int_type (dhandle, 4, false);
03440 break;
03441 case 5:
03442 name = "unsigned char";
03443 rettype = debug_make_int_type (dhandle, 1, true);
03444 break;
03445 case 6:
03446 name = "signed char";
03447 rettype = debug_make_int_type (dhandle, 1, false);
03448 break;
03449 case 7:
03450 name = "unsigned short";
03451 rettype = debug_make_int_type (dhandle, 2, true);
03452 break;
03453 case 8:
03454 name = "unsigned int";
03455 rettype = debug_make_int_type (dhandle, 4, true);
03456 break;
03457 case 9:
03458 name = "unsigned";
03459 rettype = debug_make_int_type (dhandle, 4, true);
03460 case 10:
03461 name = "unsigned long";
03462 rettype = debug_make_int_type (dhandle, 4, true);
03463 break;
03464 case 11:
03465 name = "void";
03466 rettype = debug_make_void_type (dhandle);
03467 break;
03468 case 12:
03469
03470 name = "float";
03471 rettype = debug_make_float_type (dhandle, 4);
03472 break;
03473 case 13:
03474
03475 name = "double";
03476 rettype = debug_make_float_type (dhandle, 8);
03477 break;
03478 case 14:
03479
03480
03481
03482 name = "long double";
03483 rettype = debug_make_float_type (dhandle, 8);
03484 break;
03485 case 15:
03486 name = "integer";
03487 rettype = debug_make_int_type (dhandle, 4, false);
03488 break;
03489 case 16:
03490 name = "boolean";
03491 rettype = debug_make_bool_type (dhandle, 4);
03492 break;
03493 case 17:
03494 name = "short real";
03495 rettype = debug_make_float_type (dhandle, 4);
03496 break;
03497 case 18:
03498 name = "real";
03499 rettype = debug_make_float_type (dhandle, 8);
03500 break;
03501 case 19:
03502
03503 name = "stringptr";
03504 rettype = NULL;
03505 break;
03506 case 20:
03507
03508 name = "character";
03509 rettype = debug_make_int_type (dhandle, 1, true);
03510 break;
03511 case 21:
03512 name = "logical*1";
03513 rettype = debug_make_bool_type (dhandle, 1);
03514 break;
03515 case 22:
03516 name = "logical*2";
03517 rettype = debug_make_bool_type (dhandle, 2);
03518 break;
03519 case 23:
03520 name = "logical*4";
03521 rettype = debug_make_bool_type (dhandle, 4);
03522 break;
03523 case 24:
03524 name = "logical";
03525 rettype = debug_make_bool_type (dhandle, 4);
03526 break;
03527 case 25:
03528
03529 name = "complex";
03530 rettype = debug_make_complex_type (dhandle, 8);
03531 break;
03532 case 26:
03533
03534 name = "double complex";
03535 rettype = debug_make_complex_type (dhandle, 16);
03536 break;
03537 case 27:
03538 name = "integer*1";
03539 rettype = debug_make_int_type (dhandle, 1, false);
03540 break;
03541 case 28:
03542 name = "integer*2";
03543 rettype = debug_make_int_type (dhandle, 2, false);
03544 break;
03545 case 29:
03546 name = "integer*4";
03547 rettype = debug_make_int_type (dhandle, 4, false);
03548 break;
03549 case 30:
03550
03551 name = "wchar";
03552 rettype = debug_make_int_type (dhandle, 2, false);
03553 break;
03554 case 31:
03555 name = "long long";
03556 rettype = debug_make_int_type (dhandle, 8, false);
03557 break;
03558 case 32:
03559 name = "unsigned long long";
03560 rettype = debug_make_int_type (dhandle, 8, true);
03561 break;
03562 case 33:
03563 name = "logical*8";
03564 rettype = debug_make_bool_type (dhandle, 8);
03565 break;
03566 case 34:
03567 name = "integer*8";
03568 rettype = debug_make_int_type (dhandle, 8, false);
03569 break;
03570 default:
03571 abort ();
03572 }
03573
03574 rettype = debug_name_type (dhandle, name, rettype);
03575
03576 info->xcoff_types[-typenum] = rettype;
03577
03578 return rettype;
03579 }
03580
03581
03582
03583 static debug_type
03584 stab_find_tagged_type (dhandle, info, p, len, kind)
03585 PTR dhandle;
03586 struct stab_handle *info;
03587 const char *p;
03588 int len;
03589 enum debug_type_kind kind;
03590 {
03591 char *name;
03592 debug_type dtype;
03593 struct stab_tag *st;
03594
03595 name = savestring (p, len);
03596
03597
03598
03599
03600 dtype = debug_find_tagged_type (dhandle, name, DEBUG_KIND_ILLEGAL);
03601 if (dtype != DEBUG_TYPE_NULL)
03602 {
03603 free (name);
03604 return dtype;
03605 }
03606
03607
03608 for (st = info->tags; st != NULL; st = st->next)
03609 {
03610 if (st->name[0] == name[0]
03611 && strcmp (st->name, name) == 0)
03612 {
03613 if (st->kind == DEBUG_KIND_ILLEGAL)
03614 st->kind = kind;
03615 free (name);
03616 break;
03617 }
03618 }
03619 if (st == NULL)
03620 {
03621 st = (struct stab_tag *) xmalloc (sizeof *st);
03622 memset (st, 0, sizeof *st);
03623
03624 st->next = info->tags;
03625 st->name = name;
03626 st->kind = kind;
03627 st->slot = DEBUG_TYPE_NULL;
03628 st->type = debug_make_indirect_type (dhandle, &st->slot, name);
03629 info->tags = st;
03630 }
03631
03632 return st->type;
03633 }
03634
03635
03636
03637
03638
03639
03640
03641
03642
03643
03644
03645
03646
03647
03648
03649
03650 struct stab_demangle_typestring
03651 {
03652
03653 const char *typestring;
03654
03655 unsigned int len;
03656 };
03657
03658
03659
03660
03661 struct stab_demangle_info
03662 {
03663
03664 PTR dhandle;
03665
03666 struct stab_handle *info;
03667
03668 debug_type *args;
03669
03670 boolean varargs;
03671
03672 struct stab_demangle_typestring *typestrings;
03673
03674 unsigned int typestring_count;
03675
03676 unsigned int typestring_alloc;
03677 };
03678
03679 static void stab_bad_demangle PARAMS ((const char *));
03680 static unsigned int stab_demangle_count PARAMS ((const char **));
03681 static boolean stab_demangle_get_count
03682 PARAMS ((const char **, unsigned int *));
03683 static boolean stab_demangle_prefix
03684 PARAMS ((struct stab_demangle_info *, const char **));
03685 static boolean stab_demangle_function_name
03686 PARAMS ((struct stab_demangle_info *, const char **, const char *));
03687 static boolean stab_demangle_signature
03688 PARAMS ((struct stab_demangle_info *, const char **));
03689 static boolean stab_demangle_qualified
03690 PARAMS ((struct stab_demangle_info *, const char **, debug_type *));
03691 static boolean stab_demangle_template
03692 PARAMS ((struct stab_demangle_info *, const char **));
03693 static boolean stab_demangle_class
03694 PARAMS ((struct stab_demangle_info *, const char **, const char **));
03695 static boolean stab_demangle_args
03696 PARAMS ((struct stab_demangle_info *, const char **, debug_type **,
03697 boolean *));
03698 static boolean stab_demangle_arg
03699 PARAMS ((struct stab_demangle_info *, const char **, debug_type **,
03700 unsigned int *, unsigned int *));
03701 static boolean stab_demangle_type
03702 PARAMS ((struct stab_demangle_info *, const char **, debug_type *));
03703 static boolean stab_demangle_fund_type
03704 PARAMS ((struct stab_demangle_info *, const char **, debug_type *));
03705 static boolean stab_demangle_remember_type
03706 PARAMS ((struct stab_demangle_info *, const char *, int));
03707
03708
03709
03710 static void
03711 stab_bad_demangle (s)
03712 const char *s;
03713 {
03714 fprintf (stderr, "bad mangled name `%s'\n", s);
03715 }
03716
03717
03718
03719 static unsigned int
03720 stab_demangle_count (pp)
03721 const char **pp;
03722 {
03723 unsigned int count;
03724
03725 count = 0;
03726 while (isdigit ((unsigned char) **pp))
03727 {
03728 count *= 10;
03729 count += **pp - '0';
03730 ++*pp;
03731 }
03732 return count;
03733 }
03734
03735
03736
03737
03738 static boolean
03739 stab_demangle_get_count (pp, pi)
03740 const char **pp;
03741 unsigned int *pi;
03742 {
03743 if (! isdigit ((unsigned char) **pp))
03744 return false;
03745
03746 *pi = **pp - '0';
03747 ++*pp;
03748 if (isdigit ((unsigned char) **pp))
03749 {
03750 unsigned int count;
03751 const char *p;
03752
03753 count = *pi;
03754 p = *pp;
03755 do
03756 {
03757 count *= 10;
03758 count += *p - '0';
03759 ++p;
03760 }
03761 while (isdigit ((unsigned char) *p));
03762 if (*p == '_')
03763 {
03764 *pp = p + 1;
03765 *pi = count;
03766 }
03767 }
03768
03769 return true;
03770 }
03771
03772
03773
03774
03775 static debug_type *
03776 stab_demangle_argtypes (dhandle, info, physname, pvarargs)
03777 PTR dhandle;
03778 struct stab_handle *info;
03779 const char *physname;
03780 boolean *pvarargs;
03781 {
03782 struct stab_demangle_info minfo;
03783
03784 minfo.dhandle = dhandle;
03785 minfo.info = info;
03786 minfo.args = NULL;
03787 minfo.varargs = false;
03788 minfo.typestring_alloc = 10;
03789 minfo.typestrings = ((struct stab_demangle_typestring *)
03790 xmalloc (minfo.typestring_alloc
03791 * sizeof *minfo.typestrings));
03792 minfo.typestring_count = 0;
03793
03794
03795
03796
03797 if (! stab_demangle_prefix (&minfo, &physname))
03798 goto error_return;
03799
03800 if (*physname != '\0')
03801 {
03802 if (! stab_demangle_signature (&minfo, &physname))
03803 goto error_return;
03804 }
03805
03806 free (minfo.typestrings);
03807 minfo.typestrings = NULL;
03808
03809 if (minfo.args == NULL)
03810 fprintf (stderr, "no argument types in mangled string\n");
03811
03812 *pvarargs = minfo.varargs;
03813 return minfo.args;
03814
03815 error_return:
03816 if (minfo.typestrings != NULL)
03817 free (minfo.typestrings);
03818 return NULL;
03819 }
03820
03821
03822
03823 static boolean
03824 stab_demangle_prefix (minfo, pp)
03825 struct stab_demangle_info *minfo;
03826 const char **pp;
03827 {
03828 const char *scan;
03829 unsigned int i;
03830
03831
03832
03833
03834
03835 scan = *pp;
03836 do
03837 {
03838 scan = strchr (scan, '_');
03839 }
03840 while (scan != NULL && *++scan != '_');
03841
03842 if (scan == NULL)
03843 {
03844 stab_bad_demangle (*pp);
03845 return false;
03846 }
03847
03848 --scan;
03849
03850
03851 i = strspn (scan, "_");
03852 if (i > 2)
03853 scan += i - 2;
03854
03855 if (scan == *pp
03856 && (isdigit ((unsigned char) scan[2])
03857 || scan[2] == 'Q'
03858 || scan[2] == 't'))
03859 {
03860
03861 *pp = scan + 2;
03862 return true;
03863 }
03864 else if (scan == *pp
03865 && ! isdigit ((unsigned char) scan[2])
03866 && scan[2] != 't')
03867 {
03868
03869
03870 while (*scan == '_')
03871 ++scan;
03872 scan = strstr (scan, "__");
03873 if (scan == NULL || scan[2] == '\0')
03874 {
03875 stab_bad_demangle (*pp);
03876 return false;
03877 }
03878
03879 return stab_demangle_function_name (minfo, pp, scan);
03880 }
03881 else if (scan[2] != '\0')
03882 {
03883
03884 return stab_demangle_function_name (minfo, pp, scan);
03885 }
03886 else
03887 {
03888 stab_bad_demangle (*pp);
03889 return false;
03890 }
03891
03892 }
03893
03894
03895
03896
03897
03898 static boolean
03899 stab_demangle_function_name (minfo, pp, scan)
03900 struct stab_demangle_info *minfo;
03901 const char **pp;
03902 const char *scan;
03903 {
03904 const char *name;
03905
03906
03907
03908
03909
03910
03911 name = *pp;
03912 *pp = scan + 2;
03913
03914 if (*pp - name >= 5
03915 && strncmp (name, "type", 4) == 0
03916 && (name[4] == '$' || name[4] == '.'))
03917 {
03918 const char *tem;
03919
03920
03921 tem = name + 5;
03922 if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
03923 return false;
03924 }
03925 else if (name[0] == '_'
03926 && name[1] == '_'
03927 && name[2] == 'o'
03928 && name[3] == 'p')
03929 {
03930 const char *tem;
03931
03932
03933 tem = name + 4;
03934 if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
03935 return false;
03936 }
03937
03938 return true;
03939 }
03940
03941
03942
03943
03944 static boolean
03945 stab_demangle_signature (minfo, pp)
03946 struct stab_demangle_info *minfo;
03947 const char **pp;
03948 {
03949 const char *orig;
03950 boolean expect_func, func_done;
03951 const char *hold;
03952
03953 orig = *pp;
03954
03955 expect_func = false;
03956 func_done = false;
03957 hold = NULL;
03958
03959 while (**pp != '\0')
03960 {
03961 switch (**pp)
03962 {
03963 case 'Q':
03964 hold = *pp;
03965 if (! stab_demangle_qualified (minfo, pp, (debug_type *) NULL)
03966 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
03967 return false;
03968 expect_func = true;
03969 hold = NULL;
03970 break;
03971
03972 case 'S':
03973
03974 if (hold == NULL)
03975 hold = *pp;
03976 ++*pp;
03977 break;
03978
03979 case 'C':
03980
03981 if (hold == NULL)
03982 hold = *pp;
03983 ++*pp;
03984 break;
03985
03986 case '0': case '1': case '2': case '3': case '4':
03987 case '5': case '6': case '7': case '8': case '9':
03988 if (hold == NULL)
03989 hold = *pp;
03990 if (! stab_demangle_class (minfo, pp, (const char **) NULL)
03991 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
03992 return false;
03993 expect_func = true;
03994 hold = NULL;
03995 break;
03996
03997 case 'F':
03998
03999
04000 hold = NULL;
04001 func_done = true;
04002 ++*pp;
04003 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
04004 return false;
04005 break;
04006
04007 case 't':
04008
04009 if (hold == NULL)
04010 hold = *pp;
04011 if (! stab_demangle_template (minfo, pp)
04012 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
04013 return false;
04014 hold = NULL;
04015 expect_func = true;
04016 break;
04017
04018 case '_':
04019
04020
04021
04022
04023
04024 stab_bad_demangle (orig);
04025 return false;
04026
04027 default:
04028
04029
04030 func_done = true;
04031 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
04032 return false;
04033 break;
04034 }
04035
04036 if (expect_func)
04037 {
04038 func_done = true;
04039 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
04040 return false;
04041 }
04042 }
04043
04044 if (! func_done)
04045 {
04046
04047
04048
04049
04050 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
04051 return false;
04052 }
04053
04054 return true;
04055 }
04056
04057
04058
04059
04060 static boolean
04061 stab_demangle_qualified (minfo, pp, ptype)
04062 struct stab_demangle_info *minfo;
04063 const char **pp;
04064 debug_type *ptype;
04065 {
04066 const char *orig;
04067 const char *p;
04068 unsigned int qualifiers;
04069 debug_type context;
04070
04071 orig = *pp;
04072
04073 switch ((*pp)[1])
04074 {
04075 case '_':
04076
04077
04078
04079 p = *pp + 2;
04080 if (! isdigit ((unsigned char) *p) || *p == '0')
04081 {
04082 stab_bad_demangle (orig);
04083 return false;
04084 }
04085 qualifiers = atoi (p);
04086 while (isdigit ((unsigned char) *p))
04087 ++p;
04088 if (*p != '_')
04089 {
04090 stab_bad_demangle (orig);
04091 return false;
04092 }
04093 *pp = p + 1;
04094 break;
04095
04096 case '1': case '2': case '3': case '4': case '5':
04097 case '6': case '7': case '8': case '9':
04098 qualifiers = (*pp)[1] - '0';
04099
04100 if ((*pp)[2] == '_')
04101 ++*pp;
04102 *pp += 2;
04103 break;
04104
04105 case '0':
04106 default:
04107 stab_bad_demangle (orig);
04108 return false;
04109 }
04110
04111 context = DEBUG_TYPE_NULL;
04112
04113
04114 while (qualifiers-- > 0)
04115 {
04116 if (**pp == '_')
04117 ++*pp;
04118 if (**pp == 't')
04119 {
04120
04121
04122 if (! stab_demangle_template (minfo, pp))
04123 return false;
04124 }
04125 else
04126 {
04127 unsigned int len;
04128
04129 len = stab_demangle_count (pp);
04130 if (strlen (*pp) < len)
04131 {
04132 stab_bad_demangle (orig);
04133 return false;
04134 }
04135
04136 if (ptype != NULL)
04137 {
04138 const debug_field *fields;
04139
04140 fields = NULL;
04141 if (context != DEBUG_TYPE_NULL)
04142 fields = debug_get_fields (minfo->dhandle, context);
04143
04144 context = DEBUG_TYPE_NULL;
04145
04146 if (fields != NULL)
04147 {
04148 char *name;
04149
04150
04151
04152
04153
04154
04155
04156
04157
04158 name = savestring (*pp, len);
04159
04160 for (; *fields != DEBUG_FIELD_NULL; fields++)
04161 {
04162 debug_type ft;
04163 const char *dn;
04164
04165 ft = debug_get_field_type (minfo->dhandle, *fields);
04166 if (ft == NULL)
04167 return false;
04168 dn = debug_get_type_name (minfo->dhandle, ft);
04169 if (dn != NULL && strcmp (dn, name) == 0)
04170 {
04171 context = ft;
04172 break;
04173 }
04174 }
04175
04176 free (name);
04177 }
04178
04179 if (context == DEBUG_TYPE_NULL)
04180 {
04181
04182
04183
04184
04185 if (qualifiers == 0)
04186 {
04187 char *name;
04188
04189 name = savestring (*pp, len);
04190 context = debug_find_named_type (minfo->dhandle,
04191 name);
04192 free (name);
04193 }
04194
04195 if (context == DEBUG_TYPE_NULL)
04196 {
04197 context = stab_find_tagged_type (minfo->dhandle,
04198 minfo->info,
04199 *pp, len,
04200 (qualifiers == 0
04201 ? DEBUG_KIND_ILLEGAL
04202 : DEBUG_KIND_CLASS));
04203 if (context == DEBUG_TYPE_NULL)
04204 return false;
04205 }
04206 }
04207 }
04208
04209 *pp += len;
04210 }
04211 }
04212
04213 if (ptype != NULL)
04214 *ptype = context;
04215
04216 return true;
04217 }
04218
04219
04220
04221 static boolean
04222 stab_demangle_template (minfo, pp)
04223 struct stab_demangle_info *minfo;
04224 const char **pp;
04225 {
04226 const char *orig;
04227 unsigned int r, i;
04228
04229 orig = *pp;
04230
04231 ++*pp;
04232
04233
04234 r = stab_demangle_count (pp);
04235 if (r == 0 || strlen (*pp) < r)
04236 {
04237 stab_bad_demangle (orig);
04238 return false;
04239 }
04240 *pp += r;
04241
04242
04243 if (stab_demangle_get_count (pp, &r) == 0)
04244 {
04245 stab_bad_demangle (orig);
04246 return false;
04247 }
04248
04249 for (i = 0; i < r; i++)
04250 {
04251 if (**pp == 'Z')
04252 {
04253
04254 ++*pp;
04255 if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
04256 return false;
04257 }
04258 else
04259 {
04260 const char *old_p;
04261 boolean pointerp, realp, integralp, charp, boolp;
04262 boolean done;
04263
04264 old_p = *pp;
04265 pointerp = false;
04266 realp = false;
04267 integralp = false;
04268 charp = false;
04269 boolp = false;
04270 done = false;
04271
04272
04273
04274 if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
04275 return false;
04276
04277 while (*old_p != '\0' && ! done)
04278 {
04279 switch (*old_p)
04280 {
04281 case 'P':
04282 case 'p':
04283 case 'R':
04284 pointerp = true;
04285 done = true;
04286 break;
04287 case 'C':
04288 case 'S':
04289 case 'U':
04290 case 'V':
04291 case 'F':
04292 case 'M':
04293 case 'O':
04294 ++old_p;
04295 break;
04296 case 'Q':
04297 integralp = true;
04298 done = true;
04299 break;
04300 case 'T':
04301 abort ();
04302 case 'v':
04303 abort ();
04304 case 'x':
04305 case 'l':
04306 case 'i':
04307 case 's':
04308 case 'w':
04309 integralp = true;
04310 done = true;
04311 break;
04312 case 'b':
04313 boolp = true;
04314 done = true;
04315 break;
04316 case 'c':
04317 charp = true;
04318 done = true;
04319 break;
04320 case 'r':
04321 case 'd':
04322 case 'f':
04323 realp = true;
04324 done = true;
04325 break;
04326 default:
04327
04328 integralp = true;
04329 done = true;
04330 break;
04331 }
04332 }
04333
04334 if (integralp)
04335 {
04336 if (**pp == 'm')
04337 ++*pp;
04338 while (isdigit ((unsigned char) **pp))
04339 ++*pp;
04340 }
04341 else if (charp)
04342 {
04343 unsigned int val;
04344
04345 if (**pp == 'm')
04346 ++*pp;
04347 val = stab_demangle_count (pp);
04348 if (val == 0)
04349 {
04350 stab_bad_demangle (orig);
04351 return false;
04352 }
04353 }
04354 else if (boolp)
04355 {
04356 unsigned int val;
04357
04358 val = stab_demangle_count (pp);
04359 if (val != 0 && val != 1)
04360 {
04361 stab_bad_demangle (orig);
04362 return false;
04363 }
04364 }
04365 else if (realp)
04366 {
04367 if (**pp == 'm')
04368 ++*pp;
04369 while (isdigit ((unsigned char) **pp))
04370 ++*pp;
04371 if (**pp == '.')
04372 {
04373 ++*pp;
04374 while (isdigit ((unsigned char) **pp))
04375 ++*pp;
04376 }
04377 if (**pp == 'e')
04378 {
04379 ++*pp;
04380 while (isdigit ((unsigned char) **pp))
04381 ++*pp;
04382 }
04383 }
04384 else if (pointerp)
04385 {
04386 unsigned int len;
04387
04388 if (! stab_demangle_get_count (pp, &len))
04389 {
04390 stab_bad_demangle (orig);
04391 return false;
04392 }
04393 *pp += len;
04394 }
04395 }
04396 }
04397
04398 return true;
04399 }
04400
04401
04402
04403 static boolean
04404 stab_demangle_class (minfo, pp, pstart)
04405 struct stab_demangle_info *minfo;
04406 const char **pp;
04407 const char **pstart;
04408 {
04409 const char *orig;
04410 unsigned int n;
04411
04412 orig = *pp;
04413
04414 n = stab_demangle_count (pp);
04415 if (strlen (*pp) < n)
04416 {
04417 stab_bad_demangle (orig);
04418 return false;
04419 }
04420
04421 if (pstart != NULL)
04422 *pstart = *pp;
04423
04424 *pp += n;
04425
04426 return true;
04427 }
04428
04429
04430
04431
04432 static boolean
04433 stab_demangle_args (minfo, pp, pargs, pvarargs)
04434 struct stab_demangle_info *minfo;
04435 const char **pp;
04436 debug_type **pargs;
04437 boolean *pvarargs;
04438 {
04439 const char *orig;
04440 unsigned int alloc, count;
04441
04442 orig = *pp;
04443
04444 alloc = 10;
04445 if (pargs != NULL)
04446 {
04447 *pargs = (debug_type *) xmalloc (alloc * sizeof **pargs);
04448 *pvarargs = false;
04449 }
04450 count = 0;
04451
04452 while (**pp != '_' && **pp != '\0' && **pp != 'e')
04453 {
04454 if (**pp == 'N' || **pp == 'T')
04455 {
04456 char temptype;
04457 unsigned int r, t;
04458
04459 temptype = **pp;
04460 ++*pp;
04461
04462 if (temptype == 'T')
04463 r = 1;
04464 else
04465 {
04466 if (! stab_demangle_get_count (pp, &r))
04467 {
04468 stab_bad_demangle (orig);
04469 return false;
04470 }
04471 }
04472
04473 if (! stab_demangle_get_count (pp, &t))
04474 {
04475 stab_bad_demangle (orig);
04476 return false;
04477 }
04478
04479 if (t >= minfo->typestring_count)
04480 {
04481 stab_bad_demangle (orig);
04482 return false;
04483 }
04484 while (r-- > 0)
04485 {
04486 const char *tem;
04487
04488 tem = minfo->typestrings[t].typestring;
04489 if (! stab_demangle_arg (minfo, &tem, pargs, &count, &alloc))
04490 return false;
04491 }
04492 }
04493 else
04494 {
04495 if (! stab_demangle_arg (minfo, pp, pargs, &count, &alloc))
04496 return false;
04497 }
04498 }
04499
04500 if (pargs != NULL)
04501 (*pargs)[count] = DEBUG_TYPE_NULL;
04502
04503 if (**pp == 'e')
04504 {
04505 if (pargs != NULL)
04506 *pvarargs = true;
04507 ++*pp;
04508 }
04509
04510 return true;
04511 }
04512
04513
04514
04515 static boolean
04516 stab_demangle_arg (minfo, pp, pargs, pcount, palloc)
04517 struct stab_demangle_info *minfo;
04518 const char **pp;
04519 debug_type **pargs;
04520 unsigned int *pcount;
04521 unsigned int *palloc;
04522 {
04523 const char *start;
04524 debug_type type;
04525
04526 start = *pp;
04527 if (! stab_demangle_type (minfo, pp,
04528 pargs == NULL ? (debug_type *) NULL : &type)
04529 || ! stab_demangle_remember_type (minfo, start, *pp - start))
04530 return false;
04531
04532 if (pargs != NULL)
04533 {
04534 if (type == DEBUG_TYPE_NULL)
04535 return false;
04536
04537 if (*pcount + 1 >= *palloc)
04538 {
04539 *palloc += 10;
04540 *pargs = ((debug_type *)
04541 xrealloc (*pargs, *palloc * sizeof **pargs));
04542 }
04543 (*pargs)[*pcount] = type;
04544 ++*pcount;
04545 }
04546
04547 return true;
04548 }
04549
04550
04551
04552
04553 static boolean
04554 stab_demangle_type (minfo, pp, ptype)
04555 struct stab_demangle_info *minfo;
04556 const char **pp;
04557 debug_type *ptype;
04558 {
04559 const char *orig;
04560
04561 orig = *pp;
04562
04563 switch (**pp)
04564 {
04565 case 'P':
04566 case 'p':
04567
04568 ++*pp;
04569 if (! stab_demangle_type (minfo, pp, ptype))
04570 return false;
04571 if (ptype != NULL)
04572 *ptype = debug_make_pointer_type (minfo->dhandle, *ptype);
04573 break;
04574
04575 case 'R':
04576
04577 ++*pp;
04578 if (! stab_demangle_type (minfo, pp, ptype))
04579 return false;
04580 if (ptype != NULL)
04581 *ptype = debug_make_reference_type (minfo->dhandle, *ptype);
04582 break;
04583
04584 case 'A':
04585
04586 {
04587 unsigned long high;
04588
04589 ++*pp;
04590 high = 0;
04591 while (**pp != '\0' && **pp != '_')
04592 {
04593 if (! isdigit ((unsigned char) **pp))
04594 {
04595 stab_bad_demangle (orig);
04596 return false;
04597 }
04598 high *= 10;
04599 high += **pp - '0';
04600 ++*pp;
04601 }
04602 if (**pp != '_')
04603 {
04604 stab_bad_demangle (orig);
04605 return false;
04606 }
04607 ++*pp;
04608
04609 if (! stab_demangle_type (minfo, pp, ptype))
04610 return false;
04611 if (ptype != NULL)
04612 {
04613 debug_type int_type;
04614
04615 int_type = debug_find_named_type (minfo->dhandle, "int");
04616 if (int_type == NULL)
04617 int_type = debug_make_int_type (minfo->dhandle, 4, false);
04618 *ptype = debug_make_array_type (minfo->dhandle, *ptype, int_type,
04619 0, high, false);
04620 }
04621 }
04622 break;
04623
04624 case 'T':
04625
04626 {
04627 unsigned int i;
04628 const char *p;
04629
04630 ++*pp;
04631 if (! stab_demangle_get_count (pp, &i))
04632 {
04633 stab_bad_demangle (orig);
04634 return false;
04635 }
04636 if (i >= minfo->typestring_count)
04637 {
04638 stab_bad_demangle (orig);
04639 return false;
04640 }
04641 p = minfo->typestrings[i].typestring;
04642 if (! stab_demangle_type (minfo, &p, ptype))
04643 return false;
04644 }
04645 break;
04646
04647 case 'F':
04648
04649 {
04650 debug_type *args;
04651 boolean varargs;
04652
04653 ++*pp;
04654 if (! stab_demangle_args (minfo, pp,
04655 (ptype == NULL
04656 ? (debug_type **) NULL
04657 : &args),
04658 (ptype == NULL
04659 ? (boolean *) NULL
04660 : &varargs)))
04661 return false;
04662 if (**pp != '_')
04663 {
04664
04665
04666
04667 stab_bad_demangle (orig);
04668 return false;
04669 }
04670 ++*pp;
04671 if (! stab_demangle_type (minfo, pp, ptype))
04672 return false;
04673 if (ptype != NULL)
04674 *ptype = debug_make_function_type (minfo->dhandle, *ptype, args,
04675 varargs);
04676
04677 }
04678 break;
04679
04680 case 'M':
04681 case 'O':
04682 {
04683 boolean memberp, constp, volatilep;
04684 debug_type *args;
04685 boolean varargs;
04686 unsigned int n;
04687 const char *name;
04688
04689 memberp = **pp == 'M';
04690 constp = false;
04691 volatilep = false;
04692 args = NULL;
04693 varargs = false;
04694
04695 ++*pp;
04696 if (! isdigit ((unsigned char) **pp))
04697 {
04698 stab_bad_demangle (orig);
04699 return false;
04700 }
04701 n = stab_demangle_count (pp);
04702 if (strlen (*pp) < n)
04703 {
04704 stab_bad_demangle (orig);
04705 return false;
04706 }
04707 name = *pp;
04708 *pp += n;
04709
04710 if (memberp)
04711 {
04712 if (**pp == 'C')
04713 {
04714 constp = true;
04715 ++*pp;
04716 }
04717 else if (**pp == 'V')
04718 {
04719 volatilep = true;
04720 ++*pp;
04721 }
04722 if (**pp != 'F')
04723 {
04724 stab_bad_demangle (orig);
04725 return false;
04726 }
04727 ++*pp;
04728 if (! stab_demangle_args (minfo, pp,
04729 (ptype == NULL
04730 ? (debug_type **) NULL
04731 : &args),
04732 (ptype == NULL
04733 ? (boolean *) NULL
04734 : &varargs)))
04735 return false;
04736 }
04737
04738 if (**pp != '_')
04739 {
04740 stab_bad_demangle (orig);
04741 return false;
04742 }
04743 ++*pp;
04744
04745 if (! stab_demangle_type (minfo, pp, ptype))
04746 return false;
04747
04748 if (ptype != NULL)
04749 {
04750 debug_type class_type;
04751
04752 class_type = stab_find_tagged_type (minfo->dhandle, minfo->info,
04753 name, (int) n,
04754 DEBUG_KIND_CLASS);
04755 if (class_type == DEBUG_TYPE_NULL)
04756 return false;
04757
04758 if (! memberp)
04759 *ptype = debug_make_offset_type (minfo->dhandle, class_type,
04760 *ptype);
04761 else
04762 {
04763
04764
04765 *ptype = debug_make_method_type (minfo->dhandle, *ptype,
04766 class_type, args, varargs);
04767 }
04768 }
04769 }
04770 break;
04771
04772 case 'G':
04773 ++*pp;
04774 if (! stab_demangle_type (minfo, pp, ptype))
04775 return false;
04776 break;
04777
04778 case 'C':
04779 ++*pp;
04780 if (! stab_demangle_type (minfo, pp, ptype))
04781 return false;
04782 if (ptype != NULL)
04783 *ptype = debug_make_const_type (minfo->dhandle, *ptype);
04784 break;
04785
04786 case 'Q':
04787 {
04788 const char *hold;
04789
04790 hold = *pp;
04791 if (! stab_demangle_qualified (minfo, pp, ptype))
04792 return false;
04793 }
04794 break;
04795
04796 default:
04797 if (! stab_demangle_fund_type (minfo, pp, ptype))
04798 return false;
04799 break;
04800 }
04801
04802 return true;
04803 }
04804
04805
04806
04807
04808 static boolean
04809 stab_demangle_fund_type (minfo, pp, ptype)
04810 struct stab_demangle_info *minfo;
04811 const char **pp;
04812 debug_type *ptype;
04813 {
04814 const char *orig;
04815 boolean constp, volatilep, unsignedp, signedp;
04816 boolean done;
04817
04818 orig = *pp;
04819
04820 constp = false;
04821 volatilep = false;
04822 unsignedp = false;
04823 signedp = false;
04824
04825 done = false;
04826 while (! done)
04827 {
04828 switch (**pp)
04829 {
04830 case 'C':
04831 constp = true;
04832 ++*pp;
04833 break;
04834
04835 case 'U':
04836 unsignedp = true;
04837 ++*pp;
04838 break;
04839
04840 case 'S':
04841 signedp = true;
04842 ++*pp;
04843 break;
04844
04845 case 'V':
04846 volatilep = true;
04847 ++*pp;
04848 break;
04849
04850 default:
04851 done = true;
04852 break;
04853 }
04854 }
04855
04856 switch (**pp)
04857 {
04858 case '\0':
04859 case '_':
04860
04861 stab_bad_demangle (orig);
04862 break;
04863
04864 case 'v':
04865 if (ptype != NULL)
04866 {
04867 *ptype = debug_find_named_type (minfo->dhandle, "void");
04868 if (*ptype == DEBUG_TYPE_NULL)
04869 *ptype = debug_make_void_type (minfo->dhandle);
04870 }
04871 ++*pp;
04872 break;
04873
04874 case 'x':
04875 if (ptype != NULL)
04876 {
04877 *ptype = debug_find_named_type (minfo->dhandle,
04878 (unsignedp
04879 ? "long long unsigned int"
04880 : "long long int"));
04881 if (*ptype == DEBUG_TYPE_NULL)
04882 *ptype = debug_make_int_type (minfo->dhandle, 8, unsignedp);
04883 }
04884 ++*pp;
04885 break;
04886
04887 case 'l':
04888 if (ptype != NULL)
04889 {
04890 *ptype = debug_find_named_type (minfo->dhandle,
04891 (unsignedp
04892 ? "long unsigned int"
04893 : "long int"));
04894 if (*ptype == DEBUG_TYPE_NULL)
04895 *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
04896 }
04897 ++*pp;
04898 break;
04899
04900 case 'i':
04901 if (ptype != NULL)
04902 {
04903 *ptype = debug_find_named_type (minfo->dhandle,
04904 (unsignedp
04905 ? "unsigned int"
04906 : "int"));
04907 if (*ptype == DEBUG_TYPE_NULL)
04908 *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
04909 }
04910 ++*pp;
04911 break;
04912
04913 case 's':
04914 if (ptype != NULL)
04915 {
04916 *ptype = debug_find_named_type (minfo->dhandle,
04917 (unsignedp
04918 ? "short unsigned int"
04919 : "short int"));
04920 if (*ptype == DEBUG_TYPE_NULL)
04921 *ptype = debug_make_int_type (minfo->dhandle, 2, unsignedp);
04922 }
04923 ++*pp;
04924 break;
04925
04926 case 'b':
04927 if (ptype != NULL)
04928 {
04929 *ptype = debug_find_named_type (minfo->dhandle, "bool");
04930 if (*ptype == DEBUG_TYPE_NULL)
04931 *ptype = debug_make_bool_type (minfo->dhandle, 4);
04932 }
04933 ++*pp;
04934 break;
04935
04936 case 'c':
04937 if (ptype != NULL)
04938 {
04939 *ptype = debug_find_named_type (minfo->dhandle,
04940 (unsignedp
04941 ? "unsigned char"
04942 : (signedp
04943 ? "signed char"
04944 : "char")));
04945 if (*ptype == DEBUG_TYPE_NULL)
04946 *ptype = debug_make_int_type (minfo->dhandle, 1, unsignedp);
04947 }
04948 ++*pp;
04949 break;
04950
04951 case 'w':
04952 if (ptype != NULL)
04953 {
04954 *ptype = debug_find_named_type (minfo->dhandle, "__wchar_t");
04955 if (*ptype == DEBUG_TYPE_NULL)
04956 *ptype = debug_make_int_type (minfo->dhandle, 2, true);
04957 }
04958 ++*pp;
04959 break;
04960
04961 case 'r':
04962 if (ptype != NULL)
04963 {
04964 *ptype = debug_find_named_type (minfo->dhandle, "long double");
04965 if (*ptype == DEBUG_TYPE_NULL)
04966 *ptype = debug_make_float_type (minfo->dhandle, 8);
04967 }
04968 ++*pp;
04969 break;
04970
04971 case 'd':
04972 if (ptype != NULL)
04973 {
04974 *ptype = debug_find_named_type (minfo->dhandle, "double");
04975 if (*ptype == DEBUG_TYPE_NULL)
04976 *ptype = debug_make_float_type (minfo->dhandle, 8);
04977 }
04978 ++*pp;
04979 break;
04980
04981 case 'f':
04982 if (ptype != NULL)
04983 {
04984 *ptype = debug_find_named_type (minfo->dhandle, "float");
04985 if (*ptype == DEBUG_TYPE_NULL)
04986 *ptype = debug_make_float_type (minfo->dhandle, 4);
04987 }
04988 ++*pp;
04989 break;
04990
04991 case 'G':
04992 ++*pp;
04993 if (! isdigit ((unsigned char) **pp))
04994 {
04995 stab_bad_demangle (orig);
04996 return false;
04997 }
04998
04999 case '0': case '1': case '2': case '3': case '4':
05000 case '5': case '6': case '7': case '8': case '9':
05001 {
05002 const char *hold;
05003
05004 if (! stab_demangle_class (minfo, pp, &hold))
05005 return false;
05006 if (ptype != NULL)
05007 {
05008 char *name;
05009
05010 name = savestring (hold, *pp - hold);
05011 *ptype = debug_find_named_type (minfo->dhandle, name);
05012 if (*ptype == DEBUG_TYPE_NULL)
05013 {
05014
05015
05016 *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info,
05017 hold, *pp - hold,
05018 DEBUG_KIND_ILLEGAL);
05019 }
05020 free (name);
05021 }
05022 }
05023 break;
05024
05025 case 't':
05026 if (! stab_demangle_template (minfo, pp))
05027 return false;
05028 if (ptype != NULL)
05029 {
05030 debug_type t;
05031
05032
05033
05034
05035
05036
05037 t = debug_make_void_type (minfo->dhandle);
05038 t = debug_make_pointer_type (minfo->dhandle, t);
05039 t = debug_name_type (minfo->dhandle, "TEMPLATE", t);
05040 *ptype = t;
05041 }
05042 break;
05043
05044 default:
05045 stab_bad_demangle (orig);
05046 return false;
05047 }
05048
05049 if (ptype != NULL)
05050 {
05051 if (constp)
05052 *ptype = debug_make_const_type (minfo->dhandle, *ptype);
05053 if (volatilep)
05054 *ptype = debug_make_volatile_type (minfo->dhandle, *ptype);
05055 }
05056
05057 return true;
05058 }
05059
05060
05061
05062 static boolean
05063 stab_demangle_remember_type (minfo, p, len)
05064 struct stab_demangle_info *minfo;
05065 const char *p;
05066 int len;
05067 {
05068 if (minfo->typestring_count >= minfo->typestring_alloc)
05069 {
05070 minfo->typestring_alloc += 10;
05071 minfo->typestrings = ((struct stab_demangle_typestring *)
05072 xrealloc (minfo->typestrings,
05073 (minfo->typestring_alloc
05074 * sizeof *minfo->typestrings)));
05075 }
05076
05077 minfo->typestrings[minfo->typestring_count].typestring = p;
05078 minfo->typestrings[minfo->typestring_count].len = (unsigned int) len;
05079 ++minfo->typestring_count;
05080
05081 return true;
05082 }