Subject: bin/3391: m68k gdb can't handle sigtramp correctly
To: None <gnats-bugs@gnats.netbsd.org>
From: None <yasufu-i@is.aist-nara.ac.jp>
List: netbsd-bugs
Date: 03/26/1997 05:05:05
>Number:         3391
>Category:       bin
>Synopsis:       m68k gdb can't handle sigtramp correctly
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Mar 25 12:20:00 1997
>Last-Modified:
>Originator:     ITOH Yasufumi
>Organization:
	Nara Institute of Science and Technology, Nara, Japan
>Release:        Mar 23, 1997 (1.2D)
>Environment:
System: NetBSD acha.my.domain 1.2C NetBSD 1.2C (ACHA) #0: Sun Mar 2 06:43:08 JST 1997 yasufu-i@wonder19:/mnt/NetBSD-current/src/sys/arch/x68k/compile/ACHA x68k


>Description:
	gdb doesn't recognize that the signal handler is called by sigtramp,
	and fails to access to outer frames.

>How-To-Repeat:
	o set a breakpoint to a signal handler
	o send the signal
	o try  "bt"  and  "up"  commands, which don't work correctly.

>Fix:
	Apply the following patch to  /usr/src/gnu/usr.bin/gdb .
	I confirmed it works under NetBSD/x68k.

diff -u gdb/arch/m68k/tm.h.orig gdb/arch/m68k/tm.h
--- gdb/arch/m68k/tm.h.orig	Sat Oct 14 09:23:38 1995
+++ gdb/arch/m68k/tm.h	Wed Mar 26 04:22:32 1997
@@ -1,4 +1,4 @@
-/* Parameters for target machine Hewlett-Packard 9000/300, running bsd.
+/* Parameters for m68k based machines, running NetBSD.
    Copyright 1986, 1987, 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
 
 This file is part of GDB.
@@ -19,41 +19,52 @@
 
 	$Id: tm.h,v 1.5 1995/02/03 06:42:31 mycroft Exp $
 */
-#include <machine/vmparam.h>
 
-/* Configuration file for HP9000/300 series machine running BSD,
-   including Utah, Mt. Xinu or Berkeley variants.  This is NOT for HP-UX.
-   Problems to hpbsd-bugs@cs.utah.edu.  */
+/* Configuration file m68k based machines running NetBSD, */
 
-/* Define BPT_VECTOR if it is different than the default.
-   This is the vector number used by traps to indicate a breakpoint. */
+#ifdef CROSS_DEBUGGER
 
-#define BPT_VECTOR 0x2
+/* from <machine/vmparam.h> */
+#if defined(CROSS_TARGET_AMIGA) || defined(CROSS_TARGET_ATARI) || defined(CROSS_TARGET_SUN3) || defined(CROSS_TARGET_SUN3X)
+# define TARGET_USRSTACK	0x0E000000
+#elif defined(CROSS_TARGET_HP300) || defined(CROSS_TARGET_MVME68K)
+# define TARGET_USRSTACK	0xFFE00000
+#elif defined(CROSS_TARGET_X68K)
+# define TARGET_USRSTACK	0xFFFFD000
+#else
+ #error no cross target specified
+#endif
 
-#define TARGET_NBPG NBPG
+/* from <sys/exec.h> */
+#define SIZEOF_PSTRINGS	16
 
-/* For 4.4 this would be 2, but it is OK for us to detect an area a
-   bit bigger than necessary.  This way the same gdb binary can target
-   either 4.3 or 4.4.  */
+#define TARGET_PS_STRINGS	(TARGET_USRSTACK - SIZEOF_PS_STRINGS)
 
-#define TARGET_UPAGES UPAGES
+#else	/* not CROSS_DEBUGGER */
 
-/* On the HP300, sigtramp is in the u area.  Gak!  User struct is not
-   mapped to the same virtual address in user/kernel address space
-   (hence STACK_END_ADDR as opposed to KERNEL_U_ADDR).  This tests
-   for the whole u area, since we don't necessarily have hp300bsd
-   include files around.  */
+#include <machine/vmparam.h>
+#include <sys/exec.h>
 
-/* For 4.4, it is actually right 20 bytes before STACK_END_ADDR.  For
-   NetBSD, it is 32 bytes before STACK_END_ADDR.  We include both
-   regions in the area we test for.  */
+#undef N_BSSADDR	/* XXX conflicts with "include/aout/aout64.h" */
 
-#define SIGTRAMP_START (STACK_END_ADDR - 32)
-#define SIGTRAMP_END (STACK_END_ADDR + TARGET_UPAGES * TARGET_NBPG)
+#define TARGET_PS_STRINGS	((int) PS_STRINGS)
 
-/* Address of end of stack space.  */
+#endif	/* not CROSS_DEBUGGER */
 
-#define STACK_END_ADDR USRSTACK
+
+/* NetBSD/m68k uses  trap #2  for breakpoints. */
+
+#define BPT_VECTOR 0x2
+
+/* NetBSD/m68k uses 18byte (+ 2 for long alignment) sigtramp.
+   See  /usr/src/sys/arch/${ARCH}/${ARCH}/locore.s */
+
+#define SIZE_SIGTRAMP	20
+
+/* Address of sigtramp on NetBSD/m68k */
+
+#define SIGTRAMP_END	TARGET_PS_STRINGS
+#define SIGTRAMP_START	(SIGTRAMP_END - SIZE_SIGTRAMP)
 
 /* We define our own fetch and store methods. */
 
@@ -64,3 +75,15 @@
 
 /* Include shared library handling. */
 #include "solib.h"
+
+/*
+ * SIG_PC_FP_OFFSET is the offset from the signal handler frame to the
+ * saved pc in sigcontext.
+ * SIG_SP_FP_OFFSET is the offset from the signal handler frame to the end
+ * of sigcontext which is identical to the saved sp at SIG_PC_FP_OFFSET - 4.
+ *
+ * This value was determined by experimentation on NetBSD/x68k.
+ */
+#undef SIG_PC_FP_OFFSET
+#define SIG_PC_FP_OFFSET	532
+#define SIG_SP_FP_OFFSET	(SIG_PC_FP_OFFSET - 4)
diff -uF^[a-zA-Z_][a-z 	A-Z0-9_]*(.*[^;]$ gdb/arch/m68k/m68k-nat.c.orig gdb/arch/m68k/m68k-nat.c
--- gdb/arch/m68k/m68k-nat.c.orig	Fri Mar  1 21:12:58 1996
+++ gdb/arch/m68k/m68k-nat.c	Wed Mar 26 00:01:56 1997
@@ -1,4 +1,4 @@
-/* Native-dependent code for BSD Unix running on i386's, for GDB.
+/* Native-dependent code for BSD Unix running on m68k's, for GDB.
    Copyright 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
 
 This file is part of GDB.
>Audit-Trail:
>Unformatted: