예제 #1
0
파일: evidence.c 프로젝트: utrhira/mpik
void knh_throw(CTX ctx, ksfp_t *sfp, long start)
{
	if(IS_Exception(ctx->e)) {
		ksfp_t *sp = (sfp == NULL) ? ctx->esp : sfp + start;
		kExceptionHandler *hdr = ctx->ehdrNC;
		if((ctx->e)->uline == 0) {
			(ctx->e)->uline = knh_stack_uline(ctx, sfp);
		}
		while(ctx->stack <= sp) {
			if(sp[0].mtdNC != NULL && isCalledMethod(ctx, sp)) {
				knh_Exception_addStackTrace(ctx, ctx->e, sp+1);
				sp[0].mtdNC = 0;
			}
			if(sp[0].hdr == hdr) {
				size_t i = 0, size = knh_Array_size(hdr->stacklist);
				for(i = 0; i < size; i++) {
					kObject *o = knh_Array_n(hdr->stacklist, i);
					O_cTBL(o)->cdef->checkout(ctx, RAWPTR(o), 1);
				}
				kArrayrimSize(ctx, hdr->stacklist, 0);
#ifdef K_USING_SETJMP_
				knh_longjmp(DP(hdr)->jmpbuf, 1);
#else
				knh_ExceptionHandler_longjmp(ctx, hdr);
#endif
				goto L_NOCATCH;
			}
			sp--;
		}
		L_NOCATCH:;
		knh_write_Object(ctx, KNH_STDERR, UPCAST(ctx->e), FMT_dump);
		knh_exit(ctx, 0);
	}
}
예제 #2
0
파일: evidence.c 프로젝트: utrhira/mpik
static kline_t knh_stack_uline(CTX ctx, ksfp_t *sfp)
{
	if(sfp != NULL) {
		DBG_ASSERT(isCalledMethod(ctx, sfp + K_MTDIDX));
		return sfp_uline(ctx, sfp);
	}
	else {
		//DBG_P("Find Called Method.. ");
		sfp = ctx->esp;
		while(ctx->stack + 3 < sfp) {
			if(sfp[K_MTDIDX].mtdNC != NULL && isCalledMethod(ctx, sfp + K_MTDIDX)) {
				return sfp_uline(ctx, sfp);
			}
			sfp--;
		}
	}
	return 0;
}
예제 #3
0
파일: evidence.c 프로젝트: utrhira/mpik
static kline_t sfp_uline(CTX ctx, ksfp_t *sfp)
{
	kopl_t *pc = sfp[K_PCIDX].pc;
	DBG_ASSERT(isCalledMethod(ctx, sfp + K_MTDIDX));
	if(pc == NULL) return 0;
	{
		int line = (pc-1)->line;
		while(pc->opcode != OPCODE_THCODE) pc--;
		kuri_t uri = ((klr_THCODE_t*)pc)->uri;
		return new_ULINE(uri, line);
	}
}
예제 #4
0
static void Kthrow(KonohaContext *kctx, KonohaStack *sfp, kException *e)
{
	if(IS_Exception(e)) {
		KonohaStack *p = (sfp == NULL) ? kctx->esp : sfp - 1;
		KonohaStack *bottom = kctx->stack->stack;
		while(bottom < p) {
			if(p[0].calledMethod != NULL && isCalledMethod(kctx, p)) {
				kException_AddStackTrace(kctx, p+1, e);
				p[0].calledMethod = 0;
				//p = p[-1];
			}
			p--;
		}
	}
	KLIB KRuntime_raise(kctx, e->symbol, SoftwareFault, NULL, sfp);
}
예제 #5
0
static void Kthrow(KonohaContext *kctx, KonohaStack *sfp)
{
	KonohaExceptionContext *ctx = KonohaContext_getExceptionContext(kctx);
	kException *e = ctx->thrownException;
	if(IS_Exception(e)) {
		KonohaStack *p = (sfp == NULL) ? kctx->esp : sfp - 1;
		KonohaStack *bottom = kctx->stack->jump_bottom;
		while(bottom < p) {
			if(p[0].mtdNC != NULL && isCalledMethod(kctx, p)) {
				kException_addStackTrace(kctx, p+1, e);
				p[0].mtdNC = 0;
				//p = p[-1];
			}
			p--;
		}
	}
	//KLIB Kraise(kctx, 1);
}
예제 #6
0
void knh_throw(Ctx *ctx, knh_sfp_t *sfp, long start)
{
	if(IS_Exception(ctx->e)) {
		knh_sfp_t *sp = (sfp == NULL) ? ctx->esp : sfp + start;
		while(ctx->stack <= sp) {
			DBG_P("[%d] cid=%s ivalue=%lld", (sp - ctx->stack), CLASS__(knh_Object_cid(sp[0].o)), sp[0].ivalue);
			if(sp[0].callmtd != NULL && isCalledMethod(ctx, sp)) {
				sp = knh_Exception_addStackTrace(ctx, ctx->e, sp+1);
			}
			if(IS_ExceptionHandler(sp[0].hdr) && DP(sp[0].hdr)->return_address != NULL) {
				knh_ExceptionHandler_longjmp(ctx, sp[0].hdr);
				goto L_NOCATCH;
			}
			sp--;
		}
		L_NOCATCH:;
		{
			knh_Method_t *mtdf = knh_getSystemFormatter(ctx, CLASS_Exception, MN__dump);
			knh_write_Object(ctx, KNH_STDERR, sfp, &mtdf, UPCAST(ctx->e));
		}
		knh_exit(ctx, 0);
	}
}
예제 #7
0
static knh_sfp_t *knh_Exception_addStackTrace(Ctx *ctx, knh_Exception_t *e, knh_sfp_t *sfp)
{
	knh_intptr_t shift = sfp[K_SHIFTIDX].shift;
	knh_sfp_t *psfp = sfp - shift;
	if(ctx->stack < psfp && psfp < sfp) {
		if(psfp[K_MTDIDX].callmtd != NULL && isCalledMethod(ctx, psfp + K_MTDIDX)) {
			knh_cwb_t cwbbuf, *cwb = knh_cwb_open(ctx, &cwbbuf);
			knh_opline_t *pc = psfp[K_SHIFTIDX].pc;
			knh_Method_t *mtd = psfp[K_MTDIDX].callmtd;
			int linenum = pc->line;
			const char *file = knh_Method_file(ctx, mtd);
			knh_write_cline(ctx, cwb->w, file, linenum);
			knh_putc(ctx, cwb->w, ':');
			knh_stack_writeStackTrace(ctx, sfp, cwb->w);
			if(DP(e)->tracesNULL == NULL) {
				KNH_INITv(DP(e)->tracesNULL, new_Array(ctx, CLASS_String, 0));
			}
			knh_Array_add(ctx, DP(e)->tracesNULL, knh_cwb_newString(ctx, cwb));
			sfp = psfp;
		}
	}
	return sfp - 1;
}