From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 102060 invoked by alias); 16 Dec 2016 13:59:04 -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 101928 invoked by uid 89); 16 Dec 2016 13:59:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.4 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_SORBS_SPAM,RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=AMD64, 23166, 2316,6, gdbarch X-HELO: mga01.intel.com Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Dec 2016 13:58:53 +0000 Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP; 16 Dec 2016 05:58:51 -0800 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga004.jf.intel.com with ESMTP; 16 Dec 2016 05:58:50 -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 uBGDwnOg000967; Fri, 16 Dec 2016 13:58:49 GMT Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id uBGDwnDE001511; Fri, 16 Dec 2016 14:58:49 +0100 Received: (from heckel@localhost) by ulvlx001.iul.intel.com with œ id uBGDwnSm001508; Fri, 16 Dec 2016 14:58:49 +0100 From: Bernhard Heckel To: qiyaoltc@gmail.com Cc: gdb-patches@sourceware.org, Bernhard Heckel Subject: [PATCH V2 1/2] AMD64, Prologue: Recognize stack decrementation as prologue operation. Date: Fri, 16 Dec 2016 13:59:00 -0000 Message-Id: <1481896716-1233-2-git-send-email-bernhard.heckel@intel.com> In-Reply-To: <1481896716-1233-1-git-send-email-bernhard.heckel@intel.com> References: <1481896716-1233-1-git-send-email-bernhard.heckel@intel.com> X-IsSubscribed: yes X-SW-Source: 2016-12/txt/msg00323.txt.bz2 GCC, ICC and Clang 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-12-16 Bernhard Heckel gdb/Changelog: * amd64-tdep.c (amd64_analyze_prologue): Recognize stack decrementation as prologue operation. --- gdb/amd64-tdep.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c index a3a1fde..cbcddcb 100644 --- a/gdb/amd64-tdep.c +++ b/gdb/amd64-tdep.c @@ -2261,11 +2261,19 @@ amd64_x32_analyze_stack_align (CORE_ADDR pc, CORE_ADDR current_pc, pushq %rbp 0x55 movq %rsp, %rbp 0x48 0x89 0xe5 (or 0x48 0x8b 0xec) + in addition, functions containing local variables + sub imm8, %rsp 0x48 0x83 0xec + or + sub imm32, %rsp 0x48 0x81 0xec or (for the X32 ABI): pushq %rbp 0x55 movl %esp, %ebp 0x89 0xe5 (or 0x8b 0xec) + in addition, functions containing local variables + sub imm8, %esp 0x83 0xec + or + sub imm32, %esp 0x81 0xec Any function that doesn't start with one of these sequences will be assumed to have no prologue and thus no valid frame pointer in @@ -2283,6 +2291,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 +2330,18 @@ amd64_analyze_prologue (struct gdbarch *gdbarch, { /* OK, we actually have a frame. */ cache->frameless_p = 0; + + /* GCC, ICC and Clang 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 +2353,18 @@ amd64_analyze_prologue (struct gdbarch *gdbarch, { /* OK, we actually have a frame. */ cache->frameless_p = 0; + + /* GCC, ICC and Clang 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