From patchwork Tue Mar 29 17:13:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Don Breazeal X-Patchwork-Id: 11550 Received: (qmail 92084 invoked by alias); 29 Mar 2016 17:14:06 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 92029 invoked by uid 89); 29 Mar 2016 17:14:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 29 Mar 2016 17:13:49 +0000 Received: from svr-orw-fem-02x.mgc.mentorg.com ([147.34.96.206] helo=SVR-ORW-FEM-02.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1akxD9-00057n-M4 from Don_Breazeal@mentor.com ; Tue, 29 Mar 2016 10:13:47 -0700 Received: from [172.30.6.122] (147.34.91.1) by SVR-ORW-FEM-02.mgc.mentorg.com (147.34.96.168) with Microsoft SMTP Server (TLS) id 14.3.224.2; Tue, 29 Mar 2016 10:13:47 -0700 Subject: Re: [PATCH] Eliminate -var-create error for optzd ptr to struct To: Yao Qi , "Breazeal, Don" References: <1456273154-28629-1-git-send-email-donb@codesourcery.com> <56CD03F5.6080505@codesourcery.com> <56CDDAEE.1030504@codesourcery.com> <86r3etsdbh.fsf@gmail.com> CC: "Gustavo, Luis" , "gdb-patches@sourceware.org" From: Don Breazeal Message-ID: <56FAB7CB.20406@codesourcery.com> Date: Tue, 29 Mar 2016 10:13:47 -0700 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 MIME-Version: 1.0 In-Reply-To: <86r3etsdbh.fsf@gmail.com> X-IsSubscribed: yes On 3/29/2016 5:01 AM, Yao Qi wrote: > Don Breazeal writes: > >>>> @@ -1203,9 +1203,10 @@ value_actual_type (struct value *value, int resolve_simple_types, >>>> /* If result's target type is TYPE_CODE_STRUCT, proceed to >>>> fetch its rtti type. */ >>>> if ((TYPE_CODE (result) == TYPE_CODE_PTR >>>> - || TYPE_CODE (result) == TYPE_CODE_REF) >>>> + || TYPE_CODE (result) == TYPE_CODE_REF) >>> >>> Is this just a formatting change? >> >> Yes. I should have documented that in the ChangeLog. > > If it is just a format change, you can move it to a separate patch, and > commit it as obvious. Don't mix format change with your bug fix patch. > Hi Yao, Here is the patch with the formatting change removed, and with the more concise patch description posted most recent patchset. Thanks, --Don ---- This patch eliminates an error thrown when accessing the value of a pointer to a structure where the pointer has been optimized out and 'set print object' is 'on'. The error shows up as the rather ugly value of the pointer variable in Eclipse. If 'set print object' is 'on', GDB tries to determine the actual (derived) type of the object rather than the declared type, which requires dereferencing the pointer, which in this cases throws an error because the pointer has been optimized out. The fix is to simply ignore the 'print object on' setting for pointers or references to structures when they have been optimized out. This means we just get the declared type instead of the actual type, because in this case that's the best that we can do. I'm working on setting things in motion for a patch to Eclipse that recognizes optimized-out pointer-to-struct in this scenario and prevents any subsequent attempt to dereference it from that end. Tested on bare-metal powerpc board with Linux x86 host. gdb/ChangeLog: 2016-03-29 Don Breazeal * gdb/value.c (value_actual_type): Ignore the 'print object on' setting if the object is a pointer to or reference to a structure. --- gdb/value.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gdb/value.c b/gdb/value.c index 738b2b2..95bfdb2 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1205,7 +1205,8 @@ value_actual_type (struct value *value, int resolve_simple_types, if ((TYPE_CODE (result) == TYPE_CODE_PTR || TYPE_CODE (result) == TYPE_CODE_REF) && TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result))) - == TYPE_CODE_STRUCT) + == TYPE_CODE_STRUCT + && !value_optimized_out (value)) { struct type *real_type;