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