better run time error display
This commit is contained in:
parent
b7fed2f2d4
commit
d85bf50bfe
1 changed files with 19 additions and 8 deletions
27
tcc.c
27
tcc.c
|
@ -434,6 +434,7 @@ int parse_btype(int *type_ptr, AttributeDef *ad);
|
||||||
int type_decl(int *v, int t, int td);
|
int type_decl(int *v, int t, int td);
|
||||||
|
|
||||||
void error(const char *fmt, ...);
|
void error(const char *fmt, ...);
|
||||||
|
void rt_error(unsigned long pc, const char *fmt, ...);
|
||||||
void vpushi(int v);
|
void vpushi(int v);
|
||||||
void vset(int t, int r, int v);
|
void vset(int t, int r, int v);
|
||||||
void type_to_str(char *buf, int buf_size,
|
void type_to_str(char *buf, int buf_size,
|
||||||
|
@ -5969,6 +5970,18 @@ static void rt_printline(unsigned long wanted_pc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* emit a run time error at position 'pc' */
|
||||||
|
void rt_error(unsigned long pc, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
|
||||||
|
rt_printline(pc);
|
||||||
|
vfprintf(stderr, fmt, ap);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
exit(255);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
/* signal handler for fatal errors */
|
/* signal handler for fatal errors */
|
||||||
static void sig_error(int signum, siginfo_t *siginf, void *puc)
|
static void sig_error(int signum, siginfo_t *siginf, void *puc)
|
||||||
|
@ -5982,32 +5995,30 @@ static void sig_error(int signum, siginfo_t *siginf, void *puc)
|
||||||
#error please put the right sigcontext field
|
#error please put the right sigcontext field
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rt_printline(pc);
|
|
||||||
|
|
||||||
switch(signum) {
|
switch(signum) {
|
||||||
case SIGFPE:
|
case SIGFPE:
|
||||||
switch(siginf->si_code) {
|
switch(siginf->si_code) {
|
||||||
case FPE_INTDIV:
|
case FPE_INTDIV:
|
||||||
case FPE_FLTDIV:
|
case FPE_FLTDIV:
|
||||||
fprintf(stderr, "division by zero\n");
|
rt_error(pc, "division by zero");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "floating point exception\n");
|
rt_error(pc, "floating point exception");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SIGBUS:
|
case SIGBUS:
|
||||||
case SIGSEGV:
|
case SIGSEGV:
|
||||||
fprintf(stderr, "dereferencing invalid pointer\n");
|
rt_error(pc, "dereferencing invalid pointer");
|
||||||
break;
|
break;
|
||||||
case SIGILL:
|
case SIGILL:
|
||||||
fprintf(stderr, "illegal instruction\n");
|
rt_error(pc, "illegal instruction");
|
||||||
break;
|
break;
|
||||||
case SIGABRT:
|
case SIGABRT:
|
||||||
fprintf(stderr, "abort() called\n");
|
rt_error(pc, "abort() called");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "caught signal %d\n", signum);
|
rt_error(pc, "caught signal %d", signum);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
exit(255);
|
exit(255);
|
||||||
|
|
Loading…
Add table
Reference in a new issue