Subversion Repositories Kolibri OS

Rev

Rev 5217 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /* stabs.c -- Parse COFF debugging information
  2.    Copyright (C) 1996-2015 Free Software Foundation, Inc.
  3.    Written by Ian Lance Taylor <ian@cygnus.com>.
  4.  
  5.    This file is part of GNU Binutils.
  6.  
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 3 of the License, or
  10.    (at your option) any later version.
  11.  
  12.    This program is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with this program; if not, write to the Free Software
  19.    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
  20.    02110-1301, USA.  */
  21.  
  22. /* This file contains code which parses COFF debugging information.  */
  23.  
  24. #include "sysdep.h"
  25. #include "bfd.h"
  26. #include "coff/internal.h"
  27. #include "libiberty.h"
  28. #include "bucomm.h"
  29. #include "debug.h"
  30. #include "budbg.h"
  31.  
  32. /* FIXME: We should not need this BFD internal file.  We need it for
  33.    the N_BTMASK, etc., values.  */
  34. #include "libcoff.h"
  35.  
  36. /* These macros extract the right mask and shifts for this BFD.  They
  37.    assume that there is a local variable named ABFD.  This is so that
  38.    macros like ISFCN and DECREF, from coff/internal.h, will work
  39.    without modification.  */
  40. #define N_BTMASK (coff_data (abfd)->local_n_btmask)
  41. #define N_BTSHFT (coff_data (abfd)->local_n_btshft)
  42. #define N_TMASK  (coff_data (abfd)->local_n_tmask)
  43. #define N_TSHIFT (coff_data (abfd)->local_n_tshift)
  44.  
  45. /* This structure is used to hold the symbols, as well as the current
  46.    location within the symbols.  */
  47.  
  48. struct coff_symbols
  49. {
  50.   /* The symbols.  */
  51.   asymbol **syms;
  52.   /* The number of symbols.  */
  53.   long symcount;
  54.   /* The index of the current symbol.  */
  55.   long symno;
  56.   /* The index of the current symbol in the COFF symbol table (where
  57.      each auxent counts as a symbol).  */
  58.   long coff_symno;
  59. };
  60.  
  61. /* The largest basic type we are prepared to handle.  */
  62.  
  63. #define T_MAX (T_LNGDBL)
  64.  
  65. /* This structure is used to hold slots.  */
  66.  
  67. struct coff_slots
  68. {
  69.   /* Next set of slots.  */
  70.   struct coff_slots *next;
  71.   /* Slots.  */
  72. #define COFF_SLOTS (16)
  73.   debug_type slots[COFF_SLOTS];
  74. };
  75.  
  76. /* This structure is used to map symbol indices to types.  */
  77.  
  78. struct coff_types
  79. {
  80.   /* Slots.  */
  81.   struct coff_slots *slots;
  82.   /* Basic types.  */
  83.   debug_type basic[T_MAX + 1];
  84. };
  85.  
  86. static debug_type *coff_get_slot (struct coff_types *, long);
  87. static debug_type parse_coff_type
  88.   (bfd *, struct coff_symbols *, struct coff_types *, long, int,
  89.    union internal_auxent *, bfd_boolean, void *);
  90. static debug_type parse_coff_base_type
  91.   (bfd *, struct coff_symbols *, struct coff_types *, long, int,
  92.    union internal_auxent *, void *);
  93. static debug_type parse_coff_struct_type
  94.   (bfd *, struct coff_symbols *, struct coff_types *, int,
  95.    union internal_auxent *, void *);
  96. static debug_type parse_coff_enum_type
  97.   (bfd *, struct coff_symbols *, struct coff_types *,
  98.    union internal_auxent *, void *);
  99. static bfd_boolean parse_coff_symbol
  100.   (bfd *, struct coff_types *, asymbol *, long, struct internal_syment *,
  101.    void *, debug_type, bfd_boolean);
  102. static bfd_boolean external_coff_symbol_p (int sym_class);
  103. /* Return the slot for a type.  */
  104.  
  105. static debug_type *
  106. coff_get_slot (struct coff_types *types, long indx)
  107. {
  108.   struct coff_slots **pps;
  109.  
  110.   pps = &types->slots;
  111.  
  112.   /* PR 17512: file: 078-18333-0.001:0.1.
  113.      FIXME: The value of 1000 is a guess.  Maybe a better heuristic is needed.  */
  114.   if (indx / COFF_SLOTS > 1000)
  115.     fatal (_("Excessively large slot index: %lx"), indx);
  116.  
  117.   while (indx >= COFF_SLOTS)
  118.     {
  119.       if (*pps == NULL)
  120.         {
  121.           *pps = (struct coff_slots *) xmalloc (sizeof **pps);
  122.           memset (*pps, 0, sizeof **pps);
  123.         }
  124.       pps = &(*pps)->next;
  125.       indx -= COFF_SLOTS;
  126.     }
  127.  
  128.   if (*pps == NULL)
  129.     {
  130.       *pps = (struct coff_slots *) xmalloc (sizeof **pps);
  131.       memset (*pps, 0, sizeof **pps);
  132.     }
  133.  
  134.   return (*pps)->slots + indx;
  135. }
  136.  
  137. /* Parse a COFF type code in NTYPE.  */
  138.  
  139. static debug_type
  140. parse_coff_type (bfd *abfd, struct coff_symbols *symbols,
  141.                  struct coff_types *types, long coff_symno, int ntype,
  142.                  union internal_auxent *pauxent, bfd_boolean useaux,
  143.                  void *dhandle)
  144. {
  145.   debug_type type;
  146.  
  147.   if ((ntype & ~N_BTMASK) != 0)
  148.     {
  149.       int newtype;
  150.  
  151.       newtype = DECREF (ntype);
  152.  
  153.       if (ISPTR (ntype))
  154.         {
  155.           type = parse_coff_type (abfd, symbols, types, coff_symno, newtype,
  156.                                   pauxent, useaux, dhandle);
  157.           type = debug_make_pointer_type (dhandle, type);
  158.         }
  159.       else if (ISFCN (ntype))
  160.         {
  161.           type = parse_coff_type (abfd, symbols, types, coff_symno, newtype,
  162.                                   pauxent, useaux, dhandle);
  163.           type = debug_make_function_type (dhandle, type, (debug_type *) NULL,
  164.                                            FALSE);
  165.         }
  166.       else if (ISARY (ntype))
  167.         {
  168.           int n;
  169.  
  170.           if (pauxent == NULL)
  171.             n = 0;
  172.           else
  173.             {
  174.               unsigned short *dim;
  175.               int i;
  176.  
  177.               /* FIXME: If pauxent->x_sym.x_tagndx.l == 0, gdb sets
  178.                  the c_naux field of the syment to 0.  */
  179.  
  180.               /* Move the dimensions down, so that the next array
  181.                  picks up the next one.  */
  182.               dim = pauxent->x_sym.x_fcnary.x_ary.x_dimen;
  183.               n = dim[0];
  184.               for (i = 0; *dim != 0 && i < DIMNUM - 1; i++, dim++)
  185.                 *dim = *(dim + 1);
  186.               *dim = 0;
  187.             }
  188.  
  189.           type = parse_coff_type (abfd, symbols, types, coff_symno, newtype,
  190.                                   pauxent, FALSE, dhandle);
  191.           type = debug_make_array_type (dhandle, type,
  192.                                         parse_coff_base_type (abfd, symbols,
  193.                                                               types,
  194.                                                               coff_symno,
  195.                                                               T_INT,
  196.                                                               NULL, dhandle),
  197.                                         0, n - 1, FALSE);
  198.         }
  199.       else
  200.         {
  201.           non_fatal (_("parse_coff_type: Bad type code 0x%x"), ntype);
  202.           return DEBUG_TYPE_NULL;
  203.         }
  204.  
  205.       return type;
  206.     }
  207.  
  208.   if (pauxent != NULL && pauxent->x_sym.x_tagndx.l > 0)
  209.     {
  210.       debug_type *slot;
  211.  
  212.       /* This is a reference to an existing type.  FIXME: gdb checks
  213.          that the class is not C_STRTAG, nor C_UNTAG, nor C_ENTAG.  */
  214.       slot = coff_get_slot (types, pauxent->x_sym.x_tagndx.l);
  215.       if (*slot != DEBUG_TYPE_NULL)
  216.         return *slot;
  217.       else
  218.         return debug_make_indirect_type (dhandle, slot, (const char *) NULL);
  219.     }
  220.  
  221.   /* If the aux entry has already been used for something, useaux will
  222.      have been set to false, indicating that parse_coff_base_type
  223.      should not use it.  We need to do it this way, rather than simply
  224.      passing pauxent as NULL, because we need to be able handle
  225.      multiple array dimensions while still discarding pauxent after
  226.      having handled all of them.  */
  227.   if (! useaux)
  228.     pauxent = NULL;
  229.  
  230.   return parse_coff_base_type (abfd, symbols, types, coff_symno, ntype,
  231.                                pauxent, dhandle);
  232. }
  233.  
  234. /* Parse a basic COFF type in NTYPE.  */
  235.  
  236. static debug_type
  237. parse_coff_base_type (bfd *abfd, struct coff_symbols *symbols,
  238.                       struct coff_types *types, long coff_symno, int ntype,
  239.                       union internal_auxent *pauxent, void *dhandle)
  240. {
  241.   debug_type ret;
  242.   bfd_boolean set_basic;
  243.   const char *name;
  244.   debug_type *slot;
  245.  
  246.   if (ntype >= 0
  247.       && ntype <= T_MAX
  248.       && types->basic[ntype] != DEBUG_TYPE_NULL)
  249.     return types->basic[ntype];
  250.  
  251.   set_basic = TRUE;
  252.   name = NULL;
  253.  
  254.   switch (ntype)
  255.     {
  256.     default:
  257.       ret = debug_make_void_type (dhandle);
  258.       break;
  259.  
  260.     case T_NULL:
  261.     case T_VOID:
  262.       ret = debug_make_void_type (dhandle);
  263.       name = "void";
  264.       break;
  265.  
  266.     case T_CHAR:
  267.       ret = debug_make_int_type (dhandle, 1, FALSE);
  268.       name = "char";
  269.       break;
  270.  
  271.     case T_SHORT:
  272.       ret = debug_make_int_type (dhandle, 2, FALSE);
  273.       name = "short";
  274.       break;
  275.  
  276.     case T_INT:
  277.       /* FIXME: Perhaps the size should depend upon the architecture.  */
  278.       ret = debug_make_int_type (dhandle, 4, FALSE);
  279.       name = "int";
  280.       break;
  281.  
  282.     case T_LONG:
  283.       ret = debug_make_int_type (dhandle, 4, FALSE);
  284.       name = "long";
  285.       break;
  286.  
  287.     case T_FLOAT:
  288.       ret = debug_make_float_type (dhandle, 4);
  289.       name = "float";
  290.       break;
  291.  
  292.     case T_DOUBLE:
  293.       ret = debug_make_float_type (dhandle, 8);
  294.       name = "double";
  295.       break;
  296.  
  297.     case T_LNGDBL:
  298.       ret = debug_make_float_type (dhandle, 12);
  299.       name = "long double";
  300.       break;
  301.  
  302.     case T_UCHAR:
  303.       ret = debug_make_int_type (dhandle, 1, TRUE);
  304.       name = "unsigned char";
  305.       break;
  306.  
  307.     case T_USHORT:
  308.       ret = debug_make_int_type (dhandle, 2, TRUE);
  309.       name = "unsigned short";
  310.       break;
  311.  
  312.     case T_UINT:
  313.       ret = debug_make_int_type (dhandle, 4, TRUE);
  314.       name = "unsigned int";
  315.       break;
  316.  
  317.     case T_ULONG:
  318.       ret = debug_make_int_type (dhandle, 4, TRUE);
  319.       name = "unsigned long";
  320.       break;
  321.  
  322.     case T_STRUCT:
  323.       if (pauxent == NULL)
  324.         ret = debug_make_struct_type (dhandle, TRUE, 0,
  325.                                       (debug_field *) NULL);
  326.       else
  327.         ret = parse_coff_struct_type (abfd, symbols, types, ntype, pauxent,
  328.                                       dhandle);
  329.  
  330.       slot = coff_get_slot (types, coff_symno);
  331.       *slot = ret;
  332.  
  333.       set_basic = FALSE;
  334.       break;
  335.  
  336.     case T_UNION:
  337.       if (pauxent == NULL)
  338.         ret = debug_make_struct_type (dhandle, FALSE, 0, (debug_field *) NULL);
  339.       else
  340.         ret = parse_coff_struct_type (abfd, symbols, types, ntype, pauxent,
  341.                                       dhandle);
  342.  
  343.       slot = coff_get_slot (types, coff_symno);
  344.       *slot = ret;
  345.  
  346.       set_basic = FALSE;
  347.       break;
  348.  
  349.     case T_ENUM:
  350.       if (pauxent == NULL)
  351.         ret = debug_make_enum_type (dhandle, (const char **) NULL,
  352.                                     (bfd_signed_vma *) NULL);
  353.       else
  354.         ret = parse_coff_enum_type (abfd, symbols, types, pauxent, dhandle);
  355.  
  356.       slot = coff_get_slot (types, coff_symno);
  357.       *slot = ret;
  358.  
  359.       set_basic = FALSE;
  360.       break;
  361.     }
  362.  
  363.   if (name != NULL)
  364.     ret = debug_name_type (dhandle, name, ret);
  365.  
  366.   if (set_basic
  367.       && ntype >= 0
  368.       && ntype <= T_MAX)
  369.     types->basic[ntype] = ret;
  370.  
  371.   return ret;
  372. }
  373.  
  374. /* Parse a struct type.  */
  375.  
  376. static debug_type
  377. parse_coff_struct_type (bfd *abfd, struct coff_symbols *symbols,
  378.                         struct coff_types *types, int ntype,
  379.                         union internal_auxent *pauxent, void *dhandle)
  380. {
  381.   long symend;
  382.   int alloc;
  383.   debug_field *fields;
  384.   int count;
  385.   bfd_boolean done;
  386.  
  387.   symend = pauxent->x_sym.x_fcnary.x_fcn.x_endndx.l;
  388.  
  389.   alloc = 10;
  390.   fields = (debug_field *) xmalloc (alloc * sizeof *fields);
  391.   count = 0;
  392.  
  393.   done = FALSE;
  394.   while (! done
  395.          && symbols->coff_symno < symend
  396.          && symbols->symno < symbols->symcount)
  397.     {
  398.       asymbol *sym;
  399.       long this_coff_symno;
  400.       struct internal_syment syment;
  401.       union internal_auxent auxent;
  402.       union internal_auxent *psubaux;
  403.       bfd_vma bitpos = 0, bitsize = 0;
  404.  
  405.       sym = symbols->syms[symbols->symno];
  406.  
  407.       if (! bfd_coff_get_syment (abfd, sym, &syment))
  408.         {
  409.           non_fatal (_("bfd_coff_get_syment failed: %s"),
  410.                      bfd_errmsg (bfd_get_error ()));
  411.           return DEBUG_TYPE_NULL;
  412.         }
  413.  
  414.       this_coff_symno = symbols->coff_symno;
  415.  
  416.       ++symbols->symno;
  417.       symbols->coff_symno += 1 + syment.n_numaux;
  418.  
  419.       if (syment.n_numaux == 0)
  420.         psubaux = NULL;
  421.       else
  422.         {
  423.           if (! bfd_coff_get_auxent (abfd, sym, 0, &auxent))
  424.             {
  425.               non_fatal (_("bfd_coff_get_auxent failed: %s"),
  426.                          bfd_errmsg (bfd_get_error ()));
  427.               return DEBUG_TYPE_NULL;
  428.             }
  429.           psubaux = &auxent;
  430.         }
  431.  
  432.       switch (syment.n_sclass)
  433.         {
  434.         case C_MOS:
  435.         case C_MOU:
  436.           bitpos = 8 * bfd_asymbol_value (sym);
  437.           bitsize = 0;
  438.           break;
  439.  
  440.         case C_FIELD:
  441.           bitpos = bfd_asymbol_value (sym);
  442.           bitsize = auxent.x_sym.x_misc.x_lnsz.x_size;
  443.           break;
  444.  
  445.         case C_EOS:
  446.           done = TRUE;
  447.           break;
  448.         }
  449.  
  450.       if (! done)
  451.         {
  452.           debug_type ftype;
  453.           debug_field f;
  454.  
  455.           ftype = parse_coff_type (abfd, symbols, types, this_coff_symno,
  456.                                    syment.n_type, psubaux, TRUE, dhandle);
  457.           f = debug_make_field (dhandle, bfd_asymbol_name (sym), ftype,
  458.                                 bitpos, bitsize, DEBUG_VISIBILITY_PUBLIC);
  459.           if (f == DEBUG_FIELD_NULL)
  460.             return DEBUG_TYPE_NULL;
  461.  
  462.           if (count + 1 >= alloc)
  463.             {
  464.               alloc += 10;
  465.               fields = ((debug_field *)
  466.                         xrealloc (fields, alloc * sizeof *fields));
  467.             }
  468.  
  469.           fields[count] = f;
  470.           ++count;
  471.         }
  472.     }
  473.  
  474.   fields[count] = DEBUG_FIELD_NULL;
  475.  
  476.   return debug_make_struct_type (dhandle, ntype == T_STRUCT,
  477.                                  pauxent->x_sym.x_misc.x_lnsz.x_size,
  478.                                  fields);
  479. }
  480.  
  481. /* Parse an enum type.  */
  482.  
  483. static debug_type
  484. parse_coff_enum_type (bfd *abfd, struct coff_symbols *symbols,
  485.                       struct coff_types *types ATTRIBUTE_UNUSED,
  486.                       union internal_auxent *pauxent, void *dhandle)
  487. {
  488.   long symend;
  489.   int alloc;
  490.   const char **names;
  491.   bfd_signed_vma *vals;
  492.   int count;
  493.   bfd_boolean done;
  494.  
  495.   symend = pauxent->x_sym.x_fcnary.x_fcn.x_endndx.l;
  496.  
  497.   alloc = 10;
  498.   names = (const char **) xmalloc (alloc * sizeof *names);
  499.   vals = (bfd_signed_vma *) xmalloc (alloc * sizeof *vals);
  500.   count = 0;
  501.  
  502.   done = FALSE;
  503.   while (! done
  504.          && symbols->coff_symno < symend
  505.          && symbols->symno < symbols->symcount)
  506.     {
  507.       asymbol *sym;
  508.       struct internal_syment syment;
  509.  
  510.       sym = symbols->syms[symbols->symno];
  511.  
  512.       if (! bfd_coff_get_syment (abfd, sym, &syment))
  513.         {
  514.           non_fatal (_("bfd_coff_get_syment failed: %s"),
  515.                      bfd_errmsg (bfd_get_error ()));
  516.           return DEBUG_TYPE_NULL;
  517.         }
  518.  
  519.       ++symbols->symno;
  520.       symbols->coff_symno += 1 + syment.n_numaux;
  521.  
  522.       switch (syment.n_sclass)
  523.         {
  524.         case C_MOE:
  525.           if (count + 1 >= alloc)
  526.             {
  527.               alloc += 10;
  528.               names = ((const char **)
  529.                        xrealloc (names, alloc * sizeof *names));
  530.               vals = ((bfd_signed_vma *)
  531.                       xrealloc (vals, alloc * sizeof *vals));
  532.             }
  533.  
  534.           names[count] = bfd_asymbol_name (sym);
  535.           vals[count] = bfd_asymbol_value (sym);
  536.           ++count;
  537.           break;
  538.  
  539.         case C_EOS:
  540.           done = TRUE;
  541.           break;
  542.         }
  543.     }
  544.  
  545.   names[count] = NULL;
  546.  
  547.   return debug_make_enum_type (dhandle, names, vals);
  548. }
  549.  
  550. /* Handle a single COFF symbol.  */
  551.  
  552. static bfd_boolean
  553. parse_coff_symbol (bfd *abfd ATTRIBUTE_UNUSED, struct coff_types *types,
  554.                    asymbol *sym, long coff_symno,
  555.                    struct internal_syment *psyment, void *dhandle,
  556.                    debug_type type, bfd_boolean within_function)
  557. {
  558.   switch (psyment->n_sclass)
  559.     {
  560.     case C_NULL:
  561.       break;
  562.  
  563.     case C_AUTO:
  564.       if (! debug_record_variable (dhandle, bfd_asymbol_name (sym), type,
  565.                                    DEBUG_LOCAL, bfd_asymbol_value (sym)))
  566.         return FALSE;
  567.       break;
  568.  
  569.     case C_WEAKEXT:
  570.     case C_EXT:
  571.       if (! debug_record_variable (dhandle, bfd_asymbol_name (sym), type,
  572.                                    DEBUG_GLOBAL, bfd_asymbol_value (sym)))
  573.         return FALSE;
  574.       break;
  575.  
  576.     case C_STAT:
  577.       if (! debug_record_variable (dhandle, bfd_asymbol_name (sym), type,
  578.                                    (within_function
  579.                                     ? DEBUG_LOCAL_STATIC
  580.                                     : DEBUG_STATIC),
  581.                                    bfd_asymbol_value (sym)))
  582.         return FALSE;
  583.       break;
  584.  
  585.     case C_REG:
  586.       /* FIXME: We may need to convert the register number.  */
  587.       if (! debug_record_variable (dhandle, bfd_asymbol_name (sym), type,
  588.                                    DEBUG_REGISTER, bfd_asymbol_value (sym)))
  589.         return FALSE;
  590.       break;
  591.  
  592.     case C_LABEL:
  593.       break;
  594.  
  595.     case C_ARG:
  596.       if (! debug_record_parameter (dhandle, bfd_asymbol_name (sym), type,
  597.                                     DEBUG_PARM_STACK, bfd_asymbol_value (sym)))
  598.         return FALSE;
  599.       break;
  600.  
  601.     case C_REGPARM:
  602.       /* FIXME: We may need to convert the register number.  */
  603.       if (! debug_record_parameter (dhandle, bfd_asymbol_name (sym), type,
  604.                                     DEBUG_PARM_REG, bfd_asymbol_value (sym)))
  605.         return FALSE;
  606.       break;
  607.  
  608.     case C_TPDEF:
  609.       type = debug_name_type (dhandle, bfd_asymbol_name (sym), type);
  610.       if (type == DEBUG_TYPE_NULL)
  611.         return FALSE;
  612.       break;
  613.  
  614.     case C_STRTAG:
  615.     case C_UNTAG:
  616.     case C_ENTAG:
  617.       {
  618.         debug_type *slot;
  619.  
  620.         type = debug_tag_type (dhandle, bfd_asymbol_name (sym), type);
  621.         if (type == DEBUG_TYPE_NULL)
  622.           return FALSE;
  623.  
  624.         /* Store the named type into the slot, so that references get
  625.            the name.  */
  626.         slot = coff_get_slot (types, coff_symno);
  627.         *slot = type;
  628.       }
  629.       break;
  630.  
  631.     default:
  632.       break;
  633.     }
  634.  
  635.   return TRUE;
  636. }
  637.  
  638. /* Determine if a symbol has external visibility.  */
  639.  
  640. static bfd_boolean
  641. external_coff_symbol_p (int sym_class)
  642. {
  643.   switch (sym_class)
  644.     {
  645.     case C_EXT:
  646.     case C_WEAKEXT:
  647.       return TRUE;
  648.     default:
  649.       break;
  650.     }
  651.   return FALSE;
  652. }
  653.  
  654. /* This is the main routine.  It looks through all the symbols and
  655.    handles them.  */
  656.  
  657. bfd_boolean
  658. parse_coff (bfd *abfd, asymbol **syms, long symcount, void *dhandle)
  659. {
  660.   struct coff_symbols symbols;
  661.   struct coff_types types;
  662.   int i;
  663.   long next_c_file;
  664.   const char *fnname;
  665.   int fnclass;
  666.   int fntype;
  667.   bfd_vma fnend;
  668.   alent *linenos;
  669.   bfd_boolean within_function;
  670.   long this_coff_symno;
  671.  
  672.   symbols.syms = syms;
  673.   symbols.symcount = symcount;
  674.   symbols.symno = 0;
  675.   symbols.coff_symno = 0;
  676.  
  677.   types.slots = NULL;
  678.   for (i = 0; i <= T_MAX; i++)
  679.     types.basic[i] = DEBUG_TYPE_NULL;
  680.  
  681.   next_c_file = -1;
  682.   fnname = NULL;
  683.   fnclass = 0;
  684.   fntype = 0;
  685.   fnend = 0;
  686.   linenos = NULL;
  687.   within_function = FALSE;
  688.  
  689.   while (symbols.symno < symcount)
  690.     {
  691.       asymbol *sym;
  692.       const char *name;
  693.       struct internal_syment syment;
  694.       union internal_auxent auxent;
  695.       union internal_auxent *paux;
  696.       debug_type type;
  697.  
  698.       sym = syms[symbols.symno];
  699.  
  700.       if (! bfd_coff_get_syment (abfd, sym, &syment))
  701.         {
  702.           non_fatal (_("bfd_coff_get_syment failed: %s"),
  703.                      bfd_errmsg (bfd_get_error ()));
  704.           return FALSE;
  705.         }
  706.  
  707.       name = bfd_asymbol_name (sym);
  708.  
  709.       this_coff_symno = symbols.coff_symno;
  710.  
  711.       ++symbols.symno;
  712.       symbols.coff_symno += 1 + syment.n_numaux;
  713.  
  714.       /* We only worry about the first auxent, because that is the
  715.          only one which is relevant for debugging information.  */
  716.       if (syment.n_numaux == 0)
  717.         paux = NULL;
  718.       else
  719.         {
  720.           if (! bfd_coff_get_auxent (abfd, sym, 0, &auxent))
  721.             {
  722.               non_fatal (_("bfd_coff_get_auxent failed: %s"),
  723.                          bfd_errmsg (bfd_get_error ()));
  724.               return FALSE;
  725.             }
  726.           paux = &auxent;
  727.         }
  728.  
  729.       if (this_coff_symno == next_c_file && syment.n_sclass != C_FILE)
  730.         {
  731.           /* The last C_FILE symbol points to the first external
  732.              symbol.  */
  733.           if (! debug_set_filename (dhandle, "*globals*"))
  734.             return FALSE;
  735.         }
  736.  
  737.       switch (syment.n_sclass)
  738.         {
  739.         case C_EFCN:
  740.         case C_EXTDEF:
  741.         case C_ULABEL:
  742.         case C_USTATIC:
  743.         case C_LINE:
  744.         case C_ALIAS:
  745.         case C_HIDDEN:
  746.           /* Just ignore these classes.  */
  747.           break;
  748.  
  749.         case C_FILE:
  750.           next_c_file = syment.n_value;
  751.           if (! debug_set_filename (dhandle, name))
  752.             return FALSE;
  753.           break;
  754.  
  755.         case C_STAT:
  756.           /* Ignore static symbols with a type of T_NULL.  These
  757.              represent section entries.  */
  758.           if (syment.n_type == T_NULL)
  759.             break;
  760.           /* Fall through.  */
  761.         case C_WEAKEXT:
  762.         case C_EXT:
  763.           if (ISFCN (syment.n_type))
  764.             {
  765.               fnname = name;
  766.               fnclass = syment.n_sclass;
  767.               fntype = syment.n_type;
  768.               if (syment.n_numaux > 0)
  769.                 fnend = bfd_asymbol_value (sym) + auxent.x_sym.x_misc.x_fsize;
  770.               else
  771.                 fnend = 0;
  772.               linenos = BFD_SEND (abfd, _get_lineno, (abfd, sym));
  773.               break;
  774.             }
  775.           type = parse_coff_type (abfd, &symbols, &types, this_coff_symno,
  776.                                   syment.n_type, paux, TRUE, dhandle);
  777.           if (type == DEBUG_TYPE_NULL)
  778.             return FALSE;
  779.           if (! parse_coff_symbol (abfd, &types, sym, this_coff_symno, &syment,
  780.                                    dhandle, type, within_function))
  781.             return FALSE;
  782.           break;
  783.  
  784.         case C_FCN:
  785.           if (strcmp (name, ".bf") == 0)
  786.             {
  787.               if (fnname == NULL)
  788.                 {
  789.                   non_fatal (_("%ld: .bf without preceding function"),
  790.                              this_coff_symno);
  791.                   return FALSE;
  792.                 }
  793.  
  794.               type = parse_coff_type (abfd, &symbols, &types, this_coff_symno,
  795.                                       DECREF (fntype), paux, FALSE, dhandle);
  796.               if (type == DEBUG_TYPE_NULL)
  797.                 return FALSE;
  798.  
  799.               if (! debug_record_function (dhandle, fnname, type,
  800.                                            external_coff_symbol_p (fnclass),
  801.                                            bfd_asymbol_value (sym)))
  802.                 return FALSE;
  803.  
  804.               if (linenos != NULL)
  805.                 {
  806.                   int base;
  807.                   bfd_vma addr;
  808.  
  809.                   if (syment.n_numaux == 0)
  810.                     base = 0;
  811.                   else
  812.                     base = auxent.x_sym.x_misc.x_lnsz.x_lnno - 1;
  813.  
  814.                   addr = bfd_get_section_vma (abfd, bfd_get_section (sym));
  815.  
  816.                   ++linenos;
  817.  
  818.                   while (linenos->line_number != 0)
  819.                     {
  820.                       if (! debug_record_line (dhandle,
  821.                                                linenos->line_number + base,
  822.                                                linenos->u.offset + addr))
  823.                         return FALSE;
  824.                       ++linenos;
  825.                     }
  826.                 }
  827.  
  828.               fnname = NULL;
  829.               linenos = NULL;
  830.               fnclass = 0;
  831.               fntype = 0;
  832.  
  833.               within_function = TRUE;
  834.             }
  835.           else if (strcmp (name, ".ef") == 0)
  836.             {
  837.               if (! within_function)
  838.                 {
  839.                   non_fatal (_("%ld: unexpected .ef\n"), this_coff_symno);
  840.                   return FALSE;
  841.                 }
  842.  
  843.               if (bfd_asymbol_value (sym) > fnend)
  844.                 fnend = bfd_asymbol_value (sym);
  845.               if (! debug_end_function (dhandle, fnend))
  846.                 return FALSE;
  847.  
  848.               fnend = 0;
  849.               within_function = FALSE;
  850.             }
  851.           break;
  852.  
  853.         case C_BLOCK:
  854.           if (strcmp (name, ".bb") == 0)
  855.             {
  856.               if (! debug_start_block (dhandle, bfd_asymbol_value (sym)))
  857.                 return FALSE;
  858.             }
  859.           else if (strcmp (name, ".eb") == 0)
  860.             {
  861.               if (! debug_end_block (dhandle, bfd_asymbol_value (sym)))
  862.                 return FALSE;
  863.             }
  864.           break;
  865.  
  866.         default:
  867.           type = parse_coff_type (abfd, &symbols, &types, this_coff_symno,
  868.                                   syment.n_type, paux, TRUE, dhandle);
  869.           if (type == DEBUG_TYPE_NULL)
  870.             return FALSE;
  871.           if (! parse_coff_symbol (abfd, &types, sym, this_coff_symno, &syment,
  872.                                    dhandle, type, within_function))
  873.             return FALSE;
  874.           break;
  875.         }
  876.     }
  877.  
  878.   return TRUE;
  879. }
  880.