OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [dwarfread.c] - Diff between revs 105 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 105 Rev 1765
/* DWARF debugging format support for GDB.
/* DWARF debugging format support for GDB.
   Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1998
   Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1998
   Free Software Foundation, Inc.
   Free Software Foundation, Inc.
   Written by Fred Fish at Cygnus Support.  Portions based on dbxread.c,
   Written by Fred Fish at Cygnus Support.  Portions based on dbxread.c,
   mipsread.c, coffread.c, and dwarfread.c from a Data General SVR4 gdb port.
   mipsread.c, coffread.c, and dwarfread.c from a Data General SVR4 gdb port.
 
 
   This file is part of GDB.
   This file is part of GDB.
 
 
   This program is free software; you can redistribute it and/or modify
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   (at your option) any later version.
 
 
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 
/*
/*
 
 
   FIXME: Do we need to generate dependencies in partial symtabs?
   FIXME: Do we need to generate dependencies in partial symtabs?
   (Perhaps we don't need to).
   (Perhaps we don't need to).
 
 
   FIXME: Resolve minor differences between what information we put in the
   FIXME: Resolve minor differences between what information we put in the
   partial symbol table and what dbxread puts in.  For example, we don't yet
   partial symbol table and what dbxread puts in.  For example, we don't yet
   put enum constants there.  And dbxread seems to invent a lot of typedefs
   put enum constants there.  And dbxread seems to invent a lot of typedefs
   we never see.  Use the new printpsym command to see the partial symbol table
   we never see.  Use the new printpsym command to see the partial symbol table
   contents.
   contents.
 
 
   FIXME: Figure out a better way to tell gdb about the name of the function
   FIXME: Figure out a better way to tell gdb about the name of the function
   contain the user's entry point (I.E. main())
   contain the user's entry point (I.E. main())
 
 
   FIXME: See other FIXME's and "ifdef 0" scattered throughout the code for
   FIXME: See other FIXME's and "ifdef 0" scattered throughout the code for
   other things to work on, if you get bored. :-)
   other things to work on, if you get bored. :-)
 
 
 */
 */
 
 
#include "defs.h"
#include "defs.h"
#include "symtab.h"
#include "symtab.h"
#include "gdbtypes.h"
#include "gdbtypes.h"
#include "symfile.h"
#include "symfile.h"
#include "objfiles.h"
#include "objfiles.h"
#include "elf/dwarf.h"
#include "elf/dwarf.h"
#include "buildsym.h"
#include "buildsym.h"
#include "demangle.h"
#include "demangle.h"
#include "expression.h"         /* Needed for enum exp_opcode in language.h, sigh... */
#include "expression.h"         /* Needed for enum exp_opcode in language.h, sigh... */
#include "language.h"
#include "language.h"
#include "complaints.h"
#include "complaints.h"
 
 
#include <fcntl.h>
#include <fcntl.h>
#include "gdb_string.h"
#include "gdb_string.h"
 
 
/* Some macros to provide DIE info for complaints. */
/* Some macros to provide DIE info for complaints. */
 
 
#define DIE_ID (curdie!=NULL ? curdie->die_ref : 0)
#define DIE_ID (curdie!=NULL ? curdie->die_ref : 0)
#define DIE_NAME (curdie!=NULL && curdie->at_name!=NULL) ? curdie->at_name : ""
#define DIE_NAME (curdie!=NULL && curdie->at_name!=NULL) ? curdie->at_name : ""
 
 
/* Complaints that can be issued during DWARF debug info reading. */
/* Complaints that can be issued during DWARF debug info reading. */
 
 
struct complaint no_bfd_get_N =
struct complaint no_bfd_get_N =
{
{
  "DIE @ 0x%x \"%s\", no bfd support for %d byte data object", 0, 0
  "DIE @ 0x%x \"%s\", no bfd support for %d byte data object", 0, 0
};
};
 
 
struct complaint malformed_die =
struct complaint malformed_die =
{
{
  "DIE @ 0x%x \"%s\", malformed DIE, bad length (%d bytes)", 0, 0
  "DIE @ 0x%x \"%s\", malformed DIE, bad length (%d bytes)", 0, 0
};
};
 
 
struct complaint bad_die_ref =
struct complaint bad_die_ref =
{
{
  "DIE @ 0x%x \"%s\", reference to DIE (0x%x) outside compilation unit", 0, 0
  "DIE @ 0x%x \"%s\", reference to DIE (0x%x) outside compilation unit", 0, 0
};
};
 
 
struct complaint unknown_attribute_form =
struct complaint unknown_attribute_form =
{
{
  "DIE @ 0x%x \"%s\", unknown attribute form (0x%x)", 0, 0
  "DIE @ 0x%x \"%s\", unknown attribute form (0x%x)", 0, 0
};
};
 
 
struct complaint unknown_attribute_length =
struct complaint unknown_attribute_length =
{
{
  "DIE @ 0x%x \"%s\", unknown attribute length, skipped remaining attributes", 0, 0
  "DIE @ 0x%x \"%s\", unknown attribute length, skipped remaining attributes", 0, 0
};
};
 
 
struct complaint unexpected_fund_type =
struct complaint unexpected_fund_type =
{
{
  "DIE @ 0x%x \"%s\", unexpected fundamental type 0x%x", 0, 0
  "DIE @ 0x%x \"%s\", unexpected fundamental type 0x%x", 0, 0
};
};
 
 
struct complaint unknown_type_modifier =
struct complaint unknown_type_modifier =
{
{
  "DIE @ 0x%x \"%s\", unknown type modifier %u", 0, 0
  "DIE @ 0x%x \"%s\", unknown type modifier %u", 0, 0
};
};
 
 
struct complaint volatile_ignored =
struct complaint volatile_ignored =
{
{
  "DIE @ 0x%x \"%s\", type modifier 'volatile' ignored", 0, 0
  "DIE @ 0x%x \"%s\", type modifier 'volatile' ignored", 0, 0
};
};
 
 
struct complaint const_ignored =
struct complaint const_ignored =
{
{
  "DIE @ 0x%x \"%s\", type modifier 'const' ignored", 0, 0
  "DIE @ 0x%x \"%s\", type modifier 'const' ignored", 0, 0
};
};
 
 
struct complaint botched_modified_type =
struct complaint botched_modified_type =
{
{
  "DIE @ 0x%x \"%s\", botched modified type decoding (mtype 0x%x)", 0, 0
  "DIE @ 0x%x \"%s\", botched modified type decoding (mtype 0x%x)", 0, 0
};
};
 
 
struct complaint op_deref2 =
struct complaint op_deref2 =
{
{
  "DIE @ 0x%x \"%s\", OP_DEREF2 address 0x%x not handled", 0, 0
  "DIE @ 0x%x \"%s\", OP_DEREF2 address 0x%x not handled", 0, 0
};
};
 
 
struct complaint op_deref4 =
struct complaint op_deref4 =
{
{
  "DIE @ 0x%x \"%s\", OP_DEREF4 address 0x%x not handled", 0, 0
  "DIE @ 0x%x \"%s\", OP_DEREF4 address 0x%x not handled", 0, 0
};
};
 
 
struct complaint basereg_not_handled =
struct complaint basereg_not_handled =
{
{
  "DIE @ 0x%x \"%s\", BASEREG %d not handled", 0, 0
  "DIE @ 0x%x \"%s\", BASEREG %d not handled", 0, 0
};
};
 
 
struct complaint dup_user_type_allocation =
struct complaint dup_user_type_allocation =
{
{
  "DIE @ 0x%x \"%s\", internal error: duplicate user type allocation", 0, 0
  "DIE @ 0x%x \"%s\", internal error: duplicate user type allocation", 0, 0
};
};
 
 
struct complaint dup_user_type_definition =
struct complaint dup_user_type_definition =
{
{
  "DIE @ 0x%x \"%s\", internal error: duplicate user type definition", 0, 0
  "DIE @ 0x%x \"%s\", internal error: duplicate user type definition", 0, 0
};
};
 
 
struct complaint missing_tag =
struct complaint missing_tag =
{
{
  "DIE @ 0x%x \"%s\", missing class, structure, or union tag", 0, 0
  "DIE @ 0x%x \"%s\", missing class, structure, or union tag", 0, 0
};
};
 
 
struct complaint bad_array_element_type =
struct complaint bad_array_element_type =
{
{
  "DIE @ 0x%x \"%s\", bad array element type attribute 0x%x", 0, 0
  "DIE @ 0x%x \"%s\", bad array element type attribute 0x%x", 0, 0
};
};
 
 
struct complaint subscript_data_items =
struct complaint subscript_data_items =
{
{
  "DIE @ 0x%x \"%s\", can't decode subscript data items", 0, 0
  "DIE @ 0x%x \"%s\", can't decode subscript data items", 0, 0
};
};
 
 
struct complaint unhandled_array_subscript_format =
struct complaint unhandled_array_subscript_format =
{
{
  "DIE @ 0x%x \"%s\", array subscript format 0x%x not handled yet", 0, 0
  "DIE @ 0x%x \"%s\", array subscript format 0x%x not handled yet", 0, 0
};
};
 
 
struct complaint unknown_array_subscript_format =
struct complaint unknown_array_subscript_format =
{
{
  "DIE @ 0x%x \"%s\", unknown array subscript format %x", 0, 0
  "DIE @ 0x%x \"%s\", unknown array subscript format %x", 0, 0
};
};
 
 
struct complaint not_row_major =
struct complaint not_row_major =
{
{
  "DIE @ 0x%x \"%s\", array not row major; not handled correctly", 0, 0
  "DIE @ 0x%x \"%s\", array not row major; not handled correctly", 0, 0
};
};
 
 
struct complaint missing_at_name =
struct complaint missing_at_name =
{
{
  "DIE @ 0x%x, AT_name tag missing", 0, 0
  "DIE @ 0x%x, AT_name tag missing", 0, 0
};
};
 
 
typedef unsigned int DIE_REF;   /* Reference to a DIE */
typedef unsigned int DIE_REF;   /* Reference to a DIE */
 
 
#ifndef GCC_PRODUCER
#ifndef GCC_PRODUCER
#define GCC_PRODUCER "GNU C "
#define GCC_PRODUCER "GNU C "
#endif
#endif
 
 
#ifndef GPLUS_PRODUCER
#ifndef GPLUS_PRODUCER
#define GPLUS_PRODUCER "GNU C++ "
#define GPLUS_PRODUCER "GNU C++ "
#endif
#endif
 
 
#ifndef LCC_PRODUCER
#ifndef LCC_PRODUCER
#define LCC_PRODUCER "NCR C/C++"
#define LCC_PRODUCER "NCR C/C++"
#endif
#endif
 
 
#ifndef CHILL_PRODUCER
#ifndef CHILL_PRODUCER
#define CHILL_PRODUCER "GNU Chill "
#define CHILL_PRODUCER "GNU Chill "
#endif
#endif
 
 
/* Provide a default mapping from a DWARF register number to a gdb REGNUM.  */
/* Provide a default mapping from a DWARF register number to a gdb REGNUM.  */
#ifndef DWARF_REG_TO_REGNUM
#ifndef DWARF_REG_TO_REGNUM
#define DWARF_REG_TO_REGNUM(num) (num)
#define DWARF_REG_TO_REGNUM(num) (num)
#endif
#endif
 
 
/* Flags to target_to_host() that tell whether or not the data object is
/* Flags to target_to_host() that tell whether or not the data object is
   expected to be signed.  Used, for example, when fetching a signed
   expected to be signed.  Used, for example, when fetching a signed
   integer in the target environment which is used as a signed integer
   integer in the target environment which is used as a signed integer
   in the host environment, and the two environments have different sized
   in the host environment, and the two environments have different sized
   ints.  In this case, *somebody* has to sign extend the smaller sized
   ints.  In this case, *somebody* has to sign extend the smaller sized
   int. */
   int. */
 
 
#define GET_UNSIGNED    0        /* No sign extension required */
#define GET_UNSIGNED    0        /* No sign extension required */
#define GET_SIGNED      1       /* Sign extension required */
#define GET_SIGNED      1       /* Sign extension required */
 
 
/* Defines for things which are specified in the document "DWARF Debugging
/* Defines for things which are specified in the document "DWARF Debugging
   Information Format" published by UNIX International, Programming Languages
   Information Format" published by UNIX International, Programming Languages
   SIG.  These defines are based on revision 1.0.0, Jan 20, 1992. */
   SIG.  These defines are based on revision 1.0.0, Jan 20, 1992. */
 
 
#define SIZEOF_DIE_LENGTH       4
#define SIZEOF_DIE_LENGTH       4
#define SIZEOF_DIE_TAG          2
#define SIZEOF_DIE_TAG          2
#define SIZEOF_ATTRIBUTE        2
#define SIZEOF_ATTRIBUTE        2
#define SIZEOF_FORMAT_SPECIFIER 1
#define SIZEOF_FORMAT_SPECIFIER 1
#define SIZEOF_FMT_FT           2
#define SIZEOF_FMT_FT           2
#define SIZEOF_LINETBL_LENGTH   4
#define SIZEOF_LINETBL_LENGTH   4
#define SIZEOF_LINETBL_LINENO   4
#define SIZEOF_LINETBL_LINENO   4
#define SIZEOF_LINETBL_STMT     2
#define SIZEOF_LINETBL_STMT     2
#define SIZEOF_LINETBL_DELTA    4
#define SIZEOF_LINETBL_DELTA    4
#define SIZEOF_LOC_ATOM_CODE    1
#define SIZEOF_LOC_ATOM_CODE    1
 
 
#define FORM_FROM_ATTR(attr)    ((attr) & 0xF)  /* Implicitly specified */
#define FORM_FROM_ATTR(attr)    ((attr) & 0xF)  /* Implicitly specified */
 
 
/* Macros that return the sizes of various types of data in the target
/* Macros that return the sizes of various types of data in the target
   environment.
   environment.
 
 
   FIXME:  Currently these are just compile time constants (as they are in
   FIXME:  Currently these are just compile time constants (as they are in
   other parts of gdb as well).  They need to be able to get the right size
   other parts of gdb as well).  They need to be able to get the right size
   either from the bfd or possibly from the DWARF info.  It would be nice if
   either from the bfd or possibly from the DWARF info.  It would be nice if
   the DWARF producer inserted DIES that describe the fundamental types in
   the DWARF producer inserted DIES that describe the fundamental types in
   the target environment into the DWARF info, similar to the way dbx stabs
   the target environment into the DWARF info, similar to the way dbx stabs
   producers produce information about their fundamental types. */
   producers produce information about their fundamental types. */
 
 
#define TARGET_FT_POINTER_SIZE(objfile) (TARGET_PTR_BIT / TARGET_CHAR_BIT)
#define TARGET_FT_POINTER_SIZE(objfile) (TARGET_PTR_BIT / TARGET_CHAR_BIT)
#define TARGET_FT_LONG_SIZE(objfile)    (TARGET_LONG_BIT / TARGET_CHAR_BIT)
#define TARGET_FT_LONG_SIZE(objfile)    (TARGET_LONG_BIT / TARGET_CHAR_BIT)
 
 
/* The Amiga SVR4 header file <dwarf.h> defines AT_element_list as a
/* The Amiga SVR4 header file <dwarf.h> defines AT_element_list as a
   FORM_BLOCK2, and this is the value emitted by the AT&T compiler.
   FORM_BLOCK2, and this is the value emitted by the AT&T compiler.
   However, the Issue 2 DWARF specification from AT&T defines it as
   However, the Issue 2 DWARF specification from AT&T defines it as
   a FORM_BLOCK4, as does the latest specification from UI/PLSIG.
   a FORM_BLOCK4, as does the latest specification from UI/PLSIG.
   For backwards compatibility with the AT&T compiler produced executables
   For backwards compatibility with the AT&T compiler produced executables
   we define AT_short_element_list for this variant. */
   we define AT_short_element_list for this variant. */
 
 
#define AT_short_element_list    (0x00f0|FORM_BLOCK2)
#define AT_short_element_list    (0x00f0|FORM_BLOCK2)
 
 
/* External variables referenced. */
/* External variables referenced. */
 
 
extern int info_verbose;        /* From main.c; nonzero => verbose */
extern int info_verbose;        /* From main.c; nonzero => verbose */
extern char *warning_pre_print; /* From utils.c */
extern char *warning_pre_print; /* From utils.c */
 
 
/* The DWARF debugging information consists of two major pieces,
/* The DWARF debugging information consists of two major pieces,
   one is a block of DWARF Information Entries (DIE's) and the other
   one is a block of DWARF Information Entries (DIE's) and the other
   is a line number table.  The "struct dieinfo" structure contains
   is a line number table.  The "struct dieinfo" structure contains
   the information for a single DIE, the one currently being processed.
   the information for a single DIE, the one currently being processed.
 
 
   In order to make it easier to randomly access the attribute fields
   In order to make it easier to randomly access the attribute fields
   of the current DIE, which are specifically unordered within the DIE,
   of the current DIE, which are specifically unordered within the DIE,
   each DIE is scanned and an instance of the "struct dieinfo"
   each DIE is scanned and an instance of the "struct dieinfo"
   structure is initialized.
   structure is initialized.
 
 
   Initialization is done in two levels.  The first, done by basicdieinfo(),
   Initialization is done in two levels.  The first, done by basicdieinfo(),
   just initializes those fields that are vital to deciding whether or not
   just initializes those fields that are vital to deciding whether or not
   to use this DIE, how to skip past it, etc.  The second, done by the
   to use this DIE, how to skip past it, etc.  The second, done by the
   function completedieinfo(), fills in the rest of the information.
   function completedieinfo(), fills in the rest of the information.
 
 
   Attributes which have block forms are not interpreted at the time
   Attributes which have block forms are not interpreted at the time
   the DIE is scanned, instead we just save pointers to the start
   the DIE is scanned, instead we just save pointers to the start
   of their value fields.
   of their value fields.
 
 
   Some fields have a flag <name>_p that is set when the value of the
   Some fields have a flag <name>_p that is set when the value of the
   field is valid (I.E. we found a matching attribute in the DIE).  Since
   field is valid (I.E. we found a matching attribute in the DIE).  Since
   we may want to test for the presence of some attributes in the DIE,
   we may want to test for the presence of some attributes in the DIE,
   such as AT_low_pc, without restricting the values of the field,
   such as AT_low_pc, without restricting the values of the field,
   we need someway to note that we found such an attribute.
   we need someway to note that we found such an attribute.
 
 
 */
 */
 
 
typedef char BLOCK;
typedef char BLOCK;
 
 
struct dieinfo
struct dieinfo
  {
  {
    char *die;                  /* Pointer to the raw DIE data */
    char *die;                  /* Pointer to the raw DIE data */
    unsigned long die_length;   /* Length of the raw DIE data */
    unsigned long die_length;   /* Length of the raw DIE data */
    DIE_REF die_ref;            /* Offset of this DIE */
    DIE_REF die_ref;            /* Offset of this DIE */
    unsigned short die_tag;     /* Tag for this DIE */
    unsigned short die_tag;     /* Tag for this DIE */
    unsigned long at_padding;
    unsigned long at_padding;
    unsigned long at_sibling;
    unsigned long at_sibling;
    BLOCK *at_location;
    BLOCK *at_location;
    char *at_name;
    char *at_name;
    unsigned short at_fund_type;
    unsigned short at_fund_type;
    BLOCK *at_mod_fund_type;
    BLOCK *at_mod_fund_type;
    unsigned long at_user_def_type;
    unsigned long at_user_def_type;
    BLOCK *at_mod_u_d_type;
    BLOCK *at_mod_u_d_type;
    unsigned short at_ordering;
    unsigned short at_ordering;
    BLOCK *at_subscr_data;
    BLOCK *at_subscr_data;
    unsigned long at_byte_size;
    unsigned long at_byte_size;
    unsigned short at_bit_offset;
    unsigned short at_bit_offset;
    unsigned long at_bit_size;
    unsigned long at_bit_size;
    BLOCK *at_element_list;
    BLOCK *at_element_list;
    unsigned long at_stmt_list;
    unsigned long at_stmt_list;
    CORE_ADDR at_low_pc;
    CORE_ADDR at_low_pc;
    CORE_ADDR at_high_pc;
    CORE_ADDR at_high_pc;
    unsigned long at_language;
    unsigned long at_language;
    unsigned long at_member;
    unsigned long at_member;
    unsigned long at_discr;
    unsigned long at_discr;
    BLOCK *at_discr_value;
    BLOCK *at_discr_value;
    BLOCK *at_string_length;
    BLOCK *at_string_length;
    char *at_comp_dir;
    char *at_comp_dir;
    char *at_producer;
    char *at_producer;
    unsigned long at_start_scope;
    unsigned long at_start_scope;
    unsigned long at_stride_size;
    unsigned long at_stride_size;
    unsigned long at_src_info;
    unsigned long at_src_info;
    char *at_prototyped;
    char *at_prototyped;
    unsigned int has_at_low_pc:1;
    unsigned int has_at_low_pc:1;
    unsigned int has_at_stmt_list:1;
    unsigned int has_at_stmt_list:1;
    unsigned int has_at_byte_size:1;
    unsigned int has_at_byte_size:1;
    unsigned int short_element_list:1;
    unsigned int short_element_list:1;
 
 
    /* Kludge to identify register variables */
    /* Kludge to identify register variables */
 
 
    unsigned int isreg;
    unsigned int isreg;
 
 
    /* Kludge to identify optimized out variables */
    /* Kludge to identify optimized out variables */
 
 
    unsigned int optimized_out;
    unsigned int optimized_out;
 
 
    /* Kludge to identify basereg references.
    /* Kludge to identify basereg references.
       Nonzero if we have an offset relative to a basereg.  */
       Nonzero if we have an offset relative to a basereg.  */
 
 
    unsigned int offreg;
    unsigned int offreg;
 
 
    /* Kludge to identify which base register is it relative to.  */
    /* Kludge to identify which base register is it relative to.  */
 
 
    unsigned int basereg;
    unsigned int basereg;
  };
  };
 
 
static int diecount;            /* Approximate count of dies for compilation unit */
static int diecount;            /* Approximate count of dies for compilation unit */
static struct dieinfo *curdie;  /* For warnings and such */
static struct dieinfo *curdie;  /* For warnings and such */
 
 
static char *dbbase;            /* Base pointer to dwarf info */
static char *dbbase;            /* Base pointer to dwarf info */
static int dbsize;              /* Size of dwarf info in bytes */
static int dbsize;              /* Size of dwarf info in bytes */
static int dbroff;              /* Relative offset from start of .debug section */
static int dbroff;              /* Relative offset from start of .debug section */
static char *lnbase;            /* Base pointer to line section */
static char *lnbase;            /* Base pointer to line section */
 
 
/* This value is added to each symbol value.  FIXME:  Generalize to
/* This value is added to each symbol value.  FIXME:  Generalize to
   the section_offsets structure used by dbxread (once this is done,
   the section_offsets structure used by dbxread (once this is done,
   pass the appropriate section number to end_symtab).  */
   pass the appropriate section number to end_symtab).  */
static CORE_ADDR baseaddr;      /* Add to each symbol value */
static CORE_ADDR baseaddr;      /* Add to each symbol value */
 
 
/* The section offsets used in the current psymtab or symtab.  FIXME,
/* The section offsets used in the current psymtab or symtab.  FIXME,
   only used to pass one value (baseaddr) at the moment.  */
   only used to pass one value (baseaddr) at the moment.  */
static struct section_offsets *base_section_offsets;
static struct section_offsets *base_section_offsets;
 
 
/* We put a pointer to this structure in the read_symtab_private field
/* We put a pointer to this structure in the read_symtab_private field
   of the psymtab.  */
   of the psymtab.  */
 
 
struct dwfinfo
struct dwfinfo
  {
  {
    /* Always the absolute file offset to the start of the ".debug"
    /* Always the absolute file offset to the start of the ".debug"
       section for the file containing the DIE's being accessed.  */
       section for the file containing the DIE's being accessed.  */
    file_ptr dbfoff;
    file_ptr dbfoff;
    /* Relative offset from the start of the ".debug" section to the
    /* Relative offset from the start of the ".debug" section to the
       first DIE to be accessed.  When building the partial symbol
       first DIE to be accessed.  When building the partial symbol
       table, this value will be zero since we are accessing the
       table, this value will be zero since we are accessing the
       entire ".debug" section.  When expanding a partial symbol
       entire ".debug" section.  When expanding a partial symbol
       table entry, this value will be the offset to the first
       table entry, this value will be the offset to the first
       DIE for the compilation unit containing the symbol that
       DIE for the compilation unit containing the symbol that
       triggers the expansion.  */
       triggers the expansion.  */
    int dbroff;
    int dbroff;
    /* The size of the chunk of DIE's being examined, in bytes.  */
    /* The size of the chunk of DIE's being examined, in bytes.  */
    int dblength;
    int dblength;
    /* The absolute file offset to the line table fragment.  Ignored
    /* The absolute file offset to the line table fragment.  Ignored
       when building partial symbol tables, but used when expanding
       when building partial symbol tables, but used when expanding
       them, and contains the absolute file offset to the fragment
       them, and contains the absolute file offset to the fragment
       of the ".line" section containing the line numbers for the
       of the ".line" section containing the line numbers for the
       current compilation unit.  */
       current compilation unit.  */
    file_ptr lnfoff;
    file_ptr lnfoff;
  };
  };
 
 
#define DBFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbfoff)
#define DBFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbfoff)
#define DBROFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbroff)
#define DBROFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbroff)
#define DBLENGTH(p) (((struct dwfinfo *)((p)->read_symtab_private))->dblength)
#define DBLENGTH(p) (((struct dwfinfo *)((p)->read_symtab_private))->dblength)
#define LNFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->lnfoff)
#define LNFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->lnfoff)
 
 
/* The generic symbol table building routines have separate lists for
/* The generic symbol table building routines have separate lists for
   file scope symbols and all all other scopes (local scopes).  So
   file scope symbols and all all other scopes (local scopes).  So
   we need to select the right one to pass to add_symbol_to_list().
   we need to select the right one to pass to add_symbol_to_list().
   We do it by keeping a pointer to the correct list in list_in_scope.
   We do it by keeping a pointer to the correct list in list_in_scope.
 
 
   FIXME:  The original dwarf code just treated the file scope as the first
   FIXME:  The original dwarf code just treated the file scope as the first
   local scope, and all other local scopes as nested local scopes, and worked
   local scope, and all other local scopes as nested local scopes, and worked
   fine.  Check to see if we really need to distinguish these in buildsym.c */
   fine.  Check to see if we really need to distinguish these in buildsym.c */
 
 
struct pending **list_in_scope = &file_symbols;
struct pending **list_in_scope = &file_symbols;
 
 
/* DIES which have user defined types or modified user defined types refer to
/* DIES which have user defined types or modified user defined types refer to
   other DIES for the type information.  Thus we need to associate the offset
   other DIES for the type information.  Thus we need to associate the offset
   of a DIE for a user defined type with a pointer to the type information.
   of a DIE for a user defined type with a pointer to the type information.
 
 
   Originally this was done using a simple but expensive algorithm, with an
   Originally this was done using a simple but expensive algorithm, with an
   array of unsorted structures, each containing an offset/type-pointer pair.
   array of unsorted structures, each containing an offset/type-pointer pair.
   This array was scanned linearly each time a lookup was done.  The result
   This array was scanned linearly each time a lookup was done.  The result
   was that gdb was spending over half it's startup time munging through this
   was that gdb was spending over half it's startup time munging through this
   array of pointers looking for a structure that had the right offset member.
   array of pointers looking for a structure that had the right offset member.
 
 
   The second attempt used the same array of structures, but the array was
   The second attempt used the same array of structures, but the array was
   sorted using qsort each time a new offset/type was recorded, and a binary
   sorted using qsort each time a new offset/type was recorded, and a binary
   search was used to find the type pointer for a given DIE offset.  This was
   search was used to find the type pointer for a given DIE offset.  This was
   even slower, due to the overhead of sorting the array each time a new
   even slower, due to the overhead of sorting the array each time a new
   offset/type pair was entered.
   offset/type pair was entered.
 
 
   The third attempt uses a fixed size array of type pointers, indexed by a
   The third attempt uses a fixed size array of type pointers, indexed by a
   value derived from the DIE offset.  Since the minimum DIE size is 4 bytes,
   value derived from the DIE offset.  Since the minimum DIE size is 4 bytes,
   we can divide any DIE offset by 4 to obtain a unique index into this fixed
   we can divide any DIE offset by 4 to obtain a unique index into this fixed
   size array.  Since each element is a 4 byte pointer, it takes exactly as
   size array.  Since each element is a 4 byte pointer, it takes exactly as
   much memory to hold this array as to hold the DWARF info for a given
   much memory to hold this array as to hold the DWARF info for a given
   compilation unit.  But it gets freed as soon as we are done with it.
   compilation unit.  But it gets freed as soon as we are done with it.
   This has worked well in practice, as a reasonable tradeoff between memory
   This has worked well in practice, as a reasonable tradeoff between memory
   consumption and speed, without having to resort to much more complicated
   consumption and speed, without having to resort to much more complicated
   algorithms. */
   algorithms. */
 
 
static struct type **utypes;    /* Pointer to array of user type pointers */
static struct type **utypes;    /* Pointer to array of user type pointers */
static int numutypes;           /* Max number of user type pointers */
static int numutypes;           /* Max number of user type pointers */
 
 
/* Maintain an array of referenced fundamental types for the current
/* Maintain an array of referenced fundamental types for the current
   compilation unit being read.  For DWARF version 1, we have to construct
   compilation unit being read.  For DWARF version 1, we have to construct
   the fundamental types on the fly, since no information about the
   the fundamental types on the fly, since no information about the
   fundamental types is supplied.  Each such fundamental type is created by
   fundamental types is supplied.  Each such fundamental type is created by
   calling a language dependent routine to create the type, and then a
   calling a language dependent routine to create the type, and then a
   pointer to that type is then placed in the array at the index specified
   pointer to that type is then placed in the array at the index specified
   by it's FT_<TYPENAME> value.  The array has a fixed size set by the
   by it's FT_<TYPENAME> value.  The array has a fixed size set by the
   FT_NUM_MEMBERS compile time constant, which is the number of predefined
   FT_NUM_MEMBERS compile time constant, which is the number of predefined
   fundamental types gdb knows how to construct. */
   fundamental types gdb knows how to construct. */
 
 
static struct type *ftypes[FT_NUM_MEMBERS];     /* Fundamental types */
static struct type *ftypes[FT_NUM_MEMBERS];     /* Fundamental types */
 
 
/* Record the language for the compilation unit which is currently being
/* Record the language for the compilation unit which is currently being
   processed.  We know it once we have seen the TAG_compile_unit DIE,
   processed.  We know it once we have seen the TAG_compile_unit DIE,
   and we need it while processing the DIE's for that compilation unit.
   and we need it while processing the DIE's for that compilation unit.
   It is eventually saved in the symtab structure, but we don't finalize
   It is eventually saved in the symtab structure, but we don't finalize
   the symtab struct until we have processed all the DIE's for the
   the symtab struct until we have processed all the DIE's for the
   compilation unit.  We also need to get and save a pointer to the
   compilation unit.  We also need to get and save a pointer to the
   language struct for this language, so we can call the language
   language struct for this language, so we can call the language
   dependent routines for doing things such as creating fundamental
   dependent routines for doing things such as creating fundamental
   types. */
   types. */
 
 
static enum language cu_language;
static enum language cu_language;
static const struct language_defn *cu_language_defn;
static const struct language_defn *cu_language_defn;
 
 
/* Forward declarations of static functions so we don't have to worry
/* Forward declarations of static functions so we don't have to worry
   about ordering within this file.  */
   about ordering within this file.  */
 
 
static void
static void
free_utypes PARAMS ((PTR));
free_utypes PARAMS ((PTR));
 
 
static int
static int
attribute_size PARAMS ((unsigned int));
attribute_size PARAMS ((unsigned int));
 
 
static CORE_ADDR
static CORE_ADDR
  target_to_host PARAMS ((char *, int, int, struct objfile *));
  target_to_host PARAMS ((char *, int, int, struct objfile *));
 
 
static void
static void
add_enum_psymbol PARAMS ((struct dieinfo *, struct objfile *));
add_enum_psymbol PARAMS ((struct dieinfo *, struct objfile *));
 
 
static void
static void
handle_producer PARAMS ((char *));
handle_producer PARAMS ((char *));
 
 
static void
static void
read_file_scope PARAMS ((struct dieinfo *, char *, char *, struct objfile *));
read_file_scope PARAMS ((struct dieinfo *, char *, char *, struct objfile *));
 
 
static void
static void
read_func_scope PARAMS ((struct dieinfo *, char *, char *, struct objfile *));
read_func_scope PARAMS ((struct dieinfo *, char *, char *, struct objfile *));
 
 
static void
static void
read_lexical_block_scope PARAMS ((struct dieinfo *, char *, char *,
read_lexical_block_scope PARAMS ((struct dieinfo *, char *, char *,
                                  struct objfile *));
                                  struct objfile *));
 
 
static void
static void
scan_partial_symbols PARAMS ((char *, char *, struct objfile *));
scan_partial_symbols PARAMS ((char *, char *, struct objfile *));
 
 
static void
static void
scan_compilation_units PARAMS ((char *, char *, file_ptr,
scan_compilation_units PARAMS ((char *, char *, file_ptr,
                                file_ptr, struct objfile *));
                                file_ptr, struct objfile *));
 
 
static void
static void
add_partial_symbol PARAMS ((struct dieinfo *, struct objfile *));
add_partial_symbol PARAMS ((struct dieinfo *, struct objfile *));
 
 
static void
static void
basicdieinfo PARAMS ((struct dieinfo *, char *, struct objfile *));
basicdieinfo PARAMS ((struct dieinfo *, char *, struct objfile *));
 
 
static void
static void
completedieinfo PARAMS ((struct dieinfo *, struct objfile *));
completedieinfo PARAMS ((struct dieinfo *, struct objfile *));
 
 
static void
static void
dwarf_psymtab_to_symtab PARAMS ((struct partial_symtab *));
dwarf_psymtab_to_symtab PARAMS ((struct partial_symtab *));
 
 
static void
static void
psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
 
 
static void
static void
read_ofile_symtab PARAMS ((struct partial_symtab *));
read_ofile_symtab PARAMS ((struct partial_symtab *));
 
 
static void
static void
process_dies PARAMS ((char *, char *, struct objfile *));
process_dies PARAMS ((char *, char *, struct objfile *));
 
 
static void
static void
read_structure_scope PARAMS ((struct dieinfo *, char *, char *,
read_structure_scope PARAMS ((struct dieinfo *, char *, char *,
                              struct objfile *));
                              struct objfile *));
 
 
static struct type *
static struct type *
  decode_array_element_type PARAMS ((char *));
  decode_array_element_type PARAMS ((char *));
 
 
static struct type *
static struct type *
  decode_subscript_data_item PARAMS ((char *, char *));
  decode_subscript_data_item PARAMS ((char *, char *));
 
 
static void
static void
dwarf_read_array_type PARAMS ((struct dieinfo *));
dwarf_read_array_type PARAMS ((struct dieinfo *));
 
 
static void
static void
read_tag_pointer_type PARAMS ((struct dieinfo * dip));
read_tag_pointer_type PARAMS ((struct dieinfo * dip));
 
 
static void
static void
read_tag_string_type PARAMS ((struct dieinfo * dip));
read_tag_string_type PARAMS ((struct dieinfo * dip));
 
 
static void
static void
read_subroutine_type PARAMS ((struct dieinfo *, char *, char *));
read_subroutine_type PARAMS ((struct dieinfo *, char *, char *));
 
 
static void
static void
read_enumeration PARAMS ((struct dieinfo *, char *, char *, struct objfile *));
read_enumeration PARAMS ((struct dieinfo *, char *, char *, struct objfile *));
 
 
static struct type *
static struct type *
  struct_type PARAMS ((struct dieinfo *, char *, char *, struct objfile *));
  struct_type PARAMS ((struct dieinfo *, char *, char *, struct objfile *));
 
 
static struct type *
static struct type *
  enum_type PARAMS ((struct dieinfo *, struct objfile *));
  enum_type PARAMS ((struct dieinfo *, struct objfile *));
 
 
static void
static void
decode_line_numbers PARAMS ((char *));
decode_line_numbers PARAMS ((char *));
 
 
static struct type *
static struct type *
  decode_die_type PARAMS ((struct dieinfo *));
  decode_die_type PARAMS ((struct dieinfo *));
 
 
static struct type *
static struct type *
  decode_mod_fund_type PARAMS ((char *));
  decode_mod_fund_type PARAMS ((char *));
 
 
static struct type *
static struct type *
  decode_mod_u_d_type PARAMS ((char *));
  decode_mod_u_d_type PARAMS ((char *));
 
 
static struct type *
static struct type *
  decode_modified_type PARAMS ((char *, unsigned int, int));
  decode_modified_type PARAMS ((char *, unsigned int, int));
 
 
static struct type *
static struct type *
  decode_fund_type PARAMS ((unsigned int));
  decode_fund_type PARAMS ((unsigned int));
 
 
static char *
static char *
  create_name PARAMS ((char *, struct obstack *));
  create_name PARAMS ((char *, struct obstack *));
 
 
static struct type *
static struct type *
  lookup_utype PARAMS ((DIE_REF));
  lookup_utype PARAMS ((DIE_REF));
 
 
static struct type *
static struct type *
  alloc_utype PARAMS ((DIE_REF, struct type *));
  alloc_utype PARAMS ((DIE_REF, struct type *));
 
 
static struct symbol *
static struct symbol *
  new_symbol PARAMS ((struct dieinfo *, struct objfile *));
  new_symbol PARAMS ((struct dieinfo *, struct objfile *));
 
 
static void
static void
synthesize_typedef PARAMS ((struct dieinfo *, struct objfile *,
synthesize_typedef PARAMS ((struct dieinfo *, struct objfile *,
                            struct type *));
                            struct type *));
 
 
static int
static int
locval PARAMS ((struct dieinfo *));
locval PARAMS ((struct dieinfo *));
 
 
static void
static void
set_cu_language PARAMS ((struct dieinfo *));
set_cu_language PARAMS ((struct dieinfo *));
 
 
static struct type *
static struct type *
  dwarf_fundamental_type PARAMS ((struct objfile *, int));
  dwarf_fundamental_type PARAMS ((struct objfile *, int));
 
 
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   dwarf_fundamental_type -- lookup or create a fundamental type
   dwarf_fundamental_type -- lookup or create a fundamental type
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   struct type *
   struct type *
   dwarf_fundamental_type (struct objfile *objfile, int typeid)
   dwarf_fundamental_type (struct objfile *objfile, int typeid)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   DWARF version 1 doesn't supply any fundamental type information,
   DWARF version 1 doesn't supply any fundamental type information,
   so gdb has to construct such types.  It has a fixed number of
   so gdb has to construct such types.  It has a fixed number of
   fundamental types that it knows how to construct, which is the
   fundamental types that it knows how to construct, which is the
   union of all types that it knows how to construct for all languages
   union of all types that it knows how to construct for all languages
   that it knows about.  These are enumerated in gdbtypes.h.
   that it knows about.  These are enumerated in gdbtypes.h.
 
 
   As an example, assume we find a DIE that references a DWARF
   As an example, assume we find a DIE that references a DWARF
   fundamental type of FT_integer.  We first look in the ftypes
   fundamental type of FT_integer.  We first look in the ftypes
   array to see if we already have such a type, indexed by the
   array to see if we already have such a type, indexed by the
   gdb internal value of FT_INTEGER.  If so, we simply return a
   gdb internal value of FT_INTEGER.  If so, we simply return a
   pointer to that type.  If not, then we ask an appropriate
   pointer to that type.  If not, then we ask an appropriate
   language dependent routine to create a type FT_INTEGER, using
   language dependent routine to create a type FT_INTEGER, using
   defaults reasonable for the current target machine, and install
   defaults reasonable for the current target machine, and install
   that type in ftypes for future reference.
   that type in ftypes for future reference.
 
 
   RETURNS
   RETURNS
 
 
   Pointer to a fundamental type.
   Pointer to a fundamental type.
 
 
 */
 */
 
 
static struct type *
static struct type *
dwarf_fundamental_type (objfile, typeid)
dwarf_fundamental_type (objfile, typeid)
     struct objfile *objfile;
     struct objfile *objfile;
     int typeid;
     int typeid;
{
{
  if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
  if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
    {
    {
      error ("internal error - invalid fundamental type id %d", typeid);
      error ("internal error - invalid fundamental type id %d", typeid);
    }
    }
 
 
  /* Look for this particular type in the fundamental type vector.  If one is
  /* Look for this particular type in the fundamental type vector.  If one is
     not found, create and install one appropriate for the current language
     not found, create and install one appropriate for the current language
     and the current target machine. */
     and the current target machine. */
 
 
  if (ftypes[typeid] == NULL)
  if (ftypes[typeid] == NULL)
    {
    {
      ftypes[typeid] = cu_language_defn->la_fund_type (objfile, typeid);
      ftypes[typeid] = cu_language_defn->la_fund_type (objfile, typeid);
    }
    }
 
 
  return (ftypes[typeid]);
  return (ftypes[typeid]);
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   set_cu_language -- set local copy of language for compilation unit
   set_cu_language -- set local copy of language for compilation unit
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   void
   void
   set_cu_language (struct dieinfo *dip)
   set_cu_language (struct dieinfo *dip)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Decode the language attribute for a compilation unit DIE and
   Decode the language attribute for a compilation unit DIE and
   remember what the language was.  We use this at various times
   remember what the language was.  We use this at various times
   when processing DIE's for a given compilation unit.
   when processing DIE's for a given compilation unit.
 
 
   RETURNS
   RETURNS
 
 
   No return value.
   No return value.
 
 
 */
 */
 
 
static void
static void
set_cu_language (dip)
set_cu_language (dip)
     struct dieinfo *dip;
     struct dieinfo *dip;
{
{
  switch (dip->at_language)
  switch (dip->at_language)
    {
    {
    case LANG_C89:
    case LANG_C89:
    case LANG_C:
    case LANG_C:
      cu_language = language_c;
      cu_language = language_c;
      break;
      break;
    case LANG_C_PLUS_PLUS:
    case LANG_C_PLUS_PLUS:
      cu_language = language_cplus;
      cu_language = language_cplus;
      break;
      break;
    case LANG_CHILL:
    case LANG_CHILL:
      cu_language = language_chill;
      cu_language = language_chill;
      break;
      break;
    case LANG_MODULA2:
    case LANG_MODULA2:
      cu_language = language_m2;
      cu_language = language_m2;
      break;
      break;
    case LANG_FORTRAN77:
    case LANG_FORTRAN77:
    case LANG_FORTRAN90:
    case LANG_FORTRAN90:
      cu_language = language_fortran;
      cu_language = language_fortran;
      break;
      break;
    case LANG_ADA83:
    case LANG_ADA83:
    case LANG_COBOL74:
    case LANG_COBOL74:
    case LANG_COBOL85:
    case LANG_COBOL85:
    case LANG_PASCAL83:
    case LANG_PASCAL83:
      /* We don't know anything special about these yet. */
      /* We don't know anything special about these yet. */
      cu_language = language_unknown;
      cu_language = language_unknown;
      break;
      break;
    default:
    default:
      /* If no at_language, try to deduce one from the filename */
      /* If no at_language, try to deduce one from the filename */
      cu_language = deduce_language_from_filename (dip->at_name);
      cu_language = deduce_language_from_filename (dip->at_name);
      break;
      break;
    }
    }
  cu_language_defn = language_def (cu_language);
  cu_language_defn = language_def (cu_language);
}
}
 
 
/*
/*
 
 
   GLOBAL FUNCTION
   GLOBAL FUNCTION
 
 
   dwarf_build_psymtabs -- build partial symtabs from DWARF debug info
   dwarf_build_psymtabs -- build partial symtabs from DWARF debug info
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   void dwarf_build_psymtabs (struct objfile *objfile,
   void dwarf_build_psymtabs (struct objfile *objfile,
   int mainline, file_ptr dbfoff, unsigned int dbfsize,
   int mainline, file_ptr dbfoff, unsigned int dbfsize,
   file_ptr lnoffset, unsigned int lnsize)
   file_ptr lnoffset, unsigned int lnsize)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   This function is called upon to build partial symtabs from files
   This function is called upon to build partial symtabs from files
   containing DIE's (Dwarf Information Entries) and DWARF line numbers.
   containing DIE's (Dwarf Information Entries) and DWARF line numbers.
 
 
   It is passed a bfd* containing the DIES
   It is passed a bfd* containing the DIES
   and line number information, the corresponding filename for that
   and line number information, the corresponding filename for that
   file, a base address for relocating the symbols, a flag indicating
   file, a base address for relocating the symbols, a flag indicating
   whether or not this debugging information is from a "main symbol
   whether or not this debugging information is from a "main symbol
   table" rather than a shared library or dynamically linked file,
   table" rather than a shared library or dynamically linked file,
   and file offset/size pairs for the DIE information and line number
   and file offset/size pairs for the DIE information and line number
   information.
   information.
 
 
   RETURNS
   RETURNS
 
 
   No return value.
   No return value.
 
 
 */
 */
 
 
void
void
dwarf_build_psymtabs (objfile, mainline, dbfoff, dbfsize,
dwarf_build_psymtabs (objfile, mainline, dbfoff, dbfsize,
                      lnoffset, lnsize)
                      lnoffset, lnsize)
     struct objfile *objfile;
     struct objfile *objfile;
     int mainline;
     int mainline;
     file_ptr dbfoff;
     file_ptr dbfoff;
     unsigned int dbfsize;
     unsigned int dbfsize;
     file_ptr lnoffset;
     file_ptr lnoffset;
     unsigned int lnsize;
     unsigned int lnsize;
{
{
  bfd *abfd = objfile->obfd;
  bfd *abfd = objfile->obfd;
  struct cleanup *back_to;
  struct cleanup *back_to;
 
 
  current_objfile = objfile;
  current_objfile = objfile;
  dbsize = dbfsize;
  dbsize = dbfsize;
  dbbase = xmalloc (dbsize);
  dbbase = xmalloc (dbsize);
  dbroff = 0;
  dbroff = 0;
  if ((bfd_seek (abfd, dbfoff, SEEK_SET) != 0) ||
  if ((bfd_seek (abfd, dbfoff, SEEK_SET) != 0) ||
      (bfd_read (dbbase, dbsize, 1, abfd) != dbsize))
      (bfd_read (dbbase, dbsize, 1, abfd) != dbsize))
    {
    {
      free (dbbase);
      free (dbbase);
      error ("can't read DWARF data from '%s'", bfd_get_filename (abfd));
      error ("can't read DWARF data from '%s'", bfd_get_filename (abfd));
    }
    }
  back_to = make_cleanup (free, dbbase);
  back_to = make_cleanup (free, dbbase);
 
 
  /* If we are reinitializing, or if we have never loaded syms yet, init.
  /* If we are reinitializing, or if we have never loaded syms yet, init.
     Since we have no idea how many DIES we are looking at, we just guess
     Since we have no idea how many DIES we are looking at, we just guess
     some arbitrary value. */
     some arbitrary value. */
 
 
  if (mainline || objfile->global_psymbols.size == 0 ||
  if (mainline || objfile->global_psymbols.size == 0 ||
      objfile->static_psymbols.size == 0)
      objfile->static_psymbols.size == 0)
    {
    {
      init_psymbol_list (objfile, 1024);
      init_psymbol_list (objfile, 1024);
    }
    }
 
 
  /* Save the relocation factor where everybody can see it.  */
  /* Save the relocation factor where everybody can see it.  */
 
 
  base_section_offsets = objfile->section_offsets;
  base_section_offsets = objfile->section_offsets;
  baseaddr = ANOFFSET (objfile->section_offsets, 0);
  baseaddr = ANOFFSET (objfile->section_offsets, 0);
 
 
  /* Follow the compilation unit sibling chain, building a partial symbol
  /* Follow the compilation unit sibling chain, building a partial symbol
     table entry for each one.  Save enough information about each compilation
     table entry for each one.  Save enough information about each compilation
     unit to locate the full DWARF information later. */
     unit to locate the full DWARF information later. */
 
 
  scan_compilation_units (dbbase, dbbase + dbsize, dbfoff, lnoffset, objfile);
  scan_compilation_units (dbbase, dbbase + dbsize, dbfoff, lnoffset, objfile);
 
 
  do_cleanups (back_to);
  do_cleanups (back_to);
  current_objfile = NULL;
  current_objfile = NULL;
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   read_lexical_block_scope -- process all dies in a lexical block
   read_lexical_block_scope -- process all dies in a lexical block
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static void read_lexical_block_scope (struct dieinfo *dip,
   static void read_lexical_block_scope (struct dieinfo *dip,
   char *thisdie, char *enddie)
   char *thisdie, char *enddie)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Process all the DIES contained within a lexical block scope.
   Process all the DIES contained within a lexical block scope.
   Start a new scope, process the dies, and then close the scope.
   Start a new scope, process the dies, and then close the scope.
 
 
 */
 */
 
 
static void
static void
read_lexical_block_scope (dip, thisdie, enddie, objfile)
read_lexical_block_scope (dip, thisdie, enddie, objfile)
     struct dieinfo *dip;
     struct dieinfo *dip;
     char *thisdie;
     char *thisdie;
     char *enddie;
     char *enddie;
     struct objfile *objfile;
     struct objfile *objfile;
{
{
  register struct context_stack *new;
  register struct context_stack *new;
 
 
  push_context (0, dip->at_low_pc);
  push_context (0, dip->at_low_pc);
  process_dies (thisdie + dip->die_length, enddie, objfile);
  process_dies (thisdie + dip->die_length, enddie, objfile);
  new = pop_context ();
  new = pop_context ();
  if (local_symbols != NULL)
  if (local_symbols != NULL)
    {
    {
      finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
      finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
                    dip->at_high_pc, objfile);
                    dip->at_high_pc, objfile);
    }
    }
  local_symbols = new->locals;
  local_symbols = new->locals;
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   lookup_utype -- look up a user defined type from die reference
   lookup_utype -- look up a user defined type from die reference
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static type *lookup_utype (DIE_REF die_ref)
   static type *lookup_utype (DIE_REF die_ref)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Given a DIE reference, lookup the user defined type associated with
   Given a DIE reference, lookup the user defined type associated with
   that DIE, if it has been registered already.  If not registered, then
   that DIE, if it has been registered already.  If not registered, then
   return NULL.  Alloc_utype() can be called to register an empty
   return NULL.  Alloc_utype() can be called to register an empty
   type for this reference, which will be filled in later when the
   type for this reference, which will be filled in later when the
   actual referenced DIE is processed.
   actual referenced DIE is processed.
 */
 */
 
 
static struct type *
static struct type *
lookup_utype (die_ref)
lookup_utype (die_ref)
     DIE_REF die_ref;
     DIE_REF die_ref;
{
{
  struct type *type = NULL;
  struct type *type = NULL;
  int utypeidx;
  int utypeidx;
 
 
  utypeidx = (die_ref - dbroff) / 4;
  utypeidx = (die_ref - dbroff) / 4;
  if ((utypeidx < 0) || (utypeidx >= numutypes))
  if ((utypeidx < 0) || (utypeidx >= numutypes))
    {
    {
      complain (&bad_die_ref, DIE_ID, DIE_NAME);
      complain (&bad_die_ref, DIE_ID, DIE_NAME);
    }
    }
  else
  else
    {
    {
      type = *(utypes + utypeidx);
      type = *(utypes + utypeidx);
    }
    }
  return (type);
  return (type);
}
}
 
 
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   alloc_utype  -- add a user defined type for die reference
   alloc_utype  -- add a user defined type for die reference
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static type *alloc_utype (DIE_REF die_ref, struct type *utypep)
   static type *alloc_utype (DIE_REF die_ref, struct type *utypep)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Given a die reference DIE_REF, and a possible pointer to a user
   Given a die reference DIE_REF, and a possible pointer to a user
   defined type UTYPEP, register that this reference has a user
   defined type UTYPEP, register that this reference has a user
   defined type and either use the specified type in UTYPEP or
   defined type and either use the specified type in UTYPEP or
   make a new empty type that will be filled in later.
   make a new empty type that will be filled in later.
 
 
   We should only be called after calling lookup_utype() to verify that
   We should only be called after calling lookup_utype() to verify that
   there is not currently a type registered for DIE_REF.
   there is not currently a type registered for DIE_REF.
 */
 */
 
 
static struct type *
static struct type *
alloc_utype (die_ref, utypep)
alloc_utype (die_ref, utypep)
     DIE_REF die_ref;
     DIE_REF die_ref;
     struct type *utypep;
     struct type *utypep;
{
{
  struct type **typep;
  struct type **typep;
  int utypeidx;
  int utypeidx;
 
 
  utypeidx = (die_ref - dbroff) / 4;
  utypeidx = (die_ref - dbroff) / 4;
  typep = utypes + utypeidx;
  typep = utypes + utypeidx;
  if ((utypeidx < 0) || (utypeidx >= numutypes))
  if ((utypeidx < 0) || (utypeidx >= numutypes))
    {
    {
      utypep = dwarf_fundamental_type (current_objfile, FT_INTEGER);
      utypep = dwarf_fundamental_type (current_objfile, FT_INTEGER);
      complain (&bad_die_ref, DIE_ID, DIE_NAME);
      complain (&bad_die_ref, DIE_ID, DIE_NAME);
    }
    }
  else if (*typep != NULL)
  else if (*typep != NULL)
    {
    {
      utypep = *typep;
      utypep = *typep;
      complain (&dup_user_type_allocation, DIE_ID, DIE_NAME);
      complain (&dup_user_type_allocation, DIE_ID, DIE_NAME);
    }
    }
  else
  else
    {
    {
      if (utypep == NULL)
      if (utypep == NULL)
        {
        {
          utypep = alloc_type (current_objfile);
          utypep = alloc_type (current_objfile);
        }
        }
      *typep = utypep;
      *typep = utypep;
    }
    }
  return (utypep);
  return (utypep);
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   free_utypes -- free the utypes array and reset pointer & count
   free_utypes -- free the utypes array and reset pointer & count
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static void free_utypes (PTR dummy)
   static void free_utypes (PTR dummy)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Called via do_cleanups to free the utypes array, reset the pointer to NULL,
   Called via do_cleanups to free the utypes array, reset the pointer to NULL,
   and set numutypes back to zero.  This ensures that the utypes does not get
   and set numutypes back to zero.  This ensures that the utypes does not get
   referenced after being freed.
   referenced after being freed.
 */
 */
 
 
static void
static void
free_utypes (dummy)
free_utypes (dummy)
     PTR dummy;
     PTR dummy;
{
{
  free (utypes);
  free (utypes);
  utypes = NULL;
  utypes = NULL;
  numutypes = 0;
  numutypes = 0;
}
}
 
 
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   decode_die_type -- return a type for a specified die
   decode_die_type -- return a type for a specified die
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static struct type *decode_die_type (struct dieinfo *dip)
   static struct type *decode_die_type (struct dieinfo *dip)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Given a pointer to a die information structure DIP, decode the
   Given a pointer to a die information structure DIP, decode the
   type of the die and return a pointer to the decoded type.  All
   type of the die and return a pointer to the decoded type.  All
   dies without specific types default to type int.
   dies without specific types default to type int.
 */
 */
 
 
static struct type *
static struct type *
decode_die_type (dip)
decode_die_type (dip)
     struct dieinfo *dip;
     struct dieinfo *dip;
{
{
  struct type *type = NULL;
  struct type *type = NULL;
 
 
  if (dip->at_fund_type != 0)
  if (dip->at_fund_type != 0)
    {
    {
      type = decode_fund_type (dip->at_fund_type);
      type = decode_fund_type (dip->at_fund_type);
    }
    }
  else if (dip->at_mod_fund_type != NULL)
  else if (dip->at_mod_fund_type != NULL)
    {
    {
      type = decode_mod_fund_type (dip->at_mod_fund_type);
      type = decode_mod_fund_type (dip->at_mod_fund_type);
    }
    }
  else if (dip->at_user_def_type)
  else if (dip->at_user_def_type)
    {
    {
      if ((type = lookup_utype (dip->at_user_def_type)) == NULL)
      if ((type = lookup_utype (dip->at_user_def_type)) == NULL)
        {
        {
          type = alloc_utype (dip->at_user_def_type, NULL);
          type = alloc_utype (dip->at_user_def_type, NULL);
        }
        }
    }
    }
  else if (dip->at_mod_u_d_type)
  else if (dip->at_mod_u_d_type)
    {
    {
      type = decode_mod_u_d_type (dip->at_mod_u_d_type);
      type = decode_mod_u_d_type (dip->at_mod_u_d_type);
    }
    }
  else
  else
    {
    {
      type = dwarf_fundamental_type (current_objfile, FT_VOID);
      type = dwarf_fundamental_type (current_objfile, FT_VOID);
    }
    }
  return (type);
  return (type);
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   struct_type -- compute and return the type for a struct or union
   struct_type -- compute and return the type for a struct or union
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static struct type *struct_type (struct dieinfo *dip, char *thisdie,
   static struct type *struct_type (struct dieinfo *dip, char *thisdie,
   char *enddie, struct objfile *objfile)
   char *enddie, struct objfile *objfile)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Given pointer to a die information structure for a die which
   Given pointer to a die information structure for a die which
   defines a union or structure (and MUST define one or the other),
   defines a union or structure (and MUST define one or the other),
   and pointers to the raw die data that define the range of dies which
   and pointers to the raw die data that define the range of dies which
   define the members, compute and return the user defined type for the
   define the members, compute and return the user defined type for the
   structure or union.
   structure or union.
 */
 */
 
 
static struct type *
static struct type *
struct_type (dip, thisdie, enddie, objfile)
struct_type (dip, thisdie, enddie, objfile)
     struct dieinfo *dip;
     struct dieinfo *dip;
     char *thisdie;
     char *thisdie;
     char *enddie;
     char *enddie;
     struct objfile *objfile;
     struct objfile *objfile;
{
{
  struct type *type;
  struct type *type;
  struct nextfield
  struct nextfield
    {
    {
      struct nextfield *next;
      struct nextfield *next;
      struct field field;
      struct field field;
    };
    };
  struct nextfield *list = NULL;
  struct nextfield *list = NULL;
  struct nextfield *new;
  struct nextfield *new;
  int nfields = 0;
  int nfields = 0;
  int n;
  int n;
  struct dieinfo mbr;
  struct dieinfo mbr;
  char *nextdie;
  char *nextdie;
  int anonymous_size;
  int anonymous_size;
 
 
  if ((type = lookup_utype (dip->die_ref)) == NULL)
  if ((type = lookup_utype (dip->die_ref)) == NULL)
    {
    {
      /* No forward references created an empty type, so install one now */
      /* No forward references created an empty type, so install one now */
      type = alloc_utype (dip->die_ref, NULL);
      type = alloc_utype (dip->die_ref, NULL);
    }
    }
  INIT_CPLUS_SPECIFIC (type);
  INIT_CPLUS_SPECIFIC (type);
  switch (dip->die_tag)
  switch (dip->die_tag)
    {
    {
    case TAG_class_type:
    case TAG_class_type:
      TYPE_CODE (type) = TYPE_CODE_CLASS;
      TYPE_CODE (type) = TYPE_CODE_CLASS;
      break;
      break;
    case TAG_structure_type:
    case TAG_structure_type:
      TYPE_CODE (type) = TYPE_CODE_STRUCT;
      TYPE_CODE (type) = TYPE_CODE_STRUCT;
      break;
      break;
    case TAG_union_type:
    case TAG_union_type:
      TYPE_CODE (type) = TYPE_CODE_UNION;
      TYPE_CODE (type) = TYPE_CODE_UNION;
      break;
      break;
    default:
    default:
      /* Should never happen */
      /* Should never happen */
      TYPE_CODE (type) = TYPE_CODE_UNDEF;
      TYPE_CODE (type) = TYPE_CODE_UNDEF;
      complain (&missing_tag, DIE_ID, DIE_NAME);
      complain (&missing_tag, DIE_ID, DIE_NAME);
      break;
      break;
    }
    }
  /* Some compilers try to be helpful by inventing "fake" names for
  /* Some compilers try to be helpful by inventing "fake" names for
     anonymous enums, structures, and unions, like "~0fake" or ".0fake".
     anonymous enums, structures, and unions, like "~0fake" or ".0fake".
     Thanks, but no thanks... */
     Thanks, but no thanks... */
  if (dip->at_name != NULL
  if (dip->at_name != NULL
      && *dip->at_name != '~'
      && *dip->at_name != '~'
      && *dip->at_name != '.')
      && *dip->at_name != '.')
    {
    {
      TYPE_TAG_NAME (type) = obconcat (&objfile->type_obstack,
      TYPE_TAG_NAME (type) = obconcat (&objfile->type_obstack,
                                       "", "", dip->at_name);
                                       "", "", dip->at_name);
    }
    }
  /* Use whatever size is known.  Zero is a valid size.  We might however
  /* Use whatever size is known.  Zero is a valid size.  We might however
     wish to check has_at_byte_size to make sure that some byte size was
     wish to check has_at_byte_size to make sure that some byte size was
     given explicitly, but DWARF doesn't specify that explicit sizes of
     given explicitly, but DWARF doesn't specify that explicit sizes of
     zero have to present, so complaining about missing sizes should
     zero have to present, so complaining about missing sizes should
     probably not be the default. */
     probably not be the default. */
  TYPE_LENGTH (type) = dip->at_byte_size;
  TYPE_LENGTH (type) = dip->at_byte_size;
  thisdie += dip->die_length;
  thisdie += dip->die_length;
  while (thisdie < enddie)
  while (thisdie < enddie)
    {
    {
      basicdieinfo (&mbr, thisdie, objfile);
      basicdieinfo (&mbr, thisdie, objfile);
      completedieinfo (&mbr, objfile);
      completedieinfo (&mbr, objfile);
      if (mbr.die_length <= SIZEOF_DIE_LENGTH)
      if (mbr.die_length <= SIZEOF_DIE_LENGTH)
        {
        {
          break;
          break;
        }
        }
      else if (mbr.at_sibling != 0)
      else if (mbr.at_sibling != 0)
        {
        {
          nextdie = dbbase + mbr.at_sibling - dbroff;
          nextdie = dbbase + mbr.at_sibling - dbroff;
        }
        }
      else
      else
        {
        {
          nextdie = thisdie + mbr.die_length;
          nextdie = thisdie + mbr.die_length;
        }
        }
      switch (mbr.die_tag)
      switch (mbr.die_tag)
        {
        {
        case TAG_member:
        case TAG_member:
          /* Get space to record the next field's data.  */
          /* Get space to record the next field's data.  */
          new = (struct nextfield *) alloca (sizeof (struct nextfield));
          new = (struct nextfield *) alloca (sizeof (struct nextfield));
          new->next = list;
          new->next = list;
          list = new;
          list = new;
          /* Save the data.  */
          /* Save the data.  */
          list->field.name =
          list->field.name =
            obsavestring (mbr.at_name, strlen (mbr.at_name),
            obsavestring (mbr.at_name, strlen (mbr.at_name),
                          &objfile->type_obstack);
                          &objfile->type_obstack);
          FIELD_TYPE (list->field) = decode_die_type (&mbr);
          FIELD_TYPE (list->field) = decode_die_type (&mbr);
          FIELD_BITPOS (list->field) = 8 * locval (&mbr);
          FIELD_BITPOS (list->field) = 8 * locval (&mbr);
          /* Handle bit fields. */
          /* Handle bit fields. */
          FIELD_BITSIZE (list->field) = mbr.at_bit_size;
          FIELD_BITSIZE (list->field) = mbr.at_bit_size;
          if (BITS_BIG_ENDIAN)
          if (BITS_BIG_ENDIAN)
            {
            {
              /* For big endian bits, the at_bit_offset gives the
              /* For big endian bits, the at_bit_offset gives the
                 additional bit offset from the MSB of the containing
                 additional bit offset from the MSB of the containing
                 anonymous object to the MSB of the field.  We don't
                 anonymous object to the MSB of the field.  We don't
                 have to do anything special since we don't need to
                 have to do anything special since we don't need to
                 know the size of the anonymous object. */
                 know the size of the anonymous object. */
              FIELD_BITPOS (list->field) += mbr.at_bit_offset;
              FIELD_BITPOS (list->field) += mbr.at_bit_offset;
            }
            }
          else
          else
            {
            {
              /* For little endian bits, we need to have a non-zero
              /* For little endian bits, we need to have a non-zero
                 at_bit_size, so that we know we are in fact dealing
                 at_bit_size, so that we know we are in fact dealing
                 with a bitfield.  Compute the bit offset to the MSB
                 with a bitfield.  Compute the bit offset to the MSB
                 of the anonymous object, subtract off the number of
                 of the anonymous object, subtract off the number of
                 bits from the MSB of the field to the MSB of the
                 bits from the MSB of the field to the MSB of the
                 object, and then subtract off the number of bits of
                 object, and then subtract off the number of bits of
                 the field itself.  The result is the bit offset of
                 the field itself.  The result is the bit offset of
                 the LSB of the field. */
                 the LSB of the field. */
              if (mbr.at_bit_size > 0)
              if (mbr.at_bit_size > 0)
                {
                {
                  if (mbr.has_at_byte_size)
                  if (mbr.has_at_byte_size)
                    {
                    {
                      /* The size of the anonymous object containing
                      /* The size of the anonymous object containing
                         the bit field is explicit, so use the
                         the bit field is explicit, so use the
                         indicated size (in bytes). */
                         indicated size (in bytes). */
                      anonymous_size = mbr.at_byte_size;
                      anonymous_size = mbr.at_byte_size;
                    }
                    }
                  else
                  else
                    {
                    {
                      /* The size of the anonymous object containing
                      /* The size of the anonymous object containing
                         the bit field matches the size of an object
                         the bit field matches the size of an object
                         of the bit field's type.  DWARF allows
                         of the bit field's type.  DWARF allows
                         at_byte_size to be left out in such cases, as
                         at_byte_size to be left out in such cases, as
                         a debug information size optimization. */
                         a debug information size optimization. */
                      anonymous_size = TYPE_LENGTH (list->field.type);
                      anonymous_size = TYPE_LENGTH (list->field.type);
                    }
                    }
                  FIELD_BITPOS (list->field) +=
                  FIELD_BITPOS (list->field) +=
                    anonymous_size * 8 - mbr.at_bit_offset - mbr.at_bit_size;
                    anonymous_size * 8 - mbr.at_bit_offset - mbr.at_bit_size;
                }
                }
            }
            }
          nfields++;
          nfields++;
          break;
          break;
        default:
        default:
          process_dies (thisdie, nextdie, objfile);
          process_dies (thisdie, nextdie, objfile);
          break;
          break;
        }
        }
      thisdie = nextdie;
      thisdie = nextdie;
    }
    }
  /* Now create the vector of fields, and record how big it is.  We may
  /* Now create the vector of fields, and record how big it is.  We may
     not even have any fields, if this DIE was generated due to a reference
     not even have any fields, if this DIE was generated due to a reference
     to an anonymous structure or union.  In this case, TYPE_FLAG_STUB is
     to an anonymous structure or union.  In this case, TYPE_FLAG_STUB is
     set, which clues gdb in to the fact that it needs to search elsewhere
     set, which clues gdb in to the fact that it needs to search elsewhere
     for the full structure definition. */
     for the full structure definition. */
  if (nfields == 0)
  if (nfields == 0)
    {
    {
      TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
      TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
    }
    }
  else
  else
    {
    {
      TYPE_NFIELDS (type) = nfields;
      TYPE_NFIELDS (type) = nfields;
      TYPE_FIELDS (type) = (struct field *)
      TYPE_FIELDS (type) = (struct field *)
        TYPE_ALLOC (type, sizeof (struct field) * nfields);
        TYPE_ALLOC (type, sizeof (struct field) * nfields);
      /* Copy the saved-up fields into the field vector.  */
      /* Copy the saved-up fields into the field vector.  */
      for (n = nfields; list; list = list->next)
      for (n = nfields; list; list = list->next)
        {
        {
          TYPE_FIELD (type, --n) = list->field;
          TYPE_FIELD (type, --n) = list->field;
        }
        }
    }
    }
  return (type);
  return (type);
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   read_structure_scope -- process all dies within struct or union
   read_structure_scope -- process all dies within struct or union
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static void read_structure_scope (struct dieinfo *dip,
   static void read_structure_scope (struct dieinfo *dip,
   char *thisdie, char *enddie, struct objfile *objfile)
   char *thisdie, char *enddie, struct objfile *objfile)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Called when we find the DIE that starts a structure or union
   Called when we find the DIE that starts a structure or union
   scope (definition) to process all dies that define the members
   scope (definition) to process all dies that define the members
   of the structure or union.  DIP is a pointer to the die info
   of the structure or union.  DIP is a pointer to the die info
   struct for the DIE that names the structure or union.
   struct for the DIE that names the structure or union.
 
 
   NOTES
   NOTES
 
 
   Note that we need to call struct_type regardless of whether or not
   Note that we need to call struct_type regardless of whether or not
   the DIE has an at_name attribute, since it might be an anonymous
   the DIE has an at_name attribute, since it might be an anonymous
   structure or union.  This gets the type entered into our set of
   structure or union.  This gets the type entered into our set of
   user defined types.
   user defined types.
 
 
   However, if the structure is incomplete (an opaque struct/union)
   However, if the structure is incomplete (an opaque struct/union)
   then suppress creating a symbol table entry for it since gdb only
   then suppress creating a symbol table entry for it since gdb only
   wants to find the one with the complete definition.  Note that if
   wants to find the one with the complete definition.  Note that if
   it is complete, we just call new_symbol, which does it's own
   it is complete, we just call new_symbol, which does it's own
   checking about whether the struct/union is anonymous or not (and
   checking about whether the struct/union is anonymous or not (and
   suppresses creating a symbol table entry itself).
   suppresses creating a symbol table entry itself).
 
 
 */
 */
 
 
static void
static void
read_structure_scope (dip, thisdie, enddie, objfile)
read_structure_scope (dip, thisdie, enddie, objfile)
     struct dieinfo *dip;
     struct dieinfo *dip;
     char *thisdie;
     char *thisdie;
     char *enddie;
     char *enddie;
     struct objfile *objfile;
     struct objfile *objfile;
{
{
  struct type *type;
  struct type *type;
  struct symbol *sym;
  struct symbol *sym;
 
 
  type = struct_type (dip, thisdie, enddie, objfile);
  type = struct_type (dip, thisdie, enddie, objfile);
  if (!(TYPE_FLAGS (type) & TYPE_FLAG_STUB))
  if (!(TYPE_FLAGS (type) & TYPE_FLAG_STUB))
    {
    {
      sym = new_symbol (dip, objfile);
      sym = new_symbol (dip, objfile);
      if (sym != NULL)
      if (sym != NULL)
        {
        {
          SYMBOL_TYPE (sym) = type;
          SYMBOL_TYPE (sym) = type;
          if (cu_language == language_cplus)
          if (cu_language == language_cplus)
            {
            {
              synthesize_typedef (dip, objfile, type);
              synthesize_typedef (dip, objfile, type);
            }
            }
        }
        }
    }
    }
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   decode_array_element_type -- decode type of the array elements
   decode_array_element_type -- decode type of the array elements
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static struct type *decode_array_element_type (char *scan, char *end)
   static struct type *decode_array_element_type (char *scan, char *end)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   As the last step in decoding the array subscript information for an
   As the last step in decoding the array subscript information for an
   array DIE, we need to decode the type of the array elements.  We are
   array DIE, we need to decode the type of the array elements.  We are
   passed a pointer to this last part of the subscript information and
   passed a pointer to this last part of the subscript information and
   must return the appropriate type.  If the type attribute is not
   must return the appropriate type.  If the type attribute is not
   recognized, just warn about the problem and return type int.
   recognized, just warn about the problem and return type int.
 */
 */
 
 
static struct type *
static struct type *
decode_array_element_type (scan)
decode_array_element_type (scan)
     char *scan;
     char *scan;
{
{
  struct type *typep;
  struct type *typep;
  DIE_REF die_ref;
  DIE_REF die_ref;
  unsigned short attribute;
  unsigned short attribute;
  unsigned short fundtype;
  unsigned short fundtype;
  int nbytes;
  int nbytes;
 
 
  attribute = target_to_host (scan, SIZEOF_ATTRIBUTE, GET_UNSIGNED,
  attribute = target_to_host (scan, SIZEOF_ATTRIBUTE, GET_UNSIGNED,
                              current_objfile);
                              current_objfile);
  scan += SIZEOF_ATTRIBUTE;
  scan += SIZEOF_ATTRIBUTE;
  if ((nbytes = attribute_size (attribute)) == -1)
  if ((nbytes = attribute_size (attribute)) == -1)
    {
    {
      complain (&bad_array_element_type, DIE_ID, DIE_NAME, attribute);
      complain (&bad_array_element_type, DIE_ID, DIE_NAME, attribute);
      typep = dwarf_fundamental_type (current_objfile, FT_INTEGER);
      typep = dwarf_fundamental_type (current_objfile, FT_INTEGER);
    }
    }
  else
  else
    {
    {
      switch (attribute)
      switch (attribute)
        {
        {
        case AT_fund_type:
        case AT_fund_type:
          fundtype = target_to_host (scan, nbytes, GET_UNSIGNED,
          fundtype = target_to_host (scan, nbytes, GET_UNSIGNED,
                                     current_objfile);
                                     current_objfile);
          typep = decode_fund_type (fundtype);
          typep = decode_fund_type (fundtype);
          break;
          break;
        case AT_mod_fund_type:
        case AT_mod_fund_type:
          typep = decode_mod_fund_type (scan);
          typep = decode_mod_fund_type (scan);
          break;
          break;
        case AT_user_def_type:
        case AT_user_def_type:
          die_ref = target_to_host (scan, nbytes, GET_UNSIGNED,
          die_ref = target_to_host (scan, nbytes, GET_UNSIGNED,
                                    current_objfile);
                                    current_objfile);
          if ((typep = lookup_utype (die_ref)) == NULL)
          if ((typep = lookup_utype (die_ref)) == NULL)
            {
            {
              typep = alloc_utype (die_ref, NULL);
              typep = alloc_utype (die_ref, NULL);
            }
            }
          break;
          break;
        case AT_mod_u_d_type:
        case AT_mod_u_d_type:
          typep = decode_mod_u_d_type (scan);
          typep = decode_mod_u_d_type (scan);
          break;
          break;
        default:
        default:
          complain (&bad_array_element_type, DIE_ID, DIE_NAME, attribute);
          complain (&bad_array_element_type, DIE_ID, DIE_NAME, attribute);
          typep = dwarf_fundamental_type (current_objfile, FT_INTEGER);
          typep = dwarf_fundamental_type (current_objfile, FT_INTEGER);
          break;
          break;
        }
        }
    }
    }
  return (typep);
  return (typep);
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   decode_subscript_data_item -- decode array subscript item
   decode_subscript_data_item -- decode array subscript item
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static struct type *
   static struct type *
   decode_subscript_data_item (char *scan, char *end)
   decode_subscript_data_item (char *scan, char *end)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   The array subscripts and the data type of the elements of an
   The array subscripts and the data type of the elements of an
   array are described by a list of data items, stored as a block
   array are described by a list of data items, stored as a block
   of contiguous bytes.  There is a data item describing each array
   of contiguous bytes.  There is a data item describing each array
   dimension, and a final data item describing the element type.
   dimension, and a final data item describing the element type.
   The data items are ordered the same as their appearance in the
   The data items are ordered the same as their appearance in the
   source (I.E. leftmost dimension first, next to leftmost second,
   source (I.E. leftmost dimension first, next to leftmost second,
   etc).
   etc).
 
 
   The data items describing each array dimension consist of four
   The data items describing each array dimension consist of four
   parts: (1) a format specifier, (2) type type of the subscript
   parts: (1) a format specifier, (2) type type of the subscript
   index, (3) a description of the low bound of the array dimension,
   index, (3) a description of the low bound of the array dimension,
   and (4) a description of the high bound of the array dimension.
   and (4) a description of the high bound of the array dimension.
 
 
   The last data item is the description of the type of each of
   The last data item is the description of the type of each of
   the array elements.
   the array elements.
 
 
   We are passed a pointer to the start of the block of bytes
   We are passed a pointer to the start of the block of bytes
   containing the remaining data items, and a pointer to the first
   containing the remaining data items, and a pointer to the first
   byte past the data.  This function recursively decodes the
   byte past the data.  This function recursively decodes the
   remaining data items and returns a type.
   remaining data items and returns a type.
 
 
   If we somehow fail to decode some data, we complain about it
   If we somehow fail to decode some data, we complain about it
   and return a type "array of int".
   and return a type "array of int".
 
 
   BUGS
   BUGS
   FIXME:  This code only implements the forms currently used
   FIXME:  This code only implements the forms currently used
   by the AT&T and GNU C compilers.
   by the AT&T and GNU C compilers.
 
 
   The end pointer is supplied for error checking, maybe we should
   The end pointer is supplied for error checking, maybe we should
   use it for that...
   use it for that...
 */
 */
 
 
static struct type *
static struct type *
decode_subscript_data_item (scan, end)
decode_subscript_data_item (scan, end)
     char *scan;
     char *scan;
     char *end;
     char *end;
{
{
  struct type *typep = NULL;    /* Array type we are building */
  struct type *typep = NULL;    /* Array type we are building */
  struct type *nexttype;        /* Type of each element (may be array) */
  struct type *nexttype;        /* Type of each element (may be array) */
  struct type *indextype;       /* Type of this index */
  struct type *indextype;       /* Type of this index */
  struct type *rangetype;
  struct type *rangetype;
  unsigned int format;
  unsigned int format;
  unsigned short fundtype;
  unsigned short fundtype;
  unsigned long lowbound;
  unsigned long lowbound;
  unsigned long highbound;
  unsigned long highbound;
  int nbytes;
  int nbytes;
 
 
  format = target_to_host (scan, SIZEOF_FORMAT_SPECIFIER, GET_UNSIGNED,
  format = target_to_host (scan, SIZEOF_FORMAT_SPECIFIER, GET_UNSIGNED,
                           current_objfile);
                           current_objfile);
  scan += SIZEOF_FORMAT_SPECIFIER;
  scan += SIZEOF_FORMAT_SPECIFIER;
  switch (format)
  switch (format)
    {
    {
    case FMT_ET:
    case FMT_ET:
      typep = decode_array_element_type (scan);
      typep = decode_array_element_type (scan);
      break;
      break;
    case FMT_FT_C_C:
    case FMT_FT_C_C:
      fundtype = target_to_host (scan, SIZEOF_FMT_FT, GET_UNSIGNED,
      fundtype = target_to_host (scan, SIZEOF_FMT_FT, GET_UNSIGNED,
                                 current_objfile);
                                 current_objfile);
      indextype = decode_fund_type (fundtype);
      indextype = decode_fund_type (fundtype);
      scan += SIZEOF_FMT_FT;
      scan += SIZEOF_FMT_FT;
      nbytes = TARGET_FT_LONG_SIZE (current_objfile);
      nbytes = TARGET_FT_LONG_SIZE (current_objfile);
      lowbound = target_to_host (scan, nbytes, GET_UNSIGNED, current_objfile);
      lowbound = target_to_host (scan, nbytes, GET_UNSIGNED, current_objfile);
      scan += nbytes;
      scan += nbytes;
      highbound = target_to_host (scan, nbytes, GET_UNSIGNED, current_objfile);
      highbound = target_to_host (scan, nbytes, GET_UNSIGNED, current_objfile);
      scan += nbytes;
      scan += nbytes;
      nexttype = decode_subscript_data_item (scan, end);
      nexttype = decode_subscript_data_item (scan, end);
      if (nexttype == NULL)
      if (nexttype == NULL)
        {
        {
          /* Munged subscript data or other problem, fake it. */
          /* Munged subscript data or other problem, fake it. */
          complain (&subscript_data_items, DIE_ID, DIE_NAME);
          complain (&subscript_data_items, DIE_ID, DIE_NAME);
          nexttype = dwarf_fundamental_type (current_objfile, FT_INTEGER);
          nexttype = dwarf_fundamental_type (current_objfile, FT_INTEGER);
        }
        }
      rangetype = create_range_type ((struct type *) NULL, indextype,
      rangetype = create_range_type ((struct type *) NULL, indextype,
                                     lowbound, highbound);
                                     lowbound, highbound);
      typep = create_array_type ((struct type *) NULL, nexttype, rangetype);
      typep = create_array_type ((struct type *) NULL, nexttype, rangetype);
      break;
      break;
    case FMT_FT_C_X:
    case FMT_FT_C_X:
    case FMT_FT_X_C:
    case FMT_FT_X_C:
    case FMT_FT_X_X:
    case FMT_FT_X_X:
    case FMT_UT_C_C:
    case FMT_UT_C_C:
    case FMT_UT_C_X:
    case FMT_UT_C_X:
    case FMT_UT_X_C:
    case FMT_UT_X_C:
    case FMT_UT_X_X:
    case FMT_UT_X_X:
      complain (&unhandled_array_subscript_format, DIE_ID, DIE_NAME, format);
      complain (&unhandled_array_subscript_format, DIE_ID, DIE_NAME, format);
      nexttype = dwarf_fundamental_type (current_objfile, FT_INTEGER);
      nexttype = dwarf_fundamental_type (current_objfile, FT_INTEGER);
      rangetype = create_range_type ((struct type *) NULL, nexttype, 0, 0);
      rangetype = create_range_type ((struct type *) NULL, nexttype, 0, 0);
      typep = create_array_type ((struct type *) NULL, nexttype, rangetype);
      typep = create_array_type ((struct type *) NULL, nexttype, rangetype);
      break;
      break;
    default:
    default:
      complain (&unknown_array_subscript_format, DIE_ID, DIE_NAME, format);
      complain (&unknown_array_subscript_format, DIE_ID, DIE_NAME, format);
      nexttype = dwarf_fundamental_type (current_objfile, FT_INTEGER);
      nexttype = dwarf_fundamental_type (current_objfile, FT_INTEGER);
      rangetype = create_range_type ((struct type *) NULL, nexttype, 0, 0);
      rangetype = create_range_type ((struct type *) NULL, nexttype, 0, 0);
      typep = create_array_type ((struct type *) NULL, nexttype, rangetype);
      typep = create_array_type ((struct type *) NULL, nexttype, rangetype);
      break;
      break;
    }
    }
  return (typep);
  return (typep);
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   dwarf_read_array_type -- read TAG_array_type DIE
   dwarf_read_array_type -- read TAG_array_type DIE
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static void dwarf_read_array_type (struct dieinfo *dip)
   static void dwarf_read_array_type (struct dieinfo *dip)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Extract all information from a TAG_array_type DIE and add to
   Extract all information from a TAG_array_type DIE and add to
   the user defined type vector.
   the user defined type vector.
 */
 */
 
 
static void
static void
dwarf_read_array_type (dip)
dwarf_read_array_type (dip)
     struct dieinfo *dip;
     struct dieinfo *dip;
{
{
  struct type *type;
  struct type *type;
  struct type *utype;
  struct type *utype;
  char *sub;
  char *sub;
  char *subend;
  char *subend;
  unsigned short blocksz;
  unsigned short blocksz;
  int nbytes;
  int nbytes;
 
 
  if (dip->at_ordering != ORD_row_major)
  if (dip->at_ordering != ORD_row_major)
    {
    {
      /* FIXME:  Can gdb even handle column major arrays? */
      /* FIXME:  Can gdb even handle column major arrays? */
      complain (&not_row_major, DIE_ID, DIE_NAME);
      complain (&not_row_major, DIE_ID, DIE_NAME);
    }
    }
  if ((sub = dip->at_subscr_data) != NULL)
  if ((sub = dip->at_subscr_data) != NULL)
    {
    {
      nbytes = attribute_size (AT_subscr_data);
      nbytes = attribute_size (AT_subscr_data);
      blocksz = target_to_host (sub, nbytes, GET_UNSIGNED, current_objfile);
      blocksz = target_to_host (sub, nbytes, GET_UNSIGNED, current_objfile);
      subend = sub + nbytes + blocksz;
      subend = sub + nbytes + blocksz;
      sub += nbytes;
      sub += nbytes;
      type = decode_subscript_data_item (sub, subend);
      type = decode_subscript_data_item (sub, subend);
      if ((utype = lookup_utype (dip->die_ref)) == NULL)
      if ((utype = lookup_utype (dip->die_ref)) == NULL)
        {
        {
          /* Install user defined type that has not been referenced yet. */
          /* Install user defined type that has not been referenced yet. */
          alloc_utype (dip->die_ref, type);
          alloc_utype (dip->die_ref, type);
        }
        }
      else if (TYPE_CODE (utype) == TYPE_CODE_UNDEF)
      else if (TYPE_CODE (utype) == TYPE_CODE_UNDEF)
        {
        {
          /* Ick!  A forward ref has already generated a blank type in our
          /* Ick!  A forward ref has already generated a blank type in our
             slot, and this type probably already has things pointing to it
             slot, and this type probably already has things pointing to it
             (which is what caused it to be created in the first place).
             (which is what caused it to be created in the first place).
             If it's just a place holder we can plop our fully defined type
             If it's just a place holder we can plop our fully defined type
             on top of it.  We can't recover the space allocated for our
             on top of it.  We can't recover the space allocated for our
             new type since it might be on an obstack, but we could reuse
             new type since it might be on an obstack, but we could reuse
             it if we kept a list of them, but it might not be worth it
             it if we kept a list of them, but it might not be worth it
             (FIXME). */
             (FIXME). */
          *utype = *type;
          *utype = *type;
        }
        }
      else
      else
        {
        {
          /* Double ick!  Not only is a type already in our slot, but
          /* Double ick!  Not only is a type already in our slot, but
             someone has decorated it.  Complain and leave it alone. */
             someone has decorated it.  Complain and leave it alone. */
          complain (&dup_user_type_definition, DIE_ID, DIE_NAME);
          complain (&dup_user_type_definition, DIE_ID, DIE_NAME);
        }
        }
    }
    }
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   read_tag_pointer_type -- read TAG_pointer_type DIE
   read_tag_pointer_type -- read TAG_pointer_type DIE
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static void read_tag_pointer_type (struct dieinfo *dip)
   static void read_tag_pointer_type (struct dieinfo *dip)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Extract all information from a TAG_pointer_type DIE and add to
   Extract all information from a TAG_pointer_type DIE and add to
   the user defined type vector.
   the user defined type vector.
 */
 */
 
 
static void
static void
read_tag_pointer_type (dip)
read_tag_pointer_type (dip)
     struct dieinfo *dip;
     struct dieinfo *dip;
{
{
  struct type *type;
  struct type *type;
  struct type *utype;
  struct type *utype;
 
 
  type = decode_die_type (dip);
  type = decode_die_type (dip);
  if ((utype = lookup_utype (dip->die_ref)) == NULL)
  if ((utype = lookup_utype (dip->die_ref)) == NULL)
    {
    {
      utype = lookup_pointer_type (type);
      utype = lookup_pointer_type (type);
      alloc_utype (dip->die_ref, utype);
      alloc_utype (dip->die_ref, utype);
    }
    }
  else
  else
    {
    {
      TYPE_TARGET_TYPE (utype) = type;
      TYPE_TARGET_TYPE (utype) = type;
      TYPE_POINTER_TYPE (type) = utype;
      TYPE_POINTER_TYPE (type) = utype;
 
 
      /* We assume the machine has only one representation for pointers!  */
      /* We assume the machine has only one representation for pointers!  */
      /* FIXME:  Possably a poor assumption  */
      /* FIXME:  Possably a poor assumption  */
      TYPE_LENGTH (utype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
      TYPE_LENGTH (utype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
      TYPE_CODE (utype) = TYPE_CODE_PTR;
      TYPE_CODE (utype) = TYPE_CODE_PTR;
    }
    }
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   read_tag_string_type -- read TAG_string_type DIE
   read_tag_string_type -- read TAG_string_type DIE
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static void read_tag_string_type (struct dieinfo *dip)
   static void read_tag_string_type (struct dieinfo *dip)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Extract all information from a TAG_string_type DIE and add to
   Extract all information from a TAG_string_type DIE and add to
   the user defined type vector.  It isn't really a user defined
   the user defined type vector.  It isn't really a user defined
   type, but it behaves like one, with other DIE's using an
   type, but it behaves like one, with other DIE's using an
   AT_user_def_type attribute to reference it.
   AT_user_def_type attribute to reference it.
 */
 */
 
 
static void
static void
read_tag_string_type (dip)
read_tag_string_type (dip)
     struct dieinfo *dip;
     struct dieinfo *dip;
{
{
  struct type *utype;
  struct type *utype;
  struct type *indextype;
  struct type *indextype;
  struct type *rangetype;
  struct type *rangetype;
  unsigned long lowbound = 0;
  unsigned long lowbound = 0;
  unsigned long highbound;
  unsigned long highbound;
 
 
  if (dip->has_at_byte_size)
  if (dip->has_at_byte_size)
    {
    {
      /* A fixed bounds string */
      /* A fixed bounds string */
      highbound = dip->at_byte_size - 1;
      highbound = dip->at_byte_size - 1;
    }
    }
  else
  else
    {
    {
      /* A varying length string.  Stub for now.  (FIXME) */
      /* A varying length string.  Stub for now.  (FIXME) */
      highbound = 1;
      highbound = 1;
    }
    }
  indextype = dwarf_fundamental_type (current_objfile, FT_INTEGER);
  indextype = dwarf_fundamental_type (current_objfile, FT_INTEGER);
  rangetype = create_range_type ((struct type *) NULL, indextype, lowbound,
  rangetype = create_range_type ((struct type *) NULL, indextype, lowbound,
                                 highbound);
                                 highbound);
 
 
  utype = lookup_utype (dip->die_ref);
  utype = lookup_utype (dip->die_ref);
  if (utype == NULL)
  if (utype == NULL)
    {
    {
      /* No type defined, go ahead and create a blank one to use. */
      /* No type defined, go ahead and create a blank one to use. */
      utype = alloc_utype (dip->die_ref, (struct type *) NULL);
      utype = alloc_utype (dip->die_ref, (struct type *) NULL);
    }
    }
  else
  else
    {
    {
      /* Already a type in our slot due to a forward reference. Make sure it
      /* Already a type in our slot due to a forward reference. Make sure it
         is a blank one.  If not, complain and leave it alone. */
         is a blank one.  If not, complain and leave it alone. */
      if (TYPE_CODE (utype) != TYPE_CODE_UNDEF)
      if (TYPE_CODE (utype) != TYPE_CODE_UNDEF)
        {
        {
          complain (&dup_user_type_definition, DIE_ID, DIE_NAME);
          complain (&dup_user_type_definition, DIE_ID, DIE_NAME);
          return;
          return;
        }
        }
    }
    }
 
 
  /* Create the string type using the blank type we either found or created. */
  /* Create the string type using the blank type we either found or created. */
  utype = create_string_type (utype, rangetype);
  utype = create_string_type (utype, rangetype);
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   read_subroutine_type -- process TAG_subroutine_type dies
   read_subroutine_type -- process TAG_subroutine_type dies
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static void read_subroutine_type (struct dieinfo *dip, char thisdie,
   static void read_subroutine_type (struct dieinfo *dip, char thisdie,
   char *enddie)
   char *enddie)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Handle DIES due to C code like:
   Handle DIES due to C code like:
 
 
   struct foo {
   struct foo {
   int (*funcp)(int a, long l);  (Generates TAG_subroutine_type DIE)
   int (*funcp)(int a, long l);  (Generates TAG_subroutine_type DIE)
   int b;
   int b;
   };
   };
 
 
   NOTES
   NOTES
 
 
   The parameter DIES are currently ignored.  See if gdb has a way to
   The parameter DIES are currently ignored.  See if gdb has a way to
   include this info in it's type system, and decode them if so.  Is
   include this info in it's type system, and decode them if so.  Is
   this what the type structure's "arg_types" field is for?  (FIXME)
   this what the type structure's "arg_types" field is for?  (FIXME)
 */
 */
 
 
static void
static void
read_subroutine_type (dip, thisdie, enddie)
read_subroutine_type (dip, thisdie, enddie)
     struct dieinfo *dip;
     struct dieinfo *dip;
     char *thisdie;
     char *thisdie;
     char *enddie;
     char *enddie;
{
{
  struct type *type;            /* Type that this function returns */
  struct type *type;            /* Type that this function returns */
  struct type *ftype;           /* Function that returns above type */
  struct type *ftype;           /* Function that returns above type */
 
 
  /* Decode the type that this subroutine returns */
  /* Decode the type that this subroutine returns */
 
 
  type = decode_die_type (dip);
  type = decode_die_type (dip);
 
 
  /* Check to see if we already have a partially constructed user
  /* Check to see if we already have a partially constructed user
     defined type for this DIE, from a forward reference. */
     defined type for this DIE, from a forward reference. */
 
 
  if ((ftype = lookup_utype (dip->die_ref)) == NULL)
  if ((ftype = lookup_utype (dip->die_ref)) == NULL)
    {
    {
      /* This is the first reference to one of these types.  Make
      /* This is the first reference to one of these types.  Make
         a new one and place it in the user defined types. */
         a new one and place it in the user defined types. */
      ftype = lookup_function_type (type);
      ftype = lookup_function_type (type);
      alloc_utype (dip->die_ref, ftype);
      alloc_utype (dip->die_ref, ftype);
    }
    }
  else if (TYPE_CODE (ftype) == TYPE_CODE_UNDEF)
  else if (TYPE_CODE (ftype) == TYPE_CODE_UNDEF)
    {
    {
      /* We have an existing partially constructed type, so bash it
      /* We have an existing partially constructed type, so bash it
         into the correct type. */
         into the correct type. */
      TYPE_TARGET_TYPE (ftype) = type;
      TYPE_TARGET_TYPE (ftype) = type;
      TYPE_LENGTH (ftype) = 1;
      TYPE_LENGTH (ftype) = 1;
      TYPE_CODE (ftype) = TYPE_CODE_FUNC;
      TYPE_CODE (ftype) = TYPE_CODE_FUNC;
    }
    }
  else
  else
    {
    {
      complain (&dup_user_type_definition, DIE_ID, DIE_NAME);
      complain (&dup_user_type_definition, DIE_ID, DIE_NAME);
    }
    }
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   read_enumeration -- process dies which define an enumeration
   read_enumeration -- process dies which define an enumeration
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static void read_enumeration (struct dieinfo *dip, char *thisdie,
   static void read_enumeration (struct dieinfo *dip, char *thisdie,
   char *enddie, struct objfile *objfile)
   char *enddie, struct objfile *objfile)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Given a pointer to a die which begins an enumeration, process all
   Given a pointer to a die which begins an enumeration, process all
   the dies that define the members of the enumeration.
   the dies that define the members of the enumeration.
 
 
   NOTES
   NOTES
 
 
   Note that we need to call enum_type regardless of whether or not we
   Note that we need to call enum_type regardless of whether or not we
   have a symbol, since we might have an enum without a tag name (thus
   have a symbol, since we might have an enum without a tag name (thus
   no symbol for the tagname).
   no symbol for the tagname).
 */
 */
 
 
static void
static void
read_enumeration (dip, thisdie, enddie, objfile)
read_enumeration (dip, thisdie, enddie, objfile)
     struct dieinfo *dip;
     struct dieinfo *dip;
     char *thisdie;
     char *thisdie;
     char *enddie;
     char *enddie;
     struct objfile *objfile;
     struct objfile *objfile;
{
{
  struct type *type;
  struct type *type;
  struct symbol *sym;
  struct symbol *sym;
 
 
  type = enum_type (dip, objfile);
  type = enum_type (dip, objfile);
  sym = new_symbol (dip, objfile);
  sym = new_symbol (dip, objfile);
  if (sym != NULL)
  if (sym != NULL)
    {
    {
      SYMBOL_TYPE (sym) = type;
      SYMBOL_TYPE (sym) = type;
      if (cu_language == language_cplus)
      if (cu_language == language_cplus)
        {
        {
          synthesize_typedef (dip, objfile, type);
          synthesize_typedef (dip, objfile, type);
        }
        }
    }
    }
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   enum_type -- decode and return a type for an enumeration
   enum_type -- decode and return a type for an enumeration
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static type *enum_type (struct dieinfo *dip, struct objfile *objfile)
   static type *enum_type (struct dieinfo *dip, struct objfile *objfile)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Given a pointer to a die information structure for the die which
   Given a pointer to a die information structure for the die which
   starts an enumeration, process all the dies that define the members
   starts an enumeration, process all the dies that define the members
   of the enumeration and return a type pointer for the enumeration.
   of the enumeration and return a type pointer for the enumeration.
 
 
   At the same time, for each member of the enumeration, create a
   At the same time, for each member of the enumeration, create a
   symbol for it with namespace VAR_NAMESPACE and class LOC_CONST,
   symbol for it with namespace VAR_NAMESPACE and class LOC_CONST,
   and give it the type of the enumeration itself.
   and give it the type of the enumeration itself.
 
 
   NOTES
   NOTES
 
 
   Note that the DWARF specification explicitly mandates that enum
   Note that the DWARF specification explicitly mandates that enum
   constants occur in reverse order from the source program order,
   constants occur in reverse order from the source program order,
   for "consistency" and because this ordering is easier for many
   for "consistency" and because this ordering is easier for many
   compilers to generate. (Draft 6, sec 3.8.5, Enumeration type
   compilers to generate. (Draft 6, sec 3.8.5, Enumeration type
   Entries).  Because gdb wants to see the enum members in program
   Entries).  Because gdb wants to see the enum members in program
   source order, we have to ensure that the order gets reversed while
   source order, we have to ensure that the order gets reversed while
   we are processing them.
   we are processing them.
 */
 */
 
 
static struct type *
static struct type *
enum_type (dip, objfile)
enum_type (dip, objfile)
     struct dieinfo *dip;
     struct dieinfo *dip;
     struct objfile *objfile;
     struct objfile *objfile;
{
{
  struct type *type;
  struct type *type;
  struct nextfield
  struct nextfield
    {
    {
      struct nextfield *next;
      struct nextfield *next;
      struct field field;
      struct field field;
    };
    };
  struct nextfield *list = NULL;
  struct nextfield *list = NULL;
  struct nextfield *new;
  struct nextfield *new;
  int nfields = 0;
  int nfields = 0;
  int n;
  int n;
  char *scan;
  char *scan;
  char *listend;
  char *listend;
  unsigned short blocksz;
  unsigned short blocksz;
  struct symbol *sym;
  struct symbol *sym;
  int nbytes;
  int nbytes;
  int unsigned_enum = 1;
  int unsigned_enum = 1;
 
 
  if ((type = lookup_utype (dip->die_ref)) == NULL)
  if ((type = lookup_utype (dip->die_ref)) == NULL)
    {
    {
      /* No forward references created an empty type, so install one now */
      /* No forward references created an empty type, so install one now */
      type = alloc_utype (dip->die_ref, NULL);
      type = alloc_utype (dip->die_ref, NULL);
    }
    }
  TYPE_CODE (type) = TYPE_CODE_ENUM;
  TYPE_CODE (type) = TYPE_CODE_ENUM;
  /* Some compilers try to be helpful by inventing "fake" names for
  /* Some compilers try to be helpful by inventing "fake" names for
     anonymous enums, structures, and unions, like "~0fake" or ".0fake".
     anonymous enums, structures, and unions, like "~0fake" or ".0fake".
     Thanks, but no thanks... */
     Thanks, but no thanks... */
  if (dip->at_name != NULL
  if (dip->at_name != NULL
      && *dip->at_name != '~'
      && *dip->at_name != '~'
      && *dip->at_name != '.')
      && *dip->at_name != '.')
    {
    {
      TYPE_TAG_NAME (type) = obconcat (&objfile->type_obstack,
      TYPE_TAG_NAME (type) = obconcat (&objfile->type_obstack,
                                       "", "", dip->at_name);
                                       "", "", dip->at_name);
    }
    }
  if (dip->at_byte_size != 0)
  if (dip->at_byte_size != 0)
    {
    {
      TYPE_LENGTH (type) = dip->at_byte_size;
      TYPE_LENGTH (type) = dip->at_byte_size;
    }
    }
  if ((scan = dip->at_element_list) != NULL)
  if ((scan = dip->at_element_list) != NULL)
    {
    {
      if (dip->short_element_list)
      if (dip->short_element_list)
        {
        {
          nbytes = attribute_size (AT_short_element_list);
          nbytes = attribute_size (AT_short_element_list);
        }
        }
      else
      else
        {
        {
          nbytes = attribute_size (AT_element_list);
          nbytes = attribute_size (AT_element_list);
        }
        }
      blocksz = target_to_host (scan, nbytes, GET_UNSIGNED, objfile);
      blocksz = target_to_host (scan, nbytes, GET_UNSIGNED, objfile);
      listend = scan + nbytes + blocksz;
      listend = scan + nbytes + blocksz;
      scan += nbytes;
      scan += nbytes;
      while (scan < listend)
      while (scan < listend)
        {
        {
          new = (struct nextfield *) alloca (sizeof (struct nextfield));
          new = (struct nextfield *) alloca (sizeof (struct nextfield));
          new->next = list;
          new->next = list;
          list = new;
          list = new;
          FIELD_TYPE (list->field) = NULL;
          FIELD_TYPE (list->field) = NULL;
          FIELD_BITSIZE (list->field) = 0;
          FIELD_BITSIZE (list->field) = 0;
          FIELD_BITPOS (list->field) =
          FIELD_BITPOS (list->field) =
            target_to_host (scan, TARGET_FT_LONG_SIZE (objfile), GET_SIGNED,
            target_to_host (scan, TARGET_FT_LONG_SIZE (objfile), GET_SIGNED,
                            objfile);
                            objfile);
          scan += TARGET_FT_LONG_SIZE (objfile);
          scan += TARGET_FT_LONG_SIZE (objfile);
          list->field.name = obsavestring (scan, strlen (scan),
          list->field.name = obsavestring (scan, strlen (scan),
                                           &objfile->type_obstack);
                                           &objfile->type_obstack);
          scan += strlen (scan) + 1;
          scan += strlen (scan) + 1;
          nfields++;
          nfields++;
          /* Handcraft a new symbol for this enum member. */
          /* Handcraft a new symbol for this enum member. */
          sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
          sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
                                                 sizeof (struct symbol));
                                                 sizeof (struct symbol));
          memset (sym, 0, sizeof (struct symbol));
          memset (sym, 0, sizeof (struct symbol));
          SYMBOL_NAME (sym) = create_name (list->field.name,
          SYMBOL_NAME (sym) = create_name (list->field.name,
                                           &objfile->symbol_obstack);
                                           &objfile->symbol_obstack);
          SYMBOL_INIT_LANGUAGE_SPECIFIC (sym, cu_language);
          SYMBOL_INIT_LANGUAGE_SPECIFIC (sym, cu_language);
          SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
          SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
          SYMBOL_CLASS (sym) = LOC_CONST;
          SYMBOL_CLASS (sym) = LOC_CONST;
          SYMBOL_TYPE (sym) = type;
          SYMBOL_TYPE (sym) = type;
          SYMBOL_VALUE (sym) = FIELD_BITPOS (list->field);
          SYMBOL_VALUE (sym) = FIELD_BITPOS (list->field);
          if (SYMBOL_VALUE (sym) < 0)
          if (SYMBOL_VALUE (sym) < 0)
            unsigned_enum = 0;
            unsigned_enum = 0;
          add_symbol_to_list (sym, list_in_scope);
          add_symbol_to_list (sym, list_in_scope);
        }
        }
      /* Now create the vector of fields, and record how big it is. This is
      /* Now create the vector of fields, and record how big it is. This is
         where we reverse the order, by pulling the members off the list in
         where we reverse the order, by pulling the members off the list in
         reverse order from how they were inserted.  If we have no fields
         reverse order from how they were inserted.  If we have no fields
         (this is apparently possible in C++) then skip building a field
         (this is apparently possible in C++) then skip building a field
         vector. */
         vector. */
      if (nfields > 0)
      if (nfields > 0)
        {
        {
          if (unsigned_enum)
          if (unsigned_enum)
            TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
            TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
          TYPE_NFIELDS (type) = nfields;
          TYPE_NFIELDS (type) = nfields;
          TYPE_FIELDS (type) = (struct field *)
          TYPE_FIELDS (type) = (struct field *)
            obstack_alloc (&objfile->symbol_obstack, sizeof (struct field) * nfields);
            obstack_alloc (&objfile->symbol_obstack, sizeof (struct field) * nfields);
          /* Copy the saved-up fields into the field vector.  */
          /* Copy the saved-up fields into the field vector.  */
          for (n = 0; (n < nfields) && (list != NULL); list = list->next)
          for (n = 0; (n < nfields) && (list != NULL); list = list->next)
            {
            {
              TYPE_FIELD (type, n++) = list->field;
              TYPE_FIELD (type, n++) = list->field;
            }
            }
        }
        }
    }
    }
  return (type);
  return (type);
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   read_func_scope -- process all dies within a function scope
   read_func_scope -- process all dies within a function scope
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Process all dies within a given function scope.  We are passed
   Process all dies within a given function scope.  We are passed
   a die information structure pointer DIP for the die which
   a die information structure pointer DIP for the die which
   starts the function scope, and pointers into the raw die data
   starts the function scope, and pointers into the raw die data
   that define the dies within the function scope.
   that define the dies within the function scope.
 
 
   For now, we ignore lexical block scopes within the function.
   For now, we ignore lexical block scopes within the function.
   The problem is that AT&T cc does not define a DWARF lexical
   The problem is that AT&T cc does not define a DWARF lexical
   block scope for the function itself, while gcc defines a
   block scope for the function itself, while gcc defines a
   lexical block scope for the function.  We need to think about
   lexical block scope for the function.  We need to think about
   how to handle this difference, or if it is even a problem.
   how to handle this difference, or if it is even a problem.
   (FIXME)
   (FIXME)
 */
 */
 
 
static void
static void
read_func_scope (dip, thisdie, enddie, objfile)
read_func_scope (dip, thisdie, enddie, objfile)
     struct dieinfo *dip;
     struct dieinfo *dip;
     char *thisdie;
     char *thisdie;
     char *enddie;
     char *enddie;
     struct objfile *objfile;
     struct objfile *objfile;
{
{
  register struct context_stack *new;
  register struct context_stack *new;
 
 
  /* AT_name is absent if the function is described with an
  /* AT_name is absent if the function is described with an
     AT_abstract_origin tag.
     AT_abstract_origin tag.
     Ignore the function description for now to avoid GDB core dumps.
     Ignore the function description for now to avoid GDB core dumps.
     FIXME: Add code to handle AT_abstract_origin tags properly.  */
     FIXME: Add code to handle AT_abstract_origin tags properly.  */
  if (dip->at_name == NULL)
  if (dip->at_name == NULL)
    {
    {
      complain (&missing_at_name, DIE_ID);
      complain (&missing_at_name, DIE_ID);
      return;
      return;
    }
    }
 
 
  if (objfile->ei.entry_point >= dip->at_low_pc &&
  if (objfile->ei.entry_point >= dip->at_low_pc &&
      objfile->ei.entry_point < dip->at_high_pc)
      objfile->ei.entry_point < dip->at_high_pc)
    {
    {
      objfile->ei.entry_func_lowpc = dip->at_low_pc;
      objfile->ei.entry_func_lowpc = dip->at_low_pc;
      objfile->ei.entry_func_highpc = dip->at_high_pc;
      objfile->ei.entry_func_highpc = dip->at_high_pc;
    }
    }
  new = push_context (0, dip->at_low_pc);
  new = push_context (0, dip->at_low_pc);
  new->name = new_symbol (dip, objfile);
  new->name = new_symbol (dip, objfile);
  list_in_scope = &local_symbols;
  list_in_scope = &local_symbols;
  process_dies (thisdie + dip->die_length, enddie, objfile);
  process_dies (thisdie + dip->die_length, enddie, objfile);
  new = pop_context ();
  new = pop_context ();
  /* Make a block for the local symbols within.  */
  /* Make a block for the local symbols within.  */
  finish_block (new->name, &local_symbols, new->old_blocks,
  finish_block (new->name, &local_symbols, new->old_blocks,
                new->start_addr, dip->at_high_pc, objfile);
                new->start_addr, dip->at_high_pc, objfile);
  list_in_scope = &file_symbols;
  list_in_scope = &file_symbols;
}
}
 
 
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   handle_producer -- process the AT_producer attribute
   handle_producer -- process the AT_producer attribute
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Perform any operations that depend on finding a particular
   Perform any operations that depend on finding a particular
   AT_producer attribute.
   AT_producer attribute.
 
 
 */
 */
 
 
static void
static void
handle_producer (producer)
handle_producer (producer)
     char *producer;
     char *producer;
{
{
 
 
  /* If this compilation unit was compiled with g++ or gcc, then set the
  /* If this compilation unit was compiled with g++ or gcc, then set the
     processing_gcc_compilation flag. */
     processing_gcc_compilation flag. */
 
 
  if (STREQN (producer, GCC_PRODUCER, strlen (GCC_PRODUCER)))
  if (STREQN (producer, GCC_PRODUCER, strlen (GCC_PRODUCER)))
    {
    {
      char version = producer[strlen (GCC_PRODUCER)];
      char version = producer[strlen (GCC_PRODUCER)];
      processing_gcc_compilation = (version == '2' ? 2 : 1);
      processing_gcc_compilation = (version == '2' ? 2 : 1);
    }
    }
  else
  else
    {
    {
      processing_gcc_compilation =
      processing_gcc_compilation =
        STREQN (producer, GPLUS_PRODUCER, strlen (GPLUS_PRODUCER))
        STREQN (producer, GPLUS_PRODUCER, strlen (GPLUS_PRODUCER))
        || STREQN (producer, CHILL_PRODUCER, strlen (CHILL_PRODUCER));
        || STREQN (producer, CHILL_PRODUCER, strlen (CHILL_PRODUCER));
    }
    }
 
 
  /* Select a demangling style if we can identify the producer and if
  /* Select a demangling style if we can identify the producer and if
     the current style is auto.  We leave the current style alone if it
     the current style is auto.  We leave the current style alone if it
     is not auto.  We also leave the demangling style alone if we find a
     is not auto.  We also leave the demangling style alone if we find a
     gcc (cc1) producer, as opposed to a g++ (cc1plus) producer. */
     gcc (cc1) producer, as opposed to a g++ (cc1plus) producer. */
 
 
  if (AUTO_DEMANGLING)
  if (AUTO_DEMANGLING)
    {
    {
      if (STREQN (producer, GPLUS_PRODUCER, strlen (GPLUS_PRODUCER)))
      if (STREQN (producer, GPLUS_PRODUCER, strlen (GPLUS_PRODUCER)))
        {
        {
          set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
          set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
        }
        }
      else if (STREQN (producer, LCC_PRODUCER, strlen (LCC_PRODUCER)))
      else if (STREQN (producer, LCC_PRODUCER, strlen (LCC_PRODUCER)))
        {
        {
          set_demangling_style (LUCID_DEMANGLING_STYLE_STRING);
          set_demangling_style (LUCID_DEMANGLING_STYLE_STRING);
        }
        }
    }
    }
}
}
 
 
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   read_file_scope -- process all dies within a file scope
   read_file_scope -- process all dies within a file scope
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Process all dies within a given file scope.  We are passed a
   Process all dies within a given file scope.  We are passed a
   pointer to the die information structure for the die which
   pointer to the die information structure for the die which
   starts the file scope, and pointers into the raw die data which
   starts the file scope, and pointers into the raw die data which
   mark the range of dies within the file scope.
   mark the range of dies within the file scope.
 
 
   When the partial symbol table is built, the file offset for the line
   When the partial symbol table is built, the file offset for the line
   number table for each compilation unit is saved in the partial symbol
   number table for each compilation unit is saved in the partial symbol
   table entry for that compilation unit.  As the symbols for each
   table entry for that compilation unit.  As the symbols for each
   compilation unit are read, the line number table is read into memory
   compilation unit are read, the line number table is read into memory
   and the variable lnbase is set to point to it.  Thus all we have to
   and the variable lnbase is set to point to it.  Thus all we have to
   do is use lnbase to access the line number table for the current
   do is use lnbase to access the line number table for the current
   compilation unit.
   compilation unit.
 */
 */
 
 
static void
static void
read_file_scope (dip, thisdie, enddie, objfile)
read_file_scope (dip, thisdie, enddie, objfile)
     struct dieinfo *dip;
     struct dieinfo *dip;
     char *thisdie;
     char *thisdie;
     char *enddie;
     char *enddie;
     struct objfile *objfile;
     struct objfile *objfile;
{
{
  struct cleanup *back_to;
  struct cleanup *back_to;
  struct symtab *symtab;
  struct symtab *symtab;
 
 
  if (objfile->ei.entry_point >= dip->at_low_pc &&
  if (objfile->ei.entry_point >= dip->at_low_pc &&
      objfile->ei.entry_point < dip->at_high_pc)
      objfile->ei.entry_point < dip->at_high_pc)
    {
    {
      objfile->ei.entry_file_lowpc = dip->at_low_pc;
      objfile->ei.entry_file_lowpc = dip->at_low_pc;
      objfile->ei.entry_file_highpc = dip->at_high_pc;
      objfile->ei.entry_file_highpc = dip->at_high_pc;
    }
    }
  set_cu_language (dip);
  set_cu_language (dip);
  if (dip->at_producer != NULL)
  if (dip->at_producer != NULL)
    {
    {
      handle_producer (dip->at_producer);
      handle_producer (dip->at_producer);
    }
    }
  numutypes = (enddie - thisdie) / 4;
  numutypes = (enddie - thisdie) / 4;
  utypes = (struct type **) xmalloc (numutypes * sizeof (struct type *));
  utypes = (struct type **) xmalloc (numutypes * sizeof (struct type *));
  back_to = make_cleanup (free_utypes, NULL);
  back_to = make_cleanup (free_utypes, NULL);
  memset (utypes, 0, numutypes * sizeof (struct type *));
  memset (utypes, 0, numutypes * sizeof (struct type *));
  memset (ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *));
  memset (ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *));
  start_symtab (dip->at_name, dip->at_comp_dir, dip->at_low_pc);
  start_symtab (dip->at_name, dip->at_comp_dir, dip->at_low_pc);
  record_debugformat ("DWARF 1");
  record_debugformat ("DWARF 1");
  decode_line_numbers (lnbase);
  decode_line_numbers (lnbase);
  process_dies (thisdie + dip->die_length, enddie, objfile);
  process_dies (thisdie + dip->die_length, enddie, objfile);
 
 
  symtab = end_symtab (dip->at_high_pc, objfile, 0);
  symtab = end_symtab (dip->at_high_pc, objfile, 0);
  if (symtab != NULL)
  if (symtab != NULL)
    {
    {
      symtab->language = cu_language;
      symtab->language = cu_language;
    }
    }
  do_cleanups (back_to);
  do_cleanups (back_to);
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   process_dies -- process a range of DWARF Information Entries
   process_dies -- process a range of DWARF Information Entries
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static void process_dies (char *thisdie, char *enddie,
   static void process_dies (char *thisdie, char *enddie,
   struct objfile *objfile)
   struct objfile *objfile)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Process all DIE's in a specified range.  May be (and almost
   Process all DIE's in a specified range.  May be (and almost
   certainly will be) called recursively.
   certainly will be) called recursively.
 */
 */
 
 
static void
static void
process_dies (thisdie, enddie, objfile)
process_dies (thisdie, enddie, objfile)
     char *thisdie;
     char *thisdie;
     char *enddie;
     char *enddie;
     struct objfile *objfile;
     struct objfile *objfile;
{
{
  char *nextdie;
  char *nextdie;
  struct dieinfo di;
  struct dieinfo di;
 
 
  while (thisdie < enddie)
  while (thisdie < enddie)
    {
    {
      basicdieinfo (&di, thisdie, objfile);
      basicdieinfo (&di, thisdie, objfile);
      if (di.die_length < SIZEOF_DIE_LENGTH)
      if (di.die_length < SIZEOF_DIE_LENGTH)
        {
        {
          break;
          break;
        }
        }
      else if (di.die_tag == TAG_padding)
      else if (di.die_tag == TAG_padding)
        {
        {
          nextdie = thisdie + di.die_length;
          nextdie = thisdie + di.die_length;
        }
        }
      else
      else
        {
        {
          completedieinfo (&di, objfile);
          completedieinfo (&di, objfile);
          if (di.at_sibling != 0)
          if (di.at_sibling != 0)
            {
            {
              nextdie = dbbase + di.at_sibling - dbroff;
              nextdie = dbbase + di.at_sibling - dbroff;
            }
            }
          else
          else
            {
            {
              nextdie = thisdie + di.die_length;
              nextdie = thisdie + di.die_length;
            }
            }
#ifdef SMASH_TEXT_ADDRESS
#ifdef SMASH_TEXT_ADDRESS
          /* I think that these are always text, not data, addresses.  */
          /* I think that these are always text, not data, addresses.  */
          SMASH_TEXT_ADDRESS (di.at_low_pc);
          SMASH_TEXT_ADDRESS (di.at_low_pc);
          SMASH_TEXT_ADDRESS (di.at_high_pc);
          SMASH_TEXT_ADDRESS (di.at_high_pc);
#endif
#endif
          switch (di.die_tag)
          switch (di.die_tag)
            {
            {
            case TAG_compile_unit:
            case TAG_compile_unit:
              /* Skip Tag_compile_unit if we are already inside a compilation
              /* Skip Tag_compile_unit if we are already inside a compilation
                 unit, we are unable to handle nested compilation units
                 unit, we are unable to handle nested compilation units
                 properly (FIXME).  */
                 properly (FIXME).  */
              if (current_subfile == NULL)
              if (current_subfile == NULL)
                read_file_scope (&di, thisdie, nextdie, objfile);
                read_file_scope (&di, thisdie, nextdie, objfile);
              else
              else
                nextdie = thisdie + di.die_length;
                nextdie = thisdie + di.die_length;
              break;
              break;
            case TAG_global_subroutine:
            case TAG_global_subroutine:
            case TAG_subroutine:
            case TAG_subroutine:
              if (di.has_at_low_pc)
              if (di.has_at_low_pc)
                {
                {
                  read_func_scope (&di, thisdie, nextdie, objfile);
                  read_func_scope (&di, thisdie, nextdie, objfile);
                }
                }
              break;
              break;
            case TAG_lexical_block:
            case TAG_lexical_block:
              read_lexical_block_scope (&di, thisdie, nextdie, objfile);
              read_lexical_block_scope (&di, thisdie, nextdie, objfile);
              break;
              break;
            case TAG_class_type:
            case TAG_class_type:
            case TAG_structure_type:
            case TAG_structure_type:
            case TAG_union_type:
            case TAG_union_type:
              read_structure_scope (&di, thisdie, nextdie, objfile);
              read_structure_scope (&di, thisdie, nextdie, objfile);
              break;
              break;
            case TAG_enumeration_type:
            case TAG_enumeration_type:
              read_enumeration (&di, thisdie, nextdie, objfile);
              read_enumeration (&di, thisdie, nextdie, objfile);
              break;
              break;
            case TAG_subroutine_type:
            case TAG_subroutine_type:
              read_subroutine_type (&di, thisdie, nextdie);
              read_subroutine_type (&di, thisdie, nextdie);
              break;
              break;
            case TAG_array_type:
            case TAG_array_type:
              dwarf_read_array_type (&di);
              dwarf_read_array_type (&di);
              break;
              break;
            case TAG_pointer_type:
            case TAG_pointer_type:
              read_tag_pointer_type (&di);
              read_tag_pointer_type (&di);
              break;
              break;
            case TAG_string_type:
            case TAG_string_type:
              read_tag_string_type (&di);
              read_tag_string_type (&di);
              break;
              break;
            default:
            default:
              new_symbol (&di, objfile);
              new_symbol (&di, objfile);
              break;
              break;
            }
            }
        }
        }
      thisdie = nextdie;
      thisdie = nextdie;
    }
    }
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   decode_line_numbers -- decode a line number table fragment
   decode_line_numbers -- decode a line number table fragment
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static void decode_line_numbers (char *tblscan, char *tblend,
   static void decode_line_numbers (char *tblscan, char *tblend,
   long length, long base, long line, long pc)
   long length, long base, long line, long pc)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Translate the DWARF line number information to gdb form.
   Translate the DWARF line number information to gdb form.
 
 
   The ".line" section contains one or more line number tables, one for
   The ".line" section contains one or more line number tables, one for
   each ".line" section from the objects that were linked.
   each ".line" section from the objects that were linked.
 
 
   The AT_stmt_list attribute for each TAG_source_file entry in the
   The AT_stmt_list attribute for each TAG_source_file entry in the
   ".debug" section contains the offset into the ".line" section for the
   ".debug" section contains the offset into the ".line" section for the
   start of the table for that file.
   start of the table for that file.
 
 
   The table itself has the following structure:
   The table itself has the following structure:
 
 
   <table length><base address><source statement entry>
   <table length><base address><source statement entry>
   4 bytes       4 bytes       10 bytes
   4 bytes       4 bytes       10 bytes
 
 
   The table length is the total size of the table, including the 4 bytes
   The table length is the total size of the table, including the 4 bytes
   for the length information.
   for the length information.
 
 
   The base address is the address of the first instruction generated
   The base address is the address of the first instruction generated
   for the source file.
   for the source file.
 
 
   Each source statement entry has the following structure:
   Each source statement entry has the following structure:
 
 
   <line number><statement position><address delta>
   <line number><statement position><address delta>
   4 bytes      2 bytes             4 bytes
   4 bytes      2 bytes             4 bytes
 
 
   The line number is relative to the start of the file, starting with
   The line number is relative to the start of the file, starting with
   line 1.
   line 1.
 
 
   The statement position either -1 (0xFFFF) or the number of characters
   The statement position either -1 (0xFFFF) or the number of characters
   from the beginning of the line to the beginning of the statement.
   from the beginning of the line to the beginning of the statement.
 
 
   The address delta is the difference between the base address and
   The address delta is the difference between the base address and
   the address of the first instruction for the statement.
   the address of the first instruction for the statement.
 
 
   Note that we must copy the bytes from the packed table to our local
   Note that we must copy the bytes from the packed table to our local
   variables before attempting to use them, to avoid alignment problems
   variables before attempting to use them, to avoid alignment problems
   on some machines, particularly RISC processors.
   on some machines, particularly RISC processors.
 
 
   BUGS
   BUGS
 
 
   Does gdb expect the line numbers to be sorted?  They are now by
   Does gdb expect the line numbers to be sorted?  They are now by
   chance/luck, but are not required to be.  (FIXME)
   chance/luck, but are not required to be.  (FIXME)
 
 
   The line with number 0 is unused, gdb apparently can discover the
   The line with number 0 is unused, gdb apparently can discover the
   span of the last line some other way. How?  (FIXME)
   span of the last line some other way. How?  (FIXME)
 */
 */
 
 
static void
static void
decode_line_numbers (linetable)
decode_line_numbers (linetable)
     char *linetable;
     char *linetable;
{
{
  char *tblscan;
  char *tblscan;
  char *tblend;
  char *tblend;
  unsigned long length;
  unsigned long length;
  unsigned long base;
  unsigned long base;
  unsigned long line;
  unsigned long line;
  unsigned long pc;
  unsigned long pc;
 
 
  if (linetable != NULL)
  if (linetable != NULL)
    {
    {
      tblscan = tblend = linetable;
      tblscan = tblend = linetable;
      length = target_to_host (tblscan, SIZEOF_LINETBL_LENGTH, GET_UNSIGNED,
      length = target_to_host (tblscan, SIZEOF_LINETBL_LENGTH, GET_UNSIGNED,
                               current_objfile);
                               current_objfile);
      tblscan += SIZEOF_LINETBL_LENGTH;
      tblscan += SIZEOF_LINETBL_LENGTH;
      tblend += length;
      tblend += length;
      base = target_to_host (tblscan, TARGET_FT_POINTER_SIZE (objfile),
      base = target_to_host (tblscan, TARGET_FT_POINTER_SIZE (objfile),
                             GET_UNSIGNED, current_objfile);
                             GET_UNSIGNED, current_objfile);
      tblscan += TARGET_FT_POINTER_SIZE (objfile);
      tblscan += TARGET_FT_POINTER_SIZE (objfile);
      base += baseaddr;
      base += baseaddr;
      while (tblscan < tblend)
      while (tblscan < tblend)
        {
        {
          line = target_to_host (tblscan, SIZEOF_LINETBL_LINENO, GET_UNSIGNED,
          line = target_to_host (tblscan, SIZEOF_LINETBL_LINENO, GET_UNSIGNED,
                                 current_objfile);
                                 current_objfile);
          tblscan += SIZEOF_LINETBL_LINENO + SIZEOF_LINETBL_STMT;
          tblscan += SIZEOF_LINETBL_LINENO + SIZEOF_LINETBL_STMT;
          pc = target_to_host (tblscan, SIZEOF_LINETBL_DELTA, GET_UNSIGNED,
          pc = target_to_host (tblscan, SIZEOF_LINETBL_DELTA, GET_UNSIGNED,
                               current_objfile);
                               current_objfile);
          tblscan += SIZEOF_LINETBL_DELTA;
          tblscan += SIZEOF_LINETBL_DELTA;
          pc += base;
          pc += base;
          if (line != 0)
          if (line != 0)
            {
            {
              record_line (current_subfile, line, pc);
              record_line (current_subfile, line, pc);
            }
            }
        }
        }
    }
    }
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   locval -- compute the value of a location attribute
   locval -- compute the value of a location attribute
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static int locval (struct dieinfo *dip)
   static int locval (struct dieinfo *dip)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Given pointer to a string of bytes that define a location, compute
   Given pointer to a string of bytes that define a location, compute
   the location and return the value.
   the location and return the value.
   A location description containing no atoms indicates that the
   A location description containing no atoms indicates that the
   object is optimized out. The optimized_out flag is set for those,
   object is optimized out. The optimized_out flag is set for those,
   the return value is meaningless.
   the return value is meaningless.
 
 
   When computing values involving the current value of the frame pointer,
   When computing values involving the current value of the frame pointer,
   the value zero is used, which results in a value relative to the frame
   the value zero is used, which results in a value relative to the frame
   pointer, rather than the absolute value.  This is what GDB wants
   pointer, rather than the absolute value.  This is what GDB wants
   anyway.
   anyway.
 
 
   When the result is a register number, the isreg flag is set, otherwise
   When the result is a register number, the isreg flag is set, otherwise
   it is cleared.  This is a kludge until we figure out a better
   it is cleared.  This is a kludge until we figure out a better
   way to handle the problem.  Gdb's design does not mesh well with the
   way to handle the problem.  Gdb's design does not mesh well with the
   DWARF notion of a location computing interpreter, which is a shame
   DWARF notion of a location computing interpreter, which is a shame
   because the flexibility goes unused.
   because the flexibility goes unused.
 
 
   NOTES
   NOTES
 
 
   Note that stack[0] is unused except as a default error return.
   Note that stack[0] is unused except as a default error return.
   Note that stack overflow is not yet handled.
   Note that stack overflow is not yet handled.
 */
 */
 
 
static int
static int
locval (dip)
locval (dip)
     struct dieinfo *dip;
     struct dieinfo *dip;
{
{
  unsigned short nbytes;
  unsigned short nbytes;
  unsigned short locsize;
  unsigned short locsize;
  auto long stack[64];
  auto long stack[64];
  int stacki;
  int stacki;
  char *loc;
  char *loc;
  char *end;
  char *end;
  int loc_atom_code;
  int loc_atom_code;
  int loc_value_size;
  int loc_value_size;
 
 
  loc = dip->at_location;
  loc = dip->at_location;
  nbytes = attribute_size (AT_location);
  nbytes = attribute_size (AT_location);
  locsize = target_to_host (loc, nbytes, GET_UNSIGNED, current_objfile);
  locsize = target_to_host (loc, nbytes, GET_UNSIGNED, current_objfile);
  loc += nbytes;
  loc += nbytes;
  end = loc + locsize;
  end = loc + locsize;
  stacki = 0;
  stacki = 0;
  stack[stacki] = 0;
  stack[stacki] = 0;
  dip->isreg = 0;
  dip->isreg = 0;
  dip->offreg = 0;
  dip->offreg = 0;
  dip->optimized_out = 1;
  dip->optimized_out = 1;
  loc_value_size = TARGET_FT_LONG_SIZE (current_objfile);
  loc_value_size = TARGET_FT_LONG_SIZE (current_objfile);
  while (loc < end)
  while (loc < end)
    {
    {
      dip->optimized_out = 0;
      dip->optimized_out = 0;
      loc_atom_code = target_to_host (loc, SIZEOF_LOC_ATOM_CODE, GET_UNSIGNED,
      loc_atom_code = target_to_host (loc, SIZEOF_LOC_ATOM_CODE, GET_UNSIGNED,
                                      current_objfile);
                                      current_objfile);
      loc += SIZEOF_LOC_ATOM_CODE;
      loc += SIZEOF_LOC_ATOM_CODE;
      switch (loc_atom_code)
      switch (loc_atom_code)
        {
        {
        case 0:
        case 0:
          /* error */
          /* error */
          loc = end;
          loc = end;
          break;
          break;
        case OP_REG:
        case OP_REG:
          /* push register (number) */
          /* push register (number) */
          stack[++stacki]
          stack[++stacki]
            = DWARF_REG_TO_REGNUM (target_to_host (loc, loc_value_size,
            = DWARF_REG_TO_REGNUM (target_to_host (loc, loc_value_size,
                                                   GET_UNSIGNED,
                                                   GET_UNSIGNED,
                                                   current_objfile));
                                                   current_objfile));
          loc += loc_value_size;
          loc += loc_value_size;
          dip->isreg = 1;
          dip->isreg = 1;
          break;
          break;
        case OP_BASEREG:
        case OP_BASEREG:
          /* push value of register (number) */
          /* push value of register (number) */
          /* Actually, we compute the value as if register has 0, so the
          /* Actually, we compute the value as if register has 0, so the
             value ends up being the offset from that register.  */
             value ends up being the offset from that register.  */
          dip->offreg = 1;
          dip->offreg = 1;
          dip->basereg = target_to_host (loc, loc_value_size, GET_UNSIGNED,
          dip->basereg = target_to_host (loc, loc_value_size, GET_UNSIGNED,
                                         current_objfile);
                                         current_objfile);
          loc += loc_value_size;
          loc += loc_value_size;
          stack[++stacki] = 0;
          stack[++stacki] = 0;
          break;
          break;
        case OP_ADDR:
        case OP_ADDR:
          /* push address (relocated address) */
          /* push address (relocated address) */
          stack[++stacki] = target_to_host (loc, loc_value_size,
          stack[++stacki] = target_to_host (loc, loc_value_size,
                                            GET_UNSIGNED, current_objfile);
                                            GET_UNSIGNED, current_objfile);
          loc += loc_value_size;
          loc += loc_value_size;
          break;
          break;
        case OP_CONST:
        case OP_CONST:
          /* push constant (number)   FIXME: signed or unsigned! */
          /* push constant (number)   FIXME: signed or unsigned! */
          stack[++stacki] = target_to_host (loc, loc_value_size,
          stack[++stacki] = target_to_host (loc, loc_value_size,
                                            GET_SIGNED, current_objfile);
                                            GET_SIGNED, current_objfile);
          loc += loc_value_size;
          loc += loc_value_size;
          break;
          break;
        case OP_DEREF2:
        case OP_DEREF2:
          /* pop, deref and push 2 bytes (as a long) */
          /* pop, deref and push 2 bytes (as a long) */
          complain (&op_deref2, DIE_ID, DIE_NAME, stack[stacki]);
          complain (&op_deref2, DIE_ID, DIE_NAME, stack[stacki]);
          break;
          break;
        case OP_DEREF4: /* pop, deref and push 4 bytes (as a long) */
        case OP_DEREF4: /* pop, deref and push 4 bytes (as a long) */
          complain (&op_deref4, DIE_ID, DIE_NAME, stack[stacki]);
          complain (&op_deref4, DIE_ID, DIE_NAME, stack[stacki]);
          break;
          break;
        case OP_ADD:            /* pop top 2 items, add, push result */
        case OP_ADD:            /* pop top 2 items, add, push result */
          stack[stacki - 1] += stack[stacki];
          stack[stacki - 1] += stack[stacki];
          stacki--;
          stacki--;
          break;
          break;
        }
        }
    }
    }
  return (stack[stacki]);
  return (stack[stacki]);
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   read_ofile_symtab -- build a full symtab entry from chunk of DIE's
   read_ofile_symtab -- build a full symtab entry from chunk of DIE's
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static void read_ofile_symtab (struct partial_symtab *pst)
   static void read_ofile_symtab (struct partial_symtab *pst)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   When expanding a partial symbol table entry to a full symbol table
   When expanding a partial symbol table entry to a full symbol table
   entry, this is the function that gets called to read in the symbols
   entry, this is the function that gets called to read in the symbols
   for the compilation unit.  A pointer to the newly constructed symtab,
   for the compilation unit.  A pointer to the newly constructed symtab,
   which is now the new first one on the objfile's symtab list, is
   which is now the new first one on the objfile's symtab list, is
   stashed in the partial symbol table entry.
   stashed in the partial symbol table entry.
 */
 */
 
 
static void
static void
read_ofile_symtab (pst)
read_ofile_symtab (pst)
     struct partial_symtab *pst;
     struct partial_symtab *pst;
{
{
  struct cleanup *back_to;
  struct cleanup *back_to;
  unsigned long lnsize;
  unsigned long lnsize;
  file_ptr foffset;
  file_ptr foffset;
  bfd *abfd;
  bfd *abfd;
  char lnsizedata[SIZEOF_LINETBL_LENGTH];
  char lnsizedata[SIZEOF_LINETBL_LENGTH];
 
 
  abfd = pst->objfile->obfd;
  abfd = pst->objfile->obfd;
  current_objfile = pst->objfile;
  current_objfile = pst->objfile;
 
 
  /* Allocate a buffer for the entire chunk of DIE's for this compilation
  /* Allocate a buffer for the entire chunk of DIE's for this compilation
     unit, seek to the location in the file, and read in all the DIE's. */
     unit, seek to the location in the file, and read in all the DIE's. */
 
 
  diecount = 0;
  diecount = 0;
  dbsize = DBLENGTH (pst);
  dbsize = DBLENGTH (pst);
  dbbase = xmalloc (dbsize);
  dbbase = xmalloc (dbsize);
  dbroff = DBROFF (pst);
  dbroff = DBROFF (pst);
  foffset = DBFOFF (pst) + dbroff;
  foffset = DBFOFF (pst) + dbroff;
  base_section_offsets = pst->section_offsets;
  base_section_offsets = pst->section_offsets;
  baseaddr = ANOFFSET (pst->section_offsets, 0);
  baseaddr = ANOFFSET (pst->section_offsets, 0);
  if (bfd_seek (abfd, foffset, SEEK_SET) ||
  if (bfd_seek (abfd, foffset, SEEK_SET) ||
      (bfd_read (dbbase, dbsize, 1, abfd) != dbsize))
      (bfd_read (dbbase, dbsize, 1, abfd) != dbsize))
    {
    {
      free (dbbase);
      free (dbbase);
      error ("can't read DWARF data");
      error ("can't read DWARF data");
    }
    }
  back_to = make_cleanup (free, dbbase);
  back_to = make_cleanup (free, dbbase);
 
 
  /* If there is a line number table associated with this compilation unit
  /* If there is a line number table associated with this compilation unit
     then read the size of this fragment in bytes, from the fragment itself.
     then read the size of this fragment in bytes, from the fragment itself.
     Allocate a buffer for the fragment and read it in for future
     Allocate a buffer for the fragment and read it in for future
     processing. */
     processing. */
 
 
  lnbase = NULL;
  lnbase = NULL;
  if (LNFOFF (pst))
  if (LNFOFF (pst))
    {
    {
      if (bfd_seek (abfd, LNFOFF (pst), SEEK_SET) ||
      if (bfd_seek (abfd, LNFOFF (pst), SEEK_SET) ||
          (bfd_read ((PTR) lnsizedata, sizeof (lnsizedata), 1, abfd) !=
          (bfd_read ((PTR) lnsizedata, sizeof (lnsizedata), 1, abfd) !=
           sizeof (lnsizedata)))
           sizeof (lnsizedata)))
        {
        {
          error ("can't read DWARF line number table size");
          error ("can't read DWARF line number table size");
        }
        }
      lnsize = target_to_host (lnsizedata, SIZEOF_LINETBL_LENGTH,
      lnsize = target_to_host (lnsizedata, SIZEOF_LINETBL_LENGTH,
                               GET_UNSIGNED, pst->objfile);
                               GET_UNSIGNED, pst->objfile);
      lnbase = xmalloc (lnsize);
      lnbase = xmalloc (lnsize);
      if (bfd_seek (abfd, LNFOFF (pst), SEEK_SET) ||
      if (bfd_seek (abfd, LNFOFF (pst), SEEK_SET) ||
          (bfd_read (lnbase, lnsize, 1, abfd) != lnsize))
          (bfd_read (lnbase, lnsize, 1, abfd) != lnsize))
        {
        {
          free (lnbase);
          free (lnbase);
          error ("can't read DWARF line numbers");
          error ("can't read DWARF line numbers");
        }
        }
      make_cleanup (free, lnbase);
      make_cleanup (free, lnbase);
    }
    }
 
 
  process_dies (dbbase, dbbase + dbsize, pst->objfile);
  process_dies (dbbase, dbbase + dbsize, pst->objfile);
  do_cleanups (back_to);
  do_cleanups (back_to);
  current_objfile = NULL;
  current_objfile = NULL;
  pst->symtab = pst->objfile->symtabs;
  pst->symtab = pst->objfile->symtabs;
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   psymtab_to_symtab_1 -- do grunt work for building a full symtab entry
   psymtab_to_symtab_1 -- do grunt work for building a full symtab entry
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static void psymtab_to_symtab_1 (struct partial_symtab *pst)
   static void psymtab_to_symtab_1 (struct partial_symtab *pst)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Called once for each partial symbol table entry that needs to be
   Called once for each partial symbol table entry that needs to be
   expanded into a full symbol table entry.
   expanded into a full symbol table entry.
 
 
 */
 */
 
 
static void
static void
psymtab_to_symtab_1 (pst)
psymtab_to_symtab_1 (pst)
     struct partial_symtab *pst;
     struct partial_symtab *pst;
{
{
  int i;
  int i;
  struct cleanup *old_chain;
  struct cleanup *old_chain;
 
 
  if (pst != NULL)
  if (pst != NULL)
    {
    {
      if (pst->readin)
      if (pst->readin)
        {
        {
          warning ("psymtab for %s already read in.  Shouldn't happen.",
          warning ("psymtab for %s already read in.  Shouldn't happen.",
                   pst->filename);
                   pst->filename);
        }
        }
      else
      else
        {
        {
          /* Read in all partial symtabs on which this one is dependent */
          /* Read in all partial symtabs on which this one is dependent */
          for (i = 0; i < pst->number_of_dependencies; i++)
          for (i = 0; i < pst->number_of_dependencies; i++)
            {
            {
              if (!pst->dependencies[i]->readin)
              if (!pst->dependencies[i]->readin)
                {
                {
                  /* Inform about additional files that need to be read in. */
                  /* Inform about additional files that need to be read in. */
                  if (info_verbose)
                  if (info_verbose)
                    {
                    {
                      fputs_filtered (" ", gdb_stdout);
                      fputs_filtered (" ", gdb_stdout);
                      wrap_here ("");
                      wrap_here ("");
                      fputs_filtered ("and ", gdb_stdout);
                      fputs_filtered ("and ", gdb_stdout);
                      wrap_here ("");
                      wrap_here ("");
                      printf_filtered ("%s...",
                      printf_filtered ("%s...",
                                       pst->dependencies[i]->filename);
                                       pst->dependencies[i]->filename);
                      wrap_here ("");
                      wrap_here ("");
                      gdb_flush (gdb_stdout);   /* Flush output */
                      gdb_flush (gdb_stdout);   /* Flush output */
                    }
                    }
                  psymtab_to_symtab_1 (pst->dependencies[i]);
                  psymtab_to_symtab_1 (pst->dependencies[i]);
                }
                }
            }
            }
          if (DBLENGTH (pst))   /* Otherwise it's a dummy */
          if (DBLENGTH (pst))   /* Otherwise it's a dummy */
            {
            {
              buildsym_init ();
              buildsym_init ();
              old_chain = make_cleanup (really_free_pendings, 0);
              old_chain = make_cleanup (really_free_pendings, 0);
              read_ofile_symtab (pst);
              read_ofile_symtab (pst);
              if (info_verbose)
              if (info_verbose)
                {
                {
                  printf_filtered ("%d DIE's, sorting...", diecount);
                  printf_filtered ("%d DIE's, sorting...", diecount);
                  wrap_here ("");
                  wrap_here ("");
                  gdb_flush (gdb_stdout);
                  gdb_flush (gdb_stdout);
                }
                }
              sort_symtab_syms (pst->symtab);
              sort_symtab_syms (pst->symtab);
              do_cleanups (old_chain);
              do_cleanups (old_chain);
            }
            }
          pst->readin = 1;
          pst->readin = 1;
        }
        }
    }
    }
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   dwarf_psymtab_to_symtab -- build a full symtab entry from partial one
   dwarf_psymtab_to_symtab -- build a full symtab entry from partial one
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static void dwarf_psymtab_to_symtab (struct partial_symtab *pst)
   static void dwarf_psymtab_to_symtab (struct partial_symtab *pst)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   This is the DWARF support entry point for building a full symbol
   This is the DWARF support entry point for building a full symbol
   table entry from a partial symbol table entry.  We are passed a
   table entry from a partial symbol table entry.  We are passed a
   pointer to the partial symbol table entry that needs to be expanded.
   pointer to the partial symbol table entry that needs to be expanded.
 
 
 */
 */
 
 
static void
static void
dwarf_psymtab_to_symtab (pst)
dwarf_psymtab_to_symtab (pst)
     struct partial_symtab *pst;
     struct partial_symtab *pst;
{
{
 
 
  if (pst != NULL)
  if (pst != NULL)
    {
    {
      if (pst->readin)
      if (pst->readin)
        {
        {
          warning ("psymtab for %s already read in.  Shouldn't happen.",
          warning ("psymtab for %s already read in.  Shouldn't happen.",
                   pst->filename);
                   pst->filename);
        }
        }
      else
      else
        {
        {
          if (DBLENGTH (pst) || pst->number_of_dependencies)
          if (DBLENGTH (pst) || pst->number_of_dependencies)
            {
            {
              /* Print the message now, before starting serious work, to avoid
              /* Print the message now, before starting serious work, to avoid
                 disconcerting pauses.  */
                 disconcerting pauses.  */
              if (info_verbose)
              if (info_verbose)
                {
                {
                  printf_filtered ("Reading in symbols for %s...",
                  printf_filtered ("Reading in symbols for %s...",
                                   pst->filename);
                                   pst->filename);
                  gdb_flush (gdb_stdout);
                  gdb_flush (gdb_stdout);
                }
                }
 
 
              psymtab_to_symtab_1 (pst);
              psymtab_to_symtab_1 (pst);
 
 
#if 0                           /* FIXME:  Check to see what dbxread is doing here and see if
#if 0                           /* FIXME:  Check to see what dbxread is doing here and see if
                                   we need to do an equivalent or is this something peculiar to
                                   we need to do an equivalent or is this something peculiar to
                                   stabs/a.out format.
                                   stabs/a.out format.
                                   Match with global symbols.  This only needs to be done once,
                                   Match with global symbols.  This only needs to be done once,
                                   after all of the symtabs and dependencies have been read in.
                                   after all of the symtabs and dependencies have been read in.
                                 */
                                 */
              scan_file_globals (pst->objfile);
              scan_file_globals (pst->objfile);
#endif
#endif
 
 
              /* Finish up the verbose info message.  */
              /* Finish up the verbose info message.  */
              if (info_verbose)
              if (info_verbose)
                {
                {
                  printf_filtered ("done.\n");
                  printf_filtered ("done.\n");
                  gdb_flush (gdb_stdout);
                  gdb_flush (gdb_stdout);
                }
                }
            }
            }
        }
        }
    }
    }
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   add_enum_psymbol -- add enumeration members to partial symbol table
   add_enum_psymbol -- add enumeration members to partial symbol table
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Given pointer to a DIE that is known to be for an enumeration,
   Given pointer to a DIE that is known to be for an enumeration,
   extract the symbolic names of the enumeration members and add
   extract the symbolic names of the enumeration members and add
   partial symbols for them.
   partial symbols for them.
 */
 */
 
 
static void
static void
add_enum_psymbol (dip, objfile)
add_enum_psymbol (dip, objfile)
     struct dieinfo *dip;
     struct dieinfo *dip;
     struct objfile *objfile;
     struct objfile *objfile;
{
{
  char *scan;
  char *scan;
  char *listend;
  char *listend;
  unsigned short blocksz;
  unsigned short blocksz;
  int nbytes;
  int nbytes;
 
 
  if ((scan = dip->at_element_list) != NULL)
  if ((scan = dip->at_element_list) != NULL)
    {
    {
      if (dip->short_element_list)
      if (dip->short_element_list)
        {
        {
          nbytes = attribute_size (AT_short_element_list);
          nbytes = attribute_size (AT_short_element_list);
        }
        }
      else
      else
        {
        {
          nbytes = attribute_size (AT_element_list);
          nbytes = attribute_size (AT_element_list);
        }
        }
      blocksz = target_to_host (scan, nbytes, GET_UNSIGNED, objfile);
      blocksz = target_to_host (scan, nbytes, GET_UNSIGNED, objfile);
      scan += nbytes;
      scan += nbytes;
      listend = scan + blocksz;
      listend = scan + blocksz;
      while (scan < listend)
      while (scan < listend)
        {
        {
          scan += TARGET_FT_LONG_SIZE (objfile);
          scan += TARGET_FT_LONG_SIZE (objfile);
          add_psymbol_to_list (scan, strlen (scan), VAR_NAMESPACE, LOC_CONST,
          add_psymbol_to_list (scan, strlen (scan), VAR_NAMESPACE, LOC_CONST,
                               &objfile->static_psymbols, 0, 0, cu_language,
                               &objfile->static_psymbols, 0, 0, cu_language,
                               objfile);
                               objfile);
          scan += strlen (scan) + 1;
          scan += strlen (scan) + 1;
        }
        }
    }
    }
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   add_partial_symbol -- add symbol to partial symbol table
   add_partial_symbol -- add symbol to partial symbol table
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Given a DIE, if it is one of the types that we want to
   Given a DIE, if it is one of the types that we want to
   add to a partial symbol table, finish filling in the die info
   add to a partial symbol table, finish filling in the die info
   and then add a partial symbol table entry for it.
   and then add a partial symbol table entry for it.
 
 
   NOTES
   NOTES
 
 
   The caller must ensure that the DIE has a valid name attribute.
   The caller must ensure that the DIE has a valid name attribute.
 */
 */
 
 
static void
static void
add_partial_symbol (dip, objfile)
add_partial_symbol (dip, objfile)
     struct dieinfo *dip;
     struct dieinfo *dip;
     struct objfile *objfile;
     struct objfile *objfile;
{
{
  switch (dip->die_tag)
  switch (dip->die_tag)
    {
    {
    case TAG_global_subroutine:
    case TAG_global_subroutine:
      add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
      add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
                           VAR_NAMESPACE, LOC_BLOCK,
                           VAR_NAMESPACE, LOC_BLOCK,
                           &objfile->global_psymbols,
                           &objfile->global_psymbols,
                           0, dip->at_low_pc, cu_language, objfile);
                           0, dip->at_low_pc, cu_language, objfile);
      break;
      break;
    case TAG_global_variable:
    case TAG_global_variable:
      add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
      add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
                           VAR_NAMESPACE, LOC_STATIC,
                           VAR_NAMESPACE, LOC_STATIC,
                           &objfile->global_psymbols,
                           &objfile->global_psymbols,
                           0, 0, cu_language, objfile);
                           0, 0, cu_language, objfile);
      break;
      break;
    case TAG_subroutine:
    case TAG_subroutine:
      add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
      add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
                           VAR_NAMESPACE, LOC_BLOCK,
                           VAR_NAMESPACE, LOC_BLOCK,
                           &objfile->static_psymbols,
                           &objfile->static_psymbols,
                           0, dip->at_low_pc, cu_language, objfile);
                           0, dip->at_low_pc, cu_language, objfile);
      break;
      break;
    case TAG_local_variable:
    case TAG_local_variable:
      add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
      add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
                           VAR_NAMESPACE, LOC_STATIC,
                           VAR_NAMESPACE, LOC_STATIC,
                           &objfile->static_psymbols,
                           &objfile->static_psymbols,
                           0, 0, cu_language, objfile);
                           0, 0, cu_language, objfile);
      break;
      break;
    case TAG_typedef:
    case TAG_typedef:
      add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
      add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
                           VAR_NAMESPACE, LOC_TYPEDEF,
                           VAR_NAMESPACE, LOC_TYPEDEF,
                           &objfile->static_psymbols,
                           &objfile->static_psymbols,
                           0, 0, cu_language, objfile);
                           0, 0, cu_language, objfile);
      break;
      break;
    case TAG_class_type:
    case TAG_class_type:
    case TAG_structure_type:
    case TAG_structure_type:
    case TAG_union_type:
    case TAG_union_type:
    case TAG_enumeration_type:
    case TAG_enumeration_type:
      /* Do not add opaque aggregate definitions to the psymtab.  */
      /* Do not add opaque aggregate definitions to the psymtab.  */
      if (!dip->has_at_byte_size)
      if (!dip->has_at_byte_size)
        break;
        break;
      add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
      add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
                           STRUCT_NAMESPACE, LOC_TYPEDEF,
                           STRUCT_NAMESPACE, LOC_TYPEDEF,
                           &objfile->static_psymbols,
                           &objfile->static_psymbols,
                           0, 0, cu_language, objfile);
                           0, 0, cu_language, objfile);
      if (cu_language == language_cplus)
      if (cu_language == language_cplus)
        {
        {
          /* For C++, these implicitly act as typedefs as well. */
          /* For C++, these implicitly act as typedefs as well. */
          add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
          add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
                               VAR_NAMESPACE, LOC_TYPEDEF,
                               VAR_NAMESPACE, LOC_TYPEDEF,
                               &objfile->static_psymbols,
                               &objfile->static_psymbols,
                               0, 0, cu_language, objfile);
                               0, 0, cu_language, objfile);
        }
        }
      break;
      break;
    }
    }
}
}
/* *INDENT-OFF* */
/* *INDENT-OFF* */
/*
/*
 
 
LOCAL FUNCTION
LOCAL FUNCTION
 
 
        scan_partial_symbols -- scan DIE's within a single compilation unit
        scan_partial_symbols -- scan DIE's within a single compilation unit
 
 
DESCRIPTION
DESCRIPTION
 
 
        Process the DIE's within a single compilation unit, looking for
        Process the DIE's within a single compilation unit, looking for
        interesting DIE's that contribute to the partial symbol table entry
        interesting DIE's that contribute to the partial symbol table entry
        for this compilation unit.
        for this compilation unit.
 
 
NOTES
NOTES
 
 
        There are some DIE's that may appear both at file scope and within
        There are some DIE's that may appear both at file scope and within
        the scope of a function.  We are only interested in the ones at file
        the scope of a function.  We are only interested in the ones at file
        scope, and the only way to tell them apart is to keep track of the
        scope, and the only way to tell them apart is to keep track of the
        scope.  For example, consider the test case:
        scope.  For example, consider the test case:
 
 
                static int i;
                static int i;
                main () { int j; }
                main () { int j; }
 
 
        for which the relevant DWARF segment has the structure:
        for which the relevant DWARF segment has the structure:
 
 
                0x51:
                0x51:
                0x23   global subrtn   sibling     0x9b
                0x23   global subrtn   sibling     0x9b
                                       name        main
                                       name        main
                                       fund_type   FT_integer
                                       fund_type   FT_integer
                                       low_pc      0x800004cc
                                       low_pc      0x800004cc
                                       high_pc     0x800004d4
                                       high_pc     0x800004d4
 
 
                0x74:
                0x74:
                0x23   local var       sibling     0x97
                0x23   local var       sibling     0x97
                                       name        j
                                       name        j
                                       fund_type   FT_integer
                                       fund_type   FT_integer
                                       location    OP_BASEREG 0xe
                                       location    OP_BASEREG 0xe
                                                   OP_CONST 0xfffffffc
                                                   OP_CONST 0xfffffffc
                                                   OP_ADD
                                                   OP_ADD
                0x97:
                0x97:
                0x4
                0x4
 
 
                0x9b:
                0x9b:
                0x1d   local var       sibling     0xb8
                0x1d   local var       sibling     0xb8
                                       name        i
                                       name        i
                                       fund_type   FT_integer
                                       fund_type   FT_integer
                                       location    OP_ADDR 0x800025dc
                                       location    OP_ADDR 0x800025dc
 
 
                0xb8:
                0xb8:
                0x4
                0x4
 
 
        We want to include the symbol 'i' in the partial symbol table, but
        We want to include the symbol 'i' in the partial symbol table, but
        not the symbol 'j'.  In essence, we want to skip all the dies within
        not the symbol 'j'.  In essence, we want to skip all the dies within
        the scope of a TAG_global_subroutine DIE.
        the scope of a TAG_global_subroutine DIE.
 
 
        Don't attempt to add anonymous structures or unions since they have
        Don't attempt to add anonymous structures or unions since they have
        no name.  Anonymous enumerations however are processed, because we
        no name.  Anonymous enumerations however are processed, because we
        want to extract their member names (the check for a tag name is
        want to extract their member names (the check for a tag name is
        done later).
        done later).
 
 
        Also, for variables and subroutines, check that this is the place
        Also, for variables and subroutines, check that this is the place
        where the actual definition occurs, rather than just a reference
        where the actual definition occurs, rather than just a reference
        to an external.
        to an external.
 */
 */
/* *INDENT-ON* */
/* *INDENT-ON* */
 
 
 
 
 
 
static void
static void
scan_partial_symbols (thisdie, enddie, objfile)
scan_partial_symbols (thisdie, enddie, objfile)
     char *thisdie;
     char *thisdie;
     char *enddie;
     char *enddie;
     struct objfile *objfile;
     struct objfile *objfile;
{
{
  char *nextdie;
  char *nextdie;
  char *temp;
  char *temp;
  struct dieinfo di;
  struct dieinfo di;
 
 
  while (thisdie < enddie)
  while (thisdie < enddie)
    {
    {
      basicdieinfo (&di, thisdie, objfile);
      basicdieinfo (&di, thisdie, objfile);
      if (di.die_length < SIZEOF_DIE_LENGTH)
      if (di.die_length < SIZEOF_DIE_LENGTH)
        {
        {
          break;
          break;
        }
        }
      else
      else
        {
        {
          nextdie = thisdie + di.die_length;
          nextdie = thisdie + di.die_length;
          /* To avoid getting complete die information for every die, we
          /* To avoid getting complete die information for every die, we
             only do it (below) for the cases we are interested in. */
             only do it (below) for the cases we are interested in. */
          switch (di.die_tag)
          switch (di.die_tag)
            {
            {
            case TAG_global_subroutine:
            case TAG_global_subroutine:
            case TAG_subroutine:
            case TAG_subroutine:
              completedieinfo (&di, objfile);
              completedieinfo (&di, objfile);
              if (di.at_name && (di.has_at_low_pc || di.at_location))
              if (di.at_name && (di.has_at_low_pc || di.at_location))
                {
                {
                  add_partial_symbol (&di, objfile);
                  add_partial_symbol (&di, objfile);
                  /* If there is a sibling attribute, adjust the nextdie
                  /* If there is a sibling attribute, adjust the nextdie
                     pointer to skip the entire scope of the subroutine.
                     pointer to skip the entire scope of the subroutine.
                     Apply some sanity checking to make sure we don't
                     Apply some sanity checking to make sure we don't
                     overrun or underrun the range of remaining DIE's */
                     overrun or underrun the range of remaining DIE's */
                  if (di.at_sibling != 0)
                  if (di.at_sibling != 0)
                    {
                    {
                      temp = dbbase + di.at_sibling - dbroff;
                      temp = dbbase + di.at_sibling - dbroff;
                      if ((temp < thisdie) || (temp >= enddie))
                      if ((temp < thisdie) || (temp >= enddie))
                        {
                        {
                          complain (&bad_die_ref, DIE_ID, DIE_NAME,
                          complain (&bad_die_ref, DIE_ID, DIE_NAME,
                                    di.at_sibling);
                                    di.at_sibling);
                        }
                        }
                      else
                      else
                        {
                        {
                          nextdie = temp;
                          nextdie = temp;
                        }
                        }
                    }
                    }
                }
                }
              break;
              break;
            case TAG_global_variable:
            case TAG_global_variable:
            case TAG_local_variable:
            case TAG_local_variable:
              completedieinfo (&di, objfile);
              completedieinfo (&di, objfile);
              if (di.at_name && (di.has_at_low_pc || di.at_location))
              if (di.at_name && (di.has_at_low_pc || di.at_location))
                {
                {
                  add_partial_symbol (&di, objfile);
                  add_partial_symbol (&di, objfile);
                }
                }
              break;
              break;
            case TAG_typedef:
            case TAG_typedef:
            case TAG_class_type:
            case TAG_class_type:
            case TAG_structure_type:
            case TAG_structure_type:
            case TAG_union_type:
            case TAG_union_type:
              completedieinfo (&di, objfile);
              completedieinfo (&di, objfile);
              if (di.at_name)
              if (di.at_name)
                {
                {
                  add_partial_symbol (&di, objfile);
                  add_partial_symbol (&di, objfile);
                }
                }
              break;
              break;
            case TAG_enumeration_type:
            case TAG_enumeration_type:
              completedieinfo (&di, objfile);
              completedieinfo (&di, objfile);
              if (di.at_name)
              if (di.at_name)
                {
                {
                  add_partial_symbol (&di, objfile);
                  add_partial_symbol (&di, objfile);
                }
                }
              add_enum_psymbol (&di, objfile);
              add_enum_psymbol (&di, objfile);
              break;
              break;
            }
            }
        }
        }
      thisdie = nextdie;
      thisdie = nextdie;
    }
    }
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   scan_compilation_units -- build a psymtab entry for each compilation
   scan_compilation_units -- build a psymtab entry for each compilation
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   This is the top level dwarf parsing routine for building partial
   This is the top level dwarf parsing routine for building partial
   symbol tables.
   symbol tables.
 
 
   It scans from the beginning of the DWARF table looking for the first
   It scans from the beginning of the DWARF table looking for the first
   TAG_compile_unit DIE, and then follows the sibling chain to locate
   TAG_compile_unit DIE, and then follows the sibling chain to locate
   each additional TAG_compile_unit DIE.
   each additional TAG_compile_unit DIE.
 
 
   For each TAG_compile_unit DIE it creates a partial symtab structure,
   For each TAG_compile_unit DIE it creates a partial symtab structure,
   calls a subordinate routine to collect all the compilation unit's
   calls a subordinate routine to collect all the compilation unit's
   global DIE's, file scope DIEs, typedef DIEs, etc, and then links the
   global DIE's, file scope DIEs, typedef DIEs, etc, and then links the
   new partial symtab structure into the partial symbol table.  It also
   new partial symtab structure into the partial symbol table.  It also
   records the appropriate information in the partial symbol table entry
   records the appropriate information in the partial symbol table entry
   to allow the chunk of DIE's and line number table for this compilation
   to allow the chunk of DIE's and line number table for this compilation
   unit to be located and re-read later, to generate a complete symbol
   unit to be located and re-read later, to generate a complete symbol
   table entry for the compilation unit.
   table entry for the compilation unit.
 
 
   Thus it effectively partitions up a chunk of DIE's for multiple
   Thus it effectively partitions up a chunk of DIE's for multiple
   compilation units into smaller DIE chunks and line number tables,
   compilation units into smaller DIE chunks and line number tables,
   and associates them with a partial symbol table entry.
   and associates them with a partial symbol table entry.
 
 
   NOTES
   NOTES
 
 
   If any compilation unit has no line number table associated with
   If any compilation unit has no line number table associated with
   it for some reason (a missing at_stmt_list attribute, rather than
   it for some reason (a missing at_stmt_list attribute, rather than
   just one with a value of zero, which is valid) then we ensure that
   just one with a value of zero, which is valid) then we ensure that
   the recorded file offset is zero so that the routine which later
   the recorded file offset is zero so that the routine which later
   reads line number table fragments knows that there is no fragment
   reads line number table fragments knows that there is no fragment
   to read.
   to read.
 
 
   RETURNS
   RETURNS
 
 
   Returns no value.
   Returns no value.
 
 
 */
 */
 
 
static void
static void
scan_compilation_units (thisdie, enddie, dbfoff, lnoffset, objfile)
scan_compilation_units (thisdie, enddie, dbfoff, lnoffset, objfile)
     char *thisdie;
     char *thisdie;
     char *enddie;
     char *enddie;
     file_ptr dbfoff;
     file_ptr dbfoff;
     file_ptr lnoffset;
     file_ptr lnoffset;
     struct objfile *objfile;
     struct objfile *objfile;
{
{
  char *nextdie;
  char *nextdie;
  struct dieinfo di;
  struct dieinfo di;
  struct partial_symtab *pst;
  struct partial_symtab *pst;
  int culength;
  int culength;
  int curoff;
  int curoff;
  file_ptr curlnoffset;
  file_ptr curlnoffset;
 
 
  while (thisdie < enddie)
  while (thisdie < enddie)
    {
    {
      basicdieinfo (&di, thisdie, objfile);
      basicdieinfo (&di, thisdie, objfile);
      if (di.die_length < SIZEOF_DIE_LENGTH)
      if (di.die_length < SIZEOF_DIE_LENGTH)
        {
        {
          break;
          break;
        }
        }
      else if (di.die_tag != TAG_compile_unit)
      else if (di.die_tag != TAG_compile_unit)
        {
        {
          nextdie = thisdie + di.die_length;
          nextdie = thisdie + di.die_length;
        }
        }
      else
      else
        {
        {
          completedieinfo (&di, objfile);
          completedieinfo (&di, objfile);
          set_cu_language (&di);
          set_cu_language (&di);
          if (di.at_sibling != 0)
          if (di.at_sibling != 0)
            {
            {
              nextdie = dbbase + di.at_sibling - dbroff;
              nextdie = dbbase + di.at_sibling - dbroff;
            }
            }
          else
          else
            {
            {
              nextdie = thisdie + di.die_length;
              nextdie = thisdie + di.die_length;
            }
            }
          curoff = thisdie - dbbase;
          curoff = thisdie - dbbase;
          culength = nextdie - thisdie;
          culength = nextdie - thisdie;
          curlnoffset = di.has_at_stmt_list ? lnoffset + di.at_stmt_list : 0;
          curlnoffset = di.has_at_stmt_list ? lnoffset + di.at_stmt_list : 0;
 
 
          /* First allocate a new partial symbol table structure */
          /* First allocate a new partial symbol table structure */
 
 
          pst = start_psymtab_common (objfile, base_section_offsets,
          pst = start_psymtab_common (objfile, base_section_offsets,
                                      di.at_name, di.at_low_pc,
                                      di.at_name, di.at_low_pc,
                                      objfile->global_psymbols.next,
                                      objfile->global_psymbols.next,
                                      objfile->static_psymbols.next);
                                      objfile->static_psymbols.next);
 
 
          pst->texthigh = di.at_high_pc;
          pst->texthigh = di.at_high_pc;
          pst->read_symtab_private = (char *)
          pst->read_symtab_private = (char *)
            obstack_alloc (&objfile->psymbol_obstack,
            obstack_alloc (&objfile->psymbol_obstack,
                           sizeof (struct dwfinfo));
                           sizeof (struct dwfinfo));
          DBFOFF (pst) = dbfoff;
          DBFOFF (pst) = dbfoff;
          DBROFF (pst) = curoff;
          DBROFF (pst) = curoff;
          DBLENGTH (pst) = culength;
          DBLENGTH (pst) = culength;
          LNFOFF (pst) = curlnoffset;
          LNFOFF (pst) = curlnoffset;
          pst->read_symtab = dwarf_psymtab_to_symtab;
          pst->read_symtab = dwarf_psymtab_to_symtab;
 
 
          /* Now look for partial symbols */
          /* Now look for partial symbols */
 
 
          scan_partial_symbols (thisdie + di.die_length, nextdie, objfile);
          scan_partial_symbols (thisdie + di.die_length, nextdie, objfile);
 
 
          pst->n_global_syms = objfile->global_psymbols.next -
          pst->n_global_syms = objfile->global_psymbols.next -
            (objfile->global_psymbols.list + pst->globals_offset);
            (objfile->global_psymbols.list + pst->globals_offset);
          pst->n_static_syms = objfile->static_psymbols.next -
          pst->n_static_syms = objfile->static_psymbols.next -
            (objfile->static_psymbols.list + pst->statics_offset);
            (objfile->static_psymbols.list + pst->statics_offset);
          sort_pst_symbols (pst);
          sort_pst_symbols (pst);
          /* If there is already a psymtab or symtab for a file of this name,
          /* If there is already a psymtab or symtab for a file of this name,
             remove it. (If there is a symtab, more drastic things also
             remove it. (If there is a symtab, more drastic things also
             happen.)  This happens in VxWorks.  */
             happen.)  This happens in VxWorks.  */
          free_named_symtabs (pst->filename);
          free_named_symtabs (pst->filename);
        }
        }
      thisdie = nextdie;
      thisdie = nextdie;
    }
    }
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   new_symbol -- make a symbol table entry for a new symbol
   new_symbol -- make a symbol table entry for a new symbol
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static struct symbol *new_symbol (struct dieinfo *dip,
   static struct symbol *new_symbol (struct dieinfo *dip,
   struct objfile *objfile)
   struct objfile *objfile)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Given a pointer to a DWARF information entry, figure out if we need
   Given a pointer to a DWARF information entry, figure out if we need
   to make a symbol table entry for it, and if so, create a new entry
   to make a symbol table entry for it, and if so, create a new entry
   and return a pointer to it.
   and return a pointer to it.
 */
 */
 
 
static struct symbol *
static struct symbol *
new_symbol (dip, objfile)
new_symbol (dip, objfile)
     struct dieinfo *dip;
     struct dieinfo *dip;
     struct objfile *objfile;
     struct objfile *objfile;
{
{
  struct symbol *sym = NULL;
  struct symbol *sym = NULL;
 
 
  if (dip->at_name != NULL)
  if (dip->at_name != NULL)
    {
    {
      sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
      sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
                                             sizeof (struct symbol));
                                             sizeof (struct symbol));
      OBJSTAT (objfile, n_syms++);
      OBJSTAT (objfile, n_syms++);
      memset (sym, 0, sizeof (struct symbol));
      memset (sym, 0, sizeof (struct symbol));
      SYMBOL_NAME (sym) = create_name (dip->at_name,
      SYMBOL_NAME (sym) = create_name (dip->at_name,
                                       &objfile->symbol_obstack);
                                       &objfile->symbol_obstack);
      /* default assumptions */
      /* default assumptions */
      SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
      SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
      SYMBOL_CLASS (sym) = LOC_STATIC;
      SYMBOL_CLASS (sym) = LOC_STATIC;
      SYMBOL_TYPE (sym) = decode_die_type (dip);
      SYMBOL_TYPE (sym) = decode_die_type (dip);
 
 
      /* If this symbol is from a C++ compilation, then attempt to cache the
      /* If this symbol is from a C++ compilation, then attempt to cache the
         demangled form for future reference.  This is a typical time versus
         demangled form for future reference.  This is a typical time versus
         space tradeoff, that was decided in favor of time because it sped up
         space tradeoff, that was decided in favor of time because it sped up
         C++ symbol lookups by a factor of about 20. */
         C++ symbol lookups by a factor of about 20. */
 
 
      SYMBOL_LANGUAGE (sym) = cu_language;
      SYMBOL_LANGUAGE (sym) = cu_language;
      SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
      SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
      switch (dip->die_tag)
      switch (dip->die_tag)
        {
        {
        case TAG_label:
        case TAG_label:
          SYMBOL_VALUE_ADDRESS (sym) = dip->at_low_pc;
          SYMBOL_VALUE_ADDRESS (sym) = dip->at_low_pc;
          SYMBOL_CLASS (sym) = LOC_LABEL;
          SYMBOL_CLASS (sym) = LOC_LABEL;
          break;
          break;
        case TAG_global_subroutine:
        case TAG_global_subroutine:
        case TAG_subroutine:
        case TAG_subroutine:
          SYMBOL_VALUE_ADDRESS (sym) = dip->at_low_pc;
          SYMBOL_VALUE_ADDRESS (sym) = dip->at_low_pc;
          SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
          SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
          if (dip->at_prototyped)
          if (dip->at_prototyped)
            TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED;
            TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED;
          SYMBOL_CLASS (sym) = LOC_BLOCK;
          SYMBOL_CLASS (sym) = LOC_BLOCK;
          if (dip->die_tag == TAG_global_subroutine)
          if (dip->die_tag == TAG_global_subroutine)
            {
            {
              add_symbol_to_list (sym, &global_symbols);
              add_symbol_to_list (sym, &global_symbols);
            }
            }
          else
          else
            {
            {
              add_symbol_to_list (sym, list_in_scope);
              add_symbol_to_list (sym, list_in_scope);
            }
            }
          break;
          break;
        case TAG_global_variable:
        case TAG_global_variable:
          if (dip->at_location != NULL)
          if (dip->at_location != NULL)
            {
            {
              SYMBOL_VALUE_ADDRESS (sym) = locval (dip);
              SYMBOL_VALUE_ADDRESS (sym) = locval (dip);
              add_symbol_to_list (sym, &global_symbols);
              add_symbol_to_list (sym, &global_symbols);
              SYMBOL_CLASS (sym) = LOC_STATIC;
              SYMBOL_CLASS (sym) = LOC_STATIC;
              SYMBOL_VALUE (sym) += baseaddr;
              SYMBOL_VALUE (sym) += baseaddr;
            }
            }
          break;
          break;
        case TAG_local_variable:
        case TAG_local_variable:
          if (dip->at_location != NULL)
          if (dip->at_location != NULL)
            {
            {
              int loc = locval (dip);
              int loc = locval (dip);
              if (dip->optimized_out)
              if (dip->optimized_out)
                {
                {
                  SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
                  SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
                }
                }
              else if (dip->isreg)
              else if (dip->isreg)
                {
                {
                  SYMBOL_CLASS (sym) = LOC_REGISTER;
                  SYMBOL_CLASS (sym) = LOC_REGISTER;
                }
                }
              else if (dip->offreg)
              else if (dip->offreg)
                {
                {
                  SYMBOL_CLASS (sym) = LOC_BASEREG;
                  SYMBOL_CLASS (sym) = LOC_BASEREG;
                  SYMBOL_BASEREG (sym) = dip->basereg;
                  SYMBOL_BASEREG (sym) = dip->basereg;
                }
                }
              else
              else
                {
                {
                  SYMBOL_CLASS (sym) = LOC_STATIC;
                  SYMBOL_CLASS (sym) = LOC_STATIC;
                  SYMBOL_VALUE (sym) += baseaddr;
                  SYMBOL_VALUE (sym) += baseaddr;
                }
                }
              if (SYMBOL_CLASS (sym) == LOC_STATIC)
              if (SYMBOL_CLASS (sym) == LOC_STATIC)
                {
                {
                  /* LOC_STATIC address class MUST use SYMBOL_VALUE_ADDRESS,
                  /* LOC_STATIC address class MUST use SYMBOL_VALUE_ADDRESS,
                     which may store to a bigger location than SYMBOL_VALUE. */
                     which may store to a bigger location than SYMBOL_VALUE. */
                  SYMBOL_VALUE_ADDRESS (sym) = loc;
                  SYMBOL_VALUE_ADDRESS (sym) = loc;
                }
                }
              else
              else
                {
                {
                  SYMBOL_VALUE (sym) = loc;
                  SYMBOL_VALUE (sym) = loc;
                }
                }
              add_symbol_to_list (sym, list_in_scope);
              add_symbol_to_list (sym, list_in_scope);
            }
            }
          break;
          break;
        case TAG_formal_parameter:
        case TAG_formal_parameter:
          if (dip->at_location != NULL)
          if (dip->at_location != NULL)
            {
            {
              SYMBOL_VALUE (sym) = locval (dip);
              SYMBOL_VALUE (sym) = locval (dip);
            }
            }
          add_symbol_to_list (sym, list_in_scope);
          add_symbol_to_list (sym, list_in_scope);
          if (dip->isreg)
          if (dip->isreg)
            {
            {
              SYMBOL_CLASS (sym) = LOC_REGPARM;
              SYMBOL_CLASS (sym) = LOC_REGPARM;
            }
            }
          else if (dip->offreg)
          else if (dip->offreg)
            {
            {
              SYMBOL_CLASS (sym) = LOC_BASEREG_ARG;
              SYMBOL_CLASS (sym) = LOC_BASEREG_ARG;
              SYMBOL_BASEREG (sym) = dip->basereg;
              SYMBOL_BASEREG (sym) = dip->basereg;
            }
            }
          else
          else
            {
            {
              SYMBOL_CLASS (sym) = LOC_ARG;
              SYMBOL_CLASS (sym) = LOC_ARG;
            }
            }
          break;
          break;
        case TAG_unspecified_parameters:
        case TAG_unspecified_parameters:
          /* From varargs functions; gdb doesn't seem to have any interest in
          /* From varargs functions; gdb doesn't seem to have any interest in
             this information, so just ignore it for now. (FIXME?) */
             this information, so just ignore it for now. (FIXME?) */
          break;
          break;
        case TAG_class_type:
        case TAG_class_type:
        case TAG_structure_type:
        case TAG_structure_type:
        case TAG_union_type:
        case TAG_union_type:
        case TAG_enumeration_type:
        case TAG_enumeration_type:
          SYMBOL_CLASS (sym) = LOC_TYPEDEF;
          SYMBOL_CLASS (sym) = LOC_TYPEDEF;
          SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
          SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
          add_symbol_to_list (sym, list_in_scope);
          add_symbol_to_list (sym, list_in_scope);
          break;
          break;
        case TAG_typedef:
        case TAG_typedef:
          SYMBOL_CLASS (sym) = LOC_TYPEDEF;
          SYMBOL_CLASS (sym) = LOC_TYPEDEF;
          SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
          SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
          add_symbol_to_list (sym, list_in_scope);
          add_symbol_to_list (sym, list_in_scope);
          break;
          break;
        default:
        default:
          /* Not a tag we recognize.  Hopefully we aren't processing trash
          /* Not a tag we recognize.  Hopefully we aren't processing trash
             data, but since we must specifically ignore things we don't
             data, but since we must specifically ignore things we don't
             recognize, there is nothing else we should do at this point. */
             recognize, there is nothing else we should do at this point. */
          break;
          break;
        }
        }
    }
    }
  return (sym);
  return (sym);
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   synthesize_typedef -- make a symbol table entry for a "fake" typedef
   synthesize_typedef -- make a symbol table entry for a "fake" typedef
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static void synthesize_typedef (struct dieinfo *dip,
   static void synthesize_typedef (struct dieinfo *dip,
   struct objfile *objfile,
   struct objfile *objfile,
   struct type *type);
   struct type *type);
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Given a pointer to a DWARF information entry, synthesize a typedef
   Given a pointer to a DWARF information entry, synthesize a typedef
   for the name in the DIE, using the specified type.
   for the name in the DIE, using the specified type.
 
 
   This is used for C++ class, structs, unions, and enumerations to
   This is used for C++ class, structs, unions, and enumerations to
   set up the tag name as a type.
   set up the tag name as a type.
 
 
 */
 */
 
 
static void
static void
synthesize_typedef (dip, objfile, type)
synthesize_typedef (dip, objfile, type)
     struct dieinfo *dip;
     struct dieinfo *dip;
     struct objfile *objfile;
     struct objfile *objfile;
     struct type *type;
     struct type *type;
{
{
  struct symbol *sym = NULL;
  struct symbol *sym = NULL;
 
 
  if (dip->at_name != NULL)
  if (dip->at_name != NULL)
    {
    {
      sym = (struct symbol *)
      sym = (struct symbol *)
        obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
        obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
      OBJSTAT (objfile, n_syms++);
      OBJSTAT (objfile, n_syms++);
      memset (sym, 0, sizeof (struct symbol));
      memset (sym, 0, sizeof (struct symbol));
      SYMBOL_NAME (sym) = create_name (dip->at_name,
      SYMBOL_NAME (sym) = create_name (dip->at_name,
                                       &objfile->symbol_obstack);
                                       &objfile->symbol_obstack);
      SYMBOL_INIT_LANGUAGE_SPECIFIC (sym, cu_language);
      SYMBOL_INIT_LANGUAGE_SPECIFIC (sym, cu_language);
      SYMBOL_TYPE (sym) = type;
      SYMBOL_TYPE (sym) = type;
      SYMBOL_CLASS (sym) = LOC_TYPEDEF;
      SYMBOL_CLASS (sym) = LOC_TYPEDEF;
      SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
      SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
      add_symbol_to_list (sym, list_in_scope);
      add_symbol_to_list (sym, list_in_scope);
    }
    }
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   decode_mod_fund_type -- decode a modified fundamental type
   decode_mod_fund_type -- decode a modified fundamental type
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static struct type *decode_mod_fund_type (char *typedata)
   static struct type *decode_mod_fund_type (char *typedata)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Decode a block of data containing a modified fundamental
   Decode a block of data containing a modified fundamental
   type specification.  TYPEDATA is a pointer to the block,
   type specification.  TYPEDATA is a pointer to the block,
   which starts with a length containing the size of the rest
   which starts with a length containing the size of the rest
   of the block.  At the end of the block is a fundmental type
   of the block.  At the end of the block is a fundmental type
   code value that gives the fundamental type.  Everything
   code value that gives the fundamental type.  Everything
   in between are type modifiers.
   in between are type modifiers.
 
 
   We simply compute the number of modifiers and call the general
   We simply compute the number of modifiers and call the general
   function decode_modified_type to do the actual work.
   function decode_modified_type to do the actual work.
 */
 */
 
 
static struct type *
static struct type *
decode_mod_fund_type (typedata)
decode_mod_fund_type (typedata)
     char *typedata;
     char *typedata;
{
{
  struct type *typep = NULL;
  struct type *typep = NULL;
  unsigned short modcount;
  unsigned short modcount;
  int nbytes;
  int nbytes;
 
 
  /* Get the total size of the block, exclusive of the size itself */
  /* Get the total size of the block, exclusive of the size itself */
 
 
  nbytes = attribute_size (AT_mod_fund_type);
  nbytes = attribute_size (AT_mod_fund_type);
  modcount = target_to_host (typedata, nbytes, GET_UNSIGNED, current_objfile);
  modcount = target_to_host (typedata, nbytes, GET_UNSIGNED, current_objfile);
  typedata += nbytes;
  typedata += nbytes;
 
 
  /* Deduct the size of the fundamental type bytes at the end of the block. */
  /* Deduct the size of the fundamental type bytes at the end of the block. */
 
 
  modcount -= attribute_size (AT_fund_type);
  modcount -= attribute_size (AT_fund_type);
 
 
  /* Now do the actual decoding */
  /* Now do the actual decoding */
 
 
  typep = decode_modified_type (typedata, modcount, AT_mod_fund_type);
  typep = decode_modified_type (typedata, modcount, AT_mod_fund_type);
  return (typep);
  return (typep);
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   decode_mod_u_d_type -- decode a modified user defined type
   decode_mod_u_d_type -- decode a modified user defined type
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static struct type *decode_mod_u_d_type (char *typedata)
   static struct type *decode_mod_u_d_type (char *typedata)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Decode a block of data containing a modified user defined
   Decode a block of data containing a modified user defined
   type specification.  TYPEDATA is a pointer to the block,
   type specification.  TYPEDATA is a pointer to the block,
   which consists of a two byte length, containing the size
   which consists of a two byte length, containing the size
   of the rest of the block.  At the end of the block is a
   of the rest of the block.  At the end of the block is a
   four byte value that gives a reference to a user defined type.
   four byte value that gives a reference to a user defined type.
   Everything in between are type modifiers.
   Everything in between are type modifiers.
 
 
   We simply compute the number of modifiers and call the general
   We simply compute the number of modifiers and call the general
   function decode_modified_type to do the actual work.
   function decode_modified_type to do the actual work.
 */
 */
 
 
static struct type *
static struct type *
decode_mod_u_d_type (typedata)
decode_mod_u_d_type (typedata)
     char *typedata;
     char *typedata;
{
{
  struct type *typep = NULL;
  struct type *typep = NULL;
  unsigned short modcount;
  unsigned short modcount;
  int nbytes;
  int nbytes;
 
 
  /* Get the total size of the block, exclusive of the size itself */
  /* Get the total size of the block, exclusive of the size itself */
 
 
  nbytes = attribute_size (AT_mod_u_d_type);
  nbytes = attribute_size (AT_mod_u_d_type);
  modcount = target_to_host (typedata, nbytes, GET_UNSIGNED, current_objfile);
  modcount = target_to_host (typedata, nbytes, GET_UNSIGNED, current_objfile);
  typedata += nbytes;
  typedata += nbytes;
 
 
  /* Deduct the size of the reference type bytes at the end of the block. */
  /* Deduct the size of the reference type bytes at the end of the block. */
 
 
  modcount -= attribute_size (AT_user_def_type);
  modcount -= attribute_size (AT_user_def_type);
 
 
  /* Now do the actual decoding */
  /* Now do the actual decoding */
 
 
  typep = decode_modified_type (typedata, modcount, AT_mod_u_d_type);
  typep = decode_modified_type (typedata, modcount, AT_mod_u_d_type);
  return (typep);
  return (typep);
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   decode_modified_type -- decode modified user or fundamental type
   decode_modified_type -- decode modified user or fundamental type
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static struct type *decode_modified_type (char *modifiers,
   static struct type *decode_modified_type (char *modifiers,
   unsigned short modcount, int mtype)
   unsigned short modcount, int mtype)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Decode a modified type, either a modified fundamental type or
   Decode a modified type, either a modified fundamental type or
   a modified user defined type.  MODIFIERS is a pointer to the
   a modified user defined type.  MODIFIERS is a pointer to the
   block of bytes that define MODCOUNT modifiers.  Immediately
   block of bytes that define MODCOUNT modifiers.  Immediately
   following the last modifier is a short containing the fundamental
   following the last modifier is a short containing the fundamental
   type or a long containing the reference to the user defined
   type or a long containing the reference to the user defined
   type.  Which one is determined by MTYPE, which is either
   type.  Which one is determined by MTYPE, which is either
   AT_mod_fund_type or AT_mod_u_d_type to indicate what modified
   AT_mod_fund_type or AT_mod_u_d_type to indicate what modified
   type we are generating.
   type we are generating.
 
 
   We call ourself recursively to generate each modified type,`
   We call ourself recursively to generate each modified type,`
   until MODCOUNT reaches zero, at which point we have consumed
   until MODCOUNT reaches zero, at which point we have consumed
   all the modifiers and generate either the fundamental type or
   all the modifiers and generate either the fundamental type or
   user defined type.  When the recursion unwinds, each modifier
   user defined type.  When the recursion unwinds, each modifier
   is applied in turn to generate the full modified type.
   is applied in turn to generate the full modified type.
 
 
   NOTES
   NOTES
 
 
   If we find a modifier that we don't recognize, and it is not one
   If we find a modifier that we don't recognize, and it is not one
   of those reserved for application specific use, then we issue a
   of those reserved for application specific use, then we issue a
   warning and simply ignore the modifier.
   warning and simply ignore the modifier.
 
 
   BUGS
   BUGS
 
 
   We currently ignore MOD_const and MOD_volatile.  (FIXME)
   We currently ignore MOD_const and MOD_volatile.  (FIXME)
 
 
 */
 */
 
 
static struct type *
static struct type *
decode_modified_type (modifiers, modcount, mtype)
decode_modified_type (modifiers, modcount, mtype)
     char *modifiers;
     char *modifiers;
     unsigned int modcount;
     unsigned int modcount;
     int mtype;
     int mtype;
{
{
  struct type *typep = NULL;
  struct type *typep = NULL;
  unsigned short fundtype;
  unsigned short fundtype;
  DIE_REF die_ref;
  DIE_REF die_ref;
  char modifier;
  char modifier;
  int nbytes;
  int nbytes;
 
 
  if (modcount == 0)
  if (modcount == 0)
    {
    {
      switch (mtype)
      switch (mtype)
        {
        {
        case AT_mod_fund_type:
        case AT_mod_fund_type:
          nbytes = attribute_size (AT_fund_type);
          nbytes = attribute_size (AT_fund_type);
          fundtype = target_to_host (modifiers, nbytes, GET_UNSIGNED,
          fundtype = target_to_host (modifiers, nbytes, GET_UNSIGNED,
                                     current_objfile);
                                     current_objfile);
          typep = decode_fund_type (fundtype);
          typep = decode_fund_type (fundtype);
          break;
          break;
        case AT_mod_u_d_type:
        case AT_mod_u_d_type:
          nbytes = attribute_size (AT_user_def_type);
          nbytes = attribute_size (AT_user_def_type);
          die_ref = target_to_host (modifiers, nbytes, GET_UNSIGNED,
          die_ref = target_to_host (modifiers, nbytes, GET_UNSIGNED,
                                    current_objfile);
                                    current_objfile);
          if ((typep = lookup_utype (die_ref)) == NULL)
          if ((typep = lookup_utype (die_ref)) == NULL)
            {
            {
              typep = alloc_utype (die_ref, NULL);
              typep = alloc_utype (die_ref, NULL);
            }
            }
          break;
          break;
        default:
        default:
          complain (&botched_modified_type, DIE_ID, DIE_NAME, mtype);
          complain (&botched_modified_type, DIE_ID, DIE_NAME, mtype);
          typep = dwarf_fundamental_type (current_objfile, FT_INTEGER);
          typep = dwarf_fundamental_type (current_objfile, FT_INTEGER);
          break;
          break;
        }
        }
    }
    }
  else
  else
    {
    {
      modifier = *modifiers++;
      modifier = *modifiers++;
      typep = decode_modified_type (modifiers, --modcount, mtype);
      typep = decode_modified_type (modifiers, --modcount, mtype);
      switch (modifier)
      switch (modifier)
        {
        {
        case MOD_pointer_to:
        case MOD_pointer_to:
          typep = lookup_pointer_type (typep);
          typep = lookup_pointer_type (typep);
          break;
          break;
        case MOD_reference_to:
        case MOD_reference_to:
          typep = lookup_reference_type (typep);
          typep = lookup_reference_type (typep);
          break;
          break;
        case MOD_const:
        case MOD_const:
          complain (&const_ignored, DIE_ID, DIE_NAME);  /* FIXME */
          complain (&const_ignored, DIE_ID, DIE_NAME);  /* FIXME */
          break;
          break;
        case MOD_volatile:
        case MOD_volatile:
          complain (&volatile_ignored, DIE_ID, DIE_NAME);       /* FIXME */
          complain (&volatile_ignored, DIE_ID, DIE_NAME);       /* FIXME */
          break;
          break;
        default:
        default:
          if (!(MOD_lo_user <= (unsigned char) modifier
          if (!(MOD_lo_user <= (unsigned char) modifier
                && (unsigned char) modifier <= MOD_hi_user))
                && (unsigned char) modifier <= MOD_hi_user))
            {
            {
              complain (&unknown_type_modifier, DIE_ID, DIE_NAME, modifier);
              complain (&unknown_type_modifier, DIE_ID, DIE_NAME, modifier);
            }
            }
          break;
          break;
        }
        }
    }
    }
  return (typep);
  return (typep);
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   decode_fund_type -- translate basic DWARF type to gdb base type
   decode_fund_type -- translate basic DWARF type to gdb base type
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Given an integer that is one of the fundamental DWARF types,
   Given an integer that is one of the fundamental DWARF types,
   translate it to one of the basic internal gdb types and return
   translate it to one of the basic internal gdb types and return
   a pointer to the appropriate gdb type (a "struct type *").
   a pointer to the appropriate gdb type (a "struct type *").
 
 
   NOTES
   NOTES
 
 
   For robustness, if we are asked to translate a fundamental
   For robustness, if we are asked to translate a fundamental
   type that we are unprepared to deal with, we return int so
   type that we are unprepared to deal with, we return int so
   callers can always depend upon a valid type being returned,
   callers can always depend upon a valid type being returned,
   and so gdb may at least do something reasonable by default.
   and so gdb may at least do something reasonable by default.
   If the type is not in the range of those types defined as
   If the type is not in the range of those types defined as
   application specific types, we also issue a warning.
   application specific types, we also issue a warning.
 */
 */
 
 
static struct type *
static struct type *
decode_fund_type (fundtype)
decode_fund_type (fundtype)
     unsigned int fundtype;
     unsigned int fundtype;
{
{
  struct type *typep = NULL;
  struct type *typep = NULL;
 
 
  switch (fundtype)
  switch (fundtype)
    {
    {
 
 
    case FT_void:
    case FT_void:
      typep = dwarf_fundamental_type (current_objfile, FT_VOID);
      typep = dwarf_fundamental_type (current_objfile, FT_VOID);
      break;
      break;
 
 
    case FT_boolean:            /* Was FT_set in AT&T version */
    case FT_boolean:            /* Was FT_set in AT&T version */
      typep = dwarf_fundamental_type (current_objfile, FT_BOOLEAN);
      typep = dwarf_fundamental_type (current_objfile, FT_BOOLEAN);
      break;
      break;
 
 
    case FT_pointer:            /* (void *) */
    case FT_pointer:            /* (void *) */
      typep = dwarf_fundamental_type (current_objfile, FT_VOID);
      typep = dwarf_fundamental_type (current_objfile, FT_VOID);
      typep = lookup_pointer_type (typep);
      typep = lookup_pointer_type (typep);
      break;
      break;
 
 
    case FT_char:
    case FT_char:
      typep = dwarf_fundamental_type (current_objfile, FT_CHAR);
      typep = dwarf_fundamental_type (current_objfile, FT_CHAR);
      break;
      break;
 
 
    case FT_signed_char:
    case FT_signed_char:
      typep = dwarf_fundamental_type (current_objfile, FT_SIGNED_CHAR);
      typep = dwarf_fundamental_type (current_objfile, FT_SIGNED_CHAR);
      break;
      break;
 
 
    case FT_unsigned_char:
    case FT_unsigned_char:
      typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_CHAR);
      typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_CHAR);
      break;
      break;
 
 
    case FT_short:
    case FT_short:
      typep = dwarf_fundamental_type (current_objfile, FT_SHORT);
      typep = dwarf_fundamental_type (current_objfile, FT_SHORT);
      break;
      break;
 
 
    case FT_signed_short:
    case FT_signed_short:
      typep = dwarf_fundamental_type (current_objfile, FT_SIGNED_SHORT);
      typep = dwarf_fundamental_type (current_objfile, FT_SIGNED_SHORT);
      break;
      break;
 
 
    case FT_unsigned_short:
    case FT_unsigned_short:
      typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_SHORT);
      typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_SHORT);
      break;
      break;
 
 
    case FT_integer:
    case FT_integer:
      typep = dwarf_fundamental_type (current_objfile, FT_INTEGER);
      typep = dwarf_fundamental_type (current_objfile, FT_INTEGER);
      break;
      break;
 
 
    case FT_signed_integer:
    case FT_signed_integer:
      typep = dwarf_fundamental_type (current_objfile, FT_SIGNED_INTEGER);
      typep = dwarf_fundamental_type (current_objfile, FT_SIGNED_INTEGER);
      break;
      break;
 
 
    case FT_unsigned_integer:
    case FT_unsigned_integer:
      typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER);
      typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER);
      break;
      break;
 
 
    case FT_long:
    case FT_long:
      typep = dwarf_fundamental_type (current_objfile, FT_LONG);
      typep = dwarf_fundamental_type (current_objfile, FT_LONG);
      break;
      break;
 
 
    case FT_signed_long:
    case FT_signed_long:
      typep = dwarf_fundamental_type (current_objfile, FT_SIGNED_LONG);
      typep = dwarf_fundamental_type (current_objfile, FT_SIGNED_LONG);
      break;
      break;
 
 
    case FT_unsigned_long:
    case FT_unsigned_long:
      typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_LONG);
      typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_LONG);
      break;
      break;
 
 
    case FT_long_long:
    case FT_long_long:
      typep = dwarf_fundamental_type (current_objfile, FT_LONG_LONG);
      typep = dwarf_fundamental_type (current_objfile, FT_LONG_LONG);
      break;
      break;
 
 
    case FT_signed_long_long:
    case FT_signed_long_long:
      typep = dwarf_fundamental_type (current_objfile, FT_SIGNED_LONG_LONG);
      typep = dwarf_fundamental_type (current_objfile, FT_SIGNED_LONG_LONG);
      break;
      break;
 
 
    case FT_unsigned_long_long:
    case FT_unsigned_long_long:
      typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_LONG_LONG);
      typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_LONG_LONG);
      break;
      break;
 
 
    case FT_float:
    case FT_float:
      typep = dwarf_fundamental_type (current_objfile, FT_FLOAT);
      typep = dwarf_fundamental_type (current_objfile, FT_FLOAT);
      break;
      break;
 
 
    case FT_dbl_prec_float:
    case FT_dbl_prec_float:
      typep = dwarf_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT);
      typep = dwarf_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT);
      break;
      break;
 
 
    case FT_ext_prec_float:
    case FT_ext_prec_float:
      typep = dwarf_fundamental_type (current_objfile, FT_EXT_PREC_FLOAT);
      typep = dwarf_fundamental_type (current_objfile, FT_EXT_PREC_FLOAT);
      break;
      break;
 
 
    case FT_complex:
    case FT_complex:
      typep = dwarf_fundamental_type (current_objfile, FT_COMPLEX);
      typep = dwarf_fundamental_type (current_objfile, FT_COMPLEX);
      break;
      break;
 
 
    case FT_dbl_prec_complex:
    case FT_dbl_prec_complex:
      typep = dwarf_fundamental_type (current_objfile, FT_DBL_PREC_COMPLEX);
      typep = dwarf_fundamental_type (current_objfile, FT_DBL_PREC_COMPLEX);
      break;
      break;
 
 
    case FT_ext_prec_complex:
    case FT_ext_prec_complex:
      typep = dwarf_fundamental_type (current_objfile, FT_EXT_PREC_COMPLEX);
      typep = dwarf_fundamental_type (current_objfile, FT_EXT_PREC_COMPLEX);
      break;
      break;
 
 
    }
    }
 
 
  if (typep == NULL)
  if (typep == NULL)
    {
    {
      typep = dwarf_fundamental_type (current_objfile, FT_INTEGER);
      typep = dwarf_fundamental_type (current_objfile, FT_INTEGER);
      if (!(FT_lo_user <= fundtype && fundtype <= FT_hi_user))
      if (!(FT_lo_user <= fundtype && fundtype <= FT_hi_user))
        {
        {
          complain (&unexpected_fund_type, DIE_ID, DIE_NAME, fundtype);
          complain (&unexpected_fund_type, DIE_ID, DIE_NAME, fundtype);
        }
        }
    }
    }
 
 
  return (typep);
  return (typep);
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   create_name -- allocate a fresh copy of a string on an obstack
   create_name -- allocate a fresh copy of a string on an obstack
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Given a pointer to a string and a pointer to an obstack, allocates
   Given a pointer to a string and a pointer to an obstack, allocates
   a fresh copy of the string on the specified obstack.
   a fresh copy of the string on the specified obstack.
 
 
 */
 */
 
 
static char *
static char *
create_name (name, obstackp)
create_name (name, obstackp)
     char *name;
     char *name;
     struct obstack *obstackp;
     struct obstack *obstackp;
{
{
  int length;
  int length;
  char *newname;
  char *newname;
 
 
  length = strlen (name) + 1;
  length = strlen (name) + 1;
  newname = (char *) obstack_alloc (obstackp, length);
  newname = (char *) obstack_alloc (obstackp, length);
  strcpy (newname, name);
  strcpy (newname, name);
  return (newname);
  return (newname);
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   basicdieinfo -- extract the minimal die info from raw die data
   basicdieinfo -- extract the minimal die info from raw die data
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   void basicdieinfo (char *diep, struct dieinfo *dip,
   void basicdieinfo (char *diep, struct dieinfo *dip,
   struct objfile *objfile)
   struct objfile *objfile)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Given a pointer to raw DIE data, and a pointer to an instance of a
   Given a pointer to raw DIE data, and a pointer to an instance of a
   die info structure, this function extracts the basic information
   die info structure, this function extracts the basic information
   from the DIE data required to continue processing this DIE, along
   from the DIE data required to continue processing this DIE, along
   with some bookkeeping information about the DIE.
   with some bookkeeping information about the DIE.
 
 
   The information we absolutely must have includes the DIE tag,
   The information we absolutely must have includes the DIE tag,
   and the DIE length.  If we need the sibling reference, then we
   and the DIE length.  If we need the sibling reference, then we
   will have to call completedieinfo() to process all the remaining
   will have to call completedieinfo() to process all the remaining
   DIE information.
   DIE information.
 
 
   Note that since there is no guarantee that the data is properly
   Note that since there is no guarantee that the data is properly
   aligned in memory for the type of access required (indirection
   aligned in memory for the type of access required (indirection
   through anything other than a char pointer), and there is no
   through anything other than a char pointer), and there is no
   guarantee that it is in the same byte order as the gdb host,
   guarantee that it is in the same byte order as the gdb host,
   we call a function which deals with both alignment and byte
   we call a function which deals with both alignment and byte
   swapping issues.  Possibly inefficient, but quite portable.
   swapping issues.  Possibly inefficient, but quite portable.
 
 
   We also take care of some other basic things at this point, such
   We also take care of some other basic things at this point, such
   as ensuring that the instance of the die info structure starts
   as ensuring that the instance of the die info structure starts
   out completely zero'd and that curdie is initialized for use
   out completely zero'd and that curdie is initialized for use
   in error reporting if we have a problem with the current die.
   in error reporting if we have a problem with the current die.
 
 
   NOTES
   NOTES
 
 
   All DIE's must have at least a valid length, thus the minimum
   All DIE's must have at least a valid length, thus the minimum
   DIE size is SIZEOF_DIE_LENGTH.  In order to have a valid tag, the
   DIE size is SIZEOF_DIE_LENGTH.  In order to have a valid tag, the
   DIE size must be at least SIZEOF_DIE_TAG larger, otherwise they
   DIE size must be at least SIZEOF_DIE_TAG larger, otherwise they
   are forced to be TAG_padding DIES.
   are forced to be TAG_padding DIES.
 
 
   Padding DIES must be at least SIZEOF_DIE_LENGTH in length, implying
   Padding DIES must be at least SIZEOF_DIE_LENGTH in length, implying
   that if a padding DIE is used for alignment and the amount needed is
   that if a padding DIE is used for alignment and the amount needed is
   less than SIZEOF_DIE_LENGTH, then the padding DIE has to be big
   less than SIZEOF_DIE_LENGTH, then the padding DIE has to be big
   enough to align to the next alignment boundry.
   enough to align to the next alignment boundry.
 
 
   We do some basic sanity checking here, such as verifying that the
   We do some basic sanity checking here, such as verifying that the
   length of the die would not cause it to overrun the recorded end of
   length of the die would not cause it to overrun the recorded end of
   the buffer holding the DIE info.  If we find a DIE that is either
   the buffer holding the DIE info.  If we find a DIE that is either
   too small or too large, we force it's length to zero which should
   too small or too large, we force it's length to zero which should
   cause the caller to take appropriate action.
   cause the caller to take appropriate action.
 */
 */
 
 
static void
static void
basicdieinfo (dip, diep, objfile)
basicdieinfo (dip, diep, objfile)
     struct dieinfo *dip;
     struct dieinfo *dip;
     char *diep;
     char *diep;
     struct objfile *objfile;
     struct objfile *objfile;
{
{
  curdie = dip;
  curdie = dip;
  memset (dip, 0, sizeof (struct dieinfo));
  memset (dip, 0, sizeof (struct dieinfo));
  dip->die = diep;
  dip->die = diep;
  dip->die_ref = dbroff + (diep - dbbase);
  dip->die_ref = dbroff + (diep - dbbase);
  dip->die_length = target_to_host (diep, SIZEOF_DIE_LENGTH, GET_UNSIGNED,
  dip->die_length = target_to_host (diep, SIZEOF_DIE_LENGTH, GET_UNSIGNED,
                                    objfile);
                                    objfile);
  if ((dip->die_length < SIZEOF_DIE_LENGTH) ||
  if ((dip->die_length < SIZEOF_DIE_LENGTH) ||
      ((diep + dip->die_length) > (dbbase + dbsize)))
      ((diep + dip->die_length) > (dbbase + dbsize)))
    {
    {
      complain (&malformed_die, DIE_ID, DIE_NAME, dip->die_length);
      complain (&malformed_die, DIE_ID, DIE_NAME, dip->die_length);
      dip->die_length = 0;
      dip->die_length = 0;
    }
    }
  else if (dip->die_length < (SIZEOF_DIE_LENGTH + SIZEOF_DIE_TAG))
  else if (dip->die_length < (SIZEOF_DIE_LENGTH + SIZEOF_DIE_TAG))
    {
    {
      dip->die_tag = TAG_padding;
      dip->die_tag = TAG_padding;
    }
    }
  else
  else
    {
    {
      diep += SIZEOF_DIE_LENGTH;
      diep += SIZEOF_DIE_LENGTH;
      dip->die_tag = target_to_host (diep, SIZEOF_DIE_TAG, GET_UNSIGNED,
      dip->die_tag = target_to_host (diep, SIZEOF_DIE_TAG, GET_UNSIGNED,
                                     objfile);
                                     objfile);
    }
    }
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   completedieinfo -- finish reading the information for a given DIE
   completedieinfo -- finish reading the information for a given DIE
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   void completedieinfo (struct dieinfo *dip, struct objfile *objfile)
   void completedieinfo (struct dieinfo *dip, struct objfile *objfile)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Given a pointer to an already partially initialized die info structure,
   Given a pointer to an already partially initialized die info structure,
   scan the raw DIE data and finish filling in the die info structure
   scan the raw DIE data and finish filling in the die info structure
   from the various attributes found.
   from the various attributes found.
 
 
   Note that since there is no guarantee that the data is properly
   Note that since there is no guarantee that the data is properly
   aligned in memory for the type of access required (indirection
   aligned in memory for the type of access required (indirection
   through anything other than a char pointer), and there is no
   through anything other than a char pointer), and there is no
   guarantee that it is in the same byte order as the gdb host,
   guarantee that it is in the same byte order as the gdb host,
   we call a function which deals with both alignment and byte
   we call a function which deals with both alignment and byte
   swapping issues.  Possibly inefficient, but quite portable.
   swapping issues.  Possibly inefficient, but quite portable.
 
 
   NOTES
   NOTES
 
 
   Each time we are called, we increment the diecount variable, which
   Each time we are called, we increment the diecount variable, which
   keeps an approximate count of the number of dies processed for
   keeps an approximate count of the number of dies processed for
   each compilation unit.  This information is presented to the user
   each compilation unit.  This information is presented to the user
   if the info_verbose flag is set.
   if the info_verbose flag is set.
 
 
 */
 */
 
 
static void
static void
completedieinfo (dip, objfile)
completedieinfo (dip, objfile)
     struct dieinfo *dip;
     struct dieinfo *dip;
     struct objfile *objfile;
     struct objfile *objfile;
{
{
  char *diep;                   /* Current pointer into raw DIE data */
  char *diep;                   /* Current pointer into raw DIE data */
  char *end;                    /* Terminate DIE scan here */
  char *end;                    /* Terminate DIE scan here */
  unsigned short attr;          /* Current attribute being scanned */
  unsigned short attr;          /* Current attribute being scanned */
  unsigned short form;          /* Form of the attribute */
  unsigned short form;          /* Form of the attribute */
  int nbytes;                   /* Size of next field to read */
  int nbytes;                   /* Size of next field to read */
 
 
  diecount++;
  diecount++;
  diep = dip->die;
  diep = dip->die;
  end = diep + dip->die_length;
  end = diep + dip->die_length;
  diep += SIZEOF_DIE_LENGTH + SIZEOF_DIE_TAG;
  diep += SIZEOF_DIE_LENGTH + SIZEOF_DIE_TAG;
  while (diep < end)
  while (diep < end)
    {
    {
      attr = target_to_host (diep, SIZEOF_ATTRIBUTE, GET_UNSIGNED, objfile);
      attr = target_to_host (diep, SIZEOF_ATTRIBUTE, GET_UNSIGNED, objfile);
      diep += SIZEOF_ATTRIBUTE;
      diep += SIZEOF_ATTRIBUTE;
      if ((nbytes = attribute_size (attr)) == -1)
      if ((nbytes = attribute_size (attr)) == -1)
        {
        {
          complain (&unknown_attribute_length, DIE_ID, DIE_NAME);
          complain (&unknown_attribute_length, DIE_ID, DIE_NAME);
          diep = end;
          diep = end;
          continue;
          continue;
        }
        }
      switch (attr)
      switch (attr)
        {
        {
        case AT_fund_type:
        case AT_fund_type:
          dip->at_fund_type = target_to_host (diep, nbytes, GET_UNSIGNED,
          dip->at_fund_type = target_to_host (diep, nbytes, GET_UNSIGNED,
                                              objfile);
                                              objfile);
          break;
          break;
        case AT_ordering:
        case AT_ordering:
          dip->at_ordering = target_to_host (diep, nbytes, GET_UNSIGNED,
          dip->at_ordering = target_to_host (diep, nbytes, GET_UNSIGNED,
                                             objfile);
                                             objfile);
          break;
          break;
        case AT_bit_offset:
        case AT_bit_offset:
          dip->at_bit_offset = target_to_host (diep, nbytes, GET_UNSIGNED,
          dip->at_bit_offset = target_to_host (diep, nbytes, GET_UNSIGNED,
                                               objfile);
                                               objfile);
          break;
          break;
        case AT_sibling:
        case AT_sibling:
          dip->at_sibling = target_to_host (diep, nbytes, GET_UNSIGNED,
          dip->at_sibling = target_to_host (diep, nbytes, GET_UNSIGNED,
                                            objfile);
                                            objfile);
          break;
          break;
        case AT_stmt_list:
        case AT_stmt_list:
          dip->at_stmt_list = target_to_host (diep, nbytes, GET_UNSIGNED,
          dip->at_stmt_list = target_to_host (diep, nbytes, GET_UNSIGNED,
                                              objfile);
                                              objfile);
          dip->has_at_stmt_list = 1;
          dip->has_at_stmt_list = 1;
          break;
          break;
        case AT_low_pc:
        case AT_low_pc:
          dip->at_low_pc = target_to_host (diep, nbytes, GET_UNSIGNED,
          dip->at_low_pc = target_to_host (diep, nbytes, GET_UNSIGNED,
                                           objfile);
                                           objfile);
          dip->at_low_pc += baseaddr;
          dip->at_low_pc += baseaddr;
          dip->has_at_low_pc = 1;
          dip->has_at_low_pc = 1;
          break;
          break;
        case AT_high_pc:
        case AT_high_pc:
          dip->at_high_pc = target_to_host (diep, nbytes, GET_UNSIGNED,
          dip->at_high_pc = target_to_host (diep, nbytes, GET_UNSIGNED,
                                            objfile);
                                            objfile);
          dip->at_high_pc += baseaddr;
          dip->at_high_pc += baseaddr;
          break;
          break;
        case AT_language:
        case AT_language:
          dip->at_language = target_to_host (diep, nbytes, GET_UNSIGNED,
          dip->at_language = target_to_host (diep, nbytes, GET_UNSIGNED,
                                             objfile);
                                             objfile);
          break;
          break;
        case AT_user_def_type:
        case AT_user_def_type:
          dip->at_user_def_type = target_to_host (diep, nbytes,
          dip->at_user_def_type = target_to_host (diep, nbytes,
                                                  GET_UNSIGNED, objfile);
                                                  GET_UNSIGNED, objfile);
          break;
          break;
        case AT_byte_size:
        case AT_byte_size:
          dip->at_byte_size = target_to_host (diep, nbytes, GET_UNSIGNED,
          dip->at_byte_size = target_to_host (diep, nbytes, GET_UNSIGNED,
                                              objfile);
                                              objfile);
          dip->has_at_byte_size = 1;
          dip->has_at_byte_size = 1;
          break;
          break;
        case AT_bit_size:
        case AT_bit_size:
          dip->at_bit_size = target_to_host (diep, nbytes, GET_UNSIGNED,
          dip->at_bit_size = target_to_host (diep, nbytes, GET_UNSIGNED,
                                             objfile);
                                             objfile);
          break;
          break;
        case AT_member:
        case AT_member:
          dip->at_member = target_to_host (diep, nbytes, GET_UNSIGNED,
          dip->at_member = target_to_host (diep, nbytes, GET_UNSIGNED,
                                           objfile);
                                           objfile);
          break;
          break;
        case AT_discr:
        case AT_discr:
          dip->at_discr = target_to_host (diep, nbytes, GET_UNSIGNED,
          dip->at_discr = target_to_host (diep, nbytes, GET_UNSIGNED,
                                          objfile);
                                          objfile);
          break;
          break;
        case AT_location:
        case AT_location:
          dip->at_location = diep;
          dip->at_location = diep;
          break;
          break;
        case AT_mod_fund_type:
        case AT_mod_fund_type:
          dip->at_mod_fund_type = diep;
          dip->at_mod_fund_type = diep;
          break;
          break;
        case AT_subscr_data:
        case AT_subscr_data:
          dip->at_subscr_data = diep;
          dip->at_subscr_data = diep;
          break;
          break;
        case AT_mod_u_d_type:
        case AT_mod_u_d_type:
          dip->at_mod_u_d_type = diep;
          dip->at_mod_u_d_type = diep;
          break;
          break;
        case AT_element_list:
        case AT_element_list:
          dip->at_element_list = diep;
          dip->at_element_list = diep;
          dip->short_element_list = 0;
          dip->short_element_list = 0;
          break;
          break;
        case AT_short_element_list:
        case AT_short_element_list:
          dip->at_element_list = diep;
          dip->at_element_list = diep;
          dip->short_element_list = 1;
          dip->short_element_list = 1;
          break;
          break;
        case AT_discr_value:
        case AT_discr_value:
          dip->at_discr_value = diep;
          dip->at_discr_value = diep;
          break;
          break;
        case AT_string_length:
        case AT_string_length:
          dip->at_string_length = diep;
          dip->at_string_length = diep;
          break;
          break;
        case AT_name:
        case AT_name:
          dip->at_name = diep;
          dip->at_name = diep;
          break;
          break;
        case AT_comp_dir:
        case AT_comp_dir:
          /* For now, ignore any "hostname:" portion, since gdb doesn't
          /* For now, ignore any "hostname:" portion, since gdb doesn't
             know how to deal with it.  (FIXME). */
             know how to deal with it.  (FIXME). */
          dip->at_comp_dir = strrchr (diep, ':');
          dip->at_comp_dir = strrchr (diep, ':');
          if (dip->at_comp_dir != NULL)
          if (dip->at_comp_dir != NULL)
            {
            {
              dip->at_comp_dir++;
              dip->at_comp_dir++;
            }
            }
          else
          else
            {
            {
              dip->at_comp_dir = diep;
              dip->at_comp_dir = diep;
            }
            }
          break;
          break;
        case AT_producer:
        case AT_producer:
          dip->at_producer = diep;
          dip->at_producer = diep;
          break;
          break;
        case AT_start_scope:
        case AT_start_scope:
          dip->at_start_scope = target_to_host (diep, nbytes, GET_UNSIGNED,
          dip->at_start_scope = target_to_host (diep, nbytes, GET_UNSIGNED,
                                                objfile);
                                                objfile);
          break;
          break;
        case AT_stride_size:
        case AT_stride_size:
          dip->at_stride_size = target_to_host (diep, nbytes, GET_UNSIGNED,
          dip->at_stride_size = target_to_host (diep, nbytes, GET_UNSIGNED,
                                                objfile);
                                                objfile);
          break;
          break;
        case AT_src_info:
        case AT_src_info:
          dip->at_src_info = target_to_host (diep, nbytes, GET_UNSIGNED,
          dip->at_src_info = target_to_host (diep, nbytes, GET_UNSIGNED,
                                             objfile);
                                             objfile);
          break;
          break;
        case AT_prototyped:
        case AT_prototyped:
          dip->at_prototyped = diep;
          dip->at_prototyped = diep;
          break;
          break;
        default:
        default:
          /* Found an attribute that we are unprepared to handle.  However
          /* Found an attribute that we are unprepared to handle.  However
             it is specifically one of the design goals of DWARF that
             it is specifically one of the design goals of DWARF that
             consumers should ignore unknown attributes.  As long as the
             consumers should ignore unknown attributes.  As long as the
             form is one that we recognize (so we know how to skip it),
             form is one that we recognize (so we know how to skip it),
             we can just ignore the unknown attribute. */
             we can just ignore the unknown attribute. */
          break;
          break;
        }
        }
      form = FORM_FROM_ATTR (attr);
      form = FORM_FROM_ATTR (attr);
      switch (form)
      switch (form)
        {
        {
        case FORM_DATA2:
        case FORM_DATA2:
          diep += 2;
          diep += 2;
          break;
          break;
        case FORM_DATA4:
        case FORM_DATA4:
        case FORM_REF:
        case FORM_REF:
          diep += 4;
          diep += 4;
          break;
          break;
        case FORM_DATA8:
        case FORM_DATA8:
          diep += 8;
          diep += 8;
          break;
          break;
        case FORM_ADDR:
        case FORM_ADDR:
          diep += TARGET_FT_POINTER_SIZE (objfile);
          diep += TARGET_FT_POINTER_SIZE (objfile);
          break;
          break;
        case FORM_BLOCK2:
        case FORM_BLOCK2:
          diep += 2 + target_to_host (diep, nbytes, GET_UNSIGNED, objfile);
          diep += 2 + target_to_host (diep, nbytes, GET_UNSIGNED, objfile);
          break;
          break;
        case FORM_BLOCK4:
        case FORM_BLOCK4:
          diep += 4 + target_to_host (diep, nbytes, GET_UNSIGNED, objfile);
          diep += 4 + target_to_host (diep, nbytes, GET_UNSIGNED, objfile);
          break;
          break;
        case FORM_STRING:
        case FORM_STRING:
          diep += strlen (diep) + 1;
          diep += strlen (diep) + 1;
          break;
          break;
        default:
        default:
          complain (&unknown_attribute_form, DIE_ID, DIE_NAME, form);
          complain (&unknown_attribute_form, DIE_ID, DIE_NAME, form);
          diep = end;
          diep = end;
          break;
          break;
        }
        }
    }
    }
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   target_to_host -- swap in target data to host
   target_to_host -- swap in target data to host
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   target_to_host (char *from, int nbytes, int signextend,
   target_to_host (char *from, int nbytes, int signextend,
   struct objfile *objfile)
   struct objfile *objfile)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Given pointer to data in target format in FROM, a byte count for
   Given pointer to data in target format in FROM, a byte count for
   the size of the data in NBYTES, a flag indicating whether or not
   the size of the data in NBYTES, a flag indicating whether or not
   the data is signed in SIGNEXTEND, and a pointer to the current
   the data is signed in SIGNEXTEND, and a pointer to the current
   objfile in OBJFILE, convert the data to host format and return
   objfile in OBJFILE, convert the data to host format and return
   the converted value.
   the converted value.
 
 
   NOTES
   NOTES
 
 
   FIXME:  If we read data that is known to be signed, and expect to
   FIXME:  If we read data that is known to be signed, and expect to
   use it as signed data, then we need to explicitly sign extend the
   use it as signed data, then we need to explicitly sign extend the
   result until the bfd library is able to do this for us.
   result until the bfd library is able to do this for us.
 
 
   FIXME: Would a 32 bit target ever need an 8 byte result?
   FIXME: Would a 32 bit target ever need an 8 byte result?
 
 
 */
 */
 
 
static CORE_ADDR
static CORE_ADDR
target_to_host (from, nbytes, signextend, objfile)
target_to_host (from, nbytes, signextend, objfile)
     char *from;
     char *from;
     int nbytes;
     int nbytes;
     int signextend;            /* FIXME:  Unused */
     int signextend;            /* FIXME:  Unused */
     struct objfile *objfile;
     struct objfile *objfile;
{
{
  CORE_ADDR rtnval;
  CORE_ADDR rtnval;
 
 
  switch (nbytes)
  switch (nbytes)
    {
    {
    case 8:
    case 8:
      rtnval = bfd_get_64 (objfile->obfd, (bfd_byte *) from);
      rtnval = bfd_get_64 (objfile->obfd, (bfd_byte *) from);
      break;
      break;
    case 4:
    case 4:
      rtnval = bfd_get_32 (objfile->obfd, (bfd_byte *) from);
      rtnval = bfd_get_32 (objfile->obfd, (bfd_byte *) from);
      break;
      break;
    case 2:
    case 2:
      rtnval = bfd_get_16 (objfile->obfd, (bfd_byte *) from);
      rtnval = bfd_get_16 (objfile->obfd, (bfd_byte *) from);
      break;
      break;
    case 1:
    case 1:
      rtnval = bfd_get_8 (objfile->obfd, (bfd_byte *) from);
      rtnval = bfd_get_8 (objfile->obfd, (bfd_byte *) from);
      break;
      break;
    default:
    default:
      complain (&no_bfd_get_N, DIE_ID, DIE_NAME, nbytes);
      complain (&no_bfd_get_N, DIE_ID, DIE_NAME, nbytes);
      rtnval = 0;
      rtnval = 0;
      break;
      break;
    }
    }
  return (rtnval);
  return (rtnval);
}
}
 
 
/*
/*
 
 
   LOCAL FUNCTION
   LOCAL FUNCTION
 
 
   attribute_size -- compute size of data for a DWARF attribute
   attribute_size -- compute size of data for a DWARF attribute
 
 
   SYNOPSIS
   SYNOPSIS
 
 
   static int attribute_size (unsigned int attr)
   static int attribute_size (unsigned int attr)
 
 
   DESCRIPTION
   DESCRIPTION
 
 
   Given a DWARF attribute in ATTR, compute the size of the first
   Given a DWARF attribute in ATTR, compute the size of the first
   piece of data associated with this attribute and return that
   piece of data associated with this attribute and return that
   size.
   size.
 
 
   Returns -1 for unrecognized attributes.
   Returns -1 for unrecognized attributes.
 
 
 */
 */
 
 
static int
static int
attribute_size (attr)
attribute_size (attr)
     unsigned int attr;
     unsigned int attr;
{
{
  int nbytes;                   /* Size of next data for this attribute */
  int nbytes;                   /* Size of next data for this attribute */
  unsigned short form;          /* Form of the attribute */
  unsigned short form;          /* Form of the attribute */
 
 
  form = FORM_FROM_ATTR (attr);
  form = FORM_FROM_ATTR (attr);
  switch (form)
  switch (form)
    {
    {
    case FORM_STRING:           /* A variable length field is next */
    case FORM_STRING:           /* A variable length field is next */
      nbytes = 0;
      nbytes = 0;
      break;
      break;
    case FORM_DATA2:            /* Next 2 byte field is the data itself */
    case FORM_DATA2:            /* Next 2 byte field is the data itself */
    case FORM_BLOCK2:           /* Next 2 byte field is a block length */
    case FORM_BLOCK2:           /* Next 2 byte field is a block length */
      nbytes = 2;
      nbytes = 2;
      break;
      break;
    case FORM_DATA4:            /* Next 4 byte field is the data itself */
    case FORM_DATA4:            /* Next 4 byte field is the data itself */
    case FORM_BLOCK4:           /* Next 4 byte field is a block length */
    case FORM_BLOCK4:           /* Next 4 byte field is a block length */
    case FORM_REF:              /* Next 4 byte field is a DIE offset */
    case FORM_REF:              /* Next 4 byte field is a DIE offset */
      nbytes = 4;
      nbytes = 4;
      break;
      break;
    case FORM_DATA8:            /* Next 8 byte field is the data itself */
    case FORM_DATA8:            /* Next 8 byte field is the data itself */
      nbytes = 8;
      nbytes = 8;
      break;
      break;
    case FORM_ADDR:             /* Next field size is target sizeof(void *) */
    case FORM_ADDR:             /* Next field size is target sizeof(void *) */
      nbytes = TARGET_FT_POINTER_SIZE (objfile);
      nbytes = TARGET_FT_POINTER_SIZE (objfile);
      break;
      break;
    default:
    default:
      complain (&unknown_attribute_form, DIE_ID, DIE_NAME, form);
      complain (&unknown_attribute_form, DIE_ID, DIE_NAME, form);
      nbytes = -1;
      nbytes = -1;
      break;
      break;
    }
    }
  return (nbytes);
  return (nbytes);
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.