- LLNI_CRITICAL_START;
-
- stacktrace_t* st = (stacktrace_t *) LLNI_array_data(ba);
-
- if ((index < 0) || (index >= st->length)) {
- /* XXX This should be an IndexOutOfBoundsException (check this
- again). */
- exceptions_throw_arrayindexoutofboundsexception();
- return NULL;
- }
-
- // Get the stacktrace entry.
- stacktrace_entry_t* ste = &(st->entries[index]);
-
- // Get the codeinfo, methodinfo and classinfo.
- codeinfo* code = ste->code;
- methodinfo* m = code->m;
- classinfo* c = m->clazz;
-
- // Get filename.
- java_handle_t* filename;
-
- if (!(m->flags & ACC_NATIVE)) {
- if (c->sourcefile != NULL)
- filename = javastring_new(c->sourcefile);
- else
- filename = NULL;
- }
- else
- filename = NULL;
-
- // Get line number.
- int32_t linenumber;
-
- if (m->flags & ACC_NATIVE) {
- linenumber = -2;
- }
- else {
- /* FIXME The linenumbertable_linenumber_for_pc could change
- the methodinfo pointer when hitting an inlined method. */
-
- linenumber = linenumbertable_linenumber_for_pc(&m, code, ste->pc);
- linenumber = (linenumber == 0) ? -1 : linenumber;
- }
-
- LLNI_CRITICAL_END;
-
- // Get declaring class name.
- java_handle_t* declaringclass = class_get_classname(c);
-
- // Allocate a new StackTraceElement object.
- java_lang_StackTraceElement jlste(declaringclass, javastring_new(m->name), filename, linenumber);
-
- if (jlste.is_null())
- return NULL;