This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] 32 bit-ism in lm32-tdep.c (and some sloppy macros)
- From: Tom Tromey <tromey at redhat dot com>
- To: Werner Almesberger <werner at almesberger dot net>
- Cc: gdb-patches at sourceware dot org, Jon Beniston <jon at beniston dot com>
- Date: Mon, 14 Nov 2011 08:48:48 -0700
- Subject: Re: [PATCH] 32 bit-ism in lm32-tdep.c (and some sloppy macros)
- References: <20111111233808.GA10815@ws>
>>>>> "Werner" == Werner Almesberger <werner@almesberger.net> writes:
Werner> The reason for this is that stack frames weren't unwound correctly.
Werner> The bug is in the LM32_IMM16 macro, which tries to do sign expansion
Werner> by shifting the value to the left edge of a long, expecting it to
Werner> be 32 bits. This trick produces incorrect results on 64 bit systems.
Thanks for the patch.
It needs a ChangeLog entry.
Werner> The patch below delegates the work of figuring out such details to
Werner> the compiler. I've also taken the liberty of protecting all the
Werner> macro arguments, just in case.
Werner> -#define LM32_IMM16(insn) ((((long)insn & 0xffff) << 16) >> 16)
[...]
Werner> +#define LM32_IMM16(insn) ((long) (int16_t) (insn))
I was a little surprised to find out we already use int16_t in gdb.
Anyway, it seems that the macro would be more obvious as:
#define LM32_IMM16(insn) ((long) ((insn) & 0xffff))
WDYT?
Tom