ChangeLog rotation
[deliverable/binutils-gdb.git] / binutils / rdcoff.c
CommitLineData
252b5132 1/* stabs.c -- Parse COFF debugging information
82704155 2 Copyright (C) 1996-2019 Free Software Foundation, Inc.
252b5132
RH
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
32866df7 9 the Free Software Foundation; either version 3 of the License, or
252b5132
RH
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
b43b5d5f
NC
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
20 02110-1301, USA. */
252b5132
RH
21
22/* This file contains code which parses COFF debugging information. */
23
3db64b00 24#include "sysdep.h"
252b5132
RH
25#include "bfd.h"
26#include "coff/internal.h"
252b5132 27#include "libiberty.h"
3db64b00 28#include "bucomm.h"
252b5132
RH
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
48struct 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
67struct 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
78struct coff_types
79{
80 /* Slots. */
81 struct coff_slots *slots;
82 /* Basic types. */
83 debug_type basic[T_MAX + 1];
84};
85
f41e4712 86static debug_type *coff_get_slot (struct coff_types *, long);
252b5132 87static debug_type parse_coff_type
2da42df6
AJ
88 (bfd *, struct coff_symbols *, struct coff_types *, long, int,
89 union internal_auxent *, bfd_boolean, void *);
252b5132 90static debug_type parse_coff_base_type
2da42df6
AJ
91 (bfd *, struct coff_symbols *, struct coff_types *, long, int,
92 union internal_auxent *, void *);
252b5132 93static debug_type parse_coff_struct_type
2da42df6
AJ
94 (bfd *, struct coff_symbols *, struct coff_types *, int,
95 union internal_auxent *, void *);
252b5132 96static debug_type parse_coff_enum_type
2da42df6
AJ
97 (bfd *, struct coff_symbols *, struct coff_types *,
98 union internal_auxent *, void *);
b34976b6 99static bfd_boolean parse_coff_symbol
2da42df6
AJ
100 (bfd *, struct coff_types *, asymbol *, long, struct internal_syment *,
101 void *, debug_type, bfd_boolean);
102static bfd_boolean external_coff_symbol_p (int sym_class);
252b5132
RH
103\f
104/* Return the slot for a type. */
105
106static debug_type *
f41e4712 107coff_get_slot (struct coff_types *types, long indx)
252b5132
RH
108{
109 struct coff_slots **pps;
110
111 pps = &types->slots;
112
f41e4712
NC
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
252b5132
RH
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
140static debug_type
2da42df6
AJ
141parse_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)
252b5132
RH
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,
b34976b6 165 FALSE);
252b5132
RH
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,
b34976b6 191 pauxent, FALSE, dhandle);
252b5132
RH
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),
b34976b6 198 0, n - 1, FALSE);
252b5132
RH
199 }
200 else
201 {
37cc8ec1 202 non_fatal (_("parse_coff_type: Bad type code 0x%x"), ntype);
252b5132
RH
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
237static debug_type
2da42df6
AJ
238parse_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)
252b5132
RH
241{
242 debug_type ret;
b34976b6 243 bfd_boolean set_basic;
252b5132
RH
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
b34976b6 252 set_basic = TRUE;
252b5132
RH
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:
b34976b6 268 ret = debug_make_int_type (dhandle, 1, FALSE);
252b5132
RH
269 name = "char";
270 break;
271
272 case T_SHORT:
b34976b6 273 ret = debug_make_int_type (dhandle, 2, FALSE);
252b5132
RH
274 name = "short";
275 break;
276
277 case T_INT:
278 /* FIXME: Perhaps the size should depend upon the architecture. */
b34976b6 279 ret = debug_make_int_type (dhandle, 4, FALSE);
252b5132
RH
280 name = "int";
281 break;
282
283 case T_LONG:
b34976b6 284 ret = debug_make_int_type (dhandle, 4, FALSE);
252b5132
RH
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:
b34976b6 304 ret = debug_make_int_type (dhandle, 1, TRUE);
252b5132
RH
305 name = "unsigned char";
306 break;
307
308 case T_USHORT:
b34976b6 309 ret = debug_make_int_type (dhandle, 2, TRUE);
252b5132
RH
310 name = "unsigned short";
311 break;
312
313 case T_UINT:
b34976b6 314 ret = debug_make_int_type (dhandle, 4, TRUE);
252b5132
RH
315 name = "unsigned int";
316 break;
317
318 case T_ULONG:
b34976b6 319 ret = debug_make_int_type (dhandle, 4, TRUE);
252b5132
RH
320 name = "unsigned long";
321 break;
322
323 case T_STRUCT:
324 if (pauxent == NULL)
b34976b6 325 ret = debug_make_struct_type (dhandle, TRUE, 0,
252b5132
RH
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
b34976b6 334 set_basic = FALSE;
252b5132
RH
335 break;
336
337 case T_UNION:
338 if (pauxent == NULL)
b34976b6 339 ret = debug_make_struct_type (dhandle, FALSE, 0, (debug_field *) NULL);
252b5132
RH
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
b34976b6 347 set_basic = FALSE;
252b5132
RH
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
b34976b6 360 set_basic = FALSE;
252b5132
RH
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
377static debug_type
2da42df6
AJ
378parse_coff_struct_type (bfd *abfd, struct coff_symbols *symbols,
379 struct coff_types *types, int ntype,
380 union internal_auxent *pauxent, void *dhandle)
252b5132
RH
381{
382 long symend;
383 int alloc;
384 debug_field *fields;
385 int count;
b34976b6 386 bfd_boolean done;
252b5132
RH
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
b34976b6 394 done = FALSE;
252b5132
RH
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 {
37cc8ec1
AM
410 non_fatal (_("bfd_coff_get_syment failed: %s"),
411 bfd_errmsg (bfd_get_error ()));
e3d39609 412 free (fields);
252b5132
RH
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 {
37cc8ec1
AM
427 non_fatal (_("bfd_coff_get_auxent failed: %s"),
428 bfd_errmsg (bfd_get_error ()));
e3d39609 429 free (fields);
252b5132
RH
430 return DEBUG_TYPE_NULL;
431 }
432 psubaux = &auxent;
433 }
434
435 switch (syment.n_sclass)
436 {
437 case C_MOS:
438 case C_MOU:
439 bitpos = 8 * bfd_asymbol_value (sym);
440 bitsize = 0;
441 break;
442
443 case C_FIELD:
444 bitpos = bfd_asymbol_value (sym);
445 bitsize = auxent.x_sym.x_misc.x_lnsz.x_size;
446 break;
447
448 case C_EOS:
b34976b6 449 done = TRUE;
252b5132
RH
450 break;
451 }
452
453 if (! done)
454 {
455 debug_type ftype;
456 debug_field f;
457
458 ftype = parse_coff_type (abfd, symbols, types, this_coff_symno,
b34976b6 459 syment.n_type, psubaux, TRUE, dhandle);
252b5132
RH
460 f = debug_make_field (dhandle, bfd_asymbol_name (sym), ftype,
461 bitpos, bitsize, DEBUG_VISIBILITY_PUBLIC);
462 if (f == DEBUG_FIELD_NULL)
463 return DEBUG_TYPE_NULL;
464
465 if (count + 1 >= alloc)
466 {
467 alloc += 10;
468 fields = ((debug_field *)
469 xrealloc (fields, alloc * sizeof *fields));
470 }
471
472 fields[count] = f;
473 ++count;
474 }
475 }
476
477 fields[count] = DEBUG_FIELD_NULL;
478
479 return debug_make_struct_type (dhandle, ntype == T_STRUCT,
480 pauxent->x_sym.x_misc.x_lnsz.x_size,
481 fields);
482}
483
484/* Parse an enum type. */
485
486static debug_type
2da42df6
AJ
487parse_coff_enum_type (bfd *abfd, struct coff_symbols *symbols,
488 struct coff_types *types ATTRIBUTE_UNUSED,
489 union internal_auxent *pauxent, void *dhandle)
252b5132
RH
490{
491 long symend;
492 int alloc;
493 const char **names;
494 bfd_signed_vma *vals;
495 int count;
b34976b6 496 bfd_boolean done;
252b5132
RH
497
498 symend = pauxent->x_sym.x_fcnary.x_fcn.x_endndx.l;
499
500 alloc = 10;
501 names = (const char **) xmalloc (alloc * sizeof *names);
502 vals = (bfd_signed_vma *) xmalloc (alloc * sizeof *vals);
503 count = 0;
504
b34976b6 505 done = FALSE;
252b5132
RH
506 while (! done
507 && symbols->coff_symno < symend
508 && symbols->symno < symbols->symcount)
509 {
510 asymbol *sym;
511 struct internal_syment syment;
512
513 sym = symbols->syms[symbols->symno];
514
515 if (! bfd_coff_get_syment (abfd, sym, &syment))
516 {
37cc8ec1
AM
517 non_fatal (_("bfd_coff_get_syment failed: %s"),
518 bfd_errmsg (bfd_get_error ()));
e3d39609
NC
519 free (names);
520 free (vals);
252b5132
RH
521 return DEBUG_TYPE_NULL;
522 }
523
524 ++symbols->symno;
525 symbols->coff_symno += 1 + syment.n_numaux;
526
527 switch (syment.n_sclass)
528 {
529 case C_MOE:
530 if (count + 1 >= alloc)
531 {
532 alloc += 10;
533 names = ((const char **)
534 xrealloc (names, alloc * sizeof *names));
535 vals = ((bfd_signed_vma *)
536 xrealloc (vals, alloc * sizeof *vals));
537 }
538
539 names[count] = bfd_asymbol_name (sym);
540 vals[count] = bfd_asymbol_value (sym);
541 ++count;
542 break;
543
544 case C_EOS:
b34976b6 545 done = TRUE;
252b5132
RH
546 break;
547 }
548 }
549
550 names[count] = NULL;
551
552 return debug_make_enum_type (dhandle, names, vals);
553}
554
555/* Handle a single COFF symbol. */
556
b34976b6 557static bfd_boolean
2da42df6
AJ
558parse_coff_symbol (bfd *abfd ATTRIBUTE_UNUSED, struct coff_types *types,
559 asymbol *sym, long coff_symno,
560 struct internal_syment *psyment, void *dhandle,
561 debug_type type, bfd_boolean within_function)
252b5132
RH
562{
563 switch (psyment->n_sclass)
564 {
565 case C_NULL:
566 break;
567
568 case C_AUTO:
569 if (! debug_record_variable (dhandle, bfd_asymbol_name (sym), type,
570 DEBUG_LOCAL, bfd_asymbol_value (sym)))
b34976b6 571 return FALSE;
252b5132
RH
572 break;
573
05c58a7c 574 case C_WEAKEXT:
252b5132
RH
575 case C_EXT:
576 if (! debug_record_variable (dhandle, bfd_asymbol_name (sym), type,
577 DEBUG_GLOBAL, bfd_asymbol_value (sym)))
b34976b6 578 return FALSE;
252b5132
RH
579 break;
580
581 case C_STAT:
582 if (! debug_record_variable (dhandle, bfd_asymbol_name (sym), type,
583 (within_function
584 ? DEBUG_LOCAL_STATIC
585 : DEBUG_STATIC),
586 bfd_asymbol_value (sym)))
b34976b6 587 return FALSE;
252b5132
RH
588 break;
589
590 case C_REG:
591 /* FIXME: We may need to convert the register number. */
592 if (! debug_record_variable (dhandle, bfd_asymbol_name (sym), type,
593 DEBUG_REGISTER, bfd_asymbol_value (sym)))
b34976b6 594 return FALSE;
252b5132
RH
595 break;
596
597 case C_LABEL:
598 break;
599
600 case C_ARG:
601 if (! debug_record_parameter (dhandle, bfd_asymbol_name (sym), type,
602 DEBUG_PARM_STACK, bfd_asymbol_value (sym)))
b34976b6 603 return FALSE;
252b5132
RH
604 break;
605
606 case C_REGPARM:
607 /* FIXME: We may need to convert the register number. */
608 if (! debug_record_parameter (dhandle, bfd_asymbol_name (sym), type,
609 DEBUG_PARM_REG, bfd_asymbol_value (sym)))
b34976b6 610 return FALSE;
252b5132
RH
611 break;
612
613 case C_TPDEF:
614 type = debug_name_type (dhandle, bfd_asymbol_name (sym), type);
615 if (type == DEBUG_TYPE_NULL)
b34976b6 616 return FALSE;
252b5132
RH
617 break;
618
619 case C_STRTAG:
620 case C_UNTAG:
621 case C_ENTAG:
622 {
623 debug_type *slot;
624
625 type = debug_tag_type (dhandle, bfd_asymbol_name (sym), type);
626 if (type == DEBUG_TYPE_NULL)
b34976b6 627 return FALSE;
252b5132
RH
628
629 /* Store the named type into the slot, so that references get
630 the name. */
631 slot = coff_get_slot (types, coff_symno);
632 *slot = type;
633 }
634 break;
635
636 default:
637 break;
638 }
639
b34976b6 640 return TRUE;
252b5132
RH
641}
642
05c58a7c
NC
643/* Determine if a symbol has external visibility. */
644
b34976b6 645static bfd_boolean
2da42df6 646external_coff_symbol_p (int sym_class)
05c58a7c
NC
647{
648 switch (sym_class)
649 {
53c7db4b
KH
650 case C_EXT:
651 case C_WEAKEXT:
b34976b6 652 return TRUE;
05c58a7c
NC
653 default:
654 break;
655 }
b34976b6 656 return FALSE;
05c58a7c
NC
657}
658
252b5132
RH
659/* This is the main routine. It looks through all the symbols and
660 handles them. */
661
b34976b6 662bfd_boolean
2da42df6 663parse_coff (bfd *abfd, asymbol **syms, long symcount, void *dhandle)
252b5132
RH
664{
665 struct coff_symbols symbols;
666 struct coff_types types;
667 int i;
668 long next_c_file;
669 const char *fnname;
670 int fnclass;
671 int fntype;
672 bfd_vma fnend;
673 alent *linenos;
b34976b6 674 bfd_boolean within_function;
252b5132
RH
675 long this_coff_symno;
676
677 symbols.syms = syms;
678 symbols.symcount = symcount;
679 symbols.symno = 0;
680 symbols.coff_symno = 0;
681
682 types.slots = NULL;
683 for (i = 0; i <= T_MAX; i++)
684 types.basic[i] = DEBUG_TYPE_NULL;
685
686 next_c_file = -1;
687 fnname = NULL;
688 fnclass = 0;
689 fntype = 0;
690 fnend = 0;
691 linenos = NULL;
b34976b6 692 within_function = FALSE;
252b5132
RH
693
694 while (symbols.symno < symcount)
695 {
696 asymbol *sym;
697 const char *name;
698 struct internal_syment syment;
699 union internal_auxent auxent;
700 union internal_auxent *paux;
701 debug_type type;
702
703 sym = syms[symbols.symno];
704
705 if (! bfd_coff_get_syment (abfd, sym, &syment))
706 {
37cc8ec1
AM
707 non_fatal (_("bfd_coff_get_syment failed: %s"),
708 bfd_errmsg (bfd_get_error ()));
b34976b6 709 return FALSE;
252b5132
RH
710 }
711
712 name = bfd_asymbol_name (sym);
713
714 this_coff_symno = symbols.coff_symno;
715
716 ++symbols.symno;
717 symbols.coff_symno += 1 + syment.n_numaux;
718
719 /* We only worry about the first auxent, because that is the
720 only one which is relevant for debugging information. */
721 if (syment.n_numaux == 0)
722 paux = NULL;
723 else
724 {
725 if (! bfd_coff_get_auxent (abfd, sym, 0, &auxent))
726 {
37cc8ec1
AM
727 non_fatal (_("bfd_coff_get_auxent failed: %s"),
728 bfd_errmsg (bfd_get_error ()));
b34976b6 729 return FALSE;
252b5132
RH
730 }
731 paux = &auxent;
732 }
733
734 if (this_coff_symno == next_c_file && syment.n_sclass != C_FILE)
735 {
736 /* The last C_FILE symbol points to the first external
737 symbol. */
738 if (! debug_set_filename (dhandle, "*globals*"))
b34976b6 739 return FALSE;
252b5132
RH
740 }
741
742 switch (syment.n_sclass)
743 {
744 case C_EFCN:
745 case C_EXTDEF:
746 case C_ULABEL:
747 case C_USTATIC:
748 case C_LINE:
749 case C_ALIAS:
750 case C_HIDDEN:
751 /* Just ignore these classes. */
752 break;
753
754 case C_FILE:
755 next_c_file = syment.n_value;
756 if (! debug_set_filename (dhandle, name))
b34976b6 757 return FALSE;
252b5132
RH
758 break;
759
760 case C_STAT:
761 /* Ignore static symbols with a type of T_NULL. These
762 represent section entries. */
763 if (syment.n_type == T_NULL)
764 break;
765 /* Fall through. */
53c7db4b 766 case C_WEAKEXT:
252b5132
RH
767 case C_EXT:
768 if (ISFCN (syment.n_type))
769 {
770 fnname = name;
771 fnclass = syment.n_sclass;
772 fntype = syment.n_type;
773 if (syment.n_numaux > 0)
774 fnend = bfd_asymbol_value (sym) + auxent.x_sym.x_misc.x_fsize;
775 else
776 fnend = 0;
777 linenos = BFD_SEND (abfd, _get_lineno, (abfd, sym));
778 break;
779 }
780 type = parse_coff_type (abfd, &symbols, &types, this_coff_symno,
b34976b6 781 syment.n_type, paux, TRUE, dhandle);
252b5132 782 if (type == DEBUG_TYPE_NULL)
b34976b6 783 return FALSE;
252b5132
RH
784 if (! parse_coff_symbol (abfd, &types, sym, this_coff_symno, &syment,
785 dhandle, type, within_function))
b34976b6 786 return FALSE;
252b5132
RH
787 break;
788
789 case C_FCN:
790 if (strcmp (name, ".bf") == 0)
791 {
792 if (fnname == NULL)
793 {
37cc8ec1
AM
794 non_fatal (_("%ld: .bf without preceding function"),
795 this_coff_symno);
b34976b6 796 return FALSE;
252b5132
RH
797 }
798
799 type = parse_coff_type (abfd, &symbols, &types, this_coff_symno,
b34976b6 800 DECREF (fntype), paux, FALSE, dhandle);
252b5132 801 if (type == DEBUG_TYPE_NULL)
b34976b6 802 return FALSE;
252b5132
RH
803
804 if (! debug_record_function (dhandle, fnname, type,
05c58a7c 805 external_coff_symbol_p (fnclass),
252b5132 806 bfd_asymbol_value (sym)))
b34976b6 807 return FALSE;
252b5132
RH
808
809 if (linenos != NULL)
810 {
811 int base;
812 bfd_vma addr;
813
814 if (syment.n_numaux == 0)
815 base = 0;
816 else
817 base = auxent.x_sym.x_misc.x_lnsz.x_lnno - 1;
818
fd361982 819 addr = bfd_section_vma (bfd_asymbol_section (sym));
252b5132
RH
820
821 ++linenos;
822
823 while (linenos->line_number != 0)
824 {
825 if (! debug_record_line (dhandle,
826 linenos->line_number + base,
827 linenos->u.offset + addr))
b34976b6 828 return FALSE;
252b5132
RH
829 ++linenos;
830 }
831 }
832
833 fnname = NULL;
834 linenos = NULL;
835 fnclass = 0;
836 fntype = 0;
837
b34976b6 838 within_function = TRUE;
252b5132
RH
839 }
840 else if (strcmp (name, ".ef") == 0)
841 {
842 if (! within_function)
843 {
37cc8ec1 844 non_fatal (_("%ld: unexpected .ef\n"), this_coff_symno);
b34976b6 845 return FALSE;
252b5132
RH
846 }
847
848 if (bfd_asymbol_value (sym) > fnend)
849 fnend = bfd_asymbol_value (sym);
850 if (! debug_end_function (dhandle, fnend))
b34976b6 851 return FALSE;
252b5132
RH
852
853 fnend = 0;
b34976b6 854 within_function = FALSE;
252b5132
RH
855 }
856 break;
857
858 case C_BLOCK:
859 if (strcmp (name, ".bb") == 0)
860 {
861 if (! debug_start_block (dhandle, bfd_asymbol_value (sym)))
b34976b6 862 return FALSE;
252b5132
RH
863 }
864 else if (strcmp (name, ".eb") == 0)
865 {
866 if (! debug_end_block (dhandle, bfd_asymbol_value (sym)))
b34976b6 867 return FALSE;
252b5132
RH
868 }
869 break;
870
871 default:
872 type = parse_coff_type (abfd, &symbols, &types, this_coff_symno,
b34976b6 873 syment.n_type, paux, TRUE, dhandle);
252b5132 874 if (type == DEBUG_TYPE_NULL)
b34976b6 875 return FALSE;
252b5132
RH
876 if (! parse_coff_symbol (abfd, &types, sym, this_coff_symno, &syment,
877 dhandle, type, within_function))
b34976b6 878 return FALSE;
252b5132
RH
879 break;
880 }
881 }
882
b34976b6 883 return TRUE;
252b5132 884}
This page took 0.937147 seconds and 4 git commands to generate.