From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 94496 invoked by alias); 1 Dec 2016 14:17:13 -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 94335 invoked by uid 89); 1 Dec 2016 14:17:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mga04.intel.com Received: from mga04.intel.com (HELO mga04.intel.com) (192.55.52.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 01 Dec 2016 14:17:02 +0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP; 01 Dec 2016 06:17:01 -0800 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga002.jf.intel.com with ESMTP; 01 Dec 2016 06:17:00 -0800 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id uB1EGxcw011985; Thu, 1 Dec 2016 14:16:59 GMT Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id uB1EGxUd003401; Thu, 1 Dec 2016 15:16:59 +0100 Received: (from heckel@localhost) by ulvlx001.iul.intel.com with œ id uB1EGwpH003398; Thu, 1 Dec 2016 15:16:59 +0100 From: Bernhard Heckel To: qiyaoltc@gmail.com Cc: gdb-patches@sourceware.org, Bernhard Heckel Subject: [PATCH] AMD64, Prologue: Recognize stack decrementation as prologue operation. Date: Thu, 01 Dec 2016 14:17:00 -0000 Message-Id: <1480601804-3128-1-git-send-email-bernhard.heckel@intel.com> X-IsSubscribed: yes X-SW-Source: 2016-12/txt/msg00035.txt.bz2 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. 2016-10-20 Bernhard Heckel gdb/Changelog: amd64-tdep.c (amd64_analyze_prologue): Recognize stack decrementation as prologue operation. --- 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 }; 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. */ + 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; } } -- 2.7.1.339.g0233b80