#include "defs.h"
#include "bfd.h"
-#include "elf-bfd.h"
#include "symtab.h"
#include "gdbtypes.h"
#include "symfile.h"
whatever scope is currently getting read. */
static int address_size;
-/* Some elf32 object file formats while linked for a 32 bit address
- space contain debug information that has assumed 64 bit
- addresses. Eg 64 bit MIPS target produced by GCC/GAS/LD where the
- symbol table contains 32bit address values while its .debug_info
- section contains 64 bit address values.
- ADDRESS_SIGNIFICANT_SIZE specifies the number significant bits in
- the ADDRESS_SIZE bytes read from the file */
-static int address_significant_size;
-
/* Externals references. */
extern int info_verbose; /* From main.c; nonzero => verbose */
static void dwarf2_locate_sections PARAMS ((bfd *, asection *, PTR));
#if 0
-static void dwarf2_build_psymtabs_easy PARAMS ((struct objfile *,
- struct section_offsets *,
- int));
+static void dwarf2_build_psymtabs_easy PARAMS ((struct objfile *, int));
#endif
-static void dwarf2_build_psymtabs_hard PARAMS ((struct objfile *,
- struct section_offsets *,
- int));
+static void dwarf2_build_psymtabs_hard PARAMS ((struct objfile *, int));
static char *scan_partial_symbols PARAMS ((char *, struct objfile *,
CORE_ADDR *, CORE_ADDR *));
static struct attribute *dwarf_attr PARAMS ((struct die_info *,
unsigned int));
+static int die_is_declaration (struct die_info *);
+
static void dwarf_decode_lines PARAMS ((unsigned int, char *, bfd *));
static void dwarf2_start_subfile PARAMS ((char *, char *));
static void dwarf2_const_value PARAMS ((struct attribute *, struct symbol *,
struct objfile *));
+static void dwarf2_const_value_data (struct attribute *attr,
+ struct symbol *sym,
+ int bits);
+
static struct type *die_type PARAMS ((struct die_info *, struct objfile *));
static struct type *die_containing_type PARAMS ((struct die_info *,
struct type *,
struct objfile *));
-static char *skip_member_fn_name PARAMS ((char *));
-
static void dwarf2_add_member_fn PARAMS ((struct field_info *,
struct die_info *, struct type *,
struct objfile * objfile));
/* Build a partial symbol table. */
void
-dwarf2_build_psymtabs (objfile, section_offsets, mainline)
+dwarf2_build_psymtabs (objfile, mainline)
struct objfile *objfile;
- struct section_offsets *section_offsets;
int mainline;
{
#if 0
if (dwarf_aranges_offset && dwarf_pubnames_offset)
{
- /* Things are significanlty easier if we have .debug_aranges and
+ /* Things are significantly easier if we have .debug_aranges and
.debug_pubnames sections */
- dwarf2_build_psymtabs_easy (objfile, section_offsets, mainline);
+ dwarf2_build_psymtabs_easy (objfile, mainline);
}
else
#endif
/* only test this case for now */
{
/* In this case we have to work a bit harder */
- dwarf2_build_psymtabs_hard (objfile, section_offsets, mainline);
+ dwarf2_build_psymtabs_hard (objfile, mainline);
}
}
.debug_pubnames and .debug_aranges sections. */
static void
-dwarf2_build_psymtabs_easy (objfile, section_offsets, mainline)
+dwarf2_build_psymtabs_easy (objfile, mainline)
struct objfile *objfile;
- struct section_offsets *section_offsets;
int mainline;
{
bfd *abfd = objfile->obfd;
.debug_info and .debug_abbrev sections. */
static void
-dwarf2_build_psymtabs_hard (objfile, section_offsets, mainline)
+dwarf2_build_psymtabs_hard (objfile, mainline)
struct objfile *objfile;
- struct section_offsets *section_offsets;
int mainline;
{
/* Instead of reading this into a big buffer, we should probably use
int comp_unit_has_pc_info;
CORE_ADDR lowpc, highpc;
- /* Number of bytes of any addresses that are signficant */
- address_significant_size = get_elf_backend_data (abfd)->s->arch_size / 8;
-
info_ptr = dwarf_info_buffer;
abbrev_ptr = dwarf_abbrev_buffer;
(long) (beg_of_comp_unit - dwarf_info_buffer));
return;
}
- if (address_size < address_significant_size)
- {
- error ("Dwarf Error: bad address size (%ld) in compilation unit header (offset 0x%lx + 11).",
- (long) cu_header.addr_size,
- (long) (beg_of_comp_unit - dwarf_info_buffer));
- }
-
/* Read the abbrevs for this compilation unit into a table */
dwarf2_read_abbrevs (abfd, cu_header.abbrev_offset);
make_cleanup (dwarf2_empty_abbrev_table, NULL);
set_cu_language (comp_unit_die.language);
/* Allocate a new partial symbol table structure */
- pst = start_psymtab_common (objfile, section_offsets,
- comp_unit_die.name ? comp_unit_die.name : "",
+ pst = start_psymtab_common (objfile, objfile->section_offsets,
+ comp_unit_die.name ? comp_unit_die.name : "",
comp_unit_die.lowpc,
objfile->global_psymbols.next,
objfile->static_psymbols.next);
DWARF_ABBREV_BUFFER (pst) = dwarf_abbrev_buffer;
DWARF_ABBREV_SIZE (pst) = dwarf_abbrev_size;
DWARF_LINE_BUFFER (pst) = dwarf_line_buffer;
- baseaddr = ANOFFSET (section_offsets, 0);
+ baseaddr = ANOFFSET (objfile->section_offsets, 0);
/* Store the function that reads in the rest of the symbol table */
pst->read_symtab = dwarf2_psymtab_to_symtab;
int nesting_level = 1;
int has_pc_info;
- *lowpc = ((CORE_ADDR) - 1);
+ *lowpc = ((CORE_ADDR) -1);
*highpc = ((CORE_ADDR) 0);
while (nesting_level)
/* If we didn't find a lowpc, set it to highpc to avoid complaints
from `maint check'. */
- if (*lowpc == ((CORE_ADDR) - 1))
+ if (*lowpc == ((CORE_ADDR) -1))
*lowpc = *highpc;
return info_ptr;
}
back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
buildsym_init ();
- make_cleanup ((make_cleanup_func) really_free_pendings, NULL);
+ make_cleanup (really_free_pendings, NULL);
/* read in the comp_unit header */
cu_header.length = read_4_bytes (abfd, info_ptr);
struct objfile *objfile;
{
unsigned int line_offset = 0;
- CORE_ADDR lowpc = ((CORE_ADDR) - 1);
+ CORE_ADDR lowpc = ((CORE_ADDR) -1);
CORE_ADDR highpc = ((CORE_ADDR) 0);
struct attribute *attr;
char *name = "<unknown>";
/* If we didn't find a lowpc, set it to highpc to avoid complaints
from finish_block. */
- if (lowpc == ((CORE_ADDR) - 1))
+ if (lowpc == ((CORE_ADDR) -1))
lowpc = highpc;
lowpc += baseaddr;
highpc += baseaddr;
objfile->ei.entry_func_highpc = highpc;
}
- if (STREQ (name, "main")) /* FIXME: hardwired name */
- {
- objfile->ei.main_func_lowpc = lowpc;
- objfile->ei.main_func_highpc = highpc;
- }
-
/* Decode DW_AT_frame_base location descriptor if present, keep result
for DW_OP_fbreg operands in decode_locdesc. */
frame_base_reg = -1;
else if (die->tag == DW_TAG_variable)
{
char *physname;
- char *cp;
/* C++ static member.
- Get physical name, extract field name from physical name. */
- physname = dwarf2_linkage_name (die);
- if (physname == NULL)
+ Get name of field. */
+ attr = dwarf_attr (die, DW_AT_name);
+ if (attr && DW_STRING (attr))
+ fieldname = DW_STRING (attr);
+ else
return;
- cp = physname;
- while (*cp && !is_cplus_marker (*cp))
- cp++;
- if (*cp)
- fieldname = cp + 1;
- if (*fieldname == '\0')
- {
- complain (&dwarf2_bad_static_member_name, physname);
- }
+ /* Get physical name. */
+ physname = dwarf2_linkage_name (die);
SET_FIELD_PHYSNAME (*fp, obsavestring (physname, strlen (physname),
&objfile->type_obstack));
}
}
-/* Skip to the end of a member function name in a mangled name. */
-
-static char *
-skip_member_fn_name (physname)
- char *physname;
-{
- char *endname = physname;
-
- /* Skip over leading underscores. */
- while (*endname == '_')
- endname++;
-
- /* Find two succesive underscores. */
- do
- endname = strchr (endname, '_');
- while (endname != NULL && *++endname != '_');
-
- if (endname == NULL)
- {
- complain (&dwarf2_bad_member_name_complaint, physname);
- endname = physname;
- }
- else
- {
- /* Take care of trailing underscores. */
- if (endname[1] != '_')
- endname--;
- }
- return endname;
-}
-
/* Add a member function to the proper fieldlist. */
static void
char *physname;
struct nextfnfield *new_fnfield;
- /* Extract member function name from mangled name. */
- physname = dwarf2_linkage_name (die);
- if (physname == NULL)
- return;
- if ((physname[0] == '_' && physname[1] == '_'
- && strchr ("0123456789Qt", physname[2]))
- || DESTRUCTOR_PREFIX_P (physname))
- {
- /* Constructor and destructor field names are set to the name
- of the class, but without template parameter lists.
- The name might be missing for anonymous aggregates. */
- if (TYPE_TAG_NAME (type))
- {
- char *p = strchr (TYPE_TAG_NAME (type), '<');
-
- if (p == NULL)
- fieldname = TYPE_TAG_NAME (type);
- else
- fieldname = obsavestring (TYPE_TAG_NAME (type),
- p - TYPE_TAG_NAME (type),
- &objfile->type_obstack);
- }
- else
- {
- char *anon_name = "";
- fieldname = obsavestring (anon_name, strlen (anon_name),
- &objfile->type_obstack);
- }
- }
+ /* Get name of member function. */
+ attr = dwarf_attr (die, DW_AT_name);
+ if (attr && DW_STRING (attr))
+ fieldname = DW_STRING (attr);
else
- {
- char *endname = skip_member_fn_name (physname);
+ return;
- /* Ignore member function if we were unable not extract the member
- function name. */
- if (endname == physname)
- return;
- fieldname = obsavestring (physname, endname - physname,
- &objfile->type_obstack);
- }
+ /* Get the mangled name. */
+ physname = dwarf2_linkage_name (die);
/* Look up member function name in fieldlist. */
for (i = 0; i < fip->nfnfields; i++)
(fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
* sizeof (struct fnfieldlist));
if (fip->nfnfields == 0)
- make_cleanup ((make_cleanup_func) free_current_contents,
- &fip->fnfieldlists);
+ make_cleanup (free_current_contents, &fip->fnfieldlists);
}
flp = &fip->fnfieldlists[fip->nfnfields];
flp->name = fieldname;
type within the structure itself. */
die->type = type;
- if (die->has_children)
+ if (die->has_children && ! die_is_declaration (die))
{
struct field_info fi;
struct die_info *child_die;
xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
* sizeof (struct type *));
if (ndim == 0)
- make_cleanup ((make_cleanup_func) free_current_contents,
- &range_types);
+ make_cleanup (free_current_contents, &range_types);
}
range_types[ndim++] = create_range_type (NULL, index_type, low, high);
}
switch (address_size)
{
+ case 2:
+ retval = bfd_get_16 (abfd, (bfd_byte *) buf);
+ break;
case 4:
retval = bfd_get_32 (abfd, (bfd_byte *) buf);
break;
/* *THE* alternative is 8, right? */
abort ();
}
- /* If the address being read is larger than the address that is
- applicable for the object file format then mask it down to the
- correct size. Take care to avoid unnecessary shift or shift
- overflow */
- if (address_size > address_significant_size
- && address_significant_size < sizeof (CORE_ADDR))
- {
- CORE_ADDR mask = ((CORE_ADDR) 0) - 1;
- retval &= ~(mask << (address_significant_size * 8));
- }
- return retval;
+
+ return retval;
}
static char *
return NULL;
}
+static int
+die_is_declaration (struct die_info *die)
+{
+ return (dwarf_attr (die, DW_AT_declaration)
+ && ! dwarf_attr (die, DW_AT_specification));
+}
+
/* Decode the line number information for the compilation unit whose
line number info is at OFFSET in the .debug_line section.
The compilation directory of the file is passed in COMP_DIR. */
line_ptr += 1;
lh.standard_opcode_lengths = (unsigned char *)
xmalloc (lh.opcode_base * sizeof (unsigned char));
- back_to = make_cleanup ((make_cleanup_func) free_current_contents,
- &lh.standard_opcode_lengths);
+ back_to = make_cleanup (free_current_contents, &lh.standard_opcode_lengths);
lh.standard_opcode_lengths[0] = 1;
for (i = 1; i < lh.opcode_base; ++i)
xrealloc (dirs.dirs,
(dirs.num_dirs + DIR_ALLOC_CHUNK) * sizeof (char *));
if (dirs.num_dirs == 0)
- make_cleanup ((make_cleanup_func) free_current_contents, &dirs.dirs);
+ make_cleanup (free_current_contents, &dirs.dirs);
}
dirs.dirs[dirs.num_dirs++] = cur_dir;
}
(files.num_files + FILE_ALLOC_CHUNK)
* sizeof (struct fileinfo));
if (files.num_files == 0)
- make_cleanup ((make_cleanup_func) free_current_contents,
- &files.files);
+ make_cleanup (free_current_contents, &files.files);
}
files.files[files.num_files].name = cur_file;
files.files[files.num_files].dir =
(files.num_files + FILE_ALLOC_CHUNK)
* sizeof (struct fileinfo));
if (files.num_files == 0)
- make_cleanup ((make_cleanup_func) free_current_contents,
- &files.files);
+ make_cleanup (free_current_contents, &files.files);
}
files.files[files.num_files].name = cur_file;
files.files[files.num_files].dir =
case DW_LNS_set_basic_block:
basic_block = 1;
break;
+ /* Add to the address register of the state machine the
+ address increment value corresponding to special opcode
+ 255. Ie, this value is scaled by the minimum instruction
+ length since special opcode 255 would have scaled the
+ the increment. */
case DW_LNS_const_add_pc:
- address += (255 - lh.opcode_base) / lh.line_range;
+ address += (lh.minimum_instruction_length
+ * ((255 - lh.opcode_base) / lh.line_range));
break;
case DW_LNS_fixed_advance_pc:
address += read_2_bytes (abfd, line_ptr);
to make a symbol table entry for it, and if so, create a new entry
and return a pointer to it.
If TYPE is NULL, determine symbol type from the die, otherwise
- used the passed type.
- */
+ used the passed type. */
static struct symbol *
new_symbol (die, type, objfile)
memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
break;
+
+ /* The DW_AT_const_value attributes are supposed to carry the
+ symbol's value "represented as it would be on the target
+ architecture." By the time we get here, it's already been
+ converted to host endianness, so we just need to sign- or
+ zero-extend it as appropriate. */
+ case DW_FORM_data1:
+ dwarf2_const_value_data (attr, sym, 8);
+ break;
case DW_FORM_data2:
+ dwarf2_const_value_data (attr, sym, 16);
+ break;
case DW_FORM_data4:
+ dwarf2_const_value_data (attr, sym, 32);
+ break;
case DW_FORM_data8:
- case DW_FORM_data1:
+ dwarf2_const_value_data (attr, sym, 64);
+ break;
+
case DW_FORM_sdata:
+ SYMBOL_VALUE (sym) = DW_SND (attr);
+ SYMBOL_CLASS (sym) = LOC_CONST;
+ break;
+
case DW_FORM_udata:
SYMBOL_VALUE (sym) = DW_UNSND (attr);
SYMBOL_CLASS (sym) = LOC_CONST;
break;
+
default:
complain (&dwarf2_unsupported_const_value_attr,
dwarf_form_name (attr->form));
}
}
+
+/* Given an attr with a DW_FORM_dataN value in host byte order, sign-
+ or zero-extend it as appropriate for the symbol's type. */
+static void
+dwarf2_const_value_data (struct attribute *attr,
+ struct symbol *sym,
+ int bits)
+{
+ LONGEST l = DW_UNSND (attr);
+
+ if (bits < sizeof (l) * 8)
+ {
+ if (TYPE_UNSIGNED (SYMBOL_TYPE (sym)))
+ l &= ((LONGEST) 1 << bits) - 1;
+ else
+ l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits);
+ }
+
+ SYMBOL_VALUE (sym) = l;
+ SYMBOL_CLASS (sym) = LOC_CONST;
+}
+
+
/* Return the type of the die in question using its DW_AT_type attribute. */
static struct type *
i += bytes_read;
break;
+ case DW_OP_bregx:
+ offreg = 1;
+ basereg = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
+ i += bytes_read;
+ stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
+ i += bytes_read;
+ break;
+
case DW_OP_fbreg:
stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
i += bytes_read;