View Javadoc

1   // Throwable.java, created Fri Aug 16 18:11:49 2002 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.ClassLib.sun14_linux.java.lang;
5   
6   import joeq.Allocator.CodeAllocator;
7   import joeq.Class.jq_CompiledCode;
8   import joeq.Class.jq_Method;
9   import joeq.Memory.CodeAddress;
10  import joeq.Runtime.ExceptionDeliverer;
11  import joeq.UTF.Utf8;
12  
13  /***
14   * Throwable
15   *
16   * @author  John Whaley <jwhaley@alum.mit.edu>
17   * @version $Id: Throwable.java 1744 2004-05-07 08:11:01Z joewhaley $
18   */
19  public abstract class Throwable {
20      
21      private java.lang.Object backtrace;
22      
23      // native method implementations
24      private int getStackTraceDepth() {
25          ExceptionDeliverer.StackFrame backtrace = (ExceptionDeliverer.StackFrame)this.backtrace;
26          int i=-1;
27          while (backtrace != null) { backtrace = backtrace.getNext(); ++i; }
28          if (i == -1) i = 0;
29          return i;
30      }
31      
32      private StackTraceElement getStackTraceElement(int i) {
33          ExceptionDeliverer.StackFrame backtrace = (ExceptionDeliverer.StackFrame)this.backtrace;
34          while (--i >= 0) { backtrace = backtrace.getNext(); }
35          java.lang.String declaringClass = "";
36          java.lang.String methodName = "";
37          java.lang.String fileName = null;
38          int lineNumber = -2;
39          CodeAddress ip = backtrace.getIP();
40          jq_CompiledCode cc = CodeAllocator.getCodeContaining(ip);
41          if (cc != null) {
42              jq_Method m = cc.getMethod();
43              if (m != null) {
44                  declaringClass = m.getDeclaringClass().getJDKName();
45                  methodName = m.getName().toString();
46                  //int code_offset = ip.difference(cc.getStart());
47                  Utf8 fn = m.getDeclaringClass().getSourceFile();
48                  if (fn != null) fileName = fn.toString();
49                  int bc_index = cc.getBytecodeIndex(ip);
50                  lineNumber = m.getLineNumber(bc_index);
51              }
52          }
53          return new StackTraceElement(declaringClass, methodName, fileName, lineNumber);
54      }
55  
56      public java.lang.Throwable fillInStackTrace() {
57          this.backtrace = ExceptionDeliverer.getStackTrace();
58          java.lang.Object o = this;
59          return (java.lang.Throwable)o;
60      }
61  
62      public java.lang.Object getBacktraceObject() { return this.backtrace; }
63  }