Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] x86 - jump instruction after the prologue
@ 2004-04-19 17:32 Jerome Guitton
  2004-04-27 16:37 ` Jerome Guitton
  0 siblings, 1 reply; 10+ messages in thread
From: Jerome Guitton @ 2004-04-19 17:32 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1252 bytes --]

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

[-- Attachment #2: diff --]
[-- Type: text/plain, Size: 921 bytes --]

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.  */

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFA] x86 - jump instruction after the prologue
  2004-04-19 17:32 [RFA] x86 - jump instruction after the prologue Jerome Guitton
@ 2004-04-27 16:37 ` Jerome Guitton
  2004-04-29 16:24   ` Mark Kettenis
  0 siblings, 1 reply; 10+ messages in thread
From: Jerome Guitton @ 2004-04-27 16:37 UTC (permalink / raw)
  To: gdb-patches

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.  */


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFA] x86 - jump instruction after the prologue
  2004-04-27 16:37 ` Jerome Guitton
@ 2004-04-29 16:24   ` Mark Kettenis
  2004-04-29 16:29     ` Jerome Guitton
  2004-05-10 20:48     ` Daniel Jacobowitz
  0 siblings, 2 replies; 10+ messages in thread
From: Mark Kettenis @ 2004-04-29 16:24 UTC (permalink / raw)
  To: guitton; +Cc: gdb-patches

   Date: Tue, 27 Apr 2004 18:37:25 +0200
   From: Jerome Guitton <guitton@act-europe.fr>

   Ping? Still waiting for approval...

Sorry about that.  I've reviewed your patch.  I've tweaked the comment
a bit and checked in the attached.

Thanks,

Mark


Index: ChangeLog
from  Jerome Guitton  <guitton@gnat.com>
	Mark Kettenis  <kettenis@gnu.org>

	* 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.188
diff -u -p -r1.188 i386-tdep.c
--- i386-tdep.c 29 Apr 2004 16:13:21 -0000 1.188
+++ i386-tdep.c 29 Apr 2004 16:20:47 -0000
@@ -750,7 +750,13 @@ i386_skip_prologue (CORE_ADDR start_pc)
 	}
     }
 
-  return i386_follow_jump (pc);
+  /* If the function starts with a branch (to startup code at the end)
+     the last instruction should bring us back to the first
+     instruction of the real code.  */
+  if (i386_follow_jump (start_pc) != start_pc)
+    pc = i386_follow_jump (pc);
+
+  return pc;
 }
 
 /* This function is 64-bit safe.  */


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFA] x86 - jump instruction after the prologue
  2004-04-29 16:24   ` Mark Kettenis
@ 2004-04-29 16:29     ` Jerome Guitton
  2004-05-10 20:48     ` Daniel Jacobowitz
  1 sibling, 0 replies; 10+ messages in thread
From: Jerome Guitton @ 2004-04-29 16:29 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: gdb-patches

Mark Kettenis (kettenis@chello.nl):

> Sorry about that.  I've reviewed your patch.  I've tweaked the comment
> a bit and checked in the attached.

Great! Thanks!

-- 
Jerome


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFA] x86 - jump instruction after the prologue
  2004-04-29 16:24   ` Mark Kettenis
  2004-04-29 16:29     ` Jerome Guitton
@ 2004-05-10 20:48     ` Daniel Jacobowitz
  2004-05-12 10:31       ` Jerome Guitton
  1 sibling, 1 reply; 10+ messages in thread
From: Daniel Jacobowitz @ 2004-05-10 20:48 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: guitton, gdb-patches

On Thu, Apr 29, 2004 at 06:24:07PM +0200, Mark Kettenis wrote:
>    Date: Tue, 27 Apr 2004 18:37:25 +0200
>    From: Jerome Guitton <guitton@act-europe.fr>
> 
>    Ping? Still waiting for approval...
> 
> Sorry about that.  I've reviewed your patch.  I've tweaked the comment
> a bit and checked in the attached.

The testcase, unfortunately, fails on i386-linux using GCC 3.3 and
dwarf2 (it succeeds with stabs).

The failure occurs because we set the breakpoint in main() instead of
in jump_at_beginning.  Here's the relevant line info, in minsym_found:

(top-gdb) p/x msymbol.ginfo.value.address
$10 = 0x80483a8
(top-gdb) p/x values.sals[0]
$11 = {symtab = 0x82f4e78, section = 0x0, line = 0xc, pc = 0x804838c, end = 0x80483b2}

We use the start of the line, which is before the beginning of the
function we want to skip.  If funfirstline, should we ignore lines
which start before the beginning of the function?

Also, should we write i386-prologue.c in assembly to avoid this
problem?  That's what Fred did for SH to avoid a similar difficulty.

> 
> Thanks,
> 
> Mark
> 
> 
> Index: ChangeLog
> from  Jerome Guitton  <guitton@gnat.com>
> 	Mark Kettenis  <kettenis@gnu.org>
> 
> 	* 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.188
> diff -u -p -r1.188 i386-tdep.c
> --- i386-tdep.c 29 Apr 2004 16:13:21 -0000 1.188
> +++ i386-tdep.c 29 Apr 2004 16:20:47 -0000
> @@ -750,7 +750,13 @@ i386_skip_prologue (CORE_ADDR start_pc)
>  	}
>      }
>  
> -  return i386_follow_jump (pc);
> +  /* If the function starts with a branch (to startup code at the end)
> +     the last instruction should bring us back to the first
> +     instruction of the real code.  */
> +  if (i386_follow_jump (start_pc) != start_pc)
> +    pc = i386_follow_jump (pc);
> +
> +  return pc;
>  }
>  
>  /* This function is 64-bit safe.  */
> 

-- 
Daniel Jacobowitz


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFA] x86 - jump instruction after the prologue
  2004-05-10 20:48     ` Daniel Jacobowitz
@ 2004-05-12 10:31       ` Jerome Guitton
  2004-08-08 21:36         ` Daniel Jacobowitz
  0 siblings, 1 reply; 10+ messages in thread
From: Jerome Guitton @ 2004-05-12 10:31 UTC (permalink / raw)
  To: Mark Kettenis, gdb-patches

Daniel Jacobowitz (drow@false.org):

> Also, should we write i386-prologue.c in assembly to avoid this
> problem?  That's what Fred did for SH to avoid a similar difficulty.

Can't we compile this file without debug info?

-- 
Jerome


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFA] x86 - jump instruction after the prologue
  2004-05-12 10:31       ` Jerome Guitton
@ 2004-08-08 21:36         ` Daniel Jacobowitz
  2004-08-08 21:46           ` Michael Chastain
  2004-08-08 22:07           ` Mark Kettenis
  0 siblings, 2 replies; 10+ messages in thread
From: Daniel Jacobowitz @ 2004-08-08 21:36 UTC (permalink / raw)
  To: Jerome Guitton; +Cc: Mark Kettenis, gdb-patches, Michael Chastain

On Wed, May 12, 2004 at 01:31:01PM +0200, Jerome Guitton wrote:
> Daniel Jacobowitz (drow@false.org):
> 
> > Also, should we write i386-prologue.c in assembly to avoid this
> > problem?  That's what Fred did for SH to avoid a similar difficulty.
> 
> Can't we compile this file without debug info?

Yes indeed, and that fixes it.

Background analysis of the problem: GCC uses the .loc directive to emit
line number information when using dwarf2 and a recent GNU assembler. 
There is no way for GCC to force the emission of a DW_LNE_end_sequence
marker, so the last .loc directive is assumed to continue until the end
of the .text section, which includes all of the assembly functions in
i386-prologue.c which are written out using asm().

I've made a note that gas should support a way to emit the EOS marker,
and GCC should use it.  Not hard to implement but I haven't got the
time right now.

In the mean time, this is a test of a prologue analyzer.  Compiling it
without debug information seems reasonable to me.  Tested on
i686-pc-linux-gnu, OK?

-- 
Daniel Jacobowitz

2004-08-08  Daniel Jacobowitz  <dan@debian.org>

	* gdb.arch/i386-prologue.exp: Compile without debug information.

Index: testsuite/gdb.arch/i386-prologue.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.arch/i386-prologue.exp,v
retrieving revision 1.8
diff -u -p -r1.8 i386-prologue.exp
--- testsuite/gdb.arch/i386-prologue.exp	1 Aug 2004 14:28:51 -0000	1.8
+++ testsuite/gdb.arch/i386-prologue.exp	8 Aug 2004 21:31:57 -0000
@@ -44,7 +44,9 @@ if [istarget "i?86-*-cygwin*"] then {
   set additional_flags "additional_flags=-DSYMBOL_PREFIX=\"_\""
 }   
 
-if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug $additional_flags]] != "" } {
+# Don't use "debug", so that we don't have line information for the assembly
+# fragments.
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list $additional_flags]] != "" } {
     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
 }
 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFA] x86 - jump instruction after the prologue
  2004-08-08 21:36         ` Daniel Jacobowitz
@ 2004-08-08 21:46           ` Michael Chastain
  2004-08-08 22:07           ` Mark Kettenis
  1 sibling, 0 replies; 10+ messages in thread
From: Michael Chastain @ 2004-08-08 21:46 UTC (permalink / raw)
  To: guitton, drow; +Cc: kettenis, gdb-patches

Daniel Jacobowitz <drow@false.org> wrote:
> In the mean time, this is a test of a prologue analyzer.  Compiling it
> without debug information seems reasonable to me.  Tested on
> i686-pc-linux-gnu, OK?

Give it 24 hours to see if Mark has anything to say about it.
If it's okay with Mark then I approve it.

Michael C

===

2004-08-08  Daniel Jacobowitz  <dan@debian.org>

	* gdb.arch/i386-prologue.exp: Compile without debug information.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFA] x86 - jump instruction after the prologue
  2004-08-08 21:36         ` Daniel Jacobowitz
  2004-08-08 21:46           ` Michael Chastain
@ 2004-08-08 22:07           ` Mark Kettenis
  2004-08-08 22:15             ` Daniel Jacobowitz
  1 sibling, 1 reply; 10+ messages in thread
From: Mark Kettenis @ 2004-08-08 22:07 UTC (permalink / raw)
  To: drow; +Cc: guitton, gdb-patches, mec.gnu

   Date: Sun, 8 Aug 2004 17:36:15 -0400
   From: Daniel Jacobowitz <drow@false.org>

   On Wed, May 12, 2004 at 01:31:01PM +0200, Jerome Guitton wrote:
   > Daniel Jacobowitz (drow@false.org):
   > 
   > > Also, should we write i386-prologue.c in assembly to avoid this
   > > problem?  That's what Fred did for SH to avoid a similar difficulty.
   > 
   > Can't we compile this file without debug info?

   Yes indeed, and that fixes it.

   [snip]

   In the mean time, this is a test of a prologue analyzer.  Compiling it
   without debug information seems reasonable to me.  Tested on
   i686-pc-linux-gnu, OK?

Tested on i386-unknown-freebsd4.7 (which uses stabs).  Works fine, so
yes OK.  Thanks for looking into this.

Mark


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFA] x86 - jump instruction after the prologue
  2004-08-08 22:07           ` Mark Kettenis
@ 2004-08-08 22:15             ` Daniel Jacobowitz
  0 siblings, 0 replies; 10+ messages in thread
From: Daniel Jacobowitz @ 2004-08-08 22:15 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: guitton, gdb-patches, mec.gnu

On Mon, Aug 09, 2004 at 12:06:22AM +0200, Mark Kettenis wrote:
>    Date: Sun, 8 Aug 2004 17:36:15 -0400
>    From: Daniel Jacobowitz <drow@false.org>
> 
>    On Wed, May 12, 2004 at 01:31:01PM +0200, Jerome Guitton wrote:
>    > Daniel Jacobowitz (drow@false.org):
>    > 
>    > > Also, should we write i386-prologue.c in assembly to avoid this
>    > > problem?  That's what Fred did for SH to avoid a similar difficulty.
>    > 
>    > Can't we compile this file without debug info?
> 
>    Yes indeed, and that fixes it.
> 
>    [snip]
> 
>    In the mean time, this is a test of a prologue analyzer.  Compiling it
>    without debug information seems reasonable to me.  Tested on
>    i686-pc-linux-gnu, OK?
> 
> Tested on i386-unknown-freebsd4.7 (which uses stabs).  Works fine, so
> yes OK.  Thanks for looking into this.

Thanks to both of you; checked in.

-- 
Daniel Jacobowitz


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2004-08-08 22:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-19 17:32 [RFA] x86 - jump instruction after the prologue Jerome Guitton
2004-04-27 16:37 ` Jerome Guitton
2004-04-29 16:24   ` Mark Kettenis
2004-04-29 16:29     ` Jerome Guitton
2004-05-10 20:48     ` Daniel Jacobowitz
2004-05-12 10:31       ` Jerome Guitton
2004-08-08 21:36         ` Daniel Jacobowitz
2004-08-08 21:46           ` Michael Chastain
2004-08-08 22:07           ` Mark Kettenis
2004-08-08 22:15             ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox