History

better run time error display

bellard committed 24 years ago

Commit d85bf501 parent b7fed2f1 file · +19 −8Browse files

Unified · Split

tcc.c+19−8
@@ -434,6 +434,7 @@ int parse_btype(int *type_ptr, AttributeDef *ad); · 433 unmodified lines
434int type_decl(int *v, int t, int td);434int type_decl(int *v, int t, int td);
435 435
436void error(const char *fmt, ...);436void error(const char *fmt, ...);
437void rt_error(unsigned long pc, const char *fmt, ...);
437void vpushi(int v);438void vpushi(int v);
438void vset(int t, int r, int v);439void vset(int t, int r, int v);
439void type_to_str(char *buf, int buf_size, 440void type_to_str(char *buf, int buf_size,
@@ -5969,6 +5970,18 @@ static void rt_printline(unsigned long wanted_pc) · 5529 unmodified lines
5969 }5970 }
5970}5971}
5971 5972
5973/* emit a run time error at position 'pc' */
5974void rt_error(unsigned long pc, const char *fmt, ...)
5975{
5976 va_list ap;
5977 va_start(ap, fmt);
5978
5979 rt_printline(pc);
5980 vfprintf(stderr, fmt, ap);
5981 fprintf(stderr, "\n");
5982 exit(255);
5983 va_end(ap);
5984}
5972 5985
5973/* signal handler for fatal errors */5986/* signal handler for fatal errors */
5974static void sig_error(int signum, siginfo_t *siginf, void *puc)5987static 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) · 7 unmodified lines
5982#error please put the right sigcontext field 5995#error please put the right sigcontext field
5983#endif5996#endif
5984 5997
5985 rt_printline(pc);
5986
5987 switch(signum) {5998 switch(signum) {
5988 case SIGFPE:5999 case SIGFPE:
5989 switch(siginf->si_code) {6000 switch(siginf->si_code) {
5990 case FPE_INTDIV:6001 case FPE_INTDIV:
5991 case FPE_FLTDIV:6002 case FPE_FLTDIV:
5992 fprintf(stderr, "division by zero\n");6003 rt_error(pc, "division by zero");
5993 break;6004 break;
5994 default:6005 default:
5995 fprintf(stderr, "floating point exception\n");6006 rt_error(pc, "floating point exception");
5996 break;6007 break;
5997 }6008 }
5998 break;6009 break;
5999 case SIGBUS:6010 case SIGBUS:
6000 case SIGSEGV:6011 case SIGSEGV:
6001 fprintf(stderr, "dereferencing invalid pointer\n");6012 rt_error(pc, "dereferencing invalid pointer");
6002 break;6013 break;
6003 case SIGILL:6014 case SIGILL:
6004 fprintf(stderr, "illegal instruction\n");6015 rt_error(pc, "illegal instruction");
6005 break;6016 break;
6006 case SIGABRT:6017 case SIGABRT:
6007 fprintf(stderr, "abort() called\n");6018 rt_error(pc, "abort() called");
6008 break;6019 break;
6009 default:6020 default:
6010 fprintf(stderr, "caught signal %d\n", signum);6021 rt_error(pc, "caught signal %d", signum);
6011 break;6022 break;
6012 }6023 }
6013 exit(255);6024 exit(255);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t