[Kaffe] patch for stack trace printing.

Moses DeJong dejong at cs.umn.edu
Fri Feb 5 14:10:24 PST 1999


Hi all.


I have been looking at the exception stack trace printing
and there is still a problem with the way class names
are printed. Here is an example file and the output under
Kaffe and JDK.


public class ExceptionFile
{
    public static void main(String[] argv) throws Exception {
	SomeClass sc = new SomeClass();
	Thread t = new Thread(sc);
	t.start();
    }
}

class SomeClass implements Runnable {
    public void run() {
	try {
	    SomeClass.foo();
	} catch (Exception e) {
	    e.printStackTrace();
	}
    }

    public static void foo() throws Exception {
	throw new Exception();
    }
}







/*
JDK output

% java ExceptionFile
java.lang.Exception
        at SomeClass.foo(ExceptionFile.java:22)
        at SomeClass.run(ExceptionFile.java:15)
        at java.lang.Thread.run(Thread.java)

*/


/*
Kaffe output

% kaffe ExceptionFile
java.lang.Exception
        at java/lang/Throwable.<init>(Throwable.java:31)
        at java/lang/Exception.<init>(Exception.java:17)
        at SomeClass.foo(ExceptionFile.java:20)
        at SomeClass.run(ExceptionFile.java:13)
        at java/lang/Thread.run(Thread.java:245)

*/


/*
Kaffe output with my patch

% kaffe ExceptionFile
java.lang.Exception
        at java.lang.Throwable.<init>(Throwable.java:31)
        at java.lang.Exception.<init>(Exception.java:17)
        at SomeClass.foo(ExceptionFile.java:20)
        at SomeClass.run(ExceptionFile.java:13)
        at java.lang.Thread.run(Thread.java:245)
*/





Index: stackTrace.c
===================================================================
RCS file: /home/cvspublic/kaffe/kaffe/kaffevm/stackTrace.c,v
retrieving revision 1.8
diff -u -r1.8 stackTrace.c
--- stackTrace.c        1999/02/04 07:36:19     1.8
+++ stackTrace.c        1999/02/05 23:10:55
@@ -99,6 +99,7 @@
        int j;
        Hjava_lang_Object* str;
        jchar* cptr;
+       char * class_dot_name, * tmp;
 
        info = (stackTraceInfo*)unhand(o)->backtrace;
        if (info == 0) {
@@ -118,20 +119,32 @@
                                        }
                                }
                        }
+
+                       class_dot_name = strdup(CLASS_CNAME(meth->class));
+                       assert(class_dot_name != NULL);
+                       /* change '/' to '.' in the class name */
+                       tmp = class_dot_name;
+                       while( *tmp ) {
+                           if (*tmp == '/') {
+                               *tmp = '.';
+                           }
+                           tmp++;
+                       }
                        if (linenr == -1) {
                                sprintf(buf, "\tat %.80s.%.80s(%s:line unknown, pc %p)",
-                                       CLASS_CNAME(meth->class),
+                                       class_dot_name,
                                        meth->name->data, 
                                        CLASS_SOURCEFILE(meth->class),
                                        (void*)pc);
                        }
                        else {
                                sprintf(buf, "\tat %.80s.%.80s(%s:%d)",
-                                       CLASS_CNAME(meth->class),
+                                       class_dot_name,
                                        meth->name->data,
                                        CLASS_SOURCEFILE(meth->class),
                                        linenr);
                        }
+                       free(class_dot_name);
                        len = strlen(buf);
                        str = newArray(TYPE_CLASS(TYPE_Char), len);
                        cptr = (jchar*)OBJARRAY_DATA(str);




More information about the kaffe mailing list