Bug Summary

File:src/gnu/usr.bin/binutils-2.17/binutils/ieee.c
Warning:line 4868, column 3
Value stored to 'nindx' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name ieee.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/binutils-2.17/obj/binutils -resource-dir /usr/local/lib/clang/13.0.0 -D HAVE_CONFIG_H -I . -I /usr/src/gnu/usr.bin/binutils-2.17/binutils -I . -D _GNU_SOURCE -I . -I /usr/src/gnu/usr.bin/binutils-2.17/binutils -I ../bfd -I /usr/src/gnu/usr.bin/binutils-2.17/binutils/../bfd -I /usr/src/gnu/usr.bin/binutils-2.17/binutils/../include -I /usr/src/gnu/usr.bin/binutils-2.17/binutils/../intl -I ../intl -D LOCALEDIR="/usr/share/locale" -D bin_dummy_emulation=bin_vanilla_emulation -D PIE_DEFAULT=1 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/gnu/usr.bin/binutils-2.17/obj/binutils -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c
1/* ieee.c -- Read and write IEEE-695 debugging information.
2 Copyright 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2006
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor <ian@cygnus.com>.
5
6 This file is part of GNU Binutils.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
21 02110-1301, USA. */
22
23/* This file reads and writes IEEE-695 debugging information. */
24
25#include <stdio.h>
26#include <assert.h>
27
28#include "bfd.h"
29#include "ieee.h"
30#include "bucomm.h"
31#include "libiberty.h"
32#include "debug.h"
33#include "budbg.h"
34#include "filenames.h"
35
36/* This structure holds an entry on the block stack. */
37
38struct ieee_block
39{
40 /* The kind of block. */
41 int kind;
42 /* The source file name, for a BB5 block. */
43 const char *filename;
44 /* The index of the function type, for a BB4 or BB6 block. */
45 unsigned int fnindx;
46 /* TRUE if this function is being skipped. */
47 bfd_boolean skip;
48};
49
50/* This structure is the block stack. */
51
52#define BLOCKSTACK_SIZE(16) (16)
53
54struct ieee_blockstack
55{
56 /* The stack pointer. */
57 struct ieee_block *bsp;
58 /* The stack. */
59 struct ieee_block stack[BLOCKSTACK_SIZE(16)];
60};
61
62/* This structure holds information for a variable. */
63
64struct ieee_var
65{
66 /* Start of name. */
67 const char *name;
68 /* Length of name. */
69 unsigned long namlen;
70 /* Type. */
71 debug_type type;
72 /* Slot if we make an indirect type. */
73 debug_type *pslot;
74 /* Kind of variable or function. */
75 enum
76 {
77 IEEE_UNKNOWN,
78 IEEE_EXTERNAL,
79 IEEE_GLOBAL,
80 IEEE_STATIC,
81 IEEE_LOCAL,
82 IEEE_FUNCTION
83 } kind;
84};
85
86/* This structure holds all the variables. */
87
88struct ieee_vars
89{
90 /* Number of slots allocated. */
91 unsigned int alloc;
92 /* Variables. */
93 struct ieee_var *vars;
94};
95
96/* This structure holds information for a type. We need this because
97 we don't want to represent bitfields as real types. */
98
99struct ieee_type
100{
101 /* Type. */
102 debug_type type;
103 /* Slot if this is type is referenced before it is defined. */
104 debug_type *pslot;
105 /* Slots for arguments if we make indirect types for them. */
106 debug_type *arg_slots;
107 /* If this is a bitfield, this is the size in bits. If this is not
108 a bitfield, this is zero. */
109 unsigned long bitsize;
110};
111
112/* This structure holds all the type information. */
113
114struct ieee_types
115{
116 /* Number of slots allocated. */
117 unsigned int alloc;
118 /* Types. */
119 struct ieee_type *types;
120 /* Builtin types. */
121#define BUILTIN_TYPE_COUNT(60) (60)
122 debug_type builtins[BUILTIN_TYPE_COUNT(60)];
123};
124
125/* This structure holds a linked last of structs with their tag names,
126 so that we can convert them to C++ classes if necessary. */
127
128struct ieee_tag
129{
130 /* Next tag. */
131 struct ieee_tag *next;
132 /* This tag name. */
133 const char *name;
134 /* The type of the tag. */
135 debug_type type;
136 /* The tagged type is an indirect type pointing at this slot. */
137 debug_type slot;
138 /* This is an array of slots used when a field type is converted
139 into a indirect type, in case it needs to be later converted into
140 a reference type. */
141 debug_type *fslots;
142};
143
144/* This structure holds the information we pass around to the parsing
145 functions. */
146
147struct ieee_info
148{
149 /* The debugging handle. */
150 void *dhandle;
151 /* The BFD. */
152 bfd *abfd;
153 /* The start of the bytes to be parsed. */
154 const bfd_byte *bytes;
155 /* The end of the bytes to be parsed. */
156 const bfd_byte *pend;
157 /* The block stack. */
158 struct ieee_blockstack blockstack;
159 /* Whether we have seen a BB1 or BB2. */
160 bfd_boolean saw_filename;
161 /* The variables. */
162 struct ieee_vars vars;
163 /* The global variables, after a global typedef block. */
164 struct ieee_vars *global_vars;
165 /* The types. */
166 struct ieee_types types;
167 /* The global types, after a global typedef block. */
168 struct ieee_types *global_types;
169 /* The list of tagged structs. */
170 struct ieee_tag *tags;
171};
172
173/* Basic builtin types, not including the pointers. */
174
175enum builtin_types
176{
177 builtin_unknown = 0,
178 builtin_void = 1,
179 builtin_signed_char = 2,
180 builtin_unsigned_char = 3,
181 builtin_signed_short_int = 4,
182 builtin_unsigned_short_int = 5,
183 builtin_signed_long = 6,
184 builtin_unsigned_long = 7,
185 builtin_signed_long_long = 8,
186 builtin_unsigned_long_long = 9,
187 builtin_float = 10,
188 builtin_double = 11,
189 builtin_long_double = 12,
190 builtin_long_long_double = 13,
191 builtin_quoted_string = 14,
192 builtin_instruction_address = 15,
193 builtin_int = 16,
194 builtin_unsigned = 17,
195 builtin_unsigned_int = 18,
196 builtin_char = 19,
197 builtin_long = 20,
198 builtin_short = 21,
199 builtin_unsigned_short = 22,
200 builtin_short_int = 23,
201 builtin_signed_short = 24,
202 builtin_bcd_float = 25
203};
204
205/* These are the values found in the derivation flags of a 'b'
206 component record of a 'T' type extension record in a C++ pmisc
207 record. These are bitmasks. */
208
209/* Set for a private base class, clear for a public base class.
210 Protected base classes are not supported. */
211#define BASEFLAGS_PRIVATE(0x1) (0x1)
212/* Set for a virtual base class. */
213#define BASEFLAGS_VIRTUAL(0x2) (0x2)
214/* Set for a friend class, clear for a base class. */
215#define BASEFLAGS_FRIEND(0x10) (0x10)
216
217/* These are the values found in the specs flags of a 'd', 'm', or 'v'
218 component record of a 'T' type extension record in a C++ pmisc
219 record. The same flags are used for a 'M' record in a C++ pmisc
220 record. */
221
222/* The lower two bits hold visibility information. */
223#define CXXFLAGS_VISIBILITY(0x3) (0x3)
224/* This value in the lower two bits indicates a public member. */
225#define CXXFLAGS_VISIBILITY_PUBLIC(0x0) (0x0)
226/* This value in the lower two bits indicates a private member. */
227#define CXXFLAGS_VISIBILITY_PRIVATE(0x1) (0x1)
228/* This value in the lower two bits indicates a protected member. */
229#define CXXFLAGS_VISIBILITY_PROTECTED(0x2) (0x2)
230/* Set for a static member. */
231#define CXXFLAGS_STATIC(0x4) (0x4)
232/* Set for a virtual override. */
233#define CXXFLAGS_OVERRIDE(0x8) (0x8)
234/* Set for a friend function. */
235#define CXXFLAGS_FRIEND(0x10) (0x10)
236/* Set for a const function. */
237#define CXXFLAGS_CONST(0x20) (0x20)
238/* Set for a volatile function. */
239#define CXXFLAGS_VOLATILE(0x40) (0x40)
240/* Set for an overloaded function. */
241#define CXXFLAGS_OVERLOADED(0x80) (0x80)
242/* Set for an operator function. */
243#define CXXFLAGS_OPERATOR(0x100) (0x100)
244/* Set for a constructor or destructor. */
245#define CXXFLAGS_CTORDTOR(0x400) (0x400)
246/* Set for a constructor. */
247#define CXXFLAGS_CTOR(0x200) (0x200)
248/* Set for an inline function. */
249#define CXXFLAGS_INLINE(0x800) (0x800)
250
251/* Local functions. */
252
253static void ieee_error (struct ieee_info *, const bfd_byte *, const char *);
254static void ieee_eof (struct ieee_info *);
255static char *savestring (const char *, unsigned long);
256static bfd_boolean ieee_read_number
257 (struct ieee_info *, const bfd_byte **, bfd_vma *);
258static bfd_boolean ieee_read_optional_number
259 (struct ieee_info *, const bfd_byte **, bfd_vma *, bfd_boolean *);
260static bfd_boolean ieee_read_id
261 (struct ieee_info *, const bfd_byte **, const char **, unsigned long *);
262static bfd_boolean ieee_read_optional_id
263 (struct ieee_info *, const bfd_byte **, const char **, unsigned long *,
264 bfd_boolean *);
265static bfd_boolean ieee_read_expression
266 (struct ieee_info *, const bfd_byte **, bfd_vma *);
267static debug_type ieee_builtin_type
268 (struct ieee_info *, const bfd_byte *, unsigned int);
269static bfd_boolean ieee_alloc_type
270 (struct ieee_info *, unsigned int, bfd_boolean);
271static bfd_boolean ieee_read_type_index
272 (struct ieee_info *, const bfd_byte **, debug_type *);
273static int ieee_regno_to_genreg (bfd *, int);
274static int ieee_genreg_to_regno (bfd *, int);
275static bfd_boolean parse_ieee_bb (struct ieee_info *, const bfd_byte **);
276static bfd_boolean parse_ieee_be (struct ieee_info *, const bfd_byte **);
277static bfd_boolean parse_ieee_nn (struct ieee_info *, const bfd_byte **);
278static bfd_boolean parse_ieee_ty (struct ieee_info *, const bfd_byte **);
279static bfd_boolean parse_ieee_atn (struct ieee_info *, const bfd_byte **);
280static bfd_boolean ieee_read_cxx_misc
281 (struct ieee_info *, const bfd_byte **, unsigned long);
282static bfd_boolean ieee_read_cxx_class
283 (struct ieee_info *, const bfd_byte **, unsigned long);
284static bfd_boolean ieee_read_cxx_defaults
285 (struct ieee_info *, const bfd_byte **, unsigned long);
286static bfd_boolean ieee_read_reference
287 (struct ieee_info *, const bfd_byte **);
288static bfd_boolean ieee_require_asn
289 (struct ieee_info *, const bfd_byte **, bfd_vma *);
290static bfd_boolean ieee_require_atn65
291 (struct ieee_info *, const bfd_byte **, const char **, unsigned long *);
292
293/* Report an error in the IEEE debugging information. */
294
295static void
296ieee_error (struct ieee_info *info, const bfd_byte *p, const char *s)
297{
298 if (p != NULL((void*)0))
299 fprintf (stderr(&__sF[2]), "%s: 0x%lx: %s (0x%x)\n", bfd_get_filename (info->abfd)((char *) (info->abfd)->filename),
300 (unsigned long) (p - info->bytes), s, *p);
301 else
302 fprintf (stderr(&__sF[2]), "%s: %s\n", bfd_get_filename (info->abfd)((char *) (info->abfd)->filename), s);
303}
304
305/* Report an unexpected EOF in the IEEE debugging information. */
306
307static void
308ieee_eof (struct ieee_info *info)
309{
310 ieee_error (info, (const bfd_byte *) NULL((void*)0),
311 _("unexpected end of debugging information")("unexpected end of debugging information"));
312}
313
314/* Save a string in memory. */
315
316static char *
317savestring (const char *start, unsigned long len)
318{
319 char *ret;
320
321 ret = (char *) xmalloc (len + 1);
322 memcpy (ret, start, len);
323 ret[len] = '\0';
324 return ret;
325}
326
327/* Read a number which must be present in an IEEE file. */
328
329static bfd_boolean
330ieee_read_number (struct ieee_info *info, const bfd_byte **pp, bfd_vma *pv)
331{
332 return ieee_read_optional_number (info, pp, pv, (bfd_boolean *) NULL((void*)0));
333}
334
335/* Read a number in an IEEE file. If ppresent is not NULL, the number
336 need not be there. */
337
338static bfd_boolean
339ieee_read_optional_number (struct ieee_info *info, const bfd_byte **pp,
340 bfd_vma *pv, bfd_boolean *ppresent)
341{
342 ieee_record_enum_type b;
343
344 if (*pp >= info->pend)
345 {
346 if (ppresent != NULL((void*)0))
347 {
348 *ppresent = FALSE0;
349 return TRUE1;
350 }
351 ieee_eof (info);
352 return FALSE0;
353 }
354
355 b = (ieee_record_enum_type) **pp;
356 ++*pp;
357
358 if (b <= ieee_number_end_enum)
359 {
360 *pv = (bfd_vma) b;
361 if (ppresent != NULL((void*)0))
362 *ppresent = TRUE1;
363 return TRUE1;
364 }
365
366 if (b >= ieee_number_repeat_start_enum && b <= ieee_number_repeat_end_enum)
367 {
368 unsigned int i;
369
370 i = (int) b - (int) ieee_number_repeat_start_enum;
371 if (*pp + i - 1 >= info->pend)
372 {
373 ieee_eof (info);
374 return FALSE0;
375 }
376
377 *pv = 0;
378 for (; i > 0; i--)
379 {
380 *pv <<= 8;
381 *pv += **pp;
382 ++*pp;
383 }
384
385 if (ppresent != NULL((void*)0))
386 *ppresent = TRUE1;
387
388 return TRUE1;
389 }
390
391 if (ppresent != NULL((void*)0))
392 {
393 --*pp;
394 *ppresent = FALSE0;
395 return TRUE1;
396 }
397
398 ieee_error (info, *pp - 1, _("invalid number")("invalid number"));
399 return FALSE0;
400}
401
402/* Read a required string from an IEEE file. */
403
404static bfd_boolean
405ieee_read_id (struct ieee_info *info, const bfd_byte **pp,
406 const char **pname, unsigned long *pnamlen)
407{
408 return ieee_read_optional_id (info, pp, pname, pnamlen, (bfd_boolean *) NULL((void*)0));
409}
410
411/* Read a string from an IEEE file. If ppresent is not NULL, the
412 string is optional. */
413
414static bfd_boolean
415ieee_read_optional_id (struct ieee_info *info, const bfd_byte **pp,
416 const char **pname, unsigned long *pnamlen,
417 bfd_boolean *ppresent)
418{
419 bfd_byte b;
420 unsigned long len;
421
422 if (*pp >= info->pend)
423 {
424 ieee_eof (info);
425 return FALSE0;
426 }
427
428 b = **pp;
429 ++*pp;
430
431 if (b <= 0x7f)
432 len = b;
433 else if ((ieee_record_enum_type) b == ieee_extension_length_1_enum)
434 {
435 len = **pp;
436 ++*pp;
437 }
438 else if ((ieee_record_enum_type) b == ieee_extension_length_2_enum)
439 {
440 len = (**pp << 8) + (*pp)[1];
441 *pp += 2;
442 }
443 else
444 {
445 if (ppresent != NULL((void*)0))
446 {
447 --*pp;
448 *ppresent = FALSE0;
449 return TRUE1;
450 }
451 ieee_error (info, *pp - 1, _("invalid string length")("invalid string length"));
452 return FALSE0;
453 }
454
455 if ((unsigned long) (info->pend - *pp) < len)
456 {
457 ieee_eof (info);
458 return FALSE0;
459 }
460
461 *pname = (const char *) *pp;
462 *pnamlen = len;
463 *pp += len;
464
465 if (ppresent != NULL((void*)0))
466 *ppresent = TRUE1;
467
468 return TRUE1;
469}
470
471/* Read an expression from an IEEE file. Since this code is only used
472 to parse debugging information, I haven't bothered to write a full
473 blown IEEE expression parser. I've only thrown in the things I've
474 seen in debugging information. This can be easily extended if
475 necessary. */
476
477static bfd_boolean
478ieee_read_expression (struct ieee_info *info, const bfd_byte **pp,
479 bfd_vma *pv)
480{
481 const bfd_byte *expr_start;
482#define EXPR_STACK_SIZE(10) (10)
483 bfd_vma expr_stack[EXPR_STACK_SIZE(10)];
484 bfd_vma *esp;
485
486 expr_start = *pp;
487
488 esp = expr_stack;
489
490 while (1)
491 {
492 const bfd_byte *start;
493 bfd_vma val;
494 bfd_boolean present;
495 ieee_record_enum_type c;
496
497 start = *pp;
498
499 if (! ieee_read_optional_number (info, pp, &val, &present))
500 return FALSE0;
501
502 if (present)
503 {
504 if (esp - expr_stack >= EXPR_STACK_SIZE(10))
505 {
506 ieee_error (info, start, _("expression stack overflow")("expression stack overflow"));
507 return FALSE0;
508 }
509 *esp++ = val;
510 continue;
511 }
512
513 c = (ieee_record_enum_type) **pp;
514
515 if (c >= ieee_module_beginning_enum)
516 break;
517
518 ++*pp;
519
520 if (c == ieee_comma)
521 break;
522
523 switch (c)
524 {
525 default:
526 ieee_error (info, start, _("unsupported IEEE expression operator")("unsupported IEEE expression operator"));
527 break;
528
529 case ieee_variable_R_enum:
530 {
531 bfd_vma indx;
532 asection *s;
533
534 if (! ieee_read_number (info, pp, &indx))
535 return FALSE0;
536 for (s = info->abfd->sections; s != NULL((void*)0); s = s->next)
537 if ((bfd_vma) s->target_index == indx)
538 break;
539 if (s == NULL((void*)0))
540 {
541 ieee_error (info, start, _("unknown section")("unknown section"));
542 return FALSE0;
543 }
544
545 if (esp - expr_stack >= EXPR_STACK_SIZE(10))
546 {
547 ieee_error (info, start, _("expression stack overflow")("expression stack overflow"));
548 return FALSE0;
549 }
550
551 *esp++ = bfd_get_section_vma (info->abfd, s)((s)->vma + 0);
552 }
553 break;
554
555 case ieee_function_plus_enum:
556 case ieee_function_minus_enum:
557 {
558 bfd_vma v1, v2;
559
560 if (esp - expr_stack < 2)
561 {
562 ieee_error (info, start, _("expression stack underflow")("expression stack underflow"));
563 return FALSE0;
564 }
565
566 v1 = *--esp;
567 v2 = *--esp;
568 *esp++ = v1 + v2;
569 }
570 break;
571 }
572 }
573
574 if (esp - 1 != expr_stack)
575 {
576 ieee_error (info, expr_start, _("expression stack mismatch")("expression stack mismatch"));
577 return FALSE0;
578 }
579
580 *pv = *--esp;
581
582 return TRUE1;
583}
584
585/* Return an IEEE builtin type. */
586
587static debug_type
588ieee_builtin_type (struct ieee_info *info, const bfd_byte *p,
589 unsigned int indx)
590{
591 void *dhandle;
592 debug_type type;
593 const char *name;
594
595 if (indx < BUILTIN_TYPE_COUNT(60)
596 && info->types.builtins[indx] != DEBUG_TYPE_NULL((debug_type) ((void*)0)))
597 return info->types.builtins[indx];
598
599 dhandle = info->dhandle;
600
601 if (indx >= 32 && indx < 64)
602 {
603 type = debug_make_pointer_type (dhandle,
604 ieee_builtin_type (info, p, indx - 32));
605 assert (indx < BUILTIN_TYPE_COUNT)((indx < (60)) ? (void)0 : __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 605, __func__, "indx < BUILTIN_TYPE_COUNT"))
;
606 info->types.builtins[indx] = type;
607 return type;
608 }
609
610 switch ((enum builtin_types) indx)
611 {
612 default:
613 ieee_error (info, p, _("unknown builtin type")("unknown builtin type"));
614 return NULL((void*)0);
615
616 case builtin_unknown:
617 type = debug_make_void_type (dhandle);
618 name = NULL((void*)0);
619 break;
620
621 case builtin_void:
622 type = debug_make_void_type (dhandle);
623 name = "void";
624 break;
625
626 case builtin_signed_char:
627 type = debug_make_int_type (dhandle, 1, FALSE0);
628 name = "signed char";
629 break;
630
631 case builtin_unsigned_char:
632 type = debug_make_int_type (dhandle, 1, TRUE1);
633 name = "unsigned char";
634 break;
635
636 case builtin_signed_short_int:
637 type = debug_make_int_type (dhandle, 2, FALSE0);
638 name = "signed short int";
639 break;
640
641 case builtin_unsigned_short_int:
642 type = debug_make_int_type (dhandle, 2, TRUE1);
643 name = "unsigned short int";
644 break;
645
646 case builtin_signed_long:
647 type = debug_make_int_type (dhandle, 4, FALSE0);
648 name = "signed long";
649 break;
650
651 case builtin_unsigned_long:
652 type = debug_make_int_type (dhandle, 4, TRUE1);
653 name = "unsigned long";
654 break;
655
656 case builtin_signed_long_long:
657 type = debug_make_int_type (dhandle, 8, FALSE0);
658 name = "signed long long";
659 break;
660
661 case builtin_unsigned_long_long:
662 type = debug_make_int_type (dhandle, 8, TRUE1);
663 name = "unsigned long long";
664 break;
665
666 case builtin_float:
667 type = debug_make_float_type (dhandle, 4);
668 name = "float";
669 break;
670
671 case builtin_double:
672 type = debug_make_float_type (dhandle, 8);
673 name = "double";
674 break;
675
676 case builtin_long_double:
677 /* FIXME: The size for this type should depend upon the
678 processor. */
679 type = debug_make_float_type (dhandle, 12);
680 name = "long double";
681 break;
682
683 case builtin_long_long_double:
684 type = debug_make_float_type (dhandle, 16);
685 name = "long long double";
686 break;
687
688 case builtin_quoted_string:
689 type = debug_make_array_type (dhandle,
690 ieee_builtin_type (info, p,
691 ((unsigned int)
692 builtin_char)),
693 ieee_builtin_type (info, p,
694 ((unsigned int)
695 builtin_int)),
696 0, -1, TRUE1);
697 name = "QUOTED STRING";
698 break;
699
700 case builtin_instruction_address:
701 /* FIXME: This should be a code address. */
702 type = debug_make_int_type (dhandle, 4, TRUE1);
703 name = "instruction address";
704 break;
705
706 case builtin_int:
707 /* FIXME: The size for this type should depend upon the
708 processor. */
709 type = debug_make_int_type (dhandle, 4, FALSE0);
710 name = "int";
711 break;
712
713 case builtin_unsigned:
714 /* FIXME: The size for this type should depend upon the
715 processor. */
716 type = debug_make_int_type (dhandle, 4, TRUE1);
717 name = "unsigned";
718 break;
719
720 case builtin_unsigned_int:
721 /* FIXME: The size for this type should depend upon the
722 processor. */
723 type = debug_make_int_type (dhandle, 4, TRUE1);
724 name = "unsigned int";
725 break;
726
727 case builtin_char:
728 type = debug_make_int_type (dhandle, 1, FALSE0);
729 name = "char";
730 break;
731
732 case builtin_long:
733 type = debug_make_int_type (dhandle, 4, FALSE0);
734 name = "long";
735 break;
736
737 case builtin_short:
738 type = debug_make_int_type (dhandle, 2, FALSE0);
739 name = "short";
740 break;
741
742 case builtin_unsigned_short:
743 type = debug_make_int_type (dhandle, 2, TRUE1);
744 name = "unsigned short";
745 break;
746
747 case builtin_short_int:
748 type = debug_make_int_type (dhandle, 2, FALSE0);
749 name = "short int";
750 break;
751
752 case builtin_signed_short:
753 type = debug_make_int_type (dhandle, 2, FALSE0);
754 name = "signed short";
755 break;
756
757 case builtin_bcd_float:
758 ieee_error (info, p, _("BCD float type not supported")("BCD float type not supported"));
759 return DEBUG_TYPE_NULL((debug_type) ((void*)0));
760 }
761
762 if (name != NULL((void*)0))
763 type = debug_name_type (dhandle, name, type);
764
765 assert (indx < BUILTIN_TYPE_COUNT)((indx < (60)) ? (void)0 : __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 765, __func__, "indx < BUILTIN_TYPE_COUNT"))
;
766
767 info->types.builtins[indx] = type;
768
769 return type;
770}
771
772/* Allocate more space in the type table. If ref is TRUE, this is a
773 reference to the type; if it is not already defined, we should set
774 up an indirect type. */
775
776static bfd_boolean
777ieee_alloc_type (struct ieee_info *info, unsigned int indx, bfd_boolean ref)
778{
779 unsigned int nalloc;
780 register struct ieee_type *t;
781 struct ieee_type *tend;
782
783 if (indx >= info->types.alloc)
784 {
785 nalloc = info->types.alloc;
786 if (nalloc == 0)
787 nalloc = 4;
788 while (indx >= nalloc)
789 nalloc *= 2;
790
791 info->types.types = ((struct ieee_type *)
792 xrealloc (info->types.types,
793 nalloc * sizeof *info->types.types));
794
795 memset (info->types.types + info->types.alloc, 0,
796 (nalloc - info->types.alloc) * sizeof *info->types.types);
797
798 tend = info->types.types + nalloc;
799 for (t = info->types.types + info->types.alloc; t < tend; t++)
800 t->type = DEBUG_TYPE_NULL((debug_type) ((void*)0));
801
802 info->types.alloc = nalloc;
803 }
804
805 if (ref)
806 {
807 t = info->types.types + indx;
808 if (t->type == NULL((void*)0))
809 {
810 t->pslot = (debug_type *) xmalloc (sizeof *t->pslot);
811 *t->pslot = DEBUG_TYPE_NULL((debug_type) ((void*)0));
812 t->type = debug_make_indirect_type (info->dhandle, t->pslot,
813 (const char *) NULL((void*)0));
814 if (t->type == NULL((void*)0))
815 return FALSE0;
816 }
817 }
818
819 return TRUE1;
820}
821
822/* Read a type index and return the corresponding type. */
823
824static bfd_boolean
825ieee_read_type_index (struct ieee_info *info, const bfd_byte **pp,
826 debug_type *ptype)
827{
828 const bfd_byte *start;
829 bfd_vma indx;
830
831 start = *pp;
832
833 if (! ieee_read_number (info, pp, &indx))
834 return FALSE0;
835
836 if (indx < 256)
837 {
838 *ptype = ieee_builtin_type (info, start, indx);
839 if (*ptype == NULL((void*)0))
840 return FALSE0;
841 return TRUE1;
842 }
843
844 indx -= 256;
845 if (! ieee_alloc_type (info, indx, TRUE1))
846 return FALSE0;
847
848 *ptype = info->types.types[indx].type;
849
850 return TRUE1;
851}
852
853/* Parse IEEE debugging information for a file. This is passed the
854 bytes which compose the Debug Information Part of an IEEE file. */
855
856bfd_boolean
857parse_ieee (void *dhandle, bfd *abfd, const bfd_byte *bytes, bfd_size_type len)
858{
859 struct ieee_info info;
860 unsigned int i;
861 const bfd_byte *p, *pend;
862
863 info.dhandle = dhandle;
864 info.abfd = abfd;
865 info.bytes = bytes;
866 info.pend = bytes + len;
867 info.blockstack.bsp = info.blockstack.stack;
868 info.saw_filename = FALSE0;
869 info.vars.alloc = 0;
870 info.vars.vars = NULL((void*)0);
871 info.global_vars = NULL((void*)0);
872 info.types.alloc = 0;
873 info.types.types = NULL((void*)0);
874 info.global_types = NULL((void*)0);
875 info.tags = NULL((void*)0);
876 for (i = 0; i < BUILTIN_TYPE_COUNT(60); i++)
877 info.types.builtins[i] = DEBUG_TYPE_NULL((debug_type) ((void*)0));
878
879 p = bytes;
880 pend = info.pend;
881 while (p < pend)
882 {
883 const bfd_byte *record_start;
884 ieee_record_enum_type c;
885
886 record_start = p;
887
888 c = (ieee_record_enum_type) *p++;
889
890 if (c == ieee_at_record_enum)
891 c = (ieee_record_enum_type) (((unsigned int) c << 8) | *p++);
892
893 if (c <= ieee_number_repeat_end_enum)
894 {
895 ieee_error (&info, record_start, _("unexpected number")("unexpected number"));
896 return FALSE0;
897 }
898
899 switch (c)
900 {
901 default:
902 ieee_error (&info, record_start, _("unexpected record type")("unexpected record type"));
903 return FALSE0;
904
905 case ieee_bb_record_enum:
906 if (! parse_ieee_bb (&info, &p))
907 return FALSE0;
908 break;
909
910 case ieee_be_record_enum:
911 if (! parse_ieee_be (&info, &p))
912 return FALSE0;
913 break;
914
915 case ieee_nn_record:
916 if (! parse_ieee_nn (&info, &p))
917 return FALSE0;
918 break;
919
920 case ieee_ty_record_enum:
921 if (! parse_ieee_ty (&info, &p))
922 return FALSE0;
923 break;
924
925 case ieee_atn_record_enum:
926 if (! parse_ieee_atn (&info, &p))
927 return FALSE0;
928 break;
929 }
930 }
931
932 if (info.blockstack.bsp != info.blockstack.stack)
933 {
934 ieee_error (&info, (const bfd_byte *) NULL((void*)0),
935 _("blocks left on stack at end")("blocks left on stack at end"));
936 return FALSE0;
937 }
938
939 return TRUE1;
940}
941
942/* Handle an IEEE BB record. */
943
944static bfd_boolean
945parse_ieee_bb (struct ieee_info *info, const bfd_byte **pp)
946{
947 const bfd_byte *block_start;
948 bfd_byte b;
949 bfd_vma size;
950 const char *name;
951 unsigned long namlen;
952 char *namcopy = NULL((void*)0);
953 unsigned int fnindx;
954 bfd_boolean skip;
955
956 block_start = *pp;
957
958 b = **pp;
959 ++*pp;
960
961 if (! ieee_read_number (info, pp, &size)
962 || ! ieee_read_id (info, pp, &name, &namlen))
963 return FALSE0;
964
965 fnindx = (unsigned int) -1;
966 skip = FALSE0;
967
968 switch (b)
969 {
970 case 1:
971 /* BB1: Type definitions local to a module. */
972 namcopy = savestring (name, namlen);
973 if (namcopy == NULL((void*)0))
974 return FALSE0;
975 if (! debug_set_filename (info->dhandle, namcopy))
976 return FALSE0;
977 info->saw_filename = TRUE1;
978
979 /* Discard any variables or types we may have seen before. */
980 if (info->vars.vars != NULL((void*)0))
981 free (info->vars.vars);
982 info->vars.vars = NULL((void*)0);
983 info->vars.alloc = 0;
984 if (info->types.types != NULL((void*)0))
985 free (info->types.types);
986 info->types.types = NULL((void*)0);
987 info->types.alloc = 0;
988
989 /* Initialize the types to the global types. */
990 if (info->global_types != NULL((void*)0))
991 {
992 info->types.alloc = info->global_types->alloc;
993 info->types.types = ((struct ieee_type *)
994 xmalloc (info->types.alloc
995 * sizeof (*info->types.types)));
996 memcpy (info->types.types, info->global_types->types,
997 info->types.alloc * sizeof (*info->types.types));
998 }
999
1000 break;
1001
1002 case 2:
1003 /* BB2: Global type definitions. The name is supposed to be
1004 empty, but we don't check. */
1005 if (! debug_set_filename (info->dhandle, "*global*"))
1006 return FALSE0;
1007 info->saw_filename = TRUE1;
1008 break;
1009
1010 case 3:
1011 /* BB3: High level module block begin. We don't have to do
1012 anything here. The name is supposed to be the same as for
1013 the BB1, but we don't check. */
1014 break;
1015
1016 case 4:
1017 /* BB4: Global function. */
1018 {
1019 bfd_vma stackspace, typindx, offset;
1020 debug_type return_type;
1021
1022 if (! ieee_read_number (info, pp, &stackspace)
1023 || ! ieee_read_number (info, pp, &typindx)
1024 || ! ieee_read_expression (info, pp, &offset))
1025 return FALSE0;
1026
1027 /* We have no way to record the stack space. FIXME. */
1028
1029 if (typindx < 256)
1030 {
1031 return_type = ieee_builtin_type (info, block_start, typindx);
1032 if (return_type == DEBUG_TYPE_NULL((debug_type) ((void*)0)))
1033 return FALSE0;
1034 }
1035 else
1036 {
1037 typindx -= 256;
1038 if (! ieee_alloc_type (info, typindx, TRUE1))
1039 return FALSE0;
1040 fnindx = typindx;
1041 return_type = info->types.types[typindx].type;
1042 if (debug_get_type_kind (info->dhandle, return_type)
1043 == DEBUG_KIND_FUNCTION)
1044 return_type = debug_get_return_type (info->dhandle,
1045 return_type);
1046 }
1047
1048 namcopy = savestring (name, namlen);
1049 if (namcopy == NULL((void*)0))
1050 return FALSE0;
1051 if (! debug_record_function (info->dhandle, namcopy, return_type,
1052 TRUE1, offset))
1053 return FALSE0;
1054 }
1055 break;
1056
1057 case 5:
1058 /* BB5: File name for source line numbers. */
1059 {
1060 unsigned int i;
1061
1062 /* We ignore the date and time. FIXME. */
1063 for (i = 0; i < 6; i++)
1064 {
1065 bfd_vma ignore;
1066 bfd_boolean present;
1067
1068 if (! ieee_read_optional_number (info, pp, &ignore, &present))
1069 return FALSE0;
1070 if (! present)
1071 break;
1072 }
1073
1074 namcopy = savestring (name, namlen);
1075 if (namcopy == NULL((void*)0))
1076 return FALSE0;
1077 if (! debug_start_source (info->dhandle, namcopy))
1078 return FALSE0;
1079 }
1080 break;
1081
1082 case 6:
1083 /* BB6: Local function or block. */
1084 {
1085 bfd_vma stackspace, typindx, offset;
1086
1087 if (! ieee_read_number (info, pp, &stackspace)
1088 || ! ieee_read_number (info, pp, &typindx)
1089 || ! ieee_read_expression (info, pp, &offset))
1090 return FALSE0;
1091
1092 /* We have no way to record the stack space. FIXME. */
1093
1094 if (namlen == 0)
1095 {
1096 if (! debug_start_block (info->dhandle, offset))
1097 return FALSE0;
1098 /* Change b to indicate that this is a block
1099 rather than a function. */
1100 b = 0x86;
1101 }
1102 else
1103 {
1104 /* The MRI C++ compiler will output a fake function named
1105 __XRYCPP to hold C++ debugging information. We skip
1106 that function. This is not crucial, but it makes
1107 converting from IEEE to other debug formats work
1108 better. */
1109 if (strncmp (name, "__XRYCPP", namlen) == 0)
1110 skip = TRUE1;
1111 else
1112 {
1113 debug_type return_type;
1114
1115 if (typindx < 256)
1116 {
1117 return_type = ieee_builtin_type (info, block_start,
1118 typindx);
1119 if (return_type == NULL((void*)0))
1120 return FALSE0;
1121 }
1122 else
1123 {
1124 typindx -= 256;
1125 if (! ieee_alloc_type (info, typindx, TRUE1))
1126 return FALSE0;
1127 fnindx = typindx;
1128 return_type = info->types.types[typindx].type;
1129 if (debug_get_type_kind (info->dhandle, return_type)
1130 == DEBUG_KIND_FUNCTION)
1131 return_type = debug_get_return_type (info->dhandle,
1132 return_type);
1133 }
1134
1135 namcopy = savestring (name, namlen);
1136 if (namcopy == NULL((void*)0))
1137 return FALSE0;
1138 if (! debug_record_function (info->dhandle, namcopy,
1139 return_type, FALSE0, offset))
1140 return FALSE0;
1141 }
1142 }
1143 }
1144 break;
1145
1146 case 10:
1147 /* BB10: Assembler module scope. In the normal case, we
1148 completely ignore all this information. FIXME. */
1149 {
1150 const char *inam, *vstr;
1151 unsigned long inamlen, vstrlen;
1152 bfd_vma tool_type;
1153 bfd_boolean present;
1154 unsigned int i;
1155
1156 if (! info->saw_filename)
1157 {
1158 namcopy = savestring (name, namlen);
1159 if (namcopy == NULL((void*)0))
1160 return FALSE0;
1161 if (! debug_set_filename (info->dhandle, namcopy))
1162 return FALSE0;
1163 info->saw_filename = TRUE1;
1164 }
1165
1166 if (! ieee_read_id (info, pp, &inam, &inamlen)
1167 || ! ieee_read_number (info, pp, &tool_type)
1168 || ! ieee_read_optional_id (info, pp, &vstr, &vstrlen, &present))
1169 return FALSE0;
1170 for (i = 0; i < 6; i++)
1171 {
1172 bfd_vma ignore;
1173
1174 if (! ieee_read_optional_number (info, pp, &ignore, &present))
1175 return FALSE0;
1176 if (! present)
1177 break;
1178 }
1179 }
1180 break;
1181
1182 case 11:
1183 /* BB11: Module section. We completely ignore all this
1184 information. FIXME. */
1185 {
1186 bfd_vma sectype, secindx, offset, map;
1187 bfd_boolean present;
1188
1189 if (! ieee_read_number (info, pp, &sectype)
1190 || ! ieee_read_number (info, pp, &secindx)
1191 || ! ieee_read_expression (info, pp, &offset)
1192 || ! ieee_read_optional_number (info, pp, &map, &present))
1193 return FALSE0;
1194 }
1195 break;
1196
1197 default:
1198 ieee_error (info, block_start, _("unknown BB type")("unknown BB type"));
1199 return FALSE0;
1200 }
1201
1202
1203 /* Push this block on the block stack. */
1204
1205 if (info->blockstack.bsp >= info->blockstack.stack + BLOCKSTACK_SIZE(16))
1206 {
1207 ieee_error (info, (const bfd_byte *) NULL((void*)0), _("stack overflow")("stack overflow"));
1208 return FALSE0;
1209 }
1210
1211 info->blockstack.bsp->kind = b;
1212 if (b == 5)
1213 info->blockstack.bsp->filename = namcopy;
1214 info->blockstack.bsp->fnindx = fnindx;
1215 info->blockstack.bsp->skip = skip;
1216 ++info->blockstack.bsp;
1217
1218 return TRUE1;
1219}
1220
1221/* Handle an IEEE BE record. */
1222
1223static bfd_boolean
1224parse_ieee_be (struct ieee_info *info, const bfd_byte **pp)
1225{
1226 bfd_vma offset;
1227
1228 if (info->blockstack.bsp <= info->blockstack.stack)
1229 {
1230 ieee_error (info, *pp, _("stack underflow")("stack underflow"));
1231 return FALSE0;
1232 }
1233 --info->blockstack.bsp;
1234
1235 switch (info->blockstack.bsp->kind)
1236 {
1237 case 2:
1238 /* When we end the global typedefs block, we copy out the
1239 contents of info->vars. This is because the variable indices
1240 may be reused in the local blocks. However, we need to
1241 preserve them so that we can locate a function returning a
1242 reference variable whose type is named in the global typedef
1243 block. */
1244 info->global_vars = ((struct ieee_vars *)
1245 xmalloc (sizeof *info->global_vars));
1246 info->global_vars->alloc = info->vars.alloc;
1247 info->global_vars->vars = ((struct ieee_var *)
1248 xmalloc (info->vars.alloc
1249 * sizeof (*info->vars.vars)));
1250 memcpy (info->global_vars->vars, info->vars.vars,
1251 info->vars.alloc * sizeof (*info->vars.vars));
1252
1253 /* We also copy out the non builtin parts of info->types, since
1254 the types are discarded when we start a new block. */
1255 info->global_types = ((struct ieee_types *)
1256 xmalloc (sizeof *info->global_types));
1257 info->global_types->alloc = info->types.alloc;
1258 info->global_types->types = ((struct ieee_type *)
1259 xmalloc (info->types.alloc
1260 * sizeof (*info->types.types)));
1261 memcpy (info->global_types->types, info->types.types,
1262 info->types.alloc * sizeof (*info->types.types));
1263 memset (info->global_types->builtins, 0,
1264 sizeof (info->global_types->builtins));
1265
1266 break;
1267
1268 case 4:
1269 case 6:
1270 if (! ieee_read_expression (info, pp, &offset))
1271 return FALSE0;
1272 if (! info->blockstack.bsp->skip)
1273 {
1274 if (! debug_end_function (info->dhandle, offset + 1))
1275 return FALSE0;
1276 }
1277 break;
1278
1279 case 0x86:
1280 /* This is BE6 when BB6 started a block rather than a local
1281 function. */
1282 if (! ieee_read_expression (info, pp, &offset))
1283 return FALSE0;
1284 if (! debug_end_block (info->dhandle, offset + 1))
1285 return FALSE0;
1286 break;
1287
1288 case 5:
1289 /* When we end a BB5, we look up the stack for the last BB5, if
1290 there is one, so that we can call debug_start_source. */
1291 if (info->blockstack.bsp > info->blockstack.stack)
1292 {
1293 struct ieee_block *bl;
1294
1295 bl = info->blockstack.bsp;
1296 do
1297 {
1298 --bl;
1299 if (bl->kind == 5)
1300 {
1301 if (! debug_start_source (info->dhandle, bl->filename))
1302 return FALSE0;
1303 break;
1304 }
1305 }
1306 while (bl != info->blockstack.stack);
1307 }
1308 break;
1309
1310 case 11:
1311 if (! ieee_read_expression (info, pp, &offset))
1312 return FALSE0;
1313 /* We just ignore the module size. FIXME. */
1314 break;
1315
1316 default:
1317 /* Other block types do not have any trailing information. */
1318 break;
1319 }
1320
1321 return TRUE1;
1322}
1323
1324/* Parse an NN record. */
1325
1326static bfd_boolean
1327parse_ieee_nn (struct ieee_info *info, const bfd_byte **pp)
1328{
1329 const bfd_byte *nn_start;
1330 bfd_vma varindx;
1331 const char *name;
1332 unsigned long namlen;
1333
1334 nn_start = *pp;
1335
1336 if (! ieee_read_number (info, pp, &varindx)
1337 || ! ieee_read_id (info, pp, &name, &namlen))
1338 return FALSE0;
1339
1340 if (varindx < 32)
1341 {
1342 ieee_error (info, nn_start, _("illegal variable index")("illegal variable index"));
1343 return FALSE0;
1344 }
1345 varindx -= 32;
1346
1347 if (varindx >= info->vars.alloc)
1348 {
1349 unsigned int alloc;
1350
1351 alloc = info->vars.alloc;
1352 if (alloc == 0)
1353 alloc = 4;
1354 while (varindx >= alloc)
1355 alloc *= 2;
1356 info->vars.vars = ((struct ieee_var *)
1357 xrealloc (info->vars.vars,
1358 alloc * sizeof *info->vars.vars));
1359 memset (info->vars.vars + info->vars.alloc, 0,
1360 (alloc - info->vars.alloc) * sizeof *info->vars.vars);
1361 info->vars.alloc = alloc;
1362 }
1363
1364 info->vars.vars[varindx].name = name;
1365 info->vars.vars[varindx].namlen = namlen;
1366
1367 return TRUE1;
1368}
1369
1370/* Parse a TY record. */
1371
1372static bfd_boolean
1373parse_ieee_ty (struct ieee_info *info, const bfd_byte **pp)
1374{
1375 const bfd_byte *ty_start, *ty_var_start, *ty_code_start;
1376 bfd_vma typeindx, varindx, tc;
1377 void *dhandle;
1378 bfd_boolean tag, typdef;
1379 debug_type *arg_slots;
1380 unsigned long type_bitsize;
1381 debug_type type;
1382
1383 ty_start = *pp;
1384
1385 if (! ieee_read_number (info, pp, &typeindx))
1386 return FALSE0;
1387
1388 if (typeindx < 256)
1389 {
1390 ieee_error (info, ty_start, _("illegal type index")("illegal type index"));
1391 return FALSE0;
1392 }
1393
1394 typeindx -= 256;
1395 if (! ieee_alloc_type (info, typeindx, FALSE0))
1396 return FALSE0;
1397
1398 if (**pp != 0xce)
1399 {
1400 ieee_error (info, *pp, _("unknown TY code")("unknown TY code"));
1401 return FALSE0;
1402 }
1403 ++*pp;
1404
1405 ty_var_start = *pp;
1406
1407 if (! ieee_read_number (info, pp, &varindx))
1408 return FALSE0;
1409
1410 if (varindx < 32)
1411 {
1412 ieee_error (info, ty_var_start, _("illegal variable index")("illegal variable index"));
1413 return FALSE0;
1414 }
1415 varindx -= 32;
1416
1417 if (varindx >= info->vars.alloc || info->vars.vars[varindx].name == NULL((void*)0))
1418 {
1419 ieee_error (info, ty_var_start, _("undefined variable in TY")("undefined variable in TY"));
1420 return FALSE0;
1421 }
1422
1423 ty_code_start = *pp;
1424
1425 if (! ieee_read_number (info, pp, &tc))
1426 return FALSE0;
1427
1428 dhandle = info->dhandle;
1429
1430 tag = FALSE0;
1431 typdef = FALSE0;
1432 arg_slots = NULL((void*)0);
1433 type_bitsize = 0;
1434 switch (tc)
1435 {
1436 default:
1437 ieee_error (info, ty_code_start, _("unknown TY code")("unknown TY code"));
1438 return FALSE0;
1439
1440 case '!':
1441 /* Unknown type, with size. We treat it as int. FIXME. */
1442 {
1443 bfd_vma size;
1444
1445 if (! ieee_read_number (info, pp, &size))
1446 return FALSE0;
1447 type = debug_make_int_type (dhandle, size, FALSE0);
1448 }
1449 break;
1450
1451 case 'A': /* Array. */
1452 case 'a': /* FORTRAN array in column/row order. FIXME: Not
1453 distinguished from normal array. */
1454 {
1455 debug_type ele_type;
1456 bfd_vma lower, upper;
1457
1458 if (! ieee_read_type_index (info, pp, &ele_type)
1459 || ! ieee_read_number (info, pp, &lower)
1460 || ! ieee_read_number (info, pp, &upper))
1461 return FALSE0;
1462 type = debug_make_array_type (dhandle, ele_type,
1463 ieee_builtin_type (info, ty_code_start,
1464 ((unsigned int)
1465 builtin_int)),
1466 (bfd_signed_vma) lower,
1467 (bfd_signed_vma) upper,
1468 FALSE0);
1469 }
1470 break;
1471
1472 case 'E':
1473 /* Simple enumeration. */
1474 {
1475 bfd_vma size;
1476 unsigned int alloc;
1477 const char **names;
1478 unsigned int c;
1479 bfd_signed_vma *vals;
1480 unsigned int i;
1481
1482 if (! ieee_read_number (info, pp, &size))
1483 return FALSE0;
1484 /* FIXME: we ignore the enumeration size. */
1485
1486 alloc = 10;
1487 names = (const char **) xmalloc (alloc * sizeof *names);
1488 memset (names, 0, alloc * sizeof *names);
1489 c = 0;
1490 while (1)
1491 {
1492 const char *name;
1493 unsigned long namlen;
1494 bfd_boolean present;
1495
1496 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1497 return FALSE0;
1498 if (! present)
1499 break;
1500
1501 if (c + 1 >= alloc)
1502 {
1503 alloc += 10;
1504 names = ((const char **)
1505 xrealloc (names, alloc * sizeof *names));
1506 }
1507
1508 names[c] = savestring (name, namlen);
1509 if (names[c] == NULL((void*)0))
1510 return FALSE0;
1511 ++c;
1512 }
1513
1514 names[c] = NULL((void*)0);
1515
1516 vals = (bfd_signed_vma *) xmalloc (c * sizeof *vals);
1517 for (i = 0; i < c; i++)
1518 vals[i] = i;
1519
1520 type = debug_make_enum_type (dhandle, names, vals);
1521 tag = TRUE1;
1522 }
1523 break;
1524
1525 case 'G':
1526 /* Struct with bit fields. */
1527 {
1528 bfd_vma size;
1529 unsigned int alloc;
1530 debug_field *fields;
1531 unsigned int c;
1532
1533 if (! ieee_read_number (info, pp, &size))
1534 return FALSE0;
1535
1536 alloc = 10;
1537 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
1538 c = 0;
1539 while (1)
1540 {
1541 const char *name;
1542 unsigned long namlen;
1543 bfd_boolean present;
1544 debug_type ftype;
1545 bfd_vma bitpos, bitsize;
1546
1547 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1548 return FALSE0;
1549 if (! present)
1550 break;
1551 if (! ieee_read_type_index (info, pp, &ftype)
1552 || ! ieee_read_number (info, pp, &bitpos)
1553 || ! ieee_read_number (info, pp, &bitsize))
1554 return FALSE0;
1555
1556 if (c + 1 >= alloc)
1557 {
1558 alloc += 10;
1559 fields = ((debug_field *)
1560 xrealloc (fields, alloc * sizeof *fields));
1561 }
1562
1563 fields[c] = debug_make_field (dhandle, savestring (name, namlen),
1564 ftype, bitpos, bitsize,
1565 DEBUG_VISIBILITY_PUBLIC);
1566 if (fields[c] == NULL((void*)0))
1567 return FALSE0;
1568 ++c;
1569 }
1570
1571 fields[c] = NULL((void*)0);
1572
1573 type = debug_make_struct_type (dhandle, TRUE1, size, fields);
1574 tag = TRUE1;
1575 }
1576 break;
1577
1578 case 'N':
1579 /* Enumeration. */
1580 {
1581 unsigned int alloc;
1582 const char **names;
1583 bfd_signed_vma *vals;
1584 unsigned int c;
1585
1586 alloc = 10;
1587 names = (const char **) xmalloc (alloc * sizeof *names);
1588 vals = (bfd_signed_vma *) xmalloc (alloc * sizeof *names);
1589 c = 0;
1590 while (1)
1591 {
1592 const char *name;
1593 unsigned long namlen;
1594 bfd_boolean present;
1595 bfd_vma val;
1596
1597 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1598 return FALSE0;
1599 if (! present)
1600 break;
1601 if (! ieee_read_number (info, pp, &val))
1602 return FALSE0;
1603
1604 /* If the length of the name is zero, then the value is
1605 actually the size of the enum. We ignore this
1606 information. FIXME. */
1607 if (namlen == 0)
1608 continue;
1609
1610 if (c + 1 >= alloc)
1611 {
1612 alloc += 10;
1613 names = ((const char **)
1614 xrealloc (names, alloc * sizeof *names));
1615 vals = ((bfd_signed_vma *)
1616 xrealloc (vals, alloc * sizeof *vals));
1617 }
1618
1619 names[c] = savestring (name, namlen);
1620 if (names[c] == NULL((void*)0))
1621 return FALSE0;
1622 vals[c] = (bfd_signed_vma) val;
1623 ++c;
1624 }
1625
1626 names[c] = NULL((void*)0);
1627
1628 type = debug_make_enum_type (dhandle, names, vals);
1629 tag = TRUE1;
1630 }
1631 break;
1632
1633 case 'O': /* Small pointer. We don't distinguish small and large
1634 pointers. FIXME. */
1635 case 'P': /* Large pointer. */
1636 {
1637 debug_type t;
1638
1639 if (! ieee_read_type_index (info, pp, &t))
1640 return FALSE0;
1641 type = debug_make_pointer_type (dhandle, t);
1642 }
1643 break;
1644
1645 case 'R':
1646 /* Range. */
1647 {
1648 bfd_vma low, high, signedp, size;
1649
1650 if (! ieee_read_number (info, pp, &low)
1651 || ! ieee_read_number (info, pp, &high)
1652 || ! ieee_read_number (info, pp, &signedp)
1653 || ! ieee_read_number (info, pp, &size))
1654 return FALSE0;
1655
1656 type = debug_make_range_type (dhandle,
1657 debug_make_int_type (dhandle, size,
1658 ! signedp),
1659 (bfd_signed_vma) low,
1660 (bfd_signed_vma) high);
1661 }
1662 break;
1663
1664 case 'S': /* Struct. */
1665 case 'U': /* Union. */
1666 {
1667 bfd_vma size;
1668 unsigned int alloc;
1669 debug_field *fields;
1670 unsigned int c;
1671
1672 if (! ieee_read_number (info, pp, &size))
1673 return FALSE0;
1674
1675 alloc = 10;
1676 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
1677 c = 0;
1678 while (1)
1679 {
1680 const char *name;
1681 unsigned long namlen;
1682 bfd_boolean present;
1683 bfd_vma tindx;
1684 bfd_vma offset;
1685 debug_type ftype;
1686 bfd_vma bitsize;
1687
1688 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1689 return FALSE0;
1690 if (! present)
1691 break;
1692 if (! ieee_read_number (info, pp, &tindx)
1693 || ! ieee_read_number (info, pp, &offset))
1694 return FALSE0;
1695
1696 if (tindx < 256)
1697 {
1698 ftype = ieee_builtin_type (info, ty_code_start, tindx);
1699 bitsize = 0;
1700 offset *= 8;
1701 }
1702 else
1703 {
1704 struct ieee_type *t;
1705
1706 tindx -= 256;
1707 if (! ieee_alloc_type (info, tindx, TRUE1))
1708 return FALSE0;
1709 t = info->types.types + tindx;
1710 ftype = t->type;
1711 bitsize = t->bitsize;
1712 if (bitsize == 0)
1713 offset *= 8;
1714 }
1715
1716 if (c + 1 >= alloc)
1717 {
1718 alloc += 10;
1719 fields = ((debug_field *)
1720 xrealloc (fields, alloc * sizeof *fields));
1721 }
1722
1723 fields[c] = debug_make_field (dhandle, savestring (name, namlen),
1724 ftype, offset, bitsize,
1725 DEBUG_VISIBILITY_PUBLIC);
1726 if (fields[c] == NULL((void*)0))
1727 return FALSE0;
1728 ++c;
1729 }
1730
1731 fields[c] = NULL((void*)0);
1732
1733 type = debug_make_struct_type (dhandle, tc == 'S', size, fields);
1734 tag = TRUE1;
1735 }
1736 break;
1737
1738 case 'T':
1739 /* Typedef. */
1740 if (! ieee_read_type_index (info, pp, &type))
1741 return FALSE0;
1742 typdef = TRUE1;
1743 break;
1744
1745 case 'X':
1746 /* Procedure. FIXME: This is an extern declaration, which we
1747 have no way of representing. */
1748 {
1749 bfd_vma attr;
1750 debug_type rtype;
1751 bfd_vma nargs;
1752 bfd_boolean present;
1753 struct ieee_var *pv;
1754
1755 /* FIXME: We ignore the attribute and the argument names. */
1756
1757 if (! ieee_read_number (info, pp, &attr)
1758 || ! ieee_read_type_index (info, pp, &rtype)
1759 || ! ieee_read_number (info, pp, &nargs))
1760 return FALSE0;
1761 do
1762 {
1763 const char *name;
1764 unsigned long namlen;
1765
1766 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1767 return FALSE0;
1768 }
1769 while (present);
1770
1771 pv = info->vars.vars + varindx;
1772 pv->kind = IEEE_EXTERNAL;
1773 if (pv->namlen > 0
1774 && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER)
1775 {
1776 /* Set up the return type as an indirect type pointing to
1777 the variable slot, so that we can change it to a
1778 reference later if appropriate. */
1779 pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot);
1780 *pv->pslot = rtype;
1781 rtype = debug_make_indirect_type (dhandle, pv->pslot,
1782 (const char *) NULL((void*)0));
1783 }
1784
1785 type = debug_make_function_type (dhandle, rtype, (debug_type *) NULL((void*)0),
1786 FALSE0);
1787 }
1788 break;
1789
1790 case 'V':
1791 /* Void. This is not documented, but the MRI compiler emits it. */
1792 type = debug_make_void_type (dhandle);
1793 break;
1794
1795 case 'Z':
1796 /* Array with 0 lower bound. */
1797 {
1798 debug_type etype;
1799 bfd_vma high;
1800
1801 if (! ieee_read_type_index (info, pp, &etype)
1802 || ! ieee_read_number (info, pp, &high))
1803 return FALSE0;
1804
1805 type = debug_make_array_type (dhandle, etype,
1806 ieee_builtin_type (info, ty_code_start,
1807 ((unsigned int)
1808 builtin_int)),
1809 0, (bfd_signed_vma) high, FALSE0);
1810 }
1811 break;
1812
1813 case 'c': /* Complex. */
1814 case 'd': /* Double complex. */
1815 {
1816 const char *name;
1817 unsigned long namlen;
1818
1819 /* FIXME: I don't know what the name means. */
1820
1821 if (! ieee_read_id (info, pp, &name, &namlen))
1822 return FALSE0;
1823
1824 type = debug_make_complex_type (dhandle, tc == 'c' ? 4 : 8);
1825 }
1826 break;
1827
1828 case 'f':
1829 /* Pascal file name. FIXME. */
1830 ieee_error (info, ty_code_start, _("Pascal file name not supported")("Pascal file name not supported"));
1831 return FALSE0;
1832
1833 case 'g':
1834 /* Bitfield type. */
1835 {
1836 bfd_vma signedp, bitsize, dummy;
1837 const bfd_byte *hold;
1838 bfd_boolean present;
1839
1840 if (! ieee_read_number (info, pp, &signedp)
1841 || ! ieee_read_number (info, pp, &bitsize))
1842 return FALSE0;
1843
1844 /* I think the documentation says that there is a type index,
1845 but some actual files do not have one. */
1846 hold = *pp;
1847 if (! ieee_read_optional_number (info, pp, &dummy, &present))
1848 return FALSE0;
1849 if (! present)
1850 {
1851 /* FIXME: This is just a guess. */
1852 type = debug_make_int_type (dhandle, 4,
1853 signedp ? FALSE0 : TRUE1);
1854 }
1855 else
1856 {
1857 *pp = hold;
1858 if (! ieee_read_type_index (info, pp, &type))
1859 return FALSE0;
1860 }
1861 type_bitsize = bitsize;
1862 }
1863 break;
1864
1865 case 'n':
1866 /* Qualifier. */
1867 {
1868 bfd_vma kind;
1869 debug_type t;
1870
1871 if (! ieee_read_number (info, pp, &kind)
1872 || ! ieee_read_type_index (info, pp, &t))
1873 return FALSE0;
1874
1875 switch (kind)
1876 {
1877 default:
1878 ieee_error (info, ty_start, _("unsupported qualifier")("unsupported qualifier"));
1879 return FALSE0;
1880
1881 case 1:
1882 type = debug_make_const_type (dhandle, t);
1883 break;
1884
1885 case 2:
1886 type = debug_make_volatile_type (dhandle, t);
1887 break;
1888 }
1889 }
1890 break;
1891
1892 case 's':
1893 /* Set. */
1894 {
1895 bfd_vma size;
1896 debug_type etype;
1897
1898 if (! ieee_read_number (info, pp, &size)
1899 || ! ieee_read_type_index (info, pp, &etype))
1900 return FALSE0;
1901
1902 /* FIXME: We ignore the size. */
1903
1904 type = debug_make_set_type (dhandle, etype, FALSE0);
1905 }
1906 break;
1907
1908 case 'x':
1909 /* Procedure with compiler dependencies. */
1910 {
1911 struct ieee_var *pv;
1912 bfd_vma attr, frame_type, push_mask, nargs, level, father;
1913 debug_type rtype;
1914 debug_type *arg_types;
1915 bfd_boolean varargs;
1916 bfd_boolean present;
1917
1918 /* FIXME: We ignore some of this information. */
1919
1920 pv = info->vars.vars + varindx;
1921
1922 if (! ieee_read_number (info, pp, &attr)
1923 || ! ieee_read_number (info, pp, &frame_type)
1924 || ! ieee_read_number (info, pp, &push_mask)
1925 || ! ieee_read_type_index (info, pp, &rtype)
1926 || ! ieee_read_number (info, pp, &nargs))
1927 return FALSE0;
1928 if (nargs == (bfd_vma) -1)
1929 {
1930 arg_types = NULL((void*)0);
1931 varargs = FALSE0;
1932 }
1933 else
1934 {
1935 unsigned int i;
1936
1937 arg_types = ((debug_type *)
1938 xmalloc ((nargs + 1) * sizeof *arg_types));
1939 for (i = 0; i < nargs; i++)
1940 if (! ieee_read_type_index (info, pp, arg_types + i))
1941 return FALSE0;
1942
1943 /* If the last type is pointer to void, this is really a
1944 varargs function. */
1945 varargs = FALSE0;
1946 if (nargs > 0)
1947 {
1948 debug_type last;
1949
1950 last = arg_types[nargs - 1];
1951 if (debug_get_type_kind (dhandle, last) == DEBUG_KIND_POINTER
1952 && (debug_get_type_kind (dhandle,
1953 debug_get_target_type (dhandle,
1954 last))
1955 == DEBUG_KIND_VOID))
1956 {
1957 --nargs;
1958 varargs = TRUE1;
1959 }
1960 }
1961
1962 /* If there are any pointer arguments, turn them into
1963 indirect types in case we later need to convert them to
1964 reference types. */
1965 for (i = 0; i < nargs; i++)
1966 {
1967 if (debug_get_type_kind (dhandle, arg_types[i])
1968 == DEBUG_KIND_POINTER)
1969 {
1970 if (arg_slots == NULL((void*)0))
1971 {
1972 arg_slots = ((debug_type *)
1973 xmalloc (nargs * sizeof *arg_slots));
1974 memset (arg_slots, 0, nargs * sizeof *arg_slots);
1975 }
1976 arg_slots[i] = arg_types[i];
1977 arg_types[i] =
1978 debug_make_indirect_type (dhandle,
1979 arg_slots + i,
1980 (const char *) NULL((void*)0));
1981 }
1982 }
1983
1984 arg_types[nargs] = DEBUG_TYPE_NULL((debug_type) ((void*)0));
1985 }
1986 if (! ieee_read_number (info, pp, &level)
1987 || ! ieee_read_optional_number (info, pp, &father, &present))
1988 return FALSE0;
1989
1990 /* We can't distinguish between a global function and a static
1991 function. */
1992 pv->kind = IEEE_FUNCTION;
1993
1994 if (pv->namlen > 0
1995 && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER)
1996 {
1997 /* Set up the return type as an indirect type pointing to
1998 the variable slot, so that we can change it to a
1999 reference later if appropriate. */
2000 pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot);
2001 *pv->pslot = rtype;
2002 rtype = debug_make_indirect_type (dhandle, pv->pslot,
2003 (const char *) NULL((void*)0));
2004 }
2005
2006 type = debug_make_function_type (dhandle, rtype, arg_types, varargs);
2007 }
2008 break;
2009 }
2010
2011 /* Record the type in the table. */
2012
2013 if (type == DEBUG_TYPE_NULL((debug_type) ((void*)0)))
2014 return FALSE0;
2015
2016 info->vars.vars[varindx].type = type;
2017
2018 if ((tag || typdef)
2019 && info->vars.vars[varindx].namlen > 0)
2020 {
2021 const char *name;
2022
2023 name = savestring (info->vars.vars[varindx].name,
2024 info->vars.vars[varindx].namlen);
2025 if (typdef)
2026 type = debug_name_type (dhandle, name, type);
2027 else if (tc == 'E' || tc == 'N')
2028 type = debug_tag_type (dhandle, name, type);
2029 else
2030 {
2031 struct ieee_tag *it;
2032
2033 /* We must allocate all struct tags as indirect types, so
2034 that if we later see a definition of the tag as a C++
2035 record we can update the indirect slot and automatically
2036 change all the existing references. */
2037 it = (struct ieee_tag *) xmalloc (sizeof *it);
2038 memset (it, 0, sizeof *it);
2039 it->next = info->tags;
2040 info->tags = it;
2041 it->name = name;
2042 it->slot = type;
2043
2044 type = debug_make_indirect_type (dhandle, &it->slot, name);
2045 type = debug_tag_type (dhandle, name, type);
2046
2047 it->type = type;
2048 }
2049 if (type == NULL((void*)0))
2050 return FALSE0;
2051 }
2052
2053 info->types.types[typeindx].type = type;
2054 info->types.types[typeindx].arg_slots = arg_slots;
2055 info->types.types[typeindx].bitsize = type_bitsize;
2056
2057 /* We may have already allocated type as an indirect type pointing
2058 to slot. It does no harm to replace the indirect type with the
2059 real type. Filling in slot as well handles the indirect types
2060 which are already hanging around. */
2061 if (info->types.types[typeindx].pslot != NULL((void*)0))
2062 *info->types.types[typeindx].pslot = type;
2063
2064 return TRUE1;
2065}
2066
2067/* Parse an ATN record. */
2068
2069static bfd_boolean
2070parse_ieee_atn (struct ieee_info *info, const bfd_byte **pp)
2071{
2072 const bfd_byte *atn_start, *atn_code_start;
2073 bfd_vma varindx;
2074 struct ieee_var *pvar;
2075 debug_type type;
2076 bfd_vma atn_code;
2077 void *dhandle;
2078 bfd_vma v, v2, v3, v4, v5;
2079 const char *name;
2080 unsigned long namlen;
2081 char *namcopy;
2082 bfd_boolean present;
2083 int blocktype;
2084
2085 atn_start = *pp;
2086
2087 if (! ieee_read_number (info, pp, &varindx)
2088 || ! ieee_read_type_index (info, pp, &type))
2089 return FALSE0;
2090
2091 atn_code_start = *pp;
2092
2093 if (! ieee_read_number (info, pp, &atn_code))
2094 return FALSE0;
2095
2096 if (varindx == 0)
2097 {
2098 pvar = NULL((void*)0);
2099 name = "";
2100 namlen = 0;
2101 }
2102 else if (varindx < 32)
2103 {
2104 /* The MRI compiler reportedly sometimes emits variable lifetime
2105 information for a register. We just ignore it. */
2106 if (atn_code == 9)
2107 return ieee_read_number (info, pp, &v);
2108
2109 ieee_error (info, atn_start, _("illegal variable index")("illegal variable index"));
2110 return FALSE0;
2111 }
2112 else
2113 {
2114 varindx -= 32;
2115 if (varindx >= info->vars.alloc
2116 || info->vars.vars[varindx].name == NULL((void*)0))
2117 {
2118 /* The MRI compiler or linker sometimes omits the NN record
2119 for a pmisc record. */
2120 if (atn_code == 62)
2121 {
2122 if (varindx >= info->vars.alloc)
2123 {
2124 unsigned int alloc;
2125
2126 alloc = info->vars.alloc;
2127 if (alloc == 0)
2128 alloc = 4;
2129 while (varindx >= alloc)
2130 alloc *= 2;
2131 info->vars.vars = ((struct ieee_var *)
2132 xrealloc (info->vars.vars,
2133 (alloc
2134 * sizeof *info->vars.vars)));
2135 memset (info->vars.vars + info->vars.alloc, 0,
2136 ((alloc - info->vars.alloc)
2137 * sizeof *info->vars.vars));
2138 info->vars.alloc = alloc;
2139 }
2140
2141 pvar = info->vars.vars + varindx;
2142 pvar->name = "";
2143 pvar->namlen = 0;
2144 }
2145 else
2146 {
2147 ieee_error (info, atn_start, _("undefined variable in ATN")("undefined variable in ATN"));
2148 return FALSE0;
2149 }
2150 }
2151
2152 pvar = info->vars.vars + varindx;
2153
2154 pvar->type = type;
2155
2156 name = pvar->name;
2157 namlen = pvar->namlen;
2158 }
2159
2160 dhandle = info->dhandle;
2161
2162 /* If we are going to call debug_record_variable with a pointer
2163 type, change the type to an indirect type so that we can later
2164 change it to a reference type if we encounter a C++ pmisc 'R'
2165 record. */
2166 if (pvar != NULL((void*)0)
2167 && type != DEBUG_TYPE_NULL((debug_type) ((void*)0))
2168 && debug_get_type_kind (dhandle, type) == DEBUG_KIND_POINTER)
2169 {
2170 switch (atn_code)
2171 {
2172 case 1:
2173 case 2:
2174 case 3:
2175 case 5:
2176 case 8:
2177 case 10:
2178 pvar->pslot = (debug_type *) xmalloc (sizeof *pvar->pslot);
2179 *pvar->pslot = type;
2180 type = debug_make_indirect_type (dhandle, pvar->pslot,
2181 (const char *) NULL((void*)0));
2182 pvar->type = type;
2183 break;
2184 }
2185 }
2186
2187 switch (atn_code)
2188 {
2189 default:
2190 ieee_error (info, atn_code_start, _("unknown ATN type")("unknown ATN type"));
2191 return FALSE0;
2192
2193 case 1:
2194 /* Automatic variable. */
2195 if (! ieee_read_number (info, pp, &v))
2196 return FALSE0;
2197 namcopy = savestring (name, namlen);
2198 if (type == NULL((void*)0))
2199 type = debug_make_void_type (dhandle);
2200 if (pvar != NULL((void*)0))
2201 pvar->kind = IEEE_LOCAL;
2202 return debug_record_variable (dhandle, namcopy, type, DEBUG_LOCAL, v);
2203
2204 case 2:
2205 /* Register variable. */
2206 if (! ieee_read_number (info, pp, &v))
2207 return FALSE0;
2208 namcopy = savestring (name, namlen);
2209 if (type == NULL((void*)0))
2210 type = debug_make_void_type (dhandle);
2211 if (pvar != NULL((void*)0))
2212 pvar->kind = IEEE_LOCAL;
2213 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER,
2214 ieee_regno_to_genreg (info->abfd, v));
2215
2216 case 3:
2217 /* Static variable. */
2218 if (! ieee_require_asn (info, pp, &v))
2219 return FALSE0;
2220 namcopy = savestring (name, namlen);
2221 if (type == NULL((void*)0))
2222 type = debug_make_void_type (dhandle);
2223 if (info->blockstack.bsp <= info->blockstack.stack)
2224 blocktype = 0;
2225 else
2226 blocktype = info->blockstack.bsp[-1].kind;
2227 if (pvar != NULL((void*)0))
2228 {
2229 if (blocktype == 4 || blocktype == 6)
2230 pvar->kind = IEEE_LOCAL;
2231 else
2232 pvar->kind = IEEE_STATIC;
2233 }
2234 return debug_record_variable (dhandle, namcopy, type,
2235 (blocktype == 4 || blocktype == 6
2236 ? DEBUG_LOCAL_STATIC
2237 : DEBUG_STATIC),
2238 v);
2239
2240 case 4:
2241 /* External function. We don't currently record these. FIXME. */
2242 if (pvar != NULL((void*)0))
2243 pvar->kind = IEEE_EXTERNAL;
2244 return TRUE1;
2245
2246 case 5:
2247 /* External variable. We don't currently record these. FIXME. */
2248 if (pvar != NULL((void*)0))
2249 pvar->kind = IEEE_EXTERNAL;
2250 return TRUE1;
2251
2252 case 7:
2253 if (! ieee_read_number (info, pp, &v)
2254 || ! ieee_read_number (info, pp, &v2)
2255 || ! ieee_read_optional_number (info, pp, &v3, &present))
2256 return FALSE0;
2257 if (present)
2258 {
2259 if (! ieee_read_optional_number (info, pp, &v4, &present))
2260 return FALSE0;
2261 }
2262
2263 /* We just ignore the two optional fields in v3 and v4, since
2264 they are not defined. */
2265
2266 if (! ieee_require_asn (info, pp, &v3))
2267 return FALSE0;
2268
2269 /* We have no way to record the column number. FIXME. */
2270
2271 return debug_record_line (dhandle, v, v3);
2272
2273 case 8:
2274 /* Global variable. */
2275 if (! ieee_require_asn (info, pp, &v))
2276 return FALSE0;
2277 namcopy = savestring (name, namlen);
2278 if (type == NULL((void*)0))
2279 type = debug_make_void_type (dhandle);
2280 if (pvar != NULL((void*)0))
2281 pvar->kind = IEEE_GLOBAL;
2282 return debug_record_variable (dhandle, namcopy, type, DEBUG_GLOBAL, v);
2283
2284 case 9:
2285 /* Variable lifetime information. */
2286 if (! ieee_read_number (info, pp, &v))
2287 return FALSE0;
2288
2289 /* We have no way to record this information. FIXME. */
2290 return TRUE1;
2291
2292 case 10:
2293 /* Locked register. The spec says that there are two required
2294 fields, but at least on occasion the MRI compiler only emits
2295 one. */
2296 if (! ieee_read_number (info, pp, &v)
2297 || ! ieee_read_optional_number (info, pp, &v2, &present))
2298 return FALSE0;
2299
2300 /* I think this means a variable that is both in a register and
2301 a frame slot. We ignore the frame slot. FIXME. */
2302
2303 namcopy = savestring (name, namlen);
2304 if (type == NULL((void*)0))
2305 type = debug_make_void_type (dhandle);
2306 if (pvar != NULL((void*)0))
2307 pvar->kind = IEEE_LOCAL;
2308 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER, v);
2309
2310 case 11:
2311 /* Reserved for FORTRAN common. */
2312 ieee_error (info, atn_code_start, _("unsupported ATN11")("unsupported ATN11"));
2313
2314 /* Return TRUE to keep going. */
2315 return TRUE1;
2316
2317 case 12:
2318 /* Based variable. */
2319 v3 = 0;
2320 v4 = 0x80;
2321 v5 = 0;
2322 if (! ieee_read_number (info, pp, &v)
2323 || ! ieee_read_number (info, pp, &v2)
2324 || ! ieee_read_optional_number (info, pp, &v3, &present))
2325 return FALSE0;
2326 if (present)
2327 {
2328 if (! ieee_read_optional_number (info, pp, &v4, &present))
2329 return FALSE0;
2330 if (present)
2331 {
2332 if (! ieee_read_optional_number (info, pp, &v5, &present))
2333 return FALSE0;
2334 }
2335 }
2336
2337 /* We have no way to record this information. FIXME. */
2338
2339 ieee_error (info, atn_code_start, _("unsupported ATN12")("unsupported ATN12"));
2340
2341 /* Return TRUE to keep going. */
2342 return TRUE1;
2343
2344 case 16:
2345 /* Constant. The description of this that I have is ambiguous,
2346 so I'm not going to try to implement it. */
2347 if (! ieee_read_number (info, pp, &v)
2348 || ! ieee_read_optional_number (info, pp, &v2, &present))
2349 return FALSE0;
2350 if (present)
2351 {
2352 if (! ieee_read_optional_number (info, pp, &v2, &present))
2353 return FALSE0;
2354 if (present)
2355 {
2356 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
2357 return FALSE0;
2358 }
2359 }
2360
2361 if ((ieee_record_enum_type) **pp == ieee_e2_first_byte_enum)
2362 {
2363 if (! ieee_require_asn (info, pp, &v3))
2364 return FALSE0;
2365 }
2366
2367 return TRUE1;
2368
2369 case 19:
2370 /* Static variable from assembler. */
2371 v2 = 0;
2372 if (! ieee_read_number (info, pp, &v)
2373 || ! ieee_read_optional_number (info, pp, &v2, &present)
2374 || ! ieee_require_asn (info, pp, &v3))
2375 return FALSE0;
2376 namcopy = savestring (name, namlen);
2377 /* We don't really handle this correctly. FIXME. */
2378 return debug_record_variable (dhandle, namcopy,
2379 debug_make_void_type (dhandle),
2380 v2 != 0 ? DEBUG_GLOBAL : DEBUG_STATIC,
2381 v3);
2382
2383 case 62:
2384 /* Procedure miscellaneous information. */
2385 case 63:
2386 /* Variable miscellaneous information. */
2387 case 64:
2388 /* Module miscellaneous information. */
2389 if (! ieee_read_number (info, pp, &v)
2390 || ! ieee_read_number (info, pp, &v2)
2391 || ! ieee_read_optional_id (info, pp, &name, &namlen, &present))
2392 return FALSE0;
2393
2394 if (atn_code == 62 && v == 80)
2395 {
2396 if (present)
2397 {
2398 ieee_error (info, atn_code_start,
2399 _("unexpected string in C++ misc")("unexpected string in C++ misc"));
2400 return FALSE0;
2401 }
2402 return ieee_read_cxx_misc (info, pp, v2);
2403 }
2404
2405 /* We just ignore all of this stuff. FIXME. */
2406
2407 for (; v2 > 0; --v2)
2408 {
2409 switch ((ieee_record_enum_type) **pp)
2410 {
2411 default:
2412 ieee_error (info, *pp, _("bad misc record")("bad misc record"));
2413 return FALSE0;
2414
2415 case ieee_at_record_enum:
2416 if (! ieee_require_atn65 (info, pp, &name, &namlen))
2417 return FALSE0;
2418 break;
2419
2420 case ieee_e2_first_byte_enum:
2421 if (! ieee_require_asn (info, pp, &v3))
2422 return FALSE0;
2423 break;
2424 }
2425 }
2426
2427 return TRUE1;
2428 }
2429
2430 /*NOTREACHED*/
2431}
2432
2433/* Handle C++ debugging miscellaneous records. This is called for
2434 procedure miscellaneous records of type 80. */
2435
2436static bfd_boolean
2437ieee_read_cxx_misc (struct ieee_info *info, const bfd_byte **pp,
2438 unsigned long count)
2439{
2440 const bfd_byte *start;
2441 bfd_vma category;
2442
2443 start = *pp;
2444
2445 /* Get the category of C++ misc record. */
2446 if (! ieee_require_asn (info, pp, &category))
2447 return FALSE0;
2448 --count;
2449
2450 switch (category)
2451 {
2452 default:
2453 ieee_error (info, start, _("unrecognized C++ misc record")("unrecognized C++ misc record"));
2454 return FALSE0;
2455
2456 case 'T':
2457 if (! ieee_read_cxx_class (info, pp, count))
2458 return FALSE0;
2459 break;
2460
2461 case 'M':
2462 {
2463 bfd_vma flags;
2464 const char *name;
2465 unsigned long namlen;
2466
2467 /* The IEEE spec indicates that the 'M' record only has a
2468 flags field. The MRI compiler also emits the name of the
2469 function. */
2470
2471 if (! ieee_require_asn (info, pp, &flags))
2472 return FALSE0;
2473 if (*pp < info->pend
2474 && (ieee_record_enum_type) **pp == ieee_at_record_enum)
2475 {
2476 if (! ieee_require_atn65 (info, pp, &name, &namlen))
2477 return FALSE0;
2478 }
2479
2480 /* This is emitted for method functions, but I don't think we
2481 care very much. It might help if it told us useful
2482 information like the class with which this function is
2483 associated, but it doesn't, so it isn't helpful. */
2484 }
2485 break;
2486
2487 case 'B':
2488 if (! ieee_read_cxx_defaults (info, pp, count))
2489 return FALSE0;
2490 break;
2491
2492 case 'z':
2493 {
2494 const char *name, *mangled, *class;
2495 unsigned long namlen, mangledlen, classlen;
2496 bfd_vma control;
2497
2498 /* Pointer to member. */
2499
2500 if (! ieee_require_atn65 (info, pp, &name, &namlen)
2501 || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen)
2502 || ! ieee_require_atn65 (info, pp, &class, &classlen)
2503 || ! ieee_require_asn (info, pp, &control))
2504 return FALSE0;
2505
2506 /* FIXME: We should now track down name and change its type. */
2507 }
2508 break;
2509
2510 case 'R':
2511 if (! ieee_read_reference (info, pp))
2512 return FALSE0;
2513 break;
2514 }
2515
2516 return TRUE1;
2517}
2518
2519/* Read a C++ class definition. This is a pmisc type 80 record of
2520 category 'T'. */
2521
2522static bfd_boolean
2523ieee_read_cxx_class (struct ieee_info *info, const bfd_byte **pp,
2524 unsigned long count)
2525{
2526 const bfd_byte *start;
2527 bfd_vma class;
2528 const char *tag;
2529 unsigned long taglen;
2530 struct ieee_tag *it;
2531 void *dhandle;
2532 debug_field *fields;
2533 unsigned int field_count, field_alloc;
2534 debug_baseclass *baseclasses;
2535 unsigned int baseclasses_count, baseclasses_alloc;
2536 const debug_field *structfields;
2537 struct ieee_method
2538 {
2539 const char *name;
2540 unsigned long namlen;
2541 debug_method_variant *variants;
2542 unsigned count;
2543 unsigned int alloc;
2544 } *methods;
2545 unsigned int methods_count, methods_alloc;
2546 debug_type vptrbase;
2547 bfd_boolean ownvptr;
2548 debug_method *dmethods;
2549
2550 start = *pp;
2551
2552 if (! ieee_require_asn (info, pp, &class))
2553 return FALSE0;
2554 --count;
2555
2556 if (! ieee_require_atn65 (info, pp, &tag, &taglen))
2557 return FALSE0;
2558 --count;
2559
2560 /* Find the C struct with this name. */
2561 for (it = info->tags; it != NULL((void*)0); it = it->next)
2562 if (it->name[0] == tag[0]
2563 && strncmp (it->name, tag, taglen) == 0
2564 && strlen (it->name) == taglen)
2565 break;
2566 if (it == NULL((void*)0))
2567 {
2568 ieee_error (info, start, _("undefined C++ object")("undefined C++ object"));
2569 return FALSE0;
2570 }
2571
2572 dhandle = info->dhandle;
2573
2574 fields = NULL((void*)0);
2575 field_count = 0;
2576 field_alloc = 0;
2577 baseclasses = NULL((void*)0);
2578 baseclasses_count = 0;
2579 baseclasses_alloc = 0;
2580 methods = NULL((void*)0);
2581 methods_count = 0;
2582 methods_alloc = 0;
2583 vptrbase = DEBUG_TYPE_NULL((debug_type) ((void*)0));
2584 ownvptr = FALSE0;
2585
2586 structfields = debug_get_fields (dhandle, it->type);
2587
2588 while (count > 0)
2589 {
2590 bfd_vma id;
2591 const bfd_byte *spec_start;
2592
2593 spec_start = *pp;
2594
2595 if (! ieee_require_asn (info, pp, &id))
2596 return FALSE0;
2597 --count;
2598
2599 switch (id)
2600 {
2601 default:
2602 ieee_error (info, spec_start, _("unrecognized C++ object spec")("unrecognized C++ object spec"));
2603 return FALSE0;
2604
2605 case 'b':
2606 {
2607 bfd_vma flags, cinline;
2608 const char *basename, *fieldname;
2609 unsigned long baselen, fieldlen;
2610 char *basecopy;
2611 debug_type basetype;
2612 bfd_vma bitpos;
2613 bfd_boolean virtualp;
2614 enum debug_visibility visibility;
2615 debug_baseclass baseclass;
2616
2617 /* This represents a base or friend class. */
2618
2619 if (! ieee_require_asn (info, pp, &flags)
2620 || ! ieee_require_atn65 (info, pp, &basename, &baselen)
2621 || ! ieee_require_asn (info, pp, &cinline)
2622 || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen))
2623 return FALSE0;
2624 count -= 4;
2625
2626 /* We have no way of recording friend information, so we
2627 just ignore it. */
2628 if ((flags & BASEFLAGS_FRIEND(0x10)) != 0)
2629 break;
2630
2631 /* I assume that either all of the members of the
2632 baseclass are included in the object, starting at the
2633 beginning of the object, or that none of them are
2634 included. */
2635
2636 if ((fieldlen == 0) == (cinline == 0))
2637 {
2638 ieee_error (info, start, _("unsupported C++ object type")("unsupported C++ object type"));
2639 return FALSE0;
2640 }
2641
2642 basecopy = savestring (basename, baselen);
2643 basetype = debug_find_tagged_type (dhandle, basecopy,
2644 DEBUG_KIND_ILLEGAL);
2645 free (basecopy);
2646 if (basetype == DEBUG_TYPE_NULL((debug_type) ((void*)0)))
2647 {
2648 ieee_error (info, start, _("C++ base class not defined")("C++ base class not defined"));
2649 return FALSE0;
2650 }
2651
2652 if (fieldlen == 0)
2653 bitpos = 0;
2654 else
2655 {
2656 const debug_field *pf;
2657
2658 if (structfields == NULL((void*)0))
2659 {
2660 ieee_error (info, start, _("C++ object has no fields")("C++ object has no fields"));
2661 return FALSE0;
2662 }
2663
2664 for (pf = structfields; *pf != DEBUG_FIELD_NULL((debug_field) ((void*)0)); pf++)
2665 {
2666 const char *fname;
2667
2668 fname = debug_get_field_name (dhandle, *pf);
2669 if (fname == NULL((void*)0))
2670 return FALSE0;
2671 if (fname[0] == fieldname[0]
2672 && strncmp (fname, fieldname, fieldlen) == 0
2673 && strlen (fname) == fieldlen)
2674 break;
2675 }
2676 if (*pf == DEBUG_FIELD_NULL((debug_field) ((void*)0)))
2677 {
2678 ieee_error (info, start,
2679 _("C++ base class not found in container")("C++ base class not found in container"));
2680 return FALSE0;
2681 }
2682
2683 bitpos = debug_get_field_bitpos (dhandle, *pf);
2684 }
2685
2686 if ((flags & BASEFLAGS_VIRTUAL(0x2)) != 0)
2687 virtualp = TRUE1;
2688 else
2689 virtualp = FALSE0;
2690 if ((flags & BASEFLAGS_PRIVATE(0x1)) != 0)
2691 visibility = DEBUG_VISIBILITY_PRIVATE;
2692 else
2693 visibility = DEBUG_VISIBILITY_PUBLIC;
2694
2695 baseclass = debug_make_baseclass (dhandle, basetype, bitpos,
2696 virtualp, visibility);
2697 if (baseclass == DEBUG_BASECLASS_NULL((debug_baseclass) ((void*)0)))
2698 return FALSE0;
2699
2700 if (baseclasses_count + 1 >= baseclasses_alloc)
2701 {
2702 baseclasses_alloc += 10;
2703 baseclasses = ((debug_baseclass *)
2704 xrealloc (baseclasses,
2705 (baseclasses_alloc
2706 * sizeof *baseclasses)));
2707 }
2708
2709 baseclasses[baseclasses_count] = baseclass;
2710 ++baseclasses_count;
2711 baseclasses[baseclasses_count] = DEBUG_BASECLASS_NULL((debug_baseclass) ((void*)0));
2712 }
2713 break;
2714
2715 case 'd':
2716 {
2717 bfd_vma flags;
2718 const char *fieldname, *mangledname;
2719 unsigned long fieldlen, mangledlen;
2720 char *fieldcopy;
2721 bfd_boolean staticp;
2722 debug_type ftype;
2723 const debug_field *pf = NULL((void*)0);
2724 enum debug_visibility visibility;
2725 debug_field field;
2726
2727 /* This represents a data member. */
2728
2729 if (! ieee_require_asn (info, pp, &flags)
2730 || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen)
2731 || ! ieee_require_atn65 (info, pp, &mangledname, &mangledlen))
2732 return FALSE0;
2733 count -= 3;
2734
2735 fieldcopy = savestring (fieldname, fieldlen);
2736
2737 staticp = (flags & CXXFLAGS_STATIC(0x4)) != 0 ? TRUE1 : FALSE0;
2738
2739 if (staticp)
2740 {
2741 struct ieee_var *pv, *pvend;
2742
2743 /* See if we can find a definition for this variable. */
2744 pv = info->vars.vars;
2745 pvend = pv + info->vars.alloc;
2746 for (; pv < pvend; pv++)
2747 if (pv->namlen == mangledlen
2748 && strncmp (pv->name, mangledname, mangledlen) == 0)
2749 break;
2750 if (pv < pvend)
2751 ftype = pv->type;
2752 else
2753 {
2754 /* This can happen if the variable is never used. */
2755 ftype = ieee_builtin_type (info, start,
2756 (unsigned int) builtin_void);
2757 }
2758 }
2759 else
2760 {
2761 unsigned int findx;
2762
2763 if (structfields == NULL((void*)0))
2764 {
2765 ieee_error (info, start, _("C++ object has no fields")("C++ object has no fields"));
2766 return FALSE0;
2767 }
2768
2769 for (pf = structfields, findx = 0;
2770 *pf != DEBUG_FIELD_NULL((debug_field) ((void*)0));
2771 pf++, findx++)
2772 {
2773 const char *fname;
2774
2775 fname = debug_get_field_name (dhandle, *pf);
2776 if (fname == NULL((void*)0))
2777 return FALSE0;
2778 if (fname[0] == mangledname[0]
2779 && strncmp (fname, mangledname, mangledlen) == 0
2780 && strlen (fname) == mangledlen)
2781 break;
2782 }
2783 if (*pf == DEBUG_FIELD_NULL((debug_field) ((void*)0)))
2784 {
2785 ieee_error (info, start,
2786 _("C++ data member not found in container")("C++ data member not found in container"));
2787 return FALSE0;
2788 }
2789
2790 ftype = debug_get_field_type (dhandle, *pf);
2791
2792 if (debug_get_type_kind (dhandle, ftype) == DEBUG_KIND_POINTER)
2793 {
2794 /* We might need to convert this field into a
2795 reference type later on, so make it an indirect
2796 type. */
2797 if (it->fslots == NULL((void*)0))
2798 {
2799 unsigned int fcnt;
2800 const debug_field *pfcnt;
2801
2802 fcnt = 0;
2803 for (pfcnt = structfields;
2804 *pfcnt != DEBUG_FIELD_NULL((debug_field) ((void*)0));
2805 pfcnt++)
2806 ++fcnt;
2807 it->fslots = ((debug_type *)
2808 xmalloc (fcnt * sizeof *it->fslots));
2809 memset (it->fslots, 0,
2810 fcnt * sizeof *it->fslots);
2811 }
2812
2813 if (ftype == DEBUG_TYPE_NULL((debug_type) ((void*)0)))
2814 return FALSE0;
2815 it->fslots[findx] = ftype;
2816 ftype = debug_make_indirect_type (dhandle,
2817 it->fslots + findx,
2818 (const char *) NULL((void*)0));
2819 }
2820 }
2821 if (ftype == DEBUG_TYPE_NULL((debug_type) ((void*)0)))
2822 return FALSE0;
2823
2824 switch (flags & CXXFLAGS_VISIBILITY(0x3))
2825 {
2826 default:
2827 ieee_error (info, start, _("unknown C++ visibility")("unknown C++ visibility"));
2828 return FALSE0;
2829
2830 case CXXFLAGS_VISIBILITY_PUBLIC(0x0):
2831 visibility = DEBUG_VISIBILITY_PUBLIC;
2832 break;
2833
2834 case CXXFLAGS_VISIBILITY_PRIVATE(0x1):
2835 visibility = DEBUG_VISIBILITY_PRIVATE;
2836 break;
2837
2838 case CXXFLAGS_VISIBILITY_PROTECTED(0x2):
2839 visibility = DEBUG_VISIBILITY_PROTECTED;
2840 break;
2841 }
2842
2843 if (staticp)
2844 {
2845 char *mangledcopy;
2846
2847 mangledcopy = savestring (mangledname, mangledlen);
2848
2849 field = debug_make_static_member (dhandle, fieldcopy,
2850 ftype, mangledcopy,
2851 visibility);
2852 }
2853 else
2854 {
2855 bfd_vma bitpos, bitsize;
2856
2857 bitpos = debug_get_field_bitpos (dhandle, *pf);
2858 bitsize = debug_get_field_bitsize (dhandle, *pf);
2859 if (bitpos == (bfd_vma) -1 || bitsize == (bfd_vma) -1)
2860 {
2861 ieee_error (info, start, _("bad C++ field bit pos or size")("bad C++ field bit pos or size"));
2862 return FALSE0;
2863 }
2864 field = debug_make_field (dhandle, fieldcopy, ftype, bitpos,
2865 bitsize, visibility);
2866 }
2867
2868 if (field == DEBUG_FIELD_NULL((debug_field) ((void*)0)))
2869 return FALSE0;
2870
2871 if (field_count + 1 >= field_alloc)
2872 {
2873 field_alloc += 10;
2874 fields = ((debug_field *)
2875 xrealloc (fields, field_alloc * sizeof *fields));
2876 }
2877
2878 fields[field_count] = field;
2879 ++field_count;
2880 fields[field_count] = DEBUG_FIELD_NULL((debug_field) ((void*)0));
2881 }
2882 break;
2883
2884 case 'm':
2885 case 'v':
2886 {
2887 bfd_vma flags, voffset, control;
2888 const char *name, *mangled;
2889 unsigned long namlen, mangledlen;
2890 struct ieee_var *pv, *pvend;
2891 debug_type type;
2892 enum debug_visibility visibility;
2893 bfd_boolean constp, volatilep;
2894 char *mangledcopy;
2895 debug_method_variant mv;
2896 struct ieee_method *meth;
2897 unsigned int im;
2898
2899 if (! ieee_require_asn (info, pp, &flags)
2900 || ! ieee_require_atn65 (info, pp, &name, &namlen)
2901 || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
2902 return FALSE0;
2903 count -= 3;
2904 if (id != 'v')
2905 voffset = 0;
2906 else
2907 {
2908 if (! ieee_require_asn (info, pp, &voffset))
2909 return FALSE0;
2910 --count;
2911 }
2912 if (! ieee_require_asn (info, pp, &control))
2913 return FALSE0;
2914 --count;
2915
2916 /* We just ignore the control information. */
2917
2918 /* We have no way to represent friend information, so we
2919 just ignore it. */
2920 if ((flags & CXXFLAGS_FRIEND(0x10)) != 0)
2921 break;
2922
2923 /* We should already have seen a type for the function. */
2924 pv = info->vars.vars;
2925 pvend = pv + info->vars.alloc;
2926 for (; pv < pvend; pv++)
2927 if (pv->namlen == mangledlen
2928 && strncmp (pv->name, mangled, mangledlen) == 0)
2929 break;
2930
2931 if (pv >= pvend)
2932 {
2933 /* We won't have type information for this function if
2934 it is not included in this file. We don't try to
2935 handle this case. FIXME. */
2936 type = (debug_make_function_type
2937 (dhandle,
2938 ieee_builtin_type (info, start,
2939 (unsigned int) builtin_void),
2940 (debug_type *) NULL((void*)0),
2941 FALSE0));
2942 }
2943 else
2944 {
2945 debug_type return_type;
2946 const debug_type *arg_types;
2947 bfd_boolean varargs;
2948
2949 if (debug_get_type_kind (dhandle, pv->type)
2950 != DEBUG_KIND_FUNCTION)
2951 {
2952 ieee_error (info, start,
2953 _("bad type for C++ method function")("bad type for C++ method function"));
2954 return FALSE0;
2955 }
2956
2957 return_type = debug_get_return_type (dhandle, pv->type);
2958 arg_types = debug_get_parameter_types (dhandle, pv->type,
2959 &varargs);
2960 if (return_type == DEBUG_TYPE_NULL((debug_type) ((void*)0)) || arg_types == NULL((void*)0))
2961 {
2962 ieee_error (info, start,
2963 _("no type information for C++ method function")("no type information for C++ method function"));
2964 return FALSE0;
2965 }
2966
2967 type = debug_make_method_type (dhandle, return_type, it->type,
2968 (debug_type *) arg_types,
2969 varargs);
2970 }
2971 if (type == DEBUG_TYPE_NULL((debug_type) ((void*)0)))
2972 return FALSE0;
2973
2974 switch (flags & CXXFLAGS_VISIBILITY(0x3))
2975 {
2976 default:
2977 ieee_error (info, start, _("unknown C++ visibility")("unknown C++ visibility"));
2978 return FALSE0;
2979
2980 case CXXFLAGS_VISIBILITY_PUBLIC(0x0):
2981 visibility = DEBUG_VISIBILITY_PUBLIC;
2982 break;
2983
2984 case CXXFLAGS_VISIBILITY_PRIVATE(0x1):
2985 visibility = DEBUG_VISIBILITY_PRIVATE;
2986 break;
2987
2988 case CXXFLAGS_VISIBILITY_PROTECTED(0x2):
2989 visibility = DEBUG_VISIBILITY_PROTECTED;
2990 break;
2991 }
2992
2993 constp = (flags & CXXFLAGS_CONST(0x20)) != 0 ? TRUE1 : FALSE0;
2994 volatilep = (flags & CXXFLAGS_VOLATILE(0x40)) != 0 ? TRUE1 : FALSE0;
2995
2996 mangledcopy = savestring (mangled, mangledlen);
2997
2998 if ((flags & CXXFLAGS_STATIC(0x4)) != 0)
2999 {
3000 if (id == 'v')
3001 {
3002 ieee_error (info, start, _("C++ static virtual method")("C++ static virtual method"));
3003 return FALSE0;
3004 }
3005 mv = debug_make_static_method_variant (dhandle, mangledcopy,
3006 type, visibility,
3007 constp, volatilep);
3008 }
3009 else
3010 {
3011 debug_type vcontext;
3012
3013 if (id != 'v')
3014 vcontext = DEBUG_TYPE_NULL((debug_type) ((void*)0));
3015 else
3016 {
3017 /* FIXME: How can we calculate this correctly? */
3018 vcontext = it->type;
3019 }
3020 mv = debug_make_method_variant (dhandle, mangledcopy, type,
3021 visibility, constp,
3022 volatilep, voffset,
3023 vcontext);
3024 }
3025 if (mv == DEBUG_METHOD_VARIANT_NULL((debug_method_variant) ((void*)0)))
3026 return FALSE0;
3027
3028 for (meth = methods, im = 0; im < methods_count; meth++, im++)
3029 if (meth->namlen == namlen
3030 && strncmp (meth->name, name, namlen) == 0)
3031 break;
3032 if (im >= methods_count)
3033 {
3034 if (methods_count >= methods_alloc)
3035 {
3036 methods_alloc += 10;
3037 methods = ((struct ieee_method *)
3038 xrealloc (methods,
3039 methods_alloc * sizeof *methods));
3040 }
3041 methods[methods_count].name = name;
3042 methods[methods_count].namlen = namlen;
3043 methods[methods_count].variants = NULL((void*)0);
3044 methods[methods_count].count = 0;
3045 methods[methods_count].alloc = 0;
3046 meth = methods + methods_count;
3047 ++methods_count;
3048 }
3049
3050 if (meth->count + 1 >= meth->alloc)
3051 {
3052 meth->alloc += 10;
3053 meth->variants = ((debug_method_variant *)
3054 xrealloc (meth->variants,
3055 (meth->alloc
3056 * sizeof *meth->variants)));
3057 }
3058
3059 meth->variants[meth->count] = mv;
3060 ++meth->count;
3061 meth->variants[meth->count] = DEBUG_METHOD_VARIANT_NULL((debug_method_variant) ((void*)0));
3062 }
3063 break;
3064
3065 case 'o':
3066 {
3067 bfd_vma spec;
3068
3069 /* We have no way to store this information, so we just
3070 ignore it. */
3071 if (! ieee_require_asn (info, pp, &spec))
3072 return FALSE0;
3073 --count;
3074 if ((spec & 4) != 0)
3075 {
3076 const char *filename;
3077 unsigned long filenamlen;
3078 bfd_vma lineno;
3079
3080 if (! ieee_require_atn65 (info, pp, &filename, &filenamlen)
3081 || ! ieee_require_asn (info, pp, &lineno))
3082 return FALSE0;
3083 count -= 2;
3084 }
3085 else if ((spec & 8) != 0)
3086 {
3087 const char *mangled;
3088 unsigned long mangledlen;
3089
3090 if (! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
3091 return FALSE0;
3092 --count;
3093 }
3094 else
3095 {
3096 ieee_error (info, start,
3097 _("unrecognized C++ object overhead spec")("unrecognized C++ object overhead spec"));
3098 return FALSE0;
3099 }
3100 }
3101 break;
3102
3103 case 'z':
3104 {
3105 const char *vname, *basename;
3106 unsigned long vnamelen, baselen;
3107 bfd_vma vsize, control;
3108
3109 /* A virtual table pointer. */
3110
3111 if (! ieee_require_atn65 (info, pp, &vname, &vnamelen)
3112 || ! ieee_require_asn (info, pp, &vsize)
3113 || ! ieee_require_atn65 (info, pp, &basename, &baselen)
3114 || ! ieee_require_asn (info, pp, &control))
3115 return FALSE0;
3116 count -= 4;
3117
3118 /* We just ignore the control number. We don't care what
3119 the virtual table name is. We have no way to store the
3120 virtual table size, and I don't think we care anyhow. */
3121
3122 /* FIXME: We can't handle multiple virtual table pointers. */
3123
3124 if (baselen == 0)
3125 ownvptr = TRUE1;
3126 else
3127 {
3128 char *basecopy;
3129
3130 basecopy = savestring (basename, baselen);
3131 vptrbase = debug_find_tagged_type (dhandle, basecopy,
3132 DEBUG_KIND_ILLEGAL);
3133 free (basecopy);
3134 if (vptrbase == DEBUG_TYPE_NULL((debug_type) ((void*)0)))
3135 {
3136 ieee_error (info, start, _("undefined C++ vtable")("undefined C++ vtable"));
3137 return FALSE0;
3138 }
3139 }
3140 }
3141 break;
3142 }
3143 }
3144
3145 /* Now that we have seen all the method variants, we can call
3146 debug_make_method for each one. */
3147
3148 if (methods_count == 0)
3149 dmethods = NULL((void*)0);
3150 else
3151 {
3152 unsigned int i;
3153
3154 dmethods = ((debug_method *)
3155 xmalloc ((methods_count + 1) * sizeof *dmethods));
3156 for (i = 0; i < methods_count; i++)
3157 {
3158 char *namcopy;
3159
3160 namcopy = savestring (methods[i].name, methods[i].namlen);
3161 dmethods[i] = debug_make_method (dhandle, namcopy,
3162 methods[i].variants);
3163 if (dmethods[i] == DEBUG_METHOD_NULL((debug_method) ((void*)0)))
3164 return FALSE0;
3165 }
3166 dmethods[i] = DEBUG_METHOD_NULL((debug_method) ((void*)0));
3167 free (methods);
3168 }
3169
3170 /* The struct type was created as an indirect type pointing at
3171 it->slot. We update it->slot to automatically update all
3172 references to this struct. */
3173 it->slot = debug_make_object_type (dhandle,
3174 class != 'u',
3175 debug_get_type_size (dhandle,
3176 it->slot),
3177 fields, baseclasses, dmethods,
3178 vptrbase, ownvptr);
3179 if (it->slot == DEBUG_TYPE_NULL((debug_type) ((void*)0)))
3180 return FALSE0;
3181
3182 return TRUE1;
3183}
3184
3185/* Read C++ default argument value and reference type information. */
3186
3187static bfd_boolean
3188ieee_read_cxx_defaults (struct ieee_info *info, const bfd_byte **pp,
3189 unsigned long count)
3190{
3191 const bfd_byte *start;
3192 const char *fnname;
3193 unsigned long fnlen;
3194 bfd_vma defcount;
3195
3196 start = *pp;
3197
3198 /* Giving the function name before the argument count is an addendum
3199 to the spec. The function name is demangled, though, so this
3200 record must always refer to the current function. */
3201
3202 if (info->blockstack.bsp <= info->blockstack.stack
3203 || info->blockstack.bsp[-1].fnindx == (unsigned int) -1)
3204 {
3205 ieee_error (info, start, _("C++ default values not in a function")("C++ default values not in a function"));
3206 return FALSE0;
3207 }
3208
3209 if (! ieee_require_atn65 (info, pp, &fnname, &fnlen)
3210 || ! ieee_require_asn (info, pp, &defcount))
3211 return FALSE0;
3212 count -= 2;
3213
3214 while (defcount-- > 0)
3215 {
3216 bfd_vma type, val;
3217 const char *strval;
3218 unsigned long strvallen;
3219
3220 if (! ieee_require_asn (info, pp, &type))
3221 return FALSE0;
3222 --count;
3223
3224 switch (type)
3225 {
3226 case 0:
3227 case 4:
3228 break;
3229
3230 case 1:
3231 case 2:
3232 if (! ieee_require_asn (info, pp, &val))
3233 return FALSE0;
3234 --count;
3235 break;
3236
3237 case 3:
3238 case 7:
3239 if (! ieee_require_atn65 (info, pp, &strval, &strvallen))
3240 return FALSE0;
3241 --count;
3242 break;
3243
3244 default:
3245 ieee_error (info, start, _("unrecognized C++ default type")("unrecognized C++ default type"));
3246 return FALSE0;
3247 }
3248
3249 /* We have no way to record the default argument values, so we
3250 just ignore them. FIXME. */
3251 }
3252
3253 /* Any remaining arguments are indices of parameters that are really
3254 reference type. */
3255 if (count > 0)
3256 {
3257 void *dhandle;
3258 debug_type *arg_slots;
3259
3260 dhandle = info->dhandle;
3261 arg_slots = info->types.types[info->blockstack.bsp[-1].fnindx].arg_slots;
3262 while (count-- > 0)
3263 {
3264 bfd_vma indx;
3265 debug_type target;
3266
3267 if (! ieee_require_asn (info, pp, &indx))
3268 return FALSE0;
3269 /* The index is 1 based. */
3270 --indx;
3271 if (arg_slots == NULL((void*)0)
3272 || arg_slots[indx] == DEBUG_TYPE_NULL((debug_type) ((void*)0))
3273 || (debug_get_type_kind (dhandle, arg_slots[indx])
3274 != DEBUG_KIND_POINTER))
3275 {
3276 ieee_error (info, start, _("reference parameter is not a pointer")("reference parameter is not a pointer"));
3277 return FALSE0;
3278 }
3279
3280 target = debug_get_target_type (dhandle, arg_slots[indx]);
3281 arg_slots[indx] = debug_make_reference_type (dhandle, target);
3282 if (arg_slots[indx] == DEBUG_TYPE_NULL((debug_type) ((void*)0)))
3283 return FALSE0;
3284 }
3285 }
3286
3287 return TRUE1;
3288}
3289
3290/* Read a C++ reference definition. */
3291
3292static bfd_boolean
3293ieee_read_reference (struct ieee_info *info, const bfd_byte **pp)
3294{
3295 const bfd_byte *start;
3296 bfd_vma flags;
3297 const char *class, *name;
3298 unsigned long classlen, namlen;
3299 debug_type *pslot;
3300 debug_type target;
3301
3302 start = *pp;
3303
3304 if (! ieee_require_asn (info, pp, &flags))
3305 return FALSE0;
3306
3307 /* Giving the class name before the member name is in an addendum to
3308 the spec. */
3309 if (flags == 3)
3310 {
3311 if (! ieee_require_atn65 (info, pp, &class, &classlen))
3312 return FALSE0;
3313 }
3314
3315 if (! ieee_require_atn65 (info, pp, &name, &namlen))
3316 return FALSE0;
3317
3318 pslot = NULL((void*)0);
3319 if (flags != 3)
3320 {
3321 int pass;
3322
3323 /* We search from the last variable indices to the first in
3324 hopes of finding local variables correctly. We search the
3325 local variables on the first pass, and the global variables
3326 on the second. FIXME: This probably won't work in all cases.
3327 On the other hand, I don't know what will. */
3328 for (pass = 0; pass < 2; pass++)
3329 {
3330 struct ieee_vars *vars;
3331 int i;
3332 struct ieee_var *pv = NULL((void*)0);
3333
3334 if (pass == 0)
3335 vars = &info->vars;
3336 else
3337 {
3338 vars = info->global_vars;
3339 if (vars == NULL((void*)0))
3340 break;
3341 }
3342
3343 for (i = (int) vars->alloc - 1; i >= 0; i--)
3344 {
3345 bfd_boolean found;
3346
3347 pv = vars->vars + i;
3348
3349 if (pv->pslot == NULL((void*)0)
3350 || pv->namlen != namlen
3351 || strncmp (pv->name, name, namlen) != 0)
3352 continue;
3353
3354 found = FALSE0;
3355 switch (flags)
3356 {
3357 default:
3358 ieee_error (info, start,
3359 _("unrecognized C++ reference type")("unrecognized C++ reference type"));
3360 return FALSE0;
3361
3362 case 0:
3363 /* Global variable or function. */
3364 if (pv->kind == IEEE_GLOBAL
3365 || pv->kind == IEEE_EXTERNAL
3366 || pv->kind == IEEE_FUNCTION)
3367 found = TRUE1;
3368 break;
3369
3370 case 1:
3371 /* Global static variable or function. */
3372 if (pv->kind == IEEE_STATIC
3373 || pv->kind == IEEE_FUNCTION)
3374 found = TRUE1;
3375 break;
3376
3377 case 2:
3378 /* Local variable. */
3379 if (pv->kind == IEEE_LOCAL)
3380 found = TRUE1;
3381 break;
3382 }
3383
3384 if (found)
3385 break;
3386 }
3387
3388 if (i >= 0)
3389 {
3390 pslot = pv->pslot;
3391 break;
3392 }
3393 }
3394 }
3395 else
3396 {
3397 struct ieee_tag *it;
3398
3399 for (it = info->tags; it != NULL((void*)0); it = it->next)
3400 {
3401 if (it->name[0] == class[0]
3402 && strncmp (it->name, class, classlen) == 0
3403 && strlen (it->name) == classlen)
3404 {
3405 if (it->fslots != NULL((void*)0))
3406 {
3407 const debug_field *pf;
3408 unsigned int findx;
3409
3410 pf = debug_get_fields (info->dhandle, it->type);
3411 if (pf == NULL((void*)0))
3412 {
3413 ieee_error (info, start,
3414 "C++ reference in class with no fields");
3415 return FALSE0;
3416 }
3417
3418 for (findx = 0; *pf != DEBUG_FIELD_NULL((debug_field) ((void*)0)); pf++, findx++)
3419 {
3420 const char *fname;
3421
3422 fname = debug_get_field_name (info->dhandle, *pf);
3423 if (fname == NULL((void*)0))
3424 return FALSE0;
3425 if (strncmp (fname, name, namlen) == 0
3426 && strlen (fname) == namlen)
3427 {
3428 pslot = it->fslots + findx;
3429 break;
3430 }
3431 }
3432 }
3433
3434 break;
3435 }
3436 }
3437 }
3438
3439 if (pslot == NULL((void*)0))
3440 {
3441 ieee_error (info, start, _("C++ reference not found")("C++ reference not found"));
3442 return FALSE0;
3443 }
3444
3445 /* We allocated the type of the object as an indirect type pointing
3446 to *pslot, which we can now update to be a reference type. */
3447 if (debug_get_type_kind (info->dhandle, *pslot) != DEBUG_KIND_POINTER)
3448 {
3449 ieee_error (info, start, _("C++ reference is not pointer")("C++ reference is not pointer"));
3450 return FALSE0;
3451 }
3452
3453 target = debug_get_target_type (info->dhandle, *pslot);
3454 *pslot = debug_make_reference_type (info->dhandle, target);
3455 if (*pslot == DEBUG_TYPE_NULL((debug_type) ((void*)0)))
3456 return FALSE0;
3457
3458 return TRUE1;
3459}
3460
3461/* Require an ASN record. */
3462
3463static bfd_boolean
3464ieee_require_asn (struct ieee_info *info, const bfd_byte **pp, bfd_vma *pv)
3465{
3466 const bfd_byte *start;
3467 ieee_record_enum_type c;
3468 bfd_vma varindx;
3469
3470 start = *pp;
3471
3472 c = (ieee_record_enum_type) **pp;
3473 if (c != ieee_e2_first_byte_enum)
3474 {
3475 ieee_error (info, start, _("missing required ASN")("missing required ASN"));
3476 return FALSE0;
3477 }
3478 ++*pp;
3479
3480 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
3481 if (c != ieee_asn_record_enum)
3482 {
3483 ieee_error (info, start, _("missing required ASN")("missing required ASN"));
3484 return FALSE0;
3485 }
3486 ++*pp;
3487
3488 /* Just ignore the variable index. */
3489 if (! ieee_read_number (info, pp, &varindx))
3490 return FALSE0;
3491
3492 return ieee_read_expression (info, pp, pv);
3493}
3494
3495/* Require an ATN65 record. */
3496
3497static bfd_boolean
3498ieee_require_atn65 (struct ieee_info *info, const bfd_byte **pp,
3499 const char **pname, unsigned long *pnamlen)
3500{
3501 const bfd_byte *start;
3502 ieee_record_enum_type c;
3503 bfd_vma name_indx, type_indx, atn_code;
3504
3505 start = *pp;
3506
3507 c = (ieee_record_enum_type) **pp;
3508 if (c != ieee_at_record_enum)
3509 {
3510 ieee_error (info, start, _("missing required ATN65")("missing required ATN65"));
3511 return FALSE0;
3512 }
3513 ++*pp;
3514
3515 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
3516 if (c != ieee_atn_record_enum)
3517 {
3518 ieee_error (info, start, _("missing required ATN65")("missing required ATN65"));
3519 return FALSE0;
3520 }
3521 ++*pp;
3522
3523 if (! ieee_read_number (info, pp, &name_indx)
3524 || ! ieee_read_number (info, pp, &type_indx)
3525 || ! ieee_read_number (info, pp, &atn_code))
3526 return FALSE0;
3527
3528 /* Just ignore name_indx. */
3529
3530 if (type_indx != 0 || atn_code != 65)
3531 {
3532 ieee_error (info, start, _("bad ATN65 record")("bad ATN65 record"));
3533 return FALSE0;
3534 }
3535
3536 return ieee_read_id (info, pp, pname, pnamlen);
3537}
3538
3539/* Convert a register number in IEEE debugging information into a
3540 generic register number. */
3541
3542static int
3543ieee_regno_to_genreg (bfd *abfd, int r)
3544{
3545 switch (bfd_get_arch (abfd))
3546 {
3547 case bfd_arch_m68k:
3548 /* For some reasons stabs adds 2 to the floating point register
3549 numbers. */
3550 if (r >= 16)
3551 r += 2;
3552 break;
3553
3554 case bfd_arch_i960:
3555 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
3556 32 to 35 for fp0 to fp3. */
3557 --r;
3558 break;
3559
3560 default:
3561 break;
3562 }
3563
3564 return r;
3565}
3566
3567/* Convert a generic register number to an IEEE specific one. */
3568
3569static int
3570ieee_genreg_to_regno (bfd *abfd, int r)
3571{
3572 switch (bfd_get_arch (abfd))
3573 {
3574 case bfd_arch_m68k:
3575 /* For some reason stabs add 2 to the floating point register
3576 numbers. */
3577 if (r >= 18)
3578 r -= 2;
3579 break;
3580
3581 case bfd_arch_i960:
3582 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
3583 32 to 35 for fp0 to fp3. */
3584 ++r;
3585 break;
3586
3587 default:
3588 break;
3589 }
3590
3591 return r;
3592}
3593
3594/* These routines build IEEE debugging information out of the generic
3595 debugging information. */
3596
3597/* We build the IEEE debugging information byte by byte. Rather than
3598 waste time copying data around, we use a linked list of buffers to
3599 hold the data. */
3600
3601#define IEEE_BUFSIZE(490) (490)
3602
3603struct ieee_buf
3604{
3605 /* Next buffer. */
3606 struct ieee_buf *next;
3607 /* Number of data bytes in this buffer. */
3608 unsigned int c;
3609 /* Bytes. */
3610 bfd_byte buf[IEEE_BUFSIZE(490)];
3611};
3612
3613/* A list of buffers. */
3614
3615struct ieee_buflist
3616{
3617 /* Head of list. */
3618 struct ieee_buf *head;
3619 /* Tail--last buffer on list. */
3620 struct ieee_buf *tail;
3621};
3622
3623/* In order to generate the BB11 blocks required by the HP emulator,
3624 we keep track of ranges of addresses which correspond to a given
3625 compilation unit. */
3626
3627struct ieee_range
3628{
3629 /* Next range. */
3630 struct ieee_range *next;
3631 /* Low address. */
3632 bfd_vma low;
3633 /* High address. */
3634 bfd_vma high;
3635};
3636
3637/* This structure holds information for a class on the type stack. */
3638
3639struct ieee_type_class
3640{
3641 /* The name index in the debugging information. */
3642 unsigned int indx;
3643 /* The pmisc records for the class. */
3644 struct ieee_buflist pmiscbuf;
3645 /* The number of pmisc records. */
3646 unsigned int pmisccount;
3647 /* The name of the class holding the virtual table, if not this
3648 class. */
3649 const char *vclass;
3650 /* Whether this class holds its own virtual table. */
3651 bfd_boolean ownvptr;
3652 /* The largest virtual table offset seen so far. */
3653 bfd_vma voffset;
3654 /* The current method. */
3655 const char *method;
3656 /* Additional pmisc records used to record fields of reference type. */
3657 struct ieee_buflist refs;
3658};
3659
3660/* This is how we store types for the writing routines. Most types
3661 are simply represented by a type index. */
3662
3663struct ieee_write_type
3664{
3665 /* Type index. */
3666 unsigned int indx;
3667 /* The size of the type, if known. */
3668 unsigned int size;
3669 /* The name of the type, if any. */
3670 const char *name;
3671 /* If this is a function or method type, we build the type here, and
3672 only add it to the output buffers if we need it. */
3673 struct ieee_buflist fndef;
3674 /* If this is a struct, this is where the struct definition is
3675 built. */
3676 struct ieee_buflist strdef;
3677 /* If this is a class, this is where the class information is built. */
3678 struct ieee_type_class *classdef;
3679 /* Whether the type is unsigned. */
3680 unsigned int unsignedp : 1;
3681 /* Whether this is a reference type. */
3682 unsigned int referencep : 1;
3683 /* Whether this is in the local type block. */
3684 unsigned int localp : 1;
3685 /* Whether this is a duplicate struct definition which we are
3686 ignoring. */
3687 unsigned int ignorep : 1;
3688};
3689
3690/* This is the type stack used by the debug writing routines. FIXME:
3691 We could generate more efficient output if we remembered when we
3692 have output a particular type before. */
3693
3694struct ieee_type_stack
3695{
3696 /* Next entry on stack. */
3697 struct ieee_type_stack *next;
3698 /* Type information. */
3699 struct ieee_write_type type;
3700};
3701
3702/* This is a list of associations between a name and some types.
3703 These are used for typedefs and tags. */
3704
3705struct ieee_name_type
3706{
3707 /* Next type for this name. */
3708 struct ieee_name_type *next;
3709 /* ID number. For a typedef, this is the index of the type to which
3710 this name is typedefed. */
3711 unsigned int id;
3712 /* Type. */
3713 struct ieee_write_type type;
3714 /* If this is a tag which has not yet been defined, this is the
3715 kind. If the tag has been defined, this is DEBUG_KIND_ILLEGAL. */
3716 enum debug_type_kind kind;
3717};
3718
3719/* We use a hash table to associate names and types. */
3720
3721struct ieee_name_type_hash_table
3722{
3723 struct bfd_hash_table root;
3724};
3725
3726struct ieee_name_type_hash_entry
3727{
3728 struct bfd_hash_entry root;
3729 /* Information for this name. */
3730 struct ieee_name_type *types;
3731};
3732
3733/* This is a list of enums. */
3734
3735struct ieee_defined_enum
3736{
3737 /* Next enum. */
3738 struct ieee_defined_enum *next;
3739 /* Type index. */
3740 unsigned int indx;
3741 /* Whether this enum has been defined. */
3742 bfd_boolean defined;
3743 /* Tag. */
3744 const char *tag;
3745 /* Names. */
3746 const char **names;
3747 /* Values. */
3748 bfd_signed_vma *vals;
3749};
3750
3751/* We keep a list of modified versions of types, so that we don't
3752 output them more than once. */
3753
3754struct ieee_modified_type
3755{
3756 /* Pointer to this type. */
3757 unsigned int pointer;
3758 /* Function with unknown arguments returning this type. */
3759 unsigned int function;
3760 /* Const version of this type. */
3761 unsigned int const_qualified;
3762 /* Volatile version of this type. */
3763 unsigned int volatile_qualified;
3764 /* List of arrays of this type of various bounds. */
3765 struct ieee_modified_array_type *arrays;
3766};
3767
3768/* A list of arrays bounds. */
3769
3770struct ieee_modified_array_type
3771{
3772 /* Next array bounds. */
3773 struct ieee_modified_array_type *next;
3774 /* Type index with these bounds. */
3775 unsigned int indx;
3776 /* Low bound. */
3777 bfd_signed_vma low;
3778 /* High bound. */
3779 bfd_signed_vma high;
3780};
3781
3782/* This is a list of pending function parameter information. We don't
3783 output them until we see the first block. */
3784
3785struct ieee_pending_parm
3786{
3787 /* Next pending parameter. */
3788 struct ieee_pending_parm *next;
3789 /* Name. */
3790 const char *name;
3791 /* Type index. */
3792 unsigned int type;
3793 /* Whether the type is a reference. */
3794 bfd_boolean referencep;
3795 /* Kind. */
3796 enum debug_parm_kind kind;
3797 /* Value. */
3798 bfd_vma val;
3799};
3800
3801/* This is the handle passed down by debug_write. */
3802
3803struct ieee_handle
3804{
3805 /* BFD we are writing to. */
3806 bfd *abfd;
3807 /* Whether we got an error in a subroutine called via traverse or
3808 map_over_sections. */
3809 bfd_boolean error;
3810 /* Current data buffer list. */
3811 struct ieee_buflist *current;
3812 /* Current data buffer. */
3813 struct ieee_buf *curbuf;
3814 /* Filename of current compilation unit. */
3815 const char *filename;
3816 /* Module name of current compilation unit. */
3817 const char *modname;
3818 /* List of buffer for global types. */
3819 struct ieee_buflist global_types;
3820 /* List of finished data buffers. */
3821 struct ieee_buflist data;
3822 /* List of buffers for typedefs in the current compilation unit. */
3823 struct ieee_buflist types;
3824 /* List of buffers for variables and functions in the current
3825 compilation unit. */
3826 struct ieee_buflist vars;
3827 /* List of buffers for C++ class definitions in the current
3828 compilation unit. */
3829 struct ieee_buflist cxx;
3830 /* List of buffers for line numbers in the current compilation unit. */
3831 struct ieee_buflist linenos;
3832 /* Ranges for the current compilation unit. */
3833 struct ieee_range *ranges;
3834 /* Ranges for all debugging information. */
3835 struct ieee_range *global_ranges;
3836 /* Nested pending ranges. */
3837 struct ieee_range *pending_ranges;
3838 /* Type stack. */
3839 struct ieee_type_stack *type_stack;
3840 /* Next unallocated type index. */
3841 unsigned int type_indx;
3842 /* Next unallocated name index. */
3843 unsigned int name_indx;
3844 /* Typedefs. */
3845 struct ieee_name_type_hash_table typedefs;
3846 /* Tags. */
3847 struct ieee_name_type_hash_table tags;
3848 /* Enums. */
3849 struct ieee_defined_enum *enums;
3850 /* Modified versions of types. */
3851 struct ieee_modified_type *modified;
3852 /* Number of entries allocated in modified. */
3853 unsigned int modified_alloc;
3854 /* 4 byte complex type. */
3855 unsigned int complex_float_index;
3856 /* 8 byte complex type. */
3857 unsigned int complex_double_index;
3858 /* The depth of block nesting. This is 0 outside a function, and 1
3859 just after start_function is called. */
3860 unsigned int block_depth;
3861 /* The name of the current function. */
3862 const char *fnname;
3863 /* List of buffers for the type of the function we are currently
3864 writing out. */
3865 struct ieee_buflist fntype;
3866 /* List of buffers for the parameters of the function we are
3867 currently writing out. */
3868 struct ieee_buflist fnargs;
3869 /* Number of arguments written to fnargs. */
3870 unsigned int fnargcount;
3871 /* Pending function parameters. */
3872 struct ieee_pending_parm *pending_parms;
3873 /* Current line number filename. */
3874 const char *lineno_filename;
3875 /* Line number name index. */
3876 unsigned int lineno_name_indx;
3877 /* Filename of pending line number. */
3878 const char *pending_lineno_filename;
3879 /* Pending line number. */
3880 unsigned long pending_lineno;
3881 /* Address of pending line number. */
3882 bfd_vma pending_lineno_addr;
3883 /* Highest address seen at end of procedure. */
3884 bfd_vma highaddr;
3885};
3886
3887static bfd_boolean ieee_init_buffer
3888 (struct ieee_handle *, struct ieee_buflist *);
3889static bfd_boolean ieee_change_buffer
3890 (struct ieee_handle *, struct ieee_buflist *);
3891static bfd_boolean ieee_append_buffer
3892 (struct ieee_handle *, struct ieee_buflist *, struct ieee_buflist *);
3893static bfd_boolean ieee_real_write_byte (struct ieee_handle *, int);
3894static bfd_boolean ieee_write_2bytes (struct ieee_handle *, int);
3895static bfd_boolean ieee_write_number (struct ieee_handle *, bfd_vma);
3896static bfd_boolean ieee_write_id (struct ieee_handle *, const char *);
3897static bfd_boolean ieee_write_asn
3898 (struct ieee_handle *, unsigned int, bfd_vma);
3899static bfd_boolean ieee_write_atn65
3900 (struct ieee_handle *, unsigned int, const char *);
3901static bfd_boolean ieee_push_type
3902 (struct ieee_handle *, unsigned int, unsigned int, bfd_boolean,
3903 bfd_boolean);
3904static unsigned int ieee_pop_type (struct ieee_handle *);
3905static void ieee_pop_unused_type (struct ieee_handle *);
3906static unsigned int ieee_pop_type_used (struct ieee_handle *, bfd_boolean);
3907static bfd_boolean ieee_add_range
3908 (struct ieee_handle *, bfd_boolean, bfd_vma, bfd_vma);
3909static bfd_boolean ieee_start_range (struct ieee_handle *, bfd_vma);
3910static bfd_boolean ieee_end_range (struct ieee_handle *, bfd_vma);
3911static bfd_boolean ieee_define_type
3912 (struct ieee_handle *, unsigned int, bfd_boolean, bfd_boolean);
3913static bfd_boolean ieee_define_named_type
3914 (struct ieee_handle *, const char *, unsigned int, unsigned int,
3915 bfd_boolean, bfd_boolean, struct ieee_buflist *);
3916static struct ieee_modified_type *ieee_get_modified_info
3917 (struct ieee_handle *, unsigned int);
3918static struct bfd_hash_entry *ieee_name_type_newfunc
3919 (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
3920static bfd_boolean ieee_write_undefined_tag
3921 (struct ieee_name_type_hash_entry *, void *);
3922static bfd_boolean ieee_finish_compilation_unit (struct ieee_handle *);
3923static void ieee_add_bb11_blocks (bfd *, asection *, void *);
3924static bfd_boolean ieee_add_bb11
3925 (struct ieee_handle *, asection *, bfd_vma, bfd_vma);
3926static bfd_boolean ieee_output_pending_parms (struct ieee_handle *);
3927static unsigned int ieee_vis_to_flags (enum debug_visibility);
3928static bfd_boolean ieee_class_method_var
3929 (struct ieee_handle *, const char *, enum debug_visibility, bfd_boolean,
3930 bfd_boolean, bfd_boolean, bfd_vma, bfd_boolean);
3931
3932static bfd_boolean ieee_start_compilation_unit (void *, const char *);
3933static bfd_boolean ieee_start_source (void *, const char *);
3934static bfd_boolean ieee_empty_type (void *);
3935static bfd_boolean ieee_void_type (void *);
3936static bfd_boolean ieee_int_type (void *, unsigned int, bfd_boolean);
3937static bfd_boolean ieee_float_type (void *, unsigned int);
3938static bfd_boolean ieee_complex_type (void *, unsigned int);
3939static bfd_boolean ieee_bool_type (void *, unsigned int);
3940static bfd_boolean ieee_enum_type
3941 (void *, const char *, const char **, bfd_signed_vma *);
3942static bfd_boolean ieee_pointer_type (void *);
3943static bfd_boolean ieee_function_type (void *, int, bfd_boolean);
3944static bfd_boolean ieee_reference_type (void *);
3945static bfd_boolean ieee_range_type (void *, bfd_signed_vma, bfd_signed_vma);
3946static bfd_boolean ieee_array_type
3947 (void *, bfd_signed_vma, bfd_signed_vma, bfd_boolean);
3948static bfd_boolean ieee_set_type (void *, bfd_boolean);
3949static bfd_boolean ieee_offset_type (void *);
3950static bfd_boolean ieee_method_type (void *, bfd_boolean, int, bfd_boolean);
3951static bfd_boolean ieee_const_type (void *);
3952static bfd_boolean ieee_volatile_type (void *);
3953static bfd_boolean ieee_start_struct_type
3954 (void *, const char *, unsigned int, bfd_boolean, unsigned int);
3955static bfd_boolean ieee_struct_field
3956 (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
3957static bfd_boolean ieee_end_struct_type (void *);
3958static bfd_boolean ieee_start_class_type
3959 (void *, const char *, unsigned int, bfd_boolean, unsigned int, bfd_boolean,
3960 bfd_boolean);
3961static bfd_boolean ieee_class_static_member
3962 (void *, const char *, const char *, enum debug_visibility);
3963static bfd_boolean ieee_class_baseclass
3964 (void *, bfd_vma, bfd_boolean, enum debug_visibility);
3965static bfd_boolean ieee_class_start_method (void *, const char *);
3966static bfd_boolean ieee_class_method_variant
3967 (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean,
3968 bfd_vma, bfd_boolean);
3969static bfd_boolean ieee_class_static_method_variant
3970 (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean);
3971static bfd_boolean ieee_class_end_method (void *);
3972static bfd_boolean ieee_end_class_type (void *);
3973static bfd_boolean ieee_typedef_type (void *, const char *);
3974static bfd_boolean ieee_tag_type
3975 (void *, const char *, unsigned int, enum debug_type_kind);
3976static bfd_boolean ieee_typdef (void *, const char *);
3977static bfd_boolean ieee_tag (void *, const char *);
3978static bfd_boolean ieee_int_constant (void *, const char *, bfd_vma);
3979static bfd_boolean ieee_float_constant (void *, const char *, double);
3980static bfd_boolean ieee_typed_constant (void *, const char *, bfd_vma);
3981static bfd_boolean ieee_variable
3982 (void *, const char *, enum debug_var_kind, bfd_vma);
3983static bfd_boolean ieee_start_function (void *, const char *, bfd_boolean);
3984static bfd_boolean ieee_function_parameter
3985 (void *, const char *, enum debug_parm_kind, bfd_vma);
3986static bfd_boolean ieee_start_block (void *, bfd_vma);
3987static bfd_boolean ieee_end_block (void *, bfd_vma);
3988static bfd_boolean ieee_end_function (void *);
3989static bfd_boolean ieee_lineno (void *, const char *, unsigned long, bfd_vma);
3990
3991static const struct debug_write_fns ieee_fns =
3992{
3993 ieee_start_compilation_unit,
3994 ieee_start_source,
3995 ieee_empty_type,
3996 ieee_void_type,
3997 ieee_int_type,
3998 ieee_float_type,
3999 ieee_complex_type,
4000 ieee_bool_type,
4001 ieee_enum_type,
4002 ieee_pointer_type,
4003 ieee_function_type,
4004 ieee_reference_type,
4005 ieee_range_type,
4006 ieee_array_type,
4007 ieee_set_type,
4008 ieee_offset_type,
4009 ieee_method_type,
4010 ieee_const_type,
4011 ieee_volatile_type,
4012 ieee_start_struct_type,
4013 ieee_struct_field,
4014 ieee_end_struct_type,
4015 ieee_start_class_type,
4016 ieee_class_static_member,
4017 ieee_class_baseclass,
4018 ieee_class_start_method,
4019 ieee_class_method_variant,
4020 ieee_class_static_method_variant,
4021 ieee_class_end_method,
4022 ieee_end_class_type,
4023 ieee_typedef_type,
4024 ieee_tag_type,
4025 ieee_typdef,
4026 ieee_tag,
4027 ieee_int_constant,
4028 ieee_float_constant,
4029 ieee_typed_constant,
4030 ieee_variable,
4031 ieee_start_function,
4032 ieee_function_parameter,
4033 ieee_start_block,
4034 ieee_end_block,
4035 ieee_end_function,
4036 ieee_lineno
4037};
4038
4039/* Initialize a buffer to be empty. */
4040
4041static bfd_boolean
4042ieee_init_buffer (struct ieee_handle *info ATTRIBUTE_UNUSED__attribute__ ((__unused__)),
4043 struct ieee_buflist *buflist)
4044{
4045 buflist->head = NULL((void*)0);
4046 buflist->tail = NULL((void*)0);
4047 return TRUE1;
4048}
4049
4050/* See whether a buffer list has any data. */
4051
4052#define ieee_buffer_emptyp(buflist)((buflist)->head == ((void*)0)) ((buflist)->head == NULL((void*)0))
4053
4054/* Change the current buffer to a specified buffer chain. */
4055
4056static bfd_boolean
4057ieee_change_buffer (struct ieee_handle *info, struct ieee_buflist *buflist)
4058{
4059 if (buflist->head == NULL((void*)0))
4060 {
4061 struct ieee_buf *buf;
4062
4063 buf = (struct ieee_buf *) xmalloc (sizeof *buf);
4064 buf->next = NULL((void*)0);
4065 buf->c = 0;
4066 buflist->head = buf;
4067 buflist->tail = buf;
4068 }
4069
4070 info->current = buflist;
4071 info->curbuf = buflist->tail;
4072
4073 return TRUE1;
4074}
4075
4076/* Append a buffer chain. */
4077
4078static bfd_boolean
4079ieee_append_buffer (struct ieee_handle *info ATTRIBUTE_UNUSED__attribute__ ((__unused__)),
4080 struct ieee_buflist *mainbuf,
4081 struct ieee_buflist *newbuf)
4082{
4083 if (newbuf->head != NULL((void*)0))
4084 {
4085 if (mainbuf->head == NULL((void*)0))
4086 mainbuf->head = newbuf->head;
4087 else
4088 mainbuf->tail->next = newbuf->head;
4089 mainbuf->tail = newbuf->tail;
4090 }
4091 return TRUE1;
4092}
4093
4094/* Write a byte into the buffer. We use a macro for speed and a
4095 function for the complex cases. */
4096
4097#define ieee_write_byte(info, b)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (b), 1) : ieee_real_write_byte
((info), (b)))
\
4098 ((info)->curbuf->c < IEEE_BUFSIZE(490) \
4099 ? ((info)->curbuf->buf[(info)->curbuf->c++] = (b), TRUE1) \
4100 : ieee_real_write_byte ((info), (b)))
4101
4102static bfd_boolean
4103ieee_real_write_byte (struct ieee_handle *info, int b)
4104{
4105 if (info->curbuf->c >= IEEE_BUFSIZE(490))
4106 {
4107 struct ieee_buf *n;
4108
4109 n = (struct ieee_buf *) xmalloc (sizeof *n);
4110 n->next = NULL((void*)0);
4111 n->c = 0;
4112 if (info->current->head == NULL((void*)0))
4113 info->current->head = n;
4114 else
4115 info->current->tail->next = n;
4116 info->current->tail = n;
4117 info->curbuf = n;
4118 }
4119
4120 info->curbuf->buf[info->curbuf->c] = b;
4121 ++info->curbuf->c;
4122
4123 return TRUE1;
4124}
4125
4126/* Write out two bytes. */
4127
4128static bfd_boolean
4129ieee_write_2bytes (struct ieee_handle *info, int i)
4130{
4131 return (ieee_write_byte (info, i >> 8)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (i >> 8), 1) : ieee_real_write_byte
((info), (i >> 8)))
4132 && ieee_write_byte (info, i & 0xff)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (i & 0xff), 1) : ieee_real_write_byte
((info), (i & 0xff)))
);
4133}
4134
4135/* Write out an integer. */
4136
4137static bfd_boolean
4138ieee_write_number (struct ieee_handle *info, bfd_vma v)
4139{
4140 bfd_vma t;
4141 bfd_byte ab[20];
4142 bfd_byte *p;
4143 unsigned int c;
4144
4145 if (v <= (bfd_vma) ieee_number_end_enum)
4146 return ieee_write_byte (info, (int) v)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) v), 1) : ieee_real_write_byte
((info), ((int) v)))
;
4147
4148 t = v;
4149 p = ab + sizeof ab;
4150 while (t != 0)
4151 {
4152 *--p = t & 0xff;
4153 t >>= 8;
4154 }
4155 c = (ab + 20) - p;
4156
4157 if (c > (unsigned int) (ieee_number_repeat_end_enum
4158 - ieee_number_repeat_start_enum))
4159 {
4160 fprintf (stderr(&__sF[2]), _("IEEE numeric overflow: 0x")("IEEE numeric overflow: 0x"));
4161 fprintf_vma (stderr, v)fprintf ((&__sF[2]), "%016lx", v);
4162 fprintf (stderr(&__sF[2]), "\n");
4163 return FALSE0;
4164 }
4165
4166 if (! ieee_write_byte (info, (int) ieee_number_repeat_start_enum + c)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_number_repeat_start_enum
+ c), 1) : ieee_real_write_byte ((info), ((int) ieee_number_repeat_start_enum
+ c)))
)
4167 return FALSE0;
4168 for (; c > 0; --c, ++p)
4169 {
4170 if (! ieee_write_byte (info, *p)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (*p), 1) : ieee_real_write_byte
((info), (*p)))
)
4171 return FALSE0;
4172 }
4173
4174 return TRUE1;
4175}
4176
4177/* Write out a string. */
4178
4179static bfd_boolean
4180ieee_write_id (struct ieee_handle *info, const char *s)
4181{
4182 unsigned int len;
4183
4184 len = strlen (s);
4185 if (len <= 0x7f)
4186 {
4187 if (! ieee_write_byte (info, len)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (len), 1) : ieee_real_write_byte
((info), (len)))
)
4188 return FALSE0;
4189 }
4190 else if (len <= 0xff)
4191 {
4192 if (! ieee_write_byte (info, (int) ieee_extension_length_1_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_extension_length_1_enum
), 1) : ieee_real_write_byte ((info), ((int) ieee_extension_length_1_enum
)))
4193 || ! ieee_write_byte (info, len)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (len), 1) : ieee_real_write_byte
((info), (len)))
)
4194 return FALSE0;
4195 }
4196 else if (len <= 0xffff)
4197 {
4198 if (! ieee_write_byte (info, (int) ieee_extension_length_2_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_extension_length_2_enum
), 1) : ieee_real_write_byte ((info), ((int) ieee_extension_length_2_enum
)))
4199 || ! ieee_write_2bytes (info, len))
4200 return FALSE0;
4201 }
4202 else
4203 {
4204 fprintf (stderr(&__sF[2]), _("IEEE string length overflow: %u\n")("IEEE string length overflow: %u\n"), len);
4205 return FALSE0;
4206 }
4207
4208 for (; *s != '\0'; s++)
4209 if (! ieee_write_byte (info, *s)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (*s), 1) : ieee_real_write_byte
((info), (*s)))
)
4210 return FALSE0;
4211
4212 return TRUE1;
4213}
4214
4215/* Write out an ASN record. */
4216
4217static bfd_boolean
4218ieee_write_asn (struct ieee_handle *info, unsigned int indx, bfd_vma val)
4219{
4220 return (ieee_write_2bytes (info, (int) ieee_asn_record_enum)
4221 && ieee_write_number (info, indx)
4222 && ieee_write_number (info, val));
4223}
4224
4225/* Write out an ATN65 record. */
4226
4227static bfd_boolean
4228ieee_write_atn65 (struct ieee_handle *info, unsigned int indx, const char *s)
4229{
4230 return (ieee_write_2bytes (info, (int) ieee_atn_record_enum)
4231 && ieee_write_number (info, indx)
4232 && ieee_write_number (info, 0)
4233 && ieee_write_number (info, 65)
4234 && ieee_write_id (info, s));
4235}
4236
4237/* Push a type index onto the type stack. */
4238
4239static bfd_boolean
4240ieee_push_type (struct ieee_handle *info, unsigned int indx,
4241 unsigned int size, bfd_boolean unsignedp, bfd_boolean localp)
4242{
4243 struct ieee_type_stack *ts;
4244
4245 ts = (struct ieee_type_stack *) xmalloc (sizeof *ts);
4246 memset (ts, 0, sizeof *ts);
4247
4248 ts->type.indx = indx;
4249 ts->type.size = size;
4250 ts->type.unsignedp = unsignedp;
4251 ts->type.localp = localp;
4252
4253 ts->next = info->type_stack;
4254 info->type_stack = ts;
4255
4256 return TRUE1;
4257}
4258
4259/* Pop a type index off the type stack. */
4260
4261static unsigned int
4262ieee_pop_type (struct ieee_handle *info)
4263{
4264 return ieee_pop_type_used (info, TRUE1);
4265}
4266
4267/* Pop an unused type index off the type stack. */
4268
4269static void
4270ieee_pop_unused_type (struct ieee_handle *info)
4271{
4272 (void) ieee_pop_type_used (info, FALSE0);
4273}
4274
4275/* Pop a used or unused type index off the type stack. */
4276
4277static unsigned int
4278ieee_pop_type_used (struct ieee_handle *info, bfd_boolean used)
4279{
4280 struct ieee_type_stack *ts;
4281 unsigned int ret;
4282
4283 ts = info->type_stack;
4284 assert (ts != NULL)((ts != ((void*)0)) ? (void)0 : __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 4284, __func__, "ts != NULL"))
;
4285
4286 /* If this is a function type, and we need it, we need to append the
4287 actual definition to the typedef block now. */
4288 if (used && ! ieee_buffer_emptyp (&ts->type.fndef)((&ts->type.fndef)->head == ((void*)0)))
4289 {
4290 struct ieee_buflist *buflist;
4291
4292 if (ts->type.localp)
4293 {
4294 /* Make sure we have started the types block. */
4295 if (ieee_buffer_emptyp (&info->types)((&info->types)->head == ((void*)0)))
4296 {
4297 if (! ieee_change_buffer (info, &info->types)
4298 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_bb_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_bb_record_enum
)))
4299 || ! ieee_write_byte (info, 1)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (1), 1) : ieee_real_write_byte
((info), (1)))
4300 || ! ieee_write_number (info, 0)
4301 || ! ieee_write_id (info, info->modname))
4302 return FALSE0;
4303 }
4304 buflist = &info->types;
4305 }
4306 else
4307 {
4308 /* Make sure we started the global type block. */
4309 if (ieee_buffer_emptyp (&info->global_types)((&info->global_types)->head == ((void*)0)))
4310 {
4311 if (! ieee_change_buffer (info, &info->global_types)
4312 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_bb_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_bb_record_enum
)))
4313 || ! ieee_write_byte (info, 2)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (2), 1) : ieee_real_write_byte
((info), (2)))
4314 || ! ieee_write_number (info, 0)
4315 || ! ieee_write_id (info, ""))
4316 return FALSE0;
4317 }
4318 buflist = &info->global_types;
4319 }
4320
4321 if (! ieee_append_buffer (info, buflist, &ts->type.fndef))
4322 return FALSE0;
4323 }
4324
4325 ret = ts->type.indx;
4326 info->type_stack = ts->next;
4327 free (ts);
4328 return ret;
4329}
4330
4331/* Add a range of bytes included in the current compilation unit. */
4332
4333static bfd_boolean
4334ieee_add_range (struct ieee_handle *info, bfd_boolean global, bfd_vma low,
4335 bfd_vma high)
4336{
4337 struct ieee_range **plist, *r, **pr;
4338
4339 if (low == (bfd_vma) -1 || high == (bfd_vma) -1 || low == high)
4340 return TRUE1;
4341
4342 if (global)
4343 plist = &info->global_ranges;
4344 else
4345 plist = &info->ranges;
4346
4347 for (r = *plist; r != NULL((void*)0); r = r->next)
4348 {
4349 if (high >= r->low && low <= r->high)
4350 {
4351 /* The new range overlaps r. */
4352 if (low < r->low)
4353 r->low = low;
4354 if (high > r->high)
4355 r->high = high;
4356 pr = &r->next;
4357 while (*pr != NULL((void*)0) && (*pr)->low <= r->high)
4358 {
4359 struct ieee_range *n;
4360
4361 if ((*pr)->high > r->high)
4362 r->high = (*pr)->high;
4363 n = (*pr)->next;
4364 free (*pr);
4365 *pr = n;
4366 }
4367 return TRUE1;
4368 }
4369 }
4370
4371 r = (struct ieee_range *) xmalloc (sizeof *r);
4372 memset (r, 0, sizeof *r);
4373
4374 r->low = low;
4375 r->high = high;
4376
4377 /* Store the ranges sorted by address. */
4378 for (pr = plist; *pr != NULL((void*)0); pr = &(*pr)->next)
4379 if ((*pr)->low > high)
4380 break;
4381 r->next = *pr;
4382 *pr = r;
4383
4384 return TRUE1;
4385}
4386
4387/* Start a new range for which we only have the low address. */
4388
4389static bfd_boolean
4390ieee_start_range (struct ieee_handle *info, bfd_vma low)
4391{
4392 struct ieee_range *r;
4393
4394 r = (struct ieee_range *) xmalloc (sizeof *r);
4395 memset (r, 0, sizeof *r);
4396 r->low = low;
4397 r->next = info->pending_ranges;
4398 info->pending_ranges = r;
4399 return TRUE1;
4400}
4401
4402/* Finish a range started by ieee_start_range. */
4403
4404static bfd_boolean
4405ieee_end_range (struct ieee_handle *info, bfd_vma high)
4406{
4407 struct ieee_range *r;
4408 bfd_vma low;
4409
4410 assert (info->pending_ranges != NULL)((info->pending_ranges != ((void*)0)) ? (void)0 : __assert2
("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c", 4410, __func__
, "info->pending_ranges != NULL"))
;
4411 r = info->pending_ranges;
4412 low = r->low;
4413 info->pending_ranges = r->next;
4414 free (r);
4415 return ieee_add_range (info, FALSE0, low, high);
4416}
4417
4418/* Start defining a type. */
4419
4420static bfd_boolean
4421ieee_define_type (struct ieee_handle *info, unsigned int size,
4422 bfd_boolean unsignedp, bfd_boolean localp)
4423{
4424 return ieee_define_named_type (info, (const char *) NULL((void*)0),
4425 (unsigned int) -1, size, unsignedp,
4426 localp, (struct ieee_buflist *) NULL((void*)0));
4427}
4428
4429/* Start defining a named type. */
4430
4431static bfd_boolean
4432ieee_define_named_type (struct ieee_handle *info, const char *name,
4433 unsigned int indx, unsigned int size,
4434 bfd_boolean unsignedp, bfd_boolean localp,
4435 struct ieee_buflist *buflist)
4436{
4437 unsigned int type_indx;
4438 unsigned int name_indx;
4439
4440 if (indx != (unsigned int) -1)
4441 type_indx = indx;
4442 else
4443 {
4444 type_indx = info->type_indx;
4445 ++info->type_indx;
4446 }
4447
4448 name_indx = info->name_indx;
4449 ++info->name_indx;
4450
4451 if (name == NULL((void*)0))
4452 name = "";
4453
4454 /* If we were given a buffer, use it; otherwise, use either the
4455 local or the global type information, and make sure that the type
4456 block is started. */
4457 if (buflist != NULL((void*)0))
4458 {
4459 if (! ieee_change_buffer (info, buflist))
4460 return FALSE0;
4461 }
4462 else if (localp)
4463 {
4464 if (! ieee_buffer_emptyp (&info->types)((&info->types)->head == ((void*)0)))
4465 {
4466 if (! ieee_change_buffer (info, &info->types))
4467 return FALSE0;
4468 }
4469 else
4470 {
4471 if (! ieee_change_buffer (info, &info->types)
4472 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_bb_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_bb_record_enum
)))
4473 || ! ieee_write_byte (info, 1)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (1), 1) : ieee_real_write_byte
((info), (1)))
4474 || ! ieee_write_number (info, 0)
4475 || ! ieee_write_id (info, info->modname))
4476 return FALSE0;
4477 }
4478 }
4479 else
4480 {
4481 if (! ieee_buffer_emptyp (&info->global_types)((&info->global_types)->head == ((void*)0)))
4482 {
4483 if (! ieee_change_buffer (info, &info->global_types))
4484 return FALSE0;
4485 }
4486 else
4487 {
4488 if (! ieee_change_buffer (info, &info->global_types)
4489 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_bb_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_bb_record_enum
)))
4490 || ! ieee_write_byte (info, 2)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (2), 1) : ieee_real_write_byte
((info), (2)))
4491 || ! ieee_write_number (info, 0)
4492 || ! ieee_write_id (info, ""))
4493 return FALSE0;
4494 }
4495 }
4496
4497 /* Push the new type on the type stack, write out an NN record, and
4498 write out the start of a TY record. The caller will then finish
4499 the TY record. */
4500 if (! ieee_push_type (info, type_indx, size, unsignedp, localp))
4501 return FALSE0;
4502
4503 return (ieee_write_byte (info, (int) ieee_nn_record)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_nn_record), 1) :
ieee_real_write_byte ((info), ((int) ieee_nn_record)))
4504 && ieee_write_number (info, name_indx)
4505 && ieee_write_id (info, name)
4506 && ieee_write_byte (info, (int) ieee_ty_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_ty_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_ty_record_enum
)))
4507 && ieee_write_number (info, type_indx)
4508 && ieee_write_byte (info, 0xce)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (0xce), 1) : ieee_real_write_byte
((info), (0xce)))
4509 && ieee_write_number (info, name_indx));
4510}
4511
4512/* Get an entry to the list of modified versions of a type. */
4513
4514static struct ieee_modified_type *
4515ieee_get_modified_info (struct ieee_handle *info, unsigned int indx)
4516{
4517 if (indx >= info->modified_alloc)
4518 {
4519 unsigned int nalloc;
4520
4521 nalloc = info->modified_alloc;
4522 if (nalloc == 0)
4523 nalloc = 16;
4524 while (indx >= nalloc)
4525 nalloc *= 2;
4526 info->modified = ((struct ieee_modified_type *)
4527 xrealloc (info->modified,
4528 nalloc * sizeof *info->modified));
4529 memset (info->modified + info->modified_alloc, 0,
4530 (nalloc - info->modified_alloc) * sizeof *info->modified);
4531 info->modified_alloc = nalloc;
4532 }
4533
4534 return info->modified + indx;
4535}
4536
4537/* Routines for the hash table mapping names to types. */
4538
4539/* Initialize an entry in the hash table. */
4540
4541static struct bfd_hash_entry *
4542ieee_name_type_newfunc (struct bfd_hash_entry *entry,
4543 struct bfd_hash_table *table, const char *string)
4544{
4545 struct ieee_name_type_hash_entry *ret =
4546 (struct ieee_name_type_hash_entry *) entry;
4547
4548 /* Allocate the structure if it has not already been allocated by a
4549 subclass. */
4550 if (ret == NULL((void*)0))
4551 ret = ((struct ieee_name_type_hash_entry *)
4552 bfd_hash_allocate (table, sizeof *ret));
4553 if (ret == NULL((void*)0))
4554 return NULL((void*)0);
4555
4556 /* Call the allocation method of the superclass. */
4557 ret = ((struct ieee_name_type_hash_entry *)
4558 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
4559 if (ret)
4560 {
4561 /* Set local fields. */
4562 ret->types = NULL((void*)0);
4563 }
4564
4565 return (struct bfd_hash_entry *) ret;
4566}
4567
4568/* Look up an entry in the hash table. */
4569
4570#define ieee_name_type_hash_lookup(table, string, create, copy)((struct ieee_name_type_hash_entry *) bfd_hash_lookup (&(
table)->root, (string), (create), (copy)))
\
4571 ((struct ieee_name_type_hash_entry *) \
4572 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
4573
4574/* Traverse the hash table. */
4575
4576#define ieee_name_type_hash_traverse(table, func, info)(bfd_hash_traverse (&(table)->root, (bfd_boolean (*) (
struct bfd_hash_entry *, void *)) (func), (info)))
\
4577 (bfd_hash_traverse \
4578 (&(table)->root, \
4579 (bfd_boolean (*) (struct bfd_hash_entry *, void *)) (func), \
4580 (info)))
4581
4582/* The general routine to write out IEEE debugging information. */
4583
4584bfd_boolean
4585write_ieee_debugging_info (bfd *abfd, void *dhandle)
4586{
4587 struct ieee_handle info;
4588 asection *s;
4589 const char *err;
4590 struct ieee_buf *b;
4591
4592 memset (&info, 0, sizeof info);
4593 info.abfd = abfd;
4594 info.type_indx = 256;
4595 info.name_indx = 32;
4596
4597 if (!bfd_hash_table_init (&info.typedefs.root, ieee_name_type_newfunc,
4598 sizeof (struct ieee_name_type_hash_entry))
4599 || !bfd_hash_table_init (&info.tags.root, ieee_name_type_newfunc,
4600 sizeof (struct ieee_name_type_hash_entry)))
4601 return FALSE0;
4602
4603 if (! ieee_init_buffer (&info, &info.global_types)
4604 || ! ieee_init_buffer (&info, &info.data)
4605 || ! ieee_init_buffer (&info, &info.types)
4606 || ! ieee_init_buffer (&info, &info.vars)
4607 || ! ieee_init_buffer (&info, &info.cxx)
4608 || ! ieee_init_buffer (&info, &info.linenos)
4609 || ! ieee_init_buffer (&info, &info.fntype)
4610 || ! ieee_init_buffer (&info, &info.fnargs))
4611 return FALSE0;
4612
4613 if (! debug_write (dhandle, &ieee_fns, (void *) &info))
4614 return FALSE0;
4615
4616 if (info.filename != NULL((void*)0))
4617 {
4618 if (! ieee_finish_compilation_unit (&info))
4619 return FALSE0;
4620 }
4621
4622 /* Put any undefined tags in the global typedef information. */
4623 info.error = FALSE0;
4624 ieee_name_type_hash_traverse (&info.tags,(bfd_hash_traverse (&(&info.tags)->root, (bfd_boolean
(*) (struct bfd_hash_entry *, void *)) (ieee_write_undefined_tag
), ((void *) &info)))
4625 ieee_write_undefined_tag,(bfd_hash_traverse (&(&info.tags)->root, (bfd_boolean
(*) (struct bfd_hash_entry *, void *)) (ieee_write_undefined_tag
), ((void *) &info)))
4626 (void *) &info)(bfd_hash_traverse (&(&info.tags)->root, (bfd_boolean
(*) (struct bfd_hash_entry *, void *)) (ieee_write_undefined_tag
), ((void *) &info)))
;
4627 if (info.error)
4628 return FALSE0;
4629
4630 /* Prepend the global typedef information to the other data. */
4631 if (! ieee_buffer_emptyp (&info.global_types)((&info.global_types)->head == ((void*)0)))
4632 {
4633 /* The HP debugger seems to have a bug in which it ignores the
4634 last entry in the global types, so we add a dummy entry. */
4635 if (! ieee_change_buffer (&info, &info.global_types)
4636 || ! ieee_write_byte (&info, (int) ieee_nn_record)((&info)->curbuf->c < (490) ? ((&info)->curbuf
->buf[(&info)->curbuf->c++] = ((int) ieee_nn_record
), 1) : ieee_real_write_byte ((&info), ((int) ieee_nn_record
)))
4637 || ! ieee_write_number (&info, info.name_indx)
4638 || ! ieee_write_id (&info, "")
4639 || ! ieee_write_byte (&info, (int) ieee_ty_record_enum)((&info)->curbuf->c < (490) ? ((&info)->curbuf
->buf[(&info)->curbuf->c++] = ((int) ieee_ty_record_enum
), 1) : ieee_real_write_byte ((&info), ((int) ieee_ty_record_enum
)))
4640 || ! ieee_write_number (&info, info.type_indx)
4641 || ! ieee_write_byte (&info, 0xce)((&info)->curbuf->c < (490) ? ((&info)->curbuf
->buf[(&info)->curbuf->c++] = (0xce), 1) : ieee_real_write_byte
((&info), (0xce)))
4642 || ! ieee_write_number (&info, info.name_indx)
4643 || ! ieee_write_number (&info, 'P')
4644 || ! ieee_write_number (&info, (int) builtin_void + 32)
4645 || ! ieee_write_byte (&info, (int) ieee_be_record_enum)((&info)->curbuf->c < (490) ? ((&info)->curbuf
->buf[(&info)->curbuf->c++] = ((int) ieee_be_record_enum
), 1) : ieee_real_write_byte ((&info), ((int) ieee_be_record_enum
)))
)
4646 return FALSE0;
4647
4648 if (! ieee_append_buffer (&info, &info.global_types, &info.data))
4649 return FALSE0;
4650 info.data = info.global_types;
4651 }
4652
4653 /* Make sure that we have declare BB11 blocks for each range in the
4654 file. They are added to info->vars. */
4655 info.error = FALSE0;
4656 if (! ieee_init_buffer (&info, &info.vars))
4657 return FALSE0;
4658 bfd_map_over_sections (abfd, ieee_add_bb11_blocks, (void *) &info);
4659 if (info.error)
4660 return FALSE0;
4661 if (! ieee_buffer_emptyp (&info.vars)((&info.vars)->head == ((void*)0)))
4662 {
4663 if (! ieee_change_buffer (&info, &info.vars)
4664 || ! ieee_write_byte (&info, (int) ieee_be_record_enum)((&info)->curbuf->c < (490) ? ((&info)->curbuf
->buf[(&info)->curbuf->c++] = ((int) ieee_be_record_enum
), 1) : ieee_real_write_byte ((&info), ((int) ieee_be_record_enum
)))
)
4665 return FALSE0;
4666
4667 if (! ieee_append_buffer (&info, &info.data, &info.vars))
4668 return FALSE0;
4669 }
4670
4671 /* Now all the data is in info.data. Write it out to the BFD. We
4672 normally would need to worry about whether all the other sections
4673 are set up yet, but the IEEE backend will handle this particular
4674 case correctly regardless. */
4675 if (ieee_buffer_emptyp (&info.data)((&info.data)->head == ((void*)0)))
4676 {
4677 /* There is no debugging information. */
4678 return TRUE1;
4679 }
4680 err = NULL((void*)0);
4681 s = bfd_make_section (abfd, ".debug");
4682 if (s == NULL((void*)0))
4683 err = "bfd_make_section";
4684 if (err == NULL((void*)0))
4685 {
4686 if (! bfd_set_section_flags (abfd, s, SEC_DEBUGGING0x2000 | SEC_HAS_CONTENTS0x100))
4687 err = "bfd_set_section_flags";
4688 }
4689 if (err == NULL((void*)0))
4690 {
4691 bfd_size_type size;
4692
4693 size = 0;
4694 for (b = info.data.head; b != NULL((void*)0); b = b->next)
4695 size += b->c;
4696 if (! bfd_set_section_size (abfd, s, size))
4697 err = "bfd_set_section_size";
4698 }
4699 if (err == NULL((void*)0))
4700 {
4701 file_ptr offset;
4702
4703 offset = 0;
4704 for (b = info.data.head; b != NULL((void*)0); b = b->next)
4705 {
4706 if (! bfd_set_section_contents (abfd, s, b->buf, offset, b->c))
4707 {
4708 err = "bfd_set_section_contents";
4709 break;
4710 }
4711 offset += b->c;
4712 }
4713 }
4714
4715 if (err != NULL((void*)0))
4716 {
4717 fprintf (stderr(&__sF[2]), "%s: %s: %s\n", bfd_get_filename (abfd)((char *) (abfd)->filename), err,
4718 bfd_errmsg (bfd_get_error ()));
4719 return FALSE0;
4720 }
4721
4722 bfd_hash_table_free (&info.typedefs.root);
4723 bfd_hash_table_free (&info.tags.root);
4724
4725 return TRUE1;
4726}
4727
4728/* Write out information for an undefined tag. This is called via
4729 ieee_name_type_hash_traverse. */
4730
4731static bfd_boolean
4732ieee_write_undefined_tag (struct ieee_name_type_hash_entry *h, void *p)
4733{
4734 struct ieee_handle *info = (struct ieee_handle *) p;
4735 struct ieee_name_type *nt;
4736
4737 for (nt = h->types; nt != NULL((void*)0); nt = nt->next)
4738 {
4739 unsigned int name_indx;
4740 char code;
4741
4742 if (nt->kind == DEBUG_KIND_ILLEGAL)
4743 continue;
4744
4745 if (ieee_buffer_emptyp (&info->global_types)((&info->global_types)->head == ((void*)0)))
4746 {
4747 if (! ieee_change_buffer (info, &info->global_types)
4748 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_bb_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_bb_record_enum
)))
4749 || ! ieee_write_byte (info, 2)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (2), 1) : ieee_real_write_byte
((info), (2)))
4750 || ! ieee_write_number (info, 0)
4751 || ! ieee_write_id (info, ""))
4752 {
4753 info->error = TRUE1;
4754 return FALSE0;
4755 }
4756 }
4757 else
4758 {
4759 if (! ieee_change_buffer (info, &info->global_types))
4760 {
4761 info->error = TRUE1;
4762 return FALSE0;
4763 }
4764 }
4765
4766 name_indx = info->name_indx;
4767 ++info->name_indx;
4768 if (! ieee_write_byte (info, (int) ieee_nn_record)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_nn_record), 1) :
ieee_real_write_byte ((info), ((int) ieee_nn_record)))
4769 || ! ieee_write_number (info, name_indx)
4770 || ! ieee_write_id (info, nt->type.name)
4771 || ! ieee_write_byte (info, (int) ieee_ty_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_ty_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_ty_record_enum
)))
4772 || ! ieee_write_number (info, nt->type.indx)
4773 || ! ieee_write_byte (info, 0xce)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (0xce), 1) : ieee_real_write_byte
((info), (0xce)))
4774 || ! ieee_write_number (info, name_indx))
4775 {
4776 info->error = TRUE1;
4777 return FALSE0;
4778 }
4779
4780 switch (nt->kind)
4781 {
4782 default:
4783 abort ();
4784 info->error = TRUE1;
4785 return FALSE0;
4786 case DEBUG_KIND_STRUCT:
4787 case DEBUG_KIND_CLASS:
4788 code = 'S';
4789 break;
4790 case DEBUG_KIND_UNION:
4791 case DEBUG_KIND_UNION_CLASS:
4792 code = 'U';
4793 break;
4794 case DEBUG_KIND_ENUM:
4795 code = 'E';
4796 break;
4797 }
4798 if (! ieee_write_number (info, code)
4799 || ! ieee_write_number (info, 0))
4800 {
4801 info->error = TRUE1;
4802 return FALSE0;
4803 }
4804 }
4805
4806 return TRUE1;
4807}
4808
4809/* Start writing out information for a compilation unit. */
4810
4811static bfd_boolean
4812ieee_start_compilation_unit (void *p, const char *filename)
4813{
4814 struct ieee_handle *info = (struct ieee_handle *) p;
4815 const char *modname;
4816#ifdef HAVE_DOS_BASED_FILE_SYSTEM
4817 const char *backslash;
4818#endif
4819 char *c, *s;
4820 unsigned int nindx;
4821
4822 if (info->filename != NULL((void*)0))
4823 {
4824 if (! ieee_finish_compilation_unit (info))
4825 return FALSE0;
4826 }
4827
4828 info->filename = filename;
4829 modname = strrchr (filename, '/');
4830#ifdef HAVE_DOS_BASED_FILE_SYSTEM
4831 /* We could have a mixed forward/back slash case. */
4832 backslash = strrchr (filename, '\\');
4833 if (modname == NULL((void*)0) || (backslash != NULL((void*)0) && backslash > modname))
4834 modname = backslash;
4835#endif
4836
4837 if (modname != NULL((void*)0))
4838 ++modname;
4839#ifdef HAVE_DOS_BASED_FILE_SYSTEM
4840 else if (filename[0] && filename[1] == ':')
4841 modname = filename + 2;
4842#endif
4843 else
4844 modname = filename;
4845
4846 c = xstrdup (modname);
4847 s = strrchr (c, '.');
4848 if (s != NULL((void*)0))
4849 *s = '\0';
4850 info->modname = c;
4851
4852 if (! ieee_init_buffer (info, &info->types)
4853 || ! ieee_init_buffer (info, &info->vars)
4854 || ! ieee_init_buffer (info, &info->cxx)
4855 || ! ieee_init_buffer (info, &info->linenos))
4856 return FALSE0;
4857 info->ranges = NULL((void*)0);
4858
4859 /* Always include a BB1 and a BB3 block. That is what the output of
4860 the MRI linker seems to look like. */
4861 if (! ieee_change_buffer (info, &info->types)
4862 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_bb_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_bb_record_enum
)))
4863 || ! ieee_write_byte (info, 1)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (1), 1) : ieee_real_write_byte
((info), (1)))
4864 || ! ieee_write_number (info, 0)
4865 || ! ieee_write_id (info, info->modname))
4866 return FALSE0;
4867
4868 nindx = info->name_indx;
Value stored to 'nindx' is never read
4869 ++info->name_indx;
4870 if (! ieee_change_buffer (info, &info->vars)
4871 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_bb_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_bb_record_enum
)))
4872 || ! ieee_write_byte (info, 3)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (3), 1) : ieee_real_write_byte
((info), (3)))
4873 || ! ieee_write_number (info, 0)
4874 || ! ieee_write_id (info, info->modname))
4875 return FALSE0;
4876
4877 return TRUE1;
4878}
4879
4880/* Finish up a compilation unit. */
4881
4882static bfd_boolean
4883ieee_finish_compilation_unit (struct ieee_handle *info)
4884{
4885 struct ieee_range *r;
4886
4887 if (! ieee_buffer_emptyp (&info->types)((&info->types)->head == ((void*)0)))
4888 {
4889 if (! ieee_change_buffer (info, &info->types)
4890 || ! ieee_write_byte (info, (int) ieee_be_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_be_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_be_record_enum
)))
)
4891 return FALSE0;
4892 }
4893
4894 if (! ieee_buffer_emptyp (&info->cxx)((&info->cxx)->head == ((void*)0)))
4895 {
4896 /* Append any C++ information to the global function and
4897 variable information. */
4898 assert (! ieee_buffer_emptyp (&info->vars))((! ((&info->vars)->head == ((void*)0))) ? (void)0 :
__assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 4898, __func__, "! ieee_buffer_emptyp (&info->vars)"
))
;
4899 if (! ieee_change_buffer (info, &info->vars))
4900 return FALSE0;
4901
4902 /* We put the pmisc records in a dummy procedure, just as the
4903 MRI compiler does. */
4904 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_bb_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_bb_record_enum
)))
4905 || ! ieee_write_byte (info, 6)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (6), 1) : ieee_real_write_byte
((info), (6)))
4906 || ! ieee_write_number (info, 0)
4907 || ! ieee_write_id (info, "__XRYCPP")
4908 || ! ieee_write_number (info, 0)
4909 || ! ieee_write_number (info, 0)
4910 || ! ieee_write_number (info, info->highaddr - 1)
4911 || ! ieee_append_buffer (info, &info->vars, &info->cxx)
4912 || ! ieee_change_buffer (info, &info->vars)
4913 || ! ieee_write_byte (info, (int) ieee_be_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_be_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_be_record_enum
)))
4914 || ! ieee_write_number (info, info->highaddr - 1))
4915 return FALSE0;
4916 }
4917
4918 if (! ieee_buffer_emptyp (&info->vars)((&info->vars)->head == ((void*)0)))
4919 {
4920 if (! ieee_change_buffer (info, &info->vars)
4921 || ! ieee_write_byte (info, (int) ieee_be_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_be_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_be_record_enum
)))
)
4922 return FALSE0;
4923 }
4924
4925 if (info->pending_lineno_filename != NULL((void*)0))
4926 {
4927 /* Force out the pending line number. */
4928 if (! ieee_lineno ((void *) info, (const char *) NULL((void*)0), 0, (bfd_vma) -1))
4929 return FALSE0;
4930 }
4931 if (! ieee_buffer_emptyp (&info->linenos)((&info->linenos)->head == ((void*)0)))
4932 {
4933 if (! ieee_change_buffer (info, &info->linenos)
4934 || ! ieee_write_byte (info, (int) ieee_be_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_be_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_be_record_enum
)))
)
4935 return FALSE0;
4936 if (strcmp (info->filename, info->lineno_filename) != 0)
4937 {
4938 /* We were not in the main file. We just closed the
4939 included line number block, and now we must close the
4940 main line number block. */
4941 if (! ieee_write_byte (info, (int) ieee_be_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_be_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_be_record_enum
)))
)
4942 return FALSE0;
4943 }
4944 }
4945
4946 if (! ieee_append_buffer (info, &info->data, &info->types)
4947 || ! ieee_append_buffer (info, &info->data, &info->vars)
4948 || ! ieee_append_buffer (info, &info->data, &info->linenos))
4949 return FALSE0;
4950
4951 /* Build BB10/BB11 blocks based on the ranges we recorded. */
4952 if (! ieee_change_buffer (info, &info->data))
4953 return FALSE0;
4954
4955 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_bb_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_bb_record_enum
)))
4956 || ! ieee_write_byte (info, 10)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (10), 1) : ieee_real_write_byte
((info), (10)))
4957 || ! ieee_write_number (info, 0)
4958 || ! ieee_write_id (info, info->modname)
4959 || ! ieee_write_id (info, "")
4960 || ! ieee_write_number (info, 0)
4961 || ! ieee_write_id (info, "GNU objcopy"))
4962 return FALSE0;
4963
4964 for (r = info->ranges; r != NULL((void*)0); r = r->next)
4965 {
4966 bfd_vma low, high;
4967 asection *s;
4968 int kind;
4969
4970 low = r->low;
4971 high = r->high;
4972
4973 /* Find the section corresponding to this range. */
4974 for (s = info->abfd->sections; s != NULL((void*)0); s = s->next)
4975 {
4976 if (bfd_get_section_vma (info->abfd, s)((s)->vma + 0) <= low
4977 && high <= (bfd_get_section_vma (info->abfd, s)((s)->vma + 0)
4978 + bfd_section_size (info->abfd, s)((s)->size)))
4979 break;
4980 }
4981
4982 if (s == NULL((void*)0))
4983 {
4984 /* Just ignore this range. */
4985 continue;
4986 }
4987
4988 /* Coalesce ranges if it seems reasonable. */
4989 while (r->next != NULL((void*)0)
4990 && high + 0x1000 >= r->next->low
4991 && (r->next->high
4992 <= (bfd_get_section_vma (info->abfd, s)((s)->vma + 0)
4993 + bfd_section_size (info->abfd, s)((s)->size))))
4994 {
4995 r = r->next;
4996 high = r->high;
4997 }
4998
4999 if ((s->flags & SEC_CODE0x010) != 0)
5000 kind = 1;
5001 else if ((s->flags & SEC_READONLY0x008) != 0)
5002 kind = 3;
5003 else
5004 kind = 2;
5005
5006 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_bb_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_bb_record_enum
)))
5007 || ! ieee_write_byte (info, 11)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (11), 1) : ieee_real_write_byte
((info), (11)))
5008 || ! ieee_write_number (info, 0)
5009 || ! ieee_write_id (info, "")
5010 || ! ieee_write_number (info, kind)
5011 || ! ieee_write_number (info, s->index + IEEE_SECTION_NUMBER_BASE1)
5012 || ! ieee_write_number (info, low)
5013 || ! ieee_write_byte (info, (int) ieee_be_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_be_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_be_record_enum
)))
5014 || ! ieee_write_number (info, high - low))
5015 return FALSE0;
5016
5017 /* Add this range to the list of global ranges. */
5018 if (! ieee_add_range (info, TRUE1, low, high))
5019 return FALSE0;
5020 }
5021
5022 if (! ieee_write_byte (info, (int) ieee_be_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_be_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_be_record_enum
)))
)
5023 return FALSE0;
5024
5025 return TRUE1;
5026}
5027
5028/* Add BB11 blocks describing each range that we have not already
5029 described. */
5030
5031static void
5032ieee_add_bb11_blocks (bfd *abfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), asection *sec, void *data)
5033{
5034 struct ieee_handle *info = (struct ieee_handle *) data;
5035 bfd_vma low, high;
5036 struct ieee_range *r;
5037
5038 low = bfd_get_section_vma (abfd, sec)((sec)->vma + 0);
5039 high = low + bfd_section_size (abfd, sec)((sec)->size);
5040
5041 /* Find the first range at or after this section. The ranges are
5042 sorted by address. */
5043 for (r = info->global_ranges; r != NULL((void*)0); r = r->next)
5044 if (r->high > low)
5045 break;
5046
5047 while (low < high)
5048 {
5049 if (r == NULL((void*)0) || r->low >= high)
5050 {
5051 if (! ieee_add_bb11 (info, sec, low, high))
5052 info->error = TRUE1;
5053 return;
5054 }
5055
5056 if (low < r->low
5057 && r->low - low > 0x100)
5058 {
5059 if (! ieee_add_bb11 (info, sec, low, r->low))
5060 {
5061 info->error = TRUE1;
5062 return;
5063 }
5064 }
5065 low = r->high;
5066
5067 r = r->next;
5068 }
5069}
5070
5071/* Add a single BB11 block for a range. We add it to info->vars. */
5072
5073static bfd_boolean
5074ieee_add_bb11 (struct ieee_handle *info, asection *sec, bfd_vma low,
5075 bfd_vma high)
5076{
5077 int kind;
5078
5079 if (! ieee_buffer_emptyp (&info->vars)((&info->vars)->head == ((void*)0)))
5080 {
5081 if (! ieee_change_buffer (info, &info->vars))
5082 return FALSE0;
5083 }
5084 else
5085 {
5086 const char *filename, *modname;
5087#ifdef HAVE_DOS_BASED_FILE_SYSTEM
5088 const char *backslash;
5089#endif
5090 char *c, *s;
5091
5092 /* Start the enclosing BB10 block. */
5093 filename = bfd_get_filename (info->abfd)((char *) (info->abfd)->filename);
5094 modname = strrchr (filename, '/');
5095#ifdef HAVE_DOS_BASED_FILE_SYSTEM
5096 backslash = strrchr (filename, '\\');
5097 if (modname == NULL((void*)0) || (backslash != NULL((void*)0) && backslash > modname))
5098 modname = backslash;
5099#endif
5100
5101 if (modname != NULL((void*)0))
5102 ++modname;
5103#ifdef HAVE_DOS_BASED_FILE_SYSTEM
5104 else if (filename[0] && filename[1] == ':')
5105 modname = filename + 2;
5106#endif
5107 else
5108 modname = filename;
5109
5110 c = xstrdup (modname);
5111 s = strrchr (c, '.');
5112 if (s != NULL((void*)0))
5113 *s = '\0';
5114
5115 if (! ieee_change_buffer (info, &info->vars)
5116 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_bb_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_bb_record_enum
)))
5117 || ! ieee_write_byte (info, 10)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (10), 1) : ieee_real_write_byte
((info), (10)))
5118 || ! ieee_write_number (info, 0)
5119 || ! ieee_write_id (info, c)
5120 || ! ieee_write_id (info, "")
5121 || ! ieee_write_number (info, 0)
5122 || ! ieee_write_id (info, "GNU objcopy"))
5123 return FALSE0;
5124
5125 free (c);
5126 }
5127
5128 if ((sec->flags & SEC_CODE0x010) != 0)
5129 kind = 1;
5130 else if ((sec->flags & SEC_READONLY0x008) != 0)
5131 kind = 3;
5132 else
5133 kind = 2;
5134
5135 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_bb_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_bb_record_enum
)))
5136 || ! ieee_write_byte (info, 11)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (11), 1) : ieee_real_write_byte
((info), (11)))
5137 || ! ieee_write_number (info, 0)
5138 || ! ieee_write_id (info, "")
5139 || ! ieee_write_number (info, kind)
5140 || ! ieee_write_number (info, sec->index + IEEE_SECTION_NUMBER_BASE1)
5141 || ! ieee_write_number (info, low)
5142 || ! ieee_write_byte (info, (int) ieee_be_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_be_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_be_record_enum
)))
5143 || ! ieee_write_number (info, high - low))
5144 return FALSE0;
5145
5146 return TRUE1;
5147}
5148
5149/* Start recording information from a particular source file. This is
5150 used to record which file defined which types, variables, etc. It
5151 is not used for line numbers, since the lineno entry point passes
5152 down the file name anyhow. IEEE debugging information doesn't seem
5153 to store this information anywhere. */
5154
5155static bfd_boolean
5156ieee_start_source (void *p ATTRIBUTE_UNUSED__attribute__ ((__unused__)),
5157 const char *filename ATTRIBUTE_UNUSED__attribute__ ((__unused__)))
5158{
5159 return TRUE1;
5160}
5161
5162/* Make an empty type. */
5163
5164static bfd_boolean
5165ieee_empty_type (void *p)
5166{
5167 struct ieee_handle *info = (struct ieee_handle *) p;
5168
5169 return ieee_push_type (info, (int) builtin_unknown, 0, FALSE0, FALSE0);
5170}
5171
5172/* Make a void type. */
5173
5174static bfd_boolean
5175ieee_void_type (void *p)
5176{
5177 struct ieee_handle *info = (struct ieee_handle *) p;
5178
5179 return ieee_push_type (info, (int) builtin_void, 0, FALSE0, FALSE0);
5180}
5181
5182/* Make an integer type. */
5183
5184static bfd_boolean
5185ieee_int_type (void *p, unsigned int size, bfd_boolean unsignedp)
5186{
5187 struct ieee_handle *info = (struct ieee_handle *) p;
5188 unsigned int indx;
5189
5190 switch (size)
5191 {
5192 case 1:
5193 indx = (int) builtin_signed_char;
5194 break;
5195 case 2:
5196 indx = (int) builtin_signed_short_int;
5197 break;
5198 case 4:
5199 indx = (int) builtin_signed_long;
5200 break;
5201 case 8:
5202 indx = (int) builtin_signed_long_long;
5203 break;
5204 default:
5205 fprintf (stderr(&__sF[2]), _("IEEE unsupported integer type size %u\n")("IEEE unsupported integer type size %u\n"), size);
5206 return FALSE0;
5207 }
5208
5209 if (unsignedp)
5210 ++indx;
5211
5212 return ieee_push_type (info, indx, size, unsignedp, FALSE0);
5213}
5214
5215/* Make a floating point type. */
5216
5217static bfd_boolean
5218ieee_float_type (void *p, unsigned int size)
5219{
5220 struct ieee_handle *info = (struct ieee_handle *) p;
5221 unsigned int indx;
5222
5223 switch (size)
5224 {
5225 case 4:
5226 indx = (int) builtin_float;
5227 break;
5228 case 8:
5229 indx = (int) builtin_double;
5230 break;
5231 case 12:
5232 /* FIXME: This size really depends upon the processor. */
5233 indx = (int) builtin_long_double;
5234 break;
5235 case 16:
5236 indx = (int) builtin_long_long_double;
5237 break;
5238 default:
5239 fprintf (stderr(&__sF[2]), _("IEEE unsupported float type size %u\n")("IEEE unsupported float type size %u\n"), size);
5240 return FALSE0;
5241 }
5242
5243 return ieee_push_type (info, indx, size, FALSE0, FALSE0);
5244}
5245
5246/* Make a complex type. */
5247
5248static bfd_boolean
5249ieee_complex_type (void *p, unsigned int size)
5250{
5251 struct ieee_handle *info = (struct ieee_handle *) p;
5252 char code;
5253
5254 switch (size)
5255 {
5256 case 4:
5257 if (info->complex_float_index != 0)
5258 return ieee_push_type (info, info->complex_float_index, size * 2,
5259 FALSE0, FALSE0);
5260 code = 'c';
5261 break;
5262 case 12:
5263 case 16:
5264 /* These cases can be output by gcc -gstabs. Outputting the
5265 wrong type is better than crashing. */
5266 case 8:
5267 if (info->complex_double_index != 0)
5268 return ieee_push_type (info, info->complex_double_index, size * 2,
5269 FALSE0, FALSE0);
5270 code = 'd';
5271 break;
5272 default:
5273 fprintf (stderr(&__sF[2]), _("IEEE unsupported complex type size %u\n")("IEEE unsupported complex type size %u\n"), size);
5274 return FALSE0;
5275 }
5276
5277 /* FIXME: I don't know what the string is for. */
5278 if (! ieee_define_type (info, size * 2, FALSE0, FALSE0)
5279 || ! ieee_write_number (info, code)
5280 || ! ieee_write_id (info, ""))
5281 return FALSE0;
5282
5283 if (size == 4)
5284 info->complex_float_index = info->type_stack->type.indx;
5285 else
5286 info->complex_double_index = info->type_stack->type.indx;
5287
5288 return TRUE1;
5289}
5290
5291/* Make a boolean type. IEEE doesn't support these, so we just make
5292 an integer type instead. */
5293
5294static bfd_boolean
5295ieee_bool_type (void *p, unsigned int size)
5296{
5297 return ieee_int_type (p, size, TRUE1);
5298}
5299
5300/* Make an enumeration. */
5301
5302static bfd_boolean
5303ieee_enum_type (void *p, const char *tag, const char **names,
5304 bfd_signed_vma *vals)
5305{
5306 struct ieee_handle *info = (struct ieee_handle *) p;
5307 struct ieee_defined_enum *e;
5308 bfd_boolean localp, simple;
5309 unsigned int indx;
5310 int i = 0;
5311
5312 localp = FALSE0;
5313 indx = (unsigned int) -1;
5314 for (e = info->enums; e != NULL((void*)0); e = e->next)
5315 {
5316 if (tag == NULL((void*)0))
5317 {
5318 if (e->tag != NULL((void*)0))
5319 continue;
5320 }
5321 else
5322 {
5323 if (e->tag == NULL((void*)0)
5324 || tag[0] != e->tag[0]
5325 || strcmp (tag, e->tag) != 0)
5326 continue;
5327 }
5328
5329 if (! e->defined)
5330 {
5331 /* This enum tag has been seen but not defined. */
5332 indx = e->indx;
5333 break;
5334 }
5335
5336 if (names != NULL((void*)0) && e->names != NULL((void*)0))
5337 {
5338 for (i = 0; names[i] != NULL((void*)0) && e->names[i] != NULL((void*)0); i++)
5339 {
5340 if (names[i][0] != e->names[i][0]
5341 || vals[i] != e->vals[i]
5342 || strcmp (names[i], e->names[i]) != 0)
5343 break;
5344 }
5345 }
5346
5347 if ((names == NULL((void*)0) && e->names == NULL((void*)0))
5348 || (names != NULL((void*)0)
5349 && e->names != NULL((void*)0)
5350 && names[i] == NULL((void*)0)
5351 && e->names[i] == NULL((void*)0)))
5352 {
5353 /* We've seen this enum before. */
5354 return ieee_push_type (info, e->indx, 0, TRUE1, FALSE0);
5355 }
5356
5357 if (tag != NULL((void*)0))
5358 {
5359 /* We've already seen an enum of the same name, so we must make
5360 sure to output this one locally. */
5361 localp = TRUE1;
5362 break;
5363 }
5364 }
5365
5366 /* If this is a simple enumeration, in which the values start at 0
5367 and always increment by 1, we can use type E. Otherwise we must
5368 use type N. */
5369
5370 simple = TRUE1;
5371 if (names != NULL((void*)0))
5372 {
5373 for (i = 0; names[i] != NULL((void*)0); i++)
5374 {
5375 if (vals[i] != i)
5376 {
5377 simple = FALSE0;
5378 break;
5379 }
5380 }
5381 }
5382
5383 if (! ieee_define_named_type (info, tag, indx, 0, TRUE1, localp,
5384 (struct ieee_buflist *) NULL((void*)0))
5385 || ! ieee_write_number (info, simple ? 'E' : 'N'))
5386 return FALSE0;
5387 if (simple)
5388 {
5389 /* FIXME: This is supposed to be the enumeration size, but we
5390 don't store that. */
5391 if (! ieee_write_number (info, 4))
5392 return FALSE0;
5393 }
5394 if (names != NULL((void*)0))
5395 {
5396 for (i = 0; names[i] != NULL((void*)0); i++)
5397 {
5398 if (! ieee_write_id (info, names[i]))
5399 return FALSE0;
5400 if (! simple)
5401 {
5402 if (! ieee_write_number (info, vals[i]))
5403 return FALSE0;
5404 }
5405 }
5406 }
5407
5408 if (! localp)
5409 {
5410 if (indx == (unsigned int) -1)
5411 {
5412 e = (struct ieee_defined_enum *) xmalloc (sizeof *e);
5413 memset (e, 0, sizeof *e);
5414 e->indx = info->type_stack->type.indx;
5415 e->tag = tag;
5416
5417 e->next = info->enums;
5418 info->enums = e;
5419 }
5420
5421 e->names = names;
5422 e->vals = vals;
5423 e->defined = TRUE1;
5424 }
5425
5426 return TRUE1;
5427}
5428
5429/* Make a pointer type. */
5430
5431static bfd_boolean
5432ieee_pointer_type (void *p)
5433{
5434 struct ieee_handle *info = (struct ieee_handle *) p;
5435 bfd_boolean localp;
5436 unsigned int indx;
5437 struct ieee_modified_type *m = NULL((void*)0);
5438
5439 localp = info->type_stack->type.localp;
5440 indx = ieee_pop_type (info);
5441
5442 /* A pointer to a simple builtin type can be obtained by adding 32.
5443 FIXME: Will this be a short pointer, and will that matter? */
5444 if (indx < 32)
5445 return ieee_push_type (info, indx + 32, 0, TRUE1, FALSE0);
5446
5447 if (! localp)
5448 {
5449 m = ieee_get_modified_info (p, indx);
5450 if (m == NULL((void*)0))
5451 return FALSE0;
5452
5453 /* FIXME: The size should depend upon the architecture. */
5454 if (m->pointer > 0)
5455 return ieee_push_type (info, m->pointer, 4, TRUE1, FALSE0);
5456 }
5457
5458 if (! ieee_define_type (info, 4, TRUE1, localp)
5459 || ! ieee_write_number (info, 'P')
5460 || ! ieee_write_number (info, indx))
5461 return FALSE0;
5462
5463 if (! localp)
5464 m->pointer = info->type_stack->type.indx;
5465
5466 return TRUE1;
5467}
5468
5469/* Make a function type. This will be called for a method, but we
5470 don't want to actually add it to the type table in that case. We
5471 handle this by defining the type in a private buffer, and only
5472 adding that buffer to the typedef block if we are going to use it. */
5473
5474static bfd_boolean
5475ieee_function_type (void *p, int argcount, bfd_boolean varargs)
5476{
5477 struct ieee_handle *info = (struct ieee_handle *) p;
5478 bfd_boolean localp;
5479 unsigned int *args = NULL((void*)0);
5480 int i;
5481 unsigned int retindx;
5482 struct ieee_buflist fndef;
5483 struct ieee_modified_type *m;
5484
5485 localp = FALSE0;
5486
5487 if (argcount > 0)
5488 {
5489 args = (unsigned int *) xmalloc (argcount * sizeof *args);
5490 for (i = argcount - 1; i >= 0; i--)
5491 {
5492 if (info->type_stack->type.localp)
5493 localp = TRUE1;
5494 args[i] = ieee_pop_type (info);
5495 }
5496 }
5497 else if (argcount < 0)
5498 varargs = FALSE0;
5499
5500 if (info->type_stack->type.localp)
5501 localp = TRUE1;
5502 retindx = ieee_pop_type (info);
5503
5504 m = NULL((void*)0);
5505 if (argcount < 0 && ! localp)
5506 {
5507 m = ieee_get_modified_info (p, retindx);
5508 if (m == NULL((void*)0))
5509 return FALSE0;
5510
5511 if (m->function > 0)
5512 return ieee_push_type (info, m->function, 0, TRUE1, FALSE0);
5513 }
5514
5515 /* An attribute of 0x41 means that the frame and push mask are
5516 unknown. */
5517 if (! ieee_init_buffer (info, &fndef)
5518 || ! ieee_define_named_type (info, (const char *) NULL((void*)0),
5519 (unsigned int) -1, 0, TRUE1, localp,
5520 &fndef)
5521 || ! ieee_write_number (info, 'x')
5522 || ! ieee_write_number (info, 0x41)
5523 || ! ieee_write_number (info, 0)
5524 || ! ieee_write_number (info, 0)
5525 || ! ieee_write_number (info, retindx)
5526 || ! ieee_write_number (info, (bfd_vma) argcount + (varargs ? 1 : 0)))
5527 return FALSE0;
5528 if (argcount > 0)
5529 {
5530 for (i = 0; i < argcount; i++)
5531 if (! ieee_write_number (info, args[i]))
5532 return FALSE0;
5533 free (args);
5534 }
5535 if (varargs)
5536 {
5537 /* A varargs function is represented by writing out the last
5538 argument as type void *, although this makes little sense. */
5539 if (! ieee_write_number (info, (bfd_vma) builtin_void + 32))
5540 return FALSE0;
5541 }
5542
5543 if (! ieee_write_number (info, 0))
5544 return FALSE0;
5545
5546 /* We wrote the information into fndef, in case we don't need it.
5547 It will be appended to info->types by ieee_pop_type. */
5548 info->type_stack->type.fndef = fndef;
5549
5550 if (m != NULL((void*)0))
5551 m->function = info->type_stack->type.indx;
5552
5553 return TRUE1;
5554}
5555
5556/* Make a reference type. */
5557
5558static bfd_boolean
5559ieee_reference_type (void *p)
5560{
5561 struct ieee_handle *info = (struct ieee_handle *) p;
5562
5563 /* IEEE appears to record a normal pointer type, and then use a
5564 pmisc record to indicate that it is really a reference. */
5565
5566 if (! ieee_pointer_type (p))
5567 return FALSE0;
5568 info->type_stack->type.referencep = TRUE1;
5569 return TRUE1;
5570}
5571
5572/* Make a range type. */
5573
5574static bfd_boolean
5575ieee_range_type (void *p, bfd_signed_vma low, bfd_signed_vma high)
5576{
5577 struct ieee_handle *info = (struct ieee_handle *) p;
5578 unsigned int size;
5579 bfd_boolean unsignedp, localp;
5580
5581 size = info->type_stack->type.size;
5582 unsignedp = info->type_stack->type.unsignedp;
5583 localp = info->type_stack->type.localp;
5584 ieee_pop_unused_type (info);
5585 return (ieee_define_type (info, size, unsignedp, localp)
5586 && ieee_write_number (info, 'R')
5587 && ieee_write_number (info, (bfd_vma) low)
5588 && ieee_write_number (info, (bfd_vma) high)
5589 && ieee_write_number (info, unsignedp ? 0 : 1)
5590 && ieee_write_number (info, size));
5591}
5592
5593/* Make an array type. */
5594
5595static bfd_boolean
5596ieee_array_type (void *p, bfd_signed_vma low, bfd_signed_vma high,
5597 bfd_boolean stringp ATTRIBUTE_UNUSED__attribute__ ((__unused__)))
5598{
5599 struct ieee_handle *info = (struct ieee_handle *) p;
5600 unsigned int eleindx;
5601 bfd_boolean localp;
5602 unsigned int size;
5603 struct ieee_modified_type *m = NULL((void*)0);
5604 struct ieee_modified_array_type *a;
5605
5606 /* IEEE does not store the range, so we just ignore it. */
5607 ieee_pop_unused_type (info);
5608 localp = info->type_stack->type.localp;
5609 size = info->type_stack->type.size;
5610 eleindx = ieee_pop_type (info);
5611
5612 /* If we don't know the range, treat the size as exactly one
5613 element. */
5614 if (low < high)
5615 size *= (high - low) + 1;
5616
5617 if (! localp)
5618 {
5619 m = ieee_get_modified_info (info, eleindx);
5620 if (m == NULL((void*)0))
5621 return FALSE0;
5622
5623 for (a = m->arrays; a != NULL((void*)0); a = a->next)
5624 {
5625 if (a->low == low && a->high == high)
5626 return ieee_push_type (info, a->indx, size, FALSE0, FALSE0);
5627 }
5628 }
5629
5630 if (! ieee_define_type (info, size, FALSE0, localp)
5631 || ! ieee_write_number (info, low == 0 ? 'Z' : 'C')
5632 || ! ieee_write_number (info, eleindx))
5633 return FALSE0;
5634 if (low != 0)
5635 {
5636 if (! ieee_write_number (info, low))
5637 return FALSE0;
5638 }
5639
5640 if (! ieee_write_number (info, high + 1))
5641 return FALSE0;
5642
5643 if (! localp)
5644 {
5645 a = (struct ieee_modified_array_type *) xmalloc (sizeof *a);
5646 memset (a, 0, sizeof *a);
5647
5648 a->indx = info->type_stack->type.indx;
5649 a->low = low;
5650 a->high = high;
5651
5652 a->next = m->arrays;
5653 m->arrays = a;
5654 }
5655
5656 return TRUE1;
5657}
5658
5659/* Make a set type. */
5660
5661static bfd_boolean
5662ieee_set_type (void *p, bfd_boolean bitstringp ATTRIBUTE_UNUSED__attribute__ ((__unused__)))
5663{
5664 struct ieee_handle *info = (struct ieee_handle *) p;
5665 bfd_boolean localp;
5666 unsigned int eleindx;
5667
5668 localp = info->type_stack->type.localp;
5669 eleindx = ieee_pop_type (info);
5670
5671 /* FIXME: We don't know the size, so we just use 4. */
5672
5673 return (ieee_define_type (info, 0, TRUE1, localp)
5674 && ieee_write_number (info, 's')
5675 && ieee_write_number (info, 4)
5676 && ieee_write_number (info, eleindx));
5677}
5678
5679/* Make an offset type. */
5680
5681static bfd_boolean
5682ieee_offset_type (void *p)
5683{
5684 struct ieee_handle *info = (struct ieee_handle *) p;
5685 unsigned int targetindx, baseindx;
5686
5687 targetindx = ieee_pop_type (info);
5688 baseindx = ieee_pop_type (info);
5689
5690 /* FIXME: The MRI C++ compiler does not appear to generate any
5691 useful type information about an offset type. It just records a
5692 pointer to member as an integer. The MRI/HP IEEE spec does
5693 describe a pmisc record which can be used for a pointer to
5694 member. Unfortunately, it does not describe the target type,
5695 which seems pretty important. I'm going to punt this for now. */
5696
5697 return ieee_int_type (p, 4, TRUE1);
5698}
5699
5700/* Make a method type. */
5701
5702static bfd_boolean
5703ieee_method_type (void *p, bfd_boolean domain, int argcount,
5704 bfd_boolean varargs)
5705{
5706 struct ieee_handle *info = (struct ieee_handle *) p;
5707
5708 /* FIXME: The MRI/HP IEEE spec defines a pmisc record to use for a
5709 method, but the definition is incomplete. We just output an 'x'
5710 type. */
5711
5712 if (domain)
5713 ieee_pop_unused_type (info);
5714
5715 return ieee_function_type (p, argcount, varargs);
5716}
5717
5718/* Make a const qualified type. */
5719
5720static bfd_boolean
5721ieee_const_type (void *p)
5722{
5723 struct ieee_handle *info = (struct ieee_handle *) p;
5724 unsigned int size;
5725 bfd_boolean unsignedp, localp;
5726 unsigned int indx;
5727 struct ieee_modified_type *m = NULL((void*)0);
5728
5729 size = info->type_stack->type.size;
5730 unsignedp = info->type_stack->type.unsignedp;
5731 localp = info->type_stack->type.localp;
5732 indx = ieee_pop_type (info);
5733
5734 if (! localp)
5735 {
5736 m = ieee_get_modified_info (info, indx);
5737 if (m == NULL((void*)0))
5738 return FALSE0;
5739
5740 if (m->const_qualified > 0)
5741 return ieee_push_type (info, m->const_qualified, size, unsignedp,
5742 FALSE0);
5743 }
5744
5745 if (! ieee_define_type (info, size, unsignedp, localp)
5746 || ! ieee_write_number (info, 'n')
5747 || ! ieee_write_number (info, 1)
5748 || ! ieee_write_number (info, indx))
5749 return FALSE0;
5750
5751 if (! localp)
5752 m->const_qualified = info->type_stack->type.indx;
5753
5754 return TRUE1;
5755}
5756
5757/* Make a volatile qualified type. */
5758
5759static bfd_boolean
5760ieee_volatile_type (void *p)
5761{
5762 struct ieee_handle *info = (struct ieee_handle *) p;
5763 unsigned int size;
5764 bfd_boolean unsignedp, localp;
5765 unsigned int indx;
5766 struct ieee_modified_type *m = NULL((void*)0);
5767
5768 size = info->type_stack->type.size;
5769 unsignedp = info->type_stack->type.unsignedp;
5770 localp = info->type_stack->type.localp;
5771 indx = ieee_pop_type (info);
5772
5773 if (! localp)
5774 {
5775 m = ieee_get_modified_info (info, indx);
5776 if (m == NULL((void*)0))
5777 return FALSE0;
5778
5779 if (m->volatile_qualified > 0)
5780 return ieee_push_type (info, m->volatile_qualified, size, unsignedp,
5781 FALSE0);
5782 }
5783
5784 if (! ieee_define_type (info, size, unsignedp, localp)
5785 || ! ieee_write_number (info, 'n')
5786 || ! ieee_write_number (info, 2)
5787 || ! ieee_write_number (info, indx))
5788 return FALSE0;
5789
5790 if (! localp)
5791 m->volatile_qualified = info->type_stack->type.indx;
5792
5793 return TRUE1;
5794}
5795
5796/* Convert an enum debug_visibility into a CXXFLAGS value. */
5797
5798static unsigned int
5799ieee_vis_to_flags (enum debug_visibility visibility)
5800{
5801 switch (visibility)
5802 {
5803 default:
5804 abort ();
5805 case DEBUG_VISIBILITY_PUBLIC:
5806 return CXXFLAGS_VISIBILITY_PUBLIC(0x0);
5807 case DEBUG_VISIBILITY_PRIVATE:
5808 return CXXFLAGS_VISIBILITY_PRIVATE(0x1);
5809 case DEBUG_VISIBILITY_PROTECTED:
5810 return CXXFLAGS_VISIBILITY_PROTECTED(0x2);
5811 }
5812 /*NOTREACHED*/
5813}
5814
5815/* Start defining a struct type. We build it in the strdef field on
5816 the stack, to avoid confusing type definitions required by the
5817 fields with the struct type itself. */
5818
5819static bfd_boolean
5820ieee_start_struct_type (void *p, const char *tag, unsigned int id,
5821 bfd_boolean structp, unsigned int size)
5822{
5823 struct ieee_handle *info = (struct ieee_handle *) p;
5824 bfd_boolean localp, ignorep;
5825 bfd_boolean copy;
5826 char ab[20];
5827 const char *look;
5828 struct ieee_name_type_hash_entry *h;
5829 struct ieee_name_type *nt, *ntlook;
5830 struct ieee_buflist strdef;
5831
5832 localp = FALSE0;
5833 ignorep = FALSE0;
5834
5835 /* We need to create a tag for internal use even if we don't want
5836 one for external use. This will let us refer to an anonymous
5837 struct. */
5838 if (tag != NULL((void*)0))
5839 {
5840 look = tag;
5841 copy = FALSE0;
5842 }
5843 else
5844 {
5845 sprintf (ab, "__anon%u", id);
5846 look = ab;
5847 copy = TRUE1;
5848 }
5849
5850 /* If we already have references to the tag, we must use the
5851 existing type index. */
5852 h = ieee_name_type_hash_lookup (&info->tags, look, TRUE, copy)((struct ieee_name_type_hash_entry *) bfd_hash_lookup (&(
&info->tags)->root, (look), (1), (copy)))
;
5853 if (h == NULL((void*)0))
5854 return FALSE0;
5855
5856 nt = NULL((void*)0);
5857 for (ntlook = h->types; ntlook != NULL((void*)0); ntlook = ntlook->next)
5858 {
5859 if (ntlook->id == id)
5860 nt = ntlook;
5861 else if (! ntlook->type.localp)
5862 {
5863 /* We are creating a duplicate definition of a globally
5864 defined tag. Force it to be local to avoid
5865 confusion. */
5866 localp = TRUE1;
5867 }
5868 }
5869
5870 if (nt != NULL((void*)0))
5871 {
5872 assert (localp == nt->type.localp)((localp == nt->type.localp) ? (void)0 : __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 5872, __func__, "localp == nt->type.localp"))
;
5873 if (nt->kind == DEBUG_KIND_ILLEGAL && ! localp)
5874 {
5875 /* We've already seen a global definition of the type.
5876 Ignore this new definition. */
5877 ignorep = TRUE1;
5878 }
5879 }
5880 else
5881 {
5882 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
5883 memset (nt, 0, sizeof *nt);
5884 nt->id = id;
5885 nt->type.name = h->root.string;
5886 nt->next = h->types;
5887 h->types = nt;
5888 nt->type.indx = info->type_indx;
5889 ++info->type_indx;
5890 }
5891
5892 nt->kind = DEBUG_KIND_ILLEGAL;
5893
5894 if (! ieee_init_buffer (info, &strdef)
5895 || ! ieee_define_named_type (info, tag, nt->type.indx, size, TRUE1,
5896 localp, &strdef)
5897 || ! ieee_write_number (info, structp ? 'S' : 'U')
5898 || ! ieee_write_number (info, size))
5899 return FALSE0;
5900
5901 if (! ignorep)
5902 {
5903 const char *hold;
5904
5905 /* We never want nt->type.name to be NULL. We want the rest of
5906 the type to be the object set up on the type stack; it will
5907 have a NULL name if tag is NULL. */
5908 hold = nt->type.name;
5909 nt->type = info->type_stack->type;
5910 nt->type.name = hold;
5911 }
5912
5913 info->type_stack->type.name = tag;
5914 info->type_stack->type.strdef = strdef;
5915 info->type_stack->type.ignorep = ignorep;
5916
5917 return TRUE1;
5918}
5919
5920/* Add a field to a struct. */
5921
5922static bfd_boolean
5923ieee_struct_field (void *p, const char *name, bfd_vma bitpos, bfd_vma bitsize,
5924 enum debug_visibility visibility)
5925{
5926 struct ieee_handle *info = (struct ieee_handle *) p;
5927 unsigned int size;
5928 bfd_boolean unsignedp;
5929 bfd_boolean referencep;
5930 bfd_boolean localp;
5931 unsigned int indx;
5932 bfd_vma offset;
5933
5934 assert (info->type_stack != NULL((info->type_stack != ((void*)0) && info->type_stack
->next != ((void*)0) && ! ((&info->type_stack
->next->type.strdef)->head == ((void*)0))) ? (void)0
: __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 5936, __func__, "info->type_stack != NULL && info->type_stack->next != NULL && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef)"
))
5935 && info->type_stack->next != NULL((info->type_stack != ((void*)0) && info->type_stack
->next != ((void*)0) && ! ((&info->type_stack
->next->type.strdef)->head == ((void*)0))) ? (void)0
: __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 5936, __func__, "info->type_stack != NULL && info->type_stack->next != NULL && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef)"
))
5936 && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef))((info->type_stack != ((void*)0) && info->type_stack
->next != ((void*)0) && ! ((&info->type_stack
->next->type.strdef)->head == ((void*)0))) ? (void)0
: __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 5936, __func__, "info->type_stack != NULL && info->type_stack->next != NULL && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef)"
))
;
5937
5938 /* If we are ignoring this struct definition, just pop and ignore
5939 the type. */
5940 if (info->type_stack->next->type.ignorep)
5941 {
5942 ieee_pop_unused_type (info);
5943 return TRUE1;
5944 }
5945
5946 size = info->type_stack->type.size;
5947 unsignedp = info->type_stack->type.unsignedp;
5948 referencep = info->type_stack->type.referencep;
5949 localp = info->type_stack->type.localp;
5950 indx = ieee_pop_type (info);
5951
5952 if (localp)
5953 info->type_stack->type.localp = TRUE1;
5954
5955 if (info->type_stack->type.classdef != NULL((void*)0))
5956 {
5957 unsigned int flags;
5958 unsigned int nindx;
5959
5960 /* This is a class. We must add a description of this field to
5961 the class records we are building. */
5962
5963 flags = ieee_vis_to_flags (visibility);
5964 nindx = info->type_stack->type.classdef->indx;
5965 if (! ieee_change_buffer (info,
5966 &info->type_stack->type.classdef->pmiscbuf)
5967 || ! ieee_write_asn (info, nindx, 'd')
5968 || ! ieee_write_asn (info, nindx, flags)
5969 || ! ieee_write_atn65 (info, nindx, name)
5970 || ! ieee_write_atn65 (info, nindx, name))
5971 return FALSE0;
5972 info->type_stack->type.classdef->pmisccount += 4;
5973
5974 if (referencep)
5975 {
5976 unsigned int nindx;
5977
5978 /* We need to output a record recording that this field is
5979 really of reference type. We put this on the refs field
5980 of classdef, so that it can be appended to the C++
5981 records after the class is defined. */
5982
5983 nindx = info->name_indx;
5984 ++info->name_indx;
5985
5986 if (! ieee_change_buffer (info,
5987 &info->type_stack->type.classdef->refs)
5988 || ! ieee_write_byte (info, (int) ieee_nn_record)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_nn_record), 1) :
ieee_real_write_byte ((info), ((int) ieee_nn_record)))
5989 || ! ieee_write_number (info, nindx)
5990 || ! ieee_write_id (info, "")
5991 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
5992 || ! ieee_write_number (info, nindx)
5993 || ! ieee_write_number (info, 0)
5994 || ! ieee_write_number (info, 62)
5995 || ! ieee_write_number (info, 80)
5996 || ! ieee_write_number (info, 4)
5997 || ! ieee_write_asn (info, nindx, 'R')
5998 || ! ieee_write_asn (info, nindx, 3)
5999 || ! ieee_write_atn65 (info, nindx, info->type_stack->type.name)
6000 || ! ieee_write_atn65 (info, nindx, name))
6001 return FALSE0;
6002 }
6003 }
6004
6005 /* If the bitsize doesn't match the expected size, we need to output
6006 a bitfield type. */
6007 if (size == 0 || bitsize == 0 || bitsize == size * 8)
6008 offset = bitpos / 8;
6009 else
6010 {
6011 if (! ieee_define_type (info, 0, unsignedp,
6012 info->type_stack->type.localp)
6013 || ! ieee_write_number (info, 'g')
6014 || ! ieee_write_number (info, unsignedp ? 0 : 1)
6015 || ! ieee_write_number (info, bitsize)
6016 || ! ieee_write_number (info, indx))
6017 return FALSE0;
6018 indx = ieee_pop_type (info);
6019 offset = bitpos;
6020 }
6021
6022 /* Switch to the struct we are building in order to output this
6023 field definition. */
6024 return (ieee_change_buffer (info, &info->type_stack->type.strdef)
6025 && ieee_write_id (info, name)
6026 && ieee_write_number (info, indx)
6027 && ieee_write_number (info, offset));
6028}
6029
6030/* Finish up a struct type. */
6031
6032static bfd_boolean
6033ieee_end_struct_type (void *p)
6034{
6035 struct ieee_handle *info = (struct ieee_handle *) p;
6036 struct ieee_buflist *pb;
6037
6038 assert (info->type_stack != NULL((info->type_stack != ((void*)0) && ! ((&info->
type_stack->type.strdef)->head == ((void*)0))) ? (void)
0 : __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 6039, __func__, "info->type_stack != NULL && ! ieee_buffer_emptyp (&info->type_stack->type.strdef)"
))
6039 && ! ieee_buffer_emptyp (&info->type_stack->type.strdef))((info->type_stack != ((void*)0) && ! ((&info->
type_stack->type.strdef)->head == ((void*)0))) ? (void)
0 : __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 6039, __func__, "info->type_stack != NULL && ! ieee_buffer_emptyp (&info->type_stack->type.strdef)"
))
;
6040
6041 /* If we were ignoring this struct definition because it was a
6042 duplicate definition, just through away whatever bytes we have
6043 accumulated. Leave the type on the stack. */
6044 if (info->type_stack->type.ignorep)
6045 return TRUE1;
6046
6047 /* If this is not a duplicate definition of this tag, then localp
6048 will be FALSE, and we can put it in the global type block.
6049 FIXME: We should avoid outputting duplicate definitions which are
6050 the same. */
6051 if (! info->type_stack->type.localp)
6052 {
6053 /* Make sure we have started the global type block. */
6054 if (ieee_buffer_emptyp (&info->global_types)((&info->global_types)->head == ((void*)0)))
6055 {
6056 if (! ieee_change_buffer (info, &info->global_types)
6057 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_bb_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_bb_record_enum
)))
6058 || ! ieee_write_byte (info, 2)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (2), 1) : ieee_real_write_byte
((info), (2)))
6059 || ! ieee_write_number (info, 0)
6060 || ! ieee_write_id (info, ""))
6061 return FALSE0;
6062 }
6063 pb = &info->global_types;
6064 }
6065 else
6066 {
6067 /* Make sure we have started the types block. */
6068 if (ieee_buffer_emptyp (&info->types)((&info->types)->head == ((void*)0)))
6069 {
6070 if (! ieee_change_buffer (info, &info->types)
6071 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_bb_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_bb_record_enum
)))
6072 || ! ieee_write_byte (info, 1)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (1), 1) : ieee_real_write_byte
((info), (1)))
6073 || ! ieee_write_number (info, 0)
6074 || ! ieee_write_id (info, info->modname))
6075 return FALSE0;
6076 }
6077 pb = &info->types;
6078 }
6079
6080 /* Append the struct definition to the types. */
6081 if (! ieee_append_buffer (info, pb, &info->type_stack->type.strdef)
6082 || ! ieee_init_buffer (info, &info->type_stack->type.strdef))
6083 return FALSE0;
6084
6085 /* Leave the struct on the type stack. */
6086
6087 return TRUE1;
6088}
6089
6090/* Start a class type. */
6091
6092static bfd_boolean
6093ieee_start_class_type (void *p, const char *tag, unsigned int id,
6094 bfd_boolean structp, unsigned int size,
6095 bfd_boolean vptr, bfd_boolean ownvptr)
6096{
6097 struct ieee_handle *info = (struct ieee_handle *) p;
6098 const char *vclass;
6099 struct ieee_buflist pmiscbuf;
6100 unsigned int indx;
6101 struct ieee_type_class *classdef;
6102
6103 /* A C++ class is output as a C++ struct along with a set of pmisc
6104 records describing the class. */
6105
6106 /* We need to have a name so that we can associate the struct and
6107 the class. */
6108 if (tag == NULL((void*)0))
6109 {
6110 char *t;
6111
6112 t = (char *) xmalloc (20);
6113 sprintf (t, "__anon%u", id);
6114 tag = t;
6115 }
6116
6117 /* We can't write out the virtual table information until we have
6118 finished the class, because we don't know the virtual table size.
6119 We get the size from the largest voffset we see. */
6120 vclass = NULL((void*)0);
6121 if (vptr && ! ownvptr)
6122 {
6123 vclass = info->type_stack->type.name;
6124 assert (vclass != NULL)((vclass != ((void*)0)) ? (void)0 : __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 6124, __func__, "vclass != NULL"))
;
6125 /* We don't call ieee_pop_unused_type, since the class should
6126 get defined. */
6127 (void) ieee_pop_type (info);
6128 }
6129
6130 if (! ieee_start_struct_type (p, tag, id, structp, size))
6131 return FALSE0;
6132
6133 indx = info->name_indx;
6134 ++info->name_indx;
6135
6136 /* We write out pmisc records into the classdef field. We will
6137 write out the pmisc start after we know the number of records we
6138 need. */
6139 if (! ieee_init_buffer (info, &pmiscbuf)
6140 || ! ieee_change_buffer (info, &pmiscbuf)
6141 || ! ieee_write_asn (info, indx, 'T')
6142 || ! ieee_write_asn (info, indx, structp ? 'o' : 'u')
6143 || ! ieee_write_atn65 (info, indx, tag))
6144 return FALSE0;
6145
6146 classdef = (struct ieee_type_class *) xmalloc (sizeof *classdef);
6147 memset (classdef, 0, sizeof *classdef);
6148
6149 classdef->indx = indx;
6150 classdef->pmiscbuf = pmiscbuf;
6151 classdef->pmisccount = 3;
6152 classdef->vclass = vclass;
6153 classdef->ownvptr = ownvptr;
6154
6155 info->type_stack->type.classdef = classdef;
6156
6157 return TRUE1;
6158}
6159
6160/* Add a static member to a class. */
6161
6162static bfd_boolean
6163ieee_class_static_member (void *p, const char *name, const char *physname,
6164 enum debug_visibility visibility)
6165{
6166 struct ieee_handle *info = (struct ieee_handle *) p;
6167 unsigned int flags;
6168 unsigned int nindx;
6169
6170 /* We don't care about the type. Hopefully there will be a call to
6171 ieee_variable declaring the physical name and the type, since
6172 that is where an IEEE consumer must get the type. */
6173 ieee_pop_unused_type (info);
6174
6175 assert (info->type_stack != NULL((info->type_stack != ((void*)0) && info->type_stack
->type.classdef != ((void*)0)) ? (void)0 : __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 6176, __func__, "info->type_stack != NULL && info->type_stack->type.classdef != NULL"
))
6176 && info->type_stack->type.classdef != NULL)((info->type_stack != ((void*)0) && info->type_stack
->type.classdef != ((void*)0)) ? (void)0 : __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 6176, __func__, "info->type_stack != NULL && info->type_stack->type.classdef != NULL"
))
;
6177
6178 flags = ieee_vis_to_flags (visibility);
6179 flags |= CXXFLAGS_STATIC(0x4);
6180
6181 nindx = info->type_stack->type.classdef->indx;
6182
6183 if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf)
6184 || ! ieee_write_asn (info, nindx, 'd')
6185 || ! ieee_write_asn (info, nindx, flags)
6186 || ! ieee_write_atn65 (info, nindx, name)
6187 || ! ieee_write_atn65 (info, nindx, physname))
6188 return FALSE0;
6189 info->type_stack->type.classdef->pmisccount += 4;
6190
6191 return TRUE1;
6192}
6193
6194/* Add a base class to a class. */
6195
6196static bfd_boolean
6197ieee_class_baseclass (void *p, bfd_vma bitpos, bfd_boolean virtual,
6198 enum debug_visibility visibility)
6199{
6200 struct ieee_handle *info = (struct ieee_handle *) p;
6201 const char *bname;
6202 bfd_boolean localp;
6203 unsigned int bindx;
6204 char *fname;
6205 unsigned int flags;
6206 unsigned int nindx;
6207
6208 assert (info->type_stack != NULL((info->type_stack != ((void*)0) && info->type_stack
->type.name != ((void*)0) && info->type_stack->
next != ((void*)0) && info->type_stack->next->
type.classdef != ((void*)0) && ! ((&info->type_stack
->next->type.strdef)->head == ((void*)0))) ? (void)0
: __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 6212, __func__, "info->type_stack != NULL && info->type_stack->type.name != NULL && info->type_stack->next != NULL && info->type_stack->next->type.classdef != NULL && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef)"
))
6209 && info->type_stack->type.name != NULL((info->type_stack != ((void*)0) && info->type_stack
->type.name != ((void*)0) && info->type_stack->
next != ((void*)0) && info->type_stack->next->
type.classdef != ((void*)0) && ! ((&info->type_stack
->next->type.strdef)->head == ((void*)0))) ? (void)0
: __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 6212, __func__, "info->type_stack != NULL && info->type_stack->type.name != NULL && info->type_stack->next != NULL && info->type_stack->next->type.classdef != NULL && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef)"
))
6210 && info->type_stack->next != NULL((info->type_stack != ((void*)0) && info->type_stack
->type.name != ((void*)0) && info->type_stack->
next != ((void*)0) && info->type_stack->next->
type.classdef != ((void*)0) && ! ((&info->type_stack
->next->type.strdef)->head == ((void*)0))) ? (void)0
: __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 6212, __func__, "info->type_stack != NULL && info->type_stack->type.name != NULL && info->type_stack->next != NULL && info->type_stack->next->type.classdef != NULL && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef)"
))
6211 && info->type_stack->next->type.classdef != NULL((info->type_stack != ((void*)0) && info->type_stack
->type.name != ((void*)0) && info->type_stack->
next != ((void*)0) && info->type_stack->next->
type.classdef != ((void*)0) && ! ((&info->type_stack
->next->type.strdef)->head == ((void*)0))) ? (void)0
: __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 6212, __func__, "info->type_stack != NULL && info->type_stack->type.name != NULL && info->type_stack->next != NULL && info->type_stack->next->type.classdef != NULL && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef)"
))
6212 && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef))((info->type_stack != ((void*)0) && info->type_stack
->type.name != ((void*)0) && info->type_stack->
next != ((void*)0) && info->type_stack->next->
type.classdef != ((void*)0) && ! ((&info->type_stack
->next->type.strdef)->head == ((void*)0))) ? (void)0
: __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 6212, __func__, "info->type_stack != NULL && info->type_stack->type.name != NULL && info->type_stack->next != NULL && info->type_stack->next->type.classdef != NULL && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef)"
))
;
6213
6214 bname = info->type_stack->type.name;
6215 localp = info->type_stack->type.localp;
6216 bindx = ieee_pop_type (info);
6217
6218 /* We are currently defining both a struct and a class. We must
6219 write out a field definition in the struct which holds the base
6220 class. The stabs debugging reader will create a field named
6221 _vb$CLASS for a virtual base class, so we just use that. FIXME:
6222 we should not depend upon a detail of stabs debugging. */
6223 if (virtual)
6224 {
6225 fname = (char *) xmalloc (strlen (bname) + sizeof "_vb$");
6226 sprintf (fname, "_vb$%s", bname);
6227 flags = BASEFLAGS_VIRTUAL(0x2);
6228 }
6229 else
6230 {
6231 if (localp)
6232 info->type_stack->type.localp = TRUE1;
6233
6234 fname = (char *) xmalloc (strlen (bname) + sizeof "_b$");
6235 sprintf (fname, "_b$%s", bname);
6236
6237 if (! ieee_change_buffer (info, &info->type_stack->type.strdef)
6238 || ! ieee_write_id (info, fname)
6239 || ! ieee_write_number (info, bindx)
6240 || ! ieee_write_number (info, bitpos / 8))
6241 return FALSE0;
6242 flags = 0;
6243 }
6244
6245 if (visibility == DEBUG_VISIBILITY_PRIVATE)
6246 flags |= BASEFLAGS_PRIVATE(0x1);
6247
6248 nindx = info->type_stack->type.classdef->indx;
6249
6250 if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf)
6251 || ! ieee_write_asn (info, nindx, 'b')
6252 || ! ieee_write_asn (info, nindx, flags)
6253 || ! ieee_write_atn65 (info, nindx, bname)
6254 || ! ieee_write_asn (info, nindx, 0)
6255 || ! ieee_write_atn65 (info, nindx, fname))
6256 return FALSE0;
6257 info->type_stack->type.classdef->pmisccount += 5;
6258
6259 free (fname);
6260
6261 return TRUE1;
6262}
6263
6264/* Start building a method for a class. */
6265
6266static bfd_boolean
6267ieee_class_start_method (void *p, const char *name)
6268{
6269 struct ieee_handle *info = (struct ieee_handle *) p;
6270
6271 assert (info->type_stack != NULL((info->type_stack != ((void*)0) && info->type_stack
->type.classdef != ((void*)0) && info->type_stack
->type.classdef->method == ((void*)0)) ? (void)0 : __assert2
("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c", 6273, __func__
, "info->type_stack != NULL && info->type_stack->type.classdef != NULL && info->type_stack->type.classdef->method == NULL"
))
6272 && info->type_stack->type.classdef != NULL((info->type_stack != ((void*)0) && info->type_stack
->type.classdef != ((void*)0) && info->type_stack
->type.classdef->method == ((void*)0)) ? (void)0 : __assert2
("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c", 6273, __func__
, "info->type_stack != NULL && info->type_stack->type.classdef != NULL && info->type_stack->type.classdef->method == NULL"
))
6273 && info->type_stack->type.classdef->method == NULL)((info->type_stack != ((void*)0) && info->type_stack
->type.classdef != ((void*)0) && info->type_stack
->type.classdef->method == ((void*)0)) ? (void)0 : __assert2
("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c", 6273, __func__
, "info->type_stack != NULL && info->type_stack->type.classdef != NULL && info->type_stack->type.classdef->method == NULL"
))
;
6274
6275 info->type_stack->type.classdef->method = name;
6276
6277 return TRUE1;
6278}
6279
6280/* Define a new method variant, either static or not. */
6281
6282static bfd_boolean
6283ieee_class_method_var (struct ieee_handle *info, const char *physname,
6284 enum debug_visibility visibility,
6285 bfd_boolean staticp, bfd_boolean constp,
6286 bfd_boolean volatilep, bfd_vma voffset,
6287 bfd_boolean context)
6288{
6289 unsigned int flags;
6290 unsigned int nindx;
6291 bfd_boolean virtual;
6292
6293 /* We don't need the type of the method. An IEEE consumer which
6294 wants the type must track down the function by the physical name
6295 and get the type from that. */
6296 ieee_pop_unused_type (info);
6297
6298 /* We don't use the context. FIXME: We probably ought to use it to
6299 adjust the voffset somehow, but I don't really know how. */
6300 if (context)
6301 ieee_pop_unused_type (info);
6302
6303 assert (info->type_stack != NULL((info->type_stack != ((void*)0) && info->type_stack
->type.classdef != ((void*)0) && info->type_stack
->type.classdef->method != ((void*)0)) ? (void)0 : __assert2
("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c", 6305, __func__
, "info->type_stack != NULL && info->type_stack->type.classdef != NULL && info->type_stack->type.classdef->method != NULL"
))
6304 && info->type_stack->type.classdef != NULL((info->type_stack != ((void*)0) && info->type_stack
->type.classdef != ((void*)0) && info->type_stack
->type.classdef->method != ((void*)0)) ? (void)0 : __assert2
("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c", 6305, __func__
, "info->type_stack != NULL && info->type_stack->type.classdef != NULL && info->type_stack->type.classdef->method != NULL"
))
6305 && info->type_stack->type.classdef->method != NULL)((info->type_stack != ((void*)0) && info->type_stack
->type.classdef != ((void*)0) && info->type_stack
->type.classdef->method != ((void*)0)) ? (void)0 : __assert2
("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c", 6305, __func__
, "info->type_stack != NULL && info->type_stack->type.classdef != NULL && info->type_stack->type.classdef->method != NULL"
))
;
6306
6307 flags = ieee_vis_to_flags (visibility);
6308
6309 /* FIXME: We never set CXXFLAGS_OVERRIDE, CXXFLAGS_OPERATOR,
6310 CXXFLAGS_CTORDTOR, CXXFLAGS_CTOR, or CXXFLAGS_INLINE. */
6311
6312 if (staticp)
6313 flags |= CXXFLAGS_STATIC(0x4);
6314 if (constp)
6315 flags |= CXXFLAGS_CONST(0x20);
6316 if (volatilep)
6317 flags |= CXXFLAGS_VOLATILE(0x40);
6318
6319 nindx = info->type_stack->type.classdef->indx;
6320
6321 virtual = context || voffset > 0;
6322
6323 if (! ieee_change_buffer (info,
6324 &info->type_stack->type.classdef->pmiscbuf)
6325 || ! ieee_write_asn (info, nindx, virtual ? 'v' : 'm')
6326 || ! ieee_write_asn (info, nindx, flags)
6327 || ! ieee_write_atn65 (info, nindx,
6328 info->type_stack->type.classdef->method)
6329 || ! ieee_write_atn65 (info, nindx, physname))
6330 return FALSE0;
6331
6332 if (virtual)
6333 {
6334 if (voffset > info->type_stack->type.classdef->voffset)
6335 info->type_stack->type.classdef->voffset = voffset;
6336 if (! ieee_write_asn (info, nindx, voffset))
6337 return FALSE0;
6338 ++info->type_stack->type.classdef->pmisccount;
6339 }
6340
6341 if (! ieee_write_asn (info, nindx, 0))
6342 return FALSE0;
6343
6344 info->type_stack->type.classdef->pmisccount += 5;
6345
6346 return TRUE1;
6347}
6348
6349/* Define a new method variant. */
6350
6351static bfd_boolean
6352ieee_class_method_variant (void *p, const char *physname,
6353 enum debug_visibility visibility,
6354 bfd_boolean constp, bfd_boolean volatilep,
6355 bfd_vma voffset, bfd_boolean context)
6356{
6357 struct ieee_handle *info = (struct ieee_handle *) p;
6358
6359 return ieee_class_method_var (info, physname, visibility, FALSE0, constp,
6360 volatilep, voffset, context);
6361}
6362
6363/* Define a new static method variant. */
6364
6365static bfd_boolean
6366ieee_class_static_method_variant (void *p, const char *physname,
6367 enum debug_visibility visibility,
6368 bfd_boolean constp, bfd_boolean volatilep)
6369{
6370 struct ieee_handle *info = (struct ieee_handle *) p;
6371
6372 return ieee_class_method_var (info, physname, visibility, TRUE1, constp,
6373 volatilep, 0, FALSE0);
6374}
6375
6376/* Finish up a method. */
6377
6378static bfd_boolean
6379ieee_class_end_method (void *p)
6380{
6381 struct ieee_handle *info = (struct ieee_handle *) p;
6382
6383 assert (info->type_stack != NULL((info->type_stack != ((void*)0) && info->type_stack
->type.classdef != ((void*)0) && info->type_stack
->type.classdef->method != ((void*)0)) ? (void)0 : __assert2
("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c", 6385, __func__
, "info->type_stack != NULL && info->type_stack->type.classdef != NULL && info->type_stack->type.classdef->method != NULL"
))
6384 && info->type_stack->type.classdef != NULL((info->type_stack != ((void*)0) && info->type_stack
->type.classdef != ((void*)0) && info->type_stack
->type.classdef->method != ((void*)0)) ? (void)0 : __assert2
("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c", 6385, __func__
, "info->type_stack != NULL && info->type_stack->type.classdef != NULL && info->type_stack->type.classdef->method != NULL"
))
6385 && info->type_stack->type.classdef->method != NULL)((info->type_stack != ((void*)0) && info->type_stack
->type.classdef != ((void*)0) && info->type_stack
->type.classdef->method != ((void*)0)) ? (void)0 : __assert2
("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c", 6385, __func__
, "info->type_stack != NULL && info->type_stack->type.classdef != NULL && info->type_stack->type.classdef->method != NULL"
))
;
6386
6387 info->type_stack->type.classdef->method = NULL((void*)0);
6388
6389 return TRUE1;
6390}
6391
6392/* Finish up a class. */
6393
6394static bfd_boolean
6395ieee_end_class_type (void *p)
6396{
6397 struct ieee_handle *info = (struct ieee_handle *) p;
6398 unsigned int nindx;
6399
6400 assert (info->type_stack != NULL((info->type_stack != ((void*)0) && info->type_stack
->type.classdef != ((void*)0)) ? (void)0 : __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 6401, __func__, "info->type_stack != NULL && info->type_stack->type.classdef != NULL"
))
6401 && info->type_stack->type.classdef != NULL)((info->type_stack != ((void*)0) && info->type_stack
->type.classdef != ((void*)0)) ? (void)0 : __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 6401, __func__, "info->type_stack != NULL && info->type_stack->type.classdef != NULL"
))
;
6402
6403 /* If we were ignoring this class definition because it was a
6404 duplicate definition, just through away whatever bytes we have
6405 accumulated. Leave the type on the stack. */
6406 if (info->type_stack->type.ignorep)
6407 return TRUE1;
6408
6409 nindx = info->type_stack->type.classdef->indx;
6410
6411 /* If we have a virtual table, we can write out the information now. */
6412 if (info->type_stack->type.classdef->vclass != NULL((void*)0)
6413 || info->type_stack->type.classdef->ownvptr)
6414 {
6415 if (! ieee_change_buffer (info,
6416 &info->type_stack->type.classdef->pmiscbuf)
6417 || ! ieee_write_asn (info, nindx, 'z')
6418 || ! ieee_write_atn65 (info, nindx, "")
6419 || ! ieee_write_asn (info, nindx,
6420 info->type_stack->type.classdef->voffset))
6421 return FALSE0;
6422 if (info->type_stack->type.classdef->ownvptr)
6423 {
6424 if (! ieee_write_atn65 (info, nindx, ""))
6425 return FALSE0;
6426 }
6427 else
6428 {
6429 if (! ieee_write_atn65 (info, nindx,
6430 info->type_stack->type.classdef->vclass))
6431 return FALSE0;
6432 }
6433 if (! ieee_write_asn (info, nindx, 0))
6434 return FALSE0;
6435 info->type_stack->type.classdef->pmisccount += 5;
6436 }
6437
6438 /* Now that we know the number of pmisc records, we can write out
6439 the atn62 which starts the pmisc records, and append them to the
6440 C++ buffers. */
6441
6442 if (! ieee_change_buffer (info, &info->cxx)
6443 || ! ieee_write_byte (info, (int) ieee_nn_record)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_nn_record), 1) :
ieee_real_write_byte ((info), ((int) ieee_nn_record)))
6444 || ! ieee_write_number (info, nindx)
6445 || ! ieee_write_id (info, "")
6446 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6447 || ! ieee_write_number (info, nindx)
6448 || ! ieee_write_number (info, 0)
6449 || ! ieee_write_number (info, 62)
6450 || ! ieee_write_number (info, 80)
6451 || ! ieee_write_number (info,
6452 info->type_stack->type.classdef->pmisccount))
6453 return FALSE0;
6454
6455 if (! ieee_append_buffer (info, &info->cxx,
6456 &info->type_stack->type.classdef->pmiscbuf))
6457 return FALSE0;
6458 if (! ieee_buffer_emptyp (&info->type_stack->type.classdef->refs)((&info->type_stack->type.classdef->refs)->head
== ((void*)0))
)
6459 {
6460 if (! ieee_append_buffer (info, &info->cxx,
6461 &info->type_stack->type.classdef->refs))
6462 return FALSE0;
6463 }
6464
6465 return ieee_end_struct_type (p);
6466}
6467
6468/* Push a previously seen typedef onto the type stack. */
6469
6470static bfd_boolean
6471ieee_typedef_type (void *p, const char *name)
6472{
6473 struct ieee_handle *info = (struct ieee_handle *) p;
6474 struct ieee_name_type_hash_entry *h;
6475 struct ieee_name_type *nt;
6476
6477 h = ieee_name_type_hash_lookup (&info->typedefs, name, FALSE, FALSE)((struct ieee_name_type_hash_entry *) bfd_hash_lookup (&(
&info->typedefs)->root, (name), (0), (0)))
;
6478
6479 /* h should never be NULL, since that would imply that the generic
6480 debugging code has asked for a typedef which it has not yet
6481 defined. */
6482 assert (h != NULL)((h != ((void*)0)) ? (void)0 : __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 6482, __func__, "h != NULL"))
;
6483
6484 /* We always use the most recently defined type for this name, which
6485 will be the first one on the list. */
6486
6487 nt = h->types;
6488 if (! ieee_push_type (info, nt->type.indx, nt->type.size,
6489 nt->type.unsignedp, nt->type.localp))
6490 return FALSE0;
6491
6492 /* Copy over any other type information we may have. */
6493 info->type_stack->type = nt->type;
6494
6495 return TRUE1;
6496}
6497
6498/* Push a tagged type onto the type stack. */
6499
6500static bfd_boolean
6501ieee_tag_type (void *p, const char *name, unsigned int id,
6502 enum debug_type_kind kind)
6503{
6504 struct ieee_handle *info = (struct ieee_handle *) p;
6505 bfd_boolean localp;
6506 bfd_boolean copy;
6507 char ab[20];
6508 struct ieee_name_type_hash_entry *h;
6509 struct ieee_name_type *nt;
6510
6511 if (kind == DEBUG_KIND_ENUM)
6512 {
6513 struct ieee_defined_enum *e;
6514
6515 if (name == NULL((void*)0))
6516 abort ();
6517 for (e = info->enums; e != NULL((void*)0); e = e->next)
6518 if (e->tag != NULL((void*)0) && strcmp (e->tag, name) == 0)
6519 return ieee_push_type (info, e->indx, 0, TRUE1, FALSE0);
6520
6521 e = (struct ieee_defined_enum *) xmalloc (sizeof *e);
6522 memset (e, 0, sizeof *e);
6523
6524 e->indx = info->type_indx;
6525 ++info->type_indx;
6526 e->tag = name;
6527 e->defined = FALSE0;
6528
6529 e->next = info->enums;
6530 info->enums = e;
6531
6532 return ieee_push_type (info, e->indx, 0, TRUE1, FALSE0);
6533 }
6534
6535 localp = FALSE0;
6536
6537 copy = FALSE0;
6538 if (name == NULL((void*)0))
6539 {
6540 sprintf (ab, "__anon%u", id);
6541 name = ab;
6542 copy = TRUE1;
6543 }
6544
6545 h = ieee_name_type_hash_lookup (&info->tags, name, TRUE, copy)((struct ieee_name_type_hash_entry *) bfd_hash_lookup (&(
&info->tags)->root, (name), (1), (copy)))
;
6546 if (h == NULL((void*)0))
6547 return FALSE0;
6548
6549 for (nt = h->types; nt != NULL((void*)0); nt = nt->next)
6550 {
6551 if (nt->id == id)
6552 {
6553 if (! ieee_push_type (info, nt->type.indx, nt->type.size,
6554 nt->type.unsignedp, nt->type.localp))
6555 return FALSE0;
6556 /* Copy over any other type information we may have. */
6557 info->type_stack->type = nt->type;
6558 return TRUE1;
6559 }
6560
6561 if (! nt->type.localp)
6562 {
6563 /* This is a duplicate of a global type, so it must be
6564 local. */
6565 localp = TRUE1;
6566 }
6567 }
6568
6569 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
6570 memset (nt, 0, sizeof *nt);
6571
6572 nt->id = id;
6573 nt->type.name = h->root.string;
6574 nt->type.indx = info->type_indx;
6575 nt->type.localp = localp;
6576 ++info->type_indx;
6577 nt->kind = kind;
6578
6579 nt->next = h->types;
6580 h->types = nt;
6581
6582 if (! ieee_push_type (info, nt->type.indx, 0, FALSE0, localp))
6583 return FALSE0;
6584
6585 info->type_stack->type.name = h->root.string;
6586
6587 return TRUE1;
6588}
6589
6590/* Output a typedef. */
6591
6592static bfd_boolean
6593ieee_typdef (void *p, const char *name)
6594{
6595 struct ieee_handle *info = (struct ieee_handle *) p;
6596 struct ieee_write_type type;
6597 unsigned int indx;
6598 bfd_boolean found;
6599 bfd_boolean localp;
6600 struct ieee_name_type_hash_entry *h;
6601 struct ieee_name_type *nt;
6602
6603 type = info->type_stack->type;
6604 indx = type.indx;
6605
6606 /* If this is a simple builtin type using a builtin name, we don't
6607 want to output the typedef itself. We also want to change the
6608 type index to correspond to the name being used. We recognize
6609 names used in stabs debugging output even if they don't exactly
6610 correspond to the names used for the IEEE builtin types. */
6611 found = FALSE0;
6612 if (indx <= (unsigned int) builtin_bcd_float)
6613 {
6614 switch ((enum builtin_types) indx)
6615 {
6616 default:
6617 break;
6618
6619 case builtin_void:
6620 if (strcmp (name, "void") == 0)
6621 found = TRUE1;
6622 break;
6623
6624 case builtin_signed_char:
6625 case builtin_char:
6626 if (strcmp (name, "signed char") == 0)
6627 {
6628 indx = (unsigned int) builtin_signed_char;
6629 found = TRUE1;
6630 }
6631 else if (strcmp (name, "char") == 0)
6632 {
6633 indx = (unsigned int) builtin_char;
6634 found = TRUE1;
6635 }
6636 break;
6637
6638 case builtin_unsigned_char:
6639 if (strcmp (name, "unsigned char") == 0)
6640 found = TRUE1;
6641 break;
6642
6643 case builtin_signed_short_int:
6644 case builtin_short:
6645 case builtin_short_int:
6646 case builtin_signed_short:
6647 if (strcmp (name, "signed short int") == 0)
6648 {
6649 indx = (unsigned int) builtin_signed_short_int;
6650 found = TRUE1;
6651 }
6652 else if (strcmp (name, "short") == 0)
6653 {
6654 indx = (unsigned int) builtin_short;
6655 found = TRUE1;
6656 }
6657 else if (strcmp (name, "short int") == 0)
6658 {
6659 indx = (unsigned int) builtin_short_int;
6660 found = TRUE1;
6661 }
6662 else if (strcmp (name, "signed short") == 0)
6663 {
6664 indx = (unsigned int) builtin_signed_short;
6665 found = TRUE1;
6666 }
6667 break;
6668
6669 case builtin_unsigned_short_int:
6670 case builtin_unsigned_short:
6671 if (strcmp (name, "unsigned short int") == 0
6672 || strcmp (name, "short unsigned int") == 0)
6673 {
6674 indx = builtin_unsigned_short_int;
6675 found = TRUE1;
6676 }
6677 else if (strcmp (name, "unsigned short") == 0)
6678 {
6679 indx = builtin_unsigned_short;
6680 found = TRUE1;
6681 }
6682 break;
6683
6684 case builtin_signed_long:
6685 case builtin_int: /* FIXME: Size depends upon architecture. */
6686 case builtin_long:
6687 if (strcmp (name, "signed long") == 0)
6688 {
6689 indx = builtin_signed_long;
6690 found = TRUE1;
6691 }
6692 else if (strcmp (name, "int") == 0)
6693 {
6694 indx = builtin_int;
6695 found = TRUE1;
6696 }
6697 else if (strcmp (name, "long") == 0
6698 || strcmp (name, "long int") == 0)
6699 {
6700 indx = builtin_long;
6701 found = TRUE1;
6702 }
6703 break;
6704
6705 case builtin_unsigned_long:
6706 case builtin_unsigned: /* FIXME: Size depends upon architecture. */
6707 case builtin_unsigned_int: /* FIXME: Like builtin_unsigned. */
6708 if (strcmp (name, "unsigned long") == 0
6709 || strcmp (name, "long unsigned int") == 0)
6710 {
6711 indx = builtin_unsigned_long;
6712 found = TRUE1;
6713 }
6714 else if (strcmp (name, "unsigned") == 0)
6715 {
6716 indx = builtin_unsigned;
6717 found = TRUE1;
6718 }
6719 else if (strcmp (name, "unsigned int") == 0)
6720 {
6721 indx = builtin_unsigned_int;
6722 found = TRUE1;
6723 }
6724 break;
6725
6726 case builtin_signed_long_long:
6727 if (strcmp (name, "signed long long") == 0
6728 || strcmp (name, "long long int") == 0)
6729 found = TRUE1;
6730 break;
6731
6732 case builtin_unsigned_long_long:
6733 if (strcmp (name, "unsigned long long") == 0
6734 || strcmp (name, "long long unsigned int") == 0)
6735 found = TRUE1;
6736 break;
6737
6738 case builtin_float:
6739 if (strcmp (name, "float") == 0)
6740 found = TRUE1;
6741 break;
6742
6743 case builtin_double:
6744 if (strcmp (name, "double") == 0)
6745 found = TRUE1;
6746 break;
6747
6748 case builtin_long_double:
6749 if (strcmp (name, "long double") == 0)
6750 found = TRUE1;
6751 break;
6752
6753 case builtin_long_long_double:
6754 if (strcmp (name, "long long double") == 0)
6755 found = TRUE1;
6756 break;
6757 }
6758
6759 if (found)
6760 type.indx = indx;
6761 }
6762
6763 h = ieee_name_type_hash_lookup (&info->typedefs, name, TRUE, FALSE)((struct ieee_name_type_hash_entry *) bfd_hash_lookup (&(
&info->typedefs)->root, (name), (1), (0)))
;
6764 if (h == NULL((void*)0))
6765 return FALSE0;
6766
6767 /* See if we have already defined this type with this name. */
6768 localp = type.localp;
6769 for (nt = h->types; nt != NULL((void*)0); nt = nt->next)
6770 {
6771 if (nt->id == indx)
6772 {
6773 /* If this is a global definition, then we don't need to
6774 do anything here. */
6775 if (! nt->type.localp)
6776 {
6777 ieee_pop_unused_type (info);
6778 return TRUE1;
6779 }
6780 }
6781 else
6782 {
6783 /* This is a duplicate definition, so make this one local. */
6784 localp = TRUE1;
6785 }
6786 }
6787
6788 /* We need to add a new typedef for this type. */
6789
6790 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
6791 memset (nt, 0, sizeof *nt);
6792 nt->id = indx;
6793 nt->type = type;
6794 nt->type.name = name;
6795 nt->type.localp = localp;
6796 nt->kind = DEBUG_KIND_ILLEGAL;
6797
6798 nt->next = h->types;
6799 h->types = nt;
6800
6801 if (found)
6802 {
6803 /* This is one of the builtin typedefs, so we don't need to
6804 actually define it. */
6805 ieee_pop_unused_type (info);
6806 return TRUE1;
6807 }
6808
6809 indx = ieee_pop_type (info);
6810
6811 if (! ieee_define_named_type (info, name, (unsigned int) -1, type.size,
6812 type.unsignedp, localp,
6813 (struct ieee_buflist *) NULL((void*)0))
6814 || ! ieee_write_number (info, 'T')
6815 || ! ieee_write_number (info, indx))
6816 return FALSE0;
6817
6818 /* Remove the type we just added to the type stack. This should not
6819 be ieee_pop_unused_type, since the type is used, we just don't
6820 need it now. */
6821 (void) ieee_pop_type (info);
6822
6823 return TRUE1;
6824}
6825
6826/* Output a tag for a type. We don't have to do anything here. */
6827
6828static bfd_boolean
6829ieee_tag (void *p, const char *name ATTRIBUTE_UNUSED__attribute__ ((__unused__)))
6830{
6831 struct ieee_handle *info = (struct ieee_handle *) p;
6832
6833 /* This should not be ieee_pop_unused_type, since we want the type
6834 to be defined. */
6835 (void) ieee_pop_type (info);
6836 return TRUE1;
6837}
6838
6839/* Output an integer constant. */
6840
6841static bfd_boolean
6842ieee_int_constant (void *p ATTRIBUTE_UNUSED__attribute__ ((__unused__)), const char *name ATTRIBUTE_UNUSED__attribute__ ((__unused__)),
6843 bfd_vma val ATTRIBUTE_UNUSED__attribute__ ((__unused__)))
6844{
6845 /* FIXME. */
6846 return TRUE1;
6847}
6848
6849/* Output a floating point constant. */
6850
6851static bfd_boolean
6852ieee_float_constant (void *p ATTRIBUTE_UNUSED__attribute__ ((__unused__)),
6853 const char *name ATTRIBUTE_UNUSED__attribute__ ((__unused__)),
6854 double val ATTRIBUTE_UNUSED__attribute__ ((__unused__)))
6855{
6856 /* FIXME. */
6857 return TRUE1;
6858}
6859
6860/* Output a typed constant. */
6861
6862static bfd_boolean
6863ieee_typed_constant (void *p, const char *name ATTRIBUTE_UNUSED__attribute__ ((__unused__)),
6864 bfd_vma val ATTRIBUTE_UNUSED__attribute__ ((__unused__)))
6865{
6866 struct ieee_handle *info = (struct ieee_handle *) p;
6867
6868 /* FIXME. */
6869 ieee_pop_unused_type (info);
6870 return TRUE1;
6871}
6872
6873/* Output a variable. */
6874
6875static bfd_boolean
6876ieee_variable (void *p, const char *name, enum debug_var_kind kind,
6877 bfd_vma val)
6878{
6879 struct ieee_handle *info = (struct ieee_handle *) p;
6880 unsigned int name_indx;
6881 unsigned int size;
6882 bfd_boolean referencep;
6883 unsigned int type_indx;
6884 bfd_boolean asn;
6885 int refflag;
6886
6887 size = info->type_stack->type.size;
6888 referencep = info->type_stack->type.referencep;
6889 type_indx = ieee_pop_type (info);
6890
6891 assert (! ieee_buffer_emptyp (&info->vars))((! ((&info->vars)->head == ((void*)0))) ? (void)0 :
__assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 6891, __func__, "! ieee_buffer_emptyp (&info->vars)"
))
;
6892 if (! ieee_change_buffer (info, &info->vars))
6893 return FALSE0;
6894
6895 name_indx = info->name_indx;
6896 ++info->name_indx;
6897
6898 /* Write out an NN and an ATN record for this variable. */
6899 if (! ieee_write_byte (info, (int) ieee_nn_record)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_nn_record), 1) :
ieee_real_write_byte ((info), ((int) ieee_nn_record)))
6900 || ! ieee_write_number (info, name_indx)
6901 || ! ieee_write_id (info, name)
6902 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6903 || ! ieee_write_number (info, name_indx)
6904 || ! ieee_write_number (info, type_indx))
6905 return FALSE0;
6906 switch (kind)
6907 {
6908 default:
6909 abort ();
6910 return FALSE0;
6911 case DEBUG_GLOBAL:
6912 if (! ieee_write_number (info, 8)
6913 || ! ieee_add_range (info, FALSE0, val, val + size))
6914 return FALSE0;
6915 refflag = 0;
6916 asn = TRUE1;
6917 break;
6918 case DEBUG_STATIC:
6919 if (! ieee_write_number (info, 3)
6920 || ! ieee_add_range (info, FALSE0, val, val + size))
6921 return FALSE0;
6922 refflag = 1;
6923 asn = TRUE1;
6924 break;
6925 case DEBUG_LOCAL_STATIC:
6926 if (! ieee_write_number (info, 3)
6927 || ! ieee_add_range (info, FALSE0, val, val + size))
6928 return FALSE0;
6929 refflag = 2;
6930 asn = TRUE1;
6931 break;
6932 case DEBUG_LOCAL:
6933 if (! ieee_write_number (info, 1)
6934 || ! ieee_write_number (info, val))
6935 return FALSE0;
6936 refflag = 2;
6937 asn = FALSE0;
6938 break;
6939 case DEBUG_REGISTER:
6940 if (! ieee_write_number (info, 2)
6941 || ! ieee_write_number (info,
6942 ieee_genreg_to_regno (info->abfd, val)))
6943 return FALSE0;
6944 refflag = 2;
6945 asn = FALSE0;
6946 break;
6947 }
6948
6949 if (asn)
6950 {
6951 if (! ieee_write_asn (info, name_indx, val))
6952 return FALSE0;
6953 }
6954
6955 /* If this is really a reference type, then we just output it with
6956 pointer type, and must now output a C++ record indicating that it
6957 is really reference type. */
6958 if (referencep)
6959 {
6960 unsigned int nindx;
6961
6962 nindx = info->name_indx;
6963 ++info->name_indx;
6964
6965 /* If this is a global variable, we want to output the misc
6966 record in the C++ misc record block. Otherwise, we want to
6967 output it just after the variable definition, which is where
6968 the current buffer is. */
6969 if (refflag != 2)
6970 {
6971 if (! ieee_change_buffer (info, &info->cxx))
6972 return FALSE0;
6973 }
6974
6975 if (! ieee_write_byte (info, (int) ieee_nn_record)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_nn_record), 1) :
ieee_real_write_byte ((info), ((int) ieee_nn_record)))
6976 || ! ieee_write_number (info, nindx)
6977 || ! ieee_write_id (info, "")
6978 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6979 || ! ieee_write_number (info, nindx)
6980 || ! ieee_write_number (info, 0)
6981 || ! ieee_write_number (info, 62)
6982 || ! ieee_write_number (info, 80)
6983 || ! ieee_write_number (info, 3)
6984 || ! ieee_write_asn (info, nindx, 'R')
6985 || ! ieee_write_asn (info, nindx, refflag)
6986 || ! ieee_write_atn65 (info, nindx, name))
6987 return FALSE0;
6988 }
6989
6990 return TRUE1;
6991}
6992
6993/* Start outputting information for a function. */
6994
6995static bfd_boolean
6996ieee_start_function (void *p, const char *name, bfd_boolean global)
6997{
6998 struct ieee_handle *info = (struct ieee_handle *) p;
6999 bfd_boolean referencep;
7000 unsigned int retindx, typeindx;
7001
7002 referencep = info->type_stack->type.referencep;
7003 retindx = ieee_pop_type (info);
7004
7005 /* Besides recording a BB4 or BB6 block, we record the type of the
7006 function in the BB1 typedef block. We can't write out the full
7007 type until we have seen all the parameters, so we accumulate it
7008 in info->fntype and info->fnargs. */
7009 if (! ieee_buffer_emptyp (&info->fntype)((&info->fntype)->head == ((void*)0)))
7010 {
7011 /* FIXME: This might happen someday if we support nested
7012 functions. */
7013 abort ();
7014 }
7015
7016 info->fnname = name;
7017
7018 /* An attribute of 0x40 means that the push mask is unknown. */
7019 if (! ieee_define_named_type (info, name, (unsigned int) -1, 0, FALSE0, TRUE1,
7020 &info->fntype)
7021 || ! ieee_write_number (info, 'x')
7022 || ! ieee_write_number (info, 0x40)
7023 || ! ieee_write_number (info, 0)
7024 || ! ieee_write_number (info, 0)
7025 || ! ieee_write_number (info, retindx))
7026 return FALSE0;
7027
7028 typeindx = ieee_pop_type (info);
7029
7030 if (! ieee_init_buffer (info, &info->fnargs))
7031 return FALSE0;
7032 info->fnargcount = 0;
7033
7034 /* If the function return value is actually a reference type, we
7035 must add a record indicating that. */
7036 if (referencep)
7037 {
7038 unsigned int nindx;
7039
7040 nindx = info->name_indx;
7041 ++info->name_indx;
7042 if (! ieee_change_buffer (info, &info->cxx)
7043 || ! ieee_write_byte (info, (int) ieee_nn_record)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_nn_record), 1) :
ieee_real_write_byte ((info), ((int) ieee_nn_record)))
7044 || ! ieee_write_number (info, nindx)
7045 || ! ieee_write_id (info, "")
7046 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7047 || ! ieee_write_number (info, nindx)
7048 || ! ieee_write_number (info, 0)
7049 || ! ieee_write_number (info, 62)
7050 || ! ieee_write_number (info, 80)
7051 || ! ieee_write_number (info, 3)
7052 || ! ieee_write_asn (info, nindx, 'R')
7053 || ! ieee_write_asn (info, nindx, global ? 0 : 1)
7054 || ! ieee_write_atn65 (info, nindx, name))
7055 return FALSE0;
7056 }
7057
7058 assert (! ieee_buffer_emptyp (&info->vars))((! ((&info->vars)->head == ((void*)0))) ? (void)0 :
__assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 7058, __func__, "! ieee_buffer_emptyp (&info->vars)"
))
;
7059 if (! ieee_change_buffer (info, &info->vars))
7060 return FALSE0;
7061
7062 /* The address is written out as the first block. */
7063
7064 ++info->block_depth;
7065
7066 return (ieee_write_byte (info, (int) ieee_bb_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_bb_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_bb_record_enum
)))
7067 && ieee_write_byte (info, global ? 4 : 6)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (global ? 4 : 6), 1) : ieee_real_write_byte
((info), (global ? 4 : 6)))
7068 && ieee_write_number (info, 0)
7069 && ieee_write_id (info, name)
7070 && ieee_write_number (info, 0)
7071 && ieee_write_number (info, typeindx));
7072}
7073
7074/* Add a function parameter. This will normally be called before the
7075 first block, so we postpone them until we see the block. */
7076
7077static bfd_boolean
7078ieee_function_parameter (void *p, const char *name, enum debug_parm_kind kind,
7079 bfd_vma val)
7080{
7081 struct ieee_handle *info = (struct ieee_handle *) p;
7082 struct ieee_pending_parm *m, **pm;
7083
7084 assert (info->block_depth == 1)((info->block_depth == 1) ? (void)0 : __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 7084, __func__, "info->block_depth == 1"))
;
7085
7086 m = (struct ieee_pending_parm *) xmalloc (sizeof *m);
7087 memset (m, 0, sizeof *m);
7088
7089 m->next = NULL((void*)0);
7090 m->name = name;
7091 m->referencep = info->type_stack->type.referencep;
7092 m->type = ieee_pop_type (info);
7093 m->kind = kind;
7094 m->val = val;
7095
7096 for (pm = &info->pending_parms; *pm != NULL((void*)0); pm = &(*pm)->next)
7097 ;
7098 *pm = m;
7099
7100 /* Add the type to the fnargs list. */
7101 if (! ieee_change_buffer (info, &info->fnargs)
7102 || ! ieee_write_number (info, m->type))
7103 return FALSE0;
7104 ++info->fnargcount;
7105
7106 return TRUE1;
7107}
7108
7109/* Output pending function parameters. */
7110
7111static bfd_boolean
7112ieee_output_pending_parms (struct ieee_handle *info)
7113{
7114 struct ieee_pending_parm *m;
7115 unsigned int refcount;
7116
7117 refcount = 0;
7118 for (m = info->pending_parms; m != NULL((void*)0); m = m->next)
7119 {
7120 enum debug_var_kind vkind;
7121
7122 switch (m->kind)
7123 {
7124 default:
7125 abort ();
7126 return FALSE0;
7127 case DEBUG_PARM_STACK:
7128 case DEBUG_PARM_REFERENCE:
7129 vkind = DEBUG_LOCAL;
7130 break;
7131 case DEBUG_PARM_REG:
7132 case DEBUG_PARM_REF_REG:
7133 vkind = DEBUG_REGISTER;
7134 break;
7135 }
7136
7137 if (! ieee_push_type (info, m->type, 0, FALSE0, FALSE0))
7138 return FALSE0;
7139 info->type_stack->type.referencep = m->referencep;
7140 if (m->referencep)
7141 ++refcount;
7142 if (! ieee_variable ((void *) info, m->name, vkind, m->val))
7143 return FALSE0;
7144 }
7145
7146 /* If there are any reference parameters, we need to output a
7147 miscellaneous record indicating them. */
7148 if (refcount > 0)
7149 {
7150 unsigned int nindx, varindx;
7151
7152 /* FIXME: The MRI compiler outputs the demangled function name
7153 here, but we are outputting the mangled name. */
7154 nindx = info->name_indx;
7155 ++info->name_indx;
7156 if (! ieee_change_buffer (info, &info->vars)
7157 || ! ieee_write_byte (info, (int) ieee_nn_record)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_nn_record), 1) :
ieee_real_write_byte ((info), ((int) ieee_nn_record)))
7158 || ! ieee_write_number (info, nindx)
7159 || ! ieee_write_id (info, "")
7160 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7161 || ! ieee_write_number (info, nindx)
7162 || ! ieee_write_number (info, 0)
7163 || ! ieee_write_number (info, 62)
7164 || ! ieee_write_number (info, 80)
7165 || ! ieee_write_number (info, refcount + 3)
7166 || ! ieee_write_asn (info, nindx, 'B')
7167 || ! ieee_write_atn65 (info, nindx, info->fnname)
7168 || ! ieee_write_asn (info, nindx, 0))
7169 return FALSE0;
7170 for (m = info->pending_parms, varindx = 1;
7171 m != NULL((void*)0);
7172 m = m->next, varindx++)
7173 {
7174 if (m->referencep)
7175 {
7176 if (! ieee_write_asn (info, nindx, varindx))
7177 return FALSE0;
7178 }
7179 }
7180 }
7181
7182 m = info->pending_parms;
7183 while (m != NULL((void*)0))
7184 {
7185 struct ieee_pending_parm *next;
7186
7187 next = m->next;
7188 free (m);
7189 m = next;
7190 }
7191
7192 info->pending_parms = NULL((void*)0);
7193
7194 return TRUE1;
7195}
7196
7197/* Start a block. If this is the first block, we output the address
7198 to finish the BB4 or BB6, and then output the function parameters. */
7199
7200static bfd_boolean
7201ieee_start_block (void *p, bfd_vma addr)
7202{
7203 struct ieee_handle *info = (struct ieee_handle *) p;
7204
7205 if (! ieee_change_buffer (info, &info->vars))
7206 return FALSE0;
7207
7208 if (info->block_depth == 1)
7209 {
7210 if (! ieee_write_number (info, addr)
7211 || ! ieee_output_pending_parms (info))
7212 return FALSE0;
7213 }
7214 else
7215 {
7216 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_bb_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_bb_record_enum
)))
7217 || ! ieee_write_byte (info, 6)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (6), 1) : ieee_real_write_byte
((info), (6)))
7218 || ! ieee_write_number (info, 0)
7219 || ! ieee_write_id (info, "")
7220 || ! ieee_write_number (info, 0)
7221 || ! ieee_write_number (info, 0)
7222 || ! ieee_write_number (info, addr))
7223 return FALSE0;
7224 }
7225
7226 if (! ieee_start_range (info, addr))
7227 return FALSE0;
7228
7229 ++info->block_depth;
7230
7231 return TRUE1;
7232}
7233
7234/* End a block. */
7235
7236static bfd_boolean
7237ieee_end_block (void *p, bfd_vma addr)
7238{
7239 struct ieee_handle *info = (struct ieee_handle *) p;
7240
7241 /* The address we are given is the end of the block, but IEEE seems
7242 to want to the address of the last byte in the block, so we
7243 subtract one. */
7244 if (! ieee_change_buffer (info, &info->vars)
7245 || ! ieee_write_byte (info, (int) ieee_be_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_be_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_be_record_enum
)))
7246 || ! ieee_write_number (info, addr - 1))
7247 return FALSE0;
7248
7249 if (! ieee_end_range (info, addr))
7250 return FALSE0;
7251
7252 --info->block_depth;
7253
7254 if (addr > info->highaddr)
7255 info->highaddr = addr;
7256
7257 return TRUE1;
7258}
7259
7260/* End a function. */
7261
7262static bfd_boolean
7263ieee_end_function (void *p)
7264{
7265 struct ieee_handle *info = (struct ieee_handle *) p;
7266
7267 assert (info->block_depth == 1)((info->block_depth == 1) ? (void)0 : __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 7267, __func__, "info->block_depth == 1"))
;
7268
7269 --info->block_depth;
7270
7271 /* Now we can finish up fntype, and add it to the typdef section.
7272 At this point, fntype is the 'x' type up to the argument count,
7273 and fnargs is the argument types. We must add the argument
7274 count, and we must add the level. FIXME: We don't record varargs
7275 functions correctly. In fact, stabs debugging does not give us
7276 enough information to do so. */
7277 if (! ieee_change_buffer (info, &info->fntype)
7278 || ! ieee_write_number (info, info->fnargcount)
7279 || ! ieee_change_buffer (info, &info->fnargs)
7280 || ! ieee_write_number (info, 0))
7281 return FALSE0;
7282
7283 /* Make sure the typdef block has been started. */
7284 if (ieee_buffer_emptyp (&info->types)((&info->types)->head == ((void*)0)))
7285 {
7286 if (! ieee_change_buffer (info, &info->types)
7287 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_bb_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_bb_record_enum
)))
7288 || ! ieee_write_byte (info, 1)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (1), 1) : ieee_real_write_byte
((info), (1)))
7289 || ! ieee_write_number (info, 0)
7290 || ! ieee_write_id (info, info->modname))
7291 return FALSE0;
7292 }
7293
7294 if (! ieee_append_buffer (info, &info->types, &info->fntype)
7295 || ! ieee_append_buffer (info, &info->types, &info->fnargs))
7296 return FALSE0;
7297
7298 info->fnname = NULL((void*)0);
7299 if (! ieee_init_buffer (info, &info->fntype)
7300 || ! ieee_init_buffer (info, &info->fnargs))
7301 return FALSE0;
7302 info->fnargcount = 0;
7303
7304 return TRUE1;
7305}
7306
7307/* Record line number information. */
7308
7309static bfd_boolean
7310ieee_lineno (void *p, const char *filename, unsigned long lineno, bfd_vma addr)
7311{
7312 struct ieee_handle *info = (struct ieee_handle *) p;
7313
7314 assert (info->filename != NULL)((info->filename != ((void*)0)) ? (void)0 : __assert2("/usr/src/gnu/usr.bin/binutils-2.17/binutils/ieee.c"
, 7314, __func__, "info->filename != NULL"))
;
7315
7316 /* The HP simulator seems to get confused when more than one line is
7317 listed for the same address, at least if they are in different
7318 files. We handle this by always listing the last line for a
7319 given address, since that seems to be the one that gdb uses. */
7320 if (info->pending_lineno_filename != NULL((void*)0)
7321 && addr != info->pending_lineno_addr)
7322 {
7323 /* Make sure we have a line number block. */
7324 if (! ieee_buffer_emptyp (&info->linenos)((&info->linenos)->head == ((void*)0)))
7325 {
7326 if (! ieee_change_buffer (info, &info->linenos))
7327 return FALSE0;
7328 }
7329 else
7330 {
7331 info->lineno_name_indx = info->name_indx;
7332 ++info->name_indx;
7333 if (! ieee_change_buffer (info, &info->linenos)
7334 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_bb_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_bb_record_enum
)))
7335 || ! ieee_write_byte (info, 5)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (5), 1) : ieee_real_write_byte
((info), (5)))
7336 || ! ieee_write_number (info, 0)
7337 || ! ieee_write_id (info, info->filename)
7338 || ! ieee_write_byte (info, (int) ieee_nn_record)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_nn_record), 1) :
ieee_real_write_byte ((info), ((int) ieee_nn_record)))
7339 || ! ieee_write_number (info, info->lineno_name_indx)
7340 || ! ieee_write_id (info, ""))
7341 return FALSE0;
7342 info->lineno_filename = info->filename;
7343 }
7344
7345 if (strcmp (info->pending_lineno_filename, info->lineno_filename) != 0)
7346 {
7347 if (strcmp (info->filename, info->lineno_filename) != 0)
7348 {
7349 /* We were not in the main file. Close the block for the
7350 included file. */
7351 if (! ieee_write_byte (info, (int) ieee_be_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_be_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_be_record_enum
)))
)
7352 return FALSE0;
7353 if (strcmp (info->filename, info->pending_lineno_filename) == 0)
7354 {
7355 /* We need a new NN record, and we aren't about to
7356 output one. */
7357 info->lineno_name_indx = info->name_indx;
7358 ++info->name_indx;
7359 if (! ieee_write_byte (info, (int) ieee_nn_record)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_nn_record), 1) :
ieee_real_write_byte ((info), ((int) ieee_nn_record)))
7360 || ! ieee_write_number (info, info->lineno_name_indx)
7361 || ! ieee_write_id (info, ""))
7362 return FALSE0;
7363 }
7364 }
7365 if (strcmp (info->filename, info->pending_lineno_filename) != 0)
7366 {
7367 /* We are not changing to the main file. Open a block for
7368 the new included file. */
7369 info->lineno_name_indx = info->name_indx;
7370 ++info->name_indx;
7371 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_bb_record_enum),
1) : ieee_real_write_byte ((info), ((int) ieee_bb_record_enum
)))
7372 || ! ieee_write_byte (info, 5)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = (5), 1) : ieee_real_write_byte
((info), (5)))
7373 || ! ieee_write_number (info, 0)
7374 || ! ieee_write_id (info, info->pending_lineno_filename)
7375 || ! ieee_write_byte (info, (int) ieee_nn_record)((info)->curbuf->c < (490) ? ((info)->curbuf->
buf[(info)->curbuf->c++] = ((int) ieee_nn_record), 1) :
ieee_real_write_byte ((info), ((int) ieee_nn_record)))
7376 || ! ieee_write_number (info, info->lineno_name_indx)
7377 || ! ieee_write_id (info, ""))
7378 return FALSE0;
7379 }
7380 info->lineno_filename = info->pending_lineno_filename;
7381 }
7382
7383 if (! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7384 || ! ieee_write_number (info, info->lineno_name_indx)
7385 || ! ieee_write_number (info, 0)
7386 || ! ieee_write_number (info, 7)
7387 || ! ieee_write_number (info, info->pending_lineno)
7388 || ! ieee_write_number (info, 0)
7389 || ! ieee_write_asn (info, info->lineno_name_indx,
7390 info->pending_lineno_addr))
7391 return FALSE0;
7392 }
7393
7394 info->pending_lineno_filename = filename;
7395 info->pending_lineno = lineno;
7396 info->pending_lineno_addr = addr;
7397
7398 return TRUE1;
7399}