]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Typeprint: Resolve any dynamic target type of a pointer.
authorBernhard Heckel <bernhard.heckel@intel.com>
Tue, 12 Jul 2016 06:19:34 +0000 (08:19 +0200)
committerBernhard Heckel <bernhard.heckel@intel.com>
Tue, 12 Jul 2016 06:19:34 +0000 (08:19 +0200)
Before continuing with language specific type printing
we have to resolve the target type of a pointer
as we might wanna print more details of the target
like the dimension of an array. We have to resolve it here
as we don't have any address information later on.

2016-07-08  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/Changelog:
* typeprint.c (whatis_exp): Resolve dynamic target type
  of pointers.

gdb/Testsuite/Changelog:
* gdb.cp/vla-cxx.cc: Added pointer to dynamic type.
* gdb.cp/vla-cxx.exp: Test pointer to dynamic type.

Change-Id: Idff0d6dd0eab3125b45d470a12b5e66b392e42c3

gdb/testsuite/gdb.cp/vla-cxx.cc
gdb/testsuite/gdb.cp/vla-cxx.exp
gdb/typeprint.c

index a1fd510e309f19d0027c74e8d40522ebdf3793eb..5f8f8ab4fc1fda2241d01a2a0d103d6c374505dd 100644 (file)
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+extern "C" {
+#include <stddef.h>
+}
+
 struct container;
 
 struct element
@@ -40,11 +44,16 @@ int main(int argc, char **argv)
   typedef typeof (vla) &vlareftypedef;
   vlareftypedef vlaref2 (vla);
   container c;
+  typeof (vla) *ptr = NULL;
+
+  // Before pointer assignment
+  ptr = &vla;
 
   for (int i = 0; i < z; ++i)
     vla[i] = 5 + 2 * i;
 
   // vlas_filled
   vla[0] = 2 * vla[0];
+
   return vla[2];
 }
index f6224dc97b5e3c00fbe1d369b5431f805fd411b9..babdfb7651b27d56f7a9eda17ce61f4ef5af5cf9 100644 (file)
@@ -23,6 +23,10 @@ if ![runto_main] {
     return -1
 }
 
+gdb_breakpoint [gdb_get_line_number "Before pointer assignment"]
+gdb_continue_to_breakpoint "Before pointer assignment"
+gdb_test "ptype ptr" "int \\(\\*\\)\\\[variable length\\\]" "ptype ptr, Before pointer assignment"
+
 gdb_breakpoint [gdb_get_line_number "vlas_filled"]
 gdb_continue_to_breakpoint "vlas_filled"
 
@@ -33,3 +37,4 @@ gdb_test "print vlaref" " = \\(int \\(&\\)\\\[3\\\]\\) @$hex: \\{5, 7, 9\\}"
 # bug being tested, it's better not to depend on the exact spelling.
 gdb_test "print vlaref2" " = \\(.*\\) @$hex: \\{5, 7, 9\\}"
 gdb_test "print c" " = \\{e = \\{c = @$hex\\}\\}"
+gdb_test "ptype ptr" "int \\(\\*\\)\\\[3\\\]"
index e77513e1c4ad85b7ab17cb8667048483c6c03b32..e3d84c7090da5f174b1839092be026faabaae4cd 100644 (file)
@@ -485,6 +485,25 @@ whatis_exp (char *exp, int show)
       printf_filtered (" */\n");    
     }
 
+  /* Resolve any dynamic target type, as we might print
+     additional information about the target.
+     For example, in Fortran and C we are printing the dimension of the
+     dynamic array the pointer is pointing to.  */
+  if (TYPE_CODE (type) == TYPE_CODE_PTR
+      && is_dynamic_type (type) == 1)
+    {
+      CORE_ADDR addr;
+      if (NULL != TYPE_DATA_LOCATION (TYPE_TARGET_TYPE(type)))
+       addr = value_address (val);
+      else
+       addr = value_as_address (val);
+
+      if (addr != 0
+         && type_not_associated (type) == 0)
+       TYPE_TARGET_TYPE (type) = resolve_dynamic_type (TYPE_TARGET_TYPE (type),
+                                                       NULL, addr);
+    }
+
   LA_PRINT_TYPE (type, "", gdb_stdout, show, 0, &flags);
   printf_filtered ("\n");