From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2852 invoked by alias); 3 Jun 2011 13:52:02 -0000 Received: (qmail 2843 invoked by uid 22791); 3 Jun 2011 13:52:01 -0000 X-SWARE-Spam-Status: No, hits=-6.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 03 Jun 2011 13:51:41 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p53Dpc9X008965 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 3 Jun 2011 09:51:38 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p53DpcIs028334; Fri, 3 Jun 2011 09:51:38 -0400 Received: from opsy.redhat.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p53DpbKi019528; Fri, 3 Jun 2011 09:51:37 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id B694F37817D; Fri, 3 Jun 2011 07:51:36 -0600 (MDT) From: Tom Tromey To: Jakub Jelinek Cc: Cary Coutant , Ulrich Weigand , gdb-patches@sourceware.org Subject: Re: RFC: implement typed DWARF stack References: <201105161550.p4GFo5hk014748@d06av02.portsmouth.uk.ibm.com> <20110517083521.GZ17079@tyan-ft48-01.lab.bos.redhat.com> Date: Fri, 03 Jun 2011 13:52:00 -0000 In-Reply-To: <20110517083521.GZ17079@tyan-ft48-01.lab.bos.redhat.com> (Jakub Jelinek's message of "Tue, 17 May 2011 10:35:21 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (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: 2011-06/txt/msg00050.txt.bz2 >>>>> "Jakub" == Jakub Jelinek writes: Jakub> My point is that we have two right shift operations, DW_OP_shr{,a}, so Jakub> it is IMHO better to just keep them as two operations even for typed Jakub> stack. Ok, no problem. I am checking this in on the trunk; it changes DW_OP_shra to always be a signed operation. Tom 2011-06-03 Tom Tromey * dwarf2expr.c (get_signed_type): New function. (execute_stack_op) : Always perform a signed shift. diff --git a/gdb/dwarf2expr.c b/gdb/dwarf2expr.c index 5cd33a6..3c60b6a 100644 --- a/gdb/dwarf2expr.c +++ b/gdb/dwarf2expr.c @@ -229,6 +229,28 @@ get_unsigned_type (struct gdbarch *gdbarch, struct type *type) } } +/* Return the signed form of TYPE. TYPE is necessarily an integral + type. */ + +static struct type * +get_signed_type (struct gdbarch *gdbarch, struct type *type) +{ + switch (TYPE_LENGTH (type)) + { + case 1: + return builtin_type (gdbarch)->builtin_int8; + case 2: + return builtin_type (gdbarch)->builtin_int16; + case 4: + return builtin_type (gdbarch)->builtin_int32; + case 8: + return builtin_type (gdbarch)->builtin_int64; + default: + error (_("no signed variant found for type, while evaluating " + "DWARF expression")); + } +} + /* Retrieve the N'th item on CTX's stack, converted to an address. */ CORE_ADDR @@ -996,7 +1018,19 @@ execute_stack_op (struct dwarf_expr_context *ctx, case DW_OP_shra: dwarf_require_integral (value_type (first)); dwarf_require_integral (value_type (second)); + if (TYPE_UNSIGNED (value_type (first))) + { + struct type *stype + = get_signed_type (ctx->gdbarch, value_type (first)); + + first = value_cast (stype, first); + } + result_val = value_binop (first, second, BINOP_RSH); + /* Make sure we wind up with the same type we started + with. */ + if (value_type (result_val) != value_type (second)) + result_val = value_cast (value_type (second), result_val); break; case DW_OP_xor: dwarf_require_integral (value_type (first));