From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17944 invoked by alias); 27 Apr 2004 16:37:30 -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 17886 invoked from network); 27 Apr 2004 16:37:27 -0000 Received: from unknown (HELO dublin.act-europe.fr) (212.157.227.154) by sources.redhat.com with SMTP; 27 Apr 2004 16:37:27 -0000 Received: from localhost (province.act-europe.fr [10.10.0.214]) by filtered-dublin.act-europe.fr (Postfix) with ESMTP id 956CB229EA1 for ; Tue, 27 Apr 2004 18:37:26 +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 67693-06 for ; Tue, 27 Apr 2004 18:37:26 +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 6088B229E04 for ; Tue, 27 Apr 2004 18:37:26 +0200 (MET DST) Received: by berne.act-europe.fr (Postfix, from userid 560) id C317A592B; Tue, 27 Apr 2004 12:37:25 -0400 (EDT) Date: Tue, 27 Apr 2004 16:37:00 -0000 From: Jerome Guitton To: gdb-patches@sources.redhat.com Subject: Re: [RFA] x86 - jump instruction after the prologue Message-ID: <20040427163725.GA7319@act-europe.fr> References: <20040419173249.GA22201@act-europe.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040419173249.GA22201@act-europe.fr> User-Agent: Mutt/1.4i X-Virus-Scanned: by amavisd-new at act-europe.fr X-SW-Source: 2004-04/txt/msg00620.txt.bz2 Ping? Still waiting for approval... (I have a testcase for that, coming soon...) Jerome Guitton (guitton@act-europe.fr): > 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 > 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. */