pike.git / src / error.c

version» Context lines:

pike.git/src/error.c:8:   #include "svalue.h"   #include "pike_macros.h"   #include "pike_error.h"   #include "interpret.h"   #include "stralloc.h"   #include "builtin_functions.h"   #include "array.h"   #include "mapping.h"   #include "object.h"   #include "main.h" - #include "builtin_functions.h" +    #include "backend.h"   #include "operators.h"   #include "module_support.h"   #include "threads.h"   #include "gc.h"   #include "pike_types.h"   #include "sprintf.h" -  + #include "pikecode.h"      /* __attribute__ only applies to function declarations, not    definitions, so we disable them here. */   #undef ATTRIBUTE   #define ATTRIBUTE(X)      /* #define ERROR_DEBUG */      PMOD_EXPORT const char msg_fatal_error[] =    "%s:%ld: Fatal error:\n";
pike.git/src/error.c:38: Inside #if defined(PIKE_DEBUG)
   "UNSETJMP out of sync! (last SETJMP at %s)!\n";   PMOD_EXPORT const char msg_unsetjmp_nosync_2[] =    "UNSETJMP out of sync! (Pike_interpreter.recoveries = 0)\n";   PMOD_EXPORT const char msg_last_setjmp[] =    "LAST SETJMP: %s\n";   PMOD_EXPORT const char msg_unset_onerr_nosync_1[] =    "UNSET_ONERROR out of sync (%p != %p).\n"    "Last SET_ONERROR is from %s\n";   PMOD_EXPORT const char msg_unset_onerr_nosync_2[] =    "UNSET_ONERROR out of sync. No Pike_interpreter.recoveries left.\n"; - PMOD_EXPORT const char msg_assert_onerr[] = -  "%s ASSERT_ONERROR(%p) failed\n"; +    #endif   PMOD_EXPORT const char msg_bad_arg[] =    "Bad argument %d to %s(). Expected %s.\n";   PMOD_EXPORT const char msg_bad_arg_2[] =    "Bad argument %d to %s(). %s\n";   PMOD_EXPORT const char msg_out_of_mem[] =    "Out of memory.\n";   PMOD_EXPORT const char msg_out_of_mem_2[] = -  "Out of memory - failed to allocate %"PRINTSIZET"d bytes.\n"; +  "Out of memory - failed to allocate %"PRINTSIZET"u bytes.\n";   PMOD_EXPORT const char msg_div_by_zero[] =    "Division by zero.\n";      /*    * Recoveries handling.    */      #ifdef PIKE_DEBUG - /* struct mapping *recovery_lookup = NULL; */ +       PMOD_EXPORT void check_recovery_context(void)   {    char foo;   #define TESTILITEST ((((char *)Pike_interpreter.recoveries)-((char *)&foo))*STACK_DIRECTION)    if(Pike_interpreter.recoveries &&    Pike_interpreter.recoveries->on_stack &&    TESTILITEST > 0) {    fprintf(stderr, "Recoveries is out biking (Pike_interpreter.recoveries=%p, Pike_sp=%p, %ld)!\n",    Pike_interpreter.recoveries, &foo,    (long)TESTILITEST);    fprintf(stderr, "Last recovery was added at %s:%d\n",    Pike_interpreter.recoveries->file,    Pike_interpreter.recoveries->line); -  push_int((ptrdiff_t)Pike_interpreter.recoveries); - /* if ((s = low_mapping_lookup(recovery_lookup, Pike_sp-1))) { */ - /* fprintf(stderr, "Try also looking at %s.\n", (char*)s->u.integer); */ - /* } */ -  pop_stack(); +     Pike_fatal("Recoveries is out biking (Pike_interpreter.recoveries=%p, C sp=%p, %ld)!\n",    Pike_interpreter.recoveries, &foo,    (long)TESTILITEST);    }       /* Add more stuff here when required */   }   #endif      /*! @decl void _gdb_breakpoint()
pike.git/src/error.c:112:    r->on_stack = on_stack;   #endif    r->frame_pointer=Pike_fp;    r->stack_pointer=Pike_sp - stack_pop_levels - Pike_interpreter.evaluator_stack;    r->mark_sp=Pike_mark_sp - Pike_interpreter.mark_stack;    r->previous=Pike_interpreter.recoveries;    r->onerror=0;    r->severity=THROW_ERROR;    Pike_interpreter.recoveries=r;    check_recovery_context(); - #ifdef PIKE_DEBUG - /* if (recovery_lookup && Pike_sp) { */ - /* push_int((ptrdiff_t)r); */ - /* push_int((ptrdiff_t)location); */ - /* mapping_insert(recovery_lookup, Pike_sp-2, Pike_sp-1); */ - /* pop_n_elems(2); */ - /* } */ - #endif +     return r;   }      /* coverity[+kill] */   PMOD_EXPORT DECLSPEC(noreturn) void pike_throw(void) ATTRIBUTE((noreturn))   {   #ifdef TRACE_UNFINISHED_TYPE_FIELDS    accept_unfinished_type_fields++;   #endif   
pike.git/src/error.c:215: Inside #if defined(DEBUG_MALLOC) && defined(PIKE_DEBUG)
   debug_malloc_update_location(throw_value.u.refs,    Pike_interpreter.recoveries->file);    debug_malloc_touch(throw_value.u.refs);    }   #endif      #ifdef TRACE_UNFINISHED_TYPE_FIELDS    accept_unfinished_type_fields--;   #endif    + #ifndef OPCODE_INLINE_CATCH    if (Pike_interpreter.catch_ctx &&    &Pike_interpreter.catch_ctx->recovery == Pike_interpreter.recoveries) {    /* This is a phony recovery made in F_CATCH that hasn't been passed    * to LOW_SETJMP. The real jmpbuf is in catching_eval_instruction. */   #ifdef PIKE_DEBUG    if (!Pike_interpreter.catching_eval_jmpbuf)    Pike_fatal ("Got phony F_CATCH recovery but no catching_eval_jmpbuf.\n");   #endif    LOW_LONGJMP (*Pike_interpreter.catching_eval_jmpbuf, 1);    }    else -  + #endif /* OPCODE_INLINE_CATCH */    LOW_LONGJMP(Pike_interpreter.recoveries->recovery,1);   }    - PMOD_EXPORT void push_error(const char *description) + static void push_error(const char *description)   {    push_text(description);    f_backtrace(0);    f_aggregate(2);   }      PMOD_EXPORT struct svalue throw_value = SVALUE_INIT_FREE;   PMOD_EXPORT int throw_severity;   static const char *in_error;   
pike.git/src/error.c:458: Inside #if defined(__NT__)
   exit(-6); /* -SIGIOT */    }    fnordel=999/fnordel;   }   #else /* !__NT__ */   #define do_abort() abort()   #endif /* __NT__ */      PMOD_EXPORT void fatal_on_error(const void *msg)   { +  JMP_BUF tmp; +     /* It's ok if we're exiting. */    if (throw_severity == THROW_EXIT) return;      #ifdef PIKE_DEBUG    if (d_flag) {    fprintf(stderr,"%s\n",(char *)msg);    dump_backlog();    }   #endif    fprintf(stderr,"%s\n",(char *)msg); -  +  +  if (SETJMP(tmp)) { +  fprintf(stderr, "Error in handle_error().\n"); +  } else { +  call_handle_error(); +  } +  UNSETJMP(tmp); +     do_abort();   }      /* coverity[+kill] */   PMOD_EXPORT DECLSPEC(noreturn) void debug_va_fatal(const char *fmt, va_list args) ATTRIBUTE((noreturn))   {    static int in_fatal = 0;       /* fprintf(stderr, "Raw error: %s\n", fmt); */   
pike.git/src/error.c:551:      /* coverity[+kill] */   PMOD_EXPORT DECLSPEC(noreturn) void debug_fatal(const char *fmt, ...) ATTRIBUTE((noreturn))   {    va_list args;    va_start(args,fmt);    debug_va_fatal (fmt, args);    va_end (args);   }    - #if 1 -  +    /*! @class MasterObject    */      /*! @decl string describe_backtrace(mixed exception)    *!    *! Called by various routines to format a readable    *! description of an exception.    *!    *! @param exception    *! Something that was thrown. Usually an @[Error.Generic] object, or
pike.git/src/error.c:661:    *!    *! @note    *! The error message is always terminated with a newline.    *!    *! @seealso    *! @[backtrace()]    */   static void f_error_index(INT32 args)   {    INT_TYPE ind; -  get_all_args("`[]",args,"%i",&ind); +  get_all_args(NULL, args, "%i", &ind);       switch(ind)    {    case 0:    pop_n_elems(args);    apply_current (generic_err_message_fun, 0);    break;    case 1:    pop_n_elems(args);    apply_current (generic_err_backtrace_fun, 0);    break;    default: -  index_error("`[]", Pike_sp-args, args, NULL, Pike_sp-args, +  index_error("`[]", args, NULL, Pike_sp-args,    "Index %"PRINTPIKEINT"d is out of range 0..1.\n", ind);    break;    }   }      static void f_error__sizeof(INT32 args)   {    pop_n_elems(args);    push_int(2);   }
pike.git/src/error.c:820:   }      /*! @decl void create(string message, @    *! void|array(backtrace_frame|array(mixed)) backtrace)    */   static void f_error_create(INT32 args)   {    struct pike_string *msg;    struct array *bt = NULL;    -  get_all_args("create", args, "%W.%A", &msg, &bt); +  get_all_args(NULL, args, "%W.%A", &msg, &bt);       do_free_string(GENERIC_ERROR_THIS->error_message);    copy_shared_string(GENERIC_ERROR_THIS->error_message, msg);       if (bt) {    if (GENERIC_ERROR_THIS->error_backtrace)    free_array (GENERIC_ERROR_THIS->error_backtrace);    add_ref (GENERIC_ERROR_THIS->error_backtrace = bt);    }    else {
pike.git/src/error.c:862:   #endif /* ERROR_DEBUG */      #define INIT_ERROR(FEL)\    va_list foo; \    struct object *o; \    va_start(foo,desc); \    ASSERT_THREAD_SWAPPED_IN(); \    DWERROR("%s(): Throwing a " #FEL " error\n", func); \    o=fast_clone_object(PIKE_CONCAT(FEL,_error_program))    - #define ERROR_DONE(FOO) \ -  PIKE_CONCAT(FOO,_error_va(o,func, \ -  base_sp, args, \ -  desc, &foo)); \ + #define ERROR_DONE() \ +  generic_error_va(o,func, base_sp, args, desc, &foo); \    va_end(foo)      #define ERROR_STRUCT(STRUCT,O) \    ((struct PIKE_CONCAT(STRUCT,_error_struct) *)((O)->storage + PIKE_CONCAT(STRUCT,_error_offset)))      #define ERROR_COPY(STRUCT,X) \    ERROR_STRUCT(STRUCT,o)->X=X      #define ERROR_COPY_SVALUE(STRUCT,X) do { \    if (X) { \
pike.git/src/error.c:922:    in_error=0;    Pike_fatal("Recursive error() calls, original error: %s", tmp);    }    in_error = fmt ? fmt : "no error message";       if (fmt) {    struct string_builder s;    init_string_builder(&s, 0);    string_builder_vsprintf(&s, fmt, *fmt_args);    - #if 0 -  if (!master_program) { -  fprintf(stderr, "ERROR: %s\n", s.s->str); -  } - #endif -  +     if (err->error_message) free_string(err->error_message);    err->error_message = finish_string_builder(&s);    }       f_backtrace(0);    -  if(func) +  if(func && base_sp)    {    int i;    push_int(0);    push_int(0);    push_text(func);       for (i=0;i<args;i++)    push_svalue(base_sp + i);    f_aggregate(args + 3);    f_aggregate(1);
pike.git/src/error.c:976:      /* Throw a preallocated error object.    *    * NOTE: The object MUST NOT have been cloned by a plain low_clone()!    * At least fast_clone_object() MUST have been used, or the object    * data must have been properly initialized in some other way!    */   /* coverity[+kill] */   PMOD_EXPORT DECLSPEC(noreturn) void throw_error_object(    struct object *o, -  const char *func, -  struct svalue *base_sp, int args, +  const char *func, int args,    const char *desc, ...) ATTRIBUTE((noreturn))   { -  +  const struct svalue *base_sp = Pike_sp - args;    va_list foo;    va_start(foo,desc);    ASSERT_THREAD_SWAPPED_IN();    DWERROR("%s(): Throwing an error object\n", func); -  ERROR_DONE(generic); +  ERROR_DONE();   }      /* coverity[+kill] */   PMOD_EXPORT DECLSPEC(noreturn) void generic_error(    const char *func, -  struct svalue *base_sp, int args, +  const struct svalue *base_sp, int args,    const char *desc, ...) ATTRIBUTE((noreturn))   {    INIT_ERROR(generic); -  ERROR_DONE(generic); +  ERROR_DONE();   }      /* coverity[+kill] */   PMOD_EXPORT DECLSPEC(noreturn) void index_error( -  const char *func, -  struct svalue *base_sp, int args, +  const char *func, int args,    struct svalue *value,    struct svalue *index,    const char *desc, ...) ATTRIBUTE((noreturn))   { -  +  const struct svalue *base_sp = Pike_sp - args;    INIT_ERROR(index);    ERROR_COPY_SVALUE(index, value);    ERROR_COPY_SVALUE(index, index); -  ERROR_DONE(generic); +  ERROR_DONE();   }      /* coverity[+kill] */   PMOD_EXPORT DECLSPEC(noreturn) void bad_arg_error( -  const char *func, -  struct svalue *base_sp, int args, +  const char *func, int args,    int which_argument,    const char *expected_type,    struct svalue *got_value,    const char *desc, ...) ATTRIBUTE((noreturn))   { -  +  const struct svalue *base_sp = args>=0 ? Pike_sp-args : NULL;    INIT_ERROR(bad_argument);    ERROR_COPY(bad_argument, which_argument);    if (expected_type)    ERROR_STRUCT(bad_argument,o)->expected_type =    make_shared_string(expected_type);    else    ERROR_STRUCT(bad_argument,o)->expected_type = NULL;    ERROR_COPY_SVALUE(bad_argument, got_value); -  +     DWERROR("%s():Bad arg %d (expected %s)\n",    func, which_argument, expected_type); -  ERROR_DONE(generic); +  ERROR_DONE();   }      /* coverity[+kill] */   PMOD_EXPORT DECLSPEC(noreturn) void math_error( -  const char *func, -  struct svalue *base_sp, int args, +  const char *func, int args,    struct svalue *number,    const char *desc, ...) ATTRIBUTE((noreturn))   {    INIT_ERROR(math); -  +  const struct svalue *base_sp = Pike_sp - args;    if(number)    {    ERROR_COPY_SVALUE(math, number);    }else{    SET_SVAL(ERROR_STRUCT(math,o)->number, PIKE_T_INT, NUMBER_UNDEFINED,    integer, 0);    } -  ERROR_DONE(generic); +  ERROR_DONE();   }      /* coverity[+kill] */ - PMOD_EXPORT DECLSPEC(noreturn) void resource_error( -  const char *func, -  struct svalue *base_sp, int args, -  const char *resource_type, + static DECLSPEC(noreturn) void resource_error( +  const char *func, int args,    size_t howmuch_,    const char *desc, ...) ATTRIBUTE((noreturn))   {    INT_TYPE howmuch = (INT_TYPE)howmuch_; -  +  const struct svalue *base_sp = NULL;    INIT_ERROR(resource); -  +  if(args>=0) base_sp = Pike_sp-args;    ERROR_COPY(resource, howmuch); -  ERROR_STRUCT(resource,o)->resource_type=make_shared_string(resource_type); -  ERROR_DONE(generic); +  ERROR_STRUCT(resource,o)->resource_type=make_shared_string("memory"); +  ERROR_DONE();   }    - /* coverity[+kill] */ - PMOD_EXPORT DECLSPEC(noreturn) void permission_error( -  const char *func, -  struct svalue *base_sp, int args, -  const char *permission_type, -  const char *desc, ...) ATTRIBUTE((noreturn)) + PMOD_EXPORT DECLSPEC(noreturn) void out_of_memory_error ( +  const char *func, int args, +  size_t amount)   { -  INIT_ERROR(permission); -  ERROR_STRUCT(permission,o)->permission_type= -  make_shared_string(permission_type); -  ERROR_DONE(generic); +  resource_error (func, args, amount, +  amount ? msg_out_of_mem_2 : msg_out_of_mem, amount); +  UNREACHABLE();   }      /* coverity[+kill] */   PMOD_EXPORT void wrong_number_of_args_error(const char *name, int args, int expected)   {    if(expected>args)    { -  bad_arg_error (name, Pike_sp-args, args, expected, NULL, NULL, +  bad_arg_error (name, args, expected, NULL, NULL,    "Too few arguments to %s(). Expected at least %d (got %d).\n",    name, expected, args);    }else { -  bad_arg_error (name, Pike_sp-args, args, expected, NULL, NULL, +  bad_arg_error (name, args, expected, NULL, NULL,    "Too many arguments to %s(). Expected at most %d (got %d).\n",    name, expected, args);    }   }      #ifdef PIKE_DEBUG   static void gc_check_throw_value(struct callback *UNUSED(foo), void *UNUSED(bar), void *UNUSED(gazonk))   {    gc_mark_external_svalues(&throw_value,1," in the throw value");   }   #endif      void init_error(void)   {   #define ERR_SETUP   #include "errors.h"      #ifdef PIKE_DEBUG    dmalloc_accept_leak(add_gc_callback(gc_check_throw_value,0,0)); -  - /* recovery_lookup = allocate_mapping(100); */ +    #endif   }      void cleanup_error(void)   { - #ifdef PIKE_DEBUG - /* free_mapping(recovery_lookup); */ - #endif +    #define ERR_CLEANUP   #include "errors.h"   } - #endif +