From patchwork Fri Jul 3 01:09:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert O'Callahan X-Patchwork-Id: 7479 Received: (qmail 70466 invoked by alias); 3 Jul 2015 01:09:57 -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 70455 invoked by uid 89); 3 Jul 2015 01:09:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f48.google.com Received: from mail-pa0-f48.google.com (HELO mail-pa0-f48.google.com) (209.85.220.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 03 Jul 2015 01:09:56 +0000 Received: by pacws9 with SMTP id ws9so49277381pac.0 for ; Thu, 02 Jul 2015 18:09:54 -0700 (PDT) X-Received: by 10.66.63.9 with SMTP id c9mr71248706pas.40.1435885794212; Thu, 02 Jul 2015 18:09:54 -0700 (PDT) Received: from ?IPv6:2001:cb0:b202:232:2677:3ff:fece:dc64? ([2001:cb0:b202:232:2677:3ff:fece:dc64]) by mx.google.com with ESMTPSA id qa1sm7018491pab.0.2015.07.02.18.09.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Jul 2015 18:09:53 -0700 (PDT) To: gdb-patches@sourceware.org From: Robert O'Callahan Subject: [PATCH] preserve 'to' bits when generating bytecode for a narrowing conversion Message-ID: <5595E0DB.30104@ocallahan.org> Date: Fri, 3 Jul 2015 13:09:47 +1200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 MIME-Version: 1.0 The existing code preserves 'from' bits, which is incorrect. E.g. (gdb) maint agent-eval (char)255L Scope: 0x4008d6 Reg mask: 00 0 const16 255 3 ext 64 5 end 'ext 64' should be 'ext 8'; this bytecode evaluates to 255 instead of the correct result of -1. The fix is simple. I ran the entire test suite on x86-64 and there were no new test failures. gdb/ChangeLog: 2014-06-18 Robert O'Callahan * ax-gdb.c (gen_conversion): Update. gdb/testsuite/ChangeLog: 2014-06-18 Robert O'Callahan * ax.exp: Add test. --- gdb/ax-gdb.c | 2 +- gdb/testsuite/gdb.trace/ax.exp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index 7a9d1e7..38dacac 100644 --- a/gdb/ax-gdb.c +++ b/gdb/ax-gdb.c @@ -885,7 +885,7 @@ gen_conversion (struct agent_expr *ax, struct type *from, struct type *to) /* If we're converting to a narrower type, then we need to clear out the upper bits. */ if (TYPE_LENGTH (to) < TYPE_LENGTH (from)) - gen_extend (ax, from); + gen_extend (ax, to); /* If the two values have equal width, but different signednesses, then we need to extend. */ diff --git a/gdb/testsuite/gdb.trace/ax.exp b/gdb/testsuite/gdb.trace/ax.exp index e3d0479..d064475 100644 --- a/gdb/testsuite/gdb.trace/ax.exp +++ b/gdb/testsuite/gdb.trace/ax.exp @@ -80,6 +80,8 @@ gdb_test "maint agent &gdb_long_test == &gdb_short_test" "" "maint agent &gdb_lo gdb_test "maint agent &gdb_long_test < &gdb_short_test" "" "maint agent &gdb_long_test < &gdb_short_test" +gdb_test "maint agent (unsigned char)1L" ".*ext 8.*" "maint agent (unsigned char)1L" + # Now test eval version of agent expressions. gdb_test "maint agent-eval 12" ".*const8 12.*end.*" "maint agent-eval 12"