예제 #1
0
char * MVM_exception_backtrace_line(MVMThreadContext *tc, MVMFrame *cur_frame, MVMuint16 not_top) {
    MVMString *filename = cur_frame->static_info->body.cu->body.filename;
    MVMString *name = cur_frame->static_info->body.name;
    /* XXX TODO: make the caller pass in a char ** and a length pointer so
     * we can update it if necessary, and the caller can cache it. */
    char *o = malloc(1024);
    MVMuint8 *cur_op = !not_top ? (*tc->interp_cur_op) : cur_frame->return_address;
    MVMuint32 offset = cur_op - cur_frame->static_info->body.bytecode;
    MVMuint32 instr = MVM_bytecode_offset_to_instr_idx(tc, cur_frame->static_info, offset);
    MVMBytecodeAnnotation *annot = MVM_bytecode_resolve_annotation(tc, &cur_frame->static_info->body, offset);

    MVMuint32 line_number = annot ? annot->line_number + 1 : 1;
    MVMuint16 string_heap_index = annot ? annot->filename_string_heap_index : 0;
    char *tmp1 = annot && string_heap_index < cur_frame->static_info->body.cu->body.num_strings
        ? MVM_string_utf8_encode(tc,
            cur_frame->static_info->body.cu->body.strings[string_heap_index], NULL)
        : NULL;

    sprintf(o, " %s %s:%u  (%s:%s:%u)",
        not_top ? "from" : "  at",
        tmp1 ? tmp1 : "<unknown>",
        line_number,
        filename ? (char *) MVM_string_utf8_encode(tc, filename, NULL) : "<ephemeral file>",
        name ? (char *) MVM_string_utf8_encode(tc, name, NULL) : "<anonymous frame>",
        instr
    );

    if (tmp1)
        free(tmp1);
    if (annot)
        free(annot);

    return o;
}
예제 #2
0
파일: exceptions.c 프로젝트: danaj/MoarVM
char * MVM_exception_backtrace_line(MVMThreadContext *tc, MVMFrame *cur_frame, MVMuint16 not_top) {
    MVMString *filename = cur_frame->static_info->body.cu->body.filename;
    MVMString *name = cur_frame->static_info->body.name;
    /* XXX TODO: make the caller pass in a char ** and a length pointer so
     * we can update it if necessary, and the caller can cache it. */
    char *o = malloc(1024);
    MVMuint8 *cur_op = not_top ? cur_frame->return_address : cur_frame->throw_address;
    MVMuint32 offset = cur_op - cur_frame->effective_bytecode;
    MVMuint32 instr = MVM_bytecode_offset_to_instr_idx(tc, cur_frame->static_info, offset);
    MVMBytecodeAnnotation *annot = MVM_bytecode_resolve_annotation(tc, &cur_frame->static_info->body,
                                        offset > 0 ? offset - 1 : 0);

    MVMuint32 line_number = annot ? annot->line_number : 1;
    MVMuint16 string_heap_index = annot ? annot->filename_string_heap_index : 0;
    char *tmp1 = annot && string_heap_index < cur_frame->static_info->body.cu->body.num_strings
        ? MVM_string_utf8_encode(tc,
            cur_frame->static_info->body.cu->body.strings[string_heap_index], NULL)
        : NULL;

    /* We may be mid-instruction if exception was thrown at an unfortunate
     * point; try to cope with that. */
    if (instr == MVM_BC_ILLEGAL_OFFSET && offset >= 2)
        instr = MVM_bytecode_offset_to_instr_idx(tc, cur_frame->static_info, offset - 2);

    snprintf(o, 1024, " %s %s:%u  (%s:%s:%u)",
        not_top ? "from" : "  at",
        tmp1 ? tmp1 : "<unknown>",
        line_number,
        filename ? (char *) MVM_string_utf8_encode(tc, filename, NULL) : "<ephemeral file>",
        name ? (char *) MVM_string_utf8_encode(tc, name, NULL) : "<anonymous frame>",
        instr
    );

    if (tmp1)
        free(tmp1);
    if (annot)
        free(annot);

    return o;
}