aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2read.c
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@adacore.com>2014-01-29 17:39:56 +0400
committerJoel Brobecker <brobecker@adacore.com>2014-02-26 06:32:39 -0800
commitdc53a7adb516adbf2f646a078a1140b1044a39f5 (patch)
tree265682442b18ec0711c4957a931474de426beb9b /gdb/dwarf2read.c
parent12ab52e9772a9170018feb44de3ef217e051cc60 (diff)
downloadgdb-dc53a7adb516adbf2f646a078a1140b1044a39f5.zip
gdb-dc53a7adb516adbf2f646a078a1140b1044a39f5.tar.gz
gdb-dc53a7adb516adbf2f646a078a1140b1044a39f5.tar.bz2
DWARF: Add array DW_AT_bit_stride and DW_AT_byte_stride support
Consider the following declarations in Ada... type Item is range -32 .. 31; for Item'Size use 6; type Table is array (Natural range 0 .. 4) of Item; pragma Pack (Table); ... which declare a packed array whose elements are 6 bits long. The debugger currently does not notice that the array is packed, and thus prints values of this type incorrectly. This can be seen in the "ptype" output: (gdb) ptype table type = array (0 .. 4) of foo.item Normally, the debugger should print: (gdb) ptype table type = array (0 .. 4) of foo.item <packed: 6-bit elements> The debugging information for this array looks like this: .uleb128 0xf # (DIE (0x15c) DW_TAG_array_type) .long .LASF9 # DW_AT_name: "pck__table" .byte 0x6 # DW_AT_bit_stride .long 0x1a9 # DW_AT_type .uleb128 0x10 # (DIE (0x16a) DW_TAG_subrange_type) .long 0x3b # DW_AT_type .byte 0 # DW_AT_lower_bound .byte 0x4 # DW_AT_upper_bound .byte 0 # end of children of DIE 0x15c The interesting part is the DW_AT_bit_stride attribute, which tells the size of the array elements is 6 bits, rather than the normal element type's size. This patch adds support for this attribute by first creating gdbtypes.c::create_array_type_with_stride, which is an enhanced version of create_array_type taking an extra parameter as the stride. The old create_array_type can then be re-implemented very simply by calling the new create_array_type_with_stride. We can then use this new function from dwarf2read, to create arrays with or without stride. gdb/ChangeLog: * gdbtypes.h (create_array_type_with_stride): Add declaration. * gdbtypes.c (create_array_type_with_stride): New function, renaming create_array_type, but with an added parameter called "bit_stride". (create_array_type): Re-implement using create_array_type_with_stride. * dwarf2read.c (read_array_type): Add support for DW_AT_byte_stride and DW_AT_bit_stride attributes. gdb/testsuite/ChangeLog: * gdb.dwarf2/arr-stride.c: New file. * gdb.dwarf2/arr-stride.exp: New file. The test, relying purely on generating an assembly file, only verifies the type description of our array. But I was also able to verify manually that the debugger print values of these types correctly as well (which was not the case prior to this patch).
Diffstat (limited to 'gdb/dwarf2read.c')
-rw-r--r--gdb/dwarf2read.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 3eaa0b1..d7dc38c 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -13281,6 +13281,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
int ndim = 0;
struct cleanup *back_to;
const char *name;
+ unsigned int bit_stride = 0;
element_type = die_type (die, cu);
@@ -13289,13 +13290,22 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
if (type)
return type;
+ attr = dwarf2_attr (die, DW_AT_byte_stride, cu);
+ if (attr != NULL)
+ bit_stride = DW_UNSND (attr) * 8;
+
+ attr = dwarf2_attr (die, DW_AT_bit_stride, cu);
+ if (attr != NULL)
+ bit_stride = DW_UNSND (attr);
+
/* Irix 6.2 native cc creates array types without children for
arrays with unspecified length. */
if (die->child == NULL)
{
index_type = objfile_type (objfile)->builtin_int;
range_type = create_range_type (NULL, index_type, 0, -1);
- type = create_array_type (NULL, element_type, range_type);
+ type = create_array_type_with_stride (NULL, element_type, range_type,
+ bit_stride);
return set_die_type (die, type, cu);
}
@@ -13335,12 +13345,14 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
int i = 0;
while (i < ndim)
- type = create_array_type (NULL, type, range_types[i++]);
+ type = create_array_type_with_stride (NULL, type, range_types[i++],
+ bit_stride);
}
else
{
while (ndim-- > 0)
- type = create_array_type (NULL, type, range_types[ndim]);
+ type = create_array_type_with_stride (NULL, type, range_types[ndim],
+ bit_stride);
}
/* Understand Dwarf2 support for vector types (like they occur on