118334Speter/* DWARF 2 debugging format support for GDB. 2132718Skan Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 3169689Skan 2004 418334Speter Free Software Foundation, Inc. 590075Sobrien 618334Speter Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, 790075Sobrien Inc. with support from Florida State University (under contract 890075Sobrien with the Ada Joint Program Office), and Silicon Graphics, Inc. 990075Sobrien Initial contribution by Brent Benson, Harris Computer Systems, Inc., 1090075Sobrien based on Fred Fish's (Cygnus Support) implementation of DWARF 1 1118334Speter support in dwarfread.c 1290075Sobrien 1390075Sobrien This file is part of GDB. 1490075Sobrien 1590075Sobrien This program is free software; you can redistribute it and/or modify 1618334Speter it under the terms of the GNU General Public License as published by 1790075Sobrien the Free Software Foundation; either version 2 of the License, or (at 1890075Sobrien your option) any later version. 19169689Skan 20169689Skan This program is distributed in the hope that it will be useful, but 2118334Speter WITHOUT ANY WARRANTY; without even the implied warranty of 2218334Speter MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 2318334Speter General Public License for more details. 2418334Speter 2518334Speter You should have received a copy of the GNU General Public License 2618334Speter along with this program; if not, write to the Free Software 2718334Speter Foundation, Inc., 59 Temple Place - Suite 330, 2818334Speter Boston, MA 02111-1307, USA. */ 2918334Speter 3018334Speter#include "defs.h" 3118334Speter#include "bfd.h" 3218334Speter#include "symtab.h" 3318334Speter#include "gdbtypes.h" 3418334Speter#include "objfiles.h" 3518334Speter#include "elf/dwarf2.h" 3618334Speter#include "buildsym.h" 3718334Speter#include "demangle.h" 3818334Speter#include "expression.h" 3918334Speter#include "filenames.h" /* for DOSish file names */ 4018334Speter#include "macrotab.h" 4118334Speter#include "language.h" 4218334Speter#include "complaints.h" 4318334Speter#include "bcache.h" 4418334Speter#include "dwarf2expr.h" 4518334Speter#include "dwarf2loc.h" 4618334Speter#include "cp-support.h" 4718334Speter 4818334Speter#include <fcntl.h> 4918334Speter#include "gdb_string.h" 5018334Speter#include "gdb_assert.h" 5118334Speter#include <sys/types.h> 5218334Speter 5318334Speter#ifndef DWARF2_REG_TO_REGNUM 5418334Speter#define DWARF2_REG_TO_REGNUM(REG) (REG) 5518334Speter#endif 5618334Speter 5718334Speter#if 0 5818334Speter/* .debug_info header for a compilation unit 5918334Speter Because of alignment constraints, this structure has padding and cannot 6018334Speter be mapped directly onto the beginning of the .debug_info section. */ 6118334Spetertypedef struct comp_unit_header 6218334Speter { 6318334Speter unsigned int length; /* length of the .debug_info 6418334Speter contribution */ 6518334Speter unsigned short version; /* version number -- 2 for DWARF 6618334Speter version 2 */ 6718334Speter unsigned int abbrev_offset; /* offset into .debug_abbrev section */ 6818334Speter unsigned char addr_size; /* byte size of an address -- 4 */ 6918334Speter } 7018334Speter_COMP_UNIT_HEADER; 7118334Speter#define _ACTUAL_COMP_UNIT_HEADER_SIZE 11 7218334Speter#endif 7318334Speter 7418334Speter/* .debug_pubnames header 7518334Speter Because of alignment constraints, this structure has padding and cannot 7618334Speter be mapped directly onto the beginning of the .debug_info section. */ 7718334Spetertypedef struct pubnames_header 7818334Speter { 7918334Speter unsigned int length; /* length of the .debug_pubnames 8018334Speter contribution */ 8118334Speter unsigned char version; /* version number -- 2 for DWARF 8218334Speter version 2 */ 8318334Speter unsigned int info_offset; /* offset into .debug_info section */ 8418334Speter unsigned int info_size; /* byte size of .debug_info section 8518334Speter portion */ 8618334Speter } 8718334Speter_PUBNAMES_HEADER; 8818334Speter#define _ACTUAL_PUBNAMES_HEADER_SIZE 13 8918334Speter 9018334Speter/* .debug_pubnames header 9118334Speter Because of alignment constraints, this structure has padding and cannot 9218334Speter be mapped directly onto the beginning of the .debug_info section. */ 9318334Spetertypedef struct aranges_header 9418334Speter { 9518334Speter unsigned int length; /* byte len of the .debug_aranges 9618334Speter contribution */ 9718334Speter unsigned short version; /* version number -- 2 for DWARF 9818334Speter version 2 */ 9918334Speter unsigned int info_offset; /* offset into .debug_info section */ 10018334Speter unsigned char addr_size; /* byte size of an address */ 10118334Speter unsigned char seg_size; /* byte size of segment descriptor */ 10218334Speter } 10318334Speter_ARANGES_HEADER; 10418334Speter#define _ACTUAL_ARANGES_HEADER_SIZE 12 10518334Speter 10618334Speter/* .debug_line statement program prologue 10718334Speter Because of alignment constraints, this structure has padding and cannot 108169689Skan be mapped directly onto the beginning of the .debug_info section. */ 10918334Spetertypedef struct statement_prologue 11018334Speter { 11118334Speter unsigned int total_length; /* byte length of the statement 11218334Speter information */ 11318334Speter unsigned short version; /* version number -- 2 for DWARF 11418334Speter version 2 */ 11518334Speter unsigned int prologue_length; /* # bytes between prologue & 11618334Speter stmt program */ 11718334Speter unsigned char minimum_instruction_length; /* byte size of 11818334Speter smallest instr */ 11918334Speter unsigned char default_is_stmt; /* initial value of is_stmt 12018334Speter register */ 12118334Speter char line_base; 12218334Speter unsigned char line_range; 12318334Speter unsigned char opcode_base; /* number assigned to first special 12418334Speter opcode */ 12518334Speter unsigned char *standard_opcode_lengths; 12618334Speter } 12718334Speter_STATEMENT_PROLOGUE; 12818334Speter 12918334Speter/* offsets and sizes of debugging sections */ 13018334Speter 13118334Speterstatic unsigned int dwarf_info_size; 13218334Speterstatic unsigned int dwarf_abbrev_size; 13318334Speterstatic unsigned int dwarf_line_size; 13418334Speterstatic unsigned int dwarf_pubnames_size; 13518334Speterstatic unsigned int dwarf_aranges_size; 13618334Speterstatic unsigned int dwarf_loc_size; 13718334Speterstatic unsigned int dwarf_macinfo_size; 13818334Speterstatic unsigned int dwarf_str_size; 13918334Speterstatic unsigned int dwarf_ranges_size; 14018334Speterunsigned int dwarf_frame_size; 14118334Speterunsigned int dwarf_eh_frame_size; 14218334Speter 14318334Speterstatic asection *dwarf_info_section; 14418334Speterstatic asection *dwarf_abbrev_section; 14518334Speterstatic asection *dwarf_line_section; 14618334Speterstatic asection *dwarf_pubnames_section; 14718334Speterstatic asection *dwarf_aranges_section; 14818334Speterstatic asection *dwarf_loc_section; 14918334Speterstatic asection *dwarf_macinfo_section; 15018334Speterstatic asection *dwarf_str_section; 15118334Speterstatic asection *dwarf_ranges_section; 15290075Sobrienasection *dwarf_frame_section; 15318334Speterasection *dwarf_eh_frame_section; 15418334Speter 15550397Sobrien/* names of the debugging sections */ 156132718Skan 157132718Skan#define INFO_SECTION ".debug_info" 15818334Speter#define ABBREV_SECTION ".debug_abbrev" 15918334Speter#define LINE_SECTION ".debug_line" 16090075Sobrien#define PUBNAMES_SECTION ".debug_pubnames" 16190075Sobrien#define ARANGES_SECTION ".debug_aranges" 16218334Speter#define LOC_SECTION ".debug_loc" 16318334Speter#define MACINFO_SECTION ".debug_macinfo" 16418334Speter#define STR_SECTION ".debug_str" 16518334Speter#define RANGES_SECTION ".debug_ranges" 16690075Sobrien#define FRAME_SECTION ".debug_frame" 16752284Sobrien#define EH_FRAME_SECTION ".eh_frame" 16890075Sobrien 16990075Sobrien/* local data types */ 17052284Sobrien 17190075Sobrien/* We hold several abbreviation tables in memory at the same time. */ 172117395Skan#ifndef ABBREV_HASH_SIZE 173169689Skan#define ABBREV_HASH_SIZE 121 174169689Skan#endif 175169689Skan 176169689Skan/* The data in a compilation unit header, after target2host 17718334Speter translation, looks like this. */ 178169689Skanstruct comp_unit_head 179169689Skan { 180117395Skan unsigned long length; 181117395Skan short version; 182117395Skan unsigned int abbrev_offset; 183117395Skan unsigned char addr_size; 184117395Skan unsigned char signed_addr_p; 185117395Skan unsigned int offset_size; /* size of file offsets; either 4 or 8 */ 186169689Skan unsigned int initial_length_size; /* size of the length field; either 187117395Skan 4 or 12 */ 18818334Speter 18918334Speter /* Offset to the first byte of this compilation unit header in the 190169689Skan * .debug_info section, for resolving relative reference dies. */ 191169689Skan 19218334Speter unsigned int offset; 19318334Speter 19418334Speter /* Pointer to this compilation unit header in the .debug_info 19518334Speter * section */ 19618334Speter 19718334Speter char *cu_head_ptr; 19818334Speter 19918334Speter /* Pointer to the first die of this compilatio unit. This will 20018334Speter * be the first byte following the compilation unit header. */ 20118334Speter 20218334Speter char *first_die_ptr; 20318334Speter 20418334Speter /* Pointer to the next compilation unit header in the program. */ 20590075Sobrien 20618334Speter struct comp_unit_head *next; 20718334Speter 208117395Skan /* DWARF abbreviation table associated with this compilation unit */ 20990075Sobrien 21018334Speter struct abbrev_info *dwarf2_abbrevs[ABBREV_HASH_SIZE]; 21190075Sobrien 21290075Sobrien /* Base address of this compilation unit. */ 21390075Sobrien 21490075Sobrien CORE_ADDR base_address; 21590075Sobrien 21690075Sobrien /* Non-zero if base_address has been set. */ 217169689Skan 21890075Sobrien int base_known; 21990075Sobrien }; 22018334Speter 22190075Sobrien/* Internal state when decoding a particular compilation unit. */ 22218334Speterstruct dwarf2_cu 22390075Sobrien{ 22490075Sobrien /* The objfile containing this compilation unit. */ 22590075Sobrien struct objfile *objfile; 22690075Sobrien 22790075Sobrien /* The header of the compilation unit. 22890075Sobrien 22918334Speter FIXME drow/2003-11-10: Some of the things from the comp_unit_head 23090075Sobrien should be moved to the dwarf2_cu structure; for instance the abbrevs 23190075Sobrien hash table. */ 23290075Sobrien struct comp_unit_head header; 233169689Skan 234169689Skan struct function_range *first_fn, *last_fn, *cached_fn; 235169689Skan 236169689Skan /* The language we are debugging. */ 237169689Skan enum language language; 238117395Skan const struct language_defn *language_defn; 23918334Speter 24018334Speter /* The generic symbol table building routines have separate lists for 24118334Speter file scope symbols and all all other scopes (local scopes). So 24218334Speter we need to select the right one to pass to add_symbol_to_list(). 24390075Sobrien We do it by keeping a pointer to the correct list in list_in_scope. 24418334Speter 24590075Sobrien FIXME: The original dwarf code just treated the file scope as the 246169689Skan first local scope, and all other local scopes as nested local 24718334Speter scopes, and worked fine. Check to see if we really need to 24818334Speter distinguish these in buildsym.c. */ 24918334Speter struct pending **list_in_scope; 250132718Skan 251132718Skan /* Maintain an array of referenced fundamental types for the current 252132718Skan compilation unit being read. For DWARF version 1, we have to construct 25350397Sobrien the fundamental types on the fly, since no information about the 254132718Skan fundamental types is supplied. Each such fundamental type is created by 255132718Skan calling a language dependent routine to create the type, and then a 256132718Skan pointer to that type is then placed in the array at the index specified 257132718Skan by it's FT_<TYPENAME> value. The array has a fixed size set by the 258132718Skan FT_NUM_MEMBERS compile time constant, which is the number of predefined 259132718Skan fundamental types gdb knows how to construct. */ 260132718Skan struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */ 261169689Skan}; 262132718Skan 263169689Skan/* The line number information for a compilation unit (found in the 264132718Skan .debug_line section) begins with a "statement program header", 265132718Skan which contains the following information. */ 266132718Skanstruct line_header 267132718Skan{ 268132718Skan unsigned int total_length; 269132718Skan unsigned short version; 270132718Skan unsigned int header_length; 271132718Skan unsigned char minimum_instruction_length; 272132718Skan unsigned char default_is_stmt; 27318334Speter int line_base; 274117395Skan unsigned char line_range; 27552284Sobrien unsigned char opcode_base; 27652284Sobrien 277132718Skan /* standard_opcode_lengths[i] is the number of operands for the 27852284Sobrien standard opcode whose value is i. This means that 27990075Sobrien standard_opcode_lengths[0] is unused, and the last meaningful 28090075Sobrien element is standard_opcode_lengths[opcode_base - 1]. */ 28190075Sobrien unsigned char *standard_opcode_lengths; 28290075Sobrien 28390075Sobrien /* The include_directories table. NOTE! These strings are not 28490075Sobrien allocated with xmalloc; instead, they are pointers into 28590075Sobrien debug_line_buffer. If you try to free them, `free' will get 28690075Sobrien indigestion. */ 28752284Sobrien unsigned int num_include_dirs, include_dirs_size; 28890075Sobrien char **include_dirs; 28990075Sobrien 29090075Sobrien /* The file_names table. NOTE! These strings are not allocated 29190075Sobrien with xmalloc; instead, they are pointers into debug_line_buffer. 29290075Sobrien Don't try to free them directly. */ 29390075Sobrien unsigned int num_file_names, file_names_size; 29490075Sobrien struct file_entry 29590075Sobrien { 29690075Sobrien char *name; 29790075Sobrien unsigned int dir_index; 29852284Sobrien unsigned int mod_time; 29990075Sobrien unsigned int length; 30052284Sobrien } *file_names; 30152284Sobrien 30252284Sobrien /* The start and end of the statement program following this 30390075Sobrien header. These point into dwarf_line_buffer. */ 30452284Sobrien char *statement_program_start, *statement_program_end; 30552284Sobrien}; 306132718Skan 30752284Sobrien/* When we construct a partial symbol table entry we only 30890075Sobrien need this much information. */ 30990075Sobrienstruct partial_die_info 31090075Sobrien { 31190075Sobrien enum dwarf_tag tag; 31252284Sobrien unsigned char has_children; 31390075Sobrien unsigned char is_external; 31452284Sobrien unsigned char is_declaration; 315169689Skan unsigned char has_type; 31690075Sobrien unsigned int offset; 31790075Sobrien unsigned int abbrev; 318169689Skan char *name; 319169689Skan int has_pc_info; 320169689Skan CORE_ADDR lowpc; 32190075Sobrien CORE_ADDR highpc; 32290075Sobrien struct dwarf_block *locdesc; 323169689Skan unsigned int language; 324169689Skan char *sibling; 325169689Skan }; 326169689Skan 327169689Skan/* This data structure holds the information of an abbrev. */ 32890075Sobrienstruct abbrev_info 32990075Sobrien { 330169689Skan unsigned int number; /* number identifying abbrev */ 33190075Sobrien enum dwarf_tag tag; /* dwarf tag */ 33290075Sobrien int has_children; /* boolean */ 33390075Sobrien unsigned int num_attrs; /* number of attributes */ 33490075Sobrien struct attr_abbrev *attrs; /* an array of attribute descriptions */ 335169689Skan struct abbrev_info *next; /* next in chain */ 33690075Sobrien }; 33790075Sobrien 33890075Sobrienstruct attr_abbrev 33952284Sobrien { 34052284Sobrien enum dwarf_attribute name; 34190075Sobrien enum dwarf_form form; 34218334Speter }; 34390075Sobrien 344132718Skan/* This data structure holds a complete die structure. */ 34518334Speterstruct die_info 346117395Skan { 34790075Sobrien enum dwarf_tag tag; /* Tag indicating type of die */ 34818334Speter unsigned int abbrev; /* Abbrev number */ 349132718Skan unsigned int offset; /* Offset in .debug_info section */ 35090075Sobrien unsigned int num_attrs; /* Number of attributes */ 35190075Sobrien struct attribute *attrs; /* An array of attributes */ 35218334Speter struct die_info *next_ref; /* Next die in ref hash table */ 35390075Sobrien 354117395Skan /* The dies in a compilation unit form an n-ary tree. PARENT 35590075Sobrien points to this die's parent; CHILD points to the first child of 356169689Skan this node; and all the children of a given node are chained 35790075Sobrien together via their SIBLING fields, terminated by a die whose 35890075Sobrien tag is zero. */ 35990075Sobrien struct die_info *child; /* Its first child, if any. */ 36018334Speter struct die_info *sibling; /* Its next sibling, if any. */ 36118334Speter struct die_info *parent; /* Its parent, if any. */ 362169689Skan 36318334Speter struct type *type; /* Cached type information */ 36418334Speter }; 365132718Skan 36618334Speter/* Attributes have a name and a value */ 36718334Speterstruct attribute 36818334Speter { 36918334Speter enum dwarf_attribute name; 37050397Sobrien enum dwarf_form form; 37150397Sobrien union 37250397Sobrien { 37350397Sobrien char *str; 37450397Sobrien struct dwarf_block *blk; 37550397Sobrien unsigned long unsnd; 37650397Sobrien long int snd; 37790075Sobrien CORE_ADDR addr; 37818334Speter } 37918334Speter u; 38090075Sobrien }; 381117395Skan 382169689Skanstruct function_range 38318334Speter{ 38450397Sobrien const char *name; 385117395Skan CORE_ADDR lowpc, highpc; 38650397Sobrien int seen_line; 38750397Sobrien struct function_range *next; 388132718Skan}; 38950397Sobrien 39050397Sobrien/* Get at parts of an attribute structure */ 39150397Sobrien 39250397Sobrien#define DW_STRING(attr) ((attr)->u.str) 39350397Sobrien#define DW_UNSND(attr) ((attr)->u.unsnd) 394117395Skan#define DW_BLOCK(attr) ((attr)->u.blk) 39550397Sobrien#define DW_SND(attr) ((attr)->u.snd) 39650397Sobrien#define DW_ADDR(attr) ((attr)->u.addr) 39750397Sobrien 39850397Sobrien/* Blocks are a bunch of untyped bytes. */ 39950397Sobrienstruct dwarf_block 40050397Sobrien { 40150397Sobrien unsigned int size; 40250397Sobrien char *data; 40350397Sobrien }; 40450397Sobrien 40550397Sobrien#ifndef ATTR_ALLOC_CHUNK 40650397Sobrien#define ATTR_ALLOC_CHUNK 4 40750397Sobrien#endif 40818334Speter 40918334Speter/* A hash table of die offsets for following references. */ 41018334Speter#ifndef REF_HASH_SIZE 41150397Sobrien#define REF_HASH_SIZE 1021 41218334Speter#endif 41318334Speter 414132718Skanstatic struct die_info *die_ref_table[REF_HASH_SIZE]; 41518334Speter 41618334Speter/* Obstack for allocating temporary storage used during symbol reading. */ 41790075Sobrienstatic struct obstack dwarf2_tmp_obstack; 41818334Speter 41990075Sobrien/* Allocate fields for structs, unions and enums in this size. */ 420117395Skan#ifndef DW_FIELD_ALLOC_CHUNK 42190075Sobrien#define DW_FIELD_ALLOC_CHUNK 4 42290075Sobrien#endif 42390075Sobrien 42490075Sobrien/* Actually data from the sections. */ 42518334Speterstatic char *dwarf_info_buffer; 42690075Sobrienstatic char *dwarf_abbrev_buffer; 42790075Sobrienstatic char *dwarf_line_buffer; 42890075Sobrienstatic char *dwarf_str_buffer; 42990075Sobrienstatic char *dwarf_macinfo_buffer; 43090075Sobrienstatic char *dwarf_ranges_buffer; 43118334Speterstatic char *dwarf_loc_buffer; 43290075Sobrien 43318334Speter/* A zeroed version of a partial die for initialization purposes. */ 43418334Speterstatic struct partial_die_info zeroed_partial_die; 43590075Sobrien 43690075Sobrien/* FIXME: decode_locdesc sets these variables to describe the location 43790075Sobrien to the caller. These ought to be a structure or something. If 43890075Sobrien none of the flags are set, the object lives at the address returned 43990075Sobrien by decode_locdesc. */ 440169689Skan 441169689Skanstatic int isreg; /* Object lives in register. 442169689Skan decode_locdesc's return value is 443169689Skan the register number. */ 444169689Skan 445169689Skan/* We put a pointer to this structure in the read_symtab_private field 446169689Skan of the psymtab. 44718334Speter The complete dwarf information for an objfile is kept in the 44818334Speter objfile_obstack, so that absolute die references can be handled. 44918334Speter Most of the information in this structure is related to an entire 450117395Skan object file and could be passed via the sym_private field of the objfile. 451117395Skan It is however conceivable that dwarf2 might not be the only type 452117395Skan of symbols read from an object file. */ 45390075Sobrien 45418334Speterstruct dwarf2_pinfo 45550397Sobrien { 45618334Speter /* Pointer to start of dwarf info buffer for the objfile. */ 45790075Sobrien 458132718Skan char *dwarf_info_buffer; 45918334Speter 46018334Speter /* Offset in dwarf_info_buffer for this compilation unit. */ 46118334Speter 46218334Speter unsigned long dwarf_info_offset; 46318334Speter 46418334Speter /* Pointer to start of dwarf abbreviation buffer for the objfile. */ 46590075Sobrien 46690075Sobrien char *dwarf_abbrev_buffer; 46752284Sobrien 46818334Speter /* Size of dwarf abbreviation section for the objfile. */ 46990075Sobrien 47052284Sobrien unsigned int dwarf_abbrev_size; 47118334Speter 47218334Speter /* Pointer to start of dwarf line buffer for the objfile. */ 47318334Speter 47452284Sobrien char *dwarf_line_buffer; 47552284Sobrien 47652284Sobrien /* Size of dwarf_line_buffer, in bytes. */ 47718334Speter 47852284Sobrien unsigned int dwarf_line_size; 47952284Sobrien 48052284Sobrien /* Pointer to start of dwarf string buffer for the objfile. */ 48190075Sobrien 48252284Sobrien char *dwarf_str_buffer; 48352284Sobrien 48452284Sobrien /* Size of dwarf string section for the objfile. */ 48552284Sobrien 48652284Sobrien unsigned int dwarf_str_size; 48752284Sobrien 48890075Sobrien /* Pointer to start of dwarf macro buffer for the objfile. */ 48952284Sobrien 49052284Sobrien char *dwarf_macinfo_buffer; 49150397Sobrien 49290075Sobrien /* Size of dwarf macinfo section for the objfile. */ 49390075Sobrien 494169689Skan unsigned int dwarf_macinfo_size; 49590075Sobrien 49618334Speter /* Pointer to start of dwarf ranges buffer for the objfile. */ 49718334Speter 49818334Speter char *dwarf_ranges_buffer; 49918334Speter 50018334Speter /* Size of dwarf ranges buffer for the objfile. */ 50118334Speter 50218334Speter unsigned int dwarf_ranges_size; 503132718Skan 50418334Speter /* Pointer to start of dwarf locations buffer for the objfile. */ 50518334Speter 50618334Speter char *dwarf_loc_buffer; 50718334Speter 50818334Speter /* Size of dwarf locations buffer for the objfile. */ 50918334Speter 51018334Speter unsigned int dwarf_loc_size; 511169689Skan }; 51218334Speter 51318334Speter#define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private) 51418334Speter#define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer) 51518334Speter#define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset) 51618334Speter#define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer) 51718334Speter#define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size) 51818334Speter#define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer) 51918334Speter#define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size) 52018334Speter#define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer) 52118334Speter#define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size) 52218334Speter#define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer) 52318334Speter#define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size) 52418334Speter#define DWARF_RANGES_BUFFER(p) (PST_PRIVATE(p)->dwarf_ranges_buffer) 52518334Speter#define DWARF_RANGES_SIZE(p) (PST_PRIVATE(p)->dwarf_ranges_size) 52618334Speter#define DWARF_LOC_BUFFER(p) (PST_PRIVATE(p)->dwarf_loc_buffer) 52750397Sobrien#define DWARF_LOC_SIZE(p) (PST_PRIVATE(p)->dwarf_loc_size) 52818334Speter 52990075Sobrien/* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, 53018334Speter but this would require a corresponding change in unpack_field_as_long 53190075Sobrien and friends. */ 53250397Sobrienstatic int bits_per_byte = 8; 533169689Skan 53450397Sobrien/* The routines that read and process dies for a C struct or C++ class 53590075Sobrien pass lists of data member fields and lists of member function fields 53650397Sobrien in an instance of a field_info structure, as defined below. */ 53750397Sobrienstruct field_info 538117395Skan { 53990075Sobrien /* List of data member and baseclasses fields. */ 54090075Sobrien struct nextfield 54190075Sobrien { 54290075Sobrien struct nextfield *next; 54390075Sobrien int accessibility; 54490075Sobrien int virtuality; 54590075Sobrien struct field field; 54690075Sobrien } 54790075Sobrien *fields; 54890075Sobrien 54990075Sobrien /* Number of fields. */ 55090075Sobrien int nfields; 55190075Sobrien 55290075Sobrien /* Number of baseclasses. */ 55350397Sobrien int nbaseclasses; 55418334Speter 55518334Speter /* Set if the accesibility of one of the fields is not public. */ 55618334Speter int non_public_fields; 55718334Speter 55818334Speter /* Member function fields array, entries are allocated in the order they 55918334Speter are encountered in the object file. */ 56018334Speter struct nextfnfield 56118334Speter { 56218334Speter struct nextfnfield *next; 56318334Speter struct fn_field fnfield; 56418334Speter } 56518334Speter *fnfields; 56618334Speter 56718334Speter /* Member function fieldlist array, contains name of possibly overloaded 56890075Sobrien member function, number of overloaded member functions and a pointer 56918334Speter to the head of the member function field chain. */ 57018334Speter struct fnfieldlist 57118334Speter { 57218334Speter char *name; 57318334Speter int length; 57450397Sobrien struct nextfnfield *head; 57518334Speter } 57690075Sobrien *fnfieldlists; 57752284Sobrien 57890075Sobrien /* Number of entries in the fnfieldlists array. */ 57918334Speter int nfnfields; 58018334Speter }; 58150397Sobrien 58218334Speter/* Various complaints about symbol reading that don't abort the process */ 58318334Speter 58418334Speterstatic void 58590075Sobriendwarf2_statement_list_fits_in_line_number_section_complaint (void) 58618334Speter{ 58718334Speter complaint (&symfile_complaints, 58852284Sobrien "statement list doesn't fit in .debug_line section"); 58990075Sobrien} 59018334Speter 59118334Speterstatic void 59218334Speterdwarf2_complex_location_expr_complaint (void) 59318334Speter{ 59418334Speter complaint (&symfile_complaints, "location expression too complex"); 59518334Speter} 59618334Speter 59718334Speterstatic void 59818334Speterdwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, 59918334Speter int arg3) 60018334Speter{ 60118334Speter complaint (&symfile_complaints, 60218334Speter "const value length mismatch for '%s', got %d, expected %d", arg1, 60318334Speter arg2, arg3); 60418334Speter} 60590075Sobrien 60618334Speterstatic void 60718334Speterdwarf2_macros_too_long_complaint (void) 60818334Speter{ 609132718Skan complaint (&symfile_complaints, 61018334Speter "macro info runs off end of `.debug_macinfo' section"); 61118334Speter} 61290075Sobrien 61350397Sobrienstatic void 61418334Speterdwarf2_macro_malformed_definition_complaint (const char *arg1) 61552284Sobrien{ 61652284Sobrien complaint (&symfile_complaints, 61718334Speter "macro debug info contains a malformed macro definition:\n`%s'", 61818334Speter arg1); 61918334Speter} 62018334Speter 62190075Sobrienstatic void 62218334Speterdwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) 62318334Speter{ 624169689Skan complaint (&symfile_complaints, 62518334Speter "invalid attribute class or form for '%s' in '%s'", arg1, arg2); 62618334Speter} 62718334Speter 62818334Speter/* local function prototypes */ 62918334Speter 63018334Speterstatic void dwarf2_locate_sections (bfd *, asection *, void *); 63118334Speter 63250397Sobrien#if 0 633117395Skanstatic void dwarf2_build_psymtabs_easy (struct objfile *, int); 63490075Sobrien#endif 63518334Speter 63618334Speterstatic void dwarf2_build_psymtabs_hard (struct objfile *, int); 63790075Sobrien 63818334Speterstatic char *scan_partial_symbols (char *, CORE_ADDR *, CORE_ADDR *, 63918334Speter struct dwarf2_cu *, 64018334Speter const char *namespace); 64118334Speter 64218334Speterstatic void add_partial_symbol (struct partial_die_info *, struct dwarf2_cu *, 64350397Sobrien const char *namespace); 64418334Speter 64552284Sobrienstatic int pdi_needs_namespace (enum dwarf_tag tag, const char *namespace); 646132718Skan 64718334Speterstatic char *add_partial_namespace (struct partial_die_info *pdi, 648169689Skan char *info_ptr, 649169689Skan CORE_ADDR *lowpc, CORE_ADDR *highpc, 650169689Skan struct dwarf2_cu *cu, 651169689Skan const char *namespace); 652169689Skan 653169689Skanstatic char *add_partial_structure (struct partial_die_info *struct_pdi, 654169689Skan char *info_ptr, 655169689Skan struct dwarf2_cu *cu, 656169689Skan const char *namespace); 657169689Skan 658169689Skanstatic char *add_partial_enumeration (struct partial_die_info *enum_pdi, 659169689Skan char *info_ptr, 660169689Skan struct dwarf2_cu *cu, 661169689Skan const char *namespace); 662169689Skan 66318334Speterstatic char *locate_pdi_sibling (struct partial_die_info *orig_pdi, 66418334Speter char *info_ptr, 66518334Speter bfd *abfd, 66618334Speter struct dwarf2_cu *cu); 66718334Speter 66818334Speterstatic void dwarf2_psymtab_to_symtab (struct partial_symtab *); 669132718Skan 67018334Speterstatic void psymtab_to_symtab_1 (struct partial_symtab *); 67152750Sobrien 67218334Speterchar *dwarf2_read_section (struct objfile *, asection *); 67352750Sobrien 67452750Sobrienstatic void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu); 675132718Skan 67652750Sobrienstatic void dwarf2_empty_abbrev_table (void *); 67752750Sobrien 67890075Sobrienstatic struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, 67990075Sobrien struct dwarf2_cu *); 680169689Skan 681169689Skanstatic char *read_partial_die (struct partial_die_info *, 68218334Speter bfd *, char *, struct dwarf2_cu *); 68318334Speter 68418334Speterstatic char *read_full_die (struct die_info **, bfd *, char *, 68518334Speter struct dwarf2_cu *, int *); 68618334Speter 68790075Sobrienstatic char *read_attribute (struct attribute *, struct attr_abbrev *, 68890075Sobrien bfd *, char *, struct dwarf2_cu *); 68990075Sobrien 69090075Sobrienstatic char *read_attribute_value (struct attribute *, unsigned, 69118334Speter bfd *, char *, struct dwarf2_cu *); 69218334Speter 69350397Sobrienstatic unsigned int read_1_byte (bfd *, char *); 69418334Speter 69518334Speterstatic int read_1_signed_byte (bfd *, char *); 696132718Skan 69718334Speterstatic unsigned int read_2_bytes (bfd *, char *); 698169689Skan 699169689Skanstatic unsigned int read_4_bytes (bfd *, char *); 700169689Skan 70118334Speterstatic unsigned long read_8_bytes (bfd *, char *); 702169689Skan 703169689Skanstatic CORE_ADDR read_address (bfd *, char *ptr, struct dwarf2_cu *, 70418334Speter int *bytes_read); 70518334Speter 70618334Speterstatic LONGEST read_initial_length (bfd *, char *, 70718334Speter struct comp_unit_head *, int *bytes_read); 70818334Speter 70950397Sobrienstatic LONGEST read_offset (bfd *, char *, const struct comp_unit_head *, 71018334Speter int *bytes_read); 71118334Speter 712132718Skanstatic char *read_n_bytes (bfd *, char *, unsigned int); 71318334Speter 71490075Sobrienstatic char *read_string (bfd *, char *, unsigned int *); 71518334Speter 71690075Sobrienstatic char *read_indirect_string (bfd *, char *, const struct comp_unit_head *, 71718334Speter unsigned int *); 71818334Speter 71918334Speterstatic unsigned long read_unsigned_leb128 (bfd *, char *, unsigned int *); 72018334Speter 72118334Speterstatic long read_signed_leb128 (bfd *, char *, unsigned int *); 72218334Speter 72318334Speterstatic void set_cu_language (unsigned int, struct dwarf2_cu *); 72418334Speter 72518334Speterstatic struct attribute *dwarf2_attr (struct die_info *, unsigned int, 72618334Speter struct dwarf2_cu *); 727169689Skan 72818334Speterstatic int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); 72918334Speter 73018334Speterstatic struct die_info *die_specification (struct die_info *die, 73118334Speter struct dwarf2_cu *); 73250397Sobrien 73318334Speterstatic void free_line_header (struct line_header *lh); 73418334Speter 735132718Skanstatic struct line_header *(dwarf_decode_line_header 73618334Speter (unsigned int offset, 73718334Speter bfd *abfd, struct dwarf2_cu *cu)); 73818334Speter 739169689Skanstatic void dwarf_decode_lines (struct line_header *, char *, bfd *, 74018334Speter struct dwarf2_cu *); 74118334Speter 74218334Speterstatic void dwarf2_start_subfile (char *, char *); 74318334Speter 74418334Speterstatic struct symbol *new_symbol (struct die_info *, struct type *, 74518334Speter struct dwarf2_cu *); 74618334Speter 74718334Speterstatic void dwarf2_const_value (struct attribute *, struct symbol *, 74818334Speter struct dwarf2_cu *); 74918334Speter 75090075Sobrienstatic void dwarf2_const_value_data (struct attribute *attr, 75190075Sobrien struct symbol *sym, 75290075Sobrien int bits); 75350397Sobrien 75418334Speterstatic struct type *die_type (struct die_info *, struct dwarf2_cu *); 75518334Speter 756132718Skanstatic struct type *die_containing_type (struct die_info *, 75718334Speter struct dwarf2_cu *); 75818334Speter 75918334Speter#if 0 76018334Speterstatic struct type *type_at_offset (unsigned int, struct objfile *); 76190075Sobrien#endif 76290075Sobrien 76390075Sobrienstatic struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *); 76490075Sobrien 76590075Sobrienstatic void read_type_die (struct die_info *, struct dwarf2_cu *); 76690075Sobrien 76790075Sobrienstatic char *determine_prefix (struct die_info *die, struct dwarf2_cu *); 76890075Sobrien 76990075Sobrienstatic char *typename_concat (const char *prefix, const char *suffix); 770117395Skan 77190075Sobrienstatic void read_typedef (struct die_info *, struct dwarf2_cu *); 772117395Skan 773169689Skanstatic void read_base_type (struct die_info *, struct dwarf2_cu *); 77490075Sobrien 77590075Sobrienstatic void read_subrange_type (struct die_info *die, struct dwarf2_cu *cu); 77690075Sobrien 77718334Speterstatic void read_file_scope (struct die_info *, struct dwarf2_cu *); 77818334Speter 779169689Skanstatic void read_func_scope (struct die_info *, struct dwarf2_cu *); 78018334Speter 78190075Sobrienstatic void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); 78290075Sobrien 78318334Speterstatic int dwarf2_get_pc_bounds (struct die_info *, 78490075Sobrien CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *); 78590075Sobrien 78690075Sobrienstatic void get_scope_pc_bounds (struct die_info *, 78790075Sobrien CORE_ADDR *, CORE_ADDR *, 78818334Speter struct dwarf2_cu *); 78990075Sobrien 79090075Sobrienstatic void dwarf2_add_field (struct field_info *, struct die_info *, 79190075Sobrien struct dwarf2_cu *); 79218334Speter 79318334Speterstatic void dwarf2_attach_fields_to_type (struct field_info *, 79418334Speter struct type *, struct dwarf2_cu *); 79518334Speter 79618334Speterstatic void dwarf2_add_member_fn (struct field_info *, 79718334Speter struct die_info *, struct type *, 79818334Speter struct dwarf2_cu *); 79918334Speter 80018334Speterstatic void dwarf2_attach_fn_fields_to_type (struct field_info *, 80190075Sobrien struct type *, struct dwarf2_cu *); 80290075Sobrien 80390075Sobrienstatic void read_structure_type (struct die_info *, struct dwarf2_cu *); 80490075Sobrien 80518334Speterstatic void process_structure_scope (struct die_info *, struct dwarf2_cu *); 80650397Sobrien 80718334Speterstatic char *determine_class_name (struct die_info *die, struct dwarf2_cu *cu); 80818334Speter 809132718Skanstatic void read_common_block (struct die_info *, struct dwarf2_cu *); 81018334Speter 81118334Speterstatic void read_namespace (struct die_info *die, struct dwarf2_cu *); 81290075Sobrien 81318334Speterstatic const char *namespace_name (struct die_info *die, 81418334Speter int *is_anonymous, struct dwarf2_cu *); 81518334Speter 81618334Speterstatic void read_enumeration_type (struct die_info *, struct dwarf2_cu *); 81718334Speter 81818334Speterstatic void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); 81918334Speter 82018334Speterstatic struct type *dwarf_base_type (int, int, struct dwarf2_cu *); 821169689Skan 822169689Skanstatic CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); 823169689Skan 824169689Skanstatic void read_array_type (struct die_info *, struct dwarf2_cu *); 825169689Skan 826169689Skanstatic void read_tag_pointer_type (struct die_info *, struct dwarf2_cu *); 827169689Skan 828169689Skanstatic void read_tag_unspecified_type (struct die_info *, struct dwarf2_cu *); 829169689Skan 830169689Skanstatic void read_tag_ptr_to_member_type (struct die_info *, 831169689Skan struct dwarf2_cu *); 83218334Speter 83318334Speterstatic void read_tag_reference_type (struct die_info *, struct dwarf2_cu *); 83418334Speter 83518334Speterstatic void read_tag_const_type (struct die_info *, struct dwarf2_cu *); 83618334Speter 83718334Speterstatic void read_tag_volatile_type (struct die_info *, struct dwarf2_cu *); 83818334Speter 83990075Sobrienstatic void read_tag_restrict_type (struct die_info *, struct dwarf2_cu *); 84090075Sobrien 84190075Sobrienstatic void read_tag_string_type (struct die_info *, struct dwarf2_cu *); 842132718Skan 84390075Sobrienstatic void read_subroutine_type (struct die_info *, struct dwarf2_cu *); 84490075Sobrien 845132718Skanstatic struct die_info *read_comp_unit (char *, bfd *, struct dwarf2_cu *); 84690075Sobrien 84790075Sobrienstatic struct die_info *read_die_and_children (char *info_ptr, bfd *abfd, 848169689Skan struct dwarf2_cu *, 849169689Skan char **new_info_ptr, 85090075Sobrien struct die_info *parent); 851169689Skan 85290075Sobrienstatic struct die_info *read_die_and_siblings (char *info_ptr, bfd *abfd, 85390075Sobrien struct dwarf2_cu *, 85490075Sobrien char **new_info_ptr, 85590075Sobrien struct die_info *parent); 85690075Sobrien 85790075Sobrienstatic void free_die_list (struct die_info *); 85890075Sobrien 85990075Sobrienstatic struct cleanup *make_cleanup_free_die_list (struct die_info *); 86018334Speter 86190075Sobrienstatic void process_die (struct die_info *, struct dwarf2_cu *); 86290075Sobrien 86318334Speterstatic char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *); 86418334Speter 86518334Speterstatic char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); 86618334Speter 86718334Speterstatic struct die_info *dwarf2_extension (struct die_info *die, 86850397Sobrien struct dwarf2_cu *); 86918334Speter 870169689Skanstatic char *dwarf_tag_name (unsigned int); 871169689Skan 87290075Sobrienstatic char *dwarf_attr_name (unsigned int); 87318334Speter 87418334Speterstatic char *dwarf_form_name (unsigned int); 87518334Speter 87618334Speterstatic char *dwarf_stack_op_name (unsigned int); 87718334Speter 87818334Speterstatic char *dwarf_bool_name (unsigned int); 879169689Skan 880169689Skanstatic char *dwarf_type_encoding_name (unsigned int); 88118334Speter 88218334Speter#if 0 88318334Speterstatic char *dwarf_cfi_name (unsigned int); 88418334Speter 885169689Skanstruct die_info *copy_die (struct die_info *); 886169689Skan#endif 887169689Skan 888169689Skanstatic struct die_info *sibling_die (struct die_info *); 889169689Skan 890169689Skanstatic void dump_die (struct die_info *); 891169689Skan 892169689Skanstatic void dump_die_list (struct die_info *); 893169689Skan 894169689Skanstatic void store_in_ref_table (unsigned int, struct die_info *); 89590075Sobrien 89690075Sobrienstatic void dwarf2_empty_hash_tables (void); 89718334Speter 89890075Sobrienstatic unsigned int dwarf2_get_ref_die_offset (struct attribute *, 89990075Sobrien struct dwarf2_cu *); 90090075Sobrien 901132718Skanstatic int dwarf2_get_attr_constant_value (struct attribute *, int); 90290075Sobrien 90390075Sobrienstatic struct die_info *follow_die_ref (unsigned int); 90418334Speter 90518334Speterstatic struct type *dwarf2_fundamental_type (struct objfile *, int, 906169689Skan struct dwarf2_cu *); 907169689Skan 908169689Skan/* memory allocation interface */ 909169689Skan 910169689Skanstatic void dwarf2_free_tmp_obstack (void *); 911169689Skan 912169689Skanstatic struct dwarf_block *dwarf_alloc_block (void); 913169689Skan 914169689Skanstatic struct abbrev_info *dwarf_alloc_abbrev (void); 915169689Skan 916169689Skanstatic struct die_info *dwarf_alloc_die (void); 917169689Skan 918169689Skanstatic void initialize_cu_func_list (struct dwarf2_cu *); 919169689Skan 920169689Skanstatic void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR, 921169689Skan struct dwarf2_cu *); 922169689Skan 923169689Skanstatic void dwarf_decode_macros (struct line_header *, unsigned int, 924169689Skan char *, bfd *, struct dwarf2_cu *); 925169689Skan 926169689Skanstatic int attr_form_is_block (struct attribute *); 927169689Skan 928169689Skanstatic void 929169689Skandwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, 930169689Skan struct dwarf2_cu *cu); 931169689Skan 932169689Skan/* Try to locate the sections we need for DWARF 2 debugging 933169689Skan information and return true if we have enough to do something. */ 934169689Skan 935169689Skanint 936169689Skandwarf2_has_info (bfd *abfd) 937169689Skan{ 938169689Skan dwarf_info_section = 0; 939169689Skan dwarf_abbrev_section = 0; 940169689Skan dwarf_line_section = 0; 941169689Skan dwarf_str_section = 0; 942169689Skan dwarf_macinfo_section = 0; 943169689Skan dwarf_frame_section = 0; 944169689Skan dwarf_eh_frame_section = 0; 945169689Skan dwarf_ranges_section = 0; 946169689Skan dwarf_loc_section = 0; 947169689Skan 948169689Skan bfd_map_over_sections (abfd, dwarf2_locate_sections, NULL); 949169689Skan return (dwarf_info_section != NULL && dwarf_abbrev_section != NULL); 950169689Skan} 951169689Skan 95218334Speter/* This function is mapped across the sections and remembers the 953132718Skan offset and size of each of the debugging sections we are interested 954132718Skan in. */ 95518334Speter 956132718Skanstatic void 957132718Skandwarf2_locate_sections (bfd *ignore_abfd, asection *sectp, void *ignore_ptr) 95818334Speter{ 95918334Speter if (strcmp (sectp->name, INFO_SECTION) == 0) 96018334Speter { 96118334Speter dwarf_info_size = bfd_get_section_size (sectp); 96218334Speter dwarf_info_section = sectp; 963132718Skan } 96418334Speter else if (strcmp (sectp->name, ABBREV_SECTION) == 0) 96518334Speter { 96618334Speter dwarf_abbrev_size = bfd_get_section_size (sectp); 96718334Speter dwarf_abbrev_section = sectp; 96818334Speter } 96918334Speter else if (strcmp (sectp->name, LINE_SECTION) == 0) 97050397Sobrien { 97118334Speter dwarf_line_size = bfd_get_section_size (sectp); 97218334Speter dwarf_line_section = sectp; 97318334Speter } 97418334Speter else if (strcmp (sectp->name, PUBNAMES_SECTION) == 0) 97518334Speter { 97618334Speter dwarf_pubnames_size = bfd_get_section_size (sectp); 97750397Sobrien dwarf_pubnames_section = sectp; 978169689Skan } 97918334Speter else if (strcmp (sectp->name, ARANGES_SECTION) == 0) 98018334Speter { 98118334Speter dwarf_aranges_size = bfd_get_section_size (sectp); 98218334Speter dwarf_aranges_section = sectp; 98318334Speter } 984146895Skan else if (strcmp (sectp->name, LOC_SECTION) == 0) 985169689Skan { 98618334Speter dwarf_loc_size = bfd_get_section_size (sectp); 987146895Skan dwarf_loc_section = sectp; 988146895Skan } 989146895Skan else if (strcmp (sectp->name, MACINFO_SECTION) == 0) 990169689Skan { 991146895Skan dwarf_macinfo_size = bfd_get_section_size (sectp); 99218334Speter dwarf_macinfo_section = sectp; 99350397Sobrien } 99418334Speter else if (strcmp (sectp->name, STR_SECTION) == 0) 99518334Speter { 996132718Skan dwarf_str_size = bfd_get_section_size (sectp); 997132718Skan dwarf_str_section = sectp; 99818334Speter } 999132718Skan else if (strcmp (sectp->name, FRAME_SECTION) == 0) 1000132718Skan { 1001132718Skan dwarf_frame_size = bfd_get_section_size (sectp); 100218334Speter dwarf_frame_section = sectp; 100318334Speter } 1004132718Skan else if (strcmp (sectp->name, EH_FRAME_SECTION) == 0) 100590075Sobrien { 1006132718Skan flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); 100718334Speter if (aflag & SEC_HAS_CONTENTS) 100818334Speter { 100950397Sobrien dwarf_eh_frame_size = bfd_get_section_size (sectp); 101018334Speter dwarf_eh_frame_section = sectp; 101118334Speter } 101218334Speter } 101318334Speter else if (strcmp (sectp->name, RANGES_SECTION) == 0) 101450397Sobrien { 101518334Speter dwarf_ranges_size = bfd_get_section_size (sectp); 101618334Speter dwarf_ranges_section = sectp; 101718334Speter } 101818334Speter} 101990075Sobrien 102018334Speter/* Build a partial symbol table. */ 1021132718Skan 102290075Sobrienvoid 1023132718Skandwarf2_build_psymtabs (struct objfile *objfile, int mainline) 102418334Speter{ 102518334Speter 1026117395Skan /* We definitely need the .debug_info and .debug_abbrev sections */ 1027169689Skan 102818334Speter dwarf_info_buffer = dwarf2_read_section (objfile, dwarf_info_section); 102918334Speter dwarf_abbrev_buffer = dwarf2_read_section (objfile, dwarf_abbrev_section); 103018334Speter 103118334Speter if (dwarf_line_section) 103218334Speter dwarf_line_buffer = dwarf2_read_section (objfile, dwarf_line_section); 103318334Speter else 103418334Speter dwarf_line_buffer = NULL; 103518334Speter 103618334Speter if (dwarf_str_section) 103718334Speter dwarf_str_buffer = dwarf2_read_section (objfile, dwarf_str_section); 103818334Speter else 103950397Sobrien dwarf_str_buffer = NULL; 104018334Speter 104118334Speter if (dwarf_macinfo_section) 104218334Speter dwarf_macinfo_buffer = dwarf2_read_section (objfile, 104318334Speter dwarf_macinfo_section); 104418334Speter else 104518334Speter dwarf_macinfo_buffer = NULL; 104618334Speter 104718334Speter if (dwarf_ranges_section) 104818334Speter dwarf_ranges_buffer = dwarf2_read_section (objfile, dwarf_ranges_section); 104918334Speter else 1050132718Skan dwarf_ranges_buffer = NULL; 105190075Sobrien 105218334Speter if (dwarf_loc_section) 105318334Speter dwarf_loc_buffer = dwarf2_read_section (objfile, dwarf_loc_section); 105418334Speter else 105518334Speter dwarf_loc_buffer = NULL; 105618334Speter 105718334Speter if (mainline 105818334Speter || (objfile->global_psymbols.size == 0 105918334Speter && objfile->static_psymbols.size == 0)) 1060169689Skan { 106190075Sobrien init_psymbol_list (objfile, 1024); 106218334Speter } 1063132718Skan 1064169689Skan#if 0 106550397Sobrien if (dwarf_aranges_offset && dwarf_pubnames_offset) 106650397Sobrien { 106718334Speter /* Things are significantly easier if we have .debug_aranges and 106818334Speter .debug_pubnames sections */ 106918334Speter 107018334Speter dwarf2_build_psymtabs_easy (objfile, mainline); 1071169689Skan } 107218334Speter else 1073169689Skan#endif 1074169689Skan /* only test this case for now */ 107518334Speter { 107618334Speter /* In this case we have to work a bit harder */ 107718334Speter dwarf2_build_psymtabs_hard (objfile, mainline); 107818334Speter } 107918334Speter} 1080117395Skan 1081169689Skan#if 0 108218334Speter/* Build the partial symbol table from the information in the 1083169689Skan .debug_pubnames and .debug_aranges sections. */ 108418334Speter 108518334Speterstatic void 108618334Speterdwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline) 108718334Speter{ 108818334Speter bfd *abfd = objfile->obfd; 1089132718Skan char *aranges_buffer, *pubnames_buffer; 1090132718Skan char *aranges_ptr, *pubnames_ptr; 109118334Speter unsigned int entry_length, version, info_offset, info_size; 1092169689Skan 1093169689Skan pubnames_buffer = dwarf2_read_section (objfile, 1094169689Skan dwarf_pubnames_section); 1095169689Skan pubnames_ptr = pubnames_buffer; 1096169689Skan while ((pubnames_ptr - pubnames_buffer) < dwarf_pubnames_size) 1097169689Skan { 1098169689Skan struct comp_unit_head cu_header; 1099169689Skan int bytes_read; 1100169689Skan 1101169689Skan entry_length = read_initial_length (abfd, pubnames_ptr, &cu_header, 1102169689Skan &bytes_read); 1103169689Skan pubnames_ptr += bytes_read; 1104169689Skan version = read_1_byte (abfd, pubnames_ptr); 1105169689Skan pubnames_ptr += 1; 1106169689Skan info_offset = read_4_bytes (abfd, pubnames_ptr); 1107169689Skan pubnames_ptr += 4; 110818334Speter info_size = read_4_bytes (abfd, pubnames_ptr); 110990075Sobrien pubnames_ptr += 4; 111090075Sobrien } 111190075Sobrien 111290075Sobrien aranges_buffer = dwarf2_read_section (objfile, 111390075Sobrien dwarf_aranges_section); 1114132718Skan 111518334Speter} 111690075Sobrien#endif 111790075Sobrien 111818334Speter/* Read in the comp unit header information from the debug_info at 1119169689Skan info_ptr. */ 112018334Speter 112118334Speterstatic char * 112290075Sobrienread_comp_unit_head (struct comp_unit_head *cu_header, 112318334Speter char *info_ptr, bfd *abfd) 112490075Sobrien{ 112590075Sobrien int signed_addr; 112690075Sobrien int bytes_read; 112790075Sobrien cu_header->length = read_initial_length (abfd, info_ptr, cu_header, 112890075Sobrien &bytes_read); 112990075Sobrien info_ptr += bytes_read; 113090075Sobrien cu_header->version = read_2_bytes (abfd, info_ptr); 113190075Sobrien info_ptr += 2; 113218334Speter cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, 113390075Sobrien &bytes_read); 113490075Sobrien info_ptr += bytes_read; 113590075Sobrien cu_header->addr_size = read_1_byte (abfd, info_ptr); 113690075Sobrien info_ptr += 1; 113790075Sobrien signed_addr = bfd_get_sign_extend_vma (abfd); 113890075Sobrien if (signed_addr < 0) 113990075Sobrien internal_error (__FILE__, __LINE__, 114090075Sobrien "read_comp_unit_head: dwarf from non elf file"); 114190075Sobrien cu_header->signed_addr_p = signed_addr; 114290075Sobrien return info_ptr; 114390075Sobrien} 114490075Sobrien 1145132718Skan/* Build the partial symbol table by doing a quick pass through the 114690075Sobrien .debug_info and .debug_abbrev sections. */ 114790075Sobrien 114890075Sobrienstatic void 114990075Sobriendwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline) 115090075Sobrien{ 115190075Sobrien /* Instead of reading this into a big buffer, we should probably use 1152169689Skan mmap() on architectures that support it. (FIXME) */ 115390075Sobrien bfd *abfd = objfile->obfd; 115418334Speter char *info_ptr, *abbrev_ptr; 115590075Sobrien char *beg_of_comp_unit; 115690075Sobrien struct partial_die_info comp_unit_die; 115790075Sobrien struct partial_symtab *pst; 115890075Sobrien struct cleanup *back_to; 115990075Sobrien CORE_ADDR lowpc, highpc, baseaddr; 116090075Sobrien 1161161651Skan info_ptr = dwarf_info_buffer; 1162161651Skan abbrev_ptr = dwarf_abbrev_buffer; 1163161651Skan 116490075Sobrien /* We use dwarf2_tmp_obstack for objects that don't need to survive 116590075Sobrien the partial symbol scan, like attribute values. 116690075Sobrien 1167117395Skan We could reduce our peak memory consumption during partial symbol 116890075Sobrien table construction by freeing stuff from this obstack more often 116990075Sobrien --- say, after processing each compilation unit, or each die --- 117090075Sobrien but it turns out that this saves almost nothing. For an 1171117395Skan executable with 11Mb of Dwarf 2 data, I found about 64k allocated 117290075Sobrien on dwarf2_tmp_obstack. Some investigation showed: 1173132718Skan 117418334Speter 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*, 117590075Sobrien DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are 117690075Sobrien all fixed-length values not requiring dynamic allocation. 117790075Sobrien 1178169689Skan 2) 30% of the attributes used the form DW_FORM_string. For 117990075Sobrien DW_FORM_string, read_attribute simply hands back a pointer to 118090075Sobrien the null-terminated string in dwarf_info_buffer, so no dynamic 118118334Speter allocation is needed there either. 1182161651Skan 1183161651Skan 3) The remaining 1% of the attributes all used DW_FORM_block1. 1184161651Skan 75% of those were DW_AT_frame_base location lists for 1185161651Skan functions; the rest were DW_AT_location attributes, probably 118690075Sobrien for the global variables. 1187161651Skan 1188161651Skan Anyway, what this all means is that the memory the dwarf2 118990075Sobrien reader uses as temporary space reading partial symbols is about 119090075Sobrien 0.5% as much as we use for dwarf_*_buffer. That's noise. */ 119190075Sobrien 1192117395Skan obstack_init (&dwarf2_tmp_obstack); 119390075Sobrien back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL); 119490075Sobrien 119590075Sobrien /* Since the objects we're extracting from dwarf_info_buffer vary in 119690075Sobrien length, only the individual functions to extract them (like 119790075Sobrien read_comp_unit_head and read_partial_die) can really know whether 119890075Sobrien the buffer is large enough to hold another complete object. 119990075Sobrien 120090075Sobrien At the moment, they don't actually check that. If 120190075Sobrien dwarf_info_buffer holds just one extra byte after the last 120290075Sobrien compilation unit's dies, then read_comp_unit_head will happily 120390075Sobrien read off the end of the buffer. read_partial_die is similarly 120490075Sobrien casual. Those functions should be fixed. 120590075Sobrien 120690075Sobrien For this loop condition, simply checking whether there's any data 120790075Sobrien left at all should be sufficient. */ 120890075Sobrien while (info_ptr < dwarf_info_buffer + dwarf_info_size) 120990075Sobrien { 121090075Sobrien struct dwarf2_cu cu; 121190075Sobrien beg_of_comp_unit = info_ptr; 121290075Sobrien 121390075Sobrien cu.objfile = objfile; 121490075Sobrien info_ptr = read_comp_unit_head (&cu.header, info_ptr, abfd); 121590075Sobrien 121618334Speter if (cu.header.version != 2) 121790075Sobrien { 121890075Sobrien 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)); 121990075Sobrien return; 122090075Sobrien } 122190075Sobrien if (cu.header.abbrev_offset >= dwarf_abbrev_size) 122290075Sobrien { 122318334Speter error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]", 122490075Sobrien (long) cu.header.abbrev_offset, 122518334Speter (long) (beg_of_comp_unit - dwarf_info_buffer), 122618334Speter bfd_get_filename (abfd)); 122718334Speter return; 122818334Speter } 122918334Speter if (beg_of_comp_unit + cu.header.length + cu.header.initial_length_size 123090075Sobrien > dwarf_info_buffer + dwarf_info_size) 123118334Speter { 123218334Speter error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]", 123390075Sobrien (long) cu.header.length, 123418334Speter (long) (beg_of_comp_unit - dwarf_info_buffer), 123518334Speter bfd_get_filename (abfd)); 1236132718Skan return; 123718334Speter } 123818334Speter /* Complete the cu_header */ 123918334Speter cu.header.offset = beg_of_comp_unit - dwarf_info_buffer; 124018334Speter cu.header.first_die_ptr = info_ptr; 124190075Sobrien cu.header.cu_head_ptr = beg_of_comp_unit; 124290075Sobrien 124318334Speter cu.list_in_scope = &file_symbols; 124418334Speter 124550397Sobrien /* Read the abbrevs for this compilation unit into a table */ 124690075Sobrien dwarf2_read_abbrevs (abfd, &cu); 124790075Sobrien make_cleanup (dwarf2_empty_abbrev_table, cu.header.dwarf2_abbrevs); 124890075Sobrien 124990075Sobrien /* Read the compilation unit die */ 125018334Speter info_ptr = read_partial_die (&comp_unit_die, abfd, info_ptr, 125190075Sobrien &cu); 125290075Sobrien 125390075Sobrien /* Set the language we're debugging */ 125490075Sobrien set_cu_language (comp_unit_die.language, &cu); 125518334Speter 125690075Sobrien /* Allocate a new partial symbol table structure */ 125790075Sobrien pst = start_psymtab_common (objfile, objfile->section_offsets, 125818334Speter comp_unit_die.name ? comp_unit_die.name : "", 125918334Speter comp_unit_die.lowpc, 126018334Speter objfile->global_psymbols.next, 126118334Speter objfile->static_psymbols.next); 126250397Sobrien 126318334Speter pst->read_symtab_private = (char *) 126418334Speter obstack_alloc (&objfile->objfile_obstack, sizeof (struct dwarf2_pinfo)); 126518334Speter DWARF_INFO_BUFFER (pst) = dwarf_info_buffer; 126618334Speter DWARF_INFO_OFFSET (pst) = beg_of_comp_unit - dwarf_info_buffer; 126718334Speter DWARF_ABBREV_BUFFER (pst) = dwarf_abbrev_buffer; 126818334Speter DWARF_ABBREV_SIZE (pst) = dwarf_abbrev_size; 126918334Speter DWARF_LINE_BUFFER (pst) = dwarf_line_buffer; 127018334Speter DWARF_LINE_SIZE (pst) = dwarf_line_size; 127190075Sobrien DWARF_STR_BUFFER (pst) = dwarf_str_buffer; 127218334Speter DWARF_STR_SIZE (pst) = dwarf_str_size; 127318334Speter DWARF_MACINFO_BUFFER (pst) = dwarf_macinfo_buffer; 127418334Speter DWARF_MACINFO_SIZE (pst) = dwarf_macinfo_size; 127518334Speter DWARF_RANGES_BUFFER (pst) = dwarf_ranges_buffer; 127690075Sobrien DWARF_RANGES_SIZE (pst) = dwarf_ranges_size; 127718334Speter DWARF_LOC_BUFFER (pst) = dwarf_loc_buffer; 127818334Speter DWARF_LOC_SIZE (pst) = dwarf_loc_size; 127918334Speter baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 128050397Sobrien 128118334Speter /* Store the function that reads in the rest of the symbol table */ 128218334Speter pst->read_symtab = dwarf2_psymtab_to_symtab; 128318334Speter 128418334Speter /* Check if comp unit has_children. 128518334Speter If so, read the rest of the partial symbols from this comp unit. 128650397Sobrien If not, there's no more debug_info for this comp unit. */ 128718334Speter if (comp_unit_die.has_children) 128818334Speter { 128918334Speter lowpc = ((CORE_ADDR) -1); 129018334Speter highpc = ((CORE_ADDR) 0); 129118334Speter 129218334Speter info_ptr = scan_partial_symbols (info_ptr, &lowpc, &highpc, 129318334Speter &cu, NULL); 129418334Speter 129550397Sobrien /* If we didn't find a lowpc, set it to highpc to avoid 129618334Speter complaints from `maint check'. */ 129718334Speter if (lowpc == ((CORE_ADDR) -1)) 129818334Speter lowpc = highpc; 129918334Speter 130050397Sobrien /* If the compilation unit didn't have an explicit address range, 130118334Speter then use the information extracted from its child dies. */ 130218334Speter if (! comp_unit_die.has_pc_info) 130318334Speter { 130418334Speter comp_unit_die.lowpc = lowpc; 130590075Sobrien comp_unit_die.highpc = highpc; 130690075Sobrien } 130790075Sobrien } 130818334Speter pst->textlow = comp_unit_die.lowpc + baseaddr; 130990075Sobrien pst->texthigh = comp_unit_die.highpc + baseaddr; 131090075Sobrien 131190075Sobrien pst->n_global_syms = objfile->global_psymbols.next - 131290075Sobrien (objfile->global_psymbols.list + pst->globals_offset); 131390075Sobrien pst->n_static_syms = objfile->static_psymbols.next - 131490075Sobrien (objfile->static_psymbols.list + pst->statics_offset); 131518334Speter sort_pst_symbols (pst); 131618334Speter 131718334Speter /* If there is already a psymtab or symtab for a file of this 131818334Speter name, remove it. (If there is a symtab, more drastic things 131918334Speter also happen.) This happens in VxWorks. */ 1320132718Skan free_named_symtabs (pst->filename); 1321132718Skan 132218334Speter info_ptr = beg_of_comp_unit + cu.header.length 1323132718Skan + cu.header.initial_length_size; 1324132718Skan } 132518334Speter do_cleanups (back_to); 132618334Speter} 1327132718Skan 132818334Speter/* Read in all interesting dies to the end of the compilation unit or 132990075Sobrien to the end of the current namespace. NAMESPACE is NULL if we 133090075Sobrien haven't yet encountered any DW_TAG_namespace entries; otherwise, 133190075Sobrien it's the name of the current namespace. In particular, it's the 133290075Sobrien empty string if we're currently in the global namespace but have 133390075Sobrien previously encountered a DW_TAG_namespace. */ 133490075Sobrien 1335117395Skanstatic char * 1336117395Skanscan_partial_symbols (char *info_ptr, CORE_ADDR *lowpc, 1337117395Skan CORE_ADDR *highpc, struct dwarf2_cu *cu, 1338117395Skan const char *namespace) 1339132718Skan{ 1340117395Skan struct objfile *objfile = cu->objfile; 134190075Sobrien bfd *abfd = objfile->obfd; 1342169689Skan struct partial_die_info pdi; 1343169689Skan 134490075Sobrien /* Now, march along the PDI's, descending into ones which have 134518334Speter interesting children but skipping the children of the other ones, 134690075Sobrien until we reach the end of the compilation unit. */ 134790075Sobrien 134890075Sobrien while (1) 134918334Speter { 135090075Sobrien /* This flag tells whether or not info_ptr has gotten updated 135190075Sobrien inside the loop. */ 135290075Sobrien int info_ptr_updated = 0; 135390075Sobrien 135418334Speter info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu); 135590075Sobrien 135690075Sobrien /* Anonymous namespaces have no name but have interesting 135790075Sobrien children, so we need to look at them. Ditto for anonymous 1358169689Skan enums. */ 135990075Sobrien 1360117395Skan if (pdi.name != NULL || pdi.tag == DW_TAG_namespace 136190075Sobrien || pdi.tag == DW_TAG_enumeration_type) 136290075Sobrien { 136390075Sobrien switch (pdi.tag) 136490075Sobrien { 136590075Sobrien case DW_TAG_subprogram: 136690075Sobrien if (pdi.has_pc_info) 136790075Sobrien { 136890075Sobrien if (pdi.lowpc < *lowpc) 1369169689Skan { 137090075Sobrien *lowpc = pdi.lowpc; 137190075Sobrien } 1372132718Skan if (pdi.highpc > *highpc) 137390075Sobrien { 137490075Sobrien *highpc = pdi.highpc; 137590075Sobrien } 137690075Sobrien if (!pdi.is_declaration) 137790075Sobrien { 1378117395Skan add_partial_symbol (&pdi, cu, namespace); 137990075Sobrien } 138090075Sobrien } 1381169689Skan break; 138290075Sobrien case DW_TAG_variable: 1383169689Skan case DW_TAG_typedef: 1384169689Skan case DW_TAG_union_type: 1385169689Skan if (!pdi.is_declaration) 1386169689Skan { 1387169689Skan add_partial_symbol (&pdi, cu, namespace); 1388169689Skan } 1389169689Skan break; 1390169689Skan case DW_TAG_class_type: 1391169689Skan case DW_TAG_structure_type: 1392169689Skan if (!pdi.is_declaration) 1393169689Skan { 1394169689Skan info_ptr = add_partial_structure (&pdi, info_ptr, cu, 1395169689Skan namespace); 1396169689Skan info_ptr_updated = 1; 1397169689Skan } 139890075Sobrien break; 139990075Sobrien case DW_TAG_enumeration_type: 140090075Sobrien if (!pdi.is_declaration) 140118334Speter { 140290075Sobrien info_ptr = add_partial_enumeration (&pdi, info_ptr, cu, 140318334Speter namespace); 140490075Sobrien info_ptr_updated = 1; 140590075Sobrien } 140690075Sobrien break; 140790075Sobrien case DW_TAG_base_type: 140890075Sobrien case DW_TAG_subrange_type: 140990075Sobrien /* File scope base type definitions are added to the partial 141090075Sobrien symbol table. */ 141190075Sobrien add_partial_symbol (&pdi, cu, namespace); 141290075Sobrien break; 141390075Sobrien case DW_TAG_namespace: 141490075Sobrien /* We've hit a DW_TAG_namespace entry, so we know this 141590075Sobrien file has been compiled using a compiler that 141690075Sobrien generates them; update NAMESPACE to reflect that. */ 1417169689Skan if (namespace == NULL) 141890075Sobrien namespace = ""; 141990075Sobrien info_ptr = add_partial_namespace (&pdi, info_ptr, lowpc, highpc, 1420132718Skan cu, namespace); 142190075Sobrien info_ptr_updated = 1; 142290075Sobrien break; 142390075Sobrien default: 142490075Sobrien break; 142590075Sobrien } 142690075Sobrien } 142790075Sobrien 142890075Sobrien if (pdi.tag == 0) 142990075Sobrien break; 143090075Sobrien 143118334Speter /* If the die has a sibling, skip to the sibling, unless another 143290075Sobrien function has already updated info_ptr for us. */ 1433169689Skan 143490075Sobrien /* NOTE: carlton/2003-06-16: This is a bit hackish, but whether 143590075Sobrien or not we want to update this depends on enough stuff (not 143690075Sobrien only pdi.tag but also whether or not pdi.name is NULL) that 143790075Sobrien this seems like the easiest way to handle the issue. */ 143890075Sobrien 143918334Speter if (!info_ptr_updated) 144090075Sobrien info_ptr = locate_pdi_sibling (&pdi, info_ptr, abfd, cu); 144190075Sobrien } 144218334Speter 144390075Sobrien return info_ptr; 144490075Sobrien} 1445169689Skan 144690075Sobrienstatic void 144718334Speteradd_partial_symbol (struct partial_die_info *pdi, 144890075Sobrien struct dwarf2_cu *cu, const char *namespace) 144918334Speter{ 145090075Sobrien struct objfile *objfile = cu->objfile; 145190075Sobrien CORE_ADDR addr = 0; 145290075Sobrien char *actual_name = pdi->name; 145390075Sobrien const struct partial_symbol *psym = NULL; 145490075Sobrien CORE_ADDR baseaddr; 145590075Sobrien 145690075Sobrien baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 145790075Sobrien 145818334Speter /* If we're not in the global namespace and if the namespace name 145990075Sobrien isn't encoded in a mangled actual_name, add it. */ 146090075Sobrien 146118334Speter if (pdi_needs_namespace (pdi->tag, namespace)) 146290075Sobrien { 146318334Speter actual_name = alloca (strlen (pdi->name) + 2 + strlen (namespace) + 1); 146490075Sobrien strcpy (actual_name, namespace); 146518334Speter strcat (actual_name, "::"); 146690075Sobrien strcat (actual_name, pdi->name); 146790075Sobrien } 146818334Speter 146990075Sobrien switch (pdi->tag) 147090075Sobrien { 147190075Sobrien case DW_TAG_subprogram: 147290075Sobrien if (pdi->is_external) 147390075Sobrien { 147490075Sobrien /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, 147518334Speter mst_text, objfile); */ 147690075Sobrien psym = add_psymbol_to_list (actual_name, strlen (actual_name), 147790075Sobrien VAR_DOMAIN, LOC_BLOCK, 147818334Speter &objfile->global_psymbols, 147990075Sobrien 0, pdi->lowpc + baseaddr, 148090075Sobrien cu->language, objfile); 148190075Sobrien } 148290075Sobrien else 148390075Sobrien { 148490075Sobrien /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, 148590075Sobrien mst_file_text, objfile); */ 148690075Sobrien psym = add_psymbol_to_list (actual_name, strlen (actual_name), 148790075Sobrien VAR_DOMAIN, LOC_BLOCK, 148890075Sobrien &objfile->static_psymbols, 148990075Sobrien 0, pdi->lowpc + baseaddr, 149018334Speter cu->language, objfile); 149190075Sobrien } 149290075Sobrien break; 149318334Speter case DW_TAG_variable: 149490075Sobrien if (pdi->is_external) 149518334Speter { 149690075Sobrien /* Global Variable. 149790075Sobrien Don't enter into the minimal symbol tables as there is 149890075Sobrien a minimal symbol table entry from the ELF symbols already. 149990075Sobrien Enter into partial symbol table if it has a location 150090075Sobrien descriptor or a type. 150190075Sobrien If the location descriptor is missing, new_symbol will create 150290075Sobrien a LOC_UNRESOLVED symbol, the address of the variable will then 150390075Sobrien be determined from the minimal symbol table whenever the variable 150418334Speter is referenced. 150590075Sobrien The address for the partial symbol table entry is not 150690075Sobrien used by GDB, but it comes in handy for debugging partial symbol 150718334Speter table building. */ 150890075Sobrien 150990075Sobrien if (pdi->locdesc) 151090075Sobrien addr = decode_locdesc (pdi->locdesc, cu); 151190075Sobrien if (pdi->locdesc || pdi->has_type) 151290075Sobrien psym = add_psymbol_to_list (actual_name, strlen (actual_name), 151390075Sobrien VAR_DOMAIN, LOC_STATIC, 151490075Sobrien &objfile->global_psymbols, 151518334Speter 0, addr + baseaddr, 151690075Sobrien cu->language, objfile); 151718334Speter } 151890075Sobrien else 151990075Sobrien { 1520169689Skan /* Static Variable. Skip symbols without location descriptors. */ 1521169689Skan if (pdi->locdesc == NULL) 152218334Speter return; 152390075Sobrien addr = decode_locdesc (pdi->locdesc, cu); 152490075Sobrien /*prim_record_minimal_symbol (actual_name, addr + baseaddr, 152590075Sobrien mst_file_data, objfile); */ 152690075Sobrien psym = add_psymbol_to_list (actual_name, strlen (actual_name), 152718334Speter VAR_DOMAIN, LOC_STATIC, 152890075Sobrien &objfile->static_psymbols, 152990075Sobrien 0, addr + baseaddr, 153090075Sobrien cu->language, objfile); 153190075Sobrien } 153218334Speter break; 153390075Sobrien case DW_TAG_typedef: 153490075Sobrien case DW_TAG_base_type: 153590075Sobrien case DW_TAG_subrange_type: 153618334Speter add_psymbol_to_list (actual_name, strlen (actual_name), 153790075Sobrien VAR_DOMAIN, LOC_TYPEDEF, 153890075Sobrien &objfile->static_psymbols, 153990075Sobrien 0, (CORE_ADDR) 0, cu->language, objfile); 154090075Sobrien break; 154190075Sobrien case DW_TAG_class_type: 154218334Speter case DW_TAG_structure_type: 154390075Sobrien case DW_TAG_union_type: 154490075Sobrien case DW_TAG_enumeration_type: 154590075Sobrien /* Skip aggregate types without children, these are external 154690075Sobrien references. */ 154790075Sobrien /* NOTE: carlton/2003-10-07: See comment in new_symbol about 154890075Sobrien static vs. global. */ 154990075Sobrien if (pdi->has_children == 0) 155090075Sobrien return; 155118334Speter add_psymbol_to_list (actual_name, strlen (actual_name), 155290075Sobrien STRUCT_DOMAIN, LOC_TYPEDEF, 155390075Sobrien cu->language == language_cplus 155490075Sobrien ? &objfile->global_psymbols 155590075Sobrien : &objfile->static_psymbols, 155690075Sobrien 0, (CORE_ADDR) 0, cu->language, objfile); 155790075Sobrien 155890075Sobrien if (cu->language == language_cplus) 155990075Sobrien { 156090075Sobrien /* For C++, these implicitly act as typedefs as well. */ 156190075Sobrien add_psymbol_to_list (actual_name, strlen (actual_name), 156290075Sobrien VAR_DOMAIN, LOC_TYPEDEF, 156318334Speter &objfile->global_psymbols, 156490075Sobrien 0, (CORE_ADDR) 0, cu->language, objfile); 156518334Speter } 156690075Sobrien break; 156790075Sobrien case DW_TAG_enumerator: 156890075Sobrien add_psymbol_to_list (actual_name, strlen (actual_name), 156990075Sobrien VAR_DOMAIN, LOC_CONST, 157090075Sobrien cu->language == language_cplus 157190075Sobrien ? &objfile->global_psymbols 157290075Sobrien : &objfile->static_psymbols, 157390075Sobrien 0, (CORE_ADDR) 0, cu->language, objfile); 157490075Sobrien break; 157518334Speter default: 157690075Sobrien break; 157790075Sobrien } 157818334Speter 157990075Sobrien /* Check to see if we should scan the name for possible namespace 158090075Sobrien info. Only do this if this is C++, if we don't have namespace 158190075Sobrien debugging info in the file, if the psym is of an appropriate type 158290075Sobrien (otherwise we'll have psym == NULL), and if we actually had a 158390075Sobrien mangled name to begin with. */ 158490075Sobrien 158590075Sobrien if (cu->language == language_cplus 158690075Sobrien && namespace == NULL 158718334Speter && psym != NULL 158890075Sobrien && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL) 158918334Speter cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym), 159018334Speter objfile); 159118334Speter} 159218334Speter 159390075Sobrien/* Determine whether a die of type TAG living in the C++ namespace 1594132718Skan NAMESPACE needs to have the name of the namespace prepended to the 1595169689Skan name listed in the die. */ 159690075Sobrien 159790075Sobrienstatic int 159890075Sobrienpdi_needs_namespace (enum dwarf_tag tag, const char *namespace) 159990075Sobrien{ 160090075Sobrien if (namespace == NULL || namespace[0] == '\0') 160190075Sobrien return 0; 160290075Sobrien 160390075Sobrien switch (tag) 160490075Sobrien { 160590075Sobrien case DW_TAG_typedef: 160690075Sobrien case DW_TAG_class_type: 160718334Speter case DW_TAG_structure_type: 1608169689Skan case DW_TAG_union_type: 1609169689Skan case DW_TAG_enumeration_type: 1610169689Skan case DW_TAG_enumerator: 1611169689Skan return 1; 1612169689Skan default: 161390075Sobrien return 0; 161418334Speter } 161590075Sobrien} 161690075Sobrien 161718334Speter/* Read a partial die corresponding to a namespace; also, add a symbol 161890075Sobrien corresponding to that namespace to the symbol table. NAMESPACE is 161918334Speter the name of the enclosing namespace. */ 162090075Sobrien 162190075Sobrienstatic char * 162218334Speteradd_partial_namespace (struct partial_die_info *pdi, char *info_ptr, 162390075Sobrien CORE_ADDR *lowpc, CORE_ADDR *highpc, 162490075Sobrien struct dwarf2_cu *cu, const char *namespace) 162590075Sobrien{ 162690075Sobrien struct objfile *objfile = cu->objfile; 162790075Sobrien const char *new_name = pdi->name; 162890075Sobrien char *full_name; 162918334Speter 163090075Sobrien /* Calculate the full name of the namespace that we just entered. */ 163190075Sobrien 163218334Speter if (new_name == NULL) 1633169689Skan new_name = "(anonymous namespace)"; 1634169689Skan full_name = alloca (strlen (namespace) + 2 + strlen (new_name) + 1); 1635169689Skan strcpy (full_name, namespace); 1636169689Skan if (*namespace != '\0') 1637169689Skan strcat (full_name, "::"); 1638169689Skan strcat (full_name, new_name); 1639169689Skan 1640169689Skan /* FIXME: carlton/2003-10-07: We can't just replace this by a call 1641169689Skan to add_partial_symbol, because we don't have a way to pass in the 1642169689Skan full name to that function; that might be a flaw in 1643169689Skan add_partial_symbol's interface. */ 1644169689Skan 1645169689Skan add_psymbol_to_list (full_name, strlen (full_name), 1646169689Skan VAR_DOMAIN, LOC_TYPEDEF, 1647169689Skan &objfile->global_psymbols, 1648169689Skan 0, 0, cu->language, objfile); 1649169689Skan 1650169689Skan /* Now scan partial symbols in that namespace. */ 1651169689Skan 1652169689Skan if (pdi->has_children) 1653169689Skan info_ptr = scan_partial_symbols (info_ptr, lowpc, highpc, cu, full_name); 1654169689Skan 1655169689Skan return info_ptr; 1656169689Skan} 1657169689Skan 1658169689Skan/* Read a partial die corresponding to a class or structure. */ 1659169689Skan 1660132718Skanstatic char * 1661132718Skanadd_partial_structure (struct partial_die_info *struct_pdi, char *info_ptr, 1662169689Skan struct dwarf2_cu *cu, 1663132718Skan const char *namespace) 1664132718Skan{ 1665132718Skan bfd *abfd = cu->objfile->obfd; 1666132718Skan char *actual_class_name = NULL; 1667132718Skan 1668132718Skan if (cu->language == language_cplus 1669132718Skan && (namespace == NULL || namespace[0] == '\0') 1670132718Skan && struct_pdi->name != NULL 1671169689Skan && struct_pdi->has_children) 1672132718Skan { 1673132718Skan /* See if we can figure out if the class lives in a namespace 1674132718Skan (or is nested within another class.) We do this by looking 1675132718Skan for a member function; its demangled name will contain 1676132718Skan namespace info, if there is any. */ 1677132718Skan 1678132718Skan /* NOTE: carlton/2003-10-07: Getting the info this way changes 1679132718Skan what template types look like, because the demangler 1680132718Skan frequently doesn't give the same name as the debug info. We 1681132718Skan could fix this by only using the demangled name to get the 1682132718Skan prefix (but see comment in read_structure_type). */ 1683132718Skan 1684132718Skan /* FIXME: carlton/2004-01-23: If NAMESPACE equals "", we have 1685132718Skan the appropriate debug information, so it would be nice to be 1686132718Skan able to avoid this hack. But NAMESPACE may not be the 1687132718Skan namespace where this class was defined: NAMESPACE reflects 1688132718Skan where STRUCT_PDI occurs in the tree of dies, but because of 1689132718Skan DW_AT_specification, that may not actually tell us where the 1690132718Skan class is defined. (See the comment in read_func_scope for an 1691132718Skan example of how this could occur.) 1692132718Skan 1693132718Skan Unfortunately, our current partial symtab data structures are 1694169689Skan completely unable to deal with DW_AT_specification. So, for 1695169689Skan now, the best thing to do is to get nesting information from 1696169689Skan places other than the tree structure of dies if there's any 1697169689Skan chance that a DW_AT_specification is involved. :-( */ 1698169689Skan 1699169689Skan char *next_child = info_ptr; 1700169689Skan 1701169689Skan while (1) 1702169689Skan { 1703169689Skan struct partial_die_info child_pdi; 1704169689Skan 1705169689Skan next_child = read_partial_die (&child_pdi, abfd, next_child, 1706169689Skan cu); 1707169689Skan if (!child_pdi.tag) 1708169689Skan break; 1709169689Skan if (child_pdi.tag == DW_TAG_subprogram) 1710169689Skan { 1711169689Skan actual_class_name = class_name_from_physname (child_pdi.name); 1712169689Skan if (actual_class_name != NULL) 1713169689Skan struct_pdi->name = actual_class_name; 1714169689Skan break; 1715169689Skan } 1716169689Skan else 1717169689Skan { 1718169689Skan next_child = locate_pdi_sibling (&child_pdi, next_child, 1719169689Skan abfd, cu); 1720169689Skan } 1721169689Skan } 1722169689Skan } 1723169689Skan 1724169689Skan add_partial_symbol (struct_pdi, cu, namespace); 1725169689Skan xfree (actual_class_name); 1726169689Skan 1727169689Skan return locate_pdi_sibling (struct_pdi, info_ptr, abfd, cu); 1728169689Skan} 1729169689Skan 1730169689Skan/* Read a partial die corresponding to an enumeration type. */ 1731169689Skan 1732169689Skanstatic char * 1733169689Skanadd_partial_enumeration (struct partial_die_info *enum_pdi, char *info_ptr, 1734169689Skan struct dwarf2_cu *cu, const char *namespace) 1735169689Skan{ 1736169689Skan struct objfile *objfile = cu->objfile; 1737169689Skan bfd *abfd = objfile->obfd; 1738169689Skan struct partial_die_info pdi; 1739169689Skan 1740169689Skan if (enum_pdi->name != NULL) 1741169689Skan add_partial_symbol (enum_pdi, cu, namespace); 1742169689Skan 1743169689Skan while (1) 1744169689Skan { 1745169689Skan info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu); 1746169689Skan if (pdi.tag == 0) 1747169689Skan break; 1748169689Skan if (pdi.tag != DW_TAG_enumerator || pdi.name == NULL) 1749169689Skan complaint (&symfile_complaints, "malformed enumerator DIE ignored"); 1750169689Skan else 1751169689Skan add_partial_symbol (&pdi, cu, namespace); 1752169689Skan } 1753169689Skan 1754169689Skan return info_ptr; 1755169689Skan} 1756169689Skan 1757169689Skan/* Locate ORIG_PDI's sibling; INFO_PTR should point to the next DIE 1758169689Skan after ORIG_PDI. */ 1759169689Skan 1760169689Skanstatic char * 1761169689Skanlocate_pdi_sibling (struct partial_die_info *orig_pdi, char *info_ptr, 1762169689Skan bfd *abfd, struct dwarf2_cu *cu) 1763169689Skan{ 1764169689Skan /* Do we know the sibling already? */ 1765169689Skan 1766169689Skan if (orig_pdi->sibling) 1767169689Skan return orig_pdi->sibling; 1768169689Skan 1769169689Skan /* Are there any children to deal with? */ 1770169689Skan 1771169689Skan if (!orig_pdi->has_children) 1772169689Skan return info_ptr; 1773169689Skan 1774169689Skan /* Okay, we don't know the sibling, but we have children that we 1775169689Skan want to skip. So read children until we run into one without a 1776169689Skan tag; return whatever follows it. */ 1777169689Skan 1778169689Skan while (1) 1779169689Skan { 1780169689Skan struct partial_die_info pdi; 1781169689Skan 1782169689Skan info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu); 1783169689Skan 1784169689Skan if (pdi.tag == 0) 1785169689Skan return info_ptr; 1786169689Skan else 1787169689Skan info_ptr = locate_pdi_sibling (&pdi, info_ptr, abfd, cu); 1788169689Skan } 1789169689Skan} 1790169689Skan 1791169689Skan/* Expand this partial symbol table into a full symbol table. */ 1792169689Skan 1793169689Skanstatic void 1794169689Skandwarf2_psymtab_to_symtab (struct partial_symtab *pst) 1795169689Skan{ 1796169689Skan /* FIXME: This is barely more than a stub. */ 1797169689Skan if (pst != NULL) 1798169689Skan { 1799169689Skan if (pst->readin) 1800169689Skan { 1801169689Skan warning ("bug: psymtab for %s is already read in.", pst->filename); 1802169689Skan } 1803169689Skan else 1804169689Skan { 1805169689Skan if (info_verbose) 1806169689Skan { 1807169689Skan printf_filtered ("Reading in symbols for %s...", pst->filename); 1808169689Skan gdb_flush (gdb_stdout); 1809169689Skan } 1810117395Skan 1811117395Skan psymtab_to_symtab_1 (pst); 1812117395Skan 181318334Speter /* Finish up the debug error message. */ 181490075Sobrien if (info_verbose) 1815169689Skan printf_filtered ("done.\n"); 1816169689Skan } 1817132718Skan } 181818334Speter} 1819117395Skan 182090075Sobrienstatic void 182190075Sobrienpsymtab_to_symtab_1 (struct partial_symtab *pst) 182290075Sobrien{ 182318334Speter struct objfile *objfile = pst->objfile; 182490075Sobrien bfd *abfd = objfile->obfd; 1825169689Skan struct dwarf2_cu cu; 182618334Speter struct die_info *dies; 182790075Sobrien unsigned long offset; 182890075Sobrien CORE_ADDR lowpc, highpc; 182918334Speter struct die_info *child_die; 183090075Sobrien char *info_ptr; 1831169689Skan struct symtab *symtab; 183290075Sobrien struct cleanup *back_to; 183318334Speter struct attribute *attr; 183418334Speter CORE_ADDR baseaddr; 183590075Sobrien 183690075Sobrien /* Set local variables from the partial symbol table info. */ 183718334Speter offset = DWARF_INFO_OFFSET (pst); 183890075Sobrien dwarf_info_buffer = DWARF_INFO_BUFFER (pst); 183990075Sobrien dwarf_abbrev_buffer = DWARF_ABBREV_BUFFER (pst); 184050397Sobrien dwarf_abbrev_size = DWARF_ABBREV_SIZE (pst); 184190075Sobrien dwarf_line_buffer = DWARF_LINE_BUFFER (pst); 184290075Sobrien dwarf_line_size = DWARF_LINE_SIZE (pst); 184350397Sobrien dwarf_str_buffer = DWARF_STR_BUFFER (pst); 184490075Sobrien dwarf_str_size = DWARF_STR_SIZE (pst); 184590075Sobrien dwarf_macinfo_buffer = DWARF_MACINFO_BUFFER (pst); 184690075Sobrien dwarf_macinfo_size = DWARF_MACINFO_SIZE (pst); 184790075Sobrien dwarf_ranges_buffer = DWARF_RANGES_BUFFER (pst); 184890075Sobrien dwarf_ranges_size = DWARF_RANGES_SIZE (pst); 184990075Sobrien dwarf_loc_buffer = DWARF_LOC_BUFFER (pst); 185090075Sobrien dwarf_loc_size = DWARF_LOC_SIZE (pst); 185190075Sobrien info_ptr = dwarf_info_buffer + offset; 185290075Sobrien baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 1853117395Skan 1854117395Skan /* We're in the global namespace. */ 185590075Sobrien processing_current_prefix = ""; 185690075Sobrien 185790075Sobrien obstack_init (&dwarf2_tmp_obstack); 185890075Sobrien back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL); 185990075Sobrien 186090075Sobrien buildsym_init (); 186190075Sobrien make_cleanup (really_free_pendings, NULL); 186290075Sobrien 186390075Sobrien cu.objfile = objfile; 186450397Sobrien 186590075Sobrien /* read in the comp_unit header */ 186690075Sobrien info_ptr = read_comp_unit_head (&cu.header, info_ptr, abfd); 186790075Sobrien 186890075Sobrien /* Read the abbrevs for this compilation unit */ 186950397Sobrien dwarf2_read_abbrevs (abfd, &cu); 187090075Sobrien make_cleanup (dwarf2_empty_abbrev_table, cu.header.dwarf2_abbrevs); 187190075Sobrien 187290075Sobrien cu.header.offset = offset; 187390075Sobrien 187490075Sobrien cu.list_in_scope = &file_symbols; 187590075Sobrien 1876117395Skan dies = read_comp_unit (info_ptr, abfd, &cu); 187790075Sobrien 187850397Sobrien make_cleanup_free_die_list (dies); 187990075Sobrien 188090075Sobrien /* Find the base address of the compilation unit for range lists and 188190075Sobrien location lists. It will normally be specified by DW_AT_low_pc. 188250397Sobrien In DWARF-3 draft 4, the base address could be overridden by 188390075Sobrien DW_AT_entry_pc. It's been removed, but GCC still uses this for 188490075Sobrien compilation units with discontinuous ranges. */ 188590075Sobrien 188650397Sobrien cu.header.base_known = 0; 188790075Sobrien cu.header.base_address = 0; 188890075Sobrien 188990075Sobrien attr = dwarf2_attr (dies, DW_AT_entry_pc, &cu); 189090075Sobrien if (attr) 189150397Sobrien { 189290075Sobrien cu.header.base_address = DW_ADDR (attr); 189390075Sobrien cu.header.base_known = 1; 189450397Sobrien } 189590075Sobrien else 189690075Sobrien { 189790075Sobrien attr = dwarf2_attr (dies, DW_AT_low_pc, &cu); 1898169689Skan if (attr) 1899169689Skan { 1900169689Skan cu.header.base_address = DW_ADDR (attr); 1901169689Skan cu.header.base_known = 1; 1902169689Skan } 1903169689Skan } 1904169689Skan 190550397Sobrien /* Do line number decoding in read_file_scope () */ 190690075Sobrien process_die (dies, &cu); 190750397Sobrien 190890075Sobrien /* Some compilers don't define a DW_AT_high_pc attribute for the 190990075Sobrien compilation unit. If the DW_AT_high_pc is missing, synthesize 191090075Sobrien it, by scanning the DIE's below the compilation unit. */ 1911117395Skan get_scope_pc_bounds (dies, &lowpc, &highpc, &cu); 191290075Sobrien 191390075Sobrien symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); 191490075Sobrien 191550397Sobrien /* Set symtab language to language from DW_AT_language. 191690075Sobrien If the compilation is from a C file generated by language preprocessors, 1917169689Skan do not set the language if it was already deduced by start_subfile. */ 191890075Sobrien if (symtab != NULL 191950397Sobrien && !(cu.language == language_c && symtab->language != language_c)) 192090075Sobrien { 192150397Sobrien symtab->language = cu.language; 192290075Sobrien } 192390075Sobrien pst->symtab = symtab; 192490075Sobrien pst->readin = 1; 1925132718Skan 1926132718Skan do_cleanups (back_to); 192718334Speter} 192818334Speter 192918334Speter/* Process a die and its children. */ 193018334Speter 193152284Sobrienstatic void 193218334Speterprocess_die (struct die_info *die, struct dwarf2_cu *cu) 193318334Speter{ 193418334Speter switch (die->tag) 193518334Speter { 193618334Speter case DW_TAG_padding: 193718334Speter break; 193818334Speter case DW_TAG_compile_unit: 193918334Speter read_file_scope (die, cu); 1940132718Skan break; 194118334Speter case DW_TAG_subprogram: 194218334Speter read_subroutine_type (die, cu); 194352284Sobrien read_func_scope (die, cu); 194418334Speter break; 194518334Speter case DW_TAG_inlined_subroutine: 194618334Speter /* FIXME: These are ignored for now. 194718334Speter They could be used to set breakpoints on all inlined instances 194818334Speter of a function and make GDB `next' properly over inlined functions. */ 194990075Sobrien break; 195090075Sobrien case DW_TAG_lexical_block: 195118334Speter case DW_TAG_try_block: 195218334Speter case DW_TAG_catch_block: 195318334Speter read_lexical_block_scope (die, cu); 195418334Speter break; 195518334Speter case DW_TAG_class_type: 195618334Speter case DW_TAG_structure_type: 195752284Sobrien case DW_TAG_union_type: 195818334Speter read_structure_type (die, cu); 195990075Sobrien process_structure_scope (die, cu); 196090075Sobrien break; 196190075Sobrien case DW_TAG_enumeration_type: 196218334Speter read_enumeration_type (die, cu); 196318334Speter process_enumeration_scope (die, cu); 196490075Sobrien break; 196552284Sobrien 196652284Sobrien /* FIXME drow/2004-03-14: These initialize die->type, but do not create 196752284Sobrien a symbol or process any children. Therefore it doesn't do anything 196818334Speter that won't be done on-demand by read_type_die. */ 196952284Sobrien case DW_TAG_subroutine_type: 197052284Sobrien read_subroutine_type (die, cu); 197152284Sobrien break; 197290075Sobrien case DW_TAG_array_type: 1973117395Skan read_array_type (die, cu); 1974169689Skan break; 197518334Speter case DW_TAG_pointer_type: 197650397Sobrien read_tag_pointer_type (die, cu); 197790075Sobrien break; 197890075Sobrien case DW_TAG_ptr_to_member_type: 1979169689Skan read_tag_ptr_to_member_type (die, cu); 198018334Speter break; 198190075Sobrien case DW_TAG_reference_type: 198290075Sobrien case DW_TAG_rvalue_reference_type: 198318334Speter read_tag_reference_type (die, cu); 198418334Speter break; 198518334Speter case DW_TAG_string_type: 198618334Speter read_tag_string_type (die, cu); 198718334Speter break; 198818334Speter /* END FIXME */ 198918334Speter 1990132718Skan case DW_TAG_base_type: 1991132718Skan read_base_type (die, cu); 1992132718Skan /* Add a typedef symbol for the type definition, if it has a 199318334Speter DW_AT_name. */ 199418334Speter new_symbol (die, die->type, cu); 199518334Speter break; 199618334Speter case DW_TAG_subrange_type: 199718334Speter read_subrange_type (die, cu); 199818334Speter /* Add a typedef symbol for the type definition, if it has a 199918334Speter DW_AT_name. */ 2000169689Skan new_symbol (die, die->type, cu); 200118334Speter break; 200218334Speter case DW_TAG_common_block: 200318334Speter read_common_block (die, cu); 200418334Speter break; 200518334Speter case DW_TAG_common_inclusion: 200618334Speter break; 200718334Speter case DW_TAG_namespace: 200818334Speter processing_has_namespace_info = 1; 200918334Speter read_namespace (die, cu); 201018334Speter break; 201118334Speter case DW_TAG_imported_declaration: 201218334Speter case DW_TAG_imported_module: 201318334Speter /* FIXME: carlton/2002-10-16: Eventually, we should use the 201418334Speter information contained in these. DW_TAG_imported_declaration 201518334Speter dies shouldn't have children; DW_TAG_imported_module dies 201618334Speter shouldn't in the C++ case, but conceivably could in the 201718334Speter Fortran case, so we'll have to replace this gdb_assert if 201818334Speter Fortran compilers start generating that info. */ 201918334Speter processing_has_namespace_info = 1; 202018334Speter gdb_assert (die->child == NULL); 202118334Speter break; 202218334Speter default: 2023132718Skan new_symbol (die, NULL, cu); 2024132718Skan break; 202518334Speter } 202618334Speter} 202718334Speter 202818334Speterstatic void 202918334Speterinitialize_cu_func_list (struct dwarf2_cu *cu) 203018334Speter{ 203118334Speter cu->first_fn = cu->last_fn = cu->cached_fn = NULL; 203218334Speter} 2033169689Skan 203418334Speterstatic void 203518334Speterread_file_scope (struct die_info *die, struct dwarf2_cu *cu) 203618334Speter{ 203718334Speter struct objfile *objfile = cu->objfile; 203818334Speter struct comp_unit_head *cu_header = &cu->header; 203918334Speter struct cleanup *back_to = make_cleanup (null_cleanup, 0); 204018334Speter CORE_ADDR lowpc = ((CORE_ADDR) -1); 204118334Speter CORE_ADDR highpc = ((CORE_ADDR) 0); 204218334Speter struct attribute *attr; 204318334Speter char *name = "<unknown>"; 204418334Speter char *comp_dir = NULL; 204518334Speter struct die_info *child_die; 204618334Speter bfd *abfd = objfile->obfd; 204718334Speter struct line_header *line_header = 0; 204890075Sobrien CORE_ADDR baseaddr; 204918334Speter 205018334Speter baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 205118334Speter 205252284Sobrien get_scope_pc_bounds (die, &lowpc, &highpc, cu); 205390075Sobrien 2054169689Skan /* If we didn't find a lowpc, set it to highpc to avoid complaints 205552284Sobrien from finish_block. */ 2056169689Skan if (lowpc == ((CORE_ADDR) -1)) 205718334Speter lowpc = highpc; 205818334Speter lowpc += baseaddr; 205918334Speter highpc += baseaddr; 206090075Sobrien 206190075Sobrien attr = dwarf2_attr (die, DW_AT_name, cu); 206290075Sobrien if (attr) 206390075Sobrien { 206418334Speter name = DW_STRING (attr); 206590075Sobrien } 206618334Speter attr = dwarf2_attr (die, DW_AT_comp_dir, cu); 2067169689Skan if (attr) 206818334Speter { 206990075Sobrien comp_dir = DW_STRING (attr); 207018334Speter if (comp_dir) 207190075Sobrien { 207290075Sobrien /* Irix 6.2 native cc prepends <machine>.: to the compilation 207390075Sobrien directory, get rid of it. */ 207490075Sobrien char *cp = strchr (comp_dir, ':'); 207518334Speter 207618334Speter if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/') 207718334Speter comp_dir = cp + 1; 207818334Speter } 207990075Sobrien } 208018334Speter 208118334Speter if (objfile->ei.entry_point >= lowpc && 208218334Speter objfile->ei.entry_point < highpc) 208318334Speter { 208418334Speter objfile->ei.deprecated_entry_file_lowpc = lowpc; 208518334Speter objfile->ei.deprecated_entry_file_highpc = highpc; 208618334Speter } 208790075Sobrien 208818334Speter attr = dwarf2_attr (die, DW_AT_language, cu); 208918334Speter if (attr) 209090075Sobrien { 209118334Speter set_cu_language (DW_UNSND (attr), cu); 209218334Speter } 209350397Sobrien 209418334Speter /* We assume that we're processing GCC output. */ 209552284Sobrien processing_gcc_compilation = 2; 209690075Sobrien#if 0 209718334Speter /* FIXME:Do something here. */ 209890075Sobrien if (dip->at_producer != NULL) 209918334Speter { 2100169689Skan handle_producer (dip->at_producer); 210118334Speter } 210290075Sobrien#endif 210318334Speter 210418334Speter /* The compilation unit may be in a different language or objfile, 210518334Speter zero out all remembered fundamental types. */ 210618334Speter memset (cu->ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *)); 210718334Speter 210818334Speter start_symtab (name, comp_dir, lowpc); 210918334Speter record_debugformat ("DWARF 2"); 2110169689Skan 211118334Speter initialize_cu_func_list (cu); 211218334Speter 211318334Speter /* Process all dies in compilation unit. */ 211418334Speter if (die->child != NULL) 211518334Speter { 211618334Speter child_die = die->child; 211718334Speter while (child_die && child_die->tag) 211818334Speter { 211918334Speter process_die (child_die, cu); 212018334Speter child_die = sibling_die (child_die); 212118334Speter } 212218334Speter } 212318334Speter 2124169689Skan /* Decode line number information if present. */ 212518334Speter attr = dwarf2_attr (die, DW_AT_stmt_list, cu); 212618334Speter if (attr) 212718334Speter { 212818334Speter unsigned int line_offset = DW_UNSND (attr); 212918334Speter line_header = dwarf_decode_line_header (line_offset, abfd, cu); 213018334Speter if (line_header) 213150397Sobrien { 213218334Speter make_cleanup ((make_cleanup_ftype *) free_line_header, 213352284Sobrien (void *) line_header); 213490075Sobrien dwarf_decode_lines (line_header, comp_dir, abfd, cu); 213518334Speter } 213618334Speter } 213750397Sobrien 213818334Speter /* Decode macro information, if present. Dwarf 2 macro information 213918334Speter refers to information in the line number info statement program 214018334Speter header, so we can only read it if we've read the header 214190075Sobrien successfully. */ 214218334Speter attr = dwarf2_attr (die, DW_AT_macro_info, cu); 214318334Speter if (attr && line_header) 214452284Sobrien { 214518334Speter unsigned int macro_offset = DW_UNSND (attr); 214690075Sobrien dwarf_decode_macros (line_header, macro_offset, 214790075Sobrien comp_dir, abfd, cu); 214890075Sobrien } 214990075Sobrien do_cleanups (back_to); 215090075Sobrien} 215118334Speter 215218334Speterstatic void 215318334Speteradd_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, 215418334Speter struct dwarf2_cu *cu) 215518334Speter{ 215618334Speter struct function_range *thisfn; 215718334Speter 215818334Speter thisfn = (struct function_range *) 215918334Speter obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct function_range)); 216050397Sobrien thisfn->name = name; 216118334Speter thisfn->lowpc = lowpc; 216218334Speter thisfn->highpc = highpc; 216318334Speter thisfn->seen_line = 0; 216418334Speter thisfn->next = NULL; 216518334Speter 216618334Speter if (cu->last_fn == NULL) 216718334Speter cu->first_fn = thisfn; 216890075Sobrien else 216990075Sobrien cu->last_fn->next = thisfn; 217018334Speter 217118334Speter cu->last_fn = thisfn; 217218334Speter} 217318334Speter 217418334Speterstatic void 217518334Speterread_func_scope (struct die_info *die, struct dwarf2_cu *cu) 217618334Speter{ 217718334Speter struct objfile *objfile = cu->objfile; 217818334Speter struct context_stack *new; 217918334Speter CORE_ADDR lowpc; 218018334Speter CORE_ADDR highpc; 218118334Speter struct die_info *child_die; 218218334Speter struct attribute *attr; 218318334Speter char *name; 218418334Speter const char *previous_prefix = processing_current_prefix; 218590075Sobrien struct cleanup *back_to = NULL; 218618334Speter CORE_ADDR baseaddr; 218718334Speter 218818334Speter baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 218918334Speter 219090075Sobrien name = dwarf2_linkage_name (die, cu); 219118334Speter 219218334Speter /* Ignore functions with missing or empty names and functions with 219390075Sobrien missing or invalid low and high pc attributes. */ 219490075Sobrien if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) 219518334Speter return; 219618334Speter 219718334Speter if (cu->language == language_cplus) 219818334Speter { 219952284Sobrien struct die_info *spec_die = die_specification (die, cu); 220090075Sobrien 220118334Speter /* NOTE: carlton/2004-01-23: We have to be careful in the 220218334Speter presence of DW_AT_specification. For example, with GCC 3.4, 220318334Speter given the code 220418334Speter 220590075Sobrien namespace N { 220618334Speter void foo() { 220752284Sobrien // Definition of N::foo. 220890075Sobrien } 220918334Speter } 221090075Sobrien 221190075Sobrien then we'll have a tree of DIEs like this: 221218334Speter 221318334Speter 1: DW_TAG_compile_unit 221418334Speter 2: DW_TAG_namespace // N 221518334Speter 3: DW_TAG_subprogram // declaration of N::foo 221618334Speter 4: DW_TAG_subprogram // definition of N::foo 221718334Speter DW_AT_specification // refers to die #3 221818334Speter 221918334Speter Thus, when processing die #4, we have to pretend that we're 2220132718Skan in the context of its DW_AT_specification, namely the contex 2221132718Skan of die #3. */ 222218334Speter 2223132718Skan if (spec_die != NULL) 2224132718Skan { 222518334Speter char *specification_prefix = determine_prefix (spec_die, cu); 222690075Sobrien processing_current_prefix = specification_prefix; 2227132718Skan back_to = make_cleanup (xfree, specification_prefix); 222890075Sobrien } 222918334Speter } 2230169689Skan 223190075Sobrien lowpc += baseaddr; 223290075Sobrien highpc += baseaddr; 223318334Speter 223490075Sobrien /* Record the function range for dwarf_decode_lines. */ 223590075Sobrien add_to_cu_func_list (name, lowpc, highpc, cu); 223690075Sobrien 223718334Speter if (objfile->ei.entry_point >= lowpc && 223890075Sobrien objfile->ei.entry_point < highpc) 223990075Sobrien { 2240169689Skan objfile->ei.entry_func_lowpc = lowpc; 224118334Speter objfile->ei.entry_func_highpc = highpc; 224290075Sobrien } 224318334Speter 224490075Sobrien new = push_context (0, lowpc); 224590075Sobrien new->name = new_symbol (die, die->type, cu); 224690075Sobrien 224790075Sobrien /* If there is a location expression for DW_AT_frame_base, record 224890075Sobrien it. */ 224990075Sobrien attr = dwarf2_attr (die, DW_AT_frame_base, cu); 225090075Sobrien if (attr) 225118334Speter /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location 225218334Speter expression is being recorded directly in the function's symbol 225318334Speter and not in a separate frame-base object. I guess this hack is 225418334Speter to avoid adding some sort of frame-base adjunct/annex to the 225518334Speter function's symbol :-(. The problem with doing this is that it 225650397Sobrien results in a function symbol with a location expression that 225718334Speter has nothing to do with the location of the function, ouch! The 225852284Sobrien relationship should be: a function's symbol has-a frame base; a 225918334Speter frame-base has-a location expression. */ 226052284Sobrien dwarf2_symbol_mark_computed (attr, new->name, cu); 226118334Speter 226218334Speter cu->list_in_scope = &local_symbols; 226318334Speter 226418334Speter if (die->child != NULL) 226550397Sobrien { 226618334Speter child_die = die->child; 226752284Sobrien while (child_die && child_die->tag) 2268132718Skan { 226918334Speter process_die (child_die, cu); 227018334Speter child_die = sibling_die (child_die); 227118334Speter } 227218334Speter } 227318334Speter 227418334Speter new = pop_context (); 2275169689Skan /* Make a block for the local symbols within. */ 2276169689Skan finish_block (new->name, &local_symbols, new->old_blocks, 2277169689Skan lowpc, highpc, objfile); 2278169689Skan 2279169689Skan /* In C++, we can have functions nested inside functions (e.g., when 2280169689Skan a function declares a class that has methods). This means that 2281169689Skan when we finish processing a function scope, we may need to go 2282169689Skan back to building a containing block's symbol lists. */ 228318334Speter local_symbols = new->locals; 228418334Speter param_symbols = new->params; 2285132718Skan 2286132718Skan /* If we've finished processing a top-level function, subsequent 228718334Speter symbols go in the file symbol list. */ 228818334Speter if (outermost_context_p ()) 228918334Speter cu->list_in_scope = &file_symbols; 229050397Sobrien 229118334Speter processing_current_prefix = previous_prefix; 2292169689Skan if (back_to != NULL) 2293132718Skan do_cleanups (back_to); 229418334Speter} 2295169689Skan 2296169689Skan/* Process all the DIES contained within a lexical block scope. Start 2297169689Skan a new scope, process the dies, and then close the scope. */ 2298169689Skan 2299169689Skanstatic void 2300169689Skanread_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) 2301169689Skan{ 2302169689Skan struct objfile *objfile = cu->objfile; 2303169689Skan struct context_stack *new; 2304169689Skan CORE_ADDR lowpc, highpc; 230518334Speter struct die_info *child_die; 230618334Speter CORE_ADDR baseaddr; 230718334Speter 230850397Sobrien baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 230918334Speter 231090075Sobrien /* Ignore blocks with missing or invalid low and high pc attributes. */ 231118334Speter /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges 231218334Speter as multiple lexical blocks? Handling children in a sane way would 231318334Speter be nasty. Might be easier to properly extend generic blocks to 231418334Speter describe ranges. */ 231590075Sobrien if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) 231618334Speter return; 231718334Speter lowpc += baseaddr; 231818334Speter highpc += baseaddr; 2319132718Skan 2320132718Skan push_context (0, lowpc); 232118334Speter if (die->child != NULL) 232218334Speter { 232318334Speter child_die = die->child; 232418334Speter while (child_die && child_die->tag) 232518334Speter { 232618334Speter process_die (child_die, cu); 232790075Sobrien child_die = sibling_die (child_die); 232890075Sobrien } 2329169689Skan } 233090075Sobrien new = pop_context (); 233118334Speter 233218334Speter if (local_symbols != NULL) 233350397Sobrien { 233418334Speter finish_block (0, &local_symbols, new->old_blocks, new->start_addr, 233518334Speter highpc, objfile); 2336132718Skan } 233718334Speter local_symbols = new->locals; 233818334Speter} 233990075Sobrien 234018334Speter/* Get low and high pc attributes from a die. Return 1 if the attributes 2341169689Skan are present and valid, otherwise, return 0. Return -1 if the range is 2342169689Skan discontinuous, i.e. derived from DW_AT_ranges information. */ 2343169689Skanstatic int 2344169689Skandwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, 2345169689Skan CORE_ADDR *highpc, struct dwarf2_cu *cu) 2346169689Skan{ 2347169689Skan struct objfile *objfile = cu->objfile; 2348169689Skan struct comp_unit_head *cu_header = &cu->header; 2349169689Skan struct attribute *attr; 2350169689Skan bfd *obfd = objfile->obfd; 2351169689Skan CORE_ADDR low = 0; 2352169689Skan CORE_ADDR high = 0; 2353169689Skan int ret = 0; 235490075Sobrien 235590075Sobrien attr = dwarf2_attr (die, DW_AT_high_pc, cu); 235618334Speter if (attr) 235790075Sobrien { 235890075Sobrien high = DW_ADDR (attr); 2359132718Skan attr = dwarf2_attr (die, DW_AT_low_pc, cu); 236090075Sobrien if (attr) 236190075Sobrien low = DW_ADDR (attr); 236290075Sobrien else 236318334Speter /* Found high w/o low attribute. */ 236450397Sobrien return 0; 236518334Speter 2366169689Skan /* Found consecutive range of addresses. */ 2367169689Skan ret = 1; 2368169689Skan } 2369169689Skan else 2370169689Skan { 2371169689Skan attr = dwarf2_attr (die, DW_AT_ranges, cu); 2372169689Skan if (attr != NULL) 2373169689Skan { 237418334Speter unsigned int addr_size = cu_header->addr_size; 2375169689Skan CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); 2376169689Skan /* Value of the DW_AT_ranges attribute is the offset in the 2377169689Skan .debug_ranges section. */ 2378169689Skan unsigned int offset = DW_UNSND (attr); 2379169689Skan /* Base address selection entry. */ 2380169689Skan CORE_ADDR base; 2381169689Skan int found_base; 2382169689Skan int dummy; 2383169689Skan char *buffer; 2384169689Skan CORE_ADDR marker; 2385169689Skan int low_set; 2386169689Skan 2387169689Skan found_base = cu_header->base_known; 2388169689Skan base = cu_header->base_address; 2389169689Skan 2390169689Skan if (offset >= dwarf_ranges_size) 2391169689Skan { 2392169689Skan complaint (&symfile_complaints, 2393169689Skan "Offset %d out of bounds for DW_AT_ranges attribute", 2394169689Skan offset); 2395169689Skan return 0; 2396169689Skan } 2397169689Skan buffer = dwarf_ranges_buffer + offset; 2398169689Skan 2399169689Skan /* Read in the largest possible address. */ 2400169689Skan marker = read_address (obfd, buffer, cu, &dummy); 2401169689Skan if ((marker & mask) == mask) 2402169689Skan { 2403169689Skan /* If we found the largest possible address, then 2404169689Skan read the base address. */ 2405169689Skan base = read_address (obfd, buffer + addr_size, cu, &dummy); 2406169689Skan buffer += 2 * addr_size; 2407169689Skan offset += 2 * addr_size; 2408169689Skan found_base = 1; 2409169689Skan } 2410169689Skan 2411169689Skan low_set = 0; 2412169689Skan 2413169689Skan while (1) 2414169689Skan { 2415169689Skan CORE_ADDR range_beginning, range_end; 2416169689Skan 2417169689Skan range_beginning = read_address (obfd, buffer, cu, &dummy); 2418169689Skan buffer += addr_size; 2419169689Skan range_end = read_address (obfd, buffer, cu, &dummy); 2420169689Skan buffer += addr_size; 2421169689Skan offset += 2 * addr_size; 2422169689Skan 2423169689Skan /* An end of list marker is a pair of zero addresses. */ 2424169689Skan if (range_beginning == 0 && range_end == 0) 2425169689Skan /* Found the end of list entry. */ 2426169689Skan break; 2427169689Skan 2428169689Skan /* Each base address selection entry is a pair of 2 values. 2429169689Skan The first is the largest possible address, the second is 2430169689Skan the base address. Check for a base address here. */ 2431169689Skan if ((range_beginning & mask) == mask) 2432169689Skan { 2433169689Skan /* If we found the largest possible address, then 2434169689Skan read the base address. */ 2435169689Skan base = read_address (obfd, buffer + addr_size, cu, &dummy); 2436169689Skan found_base = 1; 2437169689Skan continue; 2438169689Skan } 2439169689Skan 2440169689Skan if (!found_base) 2441169689Skan { 2442169689Skan /* We have no valid base address for the ranges 2443169689Skan data. */ 2444169689Skan complaint (&symfile_complaints, 2445169689Skan "Invalid .debug_ranges data (no base address)"); 2446169689Skan return 0; 2447169689Skan } 2448169689Skan 2449169689Skan range_beginning += base; 2450169689Skan range_end += base; 2451169689Skan 2452169689Skan /* FIXME: This is recording everything as a low-high 2453169689Skan segment of consecutive addresses. We should have a 2454169689Skan data structure for discontiguous block ranges 2455169689Skan instead. */ 2456169689Skan if (! low_set) 2457169689Skan { 245818334Speter low = range_beginning; 245918334Speter high = range_end; 246018334Speter low_set = 1; 246150397Sobrien } 246218334Speter else 246318334Speter { 246490075Sobrien if (range_beginning < low) 246518334Speter low = range_beginning; 246618334Speter if (range_end > high) 246718334Speter high = range_end; 246818334Speter } 246950397Sobrien } 247018334Speter 247118334Speter if (! low_set) 247250397Sobrien /* If the first entry is an end-of-list marker, the range 247318334Speter describes an empty scope, i.e. no instructions. */ 247418334Speter return 0; 2475169689Skan 247618334Speter ret = -1; 2477169689Skan } 247818334Speter } 247952284Sobrien 2480117395Skan if (high < low) 248152284Sobrien return 0; 248252284Sobrien 248318334Speter /* When using the GNU linker, .gnu.linkonce. sections are used to 248418334Speter eliminate duplicate copies of functions and vtables and such. 248518334Speter The linker will arbitrarily choose one and discard the others. 248650397Sobrien The AT_*_pc values for such functions refer to local labels in 248718334Speter these sections. If the section from that file was discarded, the 248852284Sobrien labels are not in the output, so the relocs get a value of 0. 248952284Sobrien If this is a discarded function, mark the pc bounds as invalid, 249052284Sobrien so that GDB will ignore it. */ 249152284Sobrien if (low == 0 && (bfd_get_file_flags (obfd) & HAS_RELOC) == 0) 249252284Sobrien return 0; 249318334Speter 249452284Sobrien *lowpc = low; 249552284Sobrien *highpc = high; 249652284Sobrien return ret; 249752284Sobrien} 249852284Sobrien 249918334Speter/* Get the low and high pc's represented by the scope DIE, and store 2500169689Skan them in *LOWPC and *HIGHPC. If the correct values can't be 250118334Speter determined, set *LOWPC to -1 and *HIGHPC to 0. */ 250252284Sobrien 250352284Sobrienstatic void 250452284Sobrienget_scope_pc_bounds (struct die_info *die, 250518334Speter CORE_ADDR *lowpc, CORE_ADDR *highpc, 250652284Sobrien struct dwarf2_cu *cu) 250718334Speter{ 250850397Sobrien CORE_ADDR best_low = (CORE_ADDR) -1; 250918334Speter CORE_ADDR best_high = (CORE_ADDR) 0; 251052284Sobrien CORE_ADDR current_low, current_high; 251152284Sobrien 251252284Sobrien if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu)) 251352284Sobrien { 251452284Sobrien best_low = current_low; 251552284Sobrien best_high = current_high; 251652284Sobrien } 251752284Sobrien else 251818334Speter { 251950397Sobrien struct die_info *child = die->child; 252018334Speter 252118334Speter while (child && child->tag) 2522169689Skan { 252318334Speter switch (child->tag) { 252490075Sobrien case DW_TAG_subprogram: 252590075Sobrien if (dwarf2_get_pc_bounds (child, ¤t_low, ¤t_high, cu)) 2526132718Skan { 252718334Speter best_low = min (best_low, current_low); 252818334Speter best_high = max (best_high, current_high); 252990075Sobrien } 253018334Speter break; 253118334Speter case DW_TAG_namespace: 2532132718Skan /* FIXME: carlton/2004-01-16: Should we do this for 253318334Speter DW_TAG_class_type/DW_TAG_structure_type, too? I think 253490075Sobrien that current GCC's always emit the DIEs corresponding 253590075Sobrien to definitions of methods of classes as children of a 253618334Speter DW_TAG_compile_unit or DW_TAG_namespace (as opposed to 253790075Sobrien the DIEs giving the declarations, which could be 253890075Sobrien anywhere). But I don't see any reason why the 253990075Sobrien standards says that they have to be there. */ 254090075Sobrien get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); 254190075Sobrien 254290075Sobrien if (current_low != ((CORE_ADDR) -1)) 254390075Sobrien { 254490075Sobrien best_low = min (best_low, current_low); 254590075Sobrien best_high = max (best_high, current_high); 254690075Sobrien } 254790075Sobrien break; 254890075Sobrien default: 254990075Sobrien /* Ignore. */ 255090075Sobrien break; 255190075Sobrien } 2552117395Skan 255390075Sobrien child = sibling_die (child); 255490075Sobrien } 255518334Speter } 255690075Sobrien 255790075Sobrien *lowpc = best_low; 255890075Sobrien *highpc = best_high; 255990075Sobrien} 2560132718Skan 256190075Sobrien/* Add an aggregate field to the field list. */ 2562117395Skan 256390075Sobrienstatic void 2564169689Skandwarf2_add_field (struct field_info *fip, struct die_info *die, 256590075Sobrien struct dwarf2_cu *cu) 2566117395Skan{ 256790075Sobrien struct objfile *objfile = cu->objfile; 2568117395Skan struct nextfield *new_field; 256990075Sobrien struct attribute *attr; 2570117395Skan struct field *fp; 257118334Speter char *fieldname = ""; 2572132718Skan 257390075Sobrien /* Allocate a new field list entry and link it in. */ 257418334Speter new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); 2575169689Skan make_cleanup (xfree, new_field); 257690075Sobrien memset (new_field, 0, sizeof (struct nextfield)); 257790075Sobrien new_field->next = fip->fields; 257890075Sobrien fip->fields = new_field; 257990075Sobrien fip->nfields++; 258018334Speter 258190075Sobrien /* Handle accessibility and virtuality of field. 258290075Sobrien The default accessibility for members is public, the default 258390075Sobrien accessibility for inheritance is private. */ 258490075Sobrien if (die->tag != DW_TAG_inheritance) 258590075Sobrien new_field->accessibility = DW_ACCESS_public; 258690075Sobrien else 258790075Sobrien new_field->accessibility = DW_ACCESS_private; 258890075Sobrien new_field->virtuality = DW_VIRTUALITY_none; 258990075Sobrien 2590169689Skan attr = dwarf2_attr (die, DW_AT_accessibility, cu); 259190075Sobrien if (attr) 259290075Sobrien new_field->accessibility = DW_UNSND (attr); 259390075Sobrien if (new_field->accessibility != DW_ACCESS_public) 259490075Sobrien fip->non_public_fields = 1; 259590075Sobrien attr = dwarf2_attr (die, DW_AT_virtuality, cu); 259690075Sobrien if (attr) 259790075Sobrien new_field->virtuality = DW_UNSND (attr); 259890075Sobrien 259990075Sobrien fp = &new_field->field; 260090075Sobrien 260190075Sobrien if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) 260290075Sobrien { 260390075Sobrien /* Data member other than a C++ static data member. */ 260490075Sobrien 2605132718Skan /* Get type of field. */ 260690075Sobrien fp->type = die_type (die, cu); 260790075Sobrien 260890075Sobrien FIELD_STATIC_KIND (*fp) = 0; 260990075Sobrien 261090075Sobrien /* Get bit size of field (zero if none). */ 261190075Sobrien attr = dwarf2_attr (die, DW_AT_bit_size, cu); 261290075Sobrien if (attr) 261390075Sobrien { 261418334Speter FIELD_BITSIZE (*fp) = DW_UNSND (attr); 261590075Sobrien } 261690075Sobrien else 2617169689Skan { 261890075Sobrien FIELD_BITSIZE (*fp) = 0; 261918334Speter } 262090075Sobrien 262190075Sobrien /* Get bit offset of field. */ 262290075Sobrien attr = dwarf2_attr (die, DW_AT_data_member_location, cu); 262390075Sobrien if (attr) 262490075Sobrien { 262590075Sobrien FIELD_BITPOS (*fp) = 262690075Sobrien decode_locdesc (DW_BLOCK (attr), cu) * bits_per_byte; 262790075Sobrien } 262890075Sobrien else 262990075Sobrien FIELD_BITPOS (*fp) = 0; 2630102780Skan attr = dwarf2_attr (die, DW_AT_bit_offset, cu); 263190075Sobrien if (attr) 263290075Sobrien { 263390075Sobrien if (BITS_BIG_ENDIAN) 263490075Sobrien { 263590075Sobrien /* For big endian bits, the DW_AT_bit_offset gives the 2636169689Skan additional bit offset from the MSB of the containing 2637169689Skan anonymous object to the MSB of the field. We don't 2638169689Skan have to do anything special since we don't need to 2639169689Skan know the size of the anonymous object. */ 2640169689Skan FIELD_BITPOS (*fp) += DW_UNSND (attr); 2641169689Skan } 2642169689Skan else 2643169689Skan { 2644169689Skan /* For little endian bits, compute the bit offset to the 2645169689Skan MSB of the anonymous object, subtract off the number of 2646169689Skan bits from the MSB of the field to the MSB of the 2647169689Skan object, and then subtract off the number of bits of 2648169689Skan the field itself. The result is the bit offset of 2649169689Skan the LSB of the field. */ 2650169689Skan int anonymous_size; 2651169689Skan int bit_offset = DW_UNSND (attr); 2652169689Skan 2653169689Skan attr = dwarf2_attr (die, DW_AT_byte_size, cu); 2654169689Skan if (attr) 2655169689Skan { 2656169689Skan /* The size of the anonymous object containing 2657169689Skan the bit field is explicit, so use the 2658169689Skan indicated size (in bytes). */ 265990075Sobrien anonymous_size = DW_UNSND (attr); 2660169689Skan } 266190075Sobrien else 2662169689Skan { 266390075Sobrien /* The size of the anonymous object containing 2664169689Skan the bit field must be inferred from the type 2665169689Skan attribute of the data member containing the 266690075Sobrien bit field. */ 266790075Sobrien anonymous_size = TYPE_LENGTH (fp->type); 2668169689Skan } 2669169689Skan FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte 267090075Sobrien - bit_offset - FIELD_BITSIZE (*fp); 2671169689Skan } 2672169689Skan } 2673169689Skan 2674169689Skan /* Get name of field. */ 267590075Sobrien attr = dwarf2_attr (die, DW_AT_name, cu); 2676169689Skan if (attr && DW_STRING (attr)) 2677169689Skan fieldname = DW_STRING (attr); 267818334Speter fp->name = obsavestring (fieldname, strlen (fieldname), 267918334Speter &objfile->objfile_obstack); 268018334Speter 268118334Speter /* Change accessibility for artificial fields (e.g. virtual table 2682169689Skan pointer or virtual base class pointer) to private. */ 2683169689Skan if (dwarf2_attr (die, DW_AT_artificial, cu)) 2684117395Skan { 268518334Speter new_field->accessibility = DW_ACCESS_private; 2686169689Skan fip->non_public_fields = 1; 268790075Sobrien } 2688169689Skan } 268918334Speter else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) 2690169689Skan { 2691169689Skan /* C++ static member. */ 269218334Speter 269318334Speter /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that 2694169689Skan is a declaration, but all versions of G++ as of this writing 269590075Sobrien (so through at least 3.2.1) incorrectly generate 2696169689Skan DW_TAG_variable tags. */ 269790075Sobrien 269890075Sobrien char *physname; 269990075Sobrien 2700169689Skan /* Get name of field. */ 2701117395Skan attr = dwarf2_attr (die, DW_AT_name, cu); 2702169689Skan if (attr && DW_STRING (attr)) 2703169689Skan fieldname = DW_STRING (attr); 2704169689Skan else 2705169689Skan return; 270618334Speter 2707169689Skan /* Get physical name. */ 2708169689Skan physname = dwarf2_linkage_name (die, cu); 2709169689Skan 2710169689Skan SET_FIELD_PHYSNAME (*fp, obsavestring (physname, strlen (physname), 2711169689Skan &objfile->objfile_obstack)); 2712169689Skan FIELD_TYPE (*fp) = die_type (die, cu); 2713169689Skan FIELD_NAME (*fp) = obsavestring (fieldname, strlen (fieldname), 271490075Sobrien &objfile->objfile_obstack); 271518334Speter } 2716169689Skan else if (die->tag == DW_TAG_inheritance) 2717169689Skan { 2718169689Skan /* C++ base class field. */ 2719169689Skan attr = dwarf2_attr (die, DW_AT_data_member_location, cu); 2720169689Skan if (attr) 2721169689Skan FIELD_BITPOS (*fp) = (decode_locdesc (DW_BLOCK (attr), cu) 2722169689Skan * bits_per_byte); 2723169689Skan FIELD_BITSIZE (*fp) = 0; 272490075Sobrien FIELD_STATIC_KIND (*fp) = 0; 272590075Sobrien FIELD_TYPE (*fp) = die_type (die, cu); 272690075Sobrien FIELD_NAME (*fp) = type_name_no_tag (fp->type); 272790075Sobrien fip->nbaseclasses++; 2728169689Skan } 272990075Sobrien} 2730169689Skan 2731169689Skan/* Create the vector of fields, and attach it to the type. */ 2732169689Skan 273390075Sobrienstatic void 273490075Sobriendwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, 273590075Sobrien struct dwarf2_cu *cu) 273690075Sobrien{ 273718334Speter int nfields = fip->nfields; 273890075Sobrien 273990075Sobrien /* Record the field count, allocate space for the array of fields, 274018334Speter and create blank accessibility bitfields if necessary. */ 2741117395Skan TYPE_NFIELDS (type) = nfields; 2742132718Skan TYPE_FIELDS (type) = (struct field *) 274318334Speter TYPE_ALLOC (type, sizeof (struct field) * nfields); 2744169689Skan memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); 274518334Speter 2746117395Skan if (fip->non_public_fields) 274790075Sobrien { 274818334Speter ALLOCATE_CPLUS_STRUCT_TYPE (type); 274990075Sobrien 275090075Sobrien TYPE_FIELD_PRIVATE_BITS (type) = 275190075Sobrien (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); 275290075Sobrien B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); 275318334Speter 275418334Speter TYPE_FIELD_PROTECTED_BITS (type) = 2755169689Skan (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); 2756169689Skan B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); 2757169689Skan 2758169689Skan TYPE_FIELD_IGNORE_BITS (type) = 2759169689Skan (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); 2760169689Skan B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); 2761169689Skan } 2762169689Skan 2763169689Skan /* If the type has baseclasses, allocate and clear a bit vector for 2764169689Skan TYPE_FIELD_VIRTUAL_BITS. */ 2765169689Skan if (fip->nbaseclasses) 2766169689Skan { 2767169689Skan int num_bytes = B_BYTES (fip->nbaseclasses); 2768169689Skan char *pointer; 2769169689Skan 2770169689Skan ALLOCATE_CPLUS_STRUCT_TYPE (type); 2771169689Skan pointer = (char *) TYPE_ALLOC (type, num_bytes); 2772169689Skan TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer; 2773169689Skan B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); 2774169689Skan TYPE_N_BASECLASSES (type) = fip->nbaseclasses; 2775169689Skan } 2776169689Skan 2777169689Skan /* Copy the saved-up fields into the field vector. Start from the head 2778169689Skan of the list, adding to the tail of the field array, so that they end 2779169689Skan up in the same order in the array in which they were added to the list. */ 2780169689Skan while (nfields-- > 0) 2781169689Skan { 2782169689Skan TYPE_FIELD (type, nfields) = fip->fields->field; 2783169689Skan switch (fip->fields->accessibility) 2784169689Skan { 2785169689Skan case DW_ACCESS_private: 2786169689Skan SET_TYPE_FIELD_PRIVATE (type, nfields); 2787169689Skan break; 2788169689Skan 2789169689Skan case DW_ACCESS_protected: 2790169689Skan SET_TYPE_FIELD_PROTECTED (type, nfields); 2791169689Skan break; 2792169689Skan 2793169689Skan case DW_ACCESS_public: 2794169689Skan break; 2795169689Skan 2796169689Skan default: 2797169689Skan /* Unknown accessibility. Complain and treat it as public. */ 2798169689Skan { 2799169689Skan complaint (&symfile_complaints, "unsupported accessibility %d", 2800169689Skan fip->fields->accessibility); 2801169689Skan } 2802169689Skan break; 2803169689Skan } 2804169689Skan if (nfields < fip->nbaseclasses) 2805169689Skan { 2806169689Skan switch (fip->fields->virtuality) 2807169689Skan { 2808169689Skan case DW_VIRTUALITY_virtual: 2809169689Skan case DW_VIRTUALITY_pure_virtual: 281090075Sobrien SET_TYPE_FIELD_VIRTUAL (type, nfields); 281190075Sobrien break; 2812169689Skan } 2813169689Skan } 281418334Speter fip->fields = fip->fields->next; 281518334Speter } 281690075Sobrien} 2817169689Skan 281890075Sobrien/* Add a member function to the proper fieldlist. */ 2819132718Skan 282018334Speterstatic void 2821117395Skandwarf2_add_member_fn (struct field_info *fip, struct die_info *die, 282290075Sobrien struct type *type, struct dwarf2_cu *cu) 2823169689Skan{ 2824169689Skan struct objfile *objfile = cu->objfile; 282518334Speter struct attribute *attr; 2826169689Skan struct fnfieldlist *flp; 2827169689Skan int i; 282818334Speter struct fn_field *fnp; 2829169689Skan char *fieldname; 2830169689Skan char *physname; 2831169689Skan struct nextfnfield *new_fnfield; 2832169689Skan 2833169689Skan /* Get name of member function. */ 2834169689Skan attr = dwarf2_attr (die, DW_AT_name, cu); 2835122180Skan if (attr && DW_STRING (attr)) 2836169689Skan fieldname = DW_STRING (attr); 2837122180Skan else 2838122180Skan return; 2839122180Skan 2840122180Skan /* Get the mangled name. */ 2841122180Skan physname = dwarf2_linkage_name (die, cu); 2842122180Skan 2843122180Skan /* Look up member function name in fieldlist. */ 2844122180Skan for (i = 0; i < fip->nfnfields; i++) 2845122180Skan { 2846117395Skan if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) 2847169689Skan break; 284890075Sobrien } 2849169689Skan 2850169689Skan /* Create new list element if necessary. */ 285190075Sobrien if (i < fip->nfnfields) 285218334Speter flp = &fip->fnfieldlists[i]; 285390075Sobrien else 285490075Sobrien { 2855169689Skan if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) 2856132718Skan { 285790075Sobrien fip->fnfieldlists = (struct fnfieldlist *) 2858169689Skan xrealloc (fip->fnfieldlists, 2859169689Skan (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) 286090075Sobrien * sizeof (struct fnfieldlist)); 286190075Sobrien if (fip->nfnfields == 0) 286290075Sobrien make_cleanup (free_current_contents, &fip->fnfieldlists); 286390075Sobrien } 286418334Speter flp = &fip->fnfieldlists[fip->nfnfields]; 286590075Sobrien flp->name = fieldname; 2866169689Skan flp->length = 0; 2867132718Skan flp->head = NULL; 286890075Sobrien fip->nfnfields++; 286918334Speter } 287090075Sobrien 287190075Sobrien /* Create a new member function field and chain it to the field list 287290075Sobrien entry. */ 2873169689Skan new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); 287490075Sobrien make_cleanup (xfree, new_fnfield); 2875169689Skan memset (new_fnfield, 0, sizeof (struct nextfnfield)); 287690075Sobrien new_fnfield->next = flp->head; 2877169689Skan flp->head = new_fnfield; 287890075Sobrien flp->length++; 2879169689Skan 288090075Sobrien /* Fill in the member function field info. */ 2881132718Skan fnp = &new_fnfield->fnfield; 2882169689Skan fnp->physname = obsavestring (physname, strlen (physname), 288390075Sobrien &objfile->objfile_obstack); 288490075Sobrien fnp->type = alloc_type (objfile); 288590075Sobrien if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC) 288650397Sobrien { 2887169689Skan int nparams = TYPE_NFIELDS (die->type); 288890075Sobrien 2889169689Skan /* TYPE is the domain of this method, and DIE->TYPE is the type 289090075Sobrien of the method itself (TYPE_CODE_METHOD). */ 289190075Sobrien smash_to_method_type (fnp->type, type, 2892169689Skan TYPE_TARGET_TYPE (die->type), 2893169689Skan TYPE_FIELDS (die->type), 2894169689Skan TYPE_NFIELDS (die->type), 289590075Sobrien TYPE_VARARGS (die->type)); 289618334Speter 2897132718Skan /* Handle static member functions. 2898169689Skan Dwarf2 has no clean way to discern C++ static and non-static 289990075Sobrien member functions. G++ helps GDB by marking the first 290018334Speter parameter for non-static member functions (which is the 290190075Sobrien this pointer) as artificial. We obtain this information 290290075Sobrien from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ 290390075Sobrien if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (die->type, 0) == 0) 290418334Speter fnp->voffset = VOFFSET_STATIC; 290590075Sobrien } 290690075Sobrien else 290790075Sobrien complaint (&symfile_complaints, "member function type missing for '%s'", 290890075Sobrien physname); 290990075Sobrien 291090075Sobrien /* Get fcontext from DW_AT_containing_type if present. */ 291118334Speter if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) 2912169689Skan fnp->fcontext = die_containing_type (die, cu); 2913169689Skan 291418334Speter /* dwarf2 doesn't have stubbed physical names, so the setting of is_const 2915169689Skan and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ 291690075Sobrien 2917132718Skan /* Get accessibility. */ 291890075Sobrien attr = dwarf2_attr (die, DW_AT_accessibility, cu); 291918334Speter if (attr) 2920122180Skan { 2921122180Skan switch (DW_UNSND (attr)) 2922122180Skan { 2923122180Skan case DW_ACCESS_private: 2924122180Skan fnp->is_private = 1; 2925122180Skan break; 292618334Speter case DW_ACCESS_protected: 2927132718Skan fnp->is_protected = 1; 2928132718Skan break; 2929132718Skan } 2930132718Skan } 2931132718Skan 2932132718Skan /* Check for artificial methods. */ 2933122180Skan attr = dwarf2_attr (die, DW_AT_artificial, cu); 2934122180Skan if (attr && DW_UNSND (attr) != 0) 2935122180Skan fnp->is_artificial = 1; 2936122180Skan 2937122180Skan /* Get index in virtual function table if it is a virtual member function. */ 2938132718Skan attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); 2939122180Skan if (attr) 2940122180Skan { 2941117395Skan /* Support the .debug_loc offsets */ 2942117395Skan if (attr_form_is_block (attr)) 2943117395Skan { 294490075Sobrien fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; 2945169689Skan } 294690075Sobrien else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) 294790075Sobrien { 2948169689Skan dwarf2_complex_location_expr_complaint (); 294918334Speter } 295018334Speter else 295190075Sobrien { 295290075Sobrien dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", 2953169689Skan fieldname); 2954169689Skan } 295518334Speter } 295690075Sobrien} 295718334Speter 2958122180Skan/* Create the vector of member function fields, and attach it to the type. */ 2959122180Skan 2960122180Skanstatic void 2961122180Skandwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, 2962169689Skan struct dwarf2_cu *cu) 296390075Sobrien{ 296490075Sobrien struct fnfieldlist *flp; 296590075Sobrien int total_length = 0; 296690075Sobrien int i; 296790075Sobrien 296818334Speter ALLOCATE_CPLUS_STRUCT_TYPE (type); 296990075Sobrien TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) 2970169689Skan TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); 297118334Speter 297290075Sobrien for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) 297318334Speter { 2974122180Skan struct nextfnfield *nfp = flp->head; 2975122180Skan struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); 2976122180Skan int k; 2977122180Skan 2978122180Skan TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; 2979122180Skan TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; 2980122180Skan fn_flp->fn_fields = (struct fn_field *) 2981122180Skan TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); 2982122180Skan for (k = flp->length; (k--, nfp); nfp = nfp->next) 2983122180Skan fn_flp->fn_fields[k] = nfp->fnfield; 2984122180Skan 2985122180Skan total_length += flp->length; 2986122180Skan } 2987169689Skan 298890075Sobrien TYPE_NFN_FIELDS (type) = fip->nfnfields; 298990075Sobrien TYPE_NFN_FIELDS_TOTAL (type) = total_length; 299090075Sobrien} 299190075Sobrien 2992169689Skan/* Called when we find the DIE that starts a structure or union scope 299390075Sobrien (definition) to process all dies that define the members of the 2994122180Skan structure or union. 2995169689Skan 299618334Speter NOTE: we need to call struct_type regardless of whether or not the 299790075Sobrien DIE has an at_name attribute, since it might be an anonymous 299818334Speter structure or union. This gets the type entered into our set of 2999169689Skan user defined types. 300018334Speter 300150397Sobrien However, if the structure is incomplete (an opaque struct/union) 300290075Sobrien then suppress creating a symbol table entry for it since gdb only 300390075Sobrien wants to find the one with the complete definition. Note that if 300490075Sobrien it is complete, we just call new_symbol, which does it's own 300590075Sobrien checking about whether the struct/union is anonymous or not (and 3006169689Skan suppresses creating a symbol table entry itself). */ 3007169689Skan 300818334Speterstatic void 3009117395Skanread_structure_type (struct die_info *die, struct dwarf2_cu *cu) 3010117395Skan{ 301190075Sobrien struct objfile *objfile = cu->objfile; 3012169689Skan struct type *type; 301318334Speter struct attribute *attr; 301490075Sobrien const char *previous_prefix = processing_current_prefix; 301590075Sobrien struct cleanup *back_to = NULL; 301618334Speter 301790075Sobrien if (die->type) 301890075Sobrien return; 301990075Sobrien 302018334Speter type = alloc_type (objfile); 302190075Sobrien 302290075Sobrien INIT_CPLUS_SPECIFIC (type); 3023169689Skan attr = dwarf2_attr (die, DW_AT_name, cu); 302418334Speter if (attr && DW_STRING (attr)) 302590075Sobrien { 3026169689Skan if (cu->language == language_cplus) 3027169689Skan { 3028117395Skan char *new_prefix = determine_class_name (die, cu); 3029117395Skan TYPE_TAG_NAME (type) = obsavestring (new_prefix, 303090075Sobrien strlen (new_prefix), 3031117395Skan &objfile->objfile_obstack); 303290075Sobrien back_to = make_cleanup (xfree, new_prefix); 303390075Sobrien processing_current_prefix = new_prefix; 303418334Speter } 303590075Sobrien else 3036169689Skan { 303790075Sobrien TYPE_TAG_NAME (type) = DW_STRING (attr); 3038169689Skan } 3039169689Skan } 3040169689Skan 3041117395Skan if (die->tag == DW_TAG_structure_type) 304218334Speter { 304396263Sobrien TYPE_CODE (type) = TYPE_CODE_STRUCT; 304490075Sobrien } 304590075Sobrien else if (die->tag == DW_TAG_union_type) 304618334Speter { 3047169689Skan TYPE_CODE (type) = TYPE_CODE_UNION; 3048169689Skan } 3049169689Skan else 3050169689Skan { 3051169689Skan /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT 3052169689Skan in gdbtypes.h. */ 305318334Speter TYPE_CODE (type) = TYPE_CODE_CLASS; 3054169689Skan } 3055169689Skan 3056169689Skan attr = dwarf2_attr (die, DW_AT_byte_size, cu); 3057169689Skan if (attr) 3058169689Skan { 3059169689Skan TYPE_LENGTH (type) = DW_UNSND (attr); 3060169689Skan } 3061169689Skan else 3062169689Skan { 3063169689Skan TYPE_LENGTH (type) = 0; 3064169689Skan } 3065169689Skan 3066169689Skan /* We need to add the type field to the die immediately so we don't 3067169689Skan infinitely recurse when dealing with pointers to the structure 3068169689Skan type within the structure itself. */ 3069169689Skan die->type = type; 3070169689Skan 3071169689Skan if (die->child != NULL && ! die_is_declaration (die, cu)) 3072169689Skan { 3073169689Skan struct field_info fi; 3074169689Skan struct die_info *child_die; 3075169689Skan struct cleanup *back_to = make_cleanup (null_cleanup, NULL); 3076169689Skan 3077169689Skan memset (&fi, 0, sizeof (struct field_info)); 3078169689Skan 3079169689Skan child_die = die->child; 3080169689Skan 3081169689Skan while (child_die && child_die->tag) 3082169689Skan { 3083169689Skan if (child_die->tag == DW_TAG_member 3084169689Skan || child_die->tag == DW_TAG_variable) 3085169689Skan { 3086169689Skan /* NOTE: carlton/2002-11-05: A C++ static data member 3087169689Skan should be a DW_TAG_member that is a declaration, but 3088169689Skan all versions of G++ as of this writing (so through at 3089169689Skan least 3.2.1) incorrectly generate DW_TAG_variable 3090169689Skan tags for them instead. */ 3091169689Skan dwarf2_add_field (&fi, child_die, cu); 3092169689Skan } 3093169689Skan else if (child_die->tag == DW_TAG_subprogram) 3094169689Skan { 3095169689Skan /* C++ member function. */ 3096169689Skan read_type_die (child_die, cu); 3097169689Skan dwarf2_add_member_fn (&fi, child_die, type, cu); 3098169689Skan } 3099169689Skan else if (child_die->tag == DW_TAG_inheritance) 3100169689Skan { 3101169689Skan /* C++ base class field. */ 3102169689Skan dwarf2_add_field (&fi, child_die, cu); 3103169689Skan } 3104169689Skan child_die = sibling_die (child_die); 3105169689Skan } 3106169689Skan 3107169689Skan /* Attach fields and member functions to the type. */ 3108169689Skan if (fi.nfields) 3109169689Skan dwarf2_attach_fields_to_type (&fi, type, cu); 3110169689Skan if (fi.nfnfields) 3111169689Skan { 3112169689Skan dwarf2_attach_fn_fields_to_type (&fi, type, cu); 3113169689Skan 3114169689Skan /* Get the type which refers to the base class (possibly this 3115169689Skan class itself) which contains the vtable pointer for the current 3116169689Skan class from the DW_AT_containing_type attribute. */ 3117169689Skan 3118169689Skan if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) 3119169689Skan { 3120169689Skan struct type *t = die_containing_type (die, cu); 3121169689Skan 3122169689Skan TYPE_VPTR_BASETYPE (type) = t; 3123169689Skan if (type == t) 3124169689Skan { 3125169689Skan static const char vptr_name[] = 3126169689Skan {'_', 'v', 'p', 't', 'r', '\0'}; 3127169689Skan int i; 3128169689Skan 3129169689Skan /* Our own class provides vtbl ptr. */ 3130169689Skan for (i = TYPE_NFIELDS (t) - 1; 3131169689Skan i >= TYPE_N_BASECLASSES (t); 3132169689Skan --i) 3133169689Skan { 3134169689Skan char *fieldname = TYPE_FIELD_NAME (t, i); 3135169689Skan 3136169689Skan if ((strncmp (fieldname, vptr_name, 3137169689Skan strlen (vptr_name) - 1) 3138169689Skan == 0) 3139169689Skan && is_cplus_marker (fieldname[strlen (vptr_name)])) 3140169689Skan { 3141169689Skan TYPE_VPTR_FIELDNO (type) = i; 3142169689Skan break; 3143169689Skan } 3144169689Skan } 3145169689Skan 3146169689Skan /* Complain if virtual function table field not found. */ 3147169689Skan if (i < TYPE_N_BASECLASSES (t)) 3148169689Skan complaint (&symfile_complaints, 3149169689Skan "virtual function table pointer not found when defining class '%s'", 3150169689Skan TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : 3151169689Skan ""); 3152169689Skan } 3153169689Skan else 3154169689Skan { 3155169689Skan TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); 3156169689Skan } 3157169689Skan } 3158169689Skan } 315918334Speter 316018334Speter do_cleanups (back_to); 3161169689Skan } 3162169689Skan else 3163169689Skan { 3164169689Skan /* No children, must be stub. */ 3165169689Skan TYPE_FLAGS (type) |= TYPE_FLAG_STUB; 3166169689Skan } 3167169689Skan 3168169689Skan processing_current_prefix = previous_prefix; 3169169689Skan if (back_to != NULL) 3170169689Skan do_cleanups (back_to); 3171117395Skan} 3172169689Skan 3173169689Skanstatic void 3174169689Skanprocess_structure_scope (struct die_info *die, struct dwarf2_cu *cu) 3175169689Skan{ 3176169689Skan struct objfile *objfile = cu->objfile; 3177169689Skan const char *previous_prefix = processing_current_prefix; 3178169689Skan struct die_info *child_die = die->child; 3179169689Skan 3180169689Skan if (TYPE_TAG_NAME (die->type) != NULL) 3181169689Skan processing_current_prefix = TYPE_TAG_NAME (die->type); 3182169689Skan 3183169689Skan /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its 3184169689Skan snapshots) has been known to create a die giving a declaration 3185169689Skan for a class that has, as a child, a die giving a definition for a 3186169689Skan nested class. So we have to process our children even if the 3187169689Skan current die is a declaration. Normally, of course, a declaration 3188169689Skan won't have any children at all. */ 3189169689Skan 3190169689Skan while (child_die != NULL && child_die->tag) 3191169689Skan { 3192169689Skan if (child_die->tag == DW_TAG_member 3193169689Skan || child_die->tag == DW_TAG_variable 3194169689Skan || child_die->tag == DW_TAG_inheritance) 3195169689Skan { 3196169689Skan /* Do nothing. */ 3197169689Skan } 3198169689Skan else 3199169689Skan process_die (child_die, cu); 3200169689Skan 3201169689Skan child_die = sibling_die (child_die); 3202169689Skan } 3203169689Skan 3204169689Skan if (die->child != NULL && ! die_is_declaration (die, cu)) 3205169689Skan new_symbol (die, die->type, cu); 3206169689Skan 3207169689Skan processing_current_prefix = previous_prefix; 3208169689Skan} 3209169689Skan 3210169689Skan/* Given a DW_AT_enumeration_type die, set its type. We do not 3211169689Skan complete the type's fields yet, or create any symbols. */ 3212 3213static void 3214read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) 3215{ 3216 struct objfile *objfile = cu->objfile; 3217 struct type *type; 3218 struct attribute *attr; 3219 3220 if (die->type) 3221 return; 3222 3223 type = alloc_type (objfile); 3224 3225 TYPE_CODE (type) = TYPE_CODE_ENUM; 3226 attr = dwarf2_attr (die, DW_AT_name, cu); 3227 if (attr && DW_STRING (attr)) 3228 { 3229 const char *name = DW_STRING (attr); 3230 3231 if (processing_has_namespace_info) 3232 { 3233 TYPE_TAG_NAME (type) = obconcat (&objfile->objfile_obstack, 3234 processing_current_prefix, 3235 processing_current_prefix[0] == '\0' 3236 ? "" : "::", 3237 name); 3238 } 3239 else 3240 { 3241 TYPE_TAG_NAME (type) = obsavestring (name, strlen (name), 3242 &objfile->objfile_obstack); 3243 } 3244 } 3245 3246 attr = dwarf2_attr (die, DW_AT_byte_size, cu); 3247 if (attr) 3248 { 3249 TYPE_LENGTH (type) = DW_UNSND (attr); 3250 } 3251 else 3252 { 3253 TYPE_LENGTH (type) = 0; 3254 } 3255 3256 die->type = type; 3257} 3258 3259/* Determine the name of the type represented by DIE, which should be 3260 a named C++ compound type. Return the name in question; the caller 3261 is responsible for xfree()'ing it. */ 3262 3263static char * 3264determine_class_name (struct die_info *die, struct dwarf2_cu *cu) 3265{ 3266 struct cleanup *back_to = NULL; 3267 struct die_info *spec_die = die_specification (die, cu); 3268 char *new_prefix = NULL; 3269 3270 /* If this is the definition of a class that is declared by another 3271 die, then processing_current_prefix may not be accurate; see 3272 read_func_scope for a similar example. */ 3273 if (spec_die != NULL) 3274 { 3275 char *specification_prefix = determine_prefix (spec_die, cu); 3276 processing_current_prefix = specification_prefix; 3277 back_to = make_cleanup (xfree, specification_prefix); 3278 } 3279 3280 /* If we don't have namespace debug info, guess the name by trying 3281 to demangle the names of members, just like we did in 3282 add_partial_structure. */ 3283 if (!processing_has_namespace_info) 3284 { 3285 struct die_info *child; 3286 3287 for (child = die->child; 3288 child != NULL && child->tag != 0; 3289 child = sibling_die (child)) 3290 { 3291 if (child->tag == DW_TAG_subprogram) 3292 { 3293 new_prefix = class_name_from_physname (dwarf2_linkage_name 3294 (child, cu)); 3295 3296 if (new_prefix != NULL) 3297 break; 3298 } 3299 } 3300 } 3301 3302 if (new_prefix == NULL) 3303 { 3304 const char *name = dwarf2_name (die, cu); 3305 new_prefix = typename_concat (processing_current_prefix, 3306 name ? name : "<<anonymous>>"); 3307 } 3308 3309 if (back_to != NULL) 3310 do_cleanups (back_to); 3311 3312 return new_prefix; 3313} 3314 3315/* Given a pointer to a die which begins an enumeration, process all 3316 the dies that define the members of the enumeration, and create the 3317 symbol for the enumeration type. 3318 3319 NOTE: We reverse the order of the element list. */ 3320 3321static void 3322process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) 3323{ 3324 struct objfile *objfile = cu->objfile; 3325 struct die_info *child_die; 3326 struct field *fields; 3327 struct attribute *attr; 3328 struct symbol *sym; 3329 int num_fields; 3330 int unsigned_enum = 1; 3331 3332 num_fields = 0; 3333 fields = NULL; 3334 if (die->child != NULL) 3335 { 3336 child_die = die->child; 3337 while (child_die && child_die->tag) 3338 { 3339 if (child_die->tag != DW_TAG_enumerator) 3340 { 3341 process_die (child_die, cu); 3342 } 3343 else 3344 { 3345 attr = dwarf2_attr (child_die, DW_AT_name, cu); 3346 if (attr) 3347 { 3348 sym = new_symbol (child_die, die->type, cu); 3349 if (SYMBOL_VALUE (sym) < 0) 3350 unsigned_enum = 0; 3351 3352 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) 3353 { 3354 fields = (struct field *) 3355 xrealloc (fields, 3356 (num_fields + DW_FIELD_ALLOC_CHUNK) 3357 * sizeof (struct field)); 3358 } 3359 3360 FIELD_NAME (fields[num_fields]) = DEPRECATED_SYMBOL_NAME (sym); 3361 FIELD_TYPE (fields[num_fields]) = NULL; 3362 FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym); 3363 FIELD_BITSIZE (fields[num_fields]) = 0; 3364 FIELD_STATIC_KIND (fields[num_fields]) = 0; 3365 3366 num_fields++; 3367 } 3368 } 3369 3370 child_die = sibling_die (child_die); 3371 } 3372 3373 if (num_fields) 3374 { 3375 TYPE_NFIELDS (die->type) = num_fields; 3376 TYPE_FIELDS (die->type) = (struct field *) 3377 TYPE_ALLOC (die->type, sizeof (struct field) * num_fields); 3378 memcpy (TYPE_FIELDS (die->type), fields, 3379 sizeof (struct field) * num_fields); 3380 xfree (fields); 3381 } 3382 if (unsigned_enum) 3383 TYPE_FLAGS (die->type) |= TYPE_FLAG_UNSIGNED; 3384 } 3385 3386 new_symbol (die, die->type, cu); 3387} 3388 3389/* Extract all information from a DW_TAG_array_type DIE and put it in 3390 the DIE's type field. For now, this only handles one dimensional 3391 arrays. */ 3392 3393static void 3394read_array_type (struct die_info *die, struct dwarf2_cu *cu) 3395{ 3396 struct objfile *objfile = cu->objfile; 3397 struct die_info *child_die; 3398 struct type *type = NULL; 3399 struct type *element_type, *range_type, *index_type; 3400 struct type **range_types = NULL; 3401 struct attribute *attr; 3402 int ndim = 0; 3403 struct cleanup *back_to; 3404 3405 /* Return if we've already decoded this type. */ 3406 if (die->type) 3407 { 3408 return; 3409 } 3410 3411 element_type = die_type (die, cu); 3412 3413 /* Irix 6.2 native cc creates array types without children for 3414 arrays with unspecified length. */ 3415 if (die->child == NULL) 3416 { 3417 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu); 3418 range_type = create_range_type (NULL, index_type, 0, -1); 3419 die->type = create_array_type (NULL, element_type, range_type); 3420 return; 3421 } 3422 3423 back_to = make_cleanup (null_cleanup, NULL); 3424 child_die = die->child; 3425 while (child_die && child_die->tag) 3426 { 3427 if (child_die->tag == DW_TAG_subrange_type) 3428 { 3429 read_subrange_type (child_die, cu); 3430 3431 if (child_die->type != NULL) 3432 { 3433 /* The range type was succesfully read. Save it for 3434 the array type creation. */ 3435 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) 3436 { 3437 range_types = (struct type **) 3438 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) 3439 * sizeof (struct type *)); 3440 if (ndim == 0) 3441 make_cleanup (free_current_contents, &range_types); 3442 } 3443 range_types[ndim++] = child_die->type; 3444 } 3445 } 3446 child_die = sibling_die (child_die); 3447 } 3448 3449 /* Dwarf2 dimensions are output from left to right, create the 3450 necessary array types in backwards order. */ 3451 type = element_type; 3452 while (ndim-- > 0) 3453 type = create_array_type (NULL, type, range_types[ndim]); 3454 3455 /* Understand Dwarf2 support for vector types (like they occur on 3456 the PowerPC w/ AltiVec). Gcc just adds another attribute to the 3457 array type. This is not part of the Dwarf2/3 standard yet, but a 3458 custom vendor extension. The main difference between a regular 3459 array and the vector variant is that vectors are passed by value 3460 to functions. */ 3461 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); 3462 if (attr) 3463 TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR; 3464 3465 do_cleanups (back_to); 3466 3467 /* Install the type in the die. */ 3468 die->type = type; 3469} 3470 3471/* First cut: install each common block member as a global variable. */ 3472 3473static void 3474read_common_block (struct die_info *die, struct dwarf2_cu *cu) 3475{ 3476 struct die_info *child_die; 3477 struct attribute *attr; 3478 struct symbol *sym; 3479 CORE_ADDR base = (CORE_ADDR) 0; 3480 3481 attr = dwarf2_attr (die, DW_AT_location, cu); 3482 if (attr) 3483 { 3484 /* Support the .debug_loc offsets */ 3485 if (attr_form_is_block (attr)) 3486 { 3487 base = decode_locdesc (DW_BLOCK (attr), cu); 3488 } 3489 else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) 3490 { 3491 dwarf2_complex_location_expr_complaint (); 3492 } 3493 else 3494 { 3495 dwarf2_invalid_attrib_class_complaint ("DW_AT_location", 3496 "common block member"); 3497 } 3498 } 3499 if (die->child != NULL) 3500 { 3501 child_die = die->child; 3502 while (child_die && child_die->tag) 3503 { 3504 sym = new_symbol (child_die, NULL, cu); 3505 attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu); 3506 if (attr) 3507 { 3508 SYMBOL_VALUE_ADDRESS (sym) = 3509 base + decode_locdesc (DW_BLOCK (attr), cu); 3510 add_symbol_to_list (sym, &global_symbols); 3511 } 3512 child_die = sibling_die (child_die); 3513 } 3514 } 3515} 3516 3517/* Read a C++ namespace. */ 3518 3519static void 3520read_namespace (struct die_info *die, struct dwarf2_cu *cu) 3521{ 3522 struct objfile *objfile = cu->objfile; 3523 const char *previous_prefix = processing_current_prefix; 3524 const char *name; 3525 int is_anonymous; 3526 struct die_info *current_die; 3527 3528 name = namespace_name (die, &is_anonymous, cu); 3529 3530 /* Now build the name of the current namespace. */ 3531 3532 if (previous_prefix[0] == '\0') 3533 { 3534 processing_current_prefix = name; 3535 } 3536 else 3537 { 3538 /* We need temp_name around because processing_current_prefix 3539 is a const char *. */ 3540 char *temp_name = alloca (strlen (previous_prefix) 3541 + 2 + strlen(name) + 1); 3542 strcpy (temp_name, previous_prefix); 3543 strcat (temp_name, "::"); 3544 strcat (temp_name, name); 3545 3546 processing_current_prefix = temp_name; 3547 } 3548 3549 /* Add a symbol associated to this if we haven't seen the namespace 3550 before. Also, add a using directive if it's an anonymous 3551 namespace. */ 3552 3553 if (dwarf2_extension (die, cu) == NULL) 3554 { 3555 struct type *type; 3556 3557 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct, 3558 this cast will hopefully become unnecessary. */ 3559 type = init_type (TYPE_CODE_NAMESPACE, 0, 0, 3560 (char *) processing_current_prefix, 3561 objfile); 3562 TYPE_TAG_NAME (type) = TYPE_NAME (type); 3563 3564 new_symbol (die, type, cu); 3565 die->type = type; 3566 3567 if (is_anonymous) 3568 cp_add_using_directive (processing_current_prefix, 3569 strlen (previous_prefix), 3570 strlen (processing_current_prefix)); 3571 } 3572 3573 if (die->child != NULL) 3574 { 3575 struct die_info *child_die = die->child; 3576 3577 while (child_die && child_die->tag) 3578 { 3579 process_die (child_die, cu); 3580 child_die = sibling_die (child_die); 3581 } 3582 } 3583 3584 processing_current_prefix = previous_prefix; 3585} 3586 3587/* Return the name of the namespace represented by DIE. Set 3588 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous 3589 namespace. */ 3590 3591static const char * 3592namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) 3593{ 3594 struct die_info *current_die; 3595 const char *name = NULL; 3596 3597 /* Loop through the extensions until we find a name. */ 3598 3599 for (current_die = die; 3600 current_die != NULL; 3601 current_die = dwarf2_extension (die, cu)) 3602 { 3603 name = dwarf2_name (current_die, cu); 3604 if (name != NULL) 3605 break; 3606 } 3607 3608 /* Is it an anonymous namespace? */ 3609 3610 *is_anonymous = (name == NULL); 3611 if (*is_anonymous) 3612 name = "(anonymous namespace)"; 3613 3614 return name; 3615} 3616 3617/* Extract all information from a DW_TAG_pointer_type DIE and add to 3618 the user defined type vector. */ 3619 3620static void 3621read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) 3622{ 3623 struct comp_unit_head *cu_header = &cu->header; 3624 struct type *type; 3625 struct attribute *attr_byte_size; 3626 struct attribute *attr_address_class; 3627 int byte_size, addr_class; 3628 3629 if (die->type) 3630 { 3631 return; 3632 } 3633 3634 type = lookup_pointer_type (die_type (die, cu)); 3635 3636 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); 3637 if (attr_byte_size) 3638 byte_size = DW_UNSND (attr_byte_size); 3639 else 3640 byte_size = cu_header->addr_size; 3641 3642 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); 3643 if (attr_address_class) 3644 addr_class = DW_UNSND (attr_address_class); 3645 else 3646 addr_class = DW_ADDR_none; 3647 3648 /* If the pointer size or address class is different than the 3649 default, create a type variant marked as such and set the 3650 length accordingly. */ 3651 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) 3652 { 3653 if (ADDRESS_CLASS_TYPE_FLAGS_P ()) 3654 { 3655 int type_flags; 3656 3657 type_flags = ADDRESS_CLASS_TYPE_FLAGS (byte_size, addr_class); 3658 gdb_assert ((type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0); 3659 type = make_type_with_address_space (type, type_flags); 3660 } 3661 else if (TYPE_LENGTH (type) != byte_size) 3662 { 3663 complaint (&symfile_complaints, "invalid pointer size %d", byte_size); 3664 } 3665 else { 3666 /* Should we also complain about unhandled address classes? */ 3667 } 3668 } 3669 3670 TYPE_LENGTH (type) = byte_size; 3671 die->type = type; 3672} 3673 3674/* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to 3675 the user defined type vector. */ 3676 3677static void 3678read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) 3679{ 3680 struct objfile *objfile = cu->objfile; 3681 struct type *type; 3682 struct type *to_type; 3683 struct type *domain; 3684 3685 if (die->type) 3686 { 3687 return; 3688 } 3689 3690 type = alloc_type (objfile); 3691 to_type = die_type (die, cu); 3692 domain = die_containing_type (die, cu); 3693 smash_to_member_type (type, domain, to_type); 3694 3695 die->type = type; 3696} 3697 3698/* Extract all information from a DW_TAG_reference_type DIE and add to 3699 the user defined type vector. */ 3700 3701static void 3702read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) 3703{ 3704 struct comp_unit_head *cu_header = &cu->header; 3705 struct type *type; 3706 struct attribute *attr; 3707 3708 if (die->type) 3709 { 3710 return; 3711 } 3712 3713 type = lookup_reference_type (die_type (die, cu)); 3714 attr = dwarf2_attr (die, DW_AT_byte_size, cu); 3715 if (attr) 3716 { 3717 TYPE_LENGTH (type) = DW_UNSND (attr); 3718 } 3719 else 3720 { 3721 TYPE_LENGTH (type) = cu_header->addr_size; 3722 } 3723 die->type = type; 3724} 3725 3726static void 3727read_tag_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) 3728{ 3729 struct objfile *objfile = cu->objfile; 3730 struct type *type; 3731 struct attribute *attr; 3732 3733 if (die->type) 3734 { 3735 return; 3736 } 3737 3738 type = alloc_type (objfile); 3739 TYPE_LENGTH (type) = 0; 3740 attr = dwarf2_attr (die, DW_AT_name, cu); 3741 if (attr && DW_STRING (attr)) 3742 TYPE_NAME (type) = DW_STRING (attr); 3743 3744 die->type = type; 3745} 3746 3747static void 3748read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) 3749{ 3750 struct type *base_type; 3751 3752 if (die->type) 3753 { 3754 return; 3755 } 3756 3757 base_type = die_type (die, cu); 3758 die->type = make_cvr_type (1, TYPE_VOLATILE (base_type), 3759 TYPE_RESTRICT (base_type), base_type, 0); 3760} 3761 3762static void 3763read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) 3764{ 3765 struct type *base_type; 3766 3767 if (die->type) 3768 { 3769 return; 3770 } 3771 3772 base_type = die_type (die, cu); 3773 die->type = make_cvr_type (TYPE_CONST (base_type), 1, 3774 TYPE_RESTRICT (base_type), base_type, 0); 3775} 3776 3777static void 3778read_tag_restrict_type (struct die_info *die, struct dwarf2_cu *cu) 3779{ 3780 struct type *base_type; 3781 3782 if (die->type) 3783 { 3784 return; 3785 } 3786 3787 base_type = die_type (die, cu); 3788 die->type = make_cvr_type (TYPE_CONST (base_type), TYPE_VOLATILE (base_type), 3789 1, base_type, 0); 3790} 3791 3792/* Extract all information from a DW_TAG_string_type DIE and add to 3793 the user defined type vector. It isn't really a user defined type, 3794 but it behaves like one, with other DIE's using an AT_user_def_type 3795 attribute to reference it. */ 3796 3797static void 3798read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) 3799{ 3800 struct objfile *objfile = cu->objfile; 3801 struct type *type, *range_type, *index_type, *char_type; 3802 struct attribute *attr; 3803 unsigned int length; 3804 3805 if (die->type) 3806 { 3807 return; 3808 } 3809 3810 attr = dwarf2_attr (die, DW_AT_string_length, cu); 3811 if (attr) 3812 { 3813 length = DW_UNSND (attr); 3814 } 3815 else 3816 { 3817 /* check for the DW_AT_byte_size attribute */ 3818 attr = dwarf2_attr (die, DW_AT_byte_size, cu); 3819 if (attr) 3820 { 3821 length = DW_UNSND (attr); 3822 } 3823 else 3824 { 3825 length = 1; 3826 } 3827 } 3828 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu); 3829 range_type = create_range_type (NULL, index_type, 1, length); 3830 if (cu->language == language_fortran) 3831 { 3832 /* Need to create a unique string type for bounds 3833 information */ 3834 type = create_string_type (0, range_type); 3835 } 3836 else 3837 { 3838 char_type = dwarf2_fundamental_type (objfile, FT_CHAR, cu); 3839 type = create_string_type (char_type, range_type); 3840 } 3841 die->type = type; 3842} 3843 3844/* Handle DIES due to C code like: 3845 3846 struct foo 3847 { 3848 int (*funcp)(int a, long l); 3849 int b; 3850 }; 3851 3852 ('funcp' generates a DW_TAG_subroutine_type DIE) 3853 */ 3854 3855static void 3856read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) 3857{ 3858 struct type *type; /* Type that this function returns */ 3859 struct type *ftype; /* Function that returns above type */ 3860 struct attribute *attr; 3861 3862 /* Decode the type that this subroutine returns */ 3863 if (die->type) 3864 { 3865 return; 3866 } 3867 type = die_type (die, cu); 3868 ftype = lookup_function_type (type); 3869 3870 /* All functions in C++ have prototypes. */ 3871 attr = dwarf2_attr (die, DW_AT_prototyped, cu); 3872 if ((attr && (DW_UNSND (attr) != 0)) 3873 || cu->language == language_cplus) 3874 TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED; 3875 3876 if (die->child != NULL) 3877 { 3878 struct die_info *child_die; 3879 int nparams = 0; 3880 int iparams = 0; 3881 3882 /* Count the number of parameters. 3883 FIXME: GDB currently ignores vararg functions, but knows about 3884 vararg member functions. */ 3885 child_die = die->child; 3886 while (child_die && child_die->tag) 3887 { 3888 if (child_die->tag == DW_TAG_formal_parameter) 3889 nparams++; 3890 else if (child_die->tag == DW_TAG_unspecified_parameters) 3891 TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS; 3892 child_die = sibling_die (child_die); 3893 } 3894 3895 /* Allocate storage for parameters and fill them in. */ 3896 TYPE_NFIELDS (ftype) = nparams; 3897 TYPE_FIELDS (ftype) = (struct field *) 3898 TYPE_ALLOC (ftype, nparams * sizeof (struct field)); 3899 3900 child_die = die->child; 3901 while (child_die && child_die->tag) 3902 { 3903 if (child_die->tag == DW_TAG_formal_parameter) 3904 { 3905 /* Dwarf2 has no clean way to discern C++ static and non-static 3906 member functions. G++ helps GDB by marking the first 3907 parameter for non-static member functions (which is the 3908 this pointer) as artificial. We pass this information 3909 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */ 3910 attr = dwarf2_attr (child_die, DW_AT_artificial, cu); 3911 if (attr) 3912 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); 3913 else 3914 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; 3915 TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu); 3916 iparams++; 3917 } 3918 child_die = sibling_die (child_die); 3919 } 3920 } 3921 3922 die->type = ftype; 3923} 3924 3925static void 3926read_typedef (struct die_info *die, struct dwarf2_cu *cu) 3927{ 3928 struct objfile *objfile = cu->objfile; 3929 struct attribute *attr; 3930 char *name = NULL; 3931 3932 if (!die->type) 3933 { 3934 attr = dwarf2_attr (die, DW_AT_name, cu); 3935 if (attr && DW_STRING (attr)) 3936 { 3937 name = DW_STRING (attr); 3938 } 3939 die->type = init_type (TYPE_CODE_TYPEDEF, 0, TYPE_FLAG_TARGET_STUB, name, objfile); 3940 TYPE_TARGET_TYPE (die->type) = die_type (die, cu); 3941 } 3942} 3943 3944/* Find a representation of a given base type and install 3945 it in the TYPE field of the die. */ 3946 3947static void 3948read_base_type (struct die_info *die, struct dwarf2_cu *cu) 3949{ 3950 struct objfile *objfile = cu->objfile; 3951 struct type *type; 3952 struct attribute *attr; 3953 int encoding = 0, size = 0; 3954 3955 /* If we've already decoded this die, this is a no-op. */ 3956 if (die->type) 3957 { 3958 return; 3959 } 3960 3961 attr = dwarf2_attr (die, DW_AT_encoding, cu); 3962 if (attr) 3963 { 3964 encoding = DW_UNSND (attr); 3965 } 3966 attr = dwarf2_attr (die, DW_AT_byte_size, cu); 3967 if (attr) 3968 { 3969 size = DW_UNSND (attr); 3970 } 3971 attr = dwarf2_attr (die, DW_AT_name, cu); 3972 if (attr && DW_STRING (attr)) 3973 { 3974 enum type_code code = TYPE_CODE_INT; 3975 int type_flags = 0; 3976 3977 switch (encoding) 3978 { 3979 case DW_ATE_address: 3980 /* Turn DW_ATE_address into a void * pointer. */ 3981 code = TYPE_CODE_PTR; 3982 type_flags |= TYPE_FLAG_UNSIGNED; 3983 break; 3984 case DW_ATE_boolean: 3985 code = TYPE_CODE_BOOL; 3986 type_flags |= TYPE_FLAG_UNSIGNED; 3987 break; 3988 case DW_ATE_complex_float: 3989 code = TYPE_CODE_COMPLEX; 3990 break; 3991 case DW_ATE_float: 3992 code = TYPE_CODE_FLT; 3993 break; 3994 case DW_ATE_signed: 3995 case DW_ATE_signed_char: 3996 break; 3997 case DW_ATE_unsigned: 3998 case DW_ATE_unsigned_char: 3999 type_flags |= TYPE_FLAG_UNSIGNED; 4000 break; 4001 default: 4002 complaint (&symfile_complaints, "unsupported DW_AT_encoding: '%s'", 4003 dwarf_type_encoding_name (encoding)); 4004 break; 4005 } 4006 type = init_type (code, size, type_flags, DW_STRING (attr), objfile); 4007 if (encoding == DW_ATE_address) 4008 TYPE_TARGET_TYPE (type) = dwarf2_fundamental_type (objfile, FT_VOID, 4009 cu); 4010 else if (encoding == DW_ATE_complex_float) 4011 { 4012 if (size == 32) 4013 TYPE_TARGET_TYPE (type) 4014 = dwarf2_fundamental_type (objfile, FT_EXT_PREC_FLOAT, cu); 4015 else if (size == 16) 4016 TYPE_TARGET_TYPE (type) 4017 = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu); 4018 else if (size == 8) 4019 TYPE_TARGET_TYPE (type) 4020 = dwarf2_fundamental_type (objfile, FT_FLOAT, cu); 4021 } 4022 } 4023 else 4024 { 4025 type = dwarf_base_type (encoding, size, cu); 4026 } 4027 die->type = type; 4028} 4029 4030/* Read the given DW_AT_subrange DIE. */ 4031 4032static void 4033read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) 4034{ 4035 struct type *base_type; 4036 struct type *range_type; 4037 struct attribute *attr; 4038 int low = 0; 4039 int high = -1; 4040 4041 /* If we have already decoded this die, then nothing more to do. */ 4042 if (die->type) 4043 return; 4044 4045 base_type = die_type (die, cu); 4046 if (base_type == NULL) 4047 { 4048 complaint (&symfile_complaints, 4049 "DW_AT_type missing from DW_TAG_subrange_type"); 4050 return; 4051 } 4052 4053 if (TYPE_CODE (base_type) == TYPE_CODE_VOID) 4054 base_type = alloc_type (NULL); 4055 4056 if (cu->language == language_fortran) 4057 { 4058 /* FORTRAN implies a lower bound of 1, if not given. */ 4059 low = 1; 4060 } 4061 4062 attr = dwarf2_attr (die, DW_AT_lower_bound, cu); 4063 if (attr) 4064 low = dwarf2_get_attr_constant_value (attr, 0); 4065 4066 attr = dwarf2_attr (die, DW_AT_upper_bound, cu); 4067 if (attr) 4068 { 4069 if (attr->form == DW_FORM_block1) 4070 { 4071 /* GCC encodes arrays with unspecified or dynamic length 4072 with a DW_FORM_block1 attribute. 4073 FIXME: GDB does not yet know how to handle dynamic 4074 arrays properly, treat them as arrays with unspecified 4075 length for now. 4076 4077 FIXME: jimb/2003-09-22: GDB does not really know 4078 how to handle arrays of unspecified length 4079 either; we just represent them as zero-length 4080 arrays. Choose an appropriate upper bound given 4081 the lower bound we've computed above. */ 4082 high = low - 1; 4083 } 4084 else 4085 high = dwarf2_get_attr_constant_value (attr, 1); 4086 } 4087 4088 range_type = create_range_type (NULL, base_type, low, high); 4089 4090 attr = dwarf2_attr (die, DW_AT_name, cu); 4091 if (attr && DW_STRING (attr)) 4092 TYPE_NAME (range_type) = DW_STRING (attr); 4093 4094 attr = dwarf2_attr (die, DW_AT_byte_size, cu); 4095 if (attr) 4096 TYPE_LENGTH (range_type) = DW_UNSND (attr); 4097 4098 die->type = range_type; 4099} 4100 4101 4102/* Read a whole compilation unit into a linked list of dies. */ 4103 4104static struct die_info * 4105read_comp_unit (char *info_ptr, bfd *abfd, struct dwarf2_cu *cu) 4106{ 4107 /* Reset die reference table; we are 4108 building new ones now. */ 4109 dwarf2_empty_hash_tables (); 4110 4111 return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL); 4112} 4113 4114/* Read a single die and all its descendents. Set the die's sibling 4115 field to NULL; set other fields in the die correctly, and set all 4116 of the descendents' fields correctly. Set *NEW_INFO_PTR to the 4117 location of the info_ptr after reading all of those dies. PARENT 4118 is the parent of the die in question. */ 4119 4120static struct die_info * 4121read_die_and_children (char *info_ptr, bfd *abfd, 4122 struct dwarf2_cu *cu, 4123 char **new_info_ptr, 4124 struct die_info *parent) 4125{ 4126 struct die_info *die; 4127 char *cur_ptr; 4128 int has_children; 4129 4130 cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children); 4131 store_in_ref_table (die->offset, die); 4132 4133 if (has_children) 4134 { 4135 die->child = read_die_and_siblings (cur_ptr, abfd, cu, 4136 new_info_ptr, die); 4137 } 4138 else 4139 { 4140 die->child = NULL; 4141 *new_info_ptr = cur_ptr; 4142 } 4143 4144 die->sibling = NULL; 4145 die->parent = parent; 4146 return die; 4147} 4148 4149/* Read a die, all of its descendents, and all of its siblings; set 4150 all of the fields of all of the dies correctly. Arguments are as 4151 in read_die_and_children. */ 4152 4153static struct die_info * 4154read_die_and_siblings (char *info_ptr, bfd *abfd, 4155 struct dwarf2_cu *cu, 4156 char **new_info_ptr, 4157 struct die_info *parent) 4158{ 4159 struct die_info *first_die, *last_sibling; 4160 char *cur_ptr; 4161 4162 cur_ptr = info_ptr; 4163 first_die = last_sibling = NULL; 4164 4165 while (1) 4166 { 4167 struct die_info *die 4168 = read_die_and_children (cur_ptr, abfd, cu, &cur_ptr, parent); 4169 4170 if (!first_die) 4171 { 4172 first_die = die; 4173 } 4174 else 4175 { 4176 last_sibling->sibling = die; 4177 } 4178 4179 if (die->tag == 0) 4180 { 4181 *new_info_ptr = cur_ptr; 4182 return first_die; 4183 } 4184 else 4185 { 4186 last_sibling = die; 4187 } 4188 } 4189} 4190 4191/* Free a linked list of dies. */ 4192 4193static void 4194free_die_list (struct die_info *dies) 4195{ 4196 struct die_info *die, *next; 4197 4198 die = dies; 4199 while (die) 4200 { 4201 if (die->child != NULL) 4202 free_die_list (die->child); 4203 next = die->sibling; 4204 xfree (die->attrs); 4205 xfree (die); 4206 die = next; 4207 } 4208} 4209 4210static void 4211do_free_die_list_cleanup (void *dies) 4212{ 4213 free_die_list (dies); 4214} 4215 4216static struct cleanup * 4217make_cleanup_free_die_list (struct die_info *dies) 4218{ 4219 return make_cleanup (do_free_die_list_cleanup, dies); 4220} 4221 4222 4223/* Read the contents of the section at OFFSET and of size SIZE from the 4224 object file specified by OBJFILE into the objfile_obstack and return it. */ 4225 4226char * 4227dwarf2_read_section (struct objfile *objfile, asection *sectp) 4228{ 4229 bfd *abfd = objfile->obfd; 4230 char *buf, *retbuf; 4231 bfd_size_type size = bfd_get_section_size (sectp); 4232 4233 if (size == 0) 4234 return NULL; 4235 4236 buf = (char *) obstack_alloc (&objfile->objfile_obstack, size); 4237 retbuf 4238 = (char *) symfile_relocate_debug_section (abfd, sectp, (bfd_byte *) buf); 4239 if (retbuf != NULL) 4240 return retbuf; 4241 4242 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 4243 || bfd_bread (buf, size, abfd) != size) 4244 error ("Dwarf Error: Can't read DWARF data from '%s'", 4245 bfd_get_filename (abfd)); 4246 4247 return buf; 4248} 4249 4250/* In DWARF version 2, the description of the debugging information is 4251 stored in a separate .debug_abbrev section. Before we read any 4252 dies from a section we read in all abbreviations and install them 4253 in a hash table. */ 4254 4255static void 4256dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) 4257{ 4258 struct comp_unit_head *cu_header = &cu->header; 4259 char *abbrev_ptr; 4260 struct abbrev_info *cur_abbrev; 4261 unsigned int abbrev_number, bytes_read, abbrev_name; 4262 unsigned int abbrev_form, hash_number; 4263 4264 /* Initialize dwarf2 abbrevs */ 4265 memset (cu_header->dwarf2_abbrevs, 0, 4266 ABBREV_HASH_SIZE*sizeof (struct abbrev_info *)); 4267 4268 abbrev_ptr = dwarf_abbrev_buffer + cu_header->abbrev_offset; 4269 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); 4270 abbrev_ptr += bytes_read; 4271 4272 /* loop until we reach an abbrev number of 0 */ 4273 while (abbrev_number) 4274 { 4275 cur_abbrev = dwarf_alloc_abbrev (); 4276 4277 /* read in abbrev header */ 4278 cur_abbrev->number = abbrev_number; 4279 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); 4280 abbrev_ptr += bytes_read; 4281 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); 4282 abbrev_ptr += 1; 4283 4284 /* now read in declarations */ 4285 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); 4286 abbrev_ptr += bytes_read; 4287 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); 4288 abbrev_ptr += bytes_read; 4289 while (abbrev_name) 4290 { 4291 if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0) 4292 { 4293 cur_abbrev->attrs = (struct attr_abbrev *) 4294 xrealloc (cur_abbrev->attrs, 4295 (cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK) 4296 * sizeof (struct attr_abbrev)); 4297 } 4298 cur_abbrev->attrs[cur_abbrev->num_attrs].name = abbrev_name; 4299 cur_abbrev->attrs[cur_abbrev->num_attrs++].form = abbrev_form; 4300 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); 4301 abbrev_ptr += bytes_read; 4302 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); 4303 abbrev_ptr += bytes_read; 4304 } 4305 4306 hash_number = abbrev_number % ABBREV_HASH_SIZE; 4307 cur_abbrev->next = cu_header->dwarf2_abbrevs[hash_number]; 4308 cu_header->dwarf2_abbrevs[hash_number] = cur_abbrev; 4309 4310 /* Get next abbreviation. 4311 Under Irix6 the abbreviations for a compilation unit are not 4312 always properly terminated with an abbrev number of 0. 4313 Exit loop if we encounter an abbreviation which we have 4314 already read (which means we are about to read the abbreviations 4315 for the next compile unit) or if the end of the abbreviation 4316 table is reached. */ 4317 if ((unsigned int) (abbrev_ptr - dwarf_abbrev_buffer) 4318 >= dwarf_abbrev_size) 4319 break; 4320 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); 4321 abbrev_ptr += bytes_read; 4322 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) 4323 break; 4324 } 4325} 4326 4327/* Empty the abbrev table for a new compilation unit. */ 4328 4329static void 4330dwarf2_empty_abbrev_table (void *ptr_to_abbrevs_table) 4331{ 4332 int i; 4333 struct abbrev_info *abbrev, *next; 4334 struct abbrev_info **abbrevs; 4335 4336 abbrevs = (struct abbrev_info **)ptr_to_abbrevs_table; 4337 4338 for (i = 0; i < ABBREV_HASH_SIZE; ++i) 4339 { 4340 next = NULL; 4341 abbrev = abbrevs[i]; 4342 while (abbrev) 4343 { 4344 next = abbrev->next; 4345 xfree (abbrev->attrs); 4346 xfree (abbrev); 4347 abbrev = next; 4348 } 4349 abbrevs[i] = NULL; 4350 } 4351} 4352 4353/* Lookup an abbrev_info structure in the abbrev hash table. */ 4354 4355static struct abbrev_info * 4356dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) 4357{ 4358 struct comp_unit_head *cu_header = &cu->header; 4359 unsigned int hash_number; 4360 struct abbrev_info *abbrev; 4361 4362 hash_number = number % ABBREV_HASH_SIZE; 4363 abbrev = cu_header->dwarf2_abbrevs[hash_number]; 4364 4365 while (abbrev) 4366 { 4367 if (abbrev->number == number) 4368 return abbrev; 4369 else 4370 abbrev = abbrev->next; 4371 } 4372 return NULL; 4373} 4374 4375/* Read a minimal amount of information into the minimal die structure. */ 4376 4377static char * 4378read_partial_die (struct partial_die_info *part_die, bfd *abfd, 4379 char *info_ptr, struct dwarf2_cu *cu) 4380{ 4381 unsigned int abbrev_number, bytes_read, i; 4382 struct abbrev_info *abbrev; 4383 struct attribute attr; 4384 struct attribute spec_attr; 4385 int found_spec_attr = 0; 4386 int has_low_pc_attr = 0; 4387 int has_high_pc_attr = 0; 4388 4389 *part_die = zeroed_partial_die; 4390 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); 4391 info_ptr += bytes_read; 4392 if (!abbrev_number) 4393 return info_ptr; 4394 4395 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); 4396 if (!abbrev) 4397 { 4398 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number, 4399 bfd_get_filename (abfd)); 4400 } 4401 part_die->offset = info_ptr - dwarf_info_buffer; 4402 part_die->tag = abbrev->tag; 4403 part_die->has_children = abbrev->has_children; 4404 part_die->abbrev = abbrev_number; 4405 4406 for (i = 0; i < abbrev->num_attrs; ++i) 4407 { 4408 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); 4409 4410 /* Store the data if it is of an attribute we want to keep in a 4411 partial symbol table. */ 4412 switch (attr.name) 4413 { 4414 case DW_AT_name: 4415 4416 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */ 4417 if (part_die->name == NULL) 4418 part_die->name = DW_STRING (&attr); 4419 break; 4420 case DW_AT_MIPS_linkage_name: 4421 part_die->name = DW_STRING (&attr); 4422 break; 4423 case DW_AT_low_pc: 4424 has_low_pc_attr = 1; 4425 part_die->lowpc = DW_ADDR (&attr); 4426 break; 4427 case DW_AT_high_pc: 4428 has_high_pc_attr = 1; 4429 part_die->highpc = DW_ADDR (&attr); 4430 break; 4431 case DW_AT_location: 4432 /* Support the .debug_loc offsets */ 4433 if (attr_form_is_block (&attr)) 4434 { 4435 part_die->locdesc = DW_BLOCK (&attr); 4436 } 4437 else if (attr.form == DW_FORM_data4 || attr.form == DW_FORM_data8) 4438 { 4439 dwarf2_complex_location_expr_complaint (); 4440 } 4441 else 4442 { 4443 dwarf2_invalid_attrib_class_complaint ("DW_AT_location", 4444 "partial symbol information"); 4445 } 4446 break; 4447 case DW_AT_language: 4448 part_die->language = DW_UNSND (&attr); 4449 break; 4450 case DW_AT_external: 4451 part_die->is_external = DW_UNSND (&attr); 4452 break; 4453 case DW_AT_declaration: 4454 part_die->is_declaration = DW_UNSND (&attr); 4455 break; 4456 case DW_AT_type: 4457 part_die->has_type = 1; 4458 break; 4459 case DW_AT_abstract_origin: 4460 case DW_AT_specification: 4461 found_spec_attr = 1; 4462 spec_attr = attr; 4463 break; 4464 case DW_AT_sibling: 4465 /* Ignore absolute siblings, they might point outside of 4466 the current compile unit. */ 4467 if (attr.form == DW_FORM_ref_addr) 4468 complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling"); 4469 else 4470 part_die->sibling = 4471 dwarf_info_buffer + dwarf2_get_ref_die_offset (&attr, cu); 4472 break; 4473 default: 4474 break; 4475 } 4476 } 4477 4478 /* If we found a reference attribute and the die has no name, try 4479 to find a name in the referred to die. */ 4480 4481 if (found_spec_attr && part_die->name == NULL) 4482 { 4483 struct partial_die_info spec_die; 4484 char *spec_ptr; 4485 4486 spec_ptr = dwarf_info_buffer 4487 + dwarf2_get_ref_die_offset (&spec_attr, cu); 4488 read_partial_die (&spec_die, abfd, spec_ptr, cu); 4489 if (spec_die.name) 4490 { 4491 part_die->name = spec_die.name; 4492 4493 /* Copy DW_AT_external attribute if it is set. */ 4494 if (spec_die.is_external) 4495 part_die->is_external = spec_die.is_external; 4496 } 4497 } 4498 4499 /* When using the GNU linker, .gnu.linkonce. sections are used to 4500 eliminate duplicate copies of functions and vtables and such. 4501 The linker will arbitrarily choose one and discard the others. 4502 The AT_*_pc values for such functions refer to local labels in 4503 these sections. If the section from that file was discarded, the 4504 labels are not in the output, so the relocs get a value of 0. 4505 If this is a discarded function, mark the pc bounds as invalid, 4506 so that GDB will ignore it. */ 4507 if (has_low_pc_attr && has_high_pc_attr 4508 && part_die->lowpc < part_die->highpc 4509 && (part_die->lowpc != 0 4510 || (bfd_get_file_flags (abfd) & HAS_RELOC))) 4511 part_die->has_pc_info = 1; 4512 return info_ptr; 4513} 4514 4515/* Read the die from the .debug_info section buffer. Set DIEP to 4516 point to a newly allocated die with its information, except for its 4517 child, sibling, and parent fields. Set HAS_CHILDREN to tell 4518 whether the die has children or not. */ 4519 4520static char * 4521read_full_die (struct die_info **diep, bfd *abfd, char *info_ptr, 4522 struct dwarf2_cu *cu, int *has_children) 4523{ 4524 unsigned int abbrev_number, bytes_read, i, offset; 4525 struct abbrev_info *abbrev; 4526 struct die_info *die; 4527 4528 offset = info_ptr - dwarf_info_buffer; 4529 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); 4530 info_ptr += bytes_read; 4531 if (!abbrev_number) 4532 { 4533 die = dwarf_alloc_die (); 4534 die->tag = 0; 4535 die->abbrev = abbrev_number; 4536 die->type = NULL; 4537 *diep = die; 4538 *has_children = 0; 4539 return info_ptr; 4540 } 4541 4542 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); 4543 if (!abbrev) 4544 { 4545 error ("Dwarf Error: could not find abbrev number %d [in module %s]", 4546 abbrev_number, 4547 bfd_get_filename (abfd)); 4548 } 4549 die = dwarf_alloc_die (); 4550 die->offset = offset; 4551 die->tag = abbrev->tag; 4552 die->abbrev = abbrev_number; 4553 die->type = NULL; 4554 4555 die->num_attrs = abbrev->num_attrs; 4556 die->attrs = (struct attribute *) 4557 xmalloc (die->num_attrs * sizeof (struct attribute)); 4558 4559 for (i = 0; i < abbrev->num_attrs; ++i) 4560 { 4561 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], 4562 abfd, info_ptr, cu); 4563 } 4564 4565 *diep = die; 4566 *has_children = abbrev->has_children; 4567 return info_ptr; 4568} 4569 4570/* Read an attribute value described by an attribute form. */ 4571 4572static char * 4573read_attribute_value (struct attribute *attr, unsigned form, 4574 bfd *abfd, char *info_ptr, 4575 struct dwarf2_cu *cu) 4576{ 4577 struct comp_unit_head *cu_header = &cu->header; 4578 unsigned int bytes_read; 4579 struct dwarf_block *blk; 4580 4581 attr->form = form; 4582 switch (form) 4583 { 4584 case DW_FORM_addr: 4585 case DW_FORM_ref_addr: 4586 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); 4587 info_ptr += bytes_read; 4588 break; 4589 case DW_FORM_block2: 4590 blk = dwarf_alloc_block (); 4591 blk->size = read_2_bytes (abfd, info_ptr); 4592 info_ptr += 2; 4593 blk->data = read_n_bytes (abfd, info_ptr, blk->size); 4594 info_ptr += blk->size; 4595 DW_BLOCK (attr) = blk; 4596 break; 4597 case DW_FORM_block4: 4598 blk = dwarf_alloc_block (); 4599 blk->size = read_4_bytes (abfd, info_ptr); 4600 info_ptr += 4; 4601 blk->data = read_n_bytes (abfd, info_ptr, blk->size); 4602 info_ptr += blk->size; 4603 DW_BLOCK (attr) = blk; 4604 break; 4605 case DW_FORM_data2: 4606 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); 4607 info_ptr += 2; 4608 break; 4609 case DW_FORM_data4: 4610 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); 4611 info_ptr += 4; 4612 break; 4613 case DW_FORM_data8: 4614 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); 4615 info_ptr += 8; 4616 break; 4617 case DW_FORM_string: 4618 DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read); 4619 info_ptr += bytes_read; 4620 break; 4621 case DW_FORM_strp: 4622 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, 4623 &bytes_read); 4624 info_ptr += bytes_read; 4625 break; 4626 case DW_FORM_block: 4627 blk = dwarf_alloc_block (); 4628 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); 4629 info_ptr += bytes_read; 4630 blk->data = read_n_bytes (abfd, info_ptr, blk->size); 4631 info_ptr += blk->size; 4632 DW_BLOCK (attr) = blk; 4633 break; 4634 case DW_FORM_block1: 4635 blk = dwarf_alloc_block (); 4636 blk->size = read_1_byte (abfd, info_ptr); 4637 info_ptr += 1; 4638 blk->data = read_n_bytes (abfd, info_ptr, blk->size); 4639 info_ptr += blk->size; 4640 DW_BLOCK (attr) = blk; 4641 break; 4642 case DW_FORM_data1: 4643 DW_UNSND (attr) = read_1_byte (abfd, info_ptr); 4644 info_ptr += 1; 4645 break; 4646 case DW_FORM_flag: 4647 DW_UNSND (attr) = read_1_byte (abfd, info_ptr); 4648 info_ptr += 1; 4649 break; 4650 case DW_FORM_flag_present: 4651 DW_UNSND (attr) = 1; 4652 break; 4653 case DW_FORM_sdata: 4654 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); 4655 info_ptr += bytes_read; 4656 break; 4657 case DW_FORM_udata: 4658 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); 4659 info_ptr += bytes_read; 4660 break; 4661 case DW_FORM_ref1: 4662 DW_UNSND (attr) = read_1_byte (abfd, info_ptr); 4663 info_ptr += 1; 4664 break; 4665 case DW_FORM_ref2: 4666 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); 4667 info_ptr += 2; 4668 break; 4669 case DW_FORM_ref4: 4670 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); 4671 info_ptr += 4; 4672 break; 4673 case DW_FORM_ref8: 4674 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); 4675 info_ptr += 8; 4676 break; 4677 case DW_FORM_ref_udata: 4678 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); 4679 info_ptr += bytes_read; 4680 break; 4681 case DW_FORM_indirect: 4682 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); 4683 info_ptr += bytes_read; 4684 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); 4685 break; 4686 default: 4687 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]", 4688 dwarf_form_name (form), 4689 bfd_get_filename (abfd)); 4690 } 4691 return info_ptr; 4692} 4693 4694/* Read an attribute described by an abbreviated attribute. */ 4695 4696static char * 4697read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, 4698 bfd *abfd, char *info_ptr, struct dwarf2_cu *cu) 4699{ 4700 attr->name = abbrev->name; 4701 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); 4702} 4703 4704/* read dwarf information from a buffer */ 4705 4706static unsigned int 4707read_1_byte (bfd *abfd, char *buf) 4708{ 4709 return bfd_get_8 (abfd, (bfd_byte *) buf); 4710} 4711 4712static int 4713read_1_signed_byte (bfd *abfd, char *buf) 4714{ 4715 return bfd_get_signed_8 (abfd, (bfd_byte *) buf); 4716} 4717 4718static unsigned int 4719read_2_bytes (bfd *abfd, char *buf) 4720{ 4721 return bfd_get_16 (abfd, (bfd_byte *) buf); 4722} 4723 4724static int 4725read_2_signed_bytes (bfd *abfd, char *buf) 4726{ 4727 return bfd_get_signed_16 (abfd, (bfd_byte *) buf); 4728} 4729 4730static unsigned int 4731read_4_bytes (bfd *abfd, char *buf) 4732{ 4733 return bfd_get_32 (abfd, (bfd_byte *) buf); 4734} 4735 4736static int 4737read_4_signed_bytes (bfd *abfd, char *buf) 4738{ 4739 return bfd_get_signed_32 (abfd, (bfd_byte *) buf); 4740} 4741 4742static unsigned long 4743read_8_bytes (bfd *abfd, char *buf) 4744{ 4745 return bfd_get_64 (abfd, (bfd_byte *) buf); 4746} 4747 4748static CORE_ADDR 4749read_address (bfd *abfd, char *buf, struct dwarf2_cu *cu, int *bytes_read) 4750{ 4751 struct comp_unit_head *cu_header = &cu->header; 4752 CORE_ADDR retval = 0; 4753 4754 if (cu_header->signed_addr_p) 4755 { 4756 switch (cu_header->addr_size) 4757 { 4758 case 2: 4759 retval = bfd_get_signed_16 (abfd, (bfd_byte *) buf); 4760 break; 4761 case 4: 4762 retval = bfd_get_signed_32 (abfd, (bfd_byte *) buf); 4763 break; 4764 case 8: 4765 retval = bfd_get_signed_64 (abfd, (bfd_byte *) buf); 4766 break; 4767 default: 4768 internal_error (__FILE__, __LINE__, 4769 "read_address: bad switch, signed [in module %s]", 4770 bfd_get_filename (abfd)); 4771 } 4772 } 4773 else 4774 { 4775 switch (cu_header->addr_size) 4776 { 4777 case 2: 4778 retval = bfd_get_16 (abfd, (bfd_byte *) buf); 4779 break; 4780 case 4: 4781 retval = bfd_get_32 (abfd, (bfd_byte *) buf); 4782 break; 4783 case 8: 4784 retval = bfd_get_64 (abfd, (bfd_byte *) buf); 4785 break; 4786 default: 4787 internal_error (__FILE__, __LINE__, 4788 "read_address: bad switch, unsigned [in module %s]", 4789 bfd_get_filename (abfd)); 4790 } 4791 } 4792 4793 *bytes_read = cu_header->addr_size; 4794 return retval; 4795} 4796 4797/* Read the initial length from a section. The (draft) DWARF 3 4798 specification allows the initial length to take up either 4 bytes 4799 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 4800 bytes describe the length and all offsets will be 8 bytes in length 4801 instead of 4. 4802 4803 An older, non-standard 64-bit format is also handled by this 4804 function. The older format in question stores the initial length 4805 as an 8-byte quantity without an escape value. Lengths greater 4806 than 2^32 aren't very common which means that the initial 4 bytes 4807 is almost always zero. Since a length value of zero doesn't make 4808 sense for the 32-bit format, this initial zero can be considered to 4809 be an escape value which indicates the presence of the older 64-bit 4810 format. As written, the code can't detect (old format) lengths 4811 greater than 4GB. If it becomes necessary to handle lengths somewhat 4812 larger than 4GB, we could allow other small values (such as the 4813 non-sensical values of 1, 2, and 3) to also be used as escape values 4814 indicating the presence of the old format. 4815 4816 The value returned via bytes_read should be used to increment 4817 the relevant pointer after calling read_initial_length(). 4818 4819 As a side effect, this function sets the fields initial_length_size 4820 and offset_size in cu_header to the values appropriate for the 4821 length field. (The format of the initial length field determines 4822 the width of file offsets to be fetched later with fetch_offset().) 4823 4824 [ Note: read_initial_length() and read_offset() are based on the 4825 document entitled "DWARF Debugging Information Format", revision 4826 3, draft 8, dated November 19, 2001. This document was obtained 4827 from: 4828 4829 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf 4830 4831 This document is only a draft and is subject to change. (So beware.) 4832 4833 Details regarding the older, non-standard 64-bit format were 4834 determined empirically by examining 64-bit ELF files produced 4835 by the SGI toolchain on an IRIX 6.5 machine. 4836 4837 - Kevin, July 16, 2002 4838 ] */ 4839 4840static LONGEST 4841read_initial_length (bfd *abfd, char *buf, struct comp_unit_head *cu_header, 4842 int *bytes_read) 4843{ 4844 LONGEST retval = 0; 4845 4846 retval = bfd_get_32 (abfd, (bfd_byte *) buf); 4847 4848 if (retval == 0xffffffff) 4849 { 4850 retval = bfd_get_64 (abfd, (bfd_byte *) buf + 4); 4851 *bytes_read = 12; 4852 if (cu_header != NULL) 4853 { 4854 cu_header->initial_length_size = 12; 4855 cu_header->offset_size = 8; 4856 } 4857 } 4858 else if (retval == 0) 4859 { 4860 /* Handle (non-standard) 64-bit DWARF2 formats such as that used 4861 by IRIX. */ 4862 retval = bfd_get_64 (abfd, (bfd_byte *) buf); 4863 *bytes_read = 8; 4864 if (cu_header != NULL) 4865 { 4866 cu_header->initial_length_size = 8; 4867 cu_header->offset_size = 8; 4868 } 4869 } 4870 else 4871 { 4872 *bytes_read = 4; 4873 if (cu_header != NULL) 4874 { 4875 cu_header->initial_length_size = 4; 4876 cu_header->offset_size = 4; 4877 } 4878 } 4879 4880 return retval; 4881} 4882 4883/* Read an offset from the data stream. The size of the offset is 4884 given by cu_header->offset_size. */ 4885 4886static LONGEST 4887read_offset (bfd *abfd, char *buf, const struct comp_unit_head *cu_header, 4888 int *bytes_read) 4889{ 4890 LONGEST retval = 0; 4891 4892 switch (cu_header->offset_size) 4893 { 4894 case 4: 4895 retval = bfd_get_32 (abfd, (bfd_byte *) buf); 4896 *bytes_read = 4; 4897 break; 4898 case 8: 4899 retval = bfd_get_64 (abfd, (bfd_byte *) buf); 4900 *bytes_read = 8; 4901 break; 4902 default: 4903 internal_error (__FILE__, __LINE__, 4904 "read_offset: bad switch [in module %s]", 4905 bfd_get_filename (abfd)); 4906 } 4907 4908 return retval; 4909} 4910 4911static char * 4912read_n_bytes (bfd *abfd, char *buf, unsigned int size) 4913{ 4914 /* If the size of a host char is 8 bits, we can return a pointer 4915 to the buffer, otherwise we have to copy the data to a buffer 4916 allocated on the temporary obstack. */ 4917 gdb_assert (HOST_CHAR_BIT == 8); 4918 return buf; 4919} 4920 4921static char * 4922read_string (bfd *abfd, char *buf, unsigned int *bytes_read_ptr) 4923{ 4924 /* If the size of a host char is 8 bits, we can return a pointer 4925 to the string, otherwise we have to copy the string to a buffer 4926 allocated on the temporary obstack. */ 4927 gdb_assert (HOST_CHAR_BIT == 8); 4928 if (*buf == '\0') 4929 { 4930 *bytes_read_ptr = 1; 4931 return NULL; 4932 } 4933 *bytes_read_ptr = strlen (buf) + 1; 4934 return buf; 4935} 4936 4937static char * 4938read_indirect_string (bfd *abfd, char *buf, 4939 const struct comp_unit_head *cu_header, 4940 unsigned int *bytes_read_ptr) 4941{ 4942 LONGEST str_offset = read_offset (abfd, buf, cu_header, 4943 (int *) bytes_read_ptr); 4944 4945 if (dwarf_str_buffer == NULL) 4946 { 4947 error ("DW_FORM_strp used without .debug_str section [in module %s]", 4948 bfd_get_filename (abfd)); 4949 return NULL; 4950 } 4951 if (str_offset >= dwarf_str_size) 4952 { 4953 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]", 4954 bfd_get_filename (abfd)); 4955 return NULL; 4956 } 4957 gdb_assert (HOST_CHAR_BIT == 8); 4958 if (dwarf_str_buffer[str_offset] == '\0') 4959 return NULL; 4960 return dwarf_str_buffer + str_offset; 4961} 4962 4963static unsigned long 4964read_unsigned_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr) 4965{ 4966 unsigned long result; 4967 unsigned int num_read; 4968 int i, shift; 4969 unsigned char byte; 4970 4971 result = 0; 4972 shift = 0; 4973 num_read = 0; 4974 i = 0; 4975 while (1) 4976 { 4977 byte = bfd_get_8 (abfd, (bfd_byte *) buf); 4978 buf++; 4979 num_read++; 4980 result |= ((unsigned long)(byte & 127) << shift); 4981 if ((byte & 128) == 0) 4982 { 4983 break; 4984 } 4985 shift += 7; 4986 } 4987 *bytes_read_ptr = num_read; 4988 return result; 4989} 4990 4991static long 4992read_signed_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr) 4993{ 4994 long result; 4995 int i, shift, size, num_read; 4996 unsigned char byte; 4997 4998 result = 0; 4999 shift = 0; 5000 size = 32; 5001 num_read = 0; 5002 i = 0; 5003 while (1) 5004 { 5005 byte = bfd_get_8 (abfd, (bfd_byte *) buf); 5006 buf++; 5007 num_read++; 5008 result |= ((long)(byte & 127) << shift); 5009 shift += 7; 5010 if ((byte & 128) == 0) 5011 { 5012 break; 5013 } 5014 } 5015 if ((shift < size) && (byte & 0x40)) 5016 { 5017 result |= -(1 << shift); 5018 } 5019 *bytes_read_ptr = num_read; 5020 return result; 5021} 5022 5023static void 5024set_cu_language (unsigned int lang, struct dwarf2_cu *cu) 5025{ 5026 switch (lang) 5027 { 5028 case DW_LANG_C89: 5029 case DW_LANG_C: 5030 cu->language = language_c; 5031 break; 5032 case DW_LANG_C_plus_plus: 5033 cu->language = language_cplus; 5034 break; 5035 case DW_LANG_Fortran77: 5036 case DW_LANG_Fortran90: 5037 case DW_LANG_Fortran95: 5038 cu->language = language_fortran; 5039 break; 5040 case DW_LANG_Mips_Assembler: 5041 cu->language = language_asm; 5042 break; 5043 case DW_LANG_Java: 5044 cu->language = language_java; 5045 break; 5046 case DW_LANG_Ada83: 5047 case DW_LANG_Ada95: 5048 case DW_LANG_Cobol74: 5049 case DW_LANG_Cobol85: 5050 case DW_LANG_Pascal83: 5051 case DW_LANG_Modula2: 5052 default: 5053 cu->language = language_minimal; 5054 break; 5055 } 5056 cu->language_defn = language_def (cu->language); 5057} 5058 5059/* Return the named attribute or NULL if not there. */ 5060 5061static struct attribute * 5062dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) 5063{ 5064 unsigned int i; 5065 struct attribute *spec = NULL; 5066 5067 for (i = 0; i < die->num_attrs; ++i) 5068 { 5069 if (die->attrs[i].name == name) 5070 { 5071 return &die->attrs[i]; 5072 } 5073 if (die->attrs[i].name == DW_AT_specification 5074 || die->attrs[i].name == DW_AT_abstract_origin) 5075 spec = &die->attrs[i]; 5076 } 5077 if (spec) 5078 { 5079 struct die_info *ref_die = 5080 follow_die_ref (dwarf2_get_ref_die_offset (spec, cu)); 5081 5082 if (ref_die) 5083 return dwarf2_attr (ref_die, name, cu); 5084 } 5085 5086 return NULL; 5087} 5088 5089static int 5090die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) 5091{ 5092 return (dwarf2_attr (die, DW_AT_declaration, cu) 5093 && ! dwarf2_attr (die, DW_AT_specification, cu)); 5094} 5095 5096/* Return the die giving the specification for DIE, if there is 5097 one. */ 5098 5099static struct die_info * 5100die_specification (struct die_info *die, struct dwarf2_cu *cu) 5101{ 5102 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, cu); 5103 5104 if (spec_attr == NULL) 5105 return NULL; 5106 else 5107 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr, cu)); 5108} 5109 5110/* Free the line_header structure *LH, and any arrays and strings it 5111 refers to. */ 5112static void 5113free_line_header (struct line_header *lh) 5114{ 5115 if (lh->standard_opcode_lengths) 5116 xfree (lh->standard_opcode_lengths); 5117 5118 /* Remember that all the lh->file_names[i].name pointers are 5119 pointers into debug_line_buffer, and don't need to be freed. */ 5120 if (lh->file_names) 5121 xfree (lh->file_names); 5122 5123 /* Similarly for the include directory names. */ 5124 if (lh->include_dirs) 5125 xfree (lh->include_dirs); 5126 5127 xfree (lh); 5128} 5129 5130 5131/* Add an entry to LH's include directory table. */ 5132static void 5133add_include_dir (struct line_header *lh, char *include_dir) 5134{ 5135 /* Grow the array if necessary. */ 5136 if (lh->include_dirs_size == 0) 5137 { 5138 lh->include_dirs_size = 1; /* for testing */ 5139 lh->include_dirs = xmalloc (lh->include_dirs_size 5140 * sizeof (*lh->include_dirs)); 5141 } 5142 else if (lh->num_include_dirs >= lh->include_dirs_size) 5143 { 5144 lh->include_dirs_size *= 2; 5145 lh->include_dirs = xrealloc (lh->include_dirs, 5146 (lh->include_dirs_size 5147 * sizeof (*lh->include_dirs))); 5148 } 5149 5150 lh->include_dirs[lh->num_include_dirs++] = include_dir; 5151} 5152 5153 5154/* Add an entry to LH's file name table. */ 5155static void 5156add_file_name (struct line_header *lh, 5157 char *name, 5158 unsigned int dir_index, 5159 unsigned int mod_time, 5160 unsigned int length) 5161{ 5162 struct file_entry *fe; 5163 5164 /* Grow the array if necessary. */ 5165 if (lh->file_names_size == 0) 5166 { 5167 lh->file_names_size = 1; /* for testing */ 5168 lh->file_names = xmalloc (lh->file_names_size 5169 * sizeof (*lh->file_names)); 5170 } 5171 else if (lh->num_file_names >= lh->file_names_size) 5172 { 5173 lh->file_names_size *= 2; 5174 lh->file_names = xrealloc (lh->file_names, 5175 (lh->file_names_size 5176 * sizeof (*lh->file_names))); 5177 } 5178 5179 fe = &lh->file_names[lh->num_file_names++]; 5180 fe->name = name; 5181 fe->dir_index = dir_index; 5182 fe->mod_time = mod_time; 5183 fe->length = length; 5184} 5185 5186 5187/* Read the statement program header starting at OFFSET in 5188 dwarf_line_buffer, according to the endianness of ABFD. Return a 5189 pointer to a struct line_header, allocated using xmalloc. 5190 5191 NOTE: the strings in the include directory and file name tables of 5192 the returned object point into debug_line_buffer, and must not be 5193 freed. */ 5194static struct line_header * 5195dwarf_decode_line_header (unsigned int offset, bfd *abfd, 5196 struct dwarf2_cu *cu) 5197{ 5198 struct cleanup *back_to; 5199 struct line_header *lh; 5200 char *line_ptr; 5201 int bytes_read; 5202 int i; 5203 char *cur_dir, *cur_file; 5204 5205 if (dwarf_line_buffer == NULL) 5206 { 5207 complaint (&symfile_complaints, "missing .debug_line section"); 5208 return 0; 5209 } 5210 5211 /* Make sure that at least there's room for the total_length field. That 5212 could be 12 bytes long, but we're just going to fudge that. */ 5213 if (offset + 4 >= dwarf_line_size) 5214 { 5215 dwarf2_statement_list_fits_in_line_number_section_complaint (); 5216 return 0; 5217 } 5218 5219 lh = xmalloc (sizeof (*lh)); 5220 memset (lh, 0, sizeof (*lh)); 5221 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, 5222 (void *) lh); 5223 5224 line_ptr = dwarf_line_buffer + offset; 5225 5226 /* read in the header */ 5227 lh->total_length = read_initial_length (abfd, line_ptr, &cu->header, &bytes_read); 5228 line_ptr += bytes_read; 5229 if (line_ptr + lh->total_length > dwarf_line_buffer + dwarf_line_size) 5230 { 5231 dwarf2_statement_list_fits_in_line_number_section_complaint (); 5232 return 0; 5233 } 5234 lh->statement_program_end = line_ptr + lh->total_length; 5235 lh->version = read_2_bytes (abfd, line_ptr); 5236 line_ptr += 2; 5237 lh->header_length = read_offset (abfd, line_ptr, &cu->header, &bytes_read); 5238 line_ptr += bytes_read; 5239 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); 5240 line_ptr += 1; 5241 lh->default_is_stmt = read_1_byte (abfd, line_ptr); 5242 line_ptr += 1; 5243 lh->line_base = read_1_signed_byte (abfd, line_ptr); 5244 line_ptr += 1; 5245 lh->line_range = read_1_byte (abfd, line_ptr); 5246 line_ptr += 1; 5247 lh->opcode_base = read_1_byte (abfd, line_ptr); 5248 line_ptr += 1; 5249 lh->standard_opcode_lengths 5250 = (unsigned char *) xmalloc (lh->opcode_base * sizeof (unsigned char)); 5251 5252 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ 5253 for (i = 1; i < lh->opcode_base; ++i) 5254 { 5255 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); 5256 line_ptr += 1; 5257 } 5258 5259 /* Read directory table */ 5260 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL) 5261 { 5262 line_ptr += bytes_read; 5263 add_include_dir (lh, cur_dir); 5264 } 5265 line_ptr += bytes_read; 5266 5267 /* Read file name table */ 5268 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL) 5269 { 5270 unsigned int dir_index, mod_time, length; 5271 5272 line_ptr += bytes_read; 5273 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); 5274 line_ptr += bytes_read; 5275 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); 5276 line_ptr += bytes_read; 5277 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); 5278 line_ptr += bytes_read; 5279 5280 add_file_name (lh, cur_file, dir_index, mod_time, length); 5281 } 5282 line_ptr += bytes_read; 5283 lh->statement_program_start = line_ptr; 5284 5285 if (line_ptr > dwarf_line_buffer + dwarf_line_size) 5286 complaint (&symfile_complaints, 5287 "line number info header doesn't fit in `.debug_line' section"); 5288 5289 discard_cleanups (back_to); 5290 return lh; 5291} 5292 5293/* This function exists to work around a bug in certain compilers 5294 (particularly GCC 2.95), in which the first line number marker of a 5295 function does not show up until after the prologue, right before 5296 the second line number marker. This function shifts ADDRESS down 5297 to the beginning of the function if necessary, and is called on 5298 addresses passed to record_line. */ 5299 5300static CORE_ADDR 5301check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) 5302{ 5303 struct function_range *fn; 5304 5305 /* Find the function_range containing address. */ 5306 if (!cu->first_fn) 5307 return address; 5308 5309 if (!cu->cached_fn) 5310 cu->cached_fn = cu->first_fn; 5311 5312 fn = cu->cached_fn; 5313 while (fn) 5314 if (fn->lowpc <= address && fn->highpc > address) 5315 goto found; 5316 else 5317 fn = fn->next; 5318 5319 fn = cu->first_fn; 5320 while (fn && fn != cu->cached_fn) 5321 if (fn->lowpc <= address && fn->highpc > address) 5322 goto found; 5323 else 5324 fn = fn->next; 5325 5326 return address; 5327 5328 found: 5329 if (fn->seen_line) 5330 return address; 5331 if (address != fn->lowpc) 5332 complaint (&symfile_complaints, 5333 "misplaced first line number at 0x%lx for '%s'", 5334 (unsigned long) address, fn->name); 5335 fn->seen_line = 1; 5336 return fn->lowpc; 5337} 5338 5339/* Decode the line number information for the compilation unit whose 5340 line number info is at OFFSET in the .debug_line section. 5341 The compilation directory of the file is passed in COMP_DIR. */ 5342 5343static void 5344dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd, 5345 struct dwarf2_cu *cu) 5346{ 5347 char *line_ptr; 5348 char *line_end; 5349 unsigned int bytes_read; 5350 unsigned char op_code, extended_op, adj_opcode; 5351 CORE_ADDR baseaddr; 5352 struct objfile *objfile = cu->objfile; 5353 5354 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 5355 5356 line_ptr = lh->statement_program_start; 5357 line_end = lh->statement_program_end; 5358 5359 /* Read the statement sequences until there's nothing left. */ 5360 while (line_ptr < line_end) 5361 { 5362 /* state machine registers */ 5363 CORE_ADDR address = 0; 5364 unsigned int file = 1; 5365 unsigned int line = 1; 5366 unsigned int column = 0; 5367 int is_stmt = lh->default_is_stmt; 5368 int basic_block = 0; 5369 int end_sequence = 0; 5370 5371 /* Start a subfile for the current file of the state machine. */ 5372 if (lh->num_file_names >= file) 5373 { 5374 /* lh->include_dirs and lh->file_names are 0-based, but the 5375 directory and file name numbers in the statement program 5376 are 1-based. */ 5377 struct file_entry *fe = &lh->file_names[file - 1]; 5378 char *dir; 5379 if (fe->dir_index) 5380 dir = lh->include_dirs[fe->dir_index - 1]; 5381 else 5382 dir = comp_dir; 5383 dwarf2_start_subfile (fe->name, dir); 5384 } 5385 5386 /* Decode the table. */ 5387 while (!end_sequence) 5388 { 5389 op_code = read_1_byte (abfd, line_ptr); 5390 line_ptr += 1; 5391 5392 if (op_code >= lh->opcode_base) 5393 { /* Special operand. */ 5394 adj_opcode = op_code - lh->opcode_base; 5395 address += (adj_opcode / lh->line_range) 5396 * lh->minimum_instruction_length; 5397 line += lh->line_base + (adj_opcode % lh->line_range); 5398 /* append row to matrix using current values */ 5399 record_line (current_subfile, line, 5400 check_cu_functions (address, cu)); 5401 basic_block = 1; 5402 } 5403 else switch (op_code) 5404 { 5405 case DW_LNS_extended_op: 5406 line_ptr += 1; /* ignore length */ 5407 extended_op = read_1_byte (abfd, line_ptr); 5408 line_ptr += 1; 5409 switch (extended_op) 5410 { 5411 case DW_LNE_end_sequence: 5412 end_sequence = 1; 5413 record_line (current_subfile, 0, address); 5414 break; 5415 case DW_LNE_set_address: 5416 address = read_address (abfd, line_ptr, cu, &bytes_read); 5417 line_ptr += bytes_read; 5418 address += baseaddr; 5419 break; 5420 case DW_LNE_define_file: 5421 { 5422 char *cur_file; 5423 unsigned int dir_index, mod_time, length; 5424 5425 cur_file = read_string (abfd, line_ptr, &bytes_read); 5426 line_ptr += bytes_read; 5427 dir_index = 5428 read_unsigned_leb128 (abfd, line_ptr, &bytes_read); 5429 line_ptr += bytes_read; 5430 mod_time = 5431 read_unsigned_leb128 (abfd, line_ptr, &bytes_read); 5432 line_ptr += bytes_read; 5433 length = 5434 read_unsigned_leb128 (abfd, line_ptr, &bytes_read); 5435 line_ptr += bytes_read; 5436 add_file_name (lh, cur_file, dir_index, mod_time, length); 5437 } 5438 break; 5439 default: 5440 complaint (&symfile_complaints, 5441 "mangled .debug_line section"); 5442 return; 5443 } 5444 break; 5445 case DW_LNS_copy: 5446 record_line (current_subfile, line, 5447 check_cu_functions (address, cu)); 5448 basic_block = 0; 5449 break; 5450 case DW_LNS_advance_pc: 5451 address += lh->minimum_instruction_length 5452 * read_unsigned_leb128 (abfd, line_ptr, &bytes_read); 5453 line_ptr += bytes_read; 5454 break; 5455 case DW_LNS_advance_line: 5456 line += read_signed_leb128 (abfd, line_ptr, &bytes_read); 5457 line_ptr += bytes_read; 5458 break; 5459 case DW_LNS_set_file: 5460 { 5461 /* lh->include_dirs and lh->file_names are 0-based, 5462 but the directory and file name numbers in the 5463 statement program are 1-based. */ 5464 struct file_entry *fe; 5465 char *dir; 5466 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); 5467 line_ptr += bytes_read; 5468 fe = &lh->file_names[file - 1]; 5469 if (fe->dir_index) 5470 dir = lh->include_dirs[fe->dir_index - 1]; 5471 else 5472 dir = comp_dir; 5473 dwarf2_start_subfile (fe->name, dir); 5474 } 5475 break; 5476 case DW_LNS_set_column: 5477 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); 5478 line_ptr += bytes_read; 5479 break; 5480 case DW_LNS_negate_stmt: 5481 is_stmt = (!is_stmt); 5482 break; 5483 case DW_LNS_set_basic_block: 5484 basic_block = 1; 5485 break; 5486 /* Add to the address register of the state machine the 5487 address increment value corresponding to special opcode 5488 255. Ie, this value is scaled by the minimum instruction 5489 length since special opcode 255 would have scaled the 5490 the increment. */ 5491 case DW_LNS_const_add_pc: 5492 address += (lh->minimum_instruction_length 5493 * ((255 - lh->opcode_base) / lh->line_range)); 5494 break; 5495 case DW_LNS_fixed_advance_pc: 5496 address += read_2_bytes (abfd, line_ptr); 5497 line_ptr += 2; 5498 break; 5499 default: 5500 { /* Unknown standard opcode, ignore it. */ 5501 int i; 5502 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) 5503 { 5504 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); 5505 line_ptr += bytes_read; 5506 } 5507 } 5508 } 5509 } 5510 } 5511} 5512 5513/* Start a subfile for DWARF. FILENAME is the name of the file and 5514 DIRNAME the name of the source directory which contains FILENAME 5515 or NULL if not known. 5516 This routine tries to keep line numbers from identical absolute and 5517 relative file names in a common subfile. 5518 5519 Using the `list' example from the GDB testsuite, which resides in 5520 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename 5521 of /srcdir/list0.c yields the following debugging information for list0.c: 5522 5523 DW_AT_name: /srcdir/list0.c 5524 DW_AT_comp_dir: /compdir 5525 files.files[0].name: list0.h 5526 files.files[0].dir: /srcdir 5527 files.files[1].name: list0.c 5528 files.files[1].dir: /srcdir 5529 5530 The line number information for list0.c has to end up in a single 5531 subfile, so that `break /srcdir/list0.c:1' works as expected. */ 5532 5533static void 5534dwarf2_start_subfile (char *filename, char *dirname) 5535{ 5536 /* If the filename isn't absolute, try to match an existing subfile 5537 with the full pathname. */ 5538 5539 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) 5540 { 5541 struct subfile *subfile; 5542 char *fullname = concat (dirname, "/", filename, NULL); 5543 5544 for (subfile = subfiles; subfile; subfile = subfile->next) 5545 { 5546 if (FILENAME_CMP (subfile->name, fullname) == 0) 5547 { 5548 current_subfile = subfile; 5549 xfree (fullname); 5550 return; 5551 } 5552 } 5553 xfree (fullname); 5554 } 5555 start_subfile (filename, dirname); 5556} 5557 5558static void 5559var_decode_location (struct attribute *attr, struct symbol *sym, 5560 struct dwarf2_cu *cu) 5561{ 5562 struct objfile *objfile = cu->objfile; 5563 struct comp_unit_head *cu_header = &cu->header; 5564 5565 /* NOTE drow/2003-01-30: There used to be a comment and some special 5566 code here to turn a symbol with DW_AT_external and a 5567 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was 5568 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux 5569 with some versions of binutils) where shared libraries could have 5570 relocations against symbols in their debug information - the 5571 minimal symbol would have the right address, but the debug info 5572 would not. It's no longer necessary, because we will explicitly 5573 apply relocations when we read in the debug information now. */ 5574 5575 /* A DW_AT_location attribute with no contents indicates that a 5576 variable has been optimized away. */ 5577 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) 5578 { 5579 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; 5580 return; 5581 } 5582 5583 /* Handle one degenerate form of location expression specially, to 5584 preserve GDB's previous behavior when section offsets are 5585 specified. If this is just a DW_OP_addr then mark this symbol 5586 as LOC_STATIC. */ 5587 5588 if (attr_form_is_block (attr) 5589 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size 5590 && DW_BLOCK (attr)->data[0] == DW_OP_addr) 5591 { 5592 int dummy; 5593 5594 SYMBOL_VALUE_ADDRESS (sym) = 5595 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); 5596 fixup_symbol_section (sym, objfile); 5597 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, 5598 SYMBOL_SECTION (sym)); 5599 SYMBOL_CLASS (sym) = LOC_STATIC; 5600 return; 5601 } 5602 5603 /* NOTE drow/2002-01-30: It might be worthwhile to have a static 5604 expression evaluator, and use LOC_COMPUTED only when necessary 5605 (i.e. when the value of a register or memory location is 5606 referenced, or a thread-local block, etc.). Then again, it might 5607 not be worthwhile. I'm assuming that it isn't unless performance 5608 or memory numbers show me otherwise. */ 5609 5610 dwarf2_symbol_mark_computed (attr, sym, cu); 5611 SYMBOL_CLASS (sym) = LOC_COMPUTED; 5612} 5613 5614/* Given a pointer to a DWARF information entry, figure out if we need 5615 to make a symbol table entry for it, and if so, create a new entry 5616 and return a pointer to it. 5617 If TYPE is NULL, determine symbol type from the die, otherwise 5618 used the passed type. */ 5619 5620static struct symbol * 5621new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) 5622{ 5623 struct objfile *objfile = cu->objfile; 5624 struct symbol *sym = NULL; 5625 char *name; 5626 struct attribute *attr = NULL; 5627 struct attribute *attr2 = NULL; 5628 CORE_ADDR baseaddr; 5629 5630 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 5631 5632 if (die->tag != DW_TAG_namespace) 5633 name = dwarf2_linkage_name (die, cu); 5634 else 5635 name = TYPE_NAME (type); 5636 5637 if (name) 5638 { 5639 sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, 5640 sizeof (struct symbol)); 5641 OBJSTAT (objfile, n_syms++); 5642 memset (sym, 0, sizeof (struct symbol)); 5643 5644 /* Cache this symbol's name and the name's demangled form (if any). */ 5645 SYMBOL_LANGUAGE (sym) = cu->language; 5646 SYMBOL_SET_NAMES (sym, name, strlen (name), objfile); 5647 5648 /* Default assumptions. 5649 Use the passed type or decode it from the die. */ 5650 SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 5651 SYMBOL_CLASS (sym) = LOC_STATIC; 5652 if (type != NULL) 5653 SYMBOL_TYPE (sym) = type; 5654 else 5655 SYMBOL_TYPE (sym) = die_type (die, cu); 5656 attr = dwarf2_attr (die, DW_AT_decl_line, cu); 5657 if (attr) 5658 { 5659 SYMBOL_LINE (sym) = DW_UNSND (attr); 5660 } 5661 switch (die->tag) 5662 { 5663 case DW_TAG_label: 5664 attr = dwarf2_attr (die, DW_AT_low_pc, cu); 5665 if (attr) 5666 { 5667 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; 5668 } 5669 SYMBOL_CLASS (sym) = LOC_LABEL; 5670 break; 5671 case DW_TAG_subprogram: 5672 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by 5673 finish_block. */ 5674 SYMBOL_CLASS (sym) = LOC_BLOCK; 5675 attr2 = dwarf2_attr (die, DW_AT_external, cu); 5676 if (attr2 && (DW_UNSND (attr2) != 0)) 5677 { 5678 add_symbol_to_list (sym, &global_symbols); 5679 } 5680 else 5681 { 5682 add_symbol_to_list (sym, cu->list_in_scope); 5683 } 5684 break; 5685 case DW_TAG_variable: 5686 /* Compilation with minimal debug info may result in variables 5687 with missing type entries. Change the misleading `void' type 5688 to something sensible. */ 5689 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) 5690 SYMBOL_TYPE (sym) = init_type (TYPE_CODE_INT, 5691 TARGET_INT_BIT / HOST_CHAR_BIT, 0, 5692 "<variable, no debug info>", 5693 objfile); 5694 attr = dwarf2_attr (die, DW_AT_const_value, cu); 5695 if (attr) 5696 { 5697 dwarf2_const_value (attr, sym, cu); 5698 attr2 = dwarf2_attr (die, DW_AT_external, cu); 5699 if (attr2 && (DW_UNSND (attr2) != 0)) 5700 add_symbol_to_list (sym, &global_symbols); 5701 else 5702 add_symbol_to_list (sym, cu->list_in_scope); 5703 break; 5704 } 5705 attr = dwarf2_attr (die, DW_AT_location, cu); 5706 if (attr) 5707 { 5708 var_decode_location (attr, sym, cu); 5709 attr2 = dwarf2_attr (die, DW_AT_external, cu); 5710 if (attr2 && (DW_UNSND (attr2) != 0)) 5711 add_symbol_to_list (sym, &global_symbols); 5712 else 5713 add_symbol_to_list (sym, cu->list_in_scope); 5714 } 5715 else 5716 { 5717 /* We do not know the address of this symbol. 5718 If it is an external symbol and we have type information 5719 for it, enter the symbol as a LOC_UNRESOLVED symbol. 5720 The address of the variable will then be determined from 5721 the minimal symbol table whenever the variable is 5722 referenced. */ 5723 attr2 = dwarf2_attr (die, DW_AT_external, cu); 5724 if (attr2 && (DW_UNSND (attr2) != 0) 5725 && dwarf2_attr (die, DW_AT_type, cu) != NULL) 5726 { 5727 SYMBOL_CLASS (sym) = LOC_UNRESOLVED; 5728 add_symbol_to_list (sym, &global_symbols); 5729 } 5730 } 5731 break; 5732 case DW_TAG_formal_parameter: 5733 attr = dwarf2_attr (die, DW_AT_location, cu); 5734 if (attr) 5735 { 5736 var_decode_location (attr, sym, cu); 5737 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */ 5738 if (SYMBOL_CLASS (sym) == LOC_COMPUTED) 5739 SYMBOL_CLASS (sym) = LOC_COMPUTED_ARG; 5740 } 5741 attr = dwarf2_attr (die, DW_AT_const_value, cu); 5742 if (attr) 5743 { 5744 dwarf2_const_value (attr, sym, cu); 5745 } 5746 add_symbol_to_list (sym, cu->list_in_scope); 5747 break; 5748 case DW_TAG_unspecified_parameters: 5749 /* From varargs functions; gdb doesn't seem to have any 5750 interest in this information, so just ignore it for now. 5751 (FIXME?) */ 5752 break; 5753 case DW_TAG_class_type: 5754 case DW_TAG_structure_type: 5755 case DW_TAG_union_type: 5756 case DW_TAG_enumeration_type: 5757 SYMBOL_CLASS (sym) = LOC_TYPEDEF; 5758 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; 5759 5760 /* Make sure that the symbol includes appropriate enclosing 5761 classes/namespaces in its name. These are calculated in 5762 read_structure_type, and the correct name is saved in 5763 the type. */ 5764 5765 if (cu->language == language_cplus) 5766 { 5767 struct type *type = SYMBOL_TYPE (sym); 5768 5769 if (TYPE_TAG_NAME (type) != NULL) 5770 { 5771 /* FIXME: carlton/2003-11-10: Should this use 5772 SYMBOL_SET_NAMES instead? (The same problem also 5773 arises a further down in the function.) */ 5774 SYMBOL_LINKAGE_NAME (sym) 5775 = obsavestring (TYPE_TAG_NAME (type), 5776 strlen (TYPE_TAG_NAME (type)), 5777 &objfile->objfile_obstack); 5778 } 5779 } 5780 5781 { 5782 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't 5783 really ever be static objects: otherwise, if you try 5784 to, say, break of a class's method and you're in a file 5785 which doesn't mention that class, it won't work unless 5786 the check for all static symbols in lookup_symbol_aux 5787 saves you. See the OtherFileClass tests in 5788 gdb.c++/namespace.exp. */ 5789 5790 struct pending **list_to_add; 5791 5792 list_to_add = (cu->list_in_scope == &file_symbols 5793 && cu->language == language_cplus 5794 ? &global_symbols : cu->list_in_scope); 5795 5796 add_symbol_to_list (sym, list_to_add); 5797 5798 /* The semantics of C++ state that "struct foo { ... }" also 5799 defines a typedef for "foo". Synthesize a typedef symbol so 5800 that "ptype foo" works as expected. */ 5801 if (cu->language == language_cplus) 5802 { 5803 struct symbol *typedef_sym = (struct symbol *) 5804 obstack_alloc (&objfile->objfile_obstack, 5805 sizeof (struct symbol)); 5806 *typedef_sym = *sym; 5807 SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN; 5808 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) 5809 TYPE_NAME (SYMBOL_TYPE (sym)) = 5810 obsavestring (SYMBOL_NATURAL_NAME (sym), 5811 strlen (SYMBOL_NATURAL_NAME (sym)), 5812 &objfile->objfile_obstack); 5813 add_symbol_to_list (typedef_sym, list_to_add); 5814 } 5815 } 5816 break; 5817 case DW_TAG_typedef: 5818 if (processing_has_namespace_info 5819 && processing_current_prefix[0] != '\0') 5820 { 5821 SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->objfile_obstack, 5822 processing_current_prefix, 5823 "::", 5824 name); 5825 } 5826 SYMBOL_CLASS (sym) = LOC_TYPEDEF; 5827 SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 5828 add_symbol_to_list (sym, cu->list_in_scope); 5829 break; 5830 case DW_TAG_base_type: 5831 case DW_TAG_subrange_type: 5832 SYMBOL_CLASS (sym) = LOC_TYPEDEF; 5833 SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 5834 add_symbol_to_list (sym, cu->list_in_scope); 5835 break; 5836 case DW_TAG_enumerator: 5837 if (processing_has_namespace_info 5838 && processing_current_prefix[0] != '\0') 5839 { 5840 SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->objfile_obstack, 5841 processing_current_prefix, 5842 "::", 5843 name); 5844 } 5845 attr = dwarf2_attr (die, DW_AT_const_value, cu); 5846 if (attr) 5847 { 5848 dwarf2_const_value (attr, sym, cu); 5849 } 5850 { 5851 /* NOTE: carlton/2003-11-10: See comment above in the 5852 DW_TAG_class_type, etc. block. */ 5853 5854 struct pending **list_to_add; 5855 5856 list_to_add = (cu->list_in_scope == &file_symbols 5857 && cu->language == language_cplus 5858 ? &global_symbols : cu->list_in_scope); 5859 5860 add_symbol_to_list (sym, list_to_add); 5861 } 5862 break; 5863 case DW_TAG_namespace: 5864 SYMBOL_CLASS (sym) = LOC_TYPEDEF; 5865 add_symbol_to_list (sym, &global_symbols); 5866 break; 5867 default: 5868 /* Not a tag we recognize. Hopefully we aren't processing 5869 trash data, but since we must specifically ignore things 5870 we don't recognize, there is nothing else we should do at 5871 this point. */ 5872 complaint (&symfile_complaints, "unsupported tag: '%s'", 5873 dwarf_tag_name (die->tag)); 5874 break; 5875 } 5876 } 5877 return (sym); 5878} 5879 5880/* Copy constant value from an attribute to a symbol. */ 5881 5882static void 5883dwarf2_const_value (struct attribute *attr, struct symbol *sym, 5884 struct dwarf2_cu *cu) 5885{ 5886 struct objfile *objfile = cu->objfile; 5887 struct comp_unit_head *cu_header = &cu->header; 5888 struct dwarf_block *blk; 5889 5890 switch (attr->form) 5891 { 5892 case DW_FORM_addr: 5893 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size) 5894 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym), 5895 cu_header->addr_size, 5896 TYPE_LENGTH (SYMBOL_TYPE 5897 (sym))); 5898 SYMBOL_VALUE_BYTES (sym) = (char *) 5899 obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size); 5900 /* NOTE: cagney/2003-05-09: In-lined store_address call with 5901 it's body - store_unsigned_integer. */ 5902 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size, 5903 DW_ADDR (attr)); 5904 SYMBOL_CLASS (sym) = LOC_CONST_BYTES; 5905 break; 5906 case DW_FORM_block1: 5907 case DW_FORM_block2: 5908 case DW_FORM_block4: 5909 case DW_FORM_block: 5910 blk = DW_BLOCK (attr); 5911 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size) 5912 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym), 5913 blk->size, 5914 TYPE_LENGTH (SYMBOL_TYPE 5915 (sym))); 5916 SYMBOL_VALUE_BYTES (sym) = (char *) 5917 obstack_alloc (&objfile->objfile_obstack, blk->size); 5918 memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size); 5919 SYMBOL_CLASS (sym) = LOC_CONST_BYTES; 5920 break; 5921 5922 /* The DW_AT_const_value attributes are supposed to carry the 5923 symbol's value "represented as it would be on the target 5924 architecture." By the time we get here, it's already been 5925 converted to host endianness, so we just need to sign- or 5926 zero-extend it as appropriate. */ 5927 case DW_FORM_data1: 5928 dwarf2_const_value_data (attr, sym, 8); 5929 break; 5930 case DW_FORM_data2: 5931 dwarf2_const_value_data (attr, sym, 16); 5932 break; 5933 case DW_FORM_data4: 5934 dwarf2_const_value_data (attr, sym, 32); 5935 break; 5936 case DW_FORM_data8: 5937 dwarf2_const_value_data (attr, sym, 64); 5938 break; 5939 5940 case DW_FORM_sdata: 5941 SYMBOL_VALUE (sym) = DW_SND (attr); 5942 SYMBOL_CLASS (sym) = LOC_CONST; 5943 break; 5944 5945 case DW_FORM_udata: 5946 SYMBOL_VALUE (sym) = DW_UNSND (attr); 5947 SYMBOL_CLASS (sym) = LOC_CONST; 5948 break; 5949 5950 default: 5951 complaint (&symfile_complaints, 5952 "unsupported const value attribute form: '%s'", 5953 dwarf_form_name (attr->form)); 5954 SYMBOL_VALUE (sym) = 0; 5955 SYMBOL_CLASS (sym) = LOC_CONST; 5956 break; 5957 } 5958} 5959 5960 5961/* Given an attr with a DW_FORM_dataN value in host byte order, sign- 5962 or zero-extend it as appropriate for the symbol's type. */ 5963static void 5964dwarf2_const_value_data (struct attribute *attr, 5965 struct symbol *sym, 5966 int bits) 5967{ 5968 LONGEST l = DW_UNSND (attr); 5969 5970 if (bits < sizeof (l) * 8) 5971 { 5972 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym))) 5973 l &= ((LONGEST) 1 << bits) - 1; 5974 else 5975 l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits); 5976 } 5977 5978 SYMBOL_VALUE (sym) = l; 5979 SYMBOL_CLASS (sym) = LOC_CONST; 5980} 5981 5982 5983/* Return the type of the die in question using its DW_AT_type attribute. */ 5984 5985static struct type * 5986die_type (struct die_info *die, struct dwarf2_cu *cu) 5987{ 5988 struct type *type; 5989 struct attribute *type_attr; 5990 struct die_info *type_die; 5991 unsigned int ref; 5992 5993 type_attr = dwarf2_attr (die, DW_AT_type, cu); 5994 if (!type_attr) 5995 { 5996 /* A missing DW_AT_type represents a void type. */ 5997 return dwarf2_fundamental_type (cu->objfile, FT_VOID, cu); 5998 } 5999 else 6000 { 6001 ref = dwarf2_get_ref_die_offset (type_attr, cu); 6002 type_die = follow_die_ref (ref); 6003 if (!type_die) 6004 { 6005 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", 6006 ref, cu->objfile->name); 6007 return NULL; 6008 } 6009 } 6010 type = tag_type_to_type (type_die, cu); 6011 if (!type) 6012 { 6013 dump_die (type_die); 6014 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]", 6015 cu->objfile->name); 6016 } 6017 return type; 6018} 6019 6020/* Return the containing type of the die in question using its 6021 DW_AT_containing_type attribute. */ 6022 6023static struct type * 6024die_containing_type (struct die_info *die, struct dwarf2_cu *cu) 6025{ 6026 struct type *type = NULL; 6027 struct attribute *type_attr; 6028 struct die_info *type_die = NULL; 6029 unsigned int ref; 6030 6031 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); 6032 if (type_attr) 6033 { 6034 ref = dwarf2_get_ref_die_offset (type_attr, cu); 6035 type_die = follow_die_ref (ref); 6036 if (!type_die) 6037 { 6038 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref, 6039 cu->objfile->name); 6040 return NULL; 6041 } 6042 type = tag_type_to_type (type_die, cu); 6043 } 6044 if (!type) 6045 { 6046 if (type_die) 6047 dump_die (type_die); 6048 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]", 6049 cu->objfile->name); 6050 } 6051 return type; 6052} 6053 6054#if 0 6055static struct type * 6056type_at_offset (unsigned int offset, struct dwarf2_cu *cu) 6057{ 6058 struct die_info *die; 6059 struct type *type; 6060 6061 die = follow_die_ref (offset); 6062 if (!die) 6063 { 6064 error ("Dwarf Error: Cannot find type referent at offset %d.", offset); 6065 return NULL; 6066 } 6067 type = tag_type_to_type (die, cu); 6068 return type; 6069} 6070#endif 6071 6072static struct type * 6073tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu) 6074{ 6075 if (die->type) 6076 { 6077 return die->type; 6078 } 6079 else 6080 { 6081 read_type_die (die, cu); 6082 if (!die->type) 6083 { 6084 dump_die (die); 6085 error ("Dwarf Error: Cannot find type of die 0x%x [in module %s]", 6086 die->tag, cu->objfile->name); 6087 } 6088 return die->type; 6089 } 6090} 6091 6092static void 6093read_type_die (struct die_info *die, struct dwarf2_cu *cu) 6094{ 6095 char *prefix = determine_prefix (die, cu); 6096 const char *old_prefix = processing_current_prefix; 6097 struct cleanup *back_to = make_cleanup (xfree, prefix); 6098 processing_current_prefix = prefix; 6099 6100 switch (die->tag) 6101 { 6102 case DW_TAG_class_type: 6103 case DW_TAG_structure_type: 6104 case DW_TAG_union_type: 6105 read_structure_type (die, cu); 6106 break; 6107 case DW_TAG_enumeration_type: 6108 read_enumeration_type (die, cu); 6109 break; 6110 case DW_TAG_subprogram: 6111 case DW_TAG_subroutine_type: 6112 read_subroutine_type (die, cu); 6113 break; 6114 case DW_TAG_array_type: 6115 read_array_type (die, cu); 6116 break; 6117 case DW_TAG_pointer_type: 6118 read_tag_pointer_type (die, cu); 6119 break; 6120 case DW_TAG_unspecified_type: 6121 read_tag_unspecified_type (die, cu); 6122 break; 6123 case DW_TAG_ptr_to_member_type: 6124 read_tag_ptr_to_member_type (die, cu); 6125 break; 6126 case DW_TAG_reference_type: 6127 case DW_TAG_rvalue_reference_type: 6128 read_tag_reference_type (die, cu); 6129 break; 6130 case DW_TAG_const_type: 6131 read_tag_const_type (die, cu); 6132 break; 6133 case DW_TAG_volatile_type: 6134 read_tag_volatile_type (die, cu); 6135 break; 6136 case DW_TAG_restrict_type: 6137 read_tag_restrict_type (die, cu); 6138 break; 6139 case DW_TAG_string_type: 6140 read_tag_string_type (die, cu); 6141 break; 6142 case DW_TAG_typedef: 6143 read_typedef (die, cu); 6144 break; 6145 case DW_TAG_subrange_type: 6146 read_subrange_type (die, cu); 6147 break; 6148 case DW_TAG_base_type: 6149 read_base_type (die, cu); 6150 break; 6151 default: 6152 complaint (&symfile_complaints, "unexepected tag in read_type_die: '%s'", 6153 dwarf_tag_name (die->tag)); 6154 break; 6155 } 6156 6157 processing_current_prefix = old_prefix; 6158 do_cleanups (back_to); 6159} 6160 6161/* Return the name of the namespace/class that DIE is defined within, 6162 or "" if we can't tell. The caller should xfree the result. */ 6163 6164/* NOTE: carlton/2004-01-23: See read_func_scope (and the comment 6165 therein) for an example of how to use this function to deal with 6166 DW_AT_specification. */ 6167 6168static char * 6169determine_prefix (struct die_info *die, struct dwarf2_cu *cu) 6170{ 6171 struct die_info *parent; 6172 6173 if (cu->language != language_cplus) 6174 return NULL; 6175 6176 parent = die->parent; 6177 6178 if (parent == NULL) 6179 { 6180 return xstrdup (""); 6181 } 6182 else 6183 { 6184 switch (parent->tag) { 6185 case DW_TAG_namespace: 6186 { 6187 /* FIXME: carlton/2004-03-05: Should I follow extension dies 6188 before doing this check? */ 6189 if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL) 6190 { 6191 return xstrdup (TYPE_TAG_NAME (parent->type)); 6192 } 6193 else 6194 { 6195 int dummy; 6196 char *parent_prefix = determine_prefix (parent, cu); 6197 char *retval = typename_concat (parent_prefix, 6198 namespace_name (parent, &dummy, 6199 cu)); 6200 xfree (parent_prefix); 6201 return retval; 6202 } 6203 } 6204 break; 6205 case DW_TAG_class_type: 6206 case DW_TAG_structure_type: 6207 { 6208 if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL) 6209 { 6210 return xstrdup (TYPE_TAG_NAME (parent->type)); 6211 } 6212 else 6213 { 6214 const char *old_prefix = processing_current_prefix; 6215 char *new_prefix = determine_prefix (parent, cu); 6216 char *retval; 6217 6218 processing_current_prefix = new_prefix; 6219 retval = determine_class_name (parent, cu); 6220 processing_current_prefix = old_prefix; 6221 6222 xfree (new_prefix); 6223 return retval; 6224 } 6225 } 6226 default: 6227 return determine_prefix (parent, cu); 6228 } 6229 } 6230} 6231 6232/* Return a newly-allocated string formed by concatenating PREFIX, 6233 "::", and SUFFIX, except that if PREFIX is NULL or the empty 6234 string, just return a copy of SUFFIX. */ 6235 6236static char * 6237typename_concat (const char *prefix, const char *suffix) 6238{ 6239 if (prefix == NULL || prefix[0] == '\0') 6240 return xstrdup (suffix); 6241 else 6242 { 6243 char *retval = xmalloc (strlen (prefix) + 2 + strlen (suffix) + 1); 6244 6245 strcpy (retval, prefix); 6246 strcat (retval, "::"); 6247 strcat (retval, suffix); 6248 6249 return retval; 6250 } 6251} 6252 6253static struct type * 6254dwarf_base_type (int encoding, int size, struct dwarf2_cu *cu) 6255{ 6256 struct objfile *objfile = cu->objfile; 6257 6258 /* FIXME - this should not produce a new (struct type *) 6259 every time. It should cache base types. */ 6260 struct type *type; 6261 switch (encoding) 6262 { 6263 case DW_ATE_address: 6264 type = dwarf2_fundamental_type (objfile, FT_VOID, cu); 6265 return type; 6266 case DW_ATE_boolean: 6267 type = dwarf2_fundamental_type (objfile, FT_BOOLEAN, cu); 6268 return type; 6269 case DW_ATE_complex_float: 6270 if (size == 16) 6271 { 6272 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_COMPLEX, cu); 6273 } 6274 else 6275 { 6276 type = dwarf2_fundamental_type (objfile, FT_COMPLEX, cu); 6277 } 6278 return type; 6279 case DW_ATE_float: 6280 if (size == 8) 6281 { 6282 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu); 6283 } 6284 else 6285 { 6286 type = dwarf2_fundamental_type (objfile, FT_FLOAT, cu); 6287 } 6288 return type; 6289 case DW_ATE_signed: 6290 switch (size) 6291 { 6292 case 1: 6293 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu); 6294 break; 6295 case 2: 6296 type = dwarf2_fundamental_type (objfile, FT_SIGNED_SHORT, cu); 6297 break; 6298 default: 6299 case 4: 6300 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu); 6301 break; 6302 } 6303 return type; 6304 case DW_ATE_signed_char: 6305 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu); 6306 return type; 6307 case DW_ATE_unsigned: 6308 switch (size) 6309 { 6310 case 1: 6311 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu); 6312 break; 6313 case 2: 6314 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_SHORT, cu); 6315 break; 6316 default: 6317 case 4: 6318 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_INTEGER, cu); 6319 break; 6320 } 6321 return type; 6322 case DW_ATE_unsigned_char: 6323 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu); 6324 return type; 6325 default: 6326 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu); 6327 return type; 6328 } 6329} 6330 6331#if 0 6332struct die_info * 6333copy_die (struct die_info *old_die) 6334{ 6335 struct die_info *new_die; 6336 int i, num_attrs; 6337 6338 new_die = (struct die_info *) xmalloc (sizeof (struct die_info)); 6339 memset (new_die, 0, sizeof (struct die_info)); 6340 6341 new_die->tag = old_die->tag; 6342 new_die->has_children = old_die->has_children; 6343 new_die->abbrev = old_die->abbrev; 6344 new_die->offset = old_die->offset; 6345 new_die->type = NULL; 6346 6347 num_attrs = old_die->num_attrs; 6348 new_die->num_attrs = num_attrs; 6349 new_die->attrs = (struct attribute *) 6350 xmalloc (num_attrs * sizeof (struct attribute)); 6351 6352 for (i = 0; i < old_die->num_attrs; ++i) 6353 { 6354 new_die->attrs[i].name = old_die->attrs[i].name; 6355 new_die->attrs[i].form = old_die->attrs[i].form; 6356 new_die->attrs[i].u.addr = old_die->attrs[i].u.addr; 6357 } 6358 6359 new_die->next = NULL; 6360 return new_die; 6361} 6362#endif 6363 6364/* Return sibling of die, NULL if no sibling. */ 6365 6366static struct die_info * 6367sibling_die (struct die_info *die) 6368{ 6369 return die->sibling; 6370} 6371 6372/* Get linkage name of a die, return NULL if not found. */ 6373 6374static char * 6375dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu) 6376{ 6377 struct attribute *attr; 6378 6379 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); 6380 if (attr && DW_STRING (attr)) 6381 return DW_STRING (attr); 6382 attr = dwarf2_attr (die, DW_AT_name, cu); 6383 if (attr && DW_STRING (attr)) 6384 return DW_STRING (attr); 6385 return NULL; 6386} 6387 6388/* Get name of a die, return NULL if not found. */ 6389 6390static char * 6391dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) 6392{ 6393 struct attribute *attr; 6394 6395 attr = dwarf2_attr (die, DW_AT_name, cu); 6396 if (attr && DW_STRING (attr)) 6397 return DW_STRING (attr); 6398 return NULL; 6399} 6400 6401/* Return the die that this die in an extension of, or NULL if there 6402 is none. */ 6403 6404static struct die_info * 6405dwarf2_extension (struct die_info *die, struct dwarf2_cu *cu) 6406{ 6407 struct attribute *attr; 6408 struct die_info *extension_die; 6409 unsigned int ref; 6410 6411 attr = dwarf2_attr (die, DW_AT_extension, cu); 6412 if (attr == NULL) 6413 return NULL; 6414 6415 ref = dwarf2_get_ref_die_offset (attr, cu); 6416 extension_die = follow_die_ref (ref); 6417 if (!extension_die) 6418 { 6419 error ("Dwarf Error: Cannot find referent at offset %d.", ref); 6420 } 6421 6422 return extension_die; 6423} 6424 6425/* Convert a DIE tag into its string name. */ 6426 6427static char * 6428dwarf_tag_name (unsigned tag) 6429{ 6430 switch (tag) 6431 { 6432 case DW_TAG_padding: 6433 return "DW_TAG_padding"; 6434 case DW_TAG_array_type: 6435 return "DW_TAG_array_type"; 6436 case DW_TAG_class_type: 6437 return "DW_TAG_class_type"; 6438 case DW_TAG_entry_point: 6439 return "DW_TAG_entry_point"; 6440 case DW_TAG_enumeration_type: 6441 return "DW_TAG_enumeration_type"; 6442 case DW_TAG_formal_parameter: 6443 return "DW_TAG_formal_parameter"; 6444 case DW_TAG_imported_declaration: 6445 return "DW_TAG_imported_declaration"; 6446 case DW_TAG_label: 6447 return "DW_TAG_label"; 6448 case DW_TAG_lexical_block: 6449 return "DW_TAG_lexical_block"; 6450 case DW_TAG_member: 6451 return "DW_TAG_member"; 6452 case DW_TAG_pointer_type: 6453 return "DW_TAG_pointer_type"; 6454 case DW_TAG_reference_type: 6455 return "DW_TAG_reference_type"; 6456 case DW_TAG_rvalue_reference_type: 6457 return "DW_TAG_rvalue_reference_type"; 6458 case DW_TAG_compile_unit: 6459 return "DW_TAG_compile_unit"; 6460 case DW_TAG_string_type: 6461 return "DW_TAG_string_type"; 6462 case DW_TAG_structure_type: 6463 return "DW_TAG_structure_type"; 6464 case DW_TAG_subroutine_type: 6465 return "DW_TAG_subroutine_type"; 6466 case DW_TAG_typedef: 6467 return "DW_TAG_typedef"; 6468 case DW_TAG_union_type: 6469 return "DW_TAG_union_type"; 6470 case DW_TAG_unspecified_parameters: 6471 return "DW_TAG_unspecified_parameters"; 6472 case DW_TAG_variant: 6473 return "DW_TAG_variant"; 6474 case DW_TAG_common_block: 6475 return "DW_TAG_common_block"; 6476 case DW_TAG_common_inclusion: 6477 return "DW_TAG_common_inclusion"; 6478 case DW_TAG_inheritance: 6479 return "DW_TAG_inheritance"; 6480 case DW_TAG_inlined_subroutine: 6481 return "DW_TAG_inlined_subroutine"; 6482 case DW_TAG_module: 6483 return "DW_TAG_module"; 6484 case DW_TAG_ptr_to_member_type: 6485 return "DW_TAG_ptr_to_member_type"; 6486 case DW_TAG_set_type: 6487 return "DW_TAG_set_type"; 6488 case DW_TAG_subrange_type: 6489 return "DW_TAG_subrange_type"; 6490 case DW_TAG_with_stmt: 6491 return "DW_TAG_with_stmt"; 6492 case DW_TAG_access_declaration: 6493 return "DW_TAG_access_declaration"; 6494 case DW_TAG_base_type: 6495 return "DW_TAG_base_type"; 6496 case DW_TAG_catch_block: 6497 return "DW_TAG_catch_block"; 6498 case DW_TAG_const_type: 6499 return "DW_TAG_const_type"; 6500 case DW_TAG_constant: 6501 return "DW_TAG_constant"; 6502 case DW_TAG_enumerator: 6503 return "DW_TAG_enumerator"; 6504 case DW_TAG_file_type: 6505 return "DW_TAG_file_type"; 6506 case DW_TAG_friend: 6507 return "DW_TAG_friend"; 6508 case DW_TAG_namelist: 6509 return "DW_TAG_namelist"; 6510 case DW_TAG_namelist_item: 6511 return "DW_TAG_namelist_item"; 6512 case DW_TAG_packed_type: 6513 return "DW_TAG_packed_type"; 6514 case DW_TAG_subprogram: 6515 return "DW_TAG_subprogram"; 6516 case DW_TAG_template_type_param: 6517 return "DW_TAG_template_type_param"; 6518 case DW_TAG_template_value_param: 6519 return "DW_TAG_template_value_param"; 6520 case DW_TAG_thrown_type: 6521 return "DW_TAG_thrown_type"; 6522 case DW_TAG_try_block: 6523 return "DW_TAG_try_block"; 6524 case DW_TAG_variant_part: 6525 return "DW_TAG_variant_part"; 6526 case DW_TAG_variable: 6527 return "DW_TAG_variable"; 6528 case DW_TAG_volatile_type: 6529 return "DW_TAG_volatile_type"; 6530 case DW_TAG_dwarf_procedure: 6531 return "DW_TAG_dwarf_procedure"; 6532 case DW_TAG_restrict_type: 6533 return "DW_TAG_restrict_type"; 6534 case DW_TAG_interface_type: 6535 return "DW_TAG_interface_type"; 6536 case DW_TAG_namespace: 6537 return "DW_TAG_namespace"; 6538 case DW_TAG_imported_module: 6539 return "DW_TAG_imported_module"; 6540 case DW_TAG_unspecified_type: 6541 return "DW_TAG_unspecified_type"; 6542 case DW_TAG_partial_unit: 6543 return "DW_TAG_partial_unit"; 6544 case DW_TAG_imported_unit: 6545 return "DW_TAG_imported_unit"; 6546 case DW_TAG_MIPS_loop: 6547 return "DW_TAG_MIPS_loop"; 6548 case DW_TAG_format_label: 6549 return "DW_TAG_format_label"; 6550 case DW_TAG_function_template: 6551 return "DW_TAG_function_template"; 6552 case DW_TAG_class_template: 6553 return "DW_TAG_class_template"; 6554 default: 6555 return "DW_TAG_<unknown>"; 6556 } 6557} 6558 6559/* Convert a DWARF attribute code into its string name. */ 6560 6561static char * 6562dwarf_attr_name (unsigned attr) 6563{ 6564 switch (attr) 6565 { 6566 case DW_AT_sibling: 6567 return "DW_AT_sibling"; 6568 case DW_AT_location: 6569 return "DW_AT_location"; 6570 case DW_AT_name: 6571 return "DW_AT_name"; 6572 case DW_AT_ordering: 6573 return "DW_AT_ordering"; 6574 case DW_AT_subscr_data: 6575 return "DW_AT_subscr_data"; 6576 case DW_AT_byte_size: 6577 return "DW_AT_byte_size"; 6578 case DW_AT_bit_offset: 6579 return "DW_AT_bit_offset"; 6580 case DW_AT_bit_size: 6581 return "DW_AT_bit_size"; 6582 case DW_AT_element_list: 6583 return "DW_AT_element_list"; 6584 case DW_AT_stmt_list: 6585 return "DW_AT_stmt_list"; 6586 case DW_AT_low_pc: 6587 return "DW_AT_low_pc"; 6588 case DW_AT_high_pc: 6589 return "DW_AT_high_pc"; 6590 case DW_AT_language: 6591 return "DW_AT_language"; 6592 case DW_AT_member: 6593 return "DW_AT_member"; 6594 case DW_AT_discr: 6595 return "DW_AT_discr"; 6596 case DW_AT_discr_value: 6597 return "DW_AT_discr_value"; 6598 case DW_AT_visibility: 6599 return "DW_AT_visibility"; 6600 case DW_AT_import: 6601 return "DW_AT_import"; 6602 case DW_AT_string_length: 6603 return "DW_AT_string_length"; 6604 case DW_AT_common_reference: 6605 return "DW_AT_common_reference"; 6606 case DW_AT_comp_dir: 6607 return "DW_AT_comp_dir"; 6608 case DW_AT_const_value: 6609 return "DW_AT_const_value"; 6610 case DW_AT_containing_type: 6611 return "DW_AT_containing_type"; 6612 case DW_AT_default_value: 6613 return "DW_AT_default_value"; 6614 case DW_AT_inline: 6615 return "DW_AT_inline"; 6616 case DW_AT_is_optional: 6617 return "DW_AT_is_optional"; 6618 case DW_AT_lower_bound: 6619 return "DW_AT_lower_bound"; 6620 case DW_AT_producer: 6621 return "DW_AT_producer"; 6622 case DW_AT_prototyped: 6623 return "DW_AT_prototyped"; 6624 case DW_AT_return_addr: 6625 return "DW_AT_return_addr"; 6626 case DW_AT_start_scope: 6627 return "DW_AT_start_scope"; 6628 case DW_AT_stride_size: 6629 return "DW_AT_stride_size"; 6630 case DW_AT_upper_bound: 6631 return "DW_AT_upper_bound"; 6632 case DW_AT_abstract_origin: 6633 return "DW_AT_abstract_origin"; 6634 case DW_AT_accessibility: 6635 return "DW_AT_accessibility"; 6636 case DW_AT_address_class: 6637 return "DW_AT_address_class"; 6638 case DW_AT_artificial: 6639 return "DW_AT_artificial"; 6640 case DW_AT_base_types: 6641 return "DW_AT_base_types"; 6642 case DW_AT_calling_convention: 6643 return "DW_AT_calling_convention"; 6644 case DW_AT_count: 6645 return "DW_AT_count"; 6646 case DW_AT_data_member_location: 6647 return "DW_AT_data_member_location"; 6648 case DW_AT_decl_column: 6649 return "DW_AT_decl_column"; 6650 case DW_AT_decl_file: 6651 return "DW_AT_decl_file"; 6652 case DW_AT_decl_line: 6653 return "DW_AT_decl_line"; 6654 case DW_AT_declaration: 6655 return "DW_AT_declaration"; 6656 case DW_AT_discr_list: 6657 return "DW_AT_discr_list"; 6658 case DW_AT_encoding: 6659 return "DW_AT_encoding"; 6660 case DW_AT_external: 6661 return "DW_AT_external"; 6662 case DW_AT_frame_base: 6663 return "DW_AT_frame_base"; 6664 case DW_AT_friend: 6665 return "DW_AT_friend"; 6666 case DW_AT_identifier_case: 6667 return "DW_AT_identifier_case"; 6668 case DW_AT_macro_info: 6669 return "DW_AT_macro_info"; 6670 case DW_AT_namelist_items: 6671 return "DW_AT_namelist_items"; 6672 case DW_AT_priority: 6673 return "DW_AT_priority"; 6674 case DW_AT_segment: 6675 return "DW_AT_segment"; 6676 case DW_AT_specification: 6677 return "DW_AT_specification"; 6678 case DW_AT_static_link: 6679 return "DW_AT_static_link"; 6680 case DW_AT_type: 6681 return "DW_AT_type"; 6682 case DW_AT_use_location: 6683 return "DW_AT_use_location"; 6684 case DW_AT_variable_parameter: 6685 return "DW_AT_variable_parameter"; 6686 case DW_AT_virtuality: 6687 return "DW_AT_virtuality"; 6688 case DW_AT_vtable_elem_location: 6689 return "DW_AT_vtable_elem_location"; 6690 case DW_AT_allocated: 6691 return "DW_AT_allocated"; 6692 case DW_AT_associated: 6693 return "DW_AT_associated"; 6694 case DW_AT_data_location: 6695 return "DW_AT_data_location"; 6696 case DW_AT_stride: 6697 return "DW_AT_stride"; 6698 case DW_AT_entry_pc: 6699 return "DW_AT_entry_pc"; 6700 case DW_AT_use_UTF8: 6701 return "DW_AT_use_UTF8"; 6702 case DW_AT_extension: 6703 return "DW_AT_extension"; 6704 case DW_AT_ranges: 6705 return "DW_AT_ranges"; 6706 case DW_AT_trampoline: 6707 return "DW_AT_trampoline"; 6708 case DW_AT_call_column: 6709 return "DW_AT_call_column"; 6710 case DW_AT_call_file: 6711 return "DW_AT_call_file"; 6712 case DW_AT_call_line: 6713 return "DW_AT_call_line"; 6714#ifdef MIPS 6715 case DW_AT_MIPS_fde: 6716 return "DW_AT_MIPS_fde"; 6717 case DW_AT_MIPS_loop_begin: 6718 return "DW_AT_MIPS_loop_begin"; 6719 case DW_AT_MIPS_tail_loop_begin: 6720 return "DW_AT_MIPS_tail_loop_begin"; 6721 case DW_AT_MIPS_epilog_begin: 6722 return "DW_AT_MIPS_epilog_begin"; 6723 case DW_AT_MIPS_loop_unroll_factor: 6724 return "DW_AT_MIPS_loop_unroll_factor"; 6725 case DW_AT_MIPS_software_pipeline_depth: 6726 return "DW_AT_MIPS_software_pipeline_depth"; 6727#endif 6728 case DW_AT_MIPS_linkage_name: 6729 return "DW_AT_MIPS_linkage_name"; 6730 6731 case DW_AT_sf_names: 6732 return "DW_AT_sf_names"; 6733 case DW_AT_src_info: 6734 return "DW_AT_src_info"; 6735 case DW_AT_mac_info: 6736 return "DW_AT_mac_info"; 6737 case DW_AT_src_coords: 6738 return "DW_AT_src_coords"; 6739 case DW_AT_body_begin: 6740 return "DW_AT_body_begin"; 6741 case DW_AT_body_end: 6742 return "DW_AT_body_end"; 6743 case DW_AT_GNU_vector: 6744 return "DW_AT_GNU_vector"; 6745 default: 6746 return "DW_AT_<unknown>"; 6747 } 6748} 6749 6750/* Convert a DWARF value form code into its string name. */ 6751 6752static char * 6753dwarf_form_name (unsigned form) 6754{ 6755 switch (form) 6756 { 6757 case DW_FORM_addr: 6758 return "DW_FORM_addr"; 6759 case DW_FORM_block2: 6760 return "DW_FORM_block2"; 6761 case DW_FORM_block4: 6762 return "DW_FORM_block4"; 6763 case DW_FORM_data2: 6764 return "DW_FORM_data2"; 6765 case DW_FORM_data4: 6766 return "DW_FORM_data4"; 6767 case DW_FORM_data8: 6768 return "DW_FORM_data8"; 6769 case DW_FORM_string: 6770 return "DW_FORM_string"; 6771 case DW_FORM_block: 6772 return "DW_FORM_block"; 6773 case DW_FORM_block1: 6774 return "DW_FORM_block1"; 6775 case DW_FORM_data1: 6776 return "DW_FORM_data1"; 6777 case DW_FORM_flag: 6778 return "DW_FORM_flag"; 6779 case DW_FORM_sdata: 6780 return "DW_FORM_sdata"; 6781 case DW_FORM_strp: 6782 return "DW_FORM_strp"; 6783 case DW_FORM_udata: 6784 return "DW_FORM_udata"; 6785 case DW_FORM_ref_addr: 6786 return "DW_FORM_ref_addr"; 6787 case DW_FORM_ref1: 6788 return "DW_FORM_ref1"; 6789 case DW_FORM_ref2: 6790 return "DW_FORM_ref2"; 6791 case DW_FORM_ref4: 6792 return "DW_FORM_ref4"; 6793 case DW_FORM_ref8: 6794 return "DW_FORM_ref8"; 6795 case DW_FORM_ref_udata: 6796 return "DW_FORM_ref_udata"; 6797 case DW_FORM_indirect: 6798 return "DW_FORM_indirect"; 6799 default: 6800 return "DW_FORM_<unknown>"; 6801 } 6802} 6803 6804/* Convert a DWARF stack opcode into its string name. */ 6805 6806static char * 6807dwarf_stack_op_name (unsigned op) 6808{ 6809 switch (op) 6810 { 6811 case DW_OP_addr: 6812 return "DW_OP_addr"; 6813 case DW_OP_deref: 6814 return "DW_OP_deref"; 6815 case DW_OP_const1u: 6816 return "DW_OP_const1u"; 6817 case DW_OP_const1s: 6818 return "DW_OP_const1s"; 6819 case DW_OP_const2u: 6820 return "DW_OP_const2u"; 6821 case DW_OP_const2s: 6822 return "DW_OP_const2s"; 6823 case DW_OP_const4u: 6824 return "DW_OP_const4u"; 6825 case DW_OP_const4s: 6826 return "DW_OP_const4s"; 6827 case DW_OP_const8u: 6828 return "DW_OP_const8u"; 6829 case DW_OP_const8s: 6830 return "DW_OP_const8s"; 6831 case DW_OP_constu: 6832 return "DW_OP_constu"; 6833 case DW_OP_consts: 6834 return "DW_OP_consts"; 6835 case DW_OP_dup: 6836 return "DW_OP_dup"; 6837 case DW_OP_drop: 6838 return "DW_OP_drop"; 6839 case DW_OP_over: 6840 return "DW_OP_over"; 6841 case DW_OP_pick: 6842 return "DW_OP_pick"; 6843 case DW_OP_swap: 6844 return "DW_OP_swap"; 6845 case DW_OP_rot: 6846 return "DW_OP_rot"; 6847 case DW_OP_xderef: 6848 return "DW_OP_xderef"; 6849 case DW_OP_abs: 6850 return "DW_OP_abs"; 6851 case DW_OP_and: 6852 return "DW_OP_and"; 6853 case DW_OP_div: 6854 return "DW_OP_div"; 6855 case DW_OP_minus: 6856 return "DW_OP_minus"; 6857 case DW_OP_mod: 6858 return "DW_OP_mod"; 6859 case DW_OP_mul: 6860 return "DW_OP_mul"; 6861 case DW_OP_neg: 6862 return "DW_OP_neg"; 6863 case DW_OP_not: 6864 return "DW_OP_not"; 6865 case DW_OP_or: 6866 return "DW_OP_or"; 6867 case DW_OP_plus: 6868 return "DW_OP_plus"; 6869 case DW_OP_plus_uconst: 6870 return "DW_OP_plus_uconst"; 6871 case DW_OP_shl: 6872 return "DW_OP_shl"; 6873 case DW_OP_shr: 6874 return "DW_OP_shr"; 6875 case DW_OP_shra: 6876 return "DW_OP_shra"; 6877 case DW_OP_xor: 6878 return "DW_OP_xor"; 6879 case DW_OP_bra: 6880 return "DW_OP_bra"; 6881 case DW_OP_eq: 6882 return "DW_OP_eq"; 6883 case DW_OP_ge: 6884 return "DW_OP_ge"; 6885 case DW_OP_gt: 6886 return "DW_OP_gt"; 6887 case DW_OP_le: 6888 return "DW_OP_le"; 6889 case DW_OP_lt: 6890 return "DW_OP_lt"; 6891 case DW_OP_ne: 6892 return "DW_OP_ne"; 6893 case DW_OP_skip: 6894 return "DW_OP_skip"; 6895 case DW_OP_lit0: 6896 return "DW_OP_lit0"; 6897 case DW_OP_lit1: 6898 return "DW_OP_lit1"; 6899 case DW_OP_lit2: 6900 return "DW_OP_lit2"; 6901 case DW_OP_lit3: 6902 return "DW_OP_lit3"; 6903 case DW_OP_lit4: 6904 return "DW_OP_lit4"; 6905 case DW_OP_lit5: 6906 return "DW_OP_lit5"; 6907 case DW_OP_lit6: 6908 return "DW_OP_lit6"; 6909 case DW_OP_lit7: 6910 return "DW_OP_lit7"; 6911 case DW_OP_lit8: 6912 return "DW_OP_lit8"; 6913 case DW_OP_lit9: 6914 return "DW_OP_lit9"; 6915 case DW_OP_lit10: 6916 return "DW_OP_lit10"; 6917 case DW_OP_lit11: 6918 return "DW_OP_lit11"; 6919 case DW_OP_lit12: 6920 return "DW_OP_lit12"; 6921 case DW_OP_lit13: 6922 return "DW_OP_lit13"; 6923 case DW_OP_lit14: 6924 return "DW_OP_lit14"; 6925 case DW_OP_lit15: 6926 return "DW_OP_lit15"; 6927 case DW_OP_lit16: 6928 return "DW_OP_lit16"; 6929 case DW_OP_lit17: 6930 return "DW_OP_lit17"; 6931 case DW_OP_lit18: 6932 return "DW_OP_lit18"; 6933 case DW_OP_lit19: 6934 return "DW_OP_lit19"; 6935 case DW_OP_lit20: 6936 return "DW_OP_lit20"; 6937 case DW_OP_lit21: 6938 return "DW_OP_lit21"; 6939 case DW_OP_lit22: 6940 return "DW_OP_lit22"; 6941 case DW_OP_lit23: 6942 return "DW_OP_lit23"; 6943 case DW_OP_lit24: 6944 return "DW_OP_lit24"; 6945 case DW_OP_lit25: 6946 return "DW_OP_lit25"; 6947 case DW_OP_lit26: 6948 return "DW_OP_lit26"; 6949 case DW_OP_lit27: 6950 return "DW_OP_lit27"; 6951 case DW_OP_lit28: 6952 return "DW_OP_lit28"; 6953 case DW_OP_lit29: 6954 return "DW_OP_lit29"; 6955 case DW_OP_lit30: 6956 return "DW_OP_lit30"; 6957 case DW_OP_lit31: 6958 return "DW_OP_lit31"; 6959 case DW_OP_reg0: 6960 return "DW_OP_reg0"; 6961 case DW_OP_reg1: 6962 return "DW_OP_reg1"; 6963 case DW_OP_reg2: 6964 return "DW_OP_reg2"; 6965 case DW_OP_reg3: 6966 return "DW_OP_reg3"; 6967 case DW_OP_reg4: 6968 return "DW_OP_reg4"; 6969 case DW_OP_reg5: 6970 return "DW_OP_reg5"; 6971 case DW_OP_reg6: 6972 return "DW_OP_reg6"; 6973 case DW_OP_reg7: 6974 return "DW_OP_reg7"; 6975 case DW_OP_reg8: 6976 return "DW_OP_reg8"; 6977 case DW_OP_reg9: 6978 return "DW_OP_reg9"; 6979 case DW_OP_reg10: 6980 return "DW_OP_reg10"; 6981 case DW_OP_reg11: 6982 return "DW_OP_reg11"; 6983 case DW_OP_reg12: 6984 return "DW_OP_reg12"; 6985 case DW_OP_reg13: 6986 return "DW_OP_reg13"; 6987 case DW_OP_reg14: 6988 return "DW_OP_reg14"; 6989 case DW_OP_reg15: 6990 return "DW_OP_reg15"; 6991 case DW_OP_reg16: 6992 return "DW_OP_reg16"; 6993 case DW_OP_reg17: 6994 return "DW_OP_reg17"; 6995 case DW_OP_reg18: 6996 return "DW_OP_reg18"; 6997 case DW_OP_reg19: 6998 return "DW_OP_reg19"; 6999 case DW_OP_reg20: 7000 return "DW_OP_reg20"; 7001 case DW_OP_reg21: 7002 return "DW_OP_reg21"; 7003 case DW_OP_reg22: 7004 return "DW_OP_reg22"; 7005 case DW_OP_reg23: 7006 return "DW_OP_reg23"; 7007 case DW_OP_reg24: 7008 return "DW_OP_reg24"; 7009 case DW_OP_reg25: 7010 return "DW_OP_reg25"; 7011 case DW_OP_reg26: 7012 return "DW_OP_reg26"; 7013 case DW_OP_reg27: 7014 return "DW_OP_reg27"; 7015 case DW_OP_reg28: 7016 return "DW_OP_reg28"; 7017 case DW_OP_reg29: 7018 return "DW_OP_reg29"; 7019 case DW_OP_reg30: 7020 return "DW_OP_reg30"; 7021 case DW_OP_reg31: 7022 return "DW_OP_reg31"; 7023 case DW_OP_breg0: 7024 return "DW_OP_breg0"; 7025 case DW_OP_breg1: 7026 return "DW_OP_breg1"; 7027 case DW_OP_breg2: 7028 return "DW_OP_breg2"; 7029 case DW_OP_breg3: 7030 return "DW_OP_breg3"; 7031 case DW_OP_breg4: 7032 return "DW_OP_breg4"; 7033 case DW_OP_breg5: 7034 return "DW_OP_breg5"; 7035 case DW_OP_breg6: 7036 return "DW_OP_breg6"; 7037 case DW_OP_breg7: 7038 return "DW_OP_breg7"; 7039 case DW_OP_breg8: 7040 return "DW_OP_breg8"; 7041 case DW_OP_breg9: 7042 return "DW_OP_breg9"; 7043 case DW_OP_breg10: 7044 return "DW_OP_breg10"; 7045 case DW_OP_breg11: 7046 return "DW_OP_breg11"; 7047 case DW_OP_breg12: 7048 return "DW_OP_breg12"; 7049 case DW_OP_breg13: 7050 return "DW_OP_breg13"; 7051 case DW_OP_breg14: 7052 return "DW_OP_breg14"; 7053 case DW_OP_breg15: 7054 return "DW_OP_breg15"; 7055 case DW_OP_breg16: 7056 return "DW_OP_breg16"; 7057 case DW_OP_breg17: 7058 return "DW_OP_breg17"; 7059 case DW_OP_breg18: 7060 return "DW_OP_breg18"; 7061 case DW_OP_breg19: 7062 return "DW_OP_breg19"; 7063 case DW_OP_breg20: 7064 return "DW_OP_breg20"; 7065 case DW_OP_breg21: 7066 return "DW_OP_breg21"; 7067 case DW_OP_breg22: 7068 return "DW_OP_breg22"; 7069 case DW_OP_breg23: 7070 return "DW_OP_breg23"; 7071 case DW_OP_breg24: 7072 return "DW_OP_breg24"; 7073 case DW_OP_breg25: 7074 return "DW_OP_breg25"; 7075 case DW_OP_breg26: 7076 return "DW_OP_breg26"; 7077 case DW_OP_breg27: 7078 return "DW_OP_breg27"; 7079 case DW_OP_breg28: 7080 return "DW_OP_breg28"; 7081 case DW_OP_breg29: 7082 return "DW_OP_breg29"; 7083 case DW_OP_breg30: 7084 return "DW_OP_breg30"; 7085 case DW_OP_breg31: 7086 return "DW_OP_breg31"; 7087 case DW_OP_regx: 7088 return "DW_OP_regx"; 7089 case DW_OP_fbreg: 7090 return "DW_OP_fbreg"; 7091 case DW_OP_bregx: 7092 return "DW_OP_bregx"; 7093 case DW_OP_piece: 7094 return "DW_OP_piece"; 7095 case DW_OP_deref_size: 7096 return "DW_OP_deref_size"; 7097 case DW_OP_xderef_size: 7098 return "DW_OP_xderef_size"; 7099 case DW_OP_nop: 7100 return "DW_OP_nop"; 7101 /* DWARF 3 extensions. */ 7102 case DW_OP_push_object_address: 7103 return "DW_OP_push_object_address"; 7104 case DW_OP_call2: 7105 return "DW_OP_call2"; 7106 case DW_OP_call4: 7107 return "DW_OP_call4"; 7108 case DW_OP_call_ref: 7109 return "DW_OP_call_ref"; 7110 /* GNU extensions. */ 7111 case DW_OP_GNU_push_tls_address: 7112 return "DW_OP_GNU_push_tls_address"; 7113 default: 7114 return "OP_<unknown>"; 7115 } 7116} 7117 7118static char * 7119dwarf_bool_name (unsigned mybool) 7120{ 7121 if (mybool) 7122 return "TRUE"; 7123 else 7124 return "FALSE"; 7125} 7126 7127/* Convert a DWARF type code into its string name. */ 7128 7129static char * 7130dwarf_type_encoding_name (unsigned enc) 7131{ 7132 switch (enc) 7133 { 7134 case DW_ATE_address: 7135 return "DW_ATE_address"; 7136 case DW_ATE_boolean: 7137 return "DW_ATE_boolean"; 7138 case DW_ATE_complex_float: 7139 return "DW_ATE_complex_float"; 7140 case DW_ATE_float: 7141 return "DW_ATE_float"; 7142 case DW_ATE_signed: 7143 return "DW_ATE_signed"; 7144 case DW_ATE_signed_char: 7145 return "DW_ATE_signed_char"; 7146 case DW_ATE_unsigned: 7147 return "DW_ATE_unsigned"; 7148 case DW_ATE_unsigned_char: 7149 return "DW_ATE_unsigned_char"; 7150 case DW_ATE_imaginary_float: 7151 return "DW_ATE_imaginary_float"; 7152 default: 7153 return "DW_ATE_<unknown>"; 7154 } 7155} 7156 7157/* Convert a DWARF call frame info operation to its string name. */ 7158 7159#if 0 7160static char * 7161dwarf_cfi_name (unsigned cfi_opc) 7162{ 7163 switch (cfi_opc) 7164 { 7165 case DW_CFA_advance_loc: 7166 return "DW_CFA_advance_loc"; 7167 case DW_CFA_offset: 7168 return "DW_CFA_offset"; 7169 case DW_CFA_restore: 7170 return "DW_CFA_restore"; 7171 case DW_CFA_nop: 7172 return "DW_CFA_nop"; 7173 case DW_CFA_set_loc: 7174 return "DW_CFA_set_loc"; 7175 case DW_CFA_advance_loc1: 7176 return "DW_CFA_advance_loc1"; 7177 case DW_CFA_advance_loc2: 7178 return "DW_CFA_advance_loc2"; 7179 case DW_CFA_advance_loc4: 7180 return "DW_CFA_advance_loc4"; 7181 case DW_CFA_offset_extended: 7182 return "DW_CFA_offset_extended"; 7183 case DW_CFA_restore_extended: 7184 return "DW_CFA_restore_extended"; 7185 case DW_CFA_undefined: 7186 return "DW_CFA_undefined"; 7187 case DW_CFA_same_value: 7188 return "DW_CFA_same_value"; 7189 case DW_CFA_register: 7190 return "DW_CFA_register"; 7191 case DW_CFA_remember_state: 7192 return "DW_CFA_remember_state"; 7193 case DW_CFA_restore_state: 7194 return "DW_CFA_restore_state"; 7195 case DW_CFA_def_cfa: 7196 return "DW_CFA_def_cfa"; 7197 case DW_CFA_def_cfa_register: 7198 return "DW_CFA_def_cfa_register"; 7199 case DW_CFA_def_cfa_offset: 7200 return "DW_CFA_def_cfa_offset"; 7201 7202 /* DWARF 3 */ 7203 case DW_CFA_def_cfa_expression: 7204 return "DW_CFA_def_cfa_expression"; 7205 case DW_CFA_expression: 7206 return "DW_CFA_expression"; 7207 case DW_CFA_offset_extended_sf: 7208 return "DW_CFA_offset_extended_sf"; 7209 case DW_CFA_def_cfa_sf: 7210 return "DW_CFA_def_cfa_sf"; 7211 case DW_CFA_def_cfa_offset_sf: 7212 return "DW_CFA_def_cfa_offset_sf"; 7213 7214 /* SGI/MIPS specific */ 7215 case DW_CFA_MIPS_advance_loc8: 7216 return "DW_CFA_MIPS_advance_loc8"; 7217 7218 /* GNU extensions */ 7219 case DW_CFA_GNU_window_save: 7220 return "DW_CFA_GNU_window_save"; 7221 case DW_CFA_GNU_args_size: 7222 return "DW_CFA_GNU_args_size"; 7223 case DW_CFA_GNU_negative_offset_extended: 7224 return "DW_CFA_GNU_negative_offset_extended"; 7225 7226 default: 7227 return "DW_CFA_<unknown>"; 7228 } 7229} 7230#endif 7231 7232static void 7233dump_die (struct die_info *die) 7234{ 7235 unsigned int i; 7236 7237 fprintf_unfiltered (gdb_stderr, "Die: %s (abbrev = %d, offset = %d)\n", 7238 dwarf_tag_name (die->tag), die->abbrev, die->offset); 7239 fprintf_unfiltered (gdb_stderr, "\thas children: %s\n", 7240 dwarf_bool_name (die->child != NULL)); 7241 7242 fprintf_unfiltered (gdb_stderr, "\tattributes:\n"); 7243 for (i = 0; i < die->num_attrs; ++i) 7244 { 7245 fprintf_unfiltered (gdb_stderr, "\t\t%s (%s) ", 7246 dwarf_attr_name (die->attrs[i].name), 7247 dwarf_form_name (die->attrs[i].form)); 7248 switch (die->attrs[i].form) 7249 { 7250 case DW_FORM_ref_addr: 7251 case DW_FORM_addr: 7252 fprintf_unfiltered (gdb_stderr, "address: "); 7253 print_address_numeric (DW_ADDR (&die->attrs[i]), 1, gdb_stderr); 7254 break; 7255 case DW_FORM_block2: 7256 case DW_FORM_block4: 7257 case DW_FORM_block: 7258 case DW_FORM_block1: 7259 fprintf_unfiltered (gdb_stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size); 7260 break; 7261 case DW_FORM_data1: 7262 case DW_FORM_data2: 7263 case DW_FORM_data4: 7264 case DW_FORM_data8: 7265 case DW_FORM_ref1: 7266 case DW_FORM_ref2: 7267 case DW_FORM_ref4: 7268 case DW_FORM_udata: 7269 case DW_FORM_sdata: 7270 fprintf_unfiltered (gdb_stderr, "constant: %ld", DW_UNSND (&die->attrs[i])); 7271 break; 7272 case DW_FORM_string: 7273 case DW_FORM_strp: 7274 fprintf_unfiltered (gdb_stderr, "string: \"%s\"", 7275 DW_STRING (&die->attrs[i]) 7276 ? DW_STRING (&die->attrs[i]) : ""); 7277 break; 7278 case DW_FORM_flag: 7279 if (DW_UNSND (&die->attrs[i])) 7280 fprintf_unfiltered (gdb_stderr, "flag: TRUE"); 7281 else 7282 fprintf_unfiltered (gdb_stderr, "flag: FALSE"); 7283 break; 7284 case DW_FORM_flag_present: 7285 fprintf_unfiltered (gdb_stderr, "flag: TRUE"); 7286 break; 7287 case DW_FORM_indirect: 7288 /* the reader will have reduced the indirect form to 7289 the "base form" so this form should not occur */ 7290 fprintf_unfiltered (gdb_stderr, "unexpected attribute form: DW_FORM_indirect"); 7291 break; 7292 default: 7293 fprintf_unfiltered (gdb_stderr, "unsupported attribute form: %d.", 7294 die->attrs[i].form); 7295 } 7296 fprintf_unfiltered (gdb_stderr, "\n"); 7297 } 7298} 7299 7300static void 7301dump_die_list (struct die_info *die) 7302{ 7303 while (die) 7304 { 7305 dump_die (die); 7306 if (die->child != NULL) 7307 dump_die_list (die->child); 7308 if (die->sibling != NULL) 7309 dump_die_list (die->sibling); 7310 } 7311} 7312 7313static void 7314store_in_ref_table (unsigned int offset, struct die_info *die) 7315{ 7316 int h; 7317 struct die_info *old; 7318 7319 h = (offset % REF_HASH_SIZE); 7320 old = die_ref_table[h]; 7321 die->next_ref = old; 7322 die_ref_table[h] = die; 7323} 7324 7325 7326static void 7327dwarf2_empty_hash_tables (void) 7328{ 7329 memset (die_ref_table, 0, sizeof (die_ref_table)); 7330} 7331 7332static unsigned int 7333dwarf2_get_ref_die_offset (struct attribute *attr, struct dwarf2_cu *cu) 7334{ 7335 unsigned int result = 0; 7336 7337 switch (attr->form) 7338 { 7339 case DW_FORM_ref_addr: 7340 result = DW_ADDR (attr); 7341 break; 7342 case DW_FORM_ref1: 7343 case DW_FORM_ref2: 7344 case DW_FORM_ref4: 7345 case DW_FORM_ref8: 7346 case DW_FORM_ref_udata: 7347 result = cu->header.offset + DW_UNSND (attr); 7348 break; 7349 default: 7350 complaint (&symfile_complaints, 7351 "unsupported die ref attribute form: '%s'", 7352 dwarf_form_name (attr->form)); 7353 } 7354 return result; 7355} 7356 7357/* Return the constant value held by the given attribute. Return -1 7358 if the value held by the attribute is not constant. */ 7359 7360static int 7361dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) 7362{ 7363 if (attr->form == DW_FORM_sdata) 7364 return DW_SND (attr); 7365 else if (attr->form == DW_FORM_udata 7366 || attr->form == DW_FORM_data1 7367 || attr->form == DW_FORM_data2 7368 || attr->form == DW_FORM_data4 7369 || attr->form == DW_FORM_data8) 7370 return DW_UNSND (attr); 7371 else 7372 { 7373 complaint (&symfile_complaints, "Attribute value is not a constant (%s)", 7374 dwarf_form_name (attr->form)); 7375 return default_value; 7376 } 7377} 7378 7379static struct die_info * 7380follow_die_ref (unsigned int offset) 7381{ 7382 struct die_info *die; 7383 int h; 7384 7385 h = (offset % REF_HASH_SIZE); 7386 die = die_ref_table[h]; 7387 while (die) 7388 { 7389 if (die->offset == offset) 7390 { 7391 return die; 7392 } 7393 die = die->next_ref; 7394 } 7395 return NULL; 7396} 7397 7398static struct type * 7399dwarf2_fundamental_type (struct objfile *objfile, int typeid, 7400 struct dwarf2_cu *cu) 7401{ 7402 if (typeid < 0 || typeid >= FT_NUM_MEMBERS) 7403 { 7404 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]", 7405 typeid, objfile->name); 7406 } 7407 7408 /* Look for this particular type in the fundamental type vector. If 7409 one is not found, create and install one appropriate for the 7410 current language and the current target machine. */ 7411 7412 if (cu->ftypes[typeid] == NULL) 7413 { 7414 cu->ftypes[typeid] = cu->language_defn->la_fund_type (objfile, typeid); 7415 } 7416 7417 return (cu->ftypes[typeid]); 7418} 7419 7420/* Decode simple location descriptions. 7421 Given a pointer to a dwarf block that defines a location, compute 7422 the location and return the value. 7423 7424 NOTE drow/2003-11-18: This function is called in two situations 7425 now: for the address of static or global variables (partial symbols 7426 only) and for offsets into structures which are expected to be 7427 (more or less) constant. The partial symbol case should go away, 7428 and only the constant case should remain. That will let this 7429 function complain more accurately. A few special modes are allowed 7430 without complaint for global variables (for instance, global 7431 register values and thread-local values). 7432 7433 A location description containing no operations indicates that the 7434 object is optimized out. The return value is 0 for that case. 7435 FIXME drow/2003-11-16: No callers check for this case any more; soon all 7436 callers will only want a very basic result and this can become a 7437 complaint. 7438 7439 When the result is a register number, the global isreg flag is set, 7440 otherwise it is cleared. 7441 7442 Note that stack[0] is unused except as a default error return. 7443 Note that stack overflow is not yet handled. */ 7444 7445static CORE_ADDR 7446decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) 7447{ 7448 struct objfile *objfile = cu->objfile; 7449 struct comp_unit_head *cu_header = &cu->header; 7450 int i; 7451 int size = blk->size; 7452 char *data = blk->data; 7453 CORE_ADDR stack[64]; 7454 int stacki; 7455 unsigned int bytes_read, unsnd; 7456 unsigned char op; 7457 7458 i = 0; 7459 stacki = 0; 7460 stack[stacki] = 0; 7461 isreg = 0; 7462 7463 while (i < size) 7464 { 7465 op = data[i++]; 7466 switch (op) 7467 { 7468 case DW_OP_lit0: 7469 case DW_OP_lit1: 7470 case DW_OP_lit2: 7471 case DW_OP_lit3: 7472 case DW_OP_lit4: 7473 case DW_OP_lit5: 7474 case DW_OP_lit6: 7475 case DW_OP_lit7: 7476 case DW_OP_lit8: 7477 case DW_OP_lit9: 7478 case DW_OP_lit10: 7479 case DW_OP_lit11: 7480 case DW_OP_lit12: 7481 case DW_OP_lit13: 7482 case DW_OP_lit14: 7483 case DW_OP_lit15: 7484 case DW_OP_lit16: 7485 case DW_OP_lit17: 7486 case DW_OP_lit18: 7487 case DW_OP_lit19: 7488 case DW_OP_lit20: 7489 case DW_OP_lit21: 7490 case DW_OP_lit22: 7491 case DW_OP_lit23: 7492 case DW_OP_lit24: 7493 case DW_OP_lit25: 7494 case DW_OP_lit26: 7495 case DW_OP_lit27: 7496 case DW_OP_lit28: 7497 case DW_OP_lit29: 7498 case DW_OP_lit30: 7499 case DW_OP_lit31: 7500 stack[++stacki] = op - DW_OP_lit0; 7501 break; 7502 7503 case DW_OP_reg0: 7504 case DW_OP_reg1: 7505 case DW_OP_reg2: 7506 case DW_OP_reg3: 7507 case DW_OP_reg4: 7508 case DW_OP_reg5: 7509 case DW_OP_reg6: 7510 case DW_OP_reg7: 7511 case DW_OP_reg8: 7512 case DW_OP_reg9: 7513 case DW_OP_reg10: 7514 case DW_OP_reg11: 7515 case DW_OP_reg12: 7516 case DW_OP_reg13: 7517 case DW_OP_reg14: 7518 case DW_OP_reg15: 7519 case DW_OP_reg16: 7520 case DW_OP_reg17: 7521 case DW_OP_reg18: 7522 case DW_OP_reg19: 7523 case DW_OP_reg20: 7524 case DW_OP_reg21: 7525 case DW_OP_reg22: 7526 case DW_OP_reg23: 7527 case DW_OP_reg24: 7528 case DW_OP_reg25: 7529 case DW_OP_reg26: 7530 case DW_OP_reg27: 7531 case DW_OP_reg28: 7532 case DW_OP_reg29: 7533 case DW_OP_reg30: 7534 case DW_OP_reg31: 7535 isreg = 1; 7536 stack[++stacki] = op - DW_OP_reg0; 7537 if (i < size) 7538 dwarf2_complex_location_expr_complaint (); 7539 break; 7540 7541 case DW_OP_regx: 7542 isreg = 1; 7543 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); 7544 i += bytes_read; 7545 stack[++stacki] = unsnd; 7546 if (i < size) 7547 dwarf2_complex_location_expr_complaint (); 7548 break; 7549 7550 case DW_OP_addr: 7551 stack[++stacki] = read_address (objfile->obfd, &data[i], 7552 cu, &bytes_read); 7553 i += bytes_read; 7554 break; 7555 7556 case DW_OP_const1u: 7557 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); 7558 i += 1; 7559 break; 7560 7561 case DW_OP_const1s: 7562 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); 7563 i += 1; 7564 break; 7565 7566 case DW_OP_const2u: 7567 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); 7568 i += 2; 7569 break; 7570 7571 case DW_OP_const2s: 7572 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); 7573 i += 2; 7574 break; 7575 7576 case DW_OP_const4u: 7577 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); 7578 i += 4; 7579 break; 7580 7581 case DW_OP_const4s: 7582 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); 7583 i += 4; 7584 break; 7585 7586 case DW_OP_constu: 7587 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), 7588 &bytes_read); 7589 i += bytes_read; 7590 break; 7591 7592 case DW_OP_consts: 7593 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); 7594 i += bytes_read; 7595 break; 7596 7597 case DW_OP_dup: 7598 stack[stacki + 1] = stack[stacki]; 7599 stacki++; 7600 break; 7601 7602 case DW_OP_plus: 7603 stack[stacki - 1] += stack[stacki]; 7604 stacki--; 7605 break; 7606 7607 case DW_OP_plus_uconst: 7608 stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read); 7609 i += bytes_read; 7610 break; 7611 7612 case DW_OP_minus: 7613 stack[stacki - 1] -= stack[stacki]; 7614 stacki--; 7615 break; 7616 7617 case DW_OP_deref: 7618 /* If we're not the last op, then we definitely can't encode 7619 this using GDB's address_class enum. This is valid for partial 7620 global symbols, although the variable's address will be bogus 7621 in the psymtab. */ 7622 if (i < size) 7623 dwarf2_complex_location_expr_complaint (); 7624 break; 7625 7626 case DW_OP_GNU_push_tls_address: 7627 /* The top of the stack has the offset from the beginning 7628 of the thread control block at which the variable is located. */ 7629 /* Nothing should follow this operator, so the top of stack would 7630 be returned. */ 7631 /* This is valid for partial global symbols, but the variable's 7632 address will be bogus in the psymtab. */ 7633 if (i < size) 7634 dwarf2_complex_location_expr_complaint (); 7635 break; 7636 7637 default: 7638 complaint (&symfile_complaints, "unsupported stack op: '%s'", 7639 dwarf_stack_op_name (op)); 7640 return (stack[stacki]); 7641 } 7642 } 7643 return (stack[stacki]); 7644} 7645 7646/* memory allocation interface */ 7647 7648static void 7649dwarf2_free_tmp_obstack (void *ignore) 7650{ 7651 obstack_free (&dwarf2_tmp_obstack, NULL); 7652} 7653 7654static struct dwarf_block * 7655dwarf_alloc_block (void) 7656{ 7657 struct dwarf_block *blk; 7658 7659 blk = (struct dwarf_block *) 7660 obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct dwarf_block)); 7661 return (blk); 7662} 7663 7664static struct abbrev_info * 7665dwarf_alloc_abbrev (void) 7666{ 7667 struct abbrev_info *abbrev; 7668 7669 abbrev = (struct abbrev_info *) xmalloc (sizeof (struct abbrev_info)); 7670 memset (abbrev, 0, sizeof (struct abbrev_info)); 7671 return (abbrev); 7672} 7673 7674static struct die_info * 7675dwarf_alloc_die (void) 7676{ 7677 struct die_info *die; 7678 7679 die = (struct die_info *) xmalloc (sizeof (struct die_info)); 7680 memset (die, 0, sizeof (struct die_info)); 7681 return (die); 7682} 7683 7684 7685/* Macro support. */ 7686 7687 7688/* Return the full name of file number I in *LH's file name table. 7689 Use COMP_DIR as the name of the current directory of the 7690 compilation. The result is allocated using xmalloc; the caller is 7691 responsible for freeing it. */ 7692static char * 7693file_full_name (int file, struct line_header *lh, const char *comp_dir) 7694{ 7695 struct file_entry *fe = &lh->file_names[file - 1]; 7696 7697 if (IS_ABSOLUTE_PATH (fe->name)) 7698 return xstrdup (fe->name); 7699 else 7700 { 7701 const char *dir; 7702 int dir_len; 7703 char *full_name; 7704 7705 if (fe->dir_index) 7706 dir = lh->include_dirs[fe->dir_index - 1]; 7707 else 7708 dir = comp_dir; 7709 7710 if (dir) 7711 { 7712 dir_len = strlen (dir); 7713 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); 7714 strcpy (full_name, dir); 7715 full_name[dir_len] = '/'; 7716 strcpy (full_name + dir_len + 1, fe->name); 7717 return full_name; 7718 } 7719 else 7720 return xstrdup (fe->name); 7721 } 7722} 7723 7724 7725static struct macro_source_file * 7726macro_start_file (int file, int line, 7727 struct macro_source_file *current_file, 7728 const char *comp_dir, 7729 struct line_header *lh, struct objfile *objfile) 7730{ 7731 /* The full name of this source file. */ 7732 char *full_name = file_full_name (file, lh, comp_dir); 7733 7734 /* We don't create a macro table for this compilation unit 7735 at all until we actually get a filename. */ 7736 if (! pending_macros) 7737 pending_macros = new_macro_table (&objfile->objfile_obstack, 7738 objfile->macro_cache); 7739 7740 if (! current_file) 7741 /* If we have no current file, then this must be the start_file 7742 directive for the compilation unit's main source file. */ 7743 current_file = macro_set_main (pending_macros, full_name); 7744 else 7745 current_file = macro_include (current_file, line, full_name); 7746 7747 xfree (full_name); 7748 7749 return current_file; 7750} 7751 7752 7753/* Copy the LEN characters at BUF to a xmalloc'ed block of memory, 7754 followed by a null byte. */ 7755static char * 7756copy_string (const char *buf, int len) 7757{ 7758 char *s = xmalloc (len + 1); 7759 memcpy (s, buf, len); 7760 s[len] = '\0'; 7761 7762 return s; 7763} 7764 7765 7766static const char * 7767consume_improper_spaces (const char *p, const char *body) 7768{ 7769 if (*p == ' ') 7770 { 7771 complaint (&symfile_complaints, 7772 "macro definition contains spaces in formal argument list:\n`%s'", 7773 body); 7774 7775 while (*p == ' ') 7776 p++; 7777 } 7778 7779 return p; 7780} 7781 7782 7783static void 7784parse_macro_definition (struct macro_source_file *file, int line, 7785 const char *body) 7786{ 7787 const char *p; 7788 7789 /* The body string takes one of two forms. For object-like macro 7790 definitions, it should be: 7791 7792 <macro name> " " <definition> 7793 7794 For function-like macro definitions, it should be: 7795 7796 <macro name> "() " <definition> 7797 or 7798 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> 7799 7800 Spaces may appear only where explicitly indicated, and in the 7801 <definition>. 7802 7803 The Dwarf 2 spec says that an object-like macro's name is always 7804 followed by a space, but versions of GCC around March 2002 omit 7805 the space when the macro's definition is the empty string. 7806 7807 The Dwarf 2 spec says that there should be no spaces between the 7808 formal arguments in a function-like macro's formal argument list, 7809 but versions of GCC around March 2002 include spaces after the 7810 commas. */ 7811 7812 7813 /* Find the extent of the macro name. The macro name is terminated 7814 by either a space or null character (for an object-like macro) or 7815 an opening paren (for a function-like macro). */ 7816 for (p = body; *p; p++) 7817 if (*p == ' ' || *p == '(') 7818 break; 7819 7820 if (*p == ' ' || *p == '\0') 7821 { 7822 /* It's an object-like macro. */ 7823 int name_len = p - body; 7824 char *name = copy_string (body, name_len); 7825 const char *replacement; 7826 7827 if (*p == ' ') 7828 replacement = body + name_len + 1; 7829 else 7830 { 7831 dwarf2_macro_malformed_definition_complaint (body); 7832 replacement = body + name_len; 7833 } 7834 7835 macro_define_object (file, line, name, replacement); 7836 7837 xfree (name); 7838 } 7839 else if (*p == '(') 7840 { 7841 /* It's a function-like macro. */ 7842 char *name = copy_string (body, p - body); 7843 int argc = 0; 7844 int argv_size = 1; 7845 char **argv = xmalloc (argv_size * sizeof (*argv)); 7846 7847 p++; 7848 7849 p = consume_improper_spaces (p, body); 7850 7851 /* Parse the formal argument list. */ 7852 while (*p && *p != ')') 7853 { 7854 /* Find the extent of the current argument name. */ 7855 const char *arg_start = p; 7856 7857 while (*p && *p != ',' && *p != ')' && *p != ' ') 7858 p++; 7859 7860 if (! *p || p == arg_start) 7861 dwarf2_macro_malformed_definition_complaint (body); 7862 else 7863 { 7864 /* Make sure argv has room for the new argument. */ 7865 if (argc >= argv_size) 7866 { 7867 argv_size *= 2; 7868 argv = xrealloc (argv, argv_size * sizeof (*argv)); 7869 } 7870 7871 argv[argc++] = copy_string (arg_start, p - arg_start); 7872 } 7873 7874 p = consume_improper_spaces (p, body); 7875 7876 /* Consume the comma, if present. */ 7877 if (*p == ',') 7878 { 7879 p++; 7880 7881 p = consume_improper_spaces (p, body); 7882 } 7883 } 7884 7885 if (*p == ')') 7886 { 7887 p++; 7888 7889 if (*p == ' ') 7890 /* Perfectly formed definition, no complaints. */ 7891 macro_define_function (file, line, name, 7892 argc, (const char **) argv, 7893 p + 1); 7894 else if (*p == '\0') 7895 { 7896 /* Complain, but do define it. */ 7897 dwarf2_macro_malformed_definition_complaint (body); 7898 macro_define_function (file, line, name, 7899 argc, (const char **) argv, 7900 p); 7901 } 7902 else 7903 /* Just complain. */ 7904 dwarf2_macro_malformed_definition_complaint (body); 7905 } 7906 else 7907 /* Just complain. */ 7908 dwarf2_macro_malformed_definition_complaint (body); 7909 7910 xfree (name); 7911 { 7912 int i; 7913 7914 for (i = 0; i < argc; i++) 7915 xfree (argv[i]); 7916 } 7917 xfree (argv); 7918 } 7919 else 7920 dwarf2_macro_malformed_definition_complaint (body); 7921} 7922 7923 7924static void 7925dwarf_decode_macros (struct line_header *lh, unsigned int offset, 7926 char *comp_dir, bfd *abfd, 7927 struct dwarf2_cu *cu) 7928{ 7929 char *mac_ptr, *mac_end; 7930 struct macro_source_file *current_file = 0; 7931 7932 if (dwarf_macinfo_buffer == NULL) 7933 { 7934 complaint (&symfile_complaints, "missing .debug_macinfo section"); 7935 return; 7936 } 7937 7938 mac_ptr = dwarf_macinfo_buffer + offset; 7939 mac_end = dwarf_macinfo_buffer + dwarf_macinfo_size; 7940 7941 for (;;) 7942 { 7943 enum dwarf_macinfo_record_type macinfo_type; 7944 7945 /* Do we at least have room for a macinfo type byte? */ 7946 if (mac_ptr >= mac_end) 7947 { 7948 dwarf2_macros_too_long_complaint (); 7949 return; 7950 } 7951 7952 macinfo_type = read_1_byte (abfd, mac_ptr); 7953 mac_ptr++; 7954 7955 switch (macinfo_type) 7956 { 7957 /* A zero macinfo type indicates the end of the macro 7958 information. */ 7959 case 0: 7960 return; 7961 7962 case DW_MACINFO_define: 7963 case DW_MACINFO_undef: 7964 { 7965 int bytes_read; 7966 int line; 7967 char *body; 7968 7969 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); 7970 mac_ptr += bytes_read; 7971 body = read_string (abfd, mac_ptr, &bytes_read); 7972 mac_ptr += bytes_read; 7973 7974 if (! current_file) 7975 complaint (&symfile_complaints, 7976 "debug info gives macro %s outside of any file: %s", 7977 macinfo_type == 7978 DW_MACINFO_define ? "definition" : macinfo_type == 7979 DW_MACINFO_undef ? "undefinition" : 7980 "something-or-other", body); 7981 else 7982 { 7983 if (macinfo_type == DW_MACINFO_define) 7984 parse_macro_definition (current_file, line, body); 7985 else if (macinfo_type == DW_MACINFO_undef) 7986 macro_undef (current_file, line, body); 7987 } 7988 } 7989 break; 7990 7991 case DW_MACINFO_start_file: 7992 { 7993 int bytes_read; 7994 int line, file; 7995 7996 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); 7997 mac_ptr += bytes_read; 7998 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); 7999 mac_ptr += bytes_read; 8000 8001 current_file = macro_start_file (file, line, 8002 current_file, comp_dir, 8003 lh, cu->objfile); 8004 } 8005 break; 8006 8007 case DW_MACINFO_end_file: 8008 if (! current_file) 8009 complaint (&symfile_complaints, 8010 "macro debug info has an unmatched `close_file' directive"); 8011 else 8012 { 8013 current_file = current_file->included_by; 8014 if (! current_file) 8015 { 8016 enum dwarf_macinfo_record_type next_type; 8017 8018 /* GCC circa March 2002 doesn't produce the zero 8019 type byte marking the end of the compilation 8020 unit. Complain if it's not there, but exit no 8021 matter what. */ 8022 8023 /* Do we at least have room for a macinfo type byte? */ 8024 if (mac_ptr >= mac_end) 8025 { 8026 dwarf2_macros_too_long_complaint (); 8027 return; 8028 } 8029 8030 /* We don't increment mac_ptr here, so this is just 8031 a look-ahead. */ 8032 next_type = read_1_byte (abfd, mac_ptr); 8033 if (next_type != 0) 8034 complaint (&symfile_complaints, 8035 "no terminating 0-type entry for macros in `.debug_macinfo' section"); 8036 8037 return; 8038 } 8039 } 8040 break; 8041 8042 case DW_MACINFO_vendor_ext: 8043 { 8044 int bytes_read; 8045 int constant; 8046 char *string; 8047 8048 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); 8049 mac_ptr += bytes_read; 8050 string = read_string (abfd, mac_ptr, &bytes_read); 8051 mac_ptr += bytes_read; 8052 8053 /* We don't recognize any vendor extensions. */ 8054 } 8055 break; 8056 } 8057 } 8058} 8059 8060/* Check if the attribute's form is a DW_FORM_block* 8061 if so return true else false. */ 8062static int 8063attr_form_is_block (struct attribute *attr) 8064{ 8065 return (attr == NULL ? 0 : 8066 attr->form == DW_FORM_block1 8067 || attr->form == DW_FORM_block2 8068 || attr->form == DW_FORM_block4 8069 || attr->form == DW_FORM_block); 8070} 8071 8072static void 8073dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, 8074 struct dwarf2_cu *cu) 8075{ 8076 if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) 8077 { 8078 struct dwarf2_loclist_baton *baton; 8079 8080 baton = obstack_alloc (&cu->objfile->objfile_obstack, 8081 sizeof (struct dwarf2_loclist_baton)); 8082 baton->objfile = cu->objfile; 8083 8084 /* We don't know how long the location list is, but make sure we 8085 don't run off the edge of the section. */ 8086 baton->size = dwarf_loc_size - DW_UNSND (attr); 8087 baton->data = dwarf_loc_buffer + DW_UNSND (attr); 8088 baton->base_address = cu->header.base_address; 8089 if (cu->header.base_known == 0) 8090 complaint (&symfile_complaints, 8091 "Location list used without specifying the CU base address."); 8092 8093 SYMBOL_OPS (sym) = &dwarf2_loclist_funcs; 8094 SYMBOL_LOCATION_BATON (sym) = baton; 8095 } 8096 else 8097 { 8098 struct dwarf2_locexpr_baton *baton; 8099 8100 baton = obstack_alloc (&cu->objfile->objfile_obstack, 8101 sizeof (struct dwarf2_locexpr_baton)); 8102 baton->objfile = cu->objfile; 8103 8104 if (attr_form_is_block (attr)) 8105 { 8106 /* Note that we're just copying the block's data pointer 8107 here, not the actual data. We're still pointing into the 8108 dwarf_info_buffer for SYM's objfile; right now we never 8109 release that buffer, but when we do clean up properly 8110 this may need to change. */ 8111 baton->size = DW_BLOCK (attr)->size; 8112 baton->data = DW_BLOCK (attr)->data; 8113 } 8114 else 8115 { 8116 dwarf2_invalid_attrib_class_complaint ("location description", 8117 SYMBOL_NATURAL_NAME (sym)); 8118 baton->size = 0; 8119 baton->data = NULL; 8120 } 8121 8122 SYMBOL_OPS (sym) = &dwarf2_locexpr_funcs; 8123 SYMBOL_LOCATION_BATON (sym) = baton; 8124 } 8125} 8126