00001 /* ieee.c -- Read and write IEEE-695 debugging information. 00002 Copyright (C) 1996 Free Software Foundation, Inc. 00003 Written by Ian Lance Taylor <ian@cygnus.com>. 00004 00005 This file is part of GNU Binutils. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00020 02111-1307, USA. */ 00021 00022 /* This file reads and writes IEEE-695 debugging information. */ 00023 00024 #include <stdio.h> 00025 #include <assert.h> 00026 00027 #include <bfd.h> 00028 #include "ieee.h" 00029 #include "bucomm.h" 00030 #include <libiberty.h> 00031 #include "debug.h" 00032 #include "budbg.h" 00033 00034 /* This structure holds an entry on the block stack. */ 00035 00036 struct ieee_block 00037 { 00038 /* The kind of block. */ 00039 int kind; 00040 /* The source file name, for a BB5 block. */ 00041 const char *filename; 00042 /* The index of the function type, for a BB4 or BB6 block. */ 00043 unsigned int fnindx; 00044 /* True if this function is being skipped. */ 00045 boolean skip; 00046 }; 00047 00048 /* This structure is the block stack. */ 00049 00050 #define BLOCKSTACK_SIZE (16) 00051 00052 struct ieee_blockstack 00053 { 00054 /* The stack pointer. */ 00055 struct ieee_block *bsp; 00056 /* The stack. */ 00057 struct ieee_block stack[BLOCKSTACK_SIZE]; 00058 }; 00059 00060 /* This structure holds information for a variable. */ 00061 00062 struct ieee_var 00063 { 00064 /* Start of name. */ 00065 const char *name; 00066 /* Length of name. */ 00067 unsigned long namlen; 00068 /* Type. */ 00069 debug_type type; 00070 /* Slot if we make an indirect type. */ 00071 debug_type *pslot; 00072 /* Kind of variable or function. */ 00073 enum 00074 { 00075 IEEE_UNKNOWN, 00076 IEEE_EXTERNAL, 00077 IEEE_GLOBAL, 00078 IEEE_STATIC, 00079 IEEE_LOCAL, 00080 IEEE_FUNCTION 00081 } kind; 00082 }; 00083 00084 /* This structure holds all the variables. */ 00085 00086 struct ieee_vars 00087 { 00088 /* Number of slots allocated. */ 00089 unsigned int alloc; 00090 /* Variables. */ 00091 struct ieee_var *vars; 00092 }; 00093 00094 /* This structure holds information for a type. We need this because 00095 we don't want to represent bitfields as real types. */ 00096 00097 struct ieee_type 00098 { 00099 /* Type. */ 00100 debug_type type; 00101 /* Slot if this is type is referenced before it is defined. */ 00102 debug_type *pslot; 00103 /* Slots for arguments if we make indirect types for them. */ 00104 debug_type *arg_slots; 00105 /* If this is a bitfield, this is the size in bits. If this is not 00106 a bitfield, this is zero. */ 00107 unsigned long bitsize; 00108 }; 00109 00110 /* This structure holds all the type information. */ 00111 00112 struct ieee_types 00113 { 00114 /* Number of slots allocated. */ 00115 unsigned int alloc; 00116 /* Types. */ 00117 struct ieee_type *types; 00118 /* Builtin types. */ 00119 #define BUILTIN_TYPE_COUNT (60) 00120 debug_type builtins[BUILTIN_TYPE_COUNT]; 00121 }; 00122 00123 /* This structure holds a linked last of structs with their tag names, 00124 so that we can convert them to C++ classes if necessary. */ 00125 00126 struct ieee_tag 00127 { 00128 /* Next tag. */ 00129 struct ieee_tag *next; 00130 /* This tag name. */ 00131 const char *name; 00132 /* The type of the tag. */ 00133 debug_type type; 00134 /* The tagged type is an indirect type pointing at this slot. */ 00135 debug_type slot; 00136 /* This is an array of slots used when a field type is converted 00137 into a indirect type, in case it needs to be later converted into 00138 a reference type. */ 00139 debug_type *fslots; 00140 }; 00141 00142 /* This structure holds the information we pass around to the parsing 00143 functions. */ 00144 00145 struct ieee_info 00146 { 00147 /* The debugging handle. */ 00148 PTR dhandle; 00149 /* The BFD. */ 00150 bfd *abfd; 00151 /* The start of the bytes to be parsed. */ 00152 const bfd_byte *bytes; 00153 /* The end of the bytes to be parsed. */ 00154 const bfd_byte *pend; 00155 /* The block stack. */ 00156 struct ieee_blockstack blockstack; 00157 /* Whether we have seen a BB1 or BB2. */ 00158 boolean saw_filename; 00159 /* The variables. */ 00160 struct ieee_vars vars; 00161 /* The global variables, after a global typedef block. */ 00162 struct ieee_vars *global_vars; 00163 /* The types. */ 00164 struct ieee_types types; 00165 /* The global types, after a global typedef block. */ 00166 struct ieee_types *global_types; 00167 /* The list of tagged structs. */ 00168 struct ieee_tag *tags; 00169 }; 00170 00171 /* Basic builtin types, not including the pointers. */ 00172 00173 enum builtin_types 00174 { 00175 builtin_unknown = 0, 00176 builtin_void = 1, 00177 builtin_signed_char = 2, 00178 builtin_unsigned_char = 3, 00179 builtin_signed_short_int = 4, 00180 builtin_unsigned_short_int = 5, 00181 builtin_signed_long = 6, 00182 builtin_unsigned_long = 7, 00183 builtin_signed_long_long = 8, 00184 builtin_unsigned_long_long = 9, 00185 builtin_float = 10, 00186 builtin_double = 11, 00187 builtin_long_double = 12, 00188 builtin_long_long_double = 13, 00189 builtin_quoted_string = 14, 00190 builtin_instruction_address = 15, 00191 builtin_int = 16, 00192 builtin_unsigned = 17, 00193 builtin_unsigned_int = 18, 00194 builtin_char = 19, 00195 builtin_long = 20, 00196 builtin_short = 21, 00197 builtin_unsigned_short = 22, 00198 builtin_short_int = 23, 00199 builtin_signed_short = 24, 00200 builtin_bcd_float = 25 00201 }; 00202 00203 /* These are the values found in the derivation flags of a 'b' 00204 component record of a 'T' type extension record in a C++ pmisc 00205 record. These are bitmasks. */ 00206 00207 /* Set for a private base class, clear for a public base class. 00208 Protected base classes are not supported. */ 00209 #define BASEFLAGS_PRIVATE (0x1) 00210 /* Set for a virtual base class. */ 00211 #define BASEFLAGS_VIRTUAL (0x2) 00212 /* Set for a friend class, clear for a base class. */ 00213 #define BASEFLAGS_FRIEND (0x10) 00214 00215 /* These are the values found in the specs flags of a 'd', 'm', or 'v' 00216 component record of a 'T' type extension record in a C++ pmisc 00217 record. The same flags are used for a 'M' record in a C++ pmisc 00218 record. */ 00219 00220 /* The lower two bits hold visibility information. */ 00221 #define CXXFLAGS_VISIBILITY (0x3) 00222 /* This value in the lower two bits indicates a public member. */ 00223 #define CXXFLAGS_VISIBILITY_PUBLIC (0x0) 00224 /* This value in the lower two bits indicates a private member. */ 00225 #define CXXFLAGS_VISIBILITY_PRIVATE (0x1) 00226 /* This value in the lower two bits indicates a protected member. */ 00227 #define CXXFLAGS_VISIBILITY_PROTECTED (0x2) 00228 /* Set for a static member. */ 00229 #define CXXFLAGS_STATIC (0x4) 00230 /* Set for a virtual override. */ 00231 #define CXXFLAGS_OVERRIDE (0x8) 00232 /* Set for a friend function. */ 00233 #define CXXFLAGS_FRIEND (0x10) 00234 /* Set for a const function. */ 00235 #define CXXFLAGS_CONST (0x20) 00236 /* Set for a volatile function. */ 00237 #define CXXFLAGS_VOLATILE (0x40) 00238 /* Set for an overloaded function. */ 00239 #define CXXFLAGS_OVERLOADED (0x80) 00240 /* Set for an operator function. */ 00241 #define CXXFLAGS_OPERATOR (0x100) 00242 /* Set for a constructor or destructor. */ 00243 #define CXXFLAGS_CTORDTOR (0x400) 00244 /* Set for a constructor. */ 00245 #define CXXFLAGS_CTOR (0x200) 00246 /* Set for an inline function. */ 00247 #define CXXFLAGS_INLINE (0x800) 00248 00249 /* Local functions. */ 00250 00251 static void ieee_error 00252 PARAMS ((struct ieee_info *, const bfd_byte *, const char *)); 00253 static void ieee_eof PARAMS ((struct ieee_info *)); 00254 static char *savestring PARAMS ((const char *, unsigned long)); 00255 static boolean ieee_read_number 00256 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *)); 00257 static boolean ieee_read_optional_number 00258 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *, boolean *)); 00259 static boolean ieee_read_id 00260 PARAMS ((struct ieee_info *, const bfd_byte **, const char **, 00261 unsigned long *)); 00262 static boolean ieee_read_optional_id 00263 PARAMS ((struct ieee_info *, const bfd_byte **, const char **, 00264 unsigned long *, boolean *)); 00265 static boolean ieee_read_expression 00266 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *)); 00267 static debug_type ieee_builtin_type 00268 PARAMS ((struct ieee_info *, const bfd_byte *, unsigned int)); 00269 static boolean ieee_alloc_type 00270 PARAMS ((struct ieee_info *, unsigned int, boolean)); 00271 static boolean ieee_read_type_index 00272 PARAMS ((struct ieee_info *, const bfd_byte **, debug_type *)); 00273 static int ieee_regno_to_genreg PARAMS ((bfd *, int)); 00274 static int ieee_genreg_to_regno PARAMS ((bfd *, int)); 00275 static boolean parse_ieee_bb PARAMS ((struct ieee_info *, const bfd_byte **)); 00276 static boolean parse_ieee_be PARAMS ((struct ieee_info *, const bfd_byte **)); 00277 static boolean parse_ieee_nn PARAMS ((struct ieee_info *, const bfd_byte **)); 00278 static boolean parse_ieee_ty PARAMS ((struct ieee_info *, const bfd_byte **)); 00279 static boolean parse_ieee_atn PARAMS ((struct ieee_info *, const bfd_byte **)); 00280 static boolean ieee_read_cxx_misc 00281 PARAMS ((struct ieee_info *, const bfd_byte **, unsigned long)); 00282 static boolean ieee_read_cxx_class 00283 PARAMS ((struct ieee_info *, const bfd_byte **, unsigned long)); 00284 static boolean ieee_read_cxx_defaults 00285 PARAMS ((struct ieee_info *, const bfd_byte **, unsigned long)); 00286 static boolean ieee_read_reference 00287 PARAMS ((struct ieee_info *, const bfd_byte **)); 00288 static boolean ieee_require_asn 00289 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *)); 00290 static boolean ieee_require_atn65 00291 PARAMS ((struct ieee_info *, const bfd_byte **, const char **, 00292 unsigned long *)); 00293 00294 /* Report an error in the IEEE debugging information. */ 00295 00296 static void 00297 ieee_error (info, p, s) 00298 struct ieee_info *info; 00299 const bfd_byte *p; 00300 const char *s; 00301 { 00302 if (p != NULL) 00303 fprintf (stderr, "%s: 0x%lx: %s (0x%x)\n", bfd_get_filename (info->abfd), 00304 (unsigned long) (p - info->bytes), s, *p); 00305 else 00306 fprintf (stderr, "%s: %s\n", bfd_get_filename (info->abfd), s); 00307 } 00308 00309 /* Report an unexpected EOF in the IEEE debugging information. */ 00310 00311 static void 00312 ieee_eof (info) 00313 struct ieee_info *info; 00314 { 00315 ieee_error (info, (const bfd_byte *) NULL, 00316 "unexpected end of debugging information"); 00317 } 00318 00319 /* Save a string in memory. */ 00320 00321 static char * 00322 savestring (start, len) 00323 const char *start; 00324 unsigned long len; 00325 { 00326 char *ret; 00327 00328 ret = (char *) xmalloc (len + 1); 00329 memcpy (ret, start, len); 00330 ret[len] = '\0'; 00331 return ret; 00332 } 00333 00334 /* Read a number which must be present in an IEEE file. */ 00335 00336 static boolean 00337 ieee_read_number (info, pp, pv) 00338 struct ieee_info *info; 00339 const bfd_byte **pp; 00340 bfd_vma *pv; 00341 { 00342 return ieee_read_optional_number (info, pp, pv, (boolean *) NULL); 00343 } 00344 00345 /* Read a number in an IEEE file. If ppresent is not NULL, the number 00346 need not be there. */ 00347 00348 static boolean 00349 ieee_read_optional_number (info, pp, pv, ppresent) 00350 struct ieee_info *info; 00351 const bfd_byte **pp; 00352 bfd_vma *pv; 00353 boolean *ppresent; 00354 { 00355 ieee_record_enum_type b; 00356 00357 if (*pp >= info->pend) 00358 { 00359 if (ppresent != NULL) 00360 { 00361 *ppresent = false; 00362 return true; 00363 } 00364 ieee_eof (info); 00365 return false; 00366 } 00367 00368 b = (ieee_record_enum_type) **pp; 00369 ++*pp; 00370 00371 if (b <= ieee_number_end_enum) 00372 { 00373 *pv = (bfd_vma) b; 00374 if (ppresent != NULL) 00375 *ppresent = true; 00376 return true; 00377 } 00378 00379 if (b >= ieee_number_repeat_start_enum && b <= ieee_number_repeat_end_enum) 00380 { 00381 unsigned int i; 00382 00383 i = (int) b - (int) ieee_number_repeat_start_enum; 00384 if (*pp + i - 1 >= info->pend) 00385 { 00386 ieee_eof (info); 00387 return false; 00388 } 00389 00390 *pv = 0; 00391 for (; i > 0; i--) 00392 { 00393 *pv <<= 8; 00394 *pv += **pp; 00395 ++*pp; 00396 } 00397 00398 if (ppresent != NULL) 00399 *ppresent = true; 00400 00401 return true; 00402 } 00403 00404 if (ppresent != NULL) 00405 { 00406 --*pp; 00407 *ppresent = false; 00408 return true; 00409 } 00410 00411 ieee_error (info, *pp - 1, "invalid number"); 00412 return false; 00413 } 00414 00415 /* Read a required string from an IEEE file. */ 00416 00417 static boolean 00418 ieee_read_id (info, pp, pname, pnamlen) 00419 struct ieee_info *info; 00420 const bfd_byte **pp; 00421 const char **pname; 00422 unsigned long *pnamlen; 00423 { 00424 return ieee_read_optional_id (info, pp, pname, pnamlen, (boolean *) NULL); 00425 } 00426 00427 /* Read a string from an IEEE file. If ppresent is not NULL, the 00428 string is optional. */ 00429 00430 static boolean 00431 ieee_read_optional_id (info, pp, pname, pnamlen, ppresent) 00432 struct ieee_info *info; 00433 const bfd_byte **pp; 00434 const char **pname; 00435 unsigned long *pnamlen; 00436 boolean *ppresent; 00437 { 00438 bfd_byte b; 00439 unsigned long len; 00440 00441 if (*pp >= info->pend) 00442 { 00443 ieee_eof (info); 00444 return false; 00445 } 00446 00447 b = **pp; 00448 ++*pp; 00449 00450 if (b <= 0x7f) 00451 len = b; 00452 else if ((ieee_record_enum_type) b == ieee_extension_length_1_enum) 00453 { 00454 len = **pp; 00455 ++*pp; 00456 } 00457 else if ((ieee_record_enum_type) b == ieee_extension_length_2_enum) 00458 { 00459 len = (**pp << 8) + (*pp)[1]; 00460 *pp += 2; 00461 } 00462 else 00463 { 00464 if (ppresent != NULL) 00465 { 00466 --*pp; 00467 *ppresent = false; 00468 return true; 00469 } 00470 ieee_error (info, *pp - 1, "invalid string length"); 00471 return false; 00472 } 00473 00474 if ((unsigned long) (info->pend - *pp) < len) 00475 { 00476 ieee_eof (info); 00477 return false; 00478 } 00479 00480 *pname = (const char *) *pp; 00481 *pnamlen = len; 00482 *pp += len; 00483 00484 if (ppresent != NULL) 00485 *ppresent = true; 00486 00487 return true; 00488 } 00489 00490 /* Read an expression from an IEEE file. Since this code is only used 00491 to parse debugging information, I haven't bothered to write a full 00492 blown IEEE expression parser. I've only thrown in the things I've 00493 seen in debugging information. This can be easily extended if 00494 necessary. */ 00495 00496 static boolean 00497 ieee_read_expression (info, pp, pv) 00498 struct ieee_info *info; 00499 const bfd_byte **pp; 00500 bfd_vma *pv; 00501 { 00502 const bfd_byte *expr_start; 00503 #define EXPR_STACK_SIZE (10) 00504 bfd_vma expr_stack[EXPR_STACK_SIZE]; 00505 bfd_vma *esp; 00506 00507 expr_start = *pp; 00508 00509 esp = expr_stack; 00510 00511 while (1) 00512 { 00513 const bfd_byte *start; 00514 bfd_vma val; 00515 boolean present; 00516 ieee_record_enum_type c; 00517 00518 start = *pp; 00519 00520 if (! ieee_read_optional_number (info, pp, &val, &present)) 00521 return false; 00522 00523 if (present) 00524 { 00525 if (esp - expr_stack >= EXPR_STACK_SIZE) 00526 { 00527 ieee_error (info, start, "expression stack overflow"); 00528 return false; 00529 } 00530 *esp++ = val; 00531 continue; 00532 } 00533 00534 c = (ieee_record_enum_type) **pp; 00535 00536 if (c >= ieee_module_beginning_enum) 00537 break; 00538 00539 ++*pp; 00540 00541 if (c == ieee_comma) 00542 break; 00543 00544 switch (c) 00545 { 00546 default: 00547 ieee_error (info, start, "unsupported IEEE expression operator"); 00548 break; 00549 00550 case ieee_variable_R_enum: 00551 { 00552 bfd_vma indx; 00553 asection *s; 00554 00555 if (! ieee_read_number (info, pp, &indx)) 00556 return false; 00557 for (s = info->abfd->sections; s != NULL; s = s->next) 00558 if ((bfd_vma) s->target_index == indx) 00559 break; 00560 if (s == NULL) 00561 { 00562 ieee_error (info, start, "unknown section"); 00563 return false; 00564 } 00565 00566 if (esp - expr_stack >= EXPR_STACK_SIZE) 00567 { 00568 ieee_error (info, start, "expression stack overflow"); 00569 return false; 00570 } 00571 00572 *esp++ = bfd_get_section_vma (info->abfd, s); 00573 } 00574 break; 00575 00576 case ieee_function_plus_enum: 00577 case ieee_function_minus_enum: 00578 { 00579 bfd_vma v1, v2; 00580 00581 if (esp - expr_stack < 2) 00582 { 00583 ieee_error (info, start, "expression stack underflow"); 00584 return false; 00585 } 00586 00587 v1 = *--esp; 00588 v2 = *--esp; 00589 *esp++ = v1 + v2; 00590 } 00591 break; 00592 } 00593 } 00594 00595 if (esp - 1 != expr_stack) 00596 { 00597 ieee_error (info, expr_start, "expression stack mismatch"); 00598 return false; 00599 } 00600 00601 *pv = *--esp; 00602 00603 return true; 00604 } 00605 00606 /* Return an IEEE builtin type. */ 00607 00608 static debug_type 00609 ieee_builtin_type (info, p, indx) 00610 struct ieee_info *info; 00611 const bfd_byte *p; 00612 unsigned int indx; 00613 { 00614 PTR dhandle; 00615 debug_type type; 00616 const char *name; 00617 00618 if (indx < BUILTIN_TYPE_COUNT 00619 && info->types.builtins[indx] != DEBUG_TYPE_NULL) 00620 return info->types.builtins[indx]; 00621 00622 dhandle = info->dhandle; 00623 00624 if (indx >= 32 && indx < 64) 00625 { 00626 type = debug_make_pointer_type (dhandle, 00627 ieee_builtin_type (info, p, indx - 32)); 00628 assert (indx < BUILTIN_TYPE_COUNT); 00629 info->types.builtins[indx] = type; 00630 return type; 00631 } 00632 00633 switch ((enum builtin_types) indx) 00634 { 00635 default: 00636 ieee_error (info, p, "unknown builtin type"); 00637 return NULL; 00638 00639 case builtin_unknown: 00640 type = debug_make_void_type (dhandle); 00641 name = NULL; 00642 break; 00643 00644 case builtin_void: 00645 type = debug_make_void_type (dhandle); 00646 name = "void"; 00647 break; 00648 00649 case builtin_signed_char: 00650 type = debug_make_int_type (dhandle, 1, false); 00651 name = "signed char"; 00652 break; 00653 00654 case builtin_unsigned_char: 00655 type = debug_make_int_type (dhandle, 1, true); 00656 name = "unsigned char"; 00657 break; 00658 00659 case builtin_signed_short_int: 00660 type = debug_make_int_type (dhandle, 2, false); 00661 name = "signed short int"; 00662 break; 00663 00664 case builtin_unsigned_short_int: 00665 type = debug_make_int_type (dhandle, 2, true); 00666 name = "unsigned short int"; 00667 break; 00668 00669 case builtin_signed_long: 00670 type = debug_make_int_type (dhandle, 4, false); 00671 name = "signed long"; 00672 break; 00673 00674 case builtin_unsigned_long: 00675 type = debug_make_int_type (dhandle, 4, true); 00676 name = "unsigned long"; 00677 break; 00678 00679 case builtin_signed_long_long: 00680 type = debug_make_int_type (dhandle, 8, false); 00681 name = "signed long long"; 00682 break; 00683 00684 case builtin_unsigned_long_long: 00685 type = debug_make_int_type (dhandle, 8, true); 00686 name = "unsigned long long"; 00687 break; 00688 00689 case builtin_float: 00690 type = debug_make_float_type (dhandle, 4); 00691 name = "float"; 00692 break; 00693 00694 case builtin_double: 00695 type = debug_make_float_type (dhandle, 8); 00696 name = "double"; 00697 break; 00698 00699 case builtin_long_double: 00700 /* FIXME: The size for this type should depend upon the 00701 processor. */ 00702 type = debug_make_float_type (dhandle, 12); 00703 name = "long double"; 00704 break; 00705 00706 case builtin_long_long_double: 00707 type = debug_make_float_type (dhandle, 16); 00708 name = "long long double"; 00709 break; 00710 00711 case builtin_quoted_string: 00712 type = debug_make_array_type (dhandle, 00713 ieee_builtin_type (info, p, 00714 ((unsigned int) 00715 builtin_char)), 00716 ieee_builtin_type (info, p, 00717 ((unsigned int) 00718 builtin_int)), 00719 0, -1, true); 00720 name = "QUOTED STRING"; 00721 break; 00722 00723 case builtin_instruction_address: 00724 /* FIXME: This should be a code address. */ 00725 type = debug_make_int_type (dhandle, 4, true); 00726 name = "instruction address"; 00727 break; 00728 00729 case builtin_int: 00730 /* FIXME: The size for this type should depend upon the 00731 processor. */ 00732 type = debug_make_int_type (dhandle, 4, false); 00733 name = "int"; 00734 break; 00735 00736 case builtin_unsigned: 00737 /* FIXME: The size for this type should depend upon the 00738 processor. */ 00739 type = debug_make_int_type (dhandle, 4, true); 00740 name = "unsigned"; 00741 break; 00742 00743 case builtin_unsigned_int: 00744 /* FIXME: The size for this type should depend upon the 00745 processor. */ 00746 type = debug_make_int_type (dhandle, 4, true); 00747 name = "unsigned int"; 00748 break; 00749 00750 case builtin_char: 00751 type = debug_make_int_type (dhandle, 1, false); 00752 name = "char"; 00753 break; 00754 00755 case builtin_long: 00756 type = debug_make_int_type (dhandle, 4, false); 00757 name = "long"; 00758 break; 00759 00760 case builtin_short: 00761 type = debug_make_int_type (dhandle, 2, false); 00762 name = "short"; 00763 break; 00764 00765 case builtin_unsigned_short: 00766 type = debug_make_int_type (dhandle, 2, true); 00767 name = "unsigned short"; 00768 break; 00769 00770 case builtin_short_int: 00771 type = debug_make_int_type (dhandle, 2, false); 00772 name = "short int"; 00773 break; 00774 00775 case builtin_signed_short: 00776 type = debug_make_int_type (dhandle, 2, false); 00777 name = "signed short"; 00778 break; 00779 00780 case builtin_bcd_float: 00781 ieee_error (info, p, "BCD float type not supported"); 00782 return DEBUG_TYPE_NULL; 00783 } 00784 00785 if (name != NULL) 00786 type = debug_name_type (dhandle, name, type); 00787 00788 assert (indx < BUILTIN_TYPE_COUNT); 00789 00790 info->types.builtins[indx] = type; 00791 00792 return type; 00793 } 00794 00795 /* Allocate more space in the type table. If ref is true, this is a 00796 reference to the type; if it is not already defined, we should set 00797 up an indirect type. */ 00798 00799 static boolean 00800 ieee_alloc_type (info, indx, ref) 00801 struct ieee_info *info; 00802 unsigned int indx; 00803 boolean ref; 00804 { 00805 unsigned int nalloc; 00806 register struct ieee_type *t; 00807 struct ieee_type *tend; 00808 00809 if (indx >= info->types.alloc) 00810 { 00811 nalloc = info->types.alloc; 00812 if (nalloc == 0) 00813 nalloc = 4; 00814 while (indx >= nalloc) 00815 nalloc *= 2; 00816 00817 info->types.types = ((struct ieee_type *) 00818 xrealloc (info->types.types, 00819 nalloc * sizeof *info->types.types)); 00820 00821 memset (info->types.types + info->types.alloc, 0, 00822 (nalloc - info->types.alloc) * sizeof *info->types.types); 00823 00824 tend = info->types.types + nalloc; 00825 for (t = info->types.types + info->types.alloc; t < tend; t++) 00826 t->type = DEBUG_TYPE_NULL; 00827 00828 info->types.alloc = nalloc; 00829 } 00830 00831 if (ref) 00832 { 00833 t = info->types.types + indx; 00834 if (t->type == NULL) 00835 { 00836 t->pslot = (debug_type *) xmalloc (sizeof *t->pslot); 00837 *t->pslot = DEBUG_TYPE_NULL; 00838 t->type = debug_make_indirect_type (info->dhandle, t->pslot, 00839 (const char *) NULL); 00840 if (t->type == NULL) 00841 return false; 00842 } 00843 } 00844 00845 return true; 00846 } 00847 00848 /* Read a type index and return the corresponding type. */ 00849 00850 static boolean 00851 ieee_read_type_index (info, pp, ptype) 00852 struct ieee_info *info; 00853 const bfd_byte **pp; 00854 debug_type *ptype; 00855 { 00856 const bfd_byte *start; 00857 bfd_vma indx; 00858 00859 start = *pp; 00860 00861 if (! ieee_read_number (info, pp, &indx)) 00862 return false; 00863 00864 if (indx < 256) 00865 { 00866 *ptype = ieee_builtin_type (info, start, indx); 00867 if (*ptype == NULL) 00868 return false; 00869 return true; 00870 } 00871 00872 indx -= 256; 00873 if (! ieee_alloc_type (info, indx, true)) 00874 return false; 00875 00876 *ptype = info->types.types[indx].type; 00877 00878 return true; 00879 } 00880 00881 /* Parse IEEE debugging information for a file. This is passed the 00882 bytes which compose the Debug Information Part of an IEEE file. */ 00883 00884 boolean 00885 parse_ieee (dhandle, abfd, bytes, len) 00886 PTR dhandle; 00887 bfd *abfd; 00888 const bfd_byte *bytes; 00889 bfd_size_type len; 00890 { 00891 struct ieee_info info; 00892 unsigned int i; 00893 const bfd_byte *p, *pend; 00894 00895 info.dhandle = dhandle; 00896 info.abfd = abfd; 00897 info.bytes = bytes; 00898 info.pend = bytes + len; 00899 info.blockstack.bsp = info.blockstack.stack; 00900 info.saw_filename = false; 00901 info.vars.alloc = 0; 00902 info.vars.vars = NULL; 00903 info.types.alloc = 0; 00904 info.types.types = NULL; 00905 info.tags = NULL; 00906 for (i = 0; i < BUILTIN_TYPE_COUNT; i++) 00907 info.types.builtins[i] = DEBUG_TYPE_NULL; 00908 00909 p = bytes; 00910 pend = info.pend; 00911 while (p < pend) 00912 { 00913 const bfd_byte *record_start; 00914 ieee_record_enum_type c; 00915 00916 record_start = p; 00917 00918 c = (ieee_record_enum_type) *p++; 00919 00920 if (c == ieee_at_record_enum) 00921 c = (ieee_record_enum_type) (((unsigned int) c << 8) | *p++); 00922 00923 if (c <= ieee_number_repeat_end_enum) 00924 { 00925 ieee_error (&info, record_start, "unexpected number"); 00926 return false; 00927 } 00928 00929 switch (c) 00930 { 00931 default: 00932 ieee_error (&info, record_start, "unexpected record type"); 00933 return false; 00934 00935 case ieee_bb_record_enum: 00936 if (! parse_ieee_bb (&info, &p)) 00937 return false; 00938 break; 00939 00940 case ieee_be_record_enum: 00941 if (! parse_ieee_be (&info, &p)) 00942 return false; 00943 break; 00944 00945 case ieee_nn_record: 00946 if (! parse_ieee_nn (&info, &p)) 00947 return false; 00948 break; 00949 00950 case ieee_ty_record_enum: 00951 if (! parse_ieee_ty (&info, &p)) 00952 return false; 00953 break; 00954 00955 case ieee_atn_record_enum: 00956 if (! parse_ieee_atn (&info, &p)) 00957 return false; 00958 break; 00959 } 00960 } 00961 00962 if (info.blockstack.bsp != info.blockstack.stack) 00963 { 00964 ieee_error (&info, (const bfd_byte *) NULL, 00965 "blocks left on stack at end"); 00966 return false; 00967 } 00968 00969 return true; 00970 } 00971 00972 /* Handle an IEEE BB record. */ 00973 00974 static boolean 00975 parse_ieee_bb (info, pp) 00976 struct ieee_info *info; 00977 const bfd_byte **pp; 00978 { 00979 const bfd_byte *block_start; 00980 bfd_byte b; 00981 bfd_vma size; 00982 const char *name; 00983 unsigned long namlen; 00984 char *namcopy = NULL; 00985 unsigned int fnindx; 00986 boolean skip; 00987 00988 block_start = *pp; 00989 00990 b = **pp; 00991 ++*pp; 00992 00993 if (! ieee_read_number (info, pp, &size) 00994 || ! ieee_read_id (info, pp, &name, &namlen)) 00995 return false; 00996 00997 fnindx = (unsigned int) -1; 00998 skip = false; 00999 01000 switch (b) 01001 { 01002 case 1: 01003 /* BB1: Type definitions local to a module. */ 01004 namcopy = savestring (name, namlen); 01005 if (namcopy == NULL) 01006 return false; 01007 if (! debug_set_filename (info->dhandle, namcopy)) 01008 return false; 01009 info->saw_filename = true; 01010 01011 /* Discard any variables or types we may have seen before. */ 01012 if (info->vars.vars != NULL) 01013 free (info->vars.vars); 01014 info->vars.vars = NULL; 01015 info->vars.alloc = 0; 01016 if (info->types.types != NULL) 01017 free (info->types.types); 01018 info->types.types = NULL; 01019 info->types.alloc = 0; 01020 01021 /* Initialize the types to the global types. */ 01022 if (info->global_types != NULL) 01023 { 01024 info->types.alloc = info->global_types->alloc; 01025 info->types.types = ((struct ieee_type *) 01026 xmalloc (info->types.alloc 01027 * sizeof (*info->types.types))); 01028 memcpy (info->types.types, info->global_types->types, 01029 info->types.alloc * sizeof (*info->types.types)); 01030 } 01031 01032 break; 01033 01034 case 2: 01035 /* BB2: Global type definitions. The name is supposed to be 01036 empty, but we don't check. */ 01037 if (! debug_set_filename (info->dhandle, "*global*")) 01038 return false; 01039 info->saw_filename = true; 01040 break; 01041 01042 case 3: 01043 /* BB3: High level module block begin. We don't have to do 01044 anything here. The name is supposed to be the same as for 01045 the BB1, but we don't check. */ 01046 break; 01047 01048 case 4: 01049 /* BB4: Global function. */ 01050 { 01051 bfd_vma stackspace, typindx, offset; 01052 debug_type return_type; 01053 01054 if (! ieee_read_number (info, pp, &stackspace) 01055 || ! ieee_read_number (info, pp, &typindx) 01056 || ! ieee_read_expression (info, pp, &offset)) 01057 return false; 01058 01059 /* We have no way to record the stack space. FIXME. */ 01060 01061 if (typindx < 256) 01062 { 01063 return_type = ieee_builtin_type (info, block_start, typindx); 01064 if (return_type == DEBUG_TYPE_NULL) 01065 return false; 01066 } 01067 else 01068 { 01069 typindx -= 256; 01070 if (! ieee_alloc_type (info, typindx, true)) 01071 return false; 01072 fnindx = typindx; 01073 return_type = info->types.types[typindx].type; 01074 if (debug_get_type_kind (info->dhandle, return_type) 01075 == DEBUG_KIND_FUNCTION) 01076 return_type = debug_get_return_type (info->dhandle, 01077 return_type); 01078 } 01079 01080 namcopy = savestring (name, namlen); 01081 if (namcopy == NULL) 01082 return false; 01083 if (! debug_record_function (info->dhandle, namcopy, return_type, 01084 true, offset)) 01085 return false; 01086 } 01087 break; 01088 01089 case 5: 01090 /* BB5: File name for source line numbers. */ 01091 { 01092 unsigned int i; 01093 01094 /* We ignore the date and time. FIXME. */ 01095 for (i = 0; i < 6; i++) 01096 { 01097 bfd_vma ignore; 01098 boolean present; 01099 01100 if (! ieee_read_optional_number (info, pp, &ignore, &present)) 01101 return false; 01102 if (! present) 01103 break; 01104 } 01105 01106 namcopy = savestring (name, namlen); 01107 if (namcopy == NULL) 01108 return false; 01109 if (! debug_start_source (info->dhandle, namcopy)) 01110 return false; 01111 } 01112 break; 01113 01114 case 6: 01115 /* BB6: Local function or block. */ 01116 { 01117 bfd_vma stackspace, typindx, offset; 01118 01119 if (! ieee_read_number (info, pp, &stackspace) 01120 || ! ieee_read_number (info, pp, &typindx) 01121 || ! ieee_read_expression (info, pp, &offset)) 01122 return false; 01123 01124 /* We have no way to record the stack space. FIXME. */ 01125 01126 if (namlen == 0) 01127 { 01128 if (! debug_start_block (info->dhandle, offset)) 01129 return false; 01130 /* Change b to indicate that this is a block 01131 rather than a function. */ 01132 b = 0x86; 01133 } 01134 else 01135 { 01136 /* The MRI C++ compiler will output a fake function named 01137 __XRYCPP to hold C++ debugging information. We skip 01138 that function. This is not crucial, but it makes 01139 converting from IEEE to other debug formats work 01140 better. */ 01141 if (strncmp (name, "__XRYCPP", namlen) == 0) 01142 skip = true; 01143 else 01144 { 01145 debug_type return_type; 01146 01147 if (typindx < 256) 01148 { 01149 return_type = ieee_builtin_type (info, block_start, 01150 typindx); 01151 if (return_type == NULL) 01152 return false; 01153 } 01154 else 01155 { 01156 typindx -= 256; 01157 if (! ieee_alloc_type (info, typindx, true)) 01158 return false; 01159 fnindx = typindx; 01160 return_type = info->types.types[typindx].type; 01161 if (debug_get_type_kind (info->dhandle, return_type) 01162 == DEBUG_KIND_FUNCTION) 01163 return_type = debug_get_return_type (info->dhandle, 01164 return_type); 01165 } 01166 01167 namcopy = savestring (name, namlen); 01168 if (namcopy == NULL) 01169 return false; 01170 if (! debug_record_function (info->dhandle, namcopy, 01171 return_type, false, offset)) 01172 return false; 01173 } 01174 } 01175 } 01176 break; 01177 01178 case 10: 01179 /* BB10: Assembler module scope. In the normal case, we 01180 completely ignore all this information. FIXME. */ 01181 { 01182 const char *inam, *vstr; 01183 unsigned long inamlen, vstrlen; 01184 bfd_vma tool_type; 01185 boolean present; 01186 unsigned int i; 01187 01188 if (! info->saw_filename) 01189 { 01190 namcopy = savestring (name, namlen); 01191 if (namcopy == NULL) 01192 return false; 01193 if (! debug_set_filename (info->dhandle, namcopy)) 01194 return false; 01195 info->saw_filename = true; 01196 } 01197 01198 if (! ieee_read_id (info, pp, &inam, &inamlen) 01199 || ! ieee_read_number (info, pp, &tool_type) 01200 || ! ieee_read_optional_id (info, pp, &vstr, &vstrlen, &present)) 01201 return false; 01202 for (i = 0; i < 6; i++) 01203 { 01204 bfd_vma ignore; 01205 01206 if (! ieee_read_optional_number (info, pp, &ignore, &present)) 01207 return false; 01208 if (! present) 01209 break; 01210 } 01211 } 01212 break; 01213 01214 case 11: 01215 /* BB11: Module section. We completely ignore all this 01216 information. FIXME. */ 01217 { 01218 bfd_vma sectype, secindx, offset, map; 01219 boolean present; 01220 01221 if (! ieee_read_number (info, pp, §ype) 01222 || ! ieee_read_number (info, pp, &secindx) 01223 || ! ieee_read_expression (info, pp, &offset) 01224 || ! ieee_read_optional_number (info, pp, &map, &present)) 01225 return false; 01226 } 01227 break; 01228 01229 default: 01230 ieee_error (info, block_start, "unknown BB type"); 01231 return false; 01232 } 01233 01234 01235 /* Push this block on the block stack. */ 01236 01237 if (info->blockstack.bsp >= info->blockstack.stack + BLOCKSTACK_SIZE) 01238 { 01239 ieee_error (info, (const bfd_byte *) NULL, "stack overflow"); 01240 return false; 01241 } 01242 01243 info->blockstack.bsp->kind = b; 01244 if (b == 5) 01245 info->blockstack.bsp->filename = namcopy; 01246 info->blockstack.bsp->fnindx = fnindx; 01247 info->blockstack.bsp->skip = skip; 01248 ++info->blockstack.bsp; 01249 01250 return true; 01251 } 01252 01253 /* Handle an IEEE BE record. */ 01254 01255 static boolean 01256 parse_ieee_be (info, pp) 01257 struct ieee_info *info; 01258 const bfd_byte **pp; 01259 { 01260 bfd_vma offset; 01261 01262 if (info->blockstack.bsp <= info->blockstack.stack) 01263 { 01264 ieee_error (info, *pp, "stack underflow"); 01265 return false; 01266 } 01267 --info->blockstack.bsp; 01268 01269 switch (info->blockstack.bsp->kind) 01270 { 01271 case 2: 01272 /* When we end the global typedefs block, we copy out the the 01273 contents of info->vars. This is because the variable indices 01274 may be reused in the local blocks. However, we need to 01275 preserve them so that we can locate a function returning a 01276 reference variable whose type is named in the global typedef 01277 block. */ 01278 info->global_vars = ((struct ieee_vars *) 01279 xmalloc (sizeof *info->global_vars)); 01280 info->global_vars->alloc = info->vars.alloc; 01281 info->global_vars->vars = ((struct ieee_var *) 01282 xmalloc (info->vars.alloc 01283 * sizeof (*info->vars.vars))); 01284 memcpy (info->global_vars->vars, info->vars.vars, 01285 info->vars.alloc * sizeof (*info->vars.vars)); 01286 01287 /* We also copy out the non builtin parts of info->types, since 01288 the types are discarded when we start a new block. */ 01289 info->global_types = ((struct ieee_types *) 01290 xmalloc (sizeof *info->global_types)); 01291 info->global_types->alloc = info->types.alloc; 01292 info->global_types->types = ((struct ieee_type *) 01293 xmalloc (info->types.alloc 01294 * sizeof (*info->types.types))); 01295 memcpy (info->global_types->types, info->types.types, 01296 info->types.alloc * sizeof (*info->types.types)); 01297 memset (info->global_types->builtins, 0, 01298 sizeof (info->global_types->builtins)); 01299 01300 break; 01301 01302 case 4: 01303 case 6: 01304 if (! ieee_read_expression (info, pp, &offset)) 01305 return false; 01306 if (! info->blockstack.bsp->skip) 01307 { 01308 if (! debug_end_function (info->dhandle, offset + 1)) 01309 return false; 01310 } 01311 break; 01312 01313 case 0x86: 01314 /* This is BE6 when BB6 started a block rather than a local 01315 function. */ 01316 if (! ieee_read_expression (info, pp, &offset)) 01317 return false; 01318 if (! debug_end_block (info->dhandle, offset + 1)) 01319 return false; 01320 break; 01321 01322 case 5: 01323 /* When we end a BB5, we look up the stack for the last BB5, if 01324 there is one, so that we can call debug_start_source. */ 01325 if (info->blockstack.bsp > info->blockstack.stack) 01326 { 01327 struct ieee_block *bl; 01328 01329 bl = info->blockstack.bsp; 01330 do 01331 { 01332 --bl; 01333 if (bl->kind == 5) 01334 { 01335 if (! debug_start_source (info->dhandle, bl->filename)) 01336 return false; 01337 break; 01338 } 01339 } 01340 while (bl != info->blockstack.stack); 01341 } 01342 break; 01343 01344 case 11: 01345 if (! ieee_read_expression (info, pp, &offset)) 01346 return false; 01347 /* We just ignore the module size. FIXME. */ 01348 break; 01349 01350 default: 01351 /* Other block types do not have any trailing information. */ 01352 break; 01353 } 01354 01355 return true; 01356 } 01357 01358 /* Parse an NN record. */ 01359 01360 static boolean 01361 parse_ieee_nn (info, pp) 01362 struct ieee_info *info; 01363 const bfd_byte **pp; 01364 { 01365 const bfd_byte *nn_start; 01366 bfd_vma varindx; 01367 const char *name; 01368 unsigned long namlen; 01369 01370 nn_start = *pp; 01371 01372 if (! ieee_read_number (info, pp, &varindx) 01373 || ! ieee_read_id (info, pp, &name, &namlen)) 01374 return false; 01375 01376 if (varindx < 32) 01377 { 01378 ieee_error (info, nn_start, "illegal variable index"); 01379 return false; 01380 } 01381 varindx -= 32; 01382 01383 if (varindx >= info->vars.alloc) 01384 { 01385 unsigned int alloc; 01386 01387 alloc = info->vars.alloc; 01388 if (alloc == 0) 01389 alloc = 4; 01390 while (varindx >= alloc) 01391 alloc *= 2; 01392 info->vars.vars = ((struct ieee_var *) 01393 xrealloc (info->vars.vars, 01394 alloc * sizeof *info->vars.vars)); 01395 memset (info->vars.vars + info->vars.alloc, 0, 01396 (alloc - info->vars.alloc) * sizeof *info->vars.vars); 01397 info->vars.alloc = alloc; 01398 } 01399 01400 info->vars.vars[varindx].name = name; 01401 info->vars.vars[varindx].namlen = namlen; 01402 01403 return true; 01404 } 01405 01406 /* Parse a TY record. */ 01407 01408 static boolean 01409 parse_ieee_ty (info, pp) 01410 struct ieee_info *info; 01411 const bfd_byte **pp; 01412 { 01413 const bfd_byte *ty_start, *ty_var_start, *ty_code_start; 01414 bfd_vma typeindx, varindx, tc; 01415 PTR dhandle; 01416 boolean tag, typdef; 01417 debug_type *arg_slots; 01418 unsigned long type_bitsize; 01419 debug_type type; 01420 01421 ty_start = *pp; 01422 01423 if (! ieee_read_number (info, pp, &typeindx)) 01424 return false; 01425 01426 if (typeindx < 256) 01427 { 01428 ieee_error (info, ty_start, "illegal type index"); 01429 return false; 01430 } 01431 01432 typeindx -= 256; 01433 if (! ieee_alloc_type (info, typeindx, false)) 01434 return false; 01435 01436 if (**pp != 0xce) 01437 { 01438 ieee_error (info, *pp, "unknown TY code"); 01439 return false; 01440 } 01441 ++*pp; 01442 01443 ty_var_start = *pp; 01444 01445 if (! ieee_read_number (info, pp, &varindx)) 01446 return false; 01447 01448 if (varindx < 32) 01449 { 01450 ieee_error (info, ty_var_start, "illegal variable index"); 01451 return false; 01452 } 01453 varindx -= 32; 01454 01455 if (varindx >= info->vars.alloc || info->vars.vars[varindx].name == NULL) 01456 { 01457 ieee_error (info, ty_var_start, "undefined variable in TY"); 01458 return false; 01459 } 01460 01461 ty_code_start = *pp; 01462 01463 if (! ieee_read_number (info, pp, &tc)) 01464 return false; 01465 01466 dhandle = info->dhandle; 01467 01468 tag = false; 01469 typdef = false; 01470 arg_slots = NULL; 01471 type_bitsize = 0; 01472 switch (tc) 01473 { 01474 default: 01475 ieee_error (info, ty_code_start, "unknown TY code"); 01476 return false; 01477 01478 case '!': 01479 /* Unknown type, with size. We treat it as int. FIXME. */ 01480 { 01481 bfd_vma size; 01482 01483 if (! ieee_read_number (info, pp, &size)) 01484 return false; 01485 type = debug_make_int_type (dhandle, size, false); 01486 } 01487 break; 01488 01489 case 'A': /* Array. */ 01490 case 'a': /* FORTRAN array in column/row order. FIXME: Not 01491 distinguished from normal array. */ 01492 { 01493 debug_type ele_type; 01494 bfd_vma lower, upper; 01495 01496 if (! ieee_read_type_index (info, pp, &ele_type) 01497 || ! ieee_read_number (info, pp, &lower) 01498 || ! ieee_read_number (info, pp, &upper)) 01499 return false; 01500 type = debug_make_array_type (dhandle, ele_type, 01501 ieee_builtin_type (info, ty_code_start, 01502 ((unsigned int) 01503 builtin_int)), 01504 (bfd_signed_vma) lower, 01505 (bfd_signed_vma) upper, 01506 false); 01507 } 01508 break; 01509 01510 case 'E': 01511 /* Simple enumeration. */ 01512 { 01513 bfd_vma size; 01514 unsigned int alloc; 01515 const char **names; 01516 unsigned int c; 01517 bfd_signed_vma *vals; 01518 unsigned int i; 01519 01520 if (! ieee_read_number (info, pp, &size)) 01521 return false; 01522 /* FIXME: we ignore the enumeration size. */ 01523 01524 alloc = 10; 01525 names = (const char **) xmalloc (alloc * sizeof *names); 01526 memset (names, 0, alloc * sizeof *names); 01527 c = 0; 01528 while (1) 01529 { 01530 const char *name; 01531 unsigned long namlen; 01532 boolean present; 01533 01534 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present)) 01535 return false; 01536 if (! present) 01537 break; 01538 01539 if (c + 1 >= alloc) 01540 { 01541 alloc += 10; 01542 names = ((const char **) 01543 xrealloc (names, alloc * sizeof *names)); 01544 } 01545 01546 names[c] = savestring (name, namlen); 01547 if (names[c] == NULL) 01548 return false; 01549 ++c; 01550 } 01551 01552 names[c] = NULL; 01553 01554 vals = (bfd_signed_vma *) xmalloc (c * sizeof *vals); 01555 for (i = 0; i < c; i++) 01556 vals[i] = i; 01557 01558 type = debug_make_enum_type (dhandle, names, vals); 01559 tag = true; 01560 } 01561 break; 01562 01563 case 'G': 01564 /* Struct with bit fields. */ 01565 { 01566 bfd_vma size; 01567 unsigned int alloc; 01568 debug_field *fields; 01569 unsigned int c; 01570 01571 if (! ieee_read_number (info, pp, &size)) 01572 return false; 01573 01574 alloc = 10; 01575 fields = (debug_field *) xmalloc (alloc * sizeof *fields); 01576 c = 0; 01577 while (1) 01578 { 01579 const char *name; 01580 unsigned long namlen; 01581 boolean present; 01582 debug_type ftype; 01583 bfd_vma bitpos, bitsize; 01584 01585 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present)) 01586 return false; 01587 if (! present) 01588 break; 01589 if (! ieee_read_type_index (info, pp, &ftype) 01590 || ! ieee_read_number (info, pp, &bitpos) 01591 || ! ieee_read_number (info, pp, &bitsize)) 01592 return false; 01593 01594 if (c + 1 >= alloc) 01595 { 01596 alloc += 10; 01597 fields = ((debug_field *) 01598 xrealloc (fields, alloc * sizeof *fields)); 01599 } 01600 01601 fields[c] = debug_make_field (dhandle, savestring (name, namlen), 01602 ftype, bitpos, bitsize, 01603 DEBUG_VISIBILITY_PUBLIC); 01604 if (fields[c] == NULL) 01605 return false; 01606 ++c; 01607 } 01608 01609 fields[c] = NULL; 01610 01611 type = debug_make_struct_type (dhandle, true, size, fields); 01612 tag = true; 01613 } 01614 break; 01615 01616 case 'N': 01617 /* Enumeration. */ 01618 { 01619 unsigned int alloc; 01620 const char **names; 01621 bfd_signed_vma *vals; 01622 unsigned int c; 01623 01624 alloc = 10; 01625 names = (const char **) xmalloc (alloc * sizeof *names); 01626 vals = (bfd_signed_vma *) xmalloc (alloc * sizeof *names); 01627 c = 0; 01628 while (1) 01629 { 01630 const char *name; 01631 unsigned long namlen; 01632 boolean present; 01633 bfd_vma val; 01634 01635 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present)) 01636 return false; 01637 if (! present) 01638 break; 01639 if (! ieee_read_number (info, pp, &val)) 01640 return false; 01641 01642 /* If the length of the name is zero, then the value is 01643 actually the size of the enum. We ignore this 01644 information. FIXME. */ 01645 if (namlen == 0) 01646 continue; 01647 01648 if (c + 1 >= alloc) 01649 { 01650 alloc += 10; 01651 names = ((const char **) 01652 xrealloc (names, alloc * sizeof *names)); 01653 vals = ((bfd_signed_vma *) 01654 xrealloc (vals, alloc * sizeof *vals)); 01655 } 01656 01657 names[c] = savestring (name, namlen); 01658 if (names[c] == NULL) 01659 return false; 01660 vals[c] = (bfd_signed_vma) val; 01661 ++c; 01662 } 01663 01664 names[c] = NULL; 01665 01666 type = debug_make_enum_type (dhandle, names, vals); 01667 tag = true; 01668 } 01669 break; 01670 01671 case 'O': /* Small pointer. We don't distinguish small and large 01672 pointers. FIXME. */ 01673 case 'P': /* Large pointer. */ 01674 { 01675 debug_type t; 01676 01677 if (! ieee_read_type_index (info, pp, &t)) 01678 return false; 01679 type = debug_make_pointer_type (dhandle, t); 01680 } 01681 break; 01682 01683 case 'R': 01684 /* Range. */ 01685 { 01686 bfd_vma low, high, signedp, size; 01687 01688 if (! ieee_read_number (info, pp, &low) 01689 || ! ieee_read_number (info, pp, &high) 01690 || ! ieee_read_number (info, pp, &signedp) 01691 || ! ieee_read_number (info, pp, &size)) 01692 return false; 01693 01694 type = debug_make_range_type (dhandle, 01695 debug_make_int_type (dhandle, size, 01696 ! signedp), 01697 (bfd_signed_vma) low, 01698 (bfd_signed_vma) high); 01699 } 01700 break; 01701 01702 case 'S': /* Struct. */ 01703 case 'U': /* Union. */ 01704 { 01705 bfd_vma size; 01706 unsigned int alloc; 01707 debug_field *fields; 01708 unsigned int c; 01709 01710 if (! ieee_read_number (info, pp, &size)) 01711 return false; 01712 01713 alloc = 10; 01714 fields = (debug_field *) xmalloc (alloc * sizeof *fields); 01715 c = 0; 01716 while (1) 01717 { 01718 const char *name; 01719 unsigned long namlen; 01720 boolean present; 01721 bfd_vma tindx; 01722 bfd_vma offset; 01723 debug_type ftype; 01724 bfd_vma bitsize; 01725 01726 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present)) 01727 return false; 01728 if (! present) 01729 break; 01730 if (! ieee_read_number (info, pp, &tindx) 01731 || ! ieee_read_number (info, pp, &offset)) 01732 return false; 01733 01734 if (tindx < 256) 01735 { 01736 ftype = ieee_builtin_type (info, ty_code_start, tindx); 01737 bitsize = 0; 01738 offset *= 8; 01739 } 01740 else 01741 { 01742 struct ieee_type *t; 01743 01744 tindx -= 256; 01745 if (! ieee_alloc_type (info, tindx, true)) 01746 return false; 01747 t = info->types.types + tindx; 01748 ftype = t->type; 01749 bitsize = t->bitsize; 01750 if (bitsize == 0) 01751 offset *= 8; 01752 } 01753 01754 if (c + 1 >= alloc) 01755 { 01756 alloc += 10; 01757 fields = ((debug_field *) 01758 xrealloc (fields, alloc * sizeof *fields)); 01759 } 01760 01761 fields[c] = debug_make_field (dhandle, savestring (name, namlen), 01762 ftype, offset, bitsize, 01763 DEBUG_VISIBILITY_PUBLIC); 01764 if (fields[c] == NULL) 01765 return false; 01766 ++c; 01767 } 01768 01769 fields[c] = NULL; 01770 01771 type = debug_make_struct_type (dhandle, tc == 'S', size, fields); 01772 tag = true; 01773 } 01774 break; 01775 01776 case 'T': 01777 /* Typedef. */ 01778 if (! ieee_read_type_index (info, pp, &type)) 01779 return false; 01780 typdef = true; 01781 break; 01782 01783 case 'X': 01784 /* Procedure. FIXME: This is an extern declaration, which we 01785 have no way of representing. */ 01786 { 01787 bfd_vma attr; 01788 debug_type rtype; 01789 bfd_vma nargs; 01790 boolean present; 01791 struct ieee_var *pv; 01792 01793 /* FIXME: We ignore the attribute and the argument names. */ 01794 01795 if (! ieee_read_number (info, pp, &attr) 01796 || ! ieee_read_type_index (info, pp, &rtype) 01797 || ! ieee_read_number (info, pp, &nargs)) 01798 return false; 01799 do 01800 { 01801 const char *name; 01802 unsigned long namlen; 01803 01804 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present)) 01805 return false; 01806 } 01807 while (present); 01808 01809 pv = info->vars.vars + varindx; 01810 pv->kind = IEEE_EXTERNAL; 01811 if (pv->namlen > 0 01812 && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER) 01813 { 01814 /* Set up the return type as an indirect type pointing to 01815 the variable slot, so that we can change it to a 01816 reference later if appropriate. */ 01817 pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot); 01818 *pv->pslot = rtype; 01819 rtype = debug_make_indirect_type (dhandle, pv->pslot, 01820 (const char *) NULL); 01821 } 01822 01823 type = debug_make_function_type (dhandle, rtype, (debug_type *) NULL, 01824 false); 01825 } 01826 break; 01827 01828 case 'V': 01829 /* Void. This is not documented, but the MRI compiler emits it. */ 01830 type = debug_make_void_type (dhandle); 01831 break; 01832 01833 case 'Z': 01834 /* Array with 0 lower bound. */ 01835 { 01836 debug_type etype; 01837 bfd_vma high; 01838 01839 if (! ieee_read_type_index (info, pp, &etype) 01840 || ! ieee_read_number (info, pp, &high)) 01841 return false; 01842 01843 type = debug_make_array_type (dhandle, etype, 01844 ieee_builtin_type (info, ty_code_start, 01845 ((unsigned int) 01846 builtin_int)), 01847 0, (bfd_signed_vma) high, false); 01848 } 01849 break; 01850 01851 case 'c': /* Complex. */ 01852 case 'd': /* Double complex. */ 01853 { 01854 const char *name; 01855 unsigned long namlen; 01856 01857 /* FIXME: I don't know what the name means. */ 01858 01859 if (! ieee_read_id (info, pp, &name, &namlen)) 01860 return false; 01861 01862 type = debug_make_complex_type (dhandle, tc == 'c' ? 4 : 8); 01863 } 01864 break; 01865 01866 case 'f': 01867 /* Pascal file name. FIXME. */ 01868 ieee_error (info, ty_code_start, "Pascal file name not supported"); 01869 return false; 01870 01871 case 'g': 01872 /* Bitfield type. */ 01873 { 01874 bfd_vma signedp, bitsize, dummy; 01875 const bfd_byte *hold; 01876 boolean present; 01877 01878 if (! ieee_read_number (info, pp, &signedp) 01879 || ! ieee_read_number (info, pp, &bitsize)) 01880 return false; 01881 01882 /* I think the documentation says that there is a type index, 01883 but some actual files do not have one. */ 01884 hold = *pp; 01885 if (! ieee_read_optional_number (info, pp, &dummy, &present)) 01886 return false; 01887 if (! present) 01888 { 01889 /* FIXME: This is just a guess. */ 01890 type = debug_make_int_type (dhandle, 4, 01891 signedp ? false : true); 01892 } 01893 else 01894 { 01895 *pp = hold; 01896 if (! ieee_read_type_index (info, pp, &type)) 01897 return false; 01898 } 01899 type_bitsize = bitsize; 01900 } 01901 break; 01902 01903 case 'n': 01904 /* Qualifier. */ 01905 { 01906 bfd_vma kind; 01907 debug_type t; 01908 01909 if (! ieee_read_number (info, pp, &kind) 01910 || ! ieee_read_type_index (info, pp, &t)) 01911 return false; 01912 01913 switch (kind) 01914 { 01915 default: 01916 ieee_error (info, ty_start, "unsupported qualifer"); 01917 return false; 01918 01919 case 1: 01920 type = debug_make_const_type (dhandle, t); 01921 break; 01922 01923 case 2: 01924 type = debug_make_volatile_type (dhandle, t); 01925 break; 01926 } 01927 } 01928 break; 01929 01930 case 's': 01931 /* Set. */ 01932 { 01933 bfd_vma size; 01934 debug_type etype; 01935 01936 if (! ieee_read_number (info, pp, &size) 01937 || ! ieee_read_type_index (info, pp, &etype)) 01938 return false; 01939 01940 /* FIXME: We ignore the size. */ 01941 01942 type = debug_make_set_type (dhandle, etype, false); 01943 } 01944 break; 01945 01946 case 'x': 01947 /* Procedure with compiler dependencies. */ 01948 { 01949 struct ieee_var *pv; 01950 bfd_vma attr, frame_type, push_mask, nargs, level, father; 01951 debug_type rtype; 01952 debug_type *arg_types; 01953 boolean varargs; 01954 boolean present; 01955 01956 /* FIXME: We ignore some of this information. */ 01957 01958 pv = info->vars.vars + varindx; 01959 01960 if (! ieee_read_number (info, pp, &attr) 01961 || ! ieee_read_number (info, pp, &frame_type) 01962 || ! ieee_read_number (info, pp, &push_mask) 01963 || ! ieee_read_type_index (info, pp, &rtype) 01964 || ! ieee_read_number (info, pp, &nargs)) 01965 return false; 01966 if (nargs == (bfd_vma) -1) 01967 { 01968 arg_types = NULL; 01969 varargs = false; 01970 } 01971 else 01972 { 01973 unsigned int i; 01974 01975 arg_types = ((debug_type *) 01976 xmalloc ((nargs + 1) * sizeof *arg_types)); 01977 for (i = 0; i < nargs; i++) 01978 if (! ieee_read_type_index (info, pp, arg_types + i)) 01979 return false; 01980 01981 /* If the last type is pointer to void, this is really a 01982 varargs function. */ 01983 varargs = false; 01984 if (nargs > 0) 01985 { 01986 debug_type last; 01987 01988 last = arg_types[nargs - 1]; 01989 if (debug_get_type_kind (dhandle, last) == DEBUG_KIND_POINTER 01990 && (debug_get_type_kind (dhandle, 01991 debug_get_target_type (dhandle, 01992 last)) 01993 == DEBUG_KIND_VOID)) 01994 { 01995 --nargs; 01996 varargs = true; 01997 } 01998 } 01999 02000 /* If there are any pointer arguments, turn them into 02001 indirect types in case we later need to convert them to 02002 reference types. */ 02003 for (i = 0; i < nargs; i++) 02004 { 02005 if (debug_get_type_kind (dhandle, arg_types[i]) 02006 == DEBUG_KIND_POINTER) 02007 { 02008 if (arg_slots == NULL) 02009 { 02010 arg_slots = ((debug_type *) 02011 xmalloc (nargs * sizeof *arg_slots)); 02012 memset (arg_slots, 0, nargs * sizeof *arg_slots); 02013 } 02014 arg_slots[i] = arg_types[i]; 02015 arg_types[i] = 02016 debug_make_indirect_type (dhandle, 02017 arg_slots + i, 02018 (const char *) NULL); 02019 } 02020 } 02021 02022 arg_types[nargs] = DEBUG_TYPE_NULL; 02023 } 02024 if (! ieee_read_number (info, pp, &level) 02025 || ! ieee_read_optional_number (info, pp, &father, &present)) 02026 return false; 02027 02028 /* We can't distinguish between a global function and a static 02029 function. */ 02030 pv->kind = IEEE_FUNCTION; 02031 02032 if (pv->namlen > 0 02033 && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER) 02034 { 02035 /* Set up the return type as an indirect type pointing to 02036 the variable slot, so that we can change it to a 02037 reference later if appropriate. */ 02038 pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot); 02039 *pv->pslot = rtype; 02040 rtype = debug_make_indirect_type (dhandle, pv->pslot, 02041 (const char *) NULL); 02042 } 02043 02044 type = debug_make_function_type (dhandle, rtype, arg_types, varargs); 02045 } 02046 break; 02047 } 02048 02049 /* Record the type in the table. */ 02050 02051 if (type == DEBUG_TYPE_NULL) 02052 return false; 02053 02054 info->vars.vars[varindx].type = type; 02055 02056 if ((tag || typdef) 02057 && info->vars.vars[varindx].namlen > 0) 02058 { 02059 const char *name; 02060 02061 name = savestring (info->vars.vars[varindx].name, 02062 info->vars.vars[varindx].namlen); 02063 if (typdef) 02064 type = debug_name_type (dhandle, name, type); 02065 else if (tc == 'E' || tc == 'N') 02066 type = debug_tag_type (dhandle, name, type); 02067 else 02068 { 02069 struct ieee_tag *it; 02070 02071 /* We must allocate all struct tags as indirect types, so 02072 that if we later see a definition of the tag as a C++ 02073 record we can update the indirect slot and automatically 02074 change all the existing references. */ 02075 it = (struct ieee_tag *) xmalloc (sizeof *it); 02076 memset (it, 0, sizeof *it); 02077 it->next = info->tags; 02078 info->tags = it; 02079 it->name = name; 02080 it->slot = type; 02081 02082 type = debug_make_indirect_type (dhandle, &it->slot, name); 02083 type = debug_tag_type (dhandle, name, type); 02084 02085 it->type = type; 02086 } 02087 if (type == NULL) 02088 return false; 02089 } 02090 02091 info->types.types[typeindx].type = type; 02092 info->types.types[typeindx].arg_slots = arg_slots; 02093 info->types.types[typeindx].bitsize = type_bitsize; 02094 02095 /* We may have already allocated type as an indirect type pointing 02096 to slot. It does no harm to replace the indirect type with the 02097 real type. Filling in slot as well handles the indirect types 02098 which are already hanging around. */ 02099 if (info->types.types[typeindx].pslot != NULL) 02100 *info->types.types[typeindx].pslot = type; 02101 02102 return true; 02103 } 02104 02105 /* Parse an ATN record. */ 02106 02107 static boolean 02108 parse_ieee_atn (info, pp) 02109 struct ieee_info *info; 02110 const bfd_byte **pp; 02111 { 02112 const bfd_byte *atn_start, *atn_code_start; 02113 bfd_vma varindx; 02114 struct ieee_var *pvar; 02115 debug_type type; 02116 bfd_vma atn_code; 02117 PTR dhandle; 02118 bfd_vma v, v2, v3, v4, v5; 02119 const char *name; 02120 unsigned long namlen; 02121 char *namcopy; 02122 boolean present; 02123 int blocktype; 02124 02125 atn_start = *pp; 02126 02127 if (! ieee_read_number (info, pp, &varindx) 02128 || ! ieee_read_type_index (info, pp, &type)) 02129 return false; 02130 02131 atn_code_start = *pp; 02132 02133 if (! ieee_read_number (info, pp, &atn_code)) 02134 return false; 02135 02136 if (varindx == 0) 02137 { 02138 pvar = NULL; 02139 name = ""; 02140 namlen = 0; 02141 } 02142 else if (varindx < 32) 02143 { 02144 ieee_error (info, atn_start, "illegal variable index"); 02145 return false; 02146 } 02147 else 02148 { 02149 varindx -= 32; 02150 if (varindx >= info->vars.alloc 02151 || info->vars.vars[varindx].name == NULL) 02152 { 02153 /* The MRI compiler or linker sometimes omits the NN record 02154 for a pmisc record. */ 02155 if (atn_code == 62) 02156 { 02157 if (varindx >= info->vars.alloc) 02158 { 02159 unsigned int alloc; 02160 02161 alloc = info->vars.alloc; 02162 if (alloc == 0) 02163 alloc = 4; 02164 while (varindx >= alloc) 02165 alloc *= 2; 02166 info->vars.vars = ((struct ieee_var *) 02167 xrealloc (info->vars.vars, 02168 (alloc 02169 * sizeof *info->vars.vars))); 02170 memset (info->vars.vars + info->vars.alloc, 0, 02171 ((alloc - info->vars.alloc) 02172 * sizeof *info->vars.vars)); 02173 info->vars.alloc = alloc; 02174 } 02175 02176 pvar = info->vars.vars + varindx; 02177 pvar->name = ""; 02178 pvar->namlen = 0; 02179 } 02180 else 02181 { 02182 ieee_error (info, atn_start, "undefined variable in ATN"); 02183 return false; 02184 } 02185 } 02186 02187 pvar = info->vars.vars + varindx; 02188 02189 pvar->type = type; 02190 02191 name = pvar->name; 02192 namlen = pvar->namlen; 02193 } 02194 02195 dhandle = info->dhandle; 02196 02197 /* If we are going to call debug_record_variable with a pointer 02198 type, change the type to an indirect type so that we can later 02199 change it to a reference type if we encounter a C++ pmisc 'R' 02200 record. */ 02201 if (pvar != NULL 02202 && type != DEBUG_TYPE_NULL 02203 && debug_get_type_kind (dhandle, type) == DEBUG_KIND_POINTER) 02204 { 02205 switch (atn_code) 02206 { 02207 case 1: 02208 case 2: 02209 case 3: 02210 case 5: 02211 case 8: 02212 case 10: 02213 pvar->pslot = (debug_type *) xmalloc (sizeof *pvar->pslot); 02214 *pvar->pslot = type; 02215 type = debug_make_indirect_type (dhandle, pvar->pslot, 02216 (const char *) NULL); 02217 pvar->type = type; 02218 break; 02219 } 02220 } 02221 02222 switch (atn_code) 02223 { 02224 default: 02225 ieee_error (info, atn_code_start, "unknown ATN type"); 02226 return false; 02227 02228 case 1: 02229 /* Automatic variable. */ 02230 if (! ieee_read_number (info, pp, &v)) 02231 return false; 02232 namcopy = savestring (name, namlen); 02233 if (type == NULL) 02234 type = debug_make_void_type (dhandle); 02235 if (pvar != NULL) 02236 pvar->kind = IEEE_LOCAL; 02237 return debug_record_variable (dhandle, namcopy, type, DEBUG_LOCAL, v); 02238 02239 case 2: 02240 /* Register variable. */ 02241 if (! ieee_read_number (info, pp, &v)) 02242 return false; 02243 namcopy = savestring (name, namlen); 02244 if (type == NULL) 02245 type = debug_make_void_type (dhandle); 02246 if (pvar != NULL) 02247 pvar->kind = IEEE_LOCAL; 02248 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER, 02249 ieee_regno_to_genreg (info->abfd, v)); 02250 02251 case 3: 02252 /* Static variable. */ 02253 if (! ieee_require_asn (info, pp, &v)) 02254 return false; 02255 namcopy = savestring (name, namlen); 02256 if (type == NULL) 02257 type = debug_make_void_type (dhandle); 02258 if (info->blockstack.bsp <= info->blockstack.stack) 02259 blocktype = 0; 02260 else 02261 blocktype = info->blockstack.bsp[-1].kind; 02262 if (pvar != NULL) 02263 { 02264 if (blocktype == 4 || blocktype == 6) 02265 pvar->kind = IEEE_LOCAL; 02266 else 02267 pvar->kind = IEEE_STATIC; 02268 } 02269 return debug_record_variable (dhandle, namcopy, type, 02270 (blocktype == 4 || blocktype == 6 02271 ? DEBUG_LOCAL_STATIC 02272 : DEBUG_STATIC), 02273 v); 02274 02275 case 4: 02276 /* External function. We don't currently record these. FIXME. */ 02277 if (pvar != NULL) 02278 pvar->kind = IEEE_EXTERNAL; 02279 return true; 02280 02281 case 5: 02282 /* External variable. We don't currently record these. FIXME. */ 02283 if (pvar != NULL) 02284 pvar->kind = IEEE_EXTERNAL; 02285 return true; 02286 02287 case 7: 02288 if (! ieee_read_number (info, pp, &v) 02289 || ! ieee_read_number (info, pp, &v2) 02290 || ! ieee_read_optional_number (info, pp, &v3, &present)) 02291 return false; 02292 if (present) 02293 { 02294 if (! ieee_read_optional_number (info, pp, &v4, &present)) 02295 return false; 02296 } 02297 02298 /* We just ignore the two optional fields in v3 and v4, since 02299 they are not defined. */ 02300 02301 if (! ieee_require_asn (info, pp, &v3)) 02302 return false; 02303 02304 /* We have no way to record the column number. FIXME. */ 02305 02306 return debug_record_line (dhandle, v, v3); 02307 02308 case 8: 02309 /* Global variable. */ 02310 if (! ieee_require_asn (info, pp, &v)) 02311 return false; 02312 namcopy = savestring (name, namlen); 02313 if (type == NULL) 02314 type = debug_make_void_type (dhandle); 02315 if (pvar != NULL) 02316 pvar->kind = IEEE_GLOBAL; 02317 return debug_record_variable (dhandle, namcopy, type, DEBUG_GLOBAL, v); 02318 02319 case 9: 02320 /* Variable lifetime information. */ 02321 if (! ieee_read_number (info, pp, &v)) 02322 return false; 02323 02324 /* We have no way to record this information. FIXME. */ 02325 return true; 02326 02327 case 10: 02328 /* Locked register. The spec says that there are two required 02329 fields, but at least on occasion the MRI compiler only emits 02330 one. */ 02331 if (! ieee_read_number (info, pp, &v) 02332 || ! ieee_read_optional_number (info, pp, &v2, &present)) 02333 return false; 02334 02335 /* I think this means a variable that is both in a register and 02336 a frame slot. We ignore the frame slot. FIXME. */ 02337 02338 namcopy = savestring (name, namlen); 02339 if (type == NULL) 02340 type = debug_make_void_type (dhandle); 02341 if (pvar != NULL) 02342 pvar->kind = IEEE_LOCAL; 02343 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER, v); 02344 02345 case 11: 02346 /* Reserved for FORTRAN common. */ 02347 ieee_error (info, atn_code_start, "unsupported ATN11"); 02348 02349 /* Return true to keep going. */ 02350 return true; 02351 02352 case 12: 02353 /* Based variable. */ 02354 v3 = 0; 02355 v4 = 0x80; 02356 v5 = 0; 02357 if (! ieee_read_number (info, pp, &v) 02358 || ! ieee_read_number (info, pp, &v2) 02359 || ! ieee_read_optional_number (info, pp, &v3, &present)) 02360 return false; 02361 if (present) 02362 { 02363 if (! ieee_read_optional_number (info, pp, &v4, &present)) 02364 return false; 02365 if (present) 02366 { 02367 if (! ieee_read_optional_number (info, pp, &v5, &present)) 02368 return false; 02369 } 02370 } 02371 02372 /* We have no way to record this information. FIXME. */ 02373 02374 ieee_error (info, atn_code_start, "unsupported ATN12"); 02375 02376 /* Return true to keep going. */ 02377 return true; 02378 02379 case 16: 02380 /* Constant. The description of this that I have is ambiguous, 02381 so I'm not going to try to implement it. */ 02382 if (! ieee_read_number (info, pp, &v) 02383 || ! ieee_read_optional_number (info, pp, &v2, &present)) 02384 return false; 02385 if (present) 02386 { 02387 if (! ieee_read_optional_number (info, pp, &v2, &present)) 02388 return false; 02389 if (present) 02390 { 02391 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present)) 02392 return false; 02393 } 02394 } 02395 02396 if ((ieee_record_enum_type) **pp == ieee_e2_first_byte_enum) 02397 { 02398 if (! ieee_require_asn (info, pp, &v3)) 02399 return false; 02400 } 02401 02402 return true; 02403 02404 case 19: 02405 /* Static variable from assembler. */ 02406 v2 = 0; 02407 if (! ieee_read_number (info, pp, &v) 02408 || ! ieee_read_optional_number (info, pp, &v2, &present) 02409 || ! ieee_require_asn (info, pp, &v3)) 02410 return false; 02411 namcopy = savestring (name, namlen); 02412 /* We don't really handle this correctly. FIXME. */ 02413 return debug_record_variable (dhandle, namcopy, 02414 debug_make_void_type (dhandle), 02415 v2 != 0 ? DEBUG_GLOBAL : DEBUG_STATIC, 02416 v3); 02417 02418 case 62: 02419 /* Procedure miscellaneous information. */ 02420 case 63: 02421 /* Variable miscellaneous information. */ 02422 case 64: 02423 /* Module miscellaneous information. */ 02424 if (! ieee_read_number (info, pp, &v) 02425 || ! ieee_read_number (info, pp, &v2) 02426 || ! ieee_read_optional_id (info, pp, &name, &namlen, &present)) 02427 return false; 02428 02429 if (atn_code == 62 && v == 80) 02430 { 02431 if (present) 02432 { 02433 ieee_error (info, atn_code_start, 02434 "unexpected string in C++ misc"); 02435 return false; 02436 } 02437 return ieee_read_cxx_misc (info, pp, v2); 02438 } 02439 02440 /* We just ignore all of this stuff. FIXME. */ 02441 02442 for (; v2 > 0; --v2) 02443 { 02444 switch ((ieee_record_enum_type) **pp) 02445 { 02446 default: 02447 ieee_error (info, *pp, "bad misc record"); 02448 return false; 02449 02450 case ieee_at_record_enum: 02451 if (! ieee_require_atn65 (info, pp, &name, &namlen)) 02452 return false; 02453 break; 02454 02455 case ieee_e2_first_byte_enum: 02456 if (! ieee_require_asn (info, pp, &v3)) 02457 return false; 02458 break; 02459 } 02460 } 02461 02462 return true; 02463 } 02464 02465 /*NOTREACHED*/ 02466 } 02467 02468 /* Handle C++ debugging miscellaneous records. This is called for 02469 procedure miscellaneous records of type 80. */ 02470 02471 static boolean 02472 ieee_read_cxx_misc (info, pp, count) 02473 struct ieee_info *info; 02474 const bfd_byte **pp; 02475 unsigned long count; 02476 { 02477 const bfd_byte *start; 02478 bfd_vma category; 02479 02480 start = *pp; 02481 02482 /* Get the category of C++ misc record. */ 02483 if (! ieee_require_asn (info, pp, &category)) 02484 return false; 02485 --count; 02486 02487 switch (category) 02488 { 02489 default: 02490 ieee_error (info, start, "unrecognized C++ misc record"); 02491 return false; 02492 02493 case 'T': 02494 if (! ieee_read_cxx_class (info, pp, count)) 02495 return false; 02496 break; 02497 02498 case 'M': 02499 { 02500 bfd_vma flags; 02501 const char *name; 02502 unsigned long namlen; 02503 02504 /* The IEEE spec indicates that the 'M' record only has a 02505 flags field. The MRI compiler also emits the name of the 02506 function. */ 02507 02508 if (! ieee_require_asn (info, pp, &flags)) 02509 return false; 02510 if (*pp < info->pend 02511 && (ieee_record_enum_type) **pp == ieee_at_record_enum) 02512 { 02513 if (! ieee_require_atn65 (info, pp, &name, &namlen)) 02514 return false; 02515 } 02516 02517 /* This is emitted for method functions, but I don't think we 02518 care very much. It might help if it told us useful 02519 information like the class with which this function is 02520 associated, but it doesn't, so it isn't helpful. */ 02521 } 02522 break; 02523 02524 case 'B': 02525 if (! ieee_read_cxx_defaults (info, pp, count)) 02526 return false; 02527 break; 02528 02529 case 'z': 02530 { 02531 const char *name, *mangled, *class; 02532 unsigned long namlen, mangledlen, classlen; 02533 bfd_vma control; 02534 02535 /* Pointer to member. */ 02536 02537 if (! ieee_require_atn65 (info, pp, &name, &namlen) 02538 || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen) 02539 || ! ieee_require_atn65 (info, pp, &class, &classlen) 02540 || ! ieee_require_asn (info, pp, &control)) 02541 return false; 02542 02543 /* FIXME: We should now track down name and change its type. */ 02544 } 02545 break; 02546 02547 case 'R': 02548 if (! ieee_read_reference (info, pp)) 02549 return false; 02550 break; 02551 } 02552 02553 return true; 02554 } 02555 02556 /* Read a C++ class definition. This is a pmisc type 80 record of 02557 category 'T'. */ 02558 02559 static boolean 02560 ieee_read_cxx_class (info, pp, count) 02561 struct ieee_info *info; 02562 const bfd_byte **pp; 02563 unsigned long count; 02564 { 02565 const bfd_byte *start; 02566 bfd_vma class; 02567 const char *tag; 02568 unsigned long taglen; 02569 struct ieee_tag *it; 02570 PTR dhandle; 02571 debug_field *fields; 02572 unsigned int field_count, field_alloc; 02573 debug_baseclass *baseclasses; 02574 unsigned int baseclasses_count, baseclasses_alloc; 02575 const debug_field *structfields; 02576 struct ieee_method 02577 { 02578 const char *name; 02579 unsigned long namlen; 02580 debug_method_variant *variants; 02581 unsigned count; 02582 unsigned int alloc; 02583 } *methods; 02584 unsigned int methods_count, methods_alloc; 02585 debug_type vptrbase; 02586 boolean ownvptr; 02587 debug_method *dmethods; 02588 02589 start = *pp; 02590 02591 if (! ieee_require_asn (info, pp, &class)) 02592 return false; 02593 --count; 02594 02595 if (! ieee_require_atn65 (info, pp, &tag, &taglen)) 02596 return false; 02597 --count; 02598 02599 /* Find the C struct with this name. */ 02600 for (it = info->tags; it != NULL; it = it->next) 02601 if (it->name[0] == tag[0] 02602 && strncmp (it->name, tag, taglen) == 0 02603 && strlen (it->name) == taglen) 02604 break; 02605 if (it == NULL) 02606 { 02607 ieee_error (info, start, "undefined C++ object"); 02608 return false; 02609 } 02610 02611 dhandle = info->dhandle; 02612 02613 fields = NULL; 02614 field_count = 0; 02615 field_alloc = 0; 02616 baseclasses = NULL; 02617 baseclasses_count = 0; 02618 baseclasses_alloc = 0; 02619 methods = NULL; 02620 methods_count = 0; 02621 methods_alloc = 0; 02622 vptrbase = DEBUG_TYPE_NULL; 02623 ownvptr = false; 02624 02625 structfields = debug_get_fields (dhandle, it->type); 02626 02627 while (count > 0) 02628 { 02629 bfd_vma id; 02630 const bfd_byte *spec_start; 02631 02632 spec_start = *pp; 02633 02634 if (! ieee_require_asn (info, pp, &id)) 02635 return false; 02636 --count; 02637 02638 switch (id) 02639 { 02640 default: 02641 ieee_error (info, spec_start, "unrecognized C++ object spec"); 02642 return false; 02643 02644 case 'b': 02645 { 02646 bfd_vma flags, cinline; 02647 const char *basename, *fieldname; 02648 unsigned long baselen, fieldlen; 02649 char *basecopy; 02650 debug_type basetype; 02651 bfd_vma bitpos; 02652 boolean virtualp; 02653 enum debug_visibility visibility; 02654 debug_baseclass baseclass; 02655 02656 /* This represents a base or friend class. */ 02657 02658 if (! ieee_require_asn (info, pp, &flags) 02659 || ! ieee_require_atn65 (info, pp, &basename, &baselen) 02660 || ! ieee_require_asn (info, pp, &cinline) 02661 || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen)) 02662 return false; 02663 count -= 4; 02664 02665 /* We have no way of recording friend information, so we 02666 just ignore it. */ 02667 if ((flags & BASEFLAGS_FRIEND) != 0) 02668 break; 02669 02670 /* I assume that either all of the members of the 02671 baseclass are included in the object, starting at the 02672 beginning of the object, or that none of them are 02673 included. */ 02674 02675 if ((fieldlen == 0) == (cinline == 0)) 02676 { 02677 ieee_error (info, start, "unsupported C++ object type"); 02678 return false; 02679 } 02680 02681 basecopy = savestring (basename, baselen); 02682 basetype = debug_find_tagged_type (dhandle, basecopy, 02683 DEBUG_KIND_ILLEGAL); 02684 free (basecopy); 02685 if (basetype == DEBUG_TYPE_NULL) 02686 { 02687 ieee_error (info, start, "C++ base class not defined"); 02688 return false; 02689 } 02690 02691 if (fieldlen == 0) 02692 bitpos = 0; 02693 else 02694 { 02695 const debug_field *pf; 02696 02697 if (structfields == NULL) 02698 { 02699 ieee_error (info, start, "C++ object has no fields"); 02700 return false; 02701 } 02702 02703 for (pf = structfields; *pf != DEBUG_FIELD_NULL; pf++) 02704 { 02705 const char *fname; 02706 02707 fname = debug_get_field_name (dhandle, *pf); 02708 if (fname == NULL) 02709 return false; 02710 if (fname[0] == fieldname[0] 02711 && strncmp (fname, fieldname, fieldlen) == 0 02712 && strlen (fname) == fieldlen) 02713 break; 02714 } 02715 if (*pf == DEBUG_FIELD_NULL) 02716 { 02717 ieee_error (info, start, 02718 "C++ base class not found in container"); 02719 return false; 02720 } 02721 02722 bitpos = debug_get_field_bitpos (dhandle, *pf); 02723 } 02724 02725 if ((flags & BASEFLAGS_VIRTUAL) != 0) 02726 virtualp = true; 02727 else 02728 virtualp = false; 02729 if ((flags & BASEFLAGS_PRIVATE) != 0) 02730 visibility = DEBUG_VISIBILITY_PRIVATE; 02731 else 02732 visibility = DEBUG_VISIBILITY_PUBLIC; 02733 02734 baseclass = debug_make_baseclass (dhandle, basetype, bitpos, 02735 virtualp, visibility); 02736 if (baseclass == DEBUG_BASECLASS_NULL) 02737 return false; 02738 02739 if (baseclasses_count + 1 >= baseclasses_alloc) 02740 { 02741 baseclasses_alloc += 10; 02742 baseclasses = ((debug_baseclass *) 02743 xrealloc (baseclasses, 02744 (baseclasses_alloc 02745 * sizeof *baseclasses))); 02746 } 02747 02748 baseclasses[baseclasses_count] = baseclass; 02749 ++baseclasses_count; 02750 baseclasses[baseclasses_count] = DEBUG_BASECLASS_NULL; 02751 } 02752 break; 02753 02754 case 'd': 02755 { 02756 bfd_vma flags; 02757 const char *fieldname, *mangledname; 02758 unsigned long fieldlen, mangledlen; 02759 char *fieldcopy; 02760 boolean staticp; 02761 debug_type ftype; 02762 const debug_field *pf = NULL; 02763 enum debug_visibility visibility; 02764 debug_field field; 02765 02766 /* This represents a data member. */ 02767 02768 if (! ieee_require_asn (info, pp, &flags) 02769 || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen) 02770 || ! ieee_require_atn65 (info, pp, &mangledname, &mangledlen)) 02771 return false; 02772 count -= 3; 02773 02774 fieldcopy = savestring (fieldname, fieldlen); 02775 02776 staticp = (flags & CXXFLAGS_STATIC) != 0 ? true : false; 02777 02778 if (staticp) 02779 { 02780 struct ieee_var *pv, *pvend; 02781 02782 /* See if we can find a definition for this variable. */ 02783 pv = info->vars.vars; 02784 pvend = pv + info->vars.alloc; 02785 for (; pv < pvend; pv++) 02786 if (pv->namlen == mangledlen 02787 && strncmp (pv->name, mangledname, mangledlen) == 0) 02788 break; 02789 if (pv < pvend) 02790 ftype = pv->type; 02791 else 02792 { 02793 /* This can happen if the variable is never used. */ 02794 ftype = ieee_builtin_type (info, start, 02795 (unsigned int) builtin_void); 02796 } 02797 } 02798 else 02799 { 02800 unsigned int findx; 02801 02802 if (structfields == NULL) 02803 { 02804 ieee_error (info, start, "C++ object has no fields"); 02805 return false; 02806 } 02807 02808 for (pf = structfields, findx = 0; 02809 *pf != DEBUG_FIELD_NULL; 02810 pf++, findx++) 02811 { 02812 const char *fname; 02813 02814 fname = debug_get_field_name (dhandle, *pf); 02815 if (fname == NULL) 02816 return false; 02817 if (fname[0] == mangledname[0] 02818 && strncmp (fname, mangledname, mangledlen) == 0 02819 && strlen (fname) == mangledlen) 02820 break; 02821 } 02822 if (*pf == DEBUG_FIELD_NULL) 02823 { 02824 ieee_error (info, start, 02825 "C++ data member not found in container"); 02826 return false; 02827 } 02828 02829 ftype = debug_get_field_type (dhandle, *pf); 02830 02831 if (debug_get_type_kind (dhandle, ftype) == DEBUG_KIND_POINTER) 02832 { 02833 /* We might need to convert this field into a 02834 reference type later on, so make it an indirect 02835 type. */ 02836 if (it->fslots == NULL) 02837 { 02838 unsigned int fcnt; 02839 const debug_field *pfcnt; 02840 02841 fcnt = 0; 02842 for (pfcnt = structfields; 02843 *pfcnt != DEBUG_FIELD_NULL; 02844 pfcnt++) 02845 ++fcnt; 02846 it->fslots = ((debug_type *) 02847 xmalloc (fcnt * sizeof *it->fslots)); 02848 memset (it->fslots, 0, 02849 fcnt * sizeof *it->fslots); 02850 } 02851 02852 if (ftype == DEBUG_TYPE_NULL) 02853 return false; 02854 it->fslots[findx] = ftype; 02855 ftype = debug_make_indirect_type (dhandle, 02856 it->fslots + findx, 02857 (const char *) NULL); 02858 } 02859 } 02860 if (ftype == DEBUG_TYPE_NULL) 02861 return false; 02862 02863 switch (flags & CXXFLAGS_VISIBILITY) 02864 { 02865 default: 02866 ieee_error (info, start, "unknown C++ visibility"); 02867 return false; 02868 02869 case CXXFLAGS_VISIBILITY_PUBLIC: 02870 visibility = DEBUG_VISIBILITY_PUBLIC; 02871 break; 02872 02873 case CXXFLAGS_VISIBILITY_PRIVATE: 02874 visibility = DEBUG_VISIBILITY_PRIVATE; 02875 break; 02876 02877 case CXXFLAGS_VISIBILITY_PROTECTED: 02878 visibility = DEBUG_VISIBILITY_PROTECTED; 02879 break; 02880 } 02881 02882 if (staticp) 02883 { 02884 char *mangledcopy; 02885 02886 mangledcopy = savestring (mangledname, mangledlen); 02887 02888 field = debug_make_static_member (dhandle, fieldcopy, 02889 ftype, mangledcopy, 02890 visibility); 02891 } 02892 else 02893 { 02894 bfd_vma bitpos, bitsize; 02895 02896 bitpos = debug_get_field_bitpos (dhandle, *pf); 02897 bitsize = debug_get_field_bitsize (dhandle, *pf); 02898 if (bitpos == (bfd_vma) -1 || bitsize == (bfd_vma) -1) 02899 { 02900 ieee_error (info, start, "bad C++ field bit pos or size"); 02901 return false; 02902 } 02903 field = debug_make_field (dhandle, fieldcopy, ftype, bitpos, 02904 bitsize, visibility); 02905 } 02906 02907 if (field == DEBUG_FIELD_NULL) 02908 return false; 02909 02910 if (field_count + 1 >= field_alloc) 02911 { 02912 field_alloc += 10; 02913 fields = ((debug_field *) 02914 xrealloc (fields, field_alloc * sizeof *fields)); 02915 } 02916 02917 fields[field_count] = field; 02918 ++field_count; 02919 fields[field_count] = DEBUG_FIELD_NULL; 02920 } 02921 break; 02922 02923 case 'm': 02924 case 'v': 02925 { 02926 bfd_vma flags, voffset, control; 02927 const char *name, *mangled; 02928 unsigned long namlen, mangledlen; 02929 struct ieee_var *pv, *pvend; 02930 debug_type type; 02931 enum debug_visibility visibility; 02932 boolean constp, volatilep; 02933 char *mangledcopy; 02934 debug_method_variant mv; 02935 struct ieee_method *meth; 02936 unsigned int im; 02937 02938 if (! ieee_require_asn (info, pp, &flags) 02939 || ! ieee_require_atn65 (info, pp, &name, &namlen) 02940 || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen)) 02941 return false; 02942 count -= 3; 02943 if (id != 'v') 02944 voffset = 0; 02945 else 02946 { 02947 if (! ieee_require_asn (info, pp, &voffset)) 02948 return false; 02949 --count; 02950 } 02951 if (! ieee_require_asn (info, pp, &control)) 02952 return false; 02953 --count; 02954 02955 /* We just ignore the control information. */ 02956 02957 /* We have no way to represent friend information, so we 02958 just ignore it. */ 02959 if ((flags & CXXFLAGS_FRIEND) != 0) 02960 break; 02961 02962 /* We should already have seen a type for the function. */ 02963 pv = info->vars.vars; 02964 pvend = pv + info->vars.alloc; 02965 for (; pv < pvend; pv++) 02966 if (pv->namlen == mangledlen 02967 && strncmp (pv->name, mangled, mangledlen) == 0) 02968 break; 02969 02970 if (pv >= pvend) 02971 { 02972 /* We won't have type information for this function if 02973 it is not included in this file. We don't try to 02974 handle this case. FIXME. */ 02975 type = (debug_make_function_type 02976 (dhandle, 02977 ieee_builtin_type (info, start, 02978 (unsigned int) builtin_void), 02979 (debug_type *) NULL, 02980 false)); 02981 } 02982 else 02983 { 02984 debug_type return_type; 02985 const debug_type *arg_types; 02986 boolean varargs; 02987 02988 if (debug_get_type_kind (dhandle, pv->type) 02989 != DEBUG_KIND_FUNCTION) 02990 { 02991 ieee_error (info, start, 02992 "bad type for C++ method function"); 02993 return false; 02994 } 02995 02996 return_type = debug_get_return_type (dhandle, pv->type); 02997 arg_types = debug_get_parameter_types (dhandle, pv->type, 02998 &varargs); 02999 if (return_type == DEBUG_TYPE_NULL || arg_types == NULL) 03000 { 03001 ieee_error (info, start, 03002 "no type information for C++ method function"); 03003 return false; 03004 } 03005 03006 type = debug_make_method_type (dhandle, return_type, it->type, 03007 (debug_type *) arg_types, 03008 varargs); 03009 } 03010 if (type == DEBUG_TYPE_NULL) 03011 return false; 03012 03013 switch (flags & CXXFLAGS_VISIBILITY) 03014 { 03015 default: 03016 ieee_error (info, start, "unknown C++ visibility"); 03017 return false; 03018 03019 case CXXFLAGS_VISIBILITY_PUBLIC: 03020 visibility = DEBUG_VISIBILITY_PUBLIC; 03021 break; 03022 03023 case CXXFLAGS_VISIBILITY_PRIVATE: 03024 visibility = DEBUG_VISIBILITY_PRIVATE; 03025 break; 03026 03027 case CXXFLAGS_VISIBILITY_PROTECTED: 03028 visibility = DEBUG_VISIBILITY_PROTECTED; 03029 break; 03030 } 03031 03032 constp = (flags & CXXFLAGS_CONST) != 0 ? true : false; 03033 volatilep = (flags & CXXFLAGS_VOLATILE) != 0 ? true : false; 03034 03035 mangledcopy = savestring (mangled, mangledlen); 03036 03037 if ((flags & CXXFLAGS_STATIC) != 0) 03038 { 03039 if (id == 'v') 03040 { 03041 ieee_error (info, start, "C++ static virtual method"); 03042 return false; 03043 } 03044 mv = debug_make_static_method_variant (dhandle, mangledcopy, 03045 type, visibility, 03046 constp, volatilep); 03047 } 03048 else 03049 { 03050 debug_type vcontext; 03051 03052 if (id != 'v') 03053 vcontext = DEBUG_TYPE_NULL; 03054 else 03055 { 03056 /* FIXME: How can we calculate this correctly? */ 03057 vcontext = it->type; 03058 } 03059 mv = debug_make_method_variant (dhandle, mangledcopy, type, 03060 visibility, constp, 03061 volatilep, voffset, 03062 vcontext); 03063 } 03064 if (mv == DEBUG_METHOD_VARIANT_NULL) 03065 return false; 03066 03067 for (meth = methods, im = 0; im < methods_count; meth++, im++) 03068 if (meth->namlen == namlen 03069 && strncmp (meth->name, name, namlen) == 0) 03070 break; 03071 if (im >= methods_count) 03072 { 03073 if (methods_count >= methods_alloc) 03074 { 03075 methods_alloc += 10; 03076 methods = ((struct ieee_method *) 03077 xrealloc (methods, 03078 methods_alloc * sizeof *methods)); 03079 } 03080 methods[methods_count].name = name; 03081 methods[methods_count].namlen = namlen; 03082 methods[methods_count].variants = NULL; 03083 methods[methods_count].count = 0; 03084 methods[methods_count].alloc = 0; 03085 meth = methods + methods_count; 03086 ++methods_count; 03087 } 03088 03089 if (meth->count + 1 >= meth->alloc) 03090 { 03091 meth->alloc += 10; 03092 meth->variants = ((debug_method_variant *) 03093 xrealloc (meth->variants, 03094 (meth->alloc 03095 * sizeof *meth->variants))); 03096 } 03097 03098 meth->variants[meth->count] = mv; 03099 ++meth->count; 03100 meth->variants[meth->count] = DEBUG_METHOD_VARIANT_NULL; 03101 } 03102 break; 03103 03104 case 'o': 03105 { 03106 bfd_vma spec; 03107 03108 /* We have no way to store this information, so we just 03109 ignore it. */ 03110 if (! ieee_require_asn (info, pp, &spec)) 03111 return false; 03112 --count; 03113 if ((spec & 4) != 0) 03114 { 03115 const char *filename; 03116 unsigned long filenamlen; 03117 bfd_vma lineno; 03118 03119 if (! ieee_require_atn65 (info, pp, &filename, &filenamlen) 03120 || ! ieee_require_asn (info, pp, &lineno)) 03121 return false; 03122 count -= 2; 03123 } 03124 else if ((spec & 8) != 0) 03125 { 03126 const char *mangled; 03127 unsigned long mangledlen; 03128 03129 if (! ieee_require_atn65 (info, pp, &mangled, &mangledlen)) 03130 return false; 03131 --count; 03132 } 03133 else 03134 { 03135 ieee_error (info, start, 03136 "unrecognized C++ object overhead spec"); 03137 return false; 03138 } 03139 } 03140 break; 03141 03142 case 'z': 03143 { 03144 const char *vname, *basename; 03145 unsigned long vnamelen, baselen; 03146 bfd_vma vsize, control; 03147 03148 /* A virtual table pointer. */ 03149 03150 if (! ieee_require_atn65 (info, pp, &vname, &vnamelen) 03151 || ! ieee_require_asn (info, pp, &vsize) 03152 || ! ieee_require_atn65 (info, pp, &basename, &baselen) 03153 || ! ieee_require_asn (info, pp, &control)) 03154 return false; 03155 count -= 4; 03156 03157 /* We just ignore the control number. We don't care what 03158 the virtual table name is. We have no way to store the 03159 virtual table size, and I don't think we care anyhow. */ 03160 03161 /* FIXME: We can't handle multiple virtual table pointers. */ 03162 03163 if (baselen == 0) 03164 ownvptr = true; 03165 else 03166 { 03167 char *basecopy; 03168 03169 basecopy = savestring (basename, baselen); 03170 vptrbase = debug_find_tagged_type (dhandle, basecopy, 03171 DEBUG_KIND_ILLEGAL); 03172 free (basecopy); 03173 if (vptrbase == DEBUG_TYPE_NULL) 03174 { 03175 ieee_error (info, start, "undefined C++ vtable"); 03176 return false; 03177 } 03178 } 03179 } 03180 break; 03181 } 03182 } 03183 03184 /* Now that we have seen all the method variants, we can call 03185 debug_make_method for each one. */ 03186 03187 if (methods_count == 0) 03188 dmethods = NULL; 03189 else 03190 { 03191 unsigned int i; 03192 03193 dmethods = ((debug_method *) 03194 xmalloc ((methods_count + 1) * sizeof *dmethods)); 03195 for (i = 0; i < methods_count; i++) 03196 { 03197 char *namcopy; 03198 03199 namcopy = savestring (methods[i].name, methods[i].namlen); 03200 dmethods[i] = debug_make_method (dhandle, namcopy, 03201 methods[i].variants); 03202 if (dmethods[i] == DEBUG_METHOD_NULL) 03203 return false; 03204 } 03205 dmethods[i] = DEBUG_METHOD_NULL; 03206 free (methods); 03207 } 03208 03209 /* The struct type was created as an indirect type pointing at 03210 it->slot. We update it->slot to automatically update all 03211 references to this struct. */ 03212 it->slot = debug_make_object_type (dhandle, 03213 class != 'u', 03214 debug_get_type_size (dhandle, 03215 it->slot), 03216 fields, baseclasses, dmethods, 03217 vptrbase, ownvptr); 03218 if (it->slot == DEBUG_TYPE_NULL) 03219 return false; 03220 03221 return true; 03222 } 03223 03224 /* Read C++ default argument value and reference type information. */ 03225 03226 static boolean 03227 ieee_read_cxx_defaults (info, pp, count) 03228 struct ieee_info *info; 03229 const bfd_byte **pp; 03230 unsigned long count; 03231 { 03232 const bfd_byte *start; 03233 const char *fnname; 03234 unsigned long fnlen; 03235 bfd_vma defcount; 03236 03237 start = *pp; 03238 03239 /* Giving the function name before the argument count is an addendum 03240 to the spec. The function name is demangled, though, so this 03241 record must always refer to the current function. */ 03242 03243 if (info->blockstack.bsp <= info->blockstack.stack 03244 || info->blockstack.bsp[-1].fnindx == (unsigned int) -1) 03245 { 03246 ieee_error (info, start, "C++ default values not in a function"); 03247 return false; 03248 } 03249 03250 if (! ieee_require_atn65 (info, pp, &fnname, &fnlen) 03251 || ! ieee_require_asn (info, pp, &defcount)) 03252 return false; 03253 count -= 2; 03254 03255 while (defcount-- > 0) 03256 { 03257 bfd_vma type, val; 03258 const char *strval; 03259 unsigned long strvallen; 03260 03261 if (! ieee_require_asn (info, pp, &type)) 03262 return false; 03263 --count; 03264 03265 switch (type) 03266 { 03267 case 0: 03268 case 4: 03269 break; 03270 03271 case 1: 03272 case 2: 03273 if (! ieee_require_asn (info, pp, &val)) 03274 return false; 03275 --count; 03276 break; 03277 03278 case 3: 03279 case 7: 03280 if (! ieee_require_atn65 (info, pp, &strval, &strvallen)) 03281 return false; 03282 --count; 03283 break; 03284 03285 default: 03286 ieee_error (info, start, "unrecognized C++ default type"); 03287 return false; 03288 } 03289 03290 /* We have no way to record the default argument values, so we 03291 just ignore them. FIXME. */ 03292 } 03293 03294 /* Any remaining arguments are indices of parameters that are really 03295 reference type. */ 03296 if (count > 0) 03297 { 03298 PTR dhandle; 03299 debug_type *arg_slots; 03300 03301 dhandle = info->dhandle; 03302 arg_slots = info->types.types[info->blockstack.bsp[-1].fnindx].arg_slots; 03303 while (count-- > 0) 03304 { 03305 bfd_vma indx; 03306 debug_type target; 03307 03308 if (! ieee_require_asn (info, pp, &indx)) 03309 return false; 03310 /* The index is 1 based. */ 03311 --indx; 03312 if (arg_slots == NULL 03313 || arg_slots[indx] == DEBUG_TYPE_NULL 03314 || (debug_get_type_kind (dhandle, arg_slots[indx]) 03315 != DEBUG_KIND_POINTER)) 03316 { 03317 ieee_error (info, start, "reference parameter is not a pointer"); 03318 return false; 03319 } 03320 03321 target = debug_get_target_type (dhandle, arg_slots[indx]); 03322 arg_slots[indx] = debug_make_reference_type (dhandle, target); 03323 if (arg_slots[indx] == DEBUG_TYPE_NULL) 03324 return false; 03325 } 03326 } 03327 03328 return true; 03329 } 03330 03331 /* Read a C++ reference definition. */ 03332 03333 static boolean 03334 ieee_read_reference (info, pp) 03335 struct ieee_info *info; 03336 const bfd_byte **pp; 03337 { 03338 const bfd_byte *start; 03339 bfd_vma flags; 03340 const char *class, *name; 03341 unsigned long classlen, namlen; 03342 debug_type *pslot; 03343 debug_type target; 03344 03345 start = *pp; 03346 03347 if (! ieee_require_asn (info, pp, &flags)) 03348 return false; 03349 03350 /* Giving the class name before the member name is in an addendum to 03351 the spec. */ 03352 if (flags == 3) 03353 { 03354 if (! ieee_require_atn65 (info, pp, &class, &classlen)) 03355 return false; 03356 } 03357 03358 if (! ieee_require_atn65 (info, pp, &name, &namlen)) 03359 return false; 03360 03361 pslot = NULL; 03362 if (flags != 3) 03363 { 03364 int pass; 03365 03366 /* We search from the last variable indices to the first in 03367 hopes of finding local variables correctly. We search the 03368 local variables on the first pass, and the global variables 03369 on the second. FIXME: This probably won't work in all cases. 03370 On the other hand, I don't know what will. */ 03371 for (pass = 0; pass < 2; pass++) 03372 { 03373 struct ieee_vars *vars; 03374 int i; 03375 struct ieee_var *pv = NULL; 03376 03377 if (pass == 0) 03378 vars = &info->vars; 03379 else 03380 { 03381 vars = info->global_vars; 03382 if (vars == NULL) 03383 break; 03384 } 03385 03386 for (i = (int) vars->alloc - 1; i >= 0; i--) 03387 { 03388 boolean found; 03389 03390 pv = vars->vars + i; 03391 03392 if (pv->pslot == NULL 03393 || pv->namlen != namlen 03394 || strncmp (pv->name, name, namlen) != 0) 03395 continue; 03396 03397 found = false; 03398 switch (flags) 03399 { 03400 default: 03401 ieee_error (info, start, 03402 "unrecognized C++ reference type"); 03403 return false; 03404 03405 case 0: 03406 /* Global variable or function. */ 03407 if (pv->kind == IEEE_GLOBAL 03408 || pv->kind == IEEE_EXTERNAL 03409 || pv->kind == IEEE_FUNCTION) 03410 found = true; 03411 break; 03412 03413 case 1: 03414 /* Global static variable or function. */ 03415 if (pv->kind == IEEE_STATIC 03416 || pv->kind == IEEE_FUNCTION) 03417 found = true; 03418 break; 03419 03420 case 2: 03421 /* Local variable. */ 03422 if (pv->kind == IEEE_LOCAL) 03423 found = true; 03424 break; 03425 } 03426 03427 if (found) 03428 break; 03429 } 03430 03431 if (i >= 0) 03432 { 03433 pslot = pv->pslot; 03434 break; 03435 } 03436 } 03437 } 03438 else 03439 { 03440 struct ieee_tag *it; 03441 03442 for (it = info->tags; it != NULL; it = it->next) 03443 { 03444 if (it->name[0] == class[0] 03445 && strncmp (it->name, class, classlen) == 0 03446 && strlen (it->name) == classlen) 03447 { 03448 if (it->fslots != NULL) 03449 { 03450 const debug_field *pf; 03451 unsigned int findx; 03452 03453 pf = debug_get_fields (info->dhandle, it->type); 03454 if (pf == NULL) 03455 { 03456 ieee_error (info, start, 03457 "C++ reference in class with no fields"); 03458 return false; 03459 } 03460 03461 for (findx = 0; *pf != DEBUG_FIELD_NULL; pf++, findx++) 03462 { 03463 const char *fname; 03464 03465 fname = debug_get_field_name (info->dhandle, *pf); 03466 if (fname == NULL) 03467 return false; 03468 if (strncmp (fname, name, namlen) == 0 03469 && strlen (fname) == namlen) 03470 { 03471 pslot = it->fslots + findx; 03472 break; 03473 } 03474 } 03475 } 03476 03477 break; 03478 } 03479 } 03480 } 03481 03482 if (pslot == NULL) 03483 { 03484 ieee_error (info, start, "C++ reference not found"); 03485 return false; 03486 } 03487 03488 /* We allocated the type of the object as an indirect type pointing 03489 to *pslot, which we can now update to be a reference type. */ 03490 if (debug_get_type_kind (info->dhandle, *pslot) != DEBUG_KIND_POINTER) 03491 { 03492 ieee_error (info, start, "C++ reference is not pointer"); 03493 return false; 03494 } 03495 03496 target = debug_get_target_type (info->dhandle, *pslot); 03497 *pslot = debug_make_reference_type (info->dhandle, target); 03498 if (*pslot == DEBUG_TYPE_NULL) 03499 return false; 03500 03501 return true; 03502 } 03503 03504 /* Require an ASN record. */ 03505 03506 static boolean 03507 ieee_require_asn (info, pp, pv) 03508 struct ieee_info *info; 03509 const bfd_byte **pp; 03510 bfd_vma *pv; 03511 { 03512 const bfd_byte *start; 03513 ieee_record_enum_type c; 03514 bfd_vma varindx; 03515 03516 start = *pp; 03517 03518 c = (ieee_record_enum_type) **pp; 03519 if (c != ieee_e2_first_byte_enum) 03520 { 03521 ieee_error (info, start, "missing required ASN"); 03522 return false; 03523 } 03524 ++*pp; 03525 03526 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp); 03527 if (c != ieee_asn_record_enum) 03528 { 03529 ieee_error (info, start, "missing required ASN"); 03530 return false; 03531 } 03532 ++*pp; 03533 03534 /* Just ignore the variable index. */ 03535 if (! ieee_read_number (info, pp, &varindx)) 03536 return false; 03537 03538 return ieee_read_expression (info, pp, pv); 03539 } 03540 03541 /* Require an ATN65 record. */ 03542 03543 static boolean 03544 ieee_require_atn65 (info, pp, pname, pnamlen) 03545 struct ieee_info *info; 03546 const bfd_byte **pp; 03547 const char **pname; 03548 unsigned long *pnamlen; 03549 { 03550 const bfd_byte *start; 03551 ieee_record_enum_type c; 03552 bfd_vma name_indx, type_indx, atn_code; 03553 03554 start = *pp; 03555 03556 c = (ieee_record_enum_type) **pp; 03557 if (c != ieee_at_record_enum) 03558 { 03559 ieee_error (info, start, "missing required ATN65"); 03560 return false; 03561 } 03562 ++*pp; 03563 03564 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp); 03565 if (c != ieee_atn_record_enum) 03566 { 03567 ieee_error (info, start, "missing required ATN65"); 03568 return false; 03569 } 03570 ++*pp; 03571 03572 if (! ieee_read_number (info, pp, &name_indx) 03573 || ! ieee_read_number (info, pp, &type_indx) 03574 || ! ieee_read_number (info, pp, &atn_code)) 03575 return false; 03576 03577 /* Just ignore name_indx. */ 03578 03579 if (type_indx != 0 || atn_code != 65) 03580 { 03581 ieee_error (info, start, "bad ATN65 record"); 03582 return false; 03583 } 03584 03585 return ieee_read_id (info, pp, pname, pnamlen); 03586 } 03587 03588 /* Convert a register number in IEEE debugging information into a 03589 generic register number. */ 03590 03591 static int 03592 ieee_regno_to_genreg (abfd, r) 03593 bfd *abfd; 03594 int r; 03595 { 03596 switch (bfd_get_arch (abfd)) 03597 { 03598 case bfd_arch_m68k: 03599 /* For some reasons stabs adds 2 to the floating point register 03600 numbers. */ 03601 if (r >= 16) 03602 r += 2; 03603 break; 03604 03605 case bfd_arch_i960: 03606 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and 03607 32 to 35 for fp0 to fp3. */ 03608 --r; 03609 break; 03610 03611 default: 03612 break; 03613 } 03614 03615 return r; 03616 } 03617 03618 /* Convert a generic register number to an IEEE specific one. */ 03619 03620 static int 03621 ieee_genreg_to_regno (abfd, r) 03622 bfd *abfd; 03623 int r; 03624 { 03625 switch (bfd_get_arch (abfd)) 03626 { 03627 case bfd_arch_m68k: 03628 /* For some reason stabs add 2 to the floating point register 03629 numbers. */ 03630 if (r >= 18) 03631 r -= 2; 03632 break; 03633 03634 case bfd_arch_i960: 03635 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and 03636 32 to 35 for fp0 to fp3. */ 03637 ++r; 03638 break; 03639 03640 default: 03641 break; 03642 } 03643 03644 return r; 03645 } 03646 03647 /* These routines build IEEE debugging information out of the generic 03648 debugging information. */ 03649 03650 /* We build the IEEE debugging information byte by byte. Rather than 03651 waste time copying data around, we use a linked list of buffers to 03652 hold the data. */ 03653 03654 #define IEEE_BUFSIZE (490) 03655 03656 struct ieee_buf 03657 { 03658 /* Next buffer. */ 03659 struct ieee_buf *next; 03660 /* Number of data bytes in this buffer. */ 03661 unsigned int c; 03662 /* Bytes. */ 03663 bfd_byte buf[IEEE_BUFSIZE]; 03664 }; 03665 03666 /* A list of buffers. */ 03667 03668 struct ieee_buflist 03669 { 03670 /* Head of list. */ 03671 struct ieee_buf *head; 03672 /* Tail--last buffer on list. */ 03673 struct ieee_buf *tail; 03674 }; 03675 03676 /* In order to generate the BB11 blocks required by the HP emulator, 03677 we keep track of ranges of addresses which correspond to a given 03678 compilation unit. */ 03679 03680 struct ieee_range 03681 { 03682 /* Next range. */ 03683 struct ieee_range *next; 03684 /* Low address. */ 03685 bfd_vma low; 03686 /* High address. */ 03687 bfd_vma high; 03688 }; 03689 03690 /* This structure holds information for a class on the type stack. */ 03691 03692 struct ieee_type_class 03693 { 03694 /* The name index in the debugging information. */ 03695 unsigned int indx; 03696 /* The pmisc records for the class. */ 03697 struct ieee_buflist pmiscbuf; 03698 /* The number of pmisc records. */ 03699 unsigned int pmisccount; 03700 /* The name of the class holding the virtual table, if not this 03701 class. */ 03702 const char *vclass; 03703 /* Whether this class holds its own virtual table. */ 03704 boolean ownvptr; 03705 /* The largest virtual table offset seen so far. */ 03706 bfd_vma voffset; 03707 /* The current method. */ 03708 const char *method; 03709 /* Additional pmisc records used to record fields of reference type. */ 03710 struct ieee_buflist refs; 03711 }; 03712 03713 /* This is how we store types for the writing routines. Most types 03714 are simply represented by a type index. */ 03715 03716 struct ieee_write_type 03717 { 03718 /* Type index. */ 03719 unsigned int indx; 03720 /* The size of the type, if known. */ 03721 unsigned int size; 03722 /* The name of the type, if any. */ 03723 const char *name; 03724 /* If this is a function or method type, we build the type here, and 03725 only add it to the output buffers if we need it. */ 03726 struct ieee_buflist fndef; 03727 /* If this is a struct, this is where the struct definition is 03728 built. */ 03729 struct ieee_buflist strdef; 03730 /* If this is a class, this is where the class information is built. */ 03731 struct ieee_type_class *classdef; 03732 /* Whether the type is unsigned. */ 03733 unsigned int unsignedp : 1; 03734 /* Whether this is a reference type. */ 03735 unsigned int referencep : 1; 03736 /* Whether this is in the local type block. */ 03737 unsigned int localp : 1; 03738 /* Whether this is a duplicate struct definition which we are 03739 ignoring. */ 03740 unsigned int ignorep : 1; 03741 }; 03742 03743 /* This is the type stack used by the debug writing routines. FIXME: 03744 We could generate more efficient output if we remembered when we 03745 have output a particular type before. */ 03746 03747 struct ieee_type_stack 03748 { 03749 /* Next entry on stack. */ 03750 struct ieee_type_stack *next; 03751 /* Type information. */ 03752 struct ieee_write_type type; 03753 }; 03754 03755 /* This is a list of associations between a name and some types. 03756 These are used for typedefs and tags. */ 03757 03758 struct ieee_name_type 03759 { 03760 /* Next type for this name. */ 03761 struct ieee_name_type *next; 03762 /* ID number. For a typedef, this is the index of the type to which 03763 this name is typedefed. */ 03764 unsigned int id; 03765 /* Type. */ 03766 struct ieee_write_type type; 03767 /* If this is a tag which has not yet been defined, this is the 03768 kind. If the tag has been defined, this is DEBUG_KIND_ILLEGAL. */ 03769 enum debug_type_kind kind; 03770 }; 03771 03772 /* We use a hash table to associate names and types. */ 03773 03774 struct ieee_name_type_hash_table 03775 { 03776 struct bfd_hash_table root; 03777 }; 03778 03779 struct ieee_name_type_hash_entry 03780 { 03781 struct bfd_hash_entry root; 03782 /* Information for this name. */ 03783 struct ieee_name_type *types; 03784 }; 03785 03786 /* This is a list of enums. */ 03787 03788 struct ieee_defined_enum 03789 { 03790 /* Next enum. */ 03791 struct ieee_defined_enum *next; 03792 /* Type index. */ 03793 unsigned int indx; 03794 /* Whether this enum has been defined. */ 03795 boolean defined; 03796 /* Tag. */ 03797 const char *tag; 03798 /* Names. */ 03799 const char **names; 03800 /* Values. */ 03801 bfd_signed_vma *vals; 03802 }; 03803 03804 /* We keep a list of modified versions of types, so that we don't 03805 output them more than once. */ 03806 03807 struct ieee_modified_type 03808 { 03809 /* Pointer to this type. */ 03810 unsigned int pointer; 03811 /* Function with unknown arguments returning this type. */ 03812 unsigned int function; 03813 /* Const version of this type. */ 03814 unsigned int const_qualified; 03815 /* Volatile version of this type. */ 03816 unsigned int volatile_qualified; 03817 /* List of arrays of this type of various bounds. */ 03818 struct ieee_modified_array_type *arrays; 03819 }; 03820 03821 /* A list of arrays bounds. */ 03822 03823 struct ieee_modified_array_type 03824 { 03825 /* Next array bounds. */ 03826 struct ieee_modified_array_type *next; 03827 /* Type index with these bounds. */ 03828 unsigned int indx; 03829 /* Low bound. */ 03830 bfd_signed_vma low; 03831 /* High bound. */ 03832 bfd_signed_vma high; 03833 }; 03834 03835 /* This is a list of pending function parameter information. We don't 03836 output them until we see the first block. */ 03837 03838 struct ieee_pending_parm 03839 { 03840 /* Next pending parameter. */ 03841 struct ieee_pending_parm *next; 03842 /* Name. */ 03843 const char *name; 03844 /* Type index. */ 03845 unsigned int type; 03846 /* Whether the type is a reference. */ 03847 boolean referencep; 03848 /* Kind. */ 03849 enum debug_parm_kind kind; 03850 /* Value. */ 03851 bfd_vma val; 03852 }; 03853 03854 /* This is the handle passed down by debug_write. */ 03855 03856 struct ieee_handle 03857 { 03858 /* BFD we are writing to. */ 03859 bfd *abfd; 03860 /* Whether we got an error in a subroutine called via traverse or 03861 map_over_sections. */ 03862 boolean error; 03863 /* Current data buffer list. */ 03864 struct ieee_buflist *current; 03865 /* Current data buffer. */ 03866 struct ieee_buf *curbuf; 03867 /* Filename of current compilation unit. */ 03868 const char *filename; 03869 /* Module name of current compilation unit. */ 03870 const char *modname; 03871 /* List of buffer for global types. */ 03872 struct ieee_buflist global_types; 03873 /* List of finished data buffers. */ 03874 struct ieee_buflist data; 03875 /* List of buffers for typedefs in the current compilation unit. */ 03876 struct ieee_buflist types; 03877 /* List of buffers for variables and functions in the current 03878 compilation unit. */ 03879 struct ieee_buflist vars; 03880 /* List of buffers for C++ class definitions in the current 03881 compilation unit. */ 03882 struct ieee_buflist cxx; 03883 /* List of buffers for line numbers in the current compilation unit. */ 03884 struct ieee_buflist linenos; 03885 /* Ranges for the current compilation unit. */ 03886 struct ieee_range *ranges; 03887 /* Ranges for all debugging information. */ 03888 struct ieee_range *global_ranges; 03889 /* Nested pending ranges. */ 03890 struct ieee_range *pending_ranges; 03891 /* Type stack. */ 03892 struct ieee_type_stack *type_stack; 03893 /* Next unallocated type index. */ 03894 unsigned int type_indx; 03895 /* Next unallocated name index. */ 03896 unsigned int name_indx; 03897 /* Typedefs. */ 03898 struct ieee_name_type_hash_table typedefs; 03899 /* Tags. */ 03900 struct ieee_name_type_hash_table tags; 03901 /* Enums. */ 03902 struct ieee_defined_enum *enums; 03903 /* Modified versions of types. */ 03904 struct ieee_modified_type *modified; 03905 /* Number of entries allocated in modified. */ 03906 unsigned int modified_alloc; 03907 /* 4 byte complex type. */ 03908 unsigned int complex_float_index; 03909 /* 8 byte complex type. */ 03910 unsigned int complex_double_index; 03911 /* The depth of block nesting. This is 0 outside a function, and 1 03912 just after start_function is called. */ 03913 unsigned int block_depth; 03914 /* The name of the current function. */ 03915 const char *fnname; 03916 /* List of buffers for the type of the function we are currently 03917 writing out. */ 03918 struct ieee_buflist fntype; 03919 /* List of buffers for the parameters of the function we are 03920 currently writing out. */ 03921 struct ieee_buflist fnargs; 03922 /* Number of arguments written to fnargs. */ 03923 unsigned int fnargcount; 03924 /* Pending function parameters. */ 03925 struct ieee_pending_parm *pending_parms; 03926 /* Current line number filename. */ 03927 const char *lineno_filename; 03928 /* Line number name index. */ 03929 unsigned int lineno_name_indx; 03930 /* Filename of pending line number. */ 03931 const char *pending_lineno_filename; 03932 /* Pending line number. */ 03933 unsigned long pending_lineno; 03934 /* Address of pending line number. */ 03935 bfd_vma pending_lineno_addr; 03936 /* Highest address seen at end of procedure. */ 03937 bfd_vma highaddr; 03938 }; 03939 03940 static boolean ieee_init_buffer 03941 PARAMS ((struct ieee_handle *, struct ieee_buflist *)); 03942 static boolean ieee_change_buffer 03943 PARAMS ((struct ieee_handle *, struct ieee_buflist *)); 03944 static boolean ieee_append_buffer 03945 PARAMS ((struct ieee_handle *, struct ieee_buflist *, 03946 struct ieee_buflist *)); 03947 static boolean ieee_real_write_byte PARAMS ((struct ieee_handle *, int)); 03948 static boolean ieee_write_2bytes PARAMS ((struct ieee_handle *, int)); 03949 static boolean ieee_write_number PARAMS ((struct ieee_handle *, bfd_vma)); 03950 static boolean ieee_write_id PARAMS ((struct ieee_handle *, const char *)); 03951 static boolean ieee_write_asn 03952 PARAMS ((struct ieee_handle *, unsigned int, bfd_vma)); 03953 static boolean ieee_write_atn65 03954 PARAMS ((struct ieee_handle *, unsigned int, const char *)); 03955 static boolean ieee_push_type 03956 PARAMS ((struct ieee_handle *, unsigned int, unsigned int, boolean, 03957 boolean)); 03958 static unsigned int ieee_pop_type PARAMS ((struct ieee_handle *)); 03959 static void ieee_pop_unused_type PARAMS ((struct ieee_handle *)); 03960 static unsigned int ieee_pop_type_used 03961 PARAMS ((struct ieee_handle *, boolean)); 03962 static boolean ieee_add_range 03963 PARAMS ((struct ieee_handle *, boolean, bfd_vma, bfd_vma)); 03964 static boolean ieee_start_range PARAMS ((struct ieee_handle *, bfd_vma)); 03965 static boolean ieee_end_range PARAMS ((struct ieee_handle *, bfd_vma)); 03966 static boolean ieee_define_type 03967 PARAMS ((struct ieee_handle *, unsigned int, boolean, boolean)); 03968 static boolean ieee_define_named_type 03969 PARAMS ((struct ieee_handle *, const char *, unsigned int, unsigned int, 03970 boolean, boolean, struct ieee_buflist *)); 03971 static struct ieee_modified_type *ieee_get_modified_info 03972 PARAMS ((struct ieee_handle *, unsigned int)); 03973 static struct bfd_hash_entry *ieee_name_type_newfunc 03974 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); 03975 static boolean ieee_write_undefined_tag 03976 PARAMS ((struct ieee_name_type_hash_entry *, PTR)); 03977 static boolean ieee_finish_compilation_unit PARAMS ((struct ieee_handle *)); 03978 static void ieee_add_bb11_blocks PARAMS ((bfd *, asection *, PTR)); 03979 static boolean ieee_add_bb11 03980 PARAMS ((struct ieee_handle *, asection *, bfd_vma, bfd_vma)); 03981 static boolean ieee_output_pending_parms PARAMS ((struct ieee_handle *)); 03982 static unsigned int ieee_vis_to_flags PARAMS ((enum debug_visibility)); 03983 static boolean ieee_class_method_var 03984 PARAMS ((struct ieee_handle *, const char *, enum debug_visibility, boolean, 03985 boolean, boolean, bfd_vma, boolean)); 03986 03987 static boolean ieee_start_compilation_unit PARAMS ((PTR, const char *)); 03988 static boolean ieee_start_source PARAMS ((PTR, const char *)); 03989 static boolean ieee_empty_type PARAMS ((PTR)); 03990 static boolean ieee_void_type PARAMS ((PTR)); 03991 static boolean ieee_int_type PARAMS ((PTR, unsigned int, boolean)); 03992 static boolean ieee_float_type PARAMS ((PTR, unsigned int)); 03993 static boolean ieee_complex_type PARAMS ((PTR, unsigned int)); 03994 static boolean ieee_bool_type PARAMS ((PTR, unsigned int)); 03995 static boolean ieee_enum_type 03996 PARAMS ((PTR, const char *, const char **, bfd_signed_vma *)); 03997 static boolean ieee_pointer_type PARAMS ((PTR)); 03998 static boolean ieee_function_type PARAMS ((PTR, int, boolean)); 03999 static boolean ieee_reference_type PARAMS ((PTR)); 04000 static boolean ieee_range_type PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma)); 04001 static boolean ieee_array_type 04002 PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma, boolean)); 04003 static boolean ieee_set_type PARAMS ((PTR, boolean)); 04004 static boolean ieee_offset_type PARAMS ((PTR)); 04005 static boolean ieee_method_type PARAMS ((PTR, boolean, int, boolean)); 04006 static boolean ieee_const_type PARAMS ((PTR)); 04007 static boolean ieee_volatile_type PARAMS ((PTR)); 04008 static boolean ieee_start_struct_type 04009 PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int)); 04010 static boolean ieee_struct_field 04011 PARAMS ((PTR, const char *, bfd_vma, bfd_vma, enum debug_visibility)); 04012 static boolean ieee_end_struct_type PARAMS ((PTR)); 04013 static boolean ieee_start_class_type 04014 PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int, boolean, 04015 boolean)); 04016 static boolean ieee_class_static_member 04017 PARAMS ((PTR, const char *, const char *, enum debug_visibility)); 04018 static boolean ieee_class_baseclass 04019 PARAMS ((PTR, bfd_vma, boolean, enum debug_visibility)); 04020 static boolean ieee_class_start_method PARAMS ((PTR, const char *)); 04021 static boolean ieee_class_method_variant 04022 PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean, 04023 bfd_vma, boolean)); 04024 static boolean ieee_class_static_method_variant 04025 PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean)); 04026 static boolean ieee_class_end_method PARAMS ((PTR)); 04027 static boolean ieee_end_class_type PARAMS ((PTR)); 04028 static boolean ieee_typedef_type PARAMS ((PTR, const char *)); 04029 static boolean ieee_tag_type 04030 PARAMS ((PTR, const char *, unsigned int, enum debug_type_kind)); 04031 static boolean ieee_typdef PARAMS ((PTR, const char *)); 04032 static boolean ieee_tag PARAMS ((PTR, const char *)); 04033 static boolean ieee_int_constant PARAMS ((PTR, const char *, bfd_vma)); 04034 static boolean ieee_float_constant PARAMS ((PTR, const char *, double)); 04035 static boolean ieee_typed_constant PARAMS ((PTR, const char *, bfd_vma)); 04036 static boolean ieee_variable 04037 PARAMS ((PTR, const char *, enum debug_var_kind, bfd_vma)); 04038 static boolean ieee_start_function PARAMS ((PTR, const char *, boolean)); 04039 static boolean ieee_function_parameter 04040 PARAMS ((PTR, const char *, enum debug_parm_kind, bfd_vma)); 04041 static boolean ieee_start_block PARAMS ((PTR, bfd_vma)); 04042 static boolean ieee_end_block PARAMS ((PTR, bfd_vma)); 04043 static boolean ieee_end_function PARAMS ((PTR)); 04044 static boolean ieee_lineno 04045 PARAMS ((PTR, const char *, unsigned long, bfd_vma)); 04046 04047 static const struct debug_write_fns ieee_fns = 04048 { 04049 ieee_start_compilation_unit, 04050 ieee_start_source, 04051 ieee_empty_type, 04052 ieee_void_type, 04053 ieee_int_type, 04054 ieee_float_type, 04055 ieee_complex_type, 04056 ieee_bool_type, 04057 ieee_enum_type, 04058 ieee_pointer_type, 04059 ieee_function_type, 04060 ieee_reference_type, 04061 ieee_range_type, 04062 ieee_array_type, 04063 ieee_set_type, 04064 ieee_offset_type, 04065 ieee_method_type, 04066 ieee_const_type, 04067 ieee_volatile_type, 04068 ieee_start_struct_type, 04069 ieee_struct_field, 04070 ieee_end_struct_type, 04071 ieee_start_class_type, 04072 ieee_class_static_member, 04073 ieee_class_baseclass, 04074 ieee_class_start_method, 04075 ieee_class_method_variant, 04076 ieee_class_static_method_variant, 04077 ieee_class_end_method, 04078 ieee_end_class_type, 04079 ieee_typedef_type, 04080 ieee_tag_type, 04081 ieee_typdef, 04082 ieee_tag, 04083 ieee_int_constant, 04084 ieee_float_constant, 04085 ieee_typed_constant, 04086 ieee_variable, 04087 ieee_start_function, 04088 ieee_function_parameter, 04089 ieee_start_block, 04090 ieee_end_block, 04091 ieee_end_function, 04092 ieee_lineno 04093 }; 04094 04095 /* Initialize a buffer to be empty. */ 04096 04097 /*ARGSUSED*/ 04098 static boolean 04099 ieee_init_buffer (info, buflist) 04100 struct ieee_handle *info; 04101 struct ieee_buflist *buflist; 04102 { 04103 buflist->head = NULL; 04104 buflist->tail = NULL; 04105 return true; 04106 } 04107 04108 /* See whether a buffer list has any data. */ 04109 04110 #define ieee_buffer_emptyp(buflist) ((buflist)->head == NULL) 04111 04112 /* Change the current buffer to a specified buffer chain. */ 04113 04114 static boolean 04115 ieee_change_buffer (info, buflist) 04116 struct ieee_handle *info; 04117 struct ieee_buflist *buflist; 04118 { 04119 if (buflist->head == NULL) 04120 { 04121 struct ieee_buf *buf; 04122 04123 buf = (struct ieee_buf *) xmalloc (sizeof *buf); 04124 buf->next = NULL; 04125 buf->c = 0; 04126 buflist->head = buf; 04127 buflist->tail = buf; 04128 } 04129 04130 info->current = buflist; 04131 info->curbuf = buflist->tail; 04132 04133 return true; 04134 } 04135 04136 /* Append a buffer chain. */ 04137 04138 /*ARGSUSED*/ 04139 static boolean 04140 ieee_append_buffer (info, mainbuf, newbuf) 04141 struct ieee_handle *info; 04142 struct ieee_buflist *mainbuf; 04143 struct ieee_buflist *newbuf; 04144 { 04145 if (newbuf->head != NULL) 04146 { 04147 if (mainbuf->head == NULL) 04148 mainbuf->head = newbuf->head; 04149 else 04150 mainbuf->tail->next = newbuf->head; 04151 mainbuf->tail = newbuf->tail; 04152 } 04153 return true; 04154 } 04155 04156 /* Write a byte into the buffer. We use a macro for speed and a 04157 function for the complex cases. */ 04158 04159 #define ieee_write_byte(info, b) \ 04160 ((info)->curbuf->c < IEEE_BUFSIZE \ 04161 ? ((info)->curbuf->buf[(info)->curbuf->c++] = (b), true) \ 04162 : ieee_real_write_byte ((info), (b))) 04163 04164 static boolean 04165 ieee_real_write_byte (info, b) 04166 struct ieee_handle *info; 04167 int b; 04168 { 04169 if (info->curbuf->c >= IEEE_BUFSIZE) 04170 { 04171 struct ieee_buf *n; 04172 04173 n = (struct ieee_buf *) xmalloc (sizeof *n); 04174 n->next = NULL; 04175 n->c = 0; 04176 if (info->current->head == NULL) 04177 info->current->head = n; 04178 else 04179 info->current->tail->next = n; 04180 info->current->tail = n; 04181 info->curbuf = n; 04182 } 04183 04184 info->curbuf->buf[info->curbuf->c] = b; 04185 ++info->curbuf->c; 04186 04187 return true; 04188 } 04189 04190 /* Write out two bytes. */ 04191 04192 static boolean 04193 ieee_write_2bytes (info, i) 04194 struct ieee_handle *info; 04195 int i; 04196 { 04197 return (ieee_write_byte (info, i >> 8) 04198 && ieee_write_byte (info, i & 0xff)); 04199 } 04200 04201 /* Write out an integer. */ 04202 04203 static boolean 04204 ieee_write_number (info, v) 04205 struct ieee_handle *info; 04206 bfd_vma v; 04207 { 04208 bfd_vma t; 04209 bfd_byte ab[20]; 04210 bfd_byte *p; 04211 unsigned int c; 04212 04213 if (v <= (bfd_vma) ieee_number_end_enum) 04214 return ieee_write_byte (info, (int) v); 04215 04216 t = v; 04217 p = ab + sizeof ab; 04218 while (t != 0) 04219 { 04220 *--p = t & 0xff; 04221 t >>= 8; 04222 } 04223 c = (ab + 20) - p; 04224 04225 if (c > (unsigned int) (ieee_number_repeat_end_enum 04226 - ieee_number_repeat_start_enum)) 04227 { 04228 fprintf (stderr, "IEEE numeric overflow: 0x"); 04229 fprintf_vma (stderr, v); 04230 fprintf (stderr, "\n"); 04231 return false; 04232 } 04233 04234 if (! ieee_write_byte (info, (int) ieee_number_repeat_start_enum + c)) 04235 return false; 04236 for (; c > 0; --c, ++p) 04237 { 04238 if (! ieee_write_byte (info, *p)) 04239 return false; 04240 } 04241 04242 return true; 04243 } 04244 04245 /* Write out a string. */ 04246 04247 static boolean 04248 ieee_write_id (info, s) 04249 struct ieee_handle *info; 04250 const char *s; 04251 { 04252 unsigned int len; 04253 04254 len = strlen (s); 04255 if (len <= 0x7f) 04256 { 04257 if (! ieee_write_byte (info, len)) 04258 return false; 04259 } 04260 else if (len <= 0xff) 04261 { 04262 if (! ieee_write_byte (info, (int) ieee_extension_length_1_enum) 04263 || ! ieee_write_byte (info, len)) 04264 return false; 04265 } 04266 else if (len <= 0xffff) 04267 { 04268 if (! ieee_write_byte (info, (int) ieee_extension_length_2_enum) 04269 || ! ieee_write_2bytes (info, len)) 04270 return false; 04271 } 04272 else 04273 { 04274 fprintf (stderr, "IEEE string length overflow: %u\n", len); 04275 return false; 04276 } 04277 04278 for (; *s != '\0'; s++) 04279 if (! ieee_write_byte (info, *s)) 04280 return false; 04281 04282 return true; 04283 } 04284 04285 /* Write out an ASN record. */ 04286 04287 static boolean 04288 ieee_write_asn (info, indx, val) 04289 struct ieee_handle *info; 04290 unsigned int indx; 04291 bfd_vma val; 04292 { 04293 return (ieee_write_2bytes (info, (int) ieee_asn_record_enum) 04294 && ieee_write_number (info, indx) 04295 && ieee_write_number (info, val)); 04296 } 04297 04298 /* Write out an ATN65 record. */ 04299 04300 static boolean 04301 ieee_write_atn65 (info, indx, s) 04302 struct ieee_handle *info; 04303 unsigned int indx; 04304 const char *s; 04305 { 04306 return (ieee_write_2bytes (info, (int) ieee_atn_record_enum) 04307 && ieee_write_number (info, indx) 04308 && ieee_write_number (info, 0) 04309 && ieee_write_number (info, 65) 04310 && ieee_write_id (info, s)); 04311 } 04312 04313 /* Push a type index onto the type stack. */ 04314 04315 static boolean 04316 ieee_push_type (info, indx, size, unsignedp, localp) 04317 struct ieee_handle *info; 04318 unsigned int indx; 04319 unsigned int size; 04320 boolean unsignedp; 04321 boolean localp; 04322 { 04323 struct ieee_type_stack *ts; 04324 04325 ts = (struct ieee_type_stack *) xmalloc (sizeof *ts); 04326 memset (ts, 0, sizeof *ts); 04327 04328 ts->type.indx = indx; 04329 ts->type.size = size; 04330 ts->type.unsignedp = unsignedp; 04331 ts->type.localp = localp; 04332 04333 ts->next = info->type_stack; 04334 info->type_stack = ts; 04335 04336 return true; 04337 } 04338 04339 /* Pop a type index off the type stack. */ 04340 04341 static unsigned int 04342 ieee_pop_type (info) 04343 struct ieee_handle *info; 04344 { 04345 return ieee_pop_type_used (info, true); 04346 } 04347 04348 /* Pop an unused type index off the type stack. */ 04349 04350 static void 04351 ieee_pop_unused_type (info) 04352 struct ieee_handle *info; 04353 { 04354 (void) ieee_pop_type_used (info, false); 04355 } 04356 04357 /* Pop a used or unused type index off the type stack. */ 04358 04359 static unsigned int 04360 ieee_pop_type_used (info, used) 04361 struct ieee_handle *info; 04362 boolean used; 04363 { 04364 struct ieee_type_stack *ts; 04365 unsigned int ret; 04366 04367 ts = info->type_stack; 04368 assert (ts != NULL); 04369 04370 /* If this is a function type, and we need it, we need to append the 04371 actual definition to the typedef block now. */ 04372 if (used && ! ieee_buffer_emptyp (&ts->type.fndef)) 04373 { 04374 struct ieee_buflist *buflist; 04375 04376 if (ts->type.localp) 04377 { 04378 /* Make sure we have started the types block. */ 04379 if (ieee_buffer_emptyp (&info->types)) 04380 { 04381 if (! ieee_change_buffer (info, &info->types) 04382 || ! ieee_write_byte (info, (int) ieee_bb_record_enum) 04383 || ! ieee_write_byte (info, 1) 04384 || ! ieee_write_number (info, 0) 04385 || ! ieee_write_id (info, info->modname)) 04386 return false; 04387 } 04388 buflist = &info->types; 04389 } 04390 else 04391 { 04392 /* Make sure we started the global type block. */ 04393 if (ieee_buffer_emptyp (&info->global_types)) 04394 { 04395 if (! ieee_change_buffer (info, &info->global_types) 04396 || ! ieee_write_byte (info, (int) ieee_bb_record_enum) 04397 || ! ieee_write_byte (info, 2) 04398 || ! ieee_write_number (info, 0) 04399 || ! ieee_write_id (info, "")) 04400 return false; 04401 } 04402 buflist = &info->global_types; 04403 } 04404 04405 if (! ieee_append_buffer (info, buflist, &ts->type.fndef)) 04406 return false; 04407 } 04408 04409 ret = ts->type.indx; 04410 info->type_stack = ts->next; 04411 free (ts); 04412 return ret; 04413 } 04414 04415 /* Add a range of bytes included in the current compilation unit. */ 04416 04417 static boolean 04418 ieee_add_range (info, global, low, high) 04419 struct ieee_handle *info; 04420 boolean global; 04421 bfd_vma low; 04422 bfd_vma high; 04423 { 04424 struct ieee_range **plist, *r, **pr; 04425 04426 if (low == (bfd_vma) -1 || high == (bfd_vma) -1 || low == high) 04427 return true; 04428 04429 if (global) 04430 plist = &info->global_ranges; 04431 else 04432 plist = &info->ranges; 04433 04434 for (r = *plist; r != NULL; r = r->next) 04435 { 04436 if (high >= r->low && low <= r->high) 04437 { 04438 /* The new range overlaps r. */ 04439 if (low < r->low) 04440 r->low = low; 04441 if (high > r->high) 04442 r->high = high; 04443 pr = &r->next; 04444 while (*pr != NULL && (*pr)->low <= r->high) 04445 { 04446 struct ieee_range *n; 04447 04448 if ((*pr)->high > r->high) 04449 r->high = (*pr)->high; 04450 n = (*pr)->next; 04451 free (*pr); 04452 *pr = n; 04453 } 04454 return true; 04455 } 04456 } 04457 04458 r = (struct ieee_range *) xmalloc (sizeof *r); 04459 memset (r, 0, sizeof *r); 04460 04461 r->low = low; 04462 r->high = high; 04463 04464 /* Store the ranges sorted by address. */ 04465 for (pr = plist; *pr != NULL; pr = &(*pr)->next) 04466 if ((*pr)->low > high) 04467 break; 04468 r->next = *pr; 04469 *pr = r; 04470 04471 return true; 04472 } 04473 04474 /* Start a new range for which we only have the low address. */ 04475 04476 static boolean 04477 ieee_start_range (info, low) 04478 struct ieee_handle *info; 04479 bfd_vma low; 04480 { 04481 struct ieee_range *r; 04482 04483 r = (struct ieee_range *) xmalloc (sizeof *r); 04484 memset (r, 0, sizeof *r); 04485 r->low = low; 04486 r->next = info->pending_ranges; 04487 info->pending_ranges = r; 04488 return true; 04489 } 04490 04491 /* Finish a range started by ieee_start_range. */ 04492 04493 static boolean 04494 ieee_end_range (info, high) 04495 struct ieee_handle *info; 04496 bfd_vma high; 04497 { 04498 struct ieee_range *r; 04499 bfd_vma low; 04500 04501 assert (info->pending_ranges != NULL); 04502 r = info->pending_ranges; 04503 low = r->low; 04504 info->pending_ranges = r->next; 04505 free (r); 04506 return ieee_add_range (info, false, low, high); 04507 } 04508 04509 /* Start defining a type. */ 04510 04511 static boolean 04512 ieee_define_type (info, size, unsignedp, localp) 04513 struct ieee_handle *info; 04514 unsigned int size; 04515 boolean unsignedp; 04516 boolean localp; 04517 { 04518 return ieee_define_named_type (info, (const char *) NULL, 04519 (unsigned int) -1, size, unsignedp, 04520 localp, (struct ieee_buflist *) NULL); 04521 } 04522 04523 /* Start defining a named type. */ 04524 04525 static boolean 04526 ieee_define_named_type (info, name, indx, size, unsignedp, localp, buflist) 04527 struct ieee_handle *info; 04528 const char *name; 04529 unsigned int indx; 04530 unsigned int size; 04531 boolean unsignedp; 04532 boolean localp; 04533 struct ieee_buflist *buflist; 04534 { 04535 unsigned int type_indx; 04536 unsigned int name_indx; 04537 04538 if (indx != (unsigned int) -1) 04539 type_indx = indx; 04540 else 04541 { 04542 type_indx = info->type_indx; 04543 ++info->type_indx; 04544 } 04545 04546 name_indx = info->name_indx; 04547 ++info->name_indx; 04548 04549 if (name == NULL) 04550 name = ""; 04551 04552 /* If we were given a buffer, use it; otherwise, use either the 04553 local or the global type information, and make sure that the type 04554 block is started. */ 04555 if (buflist != NULL) 04556 { 04557 if (! ieee_change_buffer (info, buflist)) 04558 return false; 04559 } 04560 else if (localp) 04561 { 04562 if (! ieee_buffer_emptyp (&info->types)) 04563 { 04564 if (! ieee_change_buffer (info, &info->types)) 04565 return false; 04566 } 04567 else 04568 { 04569 if (! ieee_change_buffer (info, &info->types) 04570 || ! ieee_write_byte (info, (int) ieee_bb_record_enum) 04571 || ! ieee_write_byte (info, 1) 04572 || ! ieee_write_number (info, 0) 04573 || ! ieee_write_id (info, info->modname)) 04574 return false; 04575 } 04576 } 04577 else 04578 { 04579 if (! ieee_buffer_emptyp (&info->global_types)) 04580 { 04581 if (! ieee_change_buffer (info, &info->global_types)) 04582 return false; 04583 } 04584 else 04585 { 04586 if (! ieee_change_buffer (info, &info->global_types) 04587 || ! ieee_write_byte (info, (int) ieee_bb_record_enum) 04588 || ! ieee_write_byte (info, 2) 04589 || ! ieee_write_number (info, 0) 04590 || ! ieee_write_id (info, "")) 04591 return false; 04592 } 04593 } 04594 04595 /* Push the new type on the type stack, write out an NN record, and 04596 write out the start of a TY record. The caller will then finish 04597 the TY record. */ 04598 if (! ieee_push_type (info, type_indx, size, unsignedp, localp)) 04599 return false; 04600 04601 return (ieee_write_byte (info, (int) ieee_nn_record) 04602 && ieee_write_number (info, name_indx) 04603 && ieee_write_id (info, name) 04604 && ieee_write_byte (info, (int) ieee_ty_record_enum) 04605 && ieee_write_number (info, type_indx) 04606 && ieee_write_byte (info, 0xce) 04607 && ieee_write_number (info, name_indx)); 04608 } 04609 04610 /* Get an entry to the list of modified versions of a type. */ 04611 04612 static struct ieee_modified_type * 04613 ieee_get_modified_info (info, indx) 04614 struct ieee_handle *info; 04615 unsigned int indx; 04616 { 04617 if (indx >= info->modified_alloc) 04618 { 04619 unsigned int nalloc; 04620 04621 nalloc = info->modified_alloc; 04622 if (nalloc == 0) 04623 nalloc = 16; 04624 while (indx >= nalloc) 04625 nalloc *= 2; 04626 info->modified = ((struct ieee_modified_type *) 04627 xrealloc (info->modified, 04628 nalloc * sizeof *info->modified)); 04629 memset (info->modified + info->modified_alloc, 0, 04630 (nalloc - info->modified_alloc) * sizeof *info->modified); 04631 info->modified_alloc = nalloc; 04632 } 04633 04634 return info->modified + indx; 04635 } 04636 04637 /* Routines for the hash table mapping names to types. */ 04638 04639 /* Initialize an entry in the hash table. */ 04640 04641 static struct bfd_hash_entry * 04642 ieee_name_type_newfunc (entry, table, string) 04643 struct bfd_hash_entry *entry; 04644 struct bfd_hash_table *table; 04645 const char *string; 04646 { 04647 struct ieee_name_type_hash_entry *ret = 04648 (struct ieee_name_type_hash_entry *) entry; 04649 04650 /* Allocate the structure if it has not already been allocated by a 04651 subclass. */ 04652 if (ret == NULL) 04653 ret = ((struct ieee_name_type_hash_entry *) 04654 bfd_hash_allocate (table, sizeof *ret)); 04655 if (ret == NULL) 04656 return NULL; 04657 04658 /* Call the allocation method of the superclass. */ 04659 ret = ((struct ieee_name_type_hash_entry *) 04660 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string)); 04661 if (ret) 04662 { 04663 /* Set local fields. */ 04664 ret->types = NULL; 04665 } 04666 04667 return (struct bfd_hash_entry *) ret; 04668 } 04669 04670 /* Look up an entry in the hash table. */ 04671 04672 #define ieee_name_type_hash_lookup(table, string, create, copy) \ 04673 ((struct ieee_name_type_hash_entry *) \ 04674 bfd_hash_lookup (&(table)->root, (string), (create), (copy))) 04675 04676 /* Traverse the hash table. */ 04677 04678 #define ieee_name_type_hash_traverse(table, func, info) \ 04679 (bfd_hash_traverse \ 04680 (&(table)->root, \ 04681 (boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) (func), \ 04682 (info))) 04683 04684 /* The general routine to write out IEEE debugging information. */ 04685 04686 boolean 04687 write_ieee_debugging_info (abfd, dhandle) 04688 bfd *abfd; 04689 PTR dhandle; 04690 { 04691 struct ieee_handle info; 04692 asection *s; 04693 const char *err; 04694 struct ieee_buf *b; 04695 04696 memset (&info, 0, sizeof info); 04697 info.abfd = abfd; 04698 info.type_indx = 256; 04699 info.name_indx = 32; 04700 04701 if (! bfd_hash_table_init (&info.typedefs.root, ieee_name_type_newfunc) 04702 || ! bfd_hash_table_init (&info.tags.root, ieee_name_type_newfunc)) 04703 return false; 04704 04705 if (! ieee_init_buffer (&info, &info.global_types) 04706 || ! ieee_init_buffer (&info, &info.data) 04707 || ! ieee_init_buffer (&info, &info.types) 04708 || ! ieee_init_buffer (&info, &info.vars) 04709 || ! ieee_init_buffer (&info, &info.cxx) 04710 || ! ieee_init_buffer (&info, &info.linenos) 04711 || ! ieee_init_buffer (&info, &info.fntype) 04712 || ! ieee_init_buffer (&info, &info.fnargs)) 04713 return false; 04714 04715 if (! debug_write (dhandle, &ieee_fns, (PTR) &info)) 04716 return false; 04717 04718 if (info.filename != NULL) 04719 { 04720 if (! ieee_finish_compilation_unit (&info)) 04721 return false; 04722 } 04723 04724 /* Put any undefined tags in the global typedef information. */ 04725 info.error = false; 04726 ieee_name_type_hash_traverse (&info.tags, 04727 ieee_write_undefined_tag, 04728 (PTR) &info); 04729 if (info.error) 04730 return false; 04731 04732 /* Prepend the global typedef information to the other data. */ 04733 if (! ieee_buffer_emptyp (&info.global_types)) 04734 { 04735 /* The HP debugger seems to have a bug in which it ignores the 04736 last entry in the global types, so we add a dummy entry. */ 04737 if (! ieee_change_buffer (&info, &info.global_types) 04738 || ! ieee_write_byte (&info, (int) ieee_nn_record) 04739 || ! ieee_write_number (&info, info.name_indx) 04740 || ! ieee_write_id (&info, "") 04741 || ! ieee_write_byte (&info, (int) ieee_ty_record_enum) 04742 || ! ieee_write_number (&info, info.type_indx) 04743 || ! ieee_write_byte (&info, 0xce) 04744 || ! ieee_write_number (&info, info.name_indx) 04745 || ! ieee_write_number (&info, 'P') 04746 || ! ieee_write_number (&info, (int) builtin_void + 32) 04747 || ! ieee_write_byte (&info, (int) ieee_be_record_enum)) 04748 return false; 04749 04750 if (! ieee_append_buffer (&info, &info.global_types, &info.data)) 04751 return false; 04752 info.data = info.global_types; 04753 } 04754 04755 /* Make sure that we have declare BB11 blocks for each range in the 04756 file. They are added to info->vars. */ 04757 info.error = false; 04758 if (! ieee_init_buffer (&info, &info.vars)) 04759 return false; 04760 bfd_map_over_sections (abfd, ieee_add_bb11_blocks, (PTR) &info); 04761 if (info.error) 04762 return false; 04763 if (! ieee_buffer_emptyp (&info.vars)) 04764 { 04765 if (! ieee_change_buffer (&info, &info.vars) 04766 || ! ieee_write_byte (&info, (int) ieee_be_record_enum)) 04767 return false; 04768 04769 if (! ieee_append_buffer (&info, &info.data, &info.vars)) 04770 return false; 04771 } 04772 04773 /* Now all the data is in info.data. Write it out to the BFD. We 04774 normally would need to worry about whether all the other sections 04775 are set up yet, but the IEEE backend will handle this particular 04776 case correctly regardless. */ 04777 if (ieee_buffer_emptyp (&info.data)) 04778 { 04779 /* There is no debugging information. */ 04780 return true; 04781 } 04782 err = NULL; 04783 s = bfd_make_section (abfd, ".debug"); 04784 if (s == NULL) 04785 err = "bfd_make_section"; 04786 if (err == NULL) 04787 { 04788 if (! bfd_set_section_flags (abfd, s, SEC_DEBUGGING | SEC_HAS_CONTENTS)) 04789 err = "bfd_set_section_flags"; 04790 } 04791 if (err == NULL) 04792 { 04793 bfd_size_type size; 04794 04795 size = 0; 04796 for (b = info.data.head; b != NULL; b = b->next) 04797 size += b->c; 04798 if (! bfd_set_section_size (abfd, s, size)) 04799 err = "bfd_set_section_size"; 04800 } 04801 if (err == NULL) 04802 { 04803 file_ptr offset; 04804 04805 offset = 0; 04806 for (b = info.data.head; b != NULL; b = b->next) 04807 { 04808 if (! bfd_set_section_contents (abfd, s, b->buf, offset, b->c)) 04809 { 04810 err = "bfd_set_section_contents"; 04811 break; 04812 } 04813 offset += b->c; 04814 } 04815 } 04816 04817 if (err != NULL) 04818 { 04819 fprintf (stderr, "%s: %s: %s\n", bfd_get_filename (abfd), err, 04820 bfd_errmsg (bfd_get_error ())); 04821 return false; 04822 } 04823 04824 bfd_hash_table_free (&info.typedefs.root); 04825 bfd_hash_table_free (&info.tags.root); 04826 04827 return true; 04828 } 04829 04830 /* Write out information for an undefined tag. This is called via 04831 ieee_name_type_hash_traverse. */ 04832 04833 static boolean 04834 ieee_write_undefined_tag (h, p) 04835 struct ieee_name_type_hash_entry *h; 04836 PTR p; 04837 { 04838 struct ieee_handle *info = (struct ieee_handle *) p; 04839 struct ieee_name_type *nt; 04840 04841 for (nt = h->types; nt != NULL; nt = nt->next) 04842 { 04843 unsigned int name_indx; 04844 char code; 04845 04846 if (nt->kind == DEBUG_KIND_ILLEGAL) 04847 continue; 04848 04849 if (ieee_buffer_emptyp (&info->global_types)) 04850 { 04851 if (! ieee_change_buffer (info, &info->global_types) 04852 || ! ieee_write_byte (info, (int) ieee_bb_record_enum) 04853 || ! ieee_write_byte (info, 2) 04854 || ! ieee_write_number (info, 0) 04855 || ! ieee_write_id (info, "")) 04856 { 04857 info->error = true; 04858 return false; 04859 } 04860 } 04861 else 04862 { 04863 if (! ieee_change_buffer (info, &info->global_types)) 04864 { 04865 info->error = true; 04866 return false; 04867 } 04868 } 04869 04870 name_indx = info->name_indx; 04871 ++info->name_indx; 04872 if (! ieee_write_byte (info, (int) ieee_nn_record) 04873 || ! ieee_write_number (info, name_indx) 04874 || ! ieee_write_id (info, nt->type.name) 04875 || ! ieee_write_byte (info, (int) ieee_ty_record_enum) 04876 || ! ieee_write_number (info, nt->type.indx) 04877 || ! ieee_write_byte (info, 0xce) 04878 || ! ieee_write_number (info, name_indx)) 04879 { 04880 info->error = true; 04881 return false; 04882 } 04883 04884 switch (nt->kind) 04885 { 04886 default: 04887 abort (); 04888 info->error = true; 04889 return false; 04890 case DEBUG_KIND_STRUCT: 04891 case DEBUG_KIND_CLASS: 04892 code = 'S'; 04893 break; 04894 case DEBUG_KIND_UNION: 04895 case DEBUG_KIND_UNION_CLASS: 04896 code = 'U'; 04897 break; 04898 case DEBUG_KIND_ENUM: 04899 code = 'E'; 04900 break; 04901 } 04902 if (! ieee_write_number (info, code) 04903 || ! ieee_write_number (info, 0)) 04904 { 04905 info->error = true; 04906 return false; 04907 } 04908 } 04909 04910 return true; 04911 } 04912 04913 /* Start writing out information for a compilation unit. */ 04914 04915 static boolean 04916 ieee_start_compilation_unit (p, filename) 04917 PTR p; 04918 const char *filename; 04919 { 04920 struct ieee_handle *info = (struct ieee_handle *) p; 04921 const char *modname; 04922 char *c, *s; 04923 unsigned int nindx; 04924 04925 if (info->filename != NULL) 04926 { 04927 if (! ieee_finish_compilation_unit (info)) 04928 return false; 04929 } 04930 04931 info->filename = filename; 04932 modname = strrchr (filename, '/'); 04933 if (modname != NULL) 04934 ++modname; 04935 else 04936 { 04937 modname = strrchr (filename, '\\'); 04938 if (modname != NULL) 04939 ++modname; 04940 else 04941 modname = filename; 04942 } 04943 c = xstrdup (modname); 04944 s = strrchr (c, '.'); 04945 if (s != NULL) 04946 *s = '\0'; 04947 info->modname = c; 04948 04949 if (! ieee_init_buffer (info, &info->types) 04950 || ! ieee_init_buffer (info, &info->vars) 04951 || ! ieee_init_buffer (info, &info->cxx) 04952 || ! ieee_init_buffer (info, &info->linenos)) 04953 return false; 04954 info->ranges = NULL; 04955 04956 /* Always include a BB1 and a BB3 block. That is what the output of 04957 the MRI linker seems to look like. */ 04958 if (! ieee_change_buffer (info, &info->types) 04959 || ! ieee_write_byte (info, (int) ieee_bb_record_enum) 04960 || ! ieee_write_byte (info, 1) 04961 || ! ieee_write_number (info, 0) 04962 || ! ieee_write_id (info, info->modname)) 04963 return false; 04964 04965 nindx = info->name_indx; 04966 ++info->name_indx; 04967 if (! ieee_change_buffer (info, &info->vars) 04968 || ! ieee_write_byte (info, (int) ieee_bb_record_enum) 04969 || ! ieee_write_byte (info, 3) 04970 || ! ieee_write_number (info, 0) 04971 || ! ieee_write_id (info, info->modname)) 04972 return false; 04973 04974 return true; 04975 } 04976 04977 /* Finish up a compilation unit. */ 04978 04979 static boolean 04980 ieee_finish_compilation_unit (info) 04981 struct ieee_handle *info; 04982 { 04983 struct ieee_range *r; 04984 04985 if (! ieee_buffer_emptyp (&info->types)) 04986 { 04987 if (! ieee_change_buffer (info, &info->types) 04988 || ! ieee_write_byte (info, (int) ieee_be_record_enum)) 04989 return false; 04990 } 04991 04992 if (! ieee_buffer_emptyp (&info->cxx)) 04993 { 04994 /* Append any C++ information to the global function and 04995 variable information. */ 04996 assert (! ieee_buffer_emptyp (&info->vars)); 04997 if (! ieee_change_buffer (info, &info->vars)) 04998 return false; 04999 05000 /* We put the pmisc records in a dummy procedure, just as the 05001 MRI compiler does. */ 05002 if (! ieee_write_byte (info, (int) ieee_bb_record_enum) 05003 || ! ieee_write_byte (info, 6) 05004 || ! ieee_write_number (info, 0) 05005 || ! ieee_write_id (info, "__XRYCPP") 05006 || ! ieee_write_number (info, 0) 05007 || ! ieee_write_number (info, 0) 05008 || ! ieee_write_number (info, info->highaddr - 1) 05009 || ! ieee_append_buffer (info, &info->vars, &info->cxx) 05010 || ! ieee_change_buffer (info, &info->vars) 05011 || ! ieee_write_byte (info, (int) ieee_be_record_enum) 05012 || ! ieee_write_number (info, info->highaddr - 1)) 05013 return false; 05014 } 05015 05016 if (! ieee_buffer_emptyp (&info->vars)) 05017 { 05018 if (! ieee_change_buffer (info, &info->vars) 05019 || ! ieee_write_byte (info, (int) ieee_be_record_enum)) 05020 return false; 05021 } 05022 05023 if (info->pending_lineno_filename != NULL) 05024 { 05025 /* Force out the pending line number. */ 05026 if (! ieee_lineno ((PTR) info, (const char *) NULL, 0, (bfd_vma) -1)) 05027 return false; 05028 } 05029 if (! ieee_buffer_emptyp (&info->linenos)) 05030 { 05031 if (! ieee_change_buffer (info, &info->linenos) 05032 || ! ieee_write_byte (info, (int) ieee_be_record_enum)) 05033 return false; 05034 if (strcmp (info->filename, info->lineno_filename) != 0) 05035 { 05036 /* We were not in the main file. We just closed the 05037 included line number block, and now we must close the 05038 main line number block. */ 05039 if (! ieee_write_byte (info, (int) ieee_be_record_enum)) 05040 return false; 05041 } 05042 } 05043 05044 if (! ieee_append_buffer (info, &info->data, &info->types) 05045 || ! ieee_append_buffer (info, &info->data, &info->vars) 05046 || ! ieee_append_buffer (info, &info->data, &info->linenos)) 05047 return false; 05048 05049 /* Build BB10/BB11 blocks based on the ranges we recorded. */ 05050 if (! ieee_change_buffer (info, &info->data)) 05051 return false; 05052 05053 if (! ieee_write_byte (info, (int) ieee_bb_record_enum) 05054 || ! ieee_write_byte (info, 10) 05055 || ! ieee_write_number (info, 0) 05056 || ! ieee_write_id (info, info->modname) 05057 || ! ieee_write_id (info, "") 05058 || ! ieee_write_number (info, 0) 05059 || ! ieee_write_id (info, "GNU objcopy")) 05060 return false; 05061 05062 for (r = info->ranges; r != NULL; r = r->next) 05063 { 05064 bfd_vma low, high; 05065 asection *s; 05066 int kind; 05067 05068 low = r->low; 05069 high = r->high; 05070 05071 /* Find the section corresponding to this range. */ 05072 for (s = info->abfd->sections; s != NULL; s = s->next) 05073 { 05074 if (bfd_get_section_vma (info->abfd, s) <= low 05075 && high <= (bfd_get_section_vma (info->abfd, s) 05076 + bfd_section_size (info->abfd, s))) 05077 break; 05078 } 05079 05080 if (s == NULL) 05081 { 05082 /* Just ignore this range. */ 05083 continue; 05084 } 05085 05086 /* Coalesce ranges if it seems reasonable. */ 05087 while (r->next != NULL 05088 && high + 0x1000 >= r->next->low 05089 && (r->next->high 05090 <= (bfd_get_section_vma (info->abfd, s) 05091 + bfd_section_size (info->abfd, s)))) 05092 { 05093 r = r->next; 05094 high = r->high; 05095 } 05096 05097 if ((s->flags & SEC_CODE) != 0) 05098 kind = 1; 05099 else if ((s->flags & SEC_READONLY) != 0) 05100 kind = 3; 05101 else 05102 kind = 2; 05103 05104 if (! ieee_write_byte (info, (int) ieee_bb_record_enum) 05105 || ! ieee_write_byte (info, 11) 05106 || ! ieee_write_number (info, 0) 05107 || ! ieee_write_id (info, "") 05108 || ! ieee_write_number (info, kind) 05109 || ! ieee_write_number (info, s->index + IEEE_SECTION_NUMBER_BASE) 05110 || ! ieee_write_number (info, low) 05111 || ! ieee_write_byte (info, (int) ieee_be_record_enum) 05112 || ! ieee_write_number (info, high - low)) 05113 return false; 05114 05115 /* Add this range to the list of global ranges. */ 05116 if (! ieee_add_range (info, true, low, high)) 05117 return false; 05118 } 05119 05120 if (! ieee_write_byte (info, (int) ieee_be_record_enum)) 05121 return false; 05122 05123 return true; 05124 } 05125 05126 /* Add BB11 blocks describing each range that we have not already 05127 described. */ 05128 05129 static void 05130 ieee_add_bb11_blocks (abfd, sec, data) 05131 bfd *abfd; 05132 asection *sec; 05133 PTR data; 05134 { 05135 struct ieee_handle *info = (struct ieee_handle *) data; 05136 bfd_vma low, high; 05137 struct ieee_range *r; 05138 05139 low = bfd_get_section_vma (abfd, sec); 05140 high = low + bfd_section_size (abfd, sec); 05141 05142 /* Find the first range at or after this section. The ranges are 05143 sorted by address. */ 05144 for (r = info->global_ranges; r != NULL; r = r->next) 05145 if (r->high > low) 05146 break; 05147 05148 while (low < high) 05149 { 05150 if (r == NULL || r->low >= high) 05151 { 05152 if (! ieee_add_bb11 (info, sec, low, high)) 05153 info->error = true; 05154 return; 05155 } 05156 05157 if (low < r->low 05158 && r->low - low > 0x100) 05159 { 05160 if (! ieee_add_bb11 (info, sec, low, r->low)) 05161 { 05162 info->error = true; 05163 return; 05164 } 05165 } 05166 low = r->high; 05167 05168 r = r->next; 05169 } 05170 } 05171 05172 /* Add a single BB11 block for a range. We add it to info->vars. */ 05173 05174 static boolean 05175 ieee_add_bb11 (info, sec, low, high) 05176 struct ieee_handle *info; 05177 asection *sec; 05178 bfd_vma low; 05179 bfd_vma high; 05180 { 05181 int kind; 05182 05183 if (! ieee_buffer_emptyp (&info->vars)) 05184 { 05185 if (! ieee_change_buffer (info, &info->vars)) 05186 return false; 05187 } 05188 else 05189 { 05190 const char *filename, *modname; 05191 char *c, *s; 05192 05193 /* Start the enclosing BB10 block. */ 05194 filename = bfd_get_filename (info->abfd); 05195 modname = strrchr (filename, '/'); 05196 if (modname != NULL) 05197 ++modname; 05198 else 05199 { 05200 modname = strrchr (filename, '\\'); 05201 if (modname != NULL) 05202 ++modname; 05203 else 05204 modname = filename; 05205 } 05206 c = xstrdup (modname); 05207 s = strrchr (c, '.'); 05208 if (s != NULL) 05209 *s = '\0'; 05210 05211 if (! ieee_change_buffer (info, &info->vars) 05212 || ! ieee_write_byte (info, (int) ieee_bb_record_enum) 05213 || ! ieee_write_byte (info, 10) 05214 || ! ieee_write_number (info, 0) 05215 || ! ieee_write_id (info, c) 05216 || ! ieee_write_id (info, "") 05217 || ! ieee_write_number (info, 0) 05218 || ! ieee_write_id (info, "GNU objcopy")) 05219 return false; 05220 05221 free (c); 05222 } 05223 05224 if ((sec->flags & SEC_CODE) != 0) 05225 kind = 1; 05226 else if ((sec->flags & SEC_READONLY) != 0) 05227 kind = 3; 05228 else 05229 kind = 2; 05230 05231 if (! ieee_write_byte (info, (int) ieee_bb_record_enum) 05232 || ! ieee_write_byte (info, 11) 05233 || ! ieee_write_number (info, 0) 05234 || ! ieee_write_id (info, "") 05235 || ! ieee_write_number (info, kind) 05236 || ! ieee_write_number (info, sec->index + IEEE_SECTION_NUMBER_BASE) 05237 || ! ieee_write_number (info, low) 05238 || ! ieee_write_byte (info, (int) ieee_be_record_enum) 05239 || ! ieee_write_number (info, high - low)) 05240 return false; 05241 05242 return true; 05243 } 05244 05245 /* Start recording information from a particular source file. This is 05246 used to record which file defined which types, variables, etc. It 05247 is not used for line numbers, since the lineno entry point passes 05248 down the file name anyhow. IEEE debugging information doesn't seem 05249 to store this information anywhere. */ 05250 05251 /*ARGSUSED*/ 05252 static boolean 05253 ieee_start_source (p, filename) 05254 PTR p; 05255 const char *filename; 05256 { 05257 return true; 05258 } 05259 05260 /* Make an empty type. */ 05261 05262 static boolean 05263 ieee_empty_type (p) 05264 PTR p; 05265 { 05266 struct ieee_handle *info = (struct ieee_handle *) p; 05267 05268 return ieee_push_type (info, (int) builtin_unknown, 0, false, false); 05269 } 05270 05271 /* Make a void type. */ 05272 05273 static boolean 05274 ieee_void_type (p) 05275 PTR p; 05276 { 05277 struct ieee_handle *info = (struct ieee_handle *) p; 05278 05279 return ieee_push_type (info, (int) builtin_void, 0, false, false); 05280 } 05281 05282 /* Make an integer type. */ 05283 05284 static boolean 05285 ieee_int_type (p, size, unsignedp) 05286 PTR p; 05287 unsigned int size; 05288 boolean unsignedp; 05289 { 05290 struct ieee_handle *info = (struct ieee_handle *) p; 05291 unsigned int indx; 05292 05293 switch (size) 05294 { 05295 case 1: 05296 indx = (int) builtin_signed_char; 05297 break; 05298 case 2: 05299 indx = (int) builtin_signed_short_int; 05300 break; 05301 case 4: 05302 indx = (int) builtin_signed_long; 05303 break; 05304 case 8: 05305 indx = (int) builtin_signed_long_long; 05306 break; 05307 default: 05308 fprintf (stderr, "IEEE unsupported integer type size %u\n", size); 05309 return false; 05310 } 05311 05312 if (unsignedp) 05313 ++indx; 05314 05315 return ieee_push_type (info, indx, size, unsignedp, false); 05316 } 05317 05318 /* Make a floating point type. */ 05319 05320 static boolean 05321 ieee_float_type (p, size) 05322 PTR p; 05323 unsigned int size; 05324 { 05325 struct ieee_handle *info = (struct ieee_handle *) p; 05326 unsigned int indx; 05327 05328 switch (size) 05329 { 05330 case 4: 05331 indx = (int) builtin_float; 05332 break; 05333 case 8: 05334 indx = (int) builtin_double; 05335 break; 05336 case 12: 05337 /* FIXME: This size really depends upon the processor. */ 05338 indx = (int) builtin_long_double; 05339 break; 05340 case 16: 05341 indx = (int) builtin_long_long_double; 05342 break; 05343 default: 05344 fprintf (stderr, "IEEE unsupported float type size %u\n", size); 05345 return false; 05346 } 05347 05348 return ieee_push_type (info, indx, size, false, false); 05349 } 05350 05351 /* Make a complex type. */ 05352 05353 static boolean 05354 ieee_complex_type (p, size) 05355 PTR p; 05356 unsigned int size; 05357 { 05358 struct ieee_handle *info = (struct ieee_handle *) p; 05359 char code; 05360 05361 switch (size) 05362 { 05363 case 4: 05364 if (info->complex_float_index != 0) 05365 return ieee_push_type (info, info->complex_float_index, size * 2, 05366 false, false); 05367 code = 'c'; 05368 break; 05369 case 12: 05370 case 16: 05371 /* These cases can be output by gcc -gstabs. Outputting the 05372 wrong type is better than crashing. */ 05373 case 8: 05374 if (info->complex_double_index != 0) 05375 return ieee_push_type (info, info->complex_double_index, size * 2, 05376 false, false); 05377 code = 'd'; 05378 break; 05379 default: 05380 fprintf (stderr, "IEEE unsupported complex type size %u\n", size); 05381 return false; 05382 } 05383 05384 /* FIXME: I don't know what the string is for. */ 05385 if (! ieee_define_type (info, size * 2, false, false) 05386 || ! ieee_write_number (info, code) 05387 || ! ieee_write_id (info, "")) 05388 return false; 05389 05390 if (size == 4) 05391 info->complex_float_index = info->type_stack->type.indx; 05392 else 05393 info->complex_double_index = info->type_stack->type.indx; 05394 05395 return true; 05396 } 05397 05398 /* Make a boolean type. IEEE doesn't support these, so we just make 05399 an integer type instead. */ 05400 05401 static boolean 05402 ieee_bool_type (p, size) 05403 PTR p; 05404 unsigned int size; 05405 { 05406 return ieee_int_type (p, size, true); 05407 } 05408 05409 /* Make an enumeration. */ 05410 05411 static boolean 05412 ieee_enum_type (p, tag, names, vals) 05413 PTR p; 05414 const char *tag; 05415 const char **names; 05416 bfd_signed_vma *vals; 05417 { 05418 struct ieee_handle *info = (struct ieee_handle *) p; 05419 struct ieee_defined_enum *e; 05420 boolean localp, simple; 05421 unsigned int indx; 05422 int i = 0; 05423 05424 localp = false; 05425 indx = (unsigned int) -1; 05426 for (e = info->enums; e != NULL; e = e->next) 05427 { 05428 if (tag == NULL) 05429 { 05430 if (e->tag != NULL) 05431 continue; 05432 } 05433 else 05434 { 05435 if (e->tag == NULL 05436 || tag[0] != e->tag[0] 05437 || strcmp (tag, e->tag) != 0) 05438 continue; 05439 } 05440 05441 if (! e->defined) 05442 { 05443 /* This enum tag has been seen but not defined. */ 05444 indx = e->indx; 05445 break; 05446 } 05447 05448 if (names != NULL && e->names != NULL) 05449 { 05450 for (i = 0; names[i] != NULL && e->names[i] != NULL; i++) 05451 { 05452 if (names[i][0] != e->names[i][0] 05453 || vals[i] != e->vals[i] 05454 || strcmp (names[i], e->names[i]) != 0) 05455 break; 05456 } 05457 } 05458 05459 if ((names == NULL && e->names == NULL) 05460 || (names != NULL 05461 && e->names != NULL 05462 && names[i] == NULL 05463 && e->names[i] == NULL)) 05464 { 05465 /* We've seen this enum before. */ 05466 return ieee_push_type (info, e->indx, 0, true, false); 05467 } 05468 05469 if (tag != NULL) 05470 { 05471 /* We've already seen an enum of the same name, so we must make 05472 sure to output this one locally. */ 05473 localp = true; 05474 break; 05475 } 05476 } 05477 05478 /* If this is a simple enumeration, in which the values start at 0 05479 and always increment by 1, we can use type E. Otherwise we must 05480 use type N. */ 05481 05482 simple = true; 05483 if (names != NULL) 05484 { 05485 for (i = 0; names[i] != NULL; i++) 05486 { 05487 if (vals[i] != i) 05488 { 05489 simple = false; 05490 break; 05491 } 05492 } 05493 } 05494 05495 if (! ieee_define_named_type (info, tag, indx, 0, true, localp, 05496 (struct ieee_buflist *) NULL) 05497 || ! ieee_write_number (info, simple ? 'E' : 'N')) 05498 return false; 05499 if (simple) 05500 { 05501 /* FIXME: This is supposed to be the enumeration size, but we 05502 don't store that. */ 05503 if (! ieee_write_number (info, 4)) 05504 return false; 05505 } 05506 if (names != NULL) 05507 { 05508 for (i = 0; names[i] != NULL; i++) 05509 { 05510 if (! ieee_write_id (info, names[i])) 05511 return false; 05512 if (! simple) 05513 { 05514 if (! ieee_write_number (info, vals[i])) 05515 return false; 05516 } 05517 } 05518 } 05519 05520 if (! localp) 05521 { 05522 if (indx == (unsigned int) -1) 05523 { 05524 e = (struct ieee_defined_enum *) xmalloc (sizeof *e); 05525 memset (e, 0, sizeof *e); 05526 e->indx = info->type_stack->type.indx; 05527 e->tag = tag; 05528 05529 e->next = info->enums; 05530 info->enums = e; 05531 } 05532 05533 e->names = names; 05534 e->vals = vals; 05535 e->defined = true; 05536 } 05537 05538 return true; 05539 } 05540 05541 /* Make a pointer type. */ 05542 05543 static boolean 05544 ieee_pointer_type (p) 05545 PTR p; 05546 { 05547 struct ieee_handle *info = (struct ieee_handle *) p; 05548 boolean localp; 05549 unsigned int indx; 05550 struct ieee_modified_type *m = NULL; 05551 05552 localp = info->type_stack->type.localp; 05553 indx = ieee_pop_type (info); 05554 05555 /* A pointer to a simple builtin type can be obtained by adding 32. 05556 FIXME: Will this be a short pointer, and will that matter? */ 05557 if (indx < 32) 05558 return ieee_push_type (info, indx + 32, 0, true, false); 05559 05560 if (! localp) 05561 { 05562 m = ieee_get_modified_info (p, indx); 05563 if (m == NULL) 05564 return false; 05565 05566 /* FIXME: The size should depend upon the architecture. */ 05567 if (m->pointer > 0) 05568 return ieee_push_type (info, m->pointer, 4, true, false); 05569 } 05570 05571 if (! ieee_define_type (info, 4, true, localp) 05572 || ! ieee_write_number (info, 'P') 05573 || ! ieee_write_number (info, indx)) 05574 return false; 05575 05576 if (! localp) 05577 m->pointer = info->type_stack->type.indx; 05578 05579 return true; 05580 } 05581 05582 /* Make a function type. This will be called for a method, but we 05583 don't want to actually add it to the type table in that case. We 05584 handle this by defining the type in a private buffer, and only 05585 adding that buffer to the typedef block if we are going to use it. */ 05586 05587 static boolean 05588 ieee_function_type (p, argcount, varargs) 05589 PTR p; 05590 int argcount; 05591 boolean varargs; 05592 { 05593 struct ieee_handle *info = (struct ieee_handle *) p; 05594 boolean localp; 05595 unsigned int *args = NULL; 05596 int i; 05597 unsigned int retindx; 05598 struct ieee_buflist fndef; 05599 struct ieee_modified_type *m; 05600 05601 localp = false; 05602 05603 if (argcount > 0) 05604 { 05605 args = (unsigned int *) xmalloc (argcount * sizeof *args); 05606 for (i = argcount - 1; i >= 0; i--) 05607 { 05608 if (info->type_stack->type.localp) 05609 localp = true; 05610 args[i] = ieee_pop_type (info); 05611 } 05612 } 05613 else if (argcount < 0) 05614 varargs = false; 05615 05616 if (info->type_stack->type.localp) 05617 localp = true; 05618 retindx = ieee_pop_type (info); 05619 05620 m = NULL; 05621 if (argcount < 0 && ! localp) 05622 { 05623 m = ieee_get_modified_info (p, retindx); 05624 if (m == NULL) 05625 return false; 05626 05627 if (m->function > 0) 05628 return ieee_push_type (info, m->function, 0, true, false); 05629 } 05630 05631 /* An attribute of 0x41 means that the frame and push mask are 05632 unknown. */ 05633 if (! ieee_init_buffer (info, &fndef) 05634 || ! ieee_define_named_type (info, (const char *) NULL, 05635 (unsigned int) -1, 0, true, localp, 05636 &fndef) 05637 || ! ieee_write_number (info, 'x') 05638 || ! ieee_write_number (info, 0x41) 05639 || ! ieee_write_number (info, 0) 05640 || ! ieee_write_number (info, 0) 05641 || ! ieee_write_number (info, retindx) 05642 || ! ieee_write_number (info, (bfd_vma) argcount + (varargs ? 1 : 0))) 05643 return false; 05644 if (argcount > 0) 05645 { 05646 for (i = 0; i < argcount; i++) 05647 if (! ieee_write_number (info, args[i])) 05648 return false; 05649 free (args); 05650 } 05651 if (varargs) 05652 { 05653 /* A varargs function is represented by writing out the last 05654 argument as type void *, although this makes little sense. */ 05655 if (! ieee_write_number (info, (bfd_vma) builtin_void + 32)) 05656 return false; 05657 } 05658 05659 if (! ieee_write_number (info, 0)) 05660 return false; 05661 05662 /* We wrote the information into fndef, in case we don't need it. 05663 It will be appended to info->types by ieee_pop_type. */ 05664 info->type_stack->type.fndef = fndef; 05665 05666 if (m != NULL) 05667 m->function = info->type_stack->type.indx; 05668 05669 return true; 05670 } 05671 05672 /* Make a reference type. */ 05673 05674 static boolean 05675 ieee_reference_type (p) 05676 PTR p; 05677 { 05678 struct ieee_handle *info = (struct ieee_handle *) p; 05679 05680 /* IEEE appears to record a normal pointer type, and then use a 05681 pmisc record to indicate that it is really a reference. */ 05682 05683 if (! ieee_pointer_type (p)) 05684 return false; 05685 info->type_stack->type.referencep = true; 05686 return true; 05687 } 05688 05689 /* Make a range type. */ 05690 05691 static boolean 05692 ieee_range_type (p, low, high) 05693 PTR p; 05694 bfd_signed_vma low; 05695 bfd_signed_vma high; 05696 { 05697 struct ieee_handle *info = (struct ieee_handle *) p; 05698 unsigned int size; 05699 boolean unsignedp, localp; 05700 05701 size = info->type_stack->type.size; 05702 unsignedp = info->type_stack->type.unsignedp; 05703 localp = info->type_stack->type.localp; 05704 ieee_pop_unused_type (info); 05705 return (ieee_define_type (info, size, unsignedp, localp) 05706 && ieee_write_number (info, 'R') 05707 && ieee_write_number (info, (bfd_vma) low) 05708 && ieee_write_number (info, (bfd_vma) high) 05709 && ieee_write_number (info, unsignedp ? 0 : 1) 05710 && ieee_write_number (info, size)); 05711 } 05712 05713 /* Make an array type. */ 05714 05715 /*ARGSUSED*/ 05716 static boolean 05717 ieee_array_type (p, low, high, stringp) 05718 PTR p; 05719 bfd_signed_vma low; 05720 bfd_signed_vma high; 05721 boolean stringp; 05722 { 05723 struct ieee_handle *info = (struct ieee_handle *) p; 05724 unsigned int eleindx; 05725 boolean localp; 05726 unsigned int size; 05727 struct ieee_modified_type *m = NULL; 05728 struct ieee_modified_array_type *a; 05729 05730 /* IEEE does not store the range, so we just ignore it. */ 05731 ieee_pop_unused_type (info); 05732 localp = info->type_stack->type.localp; 05733 size = info->type_stack->type.size; 05734 eleindx = ieee_pop_type (info); 05735 05736 /* If we don't know the range, treat the size as exactly one 05737 element. */ 05738 if (low < high) 05739 size *= (high - low) + 1; 05740 05741 if (! localp) 05742 { 05743 m = ieee_get_modified_info (info, eleindx); 05744 if (m == NULL) 05745 return false; 05746 05747 for (a = m->arrays; a != NULL; a = a->next) 05748 { 05749 if (a->low == low && a->high == high) 05750 return ieee_push_type (info, a->indx, size, false, false); 05751 } 05752 } 05753 05754 if (! ieee_define_type (info, size, false, localp) 05755 || ! ieee_write_number (info, low == 0 ? 'Z' : 'C') 05756 || ! ieee_write_number (info, eleindx)) 05757 return false; 05758 if (low != 0) 05759 { 05760 if (! ieee_write_number (info, low)) 05761 return false; 05762 } 05763 05764 if (! ieee_write_number (info, high + 1)) 05765 return false; 05766 05767 if (! localp) 05768 { 05769 a = (struct ieee_modified_array_type *) xmalloc (sizeof *a); 05770 memset (a, 0, sizeof *a); 05771 05772 a->indx = info->type_stack->type.indx; 05773 a->low = low; 05774 a->high = high; 05775 05776 a->next = m->arrays; 05777 m->arrays = a; 05778 } 05779 05780 return true; 05781 } 05782 05783 /* Make a set type. */ 05784 05785 static boolean 05786 ieee_set_type (p, bitstringp) 05787 PTR p; 05788 boolean bitstringp; 05789 { 05790 struct ieee_handle *info = (struct ieee_handle *) p; 05791 boolean localp; 05792 unsigned int eleindx; 05793 05794 localp = info->type_stack->type.localp; 05795 eleindx = ieee_pop_type (info); 05796 05797 /* FIXME: We don't know the size, so we just use 4. */ 05798 05799 return (ieee_define_type (info, 0, true, localp) 05800 && ieee_write_number (info, 's') 05801 && ieee_write_number (info, 4) 05802 && ieee_write_number (info, eleindx)); 05803 } 05804 05805 /* Make an offset type. */ 05806 05807 static boolean 05808 ieee_offset_type (p) 05809 PTR p; 05810 { 05811 struct ieee_handle *info = (struct ieee_handle *) p; 05812 unsigned int targetindx, baseindx; 05813 05814 targetindx = ieee_pop_type (info); 05815 baseindx = ieee_pop_type (info); 05816 05817 /* FIXME: The MRI C++ compiler does not appear to generate any 05818 useful type information about an offset type. It just records a 05819 pointer to member as an integer. The MRI/HP IEEE spec does 05820 describe a pmisc record which can be used for a pointer to 05821 member. Unfortunately, it does not describe the target type, 05822 which seems pretty important. I'm going to punt this for now. */ 05823 05824 return ieee_int_type (p, 4, true); 05825 } 05826 05827 /* Make a method type. */ 05828 05829 static boolean 05830 ieee_method_type (p, domain, argcount, varargs) 05831 PTR p; 05832 boolean domain; 05833 int argcount; 05834 boolean varargs; 05835 { 05836 struct ieee_handle *info = (struct ieee_handle *) p; 05837 05838 /* FIXME: The MRI/HP IEEE spec defines a pmisc record to use for a 05839 method, but the definition is incomplete. We just output an 'x' 05840 type. */ 05841 05842 if (domain) 05843 ieee_pop_unused_type (info); 05844 05845 return ieee_function_type (p, argcount, varargs); 05846 } 05847 05848 /* Make a const qualified type. */ 05849 05850 static boolean 05851 ieee_const_type (p) 05852 PTR p; 05853 { 05854 struct ieee_handle *info = (struct ieee_handle *) p; 05855 unsigned int size; 05856 boolean unsignedp, localp; 05857 unsigned int indx; 05858 struct ieee_modified_type *m = NULL; 05859 05860 size = info->type_stack->type.size; 05861 unsignedp = info->type_stack->type.unsignedp; 05862 localp = info->type_stack->type.localp; 05863 indx = ieee_pop_type (info); 05864 05865 if (! localp) 05866 { 05867 m = ieee_get_modified_info (info, indx); 05868 if (m == NULL) 05869 return false; 05870 05871 if (m->const_qualified > 0) 05872 return ieee_push_type (info, m->const_qualified, size, unsignedp, 05873 false); 05874 } 05875 05876 if (! ieee_define_type (info, size, unsignedp, localp) 05877 || ! ieee_write_number (info, 'n') 05878 || ! ieee_write_number (info, 1) 05879 || ! ieee_write_number (info, indx)) 05880 return false; 05881 05882 if (! localp) 05883 m->const_qualified = info->type_stack->type.indx; 05884 05885 return true; 05886 } 05887 05888 /* Make a volatile qualified type. */ 05889 05890 static boolean 05891 ieee_volatile_type (p) 05892 PTR p; 05893 { 05894 struct ieee_handle *info = (struct ieee_handle *) p; 05895 unsigned int size; 05896 boolean unsignedp, localp; 05897 unsigned int indx; 05898 struct ieee_modified_type *m = NULL; 05899 05900 size = info->type_stack->type.size; 05901 unsignedp = info->type_stack->type.unsignedp; 05902 localp = info->type_stack->type.localp; 05903 indx = ieee_pop_type (info); 05904 05905 if (! localp) 05906 { 05907 m = ieee_get_modified_info (info, indx); 05908 if (m == NULL) 05909 return false; 05910 05911 if (m->volatile_qualified > 0) 05912 return ieee_push_type (info, m->volatile_qualified, size, unsignedp, 05913 false); 05914 } 05915 05916 if (! ieee_define_type (info, size, unsignedp, localp) 05917 || ! ieee_write_number (info, 'n') 05918 || ! ieee_write_number (info, 2) 05919 || ! ieee_write_number (info, indx)) 05920 return false; 05921 05922 if (! localp) 05923 m->volatile_qualified = info->type_stack->type.indx; 05924 05925 return true; 05926 } 05927 05928 /* Convert an enum debug_visibility into a CXXFLAGS value. */ 05929 05930 static unsigned int 05931 ieee_vis_to_flags (visibility) 05932 enum debug_visibility visibility; 05933 { 05934 switch (visibility) 05935 { 05936 default: 05937 abort (); 05938 case DEBUG_VISIBILITY_PUBLIC: 05939 return CXXFLAGS_VISIBILITY_PUBLIC; 05940 case DEBUG_VISIBILITY_PRIVATE: 05941 return CXXFLAGS_VISIBILITY_PRIVATE; 05942 case DEBUG_VISIBILITY_PROTECTED: 05943 return CXXFLAGS_VISIBILITY_PROTECTED; 05944 } 05945 /*NOTREACHED*/ 05946 } 05947 05948 /* Start defining a struct type. We build it in the strdef field on 05949 the stack, to avoid confusing type definitions required by the 05950 fields with the struct type itself. */ 05951 05952 static boolean 05953 ieee_start_struct_type (p, tag, id, structp, size) 05954 PTR p; 05955 const char *tag; 05956 unsigned int id; 05957 boolean structp; 05958 unsigned int size; 05959 { 05960 struct ieee_handle *info = (struct ieee_handle *) p; 05961 boolean localp, ignorep; 05962 boolean copy; 05963 char ab[20]; 05964 const char *look; 05965 struct ieee_name_type_hash_entry *h; 05966 struct ieee_name_type *nt, *ntlook; 05967 struct ieee_buflist strdef; 05968 05969 localp = false; 05970 ignorep = false; 05971 05972 /* We need to create a tag for internal use even if we don't want 05973 one for external use. This will let us refer to an anonymous 05974 struct. */ 05975 if (tag != NULL) 05976 { 05977 look = tag; 05978 copy = false; 05979 } 05980 else 05981 { 05982 sprintf (ab, "__anon%u", id); 05983 look = ab; 05984 copy = true; 05985 } 05986 05987 /* If we already have references to the tag, we must use the 05988 existing type index. */ 05989 h = ieee_name_type_hash_lookup (&info->tags, look, true, copy); 05990 if (h == NULL) 05991 return false; 05992 05993 nt = NULL; 05994 for (ntlook = h->types; ntlook != NULL; ntlook = ntlook->next) 05995 { 05996 if (ntlook->id == id) 05997 nt = ntlook; 05998 else if (! ntlook->type.localp) 05999 { 06000 /* We are creating a duplicate definition of a globally 06001 defined tag. Force it to be local to avoid 06002 confusion. */ 06003 localp = true; 06004 } 06005 } 06006 06007 if (nt != NULL) 06008 { 06009 assert (localp == nt->type.localp); 06010 if (nt->kind == DEBUG_KIND_ILLEGAL && ! localp) 06011 { 06012 /* We've already seen a global definition of the type. 06013 Ignore this new definition. */ 06014 ignorep = true; 06015 } 06016 } 06017 else 06018 { 06019 nt = (struct ieee_name_type *) xmalloc (sizeof *nt); 06020 memset (nt, 0, sizeof *nt); 06021 nt->id = id; 06022 nt->type.name = h->root.string; 06023 nt->next = h->types; 06024 h->types = nt; 06025 nt->type.indx = info->type_indx; 06026 ++info->type_indx; 06027 } 06028 06029 nt->kind = DEBUG_KIND_ILLEGAL; 06030 06031 if (! ieee_init_buffer (info, &strdef) 06032 || ! ieee_define_named_type (info, tag, nt->type.indx, size, true, 06033 localp, &strdef) 06034 || ! ieee_write_number (info, structp ? 'S' : 'U') 06035 || ! ieee_write_number (info, size)) 06036 return false; 06037 06038 if (! ignorep) 06039 { 06040 const char *hold; 06041 06042 /* We never want nt->type.name to be NULL. We want the rest of 06043 the type to be the object set up on the type stack; it will 06044 have a NULL name if tag is NULL. */ 06045 hold = nt->type.name; 06046 nt->type = info->type_stack->type; 06047 nt->type.name = hold; 06048 } 06049 06050 info->type_stack->type.name = tag; 06051 info->type_stack->type.strdef = strdef; 06052 info->type_stack->type.ignorep = ignorep; 06053 06054 return true; 06055 } 06056 06057 /* Add a field to a struct. */ 06058 06059 static boolean 06060 ieee_struct_field (p, name, bitpos, bitsize, visibility) 06061 PTR p; 06062 const char *name; 06063 bfd_vma bitpos; 06064 bfd_vma bitsize; 06065 enum debug_visibility visibility; 06066 { 06067 struct ieee_handle *info = (struct ieee_handle *) p; 06068 unsigned int size; 06069 boolean unsignedp; 06070 boolean referencep; 06071 boolean localp; 06072 unsigned int indx; 06073 bfd_vma offset; 06074 06075 assert (info->type_stack != NULL 06076 && info->type_stack->next != NULL 06077 && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef)); 06078 06079 /* If we are ignoring this struct definition, just pop and ignore 06080 the type. */ 06081 if (info->type_stack->next->type.ignorep) 06082 { 06083 ieee_pop_unused_type (info); 06084 return true; 06085 } 06086 06087 size = info->type_stack->type.size; 06088 unsignedp = info->type_stack->type.unsignedp; 06089 referencep = info->type_stack->type.referencep; 06090 localp = info->type_stack->type.localp; 06091 indx = ieee_pop_type (info); 06092 06093 if (localp) 06094 info->type_stack->type.localp = true; 06095 06096 if (info->type_stack->type.classdef != NULL) 06097 { 06098 unsigned int flags; 06099 unsigned int nindx; 06100 06101 /* This is a class. We must add a description of this field to 06102 the class records we are building. */ 06103 06104 flags = ieee_vis_to_flags (visibility); 06105 nindx = info->type_stack->type.classdef->indx; 06106 if (! ieee_change_buffer (info, 06107 &info->type_stack->type.classdef->pmiscbuf) 06108 || ! ieee_write_asn (info, nindx, 'd') 06109 || ! ieee_write_asn (info, nindx, flags) 06110 || ! ieee_write_atn65 (info, nindx, name) 06111 || ! ieee_write_atn65 (info, nindx, name)) 06112 return false; 06113 info->type_stack->type.classdef->pmisccount += 4; 06114 06115 if (referencep) 06116 { 06117 unsigned int nindx; 06118 06119 /* We need to output a record recording that this field is 06120 really of reference type. We put this on the refs field 06121 of classdef, so that it can be appended to the C++ 06122 records after the class is defined. */ 06123 06124 nindx = info->name_indx; 06125 ++info->name_indx; 06126 06127 if (! ieee_change_buffer (info, 06128 &info->type_stack->type.classdef->refs) 06129 || ! ieee_write_byte (info, (int) ieee_nn_record) 06130 || ! ieee_write_number (info, nindx) 06131 || ! ieee_write_id (info, "") 06132 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum) 06133 || ! ieee_write_number (info, nindx) 06134 || ! ieee_write_number (info, 0) 06135 || ! ieee_write_number (info, 62) 06136 || ! ieee_write_number (info, 80) 06137 || ! ieee_write_number (info, 4) 06138 || ! ieee_write_asn (info, nindx, 'R') 06139 || ! ieee_write_asn (info, nindx, 3) 06140 || ! ieee_write_atn65 (info, nindx, info->type_stack->type.name) 06141 || ! ieee_write_atn65 (info, nindx, name)) 06142 return false; 06143 } 06144 } 06145 06146 /* If the bitsize doesn't match the expected size, we need to output 06147 a bitfield type. */ 06148 if (size == 0 || bitsize == 0 || bitsize == size * 8) 06149 offset = bitpos / 8; 06150 else 06151 { 06152 if (! ieee_define_type (info, 0, unsignedp, 06153 info->type_stack->type.localp) 06154 || ! ieee_write_number (info, 'g') 06155 || ! ieee_write_number (info, unsignedp ? 0 : 1) 06156 || ! ieee_write_number (info, bitsize) 06157 || ! ieee_write_number (info, indx)) 06158 return false; 06159 indx = ieee_pop_type (info); 06160 offset = bitpos; 06161 } 06162 06163 /* Switch to the struct we are building in order to output this 06164 field definition. */ 06165 return (ieee_change_buffer (info, &info->type_stack->type.strdef) 06166 && ieee_write_id (info, name) 06167 && ieee_write_number (info, indx) 06168 && ieee_write_number (info, offset)); 06169 } 06170 06171 /* Finish up a struct type. */ 06172 06173 static boolean 06174 ieee_end_struct_type (p) 06175 PTR p; 06176 { 06177 struct ieee_handle *info = (struct ieee_handle *) p; 06178 struct ieee_buflist *pb; 06179 06180 assert (info->type_stack != NULL 06181 && ! ieee_buffer_emptyp (&info->type_stack->type.strdef)); 06182 06183 /* If we were ignoring this struct definition because it was a 06184 duplicate defintion, just through away whatever bytes we have 06185 accumulated. Leave the type on the stack. */ 06186 if (info->type_stack->type.ignorep) 06187 return true; 06188 06189 /* If this is not a duplicate definition of this tag, then localp 06190 will be false, and we can put it in the global type block. 06191 FIXME: We should avoid outputting duplicate definitions which are 06192 the same. */ 06193 if (! info->type_stack->type.localp) 06194 { 06195 /* Make sure we have started the global type block. */ 06196 if (ieee_buffer_emptyp (&info->global_types)) 06197 { 06198 if (! ieee_change_buffer (info, &info->global_types) 06199 || ! ieee_write_byte (info, (int) ieee_bb_record_enum) 06200 || ! ieee_write_byte (info, 2) 06201 || ! ieee_write_number (info, 0) 06202 || ! ieee_write_id (info, "")) 06203 return false; 06204 } 06205 pb = &info->global_types; 06206 } 06207 else 06208 { 06209 /* Make sure we have started the types block. */ 06210 if (ieee_buffer_emptyp (&info->types)) 06211 { 06212 if (! ieee_change_buffer (info, &info->types) 06213 || ! ieee_write_byte (info, (int) ieee_bb_record_enum) 06214 || ! ieee_write_byte (info, 1) 06215 || ! ieee_write_number (info, 0) 06216 || ! ieee_write_id (info, info->modname)) 06217 return false; 06218 } 06219 pb = &info->types; 06220 } 06221 06222 /* Append the struct definition to the types. */ 06223 if (! ieee_append_buffer (info, pb, &info->type_stack->type.strdef) 06224 || ! ieee_init_buffer (info, &info->type_stack->type.strdef)) 06225 return false; 06226 06227 /* Leave the struct on the type stack. */ 06228 06229 return true; 06230 } 06231 06232 /* Start a class type. */ 06233 06234 static boolean 06235 ieee_start_class_type (p, tag, id, structp, size, vptr, ownvptr) 06236 PTR p; 06237 const char *tag; 06238 unsigned int id; 06239 boolean structp; 06240 unsigned int size; 06241 boolean vptr; 06242 boolean ownvptr; 06243 { 06244 struct ieee_handle *info = (struct ieee_handle *) p; 06245 const char *vclass; 06246 struct ieee_buflist pmiscbuf; 06247 unsigned int indx; 06248 struct ieee_type_class *classdef; 06249 06250 /* A C++ class is output as a C++ struct along with a set of pmisc 06251 records describing the class. */ 06252 06253 /* We need to have a name so that we can associate the struct and 06254 the class. */ 06255 if (tag == NULL) 06256 { 06257 char *t; 06258 06259 t = (char *) xmalloc (20); 06260 sprintf (t, "__anon%u", id); 06261 tag = t; 06262 } 06263 06264 /* We can't write out the virtual table information until we have 06265 finished the class, because we don't know the virtual table size. 06266 We get the size from the largest voffset we see. */ 06267 vclass = NULL; 06268 if (vptr && ! ownvptr) 06269 { 06270 vclass = info->type_stack->type.name; 06271 assert (vclass != NULL); 06272 /* We don't call ieee_pop_unused_type, since the class should 06273 get defined. */ 06274 (void) ieee_pop_type (info); 06275 } 06276 06277 if (! ieee_start_struct_type (p, tag, id, structp, size)) 06278 return false; 06279 06280 indx = info->name_indx; 06281 ++info->name_indx; 06282 06283 /* We write out pmisc records into the classdef field. We will 06284 write out the pmisc start after we know the number of records we 06285 need. */ 06286 if (! ieee_init_buffer (info, &pmiscbuf) 06287 || ! ieee_change_buffer (info, &pmiscbuf) 06288 || ! ieee_write_asn (info, indx, 'T') 06289 || ! ieee_write_asn (info, indx, structp ? 'o' : 'u') 06290 || ! ieee_write_atn65 (info, indx, tag)) 06291 return false; 06292 06293 classdef = (struct ieee_type_class *) xmalloc (sizeof *classdef); 06294 memset (classdef, 0, sizeof *classdef); 06295 06296 classdef->indx = indx; 06297 classdef->pmiscbuf = pmiscbuf; 06298 classdef->pmisccount = 3; 06299 classdef->vclass = vclass; 06300 classdef->ownvptr = ownvptr; 06301 06302 info->type_stack->type.classdef = classdef; 06303 06304 return true; 06305 } 06306 06307 /* Add a static member to a class. */ 06308 06309 static boolean 06310 ieee_class_static_member (p, name, physname, visibility) 06311 PTR p; 06312 const char *name; 06313 const char *physname; 06314 enum debug_visibility visibility; 06315 { 06316 struct ieee_handle *info = (struct ieee_handle *) p; 06317 unsigned int flags; 06318 unsigned int nindx; 06319 06320 /* We don't care about the type. Hopefully there will be a call to 06321 ieee_variable declaring the physical name and the type, since 06322 that is where an IEEE consumer must get the type. */ 06323 ieee_pop_unused_type (info); 06324 06325 assert (info->type_stack != NULL 06326 && info->type_stack->type.classdef != NULL); 06327 06328 flags = ieee_vis_to_flags (visibility); 06329 flags |= CXXFLAGS_STATIC; 06330 06331 nindx = info->type_stack->type.classdef->indx; 06332 06333 if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf) 06334 || ! ieee_write_asn (info, nindx, 'd') 06335 || ! ieee_write_asn (info, nindx, flags) 06336 || ! ieee_write_atn65 (info, nindx, name) 06337 || ! ieee_write_atn65 (info, nindx, physname)) 06338 return false; 06339 info->type_stack->type.classdef->pmisccount += 4; 06340 06341 return true; 06342 } 06343 06344 /* Add a base class to a class. */ 06345 06346 static boolean 06347 ieee_class_baseclass (p, bitpos, virtual, visibility) 06348 PTR p; 06349 bfd_vma bitpos; 06350 boolean virtual; 06351 enum debug_visibility visibility; 06352 { 06353 struct ieee_handle *info = (struct ieee_handle *) p; 06354 const char *bname; 06355 boolean localp; 06356 unsigned int bindx; 06357 char *fname; 06358 unsigned int flags; 06359 unsigned int nindx; 06360 06361 assert (info->type_stack != NULL 06362 && info->type_stack->type.name != NULL 06363 && info->type_stack->next != NULL 06364 && info->type_stack->next->type.classdef != NULL 06365 && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef)); 06366 06367 bname = info->type_stack->type.name; 06368 localp = info->type_stack->type.localp; 06369 bindx = ieee_pop_type (info); 06370 06371 /* We are currently defining both a struct and a class. We must 06372 write out a field definition in the struct which holds the base 06373 class. The stabs debugging reader will create a field named 06374 _vb$CLASS for a virtual base class, so we just use that. FIXME: 06375 we should not depend upon a detail of stabs debugging. */ 06376 if (virtual) 06377 { 06378 fname = (char *) xmalloc (strlen (bname) + sizeof "_vb$"); 06379 sprintf (fname, "_vb$%s", bname); 06380 flags = BASEFLAGS_VIRTUAL; 06381 } 06382 else 06383 { 06384 if (localp) 06385 info->type_stack->type.localp = true; 06386 06387 fname = (char *) xmalloc (strlen (bname) + sizeof "_b$"); 06388 sprintf (fname, "_b$%s", bname); 06389 06390 if (! ieee_change_buffer (info, &info->type_stack->type.strdef) 06391 || ! ieee_write_id (info, fname) 06392 || ! ieee_write_number (info, bindx) 06393 || ! ieee_write_number (info, bitpos / 8)) 06394 return false; 06395 flags = 0; 06396 } 06397 06398 if (visibility == DEBUG_VISIBILITY_PRIVATE) 06399 flags |= BASEFLAGS_PRIVATE; 06400 06401 nindx = info->type_stack->type.classdef->indx; 06402 06403 if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf) 06404 || ! ieee_write_asn (info, nindx, 'b') 06405 || ! ieee_write_asn (info, nindx, flags) 06406 || ! ieee_write_atn65 (info, nindx, bname) 06407 || ! ieee_write_asn (info, nindx, 0) 06408 || ! ieee_write_atn65 (info, nindx, fname)) 06409 return false; 06410 info->type_stack->type.classdef->pmisccount += 5; 06411 06412 free (fname); 06413 06414 return true; 06415 } 06416 06417 /* Start building a method for a class. */ 06418 06419 static boolean 06420 ieee_class_start_method (p, name) 06421 PTR p; 06422 const char *name; 06423 { 06424 struct ieee_handle *info = (struct ieee_handle *) p; 06425 06426 assert (info->type_stack != NULL 06427 && info->type_stack->type.classdef != NULL 06428 && info->type_stack->type.classdef->method == NULL); 06429 06430 info->type_stack->type.classdef->method = name; 06431 06432 return true; 06433 } 06434 06435 /* Define a new method variant, either static or not. */ 06436 06437 static boolean 06438 ieee_class_method_var (info, physname, visibility, staticp, constp, 06439 volatilep, voffset, context) 06440 struct ieee_handle *info; 06441 const char *physname; 06442 enum debug_visibility visibility; 06443 boolean staticp; 06444 boolean constp; 06445 boolean volatilep; 06446 bfd_vma voffset; 06447 boolean context; 06448 { 06449 unsigned int flags; 06450 unsigned int nindx; 06451 boolean virtual; 06452 06453 /* We don't need the type of the method. An IEEE consumer which 06454 wants the type must track down the function by the physical name 06455 and get the type from that. */ 06456 ieee_pop_unused_type (info); 06457 06458 /* We don't use the context. FIXME: We probably ought to use it to 06459 adjust the voffset somehow, but I don't really know how. */ 06460 if (context) 06461 ieee_pop_unused_type (info); 06462 06463 assert (info->type_stack != NULL 06464 && info->type_stack->type.classdef != NULL 06465 && info->type_stack->type.classdef->method != NULL); 06466 06467 flags = ieee_vis_to_flags (visibility); 06468 06469 /* FIXME: We never set CXXFLAGS_OVERRIDE, CXXFLAGS_OPERATOR, 06470 CXXFLAGS_CTORDTOR, CXXFLAGS_CTOR, or CXXFLAGS_INLINE. */ 06471 06472 if (staticp) 06473 flags |= CXXFLAGS_STATIC; 06474 if (constp) 06475 flags |= CXXFLAGS_CONST; 06476 if (volatilep) 06477 flags |= CXXFLAGS_VOLATILE; 06478 06479 nindx = info->type_stack->type.classdef->indx; 06480 06481 virtual = context || voffset > 0; 06482 06483 if (! ieee_change_buffer (info, 06484 &info->type_stack->type.classdef->pmiscbuf) 06485 || ! ieee_write_asn (info, nindx, virtual ? 'v' : 'm') 06486 || ! ieee_write_asn (info, nindx, flags) 06487 || ! ieee_write_atn65 (info, nindx, 06488 info->type_stack->type.classdef->method) 06489 || ! ieee_write_atn65 (info, nindx, physname)) 06490 return false; 06491 06492 if (virtual) 06493 { 06494 if (voffset > info->type_stack->type.classdef->voffset) 06495 info->type_stack->type.classdef->voffset = voffset; 06496 if (! ieee_write_asn (info, nindx, voffset)) 06497 return false; 06498 ++info->type_stack->type.classdef->pmisccount; 06499 } 06500 06501 if (! ieee_write_asn (info, nindx, 0)) 06502 return false; 06503 06504 info->type_stack->type.classdef->pmisccount += 5; 06505 06506 return true; 06507 } 06508 06509 /* Define a new method variant. */ 06510 06511 static boolean 06512 ieee_class_method_variant (p, physname, visibility, constp, volatilep, 06513 voffset, context) 06514 PTR p; 06515 const char *physname; 06516 enum debug_visibility visibility; 06517 boolean constp; 06518 boolean volatilep; 06519 bfd_vma voffset; 06520 boolean context; 06521 { 06522 struct ieee_handle *info = (struct ieee_handle *) p; 06523 06524 return ieee_class_method_var (info, physname, visibility, false, constp, 06525 volatilep, voffset, context); 06526 } 06527 06528 /* Define a new static method variant. */ 06529 06530 static boolean 06531 ieee_class_static_method_variant (p, physname, visibility, constp, volatilep) 06532 PTR p; 06533 const char *physname; 06534 enum debug_visibility visibility; 06535 boolean constp; 06536 boolean volatilep; 06537 { 06538 struct ieee_handle *info = (struct ieee_handle *) p; 06539 06540 return ieee_class_method_var (info, physname, visibility, true, constp, 06541 volatilep, 0, false); 06542 } 06543 06544 /* Finish up a method. */ 06545 06546 static boolean 06547 ieee_class_end_method (p) 06548 PTR p; 06549 { 06550 struct ieee_handle *info = (struct ieee_handle *) p; 06551 06552 assert (info->type_stack != NULL 06553 && info->type_stack->type.classdef != NULL 06554 && info->type_stack->type.classdef->method != NULL); 06555 06556 info->type_stack->type.classdef->method = NULL; 06557 06558 return true; 06559 } 06560 06561 /* Finish up a class. */ 06562 06563 static boolean 06564 ieee_end_class_type (p) 06565 PTR p; 06566 { 06567 struct ieee_handle *info = (struct ieee_handle *) p; 06568 unsigned int nindx; 06569 06570 assert (info->type_stack != NULL 06571 && info->type_stack->type.classdef != NULL); 06572 06573 /* If we were ignoring this class definition because it was a 06574 duplicate definition, just through away whatever bytes we have 06575 accumulated. Leave the type on the stack. */ 06576 if (info->type_stack->type.ignorep) 06577 return true; 06578 06579 nindx = info->type_stack->type.classdef->indx; 06580 06581 /* If we have a virtual table, we can write out the information now. */ 06582 if (info->type_stack->type.classdef->vclass != NULL 06583 || info->type_stack->type.classdef->ownvptr) 06584 { 06585 if (! ieee_change_buffer (info, 06586 &info->type_stack->type.classdef->pmiscbuf) 06587 || ! ieee_write_asn (info, nindx, 'z') 06588 || ! ieee_write_atn65 (info, nindx, "") 06589 || ! ieee_write_asn (info, nindx, 06590 info->type_stack->type.classdef->voffset)) 06591 return false; 06592 if (info->type_stack->type.classdef->ownvptr) 06593 { 06594 if (! ieee_write_atn65 (info, nindx, "")) 06595 return false; 06596 } 06597 else 06598 { 06599 if (! ieee_write_atn65 (info, nindx, 06600 info->type_stack->type.classdef->vclass)) 06601 return false; 06602 } 06603 if (! ieee_write_asn (info, nindx, 0)) 06604 return false; 06605 info->type_stack->type.classdef->pmisccount += 5; 06606 } 06607 06608 /* Now that we know the number of pmisc records, we can write out 06609 the atn62 which starts the pmisc records, and append them to the 06610 C++ buffers. */ 06611 06612 if (! ieee_change_buffer (info, &info->cxx) 06613 || ! ieee_write_byte (info, (int) ieee_nn_record) 06614 || ! ieee_write_number (info, nindx) 06615 || ! ieee_write_id (info, "") 06616 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum) 06617 || ! ieee_write_number (info, nindx) 06618 || ! ieee_write_number (info, 0) 06619 || ! ieee_write_number (info, 62) 06620 || ! ieee_write_number (info, 80) 06621 || ! ieee_write_number (info, 06622 info->type_stack->type.classdef->pmisccount)) 06623 return false; 06624 06625 if (! ieee_append_buffer (info, &info->cxx, 06626 &info->type_stack->type.classdef->pmiscbuf)) 06627 return false; 06628 if (! ieee_buffer_emptyp (&info->type_stack->type.classdef->refs)) 06629 { 06630 if (! ieee_append_buffer (info, &info->cxx, 06631 &info->type_stack->type.classdef->refs)) 06632 return false; 06633 } 06634 06635 return ieee_end_struct_type (p); 06636 } 06637 06638 /* Push a previously seen typedef onto the type stack. */ 06639 06640 static boolean 06641 ieee_typedef_type (p, name) 06642 PTR p; 06643 const char *name; 06644 { 06645 struct ieee_handle *info = (struct ieee_handle *) p; 06646 struct ieee_name_type_hash_entry *h; 06647 struct ieee_name_type *nt; 06648 06649 h = ieee_name_type_hash_lookup (&info->typedefs, name, false, false); 06650 06651 /* h should never be NULL, since that would imply that the generic 06652 debugging code has asked for a typedef which it has not yet 06653 defined. */ 06654 assert (h != NULL); 06655 06656 /* We always use the most recently defined type for this name, which 06657 will be the first one on the list. */ 06658 06659 nt = h->types; 06660 if (! ieee_push_type (info, nt->type.indx, nt->type.size, 06661 nt->type.unsignedp, nt->type.localp)) 06662 return false; 06663 06664 /* Copy over any other type information we may have. */ 06665 info->type_stack->type = nt->type; 06666 06667 return true; 06668 } 06669 06670 /* Push a tagged type onto the type stack. */ 06671 06672 static boolean 06673 ieee_tag_type (p, name, id, kind) 06674 PTR p; 06675 const char *name; 06676 unsigned int id; 06677 enum debug_type_kind kind; 06678 { 06679 struct ieee_handle *info = (struct ieee_handle *) p; 06680 boolean localp; 06681 boolean copy; 06682 char ab[20]; 06683 struct ieee_name_type_hash_entry *h; 06684 struct ieee_name_type *nt; 06685 06686 if (kind == DEBUG_KIND_ENUM) 06687 { 06688 struct ieee_defined_enum *e; 06689 06690 if (name == NULL) 06691 abort (); 06692 for (e = info->enums; e != NULL; e = e->next) 06693 if (e->tag != NULL && strcmp (e->tag, name) == 0) 06694 return ieee_push_type (info, e->indx, 0, true, false); 06695 06696 e = (struct ieee_defined_enum *) xmalloc (sizeof *e); 06697 memset (e, 0, sizeof *e); 06698 06699 e->indx = info->type_indx; 06700 ++info->type_indx; 06701 e->tag = name; 06702 e->defined = false; 06703 06704 e->next = info->enums; 06705 info->enums = e; 06706 06707 return ieee_push_type (info, e->indx, 0, true, false); 06708 } 06709 06710 localp = false; 06711 06712 copy = false; 06713 if (name == NULL) 06714 { 06715 sprintf (ab, "__anon%u", id); 06716 name = ab; 06717 copy = true; 06718 } 06719 06720 h = ieee_name_type_hash_lookup (&info->tags, name, true, copy); 06721 if (h == NULL) 06722 return false; 06723 06724 for (nt = h->types; nt != NULL; nt = nt->next) 06725 { 06726 if (nt->id == id) 06727 { 06728 if (! ieee_push_type (info, nt->type.indx, nt->type.size, 06729 nt->type.unsignedp, nt->type.localp)) 06730 return false; 06731 /* Copy over any other type information we may have. */ 06732 info->type_stack->type = nt->type; 06733 return true; 06734 } 06735 06736 if (! nt->type.localp) 06737 { 06738 /* This is a duplicate of a global type, so it must be 06739 local. */ 06740 localp = true; 06741 } 06742 } 06743 06744 nt = (struct ieee_name_type *) xmalloc (sizeof *nt); 06745 memset (nt, 0, sizeof *nt); 06746 06747 nt->id = id; 06748 nt->type.name = h->root.string; 06749 nt->type.indx = info->type_indx; 06750 nt->type.localp = localp; 06751 ++info->type_indx; 06752 nt->kind = kind; 06753 06754 nt->next = h->types; 06755 h->types = nt; 06756 06757 if (! ieee_push_type (info, nt->type.indx, 0, false, localp)) 06758 return false; 06759 06760 info->type_stack->type.name = h->root.string; 06761 06762 return true; 06763 } 06764 06765 /* Output a typedef. */ 06766 06767 static boolean 06768 ieee_typdef (p, name) 06769 PTR p; 06770 const char *name; 06771 { 06772 struct ieee_handle *info = (struct ieee_handle *) p; 06773 struct ieee_write_type type; 06774 unsigned int indx; 06775 boolean found; 06776 boolean localp; 06777 struct ieee_name_type_hash_entry *h; 06778 struct ieee_name_type *nt; 06779 06780 type = info->type_stack->type; 06781 indx = type.indx; 06782 06783 /* If this is a simple builtin type using a builtin name, we don't 06784 want to output the typedef itself. We also want to change the 06785 type index to correspond to the name being used. We recognize 06786 names used in stabs debugging output even if they don't exactly 06787 correspond to the names used for the IEEE builtin types. */ 06788 found = false; 06789 if (indx <= (unsigned int) builtin_bcd_float) 06790 { 06791 switch ((enum builtin_types) indx) 06792 { 06793 default: 06794 break; 06795 06796 case builtin_void: 06797 if (strcmp (name, "void") == 0) 06798 found = true; 06799 break; 06800 06801 case builtin_signed_char: 06802 case builtin_char: 06803 if (strcmp (name, "signed char") == 0) 06804 { 06805 indx = (unsigned int) builtin_signed_char; 06806 found = true; 06807 } 06808 else if (strcmp (name, "char") == 0) 06809 { 06810 indx = (unsigned int) builtin_char; 06811 found = true; 06812 } 06813 break; 06814 06815 case builtin_unsigned_char: 06816 if (strcmp (name, "unsigned char") == 0) 06817 found = true; 06818 break; 06819 06820 case builtin_signed_short_int: 06821 case builtin_short: 06822 case builtin_short_int: 06823 case builtin_signed_short: 06824 if (strcmp (name, "signed short int") == 0) 06825 { 06826 indx = (unsigned int) builtin_signed_short_int; 06827 found = true; 06828 } 06829 else if (strcmp (name, "short") == 0) 06830 { 06831 indx = (unsigned int) builtin_short; 06832 found = true; 06833 } 06834 else if (strcmp (name, "short int") == 0) 06835 { 06836 indx = (unsigned int) builtin_short_int; 06837 found = true; 06838 } 06839 else if (strcmp (name, "signed short") == 0) 06840 { 06841 indx = (unsigned int) builtin_signed_short; 06842 found = true; 06843 } 06844 break; 06845 06846 case builtin_unsigned_short_int: 06847 case builtin_unsigned_short: 06848 if (strcmp (name, "unsigned short int") == 0 06849 || strcmp (name, "short unsigned int") == 0) 06850 { 06851 indx = builtin_unsigned_short_int; 06852 found = true; 06853 } 06854 else if (strcmp (name, "unsigned short") == 0) 06855 { 06856 indx = builtin_unsigned_short; 06857 found = true; 06858 } 06859 break; 06860 06861 case builtin_signed_long: 06862 case builtin_int: /* FIXME: Size depends upon architecture. */ 06863 case builtin_long: 06864 if (strcmp (name, "signed long") == 0) 06865 { 06866 indx = builtin_signed_long; 06867 found = true; 06868 } 06869 else if (strcmp (name, "int") == 0) 06870 { 06871 indx = builtin_int; 06872 found = true; 06873 } 06874 else if (strcmp (name, "long") == 0 06875 || strcmp (name, "long int") == 0) 06876 { 06877 indx = builtin_long; 06878 found = true; 06879 } 06880 break; 06881 06882 case builtin_unsigned_long: 06883 case builtin_unsigned: /* FIXME: Size depends upon architecture. */ 06884 case builtin_unsigned_int: /* FIXME: Like builtin_unsigned. */ 06885 if (strcmp (name, "unsigned long") == 0 06886 || strcmp (name, "long unsigned int") == 0) 06887 { 06888 indx = builtin_unsigned_long; 06889 found = true; 06890 } 06891 else if (strcmp (name, "unsigned") == 0) 06892 { 06893 indx = builtin_unsigned; 06894 found = true; 06895 } 06896 else if (strcmp (name, "unsigned int") == 0) 06897 { 06898 indx = builtin_unsigned_int; 06899 found = true; 06900 } 06901 break; 06902 06903 case builtin_signed_long_long: 06904 if (strcmp (name, "signed long long") == 0 06905 || strcmp (name, "long long int") == 0) 06906 found = true; 06907 break; 06908 06909 case builtin_unsigned_long_long: 06910 if (strcmp (name, "unsigned long long") == 0 06911 || strcmp (name, "long long unsigned int") == 0) 06912 found = true; 06913 break; 06914 06915 case builtin_float: 06916 if (strcmp (name, "float") == 0) 06917 found = true; 06918 break; 06919 06920 case builtin_double: 06921 if (strcmp (name, "double") == 0) 06922 found = true; 06923 break; 06924 06925 case builtin_long_double: 06926 if (strcmp (name, "long double") == 0) 06927 found = true; 06928 break; 06929 06930 case builtin_long_long_double: 06931 if (strcmp (name, "long long double") == 0) 06932 found = true; 06933 break; 06934 } 06935 06936 if (found) 06937 type.indx = indx; 06938 } 06939 06940 h = ieee_name_type_hash_lookup (&info->typedefs, name, true, false); 06941 if (h == NULL) 06942 return false; 06943 06944 /* See if we have already defined this type with this name. */ 06945 localp = type.localp; 06946 for (nt = h->types; nt != NULL; nt = nt->next) 06947 { 06948 if (nt->id == indx) 06949 { 06950 /* If this is a global definition, then we don't need to 06951 do anything here. */ 06952 if (! nt->type.localp) 06953 { 06954 ieee_pop_unused_type (info); 06955 return true; 06956 } 06957 } 06958 else 06959 { 06960 /* This is a duplicate definition, so make this one local. */ 06961 localp = true; 06962 } 06963 } 06964 06965 /* We need to add a new typedef for this type. */ 06966 06967 nt = (struct ieee_name_type *) xmalloc (sizeof *nt); 06968 memset (nt, 0, sizeof *nt); 06969 nt->id = indx; 06970 nt->type = type; 06971 nt->type.name = name; 06972 nt->type.localp = localp; 06973 nt->kind = DEBUG_KIND_ILLEGAL; 06974 06975 nt->next = h->types; 06976 h->types = nt; 06977 06978 if (found) 06979 { 06980 /* This is one of the builtin typedefs, so we don't need to 06981 actually define it. */ 06982 ieee_pop_unused_type (info); 06983 return true; 06984 } 06985 06986 indx = ieee_pop_type (info); 06987 06988 if (! ieee_define_named_type (info, name, (unsigned int) -1, type.size, 06989 type.unsignedp, localp, 06990 (struct ieee_buflist *) NULL) 06991 || ! ieee_write_number (info, 'T') 06992 || ! ieee_write_number (info, indx)) 06993 return false; 06994 06995 /* Remove the type we just added to the type stack. This should not 06996 be ieee_pop_unused_type, since the type is used, we just don't 06997 need it now. */ 06998 (void) ieee_pop_type (info); 06999 07000 return true; 07001 } 07002 07003 /* Output a tag for a type. We don't have to do anything here. */ 07004 07005 static boolean 07006 ieee_tag (p, name) 07007 PTR p; 07008 const char *name; 07009 { 07010 struct ieee_handle *info = (struct ieee_handle *) p; 07011 07012 /* This should not be ieee_pop_unused_type, since we want the type 07013 to be defined. */ 07014 (void) ieee_pop_type (info); 07015 return true; 07016 } 07017 07018 /* Output an integer constant. */ 07019 07020 static boolean 07021 ieee_int_constant (p, name, val) 07022 PTR p; 07023 const char *name; 07024 bfd_vma val; 07025 { 07026 /* FIXME. */ 07027 return true; 07028 } 07029 07030 /* Output a floating point constant. */ 07031 07032 static boolean 07033 ieee_float_constant (p, name, val) 07034 PTR p; 07035 const char *name; 07036 double val; 07037 { 07038 /* FIXME. */ 07039 return true; 07040 } 07041 07042 /* Output a typed constant. */ 07043 07044 static boolean 07045 ieee_typed_constant (p, name, val) 07046 PTR p; 07047 const char *name; 07048 bfd_vma val; 07049 { 07050 struct ieee_handle *info = (struct ieee_handle *) p; 07051 07052 /* FIXME. */ 07053 ieee_pop_unused_type (info); 07054 return true; 07055 } 07056 07057 /* Output a variable. */ 07058 07059 static boolean 07060 ieee_variable (p, name, kind, val) 07061 PTR p; 07062 const char *name; 07063 enum debug_var_kind kind; 07064 bfd_vma val; 07065 { 07066 struct ieee_handle *info = (struct ieee_handle *) p; 07067 unsigned int name_indx; 07068 unsigned int size; 07069 boolean referencep; 07070 unsigned int type_indx; 07071 boolean asn; 07072 int refflag; 07073 07074 size = info->type_stack->type.size; 07075 referencep = info->type_stack->type.referencep; 07076 type_indx = ieee_pop_type (info); 07077 07078 assert (! ieee_buffer_emptyp (&info->vars)); 07079 if (! ieee_change_buffer (info, &info->vars)) 07080 return false; 07081 07082 name_indx = info->name_indx; 07083 ++info->name_indx; 07084 07085 /* Write out an NN and an ATN record for this variable. */ 07086 if (! ieee_write_byte (info, (int) ieee_nn_record) 07087 || ! ieee_write_number (info, name_indx) 07088 || ! ieee_write_id (info, name) 07089 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum) 07090 || ! ieee_write_number (info, name_indx) 07091 || ! ieee_write_number (info, type_indx)) 07092 return false; 07093 switch (kind) 07094 { 07095 default: 07096 abort (); 07097 return false; 07098 case DEBUG_GLOBAL: 07099 if (! ieee_write_number (info, 8) 07100 || ! ieee_add_range (info, false, val, val + size)) 07101 return false; 07102 refflag = 0; 07103 asn = true; 07104 break; 07105 case DEBUG_STATIC: 07106 if (! ieee_write_number (info, 3) 07107 || ! ieee_add_range (info, false, val, val + size)) 07108 return false; 07109 refflag = 1; 07110 asn = true; 07111 break; 07112 case DEBUG_LOCAL_STATIC: 07113 if (! ieee_write_number (info, 3) 07114 || ! ieee_add_range (info, false, val, val + size)) 07115 return false; 07116 refflag = 2; 07117 asn = true; 07118 break; 07119 case DEBUG_LOCAL: 07120 if (! ieee_write_number (info, 1) 07121 || ! ieee_write_number (info, val)) 07122 return false; 07123 refflag = 2; 07124 asn = false; 07125 break; 07126 case DEBUG_REGISTER: 07127 if (! ieee_write_number (info, 2) 07128 || ! ieee_write_number (info, 07129 ieee_genreg_to_regno (info->abfd, val))) 07130 return false; 07131 refflag = 2; 07132 asn = false; 07133 break; 07134 } 07135 07136 if (asn) 07137 { 07138 if (! ieee_write_asn (info, name_indx, val)) 07139 return false; 07140 } 07141 07142 /* If this is really a reference type, then we just output it with 07143 pointer type, and must now output a C++ record indicating that it 07144 is really reference type. */ 07145 if (referencep) 07146 { 07147 unsigned int nindx; 07148 07149 nindx = info->name_indx; 07150 ++info->name_indx; 07151 07152 /* If this is a global variable, we want to output the misc 07153 record in the C++ misc record block. Otherwise, we want to 07154 output it just after the variable definition, which is where 07155 the current buffer is. */ 07156 if (refflag != 2) 07157 { 07158 if (! ieee_change_buffer (info, &info->cxx)) 07159 return false; 07160 } 07161 07162 if (! ieee_write_byte (info, (int) ieee_nn_record) 07163 || ! ieee_write_number (info, nindx) 07164 || ! ieee_write_id (info, "") 07165 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum) 07166 || ! ieee_write_number (info, nindx) 07167 || ! ieee_write_number (info, 0) 07168 || ! ieee_write_number (info, 62) 07169 || ! ieee_write_number (info, 80) 07170 || ! ieee_write_number (info, 3) 07171 || ! ieee_write_asn (info, nindx, 'R') 07172 || ! ieee_write_asn (info, nindx, refflag) 07173 || ! ieee_write_atn65 (info, nindx, name)) 07174 return false; 07175 } 07176 07177 return true; 07178 } 07179 07180 /* Start outputting information for a function. */ 07181 07182 static boolean 07183 ieee_start_function (p, name, global) 07184 PTR p; 07185 const char *name; 07186 boolean global; 07187 { 07188 struct ieee_handle *info = (struct ieee_handle *) p; 07189 boolean referencep; 07190 unsigned int retindx, typeindx; 07191 07192 referencep = info->type_stack->type.referencep; 07193 retindx = ieee_pop_type (info); 07194 07195 /* Besides recording a BB4 or BB6 block, we record the type of the 07196 function in the BB1 typedef block. We can't write out the full 07197 type until we have seen all the parameters, so we accumulate it 07198 in info->fntype and info->fnargs. */ 07199 if (! ieee_buffer_emptyp (&info->fntype)) 07200 { 07201 /* FIXME: This might happen someday if we support nested 07202 functions. */ 07203 abort (); 07204 } 07205 07206 info->fnname = name; 07207 07208 /* An attribute of 0x40 means that the push mask is unknown. */ 07209 if (! ieee_define_named_type (info, name, (unsigned int) -1, 0, false, true, 07210 &info->fntype) 07211 || ! ieee_write_number (info, 'x') 07212 || ! ieee_write_number (info, 0x40) 07213 || ! ieee_write_number (info, 0) 07214 || ! ieee_write_number (info, 0) 07215 || ! ieee_write_number (info, retindx)) 07216 return false; 07217 07218 typeindx = ieee_pop_type (info); 07219 07220 if (! ieee_init_buffer (info, &info->fnargs)) 07221 return false; 07222 info->fnargcount = 0; 07223 07224 /* If the function return value is actually a reference type, we 07225 must add a record indicating that. */ 07226 if (referencep) 07227 { 07228 unsigned int nindx; 07229 07230 nindx = info->name_indx; 07231 ++info->name_indx; 07232 if (! ieee_change_buffer (info, &info->cxx) 07233 || ! ieee_write_byte (info, (int) ieee_nn_record) 07234 || ! ieee_write_number (info, nindx) 07235 || ! ieee_write_id (info, "") 07236 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum) 07237 || ! ieee_write_number (info, nindx) 07238 || ! ieee_write_number (info, 0) 07239 || ! ieee_write_number (info, 62) 07240 || ! ieee_write_number (info, 80) 07241 || ! ieee_write_number (info, 3) 07242 || ! ieee_write_asn (info, nindx, 'R') 07243 || ! ieee_write_asn (info, nindx, global ? 0 : 1) 07244 || ! ieee_write_atn65 (info, nindx, name)) 07245 return false; 07246 } 07247 07248 assert (! ieee_buffer_emptyp (&info->vars)); 07249 if (! ieee_change_buffer (info, &info->vars)) 07250 return false; 07251 07252 /* The address is written out as the first block. */ 07253 07254 ++info->block_depth; 07255 07256 return (ieee_write_byte (info, (int) ieee_bb_record_enum) 07257 && ieee_write_byte (info, global ? 4 : 6) 07258 && ieee_write_number (info, 0) 07259 && ieee_write_id (info, name) 07260 && ieee_write_number (info, 0) 07261 && ieee_write_number (info, typeindx)); 07262 } 07263 07264 /* Add a function parameter. This will normally be called before the 07265 first block, so we postpone them until we see the block. */ 07266 07267 static boolean 07268 ieee_function_parameter (p, name, kind, val) 07269 PTR p; 07270 const char *name; 07271 enum debug_parm_kind kind; 07272 bfd_vma val; 07273 { 07274 struct ieee_handle *info = (struct ieee_handle *) p; 07275 struct ieee_pending_parm *m, **pm; 07276 07277 assert (info->block_depth == 1); 07278 07279 m = (struct ieee_pending_parm *) xmalloc (sizeof *m); 07280 memset (m, 0, sizeof *m); 07281 07282 m->next = NULL; 07283 m->name = name; 07284 m->referencep = info->type_stack->type.referencep; 07285 m->type = ieee_pop_type (info); 07286 m->kind = kind; 07287 m->val = val; 07288 07289 for (pm = &info->pending_parms; *pm != NULL; pm = &(*pm)->next) 07290 ; 07291 *pm = m; 07292 07293 /* Add the type to the fnargs list. */ 07294 if (! ieee_change_buffer (info, &info->fnargs) 07295 || ! ieee_write_number (info, m->type)) 07296 return false; 07297 ++info->fnargcount; 07298 07299 return true; 07300 } 07301 07302 /* Output pending function parameters. */ 07303 07304 static boolean 07305 ieee_output_pending_parms (info) 07306 struct ieee_handle *info; 07307 { 07308 struct ieee_pending_parm *m; 07309 unsigned int refcount; 07310 07311 refcount = 0; 07312 for (m = info->pending_parms; m != NULL; m = m->next) 07313 { 07314 enum debug_var_kind vkind; 07315 07316 switch (m->kind) 07317 { 07318 default: 07319 abort (); 07320 return false; 07321 case DEBUG_PARM_STACK: 07322 case DEBUG_PARM_REFERENCE: 07323 vkind = DEBUG_LOCAL; 07324 break; 07325 case DEBUG_PARM_REG: 07326 case DEBUG_PARM_REF_REG: 07327 vkind = DEBUG_REGISTER; 07328 break; 07329 } 07330 07331 if (! ieee_push_type (info, m->type, 0, false, false)) 07332 return false; 07333 info->type_stack->type.referencep = m->referencep; 07334 if (m->referencep) 07335 ++refcount; 07336 if (! ieee_variable ((PTR) info, m->name, vkind, m->val)) 07337 return false; 07338 } 07339 07340 /* If there are any reference parameters, we need to output a 07341 miscellaneous record indicating them. */ 07342 if (refcount > 0) 07343 { 07344 unsigned int nindx, varindx; 07345 07346 /* FIXME: The MRI compiler outputs the demangled function name 07347 here, but we are outputting the mangled name. */ 07348 nindx = info->name_indx; 07349 ++info->name_indx; 07350 if (! ieee_change_buffer (info, &info->vars) 07351 || ! ieee_write_byte (info, (int) ieee_nn_record) 07352 || ! ieee_write_number (info, nindx) 07353 || ! ieee_write_id (info, "") 07354 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum) 07355 || ! ieee_write_number (info, nindx) 07356 || ! ieee_write_number (info, 0) 07357 || ! ieee_write_number (info, 62) 07358 || ! ieee_write_number (info, 80) 07359 || ! ieee_write_number (info, refcount + 3) 07360 || ! ieee_write_asn (info, nindx, 'B') 07361 || ! ieee_write_atn65 (info, nindx, info->fnname) 07362 || ! ieee_write_asn (info, nindx, 0)) 07363 return false; 07364 for (m = info->pending_parms, varindx = 1; 07365 m != NULL; 07366 m = m->next, varindx++) 07367 { 07368 if (m->referencep) 07369 { 07370 if (! ieee_write_asn (info, nindx, varindx)) 07371 return false; 07372 } 07373 } 07374 } 07375 07376 m = info->pending_parms; 07377 while (m != NULL) 07378 { 07379 struct ieee_pending_parm *next; 07380 07381 next = m->next; 07382 free (m); 07383 m = next; 07384 } 07385 07386 info->pending_parms = NULL; 07387 07388 return true; 07389 } 07390 07391 /* Start a block. If this is the first block, we output the address 07392 to finish the BB4 or BB6, and then output the function parameters. */ 07393 07394 static boolean 07395 ieee_start_block (p, addr) 07396 PTR p; 07397 bfd_vma addr; 07398 { 07399 struct ieee_handle *info = (struct ieee_handle *) p; 07400 07401 if (! ieee_change_buffer (info, &info->vars)) 07402 return false; 07403 07404 if (info->block_depth == 1) 07405 { 07406 if (! ieee_write_number (info, addr) 07407 || ! ieee_output_pending_parms (info)) 07408 return false; 07409 } 07410 else 07411 { 07412 if (! ieee_write_byte (info, (int) ieee_bb_record_enum) 07413 || ! ieee_write_byte (info, 6) 07414 || ! ieee_write_number (info, 0) 07415 || ! ieee_write_id (info, "") 07416 || ! ieee_write_number (info, 0) 07417 || ! ieee_write_number (info, 0) 07418 || ! ieee_write_number (info, addr)) 07419 return false; 07420 } 07421 07422 if (! ieee_start_range (info, addr)) 07423 return false; 07424 07425 ++info->block_depth; 07426 07427 return true; 07428 } 07429 07430 /* End a block. */ 07431 07432 static boolean 07433 ieee_end_block (p, addr) 07434 PTR p; 07435 bfd_vma addr; 07436 { 07437 struct ieee_handle *info = (struct ieee_handle *) p; 07438 07439 /* The address we are given is the end of the block, but IEEE seems 07440 to want to the address of the last byte in the block, so we 07441 subtract one. */ 07442 if (! ieee_change_buffer (info, &info->vars) 07443 || ! ieee_write_byte (info, (int) ieee_be_record_enum) 07444 || ! ieee_write_number (info, addr - 1)) 07445 return false; 07446 07447 if (! ieee_end_range (info, addr)) 07448 return false; 07449 07450 --info->block_depth; 07451 07452 if (addr > info->highaddr) 07453 info->highaddr = addr; 07454 07455 return true; 07456 } 07457 07458 /* End a function. */ 07459 07460 static boolean 07461 ieee_end_function (p) 07462 PTR p; 07463 { 07464 struct ieee_handle *info = (struct ieee_handle *) p; 07465 07466 assert (info->block_depth == 1); 07467 07468 --info->block_depth; 07469 07470 /* Now we can finish up fntype, and add it to the typdef section. 07471 At this point, fntype is the 'x' type up to the argument count, 07472 and fnargs is the argument types. We must add the argument 07473 count, and we must add the level. FIXME: We don't record varargs 07474 functions correctly. In fact, stabs debugging does not give us 07475 enough information to do so. */ 07476 if (! ieee_change_buffer (info, &info->fntype) 07477 || ! ieee_write_number (info, info->fnargcount) 07478 || ! ieee_change_buffer (info, &info->fnargs) 07479 || ! ieee_write_number (info, 0)) 07480 return false; 07481 07482 /* Make sure the typdef block has been started. */ 07483 if (ieee_buffer_emptyp (&info->types)) 07484 { 07485 if (! ieee_change_buffer (info, &info->types) 07486 || ! ieee_write_byte (info, (int) ieee_bb_record_enum) 07487 || ! ieee_write_byte (info, 1) 07488 || ! ieee_write_number (info, 0) 07489 || ! ieee_write_id (info, info->modname)) 07490 return false; 07491 } 07492 07493 if (! ieee_append_buffer (info, &info->types, &info->fntype) 07494 || ! ieee_append_buffer (info, &info->types, &info->fnargs)) 07495 return false; 07496 07497 info->fnname = NULL; 07498 if (! ieee_init_buffer (info, &info->fntype) 07499 || ! ieee_init_buffer (info, &info->fnargs)) 07500 return false; 07501 info->fnargcount = 0; 07502 07503 return true; 07504 } 07505 07506 /* Record line number information. */ 07507 07508 static boolean 07509 ieee_lineno (p, filename, lineno, addr) 07510 PTR p; 07511 const char *filename; 07512 unsigned long lineno; 07513 bfd_vma addr; 07514 { 07515 struct ieee_handle *info = (struct ieee_handle *) p; 07516 07517 assert (info->filename != NULL); 07518 07519 /* The HP simulator seems to get confused when more than one line is 07520 listed for the same address, at least if they are in different 07521 files. We handle this by always listing the last line for a 07522 given address, since that seems to be the one that gdb uses. */ 07523 if (info->pending_lineno_filename != NULL 07524 && addr != info->pending_lineno_addr) 07525 { 07526 /* Make sure we have a line number block. */ 07527 if (! ieee_buffer_emptyp (&info->linenos)) 07528 { 07529 if (! ieee_change_buffer (info, &info->linenos)) 07530 return false; 07531 } 07532 else 07533 { 07534 info->lineno_name_indx = info->name_indx; 07535 ++info->name_indx; 07536 if (! ieee_change_buffer (info, &info->linenos) 07537 || ! ieee_write_byte (info, (int) ieee_bb_record_enum) 07538 || ! ieee_write_byte (info, 5) 07539 || ! ieee_write_number (info, 0) 07540 || ! ieee_write_id (info, info->filename) 07541 || ! ieee_write_byte (info, (int) ieee_nn_record) 07542 || ! ieee_write_number (info, info->lineno_name_indx) 07543 || ! ieee_write_id (info, "")) 07544 return false; 07545 info->lineno_filename = info->filename; 07546 } 07547 07548 if (strcmp (info->pending_lineno_filename, info->lineno_filename) != 0) 07549 { 07550 if (strcmp (info->filename, info->lineno_filename) != 0) 07551 { 07552 /* We were not in the main file. Close the block for the 07553 included file. */ 07554 if (! ieee_write_byte (info, (int) ieee_be_record_enum)) 07555 return false; 07556 if (strcmp (info->filename, info->pending_lineno_filename) == 0) 07557 { 07558 /* We need a new NN record, and we aren't about to 07559 output one. */ 07560 info->lineno_name_indx = info->name_indx; 07561 ++info->name_indx; 07562 if (! ieee_write_byte (info, (int) ieee_nn_record) 07563 || ! ieee_write_number (info, info->lineno_name_indx) 07564 || ! ieee_write_id (info, "")) 07565 return false; 07566 } 07567 } 07568 if (strcmp (info->filename, info->pending_lineno_filename) != 0) 07569 { 07570 /* We are not changing to the main file. Open a block for 07571 the new included file. */ 07572 info->lineno_name_indx = info->name_indx; 07573 ++info->name_indx; 07574 if (! ieee_write_byte (info, (int) ieee_bb_record_enum) 07575 || ! ieee_write_byte (info, 5) 07576 || ! ieee_write_number (info, 0) 07577 || ! ieee_write_id (info, info->pending_lineno_filename) 07578 || ! ieee_write_byte (info, (int) ieee_nn_record) 07579 || ! ieee_write_number (info, info->lineno_name_indx) 07580 || ! ieee_write_id (info, "")) 07581 return false; 07582 } 07583 info->lineno_filename = info->pending_lineno_filename; 07584 } 07585 07586 if (! ieee_write_2bytes (info, (int) ieee_atn_record_enum) 07587 || ! ieee_write_number (info, info->lineno_name_indx) 07588 || ! ieee_write_number (info, 0) 07589 || ! ieee_write_number (info, 7) 07590 || ! ieee_write_number (info, info->pending_lineno) 07591 || ! ieee_write_number (info, 0) 07592 || ! ieee_write_asn (info, info->lineno_name_indx, 07593 info->pending_lineno_addr)) 07594 return false; 07595 } 07596 07597 info->pending_lineno_filename = filename; 07598 info->pending_lineno = lineno; 07599 info->pending_lineno_addr = addr; 07600 07601 return true; 07602 }
1.4.7

