This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [RFA] x86 - jump instruction after the prologue
- From: Jerome Guitton <guitton at act-europe dot fr>
- To: gdb-patches at sources dot redhat dot com
- Date: Tue, 27 Apr 2004 18:37:25 +0200
- Subject: Re: [RFA] x86 - jump instruction after the prologue
- References: <20040419173249.GA22201@act-europe.fr>
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 <guitton@gnat.com>
>
> * 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. */