cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | |
06983f | 1996-09-22 | Fredrik Hübinette (Hubbe) | | ||| This file a part of Pike, and is copyright by Fredrik Hubinette
||| Pike is distributed as GPL (General Public License)
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | ||| See the files COPYING and DISCLAIMER for more information.
\*/
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | #include "global.h"
|
bb55f8 | 1997-03-16 | Fredrik Hübinette (Hubbe) | | #include "pike_macros.h"
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | #include "error.h"
#include "interpret.h"
#include "stralloc.h"
|
06983f | 1996-09-22 | Fredrik Hübinette (Hubbe) | | #include "builtin_functions.h"
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | #include "array.h"
#include "object.h"
|
ef7c76 | 1998-03-24 | Fredrik Hübinette (Hubbe) | | #include "main.h"
#include "builtin_functions.h"
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | |
|
24ddc7 | 1998-03-28 | Henrik Grubbström (Grubba) | | RCSID("$Id: error.c,v 1.14 1998/03/28 15:33:04 grubba Exp $");
|
e9f914 | 1996-09-29 | Fredrik Hübinette (Hubbe) | | #undef ATTRIBUTE
#define ATTRIBUTE(X)
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | JMP_BUF *recoveries=0;
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | |
|
e9f914 | 1996-09-29 | Fredrik Hübinette (Hubbe) | | JMP_BUF *init_recovery(JMP_BUF *r)
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | {
r->fp=fp;
|
f0cd98 | 1996-06-21 | Fredrik Hübinette (Hubbe) | | r->sp=sp-evaluator_stack;
r->mark_sp=mark_sp - mark_stack;
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | r->previous=recoveries;
|
07513e | 1996-10-04 | Fredrik Hübinette (Hubbe) | | r->onerror=0;
|
61e9a0 | 1998-01-25 | Fredrik Hübinette (Hubbe) | | r->severity=THROW_ERROR;
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | recoveries=r;
|
e9f914 | 1996-09-29 | Fredrik Hübinette (Hubbe) | | return r;
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | }
|
5a7ab6 | 1998-01-31 | Fredrik Hübinette (Hubbe) | | void pike_throw(void) ATTRIBUTE((noreturn))
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | {
|
61e9a0 | 1998-01-25 | Fredrik Hübinette (Hubbe) | | while(recoveries && throw_severity > recoveries->severity)
{
while(recoveries->onerror)
{
(*recoveries->onerror->func)(recoveries->onerror->arg);
recoveries->onerror=recoveries->onerror->previous;
}
recoveries=recoveries->previous;
}
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | if(!recoveries)
fatal("No error recovery context.\n");
#ifdef DEBUG
|
f0cd98 | 1996-06-21 | Fredrik Hübinette (Hubbe) | | if(sp - evaluator_stack < recoveries->sp)
|
294dc5 | 1997-08-03 | Fredrik Hübinette (Hubbe) | | fatal("Stack error in error.\n");
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | #endif
while(fp != recoveries->fp)
{
#ifdef DEBUG
if(!fp)
fatal("Popped out of stack frames.\n");
#endif
free_object(fp->current_object);
free_program(fp->context.prog);
fp = fp->parent_frame;
}
|
f0cd98 | 1996-06-21 | Fredrik Hübinette (Hubbe) | | pop_n_elems(sp - evaluator_stack - recoveries->sp);
mark_sp = mark_stack + recoveries->mark_sp;
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | |
|
07513e | 1996-10-04 | Fredrik Hübinette (Hubbe) | | while(recoveries->onerror)
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | {
|
07513e | 1996-10-04 | Fredrik Hübinette (Hubbe) | | (*recoveries->onerror->func)(recoveries->onerror->arg);
recoveries->onerror=recoveries->onerror->previous;
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | }
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | longjmp(recoveries->recovery,1);
}
struct svalue throw_value = { T_INT };
|
61e9a0 | 1998-01-25 | Fredrik Hübinette (Hubbe) | | int throw_severity;
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | |
|
e9f914 | 1996-09-29 | Fredrik Hübinette (Hubbe) | | void va_error(char *fmt, va_list args) ATTRIBUTE((noreturn))
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | {
char buf[2000];
|
5fe7a7 | 1995-11-06 | Fredrik Hübinette (Hubbe) | | static char *in_error;
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | if(in_error)
{
|
5fe7a7 | 1995-11-06 | Fredrik Hübinette (Hubbe) | | char *tmp=in_error;
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | in_error=0;
|
5fe7a7 | 1995-11-06 | Fredrik Hübinette (Hubbe) | | fatal("Recursive error() calls, original error: %s",tmp);
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | }
|
5fe7a7 | 1995-11-06 | Fredrik Hübinette (Hubbe) | | in_error=buf;
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | |
VSPRINTF(buf, fmt, args);
|
dceabb | 1996-10-09 | Fredrik Hübinette (Hubbe) | | if(!recoveries)
|
06983f | 1996-09-22 | Fredrik Hübinette (Hubbe) | | {
#ifdef DEBUG
dump_backlog();
#endif
|
dceabb | 1996-10-09 | Fredrik Hübinette (Hubbe) | | fprintf(stderr,"No error recovery context!\n%s",buf);
|
06983f | 1996-09-22 | Fredrik Hübinette (Hubbe) | | exit(99);
}
|
6b9216 | 1996-05-16 | Fredrik Hübinette (Hubbe) | | if((long)strlen(buf) >= (long)sizeof(buf))
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | fatal("Buffer overflow in error()\n");
push_string(make_shared_string(buf));
f_backtrace(0);
f_aggregate(2);
free_svalue(& throw_value);
|
864d3c | 1998-01-29 | Fredrik Hübinette (Hubbe) | | throw_value = *--sp;
|
61e9a0 | 1998-01-25 | Fredrik Hübinette (Hubbe) | | throw_severity=THROW_ERROR;
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | |
in_error=0;
|
dc7cc9 | 1998-01-14 | Fredrik Hübinette (Hubbe) | | pike_throw();
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | }
|
dceabb | 1996-10-09 | Fredrik Hübinette (Hubbe) | | void exit_on_error(void *msg)
{
#ifdef DEBUG
dump_backlog();
#endif
fprintf(stderr,"%s\n",(char *)msg);
exit(1);
}
void fatal_on_error(void *msg)
{
#ifdef DEBUG
dump_backlog();
#endif
fprintf(stderr,"%s\n",(char *)msg);
abort();
}
|
e9f914 | 1996-09-29 | Fredrik Hübinette (Hubbe) | | void error(char *fmt,...) ATTRIBUTE((noreturn,format (printf, 1, 2)))
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | {
va_list args;
va_start(args,fmt);
va_error(fmt,args);
va_end(args);
}
|
5a7ab6 | 1998-01-31 | Fredrik Hübinette (Hubbe) | | void debug_fatal(char *fmt, ...) ATTRIBUTE((noreturn,format (printf, 1, 2)))
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | {
va_list args;
static int in_fatal = 0;
va_start(args,fmt);
if (in_fatal)
{
(void)VFPRINTF(stderr, fmt, args);
abort();
}
in_fatal = 1;
#ifdef DEBUG
dump_backlog();
#endif
(void)VFPRINTF(stderr, fmt, args);
|
ef7c76 | 1998-03-24 | Fredrik Hübinette (Hubbe) | |
fprintf(stderr,"Attempting to dump backlog (may fail).\n");
d_flag=t_flag=0;
push_text("Fatal error");
f_backtrace(0);
f_aggregate(2);
APPLY_MASTER("describe_backtrace",1);
if(sp[-1].type==T_STRING)
write_to_stderr(sp[-1].u.string->str, sp[-1].u.string->len);
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | fflush(stderr);
abort();
}
|