From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12857 invoked by alias); 24 Mar 2011 13:45:09 -0000 Received: (qmail 12842 invoked by uid 22791); 24 Mar 2011 13:45:08 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,TW_EG,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 24 Mar 2011 13:45:04 +0000 Received: (qmail 7525 invoked from network); 24 Mar 2011 13:45:02 -0000 Received: from unknown (HELO ?192.168.0.102?) (yao@127.0.0.2) by mail.codesourcery.com with ESMTPA; 24 Mar 2011 13:45:02 -0000 Message-ID: <4D8B4AD6.6040304@codesourcery.com> Date: Thu, 24 Mar 2011 13:56:00 -0000 From: Yao Qi User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) Gecko/20110223 Lightning/1.0b2 Thunderbird/3.1.8 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: [try 2nd 1/8] Fix cleanup_branch to take Thumb into account References: <4D15F9B8.5070705@codesourcery.com> <4D8B4947.1000000@codesourcery.com> In-Reply-To: <4D8B4947.1000000@codesourcery.com> Content-Type: multipart/mixed; boundary="------------050901010904030408080608" X-IsSubscribed: yes 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-03/txt/msg01065.txt.bz2 This is a multi-part message in MIME format. --------------050901010904030408080608 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-length: 208 When writing LR register in cleanup_branch, Thumb mode is not considered, so `pc - 4' is not value of LR. Since insn_size and insn_addr has been in `dsc', it can be easier to calculate LR. -- Yao (齐尧) --------------050901010904030408080608 Content-Type: text/x-patch; name="0001-generic-fix-to-cleanup_branch.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-generic-fix-to-cleanup_branch.patch" Content-length: 1150 2011-03-24 Yao Qi * arm-tdep.c (cleanup_branch): Set a correct return address in LR for ARM and Thumb. --- gdb/arm-tdep.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-) diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 6e5f2ab..2ebafad 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -5485,8 +5485,16 @@ cleanup_branch (struct gdbarch *gdbarch, struct regcache *regs, if (dsc->u.branch.link) { - ULONGEST pc = displaced_read_reg (regs, dsc, ARM_PC_REGNUM); - displaced_write_reg (regs, dsc, ARM_LR_REGNUM, pc - 4, CANNOT_WRITE_PC); + /* The value of LR should be the next insn of current one. In order + not to confuse logic hanlding later insn `bx lr', if current insn mode + is Thumb, the bit 0 of LR value should be set to 1. */ + ULONGEST next_insn_addr = dsc->insn_addr + dsc->insn_size; + + if (dsc->is_thumb) + next_insn_addr |= 0x1; + + displaced_write_reg (regs, dsc, ARM_LR_REGNUM, next_insn_addr, + CANNOT_WRITE_PC); } displaced_write_reg (regs, dsc, ARM_PC_REGNUM, dsc->u.branch.dest, write_pc); -- 1.7.0.4 --------------050901010904030408080608--