From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17373 invoked by alias); 13 Nov 2010 02:15:31 -0000 Received: (qmail 17364 invoked by uid 22791); 13 Nov 2010 02:15:30 -0000 X-SWARE-Spam-Status: No, hits=-1.2 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,KAM_STOCKGEN,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 13 Nov 2010 02:15:19 +0000 Received: from wpaz9.hot.corp.google.com (wpaz9.hot.corp.google.com [172.24.198.73]) by smtp-out.google.com with ESMTP id oAD2FHxi027596 for ; Fri, 12 Nov 2010 18:15:17 -0800 Received: from ruffy.mtv.corp.google.com (ruffy.mtv.corp.google.com [172.18.118.116]) by wpaz9.hot.corp.google.com with ESMTP id oAD2FGPV013084 for ; Fri, 12 Nov 2010 18:15:17 -0800 Received: by ruffy.mtv.corp.google.com (Postfix, from userid 67641) id 43ECE2461B0; Fri, 12 Nov 2010 18:15:16 -0800 (PST) To: gdb-patches@sourceware.org Subject: patch for 7.2.1? dwarf2read.c (dwarf2_const_value_data): Never sign extend. Message-Id: <20101113021516.43ECE2461B0@ruffy.mtv.corp.google.com> Date: Sat, 13 Nov 2010 02:15:00 -0000 From: dje@google.com (Doug Evans) X-System-Of-Record: true X-IsSubscribed: yes 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: 2010-11/txt/msg00167.txt.bz2 This is rather nasty. class test { static const int k128 = 128; }; test foo; int main () { return 0; } $ gdb a.out (gdb) start (gdb) p test::k128 -128 I propose adding this patch to the 7.2.1 branch. [I haven't run a regression test. If there are changes needed I'll check for those before checking in.] 2010-07-27 Tom Tromey * dwarf2read.c (dwarf2_const_value_data): Never sign extend. Index: dwarf2read.c =================================================================== RCS file: /cvs/src/src/gdb/dwarf2read.c,v retrieving revision 1.431 retrieving revision 1.432 diff -u -p -r1.431 -r1.432 --- dwarf2read.c 28 Jul 2010 19:04:07 -0000 1.431 +++ dwarf2read.c 28 Jul 2010 20:05:03 -0000 1.432 @@ -10485,8 +10485,13 @@ dwarf2_const_value (struct attribute *at } -/* Given an attr with a DW_FORM_dataN value in host byte order, sign- - or zero-extend it as appropriate for the symbol's type. */ +/* Given an attr with a DW_FORM_dataN value in host byte order, + zero-extend it as appropriate for the symbol's type. The DWARF + standard (v4) is not entirely clear about the meaning of using + DW_FORM_dataN for a constant with a signed type, where the type is + wider than the data. The conclusion of a discussion on the DWARF + list was that this is unspecified. We choose to always zero-extend + because that is the interpretation long in use by GCC. */ static void dwarf2_const_value_data (struct attribute *attr, struct symbol *sym, @@ -10495,12 +10500,7 @@ dwarf2_const_value_data (struct attribut LONGEST l = DW_UNSND (attr); if (bits < sizeof (l) * 8) - { - if (TYPE_UNSIGNED (SYMBOL_TYPE (sym))) - l &= ((LONGEST) 1 << bits) - 1; - else - l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits); - } + l &= ((LONGEST) 1 << bits) - 1; SYMBOL_VALUE (sym) = l; SYMBOL_CLASS (sym) = LOC_CONST;