Fix handling of typedefs to types having a data_location attribute.
authorJoel Brobecker <brobecker@adacore.com>
Wed, 20 Aug 2014 12:50:38 +0000 (14:50 +0200)
committerJoel Brobecker <brobecker@adacore.com>
Wed, 20 Aug 2014 13:34:19 +0000 (15:34 +0200)
Consider an array described in the debugging information as being
a typedef of an array type for which there is a DW_AT_data_location
attribute. Trying to print the value of that array currently yields
incorrect element values. For instance:

    (gdb) print foo.three_tdef
    $1 = (6293760, 0, 6293772)

The problem occurs because we check for the data_location attribute
only on the typedef type, whereas we should be checking for the
typedef's target type.  As a result, GDB erroneously thinks that
there is no data_location, and therefore starts reading the array's
content from the address of the descriptor instead of the data_location
address.

gdb/ChangeLog:

        * value.c (value_from_contents_and_address): Strip resolved_type's
        typedef layers before checking its TYPE_DATA_LOCATION.

gdb/testsuite/ChangeLog:

        * gdb.dwarf2/data-loc.exp: Add additional tests exercising
        the handling of variables declared as a typedef to an array
        which a DW_AT_data_location attribute.

gdb/ChangeLog
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.dwarf2/data-loc.exp
gdb/value.c

index c0b4f82b04c9f682014ba9179ab2fe19f1118ae0..8c6b2047579daec2744fab33aa91195255f1d918 100644 (file)
@@ -1,3 +1,8 @@
+2014-08-20  Joel Brobecker  <brobecker@adacore.com>
+
+       * value.c (value_from_contents_and_address): Strip resolved_type's
+       typedef layers before checking its TYPE_DATA_LOCATION.
+
 2014-08-20  Pedro Alves  <palves@redhat.com>
 
        * value.c (value_contents_bits_eq): Initialize l,h for gcc -Wall.
index e7a464468d3bf86656cf095319dc4c19360882fc..ef024b992a557d0ead9facc110791cd4d34e7aeb 100644 (file)
@@ -1,3 +1,9 @@
+2014-08-20  Joel Brobecker  <brobecker@adacore.com>
+
+       * gdb.dwarf2/data-loc.exp: Add additional tests exercising
+       the handling of variables declared as a typedef to an array
+       which a DW_AT_data_location attribute.
+
 2014-08-19  Andrew Burgess  <aburgess@broadcom.com>
            Pedro Alves  <palves@redhat.com>
 
index b5c5f678aea0408bcfc1745022ae74056d2dce77..81456fa030cdb3d802e80d8174e6f7f3390cbcf7 100644 (file)
@@ -42,7 +42,7 @@ Dwarf::assemble $asm_file {
                 {DW_AT_name     foo.adb}
                 {DW_AT_comp_dir /tmp}
         } {
-            declare_labels integer_label array_label
+            declare_labels integer_label array_label array_ptr_label
 
             integer_label: DW_TAG_base_type {
                 {DW_AT_byte_size 4 DW_FORM_sdata}
@@ -76,7 +76,7 @@ Dwarf::assemble $asm_file {
                     } SPECIAL_expr}
                }
            }
-            DW_TAG_typedef {
+            array_ptr_label: DW_TAG_typedef {
                 {DW_AT_name foo__array_type}
                 {DW_AT_type :$array_label}
             }
@@ -88,6 +88,14 @@ Dwarf::assemble $asm_file {
                 } SPECIAL_expr}
                 {external 1 flag}
             }
+            DW_TAG_variable {
+                {DW_AT_name foo__three_tdef}
+                {DW_AT_type :$array_ptr_label}
+                {DW_AT_location {
+                    DW_OP_addr table_1
+                } SPECIAL_expr}
+                {external 1 flag}
+            }
             DW_TAG_variable {
                 {DW_AT_name foo__five}
                 {DW_AT_type :$array_label}
@@ -96,6 +104,14 @@ Dwarf::assemble $asm_file {
                 } SPECIAL_expr}
                 {external 1 flag}
             }
+            DW_TAG_variable {
+                {DW_AT_name foo__five_tdef}
+                {DW_AT_type :$array_ptr_label}
+                {DW_AT_location {
+                    DW_OP_addr table_2
+                } SPECIAL_expr}
+                {external 1 flag}
+            }
        }
     }
 }
@@ -115,6 +131,8 @@ if ![runto_main] {
 
 gdb_test_no_output "set language ada"
 
+# foo.three
+
 gdb_test "print foo.three" \
          " = \\(1, 2, 3\\)"
 
@@ -139,6 +157,32 @@ gdb_test "print foo.three'last" \
 gdb_test "print foo.three'length" \
          " = 3"
 
+# foo.three_tdef
+
+gdb_test "print foo.three_tdef" \
+         " = \\(1, 2, 3\\)"
+
+gdb_test "ptype foo.three_tdef" \
+         "type = array \\(1 .. 3\\) of integer"
+
+gdb_test "print foo.three_tdef(1)" \
+         " = 1"
+
+gdb_test "print foo.three_tdef(2)" \
+         " = 2"
+
+gdb_test "print foo.three_tdef(3)" \
+         " = 3"
+
+gdb_test "print foo.three_tdef'first" \
+         " = 1"
+
+gdb_test "print foo.three_tdef'last" \
+         " = 3"
+
+gdb_test "print foo.three_tdef'length" \
+         " = 3"
+
 gdb_test "print foo.five" \
          " = \\(2 => 5, 8, 13, 21, 34\\)"
 
@@ -148,6 +192,8 @@ gdb_test "ptype foo.five" \
 gdb_test "ptype foo.array_type" \
          "type = array \\(<>\\) of integer"
 
+# foo.five
+
 gdb_test "print foo.five(2)" \
          " = 5"
 
@@ -172,19 +218,74 @@ gdb_test "print foo.five'last" \
 gdb_test "print foo.five'length" \
          " = 5"
 
+# foo.five_tdef
+
+gdb_test "print foo.five_tdef" \
+         " = \\(2 => 5, 8, 13, 21, 34\\)"
+
+gdb_test "ptype foo.five_tdef" \
+         "type = array \\(2 .. 6\\) of integer"
+
+gdb_test "ptype foo.array_type" \
+         "type = array \\(<>\\) of integer"
+
+gdb_test "print foo.five_tdef(2)" \
+         " = 5"
+
+gdb_test "print foo.five_tdef(3)" \
+         " = 8"
+
+gdb_test "print foo.five_tdef(4)" \
+         " = 13"
+
+gdb_test "print foo.five_tdef(5)" \
+         " = 21"
+
+gdb_test "print foo.five_tdef(6)" \
+         " = 34"
+
+gdb_test "print foo.five_tdef'first" \
+         " = 2"
+
+gdb_test "print foo.five_tdef'last" \
+         " = 6"
+
+gdb_test "print foo.five_tdef'length" \
+         " = 5"
+
 gdb_test_no_output "set lang c"
 
+# foo__three
+
 gdb_test "print foo__three" \
          " = \\{1, 2, 3\\}"
 
 gdb_test "ptype foo__three" \
          "type = integer \\\[3\\\]"
 
+# foo__three_tdef
+
+gdb_test "print foo__three_tdef" \
+         " = \\{1, 2, 3\\}"
+
+gdb_test "ptype foo__three_tdef" \
+         "type = integer \\\[3\\\]"
+
+# foo__five
+
 gdb_test "print foo__five" \
          " = \\{5, 8, 13, 21, 34\\}"
 
 gdb_test "ptype foo__five" \
          "type = integer \\\[5\\\]"
 
+# foo__five_tdef
+
+gdb_test "print foo__five_tdef" \
+         " = \\{5, 8, 13, 21, 34\\}"
+
+gdb_test "ptype foo__five_tdef" \
+         "type = integer \\\[5\\\]"
+
 gdb_test "ptype foo__array_type" \
          "type = integer \\\[variable length\\\]"
index 09ee1caec4e9a02be7c44c73f50a4fca9ef6ca52..077d2345b533ca09aead24ea1beff7b81febc0c2 100644 (file)
@@ -3475,15 +3475,16 @@ value_from_contents_and_address (struct type *type,
                                 CORE_ADDR address)
 {
   struct type *resolved_type = resolve_dynamic_type (type, address);
+  struct type *resolved_type_no_typedef = check_typedef (resolved_type);
   struct value *v;
 
   if (valaddr == NULL)
     v = allocate_value_lazy (resolved_type);
   else
     v = value_from_contents (resolved_type, valaddr);
-  if (TYPE_DATA_LOCATION (resolved_type) != NULL
-      && TYPE_DATA_LOCATION_KIND (resolved_type) == PROP_CONST)
-    address = TYPE_DATA_LOCATION_ADDR (resolved_type);
+  if (TYPE_DATA_LOCATION (resolved_type_no_typedef) != NULL
+      && TYPE_DATA_LOCATION_KIND (resolved_type_no_typedef) == PROP_CONST)
+    address = TYPE_DATA_LOCATION_ADDR (resolved_type_no_typedef);
   set_value_address (v, address);
   VALUE_LVAL (v) = lval_memory;
   return v;
This page took 0.050509 seconds and 4 git commands to generate.