[Kaffe] new stack trace patch.

Moses DeJong dejong at cs.umn.edu
Fri Feb 5 19:11:51 PST 1999


Ok, I have been working on the stack trace printing and I think
I have a good patch now. Here is an example class that shows
the problem with the current copy of kaffe. My patch fixes the
'/' in the class name problem and it does not print exception
constructor names in the stack trace.

later
mo dejong
dejong at cs.umn.edu


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 {

	// Throwable -> Exception -> IOException -> EOFException

	throw new java.io.EOFException();
    }
}

/*
JDK output

% java ExceptionFile
java.io.EOFException
        at SomeClass.foo(ExceptionFile.java:23)
        at SomeClass.run(ExceptionFile.java:13)
        at java.lang.Thread.run(Thread.java)

*/


/*
Kaffe output

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

*/


/*
Kaffe output with my patch

% kaffe ExceptionFile
java.io.EOFException
        at SomeClass.foo(ExceptionFile.java:23)
        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/06 04:09:54
@@ -99,6 +99,8 @@
 	int j;
 	Hjava_lang_Object* str;
 	jchar* cptr;
+	char * class_dot_name, * tmp;
+	Hjava_lang_Class * javaLangThrowableClass = NULL;
 
 	info = (stackTraceInfo*)unhand(o)->backtrace;
 	if (info == 0) {
@@ -107,7 +109,19 @@
 	for (i = 0; info[i].meth != ENDOFSTACK; i++) {
 		pc = info[i].pc;
 		meth = stacktraceFindMethod(&info[i]);
-		if (meth != 0) {
+		
+		/* The first method we come across is the constructor
+                   for the java.lang.Throwable class */
+
+		if (meth != NULL && javaLangThrowableClass == NULL) {
+		    javaLangThrowableClass = meth->class;
+		}
+
+		/* don't print constructors derived from Throwable */
+
+		if (meth != NULL &&
+		    !(METHOD_IS_CONSTRUCTOR(meth) &&
+		      instanceof(javaLangThrowableClass,meth->class))) {
 			linepc = 0;
 			linenr = -1;
 			if (meth->lines != 0) {
@@ -118,20 +132,34 @@
 					}
 				}
 			}
+			
+			tmp = CLASS_CNAME(meth->class);
+			class_dot_name = KMALLOC(strlen(tmp) + 1);
+			strcpy(class_dot_name,tmp);
+			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);
 			}
+			KFREE(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