Back to index

cell-binutils  2.17cvs20070401
ieee.c
Go to the documentation of this file.
00001 /* ieee.c -- Read and write IEEE-695 debugging information.
00002    Copyright 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2006
00003    Free Software Foundation, Inc.
00004    Written by Ian Lance Taylor <ian@cygnus.com>.
00005 
00006    This file is part of GNU Binutils.
00007 
00008    This program is free software; you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; either version 2 of the License, or
00011    (at your option) any later version.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
00021    02110-1301, USA.  */
00022 
00023 /* This file reads and writes IEEE-695 debugging information.  */
00024 
00025 #include <stdio.h>
00026 #include <assert.h>
00027 
00028 #include "bfd.h"
00029 #include "ieee.h"
00030 #include "bucomm.h"
00031 #include "libiberty.h"
00032 #include "debug.h"
00033 #include "budbg.h"
00034 #include "filenames.h"
00035 
00036 /* This structure holds an entry on the block stack.  */
00037 
00038 struct ieee_block
00039 {
00040   /* The kind of block.  */
00041   int kind;
00042   /* The source file name, for a BB5 block.  */
00043   const char *filename;
00044   /* The index of the function type, for a BB4 or BB6 block.  */
00045   unsigned int fnindx;
00046   /* TRUE if this function is being skipped.  */
00047   bfd_boolean skip;
00048 };
00049 
00050 /* This structure is the block stack.  */
00051 
00052 #define BLOCKSTACK_SIZE (16)
00053 
00054 struct ieee_blockstack
00055 {
00056   /* The stack pointer.  */
00057   struct ieee_block *bsp;
00058   /* The stack.  */
00059   struct ieee_block stack[BLOCKSTACK_SIZE];
00060 };
00061 
00062 /* This structure holds information for a variable.  */
00063 
00064 struct ieee_var
00065 {
00066   /* Start of name.  */
00067   const char *name;
00068   /* Length of name.  */
00069   unsigned long namlen;
00070   /* Type.  */
00071   debug_type type;
00072   /* Slot if we make an indirect type.  */
00073   debug_type *pslot;
00074   /* Kind of variable or function.  */
00075   enum
00076     {
00077       IEEE_UNKNOWN,
00078       IEEE_EXTERNAL,
00079       IEEE_GLOBAL,
00080       IEEE_STATIC,
00081       IEEE_LOCAL,
00082       IEEE_FUNCTION
00083     } kind;
00084 };
00085 
00086 /* This structure holds all the variables.  */
00087 
00088 struct ieee_vars
00089 {
00090   /* Number of slots allocated.  */
00091   unsigned int alloc;
00092   /* Variables.  */
00093   struct ieee_var *vars;
00094 };
00095 
00096 /* This structure holds information for a type.  We need this because
00097    we don't want to represent bitfields as real types.  */
00098 
00099 struct ieee_type
00100 {
00101   /* Type.  */
00102   debug_type type;
00103   /* Slot if this is type is referenced before it is defined.  */
00104   debug_type *pslot;
00105   /* Slots for arguments if we make indirect types for them.  */
00106   debug_type *arg_slots;
00107   /* If this is a bitfield, this is the size in bits.  If this is not
00108      a bitfield, this is zero.  */
00109   unsigned long bitsize;
00110 };
00111 
00112 /* This structure holds all the type information.  */
00113 
00114 struct ieee_types
00115 {
00116   /* Number of slots allocated.  */
00117   unsigned int alloc;
00118   /* Types.  */
00119   struct ieee_type *types;
00120   /* Builtin types.  */
00121 #define BUILTIN_TYPE_COUNT (60)
00122   debug_type builtins[BUILTIN_TYPE_COUNT];
00123 };
00124 
00125 /* This structure holds a linked last of structs with their tag names,
00126    so that we can convert them to C++ classes if necessary.  */
00127 
00128 struct ieee_tag
00129 {
00130   /* Next tag.  */
00131   struct ieee_tag *next;
00132   /* This tag name.  */
00133   const char *name;
00134   /* The type of the tag.  */
00135   debug_type type;
00136   /* The tagged type is an indirect type pointing at this slot.  */
00137   debug_type slot;
00138   /* This is an array of slots used when a field type is converted
00139      into a indirect type, in case it needs to be later converted into
00140      a reference type.  */
00141   debug_type *fslots;
00142 };
00143 
00144 /* This structure holds the information we pass around to the parsing
00145    functions.  */
00146 
00147 struct ieee_info
00148 {
00149   /* The debugging handle.  */
00150   void *dhandle;
00151   /* The BFD.  */
00152   bfd *abfd;
00153   /* The start of the bytes to be parsed.  */
00154   const bfd_byte *bytes;
00155   /* The end of the bytes to be parsed.  */
00156   const bfd_byte *pend;
00157   /* The block stack.  */
00158   struct ieee_blockstack blockstack;
00159   /* Whether we have seen a BB1 or BB2.  */
00160   bfd_boolean saw_filename;
00161   /* The variables.  */
00162   struct ieee_vars vars;
00163   /* The global variables, after a global typedef block.  */
00164   struct ieee_vars *global_vars;
00165   /* The types.  */
00166   struct ieee_types types;
00167   /* The global types, after a global typedef block.  */
00168   struct ieee_types *global_types;
00169   /* The list of tagged structs.  */
00170   struct ieee_tag *tags;
00171 };
00172 
00173 /* Basic builtin types, not including the pointers.  */
00174 
00175 enum builtin_types
00176 {
00177   builtin_unknown = 0,
00178   builtin_void = 1,
00179   builtin_signed_char = 2,
00180   builtin_unsigned_char = 3,
00181   builtin_signed_short_int = 4,
00182   builtin_unsigned_short_int = 5,
00183   builtin_signed_long = 6,
00184   builtin_unsigned_long = 7,
00185   builtin_signed_long_long = 8,
00186   builtin_unsigned_long_long = 9,
00187   builtin_float = 10,
00188   builtin_double = 11,
00189   builtin_long_double = 12,
00190   builtin_long_long_double = 13,
00191   builtin_quoted_string = 14,
00192   builtin_instruction_address = 15,
00193   builtin_int = 16,
00194   builtin_unsigned = 17,
00195   builtin_unsigned_int = 18,
00196   builtin_char = 19,
00197   builtin_long = 20,
00198   builtin_short = 21,
00199   builtin_unsigned_short = 22,
00200   builtin_short_int = 23,
00201   builtin_signed_short = 24,
00202   builtin_bcd_float = 25
00203 };
00204 
00205 /* These are the values found in the derivation flags of a 'b'
00206    component record of a 'T' type extension record in a C++ pmisc
00207    record.  These are bitmasks.  */
00208 
00209 /* Set for a private base class, clear for a public base class.
00210    Protected base classes are not supported.  */
00211 #define BASEFLAGS_PRIVATE (0x1)
00212 /* Set for a virtual base class.  */
00213 #define BASEFLAGS_VIRTUAL (0x2)
00214 /* Set for a friend class, clear for a base class.  */
00215 #define BASEFLAGS_FRIEND (0x10)
00216 
00217 /* These are the values found in the specs flags of a 'd', 'm', or 'v'
00218    component record of a 'T' type extension record in a C++ pmisc
00219    record.  The same flags are used for a 'M' record in a C++ pmisc
00220    record.  */
00221 
00222 /* The lower two bits hold visibility information.  */
00223 #define CXXFLAGS_VISIBILITY (0x3)
00224 /* This value in the lower two bits indicates a public member.  */
00225 #define CXXFLAGS_VISIBILITY_PUBLIC (0x0)
00226 /* This value in the lower two bits indicates a private member.  */
00227 #define CXXFLAGS_VISIBILITY_PRIVATE (0x1)
00228 /* This value in the lower two bits indicates a protected member.  */
00229 #define CXXFLAGS_VISIBILITY_PROTECTED (0x2)
00230 /* Set for a static member.  */
00231 #define CXXFLAGS_STATIC (0x4)
00232 /* Set for a virtual override.  */
00233 #define CXXFLAGS_OVERRIDE (0x8)
00234 /* Set for a friend function.  */
00235 #define CXXFLAGS_FRIEND (0x10)
00236 /* Set for a const function.  */
00237 #define CXXFLAGS_CONST (0x20)
00238 /* Set for a volatile function.  */
00239 #define CXXFLAGS_VOLATILE (0x40)
00240 /* Set for an overloaded function.  */
00241 #define CXXFLAGS_OVERLOADED (0x80)
00242 /* Set for an operator function.  */
00243 #define CXXFLAGS_OPERATOR (0x100)
00244 /* Set for a constructor or destructor.  */
00245 #define CXXFLAGS_CTORDTOR (0x400)
00246 /* Set for a constructor.  */
00247 #define CXXFLAGS_CTOR (0x200)
00248 /* Set for an inline function.  */
00249 #define CXXFLAGS_INLINE (0x800)
00250 
00251 /* Local functions.  */
00252 
00253 static void ieee_error (struct ieee_info *, const bfd_byte *, const char *);
00254 static void ieee_eof (struct ieee_info *);
00255 static char *savestring (const char *, unsigned long);
00256 static bfd_boolean ieee_read_number
00257   (struct ieee_info *, const bfd_byte **, bfd_vma *);
00258 static bfd_boolean ieee_read_optional_number
00259   (struct ieee_info *, const bfd_byte **, bfd_vma *, bfd_boolean *);
00260 static bfd_boolean ieee_read_id
00261   (struct ieee_info *, const bfd_byte **, const char **, unsigned long *);
00262 static bfd_boolean ieee_read_optional_id
00263   (struct ieee_info *, const bfd_byte **, const char **, unsigned long *,
00264    bfd_boolean *);
00265 static bfd_boolean ieee_read_expression
00266   (struct ieee_info *, const bfd_byte **, bfd_vma *);
00267 static debug_type ieee_builtin_type
00268   (struct ieee_info *, const bfd_byte *, unsigned int);
00269 static bfd_boolean ieee_alloc_type
00270   (struct ieee_info *, unsigned int, bfd_boolean);
00271 static bfd_boolean ieee_read_type_index
00272   (struct ieee_info *, const bfd_byte **, debug_type *);
00273 static int ieee_regno_to_genreg (bfd *, int);
00274 static int ieee_genreg_to_regno (bfd *, int);
00275 static bfd_boolean parse_ieee_bb (struct ieee_info *, const bfd_byte **);
00276 static bfd_boolean parse_ieee_be (struct ieee_info *, const bfd_byte **);
00277 static bfd_boolean parse_ieee_nn (struct ieee_info *, const bfd_byte **);
00278 static bfd_boolean parse_ieee_ty (struct ieee_info *, const bfd_byte **);
00279 static bfd_boolean parse_ieee_atn (struct ieee_info *, const bfd_byte **);
00280 static bfd_boolean ieee_read_cxx_misc
00281   (struct ieee_info *, const bfd_byte **, unsigned long);
00282 static bfd_boolean ieee_read_cxx_class
00283   (struct ieee_info *, const bfd_byte **, unsigned long);
00284 static bfd_boolean ieee_read_cxx_defaults
00285   (struct ieee_info *, const bfd_byte **, unsigned long);
00286 static bfd_boolean ieee_read_reference
00287   (struct ieee_info *, const bfd_byte **);
00288 static bfd_boolean ieee_require_asn
00289   (struct ieee_info *, const bfd_byte **, bfd_vma *);
00290 static bfd_boolean ieee_require_atn65
00291   (struct ieee_info *, const bfd_byte **, const char **, unsigned long *);
00292 
00293 /* Report an error in the IEEE debugging information.  */
00294 
00295 static void
00296 ieee_error (struct ieee_info *info, const bfd_byte *p, const char *s)
00297 {
00298   if (p != NULL)
00299     fprintf (stderr, "%s: 0x%lx: %s (0x%x)\n", bfd_get_filename (info->abfd),
00300             (unsigned long) (p - info->bytes), s, *p);
00301   else
00302     fprintf (stderr, "%s: %s\n", bfd_get_filename (info->abfd), s);
00303 }
00304 
00305 /* Report an unexpected EOF in the IEEE debugging information.  */
00306 
00307 static void
00308 ieee_eof (struct ieee_info *info)
00309 {
00310   ieee_error (info, (const bfd_byte *) NULL,
00311              _("unexpected end of debugging information"));
00312 }
00313 
00314 /* Save a string in memory.  */
00315 
00316 static char *
00317 savestring (const char *start, unsigned long len)
00318 {
00319   char *ret;
00320 
00321   ret = (char *) xmalloc (len + 1);
00322   memcpy (ret, start, len);
00323   ret[len] = '\0';
00324   return ret;
00325 }
00326 
00327 /* Read a number which must be present in an IEEE file.  */
00328 
00329 static bfd_boolean
00330 ieee_read_number (struct ieee_info *info, const bfd_byte **pp, bfd_vma *pv)
00331 {
00332   return ieee_read_optional_number (info, pp, pv, (bfd_boolean *) NULL);
00333 }
00334 
00335 /* Read a number in an IEEE file.  If ppresent is not NULL, the number
00336    need not be there.  */
00337 
00338 static bfd_boolean
00339 ieee_read_optional_number (struct ieee_info *info, const bfd_byte **pp,
00340                         bfd_vma *pv, bfd_boolean *ppresent)
00341 {
00342   ieee_record_enum_type b;
00343 
00344   if (*pp >= info->pend)
00345     {
00346       if (ppresent != NULL)
00347        {
00348          *ppresent = FALSE;
00349          return TRUE;
00350        }
00351       ieee_eof (info);
00352       return FALSE;
00353     }
00354 
00355   b = (ieee_record_enum_type) **pp;
00356   ++*pp;
00357 
00358   if (b <= ieee_number_end_enum)
00359     {
00360       *pv = (bfd_vma) b;
00361       if (ppresent != NULL)
00362        *ppresent = TRUE;
00363       return TRUE;
00364     }
00365 
00366   if (b >= ieee_number_repeat_start_enum && b <= ieee_number_repeat_end_enum)
00367     {
00368       unsigned int i;
00369 
00370       i = (int) b - (int) ieee_number_repeat_start_enum;
00371       if (*pp + i - 1 >= info->pend)
00372        {
00373          ieee_eof (info);
00374          return FALSE;
00375        }
00376 
00377       *pv = 0;
00378       for (; i > 0; i--)
00379        {
00380          *pv <<= 8;
00381          *pv += **pp;
00382          ++*pp;
00383        }
00384 
00385       if (ppresent != NULL)
00386        *ppresent = TRUE;
00387 
00388       return TRUE;
00389     }
00390 
00391   if (ppresent != NULL)
00392     {
00393       --*pp;
00394       *ppresent = FALSE;
00395       return TRUE;
00396     }
00397 
00398   ieee_error (info, *pp - 1, _("invalid number"));
00399   return FALSE;
00400 }
00401 
00402 /* Read a required string from an IEEE file.  */
00403 
00404 static bfd_boolean
00405 ieee_read_id (struct ieee_info *info, const bfd_byte **pp,
00406              const char **pname, unsigned long *pnamlen)
00407 {
00408   return ieee_read_optional_id (info, pp, pname, pnamlen, (bfd_boolean *) NULL);
00409 }
00410 
00411 /* Read a string from an IEEE file.  If ppresent is not NULL, the
00412    string is optional.  */
00413 
00414 static bfd_boolean
00415 ieee_read_optional_id (struct ieee_info *info, const bfd_byte **pp,
00416                      const char **pname, unsigned long *pnamlen,
00417                      bfd_boolean *ppresent)
00418 {
00419   bfd_byte b;
00420   unsigned long len;
00421 
00422   if (*pp >= info->pend)
00423     {
00424       ieee_eof (info);
00425       return FALSE;
00426     }
00427 
00428   b = **pp;
00429   ++*pp;
00430 
00431   if (b <= 0x7f)
00432     len = b;
00433   else if ((ieee_record_enum_type) b == ieee_extension_length_1_enum)
00434     {
00435       len = **pp;
00436       ++*pp;
00437     }
00438   else if ((ieee_record_enum_type) b == ieee_extension_length_2_enum)
00439     {
00440       len = (**pp << 8) + (*pp)[1];
00441       *pp += 2;
00442     }
00443   else
00444     {
00445       if (ppresent != NULL)
00446        {
00447          --*pp;
00448          *ppresent = FALSE;
00449          return TRUE;
00450        }
00451       ieee_error (info, *pp - 1, _("invalid string length"));
00452       return FALSE;
00453     }
00454 
00455   if ((unsigned long) (info->pend - *pp) < len)
00456     {
00457       ieee_eof (info);
00458       return FALSE;
00459     }
00460 
00461   *pname = (const char *) *pp;
00462   *pnamlen = len;
00463   *pp += len;
00464 
00465   if (ppresent != NULL)
00466     *ppresent = TRUE;
00467 
00468   return TRUE;
00469 }
00470 
00471 /* Read an expression from an IEEE file.  Since this code is only used
00472    to parse debugging information, I haven't bothered to write a full
00473    blown IEEE expression parser.  I've only thrown in the things I've
00474    seen in debugging information.  This can be easily extended if
00475    necessary.  */
00476 
00477 static bfd_boolean
00478 ieee_read_expression (struct ieee_info *info, const bfd_byte **pp,
00479                     bfd_vma *pv)
00480 {
00481   const bfd_byte *expr_start;
00482 #define EXPR_STACK_SIZE (10)
00483   bfd_vma expr_stack[EXPR_STACK_SIZE];
00484   bfd_vma *esp;
00485 
00486   expr_start = *pp;
00487 
00488   esp = expr_stack;
00489 
00490   while (1)
00491     {
00492       const bfd_byte *start;
00493       bfd_vma val;
00494       bfd_boolean present;
00495       ieee_record_enum_type c;
00496 
00497       start = *pp;
00498 
00499       if (! ieee_read_optional_number (info, pp, &val, &present))
00500        return FALSE;
00501 
00502       if (present)
00503        {
00504          if (esp - expr_stack >= EXPR_STACK_SIZE)
00505            {
00506              ieee_error (info, start, _("expression stack overflow"));
00507              return FALSE;
00508            }
00509          *esp++ = val;
00510          continue;
00511        }
00512 
00513       c = (ieee_record_enum_type) **pp;
00514 
00515       if (c >= ieee_module_beginning_enum)
00516        break;
00517 
00518       ++*pp;
00519 
00520       if (c == ieee_comma)
00521        break;
00522 
00523       switch (c)
00524        {
00525        default:
00526          ieee_error (info, start, _("unsupported IEEE expression operator"));
00527          break;
00528 
00529        case ieee_variable_R_enum:
00530          {
00531            bfd_vma indx;
00532            asection *s;
00533 
00534            if (! ieee_read_number (info, pp, &indx))
00535              return FALSE;
00536            for (s = info->abfd->sections; s != NULL; s = s->next)
00537              if ((bfd_vma) s->target_index == indx)
00538               break;
00539            if (s == NULL)
00540              {
00541               ieee_error (info, start, _("unknown section"));
00542               return FALSE;
00543              }
00544 
00545            if (esp - expr_stack >= EXPR_STACK_SIZE)
00546              {
00547               ieee_error (info, start, _("expression stack overflow"));
00548               return FALSE;
00549              }
00550 
00551            *esp++ = bfd_get_section_vma (info->abfd, s);
00552          }
00553          break;
00554 
00555        case ieee_function_plus_enum:
00556        case ieee_function_minus_enum:
00557          {
00558            bfd_vma v1, v2;
00559 
00560            if (esp - expr_stack < 2)
00561              {
00562               ieee_error (info, start, _("expression stack underflow"));
00563               return FALSE;
00564              }
00565 
00566            v1 = *--esp;
00567            v2 = *--esp;
00568            *esp++ = v1 + v2;
00569          }
00570          break;
00571        }
00572     }
00573 
00574   if (esp - 1 != expr_stack)
00575     {
00576       ieee_error (info, expr_start, _("expression stack mismatch"));
00577       return FALSE;
00578     }
00579 
00580   *pv = *--esp;
00581 
00582   return TRUE;
00583 }
00584 
00585 /* Return an IEEE builtin type.  */
00586 
00587 static debug_type
00588 ieee_builtin_type (struct ieee_info *info, const bfd_byte *p,
00589                  unsigned int indx)
00590 {
00591   void *dhandle;
00592   debug_type type;
00593   const char *name;
00594 
00595   if (indx < BUILTIN_TYPE_COUNT
00596       && info->types.builtins[indx] != DEBUG_TYPE_NULL)
00597     return info->types.builtins[indx];
00598 
00599   dhandle = info->dhandle;
00600 
00601   if (indx >= 32 && indx < 64)
00602     {
00603       type = debug_make_pointer_type (dhandle,
00604                                   ieee_builtin_type (info, p, indx - 32));
00605       assert (indx < BUILTIN_TYPE_COUNT);
00606       info->types.builtins[indx] = type;
00607       return type;
00608     }
00609 
00610   switch ((enum builtin_types) indx)
00611     {
00612     default:
00613       ieee_error (info, p, _("unknown builtin type"));
00614       return NULL;
00615 
00616     case builtin_unknown:
00617       type = debug_make_void_type (dhandle);
00618       name = NULL;
00619       break;
00620 
00621     case builtin_void:
00622       type = debug_make_void_type (dhandle);
00623       name = "void";
00624       break;
00625 
00626     case builtin_signed_char:
00627       type = debug_make_int_type (dhandle, 1, FALSE);
00628       name = "signed char";
00629       break;
00630 
00631     case builtin_unsigned_char:
00632       type = debug_make_int_type (dhandle, 1, TRUE);
00633       name = "unsigned char";
00634       break;
00635 
00636     case builtin_signed_short_int:
00637       type = debug_make_int_type (dhandle, 2, FALSE);
00638       name = "signed short int";
00639       break;
00640 
00641     case builtin_unsigned_short_int:
00642       type = debug_make_int_type (dhandle, 2, TRUE);
00643       name = "unsigned short int";
00644       break;
00645 
00646     case builtin_signed_long:
00647       type = debug_make_int_type (dhandle, 4, FALSE);
00648       name = "signed long";
00649       break;
00650 
00651     case builtin_unsigned_long:
00652       type = debug_make_int_type (dhandle, 4, TRUE);
00653       name = "unsigned long";
00654       break;
00655 
00656     case builtin_signed_long_long:
00657       type = debug_make_int_type (dhandle, 8, FALSE);
00658       name = "signed long long";
00659       break;
00660 
00661     case builtin_unsigned_long_long:
00662       type = debug_make_int_type (dhandle, 8, TRUE);
00663       name = "unsigned long long";
00664       break;
00665 
00666     case builtin_float:
00667       type = debug_make_float_type (dhandle, 4);
00668       name = "float";
00669       break;
00670 
00671     case builtin_double:
00672       type = debug_make_float_type (dhandle, 8);
00673       name = "double";
00674       break;
00675 
00676     case builtin_long_double:
00677       /* FIXME: The size for this type should depend upon the
00678          processor.  */
00679       type = debug_make_float_type (dhandle, 12);
00680       name = "long double";
00681       break;
00682 
00683     case builtin_long_long_double:
00684       type = debug_make_float_type (dhandle, 16);
00685       name = "long long double";
00686       break;
00687 
00688     case builtin_quoted_string:
00689       type = debug_make_array_type (dhandle,
00690                                 ieee_builtin_type (info, p,
00691                                                  ((unsigned int)
00692                                                  builtin_char)),
00693                                 ieee_builtin_type (info, p,
00694                                                  ((unsigned int)
00695                                                  builtin_int)),
00696                                 0, -1, TRUE);
00697       name = "QUOTED STRING";
00698       break;
00699 
00700     case builtin_instruction_address:
00701       /* FIXME: This should be a code address.  */
00702       type = debug_make_int_type (dhandle, 4, TRUE);
00703       name = "instruction address";
00704       break;
00705 
00706     case builtin_int:
00707       /* FIXME: The size for this type should depend upon the
00708          processor.  */
00709       type = debug_make_int_type (dhandle, 4, FALSE);
00710       name = "int";
00711       break;
00712 
00713     case builtin_unsigned:
00714       /* FIXME: The size for this type should depend upon the
00715          processor.  */
00716       type = debug_make_int_type (dhandle, 4, TRUE);
00717       name = "unsigned";
00718       break;
00719 
00720     case builtin_unsigned_int:
00721       /* FIXME: The size for this type should depend upon the
00722          processor.  */
00723       type = debug_make_int_type (dhandle, 4, TRUE);
00724       name = "unsigned int";
00725       break;
00726 
00727     case builtin_char:
00728       type = debug_make_int_type (dhandle, 1, FALSE);
00729       name = "char";
00730       break;
00731 
00732     case builtin_long:
00733       type = debug_make_int_type (dhandle, 4, FALSE);
00734       name = "long";
00735       break;
00736 
00737     case builtin_short:
00738       type = debug_make_int_type (dhandle, 2, FALSE);
00739       name = "short";
00740       break;
00741 
00742     case builtin_unsigned_short:
00743       type = debug_make_int_type (dhandle, 2, TRUE);
00744       name = "unsigned short";
00745       break;
00746 
00747     case builtin_short_int:
00748       type = debug_make_int_type (dhandle, 2, FALSE);
00749       name = "short int";
00750       break;
00751 
00752     case builtin_signed_short:
00753       type = debug_make_int_type (dhandle, 2, FALSE);
00754       name = "signed short";
00755       break;
00756 
00757     case builtin_bcd_float:
00758       ieee_error (info, p, _("BCD float type not supported"));
00759       return DEBUG_TYPE_NULL;
00760     }
00761 
00762   if (name != NULL)
00763     type = debug_name_type (dhandle, name, type);
00764 
00765   assert (indx < BUILTIN_TYPE_COUNT);
00766 
00767   info->types.builtins[indx] = type;
00768 
00769   return type;
00770 }
00771 
00772 /* Allocate more space in the type table.  If ref is TRUE, this is a
00773    reference to the type; if it is not already defined, we should set
00774    up an indirect type.  */
00775 
00776 static bfd_boolean
00777 ieee_alloc_type (struct ieee_info *info, unsigned int indx, bfd_boolean ref)
00778 {
00779   unsigned int nalloc;
00780   register struct ieee_type *t;
00781   struct ieee_type *tend;
00782 
00783   if (indx >= info->types.alloc)
00784     {
00785       nalloc = info->types.alloc;
00786       if (nalloc == 0)
00787        nalloc = 4;
00788       while (indx >= nalloc)
00789        nalloc *= 2;
00790 
00791       info->types.types = ((struct ieee_type *)
00792                         xrealloc (info->types.types,
00793                                  nalloc * sizeof *info->types.types));
00794 
00795       memset (info->types.types + info->types.alloc, 0,
00796              (nalloc - info->types.alloc) * sizeof *info->types.types);
00797 
00798       tend = info->types.types + nalloc;
00799       for (t = info->types.types + info->types.alloc; t < tend; t++)
00800        t->type = DEBUG_TYPE_NULL;
00801 
00802       info->types.alloc = nalloc;
00803     }
00804 
00805   if (ref)
00806     {
00807       t = info->types.types + indx;
00808       if (t->type == NULL)
00809        {
00810          t->pslot = (debug_type *) xmalloc (sizeof *t->pslot);
00811          *t->pslot = DEBUG_TYPE_NULL;
00812          t->type = debug_make_indirect_type (info->dhandle, t->pslot,
00813                                          (const char *) NULL);
00814          if (t->type == NULL)
00815            return FALSE;
00816        }
00817     }
00818 
00819   return TRUE;
00820 }
00821 
00822 /* Read a type index and return the corresponding type.  */
00823 
00824 static bfd_boolean
00825 ieee_read_type_index (struct ieee_info *info, const bfd_byte **pp,
00826                     debug_type *ptype)
00827 {
00828   const bfd_byte *start;
00829   bfd_vma indx;
00830 
00831   start = *pp;
00832 
00833   if (! ieee_read_number (info, pp, &indx))
00834     return FALSE;
00835 
00836   if (indx < 256)
00837     {
00838       *ptype = ieee_builtin_type (info, start, indx);
00839       if (*ptype == NULL)
00840        return FALSE;
00841       return TRUE;
00842     }
00843 
00844   indx -= 256;
00845   if (! ieee_alloc_type (info, indx, TRUE))
00846     return FALSE;
00847 
00848   *ptype = info->types.types[indx].type;
00849 
00850   return TRUE;
00851 }
00852 
00853 /* Parse IEEE debugging information for a file.  This is passed the
00854    bytes which compose the Debug Information Part of an IEEE file.  */
00855 
00856 bfd_boolean
00857 parse_ieee (void *dhandle, bfd *abfd, const bfd_byte *bytes, bfd_size_type len)
00858 {
00859   struct ieee_info info;
00860   unsigned int i;
00861   const bfd_byte *p, *pend;
00862 
00863   info.dhandle = dhandle;
00864   info.abfd = abfd;
00865   info.bytes = bytes;
00866   info.pend = bytes + len;
00867   info.blockstack.bsp = info.blockstack.stack;
00868   info.saw_filename = FALSE;
00869   info.vars.alloc = 0;
00870   info.vars.vars = NULL;
00871   info.global_vars = NULL;
00872   info.types.alloc = 0;
00873   info.types.types = NULL;
00874   info.global_types = NULL;
00875   info.tags = NULL;
00876   for (i = 0; i < BUILTIN_TYPE_COUNT; i++)
00877     info.types.builtins[i] = DEBUG_TYPE_NULL;
00878 
00879   p = bytes;
00880   pend = info.pend;
00881   while (p < pend)
00882     {
00883       const bfd_byte *record_start;
00884       ieee_record_enum_type c;
00885 
00886       record_start = p;
00887 
00888       c = (ieee_record_enum_type) *p++;
00889 
00890       if (c == ieee_at_record_enum)
00891        c = (ieee_record_enum_type) (((unsigned int) c << 8) | *p++);
00892 
00893       if (c <= ieee_number_repeat_end_enum)
00894        {
00895          ieee_error (&info, record_start, _("unexpected number"));
00896          return FALSE;
00897        }
00898 
00899       switch (c)
00900        {
00901        default:
00902          ieee_error (&info, record_start, _("unexpected record type"));
00903          return FALSE;
00904 
00905        case ieee_bb_record_enum:
00906          if (! parse_ieee_bb (&info, &p))
00907            return FALSE;
00908          break;
00909 
00910        case ieee_be_record_enum:
00911          if (! parse_ieee_be (&info, &p))
00912            return FALSE;
00913          break;
00914 
00915        case ieee_nn_record:
00916          if (! parse_ieee_nn (&info, &p))
00917            return FALSE;
00918          break;
00919 
00920        case ieee_ty_record_enum:
00921          if (! parse_ieee_ty (&info, &p))
00922            return FALSE;
00923          break;
00924 
00925        case ieee_atn_record_enum:
00926          if (! parse_ieee_atn (&info, &p))
00927            return FALSE;
00928          break;
00929        }
00930     }
00931 
00932   if (info.blockstack.bsp != info.blockstack.stack)
00933     {
00934       ieee_error (&info, (const bfd_byte *) NULL,
00935                 _("blocks left on stack at end"));
00936       return FALSE;
00937     }
00938 
00939   return TRUE;
00940 }
00941 
00942 /* Handle an IEEE BB record.  */
00943 
00944 static bfd_boolean
00945 parse_ieee_bb (struct ieee_info *info, const bfd_byte **pp)
00946 {
00947   const bfd_byte *block_start;
00948   bfd_byte b;
00949   bfd_vma size;
00950   const char *name;
00951   unsigned long namlen;
00952   char *namcopy = NULL;
00953   unsigned int fnindx;
00954   bfd_boolean skip;
00955 
00956   block_start = *pp;
00957 
00958   b = **pp;
00959   ++*pp;
00960 
00961   if (! ieee_read_number (info, pp, &size)
00962       || ! ieee_read_id (info, pp, &name, &namlen))
00963     return FALSE;
00964 
00965   fnindx = (unsigned int) -1;
00966   skip = FALSE;
00967 
00968   switch (b)
00969     {
00970     case 1:
00971       /* BB1: Type definitions local to a module.  */
00972       namcopy = savestring (name, namlen);
00973       if (namcopy == NULL)
00974        return FALSE;
00975       if (! debug_set_filename (info->dhandle, namcopy))
00976        return FALSE;
00977       info->saw_filename = TRUE;
00978 
00979       /* Discard any variables or types we may have seen before.  */
00980       if (info->vars.vars != NULL)
00981        free (info->vars.vars);
00982       info->vars.vars = NULL;
00983       info->vars.alloc = 0;
00984       if (info->types.types != NULL)
00985        free (info->types.types);
00986       info->types.types = NULL;
00987       info->types.alloc = 0;
00988 
00989       /* Initialize the types to the global types.  */
00990       if (info->global_types != NULL)
00991        {
00992          info->types.alloc = info->global_types->alloc;
00993          info->types.types = ((struct ieee_type *)
00994                             xmalloc (info->types.alloc
00995                                    * sizeof (*info->types.types)));
00996          memcpy (info->types.types, info->global_types->types,
00997                 info->types.alloc * sizeof (*info->types.types));
00998        }
00999 
01000       break;
01001 
01002     case 2:
01003       /* BB2: Global type definitions.  The name is supposed to be
01004         empty, but we don't check.  */
01005       if (! debug_set_filename (info->dhandle, "*global*"))
01006        return FALSE;
01007       info->saw_filename = TRUE;
01008       break;
01009 
01010     case 3:
01011       /* BB3: High level module block begin.  We don't have to do
01012         anything here.  The name is supposed to be the same as for
01013         the BB1, but we don't check.  */
01014       break;
01015 
01016     case 4:
01017       /* BB4: Global function.  */
01018       {
01019        bfd_vma stackspace, typindx, offset;
01020        debug_type return_type;
01021 
01022        if (! ieee_read_number (info, pp, &stackspace)
01023            || ! ieee_read_number (info, pp, &typindx)
01024            || ! ieee_read_expression (info, pp, &offset))
01025          return FALSE;
01026 
01027        /* We have no way to record the stack space.  FIXME.  */
01028 
01029        if (typindx < 256)
01030          {
01031            return_type = ieee_builtin_type (info, block_start, typindx);
01032            if (return_type == DEBUG_TYPE_NULL)
01033              return FALSE;
01034          }
01035        else
01036          {
01037            typindx -= 256;
01038            if (! ieee_alloc_type (info, typindx, TRUE))
01039              return FALSE;
01040            fnindx = typindx;
01041            return_type = info->types.types[typindx].type;
01042            if (debug_get_type_kind (info->dhandle, return_type)
01043               == DEBUG_KIND_FUNCTION)
01044              return_type = debug_get_return_type (info->dhandle,
01045                                              return_type);
01046          }
01047 
01048        namcopy = savestring (name, namlen);
01049        if (namcopy == NULL)
01050          return FALSE;
01051        if (! debug_record_function (info->dhandle, namcopy, return_type,
01052                                  TRUE, offset))
01053          return FALSE;
01054       }
01055       break;
01056 
01057     case 5:
01058       /* BB5: File name for source line numbers.  */
01059       {
01060        unsigned int i;
01061 
01062        /* We ignore the date and time.  FIXME.  */
01063        for (i = 0; i < 6; i++)
01064          {
01065            bfd_vma ignore;
01066            bfd_boolean present;
01067 
01068            if (! ieee_read_optional_number (info, pp, &ignore, &present))
01069              return FALSE;
01070            if (! present)
01071              break;
01072          }
01073 
01074        namcopy = savestring (name, namlen);
01075        if (namcopy == NULL)
01076          return FALSE;
01077        if (! debug_start_source (info->dhandle, namcopy))
01078          return FALSE;
01079       }
01080       break;
01081 
01082     case 6:
01083       /* BB6: Local function or block.  */
01084       {
01085        bfd_vma stackspace, typindx, offset;
01086 
01087        if (! ieee_read_number (info, pp, &stackspace)
01088            || ! ieee_read_number (info, pp, &typindx)
01089            || ! ieee_read_expression (info, pp, &offset))
01090          return FALSE;
01091 
01092        /* We have no way to record the stack space.  FIXME.  */
01093 
01094        if (namlen == 0)
01095          {
01096            if (! debug_start_block (info->dhandle, offset))
01097              return FALSE;
01098            /* Change b to indicate that this is a block
01099               rather than a function.  */
01100            b = 0x86;
01101          }
01102        else
01103          {
01104            /* The MRI C++ compiler will output a fake function named
01105               __XRYCPP to hold C++ debugging information.  We skip
01106               that function.  This is not crucial, but it makes
01107               converting from IEEE to other debug formats work
01108               better.  */
01109            if (strncmp (name, "__XRYCPP", namlen) == 0)
01110              skip = TRUE;
01111            else
01112              {
01113               debug_type return_type;
01114 
01115               if (typindx < 256)
01116                 {
01117                   return_type = ieee_builtin_type (info, block_start,
01118                                                typindx);
01119                   if (return_type == NULL)
01120                     return FALSE;
01121                 }
01122               else
01123                 {
01124                   typindx -= 256;
01125                   if (! ieee_alloc_type (info, typindx, TRUE))
01126                     return FALSE;
01127                   fnindx = typindx;
01128                   return_type = info->types.types[typindx].type;
01129                   if (debug_get_type_kind (info->dhandle, return_type)
01130                      == DEBUG_KIND_FUNCTION)
01131                     return_type = debug_get_return_type (info->dhandle,
01132                                                     return_type);
01133                 }
01134 
01135               namcopy = savestring (name, namlen);
01136               if (namcopy == NULL)
01137                 return FALSE;
01138               if (! debug_record_function (info->dhandle, namcopy,
01139                                         return_type, FALSE, offset))
01140                 return FALSE;
01141              }
01142          }
01143       }
01144       break;
01145 
01146     case 10:
01147       /* BB10: Assembler module scope.  In the normal case, we
01148         completely ignore all this information.  FIXME.  */
01149       {
01150        const char *inam, *vstr;
01151        unsigned long inamlen, vstrlen;
01152        bfd_vma tool_type;
01153        bfd_boolean present;
01154        unsigned int i;
01155 
01156        if (! info->saw_filename)
01157          {
01158            namcopy = savestring (name, namlen);
01159            if (namcopy == NULL)
01160              return FALSE;
01161            if (! debug_set_filename (info->dhandle, namcopy))
01162              return FALSE;
01163            info->saw_filename = TRUE;
01164          }
01165 
01166        if (! ieee_read_id (info, pp, &inam, &inamlen)
01167            || ! ieee_read_number (info, pp, &tool_type)
01168            || ! ieee_read_optional_id (info, pp, &vstr, &vstrlen, &present))
01169          return FALSE;
01170        for (i = 0; i < 6; i++)
01171          {
01172            bfd_vma ignore;
01173 
01174            if (! ieee_read_optional_number (info, pp, &ignore, &present))
01175              return FALSE;
01176            if (! present)
01177              break;
01178          }
01179       }
01180       break;
01181 
01182     case 11:
01183       /* BB11: Module section.  We completely ignore all this
01184         information.  FIXME.  */
01185       {
01186        bfd_vma sectype, secindx, offset, map;
01187        bfd_boolean present;
01188 
01189        if (! ieee_read_number (info, pp, &sectype)
01190            || ! ieee_read_number (info, pp, &secindx)
01191            || ! ieee_read_expression (info, pp, &offset)
01192            || ! ieee_read_optional_number (info, pp, &map, &present))
01193          return FALSE;
01194       }
01195       break;
01196 
01197     default:
01198       ieee_error (info, block_start, _("unknown BB type"));
01199       return FALSE;
01200     }
01201 
01202 
01203   /* Push this block on the block stack.  */
01204 
01205   if (info->blockstack.bsp >= info->blockstack.stack + BLOCKSTACK_SIZE)
01206     {
01207       ieee_error (info, (const bfd_byte *) NULL, _("stack overflow"));
01208       return FALSE;
01209     }
01210 
01211   info->blockstack.bsp->kind = b;
01212   if (b == 5)
01213     info->blockstack.bsp->filename = namcopy;
01214   info->blockstack.bsp->fnindx = fnindx;
01215   info->blockstack.bsp->skip = skip;
01216   ++info->blockstack.bsp;
01217 
01218   return TRUE;
01219 }
01220 
01221 /* Handle an IEEE BE record.  */
01222 
01223 static bfd_boolean
01224 parse_ieee_be (struct ieee_info *info, const bfd_byte **pp)
01225 {
01226   bfd_vma offset;
01227 
01228   if (info->blockstack.bsp <= info->blockstack.stack)
01229     {
01230       ieee_error (info, *pp, _("stack underflow"));
01231       return FALSE;
01232     }
01233   --info->blockstack.bsp;
01234 
01235   switch (info->blockstack.bsp->kind)
01236     {
01237     case 2:
01238       /* When we end the global typedefs block, we copy out the
01239          contents of info->vars.  This is because the variable indices
01240          may be reused in the local blocks.  However, we need to
01241          preserve them so that we can locate a function returning a
01242          reference variable whose type is named in the global typedef
01243          block.  */
01244       info->global_vars = ((struct ieee_vars *)
01245                         xmalloc (sizeof *info->global_vars));
01246       info->global_vars->alloc = info->vars.alloc;
01247       info->global_vars->vars = ((struct ieee_var *)
01248                              xmalloc (info->vars.alloc
01249                                      * sizeof (*info->vars.vars)));
01250       memcpy (info->global_vars->vars, info->vars.vars,
01251              info->vars.alloc * sizeof (*info->vars.vars));
01252 
01253       /* We also copy out the non builtin parts of info->types, since
01254          the types are discarded when we start a new block.  */
01255       info->global_types = ((struct ieee_types *)
01256                          xmalloc (sizeof *info->global_types));
01257       info->global_types->alloc = info->types.alloc;
01258       info->global_types->types = ((struct ieee_type *)
01259                                xmalloc (info->types.alloc
01260                                        * sizeof (*info->types.types)));
01261       memcpy (info->global_types->types, info->types.types,
01262              info->types.alloc * sizeof (*info->types.types));
01263       memset (info->global_types->builtins, 0,
01264              sizeof (info->global_types->builtins));
01265 
01266       break;
01267 
01268     case 4:
01269     case 6:
01270       if (! ieee_read_expression (info, pp, &offset))
01271        return FALSE;
01272       if (! info->blockstack.bsp->skip)
01273        {
01274          if (! debug_end_function (info->dhandle, offset + 1))
01275            return FALSE;
01276        }
01277       break;
01278 
01279     case 0x86:
01280       /* This is BE6 when BB6 started a block rather than a local
01281         function.  */
01282       if (! ieee_read_expression (info, pp, &offset))
01283        return FALSE;
01284       if (! debug_end_block (info->dhandle, offset + 1))
01285        return FALSE;
01286       break;
01287 
01288     case 5:
01289       /* When we end a BB5, we look up the stack for the last BB5, if
01290          there is one, so that we can call debug_start_source.  */
01291       if (info->blockstack.bsp > info->blockstack.stack)
01292        {
01293          struct ieee_block *bl;
01294 
01295          bl = info->blockstack.bsp;
01296          do
01297            {
01298              --bl;
01299              if (bl->kind == 5)
01300               {
01301                 if (! debug_start_source (info->dhandle, bl->filename))
01302                   return FALSE;
01303                 break;
01304               }
01305            }
01306          while (bl != info->blockstack.stack);
01307        }
01308       break;
01309 
01310     case 11:
01311       if (! ieee_read_expression (info, pp, &offset))
01312        return FALSE;
01313       /* We just ignore the module size.  FIXME.  */
01314       break;
01315 
01316     default:
01317       /* Other block types do not have any trailing information.  */
01318       break;
01319     }
01320 
01321   return TRUE;
01322 }
01323 
01324 /* Parse an NN record.  */
01325 
01326 static bfd_boolean
01327 parse_ieee_nn (struct ieee_info *info, const bfd_byte **pp)
01328 {
01329   const bfd_byte *nn_start;
01330   bfd_vma varindx;
01331   const char *name;
01332   unsigned long namlen;
01333 
01334   nn_start = *pp;
01335 
01336   if (! ieee_read_number (info, pp, &varindx)
01337       || ! ieee_read_id (info, pp, &name, &namlen))
01338     return FALSE;
01339 
01340   if (varindx < 32)
01341     {
01342       ieee_error (info, nn_start, _("illegal variable index"));
01343       return FALSE;
01344     }
01345   varindx -= 32;
01346 
01347   if (varindx >= info->vars.alloc)
01348     {
01349       unsigned int alloc;
01350 
01351       alloc = info->vars.alloc;
01352       if (alloc == 0)
01353        alloc = 4;
01354       while (varindx >= alloc)
01355        alloc *= 2;
01356       info->vars.vars = ((struct ieee_var *)
01357                       xrealloc (info->vars.vars,
01358                                alloc * sizeof *info->vars.vars));
01359       memset (info->vars.vars + info->vars.alloc, 0,
01360              (alloc - info->vars.alloc) * sizeof *info->vars.vars);
01361       info->vars.alloc = alloc;
01362     }
01363 
01364   info->vars.vars[varindx].name = name;
01365   info->vars.vars[varindx].namlen = namlen;
01366 
01367   return TRUE;
01368 }
01369 
01370 /* Parse a TY record.  */
01371 
01372 static bfd_boolean
01373 parse_ieee_ty (struct ieee_info *info, const bfd_byte **pp)
01374 {
01375   const bfd_byte *ty_start, *ty_var_start, *ty_code_start;
01376   bfd_vma typeindx, varindx, tc;
01377   void *dhandle;
01378   bfd_boolean tag, typdef;
01379   debug_type *arg_slots;
01380   unsigned long type_bitsize;
01381   debug_type type;
01382 
01383   ty_start = *pp;
01384 
01385   if (! ieee_read_number (info, pp, &typeindx))
01386     return FALSE;
01387 
01388   if (typeindx < 256)
01389     {
01390       ieee_error (info, ty_start, _("illegal type index"));
01391       return FALSE;
01392     }
01393 
01394   typeindx -= 256;
01395   if (! ieee_alloc_type (info, typeindx, FALSE))
01396     return FALSE;
01397 
01398   if (**pp != 0xce)
01399     {
01400       ieee_error (info, *pp, _("unknown TY code"));
01401       return FALSE;
01402     }
01403   ++*pp;
01404 
01405   ty_var_start = *pp;
01406 
01407   if (! ieee_read_number (info, pp, &varindx))
01408     return FALSE;
01409 
01410   if (varindx < 32)
01411     {
01412       ieee_error (info, ty_var_start, _("illegal variable index"));
01413       return FALSE;
01414     }
01415   varindx -= 32;
01416 
01417   if (varindx >= info->vars.alloc || info->vars.vars[varindx].name == NULL)
01418     {
01419       ieee_error (info, ty_var_start, _("undefined variable in TY"));
01420       return FALSE;
01421     }
01422 
01423   ty_code_start = *pp;
01424 
01425   if (! ieee_read_number (info, pp, &tc))
01426     return FALSE;
01427 
01428   dhandle = info->dhandle;
01429 
01430   tag = FALSE;
01431   typdef = FALSE;
01432   arg_slots = NULL;
01433   type_bitsize = 0;
01434   switch (tc)
01435     {
01436     default:
01437       ieee_error (info, ty_code_start, _("unknown TY code"));
01438       return FALSE;
01439 
01440     case '!':
01441       /* Unknown type, with size.  We treat it as int.  FIXME.  */
01442       {
01443        bfd_vma size;
01444 
01445        if (! ieee_read_number (info, pp, &size))
01446          return FALSE;
01447        type = debug_make_int_type (dhandle, size, FALSE);
01448       }
01449       break;
01450 
01451     case 'A': /* Array.  */
01452     case 'a': /* FORTRAN array in column/row order.  FIXME: Not
01453                distinguished from normal array.  */
01454       {
01455        debug_type ele_type;
01456        bfd_vma lower, upper;
01457 
01458        if (! ieee_read_type_index (info, pp, &ele_type)
01459            || ! ieee_read_number (info, pp, &lower)
01460            || ! ieee_read_number (info, pp, &upper))
01461          return FALSE;
01462        type = debug_make_array_type (dhandle, ele_type,
01463                                   ieee_builtin_type (info, ty_code_start,
01464                                                   ((unsigned int)
01465                                                    builtin_int)),
01466                                   (bfd_signed_vma) lower,
01467                                   (bfd_signed_vma) upper,
01468                                   FALSE);
01469       }
01470       break;
01471 
01472     case 'E':
01473       /* Simple enumeration.  */
01474       {
01475        bfd_vma size;
01476        unsigned int alloc;
01477        const char **names;
01478        unsigned int c;
01479        bfd_signed_vma *vals;
01480        unsigned int i;
01481 
01482        if (! ieee_read_number (info, pp, &size))
01483          return FALSE;
01484        /* FIXME: we ignore the enumeration size.  */
01485 
01486        alloc = 10;
01487        names = (const char **) xmalloc (alloc * sizeof *names);
01488        memset (names, 0, alloc * sizeof *names);
01489        c = 0;
01490        while (1)
01491          {
01492            const char *name;
01493            unsigned long namlen;
01494            bfd_boolean present;
01495 
01496            if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
01497              return FALSE;
01498            if (! present)
01499              break;
01500 
01501            if (c + 1 >= alloc)
01502              {
01503               alloc += 10;
01504               names = ((const char **)
01505                       xrealloc (names, alloc * sizeof *names));
01506              }
01507 
01508            names[c] = savestring (name, namlen);
01509            if (names[c] == NULL)
01510              return FALSE;
01511            ++c;
01512          }
01513 
01514        names[c] = NULL;
01515 
01516        vals = (bfd_signed_vma *) xmalloc (c * sizeof *vals);
01517        for (i = 0; i < c; i++)
01518          vals[i] = i;
01519 
01520        type = debug_make_enum_type (dhandle, names, vals);
01521        tag = TRUE;
01522       }
01523       break;
01524 
01525     case 'G':
01526       /* Struct with bit fields.  */
01527       {
01528        bfd_vma size;
01529        unsigned int alloc;
01530        debug_field *fields;
01531        unsigned int c;
01532 
01533        if (! ieee_read_number (info, pp, &size))
01534          return FALSE;
01535 
01536        alloc = 10;
01537        fields = (debug_field *) xmalloc (alloc * sizeof *fields);
01538        c = 0;
01539        while (1)
01540          {
01541            const char *name;
01542            unsigned long namlen;
01543            bfd_boolean present;
01544            debug_type ftype;
01545            bfd_vma bitpos, bitsize;
01546 
01547            if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
01548              return FALSE;
01549            if (! present)
01550              break;
01551            if (! ieee_read_type_index (info, pp, &ftype)
01552               || ! ieee_read_number (info, pp, &bitpos)
01553               || ! ieee_read_number (info, pp, &bitsize))
01554              return FALSE;
01555 
01556            if (c + 1 >= alloc)
01557              {
01558               alloc += 10;
01559               fields = ((debug_field *)
01560                        xrealloc (fields, alloc * sizeof *fields));
01561              }
01562 
01563            fields[c] = debug_make_field (dhandle, savestring (name, namlen),
01564                                      ftype, bitpos, bitsize,
01565                                      DEBUG_VISIBILITY_PUBLIC);
01566            if (fields[c] == NULL)
01567              return FALSE;
01568            ++c;
01569          }
01570 
01571        fields[c] = NULL;
01572 
01573        type = debug_make_struct_type (dhandle, TRUE, size, fields);
01574        tag = TRUE;
01575       }
01576       break;
01577 
01578     case 'N':
01579       /* Enumeration.  */
01580       {
01581        unsigned int alloc;
01582        const char **names;
01583        bfd_signed_vma *vals;
01584        unsigned int c;
01585 
01586        alloc = 10;
01587        names = (const char **) xmalloc (alloc * sizeof *names);
01588        vals = (bfd_signed_vma *) xmalloc (alloc * sizeof *names);
01589        c = 0;
01590        while (1)
01591          {
01592            const char *name;
01593            unsigned long namlen;
01594            bfd_boolean present;
01595            bfd_vma val;
01596 
01597            if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
01598              return FALSE;
01599            if (! present)
01600              break;
01601            if (! ieee_read_number (info, pp, &val))
01602              return FALSE;
01603 
01604            /* If the length of the name is zero, then the value is
01605                actually the size of the enum.  We ignore this
01606                information.  FIXME.  */
01607            if (namlen == 0)
01608              continue;
01609 
01610            if (c + 1 >= alloc)
01611              {
01612               alloc += 10;
01613               names = ((const char **)
01614                       xrealloc (names, alloc * sizeof *names));
01615               vals = ((bfd_signed_vma *)
01616                      xrealloc (vals, alloc * sizeof *vals));
01617              }
01618 
01619            names[c] = savestring (name, namlen);
01620            if (names[c] == NULL)
01621              return FALSE;
01622            vals[c] = (bfd_signed_vma) val;
01623            ++c;
01624          }
01625 
01626        names[c] = NULL;
01627 
01628        type = debug_make_enum_type (dhandle, names, vals);
01629        tag = TRUE;
01630       }
01631       break;
01632 
01633     case 'O': /* Small pointer.  We don't distinguish small and large
01634                pointers.  FIXME.  */
01635     case 'P': /* Large pointer.  */
01636       {
01637        debug_type t;
01638 
01639        if (! ieee_read_type_index (info, pp, &t))
01640          return FALSE;
01641        type = debug_make_pointer_type (dhandle, t);
01642       }
01643       break;
01644 
01645     case 'R':
01646       /* Range.  */
01647       {
01648        bfd_vma low, high, signedp, size;
01649 
01650        if (! ieee_read_number (info, pp, &low)
01651            || ! ieee_read_number (info, pp, &high)
01652            || ! ieee_read_number (info, pp, &signedp)
01653            || ! ieee_read_number (info, pp, &size))
01654          return FALSE;
01655 
01656        type = debug_make_range_type (dhandle,
01657                                   debug_make_int_type (dhandle, size,
01658                                                     ! signedp),
01659                                   (bfd_signed_vma) low,
01660                                   (bfd_signed_vma) high);
01661       }
01662       break;
01663 
01664     case 'S': /* Struct.  */
01665     case 'U': /* Union.  */
01666       {
01667        bfd_vma size;
01668        unsigned int alloc;
01669        debug_field *fields;
01670        unsigned int c;
01671 
01672        if (! ieee_read_number (info, pp, &size))
01673          return FALSE;
01674 
01675        alloc = 10;
01676        fields = (debug_field *) xmalloc (alloc * sizeof *fields);
01677        c = 0;
01678        while (1)
01679          {
01680            const char *name;
01681            unsigned long namlen;
01682            bfd_boolean present;
01683            bfd_vma tindx;
01684            bfd_vma offset;
01685            debug_type ftype;
01686            bfd_vma bitsize;
01687 
01688            if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
01689              return FALSE;
01690            if (! present)
01691              break;
01692            if (! ieee_read_number (info, pp, &tindx)
01693               || ! ieee_read_number (info, pp, &offset))
01694              return FALSE;
01695 
01696            if (tindx < 256)
01697              {
01698               ftype = ieee_builtin_type (info, ty_code_start, tindx);
01699               bitsize = 0;
01700               offset *= 8;
01701              }
01702            else
01703              {
01704               struct ieee_type *t;
01705 
01706               tindx -= 256;
01707               if (! ieee_alloc_type (info, tindx, TRUE))
01708                 return FALSE;
01709               t = info->types.types + tindx;
01710               ftype = t->type;
01711               bitsize = t->bitsize;
01712               if (bitsize == 0)
01713                 offset *= 8;
01714              }
01715 
01716            if (c + 1 >= alloc)
01717              {
01718               alloc += 10;
01719               fields = ((debug_field *)
01720                        xrealloc (fields, alloc * sizeof *fields));
01721              }
01722 
01723            fields[c] = debug_make_field (dhandle, savestring (name, namlen),
01724                                      ftype, offset, bitsize,
01725                                      DEBUG_VISIBILITY_PUBLIC);
01726            if (fields[c] == NULL)
01727              return FALSE;
01728            ++c;
01729          }
01730 
01731        fields[c] = NULL;
01732 
01733        type = debug_make_struct_type (dhandle, tc == 'S', size, fields);
01734        tag = TRUE;
01735       }
01736       break;
01737 
01738     case 'T':
01739       /* Typedef.  */
01740       if (! ieee_read_type_index (info, pp, &type))
01741        return FALSE;
01742       typdef = TRUE;
01743       break;
01744 
01745     case 'X':
01746       /* Procedure.  FIXME: This is an extern declaration, which we
01747          have no way of representing.  */
01748       {
01749        bfd_vma attr;
01750        debug_type rtype;
01751        bfd_vma nargs;
01752        bfd_boolean present;
01753        struct ieee_var *pv;
01754 
01755        /* FIXME: We ignore the attribute and the argument names.  */
01756 
01757        if (! ieee_read_number (info, pp, &attr)
01758            || ! ieee_read_type_index (info, pp, &rtype)
01759            || ! ieee_read_number (info, pp, &nargs))
01760          return FALSE;
01761        do
01762          {
01763            const char *name;
01764            unsigned long namlen;
01765 
01766            if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
01767              return FALSE;
01768          }
01769        while (present);
01770 
01771        pv = info->vars.vars + varindx;
01772        pv->kind = IEEE_EXTERNAL;
01773        if (pv->namlen > 0
01774            && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER)
01775          {
01776            /* Set up the return type as an indirect type pointing to
01777                the variable slot, so that we can change it to a
01778                reference later if appropriate.  */
01779            pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot);
01780            *pv->pslot = rtype;
01781            rtype = debug_make_indirect_type (dhandle, pv->pslot,
01782                                          (const char *) NULL);
01783          }
01784 
01785        type = debug_make_function_type (dhandle, rtype, (debug_type *) NULL,
01786                                     FALSE);
01787       }
01788       break;
01789 
01790     case 'V':
01791       /* Void.  This is not documented, but the MRI compiler emits it.  */
01792       type = debug_make_void_type (dhandle);
01793       break;
01794 
01795     case 'Z':
01796       /* Array with 0 lower bound.  */
01797       {
01798        debug_type etype;
01799        bfd_vma high;
01800 
01801        if (! ieee_read_type_index (info, pp, &etype)
01802            || ! ieee_read_number (info, pp, &high))
01803          return FALSE;
01804 
01805        type = debug_make_array_type (dhandle, etype,
01806                                   ieee_builtin_type (info, ty_code_start,
01807                                                   ((unsigned int)
01808                                                    builtin_int)),
01809                                   0, (bfd_signed_vma) high, FALSE);
01810       }
01811       break;
01812 
01813     case 'c': /* Complex.  */
01814     case 'd': /* Double complex.  */
01815       {
01816        const char *name;
01817        unsigned long namlen;
01818 
01819        /* FIXME: I don't know what the name means.  */
01820 
01821        if (! ieee_read_id (info, pp, &name, &namlen))
01822          return FALSE;
01823 
01824        type = debug_make_complex_type (dhandle, tc == 'c' ? 4 : 8);
01825       }
01826       break;
01827 
01828     case 'f':
01829       /* Pascal file name.  FIXME.  */
01830       ieee_error (info, ty_code_start, _("Pascal file name not supported"));
01831       return FALSE;
01832 
01833     case 'g':
01834       /* Bitfield type.  */
01835       {
01836        bfd_vma signedp, bitsize, dummy;
01837        const bfd_byte *hold;
01838        bfd_boolean present;
01839 
01840        if (! ieee_read_number (info, pp, &signedp)
01841            || ! ieee_read_number (info, pp, &bitsize))
01842          return FALSE;
01843 
01844        /* I think the documentation says that there is a type index,
01845            but some actual files do not have one.  */
01846        hold = *pp;
01847        if (! ieee_read_optional_number (info, pp, &dummy, &present))
01848          return FALSE;
01849        if (! present)
01850          {
01851            /* FIXME: This is just a guess.  */
01852            type = debug_make_int_type (dhandle, 4,
01853                                    signedp ? FALSE : TRUE);
01854          }
01855        else
01856          {
01857            *pp = hold;
01858            if (! ieee_read_type_index (info, pp, &type))
01859              return FALSE;
01860          }
01861        type_bitsize = bitsize;
01862       }
01863       break;
01864 
01865     case 'n':
01866       /* Qualifier.  */
01867       {
01868        bfd_vma kind;
01869        debug_type t;
01870 
01871        if (! ieee_read_number (info, pp, &kind)
01872            || ! ieee_read_type_index (info, pp, &t))
01873          return FALSE;
01874 
01875        switch (kind)
01876          {
01877          default:
01878            ieee_error (info, ty_start, _("unsupported qualifier"));
01879            return FALSE;
01880 
01881          case 1:
01882            type = debug_make_const_type (dhandle, t);
01883            break;
01884 
01885          case 2:
01886            type = debug_make_volatile_type (dhandle, t);
01887            break;
01888          }
01889       }
01890       break;
01891 
01892     case 's':
01893       /* Set.  */
01894       {
01895        bfd_vma size;
01896        debug_type etype;
01897 
01898        if (! ieee_read_number (info, pp, &size)
01899            || ! ieee_read_type_index (info, pp, &etype))
01900          return FALSE;
01901 
01902        /* FIXME: We ignore the size.  */
01903 
01904        type = debug_make_set_type (dhandle, etype, FALSE);
01905       }
01906       break;
01907 
01908     case 'x':
01909       /* Procedure with compiler dependencies.  */
01910       {
01911        struct ieee_var *pv;
01912        bfd_vma attr, frame_type, push_mask, nargs, level, father;
01913        debug_type rtype;
01914        debug_type *arg_types;
01915        bfd_boolean varargs;
01916        bfd_boolean present;
01917 
01918        /* FIXME: We ignore some of this information.  */
01919 
01920        pv = info->vars.vars + varindx;
01921 
01922        if (! ieee_read_number (info, pp, &attr)
01923            || ! ieee_read_number (info, pp, &frame_type)
01924            || ! ieee_read_number (info, pp, &push_mask)
01925            || ! ieee_read_type_index (info, pp, &rtype)
01926            || ! ieee_read_number (info, pp, &nargs))
01927          return FALSE;
01928        if (nargs == (bfd_vma) -1)
01929          {
01930            arg_types = NULL;
01931            varargs = FALSE;
01932          }
01933        else
01934          {
01935            unsigned int i;
01936 
01937            arg_types = ((debug_type *)
01938                       xmalloc ((nargs + 1) * sizeof *arg_types));
01939            for (i = 0; i < nargs; i++)
01940              if (! ieee_read_type_index (info, pp, arg_types + i))
01941               return FALSE;
01942 
01943            /* If the last type is pointer to void, this is really a
01944                varargs function.  */
01945            varargs = FALSE;
01946            if (nargs > 0)
01947              {
01948               debug_type last;
01949 
01950               last = arg_types[nargs - 1];
01951               if (debug_get_type_kind (dhandle, last) == DEBUG_KIND_POINTER
01952                   && (debug_get_type_kind (dhandle,
01953                                         debug_get_target_type (dhandle,
01954                                                             last))
01955                      == DEBUG_KIND_VOID))
01956                 {
01957                   --nargs;
01958                   varargs = TRUE;
01959                 }
01960              }
01961 
01962            /* If there are any pointer arguments, turn them into
01963                indirect types in case we later need to convert them to
01964                reference types.  */
01965            for (i = 0; i < nargs; i++)
01966              {
01967               if (debug_get_type_kind (dhandle, arg_types[i])
01968                   == DEBUG_KIND_POINTER)
01969                 {
01970                   if (arg_slots == NULL)
01971                     {
01972                      arg_slots = ((debug_type *)
01973                                  xmalloc (nargs * sizeof *arg_slots));
01974                      memset (arg_slots, 0, nargs * sizeof *arg_slots);
01975                     }
01976                   arg_slots[i] = arg_types[i];
01977                   arg_types[i] =
01978                     debug_make_indirect_type (dhandle,
01979                                           arg_slots + i,
01980                                           (const char *) NULL);
01981                 }
01982              }
01983 
01984            arg_types[nargs] = DEBUG_TYPE_NULL;
01985          }
01986        if (! ieee_read_number (info, pp, &level)
01987            || ! ieee_read_optional_number (info, pp, &father, &present))
01988          return FALSE;
01989 
01990        /* We can't distinguish between a global function and a static
01991            function.  */
01992        pv->kind = IEEE_FUNCTION;
01993 
01994        if (pv->namlen > 0
01995            && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER)
01996          {
01997            /* Set up the return type as an indirect type pointing to
01998                the variable slot, so that we can change it to a
01999                reference later if appropriate.  */
02000            pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot);
02001            *pv->pslot = rtype;
02002            rtype = debug_make_indirect_type (dhandle, pv->pslot,
02003                                          (const char *) NULL);
02004          }
02005 
02006        type = debug_make_function_type (dhandle, rtype, arg_types, varargs);
02007       }
02008       break;
02009     }
02010 
02011   /* Record the type in the table.  */
02012 
02013   if (type == DEBUG_TYPE_NULL)
02014     return FALSE;
02015 
02016   info->vars.vars[varindx].type = type;
02017 
02018   if ((tag || typdef)
02019       && info->vars.vars[varindx].namlen > 0)
02020     {
02021       const char *name;
02022 
02023       name = savestring (info->vars.vars[varindx].name,
02024                       info->vars.vars[varindx].namlen);
02025       if (typdef)
02026        type = debug_name_type (dhandle, name, type);
02027       else if (tc == 'E' || tc == 'N')
02028        type = debug_tag_type (dhandle, name, type);
02029       else
02030        {
02031          struct ieee_tag *it;
02032 
02033          /* We must allocate all struct tags as indirect types, so
02034              that if we later see a definition of the tag as a C++
02035              record we can update the indirect slot and automatically
02036              change all the existing references.  */
02037          it = (struct ieee_tag *) xmalloc (sizeof *it);
02038          memset (it, 0, sizeof *it);
02039          it->next = info->tags;
02040          info->tags = it;
02041          it->name = name;
02042          it->slot = type;
02043 
02044          type = debug_make_indirect_type (dhandle, &it->slot, name);
02045          type = debug_tag_type (dhandle, name, type);
02046 
02047          it->type = type;
02048        }
02049       if (type == NULL)
02050        return FALSE;
02051     }
02052 
02053   info->types.types[typeindx].type = type;
02054   info->types.types[typeindx].arg_slots = arg_slots;
02055   info->types.types[typeindx].bitsize = type_bitsize;
02056 
02057   /* We may have already allocated type as an indirect type pointing
02058      to slot.  It does no harm to replace the indirect type with the
02059      real type.  Filling in slot as well handles the indirect types
02060      which are already hanging around.  */
02061   if (info->types.types[typeindx].pslot != NULL)
02062     *info->types.types[typeindx].pslot = type;
02063 
02064   return TRUE;
02065 }
02066 
02067 /* Parse an ATN record.  */
02068 
02069 static bfd_boolean
02070 parse_ieee_atn (struct ieee_info *info, const bfd_byte **pp)
02071 {
02072   const bfd_byte *atn_start, *atn_code_start;
02073   bfd_vma varindx;
02074   struct ieee_var *pvar;
02075   debug_type type;
02076   bfd_vma atn_code;
02077   void *dhandle;
02078   bfd_vma v, v2, v3, v4, v5;
02079   const char *name;
02080   unsigned long namlen;
02081   char *namcopy;
02082   bfd_boolean present;
02083   int blocktype;
02084 
02085   atn_start = *pp;
02086 
02087   if (! ieee_read_number (info, pp, &varindx)
02088       || ! ieee_read_type_index (info, pp, &type))
02089     return FALSE;
02090 
02091   atn_code_start = *pp;
02092 
02093   if (! ieee_read_number (info, pp, &atn_code))
02094     return FALSE;
02095 
02096   if (varindx == 0)
02097     {
02098       pvar = NULL;
02099       name = "";
02100       namlen = 0;
02101     }
02102   else if (varindx < 32)
02103     {
02104       /* The MRI compiler reportedly sometimes emits variable lifetime
02105          information for a register.  We just ignore it.  */
02106       if (atn_code == 9)
02107        return ieee_read_number (info, pp, &v);
02108 
02109       ieee_error (info, atn_start, _("illegal variable index"));
02110       return FALSE;
02111     }
02112   else
02113     {
02114       varindx -= 32;
02115       if (varindx >= info->vars.alloc
02116          || info->vars.vars[varindx].name == NULL)
02117        {
02118          /* The MRI compiler or linker sometimes omits the NN record
02119              for a pmisc record.  */
02120          if (atn_code == 62)
02121            {
02122              if (varindx >= info->vars.alloc)
02123               {
02124                 unsigned int alloc;
02125 
02126                 alloc = info->vars.alloc;
02127                 if (alloc == 0)
02128                   alloc = 4;
02129                 while (varindx >= alloc)
02130                   alloc *= 2;
02131                 info->vars.vars = ((struct ieee_var *)
02132                                  xrealloc (info->vars.vars,
02133                                           (alloc
02134                                           * sizeof *info->vars.vars)));
02135                 memset (info->vars.vars + info->vars.alloc, 0,
02136                        ((alloc - info->vars.alloc)
02137                         * sizeof *info->vars.vars));
02138                 info->vars.alloc = alloc;
02139               }
02140 
02141              pvar = info->vars.vars + varindx;
02142              pvar->name = "";
02143              pvar->namlen = 0;
02144            }
02145          else
02146            {
02147              ieee_error (info, atn_start, _("undefined variable in ATN"));
02148              return FALSE;
02149            }
02150        }
02151 
02152       pvar = info->vars.vars + varindx;
02153 
02154       pvar->type = type;
02155 
02156       name = pvar->name;
02157       namlen = pvar->namlen;
02158     }
02159 
02160   dhandle = info->dhandle;
02161 
02162   /* If we are going to call debug_record_variable with a pointer
02163      type, change the type to an indirect type so that we can later
02164      change it to a reference type if we encounter a C++ pmisc 'R'
02165      record.  */
02166   if (pvar != NULL
02167       && type != DEBUG_TYPE_NULL
02168       && debug_get_type_kind (dhandle, type) == DEBUG_KIND_POINTER)
02169     {
02170       switch (atn_code)
02171        {
02172        case 1:
02173        case 2:
02174        case 3:
02175        case 5:
02176        case 8:
02177        case 10:
02178          pvar->pslot = (debug_type *) xmalloc (sizeof *pvar->pslot);
02179          *pvar->pslot = type;
02180          type = debug_make_indirect_type (dhandle, pvar->pslot,
02181                                       (const char *) NULL);
02182          pvar->type = type;
02183          break;
02184        }
02185     }
02186 
02187   switch (atn_code)
02188     {
02189     default:
02190       ieee_error (info, atn_code_start, _("unknown ATN type"));
02191       return FALSE;
02192 
02193     case 1:
02194       /* Automatic variable.  */
02195       if (! ieee_read_number (info, pp, &v))
02196        return FALSE;
02197       namcopy = savestring (name, namlen);
02198       if (type == NULL)
02199        type = debug_make_void_type (dhandle);
02200       if (pvar != NULL)
02201        pvar->kind = IEEE_LOCAL;
02202       return debug_record_variable (dhandle, namcopy, type, DEBUG_LOCAL, v);
02203 
02204     case 2:
02205       /* Register variable.  */
02206       if (! ieee_read_number (info, pp, &v))
02207        return FALSE;
02208       namcopy = savestring (name, namlen);
02209       if (type == NULL)
02210        type = debug_make_void_type (dhandle);
02211       if (pvar != NULL)
02212        pvar->kind = IEEE_LOCAL;
02213       return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER,
02214                                 ieee_regno_to_genreg (info->abfd, v));
02215 
02216     case 3:
02217       /* Static variable.  */
02218       if (! ieee_require_asn (info, pp, &v))
02219        return FALSE;
02220       namcopy = savestring (name, namlen);
02221       if (type == NULL)
02222        type = debug_make_void_type (dhandle);
02223       if (info->blockstack.bsp <= info->blockstack.stack)
02224        blocktype = 0;
02225       else
02226        blocktype = info->blockstack.bsp[-1].kind;
02227       if (pvar != NULL)
02228        {
02229          if (blocktype == 4 || blocktype == 6)
02230            pvar->kind = IEEE_LOCAL;
02231          else
02232            pvar->kind = IEEE_STATIC;
02233        }
02234       return debug_record_variable (dhandle, namcopy, type,
02235                                 (blocktype == 4 || blocktype == 6
02236                                  ? DEBUG_LOCAL_STATIC
02237                                  : DEBUG_STATIC),
02238                                 v);
02239 
02240     case 4:
02241       /* External function.  We don't currently record these.  FIXME.  */
02242       if (pvar != NULL)
02243        pvar->kind = IEEE_EXTERNAL;
02244       return TRUE;
02245 
02246     case 5:
02247       /* External variable.  We don't currently record these.  FIXME.  */
02248       if (pvar != NULL)
02249        pvar->kind = IEEE_EXTERNAL;
02250       return TRUE;
02251 
02252     case 7:
02253       if (! ieee_read_number (info, pp, &v)
02254          || ! ieee_read_number (info, pp, &v2)
02255          || ! ieee_read_optional_number (info, pp, &v3, &present))
02256        return FALSE;
02257       if (present)
02258        {
02259          if (! ieee_read_optional_number (info, pp, &v4, &present))
02260            return FALSE;
02261        }
02262 
02263       /* We just ignore the two optional fields in v3 and v4, since
02264          they are not defined.  */
02265 
02266       if (! ieee_require_asn (info, pp, &v3))
02267        return FALSE;
02268 
02269       /* We have no way to record the column number.  FIXME.  */
02270 
02271       return debug_record_line (dhandle, v, v3);
02272 
02273     case 8:
02274       /* Global variable.  */
02275       if (! ieee_require_asn (info, pp, &v))
02276        return FALSE;
02277       namcopy = savestring (name, namlen);
02278       if (type == NULL)
02279        type = debug_make_void_type (dhandle);
02280       if (pvar != NULL)
02281        pvar->kind = IEEE_GLOBAL;
02282       return debug_record_variable (dhandle, namcopy, type, DEBUG_GLOBAL, v);
02283 
02284     case 9:
02285       /* Variable lifetime information.  */
02286       if (! ieee_read_number (info, pp, &v))
02287        return FALSE;
02288 
02289       /* We have no way to record this information.  FIXME.  */
02290       return TRUE;
02291 
02292     case 10:
02293       /* Locked register.  The spec says that there are two required
02294          fields, but at least on occasion the MRI compiler only emits
02295          one.  */
02296       if (! ieee_read_number (info, pp, &v)
02297          || ! ieee_read_optional_number (info, pp, &v2, &present))
02298        return FALSE;
02299 
02300       /* I think this means a variable that is both in a register and
02301          a frame slot.  We ignore the frame slot.  FIXME.  */
02302 
02303       namcopy = savestring (name, namlen);
02304       if (type == NULL)
02305        type = debug_make_void_type (dhandle);
02306       if (pvar != NULL)
02307        pvar->kind = IEEE_LOCAL;
02308       return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER, v);
02309 
02310     case 11:
02311       /* Reserved for FORTRAN common.  */
02312       ieee_error (info, atn_code_start, _("unsupported ATN11"));
02313 
02314       /* Return TRUE to keep going.  */
02315       return TRUE;
02316 
02317     case 12:
02318       /* Based variable.  */
02319       v3 = 0;
02320       v4 = 0x80;
02321       v5 = 0;
02322       if (! ieee_read_number (info, pp, &v)
02323          || ! ieee_read_number (info, pp, &v2)
02324          || ! ieee_read_optional_number (info, pp, &v3, &present))
02325        return FALSE;
02326       if (present)
02327        {
02328          if (! ieee_read_optional_number (info, pp, &v4, &present))
02329            return FALSE;
02330          if (present)
02331            {
02332              if (! ieee_read_optional_number (info, pp, &v5, &present))
02333               return FALSE;
02334            }
02335        }
02336 
02337       /* We have no way to record this information.  FIXME.  */
02338 
02339       ieee_error (info, atn_code_start, _("unsupported ATN12"));
02340 
02341       /* Return TRUE to keep going.  */
02342       return TRUE;
02343 
02344     case 16:
02345       /* Constant.  The description of this that I have is ambiguous,
02346          so I'm not going to try to implement it.  */
02347       if (! ieee_read_number (info, pp, &v)
02348          || ! ieee_read_optional_number (info, pp, &v2, &present))
02349        return FALSE;
02350       if (present)
02351        {
02352          if (! ieee_read_optional_number (info, pp, &v2, &present))
02353            return FALSE;
02354          if (present)
02355            {
02356              if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
02357               return FALSE;
02358            }
02359        }
02360 
02361       if ((ieee_record_enum_type) **pp == ieee_e2_first_byte_enum)
02362        {
02363          if (! ieee_require_asn (info, pp, &v3))
02364            return FALSE;
02365        }
02366 
02367       return TRUE;
02368 
02369     case 19:
02370       /* Static variable from assembler.  */
02371       v2 = 0;
02372       if (! ieee_read_number (info, pp, &v)
02373          || ! ieee_read_optional_number (info, pp, &v2, &present)
02374          || ! ieee_require_asn (info, pp, &v3))
02375        return FALSE;
02376       namcopy = savestring (name, namlen);
02377       /* We don't really handle this correctly.  FIXME.  */
02378       return debug_record_variable (dhandle, namcopy,
02379                                 debug_make_void_type (dhandle),
02380                                 v2 != 0 ? DEBUG_GLOBAL : DEBUG_STATIC,
02381                                 v3);
02382 
02383     case 62:
02384       /* Procedure miscellaneous information.  */
02385     case 63:
02386       /* Variable miscellaneous information.  */
02387     case 64:
02388       /* Module miscellaneous information.  */
02389       if (! ieee_read_number (info, pp, &v)
02390          || ! ieee_read_number (info, pp, &v2)
02391          || ! ieee_read_optional_id (info, pp, &name, &namlen, &present))
02392        return FALSE;
02393 
02394       if (atn_code == 62 && v == 80)
02395        {
02396          if (present)
02397            {
02398              ieee_error (info, atn_code_start,
02399                        _("unexpected string in C++ misc"));
02400              return FALSE;
02401            }
02402          return ieee_read_cxx_misc (info, pp, v2);
02403        }
02404 
02405       /* We just ignore all of this stuff.  FIXME.  */
02406 
02407       for (; v2 > 0; --v2)
02408        {
02409          switch ((ieee_record_enum_type) **pp)
02410            {
02411            default:
02412              ieee_error (info, *pp, _("bad misc record"));
02413              return FALSE;
02414 
02415            case ieee_at_record_enum:
02416              if (! ieee_require_atn65 (info, pp, &name, &namlen))
02417               return FALSE;
02418              break;
02419 
02420            case ieee_e2_first_byte_enum:
02421              if (! ieee_require_asn (info, pp, &v3))
02422               return FALSE;
02423              break;
02424            }
02425        }
02426 
02427       return TRUE;
02428     }
02429 
02430   /*NOTREACHED*/
02431 }
02432 
02433 /* Handle C++ debugging miscellaneous records.  This is called for
02434    procedure miscellaneous records of type 80.  */
02435 
02436 static bfd_boolean
02437 ieee_read_cxx_misc (struct ieee_info *info, const bfd_byte **pp,
02438                   unsigned long count)
02439 {
02440   const bfd_byte *start;
02441   bfd_vma category;
02442 
02443   start = *pp;
02444 
02445   /* Get the category of C++ misc record.  */
02446   if (! ieee_require_asn (info, pp, &category))
02447     return FALSE;
02448   --count;
02449 
02450   switch (category)
02451     {
02452     default:
02453       ieee_error (info, start, _("unrecognized C++ misc record"));
02454       return FALSE;
02455 
02456     case 'T':
02457       if (! ieee_read_cxx_class (info, pp, count))
02458        return FALSE;
02459       break;
02460 
02461     case 'M':
02462       {
02463        bfd_vma flags;
02464        const char *name;
02465        unsigned long namlen;
02466 
02467        /* The IEEE spec indicates that the 'M' record only has a
02468            flags field.  The MRI compiler also emits the name of the
02469            function.  */
02470 
02471        if (! ieee_require_asn (info, pp, &flags))
02472          return FALSE;
02473        if (*pp < info->pend
02474            && (ieee_record_enum_type) **pp == ieee_at_record_enum)
02475          {
02476            if (! ieee_require_atn65 (info, pp, &name, &namlen))
02477              return FALSE;
02478          }
02479 
02480        /* This is emitted for method functions, but I don't think we
02481            care very much.  It might help if it told us useful
02482            information like the class with which this function is
02483            associated, but it doesn't, so it isn't helpful.  */
02484       }
02485       break;
02486 
02487     case 'B':
02488       if (! ieee_read_cxx_defaults (info, pp, count))
02489        return FALSE;
02490       break;
02491 
02492     case 'z':
02493       {
02494        const char *name, *mangled, *class;
02495        unsigned long namlen, mangledlen, classlen;
02496        bfd_vma control;
02497 
02498        /* Pointer to member.  */
02499 
02500        if (! ieee_require_atn65 (info, pp, &name, &namlen)
02501            || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen)
02502            || ! ieee_require_atn65 (info, pp, &class, &classlen)
02503            || ! ieee_require_asn (info, pp, &control))
02504          return FALSE;
02505 
02506        /* FIXME: We should now track down name and change its type.  */
02507       }
02508       break;
02509 
02510     case 'R':
02511       if (! ieee_read_reference (info, pp))
02512        return FALSE;
02513       break;
02514     }
02515 
02516   return TRUE;
02517 }
02518 
02519 /* Read a C++ class definition.  This is a pmisc type 80 record of
02520    category 'T'.  */
02521 
02522 static bfd_boolean
02523 ieee_read_cxx_class (struct ieee_info *info, const bfd_byte **pp,
02524                    unsigned long count)
02525 {
02526   const bfd_byte *start;
02527   bfd_vma class;
02528   const char *tag;
02529   unsigned long taglen;
02530   struct ieee_tag *it;
02531   void *dhandle;
02532   debug_field *fields;
02533   unsigned int field_count, field_alloc;
02534   debug_baseclass *baseclasses;
02535   unsigned int baseclasses_count, baseclasses_alloc;
02536   const debug_field *structfields;
02537   struct ieee_method
02538     {
02539       const char *name;
02540       unsigned long namlen;
02541       debug_method_variant *variants;
02542       unsigned count;
02543       unsigned int alloc;
02544     } *methods;
02545   unsigned int methods_count, methods_alloc;
02546   debug_type vptrbase;
02547   bfd_boolean ownvptr;
02548   debug_method *dmethods;
02549 
02550   start = *pp;
02551 
02552   if (! ieee_require_asn (info, pp, &class))
02553     return FALSE;
02554   --count;
02555 
02556   if (! ieee_require_atn65 (info, pp, &tag, &taglen))
02557     return FALSE;
02558   --count;
02559 
02560   /* Find the C struct with this name.  */
02561   for (it = info->tags; it != NULL; it = it->next)
02562     if (it->name[0] == tag[0]
02563        && strncmp (it->name, tag, taglen) == 0
02564        && strlen (it->name) == taglen)
02565       break;
02566   if (it == NULL)
02567     {
02568       ieee_error (info, start, _("undefined C++ object"));
02569       return FALSE;
02570     }
02571 
02572   dhandle = info->dhandle;
02573 
02574   fields = NULL;
02575   field_count = 0;
02576   field_alloc = 0;
02577   baseclasses = NULL;
02578   baseclasses_count = 0;
02579   baseclasses_alloc = 0;
02580   methods = NULL;
02581   methods_count = 0;
02582   methods_alloc = 0;
02583   vptrbase = DEBUG_TYPE_NULL;
02584   ownvptr = FALSE;
02585 
02586   structfields = debug_get_fields (dhandle, it->type);
02587 
02588   while (count > 0)
02589     {
02590       bfd_vma id;
02591       const bfd_byte *spec_start;
02592 
02593       spec_start = *pp;
02594 
02595       if (! ieee_require_asn (info, pp, &id))
02596        return FALSE;
02597       --count;
02598 
02599       switch (id)
02600        {
02601        default:
02602          ieee_error (info, spec_start, _("unrecognized C++ object spec"));
02603          return FALSE;
02604 
02605        case 'b':
02606          {
02607            bfd_vma flags, cinline;
02608            const char *basename, *fieldname;
02609            unsigned long baselen, fieldlen;
02610            char *basecopy;
02611            debug_type basetype;
02612            bfd_vma bitpos;
02613            bfd_boolean virtualp;
02614            enum debug_visibility visibility;
02615            debug_baseclass baseclass;
02616 
02617            /* This represents a base or friend class.  */
02618 
02619            if (! ieee_require_asn (info, pp, &flags)
02620               || ! ieee_require_atn65 (info, pp, &basename, &baselen)
02621               || ! ieee_require_asn (info, pp, &cinline)
02622               || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen))
02623              return FALSE;
02624            count -= 4;
02625 
02626            /* We have no way of recording friend information, so we
02627                just ignore it.  */
02628            if ((flags & BASEFLAGS_FRIEND) != 0)
02629              break;
02630 
02631            /* I assume that either all of the members of the
02632                baseclass are included in the object, starting at the
02633                beginning of the object, or that none of them are
02634                included.  */
02635 
02636            if ((fieldlen == 0) == (cinline == 0))
02637              {
02638               ieee_error (info, start, _("unsupported C++ object type"));
02639               return FALSE;
02640              }
02641 
02642            basecopy = savestring (basename, baselen);
02643            basetype = debug_find_tagged_type (dhandle, basecopy,
02644                                           DEBUG_KIND_ILLEGAL);
02645            free (basecopy);
02646            if (basetype == DEBUG_TYPE_NULL)
02647              {
02648               ieee_error (info, start, _("C++ base class not defined"));
02649               return FALSE;
02650              }
02651 
02652            if (fieldlen == 0)
02653              bitpos = 0;
02654            else
02655              {
02656               const debug_field *pf;
02657 
02658               if (structfields == NULL)
02659                 {
02660                   ieee_error (info, start, _("C++ object has no fields"));
02661                   return FALSE;
02662                 }
02663 
02664               for (pf = structfields; *pf != DEBUG_FIELD_NULL; pf++)
02665                 {
02666                   const char *fname;
02667 
02668                   fname = debug_get_field_name (dhandle, *pf);
02669                   if (fname == NULL)
02670                     return FALSE;
02671                   if (fname[0] == fieldname[0]
02672                      && strncmp (fname, fieldname, fieldlen) == 0
02673                      && strlen (fname) == fieldlen)
02674                     break;
02675                 }
02676               if (*pf == DEBUG_FIELD_NULL)
02677                 {
02678                   ieee_error (info, start,
02679                             _("C++ base class not found in container"));
02680                   return FALSE;
02681                 }
02682 
02683               bitpos = debug_get_field_bitpos (dhandle, *pf);
02684              }
02685 
02686            if ((flags & BASEFLAGS_VIRTUAL) != 0)
02687              virtualp = TRUE;
02688            else
02689              virtualp = FALSE;
02690            if ((flags & BASEFLAGS_PRIVATE) != 0)
02691              visibility = DEBUG_VISIBILITY_PRIVATE;
02692            else
02693              visibility = DEBUG_VISIBILITY_PUBLIC;
02694 
02695            baseclass = debug_make_baseclass (dhandle, basetype, bitpos,
02696                                          virtualp, visibility);
02697            if (baseclass == DEBUG_BASECLASS_NULL)
02698              return FALSE;
02699 
02700            if (baseclasses_count + 1 >= baseclasses_alloc)
02701              {
02702               baseclasses_alloc += 10;
02703               baseclasses = ((debug_baseclass *)
02704                             xrealloc (baseclasses,
02705                                     (baseclasses_alloc
02706                                      * sizeof *baseclasses)));
02707              }
02708 
02709            baseclasses[baseclasses_count] = baseclass;
02710            ++baseclasses_count;
02711            baseclasses[baseclasses_count] = DEBUG_BASECLASS_NULL;
02712          }
02713          break;
02714 
02715        case 'd':
02716          {
02717            bfd_vma flags;
02718            const char *fieldname, *mangledname;
02719            unsigned long fieldlen, mangledlen;
02720            char *fieldcopy;
02721            bfd_boolean staticp;
02722            debug_type ftype;
02723            const debug_field *pf = NULL;
02724            enum debug_visibility visibility;
02725            debug_field field;
02726 
02727            /* This represents a data member.  */
02728 
02729            if (! ieee_require_asn (info, pp, &flags)
02730               || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen)
02731               || ! ieee_require_atn65 (info, pp, &mangledname, &mangledlen))
02732              return FALSE;
02733            count -= 3;
02734 
02735            fieldcopy = savestring (fieldname, fieldlen);
02736 
02737            staticp = (flags & CXXFLAGS_STATIC) != 0 ? TRUE : FALSE;
02738 
02739            if (staticp)
02740              {
02741               struct ieee_var *pv, *pvend;
02742 
02743               /* See if we can find a definition for this variable.  */
02744               pv = info->vars.vars;
02745               pvend = pv + info->vars.alloc;
02746               for (; pv < pvend; pv++)
02747                 if (pv->namlen == mangledlen
02748                     && strncmp (pv->name, mangledname, mangledlen) == 0)
02749                   break;
02750               if (pv < pvend)
02751                 ftype = pv->type;
02752               else
02753                 {
02754                   /* This can happen if the variable is never used.  */
02755                   ftype = ieee_builtin_type (info, start,
02756                                           (unsigned int) builtin_void);
02757                 }
02758              }
02759            else
02760              {
02761               unsigned int findx;
02762 
02763               if (structfields == NULL)
02764                 {
02765                   ieee_error (info, start, _("C++ object has no fields"));
02766                   return FALSE;
02767                 }
02768 
02769               for (pf = structfields, findx = 0;
02770                    *pf != DEBUG_FIELD_NULL;
02771                    pf++, findx++)
02772                 {
02773                   const char *fname;
02774 
02775                   fname = debug_get_field_name (dhandle, *pf);
02776                   if (fname == NULL)
02777                     return FALSE;
02778                   if (fname[0] == mangledname[0]
02779                      && strncmp (fname, mangledname, mangledlen) == 0
02780                      && strlen (fname) == mangledlen)
02781                     break;
02782                 }
02783               if (*pf == DEBUG_FIELD_NULL)
02784                 {
02785                   ieee_error (info, start,
02786                             _("C++ data member not found in container"));
02787                   return FALSE;
02788                 }
02789 
02790               ftype = debug_get_field_type (dhandle, *pf);
02791 
02792               if (debug_get_type_kind (dhandle, ftype) == DEBUG_KIND_POINTER)
02793                 {
02794                   /* We might need to convert this field into a
02795                        reference type later on, so make it an indirect
02796                        type.  */
02797                   if (it->fslots == NULL)
02798                     {
02799                      unsigned int fcnt;
02800                      const debug_field *pfcnt;
02801 
02802                      fcnt = 0;
02803                      for (pfcnt = structfields;
02804                           *pfcnt != DEBUG_FIELD_NULL;
02805                           pfcnt++)
02806                        ++fcnt;
02807                      it->fslots = ((debug_type *)
02808                                   xmalloc (fcnt * sizeof *it->fslots));
02809                      memset (it->fslots, 0,
02810                             fcnt * sizeof *it->fslots);
02811                     }
02812 
02813                   if (ftype == DEBUG_TYPE_NULL)
02814                     return FALSE;
02815                   it->fslots[findx] = ftype;
02816                   ftype = debug_make_indirect_type (dhandle,
02817                                                 it->fslots + findx,
02818                                                 (const char *) NULL);
02819                 }
02820              }
02821            if (ftype == DEBUG_TYPE_NULL)
02822              return FALSE;
02823 
02824            switch (flags & CXXFLAGS_VISIBILITY)
02825              {
02826              default:
02827               ieee_error (info, start, _("unknown C++ visibility"));
02828               return FALSE;
02829 
02830              case CXXFLAGS_VISIBILITY_PUBLIC:
02831               visibility = DEBUG_VISIBILITY_PUBLIC;
02832               break;
02833 
02834              case CXXFLAGS_VISIBILITY_PRIVATE:
02835               visibility = DEBUG_VISIBILITY_PRIVATE;
02836               break;
02837 
02838              case CXXFLAGS_VISIBILITY_PROTECTED:
02839               visibility = DEBUG_VISIBILITY_PROTECTED;
02840               break;
02841              }
02842 
02843            if (staticp)
02844              {
02845               char *mangledcopy;
02846 
02847               mangledcopy = savestring (mangledname, mangledlen);
02848 
02849               field = debug_make_static_member (dhandle, fieldcopy,
02850                                             ftype, mangledcopy,
02851                                             visibility);
02852              }
02853            else
02854              {
02855               bfd_vma bitpos, bitsize;
02856 
02857               bitpos = debug_get_field_bitpos (dhandle, *pf);
02858               bitsize = debug_get_field_bitsize (dhandle, *pf);
02859               if (bitpos == (bfd_vma) -1 || bitsize == (bfd_vma) -1)
02860                 {
02861                   ieee_error (info, start, _("bad C++ field bit pos or size"));
02862                   return FALSE;
02863                 }
02864               field = debug_make_field (dhandle, fieldcopy, ftype, bitpos,
02865                                      bitsize, visibility);
02866              }
02867 
02868            if (field == DEBUG_FIELD_NULL)
02869              return FALSE;
02870 
02871            if (field_count + 1 >= field_alloc)
02872              {
02873               field_alloc += 10;
02874               fields = ((debug_field *)
02875                        xrealloc (fields, field_alloc * sizeof *fields));
02876              }
02877 
02878            fields[field_count] = field;
02879            ++field_count;
02880            fields[field_count] = DEBUG_FIELD_NULL;
02881          }
02882          break;
02883 
02884        case 'm':
02885        case 'v':
02886          {
02887            bfd_vma flags, voffset, control;
02888            const char *name, *mangled;
02889            unsigned long namlen, mangledlen;
02890            struct ieee_var *pv, *pvend;
02891            debug_type type;
02892            enum debug_visibility visibility;
02893            bfd_boolean constp, volatilep;
02894            char *mangledcopy;
02895            debug_method_variant mv;
02896            struct ieee_method *meth;
02897            unsigned int im;
02898 
02899            if (! ieee_require_asn (info, pp, &flags)
02900               || ! ieee_require_atn65 (info, pp, &name, &namlen)
02901               || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
02902              return FALSE;
02903            count -= 3;
02904            if (id != 'v')
02905              voffset = 0;
02906            else
02907              {
02908               if (! ieee_require_asn (info, pp, &voffset))
02909                 return FALSE;
02910               --count;
02911              }
02912            if (! ieee_require_asn (info, pp, &control))
02913              return FALSE;
02914            --count;
02915 
02916            /* We just ignore the control information.  */
02917 
02918            /* We have no way to represent friend information, so we
02919                just ignore it.  */
02920            if ((flags & CXXFLAGS_FRIEND) != 0)
02921              break;
02922 
02923            /* We should already have seen a type for the function.  */
02924            pv = info->vars.vars;
02925            pvend = pv + info->vars.alloc;
02926            for (; pv < pvend; pv++)
02927              if (pv->namlen == mangledlen
02928                 && strncmp (pv->name, mangled, mangledlen) == 0)
02929               break;
02930 
02931            if (pv >= pvend)
02932              {
02933               /* We won't have type information for this function if
02934                  it is not included in this file.  We don't try to
02935                  handle this case.  FIXME.  */
02936               type = (debug_make_function_type
02937                      (dhandle,
02938                       ieee_builtin_type (info, start,
02939                                        (unsigned int) builtin_void),
02940                       (debug_type *) NULL,
02941                       FALSE));
02942              }
02943            else
02944              {
02945               debug_type return_type;
02946               const debug_type *arg_types;
02947               bfd_boolean varargs;
02948 
02949               if (debug_get_type_kind (dhandle, pv->type)
02950                   != DEBUG_KIND_FUNCTION)
02951                 {
02952                   ieee_error (info, start,
02953                             _("bad type for C++ method function"));
02954                   return FALSE;
02955                 }
02956 
02957               return_type = debug_get_return_type (dhandle, pv->type);
02958               arg_types = debug_get_parameter_types (dhandle, pv->type,
02959                                                  &varargs);
02960               if (return_type == DEBUG_TYPE_NULL || arg_types == NULL)
02961                 {
02962                   ieee_error (info, start,
02963                             _("no type information for C++ method function"));
02964                   return FALSE;
02965                 }
02966 
02967               type = debug_make_method_type (dhandle, return_type, it->type,
02968                                           (debug_type *) arg_types,
02969                                           varargs);
02970              }
02971            if (type == DEBUG_TYPE_NULL)
02972              return FALSE;
02973 
02974            switch (flags & CXXFLAGS_VISIBILITY)
02975              {
02976              default:
02977               ieee_error (info, start, _("unknown C++ visibility"));
02978               return FALSE;
02979 
02980              case CXXFLAGS_VISIBILITY_PUBLIC:
02981               visibility = DEBUG_VISIBILITY_PUBLIC;
02982               break;
02983 
02984              case CXXFLAGS_VISIBILITY_PRIVATE:
02985               visibility = DEBUG_VISIBILITY_PRIVATE;
02986               break;
02987 
02988              case CXXFLAGS_VISIBILITY_PROTECTED:
02989               visibility = DEBUG_VISIBILITY_PROTECTED;
02990               break;
02991              }
02992 
02993            constp = (flags & CXXFLAGS_CONST) != 0 ? TRUE : FALSE;
02994            volatilep = (flags & CXXFLAGS_VOLATILE) != 0 ? TRUE : FALSE;
02995 
02996            mangledcopy = savestring (mangled, mangledlen);
02997 
02998            if ((flags & CXXFLAGS_STATIC) != 0)
02999              {
03000               if (id == 'v')
03001                 {
03002                   ieee_error (info, start, _("C++ static virtual method"));
03003                   return FALSE;
03004                 }
03005               mv = debug_make_static_method_variant (dhandle, mangledcopy,
03006                                                  type, visibility,
03007                                                  constp, volatilep);
03008              }
03009            else
03010              {
03011               debug_type vcontext;
03012 
03013               if (id != 'v')
03014                 vcontext = DEBUG_TYPE_NULL;
03015               else
03016                 {
03017                   /* FIXME: How can we calculate this correctly?  */
03018                   vcontext = it->type;
03019                 }
03020               mv = debug_make_method_variant (dhandle, mangledcopy, type,
03021                                           visibility, constp,
03022                                           volatilep, voffset,
03023                                           vcontext);
03024              }
03025            if (mv == DEBUG_METHOD_VARIANT_NULL)
03026              return FALSE;
03027 
03028            for (meth = methods, im = 0; im < methods_count; meth++, im++)
03029              if (meth->namlen == namlen
03030                 && strncmp (meth->name, name, namlen) == 0)
03031               break;
03032            if (im >= methods_count)
03033              {
03034               if (methods_count >= methods_alloc)
03035                 {
03036                   methods_alloc += 10;
03037                   methods = ((struct ieee_method *)
03038                             xrealloc (methods,
03039                                     methods_alloc * sizeof *methods));
03040                 }
03041               methods[methods_count].name = name;
03042               methods[methods_count].namlen = namlen;
03043               methods[methods_count].variants = NULL;
03044               methods[methods_count].count = 0;
03045               methods[methods_count].alloc = 0;
03046               meth = methods + methods_count;
03047               ++methods_count;
03048              }
03049 
03050            if (meth->count + 1 >= meth->alloc)
03051              {
03052               meth->alloc += 10;
03053               meth->variants = ((debug_method_variant *)
03054                               xrealloc (meth->variants,
03055                                        (meth->alloc
03056                                         * sizeof *meth->variants)));
03057              }
03058 
03059            meth->variants[meth->count] = mv;
03060            ++meth->count;
03061            meth->variants[meth->count] = DEBUG_METHOD_VARIANT_NULL;
03062          }
03063          break;
03064 
03065        case 'o':
03066          {
03067            bfd_vma spec;
03068 
03069            /* We have no way to store this information, so we just
03070               ignore it.  */
03071            if (! ieee_require_asn (info, pp, &spec))
03072              return FALSE;
03073            --count;
03074            if ((spec & 4) != 0)
03075              {
03076               const char *filename;
03077               unsigned long filenamlen;
03078               bfd_vma lineno;
03079 
03080               if (! ieee_require_atn65 (info, pp, &filename, &filenamlen)
03081                   || ! ieee_require_asn (info, pp, &lineno))
03082                 return FALSE;
03083               count -= 2;
03084              }
03085            else if ((spec & 8) != 0)
03086              {
03087               const char *mangled;
03088               unsigned long mangledlen;
03089 
03090               if (! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
03091                 return FALSE;
03092               --count;
03093              }
03094            else
03095              {
03096               ieee_error (info, start,
03097                          _("unrecognized C++ object overhead spec"));
03098               return FALSE;
03099              }
03100          }
03101          break;
03102 
03103        case 'z':
03104          {
03105            const char *vname, *basename;
03106            unsigned long vnamelen, baselen;
03107            bfd_vma vsize, control;
03108 
03109            /* A virtual table pointer.  */
03110 
03111            if (! ieee_require_atn65 (info, pp, &vname, &vnamelen)
03112               || ! ieee_require_asn (info, pp, &vsize)
03113               || ! ieee_require_atn65 (info, pp, &basename, &baselen)
03114               || ! ieee_require_asn (info, pp, &control))
03115              return FALSE;
03116            count -= 4;
03117 
03118            /* We just ignore the control number.  We don't care what
03119               the virtual table name is.  We have no way to store the
03120               virtual table size, and I don't think we care anyhow.  */
03121 
03122            /* FIXME: We can't handle multiple virtual table pointers.  */
03123 
03124            if (baselen == 0)
03125              ownvptr = TRUE;
03126            else
03127              {
03128               char *basecopy;
03129 
03130               basecopy = savestring (basename, baselen);
03131               vptrbase = debug_find_tagged_type (dhandle, basecopy,
03132                                              DEBUG_KIND_ILLEGAL);
03133               free (basecopy);
03134               if (vptrbase == DEBUG_TYPE_NULL)
03135                 {
03136                   ieee_error (info, start, _("undefined C++ vtable"));
03137                   return FALSE;
03138                 }
03139              }
03140          }
03141          break;
03142        }
03143     }
03144 
03145   /* Now that we have seen all the method variants, we can call
03146      debug_make_method for each one.  */
03147 
03148   if (methods_count == 0)
03149     dmethods = NULL;
03150   else
03151     {
03152       unsigned int i;
03153 
03154       dmethods = ((debug_method *)
03155                 xmalloc ((methods_count + 1) * sizeof *dmethods));
03156       for (i = 0; i < methods_count; i++)
03157        {
03158          char *namcopy;
03159 
03160          namcopy = savestring (methods[i].name, methods[i].namlen);
03161          dmethods[i] = debug_make_method (dhandle, namcopy,
03162                                       methods[i].variants);
03163          if (dmethods[i] == DEBUG_METHOD_NULL)
03164            return FALSE;
03165        }
03166       dmethods[i] = DEBUG_METHOD_NULL;
03167       free (methods);
03168     }
03169 
03170   /* The struct type was created as an indirect type pointing at
03171      it->slot.  We update it->slot to automatically update all
03172      references to this struct.  */
03173   it->slot = debug_make_object_type (dhandle,
03174                                  class != 'u',
03175                                  debug_get_type_size (dhandle,
03176                                                    it->slot),
03177                                  fields, baseclasses, dmethods,
03178                                  vptrbase, ownvptr);
03179   if (it->slot == DEBUG_TYPE_NULL)
03180     return FALSE;
03181 
03182   return TRUE;
03183 }
03184 
03185 /* Read C++ default argument value and reference type information.  */
03186 
03187 static bfd_boolean
03188 ieee_read_cxx_defaults (struct ieee_info *info, const bfd_byte **pp,
03189                      unsigned long count)
03190 {
03191   const bfd_byte *start;
03192   const char *fnname;
03193   unsigned long fnlen;
03194   bfd_vma defcount;
03195 
03196   start = *pp;
03197 
03198   /* Giving the function name before the argument count is an addendum
03199      to the spec.  The function name is demangled, though, so this
03200      record must always refer to the current function.  */
03201 
03202   if (info->blockstack.bsp <= info->blockstack.stack
03203       || info->blockstack.bsp[-1].fnindx == (unsigned int) -1)
03204     {
03205       ieee_error (info, start, _("C++ default values not in a function"));
03206       return FALSE;
03207     }
03208 
03209   if (! ieee_require_atn65 (info, pp, &fnname, &fnlen)
03210       || ! ieee_require_asn (info, pp, &defcount))
03211     return FALSE;
03212   count -= 2;
03213 
03214   while (defcount-- > 0)
03215     {
03216       bfd_vma type, val;
03217       const char *strval;
03218       unsigned long strvallen;
03219 
03220       if (! ieee_require_asn (info, pp, &type))
03221        return FALSE;
03222       --count;
03223 
03224       switch (type)
03225        {
03226        case 0:
03227        case 4:
03228          break;
03229 
03230        case 1:
03231        case 2:
03232          if (! ieee_require_asn (info, pp, &val))
03233            return FALSE;
03234          --count;
03235          break;
03236 
03237        case 3:
03238        case 7:
03239          if (! ieee_require_atn65 (info, pp, &strval, &strvallen))
03240            return FALSE;
03241          --count;
03242          break;
03243 
03244        default:
03245          ieee_error (info, start, _("unrecognized C++ default type"));
03246          return FALSE;
03247        }
03248 
03249       /* We have no way to record the default argument values, so we
03250          just ignore them.  FIXME.  */
03251     }
03252 
03253   /* Any remaining arguments are indices of parameters that are really
03254      reference type.  */
03255   if (count > 0)
03256     {
03257       void *dhandle;
03258       debug_type *arg_slots;
03259 
03260       dhandle = info->dhandle;
03261       arg_slots = info->types.types[info->blockstack.bsp[-1].fnindx].arg_slots;
03262       while (count-- > 0)
03263        {
03264          bfd_vma indx;
03265          debug_type target;
03266 
03267          if (! ieee_require_asn (info, pp, &indx))
03268            return FALSE;
03269          /* The index is 1 based.  */
03270          --indx;
03271          if (arg_slots == NULL
03272              || arg_slots[indx] == DEBUG_TYPE_NULL
03273              || (debug_get_type_kind (dhandle, arg_slots[indx])
03274                 != DEBUG_KIND_POINTER))
03275            {
03276              ieee_error (info, start, _("reference parameter is not a pointer"));
03277              return FALSE;
03278            }
03279 
03280          target = debug_get_target_type (dhandle, arg_slots[indx]);
03281          arg_slots[indx] = debug_make_reference_type (dhandle, target);
03282          if (arg_slots[indx] == DEBUG_TYPE_NULL)
03283            return FALSE;
03284        }
03285     }
03286 
03287   return TRUE;
03288 }
03289 
03290 /* Read a C++ reference definition.  */
03291 
03292 static bfd_boolean
03293 ieee_read_reference (struct ieee_info *info, const bfd_byte **pp)
03294 {
03295   const bfd_byte *start;
03296   bfd_vma flags;
03297   const char *class, *name;
03298   unsigned long classlen, namlen;
03299   debug_type *pslot;
03300   debug_type target;
03301 
03302   start = *pp;
03303 
03304   if (! ieee_require_asn (info, pp, &flags))
03305     return FALSE;
03306 
03307   /* Giving the class name before the member name is in an addendum to
03308      the spec.  */
03309   if (flags == 3)
03310     {
03311       if (! ieee_require_atn65 (info, pp, &class, &classlen))
03312        return FALSE;
03313     }
03314 
03315   if (! ieee_require_atn65 (info, pp, &name, &namlen))
03316     return FALSE;
03317 
03318   pslot = NULL;
03319   if (flags != 3)
03320     {
03321       int pass;
03322 
03323       /* We search from the last variable indices to the first in
03324         hopes of finding local variables correctly.  We search the
03325         local variables on the first pass, and the global variables
03326         on the second.  FIXME: This probably won't work in all cases.
03327         On the other hand, I don't know what will.  */
03328       for (pass = 0; pass < 2; pass++)
03329        {
03330          struct ieee_vars *vars;
03331          int i;
03332          struct ieee_var *pv = NULL;
03333 
03334          if (pass == 0)
03335            vars = &info->vars;
03336          else
03337            {
03338              vars = info->global_vars;
03339              if (vars == NULL)
03340               break;
03341            }
03342 
03343          for (i = (int) vars->alloc - 1; i >= 0; i--)
03344            {
03345              bfd_boolean found;
03346 
03347              pv = vars->vars + i;
03348 
03349              if (pv->pslot == NULL
03350                 || pv->namlen != namlen
03351                 || strncmp (pv->name, name, namlen) != 0)
03352               continue;
03353 
03354              found = FALSE;
03355              switch (flags)
03356               {
03357               default:
03358                 ieee_error (info, start,
03359                            _("unrecognized C++ reference type"));
03360                 return FALSE;
03361 
03362               case 0:
03363                 /* Global variable or function.  */
03364                 if (pv->kind == IEEE_GLOBAL
03365                     || pv->kind == IEEE_EXTERNAL
03366                     || pv->kind == IEEE_FUNCTION)
03367                   found = TRUE;
03368                 break;
03369 
03370               case 1:
03371                 /* Global static variable or function.  */
03372                 if (pv->kind == IEEE_STATIC
03373                     || pv->kind == IEEE_FUNCTION)
03374                   found = TRUE;
03375                 break;
03376 
03377               case 2:
03378                 /* Local variable.  */
03379                 if (pv->kind == IEEE_LOCAL)
03380                   found = TRUE;
03381                 break;
03382               }
03383 
03384              if (found)
03385               break;
03386            }
03387 
03388          if (i >= 0)
03389            {
03390              pslot = pv->pslot;
03391              break;
03392            }
03393        }
03394     }
03395   else
03396     {
03397       struct ieee_tag *it;
03398 
03399       for (it = info->tags; it != NULL; it = it->next)
03400        {
03401          if (it->name[0] == class[0]
03402              && strncmp (it->name, class, classlen) == 0
03403              && strlen (it->name) == classlen)
03404            {
03405              if (it->fslots != NULL)
03406               {
03407                 const debug_field *pf;
03408                 unsigned int findx;
03409 
03410                 pf = debug_get_fields (info->dhandle, it->type);
03411                 if (pf == NULL)
03412                   {
03413                     ieee_error (info, start,
03414                               "C++ reference in class with no fields");
03415                     return FALSE;
03416                   }
03417 
03418                 for (findx = 0; *pf != DEBUG_FIELD_NULL; pf++, findx++)
03419                   {
03420                     const char *fname;
03421 
03422                     fname = debug_get_field_name (info->dhandle, *pf);
03423                     if (fname == NULL)
03424                      return FALSE;
03425                     if (strncmp (fname, name, namlen) == 0
03426                        && strlen (fname) == namlen)
03427                      {
03428                        pslot = it->fslots + findx;
03429                        break;
03430                      }
03431                   }
03432               }
03433 
03434              break;
03435            }
03436        }
03437     }
03438 
03439   if (pslot == NULL)
03440     {
03441       ieee_error (info, start, _("C++ reference not found"));
03442       return FALSE;
03443     }
03444 
03445   /* We allocated the type of the object as an indirect type pointing
03446      to *pslot, which we can now update to be a reference type.  */
03447   if (debug_get_type_kind (info->dhandle, *pslot) != DEBUG_KIND_POINTER)
03448     {
03449       ieee_error (info, start, _("C++ reference is not pointer"));
03450       return FALSE;
03451     }
03452 
03453   target = debug_get_target_type (info->dhandle, *pslot);
03454   *pslot = debug_make_reference_type (info->dhandle, target);
03455   if (*pslot == DEBUG_TYPE_NULL)
03456     return FALSE;
03457 
03458   return TRUE;
03459 }
03460 
03461 /* Require an ASN record.  */
03462 
03463 static bfd_boolean
03464 ieee_require_asn (struct ieee_info *info, const bfd_byte **pp, bfd_vma *pv)
03465 {
03466   const bfd_byte *start;
03467   ieee_record_enum_type c;
03468   bfd_vma varindx;
03469 
03470   start = *pp;
03471 
03472   c = (ieee_record_enum_type) **pp;
03473   if (c != ieee_e2_first_byte_enum)
03474     {
03475       ieee_error (info, start, _("missing required ASN"));
03476       return FALSE;
03477     }
03478   ++*pp;
03479 
03480   c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
03481   if (c != ieee_asn_record_enum)
03482     {
03483       ieee_error (info, start, _("missing required ASN"));
03484       return FALSE;
03485     }
03486   ++*pp;
03487 
03488   /* Just ignore the variable index.  */
03489   if (! ieee_read_number (info, pp, &varindx))
03490     return FALSE;
03491 
03492   return ieee_read_expression (info, pp, pv);
03493 }
03494 
03495 /* Require an ATN65 record.  */
03496 
03497 static bfd_boolean
03498 ieee_require_atn65 (struct ieee_info *info, const bfd_byte **pp,
03499                   const char **pname, unsigned long *pnamlen)
03500 {
03501   const bfd_byte *start;
03502   ieee_record_enum_type c;
03503   bfd_vma name_indx, type_indx, atn_code;
03504 
03505   start = *pp;
03506 
03507   c = (ieee_record_enum_type) **pp;
03508   if (c != ieee_at_record_enum)
03509     {
03510       ieee_error (info, start, _("missing required ATN65"));
03511       return FALSE;
03512     }
03513   ++*pp;
03514 
03515   c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
03516   if (c != ieee_atn_record_enum)
03517     {
03518       ieee_error (info, start, _("missing required ATN65"));
03519       return FALSE;
03520     }
03521   ++*pp;
03522 
03523   if (! ieee_read_number (info, pp, &name_indx)
03524       || ! ieee_read_number (info, pp, &type_indx)
03525       || ! ieee_read_number (info, pp, &atn_code))
03526     return FALSE;
03527 
03528   /* Just ignore name_indx.  */
03529 
03530   if (type_indx != 0 || atn_code != 65)
03531     {
03532       ieee_error (info, start, _("bad ATN65 record"));
03533       return FALSE;
03534     }
03535 
03536   return ieee_read_id (info, pp, pname, pnamlen);
03537 }
03538 
03539 /* Convert a register number in IEEE debugging information into a
03540    generic register number.  */
03541 
03542 static int
03543 ieee_regno_to_genreg (bfd *abfd, int r)
03544 {
03545   switch (bfd_get_arch (abfd))
03546     {
03547     case bfd_arch_m68k:
03548       /* For some reasons stabs adds 2 to the floating point register
03549          numbers.  */
03550       if (r >= 16)
03551        r += 2;
03552       break;
03553 
03554     case bfd_arch_i960:
03555       /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
03556          32 to 35 for fp0 to fp3.  */
03557       --r;
03558       break;
03559 
03560     default:
03561       break;
03562     }
03563 
03564   return r;
03565 }
03566 
03567 /* Convert a generic register number to an IEEE specific one.  */
03568 
03569 static int
03570 ieee_genreg_to_regno (bfd *abfd, int r)
03571 {
03572   switch (bfd_get_arch (abfd))
03573     {
03574     case bfd_arch_m68k:
03575       /* For some reason stabs add 2 to the floating point register
03576          numbers.  */
03577       if (r >= 18)
03578        r -= 2;
03579       break;
03580 
03581     case bfd_arch_i960:
03582       /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
03583          32 to 35 for fp0 to fp3.  */
03584       ++r;
03585       break;
03586 
03587     default:
03588       break;
03589     }
03590 
03591   return r;
03592 }
03593 
03594 /* These routines build IEEE debugging information out of the generic
03595    debugging information.  */
03596 
03597 /* We build the IEEE debugging information byte by byte.  Rather than
03598    waste time copying data around, we use a linked list of buffers to
03599    hold the data.  */
03600 
03601 #define IEEE_BUFSIZE (490)
03602 
03603 struct ieee_buf
03604 {
03605   /* Next buffer.  */
03606   struct ieee_buf *next;
03607   /* Number of data bytes in this buffer.  */
03608   unsigned int c;
03609   /* Bytes.  */
03610   bfd_byte buf[IEEE_BUFSIZE];
03611 };
03612 
03613 /* A list of buffers.  */
03614 
03615 struct ieee_buflist
03616 {
03617   /* Head of list.  */
03618   struct ieee_buf *head;
03619   /* Tail--last buffer on list.  */
03620   struct ieee_buf *tail;
03621 };
03622 
03623 /* In order to generate the BB11 blocks required by the HP emulator,
03624    we keep track of ranges of addresses which correspond to a given
03625    compilation unit.  */
03626 
03627 struct ieee_range
03628 {
03629   /* Next range.  */
03630   struct ieee_range *next;
03631   /* Low address.  */
03632   bfd_vma low;
03633   /* High address.  */
03634   bfd_vma high;
03635 };
03636 
03637 /* This structure holds information for a class on the type stack.  */
03638 
03639 struct ieee_type_class
03640 {
03641   /* The name index in the debugging information.  */
03642   unsigned int indx;
03643   /* The pmisc records for the class.  */
03644   struct ieee_buflist pmiscbuf;
03645   /* The number of pmisc records.  */
03646   unsigned int pmisccount;
03647   /* The name of the class holding the virtual table, if not this
03648      class.  */
03649   const char *vclass;
03650   /* Whether this class holds its own virtual table.  */
03651   bfd_boolean ownvptr;
03652   /* The largest virtual table offset seen so far.  */
03653   bfd_vma voffset;
03654   /* The current method.  */
03655   const char *method;
03656   /* Additional pmisc records used to record fields of reference type.  */
03657   struct ieee_buflist refs;
03658 };
03659 
03660 /* This is how we store types for the writing routines.  Most types
03661    are simply represented by a type index.  */
03662 
03663 struct ieee_write_type
03664 {
03665   /* Type index.  */
03666   unsigned int indx;
03667   /* The size of the type, if known.  */
03668   unsigned int size;
03669   /* The name of the type, if any.  */
03670   const char *name;
03671   /* If this is a function or method type, we build the type here, and
03672      only add it to the output buffers if we need it.  */
03673   struct ieee_buflist fndef;
03674   /* If this is a struct, this is where the struct definition is
03675      built.  */
03676   struct ieee_buflist strdef;
03677   /* If this is a class, this is where the class information is built.  */
03678   struct ieee_type_class *classdef;
03679   /* Whether the type is unsigned.  */
03680   unsigned int unsignedp : 1;
03681   /* Whether this is a reference type.  */
03682   unsigned int referencep : 1;
03683   /* Whether this is in the local type block.  */
03684   unsigned int localp : 1;
03685   /* Whether this is a duplicate struct definition which we are
03686      ignoring.  */
03687   unsigned int ignorep : 1;
03688 };
03689 
03690 /* This is the type stack used by the debug writing routines.  FIXME:
03691    We could generate more efficient output if we remembered when we
03692    have output a particular type before.  */
03693 
03694 struct ieee_type_stack
03695 {
03696   /* Next entry on stack.  */
03697   struct ieee_type_stack *next;
03698   /* Type information.  */
03699   struct ieee_write_type type;
03700 };
03701 
03702 /* This is a list of associations between a name and some types.
03703    These are used for typedefs and tags.  */
03704 
03705 struct ieee_name_type
03706 {
03707   /* Next type for this name.  */
03708   struct ieee_name_type *next;
03709   /* ID number.  For a typedef, this is the index of the type to which
03710      this name is typedefed.  */
03711   unsigned int id;
03712   /* Type.  */
03713   struct ieee_write_type type;
03714   /* If this is a tag which has not yet been defined, this is the
03715      kind.  If the tag has been defined, this is DEBUG_KIND_ILLEGAL.  */
03716   enum debug_type_kind kind;
03717 };
03718 
03719 /* We use a hash table to associate names and types.  */
03720 
03721 struct ieee_name_type_hash_table
03722 {
03723   struct bfd_hash_table root;
03724 };
03725 
03726 struct ieee_name_type_hash_entry
03727 {
03728   struct bfd_hash_entry root;
03729   /* Information for this name.  */
03730   struct ieee_name_type *types;
03731 };
03732 
03733 /* This is a list of enums.  */
03734 
03735 struct ieee_defined_enum
03736 {
03737   /* Next enum.  */
03738   struct ieee_defined_enum *next;
03739   /* Type index.  */
03740   unsigned int indx;
03741   /* Whether this enum has been defined.  */
03742   bfd_boolean defined;
03743   /* Tag.  */
03744   const char *tag;
03745   /* Names.  */
03746   const char **names;
03747   /* Values.  */
03748   bfd_signed_vma *vals;
03749 };
03750 
03751 /* We keep a list of modified versions of types, so that we don't
03752    output them more than once.  */
03753 
03754 struct ieee_modified_type
03755 {
03756   /* Pointer to this type.  */
03757   unsigned int pointer;
03758   /* Function with unknown arguments returning this type.  */
03759   unsigned int function;
03760   /* Const version of this type.  */
03761   unsigned int const_qualified;
03762   /* Volatile version of this type.  */
03763   unsigned int volatile_qualified;
03764   /* List of arrays of this type of various bounds.  */
03765   struct ieee_modified_array_type *arrays;
03766 };
03767 
03768 /* A list of arrays bounds.  */
03769 
03770 struct ieee_modified_array_type
03771 {
03772   /* Next array bounds.  */
03773   struct ieee_modified_array_type *next;
03774   /* Type index with these bounds.  */
03775   unsigned int indx;
03776   /* Low bound.  */
03777   bfd_signed_vma low;
03778   /* High bound.  */
03779   bfd_signed_vma high;
03780 };
03781 
03782 /* This is a list of pending function parameter information.  We don't
03783    output them until we see the first block.  */
03784 
03785 struct ieee_pending_parm
03786 {
03787   /* Next pending parameter.  */
03788   struct ieee_pending_parm *next;
03789   /* Name.  */
03790   const char *name;
03791   /* Type index.  */
03792   unsigned int type;
03793   /* Whether the type is a reference.  */
03794   bfd_boolean referencep;
03795   /* Kind.  */
03796   enum debug_parm_kind kind;
03797   /* Value.  */
03798   bfd_vma val;
03799 };
03800 
03801 /* This is the handle passed down by debug_write.  */
03802 
03803 struct ieee_handle
03804 {
03805   /* BFD we are writing to.  */
03806   bfd *abfd;
03807   /* Whether we got an error in a subroutine called via traverse or
03808      map_over_sections.  */
03809   bfd_boolean error;
03810   /* Current data buffer list.  */
03811   struct ieee_buflist *current;
03812   /* Current data buffer.  */
03813   struct ieee_buf *curbuf;
03814   /* Filename of current compilation unit.  */
03815   const char *filename;
03816   /* Module name of current compilation unit.  */
03817   const char *modname;
03818   /* List of buffer for global types.  */
03819   struct ieee_buflist global_types;
03820   /* List of finished data buffers.  */
03821   struct ieee_buflist data;
03822   /* List of buffers for typedefs in the current compilation unit.  */
03823   struct ieee_buflist types;
03824   /* List of buffers for variables and functions in the current
03825      compilation unit.  */
03826   struct ieee_buflist vars;
03827   /* List of buffers for C++ class definitions in the current
03828      compilation unit.  */
03829   struct ieee_buflist cxx;
03830   /* List of buffers for line numbers in the current compilation unit.  */
03831   struct ieee_buflist linenos;
03832   /* Ranges for the current compilation unit.  */
03833   struct ieee_range *ranges;
03834   /* Ranges for all debugging information.  */
03835   struct ieee_range *global_ranges;
03836   /* Nested pending ranges.  */
03837   struct ieee_range *pending_ranges;
03838   /* Type stack.  */
03839   struct ieee_type_stack *type_stack;
03840   /* Next unallocated type index.  */
03841   unsigned int type_indx;
03842   /* Next unallocated name index.  */
03843   unsigned int name_indx;
03844   /* Typedefs.  */
03845   struct ieee_name_type_hash_table typedefs;
03846   /* Tags.  */
03847   struct ieee_name_type_hash_table tags;
03848   /* Enums.  */
03849   struct ieee_defined_enum *enums;
03850   /* Modified versions of types.  */
03851   struct ieee_modified_type *modified;
03852   /* Number of entries allocated in modified.  */
03853   unsigned int modified_alloc;
03854   /* 4 byte complex type.  */
03855   unsigned int complex_float_index;
03856   /* 8 byte complex type.  */
03857   unsigned int complex_double_index;
03858   /* The depth of block nesting.  This is 0 outside a function, and 1
03859      just after start_function is called.  */
03860   unsigned int block_depth;
03861   /* The name of the current function.  */
03862   const char *fnname;
03863   /* List of buffers for the type of the function we are currently
03864      writing out.  */
03865   struct ieee_buflist fntype;
03866   /* List of buffers for the parameters of the function we are
03867      currently writing out.  */
03868   struct ieee_buflist fnargs;
03869   /* Number of arguments written to fnargs.  */
03870   unsigned int fnargcount;
03871   /* Pending function parameters.  */
03872   struct ieee_pending_parm *pending_parms;
03873   /* Current line number filename.  */
03874   const char *lineno_filename;
03875   /* Line number name index.  */
03876   unsigned int lineno_name_indx;
03877   /* Filename of pending line number.  */
03878   const char *pending_lineno_filename;
03879   /* Pending line number.  */
03880   unsigned long pending_lineno;
03881   /* Address of pending line number.  */
03882   bfd_vma pending_lineno_addr;
03883   /* Highest address seen at end of procedure.  */
03884   bfd_vma highaddr;
03885 };
03886 
03887 static bfd_boolean ieee_init_buffer
03888   (struct ieee_handle *, struct ieee_buflist *);
03889 static bfd_boolean ieee_change_buffer
03890   (struct ieee_handle *, struct ieee_buflist *);
03891 static bfd_boolean ieee_append_buffer
03892   (struct ieee_handle *, struct ieee_buflist *, struct ieee_buflist *);
03893 static bfd_boolean ieee_real_write_byte (struct ieee_handle *, int);
03894 static bfd_boolean ieee_write_2bytes (struct ieee_handle *, int);
03895 static bfd_boolean ieee_write_number (struct ieee_handle *, bfd_vma);
03896 static bfd_boolean ieee_write_id (struct ieee_handle *, const char *);
03897 static bfd_boolean ieee_write_asn
03898   (struct ieee_handle *, unsigned int, bfd_vma);
03899 static bfd_boolean ieee_write_atn65
03900   (struct ieee_handle *, unsigned int, const char *);
03901 static bfd_boolean ieee_push_type
03902   (struct ieee_handle *, unsigned int, unsigned int, bfd_boolean,
03903    bfd_boolean);
03904 static unsigned int ieee_pop_type (struct ieee_handle *);
03905 static void ieee_pop_unused_type (struct ieee_handle *);
03906 static unsigned int ieee_pop_type_used (struct ieee_handle *, bfd_boolean);
03907 static bfd_boolean ieee_add_range
03908   (struct ieee_handle *, bfd_boolean, bfd_vma, bfd_vma);
03909 static bfd_boolean ieee_start_range (struct ieee_handle *, bfd_vma);
03910 static bfd_boolean ieee_end_range (struct ieee_handle *, bfd_vma);
03911 static bfd_boolean ieee_define_type
03912   (struct ieee_handle *, unsigned int, bfd_boolean, bfd_boolean);
03913 static bfd_boolean ieee_define_named_type
03914   (struct ieee_handle *, const char *, unsigned int, unsigned int,
03915    bfd_boolean, bfd_boolean, struct ieee_buflist *);
03916 static struct ieee_modified_type *ieee_get_modified_info
03917   (struct ieee_handle *, unsigned int);
03918 static struct bfd_hash_entry *ieee_name_type_newfunc
03919   (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
03920 static bfd_boolean ieee_write_undefined_tag
03921   (struct ieee_name_type_hash_entry *, void *);
03922 static bfd_boolean ieee_finish_compilation_unit (struct ieee_handle *);
03923 static void ieee_add_bb11_blocks (bfd *, asection *, void *);
03924 static bfd_boolean ieee_add_bb11
03925   (struct ieee_handle *, asection *, bfd_vma, bfd_vma);
03926 static bfd_boolean ieee_output_pending_parms (struct ieee_handle *);
03927 static unsigned int ieee_vis_to_flags (enum debug_visibility);
03928 static bfd_boolean ieee_class_method_var
03929   (struct ieee_handle *, const char *, enum debug_visibility, bfd_boolean,
03930    bfd_boolean, bfd_boolean, bfd_vma, bfd_boolean);
03931 
03932 static bfd_boolean ieee_start_compilation_unit (void *, const char *);
03933 static bfd_boolean ieee_start_source (void *, const char *);
03934 static bfd_boolean ieee_empty_type (void *);
03935 static bfd_boolean ieee_void_type (void *);
03936 static bfd_boolean ieee_int_type (void *, unsigned int, bfd_boolean);
03937 static bfd_boolean ieee_float_type (void *, unsigned int);
03938 static bfd_boolean ieee_complex_type (void *, unsigned int);
03939 static bfd_boolean ieee_bool_type (void *, unsigned int);
03940 static bfd_boolean ieee_enum_type
03941   (void *, const char *, const char **, bfd_signed_vma *);
03942 static bfd_boolean ieee_pointer_type (void *);
03943 static bfd_boolean ieee_function_type (void *, int, bfd_boolean);
03944 static bfd_boolean ieee_reference_type (void *);
03945 static bfd_boolean ieee_range_type (void *, bfd_signed_vma, bfd_signed_vma);
03946 static bfd_boolean ieee_array_type
03947   (void *, bfd_signed_vma, bfd_signed_vma, bfd_boolean);
03948 static bfd_boolean ieee_set_type (void *, bfd_boolean);
03949 static bfd_boolean ieee_offset_type (void *);
03950 static bfd_boolean ieee_method_type (void *, bfd_boolean, int, bfd_boolean);
03951 static bfd_boolean ieee_const_type (void *);
03952 static bfd_boolean ieee_volatile_type (void *);
03953 static bfd_boolean ieee_start_struct_type
03954   (void *, const char *, unsigned int, bfd_boolean, unsigned int);
03955 static bfd_boolean ieee_struct_field
03956   (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
03957 static bfd_boolean ieee_end_struct_type (void *);
03958 static bfd_boolean ieee_start_class_type
03959   (void *, const char *, unsigned int, bfd_boolean, unsigned int, bfd_boolean,
03960    bfd_boolean);
03961 static bfd_boolean ieee_class_static_member
03962   (void *, const char *, const char *, enum debug_visibility);
03963 static bfd_boolean ieee_class_baseclass
03964   (void *, bfd_vma, bfd_boolean, enum debug_visibility);
03965 static bfd_boolean ieee_class_start_method (void *, const char *);
03966 static bfd_boolean ieee_class_method_variant
03967   (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean,
03968    bfd_vma, bfd_boolean);
03969 static bfd_boolean ieee_class_static_method_variant
03970   (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean);
03971 static bfd_boolean ieee_class_end_method (void *);
03972 static bfd_boolean ieee_end_class_type (void *);
03973 static bfd_boolean ieee_typedef_type (void *, const char *);
03974 static bfd_boolean ieee_tag_type
03975   (void *, const char *, unsigned int, enum debug_type_kind);
03976 static bfd_boolean ieee_typdef (void *, const char *);
03977 static bfd_boolean ieee_tag (void *, const char *);
03978 static bfd_boolean ieee_int_constant (void *, const char *, bfd_vma);
03979 static bfd_boolean ieee_float_constant (void *, const char *, double);
03980 static bfd_boolean ieee_typed_constant (void *, const char *, bfd_vma);
03981 static bfd_boolean ieee_variable
03982   (void *, const char *, enum debug_var_kind, bfd_vma);
03983 static bfd_boolean ieee_start_function (void *, const char *, bfd_boolean);
03984 static bfd_boolean ieee_function_parameter
03985   (void *, const char *, enum debug_parm_kind, bfd_vma);
03986 static bfd_boolean ieee_start_block (void *, bfd_vma);
03987 static bfd_boolean ieee_end_block (void *, bfd_vma);
03988 static bfd_boolean ieee_end_function (void *);
03989 static bfd_boolean ieee_lineno (void *, const char *, unsigned long, bfd_vma);
03990 
03991 static const struct debug_write_fns ieee_fns =
03992 {
03993   ieee_start_compilation_unit,
03994   ieee_start_source,
03995   ieee_empty_type,
03996   ieee_void_type,
03997   ieee_int_type,
03998   ieee_float_type,
03999   ieee_complex_type,
04000   ieee_bool_type,
04001   ieee_enum_type,
04002   ieee_pointer_type,
04003   ieee_function_type,
04004   ieee_reference_type,
04005   ieee_range_type,
04006   ieee_array_type,
04007   ieee_set_type,
04008   ieee_offset_type,
04009   ieee_method_type,
04010   ieee_const_type,
04011   ieee_volatile_type,
04012   ieee_start_struct_type,
04013   ieee_struct_field,
04014   ieee_end_struct_type,
04015   ieee_start_class_type,
04016   ieee_class_static_member,
04017   ieee_class_baseclass,
04018   ieee_class_start_method,
04019   ieee_class_method_variant,
04020   ieee_class_static_method_variant,
04021   ieee_class_end_method,
04022   ieee_end_class_type,
04023   ieee_typedef_type,
04024   ieee_tag_type,
04025   ieee_typdef,
04026   ieee_tag,
04027   ieee_int_constant,
04028   ieee_float_constant,
04029   ieee_typed_constant,
04030   ieee_variable,
04031   ieee_start_function,
04032   ieee_function_parameter,
04033   ieee_start_block,
04034   ieee_end_block,
04035   ieee_end_function,
04036   ieee_lineno
04037 };
04038 
04039 /* Initialize a buffer to be empty.  */
04040 
04041 static bfd_boolean
04042 ieee_init_buffer (struct ieee_handle *info ATTRIBUTE_UNUSED,
04043                 struct ieee_buflist *buflist)
04044 {
04045   buflist->head = NULL;
04046   buflist->tail = NULL;
04047   return TRUE;
04048 }
04049 
04050 /* See whether a buffer list has any data.  */
04051 
04052 #define ieee_buffer_emptyp(buflist) ((buflist)->head == NULL)
04053 
04054 /* Change the current buffer to a specified buffer chain.  */
04055 
04056 static bfd_boolean
04057 ieee_change_buffer (struct ieee_handle *info, struct ieee_buflist *buflist)
04058 {
04059   if (buflist->head == NULL)
04060     {
04061       struct ieee_buf *buf;
04062 
04063       buf = (struct ieee_buf *) xmalloc (sizeof *buf);
04064       buf->next = NULL;
04065       buf->c = 0;
04066       buflist->head = buf;
04067       buflist->tail = buf;
04068     }
04069 
04070   info->current = buflist;
04071   info->curbuf = buflist->tail;
04072 
04073   return TRUE;
04074 }
04075 
04076 /* Append a buffer chain.  */
04077 
04078 static bfd_boolean
04079 ieee_append_buffer (struct ieee_handle *info ATTRIBUTE_UNUSED,
04080                   struct ieee_buflist *mainbuf,
04081                   struct ieee_buflist *newbuf)
04082 {
04083   if (newbuf->head != NULL)
04084     {
04085       if (mainbuf->head == NULL)
04086        mainbuf->head = newbuf->head;
04087       else
04088        mainbuf->tail->next = newbuf->head;
04089       mainbuf->tail = newbuf->tail;
04090     }
04091   return TRUE;
04092 }
04093 
04094 /* Write a byte into the buffer.  We use a macro for speed and a
04095    function for the complex cases.  */
04096 
04097 #define ieee_write_byte(info, b)                        \
04098   ((info)->curbuf->c < IEEE_BUFSIZE                            \
04099    ? ((info)->curbuf->buf[(info)->curbuf->c++] = (b), TRUE)    \
04100    : ieee_real_write_byte ((info), (b)))
04101 
04102 static bfd_boolean
04103 ieee_real_write_byte (struct ieee_handle *info, int b)
04104 {
04105   if (info->curbuf->c >= IEEE_BUFSIZE)
04106     {
04107       struct ieee_buf *n;
04108 
04109       n = (struct ieee_buf *) xmalloc (sizeof *n);
04110       n->next = NULL;
04111       n->c = 0;
04112       if (info->current->head == NULL)
04113        info->current->head = n;
04114       else
04115        info->current->tail->next = n;
04116       info->current->tail = n;
04117       info->curbuf = n;
04118     }
04119 
04120   info->curbuf->buf[info->curbuf->c] = b;
04121   ++info->curbuf->c;
04122 
04123   return TRUE;
04124 }
04125 
04126 /* Write out two bytes.  */
04127 
04128 static bfd_boolean
04129 ieee_write_2bytes (struct ieee_handle *info, int i)
04130 {
04131   return (ieee_write_byte (info, i >> 8)
04132          && ieee_write_byte (info, i & 0xff));
04133 }
04134 
04135 /* Write out an integer.  */
04136 
04137 static bfd_boolean
04138 ieee_write_number (struct ieee_handle *info, bfd_vma v)
04139 {
04140   bfd_vma t;
04141   bfd_byte ab[20];
04142   bfd_byte *p;
04143   unsigned int c;
04144 
04145   if (v <= (bfd_vma) ieee_number_end_enum)
04146     return ieee_write_byte (info, (int) v);
04147 
04148   t = v;
04149   p = ab + sizeof ab;
04150   while (t != 0)
04151     {
04152       *--p = t & 0xff;
04153       t >>= 8;
04154     }
04155   c = (ab + 20) - p;
04156 
04157   if (c > (unsigned int) (ieee_number_repeat_end_enum
04158                        - ieee_number_repeat_start_enum))
04159     {
04160       fprintf (stderr, _("IEEE numeric overflow: 0x"));
04161       fprintf_vma (stderr, v);
04162       fprintf (stderr, "\n");
04163       return FALSE;
04164     }
04165 
04166   if (! ieee_write_byte (info, (int) ieee_number_repeat_start_enum + c))
04167     return FALSE;
04168   for (; c > 0; --c, ++p)
04169     {
04170       if (! ieee_write_byte (info, *p))
04171        return FALSE;
04172     }
04173 
04174   return TRUE;
04175 }
04176 
04177 /* Write out a string.  */
04178 
04179 static bfd_boolean
04180 ieee_write_id (struct ieee_handle *info, const char *s)
04181 {
04182   unsigned int len;
04183 
04184   len = strlen (s);
04185   if (len <= 0x7f)
04186     {
04187       if (! ieee_write_byte (info, len))
04188        return FALSE;
04189     }
04190   else if (len <= 0xff)
04191     {
04192       if (! ieee_write_byte (info, (int) ieee_extension_length_1_enum)
04193          || ! ieee_write_byte (info, len))
04194        return FALSE;
04195     }
04196   else if (len <= 0xffff)
04197     {
04198       if (! ieee_write_byte (info, (int) ieee_extension_length_2_enum)
04199          || ! ieee_write_2bytes (info, len))
04200        return FALSE;
04201     }
04202   else
04203     {
04204       fprintf (stderr, _("IEEE string length overflow: %u\n"), len);
04205       return FALSE;
04206     }
04207 
04208   for (; *s != '\0'; s++)
04209     if (! ieee_write_byte (info, *s))
04210       return FALSE;
04211 
04212   return TRUE;
04213 }
04214 
04215 /* Write out an ASN record.  */
04216 
04217 static bfd_boolean
04218 ieee_write_asn (struct ieee_handle *info, unsigned int indx, bfd_vma val)
04219 {
04220   return (ieee_write_2bytes (info, (int) ieee_asn_record_enum)
04221          && ieee_write_number (info, indx)
04222          && ieee_write_number (info, val));
04223 }
04224 
04225 /* Write out an ATN65 record.  */
04226 
04227 static bfd_boolean
04228 ieee_write_atn65 (struct ieee_handle *info, unsigned int indx, const char *s)
04229 {
04230   return (ieee_write_2bytes (info, (int) ieee_atn_record_enum)
04231          && ieee_write_number (info, indx)
04232          && ieee_write_number (info, 0)
04233          && ieee_write_number (info, 65)
04234          && ieee_write_id (info, s));
04235 }
04236 
04237 /* Push a type index onto the type stack.  */
04238 
04239 static bfd_boolean
04240 ieee_push_type (struct ieee_handle *info, unsigned int indx,
04241               unsigned int size, bfd_boolean unsignedp, bfd_boolean localp)
04242 {
04243   struct ieee_type_stack *ts;
04244 
04245   ts = (struct ieee_type_stack *) xmalloc (sizeof *ts);
04246   memset (ts, 0, sizeof *ts);
04247 
04248   ts->type.indx = indx;
04249   ts->type.size = size;
04250   ts->type.unsignedp = unsignedp;
04251   ts->type.localp = localp;
04252 
04253   ts->next = info->type_stack;
04254   info->type_stack = ts;
04255 
04256   return TRUE;
04257 }
04258 
04259 /* Pop a type index off the type stack.  */
04260 
04261 static unsigned int
04262 ieee_pop_type (struct ieee_handle *info)
04263 {
04264   return ieee_pop_type_used (info, TRUE);
04265 }
04266 
04267 /* Pop an unused type index off the type stack.  */
04268 
04269 static void
04270 ieee_pop_unused_type (struct ieee_handle *info)
04271 {
04272   (void) ieee_pop_type_used (info, FALSE);
04273 }
04274 
04275 /* Pop a used or unused type index off the type stack.  */
04276 
04277 static unsigned int
04278 ieee_pop_type_used (struct ieee_handle *info, bfd_boolean used)
04279 {
04280   struct ieee_type_stack *ts;
04281   unsigned int ret;
04282 
04283   ts = info->type_stack;
04284   assert (ts != NULL);
04285 
04286   /* If this is a function type, and we need it, we need to append the
04287      actual definition to the typedef block now.  */
04288   if (used && ! ieee_buffer_emptyp (&ts->type.fndef))
04289     {
04290       struct ieee_buflist *buflist;
04291 
04292       if (ts->type.localp)
04293        {
04294          /* Make sure we have started the types block.  */
04295          if (ieee_buffer_emptyp (&info->types))
04296            {
04297              if (! ieee_change_buffer (info, &info->types)
04298                 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
04299                 || ! ieee_write_byte (info, 1)
04300                 || ! ieee_write_number (info, 0)
04301                 || ! ieee_write_id (info, info->modname))
04302               return FALSE;
04303            }
04304          buflist = &info->types;
04305        }
04306       else
04307        {
04308          /* Make sure we started the global type block.  */
04309          if (ieee_buffer_emptyp (&info->global_types))
04310            {
04311              if (! ieee_change_buffer (info, &info->global_types)
04312                 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
04313                 || ! ieee_write_byte (info, 2)
04314                 || ! ieee_write_number (info, 0)
04315                 || ! ieee_write_id (info, ""))
04316               return FALSE;
04317            }
04318          buflist = &info->global_types;
04319        }
04320 
04321       if (! ieee_append_buffer (info, buflist, &ts->type.fndef))
04322        return FALSE;
04323     }
04324 
04325   ret = ts->type.indx;
04326   info->type_stack = ts->next;
04327   free (ts);
04328   return ret;
04329 }
04330 
04331 /* Add a range of bytes included in the current compilation unit.  */
04332 
04333 static bfd_boolean
04334 ieee_add_range (struct ieee_handle *info, bfd_boolean global, bfd_vma low,
04335               bfd_vma high)
04336 {
04337   struct ieee_range **plist, *r, **pr;
04338 
04339   if (low == (bfd_vma) -1 || high == (bfd_vma) -1 || low == high)
04340     return TRUE;
04341 
04342   if (global)
04343     plist = &info->global_ranges;
04344   else
04345     plist = &info->ranges;
04346 
04347   for (r = *plist; r != NULL; r = r->next)
04348     {
04349       if (high >= r->low && low <= r->high)
04350        {
04351          /* The new range overlaps r.  */
04352          if (low < r->low)
04353            r->low = low;
04354          if (high > r->high)
04355            r->high = high;
04356          pr = &r->next;
04357          while (*pr != NULL && (*pr)->low <= r->high)
04358            {
04359              struct ieee_range *n;
04360 
04361              if ((*pr)->high > r->high)
04362               r->high = (*pr)->high;
04363              n = (*pr)->next;
04364              free (*pr);
04365              *pr = n;
04366            }
04367          return TRUE;
04368        }
04369     }
04370 
04371   r = (struct ieee_range *) xmalloc (sizeof *r);
04372   memset (r, 0, sizeof *r);
04373 
04374   r->low = low;
04375   r->high = high;
04376 
04377   /* Store the ranges sorted by address.  */
04378   for (pr = plist; *pr != NULL; pr = &(*pr)->next)
04379     if ((*pr)->low > high)
04380       break;
04381   r->next = *pr;
04382   *pr = r;
04383 
04384   return TRUE;
04385 }
04386 
04387 /* Start a new range for which we only have the low address.  */
04388 
04389 static bfd_boolean
04390 ieee_start_range (struct ieee_handle *info, bfd_vma low)
04391 {
04392   struct ieee_range *r;
04393 
04394   r = (struct ieee_range *) xmalloc (sizeof *r);
04395   memset (r, 0, sizeof *r);
04396   r->low = low;
04397   r->next = info->pending_ranges;
04398   info->pending_ranges = r;
04399   return TRUE;
04400 }
04401 
04402 /* Finish a range started by ieee_start_range.  */
04403 
04404 static bfd_boolean
04405 ieee_end_range (struct ieee_handle *info, bfd_vma high)
04406 {
04407   struct ieee_range *r;
04408   bfd_vma low;
04409 
04410   assert (info->pending_ranges != NULL);
04411   r = info->pending_ranges;
04412   low = r->low;
04413   info->pending_ranges = r->next;
04414   free (r);
04415   return ieee_add_range (info, FALSE, low, high);
04416 }
04417 
04418 /* Start defining a type.  */
04419 
04420 static bfd_boolean
04421 ieee_define_type (struct ieee_handle *info, unsigned int size,
04422                 bfd_boolean unsignedp, bfd_boolean localp)
04423 {
04424   return ieee_define_named_type (info, (const char *) NULL,
04425                              (unsigned int) -1, size, unsignedp,
04426                              localp, (struct ieee_buflist *) NULL);
04427 }
04428 
04429 /* Start defining a named type.  */
04430 
04431 static bfd_boolean
04432 ieee_define_named_type (struct ieee_handle *info, const char *name,
04433                      unsigned int indx, unsigned int size,
04434                      bfd_boolean unsignedp, bfd_boolean localp,
04435                      struct ieee_buflist *buflist)
04436 {
04437   unsigned int type_indx;
04438   unsigned int name_indx;
04439 
04440   if (indx != (unsigned int) -1)
04441     type_indx = indx;
04442   else
04443     {
04444       type_indx = info->type_indx;
04445       ++info->type_indx;
04446     }
04447 
04448   name_indx = info->name_indx;
04449   ++info->name_indx;
04450 
04451   if (name == NULL)
04452     name = "";
04453 
04454   /* If we were given a buffer, use it; otherwise, use either the
04455      local or the global type information, and make sure that the type
04456      block is started.  */
04457   if (buflist != NULL)
04458     {
04459       if (! ieee_change_buffer (info, buflist))
04460        return FALSE;
04461     }
04462   else if (localp)
04463     {
04464       if (! ieee_buffer_emptyp (&info->types))
04465        {
04466          if (! ieee_change_buffer (info, &info->types))
04467            return FALSE;
04468        }
04469       else
04470        {
04471          if (! ieee_change_buffer (info, &info->types)
04472              || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
04473              || ! ieee_write_byte (info, 1)
04474              || ! ieee_write_number (info, 0)
04475              || ! ieee_write_id (info, info->modname))
04476            return FALSE;
04477        }
04478     }
04479   else
04480     {
04481       if (! ieee_buffer_emptyp (&info->global_types))
04482        {
04483          if (! ieee_change_buffer (info, &info->global_types))
04484            return FALSE;
04485        }
04486       else
04487        {
04488          if (! ieee_change_buffer (info, &info->global_types)
04489              || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
04490              || ! ieee_write_byte (info, 2)
04491              || ! ieee_write_number (info, 0)
04492              || ! ieee_write_id (info, ""))
04493            return FALSE;
04494        }
04495     }
04496 
04497   /* Push the new type on the type stack, write out an NN record, and
04498      write out the start of a TY record.  The caller will then finish
04499      the TY record.  */
04500   if (! ieee_push_type (info, type_indx, size, unsignedp, localp))
04501     return FALSE;
04502 
04503   return (ieee_write_byte (info, (int) ieee_nn_record)
04504          && ieee_write_number (info, name_indx)
04505          && ieee_write_id (info, name)
04506          && ieee_write_byte (info, (int) ieee_ty_record_enum)
04507          && ieee_write_number (info, type_indx)
04508          && ieee_write_byte (info, 0xce)
04509          && ieee_write_number (info, name_indx));
04510 }
04511 
04512 /* Get an entry to the list of modified versions of a type.  */
04513 
04514 static struct ieee_modified_type *
04515 ieee_get_modified_info (struct ieee_handle *info, unsigned int indx)
04516 {
04517   if (indx >= info->modified_alloc)
04518     {
04519       unsigned int nalloc;
04520 
04521       nalloc = info->modified_alloc;
04522       if (nalloc == 0)
04523        nalloc = 16;
04524       while (indx >= nalloc)
04525        nalloc *= 2;
04526       info->modified = ((struct ieee_modified_type *)
04527                      xrealloc (info->modified,
04528                               nalloc * sizeof *info->modified));
04529       memset (info->modified + info->modified_alloc, 0,
04530              (nalloc - info->modified_alloc) * sizeof *info->modified);
04531       info->modified_alloc = nalloc;
04532     }
04533 
04534   return info->modified + indx;
04535 }
04536 
04537 /* Routines for the hash table mapping names to types.  */
04538 
04539 /* Initialize an entry in the hash table.  */
04540 
04541 static struct bfd_hash_entry *
04542 ieee_name_type_newfunc (struct bfd_hash_entry *entry,
04543                      struct bfd_hash_table *table, const char *string)
04544 {
04545   struct ieee_name_type_hash_entry *ret =
04546     (struct ieee_name_type_hash_entry *) entry;
04547 
04548   /* Allocate the structure if it has not already been allocated by a
04549      subclass.  */
04550   if (ret == NULL)
04551     ret = ((struct ieee_name_type_hash_entry *)
04552           bfd_hash_allocate (table, sizeof *ret));
04553   if (ret == NULL)
04554     return NULL;
04555 
04556   /* Call the allocation method of the superclass.  */
04557   ret = ((struct ieee_name_type_hash_entry *)
04558         bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
04559   if (ret)
04560     {
04561       /* Set local fields.  */
04562       ret->types = NULL;
04563     }
04564 
04565   return (struct bfd_hash_entry *) ret;
04566 }
04567 
04568 /* Look up an entry in the hash table.  */
04569 
04570 #define ieee_name_type_hash_lookup(table, string, create, copy) \
04571   ((struct ieee_name_type_hash_entry *) \
04572    bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
04573 
04574 /* Traverse the hash table.  */
04575 
04576 #define ieee_name_type_hash_traverse(table, func, info)               \
04577   (bfd_hash_traverse                                           \
04578    (&(table)->root,                                            \
04579     (bfd_boolean (*) (struct bfd_hash_entry *, void *)) (func),              \
04580     (info)))
04581 
04582 /* The general routine to write out IEEE debugging information.  */
04583 
04584 bfd_boolean
04585 write_ieee_debugging_info (bfd *abfd, void *dhandle)
04586 {
04587   struct ieee_handle info;
04588   asection *s;
04589   const char *err;
04590   struct ieee_buf *b;
04591 
04592   memset (&info, 0, sizeof info);
04593   info.abfd = abfd;
04594   info.type_indx = 256;
04595   info.name_indx = 32;
04596 
04597   if (!bfd_hash_table_init (&info.typedefs.root, ieee_name_type_newfunc,
04598                          sizeof (struct ieee_name_type_hash_entry))
04599       || !bfd_hash_table_init (&info.tags.root, ieee_name_type_newfunc,
04600                             sizeof (struct ieee_name_type_hash_entry)))
04601     return FALSE;
04602 
04603   if (! ieee_init_buffer (&info, &info.global_types)
04604       || ! ieee_init_buffer (&info, &info.data)
04605       || ! ieee_init_buffer (&info, &info.types)
04606       || ! ieee_init_buffer (&info, &info.vars)
04607       || ! ieee_init_buffer (&info, &info.cxx)
04608       || ! ieee_init_buffer (&info, &info.linenos)
04609       || ! ieee_init_buffer (&info, &info.fntype)
04610       || ! ieee_init_buffer (&info, &info.fnargs))
04611     return FALSE;
04612 
04613   if (! debug_write (dhandle, &ieee_fns, (void *) &info))
04614     return FALSE;
04615 
04616   if (info.filename != NULL)
04617     {
04618       if (! ieee_finish_compilation_unit (&info))
04619        return FALSE;
04620     }
04621 
04622   /* Put any undefined tags in the global typedef information.  */
04623   info.error = FALSE;
04624   ieee_name_type_hash_traverse (&info.tags,
04625                             ieee_write_undefined_tag,
04626                             (void *) &info);
04627   if (info.error)
04628     return FALSE;
04629 
04630   /* Prepend the global typedef information to the other data.  */
04631   if (! ieee_buffer_emptyp (&info.global_types))
04632     {
04633       /* The HP debugger seems to have a bug in which it ignores the
04634          last entry in the global types, so we add a dummy entry.  */
04635       if (! ieee_change_buffer (&info, &info.global_types)
04636          || ! ieee_write_byte (&info, (int) ieee_nn_record)
04637          || ! ieee_write_number (&info, info.name_indx)
04638          || ! ieee_write_id (&info, "")
04639          || ! ieee_write_byte (&info, (int) ieee_ty_record_enum)
04640          || ! ieee_write_number (&info, info.type_indx)
04641          || ! ieee_write_byte (&info, 0xce)
04642          || ! ieee_write_number (&info, info.name_indx)
04643          || ! ieee_write_number (&info, 'P')
04644          || ! ieee_write_number (&info, (int) builtin_void + 32)
04645          || ! ieee_write_byte (&info, (int) ieee_be_record_enum))
04646        return FALSE;
04647 
04648       if (! ieee_append_buffer (&info, &info.global_types, &info.data))
04649        return FALSE;
04650       info.data = info.global_types;
04651     }
04652 
04653   /* Make sure that we have declare BB11 blocks for each range in the
04654      file.  They are added to info->vars.  */
04655   info.error = FALSE;
04656   if (! ieee_init_buffer (&info, &info.vars))
04657     return FALSE;
04658   bfd_map_over_sections (abfd, ieee_add_bb11_blocks, (void *) &info);
04659   if (info.error)
04660     return FALSE;
04661   if (! ieee_buffer_emptyp (&info.vars))
04662     {
04663       if (! ieee_change_buffer (&info, &info.vars)
04664          || ! ieee_write_byte (&info, (int) ieee_be_record_enum))
04665        return FALSE;
04666 
04667       if (! ieee_append_buffer (&info, &info.data, &info.vars))
04668        return FALSE;
04669     }
04670 
04671   /* Now all the data is in info.data.  Write it out to the BFD.  We
04672      normally would need to worry about whether all the other sections
04673      are set up yet, but the IEEE backend will handle this particular
04674      case correctly regardless.  */
04675   if (ieee_buffer_emptyp (&info.data))
04676     {
04677       /* There is no debugging information.  */
04678       return TRUE;
04679     }
04680   err = NULL;
04681   s = bfd_make_section (abfd, ".debug");
04682   if (s == NULL)
04683     err = "bfd_make_section";
04684   if (err == NULL)
04685     {
04686       if (! bfd_set_section_flags (abfd, s, SEC_DEBUGGING | SEC_HAS_CONTENTS))
04687        err = "bfd_set_section_flags";
04688     }
04689   if (err == NULL)
04690     {
04691       bfd_size_type size;
04692 
04693       size = 0;
04694       for (b = info.data.head; b != NULL; b = b->next)
04695        size += b->c;
04696       if (! bfd_set_section_size (abfd, s, size))
04697        err = "bfd_set_section_size";
04698     }
04699   if (err == NULL)
04700     {
04701       file_ptr offset;
04702 
04703       offset = 0;
04704       for (b = info.data.head; b != NULL; b = b->next)
04705        {
04706          if (! bfd_set_section_contents (abfd, s, b->buf, offset, b->c))
04707            {
04708              err = "bfd_set_section_contents";
04709              break;
04710            }
04711          offset += b->c;
04712        }
04713     }
04714 
04715   if (err != NULL)
04716     {
04717       fprintf (stderr, "%s: %s: %s\n", bfd_get_filename (abfd), err,
04718               bfd_errmsg (bfd_get_error ()));
04719       return FALSE;
04720     }
04721 
04722   bfd_hash_table_free (&info.typedefs.root);
04723   bfd_hash_table_free (&info.tags.root);
04724 
04725   return TRUE;
04726 }
04727 
04728 /* Write out information for an undefined tag.  This is called via
04729    ieee_name_type_hash_traverse.  */
04730 
04731 static bfd_boolean
04732 ieee_write_undefined_tag (struct ieee_name_type_hash_entry *h, void *p)
04733 {
04734   struct ieee_handle *info = (struct ieee_handle *) p;
04735   struct ieee_name_type *nt;
04736 
04737   for (nt = h->types; nt != NULL; nt = nt->next)
04738     {
04739       unsigned int name_indx;
04740       char code;
04741 
04742       if (nt->kind == DEBUG_KIND_ILLEGAL)
04743        continue;
04744 
04745       if (ieee_buffer_emptyp (&info->global_types))
04746        {
04747          if (! ieee_change_buffer (info, &info->global_types)
04748              || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
04749              || ! ieee_write_byte (info, 2)
04750              || ! ieee_write_number (info, 0)
04751              || ! ieee_write_id (info, ""))
04752            {
04753              info->error = TRUE;
04754              return FALSE;
04755            }
04756        }
04757       else
04758        {
04759          if (! ieee_change_buffer (info, &info->global_types))
04760            {
04761              info->error = TRUE;
04762              return FALSE;
04763            }
04764        }
04765 
04766       name_indx = info->name_indx;
04767       ++info->name_indx;
04768       if (! ieee_write_byte (info, (int) ieee_nn_record)
04769          || ! ieee_write_number (info, name_indx)
04770          || ! ieee_write_id (info, nt->type.name)
04771          || ! ieee_write_byte (info, (int) ieee_ty_record_enum)
04772          || ! ieee_write_number (info, nt->type.indx)
04773          || ! ieee_write_byte (info, 0xce)
04774          || ! ieee_write_number (info, name_indx))
04775        {
04776          info->error = TRUE;
04777          return FALSE;
04778        }
04779 
04780       switch (nt->kind)
04781        {
04782        default:
04783          abort ();
04784          info->error = TRUE;
04785          return FALSE;
04786        case DEBUG_KIND_STRUCT:
04787        case DEBUG_KIND_CLASS:
04788          code = 'S';
04789          break;
04790        case DEBUG_KIND_UNION:
04791        case DEBUG_KIND_UNION_CLASS:
04792          code = 'U';
04793          break;
04794        case DEBUG_KIND_ENUM:
04795          code = 'E';
04796          break;
04797        }
04798       if (! ieee_write_number (info, code)
04799          || ! ieee_write_number (info, 0))
04800        {
04801          info->error = TRUE;
04802          return FALSE;
04803        }
04804     }
04805 
04806   return TRUE;
04807 }
04808 
04809 /* Start writing out information for a compilation unit.  */
04810 
04811 static bfd_boolean
04812 ieee_start_compilation_unit (void *p, const char *filename)
04813 {
04814   struct ieee_handle *info = (struct ieee_handle *) p;
04815   const char *modname;
04816 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
04817   const char *backslash;
04818 #endif
04819   char *c, *s;
04820   unsigned int nindx;
04821 
04822   if (info->filename != NULL)
04823     {
04824       if (! ieee_finish_compilation_unit (info))
04825        return FALSE;
04826     }
04827 
04828   info->filename = filename;
04829   modname = strrchr (filename, '/');
04830 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
04831   /* We could have a mixed forward/back slash case.  */
04832   backslash = strrchr (filename, '\\');
04833   if (modname == NULL || (backslash != NULL && backslash > modname))
04834     modname = backslash;
04835 #endif
04836 
04837   if (modname != NULL)
04838     ++modname;
04839 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
04840   else if (filename[0] && filename[1] == ':')
04841     modname = filename + 2;
04842 #endif
04843   else
04844     modname = filename;
04845 
04846   c = xstrdup (modname);
04847   s = strrchr (c, '.');
04848   if (s != NULL)
04849     *s = '\0';
04850   info->modname = c;
04851 
04852   if (! ieee_init_buffer (info, &info->types)
04853       || ! ieee_init_buffer (info, &info->vars)
04854       || ! ieee_init_buffer (info, &info->cxx)
04855       || ! ieee_init_buffer (info, &info->linenos))
04856     return FALSE;
04857   info->ranges = NULL;
04858 
04859   /* Always include a BB1 and a BB3 block.  That is what the output of
04860      the MRI linker seems to look like.  */
04861   if (! ieee_change_buffer (info, &info->types)
04862       || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
04863       || ! ieee_write_byte (info, 1)
04864       || ! ieee_write_number (info, 0)
04865       || ! ieee_write_id (info, info->modname))
04866     return FALSE;
04867 
04868   nindx = info->name_indx;
04869   ++info->name_indx;
04870   if (! ieee_change_buffer (info, &info->vars)
04871       || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
04872       || ! ieee_write_byte (info, 3)
04873       || ! ieee_write_number (info, 0)
04874       || ! ieee_write_id (info, info->modname))
04875     return FALSE;
04876 
04877   return TRUE;
04878 }
04879 
04880 /* Finish up a compilation unit.  */
04881 
04882 static bfd_boolean
04883 ieee_finish_compilation_unit (struct ieee_handle *info)
04884 {
04885   struct ieee_range *r;
04886 
04887   if (! ieee_buffer_emptyp (&info->types))
04888     {
04889       if (! ieee_change_buffer (info, &info->types)
04890          || ! ieee_write_byte (info, (int) ieee_be_record_enum))
04891        return FALSE;
04892     }
04893 
04894   if (! ieee_buffer_emptyp (&info->cxx))
04895     {
04896       /* Append any C++ information to the global function and
04897          variable information.  */
04898       assert (! ieee_buffer_emptyp (&info->vars));
04899       if (! ieee_change_buffer (info, &info->vars))
04900        return FALSE;
04901 
04902       /* We put the pmisc records in a dummy procedure, just as the
04903          MRI compiler does.  */
04904       if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
04905          || ! ieee_write_byte (info, 6)
04906          || ! ieee_write_number (info, 0)
04907          || ! ieee_write_id (info, "__XRYCPP")
04908          || ! ieee_write_number (info, 0)
04909          || ! ieee_write_number (info, 0)
04910          || ! ieee_write_number (info, info->highaddr - 1)
04911          || ! ieee_append_buffer (info, &info->vars, &info->cxx)
04912          || ! ieee_change_buffer (info, &info->vars)
04913          || ! ieee_write_byte (info, (int) ieee_be_record_enum)
04914          || ! ieee_write_number (info, info->highaddr - 1))
04915        return FALSE;
04916     }
04917 
04918   if (! ieee_buffer_emptyp (&info->vars))
04919     {
04920       if (! ieee_change_buffer (info, &info->vars)
04921          || ! ieee_write_byte (info, (int) ieee_be_record_enum))
04922        return FALSE;
04923     }
04924 
04925   if (info->pending_lineno_filename != NULL)
04926     {
04927       /* Force out the pending line number.  */
04928       if (! ieee_lineno ((void *) info, (const char *) NULL, 0, (bfd_vma) -1))
04929        return FALSE;
04930     }
04931   if (! ieee_buffer_emptyp (&info->linenos))
04932     {
04933       if (! ieee_change_buffer (info, &info->linenos)
04934          || ! ieee_write_byte (info, (int) ieee_be_record_enum))
04935        return FALSE;
04936       if (strcmp (info->filename, info->lineno_filename) != 0)
04937        {
04938          /* We were not in the main file.  We just closed the
04939              included line number block, and now we must close the
04940              main line number block.  */
04941          if (! ieee_write_byte (info, (int) ieee_be_record_enum))
04942            return FALSE;
04943        }
04944     }
04945 
04946   if (! ieee_append_buffer (info, &info->data, &info->types)
04947       || ! ieee_append_buffer (info, &info->data, &info->vars)
04948       || ! ieee_append_buffer (info, &info->data, &info->linenos))
04949     return FALSE;
04950 
04951   /* Build BB10/BB11 blocks based on the ranges we recorded.  */
04952   if (! ieee_change_buffer (info, &info->data))
04953     return FALSE;
04954 
04955   if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
04956       || ! ieee_write_byte (info, 10)
04957       || ! ieee_write_number (info, 0)
04958       || ! ieee_write_id (info, info->modname)
04959       || ! ieee_write_id (info, "")
04960       || ! ieee_write_number (info, 0)
04961       || ! ieee_write_id (info, "GNU objcopy"))
04962     return FALSE;
04963 
04964   for (r = info->ranges; r != NULL; r = r->next)
04965     {
04966       bfd_vma low, high;
04967       asection *s;
04968       int kind;
04969 
04970       low = r->low;
04971       high = r->high;
04972 
04973       /* Find the section corresponding to this range.  */
04974       for (s = info->abfd->sections; s != NULL; s = s->next)
04975        {
04976          if (bfd_get_section_vma (info->abfd, s) <= low
04977              && high <= (bfd_get_section_vma (info->abfd, s)
04978                        + bfd_section_size (info->abfd, s)))
04979            break;
04980        }
04981 
04982       if (s == NULL)
04983        {
04984          /* Just ignore this range.  */
04985          continue;
04986        }
04987 
04988       /* Coalesce ranges if it seems reasonable.  */
04989       while (r->next != NULL
04990             && high + 0x1000 >= r->next->low
04991             && (r->next->high
04992                <= (bfd_get_section_vma (info->abfd, s)
04993                    + bfd_section_size (info->abfd, s))))
04994        {
04995          r = r->next;
04996          high = r->high;
04997        }
04998 
04999       if ((s->flags & SEC_CODE) != 0)
05000        kind = 1;
05001       else if ((s->flags & SEC_READONLY) != 0)
05002        kind = 3;
05003       else
05004        kind = 2;
05005 
05006       if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
05007          || ! ieee_write_byte (info, 11)
05008          || ! ieee_write_number (info, 0)
05009          || ! ieee_write_id (info, "")
05010          || ! ieee_write_number (info, kind)
05011          || ! ieee_write_number (info, s->index + IEEE_SECTION_NUMBER_BASE)
05012          || ! ieee_write_number (info, low)
05013          || ! ieee_write_byte (info, (int) ieee_be_record_enum)
05014          || ! ieee_write_number (info, high - low))
05015        return FALSE;
05016 
05017       /* Add this range to the list of global ranges.  */
05018       if (! ieee_add_range (info, TRUE, low, high))
05019        return FALSE;
05020     }
05021 
05022   if (! ieee_write_byte (info, (int) ieee_be_record_enum))
05023     return FALSE;
05024 
05025   return TRUE;
05026 }
05027 
05028 /* Add BB11 blocks describing each range that we have not already
05029    described.  */
05030 
05031 static void
05032 ieee_add_bb11_blocks (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *data)
05033 {
05034   struct ieee_handle *info = (struct ieee_handle *) data;
05035   bfd_vma low, high;
05036   struct ieee_range *r;
05037 
05038   low = bfd_get_section_vma (abfd, sec);
05039   high = low + bfd_section_size (abfd, sec);
05040 
05041   /* Find the first range at or after this section.  The ranges are
05042      sorted by address.  */
05043   for (r = info->global_ranges; r != NULL; r = r->next)
05044     if (r->high > low)
05045       break;
05046 
05047   while (low < high)
05048     {
05049       if (r == NULL || r->low >= high)
05050        {
05051          if (! ieee_add_bb11 (info, sec, low, high))
05052            info->error = TRUE;
05053          return;
05054        }
05055 
05056       if (low < r->low
05057          && r->low - low > 0x100)
05058        {
05059          if (! ieee_add_bb11 (info, sec, low, r->low))
05060            {
05061              info->error = TRUE;
05062              return;
05063            }
05064        }
05065       low = r->high;
05066 
05067       r = r->next;
05068     }
05069 }
05070 
05071 /* Add a single BB11 block for a range.  We add it to info->vars.  */
05072 
05073 static bfd_boolean
05074 ieee_add_bb11 (struct ieee_handle *info, asection *sec, bfd_vma low,
05075               bfd_vma high)
05076 {
05077   int kind;
05078 
05079   if (! ieee_buffer_emptyp (&info->vars))
05080     {
05081       if (! ieee_change_buffer (info, &info->vars))
05082        return FALSE;
05083     }
05084   else
05085     {
05086       const char *filename, *modname;
05087 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
05088       const char *backslash;
05089 #endif
05090       char *c, *s;
05091 
05092       /* Start the enclosing BB10 block.  */
05093       filename = bfd_get_filename (info->abfd);
05094       modname = strrchr (filename, '/');
05095 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
05096       backslash = strrchr (filename, '\\');
05097       if (modname == NULL || (backslash != NULL && backslash > modname))
05098        modname = backslash;
05099 #endif
05100 
05101       if (modname != NULL)
05102        ++modname;
05103 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
05104       else if (filename[0] && filename[1] == ':')
05105        modname = filename + 2;
05106 #endif
05107       else
05108        modname = filename;
05109 
05110       c = xstrdup (modname);
05111       s = strrchr (c, '.');
05112       if (s != NULL)
05113        *s = '\0';
05114 
05115       if (! ieee_change_buffer (info, &info->vars)
05116          || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
05117          || ! ieee_write_byte (info, 10)
05118          || ! ieee_write_number (info, 0)
05119          || ! ieee_write_id (info, c)
05120          || ! ieee_write_id (info, "")
05121          || ! ieee_write_number (info, 0)
05122          || ! ieee_write_id (info, "GNU objcopy"))
05123        return FALSE;
05124 
05125       free (c);
05126     }
05127 
05128   if ((sec->flags & SEC_CODE) != 0)
05129     kind = 1;
05130   else if ((sec->flags & SEC_READONLY) != 0)
05131     kind = 3;
05132   else
05133     kind = 2;
05134 
05135   if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
05136       || ! ieee_write_byte (info, 11)
05137       || ! ieee_write_number (info, 0)
05138       || ! ieee_write_id (info, "")
05139       || ! ieee_write_number (info, kind)
05140       || ! ieee_write_number (info, sec->index + IEEE_SECTION_NUMBER_BASE)
05141       || ! ieee_write_number (info, low)
05142       || ! ieee_write_byte (info, (int) ieee_be_record_enum)
05143       || ! ieee_write_number (info, high - low))
05144     return FALSE;
05145 
05146   return TRUE;
05147 }
05148 
05149 /* Start recording information from a particular source file.  This is
05150    used to record which file defined which types, variables, etc.  It
05151    is not used for line numbers, since the lineno entry point passes
05152    down the file name anyhow.  IEEE debugging information doesn't seem
05153    to store this information anywhere.  */
05154 
05155 static bfd_boolean
05156 ieee_start_source (void *p ATTRIBUTE_UNUSED,
05157                  const char *filename ATTRIBUTE_UNUSED)
05158 {
05159   return TRUE;
05160 }
05161 
05162 /* Make an empty type.  */
05163 
05164 static bfd_boolean
05165 ieee_empty_type (void *p)
05166 {
05167   struct ieee_handle *info = (struct ieee_handle *) p;
05168 
05169   return ieee_push_type (info, (int) builtin_unknown, 0, FALSE, FALSE);
05170 }
05171 
05172 /* Make a void type.  */
05173 
05174 static bfd_boolean
05175 ieee_void_type (void *p)
05176 {
05177   struct ieee_handle *info = (struct ieee_handle *) p;
05178 
05179   return ieee_push_type (info, (int) builtin_void, 0, FALSE, FALSE);
05180 }
05181 
05182 /* Make an integer type.  */
05183 
05184 static bfd_boolean
05185 ieee_int_type (void *p, unsigned int size, bfd_boolean unsignedp)
05186 {
05187   struct ieee_handle *info = (struct ieee_handle *) p;
05188   unsigned int indx;
05189 
05190   switch (size)
05191     {
05192     case 1:
05193       indx = (int) builtin_signed_char;
05194       break;
05195     case 2:
05196       indx = (int) builtin_signed_short_int;
05197       break;
05198     case 4:
05199       indx = (int) builtin_signed_long;
05200       break;
05201     case 8:
05202       indx = (int) builtin_signed_long_long;
05203       break;
05204     default:
05205       fprintf (stderr, _("IEEE unsupported integer type size %u\n"), size);
05206       return FALSE;
05207     }
05208 
05209   if (unsignedp)
05210     ++indx;
05211 
05212   return ieee_push_type (info, indx, size, unsignedp, FALSE);
05213 }
05214 
05215 /* Make a floating point type.  */
05216 
05217 static bfd_boolean
05218 ieee_float_type (void *p, unsigned int size)
05219 {
05220   struct ieee_handle *info = (struct ieee_handle *) p;
05221   unsigned int indx;
05222 
05223   switch (size)
05224     {
05225     case 4:
05226       indx = (int) builtin_float;
05227       break;
05228     case 8:
05229       indx = (int) builtin_double;
05230       break;
05231     case 12:
05232       /* FIXME: This size really depends upon the processor.  */
05233       indx = (int) builtin_long_double;
05234       break;
05235     case 16:
05236       indx = (int) builtin_long_long_double;
05237       break;
05238     default:
05239       fprintf (stderr, _("IEEE unsupported float type size %u\n"), size);
05240       return FALSE;
05241     }
05242 
05243   return ieee_push_type (info, indx, size, FALSE, FALSE);
05244 }
05245 
05246 /* Make a complex type.  */
05247 
05248 static bfd_boolean
05249 ieee_complex_type (void *p, unsigned int size)
05250 {
05251   struct ieee_handle *info = (struct ieee_handle *) p;
05252   char code;
05253 
05254   switch (size)
05255     {
05256     case 4:
05257       if (info->complex_float_index != 0)
05258        return ieee_push_type (info, info->complex_float_index, size * 2,
05259                             FALSE, FALSE);
05260       code = 'c';
05261       break;
05262     case 12:
05263     case 16:
05264       /* These cases can be output by gcc -gstabs.  Outputting the
05265          wrong type is better than crashing.  */
05266     case 8:
05267       if (info->complex_double_index != 0)
05268        return ieee_push_type (info, info->complex_double_index, size * 2,
05269                             FALSE, FALSE);
05270       code = 'd';
05271       break;
05272     default:
05273       fprintf (stderr, _("IEEE unsupported complex type size %u\n"), size);
05274       return FALSE;
05275     }
05276 
05277   /* FIXME: I don't know what the string is for.  */
05278   if (! ieee_define_type (info, size * 2, FALSE, FALSE)
05279       || ! ieee_write_number (info, code)
05280       || ! ieee_write_id (info, ""))
05281     return FALSE;
05282 
05283   if (size == 4)
05284     info->complex_float_index = info->type_stack->type.indx;
05285   else
05286     info->complex_double_index = info->type_stack->type.indx;
05287 
05288   return TRUE;
05289 }
05290 
05291 /* Make a boolean type.  IEEE doesn't support these, so we just make
05292    an integer type instead.  */
05293 
05294 static bfd_boolean
05295 ieee_bool_type (void *p, unsigned int size)
05296 {
05297   return ieee_int_type (p, size, TRUE);
05298 }
05299 
05300 /* Make an enumeration.  */
05301 
05302 static bfd_boolean
05303 ieee_enum_type (void *p, const char *tag, const char **names,
05304               bfd_signed_vma *vals)
05305 {
05306   struct ieee_handle *info = (struct ieee_handle *) p;
05307   struct ieee_defined_enum *e;
05308   bfd_boolean localp, simple;
05309   unsigned int indx;
05310   int i = 0;
05311 
05312   localp = FALSE;
05313   indx = (unsigned int) -1;
05314   for (e = info->enums; e != NULL; e = e->next)
05315     {
05316       if (tag == NULL)
05317        {
05318          if (e->tag != NULL)
05319            continue;
05320        }
05321       else
05322        {
05323          if (e->tag == NULL
05324              || tag[0] != e->tag[0]
05325              || strcmp (tag, e->tag) != 0)
05326            continue;
05327        }
05328 
05329       if (! e->defined)
05330        {
05331          /* This enum tag has been seen but not defined.  */
05332          indx = e->indx;
05333          break;
05334        }
05335 
05336       if (names != NULL && e->names != NULL)
05337        {
05338          for (i = 0; names[i] != NULL && e->names[i] != NULL; i++)
05339            {
05340              if (names[i][0] != e->names[i][0]
05341                 || vals[i] != e->vals[i]
05342                 || strcmp (names[i], e->names[i]) != 0)
05343               break;
05344            }
05345        }
05346 
05347       if ((names == NULL && e->names == NULL)
05348          || (names != NULL
05349              && e->names != NULL
05350              && names[i] == NULL
05351              && e->names[i] == NULL))
05352        {
05353          /* We've seen this enum before.  */
05354          return ieee_push_type (info, e->indx, 0, TRUE, FALSE);
05355        }
05356 
05357       if (tag != NULL)
05358        {
05359          /* We've already seen an enum of the same name, so we must make
05360             sure to output this one locally.  */
05361          localp = TRUE;
05362          break;
05363        }
05364     }
05365 
05366   /* If this is a simple enumeration, in which the values start at 0
05367      and always increment by 1, we can use type E.  Otherwise we must
05368      use type N.  */
05369 
05370   simple = TRUE;
05371   if (names != NULL)
05372     {
05373       for (i = 0; names[i] != NULL; i++)
05374        {
05375          if (vals[i] != i)
05376            {
05377              simple = FALSE;
05378              break;
05379            }
05380        }
05381     }
05382 
05383   if (! ieee_define_named_type (info, tag, indx, 0, TRUE, localp,
05384                             (struct ieee_buflist *) NULL)
05385       || ! ieee_write_number (info, simple ? 'E' : 'N'))
05386     return FALSE;
05387   if (simple)
05388     {
05389       /* FIXME: This is supposed to be the enumeration size, but we
05390          don't store that.  */
05391       if (! ieee_write_number (info, 4))
05392        return FALSE;
05393     }
05394   if (names != NULL)
05395     {
05396       for (i = 0; names[i] != NULL; i++)
05397        {
05398          if (! ieee_write_id (info, names[i]))
05399            return FALSE;
05400          if (! simple)
05401            {
05402              if (! ieee_write_number (info, vals[i]))
05403               return FALSE;
05404            }
05405        }
05406     }
05407 
05408   if (! localp)
05409     {
05410       if (indx == (unsigned int) -1)
05411        {
05412          e = (struct ieee_defined_enum *) xmalloc (sizeof *e);
05413          memset (e, 0, sizeof *e);
05414          e->indx = info->type_stack->type.indx;
05415          e->tag = tag;
05416 
05417          e->next = info->enums;
05418          info->enums = e;
05419        }
05420 
05421       e->names = names;
05422       e->vals = vals;
05423       e->defined = TRUE;
05424     }
05425 
05426   return TRUE;
05427 }
05428 
05429 /* Make a pointer type.  */
05430 
05431 static bfd_boolean
05432 ieee_pointer_type (void *p)
05433 {
05434   struct ieee_handle *info = (struct ieee_handle *) p;
05435   bfd_boolean localp;
05436   unsigned int indx;
05437   struct ieee_modified_type *m = NULL;
05438 
05439   localp = info->type_stack->type.localp;
05440   indx = ieee_pop_type (info);
05441 
05442   /* A pointer to a simple builtin type can be obtained by adding 32.
05443      FIXME: Will this be a short pointer, and will that matter?  */
05444   if (indx < 32)
05445     return ieee_push_type (info, indx + 32, 0, TRUE, FALSE);
05446 
05447   if (! localp)
05448     {
05449       m = ieee_get_modified_info (p, indx);
05450       if (m == NULL)
05451        return FALSE;
05452 
05453       /* FIXME: The size should depend upon the architecture.  */
05454       if (m->pointer > 0)
05455        return ieee_push_type (info, m->pointer, 4, TRUE, FALSE);
05456     }
05457 
05458   if (! ieee_define_type (info, 4, TRUE, localp)
05459       || ! ieee_write_number (info, 'P')
05460       || ! ieee_write_number (info, indx))
05461     return FALSE;
05462 
05463   if (! localp)
05464     m->pointer = info->type_stack->type.indx;
05465 
05466   return TRUE;
05467 }
05468 
05469 /* Make a function type.  This will be called for a method, but we
05470    don't want to actually add it to the type table in that case.  We
05471    handle this by defining the type in a private buffer, and only
05472    adding that buffer to the typedef block if we are going to use it.  */
05473 
05474 static bfd_boolean
05475 ieee_function_type (void *p, int argcount, bfd_boolean varargs)
05476 {
05477   struct ieee_handle *info = (struct ieee_handle *) p;
05478   bfd_boolean localp;
05479   unsigned int *args = NULL;
05480   int i;
05481   unsigned int retindx;
05482   struct ieee_buflist fndef;
05483   struct ieee_modified_type *m;
05484 
05485   localp = FALSE;
05486 
05487   if (argcount > 0)
05488     {
05489       args = (unsigned int *) xmalloc (argcount * sizeof *args);
05490       for (i = argcount - 1; i >= 0; i--)
05491        {
05492          if (info->type_stack->type.localp)
05493            localp = TRUE;
05494          args[i] = ieee_pop_type (info);
05495        }
05496     }
05497   else if (argcount < 0)
05498     varargs = FALSE;
05499 
05500   if (info->type_stack->type.localp)
05501     localp = TRUE;
05502   retindx = ieee_pop_type (info);
05503 
05504   m = NULL;
05505   if (argcount < 0 && ! localp)
05506     {
05507       m = ieee_get_modified_info (p, retindx);
05508       if (m == NULL)
05509        return FALSE;
05510 
05511       if (m->function > 0)
05512        return ieee_push_type (info, m->function, 0, TRUE, FALSE);
05513     }
05514 
05515   /* An attribute of 0x41 means that the frame and push mask are
05516      unknown.  */
05517   if (! ieee_init_buffer (info, &fndef)
05518       || ! ieee_define_named_type (info, (const char *) NULL,
05519                                (unsigned int) -1, 0, TRUE, localp,
05520                                &fndef)
05521       || ! ieee_write_number (info, 'x')
05522       || ! ieee_write_number (info, 0x41)
05523       || ! ieee_write_number (info, 0)
05524       || ! ieee_write_number (info, 0)
05525       || ! ieee_write_number (info, retindx)
05526       || ! ieee_write_number (info, (bfd_vma) argcount + (varargs ? 1 : 0)))
05527     return FALSE;
05528   if (argcount > 0)
05529     {
05530       for (i = 0; i < argcount; i++)
05531        if (! ieee_write_number (info, args[i]))
05532          return FALSE;
05533       free (args);
05534     }
05535   if (varargs)
05536     {
05537       /* A varargs function is represented by writing out the last
05538          argument as type void *, although this makes little sense.  */
05539       if (! ieee_write_number (info, (bfd_vma) builtin_void + 32))
05540        return FALSE;
05541     }
05542 
05543   if (! ieee_write_number (info, 0))
05544     return FALSE;
05545 
05546   /* We wrote the information into fndef, in case we don't need it.
05547      It will be appended to info->types by ieee_pop_type.  */
05548   info->type_stack->type.fndef = fndef;
05549 
05550   if (m != NULL)
05551     m->function = info->type_stack->type.indx;
05552 
05553   return TRUE;
05554 }
05555 
05556 /* Make a reference type.  */
05557 
05558 static bfd_boolean
05559 ieee_reference_type (void *p)
05560 {
05561   struct ieee_handle *info = (struct ieee_handle *) p;
05562 
05563   /* IEEE appears to record a normal pointer type, and then use a
05564      pmisc record to indicate that it is really a reference.  */
05565 
05566   if (! ieee_pointer_type (p))
05567     return FALSE;
05568   info->type_stack->type.referencep = TRUE;
05569   return TRUE;
05570 }
05571 
05572 /* Make a range type.  */
05573 
05574 static bfd_boolean
05575 ieee_range_type (void *p, bfd_signed_vma low, bfd_signed_vma high)
05576 {
05577   struct ieee_handle *info = (struct ieee_handle *) p;
05578   unsigned int size;
05579   bfd_boolean unsignedp, localp;
05580 
05581   size = info->type_stack->type.size;
05582   unsignedp = info->type_stack->type.unsignedp;
05583   localp = info->type_stack->type.localp;
05584   ieee_pop_unused_type (info);
05585   return (ieee_define_type (info, size, unsignedp, localp)
05586          && ieee_write_number (info, 'R')
05587          && ieee_write_number (info, (bfd_vma) low)
05588          && ieee_write_number (info, (bfd_vma) high)
05589          && ieee_write_number (info, unsignedp ? 0 : 1)
05590          && ieee_write_number (info, size));
05591 }
05592 
05593 /* Make an array type.  */
05594 
05595 static bfd_boolean
05596 ieee_array_type (void *p, bfd_signed_vma low, bfd_signed_vma high,
05597                bfd_boolean stringp ATTRIBUTE_UNUSED)
05598 {
05599   struct ieee_handle *info = (struct ieee_handle *) p;
05600   unsigned int eleindx;
05601   bfd_boolean localp;
05602   unsigned int size;
05603   struct ieee_modified_type *m = NULL;
05604   struct ieee_modified_array_type *a;
05605 
05606   /* IEEE does not store the range, so we just ignore it.  */
05607   ieee_pop_unused_type (info);
05608   localp = info->type_stack->type.localp;
05609   size = info->type_stack->type.size;
05610   eleindx = ieee_pop_type (info);
05611 
05612   /* If we don't know the range, treat the size as exactly one
05613      element.  */
05614   if (low < high)
05615     size *= (high - low) + 1;
05616 
05617   if (! localp)
05618     {
05619       m = ieee_get_modified_info (info, eleindx);
05620       if (m == NULL)
05621        return FALSE;
05622 
05623       for (a = m->arrays; a != NULL; a = a->next)
05624        {
05625          if (a->low == low && a->high == high)
05626            return ieee_push_type (info, a->indx, size, FALSE, FALSE);
05627        }
05628     }
05629 
05630   if (! ieee_define_type (info, size, FALSE, localp)
05631       || ! ieee_write_number (info, low == 0 ? 'Z' : 'C')
05632       || ! ieee_write_number (info, eleindx))
05633     return FALSE;
05634   if (low != 0)
05635     {
05636       if (! ieee_write_number (info, low))
05637        return FALSE;
05638     }
05639 
05640   if (! ieee_write_number (info, high + 1))
05641     return FALSE;
05642 
05643   if (! localp)
05644     {
05645       a = (struct ieee_modified_array_type *) xmalloc (sizeof *a);
05646       memset (a, 0, sizeof *a);
05647 
05648       a->indx = info->type_stack->type.indx;
05649       a->low = low;
05650       a->high = high;
05651 
05652       a->next = m->arrays;
05653       m->arrays = a;
05654     }
05655 
05656   return TRUE;
05657 }
05658 
05659 /* Make a set type.  */
05660 
05661 static bfd_boolean
05662 ieee_set_type (void *p, bfd_boolean bitstringp ATTRIBUTE_UNUSED)
05663 {
05664   struct ieee_handle *info = (struct ieee_handle *) p;
05665   bfd_boolean localp;
05666   unsigned int eleindx;
05667 
05668   localp = info->type_stack->type.localp;
05669   eleindx = ieee_pop_type (info);
05670 
05671   /* FIXME: We don't know the size, so we just use 4.  */
05672 
05673   return (ieee_define_type (info, 0, TRUE, localp)
05674          && ieee_write_number (info, 's')
05675          && ieee_write_number (info, 4)
05676          && ieee_write_number (info, eleindx));
05677 }
05678 
05679 /* Make an offset type.  */
05680 
05681 static bfd_boolean
05682 ieee_offset_type (void *p)
05683 {
05684   struct ieee_handle *info = (struct ieee_handle *) p;
05685   unsigned int targetindx, baseindx;
05686 
05687   targetindx = ieee_pop_type (info);
05688   baseindx = ieee_pop_type (info);
05689 
05690   /* FIXME: The MRI C++ compiler does not appear to generate any
05691      useful type information about an offset type.  It just records a
05692      pointer to member as an integer.  The MRI/HP IEEE spec does
05693      describe a pmisc record which can be used for a pointer to
05694      member.  Unfortunately, it does not describe the target type,
05695      which seems pretty important.  I'm going to punt this for now.  */
05696 
05697   return ieee_int_type (p, 4, TRUE);
05698 }
05699 
05700 /* Make a method type.  */
05701 
05702 static bfd_boolean
05703 ieee_method_type (void *p, bfd_boolean domain, int argcount,
05704                 bfd_boolean varargs)
05705 {
05706   struct ieee_handle *info = (struct ieee_handle *) p;
05707 
05708   /* FIXME: The MRI/HP IEEE spec defines a pmisc record to use for a
05709      method, but the definition is incomplete.  We just output an 'x'
05710      type.  */
05711 
05712   if (domain)
05713     ieee_pop_unused_type (info);
05714 
05715   return ieee_function_type (p, argcount, varargs);
05716 }
05717 
05718 /* Make a const qualified type.  */
05719 
05720 static bfd_boolean
05721 ieee_const_type (void *p)
05722 {
05723   struct ieee_handle *info = (struct ieee_handle *) p;
05724   unsigned int size;
05725   bfd_boolean unsignedp, localp;
05726   unsigned int indx;
05727   struct ieee_modified_type *m = NULL;
05728 
05729   size = info->type_stack->type.size;
05730   unsignedp = info->type_stack->type.unsignedp;
05731   localp = info->type_stack->type.localp;
05732   indx = ieee_pop_type (info);
05733 
05734   if (! localp)
05735     {
05736       m = ieee_get_modified_info (info, indx);
05737       if (m == NULL)
05738        return FALSE;
05739 
05740       if (m->const_qualified > 0)
05741        return ieee_push_type (info, m->const_qualified, size, unsignedp,
05742                             FALSE);
05743     }
05744 
05745   if (! ieee_define_type (info, size, unsignedp, localp)
05746       || ! ieee_write_number (info, 'n')
05747       || ! ieee_write_number (info, 1)
05748       || ! ieee_write_number (info, indx))
05749     return FALSE;
05750 
05751   if (! localp)
05752     m->const_qualified = info->type_stack->type.indx;
05753 
05754   return TRUE;
05755 }
05756 
05757 /* Make a volatile qualified type.  */
05758 
05759 static bfd_boolean
05760 ieee_volatile_type (void *p)
05761 {
05762   struct ieee_handle *info = (struct ieee_handle *) p;
05763   unsigned int size;
05764   bfd_boolean unsignedp, localp;
05765   unsigned int indx;
05766   struct ieee_modified_type *m = NULL;
05767 
05768   size = info->type_stack->type.size;
05769   unsignedp = info->type_stack->type.unsignedp;
05770   localp = info->type_stack->type.localp;
05771   indx = ieee_pop_type (info);
05772 
05773   if (! localp)
05774     {
05775       m = ieee_get_modified_info (info, indx);
05776       if (m == NULL)
05777        return FALSE;
05778 
05779       if (m->volatile_qualified > 0)
05780        return ieee_push_type (info, m->volatile_qualified, size, unsignedp,
05781                             FALSE);
05782     }
05783 
05784   if (! ieee_define_type (info, size, unsignedp, localp)
05785       || ! ieee_write_number (info, 'n')
05786       || ! ieee_write_number (info, 2)
05787       || ! ieee_write_number (info, indx))
05788     return FALSE;
05789 
05790   if (! localp)
05791     m->volatile_qualified = info->type_stack->type.indx;
05792 
05793   return TRUE;
05794 }
05795 
05796 /* Convert an enum debug_visibility into a CXXFLAGS value.  */
05797 
05798 static unsigned int
05799 ieee_vis_to_flags (enum debug_visibility visibility)
05800 {
05801   switch (visibility)
05802     {
05803     default:
05804       abort ();
05805     case DEBUG_VISIBILITY_PUBLIC:
05806       return CXXFLAGS_VISIBILITY_PUBLIC;
05807     case DEBUG_VISIBILITY_PRIVATE:
05808       return CXXFLAGS_VISIBILITY_PRIVATE;
05809     case DEBUG_VISIBILITY_PROTECTED:
05810       return CXXFLAGS_VISIBILITY_PROTECTED;
05811     }
05812   /*NOTREACHED*/
05813 }
05814 
05815 /* Start defining a struct type.  We build it in the strdef field on
05816    the stack, to avoid confusing type definitions required by the
05817    fields with the struct type itself.  */
05818 
05819 static bfd_boolean
05820 ieee_start_struct_type (void *p, const char *tag, unsigned int id,
05821                      bfd_boolean structp, unsigned int size)
05822 {
05823   struct ieee_handle *info = (struct ieee_handle *) p;
05824   bfd_boolean localp, ignorep;
05825   bfd_boolean copy;
05826   char ab[20];
05827   const char *look;
05828   struct ieee_name_type_hash_entry *h;
05829   struct ieee_name_type *nt, *ntlook;
05830   struct ieee_buflist strdef;
05831 
05832   localp = FALSE;
05833   ignorep = FALSE;
05834 
05835   /* We need to create a tag for internal use even if we don't want
05836      one for external use.  This will let us refer to an anonymous
05837      struct.  */
05838   if (tag != NULL)
05839     {
05840       look = tag;
05841       copy = FALSE;
05842     }
05843   else
05844     {
05845       sprintf (ab, "__anon%u", id);
05846       look = ab;
05847       copy = TRUE;
05848     }
05849 
05850   /* If we already have references to the tag, we must use the
05851      existing type index.  */
05852   h = ieee_name_type_hash_lookup (&info->tags, look, TRUE, copy);
05853   if (h == NULL)
05854     return FALSE;
05855 
05856   nt = NULL;
05857   for (ntlook = h->types; ntlook != NULL; ntlook = ntlook->next)
05858     {
05859       if (ntlook->id == id)
05860        nt = ntlook;
05861       else if (! ntlook->type.localp)
05862        {
05863          /* We are creating a duplicate definition of a globally
05864             defined tag.  Force it to be local to avoid
05865             confusion.  */
05866          localp = TRUE;
05867        }
05868     }
05869 
05870   if (nt != NULL)
05871     {
05872       assert (localp == nt->type.localp);
05873       if (nt->kind == DEBUG_KIND_ILLEGAL && ! localp)
05874        {
05875          /* We've already seen a global definition of the type.
05876              Ignore this new definition.  */
05877          ignorep = TRUE;
05878        }
05879     }
05880   else
05881     {
05882       nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
05883       memset (nt, 0, sizeof *nt);
05884       nt->id = id;
05885       nt->type.name = h->root.string;
05886       nt->next = h->types;
05887       h->types = nt;
05888       nt->type.indx = info->type_indx;
05889       ++info->type_indx;
05890     }
05891 
05892   nt->kind = DEBUG_KIND_ILLEGAL;
05893 
05894   if (! ieee_init_buffer (info, &strdef)
05895       || ! ieee_define_named_type (info, tag, nt->type.indx, size, TRUE,
05896                                localp, &strdef)
05897       || ! ieee_write_number (info, structp ? 'S' : 'U')
05898       || ! ieee_write_number (info, size))
05899     return FALSE;
05900 
05901   if (! ignorep)
05902     {
05903       const char *hold;
05904 
05905       /* We never want nt->type.name to be NULL.  We want the rest of
05906         the type to be the object set up on the type stack; it will
05907         have a NULL name if tag is NULL.  */
05908       hold = nt->type.name;
05909       nt->type = info->type_stack->type;
05910       nt->type.name = hold;
05911     }
05912 
05913   info->type_stack->type.name = tag;
05914   info->type_stack->type.strdef = strdef;
05915   info->type_stack->type.ignorep = ignorep;
05916 
05917   return TRUE;
05918 }
05919 
05920 /* Add a field to a struct.  */
05921 
05922 static bfd_boolean
05923 ieee_struct_field (void *p, const char *name, bfd_vma bitpos, bfd_vma bitsize,
05924                  enum debug_visibility visibility)
05925 {
05926   struct ieee_handle *info = (struct ieee_handle *) p;
05927   unsigned int size;
05928   bfd_boolean unsignedp;
05929   bfd_boolean referencep;
05930   bfd_boolean localp;
05931   unsigned int indx;
05932   bfd_vma offset;
05933 
05934   assert (info->type_stack != NULL
05935          && info->type_stack->next != NULL
05936          && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef));
05937 
05938   /* If we are ignoring this struct definition, just pop and ignore
05939      the type.  */
05940   if (info->type_stack->next->type.ignorep)
05941     {
05942       ieee_pop_unused_type (info);
05943       return TRUE;
05944     }
05945 
05946   size = info->type_stack->type.size;
05947   unsignedp = info->type_stack->type.unsignedp;
05948   referencep = info->type_stack->type.referencep;
05949   localp = info->type_stack->type.localp;
05950   indx = ieee_pop_type (info);
05951 
05952   if (localp)
05953     info->type_stack->type.localp = TRUE;
05954 
05955   if (info->type_stack->type.classdef != NULL)
05956     {
05957       unsigned int flags;
05958       unsigned int nindx;
05959 
05960       /* This is a class.  We must add a description of this field to
05961          the class records we are building.  */
05962 
05963       flags = ieee_vis_to_flags (visibility);
05964       nindx = info->type_stack->type.classdef->indx;
05965       if (! ieee_change_buffer (info,
05966                             &info->type_stack->type.classdef->pmiscbuf)
05967          || ! ieee_write_asn (info, nindx, 'd')
05968          || ! ieee_write_asn (info, nindx, flags)
05969          || ! ieee_write_atn65 (info, nindx, name)
05970          || ! ieee_write_atn65 (info, nindx, name))
05971        return FALSE;
05972       info->type_stack->type.classdef->pmisccount += 4;
05973 
05974       if (referencep)
05975        {
05976          unsigned int nindx;
05977 
05978          /* We need to output a record recording that this field is
05979              really of reference type.  We put this on the refs field
05980              of classdef, so that it can be appended to the C++
05981              records after the class is defined.  */
05982 
05983          nindx = info->name_indx;
05984          ++info->name_indx;
05985 
05986          if (! ieee_change_buffer (info,
05987                                 &info->type_stack->type.classdef->refs)
05988              || ! ieee_write_byte (info, (int) ieee_nn_record)
05989              || ! ieee_write_number (info, nindx)
05990              || ! ieee_write_id (info, "")
05991              || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
05992              || ! ieee_write_number (info, nindx)
05993              || ! ieee_write_number (info, 0)
05994              || ! ieee_write_number (info, 62)
05995              || ! ieee_write_number (info, 80)
05996              || ! ieee_write_number (info, 4)
05997              || ! ieee_write_asn (info, nindx, 'R')
05998              || ! ieee_write_asn (info, nindx, 3)
05999              || ! ieee_write_atn65 (info, nindx, info->type_stack->type.name)
06000              || ! ieee_write_atn65 (info, nindx, name))
06001            return FALSE;
06002        }
06003     }
06004 
06005   /* If the bitsize doesn't match the expected size, we need to output
06006      a bitfield type.  */
06007   if (size == 0 || bitsize == 0 || bitsize == size * 8)
06008     offset = bitpos / 8;
06009   else
06010     {
06011       if (! ieee_define_type (info, 0, unsignedp,
06012                            info->type_stack->type.localp)
06013          || ! ieee_write_number (info, 'g')
06014          || ! ieee_write_number (info, unsignedp ? 0 : 1)
06015          || ! ieee_write_number (info, bitsize)
06016          || ! ieee_write_number (info, indx))
06017        return FALSE;
06018       indx = ieee_pop_type (info);
06019       offset = bitpos;
06020     }
06021 
06022   /* Switch to the struct we are building in order to output this
06023      field definition.  */
06024   return (ieee_change_buffer (info, &info->type_stack->type.strdef)
06025          && ieee_write_id (info, name)
06026          && ieee_write_number (info, indx)
06027          && ieee_write_number (info, offset));
06028 }
06029 
06030 /* Finish up a struct type.  */
06031 
06032 static bfd_boolean
06033 ieee_end_struct_type (void *p)
06034 {
06035   struct ieee_handle *info = (struct ieee_handle *) p;
06036   struct ieee_buflist *pb;
06037 
06038   assert (info->type_stack != NULL
06039          && ! ieee_buffer_emptyp (&info->type_stack->type.strdef));
06040 
06041   /* If we were ignoring this struct definition because it was a
06042      duplicate definition, just through away whatever bytes we have
06043      accumulated.  Leave the type on the stack.  */
06044   if (info->type_stack->type.ignorep)
06045     return TRUE;
06046 
06047   /* If this is not a duplicate definition of this tag, then localp
06048      will be FALSE, and we can put it in the global type block.
06049      FIXME: We should avoid outputting duplicate definitions which are
06050      the same.  */
06051   if (! info->type_stack->type.localp)
06052     {
06053       /* Make sure we have started the global type block.  */
06054       if (ieee_buffer_emptyp (&info->global_types))
06055        {
06056          if (! ieee_change_buffer (info, &info->global_types)
06057              || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
06058              || ! ieee_write_byte (info, 2)
06059              || ! ieee_write_number (info, 0)
06060              || ! ieee_write_id (info, ""))
06061            return FALSE;
06062        }
06063       pb = &info->global_types;
06064     }
06065   else
06066     {
06067       /* Make sure we have started the types block.  */
06068       if (ieee_buffer_emptyp (&info->types))
06069        {
06070          if (! ieee_change_buffer (info, &info->types)
06071              || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
06072              || ! ieee_write_byte (info, 1)
06073              || ! ieee_write_number (info, 0)
06074              || ! ieee_write_id (info, info->modname))
06075            return FALSE;
06076        }
06077       pb = &info->types;
06078     }
06079 
06080   /* Append the struct definition to the types.  */
06081   if (! ieee_append_buffer (info, pb, &info->type_stack->type.strdef)
06082       || ! ieee_init_buffer (info, &info->type_stack->type.strdef))
06083     return FALSE;
06084 
06085   /* Leave the struct on the type stack.  */
06086 
06087   return TRUE;
06088 }
06089 
06090 /* Start a class type.  */
06091 
06092 static bfd_boolean
06093 ieee_start_class_type (void *p, const char *tag, unsigned int id,
06094                      bfd_boolean structp, unsigned int size,
06095                      bfd_boolean vptr, bfd_boolean ownvptr)
06096 {
06097   struct ieee_handle *info = (struct ieee_handle *) p;
06098   const char *vclass;
06099   struct ieee_buflist pmiscbuf;
06100   unsigned int indx;
06101   struct ieee_type_class *classdef;
06102 
06103   /* A C++ class is output as a C++ struct along with a set of pmisc
06104      records describing the class.  */
06105 
06106   /* We need to have a name so that we can associate the struct and
06107      the class.  */
06108   if (tag == NULL)
06109     {
06110       char *t;
06111 
06112       t = (char *) xmalloc (20);
06113       sprintf (t, "__anon%u", id);
06114       tag = t;
06115     }
06116 
06117   /* We can't write out the virtual table information until we have
06118      finished the class, because we don't know the virtual table size.
06119      We get the size from the largest voffset we see.  */
06120   vclass = NULL;
06121   if (vptr && ! ownvptr)
06122     {
06123       vclass = info->type_stack->type.name;
06124       assert (vclass != NULL);
06125       /* We don't call ieee_pop_unused_type, since the class should
06126          get defined.  */
06127       (void) ieee_pop_type (info);
06128     }
06129 
06130   if (! ieee_start_struct_type (p, tag, id, structp, size))
06131     return FALSE;
06132 
06133   indx = info->name_indx;
06134   ++info->name_indx;
06135 
06136   /* We write out pmisc records into the classdef field.  We will
06137      write out the pmisc start after we know the number of records we
06138      need.  */
06139   if (! ieee_init_buffer (info, &pmiscbuf)
06140       || ! ieee_change_buffer (info, &pmiscbuf)
06141       || ! ieee_write_asn (info, indx, 'T')
06142       || ! ieee_write_asn (info, indx, structp ? 'o' : 'u')
06143       || ! ieee_write_atn65 (info, indx, tag))
06144     return FALSE;
06145 
06146   classdef = (struct ieee_type_class *) xmalloc (sizeof *classdef);
06147   memset (classdef, 0, sizeof *classdef);
06148 
06149   classdef->indx = indx;
06150   classdef->pmiscbuf = pmiscbuf;
06151   classdef->pmisccount = 3;
06152   classdef->vclass = vclass;
06153   classdef->ownvptr = ownvptr;
06154 
06155   info->type_stack->type.classdef = classdef;
06156 
06157   return TRUE;
06158 }
06159 
06160 /* Add a static member to a class.  */
06161 
06162 static bfd_boolean
06163 ieee_class_static_member (void *p, const char *name, const char *physname,
06164                        enum debug_visibility visibility)
06165 {
06166   struct ieee_handle *info = (struct ieee_handle *) p;
06167   unsigned int flags;
06168   unsigned int nindx;
06169 
06170   /* We don't care about the type.  Hopefully there will be a call to
06171      ieee_variable declaring the physical name and the type, since
06172      that is where an IEEE consumer must get the type.  */
06173   ieee_pop_unused_type (info);
06174 
06175   assert (info->type_stack != NULL
06176          && info->type_stack->type.classdef != NULL);
06177 
06178   flags = ieee_vis_to_flags (visibility);
06179   flags |= CXXFLAGS_STATIC;
06180 
06181   nindx = info->type_stack->type.classdef->indx;
06182 
06183   if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf)
06184       || ! ieee_write_asn (info, nindx, 'd')
06185       || ! ieee_write_asn (info, nindx, flags)
06186       || ! ieee_write_atn65 (info, nindx, name)
06187       || ! ieee_write_atn65 (info, nindx, physname))
06188     return FALSE;
06189   info->type_stack->type.classdef->pmisccount += 4;
06190 
06191   return TRUE;
06192 }
06193 
06194 /* Add a base class to a class.  */
06195 
06196 static bfd_boolean
06197 ieee_class_baseclass (void *p, bfd_vma bitpos, bfd_boolean virtual,
06198                     enum debug_visibility visibility)
06199 {
06200   struct ieee_handle *info = (struct ieee_handle *) p;
06201   const char *bname;
06202   bfd_boolean localp;
06203   unsigned int bindx;
06204   char *fname;
06205   unsigned int flags;
06206   unsigned int nindx;
06207 
06208   assert (info->type_stack != NULL
06209          && info->type_stack->type.name != NULL
06210          && info->type_stack->next != NULL
06211          && info->type_stack->next->type.classdef != NULL
06212          && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef));
06213 
06214   bname = info->type_stack->type.name;
06215   localp = info->type_stack->type.localp;
06216   bindx = ieee_pop_type (info);
06217 
06218   /* We are currently defining both a struct and a class.  We must
06219      write out a field definition in the struct which holds the base
06220      class.  The stabs debugging reader will create a field named
06221      _vb$CLASS for a virtual base class, so we just use that.  FIXME:
06222      we should not depend upon a detail of stabs debugging.  */
06223   if (virtual)
06224     {
06225       fname = (char *) xmalloc (strlen (bname) + sizeof "_vb$");
06226       sprintf (fname, "_vb$%s", bname);
06227       flags = BASEFLAGS_VIRTUAL;
06228     }
06229   else
06230     {
06231       if (localp)
06232        info->type_stack->type.localp = TRUE;
06233 
06234       fname = (char *) xmalloc (strlen (bname) + sizeof "_b$");
06235       sprintf (fname, "_b$%s", bname);
06236 
06237       if (! ieee_change_buffer (info, &info->type_stack->type.strdef)
06238          || ! ieee_write_id (info, fname)
06239          || ! ieee_write_number (info, bindx)
06240          || ! ieee_write_number (info, bitpos / 8))
06241        return FALSE;
06242       flags = 0;
06243     }
06244 
06245   if (visibility == DEBUG_VISIBILITY_PRIVATE)
06246     flags |= BASEFLAGS_PRIVATE;
06247 
06248   nindx = info->type_stack->type.classdef->indx;
06249 
06250   if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf)
06251       || ! ieee_write_asn (info, nindx, 'b')
06252       || ! ieee_write_asn (info, nindx, flags)
06253       || ! ieee_write_atn65 (info, nindx, bname)
06254       || ! ieee_write_asn (info, nindx, 0)
06255       || ! ieee_write_atn65 (info, nindx, fname))
06256     return FALSE;
06257   info->type_stack->type.classdef->pmisccount += 5;
06258 
06259   free (fname);
06260 
06261   return TRUE;
06262 }
06263 
06264 /* Start building a method for a class.  */
06265 
06266 static bfd_boolean
06267 ieee_class_start_method (void *p, const char *name)
06268 {
06269   struct ieee_handle *info = (struct ieee_handle *) p;
06270 
06271   assert (info->type_stack != NULL
06272          && info->type_stack->type.classdef != NULL
06273          && info->type_stack->type.classdef->method == NULL);
06274 
06275   info->type_stack->type.classdef->method = name;
06276 
06277   return TRUE;
06278 }
06279 
06280 /* Define a new method variant, either static or not.  */
06281 
06282 static bfd_boolean
06283 ieee_class_method_var (struct ieee_handle *info, const char *physname,
06284                      enum debug_visibility visibility,
06285                      bfd_boolean staticp, bfd_boolean constp,
06286                      bfd_boolean volatilep, bfd_vma voffset,
06287                      bfd_boolean context)
06288 {
06289   unsigned int flags;
06290   unsigned int nindx;
06291   bfd_boolean virtual;
06292 
06293   /* We don't need the type of the method.  An IEEE consumer which
06294      wants the type must track down the function by the physical name
06295      and get the type from that.  */
06296   ieee_pop_unused_type (info);
06297 
06298   /* We don't use the context.  FIXME: We probably ought to use it to
06299      adjust the voffset somehow, but I don't really know how.  */
06300   if (context)
06301     ieee_pop_unused_type (info);
06302 
06303   assert (info->type_stack != NULL
06304          && info->type_stack->type.classdef != NULL
06305          && info->type_stack->type.classdef->method != NULL);
06306 
06307   flags = ieee_vis_to_flags (visibility);
06308 
06309   /* FIXME: We never set CXXFLAGS_OVERRIDE, CXXFLAGS_OPERATOR,
06310      CXXFLAGS_CTORDTOR, CXXFLAGS_CTOR, or CXXFLAGS_INLINE.  */
06311 
06312   if (staticp)
06313     flags |= CXXFLAGS_STATIC;
06314   if (constp)
06315     flags |= CXXFLAGS_CONST;
06316   if (volatilep)
06317     flags |= CXXFLAGS_VOLATILE;
06318 
06319   nindx = info->type_stack->type.classdef->indx;
06320 
06321   virtual = context || voffset > 0;
06322 
06323   if (! ieee_change_buffer (info,
06324                          &info->type_stack->type.classdef->pmiscbuf)
06325       || ! ieee_write_asn (info, nindx, virtual ? 'v' : 'm')
06326       || ! ieee_write_asn (info, nindx, flags)
06327       || ! ieee_write_atn65 (info, nindx,
06328                           info->type_stack->type.classdef->method)
06329       || ! ieee_write_atn65 (info, nindx, physname))
06330     return FALSE;
06331 
06332   if (virtual)
06333     {
06334       if (voffset > info->type_stack->type.classdef->voffset)
06335        info->type_stack->type.classdef->voffset = voffset;
06336       if (! ieee_write_asn (info, nindx, voffset))
06337        return FALSE;
06338       ++info->type_stack->type.classdef->pmisccount;
06339     }
06340 
06341   if (! ieee_write_asn (info, nindx, 0))
06342     return FALSE;
06343 
06344   info->type_stack->type.classdef->pmisccount += 5;
06345 
06346   return TRUE;
06347 }
06348 
06349 /* Define a new method variant.  */
06350 
06351 static bfd_boolean
06352 ieee_class_method_variant (void *p, const char *physname,
06353                         enum debug_visibility visibility,
06354                         bfd_boolean constp, bfd_boolean volatilep,
06355                         bfd_vma voffset, bfd_boolean context)
06356 {
06357   struct ieee_handle *info = (struct ieee_handle *) p;
06358 
06359   return ieee_class_method_var (info, physname, visibility, FALSE, constp,
06360                             volatilep, voffset, context);
06361 }
06362 
06363 /* Define a new static method variant.  */
06364 
06365 static bfd_boolean
06366 ieee_class_static_method_variant (void *p, const char *physname,
06367                               enum debug_visibility visibility,
06368                               bfd_boolean constp, bfd_boolean volatilep)
06369 {
06370   struct ieee_handle *info = (struct ieee_handle *) p;
06371 
06372   return ieee_class_method_var (info, physname, visibility, TRUE, constp,
06373                             volatilep, 0, FALSE);
06374 }
06375 
06376 /* Finish up a method.  */
06377 
06378 static bfd_boolean
06379 ieee_class_end_method (void *p)
06380 {
06381   struct ieee_handle *info = (struct ieee_handle *) p;
06382 
06383   assert (info->type_stack != NULL
06384          && info->type_stack->type.classdef != NULL
06385          && info->type_stack->type.classdef->method != NULL);
06386 
06387   info->type_stack->type.classdef->method = NULL;
06388 
06389   return TRUE;
06390 }
06391 
06392 /* Finish up a class.  */
06393 
06394 static bfd_boolean
06395 ieee_end_class_type (void *p)
06396 {
06397   struct ieee_handle *info = (struct ieee_handle *) p;
06398   unsigned int nindx;
06399 
06400   assert (info->type_stack != NULL
06401          && info->type_stack->type.classdef != NULL);
06402 
06403   /* If we were ignoring this class definition because it was a
06404      duplicate definition, just through away whatever bytes we have
06405      accumulated.  Leave the type on the stack.  */
06406   if (info->type_stack->type.ignorep)
06407     return TRUE;
06408 
06409   nindx = info->type_stack->type.classdef->indx;
06410 
06411   /* If we have a virtual table, we can write out the information now.  */
06412   if (info->type_stack->type.classdef->vclass != NULL
06413       || info->type_stack->type.classdef->ownvptr)
06414     {
06415       if (! ieee_change_buffer (info,
06416                             &info->type_stack->type.classdef->pmiscbuf)
06417          || ! ieee_write_asn (info, nindx, 'z')
06418          || ! ieee_write_atn65 (info, nindx, "")
06419          || ! ieee_write_asn (info, nindx,
06420                             info->type_stack->type.classdef->voffset))
06421        return FALSE;
06422       if (info->type_stack->type.classdef->ownvptr)
06423        {
06424          if (! ieee_write_atn65 (info, nindx, ""))
06425            return FALSE;
06426        }
06427       else
06428        {
06429          if (! ieee_write_atn65 (info, nindx,
06430                               info->type_stack->type.classdef->vclass))
06431            return FALSE;
06432        }
06433       if (! ieee_write_asn (info, nindx, 0))
06434        return FALSE;
06435       info->type_stack->type.classdef->pmisccount += 5;
06436     }
06437 
06438   /* Now that we know the number of pmisc records, we can write out
06439      the atn62 which starts the pmisc records, and append them to the
06440      C++ buffers.  */
06441 
06442   if (! ieee_change_buffer (info, &info->cxx)
06443       || ! ieee_write_byte (info, (int) ieee_nn_record)
06444       || ! ieee_write_number (info, nindx)
06445       || ! ieee_write_id (info, "")
06446       || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
06447       || ! ieee_write_number (info, nindx)
06448       || ! ieee_write_number (info, 0)
06449       || ! ieee_write_number (info, 62)
06450       || ! ieee_write_number (info, 80)
06451       || ! ieee_write_number (info,
06452                            info->type_stack->type.classdef->pmisccount))
06453     return FALSE;
06454 
06455   if (! ieee_append_buffer (info, &info->cxx,
06456                          &info->type_stack->type.classdef->pmiscbuf))
06457     return FALSE;
06458   if (! ieee_buffer_emptyp (&info->type_stack->type.classdef->refs))
06459     {
06460       if (! ieee_append_buffer (info, &info->cxx,
06461                             &info->type_stack->type.classdef->refs))
06462        return FALSE;
06463     }
06464 
06465   return ieee_end_struct_type (p);
06466 }
06467 
06468 /* Push a previously seen typedef onto the type stack.  */
06469 
06470 static bfd_boolean
06471 ieee_typedef_type (void *p, const char *name)
06472 {
06473   struct ieee_handle *info = (struct ieee_handle *) p;
06474   struct ieee_name_type_hash_entry *h;
06475   struct ieee_name_type *nt;
06476 
06477   h = ieee_name_type_hash_lookup (&info->typedefs, name, FALSE, FALSE);
06478 
06479   /* h should never be NULL, since that would imply that the generic
06480      debugging code has asked for a typedef which it has not yet
06481      defined.  */
06482   assert (h != NULL);
06483 
06484   /* We always use the most recently defined type for this name, which
06485      will be the first one on the list.  */
06486 
06487   nt = h->types;
06488   if (! ieee_push_type (info, nt->type.indx, nt->type.size,
06489                      nt->type.unsignedp, nt->type.localp))
06490     return FALSE;
06491 
06492   /* Copy over any other type information we may have.  */
06493   info->type_stack->type = nt->type;
06494 
06495   return TRUE;
06496 }
06497 
06498 /* Push a tagged type onto the type stack.  */
06499 
06500 static bfd_boolean
06501 ieee_tag_type (void *p, const char *name, unsigned int id,
06502               enum debug_type_kind kind)
06503 {
06504   struct ieee_handle *info = (struct ieee_handle *) p;
06505   bfd_boolean localp;
06506   bfd_boolean copy;
06507   char ab[20];
06508   struct ieee_name_type_hash_entry *h;
06509   struct ieee_name_type *nt;
06510 
06511   if (kind == DEBUG_KIND_ENUM)
06512     {
06513       struct ieee_defined_enum *e;
06514 
06515       if (name == NULL)
06516        abort ();
06517       for (e = info->enums; e != NULL; e = e->next)
06518        if (e->tag != NULL && strcmp (e->tag, name) == 0)
06519          return ieee_push_type (info, e->indx, 0, TRUE, FALSE);
06520 
06521       e = (struct ieee_defined_enum *) xmalloc (sizeof *e);
06522       memset (e, 0, sizeof *e);
06523 
06524       e->indx = info->type_indx;
06525       ++info->type_indx;
06526       e->tag = name;
06527       e->defined = FALSE;
06528 
06529       e->next = info->enums;
06530       info->enums = e;
06531 
06532       return ieee_push_type (info, e->indx, 0, TRUE, FALSE);
06533     }
06534 
06535   localp = FALSE;
06536 
06537   copy = FALSE;
06538   if (name == NULL)
06539     {
06540       sprintf (ab, "__anon%u", id);
06541       name = ab;
06542       copy = TRUE;
06543     }
06544 
06545   h = ieee_name_type_hash_lookup (&info->tags, name, TRUE, copy);
06546   if (h == NULL)
06547     return FALSE;
06548 
06549   for (nt = h->types; nt != NULL; nt = nt->next)
06550     {
06551       if (nt->id == id)
06552        {
06553          if (! ieee_push_type (info, nt->type.indx, nt->type.size,
06554                             nt->type.unsignedp, nt->type.localp))
06555            return FALSE;
06556          /* Copy over any other type information we may have.  */
06557          info->type_stack->type = nt->type;
06558          return TRUE;
06559        }
06560 
06561       if (! nt->type.localp)
06562        {
06563          /* This is a duplicate of a global type, so it must be
06564              local.  */
06565          localp = TRUE;
06566        }
06567     }
06568 
06569   nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
06570   memset (nt, 0, sizeof *nt);
06571 
06572   nt->id = id;
06573   nt->type.name = h->root.string;
06574   nt->type.indx = info->type_indx;
06575   nt->type.localp = localp;
06576   ++info->type_indx;
06577   nt->kind = kind;
06578 
06579   nt->next = h->types;
06580   h->types = nt;
06581 
06582   if (! ieee_push_type (info, nt->type.indx, 0, FALSE, localp))
06583     return FALSE;
06584 
06585   info->type_stack->type.name = h->root.string;
06586 
06587   return TRUE;
06588 }
06589 
06590 /* Output a typedef.  */
06591 
06592 static bfd_boolean
06593 ieee_typdef (void *p, const char *name)
06594 {
06595   struct ieee_handle *info = (struct ieee_handle *) p;
06596   struct ieee_write_type type;
06597   unsigned int indx;
06598   bfd_boolean found;
06599   bfd_boolean localp;
06600   struct ieee_name_type_hash_entry *h;
06601   struct ieee_name_type *nt;
06602 
06603   type = info->type_stack->type;
06604   indx = type.indx;
06605 
06606   /* If this is a simple builtin type using a builtin name, we don't
06607      want to output the typedef itself.  We also want to change the
06608      type index to correspond to the name being used.  We recognize
06609      names used in stabs debugging output even if they don't exactly
06610      correspond to the names used for the IEEE builtin types.  */
06611   found = FALSE;
06612   if (indx <= (unsigned int) builtin_bcd_float)
06613     {
06614       switch ((enum builtin_types) indx)
06615        {
06616        default:
06617          break;
06618 
06619        case builtin_void:
06620          if (strcmp (name, "void") == 0)
06621            found = TRUE;
06622          break;
06623 
06624        case builtin_signed_char:
06625        case builtin_char:
06626          if (strcmp (name, "signed char") == 0)
06627            {
06628              indx = (unsigned int) builtin_signed_char;
06629              found = TRUE;
06630            }
06631          else if (strcmp (name, "char") == 0)
06632            {
06633              indx = (unsigned int) builtin_char;
06634              found = TRUE;
06635            }
06636          break;
06637 
06638        case builtin_unsigned_char:
06639          if (strcmp (name, "unsigned char") == 0)
06640            found = TRUE;
06641          break;
06642 
06643        case builtin_signed_short_int:
06644        case builtin_short:
06645        case builtin_short_int:
06646        case builtin_signed_short:
06647          if (strcmp (name, "signed short int") == 0)
06648            {
06649              indx = (unsigned int) builtin_signed_short_int;
06650              found = TRUE;
06651            }
06652          else if (strcmp (name, "short") == 0)
06653            {
06654              indx = (unsigned int) builtin_short;
06655              found = TRUE;
06656            }
06657          else if (strcmp (name, "short int") == 0)
06658            {
06659              indx = (unsigned int) builtin_short_int;
06660              found = TRUE;
06661            }
06662          else if (strcmp (name, "signed short") == 0)
06663            {
06664              indx = (unsigned int) builtin_signed_short;
06665              found = TRUE;
06666            }
06667          break;
06668 
06669        case builtin_unsigned_short_int:
06670        case builtin_unsigned_short:
06671          if (strcmp (name, "unsigned short int") == 0
06672              || strcmp (name, "short unsigned int") == 0)
06673            {
06674              indx = builtin_unsigned_short_int;
06675              found = TRUE;
06676            }
06677          else if (strcmp (name, "unsigned short") == 0)
06678            {
06679              indx = builtin_unsigned_short;
06680              found = TRUE;
06681            }
06682          break;
06683 
06684        case builtin_signed_long:
06685        case builtin_int: /* FIXME: Size depends upon architecture.  */
06686        case builtin_long:
06687          if (strcmp (name, "signed long") == 0)
06688            {
06689              indx = builtin_signed_long;
06690              found = TRUE;
06691            }
06692          else if (strcmp (name, "int") == 0)
06693            {
06694              indx = builtin_int;
06695              found = TRUE;
06696            }
06697          else if (strcmp (name, "long") == 0
06698                  || strcmp (name, "long int") == 0)
06699            {
06700              indx = builtin_long;
06701              found = TRUE;
06702            }
06703          break;
06704 
06705        case builtin_unsigned_long:
06706        case builtin_unsigned: /* FIXME: Size depends upon architecture.  */
06707        case builtin_unsigned_int: /* FIXME: Like builtin_unsigned.  */
06708          if (strcmp (name, "unsigned long") == 0
06709              || strcmp (name, "long unsigned int") == 0)
06710            {
06711              indx = builtin_unsigned_long;
06712              found = TRUE;
06713            }
06714          else if (strcmp (name, "unsigned") == 0)
06715            {
06716              indx = builtin_unsigned;
06717              found = TRUE;
06718            }
06719          else if (strcmp (name, "unsigned int") == 0)
06720            {
06721              indx = builtin_unsigned_int;
06722              found = TRUE;
06723            }
06724          break;
06725 
06726        case builtin_signed_long_long:
06727          if (strcmp (name, "signed long long") == 0
06728              || strcmp (name, "long long int") == 0)
06729            found = TRUE;
06730          break;
06731 
06732        case builtin_unsigned_long_long:
06733          if (strcmp (name, "unsigned long long") == 0
06734              || strcmp (name, "long long unsigned int") == 0)
06735            found = TRUE;
06736          break;
06737 
06738        case builtin_float:
06739          if (strcmp (name, "float") == 0)
06740            found = TRUE;
06741          break;
06742 
06743        case builtin_double:
06744          if (strcmp (name, "double") == 0)
06745            found = TRUE;
06746          break;
06747 
06748        case builtin_long_double:
06749          if (strcmp (name, "long double") == 0)
06750            found = TRUE;
06751          break;
06752 
06753        case builtin_long_long_double:
06754          if (strcmp (name, "long long double") == 0)
06755            found = TRUE;
06756          break;
06757        }
06758 
06759       if (found)
06760        type.indx = indx;
06761     }
06762 
06763   h = ieee_name_type_hash_lookup (&info->typedefs, name, TRUE, FALSE);
06764   if (h == NULL)
06765     return FALSE;
06766 
06767   /* See if we have already defined this type with this name.  */
06768   localp = type.localp;
06769   for (nt = h->types; nt != NULL; nt = nt->next)
06770     {
06771       if (nt->id == indx)
06772        {
06773          /* If this is a global definition, then we don't need to
06774             do anything here.  */
06775          if (! nt->type.localp)
06776            {
06777              ieee_pop_unused_type (info);
06778              return TRUE;
06779            }
06780        }
06781       else
06782        {
06783          /* This is a duplicate definition, so make this one local.  */
06784          localp = TRUE;
06785        }
06786     }
06787 
06788   /* We need to add a new typedef for this type.  */
06789 
06790   nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
06791   memset (nt, 0, sizeof *nt);
06792   nt->id = indx;
06793   nt->type = type;
06794   nt->type.name = name;
06795   nt->type.localp = localp;
06796   nt->kind = DEBUG_KIND_ILLEGAL;
06797 
06798   nt->next = h->types;
06799   h->types = nt;
06800 
06801   if (found)
06802     {
06803       /* This is one of the builtin typedefs, so we don't need to
06804          actually define it.  */
06805       ieee_pop_unused_type (info);
06806       return TRUE;
06807     }
06808 
06809   indx = ieee_pop_type (info);
06810 
06811   if (! ieee_define_named_type (info, name, (unsigned int) -1, type.size,
06812                             type.unsignedp,      localp,
06813                             (struct ieee_buflist *) NULL)
06814       || ! ieee_write_number (info, 'T')
06815       || ! ieee_write_number (info, indx))
06816     return FALSE;
06817 
06818   /* Remove the type we just added to the type stack.  This should not
06819      be ieee_pop_unused_type, since the type is used, we just don't
06820      need it now.  */
06821   (void) ieee_pop_type (info);
06822 
06823   return TRUE;
06824 }
06825 
06826 /* Output a tag for a type.  We don't have to do anything here.  */
06827 
06828 static bfd_boolean
06829 ieee_tag (void *p, const char *name ATTRIBUTE_UNUSED)
06830 {
06831   struct ieee_handle *info = (struct ieee_handle *) p;
06832 
06833   /* This should not be ieee_pop_unused_type, since we want the type
06834      to be defined.  */
06835   (void) ieee_pop_type (info);
06836   return TRUE;
06837 }
06838 
06839 /* Output an integer constant.  */
06840 
06841 static bfd_boolean
06842 ieee_int_constant (void *p ATTRIBUTE_UNUSED, const char *name ATTRIBUTE_UNUSED,
06843                  bfd_vma val ATTRIBUTE_UNUSED)
06844 {
06845   /* FIXME.  */
06846   return TRUE;
06847 }
06848 
06849 /* Output a floating point constant.  */
06850 
06851 static bfd_boolean
06852 ieee_float_constant (void *p ATTRIBUTE_UNUSED,
06853                    const char *name ATTRIBUTE_UNUSED,
06854                    double val ATTRIBUTE_UNUSED)
06855 {
06856   /* FIXME.  */
06857   return TRUE;
06858 }
06859 
06860 /* Output a typed constant.  */
06861 
06862 static bfd_boolean
06863 ieee_typed_constant (void *p, const char *name ATTRIBUTE_UNUSED,
06864                    bfd_vma val ATTRIBUTE_UNUSED)
06865 {
06866   struct ieee_handle *info = (struct ieee_handle *) p;
06867 
06868   /* FIXME.  */
06869   ieee_pop_unused_type (info);
06870   return TRUE;
06871 }
06872 
06873 /* Output a variable.  */
06874 
06875 static bfd_boolean
06876 ieee_variable (void *p, const char *name, enum debug_var_kind kind,
06877               bfd_vma val)
06878 {
06879   struct ieee_handle *info = (struct ieee_handle *) p;
06880   unsigned int name_indx;
06881   unsigned int size;
06882   bfd_boolean referencep;
06883   unsigned int type_indx;
06884   bfd_boolean asn;
06885   int refflag;
06886 
06887   size = info->type_stack->type.size;
06888   referencep = info->type_stack->type.referencep;
06889   type_indx = ieee_pop_type (info);
06890 
06891   assert (! ieee_buffer_emptyp (&info->vars));
06892   if (! ieee_change_buffer (info, &info->vars))
06893     return FALSE;
06894 
06895   name_indx = info->name_indx;
06896   ++info->name_indx;
06897 
06898   /* Write out an NN and an ATN record for this variable.  */
06899   if (! ieee_write_byte (info, (int) ieee_nn_record)
06900       || ! ieee_write_number (info, name_indx)
06901       || ! ieee_write_id (info, name)
06902       || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
06903       || ! ieee_write_number (info, name_indx)
06904       || ! ieee_write_number (info, type_indx))
06905     return FALSE;
06906   switch (kind)
06907     {
06908     default:
06909       abort ();
06910       return FALSE;
06911     case DEBUG_GLOBAL:
06912       if (! ieee_write_number (info, 8)
06913          || ! ieee_add_range (info, FALSE, val, val + size))
06914        return FALSE;
06915       refflag = 0;
06916       asn = TRUE;
06917       break;
06918     case DEBUG_STATIC:
06919       if (! ieee_write_number (info, 3)
06920          || ! ieee_add_range (info, FALSE, val, val + size))
06921        return FALSE;
06922       refflag = 1;
06923       asn = TRUE;
06924       break;
06925     case DEBUG_LOCAL_STATIC:
06926       if (! ieee_write_number (info, 3)
06927          || ! ieee_add_range (info, FALSE, val, val + size))
06928        return FALSE;
06929       refflag = 2;
06930       asn = TRUE;
06931       break;
06932     case DEBUG_LOCAL:
06933       if (! ieee_write_number (info, 1)
06934          || ! ieee_write_number (info, val))
06935        return FALSE;
06936       refflag = 2;
06937       asn = FALSE;
06938       break;
06939     case DEBUG_REGISTER:
06940       if (! ieee_write_number (info, 2)
06941          || ! ieee_write_number (info,
06942                               ieee_genreg_to_regno (info->abfd, val)))
06943        return FALSE;
06944       refflag = 2;
06945       asn = FALSE;
06946       break;
06947     }
06948 
06949   if (asn)
06950     {
06951       if (! ieee_write_asn (info, name_indx, val))
06952        return FALSE;
06953     }
06954 
06955   /* If this is really a reference type, then we just output it with
06956      pointer type, and must now output a C++ record indicating that it
06957      is really reference type.  */
06958   if (referencep)
06959     {
06960       unsigned int nindx;
06961 
06962       nindx = info->name_indx;
06963       ++info->name_indx;
06964 
06965       /* If this is a global variable, we want to output the misc
06966          record in the C++ misc record block.  Otherwise, we want to
06967          output it just after the variable definition, which is where
06968          the current buffer is.  */
06969       if (refflag != 2)
06970        {
06971          if (! ieee_change_buffer (info, &info->cxx))
06972            return FALSE;
06973        }
06974 
06975       if (! ieee_write_byte (info, (int) ieee_nn_record)
06976          || ! ieee_write_number (info, nindx)
06977          || ! ieee_write_id (info, "")
06978          || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
06979          || ! ieee_write_number (info, nindx)
06980          || ! ieee_write_number (info, 0)
06981          || ! ieee_write_number (info, 62)
06982          || ! ieee_write_number (info, 80)
06983          || ! ieee_write_number (info, 3)
06984          || ! ieee_write_asn (info, nindx, 'R')
06985          || ! ieee_write_asn (info, nindx, refflag)
06986          || ! ieee_write_atn65 (info, nindx, name))
06987        return FALSE;
06988     }
06989 
06990   return TRUE;
06991 }
06992 
06993 /* Start outputting information for a function.  */
06994 
06995 static bfd_boolean
06996 ieee_start_function (void *p, const char *name, bfd_boolean global)
06997 {
06998   struct ieee_handle *info = (struct ieee_handle *) p;
06999   bfd_boolean referencep;
07000   unsigned int retindx, typeindx;
07001 
07002   referencep = info->type_stack->type.referencep;
07003   retindx = ieee_pop_type (info);
07004 
07005   /* Besides recording a BB4 or BB6 block, we record the type of the
07006      function in the BB1 typedef block.  We can't write out the full
07007      type until we have seen all the parameters, so we accumulate it
07008      in info->fntype and info->fnargs.  */
07009   if (! ieee_buffer_emptyp (&info->fntype))
07010     {
07011       /* FIXME: This might happen someday if we support nested
07012          functions.  */
07013       abort ();
07014     }
07015 
07016   info->fnname = name;
07017 
07018   /* An attribute of 0x40 means that the push mask is unknown.  */
07019   if (! ieee_define_named_type (info, name, (unsigned int) -1, 0, FALSE, TRUE,
07020                             &info->fntype)
07021       || ! ieee_write_number (info, 'x')
07022       || ! ieee_write_number (info, 0x40)
07023       || ! ieee_write_number (info, 0)
07024       || ! ieee_write_number (info, 0)
07025       || ! ieee_write_number (info, retindx))
07026     return FALSE;
07027 
07028   typeindx = ieee_pop_type (info);
07029 
07030   if (! ieee_init_buffer (info, &info->fnargs))
07031     return FALSE;
07032   info->fnargcount = 0;
07033 
07034   /* If the function return value is actually a reference type, we
07035      must add a record indicating that.  */
07036   if (referencep)
07037     {
07038       unsigned int nindx;
07039 
07040       nindx = info->name_indx;
07041       ++info->name_indx;
07042       if (! ieee_change_buffer (info, &info->cxx)
07043          || ! ieee_write_byte (info, (int) ieee_nn_record)
07044          || ! ieee_write_number (info, nindx)
07045          || ! ieee_write_id (info, "")
07046          || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
07047          || ! ieee_write_number (info, nindx)
07048          || ! ieee_write_number (info, 0)
07049          || ! ieee_write_number (info, 62)
07050          || ! ieee_write_number (info, 80)
07051          || ! ieee_write_number (info, 3)
07052          || ! ieee_write_asn (info, nindx, 'R')
07053          || ! ieee_write_asn (info, nindx, global ? 0 : 1)
07054          || ! ieee_write_atn65 (info, nindx, name))
07055        return FALSE;
07056     }
07057 
07058   assert (! ieee_buffer_emptyp (&info->vars));
07059   if (! ieee_change_buffer (info, &info->vars))
07060     return FALSE;
07061 
07062   /* The address is written out as the first block.  */
07063 
07064   ++info->block_depth;
07065 
07066   return (ieee_write_byte (info, (int) ieee_bb_record_enum)
07067          && ieee_write_byte (info, global ? 4 : 6)
07068          && ieee_write_number (info, 0)
07069          && ieee_write_id (info, name)
07070          && ieee_write_number (info, 0)
07071          && ieee_write_number (info, typeindx));
07072 }
07073 
07074 /* Add a function parameter.  This will normally be called before the
07075    first block, so we postpone them until we see the block.  */
07076 
07077 static bfd_boolean
07078 ieee_function_parameter (void *p, const char *name, enum debug_parm_kind kind,
07079                       bfd_vma val)
07080 {
07081   struct ieee_handle *info = (struct ieee_handle *) p;
07082   struct ieee_pending_parm *m, **pm;
07083 
07084   assert (info->block_depth == 1);
07085 
07086   m = (struct ieee_pending_parm *) xmalloc (sizeof *m);
07087   memset (m, 0, sizeof *m);
07088 
07089   m->next = NULL;
07090   m->name = name;
07091   m->referencep = info->type_stack->type.referencep;
07092   m->type = ieee_pop_type (info);
07093   m->kind = kind;
07094   m->val = val;
07095 
07096   for (pm = &info->pending_parms; *pm != NULL; pm = &(*pm)->next)
07097     ;
07098   *pm = m;
07099 
07100   /* Add the type to the fnargs list.  */
07101   if (! ieee_change_buffer (info, &info->fnargs)
07102       || ! ieee_write_number (info, m->type))
07103     return FALSE;
07104   ++info->fnargcount;
07105 
07106   return TRUE;
07107 }
07108 
07109 /* Output pending function parameters.  */
07110 
07111 static bfd_boolean
07112 ieee_output_pending_parms (struct ieee_handle *info)
07113 {
07114   struct ieee_pending_parm *m;
07115   unsigned int refcount;
07116 
07117   refcount = 0;
07118   for (m = info->pending_parms; m != NULL; m = m->next)
07119     {
07120       enum debug_var_kind vkind;
07121 
07122       switch (m->kind)
07123        {
07124        default:
07125          abort ();
07126          return FALSE;
07127        case DEBUG_PARM_STACK:
07128        case DEBUG_PARM_REFERENCE:
07129          vkind = DEBUG_LOCAL;
07130          break;
07131        case DEBUG_PARM_REG:
07132        case DEBUG_PARM_REF_REG:
07133          vkind = DEBUG_REGISTER;
07134          break;
07135        }
07136 
07137       if (! ieee_push_type (info, m->type, 0, FALSE, FALSE))
07138        return FALSE;
07139       info->type_stack->type.referencep = m->referencep;
07140       if (m->referencep)
07141        ++refcount;
07142       if (! ieee_variable ((void *) info, m->name, vkind, m->val))
07143        return FALSE;
07144     }
07145 
07146   /* If there are any reference parameters, we need to output a
07147      miscellaneous record indicating them.  */
07148   if (refcount > 0)
07149     {
07150       unsigned int nindx, varindx;
07151 
07152       /* FIXME: The MRI compiler outputs the demangled function name
07153          here, but we are outputting the mangled name.  */
07154       nindx = info->name_indx;
07155       ++info->name_indx;
07156       if (! ieee_change_buffer (info, &info->vars)
07157          || ! ieee_write_byte (info, (int) ieee_nn_record)
07158          || ! ieee_write_number (info, nindx)
07159          || ! ieee_write_id (info, "")
07160          || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
07161          || ! ieee_write_number (info, nindx)
07162          || ! ieee_write_number (info, 0)
07163          || ! ieee_write_number (info, 62)
07164          || ! ieee_write_number (info, 80)
07165          || ! ieee_write_number (info, refcount + 3)
07166          || ! ieee_write_asn (info, nindx, 'B')
07167          || ! ieee_write_atn65 (info, nindx, info->fnname)
07168          || ! ieee_write_asn (info, nindx, 0))
07169        return FALSE;
07170       for (m = info->pending_parms, varindx = 1;
07171           m != NULL;
07172           m = m->next, varindx++)
07173        {
07174          if (m->referencep)
07175            {
07176              if (! ieee_write_asn (info, nindx, varindx))
07177               return FALSE;
07178            }
07179        }
07180     }
07181 
07182   m = info->pending_parms;
07183   while (m != NULL)
07184     {
07185       struct ieee_pending_parm *next;
07186 
07187       next = m->next;
07188       free (m);
07189       m = next;
07190     }
07191 
07192   info->pending_parms = NULL;
07193 
07194   return TRUE;
07195 }
07196 
07197 /* Start a block.  If this is the first block, we output the address
07198    to finish the BB4 or BB6, and then output the function parameters.  */
07199 
07200 static bfd_boolean
07201 ieee_start_block (void *p, bfd_vma addr)
07202 {
07203   struct ieee_handle *info = (struct ieee_handle *) p;
07204 
07205   if (! ieee_change_buffer (info, &info->vars))
07206     return FALSE;
07207 
07208   if (info->block_depth == 1)
07209     {
07210       if (! ieee_write_number (info, addr)
07211          || ! ieee_output_pending_parms (info))
07212        return FALSE;
07213     }
07214   else
07215     {
07216       if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
07217          || ! ieee_write_byte (info, 6)
07218          || ! ieee_write_number (info, 0)
07219          || ! ieee_write_id (info, "")
07220          || ! ieee_write_number (info, 0)
07221          || ! ieee_write_number (info, 0)
07222          || ! ieee_write_number (info, addr))
07223        return FALSE;
07224     }
07225 
07226   if (! ieee_start_range (info, addr))
07227     return FALSE;
07228 
07229   ++info->block_depth;
07230 
07231   return TRUE;
07232 }
07233 
07234 /* End a block.  */
07235 
07236 static bfd_boolean
07237 ieee_end_block (void *p, bfd_vma addr)
07238 {
07239   struct ieee_handle *info = (struct ieee_handle *) p;
07240 
07241   /* The address we are given is the end of the block, but IEEE seems
07242      to want to the address of the last byte in the block, so we
07243      subtract one.  */
07244   if (! ieee_change_buffer (info, &info->vars)
07245       || ! ieee_write_byte (info, (int) ieee_be_record_enum)
07246       || ! ieee_write_number (info, addr - 1))
07247     return FALSE;
07248 
07249   if (! ieee_end_range (info, addr))
07250     return FALSE;
07251 
07252   --info->block_depth;
07253 
07254   if (addr > info->highaddr)
07255     info->highaddr = addr;
07256 
07257   return TRUE;
07258 }
07259 
07260 /* End a function.  */
07261 
07262 static bfd_boolean
07263 ieee_end_function (void *p)
07264 {
07265   struct ieee_handle *info = (struct ieee_handle *) p;
07266 
07267   assert (info->block_depth == 1);
07268 
07269   --info->block_depth;
07270 
07271   /* Now we can finish up fntype, and add it to the typdef section.
07272      At this point, fntype is the 'x' type up to the argument count,
07273      and fnargs is the argument types.  We must add the argument
07274      count, and we must add the level.  FIXME: We don't record varargs
07275      functions correctly.  In fact, stabs debugging does not give us
07276      enough information to do so.  */
07277   if (! ieee_change_buffer (info, &info->fntype)
07278       || ! ieee_write_number (info, info->fnargcount)
07279       || ! ieee_change_buffer (info, &info->fnargs)
07280       || ! ieee_write_number (info, 0))
07281     return FALSE;
07282 
07283   /* Make sure the typdef block has been started.  */
07284   if (ieee_buffer_emptyp (&info->types))
07285     {
07286       if (! ieee_change_buffer (info, &info->types)
07287          || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
07288          || ! ieee_write_byte (info, 1)
07289          || ! ieee_write_number (info, 0)
07290          || ! ieee_write_id (info, info->modname))
07291        return FALSE;
07292     }
07293 
07294   if (! ieee_append_buffer (info, &info->types, &info->fntype)
07295       || ! ieee_append_buffer (info, &info->types, &info->fnargs))
07296     return FALSE;
07297 
07298   info->fnname = NULL;
07299   if (! ieee_init_buffer (info, &info->fntype)
07300       || ! ieee_init_buffer (info, &info->fnargs))
07301     return FALSE;
07302   info->fnargcount = 0;
07303 
07304   return TRUE;
07305 }
07306 
07307 /* Record line number information.  */
07308 
07309 static bfd_boolean
07310 ieee_lineno (void *p, const char *filename, unsigned long lineno, bfd_vma addr)
07311 {
07312   struct ieee_handle *info = (struct ieee_handle *) p;
07313 
07314   assert (info->filename != NULL);
07315 
07316   /* The HP simulator seems to get confused when more than one line is
07317      listed for the same address, at least if they are in different
07318      files.  We handle this by always listing the last line for a
07319      given address, since that seems to be the one that gdb uses.  */
07320   if (info->pending_lineno_filename != NULL
07321       && addr != info->pending_lineno_addr)
07322     {
07323       /* Make sure we have a line number block.  */
07324       if (! ieee_buffer_emptyp (&info->linenos))
07325        {
07326          if (! ieee_change_buffer (info, &info->linenos))
07327            return FALSE;
07328        }
07329       else
07330        {
07331          info->lineno_name_indx = info->name_indx;
07332          ++info->name_indx;
07333          if (! ieee_change_buffer (info, &info->linenos)
07334              || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
07335              || ! ieee_write_byte (info, 5)
07336              || ! ieee_write_number (info, 0)
07337              || ! ieee_write_id (info, info->filename)
07338              || ! ieee_write_byte (info, (int) ieee_nn_record)
07339              || ! ieee_write_number (info, info->lineno_name_indx)
07340              || ! ieee_write_id (info, ""))
07341            return FALSE;
07342          info->lineno_filename = info->filename;
07343        }
07344 
07345       if (strcmp (info->pending_lineno_filename, info->lineno_filename) != 0)
07346        {
07347          if (strcmp (info->filename, info->lineno_filename) != 0)
07348            {
07349              /* We were not in the main file.  Close the block for the
07350                included file.  */
07351              if (! ieee_write_byte (info, (int) ieee_be_record_enum))
07352               return FALSE;
07353              if (strcmp (info->filename, info->pending_lineno_filename) == 0)
07354               {
07355                 /* We need a new NN record, and we aren't about to
07356                    output one.  */
07357                 info->lineno_name_indx = info->name_indx;
07358                 ++info->name_indx;
07359                 if (! ieee_write_byte (info, (int) ieee_nn_record)
07360                     || ! ieee_write_number (info, info->lineno_name_indx)
07361                     || ! ieee_write_id (info, ""))
07362                   return FALSE;
07363               }
07364            }
07365          if (strcmp (info->filename, info->pending_lineno_filename) != 0)
07366            {
07367              /* We are not changing to the main file.  Open a block for
07368                the new included file.  */
07369              info->lineno_name_indx = info->name_indx;
07370              ++info->name_indx;
07371              if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
07372                 || ! ieee_write_byte (info, 5)
07373                 || ! ieee_write_number (info, 0)
07374                 || ! ieee_write_id (info, info->pending_lineno_filename)
07375                 || ! ieee_write_byte (info, (int) ieee_nn_record)
07376                 || ! ieee_write_number (info, info->lineno_name_indx)
07377                 || ! ieee_write_id (info, ""))
07378               return FALSE;
07379            }
07380          info->lineno_filename = info->pending_lineno_filename;
07381        }
07382 
07383       if (! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
07384          || ! ieee_write_number (info, info->lineno_name_indx)
07385          || ! ieee_write_number (info, 0)
07386          || ! ieee_write_number (info, 7)
07387          || ! ieee_write_number (info, info->pending_lineno)
07388          || ! ieee_write_number (info, 0)
07389          || ! ieee_write_asn (info, info->lineno_name_indx,
07390                             info->pending_lineno_addr))
07391        return FALSE;
07392     }
07393 
07394   info->pending_lineno_filename = filename;
07395   info->pending_lineno = lineno;
07396   info->pending_lineno_addr = addr;
07397 
07398   return TRUE;
07399 }