From patchwork Fri Apr 1 16:01:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Don Breazeal X-Patchwork-Id: 11593 Received: (qmail 34332 invoked by alias); 1 Apr 2016 16:01:59 -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 34319 invoked by uid 89); 1 Apr 2016 16:01:58 -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=11927 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; Fri, 01 Apr 2016 16:01:48 +0000 Received: from svr-orw-fem-03.mgc.mentorg.com ([147.34.97.39]) by relay1.mentorg.com with esmtp id 1am1W6-0002Us-9i from Don_Breazeal@mentor.com ; Fri, 01 Apr 2016 09:01:46 -0700 Received: from build4-lucid-cs (147.34.91.1) by svr-orw-fem-03.mgc.mentorg.com (147.34.97.39) with Microsoft SMTP Server id 14.3.224.2; Fri, 1 Apr 2016 09:01:45 -0700 Received: by build4-lucid-cs (Postfix, from userid 1905) id 9AAFD412F8; Fri, 1 Apr 2016 09:01:45 -0700 (PDT) From: Don Breazeal To: , Subject: Re: [PATCH] Eliminate -var-create error for optzd ptr to struct Date: Fri, 1 Apr 2016 09:01:45 -0700 Message-ID: <1459526505-19291-1-git-send-email-donb@codesourcery.com> In-Reply-To: <86a8lgrq3f.fsf@gmail.com> MIME-Version: 1.0 X-IsSubscribed: yes Hi Yao, Thanks for the review. > Please run regression test on x86-linux. If the test is regression > free, the patch is good to me. Well, that was a good call, the test was not regression-free. There were failures in gdb.mi/mi-var-list-children-invalid-grandchild.exp. The test resulted in a memory access error in the call to value_optimized_out that I had added. Before my change there was a memory access error caught in value_rtti_indirect_type, which returned NULL in that case. The fix was to catch and ignore errors from value_optimized_out. Details: The test had a pointer to a structure (p_outer), and the structure contained a pointer to another structure (p_outer->inner). The p_outer pointer was set to 0x0, and -var-create and -var-list-children were called for p_outer. With 'set print object' set to 'on', GDB wants to check the actual (rtti) type of p_outer->inner for -var-list-children. Without my change, value_rtti_indirect_type handled the memory access error when it dereferenced p_outer (0x0). With my change, value_optimized_out threw an error trying to get the value of p_outer->inner, since p_outer == 0x0. The fix is to catch errors from value_optimized_out. If we get an error, then we can't tell if the value is optimized out and we default to 'not optimized out'. We let value_rtti_indirect_type handle the memory error. I assume that I didn't see this with my bare-metal testing because it wasn't an error to access address 0x0. I'll be sure to keep that in mind in future testing. Updated patch, patch description, and ChangeLog below. OK with these changes? BTW I will hold off pushing in the corresponding test until this patch is finalized, to avoid introducing new failures. 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. Note that we if value_optimized_out throws an error we just assume the value is not optimized out. We let value_rtti_indirect_type handle any errors, and don't try to duplicate its error handling. 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 and Linux native x86_64. gdb/ChangeLog: 2016-04-01 Don Breazeal * value.c (value_actual_type): Don't try to get rtti type of the value if it has been optimized out. --- gdb/value.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/gdb/value.c b/gdb/value.c index 8268b08..018896e 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1192,6 +1192,7 @@ value_actual_type (struct value *value, int resolve_simple_types, { struct value_print_options opts; struct type *result; + int value_optzd_out; get_user_print_options (&opts); @@ -1200,12 +1201,26 @@ value_actual_type (struct value *value, int resolve_simple_types, result = value_type (value); if (opts.objectprint) { - /* 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 (check_typedef (TYPE_TARGET_TYPE (result))) - == TYPE_CODE_STRUCT) + TRY + { + value_optzd_out = value_optimized_out (value); + } + CATCH (ex, RETURN_MASK_ERROR) + { + /* If we get an error, assume the value is not optimized out. + If we call value_rtti_indirect_type, it will handle any + errors there; otherwise it won't matter. */ + value_optzd_out = 0; + } + END_CATCH + + /* 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 (check_typedef (TYPE_TARGET_TYPE (result))) + == TYPE_CODE_STRUCT + && !value_optzd_out) { struct type *real_type;