]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PR18617 - Incorrect expression bytecode generated for narrowing conversions
authorRobert O'Callahan <robert@ocallahan.org>
Wed, 8 Jul 2015 10:11:22 +0000 (11:11 +0100)
committerPedro Alves <palves@redhat.com>
Wed, 8 Jul 2015 10:11:22 +0000 (11:11 +0100)
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:
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.

gdb/ChangeLog
gdb/ax-gdb.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.trace/ax.exp

index b3b5c594acefc8754bd25232a247a85c8165564b..b376ab881ade8910047dc4560e802b305d64c170 100644 (file)
@@ -1,3 +1,8 @@
+2015-07-08  Robert O'Callahan  <robert@ocallahan.org>
+
+       PR exp/18617
+       * ax-gdb.c (gen_conversion): Extend to 'to' bits, not 'from'.
+
 2015-07-06  Joel Brobecker  <brobecker@adacore.com>
 
        * version.in: Set GDB version number to 7.9.90.DATE-cvs.
index 7a9d1e7a8f03d38f9ce068f9bffcc2dc46a54137..38dacac84650b7628fa4121e9ea989028035a339 100644 (file)
@@ -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.  */
index 0a90fa9b53ae1c2b2c936e6ff7699fae6a2e615a..e8651fa4eb1f81bc0e5ef34964db33361f40c3bc 100644 (file)
@@ -1,3 +1,8 @@
+2015-07-08  Robert O'Callahan  <robert@ocallahan.org>
+
+       PR exp/18617
+       * gdb.trace/ax.exp: Add test.
+
 2015-06-30  Martin Galvan  <martin.galvan@tallertechnologies.com>
 
        * lib/gdb.exp (test_class_help): Remove the unneeded escaping of
index e3d0479d92ca677e5e0380daac7039287f66f56b..d0644756fb2a4703c1d7372600080831519e3495 100644 (file)
@@ -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"