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
434434 int type_decl(int *v, int t, int td);
435435
436436 void error(const char *fmt, ...);
437+void rt_error(unsigned long pc, const char *fmt, ...);
437438 void vpushi(int v);
438439 void vset(int t, int r, int v);
439440 void type_to_str(char *buf, int buf_size,
@@ -5969,6 +5970,18 @@ static void rt_printline(unsigned long wanted_pc) · 5529 unmodified lines
59695970 }
59705971 }
59715972
5973+/* emit a run time error at position 'pc' */
5974+void 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+}
59725985
59735986 /* signal handler for fatal errors */
59745987 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) · 7 unmodified lines
59825995 #error please put the right sigcontext field
59835996 #endif
59845997
5985− rt_printline(pc);
5986−
59875998 switch(signum) {
59885999 case SIGFPE:
59896000 switch(siginf->si_code) {
59906001 case FPE_INTDIV:
59916002 case FPE_FLTDIV:
5992− fprintf(stderr, "division by zero\n");
6003+ rt_error(pc, "division by zero");
59936004 break;
59946005 default:
5995− fprintf(stderr, "floating point exception\n");
6006+ rt_error(pc, "floating point exception");
59966007 break;
59976008 }
59986009 break;
59996010 case SIGBUS:
60006011 case SIGSEGV:
6001− fprintf(stderr, "dereferencing invalid pointer\n");
6012+ rt_error(pc, "dereferencing invalid pointer");
60026013 break;
60036014 case SIGILL:
6004− fprintf(stderr, "illegal instruction\n");
6015+ rt_error(pc, "illegal instruction");
60056016 break;
60066017 case SIGABRT:
6007− fprintf(stderr, "abort() called\n");
6018+ rt_error(pc, "abort() called");
60086019 break;
60096020 default:
6010− fprintf(stderr, "caught signal %d\n", signum);
6021+ rt_error(pc, "caught signal %d", signum);
60116022 break;
60126023 }
60136024 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