Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: Cary Coutant <ccoutant@google.com>,
	Ulrich Weigand <uweigand@de.ibm.com>,
	       gdb-patches@sourceware.org
Subject: Re: RFC: implement typed DWARF stack
Date: Fri, 03 Jun 2011 13:52:00 -0000	[thread overview]
Message-ID: <m3hb87ja53.fsf@fleche.redhat.com> (raw)
In-Reply-To: <20110517083521.GZ17079@tyan-ft48-01.lab.bos.redhat.com> (Jakub	Jelinek's message of "Tue, 17 May 2011 10:35:21 +0200")

>>>>> "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));


  reply	other threads:[~2011-06-03 13:52 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-04 20:48 Tom Tromey
2011-05-05 16:47 ` Tom Tromey
2011-05-05 18:07 ` Ulrich Weigand
2011-05-05 18:38   ` Tom Tromey
2011-05-05 20:15     ` Tom Tromey
2011-05-09 22:02       ` Ulrich Weigand
2011-05-10 14:15         ` Tom Tromey
2011-05-11  0:15           ` Ulrich Weigand
2011-05-11 14:59             ` Tom Tromey
2011-05-11 19:44               ` Tom Tromey
2011-05-12  0:03               ` Ulrich Weigand
2011-05-12 16:33                 ` Tom Tromey
2011-05-13  7:52                   ` Regression: " Jan Kratochvil
2011-05-13 15:44                     ` Tom Tromey
2011-05-15  8:26                       ` gdbindex crash: " Jan Kratochvil
2011-05-16 17:37                         ` Tom Tromey
2011-05-17 17:01                           ` Tom Tromey
2011-05-13 17:17                     ` Tom Tromey
2011-05-13 17:34                       ` Jan Kratochvil
2011-05-12 19:32             ` Tom Tromey
2011-05-16 15:50               ` Ulrich Weigand
2011-05-16 18:09                 ` Tom Tromey
2011-05-17  8:35                   ` Jakub Jelinek
2011-06-03 13:52                     ` Tom Tromey [this message]
2011-05-10 16:39         ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3hb87ja53.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=ccoutant@google.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jakub@redhat.com \
    --cc=uweigand@de.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox