From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19436 invoked by alias); 2 Oct 2008 17:27:21 -0000 Received: (qmail 19420 invoked by uid 22791); 2 Oct 2008 17:27:20 -0000 X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 02 Oct 2008 17:26:28 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id m92HQQnY025068 for ; Thu, 2 Oct 2008 13:26:26 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m92HQPNn021629; Thu, 2 Oct 2008 13:26:25 -0400 Received: from opsy.redhat.com (vpn-10-142.bos.redhat.com [10.16.10.142]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id m92HQOdU023401; Thu, 2 Oct 2008 13:26:25 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id 0D2EF3785EE; Thu, 2 Oct 2008 11:24:58 -0600 (MDT) To: gdb-patches@sourceware.org Subject: RFA: fix crash in expression evaluation From: Tom Tromey Reply-To: tromey@redhat.com X-Attribution: Tom Date: Thu, 02 Oct 2008 17:27:00 -0000 Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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: 2008-10/txt/msg00058.txt.bz2 On irc, Vladimir pointed out this crash: http://dev.eclipse.org/mhonarc/lists/cdt-dev/msg13422.html This problem seems to have snuck in via the recent pointer math changes. This patch fixes the crash by changing coerce_array to look through typedefs. Built and regtested on x86-64 (compile farm). New test case included. Please review. Tom :ADDPATCH expressions: 2008-10-02 Tom Tromey * value.c (coerce_array): Use check_typedef. 2008-10-02 Tom Tromey * gdb.base/pointers.exp: Add test. * gdb.base/pointers.c (k, S): New typedefs. (instance): New global. diff --git a/gdb/testsuite/gdb.base/pointers.c b/gdb/testsuite/gdb.base/pointers.c index 85bfdc9..4ee5e78 100644 --- a/gdb/testsuite/gdb.base/pointers.c +++ b/gdb/testsuite/gdb.base/pointers.c @@ -71,6 +71,15 @@ float ** ptr_to_ptr_to_float; int y; + +typedef long k[5]; + +typedef struct { + k array_variable; +} S; + +S instance; + /* Do nothing function used for forcing some of the above variables to be referenced by the program source. If the variables are not referenced, some linkers will remove the symbol from the symbol diff --git a/gdb/testsuite/gdb.base/pointers.exp b/gdb/testsuite/gdb.base/pointers.exp index 5532140..d7d17e7 100644 --- a/gdb/testsuite/gdb.base/pointers.exp +++ b/gdb/testsuite/gdb.base/pointers.exp @@ -596,3 +596,7 @@ gdb_expect { timeout { fail "(timeout) ptype ppppppC" } } +# Regression test for a crash. + +gdb_test "p instance.array_variable + 0" \ + " = \\(long int \\*\\) 0x\[0-9a-f\]*" diff --git a/gdb/value.c b/gdb/value.c index f3f2c72..0c33959 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1692,11 +1692,16 @@ coerce_ref (struct value *arg) struct value * coerce_array (struct value *arg) { + struct type *type; arg = coerce_ref (arg); + type = check_typedef (value_type (arg)); if (current_language->c_style_arrays - && TYPE_CODE (value_type (arg)) == TYPE_CODE_ARRAY) - arg = value_coerce_array (arg); - if (TYPE_CODE (value_type (arg)) == TYPE_CODE_FUNC) + && TYPE_CODE (type) == TYPE_CODE_ARRAY) + { + arg = value_coerce_array (arg); + type = check_typedef (value_type (arg)); + } + if (TYPE_CODE (type) == TYPE_CODE_FUNC) arg = value_coerce_function (arg); return arg; }