public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] preserve 'to' bits when generating bytecode for a narrowing conversion
@ 2015-07-03  1:09 Robert O'Callahan
  2015-07-08 10:19 ` Pedro Alves
  0 siblings, 1 reply; 2+ messages in thread
From: Robert O'Callahan @ 2015-07-03  1:09 UTC (permalink / raw)
  To: gdb-patches

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  <robert@ocallahan.org>

	* ax-gdb.c (gen_conversion): Update.

gdb/testsuite/ChangeLog:
2014-06-18  Robert O'Callahan  <robert@ocallahan.org>

	* 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"
-- 
2.4.3

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] preserve 'to' bits when generating bytecode for a narrowing conversion
  2015-07-03  1:09 [PATCH] preserve 'to' bits when generating bytecode for a narrowing conversion Robert O'Callahan
@ 2015-07-08 10:19 ` Pedro Alves
  0 siblings, 0 replies; 2+ messages in thread
From: Pedro Alves @ 2015-07-08 10:19 UTC (permalink / raw)
  To: Robert O'Callahan, gdb-patches

On 07/03/2015 02:09 AM, Robert O'Callahan wrote:

> gdb/ChangeLog:
> 2014-06-18  Robert O'Callahan  <robert@ocallahan.org>
> 
> 	* ax-gdb.c (gen_conversion): Update.
> 
> gdb/testsuite/ChangeLog:
> 2014-06-18  Robert O'Callahan  <robert@ocallahan.org>
> 
> 	* ax.exp: Add test.

Thanks!

Pushed to both master and 7.10 branch with slightly fixed
ChangeLog entries:

gdb/ChangeLog:
2015-07-08  Robert O'Callahan  <robert@ocallahan.org>

	PR exp/18617
	* ax-gdb.c (gen_conversion): Extend to 'to' bits, not 'from'.

gdb/testsuite/ChangeLog:
2015-07-08  Robert O'Callahan  <robert@ocallahan.org>

	PR exp/18617
	* gdb.trace/ax.exp: Add test.

-- 
Pedro Alves

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-07-08 10:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-03  1:09 [PATCH] preserve 'to' bits when generating bytecode for a narrowing conversion Robert O'Callahan
2015-07-08 10:19 ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).