#endif
}
+/* A helper function that decides whether a section is empty. */
+
+static int
+dwarf2_section_empty_p (struct dwarf2_section_info *info)
+{
+ return info->asection == NULL || info->size == 0;
+}
+
/* Read the contents of the section SECTP from object file specified by
OBJFILE, store info about the section into INFO.
If the section is compressed, uncompress it before returning. */
info->was_mmapped = 0;
info->readin = 1;
- if (info->asection == NULL || info->size == 0)
+ if (dwarf2_section_empty_p (info))
return;
/* Check if the file has a 4-byte header indicating compression. */
bfd_get_filename (abfd));
}
+/* A helper function that returns the size of a section in a safe way.
+ If you are positive that the section has been read before using the
+ size, then it is safe to refer to the dwarf2_section_info object's
+ "size" field directly. In other cases, you must call this
+ function, because for compressed sections the size field is not set
+ correctly until the section has been read. */
+
+static bfd_size_type
+dwarf2_section_size (struct objfile *objfile,
+ struct dwarf2_section_info *info)
+{
+ if (!info->readin)
+ dwarf2_read_section (objfile, info);
+ return info->size;
+}
+
/* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
SECTION_NAME. */
else
gdb_assert_not_reached ("unexpected section");
- if (info->asection != NULL && info->size != 0 && info->buffer == NULL)
- /* We haven't read this section in yet. Do it now. */
- dwarf2_read_section (objfile, info);
+ dwarf2_read_section (objfile, info);
*sectp = info->asection;
*bufp = info->buffer;
offset_type types_list_elements = 0;
int i;
- if (dwarf2_per_objfile->gdb_index.asection == NULL
- || dwarf2_per_objfile->gdb_index.size == 0)
+ if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index))
return 0;
/* Older elfutils strip versions could keep the section in the main
/* Version check. */
version = MAYBE_SWAP (*(offset_type *) addr);
/* Versions earlier than 3 emitted every copy of a psymbol. This
- causes the index to behave very poorly for certain requests. So,
- it seems better to just ignore such indices. */
- if (version < 3)
+ causes the index to behave very poorly for certain requests. Version 4
+ contained incomplete addrmap. So, it seems better to just ignore such
+ indices. */
+ if (version < 4)
return 0;
/* Indexes with higher version than the one supported by GDB may be no
longer backward compatible. */
- if (version > 3)
+ if (version > 4)
return 0;
map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index);
if (this_cu->from_debug_types)
info_ptr += 8 /*signature*/ + cu.header.offset_size;
init_cu_die_reader (&reader_specs, &cu);
- info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
- &has_children);
+ read_full_die (&reader_specs, &comp_unit_die, info_ptr,
+ &has_children);
lh = NULL;
slot = NULL;
if (dwarf2_read_index (objfile))
return 1;
- dwarf2_build_psymtabs (objfile);
return 0;
}
"(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
bfd_get_filename (abfd));
- if (header->abbrev_offset >= dwarf2_per_objfile->abbrev.size)
+ if (header->abbrev_offset
+ >= dwarf2_section_size (dwarf2_per_objfile->objfile,
+ &dwarf2_per_objfile->abbrev))
error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
"(offset 0x%lx + 6) [in module %s]"),
(long) header->abbrev_offset,
struct attribute *attr;
CORE_ADDR best_lowpc = 0, best_highpc = 0;
struct die_reader_specs reader_specs;
+ const char *filename;
init_one_comp_unit (&cu, objfile);
back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
/* Allocate a new partial symbol table structure. */
attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu);
+ if (attr == NULL || !DW_STRING (attr))
+ filename = "";
+ else
+ filename = DW_STRING (attr);
pst = start_psymtab_common (objfile, objfile->section_offsets,
- (attr != NULL) ? DW_STRING (attr) : "",
+ filename,
/* TEXTLOW and TEXTHIGH are set below. */
0,
objfile->global_psymbols.next,
of the global scope. But in Ada, we want to be able to access
nested procedures globally. So all Ada subprograms are stored
in the global scope. */
- /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
+ /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
mst_text, objfile); */
- psym = add_psymbol_to_list (actual_name, strlen (actual_name),
- built_actual_name,
- VAR_DOMAIN, LOC_BLOCK,
- &objfile->global_psymbols,
- 0, pdi->lowpc + baseaddr,
- cu->language, objfile);
+ add_psymbol_to_list (actual_name, strlen (actual_name),
+ built_actual_name,
+ VAR_DOMAIN, LOC_BLOCK,
+ &objfile->global_psymbols,
+ 0, pdi->lowpc + baseaddr,
+ cu->language, objfile);
}
else
{
- /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
+ /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
mst_file_text, objfile); */
- psym = add_psymbol_to_list (actual_name, strlen (actual_name),
- built_actual_name,
- VAR_DOMAIN, LOC_BLOCK,
- &objfile->static_psymbols,
- 0, pdi->lowpc + baseaddr,
- cu->language, objfile);
+ add_psymbol_to_list (actual_name, strlen (actual_name),
+ built_actual_name,
+ VAR_DOMAIN, LOC_BLOCK,
+ &objfile->static_psymbols,
+ 0, pdi->lowpc + baseaddr,
+ cu->language, objfile);
}
break;
case DW_TAG_constant:
list = &objfile->global_psymbols;
else
list = &objfile->static_psymbols;
- psym = add_psymbol_to_list (actual_name, strlen (actual_name),
- built_actual_name, VAR_DOMAIN, LOC_STATIC,
- list, 0, 0, cu->language, objfile);
-
+ add_psymbol_to_list (actual_name, strlen (actual_name),
+ built_actual_name, VAR_DOMAIN, LOC_STATIC,
+ list, 0, 0, cu->language, objfile);
}
break;
case DW_TAG_variable:
table building. */
if (pdi->locdesc || pdi->has_type)
- psym = add_psymbol_to_list (actual_name, strlen (actual_name),
- built_actual_name,
- VAR_DOMAIN, LOC_STATIC,
- &objfile->global_psymbols,
- 0, addr + baseaddr,
- cu->language, objfile);
+ add_psymbol_to_list (actual_name, strlen (actual_name),
+ built_actual_name,
+ VAR_DOMAIN, LOC_STATIC,
+ &objfile->global_psymbols,
+ 0, addr + baseaddr,
+ cu->language, objfile);
}
else
{
xfree (actual_name);
return;
}
- /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
+ /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
mst_file_data, objfile); */
- psym = add_psymbol_to_list (actual_name, strlen (actual_name),
- built_actual_name,
- VAR_DOMAIN, LOC_STATIC,
- &objfile->static_psymbols,
- 0, addr + baseaddr,
- cu->language, objfile);
+ add_psymbol_to_list (actual_name, strlen (actual_name),
+ built_actual_name,
+ VAR_DOMAIN, LOC_STATIC,
+ &objfile->static_psymbols,
+ 0, addr + baseaddr,
+ cu->language, objfile);
}
break;
case DW_TAG_typedef:
xfree (prefixed_name);
}
else
- fputs_unfiltered (name ? name : "", buf);
+ fputs_unfiltered (name, buf);
/* Template parameters may be specified in the DIE's DW_AT_name, or
as children with DW_TAG_template_type_param or
return 0;
}
+ if (range_beginning > range_end)
+ {
+ /* Inverted range entries are invalid. */
+ complaint (&symfile_complaints,
+ _("Invalid .debug_ranges data (inverted range)"));
+ return 0;
+ }
+
+ /* Empty range entries have no effect. */
+ if (range_beginning == range_end)
+ continue;
+
range_beginning += base;
range_end += base;
- if (ranges_pst != NULL && range_beginning < range_end)
+ if (ranges_pst != NULL)
addrmap_set_empty (objfile->psymtabs_addrmap,
range_beginning + baseaddr,
range_end - 1 + baseaddr,
}
}
- if (high < low)
+ /* read_partial_die has also the strict LOW < HIGH requirement. */
+ if (high <= low)
return 0;
/* When using the GNU linker, .gnu.linkonce. sections are used to
return;
}
+ if (start > end)
+ {
+ /* Inverted range entries are invalid. */
+ complaint (&symfile_complaints,
+ _("Invalid .debug_ranges data "
+ "(inverted range)"));
+ return;
+ }
+
+ /* Empty range entries have no effect. */
+ if (start == end)
+ continue;
+
record_block_range (block,
baseaddr + base + start,
baseaddr + base + end - 1);
struct dwarf2_cu *cu)
{
struct objfile *objfile = cu->objfile;
- struct gdbarch *gdbarch = get_objfile_arch (objfile);
struct typedef_field_list *new_field;
struct attribute *attr;
struct typedef_field *fp;
case DW_VIRTUALITY_virtual:
case DW_VIRTUALITY_pure_virtual:
if (cu->language == language_ada)
- error ("unexpected virtuality in component of Ada type");
+ error (_("unexpected virtuality in component of Ada type"));
SET_TYPE_FIELD_VIRTUAL (type, nfields);
break;
}
struct type *this_type;
if (cu->language == language_ada)
- error ("unexpected member function in Ada type");
+ error (_("unexpected member function in Ada type"));
/* Get name of member function. */
fieldname = dwarf2_name (die, cu);
int i;
if (cu->language == language_ada)
- error ("unexpected member functions in Ada type");
+ error (_("unexpected member functions in Ada type"));
ALLOCATE_CPLUS_STRUCT_TYPE (type);
TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
read_namespace (struct die_info *die, struct dwarf2_cu *cu)
{
struct objfile *objfile = cu->objfile;
- const char *name;
int is_anonymous;
/* Add a symbol associated to this if we haven't seen the namespace
type = read_type_die (die, cu);
new_symbol (die, type, cu);
- name = namespace_name (die, &is_anonymous, cu);
+ namespace_name (die, &is_anonymous, cu);
if (is_anonymous)
{
const char *previous_prefix = determine_prefix (die, cu);
the subroutine die. Otherwise set the calling convention to
the default value DW_CC_normal. */
attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
- TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal;
+ if (attr)
+ TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr);
+ else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL"))
+ TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL;
+ else
+ TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal;
/* We need to add the subroutine type to the die immediately so
we don't infinitely recurse when dealing with parameters
static struct type *
read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
{
- struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
struct type *base_type;
struct type *range_type;
struct attribute *attr;
int count = dwarf2_get_attr_constant_value (attr, 1);
high = low + count - 1;
}
+ else
+ {
+ /* Unspecified array length. */
+ high = low - 1;
+ }
}
/* Dwarf-2 specifications explicitly allows to create subrange types
if (attr && attr->form == DW_FORM_block1)
TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
+ /* Ada expects an empty array on no boundary attributes. */
+ if (attr == NULL && cu->language != language_ada)
+ TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
+
name = dwarf2_name (die, cu);
if (name)
TYPE_NAME (range_type) = name;
}
}
- /* When using the GNU linker, .gnu.linkonce. sections are used to
- eliminate duplicate copies of functions and vtables and such.
- The linker will arbitrarily choose one and discard the others.
- The AT_*_pc values for such functions refer to local labels in
- these sections. If the section from that file was discarded, the
- labels are not in the output, so the relocs get a value of 0.
- If this is a discarded function, mark the pc bounds as invalid,
- so that GDB will ignore it. */
- if (has_low_pc_attr && has_high_pc_attr
- && part_die->lowpc < part_die->highpc
- && (part_die->lowpc != 0
- || dwarf2_per_objfile->has_section_at_zero))
- part_die->has_pc_info = 1;
+ if (has_low_pc_attr && has_high_pc_attr)
+ {
+ /* When using the GNU linker, .gnu.linkonce. sections are used to
+ eliminate duplicate copies of functions and vtables and such.
+ The linker will arbitrarily choose one and discard the others.
+ The AT_*_pc values for such functions refer to local labels in
+ these sections. If the section from that file was discarded, the
+ labels are not in the output, so the relocs get a value of 0.
+ If this is a discarded function, mark the pc bounds as invalid,
+ so that GDB will ignore it. */
+ if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero)
+ {
+ struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
+
+ complaint (&symfile_complaints,
+ _("DW_AT_low_pc %s is zero "
+ "for DIE at 0x%x [in module %s]"),
+ paddress (gdbarch, part_die->lowpc),
+ part_die->offset, cu->objfile->name);
+ }
+ /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
+ else if (part_die->lowpc >= part_die->highpc)
+ {
+ struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
+
+ complaint (&symfile_complaints,
+ _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
+ "for DIE at 0x%x [in module %s]"),
+ paddress (gdbarch, part_die->lowpc),
+ paddress (gdbarch, part_die->highpc),
+ part_die->offset, cu->objfile->name);
+ }
+ else
+ part_die->has_pc_info = 1;
+ }
return info_ptr;
}
break;
default:
internal_error (__FILE__, __LINE__,
- _("read_address: bad switch, unsigned [in module %s]"),
+ _("read_address: bad switch, "
+ "unsigned [in module %s]"),
bfd_get_filename (abfd));
}
}
return include_name;
}
+/* Ignore this record_line request. */
+
+static void
+noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc)
+{
+ return;
+}
+
/* Decode the Line Number Program (LNP) for the given line_header
structure and CU. The actual information extracted and the type
of structures created from the LNP depends on the value of PST.
struct gdbarch *gdbarch = get_objfile_arch (objfile);
const int decode_for_pst_p = (pst != NULL);
struct subfile *last_subfile = NULL, *first_subfile = current_subfile;
+ void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc)
+ = record_line;
baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
{
addr = gdbarch_addr_bits_remove (gdbarch, address);
if (last_subfile)
- record_line (last_subfile, 0, addr);
+ (*p_record_line) (last_subfile, 0, addr);
last_subfile = current_subfile;
}
/* Append row to matrix using current values. */
addr = check_cu_functions (address, cu);
addr = gdbarch_addr_bits_remove (gdbarch, addr);
- record_line (current_subfile, line, addr);
+ (*p_record_line) (current_subfile, line, addr);
}
}
basic_block = 0;
switch (extended_op)
{
case DW_LNE_end_sequence:
+ p_record_line = record_line;
end_sequence = 1;
break;
case DW_LNE_set_address:
address = read_address (abfd, line_ptr, cu, &bytes_read);
+
+ if (address == 0 && !dwarf2_per_objfile->has_section_at_zero)
+ {
+ /* This line table is for a function which has been
+ GCd by the linker. Ignore it. PR gdb/12528 */
+
+ long line_offset
+ = line_ptr - dwarf2_per_objfile->line.buffer;
+
+ complaint (&symfile_complaints,
+ _(".debug_line address at offset 0x%lx is 0 "
+ "[in module %s]"),
+ line_offset, cu->objfile->name);
+ p_record_line = noop_record_line;
+ }
+
op_index = 0;
line_ptr += bytes_read;
address += baseaddr;
{
addr = gdbarch_addr_bits_remove (gdbarch, address);
if (last_subfile)
- record_line (last_subfile, 0, addr);
+ (*p_record_line) (last_subfile, 0, addr);
last_subfile = current_subfile;
}
addr = check_cu_functions (address, cu);
addr = gdbarch_addr_bits_remove (gdbarch, addr);
- record_line (current_subfile, line, addr);
+ (*p_record_line) (current_subfile, line, addr);
}
}
basic_block = 0;
address increment value corresponding to special opcode
255. I.e., this value is scaled by the minimum
instruction length since special opcode 255 would have
- scaled the the increment. */
+ scaled the increment. */
case DW_LNS_const_add_pc:
{
CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range;
if (!decode_for_pst_p)
{
addr = gdbarch_addr_bits_remove (gdbarch, address);
- record_line (current_subfile, 0, addr);
+ (*p_record_line) (current_subfile, 0, addr);
}
}
}
/* Convert a DWARF stack opcode into its string name. */
const char *
-dwarf_stack_op_name (unsigned op, int def)
+dwarf_stack_op_name (unsigned op)
{
switch (op)
{
case DW_OP_GNU_implicit_pointer:
return "DW_OP_GNU_implicit_pointer";
default:
- return def ? "OP_<unknown>" : NULL;
+ return NULL;
}
}
break;
default:
- complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
- dwarf_stack_op_name (op, 1));
+ {
+ const char *name = dwarf_stack_op_name (op);
+
+ if (name)
+ complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
+ name);
+ else
+ complaint (&symfile_complaints, _("unsupported stack op: '%02x'"),
+ op);
+ }
+
return (stack[stacki]);
}
{
unsigned int bytes_read;
int constant;
- char *string;
constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
mac_ptr += bytes_read;
- string = read_direct_string (abfd, mac_ptr, &bytes_read);
+ read_direct_string (abfd, mac_ptr, &bytes_read);
mac_ptr += bytes_read;
/* We don't recognize any vendor extensions. */
/* ".debug_loc" may not exist at all, or the offset may be outside
the section. If so, fall through to the complaint in the
other branch. */
- && DW_UNSND (attr) < dwarf2_per_objfile->loc.size)
+ && DW_UNSND (attr) < dwarf2_section_size (dwarf2_per_objfile->objfile,
+ &dwarf2_per_objfile->loc))
{
struct dwarf2_loclist_baton *baton;
total_len = size_of_contents;
/* The version number. */
- val = MAYBE_SWAP (3);
+ val = MAYBE_SWAP (4);
obstack_grow (&contents, &val, sizeof (val));
/* The offset of the CU list from the start of the file. */
1. The file header. This is a sequence of values, of offset_type
unless otherwise noted:
- [0] The version number, currently 3. Versions 1 and 2 are
+ [0] The version number, currently 4. Versions 1, 2 and 3 are
obsolete.
[1] The offset, from the start of the file, of the CU list.
[2] The offset, from the start of the file, of the types CU list.