aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/lang
diff options
context:
space:
mode:
authorAndrew Haley <aph@cygnus.com>2000-02-04 16:59:35 +0000
committerAndrew Haley <aph@gcc.gnu.org>2000-02-04 16:59:35 +0000
commit43c5c8a630d2013b170215480dc14d5d833aa8bc (patch)
tree9730aa76749e0192dde76a1efdcd1b9731ef2de4 /libjava/java/lang
parent8760eaae3c4596dc5156c898a8a33a3ab01b6671 (diff)
downloadgcc-43c5c8a630d2013b170215480dc14d5d833aa8bc.zip
gcc-43c5c8a630d2013b170215480dc14d5d833aa8bc.tar.gz
gcc-43c5c8a630d2013b170215480dc14d5d833aa8bc.tar.bz2
Throwable.java (CPlusPlusDemangler): New class.
2000-02-04 Andrew Haley <aph@cygnus.com> * java/lang/Throwable.java (CPlusPlusDemangler): New class. (printStackTrace): Use a CPlusPlusDemangler to demangle names. * java/lang/natThrowable.cc (printRawStackTrace): Rename printStackTrace to printRawStackTrace. From-SVN: r31785
Diffstat (limited to 'libjava/java/lang')
-rw-r--r--libjava/java/lang/Throwable.java92
-rw-r--r--libjava/java/lang/natThrowable.cc4
2 files changed, 90 insertions, 6 deletions
diff --git a/libjava/java/lang/Throwable.java b/libjava/java/lang/Throwable.java
index e857f06..9a64597 100644
--- a/libjava/java/lang/Throwable.java
+++ b/libjava/java/lang/Throwable.java
@@ -13,6 +13,9 @@ import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.Serializable;
import java.io.OutputStreamWriter;
+import java.io.OutputStream;
+import java.io.FilterOutputStream;
+import java.io.IOException;
/**
* @author Tom Tromey <tromey@cygnus.com>
@@ -25,6 +28,69 @@ import java.io.OutputStreamWriter;
* bytecode not implemented. JDK 1.1.
*/
+/* A CPlusPlusDemangler sits on top of a PrintWriter. All input is
+ * passed through the "c++filt" program (part of GNU binutils) which
+ * demangles internal symbols to their C++ source form.
+ *
+ * Closing a CPlusPlusDemangler doesn't close the underlying
+ * PrintWriter; it does, however close underlying process and flush
+ * all its buffers, so it's possible to guarantee that after a
+ * CPlusPlusDemangler has been closed no more will ever be written to
+ * the underlying PrintWriter.
+ *
+ * FIXME: This implictly converts data from the input stream, which is
+ * a stream of characters, to a stream of bytes. We need a way of
+ * handling Unicode characters in demangled identifiers. */
+
+class CPlusPlusDemangler extends OutputStream
+{
+ java.io.OutputStream procOut;
+ java.io.InputStream procIn;
+ java.lang.Process proc;
+ PrintWriter p;
+
+ /* The number of bytes written to the underlying PrintWriter. This
+ provides a crude but fairly portable way to determine whether or
+ not the attempt to exec c++filt worked. */
+ public int written = 0;
+
+ CPlusPlusDemangler (PrintWriter writer) throws IOException
+ {
+ p = writer;
+ proc = Runtime.getRuntime ().exec ("c++filt");
+ procOut = proc.getOutputStream ();
+ procIn = proc.getInputStream ();
+ }
+
+ public void write (int b) throws IOException
+ {
+ procOut.write (b);
+ while (procIn.available () != 0)
+ {
+ int c = procIn.read ();
+ if (c == -1)
+ break;
+ else
+ {
+ p.write (c);
+ written++;
+ }
+ }
+ }
+
+ public void close () throws IOException
+ {
+ procOut.close ();
+ int c;
+ while ((c = procIn.read ()) != -1)
+ {
+ p.write (c);
+ written++;
+ }
+ p.flush ();
+ }
+}
+
public class Throwable implements Serializable
{
public native Throwable fillInStackTrace ();
@@ -46,11 +112,27 @@ public class Throwable implements Serializable
public void printStackTrace (PrintStream ps)
{
- printStackTrace (new PrintWriter(new OutputStreamWriter(ps)));
+ PrintWriter writer = new PrintWriter (ps);
+ printStackTrace (writer);
}
-
- public native void printStackTrace (PrintWriter wr);
-
+
+ public void printStackTrace (PrintWriter wr)
+ {
+ try
+ {
+ CPlusPlusDemangler cPlusPlusFilter = new CPlusPlusDemangler (wr);
+ PrintWriter writer = new PrintWriter (cPlusPlusFilter);
+ printRawStackTrace (writer);
+ writer.close ();
+ if (cPlusPlusFilter.written == 0) // The demangler has failed...
+ printRawStackTrace (wr);
+ }
+ catch (Exception e1)
+ {
+ printRawStackTrace (wr);
+ }
+ }
+
public Throwable ()
{
detailMessage = null;
@@ -70,6 +152,8 @@ public class Throwable implements Serializable
: getClass().getName() + ": " + getMessage ());
}
+ private native final void printRawStackTrace (PrintWriter wr);
+
// Name of this field comes from serialization spec.
private String detailMessage;
diff --git a/libjava/java/lang/natThrowable.cc b/libjava/java/lang/natThrowable.cc
index 6acca3a..bbe18c2 100644
--- a/libjava/java/lang/natThrowable.cc
+++ b/libjava/java/lang/natThrowable.cc
@@ -24,6 +24,7 @@ details. */
#include <java/lang/Throwable.h>
#include <java/io/PrintStream.h>
#include <java/io/PrintWriter.h>
+#include <java/io/IOException.h>
#include <sys/types.h>
@@ -61,7 +62,7 @@ java::lang::Throwable::fillInStackTrace (void)
}
void
-java::lang::Throwable::printStackTrace (java::io::PrintWriter *wr)
+java::lang::Throwable::printRawStackTrace (java::io::PrintWriter *wr)
{
wr->println (toString ());
#ifdef HAVE_BACKTRACE
@@ -90,4 +91,3 @@ java::lang::Throwable::printStackTrace (java::io::PrintWriter *wr)
}
#endif /* HAVE_BACKTRACE */
}
-