pike.git / src / error.c

version» Context lines:

pike.git/src/error.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: error.c,v 1.157 2008/05/27 15:59:17 mast Exp $ + || $Id: error.c,v 1.158 2008/05/27 17:35:34 grubba Exp $   */      #define NO_PIKE_SHORTHAND   #include "global.h"   #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"      /* __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:%d: Fatal error:\n";   #ifdef PIKE_DEBUG   PMOD_EXPORT const char msg_unsetjmp_nosync_1[] =    "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[] =
pike.git/src/error.c:54:   PMOD_EXPORT const char msg_out_of_mem_2[] =    "Out of memory - failed to allocate %"PRINTSIZET"d 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) { -  +  struct svalue *s;    fprintf(stderr, "Recoveries is out biking (Pike_interpreter.recoveries=%p, Pike_sp=%p, %ld)!\n",    Pike_interpreter.recoveries, &foo,    DO_NOT_WARN((long)TESTILITEST)); -  fprintf(stderr, "Last recovery was added at %s\n", -  Pike_interpreter.recoveries->file); +  fprintf(stderr, "Last recovery was added at %s:\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,    DO_NOT_WARN((long)TESTILITEST));    }       /* Add more stuff here when required */   }   #endif      PMOD_EXPORT void pike_gdb_breakpoint(INT32 args)
pike.git/src/error.c:96:    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;   }      PMOD_EXPORT DECLSPEC(noreturn) void pike_throw(void) ATTRIBUTE((noreturn))   {   #ifdef TRACE_UNFINISHED_TYPE_FIELDS    accept_unfinished_type_fields++;   #endif       while(Pike_interpreter.recoveries && throw_severity > Pike_interpreter.recoveries->severity)
pike.git/src/error.c:907:    va_list foo; \    struct object *o; \    va_start(foo,desc); \    ASSERT_THREAD_SWAPPED_IN(); \    o=low_clone(PIKE_CONCAT(FEL,_error_program)); \    DWERROR((stderr, "%s(): Throwing a " #FEL " error\n", func))      #define ERROR_DONE(FOO) \    PIKE_CONCAT(FOO,_error_va(o,func, \    base_sp, args, \ -  desc,&foo)); \ +  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:943:    * o A backtrace is assigned to error_backtrace.    * o If func is specified, a frame is constructed for at the end of    * backtrace using it as function name and base_sp[0..args-1] as    * arguments.    * o If fmt is specified, an error message is created from it and    * fmt_args using string_builder_vsprintf. (fmt_args is passed as a    * va_list pointer to be able to pass NULL if fmt is NULL.)    */   PMOD_EXPORT DECLSPEC(noreturn) void generic_error_va(    struct object *o, const char *func, const struct svalue *base_sp, int args, -  const char *fmt, va_list *fmt_args) +  const char *fmt, va_list fmt_args)   {    struct generic_error_struct *err =    (struct generic_error_struct *) get_storage (o, generic_error_program);      #ifdef PIKE_DEBUG    if (!err)    Pike_fatal ("Got an object which doesn't inherit generic_error_program.\n");   #endif       if(in_error)    {    const char *tmp=in_error;    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); +  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);    }
pike.git/src/error.c:1064:    const char *desc, ...) ATTRIBUTE((noreturn))   {    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((stderr, "%s():Bad arg %d (expected %s)\n", -  func, which_arg, expected_type)); +  func, which_argument, expected_type));    ERROR_DONE(generic);   }      PMOD_EXPORT DECLSPEC(noreturn) void math_error(    const char *func,    struct svalue *base_sp, int args,    struct svalue *number,    const char *desc, ...) ATTRIBUTE((noreturn))   {    INIT_ERROR(math);
pike.git/src/error.c:1140:   }   #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