From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25946 invoked by alias); 30 Mar 2013 19:13:19 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 25932 invoked by uid 89); 30 Mar 2013 19:13:12 -0000 X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_HOSTKARMA_NO,RCVD_IN_HOSTKARMA_YE,SPF_NEUTRAL,TW_XF autolearn=no version=3.3.1 Received: from haggis.mythic-beasts.com (HELO haggis.mythic-beasts.com) (93.93.131.52) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Sat, 30 Mar 2013 19:13:09 +0000 Received: from [93.93.130.49] (port=38261 helo=sphinx.mythic-beasts.com) by haggis.mythic-beasts.com with esmtp (Exim 4.72) (envelope-from ) id 1UM1D9-0007P3-Is for gdb@sourceware.org; Sat, 30 Mar 2013 19:13:07 +0000 Received: from richard (helo=localhost) by sphinx.mythic-beasts.com with local-esmtp (Exim 4.72) (envelope-from ) id 1UM1D8-0003gQ-J3 for gdb@sourceware.org; Sat, 30 Mar 2013 19:13:07 +0000 Date: Sat, 30 Mar 2013 19:13:00 -0000 From: Richard Smith To: gdb@sourceware.org Subject: Backtraces broken on i386 by unorthodox encoding of push %ebp Message-ID: User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII X-BlackCat-Spam-Score: -18 X-SW-Source: 2013-03/txt/msg00084.txt.bz2 I have an i386 program on Linux where some of the functions start with a slightly unorthodox encoding of the usual function prologue: 08048104 : 8048104: ff f5 push %ebp 8048106: 89 e5 mov %esp,%ebp However, when I have this form of prologue, gdb doesn't recongnise it, and doesn't give a meaningful backtrace. In this case, the push instruction is encoded using the two-byte PUSH r/m32 (FF /6) form, instead of the more common one-byte PUSH r32 (50+rd) form. The two instructions execute identically, and both have been around since the 8086. So far as I'm aware, the ABI doesn't require the use of the shorter encoding of the instruction in the function prologue. And for this particular application, I would prefer to continue using the two-byte form. I think it should be pretty straightforward to make gdb accept both versions of the instruction. I'm not familiar with gdb's source code, but at a guess, modifying the start of i386_analyze_frame_setup in gdb/i386-tdep.c so that it does something like this: /* Check for `pushl %ebp', either encoded using `push r32' (55) or less commonly using `push r/m32' (FF F5). */ if (op == 0x55 || op == 0xff && read_memory_unsigned_integer (pc + 1, 1, byte_order) == 0xf5) { /* Take into account that we've executed the `pushl %ebp' that starts this instruction sequence. */ cache->saved_regs[I386_EBP_REGNUM] = 0; cache->sp_offset += 4; pc += op == 0x55 ? 1 : 2; I expect the amd64 version of the code could do with a similar change. Richard