Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 Nov 2013 10:09:53 +0200
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Andriy Gapon <avg@FreeBSD.org>
Cc:        FreeBSD Current <freebsd-current@FreeBSD.org>, Luca Pizzamiglio <luca.pizzamiglio@gmail.com>
Subject:   Re: gdb has outdated knowledge of signal trampolines
Message-ID:  <20131126080953.GS59496@kib.kiev.ua>
In-Reply-To: <20131125173527.GP59496@kib.kiev.ua>
References:  <529322E1.1060105@FreeBSD.org> <20131125173527.GP59496@kib.kiev.ua>

next in thread | previous in thread | raw e-mail | index | archive | help

--cYIzBPdBhuBoQ5I4
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Nov 25, 2013 at 07:35:27PM +0200, Konstantin Belousov wrote:
> Could you update your gdb patch to use the KERN_PROC_SIGTRAMP from
> the patch below ? If this works out, I will add initialization of
> sv_szsigcode for ABIs which do not use shared page.

Below is the complete patch.  With it applied, I get
(gdb) bt
#0  sighandler (signo=3D1, info=3D0x7fffffffd2b0, context=3DUnhandled dwarf=
 expression opcode 0xf3
) at siginfo.c:34
#1  <signal handler called>
#2  0x000000080088849a in sigsuspend () from /lib/libc.so.7
#3  0x000000000040093a in main (argc=3DUnhandled dwarf expression opcode 0x=
f3
) at siginfo.c:54

diff --git a/contrib/gdb/gdb/amd64fbsd-nat.c b/contrib/gdb/gdb/amd64fbsd-na=
t.c
index f083734..dacd4a3 100644
--- a/contrib/gdb/gdb/amd64fbsd-nat.c
+++ b/contrib/gdb/gdb/amd64fbsd-nat.c
@@ -29,6 +29,7 @@
 #include <sys/types.h>
 #include <sys/ptrace.h>
 #include <sys/sysctl.h>
+#include <sys/user.h>
 #include <machine/reg.h>
=20
 #ifdef HAVE_SYS_PROCFS_H
@@ -212,24 +213,23 @@ Please report this to <bug-gdb@gnu.org>.",
=20
   SC_RBP_OFFSET =3D offset;
=20
-  /* FreeBSD provides a kern.ps_strings sysctl that we can use to
+  /* FreeBSD provides a kern.proc.sigtramp sysctl that we can use to
      locate the sigtramp.  That way we can still recognize a sigtramp
-     if its location is changed in a new kernel.  Of course this is
-     still based on the assumption that the sigtramp is placed
-     directly under the location where the program arguments and
-     environment can be found.  */
+     if its location is changed in a new kernel. */
   {
-    int mib[2];
-    long ps_strings;
+    int mib[4];
+    struct kinfo_sigtramp kst;
     size_t len;
=20
     mib[0] =3D CTL_KERN;
-    mib[1] =3D KERN_PS_STRINGS;
-    len =3D sizeof (ps_strings);
-    if (sysctl (mib, 2, &ps_strings, &len, NULL, 0) =3D=3D 0)
+    mib[1] =3D KERN_PROC;
+    mib[2] =3D KERN_PROC_SIGTRAMP;
+    mib[3] =3D getpid();
+    len =3D sizeof (kst);
+    if (sysctl (mib, sizeof(mib) / sizeof(mib[0]), &kst, &len, NULL, 0) =
=3D=3D 0)
       {
-	amd64fbsd_sigtramp_start_addr =3D ps_strings - 32;
-	amd64fbsd_sigtramp_end_addr =3D ps_strings;
+	amd64fbsd_sigtramp_start_addr =3D kst.ksigtramp_start;
+	amd64fbsd_sigtramp_end_addr =3D kst.ksigtramp_end;
       }
   }
 }
diff --git a/sys/amd64/include/pcb.h b/sys/amd64/include/pcb.h
index c106edc..80aff86 100644
--- a/sys/amd64/include/pcb.h
+++ b/sys/amd64/include/pcb.h
@@ -43,6 +43,7 @@
 #include <machine/fpu.h>
 #include <machine/segments.h>
=20
+#ifdef __amd64__
 struct pcb {
 	register_t	pcb_r15;
 	register_t	pcb_r14;
@@ -105,6 +106,7 @@ struct pcb {
=20
 	uint64_t	pcb_pad[3];
 };
+#endif
=20
 #ifdef _KERNEL
 struct trapframe;
diff --git a/sys/amd64/include/segments.h b/sys/amd64/include/segments.h
index d9f4280..6bcadc7 100644
--- a/sys/amd64/include/segments.h
+++ b/sys/amd64/include/segments.h
@@ -82,8 +82,8 @@ struct	soft_segment_descriptor {
  * region descriptors, used to load gdt/idt tables before segments yet exi=
st.
  */
 struct region_descriptor {
-	unsigned long rd_limit:16;		/* segment extent */
-	unsigned long rd_base:64 __packed;	/* base address  */
+	uint64_t rd_limit:16;		/* segment extent */
+	uint64_t rd_base:64 __packed;	/* base address  */
 } __packed;
=20
 #ifdef _KERNEL
diff --git a/sys/compat/freebsd32/freebsd32.h b/sys/compat/freebsd32/freebs=
d32.h
index 8376e95..94f886e 100644
--- a/sys/compat/freebsd32/freebsd32.h
+++ b/sys/compat/freebsd32/freebsd32.h
@@ -362,6 +362,12 @@ struct kinfo_proc32 {
 	int	ki_tdflags;
 };
=20
+struct kinfo_sigtramp32 {
+	uint32_t ksigtramp_start;
+	uint32_t ksigtramp_end;
+	uint32_t ksigtramp_spare[4];
+};
+
 struct kld32_file_stat_1 {
 	int	version;	/* set to sizeof(struct kld_file_stat_1) */
 	char	name[MAXPATHLEN];
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index 9968e76..2e6bc32 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -2632,6 +2632,60 @@ errout:
 	return (error);
 }
=20
+static int
+sysctl_kern_proc_sigtramp(SYSCTL_HANDLER_ARGS)
+{
+	int *name =3D (int *)arg1;
+	u_int namelen =3D arg2;
+	struct proc *p;
+	struct kinfo_sigtramp kst;
+	const struct sysentvec *sv;
+	int error;
+#ifdef COMPAT_FREEBSD32
+	struct kinfo_sigtramp32 kst32;
+#endif
+
+	if (namelen !=3D 1)
+		return (EINVAL);
+
+	error =3D pget((pid_t)name[0], PGET_CANDEBUG, &p);
+	if (error !=3D 0)
+		return (error);
+	sv =3D p->p_sysent;
+#ifdef COMPAT_FREEBSD32
+	if ((req->flags & SCTL_MASK32) !=3D 0) {
+		bzero(&kst32, sizeof(kst32));
+		if (SV_PROC_FLAG(p, SV_ILP32)) {
+			if (sv->sv_sigcode_base !=3D 0) {
+				kst32.ksigtramp_start =3D sv->sv_sigcode_base;
+				kst32.ksigtramp_end =3D sv->sv_sigcode_base +
+				    *sv->sv_szsigcode;
+			} else {
+				kst32.ksigtramp_start =3D sv->sv_psstrings -
+				    *sv->sv_szsigcode;
+				kst32.ksigtramp_end =3D sv->sv_psstrings;
+			}
+		}
+		PROC_UNLOCK(p);
+		error =3D SYSCTL_OUT(req, &kst32, sizeof(kst32));
+		return (error);
+	}
+#endif
+	bzero(&kst, sizeof(kst));
+	if (sv->sv_sigcode_base !=3D 0) {
+		kst.ksigtramp_start =3D (char *)sv->sv_sigcode_base;
+		kst.ksigtramp_end =3D (char *)sv->sv_sigcode_base +
+		    *sv->sv_szsigcode;
+	} else {
+		kst.ksigtramp_start =3D (char *)sv->sv_psstrings -
+		    *sv->sv_szsigcode;
+		kst.ksigtramp_end =3D (char *)sv->sv_psstrings;
+	}
+	PROC_UNLOCK(p);
+	error =3D SYSCTL_OUT(req, &kst, sizeof(kst));
+	return (error);
+}
+
 SYSCTL_NODE(_kern, KERN_PROC, proc, CTLFLAG_RD,  0, "Process table");
=20
 SYSCTL_PROC(_kern_proc, KERN_PROC_ALL, all, CTLFLAG_RD|CTLTYPE_STRUCT|
@@ -2740,3 +2794,7 @@ static SYSCTL_NODE(_kern_proc, KERN_PROC_UMASK, umask=
, CTLFLAG_RD |
 static SYSCTL_NODE(_kern_proc, KERN_PROC_OSREL, osrel, CTLFLAG_RW |
 	CTLFLAG_ANYBODY | CTLFLAG_MPSAFE, sysctl_kern_proc_osrel,
 	"Process binary osreldate");
+
+static SYSCTL_NODE(_kern_proc, KERN_PROC_SIGTRAMP, sigtramp, CTLFLAG_RD |
+	CTLFLAG_MPSAFE, sysctl_kern_proc_sigtramp,
+	"Process signal trampoline location");
diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h
index 64292ba..8e70a12 100644
--- a/sys/sys/sysctl.h
+++ b/sys/sys/sysctl.h
@@ -530,6 +530,7 @@ SYSCTL_ALLOWED_TYPES(UINT64, uint64_t *a; unsigned long=
 long *b; );
 #define	KERN_PROC_PS_STRINGS	38	/* get ps_strings location */
 #define	KERN_PROC_UMASK		39	/* process umask */
 #define	KERN_PROC_OSREL		40	/* osreldate for process binary */
+#define	KERN_PROC_SIGTRAMP	41	/* signal trampoline location */
=20
 /*
  * KERN_IPC identifiers
diff --git a/sys/sys/user.h b/sys/sys/user.h
index d2e2b6e..e926fe8 100644
--- a/sys/sys/user.h
+++ b/sys/sys/user.h
@@ -498,6 +498,12 @@ struct kinfo_kstack {
 	int	 _kkst_ispare[16];		/* Space for more stuff. */
 };
=20
+struct kinfo_sigtramp {
+	void	*ksigtramp_start;
+	void	*ksigtramp_end;
+	void	*ksigtramp_spare[4];
+};
+
 #ifdef _KERNEL
 /* Flags for kern_proc_out function. */
 #define KERN_PROC_NOTHREADS	0x1

--cYIzBPdBhuBoQ5I4
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (FreeBSD)

iQIcBAEBAgAGBQJSlFdQAAoJEJDCuSvBvK1BPr8QAIf8qsyGYHcZkubOChm6j0ZR
EXGKnb3/mM+RE6g0lo0NSux2Buffo7kG/Rt61l06Lyy15NZY0yi1AJ4rWJixhcA2
b3ecizPRZiNN3BZ7k8nk/bS7zlvrQkhzqNy0GJ9Hzmx/Ex/3I2mdmOlUwjGyzzV1
qMpMIj/H3/UDu34iwTyqOqQ3Pol0vVMpZR5Ye0H9NywpAZJH/7yecAD7SL+UQ0Lg
exwTWVZ81XjUNKDyFq4xaQEV/hm78OsHVgGLHMkbDKlF1W/sDdTQEJik8OOydQM8
gVbE86eAsTHKHDDwHIIPETlwlNdTkPUxqu3JN2xwyoBwcqAztHJV4JNDIfO7qk0d
eI/dl2w2i2JhQPAvcNVTW0oQW39POCrwiCp/o1/6faN3aepZCTG+UoZs+pjdZe6l
YvJtiBEV/L5vp19XovGY7i5LAEKm7K7LIP1RkaKJ/nSNwhLbJJ26t4nkl93Tm7ra
weTmpAg6MNcA5VIWnLb5Wk2/5RBkrMsW9IB5dPlBysWSqGpABgn85ZnUioz2Oaqu
f009cI9SkjeSguFaqXzt9+x6oPgwumFg8riR3zAFVk5mQATv7BAaYW257T93gVi/
Vxh81gp7ovh4epfBVxI1hy1/5+C/f4CXD/q7inweE/J/L1W99SkkPDbgPLNhoyme
Gz5KXABTn50IMs7hjNC1
=dPPG
-----END PGP SIGNATURE-----

--cYIzBPdBhuBoQ5I4--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20131126080953.GS59496>