From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 119813 invoked by alias); 15 May 2015 14:49:59 -0000 Mailing-List: contact gdb-testers-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-testers-owner@sourceware.org Received: (qmail 119804 invoked by uid 89); 15 May 2015 14:49:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.8 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 X-HELO: kwanyin.sergiodj.net Received: from kwanyin.sergiodj.net (HELO kwanyin.sergiodj.net) (176.31.208.32) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 15 May 2015 14:49:57 +0000 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [binutils-gdb] [Ada] problem printing negative integer values in packed arrays. From: sergiodj+buildbot@redhat.com To: gdb-testers@sourceware.org Message-Id: <9cd4d857bb046ad9be3c6d978b5b2aebb528eaf4@kwanyin> Date: Fri, 15 May 2015 14:49:00 -0000 X-SW-Source: 2015-q2/txt/msg04403.txt.bz2 *** TEST RESULTS FOR COMMIT 9cd4d857bb046ad9be3c6d978b5b2aebb528eaf4 *** Author: Joel Brobecker Branch: master Commit: 9cd4d857bb046ad9be3c6d978b5b2aebb528eaf4 [Ada] problem printing negative integer values in packed arrays. Consider the following declarations: type Signed_Small is new Integer range - (2 ** 5) .. (2 ** 5 - 1); type Signed_Simple_Array is array (1 .. 4) of Signed_Small; pragma Pack (Signed_Simple_Array); SSA : Signed_Simple_Array := (-1, 2, -3, 4); GDB currently print its value incorrectly for the elements that are negative: (gdb) print ssa $1 = (65535, 2, 1048573, 4) (gdb) print ssa(1) $2 = 65535 (gdb) print ssa(2) $3 = 2 (gdb) print ssa(3) $4 = 1048573 (gdb) print ssa(4) $5 = 4 What happens is that the sign-extension is not working because we're trying to do left shift with a negative count. In ada_value_primitive_packed_val, we have a loop which populates the extra bits of the target (unpacked) value, after extraction of the data from the original (packed) value: while (ntarg > 0) { accum |= sign << accumSize; unpacked[targ] = accum & ~(~0L << HOST_CHAR_BIT); !!! -> accumSize -= HOST_CHAR_BIT; accum >>= HOST_CHAR_BIT; ntarg -= 1; targ += delta; } At each iteration, accumSize gets decremented by HOST_CHAR_BIT, which can easily cause it to become negative, particularly on little endian targets, where accumSize is at most HOST_CHAR_BIT - 1. This causes us to perform a left-shift operation with a negative accumSize at the next loop iteration, which is undefined, and acutally does not produce the effect we wanted (value left untouched) when the code is compiled with GCC. This patch fixes the issue by simply setting accumSize to zero if negative. gdb/ChangeLog: * ada-lang.c (ada_value_primitive_packed_val): Make sure accumSize is never negative. gdb/testsuite/ChangeLog: * gdb.ada/pckd_neg: New testcase.