From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 89241 invoked by alias); 1 Dec 2016 15:32:08 -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 89232 invoked by uid 89); 1 Dec 2016 15:32:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=H*MI:sk:1480601, exercised X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 01 Dec 2016 15:31:57 +0000 Received: from svr-orw-mbx-03.mgc.mentorg.com ([147.34.90.203]) by relay1.mentorg.com with esmtp id 1cCTL2-0004hr-3Y from Luis_Gustavo@mentor.com ; Thu, 01 Dec 2016 07:31:56 -0800 Received: from [172.30.5.15] (147.34.91.1) by svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Thu, 1 Dec 2016 07:31:53 -0800 Subject: Re: [PATCH] AMD64, Prologue: Recognize stack decrementation as prologue operation. References: <1480601804-3128-1-git-send-email-bernhard.heckel@intel.com> To: Bernhard Heckel , CC: From: Luis Machado Reply-To: Luis Machado Message-ID: <2b71dfb7-0ab8-2440-b102-e8cc6dfc8bef@codesourcery.com> Date: Thu, 01 Dec 2016 15:32:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <1480601804-3128-1-git-send-email-bernhard.heckel@intel.com> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: svr-orw-mbx-04.mgc.mentorg.com (147.34.90.204) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) X-IsSubscribed: yes X-SW-Source: 2016-12/txt/msg00040.txt.bz2 On 12/01/2016 08:16 AM, Bernhard Heckel wrote: > Some compiler decrement stack pointer within the prologue > sequence in order to reserve memory for local variables. > Recognize this subtraction to stop at the very end of the > prologue. I suppose this was exercised with GCC as well via the testsuite? > > 2016-10-20 Bernhard Heckel > > gdb/Changelog: > amd64-tdep.c (amd64_analyze_prologue): Recognize stack decrementation > as prologue operation. gdb/ChangeLog above the date line, adjust date and add "*" before the filename. > > --- > gdb/amd64-tdep.c | 30 ++++++++++++++++++++++++++++++ > 1 file changed, 30 insertions(+) > > diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c > index a3a1fde..795d78e 100644 > --- a/gdb/amd64-tdep.c > +++ b/gdb/amd64-tdep.c > @@ -2283,6 +2283,12 @@ amd64_analyze_prologue (struct gdbarch *gdbarch, > /* Ditto for movl %esp, %ebp. */ > static const gdb_byte mov_esp_ebp_1[2] = { 0x89, 0xe5 }; > static const gdb_byte mov_esp_ebp_2[2] = { 0x8b, 0xec }; > + /* Ditto for subtraction on the stack pointer. */ > + static const gdb_byte sub_rsp_imm8[3] = { 0x48, 0x83, 0xec }; > + static const gdb_byte sub_rsp_imm32[3] = { 0x48, 0x81, 0xec }; > + /* Ditto for subtraction on the stack pointer. */ > + static const gdb_byte sub_esp_imm8[2] = { 0x83, 0xec }; > + static const gdb_byte sub_esp_imm32[2] = { 0x81, 0xec }; Should we add a comment making it explicit which instruction patterns we're looking at matching here? I looked up sub esp imm32, for example, and i got no meaningful hits other than some nasm posix entry. > > gdb_byte buf[3]; > gdb_byte op; > @@ -2316,6 +2322,18 @@ amd64_analyze_prologue (struct gdbarch *gdbarch, > { > /* OK, we actually have a frame. */ > cache->frameless_p = 0; > + > + /* Some compiler do subtraction on the stack pointer > + to reserve memory for local variables. > + Two common variants exist to do so. */ What compiler exactly? Would be nice to know, otherwise this is a bit vague. The comment seems to imply a specific compiler does this, or did you mean "some compilers"? > + read_code (pc + 4, buf, 3); > + if (memcmp (buf, sub_rsp_imm8, 3) == 0) > + /* Operand is 1 byte. */ > + return pc + 8; > + else if (memcmp (buf, sub_rsp_imm32, 3) == 0) > + /* Operand is 4 bytes. */ > + return pc + 11; > + > return pc + 4; > } > > @@ -2327,6 +2345,18 @@ amd64_analyze_prologue (struct gdbarch *gdbarch, > { > /* OK, we actually have a frame. */ > cache->frameless_p = 0; > + > + /* Some compiler do subtraction on the stack pointer > + to reserve memory for local variables. > + Two common variants exist to do so. */ > + read_code (pc + 3, buf, 2); > + if (memcmp (buf, sub_esp_imm8, 2) == 0) > + /* Operand is 1 byte. */ > + return pc + 6; > + else if (memcmp (buf, sub_esp_imm32, 2) == 0) > + /* Operand is 4 bytes. */ > + return pc + 9; > + > return pc + 3; > } > } > Otherwise LGTM.