From: Werner Almesberger <werner@almesberger.net>
To: gdb-patches@sourceware.org
Cc: Jon Beniston <jon@beniston.com>
Subject: [PATCH] 32 bit-ism in lm32-tdep.c (and some sloppy macros)
Date: Fri, 11 Nov 2011 23:38:00 -0000 [thread overview]
Message-ID: <20111111233808.GA10815@ws> (raw)
Hello,
since at least gdb 7.1, stack traces (where or bt) of LM32 failed
on 64 bit hosts after just a few frames with
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
The reason for this is that stack frames weren't unwound correctly.
The bug is in the LM32_IMM16 macro, which tries to do sign expansion
by shifting the value to the left edge of a long, expecting it to
be 32 bits. This trick produces incorrect results on 64 bit systems.
I've observed this problem in all gdb versions I tried, namely 7.1
through 7.3.1.
The patch below delegates the work of figuring out such details to
the compiler. I've also taken the liberty of protecting all the
macro arguments, just in case.
- Werner
--- gdb-7.3.1/gdb/lm32-tdep.c.orig 2011-11-11 18:03:54.000000000 -0300
+++ gdb-7.3.1/gdb/lm32-tdep.c 2011-11-11 18:04:24.000000000 -0300
@@ -40,11 +40,11 @@
#include "gdb_string.h"
/* Macros to extract fields from an instruction. */
-#define LM32_OPCODE(insn) ((insn >> 26) & 0x3f)
-#define LM32_REG0(insn) ((insn >> 21) & 0x1f)
-#define LM32_REG1(insn) ((insn >> 16) & 0x1f)
-#define LM32_REG2(insn) ((insn >> 11) & 0x1f)
-#define LM32_IMM16(insn) ((((long)insn & 0xffff) << 16) >> 16)
+#define LM32_OPCODE(insn) (((insn) >> 26) & 0x3f)
+#define LM32_REG0(insn) (((insn) >> 21) & 0x1f)
+#define LM32_REG1(insn) (((insn) >> 16) & 0x1f)
+#define LM32_REG2(insn) (((insn) >> 11) & 0x1f)
+#define LM32_IMM16(insn) ((long) (int16_t) (insn))
struct gdbarch_tdep
{
_______________________________________________
http://lists.milkymist.org/listinfo.cgi/devel-milkymist.org
IRC: #milkymist@Freenode
----- End forwarded message -----
next reply other threads:[~2011-11-11 23:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-11 23:38 Werner Almesberger [this message]
2011-11-14 15:49 ` Tom Tromey
2011-11-14 15:55 ` Jon Beniston
2011-11-14 15:58 ` Tom Tromey
2011-11-14 16:12 ` Pedro Alves
2011-11-14 16:21 ` Tom Tromey
2011-11-14 16:28 ` Pedro Alves
2011-11-14 16:41 ` Tom Tromey
2011-11-23 14:16 ` Mark Kettenis
2011-11-23 19:19 ` Mike Frysinger
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=20111111233808.GA10815@ws \
--to=werner@almesberger.net \
--cc=gdb-patches@sourceware.org \
--cc=jon@beniston.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