aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2read.c
diff options
context:
space:
mode:
authorMark Wielaard <mjw@redhat.com>2014-06-30 23:21:52 +0200
committerMark Wielaard <mjw@redhat.com>2014-07-01 22:11:53 +0200
commitcf363f183d9a87faeda74f33b58a6c4a22e7d1e2 (patch)
tree60b2f1984182da22c126419ac62f8f7d1c2b243d /gdb/dwarf2read.c
parent82ae6c8d79c426e1b4d6f7b8d4be5292b3e9a8c5 (diff)
downloadgdb-cf363f183d9a87faeda74f33b58a6c4a22e7d1e2.zip
gdb-cf363f183d9a87faeda74f33b58a6c4a22e7d1e2.tar.gz
gdb-cf363f183d9a87faeda74f33b58a6c4a22e7d1e2.tar.bz2
Handle volatile array types in dwarf2read.c.
read_tag_const_type propagates the cv-qualifier to the array element type, but read_tag_volatile_type didn't. Make sure that both cv-qualifiers that apply to array types are handled the same. gdb/ChangeLog * dwarf2read.c (add_array_cv_type): New function. (read_tag_const_type): Call add_array_cv_type for TYPE_CODE_ARRAY. (read_tag_volatile_type): Likewise. gdb/testsuite/ChangeLog * gdb.base/constvars.c (violent, violet, vips, virgen, vulgar, vulture, vilify, villar): New volatile array constants. (vindictive, vegetation): New const volatile array constants. * gdb.base/volatile.exp: Test volatile and const volatile array types.
Diffstat (limited to 'gdb/dwarf2read.c')
-rw-r--r--gdb/dwarf2read.c56
1 files changed, 37 insertions, 19 deletions
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 2563418..276d2f1 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -14098,6 +14098,36 @@ read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
return set_die_type (die, type, cu);
}
+/* Add the given cv-qualifiers to the element type of the array. GCC
+ outputs DWARF type qualifiers that apply to an array, not the
+ element type. But GDB relies on the array element type to carry
+ the cv-qualifiers. This mimics section 6.7.3 of the C99
+ specification. */
+
+static struct type *
+add_array_cv_type (struct die_info *die, struct dwarf2_cu *cu,
+ struct type *base_type, int cnst, int voltl)
+{
+ struct type *el_type, *inner_array;
+
+ base_type = copy_type (base_type);
+ inner_array = base_type;
+
+ while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
+ {
+ TYPE_TARGET_TYPE (inner_array) =
+ copy_type (TYPE_TARGET_TYPE (inner_array));
+ inner_array = TYPE_TARGET_TYPE (inner_array);
+ }
+
+ el_type = TYPE_TARGET_TYPE (inner_array);
+ cnst |= TYPE_CONST (el_type);
+ voltl |= TYPE_VOLATILE (el_type);
+ TYPE_TARGET_TYPE (inner_array) = make_cv_type (cnst, voltl, el_type, NULL);
+
+ return set_die_type (die, base_type, cu);
+}
+
static struct type *
read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
{
@@ -14113,25 +14143,7 @@ read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
/* In case the const qualifier is applied to an array type, the element type
is so qualified, not the array type (section 6.7.3 of C99). */
if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY)
- {
- struct type *el_type, *inner_array;
-
- base_type = copy_type (base_type);
- inner_array = base_type;
-
- while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
- {
- TYPE_TARGET_TYPE (inner_array) =
- copy_type (TYPE_TARGET_TYPE (inner_array));
- inner_array = TYPE_TARGET_TYPE (inner_array);
- }
-
- el_type = TYPE_TARGET_TYPE (inner_array);
- TYPE_TARGET_TYPE (inner_array) =
- make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL);
-
- return set_die_type (die, base_type, cu);
- }
+ return add_array_cv_type (die, cu, base_type, 1, 0);
cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
return set_die_type (die, cv_type, cu);
@@ -14149,6 +14161,12 @@ read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
if (cv_type)
return cv_type;
+ /* In case the volatile qualifier is applied to an array type, the
+ element type is so qualified, not the array type (section 6.7.3
+ of C99). */
+ if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY)
+ return add_array_cv_type (die, cu, base_type, 0, 1);
+
cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
return set_die_type (die, cv_type, cu);
}