gdb: Better support for dynamic properties with negative values
authorAndrew Burgess <andrew.burgess@embecosm.com>
Fri, 1 Mar 2019 11:06:23 +0000 (11:06 +0000)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Fri, 12 Jul 2019 11:09:55 +0000 (12:09 +0100)
When the type of a property is smaller than the CORE_ADDR in which the
property value has been placed, and if the property is signed, then
sign extend the property value from its actual type up to the size of
CORE_ADDR.

gdb/ChangeLog:

* dwarf2loc.c (dwarf2_evaluate_property): Sign extend property
value if its desired type is smaller than a CORE_ADDR and signed.

gdb/testsuite/ChangeLog:

* gdb.fortran/vla-ptype.exp: Print array with negative bounds.
* gdb.fortran/vla-sizeof.exp: Print the size of an array with
negative bounds.
* gdb.fortran/vla-value.exp: Print elements of an array with
negative bounds.
* gdb.fortran/vla.f90: Setup an array with negative bounds for
testing.

gdb/ChangeLog
gdb/dwarf2loc.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.fortran/vla-ptype.exp
gdb/testsuite/gdb.fortran/vla-sizeof.exp
gdb/testsuite/gdb.fortran/vla-value.exp
gdb/testsuite/gdb.fortran/vla.f90

index d2dec796a804aa31b04806d5b5bef9980f049a44..d79d89f9389cfb10777f8431afb0cd963ef9aaf7 100644 (file)
@@ -1,3 +1,8 @@
+2019-07-12  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * dwarf2loc.c (dwarf2_evaluate_property): Sign extend property
+       value if its desired type is smaller than a CORE_ADDR and signed.
+
 2019-07-12  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * dwarf2loc.c (dwarf2_evaluate_property): Update to take account
index 00f3d76bdbe7bfa19e8202e619041625c9b11f86..63643cb45d54a8abc4a0bc8a2d3b6c3d1fd51c70 100644 (file)
@@ -2454,6 +2454,29 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
                struct value *val = value_at (baton->property_type, *value);
                *value = value_as_address (val);
              }
+           else
+             {
+               gdb_assert (baton->property_type != NULL);
+
+               struct type *type = check_typedef (baton->property_type);
+               if (TYPE_LENGTH (type) < sizeof (CORE_ADDR)
+                   && !TYPE_UNSIGNED (type))
+                 {
+                   /* If we have a valid return candidate and it's value
+                      is signed, we have to sign-extend the value because
+                      CORE_ADDR on 64bit machine has 8 bytes but address
+                      size of an 32bit application is bytes.  */
+                   const int addr_size
+                     = (dwarf2_per_cu_addr_size (baton->locexpr.per_cu)
+                        * TARGET_CHAR_BIT);
+                   const CORE_ADDR neg_mask
+                     = (~((CORE_ADDR) 0) <<  (addr_size - 1));
+
+                   /* Check if signed bit is set and sign-extend values.  */
+                   if (*value & neg_mask)
+                     *value |= neg_mask;
+                 }
+             }
            return true;
          }
       }
index 238fcfc892565d3a327be0121938e15851072838..91b90d88e3a722771e67a3032757f8f8d070292f 100644 (file)
@@ -1,3 +1,14 @@
+2019-07-12  Bernhard Heckel  <bernhard.heckel@intel.com>
+           Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * gdb.fortran/vla-ptype.exp: Print array with negative bounds.
+       * gdb.fortran/vla-sizeof.exp: Print the size of an array with
+       negative bounds.
+       * gdb.fortran/vla-value.exp: Print elements of an array with
+       negative bounds.
+       * gdb.fortran/vla.f90: Setup an array with negative bounds for
+       testing.
+
 2019-07-11  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * gdb.base/options.exp (expect_string): Dequote strings in
index a4c3c9c703027893fd2ae832ac76750dd13c452d..7f8268bd335b329858f4ca21e3d689bd30d9af22 100644 (file)
@@ -98,3 +98,15 @@ gdb_test "ptype vla2" "type = $real, allocatable \\(:,:,:\\)" "ptype vla2 not al
 gdb_test "ptype vla2(5, 45, 20)" \
   "no such vector element \\\(vector not allocated\\\)" \
   "ptype vla2(5, 45, 20) not allocated"
+
+gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds-v1"]
+gdb_continue_to_breakpoint "vla1-neg-bounds-v1"
+gdb_test "ptype vla1" \
+    "type = $real, allocatable \\(-2:-1,-5:-2,-3:-1\\)" \
+    "ptype vla1 negative bounds"
+
+gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds-v2"]
+gdb_continue_to_breakpoint "vla1-neg-bounds-v2"
+gdb_test "ptype vla1" \
+    "type = $real, allocatable \\(-2:1,-5:2,-3:1\\)" \
+    "ptype vla1 negative lower bounds, positive upper bounds"
index 4fe6938445cb34669602393ea6e861ff6b40b5e9..4aece0b61d01b6984fa6a03450a37d64fc37db87 100644 (file)
@@ -59,3 +59,13 @@ gdb_test "print sizeof(pvla)" " = 4000" "print sizeof associated pvla"
 gdb_test "print sizeof(pvla(3,2,1))" "4" \
     "print sizeof element from associated pvla"
 gdb_test "print sizeof(pvla(3:4,2,1))" "800" "print sizeof sliced pvla"
+
+gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds-v1"]
+gdb_continue_to_breakpoint "vla1-neg-bounds-v1"
+gdb_test "print sizeof(vla1)" " = 96" \
+    "print sizeof vla1 negative bounds"
+
+gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds-v2"]
+gdb_continue_to_breakpoint "vla1-neg-bounds-v2"
+gdb_test "print sizeof(vla1)" " = 640" \
+    "print sizeof vla1 negative lower bounds, positive upper bounds"
index 3cf5d6750050c1fb1c39706a961f5a4556f901f2..ed0cace9f48846e48f434234a742ce09abfe305f 100644 (file)
@@ -161,3 +161,30 @@ gdb_breakpoint [gdb_get_line_number "pvla-deassociated"]
 gdb_continue_to_breakpoint "pvla-deassociated, second time"
 gdb_test "print \$mypvar(1,3,8)" " = 1001" \
   "print \$mypvar(1,3,8) after deallocated"
+
+gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds-v1"]
+gdb_continue_to_breakpoint "vla1-neg-bounds-v1"
+with_test_prefix "negative bounds" {
+    gdb_test "print vla1(-2,-5,-3)" " = 1"
+    gdb_test "print vla1(-2,-3,-1)" " = -231"
+    gdb_test "print vla1(-3,-5,-3)" "no such vector element"
+    gdb_test "print vla1(-2,-6,-3)" "no such vector element"
+    gdb_test "print vla1(-2,-5,-4)" "no such vector element"
+    gdb_test "print vla1(0,-2,-1)" "no such vector element"
+    gdb_test "print vla1(-1,-1,-1)" "no such vector element"
+    gdb_test "print vla1(-1,-2,0)" "no such vector element"
+}
+
+gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds-v2"]
+gdb_continue_to_breakpoint "vla1-neg-bounds-v2"
+with_test_prefix "negative lower bounds, positive upper bounds" {
+    gdb_test "print vla1(-2,-5,-3)" " = 2"
+    gdb_test "print vla1(-2,-3,-1)" " = 2"
+    gdb_test "print vla1(-2,-4,-2)" " = -242"
+    gdb_test "print vla1(-3,-5,-3)" "no such vector element"
+    gdb_test "print vla1(-2,-6,-3)" "no such vector element"
+    gdb_test "print vla1(-2,-5,-4)" "no such vector element"
+    gdb_test "print vla1(2,2,1)" "no such vector element"
+    gdb_test "print vla1(1,3,1)" "no such vector element"
+    gdb_test "print vla1(1,2,2)" "no such vector element"
+}
index 5bc608744b3ccc2d2c157f042c36a890f0fb6714..0ccb5c90d93176cbbc392a3aa2080758b0af8fe8 100644 (file)
@@ -54,4 +54,19 @@ program vla
 
   allocate (vla3 (2,2))               ! vla2-deallocated
   vla3(:,:) = 13
+
+  allocate (vla1 (-2:-1, -5:-2, -3:-1))
+  vla1(:, :, :) = 1
+  vla1(-2, -3, -1) = -231
+
+  deallocate (vla1)                   ! vla1-neg-bounds-v1
+  l = allocated(vla1)
+
+  allocate (vla1 (-2:1, -5:2, -3:1))
+  vla1(:, :, :) = 2
+  vla1(-2, -4, -2) = -242
+
+  deallocate (vla1)                   ! vla1-neg-bounds-v2
+  l = allocated(vla1)
+
 end program vla
This page took 0.036993 seconds and 4 git commands to generate.