Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Mark Kettenis <kettenis@gnu.org>
To: gdb-patches@sources.redhat.com
Subject: [RFA] Fix mips32_relative_offset()
Date: Tue, 09 Nov 2004 12:57:00 -0000	[thread overview]
Message-ID: <200411091256.iA9CujKE090590@elgar.sibelius.xs4all.nl> (raw)

The current code assumes that sizeof(long) == 32, which obviously
isn't true on LP64 platforms.  The attached patch fixes that by using
the sign-extension idiom that's also used for SPARC.  It still assumes
that a long can hold a 18-bit signed integer, but ISO C guarantees
that it can.

OK?

Mark

P.S. Incidentally I think the function should return a LONGEST instead
     of CORE_ADDR.


Index: ChangeLog
from  Mark Kettenis  <kettenis@gnu.org>

	* mips-tdep.c (mips32_relative_offset): Avoid ussumption that
	sizeof(long) == 32.

Index: mips-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/mips-tdep.c,v
retrieving revision 1.362
diff -u -p -r1.362 mips-tdep.c
--- mips-tdep.c 31 Oct 2004 21:51:58 -0000 1.362
+++ mips-tdep.c 9 Nov 2004 12:51:40 -0000
@@ -881,14 +881,8 @@ mips_fetch_instruction (CORE_ADDR addr)
 static CORE_ADDR
 mips32_relative_offset (unsigned long inst)
 {
-  long x;
-  x = itype_immediate (inst);
-  if (x & 0x8000)		/* sign bit set */
-    {
-      x |= 0xffff0000;		/* sign extension */
-    }
-  x = x << 2;
-  return x;
+  long x = ((itype_immediate (inst) ^ 0x8000) - 0x8000);
+  return x << 2;
 }
 
 /* Determine whate to set a single step breakpoint while considering


             reply	other threads:[~2004-11-09 12:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-09 12:57 Mark Kettenis [this message]
2004-11-10 14:39 ` Andrew Cagney
2004-11-10 17:48   ` Mark Kettenis

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=200411091256.iA9CujKE090590@elgar.sibelius.xs4all.nl \
    --to=kettenis@gnu.org \
    --cc=gdb-patches@sources.redhat.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