public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
From: cagney@sourceware.org
To: frysk-cvs@sourceware.org
Subject: [SCM]  master: Generate frysk.sys.Signal (and the corresponding Signal.cxx).
Date: Mon, 21 Jan 2008 22:57:00 -0000	[thread overview]
Message-ID: <20080121225657.23938.qmail@sourceware.org> (raw)

The branch, master has been updated
       via  01e4144f085eb072e2210b4a5cb6a0e8c8d12fd6 (commit)
      from  0b4b96242bb2a9e635adb03a77145e40acf119b5 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 01e4144f085eb072e2210b4a5cb6a0e8c8d12fd6
Author: Andrew Cagney <cagney@redhat.com>
Date:   Mon Jan 21 17:55:23 2008 -0500

    Generate frysk.sys.Signal (and the corresponding Signal.cxx).
    
    frysk-common/ChangeLog
    2008-01-21  Andrew Cagney  <cagney@redhat.com>
    
    	* Makefile.rules (SUFFIXES): Fix typos. cxx-sh to .cxx-sh, ..c-in
    	to .c-in, ..java-in to .java-in.
    
    frysk-sys/frysk/sys/ChangeLog
    2008-01-21  Andrew Cagney  <cagney@redhat.com>
    
    	* TestSignal.java: New file.
    	* cni/Signal.cxx: Replace this with ...
    	* cni/Signal.cxx-sh (frysk): ... this.  New file.
    	* Signal.java: Replace this with ...
    	* Signal.java-sh: ... this.  New file.
    	* ProcessIdentifier.java (intValue()): New.

-----------------------------------------------------------------------

Summary of changes:
 frysk-common/ChangeLog                             |    5 +
 frysk-common/Makefile.rules                        |    8 +-
 frysk-sys/frysk/sys/ChangeLog                      |    9 +
 frysk-sys/frysk/sys/ProcessIdentifier.java         |    6 +-
 .../frysk/sys/{Signal.java => Signal.java-sh}      |  204 ++++++++++----------
 .../frysk/sys/TestSignal.java                      |   31 ++-
 .../frysk/sys/cni/{Signal.cxx => Signal.cxx-sh}    |   54 +++---
 7 files changed, 175 insertions(+), 142 deletions(-)
 rename frysk-sys/frysk/sys/{Signal.java => Signal.java-sh} (50%)
 copy frysk-core/frysk/testbed/TestStatState.java => frysk-sys/frysk/sys/TestSignal.java (80%)
 rename frysk-sys/frysk/sys/cni/{Signal.cxx => Signal.cxx-sh} (85%)

First 500 lines of diff:
diff --git a/frysk-common/ChangeLog b/frysk-common/ChangeLog
index acce967..81f910b 100644
--- a/frysk-common/ChangeLog
+++ b/frysk-common/ChangeLog
@@ -1,3 +1,8 @@
+2008-01-21  Andrew Cagney  <cagney@redhat.com>
+
+	* Makefile.rules (SUFFIXES): Fix typos. cxx-sh to .cxx-sh, ..c-in
+	to .c-in, ..java-in to .java-in.
+
 2008-01-17  Andrew Cagney  <cagney@redhat.com>
 
 	* Makefile.rules (.jar): Sort the .class file list.
diff --git a/frysk-common/Makefile.rules b/frysk-common/Makefile.rules
index 2087b81..13d8310 100644
--- a/frysk-common/Makefile.rules
+++ b/frysk-common/Makefile.rules
@@ -231,7 +231,7 @@ SUFFIXES += .java-sh
 	$(SHELL) $< > $*.tmp $@
 	chmod a-w $*.tmp
 	mv -f $*.tmp $@
-SUFFIXES += cxx-sh
+SUFFIXES += .cxx-sh
 .cxx-sh.cxx:
 	rm -f $*.tmp
 	mkdir -p `dirname $*`
@@ -239,7 +239,7 @@ SUFFIXES += cxx-sh
 	$(SHELL) $< > $*.tmp $@
 	chmod a-w $*.tmp
 	mv -f $*.tmp $@
-SUFFIXES += ..c-sh
+SUFFIXES += .c-sh
 .c-sh.c:
 	rm -f $*.tmp
 	mkdir -p `dirname $*`
@@ -305,13 +305,13 @@ SUBST = \
 	chmod a-w $@.tmp ; \
 	mv -f $@.tmp $@
 
-SUFFIXES += ..java-in
+SUFFIXES += .java-in
 .java-in.java:
 	$(SUBST)
 SUFFIXES += .cxx-in
 .cxx-in.cxx:
 	$(SUBST)
-SUFFIXES += ..c-in
+SUFFIXES += .c-in
 .c-in.c:
 	$(SUBST)
 TestRunner.java: common/TestRunner.java-in
diff --git a/frysk-sys/frysk/sys/ChangeLog b/frysk-sys/frysk/sys/ChangeLog
index 53c85c1..8275d0a 100644
--- a/frysk-sys/frysk/sys/ChangeLog
+++ b/frysk-sys/frysk/sys/ChangeLog
@@ -1,3 +1,12 @@
+2008-01-21  Andrew Cagney  <cagney@redhat.com>
+
+	* TestSignal.java: New file.
+	* cni/Signal.cxx: Replace this with ...
+	* cni/Signal.cxx-sh (frysk): ... this.  New file.
+	* Signal.java: Replace this with ...
+	* Signal.java-sh: ... this.  New file.
+	* ProcessIdentifier.java (intValue()): New.
+
 2008-01-17  Andrew Cagney  <cagney@redhat.com>
 
 	* Signal.java (tkill(int,int)): Make public.
diff --git a/frysk-sys/frysk/sys/ProcessIdentifier.java b/frysk-sys/frysk/sys/ProcessIdentifier.java
index 2f0489f..b7cc1df 100644
--- a/frysk-sys/frysk/sys/ProcessIdentifier.java
+++ b/frysk-sys/frysk/sys/ProcessIdentifier.java
@@ -50,10 +50,12 @@ public class ProcessIdentifier
     {
 	this.pid = pid;
     }
-    public int hashCode ()
-    {
+    public int hashCode () {
 	return pid;
     }
+    public int intValue() {
+        return pid;
+    }
     public int compareTo (Object o)
     {
 	return ((ProcessIdentifier)o).pid - this.pid;
diff --git a/frysk-sys/frysk/sys/Signal.java b/frysk-sys/frysk/sys/Signal.java-sh
similarity index 50%
rename from frysk-sys/frysk/sys/Signal.java
rename to frysk-sys/frysk/sys/Signal.java-sh
index f45e755..b1f337a 100644
--- a/frysk-sys/frysk/sys/Signal.java
+++ b/frysk-sys/frysk/sys/Signal.java-sh
@@ -1,6 +1,8 @@
+#!/bin/sh
+cat <<EOF
 // This file is part of the program FRYSK.
 //
-// Copyright 2005, 2007, Red Hat Inc.
+// Copyright 2005, 2007, 2008, Red Hat Inc.
 //
 // FRYSK is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by
@@ -36,108 +38,64 @@
 // modification, you must delete this exception statement from your
 // version and license this file solely under the GPL without
 // exception.
+EOF
 
+cat <<EOF
 package frysk.sys;
 
+import java.util.Map;
+import java.util.WeakHashMap;
+
 /**
  * Host signal handling.
  *
  * Need to use native calls to find out the current host's signal
  * values.
  */
-
 public class Signal implements Comparable {
     private final int sig;
     private final String name;
-
     private Signal(int sig, String name) {
 	this.sig = sig;
 	this.name = name;
     }
 
-    private static native int alrm();
-    public static final Signal ALRM = new Signal(alrm(), "SIGALRM");
-
-    private static native int bus();
-    public static final Signal BUS = new Signal(bus(), "SIGBUS");
-
-    private static native int chld();
-    public static final Signal CHLD = new Signal(chld(), "SIGCHLD");
-
-    private static native int cont();
-    public static final Signal CONT = new Signal(cont(), "SIGCONT");
-
-    private static native int fpe();
-    public static final Signal FPE = new Signal(fpe(), "SIGFPE");
-
-    private static native int hup();
-    public static final Signal HUP = new Signal(hup(), "SIGHUP");
-
-    private static native int ill();
-    public static final Signal ILL = new Signal(ill(), "SIGILL");
-
-    private static native int int_();
-    public static final Signal INT = new Signal(int_(), "SIGINT");
-
-    private static native int io();
-    public static final Signal IO = new Signal(io(), "SIGIO");
-
-    private static native int kill();
-    public static final Signal KILL = new Signal(kill(), "SIGKILL");
-
-    private static native int none();
-    public static final Signal NONE = new Signal(none(), "SIGNONE");
-
-    private static native int prof();
-    public static final Signal PROF = new Signal(prof(), "SIGPROF");
-
-    private static native int pwr();
-    public static final Signal PWR = new Signal(pwr(), "SIGPWR");
-
-    private static native int segv();
-    public static final Signal SEGV = new Signal(segv(), "SIGSEGV");
-
-    private static native int stop();
-    public static final Signal STOP = new Signal(stop(), "SIGSTOP");
-
-    private static native int term();
-    public static final Signal TERM = new Signal(term(), "SIGTERM");
-
-    private static native int trap();
-    public static final Signal TRAP = new Signal(trap(), "SIGTRAP");
-
-    private static native int usr1();
-    public static final Signal USR1 = new Signal(usr1(), "SIGUSR1");
-
-    private static native int usr2();
-    public static final Signal USR2 = new Signal(usr2(), "SIGUSR2");
-
-    private static native int urg();
-    public static final Signal URG = new Signal(urg(), "SIGURG");
-
-    private static native int winch();
-    public static final Signal WINCH = new Signal(winch(), "SIGWINCH");
-
+    /**
+     * Dump the signal to a string.
+     */
     public String toString() {
-	return "" + sig;
+        return Integer.toString(hashCode());
+	// return name + "(" + hashCode() + ")";
     }
 
+    /**
+     * Return the signal's numeric value as an integer.
+     */
+    public int intValue() {
+	return hashCode();
+    }
+    /**
+     * Return the signal's numeric value as a String.
+     */
+    public String stringValue() {
+        return Integer.toString(hashCode());
+    }
+    /**
+     * Return the Signal in a form suitable for printing to the user.
+     */
     public String toPrint() {
-	return name;
+        return name;
     }
 
     /**
-     * Comparison operations.
+     * Comparison operations; use hashCode() so that sub-classing can
+     * provide a scratch value.
      */
     public boolean equals(Object o) {
-	return (o instanceof Signal
-		&& ((Signal)o).sig == this.sig);
-    }
-    public boolean equals(int signum) {
-	return sig == signum;
+	return (o instanceof Signal && o.hashCode() == this.hashCode());
     }
-    public int intValue() {
-	return sig;
+    public boolean equals(int sig) {
+	return this.sig == sig;
     }
     public int hashCode() {
 	return sig;
@@ -150,9 +108,15 @@ public class Signal implements Comparable {
     /**
      * Deliver SIG to process PID.
      */
-    public final void kill(int pid) {
+    public void kill(int pid) {
 	kill(pid, sig);
     }
+    /**
+     * Deliver SIG to process PID.
+     */
+    public void kill(ProcessIdentifier pid) {
+	kill(pid.intValue(), this.sig);
+    }
     private static native void kill(int pid, int signum);
     /**
      * Deliver SIGNAL to task (or thread) LWP.
@@ -160,6 +124,12 @@ public class Signal implements Comparable {
     public final void tkill(int lwp) {
 	tkill(lwp, sig);
     }
+    /**
+     * Deliver SIGNAL to task (or thread) LWP.
+     */
+    public final void tkill(ProcessIdentifier lwp) {
+	tkill(lwp.intValue(), this.sig);
+    }
     public static native void tkill(int lwp, int signum);
 
     /**
@@ -171,30 +141,66 @@ public class Signal implements Comparable {
     }
     private static native void drain(int signum);
 
+    /**
+     * A scratch value for searching the signal table.
+     */
+    private static class ScratchSignal extends Signal {
+        ScratchSignal() {
+     	    super(0, "<scratch signal>");
+	}
+        int signum;
+        public int hashCode() {
+	    return signum;
+        }
+    }
+    private static final ScratchSignal scratchSignal = new ScratchSignal();
+    /**
+     * A map for looking up known signals; weak so that scratch
+     * signals do not accumulate.
+     */
+    private static final Map signals = new WeakHashMap();
+    /**
+     * Given an integer, return (or create) the corresponding signal.
+     */
     public static Signal valueOf(int signum) {
 	if (signum < 0)
 	    throw new NullPointerException("invalid signal: " + signum);
-	if (ALRM.equals(signum)) return ALRM;
-	if (BUS.equals(signum)) return BUS;
-	if (CONT.equals(signum)) return CONT;
-	if (CHLD.equals(signum)) return CHLD;
-	if (FPE.equals(signum)) return FPE;
-	if (HUP.equals(signum)) return HUP;
-	if (ILL.equals(signum)) return ILL;
-	if (INT.equals(signum)) return INT;
-	if (IO.equals(signum)) return IO;
-	if (KILL.equals(signum)) return KILL;
-	if (NONE.equals(signum)) return NONE;
-	if (PROF.equals(signum)) return PROF;
-	if (PWR.equals(signum)) return PWR;
-	if (SEGV.equals(signum)) return SEGV;
-	if (STOP.equals(signum)) return STOP;
-	if (TERM.equals(signum)) return TERM;
-	if (TRAP.equals(signum)) return TRAP;
-	if (USR1.equals(signum)) return USR1;
-	if (USR2.equals(signum)) return USR2;
-	if (URG.equals(signum)) return URG;
-	if (WINCH.equals(signum)) return WINCH;
-	return new Signal(signum, "???");
+        synchronized (scratchSignal) {
+            scratchSignal.signum = signum;
+	    Signal signal = (Signal)signals.get(scratchSignal);
+	    if (signal == null)
+	        return signalFactory(signum, "SIG" + signum);
+	    else
+	        return signal;
+        }
     }
+
+    /**
+     * Create a signal, also enter the signal into the signals table
+     * for later retrieval.
+     */
+    private static Signal signalFactory(int sig, String name) {
+    	if (sig >= 0) {
+            Signal signal = new Signal(sig, name);
+            signals.put(signal, signal);
+	    return signal;
+        } else
+            return null; // Return a known value?
+    }
+
+    public static final Signal NONE = signalFactory(0, "SIGNONE");
+EOF
+
+for sig in \
+  hup int_ quit ill abrt fpe kill segv pipe alrm term usr1 usr2 chld cont stop tstp ttin ttou \
+  bus poll prof sys trap urg vtalrm xcpu xfsz \
+  iot emt stkflt io cld pwr info lost winch unused
+do
+    SIG=`echo "${sig}" | tr '[a-z]' '[A-Z]' | sed 's/_$//'`
+    echo "    private static native int ${sig}();"
+    echo "    public static final Signal ${SIG} = signalFactory(${sig}(), \"SIG${SIG}\");"
+done
+
+cat <<EOF
 }
+EOF
diff --git a/frysk-core/frysk/testbed/TestStatState.java b/frysk-sys/frysk/sys/TestSignal.java
similarity index 80%
copy from frysk-core/frysk/testbed/TestStatState.java
copy to frysk-sys/frysk/sys/TestSignal.java
index 679e672..c0fc79c 100644
--- a/frysk-core/frysk/testbed/TestStatState.java
+++ b/frysk-sys/frysk/sys/TestSignal.java
@@ -37,19 +37,32 @@
 // version and license this file solely under the GPL without
 // exception.
 
-package frysk.testbed;
+package frysk.sys;
+
+import frysk.junit.TestCase;
 
 /**
- * Class for directly tracking <tt>/proc/$$/stat</tt>.
+ * Test the value of some well known signals; for each confirm that
+ * they are singleton's.
  */
 
-public class TestStatState extends TestLib {
-    public void testSleeping() {
-	Offspring daemon = SlaveOffspring.createDaemon();
-	daemon.assertIs(StatState.SLEEPING);
+public class TestSignal extends TestCase {
+
+    private void check(int val, Signal sig) {
+	assertEquals("value", val, sig.intValue());
+	assertSame("identity", sig, Signal.valueOf(val));
+    }
+
+    public void testNone() {
+	check(0, Signal.NONE);
     }
-    public void testRunToSleeping() {
-	Offspring daemon = SlaveOffspring.createDaemon();
-	daemon.assertRunUntil(StatState.SLEEPING);
+
+    public void testKill() {
+	check(9, Signal.KILL);
+    }
+
+    public void testTerm() {
+	check(15, Signal.TERM);
     }
+
 }
diff --git a/frysk-sys/frysk/sys/cni/Signal.cxx b/frysk-sys/frysk/sys/cni/Signal.cxx-sh
similarity index 85%
rename from frysk-sys/frysk/sys/cni/Signal.cxx
rename to frysk-sys/frysk/sys/cni/Signal.cxx-sh
index 4899ddc..3b44859 100644
--- a/frysk-sys/frysk/sys/cni/Signal.cxx
+++ b/frysk-sys/frysk/sys/cni/Signal.cxx-sh
@@ -1,6 +1,8 @@
+#!/bin/sh
+cat <<EOF
 // This file is part of the program FRYSK.
 //
-// Copyright 2005, 2007, Red Hat Inc.
+// Copyright 2005, 2007, 2008, Red Hat Inc.
 //
 // FRYSK is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by
@@ -36,6 +38,9 @@
 // modification, you must delete this exception statement from your
 // version and license this file solely under the GPL without
 // exception.
+EOF
+
+cat <<EOF
 
 #include <sys/types.h>
 #include <signal.h>
@@ -50,33 +55,6 @@
 #include <linux.syscall.h>
 #include <unistd.h>
 
-#define SIGVAL(sig, SIG)				\
-  jint							\
-  frysk::sys::Signal::sig() {				\
-    return (jint)(SIG);					\
-  }
-SIGVAL(alrm,SIGALRM)
-SIGVAL(bus,SIGBUS)
-SIGVAL(chld,SIGCHLD)
-SIGVAL(cont,SIGCONT)
-SIGVAL(fpe,SIGFPE)
-SIGVAL(hup,SIGHUP)
-SIGVAL(ill,SIGILL)
-SIGVAL(int_,SIGINT)
-SIGVAL(io,SIGIO)
-SIGVAL(kill,SIGKILL)
-SIGVAL(none,0)
-SIGVAL(prof,SIGPROF)
-SIGVAL(pwr,SIGPWR)
-SIGVAL(segv,SIGSEGV)
-SIGVAL(stop,SIGSTOP)
-SIGVAL(term,SIGTERM)
-SIGVAL(trap,SIGTRAP)
-SIGVAL(usr1,SIGUSR1)
-SIGVAL(usr2,SIGUSR2)
-SIGVAL(urg,SIGURG)
-SIGVAL(winch,SIGWINCH)
-
 void
 frysk::sys::Signal::tkill(jint tid, jint signum) {
   errno = 0;
@@ -110,3 +88,23 @@ frysk::sys::Signal::drain (jint signum) {
 //   printf ("After: %d (%s) pending? %s\n", signum, strsignal (signum),
 // 	  sigismember (&set, signum) ? "YES" : "NO");
 }
+
+EOF
+
+for sig in \
+  hup int_ quit ill abrt fpe kill segv pipe alrm term usr1 usr2 chld cont stop tstp ttin ttou \
+  bus poll prof sys trap urg vtalrm xcpu xfsz \
+  iot emt stkflt io cld pwr info lost winch unused
+do
+    SIG=SIG`echo "${sig}" | tr '[a-z]' '[A-Z]' | sed 's/_$//'`
+    cat <<EOF
+jint
+frysk::sys::Signal::${sig}() {
+#ifdef ${SIG}
+    return ${SIG};
+#else
+    return -1;
+#endif
+}
+EOF
+done


hooks/post-receive
--
frysk system monitor/debugger


                 reply	other threads:[~2008-01-21 22:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080121225657.23938.qmail@sourceware.org \
    --to=cagney@sourceware.org \
    --cc=frysk-cvs@sourceware.org \
    --cc=frysk@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).