namefinder.java

来自「Mac OS X 10.4.9 for x86 Source Code gcc」· Java 代码 · 共 599 行 · 第 1/2 页

JAVA
599
字号
	   (CName != null	    && (CName.equals(className)		|| CName.equals("java.lang.Throwable")		|| CName.equals("java.lang.VMThrowable"))	    && MName != null	    && (MName.startsWith(consName)		|| MName.startsWith("Throwable(")		|| MName.startsWith("fillInStackTrace("))))	  {	    last_throw = i;	    // Reset counting of unknown and internal frames.	    unknown = 0;	    internal = 0;	  }	else if (remove_unknown && CName == null 		 && (MName == null || MName.startsWith("0x")))	  unknown++;	else if (remove_internal		 && ((CName == null		      && MName != null && MName.startsWith("ffi_"))		     || (CName != null && CName.startsWith("_Jv_"))		     || (CName == null && MName != null			 && MName.startsWith("_Jv_"))))	  internal++;	else if (("java.lang.Thread".equals(CName)		  || "gnu.java.lang.MainThread".equals(CName))		 && "run()".equals(MName))	  {	    end = i;	    break;	  }      }    int begin = last_throw+1;    // Now filter out everything at the start and the end that is not part    // of the "normal" user program including any elements that are internal    // calls or have no usefull information whatsoever.    // Unless that means we filter out all info.    int nr_elements = end - begin - unknown - internal + 1;    if ((begin > 0 || end < length-1 || unknown > 0 || internal > 0)	&& nr_elements > 0)      {	stack = new StackTraceElement[nr_elements];	int pos =0;	for (int i=begin; i<=end; i++)	  {	    String MName = elements[i].getMethodName();	    String CName = elements[i].getClassName();	    if (remove_unknown && CName == null 		 && (MName == null || MName.startsWith("0x")))	      ; // Skip unknown frame	    else if (remove_internal		     && ((CName == null			  && MName != null && MName.startsWith("ffi_"))			 || (CName != null && CName.startsWith("_Jv_"))			 || (CName == null && MName != null			     && MName.startsWith("_Jv_"))))	      ; // Skip internal runtime frame	    else	      {		// Null Class or Method name in elements are not allowed.		if (MName == null || CName == null)		  {		    MName = MName == null ? "" : MName;		    CName = CName == null ? "" : CName;		    stack[pos] = newElement(elements[i].getFileName(),					    elements[i].getLineNumber(),					    CName, MName,					    elements[i].isNativeMethod());		  }		else		  stack[pos] = elements[i];		pos++;	      }	  }      }    else      stack = elements;    return stack;  }  /**   * Native helper method to create a StackTraceElement. Needed to work   * around normal Java access restrictions.   */  native static private StackTraceElement newElement(String fileName,						     int lineNumber,						     String className,						     String methName,						     boolean isNative);  /**   * Creates a StackTraceElement given a string and a filename.   * Splits the given string into the class and method part.   * The string name will be a demangled to a fully qualified java method   * string. The string file will be decomposed into a file name and possibly   * a line number. The name should never be null, but the file may be if it   * is unknown.   */  private StackTraceElement createStackTraceElement(String name, String file)  {    if (!demangle)      return newElement(file, -1, null, name, false);    String s = demangleName(name);    String methodName = s;    String className = null;    int bracket = s.indexOf('(');    if (bracket > 0)      {	int dot = s.lastIndexOf('.', bracket);	if (dot > 0)	  {	    className = s.substring(0, dot);	    methodName = s.substring(dot+1, s.length());	  }      }    String fileName = file;    int line = -1;    if (fileName != null)      {	int colon = file.lastIndexOf(':');	if (colon > 0)	  {	    fileName = file.substring(0, colon);	    try	      {		line = Integer.parseInt(file.substring(colon+1, file.length()));	      }	    catch (NumberFormatException nfe) { /* ignore */ }	  }	if (line == 0)	  line =-1;	if ("".equals(fileName) || "??".equals(fileName))	  fileName = null;	else if (fileName != null)	  {	    try	      {		fileName = new File(fileName).getCanonicalPath();	      }	    catch (IOException ioe) { /* ignore */ }	  }      }    return newElement(fileName, line, className, methodName, false);  }  /**   * Demangles the given String if possible. Returns the demangled String or   * the original string if demangling is impossible.   */  private String demangleName(String s)  {    if (cppfilt != null)    {      try	{	  cppfiltOut.write(s);	  cppfiltOut.newLine();	  cppfiltOut.flush();	  return cppfiltIn.readLine();	}      catch (IOException ioe) { cppfilt.destroy(); cppfilt = null; }    }    return s;  }  /**   * Returns human readable method name and aguments given a method type   * signature as known to the interpreter and a classname.   */  public static String demangleInterpreterMethod(String m, String cn)  {    int index = 0;    int length = m.length();    StringBuffer sb = new StringBuffer(length);    // Figure out the real method name    if (m.startsWith("<init>"))      {	String className;	int i = cn.lastIndexOf('.');	if (i < 0)	  className = cn;	else	  className = cn.substring(i + 1);	sb.append(className);	index += 7;      }    else      {	int i = m.indexOf('(');	if (i > 0)	  {	    sb.append(m.substring(0,i));	    index += i + 1;	  }      }    sb.append('(');    // Demangle the type arguments    int arrayDepth = 0;    char c = (index < length) ? m.charAt(index) : ')';    while (c != ')')      {	String type;	switch(c)	{          case 'B':            type = "byte";	    break;          case 'C':            type = "char";	    break;          case 'D':            type = "double";	    break;          case 'F':            type = "float";	    break;          case 'I':            type = "int";	    break;          case 'J':            type = "long";	    break;          case 'S':            type = "short";	    break;          case 'Z':            type = "boolean";	    break;          case 'L':	    int i = m.indexOf(';', index);	    if (i > 0)	      {		type = m.substring(index+1, i);		index = i;	      }	    else	      type = "<unknown ref>";	    break;          case '[':	    type = "";	    arrayDepth++;	    break;          default:	    type = "<unknown " + c + '>';	}	sb.append(type);	// Handle arrays	if (c != '[' && arrayDepth > 0)	  while (arrayDepth > 0)	    {	      sb.append("[]");	      arrayDepth--;	    }	index++;	char nc = (index < length) ? m.charAt(index) : ')';	if (c != '[' && nc  != ')')	  sb.append(", ");	c = nc;      }    // Stop. We are not interested in the return type.    sb.append(')');    return sb.toString();  }  /**   * Releases all resources used by this NameFinder.   */  public void close()  {    if (cppfilt != null)      cppfilt.destroy();    if (addr2line != null)      addr2line.destroy();  }  /**   * Calls close to get rid of all resources.   */  protected void finalize()  {    close();  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?