private static StackTraceElement getStackTraceElement(Throwable instance, int index) {
final VmStackFrame frame = (VmStackFrame) ((Object[]) ObjectReference.fromObject(instance).toAddress().add(BACKTRACE_OFFSET).
loadObjectReference().toObject())[index];
final String location = frame.getLocationInfo();
final int lineNumber = "?".equals(location) ? -1 : Integer.parseInt(location);
final VmMethod method = frame.getMethod();
final VmType<?> vmClass = (method == null) ? null : method.getDeclaringClass();
final String fname = (vmClass == null) ? null : vmClass.getSourceFile();
final String cname = (vmClass == null) ? "<unknown class>" : vmClass.getName();
final String mname = (method == null) ? "<unknown method>" : method.getName();
return new StackTraceElement(cname, mname, fname, method == null || method.isNative() ? -2 : lineNumber);
}