Exemplo n.º 1
0
func createStackTraceElements(tObj *rtc.Obj, frame *rtda.Frame) []*StackTraceElement {
	thread := frame.Thread()
	depth := thread.StackDepth()

	// skip unrelated frames
	i := uint(1)
	for k := tObj.Class(); k != nil; k = k.SuperClass() {
		i++
	}
	if thread.TopFrameN(i).Method().Name() == "<athrow>" {
		i++
	}

	stes := make([]*StackTraceElement, 0, depth)
	for ; i < depth; i++ {
		frameN := thread.TopFrameN(i)
		methodN := frameN.Method()
		classN := methodN.Class()
		if classN.Name() != "~shim" { // skip shim frame
			lineNumber := methodN.GetLineNumber(frameN.NextPC() - 1)
			ste := &StackTraceElement{
				declaringClass: classN.NameJlsFormat(),
				methodName:     methodN.Name(),
				fileName:       classN.SourceFile(),
				lineNumber:     lineNumber,
			}
			stes = append(stes, ste)
		}
	}

	return stes
}
Exemplo n.º 2
0
func checkArrayCopy(src, dest *rtc.Obj) bool {
	srcClass := src.Class()
	destClass := dest.Class()

	if !srcClass.IsArray() || !destClass.IsArray() {
		return false
	}
	if srcClass.IsPrimitiveArray() || destClass.IsPrimitiveArray() {
		return srcClass == destClass
	}
	return true
}
Exemplo n.º 3
0
func (self *Thread) HandleUncaughtException(ex *rtc.Obj) {
	self.stack.clear()
	sysClass := rtc.BootLoader().LoadClass("java/lang/System")
	sysErr := sysClass.GetStaticValue("out", "Ljava/io/PrintStream;").(*rtc.Obj)
	printStackTrace := ex.Class().GetInstanceMethod("printStackTrace", "(Ljava/io/PrintStream;)V")

	// call ex.printStackTrace(System.err)
	newFrame := self.NewFrame(printStackTrace)
	vars := newFrame.localVars
	vars.SetRef(0, ex)
	vars.SetRef(1, sysErr)
	self.PushFrame(newFrame)

	//
	// printString := sysErr.Class().GetInstanceMethod("print", "(Ljava/lang/String;)V")
	// newFrame = self.NewFrame(printString)
	// vars = newFrame.localVars
	// vars.SetRef(0, sysErr)
	// vars.SetRef(1, JString("Exception in thread \"main\" ", newFrame))
	// self.PushFrame(newFrame)
}
Exemplo n.º 4
0
// todo
func isAppClassLoader(loader *rtc.Obj) bool {
	return loader.Class().Name() == "sun/misc/Launcher$AppClassLoader"
}