119370Spst/* DWARF debugging format support for GDB. 2130803Smarcel 3130803Smarcel Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 4130803Smarcel 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. 5130803Smarcel 619370Spst Written by Fred Fish at Cygnus Support. Portions based on dbxread.c, 719370Spst mipsread.c, coffread.c, and dwarfread.c from a Data General SVR4 gdb port. 819370Spst 998944Sobrien This file is part of GDB. 1019370Spst 1198944Sobrien This program is free software; you can redistribute it and/or modify 1298944Sobrien it under the terms of the GNU General Public License as published by 1398944Sobrien the Free Software Foundation; either version 2 of the License, or 1498944Sobrien (at your option) any later version. 1519370Spst 1698944Sobrien This program is distributed in the hope that it will be useful, 1798944Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1898944Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1998944Sobrien GNU General Public License for more details. 2019370Spst 2198944Sobrien You should have received a copy of the GNU General Public License 2298944Sobrien along with this program; if not, write to the Free Software 2398944Sobrien Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 2419370Spst 2519370Spst/* 26130803Smarcel If you are looking for DWARF-2 support, you are in the wrong file. 27130803Smarcel Go look in dwarf2read.c. This file is for the original DWARF, 28130803Smarcel also known as DWARF-1. 2919370Spst 30130803Smarcel DWARF-1 is slowly headed for obsoletion. 31130803Smarcel 32130803Smarcel In gcc HEAD 2003-11-29 16:28:31 UTC, no targets prefer dwarf-1. 33130803Smarcel 34130803Smarcel In gcc 3.3.2, these targets prefer dwarf-1: 35130803Smarcel 36130803Smarcel i[34567]86-sequent-ptx4* 37130803Smarcel i[34567]86-sequent-sysv4* 38130803Smarcel mips-sni-sysv4 39130803Smarcel sparc-hal-solaris2* 40130803Smarcel 41130803Smarcel In gcc 3.2.2, these targets prefer dwarf-1: 42130803Smarcel 43130803Smarcel i[34567]86-dg-dgux* 44130803Smarcel i[34567]86-sequent-ptx4* 45130803Smarcel i[34567]86-sequent-sysv4* 46130803Smarcel m88k-dg-dgux* 47130803Smarcel mips-sni-sysv4 48130803Smarcel sparc-hal-solaris2* 49130803Smarcel 50130803Smarcel In gcc 2.95.3, these targets prefer dwarf-1: 51130803Smarcel 52130803Smarcel i[34567]86-dg-dgux* 53130803Smarcel i[34567]86-ncr-sysv4* 54130803Smarcel i[34567]86-sequent-ptx4* 55130803Smarcel i[34567]86-sequent-sysv4* 56130803Smarcel i[34567]86-*-osf1* 57130803Smarcel i[34567]86-*-sco3.2v5* 58130803Smarcel i[34567]86-*-sysv4* 59130803Smarcel i860-alliant-* 60130803Smarcel i860-*-sysv4* 61130803Smarcel m68k-atari-sysv4* 62130803Smarcel m68k-cbm-sysv4* 63130803Smarcel m68k-*-sysv4* 64130803Smarcel m88k-dg-dgux* 65130803Smarcel m88k-*-sysv4* 66130803Smarcel mips-sni-sysv4 67130803Smarcel mips-*-gnu* 68130803Smarcel sh-*-elf* 69130803Smarcel sh-*-rtemself* 70130803Smarcel sparc-hal-solaris2* 71130803Smarcel sparc-*-sysv4* 72130803Smarcel 73130803Smarcel Some non-gcc compilers produce dwarf-1: 74130803Smarcel 75130803Smarcel PR gdb/1179 was from a user with Diab C++ 4.3. 76130803Smarcel Other users have also reported using Diab compilers with dwarf-1. 77130803Smarcel On 2003-06-09 the gdb list received a report from a user 78130803Smarcel with Absoft ProFortran f77 which is dwarf-1. 79130803Smarcel 80130803Smarcel -- chastain 2003-12-01 81130803Smarcel*/ 82130803Smarcel 83130803Smarcel/* 84130803Smarcel 8598944Sobrien FIXME: Do we need to generate dependencies in partial symtabs? 8698944Sobrien (Perhaps we don't need to). 8719370Spst 8898944Sobrien FIXME: Resolve minor differences between what information we put in the 8998944Sobrien partial symbol table and what dbxread puts in. For example, we don't yet 9098944Sobrien put enum constants there. And dbxread seems to invent a lot of typedefs 9198944Sobrien we never see. Use the new printpsym command to see the partial symbol table 9298944Sobrien contents. 9319370Spst 9498944Sobrien FIXME: Figure out a better way to tell gdb about the name of the function 9598944Sobrien contain the user's entry point (I.E. main()) 9619370Spst 9798944Sobrien FIXME: See other FIXME's and "ifdef 0" scattered throughout the code for 9898944Sobrien other things to work on, if you get bored. :-) 9919370Spst 10098944Sobrien */ 10119370Spst 10219370Spst#include "defs.h" 10319370Spst#include "symtab.h" 10419370Spst#include "gdbtypes.h" 10519370Spst#include "objfiles.h" 10619370Spst#include "elf/dwarf.h" 10719370Spst#include "buildsym.h" 10819370Spst#include "demangle.h" 10998944Sobrien#include "expression.h" /* Needed for enum exp_opcode in language.h, sigh... */ 11019370Spst#include "language.h" 11119370Spst#include "complaints.h" 11219370Spst 11319370Spst#include <fcntl.h> 11419370Spst#include "gdb_string.h" 11519370Spst 11619370Spst/* Some macros to provide DIE info for complaints. */ 11719370Spst 11819370Spst#define DIE_ID (curdie!=NULL ? curdie->die_ref : 0) 11919370Spst#define DIE_NAME (curdie!=NULL && curdie->at_name!=NULL) ? curdie->at_name : "" 12019370Spst 12119370Spst/* Complaints that can be issued during DWARF debug info reading. */ 12219370Spst 123130803Smarcelstatic void 124130803Smarcelbad_die_ref_complaint (int arg1, const char *arg2, int arg3) 12519370Spst{ 126130803Smarcel complaint (&symfile_complaints, 127130803Smarcel "DIE @ 0x%x \"%s\", reference to DIE (0x%x) outside compilation unit", 128130803Smarcel arg1, arg2, arg3); 129130803Smarcel} 13019370Spst 131130803Smarcelstatic void 132130803Smarcelunknown_attribute_form_complaint (int arg1, const char *arg2, int arg3) 13319370Spst{ 134130803Smarcel complaint (&symfile_complaints, 135130803Smarcel "DIE @ 0x%x \"%s\", unknown attribute form (0x%x)", arg1, arg2, 136130803Smarcel arg3); 137130803Smarcel} 13819370Spst 139130803Smarcelstatic void 140130803Smarceldup_user_type_definition_complaint (int arg1, const char *arg2) 14119370Spst{ 142130803Smarcel complaint (&symfile_complaints, 143130803Smarcel "DIE @ 0x%x \"%s\", internal error: duplicate user type definition", 144130803Smarcel arg1, arg2); 145130803Smarcel} 14619370Spst 147130803Smarcelstatic void 148130803Smarcelbad_array_element_type_complaint (int arg1, const char *arg2, int arg3) 14919370Spst{ 150130803Smarcel complaint (&symfile_complaints, 151130803Smarcel "DIE @ 0x%x \"%s\", bad array element type attribute 0x%x", arg1, 152130803Smarcel arg2, arg3); 153130803Smarcel} 15419370Spst 15519370Spsttypedef unsigned int DIE_REF; /* Reference to a DIE */ 15619370Spst 15719370Spst#ifndef GCC_PRODUCER 15819370Spst#define GCC_PRODUCER "GNU C " 15919370Spst#endif 16019370Spst 16119370Spst#ifndef GPLUS_PRODUCER 16219370Spst#define GPLUS_PRODUCER "GNU C++ " 16319370Spst#endif 16419370Spst 16519370Spst#ifndef LCC_PRODUCER 16619370Spst#define LCC_PRODUCER "NCR C/C++" 16719370Spst#endif 16819370Spst 16919370Spst/* Flags to target_to_host() that tell whether or not the data object is 17019370Spst expected to be signed. Used, for example, when fetching a signed 17119370Spst integer in the target environment which is used as a signed integer 17219370Spst in the host environment, and the two environments have different sized 17319370Spst ints. In this case, *somebody* has to sign extend the smaller sized 17419370Spst int. */ 17519370Spst 17619370Spst#define GET_UNSIGNED 0 /* No sign extension required */ 17719370Spst#define GET_SIGNED 1 /* Sign extension required */ 17819370Spst 17919370Spst/* Defines for things which are specified in the document "DWARF Debugging 18019370Spst Information Format" published by UNIX International, Programming Languages 18119370Spst SIG. These defines are based on revision 1.0.0, Jan 20, 1992. */ 18219370Spst 18319370Spst#define SIZEOF_DIE_LENGTH 4 18419370Spst#define SIZEOF_DIE_TAG 2 18519370Spst#define SIZEOF_ATTRIBUTE 2 18619370Spst#define SIZEOF_FORMAT_SPECIFIER 1 18719370Spst#define SIZEOF_FMT_FT 2 18819370Spst#define SIZEOF_LINETBL_LENGTH 4 18919370Spst#define SIZEOF_LINETBL_LINENO 4 19019370Spst#define SIZEOF_LINETBL_STMT 2 19119370Spst#define SIZEOF_LINETBL_DELTA 4 19219370Spst#define SIZEOF_LOC_ATOM_CODE 1 19319370Spst 19419370Spst#define FORM_FROM_ATTR(attr) ((attr) & 0xF) /* Implicitly specified */ 19519370Spst 19619370Spst/* Macros that return the sizes of various types of data in the target 19719370Spst environment. 19819370Spst 19919370Spst FIXME: Currently these are just compile time constants (as they are in 20019370Spst other parts of gdb as well). They need to be able to get the right size 20119370Spst either from the bfd or possibly from the DWARF info. It would be nice if 20219370Spst the DWARF producer inserted DIES that describe the fundamental types in 20319370Spst the target environment into the DWARF info, similar to the way dbx stabs 20419370Spst producers produce information about their fundamental types. */ 20519370Spst 20619370Spst#define TARGET_FT_POINTER_SIZE(objfile) (TARGET_PTR_BIT / TARGET_CHAR_BIT) 20719370Spst#define TARGET_FT_LONG_SIZE(objfile) (TARGET_LONG_BIT / TARGET_CHAR_BIT) 20819370Spst 20919370Spst/* The Amiga SVR4 header file <dwarf.h> defines AT_element_list as a 21019370Spst FORM_BLOCK2, and this is the value emitted by the AT&T compiler. 21119370Spst However, the Issue 2 DWARF specification from AT&T defines it as 21219370Spst a FORM_BLOCK4, as does the latest specification from UI/PLSIG. 21319370Spst For backwards compatibility with the AT&T compiler produced executables 21419370Spst we define AT_short_element_list for this variant. */ 21519370Spst 21619370Spst#define AT_short_element_list (0x00f0|FORM_BLOCK2) 21719370Spst 21819370Spst/* The DWARF debugging information consists of two major pieces, 21919370Spst one is a block of DWARF Information Entries (DIE's) and the other 22019370Spst is a line number table. The "struct dieinfo" structure contains 22119370Spst the information for a single DIE, the one currently being processed. 22219370Spst 22319370Spst In order to make it easier to randomly access the attribute fields 22419370Spst of the current DIE, which are specifically unordered within the DIE, 22519370Spst each DIE is scanned and an instance of the "struct dieinfo" 22619370Spst structure is initialized. 22719370Spst 22819370Spst Initialization is done in two levels. The first, done by basicdieinfo(), 22919370Spst just initializes those fields that are vital to deciding whether or not 23019370Spst to use this DIE, how to skip past it, etc. The second, done by the 23119370Spst function completedieinfo(), fills in the rest of the information. 23219370Spst 23319370Spst Attributes which have block forms are not interpreted at the time 23419370Spst the DIE is scanned, instead we just save pointers to the start 23519370Spst of their value fields. 23619370Spst 23719370Spst Some fields have a flag <name>_p that is set when the value of the 23819370Spst field is valid (I.E. we found a matching attribute in the DIE). Since 23919370Spst we may want to test for the presence of some attributes in the DIE, 24019370Spst such as AT_low_pc, without restricting the values of the field, 24119370Spst we need someway to note that we found such an attribute. 24298944Sobrien 24319370Spst */ 24498944Sobrien 24519370Spsttypedef char BLOCK; 24619370Spst 24798944Sobrienstruct dieinfo 24898944Sobrien { 24998944Sobrien char *die; /* Pointer to the raw DIE data */ 25098944Sobrien unsigned long die_length; /* Length of the raw DIE data */ 25198944Sobrien DIE_REF die_ref; /* Offset of this DIE */ 25298944Sobrien unsigned short die_tag; /* Tag for this DIE */ 25398944Sobrien unsigned long at_padding; 25498944Sobrien unsigned long at_sibling; 25598944Sobrien BLOCK *at_location; 25698944Sobrien char *at_name; 25798944Sobrien unsigned short at_fund_type; 25898944Sobrien BLOCK *at_mod_fund_type; 25998944Sobrien unsigned long at_user_def_type; 26098944Sobrien BLOCK *at_mod_u_d_type; 26198944Sobrien unsigned short at_ordering; 26298944Sobrien BLOCK *at_subscr_data; 26398944Sobrien unsigned long at_byte_size; 26498944Sobrien unsigned short at_bit_offset; 26598944Sobrien unsigned long at_bit_size; 26698944Sobrien BLOCK *at_element_list; 26798944Sobrien unsigned long at_stmt_list; 26898944Sobrien CORE_ADDR at_low_pc; 26998944Sobrien CORE_ADDR at_high_pc; 27098944Sobrien unsigned long at_language; 27198944Sobrien unsigned long at_member; 27298944Sobrien unsigned long at_discr; 27398944Sobrien BLOCK *at_discr_value; 27498944Sobrien BLOCK *at_string_length; 27598944Sobrien char *at_comp_dir; 27698944Sobrien char *at_producer; 27798944Sobrien unsigned long at_start_scope; 27898944Sobrien unsigned long at_stride_size; 27998944Sobrien unsigned long at_src_info; 28098944Sobrien char *at_prototyped; 28198944Sobrien unsigned int has_at_low_pc:1; 28298944Sobrien unsigned int has_at_stmt_list:1; 28398944Sobrien unsigned int has_at_byte_size:1; 28498944Sobrien unsigned int short_element_list:1; 28546283Sdfr 28698944Sobrien /* Kludge to identify register variables */ 28746283Sdfr 28898944Sobrien unsigned int isreg; 28946283Sdfr 29098944Sobrien /* Kludge to identify optimized out variables */ 29146283Sdfr 29298944Sobrien unsigned int optimized_out; 29346283Sdfr 29498944Sobrien /* Kludge to identify basereg references. 29598944Sobrien Nonzero if we have an offset relative to a basereg. */ 29646283Sdfr 29798944Sobrien unsigned int offreg; 29846283Sdfr 29998944Sobrien /* Kludge to identify which base register is it relative to. */ 30046283Sdfr 30198944Sobrien unsigned int basereg; 30298944Sobrien }; 30319370Spst 30498944Sobrienstatic int diecount; /* Approximate count of dies for compilation unit */ 30519370Spststatic struct dieinfo *curdie; /* For warnings and such */ 30619370Spst 30798944Sobrienstatic char *dbbase; /* Base pointer to dwarf info */ 30898944Sobrienstatic int dbsize; /* Size of dwarf info in bytes */ 30998944Sobrienstatic int dbroff; /* Relative offset from start of .debug section */ 31098944Sobrienstatic char *lnbase; /* Base pointer to line section */ 31119370Spst 31219370Spst/* This value is added to each symbol value. FIXME: Generalize to 31319370Spst the section_offsets structure used by dbxread (once this is done, 31419370Spst pass the appropriate section number to end_symtab). */ 31519370Spststatic CORE_ADDR baseaddr; /* Add to each symbol value */ 31619370Spst 31719370Spst/* The section offsets used in the current psymtab or symtab. FIXME, 31819370Spst only used to pass one value (baseaddr) at the moment. */ 31919370Spststatic struct section_offsets *base_section_offsets; 32019370Spst 32119370Spst/* We put a pointer to this structure in the read_symtab_private field 32219370Spst of the psymtab. */ 32319370Spst 32498944Sobrienstruct dwfinfo 32598944Sobrien { 32698944Sobrien /* Always the absolute file offset to the start of the ".debug" 32798944Sobrien section for the file containing the DIE's being accessed. */ 32898944Sobrien file_ptr dbfoff; 32998944Sobrien /* Relative offset from the start of the ".debug" section to the 33098944Sobrien first DIE to be accessed. When building the partial symbol 33198944Sobrien table, this value will be zero since we are accessing the 33298944Sobrien entire ".debug" section. When expanding a partial symbol 33398944Sobrien table entry, this value will be the offset to the first 33498944Sobrien DIE for the compilation unit containing the symbol that 33598944Sobrien triggers the expansion. */ 33698944Sobrien int dbroff; 33798944Sobrien /* The size of the chunk of DIE's being examined, in bytes. */ 33898944Sobrien int dblength; 33998944Sobrien /* The absolute file offset to the line table fragment. Ignored 34098944Sobrien when building partial symbol tables, but used when expanding 34198944Sobrien them, and contains the absolute file offset to the fragment 34298944Sobrien of the ".line" section containing the line numbers for the 34398944Sobrien current compilation unit. */ 34498944Sobrien file_ptr lnfoff; 34598944Sobrien }; 34619370Spst 34719370Spst#define DBFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbfoff) 34819370Spst#define DBROFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbroff) 34919370Spst#define DBLENGTH(p) (((struct dwfinfo *)((p)->read_symtab_private))->dblength) 35019370Spst#define LNFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->lnfoff) 35119370Spst 35219370Spst/* The generic symbol table building routines have separate lists for 35319370Spst file scope symbols and all all other scopes (local scopes). So 35419370Spst we need to select the right one to pass to add_symbol_to_list(). 35519370Spst We do it by keeping a pointer to the correct list in list_in_scope. 35619370Spst 35719370Spst FIXME: The original dwarf code just treated the file scope as the first 35819370Spst local scope, and all other local scopes as nested local scopes, and worked 35919370Spst fine. Check to see if we really need to distinguish these in buildsym.c */ 36019370Spst 36119370Spststruct pending **list_in_scope = &file_symbols; 36219370Spst 36319370Spst/* DIES which have user defined types or modified user defined types refer to 36419370Spst other DIES for the type information. Thus we need to associate the offset 36519370Spst of a DIE for a user defined type with a pointer to the type information. 36619370Spst 36719370Spst Originally this was done using a simple but expensive algorithm, with an 36819370Spst array of unsorted structures, each containing an offset/type-pointer pair. 36919370Spst This array was scanned linearly each time a lookup was done. The result 37019370Spst was that gdb was spending over half it's startup time munging through this 37119370Spst array of pointers looking for a structure that had the right offset member. 37219370Spst 37319370Spst The second attempt used the same array of structures, but the array was 37419370Spst sorted using qsort each time a new offset/type was recorded, and a binary 37519370Spst search was used to find the type pointer for a given DIE offset. This was 37619370Spst even slower, due to the overhead of sorting the array each time a new 37719370Spst offset/type pair was entered. 37819370Spst 37919370Spst The third attempt uses a fixed size array of type pointers, indexed by a 38019370Spst value derived from the DIE offset. Since the minimum DIE size is 4 bytes, 38119370Spst we can divide any DIE offset by 4 to obtain a unique index into this fixed 38219370Spst size array. Since each element is a 4 byte pointer, it takes exactly as 38319370Spst much memory to hold this array as to hold the DWARF info for a given 38419370Spst compilation unit. But it gets freed as soon as we are done with it. 38519370Spst This has worked well in practice, as a reasonable tradeoff between memory 38619370Spst consumption and speed, without having to resort to much more complicated 38719370Spst algorithms. */ 38819370Spst 38919370Spststatic struct type **utypes; /* Pointer to array of user type pointers */ 39019370Spststatic int numutypes; /* Max number of user type pointers */ 39119370Spst 39219370Spst/* Maintain an array of referenced fundamental types for the current 39319370Spst compilation unit being read. For DWARF version 1, we have to construct 39419370Spst the fundamental types on the fly, since no information about the 39519370Spst fundamental types is supplied. Each such fundamental type is created by 39619370Spst calling a language dependent routine to create the type, and then a 39719370Spst pointer to that type is then placed in the array at the index specified 39819370Spst by it's FT_<TYPENAME> value. The array has a fixed size set by the 39919370Spst FT_NUM_MEMBERS compile time constant, which is the number of predefined 40019370Spst fundamental types gdb knows how to construct. */ 40119370Spst 40298944Sobrienstatic struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */ 40319370Spst 40419370Spst/* Record the language for the compilation unit which is currently being 40519370Spst processed. We know it once we have seen the TAG_compile_unit DIE, 40619370Spst and we need it while processing the DIE's for that compilation unit. 40719370Spst It is eventually saved in the symtab structure, but we don't finalize 40819370Spst the symtab struct until we have processed all the DIE's for the 40919370Spst compilation unit. We also need to get and save a pointer to the 41019370Spst language struct for this language, so we can call the language 41119370Spst dependent routines for doing things such as creating fundamental 41219370Spst types. */ 41319370Spst 41419370Spststatic enum language cu_language; 41519370Spststatic const struct language_defn *cu_language_defn; 41619370Spst 41719370Spst/* Forward declarations of static functions so we don't have to worry 41819370Spst about ordering within this file. */ 41919370Spst 420130803Smarcelstatic void free_utypes (void *); 42146283Sdfr 42298944Sobrienstatic int attribute_size (unsigned int); 42319370Spst 42498944Sobrienstatic CORE_ADDR target_to_host (char *, int, int, struct objfile *); 42519370Spst 42698944Sobrienstatic void add_enum_psymbol (struct dieinfo *, struct objfile *); 42719370Spst 42898944Sobrienstatic void handle_producer (char *); 42919370Spst 430130803Smarcelstatic void read_file_scope (struct dieinfo *, char *, char *, 431130803Smarcel struct objfile *); 43219370Spst 433130803Smarcelstatic void read_func_scope (struct dieinfo *, char *, char *, 434130803Smarcel struct objfile *); 43519370Spst 436130803Smarcelstatic void read_lexical_block_scope (struct dieinfo *, char *, char *, 437130803Smarcel struct objfile *); 43819370Spst 43998944Sobrienstatic void scan_partial_symbols (char *, char *, struct objfile *); 44019370Spst 441130803Smarcelstatic void scan_compilation_units (char *, char *, file_ptr, file_ptr, 442130803Smarcel struct objfile *); 44319370Spst 44498944Sobrienstatic void add_partial_symbol (struct dieinfo *, struct objfile *); 44519370Spst 44698944Sobrienstatic void basicdieinfo (struct dieinfo *, char *, struct objfile *); 44719370Spst 44898944Sobrienstatic void completedieinfo (struct dieinfo *, struct objfile *); 44919370Spst 45098944Sobrienstatic void dwarf_psymtab_to_symtab (struct partial_symtab *); 45119370Spst 45298944Sobrienstatic void psymtab_to_symtab_1 (struct partial_symtab *); 45319370Spst 45498944Sobrienstatic void read_ofile_symtab (struct partial_symtab *); 45519370Spst 45698944Sobrienstatic void process_dies (char *, char *, struct objfile *); 45719370Spst 458130803Smarcelstatic void read_structure_scope (struct dieinfo *, char *, char *, 459130803Smarcel struct objfile *); 46019370Spst 46198944Sobrienstatic struct type *decode_array_element_type (char *); 46219370Spst 46398944Sobrienstatic struct type *decode_subscript_data_item (char *, char *); 46419370Spst 46598944Sobrienstatic void dwarf_read_array_type (struct dieinfo *); 46619370Spst 46798944Sobrienstatic void read_tag_pointer_type (struct dieinfo *dip); 46819370Spst 46998944Sobrienstatic void read_tag_string_type (struct dieinfo *dip); 47019370Spst 47198944Sobrienstatic void read_subroutine_type (struct dieinfo *, char *, char *); 47219370Spst 473130803Smarcelstatic void read_enumeration (struct dieinfo *, char *, char *, 474130803Smarcel struct objfile *); 47519370Spst 47698944Sobrienstatic struct type *struct_type (struct dieinfo *, char *, char *, 47798944Sobrien struct objfile *); 47819370Spst 47998944Sobrienstatic struct type *enum_type (struct dieinfo *, struct objfile *); 48019370Spst 48198944Sobrienstatic void decode_line_numbers (char *); 48219370Spst 48398944Sobrienstatic struct type *decode_die_type (struct dieinfo *); 48419370Spst 48598944Sobrienstatic struct type *decode_mod_fund_type (char *); 48619370Spst 48798944Sobrienstatic struct type *decode_mod_u_d_type (char *); 48819370Spst 48998944Sobrienstatic struct type *decode_modified_type (char *, unsigned int, int); 49019370Spst 49198944Sobrienstatic struct type *decode_fund_type (unsigned int); 49219370Spst 49398944Sobrienstatic char *create_name (char *, struct obstack *); 49419370Spst 49598944Sobrienstatic struct type *lookup_utype (DIE_REF); 49619370Spst 49798944Sobrienstatic struct type *alloc_utype (DIE_REF, struct type *); 49819370Spst 49998944Sobrienstatic struct symbol *new_symbol (struct dieinfo *, struct objfile *); 50019370Spst 501130803Smarcelstatic void synthesize_typedef (struct dieinfo *, struct objfile *, 502130803Smarcel struct type *); 50319370Spst 50498944Sobrienstatic int locval (struct dieinfo *); 50519370Spst 50698944Sobrienstatic void set_cu_language (struct dieinfo *); 50719370Spst 50898944Sobrienstatic struct type *dwarf_fundamental_type (struct objfile *, int); 50919370Spst 51019370Spst 51119370Spst/* 51219370Spst 51398944Sobrien LOCAL FUNCTION 51419370Spst 51598944Sobrien dwarf_fundamental_type -- lookup or create a fundamental type 51619370Spst 51798944Sobrien SYNOPSIS 51819370Spst 51998944Sobrien struct type * 52098944Sobrien dwarf_fundamental_type (struct objfile *objfile, int typeid) 52119370Spst 52298944Sobrien DESCRIPTION 52319370Spst 52498944Sobrien DWARF version 1 doesn't supply any fundamental type information, 52598944Sobrien so gdb has to construct such types. It has a fixed number of 52698944Sobrien fundamental types that it knows how to construct, which is the 52798944Sobrien union of all types that it knows how to construct for all languages 52898944Sobrien that it knows about. These are enumerated in gdbtypes.h. 52919370Spst 53098944Sobrien As an example, assume we find a DIE that references a DWARF 53198944Sobrien fundamental type of FT_integer. We first look in the ftypes 53298944Sobrien array to see if we already have such a type, indexed by the 53398944Sobrien gdb internal value of FT_INTEGER. If so, we simply return a 53498944Sobrien pointer to that type. If not, then we ask an appropriate 53598944Sobrien language dependent routine to create a type FT_INTEGER, using 53698944Sobrien defaults reasonable for the current target machine, and install 53798944Sobrien that type in ftypes for future reference. 53819370Spst 53998944Sobrien RETURNS 54019370Spst 54198944Sobrien Pointer to a fundamental type. 54219370Spst 54398944Sobrien */ 54419370Spst 54519370Spststatic struct type * 54698944Sobriendwarf_fundamental_type (struct objfile *objfile, int typeid) 54719370Spst{ 54819370Spst if (typeid < 0 || typeid >= FT_NUM_MEMBERS) 54919370Spst { 55019370Spst error ("internal error - invalid fundamental type id %d", typeid); 55119370Spst } 55219370Spst 55319370Spst /* Look for this particular type in the fundamental type vector. If one is 55419370Spst not found, create and install one appropriate for the current language 55519370Spst and the current target machine. */ 55619370Spst 55719370Spst if (ftypes[typeid] == NULL) 55819370Spst { 55998944Sobrien ftypes[typeid] = cu_language_defn->la_fund_type (objfile, typeid); 56019370Spst } 56119370Spst 56219370Spst return (ftypes[typeid]); 56319370Spst} 56419370Spst 56519370Spst/* 56619370Spst 56798944Sobrien LOCAL FUNCTION 56819370Spst 56998944Sobrien set_cu_language -- set local copy of language for compilation unit 57019370Spst 57198944Sobrien SYNOPSIS 57219370Spst 57398944Sobrien void 57498944Sobrien set_cu_language (struct dieinfo *dip) 57519370Spst 57698944Sobrien DESCRIPTION 57719370Spst 57898944Sobrien Decode the language attribute for a compilation unit DIE and 57998944Sobrien remember what the language was. We use this at various times 58098944Sobrien when processing DIE's for a given compilation unit. 58119370Spst 58298944Sobrien RETURNS 58319370Spst 58498944Sobrien No return value. 58519370Spst 58619370Spst */ 58719370Spst 58819370Spststatic void 58998944Sobrienset_cu_language (struct dieinfo *dip) 59019370Spst{ 59198944Sobrien switch (dip->at_language) 59219370Spst { 59398944Sobrien case LANG_C89: 59498944Sobrien case LANG_C: 59598944Sobrien cu_language = language_c; 59698944Sobrien break; 59798944Sobrien case LANG_C_PLUS_PLUS: 59898944Sobrien cu_language = language_cplus; 59998944Sobrien break; 60098944Sobrien case LANG_MODULA2: 60198944Sobrien cu_language = language_m2; 60298944Sobrien break; 60398944Sobrien case LANG_FORTRAN77: 60498944Sobrien case LANG_FORTRAN90: 60598944Sobrien cu_language = language_fortran; 60698944Sobrien break; 60798944Sobrien case LANG_ADA83: 60898944Sobrien case LANG_COBOL74: 60998944Sobrien case LANG_COBOL85: 61098944Sobrien case LANG_PASCAL83: 61198944Sobrien /* We don't know anything special about these yet. */ 61298944Sobrien cu_language = language_unknown; 61398944Sobrien break; 61498944Sobrien default: 61598944Sobrien /* If no at_language, try to deduce one from the filename */ 61698944Sobrien cu_language = deduce_language_from_filename (dip->at_name); 61798944Sobrien break; 61819370Spst } 61919370Spst cu_language_defn = language_def (cu_language); 62019370Spst} 62119370Spst 62219370Spst/* 62319370Spst 62498944Sobrien GLOBAL FUNCTION 62519370Spst 62698944Sobrien dwarf_build_psymtabs -- build partial symtabs from DWARF debug info 62719370Spst 62898944Sobrien SYNOPSIS 62919370Spst 63098944Sobrien void dwarf_build_psymtabs (struct objfile *objfile, 63198944Sobrien int mainline, file_ptr dbfoff, unsigned int dbfsize, 63298944Sobrien file_ptr lnoffset, unsigned int lnsize) 63319370Spst 63498944Sobrien DESCRIPTION 63519370Spst 63698944Sobrien This function is called upon to build partial symtabs from files 63798944Sobrien containing DIE's (Dwarf Information Entries) and DWARF line numbers. 63819370Spst 63998944Sobrien It is passed a bfd* containing the DIES 64098944Sobrien and line number information, the corresponding filename for that 64198944Sobrien file, a base address for relocating the symbols, a flag indicating 64298944Sobrien whether or not this debugging information is from a "main symbol 64398944Sobrien table" rather than a shared library or dynamically linked file, 64498944Sobrien and file offset/size pairs for the DIE information and line number 64598944Sobrien information. 64619370Spst 64798944Sobrien RETURNS 64819370Spst 64998944Sobrien No return value. 65019370Spst 65119370Spst */ 65219370Spst 65319370Spstvoid 65498944Sobriendwarf_build_psymtabs (struct objfile *objfile, int mainline, file_ptr dbfoff, 65598944Sobrien unsigned int dbfsize, file_ptr lnoffset, 65698944Sobrien unsigned int lnsize) 65719370Spst{ 65819370Spst bfd *abfd = objfile->obfd; 65919370Spst struct cleanup *back_to; 66098944Sobrien 66119370Spst current_objfile = objfile; 66219370Spst dbsize = dbfsize; 66319370Spst dbbase = xmalloc (dbsize); 66419370Spst dbroff = 0; 66519370Spst if ((bfd_seek (abfd, dbfoff, SEEK_SET) != 0) || 66698944Sobrien (bfd_bread (dbbase, dbsize, abfd) != dbsize)) 66719370Spst { 66898944Sobrien xfree (dbbase); 66919370Spst error ("can't read DWARF data from '%s'", bfd_get_filename (abfd)); 67019370Spst } 67198944Sobrien back_to = make_cleanup (xfree, dbbase); 67298944Sobrien 67319370Spst /* If we are reinitializing, or if we have never loaded syms yet, init. 67419370Spst Since we have no idea how many DIES we are looking at, we just guess 67519370Spst some arbitrary value. */ 67698944Sobrien 67798944Sobrien if (mainline 67898944Sobrien || (objfile->global_psymbols.size == 0 67998944Sobrien && objfile->static_psymbols.size == 0)) 68019370Spst { 68119370Spst init_psymbol_list (objfile, 1024); 68219370Spst } 68398944Sobrien 68419370Spst /* Save the relocation factor where everybody can see it. */ 68519370Spst 68698944Sobrien base_section_offsets = objfile->section_offsets; 68798944Sobrien baseaddr = ANOFFSET (objfile->section_offsets, 0); 68819370Spst 68919370Spst /* Follow the compilation unit sibling chain, building a partial symbol 69019370Spst table entry for each one. Save enough information about each compilation 69119370Spst unit to locate the full DWARF information later. */ 69298944Sobrien 69319370Spst scan_compilation_units (dbbase, dbbase + dbsize, dbfoff, lnoffset, objfile); 69498944Sobrien 69519370Spst do_cleanups (back_to); 69619370Spst current_objfile = NULL; 69719370Spst} 69819370Spst 69919370Spst/* 70019370Spst 70198944Sobrien LOCAL FUNCTION 70219370Spst 70398944Sobrien read_lexical_block_scope -- process all dies in a lexical block 70419370Spst 70598944Sobrien SYNOPSIS 70619370Spst 70798944Sobrien static void read_lexical_block_scope (struct dieinfo *dip, 70898944Sobrien char *thisdie, char *enddie) 70919370Spst 71098944Sobrien DESCRIPTION 71119370Spst 71298944Sobrien Process all the DIES contained within a lexical block scope. 71398944Sobrien Start a new scope, process the dies, and then close the scope. 71419370Spst 71519370Spst */ 71619370Spst 71719370Spststatic void 71898944Sobrienread_lexical_block_scope (struct dieinfo *dip, char *thisdie, char *enddie, 71998944Sobrien struct objfile *objfile) 72019370Spst{ 721130803Smarcel struct context_stack *new; 72219370Spst 72398944Sobrien push_context (0, dip->at_low_pc); 72498944Sobrien process_dies (thisdie + dip->die_length, enddie, objfile); 72519370Spst new = pop_context (); 72619370Spst if (local_symbols != NULL) 72719370Spst { 72898944Sobrien finish_block (0, &local_symbols, new->old_blocks, new->start_addr, 72998944Sobrien dip->at_high_pc, objfile); 73019370Spst } 73198944Sobrien local_symbols = new->locals; 73219370Spst} 73319370Spst 73419370Spst/* 73519370Spst 73698944Sobrien LOCAL FUNCTION 73719370Spst 73898944Sobrien lookup_utype -- look up a user defined type from die reference 73919370Spst 74098944Sobrien SYNOPSIS 74119370Spst 74298944Sobrien static type *lookup_utype (DIE_REF die_ref) 74319370Spst 74498944Sobrien DESCRIPTION 74519370Spst 74698944Sobrien Given a DIE reference, lookup the user defined type associated with 74798944Sobrien that DIE, if it has been registered already. If not registered, then 74898944Sobrien return NULL. Alloc_utype() can be called to register an empty 74998944Sobrien type for this reference, which will be filled in later when the 75098944Sobrien actual referenced DIE is processed. 75119370Spst */ 75219370Spst 75319370Spststatic struct type * 75498944Sobrienlookup_utype (DIE_REF die_ref) 75519370Spst{ 75619370Spst struct type *type = NULL; 75719370Spst int utypeidx; 75898944Sobrien 75919370Spst utypeidx = (die_ref - dbroff) / 4; 76019370Spst if ((utypeidx < 0) || (utypeidx >= numutypes)) 76119370Spst { 762130803Smarcel bad_die_ref_complaint (DIE_ID, DIE_NAME, die_ref); 76319370Spst } 76419370Spst else 76519370Spst { 76619370Spst type = *(utypes + utypeidx); 76719370Spst } 76819370Spst return (type); 76919370Spst} 77019370Spst 77119370Spst 77219370Spst/* 77319370Spst 77498944Sobrien LOCAL FUNCTION 77519370Spst 77698944Sobrien alloc_utype -- add a user defined type for die reference 77719370Spst 77898944Sobrien SYNOPSIS 77919370Spst 78098944Sobrien static type *alloc_utype (DIE_REF die_ref, struct type *utypep) 78119370Spst 78298944Sobrien DESCRIPTION 78319370Spst 78498944Sobrien Given a die reference DIE_REF, and a possible pointer to a user 78598944Sobrien defined type UTYPEP, register that this reference has a user 78698944Sobrien defined type and either use the specified type in UTYPEP or 78798944Sobrien make a new empty type that will be filled in later. 78819370Spst 78998944Sobrien We should only be called after calling lookup_utype() to verify that 79098944Sobrien there is not currently a type registered for DIE_REF. 79119370Spst */ 79219370Spst 79319370Spststatic struct type * 79498944Sobrienalloc_utype (DIE_REF die_ref, struct type *utypep) 79519370Spst{ 79619370Spst struct type **typep; 79719370Spst int utypeidx; 79898944Sobrien 79919370Spst utypeidx = (die_ref - dbroff) / 4; 80019370Spst typep = utypes + utypeidx; 80119370Spst if ((utypeidx < 0) || (utypeidx >= numutypes)) 80219370Spst { 80319370Spst utypep = dwarf_fundamental_type (current_objfile, FT_INTEGER); 804130803Smarcel bad_die_ref_complaint (DIE_ID, DIE_NAME, die_ref); 80519370Spst } 80619370Spst else if (*typep != NULL) 80719370Spst { 80819370Spst utypep = *typep; 809130803Smarcel complaint (&symfile_complaints, 810130803Smarcel "DIE @ 0x%x \"%s\", internal error: duplicate user type allocation", 811130803Smarcel DIE_ID, DIE_NAME); 81219370Spst } 81319370Spst else 81419370Spst { 81519370Spst if (utypep == NULL) 81619370Spst { 81719370Spst utypep = alloc_type (current_objfile); 81819370Spst } 81919370Spst *typep = utypep; 82019370Spst } 82119370Spst return (utypep); 82219370Spst} 82319370Spst 82419370Spst/* 82519370Spst 82698944Sobrien LOCAL FUNCTION 82719370Spst 82898944Sobrien free_utypes -- free the utypes array and reset pointer & count 82919370Spst 83098944Sobrien SYNOPSIS 83119370Spst 832130803Smarcel static void free_utypes (void *dummy) 83319370Spst 83498944Sobrien DESCRIPTION 83519370Spst 83698944Sobrien Called via do_cleanups to free the utypes array, reset the pointer to NULL, 83798944Sobrien and set numutypes back to zero. This ensures that the utypes does not get 83898944Sobrien referenced after being freed. 83919370Spst */ 84019370Spst 84119370Spststatic void 842130803Smarcelfree_utypes (void *dummy) 84319370Spst{ 84498944Sobrien xfree (utypes); 84519370Spst utypes = NULL; 84619370Spst numutypes = 0; 84719370Spst} 84819370Spst 84919370Spst 85019370Spst/* 85119370Spst 85298944Sobrien LOCAL FUNCTION 85319370Spst 85498944Sobrien decode_die_type -- return a type for a specified die 85519370Spst 85698944Sobrien SYNOPSIS 85719370Spst 85898944Sobrien static struct type *decode_die_type (struct dieinfo *dip) 85919370Spst 86098944Sobrien DESCRIPTION 86119370Spst 86298944Sobrien Given a pointer to a die information structure DIP, decode the 86398944Sobrien type of the die and return a pointer to the decoded type. All 86498944Sobrien dies without specific types default to type int. 86519370Spst */ 86619370Spst 86719370Spststatic struct type * 86898944Sobriendecode_die_type (struct dieinfo *dip) 86919370Spst{ 87019370Spst struct type *type = NULL; 87198944Sobrien 87298944Sobrien if (dip->at_fund_type != 0) 87319370Spst { 87498944Sobrien type = decode_fund_type (dip->at_fund_type); 87519370Spst } 87698944Sobrien else if (dip->at_mod_fund_type != NULL) 87719370Spst { 87898944Sobrien type = decode_mod_fund_type (dip->at_mod_fund_type); 87919370Spst } 88098944Sobrien else if (dip->at_user_def_type) 88119370Spst { 882130803Smarcel type = lookup_utype (dip->at_user_def_type); 883130803Smarcel if (type == NULL) 88419370Spst { 88598944Sobrien type = alloc_utype (dip->at_user_def_type, NULL); 88619370Spst } 88719370Spst } 88898944Sobrien else if (dip->at_mod_u_d_type) 88919370Spst { 89098944Sobrien type = decode_mod_u_d_type (dip->at_mod_u_d_type); 89119370Spst } 89219370Spst else 89319370Spst { 89446283Sdfr type = dwarf_fundamental_type (current_objfile, FT_VOID); 89519370Spst } 89619370Spst return (type); 89719370Spst} 89819370Spst 89919370Spst/* 90019370Spst 90198944Sobrien LOCAL FUNCTION 90219370Spst 90398944Sobrien struct_type -- compute and return the type for a struct or union 90419370Spst 90598944Sobrien SYNOPSIS 90619370Spst 90798944Sobrien static struct type *struct_type (struct dieinfo *dip, char *thisdie, 90898944Sobrien char *enddie, struct objfile *objfile) 90919370Spst 91098944Sobrien DESCRIPTION 91119370Spst 91298944Sobrien Given pointer to a die information structure for a die which 91398944Sobrien defines a union or structure (and MUST define one or the other), 91498944Sobrien and pointers to the raw die data that define the range of dies which 91598944Sobrien define the members, compute and return the user defined type for the 91698944Sobrien structure or union. 91719370Spst */ 91819370Spst 91919370Spststatic struct type * 92098944Sobrienstruct_type (struct dieinfo *dip, char *thisdie, char *enddie, 92198944Sobrien struct objfile *objfile) 92219370Spst{ 92319370Spst struct type *type; 92498944Sobrien struct nextfield 92598944Sobrien { 92698944Sobrien struct nextfield *next; 92798944Sobrien struct field field; 92898944Sobrien }; 92919370Spst struct nextfield *list = NULL; 93019370Spst struct nextfield *new; 93119370Spst int nfields = 0; 93219370Spst int n; 93319370Spst struct dieinfo mbr; 93419370Spst char *nextdie; 93519370Spst int anonymous_size; 93698944Sobrien 937130803Smarcel type = lookup_utype (dip->die_ref); 938130803Smarcel if (type == NULL) 93919370Spst { 94019370Spst /* No forward references created an empty type, so install one now */ 94198944Sobrien type = alloc_utype (dip->die_ref, NULL); 94219370Spst } 94398944Sobrien INIT_CPLUS_SPECIFIC (type); 94498944Sobrien switch (dip->die_tag) 94519370Spst { 94698944Sobrien case TAG_class_type: 94798944Sobrien TYPE_CODE (type) = TYPE_CODE_CLASS; 94898944Sobrien break; 94998944Sobrien case TAG_structure_type: 95098944Sobrien TYPE_CODE (type) = TYPE_CODE_STRUCT; 95198944Sobrien break; 95298944Sobrien case TAG_union_type: 95398944Sobrien TYPE_CODE (type) = TYPE_CODE_UNION; 95498944Sobrien break; 95598944Sobrien default: 95698944Sobrien /* Should never happen */ 95798944Sobrien TYPE_CODE (type) = TYPE_CODE_UNDEF; 958130803Smarcel complaint (&symfile_complaints, 959130803Smarcel "DIE @ 0x%x \"%s\", missing class, structure, or union tag", 960130803Smarcel DIE_ID, DIE_NAME); 96198944Sobrien break; 96219370Spst } 96319370Spst /* Some compilers try to be helpful by inventing "fake" names for 96419370Spst anonymous enums, structures, and unions, like "~0fake" or ".0fake". 96519370Spst Thanks, but no thanks... */ 96698944Sobrien if (dip->at_name != NULL 96798944Sobrien && *dip->at_name != '~' 96898944Sobrien && *dip->at_name != '.') 96919370Spst { 970130803Smarcel TYPE_TAG_NAME (type) = obconcat (&objfile->objfile_obstack, 97198944Sobrien "", "", dip->at_name); 97219370Spst } 97319370Spst /* Use whatever size is known. Zero is a valid size. We might however 97419370Spst wish to check has_at_byte_size to make sure that some byte size was 97519370Spst given explicitly, but DWARF doesn't specify that explicit sizes of 97619370Spst zero have to present, so complaining about missing sizes should 97719370Spst probably not be the default. */ 97898944Sobrien TYPE_LENGTH (type) = dip->at_byte_size; 97998944Sobrien thisdie += dip->die_length; 98019370Spst while (thisdie < enddie) 98119370Spst { 98219370Spst basicdieinfo (&mbr, thisdie, objfile); 98319370Spst completedieinfo (&mbr, objfile); 98419370Spst if (mbr.die_length <= SIZEOF_DIE_LENGTH) 98519370Spst { 98619370Spst break; 98719370Spst } 98819370Spst else if (mbr.at_sibling != 0) 98919370Spst { 99019370Spst nextdie = dbbase + mbr.at_sibling - dbroff; 99119370Spst } 99219370Spst else 99319370Spst { 99419370Spst nextdie = thisdie + mbr.die_length; 99519370Spst } 99619370Spst switch (mbr.die_tag) 99719370Spst { 99819370Spst case TAG_member: 999130803Smarcel /* Static fields can be either TAG_global_variable (GCC) or else 1000130803Smarcel TAG_member with no location (Diab). We could treat the latter like 1001130803Smarcel the former... but since we don't support the former, just avoid 1002130803Smarcel crashing on the latter for now. */ 1003130803Smarcel if (mbr.at_location == NULL) 1004130803Smarcel break; 1005130803Smarcel 100619370Spst /* Get space to record the next field's data. */ 100719370Spst new = (struct nextfield *) alloca (sizeof (struct nextfield)); 100898944Sobrien new->next = list; 100919370Spst list = new; 101019370Spst /* Save the data. */ 101198944Sobrien list->field.name = 101298944Sobrien obsavestring (mbr.at_name, strlen (mbr.at_name), 1013130803Smarcel &objfile->objfile_obstack); 101446283Sdfr FIELD_TYPE (list->field) = decode_die_type (&mbr); 101546283Sdfr FIELD_BITPOS (list->field) = 8 * locval (&mbr); 1016130803Smarcel FIELD_STATIC_KIND (list->field) = 0; 101719370Spst /* Handle bit fields. */ 101846283Sdfr FIELD_BITSIZE (list->field) = mbr.at_bit_size; 101919370Spst if (BITS_BIG_ENDIAN) 102019370Spst { 102119370Spst /* For big endian bits, the at_bit_offset gives the 102298944Sobrien additional bit offset from the MSB of the containing 102398944Sobrien anonymous object to the MSB of the field. We don't 102498944Sobrien have to do anything special since we don't need to 102598944Sobrien know the size of the anonymous object. */ 102646283Sdfr FIELD_BITPOS (list->field) += mbr.at_bit_offset; 102719370Spst } 102819370Spst else 102919370Spst { 103019370Spst /* For little endian bits, we need to have a non-zero 103198944Sobrien at_bit_size, so that we know we are in fact dealing 103298944Sobrien with a bitfield. Compute the bit offset to the MSB 103398944Sobrien of the anonymous object, subtract off the number of 103498944Sobrien bits from the MSB of the field to the MSB of the 103598944Sobrien object, and then subtract off the number of bits of 103698944Sobrien the field itself. The result is the bit offset of 103798944Sobrien the LSB of the field. */ 103819370Spst if (mbr.at_bit_size > 0) 103919370Spst { 104019370Spst if (mbr.has_at_byte_size) 104119370Spst { 104219370Spst /* The size of the anonymous object containing 104398944Sobrien the bit field is explicit, so use the 104498944Sobrien indicated size (in bytes). */ 104519370Spst anonymous_size = mbr.at_byte_size; 104619370Spst } 104719370Spst else 104819370Spst { 104919370Spst /* The size of the anonymous object containing 105098944Sobrien the bit field matches the size of an object 105198944Sobrien of the bit field's type. DWARF allows 105298944Sobrien at_byte_size to be left out in such cases, as 105398944Sobrien a debug information size optimization. */ 105498944Sobrien anonymous_size = TYPE_LENGTH (list->field.type); 105519370Spst } 105646283Sdfr FIELD_BITPOS (list->field) += 105719370Spst anonymous_size * 8 - mbr.at_bit_offset - mbr.at_bit_size; 105819370Spst } 105919370Spst } 106019370Spst nfields++; 106119370Spst break; 106219370Spst default: 106319370Spst process_dies (thisdie, nextdie, objfile); 106419370Spst break; 106519370Spst } 106619370Spst thisdie = nextdie; 106719370Spst } 106819370Spst /* Now create the vector of fields, and record how big it is. We may 106919370Spst not even have any fields, if this DIE was generated due to a reference 107019370Spst to an anonymous structure or union. In this case, TYPE_FLAG_STUB is 107119370Spst set, which clues gdb in to the fact that it needs to search elsewhere 107219370Spst for the full structure definition. */ 107319370Spst if (nfields == 0) 107419370Spst { 107519370Spst TYPE_FLAGS (type) |= TYPE_FLAG_STUB; 107619370Spst } 107719370Spst else 107819370Spst { 107919370Spst TYPE_NFIELDS (type) = nfields; 108019370Spst TYPE_FIELDS (type) = (struct field *) 108119370Spst TYPE_ALLOC (type, sizeof (struct field) * nfields); 108219370Spst /* Copy the saved-up fields into the field vector. */ 108398944Sobrien for (n = nfields; list; list = list->next) 108419370Spst { 108598944Sobrien TYPE_FIELD (type, --n) = list->field; 108698944Sobrien } 108719370Spst } 108819370Spst return (type); 108919370Spst} 109019370Spst 109119370Spst/* 109219370Spst 109398944Sobrien LOCAL FUNCTION 109419370Spst 109598944Sobrien read_structure_scope -- process all dies within struct or union 109619370Spst 109798944Sobrien SYNOPSIS 109819370Spst 109998944Sobrien static void read_structure_scope (struct dieinfo *dip, 110098944Sobrien char *thisdie, char *enddie, struct objfile *objfile) 110119370Spst 110298944Sobrien DESCRIPTION 110319370Spst 110498944Sobrien Called when we find the DIE that starts a structure or union 110598944Sobrien scope (definition) to process all dies that define the members 110698944Sobrien of the structure or union. DIP is a pointer to the die info 110798944Sobrien struct for the DIE that names the structure or union. 110819370Spst 110998944Sobrien NOTES 111019370Spst 111198944Sobrien Note that we need to call struct_type regardless of whether or not 111298944Sobrien the DIE has an at_name attribute, since it might be an anonymous 111398944Sobrien structure or union. This gets the type entered into our set of 111498944Sobrien user defined types. 111519370Spst 111698944Sobrien However, if the structure is incomplete (an opaque struct/union) 111798944Sobrien then suppress creating a symbol table entry for it since gdb only 111898944Sobrien wants to find the one with the complete definition. Note that if 111998944Sobrien it is complete, we just call new_symbol, which does it's own 112098944Sobrien checking about whether the struct/union is anonymous or not (and 112198944Sobrien suppresses creating a symbol table entry itself). 112298944Sobrien 112319370Spst */ 112419370Spst 112519370Spststatic void 112698944Sobrienread_structure_scope (struct dieinfo *dip, char *thisdie, char *enddie, 112798944Sobrien struct objfile *objfile) 112819370Spst{ 112919370Spst struct type *type; 113019370Spst struct symbol *sym; 113198944Sobrien 113219370Spst type = struct_type (dip, thisdie, enddie, objfile); 113398944Sobrien if (!TYPE_STUB (type)) 113419370Spst { 113519370Spst sym = new_symbol (dip, objfile); 113619370Spst if (sym != NULL) 113719370Spst { 113819370Spst SYMBOL_TYPE (sym) = type; 113919370Spst if (cu_language == language_cplus) 114019370Spst { 114119370Spst synthesize_typedef (dip, objfile, type); 114219370Spst } 114319370Spst } 114419370Spst } 114519370Spst} 114619370Spst 114719370Spst/* 114819370Spst 114998944Sobrien LOCAL FUNCTION 115019370Spst 115198944Sobrien decode_array_element_type -- decode type of the array elements 115219370Spst 115398944Sobrien SYNOPSIS 115419370Spst 115598944Sobrien static struct type *decode_array_element_type (char *scan, char *end) 115619370Spst 115798944Sobrien DESCRIPTION 115819370Spst 115998944Sobrien As the last step in decoding the array subscript information for an 116098944Sobrien array DIE, we need to decode the type of the array elements. We are 116198944Sobrien passed a pointer to this last part of the subscript information and 116298944Sobrien must return the appropriate type. If the type attribute is not 116398944Sobrien recognized, just warn about the problem and return type int. 116419370Spst */ 116519370Spst 116619370Spststatic struct type * 116798944Sobriendecode_array_element_type (char *scan) 116819370Spst{ 116919370Spst struct type *typep; 117019370Spst DIE_REF die_ref; 117119370Spst unsigned short attribute; 117219370Spst unsigned short fundtype; 117319370Spst int nbytes; 117498944Sobrien 117519370Spst attribute = target_to_host (scan, SIZEOF_ATTRIBUTE, GET_UNSIGNED, 117619370Spst current_objfile); 117719370Spst scan += SIZEOF_ATTRIBUTE; 1178130803Smarcel nbytes = attribute_size (attribute); 1179130803Smarcel if (nbytes == -1) 118019370Spst { 1181130803Smarcel bad_array_element_type_complaint (DIE_ID, DIE_NAME, attribute); 118219370Spst typep = dwarf_fundamental_type (current_objfile, FT_INTEGER); 118319370Spst } 118419370Spst else 118519370Spst { 118619370Spst switch (attribute) 118719370Spst { 118898944Sobrien case AT_fund_type: 118998944Sobrien fundtype = target_to_host (scan, nbytes, GET_UNSIGNED, 119098944Sobrien current_objfile); 119198944Sobrien typep = decode_fund_type (fundtype); 119298944Sobrien break; 119398944Sobrien case AT_mod_fund_type: 119498944Sobrien typep = decode_mod_fund_type (scan); 119598944Sobrien break; 119698944Sobrien case AT_user_def_type: 119798944Sobrien die_ref = target_to_host (scan, nbytes, GET_UNSIGNED, 119898944Sobrien current_objfile); 1199130803Smarcel typep = lookup_utype (die_ref); 1200130803Smarcel if (typep == NULL) 120198944Sobrien { 120298944Sobrien typep = alloc_utype (die_ref, NULL); 120398944Sobrien } 120498944Sobrien break; 120598944Sobrien case AT_mod_u_d_type: 120698944Sobrien typep = decode_mod_u_d_type (scan); 120798944Sobrien break; 120898944Sobrien default: 1209130803Smarcel bad_array_element_type_complaint (DIE_ID, DIE_NAME, attribute); 121098944Sobrien typep = dwarf_fundamental_type (current_objfile, FT_INTEGER); 121198944Sobrien break; 121298944Sobrien } 121319370Spst } 121419370Spst return (typep); 121519370Spst} 121619370Spst 121719370Spst/* 121819370Spst 121998944Sobrien LOCAL FUNCTION 122019370Spst 122198944Sobrien decode_subscript_data_item -- decode array subscript item 122219370Spst 122398944Sobrien SYNOPSIS 122419370Spst 122598944Sobrien static struct type * 122698944Sobrien decode_subscript_data_item (char *scan, char *end) 122719370Spst 122898944Sobrien DESCRIPTION 122919370Spst 123098944Sobrien The array subscripts and the data type of the elements of an 123198944Sobrien array are described by a list of data items, stored as a block 123298944Sobrien of contiguous bytes. There is a data item describing each array 123398944Sobrien dimension, and a final data item describing the element type. 123498944Sobrien The data items are ordered the same as their appearance in the 123598944Sobrien source (I.E. leftmost dimension first, next to leftmost second, 123698944Sobrien etc). 123719370Spst 123898944Sobrien The data items describing each array dimension consist of four 123998944Sobrien parts: (1) a format specifier, (2) type type of the subscript 124098944Sobrien index, (3) a description of the low bound of the array dimension, 124198944Sobrien and (4) a description of the high bound of the array dimension. 124219370Spst 124398944Sobrien The last data item is the description of the type of each of 124498944Sobrien the array elements. 124519370Spst 124698944Sobrien We are passed a pointer to the start of the block of bytes 124798944Sobrien containing the remaining data items, and a pointer to the first 124898944Sobrien byte past the data. This function recursively decodes the 124998944Sobrien remaining data items and returns a type. 125019370Spst 125198944Sobrien If we somehow fail to decode some data, we complain about it 125298944Sobrien and return a type "array of int". 125319370Spst 125498944Sobrien BUGS 125598944Sobrien FIXME: This code only implements the forms currently used 125698944Sobrien by the AT&T and GNU C compilers. 125719370Spst 125898944Sobrien The end pointer is supplied for error checking, maybe we should 125998944Sobrien use it for that... 126019370Spst */ 126119370Spst 126219370Spststatic struct type * 126398944Sobriendecode_subscript_data_item (char *scan, char *end) 126419370Spst{ 126519370Spst struct type *typep = NULL; /* Array type we are building */ 126619370Spst struct type *nexttype; /* Type of each element (may be array) */ 126719370Spst struct type *indextype; /* Type of this index */ 126819370Spst struct type *rangetype; 126919370Spst unsigned int format; 127019370Spst unsigned short fundtype; 127119370Spst unsigned long lowbound; 127219370Spst unsigned long highbound; 127319370Spst int nbytes; 127498944Sobrien 127519370Spst format = target_to_host (scan, SIZEOF_FORMAT_SPECIFIER, GET_UNSIGNED, 127619370Spst current_objfile); 127719370Spst scan += SIZEOF_FORMAT_SPECIFIER; 127819370Spst switch (format) 127919370Spst { 128019370Spst case FMT_ET: 128119370Spst typep = decode_array_element_type (scan); 128219370Spst break; 128319370Spst case FMT_FT_C_C: 128419370Spst fundtype = target_to_host (scan, SIZEOF_FMT_FT, GET_UNSIGNED, 128519370Spst current_objfile); 128619370Spst indextype = decode_fund_type (fundtype); 128719370Spst scan += SIZEOF_FMT_FT; 128819370Spst nbytes = TARGET_FT_LONG_SIZE (current_objfile); 128919370Spst lowbound = target_to_host (scan, nbytes, GET_UNSIGNED, current_objfile); 129019370Spst scan += nbytes; 129119370Spst highbound = target_to_host (scan, nbytes, GET_UNSIGNED, current_objfile); 129219370Spst scan += nbytes; 129319370Spst nexttype = decode_subscript_data_item (scan, end); 129419370Spst if (nexttype == NULL) 129519370Spst { 129619370Spst /* Munged subscript data or other problem, fake it. */ 1297130803Smarcel complaint (&symfile_complaints, 1298130803Smarcel "DIE @ 0x%x \"%s\", can't decode subscript data items", 1299130803Smarcel DIE_ID, DIE_NAME); 130019370Spst nexttype = dwarf_fundamental_type (current_objfile, FT_INTEGER); 130119370Spst } 130219370Spst rangetype = create_range_type ((struct type *) NULL, indextype, 130398944Sobrien lowbound, highbound); 130419370Spst typep = create_array_type ((struct type *) NULL, nexttype, rangetype); 130519370Spst break; 130619370Spst case FMT_FT_C_X: 130719370Spst case FMT_FT_X_C: 130819370Spst case FMT_FT_X_X: 130919370Spst case FMT_UT_C_C: 131019370Spst case FMT_UT_C_X: 131119370Spst case FMT_UT_X_C: 131219370Spst case FMT_UT_X_X: 1313130803Smarcel complaint (&symfile_complaints, 1314130803Smarcel "DIE @ 0x%x \"%s\", array subscript format 0x%x not handled yet", 1315130803Smarcel DIE_ID, DIE_NAME, format); 131619370Spst nexttype = dwarf_fundamental_type (current_objfile, FT_INTEGER); 131719370Spst rangetype = create_range_type ((struct type *) NULL, nexttype, 0, 0); 131819370Spst typep = create_array_type ((struct type *) NULL, nexttype, rangetype); 131919370Spst break; 132019370Spst default: 1321130803Smarcel complaint (&symfile_complaints, 1322130803Smarcel "DIE @ 0x%x \"%s\", unknown array subscript format %x", DIE_ID, 1323130803Smarcel DIE_NAME, format); 132419370Spst nexttype = dwarf_fundamental_type (current_objfile, FT_INTEGER); 132519370Spst rangetype = create_range_type ((struct type *) NULL, nexttype, 0, 0); 132619370Spst typep = create_array_type ((struct type *) NULL, nexttype, rangetype); 132719370Spst break; 132819370Spst } 132919370Spst return (typep); 133019370Spst} 133119370Spst 133219370Spst/* 133319370Spst 133498944Sobrien LOCAL FUNCTION 133519370Spst 133698944Sobrien dwarf_read_array_type -- read TAG_array_type DIE 133719370Spst 133898944Sobrien SYNOPSIS 133919370Spst 134098944Sobrien static void dwarf_read_array_type (struct dieinfo *dip) 134119370Spst 134298944Sobrien DESCRIPTION 134319370Spst 134498944Sobrien Extract all information from a TAG_array_type DIE and add to 134598944Sobrien the user defined type vector. 134619370Spst */ 134719370Spst 134819370Spststatic void 134998944Sobriendwarf_read_array_type (struct dieinfo *dip) 135019370Spst{ 135119370Spst struct type *type; 135219370Spst struct type *utype; 135319370Spst char *sub; 135419370Spst char *subend; 135519370Spst unsigned short blocksz; 135619370Spst int nbytes; 135798944Sobrien 135898944Sobrien if (dip->at_ordering != ORD_row_major) 135919370Spst { 136019370Spst /* FIXME: Can gdb even handle column major arrays? */ 1361130803Smarcel complaint (&symfile_complaints, 1362130803Smarcel "DIE @ 0x%x \"%s\", array not row major; not handled correctly", 1363130803Smarcel DIE_ID, DIE_NAME); 136419370Spst } 1365130803Smarcel sub = dip->at_subscr_data; 1366130803Smarcel if (sub != NULL) 136719370Spst { 136819370Spst nbytes = attribute_size (AT_subscr_data); 136919370Spst blocksz = target_to_host (sub, nbytes, GET_UNSIGNED, current_objfile); 137019370Spst subend = sub + nbytes + blocksz; 137119370Spst sub += nbytes; 137219370Spst type = decode_subscript_data_item (sub, subend); 1373130803Smarcel utype = lookup_utype (dip->die_ref); 1374130803Smarcel if (utype == NULL) 137519370Spst { 137619370Spst /* Install user defined type that has not been referenced yet. */ 137798944Sobrien alloc_utype (dip->die_ref, type); 137819370Spst } 137919370Spst else if (TYPE_CODE (utype) == TYPE_CODE_UNDEF) 138019370Spst { 138119370Spst /* Ick! A forward ref has already generated a blank type in our 138219370Spst slot, and this type probably already has things pointing to it 138319370Spst (which is what caused it to be created in the first place). 138419370Spst If it's just a place holder we can plop our fully defined type 138519370Spst on top of it. We can't recover the space allocated for our 138619370Spst new type since it might be on an obstack, but we could reuse 138719370Spst it if we kept a list of them, but it might not be worth it 138819370Spst (FIXME). */ 138919370Spst *utype = *type; 139019370Spst } 139119370Spst else 139219370Spst { 139319370Spst /* Double ick! Not only is a type already in our slot, but 139419370Spst someone has decorated it. Complain and leave it alone. */ 1395130803Smarcel dup_user_type_definition_complaint (DIE_ID, DIE_NAME); 139619370Spst } 139719370Spst } 139819370Spst} 139919370Spst 140019370Spst/* 140119370Spst 140298944Sobrien LOCAL FUNCTION 140319370Spst 140498944Sobrien read_tag_pointer_type -- read TAG_pointer_type DIE 140519370Spst 140698944Sobrien SYNOPSIS 140719370Spst 140898944Sobrien static void read_tag_pointer_type (struct dieinfo *dip) 140919370Spst 141098944Sobrien DESCRIPTION 141119370Spst 141298944Sobrien Extract all information from a TAG_pointer_type DIE and add to 141398944Sobrien the user defined type vector. 141419370Spst */ 141519370Spst 141619370Spststatic void 141798944Sobrienread_tag_pointer_type (struct dieinfo *dip) 141819370Spst{ 141919370Spst struct type *type; 142019370Spst struct type *utype; 142198944Sobrien 142219370Spst type = decode_die_type (dip); 1423130803Smarcel utype = lookup_utype (dip->die_ref); 1424130803Smarcel if (utype == NULL) 142519370Spst { 142619370Spst utype = lookup_pointer_type (type); 142798944Sobrien alloc_utype (dip->die_ref, utype); 142819370Spst } 142919370Spst else 143019370Spst { 143119370Spst TYPE_TARGET_TYPE (utype) = type; 143219370Spst TYPE_POINTER_TYPE (type) = utype; 143319370Spst 143419370Spst /* We assume the machine has only one representation for pointers! */ 143546283Sdfr /* FIXME: Possably a poor assumption */ 143698944Sobrien TYPE_LENGTH (utype) = TARGET_PTR_BIT / TARGET_CHAR_BIT; 143719370Spst TYPE_CODE (utype) = TYPE_CODE_PTR; 143819370Spst } 143919370Spst} 144019370Spst 144119370Spst/* 144219370Spst 144398944Sobrien LOCAL FUNCTION 144419370Spst 144598944Sobrien read_tag_string_type -- read TAG_string_type DIE 144619370Spst 144798944Sobrien SYNOPSIS 144819370Spst 144998944Sobrien static void read_tag_string_type (struct dieinfo *dip) 145019370Spst 145198944Sobrien DESCRIPTION 145219370Spst 145398944Sobrien Extract all information from a TAG_string_type DIE and add to 145498944Sobrien the user defined type vector. It isn't really a user defined 145598944Sobrien type, but it behaves like one, with other DIE's using an 145698944Sobrien AT_user_def_type attribute to reference it. 145719370Spst */ 145819370Spst 145919370Spststatic void 146098944Sobrienread_tag_string_type (struct dieinfo *dip) 146119370Spst{ 146219370Spst struct type *utype; 146319370Spst struct type *indextype; 146419370Spst struct type *rangetype; 146519370Spst unsigned long lowbound = 0; 146619370Spst unsigned long highbound; 146719370Spst 146898944Sobrien if (dip->has_at_byte_size) 146919370Spst { 147019370Spst /* A fixed bounds string */ 147198944Sobrien highbound = dip->at_byte_size - 1; 147219370Spst } 147319370Spst else 147419370Spst { 147519370Spst /* A varying length string. Stub for now. (FIXME) */ 147619370Spst highbound = 1; 147719370Spst } 147819370Spst indextype = dwarf_fundamental_type (current_objfile, FT_INTEGER); 147919370Spst rangetype = create_range_type ((struct type *) NULL, indextype, lowbound, 148019370Spst highbound); 148198944Sobrien 148298944Sobrien utype = lookup_utype (dip->die_ref); 148319370Spst if (utype == NULL) 148419370Spst { 148519370Spst /* No type defined, go ahead and create a blank one to use. */ 148698944Sobrien utype = alloc_utype (dip->die_ref, (struct type *) NULL); 148719370Spst } 148819370Spst else 148919370Spst { 149019370Spst /* Already a type in our slot due to a forward reference. Make sure it 149198944Sobrien is a blank one. If not, complain and leave it alone. */ 149219370Spst if (TYPE_CODE (utype) != TYPE_CODE_UNDEF) 149319370Spst { 1494130803Smarcel dup_user_type_definition_complaint (DIE_ID, DIE_NAME); 149519370Spst return; 149619370Spst } 149719370Spst } 149819370Spst 149919370Spst /* Create the string type using the blank type we either found or created. */ 150019370Spst utype = create_string_type (utype, rangetype); 150119370Spst} 150219370Spst 150319370Spst/* 150419370Spst 150598944Sobrien LOCAL FUNCTION 150619370Spst 150798944Sobrien read_subroutine_type -- process TAG_subroutine_type dies 150819370Spst 150998944Sobrien SYNOPSIS 151019370Spst 151198944Sobrien static void read_subroutine_type (struct dieinfo *dip, char thisdie, 151298944Sobrien char *enddie) 151319370Spst 151498944Sobrien DESCRIPTION 151519370Spst 151698944Sobrien Handle DIES due to C code like: 151719370Spst 151898944Sobrien struct foo { 151998944Sobrien int (*funcp)(int a, long l); (Generates TAG_subroutine_type DIE) 152098944Sobrien int b; 152198944Sobrien }; 152219370Spst 152398944Sobrien NOTES 152419370Spst 152598944Sobrien The parameter DIES are currently ignored. See if gdb has a way to 152698944Sobrien include this info in it's type system, and decode them if so. Is 152798944Sobrien this what the type structure's "arg_types" field is for? (FIXME) 152819370Spst */ 152919370Spst 153019370Spststatic void 153198944Sobrienread_subroutine_type (struct dieinfo *dip, char *thisdie, char *enddie) 153219370Spst{ 153319370Spst struct type *type; /* Type that this function returns */ 153419370Spst struct type *ftype; /* Function that returns above type */ 153598944Sobrien 153619370Spst /* Decode the type that this subroutine returns */ 153719370Spst 153819370Spst type = decode_die_type (dip); 153919370Spst 154019370Spst /* Check to see if we already have a partially constructed user 154119370Spst defined type for this DIE, from a forward reference. */ 154219370Spst 1543130803Smarcel ftype = lookup_utype (dip->die_ref); 1544130803Smarcel if (ftype == NULL) 154519370Spst { 154619370Spst /* This is the first reference to one of these types. Make 154798944Sobrien a new one and place it in the user defined types. */ 154819370Spst ftype = lookup_function_type (type); 154998944Sobrien alloc_utype (dip->die_ref, ftype); 155019370Spst } 155119370Spst else if (TYPE_CODE (ftype) == TYPE_CODE_UNDEF) 155219370Spst { 155319370Spst /* We have an existing partially constructed type, so bash it 155498944Sobrien into the correct type. */ 155519370Spst TYPE_TARGET_TYPE (ftype) = type; 155619370Spst TYPE_LENGTH (ftype) = 1; 155719370Spst TYPE_CODE (ftype) = TYPE_CODE_FUNC; 155819370Spst } 155919370Spst else 156019370Spst { 1561130803Smarcel dup_user_type_definition_complaint (DIE_ID, DIE_NAME); 156219370Spst } 156319370Spst} 156419370Spst 156519370Spst/* 156619370Spst 156798944Sobrien LOCAL FUNCTION 156819370Spst 156998944Sobrien read_enumeration -- process dies which define an enumeration 157019370Spst 157198944Sobrien SYNOPSIS 157219370Spst 157398944Sobrien static void read_enumeration (struct dieinfo *dip, char *thisdie, 157498944Sobrien char *enddie, struct objfile *objfile) 157519370Spst 157698944Sobrien DESCRIPTION 157719370Spst 157898944Sobrien Given a pointer to a die which begins an enumeration, process all 157998944Sobrien the dies that define the members of the enumeration. 158019370Spst 158198944Sobrien NOTES 158219370Spst 158398944Sobrien Note that we need to call enum_type regardless of whether or not we 158498944Sobrien have a symbol, since we might have an enum without a tag name (thus 158598944Sobrien no symbol for the tagname). 158619370Spst */ 158719370Spst 158819370Spststatic void 158998944Sobrienread_enumeration (struct dieinfo *dip, char *thisdie, char *enddie, 159098944Sobrien struct objfile *objfile) 159119370Spst{ 159219370Spst struct type *type; 159319370Spst struct symbol *sym; 159498944Sobrien 159519370Spst type = enum_type (dip, objfile); 159619370Spst sym = new_symbol (dip, objfile); 159719370Spst if (sym != NULL) 159819370Spst { 159919370Spst SYMBOL_TYPE (sym) = type; 160019370Spst if (cu_language == language_cplus) 160119370Spst { 160219370Spst synthesize_typedef (dip, objfile, type); 160319370Spst } 160419370Spst } 160519370Spst} 160619370Spst 160719370Spst/* 160819370Spst 160998944Sobrien LOCAL FUNCTION 161019370Spst 161198944Sobrien enum_type -- decode and return a type for an enumeration 161219370Spst 161398944Sobrien SYNOPSIS 161419370Spst 161598944Sobrien static type *enum_type (struct dieinfo *dip, struct objfile *objfile) 161619370Spst 161798944Sobrien DESCRIPTION 161819370Spst 161998944Sobrien Given a pointer to a die information structure for the die which 162098944Sobrien starts an enumeration, process all the dies that define the members 162198944Sobrien of the enumeration and return a type pointer for the enumeration. 162219370Spst 162398944Sobrien At the same time, for each member of the enumeration, create a 1624130803Smarcel symbol for it with domain VAR_DOMAIN and class LOC_CONST, 162598944Sobrien and give it the type of the enumeration itself. 162619370Spst 162798944Sobrien NOTES 162819370Spst 162998944Sobrien Note that the DWARF specification explicitly mandates that enum 163098944Sobrien constants occur in reverse order from the source program order, 163198944Sobrien for "consistency" and because this ordering is easier for many 163298944Sobrien compilers to generate. (Draft 6, sec 3.8.5, Enumeration type 163398944Sobrien Entries). Because gdb wants to see the enum members in program 163498944Sobrien source order, we have to ensure that the order gets reversed while 163598944Sobrien we are processing them. 163619370Spst */ 163719370Spst 163819370Spststatic struct type * 163998944Sobrienenum_type (struct dieinfo *dip, struct objfile *objfile) 164019370Spst{ 164119370Spst struct type *type; 164298944Sobrien struct nextfield 164398944Sobrien { 164498944Sobrien struct nextfield *next; 164598944Sobrien struct field field; 164698944Sobrien }; 164719370Spst struct nextfield *list = NULL; 164819370Spst struct nextfield *new; 164919370Spst int nfields = 0; 165019370Spst int n; 165119370Spst char *scan; 165219370Spst char *listend; 165319370Spst unsigned short blocksz; 165419370Spst struct symbol *sym; 165519370Spst int nbytes; 165619370Spst int unsigned_enum = 1; 165798944Sobrien 1658130803Smarcel type = lookup_utype (dip->die_ref); 1659130803Smarcel if (type == NULL) 166019370Spst { 166119370Spst /* No forward references created an empty type, so install one now */ 166298944Sobrien type = alloc_utype (dip->die_ref, NULL); 166319370Spst } 166419370Spst TYPE_CODE (type) = TYPE_CODE_ENUM; 166519370Spst /* Some compilers try to be helpful by inventing "fake" names for 166619370Spst anonymous enums, structures, and unions, like "~0fake" or ".0fake". 166719370Spst Thanks, but no thanks... */ 166898944Sobrien if (dip->at_name != NULL 166998944Sobrien && *dip->at_name != '~' 167098944Sobrien && *dip->at_name != '.') 167119370Spst { 1672130803Smarcel TYPE_TAG_NAME (type) = obconcat (&objfile->objfile_obstack, 167398944Sobrien "", "", dip->at_name); 167419370Spst } 167598944Sobrien if (dip->at_byte_size != 0) 167619370Spst { 167798944Sobrien TYPE_LENGTH (type) = dip->at_byte_size; 167819370Spst } 1679130803Smarcel scan = dip->at_element_list; 1680130803Smarcel if (scan != NULL) 168119370Spst { 168298944Sobrien if (dip->short_element_list) 168319370Spst { 168419370Spst nbytes = attribute_size (AT_short_element_list); 168519370Spst } 168619370Spst else 168719370Spst { 168819370Spst nbytes = attribute_size (AT_element_list); 168919370Spst } 169019370Spst blocksz = target_to_host (scan, nbytes, GET_UNSIGNED, objfile); 169119370Spst listend = scan + nbytes + blocksz; 169219370Spst scan += nbytes; 169319370Spst while (scan < listend) 169419370Spst { 169519370Spst new = (struct nextfield *) alloca (sizeof (struct nextfield)); 169698944Sobrien new->next = list; 169719370Spst list = new; 169846283Sdfr FIELD_TYPE (list->field) = NULL; 169946283Sdfr FIELD_BITSIZE (list->field) = 0; 1700130803Smarcel FIELD_STATIC_KIND (list->field) = 0; 170146283Sdfr FIELD_BITPOS (list->field) = 170219370Spst target_to_host (scan, TARGET_FT_LONG_SIZE (objfile), GET_SIGNED, 170319370Spst objfile); 170419370Spst scan += TARGET_FT_LONG_SIZE (objfile); 170598944Sobrien list->field.name = obsavestring (scan, strlen (scan), 1706130803Smarcel &objfile->objfile_obstack); 170719370Spst scan += strlen (scan) + 1; 170819370Spst nfields++; 170919370Spst /* Handcraft a new symbol for this enum member. */ 1710130803Smarcel sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, 171119370Spst sizeof (struct symbol)); 171219370Spst memset (sym, 0, sizeof (struct symbol)); 1713130803Smarcel DEPRECATED_SYMBOL_NAME (sym) = create_name (list->field.name, 1714130803Smarcel &objfile->objfile_obstack); 171519370Spst SYMBOL_INIT_LANGUAGE_SPECIFIC (sym, cu_language); 1716130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 171719370Spst SYMBOL_CLASS (sym) = LOC_CONST; 171819370Spst SYMBOL_TYPE (sym) = type; 171946283Sdfr SYMBOL_VALUE (sym) = FIELD_BITPOS (list->field); 172019370Spst if (SYMBOL_VALUE (sym) < 0) 172119370Spst unsigned_enum = 0; 172219370Spst add_symbol_to_list (sym, list_in_scope); 172319370Spst } 172419370Spst /* Now create the vector of fields, and record how big it is. This is 172598944Sobrien where we reverse the order, by pulling the members off the list in 172698944Sobrien reverse order from how they were inserted. If we have no fields 172798944Sobrien (this is apparently possible in C++) then skip building a field 172898944Sobrien vector. */ 172919370Spst if (nfields > 0) 173019370Spst { 173119370Spst if (unsigned_enum) 173219370Spst TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED; 173319370Spst TYPE_NFIELDS (type) = nfields; 173419370Spst TYPE_FIELDS (type) = (struct field *) 1735130803Smarcel obstack_alloc (&objfile->objfile_obstack, sizeof (struct field) * nfields); 173619370Spst /* Copy the saved-up fields into the field vector. */ 173798944Sobrien for (n = 0; (n < nfields) && (list != NULL); list = list->next) 173819370Spst { 173998944Sobrien TYPE_FIELD (type, n++) = list->field; 174098944Sobrien } 174119370Spst } 174219370Spst } 174319370Spst return (type); 174419370Spst} 174519370Spst 174619370Spst/* 174719370Spst 174898944Sobrien LOCAL FUNCTION 174919370Spst 175098944Sobrien read_func_scope -- process all dies within a function scope 175119370Spst 175298944Sobrien DESCRIPTION 175319370Spst 175498944Sobrien Process all dies within a given function scope. We are passed 175598944Sobrien a die information structure pointer DIP for the die which 175698944Sobrien starts the function scope, and pointers into the raw die data 175798944Sobrien that define the dies within the function scope. 175819370Spst 175998944Sobrien For now, we ignore lexical block scopes within the function. 176098944Sobrien The problem is that AT&T cc does not define a DWARF lexical 176198944Sobrien block scope for the function itself, while gcc defines a 176298944Sobrien lexical block scope for the function. We need to think about 176398944Sobrien how to handle this difference, or if it is even a problem. 176498944Sobrien (FIXME) 176519370Spst */ 176619370Spst 176719370Spststatic void 176898944Sobrienread_func_scope (struct dieinfo *dip, char *thisdie, char *enddie, 176998944Sobrien struct objfile *objfile) 177019370Spst{ 1771130803Smarcel struct context_stack *new; 177298944Sobrien 177319370Spst /* AT_name is absent if the function is described with an 177419370Spst AT_abstract_origin tag. 177519370Spst Ignore the function description for now to avoid GDB core dumps. 177619370Spst FIXME: Add code to handle AT_abstract_origin tags properly. */ 177798944Sobrien if (dip->at_name == NULL) 177819370Spst { 1779130803Smarcel complaint (&symfile_complaints, "DIE @ 0x%x, AT_name tag missing", 1780130803Smarcel DIE_ID); 178119370Spst return; 178219370Spst } 178319370Spst 178498944Sobrien if (objfile->ei.entry_point >= dip->at_low_pc && 178598944Sobrien objfile->ei.entry_point < dip->at_high_pc) 178619370Spst { 178798944Sobrien objfile->ei.entry_func_lowpc = dip->at_low_pc; 178898944Sobrien objfile->ei.entry_func_highpc = dip->at_high_pc; 178919370Spst } 179098944Sobrien new = push_context (0, dip->at_low_pc); 179198944Sobrien new->name = new_symbol (dip, objfile); 179219370Spst list_in_scope = &local_symbols; 179398944Sobrien process_dies (thisdie + dip->die_length, enddie, objfile); 179419370Spst new = pop_context (); 179519370Spst /* Make a block for the local symbols within. */ 179698944Sobrien finish_block (new->name, &local_symbols, new->old_blocks, 179798944Sobrien new->start_addr, dip->at_high_pc, objfile); 179819370Spst list_in_scope = &file_symbols; 179919370Spst} 180019370Spst 180119370Spst 180219370Spst/* 180319370Spst 180498944Sobrien LOCAL FUNCTION 180519370Spst 180698944Sobrien handle_producer -- process the AT_producer attribute 180719370Spst 180898944Sobrien DESCRIPTION 180919370Spst 181098944Sobrien Perform any operations that depend on finding a particular 181198944Sobrien AT_producer attribute. 181219370Spst 181319370Spst */ 181419370Spst 181519370Spststatic void 181698944Sobrienhandle_producer (char *producer) 181719370Spst{ 181819370Spst 181919370Spst /* If this compilation unit was compiled with g++ or gcc, then set the 182019370Spst processing_gcc_compilation flag. */ 182119370Spst 1822130803Smarcel if (DEPRECATED_STREQN (producer, GCC_PRODUCER, strlen (GCC_PRODUCER))) 182346283Sdfr { 182446283Sdfr char version = producer[strlen (GCC_PRODUCER)]; 182546283Sdfr processing_gcc_compilation = (version == '2' ? 2 : 1); 182646283Sdfr } 182746283Sdfr else 182846283Sdfr { 182946283Sdfr processing_gcc_compilation = 1830130803Smarcel strncmp (producer, GPLUS_PRODUCER, strlen (GPLUS_PRODUCER)) == 0; 183146283Sdfr } 183219370Spst 183319370Spst /* Select a demangling style if we can identify the producer and if 183419370Spst the current style is auto. We leave the current style alone if it 183519370Spst is not auto. We also leave the demangling style alone if we find a 183619370Spst gcc (cc1) producer, as opposed to a g++ (cc1plus) producer. */ 183719370Spst 183819370Spst if (AUTO_DEMANGLING) 183919370Spst { 1840130803Smarcel if (DEPRECATED_STREQN (producer, GPLUS_PRODUCER, strlen (GPLUS_PRODUCER))) 184119370Spst { 184298944Sobrien#if 0 184398944Sobrien /* For now, stay with AUTO_DEMANGLING for g++ output, as we don't 184498944Sobrien know whether it will use the old style or v3 mangling. */ 184519370Spst set_demangling_style (GNU_DEMANGLING_STYLE_STRING); 184698944Sobrien#endif 184719370Spst } 1848130803Smarcel else if (DEPRECATED_STREQN (producer, LCC_PRODUCER, strlen (LCC_PRODUCER))) 184919370Spst { 185019370Spst set_demangling_style (LUCID_DEMANGLING_STYLE_STRING); 185119370Spst } 185219370Spst } 185319370Spst} 185419370Spst 185519370Spst 185619370Spst/* 185719370Spst 185898944Sobrien LOCAL FUNCTION 185919370Spst 186098944Sobrien read_file_scope -- process all dies within a file scope 186119370Spst 186298944Sobrien DESCRIPTION 186319370Spst 186498944Sobrien Process all dies within a given file scope. We are passed a 186598944Sobrien pointer to the die information structure for the die which 186698944Sobrien starts the file scope, and pointers into the raw die data which 186798944Sobrien mark the range of dies within the file scope. 186819370Spst 186998944Sobrien When the partial symbol table is built, the file offset for the line 187098944Sobrien number table for each compilation unit is saved in the partial symbol 187198944Sobrien table entry for that compilation unit. As the symbols for each 187298944Sobrien compilation unit are read, the line number table is read into memory 187398944Sobrien and the variable lnbase is set to point to it. Thus all we have to 187498944Sobrien do is use lnbase to access the line number table for the current 187598944Sobrien compilation unit. 187619370Spst */ 187719370Spst 187819370Spststatic void 187998944Sobrienread_file_scope (struct dieinfo *dip, char *thisdie, char *enddie, 188098944Sobrien struct objfile *objfile) 188119370Spst{ 188219370Spst struct cleanup *back_to; 188319370Spst struct symtab *symtab; 188498944Sobrien 188598944Sobrien if (objfile->ei.entry_point >= dip->at_low_pc && 188698944Sobrien objfile->ei.entry_point < dip->at_high_pc) 188719370Spst { 1888130803Smarcel objfile->ei.deprecated_entry_file_lowpc = dip->at_low_pc; 1889130803Smarcel objfile->ei.deprecated_entry_file_highpc = dip->at_high_pc; 189019370Spst } 189119370Spst set_cu_language (dip); 189298944Sobrien if (dip->at_producer != NULL) 189319370Spst { 189498944Sobrien handle_producer (dip->at_producer); 189519370Spst } 189619370Spst numutypes = (enddie - thisdie) / 4; 189719370Spst utypes = (struct type **) xmalloc (numutypes * sizeof (struct type *)); 189819370Spst back_to = make_cleanup (free_utypes, NULL); 189919370Spst memset (utypes, 0, numutypes * sizeof (struct type *)); 190019370Spst memset (ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *)); 190198944Sobrien start_symtab (dip->at_name, dip->at_comp_dir, dip->at_low_pc); 190246283Sdfr record_debugformat ("DWARF 1"); 190319370Spst decode_line_numbers (lnbase); 190498944Sobrien process_dies (thisdie + dip->die_length, enddie, objfile); 190519370Spst 190698944Sobrien symtab = end_symtab (dip->at_high_pc, objfile, 0); 190719370Spst if (symtab != NULL) 190819370Spst { 190998944Sobrien symtab->language = cu_language; 191098944Sobrien } 191119370Spst do_cleanups (back_to); 191219370Spst} 191319370Spst 191419370Spst/* 191519370Spst 191698944Sobrien LOCAL FUNCTION 191719370Spst 191898944Sobrien process_dies -- process a range of DWARF Information Entries 191919370Spst 192098944Sobrien SYNOPSIS 192119370Spst 192298944Sobrien static void process_dies (char *thisdie, char *enddie, 192398944Sobrien struct objfile *objfile) 192419370Spst 192598944Sobrien DESCRIPTION 192619370Spst 192798944Sobrien Process all DIE's in a specified range. May be (and almost 192898944Sobrien certainly will be) called recursively. 192919370Spst */ 193019370Spst 193119370Spststatic void 193298944Sobrienprocess_dies (char *thisdie, char *enddie, struct objfile *objfile) 193319370Spst{ 193419370Spst char *nextdie; 193519370Spst struct dieinfo di; 193698944Sobrien 193719370Spst while (thisdie < enddie) 193819370Spst { 193919370Spst basicdieinfo (&di, thisdie, objfile); 194019370Spst if (di.die_length < SIZEOF_DIE_LENGTH) 194119370Spst { 194219370Spst break; 194319370Spst } 194419370Spst else if (di.die_tag == TAG_padding) 194519370Spst { 194619370Spst nextdie = thisdie + di.die_length; 194719370Spst } 194819370Spst else 194919370Spst { 195019370Spst completedieinfo (&di, objfile); 195119370Spst if (di.at_sibling != 0) 195219370Spst { 195319370Spst nextdie = dbbase + di.at_sibling - dbroff; 195419370Spst } 195519370Spst else 195619370Spst { 195719370Spst nextdie = thisdie + di.die_length; 195819370Spst } 195919370Spst /* I think that these are always text, not data, addresses. */ 196098944Sobrien di.at_low_pc = SMASH_TEXT_ADDRESS (di.at_low_pc); 196198944Sobrien di.at_high_pc = SMASH_TEXT_ADDRESS (di.at_high_pc); 196219370Spst switch (di.die_tag) 196319370Spst { 196419370Spst case TAG_compile_unit: 196519370Spst /* Skip Tag_compile_unit if we are already inside a compilation 196698944Sobrien unit, we are unable to handle nested compilation units 196798944Sobrien properly (FIXME). */ 196819370Spst if (current_subfile == NULL) 196919370Spst read_file_scope (&di, thisdie, nextdie, objfile); 197019370Spst else 197119370Spst nextdie = thisdie + di.die_length; 197219370Spst break; 197319370Spst case TAG_global_subroutine: 197419370Spst case TAG_subroutine: 197519370Spst if (di.has_at_low_pc) 197619370Spst { 197719370Spst read_func_scope (&di, thisdie, nextdie, objfile); 197819370Spst } 197919370Spst break; 198019370Spst case TAG_lexical_block: 198119370Spst read_lexical_block_scope (&di, thisdie, nextdie, objfile); 198219370Spst break; 198319370Spst case TAG_class_type: 198419370Spst case TAG_structure_type: 198519370Spst case TAG_union_type: 198619370Spst read_structure_scope (&di, thisdie, nextdie, objfile); 198719370Spst break; 198819370Spst case TAG_enumeration_type: 198919370Spst read_enumeration (&di, thisdie, nextdie, objfile); 199019370Spst break; 199119370Spst case TAG_subroutine_type: 199219370Spst read_subroutine_type (&di, thisdie, nextdie); 199319370Spst break; 199419370Spst case TAG_array_type: 199519370Spst dwarf_read_array_type (&di); 199619370Spst break; 199719370Spst case TAG_pointer_type: 199819370Spst read_tag_pointer_type (&di); 199919370Spst break; 200019370Spst case TAG_string_type: 200119370Spst read_tag_string_type (&di); 200219370Spst break; 200319370Spst default: 200419370Spst new_symbol (&di, objfile); 200519370Spst break; 200619370Spst } 200719370Spst } 200819370Spst thisdie = nextdie; 200919370Spst } 201019370Spst} 201119370Spst 201219370Spst/* 201319370Spst 201498944Sobrien LOCAL FUNCTION 201519370Spst 201698944Sobrien decode_line_numbers -- decode a line number table fragment 201719370Spst 201898944Sobrien SYNOPSIS 201919370Spst 202098944Sobrien static void decode_line_numbers (char *tblscan, char *tblend, 202198944Sobrien long length, long base, long line, long pc) 202219370Spst 202398944Sobrien DESCRIPTION 202419370Spst 202598944Sobrien Translate the DWARF line number information to gdb form. 202619370Spst 202798944Sobrien The ".line" section contains one or more line number tables, one for 202898944Sobrien each ".line" section from the objects that were linked. 202919370Spst 203098944Sobrien The AT_stmt_list attribute for each TAG_source_file entry in the 203198944Sobrien ".debug" section contains the offset into the ".line" section for the 203298944Sobrien start of the table for that file. 203319370Spst 203498944Sobrien The table itself has the following structure: 203519370Spst 203698944Sobrien <table length><base address><source statement entry> 203798944Sobrien 4 bytes 4 bytes 10 bytes 203819370Spst 203998944Sobrien The table length is the total size of the table, including the 4 bytes 204098944Sobrien for the length information. 204119370Spst 204298944Sobrien The base address is the address of the first instruction generated 204398944Sobrien for the source file. 204419370Spst 204598944Sobrien Each source statement entry has the following structure: 204619370Spst 204798944Sobrien <line number><statement position><address delta> 204898944Sobrien 4 bytes 2 bytes 4 bytes 204919370Spst 205098944Sobrien The line number is relative to the start of the file, starting with 205198944Sobrien line 1. 205219370Spst 205398944Sobrien The statement position either -1 (0xFFFF) or the number of characters 205498944Sobrien from the beginning of the line to the beginning of the statement. 205519370Spst 205698944Sobrien The address delta is the difference between the base address and 205798944Sobrien the address of the first instruction for the statement. 205819370Spst 205998944Sobrien Note that we must copy the bytes from the packed table to our local 206098944Sobrien variables before attempting to use them, to avoid alignment problems 206198944Sobrien on some machines, particularly RISC processors. 206219370Spst 206398944Sobrien BUGS 206419370Spst 206598944Sobrien Does gdb expect the line numbers to be sorted? They are now by 206698944Sobrien chance/luck, but are not required to be. (FIXME) 206719370Spst 206898944Sobrien The line with number 0 is unused, gdb apparently can discover the 206998944Sobrien span of the last line some other way. How? (FIXME) 207019370Spst */ 207119370Spst 207219370Spststatic void 207398944Sobriendecode_line_numbers (char *linetable) 207419370Spst{ 207519370Spst char *tblscan; 207619370Spst char *tblend; 207719370Spst unsigned long length; 207819370Spst unsigned long base; 207919370Spst unsigned long line; 208019370Spst unsigned long pc; 208198944Sobrien 208219370Spst if (linetable != NULL) 208319370Spst { 208419370Spst tblscan = tblend = linetable; 208519370Spst length = target_to_host (tblscan, SIZEOF_LINETBL_LENGTH, GET_UNSIGNED, 208619370Spst current_objfile); 208719370Spst tblscan += SIZEOF_LINETBL_LENGTH; 208819370Spst tblend += length; 208919370Spst base = target_to_host (tblscan, TARGET_FT_POINTER_SIZE (objfile), 209019370Spst GET_UNSIGNED, current_objfile); 209119370Spst tblscan += TARGET_FT_POINTER_SIZE (objfile); 209219370Spst base += baseaddr; 209319370Spst while (tblscan < tblend) 209419370Spst { 209519370Spst line = target_to_host (tblscan, SIZEOF_LINETBL_LINENO, GET_UNSIGNED, 209619370Spst current_objfile); 209719370Spst tblscan += SIZEOF_LINETBL_LINENO + SIZEOF_LINETBL_STMT; 209819370Spst pc = target_to_host (tblscan, SIZEOF_LINETBL_DELTA, GET_UNSIGNED, 209919370Spst current_objfile); 210019370Spst tblscan += SIZEOF_LINETBL_DELTA; 210119370Spst pc += base; 210219370Spst if (line != 0) 210319370Spst { 210419370Spst record_line (current_subfile, line, pc); 210519370Spst } 210619370Spst } 210719370Spst } 210819370Spst} 210919370Spst 211019370Spst/* 211119370Spst 211298944Sobrien LOCAL FUNCTION 211319370Spst 211498944Sobrien locval -- compute the value of a location attribute 211519370Spst 211698944Sobrien SYNOPSIS 211719370Spst 211898944Sobrien static int locval (struct dieinfo *dip) 211919370Spst 212098944Sobrien DESCRIPTION 212119370Spst 212298944Sobrien Given pointer to a string of bytes that define a location, compute 212398944Sobrien the location and return the value. 212498944Sobrien A location description containing no atoms indicates that the 212598944Sobrien object is optimized out. The optimized_out flag is set for those, 212698944Sobrien the return value is meaningless. 212719370Spst 212898944Sobrien When computing values involving the current value of the frame pointer, 212998944Sobrien the value zero is used, which results in a value relative to the frame 213098944Sobrien pointer, rather than the absolute value. This is what GDB wants 213198944Sobrien anyway. 213219370Spst 213398944Sobrien When the result is a register number, the isreg flag is set, otherwise 213498944Sobrien it is cleared. This is a kludge until we figure out a better 213598944Sobrien way to handle the problem. Gdb's design does not mesh well with the 213698944Sobrien DWARF notion of a location computing interpreter, which is a shame 213798944Sobrien because the flexibility goes unused. 213819370Spst 213998944Sobrien NOTES 214098944Sobrien 214198944Sobrien Note that stack[0] is unused except as a default error return. 214298944Sobrien Note that stack overflow is not yet handled. 214319370Spst */ 214419370Spst 214519370Spststatic int 214698944Sobrienlocval (struct dieinfo *dip) 214719370Spst{ 214819370Spst unsigned short nbytes; 214919370Spst unsigned short locsize; 215019370Spst auto long stack[64]; 215119370Spst int stacki; 215246283Sdfr char *loc; 215319370Spst char *end; 215419370Spst int loc_atom_code; 215519370Spst int loc_value_size; 215698944Sobrien 215798944Sobrien loc = dip->at_location; 215819370Spst nbytes = attribute_size (AT_location); 215919370Spst locsize = target_to_host (loc, nbytes, GET_UNSIGNED, current_objfile); 216019370Spst loc += nbytes; 216119370Spst end = loc + locsize; 216219370Spst stacki = 0; 216319370Spst stack[stacki] = 0; 216498944Sobrien dip->isreg = 0; 216598944Sobrien dip->offreg = 0; 216698944Sobrien dip->optimized_out = 1; 216719370Spst loc_value_size = TARGET_FT_LONG_SIZE (current_objfile); 216819370Spst while (loc < end) 216919370Spst { 217098944Sobrien dip->optimized_out = 0; 217119370Spst loc_atom_code = target_to_host (loc, SIZEOF_LOC_ATOM_CODE, GET_UNSIGNED, 217219370Spst current_objfile); 217319370Spst loc += SIZEOF_LOC_ATOM_CODE; 217419370Spst switch (loc_atom_code) 217519370Spst { 217698944Sobrien case 0: 217798944Sobrien /* error */ 217898944Sobrien loc = end; 217998944Sobrien break; 218098944Sobrien case OP_REG: 218198944Sobrien /* push register (number) */ 218298944Sobrien stack[++stacki] 218398944Sobrien = DWARF_REG_TO_REGNUM (target_to_host (loc, loc_value_size, 218498944Sobrien GET_UNSIGNED, 218598944Sobrien current_objfile)); 218698944Sobrien loc += loc_value_size; 218798944Sobrien dip->isreg = 1; 218898944Sobrien break; 218998944Sobrien case OP_BASEREG: 219098944Sobrien /* push value of register (number) */ 219198944Sobrien /* Actually, we compute the value as if register has 0, so the 219298944Sobrien value ends up being the offset from that register. */ 219398944Sobrien dip->offreg = 1; 219498944Sobrien dip->basereg = target_to_host (loc, loc_value_size, GET_UNSIGNED, 219598944Sobrien current_objfile); 219698944Sobrien loc += loc_value_size; 219798944Sobrien stack[++stacki] = 0; 219898944Sobrien break; 219998944Sobrien case OP_ADDR: 220098944Sobrien /* push address (relocated address) */ 220198944Sobrien stack[++stacki] = target_to_host (loc, loc_value_size, 220298944Sobrien GET_UNSIGNED, current_objfile); 220398944Sobrien loc += loc_value_size; 220498944Sobrien break; 220598944Sobrien case OP_CONST: 220698944Sobrien /* push constant (number) FIXME: signed or unsigned! */ 220798944Sobrien stack[++stacki] = target_to_host (loc, loc_value_size, 220898944Sobrien GET_SIGNED, current_objfile); 220998944Sobrien loc += loc_value_size; 221098944Sobrien break; 221198944Sobrien case OP_DEREF2: 221298944Sobrien /* pop, deref and push 2 bytes (as a long) */ 2213130803Smarcel complaint (&symfile_complaints, 2214130803Smarcel "DIE @ 0x%x \"%s\", OP_DEREF2 address 0x%lx not handled", 2215130803Smarcel DIE_ID, DIE_NAME, stack[stacki]); 221698944Sobrien break; 221798944Sobrien case OP_DEREF4: /* pop, deref and push 4 bytes (as a long) */ 2218130803Smarcel complaint (&symfile_complaints, 2219130803Smarcel "DIE @ 0x%x \"%s\", OP_DEREF4 address 0x%lx not handled", 2220130803Smarcel DIE_ID, DIE_NAME, stack[stacki]); 222198944Sobrien break; 222298944Sobrien case OP_ADD: /* pop top 2 items, add, push result */ 222398944Sobrien stack[stacki - 1] += stack[stacki]; 222498944Sobrien stacki--; 222598944Sobrien break; 222619370Spst } 222719370Spst } 222819370Spst return (stack[stacki]); 222919370Spst} 223019370Spst 223119370Spst/* 223219370Spst 223398944Sobrien LOCAL FUNCTION 223419370Spst 223598944Sobrien read_ofile_symtab -- build a full symtab entry from chunk of DIE's 223619370Spst 223798944Sobrien SYNOPSIS 223819370Spst 223998944Sobrien static void read_ofile_symtab (struct partial_symtab *pst) 224019370Spst 224198944Sobrien DESCRIPTION 224219370Spst 224398944Sobrien When expanding a partial symbol table entry to a full symbol table 224498944Sobrien entry, this is the function that gets called to read in the symbols 224598944Sobrien for the compilation unit. A pointer to the newly constructed symtab, 224698944Sobrien which is now the new first one on the objfile's symtab list, is 224798944Sobrien stashed in the partial symbol table entry. 224819370Spst */ 224919370Spst 225019370Spststatic void 225198944Sobrienread_ofile_symtab (struct partial_symtab *pst) 225219370Spst{ 225319370Spst struct cleanup *back_to; 225419370Spst unsigned long lnsize; 225519370Spst file_ptr foffset; 225619370Spst bfd *abfd; 225719370Spst char lnsizedata[SIZEOF_LINETBL_LENGTH]; 225819370Spst 225998944Sobrien abfd = pst->objfile->obfd; 226098944Sobrien current_objfile = pst->objfile; 226119370Spst 226219370Spst /* Allocate a buffer for the entire chunk of DIE's for this compilation 226319370Spst unit, seek to the location in the file, and read in all the DIE's. */ 226419370Spst 226519370Spst diecount = 0; 226619370Spst dbsize = DBLENGTH (pst); 226719370Spst dbbase = xmalloc (dbsize); 226898944Sobrien dbroff = DBROFF (pst); 226998944Sobrien foffset = DBFOFF (pst) + dbroff; 227019370Spst base_section_offsets = pst->section_offsets; 227119370Spst baseaddr = ANOFFSET (pst->section_offsets, 0); 227219370Spst if (bfd_seek (abfd, foffset, SEEK_SET) || 227398944Sobrien (bfd_bread (dbbase, dbsize, abfd) != dbsize)) 227419370Spst { 227598944Sobrien xfree (dbbase); 227619370Spst error ("can't read DWARF data"); 227719370Spst } 227898944Sobrien back_to = make_cleanup (xfree, dbbase); 227919370Spst 228019370Spst /* If there is a line number table associated with this compilation unit 228119370Spst then read the size of this fragment in bytes, from the fragment itself. 228219370Spst Allocate a buffer for the fragment and read it in for future 228319370Spst processing. */ 228419370Spst 228519370Spst lnbase = NULL; 228619370Spst if (LNFOFF (pst)) 228719370Spst { 228819370Spst if (bfd_seek (abfd, LNFOFF (pst), SEEK_SET) || 2289130803Smarcel (bfd_bread (lnsizedata, sizeof (lnsizedata), abfd) 229098944Sobrien != sizeof (lnsizedata))) 229119370Spst { 229219370Spst error ("can't read DWARF line number table size"); 229319370Spst } 229419370Spst lnsize = target_to_host (lnsizedata, SIZEOF_LINETBL_LENGTH, 229598944Sobrien GET_UNSIGNED, pst->objfile); 229619370Spst lnbase = xmalloc (lnsize); 229719370Spst if (bfd_seek (abfd, LNFOFF (pst), SEEK_SET) || 229898944Sobrien (bfd_bread (lnbase, lnsize, abfd) != lnsize)) 229919370Spst { 230098944Sobrien xfree (lnbase); 230119370Spst error ("can't read DWARF line numbers"); 230219370Spst } 230398944Sobrien make_cleanup (xfree, lnbase); 230419370Spst } 230519370Spst 230698944Sobrien process_dies (dbbase, dbbase + dbsize, pst->objfile); 230719370Spst do_cleanups (back_to); 230819370Spst current_objfile = NULL; 230998944Sobrien pst->symtab = pst->objfile->symtabs; 231019370Spst} 231119370Spst 231219370Spst/* 231319370Spst 231498944Sobrien LOCAL FUNCTION 231519370Spst 231698944Sobrien psymtab_to_symtab_1 -- do grunt work for building a full symtab entry 231719370Spst 231898944Sobrien SYNOPSIS 231919370Spst 232098944Sobrien static void psymtab_to_symtab_1 (struct partial_symtab *pst) 232119370Spst 232298944Sobrien DESCRIPTION 232319370Spst 232498944Sobrien Called once for each partial symbol table entry that needs to be 232598944Sobrien expanded into a full symbol table entry. 232619370Spst 232798944Sobrien */ 232819370Spst 232919370Spststatic void 233098944Sobrienpsymtab_to_symtab_1 (struct partial_symtab *pst) 233119370Spst{ 233219370Spst int i; 233319370Spst struct cleanup *old_chain; 233498944Sobrien 233519370Spst if (pst != NULL) 233619370Spst { 233719370Spst if (pst->readin) 233819370Spst { 233919370Spst warning ("psymtab for %s already read in. Shouldn't happen.", 234098944Sobrien pst->filename); 234119370Spst } 234219370Spst else 234319370Spst { 234419370Spst /* Read in all partial symtabs on which this one is dependent */ 234598944Sobrien for (i = 0; i < pst->number_of_dependencies; i++) 234619370Spst { 234798944Sobrien if (!pst->dependencies[i]->readin) 234819370Spst { 234919370Spst /* Inform about additional files that need to be read in. */ 235019370Spst if (info_verbose) 235119370Spst { 235219370Spst fputs_filtered (" ", gdb_stdout); 235319370Spst wrap_here (""); 235419370Spst fputs_filtered ("and ", gdb_stdout); 235519370Spst wrap_here (""); 235619370Spst printf_filtered ("%s...", 235798944Sobrien pst->dependencies[i]->filename); 235819370Spst wrap_here (""); 235998944Sobrien gdb_flush (gdb_stdout); /* Flush output */ 236019370Spst } 236198944Sobrien psymtab_to_symtab_1 (pst->dependencies[i]); 236219370Spst } 236398944Sobrien } 236498944Sobrien if (DBLENGTH (pst)) /* Otherwise it's a dummy */ 236519370Spst { 236619370Spst buildsym_init (); 236798944Sobrien old_chain = make_cleanup (really_free_pendings, 0); 236819370Spst read_ofile_symtab (pst); 236919370Spst if (info_verbose) 237019370Spst { 237119370Spst printf_filtered ("%d DIE's, sorting...", diecount); 237219370Spst wrap_here (""); 237319370Spst gdb_flush (gdb_stdout); 237419370Spst } 237519370Spst do_cleanups (old_chain); 237619370Spst } 237798944Sobrien pst->readin = 1; 237819370Spst } 237919370Spst } 238019370Spst} 238119370Spst 238219370Spst/* 238319370Spst 238498944Sobrien LOCAL FUNCTION 238519370Spst 238698944Sobrien dwarf_psymtab_to_symtab -- build a full symtab entry from partial one 238719370Spst 238898944Sobrien SYNOPSIS 238919370Spst 239098944Sobrien static void dwarf_psymtab_to_symtab (struct partial_symtab *pst) 239119370Spst 239298944Sobrien DESCRIPTION 239319370Spst 239498944Sobrien This is the DWARF support entry point for building a full symbol 239598944Sobrien table entry from a partial symbol table entry. We are passed a 239698944Sobrien pointer to the partial symbol table entry that needs to be expanded. 239719370Spst 239898944Sobrien */ 239919370Spst 240019370Spststatic void 240198944Sobriendwarf_psymtab_to_symtab (struct partial_symtab *pst) 240219370Spst{ 240319370Spst 240419370Spst if (pst != NULL) 240519370Spst { 240698944Sobrien if (pst->readin) 240719370Spst { 240819370Spst warning ("psymtab for %s already read in. Shouldn't happen.", 240998944Sobrien pst->filename); 241019370Spst } 241119370Spst else 241219370Spst { 241398944Sobrien if (DBLENGTH (pst) || pst->number_of_dependencies) 241419370Spst { 241519370Spst /* Print the message now, before starting serious work, to avoid 241698944Sobrien disconcerting pauses. */ 241719370Spst if (info_verbose) 241819370Spst { 241919370Spst printf_filtered ("Reading in symbols for %s...", 242098944Sobrien pst->filename); 242119370Spst gdb_flush (gdb_stdout); 242219370Spst } 242398944Sobrien 242419370Spst psymtab_to_symtab_1 (pst); 242598944Sobrien 242698944Sobrien#if 0 /* FIXME: Check to see what dbxread is doing here and see if 242798944Sobrien we need to do an equivalent or is this something peculiar to 242898944Sobrien stabs/a.out format. 242998944Sobrien Match with global symbols. This only needs to be done once, 243098944Sobrien after all of the symtabs and dependencies have been read in. 243198944Sobrien */ 243298944Sobrien scan_file_globals (pst->objfile); 243319370Spst#endif 243498944Sobrien 243519370Spst /* Finish up the verbose info message. */ 243619370Spst if (info_verbose) 243719370Spst { 243819370Spst printf_filtered ("done.\n"); 243919370Spst gdb_flush (gdb_stdout); 244019370Spst } 244119370Spst } 244219370Spst } 244319370Spst } 244419370Spst} 244519370Spst 244619370Spst/* 244719370Spst 244898944Sobrien LOCAL FUNCTION 244919370Spst 245098944Sobrien add_enum_psymbol -- add enumeration members to partial symbol table 245119370Spst 245298944Sobrien DESCRIPTION 245319370Spst 245498944Sobrien Given pointer to a DIE that is known to be for an enumeration, 245598944Sobrien extract the symbolic names of the enumeration members and add 245698944Sobrien partial symbols for them. 245798944Sobrien */ 245819370Spst 245919370Spststatic void 246098944Sobrienadd_enum_psymbol (struct dieinfo *dip, struct objfile *objfile) 246119370Spst{ 246219370Spst char *scan; 246319370Spst char *listend; 246419370Spst unsigned short blocksz; 246519370Spst int nbytes; 246698944Sobrien 2467130803Smarcel scan = dip->at_element_list; 2468130803Smarcel if (scan != NULL) 246919370Spst { 247098944Sobrien if (dip->short_element_list) 247119370Spst { 247219370Spst nbytes = attribute_size (AT_short_element_list); 247319370Spst } 247419370Spst else 247519370Spst { 247619370Spst nbytes = attribute_size (AT_element_list); 247719370Spst } 247819370Spst blocksz = target_to_host (scan, nbytes, GET_UNSIGNED, objfile); 247919370Spst scan += nbytes; 248019370Spst listend = scan + blocksz; 248119370Spst while (scan < listend) 248219370Spst { 248319370Spst scan += TARGET_FT_LONG_SIZE (objfile); 2484130803Smarcel add_psymbol_to_list (scan, strlen (scan), VAR_DOMAIN, LOC_CONST, 248598944Sobrien &objfile->static_psymbols, 0, 0, cu_language, 248619370Spst objfile); 248719370Spst scan += strlen (scan) + 1; 248819370Spst } 248919370Spst } 249019370Spst} 249119370Spst 249219370Spst/* 249319370Spst 249498944Sobrien LOCAL FUNCTION 249519370Spst 249698944Sobrien add_partial_symbol -- add symbol to partial symbol table 249719370Spst 249898944Sobrien DESCRIPTION 249919370Spst 250098944Sobrien Given a DIE, if it is one of the types that we want to 250198944Sobrien add to a partial symbol table, finish filling in the die info 250298944Sobrien and then add a partial symbol table entry for it. 250319370Spst 250498944Sobrien NOTES 250519370Spst 250698944Sobrien The caller must ensure that the DIE has a valid name attribute. 250798944Sobrien */ 250819370Spst 250919370Spststatic void 251098944Sobrienadd_partial_symbol (struct dieinfo *dip, struct objfile *objfile) 251119370Spst{ 251298944Sobrien switch (dip->die_tag) 251319370Spst { 251419370Spst case TAG_global_subroutine: 251598944Sobrien add_psymbol_to_list (dip->at_name, strlen (dip->at_name), 2516130803Smarcel VAR_DOMAIN, LOC_BLOCK, 251798944Sobrien &objfile->global_psymbols, 251898944Sobrien 0, dip->at_low_pc, cu_language, objfile); 251919370Spst break; 252019370Spst case TAG_global_variable: 252198944Sobrien add_psymbol_to_list (dip->at_name, strlen (dip->at_name), 2522130803Smarcel VAR_DOMAIN, LOC_STATIC, 252398944Sobrien &objfile->global_psymbols, 252419370Spst 0, 0, cu_language, objfile); 252519370Spst break; 252619370Spst case TAG_subroutine: 252798944Sobrien add_psymbol_to_list (dip->at_name, strlen (dip->at_name), 2528130803Smarcel VAR_DOMAIN, LOC_BLOCK, 252998944Sobrien &objfile->static_psymbols, 253098944Sobrien 0, dip->at_low_pc, cu_language, objfile); 253119370Spst break; 253219370Spst case TAG_local_variable: 253398944Sobrien add_psymbol_to_list (dip->at_name, strlen (dip->at_name), 2534130803Smarcel VAR_DOMAIN, LOC_STATIC, 253598944Sobrien &objfile->static_psymbols, 253619370Spst 0, 0, cu_language, objfile); 253719370Spst break; 253819370Spst case TAG_typedef: 253998944Sobrien add_psymbol_to_list (dip->at_name, strlen (dip->at_name), 2540130803Smarcel VAR_DOMAIN, LOC_TYPEDEF, 254198944Sobrien &objfile->static_psymbols, 254219370Spst 0, 0, cu_language, objfile); 254319370Spst break; 254419370Spst case TAG_class_type: 254519370Spst case TAG_structure_type: 254619370Spst case TAG_union_type: 254719370Spst case TAG_enumeration_type: 254819370Spst /* Do not add opaque aggregate definitions to the psymtab. */ 254998944Sobrien if (!dip->has_at_byte_size) 255019370Spst break; 255198944Sobrien add_psymbol_to_list (dip->at_name, strlen (dip->at_name), 2552130803Smarcel STRUCT_DOMAIN, LOC_TYPEDEF, 255398944Sobrien &objfile->static_psymbols, 255419370Spst 0, 0, cu_language, objfile); 255519370Spst if (cu_language == language_cplus) 255619370Spst { 255719370Spst /* For C++, these implicitly act as typedefs as well. */ 255898944Sobrien add_psymbol_to_list (dip->at_name, strlen (dip->at_name), 2559130803Smarcel VAR_DOMAIN, LOC_TYPEDEF, 256098944Sobrien &objfile->static_psymbols, 256119370Spst 0, 0, cu_language, objfile); 256219370Spst } 256319370Spst break; 256419370Spst } 256519370Spst} 256698944Sobrien/* *INDENT-OFF* */ 256719370Spst/* 256819370Spst 256919370SpstLOCAL FUNCTION 257019370Spst 257119370Spst scan_partial_symbols -- scan DIE's within a single compilation unit 257219370Spst 257319370SpstDESCRIPTION 257419370Spst 257519370Spst Process the DIE's within a single compilation unit, looking for 257619370Spst interesting DIE's that contribute to the partial symbol table entry 257719370Spst for this compilation unit. 257819370Spst 257919370SpstNOTES 258019370Spst 258119370Spst There are some DIE's that may appear both at file scope and within 258219370Spst the scope of a function. We are only interested in the ones at file 258319370Spst scope, and the only way to tell them apart is to keep track of the 258419370Spst scope. For example, consider the test case: 258519370Spst 258619370Spst static int i; 258719370Spst main () { int j; } 258819370Spst 258919370Spst for which the relevant DWARF segment has the structure: 259019370Spst 259119370Spst 0x51: 259219370Spst 0x23 global subrtn sibling 0x9b 259319370Spst name main 259419370Spst fund_type FT_integer 259519370Spst low_pc 0x800004cc 259619370Spst high_pc 0x800004d4 259719370Spst 259819370Spst 0x74: 259919370Spst 0x23 local var sibling 0x97 260019370Spst name j 260119370Spst fund_type FT_integer 260219370Spst location OP_BASEREG 0xe 260319370Spst OP_CONST 0xfffffffc 260419370Spst OP_ADD 260519370Spst 0x97: 260619370Spst 0x4 260719370Spst 260819370Spst 0x9b: 260919370Spst 0x1d local var sibling 0xb8 261019370Spst name i 261119370Spst fund_type FT_integer 261219370Spst location OP_ADDR 0x800025dc 261319370Spst 261419370Spst 0xb8: 261519370Spst 0x4 261619370Spst 261719370Spst We want to include the symbol 'i' in the partial symbol table, but 261819370Spst not the symbol 'j'. In essence, we want to skip all the dies within 261919370Spst the scope of a TAG_global_subroutine DIE. 262019370Spst 262119370Spst Don't attempt to add anonymous structures or unions since they have 262219370Spst no name. Anonymous enumerations however are processed, because we 262319370Spst want to extract their member names (the check for a tag name is 262419370Spst done later). 262519370Spst 262619370Spst Also, for variables and subroutines, check that this is the place 262719370Spst where the actual definition occurs, rather than just a reference 262819370Spst to an external. 262919370Spst */ 263098944Sobrien/* *INDENT-ON* */ 263119370Spst 263298944Sobrien 263398944Sobrien 263419370Spststatic void 263598944Sobrienscan_partial_symbols (char *thisdie, char *enddie, struct objfile *objfile) 263619370Spst{ 263719370Spst char *nextdie; 263819370Spst char *temp; 263919370Spst struct dieinfo di; 264098944Sobrien 264119370Spst while (thisdie < enddie) 264219370Spst { 264319370Spst basicdieinfo (&di, thisdie, objfile); 264419370Spst if (di.die_length < SIZEOF_DIE_LENGTH) 264519370Spst { 264619370Spst break; 264719370Spst } 264819370Spst else 264919370Spst { 265019370Spst nextdie = thisdie + di.die_length; 265119370Spst /* To avoid getting complete die information for every die, we 265219370Spst only do it (below) for the cases we are interested in. */ 265319370Spst switch (di.die_tag) 265419370Spst { 265519370Spst case TAG_global_subroutine: 265619370Spst case TAG_subroutine: 265719370Spst completedieinfo (&di, objfile); 265819370Spst if (di.at_name && (di.has_at_low_pc || di.at_location)) 265919370Spst { 266019370Spst add_partial_symbol (&di, objfile); 266119370Spst /* If there is a sibling attribute, adjust the nextdie 266219370Spst pointer to skip the entire scope of the subroutine. 266319370Spst Apply some sanity checking to make sure we don't 266419370Spst overrun or underrun the range of remaining DIE's */ 266519370Spst if (di.at_sibling != 0) 266619370Spst { 266719370Spst temp = dbbase + di.at_sibling - dbroff; 266819370Spst if ((temp < thisdie) || (temp >= enddie)) 266919370Spst { 2670130803Smarcel bad_die_ref_complaint (DIE_ID, DIE_NAME, 2671130803Smarcel di.at_sibling); 267219370Spst } 267319370Spst else 267419370Spst { 267519370Spst nextdie = temp; 267619370Spst } 267719370Spst } 267819370Spst } 267919370Spst break; 268019370Spst case TAG_global_variable: 268119370Spst case TAG_local_variable: 268219370Spst completedieinfo (&di, objfile); 268319370Spst if (di.at_name && (di.has_at_low_pc || di.at_location)) 268419370Spst { 268519370Spst add_partial_symbol (&di, objfile); 268619370Spst } 268719370Spst break; 268819370Spst case TAG_typedef: 268919370Spst case TAG_class_type: 269019370Spst case TAG_structure_type: 269119370Spst case TAG_union_type: 269219370Spst completedieinfo (&di, objfile); 269319370Spst if (di.at_name) 269419370Spst { 269519370Spst add_partial_symbol (&di, objfile); 269619370Spst } 269719370Spst break; 269819370Spst case TAG_enumeration_type: 269919370Spst completedieinfo (&di, objfile); 270019370Spst if (di.at_name) 270119370Spst { 270219370Spst add_partial_symbol (&di, objfile); 270319370Spst } 270419370Spst add_enum_psymbol (&di, objfile); 270519370Spst break; 270619370Spst } 270719370Spst } 270819370Spst thisdie = nextdie; 270919370Spst } 271019370Spst} 271119370Spst 271219370Spst/* 271319370Spst 271498944Sobrien LOCAL FUNCTION 271519370Spst 271698944Sobrien scan_compilation_units -- build a psymtab entry for each compilation 271719370Spst 271898944Sobrien DESCRIPTION 271919370Spst 272098944Sobrien This is the top level dwarf parsing routine for building partial 272198944Sobrien symbol tables. 272219370Spst 272398944Sobrien It scans from the beginning of the DWARF table looking for the first 272498944Sobrien TAG_compile_unit DIE, and then follows the sibling chain to locate 272598944Sobrien each additional TAG_compile_unit DIE. 272619370Spst 272798944Sobrien For each TAG_compile_unit DIE it creates a partial symtab structure, 272898944Sobrien calls a subordinate routine to collect all the compilation unit's 272998944Sobrien global DIE's, file scope DIEs, typedef DIEs, etc, and then links the 273098944Sobrien new partial symtab structure into the partial symbol table. It also 273198944Sobrien records the appropriate information in the partial symbol table entry 273298944Sobrien to allow the chunk of DIE's and line number table for this compilation 273398944Sobrien unit to be located and re-read later, to generate a complete symbol 273498944Sobrien table entry for the compilation unit. 273519370Spst 273698944Sobrien Thus it effectively partitions up a chunk of DIE's for multiple 273798944Sobrien compilation units into smaller DIE chunks and line number tables, 273898944Sobrien and associates them with a partial symbol table entry. 273919370Spst 274098944Sobrien NOTES 274119370Spst 274298944Sobrien If any compilation unit has no line number table associated with 274398944Sobrien it for some reason (a missing at_stmt_list attribute, rather than 274498944Sobrien just one with a value of zero, which is valid) then we ensure that 274598944Sobrien the recorded file offset is zero so that the routine which later 274698944Sobrien reads line number table fragments knows that there is no fragment 274798944Sobrien to read. 274819370Spst 274998944Sobrien RETURNS 275019370Spst 275198944Sobrien Returns no value. 275298944Sobrien 275319370Spst */ 275419370Spst 275519370Spststatic void 275698944Sobrienscan_compilation_units (char *thisdie, char *enddie, file_ptr dbfoff, 275798944Sobrien file_ptr lnoffset, struct objfile *objfile) 275819370Spst{ 275919370Spst char *nextdie; 276019370Spst struct dieinfo di; 276119370Spst struct partial_symtab *pst; 276219370Spst int culength; 276319370Spst int curoff; 276419370Spst file_ptr curlnoffset; 276519370Spst 276619370Spst while (thisdie < enddie) 276719370Spst { 276819370Spst basicdieinfo (&di, thisdie, objfile); 276919370Spst if (di.die_length < SIZEOF_DIE_LENGTH) 277019370Spst { 277119370Spst break; 277219370Spst } 277319370Spst else if (di.die_tag != TAG_compile_unit) 277419370Spst { 277519370Spst nextdie = thisdie + di.die_length; 277619370Spst } 277719370Spst else 277819370Spst { 277919370Spst completedieinfo (&di, objfile); 278019370Spst set_cu_language (&di); 278119370Spst if (di.at_sibling != 0) 278219370Spst { 278319370Spst nextdie = dbbase + di.at_sibling - dbroff; 278419370Spst } 278519370Spst else 278619370Spst { 278719370Spst nextdie = thisdie + di.die_length; 278819370Spst } 278919370Spst curoff = thisdie - dbbase; 279019370Spst culength = nextdie - thisdie; 279119370Spst curlnoffset = di.has_at_stmt_list ? lnoffset + di.at_stmt_list : 0; 279219370Spst 279319370Spst /* First allocate a new partial symbol table structure */ 279419370Spst 279519370Spst pst = start_psymtab_common (objfile, base_section_offsets, 279619370Spst di.at_name, di.at_low_pc, 279798944Sobrien objfile->global_psymbols.next, 279898944Sobrien objfile->static_psymbols.next); 279919370Spst 280098944Sobrien pst->texthigh = di.at_high_pc; 280198944Sobrien pst->read_symtab_private = (char *) 2802130803Smarcel obstack_alloc (&objfile->objfile_obstack, 280398944Sobrien sizeof (struct dwfinfo)); 280419370Spst DBFOFF (pst) = dbfoff; 280519370Spst DBROFF (pst) = curoff; 280619370Spst DBLENGTH (pst) = culength; 280798944Sobrien LNFOFF (pst) = curlnoffset; 280898944Sobrien pst->read_symtab = dwarf_psymtab_to_symtab; 280919370Spst 281019370Spst /* Now look for partial symbols */ 281119370Spst 281219370Spst scan_partial_symbols (thisdie + di.die_length, nextdie, objfile); 281319370Spst 281498944Sobrien pst->n_global_syms = objfile->global_psymbols.next - 281598944Sobrien (objfile->global_psymbols.list + pst->globals_offset); 281698944Sobrien pst->n_static_syms = objfile->static_psymbols.next - 281798944Sobrien (objfile->static_psymbols.list + pst->statics_offset); 281819370Spst sort_pst_symbols (pst); 281919370Spst /* If there is already a psymtab or symtab for a file of this name, 282019370Spst remove it. (If there is a symtab, more drastic things also 282119370Spst happen.) This happens in VxWorks. */ 282298944Sobrien free_named_symtabs (pst->filename); 282319370Spst } 282498944Sobrien thisdie = nextdie; 282519370Spst } 282619370Spst} 282719370Spst 282819370Spst/* 282919370Spst 283098944Sobrien LOCAL FUNCTION 283119370Spst 283298944Sobrien new_symbol -- make a symbol table entry for a new symbol 283319370Spst 283498944Sobrien SYNOPSIS 283519370Spst 283698944Sobrien static struct symbol *new_symbol (struct dieinfo *dip, 283798944Sobrien struct objfile *objfile) 283819370Spst 283998944Sobrien DESCRIPTION 284019370Spst 284198944Sobrien Given a pointer to a DWARF information entry, figure out if we need 284298944Sobrien to make a symbol table entry for it, and if so, create a new entry 284398944Sobrien and return a pointer to it. 284419370Spst */ 284519370Spst 284619370Spststatic struct symbol * 284798944Sobriennew_symbol (struct dieinfo *dip, struct objfile *objfile) 284819370Spst{ 284919370Spst struct symbol *sym = NULL; 285098944Sobrien 285198944Sobrien if (dip->at_name != NULL) 285219370Spst { 2853130803Smarcel sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, 285419370Spst sizeof (struct symbol)); 285519370Spst OBJSTAT (objfile, n_syms++); 285619370Spst memset (sym, 0, sizeof (struct symbol)); 285719370Spst /* default assumptions */ 2858130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 285919370Spst SYMBOL_CLASS (sym) = LOC_STATIC; 286019370Spst SYMBOL_TYPE (sym) = decode_die_type (dip); 286119370Spst 286219370Spst /* If this symbol is from a C++ compilation, then attempt to cache the 286398944Sobrien demangled form for future reference. This is a typical time versus 286498944Sobrien space tradeoff, that was decided in favor of time because it sped up 286598944Sobrien C++ symbol lookups by a factor of about 20. */ 286619370Spst 286719370Spst SYMBOL_LANGUAGE (sym) = cu_language; 2868130803Smarcel SYMBOL_SET_NAMES (sym, dip->at_name, strlen (dip->at_name), objfile); 286998944Sobrien switch (dip->die_tag) 287019370Spst { 287119370Spst case TAG_label: 287298944Sobrien SYMBOL_VALUE_ADDRESS (sym) = dip->at_low_pc; 287319370Spst SYMBOL_CLASS (sym) = LOC_LABEL; 287419370Spst break; 287519370Spst case TAG_global_subroutine: 287619370Spst case TAG_subroutine: 287798944Sobrien SYMBOL_VALUE_ADDRESS (sym) = dip->at_low_pc; 287819370Spst SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym)); 287998944Sobrien if (dip->at_prototyped) 288046283Sdfr TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED; 288119370Spst SYMBOL_CLASS (sym) = LOC_BLOCK; 288298944Sobrien if (dip->die_tag == TAG_global_subroutine) 288319370Spst { 288419370Spst add_symbol_to_list (sym, &global_symbols); 288519370Spst } 288619370Spst else 288719370Spst { 288819370Spst add_symbol_to_list (sym, list_in_scope); 288919370Spst } 289019370Spst break; 289119370Spst case TAG_global_variable: 289298944Sobrien if (dip->at_location != NULL) 289319370Spst { 289446283Sdfr SYMBOL_VALUE_ADDRESS (sym) = locval (dip); 289519370Spst add_symbol_to_list (sym, &global_symbols); 289619370Spst SYMBOL_CLASS (sym) = LOC_STATIC; 289719370Spst SYMBOL_VALUE (sym) += baseaddr; 289819370Spst } 289919370Spst break; 290019370Spst case TAG_local_variable: 290198944Sobrien if (dip->at_location != NULL) 290219370Spst { 290346283Sdfr int loc = locval (dip); 290498944Sobrien if (dip->optimized_out) 290519370Spst { 290619370Spst SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; 290719370Spst } 290898944Sobrien else if (dip->isreg) 290919370Spst { 291019370Spst SYMBOL_CLASS (sym) = LOC_REGISTER; 291119370Spst } 291298944Sobrien else if (dip->offreg) 291319370Spst { 291419370Spst SYMBOL_CLASS (sym) = LOC_BASEREG; 291598944Sobrien SYMBOL_BASEREG (sym) = dip->basereg; 291619370Spst } 291719370Spst else 291819370Spst { 291919370Spst SYMBOL_CLASS (sym) = LOC_STATIC; 292019370Spst SYMBOL_VALUE (sym) += baseaddr; 292119370Spst } 292246283Sdfr if (SYMBOL_CLASS (sym) == LOC_STATIC) 292346283Sdfr { 292446283Sdfr /* LOC_STATIC address class MUST use SYMBOL_VALUE_ADDRESS, 292546283Sdfr which may store to a bigger location than SYMBOL_VALUE. */ 292646283Sdfr SYMBOL_VALUE_ADDRESS (sym) = loc; 292746283Sdfr } 292846283Sdfr else 292946283Sdfr { 293046283Sdfr SYMBOL_VALUE (sym) = loc; 293146283Sdfr } 293246283Sdfr add_symbol_to_list (sym, list_in_scope); 293319370Spst } 293419370Spst break; 293519370Spst case TAG_formal_parameter: 293698944Sobrien if (dip->at_location != NULL) 293719370Spst { 293846283Sdfr SYMBOL_VALUE (sym) = locval (dip); 293919370Spst } 294019370Spst add_symbol_to_list (sym, list_in_scope); 294198944Sobrien if (dip->isreg) 294219370Spst { 294319370Spst SYMBOL_CLASS (sym) = LOC_REGPARM; 294419370Spst } 294598944Sobrien else if (dip->offreg) 294619370Spst { 294719370Spst SYMBOL_CLASS (sym) = LOC_BASEREG_ARG; 294898944Sobrien SYMBOL_BASEREG (sym) = dip->basereg; 294919370Spst } 295019370Spst else 295119370Spst { 295219370Spst SYMBOL_CLASS (sym) = LOC_ARG; 295319370Spst } 295419370Spst break; 295519370Spst case TAG_unspecified_parameters: 295619370Spst /* From varargs functions; gdb doesn't seem to have any interest in 295719370Spst this information, so just ignore it for now. (FIXME?) */ 295819370Spst break; 295919370Spst case TAG_class_type: 296019370Spst case TAG_structure_type: 296119370Spst case TAG_union_type: 296219370Spst case TAG_enumeration_type: 296319370Spst SYMBOL_CLASS (sym) = LOC_TYPEDEF; 2964130803Smarcel SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; 296519370Spst add_symbol_to_list (sym, list_in_scope); 296619370Spst break; 296719370Spst case TAG_typedef: 296819370Spst SYMBOL_CLASS (sym) = LOC_TYPEDEF; 2969130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 297019370Spst add_symbol_to_list (sym, list_in_scope); 297119370Spst break; 297219370Spst default: 297319370Spst /* Not a tag we recognize. Hopefully we aren't processing trash 297419370Spst data, but since we must specifically ignore things we don't 297519370Spst recognize, there is nothing else we should do at this point. */ 297619370Spst break; 297719370Spst } 297819370Spst } 297919370Spst return (sym); 298019370Spst} 298119370Spst 298219370Spst/* 298319370Spst 298498944Sobrien LOCAL FUNCTION 298519370Spst 298698944Sobrien synthesize_typedef -- make a symbol table entry for a "fake" typedef 298719370Spst 298898944Sobrien SYNOPSIS 298919370Spst 299098944Sobrien static void synthesize_typedef (struct dieinfo *dip, 299198944Sobrien struct objfile *objfile, 299298944Sobrien struct type *type); 299319370Spst 299498944Sobrien DESCRIPTION 299519370Spst 299698944Sobrien Given a pointer to a DWARF information entry, synthesize a typedef 299798944Sobrien for the name in the DIE, using the specified type. 299819370Spst 299998944Sobrien This is used for C++ class, structs, unions, and enumerations to 300098944Sobrien set up the tag name as a type. 300119370Spst 300219370Spst */ 300319370Spst 300419370Spststatic void 300598944Sobriensynthesize_typedef (struct dieinfo *dip, struct objfile *objfile, 300698944Sobrien struct type *type) 300719370Spst{ 300819370Spst struct symbol *sym = NULL; 300998944Sobrien 301098944Sobrien if (dip->at_name != NULL) 301119370Spst { 301219370Spst sym = (struct symbol *) 3013130803Smarcel obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol)); 301419370Spst OBJSTAT (objfile, n_syms++); 301519370Spst memset (sym, 0, sizeof (struct symbol)); 3016130803Smarcel DEPRECATED_SYMBOL_NAME (sym) = create_name (dip->at_name, 3017130803Smarcel &objfile->objfile_obstack); 301819370Spst SYMBOL_INIT_LANGUAGE_SPECIFIC (sym, cu_language); 301919370Spst SYMBOL_TYPE (sym) = type; 302019370Spst SYMBOL_CLASS (sym) = LOC_TYPEDEF; 3021130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 302219370Spst add_symbol_to_list (sym, list_in_scope); 302319370Spst } 302419370Spst} 302519370Spst 302619370Spst/* 302719370Spst 302898944Sobrien LOCAL FUNCTION 302919370Spst 303098944Sobrien decode_mod_fund_type -- decode a modified fundamental type 303119370Spst 303298944Sobrien SYNOPSIS 303319370Spst 303498944Sobrien static struct type *decode_mod_fund_type (char *typedata) 303519370Spst 303698944Sobrien DESCRIPTION 303719370Spst 303898944Sobrien Decode a block of data containing a modified fundamental 303998944Sobrien type specification. TYPEDATA is a pointer to the block, 304098944Sobrien which starts with a length containing the size of the rest 304198944Sobrien of the block. At the end of the block is a fundmental type 304298944Sobrien code value that gives the fundamental type. Everything 304398944Sobrien in between are type modifiers. 304419370Spst 304598944Sobrien We simply compute the number of modifiers and call the general 304698944Sobrien function decode_modified_type to do the actual work. 304798944Sobrien */ 304819370Spst 304919370Spststatic struct type * 305098944Sobriendecode_mod_fund_type (char *typedata) 305119370Spst{ 305219370Spst struct type *typep = NULL; 305319370Spst unsigned short modcount; 305419370Spst int nbytes; 305598944Sobrien 305619370Spst /* Get the total size of the block, exclusive of the size itself */ 305719370Spst 305819370Spst nbytes = attribute_size (AT_mod_fund_type); 305919370Spst modcount = target_to_host (typedata, nbytes, GET_UNSIGNED, current_objfile); 306019370Spst typedata += nbytes; 306119370Spst 306219370Spst /* Deduct the size of the fundamental type bytes at the end of the block. */ 306319370Spst 306419370Spst modcount -= attribute_size (AT_fund_type); 306519370Spst 306619370Spst /* Now do the actual decoding */ 306719370Spst 306819370Spst typep = decode_modified_type (typedata, modcount, AT_mod_fund_type); 306919370Spst return (typep); 307019370Spst} 307119370Spst 307219370Spst/* 307319370Spst 307498944Sobrien LOCAL FUNCTION 307519370Spst 307698944Sobrien decode_mod_u_d_type -- decode a modified user defined type 307719370Spst 307898944Sobrien SYNOPSIS 307919370Spst 308098944Sobrien static struct type *decode_mod_u_d_type (char *typedata) 308119370Spst 308298944Sobrien DESCRIPTION 308319370Spst 308498944Sobrien Decode a block of data containing a modified user defined 308598944Sobrien type specification. TYPEDATA is a pointer to the block, 308698944Sobrien which consists of a two byte length, containing the size 308798944Sobrien of the rest of the block. At the end of the block is a 308898944Sobrien four byte value that gives a reference to a user defined type. 308998944Sobrien Everything in between are type modifiers. 309019370Spst 309198944Sobrien We simply compute the number of modifiers and call the general 309298944Sobrien function decode_modified_type to do the actual work. 309398944Sobrien */ 309419370Spst 309519370Spststatic struct type * 309698944Sobriendecode_mod_u_d_type (char *typedata) 309719370Spst{ 309819370Spst struct type *typep = NULL; 309919370Spst unsigned short modcount; 310019370Spst int nbytes; 310198944Sobrien 310219370Spst /* Get the total size of the block, exclusive of the size itself */ 310319370Spst 310419370Spst nbytes = attribute_size (AT_mod_u_d_type); 310519370Spst modcount = target_to_host (typedata, nbytes, GET_UNSIGNED, current_objfile); 310619370Spst typedata += nbytes; 310719370Spst 310819370Spst /* Deduct the size of the reference type bytes at the end of the block. */ 310919370Spst 311019370Spst modcount -= attribute_size (AT_user_def_type); 311119370Spst 311219370Spst /* Now do the actual decoding */ 311319370Spst 311419370Spst typep = decode_modified_type (typedata, modcount, AT_mod_u_d_type); 311519370Spst return (typep); 311619370Spst} 311719370Spst 311819370Spst/* 311919370Spst 312098944Sobrien LOCAL FUNCTION 312119370Spst 312298944Sobrien decode_modified_type -- decode modified user or fundamental type 312319370Spst 312498944Sobrien SYNOPSIS 312519370Spst 312698944Sobrien static struct type *decode_modified_type (char *modifiers, 312798944Sobrien unsigned short modcount, int mtype) 312819370Spst 312998944Sobrien DESCRIPTION 313019370Spst 313198944Sobrien Decode a modified type, either a modified fundamental type or 313298944Sobrien a modified user defined type. MODIFIERS is a pointer to the 313398944Sobrien block of bytes that define MODCOUNT modifiers. Immediately 313498944Sobrien following the last modifier is a short containing the fundamental 313598944Sobrien type or a long containing the reference to the user defined 313698944Sobrien type. Which one is determined by MTYPE, which is either 313798944Sobrien AT_mod_fund_type or AT_mod_u_d_type to indicate what modified 313898944Sobrien type we are generating. 313919370Spst 314098944Sobrien We call ourself recursively to generate each modified type,` 314198944Sobrien until MODCOUNT reaches zero, at which point we have consumed 314298944Sobrien all the modifiers and generate either the fundamental type or 314398944Sobrien user defined type. When the recursion unwinds, each modifier 314498944Sobrien is applied in turn to generate the full modified type. 314519370Spst 314698944Sobrien NOTES 314719370Spst 314898944Sobrien If we find a modifier that we don't recognize, and it is not one 314998944Sobrien of those reserved for application specific use, then we issue a 315098944Sobrien warning and simply ignore the modifier. 315119370Spst 315298944Sobrien BUGS 315319370Spst 315498944Sobrien We currently ignore MOD_const and MOD_volatile. (FIXME) 315519370Spst 315619370Spst */ 315719370Spst 315819370Spststatic struct type * 315998944Sobriendecode_modified_type (char *modifiers, unsigned int modcount, int mtype) 316019370Spst{ 316119370Spst struct type *typep = NULL; 316219370Spst unsigned short fundtype; 316319370Spst DIE_REF die_ref; 316419370Spst char modifier; 316519370Spst int nbytes; 316698944Sobrien 316719370Spst if (modcount == 0) 316819370Spst { 316919370Spst switch (mtype) 317019370Spst { 317119370Spst case AT_mod_fund_type: 317219370Spst nbytes = attribute_size (AT_fund_type); 317319370Spst fundtype = target_to_host (modifiers, nbytes, GET_UNSIGNED, 317419370Spst current_objfile); 317519370Spst typep = decode_fund_type (fundtype); 317619370Spst break; 317719370Spst case AT_mod_u_d_type: 317819370Spst nbytes = attribute_size (AT_user_def_type); 317919370Spst die_ref = target_to_host (modifiers, nbytes, GET_UNSIGNED, 318019370Spst current_objfile); 3181130803Smarcel typep = lookup_utype (die_ref); 3182130803Smarcel if (typep == NULL) 318319370Spst { 318419370Spst typep = alloc_utype (die_ref, NULL); 318519370Spst } 318619370Spst break; 318719370Spst default: 3188130803Smarcel complaint (&symfile_complaints, 3189130803Smarcel "DIE @ 0x%x \"%s\", botched modified type decoding (mtype 0x%x)", 3190130803Smarcel DIE_ID, DIE_NAME, mtype); 319119370Spst typep = dwarf_fundamental_type (current_objfile, FT_INTEGER); 319219370Spst break; 319319370Spst } 319419370Spst } 319519370Spst else 319619370Spst { 319719370Spst modifier = *modifiers++; 319819370Spst typep = decode_modified_type (modifiers, --modcount, mtype); 319919370Spst switch (modifier) 320019370Spst { 320198944Sobrien case MOD_pointer_to: 320298944Sobrien typep = lookup_pointer_type (typep); 320398944Sobrien break; 320498944Sobrien case MOD_reference_to: 320598944Sobrien typep = lookup_reference_type (typep); 320698944Sobrien break; 320798944Sobrien case MOD_const: 3208130803Smarcel complaint (&symfile_complaints, 3209130803Smarcel "DIE @ 0x%x \"%s\", type modifier 'const' ignored", DIE_ID, 3210130803Smarcel DIE_NAME); /* FIXME */ 321198944Sobrien break; 321298944Sobrien case MOD_volatile: 3213130803Smarcel complaint (&symfile_complaints, 3214130803Smarcel "DIE @ 0x%x \"%s\", type modifier 'volatile' ignored", 3215130803Smarcel DIE_ID, DIE_NAME); /* FIXME */ 321698944Sobrien break; 321798944Sobrien default: 3218130803Smarcel if (!(MOD_lo_user <= (unsigned char) modifier)) 3219130803Smarcel#if 0 3220130803Smarcel/* This part of the test would always be true, and it triggers a compiler 3221130803Smarcel warning. */ 322298944Sobrien && (unsigned char) modifier <= MOD_hi_user)) 3223130803Smarcel#endif 322498944Sobrien { 3225130803Smarcel complaint (&symfile_complaints, 3226130803Smarcel "DIE @ 0x%x \"%s\", unknown type modifier %u", DIE_ID, 3227130803Smarcel DIE_NAME, modifier); 322898944Sobrien } 322998944Sobrien break; 323019370Spst } 323119370Spst } 323219370Spst return (typep); 323319370Spst} 323419370Spst 323519370Spst/* 323619370Spst 323798944Sobrien LOCAL FUNCTION 323819370Spst 323998944Sobrien decode_fund_type -- translate basic DWARF type to gdb base type 324019370Spst 324198944Sobrien DESCRIPTION 324219370Spst 324398944Sobrien Given an integer that is one of the fundamental DWARF types, 324498944Sobrien translate it to one of the basic internal gdb types and return 324598944Sobrien a pointer to the appropriate gdb type (a "struct type *"). 324619370Spst 324798944Sobrien NOTES 324819370Spst 324998944Sobrien For robustness, if we are asked to translate a fundamental 325098944Sobrien type that we are unprepared to deal with, we return int so 325198944Sobrien callers can always depend upon a valid type being returned, 325298944Sobrien and so gdb may at least do something reasonable by default. 325398944Sobrien If the type is not in the range of those types defined as 325498944Sobrien application specific types, we also issue a warning. 325598944Sobrien */ 325619370Spst 325719370Spststatic struct type * 325898944Sobriendecode_fund_type (unsigned int fundtype) 325919370Spst{ 326019370Spst struct type *typep = NULL; 326198944Sobrien 326219370Spst switch (fundtype) 326319370Spst { 326419370Spst 326519370Spst case FT_void: 326619370Spst typep = dwarf_fundamental_type (current_objfile, FT_VOID); 326719370Spst break; 326898944Sobrien 326919370Spst case FT_boolean: /* Was FT_set in AT&T version */ 327019370Spst typep = dwarf_fundamental_type (current_objfile, FT_BOOLEAN); 327119370Spst break; 327219370Spst 327319370Spst case FT_pointer: /* (void *) */ 327419370Spst typep = dwarf_fundamental_type (current_objfile, FT_VOID); 327519370Spst typep = lookup_pointer_type (typep); 327619370Spst break; 327798944Sobrien 327819370Spst case FT_char: 327919370Spst typep = dwarf_fundamental_type (current_objfile, FT_CHAR); 328019370Spst break; 328198944Sobrien 328219370Spst case FT_signed_char: 328319370Spst typep = dwarf_fundamental_type (current_objfile, FT_SIGNED_CHAR); 328419370Spst break; 328519370Spst 328619370Spst case FT_unsigned_char: 328719370Spst typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_CHAR); 328819370Spst break; 328998944Sobrien 329019370Spst case FT_short: 329119370Spst typep = dwarf_fundamental_type (current_objfile, FT_SHORT); 329219370Spst break; 329319370Spst 329419370Spst case FT_signed_short: 329519370Spst typep = dwarf_fundamental_type (current_objfile, FT_SIGNED_SHORT); 329619370Spst break; 329798944Sobrien 329819370Spst case FT_unsigned_short: 329919370Spst typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_SHORT); 330019370Spst break; 330198944Sobrien 330219370Spst case FT_integer: 330319370Spst typep = dwarf_fundamental_type (current_objfile, FT_INTEGER); 330419370Spst break; 330519370Spst 330619370Spst case FT_signed_integer: 330719370Spst typep = dwarf_fundamental_type (current_objfile, FT_SIGNED_INTEGER); 330819370Spst break; 330998944Sobrien 331019370Spst case FT_unsigned_integer: 331119370Spst typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER); 331219370Spst break; 331398944Sobrien 331419370Spst case FT_long: 331519370Spst typep = dwarf_fundamental_type (current_objfile, FT_LONG); 331619370Spst break; 331719370Spst 331819370Spst case FT_signed_long: 331919370Spst typep = dwarf_fundamental_type (current_objfile, FT_SIGNED_LONG); 332019370Spst break; 332198944Sobrien 332219370Spst case FT_unsigned_long: 332319370Spst typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_LONG); 332419370Spst break; 332598944Sobrien 332619370Spst case FT_long_long: 332719370Spst typep = dwarf_fundamental_type (current_objfile, FT_LONG_LONG); 332819370Spst break; 332919370Spst 333019370Spst case FT_signed_long_long: 333119370Spst typep = dwarf_fundamental_type (current_objfile, FT_SIGNED_LONG_LONG); 333219370Spst break; 333319370Spst 333419370Spst case FT_unsigned_long_long: 333519370Spst typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_LONG_LONG); 333619370Spst break; 333719370Spst 333819370Spst case FT_float: 333919370Spst typep = dwarf_fundamental_type (current_objfile, FT_FLOAT); 334019370Spst break; 334198944Sobrien 334219370Spst case FT_dbl_prec_float: 334319370Spst typep = dwarf_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT); 334419370Spst break; 334598944Sobrien 334619370Spst case FT_ext_prec_float: 334719370Spst typep = dwarf_fundamental_type (current_objfile, FT_EXT_PREC_FLOAT); 334819370Spst break; 334998944Sobrien 335019370Spst case FT_complex: 335119370Spst typep = dwarf_fundamental_type (current_objfile, FT_COMPLEX); 335219370Spst break; 335398944Sobrien 335419370Spst case FT_dbl_prec_complex: 335519370Spst typep = dwarf_fundamental_type (current_objfile, FT_DBL_PREC_COMPLEX); 335619370Spst break; 335798944Sobrien 335819370Spst case FT_ext_prec_complex: 335919370Spst typep = dwarf_fundamental_type (current_objfile, FT_EXT_PREC_COMPLEX); 336019370Spst break; 336198944Sobrien 336219370Spst } 336319370Spst 336419370Spst if (typep == NULL) 336519370Spst { 336619370Spst typep = dwarf_fundamental_type (current_objfile, FT_INTEGER); 336719370Spst if (!(FT_lo_user <= fundtype && fundtype <= FT_hi_user)) 336819370Spst { 3369130803Smarcel complaint (&symfile_complaints, 3370130803Smarcel "DIE @ 0x%x \"%s\", unexpected fundamental type 0x%x", 3371130803Smarcel DIE_ID, DIE_NAME, fundtype); 337219370Spst } 337319370Spst } 337498944Sobrien 337519370Spst return (typep); 337619370Spst} 337719370Spst 337819370Spst/* 337919370Spst 338098944Sobrien LOCAL FUNCTION 338119370Spst 338298944Sobrien create_name -- allocate a fresh copy of a string on an obstack 338319370Spst 338498944Sobrien DESCRIPTION 338519370Spst 338698944Sobrien Given a pointer to a string and a pointer to an obstack, allocates 338798944Sobrien a fresh copy of the string on the specified obstack. 338819370Spst 338998944Sobrien */ 339019370Spst 339119370Spststatic char * 339298944Sobriencreate_name (char *name, struct obstack *obstackp) 339319370Spst{ 339419370Spst int length; 339519370Spst char *newname; 339619370Spst 339719370Spst length = strlen (name) + 1; 339819370Spst newname = (char *) obstack_alloc (obstackp, length); 339919370Spst strcpy (newname, name); 340019370Spst return (newname); 340119370Spst} 340219370Spst 340319370Spst/* 340419370Spst 340598944Sobrien LOCAL FUNCTION 340619370Spst 340798944Sobrien basicdieinfo -- extract the minimal die info from raw die data 340819370Spst 340998944Sobrien SYNOPSIS 341019370Spst 341198944Sobrien void basicdieinfo (char *diep, struct dieinfo *dip, 341298944Sobrien struct objfile *objfile) 341319370Spst 341498944Sobrien DESCRIPTION 341519370Spst 341698944Sobrien Given a pointer to raw DIE data, and a pointer to an instance of a 341798944Sobrien die info structure, this function extracts the basic information 341898944Sobrien from the DIE data required to continue processing this DIE, along 341998944Sobrien with some bookkeeping information about the DIE. 342019370Spst 342198944Sobrien The information we absolutely must have includes the DIE tag, 342298944Sobrien and the DIE length. If we need the sibling reference, then we 342398944Sobrien will have to call completedieinfo() to process all the remaining 342498944Sobrien DIE information. 342519370Spst 342698944Sobrien Note that since there is no guarantee that the data is properly 342798944Sobrien aligned in memory for the type of access required (indirection 342898944Sobrien through anything other than a char pointer), and there is no 342998944Sobrien guarantee that it is in the same byte order as the gdb host, 343098944Sobrien we call a function which deals with both alignment and byte 343198944Sobrien swapping issues. Possibly inefficient, but quite portable. 343219370Spst 343398944Sobrien We also take care of some other basic things at this point, such 343498944Sobrien as ensuring that the instance of the die info structure starts 343598944Sobrien out completely zero'd and that curdie is initialized for use 343698944Sobrien in error reporting if we have a problem with the current die. 343719370Spst 343898944Sobrien NOTES 343919370Spst 344098944Sobrien All DIE's must have at least a valid length, thus the minimum 344198944Sobrien DIE size is SIZEOF_DIE_LENGTH. In order to have a valid tag, the 344298944Sobrien DIE size must be at least SIZEOF_DIE_TAG larger, otherwise they 344398944Sobrien are forced to be TAG_padding DIES. 344419370Spst 344598944Sobrien Padding DIES must be at least SIZEOF_DIE_LENGTH in length, implying 344698944Sobrien that if a padding DIE is used for alignment and the amount needed is 344798944Sobrien less than SIZEOF_DIE_LENGTH, then the padding DIE has to be big 344898944Sobrien enough to align to the next alignment boundry. 344919370Spst 345098944Sobrien We do some basic sanity checking here, such as verifying that the 345198944Sobrien length of the die would not cause it to overrun the recorded end of 345298944Sobrien the buffer holding the DIE info. If we find a DIE that is either 345398944Sobrien too small or too large, we force it's length to zero which should 345498944Sobrien cause the caller to take appropriate action. 345519370Spst */ 345619370Spst 345719370Spststatic void 345898944Sobrienbasicdieinfo (struct dieinfo *dip, char *diep, struct objfile *objfile) 345919370Spst{ 346019370Spst curdie = dip; 346119370Spst memset (dip, 0, sizeof (struct dieinfo)); 346298944Sobrien dip->die = diep; 346398944Sobrien dip->die_ref = dbroff + (diep - dbbase); 346498944Sobrien dip->die_length = target_to_host (diep, SIZEOF_DIE_LENGTH, GET_UNSIGNED, 346598944Sobrien objfile); 346698944Sobrien if ((dip->die_length < SIZEOF_DIE_LENGTH) || 346798944Sobrien ((diep + dip->die_length) > (dbbase + dbsize))) 346819370Spst { 3469130803Smarcel complaint (&symfile_complaints, 3470130803Smarcel "DIE @ 0x%x \"%s\", malformed DIE, bad length (%ld bytes)", 3471130803Smarcel DIE_ID, DIE_NAME, dip->die_length); 347298944Sobrien dip->die_length = 0; 347319370Spst } 347498944Sobrien else if (dip->die_length < (SIZEOF_DIE_LENGTH + SIZEOF_DIE_TAG)) 347519370Spst { 347698944Sobrien dip->die_tag = TAG_padding; 347719370Spst } 347819370Spst else 347919370Spst { 348019370Spst diep += SIZEOF_DIE_LENGTH; 348198944Sobrien dip->die_tag = target_to_host (diep, SIZEOF_DIE_TAG, GET_UNSIGNED, 348298944Sobrien objfile); 348319370Spst } 348419370Spst} 348519370Spst 348619370Spst/* 348719370Spst 348898944Sobrien LOCAL FUNCTION 348919370Spst 349098944Sobrien completedieinfo -- finish reading the information for a given DIE 349119370Spst 349298944Sobrien SYNOPSIS 349319370Spst 349498944Sobrien void completedieinfo (struct dieinfo *dip, struct objfile *objfile) 349519370Spst 349698944Sobrien DESCRIPTION 349719370Spst 349898944Sobrien Given a pointer to an already partially initialized die info structure, 349998944Sobrien scan the raw DIE data and finish filling in the die info structure 350098944Sobrien from the various attributes found. 350119370Spst 350298944Sobrien Note that since there is no guarantee that the data is properly 350398944Sobrien aligned in memory for the type of access required (indirection 350498944Sobrien through anything other than a char pointer), and there is no 350598944Sobrien guarantee that it is in the same byte order as the gdb host, 350698944Sobrien we call a function which deals with both alignment and byte 350798944Sobrien swapping issues. Possibly inefficient, but quite portable. 350819370Spst 350998944Sobrien NOTES 351019370Spst 351198944Sobrien Each time we are called, we increment the diecount variable, which 351298944Sobrien keeps an approximate count of the number of dies processed for 351398944Sobrien each compilation unit. This information is presented to the user 351498944Sobrien if the info_verbose flag is set. 351598944Sobrien 351619370Spst */ 351719370Spst 351819370Spststatic void 351998944Sobriencompletedieinfo (struct dieinfo *dip, struct objfile *objfile) 352019370Spst{ 352119370Spst char *diep; /* Current pointer into raw DIE data */ 352219370Spst char *end; /* Terminate DIE scan here */ 352319370Spst unsigned short attr; /* Current attribute being scanned */ 352419370Spst unsigned short form; /* Form of the attribute */ 352519370Spst int nbytes; /* Size of next field to read */ 352698944Sobrien 352719370Spst diecount++; 352898944Sobrien diep = dip->die; 352998944Sobrien end = diep + dip->die_length; 353019370Spst diep += SIZEOF_DIE_LENGTH + SIZEOF_DIE_TAG; 353119370Spst while (diep < end) 353219370Spst { 353319370Spst attr = target_to_host (diep, SIZEOF_ATTRIBUTE, GET_UNSIGNED, objfile); 353419370Spst diep += SIZEOF_ATTRIBUTE; 3535130803Smarcel nbytes = attribute_size (attr); 3536130803Smarcel if (nbytes == -1) 353719370Spst { 3538130803Smarcel complaint (&symfile_complaints, 3539130803Smarcel "DIE @ 0x%x \"%s\", unknown attribute length, skipped remaining attributes", 3540130803Smarcel DIE_ID, DIE_NAME); 354119370Spst diep = end; 354219370Spst continue; 354319370Spst } 354419370Spst switch (attr) 354519370Spst { 354619370Spst case AT_fund_type: 354798944Sobrien dip->at_fund_type = target_to_host (diep, nbytes, GET_UNSIGNED, 354898944Sobrien objfile); 354919370Spst break; 355019370Spst case AT_ordering: 355198944Sobrien dip->at_ordering = target_to_host (diep, nbytes, GET_UNSIGNED, 355298944Sobrien objfile); 355319370Spst break; 355419370Spst case AT_bit_offset: 355598944Sobrien dip->at_bit_offset = target_to_host (diep, nbytes, GET_UNSIGNED, 355698944Sobrien objfile); 355719370Spst break; 355819370Spst case AT_sibling: 355998944Sobrien dip->at_sibling = target_to_host (diep, nbytes, GET_UNSIGNED, 356098944Sobrien objfile); 356119370Spst break; 356219370Spst case AT_stmt_list: 356398944Sobrien dip->at_stmt_list = target_to_host (diep, nbytes, GET_UNSIGNED, 356498944Sobrien objfile); 356598944Sobrien dip->has_at_stmt_list = 1; 356619370Spst break; 356719370Spst case AT_low_pc: 356898944Sobrien dip->at_low_pc = target_to_host (diep, nbytes, GET_UNSIGNED, 356998944Sobrien objfile); 357098944Sobrien dip->at_low_pc += baseaddr; 357198944Sobrien dip->has_at_low_pc = 1; 357219370Spst break; 357319370Spst case AT_high_pc: 357498944Sobrien dip->at_high_pc = target_to_host (diep, nbytes, GET_UNSIGNED, 357598944Sobrien objfile); 357698944Sobrien dip->at_high_pc += baseaddr; 357719370Spst break; 357819370Spst case AT_language: 357998944Sobrien dip->at_language = target_to_host (diep, nbytes, GET_UNSIGNED, 358098944Sobrien objfile); 358119370Spst break; 358219370Spst case AT_user_def_type: 358398944Sobrien dip->at_user_def_type = target_to_host (diep, nbytes, 358498944Sobrien GET_UNSIGNED, objfile); 358519370Spst break; 358619370Spst case AT_byte_size: 358798944Sobrien dip->at_byte_size = target_to_host (diep, nbytes, GET_UNSIGNED, 358898944Sobrien objfile); 358998944Sobrien dip->has_at_byte_size = 1; 359019370Spst break; 359119370Spst case AT_bit_size: 359298944Sobrien dip->at_bit_size = target_to_host (diep, nbytes, GET_UNSIGNED, 359398944Sobrien objfile); 359419370Spst break; 359519370Spst case AT_member: 359698944Sobrien dip->at_member = target_to_host (diep, nbytes, GET_UNSIGNED, 359798944Sobrien objfile); 359819370Spst break; 359919370Spst case AT_discr: 360098944Sobrien dip->at_discr = target_to_host (diep, nbytes, GET_UNSIGNED, 360198944Sobrien objfile); 360219370Spst break; 360319370Spst case AT_location: 360498944Sobrien dip->at_location = diep; 360519370Spst break; 360619370Spst case AT_mod_fund_type: 360798944Sobrien dip->at_mod_fund_type = diep; 360819370Spst break; 360919370Spst case AT_subscr_data: 361098944Sobrien dip->at_subscr_data = diep; 361119370Spst break; 361219370Spst case AT_mod_u_d_type: 361398944Sobrien dip->at_mod_u_d_type = diep; 361419370Spst break; 361519370Spst case AT_element_list: 361698944Sobrien dip->at_element_list = diep; 361798944Sobrien dip->short_element_list = 0; 361819370Spst break; 361919370Spst case AT_short_element_list: 362098944Sobrien dip->at_element_list = diep; 362198944Sobrien dip->short_element_list = 1; 362219370Spst break; 362319370Spst case AT_discr_value: 362498944Sobrien dip->at_discr_value = diep; 362519370Spst break; 362619370Spst case AT_string_length: 362798944Sobrien dip->at_string_length = diep; 362819370Spst break; 362919370Spst case AT_name: 363098944Sobrien dip->at_name = diep; 363119370Spst break; 363219370Spst case AT_comp_dir: 363319370Spst /* For now, ignore any "hostname:" portion, since gdb doesn't 363419370Spst know how to deal with it. (FIXME). */ 363598944Sobrien dip->at_comp_dir = strrchr (diep, ':'); 363698944Sobrien if (dip->at_comp_dir != NULL) 363719370Spst { 363898944Sobrien dip->at_comp_dir++; 363919370Spst } 364019370Spst else 364119370Spst { 364298944Sobrien dip->at_comp_dir = diep; 364319370Spst } 364419370Spst break; 364519370Spst case AT_producer: 364698944Sobrien dip->at_producer = diep; 364719370Spst break; 364819370Spst case AT_start_scope: 364998944Sobrien dip->at_start_scope = target_to_host (diep, nbytes, GET_UNSIGNED, 365098944Sobrien objfile); 365119370Spst break; 365219370Spst case AT_stride_size: 365398944Sobrien dip->at_stride_size = target_to_host (diep, nbytes, GET_UNSIGNED, 365498944Sobrien objfile); 365519370Spst break; 365619370Spst case AT_src_info: 365798944Sobrien dip->at_src_info = target_to_host (diep, nbytes, GET_UNSIGNED, 365898944Sobrien objfile); 365919370Spst break; 366019370Spst case AT_prototyped: 366198944Sobrien dip->at_prototyped = diep; 366219370Spst break; 366319370Spst default: 366419370Spst /* Found an attribute that we are unprepared to handle. However 366519370Spst it is specifically one of the design goals of DWARF that 366619370Spst consumers should ignore unknown attributes. As long as the 366719370Spst form is one that we recognize (so we know how to skip it), 366819370Spst we can just ignore the unknown attribute. */ 366919370Spst break; 367019370Spst } 367119370Spst form = FORM_FROM_ATTR (attr); 367219370Spst switch (form) 367319370Spst { 367419370Spst case FORM_DATA2: 367519370Spst diep += 2; 367619370Spst break; 367719370Spst case FORM_DATA4: 367819370Spst case FORM_REF: 367919370Spst diep += 4; 368019370Spst break; 368119370Spst case FORM_DATA8: 368219370Spst diep += 8; 368319370Spst break; 368419370Spst case FORM_ADDR: 368519370Spst diep += TARGET_FT_POINTER_SIZE (objfile); 368619370Spst break; 368719370Spst case FORM_BLOCK2: 368819370Spst diep += 2 + target_to_host (diep, nbytes, GET_UNSIGNED, objfile); 368919370Spst break; 369019370Spst case FORM_BLOCK4: 369119370Spst diep += 4 + target_to_host (diep, nbytes, GET_UNSIGNED, objfile); 369219370Spst break; 369319370Spst case FORM_STRING: 369419370Spst diep += strlen (diep) + 1; 369519370Spst break; 369619370Spst default: 3697130803Smarcel unknown_attribute_form_complaint (DIE_ID, DIE_NAME, form); 369819370Spst diep = end; 369919370Spst break; 370019370Spst } 370119370Spst } 370219370Spst} 370319370Spst 370419370Spst/* 370519370Spst 370698944Sobrien LOCAL FUNCTION 370719370Spst 370898944Sobrien target_to_host -- swap in target data to host 370919370Spst 371098944Sobrien SYNOPSIS 371119370Spst 371298944Sobrien target_to_host (char *from, int nbytes, int signextend, 371398944Sobrien struct objfile *objfile) 371419370Spst 371598944Sobrien DESCRIPTION 371619370Spst 371798944Sobrien Given pointer to data in target format in FROM, a byte count for 371898944Sobrien the size of the data in NBYTES, a flag indicating whether or not 371998944Sobrien the data is signed in SIGNEXTEND, and a pointer to the current 372098944Sobrien objfile in OBJFILE, convert the data to host format and return 372198944Sobrien the converted value. 372219370Spst 372398944Sobrien NOTES 372419370Spst 372598944Sobrien FIXME: If we read data that is known to be signed, and expect to 372698944Sobrien use it as signed data, then we need to explicitly sign extend the 372798944Sobrien result until the bfd library is able to do this for us. 372819370Spst 372998944Sobrien FIXME: Would a 32 bit target ever need an 8 byte result? 373019370Spst 373119370Spst */ 373219370Spst 373319370Spststatic CORE_ADDR 373498944Sobrientarget_to_host (char *from, int nbytes, int signextend, /* FIXME: Unused */ 373598944Sobrien struct objfile *objfile) 373619370Spst{ 373719370Spst CORE_ADDR rtnval; 373819370Spst 373919370Spst switch (nbytes) 374019370Spst { 374198944Sobrien case 8: 374298944Sobrien rtnval = bfd_get_64 (objfile->obfd, (bfd_byte *) from); 374398944Sobrien break; 374498944Sobrien case 4: 374598944Sobrien rtnval = bfd_get_32 (objfile->obfd, (bfd_byte *) from); 374698944Sobrien break; 374798944Sobrien case 2: 374898944Sobrien rtnval = bfd_get_16 (objfile->obfd, (bfd_byte *) from); 374998944Sobrien break; 375098944Sobrien case 1: 375198944Sobrien rtnval = bfd_get_8 (objfile->obfd, (bfd_byte *) from); 375298944Sobrien break; 375398944Sobrien default: 3754130803Smarcel complaint (&symfile_complaints, 3755130803Smarcel "DIE @ 0x%x \"%s\", no bfd support for %d byte data object", 3756130803Smarcel DIE_ID, DIE_NAME, nbytes); 375798944Sobrien rtnval = 0; 375898944Sobrien break; 375919370Spst } 376019370Spst return (rtnval); 376119370Spst} 376219370Spst 376319370Spst/* 376419370Spst 376598944Sobrien LOCAL FUNCTION 376619370Spst 376798944Sobrien attribute_size -- compute size of data for a DWARF attribute 376819370Spst 376998944Sobrien SYNOPSIS 377019370Spst 377198944Sobrien static int attribute_size (unsigned int attr) 377219370Spst 377398944Sobrien DESCRIPTION 377419370Spst 377598944Sobrien Given a DWARF attribute in ATTR, compute the size of the first 377698944Sobrien piece of data associated with this attribute and return that 377798944Sobrien size. 377819370Spst 377998944Sobrien Returns -1 for unrecognized attributes. 378019370Spst 378119370Spst */ 378219370Spst 378319370Spststatic int 378498944Sobrienattribute_size (unsigned int attr) 378519370Spst{ 378619370Spst int nbytes; /* Size of next data for this attribute */ 378719370Spst unsigned short form; /* Form of the attribute */ 378819370Spst 378919370Spst form = FORM_FROM_ATTR (attr); 379019370Spst switch (form) 379119370Spst { 379298944Sobrien case FORM_STRING: /* A variable length field is next */ 379398944Sobrien nbytes = 0; 379498944Sobrien break; 379598944Sobrien case FORM_DATA2: /* Next 2 byte field is the data itself */ 379698944Sobrien case FORM_BLOCK2: /* Next 2 byte field is a block length */ 379798944Sobrien nbytes = 2; 379898944Sobrien break; 379998944Sobrien case FORM_DATA4: /* Next 4 byte field is the data itself */ 380098944Sobrien case FORM_BLOCK4: /* Next 4 byte field is a block length */ 380198944Sobrien case FORM_REF: /* Next 4 byte field is a DIE offset */ 380298944Sobrien nbytes = 4; 380398944Sobrien break; 380498944Sobrien case FORM_DATA8: /* Next 8 byte field is the data itself */ 380598944Sobrien nbytes = 8; 380698944Sobrien break; 380798944Sobrien case FORM_ADDR: /* Next field size is target sizeof(void *) */ 380898944Sobrien nbytes = TARGET_FT_POINTER_SIZE (objfile); 380998944Sobrien break; 381098944Sobrien default: 3811130803Smarcel unknown_attribute_form_complaint (DIE_ID, DIE_NAME, form); 381298944Sobrien nbytes = -1; 381398944Sobrien break; 381498944Sobrien } 381519370Spst return (nbytes); 381619370Spst} 3817