This is the mail archive of the
frysk@sources.redhat.com
mailing list for the frysk project.
Patch: fix up Syscall a bit
- From: Tom Tromey <tromey at redhat dot com>
- To: Frysk Hackers <frysk at sourceware dot org>
- Date: 16 Sep 2006 17:42:40 -0600
- Subject: Patch: fix up Syscall a bit
- Reply-to: tromey at redhat dot com
This patch fixes a few bugs in the new Syscall code:
* The unknownSyscalls hash maps were not created properly, so unknown
syscall objects would not be properly cached. I fixed this in the
simplest way, by initializing the fields in Linux*.java; it could
also be done a bit more lazily in the accessors, if desired.
* I made iterateSyscallByName be package-private. There's no reason
for this to be public, it is just a random utility method.
* I changed a couple places to catch TaskException instead of
Exception -- over-catching exceptions is mildly ugly. I changed
these same places to do exception chaining; chaining is a best
practice that enables better debugging in the field.
* I changed a couple places to avoid a redundant Integer.toString when
using the String "+" operator.
There were no test suite regressions on x86 FC5... there was one
failure but I backed out my patch and I observed it with an unmodified
tree.
Ok?
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* LinuxX8664Syscall.java (unknownSyscalls): Initialize.
* LinuxPPC.java (unknownSyscalls): Initialize.
* LinuxPPC64.java (unknownSyscalls): Initialize.
* LinuxPowerPCSyscall.java (unknownSyscalls): Initialize.
* LinuxIa32Syscall.java (unknownSyscalls): Initialize.
* LinuxEMT64.java (unknownSyscalls): Initialize.
* Syscall.java (syscallByName): Chain exceptions. Don't "over
catch".
(iterateSyscallByName): Now package-private.
(syscallByNum): Removed redundant toString. Chain exceptions.
Removed dead code. Synchronize on hash map.
Index: LinuxEMT64.java
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/proc/LinuxEMT64.java,v
retrieving revision 1.3
diff -u -r1.3 LinuxEMT64.java
--- LinuxEMT64.java 14 Sep 2006 05:58:58 -0000 1.3
+++ LinuxEMT64.java 16 Sep 2006 23:44:49 -0000
@@ -54,7 +54,7 @@
// This is used to keep track of syscalls whose number we do not
// know.
- static HashMap unknownSyscalls;
+ static HashMap unknownSyscalls = new HashMap();
private SyscallEventInfo info;
Index: LinuxIa32Syscall.java
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/proc/LinuxIa32Syscall.java,v
retrieving revision 1.1
diff -u -r1.1 LinuxIa32Syscall.java
--- LinuxIa32Syscall.java 14 Sep 2006 05:58:58 -0000 1.1
+++ LinuxIa32Syscall.java 16 Sep 2006 23:44:49 -0000
@@ -48,7 +48,7 @@
// This is used to keep track of syscalls whose number we do not
// know.
- static HashMap unknownSyscalls;
+ static HashMap unknownSyscalls = new HashMap();
static class Ia32Syscall
extends Syscall
Index: LinuxPPC.java
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/proc/LinuxPPC.java,v
retrieving revision 1.5
diff -u -r1.5 LinuxPPC.java
--- LinuxPPC.java 14 Sep 2006 05:58:58 -0000 1.5
+++ LinuxPPC.java 16 Sep 2006 23:44:49 -0000
@@ -22,7 +22,7 @@
// This is used to keep track of syscalls whose number we do not
// know.
- static HashMap unknownSyscalls;
+ static HashMap unknownSyscalls = new HashMap();
private SyscallEventInfo info;
Index: LinuxPPC64.java
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/proc/LinuxPPC64.java,v
retrieving revision 1.5
diff -u -r1.5 LinuxPPC64.java
--- LinuxPPC64.java 14 Sep 2006 05:58:58 -0000 1.5
+++ LinuxPPC64.java 16 Sep 2006 23:44:49 -0000
@@ -21,7 +21,7 @@
// This is used to keep track of syscalls whose number we do not
// know.
- static HashMap unknownSyscalls;
+ static HashMap unknownSyscalls = new HashMap();
private SyscallEventInfo info;
public SyscallEventInfo getSyscallEventInfo ()
Index: LinuxPowerPCSyscall.java
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/proc/LinuxPowerPCSyscall.java,v
retrieving revision 1.1
diff -u -r1.1 LinuxPowerPCSyscall.java
--- LinuxPowerPCSyscall.java 14 Sep 2006 05:58:58 -0000 1.1
+++ LinuxPowerPCSyscall.java 16 Sep 2006 23:44:50 -0000
@@ -48,7 +48,7 @@
// This is used to keep track of syscalls whose number we do not
// know.
- static HashMap unknownSyscalls;
+ static HashMap unknownSyscalls = new HashMap();
static class PowerPCSyscall
extends Syscall
Index: LinuxX8664Syscall.java
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/proc/LinuxX8664Syscall.java,v
retrieving revision 1.1
diff -u -r1.1 LinuxX8664Syscall.java
--- LinuxX8664Syscall.java 14 Sep 2006 05:58:58 -0000 1.1
+++ LinuxX8664Syscall.java 16 Sep 2006 23:44:50 -0000
@@ -46,7 +46,7 @@
// This is used to keep track of syscalls whose number we do not
// know.
- static HashMap unknownSyscalls;
+ static HashMap unknownSyscalls = new HashMap();
static class X8664Syscall
extends Syscall
Index: Syscall.java
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/proc/Syscall.java,v
retrieving revision 1.13
diff -u -r1.13 Syscall.java
--- Syscall.java 14 Sep 2006 05:58:58 -0000 1.13
+++ Syscall.java 16 Sep 2006 23:44:50 -0000
@@ -63,6 +63,7 @@
this.argList = argList;
this.noreturn = noreturn;
}
+
Syscall (String name, int number, int numArgs, String argList)
{
this.name = name;
@@ -230,7 +231,7 @@
* @param syscallList system calls list
* @return the Syscall object, or null
*/
- public static Syscall iterateSyscallByName (String name, Syscall[] syscallList)
+ static Syscall iterateSyscallByName (String name, Syscall[] syscallList)
{
for (int i = 0; i < syscallList.length; ++i)
if (name.equals(syscallList[i].name))
@@ -243,8 +244,8 @@
* Syscall object. Note that system call numbers are platform
* dependent. This will return a Syscall object in all cases; if
* there is no predefined system call with the given number, a unique
- * "unknown" system call with the indicated number will be saved in
- * unknownSyscalls.
+ * "unknown" system call with the indicated number will be created.
+ *
* @param num the number of the system call
* @param task the current task
* @return the Syscall object
@@ -259,24 +260,21 @@
syscallList = task.getIsa().getSyscallList ();
unknownSyscalls = task.getIsa().getUnknownSyscalls ();
}
- catch (Exception e)
+ catch (TaskException e)
{
- throw new RuntimeException ("Could not get the isa");
+ throw new RuntimeException ("Could not get the isa", e);
}
if (num < 0)
{
- throw new RuntimeException ("Negative Syscall Number:" +
- Integer.toString(num));
+ throw new RuntimeException ("Negative syscall number: " + num);
}
else if (num >= syscallList.length)
{
- synchronized (Syscall.class)
+ synchronized (unknownSyscalls)
{
Integer key = new Integer(num);
- if (unknownSyscalls == null)
- unknownSyscalls = new HashMap();
- else if (unknownSyscalls.containsKey(key))
+ if (unknownSyscalls.containsKey(key))
return (Syscall) unknownSyscalls.get(key);
class UnknownSyscall
@@ -296,8 +294,7 @@
return 0;
}
}
- Syscall result = new UnknownSyscall("UNKNOWN SYSCALL "
- + Integer.toString(num), num);
+ Syscall result = new UnknownSyscall("UNKNOWN SYSCALL " + num, num);
unknownSyscalls.put(key, result);
@@ -327,9 +324,9 @@
{
syscall = task.getIsa().syscallByName(name);
}
- catch (Exception e)
+ catch (TaskException e)
{
- throw new RuntimeException ("Could not get the name of isa");
+ throw new RuntimeException ("Could not get the name of isa", e);
}
return syscall;