summaryrefslogtreecommitdiff
path: root/gdb/dwarf2read.c
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@adacore.com>2014-02-15 19:09:58 +0400
committerJoel Brobecker <brobecker@adacore.com>2014-02-26 11:43:23 -0800
commit31aa7e4ee988b175da848cee7cff6cfb28a5aa99 (patch)
treee361b1d5ca8fbe9b8188633a27c9442c45c09a50 /gdb/dwarf2read.c
parent9b333ba3405066be10f4fc1c497b7fb1a7cafd53 (diff)
downloadbinutils-gdb-31aa7e4ee988b175da848cee7cff6cfb28a5aa99.tar.gz
DWARF: Read constant-class addresses correctly
Starting with DWARF version 4, the description of the DW_AT_high_pc attribute was amended to say: if it is of class constant, the value is an unsigned integer offset which when added to the low PC gives the address of the first location past the last instruction associated with the entity. A change was made in Apr 27th, 2012 to reflect that change: | commit 91da14142c0171e58a91ad58a32fd010b700e761 | Author: Mark Wielaard <mjw@redhat.com> | Date: Fri Apr 27 18:55:19 2012 +0000 | | * dwarf2read.c (dwarf2_get_pc_bounds): Check DW_AT_high_pc form to | see whether it is an address or a constant offset from DW_AT_low_pc. | (dwarf2_record_block_ranges): Likewise. | (read_partial_die): Likewise. Unfortunately, this new interpretation is now used regardless of the CU's DWARF version. It turns out that one of WindRiver's compilers (FTR: Diabdata 4.4) is generating DWARF version 2 info with DW_AT_high_pc attributes improperly using the data4 form. Because of that, we miscompute all high PCs incorrectly. This leads to a lot of symtabs having overlapping ranges, which in turn causes havoc in pc-to-symtab-and-line translations. One visible effect is when inserting a breakpoint on a given function: (gdb) b world Breakpoint 1 at 0x4005c4 The source location of the breakpoint is missing. The output should be: (gdb) b world Breakpoint 1 at 0x4005c8: file dw2-rel-hi-pc-world.c, line 24. What happens in this case is that the pc-to-SAL translation first starts be trying to find the symtab associated to our PC using each symtab's ranges. Because of the high_pc miscomputation, many symtabs end up matching, and the heuristic trying to select the most probable one unfortunately returns one that is unrelated (it really had no change in this case to do any better). Once we have the wrong symtab, the start searching the associated linetable, where the addresses are correct, thus finding no match, and therefore no SAL. This patch is an attempt at handling the situation as gracefully as we can, without guarantees. It introduces a new function "attr_value_as_address" which uses the correct accessor for getting the value of a given attribute. It then adjust the code throughout this unit to use this function instead of assuming that addresses always have the DW_FORM_addr format. It also fixes the original issue of miscomputing the high_pc by limiting the new interpretation of constant form DW_AT_high_pc attributes to units using DWARF version 4 or later. gdb/ChangeLog: * dwarf2read.c (attr_value_as_address): New function. (dwarf2_find_base_address, read_call_site_scope): Use attr_value_as_address in place of DW_ADDR. (dwarf2_get_pc_bounds): Use attr_value_as_address to get the low and high addresses. Slight rework of the handling of the high pc being a constant form, and limit it to DWARF verson 4 or higher. (dwarf2_record_block_ranges): Likewise. (read_partial_die): Likewise. (new_symbol_full): Use attr_value_as_address in place of DW_ADDR. gdb/testsuite/ChangeLog: * gdb.dwarf2/dw2-abs-hi-pc-hello-dbg.S: New file. * gdb.dwarf2/dw2-abs-hi-pc-hello.c: New file. * gdb.dwarf2/dw2-abs-hi-pc-world-dbg.S: New file. * gdb.dwarf2/dw2-abs-hi-pc-world.c: New file. * gdb.dwarf2/dw2-abs-hi-pc.c: New file. * gdb.dwarf2/dw2-abs-hi-pc.exp: New file. Tested on x86_64-linux.
Diffstat (limited to 'gdb/dwarf2read.c')
-rw-r--r--gdb/dwarf2read.c76
1 files changed, 48 insertions, 28 deletions
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 8c20f15f0fb..8a850f147ed 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -1942,6 +1942,36 @@ byte_swap (offset_type value)
#define MAYBE_SWAP(V) (V)
#endif /* WORDS_BIGENDIAN */
+/* Read the given attribute value as an address, taking the attribute's
+ form into account. */
+
+static CORE_ADDR
+attr_value_as_address (struct attribute *attr)
+{
+ CORE_ADDR addr;
+
+ if (attr->form != DW_FORM_addr && attr->form != DW_FORM_GNU_addr_index)
+ {
+ /* Aside from a few clearly defined exceptions, attributes that
+ contain an address must always be in DW_FORM_addr form.
+ Unfortunately, some compilers happen to be violating this
+ requirement by encoding addresses using other forms, such
+ as DW_FORM_data4 for example. For those broken compilers,
+ we try to do our best, without any guarantee of success,
+ to interpret the address correctly. It would also be nice
+ to generate a complaint, but that would require us to maintain
+ a list of legitimate cases where a non-address form is allowed,
+ as well as update callers to pass in at least the CU's DWARF
+ version. This is more overhead than what we're willing to
+ expand for a pretty rare case. */
+ addr = DW_UNSND (attr);
+ }
+ else
+ addr = DW_ADDR (attr);
+
+ return addr;
+}
+
/* The suffix for an index file. */
#define INDEX_SUFFIX ".gdb-index"
@@ -4204,7 +4234,7 @@ dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
if (attr)
{
- cu->base_address = DW_ADDR (attr);
+ cu->base_address = attr_value_as_address (attr);
cu->base_known = 1;
}
else
@@ -4212,7 +4242,7 @@ dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
attr = dwarf2_attr (die, DW_AT_low_pc, cu);
if (attr)
{
- cu->base_address = DW_ADDR (attr);
+ cu->base_address = attr_value_as_address (attr);
cu->base_known = 1;
}
}
@@ -11260,7 +11290,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
die->offset.sect_off, objfile_name (objfile));
return;
}
- pc = DW_ADDR (attr) + baseaddr;
+ pc = attr_value_as_address (attr) + baseaddr;
if (cu->call_site_htab == NULL)
cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq,
@@ -11701,12 +11731,10 @@ dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
attr = dwarf2_attr (die, DW_AT_low_pc, cu);
if (attr)
{
- low = DW_ADDR (attr);
- if (attr_high->form == DW_FORM_addr
- || attr_high->form == DW_FORM_GNU_addr_index)
- high = DW_ADDR (attr_high);
- else
- high = low + DW_UNSND (attr_high);
+ low = attr_value_as_address (attr);
+ high = attr_value_as_address (attr_high);
+ if (cu->header.version >= 4 && attr_form_is_constant (attr_high))
+ high += low;
}
else
/* Found high w/o low attribute. */
@@ -11872,13 +11900,11 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
attr = dwarf2_attr (die, DW_AT_low_pc, cu);
if (attr)
{
- CORE_ADDR low = DW_ADDR (attr);
- CORE_ADDR high;
- if (attr_high->form == DW_FORM_addr
- || attr_high->form == DW_FORM_GNU_addr_index)
- high = DW_ADDR (attr_high);
- else
- high = low + DW_UNSND (attr_high);
+ CORE_ADDR low = attr_value_as_address (attr);
+ CORE_ADDR high = attr_value_as_address (attr_high);
+
+ if (cu->header.version >= 4 && attr_form_is_constant (attr_high))
+ high += low;
record_block_range (block, baseaddr + low, baseaddr + high - 1);
}
@@ -15336,18 +15362,13 @@ read_partial_die (const struct die_reader_specs *reader,
break;
case DW_AT_low_pc:
has_low_pc_attr = 1;
- part_die->lowpc = DW_ADDR (&attr);
+ part_die->lowpc = attr_value_as_address (&attr);
break;
case DW_AT_high_pc:
has_high_pc_attr = 1;
- if (attr.form == DW_FORM_addr
- || attr.form == DW_FORM_GNU_addr_index)
- part_die->highpc = DW_ADDR (&attr);
- else
- {
- high_pc_relative = 1;
- part_die->highpc = DW_UNSND (&attr);
- }
+ part_die->highpc = attr_value_as_address (&attr);
+ if (cu->header.version >= 4 && attr_form_is_constant (&attr))
+ high_pc_relative = 1;
break;
case DW_AT_location:
/* Support the .debug_loc offsets. */
@@ -17560,9 +17581,8 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
case DW_TAG_label:
attr = dwarf2_attr (die, DW_AT_low_pc, cu);
if (attr)
- {
- SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
- }
+ SYMBOL_VALUE_ADDRESS (sym)
+ = attr_value_as_address (attr) + baseaddr;
SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
SYMBOL_ACLASS_INDEX (sym) = LOC_LABEL;