[PATCH] Workaround for FreeBSD 4.2 bug

Mark Kettenis kettenis@wins.uva.nl
Sat Jul 21 13:20:00 GMT 2001


This should work around a bug in the FreeBSD 4.2 kernel as reported by
Stu Grossman.  I rewrote his patch a bit, and used only three lines of
code plus a comment from his origional patch so I assimed we don't
need an assignment for this bit.

Checked in.


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

	* i386bsd-nat.c: Do not include <sys/sysctl.h>.
	(_initialize_i386bsd_nat) [KERN_PS_STRINGS]: Move FreeBSD-specific
	code to ...
	* i386fbsd-nat.c: ... here.  New file.
	* config/i386/fbsd.mh (NATDEPFILES): Add i386-fbsd.o.
	* config/i386/nm-fbsd.h (CHILD_RESUME): Define.
	* Makefile.in (ALLDEPFILES): Add i386fbsd-nat.c.
	(i386fbsd-nat.o): Add dependencies.

Index: i386bsd-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/i386bsd-nat.c,v
retrieving revision 1.8
diff -u -p -r1.8 i386bsd-nat.c
--- i386bsd-nat.c 2001/07/13 18:27:21 1.8
+++ i386bsd-nat.c 2001/07/21 20:15:10
@@ -323,8 +323,6 @@ kernel_u_size (void)
 /* See i386bsd-tdep.c.  */
 extern int i386bsd_sigcontext_pc_offset;
 
-#include <sys/sysctl.h>
-
 void
 _initialize_i386bsd_nat (void)
 {
@@ -337,27 +335,4 @@ _initialize_i386bsd_nat (void)
   /* Override the default value for the offset of the program counter
      in the sigcontext structure.  */
   i386bsd_sigcontext_pc_offset = offsetof (struct sigcontext, sc_pc);
-
-  /* FreeBSD provides a kern.ps_strings sysctl that we can use to
-     locate the sigtramp.  That way we can still recognize a sigtramp
-     if it's 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.  */
-#ifdef KERN_PS_STRINGS
-  {
-    int mib[2];
-    int ps_strings;
-    size_t len;
-
-    mib[0] = CTL_KERN;
-    mib[1] = KERN_PS_STRINGS;
-    len = sizeof (ps_strings);
-    if (sysctl (mib, 2, &ps_strings, &len, NULL, 0) == 0)
-      {
-	i386bsd_sigtramp_start = ps_strings - 128;
-	i386bsd_sigtramp_end = ps_strings;
-      }
-  }
-#endif
 }
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.102
diff -u -p -r1.102 Makefile.in
--- Makefile.in 2001/07/19 18:09:11 1.102
+++ Makefile.in 2001/07/21 20:15:11
@@ -1151,7 +1151,7 @@ ALLDEPFILES = 29k-share/udi/udip2soc.c 2
         hp-psymtab-read.c hp-symtab-read.c \
 	i386-tdep.c i386b-nat.c i386mach-nat.c i386v-nat.c i386-linux-nat.c \
 	i386aix-nat.c i386m3-nat.c i386v4-nat.c i386ly-tdep.c \
-	i386bsd-nat.c i386bsd-tdep.c \
+	i386bsd-nat.c i386bsd-tdep.c i386fbsd-nat.c \
 	i387-tdep.c \
 	i386-linux-tdep.c i386-nat.c \
 	i960-tdep.c \
@@ -1536,6 +1536,8 @@ i386bsd-tdep.o: i386bsd-tdep.c $(defs_h)
 	$(regcache_h)
 
 i386bsd-nat.o: i386bsd-nat.c $(defs_h) $(inferior_h) $(regcache_h)
+
+i386fbsd-nat.o: i386fbsd-nat.c $(defs_h) $(inferior_h) $(regcache_h)
 
 i386ly-nat.o: i386ly-nat.c $(defs_h) $(frame_h) $(inferior_h) target.h
 
Index: config/i386/nm-fbsd.h
===================================================================
RCS file: /cvs/src/src/gdb/config/i386/nm-fbsd.h,v
retrieving revision 1.4
diff -u -p -r1.4 nm-fbsd.h
--- config/i386/nm-fbsd.h 2001/03/31 18:09:03 1.4
+++ config/i386/nm-fbsd.h 2001/07/21 20:15:11
@@ -53,6 +53,9 @@ extern unsigned long i386bsd_dr_get_stat
 /* Override copies of {fetch,store}_inferior_registers in `infptrace.c'.  */
 #define FETCH_INFERIOR_REGISTERS
 
+/* Override child_resume in `infptrace.c' to work around a kernel bug.  */
+#define CHILD_RESUME
+
 /* We can attach and detach.  */
 #define ATTACH_DETACH
 
Index: config/i386/fbsd.mh
===================================================================
RCS file: /cvs/src/src/gdb/config/i386/fbsd.mh,v
retrieving revision 1.7
diff -u -p -r1.7 fbsd.mh
--- config/i386/fbsd.mh 2001/04/12 18:44:40 1.7
+++ config/i386/fbsd.mh 2001/07/21 20:15:11
@@ -1,6 +1,6 @@
 # Host: Intel 386 running FreeBSD
 XDEPFILES=
 # NOTE: Do not spread NATDEPFILES over several lines - it hurts BSD make.
-NATDEPFILES= fork-child.o infptrace.o inftarg.o solib.o solib-svr4.o solib-legacy.o corelow.o core-aout.o core-regset.o i387-nat.o i386bsd-nat.o i386-nat.o
+NATDEPFILES= fork-child.o infptrace.o inftarg.o solib.o solib-svr4.o solib-legacy.o corelow.o core-aout.o core-regset.o i386-nat.o i387-nat.o i386bsd-nat.o i386fbsd-nat.o
 XM_FILE= xm-fbsd.h
 NAT_FILE= nm-fbsd.h
--- /dev/null	Thu Feb 19 16:30:24 1998
+++ i386fbsd-nat.c	Sat Jul 21 14:33:58 2001
@@ -0,0 +1,102 @@
+/* Native-dependent code for FreeBSD/i386.
+   Copyright 2001 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   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 "defs.h"
+#include "inferior.h"
+#include "regcache.h"
+
+#include <sys/types.h>
+#include <sys/ptrace.h>
+#include <sys/sysctl.h>
+
+/* Prevent warning from -Wmissing-prototypes.  */
+void _initialize_i386fbsd_nat (void);
+
+/* Resume execution of the inferior process.
+   If STEP is nonzero, single-step it.
+   If SIGNAL is nonzero, give it that signal.  */
+
+void
+child_resume (ptid_t ptid, int step, enum target_signal signal)
+{
+  pid_t pid = ptid_get_pid (ptid);
+  int request = PT_STEP;
+
+  if (pid == -1)
+    /* Resume all threads.  This only gets used in the non-threaded
+       case, where "resume all threads" and "resume inferior_ptid" are
+       the same.  */
+    pid = ptid_get_pid (inferior_ptid);
+
+  if (!step)
+    {
+      unsigned int eflags;
+
+      /* Workaround for a bug in FreeBSD.  Make sure that the trace
+ 	 flag is off when doing a continue.  There is a code path
+ 	 through the kernel which leaves the flag set when it should
+ 	 have been cleared.  If a process has a signal pending (such
+ 	 as SIGALRM) and we do a PT_STEP, the process never really has
+ 	 a chance to run because the kernel needs to notify the
+ 	 debugger that a signal is being sent.  Therefore, the process
+ 	 never goes through the kernel's trap() function which would
+ 	 normally clear it.  */
+
+      eflags = read_register (PS_REGNUM);
+      if (eflags & 0x0100)
+	write_register (PS_REGNUM, eflags & ~0x0100);
+
+      request = PT_CONTINUE;
+    }
+
+  /* An addres of (caddr_t) 1 tells ptrace to continue from where it
+     was.  (If GDB wanted it to start some other way, we have already
+     written a new PC value to the child.)  */
+  if (ptrace (request, pid, (caddr_t) 1,
+	      target_signal_to_host (signal)) == -1)
+    perror_with_name ("ptrace");
+}
+
+void
+_initialize_i386fbsd_nat (void)
+{
+  /* FreeBSD provides a kern.ps_strings sysctl that we can use to
+     locate the sigtramp.  That way we can still recognize a sigtramp
+     if it's 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.  */
+#ifdef KERN_PS_STRINGS
+  {
+    int mib[2];
+    int ps_strings;
+    size_t len;
+
+    mib[0] = CTL_KERN;
+    mib[1] = KERN_PS_STRINGS;
+    len = sizeof (ps_strings);
+    if (sysctl (mib, 2, &ps_strings, &len, NULL, 0) == 0)
+      {
+	i386bsd_sigtramp_start = ps_strings - 128;
+	i386bsd_sigtramp_end = ps_strings;
+      }
+  }
+#endif
+}



More information about the Gdb-patches mailing list