From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18932 invoked by alias); 19 Apr 2004 17:32:54 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 18921 invoked from network); 19 Apr 2004 17:32:52 -0000 Received: from unknown (HELO dublin.act-europe.fr) (212.157.227.154) by sources.redhat.com with SMTP; 19 Apr 2004 17:32:52 -0000 Received: from localhost (province.act-europe.fr [10.10.0.214]) by filtered-dublin.act-europe.fr (Postfix) with ESMTP id C1AFE22BB8A for ; Mon, 19 Apr 2004 19:32:50 +0200 (MET DST) Received: from dublin.act-europe.fr ([10.10.0.154]) by localhost (province.act-europe.fr [10.10.0.214]) (amavisd-new, port 10024) with ESMTP id 34273-05 for ; Mon, 19 Apr 2004 19:32:50 +0200 (CEST) Received: from berne.act-europe.fr (berne.act-europe.fr [10.10.0.165]) by dublin.act-europe.fr (Postfix) with ESMTP id 49A4222BB89 for ; Mon, 19 Apr 2004 19:32:50 +0200 (MET DST) Received: by berne.act-europe.fr (Postfix, from userid 560) id 1A4D9592B; Mon, 19 Apr 2004 13:32:50 -0400 (EDT) Date: Mon, 19 Apr 2004 17:32:00 -0000 From: Jerome Guitton To: gdb-patches@sources.redhat.com Subject: [RFA] x86 - jump instruction after the prologue Message-ID: <20040419173249.GA22201@act-europe.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="EeQfGwPcQSOJBaQU" Content-Disposition: inline User-Agent: Mutt/1.4i X-Virus-Scanned: by amavisd-new at act-europe.fr X-SW-Source: 2004-04/txt/msg00432.txt.bz2 --EeQfGwPcQSOJBaQU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1252 Hello, For what I understand from the skip_prologue algorithm in i386-tdep.c, there are cases when the first instruction of a function is a jump to the prologue code, which is located somewhere else in the function (e.g. the end of the function). The last instruction of the prologue in this case is a branch to the "real" code. To take this case into account, GDB applies two corrections: C1: GDB tests if the first instruction of the function is a jump; if so, GDB jumps to the target of the branch (i.e. it follows the branch). C2: GDB tests if the next instruction after the prologue is a jump; if so, it considers that it is a branch back to the "real" beginning of the program and follows the branch. A problem appears if we are in the "usual" case and if the first instruction of the "real" code is a branch instruction: 0x8049454 <_ada_b>: push %ebp 0x8049455 <_ada_b+1>: mov %esp,%ebp 0x8049457 <_ada_b+3>: jmp 0x8049460 <_ada_b+12> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ In this case, GDB will not apply C1 but will apply C2. That seems wrong to me, I cannot see how the pair (not C1, C2) can be correct. See a possible fix in attachment. Tested on x86-linux, no regression. OK to apply? -- Jerome --EeQfGwPcQSOJBaQU Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=diff Content-length: 921 2004-04-19 Jerome Guitton * i386-tdep.c (i386_skip_prologue): follow the last jump only if the function begins with a branch instruction. Index: i386-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/i386-tdep.c,v retrieving revision 1.187 diff -u -p -r1.187 i386-tdep.c --- i386-tdep.c 18 Apr 2004 18:38:04 -0000 1.187 +++ i386-tdep.c 19 Apr 2004 17:08:36 -0000 @@ -750,7 +750,15 @@ i386_skip_prologue (CORE_ADDR start_pc) } } - return i386_follow_jump (pc); + /* If the first instruction of the function is a branch, then the + setup sequence is at the end of the function and the instruction + at pc is branch back to the start. In this case, follow the + jump. */ + + if (i386_follow_jump (start_pc) != start_pc) + return i386_follow_jump (pc); + else + return pc; } /* This function is 64-bit safe. */ --EeQfGwPcQSOJBaQU--