Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Re: [PATCH] Partial fix for PR backtrace/1718
@ 2004-08-01 13:54 Mark Kettenis
  0 siblings, 0 replies; 9+ messages in thread
From: Mark Kettenis @ 2004-08-01 13:54 UTC (permalink / raw)
  To: mec.gnu; +Cc: eliz, gdb-patches

[Sorry Michael and Eli, I managed to remove the Subject: line and
 therefore the list didn't accept this message]

   Date: Sun, 01 Aug 2004 01:35:39 -0400
   From: Michael Chastain <mec.gnu@mindspring.com>

   "Eli Zaretskii" <eliz@gnu.org> wrote:
   > Perhaps, then, you could post a list of all the opcodes and subsequent
   > bytes that we need to cover in i386_analyze_frame_setup?

   The compiler could schedule just about anything into the prologue!

There are some restrictions though, given that GCC can only play with
a limited set of registers.

   Let's get empirical.  I ran cc1plus and gdb through "objdump -d" and
   some perl fu.

Thanks!  This really is the info I need.  Could you post (or mail me)
the perl fu?

   We have to have "mov 0xADDRESS, %reg".  After that, recognizing
   "cmpl $IMMEDIATE, 0xADDRESS" would help.  That instruction gets scheduled
   even before "push %ebp".  Those two additions would cover 99.9% of cc1plus
   and gdb.

On System V ABI conforming systems, yes.  On systems that use the
-freg-struct-return by default (FreeBSD, OpenBSD, Cygwin and a few
others) I guess there are a bit more possibilities.  I'll try to
address -freg-struct-return too.

Anyway, I've got some ideas to make the prologue analyzer easily
extendable.

   [snip]

   The 10 truly freaky prologues are:

     .plt : pushl 0x86039e8 | jmp *0x86039ec | add %al, (%eax) | add %al, (%eax) | jmp *0x86039f0 | push $0x0 | jmp 80494cc <_init+0x18>

That's the PLT.  GDB should already handle that one, and otherwise
it'd deserve (and need) a special frame unwinder anyway like I did for
SPARC.

     _start : xor %ebp, %ebp | pop %esi | mov %esp, %ecx | and $0xfffffff0, %esp | push %eax | push %esp | push %edx

This one is rather special since it's the entry point.

Thanks!

Mark


^ permalink raw reply	[flat|nested] 9+ messages in thread
* [PATCH] Partial fix for PR backtrace/1718
@ 2004-07-24 12:59 Mark Kettenis
  2004-07-24 17:58 ` Eli Zaretskii
  2004-07-30 18:35 ` Eli Zaretskii
  0 siblings, 2 replies; 9+ messages in thread
From: Mark Kettenis @ 2004-07-24 12:59 UTC (permalink / raw)
  To: gdb-patches

This fixes the backtrace problem with Emacs that Eli reported.  It's a
partial fix since the prologue analyzer still doesn't notice that %ebx
gets saved on the stack, but that's not terribly important.  This
patch also doesn't handle all the other instructions that might end up
in the prologue.

Committed,

Mark

Index: ChangeLog
from  Mark Kettenis  <kettenis@gnu.org>

	Partial fix for PR backtrace/1718.
	* i386-tdep.c (i386_analyze_frame_setup): Handle more instructions
	that GCC migrates into the prolugue.  Don't handle any
	instructions that clobber %ebx.

Index: i386-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-tdep.c,v
retrieving revision 1.197
diff -u -p -r1.197 i386-tdep.c
--- i386-tdep.c 18 Jun 2004 16:06:24 -0000 1.197
+++ i386-tdep.c 24 Jul 2004 12:53:37 -0000
@@ -503,20 +503,28 @@ i386_analyze_frame_setup (CORE_ADDR pc, 
 
       op = read_memory_unsigned_integer (pc + 1, 1);
 
-      /* Check for some special instructions that might be migrated
-	 by GCC into the prologue.  We check for
+      /* Check for some special instructions that might be migrated by
+	 GCC into the prologue.  At this point in the prologue, code
+	 should only touch the scratch registers %eax, %ecx and %edx,
+	 so we check for
+
+	    movl $XXX, %eax
+	    movl $XXX, %ecx
+	    movl $XXX, %edx
 
-	    xorl %ebx, %ebx
+	 These instructions have opcodes 0xb8, 0xb9 and 0xba.
+
+	 We also check for
+
+	    xorl %eax, %eax
 	    xorl %ecx, %ecx
 	    xorl %edx, %edx
-	    xorl %eax, %eax
 
 	 and the equivalent
 
-	    subl %ebx, %ebx
+	    subl %eax, %eax
 	    subl %ecx, %ecx
 	    subl %edx, %edx
-	    subl %eax, %eax
 
 	 Because of the symmetry, there are actually two ways to
 	 encode these instructions; with opcode bytes 0x29 and 0x2b
@@ -524,21 +532,35 @@ i386_analyze_frame_setup (CORE_ADDR pc, 
 
 	 Make sure we only skip these instructions if we later see the
 	 `movl %esp, %ebp' that actually sets up the frame.  */
-      while (op == 0x29 || op == 0x2b || op == 0x31 || op == 0x33)
+      while ((op >= 0xb8 && op <= 0xba)
+	     || op == 0x29 || op == 0x2b
+	     || op == 0x31 || op == 0x33)
 	{
-	  op = read_memory_unsigned_integer (pc + skip + 2, 1);
-	  switch (op)
+	  if (op >= 0xb8 && op <= 0xba)
+	    {
+	      /* Skip the `movl' instructions cited above.  */
+	      skip += 5;
+	    }
+	  else
 	    {
-	    case 0xdb:	/* %ebx */
-	    case 0xc9:	/* %ecx */
-	    case 0xd2:	/* %edx */
-	    case 0xc0:	/* %eax */
-	      skip += 2;
-	      break;
-	    default:
-	      return pc + 1;
+	      /* Skip the `subl' and `xorl' instructions cited above.  */
+	      op = read_memory_unsigned_integer (pc + skip + 2, 1);
+	      switch (op)
+		{
+		case 0xc0:	/* %eax */
+		case 0xc9:	/* %ecx */
+		case 0xd2:	/* %edx */
+		  skip += 2;
+		  break;
+		default:
+		  return pc + 1;
+		}
 	    }
 
+	  /* If that's all, return now.  */
+	  if (current_pc <= pc + skip + 1)
+	    return current_pc;
+
 	  op = read_memory_unsigned_integer (pc + skip + 1, 1);
 	}
 


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

end of thread, other threads:[~2004-08-01 13:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-01 13:54 [PATCH] Partial fix for PR backtrace/1718 Mark Kettenis
  -- strict thread matches above, loose matches on Subject: below --
2004-07-24 12:59 Mark Kettenis
2004-07-24 17:58 ` Eli Zaretskii
2004-07-30 18:35 ` Eli Zaretskii
2004-07-30 20:08   ` Mark Kettenis
2004-07-31 13:41     ` Eli Zaretskii
2004-07-31 15:09       ` Michael Chastain
2004-07-31 18:44         ` Eli Zaretskii
2004-08-01  5:35           ` Michael Chastain

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