Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Fix PPC non-CFI + CFI unwinding (incomplete in HEAD)
@ 2007-01-13  9:31 Jan Kratochvil
  2007-01-13 16:04 ` Daniel Jacobowitz
  0 siblings, 1 reply; 9+ messages in thread
From: Jan Kratochvil @ 2007-01-13  9:31 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andreas Schwab, Mark Kettenis

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

Hi,

attached patches unfortunately still do not fix the upstream gdb regarding
"-pie" code as there are more PPC patches in the Red Hat gdb fork.
Posting FYI as the Red Hat gdb fork started properly unwinding all the tested
combinations.

The testcase unfortunately does not test all the code possibilities.
It was tested on some `evolution' backtrace unwinding also Gnome libraries.

Providing FYI as the complete PPC gdb functionality would need resubmitting and
reviewing the other Red Hat PPC patches (not mine).  Upon request.


The code needs to first accept Andreas Schwab's patch
	http://sourceware.org/ml/gdb-patches/2006-05/msg00166.html
I believe it have not happened due to the Mark Kettenis's pending OS review:
	http://sourceware.org/ml/gdb-patches/2006-05/msg00341.html



Regards,
Jan

[-- Attachment #2: gdb-6.3-bz140532-ppcnoncfi-skip_prologue-PIC.patch --]
[-- Type: text/plain, Size: 1718 bytes --]

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=140532


2007-01-01  Jan Kratochvil <jan.kratochvil@redhat.com>

	* rs6000-tdep.c (skip_prologue): Handle bl->brlr used by PIC code.


diff -u -rup gdb-6.5-orig/gdb/rs6000-tdep.c gdb-6.5/gdb/rs6000-tdep.c
--- gdb-6.5-orig/gdb/rs6000-tdep.c	2006-12-30 15:53:52.000000000 -0500
+++ gdb-6.5/gdb/rs6000-tdep.c	2006-12-31 19:06:28.000000000 -0500
@@ -1182,6 +1182,40 @@ skip_prologue (CORE_ADDR pc, CORE_ADDR l
       else if ((op & 0xfc000001) == 0x48000001)
 	{			/* bl foo, 
 				   to save fprs??? */
+	  CORE_ADDR bl_target;
+	  gdb_byte bl_target_op_buf[4];
+
+	  /* Safely skip:
+	     prologue: ...
+		       bl addr
+		       ...
+	     addr:     blrl
+	     as it could break the prologue by `prologue_sal.line'
+	     or `prologue_sal.line != this_sal.line' conditions below.  */
+	  /* Sign-extend it to the upper 6 bits.  */
+	  if (op & 0x02000000)
+	    bl_target = pc + -(long) (((~op) & 0x03fffffc) + 4);
+	  else
+	    bl_target = pc + (op & 0x03fffffc);
+	  if (target_read_memory (bl_target, bl_target_op_buf, 4) == 0)
+	    {
+	      unsigned long bl_target_op;
+
+	      bl_target_op = extract_signed_integer (bl_target_op_buf, 4);
+	      if (bl_target_op == 0x4e800021)	/* blrl  */
+		{
+		  /* If we did not yet retrieved LR into some GPR
+		     all our chances are lost.  On the other hand already
+		     stored LR is still kept intact in its GPR.  */
+		  if (lr_reg == -1)
+		    {
+		      /* Invalidate lr_reg, but don't set it to -1.
+			 That would mean that it had never been set.  */
+		      lr_reg = -2;
+		    }
+		  continue;
+		}
+	    }
 
 	  fdata->frameless = 0;
 	  /* Don't skip over the subroutine call if it is not within

[-- Attachment #3: gdb-6.5-bz140532-ppc-debug_frame-return_address.patch --]
[-- Type: text/plain, Size: 5196 bytes --]

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=140532


2007-01-13  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dwarf2-frame.c (decode_frame_entry_1): Call
	dwarf2_frame_return_address_regnum when processing CIE return address.
	(struct dwarf2_frame_ops): Add return_address_regnum.
	(dwarf2_frame_set_return_address_regnum): Define.
	(dwarf2_frame_return_address_regnum): Define.
	* dwarf2-frame.h (dwarf2_frame_set_return_address_regnum): Declare.
	(dwarf2_frame_return_address_regnum): Declare.
	* rs6000-tdep.c (rs6000_dwarf2_reg_to_regnum): Map also 64(CR) and
	65(FPSCR) DWARF2 registers.
	(rs6000_return_address_regnum): Define.
	(rs6000_gdbarch_init): Register rs6000_return_address_regnum.


--- gdb-6.5-ppc/gdb/dwarf2-frame.c	2007-01-12 14:40:32.000000000 -0500
+++ gdb-6.5/gdb/dwarf2-frame.c	2007-01-12 18:46:32.000000000 -0500
@@ -586,6 +586,10 @@ struct dwarf2_frame_ops
 
   /* Convert .eh_frame register number to DWARF register number.  */
   int (*eh_frame_regnum) (struct gdbarch *, int);
+
+  /* Convert .eh_frame/.debug_frame CIE return address register number to DWARF
+     register number.  */
+  int (*return_address_regnum) (struct gdbarch *, int, int);
 };
 
 /* Default architecture-specific register state initialization
@@ -693,6 +697,32 @@ dwarf2_frame_signal_frame_p (struct gdba
   return ops->signal_frame_p (gdbarch, next_frame);
 }
 
+/* Set the architecture-specific mapping of .eh_frame/.debug_frame CIE return
+   address register number to DWARF register number.  */
+
+void
+dwarf2_frame_set_return_address_regnum (struct gdbarch *gdbarch,
+					int (*return_address_regnum)
+					    (struct gdbarch *, int, int))
+{
+  struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data);
+
+  ops->return_address_regnum = return_address_regnum;
+}
+
+/* Translate a .eh_frame/.debug_frame CIE register to DWARF register.  */
+
+int
+dwarf2_frame_return_address_regnum (struct gdbarch *gdbarch, int regnum,
+				    int eh_frame_p)
+{
+  struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data);
+
+  if (ops->return_address_regnum == NULL)
+    return regnum;
+  return ops->return_address_regnum (gdbarch, regnum, eh_frame_p);
+}
+
 /* Set the architecture-specific mapping of .eh_frame register numbers to
    DWARF register numbers.  */
 
@@ -1618,6 +1648,11 @@ decode_frame_entry_1 (struct comp_unit *
       else
 	cie->return_address_register = read_unsigned_leb128 (unit->abfd, buf,
 							     &bytes_read);
+
+      cie->return_address_register
+        = dwarf2_frame_return_address_regnum (current_gdbarch,
+					      cie->return_address_register,
+					      eh_frame_p);
       if (eh_frame_p)
 	cie->return_address_register
 	  = dwarf2_frame_eh_frame_regnum (current_gdbarch,
--- gdb-6.5-ppc/gdb/dwarf2-frame.h	2007-01-12 14:40:32.000000000 -0500
+++ gdb-6.5/gdb/dwarf2-frame.h	2007-01-12 18:36:47.000000000 -0500
@@ -107,6 +107,20 @@ extern void
 extern int
   dwarf2_frame_eh_frame_regnum (struct gdbarch *gdbarch, int regnum);
 
+/* Set the architecture-specific mapping of .eh_frame/.debug_frame CIE return
+   address register number to DWARF register number.  */
+
+extern void
+  dwarf2_frame_set_return_address_regnum (struct gdbarch *gdbarch,
+					  int (*return_address_regnum)
+					      (struct gdbarch *, int, int));
+
+/* Translate a .eh_frame/.debug_frame CIE register to DWARF register.  */
+
+extern int
+  dwarf2_frame_return_address_regnum (struct gdbarch *gdbarch, int regnum,
+				      int eh_frame_p);
+
 /* Return the frame unwind methods for the function that contains PC,
    or NULL if it can't be handled by DWARF CFI frame unwinder.  */
 
--- gdb-6.5-ppc/gdb/rs6000-tdep.c	2007-01-12 14:40:32.000000000 -0500
+++ gdb-6.5/gdb/rs6000-tdep.c	2007-01-12 18:44:21.000000000 -0500
@@ -2307,6 +2307,11 @@ rs6000_dwarf2_reg_to_regnum (int num)
   else
     switch (num)
       {
+      case 64:
+        return tdep->ppc_cr_regnum;
+      /* Broken GCC uses it for CIE `Return address column' as LR.  */
+      case 65:
+        return tdep->ppc_fpscr_regnum;
       case 67:
         return tdep->ppc_vrsave_regnum - 1; /* vscr */
       case 99:
@@ -2363,6 +2368,22 @@ rs6000_eh_frame_regnum (struct gdbarch *
       }
 }
 
+/* Convert a .eh_frame/.debug_frame CIE return address register number to DWARF
+   register number.  */
+static int
+rs6000_return_address_regnum (struct gdbarch *gdbarch, int regnum,
+			      int eh_frame_p)
+{
+  if (eh_frame_p != 0)
+    return regnum;
+
+  /* Broken GCC uses it for CIE `Return address column' as LR.  */
+  if (regnum == 65)
+    return 108;
+
+  return regnum;
+}
+
 static void
 rs6000_store_return_value (struct type *type,
                            struct regcache *regcache,
@@ -3584,6 +3605,8 @@ rs6000_gdbarch_init (struct gdbarch_info
   /* Hook in the DWARF CFI frame unwinder.  */
   frame_unwind_append_sniffer (gdbarch, dwarf2_frame_sniffer);
   dwarf2_frame_set_eh_frame_regnum (gdbarch, rs6000_eh_frame_regnum);
+  dwarf2_frame_set_return_address_regnum (gdbarch,
+					  rs6000_return_address_regnum);
 
   /* Hook in ABI-specific overrides, if they have been registered.  */
   gdbarch_init_osabi (info, gdbarch);

[-- Attachment #4: gdb-6.5-bz140532-ppc-debug_frame-return_address-test.patch --]
[-- Type: text/plain, Size: 4511 bytes --]

2007-01-13  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.base/bt-ppc.c, gdb.base/bt-ppc.exp: New files.


diff -u -rupN gdb-6.5-ppc/gdb/testsuite/gdb.base/bt-ppc.c gdb-6.5/gdb/testsuite/gdb.base/bt-ppc.c
--- gdb-6.5-ppc/gdb/testsuite/gdb.base/bt-ppc.c	1969-12-31 19:00:00.000000000 -0500
+++ gdb-6.5/gdb/testsuite/gdb.base/bt-ppc.c	2007-01-12 21:34:55.000000000 -0500
@@ -0,0 +1,41 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2007 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+ 
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#include <stdlib.h>
+
+/* Force `-fpie' double jump bl->blrl.  */
+volatile int var;
+
+int func0 (void) __attribute__((__noinline__));
+int func0 (void)
+{
+  abort ();
+  return var;
+}
+
+int func1 (void) __attribute__((__noinline__));
+int func1 (void)
+{
+  return func0 () + var;
+}
+
+int main (void)
+{
+  func1 ();
+  return 0;
+}
diff -u -rupN gdb-6.5-ppc/gdb/testsuite/gdb.base/bt-ppc.exp gdb-6.5/gdb/testsuite/gdb.base/bt-ppc.exp
--- gdb-6.5-ppc/gdb/testsuite/gdb.base/bt-ppc.exp	1969-12-31 19:00:00.000000000 -0500
+++ gdb-6.5/gdb/testsuite/gdb.base/bt-ppc.exp	2007-01-12 21:27:25.000000000 -0500
@@ -0,0 +1,86 @@
+#   Copyright 2006, 2007 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
+
+# Test multiple unwinding fixes of PPC platform.
+# As the tests are platform independent we can run it everywhere.
+
+if $tracelevel then {
+    strace $tracelevel
+}
+
+set prms_id 0
+set bug_id 0
+
+# This test uses GCC-specific syntax.
+if [get_compiler_info not-used] {
+    return -1
+}
+
+if {![test_compiler_info "gcc-*"]} {
+    return 0
+}
+
+proc do_test { opts addons } {
+    global objdir srcdir subdir gdb_prompt
+
+    set testfile "bt-ppc"
+    set srcfile ${testfile}.c
+    set binfile ${objdir}/${subdir}/${testfile}
+
+    # `additional_flags' should be last as it eats arguments till eol.
+    if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" ${binfile} executable [list $opts additional_flags=$addons]] != ""} {
+	return -1
+    }
+
+    gdb_exit
+    gdb_start
+    gdb_reinitialize_dir $srcdir/$subdir
+    gdb_load ${binfile}
+
+    # We should stop in abort(3).
+
+    gdb_run_cmd
+
+    gdb_test_multiple {} "continue to abort()" {
+	-re ".*Program received signal SIGABRT,.*$gdb_prompt $" {
+	   pass "continue to abort()"
+	}
+    }
+
+    # Check backtrace:
+    # #3  0x0804835f in func0 ()
+    # #4  0x0804836a in func1 ()
+    # #5  0x0804838c in main ()
+    # (gdb)
+    # `\\.?' prefixes are needed for ppc64 without `debug' (another bug).
+
+    set show [concat $opts $addons]
+    gdb_test_multiple "bt" "Correct unwind for: $show" {
+	-re "\r\n#\[0-9\]\[^\r\n\]* in \\.?func0 \\(\[^\r\n\]*\r\n#\[0-9\]\[^\r\n\]* in \\.?func1 \\(\[^\r\n\]*\r\n#\[0-9\]\[^\r\n\]* in \\.?main \\(\[^\r\n\]*\r\n$gdb_prompt $" {
+	    pass "Correct unwind for: $show"
+	}
+    }
+}
+
+foreach eh_frame {{-fno-asynchronous-unwind-tables}
+		  {-fasynchronous-unwind-tables}} {
+    foreach pie {{} {-fpie -pie}} {
+	foreach optim {{} {-O2}} {
+	    foreach is_debug {{} {debug}} {
+		do_test $is_debug [concat $eh_frame $pie $optim]
+	    }
+	}
+    }
+}

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

* Re: [PATCH] Fix PPC non-CFI + CFI unwinding (incomplete in HEAD)
  2007-01-13  9:31 [PATCH] Fix PPC non-CFI + CFI unwinding (incomplete in HEAD) Jan Kratochvil
@ 2007-01-13 16:04 ` Daniel Jacobowitz
  2007-01-13 16:32   ` Mark Kettenis
  0 siblings, 1 reply; 9+ messages in thread
From: Daniel Jacobowitz @ 2007-01-13 16:04 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches, Andreas Schwab, Mark Kettenis, Joel Brobecker

On Sat, Jan 13, 2007 at 10:30:52AM +0100, Jan Kratochvil wrote:
> 2007-01-01  Jan Kratochvil <jan.kratochvil@redhat.com>
> 
> 	* rs6000-tdep.c (skip_prologue): Handle bl->brlr used by PIC code.

IIRC Joel was working on a patch for this case too.  I'd been hoping one of
our PPC experts would look at it...

-- 
Daniel Jacobowitz
CodeSourcery


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

* Re: [PATCH] Fix PPC non-CFI + CFI unwinding (incomplete in HEAD)
  2007-01-13 16:04 ` Daniel Jacobowitz
@ 2007-01-13 16:32   ` Mark Kettenis
  2007-01-13 16:40     ` Daniel Jacobowitz
  0 siblings, 1 reply; 9+ messages in thread
From: Mark Kettenis @ 2007-01-13 16:32 UTC (permalink / raw)
  To: drow; +Cc: jan.kratochvil, gdb-patches, schwab, mark.kettenis, brobecker

> Date: Sat, 13 Jan 2007 11:04:20 -0500
> From: Daniel Jacobowitz <drow@false.org>
> 
> On Sat, Jan 13, 2007 at 10:30:52AM +0100, Jan Kratochvil wrote:
> > 2007-01-01  Jan Kratochvil <jan.kratochvil@redhat.com>
> > 
> > 	* rs6000-tdep.c (skip_prologue): Handle bl->brlr used by PIC code.
> 
> IIRC Joel was working on a patch for this case too.  I'd been hoping one of
> our PPC experts would look at it...

I've completely lost track of the various powerpc prologue scanner
fixes floating around.  Is this patch supposed to fix the same problem
as the test below exposes?

Mark


Index: powerpc-prologue.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.arch/powerpc-prologue.c,v
retrieving revision 1.2
diff -u -p -r1.2 powerpc-prologue.c
--- powerpc-prologue.c	9 Jan 2007 17:59:09 -0000	1.2
+++ powerpc-prologue.c	13 Jan 2007 16:30:18 -0000
@@ -31,23 +31,54 @@ int
 main (void)
 {
   gdb2029 ();
+  optimized_1 ();
   return 0;
 }
 
+void
+optimized_1_marker (void)
+{
+}
+
+void
+gdb2029_marker (void)
+{
+}
+
 /* A typical PIC prologue from GCC.  */
 
 asm(".text\n"
-    "    .align 8\n"
+    "    .p2align 3\n"
     SYMBOL (gdb2029) ":\n"
-    "	stw	%r1, -32(%r1)\n"
+    "	stwu	%r1, -32(%r1)\n"
     "	mflr	%r0\n"
     "	bcl-	20,31,.+4\n"
     "	stw	%r30, 24(%r1)\n"
     "	mflr	%r30\n"
     "	stw	%r0, 36(%r1)\n"
-    "	twge	%r2, %r2\n"
+    "	bl	gdb2029_marker\n"
     "	lwz	%r0, 36(%r1)\n"
     "	lwz	%r30, 24(%r1)\n"
     "	mtlr	%r0\n"
-    "	addi	%r0, %r0, 32\n"
+    "	addi	%r1, %r1, 32\n"
+    "	blr");
+
+/* A heavily scheduled prologue.  */
+asm(".text\n"
+    "	.p2align 3\n"
+    SYMBOL (optimized_1) ":\n"
+    "	stwu	%r1,-32(%r1)\n"
+    "	lis	%r9,-16342\n"
+    "	lis	%r11,-16342\n"
+    "	mflr	%r0\n"
+    "	addi	%r11,%r11,3776\n"
+    "	stmw	%r27,12(%r1)\n"
+    "	addi	%r31,%r9,3152\n"
+    "	cmplw	%cr7,%r31,%r11\n"
+    "	stw	%r0,36(%r1)\n"
+    "	mr	%r30,%r3\n"
+    "	bl	optimized_1_marker\n"
+    "	lwz	%r0,36(%r1)\n"
+    "	lmw	%r27,12(%r1)\n"
+    "	addi	%r1,%r1,32\n"
     "	blr");
Index: powerpc-prologue.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.arch/powerpc-prologue.exp,v
retrieving revision 1.2
diff -u -p -r1.2 powerpc-prologue.exp
--- powerpc-prologue.exp	9 Jan 2007 17:59:09 -0000	1.2
+++ powerpc-prologue.exp	13 Jan 2007 16:30:18 -0000
@@ -50,12 +50,40 @@ if ![runto_main] then {
 
 # Testcase for PIC prologue.
 
-gdb_test "continue" "Program received signal SIGTRAP.*" "continue to PIC"
+gdb_breakpoint "gdb2029_marker"
+gdb_test "continue" "Breakpoint $decimal, $hex in gdb2029_marker \\(\\)" \
+	"continue to PIC"
 
 gdb_test "backtrace 10" \
-	"#0\[ \t\]*$hex in gdb2029.*\r\n#1\[ \t\]*$hex in main.*" \
+	"#0\[ \t\]*$hex in gdb2029_marker.*\r\n#1\[ \t\]*$hex in gdb2029.*\r\n#2\[ \t\]*$hex in main.*" \
+	"backtrace in PIC marker"
+
+gdb_test "finish" ".*$hex in gdb2029 .*" "finish from PIC"
+
+gdb_test "backtrace 10" \
+	"#0\[ \t\]*$hex in gdb2029 .*\r\n#1\[ \t\]*$hex in main.*" \
 	"backtrace in PIC"
 
 gdb_test "info frame" \
 	".*Saved registers:.*r30 at.*r31 at.*pc at.*lr at.*" \
 	"saved registers in PIC"
+
+# Testcase for scheduled prologue.
+
+gdb_breakpoint "optimized_1_marker"
+gdb_test "continue" "Breakpoint $decimal, $hex in optimized_1_marker \\(\\)" \
+	"continue to optimized"
+
+gdb_test "backtrace 10" \
+	"#0\[ \t\]*$hex in optimized_1_marker.*\r\n#1\[ \t\]*$hex in optimized_1.*\r\n#2\[ \t\]*$hex in main.*" \
+	"backtrace in optimized marker"
+
+gdb_test "finish" ".*$hex in optimized_1 .*" "finish from optimized"
+
+gdb_test "backtrace 10" \
+	"#0\[ \t\]*$hex in optimized_1 .*\r\n#1\[ \t\]*$hex in main.*" \
+	"backtrace in optimized"
+
+gdb_test "info frame" \
+	".*Saved registers:.*r30 at.*r31 at.*pc at.*lr at.*" \
+	"saved registers in optimized"


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

* Re: [PATCH] Fix PPC non-CFI + CFI unwinding (incomplete in HEAD)
  2007-01-13 16:32   ` Mark Kettenis
@ 2007-01-13 16:40     ` Daniel Jacobowitz
  2007-01-14 21:34       ` Jan Kratochvil
  0 siblings, 1 reply; 9+ messages in thread
From: Daniel Jacobowitz @ 2007-01-13 16:40 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: jan.kratochvil, gdb-patches, schwab, brobecker

On Sat, Jan 13, 2007 at 05:31:32PM +0100, Mark Kettenis wrote:
> > Date: Sat, 13 Jan 2007 11:04:20 -0500
> > From: Daniel Jacobowitz <drow@false.org>
> > 
> > On Sat, Jan 13, 2007 at 10:30:52AM +0100, Jan Kratochvil wrote:
> > > 2007-01-01  Jan Kratochvil <jan.kratochvil@redhat.com>
> > > 
> > > 	* rs6000-tdep.c (skip_prologue): Handle bl->brlr used by PIC code.
> > 
> > IIRC Joel was working on a patch for this case too.  I'd been hoping one of
> > our PPC experts would look at it...
> 
> I've completely lost track of the various powerpc prologue scanner
> fixes floating around.  Is this patch supposed to fix the same problem
> as the test below exposes?

No, I don't think so - it's about the blrl at the front of the GOT in
PIC code.

I was thinking of this:
  http://sourceware.org/ml/gdb-patches/2004-12/msg00249.html
  http://sourceware.org/ml/gdb-patches/2005-06/msg00242.html

I think someone needs to combine Joel's and Jan's patches.  Joel's is
nicer in that it uses branch_dest and the right mask for blrl; Jan's
is nicer in that it checks whether lr was saved or is now lost.

> +    "	stwu	%r1,-32(%r1)\n"
> +    "	lis	%r9,-16342\n"
> +    "	lis	%r11,-16342\n"
> +    "	mflr	%r0\n"
> +    "	addi	%r11,%r11,3776\n"
> +    "	stmw	%r27,12(%r1)\n"
> +    "	addi	%r31,%r9,3152\n"
> +    "	cmplw	%cr7,%r31,%r11\n"
> +    "	stw	%r0,36(%r1)\n"
> +    "	mr	%r30,%r3\n"
> +    "	bl	optimized_1_marker\n"
> +    "	lwz	%r0,36(%r1)\n"
> +    "	lmw	%r27,12(%r1)\n"
> +    "	addi	%r1,%r1,32\n"
>      "	blr");

Looks like a different problem to me :-(

By the way, Mark, did you see this message?
  http://sourceware.org/ml/gdb-patches/2006-10/msg00233.html

I'd still like to fix that problem one way or another.  If you haven't
got time to look at it, I was considering setting up a virtual machine
for the appropriate version of OpenBSD - it would be fearsomely slow,
but I'm sure it would work.

-- 
Daniel Jacobowitz
CodeSourcery


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

* Re: [PATCH] Fix PPC non-CFI + CFI unwinding (incomplete in HEAD)
  2007-01-13 16:40     ` Daniel Jacobowitz
@ 2007-01-14 21:34       ` Jan Kratochvil
  2007-01-20 19:57         ` Daniel Jacobowitz
  0 siblings, 1 reply; 9+ messages in thread
From: Jan Kratochvil @ 2007-01-14 21:34 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches, brobecker

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

On Sat, 13 Jan 2007 17:40:28 +0100, Daniel Jacobowitz wrote:
...
> I was thinking of this:
>   http://sourceware.org/ml/gdb-patches/2004-12/msg00249.html
>   http://sourceware.org/ml/gdb-patches/2005-06/msg00242.html
> 
> I think someone needs to combine Joel's and Jan's patches.  Joel's is
> nicer in that it uses branch_dest and the right mask for blrl; Jan's
> is nicer in that it checks whether lr was saved or is now lost.

Attached for:
	http://sourceware.org/ml/gdb-patches/2004-12/msg00249.html
and it does not handle in any way
	http://sourceware.org/ml/gdb-patches/2005-06/msg00242.html
as it would be IMO more appropriate to base it on the called code content but
"I do not have that Darwin code".



Regards,
Jan

[-- Attachment #2: gdb-ppc-combo.patch --]
[-- Type: text/plain, Size: 2362 bytes --]

2007-01-14  Joel Brobecker  <brobecker@gnat.com>
	    Jan Kratochvil <jan.kratochvil@redhat.com>

	* rs6000-tdep.c (bl_to_blrl_insn_p): New function.
	(skip_prologue): Allow bl->blrl used by a PIC code.


--- gdb/rs6000-tdep.c	9 Jan 2007 17:58:57 -0000	1.260
+++ gdb/rs6000-tdep.c	14 Jan 2007 21:24:51 -0000
@@ -902,6 +902,30 @@ store_param_on_stack_p (unsigned long op
   return 0;
 }
 
+/* Assuming that INSN is a "bl" instruction located at PC, return
+   nonzero if the destination of the branch is a "blrl" instruction.
+   
+   This sequence is sometimes found in certain function prologues.
+   It allows the function to load the LR register with a value that
+   they can use to access PIC data using PC-relative offsets.  */
+
+static int
+bl_to_blrl_insn_p (CORE_ADDR pc, int insn)
+{
+  const int opcode = 18;
+  const CORE_ADDR dest = branch_dest (opcode, insn, pc, -1);
+  int dest_insn;
+
+  if (dest == -1)
+    return 0;  /* Should never happen, but just return zero to be safe.  */
+  
+  dest_insn = read_memory_integer (dest, 4);
+  if ((dest_insn & 0xfc00ffff) == 0x4c000021) /* blrl */
+    return 1;
+
+  return 0;
+}
+
 static CORE_ADDR
 skip_prologue (CORE_ADDR pc, CORE_ADDR lim_pc, struct rs6000_framedata *fdata)
 {
@@ -1133,18 +1157,19 @@ skip_prologue (CORE_ADDR pc, CORE_ADDR l
 				   to save fprs??? */
 
 	  fdata->frameless = 0;
-	  /* Don't skip over the subroutine call if it is not within
-	     the first three instructions of the prologue and either
-	     we have no line table information or the line info tells
-	     us that the subroutine call is not part of the line
-	     associated with the prologue.  */
-	  if ((pc - orig_pc) > 8)
-	    {
-	      struct symtab_and_line prologue_sal = find_pc_line (orig_pc, 0);
-	      struct symtab_and_line this_sal = find_pc_line (pc, 0);
 
-	      if ((prologue_sal.line == 0) || (prologue_sal.line != this_sal.line))
-		break;
+          if (bl_to_blrl_insn_p (pc, op))
+	    {
+	      /* If we did not yet retrieved LR into some GPR
+		 all our chances are lost.  On the other hand already
+		 stored LR is still kept intact in its GPR.  */
+	      if (lr_reg == -1)
+		{
+		  /* Invalidate lr_reg, but don't set it to -1.
+		     That would mean that it had never been set.  */
+		  lr_reg = -2;
+		}
+	      continue;
 	    }
 
 	  op = read_memory_integer (pc + 4, 4);

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

* Re: [PATCH] Fix PPC non-CFI + CFI unwinding (incomplete in HEAD)
  2007-01-14 21:34       ` Jan Kratochvil
@ 2007-01-20 19:57         ` Daniel Jacobowitz
  2007-01-21 10:41           ` Mark Kettenis
  2007-01-21 21:47           ` Jan Kratochvil
  0 siblings, 2 replies; 9+ messages in thread
From: Daniel Jacobowitz @ 2007-01-20 19:57 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches, brobecker

On Sun, Jan 14, 2007 at 10:34:14PM +0100, Jan Kratochvil wrote:
> On Sat, 13 Jan 2007 17:40:28 +0100, Daniel Jacobowitz wrote:
> ...
> > I was thinking of this:
> >   http://sourceware.org/ml/gdb-patches/2004-12/msg00249.html
> >   http://sourceware.org/ml/gdb-patches/2005-06/msg00242.html
> > 
> > I think someone needs to combine Joel's and Jan's patches.  Joel's is
> > nicer in that it uses branch_dest and the right mask for blrl; Jan's
> > is nicer in that it checks whether lr was saved or is now lost.
> 
> Attached for:
> 	http://sourceware.org/ml/gdb-patches/2004-12/msg00249.html
> and it does not handle in any way
> 	http://sourceware.org/ml/gdb-patches/2005-06/msg00242.html
> as it would be IMO more appropriate to base it on the called code content but
> "I do not have that Darwin code".

I tried combining them myself.  Could you let me know if this patch
still fixes your bug?


-- 
Daniel Jacobowitz
CodeSourcery

2007-01-14  Joel Brobecker  <brobecker@gnat.com>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Daniel Jacobowitz  <dan@codesourcery.com>

	* rs6000-tdep.c (bl_to_blrl_insn_p): New function.
	(skip_prologue): Allow bl->blrl used by PIC code.

Index: rs6000-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/rs6000-tdep.c,v
retrieving revision 1.260
diff -u -p -r1.260 rs6000-tdep.c
--- rs6000-tdep.c	9 Jan 2007 17:58:57 -0000	1.260
+++ rs6000-tdep.c	20 Jan 2007 19:55:58 -0000
@@ -902,6 +902,30 @@ store_param_on_stack_p (unsigned long op
   return 0;
 }
 
+/* Assuming that INSN is a "bl" instruction located at PC, return
+   nonzero if the destination of the branch is a "blrl" instruction.
+   
+   This sequence is sometimes found in certain function prologues.
+   It allows the function to load the LR register with a value that
+   they can use to access PIC data using PC-relative offsets.  */
+
+static int
+bl_to_blrl_insn_p (CORE_ADDR pc, int insn)
+{
+  const int opcode = 18;
+  const CORE_ADDR dest = branch_dest (opcode, insn, pc, -1);
+  int dest_insn;
+
+  if (dest == -1)
+    return 0;  /* Should never happen, but just return zero to be safe.  */
+  
+  dest_insn = read_memory_integer (dest, 4);
+  if ((dest_insn & 0xfc00ffff) == 0x4c000021) /* blrl */
+    return 1;
+
+  return 0;
+}
+
 static CORE_ADDR
 skip_prologue (CORE_ADDR pc, CORE_ADDR lim_pc, struct rs6000_framedata *fdata)
 {
@@ -1133,6 +1157,12 @@ skip_prologue (CORE_ADDR pc, CORE_ADDR l
 				   to save fprs??? */
 
 	  fdata->frameless = 0;
+
+	  /* If the return address has already been saved, we can skip
+	     calls to blrl (for PIC).  */
+          if (lr_reg != -1 && bl_to_blrl_insn_p (pc, op))
+	    continue;
+
 	  /* Don't skip over the subroutine call if it is not within
 	     the first three instructions of the prologue and either
 	     we have no line table information or the line info tells


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

* Re: [PATCH] Fix PPC non-CFI + CFI unwinding (incomplete in HEAD)
  2007-01-20 19:57         ` Daniel Jacobowitz
@ 2007-01-21 10:41           ` Mark Kettenis
  2007-01-21 21:47           ` Jan Kratochvil
  1 sibling, 0 replies; 9+ messages in thread
From: Mark Kettenis @ 2007-01-21 10:41 UTC (permalink / raw)
  To: drow; +Cc: jan.kratochvil, gdb-patches, brobecker

> Date: Sat, 20 Jan 2007 14:57:22 -0500
> From: Daniel Jacobowitz <drow@false.org>
> 
> I tried combining them myself.  Could you let me know if this patch
> still fixes your bug?

This diff seems to fix

FAIL: gdb.gdb/selftest.exp: backtrace through signal handler

on powerpc-unknown-openbsd4.0.

> 2007-01-14  Joel Brobecker  <brobecker@gnat.com>
> 	    Jan Kratochvil  <jan.kratochvil@redhat.com>
> 	    Daniel Jacobowitz  <dan@codesourcery.com>
> 
> 	* rs6000-tdep.c (bl_to_blrl_insn_p): New function.
> 	(skip_prologue): Allow bl->blrl used by PIC code.


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

* Re: [PATCH] Fix PPC non-CFI + CFI unwinding (incomplete in HEAD)
  2007-01-20 19:57         ` Daniel Jacobowitz
  2007-01-21 10:41           ` Mark Kettenis
@ 2007-01-21 21:47           ` Jan Kratochvil
  2007-02-08 14:24             ` Daniel Jacobowitz
  1 sibling, 1 reply; 9+ messages in thread
From: Jan Kratochvil @ 2007-01-21 21:47 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches, brobecker

On Sat, 20 Jan 2007 20:57:22 +0100, Daniel Jacobowitz wrote:
...
> I tried combining them myself.  Could you let me know if this patch
> still fixes your bug?

Yes.


Regards,
Lace


CVS HEAD:
(gdb) bt
#0  0x0ff278cc in poll () from /lib/tls/libc.so.6
...
#16 0x0ff278b4 in poll () from /lib/tls/libc.so.6
Backtrace stopped: previous frame inner to this frame (corrupt stack?)


CVS HEAD with both {Joel's+mine} and {+yours} patch:
(gdb) bt
#0  0x0ff278cc in poll () from /lib/tls/libc.so.6
#1  0x0f97f0f0 in ?? () from /usr/lib/libglib-2.0.so.0
#2  0x0f97f704 in g_main_loop_run () from /usr/lib/libglib-2.0.so.0
#3  0x0f008d00 in gtk_main () from /usr/lib/libgtk-x11-2.0.so.0
#4  0x10013c70 in e_shell_startup_wizard_create ()
#5  0x10019678 in e_shell_construct ()
#6  0x100197bc in e_shell_new ()
#7  0x1001ab30 in ?? ()
#8  0x0f9813c4 in ?? () from /usr/lib/libglib-2.0.so.0
#9  0x0f97d040 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#10 0x0f97f2e4 in ?? () from /usr/lib/libglib-2.0.so.0
#11 0x0f97f704 in g_main_loop_run () from /usr/lib/libglib-2.0.so.0
#12 0x0e9c6b6c in bonobo_main () from /usr/lib/libbonobo-2.so.0
#13 0x1001b0d0 in main ()


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

* Re: [PATCH] Fix PPC non-CFI + CFI unwinding (incomplete in HEAD)
  2007-01-21 21:47           ` Jan Kratochvil
@ 2007-02-08 14:24             ` Daniel Jacobowitz
  0 siblings, 0 replies; 9+ messages in thread
From: Daniel Jacobowitz @ 2007-02-08 14:24 UTC (permalink / raw)
  To: gdb-patches

On Sun, Jan 21, 2007 at 10:47:21PM +0100, Jan Kratochvil wrote:
> On Sat, 20 Jan 2007 20:57:22 +0100, Daniel Jacobowitz wrote:
> ...
> > I tried combining them myself.  Could you let me know if this patch
> > still fixes your bug?
> 
> Yes.

Thanks!  I checked it in.

-- 
Daniel Jacobowitz
CodeSourcery


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

end of thread, other threads:[~2007-02-08 14:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-13  9:31 [PATCH] Fix PPC non-CFI + CFI unwinding (incomplete in HEAD) Jan Kratochvil
2007-01-13 16:04 ` Daniel Jacobowitz
2007-01-13 16:32   ` Mark Kettenis
2007-01-13 16:40     ` Daniel Jacobowitz
2007-01-14 21:34       ` Jan Kratochvil
2007-01-20 19:57         ` Daniel Jacobowitz
2007-01-21 10:41           ` Mark Kettenis
2007-01-21 21:47           ` Jan Kratochvil
2007-02-08 14:24             ` Daniel Jacobowitz

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