aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2011-06-03 14:57:29 +0000
committerTom Tromey <tromey@redhat.com>2011-06-03 14:57:29 +0000
commit8ddd9a20a759fb2dd5d221914747eaf62c62c994 (patch)
tree1c7fde90736efcfeda6947ef5c8efea53943910f
parent331fe6162297aba0d59fd5e3364b498c8d894d4c (diff)
downloadgdb-8ddd9a20a759fb2dd5d221914747eaf62c62c994.zip
gdb-8ddd9a20a759fb2dd5d221914747eaf62c62c994.tar.gz
gdb-8ddd9a20a759fb2dd5d221914747eaf62c62c994.tar.bz2
* dwarf2expr.c (get_signed_type): New function.
(execute_stack_op) <DW_OP_shra>: Always perform a signed shift.
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/dwarf2expr.c34
2 files changed, 39 insertions, 0 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 182909d..97a30af 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2011-06-03 Tom Tromey <tromey@redhat.com>
+
+ * dwarf2expr.c (get_signed_type): New function.
+ (execute_stack_op) <DW_OP_shra>: Always perform a signed shift.
+
2011-06-02 Keith Seitz <keiths@redhat.com>
* objc-lang.c (find_methods): Increment objfile_csym earlier.
diff --git a/gdb/dwarf2expr.c b/gdb/dwarf2expr.c
index 5cd33a6..3c60b6a 100644
--- a/gdb/dwarf2expr.c
+++ b/gdb/dwarf2expr.c
@@ -229,6 +229,28 @@ get_unsigned_type (struct gdbarch *gdbarch, struct type *type)
}
}
+/* Return the signed form of TYPE. TYPE is necessarily an integral
+ type. */
+
+static struct type *
+get_signed_type (struct gdbarch *gdbarch, struct type *type)
+{
+ switch (TYPE_LENGTH (type))
+ {
+ case 1:
+ return builtin_type (gdbarch)->builtin_int8;
+ case 2:
+ return builtin_type (gdbarch)->builtin_int16;
+ case 4:
+ return builtin_type (gdbarch)->builtin_int32;
+ case 8:
+ return builtin_type (gdbarch)->builtin_int64;
+ default:
+ error (_("no signed variant found for type, while evaluating "
+ "DWARF expression"));
+ }
+}
+
/* Retrieve the N'th item on CTX's stack, converted to an address. */
CORE_ADDR
@@ -996,7 +1018,19 @@ execute_stack_op (struct dwarf_expr_context *ctx,
case DW_OP_shra:
dwarf_require_integral (value_type (first));
dwarf_require_integral (value_type (second));
+ if (TYPE_UNSIGNED (value_type (first)))
+ {
+ struct type *stype
+ = get_signed_type (ctx->gdbarch, value_type (first));
+
+ first = value_cast (stype, first);
+ }
+
result_val = value_binop (first, second, BINOP_RSH);
+ /* Make sure we wind up with the same type we started
+ with. */
+ if (value_type (result_val) != value_type (second))
+ result_val = value_cast (value_type (second), result_val);
break;
case DW_OP_xor:
dwarf_require_integral (value_type (first));