From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21219 invoked by alias); 2 Jan 2015 23:57:56 -0000 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 Received: (qmail 21203 invoked by uid 89); 2 Jan 2015 23:57:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.7 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: cvs.linux-mips.org Received: from eddie.linux-mips.org (HELO cvs.linux-mips.org) (148.251.95.138) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Jan 2015 23:57:52 +0000 Received: from localhost.localdomain ([127.0.0.1]:49740 "EHLO localhost.localdomain" rhost-flags-OK-OK-OK-OK) by eddie.linux-mips.org with ESMTP id S27007171AbbABX5tkLobR (ORCPT ); Sat, 3 Jan 2015 00:57:49 +0100 Date: Fri, 02 Jan 2015 23:57:00 -0000 From: "Maciej W. Rozycki" To: gdb-patches@sourceware.org Subject: [committed] MIPS: Make the extracted stack offset signed in the prologue scanner Message-ID: User-Agent: Alpine 2.11 (LFD 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-IsSubscribed: yes X-SW-Source: 2015-01/txt/msg00018.txt.bz2 Hi, I have committed this change to clean up the handling of the stack offset in the standard MIPS prologue scanner. It is now treated as signed similarly to how the microMIPS version prologue scanner handles it. This simplifies handling and makes register offsets correct in all cases, especially where $fp is the virtual frame pointer. 2015-01-02 Maciej W. Rozycki gdb/ * mips-tdep.c (mips32_scan_prologue): Make the extracted stack offset signed. Maciej gdb-mips-scan-prologue-offset.diff Index: gdb-fsf-trunk-quilt/gdb/mips-tdep.c =================================================================== --- gdb-fsf-trunk-quilt.orig/gdb/mips-tdep.c 2014-10-13 13:40:57.657712716 +0100 +++ gdb-fsf-trunk-quilt/gdb/mips-tdep.c 2014-10-13 13:42:23.167881635 +0100 @@ -3394,7 +3394,8 @@ mips32_scan_prologue (struct gdbarch *gd frame_offset = 0; for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSN32_SIZE) { - unsigned long inst, high_word, low_word; + unsigned long inst, high_word; + long offset; int reg; this_non_prologue_insn = 0; @@ -3406,15 +3407,15 @@ mips32_scan_prologue (struct gdbarch *gd /* Save some code by pre-extracting some useful fields. */ high_word = (inst >> 16) & 0xffff; - low_word = inst & 0xffff; + offset = ((inst & 0xffff) ^ 0x8000) - 0x8000; reg = high_word & 0x1f; if (high_word == 0x27bd /* addiu $sp,$sp,-i */ || high_word == 0x23bd /* addi $sp,$sp,-i */ || high_word == 0x67bd) /* daddiu $sp,$sp,-i */ { - if (low_word & 0x8000) /* Negative stack adjustment? */ - frame_offset += 0x10000 - low_word; + if (offset < 0) /* Negative stack adjustment? */ + frame_offset -= offset; else /* Exit loop if a positive stack adjustment is found, which usually means that the stack cleanup code in the function @@ -3425,19 +3426,19 @@ mips32_scan_prologue (struct gdbarch *gd else if (((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */ && !regsize_is_64_bits) { - set_reg_offset (gdbarch, this_cache, reg, sp + low_word); + set_reg_offset (gdbarch, this_cache, reg, sp + offset); } else if (((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */ && regsize_is_64_bits) { /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra. */ - set_reg_offset (gdbarch, this_cache, reg, sp + low_word); + set_reg_offset (gdbarch, this_cache, reg, sp + offset); } else if (high_word == 0x27be) /* addiu $30,$sp,size */ { /* Old gcc frame, r30 is virtual frame pointer. */ - if ((long) low_word != frame_offset) - frame_addr = sp + low_word; + if (offset != frame_offset) + frame_addr = sp + offset; else if (this_frame && frame_reg == MIPS_SP_REGNUM) { unsigned alloca_adjust; @@ -3447,7 +3448,7 @@ mips32_scan_prologue (struct gdbarch *gd (this_frame, gdbarch_num_regs (gdbarch) + 30); frame_offset = 0; - alloca_adjust = (unsigned) (frame_addr - (sp + low_word)); + alloca_adjust = (unsigned) (frame_addr - (sp + offset)); if (alloca_adjust > 0) { /* FP > SP + frame_size. This may be because of @@ -3496,7 +3497,7 @@ mips32_scan_prologue (struct gdbarch *gd else if ((high_word & 0xFFE0) == 0xafc0 /* sw reg,offset($30) */ && !regsize_is_64_bits) { - set_reg_offset (gdbarch, this_cache, reg, frame_addr + low_word); + set_reg_offset (gdbarch, this_cache, reg, frame_addr + offset); } else if ((high_word & 0xFFE0) == 0xE7A0 /* swc1 freg,n($sp) */ || (high_word & 0xF3E0) == 0xA3C0 /* sx reg,n($s8) */