From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8155 invoked by alias); 24 Dec 2010 08:42:40 -0000 Received: (qmail 8147 invoked by uid 22791); 24 Dec 2010 08:42:40 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,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:42:36 +0000 Received: (qmail 31805 invoked from network); 24 Dec 2010 08:42:31 -0000 Received: from unknown (HELO ?192.168.1.11?) (yao@127.0.0.2) by mail.codesourcery.com with ESMTPA; 24 Dec 2010 08:42:31 -0000 Message-ID: <4D145CE6.4020005@codesourcery.com> Date: Fri, 24 Dec 2010 09:36: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, 2/2] skip insns generated by -fstack-protector References: <4D145811.4060805@codesourcery.com> In-Reply-To: <4D145811.4060805@codesourcery.com> Content-Type: multipart/mixed; boundary="------------020202020907020306040101" 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/msg00455.txt.bz2 This is a multi-part message in MIME format. --------------020202020907020306040101 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 672 On 12/24/2010 04:21 PM, Yao Qi wrote: > Patch 2 is about handling i386 stack protector insns during prologue > analysis. Without patch 1, patch 2 doesn't work in some cases. Here is a prologue generated by GCC, instructions on [1] are for stack protector. push %ebp mov %esp,%ebp and $0xfffffff0,%esp add $0xffffff80,%esp mov %gs:0x14,%eax // <---- [1] mov %eax,0x7c(%esp) // <---- [1] xor %eax,%eax // <---- [1] Compared with instructions for arm stack protector, i386's counterpart is relatively simpler. This patch is to handle them in prologue parsing. Comments are welcome. -- Yao Qi --------------020202020907020306040101 Content-Type: text/x-patch; name="i386_skip_stack_protector_1224.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="i386_skip_stack_protector_1224.patch" Content-length: 1884 gdb/ * i386-tdep.c (i386_skip_stack_protector) New. (i386_analyze_prologue): Chain i386_skip_stack_protector. diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c index 8c6f896..ee40603 100644 --- a/gdb/i386-tdep.c +++ b/gdb/i386-tdep.c @@ -1455,6 +1455,35 @@ i386_analyze_register_saves (CORE_ADDR pc, CORE_ADDR current_pc, return pc; } +/* Check whether PC points at code that for stack protector, which + is usually a sequence of three instructions, + + mov %gs:0x14,%eax + mov %eax,0x7c(%esp) + xor %eax,%eax + + If so, returns the address of the first instruction after the + stack protector code or CURRENT_PC, whichever is smaller. + Otherwise, return PC. */ + +static CORE_ADDR +i386_skip_stack_protector (CORE_ADDR pc, CORE_ADDR current_pc) +{ + gdb_byte buf[12]; + if (target_read_memory (pc, buf, sizeof buf)) + return pc; + + /* Instruction `mov %gs:0x14,%eax' can be regarded as `fingerprint' of a + sequence of code for stack protector, since it is unique and can't be + found elsewhere. */ + if (/* mov %gs:0x14,%eax. */ + buf[0] != 0x65 && buf[1] != 0xa1 && buf[2] != 14 + && buf[10] != 0x31 /* xor %eax,%eax. */) + return pc; + + return min (pc + 12, current_pc); +} + /* Do a full analysis of the prologue at PC and update CACHE accordingly. Bail out early if CURRENT_PC is reached. Return the address where the analysis stopped. @@ -1493,7 +1522,9 @@ i386_analyze_prologue (struct gdbarch *gdbarch, pc = i386_skip_probe (pc); pc = i386_analyze_stack_align (pc, current_pc, cache); pc = i386_analyze_frame_setup (gdbarch, pc, current_pc, cache); - return i386_analyze_register_saves (pc, current_pc, cache); + pc = i386_analyze_register_saves (pc, current_pc, cache); + pc = i386_skip_stack_protector (pc, current_pc); + return pc; } /* Return PC of first real instruction. */ --------------020202020907020306040101--