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