This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RFC: PowerPC/Linux signal handlers


Kevin, any comments on this patch?

[From a copyright perspective I think it's OK; this is an obvious patch
once someone tells us that the used syscall numbers have changed. 
Anyone have a different opinion?]

----- Forwarded message from Anton Blanchard <anton@samba.org> -----

Date: Thu, 16 Jan 2003 17:55:02 +1100
From: Anton Blanchard <anton@samba.org>
Subject: Bug#176963: gdb understand signal trampolines on ppc
To: Debian Bug Tracking System <submit@bugs.debian.org>
Reply-To: Anton Blanchard <anton@samba.org>, 176963@bugs.debian.org

Package: gdb
Version: 5.3-2
Severity: normal
Tags: patch

Hi,

gdb looks for the old li r0,0x7777 instruction when matching signal
trampolines. This means it only works for old kernels and only for non
rt signals. The following patch makes it look for non rt and rt signals
as well as old and new kernels.

eg I set a breakpoint on a signal handler function.

before:

Breakpoint 1, foohandler (sig=10) at /home/anton/signaltest.c:5
5		printf("in handler\n");
(gdb) bt
#0  foohandler (sig=10) at /home/anton/signaltest.c:5
#1  0xffffebf8 in ?? ()

and with the patch below:

Breakpoint 1, foohandler (sig=10) at /home/anton/signaltest.c:5
5		printf("in handler\n");
(gdb) bt
#0  foohandler (sig=10) at /home/anton/signaltest.c:5
#1  <signal handler called>
#2  0x0feda0f0 in kill () from /lib/libc.so.6
#3  0x0fed9f10 in raise () from /lib/libc.so.6
#4  0x10000508 in main () at /home/anton/signaltest.c:11
#5  0x0fec3e24 in __libc_start_main () from /lib/libc.so.6

-- System Information:
Debian Release: testing/unstable
Architecture: powerpc
Kernel: Linux krispykreme 2.4.20-pre4 #229 Wed Aug 28 16:09:40 EST 2002 ppc
Locale: LANG=C, LC_CTYPE=C

Versions of packages gdb depends on:
ii  libc6                     2.3.1-9        GNU C Library: Shared libraries an
ii  libncurses5               5.3.20021109-2 Shared libraries for terminal hand
ii  libreadline4              4.3-4          GNU readline and history libraries

-- no debconf information

diff -ru gdb-5.3_orig/gdb/ppc-linux-tdep.c gdb-5.3/gdb/ppc-linux-tdep.c
--- gdb-5.3_orig/gdb/ppc-linux-tdep.c	2002-07-31 05:03:49.000000000 +1000
+++ gdb-5.3/gdb/ppc-linux-tdep.c	2003-01-16 17:44:38.000000000 +1100
@@ -35,10 +35,16 @@
 #include "solib-svr4.h"
 #include "ppc-tdep.h"
 
-/* The following two instructions are used in the signal trampoline
-   code on GNU/Linux PPC.  */
-#define INSTR_LI_R0_0x7777	0x38007777
-#define INSTR_SC		0x44000002
+/* The following instructions are used in the signal trampoline
+   code on GNU/Linux PPC. The kernel used to use magic syscalls
+   0x6666 and 0x7777 but now uses the sigreturn syscalls. We
+   check for both. */
+#define INSTR_LI_R0_0x6666		0x38006666
+#define INSTR_LI_R0_0x7777		0x38007777
+#define INSTR_LI_R0_NR_sigreturn	0x38000077
+#define INSTR_LI_R0_NR_rt_sigreturn	0x380000AC
+
+#define INSTR_SC			0x44000002
 
 /* Since the *-tdep.c files are platform independent (i.e, they may be
    used to build cross platform debuggers), we can't include system
@@ -177,6 +183,25 @@
   return (pc == handler || pc == handler + 4);
 }
 
+static inline int insn_is_sigreturn(unsigned int pcinsn)
+{
+	int result;
+
+	switch(pcinsn) {
+		case INSTR_LI_R0_0x6666:
+		case INSTR_LI_R0_0x7777:
+		case INSTR_LI_R0_NR_sigreturn:
+		case INSTR_LI_R0_NR_rt_sigreturn:
+			result = 1;
+			break;
+		default:
+			result = 0;
+			break;
+	}
+
+	return result;
+}
+
 /*
  * The signal handler trampoline is on the stack and consists of exactly
  * two instructions.  The easiest and most accurate way of determining
@@ -196,11 +221,11 @@
   pcinsn = extract_unsigned_integer (buf + 4, 4);
 
   return (
-	   (pcinsn == INSTR_LI_R0_0x7777
+	   (insn_is_sigreturn (pcinsn)
 	    && extract_unsigned_integer (buf + 8, 4) == INSTR_SC)
 	   ||
 	   (pcinsn == INSTR_SC
-	    && extract_unsigned_integer (buf, 4) == INSTR_LI_R0_0x7777));
+	    && insn_is_sigreturn (extract_unsigned_integer (buf, 4))));
 }
 
 CORE_ADDR



----- End forwarded message -----

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]