aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/dwarf2/expr.c3
-rw-r--r--gdb/testsuite/gdb.dwarf2/shortpiece.exp52
2 files changed, 51 insertions, 4 deletions
diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c
index 0c5ce8c..eecd18f 100644
--- a/gdb/dwarf2/expr.c
+++ b/gdb/dwarf2/expr.c
@@ -161,9 +161,6 @@ rw_pieced_value (value *v, value *from, bool check_optimized)
}
else
{
- if (value_type (v) != value_enclosing_type (v))
- internal_error (_("Should not be able to create a lazy value with "
- "an enclosing type"));
if (check_optimized)
v_contents = nullptr;
else
diff --git a/gdb/testsuite/gdb.dwarf2/shortpiece.exp b/gdb/testsuite/gdb.dwarf2/shortpiece.exp
index e1fb78e..f16506a 100644
--- a/gdb/testsuite/gdb.dwarf2/shortpiece.exp
+++ b/gdb/testsuite/gdb.dwarf2/shortpiece.exp
@@ -29,7 +29,7 @@ Dwarf::assemble $asm_file {
cu { addr_size 4 } {
compile_unit {} {
- declare_labels int_label ushort_label struct_label
+ declare_labels int_label ushort_label struct_label struct_label_2
int_label: DW_TAG_base_type {
{DW_AT_byte_size 4 DW_FORM_udata}
@@ -59,6 +59,23 @@ Dwarf::assemble $asm_file {
}
}
+ struct_label_2: DW_TAG_structure_type {
+ {DW_AT_name "S_2"}
+ {DW_AT_byte_size 6 DW_FORM_udata}
+ } {
+ DW_TAG_member {
+ {DW_AT_name "a"}
+ {DW_AT_type :${int_label}}
+ {DW_AT_data_member_location 0 DW_FORM_udata}
+ }
+
+ DW_TAG_member {
+ {DW_AT_name "b"}
+ {DW_AT_type :${ushort_label}}
+ {DW_AT_data_member_location 4 DW_FORM_udata}
+ }
+ }
+
DW_TAG_variable {
{DW_AT_name "s1"}
{DW_AT_type :${struct_label}}
@@ -86,6 +103,20 @@ Dwarf::assemble $asm_file {
DW_OP_piece 8
} SPECIAL_expr}
}
+
+ DW_TAG_variable {
+ {DW_AT_name "s3"}
+ {DW_AT_type :${struct_label_2}}
+ {DW_AT_external 1 DW_FORM_flag}
+ {DW_AT_location {
+ DW_OP_constu 0
+ DW_OP_stack_value
+ DW_OP_piece 4
+ DW_OP_constu 1
+ DW_OP_stack_value
+ DW_OP_piece 2
+ } SPECIAL_expr}
+ }
}
}
}
@@ -98,3 +129,22 @@ if { [prepare_for_testing "failed to prepare" ${testfile} \
gdb_test "p s1" " = {a = 1, b = 0}"
gdb_test "p s2" \
"access outside bounds of object referenced via synthetic pointer"
+
+# When fetching a lazy value, GDB typically tries to fetch the 'full'
+# object based on the enclosing type. GDB does not support the reading
+# of a pieced value with a (possibly larger) enclosing type. However,
+# the user may want to print a value casted to a different type,
+# e.g. print (<type> []) <variable>. This cast causes an update of the
+# value's type. In case of a pieced value, GDB failed to fetch the
+# value's content.
+# This test verifies that GDB can print a pieced value casted to a
+# different type.
+gdb_test "p (int \[\]) s1" " = \\{1\\, 0\\}"
+gdb_test "p (short \[\]) s1" " = \\{1\\, 0\\, 0\\, <synthetic pointer>\\}"
+
+# Test for correct output if the size of the original object is not a
+# multiple of the array's element size.
+gdb_test "p s3" " = {a = 0, b = 1}"
+gdb_test "p (int \[\]) s3" [multi_line \
+ "warning: array element type size does not divide object size in cast" \
+ "\\$\\d = \\{0\\}"]