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