Blame SOURCES/gdb-rhbz1905702-DWARF-data_location.patch

46818e
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
46818e
From: Keith Seitz <keiths@redhat.com>
46818e
Date: Wed, 9 Dec 2020 16:47:07 -0500
46818e
Subject: gdb-rhbz1905702-DWARF-data_location.patch
46818e
46818e
;; Backport "fortran dynamic type related fixes"
46818e
;; Andrew Burgess (RH BZ 1905702)
46818e
46818e
commit e79eb02f2f09baecffb144bac6804f975065466f
46818e
46818e
gdb/fortran: resolve dynamic types when readjusting after an indirection
46818e
46818e
After dereferencing a pointer (in value_ind) or following a
46818e
reference (in coerce_ref) we call readjust_indirect_value_type to
46818e
"fixup" the type of the resulting value object.
46818e
46818e
This fixup handles cases relating to the type of the resulting object
46818e
being different (a sub-class) of the original pointers target type.
46818e
46818e
If we encounter a pointer to a dynamic type then after dereferencing a
46818e
pointer (in value_ind) the type of the object created will have had
46818e
its dynamic type resolved.  However, in readjust_indirect_value_type,
46818e
we use the target type of the original pointer to "fixup" the type of
46818e
the resulting value.  In this case, the target type will be a dynamic
46818e
type, so the resulting value object, once again has a dynamic type.
46818e
46818e
This then triggers an assertion later within GDB.
46818e
46818e
The solution I propose here is that we call resolve_dynamic_type on
46818e
the pointer's target type (within readjust_indirect_value_type) so
46818e
that the resulting value is not converted back to a dynamic type.
46818e
46818e
The test case is based on the original test in the bug report.
46818e
46818e
gdb/ChangeLog:
46818e
46818e
        PR fortran/23051
46818e
        PR fortran/26139
46818e
        * valops.c (value_ind): Pass address to
46818e
        readjust_indirect_value_type.
46818e
        * value.c (readjust_indirect_value_type): Make parameter
46818e
        non-const, and add extra address parameter.  Resolve original type
46818e
        before using it.
46818e
        * value.h (readjust_indirect_value_type): Update function
46818e
        signature and comment.
46818e
46818e
gdb/testsuite/ChangeLog:
46818e
46818e
        PR fortran/23051
46818e
        PR fortran/26139
46818e
        * gdb.fortran/class-allocatable-array.exp: New file.
46818e
        * gdb.fortran/class-allocatable-array.f90: New file.
46818e
        * gdb.fortran/pointer-to-pointer.exp: New file.
46818e
        * gdb.fortran/pointer-to-pointer.f90: New file.
46818e
46818e
diff --git a/gdb/testsuite/gdb.dwarf2/graalvm-data-loc2.c b/gdb/testsuite/gdb.dwarf2/graalvm-data-loc2.c
46818e
new file mode 100644
46818e
--- /dev/null
46818e
+++ b/gdb/testsuite/gdb.dwarf2/graalvm-data-loc2.c
46818e
@@ -0,0 +1,63 @@
46818e
+/* Copyright 2014-2020 Free Software Foundation, Inc.
46818e
+
46818e
+   This file is part of GDB.
46818e
+
46818e
+   This program is free software; you can redistribute it and/or modify
46818e
+   it under the terms of the GNU General Public License as published by
46818e
+   the Free Software Foundation; either version 3 of the License, or
46818e
+   (at your option) any later version.
46818e
+
46818e
+   This program is distributed in the hope that it will be useful,
46818e
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
46818e
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
46818e
+   GNU General Public License for more details.
46818e
+
46818e
+   You should have received a copy of the GNU General Public License
46818e
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
46818e
+
46818e
+/* This C file simulates the implementation of object pointers in
46818e
+   GraalVM Java native images where the object data is not addressed
46818e
+   directly. It serves as a regression test for a bug where printing
46818e
+   of such redirected data structures suffers from a gdb exception.
46818e
+
46818e
+   Debugging information on how to decode an object pointer to
46818e
+   identify the address of the underlying data will be generated
46818e
+   separately by the testcase using that file. */
46818e
+
46818e
+#include <stdlib.h>
46818e
+#include <string.h>
46818e
+
46818e
+struct Object {
46818e
+  struct Object *next;
46818e
+  int val;
46818e
+};
46818e
+
46818e
+struct Object *testOop;
46818e
+
46818e
+extern int debugMe() {
46818e
+  return 0;
46818e
+}
46818e
+
46818e
+struct Object *newObject() {
46818e
+  char *bytes = malloc(sizeof(struct Object));
46818e
+  return (struct Object *)bytes;
46818e
+}
46818e
+
46818e
+int
46818e
+main (void)
46818e
+{
46818e
+  struct Object *obj1 = newObject();
46818e
+  struct Object *obj2 = newObject();
46818e
+  struct Object *obj3 = newObject();
46818e
+  obj1->val = 0;
46818e
+  obj2->val = 1;
46818e
+  obj3->val = 2;
46818e
+
46818e
+  obj1->next = obj2;
46818e
+  obj2->next = obj3;
46818e
+  obj3->next = obj1;
46818e
+
46818e
+  testOop = obj1;
46818e
+
46818e
+  return debugMe();
46818e
+}
46818e
diff --git a/gdb/testsuite/gdb.dwarf2/graalvm-data-loc2.exp b/gdb/testsuite/gdb.dwarf2/graalvm-data-loc2.exp
46818e
new file mode 100644
46818e
--- /dev/null
46818e
+++ b/gdb/testsuite/gdb.dwarf2/graalvm-data-loc2.exp
46818e
@@ -0,0 +1,122 @@
46818e
+# Copyright 2014-2020 Free Software Foundation, Inc.
46818e
+
46818e
+# This program is free software; you can redistribute it and/or modify
46818e
+# it under the terms of the GNU General Public License as published by
46818e
+# the Free Software Foundation; either version 3 of the License, or
46818e
+# (at your option) any later version.
46818e
+#
46818e
+# This program is distributed in the hope that it will be useful,
46818e
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
46818e
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
46818e
+# GNU General Public License for more details.
46818e
+#
46818e
+# You should have received a copy of the GNU General Public License
46818e
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
46818e
+load_lib dwarf.exp
46818e
+
46818e
+# This test can only be run on targets which support DWARF-2 and use gas.
46818e
+if {![dwarf2_support]} {
46818e
+    return 0
46818e
+}
46818e
+
46818e
+standard_testfile .c -dw.S
46818e
+
46818e
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
46818e
+    return -1
46818e
+}
46818e
+
46818e
+# Make some DWARF for the test.
46818e
+set asm_file [standard_output_file $srcfile2]
46818e
+Dwarf::assemble $asm_file {
46818e
+    
46818e
+    cu {} {
46818e
+ 	DW_TAG_compile_unit {
46818e
+                {DW_AT_language @DW_LANG_C99}
46818e
+                {DW_AT_name     data-loc2.c}
46818e
+                {DW_AT_comp_dir /tmp}
46818e
+        } {
46818e
+            declare_labels integer_label struct_label pointer_label
46818e
+
46818e
+            integer_label: DW_TAG_base_type {
46818e
+                {DW_AT_byte_size 4 DW_FORM_sdata}
46818e
+                {DW_AT_encoding  @DW_ATE_signed}
46818e
+                {DW_AT_name      integer}
46818e
+            }
46818e
+
46818e
+	    struct_label: DW_TAG_structure_type {
46818e
+		{DW_AT_name "Object"}
46818e
+		{DW_AT_byte_size 20 DW_FORM_sdata}
46818e
+                {DW_AT_data_location {
46818e
+                    DW_OP_push_object_address
46818e
+                } SPECIAL_expr}
46818e
+	    } {
46818e
+		member {
46818e
+		    {name next}
46818e
+		    {type :$pointer_label}
46818e
+		    {data_member_location 0 data1}
46818e
+		}
46818e
+		member {
46818e
+		    {name val}
46818e
+		    {type :$integer_label}
46818e
+		    {data_member_location 8 data1}
46818e
+		}
46818e
+	    }
46818e
+	    pointer_label: DW_TAG_pointer_type {
46818e
+		{DW_AT_byte_size 4 DW_FORM_sdata}
46818e
+		{DW_AT_type  :$struct_label}
46818e
+	    }
46818e
+            DW_TAG_variable {
46818e
+                {DW_AT_name testOop}
46818e
+                {DW_AT_type :$pointer_label}
46818e
+                {DW_AT_location {
46818e
+                    DW_OP_addr [gdb_target_symbol testOop]
46818e
+                } SPECIAL_expr}
46818e
+                {external 1 flag}
46818e
+            }
46818e
+	}
46818e
+    }
46818e
+}
46818e
+
46818e
+# Now that we've generated the DWARF debugging info, rebuild our
46818e
+# program using our debug info instead of the info generated by
46818e
+# the compiler.
46818e
+
46818e
+if { [prepare_for_testing "failed to prepare" ${testfile} \
46818e
+	  [list $srcfile $asm_file] {nodebug}] } {
46818e
+    return -1
46818e
+}
46818e
+
46818e
+if ![runto_main] {
46818e
+    return -1
46818e
+}
46818e
+
46818e
+# ensure the object network is set up as expected and check that
46818e
+# printing of structs which employ the data_location does not
46818e
+# fail with a gdb exception
46818e
+
46818e
+gdb_test "break debugMe" \
46818e
+         "Breakpoint .*" \
46818e
+         "set breakpoint at debugMe"
46818e
+
46818e
+gdb_continue_to_breakpoint "continue to debugMe"
46818e
+
46818e
+gdb_test "print testOop->val" \
46818e
+         ".* = 0"
46818e
+
46818e
+gdb_test "print testOop->next->val" \
46818e
+         ".* = 1"
46818e
+
46818e
+gdb_test "print testOop->next->next->val" \
46818e
+         ".* = 2"
46818e
+
46818e
+gdb_test "print *testOop" \
46818e
+    ".* = {next = .*, val = 0}" \
46818e
+    "print contents of struct"
46818e
+
46818e
+gdb_test "print *testOop->next" \
46818e
+    ".* = {next = .*, val = 1}" \
46818e
+    "print contents of an indirect struct"
46818e
+
46818e
+gdb_test "print *testOop->next->next" \
46818e
+    ".* = {next = .*, val = 2}" \
46818e
+    "print contents of a double indirect struct"
46818e
diff --git a/gdb/testsuite/gdb.fortran/class-allocatable-array.exp b/gdb/testsuite/gdb.fortran/class-allocatable-array.exp
46818e
new file mode 100644
46818e
--- /dev/null
46818e
+++ b/gdb/testsuite/gdb.fortran/class-allocatable-array.exp
46818e
@@ -0,0 +1,43 @@
46818e
+# Copyright 2020 Free Software Foundation, Inc.
46818e
+
46818e
+# This program is free software; you can redistribute it and/or modify
46818e
+# it under the terms of the GNU General Public License as published by
46818e
+# the Free Software Foundation; either version 3 of the License, or
46818e
+# (at your option) any later version.
46818e
+#
46818e
+# This program is distributed in the hope that it will be useful,
46818e
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
46818e
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
46818e
+# GNU General Public License for more details.
46818e
+#
46818e
+# You should have received a copy of the GNU General Public License
46818e
+# along with this program.  If not, see <http://www.gnu.org/licenses/> .
46818e
+
46818e
+# Test that GDB can print an allocatable array that is a data field
46818e
+# within a class like type.
46818e
+
46818e
+if {[skip_fortran_tests]} { return -1 }
46818e
+
46818e
+standard_testfile ".f90"
46818e
+load_lib fortran.exp
46818e
+
46818e
+if {[prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
46818e
+	 {debug f90}]} {
46818e
+    return -1
46818e
+}
46818e
+
46818e
+if {![runto MAIN__]} {
46818e
+    untested main"could not run to main"
46818e
+    return -1
46818e
+}
46818e
+
46818e
+gdb_breakpoint [gdb_get_line_number "Break Here"]
46818e
+gdb_continue_to_breakpoint "Break Here"
46818e
+
46818e
+# If this first test fails then the Fortran compiler being used uses
46818e
+# different names, or maybe a completely different approach, for
46818e
+# representing class like structures.  The following tests are
46818e
+# cetainly going to fail.
46818e
+gdb_test "print this" " = \\( _data = \[^\r\n\]+, _vptr = \[^\r\n\]+\\)"
46818e
+gdb_test "print this%_data" " = \\(PTR TO -> \\( Type test_type \\)\\) \[^\r\n\]+"
46818e
+gdb_test "print this%_data%b" " = \\(\\( 1, 2, 3\\) \\( 4, 5, 6\\) \\)"
46818e
diff --git a/gdb/testsuite/gdb.fortran/class-allocatable-array.f90 b/gdb/testsuite/gdb.fortran/class-allocatable-array.f90
46818e
new file mode 100644
46818e
--- /dev/null
46818e
+++ b/gdb/testsuite/gdb.fortran/class-allocatable-array.f90
46818e
@@ -0,0 +1,54 @@
46818e
+! Copyright 2020 Free Software Foundation, Inc.
46818e
+!
46818e
+! This program is free software; you can redistribute it and/or modify
46818e
+! it under the terms of the GNU General Public License as published by
46818e
+! the Free Software Foundation; either version 3 of the License, or
46818e
+! (at your option) any later version.
46818e
+!
46818e
+! This program is distributed in the hope that it will be useful,
46818e
+! but WITHOUT ANY WARRANTY; without even the implied warranty of
46818e
+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
46818e
+! GNU General Public License for more details.
46818e
+!
46818e
+! You should have received a copy of the GNU General Public License
46818e
+! along with this program.  If not, see <http://www.gnu.org/licenses/>.
46818e
+
46818e
+module test_module
46818e
+  type test_type
46818e
+     integer a
46818e
+     real, allocatable :: b (:, :)
46818e
+   contains
46818e
+     procedure :: test_proc
46818e
+  end type test_type
46818e
+
46818e
+contains
46818e
+
46818e
+  subroutine test_proc (this)
46818e
+    class(test_type), intent (inout) :: this
46818e
+    allocate (this%b (3, 2))
46818e
+    call fill_array_2d (this%b)
46818e
+    print *, ""		! Break Here
46818e
+  contains
46818e
+    ! Helper subroutine to fill 2-dimensional array with unique
46818e
+    ! values.
46818e
+    subroutine fill_array_2d (array)
46818e
+      real, dimension (:,:) :: array
46818e
+      real :: counter
46818e
+
46818e
+      counter = 1.0
46818e
+      do i=LBOUND (array, 2), UBOUND (array, 2), 1
46818e
+         do j=LBOUND (array, 1), UBOUND (array, 1), 1
46818e
+            array (j,i) = counter
46818e
+            counter = counter + 1
46818e
+         end do
46818e
+      end do
46818e
+    end subroutine fill_array_2d
46818e
+  end subroutine test_proc
46818e
+end module
46818e
+
46818e
+program test
46818e
+  use test_module
46818e
+  implicit none
46818e
+  type(test_type) :: t
46818e
+  call t%test_proc ()
46818e
+end program test
46818e
diff --git a/gdb/testsuite/gdb.fortran/pointer-to-pointer.exp b/gdb/testsuite/gdb.fortran/pointer-to-pointer.exp
46818e
new file mode 100644
46818e
--- /dev/null
46818e
+++ b/gdb/testsuite/gdb.fortran/pointer-to-pointer.exp
46818e
@@ -0,0 +1,46 @@
46818e
+# Copyright 2020 Free Software Foundation, Inc.
46818e
+
46818e
+# This program is free software; you can redistribute it and/or modify
46818e
+# it under the terms of the GNU General Public License as published by
46818e
+# the Free Software Foundation; either version 3 of the License, or
46818e
+# (at your option) any later version.
46818e
+#
46818e
+# This program is distributed in the hope that it will be useful,
46818e
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
46818e
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
46818e
+# GNU General Public License for more details.
46818e
+#
46818e
+# You should have received a copy of the GNU General Public License
46818e
+# along with this program.  If not, see <http://www.gnu.org/licenses/> .
46818e
+
46818e
+# Test for GDB printing a pointer to a type containing a buffer.
46818e
+
46818e
+if {[skip_fortran_tests]} { return -1 }
46818e
+
46818e
+standard_testfile ".f90"
46818e
+load_lib fortran.exp
46818e
+
46818e
+if {[prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
46818e
+	 {debug f90}]} {
46818e
+    return -1
46818e
+}
46818e
+
46818e
+if {![runto MAIN__]} {
46818e
+    untested "could not run to main"
46818e
+    return -1
46818e
+}
46818e
+
46818e
+gdb_breakpoint [gdb_get_line_number "Break Here"]
46818e
+gdb_continue_to_breakpoint "Break Here"
46818e
+
46818e
+gdb_test "print *buffer" \
46818e
+    " = \\( alpha = \\(1\\.5, 2\\.5, 3\\.5, 4\\.5, 5\\.5\\) \\)"
46818e
+
46818e
+set l_buffer_type [multi_line \
46818e
+		       "Type l_buffer" \
46818e
+		       "    real\\(kind=4\\) :: alpha\\(.\\)" \
46818e
+		       "End Type l_buffer" ]
46818e
+
46818e
+gdb_test "ptype buffer" "type = PTR TO -> \\( ${l_buffer_type} \\)"
46818e
+gdb_test "ptype *buffer" "type = ${l_buffer_type}"
46818e
+gdb_test "ptype buffer%alpha" "type = real\\(kind=4\\) \\(5\\)"
46818e
diff --git a/gdb/testsuite/gdb.fortran/pointer-to-pointer.f90 b/gdb/testsuite/gdb.fortran/pointer-to-pointer.f90
46818e
new file mode 100644
46818e
--- /dev/null
46818e
+++ b/gdb/testsuite/gdb.fortran/pointer-to-pointer.f90
46818e
@@ -0,0 +1,34 @@
46818e
+! Copyright 2020 Free Software Foundation, Inc.
46818e
+!
46818e
+! This program is free software; you can redistribute it and/or modify
46818e
+! it under the terms of the GNU General Public License as published by
46818e
+! the Free Software Foundation; either version 3 of the License, or
46818e
+! (at your option) any later version.
46818e
+!
46818e
+! This program is distributed in the hope that it will be useful,
46818e
+! but WITHOUT ANY WARRANTY; without even the implied warranty of
46818e
+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
46818e
+! GNU General Public License for more details.
46818e
+!
46818e
+! You should have received a copy of the GNU General Public License
46818e
+! along with this program.  If not, see <http://www.gnu.org/licenses/>.
46818e
+
46818e
+program allocate_array
46818e
+
46818e
+  type l_buffer
46818e
+     real, dimension(:), pointer :: alpha
46818e
+  end type l_buffer
46818e
+  type(l_buffer), pointer :: buffer
46818e
+
46818e
+  allocate (buffer)
46818e
+  allocate (buffer%alpha (5))
46818e
+
46818e
+  buffer%alpha (1) = 1.5
46818e
+  buffer%alpha (2) = 2.5
46818e
+  buffer%alpha (3) = 3.5
46818e
+  buffer%alpha (4) = 4.5
46818e
+  buffer%alpha (5) = 5.5
46818e
+
46818e
+  print *, buffer%alpha	! Break Here.
46818e
+
46818e
+end program allocate_array
46818e
diff --git a/gdb/valops.c b/gdb/valops.c
46818e
--- a/gdb/valops.c
46818e
+++ b/gdb/valops.c
46818e
@@ -1553,38 +1553,28 @@ value_ind (struct value *arg1)
46818e
   if (TYPE_CODE (base_type) == TYPE_CODE_PTR)
46818e
     {
46818e
       struct type *enc_type;
46818e
-      CORE_ADDR addr;
46818e
-
46818e
-      if (type_not_associated (base_type))
46818e
-        error (_("Attempt to take contents of a not associated pointer."));
46818e
-
46818e
-      if (NULL != TYPE_DATA_LOCATION (TYPE_TARGET_TYPE (base_type)))
46818e
-	addr = value_address (arg1);
46818e
-      else
46818e
-	addr = value_as_address (arg1);
46818e
-
46818e
-      if (addr != 0)
46818e
-	TYPE_TARGET_TYPE (base_type) =
46818e
-	    resolve_dynamic_type (TYPE_TARGET_TYPE (base_type), NULL, addr);
46818e
 
46818e
       /* We may be pointing to something embedded in a larger object.
46818e
          Get the real type of the enclosing object.  */
46818e
       enc_type = check_typedef (value_enclosing_type (arg1));
46818e
       enc_type = TYPE_TARGET_TYPE (enc_type);
46818e
 
46818e
+      CORE_ADDR base_addr;
46818e
       if (TYPE_CODE (check_typedef (enc_type)) == TYPE_CODE_FUNC
46818e
 	  || TYPE_CODE (check_typedef (enc_type)) == TYPE_CODE_METHOD)
46818e
 	/* For functions, go through find_function_addr, which knows
46818e
 	   how to handle function descriptors.  */
46818e
-	arg2 = value_at_lazy (enc_type, 
46818e
-			      find_function_addr (arg1, NULL));
46818e
+	base_addr = find_function_addr (arg1, NULL);
46818e
       else
46818e
-	/* Retrieve the enclosing object pointed to.  */
46818e
-	arg2 = value_at_lazy (enc_type, 
46818e
-			      (addr - value_pointed_to_offset (arg1)));
46818e
-
46818e
+	{
46818e
+	  /* Retrieve the enclosing object pointed to.  */
46818e
+	  base_addr = (value_as_address (arg1)
46818e
+		       - value_pointed_to_offset (arg1));
46818e
+	}
46818e
+      arg2 = value_at_lazy (enc_type, base_addr);
46818e
       enc_type = value_type (arg2);
46818e
-      return readjust_indirect_value_type (arg2, enc_type, base_type, arg1);
46818e
+      return readjust_indirect_value_type (arg2, enc_type, base_type,
46818e
+					   arg1, base_addr);
46818e
     }
46818e
 
46818e
   error (_("Attempt to take contents of a non-pointer value."));
46818e
diff --git a/gdb/value.c b/gdb/value.c
46818e
--- a/gdb/value.c
46818e
+++ b/gdb/value.c
46818e
@@ -3630,10 +3630,19 @@ coerce_ref_if_computed (const struct value *arg)
46818e
 struct value *
46818e
 readjust_indirect_value_type (struct value *value, struct type *enc_type,
46818e
 			      const struct type *original_type,
46818e
-			      const struct value *original_value)
46818e
+			      struct value *original_value,
46818e
+			      CORE_ADDR original_value_address)
46818e
 {
46818e
+  gdb_assert (TYPE_CODE (original_type) == TYPE_CODE_PTR
46818e
+	      || TYPE_IS_REFERENCE (original_type));
46818e
+
46818e
+  struct type *original_target_type = TYPE_TARGET_TYPE (original_type);
46818e
+  struct type *resolved_original_target_type
46818e
+    = resolve_dynamic_type (original_target_type, NULL,
46818e
+			    original_value_address);
46818e
+
46818e
   /* Re-adjust type.  */
46818e
-  deprecated_set_value_type (value, TYPE_TARGET_TYPE (original_type));
46818e
+  deprecated_set_value_type (value, resolved_original_target_type);
46818e
 
46818e
   /* Add embedding info.  */
46818e
   set_value_enclosing_type (value, enc_type);
46818e
@@ -3660,12 +3669,11 @@ coerce_ref (struct value *arg)
46818e
   enc_type = check_typedef (value_enclosing_type (arg));
46818e
   enc_type = TYPE_TARGET_TYPE (enc_type);
46818e
 
46818e
-  retval = value_at_lazy (enc_type,
46818e
-                          unpack_pointer (value_type (arg),
46818e
-                                          value_contents (arg)));
46818e
+  CORE_ADDR addr = unpack_pointer (value_type (arg), value_contents (arg));
46818e
+  retval = value_at_lazy (enc_type, addr);
46818e
   enc_type = value_type (retval);
46818e
-  return readjust_indirect_value_type (retval, enc_type,
46818e
-                                       value_type_arg_tmp, arg);
46818e
+  return readjust_indirect_value_type (retval, enc_type, value_type_arg_tmp,
46818e
+				       arg, addr);
46818e
 }
46818e
 
46818e
 struct value *
46818e
diff --git a/gdb/value.h b/gdb/value.h
46818e
--- a/gdb/value.h
46818e
+++ b/gdb/value.h
46818e
@@ -488,7 +488,9 @@ extern struct value *coerce_ref_if_computed (const struct value *arg);
46818e
 
46818e
 /* Setup a new value type and enclosing value type for dereferenced value VALUE.
46818e
    ENC_TYPE is the new enclosing type that should be set.  ORIGINAL_TYPE and
46818e
-   ORIGINAL_VAL are the type and value of the original reference or pointer.
46818e
+   ORIGINAL_VAL are the type and value of the original reference or
46818e
+   pointer.  ORIGINAL_VALUE_ADDRESS is the address within VALUE, that is
46818e
+   the address that was dereferenced.
46818e
 
46818e
    Note, that VALUE is modified by this function.
46818e
 
46818e
@@ -497,7 +499,8 @@ extern struct value *coerce_ref_if_computed (const struct value *arg);
46818e
 extern struct value * readjust_indirect_value_type (struct value *value,
46818e
 						    struct type *enc_type,
46818e
 						    const struct type *original_type,
46818e
-						    const struct value *original_val);
46818e
+						    struct value *original_val,
46818e
+						    CORE_ADDR original_value_address);
46818e
 
46818e
 /* Convert a REF to the object referenced.  */
46818e