From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27149 invoked by alias); 11 Nov 2011 23:38:48 -0000 Received: (qmail 27139 invoked by uid 22791); 11 Nov 2011 23:38:47 -0000 X-SWARE-Spam-Status: No, hits=-3.1 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from host.almesberger.net (HELO host.almesberger.net) (204.10.140.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 11 Nov 2011 23:38:20 +0000 Received: from ws (94-163-231-201.fibertel.com.ar [201.231.163.94]) by host.almesberger.net (8.13.8/8.9.3) with SMTP id pABNcEhO021097; Fri, 11 Nov 2011 15:38:15 -0800 Received: by ws (sSMTP sendmail emulation); Fri, 11 Nov 2011 20:38:08 -0300 Date: Fri, 11 Nov 2011 23:38:00 -0000 From: Werner Almesberger To: gdb-patches@sourceware.org Cc: Jon Beniston Subject: [PATCH] 32 bit-ism in lm32-tdep.c (and some sloppy macros) Message-ID: <20111111233808.GA10815@ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-11/txt/msg00334.txt.bz2 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 -----