This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] 32 bit-ism in lm32-tdep.c (and some sloppy macros)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]