This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: RFC: implement typed DWARF stack
- From: Tom Tromey <tromey at redhat dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: Cary Coutant <ccoutant at google dot com>, Ulrich Weigand <uweigand at de dot ibm dot com>, gdb-patches at sourceware dot org
- Date: Fri, 03 Jun 2011 07:51:36 -0600
- Subject: Re: RFC: implement typed DWARF stack
- References: <m3aaerlnox.fsf@fleche.redhat.com> <201105161550.p4GFo5hk014748@d06av02.portsmouth.uk.ibm.com> <m3iptah607.fsf@fleche.redhat.com> <20110517083521.GZ17079@tyan-ft48-01.lab.bos.redhat.com>
>>>>> "Jakub" == Jakub Jelinek <jakub@redhat.com> writes:
Jakub> My point is that we have two right shift operations, DW_OP_shr{,a}, so
Jakub> it is IMHO better to just keep them as two operations even for typed
Jakub> stack.
Ok, no problem. I am checking this in on the trunk; it changes
DW_OP_shra to always be a signed operation.
Tom
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.
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));