From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26353 invoked by alias); 24 Dec 2010 08:34:31 -0000 Received: (qmail 26233 invoked by uid 22791); 24 Dec 2010 08:34:30 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,TW_XF,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; Fri, 24 Dec 2010 08:34:25 +0000 Received: (qmail 30303 invoked from network); 24 Dec 2010 08:34:23 -0000 Received: from unknown (HELO ?192.168.1.11?) (yao@127.0.0.2) by mail.codesourcery.com with ESMTPA; 24 Dec 2010 08:34:23 -0000 Message-ID: <4D145B02.8030507@codesourcery.com> Date: Fri, 24 Dec 2010 09:15:00 -0000 From: Yao Qi User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: Re: [patch i386, 0/2] skip insns generated by -fstack-protector References: <4D145811.4060805@codesourcery.com> In-Reply-To: <4D145811.4060805@codesourcery.com> Content-Type: multipart/mixed; boundary="------------030900060506080109080107" 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: 2010-12/txt/msg00454.txt.bz2 This is a multi-part message in MIME format. --------------030900060506080109080107 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 844 On 12/24/2010 04:21 PM, Yao Qi wrote: > Patch 1 is about fixing GDB analyze i386 prologue for insns and/add, > which are part of i386 prologue, but GDB can't handle. Here is a prologue generated by GCC, instructions on [1] can't be handled by GDB so far. This patch is to handle them in prologue parsing. push %ebp mov %esp,%ebp and $0xfffffff0,%esp // <---- [1] add $0xffffff80,%esp // <---- [1] mov %gs:0x14,%eax mov %eax,0x7c(%esp) xor %eax,%eax lea 0x54(%esp),%eax Note that `and' instruction, for alignment, is not a must in prologue. My knowledge on i386 prologue is very limited and GCC i386 prologue generate is too complicated to understand for me, so I am not pretty sure on this patch. I send it out, and your comments are appreciated. -- Yao Qi --------------030900060506080109080107 Content-Type: text/x-patch; name="i386_prologue_parse_1224.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="i386_prologue_parse_1224.patch" Content-length: 3011 gdb/ * i386-tdep.c (i386_analyze_frame_setup): Handle and/add sequence in prologue. diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c index 4016a70..8c6f896 100644 --- a/gdb/i386-tdep.c +++ b/gdb/i386-tdep.c @@ -1263,6 +1263,7 @@ i386_analyze_frame_setup (struct gdbarch *gdbarch, struct i386_insn *insn; gdb_byte op; int skip = 0; + int found_and_insn = 0; if (limit <= pc) return limit; @@ -1332,24 +1333,71 @@ i386_analyze_frame_setup (struct gdbarch *gdbarch, if (limit <= pc) return limit; - /* Check for stack adjustment + /* GCC may generate `and' instruction in front of stack adjustment for + stack alignment. Check for stack alignment, and skip it if any, + + and $0xfffffff0,%esp + + The change of ESP caused by this instruction is computed a little bit + different here, because we can't get value of offset from + instruction itself. We simulate the execution of this in struction + to calcuate the delta change of ESP. */ + target_read_memory (pc, &op, 1); + /* `and' with signed 8-bit immediate. */ + if (op == 0x83) + { + gdb_byte op1 = read_memory_unsigned_integer (pc + 1, 1, byte_order); + + if (op1 == 0xe4) + { + gdb_byte oprand + = read_memory_unsigned_integer (pc + 2, 1, byte_order); + CORE_ADDR esp = cache->saved_regs[I386_ESP_REGNUM]; + + found_and_insn = 1; + /* Compute the delta change of esp . */ + cache->locals = (esp & 0xff) - (esp & 0xff & oprand); + } + } + + /* Check for stack adjustment, subl $XXX, %esp + or + + add $0xffffff80, %esp + NOTE: You can't subtract a 16-bit immediate from a 32-bit reg, so we don't have to worry about a data16 prefix. */ - target_read_memory (pc, &op, 1); + + target_read_memory (pc + (found_and_insn ? 3 : 0), &op, 1); if (op == 0x83) { + gdb_byte op1 + = read_memory_unsigned_integer (pc + (found_and_insn ? 4 : 1), + 1, byte_order); /* `subl' with 8-bit immediate. */ - if (read_memory_unsigned_integer (pc + 1, 1, byte_order) != 0xec) - /* Some instruction starting with 0x83 other than `subl'. */ - return pc; - - /* `subl' with signed 8-bit immediate (though it wouldn't - make sense to be negative). */ - cache->locals = read_memory_integer (pc + 2, 1, byte_order); - return pc + 3; + if (op1 == 0xec) + { + /* `subl' with signed 8-bit immediate (though it wouldn't + make sense to be negative). */ + cache->locals + = read_memory_integer (pc + (found_and_insn ? 5 : 2), + 1, byte_order); + return pc + 3; + } + /* `add' with a 8-bit immediate. */ + else if (op1 == 0xc4) + { + cache->locals + += -1 * read_memory_integer (pc + (found_and_insn ? 5 : 2), + 1, byte_order); + return pc + (found_and_insn ? 6 : 3); + } + /* Some instruction starting with 0x83 other than `subl' or + `add'. */ + return pc; } else if (op == 0x81) { --------------030900060506080109080107--