Subversion Repositories Kolibri OS

Rev

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

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