From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 58715 invoked by alias); 24 Feb 2016 01:14:41 -0000 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 Received: (qmail 58631 invoked by uid 89); 24 Feb 2016 01:14:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=Results 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 ESMTP; Wed, 24 Feb 2016 01:14:35 +0000 Received: from svr-orw-fem-06.mgc.mentorg.com ([147.34.97.120]) by relay1.mentorg.com with esmtp id 1aYO2C-00055E-N5 from Luis_Gustavo@mentor.com for gdb-patches@sourceware.org; Tue, 23 Feb 2016 17:14:32 -0800 Received: from [172.30.1.130] (147.34.91.1) by SVR-ORW-FEM-06.mgc.mentorg.com (147.34.97.120) with Microsoft SMTP Server id 14.3.224.2; Tue, 23 Feb 2016 17:14:32 -0800 Subject: Re: [PATCH] Eliminate -var-create error for optzd ptr to struct References: <1456273154-28629-1-git-send-email-donb@codesourcery.com> To: Don Breazeal , Reply-To: Luis Machado From: Luis Machado Message-ID: <56CD03F5.6080505@codesourcery.com> Date: Wed, 24 Feb 2016 01:14:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <1456273154-28629-1-git-send-email-donb@codesourcery.com> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2016-02/txt/msg00704.txt.bz2 On 02/23/2016 09:19 PM, Don Breazeal wrote: > Problem: > This patch eliminates an error thrown when accessing the value of a > pointer to a structure where the pointer has been optimized out. > The error shows up as the rather ugly value of the pointer variable > in Eclipse. > > With this change such an access will return "" like > other optimized out variables. We should throw an error when > dereferencing an optimized-out pointer, but not when just looking > at its value. > > Cause: > The error only occurs when '-gdb-set print object on' has been set. > This setting requires GDB to "identify the actual (derived) type of > the object rather than the declared type". Part of this process > is to dereference the pointer in order to get the type of the thing > that is pointed-to. Since the pointer has been optimized out, this > is impossible, and an error is thrown. > > Fix: > 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. > > Results: > Attempts to dereference the optimized-out pointer using -var-create > or -data-evaluate-expression will throw an error, but a dereference > using -var-evaluate-expression will return an empty value. To be > consistent, this last case would also throw an error. I looked into > this some, enough to confirm that there isn't an obvious fix. Given > that my goal is just to eliminate the unnecessary error, I stopped here. > > 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. > > Testing: > I looked at creating a test case for this, but so far haven't been > able to create anything general enough to include in the test suite. > > Tested on bare-metal powerpc board with Linux x86_64 host. > > OK? > > thanks > --Don > > gdb/ChangeLog: > 2016-02-23 Don Breazeal > > * gdb/value.c (value_actual_type): Ignore the 'print object > on' setting for pointers and references to structures. > > --- > gdb/value.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/gdb/value.c b/gdb/value.c > index 738b2b2..50e4f8a 100644 > --- a/gdb/value.c > +++ b/gdb/value.c > @@ -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? > && TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result))) > - == TYPE_CODE_STRUCT) > + == TYPE_CODE_STRUCT > + && !value_optimized_out (value)) > { > struct type *real_type; > Otherwise looks OK to me. As for the testcase, how about one that creates a few pointer variables (to basic types, structures, arrays and other meaningful ones) and tries to print their original values with the "print object" enabled. This would be in MI mode, of course. I'd expect the error to be thrown in an unpatched gdb and a string for the patched debugger.