[SCM] master: cni/Errno.cxx (vajprintf): Throw a runtime exception when things fail.

cagney@sourceware.org cagney@sourceware.org
Thu Nov 15 23:49:00 GMT 2007


The branch, master has been updated
       via  d446c71317b65455e9baf4f4b321680170e6b847 (commit)
       via  e9575e7376838347fec56e7551cc2560f93073f8 (commit)
       via  26b9fd263f24c4998cabc52dbab8c3cd58ad7633 (commit)
      from  ccaef1c5b11c27ff856ce48f943b69fee0340e55 (commit)

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

- Log -----------------------------------------------------------------
commit d446c71317b65455e9baf4f4b321680170e6b847
Author: Andrew Cagney <cagney@redhat.com>
Date:   Thu Nov 15 18:41:44 2007 -0500

    cni/Errno.cxx (vajprintf): Throw a runtime exception when things fail.

commit e9575e7376838347fec56e7551cc2560f93073f8
Author: Andrew Cagney <cagney@redhat.com>
Date:   Thu Nov 15 18:24:46 2007 -0500

    Have Errno set the parent's message; so getMessage() works.
    
    frysk-sys/frysk/sys/ChangeLog
    2007-11-15  Andrew Cagney  <cagney@redhat.com>
    
    	* Errno.java (Errno()): Delete.
    	(Eio): New.
    	(toString()): Delete.
    	(message): Delete.
    	(Errno(String)): Pass reason to super-class.
    	* cni/Errno.cxx (throwErrno): Update.

commit 26b9fd263f24c4998cabc52dbab8c3cd58ad7633
Author: Andrew Cagney <cagney@redhat.com>
Date:   Thu Nov 15 17:54:59 2007 -0500

    Use [new] CLI.printError to report runtime exceptions.
    
    frysk-core/frysk/hpd/ChangeLog
    2007-11-15  Andrew Cagney  <cagney@redhat.com>
    
    	* PlocationCommand.java: Use CLI.printError(Exception).
    	* EvalCommands.java: Ditto.
    	* CLI.java (printError(Exception)): New.
    	(nasty(Exception)): New.
    	(doAttach()): Throw a RuntimeException when there
    	(execCommand(String)): Pass RuntimeExceptions to printError.
    	(commplete(String,int,List)): Print "nasty" exceptions.
    	* Message.java (Message): Remove constructor that takes a possible
    	exception cause.
    	(getException): Delete.
    	* CLI.java (addMessage): Delete variant that takes a possible
    	exception cause.
    	(flushMessages): Do not print exception cause if present.
    	* TestPlocationCommand.java (testPlocationFails()): Mark as
    	unresolved, 5345.

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

Summary of changes:
 frysk-core/frysk/hpd/CLI.java                  |   51 +++++++++++++++---------
 frysk-core/frysk/hpd/ChangeLog                 |   18 ++++++++
 frysk-core/frysk/hpd/EvalCommands.java         |    8 +--
 frysk-core/frysk/hpd/Message.java              |   33 +--------------
 frysk-core/frysk/hpd/PlocationCommand.java     |   11 +----
 frysk-core/frysk/hpd/TestPlocationCommand.java |    2 +
 frysk-sys/frysk/sys/ChangeLog                  |   10 +++++
 frysk-sys/frysk/sys/Errno.java                 |   25 +++++-------
 frysk-sys/frysk/sys/cni/Errno.cxx              |   11 ++++-
 9 files changed, 88 insertions(+), 81 deletions(-)

First 500 lines of diff:
diff --git a/frysk-core/frysk/hpd/CLI.java b/frysk-core/frysk/hpd/CLI.java
index d79e557..d7fcf07 100644
--- a/frysk-core/frysk/hpd/CLI.java
+++ b/frysk-core/frysk/hpd/CLI.java
@@ -123,8 +123,9 @@ public class CLI {
 	    return topLevelCommand.complete(this, new Input(buffer), cursor,
 					    candidates);
 	} catch (RuntimeException e) {
-	    // XXX - FIXME - What if this is something fatal?
-	    return -1;
+	    if (nasty(e))
+		e.printStackTrace(outWriter);
+	    return -1;		
 	}
     }
 
@@ -143,8 +144,7 @@ public class CLI {
 	    outWriter.print("Attached to process ");
 	    outWriter.println(attached);
         } catch (InterruptedException ie) {
-            addMessage("Attach interrupted.", Message.TYPE_ERROR, ie);
-            return;
+	    throw new RuntimeException("attachLatch interrupted");
         } finally {
             synchronized (this) {
                 attached = -1;
@@ -254,20 +254,41 @@ public class CLI {
 		    topLevelCommand.interpret(this, command);
                 }
             }
-            catch (InvalidCommandException ice) {
-                addMessage(ice.getMessage(), Message.TYPE_ERROR);
-	    }
             catch (RuntimeException e) {
-                String msg = e.getMessage();
-                if (msg == null || msg.equals(""))
-                    msg = e.toString();
-                addMessage(msg, Message.TYPE_DBG_ERROR, e);
+		printError(e);
             }
             flushMessages();
         }
         return null;
     }
 
+    /**
+     * Identify "nasty", or internal exceptions; these are the
+     * RuntimeExceptions thrown by the Java system.
+     */
+    private boolean nasty(Exception e) {
+	Throwable cause = e;
+	while (true) {
+	    Throwable c = cause.getCause();
+	    if (c == null)
+		break;
+	    cause = c;
+	}
+	return (cause instanceof NullPointerException
+		|| e.getMessage() == null);
+    }
+
+    void printError(Exception e) {
+	if (nasty(e)) {
+	    outWriter.print("Internal Error: ");
+	    e.printStackTrace(outWriter);
+	    outWriter.println();
+	} else {
+	    outWriter.print("Error: ");
+	    outWriter.println(e.getMessage());
+	}
+    }
+
     void addMessage(Message msg) {
         messages.add(msg);
     }
@@ -276,10 +297,6 @@ public class CLI {
         addMessage(new Message(msg, type));
     }
 
-    void addMessage(String msg, int type, Throwable exc) {
-        addMessage(new Message(msg, type, exc));
-    }
-
     private void flushMessages() {
         for (Iterator iter = messages.iterator(); iter.hasNext();) {
             Message tempmsg = (Message) iter.next();
@@ -293,12 +310,8 @@ public class CLI {
             if (prefix != null)
                 outWriter.print(prefix);
             outWriter.println(tempmsg.getMessage());
-	    Throwable exc = tempmsg.getException();
-	    if (exc != null)
-		exc.printStackTrace(outWriter);
             iter.remove();
         }
-	outWriter.flush();
     }
 
     PTSet createSet(String set) {
diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog
index 766529a..0f67675 100644
--- a/frysk-core/frysk/hpd/ChangeLog
+++ b/frysk-core/frysk/hpd/ChangeLog
@@ -6,6 +6,24 @@
 
 2007-11-15  Andrew Cagney  <cagney@redhat.com>
 
+	* PlocationCommand.java: Use CLI.printError(Exception).
+	* EvalCommands.java: Ditto.
+	* CLI.java (printError(Exception)): New.
+	(nasty(Exception)): New.
+	(doAttach()): Throw a RuntimeException when there
+	(execCommand(String)): Pass RuntimeExceptions to printError.
+	(commplete(String,int,List)): Print "nasty" exceptions.
+	* Message.java (Message): Remove constructor that takes a possible
+	exception cause.
+	(getException): Delete.
+	* CLI.java (addMessage): Delete variant that takes a possible
+	exception cause.
+	(flushMessages): Do not print exception cause if present.
+	* TestPlocationCommand.java (testPlocationFails()): Mark as
+	unresolved, 5345.
+
+2007-11-15  Andrew Cagney  <cagney@redhat.com>
+
 	* TestListCommand.java (testListPC()): Mark as unresolved, 5332.
 	(testListFunction()): Mark as unresolved, 5333.
 
diff --git a/frysk-core/frysk/hpd/EvalCommands.java b/frysk-core/frysk/hpd/EvalCommands.java
index 3514cdc..ada61ce 100644
--- a/frysk-core/frysk/hpd/EvalCommands.java
+++ b/frysk-core/frysk/hpd/EvalCommands.java
@@ -94,11 +94,9 @@ abstract class EvalCommands extends ParameterizedCommand {
 	    }
 	    try {
 		result = cli.parseValue(task, expression, options.dumpTree);
-	    } catch (RuntimeException nnfe) {
-		String msg = nnfe.getMessage();
-		if (msg == null || msg.equals(""))
-		    msg = nnfe.toString();
-		cli.addMessage(msg, Message.TYPE_ERROR, nnfe);
+	    } catch (RuntimeException e) {
+		cli.outWriter.println();
+		cli.printError(e);
 		continue;
 	    }
 
diff --git a/frysk-core/frysk/hpd/Message.java b/frysk-core/frysk/hpd/Message.java
index aeb4ed2..933305f 100644
--- a/frysk-core/frysk/hpd/Message.java
+++ b/frysk-core/frysk/hpd/Message.java
@@ -49,39 +49,17 @@ class Message
 	public static int TYPE_NORMAL = 3;
 	public static int TYPE_VERBOSE = 4;
 
-	private final String msg;
-	private final int type;
-        private final Throwable exc;
+	String msg = null;
+	int type = 0;
 
-        /**
-	 * Creates a new Message with the given message and type
-	 * and no exception.
-	 */
-        public Message (String msg, int type)
-        {
-	    this(msg, type, null);
-	}  
-        /**
-	 * Creates a new Message with the given message and type.
-	 * The message cannot be null or empty. The exception is optional
-	 * and may be null.
-	 */
-        public Message (String msg, int type, Throwable exc)
+	public Message (String msg, int type)
 	{
-	        if (msg == null)
-		    throw new NullPointerException("null msg");
-
-	        if (msg.equals(""))
-		    throw new IllegalArgumentException("empty msg");
-
 		this.msg = msg;
 
 		if (type < TYPE_DBG_ERROR || type > TYPE_VERBOSE)
 			throw new IllegalArgumentException("Debugger message created with illegal type.");
 		else
 			this.type = type;
-
-		this.exc = exc;
 	}
 
 	public String getMessage()
@@ -93,9 +71,4 @@ class Message
 	{
 		return type;
 	}
-
-        public Throwable getException()
-        {
-	        return exc;
-        }
 }
diff --git a/frysk-core/frysk/hpd/PlocationCommand.java b/frysk-core/frysk/hpd/PlocationCommand.java
index a40de00..5739c77 100644
--- a/frysk-core/frysk/hpd/PlocationCommand.java
+++ b/frysk-core/frysk/hpd/PlocationCommand.java
@@ -76,20 +76,13 @@ class PlocationCommand extends ParameterizedCommand {
             doWithoutTask = false;
             try {
                 result = cli.parseValue(task, sInput);	  
-            } catch (RuntimeException nnfe) {
-		String msg = nnfe.getMessage();
-		if (msg == null || msg.equals(""))
-		    msg = nnfe.toString();
-                cli.addMessage(msg, Message.TYPE_ERROR, nnfe);
+            } catch (RuntimeException e) {
+		cli.printError(e);
                 continue;
             }
 	    result.getLocation().toPrint(cli.outWriter);
 	    cli.outWriter.println();
         }
-        if (result == null) {
-            cli.addMessage("Symbol \"" + sInput + "\" is not found in the current context.",
-                           Message.TYPE_ERROR);
-        }
     }
 
     int completer(CLI cli, Input input, int cursor, List completions) {
diff --git a/frysk-core/frysk/hpd/TestPlocationCommand.java b/frysk-core/frysk/hpd/TestPlocationCommand.java
index 239777c..4cfb410 100644
--- a/frysk-core/frysk/hpd/TestPlocationCommand.java
+++ b/frysk-core/frysk/hpd/TestPlocationCommand.java
@@ -56,6 +56,8 @@ public class TestPlocationCommand
     }
     
     public void testPlocationFails() {
+	if (unresolved(5345))
+	    return;
 	e = HpdTestbed.attachXXX("hpd-c");
 	e.sendCommandExpectPrompt("plocation bogus\n", 
 		                  "\r\nError: Symbol \"bogus\" is not found in the current context..*");
diff --git a/frysk-sys/frysk/sys/ChangeLog b/frysk-sys/frysk/sys/ChangeLog
index 8a8d0dd..fcea6d1 100644
--- a/frysk-sys/frysk/sys/ChangeLog
+++ b/frysk-sys/frysk/sys/ChangeLog
@@ -1,3 +1,13 @@
+2007-11-15  Andrew Cagney  <cagney@redhat.com>
+
+	* Errno.java (Errno()): Delete.
+	(Eio): New.
+	(toString()): Delete.
+	(message): Delete.
+	(Errno(String)): Pass reason to super-class.
+	* cni/Errno.cxx (throwErrno): Update.
+	(vajprintf): Throw a runtime exception when things fail.
+
 2007-10-30  Andrew Cagney  <cagney@redhat.com>
 
 	* SyscallNum.java-sh: Rename SyscallNum.shjava.
diff --git a/frysk-sys/frysk/sys/Errno.java b/frysk-sys/frysk/sys/Errno.java
index f809f1b..9390d10 100644
--- a/frysk-sys/frysk/sys/Errno.java
+++ b/frysk-sys/frysk/sys/Errno.java
@@ -48,6 +48,10 @@ public class Errno
 {
     private static final long serialVersionUID = 1L;
 
+    protected Errno (String message) {
+	super(message);
+    }
+
     /**
      * Bad file descriptor.
      */
@@ -140,22 +144,13 @@ public class Errno
     }
 
     /**
-     * Returns the error message string for this error.
+     * Input/Output Error.
      */
-    public String toString ()
-    {
-	return message;
-    }
-    private String message;
-
-    protected Errno (String message)
-    {
-	this.message = message;
-    }
-
-    protected Errno ()
-    {
-	this.message = "internal error";
+    static public class Eio extends Errno {
+        private static final long serialVersionUID = 1L;
+	protected Eio (String message) {
+	    super (message);
+	}
     }
 
     static native void throwErrno (int err, String prefix);
diff --git a/frysk-sys/frysk/sys/cni/Errno.cxx b/frysk-sys/frysk/sys/cni/Errno.cxx
index 17f0617..4a06340 100644
--- a/frysk-sys/frysk/sys/cni/Errno.cxx
+++ b/frysk-sys/frysk/sys/cni/Errno.cxx
@@ -1,7 +1,7 @@
 // This file is part of the program FRYSK.
 //
-// Copyright 2007 Oracle Corporation.
 // Copyright 2005, 2006, 2007, Red Hat Inc.
+// Copyright 2007 Oracle Corporation.
 //
 // FRYSK is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by
@@ -60,6 +60,7 @@
 #include "frysk/sys/Errno$Echild.h"
 #include "frysk/sys/Errno$Esrch.h"
 #include "frysk/sys/Errno$Eperm.h"
+#include "frysk/sys/Errno$Eio.h"
 #include "frysk/sys/cni/Errno.hxx"
 
 /**
@@ -83,11 +84,11 @@ vajprintf (const char *fmt, va_list ap)
 {
   char* message = NULL;
   if (::vasprintf (&message, fmt, ap) < 0)
-    throw new frysk::sys::Errno ();      
+    throwRuntimeException("vasprintf failed");      
   jstring jmessage = JvNewStringUTF (message);  
   ::free (message);  
   if (jmessage == NULL)
-  	throwRuntimeException("JvNewStringUTF failed in vajprintf");  
+    throwRuntimeException("JvNewStringUTF failed in vajprintf");  
   return jmessage;
 }
 
@@ -127,6 +128,10 @@ throwErrno (int err, jstring jmessage)
   case EPERM:
     throw new frysk::sys::Errno$Eperm (jmessage);
 #endif
+#ifdef EIO
+  case EIO:
+    throw new frysk::sys::Errno$Eio (jmessage);
+#endif
   default:
     throw new frysk::sys::Errno (jmessage);
   }


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



More information about the Frysk-cvs mailing list