public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Sanimir Agovic <sanimir.agovic@intel.com>
To: tromey@redhat.com, palves@redhat.com, xdje42@gmail.com
Cc: gdb-patches@sourceware.org, keven.boell@intel.com
Subject: [PATCH v3 05/13] vla: update type from newly created value
Date: Wed, 04 Dec 2013 14:23:00 -0000	[thread overview]
Message-ID: <1386166785-28037-6-git-send-email-sanimir.agovic@intel.com> (raw)
In-Reply-To: <1386166785-28037-1-git-send-email-sanimir.agovic@intel.com>

Constructing a value based on a type and address might change the type
of the newly constructed value. Thus re-fetch type via value_type to ensure
we have the correct type at hand.

2013-10-18  Sanimir Agovic  <sanimir.agovic@intel.com>
            Keven Boell  <keven.boell@intel.com>

	* ada-lang.c (ada_value_primitive_packed_val): Re-fetch type from value.
	(ada_template_to_fixed_record_type_1): Likewise.
	(ada_to_fixed_type_1): Likewise.
	* cp-valprint.c (cp_print_value_fields_rtti): Likewise.
	(cp_print_value): Likewise.
	* d-valprint.c (dynamic_array_type): Likewise.
	* jv-valprint.c (java_value_print): Likewise.
	* valops.c (value_ind): Likewise.
	* value.c (coerce_ref): Likewise.

Change-Id: I8a0ebcbd84d8ff8db2eb24960f099d131816cb18
Signed-off-by: Sanimir Agovic <sanimir.agovic@intel.com>
---
 gdb/ada-lang.c    | 13 +++++++++++--
 gdb/cp-valprint.c |  2 ++
 gdb/d-valprint.c  |  1 +
 gdb/jv-valprint.c |  1 +
 gdb/valops.c      |  3 +++
 gdb/value.c       |  1 +
 6 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 417232c..7e1706b 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -2300,6 +2300,7 @@ ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr,
   else if (VALUE_LVAL (obj) == lval_memory && value_lazy (obj))
     {
       v = value_at (type, value_address (obj));
+      type = value_type (v);
       bytes = (unsigned char *) alloca (len);
       read_memory (value_address (v) + offset, bytes, len);
     }
@@ -7657,6 +7658,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
 		 size first before creating the value.  */
 	      check_size (rtype);
 	      dval = value_from_contents_and_address (rtype, valaddr, address);
+	      rtype = value_type (dval);
 	    }
           else
             dval = dval0;
@@ -7759,7 +7761,10 @@ ada_template_to_fixed_record_type_1 (struct type *type,
       off = TYPE_FIELD_BITPOS (rtype, variant_field);
 
       if (dval0 == NULL)
-        dval = value_from_contents_and_address (rtype, valaddr, address);
+	{
+	  dval = value_from_contents_and_address (rtype, valaddr, address);
+	  rtype = value_type (dval);
+	}
       else
         dval = dval0;
 
@@ -7900,7 +7905,10 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
     return type;
 
   if (dval0 == NULL)
-    dval = value_from_contents_and_address (type, valaddr, address);
+    {
+      dval = value_from_contents_and_address (type, valaddr, address);
+      type = value_type (dval);
+    }
   else
     dval = dval0;
 
@@ -8198,6 +8206,7 @@ ada_to_fixed_type_1 (struct type *type, const gdb_byte *valaddr,
 	      value_from_contents_and_address (fixed_record_type,
 					       valaddr,
 					       address);
+            fixed_record_type = value_type (obj);
             if (real_type != NULL)
               return to_fixed_record_type
 		(real_type, NULL,
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index bcf54ff..b868d37 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -443,6 +443,7 @@ cp_print_value_fields_rtti (struct type *type,
       /* Ugh, we have to convert back to a value here.  */
       value = value_from_contents_and_address (type, valaddr + offset,
 					       address + offset);
+      type = value_type (value);
       /* We don't actually care about most of the result here -- just
 	 the type.  We already have the correct offset, due to how
 	 val_print was initially called.  */
@@ -545,6 +546,7 @@ cp_print_value (struct type *type, struct type *real_type,
 		  base_val = value_from_contents_and_address (baseclass,
 							      buf,
 							      address + boffset);
+		  baseclass = value_type (base_val);
 		  thisoffset = 0;
 		  boffset = 0;
 		  thistype = baseclass;
diff --git a/gdb/d-valprint.c b/gdb/d-valprint.c
index 6e9c28d..cca629a 100644
--- a/gdb/d-valprint.c
+++ b/gdb/d-valprint.c
@@ -59,6 +59,7 @@ dynamic_array_type (struct type *type, const gdb_byte *valaddr,
 
       true_type = lookup_array_range_type (true_type, 0, length - 1);
       ival = value_at (true_type, addr);
+      true_type = value_type (ival);
 
       d_val_print (true_type,
 		   value_contents_for_printing (ival),
diff --git a/gdb/jv-valprint.c b/gdb/jv-valprint.c
index f465ca0..808e01b 100644
--- a/gdb/jv-valprint.c
+++ b/gdb/jv-valprint.c
@@ -65,6 +65,7 @@ java_value_print (struct value *val, struct ui_file *stream,
 	  type = lookup_pointer_type (type);
 
 	  val = value_at (type, address);
+	  type = value_type (val);
 	}
     }
 
diff --git a/gdb/valops.c b/gdb/valops.c
index 4fc57ec..ec2f1f6 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -268,6 +268,7 @@ value_cast_structs (struct type *type, struct value *v2)
 	{
 	  v = value_full_object (v2, real_type, full, top, using_enc);
 	  v = value_at_lazy (real_type, value_address (v));
+	  real_type = value_type (v);
 
 	  /* We might be trying to cast to the outermost enclosing
 	     type, in which case search_struct_field won't work.  */
@@ -803,6 +804,7 @@ value_dynamic_cast (struct type *type, struct value *arg)
     return value_at_lazy (type, addr);
 
   tem = value_at (type, addr);
+  type = value_type (tem);
 
   /* The first dynamic check specified in 5.2.7.  */
   if (is_public_ancestor (arg_type, TYPE_TARGET_TYPE (resolved_type)))
@@ -1610,6 +1612,7 @@ value_ind (struct value *arg1)
 			      (value_as_address (arg1)
 			       - value_pointed_to_offset (arg1)));
 
+      enc_type = value_type (arg2);
       return readjust_indirect_value_type (arg2, enc_type, base_type, arg1);
     }
 
diff --git a/gdb/value.c b/gdb/value.c
index 57b7696..c694741 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -3360,6 +3360,7 @@ coerce_ref (struct value *arg)
   retval = value_at_lazy (enc_type,
                           unpack_pointer (value_type (arg),
                                           value_contents (arg)));
+  enc_type = value_type (retval);
   return readjust_indirect_value_type (retval, enc_type,
                                        value_type_arg_tmp, arg);
 }
-- 
1.8.3.1

  parent reply	other threads:[~2013-12-04 14:23 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-04 14:20 [PATCH v3 00/13] C99 variable length array support Sanimir Agovic
2013-12-04 14:20 ` [PATCH v3 02/13] type: add c99 " Sanimir Agovic
2013-12-04 14:20 ` [PATCH v3 01/13] vla: introduce new bound type abstraction adapt uses Sanimir Agovic
2013-12-04 14:21 ` [PATCH v3 03/13] vla: enable sizeof operator to work with variable length arrays Sanimir Agovic
2013-12-04 14:21 ` [PATCH v3 07/13] vla: support for DW_AT_count Sanimir Agovic
2013-12-04 14:21 ` [PATCH v3 12/13] test: basic c99 vla tests for C primitives Sanimir Agovic
2013-12-04 14:21 ` [PATCH v3 04/13] vla: enable sizeof operator for indirection Sanimir Agovic
2013-12-04 14:21 ` [PATCH v3 06/13] vla: print "dynamic length" for unresolved dynamic bounds Sanimir Agovic
2013-12-04 14:21 ` [PATCH v3 08/13] vla: resolve dynamic bounds if value contents is a constant byte-sequence Sanimir Agovic
2013-12-04 14:22 ` [PATCH v3 09/13] test: cover subranges with present DW_AT_count attribute Sanimir Agovic
2013-12-04 14:22 ` [PATCH v3 06/13] vla: print "variable length" for unresolved dynamic bounds Sanimir Agovic
2013-12-04 14:22 ` [PATCH v3 10/13] test: multi-dimensional c99 vla Sanimir Agovic
2013-12-04 14:22 ` [PATCH v3 11/13] test: evaluate pointers to C99 vla correctly Sanimir Agovic
2013-12-04 14:23 ` Sanimir Agovic [this message]
2013-12-06  7:36   ` [PATCH v3 05/13] vla: update type from newly created value Doug Evans
2013-12-16 15:21     ` Agovic, Sanimir
2013-12-16 17:58       ` Doug Evans
2013-12-04 14:23 ` [PATCH v3 13/13] test: add mi vla test Sanimir Agovic
2014-01-15 11:41 ` [PATCH v3 00/13] C99 variable length array support Joel Brobecker
2014-01-15 16:15   ` Tom Tromey
2014-01-15 17:54     ` Joel Brobecker
2014-01-15 18:00       ` Tom Tromey
2014-01-16 17:00   ` Agovic, Sanimir
2014-01-16 17:30     ` Tom Tromey
2014-01-17  2:23       ` Joel Brobecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1386166785-28037-6-git-send-email-sanimir.agovic@intel.com \
    --to=sanimir.agovic@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=keven.boell@intel.com \
    --cc=palves@redhat.com \
    --cc=tromey@redhat.com \
    --cc=xdje42@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).