146283Sdfr/* DWARF 2 debugging format support for GDB. 2130803Smarcel Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 3130803Smarcel 2004 498944Sobrien Free Software Foundation, Inc. 546283Sdfr 646283Sdfr Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, 746283Sdfr Inc. with support from Florida State University (under contract 846283Sdfr with the Ada Joint Program Office), and Silicon Graphics, Inc. 946283Sdfr Initial contribution by Brent Benson, Harris Computer Systems, Inc., 1046283Sdfr based on Fred Fish's (Cygnus Support) implementation of DWARF 1 1146283Sdfr support in dwarfread.c 1246283Sdfr 1398944Sobrien This file is part of GDB. 1446283Sdfr 1598944Sobrien This program is free software; you can redistribute it and/or modify 1698944Sobrien it under the terms of the GNU General Public License as published by 1798944Sobrien the Free Software Foundation; either version 2 of the License, or (at 1898944Sobrien your option) any later version. 1946283Sdfr 2098944Sobrien This program is distributed in the hope that it will be useful, but 2198944Sobrien WITHOUT ANY WARRANTY; without even the implied warranty of 2298944Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 2398944Sobrien General Public License for more details. 2446283Sdfr 2598944Sobrien You should have received a copy of the GNU General Public License 2698944Sobrien along with this program; if not, write to the Free Software 2798944Sobrien Foundation, Inc., 59 Temple Place - Suite 330, 2898944Sobrien Boston, MA 02111-1307, USA. */ 2946283Sdfr 3046283Sdfr#include "defs.h" 3146283Sdfr#include "bfd.h" 3246283Sdfr#include "symtab.h" 3346283Sdfr#include "gdbtypes.h" 3446283Sdfr#include "objfiles.h" 3546283Sdfr#include "elf/dwarf2.h" 3646283Sdfr#include "buildsym.h" 3746283Sdfr#include "demangle.h" 3846283Sdfr#include "expression.h" 3998944Sobrien#include "filenames.h" /* for DOSish file names */ 40130803Smarcel#include "macrotab.h" 4146283Sdfr#include "language.h" 4246283Sdfr#include "complaints.h" 4398944Sobrien#include "bcache.h" 44130803Smarcel#include "dwarf2expr.h" 45130803Smarcel#include "dwarf2loc.h" 46130803Smarcel#include "cp-support.h" 47130803Smarcel 4846283Sdfr#include <fcntl.h> 4946283Sdfr#include "gdb_string.h" 5098944Sobrien#include "gdb_assert.h" 5146283Sdfr#include <sys/types.h> 5246283Sdfr 5398944Sobrien#ifndef DWARF2_REG_TO_REGNUM 5498944Sobrien#define DWARF2_REG_TO_REGNUM(REG) (REG) 5598944Sobrien#endif 5698944Sobrien 5798944Sobrien#if 0 5898944Sobrien/* .debug_info header for a compilation unit 5946283Sdfr Because of alignment constraints, this structure has padding and cannot 6046283Sdfr be mapped directly onto the beginning of the .debug_info section. */ 6146283Sdfrtypedef struct comp_unit_header 6246283Sdfr { 6346283Sdfr unsigned int length; /* length of the .debug_info 6446283Sdfr contribution */ 6546283Sdfr unsigned short version; /* version number -- 2 for DWARF 6646283Sdfr version 2 */ 6746283Sdfr unsigned int abbrev_offset; /* offset into .debug_abbrev section */ 6846283Sdfr unsigned char addr_size; /* byte size of an address -- 4 */ 6946283Sdfr } 7046283Sdfr_COMP_UNIT_HEADER; 7146283Sdfr#define _ACTUAL_COMP_UNIT_HEADER_SIZE 11 7298944Sobrien#endif 7346283Sdfr 7446283Sdfr/* .debug_pubnames header 7546283Sdfr Because of alignment constraints, this structure has padding and cannot 7646283Sdfr be mapped directly onto the beginning of the .debug_info section. */ 7746283Sdfrtypedef struct pubnames_header 7846283Sdfr { 7946283Sdfr unsigned int length; /* length of the .debug_pubnames 8046283Sdfr contribution */ 8146283Sdfr unsigned char version; /* version number -- 2 for DWARF 8246283Sdfr version 2 */ 8346283Sdfr unsigned int info_offset; /* offset into .debug_info section */ 8446283Sdfr unsigned int info_size; /* byte size of .debug_info section 8546283Sdfr portion */ 8646283Sdfr } 8746283Sdfr_PUBNAMES_HEADER; 8846283Sdfr#define _ACTUAL_PUBNAMES_HEADER_SIZE 13 8946283Sdfr 9046283Sdfr/* .debug_pubnames header 9146283Sdfr Because of alignment constraints, this structure has padding and cannot 9246283Sdfr be mapped directly onto the beginning of the .debug_info section. */ 9346283Sdfrtypedef struct aranges_header 9446283Sdfr { 9546283Sdfr unsigned int length; /* byte len of the .debug_aranges 9646283Sdfr contribution */ 9746283Sdfr unsigned short version; /* version number -- 2 for DWARF 9846283Sdfr version 2 */ 9946283Sdfr unsigned int info_offset; /* offset into .debug_info section */ 10046283Sdfr unsigned char addr_size; /* byte size of an address */ 10146283Sdfr unsigned char seg_size; /* byte size of segment descriptor */ 10246283Sdfr } 10346283Sdfr_ARANGES_HEADER; 10446283Sdfr#define _ACTUAL_ARANGES_HEADER_SIZE 12 10546283Sdfr 10646283Sdfr/* .debug_line statement program prologue 10746283Sdfr Because of alignment constraints, this structure has padding and cannot 10846283Sdfr be mapped directly onto the beginning of the .debug_info section. */ 10946283Sdfrtypedef struct statement_prologue 11046283Sdfr { 11146283Sdfr unsigned int total_length; /* byte length of the statement 11246283Sdfr information */ 11346283Sdfr unsigned short version; /* version number -- 2 for DWARF 11446283Sdfr version 2 */ 11546283Sdfr unsigned int prologue_length; /* # bytes between prologue & 11646283Sdfr stmt program */ 11746283Sdfr unsigned char minimum_instruction_length; /* byte size of 11846283Sdfr smallest instr */ 11946283Sdfr unsigned char default_is_stmt; /* initial value of is_stmt 12046283Sdfr register */ 12146283Sdfr char line_base; 12246283Sdfr unsigned char line_range; 12346283Sdfr unsigned char opcode_base; /* number assigned to first special 12446283Sdfr opcode */ 12546283Sdfr unsigned char *standard_opcode_lengths; 12646283Sdfr } 12746283Sdfr_STATEMENT_PROLOGUE; 12846283Sdfr 12946283Sdfr/* offsets and sizes of debugging sections */ 13046283Sdfr 13146283Sdfrstatic unsigned int dwarf_info_size; 13246283Sdfrstatic unsigned int dwarf_abbrev_size; 13346283Sdfrstatic unsigned int dwarf_line_size; 13446283Sdfrstatic unsigned int dwarf_pubnames_size; 13546283Sdfrstatic unsigned int dwarf_aranges_size; 13646283Sdfrstatic unsigned int dwarf_loc_size; 13746283Sdfrstatic unsigned int dwarf_macinfo_size; 13846283Sdfrstatic unsigned int dwarf_str_size; 139130803Smarcelstatic unsigned int dwarf_ranges_size; 14098944Sobrienunsigned int dwarf_frame_size; 14198944Sobrienunsigned int dwarf_eh_frame_size; 14246283Sdfr 143130803Smarcelstatic asection *dwarf_info_section; 144130803Smarcelstatic asection *dwarf_abbrev_section; 145130803Smarcelstatic asection *dwarf_line_section; 146130803Smarcelstatic asection *dwarf_pubnames_section; 147130803Smarcelstatic asection *dwarf_aranges_section; 148130803Smarcelstatic asection *dwarf_loc_section; 149130803Smarcelstatic asection *dwarf_macinfo_section; 150130803Smarcelstatic asection *dwarf_str_section; 151130803Smarcelstatic asection *dwarf_ranges_section; 152130803Smarcelasection *dwarf_frame_section; 153130803Smarcelasection *dwarf_eh_frame_section; 154130803Smarcel 15546283Sdfr/* names of the debugging sections */ 15646283Sdfr 15746283Sdfr#define INFO_SECTION ".debug_info" 15846283Sdfr#define ABBREV_SECTION ".debug_abbrev" 15946283Sdfr#define LINE_SECTION ".debug_line" 16046283Sdfr#define PUBNAMES_SECTION ".debug_pubnames" 16146283Sdfr#define ARANGES_SECTION ".debug_aranges" 16246283Sdfr#define LOC_SECTION ".debug_loc" 16346283Sdfr#define MACINFO_SECTION ".debug_macinfo" 16446283Sdfr#define STR_SECTION ".debug_str" 165130803Smarcel#define RANGES_SECTION ".debug_ranges" 16698944Sobrien#define FRAME_SECTION ".debug_frame" 16798944Sobrien#define EH_FRAME_SECTION ".eh_frame" 16846283Sdfr 16946283Sdfr/* local data types */ 17046283Sdfr 171130803Smarcel/* We hold several abbreviation tables in memory at the same time. */ 172130803Smarcel#ifndef ABBREV_HASH_SIZE 173130803Smarcel#define ABBREV_HASH_SIZE 121 174130803Smarcel#endif 175130803Smarcel 17698944Sobrien/* The data in a compilation unit header, after target2host 17798944Sobrien translation, looks like this. */ 17846283Sdfrstruct comp_unit_head 17946283Sdfr { 18098944Sobrien unsigned long length; 18146283Sdfr short version; 18246283Sdfr unsigned int abbrev_offset; 18346283Sdfr unsigned char addr_size; 18498944Sobrien unsigned char signed_addr_p; 18598944Sobrien unsigned int offset_size; /* size of file offsets; either 4 or 8 */ 18698944Sobrien unsigned int initial_length_size; /* size of the length field; either 18798944Sobrien 4 or 12 */ 188130803Smarcel 189130803Smarcel /* Offset to the first byte of this compilation unit header in the 190130803Smarcel * .debug_info section, for resolving relative reference dies. */ 191130803Smarcel 192130803Smarcel unsigned int offset; 193130803Smarcel 194130803Smarcel /* Pointer to this compilation unit header in the .debug_info 195130803Smarcel * section */ 196130803Smarcel 197130803Smarcel char *cu_head_ptr; 198130803Smarcel 199130803Smarcel /* Pointer to the first die of this compilatio unit. This will 200130803Smarcel * be the first byte following the compilation unit header. */ 201130803Smarcel 202130803Smarcel char *first_die_ptr; 203130803Smarcel 204130803Smarcel /* Pointer to the next compilation unit header in the program. */ 205130803Smarcel 206130803Smarcel struct comp_unit_head *next; 207130803Smarcel 208130803Smarcel /* DWARF abbreviation table associated with this compilation unit */ 209130803Smarcel 210130803Smarcel struct abbrev_info *dwarf2_abbrevs[ABBREV_HASH_SIZE]; 211130803Smarcel 212130803Smarcel /* Base address of this compilation unit. */ 213130803Smarcel 214130803Smarcel CORE_ADDR base_address; 215130803Smarcel 216130803Smarcel /* Non-zero if base_address has been set. */ 217130803Smarcel 218130803Smarcel int base_known; 21946283Sdfr }; 22046283Sdfr 221130803Smarcel/* Internal state when decoding a particular compilation unit. */ 222130803Smarcelstruct dwarf2_cu 223130803Smarcel{ 224130803Smarcel /* The objfile containing this compilation unit. */ 225130803Smarcel struct objfile *objfile; 226130803Smarcel 227130803Smarcel /* The header of the compilation unit. 228130803Smarcel 229130803Smarcel FIXME drow/2003-11-10: Some of the things from the comp_unit_head 230130803Smarcel should be moved to the dwarf2_cu structure; for instance the abbrevs 231130803Smarcel hash table. */ 232130803Smarcel struct comp_unit_head header; 233130803Smarcel 234130803Smarcel struct function_range *first_fn, *last_fn, *cached_fn; 235130803Smarcel 236130803Smarcel /* The language we are debugging. */ 237130803Smarcel enum language language; 238130803Smarcel const struct language_defn *language_defn; 239130803Smarcel 240130803Smarcel /* The generic symbol table building routines have separate lists for 241130803Smarcel file scope symbols and all all other scopes (local scopes). So 242130803Smarcel we need to select the right one to pass to add_symbol_to_list(). 243130803Smarcel We do it by keeping a pointer to the correct list in list_in_scope. 244130803Smarcel 245130803Smarcel FIXME: The original dwarf code just treated the file scope as the 246130803Smarcel first local scope, and all other local scopes as nested local 247130803Smarcel scopes, and worked fine. Check to see if we really need to 248130803Smarcel distinguish these in buildsym.c. */ 249130803Smarcel struct pending **list_in_scope; 250130803Smarcel 251130803Smarcel /* Maintain an array of referenced fundamental types for the current 252130803Smarcel compilation unit being read. For DWARF version 1, we have to construct 253130803Smarcel the fundamental types on the fly, since no information about the 254130803Smarcel fundamental types is supplied. Each such fundamental type is created by 255130803Smarcel calling a language dependent routine to create the type, and then a 256130803Smarcel pointer to that type is then placed in the array at the index specified 257130803Smarcel by it's FT_<TYPENAME> value. The array has a fixed size set by the 258130803Smarcel FT_NUM_MEMBERS compile time constant, which is the number of predefined 259130803Smarcel fundamental types gdb knows how to construct. */ 260130803Smarcel struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */ 261130803Smarcel}; 262130803Smarcel 263130803Smarcel/* The line number information for a compilation unit (found in the 264130803Smarcel .debug_line section) begins with a "statement program header", 265130803Smarcel which contains the following information. */ 266130803Smarcelstruct line_header 267130803Smarcel{ 268130803Smarcel unsigned int total_length; 269130803Smarcel unsigned short version; 270130803Smarcel unsigned int header_length; 271130803Smarcel unsigned char minimum_instruction_length; 272130803Smarcel unsigned char default_is_stmt; 273130803Smarcel int line_base; 274130803Smarcel unsigned char line_range; 275130803Smarcel unsigned char opcode_base; 276130803Smarcel 277130803Smarcel /* standard_opcode_lengths[i] is the number of operands for the 278130803Smarcel standard opcode whose value is i. This means that 279130803Smarcel standard_opcode_lengths[0] is unused, and the last meaningful 280130803Smarcel element is standard_opcode_lengths[opcode_base - 1]. */ 281130803Smarcel unsigned char *standard_opcode_lengths; 282130803Smarcel 283130803Smarcel /* The include_directories table. NOTE! These strings are not 284130803Smarcel allocated with xmalloc; instead, they are pointers into 285130803Smarcel debug_line_buffer. If you try to free them, `free' will get 286130803Smarcel indigestion. */ 287130803Smarcel unsigned int num_include_dirs, include_dirs_size; 288130803Smarcel char **include_dirs; 289130803Smarcel 290130803Smarcel /* The file_names table. NOTE! These strings are not allocated 291130803Smarcel with xmalloc; instead, they are pointers into debug_line_buffer. 292130803Smarcel Don't try to free them directly. */ 293130803Smarcel unsigned int num_file_names, file_names_size; 294130803Smarcel struct file_entry 29546283Sdfr { 296130803Smarcel char *name; 297130803Smarcel unsigned int dir_index; 298130803Smarcel unsigned int mod_time; 299130803Smarcel unsigned int length; 300130803Smarcel } *file_names; 30146283Sdfr 302130803Smarcel /* The start and end of the statement program following this 303130803Smarcel header. These point into dwarf_line_buffer. */ 304130803Smarcel char *statement_program_start, *statement_program_end; 305130803Smarcel}; 306130803Smarcel 30746283Sdfr/* When we construct a partial symbol table entry we only 30846283Sdfr need this much information. */ 30946283Sdfrstruct partial_die_info 31046283Sdfr { 31146283Sdfr enum dwarf_tag tag; 31246283Sdfr unsigned char has_children; 31346283Sdfr unsigned char is_external; 31446283Sdfr unsigned char is_declaration; 31546283Sdfr unsigned char has_type; 31646283Sdfr unsigned int offset; 31746283Sdfr unsigned int abbrev; 31846283Sdfr char *name; 31998944Sobrien int has_pc_info; 32046283Sdfr CORE_ADDR lowpc; 32146283Sdfr CORE_ADDR highpc; 32246283Sdfr struct dwarf_block *locdesc; 32346283Sdfr unsigned int language; 32446283Sdfr char *sibling; 32546283Sdfr }; 32646283Sdfr 32746283Sdfr/* This data structure holds the information of an abbrev. */ 32846283Sdfrstruct abbrev_info 32946283Sdfr { 33046283Sdfr unsigned int number; /* number identifying abbrev */ 33146283Sdfr enum dwarf_tag tag; /* dwarf tag */ 33246283Sdfr int has_children; /* boolean */ 33346283Sdfr unsigned int num_attrs; /* number of attributes */ 33446283Sdfr struct attr_abbrev *attrs; /* an array of attribute descriptions */ 33546283Sdfr struct abbrev_info *next; /* next in chain */ 33646283Sdfr }; 33746283Sdfr 33846283Sdfrstruct attr_abbrev 33946283Sdfr { 34046283Sdfr enum dwarf_attribute name; 34146283Sdfr enum dwarf_form form; 34246283Sdfr }; 34346283Sdfr 34446283Sdfr/* This data structure holds a complete die structure. */ 34546283Sdfrstruct die_info 34646283Sdfr { 34798944Sobrien enum dwarf_tag tag; /* Tag indicating type of die */ 34898944Sobrien unsigned int abbrev; /* Abbrev number */ 34998944Sobrien unsigned int offset; /* Offset in .debug_info section */ 35098944Sobrien unsigned int num_attrs; /* Number of attributes */ 35198944Sobrien struct attribute *attrs; /* An array of attributes */ 35298944Sobrien struct die_info *next_ref; /* Next die in ref hash table */ 353130803Smarcel 354130803Smarcel /* The dies in a compilation unit form an n-ary tree. PARENT 355130803Smarcel points to this die's parent; CHILD points to the first child of 356130803Smarcel this node; and all the children of a given node are chained 357130803Smarcel together via their SIBLING fields, terminated by a die whose 358130803Smarcel tag is zero. */ 359130803Smarcel struct die_info *child; /* Its first child, if any. */ 360130803Smarcel struct die_info *sibling; /* Its next sibling, if any. */ 361130803Smarcel struct die_info *parent; /* Its parent, if any. */ 362130803Smarcel 36398944Sobrien struct type *type; /* Cached type information */ 36446283Sdfr }; 36546283Sdfr 36646283Sdfr/* Attributes have a name and a value */ 36746283Sdfrstruct attribute 36846283Sdfr { 36946283Sdfr enum dwarf_attribute name; 37046283Sdfr enum dwarf_form form; 37146283Sdfr union 37246283Sdfr { 37346283Sdfr char *str; 37446283Sdfr struct dwarf_block *blk; 37598944Sobrien unsigned long unsnd; 37698944Sobrien long int snd; 37746283Sdfr CORE_ADDR addr; 37846283Sdfr } 37946283Sdfr u; 38046283Sdfr }; 38146283Sdfr 382130803Smarcelstruct function_range 383130803Smarcel{ 384130803Smarcel const char *name; 385130803Smarcel CORE_ADDR lowpc, highpc; 386130803Smarcel int seen_line; 387130803Smarcel struct function_range *next; 388130803Smarcel}; 389130803Smarcel 39046283Sdfr/* Get at parts of an attribute structure */ 39146283Sdfr 39246283Sdfr#define DW_STRING(attr) ((attr)->u.str) 39346283Sdfr#define DW_UNSND(attr) ((attr)->u.unsnd) 39446283Sdfr#define DW_BLOCK(attr) ((attr)->u.blk) 39546283Sdfr#define DW_SND(attr) ((attr)->u.snd) 39646283Sdfr#define DW_ADDR(attr) ((attr)->u.addr) 39746283Sdfr 39846283Sdfr/* Blocks are a bunch of untyped bytes. */ 39946283Sdfrstruct dwarf_block 40046283Sdfr { 40146283Sdfr unsigned int size; 40246283Sdfr char *data; 40346283Sdfr }; 40446283Sdfr 40546283Sdfr#ifndef ATTR_ALLOC_CHUNK 40646283Sdfr#define ATTR_ALLOC_CHUNK 4 40746283Sdfr#endif 40846283Sdfr 40946283Sdfr/* A hash table of die offsets for following references. */ 41046283Sdfr#ifndef REF_HASH_SIZE 41146283Sdfr#define REF_HASH_SIZE 1021 41246283Sdfr#endif 41346283Sdfr 41446283Sdfrstatic struct die_info *die_ref_table[REF_HASH_SIZE]; 41546283Sdfr 41646283Sdfr/* Obstack for allocating temporary storage used during symbol reading. */ 41746283Sdfrstatic struct obstack dwarf2_tmp_obstack; 41846283Sdfr 41946283Sdfr/* Allocate fields for structs, unions and enums in this size. */ 42046283Sdfr#ifndef DW_FIELD_ALLOC_CHUNK 42146283Sdfr#define DW_FIELD_ALLOC_CHUNK 4 42246283Sdfr#endif 42346283Sdfr 42446283Sdfr/* Actually data from the sections. */ 42546283Sdfrstatic char *dwarf_info_buffer; 42646283Sdfrstatic char *dwarf_abbrev_buffer; 42746283Sdfrstatic char *dwarf_line_buffer; 42898944Sobrienstatic char *dwarf_str_buffer; 429130803Smarcelstatic char *dwarf_macinfo_buffer; 430130803Smarcelstatic char *dwarf_ranges_buffer; 431130803Smarcelstatic char *dwarf_loc_buffer; 43246283Sdfr 43346283Sdfr/* A zeroed version of a partial die for initialization purposes. */ 43446283Sdfrstatic struct partial_die_info zeroed_partial_die; 43546283Sdfr 43698944Sobrien/* FIXME: decode_locdesc sets these variables to describe the location 43798944Sobrien to the caller. These ought to be a structure or something. If 43898944Sobrien none of the flags are set, the object lives at the address returned 43998944Sobrien by decode_locdesc. */ 44046283Sdfr 44198944Sobrienstatic int isreg; /* Object lives in register. 44298944Sobrien decode_locdesc's return value is 44398944Sobrien the register number. */ 44498944Sobrien 44546283Sdfr/* We put a pointer to this structure in the read_symtab_private field 44646283Sdfr of the psymtab. 44746283Sdfr The complete dwarf information for an objfile is kept in the 448130803Smarcel objfile_obstack, so that absolute die references can be handled. 44946283Sdfr Most of the information in this structure is related to an entire 45046283Sdfr object file and could be passed via the sym_private field of the objfile. 45146283Sdfr It is however conceivable that dwarf2 might not be the only type 45246283Sdfr of symbols read from an object file. */ 45346283Sdfr 45446283Sdfrstruct dwarf2_pinfo 45598944Sobrien { 45698944Sobrien /* Pointer to start of dwarf info buffer for the objfile. */ 45746283Sdfr 45898944Sobrien char *dwarf_info_buffer; 45946283Sdfr 46098944Sobrien /* Offset in dwarf_info_buffer for this compilation unit. */ 46146283Sdfr 46298944Sobrien unsigned long dwarf_info_offset; 46346283Sdfr 46498944Sobrien /* Pointer to start of dwarf abbreviation buffer for the objfile. */ 46546283Sdfr 46698944Sobrien char *dwarf_abbrev_buffer; 46746283Sdfr 46898944Sobrien /* Size of dwarf abbreviation section for the objfile. */ 46946283Sdfr 47098944Sobrien unsigned int dwarf_abbrev_size; 47146283Sdfr 47298944Sobrien /* Pointer to start of dwarf line buffer for the objfile. */ 47346283Sdfr 47498944Sobrien char *dwarf_line_buffer; 47546283Sdfr 476130803Smarcel /* Size of dwarf_line_buffer, in bytes. */ 477130803Smarcel 478130803Smarcel unsigned int dwarf_line_size; 479130803Smarcel 48098944Sobrien /* Pointer to start of dwarf string buffer for the objfile. */ 48198944Sobrien 48298944Sobrien char *dwarf_str_buffer; 48398944Sobrien 48498944Sobrien /* Size of dwarf string section for the objfile. */ 48598944Sobrien 48698944Sobrien unsigned int dwarf_str_size; 487130803Smarcel 488130803Smarcel /* Pointer to start of dwarf macro buffer for the objfile. */ 489130803Smarcel 490130803Smarcel char *dwarf_macinfo_buffer; 491130803Smarcel 492130803Smarcel /* Size of dwarf macinfo section for the objfile. */ 493130803Smarcel 494130803Smarcel unsigned int dwarf_macinfo_size; 495130803Smarcel 496130803Smarcel /* Pointer to start of dwarf ranges buffer for the objfile. */ 497130803Smarcel 498130803Smarcel char *dwarf_ranges_buffer; 499130803Smarcel 500130803Smarcel /* Size of dwarf ranges buffer for the objfile. */ 501130803Smarcel 502130803Smarcel unsigned int dwarf_ranges_size; 503130803Smarcel 504130803Smarcel /* Pointer to start of dwarf locations buffer for the objfile. */ 505130803Smarcel 506130803Smarcel char *dwarf_loc_buffer; 507130803Smarcel 508130803Smarcel /* Size of dwarf locations buffer for the objfile. */ 509130803Smarcel 510130803Smarcel unsigned int dwarf_loc_size; 51198944Sobrien }; 51298944Sobrien 51346283Sdfr#define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private) 51446283Sdfr#define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer) 51546283Sdfr#define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset) 51646283Sdfr#define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer) 51746283Sdfr#define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size) 51846283Sdfr#define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer) 519130803Smarcel#define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size) 52098944Sobrien#define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer) 52198944Sobrien#define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size) 522130803Smarcel#define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer) 523130803Smarcel#define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size) 524130803Smarcel#define DWARF_RANGES_BUFFER(p) (PST_PRIVATE(p)->dwarf_ranges_buffer) 525130803Smarcel#define DWARF_RANGES_SIZE(p) (PST_PRIVATE(p)->dwarf_ranges_size) 526130803Smarcel#define DWARF_LOC_BUFFER(p) (PST_PRIVATE(p)->dwarf_loc_buffer) 527130803Smarcel#define DWARF_LOC_SIZE(p) (PST_PRIVATE(p)->dwarf_loc_size) 52846283Sdfr 52946283Sdfr/* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, 53046283Sdfr but this would require a corresponding change in unpack_field_as_long 53146283Sdfr and friends. */ 53246283Sdfrstatic int bits_per_byte = 8; 53346283Sdfr 53446283Sdfr/* The routines that read and process dies for a C struct or C++ class 53546283Sdfr pass lists of data member fields and lists of member function fields 53646283Sdfr in an instance of a field_info structure, as defined below. */ 53746283Sdfrstruct field_info 53898944Sobrien { 53998944Sobrien /* List of data member and baseclasses fields. */ 54098944Sobrien struct nextfield 54198944Sobrien { 54298944Sobrien struct nextfield *next; 54398944Sobrien int accessibility; 54498944Sobrien int virtuality; 54598944Sobrien struct field field; 54698944Sobrien } 54798944Sobrien *fields; 54846283Sdfr 54998944Sobrien /* Number of fields. */ 55098944Sobrien int nfields; 55146283Sdfr 55298944Sobrien /* Number of baseclasses. */ 55398944Sobrien int nbaseclasses; 55446283Sdfr 55598944Sobrien /* Set if the accesibility of one of the fields is not public. */ 55698944Sobrien int non_public_fields; 55746283Sdfr 55898944Sobrien /* Member function fields array, entries are allocated in the order they 55998944Sobrien are encountered in the object file. */ 56098944Sobrien struct nextfnfield 56198944Sobrien { 56298944Sobrien struct nextfnfield *next; 56398944Sobrien struct fn_field fnfield; 56498944Sobrien } 56598944Sobrien *fnfields; 56646283Sdfr 56798944Sobrien /* Member function fieldlist array, contains name of possibly overloaded 56898944Sobrien member function, number of overloaded member functions and a pointer 56998944Sobrien to the head of the member function field chain. */ 57098944Sobrien struct fnfieldlist 57198944Sobrien { 57298944Sobrien char *name; 57398944Sobrien int length; 57498944Sobrien struct nextfnfield *head; 57598944Sobrien } 57698944Sobrien *fnfieldlists; 57746283Sdfr 57898944Sobrien /* Number of entries in the fnfieldlists array. */ 57998944Sobrien int nfnfields; 58098944Sobrien }; 58146283Sdfr 58246283Sdfr/* Various complaints about symbol reading that don't abort the process */ 58346283Sdfr 584130803Smarcelstatic void 585130803Smarceldwarf2_statement_list_fits_in_line_number_section_complaint (void) 58646283Sdfr{ 587130803Smarcel complaint (&symfile_complaints, 588130803Smarcel "statement list doesn't fit in .debug_line section"); 589130803Smarcel} 590130803Smarcel 591130803Smarcelstatic void 592130803Smarceldwarf2_complex_location_expr_complaint (void) 59346283Sdfr{ 594130803Smarcel complaint (&symfile_complaints, "location expression too complex"); 595130803Smarcel} 596130803Smarcel 597130803Smarcelstatic void 598130803Smarceldwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, 599130803Smarcel int arg3) 60046283Sdfr{ 601130803Smarcel complaint (&symfile_complaints, 602130803Smarcel "const value length mismatch for '%s', got %d, expected %d", arg1, 603130803Smarcel arg2, arg3); 604130803Smarcel} 605130803Smarcel 606130803Smarcelstatic void 607130803Smarceldwarf2_macros_too_long_complaint (void) 60846283Sdfr{ 609130803Smarcel complaint (&symfile_complaints, 610130803Smarcel "macro info runs off end of `.debug_macinfo' section"); 611130803Smarcel} 612130803Smarcel 613130803Smarcelstatic void 614130803Smarceldwarf2_macro_malformed_definition_complaint (const char *arg1) 61546283Sdfr{ 616130803Smarcel complaint (&symfile_complaints, 617130803Smarcel "macro debug info contains a malformed macro definition:\n`%s'", 618130803Smarcel arg1); 619130803Smarcel} 620130803Smarcel 621130803Smarcelstatic void 622130803Smarceldwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) 62346283Sdfr{ 624130803Smarcel complaint (&symfile_complaints, 625130803Smarcel "invalid attribute class or form for '%s' in '%s'", arg1, arg2); 626130803Smarcel} 62746283Sdfr 62846283Sdfr/* local function prototypes */ 62946283Sdfr 630130803Smarcelstatic void dwarf2_locate_sections (bfd *, asection *, void *); 63146283Sdfr 63246283Sdfr#if 0 63398944Sobrienstatic void dwarf2_build_psymtabs_easy (struct objfile *, int); 63446283Sdfr#endif 63546283Sdfr 63698944Sobrienstatic void dwarf2_build_psymtabs_hard (struct objfile *, int); 63746283Sdfr 638130803Smarcelstatic char *scan_partial_symbols (char *, CORE_ADDR *, CORE_ADDR *, 639130803Smarcel struct dwarf2_cu *, 640130803Smarcel const char *namespace); 64146283Sdfr 642130803Smarcelstatic void add_partial_symbol (struct partial_die_info *, struct dwarf2_cu *, 643130803Smarcel const char *namespace); 64446283Sdfr 645130803Smarcelstatic int pdi_needs_namespace (enum dwarf_tag tag, const char *namespace); 646130803Smarcel 647130803Smarcelstatic char *add_partial_namespace (struct partial_die_info *pdi, 648130803Smarcel char *info_ptr, 649130803Smarcel CORE_ADDR *lowpc, CORE_ADDR *highpc, 650130803Smarcel struct dwarf2_cu *cu, 651130803Smarcel const char *namespace); 652130803Smarcel 653130803Smarcelstatic char *add_partial_structure (struct partial_die_info *struct_pdi, 654130803Smarcel char *info_ptr, 655130803Smarcel struct dwarf2_cu *cu, 656130803Smarcel const char *namespace); 657130803Smarcel 658130803Smarcelstatic char *add_partial_enumeration (struct partial_die_info *enum_pdi, 659130803Smarcel char *info_ptr, 660130803Smarcel struct dwarf2_cu *cu, 661130803Smarcel const char *namespace); 662130803Smarcel 663130803Smarcelstatic char *locate_pdi_sibling (struct partial_die_info *orig_pdi, 664130803Smarcel char *info_ptr, 665130803Smarcel bfd *abfd, 666130803Smarcel struct dwarf2_cu *cu); 667130803Smarcel 66898944Sobrienstatic void dwarf2_psymtab_to_symtab (struct partial_symtab *); 66946283Sdfr 67098944Sobrienstatic void psymtab_to_symtab_1 (struct partial_symtab *); 67146283Sdfr 672130803Smarcelchar *dwarf2_read_section (struct objfile *, asection *); 67346283Sdfr 674130803Smarcelstatic void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu); 67546283Sdfr 676130803Smarcelstatic void dwarf2_empty_abbrev_table (void *); 67746283Sdfr 678130803Smarcelstatic struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, 679130803Smarcel struct dwarf2_cu *); 68046283Sdfr 68198944Sobrienstatic char *read_partial_die (struct partial_die_info *, 682130803Smarcel bfd *, char *, struct dwarf2_cu *); 68346283Sdfr 68498944Sobrienstatic char *read_full_die (struct die_info **, bfd *, char *, 685130803Smarcel struct dwarf2_cu *, int *); 68646283Sdfr 68798944Sobrienstatic char *read_attribute (struct attribute *, struct attr_abbrev *, 688130803Smarcel bfd *, char *, struct dwarf2_cu *); 68946283Sdfr 69098944Sobrienstatic char *read_attribute_value (struct attribute *, unsigned, 691130803Smarcel bfd *, char *, struct dwarf2_cu *); 69246283Sdfr 69398944Sobrienstatic unsigned int read_1_byte (bfd *, char *); 69446283Sdfr 69598944Sobrienstatic int read_1_signed_byte (bfd *, char *); 69646283Sdfr 69798944Sobrienstatic unsigned int read_2_bytes (bfd *, char *); 69846283Sdfr 69998944Sobrienstatic unsigned int read_4_bytes (bfd *, char *); 70046283Sdfr 70198944Sobrienstatic unsigned long read_8_bytes (bfd *, char *); 70246283Sdfr 703130803Smarcelstatic CORE_ADDR read_address (bfd *, char *ptr, struct dwarf2_cu *, 70498944Sobrien int *bytes_read); 70546283Sdfr 70698944Sobrienstatic LONGEST read_initial_length (bfd *, char *, 70798944Sobrien struct comp_unit_head *, int *bytes_read); 70846283Sdfr 70998944Sobrienstatic LONGEST read_offset (bfd *, char *, const struct comp_unit_head *, 71098944Sobrien int *bytes_read); 71146283Sdfr 71298944Sobrienstatic char *read_n_bytes (bfd *, char *, unsigned int); 71346283Sdfr 71498944Sobrienstatic char *read_string (bfd *, char *, unsigned int *); 71546283Sdfr 71698944Sobrienstatic char *read_indirect_string (bfd *, char *, const struct comp_unit_head *, 71798944Sobrien unsigned int *); 71846283Sdfr 71998944Sobrienstatic unsigned long read_unsigned_leb128 (bfd *, char *, unsigned int *); 72046283Sdfr 72198944Sobrienstatic long read_signed_leb128 (bfd *, char *, unsigned int *); 72246283Sdfr 723130803Smarcelstatic void set_cu_language (unsigned int, struct dwarf2_cu *); 72446283Sdfr 725130803Smarcelstatic struct attribute *dwarf2_attr (struct die_info *, unsigned int, 726130803Smarcel struct dwarf2_cu *); 72746283Sdfr 728130803Smarcelstatic int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); 72946283Sdfr 730130803Smarcelstatic struct die_info *die_specification (struct die_info *die, 731130803Smarcel struct dwarf2_cu *); 73246283Sdfr 733130803Smarcelstatic void free_line_header (struct line_header *lh); 734130803Smarcel 735130803Smarcelstatic struct line_header *(dwarf_decode_line_header 736130803Smarcel (unsigned int offset, 737130803Smarcel bfd *abfd, struct dwarf2_cu *cu)); 738130803Smarcel 739130803Smarcelstatic void dwarf_decode_lines (struct line_header *, char *, bfd *, 740130803Smarcel struct dwarf2_cu *); 741130803Smarcel 74298944Sobrienstatic void dwarf2_start_subfile (char *, char *); 74398944Sobrien 74498944Sobrienstatic struct symbol *new_symbol (struct die_info *, struct type *, 745130803Smarcel struct dwarf2_cu *); 74698944Sobrien 74798944Sobrienstatic void dwarf2_const_value (struct attribute *, struct symbol *, 748130803Smarcel struct dwarf2_cu *); 74998944Sobrien 75098944Sobrienstatic void dwarf2_const_value_data (struct attribute *attr, 75198944Sobrien struct symbol *sym, 75298944Sobrien int bits); 75398944Sobrien 754130803Smarcelstatic struct type *die_type (struct die_info *, struct dwarf2_cu *); 75598944Sobrien 756130803Smarcelstatic struct type *die_containing_type (struct die_info *, 757130803Smarcel struct dwarf2_cu *); 75898944Sobrien 75946283Sdfr#if 0 76098944Sobrienstatic struct type *type_at_offset (unsigned int, struct objfile *); 76146283Sdfr#endif 76246283Sdfr 763130803Smarcelstatic struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *); 76446283Sdfr 765130803Smarcelstatic void read_type_die (struct die_info *, struct dwarf2_cu *); 76646283Sdfr 767130803Smarcelstatic char *determine_prefix (struct die_info *die, struct dwarf2_cu *); 76846283Sdfr 769130803Smarcelstatic char *typename_concat (const char *prefix, const char *suffix); 77046283Sdfr 771130803Smarcelstatic void read_typedef (struct die_info *, struct dwarf2_cu *); 77246283Sdfr 773130803Smarcelstatic void read_base_type (struct die_info *, struct dwarf2_cu *); 77446283Sdfr 775130803Smarcelstatic void read_subrange_type (struct die_info *die, struct dwarf2_cu *cu); 77646283Sdfr 777130803Smarcelstatic void read_file_scope (struct die_info *, struct dwarf2_cu *); 778130803Smarcel 779130803Smarcelstatic void read_func_scope (struct die_info *, struct dwarf2_cu *); 780130803Smarcel 781130803Smarcelstatic void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); 782130803Smarcel 78398944Sobrienstatic int dwarf2_get_pc_bounds (struct die_info *, 784130803Smarcel CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *); 78546283Sdfr 786130803Smarcelstatic void get_scope_pc_bounds (struct die_info *, 787130803Smarcel CORE_ADDR *, CORE_ADDR *, 788130803Smarcel struct dwarf2_cu *); 789130803Smarcel 79098944Sobrienstatic void dwarf2_add_field (struct field_info *, struct die_info *, 791130803Smarcel struct dwarf2_cu *); 79246283Sdfr 79398944Sobrienstatic void dwarf2_attach_fields_to_type (struct field_info *, 794130803Smarcel struct type *, struct dwarf2_cu *); 79546283Sdfr 79698944Sobrienstatic void dwarf2_add_member_fn (struct field_info *, 79798944Sobrien struct die_info *, struct type *, 798130803Smarcel struct dwarf2_cu *); 79946283Sdfr 80098944Sobrienstatic void dwarf2_attach_fn_fields_to_type (struct field_info *, 801130803Smarcel struct type *, struct dwarf2_cu *); 80246283Sdfr 803130803Smarcelstatic void read_structure_type (struct die_info *, struct dwarf2_cu *); 80446283Sdfr 805130803Smarcelstatic void process_structure_scope (struct die_info *, struct dwarf2_cu *); 80646283Sdfr 807130803Smarcelstatic char *determine_class_name (struct die_info *die, struct dwarf2_cu *cu); 80846283Sdfr 809130803Smarcelstatic void read_common_block (struct die_info *, struct dwarf2_cu *); 81046283Sdfr 811130803Smarcelstatic void read_namespace (struct die_info *die, struct dwarf2_cu *); 81246283Sdfr 813130803Smarcelstatic const char *namespace_name (struct die_info *die, 814130803Smarcel int *is_anonymous, struct dwarf2_cu *); 81546283Sdfr 816130803Smarcelstatic void read_enumeration_type (struct die_info *, struct dwarf2_cu *); 81746283Sdfr 818130803Smarcelstatic void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); 81946283Sdfr 820130803Smarcelstatic struct type *dwarf_base_type (int, int, struct dwarf2_cu *); 82146283Sdfr 822130803Smarcelstatic CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); 82346283Sdfr 824130803Smarcelstatic void read_array_type (struct die_info *, struct dwarf2_cu *); 82546283Sdfr 826130803Smarcelstatic void read_tag_pointer_type (struct die_info *, struct dwarf2_cu *); 82746283Sdfr 828251667Semastestatic void read_tag_unspecified_type (struct die_info *, struct dwarf2_cu *); 829251667Semaste 830130803Smarcelstatic void read_tag_ptr_to_member_type (struct die_info *, 831130803Smarcel struct dwarf2_cu *); 83246283Sdfr 833130803Smarcelstatic void read_tag_reference_type (struct die_info *, struct dwarf2_cu *); 83446283Sdfr 835130803Smarcelstatic void read_tag_const_type (struct die_info *, struct dwarf2_cu *); 836130803Smarcel 837130803Smarcelstatic void read_tag_volatile_type (struct die_info *, struct dwarf2_cu *); 838130803Smarcel 839244437Semastestatic void read_tag_restrict_type (struct die_info *, struct dwarf2_cu *); 840244437Semaste 841130803Smarcelstatic void read_tag_string_type (struct die_info *, struct dwarf2_cu *); 842130803Smarcel 843130803Smarcelstatic void read_subroutine_type (struct die_info *, struct dwarf2_cu *); 844130803Smarcel 845130803Smarcelstatic struct die_info *read_comp_unit (char *, bfd *, struct dwarf2_cu *); 846130803Smarcel 847130803Smarcelstatic struct die_info *read_die_and_children (char *info_ptr, bfd *abfd, 848130803Smarcel struct dwarf2_cu *, 849130803Smarcel char **new_info_ptr, 850130803Smarcel struct die_info *parent); 851130803Smarcel 852130803Smarcelstatic struct die_info *read_die_and_siblings (char *info_ptr, bfd *abfd, 853130803Smarcel struct dwarf2_cu *, 854130803Smarcel char **new_info_ptr, 855130803Smarcel struct die_info *parent); 856130803Smarcel 85798944Sobrienstatic void free_die_list (struct die_info *); 85846283Sdfr 85998944Sobrienstatic struct cleanup *make_cleanup_free_die_list (struct die_info *); 86046283Sdfr 861130803Smarcelstatic void process_die (struct die_info *, struct dwarf2_cu *); 86246283Sdfr 863130803Smarcelstatic char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *); 86446283Sdfr 865130803Smarcelstatic char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); 866130803Smarcel 867130803Smarcelstatic struct die_info *dwarf2_extension (struct die_info *die, 868130803Smarcel struct dwarf2_cu *); 869130803Smarcel 87098944Sobrienstatic char *dwarf_tag_name (unsigned int); 87146283Sdfr 87298944Sobrienstatic char *dwarf_attr_name (unsigned int); 87346283Sdfr 87498944Sobrienstatic char *dwarf_form_name (unsigned int); 87546283Sdfr 87698944Sobrienstatic char *dwarf_stack_op_name (unsigned int); 87746283Sdfr 87898944Sobrienstatic char *dwarf_bool_name (unsigned int); 87946283Sdfr 88098944Sobrienstatic char *dwarf_type_encoding_name (unsigned int); 88146283Sdfr 88246283Sdfr#if 0 88398944Sobrienstatic char *dwarf_cfi_name (unsigned int); 88446283Sdfr 88598944Sobrienstruct die_info *copy_die (struct die_info *); 88646283Sdfr#endif 88746283Sdfr 88898944Sobrienstatic struct die_info *sibling_die (struct die_info *); 88946283Sdfr 89098944Sobrienstatic void dump_die (struct die_info *); 89146283Sdfr 89298944Sobrienstatic void dump_die_list (struct die_info *); 89346283Sdfr 89498944Sobrienstatic void store_in_ref_table (unsigned int, struct die_info *); 89546283Sdfr 89698944Sobrienstatic void dwarf2_empty_hash_tables (void); 89746283Sdfr 898130803Smarcelstatic unsigned int dwarf2_get_ref_die_offset (struct attribute *, 899130803Smarcel struct dwarf2_cu *); 90046283Sdfr 901130803Smarcelstatic int dwarf2_get_attr_constant_value (struct attribute *, int); 902130803Smarcel 90398944Sobrienstatic struct die_info *follow_die_ref (unsigned int); 90446283Sdfr 905130803Smarcelstatic struct type *dwarf2_fundamental_type (struct objfile *, int, 906130803Smarcel struct dwarf2_cu *); 90746283Sdfr 90846283Sdfr/* memory allocation interface */ 90946283Sdfr 910130803Smarcelstatic void dwarf2_free_tmp_obstack (void *); 91146283Sdfr 91298944Sobrienstatic struct dwarf_block *dwarf_alloc_block (void); 91346283Sdfr 91498944Sobrienstatic struct abbrev_info *dwarf_alloc_abbrev (void); 91546283Sdfr 91698944Sobrienstatic struct die_info *dwarf_alloc_die (void); 91746283Sdfr 918130803Smarcelstatic void initialize_cu_func_list (struct dwarf2_cu *); 919130803Smarcel 920130803Smarcelstatic void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR, 921130803Smarcel struct dwarf2_cu *); 922130803Smarcel 923130803Smarcelstatic void dwarf_decode_macros (struct line_header *, unsigned int, 924130803Smarcel char *, bfd *, struct dwarf2_cu *); 925130803Smarcel 926130803Smarcelstatic int attr_form_is_block (struct attribute *); 927130803Smarcel 928130803Smarcelstatic void 929130803Smarceldwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, 930130803Smarcel struct dwarf2_cu *cu); 931130803Smarcel 93246283Sdfr/* Try to locate the sections we need for DWARF 2 debugging 93346283Sdfr information and return true if we have enough to do something. */ 93446283Sdfr 93546283Sdfrint 93698944Sobriendwarf2_has_info (bfd *abfd) 93746283Sdfr{ 938130803Smarcel dwarf_info_section = 0; 939130803Smarcel dwarf_abbrev_section = 0; 940130803Smarcel dwarf_line_section = 0; 941130803Smarcel dwarf_str_section = 0; 942130803Smarcel dwarf_macinfo_section = 0; 943130803Smarcel dwarf_frame_section = 0; 944130803Smarcel dwarf_eh_frame_section = 0; 945130803Smarcel dwarf_ranges_section = 0; 946130803Smarcel dwarf_loc_section = 0; 947130803Smarcel 94846283Sdfr bfd_map_over_sections (abfd, dwarf2_locate_sections, NULL); 949130803Smarcel return (dwarf_info_section != NULL && dwarf_abbrev_section != NULL); 95046283Sdfr} 95146283Sdfr 95246283Sdfr/* This function is mapped across the sections and remembers the 95346283Sdfr offset and size of each of the debugging sections we are interested 95446283Sdfr in. */ 95546283Sdfr 95646283Sdfrstatic void 957130803Smarceldwarf2_locate_sections (bfd *ignore_abfd, asection *sectp, void *ignore_ptr) 95846283Sdfr{ 959130803Smarcel if (strcmp (sectp->name, INFO_SECTION) == 0) 96046283Sdfr { 961218822Sdim dwarf_info_size = bfd_get_section_size (sectp); 962130803Smarcel dwarf_info_section = sectp; 96346283Sdfr } 964130803Smarcel else if (strcmp (sectp->name, ABBREV_SECTION) == 0) 96546283Sdfr { 966218822Sdim dwarf_abbrev_size = bfd_get_section_size (sectp); 967130803Smarcel dwarf_abbrev_section = sectp; 96846283Sdfr } 969130803Smarcel else if (strcmp (sectp->name, LINE_SECTION) == 0) 97046283Sdfr { 971218822Sdim dwarf_line_size = bfd_get_section_size (sectp); 972130803Smarcel dwarf_line_section = sectp; 97346283Sdfr } 974130803Smarcel else if (strcmp (sectp->name, PUBNAMES_SECTION) == 0) 97546283Sdfr { 976218822Sdim dwarf_pubnames_size = bfd_get_section_size (sectp); 977130803Smarcel dwarf_pubnames_section = sectp; 97846283Sdfr } 979130803Smarcel else if (strcmp (sectp->name, ARANGES_SECTION) == 0) 98046283Sdfr { 981218822Sdim dwarf_aranges_size = bfd_get_section_size (sectp); 982130803Smarcel dwarf_aranges_section = sectp; 98346283Sdfr } 984130803Smarcel else if (strcmp (sectp->name, LOC_SECTION) == 0) 98546283Sdfr { 986218822Sdim dwarf_loc_size = bfd_get_section_size (sectp); 987130803Smarcel dwarf_loc_section = sectp; 98846283Sdfr } 989130803Smarcel else if (strcmp (sectp->name, MACINFO_SECTION) == 0) 99046283Sdfr { 991218822Sdim dwarf_macinfo_size = bfd_get_section_size (sectp); 992130803Smarcel dwarf_macinfo_section = sectp; 99346283Sdfr } 994130803Smarcel else if (strcmp (sectp->name, STR_SECTION) == 0) 99546283Sdfr { 996218822Sdim dwarf_str_size = bfd_get_section_size (sectp); 997130803Smarcel dwarf_str_section = sectp; 99846283Sdfr } 999130803Smarcel else if (strcmp (sectp->name, FRAME_SECTION) == 0) 100098944Sobrien { 1001218822Sdim dwarf_frame_size = bfd_get_section_size (sectp); 1002130803Smarcel dwarf_frame_section = sectp; 100398944Sobrien } 1004130803Smarcel else if (strcmp (sectp->name, EH_FRAME_SECTION) == 0) 100598944Sobrien { 1006130803Smarcel flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); 1007130803Smarcel if (aflag & SEC_HAS_CONTENTS) 1008130803Smarcel { 1009218822Sdim dwarf_eh_frame_size = bfd_get_section_size (sectp); 1010130803Smarcel dwarf_eh_frame_section = sectp; 1011130803Smarcel } 101298944Sobrien } 1013130803Smarcel else if (strcmp (sectp->name, RANGES_SECTION) == 0) 1014130803Smarcel { 1015218822Sdim dwarf_ranges_size = bfd_get_section_size (sectp); 1016130803Smarcel dwarf_ranges_section = sectp; 1017130803Smarcel } 101846283Sdfr} 101946283Sdfr 102046283Sdfr/* Build a partial symbol table. */ 102146283Sdfr 102246283Sdfrvoid 102398944Sobriendwarf2_build_psymtabs (struct objfile *objfile, int mainline) 102446283Sdfr{ 102546283Sdfr 102646283Sdfr /* We definitely need the .debug_info and .debug_abbrev sections */ 102746283Sdfr 1028130803Smarcel dwarf_info_buffer = dwarf2_read_section (objfile, dwarf_info_section); 1029130803Smarcel dwarf_abbrev_buffer = dwarf2_read_section (objfile, dwarf_abbrev_section); 103046283Sdfr 1031130803Smarcel if (dwarf_line_section) 1032130803Smarcel dwarf_line_buffer = dwarf2_read_section (objfile, dwarf_line_section); 103398944Sobrien else 1034130803Smarcel dwarf_line_buffer = NULL; 1035130803Smarcel 1036130803Smarcel if (dwarf_str_section) 1037130803Smarcel dwarf_str_buffer = dwarf2_read_section (objfile, dwarf_str_section); 1038130803Smarcel else 103998944Sobrien dwarf_str_buffer = NULL; 104098944Sobrien 1041130803Smarcel if (dwarf_macinfo_section) 1042130803Smarcel dwarf_macinfo_buffer = dwarf2_read_section (objfile, 1043130803Smarcel dwarf_macinfo_section); 1044130803Smarcel else 1045130803Smarcel dwarf_macinfo_buffer = NULL; 1046130803Smarcel 1047130803Smarcel if (dwarf_ranges_section) 1048130803Smarcel dwarf_ranges_buffer = dwarf2_read_section (objfile, dwarf_ranges_section); 1049130803Smarcel else 1050130803Smarcel dwarf_ranges_buffer = NULL; 1051130803Smarcel 1052130803Smarcel if (dwarf_loc_section) 1053130803Smarcel dwarf_loc_buffer = dwarf2_read_section (objfile, dwarf_loc_section); 1054130803Smarcel else 1055130803Smarcel dwarf_loc_buffer = NULL; 1056130803Smarcel 105798944Sobrien if (mainline 105898944Sobrien || (objfile->global_psymbols.size == 0 105998944Sobrien && objfile->static_psymbols.size == 0)) 106046283Sdfr { 106146283Sdfr init_psymbol_list (objfile, 1024); 106246283Sdfr } 106346283Sdfr 106446283Sdfr#if 0 106546283Sdfr if (dwarf_aranges_offset && dwarf_pubnames_offset) 106646283Sdfr { 106798944Sobrien /* Things are significantly easier if we have .debug_aranges and 106846283Sdfr .debug_pubnames sections */ 106946283Sdfr 107098944Sobrien dwarf2_build_psymtabs_easy (objfile, mainline); 107146283Sdfr } 107246283Sdfr else 107346283Sdfr#endif 107446283Sdfr /* only test this case for now */ 107598944Sobrien { 107646283Sdfr /* In this case we have to work a bit harder */ 107798944Sobrien dwarf2_build_psymtabs_hard (objfile, mainline); 107846283Sdfr } 107946283Sdfr} 108046283Sdfr 108146283Sdfr#if 0 108246283Sdfr/* Build the partial symbol table from the information in the 108346283Sdfr .debug_pubnames and .debug_aranges sections. */ 108446283Sdfr 108546283Sdfrstatic void 108698944Sobriendwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline) 108746283Sdfr{ 108846283Sdfr bfd *abfd = objfile->obfd; 108946283Sdfr char *aranges_buffer, *pubnames_buffer; 109046283Sdfr char *aranges_ptr, *pubnames_ptr; 109146283Sdfr unsigned int entry_length, version, info_offset, info_size; 109246283Sdfr 109346283Sdfr pubnames_buffer = dwarf2_read_section (objfile, 1094130803Smarcel dwarf_pubnames_section); 109546283Sdfr pubnames_ptr = pubnames_buffer; 109646283Sdfr while ((pubnames_ptr - pubnames_buffer) < dwarf_pubnames_size) 109746283Sdfr { 109898944Sobrien struct comp_unit_head cu_header; 109998944Sobrien int bytes_read; 110098944Sobrien 110198944Sobrien entry_length = read_initial_length (abfd, pubnames_ptr, &cu_header, 110298944Sobrien &bytes_read); 110398944Sobrien pubnames_ptr += bytes_read; 110446283Sdfr version = read_1_byte (abfd, pubnames_ptr); 110546283Sdfr pubnames_ptr += 1; 110646283Sdfr info_offset = read_4_bytes (abfd, pubnames_ptr); 110746283Sdfr pubnames_ptr += 4; 110846283Sdfr info_size = read_4_bytes (abfd, pubnames_ptr); 110946283Sdfr pubnames_ptr += 4; 111046283Sdfr } 111146283Sdfr 111246283Sdfr aranges_buffer = dwarf2_read_section (objfile, 1113130803Smarcel dwarf_aranges_section); 111446283Sdfr 111546283Sdfr} 111646283Sdfr#endif 111746283Sdfr 111898944Sobrien/* Read in the comp unit header information from the debug_info at 111998944Sobrien info_ptr. */ 112098944Sobrien 112198944Sobrienstatic char * 112298944Sobrienread_comp_unit_head (struct comp_unit_head *cu_header, 112398944Sobrien char *info_ptr, bfd *abfd) 112498944Sobrien{ 112598944Sobrien int signed_addr; 112698944Sobrien int bytes_read; 112798944Sobrien cu_header->length = read_initial_length (abfd, info_ptr, cu_header, 112898944Sobrien &bytes_read); 112998944Sobrien info_ptr += bytes_read; 113098944Sobrien cu_header->version = read_2_bytes (abfd, info_ptr); 113198944Sobrien info_ptr += 2; 113298944Sobrien cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, 113398944Sobrien &bytes_read); 113498944Sobrien info_ptr += bytes_read; 113598944Sobrien cu_header->addr_size = read_1_byte (abfd, info_ptr); 113698944Sobrien info_ptr += 1; 113798944Sobrien signed_addr = bfd_get_sign_extend_vma (abfd); 113898944Sobrien if (signed_addr < 0) 113998944Sobrien internal_error (__FILE__, __LINE__, 114098944Sobrien "read_comp_unit_head: dwarf from non elf file"); 114198944Sobrien cu_header->signed_addr_p = signed_addr; 114298944Sobrien return info_ptr; 114398944Sobrien} 114498944Sobrien 114546283Sdfr/* Build the partial symbol table by doing a quick pass through the 114646283Sdfr .debug_info and .debug_abbrev sections. */ 114746283Sdfr 114846283Sdfrstatic void 114998944Sobriendwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline) 115046283Sdfr{ 115146283Sdfr /* Instead of reading this into a big buffer, we should probably use 115246283Sdfr mmap() on architectures that support it. (FIXME) */ 115346283Sdfr bfd *abfd = objfile->obfd; 115446283Sdfr char *info_ptr, *abbrev_ptr; 115546283Sdfr char *beg_of_comp_unit; 115646283Sdfr struct partial_die_info comp_unit_die; 115746283Sdfr struct partial_symtab *pst; 115846283Sdfr struct cleanup *back_to; 1159130803Smarcel CORE_ADDR lowpc, highpc, baseaddr; 116046283Sdfr 116146283Sdfr info_ptr = dwarf_info_buffer; 116246283Sdfr abbrev_ptr = dwarf_abbrev_buffer; 116346283Sdfr 116498944Sobrien /* We use dwarf2_tmp_obstack for objects that don't need to survive 116598944Sobrien the partial symbol scan, like attribute values. 116698944Sobrien 116798944Sobrien We could reduce our peak memory consumption during partial symbol 116898944Sobrien table construction by freeing stuff from this obstack more often 116998944Sobrien --- say, after processing each compilation unit, or each die --- 117098944Sobrien but it turns out that this saves almost nothing. For an 117198944Sobrien executable with 11Mb of Dwarf 2 data, I found about 64k allocated 117298944Sobrien on dwarf2_tmp_obstack. Some investigation showed: 117398944Sobrien 117498944Sobrien 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*, 117598944Sobrien DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are 117698944Sobrien all fixed-length values not requiring dynamic allocation. 117798944Sobrien 117898944Sobrien 2) 30% of the attributes used the form DW_FORM_string. For 117998944Sobrien DW_FORM_string, read_attribute simply hands back a pointer to 118098944Sobrien the null-terminated string in dwarf_info_buffer, so no dynamic 118198944Sobrien allocation is needed there either. 118298944Sobrien 118398944Sobrien 3) The remaining 1% of the attributes all used DW_FORM_block1. 118498944Sobrien 75% of those were DW_AT_frame_base location lists for 118598944Sobrien functions; the rest were DW_AT_location attributes, probably 118698944Sobrien for the global variables. 118798944Sobrien 118898944Sobrien Anyway, what this all means is that the memory the dwarf2 118998944Sobrien reader uses as temporary space reading partial symbols is about 119098944Sobrien 0.5% as much as we use for dwarf_*_buffer. That's noise. */ 119198944Sobrien 119246283Sdfr obstack_init (&dwarf2_tmp_obstack); 119346283Sdfr back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL); 119446283Sdfr 119598944Sobrien /* Since the objects we're extracting from dwarf_info_buffer vary in 119698944Sobrien length, only the individual functions to extract them (like 119798944Sobrien read_comp_unit_head and read_partial_die) can really know whether 119898944Sobrien the buffer is large enough to hold another complete object. 119998944Sobrien 120098944Sobrien At the moment, they don't actually check that. If 120198944Sobrien dwarf_info_buffer holds just one extra byte after the last 120298944Sobrien compilation unit's dies, then read_comp_unit_head will happily 120398944Sobrien read off the end of the buffer. read_partial_die is similarly 120498944Sobrien casual. Those functions should be fixed. 120598944Sobrien 120698944Sobrien For this loop condition, simply checking whether there's any data 120798944Sobrien left at all should be sufficient. */ 120898944Sobrien while (info_ptr < dwarf_info_buffer + dwarf_info_size) 120946283Sdfr { 1210130803Smarcel struct dwarf2_cu cu; 121146283Sdfr beg_of_comp_unit = info_ptr; 121246283Sdfr 1213130803Smarcel cu.objfile = objfile; 1214130803Smarcel info_ptr = read_comp_unit_head (&cu.header, info_ptr, abfd); 1215130803Smarcel 1216130803Smarcel if (cu.header.version != 2) 121746283Sdfr { 1218130803Smarcel error ("Dwarf Error: wrong version in compilation unit header (is %d, should be %d) [in module %s]", cu.header.version, 2, bfd_get_filename (abfd)); 121946283Sdfr return; 122046283Sdfr } 1221130803Smarcel if (cu.header.abbrev_offset >= dwarf_abbrev_size) 122246283Sdfr { 1223130803Smarcel error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]", 1224130803Smarcel (long) cu.header.abbrev_offset, 1225130803Smarcel (long) (beg_of_comp_unit - dwarf_info_buffer), 1226130803Smarcel bfd_get_filename (abfd)); 122746283Sdfr return; 122846283Sdfr } 1229130803Smarcel if (beg_of_comp_unit + cu.header.length + cu.header.initial_length_size 123046283Sdfr > dwarf_info_buffer + dwarf_info_size) 123146283Sdfr { 1232130803Smarcel error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]", 1233130803Smarcel (long) cu.header.length, 1234130803Smarcel (long) (beg_of_comp_unit - dwarf_info_buffer), 1235130803Smarcel bfd_get_filename (abfd)); 123646283Sdfr return; 123746283Sdfr } 1238130803Smarcel /* Complete the cu_header */ 1239130803Smarcel cu.header.offset = beg_of_comp_unit - dwarf_info_buffer; 1240130803Smarcel cu.header.first_die_ptr = info_ptr; 1241130803Smarcel cu.header.cu_head_ptr = beg_of_comp_unit; 1242130803Smarcel 1243130803Smarcel cu.list_in_scope = &file_symbols; 1244130803Smarcel 124546283Sdfr /* Read the abbrevs for this compilation unit into a table */ 1246130803Smarcel dwarf2_read_abbrevs (abfd, &cu); 1247130803Smarcel make_cleanup (dwarf2_empty_abbrev_table, cu.header.dwarf2_abbrevs); 124846283Sdfr 124946283Sdfr /* Read the compilation unit die */ 125098944Sobrien info_ptr = read_partial_die (&comp_unit_die, abfd, info_ptr, 1251130803Smarcel &cu); 125246283Sdfr 125346283Sdfr /* Set the language we're debugging */ 1254130803Smarcel set_cu_language (comp_unit_die.language, &cu); 125546283Sdfr 125646283Sdfr /* Allocate a new partial symbol table structure */ 125798944Sobrien pst = start_psymtab_common (objfile, objfile->section_offsets, 125898944Sobrien comp_unit_die.name ? comp_unit_die.name : "", 125946283Sdfr comp_unit_die.lowpc, 126046283Sdfr objfile->global_psymbols.next, 126146283Sdfr objfile->static_psymbols.next); 126246283Sdfr 126346283Sdfr pst->read_symtab_private = (char *) 1264130803Smarcel obstack_alloc (&objfile->objfile_obstack, sizeof (struct dwarf2_pinfo)); 126598944Sobrien DWARF_INFO_BUFFER (pst) = dwarf_info_buffer; 126698944Sobrien DWARF_INFO_OFFSET (pst) = beg_of_comp_unit - dwarf_info_buffer; 126798944Sobrien DWARF_ABBREV_BUFFER (pst) = dwarf_abbrev_buffer; 126898944Sobrien DWARF_ABBREV_SIZE (pst) = dwarf_abbrev_size; 126998944Sobrien DWARF_LINE_BUFFER (pst) = dwarf_line_buffer; 1270130803Smarcel DWARF_LINE_SIZE (pst) = dwarf_line_size; 127198944Sobrien DWARF_STR_BUFFER (pst) = dwarf_str_buffer; 127298944Sobrien DWARF_STR_SIZE (pst) = dwarf_str_size; 1273130803Smarcel DWARF_MACINFO_BUFFER (pst) = dwarf_macinfo_buffer; 1274130803Smarcel DWARF_MACINFO_SIZE (pst) = dwarf_macinfo_size; 1275130803Smarcel DWARF_RANGES_BUFFER (pst) = dwarf_ranges_buffer; 1276130803Smarcel DWARF_RANGES_SIZE (pst) = dwarf_ranges_size; 1277130803Smarcel DWARF_LOC_BUFFER (pst) = dwarf_loc_buffer; 1278130803Smarcel DWARF_LOC_SIZE (pst) = dwarf_loc_size; 127998944Sobrien baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 128046283Sdfr 128146283Sdfr /* Store the function that reads in the rest of the symbol table */ 128246283Sdfr pst->read_symtab = dwarf2_psymtab_to_symtab; 128346283Sdfr 128446283Sdfr /* Check if comp unit has_children. 128546283Sdfr If so, read the rest of the partial symbols from this comp unit. 128646283Sdfr If not, there's no more debug_info for this comp unit. */ 128746283Sdfr if (comp_unit_die.has_children) 128846283Sdfr { 1289130803Smarcel lowpc = ((CORE_ADDR) -1); 1290130803Smarcel highpc = ((CORE_ADDR) 0); 129146283Sdfr 1292130803Smarcel info_ptr = scan_partial_symbols (info_ptr, &lowpc, &highpc, 1293130803Smarcel &cu, NULL); 1294130803Smarcel 1295130803Smarcel /* If we didn't find a lowpc, set it to highpc to avoid 1296130803Smarcel complaints from `maint check'. */ 1297130803Smarcel if (lowpc == ((CORE_ADDR) -1)) 1298130803Smarcel lowpc = highpc; 1299130803Smarcel 130046283Sdfr /* If the compilation unit didn't have an explicit address range, 130146283Sdfr then use the information extracted from its child dies. */ 130298944Sobrien if (! comp_unit_die.has_pc_info) 130346283Sdfr { 130498944Sobrien comp_unit_die.lowpc = lowpc; 130546283Sdfr comp_unit_die.highpc = highpc; 130646283Sdfr } 130746283Sdfr } 130898944Sobrien pst->textlow = comp_unit_die.lowpc + baseaddr; 130946283Sdfr pst->texthigh = comp_unit_die.highpc + baseaddr; 131046283Sdfr 131146283Sdfr pst->n_global_syms = objfile->global_psymbols.next - 131246283Sdfr (objfile->global_psymbols.list + pst->globals_offset); 131346283Sdfr pst->n_static_syms = objfile->static_psymbols.next - 131446283Sdfr (objfile->static_psymbols.list + pst->statics_offset); 131546283Sdfr sort_pst_symbols (pst); 131646283Sdfr 131746283Sdfr /* If there is already a psymtab or symtab for a file of this 131846283Sdfr name, remove it. (If there is a symtab, more drastic things 131946283Sdfr also happen.) This happens in VxWorks. */ 132046283Sdfr free_named_symtabs (pst->filename); 132146283Sdfr 1322130803Smarcel info_ptr = beg_of_comp_unit + cu.header.length 1323130803Smarcel + cu.header.initial_length_size; 132446283Sdfr } 132546283Sdfr do_cleanups (back_to); 132646283Sdfr} 132746283Sdfr 1328130803Smarcel/* Read in all interesting dies to the end of the compilation unit or 1329130803Smarcel to the end of the current namespace. NAMESPACE is NULL if we 1330130803Smarcel haven't yet encountered any DW_TAG_namespace entries; otherwise, 1331130803Smarcel it's the name of the current namespace. In particular, it's the 1332130803Smarcel empty string if we're currently in the global namespace but have 1333130803Smarcel previously encountered a DW_TAG_namespace. */ 133446283Sdfr 133546283Sdfrstatic char * 1336130803Smarcelscan_partial_symbols (char *info_ptr, CORE_ADDR *lowpc, 1337130803Smarcel CORE_ADDR *highpc, struct dwarf2_cu *cu, 1338130803Smarcel const char *namespace) 133946283Sdfr{ 1340130803Smarcel struct objfile *objfile = cu->objfile; 134146283Sdfr bfd *abfd = objfile->obfd; 134246283Sdfr struct partial_die_info pdi; 134346283Sdfr 1344130803Smarcel /* Now, march along the PDI's, descending into ones which have 1345130803Smarcel interesting children but skipping the children of the other ones, 1346130803Smarcel until we reach the end of the compilation unit. */ 134746283Sdfr 1348130803Smarcel while (1) 1349130803Smarcel { 1350130803Smarcel /* This flag tells whether or not info_ptr has gotten updated 1351130803Smarcel inside the loop. */ 1352130803Smarcel int info_ptr_updated = 0; 135398944Sobrien 1354130803Smarcel info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu); 135546283Sdfr 1356130803Smarcel /* Anonymous namespaces have no name but have interesting 1357130803Smarcel children, so we need to look at them. Ditto for anonymous 1358130803Smarcel enums. */ 135946283Sdfr 1360130803Smarcel if (pdi.name != NULL || pdi.tag == DW_TAG_namespace 1361130803Smarcel || pdi.tag == DW_TAG_enumeration_type) 136246283Sdfr { 136346283Sdfr switch (pdi.tag) 136446283Sdfr { 136546283Sdfr case DW_TAG_subprogram: 136698944Sobrien if (pdi.has_pc_info) 136746283Sdfr { 136846283Sdfr if (pdi.lowpc < *lowpc) 136946283Sdfr { 137046283Sdfr *lowpc = pdi.lowpc; 137146283Sdfr } 137246283Sdfr if (pdi.highpc > *highpc) 137346283Sdfr { 137446283Sdfr *highpc = pdi.highpc; 137546283Sdfr } 1376130803Smarcel if (!pdi.is_declaration) 137746283Sdfr { 1378130803Smarcel add_partial_symbol (&pdi, cu, namespace); 137946283Sdfr } 138046283Sdfr } 138146283Sdfr break; 138246283Sdfr case DW_TAG_variable: 138346283Sdfr case DW_TAG_typedef: 1384130803Smarcel case DW_TAG_union_type: 1385130803Smarcel if (!pdi.is_declaration) 1386130803Smarcel { 1387130803Smarcel add_partial_symbol (&pdi, cu, namespace); 1388130803Smarcel } 1389130803Smarcel break; 139046283Sdfr case DW_TAG_class_type: 139146283Sdfr case DW_TAG_structure_type: 1392130803Smarcel if (!pdi.is_declaration) 1393130803Smarcel { 1394130803Smarcel info_ptr = add_partial_structure (&pdi, info_ptr, cu, 1395130803Smarcel namespace); 1396130803Smarcel info_ptr_updated = 1; 1397130803Smarcel } 1398130803Smarcel break; 139946283Sdfr case DW_TAG_enumeration_type: 1400130803Smarcel if (!pdi.is_declaration) 140146283Sdfr { 1402130803Smarcel info_ptr = add_partial_enumeration (&pdi, info_ptr, cu, 1403130803Smarcel namespace); 1404130803Smarcel info_ptr_updated = 1; 140546283Sdfr } 140646283Sdfr break; 140746283Sdfr case DW_TAG_base_type: 1408130803Smarcel case DW_TAG_subrange_type: 140946283Sdfr /* File scope base type definitions are added to the partial 141098944Sobrien symbol table. */ 1411130803Smarcel add_partial_symbol (&pdi, cu, namespace); 141246283Sdfr break; 1413130803Smarcel case DW_TAG_namespace: 1414130803Smarcel /* We've hit a DW_TAG_namespace entry, so we know this 1415130803Smarcel file has been compiled using a compiler that 1416130803Smarcel generates them; update NAMESPACE to reflect that. */ 1417130803Smarcel if (namespace == NULL) 1418130803Smarcel namespace = ""; 1419130803Smarcel info_ptr = add_partial_namespace (&pdi, info_ptr, lowpc, highpc, 1420130803Smarcel cu, namespace); 1421130803Smarcel info_ptr_updated = 1; 1422130803Smarcel break; 142346283Sdfr default: 142446283Sdfr break; 142546283Sdfr } 142646283Sdfr } 142746283Sdfr 1428130803Smarcel if (pdi.tag == 0) 1429130803Smarcel break; 143046283Sdfr 1431130803Smarcel /* If the die has a sibling, skip to the sibling, unless another 1432130803Smarcel function has already updated info_ptr for us. */ 1433130803Smarcel 1434130803Smarcel /* NOTE: carlton/2003-06-16: This is a bit hackish, but whether 1435130803Smarcel or not we want to update this depends on enough stuff (not 1436130803Smarcel only pdi.tag but also whether or not pdi.name is NULL) that 1437130803Smarcel this seems like the easiest way to handle the issue. */ 1438130803Smarcel 1439130803Smarcel if (!info_ptr_updated) 1440130803Smarcel info_ptr = locate_pdi_sibling (&pdi, info_ptr, abfd, cu); 144146283Sdfr } 144246283Sdfr 144346283Sdfr return info_ptr; 144446283Sdfr} 144546283Sdfr 144646283Sdfrstatic void 1447130803Smarceladd_partial_symbol (struct partial_die_info *pdi, 1448130803Smarcel struct dwarf2_cu *cu, const char *namespace) 144946283Sdfr{ 1450130803Smarcel struct objfile *objfile = cu->objfile; 145146283Sdfr CORE_ADDR addr = 0; 1452130803Smarcel char *actual_name = pdi->name; 1453130803Smarcel const struct partial_symbol *psym = NULL; 1454130803Smarcel CORE_ADDR baseaddr; 145546283Sdfr 1456130803Smarcel baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 1457130803Smarcel 1458130803Smarcel /* If we're not in the global namespace and if the namespace name 1459130803Smarcel isn't encoded in a mangled actual_name, add it. */ 1460130803Smarcel 1461130803Smarcel if (pdi_needs_namespace (pdi->tag, namespace)) 1462130803Smarcel { 1463130803Smarcel actual_name = alloca (strlen (pdi->name) + 2 + strlen (namespace) + 1); 1464130803Smarcel strcpy (actual_name, namespace); 1465130803Smarcel strcat (actual_name, "::"); 1466130803Smarcel strcat (actual_name, pdi->name); 1467130803Smarcel } 1468130803Smarcel 146946283Sdfr switch (pdi->tag) 147046283Sdfr { 147146283Sdfr case DW_TAG_subprogram: 147246283Sdfr if (pdi->is_external) 147346283Sdfr { 1474130803Smarcel /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, 147598944Sobrien mst_text, objfile); */ 1476130803Smarcel psym = add_psymbol_to_list (actual_name, strlen (actual_name), 1477130803Smarcel VAR_DOMAIN, LOC_BLOCK, 1478130803Smarcel &objfile->global_psymbols, 1479130803Smarcel 0, pdi->lowpc + baseaddr, 1480130803Smarcel cu->language, objfile); 148146283Sdfr } 148246283Sdfr else 148346283Sdfr { 1484130803Smarcel /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, 148598944Sobrien mst_file_text, objfile); */ 1486130803Smarcel psym = add_psymbol_to_list (actual_name, strlen (actual_name), 1487130803Smarcel VAR_DOMAIN, LOC_BLOCK, 1488130803Smarcel &objfile->static_psymbols, 1489130803Smarcel 0, pdi->lowpc + baseaddr, 1490130803Smarcel cu->language, objfile); 149146283Sdfr } 149246283Sdfr break; 149346283Sdfr case DW_TAG_variable: 149446283Sdfr if (pdi->is_external) 149546283Sdfr { 149646283Sdfr /* Global Variable. 149746283Sdfr Don't enter into the minimal symbol tables as there is 149846283Sdfr a minimal symbol table entry from the ELF symbols already. 149946283Sdfr Enter into partial symbol table if it has a location 150046283Sdfr descriptor or a type. 150146283Sdfr If the location descriptor is missing, new_symbol will create 150246283Sdfr a LOC_UNRESOLVED symbol, the address of the variable will then 150346283Sdfr be determined from the minimal symbol table whenever the variable 150446283Sdfr is referenced. 150546283Sdfr The address for the partial symbol table entry is not 150646283Sdfr used by GDB, but it comes in handy for debugging partial symbol 150746283Sdfr table building. */ 150846283Sdfr 150946283Sdfr if (pdi->locdesc) 1510130803Smarcel addr = decode_locdesc (pdi->locdesc, cu); 151146283Sdfr if (pdi->locdesc || pdi->has_type) 1512130803Smarcel psym = add_psymbol_to_list (actual_name, strlen (actual_name), 1513130803Smarcel VAR_DOMAIN, LOC_STATIC, 1514130803Smarcel &objfile->global_psymbols, 1515130803Smarcel 0, addr + baseaddr, 1516130803Smarcel cu->language, objfile); 151746283Sdfr } 151846283Sdfr else 151946283Sdfr { 152046283Sdfr /* Static Variable. Skip symbols without location descriptors. */ 152146283Sdfr if (pdi->locdesc == NULL) 152246283Sdfr return; 1523130803Smarcel addr = decode_locdesc (pdi->locdesc, cu); 1524130803Smarcel /*prim_record_minimal_symbol (actual_name, addr + baseaddr, 152598944Sobrien mst_file_data, objfile); */ 1526130803Smarcel psym = add_psymbol_to_list (actual_name, strlen (actual_name), 1527130803Smarcel VAR_DOMAIN, LOC_STATIC, 1528130803Smarcel &objfile->static_psymbols, 1529130803Smarcel 0, addr + baseaddr, 1530130803Smarcel cu->language, objfile); 153146283Sdfr } 153246283Sdfr break; 153346283Sdfr case DW_TAG_typedef: 153446283Sdfr case DW_TAG_base_type: 1535130803Smarcel case DW_TAG_subrange_type: 1536130803Smarcel add_psymbol_to_list (actual_name, strlen (actual_name), 1537130803Smarcel VAR_DOMAIN, LOC_TYPEDEF, 153846283Sdfr &objfile->static_psymbols, 1539130803Smarcel 0, (CORE_ADDR) 0, cu->language, objfile); 154046283Sdfr break; 154146283Sdfr case DW_TAG_class_type: 154246283Sdfr case DW_TAG_structure_type: 154346283Sdfr case DW_TAG_union_type: 154446283Sdfr case DW_TAG_enumeration_type: 154546283Sdfr /* Skip aggregate types without children, these are external 154698944Sobrien references. */ 1547130803Smarcel /* NOTE: carlton/2003-10-07: See comment in new_symbol about 1548130803Smarcel static vs. global. */ 154946283Sdfr if (pdi->has_children == 0) 155046283Sdfr return; 1551130803Smarcel add_psymbol_to_list (actual_name, strlen (actual_name), 1552130803Smarcel STRUCT_DOMAIN, LOC_TYPEDEF, 1553130803Smarcel cu->language == language_cplus 1554130803Smarcel ? &objfile->global_psymbols 1555130803Smarcel : &objfile->static_psymbols, 1556130803Smarcel 0, (CORE_ADDR) 0, cu->language, objfile); 155746283Sdfr 1558130803Smarcel if (cu->language == language_cplus) 155946283Sdfr { 156046283Sdfr /* For C++, these implicitly act as typedefs as well. */ 1561130803Smarcel add_psymbol_to_list (actual_name, strlen (actual_name), 1562130803Smarcel VAR_DOMAIN, LOC_TYPEDEF, 1563130803Smarcel &objfile->global_psymbols, 1564130803Smarcel 0, (CORE_ADDR) 0, cu->language, objfile); 156546283Sdfr } 156646283Sdfr break; 156746283Sdfr case DW_TAG_enumerator: 1568130803Smarcel add_psymbol_to_list (actual_name, strlen (actual_name), 1569130803Smarcel VAR_DOMAIN, LOC_CONST, 1570130803Smarcel cu->language == language_cplus 1571130803Smarcel ? &objfile->global_psymbols 1572130803Smarcel : &objfile->static_psymbols, 1573130803Smarcel 0, (CORE_ADDR) 0, cu->language, objfile); 157446283Sdfr break; 157546283Sdfr default: 157646283Sdfr break; 157746283Sdfr } 1578130803Smarcel 1579130803Smarcel /* Check to see if we should scan the name for possible namespace 1580130803Smarcel info. Only do this if this is C++, if we don't have namespace 1581130803Smarcel debugging info in the file, if the psym is of an appropriate type 1582130803Smarcel (otherwise we'll have psym == NULL), and if we actually had a 1583130803Smarcel mangled name to begin with. */ 1584130803Smarcel 1585130803Smarcel if (cu->language == language_cplus 1586130803Smarcel && namespace == NULL 1587130803Smarcel && psym != NULL 1588130803Smarcel && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL) 1589130803Smarcel cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym), 1590130803Smarcel objfile); 159146283Sdfr} 159246283Sdfr 1593130803Smarcel/* Determine whether a die of type TAG living in the C++ namespace 1594130803Smarcel NAMESPACE needs to have the name of the namespace prepended to the 1595130803Smarcel name listed in the die. */ 1596130803Smarcel 1597130803Smarcelstatic int 1598130803Smarcelpdi_needs_namespace (enum dwarf_tag tag, const char *namespace) 1599130803Smarcel{ 1600130803Smarcel if (namespace == NULL || namespace[0] == '\0') 1601130803Smarcel return 0; 1602130803Smarcel 1603130803Smarcel switch (tag) 1604130803Smarcel { 1605130803Smarcel case DW_TAG_typedef: 1606130803Smarcel case DW_TAG_class_type: 1607130803Smarcel case DW_TAG_structure_type: 1608130803Smarcel case DW_TAG_union_type: 1609130803Smarcel case DW_TAG_enumeration_type: 1610130803Smarcel case DW_TAG_enumerator: 1611130803Smarcel return 1; 1612130803Smarcel default: 1613130803Smarcel return 0; 1614130803Smarcel } 1615130803Smarcel} 1616130803Smarcel 1617130803Smarcel/* Read a partial die corresponding to a namespace; also, add a symbol 1618130803Smarcel corresponding to that namespace to the symbol table. NAMESPACE is 1619130803Smarcel the name of the enclosing namespace. */ 1620130803Smarcel 1621130803Smarcelstatic char * 1622130803Smarceladd_partial_namespace (struct partial_die_info *pdi, char *info_ptr, 1623130803Smarcel CORE_ADDR *lowpc, CORE_ADDR *highpc, 1624130803Smarcel struct dwarf2_cu *cu, const char *namespace) 1625130803Smarcel{ 1626130803Smarcel struct objfile *objfile = cu->objfile; 1627130803Smarcel const char *new_name = pdi->name; 1628130803Smarcel char *full_name; 1629130803Smarcel 1630130803Smarcel /* Calculate the full name of the namespace that we just entered. */ 1631130803Smarcel 1632130803Smarcel if (new_name == NULL) 1633130803Smarcel new_name = "(anonymous namespace)"; 1634130803Smarcel full_name = alloca (strlen (namespace) + 2 + strlen (new_name) + 1); 1635130803Smarcel strcpy (full_name, namespace); 1636130803Smarcel if (*namespace != '\0') 1637130803Smarcel strcat (full_name, "::"); 1638130803Smarcel strcat (full_name, new_name); 1639130803Smarcel 1640130803Smarcel /* FIXME: carlton/2003-10-07: We can't just replace this by a call 1641130803Smarcel to add_partial_symbol, because we don't have a way to pass in the 1642130803Smarcel full name to that function; that might be a flaw in 1643130803Smarcel add_partial_symbol's interface. */ 1644130803Smarcel 1645130803Smarcel add_psymbol_to_list (full_name, strlen (full_name), 1646130803Smarcel VAR_DOMAIN, LOC_TYPEDEF, 1647130803Smarcel &objfile->global_psymbols, 1648130803Smarcel 0, 0, cu->language, objfile); 1649130803Smarcel 1650130803Smarcel /* Now scan partial symbols in that namespace. */ 1651130803Smarcel 1652130803Smarcel if (pdi->has_children) 1653130803Smarcel info_ptr = scan_partial_symbols (info_ptr, lowpc, highpc, cu, full_name); 1654130803Smarcel 1655130803Smarcel return info_ptr; 1656130803Smarcel} 1657130803Smarcel 1658130803Smarcel/* Read a partial die corresponding to a class or structure. */ 1659130803Smarcel 1660130803Smarcelstatic char * 1661130803Smarceladd_partial_structure (struct partial_die_info *struct_pdi, char *info_ptr, 1662130803Smarcel struct dwarf2_cu *cu, 1663130803Smarcel const char *namespace) 1664130803Smarcel{ 1665130803Smarcel bfd *abfd = cu->objfile->obfd; 1666130803Smarcel char *actual_class_name = NULL; 1667130803Smarcel 1668130803Smarcel if (cu->language == language_cplus 1669130803Smarcel && (namespace == NULL || namespace[0] == '\0') 1670130803Smarcel && struct_pdi->name != NULL 1671130803Smarcel && struct_pdi->has_children) 1672130803Smarcel { 1673130803Smarcel /* See if we can figure out if the class lives in a namespace 1674130803Smarcel (or is nested within another class.) We do this by looking 1675130803Smarcel for a member function; its demangled name will contain 1676130803Smarcel namespace info, if there is any. */ 1677130803Smarcel 1678130803Smarcel /* NOTE: carlton/2003-10-07: Getting the info this way changes 1679130803Smarcel what template types look like, because the demangler 1680130803Smarcel frequently doesn't give the same name as the debug info. We 1681130803Smarcel could fix this by only using the demangled name to get the 1682130803Smarcel prefix (but see comment in read_structure_type). */ 1683130803Smarcel 1684130803Smarcel /* FIXME: carlton/2004-01-23: If NAMESPACE equals "", we have 1685130803Smarcel the appropriate debug information, so it would be nice to be 1686130803Smarcel able to avoid this hack. But NAMESPACE may not be the 1687130803Smarcel namespace where this class was defined: NAMESPACE reflects 1688130803Smarcel where STRUCT_PDI occurs in the tree of dies, but because of 1689130803Smarcel DW_AT_specification, that may not actually tell us where the 1690130803Smarcel class is defined. (See the comment in read_func_scope for an 1691130803Smarcel example of how this could occur.) 1692130803Smarcel 1693130803Smarcel Unfortunately, our current partial symtab data structures are 1694130803Smarcel completely unable to deal with DW_AT_specification. So, for 1695130803Smarcel now, the best thing to do is to get nesting information from 1696130803Smarcel places other than the tree structure of dies if there's any 1697130803Smarcel chance that a DW_AT_specification is involved. :-( */ 1698130803Smarcel 1699130803Smarcel char *next_child = info_ptr; 1700130803Smarcel 1701130803Smarcel while (1) 1702130803Smarcel { 1703130803Smarcel struct partial_die_info child_pdi; 1704130803Smarcel 1705130803Smarcel next_child = read_partial_die (&child_pdi, abfd, next_child, 1706130803Smarcel cu); 1707130803Smarcel if (!child_pdi.tag) 1708130803Smarcel break; 1709130803Smarcel if (child_pdi.tag == DW_TAG_subprogram) 1710130803Smarcel { 1711130803Smarcel actual_class_name = class_name_from_physname (child_pdi.name); 1712130803Smarcel if (actual_class_name != NULL) 1713130803Smarcel struct_pdi->name = actual_class_name; 1714130803Smarcel break; 1715130803Smarcel } 1716130803Smarcel else 1717130803Smarcel { 1718130803Smarcel next_child = locate_pdi_sibling (&child_pdi, next_child, 1719130803Smarcel abfd, cu); 1720130803Smarcel } 1721130803Smarcel } 1722130803Smarcel } 1723130803Smarcel 1724130803Smarcel add_partial_symbol (struct_pdi, cu, namespace); 1725130803Smarcel xfree (actual_class_name); 1726130803Smarcel 1727130803Smarcel return locate_pdi_sibling (struct_pdi, info_ptr, abfd, cu); 1728130803Smarcel} 1729130803Smarcel 1730130803Smarcel/* Read a partial die corresponding to an enumeration type. */ 1731130803Smarcel 1732130803Smarcelstatic char * 1733130803Smarceladd_partial_enumeration (struct partial_die_info *enum_pdi, char *info_ptr, 1734130803Smarcel struct dwarf2_cu *cu, const char *namespace) 1735130803Smarcel{ 1736130803Smarcel struct objfile *objfile = cu->objfile; 1737130803Smarcel bfd *abfd = objfile->obfd; 1738130803Smarcel struct partial_die_info pdi; 1739130803Smarcel 1740130803Smarcel if (enum_pdi->name != NULL) 1741130803Smarcel add_partial_symbol (enum_pdi, cu, namespace); 1742130803Smarcel 1743130803Smarcel while (1) 1744130803Smarcel { 1745130803Smarcel info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu); 1746130803Smarcel if (pdi.tag == 0) 1747130803Smarcel break; 1748130803Smarcel if (pdi.tag != DW_TAG_enumerator || pdi.name == NULL) 1749130803Smarcel complaint (&symfile_complaints, "malformed enumerator DIE ignored"); 1750130803Smarcel else 1751130803Smarcel add_partial_symbol (&pdi, cu, namespace); 1752130803Smarcel } 1753130803Smarcel 1754130803Smarcel return info_ptr; 1755130803Smarcel} 1756130803Smarcel 1757130803Smarcel/* Locate ORIG_PDI's sibling; INFO_PTR should point to the next DIE 1758130803Smarcel after ORIG_PDI. */ 1759130803Smarcel 1760130803Smarcelstatic char * 1761130803Smarcellocate_pdi_sibling (struct partial_die_info *orig_pdi, char *info_ptr, 1762130803Smarcel bfd *abfd, struct dwarf2_cu *cu) 1763130803Smarcel{ 1764130803Smarcel /* Do we know the sibling already? */ 1765130803Smarcel 1766130803Smarcel if (orig_pdi->sibling) 1767130803Smarcel return orig_pdi->sibling; 1768130803Smarcel 1769130803Smarcel /* Are there any children to deal with? */ 1770130803Smarcel 1771130803Smarcel if (!orig_pdi->has_children) 1772130803Smarcel return info_ptr; 1773130803Smarcel 1774130803Smarcel /* Okay, we don't know the sibling, but we have children that we 1775130803Smarcel want to skip. So read children until we run into one without a 1776130803Smarcel tag; return whatever follows it. */ 1777130803Smarcel 1778130803Smarcel while (1) 1779130803Smarcel { 1780130803Smarcel struct partial_die_info pdi; 1781130803Smarcel 1782130803Smarcel info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu); 1783130803Smarcel 1784130803Smarcel if (pdi.tag == 0) 1785130803Smarcel return info_ptr; 1786130803Smarcel else 1787130803Smarcel info_ptr = locate_pdi_sibling (&pdi, info_ptr, abfd, cu); 1788130803Smarcel } 1789130803Smarcel} 1790130803Smarcel 179146283Sdfr/* Expand this partial symbol table into a full symbol table. */ 179246283Sdfr 179346283Sdfrstatic void 179498944Sobriendwarf2_psymtab_to_symtab (struct partial_symtab *pst) 179546283Sdfr{ 179646283Sdfr /* FIXME: This is barely more than a stub. */ 179746283Sdfr if (pst != NULL) 179846283Sdfr { 179946283Sdfr if (pst->readin) 180046283Sdfr { 180146283Sdfr warning ("bug: psymtab for %s is already read in.", pst->filename); 180246283Sdfr } 180346283Sdfr else 180446283Sdfr { 180546283Sdfr if (info_verbose) 180646283Sdfr { 180746283Sdfr printf_filtered ("Reading in symbols for %s...", pst->filename); 180846283Sdfr gdb_flush (gdb_stdout); 180946283Sdfr } 181046283Sdfr 181146283Sdfr psymtab_to_symtab_1 (pst); 181246283Sdfr 181346283Sdfr /* Finish up the debug error message. */ 181446283Sdfr if (info_verbose) 181546283Sdfr printf_filtered ("done.\n"); 181646283Sdfr } 181746283Sdfr } 181846283Sdfr} 181946283Sdfr 182046283Sdfrstatic void 182198944Sobrienpsymtab_to_symtab_1 (struct partial_symtab *pst) 182246283Sdfr{ 182346283Sdfr struct objfile *objfile = pst->objfile; 182446283Sdfr bfd *abfd = objfile->obfd; 1825130803Smarcel struct dwarf2_cu cu; 182646283Sdfr struct die_info *dies; 182746283Sdfr unsigned long offset; 182846283Sdfr CORE_ADDR lowpc, highpc; 182946283Sdfr struct die_info *child_die; 183046283Sdfr char *info_ptr; 183146283Sdfr struct symtab *symtab; 183246283Sdfr struct cleanup *back_to; 1833130803Smarcel struct attribute *attr; 1834130803Smarcel CORE_ADDR baseaddr; 183546283Sdfr 183646283Sdfr /* Set local variables from the partial symbol table info. */ 183798944Sobrien offset = DWARF_INFO_OFFSET (pst); 183898944Sobrien dwarf_info_buffer = DWARF_INFO_BUFFER (pst); 183998944Sobrien dwarf_abbrev_buffer = DWARF_ABBREV_BUFFER (pst); 184098944Sobrien dwarf_abbrev_size = DWARF_ABBREV_SIZE (pst); 184198944Sobrien dwarf_line_buffer = DWARF_LINE_BUFFER (pst); 1842130803Smarcel dwarf_line_size = DWARF_LINE_SIZE (pst); 184398944Sobrien dwarf_str_buffer = DWARF_STR_BUFFER (pst); 184498944Sobrien dwarf_str_size = DWARF_STR_SIZE (pst); 1845130803Smarcel dwarf_macinfo_buffer = DWARF_MACINFO_BUFFER (pst); 1846130803Smarcel dwarf_macinfo_size = DWARF_MACINFO_SIZE (pst); 1847130803Smarcel dwarf_ranges_buffer = DWARF_RANGES_BUFFER (pst); 1848130803Smarcel dwarf_ranges_size = DWARF_RANGES_SIZE (pst); 1849130803Smarcel dwarf_loc_buffer = DWARF_LOC_BUFFER (pst); 1850130803Smarcel dwarf_loc_size = DWARF_LOC_SIZE (pst); 185146283Sdfr info_ptr = dwarf_info_buffer + offset; 1852130803Smarcel baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 185346283Sdfr 1854130803Smarcel /* We're in the global namespace. */ 1855130803Smarcel processing_current_prefix = ""; 1856130803Smarcel 185746283Sdfr obstack_init (&dwarf2_tmp_obstack); 185846283Sdfr back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL); 185946283Sdfr 186046283Sdfr buildsym_init (); 186198944Sobrien make_cleanup (really_free_pendings, NULL); 186246283Sdfr 1863130803Smarcel cu.objfile = objfile; 1864130803Smarcel 186546283Sdfr /* read in the comp_unit header */ 1866130803Smarcel info_ptr = read_comp_unit_head (&cu.header, info_ptr, abfd); 186746283Sdfr 186846283Sdfr /* Read the abbrevs for this compilation unit */ 1869130803Smarcel dwarf2_read_abbrevs (abfd, &cu); 1870130803Smarcel make_cleanup (dwarf2_empty_abbrev_table, cu.header.dwarf2_abbrevs); 187146283Sdfr 1872130803Smarcel cu.header.offset = offset; 187346283Sdfr 1874130803Smarcel cu.list_in_scope = &file_symbols; 1875130803Smarcel 1876130803Smarcel dies = read_comp_unit (info_ptr, abfd, &cu); 1877130803Smarcel 187898944Sobrien make_cleanup_free_die_list (dies); 187946283Sdfr 1880130803Smarcel /* Find the base address of the compilation unit for range lists and 1881130803Smarcel location lists. It will normally be specified by DW_AT_low_pc. 1882130803Smarcel In DWARF-3 draft 4, the base address could be overridden by 1883130803Smarcel DW_AT_entry_pc. It's been removed, but GCC still uses this for 1884130803Smarcel compilation units with discontinuous ranges. */ 188546283Sdfr 1886130803Smarcel cu.header.base_known = 0; 1887130803Smarcel cu.header.base_address = 0; 1888130803Smarcel 1889130803Smarcel attr = dwarf2_attr (dies, DW_AT_entry_pc, &cu); 1890130803Smarcel if (attr) 189146283Sdfr { 1892130803Smarcel cu.header.base_address = DW_ADDR (attr); 1893130803Smarcel cu.header.base_known = 1; 1894130803Smarcel } 1895130803Smarcel else 1896130803Smarcel { 1897130803Smarcel attr = dwarf2_attr (dies, DW_AT_low_pc, &cu); 1898130803Smarcel if (attr) 189946283Sdfr { 1900130803Smarcel cu.header.base_address = DW_ADDR (attr); 1901130803Smarcel cu.header.base_known = 1; 190246283Sdfr } 190346283Sdfr } 1904130803Smarcel 1905130803Smarcel /* Do line number decoding in read_file_scope () */ 1906130803Smarcel process_die (dies, &cu); 1907130803Smarcel 1908130803Smarcel /* Some compilers don't define a DW_AT_high_pc attribute for the 1909130803Smarcel compilation unit. If the DW_AT_high_pc is missing, synthesize 1910130803Smarcel it, by scanning the DIE's below the compilation unit. */ 1911130803Smarcel get_scope_pc_bounds (dies, &lowpc, &highpc, &cu); 1912130803Smarcel 191398944Sobrien symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); 191446283Sdfr 191546283Sdfr /* Set symtab language to language from DW_AT_language. 191646283Sdfr If the compilation is from a C file generated by language preprocessors, 191746283Sdfr do not set the language if it was already deduced by start_subfile. */ 191846283Sdfr if (symtab != NULL 1919130803Smarcel && !(cu.language == language_c && symtab->language != language_c)) 192046283Sdfr { 1921130803Smarcel symtab->language = cu.language; 192246283Sdfr } 192346283Sdfr pst->symtab = symtab; 192446283Sdfr pst->readin = 1; 192546283Sdfr 192646283Sdfr do_cleanups (back_to); 192746283Sdfr} 192846283Sdfr 192946283Sdfr/* Process a die and its children. */ 193046283Sdfr 193146283Sdfrstatic void 1932130803Smarcelprocess_die (struct die_info *die, struct dwarf2_cu *cu) 193346283Sdfr{ 193446283Sdfr switch (die->tag) 193546283Sdfr { 193646283Sdfr case DW_TAG_padding: 193746283Sdfr break; 193846283Sdfr case DW_TAG_compile_unit: 1939130803Smarcel read_file_scope (die, cu); 194046283Sdfr break; 194146283Sdfr case DW_TAG_subprogram: 1942130803Smarcel read_subroutine_type (die, cu); 1943130803Smarcel read_func_scope (die, cu); 194446283Sdfr break; 194546283Sdfr case DW_TAG_inlined_subroutine: 194646283Sdfr /* FIXME: These are ignored for now. 194798944Sobrien They could be used to set breakpoints on all inlined instances 194898944Sobrien of a function and make GDB `next' properly over inlined functions. */ 194946283Sdfr break; 195046283Sdfr case DW_TAG_lexical_block: 1951130803Smarcel case DW_TAG_try_block: 1952130803Smarcel case DW_TAG_catch_block: 1953130803Smarcel read_lexical_block_scope (die, cu); 195446283Sdfr break; 195546283Sdfr case DW_TAG_class_type: 195646283Sdfr case DW_TAG_structure_type: 195746283Sdfr case DW_TAG_union_type: 1958130803Smarcel read_structure_type (die, cu); 1959130803Smarcel process_structure_scope (die, cu); 196046283Sdfr break; 196146283Sdfr case DW_TAG_enumeration_type: 1962130803Smarcel read_enumeration_type (die, cu); 1963130803Smarcel process_enumeration_scope (die, cu); 196446283Sdfr break; 1965130803Smarcel 1966130803Smarcel /* FIXME drow/2004-03-14: These initialize die->type, but do not create 1967130803Smarcel a symbol or process any children. Therefore it doesn't do anything 1968130803Smarcel that won't be done on-demand by read_type_die. */ 196946283Sdfr case DW_TAG_subroutine_type: 1970130803Smarcel read_subroutine_type (die, cu); 197146283Sdfr break; 197246283Sdfr case DW_TAG_array_type: 1973130803Smarcel read_array_type (die, cu); 197446283Sdfr break; 197546283Sdfr case DW_TAG_pointer_type: 1976130803Smarcel read_tag_pointer_type (die, cu); 197746283Sdfr break; 197846283Sdfr case DW_TAG_ptr_to_member_type: 1979130803Smarcel read_tag_ptr_to_member_type (die, cu); 198046283Sdfr break; 198146283Sdfr case DW_TAG_reference_type: 1982251665Semaste case DW_TAG_rvalue_reference_type: 1983130803Smarcel read_tag_reference_type (die, cu); 198446283Sdfr break; 198546283Sdfr case DW_TAG_string_type: 1986130803Smarcel read_tag_string_type (die, cu); 198746283Sdfr break; 1988130803Smarcel /* END FIXME */ 1989130803Smarcel 199046283Sdfr case DW_TAG_base_type: 1991130803Smarcel read_base_type (die, cu); 1992130803Smarcel /* Add a typedef symbol for the type definition, if it has a 1993130803Smarcel DW_AT_name. */ 1994130803Smarcel new_symbol (die, die->type, cu); 199546283Sdfr break; 1996130803Smarcel case DW_TAG_subrange_type: 1997130803Smarcel read_subrange_type (die, cu); 1998130803Smarcel /* Add a typedef symbol for the type definition, if it has a 1999130803Smarcel DW_AT_name. */ 2000130803Smarcel new_symbol (die, die->type, cu); 2001130803Smarcel break; 200246283Sdfr case DW_TAG_common_block: 2003130803Smarcel read_common_block (die, cu); 200446283Sdfr break; 200546283Sdfr case DW_TAG_common_inclusion: 200646283Sdfr break; 2007130803Smarcel case DW_TAG_namespace: 2008130803Smarcel processing_has_namespace_info = 1; 2009130803Smarcel read_namespace (die, cu); 2010130803Smarcel break; 2011130803Smarcel case DW_TAG_imported_declaration: 2012130803Smarcel case DW_TAG_imported_module: 2013130803Smarcel /* FIXME: carlton/2002-10-16: Eventually, we should use the 2014130803Smarcel information contained in these. DW_TAG_imported_declaration 2015130803Smarcel dies shouldn't have children; DW_TAG_imported_module dies 2016130803Smarcel shouldn't in the C++ case, but conceivably could in the 2017130803Smarcel Fortran case, so we'll have to replace this gdb_assert if 2018130803Smarcel Fortran compilers start generating that info. */ 2019130803Smarcel processing_has_namespace_info = 1; 2020130803Smarcel gdb_assert (die->child == NULL); 2021130803Smarcel break; 202246283Sdfr default: 2023130803Smarcel new_symbol (die, NULL, cu); 202446283Sdfr break; 202546283Sdfr } 202646283Sdfr} 202746283Sdfr 202846283Sdfrstatic void 2029130803Smarcelinitialize_cu_func_list (struct dwarf2_cu *cu) 203046283Sdfr{ 2031130803Smarcel cu->first_fn = cu->last_fn = cu->cached_fn = NULL; 2032130803Smarcel} 2033130803Smarcel 2034130803Smarcelstatic void 2035130803Smarcelread_file_scope (struct die_info *die, struct dwarf2_cu *cu) 2036130803Smarcel{ 2037130803Smarcel struct objfile *objfile = cu->objfile; 2038130803Smarcel struct comp_unit_head *cu_header = &cu->header; 2039130803Smarcel struct cleanup *back_to = make_cleanup (null_cleanup, 0); 204098944Sobrien CORE_ADDR lowpc = ((CORE_ADDR) -1); 204146283Sdfr CORE_ADDR highpc = ((CORE_ADDR) 0); 204246283Sdfr struct attribute *attr; 204346283Sdfr char *name = "<unknown>"; 204446283Sdfr char *comp_dir = NULL; 204546283Sdfr struct die_info *child_die; 204646283Sdfr bfd *abfd = objfile->obfd; 2047130803Smarcel struct line_header *line_header = 0; 2048130803Smarcel CORE_ADDR baseaddr; 2049130803Smarcel 2050130803Smarcel baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 205146283Sdfr 2052130803Smarcel get_scope_pc_bounds (die, &lowpc, &highpc, cu); 205346283Sdfr 205446283Sdfr /* If we didn't find a lowpc, set it to highpc to avoid complaints 205546283Sdfr from finish_block. */ 205646283Sdfr if (lowpc == ((CORE_ADDR) -1)) 205746283Sdfr lowpc = highpc; 205846283Sdfr lowpc += baseaddr; 205946283Sdfr highpc += baseaddr; 206046283Sdfr 2061130803Smarcel attr = dwarf2_attr (die, DW_AT_name, cu); 206246283Sdfr if (attr) 206346283Sdfr { 206446283Sdfr name = DW_STRING (attr); 206546283Sdfr } 2066130803Smarcel attr = dwarf2_attr (die, DW_AT_comp_dir, cu); 206746283Sdfr if (attr) 206846283Sdfr { 206946283Sdfr comp_dir = DW_STRING (attr); 207046283Sdfr if (comp_dir) 207146283Sdfr { 207246283Sdfr /* Irix 6.2 native cc prepends <machine>.: to the compilation 207346283Sdfr directory, get rid of it. */ 207446283Sdfr char *cp = strchr (comp_dir, ':'); 207546283Sdfr 207646283Sdfr if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/') 207746283Sdfr comp_dir = cp + 1; 207846283Sdfr } 207946283Sdfr } 208046283Sdfr 208146283Sdfr if (objfile->ei.entry_point >= lowpc && 208246283Sdfr objfile->ei.entry_point < highpc) 208346283Sdfr { 2084130803Smarcel objfile->ei.deprecated_entry_file_lowpc = lowpc; 2085130803Smarcel objfile->ei.deprecated_entry_file_highpc = highpc; 208646283Sdfr } 208746283Sdfr 2088130803Smarcel attr = dwarf2_attr (die, DW_AT_language, cu); 208946283Sdfr if (attr) 209046283Sdfr { 2091130803Smarcel set_cu_language (DW_UNSND (attr), cu); 209246283Sdfr } 209346283Sdfr 209446283Sdfr /* We assume that we're processing GCC output. */ 209546283Sdfr processing_gcc_compilation = 2; 209646283Sdfr#if 0 209798944Sobrien /* FIXME:Do something here. */ 209898944Sobrien if (dip->at_producer != NULL) 209946283Sdfr { 210046283Sdfr handle_producer (dip->at_producer); 210146283Sdfr } 210246283Sdfr#endif 210346283Sdfr 210446283Sdfr /* The compilation unit may be in a different language or objfile, 210546283Sdfr zero out all remembered fundamental types. */ 2106130803Smarcel memset (cu->ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *)); 210746283Sdfr 210846283Sdfr start_symtab (name, comp_dir, lowpc); 210946283Sdfr record_debugformat ("DWARF 2"); 211046283Sdfr 2111130803Smarcel initialize_cu_func_list (cu); 211246283Sdfr 211346283Sdfr /* Process all dies in compilation unit. */ 2114130803Smarcel if (die->child != NULL) 211546283Sdfr { 2116130803Smarcel child_die = die->child; 211746283Sdfr while (child_die && child_die->tag) 211846283Sdfr { 2119130803Smarcel process_die (child_die, cu); 212046283Sdfr child_die = sibling_die (child_die); 212146283Sdfr } 212246283Sdfr } 2123130803Smarcel 2124130803Smarcel /* Decode line number information if present. */ 2125130803Smarcel attr = dwarf2_attr (die, DW_AT_stmt_list, cu); 2126130803Smarcel if (attr) 2127130803Smarcel { 2128130803Smarcel unsigned int line_offset = DW_UNSND (attr); 2129130803Smarcel line_header = dwarf_decode_line_header (line_offset, abfd, cu); 2130130803Smarcel if (line_header) 2131130803Smarcel { 2132130803Smarcel make_cleanup ((make_cleanup_ftype *) free_line_header, 2133130803Smarcel (void *) line_header); 2134130803Smarcel dwarf_decode_lines (line_header, comp_dir, abfd, cu); 2135130803Smarcel } 2136130803Smarcel } 2137130803Smarcel 2138130803Smarcel /* Decode macro information, if present. Dwarf 2 macro information 2139130803Smarcel refers to information in the line number info statement program 2140130803Smarcel header, so we can only read it if we've read the header 2141130803Smarcel successfully. */ 2142130803Smarcel attr = dwarf2_attr (die, DW_AT_macro_info, cu); 2143130803Smarcel if (attr && line_header) 2144130803Smarcel { 2145130803Smarcel unsigned int macro_offset = DW_UNSND (attr); 2146130803Smarcel dwarf_decode_macros (line_header, macro_offset, 2147130803Smarcel comp_dir, abfd, cu); 2148130803Smarcel } 2149130803Smarcel do_cleanups (back_to); 215046283Sdfr} 215146283Sdfr 215246283Sdfrstatic void 2153130803Smarceladd_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, 2154130803Smarcel struct dwarf2_cu *cu) 215546283Sdfr{ 2156130803Smarcel struct function_range *thisfn; 2157130803Smarcel 2158130803Smarcel thisfn = (struct function_range *) 2159130803Smarcel obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct function_range)); 2160130803Smarcel thisfn->name = name; 2161130803Smarcel thisfn->lowpc = lowpc; 2162130803Smarcel thisfn->highpc = highpc; 2163130803Smarcel thisfn->seen_line = 0; 2164130803Smarcel thisfn->next = NULL; 2165130803Smarcel 2166130803Smarcel if (cu->last_fn == NULL) 2167130803Smarcel cu->first_fn = thisfn; 2168130803Smarcel else 2169130803Smarcel cu->last_fn->next = thisfn; 2170130803Smarcel 2171130803Smarcel cu->last_fn = thisfn; 2172130803Smarcel} 2173130803Smarcel 2174130803Smarcelstatic void 2175130803Smarcelread_func_scope (struct die_info *die, struct dwarf2_cu *cu) 2176130803Smarcel{ 2177130803Smarcel struct objfile *objfile = cu->objfile; 2178130803Smarcel struct context_stack *new; 217946283Sdfr CORE_ADDR lowpc; 218046283Sdfr CORE_ADDR highpc; 218146283Sdfr struct die_info *child_die; 218246283Sdfr struct attribute *attr; 218346283Sdfr char *name; 2184130803Smarcel const char *previous_prefix = processing_current_prefix; 2185130803Smarcel struct cleanup *back_to = NULL; 2186130803Smarcel CORE_ADDR baseaddr; 218746283Sdfr 2188130803Smarcel baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 218946283Sdfr 2190130803Smarcel name = dwarf2_linkage_name (die, cu); 2191130803Smarcel 219246283Sdfr /* Ignore functions with missing or empty names and functions with 219346283Sdfr missing or invalid low and high pc attributes. */ 2194130803Smarcel if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) 219546283Sdfr return; 219646283Sdfr 2197130803Smarcel if (cu->language == language_cplus) 2198130803Smarcel { 2199130803Smarcel struct die_info *spec_die = die_specification (die, cu); 2200130803Smarcel 2201130803Smarcel /* NOTE: carlton/2004-01-23: We have to be careful in the 2202130803Smarcel presence of DW_AT_specification. For example, with GCC 3.4, 2203130803Smarcel given the code 2204130803Smarcel 2205130803Smarcel namespace N { 2206130803Smarcel void foo() { 2207130803Smarcel // Definition of N::foo. 2208130803Smarcel } 2209130803Smarcel } 2210130803Smarcel 2211130803Smarcel then we'll have a tree of DIEs like this: 2212130803Smarcel 2213130803Smarcel 1: DW_TAG_compile_unit 2214130803Smarcel 2: DW_TAG_namespace // N 2215130803Smarcel 3: DW_TAG_subprogram // declaration of N::foo 2216130803Smarcel 4: DW_TAG_subprogram // definition of N::foo 2217130803Smarcel DW_AT_specification // refers to die #3 2218130803Smarcel 2219130803Smarcel Thus, when processing die #4, we have to pretend that we're 2220130803Smarcel in the context of its DW_AT_specification, namely the contex 2221130803Smarcel of die #3. */ 2222130803Smarcel 2223130803Smarcel if (spec_die != NULL) 2224130803Smarcel { 2225130803Smarcel char *specification_prefix = determine_prefix (spec_die, cu); 2226130803Smarcel processing_current_prefix = specification_prefix; 2227130803Smarcel back_to = make_cleanup (xfree, specification_prefix); 2228130803Smarcel } 2229130803Smarcel } 2230130803Smarcel 223146283Sdfr lowpc += baseaddr; 223246283Sdfr highpc += baseaddr; 223346283Sdfr 2234130803Smarcel /* Record the function range for dwarf_decode_lines. */ 2235130803Smarcel add_to_cu_func_list (name, lowpc, highpc, cu); 2236130803Smarcel 223746283Sdfr if (objfile->ei.entry_point >= lowpc && 223846283Sdfr objfile->ei.entry_point < highpc) 223946283Sdfr { 224046283Sdfr objfile->ei.entry_func_lowpc = lowpc; 224146283Sdfr objfile->ei.entry_func_highpc = highpc; 224246283Sdfr } 224346283Sdfr 2244130803Smarcel new = push_context (0, lowpc); 2245130803Smarcel new->name = new_symbol (die, die->type, cu); 2246130803Smarcel 2247130803Smarcel /* If there is a location expression for DW_AT_frame_base, record 2248130803Smarcel it. */ 2249130803Smarcel attr = dwarf2_attr (die, DW_AT_frame_base, cu); 225046283Sdfr if (attr) 2251130803Smarcel /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location 2252130803Smarcel expression is being recorded directly in the function's symbol 2253130803Smarcel and not in a separate frame-base object. I guess this hack is 2254130803Smarcel to avoid adding some sort of frame-base adjunct/annex to the 2255130803Smarcel function's symbol :-(. The problem with doing this is that it 2256130803Smarcel results in a function symbol with a location expression that 2257130803Smarcel has nothing to do with the location of the function, ouch! The 2258130803Smarcel relationship should be: a function's symbol has-a frame base; a 2259130803Smarcel frame-base has-a location expression. */ 2260130803Smarcel dwarf2_symbol_mark_computed (attr, new->name, cu); 226146283Sdfr 2262130803Smarcel cu->list_in_scope = &local_symbols; 226346283Sdfr 2264130803Smarcel if (die->child != NULL) 226546283Sdfr { 2266130803Smarcel child_die = die->child; 226746283Sdfr while (child_die && child_die->tag) 226846283Sdfr { 2269130803Smarcel process_die (child_die, cu); 227046283Sdfr child_die = sibling_die (child_die); 227146283Sdfr } 227246283Sdfr } 227346283Sdfr 227446283Sdfr new = pop_context (); 227546283Sdfr /* Make a block for the local symbols within. */ 227646283Sdfr finish_block (new->name, &local_symbols, new->old_blocks, 227746283Sdfr lowpc, highpc, objfile); 2278130803Smarcel 2279130803Smarcel /* In C++, we can have functions nested inside functions (e.g., when 2280130803Smarcel a function declares a class that has methods). This means that 2281130803Smarcel when we finish processing a function scope, we may need to go 2282130803Smarcel back to building a containing block's symbol lists. */ 2283130803Smarcel local_symbols = new->locals; 2284130803Smarcel param_symbols = new->params; 2285130803Smarcel 2286130803Smarcel /* If we've finished processing a top-level function, subsequent 2287130803Smarcel symbols go in the file symbol list. */ 2288130803Smarcel if (outermost_context_p ()) 2289130803Smarcel cu->list_in_scope = &file_symbols; 2290130803Smarcel 2291130803Smarcel processing_current_prefix = previous_prefix; 2292130803Smarcel if (back_to != NULL) 2293130803Smarcel do_cleanups (back_to); 229446283Sdfr} 229546283Sdfr 229646283Sdfr/* Process all the DIES contained within a lexical block scope. Start 229746283Sdfr a new scope, process the dies, and then close the scope. */ 229846283Sdfr 229946283Sdfrstatic void 2300130803Smarcelread_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) 230146283Sdfr{ 2302130803Smarcel struct objfile *objfile = cu->objfile; 2303130803Smarcel struct context_stack *new; 230446283Sdfr CORE_ADDR lowpc, highpc; 230546283Sdfr struct die_info *child_die; 2306130803Smarcel CORE_ADDR baseaddr; 230746283Sdfr 2308130803Smarcel baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 2309130803Smarcel 231046283Sdfr /* Ignore blocks with missing or invalid low and high pc attributes. */ 2311130803Smarcel /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges 2312130803Smarcel as multiple lexical blocks? Handling children in a sane way would 2313130803Smarcel be nasty. Might be easier to properly extend generic blocks to 2314130803Smarcel describe ranges. */ 2315130803Smarcel if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) 231646283Sdfr return; 231746283Sdfr lowpc += baseaddr; 231846283Sdfr highpc += baseaddr; 231946283Sdfr 232046283Sdfr push_context (0, lowpc); 2321130803Smarcel if (die->child != NULL) 232246283Sdfr { 2323130803Smarcel child_die = die->child; 232446283Sdfr while (child_die && child_die->tag) 232546283Sdfr { 2326130803Smarcel process_die (child_die, cu); 232746283Sdfr child_die = sibling_die (child_die); 232846283Sdfr } 232946283Sdfr } 233046283Sdfr new = pop_context (); 233146283Sdfr 233246283Sdfr if (local_symbols != NULL) 233346283Sdfr { 233446283Sdfr finish_block (0, &local_symbols, new->old_blocks, new->start_addr, 233546283Sdfr highpc, objfile); 233646283Sdfr } 233746283Sdfr local_symbols = new->locals; 233846283Sdfr} 233946283Sdfr 2340130803Smarcel/* Get low and high pc attributes from a die. Return 1 if the attributes 2341130803Smarcel are present and valid, otherwise, return 0. Return -1 if the range is 2342130803Smarcel discontinuous, i.e. derived from DW_AT_ranges information. */ 234346283Sdfrstatic int 2344130803Smarceldwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, 2345130803Smarcel CORE_ADDR *highpc, struct dwarf2_cu *cu) 234646283Sdfr{ 2347130803Smarcel struct objfile *objfile = cu->objfile; 2348130803Smarcel struct comp_unit_head *cu_header = &cu->header; 234946283Sdfr struct attribute *attr; 2350130803Smarcel bfd *obfd = objfile->obfd; 2351130803Smarcel CORE_ADDR low = 0; 2352130803Smarcel CORE_ADDR high = 0; 2353130803Smarcel int ret = 0; 235446283Sdfr 2355130803Smarcel attr = dwarf2_attr (die, DW_AT_high_pc, cu); 235646283Sdfr if (attr) 2357130803Smarcel { 2358130803Smarcel high = DW_ADDR (attr); 2359130803Smarcel attr = dwarf2_attr (die, DW_AT_low_pc, cu); 2360130803Smarcel if (attr) 2361130803Smarcel low = DW_ADDR (attr); 2362130803Smarcel else 2363130803Smarcel /* Found high w/o low attribute. */ 2364130803Smarcel return 0; 2365130803Smarcel 2366130803Smarcel /* Found consecutive range of addresses. */ 2367130803Smarcel ret = 1; 2368130803Smarcel } 236946283Sdfr else 2370130803Smarcel { 2371130803Smarcel attr = dwarf2_attr (die, DW_AT_ranges, cu); 2372130803Smarcel if (attr != NULL) 2373130803Smarcel { 2374130803Smarcel unsigned int addr_size = cu_header->addr_size; 2375130803Smarcel CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); 2376130803Smarcel /* Value of the DW_AT_ranges attribute is the offset in the 2377130803Smarcel .debug_ranges section. */ 2378130803Smarcel unsigned int offset = DW_UNSND (attr); 2379130803Smarcel /* Base address selection entry. */ 2380130803Smarcel CORE_ADDR base; 2381130803Smarcel int found_base; 2382130803Smarcel int dummy; 2383130803Smarcel char *buffer; 2384130803Smarcel CORE_ADDR marker; 2385130803Smarcel int low_set; 2386130803Smarcel 2387130803Smarcel found_base = cu_header->base_known; 2388130803Smarcel base = cu_header->base_address; 238946283Sdfr 2390130803Smarcel if (offset >= dwarf_ranges_size) 2391130803Smarcel { 2392130803Smarcel complaint (&symfile_complaints, 2393130803Smarcel "Offset %d out of bounds for DW_AT_ranges attribute", 2394130803Smarcel offset); 2395130803Smarcel return 0; 2396130803Smarcel } 2397130803Smarcel buffer = dwarf_ranges_buffer + offset; 2398130803Smarcel 2399130803Smarcel /* Read in the largest possible address. */ 2400130803Smarcel marker = read_address (obfd, buffer, cu, &dummy); 2401130803Smarcel if ((marker & mask) == mask) 2402130803Smarcel { 2403130803Smarcel /* If we found the largest possible address, then 2404130803Smarcel read the base address. */ 2405130803Smarcel base = read_address (obfd, buffer + addr_size, cu, &dummy); 2406130803Smarcel buffer += 2 * addr_size; 2407130803Smarcel offset += 2 * addr_size; 2408130803Smarcel found_base = 1; 2409130803Smarcel } 2410130803Smarcel 2411130803Smarcel low_set = 0; 2412130803Smarcel 2413130803Smarcel while (1) 2414130803Smarcel { 2415130803Smarcel CORE_ADDR range_beginning, range_end; 2416130803Smarcel 2417130803Smarcel range_beginning = read_address (obfd, buffer, cu, &dummy); 2418130803Smarcel buffer += addr_size; 2419130803Smarcel range_end = read_address (obfd, buffer, cu, &dummy); 2420130803Smarcel buffer += addr_size; 2421130803Smarcel offset += 2 * addr_size; 2422130803Smarcel 2423130803Smarcel /* An end of list marker is a pair of zero addresses. */ 2424130803Smarcel if (range_beginning == 0 && range_end == 0) 2425130803Smarcel /* Found the end of list entry. */ 2426130803Smarcel break; 2427130803Smarcel 2428130803Smarcel /* Each base address selection entry is a pair of 2 values. 2429130803Smarcel The first is the largest possible address, the second is 2430130803Smarcel the base address. Check for a base address here. */ 2431130803Smarcel if ((range_beginning & mask) == mask) 2432130803Smarcel { 2433130803Smarcel /* If we found the largest possible address, then 2434130803Smarcel read the base address. */ 2435130803Smarcel base = read_address (obfd, buffer + addr_size, cu, &dummy); 2436130803Smarcel found_base = 1; 2437130803Smarcel continue; 2438130803Smarcel } 2439130803Smarcel 2440130803Smarcel if (!found_base) 2441130803Smarcel { 2442130803Smarcel /* We have no valid base address for the ranges 2443130803Smarcel data. */ 2444130803Smarcel complaint (&symfile_complaints, 2445130803Smarcel "Invalid .debug_ranges data (no base address)"); 2446130803Smarcel return 0; 2447130803Smarcel } 2448130803Smarcel 2449130803Smarcel range_beginning += base; 2450130803Smarcel range_end += base; 2451130803Smarcel 2452130803Smarcel /* FIXME: This is recording everything as a low-high 2453130803Smarcel segment of consecutive addresses. We should have a 2454130803Smarcel data structure for discontiguous block ranges 2455130803Smarcel instead. */ 2456130803Smarcel if (! low_set) 2457130803Smarcel { 2458130803Smarcel low = range_beginning; 2459130803Smarcel high = range_end; 2460130803Smarcel low_set = 1; 2461130803Smarcel } 2462130803Smarcel else 2463130803Smarcel { 2464130803Smarcel if (range_beginning < low) 2465130803Smarcel low = range_beginning; 2466130803Smarcel if (range_end > high) 2467130803Smarcel high = range_end; 2468130803Smarcel } 2469130803Smarcel } 2470130803Smarcel 2471130803Smarcel if (! low_set) 2472130803Smarcel /* If the first entry is an end-of-list marker, the range 2473130803Smarcel describes an empty scope, i.e. no instructions. */ 2474130803Smarcel return 0; 2475130803Smarcel 2476130803Smarcel ret = -1; 2477130803Smarcel } 2478130803Smarcel } 2479130803Smarcel 248046283Sdfr if (high < low) 248146283Sdfr return 0; 248246283Sdfr 248346283Sdfr /* When using the GNU linker, .gnu.linkonce. sections are used to 248446283Sdfr eliminate duplicate copies of functions and vtables and such. 248546283Sdfr The linker will arbitrarily choose one and discard the others. 248646283Sdfr The AT_*_pc values for such functions refer to local labels in 248746283Sdfr these sections. If the section from that file was discarded, the 248846283Sdfr labels are not in the output, so the relocs get a value of 0. 248946283Sdfr If this is a discarded function, mark the pc bounds as invalid, 249046283Sdfr so that GDB will ignore it. */ 2491130803Smarcel if (low == 0 && (bfd_get_file_flags (obfd) & HAS_RELOC) == 0) 249246283Sdfr return 0; 249346283Sdfr 249446283Sdfr *lowpc = low; 249546283Sdfr *highpc = high; 2496130803Smarcel return ret; 249746283Sdfr} 249846283Sdfr 2499130803Smarcel/* Get the low and high pc's represented by the scope DIE, and store 2500130803Smarcel them in *LOWPC and *HIGHPC. If the correct values can't be 2501130803Smarcel determined, set *LOWPC to -1 and *HIGHPC to 0. */ 2502130803Smarcel 2503130803Smarcelstatic void 2504130803Smarcelget_scope_pc_bounds (struct die_info *die, 2505130803Smarcel CORE_ADDR *lowpc, CORE_ADDR *highpc, 2506130803Smarcel struct dwarf2_cu *cu) 2507130803Smarcel{ 2508130803Smarcel CORE_ADDR best_low = (CORE_ADDR) -1; 2509130803Smarcel CORE_ADDR best_high = (CORE_ADDR) 0; 2510130803Smarcel CORE_ADDR current_low, current_high; 2511130803Smarcel 2512130803Smarcel if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu)) 2513130803Smarcel { 2514130803Smarcel best_low = current_low; 2515130803Smarcel best_high = current_high; 2516130803Smarcel } 2517130803Smarcel else 2518130803Smarcel { 2519130803Smarcel struct die_info *child = die->child; 2520130803Smarcel 2521130803Smarcel while (child && child->tag) 2522130803Smarcel { 2523130803Smarcel switch (child->tag) { 2524130803Smarcel case DW_TAG_subprogram: 2525130803Smarcel if (dwarf2_get_pc_bounds (child, ¤t_low, ¤t_high, cu)) 2526130803Smarcel { 2527130803Smarcel best_low = min (best_low, current_low); 2528130803Smarcel best_high = max (best_high, current_high); 2529130803Smarcel } 2530130803Smarcel break; 2531130803Smarcel case DW_TAG_namespace: 2532130803Smarcel /* FIXME: carlton/2004-01-16: Should we do this for 2533130803Smarcel DW_TAG_class_type/DW_TAG_structure_type, too? I think 2534130803Smarcel that current GCC's always emit the DIEs corresponding 2535130803Smarcel to definitions of methods of classes as children of a 2536130803Smarcel DW_TAG_compile_unit or DW_TAG_namespace (as opposed to 2537130803Smarcel the DIEs giving the declarations, which could be 2538130803Smarcel anywhere). But I don't see any reason why the 2539130803Smarcel standards says that they have to be there. */ 2540130803Smarcel get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); 2541130803Smarcel 2542130803Smarcel if (current_low != ((CORE_ADDR) -1)) 2543130803Smarcel { 2544130803Smarcel best_low = min (best_low, current_low); 2545130803Smarcel best_high = max (best_high, current_high); 2546130803Smarcel } 2547130803Smarcel break; 2548130803Smarcel default: 2549130803Smarcel /* Ignore. */ 2550130803Smarcel break; 2551130803Smarcel } 2552130803Smarcel 2553130803Smarcel child = sibling_die (child); 2554130803Smarcel } 2555130803Smarcel } 2556130803Smarcel 2557130803Smarcel *lowpc = best_low; 2558130803Smarcel *highpc = best_high; 2559130803Smarcel} 2560130803Smarcel 256146283Sdfr/* Add an aggregate field to the field list. */ 256246283Sdfr 256346283Sdfrstatic void 256498944Sobriendwarf2_add_field (struct field_info *fip, struct die_info *die, 2565130803Smarcel struct dwarf2_cu *cu) 2566130803Smarcel{ 2567130803Smarcel struct objfile *objfile = cu->objfile; 256846283Sdfr struct nextfield *new_field; 256946283Sdfr struct attribute *attr; 257046283Sdfr struct field *fp; 257146283Sdfr char *fieldname = ""; 257246283Sdfr 257346283Sdfr /* Allocate a new field list entry and link it in. */ 257446283Sdfr new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); 257598944Sobrien make_cleanup (xfree, new_field); 257646283Sdfr memset (new_field, 0, sizeof (struct nextfield)); 257746283Sdfr new_field->next = fip->fields; 257846283Sdfr fip->fields = new_field; 257946283Sdfr fip->nfields++; 258046283Sdfr 258146283Sdfr /* Handle accessibility and virtuality of field. 258246283Sdfr The default accessibility for members is public, the default 258346283Sdfr accessibility for inheritance is private. */ 258446283Sdfr if (die->tag != DW_TAG_inheritance) 258546283Sdfr new_field->accessibility = DW_ACCESS_public; 258646283Sdfr else 258746283Sdfr new_field->accessibility = DW_ACCESS_private; 258846283Sdfr new_field->virtuality = DW_VIRTUALITY_none; 258946283Sdfr 2590130803Smarcel attr = dwarf2_attr (die, DW_AT_accessibility, cu); 259146283Sdfr if (attr) 259246283Sdfr new_field->accessibility = DW_UNSND (attr); 259346283Sdfr if (new_field->accessibility != DW_ACCESS_public) 259446283Sdfr fip->non_public_fields = 1; 2595130803Smarcel attr = dwarf2_attr (die, DW_AT_virtuality, cu); 259646283Sdfr if (attr) 259746283Sdfr new_field->virtuality = DW_UNSND (attr); 259846283Sdfr 259946283Sdfr fp = &new_field->field; 2600130803Smarcel 2601130803Smarcel if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) 260246283Sdfr { 2603130803Smarcel /* Data member other than a C++ static data member. */ 2604130803Smarcel 260546283Sdfr /* Get type of field. */ 2606130803Smarcel fp->type = die_type (die, cu); 260746283Sdfr 2608130803Smarcel FIELD_STATIC_KIND (*fp) = 0; 2609130803Smarcel 261046283Sdfr /* Get bit size of field (zero if none). */ 2611130803Smarcel attr = dwarf2_attr (die, DW_AT_bit_size, cu); 261246283Sdfr if (attr) 261346283Sdfr { 261446283Sdfr FIELD_BITSIZE (*fp) = DW_UNSND (attr); 261546283Sdfr } 261646283Sdfr else 261746283Sdfr { 261846283Sdfr FIELD_BITSIZE (*fp) = 0; 261946283Sdfr } 262046283Sdfr 262146283Sdfr /* Get bit offset of field. */ 2622130803Smarcel attr = dwarf2_attr (die, DW_AT_data_member_location, cu); 262346283Sdfr if (attr) 262446283Sdfr { 262546283Sdfr FIELD_BITPOS (*fp) = 2626130803Smarcel decode_locdesc (DW_BLOCK (attr), cu) * bits_per_byte; 262746283Sdfr } 262846283Sdfr else 262946283Sdfr FIELD_BITPOS (*fp) = 0; 2630130803Smarcel attr = dwarf2_attr (die, DW_AT_bit_offset, cu); 263146283Sdfr if (attr) 263246283Sdfr { 263346283Sdfr if (BITS_BIG_ENDIAN) 263446283Sdfr { 263546283Sdfr /* For big endian bits, the DW_AT_bit_offset gives the 263698944Sobrien additional bit offset from the MSB of the containing 263798944Sobrien anonymous object to the MSB of the field. We don't 263898944Sobrien have to do anything special since we don't need to 263998944Sobrien know the size of the anonymous object. */ 264046283Sdfr FIELD_BITPOS (*fp) += DW_UNSND (attr); 264146283Sdfr } 264246283Sdfr else 264346283Sdfr { 264446283Sdfr /* For little endian bits, compute the bit offset to the 264598944Sobrien MSB of the anonymous object, subtract off the number of 264698944Sobrien bits from the MSB of the field to the MSB of the 264798944Sobrien object, and then subtract off the number of bits of 264898944Sobrien the field itself. The result is the bit offset of 264998944Sobrien the LSB of the field. */ 265046283Sdfr int anonymous_size; 265146283Sdfr int bit_offset = DW_UNSND (attr); 265246283Sdfr 2653130803Smarcel attr = dwarf2_attr (die, DW_AT_byte_size, cu); 265446283Sdfr if (attr) 265546283Sdfr { 265646283Sdfr /* The size of the anonymous object containing 265746283Sdfr the bit field is explicit, so use the 265846283Sdfr indicated size (in bytes). */ 265946283Sdfr anonymous_size = DW_UNSND (attr); 266046283Sdfr } 266146283Sdfr else 266246283Sdfr { 266346283Sdfr /* The size of the anonymous object containing 266446283Sdfr the bit field must be inferred from the type 266546283Sdfr attribute of the data member containing the 266646283Sdfr bit field. */ 266746283Sdfr anonymous_size = TYPE_LENGTH (fp->type); 266846283Sdfr } 266946283Sdfr FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte 267046283Sdfr - bit_offset - FIELD_BITSIZE (*fp); 267146283Sdfr } 267246283Sdfr } 267346283Sdfr 267446283Sdfr /* Get name of field. */ 2675130803Smarcel attr = dwarf2_attr (die, DW_AT_name, cu); 267646283Sdfr if (attr && DW_STRING (attr)) 267746283Sdfr fieldname = DW_STRING (attr); 267846283Sdfr fp->name = obsavestring (fieldname, strlen (fieldname), 2679130803Smarcel &objfile->objfile_obstack); 268046283Sdfr 268146283Sdfr /* Change accessibility for artificial fields (e.g. virtual table 268298944Sobrien pointer or virtual base class pointer) to private. */ 2683130803Smarcel if (dwarf2_attr (die, DW_AT_artificial, cu)) 268446283Sdfr { 268546283Sdfr new_field->accessibility = DW_ACCESS_private; 268646283Sdfr fip->non_public_fields = 1; 268746283Sdfr } 268846283Sdfr } 2689130803Smarcel else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) 269046283Sdfr { 2691130803Smarcel /* C++ static member. */ 2692130803Smarcel 2693130803Smarcel /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that 2694130803Smarcel is a declaration, but all versions of G++ as of this writing 2695130803Smarcel (so through at least 3.2.1) incorrectly generate 2696130803Smarcel DW_TAG_variable tags. */ 2697130803Smarcel 269846283Sdfr char *physname; 269946283Sdfr 2700130803Smarcel /* Get name of field. */ 2701130803Smarcel attr = dwarf2_attr (die, DW_AT_name, cu); 270298944Sobrien if (attr && DW_STRING (attr)) 270398944Sobrien fieldname = DW_STRING (attr); 270498944Sobrien else 270546283Sdfr return; 270646283Sdfr 270798944Sobrien /* Get physical name. */ 2708130803Smarcel physname = dwarf2_linkage_name (die, cu); 270946283Sdfr 271046283Sdfr SET_FIELD_PHYSNAME (*fp, obsavestring (physname, strlen (physname), 2711130803Smarcel &objfile->objfile_obstack)); 2712130803Smarcel FIELD_TYPE (*fp) = die_type (die, cu); 271346283Sdfr FIELD_NAME (*fp) = obsavestring (fieldname, strlen (fieldname), 2714130803Smarcel &objfile->objfile_obstack); 271546283Sdfr } 271646283Sdfr else if (die->tag == DW_TAG_inheritance) 271746283Sdfr { 271846283Sdfr /* C++ base class field. */ 2719130803Smarcel attr = dwarf2_attr (die, DW_AT_data_member_location, cu); 272046283Sdfr if (attr) 2721130803Smarcel FIELD_BITPOS (*fp) = (decode_locdesc (DW_BLOCK (attr), cu) 272298944Sobrien * bits_per_byte); 272346283Sdfr FIELD_BITSIZE (*fp) = 0; 2724130803Smarcel FIELD_STATIC_KIND (*fp) = 0; 2725130803Smarcel FIELD_TYPE (*fp) = die_type (die, cu); 272646283Sdfr FIELD_NAME (*fp) = type_name_no_tag (fp->type); 272746283Sdfr fip->nbaseclasses++; 272846283Sdfr } 272946283Sdfr} 273046283Sdfr 273146283Sdfr/* Create the vector of fields, and attach it to the type. */ 273246283Sdfr 273346283Sdfrstatic void 273498944Sobriendwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, 2735130803Smarcel struct dwarf2_cu *cu) 273646283Sdfr{ 273746283Sdfr int nfields = fip->nfields; 273846283Sdfr 273946283Sdfr /* Record the field count, allocate space for the array of fields, 274046283Sdfr and create blank accessibility bitfields if necessary. */ 274146283Sdfr TYPE_NFIELDS (type) = nfields; 274246283Sdfr TYPE_FIELDS (type) = (struct field *) 274346283Sdfr TYPE_ALLOC (type, sizeof (struct field) * nfields); 274446283Sdfr memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); 274546283Sdfr 274646283Sdfr if (fip->non_public_fields) 274746283Sdfr { 274846283Sdfr ALLOCATE_CPLUS_STRUCT_TYPE (type); 274946283Sdfr 275046283Sdfr TYPE_FIELD_PRIVATE_BITS (type) = 275146283Sdfr (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); 275246283Sdfr B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); 275346283Sdfr 275446283Sdfr TYPE_FIELD_PROTECTED_BITS (type) = 275546283Sdfr (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); 275646283Sdfr B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); 275746283Sdfr 275846283Sdfr TYPE_FIELD_IGNORE_BITS (type) = 275946283Sdfr (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); 276046283Sdfr B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); 276146283Sdfr } 276246283Sdfr 276346283Sdfr /* If the type has baseclasses, allocate and clear a bit vector for 276446283Sdfr TYPE_FIELD_VIRTUAL_BITS. */ 276546283Sdfr if (fip->nbaseclasses) 276646283Sdfr { 276746283Sdfr int num_bytes = B_BYTES (fip->nbaseclasses); 276846283Sdfr char *pointer; 276946283Sdfr 277046283Sdfr ALLOCATE_CPLUS_STRUCT_TYPE (type); 277146283Sdfr pointer = (char *) TYPE_ALLOC (type, num_bytes); 277246283Sdfr TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer; 277346283Sdfr B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); 277446283Sdfr TYPE_N_BASECLASSES (type) = fip->nbaseclasses; 277546283Sdfr } 277646283Sdfr 277746283Sdfr /* Copy the saved-up fields into the field vector. Start from the head 277846283Sdfr of the list, adding to the tail of the field array, so that they end 277946283Sdfr up in the same order in the array in which they were added to the list. */ 278046283Sdfr while (nfields-- > 0) 278146283Sdfr { 278246283Sdfr TYPE_FIELD (type, nfields) = fip->fields->field; 278346283Sdfr switch (fip->fields->accessibility) 278446283Sdfr { 278598944Sobrien case DW_ACCESS_private: 278698944Sobrien SET_TYPE_FIELD_PRIVATE (type, nfields); 278798944Sobrien break; 278846283Sdfr 278998944Sobrien case DW_ACCESS_protected: 279098944Sobrien SET_TYPE_FIELD_PROTECTED (type, nfields); 279198944Sobrien break; 279246283Sdfr 279398944Sobrien case DW_ACCESS_public: 279498944Sobrien break; 279546283Sdfr 279698944Sobrien default: 279798944Sobrien /* Unknown accessibility. Complain and treat it as public. */ 279898944Sobrien { 2799130803Smarcel complaint (&symfile_complaints, "unsupported accessibility %d", 2800130803Smarcel fip->fields->accessibility); 280198944Sobrien } 280298944Sobrien break; 280346283Sdfr } 280446283Sdfr if (nfields < fip->nbaseclasses) 280546283Sdfr { 280646283Sdfr switch (fip->fields->virtuality) 280746283Sdfr { 280898944Sobrien case DW_VIRTUALITY_virtual: 280998944Sobrien case DW_VIRTUALITY_pure_virtual: 281098944Sobrien SET_TYPE_FIELD_VIRTUAL (type, nfields); 281198944Sobrien break; 281246283Sdfr } 281346283Sdfr } 281446283Sdfr fip->fields = fip->fields->next; 281546283Sdfr } 281646283Sdfr} 281746283Sdfr 281846283Sdfr/* Add a member function to the proper fieldlist. */ 281946283Sdfr 282046283Sdfrstatic void 282198944Sobriendwarf2_add_member_fn (struct field_info *fip, struct die_info *die, 2822130803Smarcel struct type *type, struct dwarf2_cu *cu) 282346283Sdfr{ 2824130803Smarcel struct objfile *objfile = cu->objfile; 282546283Sdfr struct attribute *attr; 282646283Sdfr struct fnfieldlist *flp; 282746283Sdfr int i; 282846283Sdfr struct fn_field *fnp; 282946283Sdfr char *fieldname; 283046283Sdfr char *physname; 283146283Sdfr struct nextfnfield *new_fnfield; 283246283Sdfr 283398944Sobrien /* Get name of member function. */ 2834130803Smarcel attr = dwarf2_attr (die, DW_AT_name, cu); 283598944Sobrien if (attr && DW_STRING (attr)) 283698944Sobrien fieldname = DW_STRING (attr); 283798944Sobrien else 283846283Sdfr return; 283946283Sdfr 284098944Sobrien /* Get the mangled name. */ 2841130803Smarcel physname = dwarf2_linkage_name (die, cu); 284246283Sdfr 284346283Sdfr /* Look up member function name in fieldlist. */ 284446283Sdfr for (i = 0; i < fip->nfnfields; i++) 284546283Sdfr { 2846130803Smarcel if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) 284746283Sdfr break; 284846283Sdfr } 284946283Sdfr 285046283Sdfr /* Create new list element if necessary. */ 285146283Sdfr if (i < fip->nfnfields) 285246283Sdfr flp = &fip->fnfieldlists[i]; 285346283Sdfr else 285446283Sdfr { 285546283Sdfr if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) 285646283Sdfr { 285746283Sdfr fip->fnfieldlists = (struct fnfieldlist *) 285846283Sdfr xrealloc (fip->fnfieldlists, 285946283Sdfr (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) 286098944Sobrien * sizeof (struct fnfieldlist)); 286146283Sdfr if (fip->nfnfields == 0) 286298944Sobrien make_cleanup (free_current_contents, &fip->fnfieldlists); 286346283Sdfr } 286446283Sdfr flp = &fip->fnfieldlists[fip->nfnfields]; 286546283Sdfr flp->name = fieldname; 286646283Sdfr flp->length = 0; 286746283Sdfr flp->head = NULL; 286846283Sdfr fip->nfnfields++; 286946283Sdfr } 287046283Sdfr 287146283Sdfr /* Create a new member function field and chain it to the field list 287246283Sdfr entry. */ 287346283Sdfr new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); 287498944Sobrien make_cleanup (xfree, new_fnfield); 287546283Sdfr memset (new_fnfield, 0, sizeof (struct nextfnfield)); 287646283Sdfr new_fnfield->next = flp->head; 287746283Sdfr flp->head = new_fnfield; 287846283Sdfr flp->length++; 287946283Sdfr 288046283Sdfr /* Fill in the member function field info. */ 288146283Sdfr fnp = &new_fnfield->fnfield; 288246283Sdfr fnp->physname = obsavestring (physname, strlen (physname), 2883130803Smarcel &objfile->objfile_obstack); 288446283Sdfr fnp->type = alloc_type (objfile); 288546283Sdfr if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC) 288646283Sdfr { 288746283Sdfr int nparams = TYPE_NFIELDS (die->type); 288846283Sdfr 2889130803Smarcel /* TYPE is the domain of this method, and DIE->TYPE is the type 2890130803Smarcel of the method itself (TYPE_CODE_METHOD). */ 2891130803Smarcel smash_to_method_type (fnp->type, type, 2892130803Smarcel TYPE_TARGET_TYPE (die->type), 2893130803Smarcel TYPE_FIELDS (die->type), 2894130803Smarcel TYPE_NFIELDS (die->type), 2895130803Smarcel TYPE_VARARGS (die->type)); 289646283Sdfr 289746283Sdfr /* Handle static member functions. 289898944Sobrien Dwarf2 has no clean way to discern C++ static and non-static 289998944Sobrien member functions. G++ helps GDB by marking the first 290098944Sobrien parameter for non-static member functions (which is the 290198944Sobrien this pointer) as artificial. We obtain this information 290298944Sobrien from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ 290346283Sdfr if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (die->type, 0) == 0) 290446283Sdfr fnp->voffset = VOFFSET_STATIC; 290546283Sdfr } 290646283Sdfr else 2907130803Smarcel complaint (&symfile_complaints, "member function type missing for '%s'", 2908130803Smarcel physname); 290946283Sdfr 291046283Sdfr /* Get fcontext from DW_AT_containing_type if present. */ 2911130803Smarcel if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) 2912130803Smarcel fnp->fcontext = die_containing_type (die, cu); 291346283Sdfr 291446283Sdfr /* dwarf2 doesn't have stubbed physical names, so the setting of is_const 291546283Sdfr and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ 291646283Sdfr 291746283Sdfr /* Get accessibility. */ 2918130803Smarcel attr = dwarf2_attr (die, DW_AT_accessibility, cu); 291946283Sdfr if (attr) 292046283Sdfr { 292146283Sdfr switch (DW_UNSND (attr)) 292246283Sdfr { 292398944Sobrien case DW_ACCESS_private: 292498944Sobrien fnp->is_private = 1; 292598944Sobrien break; 292698944Sobrien case DW_ACCESS_protected: 292798944Sobrien fnp->is_protected = 1; 292898944Sobrien break; 292946283Sdfr } 293046283Sdfr } 293146283Sdfr 293298944Sobrien /* Check for artificial methods. */ 2933130803Smarcel attr = dwarf2_attr (die, DW_AT_artificial, cu); 293498944Sobrien if (attr && DW_UNSND (attr) != 0) 293598944Sobrien fnp->is_artificial = 1; 293698944Sobrien 293746283Sdfr /* Get index in virtual function table if it is a virtual member function. */ 2938130803Smarcel attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); 293946283Sdfr if (attr) 2940130803Smarcel { 2941130803Smarcel /* Support the .debug_loc offsets */ 2942130803Smarcel if (attr_form_is_block (attr)) 2943130803Smarcel { 2944130803Smarcel fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; 2945130803Smarcel } 2946130803Smarcel else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) 2947130803Smarcel { 2948130803Smarcel dwarf2_complex_location_expr_complaint (); 2949130803Smarcel } 2950130803Smarcel else 2951130803Smarcel { 2952130803Smarcel dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", 2953130803Smarcel fieldname); 2954130803Smarcel } 2955130803Smarcel } 295646283Sdfr} 295746283Sdfr 295846283Sdfr/* Create the vector of member function fields, and attach it to the type. */ 295946283Sdfr 296046283Sdfrstatic void 296198944Sobriendwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, 2962130803Smarcel struct dwarf2_cu *cu) 296346283Sdfr{ 296446283Sdfr struct fnfieldlist *flp; 296546283Sdfr int total_length = 0; 296646283Sdfr int i; 296746283Sdfr 296846283Sdfr ALLOCATE_CPLUS_STRUCT_TYPE (type); 296946283Sdfr TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) 297046283Sdfr TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); 297146283Sdfr 297246283Sdfr for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) 297346283Sdfr { 297446283Sdfr struct nextfnfield *nfp = flp->head; 297546283Sdfr struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); 297646283Sdfr int k; 297746283Sdfr 297846283Sdfr TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; 297946283Sdfr TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; 298046283Sdfr fn_flp->fn_fields = (struct fn_field *) 298146283Sdfr TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); 298246283Sdfr for (k = flp->length; (k--, nfp); nfp = nfp->next) 298398944Sobrien fn_flp->fn_fields[k] = nfp->fnfield; 298446283Sdfr 298546283Sdfr total_length += flp->length; 298646283Sdfr } 298746283Sdfr 298846283Sdfr TYPE_NFN_FIELDS (type) = fip->nfnfields; 298946283Sdfr TYPE_NFN_FIELDS_TOTAL (type) = total_length; 299046283Sdfr} 299146283Sdfr 299246283Sdfr/* Called when we find the DIE that starts a structure or union scope 299346283Sdfr (definition) to process all dies that define the members of the 299446283Sdfr structure or union. 299546283Sdfr 299646283Sdfr NOTE: we need to call struct_type regardless of whether or not the 299746283Sdfr DIE has an at_name attribute, since it might be an anonymous 299846283Sdfr structure or union. This gets the type entered into our set of 299946283Sdfr user defined types. 300046283Sdfr 300146283Sdfr However, if the structure is incomplete (an opaque struct/union) 300246283Sdfr then suppress creating a symbol table entry for it since gdb only 300346283Sdfr wants to find the one with the complete definition. Note that if 300446283Sdfr it is complete, we just call new_symbol, which does it's own 300546283Sdfr checking about whether the struct/union is anonymous or not (and 300646283Sdfr suppresses creating a symbol table entry itself). */ 300746283Sdfr 300846283Sdfrstatic void 3009130803Smarcelread_structure_type (struct die_info *die, struct dwarf2_cu *cu) 301046283Sdfr{ 3011130803Smarcel struct objfile *objfile = cu->objfile; 301246283Sdfr struct type *type; 301346283Sdfr struct attribute *attr; 3014130803Smarcel const char *previous_prefix = processing_current_prefix; 3015130803Smarcel struct cleanup *back_to = NULL; 301646283Sdfr 3017130803Smarcel if (die->type) 3018130803Smarcel return; 3019130803Smarcel 302046283Sdfr type = alloc_type (objfile); 302146283Sdfr 302246283Sdfr INIT_CPLUS_SPECIFIC (type); 3023130803Smarcel attr = dwarf2_attr (die, DW_AT_name, cu); 302446283Sdfr if (attr && DW_STRING (attr)) 302546283Sdfr { 3026130803Smarcel if (cu->language == language_cplus) 3027130803Smarcel { 3028130803Smarcel char *new_prefix = determine_class_name (die, cu); 3029130803Smarcel TYPE_TAG_NAME (type) = obsavestring (new_prefix, 3030130803Smarcel strlen (new_prefix), 3031130803Smarcel &objfile->objfile_obstack); 3032130803Smarcel back_to = make_cleanup (xfree, new_prefix); 3033130803Smarcel processing_current_prefix = new_prefix; 3034130803Smarcel } 3035130803Smarcel else 3036130803Smarcel { 3037130803Smarcel TYPE_TAG_NAME (type) = DW_STRING (attr); 3038130803Smarcel } 303946283Sdfr } 304046283Sdfr 304146283Sdfr if (die->tag == DW_TAG_structure_type) 304246283Sdfr { 304346283Sdfr TYPE_CODE (type) = TYPE_CODE_STRUCT; 304446283Sdfr } 304546283Sdfr else if (die->tag == DW_TAG_union_type) 304646283Sdfr { 304746283Sdfr TYPE_CODE (type) = TYPE_CODE_UNION; 304846283Sdfr } 304946283Sdfr else 305046283Sdfr { 305146283Sdfr /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT 305298944Sobrien in gdbtypes.h. */ 305346283Sdfr TYPE_CODE (type) = TYPE_CODE_CLASS; 305446283Sdfr } 305546283Sdfr 3056130803Smarcel attr = dwarf2_attr (die, DW_AT_byte_size, cu); 305746283Sdfr if (attr) 305846283Sdfr { 305946283Sdfr TYPE_LENGTH (type) = DW_UNSND (attr); 306046283Sdfr } 306146283Sdfr else 306246283Sdfr { 306346283Sdfr TYPE_LENGTH (type) = 0; 306446283Sdfr } 306546283Sdfr 306646283Sdfr /* We need to add the type field to the die immediately so we don't 306746283Sdfr infinitely recurse when dealing with pointers to the structure 306846283Sdfr type within the structure itself. */ 306946283Sdfr die->type = type; 307046283Sdfr 3071130803Smarcel if (die->child != NULL && ! die_is_declaration (die, cu)) 307246283Sdfr { 307346283Sdfr struct field_info fi; 307446283Sdfr struct die_info *child_die; 307546283Sdfr struct cleanup *back_to = make_cleanup (null_cleanup, NULL); 307646283Sdfr 307746283Sdfr memset (&fi, 0, sizeof (struct field_info)); 307846283Sdfr 3079130803Smarcel child_die = die->child; 308046283Sdfr 308146283Sdfr while (child_die && child_die->tag) 308246283Sdfr { 3083130803Smarcel if (child_die->tag == DW_TAG_member 3084130803Smarcel || child_die->tag == DW_TAG_variable) 308546283Sdfr { 3086130803Smarcel /* NOTE: carlton/2002-11-05: A C++ static data member 3087130803Smarcel should be a DW_TAG_member that is a declaration, but 3088130803Smarcel all versions of G++ as of this writing (so through at 3089130803Smarcel least 3.2.1) incorrectly generate DW_TAG_variable 3090130803Smarcel tags for them instead. */ 3091130803Smarcel dwarf2_add_field (&fi, child_die, cu); 309246283Sdfr } 309346283Sdfr else if (child_die->tag == DW_TAG_subprogram) 309446283Sdfr { 309546283Sdfr /* C++ member function. */ 3096130803Smarcel read_type_die (child_die, cu); 3097130803Smarcel dwarf2_add_member_fn (&fi, child_die, type, cu); 309846283Sdfr } 309946283Sdfr else if (child_die->tag == DW_TAG_inheritance) 310046283Sdfr { 310146283Sdfr /* C++ base class field. */ 3102130803Smarcel dwarf2_add_field (&fi, child_die, cu); 310346283Sdfr } 310446283Sdfr child_die = sibling_die (child_die); 310546283Sdfr } 310646283Sdfr 310746283Sdfr /* Attach fields and member functions to the type. */ 310846283Sdfr if (fi.nfields) 3109130803Smarcel dwarf2_attach_fields_to_type (&fi, type, cu); 311046283Sdfr if (fi.nfnfields) 311146283Sdfr { 3112130803Smarcel dwarf2_attach_fn_fields_to_type (&fi, type, cu); 311346283Sdfr 311498944Sobrien /* Get the type which refers to the base class (possibly this 311546283Sdfr class itself) which contains the vtable pointer for the current 311646283Sdfr class from the DW_AT_containing_type attribute. */ 311746283Sdfr 3118130803Smarcel if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) 311946283Sdfr { 3120130803Smarcel struct type *t = die_containing_type (die, cu); 312146283Sdfr 312246283Sdfr TYPE_VPTR_BASETYPE (type) = t; 312346283Sdfr if (type == t) 312446283Sdfr { 312598944Sobrien static const char vptr_name[] = 312698944Sobrien {'_', 'v', 'p', 't', 'r', '\0'}; 312746283Sdfr int i; 312846283Sdfr 312946283Sdfr /* Our own class provides vtbl ptr. */ 313046283Sdfr for (i = TYPE_NFIELDS (t) - 1; 313146283Sdfr i >= TYPE_N_BASECLASSES (t); 313246283Sdfr --i) 313346283Sdfr { 313446283Sdfr char *fieldname = TYPE_FIELD_NAME (t, i); 313546283Sdfr 3136130803Smarcel if ((strncmp (fieldname, vptr_name, 3137130803Smarcel strlen (vptr_name) - 1) 3138130803Smarcel == 0) 313946283Sdfr && is_cplus_marker (fieldname[strlen (vptr_name)])) 314046283Sdfr { 314146283Sdfr TYPE_VPTR_FIELDNO (type) = i; 314246283Sdfr break; 314346283Sdfr } 314446283Sdfr } 314546283Sdfr 314646283Sdfr /* Complain if virtual function table field not found. */ 314746283Sdfr if (i < TYPE_N_BASECLASSES (t)) 3148130803Smarcel complaint (&symfile_complaints, 3149130803Smarcel "virtual function table pointer not found when defining class '%s'", 3150130803Smarcel TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : 3151130803Smarcel ""); 315246283Sdfr } 315346283Sdfr else 315446283Sdfr { 315546283Sdfr TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); 315646283Sdfr } 315746283Sdfr } 315846283Sdfr } 315946283Sdfr 316046283Sdfr do_cleanups (back_to); 316146283Sdfr } 316246283Sdfr else 316346283Sdfr { 316446283Sdfr /* No children, must be stub. */ 316546283Sdfr TYPE_FLAGS (type) |= TYPE_FLAG_STUB; 316646283Sdfr } 316746283Sdfr 3168130803Smarcel processing_current_prefix = previous_prefix; 3169130803Smarcel if (back_to != NULL) 3170130803Smarcel do_cleanups (back_to); 317146283Sdfr} 317246283Sdfr 3173130803Smarcelstatic void 3174130803Smarcelprocess_structure_scope (struct die_info *die, struct dwarf2_cu *cu) 3175130803Smarcel{ 3176130803Smarcel struct objfile *objfile = cu->objfile; 3177130803Smarcel const char *previous_prefix = processing_current_prefix; 3178130803Smarcel struct die_info *child_die = die->child; 317946283Sdfr 3180130803Smarcel if (TYPE_TAG_NAME (die->type) != NULL) 3181130803Smarcel processing_current_prefix = TYPE_TAG_NAME (die->type); 318246283Sdfr 3183130803Smarcel /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its 3184130803Smarcel snapshots) has been known to create a die giving a declaration 3185130803Smarcel for a class that has, as a child, a die giving a definition for a 3186130803Smarcel nested class. So we have to process our children even if the 3187130803Smarcel current die is a declaration. Normally, of course, a declaration 3188130803Smarcel won't have any children at all. */ 318946283Sdfr 3190130803Smarcel while (child_die != NULL && child_die->tag) 3191130803Smarcel { 3192130803Smarcel if (child_die->tag == DW_TAG_member 3193130803Smarcel || child_die->tag == DW_TAG_variable 3194130803Smarcel || child_die->tag == DW_TAG_inheritance) 3195130803Smarcel { 3196130803Smarcel /* Do nothing. */ 3197130803Smarcel } 3198130803Smarcel else 3199130803Smarcel process_die (child_die, cu); 3200130803Smarcel 3201130803Smarcel child_die = sibling_die (child_die); 3202130803Smarcel } 3203130803Smarcel 3204130803Smarcel if (die->child != NULL && ! die_is_declaration (die, cu)) 3205130803Smarcel new_symbol (die, die->type, cu); 3206130803Smarcel 3207130803Smarcel processing_current_prefix = previous_prefix; 3208130803Smarcel} 3209130803Smarcel 3210130803Smarcel/* Given a DW_AT_enumeration_type die, set its type. We do not 3211130803Smarcel complete the type's fields yet, or create any symbols. */ 3212130803Smarcel 321346283Sdfrstatic void 3214130803Smarcelread_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) 321546283Sdfr{ 3216130803Smarcel struct objfile *objfile = cu->objfile; 321746283Sdfr struct type *type; 321846283Sdfr struct attribute *attr; 321946283Sdfr 3220130803Smarcel if (die->type) 3221130803Smarcel return; 3222130803Smarcel 322346283Sdfr type = alloc_type (objfile); 322446283Sdfr 322546283Sdfr TYPE_CODE (type) = TYPE_CODE_ENUM; 3226130803Smarcel attr = dwarf2_attr (die, DW_AT_name, cu); 322746283Sdfr if (attr && DW_STRING (attr)) 322846283Sdfr { 3229130803Smarcel const char *name = DW_STRING (attr); 3230130803Smarcel 3231130803Smarcel if (processing_has_namespace_info) 3232130803Smarcel { 3233130803Smarcel TYPE_TAG_NAME (type) = obconcat (&objfile->objfile_obstack, 3234130803Smarcel processing_current_prefix, 3235130803Smarcel processing_current_prefix[0] == '\0' 3236130803Smarcel ? "" : "::", 3237130803Smarcel name); 3238130803Smarcel } 3239130803Smarcel else 3240130803Smarcel { 3241130803Smarcel TYPE_TAG_NAME (type) = obsavestring (name, strlen (name), 3242130803Smarcel &objfile->objfile_obstack); 3243130803Smarcel } 324446283Sdfr } 324546283Sdfr 3246130803Smarcel attr = dwarf2_attr (die, DW_AT_byte_size, cu); 324746283Sdfr if (attr) 324846283Sdfr { 324946283Sdfr TYPE_LENGTH (type) = DW_UNSND (attr); 325046283Sdfr } 325146283Sdfr else 325246283Sdfr { 325346283Sdfr TYPE_LENGTH (type) = 0; 325446283Sdfr } 325546283Sdfr 3256130803Smarcel die->type = type; 3257130803Smarcel} 3258130803Smarcel 3259130803Smarcel/* Determine the name of the type represented by DIE, which should be 3260130803Smarcel a named C++ compound type. Return the name in question; the caller 3261130803Smarcel is responsible for xfree()'ing it. */ 3262130803Smarcel 3263130803Smarcelstatic char * 3264130803Smarceldetermine_class_name (struct die_info *die, struct dwarf2_cu *cu) 3265130803Smarcel{ 3266130803Smarcel struct cleanup *back_to = NULL; 3267130803Smarcel struct die_info *spec_die = die_specification (die, cu); 3268130803Smarcel char *new_prefix = NULL; 3269130803Smarcel 3270130803Smarcel /* If this is the definition of a class that is declared by another 3271130803Smarcel die, then processing_current_prefix may not be accurate; see 3272130803Smarcel read_func_scope for a similar example. */ 3273130803Smarcel if (spec_die != NULL) 3274130803Smarcel { 3275130803Smarcel char *specification_prefix = determine_prefix (spec_die, cu); 3276130803Smarcel processing_current_prefix = specification_prefix; 3277130803Smarcel back_to = make_cleanup (xfree, specification_prefix); 3278130803Smarcel } 3279130803Smarcel 3280130803Smarcel /* If we don't have namespace debug info, guess the name by trying 3281130803Smarcel to demangle the names of members, just like we did in 3282130803Smarcel add_partial_structure. */ 3283130803Smarcel if (!processing_has_namespace_info) 3284130803Smarcel { 3285130803Smarcel struct die_info *child; 3286130803Smarcel 3287130803Smarcel for (child = die->child; 3288130803Smarcel child != NULL && child->tag != 0; 3289130803Smarcel child = sibling_die (child)) 3290130803Smarcel { 3291130803Smarcel if (child->tag == DW_TAG_subprogram) 3292130803Smarcel { 3293130803Smarcel new_prefix = class_name_from_physname (dwarf2_linkage_name 3294130803Smarcel (child, cu)); 3295130803Smarcel 3296130803Smarcel if (new_prefix != NULL) 3297130803Smarcel break; 3298130803Smarcel } 3299130803Smarcel } 3300130803Smarcel } 3301130803Smarcel 3302130803Smarcel if (new_prefix == NULL) 3303130803Smarcel { 3304130803Smarcel const char *name = dwarf2_name (die, cu); 3305130803Smarcel new_prefix = typename_concat (processing_current_prefix, 3306130803Smarcel name ? name : "<<anonymous>>"); 3307130803Smarcel } 3308130803Smarcel 3309130803Smarcel if (back_to != NULL) 3310130803Smarcel do_cleanups (back_to); 3311130803Smarcel 3312130803Smarcel return new_prefix; 3313130803Smarcel} 3314130803Smarcel 3315130803Smarcel/* Given a pointer to a die which begins an enumeration, process all 3316130803Smarcel the dies that define the members of the enumeration, and create the 3317130803Smarcel symbol for the enumeration type. 3318130803Smarcel 3319130803Smarcel NOTE: We reverse the order of the element list. */ 3320130803Smarcel 3321130803Smarcelstatic void 3322130803Smarcelprocess_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) 3323130803Smarcel{ 3324130803Smarcel struct objfile *objfile = cu->objfile; 3325130803Smarcel struct die_info *child_die; 3326130803Smarcel struct field *fields; 3327130803Smarcel struct attribute *attr; 3328130803Smarcel struct symbol *sym; 3329130803Smarcel int num_fields; 3330130803Smarcel int unsigned_enum = 1; 3331130803Smarcel 333246283Sdfr num_fields = 0; 333346283Sdfr fields = NULL; 3334130803Smarcel if (die->child != NULL) 333546283Sdfr { 3336130803Smarcel child_die = die->child; 333746283Sdfr while (child_die && child_die->tag) 333846283Sdfr { 333946283Sdfr if (child_die->tag != DW_TAG_enumerator) 334046283Sdfr { 3341130803Smarcel process_die (child_die, cu); 334246283Sdfr } 334346283Sdfr else 334446283Sdfr { 3345130803Smarcel attr = dwarf2_attr (child_die, DW_AT_name, cu); 334646283Sdfr if (attr) 334746283Sdfr { 3348130803Smarcel sym = new_symbol (child_die, die->type, cu); 334946283Sdfr if (SYMBOL_VALUE (sym) < 0) 335046283Sdfr unsigned_enum = 0; 335146283Sdfr 335246283Sdfr if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) 335346283Sdfr { 335446283Sdfr fields = (struct field *) 335546283Sdfr xrealloc (fields, 335646283Sdfr (num_fields + DW_FIELD_ALLOC_CHUNK) 335798944Sobrien * sizeof (struct field)); 335846283Sdfr } 335946283Sdfr 3360130803Smarcel FIELD_NAME (fields[num_fields]) = DEPRECATED_SYMBOL_NAME (sym); 336146283Sdfr FIELD_TYPE (fields[num_fields]) = NULL; 336246283Sdfr FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym); 336346283Sdfr FIELD_BITSIZE (fields[num_fields]) = 0; 3364130803Smarcel FIELD_STATIC_KIND (fields[num_fields]) = 0; 336546283Sdfr 336646283Sdfr num_fields++; 336746283Sdfr } 336846283Sdfr } 336946283Sdfr 337046283Sdfr child_die = sibling_die (child_die); 337146283Sdfr } 337246283Sdfr 337346283Sdfr if (num_fields) 337446283Sdfr { 3375130803Smarcel TYPE_NFIELDS (die->type) = num_fields; 3376130803Smarcel TYPE_FIELDS (die->type) = (struct field *) 3377130803Smarcel TYPE_ALLOC (die->type, sizeof (struct field) * num_fields); 3378130803Smarcel memcpy (TYPE_FIELDS (die->type), fields, 337946283Sdfr sizeof (struct field) * num_fields); 338098944Sobrien xfree (fields); 338146283Sdfr } 338246283Sdfr if (unsigned_enum) 3383130803Smarcel TYPE_FLAGS (die->type) |= TYPE_FLAG_UNSIGNED; 338446283Sdfr } 3385130803Smarcel 3386130803Smarcel new_symbol (die, die->type, cu); 338746283Sdfr} 338846283Sdfr 338946283Sdfr/* Extract all information from a DW_TAG_array_type DIE and put it in 339046283Sdfr the DIE's type field. For now, this only handles one dimensional 339146283Sdfr arrays. */ 339246283Sdfr 339346283Sdfrstatic void 3394130803Smarcelread_array_type (struct die_info *die, struct dwarf2_cu *cu) 339546283Sdfr{ 3396130803Smarcel struct objfile *objfile = cu->objfile; 339746283Sdfr struct die_info *child_die; 339846283Sdfr struct type *type = NULL; 339946283Sdfr struct type *element_type, *range_type, *index_type; 340046283Sdfr struct type **range_types = NULL; 340146283Sdfr struct attribute *attr; 340246283Sdfr int ndim = 0; 340346283Sdfr struct cleanup *back_to; 340446283Sdfr 340546283Sdfr /* Return if we've already decoded this type. */ 340646283Sdfr if (die->type) 340746283Sdfr { 340846283Sdfr return; 340946283Sdfr } 341046283Sdfr 3411130803Smarcel element_type = die_type (die, cu); 341246283Sdfr 341346283Sdfr /* Irix 6.2 native cc creates array types without children for 341446283Sdfr arrays with unspecified length. */ 3415130803Smarcel if (die->child == NULL) 341646283Sdfr { 3417130803Smarcel index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu); 341846283Sdfr range_type = create_range_type (NULL, index_type, 0, -1); 341946283Sdfr die->type = create_array_type (NULL, element_type, range_type); 342046283Sdfr return; 342146283Sdfr } 342246283Sdfr 342346283Sdfr back_to = make_cleanup (null_cleanup, NULL); 3424130803Smarcel child_die = die->child; 342546283Sdfr while (child_die && child_die->tag) 342646283Sdfr { 342746283Sdfr if (child_die->tag == DW_TAG_subrange_type) 342846283Sdfr { 3429130803Smarcel read_subrange_type (child_die, cu); 343046283Sdfr 3431130803Smarcel if (child_die->type != NULL) 3432130803Smarcel { 3433130803Smarcel /* The range type was succesfully read. Save it for 3434130803Smarcel the array type creation. */ 3435130803Smarcel if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) 3436130803Smarcel { 3437130803Smarcel range_types = (struct type **) 3438130803Smarcel xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) 3439130803Smarcel * sizeof (struct type *)); 3440130803Smarcel if (ndim == 0) 3441130803Smarcel make_cleanup (free_current_contents, &range_types); 3442130803Smarcel } 3443130803Smarcel range_types[ndim++] = child_die->type; 3444130803Smarcel } 344546283Sdfr } 344646283Sdfr child_die = sibling_die (child_die); 344746283Sdfr } 344846283Sdfr 344946283Sdfr /* Dwarf2 dimensions are output from left to right, create the 345046283Sdfr necessary array types in backwards order. */ 345146283Sdfr type = element_type; 345246283Sdfr while (ndim-- > 0) 345346283Sdfr type = create_array_type (NULL, type, range_types[ndim]); 345446283Sdfr 3455130803Smarcel /* Understand Dwarf2 support for vector types (like they occur on 3456130803Smarcel the PowerPC w/ AltiVec). Gcc just adds another attribute to the 3457130803Smarcel array type. This is not part of the Dwarf2/3 standard yet, but a 3458130803Smarcel custom vendor extension. The main difference between a regular 3459130803Smarcel array and the vector variant is that vectors are passed by value 3460130803Smarcel to functions. */ 3461130803Smarcel attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); 3462130803Smarcel if (attr) 3463130803Smarcel TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR; 3464130803Smarcel 346546283Sdfr do_cleanups (back_to); 346646283Sdfr 346746283Sdfr /* Install the type in the die. */ 346846283Sdfr die->type = type; 346946283Sdfr} 347046283Sdfr 347146283Sdfr/* First cut: install each common block member as a global variable. */ 347246283Sdfr 347346283Sdfrstatic void 3474130803Smarcelread_common_block (struct die_info *die, struct dwarf2_cu *cu) 347546283Sdfr{ 347646283Sdfr struct die_info *child_die; 347746283Sdfr struct attribute *attr; 347846283Sdfr struct symbol *sym; 347946283Sdfr CORE_ADDR base = (CORE_ADDR) 0; 348046283Sdfr 3481130803Smarcel attr = dwarf2_attr (die, DW_AT_location, cu); 348246283Sdfr if (attr) 348346283Sdfr { 3484130803Smarcel /* Support the .debug_loc offsets */ 3485130803Smarcel if (attr_form_is_block (attr)) 3486130803Smarcel { 3487130803Smarcel base = decode_locdesc (DW_BLOCK (attr), cu); 3488130803Smarcel } 3489130803Smarcel else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) 3490130803Smarcel { 3491130803Smarcel dwarf2_complex_location_expr_complaint (); 3492130803Smarcel } 3493130803Smarcel else 3494130803Smarcel { 3495130803Smarcel dwarf2_invalid_attrib_class_complaint ("DW_AT_location", 3496130803Smarcel "common block member"); 3497130803Smarcel } 349846283Sdfr } 3499130803Smarcel if (die->child != NULL) 350046283Sdfr { 3501130803Smarcel child_die = die->child; 350246283Sdfr while (child_die && child_die->tag) 350346283Sdfr { 3504130803Smarcel sym = new_symbol (child_die, NULL, cu); 3505130803Smarcel attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu); 350646283Sdfr if (attr) 350746283Sdfr { 350846283Sdfr SYMBOL_VALUE_ADDRESS (sym) = 3509130803Smarcel base + decode_locdesc (DW_BLOCK (attr), cu); 351046283Sdfr add_symbol_to_list (sym, &global_symbols); 351146283Sdfr } 351246283Sdfr child_die = sibling_die (child_die); 351346283Sdfr } 351446283Sdfr } 351546283Sdfr} 351646283Sdfr 3517130803Smarcel/* Read a C++ namespace. */ 3518130803Smarcel 3519130803Smarcelstatic void 3520130803Smarcelread_namespace (struct die_info *die, struct dwarf2_cu *cu) 3521130803Smarcel{ 3522130803Smarcel struct objfile *objfile = cu->objfile; 3523130803Smarcel const char *previous_prefix = processing_current_prefix; 3524130803Smarcel const char *name; 3525130803Smarcel int is_anonymous; 3526130803Smarcel struct die_info *current_die; 3527130803Smarcel 3528130803Smarcel name = namespace_name (die, &is_anonymous, cu); 3529130803Smarcel 3530130803Smarcel /* Now build the name of the current namespace. */ 3531130803Smarcel 3532130803Smarcel if (previous_prefix[0] == '\0') 3533130803Smarcel { 3534130803Smarcel processing_current_prefix = name; 3535130803Smarcel } 3536130803Smarcel else 3537130803Smarcel { 3538130803Smarcel /* We need temp_name around because processing_current_prefix 3539130803Smarcel is a const char *. */ 3540130803Smarcel char *temp_name = alloca (strlen (previous_prefix) 3541130803Smarcel + 2 + strlen(name) + 1); 3542130803Smarcel strcpy (temp_name, previous_prefix); 3543130803Smarcel strcat (temp_name, "::"); 3544130803Smarcel strcat (temp_name, name); 3545130803Smarcel 3546130803Smarcel processing_current_prefix = temp_name; 3547130803Smarcel } 3548130803Smarcel 3549130803Smarcel /* Add a symbol associated to this if we haven't seen the namespace 3550130803Smarcel before. Also, add a using directive if it's an anonymous 3551130803Smarcel namespace. */ 3552130803Smarcel 3553130803Smarcel if (dwarf2_extension (die, cu) == NULL) 3554130803Smarcel { 3555130803Smarcel struct type *type; 3556130803Smarcel 3557130803Smarcel /* FIXME: carlton/2003-06-27: Once GDB is more const-correct, 3558130803Smarcel this cast will hopefully become unnecessary. */ 3559130803Smarcel type = init_type (TYPE_CODE_NAMESPACE, 0, 0, 3560130803Smarcel (char *) processing_current_prefix, 3561130803Smarcel objfile); 3562130803Smarcel TYPE_TAG_NAME (type) = TYPE_NAME (type); 3563130803Smarcel 3564130803Smarcel new_symbol (die, type, cu); 3565130803Smarcel die->type = type; 3566130803Smarcel 3567130803Smarcel if (is_anonymous) 3568130803Smarcel cp_add_using_directive (processing_current_prefix, 3569130803Smarcel strlen (previous_prefix), 3570130803Smarcel strlen (processing_current_prefix)); 3571130803Smarcel } 3572130803Smarcel 3573130803Smarcel if (die->child != NULL) 3574130803Smarcel { 3575130803Smarcel struct die_info *child_die = die->child; 3576130803Smarcel 3577130803Smarcel while (child_die && child_die->tag) 3578130803Smarcel { 3579130803Smarcel process_die (child_die, cu); 3580130803Smarcel child_die = sibling_die (child_die); 3581130803Smarcel } 3582130803Smarcel } 3583130803Smarcel 3584130803Smarcel processing_current_prefix = previous_prefix; 3585130803Smarcel} 3586130803Smarcel 3587130803Smarcel/* Return the name of the namespace represented by DIE. Set 3588130803Smarcel *IS_ANONYMOUS to tell whether or not the namespace is an anonymous 3589130803Smarcel namespace. */ 3590130803Smarcel 3591130803Smarcelstatic const char * 3592130803Smarcelnamespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) 3593130803Smarcel{ 3594130803Smarcel struct die_info *current_die; 3595130803Smarcel const char *name = NULL; 3596130803Smarcel 3597130803Smarcel /* Loop through the extensions until we find a name. */ 3598130803Smarcel 3599130803Smarcel for (current_die = die; 3600130803Smarcel current_die != NULL; 3601130803Smarcel current_die = dwarf2_extension (die, cu)) 3602130803Smarcel { 3603130803Smarcel name = dwarf2_name (current_die, cu); 3604130803Smarcel if (name != NULL) 3605130803Smarcel break; 3606130803Smarcel } 3607130803Smarcel 3608130803Smarcel /* Is it an anonymous namespace? */ 3609130803Smarcel 3610130803Smarcel *is_anonymous = (name == NULL); 3611130803Smarcel if (*is_anonymous) 3612130803Smarcel name = "(anonymous namespace)"; 3613130803Smarcel 3614130803Smarcel return name; 3615130803Smarcel} 3616130803Smarcel 361746283Sdfr/* Extract all information from a DW_TAG_pointer_type DIE and add to 361846283Sdfr the user defined type vector. */ 361946283Sdfr 362046283Sdfrstatic void 3621130803Smarcelread_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) 362246283Sdfr{ 3623130803Smarcel struct comp_unit_head *cu_header = &cu->header; 362446283Sdfr struct type *type; 3625130803Smarcel struct attribute *attr_byte_size; 3626130803Smarcel struct attribute *attr_address_class; 3627130803Smarcel int byte_size, addr_class; 362846283Sdfr 362946283Sdfr if (die->type) 363046283Sdfr { 363146283Sdfr return; 363246283Sdfr } 363346283Sdfr 3634130803Smarcel type = lookup_pointer_type (die_type (die, cu)); 3635130803Smarcel 3636130803Smarcel attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); 3637130803Smarcel if (attr_byte_size) 3638130803Smarcel byte_size = DW_UNSND (attr_byte_size); 363946283Sdfr else 3640130803Smarcel byte_size = cu_header->addr_size; 3641130803Smarcel 3642130803Smarcel attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); 3643130803Smarcel if (attr_address_class) 3644130803Smarcel addr_class = DW_UNSND (attr_address_class); 3645130803Smarcel else 3646130803Smarcel addr_class = DW_ADDR_none; 3647130803Smarcel 3648130803Smarcel /* If the pointer size or address class is different than the 3649130803Smarcel default, create a type variant marked as such and set the 3650130803Smarcel length accordingly. */ 3651130803Smarcel if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) 365246283Sdfr { 3653130803Smarcel if (ADDRESS_CLASS_TYPE_FLAGS_P ()) 3654130803Smarcel { 3655130803Smarcel int type_flags; 3656130803Smarcel 3657130803Smarcel type_flags = ADDRESS_CLASS_TYPE_FLAGS (byte_size, addr_class); 3658130803Smarcel gdb_assert ((type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0); 3659130803Smarcel type = make_type_with_address_space (type, type_flags); 3660130803Smarcel } 3661130803Smarcel else if (TYPE_LENGTH (type) != byte_size) 3662130803Smarcel { 3663130803Smarcel complaint (&symfile_complaints, "invalid pointer size %d", byte_size); 3664130803Smarcel } 3665130803Smarcel else { 3666130803Smarcel /* Should we also complain about unhandled address classes? */ 3667130803Smarcel } 366846283Sdfr } 3669130803Smarcel 3670130803Smarcel TYPE_LENGTH (type) = byte_size; 367146283Sdfr die->type = type; 367246283Sdfr} 367346283Sdfr 367446283Sdfr/* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to 367546283Sdfr the user defined type vector. */ 367646283Sdfr 367746283Sdfrstatic void 3678130803Smarcelread_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) 367946283Sdfr{ 3680130803Smarcel struct objfile *objfile = cu->objfile; 368146283Sdfr struct type *type; 368246283Sdfr struct type *to_type; 368346283Sdfr struct type *domain; 368446283Sdfr 368546283Sdfr if (die->type) 368646283Sdfr { 368746283Sdfr return; 368846283Sdfr } 368946283Sdfr 369046283Sdfr type = alloc_type (objfile); 3691130803Smarcel to_type = die_type (die, cu); 3692130803Smarcel domain = die_containing_type (die, cu); 369346283Sdfr smash_to_member_type (type, domain, to_type); 369446283Sdfr 369546283Sdfr die->type = type; 369646283Sdfr} 369746283Sdfr 369846283Sdfr/* Extract all information from a DW_TAG_reference_type DIE and add to 369946283Sdfr the user defined type vector. */ 370046283Sdfr 370146283Sdfrstatic void 3702130803Smarcelread_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) 370346283Sdfr{ 3704130803Smarcel struct comp_unit_head *cu_header = &cu->header; 370546283Sdfr struct type *type; 370646283Sdfr struct attribute *attr; 370746283Sdfr 370846283Sdfr if (die->type) 370946283Sdfr { 371046283Sdfr return; 371146283Sdfr } 371246283Sdfr 3713130803Smarcel type = lookup_reference_type (die_type (die, cu)); 3714130803Smarcel attr = dwarf2_attr (die, DW_AT_byte_size, cu); 371546283Sdfr if (attr) 371646283Sdfr { 371746283Sdfr TYPE_LENGTH (type) = DW_UNSND (attr); 371846283Sdfr } 371946283Sdfr else 372046283Sdfr { 372198944Sobrien TYPE_LENGTH (type) = cu_header->addr_size; 372246283Sdfr } 372346283Sdfr die->type = type; 372446283Sdfr} 372546283Sdfr 372646283Sdfrstatic void 3727251667Semasteread_tag_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) 3728251667Semaste{ 3729251667Semaste struct objfile *objfile = cu->objfile; 3730251667Semaste struct type *type; 3731251667Semaste struct attribute *attr; 3732251667Semaste 3733251667Semaste if (die->type) 3734251667Semaste { 3735251667Semaste return; 3736251667Semaste } 3737251667Semaste 3738251667Semaste type = alloc_type (objfile); 3739251667Semaste TYPE_LENGTH (type) = 0; 3740251667Semaste attr = dwarf2_attr (die, DW_AT_name, cu); 3741251667Semaste if (attr && DW_STRING (attr)) 3742251667Semaste TYPE_NAME (type) = DW_STRING (attr); 3743251667Semaste 3744251667Semaste die->type = type; 3745251667Semaste} 3746251667Semaste 3747251667Semastestatic void 3748130803Smarcelread_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) 374946283Sdfr{ 375098944Sobrien struct type *base_type; 375198944Sobrien 375246283Sdfr if (die->type) 375346283Sdfr { 375446283Sdfr return; 375546283Sdfr } 375646283Sdfr 3757130803Smarcel base_type = die_type (die, cu); 3758244437Semaste die->type = make_cvr_type (1, TYPE_VOLATILE (base_type), 3759244437Semaste TYPE_RESTRICT (base_type), base_type, 0); 376046283Sdfr} 376146283Sdfr 376246283Sdfrstatic void 3763130803Smarcelread_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) 376446283Sdfr{ 376598944Sobrien struct type *base_type; 376698944Sobrien 376746283Sdfr if (die->type) 376846283Sdfr { 376946283Sdfr return; 377046283Sdfr } 377146283Sdfr 3772130803Smarcel base_type = die_type (die, cu); 3773244437Semaste die->type = make_cvr_type (TYPE_CONST (base_type), 1, 3774244437Semaste TYPE_RESTRICT (base_type), base_type, 0); 377546283Sdfr} 377646283Sdfr 3777244437Semastestatic void 3778244437Semasteread_tag_restrict_type (struct die_info *die, struct dwarf2_cu *cu) 3779244437Semaste{ 3780244437Semaste struct type *base_type; 3781244437Semaste 3782244437Semaste if (die->type) 3783244437Semaste { 3784244437Semaste return; 3785244437Semaste } 3786244437Semaste 3787244437Semaste base_type = die_type (die, cu); 3788244437Semaste die->type = make_cvr_type (TYPE_CONST (base_type), TYPE_VOLATILE (base_type), 3789244437Semaste 1, base_type, 0); 3790244437Semaste} 3791244437Semaste 379246283Sdfr/* Extract all information from a DW_TAG_string_type DIE and add to 379346283Sdfr the user defined type vector. It isn't really a user defined type, 379446283Sdfr but it behaves like one, with other DIE's using an AT_user_def_type 379546283Sdfr attribute to reference it. */ 379646283Sdfr 379746283Sdfrstatic void 3798130803Smarcelread_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) 379946283Sdfr{ 3800130803Smarcel struct objfile *objfile = cu->objfile; 380146283Sdfr struct type *type, *range_type, *index_type, *char_type; 380246283Sdfr struct attribute *attr; 380346283Sdfr unsigned int length; 380446283Sdfr 380546283Sdfr if (die->type) 380646283Sdfr { 380746283Sdfr return; 380846283Sdfr } 380946283Sdfr 3810130803Smarcel attr = dwarf2_attr (die, DW_AT_string_length, cu); 381146283Sdfr if (attr) 381246283Sdfr { 381346283Sdfr length = DW_UNSND (attr); 381446283Sdfr } 381546283Sdfr else 381646283Sdfr { 381798944Sobrien /* check for the DW_AT_byte_size attribute */ 3818130803Smarcel attr = dwarf2_attr (die, DW_AT_byte_size, cu); 381998944Sobrien if (attr) 382098944Sobrien { 382198944Sobrien length = DW_UNSND (attr); 382298944Sobrien } 382398944Sobrien else 382498944Sobrien { 382598944Sobrien length = 1; 382698944Sobrien } 382746283Sdfr } 3828130803Smarcel index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu); 382946283Sdfr range_type = create_range_type (NULL, index_type, 1, length); 3830130803Smarcel if (cu->language == language_fortran) 383198944Sobrien { 383298944Sobrien /* Need to create a unique string type for bounds 383398944Sobrien information */ 383498944Sobrien type = create_string_type (0, range_type); 383598944Sobrien } 383698944Sobrien else 383798944Sobrien { 3838130803Smarcel char_type = dwarf2_fundamental_type (objfile, FT_CHAR, cu); 383998944Sobrien type = create_string_type (char_type, range_type); 384098944Sobrien } 384146283Sdfr die->type = type; 384246283Sdfr} 384346283Sdfr 384446283Sdfr/* Handle DIES due to C code like: 384546283Sdfr 384646283Sdfr struct foo 384798944Sobrien { 384898944Sobrien int (*funcp)(int a, long l); 384998944Sobrien int b; 385098944Sobrien }; 385146283Sdfr 385246283Sdfr ('funcp' generates a DW_TAG_subroutine_type DIE) 385398944Sobrien */ 385446283Sdfr 385546283Sdfrstatic void 3856130803Smarcelread_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) 385746283Sdfr{ 385846283Sdfr struct type *type; /* Type that this function returns */ 385946283Sdfr struct type *ftype; /* Function that returns above type */ 386046283Sdfr struct attribute *attr; 386146283Sdfr 386246283Sdfr /* Decode the type that this subroutine returns */ 386346283Sdfr if (die->type) 386446283Sdfr { 386546283Sdfr return; 386646283Sdfr } 3867130803Smarcel type = die_type (die, cu); 386846283Sdfr ftype = lookup_function_type (type); 386946283Sdfr 387046283Sdfr /* All functions in C++ have prototypes. */ 3871130803Smarcel attr = dwarf2_attr (die, DW_AT_prototyped, cu); 387246283Sdfr if ((attr && (DW_UNSND (attr) != 0)) 3873130803Smarcel || cu->language == language_cplus) 387446283Sdfr TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED; 387546283Sdfr 3876130803Smarcel if (die->child != NULL) 387746283Sdfr { 387846283Sdfr struct die_info *child_die; 387946283Sdfr int nparams = 0; 388046283Sdfr int iparams = 0; 388146283Sdfr 388246283Sdfr /* Count the number of parameters. 388346283Sdfr FIXME: GDB currently ignores vararg functions, but knows about 388446283Sdfr vararg member functions. */ 3885130803Smarcel child_die = die->child; 388646283Sdfr while (child_die && child_die->tag) 388746283Sdfr { 388846283Sdfr if (child_die->tag == DW_TAG_formal_parameter) 388946283Sdfr nparams++; 389046283Sdfr else if (child_die->tag == DW_TAG_unspecified_parameters) 389146283Sdfr TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS; 389246283Sdfr child_die = sibling_die (child_die); 389346283Sdfr } 389446283Sdfr 389546283Sdfr /* Allocate storage for parameters and fill them in. */ 389646283Sdfr TYPE_NFIELDS (ftype) = nparams; 389746283Sdfr TYPE_FIELDS (ftype) = (struct field *) 389846283Sdfr TYPE_ALLOC (ftype, nparams * sizeof (struct field)); 389946283Sdfr 3900130803Smarcel child_die = die->child; 390146283Sdfr while (child_die && child_die->tag) 390246283Sdfr { 390346283Sdfr if (child_die->tag == DW_TAG_formal_parameter) 390446283Sdfr { 390546283Sdfr /* Dwarf2 has no clean way to discern C++ static and non-static 390698944Sobrien member functions. G++ helps GDB by marking the first 390798944Sobrien parameter for non-static member functions (which is the 390898944Sobrien this pointer) as artificial. We pass this information 390998944Sobrien to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */ 3910130803Smarcel attr = dwarf2_attr (child_die, DW_AT_artificial, cu); 391146283Sdfr if (attr) 391246283Sdfr TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); 391346283Sdfr else 391446283Sdfr TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; 3915130803Smarcel TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu); 391646283Sdfr iparams++; 391746283Sdfr } 391846283Sdfr child_die = sibling_die (child_die); 391946283Sdfr } 392046283Sdfr } 392146283Sdfr 392246283Sdfr die->type = ftype; 392346283Sdfr} 392446283Sdfr 392546283Sdfrstatic void 3926130803Smarcelread_typedef (struct die_info *die, struct dwarf2_cu *cu) 392746283Sdfr{ 3928130803Smarcel struct objfile *objfile = cu->objfile; 392998944Sobrien struct attribute *attr; 393098944Sobrien char *name = NULL; 393146283Sdfr 393246283Sdfr if (!die->type) 393346283Sdfr { 3934130803Smarcel attr = dwarf2_attr (die, DW_AT_name, cu); 393546283Sdfr if (attr && DW_STRING (attr)) 393698944Sobrien { 393798944Sobrien name = DW_STRING (attr); 393898944Sobrien } 393998944Sobrien die->type = init_type (TYPE_CODE_TYPEDEF, 0, TYPE_FLAG_TARGET_STUB, name, objfile); 3940130803Smarcel TYPE_TARGET_TYPE (die->type) = die_type (die, cu); 394146283Sdfr } 394246283Sdfr} 394346283Sdfr 394446283Sdfr/* Find a representation of a given base type and install 394546283Sdfr it in the TYPE field of the die. */ 394646283Sdfr 394746283Sdfrstatic void 3948130803Smarcelread_base_type (struct die_info *die, struct dwarf2_cu *cu) 394946283Sdfr{ 3950130803Smarcel struct objfile *objfile = cu->objfile; 395146283Sdfr struct type *type; 395246283Sdfr struct attribute *attr; 395346283Sdfr int encoding = 0, size = 0; 395446283Sdfr 395546283Sdfr /* If we've already decoded this die, this is a no-op. */ 395646283Sdfr if (die->type) 395746283Sdfr { 395846283Sdfr return; 395946283Sdfr } 396046283Sdfr 3961130803Smarcel attr = dwarf2_attr (die, DW_AT_encoding, cu); 396246283Sdfr if (attr) 396346283Sdfr { 396446283Sdfr encoding = DW_UNSND (attr); 396546283Sdfr } 3966130803Smarcel attr = dwarf2_attr (die, DW_AT_byte_size, cu); 396746283Sdfr if (attr) 396846283Sdfr { 396946283Sdfr size = DW_UNSND (attr); 397046283Sdfr } 3971130803Smarcel attr = dwarf2_attr (die, DW_AT_name, cu); 397246283Sdfr if (attr && DW_STRING (attr)) 397346283Sdfr { 397446283Sdfr enum type_code code = TYPE_CODE_INT; 397598944Sobrien int type_flags = 0; 397646283Sdfr 397746283Sdfr switch (encoding) 397846283Sdfr { 397946283Sdfr case DW_ATE_address: 398046283Sdfr /* Turn DW_ATE_address into a void * pointer. */ 398146283Sdfr code = TYPE_CODE_PTR; 398298944Sobrien type_flags |= TYPE_FLAG_UNSIGNED; 398346283Sdfr break; 398446283Sdfr case DW_ATE_boolean: 398546283Sdfr code = TYPE_CODE_BOOL; 398698944Sobrien type_flags |= TYPE_FLAG_UNSIGNED; 398746283Sdfr break; 398846283Sdfr case DW_ATE_complex_float: 398946283Sdfr code = TYPE_CODE_COMPLEX; 399046283Sdfr break; 399146283Sdfr case DW_ATE_float: 399246283Sdfr code = TYPE_CODE_FLT; 399346283Sdfr break; 399446283Sdfr case DW_ATE_signed: 399546283Sdfr case DW_ATE_signed_char: 399646283Sdfr break; 399746283Sdfr case DW_ATE_unsigned: 399846283Sdfr case DW_ATE_unsigned_char: 399998944Sobrien type_flags |= TYPE_FLAG_UNSIGNED; 400046283Sdfr break; 400146283Sdfr default: 4002130803Smarcel complaint (&symfile_complaints, "unsupported DW_AT_encoding: '%s'", 4003130803Smarcel dwarf_type_encoding_name (encoding)); 400446283Sdfr break; 400546283Sdfr } 400698944Sobrien type = init_type (code, size, type_flags, DW_STRING (attr), objfile); 400746283Sdfr if (encoding == DW_ATE_address) 4008130803Smarcel TYPE_TARGET_TYPE (type) = dwarf2_fundamental_type (objfile, FT_VOID, 4009130803Smarcel cu); 4010130803Smarcel else if (encoding == DW_ATE_complex_float) 4011130803Smarcel { 4012130803Smarcel if (size == 32) 4013130803Smarcel TYPE_TARGET_TYPE (type) 4014130803Smarcel = dwarf2_fundamental_type (objfile, FT_EXT_PREC_FLOAT, cu); 4015130803Smarcel else if (size == 16) 4016130803Smarcel TYPE_TARGET_TYPE (type) 4017130803Smarcel = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu); 4018130803Smarcel else if (size == 8) 4019130803Smarcel TYPE_TARGET_TYPE (type) 4020130803Smarcel = dwarf2_fundamental_type (objfile, FT_FLOAT, cu); 4021130803Smarcel } 402246283Sdfr } 402346283Sdfr else 402446283Sdfr { 4025130803Smarcel type = dwarf_base_type (encoding, size, cu); 402646283Sdfr } 402746283Sdfr die->type = type; 402846283Sdfr} 402946283Sdfr 4030130803Smarcel/* Read the given DW_AT_subrange DIE. */ 4031130803Smarcel 4032130803Smarcelstatic void 4033130803Smarcelread_subrange_type (struct die_info *die, struct dwarf2_cu *cu) 4034130803Smarcel{ 4035130803Smarcel struct type *base_type; 4036130803Smarcel struct type *range_type; 4037130803Smarcel struct attribute *attr; 4038130803Smarcel int low = 0; 4039130803Smarcel int high = -1; 4040130803Smarcel 4041130803Smarcel /* If we have already decoded this die, then nothing more to do. */ 4042130803Smarcel if (die->type) 4043130803Smarcel return; 4044130803Smarcel 4045130803Smarcel base_type = die_type (die, cu); 4046130803Smarcel if (base_type == NULL) 4047130803Smarcel { 4048130803Smarcel complaint (&symfile_complaints, 4049130803Smarcel "DW_AT_type missing from DW_TAG_subrange_type"); 4050130803Smarcel return; 4051130803Smarcel } 4052130803Smarcel 4053130803Smarcel if (TYPE_CODE (base_type) == TYPE_CODE_VOID) 4054130803Smarcel base_type = alloc_type (NULL); 4055130803Smarcel 4056130803Smarcel if (cu->language == language_fortran) 4057130803Smarcel { 4058130803Smarcel /* FORTRAN implies a lower bound of 1, if not given. */ 4059130803Smarcel low = 1; 4060130803Smarcel } 4061130803Smarcel 4062130803Smarcel attr = dwarf2_attr (die, DW_AT_lower_bound, cu); 4063130803Smarcel if (attr) 4064130803Smarcel low = dwarf2_get_attr_constant_value (attr, 0); 4065130803Smarcel 4066130803Smarcel attr = dwarf2_attr (die, DW_AT_upper_bound, cu); 4067130803Smarcel if (attr) 4068130803Smarcel { 4069130803Smarcel if (attr->form == DW_FORM_block1) 4070130803Smarcel { 4071130803Smarcel /* GCC encodes arrays with unspecified or dynamic length 4072130803Smarcel with a DW_FORM_block1 attribute. 4073130803Smarcel FIXME: GDB does not yet know how to handle dynamic 4074130803Smarcel arrays properly, treat them as arrays with unspecified 4075130803Smarcel length for now. 4076130803Smarcel 4077130803Smarcel FIXME: jimb/2003-09-22: GDB does not really know 4078130803Smarcel how to handle arrays of unspecified length 4079130803Smarcel either; we just represent them as zero-length 4080130803Smarcel arrays. Choose an appropriate upper bound given 4081130803Smarcel the lower bound we've computed above. */ 4082130803Smarcel high = low - 1; 4083130803Smarcel } 4084130803Smarcel else 4085130803Smarcel high = dwarf2_get_attr_constant_value (attr, 1); 4086130803Smarcel } 4087130803Smarcel 4088130803Smarcel range_type = create_range_type (NULL, base_type, low, high); 4089130803Smarcel 4090130803Smarcel attr = dwarf2_attr (die, DW_AT_name, cu); 4091130803Smarcel if (attr && DW_STRING (attr)) 4092130803Smarcel TYPE_NAME (range_type) = DW_STRING (attr); 4093130803Smarcel 4094130803Smarcel attr = dwarf2_attr (die, DW_AT_byte_size, cu); 4095130803Smarcel if (attr) 4096130803Smarcel TYPE_LENGTH (range_type) = DW_UNSND (attr); 4097130803Smarcel 4098130803Smarcel die->type = range_type; 4099130803Smarcel} 4100130803Smarcel 4101130803Smarcel 410246283Sdfr/* Read a whole compilation unit into a linked list of dies. */ 410346283Sdfr 410498944Sobrienstatic struct die_info * 4105130803Smarcelread_comp_unit (char *info_ptr, bfd *abfd, struct dwarf2_cu *cu) 410646283Sdfr{ 410798944Sobrien /* Reset die reference table; we are 410898944Sobrien building new ones now. */ 410998944Sobrien dwarf2_empty_hash_tables (); 411046283Sdfr 4111130803Smarcel return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL); 4112130803Smarcel} 4113130803Smarcel 4114130803Smarcel/* Read a single die and all its descendents. Set the die's sibling 4115130803Smarcel field to NULL; set other fields in the die correctly, and set all 4116130803Smarcel of the descendents' fields correctly. Set *NEW_INFO_PTR to the 4117130803Smarcel location of the info_ptr after reading all of those dies. PARENT 4118130803Smarcel is the parent of the die in question. */ 4119130803Smarcel 4120130803Smarcelstatic struct die_info * 4121130803Smarcelread_die_and_children (char *info_ptr, bfd *abfd, 4122130803Smarcel struct dwarf2_cu *cu, 4123130803Smarcel char **new_info_ptr, 4124130803Smarcel struct die_info *parent) 4125130803Smarcel{ 4126130803Smarcel struct die_info *die; 4127130803Smarcel char *cur_ptr; 4128130803Smarcel int has_children; 4129130803Smarcel 4130130803Smarcel cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children); 4131130803Smarcel store_in_ref_table (die->offset, die); 4132130803Smarcel 4133130803Smarcel if (has_children) 4134130803Smarcel { 4135130803Smarcel die->child = read_die_and_siblings (cur_ptr, abfd, cu, 4136130803Smarcel new_info_ptr, die); 4137130803Smarcel } 4138130803Smarcel else 4139130803Smarcel { 4140130803Smarcel die->child = NULL; 4141130803Smarcel *new_info_ptr = cur_ptr; 4142130803Smarcel } 4143130803Smarcel 4144130803Smarcel die->sibling = NULL; 4145130803Smarcel die->parent = parent; 4146130803Smarcel return die; 4147130803Smarcel} 4148130803Smarcel 4149130803Smarcel/* Read a die, all of its descendents, and all of its siblings; set 4150130803Smarcel all of the fields of all of the dies correctly. Arguments are as 4151130803Smarcel in read_die_and_children. */ 4152130803Smarcel 4153130803Smarcelstatic struct die_info * 4154130803Smarcelread_die_and_siblings (char *info_ptr, bfd *abfd, 4155130803Smarcel struct dwarf2_cu *cu, 4156130803Smarcel char **new_info_ptr, 4157130803Smarcel struct die_info *parent) 4158130803Smarcel{ 4159130803Smarcel struct die_info *first_die, *last_sibling; 4160130803Smarcel char *cur_ptr; 4161130803Smarcel 416246283Sdfr cur_ptr = info_ptr; 4163130803Smarcel first_die = last_sibling = NULL; 4164130803Smarcel 4165130803Smarcel while (1) 416646283Sdfr { 4167130803Smarcel struct die_info *die 4168130803Smarcel = read_die_and_children (cur_ptr, abfd, cu, &cur_ptr, parent); 4169130803Smarcel 4170130803Smarcel if (!first_die) 417146283Sdfr { 4172130803Smarcel first_die = die; 417346283Sdfr } 4174130803Smarcel else 417546283Sdfr { 4176130803Smarcel last_sibling->sibling = die; 417746283Sdfr } 417846283Sdfr 4179130803Smarcel if (die->tag == 0) 418046283Sdfr { 4181130803Smarcel *new_info_ptr = cur_ptr; 4182130803Smarcel return first_die; 418346283Sdfr } 418446283Sdfr else 418546283Sdfr { 4186130803Smarcel last_sibling = die; 418746283Sdfr } 418846283Sdfr } 418946283Sdfr} 419046283Sdfr 419146283Sdfr/* Free a linked list of dies. */ 419246283Sdfr 419346283Sdfrstatic void 419498944Sobrienfree_die_list (struct die_info *dies) 419546283Sdfr{ 419646283Sdfr struct die_info *die, *next; 419746283Sdfr 419846283Sdfr die = dies; 419946283Sdfr while (die) 420046283Sdfr { 4201130803Smarcel if (die->child != NULL) 4202130803Smarcel free_die_list (die->child); 4203130803Smarcel next = die->sibling; 420498944Sobrien xfree (die->attrs); 420598944Sobrien xfree (die); 420646283Sdfr die = next; 420746283Sdfr } 420846283Sdfr} 420946283Sdfr 421098944Sobrienstatic void 421198944Sobriendo_free_die_list_cleanup (void *dies) 421298944Sobrien{ 421398944Sobrien free_die_list (dies); 421498944Sobrien} 421598944Sobrien 421698944Sobrienstatic struct cleanup * 421798944Sobrienmake_cleanup_free_die_list (struct die_info *dies) 421898944Sobrien{ 421998944Sobrien return make_cleanup (do_free_die_list_cleanup, dies); 422098944Sobrien} 422198944Sobrien 422298944Sobrien 422346283Sdfr/* Read the contents of the section at OFFSET and of size SIZE from the 4224130803Smarcel object file specified by OBJFILE into the objfile_obstack and return it. */ 422546283Sdfr 422698944Sobrienchar * 4227130803Smarceldwarf2_read_section (struct objfile *objfile, asection *sectp) 422846283Sdfr{ 422946283Sdfr bfd *abfd = objfile->obfd; 4230130803Smarcel char *buf, *retbuf; 4231218822Sdim bfd_size_type size = bfd_get_section_size (sectp); 423246283Sdfr 423346283Sdfr if (size == 0) 423446283Sdfr return NULL; 423546283Sdfr 4236130803Smarcel buf = (char *) obstack_alloc (&objfile->objfile_obstack, size); 4237130803Smarcel retbuf 4238130803Smarcel = (char *) symfile_relocate_debug_section (abfd, sectp, (bfd_byte *) buf); 4239130803Smarcel if (retbuf != NULL) 4240130803Smarcel return retbuf; 4241130803Smarcel 4242130803Smarcel if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 4243130803Smarcel || bfd_bread (buf, size, abfd) != size) 4244130803Smarcel error ("Dwarf Error: Can't read DWARF data from '%s'", 4245130803Smarcel bfd_get_filename (abfd)); 4246130803Smarcel 424746283Sdfr return buf; 424846283Sdfr} 424946283Sdfr 425046283Sdfr/* In DWARF version 2, the description of the debugging information is 425146283Sdfr stored in a separate .debug_abbrev section. Before we read any 425246283Sdfr dies from a section we read in all abbreviations and install them 425346283Sdfr in a hash table. */ 425446283Sdfr 425546283Sdfrstatic void 4256130803Smarceldwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) 425746283Sdfr{ 4258130803Smarcel struct comp_unit_head *cu_header = &cu->header; 425946283Sdfr char *abbrev_ptr; 426046283Sdfr struct abbrev_info *cur_abbrev; 426146283Sdfr unsigned int abbrev_number, bytes_read, abbrev_name; 426246283Sdfr unsigned int abbrev_form, hash_number; 426346283Sdfr 4264130803Smarcel /* Initialize dwarf2 abbrevs */ 4265130803Smarcel memset (cu_header->dwarf2_abbrevs, 0, 4266130803Smarcel ABBREV_HASH_SIZE*sizeof (struct abbrev_info *)); 426746283Sdfr 4268130803Smarcel abbrev_ptr = dwarf_abbrev_buffer + cu_header->abbrev_offset; 426946283Sdfr abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); 427046283Sdfr abbrev_ptr += bytes_read; 427146283Sdfr 427246283Sdfr /* loop until we reach an abbrev number of 0 */ 427346283Sdfr while (abbrev_number) 427446283Sdfr { 427546283Sdfr cur_abbrev = dwarf_alloc_abbrev (); 427646283Sdfr 427746283Sdfr /* read in abbrev header */ 427846283Sdfr cur_abbrev->number = abbrev_number; 427946283Sdfr cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); 428046283Sdfr abbrev_ptr += bytes_read; 428146283Sdfr cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); 428246283Sdfr abbrev_ptr += 1; 428346283Sdfr 428446283Sdfr /* now read in declarations */ 428546283Sdfr abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); 428646283Sdfr abbrev_ptr += bytes_read; 428746283Sdfr abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); 428846283Sdfr abbrev_ptr += bytes_read; 428946283Sdfr while (abbrev_name) 429046283Sdfr { 429146283Sdfr if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0) 429246283Sdfr { 429346283Sdfr cur_abbrev->attrs = (struct attr_abbrev *) 429446283Sdfr xrealloc (cur_abbrev->attrs, 429546283Sdfr (cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK) 429698944Sobrien * sizeof (struct attr_abbrev)); 429746283Sdfr } 429846283Sdfr cur_abbrev->attrs[cur_abbrev->num_attrs].name = abbrev_name; 429946283Sdfr cur_abbrev->attrs[cur_abbrev->num_attrs++].form = abbrev_form; 430046283Sdfr abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); 430146283Sdfr abbrev_ptr += bytes_read; 430246283Sdfr abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); 430346283Sdfr abbrev_ptr += bytes_read; 430446283Sdfr } 430546283Sdfr 430646283Sdfr hash_number = abbrev_number % ABBREV_HASH_SIZE; 4307130803Smarcel cur_abbrev->next = cu_header->dwarf2_abbrevs[hash_number]; 4308130803Smarcel cu_header->dwarf2_abbrevs[hash_number] = cur_abbrev; 430946283Sdfr 431046283Sdfr /* Get next abbreviation. 431146283Sdfr Under Irix6 the abbreviations for a compilation unit are not 431298944Sobrien always properly terminated with an abbrev number of 0. 431398944Sobrien Exit loop if we encounter an abbreviation which we have 431498944Sobrien already read (which means we are about to read the abbreviations 431598944Sobrien for the next compile unit) or if the end of the abbreviation 431698944Sobrien table is reached. */ 431746283Sdfr if ((unsigned int) (abbrev_ptr - dwarf_abbrev_buffer) 431898944Sobrien >= dwarf_abbrev_size) 431946283Sdfr break; 432046283Sdfr abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); 432146283Sdfr abbrev_ptr += bytes_read; 4322130803Smarcel if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) 432346283Sdfr break; 432446283Sdfr } 432546283Sdfr} 432646283Sdfr 432746283Sdfr/* Empty the abbrev table for a new compilation unit. */ 432846283Sdfr 432946283Sdfrstatic void 4330130803Smarceldwarf2_empty_abbrev_table (void *ptr_to_abbrevs_table) 433146283Sdfr{ 433246283Sdfr int i; 433346283Sdfr struct abbrev_info *abbrev, *next; 4334130803Smarcel struct abbrev_info **abbrevs; 433546283Sdfr 4336130803Smarcel abbrevs = (struct abbrev_info **)ptr_to_abbrevs_table; 4337130803Smarcel 433846283Sdfr for (i = 0; i < ABBREV_HASH_SIZE; ++i) 433946283Sdfr { 434046283Sdfr next = NULL; 4341130803Smarcel abbrev = abbrevs[i]; 434246283Sdfr while (abbrev) 434346283Sdfr { 434446283Sdfr next = abbrev->next; 434598944Sobrien xfree (abbrev->attrs); 434698944Sobrien xfree (abbrev); 434746283Sdfr abbrev = next; 434846283Sdfr } 4349130803Smarcel abbrevs[i] = NULL; 435046283Sdfr } 435146283Sdfr} 435246283Sdfr 435346283Sdfr/* Lookup an abbrev_info structure in the abbrev hash table. */ 435446283Sdfr 435546283Sdfrstatic struct abbrev_info * 4356130803Smarceldwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) 435746283Sdfr{ 4358130803Smarcel struct comp_unit_head *cu_header = &cu->header; 435946283Sdfr unsigned int hash_number; 436046283Sdfr struct abbrev_info *abbrev; 436146283Sdfr 436246283Sdfr hash_number = number % ABBREV_HASH_SIZE; 4363130803Smarcel abbrev = cu_header->dwarf2_abbrevs[hash_number]; 436446283Sdfr 436546283Sdfr while (abbrev) 436646283Sdfr { 436746283Sdfr if (abbrev->number == number) 436846283Sdfr return abbrev; 436946283Sdfr else 437046283Sdfr abbrev = abbrev->next; 437146283Sdfr } 437246283Sdfr return NULL; 437346283Sdfr} 437446283Sdfr 437546283Sdfr/* Read a minimal amount of information into the minimal die structure. */ 437646283Sdfr 437746283Sdfrstatic char * 437898944Sobrienread_partial_die (struct partial_die_info *part_die, bfd *abfd, 4379130803Smarcel char *info_ptr, struct dwarf2_cu *cu) 438046283Sdfr{ 438146283Sdfr unsigned int abbrev_number, bytes_read, i; 438246283Sdfr struct abbrev_info *abbrev; 438346283Sdfr struct attribute attr; 438446283Sdfr struct attribute spec_attr; 438546283Sdfr int found_spec_attr = 0; 438698944Sobrien int has_low_pc_attr = 0; 438746283Sdfr int has_high_pc_attr = 0; 438846283Sdfr 438946283Sdfr *part_die = zeroed_partial_die; 439046283Sdfr abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); 439146283Sdfr info_ptr += bytes_read; 439246283Sdfr if (!abbrev_number) 439346283Sdfr return info_ptr; 439446283Sdfr 4395130803Smarcel abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); 439646283Sdfr if (!abbrev) 439746283Sdfr { 4398130803Smarcel error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number, 4399130803Smarcel bfd_get_filename (abfd)); 440046283Sdfr } 440146283Sdfr part_die->offset = info_ptr - dwarf_info_buffer; 440246283Sdfr part_die->tag = abbrev->tag; 440346283Sdfr part_die->has_children = abbrev->has_children; 440446283Sdfr part_die->abbrev = abbrev_number; 440546283Sdfr 440646283Sdfr for (i = 0; i < abbrev->num_attrs; ++i) 440746283Sdfr { 4408130803Smarcel info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); 440946283Sdfr 441046283Sdfr /* Store the data if it is of an attribute we want to keep in a 441198944Sobrien partial symbol table. */ 441246283Sdfr switch (attr.name) 441346283Sdfr { 441446283Sdfr case DW_AT_name: 441546283Sdfr 441646283Sdfr /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */ 441746283Sdfr if (part_die->name == NULL) 441846283Sdfr part_die->name = DW_STRING (&attr); 441946283Sdfr break; 442046283Sdfr case DW_AT_MIPS_linkage_name: 442146283Sdfr part_die->name = DW_STRING (&attr); 442246283Sdfr break; 442346283Sdfr case DW_AT_low_pc: 442446283Sdfr has_low_pc_attr = 1; 442546283Sdfr part_die->lowpc = DW_ADDR (&attr); 442646283Sdfr break; 442746283Sdfr case DW_AT_high_pc: 442846283Sdfr has_high_pc_attr = 1; 442946283Sdfr part_die->highpc = DW_ADDR (&attr); 443046283Sdfr break; 443146283Sdfr case DW_AT_location: 4432130803Smarcel /* Support the .debug_loc offsets */ 4433130803Smarcel if (attr_form_is_block (&attr)) 4434130803Smarcel { 4435130803Smarcel part_die->locdesc = DW_BLOCK (&attr); 4436130803Smarcel } 4437130803Smarcel else if (attr.form == DW_FORM_data4 || attr.form == DW_FORM_data8) 4438130803Smarcel { 4439130803Smarcel dwarf2_complex_location_expr_complaint (); 4440130803Smarcel } 4441130803Smarcel else 4442130803Smarcel { 4443130803Smarcel dwarf2_invalid_attrib_class_complaint ("DW_AT_location", 4444130803Smarcel "partial symbol information"); 4445130803Smarcel } 444646283Sdfr break; 444746283Sdfr case DW_AT_language: 444846283Sdfr part_die->language = DW_UNSND (&attr); 444946283Sdfr break; 445046283Sdfr case DW_AT_external: 445146283Sdfr part_die->is_external = DW_UNSND (&attr); 445246283Sdfr break; 445346283Sdfr case DW_AT_declaration: 445446283Sdfr part_die->is_declaration = DW_UNSND (&attr); 445546283Sdfr break; 445646283Sdfr case DW_AT_type: 445746283Sdfr part_die->has_type = 1; 445846283Sdfr break; 445946283Sdfr case DW_AT_abstract_origin: 446046283Sdfr case DW_AT_specification: 446146283Sdfr found_spec_attr = 1; 446246283Sdfr spec_attr = attr; 446346283Sdfr break; 446446283Sdfr case DW_AT_sibling: 446546283Sdfr /* Ignore absolute siblings, they might point outside of 446646283Sdfr the current compile unit. */ 446746283Sdfr if (attr.form == DW_FORM_ref_addr) 4468130803Smarcel complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling"); 446946283Sdfr else 447046283Sdfr part_die->sibling = 4471130803Smarcel dwarf_info_buffer + dwarf2_get_ref_die_offset (&attr, cu); 447246283Sdfr break; 447346283Sdfr default: 447446283Sdfr break; 447546283Sdfr } 447646283Sdfr } 447746283Sdfr 447846283Sdfr /* If we found a reference attribute and the die has no name, try 447946283Sdfr to find a name in the referred to die. */ 448046283Sdfr 448146283Sdfr if (found_spec_attr && part_die->name == NULL) 448246283Sdfr { 448346283Sdfr struct partial_die_info spec_die; 448446283Sdfr char *spec_ptr; 448546283Sdfr 4486130803Smarcel spec_ptr = dwarf_info_buffer 4487130803Smarcel + dwarf2_get_ref_die_offset (&spec_attr, cu); 4488130803Smarcel read_partial_die (&spec_die, abfd, spec_ptr, cu); 448946283Sdfr if (spec_die.name) 449046283Sdfr { 449146283Sdfr part_die->name = spec_die.name; 449246283Sdfr 449346283Sdfr /* Copy DW_AT_external attribute if it is set. */ 449446283Sdfr if (spec_die.is_external) 449546283Sdfr part_die->is_external = spec_die.is_external; 449646283Sdfr } 449746283Sdfr } 449846283Sdfr 449946283Sdfr /* When using the GNU linker, .gnu.linkonce. sections are used to 450046283Sdfr eliminate duplicate copies of functions and vtables and such. 450146283Sdfr The linker will arbitrarily choose one and discard the others. 450246283Sdfr The AT_*_pc values for such functions refer to local labels in 450346283Sdfr these sections. If the section from that file was discarded, the 450446283Sdfr labels are not in the output, so the relocs get a value of 0. 450546283Sdfr If this is a discarded function, mark the pc bounds as invalid, 450646283Sdfr so that GDB will ignore it. */ 450746283Sdfr if (has_low_pc_attr && has_high_pc_attr 450846283Sdfr && part_die->lowpc < part_die->highpc 450946283Sdfr && (part_die->lowpc != 0 451046283Sdfr || (bfd_get_file_flags (abfd) & HAS_RELOC))) 451198944Sobrien part_die->has_pc_info = 1; 451246283Sdfr return info_ptr; 451346283Sdfr} 451446283Sdfr 4515130803Smarcel/* Read the die from the .debug_info section buffer. Set DIEP to 4516130803Smarcel point to a newly allocated die with its information, except for its 4517130803Smarcel child, sibling, and parent fields. Set HAS_CHILDREN to tell 4518130803Smarcel whether the die has children or not. */ 451946283Sdfr 452046283Sdfrstatic char * 452198944Sobrienread_full_die (struct die_info **diep, bfd *abfd, char *info_ptr, 4522130803Smarcel struct dwarf2_cu *cu, int *has_children) 452346283Sdfr{ 452446283Sdfr unsigned int abbrev_number, bytes_read, i, offset; 452546283Sdfr struct abbrev_info *abbrev; 452646283Sdfr struct die_info *die; 452746283Sdfr 452846283Sdfr offset = info_ptr - dwarf_info_buffer; 452946283Sdfr abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); 453046283Sdfr info_ptr += bytes_read; 453146283Sdfr if (!abbrev_number) 453246283Sdfr { 453346283Sdfr die = dwarf_alloc_die (); 453446283Sdfr die->tag = 0; 453546283Sdfr die->abbrev = abbrev_number; 453646283Sdfr die->type = NULL; 453746283Sdfr *diep = die; 4538130803Smarcel *has_children = 0; 453946283Sdfr return info_ptr; 454046283Sdfr } 454146283Sdfr 4542130803Smarcel abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); 454346283Sdfr if (!abbrev) 454446283Sdfr { 4545130803Smarcel error ("Dwarf Error: could not find abbrev number %d [in module %s]", 4546130803Smarcel abbrev_number, 4547130803Smarcel bfd_get_filename (abfd)); 454846283Sdfr } 454946283Sdfr die = dwarf_alloc_die (); 455046283Sdfr die->offset = offset; 455146283Sdfr die->tag = abbrev->tag; 455246283Sdfr die->abbrev = abbrev_number; 455346283Sdfr die->type = NULL; 455446283Sdfr 455546283Sdfr die->num_attrs = abbrev->num_attrs; 455646283Sdfr die->attrs = (struct attribute *) 455746283Sdfr xmalloc (die->num_attrs * sizeof (struct attribute)); 455846283Sdfr 455946283Sdfr for (i = 0; i < abbrev->num_attrs; ++i) 456046283Sdfr { 456146283Sdfr info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], 4562130803Smarcel abfd, info_ptr, cu); 456346283Sdfr } 456446283Sdfr 456546283Sdfr *diep = die; 4566130803Smarcel *has_children = abbrev->has_children; 456746283Sdfr return info_ptr; 456846283Sdfr} 456946283Sdfr 457098944Sobrien/* Read an attribute value described by an attribute form. */ 457146283Sdfr 457246283Sdfrstatic char * 457398944Sobrienread_attribute_value (struct attribute *attr, unsigned form, 4574130803Smarcel bfd *abfd, char *info_ptr, 4575130803Smarcel struct dwarf2_cu *cu) 457646283Sdfr{ 4577130803Smarcel struct comp_unit_head *cu_header = &cu->header; 457846283Sdfr unsigned int bytes_read; 457946283Sdfr struct dwarf_block *blk; 458046283Sdfr 458198944Sobrien attr->form = form; 458298944Sobrien switch (form) 458346283Sdfr { 458446283Sdfr case DW_FORM_addr: 458546283Sdfr case DW_FORM_ref_addr: 4586130803Smarcel DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); 458798944Sobrien info_ptr += bytes_read; 458846283Sdfr break; 458946283Sdfr case DW_FORM_block2: 459046283Sdfr blk = dwarf_alloc_block (); 459146283Sdfr blk->size = read_2_bytes (abfd, info_ptr); 459246283Sdfr info_ptr += 2; 459346283Sdfr blk->data = read_n_bytes (abfd, info_ptr, blk->size); 459446283Sdfr info_ptr += blk->size; 459546283Sdfr DW_BLOCK (attr) = blk; 459646283Sdfr break; 459746283Sdfr case DW_FORM_block4: 459846283Sdfr blk = dwarf_alloc_block (); 459946283Sdfr blk->size = read_4_bytes (abfd, info_ptr); 460046283Sdfr info_ptr += 4; 460146283Sdfr blk->data = read_n_bytes (abfd, info_ptr, blk->size); 460246283Sdfr info_ptr += blk->size; 460346283Sdfr DW_BLOCK (attr) = blk; 460446283Sdfr break; 460546283Sdfr case DW_FORM_data2: 460646283Sdfr DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); 460746283Sdfr info_ptr += 2; 460846283Sdfr break; 460946283Sdfr case DW_FORM_data4: 461046283Sdfr DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); 461146283Sdfr info_ptr += 4; 461246283Sdfr break; 461346283Sdfr case DW_FORM_data8: 461446283Sdfr DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); 461546283Sdfr info_ptr += 8; 461646283Sdfr break; 461746283Sdfr case DW_FORM_string: 461846283Sdfr DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read); 461946283Sdfr info_ptr += bytes_read; 462046283Sdfr break; 462198944Sobrien case DW_FORM_strp: 462298944Sobrien DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, 462398944Sobrien &bytes_read); 462498944Sobrien info_ptr += bytes_read; 462598944Sobrien break; 462646283Sdfr case DW_FORM_block: 462746283Sdfr blk = dwarf_alloc_block (); 462846283Sdfr blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); 462946283Sdfr info_ptr += bytes_read; 463046283Sdfr blk->data = read_n_bytes (abfd, info_ptr, blk->size); 463146283Sdfr info_ptr += blk->size; 463246283Sdfr DW_BLOCK (attr) = blk; 463346283Sdfr break; 463446283Sdfr case DW_FORM_block1: 463546283Sdfr blk = dwarf_alloc_block (); 463646283Sdfr blk->size = read_1_byte (abfd, info_ptr); 463746283Sdfr info_ptr += 1; 463846283Sdfr blk->data = read_n_bytes (abfd, info_ptr, blk->size); 463946283Sdfr info_ptr += blk->size; 464046283Sdfr DW_BLOCK (attr) = blk; 464146283Sdfr break; 464246283Sdfr case DW_FORM_data1: 464346283Sdfr DW_UNSND (attr) = read_1_byte (abfd, info_ptr); 464446283Sdfr info_ptr += 1; 464546283Sdfr break; 464646283Sdfr case DW_FORM_flag: 464746283Sdfr DW_UNSND (attr) = read_1_byte (abfd, info_ptr); 464846283Sdfr info_ptr += 1; 464946283Sdfr break; 4650239870Sdim case DW_FORM_flag_present: 4651239870Sdim DW_UNSND (attr) = 1; 4652239870Sdim break; 465346283Sdfr case DW_FORM_sdata: 465446283Sdfr DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); 465546283Sdfr info_ptr += bytes_read; 465646283Sdfr break; 465746283Sdfr case DW_FORM_udata: 465846283Sdfr DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); 465946283Sdfr info_ptr += bytes_read; 466046283Sdfr break; 466146283Sdfr case DW_FORM_ref1: 466246283Sdfr DW_UNSND (attr) = read_1_byte (abfd, info_ptr); 466346283Sdfr info_ptr += 1; 466446283Sdfr break; 466546283Sdfr case DW_FORM_ref2: 466646283Sdfr DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); 466746283Sdfr info_ptr += 2; 466846283Sdfr break; 466946283Sdfr case DW_FORM_ref4: 467046283Sdfr DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); 467146283Sdfr info_ptr += 4; 467246283Sdfr break; 467398944Sobrien case DW_FORM_ref8: 467498944Sobrien DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); 467598944Sobrien info_ptr += 8; 467698944Sobrien break; 467746283Sdfr case DW_FORM_ref_udata: 467846283Sdfr DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); 467946283Sdfr info_ptr += bytes_read; 468046283Sdfr break; 468146283Sdfr case DW_FORM_indirect: 468298944Sobrien form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); 468398944Sobrien info_ptr += bytes_read; 4684130803Smarcel info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); 468598944Sobrien break; 468646283Sdfr default: 4687130803Smarcel error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]", 4688130803Smarcel dwarf_form_name (form), 4689130803Smarcel bfd_get_filename (abfd)); 469046283Sdfr } 469146283Sdfr return info_ptr; 469246283Sdfr} 469346283Sdfr 469498944Sobrien/* Read an attribute described by an abbreviated attribute. */ 469598944Sobrien 469698944Sobrienstatic char * 469798944Sobrienread_attribute (struct attribute *attr, struct attr_abbrev *abbrev, 4698130803Smarcel bfd *abfd, char *info_ptr, struct dwarf2_cu *cu) 469998944Sobrien{ 470098944Sobrien attr->name = abbrev->name; 4701130803Smarcel return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); 470298944Sobrien} 470398944Sobrien 470446283Sdfr/* read dwarf information from a buffer */ 470546283Sdfr 470646283Sdfrstatic unsigned int 470798944Sobrienread_1_byte (bfd *abfd, char *buf) 470846283Sdfr{ 470946283Sdfr return bfd_get_8 (abfd, (bfd_byte *) buf); 471046283Sdfr} 471146283Sdfr 471246283Sdfrstatic int 471398944Sobrienread_1_signed_byte (bfd *abfd, char *buf) 471446283Sdfr{ 471546283Sdfr return bfd_get_signed_8 (abfd, (bfd_byte *) buf); 471646283Sdfr} 471746283Sdfr 471846283Sdfrstatic unsigned int 471998944Sobrienread_2_bytes (bfd *abfd, char *buf) 472046283Sdfr{ 472146283Sdfr return bfd_get_16 (abfd, (bfd_byte *) buf); 472246283Sdfr} 472346283Sdfr 472446283Sdfrstatic int 472598944Sobrienread_2_signed_bytes (bfd *abfd, char *buf) 472646283Sdfr{ 472746283Sdfr return bfd_get_signed_16 (abfd, (bfd_byte *) buf); 472846283Sdfr} 472946283Sdfr 473046283Sdfrstatic unsigned int 473198944Sobrienread_4_bytes (bfd *abfd, char *buf) 473246283Sdfr{ 473346283Sdfr return bfd_get_32 (abfd, (bfd_byte *) buf); 473446283Sdfr} 473546283Sdfr 473646283Sdfrstatic int 473798944Sobrienread_4_signed_bytes (bfd *abfd, char *buf) 473846283Sdfr{ 473946283Sdfr return bfd_get_signed_32 (abfd, (bfd_byte *) buf); 474046283Sdfr} 474146283Sdfr 474298944Sobrienstatic unsigned long 474398944Sobrienread_8_bytes (bfd *abfd, char *buf) 474446283Sdfr{ 474546283Sdfr return bfd_get_64 (abfd, (bfd_byte *) buf); 474646283Sdfr} 474746283Sdfr 474846283Sdfrstatic CORE_ADDR 4749130803Smarcelread_address (bfd *abfd, char *buf, struct dwarf2_cu *cu, int *bytes_read) 475046283Sdfr{ 4751130803Smarcel struct comp_unit_head *cu_header = &cu->header; 475246283Sdfr CORE_ADDR retval = 0; 475346283Sdfr 475498944Sobrien if (cu_header->signed_addr_p) 475546283Sdfr { 475698944Sobrien switch (cu_header->addr_size) 475798944Sobrien { 475898944Sobrien case 2: 475998944Sobrien retval = bfd_get_signed_16 (abfd, (bfd_byte *) buf); 476098944Sobrien break; 476198944Sobrien case 4: 476298944Sobrien retval = bfd_get_signed_32 (abfd, (bfd_byte *) buf); 476398944Sobrien break; 476498944Sobrien case 8: 476598944Sobrien retval = bfd_get_signed_64 (abfd, (bfd_byte *) buf); 476698944Sobrien break; 476798944Sobrien default: 476898944Sobrien internal_error (__FILE__, __LINE__, 4769130803Smarcel "read_address: bad switch, signed [in module %s]", 4770130803Smarcel bfd_get_filename (abfd)); 477198944Sobrien } 477298944Sobrien } 477398944Sobrien else 477498944Sobrien { 477598944Sobrien switch (cu_header->addr_size) 477698944Sobrien { 477798944Sobrien case 2: 477898944Sobrien retval = bfd_get_16 (abfd, (bfd_byte *) buf); 477998944Sobrien break; 478098944Sobrien case 4: 478198944Sobrien retval = bfd_get_32 (abfd, (bfd_byte *) buf); 478298944Sobrien break; 478398944Sobrien case 8: 478498944Sobrien retval = bfd_get_64 (abfd, (bfd_byte *) buf); 478598944Sobrien break; 478698944Sobrien default: 478798944Sobrien internal_error (__FILE__, __LINE__, 4788130803Smarcel "read_address: bad switch, unsigned [in module %s]", 4789130803Smarcel bfd_get_filename (abfd)); 479098944Sobrien } 479198944Sobrien } 479298944Sobrien 479398944Sobrien *bytes_read = cu_header->addr_size; 479498944Sobrien return retval; 479598944Sobrien} 479698944Sobrien 4797130803Smarcel/* Read the initial length from a section. The (draft) DWARF 3 479898944Sobrien specification allows the initial length to take up either 4 bytes 479998944Sobrien or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 480098944Sobrien bytes describe the length and all offsets will be 8 bytes in length 480198944Sobrien instead of 4. 480298944Sobrien 4803130803Smarcel An older, non-standard 64-bit format is also handled by this 4804130803Smarcel function. The older format in question stores the initial length 4805130803Smarcel as an 8-byte quantity without an escape value. Lengths greater 4806130803Smarcel than 2^32 aren't very common which means that the initial 4 bytes 4807130803Smarcel is almost always zero. Since a length value of zero doesn't make 4808130803Smarcel sense for the 32-bit format, this initial zero can be considered to 4809130803Smarcel be an escape value which indicates the presence of the older 64-bit 4810130803Smarcel format. As written, the code can't detect (old format) lengths 4811130803Smarcel greater than 4GB. If it becomes necessary to handle lengths somewhat 4812130803Smarcel larger than 4GB, we could allow other small values (such as the 4813130803Smarcel non-sensical values of 1, 2, and 3) to also be used as escape values 4814130803Smarcel indicating the presence of the old format. 4815130803Smarcel 481698944Sobrien The value returned via bytes_read should be used to increment 481798944Sobrien the relevant pointer after calling read_initial_length(). 481898944Sobrien 481998944Sobrien As a side effect, this function sets the fields initial_length_size 482098944Sobrien and offset_size in cu_header to the values appropriate for the 482198944Sobrien length field. (The format of the initial length field determines 482298944Sobrien the width of file offsets to be fetched later with fetch_offset().) 482398944Sobrien 482498944Sobrien [ Note: read_initial_length() and read_offset() are based on the 482598944Sobrien document entitled "DWARF Debugging Information Format", revision 4826130803Smarcel 3, draft 8, dated November 19, 2001. This document was obtained 482798944Sobrien from: 482898944Sobrien 4829130803Smarcel http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf 483098944Sobrien 483198944Sobrien This document is only a draft and is subject to change. (So beware.) 483298944Sobrien 4833130803Smarcel Details regarding the older, non-standard 64-bit format were 4834130803Smarcel determined empirically by examining 64-bit ELF files produced 4835130803Smarcel by the SGI toolchain on an IRIX 6.5 machine. 4836130803Smarcel 4837130803Smarcel - Kevin, July 16, 2002 483898944Sobrien ] */ 483998944Sobrien 484098944Sobrienstatic LONGEST 484198944Sobrienread_initial_length (bfd *abfd, char *buf, struct comp_unit_head *cu_header, 484298944Sobrien int *bytes_read) 484398944Sobrien{ 484498944Sobrien LONGEST retval = 0; 484598944Sobrien 484698944Sobrien retval = bfd_get_32 (abfd, (bfd_byte *) buf); 484798944Sobrien 484898944Sobrien if (retval == 0xffffffff) 484998944Sobrien { 485098944Sobrien retval = bfd_get_64 (abfd, (bfd_byte *) buf + 4); 485198944Sobrien *bytes_read = 12; 485298944Sobrien if (cu_header != NULL) 485398944Sobrien { 485498944Sobrien cu_header->initial_length_size = 12; 485598944Sobrien cu_header->offset_size = 8; 485698944Sobrien } 485798944Sobrien } 4858130803Smarcel else if (retval == 0) 4859130803Smarcel { 4860130803Smarcel /* Handle (non-standard) 64-bit DWARF2 formats such as that used 4861130803Smarcel by IRIX. */ 4862130803Smarcel retval = bfd_get_64 (abfd, (bfd_byte *) buf); 4863130803Smarcel *bytes_read = 8; 4864130803Smarcel if (cu_header != NULL) 4865130803Smarcel { 4866130803Smarcel cu_header->initial_length_size = 8; 4867130803Smarcel cu_header->offset_size = 8; 4868130803Smarcel } 4869130803Smarcel } 487098944Sobrien else 487198944Sobrien { 487298944Sobrien *bytes_read = 4; 487398944Sobrien if (cu_header != NULL) 487498944Sobrien { 487598944Sobrien cu_header->initial_length_size = 4; 487698944Sobrien cu_header->offset_size = 4; 487798944Sobrien } 487898944Sobrien } 487998944Sobrien 488098944Sobrien return retval; 488198944Sobrien} 488298944Sobrien 488398944Sobrien/* Read an offset from the data stream. The size of the offset is 488498944Sobrien given by cu_header->offset_size. */ 488598944Sobrien 488698944Sobrienstatic LONGEST 488798944Sobrienread_offset (bfd *abfd, char *buf, const struct comp_unit_head *cu_header, 488898944Sobrien int *bytes_read) 488998944Sobrien{ 489098944Sobrien LONGEST retval = 0; 489198944Sobrien 489298944Sobrien switch (cu_header->offset_size) 489398944Sobrien { 489446283Sdfr case 4: 489546283Sdfr retval = bfd_get_32 (abfd, (bfd_byte *) buf); 489698944Sobrien *bytes_read = 4; 489746283Sdfr break; 489846283Sdfr case 8: 489946283Sdfr retval = bfd_get_64 (abfd, (bfd_byte *) buf); 490098944Sobrien *bytes_read = 8; 490146283Sdfr break; 490246283Sdfr default: 490398944Sobrien internal_error (__FILE__, __LINE__, 4904130803Smarcel "read_offset: bad switch [in module %s]", 4905130803Smarcel bfd_get_filename (abfd)); 490646283Sdfr } 490798944Sobrien 490898944Sobrien return retval; 490946283Sdfr} 491046283Sdfr 491146283Sdfrstatic char * 491298944Sobrienread_n_bytes (bfd *abfd, char *buf, unsigned int size) 491346283Sdfr{ 491446283Sdfr /* If the size of a host char is 8 bits, we can return a pointer 491546283Sdfr to the buffer, otherwise we have to copy the data to a buffer 491646283Sdfr allocated on the temporary obstack. */ 491798944Sobrien gdb_assert (HOST_CHAR_BIT == 8); 491846283Sdfr return buf; 491946283Sdfr} 492046283Sdfr 492146283Sdfrstatic char * 492298944Sobrienread_string (bfd *abfd, char *buf, unsigned int *bytes_read_ptr) 492346283Sdfr{ 492446283Sdfr /* If the size of a host char is 8 bits, we can return a pointer 492546283Sdfr to the string, otherwise we have to copy the string to a buffer 492646283Sdfr allocated on the temporary obstack. */ 492798944Sobrien gdb_assert (HOST_CHAR_BIT == 8); 492846283Sdfr if (*buf == '\0') 492946283Sdfr { 493046283Sdfr *bytes_read_ptr = 1; 493146283Sdfr return NULL; 493246283Sdfr } 493346283Sdfr *bytes_read_ptr = strlen (buf) + 1; 493446283Sdfr return buf; 493598944Sobrien} 493646283Sdfr 493798944Sobrienstatic char * 493898944Sobrienread_indirect_string (bfd *abfd, char *buf, 493998944Sobrien const struct comp_unit_head *cu_header, 494098944Sobrien unsigned int *bytes_read_ptr) 494198944Sobrien{ 494298944Sobrien LONGEST str_offset = read_offset (abfd, buf, cu_header, 494398944Sobrien (int *) bytes_read_ptr); 494498944Sobrien 494598944Sobrien if (dwarf_str_buffer == NULL) 494646283Sdfr { 4947130803Smarcel error ("DW_FORM_strp used without .debug_str section [in module %s]", 4948130803Smarcel bfd_get_filename (abfd)); 494998944Sobrien return NULL; 495046283Sdfr } 495198944Sobrien if (str_offset >= dwarf_str_size) 495246283Sdfr { 4953130803Smarcel error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]", 4954130803Smarcel bfd_get_filename (abfd)); 495546283Sdfr return NULL; 495646283Sdfr } 495798944Sobrien gdb_assert (HOST_CHAR_BIT == 8); 495898944Sobrien if (dwarf_str_buffer[str_offset] == '\0') 495998944Sobrien return NULL; 496098944Sobrien return dwarf_str_buffer + str_offset; 496146283Sdfr} 496246283Sdfr 496398944Sobrienstatic unsigned long 496498944Sobrienread_unsigned_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr) 496546283Sdfr{ 496698944Sobrien unsigned long result; 496798944Sobrien unsigned int num_read; 496846283Sdfr int i, shift; 496946283Sdfr unsigned char byte; 497046283Sdfr 497146283Sdfr result = 0; 497246283Sdfr shift = 0; 497346283Sdfr num_read = 0; 497446283Sdfr i = 0; 497546283Sdfr while (1) 497646283Sdfr { 497746283Sdfr byte = bfd_get_8 (abfd, (bfd_byte *) buf); 497846283Sdfr buf++; 497946283Sdfr num_read++; 498098944Sobrien result |= ((unsigned long)(byte & 127) << shift); 498146283Sdfr if ((byte & 128) == 0) 498246283Sdfr { 498346283Sdfr break; 498446283Sdfr } 498546283Sdfr shift += 7; 498646283Sdfr } 498746283Sdfr *bytes_read_ptr = num_read; 498846283Sdfr return result; 498946283Sdfr} 499046283Sdfr 499198944Sobrienstatic long 499298944Sobrienread_signed_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr) 499346283Sdfr{ 499498944Sobrien long result; 499546283Sdfr int i, shift, size, num_read; 499646283Sdfr unsigned char byte; 499746283Sdfr 499846283Sdfr result = 0; 499946283Sdfr shift = 0; 500046283Sdfr size = 32; 500146283Sdfr num_read = 0; 500246283Sdfr i = 0; 500346283Sdfr while (1) 500446283Sdfr { 500546283Sdfr byte = bfd_get_8 (abfd, (bfd_byte *) buf); 500646283Sdfr buf++; 500746283Sdfr num_read++; 500898944Sobrien result |= ((long)(byte & 127) << shift); 500946283Sdfr shift += 7; 501046283Sdfr if ((byte & 128) == 0) 501146283Sdfr { 501246283Sdfr break; 501346283Sdfr } 501446283Sdfr } 501546283Sdfr if ((shift < size) && (byte & 0x40)) 501646283Sdfr { 501746283Sdfr result |= -(1 << shift); 501846283Sdfr } 501946283Sdfr *bytes_read_ptr = num_read; 502046283Sdfr return result; 502146283Sdfr} 502246283Sdfr 502346283Sdfrstatic void 5024130803Smarcelset_cu_language (unsigned int lang, struct dwarf2_cu *cu) 502546283Sdfr{ 502646283Sdfr switch (lang) 502746283Sdfr { 502846283Sdfr case DW_LANG_C89: 502946283Sdfr case DW_LANG_C: 5030130803Smarcel cu->language = language_c; 503146283Sdfr break; 503246283Sdfr case DW_LANG_C_plus_plus: 5033130803Smarcel cu->language = language_cplus; 503446283Sdfr break; 503546283Sdfr case DW_LANG_Fortran77: 503646283Sdfr case DW_LANG_Fortran90: 503798944Sobrien case DW_LANG_Fortran95: 5038130803Smarcel cu->language = language_fortran; 503946283Sdfr break; 504046283Sdfr case DW_LANG_Mips_Assembler: 5041130803Smarcel cu->language = language_asm; 504246283Sdfr break; 504398944Sobrien case DW_LANG_Java: 5044130803Smarcel cu->language = language_java; 504598944Sobrien break; 504646283Sdfr case DW_LANG_Ada83: 5047130803Smarcel case DW_LANG_Ada95: 504846283Sdfr case DW_LANG_Cobol74: 504946283Sdfr case DW_LANG_Cobol85: 505046283Sdfr case DW_LANG_Pascal83: 505146283Sdfr case DW_LANG_Modula2: 505246283Sdfr default: 5053130803Smarcel cu->language = language_minimal; 505446283Sdfr break; 505546283Sdfr } 5056130803Smarcel cu->language_defn = language_def (cu->language); 505746283Sdfr} 505846283Sdfr 505946283Sdfr/* Return the named attribute or NULL if not there. */ 506046283Sdfr 506146283Sdfrstatic struct attribute * 5062130803Smarceldwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) 506346283Sdfr{ 506446283Sdfr unsigned int i; 506546283Sdfr struct attribute *spec = NULL; 506646283Sdfr 506746283Sdfr for (i = 0; i < die->num_attrs; ++i) 506846283Sdfr { 506946283Sdfr if (die->attrs[i].name == name) 507046283Sdfr { 507146283Sdfr return &die->attrs[i]; 507246283Sdfr } 507346283Sdfr if (die->attrs[i].name == DW_AT_specification 507446283Sdfr || die->attrs[i].name == DW_AT_abstract_origin) 507546283Sdfr spec = &die->attrs[i]; 507646283Sdfr } 507746283Sdfr if (spec) 507846283Sdfr { 507946283Sdfr struct die_info *ref_die = 5080130803Smarcel follow_die_ref (dwarf2_get_ref_die_offset (spec, cu)); 508146283Sdfr 508246283Sdfr if (ref_die) 5083130803Smarcel return dwarf2_attr (ref_die, name, cu); 508446283Sdfr } 508598944Sobrien 508646283Sdfr return NULL; 508746283Sdfr} 508846283Sdfr 508998944Sobrienstatic int 5090130803Smarceldie_is_declaration (struct die_info *die, struct dwarf2_cu *cu) 509198944Sobrien{ 5092130803Smarcel return (dwarf2_attr (die, DW_AT_declaration, cu) 5093130803Smarcel && ! dwarf2_attr (die, DW_AT_specification, cu)); 509498944Sobrien} 509598944Sobrien 5096130803Smarcel/* Return the die giving the specification for DIE, if there is 5097130803Smarcel one. */ 509846283Sdfr 5099130803Smarcelstatic struct die_info * 5100130803Smarceldie_specification (struct die_info *die, struct dwarf2_cu *cu) 510146283Sdfr{ 5102130803Smarcel struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, cu); 5103130803Smarcel 5104130803Smarcel if (spec_attr == NULL) 5105130803Smarcel return NULL; 5106130803Smarcel else 5107130803Smarcel return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr, cu)); 5108130803Smarcel} 5109130803Smarcel 5110130803Smarcel/* Free the line_header structure *LH, and any arrays and strings it 5111130803Smarcel refers to. */ 5112130803Smarcelstatic void 5113130803Smarcelfree_line_header (struct line_header *lh) 5114130803Smarcel{ 5115130803Smarcel if (lh->standard_opcode_lengths) 5116130803Smarcel xfree (lh->standard_opcode_lengths); 5117130803Smarcel 5118130803Smarcel /* Remember that all the lh->file_names[i].name pointers are 5119130803Smarcel pointers into debug_line_buffer, and don't need to be freed. */ 5120130803Smarcel if (lh->file_names) 5121130803Smarcel xfree (lh->file_names); 5122130803Smarcel 5123130803Smarcel /* Similarly for the include directory names. */ 5124130803Smarcel if (lh->include_dirs) 5125130803Smarcel xfree (lh->include_dirs); 5126130803Smarcel 5127130803Smarcel xfree (lh); 5128130803Smarcel} 5129130803Smarcel 5130130803Smarcel 5131130803Smarcel/* Add an entry to LH's include directory table. */ 5132130803Smarcelstatic void 5133130803Smarceladd_include_dir (struct line_header *lh, char *include_dir) 5134130803Smarcel{ 5135130803Smarcel /* Grow the array if necessary. */ 5136130803Smarcel if (lh->include_dirs_size == 0) 513798944Sobrien { 5138130803Smarcel lh->include_dirs_size = 1; /* for testing */ 5139130803Smarcel lh->include_dirs = xmalloc (lh->include_dirs_size 5140130803Smarcel * sizeof (*lh->include_dirs)); 514198944Sobrien } 5142130803Smarcel else if (lh->num_include_dirs >= lh->include_dirs_size) 5143130803Smarcel { 5144130803Smarcel lh->include_dirs_size *= 2; 5145130803Smarcel lh->include_dirs = xrealloc (lh->include_dirs, 5146130803Smarcel (lh->include_dirs_size 5147130803Smarcel * sizeof (*lh->include_dirs))); 5148130803Smarcel } 514946283Sdfr 5150130803Smarcel lh->include_dirs[lh->num_include_dirs++] = include_dir; 5151130803Smarcel} 5152130803Smarcel 515346283Sdfr 5154130803Smarcel/* Add an entry to LH's file name table. */ 515546283Sdfrstatic void 5156130803Smarceladd_file_name (struct line_header *lh, 5157130803Smarcel char *name, 5158130803Smarcel unsigned int dir_index, 5159130803Smarcel unsigned int mod_time, 5160130803Smarcel unsigned int length) 516146283Sdfr{ 5162130803Smarcel struct file_entry *fe; 516346283Sdfr 5164130803Smarcel /* Grow the array if necessary. */ 5165130803Smarcel if (lh->file_names_size == 0) 5166130803Smarcel { 5167130803Smarcel lh->file_names_size = 1; /* for testing */ 5168130803Smarcel lh->file_names = xmalloc (lh->file_names_size 5169130803Smarcel * sizeof (*lh->file_names)); 5170130803Smarcel } 5171130803Smarcel else if (lh->num_file_names >= lh->file_names_size) 5172130803Smarcel { 5173130803Smarcel lh->file_names_size *= 2; 5174130803Smarcel lh->file_names = xrealloc (lh->file_names, 5175130803Smarcel (lh->file_names_size 5176130803Smarcel * sizeof (*lh->file_names))); 5177130803Smarcel } 517846283Sdfr 5179130803Smarcel fe = &lh->file_names[lh->num_file_names++]; 5180130803Smarcel fe->name = name; 5181130803Smarcel fe->dir_index = dir_index; 5182130803Smarcel fe->mod_time = mod_time; 5183130803Smarcel fe->length = length; 5184130803Smarcel} 5185130803Smarcel 518646283Sdfr 5187130803Smarcel/* Read the statement program header starting at OFFSET in 5188130803Smarcel dwarf_line_buffer, according to the endianness of ABFD. Return a 5189130803Smarcel pointer to a struct line_header, allocated using xmalloc. 5190130803Smarcel 5191130803Smarcel NOTE: the strings in the include directory and file name tables of 5192130803Smarcel the returned object point into debug_line_buffer, and must not be 5193130803Smarcel freed. */ 5194130803Smarcelstatic struct line_header * 5195130803Smarceldwarf_decode_line_header (unsigned int offset, bfd *abfd, 5196130803Smarcel struct dwarf2_cu *cu) 5197130803Smarcel{ 5198130803Smarcel struct cleanup *back_to; 5199130803Smarcel struct line_header *lh; 5200130803Smarcel char *line_ptr; 5201130803Smarcel int bytes_read; 5202130803Smarcel int i; 5203130803Smarcel char *cur_dir, *cur_file; 5204130803Smarcel 520546283Sdfr if (dwarf_line_buffer == NULL) 520646283Sdfr { 5207130803Smarcel complaint (&symfile_complaints, "missing .debug_line section"); 5208130803Smarcel return 0; 520946283Sdfr } 521046283Sdfr 5211130803Smarcel /* Make sure that at least there's room for the total_length field. That 5212130803Smarcel could be 12 bytes long, but we're just going to fudge that. */ 5213130803Smarcel if (offset + 4 >= dwarf_line_size) 5214130803Smarcel { 5215130803Smarcel dwarf2_statement_list_fits_in_line_number_section_complaint (); 5216130803Smarcel return 0; 5217130803Smarcel } 521846283Sdfr 5219130803Smarcel lh = xmalloc (sizeof (*lh)); 5220130803Smarcel memset (lh, 0, sizeof (*lh)); 5221130803Smarcel back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, 5222130803Smarcel (void *) lh); 522346283Sdfr 522446283Sdfr line_ptr = dwarf_line_buffer + offset; 522546283Sdfr 5226130803Smarcel /* read in the header */ 5227214651Sgonzo lh->total_length = read_initial_length (abfd, line_ptr, &cu->header, &bytes_read); 522898944Sobrien line_ptr += bytes_read; 5229130803Smarcel if (line_ptr + lh->total_length > dwarf_line_buffer + dwarf_line_size) 5230130803Smarcel { 5231130803Smarcel dwarf2_statement_list_fits_in_line_number_section_complaint (); 5232130803Smarcel return 0; 5233130803Smarcel } 5234130803Smarcel lh->statement_program_end = line_ptr + lh->total_length; 5235130803Smarcel lh->version = read_2_bytes (abfd, line_ptr); 523646283Sdfr line_ptr += 2; 5237130803Smarcel lh->header_length = read_offset (abfd, line_ptr, &cu->header, &bytes_read); 523898944Sobrien line_ptr += bytes_read; 5239130803Smarcel lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); 524046283Sdfr line_ptr += 1; 5241130803Smarcel lh->default_is_stmt = read_1_byte (abfd, line_ptr); 524246283Sdfr line_ptr += 1; 5243130803Smarcel lh->line_base = read_1_signed_byte (abfd, line_ptr); 524446283Sdfr line_ptr += 1; 5245130803Smarcel lh->line_range = read_1_byte (abfd, line_ptr); 524646283Sdfr line_ptr += 1; 5247130803Smarcel lh->opcode_base = read_1_byte (abfd, line_ptr); 524846283Sdfr line_ptr += 1; 5249130803Smarcel lh->standard_opcode_lengths 5250130803Smarcel = (unsigned char *) xmalloc (lh->opcode_base * sizeof (unsigned char)); 525146283Sdfr 5252130803Smarcel lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ 5253130803Smarcel for (i = 1; i < lh->opcode_base; ++i) 525446283Sdfr { 5255130803Smarcel lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); 525646283Sdfr line_ptr += 1; 525746283Sdfr } 525846283Sdfr 525946283Sdfr /* Read directory table */ 526046283Sdfr while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL) 526146283Sdfr { 526246283Sdfr line_ptr += bytes_read; 5263130803Smarcel add_include_dir (lh, cur_dir); 526446283Sdfr } 526546283Sdfr line_ptr += bytes_read; 526646283Sdfr 526746283Sdfr /* Read file name table */ 526846283Sdfr while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL) 526946283Sdfr { 5270130803Smarcel unsigned int dir_index, mod_time, length; 5271130803Smarcel 527246283Sdfr line_ptr += bytes_read; 5273130803Smarcel dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); 527446283Sdfr line_ptr += bytes_read; 5275130803Smarcel mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); 527646283Sdfr line_ptr += bytes_read; 5277130803Smarcel length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); 527846283Sdfr line_ptr += bytes_read; 5279130803Smarcel 5280130803Smarcel add_file_name (lh, cur_file, dir_index, mod_time, length); 528146283Sdfr } 528246283Sdfr line_ptr += bytes_read; 5283130803Smarcel lh->statement_program_start = line_ptr; 528446283Sdfr 5285130803Smarcel if (line_ptr > dwarf_line_buffer + dwarf_line_size) 5286130803Smarcel complaint (&symfile_complaints, 5287130803Smarcel "line number info header doesn't fit in `.debug_line' section"); 5288130803Smarcel 5289130803Smarcel discard_cleanups (back_to); 5290130803Smarcel return lh; 5291130803Smarcel} 5292130803Smarcel 5293130803Smarcel/* This function exists to work around a bug in certain compilers 5294130803Smarcel (particularly GCC 2.95), in which the first line number marker of a 5295130803Smarcel function does not show up until after the prologue, right before 5296130803Smarcel the second line number marker. This function shifts ADDRESS down 5297130803Smarcel to the beginning of the function if necessary, and is called on 5298130803Smarcel addresses passed to record_line. */ 5299130803Smarcel 5300130803Smarcelstatic CORE_ADDR 5301130803Smarcelcheck_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) 5302130803Smarcel{ 5303130803Smarcel struct function_range *fn; 5304130803Smarcel 5305130803Smarcel /* Find the function_range containing address. */ 5306130803Smarcel if (!cu->first_fn) 5307130803Smarcel return address; 5308130803Smarcel 5309130803Smarcel if (!cu->cached_fn) 5310130803Smarcel cu->cached_fn = cu->first_fn; 5311130803Smarcel 5312130803Smarcel fn = cu->cached_fn; 5313130803Smarcel while (fn) 5314130803Smarcel if (fn->lowpc <= address && fn->highpc > address) 5315130803Smarcel goto found; 5316130803Smarcel else 5317130803Smarcel fn = fn->next; 5318130803Smarcel 5319130803Smarcel fn = cu->first_fn; 5320130803Smarcel while (fn && fn != cu->cached_fn) 5321130803Smarcel if (fn->lowpc <= address && fn->highpc > address) 5322130803Smarcel goto found; 5323130803Smarcel else 5324130803Smarcel fn = fn->next; 5325130803Smarcel 5326130803Smarcel return address; 5327130803Smarcel 5328130803Smarcel found: 5329130803Smarcel if (fn->seen_line) 5330130803Smarcel return address; 5331130803Smarcel if (address != fn->lowpc) 5332130803Smarcel complaint (&symfile_complaints, 5333130803Smarcel "misplaced first line number at 0x%lx for '%s'", 5334130803Smarcel (unsigned long) address, fn->name); 5335130803Smarcel fn->seen_line = 1; 5336130803Smarcel return fn->lowpc; 5337130803Smarcel} 5338130803Smarcel 5339130803Smarcel/* Decode the line number information for the compilation unit whose 5340130803Smarcel line number info is at OFFSET in the .debug_line section. 5341130803Smarcel The compilation directory of the file is passed in COMP_DIR. */ 5342130803Smarcel 5343130803Smarcelstatic void 5344130803Smarceldwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd, 5345130803Smarcel struct dwarf2_cu *cu) 5346130803Smarcel{ 5347130803Smarcel char *line_ptr; 5348130803Smarcel char *line_end; 5349130803Smarcel unsigned int bytes_read; 5350130803Smarcel unsigned char op_code, extended_op, adj_opcode; 5351130803Smarcel CORE_ADDR baseaddr; 5352130803Smarcel struct objfile *objfile = cu->objfile; 5353130803Smarcel 5354130803Smarcel baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 5355130803Smarcel 5356130803Smarcel line_ptr = lh->statement_program_start; 5357130803Smarcel line_end = lh->statement_program_end; 5358130803Smarcel 535946283Sdfr /* Read the statement sequences until there's nothing left. */ 536046283Sdfr while (line_ptr < line_end) 536146283Sdfr { 536246283Sdfr /* state machine registers */ 536346283Sdfr CORE_ADDR address = 0; 536446283Sdfr unsigned int file = 1; 536546283Sdfr unsigned int line = 1; 536646283Sdfr unsigned int column = 0; 5367130803Smarcel int is_stmt = lh->default_is_stmt; 536846283Sdfr int basic_block = 0; 536946283Sdfr int end_sequence = 0; 537046283Sdfr 537146283Sdfr /* Start a subfile for the current file of the state machine. */ 5372130803Smarcel if (lh->num_file_names >= file) 537346283Sdfr { 5374130803Smarcel /* lh->include_dirs and lh->file_names are 0-based, but the 5375130803Smarcel directory and file name numbers in the statement program 5376130803Smarcel are 1-based. */ 5377130803Smarcel struct file_entry *fe = &lh->file_names[file - 1]; 5378130803Smarcel char *dir; 5379130803Smarcel if (fe->dir_index) 5380130803Smarcel dir = lh->include_dirs[fe->dir_index - 1]; 5381130803Smarcel else 5382130803Smarcel dir = comp_dir; 5383130803Smarcel dwarf2_start_subfile (fe->name, dir); 538446283Sdfr } 538546283Sdfr 538646283Sdfr /* Decode the table. */ 538798944Sobrien while (!end_sequence) 538846283Sdfr { 538946283Sdfr op_code = read_1_byte (abfd, line_ptr); 539046283Sdfr line_ptr += 1; 539198944Sobrien 5392130803Smarcel if (op_code >= lh->opcode_base) 539398944Sobrien { /* Special operand. */ 5394130803Smarcel adj_opcode = op_code - lh->opcode_base; 5395130803Smarcel address += (adj_opcode / lh->line_range) 5396130803Smarcel * lh->minimum_instruction_length; 5397130803Smarcel line += lh->line_base + (adj_opcode % lh->line_range); 539898944Sobrien /* append row to matrix using current values */ 5399130803Smarcel record_line (current_subfile, line, 5400130803Smarcel check_cu_functions (address, cu)); 540198944Sobrien basic_block = 1; 540298944Sobrien } 540398944Sobrien else switch (op_code) 540446283Sdfr { 540546283Sdfr case DW_LNS_extended_op: 540646283Sdfr line_ptr += 1; /* ignore length */ 540746283Sdfr extended_op = read_1_byte (abfd, line_ptr); 540846283Sdfr line_ptr += 1; 540946283Sdfr switch (extended_op) 541046283Sdfr { 541146283Sdfr case DW_LNE_end_sequence: 541246283Sdfr end_sequence = 1; 5413130803Smarcel record_line (current_subfile, 0, address); 541446283Sdfr break; 541546283Sdfr case DW_LNE_set_address: 5416130803Smarcel address = read_address (abfd, line_ptr, cu, &bytes_read); 541798944Sobrien line_ptr += bytes_read; 541898944Sobrien address += baseaddr; 541946283Sdfr break; 542046283Sdfr case DW_LNE_define_file: 5421130803Smarcel { 5422130803Smarcel char *cur_file; 5423130803Smarcel unsigned int dir_index, mod_time, length; 5424130803Smarcel 5425130803Smarcel cur_file = read_string (abfd, line_ptr, &bytes_read); 5426130803Smarcel line_ptr += bytes_read; 5427130803Smarcel dir_index = 5428130803Smarcel read_unsigned_leb128 (abfd, line_ptr, &bytes_read); 5429130803Smarcel line_ptr += bytes_read; 5430130803Smarcel mod_time = 5431130803Smarcel read_unsigned_leb128 (abfd, line_ptr, &bytes_read); 5432130803Smarcel line_ptr += bytes_read; 5433130803Smarcel length = 5434130803Smarcel read_unsigned_leb128 (abfd, line_ptr, &bytes_read); 5435130803Smarcel line_ptr += bytes_read; 5436130803Smarcel add_file_name (lh, cur_file, dir_index, mod_time, length); 5437130803Smarcel } 543846283Sdfr break; 543946283Sdfr default: 5440130803Smarcel complaint (&symfile_complaints, 5441130803Smarcel "mangled .debug_line section"); 5442130803Smarcel return; 544346283Sdfr } 544446283Sdfr break; 544546283Sdfr case DW_LNS_copy: 5446130803Smarcel record_line (current_subfile, line, 5447130803Smarcel check_cu_functions (address, cu)); 544846283Sdfr basic_block = 0; 544946283Sdfr break; 545046283Sdfr case DW_LNS_advance_pc: 5451130803Smarcel address += lh->minimum_instruction_length 545246283Sdfr * read_unsigned_leb128 (abfd, line_ptr, &bytes_read); 545346283Sdfr line_ptr += bytes_read; 545446283Sdfr break; 545546283Sdfr case DW_LNS_advance_line: 545646283Sdfr line += read_signed_leb128 (abfd, line_ptr, &bytes_read); 545746283Sdfr line_ptr += bytes_read; 545846283Sdfr break; 545946283Sdfr case DW_LNS_set_file: 5460130803Smarcel { 5461130803Smarcel /* lh->include_dirs and lh->file_names are 0-based, 5462130803Smarcel but the directory and file name numbers in the 5463130803Smarcel statement program are 1-based. */ 5464130803Smarcel struct file_entry *fe; 5465130803Smarcel char *dir; 5466130803Smarcel file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); 5467130803Smarcel line_ptr += bytes_read; 5468130803Smarcel fe = &lh->file_names[file - 1]; 5469130803Smarcel if (fe->dir_index) 5470130803Smarcel dir = lh->include_dirs[fe->dir_index - 1]; 5471130803Smarcel else 5472130803Smarcel dir = comp_dir; 5473130803Smarcel dwarf2_start_subfile (fe->name, dir); 5474130803Smarcel } 547546283Sdfr break; 547646283Sdfr case DW_LNS_set_column: 547746283Sdfr column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); 547846283Sdfr line_ptr += bytes_read; 547946283Sdfr break; 548046283Sdfr case DW_LNS_negate_stmt: 548146283Sdfr is_stmt = (!is_stmt); 548246283Sdfr break; 548346283Sdfr case DW_LNS_set_basic_block: 548446283Sdfr basic_block = 1; 548546283Sdfr break; 548698944Sobrien /* Add to the address register of the state machine the 548798944Sobrien address increment value corresponding to special opcode 548898944Sobrien 255. Ie, this value is scaled by the minimum instruction 548998944Sobrien length since special opcode 255 would have scaled the 549098944Sobrien the increment. */ 549146283Sdfr case DW_LNS_const_add_pc: 5492130803Smarcel address += (lh->minimum_instruction_length 5493130803Smarcel * ((255 - lh->opcode_base) / lh->line_range)); 549446283Sdfr break; 549546283Sdfr case DW_LNS_fixed_advance_pc: 549646283Sdfr address += read_2_bytes (abfd, line_ptr); 549746283Sdfr line_ptr += 2; 549846283Sdfr break; 549998944Sobrien default: 550098944Sobrien { /* Unknown standard opcode, ignore it. */ 550198944Sobrien int i; 5502130803Smarcel for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) 550398944Sobrien { 550498944Sobrien (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); 550598944Sobrien line_ptr += bytes_read; 550698944Sobrien } 550798944Sobrien } 550846283Sdfr } 550946283Sdfr } 551046283Sdfr } 551146283Sdfr} 551246283Sdfr 551346283Sdfr/* Start a subfile for DWARF. FILENAME is the name of the file and 551446283Sdfr DIRNAME the name of the source directory which contains FILENAME 551546283Sdfr or NULL if not known. 551646283Sdfr This routine tries to keep line numbers from identical absolute and 551746283Sdfr relative file names in a common subfile. 551846283Sdfr 551946283Sdfr Using the `list' example from the GDB testsuite, which resides in 552046283Sdfr /srcdir and compiling it with Irix6.2 cc in /compdir using a filename 552146283Sdfr of /srcdir/list0.c yields the following debugging information for list0.c: 552246283Sdfr 552398944Sobrien DW_AT_name: /srcdir/list0.c 552498944Sobrien DW_AT_comp_dir: /compdir 552598944Sobrien files.files[0].name: list0.h 552698944Sobrien files.files[0].dir: /srcdir 552798944Sobrien files.files[1].name: list0.c 552898944Sobrien files.files[1].dir: /srcdir 552946283Sdfr 553046283Sdfr The line number information for list0.c has to end up in a single 553146283Sdfr subfile, so that `break /srcdir/list0.c:1' works as expected. */ 553246283Sdfr 553346283Sdfrstatic void 553498944Sobriendwarf2_start_subfile (char *filename, char *dirname) 553546283Sdfr{ 553646283Sdfr /* If the filename isn't absolute, try to match an existing subfile 553746283Sdfr with the full pathname. */ 553846283Sdfr 553998944Sobrien if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) 554046283Sdfr { 554146283Sdfr struct subfile *subfile; 554246283Sdfr char *fullname = concat (dirname, "/", filename, NULL); 554346283Sdfr 554446283Sdfr for (subfile = subfiles; subfile; subfile = subfile->next) 554546283Sdfr { 554698944Sobrien if (FILENAME_CMP (subfile->name, fullname) == 0) 554746283Sdfr { 554846283Sdfr current_subfile = subfile; 554998944Sobrien xfree (fullname); 555046283Sdfr return; 555146283Sdfr } 555246283Sdfr } 555398944Sobrien xfree (fullname); 555446283Sdfr } 555546283Sdfr start_subfile (filename, dirname); 555646283Sdfr} 555746283Sdfr 5558130803Smarcelstatic void 5559130803Smarcelvar_decode_location (struct attribute *attr, struct symbol *sym, 5560130803Smarcel struct dwarf2_cu *cu) 5561130803Smarcel{ 5562130803Smarcel struct objfile *objfile = cu->objfile; 5563130803Smarcel struct comp_unit_head *cu_header = &cu->header; 5564130803Smarcel 5565130803Smarcel /* NOTE drow/2003-01-30: There used to be a comment and some special 5566130803Smarcel code here to turn a symbol with DW_AT_external and a 5567130803Smarcel SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was 5568130803Smarcel necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux 5569130803Smarcel with some versions of binutils) where shared libraries could have 5570130803Smarcel relocations against symbols in their debug information - the 5571130803Smarcel minimal symbol would have the right address, but the debug info 5572130803Smarcel would not. It's no longer necessary, because we will explicitly 5573130803Smarcel apply relocations when we read in the debug information now. */ 5574130803Smarcel 5575130803Smarcel /* A DW_AT_location attribute with no contents indicates that a 5576130803Smarcel variable has been optimized away. */ 5577130803Smarcel if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) 5578130803Smarcel { 5579130803Smarcel SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; 5580130803Smarcel return; 5581130803Smarcel } 5582130803Smarcel 5583130803Smarcel /* Handle one degenerate form of location expression specially, to 5584130803Smarcel preserve GDB's previous behavior when section offsets are 5585130803Smarcel specified. If this is just a DW_OP_addr then mark this symbol 5586130803Smarcel as LOC_STATIC. */ 5587130803Smarcel 5588130803Smarcel if (attr_form_is_block (attr) 5589130803Smarcel && DW_BLOCK (attr)->size == 1 + cu_header->addr_size 5590130803Smarcel && DW_BLOCK (attr)->data[0] == DW_OP_addr) 5591130803Smarcel { 5592130803Smarcel int dummy; 5593130803Smarcel 5594130803Smarcel SYMBOL_VALUE_ADDRESS (sym) = 5595130803Smarcel read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); 5596130803Smarcel fixup_symbol_section (sym, objfile); 5597130803Smarcel SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, 5598130803Smarcel SYMBOL_SECTION (sym)); 5599130803Smarcel SYMBOL_CLASS (sym) = LOC_STATIC; 5600130803Smarcel return; 5601130803Smarcel } 5602130803Smarcel 5603130803Smarcel /* NOTE drow/2002-01-30: It might be worthwhile to have a static 5604130803Smarcel expression evaluator, and use LOC_COMPUTED only when necessary 5605130803Smarcel (i.e. when the value of a register or memory location is 5606130803Smarcel referenced, or a thread-local block, etc.). Then again, it might 5607130803Smarcel not be worthwhile. I'm assuming that it isn't unless performance 5608130803Smarcel or memory numbers show me otherwise. */ 5609130803Smarcel 5610130803Smarcel dwarf2_symbol_mark_computed (attr, sym, cu); 5611130803Smarcel SYMBOL_CLASS (sym) = LOC_COMPUTED; 5612130803Smarcel} 5613130803Smarcel 561446283Sdfr/* Given a pointer to a DWARF information entry, figure out if we need 561546283Sdfr to make a symbol table entry for it, and if so, create a new entry 561646283Sdfr and return a pointer to it. 561746283Sdfr If TYPE is NULL, determine symbol type from the die, otherwise 561898944Sobrien used the passed type. */ 561946283Sdfr 562046283Sdfrstatic struct symbol * 5621130803Smarcelnew_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) 562246283Sdfr{ 5623130803Smarcel struct objfile *objfile = cu->objfile; 562446283Sdfr struct symbol *sym = NULL; 562546283Sdfr char *name; 562646283Sdfr struct attribute *attr = NULL; 562746283Sdfr struct attribute *attr2 = NULL; 5628130803Smarcel CORE_ADDR baseaddr; 562946283Sdfr 5630130803Smarcel baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 5631130803Smarcel 5632130803Smarcel if (die->tag != DW_TAG_namespace) 5633130803Smarcel name = dwarf2_linkage_name (die, cu); 5634130803Smarcel else 5635130803Smarcel name = TYPE_NAME (type); 5636130803Smarcel 563746283Sdfr if (name) 563846283Sdfr { 5639130803Smarcel sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, 564046283Sdfr sizeof (struct symbol)); 564146283Sdfr OBJSTAT (objfile, n_syms++); 564246283Sdfr memset (sym, 0, sizeof (struct symbol)); 564346283Sdfr 5644130803Smarcel /* Cache this symbol's name and the name's demangled form (if any). */ 5645130803Smarcel SYMBOL_LANGUAGE (sym) = cu->language; 5646130803Smarcel SYMBOL_SET_NAMES (sym, name, strlen (name), objfile); 5647130803Smarcel 564846283Sdfr /* Default assumptions. 564998944Sobrien Use the passed type or decode it from the die. */ 5650130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 565146283Sdfr SYMBOL_CLASS (sym) = LOC_STATIC; 565246283Sdfr if (type != NULL) 565346283Sdfr SYMBOL_TYPE (sym) = type; 565446283Sdfr else 5655130803Smarcel SYMBOL_TYPE (sym) = die_type (die, cu); 5656130803Smarcel attr = dwarf2_attr (die, DW_AT_decl_line, cu); 565746283Sdfr if (attr) 565846283Sdfr { 565946283Sdfr SYMBOL_LINE (sym) = DW_UNSND (attr); 566046283Sdfr } 566146283Sdfr switch (die->tag) 566246283Sdfr { 566346283Sdfr case DW_TAG_label: 5664130803Smarcel attr = dwarf2_attr (die, DW_AT_low_pc, cu); 566546283Sdfr if (attr) 566646283Sdfr { 566746283Sdfr SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; 566846283Sdfr } 566946283Sdfr SYMBOL_CLASS (sym) = LOC_LABEL; 567046283Sdfr break; 567146283Sdfr case DW_TAG_subprogram: 567246283Sdfr /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by 567346283Sdfr finish_block. */ 567446283Sdfr SYMBOL_CLASS (sym) = LOC_BLOCK; 5675130803Smarcel attr2 = dwarf2_attr (die, DW_AT_external, cu); 567646283Sdfr if (attr2 && (DW_UNSND (attr2) != 0)) 567746283Sdfr { 567846283Sdfr add_symbol_to_list (sym, &global_symbols); 567946283Sdfr } 568046283Sdfr else 568146283Sdfr { 5682130803Smarcel add_symbol_to_list (sym, cu->list_in_scope); 568346283Sdfr } 568446283Sdfr break; 568546283Sdfr case DW_TAG_variable: 568646283Sdfr /* Compilation with minimal debug info may result in variables 568746283Sdfr with missing type entries. Change the misleading `void' type 568846283Sdfr to something sensible. */ 568946283Sdfr if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) 569046283Sdfr SYMBOL_TYPE (sym) = init_type (TYPE_CODE_INT, 569146283Sdfr TARGET_INT_BIT / HOST_CHAR_BIT, 0, 569246283Sdfr "<variable, no debug info>", 569346283Sdfr objfile); 5694130803Smarcel attr = dwarf2_attr (die, DW_AT_const_value, cu); 569546283Sdfr if (attr) 569646283Sdfr { 5697130803Smarcel dwarf2_const_value (attr, sym, cu); 5698130803Smarcel attr2 = dwarf2_attr (die, DW_AT_external, cu); 569946283Sdfr if (attr2 && (DW_UNSND (attr2) != 0)) 570046283Sdfr add_symbol_to_list (sym, &global_symbols); 570146283Sdfr else 5702130803Smarcel add_symbol_to_list (sym, cu->list_in_scope); 570346283Sdfr break; 570446283Sdfr } 5705130803Smarcel attr = dwarf2_attr (die, DW_AT_location, cu); 570646283Sdfr if (attr) 570746283Sdfr { 5708130803Smarcel var_decode_location (attr, sym, cu); 5709130803Smarcel attr2 = dwarf2_attr (die, DW_AT_external, cu); 571046283Sdfr if (attr2 && (DW_UNSND (attr2) != 0)) 5711130803Smarcel add_symbol_to_list (sym, &global_symbols); 571246283Sdfr else 5713130803Smarcel add_symbol_to_list (sym, cu->list_in_scope); 571446283Sdfr } 571546283Sdfr else 571646283Sdfr { 571746283Sdfr /* We do not know the address of this symbol. 571898944Sobrien If it is an external symbol and we have type information 571998944Sobrien for it, enter the symbol as a LOC_UNRESOLVED symbol. 572098944Sobrien The address of the variable will then be determined from 572198944Sobrien the minimal symbol table whenever the variable is 572298944Sobrien referenced. */ 5723130803Smarcel attr2 = dwarf2_attr (die, DW_AT_external, cu); 572446283Sdfr if (attr2 && (DW_UNSND (attr2) != 0) 5725130803Smarcel && dwarf2_attr (die, DW_AT_type, cu) != NULL) 572646283Sdfr { 572746283Sdfr SYMBOL_CLASS (sym) = LOC_UNRESOLVED; 572846283Sdfr add_symbol_to_list (sym, &global_symbols); 572946283Sdfr } 573046283Sdfr } 573146283Sdfr break; 573246283Sdfr case DW_TAG_formal_parameter: 5733130803Smarcel attr = dwarf2_attr (die, DW_AT_location, cu); 573446283Sdfr if (attr) 573546283Sdfr { 5736130803Smarcel var_decode_location (attr, sym, cu); 5737130803Smarcel /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */ 5738130803Smarcel if (SYMBOL_CLASS (sym) == LOC_COMPUTED) 5739130803Smarcel SYMBOL_CLASS (sym) = LOC_COMPUTED_ARG; 574046283Sdfr } 5741130803Smarcel attr = dwarf2_attr (die, DW_AT_const_value, cu); 574246283Sdfr if (attr) 574346283Sdfr { 5744130803Smarcel dwarf2_const_value (attr, sym, cu); 574546283Sdfr } 5746130803Smarcel add_symbol_to_list (sym, cu->list_in_scope); 574746283Sdfr break; 574846283Sdfr case DW_TAG_unspecified_parameters: 574946283Sdfr /* From varargs functions; gdb doesn't seem to have any 575046283Sdfr interest in this information, so just ignore it for now. 575146283Sdfr (FIXME?) */ 575246283Sdfr break; 575346283Sdfr case DW_TAG_class_type: 575446283Sdfr case DW_TAG_structure_type: 575546283Sdfr case DW_TAG_union_type: 575646283Sdfr case DW_TAG_enumeration_type: 575746283Sdfr SYMBOL_CLASS (sym) = LOC_TYPEDEF; 5758130803Smarcel SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; 575946283Sdfr 5760130803Smarcel /* Make sure that the symbol includes appropriate enclosing 5761130803Smarcel classes/namespaces in its name. These are calculated in 5762130803Smarcel read_structure_type, and the correct name is saved in 5763130803Smarcel the type. */ 5764130803Smarcel 5765130803Smarcel if (cu->language == language_cplus) 576646283Sdfr { 5767130803Smarcel struct type *type = SYMBOL_TYPE (sym); 5768130803Smarcel 5769130803Smarcel if (TYPE_TAG_NAME (type) != NULL) 5770130803Smarcel { 5771130803Smarcel /* FIXME: carlton/2003-11-10: Should this use 5772130803Smarcel SYMBOL_SET_NAMES instead? (The same problem also 5773130803Smarcel arises a further down in the function.) */ 5774130803Smarcel SYMBOL_LINKAGE_NAME (sym) 5775130803Smarcel = obsavestring (TYPE_TAG_NAME (type), 5776130803Smarcel strlen (TYPE_TAG_NAME (type)), 5777130803Smarcel &objfile->objfile_obstack); 5778130803Smarcel } 577946283Sdfr } 5780130803Smarcel 5781130803Smarcel { 5782130803Smarcel /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't 5783130803Smarcel really ever be static objects: otherwise, if you try 5784130803Smarcel to, say, break of a class's method and you're in a file 5785130803Smarcel which doesn't mention that class, it won't work unless 5786130803Smarcel the check for all static symbols in lookup_symbol_aux 5787130803Smarcel saves you. See the OtherFileClass tests in 5788130803Smarcel gdb.c++/namespace.exp. */ 5789130803Smarcel 5790130803Smarcel struct pending **list_to_add; 5791130803Smarcel 5792130803Smarcel list_to_add = (cu->list_in_scope == &file_symbols 5793130803Smarcel && cu->language == language_cplus 5794130803Smarcel ? &global_symbols : cu->list_in_scope); 5795130803Smarcel 5796130803Smarcel add_symbol_to_list (sym, list_to_add); 5797130803Smarcel 5798130803Smarcel /* The semantics of C++ state that "struct foo { ... }" also 5799130803Smarcel defines a typedef for "foo". Synthesize a typedef symbol so 5800130803Smarcel that "ptype foo" works as expected. */ 5801130803Smarcel if (cu->language == language_cplus) 5802130803Smarcel { 5803130803Smarcel struct symbol *typedef_sym = (struct symbol *) 5804130803Smarcel obstack_alloc (&objfile->objfile_obstack, 5805130803Smarcel sizeof (struct symbol)); 5806130803Smarcel *typedef_sym = *sym; 5807130803Smarcel SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN; 5808130803Smarcel if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) 5809130803Smarcel TYPE_NAME (SYMBOL_TYPE (sym)) = 5810130803Smarcel obsavestring (SYMBOL_NATURAL_NAME (sym), 5811130803Smarcel strlen (SYMBOL_NATURAL_NAME (sym)), 5812130803Smarcel &objfile->objfile_obstack); 5813130803Smarcel add_symbol_to_list (typedef_sym, list_to_add); 5814130803Smarcel } 5815130803Smarcel } 581646283Sdfr break; 581746283Sdfr case DW_TAG_typedef: 5818130803Smarcel if (processing_has_namespace_info 5819130803Smarcel && processing_current_prefix[0] != '\0') 5820130803Smarcel { 5821130803Smarcel SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->objfile_obstack, 5822130803Smarcel processing_current_prefix, 5823130803Smarcel "::", 5824130803Smarcel name); 5825130803Smarcel } 5826130803Smarcel SYMBOL_CLASS (sym) = LOC_TYPEDEF; 5827130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 5828130803Smarcel add_symbol_to_list (sym, cu->list_in_scope); 5829130803Smarcel break; 583046283Sdfr case DW_TAG_base_type: 5831130803Smarcel case DW_TAG_subrange_type: 583246283Sdfr SYMBOL_CLASS (sym) = LOC_TYPEDEF; 5833130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 5834130803Smarcel add_symbol_to_list (sym, cu->list_in_scope); 583546283Sdfr break; 583646283Sdfr case DW_TAG_enumerator: 5837130803Smarcel if (processing_has_namespace_info 5838130803Smarcel && processing_current_prefix[0] != '\0') 5839130803Smarcel { 5840130803Smarcel SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->objfile_obstack, 5841130803Smarcel processing_current_prefix, 5842130803Smarcel "::", 5843130803Smarcel name); 5844130803Smarcel } 5845130803Smarcel attr = dwarf2_attr (die, DW_AT_const_value, cu); 584646283Sdfr if (attr) 584746283Sdfr { 5848130803Smarcel dwarf2_const_value (attr, sym, cu); 584946283Sdfr } 5850130803Smarcel { 5851130803Smarcel /* NOTE: carlton/2003-11-10: See comment above in the 5852130803Smarcel DW_TAG_class_type, etc. block. */ 5853130803Smarcel 5854130803Smarcel struct pending **list_to_add; 5855130803Smarcel 5856130803Smarcel list_to_add = (cu->list_in_scope == &file_symbols 5857130803Smarcel && cu->language == language_cplus 5858130803Smarcel ? &global_symbols : cu->list_in_scope); 5859130803Smarcel 5860130803Smarcel add_symbol_to_list (sym, list_to_add); 5861130803Smarcel } 586246283Sdfr break; 5863130803Smarcel case DW_TAG_namespace: 5864130803Smarcel SYMBOL_CLASS (sym) = LOC_TYPEDEF; 5865130803Smarcel add_symbol_to_list (sym, &global_symbols); 5866130803Smarcel break; 586746283Sdfr default: 586846283Sdfr /* Not a tag we recognize. Hopefully we aren't processing 586946283Sdfr trash data, but since we must specifically ignore things 587046283Sdfr we don't recognize, there is nothing else we should do at 587146283Sdfr this point. */ 5872130803Smarcel complaint (&symfile_complaints, "unsupported tag: '%s'", 5873130803Smarcel dwarf_tag_name (die->tag)); 587446283Sdfr break; 587546283Sdfr } 587646283Sdfr } 587746283Sdfr return (sym); 587846283Sdfr} 587946283Sdfr 588046283Sdfr/* Copy constant value from an attribute to a symbol. */ 588146283Sdfr 588246283Sdfrstatic void 588398944Sobriendwarf2_const_value (struct attribute *attr, struct symbol *sym, 5884130803Smarcel struct dwarf2_cu *cu) 588546283Sdfr{ 5886130803Smarcel struct objfile *objfile = cu->objfile; 5887130803Smarcel struct comp_unit_head *cu_header = &cu->header; 588846283Sdfr struct dwarf_block *blk; 588946283Sdfr 589046283Sdfr switch (attr->form) 589146283Sdfr { 589246283Sdfr case DW_FORM_addr: 589398944Sobrien if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size) 5894130803Smarcel dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym), 5895130803Smarcel cu_header->addr_size, 5896130803Smarcel TYPE_LENGTH (SYMBOL_TYPE 5897130803Smarcel (sym))); 589846283Sdfr SYMBOL_VALUE_BYTES (sym) = (char *) 5899130803Smarcel obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size); 5900130803Smarcel /* NOTE: cagney/2003-05-09: In-lined store_address call with 5901130803Smarcel it's body - store_unsigned_integer. */ 5902130803Smarcel store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size, 5903130803Smarcel DW_ADDR (attr)); 590446283Sdfr SYMBOL_CLASS (sym) = LOC_CONST_BYTES; 590546283Sdfr break; 590646283Sdfr case DW_FORM_block1: 590746283Sdfr case DW_FORM_block2: 590846283Sdfr case DW_FORM_block4: 590946283Sdfr case DW_FORM_block: 591046283Sdfr blk = DW_BLOCK (attr); 591146283Sdfr if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size) 5912130803Smarcel dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym), 5913130803Smarcel blk->size, 5914130803Smarcel TYPE_LENGTH (SYMBOL_TYPE 5915130803Smarcel (sym))); 591646283Sdfr SYMBOL_VALUE_BYTES (sym) = (char *) 5917130803Smarcel obstack_alloc (&objfile->objfile_obstack, blk->size); 591846283Sdfr memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size); 591946283Sdfr SYMBOL_CLASS (sym) = LOC_CONST_BYTES; 592046283Sdfr break; 592198944Sobrien 592298944Sobrien /* The DW_AT_const_value attributes are supposed to carry the 592398944Sobrien symbol's value "represented as it would be on the target 592498944Sobrien architecture." By the time we get here, it's already been 592598944Sobrien converted to host endianness, so we just need to sign- or 592698944Sobrien zero-extend it as appropriate. */ 592798944Sobrien case DW_FORM_data1: 592898944Sobrien dwarf2_const_value_data (attr, sym, 8); 592998944Sobrien break; 593046283Sdfr case DW_FORM_data2: 593198944Sobrien dwarf2_const_value_data (attr, sym, 16); 593298944Sobrien break; 593346283Sdfr case DW_FORM_data4: 593498944Sobrien dwarf2_const_value_data (attr, sym, 32); 593598944Sobrien break; 593646283Sdfr case DW_FORM_data8: 593798944Sobrien dwarf2_const_value_data (attr, sym, 64); 593898944Sobrien break; 593998944Sobrien 594046283Sdfr case DW_FORM_sdata: 594198944Sobrien SYMBOL_VALUE (sym) = DW_SND (attr); 594298944Sobrien SYMBOL_CLASS (sym) = LOC_CONST; 594398944Sobrien break; 594498944Sobrien 594546283Sdfr case DW_FORM_udata: 594646283Sdfr SYMBOL_VALUE (sym) = DW_UNSND (attr); 594746283Sdfr SYMBOL_CLASS (sym) = LOC_CONST; 594846283Sdfr break; 594998944Sobrien 595046283Sdfr default: 5951130803Smarcel complaint (&symfile_complaints, 5952130803Smarcel "unsupported const value attribute form: '%s'", 5953130803Smarcel dwarf_form_name (attr->form)); 595446283Sdfr SYMBOL_VALUE (sym) = 0; 595546283Sdfr SYMBOL_CLASS (sym) = LOC_CONST; 595646283Sdfr break; 595746283Sdfr } 595846283Sdfr} 595946283Sdfr 596098944Sobrien 596198944Sobrien/* Given an attr with a DW_FORM_dataN value in host byte order, sign- 596298944Sobrien or zero-extend it as appropriate for the symbol's type. */ 596398944Sobrienstatic void 596498944Sobriendwarf2_const_value_data (struct attribute *attr, 596598944Sobrien struct symbol *sym, 596698944Sobrien int bits) 596798944Sobrien{ 596898944Sobrien LONGEST l = DW_UNSND (attr); 596998944Sobrien 597098944Sobrien if (bits < sizeof (l) * 8) 597198944Sobrien { 597298944Sobrien if (TYPE_UNSIGNED (SYMBOL_TYPE (sym))) 597398944Sobrien l &= ((LONGEST) 1 << bits) - 1; 597498944Sobrien else 597598944Sobrien l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits); 597698944Sobrien } 597798944Sobrien 597898944Sobrien SYMBOL_VALUE (sym) = l; 597998944Sobrien SYMBOL_CLASS (sym) = LOC_CONST; 598098944Sobrien} 598198944Sobrien 598298944Sobrien 598346283Sdfr/* Return the type of the die in question using its DW_AT_type attribute. */ 598446283Sdfr 598546283Sdfrstatic struct type * 5986130803Smarceldie_type (struct die_info *die, struct dwarf2_cu *cu) 598746283Sdfr{ 598846283Sdfr struct type *type; 598946283Sdfr struct attribute *type_attr; 599046283Sdfr struct die_info *type_die; 599146283Sdfr unsigned int ref; 599246283Sdfr 5993130803Smarcel type_attr = dwarf2_attr (die, DW_AT_type, cu); 599446283Sdfr if (!type_attr) 599546283Sdfr { 599646283Sdfr /* A missing DW_AT_type represents a void type. */ 5997130803Smarcel return dwarf2_fundamental_type (cu->objfile, FT_VOID, cu); 599846283Sdfr } 599946283Sdfr else 600046283Sdfr { 6001130803Smarcel ref = dwarf2_get_ref_die_offset (type_attr, cu); 600246283Sdfr type_die = follow_die_ref (ref); 600346283Sdfr if (!type_die) 600446283Sdfr { 6005130803Smarcel error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", 6006130803Smarcel ref, cu->objfile->name); 600746283Sdfr return NULL; 600846283Sdfr } 600946283Sdfr } 6010130803Smarcel type = tag_type_to_type (type_die, cu); 601146283Sdfr if (!type) 601246283Sdfr { 601346283Sdfr dump_die (type_die); 6014130803Smarcel error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]", 6015130803Smarcel cu->objfile->name); 601646283Sdfr } 601746283Sdfr return type; 601846283Sdfr} 601946283Sdfr 602046283Sdfr/* Return the containing type of the die in question using its 602146283Sdfr DW_AT_containing_type attribute. */ 602246283Sdfr 602346283Sdfrstatic struct type * 6024130803Smarceldie_containing_type (struct die_info *die, struct dwarf2_cu *cu) 602546283Sdfr{ 602646283Sdfr struct type *type = NULL; 602746283Sdfr struct attribute *type_attr; 602846283Sdfr struct die_info *type_die = NULL; 602946283Sdfr unsigned int ref; 603046283Sdfr 6031130803Smarcel type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); 603246283Sdfr if (type_attr) 603346283Sdfr { 6034130803Smarcel ref = dwarf2_get_ref_die_offset (type_attr, cu); 603546283Sdfr type_die = follow_die_ref (ref); 603646283Sdfr if (!type_die) 603746283Sdfr { 6038130803Smarcel error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref, 6039130803Smarcel cu->objfile->name); 604046283Sdfr return NULL; 604146283Sdfr } 6042130803Smarcel type = tag_type_to_type (type_die, cu); 604346283Sdfr } 604446283Sdfr if (!type) 604546283Sdfr { 604646283Sdfr if (type_die) 604746283Sdfr dump_die (type_die); 6048130803Smarcel error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]", 6049130803Smarcel cu->objfile->name); 605046283Sdfr } 605146283Sdfr return type; 605246283Sdfr} 605346283Sdfr 605446283Sdfr#if 0 605546283Sdfrstatic struct type * 6056130803Smarceltype_at_offset (unsigned int offset, struct dwarf2_cu *cu) 605746283Sdfr{ 605846283Sdfr struct die_info *die; 605946283Sdfr struct type *type; 606046283Sdfr 606146283Sdfr die = follow_die_ref (offset); 606246283Sdfr if (!die) 606346283Sdfr { 606446283Sdfr error ("Dwarf Error: Cannot find type referent at offset %d.", offset); 606546283Sdfr return NULL; 606646283Sdfr } 6067130803Smarcel type = tag_type_to_type (die, cu); 606846283Sdfr return type; 606946283Sdfr} 607046283Sdfr#endif 607146283Sdfr 607246283Sdfrstatic struct type * 6073130803Smarceltag_type_to_type (struct die_info *die, struct dwarf2_cu *cu) 607446283Sdfr{ 607546283Sdfr if (die->type) 607646283Sdfr { 607746283Sdfr return die->type; 607846283Sdfr } 607946283Sdfr else 608046283Sdfr { 6081130803Smarcel read_type_die (die, cu); 608246283Sdfr if (!die->type) 608346283Sdfr { 608446283Sdfr dump_die (die); 6085251844Semaste error ("Dwarf Error: Cannot find type of die 0x%x [in module %s]", 6086251844Semaste die->tag, cu->objfile->name); 608746283Sdfr } 608846283Sdfr return die->type; 608946283Sdfr } 609046283Sdfr} 609146283Sdfr 609246283Sdfrstatic void 6093130803Smarcelread_type_die (struct die_info *die, struct dwarf2_cu *cu) 609446283Sdfr{ 6095130803Smarcel char *prefix = determine_prefix (die, cu); 6096130803Smarcel const char *old_prefix = processing_current_prefix; 6097130803Smarcel struct cleanup *back_to = make_cleanup (xfree, prefix); 6098130803Smarcel processing_current_prefix = prefix; 6099130803Smarcel 610046283Sdfr switch (die->tag) 610146283Sdfr { 610246283Sdfr case DW_TAG_class_type: 610346283Sdfr case DW_TAG_structure_type: 610446283Sdfr case DW_TAG_union_type: 6105130803Smarcel read_structure_type (die, cu); 610646283Sdfr break; 610746283Sdfr case DW_TAG_enumeration_type: 6108130803Smarcel read_enumeration_type (die, cu); 610946283Sdfr break; 611046283Sdfr case DW_TAG_subprogram: 611146283Sdfr case DW_TAG_subroutine_type: 6112130803Smarcel read_subroutine_type (die, cu); 611346283Sdfr break; 611446283Sdfr case DW_TAG_array_type: 6115130803Smarcel read_array_type (die, cu); 611646283Sdfr break; 611746283Sdfr case DW_TAG_pointer_type: 6118130803Smarcel read_tag_pointer_type (die, cu); 611946283Sdfr break; 6120251667Semaste case DW_TAG_unspecified_type: 6121251667Semaste read_tag_unspecified_type (die, cu); 6122251667Semaste break; 612346283Sdfr case DW_TAG_ptr_to_member_type: 6124130803Smarcel read_tag_ptr_to_member_type (die, cu); 612546283Sdfr break; 612646283Sdfr case DW_TAG_reference_type: 6127251665Semaste case DW_TAG_rvalue_reference_type: 6128130803Smarcel read_tag_reference_type (die, cu); 612946283Sdfr break; 613046283Sdfr case DW_TAG_const_type: 6131130803Smarcel read_tag_const_type (die, cu); 613246283Sdfr break; 613346283Sdfr case DW_TAG_volatile_type: 6134130803Smarcel read_tag_volatile_type (die, cu); 613546283Sdfr break; 6136244437Semaste case DW_TAG_restrict_type: 6137244437Semaste read_tag_restrict_type (die, cu); 6138244437Semaste break; 613946283Sdfr case DW_TAG_string_type: 6140130803Smarcel read_tag_string_type (die, cu); 614146283Sdfr break; 614246283Sdfr case DW_TAG_typedef: 6143130803Smarcel read_typedef (die, cu); 614446283Sdfr break; 6145130803Smarcel case DW_TAG_subrange_type: 6146130803Smarcel read_subrange_type (die, cu); 6147130803Smarcel break; 614846283Sdfr case DW_TAG_base_type: 6149130803Smarcel read_base_type (die, cu); 615046283Sdfr break; 615146283Sdfr default: 6152130803Smarcel complaint (&symfile_complaints, "unexepected tag in read_type_die: '%s'", 6153130803Smarcel dwarf_tag_name (die->tag)); 615446283Sdfr break; 615546283Sdfr } 6156130803Smarcel 6157130803Smarcel processing_current_prefix = old_prefix; 6158130803Smarcel do_cleanups (back_to); 615946283Sdfr} 616046283Sdfr 6161130803Smarcel/* Return the name of the namespace/class that DIE is defined within, 6162130803Smarcel or "" if we can't tell. The caller should xfree the result. */ 6163130803Smarcel 6164130803Smarcel/* NOTE: carlton/2004-01-23: See read_func_scope (and the comment 6165130803Smarcel therein) for an example of how to use this function to deal with 6166130803Smarcel DW_AT_specification. */ 6167130803Smarcel 6168130803Smarcelstatic char * 6169130803Smarceldetermine_prefix (struct die_info *die, struct dwarf2_cu *cu) 6170130803Smarcel{ 6171130803Smarcel struct die_info *parent; 6172130803Smarcel 6173130803Smarcel if (cu->language != language_cplus) 6174130803Smarcel return NULL; 6175130803Smarcel 6176130803Smarcel parent = die->parent; 6177130803Smarcel 6178130803Smarcel if (parent == NULL) 6179130803Smarcel { 6180130803Smarcel return xstrdup (""); 6181130803Smarcel } 6182130803Smarcel else 6183130803Smarcel { 6184130803Smarcel switch (parent->tag) { 6185130803Smarcel case DW_TAG_namespace: 6186130803Smarcel { 6187130803Smarcel /* FIXME: carlton/2004-03-05: Should I follow extension dies 6188130803Smarcel before doing this check? */ 6189130803Smarcel if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL) 6190130803Smarcel { 6191130803Smarcel return xstrdup (TYPE_TAG_NAME (parent->type)); 6192130803Smarcel } 6193130803Smarcel else 6194130803Smarcel { 6195130803Smarcel int dummy; 6196130803Smarcel char *parent_prefix = determine_prefix (parent, cu); 6197130803Smarcel char *retval = typename_concat (parent_prefix, 6198130803Smarcel namespace_name (parent, &dummy, 6199130803Smarcel cu)); 6200130803Smarcel xfree (parent_prefix); 6201130803Smarcel return retval; 6202130803Smarcel } 6203130803Smarcel } 6204130803Smarcel break; 6205130803Smarcel case DW_TAG_class_type: 6206130803Smarcel case DW_TAG_structure_type: 6207130803Smarcel { 6208130803Smarcel if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL) 6209130803Smarcel { 6210130803Smarcel return xstrdup (TYPE_TAG_NAME (parent->type)); 6211130803Smarcel } 6212130803Smarcel else 6213130803Smarcel { 6214130803Smarcel const char *old_prefix = processing_current_prefix; 6215130803Smarcel char *new_prefix = determine_prefix (parent, cu); 6216130803Smarcel char *retval; 6217130803Smarcel 6218130803Smarcel processing_current_prefix = new_prefix; 6219130803Smarcel retval = determine_class_name (parent, cu); 6220130803Smarcel processing_current_prefix = old_prefix; 6221130803Smarcel 6222130803Smarcel xfree (new_prefix); 6223130803Smarcel return retval; 6224130803Smarcel } 6225130803Smarcel } 6226130803Smarcel default: 6227130803Smarcel return determine_prefix (parent, cu); 6228130803Smarcel } 6229130803Smarcel } 6230130803Smarcel} 6231130803Smarcel 6232130803Smarcel/* Return a newly-allocated string formed by concatenating PREFIX, 6233130803Smarcel "::", and SUFFIX, except that if PREFIX is NULL or the empty 6234130803Smarcel string, just return a copy of SUFFIX. */ 6235130803Smarcel 6236130803Smarcelstatic char * 6237130803Smarceltypename_concat (const char *prefix, const char *suffix) 6238130803Smarcel{ 6239130803Smarcel if (prefix == NULL || prefix[0] == '\0') 6240130803Smarcel return xstrdup (suffix); 6241130803Smarcel else 6242130803Smarcel { 6243130803Smarcel char *retval = xmalloc (strlen (prefix) + 2 + strlen (suffix) + 1); 6244130803Smarcel 6245130803Smarcel strcpy (retval, prefix); 6246130803Smarcel strcat (retval, "::"); 6247130803Smarcel strcat (retval, suffix); 6248130803Smarcel 6249130803Smarcel return retval; 6250130803Smarcel } 6251130803Smarcel} 6252130803Smarcel 625346283Sdfrstatic struct type * 6254130803Smarceldwarf_base_type (int encoding, int size, struct dwarf2_cu *cu) 625546283Sdfr{ 6256130803Smarcel struct objfile *objfile = cu->objfile; 6257130803Smarcel 625846283Sdfr /* FIXME - this should not produce a new (struct type *) 625946283Sdfr every time. It should cache base types. */ 626046283Sdfr struct type *type; 626146283Sdfr switch (encoding) 626246283Sdfr { 626346283Sdfr case DW_ATE_address: 6264130803Smarcel type = dwarf2_fundamental_type (objfile, FT_VOID, cu); 626546283Sdfr return type; 626646283Sdfr case DW_ATE_boolean: 6267130803Smarcel type = dwarf2_fundamental_type (objfile, FT_BOOLEAN, cu); 626846283Sdfr return type; 626946283Sdfr case DW_ATE_complex_float: 627046283Sdfr if (size == 16) 627146283Sdfr { 6272130803Smarcel type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_COMPLEX, cu); 627346283Sdfr } 627446283Sdfr else 627546283Sdfr { 6276130803Smarcel type = dwarf2_fundamental_type (objfile, FT_COMPLEX, cu); 627746283Sdfr } 627846283Sdfr return type; 627946283Sdfr case DW_ATE_float: 628046283Sdfr if (size == 8) 628146283Sdfr { 6282130803Smarcel type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu); 628346283Sdfr } 628446283Sdfr else 628546283Sdfr { 6286130803Smarcel type = dwarf2_fundamental_type (objfile, FT_FLOAT, cu); 628746283Sdfr } 628846283Sdfr return type; 628946283Sdfr case DW_ATE_signed: 629046283Sdfr switch (size) 629146283Sdfr { 629246283Sdfr case 1: 6293130803Smarcel type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu); 629446283Sdfr break; 629546283Sdfr case 2: 6296130803Smarcel type = dwarf2_fundamental_type (objfile, FT_SIGNED_SHORT, cu); 629746283Sdfr break; 629846283Sdfr default: 629946283Sdfr case 4: 6300130803Smarcel type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu); 630146283Sdfr break; 630246283Sdfr } 630346283Sdfr return type; 630446283Sdfr case DW_ATE_signed_char: 6305130803Smarcel type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu); 630646283Sdfr return type; 630746283Sdfr case DW_ATE_unsigned: 630846283Sdfr switch (size) 630946283Sdfr { 631046283Sdfr case 1: 6311130803Smarcel type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu); 631246283Sdfr break; 631346283Sdfr case 2: 6314130803Smarcel type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_SHORT, cu); 631546283Sdfr break; 631646283Sdfr default: 631746283Sdfr case 4: 6318130803Smarcel type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_INTEGER, cu); 631946283Sdfr break; 632046283Sdfr } 632146283Sdfr return type; 632246283Sdfr case DW_ATE_unsigned_char: 6323130803Smarcel type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu); 632446283Sdfr return type; 632546283Sdfr default: 6326130803Smarcel type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu); 632746283Sdfr return type; 632846283Sdfr } 632946283Sdfr} 633046283Sdfr 633146283Sdfr#if 0 633246283Sdfrstruct die_info * 633398944Sobriencopy_die (struct die_info *old_die) 633446283Sdfr{ 633546283Sdfr struct die_info *new_die; 633646283Sdfr int i, num_attrs; 633746283Sdfr 633846283Sdfr new_die = (struct die_info *) xmalloc (sizeof (struct die_info)); 633946283Sdfr memset (new_die, 0, sizeof (struct die_info)); 634046283Sdfr 634146283Sdfr new_die->tag = old_die->tag; 634246283Sdfr new_die->has_children = old_die->has_children; 634346283Sdfr new_die->abbrev = old_die->abbrev; 634446283Sdfr new_die->offset = old_die->offset; 634546283Sdfr new_die->type = NULL; 634646283Sdfr 634746283Sdfr num_attrs = old_die->num_attrs; 634846283Sdfr new_die->num_attrs = num_attrs; 634946283Sdfr new_die->attrs = (struct attribute *) 635046283Sdfr xmalloc (num_attrs * sizeof (struct attribute)); 635146283Sdfr 635246283Sdfr for (i = 0; i < old_die->num_attrs; ++i) 635346283Sdfr { 635446283Sdfr new_die->attrs[i].name = old_die->attrs[i].name; 635546283Sdfr new_die->attrs[i].form = old_die->attrs[i].form; 635646283Sdfr new_die->attrs[i].u.addr = old_die->attrs[i].u.addr; 635746283Sdfr } 635846283Sdfr 635946283Sdfr new_die->next = NULL; 636046283Sdfr return new_die; 636146283Sdfr} 636246283Sdfr#endif 636346283Sdfr 636446283Sdfr/* Return sibling of die, NULL if no sibling. */ 636546283Sdfr 636698944Sobrienstatic struct die_info * 636798944Sobriensibling_die (struct die_info *die) 636846283Sdfr{ 6369130803Smarcel return die->sibling; 637046283Sdfr} 637146283Sdfr 637246283Sdfr/* Get linkage name of a die, return NULL if not found. */ 637346283Sdfr 637446283Sdfrstatic char * 6375130803Smarceldwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu) 637646283Sdfr{ 637746283Sdfr struct attribute *attr; 637846283Sdfr 6379130803Smarcel attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); 638046283Sdfr if (attr && DW_STRING (attr)) 638146283Sdfr return DW_STRING (attr); 6382130803Smarcel attr = dwarf2_attr (die, DW_AT_name, cu); 638346283Sdfr if (attr && DW_STRING (attr)) 638446283Sdfr return DW_STRING (attr); 638546283Sdfr return NULL; 638646283Sdfr} 638746283Sdfr 6388130803Smarcel/* Get name of a die, return NULL if not found. */ 6389130803Smarcel 6390130803Smarcelstatic char * 6391130803Smarceldwarf2_name (struct die_info *die, struct dwarf2_cu *cu) 6392130803Smarcel{ 6393130803Smarcel struct attribute *attr; 6394130803Smarcel 6395130803Smarcel attr = dwarf2_attr (die, DW_AT_name, cu); 6396130803Smarcel if (attr && DW_STRING (attr)) 6397130803Smarcel return DW_STRING (attr); 6398130803Smarcel return NULL; 6399130803Smarcel} 6400130803Smarcel 6401130803Smarcel/* Return the die that this die in an extension of, or NULL if there 6402130803Smarcel is none. */ 6403130803Smarcel 6404130803Smarcelstatic struct die_info * 6405130803Smarceldwarf2_extension (struct die_info *die, struct dwarf2_cu *cu) 6406130803Smarcel{ 6407130803Smarcel struct attribute *attr; 6408130803Smarcel struct die_info *extension_die; 6409130803Smarcel unsigned int ref; 6410130803Smarcel 6411130803Smarcel attr = dwarf2_attr (die, DW_AT_extension, cu); 6412130803Smarcel if (attr == NULL) 6413130803Smarcel return NULL; 6414130803Smarcel 6415130803Smarcel ref = dwarf2_get_ref_die_offset (attr, cu); 6416130803Smarcel extension_die = follow_die_ref (ref); 6417130803Smarcel if (!extension_die) 6418130803Smarcel { 6419130803Smarcel error ("Dwarf Error: Cannot find referent at offset %d.", ref); 6420130803Smarcel } 6421130803Smarcel 6422130803Smarcel return extension_die; 6423130803Smarcel} 6424130803Smarcel 642546283Sdfr/* Convert a DIE tag into its string name. */ 642646283Sdfr 642746283Sdfrstatic char * 6428130803Smarceldwarf_tag_name (unsigned tag) 642946283Sdfr{ 643046283Sdfr switch (tag) 643146283Sdfr { 643246283Sdfr case DW_TAG_padding: 643346283Sdfr return "DW_TAG_padding"; 643446283Sdfr case DW_TAG_array_type: 643546283Sdfr return "DW_TAG_array_type"; 643646283Sdfr case DW_TAG_class_type: 643746283Sdfr return "DW_TAG_class_type"; 643846283Sdfr case DW_TAG_entry_point: 643946283Sdfr return "DW_TAG_entry_point"; 644046283Sdfr case DW_TAG_enumeration_type: 644146283Sdfr return "DW_TAG_enumeration_type"; 644246283Sdfr case DW_TAG_formal_parameter: 644346283Sdfr return "DW_TAG_formal_parameter"; 644446283Sdfr case DW_TAG_imported_declaration: 644546283Sdfr return "DW_TAG_imported_declaration"; 644646283Sdfr case DW_TAG_label: 644746283Sdfr return "DW_TAG_label"; 644846283Sdfr case DW_TAG_lexical_block: 644946283Sdfr return "DW_TAG_lexical_block"; 645046283Sdfr case DW_TAG_member: 645146283Sdfr return "DW_TAG_member"; 645246283Sdfr case DW_TAG_pointer_type: 645346283Sdfr return "DW_TAG_pointer_type"; 645446283Sdfr case DW_TAG_reference_type: 645546283Sdfr return "DW_TAG_reference_type"; 6456251665Semaste case DW_TAG_rvalue_reference_type: 6457251665Semaste return "DW_TAG_rvalue_reference_type"; 645846283Sdfr case DW_TAG_compile_unit: 645946283Sdfr return "DW_TAG_compile_unit"; 646046283Sdfr case DW_TAG_string_type: 646146283Sdfr return "DW_TAG_string_type"; 646246283Sdfr case DW_TAG_structure_type: 646346283Sdfr return "DW_TAG_structure_type"; 646446283Sdfr case DW_TAG_subroutine_type: 646546283Sdfr return "DW_TAG_subroutine_type"; 646646283Sdfr case DW_TAG_typedef: 646746283Sdfr return "DW_TAG_typedef"; 646846283Sdfr case DW_TAG_union_type: 646946283Sdfr return "DW_TAG_union_type"; 647046283Sdfr case DW_TAG_unspecified_parameters: 647146283Sdfr return "DW_TAG_unspecified_parameters"; 647246283Sdfr case DW_TAG_variant: 647346283Sdfr return "DW_TAG_variant"; 647446283Sdfr case DW_TAG_common_block: 647546283Sdfr return "DW_TAG_common_block"; 647646283Sdfr case DW_TAG_common_inclusion: 647746283Sdfr return "DW_TAG_common_inclusion"; 647846283Sdfr case DW_TAG_inheritance: 647946283Sdfr return "DW_TAG_inheritance"; 648046283Sdfr case DW_TAG_inlined_subroutine: 648146283Sdfr return "DW_TAG_inlined_subroutine"; 648246283Sdfr case DW_TAG_module: 648346283Sdfr return "DW_TAG_module"; 648446283Sdfr case DW_TAG_ptr_to_member_type: 648546283Sdfr return "DW_TAG_ptr_to_member_type"; 648646283Sdfr case DW_TAG_set_type: 648746283Sdfr return "DW_TAG_set_type"; 648846283Sdfr case DW_TAG_subrange_type: 648946283Sdfr return "DW_TAG_subrange_type"; 649046283Sdfr case DW_TAG_with_stmt: 649146283Sdfr return "DW_TAG_with_stmt"; 649246283Sdfr case DW_TAG_access_declaration: 649346283Sdfr return "DW_TAG_access_declaration"; 649446283Sdfr case DW_TAG_base_type: 649546283Sdfr return "DW_TAG_base_type"; 649646283Sdfr case DW_TAG_catch_block: 649746283Sdfr return "DW_TAG_catch_block"; 649846283Sdfr case DW_TAG_const_type: 649946283Sdfr return "DW_TAG_const_type"; 650046283Sdfr case DW_TAG_constant: 650146283Sdfr return "DW_TAG_constant"; 650246283Sdfr case DW_TAG_enumerator: 650346283Sdfr return "DW_TAG_enumerator"; 650446283Sdfr case DW_TAG_file_type: 650546283Sdfr return "DW_TAG_file_type"; 650646283Sdfr case DW_TAG_friend: 650746283Sdfr return "DW_TAG_friend"; 650846283Sdfr case DW_TAG_namelist: 650946283Sdfr return "DW_TAG_namelist"; 651046283Sdfr case DW_TAG_namelist_item: 651146283Sdfr return "DW_TAG_namelist_item"; 651246283Sdfr case DW_TAG_packed_type: 651346283Sdfr return "DW_TAG_packed_type"; 651446283Sdfr case DW_TAG_subprogram: 651546283Sdfr return "DW_TAG_subprogram"; 651646283Sdfr case DW_TAG_template_type_param: 651746283Sdfr return "DW_TAG_template_type_param"; 651846283Sdfr case DW_TAG_template_value_param: 651946283Sdfr return "DW_TAG_template_value_param"; 652046283Sdfr case DW_TAG_thrown_type: 652146283Sdfr return "DW_TAG_thrown_type"; 652246283Sdfr case DW_TAG_try_block: 652346283Sdfr return "DW_TAG_try_block"; 652446283Sdfr case DW_TAG_variant_part: 652546283Sdfr return "DW_TAG_variant_part"; 652646283Sdfr case DW_TAG_variable: 652746283Sdfr return "DW_TAG_variable"; 652846283Sdfr case DW_TAG_volatile_type: 652946283Sdfr return "DW_TAG_volatile_type"; 6530130803Smarcel case DW_TAG_dwarf_procedure: 6531130803Smarcel return "DW_TAG_dwarf_procedure"; 6532130803Smarcel case DW_TAG_restrict_type: 6533130803Smarcel return "DW_TAG_restrict_type"; 6534130803Smarcel case DW_TAG_interface_type: 6535130803Smarcel return "DW_TAG_interface_type"; 6536130803Smarcel case DW_TAG_namespace: 6537130803Smarcel return "DW_TAG_namespace"; 6538130803Smarcel case DW_TAG_imported_module: 6539130803Smarcel return "DW_TAG_imported_module"; 6540130803Smarcel case DW_TAG_unspecified_type: 6541130803Smarcel return "DW_TAG_unspecified_type"; 6542130803Smarcel case DW_TAG_partial_unit: 6543130803Smarcel return "DW_TAG_partial_unit"; 6544130803Smarcel case DW_TAG_imported_unit: 6545130803Smarcel return "DW_TAG_imported_unit"; 654646283Sdfr case DW_TAG_MIPS_loop: 654746283Sdfr return "DW_TAG_MIPS_loop"; 654846283Sdfr case DW_TAG_format_label: 654946283Sdfr return "DW_TAG_format_label"; 655046283Sdfr case DW_TAG_function_template: 655146283Sdfr return "DW_TAG_function_template"; 655246283Sdfr case DW_TAG_class_template: 655346283Sdfr return "DW_TAG_class_template"; 655446283Sdfr default: 655546283Sdfr return "DW_TAG_<unknown>"; 655646283Sdfr } 655746283Sdfr} 655846283Sdfr 655946283Sdfr/* Convert a DWARF attribute code into its string name. */ 656046283Sdfr 656146283Sdfrstatic char * 6562130803Smarceldwarf_attr_name (unsigned attr) 656346283Sdfr{ 656446283Sdfr switch (attr) 656546283Sdfr { 656646283Sdfr case DW_AT_sibling: 656746283Sdfr return "DW_AT_sibling"; 656846283Sdfr case DW_AT_location: 656946283Sdfr return "DW_AT_location"; 657046283Sdfr case DW_AT_name: 657146283Sdfr return "DW_AT_name"; 657246283Sdfr case DW_AT_ordering: 657346283Sdfr return "DW_AT_ordering"; 657446283Sdfr case DW_AT_subscr_data: 657546283Sdfr return "DW_AT_subscr_data"; 657646283Sdfr case DW_AT_byte_size: 657746283Sdfr return "DW_AT_byte_size"; 657846283Sdfr case DW_AT_bit_offset: 657946283Sdfr return "DW_AT_bit_offset"; 658046283Sdfr case DW_AT_bit_size: 658146283Sdfr return "DW_AT_bit_size"; 658246283Sdfr case DW_AT_element_list: 658346283Sdfr return "DW_AT_element_list"; 658446283Sdfr case DW_AT_stmt_list: 658546283Sdfr return "DW_AT_stmt_list"; 658646283Sdfr case DW_AT_low_pc: 658746283Sdfr return "DW_AT_low_pc"; 658846283Sdfr case DW_AT_high_pc: 658946283Sdfr return "DW_AT_high_pc"; 659046283Sdfr case DW_AT_language: 659146283Sdfr return "DW_AT_language"; 659246283Sdfr case DW_AT_member: 659346283Sdfr return "DW_AT_member"; 659446283Sdfr case DW_AT_discr: 659546283Sdfr return "DW_AT_discr"; 659646283Sdfr case DW_AT_discr_value: 659746283Sdfr return "DW_AT_discr_value"; 659846283Sdfr case DW_AT_visibility: 659946283Sdfr return "DW_AT_visibility"; 660046283Sdfr case DW_AT_import: 660146283Sdfr return "DW_AT_import"; 660246283Sdfr case DW_AT_string_length: 660346283Sdfr return "DW_AT_string_length"; 660446283Sdfr case DW_AT_common_reference: 660546283Sdfr return "DW_AT_common_reference"; 660646283Sdfr case DW_AT_comp_dir: 660746283Sdfr return "DW_AT_comp_dir"; 660846283Sdfr case DW_AT_const_value: 660946283Sdfr return "DW_AT_const_value"; 661046283Sdfr case DW_AT_containing_type: 661146283Sdfr return "DW_AT_containing_type"; 661246283Sdfr case DW_AT_default_value: 661346283Sdfr return "DW_AT_default_value"; 661446283Sdfr case DW_AT_inline: 661546283Sdfr return "DW_AT_inline"; 661646283Sdfr case DW_AT_is_optional: 661746283Sdfr return "DW_AT_is_optional"; 661846283Sdfr case DW_AT_lower_bound: 661946283Sdfr return "DW_AT_lower_bound"; 662046283Sdfr case DW_AT_producer: 662146283Sdfr return "DW_AT_producer"; 662246283Sdfr case DW_AT_prototyped: 662346283Sdfr return "DW_AT_prototyped"; 662446283Sdfr case DW_AT_return_addr: 662546283Sdfr return "DW_AT_return_addr"; 662646283Sdfr case DW_AT_start_scope: 662746283Sdfr return "DW_AT_start_scope"; 662846283Sdfr case DW_AT_stride_size: 662946283Sdfr return "DW_AT_stride_size"; 663046283Sdfr case DW_AT_upper_bound: 663146283Sdfr return "DW_AT_upper_bound"; 663246283Sdfr case DW_AT_abstract_origin: 663346283Sdfr return "DW_AT_abstract_origin"; 663446283Sdfr case DW_AT_accessibility: 663546283Sdfr return "DW_AT_accessibility"; 663646283Sdfr case DW_AT_address_class: 663746283Sdfr return "DW_AT_address_class"; 663846283Sdfr case DW_AT_artificial: 663946283Sdfr return "DW_AT_artificial"; 664046283Sdfr case DW_AT_base_types: 664146283Sdfr return "DW_AT_base_types"; 664246283Sdfr case DW_AT_calling_convention: 664346283Sdfr return "DW_AT_calling_convention"; 664446283Sdfr case DW_AT_count: 664546283Sdfr return "DW_AT_count"; 664646283Sdfr case DW_AT_data_member_location: 664746283Sdfr return "DW_AT_data_member_location"; 664846283Sdfr case DW_AT_decl_column: 664946283Sdfr return "DW_AT_decl_column"; 665046283Sdfr case DW_AT_decl_file: 665146283Sdfr return "DW_AT_decl_file"; 665246283Sdfr case DW_AT_decl_line: 665346283Sdfr return "DW_AT_decl_line"; 665446283Sdfr case DW_AT_declaration: 665546283Sdfr return "DW_AT_declaration"; 665646283Sdfr case DW_AT_discr_list: 665746283Sdfr return "DW_AT_discr_list"; 665846283Sdfr case DW_AT_encoding: 665946283Sdfr return "DW_AT_encoding"; 666046283Sdfr case DW_AT_external: 666146283Sdfr return "DW_AT_external"; 666246283Sdfr case DW_AT_frame_base: 666346283Sdfr return "DW_AT_frame_base"; 666446283Sdfr case DW_AT_friend: 666546283Sdfr return "DW_AT_friend"; 666646283Sdfr case DW_AT_identifier_case: 666746283Sdfr return "DW_AT_identifier_case"; 666846283Sdfr case DW_AT_macro_info: 666946283Sdfr return "DW_AT_macro_info"; 667046283Sdfr case DW_AT_namelist_items: 667146283Sdfr return "DW_AT_namelist_items"; 667246283Sdfr case DW_AT_priority: 667346283Sdfr return "DW_AT_priority"; 667446283Sdfr case DW_AT_segment: 667546283Sdfr return "DW_AT_segment"; 667646283Sdfr case DW_AT_specification: 667746283Sdfr return "DW_AT_specification"; 667846283Sdfr case DW_AT_static_link: 667946283Sdfr return "DW_AT_static_link"; 668046283Sdfr case DW_AT_type: 668146283Sdfr return "DW_AT_type"; 668246283Sdfr case DW_AT_use_location: 668346283Sdfr return "DW_AT_use_location"; 668446283Sdfr case DW_AT_variable_parameter: 668546283Sdfr return "DW_AT_variable_parameter"; 668646283Sdfr case DW_AT_virtuality: 668746283Sdfr return "DW_AT_virtuality"; 668846283Sdfr case DW_AT_vtable_elem_location: 668946283Sdfr return "DW_AT_vtable_elem_location"; 6690130803Smarcel case DW_AT_allocated: 6691130803Smarcel return "DW_AT_allocated"; 6692130803Smarcel case DW_AT_associated: 6693130803Smarcel return "DW_AT_associated"; 6694130803Smarcel case DW_AT_data_location: 6695130803Smarcel return "DW_AT_data_location"; 6696130803Smarcel case DW_AT_stride: 6697130803Smarcel return "DW_AT_stride"; 6698130803Smarcel case DW_AT_entry_pc: 6699130803Smarcel return "DW_AT_entry_pc"; 6700130803Smarcel case DW_AT_use_UTF8: 6701130803Smarcel return "DW_AT_use_UTF8"; 6702130803Smarcel case DW_AT_extension: 6703130803Smarcel return "DW_AT_extension"; 6704130803Smarcel case DW_AT_ranges: 6705130803Smarcel return "DW_AT_ranges"; 6706130803Smarcel case DW_AT_trampoline: 6707130803Smarcel return "DW_AT_trampoline"; 6708130803Smarcel case DW_AT_call_column: 6709130803Smarcel return "DW_AT_call_column"; 6710130803Smarcel case DW_AT_call_file: 6711130803Smarcel return "DW_AT_call_file"; 6712130803Smarcel case DW_AT_call_line: 6713130803Smarcel return "DW_AT_call_line"; 671446283Sdfr#ifdef MIPS 671546283Sdfr case DW_AT_MIPS_fde: 671646283Sdfr return "DW_AT_MIPS_fde"; 671746283Sdfr case DW_AT_MIPS_loop_begin: 671846283Sdfr return "DW_AT_MIPS_loop_begin"; 671946283Sdfr case DW_AT_MIPS_tail_loop_begin: 672046283Sdfr return "DW_AT_MIPS_tail_loop_begin"; 672146283Sdfr case DW_AT_MIPS_epilog_begin: 672246283Sdfr return "DW_AT_MIPS_epilog_begin"; 672346283Sdfr case DW_AT_MIPS_loop_unroll_factor: 672446283Sdfr return "DW_AT_MIPS_loop_unroll_factor"; 672546283Sdfr case DW_AT_MIPS_software_pipeline_depth: 672646283Sdfr return "DW_AT_MIPS_software_pipeline_depth"; 6727130803Smarcel#endif 672846283Sdfr case DW_AT_MIPS_linkage_name: 672946283Sdfr return "DW_AT_MIPS_linkage_name"; 673046283Sdfr 673146283Sdfr case DW_AT_sf_names: 673246283Sdfr return "DW_AT_sf_names"; 673346283Sdfr case DW_AT_src_info: 673446283Sdfr return "DW_AT_src_info"; 673546283Sdfr case DW_AT_mac_info: 673646283Sdfr return "DW_AT_mac_info"; 673746283Sdfr case DW_AT_src_coords: 673846283Sdfr return "DW_AT_src_coords"; 673946283Sdfr case DW_AT_body_begin: 674046283Sdfr return "DW_AT_body_begin"; 674146283Sdfr case DW_AT_body_end: 674246283Sdfr return "DW_AT_body_end"; 6743130803Smarcel case DW_AT_GNU_vector: 6744130803Smarcel return "DW_AT_GNU_vector"; 674546283Sdfr default: 674646283Sdfr return "DW_AT_<unknown>"; 674746283Sdfr } 674846283Sdfr} 674946283Sdfr 675046283Sdfr/* Convert a DWARF value form code into its string name. */ 675146283Sdfr 675246283Sdfrstatic char * 6753130803Smarceldwarf_form_name (unsigned form) 675446283Sdfr{ 675546283Sdfr switch (form) 675646283Sdfr { 675746283Sdfr case DW_FORM_addr: 675846283Sdfr return "DW_FORM_addr"; 675946283Sdfr case DW_FORM_block2: 676046283Sdfr return "DW_FORM_block2"; 676146283Sdfr case DW_FORM_block4: 676246283Sdfr return "DW_FORM_block4"; 676346283Sdfr case DW_FORM_data2: 676446283Sdfr return "DW_FORM_data2"; 676546283Sdfr case DW_FORM_data4: 676646283Sdfr return "DW_FORM_data4"; 676746283Sdfr case DW_FORM_data8: 676846283Sdfr return "DW_FORM_data8"; 676946283Sdfr case DW_FORM_string: 677046283Sdfr return "DW_FORM_string"; 677146283Sdfr case DW_FORM_block: 677246283Sdfr return "DW_FORM_block"; 677346283Sdfr case DW_FORM_block1: 677446283Sdfr return "DW_FORM_block1"; 677546283Sdfr case DW_FORM_data1: 677646283Sdfr return "DW_FORM_data1"; 677746283Sdfr case DW_FORM_flag: 677846283Sdfr return "DW_FORM_flag"; 677946283Sdfr case DW_FORM_sdata: 678046283Sdfr return "DW_FORM_sdata"; 678146283Sdfr case DW_FORM_strp: 678246283Sdfr return "DW_FORM_strp"; 678346283Sdfr case DW_FORM_udata: 678446283Sdfr return "DW_FORM_udata"; 678546283Sdfr case DW_FORM_ref_addr: 678646283Sdfr return "DW_FORM_ref_addr"; 678746283Sdfr case DW_FORM_ref1: 678846283Sdfr return "DW_FORM_ref1"; 678946283Sdfr case DW_FORM_ref2: 679046283Sdfr return "DW_FORM_ref2"; 679146283Sdfr case DW_FORM_ref4: 679246283Sdfr return "DW_FORM_ref4"; 679346283Sdfr case DW_FORM_ref8: 679446283Sdfr return "DW_FORM_ref8"; 679546283Sdfr case DW_FORM_ref_udata: 679646283Sdfr return "DW_FORM_ref_udata"; 679746283Sdfr case DW_FORM_indirect: 679846283Sdfr return "DW_FORM_indirect"; 679946283Sdfr default: 680046283Sdfr return "DW_FORM_<unknown>"; 680146283Sdfr } 680246283Sdfr} 680346283Sdfr 680446283Sdfr/* Convert a DWARF stack opcode into its string name. */ 680546283Sdfr 680646283Sdfrstatic char * 6807130803Smarceldwarf_stack_op_name (unsigned op) 680846283Sdfr{ 680946283Sdfr switch (op) 681046283Sdfr { 681146283Sdfr case DW_OP_addr: 681246283Sdfr return "DW_OP_addr"; 681346283Sdfr case DW_OP_deref: 681446283Sdfr return "DW_OP_deref"; 681546283Sdfr case DW_OP_const1u: 681646283Sdfr return "DW_OP_const1u"; 681746283Sdfr case DW_OP_const1s: 681846283Sdfr return "DW_OP_const1s"; 681946283Sdfr case DW_OP_const2u: 682046283Sdfr return "DW_OP_const2u"; 682146283Sdfr case DW_OP_const2s: 682246283Sdfr return "DW_OP_const2s"; 682346283Sdfr case DW_OP_const4u: 682446283Sdfr return "DW_OP_const4u"; 682546283Sdfr case DW_OP_const4s: 682646283Sdfr return "DW_OP_const4s"; 682746283Sdfr case DW_OP_const8u: 682846283Sdfr return "DW_OP_const8u"; 682946283Sdfr case DW_OP_const8s: 683046283Sdfr return "DW_OP_const8s"; 683146283Sdfr case DW_OP_constu: 683246283Sdfr return "DW_OP_constu"; 683346283Sdfr case DW_OP_consts: 683446283Sdfr return "DW_OP_consts"; 683546283Sdfr case DW_OP_dup: 683646283Sdfr return "DW_OP_dup"; 683746283Sdfr case DW_OP_drop: 683846283Sdfr return "DW_OP_drop"; 683946283Sdfr case DW_OP_over: 684046283Sdfr return "DW_OP_over"; 684146283Sdfr case DW_OP_pick: 684246283Sdfr return "DW_OP_pick"; 684346283Sdfr case DW_OP_swap: 684446283Sdfr return "DW_OP_swap"; 684546283Sdfr case DW_OP_rot: 684646283Sdfr return "DW_OP_rot"; 684746283Sdfr case DW_OP_xderef: 684846283Sdfr return "DW_OP_xderef"; 684946283Sdfr case DW_OP_abs: 685046283Sdfr return "DW_OP_abs"; 685146283Sdfr case DW_OP_and: 685246283Sdfr return "DW_OP_and"; 685346283Sdfr case DW_OP_div: 685446283Sdfr return "DW_OP_div"; 685546283Sdfr case DW_OP_minus: 685646283Sdfr return "DW_OP_minus"; 685746283Sdfr case DW_OP_mod: 685846283Sdfr return "DW_OP_mod"; 685946283Sdfr case DW_OP_mul: 686046283Sdfr return "DW_OP_mul"; 686146283Sdfr case DW_OP_neg: 686246283Sdfr return "DW_OP_neg"; 686346283Sdfr case DW_OP_not: 686446283Sdfr return "DW_OP_not"; 686546283Sdfr case DW_OP_or: 686646283Sdfr return "DW_OP_or"; 686746283Sdfr case DW_OP_plus: 686846283Sdfr return "DW_OP_plus"; 686946283Sdfr case DW_OP_plus_uconst: 687046283Sdfr return "DW_OP_plus_uconst"; 687146283Sdfr case DW_OP_shl: 687246283Sdfr return "DW_OP_shl"; 687346283Sdfr case DW_OP_shr: 687446283Sdfr return "DW_OP_shr"; 687546283Sdfr case DW_OP_shra: 687646283Sdfr return "DW_OP_shra"; 687746283Sdfr case DW_OP_xor: 687846283Sdfr return "DW_OP_xor"; 687946283Sdfr case DW_OP_bra: 688046283Sdfr return "DW_OP_bra"; 688146283Sdfr case DW_OP_eq: 688246283Sdfr return "DW_OP_eq"; 688346283Sdfr case DW_OP_ge: 688446283Sdfr return "DW_OP_ge"; 688546283Sdfr case DW_OP_gt: 688646283Sdfr return "DW_OP_gt"; 688746283Sdfr case DW_OP_le: 688846283Sdfr return "DW_OP_le"; 688946283Sdfr case DW_OP_lt: 689046283Sdfr return "DW_OP_lt"; 689146283Sdfr case DW_OP_ne: 689246283Sdfr return "DW_OP_ne"; 689346283Sdfr case DW_OP_skip: 689446283Sdfr return "DW_OP_skip"; 689546283Sdfr case DW_OP_lit0: 689646283Sdfr return "DW_OP_lit0"; 689746283Sdfr case DW_OP_lit1: 689846283Sdfr return "DW_OP_lit1"; 689946283Sdfr case DW_OP_lit2: 690046283Sdfr return "DW_OP_lit2"; 690146283Sdfr case DW_OP_lit3: 690246283Sdfr return "DW_OP_lit3"; 690346283Sdfr case DW_OP_lit4: 690446283Sdfr return "DW_OP_lit4"; 690546283Sdfr case DW_OP_lit5: 690646283Sdfr return "DW_OP_lit5"; 690746283Sdfr case DW_OP_lit6: 690846283Sdfr return "DW_OP_lit6"; 690946283Sdfr case DW_OP_lit7: 691046283Sdfr return "DW_OP_lit7"; 691146283Sdfr case DW_OP_lit8: 691246283Sdfr return "DW_OP_lit8"; 691346283Sdfr case DW_OP_lit9: 691446283Sdfr return "DW_OP_lit9"; 691546283Sdfr case DW_OP_lit10: 691646283Sdfr return "DW_OP_lit10"; 691746283Sdfr case DW_OP_lit11: 691846283Sdfr return "DW_OP_lit11"; 691946283Sdfr case DW_OP_lit12: 692046283Sdfr return "DW_OP_lit12"; 692146283Sdfr case DW_OP_lit13: 692246283Sdfr return "DW_OP_lit13"; 692346283Sdfr case DW_OP_lit14: 692446283Sdfr return "DW_OP_lit14"; 692546283Sdfr case DW_OP_lit15: 692646283Sdfr return "DW_OP_lit15"; 692746283Sdfr case DW_OP_lit16: 692846283Sdfr return "DW_OP_lit16"; 692946283Sdfr case DW_OP_lit17: 693046283Sdfr return "DW_OP_lit17"; 693146283Sdfr case DW_OP_lit18: 693246283Sdfr return "DW_OP_lit18"; 693346283Sdfr case DW_OP_lit19: 693446283Sdfr return "DW_OP_lit19"; 693546283Sdfr case DW_OP_lit20: 693646283Sdfr return "DW_OP_lit20"; 693746283Sdfr case DW_OP_lit21: 693846283Sdfr return "DW_OP_lit21"; 693946283Sdfr case DW_OP_lit22: 694046283Sdfr return "DW_OP_lit22"; 694146283Sdfr case DW_OP_lit23: 694246283Sdfr return "DW_OP_lit23"; 694346283Sdfr case DW_OP_lit24: 694446283Sdfr return "DW_OP_lit24"; 694546283Sdfr case DW_OP_lit25: 694646283Sdfr return "DW_OP_lit25"; 694746283Sdfr case DW_OP_lit26: 694846283Sdfr return "DW_OP_lit26"; 694946283Sdfr case DW_OP_lit27: 695046283Sdfr return "DW_OP_lit27"; 695146283Sdfr case DW_OP_lit28: 695246283Sdfr return "DW_OP_lit28"; 695346283Sdfr case DW_OP_lit29: 695446283Sdfr return "DW_OP_lit29"; 695546283Sdfr case DW_OP_lit30: 695646283Sdfr return "DW_OP_lit30"; 695746283Sdfr case DW_OP_lit31: 695846283Sdfr return "DW_OP_lit31"; 695946283Sdfr case DW_OP_reg0: 696046283Sdfr return "DW_OP_reg0"; 696146283Sdfr case DW_OP_reg1: 696246283Sdfr return "DW_OP_reg1"; 696346283Sdfr case DW_OP_reg2: 696446283Sdfr return "DW_OP_reg2"; 696546283Sdfr case DW_OP_reg3: 696646283Sdfr return "DW_OP_reg3"; 696746283Sdfr case DW_OP_reg4: 696846283Sdfr return "DW_OP_reg4"; 696946283Sdfr case DW_OP_reg5: 697046283Sdfr return "DW_OP_reg5"; 697146283Sdfr case DW_OP_reg6: 697246283Sdfr return "DW_OP_reg6"; 697346283Sdfr case DW_OP_reg7: 697446283Sdfr return "DW_OP_reg7"; 697546283Sdfr case DW_OP_reg8: 697646283Sdfr return "DW_OP_reg8"; 697746283Sdfr case DW_OP_reg9: 697846283Sdfr return "DW_OP_reg9"; 697946283Sdfr case DW_OP_reg10: 698046283Sdfr return "DW_OP_reg10"; 698146283Sdfr case DW_OP_reg11: 698246283Sdfr return "DW_OP_reg11"; 698346283Sdfr case DW_OP_reg12: 698446283Sdfr return "DW_OP_reg12"; 698546283Sdfr case DW_OP_reg13: 698646283Sdfr return "DW_OP_reg13"; 698746283Sdfr case DW_OP_reg14: 698846283Sdfr return "DW_OP_reg14"; 698946283Sdfr case DW_OP_reg15: 699046283Sdfr return "DW_OP_reg15"; 699146283Sdfr case DW_OP_reg16: 699246283Sdfr return "DW_OP_reg16"; 699346283Sdfr case DW_OP_reg17: 699446283Sdfr return "DW_OP_reg17"; 699546283Sdfr case DW_OP_reg18: 699646283Sdfr return "DW_OP_reg18"; 699746283Sdfr case DW_OP_reg19: 699846283Sdfr return "DW_OP_reg19"; 699946283Sdfr case DW_OP_reg20: 700046283Sdfr return "DW_OP_reg20"; 700146283Sdfr case DW_OP_reg21: 700246283Sdfr return "DW_OP_reg21"; 700346283Sdfr case DW_OP_reg22: 700446283Sdfr return "DW_OP_reg22"; 700546283Sdfr case DW_OP_reg23: 700646283Sdfr return "DW_OP_reg23"; 700746283Sdfr case DW_OP_reg24: 700846283Sdfr return "DW_OP_reg24"; 700946283Sdfr case DW_OP_reg25: 701046283Sdfr return "DW_OP_reg25"; 701146283Sdfr case DW_OP_reg26: 701246283Sdfr return "DW_OP_reg26"; 701346283Sdfr case DW_OP_reg27: 701446283Sdfr return "DW_OP_reg27"; 701546283Sdfr case DW_OP_reg28: 701646283Sdfr return "DW_OP_reg28"; 701746283Sdfr case DW_OP_reg29: 701846283Sdfr return "DW_OP_reg29"; 701946283Sdfr case DW_OP_reg30: 702046283Sdfr return "DW_OP_reg30"; 702146283Sdfr case DW_OP_reg31: 702246283Sdfr return "DW_OP_reg31"; 702346283Sdfr case DW_OP_breg0: 702446283Sdfr return "DW_OP_breg0"; 702546283Sdfr case DW_OP_breg1: 702646283Sdfr return "DW_OP_breg1"; 702746283Sdfr case DW_OP_breg2: 702846283Sdfr return "DW_OP_breg2"; 702946283Sdfr case DW_OP_breg3: 703046283Sdfr return "DW_OP_breg3"; 703146283Sdfr case DW_OP_breg4: 703246283Sdfr return "DW_OP_breg4"; 703346283Sdfr case DW_OP_breg5: 703446283Sdfr return "DW_OP_breg5"; 703546283Sdfr case DW_OP_breg6: 703646283Sdfr return "DW_OP_breg6"; 703746283Sdfr case DW_OP_breg7: 703846283Sdfr return "DW_OP_breg7"; 703946283Sdfr case DW_OP_breg8: 704046283Sdfr return "DW_OP_breg8"; 704146283Sdfr case DW_OP_breg9: 704246283Sdfr return "DW_OP_breg9"; 704346283Sdfr case DW_OP_breg10: 704446283Sdfr return "DW_OP_breg10"; 704546283Sdfr case DW_OP_breg11: 704646283Sdfr return "DW_OP_breg11"; 704746283Sdfr case DW_OP_breg12: 704846283Sdfr return "DW_OP_breg12"; 704946283Sdfr case DW_OP_breg13: 705046283Sdfr return "DW_OP_breg13"; 705146283Sdfr case DW_OP_breg14: 705246283Sdfr return "DW_OP_breg14"; 705346283Sdfr case DW_OP_breg15: 705446283Sdfr return "DW_OP_breg15"; 705546283Sdfr case DW_OP_breg16: 705646283Sdfr return "DW_OP_breg16"; 705746283Sdfr case DW_OP_breg17: 705846283Sdfr return "DW_OP_breg17"; 705946283Sdfr case DW_OP_breg18: 706046283Sdfr return "DW_OP_breg18"; 706146283Sdfr case DW_OP_breg19: 706246283Sdfr return "DW_OP_breg19"; 706346283Sdfr case DW_OP_breg20: 706446283Sdfr return "DW_OP_breg20"; 706546283Sdfr case DW_OP_breg21: 706646283Sdfr return "DW_OP_breg21"; 706746283Sdfr case DW_OP_breg22: 706846283Sdfr return "DW_OP_breg22"; 706946283Sdfr case DW_OP_breg23: 707046283Sdfr return "DW_OP_breg23"; 707146283Sdfr case DW_OP_breg24: 707246283Sdfr return "DW_OP_breg24"; 707346283Sdfr case DW_OP_breg25: 707446283Sdfr return "DW_OP_breg25"; 707546283Sdfr case DW_OP_breg26: 707646283Sdfr return "DW_OP_breg26"; 707746283Sdfr case DW_OP_breg27: 707846283Sdfr return "DW_OP_breg27"; 707946283Sdfr case DW_OP_breg28: 708046283Sdfr return "DW_OP_breg28"; 708146283Sdfr case DW_OP_breg29: 708246283Sdfr return "DW_OP_breg29"; 708346283Sdfr case DW_OP_breg30: 708446283Sdfr return "DW_OP_breg30"; 708546283Sdfr case DW_OP_breg31: 708646283Sdfr return "DW_OP_breg31"; 708746283Sdfr case DW_OP_regx: 708846283Sdfr return "DW_OP_regx"; 708946283Sdfr case DW_OP_fbreg: 709046283Sdfr return "DW_OP_fbreg"; 709146283Sdfr case DW_OP_bregx: 709246283Sdfr return "DW_OP_bregx"; 709346283Sdfr case DW_OP_piece: 709446283Sdfr return "DW_OP_piece"; 709546283Sdfr case DW_OP_deref_size: 709646283Sdfr return "DW_OP_deref_size"; 709746283Sdfr case DW_OP_xderef_size: 709846283Sdfr return "DW_OP_xderef_size"; 709946283Sdfr case DW_OP_nop: 710046283Sdfr return "DW_OP_nop"; 7101130803Smarcel /* DWARF 3 extensions. */ 7102130803Smarcel case DW_OP_push_object_address: 7103130803Smarcel return "DW_OP_push_object_address"; 7104130803Smarcel case DW_OP_call2: 7105130803Smarcel return "DW_OP_call2"; 7106130803Smarcel case DW_OP_call4: 7107130803Smarcel return "DW_OP_call4"; 7108130803Smarcel case DW_OP_call_ref: 7109130803Smarcel return "DW_OP_call_ref"; 7110130803Smarcel /* GNU extensions. */ 7111130803Smarcel case DW_OP_GNU_push_tls_address: 7112130803Smarcel return "DW_OP_GNU_push_tls_address"; 711346283Sdfr default: 711446283Sdfr return "OP_<unknown>"; 711546283Sdfr } 711646283Sdfr} 711746283Sdfr 711846283Sdfrstatic char * 711998944Sobriendwarf_bool_name (unsigned mybool) 712046283Sdfr{ 712146283Sdfr if (mybool) 712246283Sdfr return "TRUE"; 712346283Sdfr else 712446283Sdfr return "FALSE"; 712546283Sdfr} 712646283Sdfr 712746283Sdfr/* Convert a DWARF type code into its string name. */ 712846283Sdfr 712946283Sdfrstatic char * 7130130803Smarceldwarf_type_encoding_name (unsigned enc) 713146283Sdfr{ 713246283Sdfr switch (enc) 713346283Sdfr { 713446283Sdfr case DW_ATE_address: 713546283Sdfr return "DW_ATE_address"; 713646283Sdfr case DW_ATE_boolean: 713746283Sdfr return "DW_ATE_boolean"; 713846283Sdfr case DW_ATE_complex_float: 713946283Sdfr return "DW_ATE_complex_float"; 714046283Sdfr case DW_ATE_float: 714146283Sdfr return "DW_ATE_float"; 714246283Sdfr case DW_ATE_signed: 714346283Sdfr return "DW_ATE_signed"; 714446283Sdfr case DW_ATE_signed_char: 714546283Sdfr return "DW_ATE_signed_char"; 714646283Sdfr case DW_ATE_unsigned: 714746283Sdfr return "DW_ATE_unsigned"; 714846283Sdfr case DW_ATE_unsigned_char: 714946283Sdfr return "DW_ATE_unsigned_char"; 7150130803Smarcel case DW_ATE_imaginary_float: 7151130803Smarcel return "DW_ATE_imaginary_float"; 715246283Sdfr default: 715346283Sdfr return "DW_ATE_<unknown>"; 715446283Sdfr } 715546283Sdfr} 715646283Sdfr 715746283Sdfr/* Convert a DWARF call frame info operation to its string name. */ 715846283Sdfr 715946283Sdfr#if 0 716046283Sdfrstatic char * 7161130803Smarceldwarf_cfi_name (unsigned cfi_opc) 716246283Sdfr{ 716346283Sdfr switch (cfi_opc) 716446283Sdfr { 716546283Sdfr case DW_CFA_advance_loc: 716646283Sdfr return "DW_CFA_advance_loc"; 716746283Sdfr case DW_CFA_offset: 716846283Sdfr return "DW_CFA_offset"; 716946283Sdfr case DW_CFA_restore: 717046283Sdfr return "DW_CFA_restore"; 717146283Sdfr case DW_CFA_nop: 717246283Sdfr return "DW_CFA_nop"; 717346283Sdfr case DW_CFA_set_loc: 717446283Sdfr return "DW_CFA_set_loc"; 717546283Sdfr case DW_CFA_advance_loc1: 717646283Sdfr return "DW_CFA_advance_loc1"; 717746283Sdfr case DW_CFA_advance_loc2: 717846283Sdfr return "DW_CFA_advance_loc2"; 717946283Sdfr case DW_CFA_advance_loc4: 718046283Sdfr return "DW_CFA_advance_loc4"; 718146283Sdfr case DW_CFA_offset_extended: 718246283Sdfr return "DW_CFA_offset_extended"; 718346283Sdfr case DW_CFA_restore_extended: 718446283Sdfr return "DW_CFA_restore_extended"; 718546283Sdfr case DW_CFA_undefined: 718646283Sdfr return "DW_CFA_undefined"; 718746283Sdfr case DW_CFA_same_value: 718846283Sdfr return "DW_CFA_same_value"; 718946283Sdfr case DW_CFA_register: 719046283Sdfr return "DW_CFA_register"; 719146283Sdfr case DW_CFA_remember_state: 719246283Sdfr return "DW_CFA_remember_state"; 719346283Sdfr case DW_CFA_restore_state: 719446283Sdfr return "DW_CFA_restore_state"; 719546283Sdfr case DW_CFA_def_cfa: 719646283Sdfr return "DW_CFA_def_cfa"; 719746283Sdfr case DW_CFA_def_cfa_register: 719846283Sdfr return "DW_CFA_def_cfa_register"; 719946283Sdfr case DW_CFA_def_cfa_offset: 720046283Sdfr return "DW_CFA_def_cfa_offset"; 720198944Sobrien 720298944Sobrien /* DWARF 3 */ 720398944Sobrien case DW_CFA_def_cfa_expression: 720498944Sobrien return "DW_CFA_def_cfa_expression"; 720598944Sobrien case DW_CFA_expression: 720698944Sobrien return "DW_CFA_expression"; 720798944Sobrien case DW_CFA_offset_extended_sf: 720898944Sobrien return "DW_CFA_offset_extended_sf"; 720998944Sobrien case DW_CFA_def_cfa_sf: 721098944Sobrien return "DW_CFA_def_cfa_sf"; 721198944Sobrien case DW_CFA_def_cfa_offset_sf: 721298944Sobrien return "DW_CFA_def_cfa_offset_sf"; 721398944Sobrien 721446283Sdfr /* SGI/MIPS specific */ 721546283Sdfr case DW_CFA_MIPS_advance_loc8: 721646283Sdfr return "DW_CFA_MIPS_advance_loc8"; 721798944Sobrien 721898944Sobrien /* GNU extensions */ 721998944Sobrien case DW_CFA_GNU_window_save: 722098944Sobrien return "DW_CFA_GNU_window_save"; 722198944Sobrien case DW_CFA_GNU_args_size: 722298944Sobrien return "DW_CFA_GNU_args_size"; 722398944Sobrien case DW_CFA_GNU_negative_offset_extended: 722498944Sobrien return "DW_CFA_GNU_negative_offset_extended"; 722598944Sobrien 722646283Sdfr default: 722746283Sdfr return "DW_CFA_<unknown>"; 722846283Sdfr } 722946283Sdfr} 723046283Sdfr#endif 723146283Sdfr 723298944Sobrienstatic void 723398944Sobriendump_die (struct die_info *die) 723446283Sdfr{ 723546283Sdfr unsigned int i; 723646283Sdfr 723798944Sobrien fprintf_unfiltered (gdb_stderr, "Die: %s (abbrev = %d, offset = %d)\n", 723846283Sdfr dwarf_tag_name (die->tag), die->abbrev, die->offset); 723998944Sobrien fprintf_unfiltered (gdb_stderr, "\thas children: %s\n", 7240130803Smarcel dwarf_bool_name (die->child != NULL)); 724146283Sdfr 724298944Sobrien fprintf_unfiltered (gdb_stderr, "\tattributes:\n"); 724346283Sdfr for (i = 0; i < die->num_attrs; ++i) 724446283Sdfr { 724598944Sobrien fprintf_unfiltered (gdb_stderr, "\t\t%s (%s) ", 724646283Sdfr dwarf_attr_name (die->attrs[i].name), 724746283Sdfr dwarf_form_name (die->attrs[i].form)); 724846283Sdfr switch (die->attrs[i].form) 724946283Sdfr { 725046283Sdfr case DW_FORM_ref_addr: 725146283Sdfr case DW_FORM_addr: 725298944Sobrien fprintf_unfiltered (gdb_stderr, "address: "); 725346283Sdfr print_address_numeric (DW_ADDR (&die->attrs[i]), 1, gdb_stderr); 725446283Sdfr break; 725546283Sdfr case DW_FORM_block2: 725646283Sdfr case DW_FORM_block4: 725746283Sdfr case DW_FORM_block: 725846283Sdfr case DW_FORM_block1: 725998944Sobrien fprintf_unfiltered (gdb_stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size); 726046283Sdfr break; 726146283Sdfr case DW_FORM_data1: 726246283Sdfr case DW_FORM_data2: 726346283Sdfr case DW_FORM_data4: 726498944Sobrien case DW_FORM_data8: 726546283Sdfr case DW_FORM_ref1: 726646283Sdfr case DW_FORM_ref2: 726746283Sdfr case DW_FORM_ref4: 726846283Sdfr case DW_FORM_udata: 726946283Sdfr case DW_FORM_sdata: 727098944Sobrien fprintf_unfiltered (gdb_stderr, "constant: %ld", DW_UNSND (&die->attrs[i])); 727146283Sdfr break; 727246283Sdfr case DW_FORM_string: 727398944Sobrien case DW_FORM_strp: 727498944Sobrien fprintf_unfiltered (gdb_stderr, "string: \"%s\"", 727546283Sdfr DW_STRING (&die->attrs[i]) 727698944Sobrien ? DW_STRING (&die->attrs[i]) : ""); 727746283Sdfr break; 727846283Sdfr case DW_FORM_flag: 727946283Sdfr if (DW_UNSND (&die->attrs[i])) 728098944Sobrien fprintf_unfiltered (gdb_stderr, "flag: TRUE"); 728146283Sdfr else 728298944Sobrien fprintf_unfiltered (gdb_stderr, "flag: FALSE"); 728346283Sdfr break; 7284239870Sdim case DW_FORM_flag_present: 7285239870Sdim fprintf_unfiltered (gdb_stderr, "flag: TRUE"); 7286239870Sdim break; 728798944Sobrien case DW_FORM_indirect: 728898944Sobrien /* the reader will have reduced the indirect form to 728998944Sobrien the "base form" so this form should not occur */ 729098944Sobrien fprintf_unfiltered (gdb_stderr, "unexpected attribute form: DW_FORM_indirect"); 729198944Sobrien break; 729246283Sdfr default: 729398944Sobrien fprintf_unfiltered (gdb_stderr, "unsupported attribute form: %d.", 729498944Sobrien die->attrs[i].form); 729546283Sdfr } 729698944Sobrien fprintf_unfiltered (gdb_stderr, "\n"); 729746283Sdfr } 729846283Sdfr} 729946283Sdfr 730098944Sobrienstatic void 730198944Sobriendump_die_list (struct die_info *die) 730246283Sdfr{ 730346283Sdfr while (die) 730446283Sdfr { 730546283Sdfr dump_die (die); 7306130803Smarcel if (die->child != NULL) 7307130803Smarcel dump_die_list (die->child); 7308130803Smarcel if (die->sibling != NULL) 7309130803Smarcel dump_die_list (die->sibling); 731046283Sdfr } 731146283Sdfr} 731246283Sdfr 731398944Sobrienstatic void 731498944Sobrienstore_in_ref_table (unsigned int offset, struct die_info *die) 731546283Sdfr{ 731646283Sdfr int h; 731746283Sdfr struct die_info *old; 731846283Sdfr 731946283Sdfr h = (offset % REF_HASH_SIZE); 732046283Sdfr old = die_ref_table[h]; 732146283Sdfr die->next_ref = old; 732246283Sdfr die_ref_table[h] = die; 732346283Sdfr} 732446283Sdfr 732546283Sdfr 732646283Sdfrstatic void 732798944Sobriendwarf2_empty_hash_tables (void) 732846283Sdfr{ 732946283Sdfr memset (die_ref_table, 0, sizeof (die_ref_table)); 733046283Sdfr} 733146283Sdfr 733246283Sdfrstatic unsigned int 7333130803Smarceldwarf2_get_ref_die_offset (struct attribute *attr, struct dwarf2_cu *cu) 733446283Sdfr{ 733546283Sdfr unsigned int result = 0; 733646283Sdfr 733746283Sdfr switch (attr->form) 733846283Sdfr { 733946283Sdfr case DW_FORM_ref_addr: 734046283Sdfr result = DW_ADDR (attr); 734146283Sdfr break; 734246283Sdfr case DW_FORM_ref1: 734346283Sdfr case DW_FORM_ref2: 734446283Sdfr case DW_FORM_ref4: 734598944Sobrien case DW_FORM_ref8: 734646283Sdfr case DW_FORM_ref_udata: 7347130803Smarcel result = cu->header.offset + DW_UNSND (attr); 734846283Sdfr break; 734946283Sdfr default: 7350130803Smarcel complaint (&symfile_complaints, 7351130803Smarcel "unsupported die ref attribute form: '%s'", 7352130803Smarcel dwarf_form_name (attr->form)); 735346283Sdfr } 735446283Sdfr return result; 735546283Sdfr} 735646283Sdfr 7357130803Smarcel/* Return the constant value held by the given attribute. Return -1 7358130803Smarcel if the value held by the attribute is not constant. */ 7359130803Smarcel 7360130803Smarcelstatic int 7361130803Smarceldwarf2_get_attr_constant_value (struct attribute *attr, int default_value) 7362130803Smarcel{ 7363130803Smarcel if (attr->form == DW_FORM_sdata) 7364130803Smarcel return DW_SND (attr); 7365130803Smarcel else if (attr->form == DW_FORM_udata 7366130803Smarcel || attr->form == DW_FORM_data1 7367130803Smarcel || attr->form == DW_FORM_data2 7368130803Smarcel || attr->form == DW_FORM_data4 7369130803Smarcel || attr->form == DW_FORM_data8) 7370130803Smarcel return DW_UNSND (attr); 7371130803Smarcel else 7372130803Smarcel { 7373130803Smarcel complaint (&symfile_complaints, "Attribute value is not a constant (%s)", 7374130803Smarcel dwarf_form_name (attr->form)); 7375130803Smarcel return default_value; 7376130803Smarcel } 7377130803Smarcel} 7378130803Smarcel 737998944Sobrienstatic struct die_info * 738098944Sobrienfollow_die_ref (unsigned int offset) 738146283Sdfr{ 738246283Sdfr struct die_info *die; 738346283Sdfr int h; 738446283Sdfr 738546283Sdfr h = (offset % REF_HASH_SIZE); 738646283Sdfr die = die_ref_table[h]; 738746283Sdfr while (die) 738846283Sdfr { 738946283Sdfr if (die->offset == offset) 739046283Sdfr { 739146283Sdfr return die; 739246283Sdfr } 739346283Sdfr die = die->next_ref; 739446283Sdfr } 739546283Sdfr return NULL; 739646283Sdfr} 739746283Sdfr 739846283Sdfrstatic struct type * 7399130803Smarceldwarf2_fundamental_type (struct objfile *objfile, int typeid, 7400130803Smarcel struct dwarf2_cu *cu) 740146283Sdfr{ 740246283Sdfr if (typeid < 0 || typeid >= FT_NUM_MEMBERS) 740346283Sdfr { 7404130803Smarcel error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]", 7405130803Smarcel typeid, objfile->name); 740646283Sdfr } 740746283Sdfr 740846283Sdfr /* Look for this particular type in the fundamental type vector. If 740946283Sdfr one is not found, create and install one appropriate for the 741046283Sdfr current language and the current target machine. */ 741146283Sdfr 7412130803Smarcel if (cu->ftypes[typeid] == NULL) 741346283Sdfr { 7414130803Smarcel cu->ftypes[typeid] = cu->language_defn->la_fund_type (objfile, typeid); 741546283Sdfr } 741646283Sdfr 7417130803Smarcel return (cu->ftypes[typeid]); 741846283Sdfr} 741946283Sdfr 742046283Sdfr/* Decode simple location descriptions. 742146283Sdfr Given a pointer to a dwarf block that defines a location, compute 742246283Sdfr the location and return the value. 742346283Sdfr 7424130803Smarcel NOTE drow/2003-11-18: This function is called in two situations 7425130803Smarcel now: for the address of static or global variables (partial symbols 7426130803Smarcel only) and for offsets into structures which are expected to be 7427130803Smarcel (more or less) constant. The partial symbol case should go away, 7428130803Smarcel and only the constant case should remain. That will let this 7429130803Smarcel function complain more accurately. A few special modes are allowed 7430130803Smarcel without complaint for global variables (for instance, global 7431130803Smarcel register values and thread-local values). 743246283Sdfr 743346283Sdfr A location description containing no operations indicates that the 7434130803Smarcel object is optimized out. The return value is 0 for that case. 7435130803Smarcel FIXME drow/2003-11-16: No callers check for this case any more; soon all 7436130803Smarcel callers will only want a very basic result and this can become a 7437130803Smarcel complaint. 743846283Sdfr 743946283Sdfr When the result is a register number, the global isreg flag is set, 744046283Sdfr otherwise it is cleared. 744146283Sdfr 744246283Sdfr Note that stack[0] is unused except as a default error return. 744346283Sdfr Note that stack overflow is not yet handled. */ 744446283Sdfr 744546283Sdfrstatic CORE_ADDR 7446130803Smarceldecode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) 744746283Sdfr{ 7448130803Smarcel struct objfile *objfile = cu->objfile; 7449130803Smarcel struct comp_unit_head *cu_header = &cu->header; 745046283Sdfr int i; 745146283Sdfr int size = blk->size; 745246283Sdfr char *data = blk->data; 745346283Sdfr CORE_ADDR stack[64]; 745446283Sdfr int stacki; 745546283Sdfr unsigned int bytes_read, unsnd; 745646283Sdfr unsigned char op; 745746283Sdfr 745846283Sdfr i = 0; 745946283Sdfr stacki = 0; 746046283Sdfr stack[stacki] = 0; 746146283Sdfr isreg = 0; 746246283Sdfr 746346283Sdfr while (i < size) 746446283Sdfr { 746546283Sdfr op = data[i++]; 746646283Sdfr switch (op) 746746283Sdfr { 746898944Sobrien case DW_OP_lit0: 746998944Sobrien case DW_OP_lit1: 747098944Sobrien case DW_OP_lit2: 747198944Sobrien case DW_OP_lit3: 747298944Sobrien case DW_OP_lit4: 747398944Sobrien case DW_OP_lit5: 747498944Sobrien case DW_OP_lit6: 747598944Sobrien case DW_OP_lit7: 747698944Sobrien case DW_OP_lit8: 747798944Sobrien case DW_OP_lit9: 747898944Sobrien case DW_OP_lit10: 747998944Sobrien case DW_OP_lit11: 748098944Sobrien case DW_OP_lit12: 748198944Sobrien case DW_OP_lit13: 748298944Sobrien case DW_OP_lit14: 748398944Sobrien case DW_OP_lit15: 748498944Sobrien case DW_OP_lit16: 748598944Sobrien case DW_OP_lit17: 748698944Sobrien case DW_OP_lit18: 748798944Sobrien case DW_OP_lit19: 748898944Sobrien case DW_OP_lit20: 748998944Sobrien case DW_OP_lit21: 749098944Sobrien case DW_OP_lit22: 749198944Sobrien case DW_OP_lit23: 749298944Sobrien case DW_OP_lit24: 749398944Sobrien case DW_OP_lit25: 749498944Sobrien case DW_OP_lit26: 749598944Sobrien case DW_OP_lit27: 749698944Sobrien case DW_OP_lit28: 749798944Sobrien case DW_OP_lit29: 749898944Sobrien case DW_OP_lit30: 749998944Sobrien case DW_OP_lit31: 750098944Sobrien stack[++stacki] = op - DW_OP_lit0; 750198944Sobrien break; 750298944Sobrien 750346283Sdfr case DW_OP_reg0: 750446283Sdfr case DW_OP_reg1: 750546283Sdfr case DW_OP_reg2: 750646283Sdfr case DW_OP_reg3: 750746283Sdfr case DW_OP_reg4: 750846283Sdfr case DW_OP_reg5: 750946283Sdfr case DW_OP_reg6: 751046283Sdfr case DW_OP_reg7: 751146283Sdfr case DW_OP_reg8: 751246283Sdfr case DW_OP_reg9: 751346283Sdfr case DW_OP_reg10: 751446283Sdfr case DW_OP_reg11: 751546283Sdfr case DW_OP_reg12: 751646283Sdfr case DW_OP_reg13: 751746283Sdfr case DW_OP_reg14: 751846283Sdfr case DW_OP_reg15: 751946283Sdfr case DW_OP_reg16: 752046283Sdfr case DW_OP_reg17: 752146283Sdfr case DW_OP_reg18: 752246283Sdfr case DW_OP_reg19: 752346283Sdfr case DW_OP_reg20: 752446283Sdfr case DW_OP_reg21: 752546283Sdfr case DW_OP_reg22: 752646283Sdfr case DW_OP_reg23: 752746283Sdfr case DW_OP_reg24: 752846283Sdfr case DW_OP_reg25: 752946283Sdfr case DW_OP_reg26: 753046283Sdfr case DW_OP_reg27: 753146283Sdfr case DW_OP_reg28: 753246283Sdfr case DW_OP_reg29: 753346283Sdfr case DW_OP_reg30: 753446283Sdfr case DW_OP_reg31: 753546283Sdfr isreg = 1; 753646283Sdfr stack[++stacki] = op - DW_OP_reg0; 7537130803Smarcel if (i < size) 7538130803Smarcel dwarf2_complex_location_expr_complaint (); 753946283Sdfr break; 754046283Sdfr 754146283Sdfr case DW_OP_regx: 754246283Sdfr isreg = 1; 754346283Sdfr unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); 754446283Sdfr i += bytes_read; 754546283Sdfr stack[++stacki] = unsnd; 7546130803Smarcel if (i < size) 7547130803Smarcel dwarf2_complex_location_expr_complaint (); 754846283Sdfr break; 754946283Sdfr 755046283Sdfr case DW_OP_addr: 755198944Sobrien stack[++stacki] = read_address (objfile->obfd, &data[i], 7552130803Smarcel cu, &bytes_read); 755398944Sobrien i += bytes_read; 755446283Sdfr break; 755546283Sdfr 755646283Sdfr case DW_OP_const1u: 755746283Sdfr stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); 755846283Sdfr i += 1; 755946283Sdfr break; 756046283Sdfr 756146283Sdfr case DW_OP_const1s: 756246283Sdfr stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); 756346283Sdfr i += 1; 756446283Sdfr break; 756546283Sdfr 756646283Sdfr case DW_OP_const2u: 756746283Sdfr stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); 756846283Sdfr i += 2; 756946283Sdfr break; 757046283Sdfr 757146283Sdfr case DW_OP_const2s: 757246283Sdfr stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); 757346283Sdfr i += 2; 757446283Sdfr break; 757546283Sdfr 757646283Sdfr case DW_OP_const4u: 757746283Sdfr stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); 757846283Sdfr i += 4; 757946283Sdfr break; 758046283Sdfr 758146283Sdfr case DW_OP_const4s: 758246283Sdfr stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); 758346283Sdfr i += 4; 758446283Sdfr break; 758546283Sdfr 758646283Sdfr case DW_OP_constu: 758746283Sdfr stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), 758898944Sobrien &bytes_read); 758946283Sdfr i += bytes_read; 759046283Sdfr break; 759146283Sdfr 759246283Sdfr case DW_OP_consts: 759346283Sdfr stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); 759446283Sdfr i += bytes_read; 759546283Sdfr break; 759646283Sdfr 759798944Sobrien case DW_OP_dup: 759898944Sobrien stack[stacki + 1] = stack[stacki]; 759998944Sobrien stacki++; 760098944Sobrien break; 760198944Sobrien 760246283Sdfr case DW_OP_plus: 760346283Sdfr stack[stacki - 1] += stack[stacki]; 760446283Sdfr stacki--; 760546283Sdfr break; 760646283Sdfr 760746283Sdfr case DW_OP_plus_uconst: 760846283Sdfr stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read); 760946283Sdfr i += bytes_read; 761046283Sdfr break; 761146283Sdfr 761246283Sdfr case DW_OP_minus: 761398944Sobrien stack[stacki - 1] -= stack[stacki]; 761446283Sdfr stacki--; 761546283Sdfr break; 761646283Sdfr 761798944Sobrien case DW_OP_deref: 761898944Sobrien /* If we're not the last op, then we definitely can't encode 7619130803Smarcel this using GDB's address_class enum. This is valid for partial 7620130803Smarcel global symbols, although the variable's address will be bogus 7621130803Smarcel in the psymtab. */ 762298944Sobrien if (i < size) 7623130803Smarcel dwarf2_complex_location_expr_complaint (); 762498944Sobrien break; 762598944Sobrien 7626130803Smarcel case DW_OP_GNU_push_tls_address: 7627130803Smarcel /* The top of the stack has the offset from the beginning 7628130803Smarcel of the thread control block at which the variable is located. */ 7629130803Smarcel /* Nothing should follow this operator, so the top of stack would 7630130803Smarcel be returned. */ 7631130803Smarcel /* This is valid for partial global symbols, but the variable's 7632130803Smarcel address will be bogus in the psymtab. */ 7633130803Smarcel if (i < size) 7634130803Smarcel dwarf2_complex_location_expr_complaint (); 7635130803Smarcel break; 7636130803Smarcel 763746283Sdfr default: 7638130803Smarcel complaint (&symfile_complaints, "unsupported stack op: '%s'", 7639130803Smarcel dwarf_stack_op_name (op)); 764046283Sdfr return (stack[stacki]); 764146283Sdfr } 764246283Sdfr } 764346283Sdfr return (stack[stacki]); 764446283Sdfr} 764546283Sdfr 764646283Sdfr/* memory allocation interface */ 764746283Sdfr 764846283Sdfrstatic void 7649130803Smarceldwarf2_free_tmp_obstack (void *ignore) 765046283Sdfr{ 765146283Sdfr obstack_free (&dwarf2_tmp_obstack, NULL); 765246283Sdfr} 765346283Sdfr 765446283Sdfrstatic struct dwarf_block * 765598944Sobriendwarf_alloc_block (void) 765646283Sdfr{ 765746283Sdfr struct dwarf_block *blk; 765846283Sdfr 765946283Sdfr blk = (struct dwarf_block *) 766046283Sdfr obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct dwarf_block)); 766146283Sdfr return (blk); 766246283Sdfr} 766346283Sdfr 766446283Sdfrstatic struct abbrev_info * 766598944Sobriendwarf_alloc_abbrev (void) 766646283Sdfr{ 766746283Sdfr struct abbrev_info *abbrev; 766846283Sdfr 766946283Sdfr abbrev = (struct abbrev_info *) xmalloc (sizeof (struct abbrev_info)); 767046283Sdfr memset (abbrev, 0, sizeof (struct abbrev_info)); 767146283Sdfr return (abbrev); 767246283Sdfr} 767346283Sdfr 767446283Sdfrstatic struct die_info * 767598944Sobriendwarf_alloc_die (void) 767646283Sdfr{ 767746283Sdfr struct die_info *die; 767846283Sdfr 767946283Sdfr die = (struct die_info *) xmalloc (sizeof (struct die_info)); 768046283Sdfr memset (die, 0, sizeof (struct die_info)); 768146283Sdfr return (die); 768246283Sdfr} 7683130803Smarcel 7684130803Smarcel 7685130803Smarcel/* Macro support. */ 7686130803Smarcel 7687130803Smarcel 7688130803Smarcel/* Return the full name of file number I in *LH's file name table. 7689130803Smarcel Use COMP_DIR as the name of the current directory of the 7690130803Smarcel compilation. The result is allocated using xmalloc; the caller is 7691130803Smarcel responsible for freeing it. */ 7692130803Smarcelstatic char * 7693130803Smarcelfile_full_name (int file, struct line_header *lh, const char *comp_dir) 7694130803Smarcel{ 7695130803Smarcel struct file_entry *fe = &lh->file_names[file - 1]; 7696130803Smarcel 7697130803Smarcel if (IS_ABSOLUTE_PATH (fe->name)) 7698130803Smarcel return xstrdup (fe->name); 7699130803Smarcel else 7700130803Smarcel { 7701130803Smarcel const char *dir; 7702130803Smarcel int dir_len; 7703130803Smarcel char *full_name; 7704130803Smarcel 7705130803Smarcel if (fe->dir_index) 7706130803Smarcel dir = lh->include_dirs[fe->dir_index - 1]; 7707130803Smarcel else 7708130803Smarcel dir = comp_dir; 7709130803Smarcel 7710130803Smarcel if (dir) 7711130803Smarcel { 7712130803Smarcel dir_len = strlen (dir); 7713130803Smarcel full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); 7714130803Smarcel strcpy (full_name, dir); 7715130803Smarcel full_name[dir_len] = '/'; 7716130803Smarcel strcpy (full_name + dir_len + 1, fe->name); 7717130803Smarcel return full_name; 7718130803Smarcel } 7719130803Smarcel else 7720130803Smarcel return xstrdup (fe->name); 7721130803Smarcel } 7722130803Smarcel} 7723130803Smarcel 7724130803Smarcel 7725130803Smarcelstatic struct macro_source_file * 7726130803Smarcelmacro_start_file (int file, int line, 7727130803Smarcel struct macro_source_file *current_file, 7728130803Smarcel const char *comp_dir, 7729130803Smarcel struct line_header *lh, struct objfile *objfile) 7730130803Smarcel{ 7731130803Smarcel /* The full name of this source file. */ 7732130803Smarcel char *full_name = file_full_name (file, lh, comp_dir); 7733130803Smarcel 7734130803Smarcel /* We don't create a macro table for this compilation unit 7735130803Smarcel at all until we actually get a filename. */ 7736130803Smarcel if (! pending_macros) 7737130803Smarcel pending_macros = new_macro_table (&objfile->objfile_obstack, 7738130803Smarcel objfile->macro_cache); 7739130803Smarcel 7740130803Smarcel if (! current_file) 7741130803Smarcel /* If we have no current file, then this must be the start_file 7742130803Smarcel directive for the compilation unit's main source file. */ 7743130803Smarcel current_file = macro_set_main (pending_macros, full_name); 7744130803Smarcel else 7745130803Smarcel current_file = macro_include (current_file, line, full_name); 7746130803Smarcel 7747130803Smarcel xfree (full_name); 7748130803Smarcel 7749130803Smarcel return current_file; 7750130803Smarcel} 7751130803Smarcel 7752130803Smarcel 7753130803Smarcel/* Copy the LEN characters at BUF to a xmalloc'ed block of memory, 7754130803Smarcel followed by a null byte. */ 7755130803Smarcelstatic char * 7756130803Smarcelcopy_string (const char *buf, int len) 7757130803Smarcel{ 7758130803Smarcel char *s = xmalloc (len + 1); 7759130803Smarcel memcpy (s, buf, len); 7760130803Smarcel s[len] = '\0'; 7761130803Smarcel 7762130803Smarcel return s; 7763130803Smarcel} 7764130803Smarcel 7765130803Smarcel 7766130803Smarcelstatic const char * 7767130803Smarcelconsume_improper_spaces (const char *p, const char *body) 7768130803Smarcel{ 7769130803Smarcel if (*p == ' ') 7770130803Smarcel { 7771130803Smarcel complaint (&symfile_complaints, 7772130803Smarcel "macro definition contains spaces in formal argument list:\n`%s'", 7773130803Smarcel body); 7774130803Smarcel 7775130803Smarcel while (*p == ' ') 7776130803Smarcel p++; 7777130803Smarcel } 7778130803Smarcel 7779130803Smarcel return p; 7780130803Smarcel} 7781130803Smarcel 7782130803Smarcel 7783130803Smarcelstatic void 7784130803Smarcelparse_macro_definition (struct macro_source_file *file, int line, 7785130803Smarcel const char *body) 7786130803Smarcel{ 7787130803Smarcel const char *p; 7788130803Smarcel 7789130803Smarcel /* The body string takes one of two forms. For object-like macro 7790130803Smarcel definitions, it should be: 7791130803Smarcel 7792130803Smarcel <macro name> " " <definition> 7793130803Smarcel 7794130803Smarcel For function-like macro definitions, it should be: 7795130803Smarcel 7796130803Smarcel <macro name> "() " <definition> 7797130803Smarcel or 7798130803Smarcel <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> 7799130803Smarcel 7800130803Smarcel Spaces may appear only where explicitly indicated, and in the 7801130803Smarcel <definition>. 7802130803Smarcel 7803130803Smarcel The Dwarf 2 spec says that an object-like macro's name is always 7804130803Smarcel followed by a space, but versions of GCC around March 2002 omit 7805130803Smarcel the space when the macro's definition is the empty string. 7806130803Smarcel 7807130803Smarcel The Dwarf 2 spec says that there should be no spaces between the 7808130803Smarcel formal arguments in a function-like macro's formal argument list, 7809130803Smarcel but versions of GCC around March 2002 include spaces after the 7810130803Smarcel commas. */ 7811130803Smarcel 7812130803Smarcel 7813130803Smarcel /* Find the extent of the macro name. The macro name is terminated 7814130803Smarcel by either a space or null character (for an object-like macro) or 7815130803Smarcel an opening paren (for a function-like macro). */ 7816130803Smarcel for (p = body; *p; p++) 7817130803Smarcel if (*p == ' ' || *p == '(') 7818130803Smarcel break; 7819130803Smarcel 7820130803Smarcel if (*p == ' ' || *p == '\0') 7821130803Smarcel { 7822130803Smarcel /* It's an object-like macro. */ 7823130803Smarcel int name_len = p - body; 7824130803Smarcel char *name = copy_string (body, name_len); 7825130803Smarcel const char *replacement; 7826130803Smarcel 7827130803Smarcel if (*p == ' ') 7828130803Smarcel replacement = body + name_len + 1; 7829130803Smarcel else 7830130803Smarcel { 7831130803Smarcel dwarf2_macro_malformed_definition_complaint (body); 7832130803Smarcel replacement = body + name_len; 7833130803Smarcel } 7834130803Smarcel 7835130803Smarcel macro_define_object (file, line, name, replacement); 7836130803Smarcel 7837130803Smarcel xfree (name); 7838130803Smarcel } 7839130803Smarcel else if (*p == '(') 7840130803Smarcel { 7841130803Smarcel /* It's a function-like macro. */ 7842130803Smarcel char *name = copy_string (body, p - body); 7843130803Smarcel int argc = 0; 7844130803Smarcel int argv_size = 1; 7845130803Smarcel char **argv = xmalloc (argv_size * sizeof (*argv)); 7846130803Smarcel 7847130803Smarcel p++; 7848130803Smarcel 7849130803Smarcel p = consume_improper_spaces (p, body); 7850130803Smarcel 7851130803Smarcel /* Parse the formal argument list. */ 7852130803Smarcel while (*p && *p != ')') 7853130803Smarcel { 7854130803Smarcel /* Find the extent of the current argument name. */ 7855130803Smarcel const char *arg_start = p; 7856130803Smarcel 7857130803Smarcel while (*p && *p != ',' && *p != ')' && *p != ' ') 7858130803Smarcel p++; 7859130803Smarcel 7860130803Smarcel if (! *p || p == arg_start) 7861130803Smarcel dwarf2_macro_malformed_definition_complaint (body); 7862130803Smarcel else 7863130803Smarcel { 7864130803Smarcel /* Make sure argv has room for the new argument. */ 7865130803Smarcel if (argc >= argv_size) 7866130803Smarcel { 7867130803Smarcel argv_size *= 2; 7868130803Smarcel argv = xrealloc (argv, argv_size * sizeof (*argv)); 7869130803Smarcel } 7870130803Smarcel 7871130803Smarcel argv[argc++] = copy_string (arg_start, p - arg_start); 7872130803Smarcel } 7873130803Smarcel 7874130803Smarcel p = consume_improper_spaces (p, body); 7875130803Smarcel 7876130803Smarcel /* Consume the comma, if present. */ 7877130803Smarcel if (*p == ',') 7878130803Smarcel { 7879130803Smarcel p++; 7880130803Smarcel 7881130803Smarcel p = consume_improper_spaces (p, body); 7882130803Smarcel } 7883130803Smarcel } 7884130803Smarcel 7885130803Smarcel if (*p == ')') 7886130803Smarcel { 7887130803Smarcel p++; 7888130803Smarcel 7889130803Smarcel if (*p == ' ') 7890130803Smarcel /* Perfectly formed definition, no complaints. */ 7891130803Smarcel macro_define_function (file, line, name, 7892130803Smarcel argc, (const char **) argv, 7893130803Smarcel p + 1); 7894130803Smarcel else if (*p == '\0') 7895130803Smarcel { 7896130803Smarcel /* Complain, but do define it. */ 7897130803Smarcel dwarf2_macro_malformed_definition_complaint (body); 7898130803Smarcel macro_define_function (file, line, name, 7899130803Smarcel argc, (const char **) argv, 7900130803Smarcel p); 7901130803Smarcel } 7902130803Smarcel else 7903130803Smarcel /* Just complain. */ 7904130803Smarcel dwarf2_macro_malformed_definition_complaint (body); 7905130803Smarcel } 7906130803Smarcel else 7907130803Smarcel /* Just complain. */ 7908130803Smarcel dwarf2_macro_malformed_definition_complaint (body); 7909130803Smarcel 7910130803Smarcel xfree (name); 7911130803Smarcel { 7912130803Smarcel int i; 7913130803Smarcel 7914130803Smarcel for (i = 0; i < argc; i++) 7915130803Smarcel xfree (argv[i]); 7916130803Smarcel } 7917130803Smarcel xfree (argv); 7918130803Smarcel } 7919130803Smarcel else 7920130803Smarcel dwarf2_macro_malformed_definition_complaint (body); 7921130803Smarcel} 7922130803Smarcel 7923130803Smarcel 7924130803Smarcelstatic void 7925130803Smarceldwarf_decode_macros (struct line_header *lh, unsigned int offset, 7926130803Smarcel char *comp_dir, bfd *abfd, 7927130803Smarcel struct dwarf2_cu *cu) 7928130803Smarcel{ 7929130803Smarcel char *mac_ptr, *mac_end; 7930130803Smarcel struct macro_source_file *current_file = 0; 7931130803Smarcel 7932130803Smarcel if (dwarf_macinfo_buffer == NULL) 7933130803Smarcel { 7934130803Smarcel complaint (&symfile_complaints, "missing .debug_macinfo section"); 7935130803Smarcel return; 7936130803Smarcel } 7937130803Smarcel 7938130803Smarcel mac_ptr = dwarf_macinfo_buffer + offset; 7939130803Smarcel mac_end = dwarf_macinfo_buffer + dwarf_macinfo_size; 7940130803Smarcel 7941130803Smarcel for (;;) 7942130803Smarcel { 7943130803Smarcel enum dwarf_macinfo_record_type macinfo_type; 7944130803Smarcel 7945130803Smarcel /* Do we at least have room for a macinfo type byte? */ 7946130803Smarcel if (mac_ptr >= mac_end) 7947130803Smarcel { 7948130803Smarcel dwarf2_macros_too_long_complaint (); 7949130803Smarcel return; 7950130803Smarcel } 7951130803Smarcel 7952130803Smarcel macinfo_type = read_1_byte (abfd, mac_ptr); 7953130803Smarcel mac_ptr++; 7954130803Smarcel 7955130803Smarcel switch (macinfo_type) 7956130803Smarcel { 7957130803Smarcel /* A zero macinfo type indicates the end of the macro 7958130803Smarcel information. */ 7959130803Smarcel case 0: 7960130803Smarcel return; 7961130803Smarcel 7962130803Smarcel case DW_MACINFO_define: 7963130803Smarcel case DW_MACINFO_undef: 7964130803Smarcel { 7965130803Smarcel int bytes_read; 7966130803Smarcel int line; 7967130803Smarcel char *body; 7968130803Smarcel 7969130803Smarcel line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); 7970130803Smarcel mac_ptr += bytes_read; 7971130803Smarcel body = read_string (abfd, mac_ptr, &bytes_read); 7972130803Smarcel mac_ptr += bytes_read; 7973130803Smarcel 7974130803Smarcel if (! current_file) 7975130803Smarcel complaint (&symfile_complaints, 7976130803Smarcel "debug info gives macro %s outside of any file: %s", 7977130803Smarcel macinfo_type == 7978130803Smarcel DW_MACINFO_define ? "definition" : macinfo_type == 7979130803Smarcel DW_MACINFO_undef ? "undefinition" : 7980130803Smarcel "something-or-other", body); 7981130803Smarcel else 7982130803Smarcel { 7983130803Smarcel if (macinfo_type == DW_MACINFO_define) 7984130803Smarcel parse_macro_definition (current_file, line, body); 7985130803Smarcel else if (macinfo_type == DW_MACINFO_undef) 7986130803Smarcel macro_undef (current_file, line, body); 7987130803Smarcel } 7988130803Smarcel } 7989130803Smarcel break; 7990130803Smarcel 7991130803Smarcel case DW_MACINFO_start_file: 7992130803Smarcel { 7993130803Smarcel int bytes_read; 7994130803Smarcel int line, file; 7995130803Smarcel 7996130803Smarcel line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); 7997130803Smarcel mac_ptr += bytes_read; 7998130803Smarcel file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); 7999130803Smarcel mac_ptr += bytes_read; 8000130803Smarcel 8001130803Smarcel current_file = macro_start_file (file, line, 8002130803Smarcel current_file, comp_dir, 8003130803Smarcel lh, cu->objfile); 8004130803Smarcel } 8005130803Smarcel break; 8006130803Smarcel 8007130803Smarcel case DW_MACINFO_end_file: 8008130803Smarcel if (! current_file) 8009130803Smarcel complaint (&symfile_complaints, 8010130803Smarcel "macro debug info has an unmatched `close_file' directive"); 8011130803Smarcel else 8012130803Smarcel { 8013130803Smarcel current_file = current_file->included_by; 8014130803Smarcel if (! current_file) 8015130803Smarcel { 8016130803Smarcel enum dwarf_macinfo_record_type next_type; 8017130803Smarcel 8018130803Smarcel /* GCC circa March 2002 doesn't produce the zero 8019130803Smarcel type byte marking the end of the compilation 8020130803Smarcel unit. Complain if it's not there, but exit no 8021130803Smarcel matter what. */ 8022130803Smarcel 8023130803Smarcel /* Do we at least have room for a macinfo type byte? */ 8024130803Smarcel if (mac_ptr >= mac_end) 8025130803Smarcel { 8026130803Smarcel dwarf2_macros_too_long_complaint (); 8027130803Smarcel return; 8028130803Smarcel } 8029130803Smarcel 8030130803Smarcel /* We don't increment mac_ptr here, so this is just 8031130803Smarcel a look-ahead. */ 8032130803Smarcel next_type = read_1_byte (abfd, mac_ptr); 8033130803Smarcel if (next_type != 0) 8034130803Smarcel complaint (&symfile_complaints, 8035130803Smarcel "no terminating 0-type entry for macros in `.debug_macinfo' section"); 8036130803Smarcel 8037130803Smarcel return; 8038130803Smarcel } 8039130803Smarcel } 8040130803Smarcel break; 8041130803Smarcel 8042130803Smarcel case DW_MACINFO_vendor_ext: 8043130803Smarcel { 8044130803Smarcel int bytes_read; 8045130803Smarcel int constant; 8046130803Smarcel char *string; 8047130803Smarcel 8048130803Smarcel constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); 8049130803Smarcel mac_ptr += bytes_read; 8050130803Smarcel string = read_string (abfd, mac_ptr, &bytes_read); 8051130803Smarcel mac_ptr += bytes_read; 8052130803Smarcel 8053130803Smarcel /* We don't recognize any vendor extensions. */ 8054130803Smarcel } 8055130803Smarcel break; 8056130803Smarcel } 8057130803Smarcel } 8058130803Smarcel} 8059130803Smarcel 8060130803Smarcel/* Check if the attribute's form is a DW_FORM_block* 8061130803Smarcel if so return true else false. */ 8062130803Smarcelstatic int 8063130803Smarcelattr_form_is_block (struct attribute *attr) 8064130803Smarcel{ 8065130803Smarcel return (attr == NULL ? 0 : 8066130803Smarcel attr->form == DW_FORM_block1 8067130803Smarcel || attr->form == DW_FORM_block2 8068130803Smarcel || attr->form == DW_FORM_block4 8069130803Smarcel || attr->form == DW_FORM_block); 8070130803Smarcel} 8071130803Smarcel 8072130803Smarcelstatic void 8073130803Smarceldwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, 8074130803Smarcel struct dwarf2_cu *cu) 8075130803Smarcel{ 8076130803Smarcel if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) 8077130803Smarcel { 8078130803Smarcel struct dwarf2_loclist_baton *baton; 8079130803Smarcel 8080130803Smarcel baton = obstack_alloc (&cu->objfile->objfile_obstack, 8081130803Smarcel sizeof (struct dwarf2_loclist_baton)); 8082130803Smarcel baton->objfile = cu->objfile; 8083130803Smarcel 8084130803Smarcel /* We don't know how long the location list is, but make sure we 8085130803Smarcel don't run off the edge of the section. */ 8086130803Smarcel baton->size = dwarf_loc_size - DW_UNSND (attr); 8087130803Smarcel baton->data = dwarf_loc_buffer + DW_UNSND (attr); 8088130803Smarcel baton->base_address = cu->header.base_address; 8089130803Smarcel if (cu->header.base_known == 0) 8090130803Smarcel complaint (&symfile_complaints, 8091130803Smarcel "Location list used without specifying the CU base address."); 8092130803Smarcel 8093130803Smarcel SYMBOL_OPS (sym) = &dwarf2_loclist_funcs; 8094130803Smarcel SYMBOL_LOCATION_BATON (sym) = baton; 8095130803Smarcel } 8096130803Smarcel else 8097130803Smarcel { 8098130803Smarcel struct dwarf2_locexpr_baton *baton; 8099130803Smarcel 8100130803Smarcel baton = obstack_alloc (&cu->objfile->objfile_obstack, 8101130803Smarcel sizeof (struct dwarf2_locexpr_baton)); 8102130803Smarcel baton->objfile = cu->objfile; 8103130803Smarcel 8104130803Smarcel if (attr_form_is_block (attr)) 8105130803Smarcel { 8106130803Smarcel /* Note that we're just copying the block's data pointer 8107130803Smarcel here, not the actual data. We're still pointing into the 8108130803Smarcel dwarf_info_buffer for SYM's objfile; right now we never 8109130803Smarcel release that buffer, but when we do clean up properly 8110130803Smarcel this may need to change. */ 8111130803Smarcel baton->size = DW_BLOCK (attr)->size; 8112130803Smarcel baton->data = DW_BLOCK (attr)->data; 8113130803Smarcel } 8114130803Smarcel else 8115130803Smarcel { 8116130803Smarcel dwarf2_invalid_attrib_class_complaint ("location description", 8117130803Smarcel SYMBOL_NATURAL_NAME (sym)); 8118130803Smarcel baton->size = 0; 8119130803Smarcel baton->data = NULL; 8120130803Smarcel } 8121130803Smarcel 8122130803Smarcel SYMBOL_OPS (sym) = &dwarf2_locexpr_funcs; 8123130803Smarcel SYMBOL_LOCATION_BATON (sym) = baton; 8124130803Smarcel } 8125130803Smarcel} 8126