From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23217 invoked by alias); 8 Feb 2012 18:34:16 -0000 Received: (qmail 22748 invoked by uid 22791); 8 Feb 2012 18:34:13 -0000 X-SWARE-Spam-Status: No, hits=-0.2 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_WEB X-Spam-Check-By: sourceware.org Received: from forward18.mail.yandex.net (HELO forward18.mail.yandex.net) (95.108.253.143) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 08 Feb 2012 18:33:58 +0000 Received: from smtp17.mail.yandex.net (smtp17.mail.yandex.net [95.108.252.17]) by forward18.mail.yandex.net (Yandex) with ESMTP id D0B061783B4C; Wed, 8 Feb 2012 22:33:55 +0400 (MSK) Received: from smtp17.mail.yandex.net (localhost [127.0.0.1]) by smtp17.mail.yandex.net (Yandex) with ESMTP id AAE1D1900018; Wed, 8 Feb 2012 22:33:55 +0400 (MSK) Received: from kts.bestnet.kharkov.ua (kts.bestnet.kharkov.ua [80.92.226.138]) by smtp17.mail.yandex.net (nwsmtp/Yandex) with ESMTP id XsNu1ALK-XtNu4L2X; Wed, 8 Feb 2012 22:33:55 +0400 X-Yandex-Spam: 1 Message-ID: <4F32C009.2050103@yandex.ru> Date: Wed, 08 Feb 2012 18:34:00 -0000 From: xgsa User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.24) Gecko/20111108 Thunderbird/3.1.16 MIME-Version: 1.0 To: Tom Tromey CC: gdb-patches@sourceware.org Subject: Re: RTTI type improvement for References: <4ED92C05.9080803@yandex.ru> <4EF22A4D.80703@yandex.ru> <20111221193630.GA28985@host2.jankratochvil.net> <4EF30389.5010008@yandex.ru> <20111223200951.GA19581@host2.jankratochvil.net> <4EF5D1C5.5010902@yandex.ru> <20120102022153.GA686@host2.jankratochvil.net> <4F07177C.5080201@yandex.ru> In-Reply-To: Content-Type: multipart/mixed; boundary="------------070606000005060401030101" X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-02/txt/msg00108.txt.bz2 This is a multi-part message in MIME format. --------------070606000005060401030101 Content-Type: text/plain; charset=windows-1251; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1962 Hi, > Anton> +struct value * > Anton> +readjust_indirect_value_type (struct value *value, struct type *enc_type, > Anton> + struct type *original_type, > Anton> + struct value *original_value) > > I wonder if there is a cleaner way to do this same thing. > Say, a kind of value constructor as opposed to something that rewrites > an existing value? > > If not, that is fine. I just extract that code from value_ind. I'd prefer to leave it as is. > Anton> +extern struct value * > Anton> +readjust_indirect_value_type (struct value *value, struct type *enc_type, > Anton> + struct type *original_type, > Anton> + struct value *original_value); > > If you're going to split the first line that way, I think you should > indent the subsequent lines by 4 or 5 spaces (not sure what the standard > is, if there is one). > > Probably better to split before the open paren though (and still indent; > there are examples of this elsewhere). Did not noticed it. Fixed. Note, that the copyright paperwork is done. gdb/ChangeLog: 2012-01-06 Anton Gorenkov * c-valprint.c (c_value_print): Use value_rtti_indirect_type instead of value_rtti_target_type. * eval.c (evaluate_subexp_standard): Use value_rtti_indirect_type instead of value_rtti_target_type. * typeprint.c (whatis_exp): Use value_rtti_indirect_type instead of value_rtti_target_type. * valops.c (value_ind): Extract function readjust_indirect_value_type. (value_rtti_target_type): Rename to ... (value_rtti_indirect_type): ... here and make it indirect. Update function comment. * value.c (readjust_indirect_value_type): New function. (coerce_ref): Support for enclosing type setting for references with readjust_indirect_value_type. * value.h (readjust_value_type): New declaration. (value_rtti_target_type): Rename to ... (value_rtti_indirect_type): ... here. --------------070606000005060401030101 Content-Type: text/x-diff; name="gdb_reference_rtti_fix2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="gdb_reference_rtti_fix2.patch" Content-length: 8380 diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c index 82551e9..25c6688 100644 --- a/gdb/c-valprint.c +++ b/gdb/c-valprint.c @@ -728,22 +728,13 @@ c_value_print (struct value *val, struct ui_file *stream, if (value_entirely_available (val)) { - real_type = value_rtti_target_type (val, &full, &top, &using_enc); + real_type = value_rtti_indirect_type (val, &full, &top, + &using_enc); if (real_type) { /* RTTI entry found. */ - if (TYPE_CODE (type) == TYPE_CODE_PTR) - { - /* Create a pointer type pointing to the real - type. */ - type = lookup_pointer_type (real_type); - } - else - { - /* Create a reference type referencing the real - type. */ - type = lookup_reference_type (real_type); - } + type = real_type; + /* Need to adjust pointer value. */ val = value_from_pointer (type, value_as_address (val) - top); diff --git a/gdb/eval.c b/gdb/eval.c index 9913a72..de1c4bd 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -2001,16 +2001,10 @@ evaluate_subexp_standard (struct type *expect_type, if (opts.objectprint && TYPE_TARGET_TYPE(type) && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS)) { - real_type = value_rtti_target_type (arg1, &full, &top, &using_enc); + real_type = value_rtti_indirect_type (arg1, &full, &top, + &using_enc); if (real_type) - { - if (TYPE_CODE (type) == TYPE_CODE_PTR) - real_type = lookup_pointer_type (real_type); - else - real_type = lookup_reference_type (real_type); - arg1 = value_cast (real_type, arg1); - } } } diff --git a/gdb/typeprint.c b/gdb/typeprint.c index 803d20b..f257f47 100644 --- a/gdb/typeprint.c +++ b/gdb/typeprint.c @@ -139,16 +139,7 @@ whatis_exp (char *exp, int show) if (((TYPE_CODE (type) == TYPE_CODE_PTR) || (TYPE_CODE (type) == TYPE_CODE_REF)) && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS)) - { - real_type = value_rtti_target_type (val, &full, &top, &using_enc); - if (real_type) - { - if (TYPE_CODE (type) == TYPE_CODE_PTR) - real_type = lookup_pointer_type (real_type); - else - real_type = lookup_reference_type (real_type); - } - } + real_type = value_rtti_indirect_type (val, &full, &top, &using_enc); else if (TYPE_CODE (type) == TYPE_CODE_CLASS) real_type = value_rtti_type (val, &full, &top, &using_enc); } diff --git a/gdb/valops.c b/gdb/valops.c index fca601f..ee450e3 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -1772,15 +1772,7 @@ value_ind (struct value *arg1) (value_as_address (arg1) - value_pointed_to_offset (arg1))); - /* Re-adjust type. */ - deprecated_set_value_type (arg2, TYPE_TARGET_TYPE (base_type)); - /* Add embedding info. */ - set_value_enclosing_type (arg2, enc_type); - set_value_embedded_offset (arg2, value_pointed_to_offset (arg1)); - - /* We may be pointing to an object of some derived type. */ - arg2 = value_full_object (arg2, NULL, 0, 0, 0); - return arg2; + return readjust_indirect_value_type (arg2, enc_type, base_type, arg1); } error (_("Attempt to take contents of a non-pointer value.")); @@ -3526,21 +3518,48 @@ value_maybe_namespace_elt (const struct type *curtype, return result; } -/* Given a pointer value V, find the real (RTTI) type of the object it - points to. +/* Given a pointer or a reference value V, find its real (RTTI) type. Other parameters FULL, TOP, USING_ENC as with value_rtti_type() and refer to the values computed for the object pointed to. */ struct type * -value_rtti_target_type (struct value *v, int *full, - int *top, int *using_enc) +value_rtti_indirect_type (struct value *v, int *full, + int *top, int *using_enc) { struct value *target; + struct type *type, *real_type, *target_type; + + type = value_type (v); + type = check_typedef (type); + if (TYPE_CODE (type) == TYPE_CODE_REF) + target = coerce_ref (v); + else if (TYPE_CODE (type) == TYPE_CODE_PTR) + target = value_ind (v); + else + return NULL; - target = value_ind (v); + real_type = value_rtti_type (target, full, top, using_enc); + + if (real_type) + { + /* Copy qualifiers to the referenced object. */ + target_type = value_type (target); + real_type = make_cv_type (TYPE_CONST (target_type), + TYPE_VOLATILE (target_type), real_type, NULL); + if (TYPE_CODE (type) == TYPE_CODE_REF) + real_type = lookup_reference_type (real_type); + else if (TYPE_CODE (type) == TYPE_CODE_PTR) + real_type = lookup_pointer_type (real_type); + else + internal_error (__FILE__, __LINE__, _("Unexpected value type.")); + + /* Copy qualifiers to the pointer/reference. */ + real_type = make_cv_type (TYPE_CONST (type), TYPE_VOLATILE (type), + real_type, NULL); + } - return value_rtti_type (target, full, top, using_enc); + return real_type; } /* Given a value pointed to by ARGP, check its real run-time type, and diff --git a/gdb/value.c b/gdb/value.c index 583be33..85ea970 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -3134,11 +3134,30 @@ coerce_ref_if_computed (const struct value *arg) return funcs->coerce_ref (arg); } +/* Look at value.h for description. */ + +struct value * +readjust_indirect_value_type (struct value *value, struct type *enc_type, + struct type *original_type, + struct value *original_value) +{ + /* Re-adjust type. */ + deprecated_set_value_type (value, TYPE_TARGET_TYPE (original_type)); + + /* Add embedding info. */ + set_value_enclosing_type (value, enc_type); + set_value_embedded_offset (value, value_pointed_to_offset (original_value)); + + /* We may be pointing to an object of some derived type. */ + return value_full_object (value, NULL, 0, 0, 0); +} + struct value * coerce_ref (struct value *arg) { struct type *value_type_arg_tmp = check_typedef (value_type (arg)); struct value *retval; + struct type *enc_type; retval = coerce_ref_if_computed (arg); if (retval) @@ -3147,9 +3166,14 @@ coerce_ref (struct value *arg) if (TYPE_CODE (value_type_arg_tmp) != TYPE_CODE_REF) return arg; - return value_at_lazy (TYPE_TARGET_TYPE (value_type_arg_tmp), - unpack_pointer (value_type (arg), - value_contents (arg))); + enc_type = check_typedef (value_enclosing_type (arg)); + enc_type = TYPE_TARGET_TYPE (enc_type); + + retval = value_at_lazy (enc_type, + unpack_pointer (value_type (arg), + value_contents (arg))); + return readjust_indirect_value_type (retval, enc_type, + value_type_arg_tmp, arg); } struct value * diff --git a/gdb/value.h b/gdb/value.h index 2a2274d..d4c4a83 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -351,6 +351,19 @@ extern short *deprecated_value_regnum_hack (struct value *); extern struct value *coerce_ref_if_computed (const struct value *arg); +/* Setup a new value type and enclosing value type for dereferenced value VALUE. + ENC_TYPE is the new enclosing type that should be set. ORIGINAL_TYPE and + ORIGINAL_VAL are the type and value of the original reference or pointer. + + Note, that VALUE is modified by this function. + + It is a common implementation for coerce_ref and value_ind. */ + +extern struct value * readjust_indirect_value_type (struct value *value, + struct type *enc_type, + struct type *original_type, + struct value *original_val); + /* Convert a REF to the object referenced. */ extern struct value *coerce_ref (struct value *value); @@ -615,8 +628,8 @@ extern struct value *value_primitive_field (struct value *arg1, int offset, struct type *arg_type); -extern struct type *value_rtti_target_type (struct value *, int *, int *, - int *); +extern struct type *value_rtti_indirect_type (struct value *, int *, int *, + int *); extern struct value *value_full_object (struct value *, struct type *, int, int, int); --------------070606000005060401030101--