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